laymur 0.1.35 → 0.1.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{Vector2 as t,Box2 as i,MathUtils as n,ShaderMaterial as s,UniformsUtils as o,Color as e,PlaneGeometry as r,Scene as h,Mesh as u,OrthographicCamera as l,WebGLRenderTarget as a,UnsignedByteType as c,LinearFilter as d,RGBAFormat as v,NoBlending as f,Object3D as w,CanvasTexture as p,Texture as g,Camera as m}from"three";function y(){return new b}var b=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 n=this.index[t.id()];if(void 0===n){var s=new x(t,i());return this.index[t.id()]=this.array.length,this.array.push(s),s}return this.array[n]},t.prototype.insert=function(t,i){var n=new x(t,i),s=this.index[t.id()];return void 0===s?(this.index[t.id()]=this.array.length,this.array.push(n)):this.array[s]=n,n},t.prototype.erase=function(t){var i=this.index[t.id()];if(void 0!==i){this.index[t.id()]=void 0;var n=this.array[i],s=this.array.pop();return n!==s&&(this.array[i]=s,this.index[s.first.id()]=i),n}},t.prototype.copy=function(){for(var i=new t,n=0;n<this.array.length;n++){var s=this.array[n].copy();i.array[n]=s,i.index[s.first.id()]=n}return i},t}(),x=function(){function t(t,i){this.first=t,this.second=i}return t.prototype.copy=function(){return new t(this.first,this.second)},t}(),C=function(){function t(t){void 0===t&&(t=""),this.t=0,this.i=null,this.o=S++,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 E(this,t)},t.prototype.minus=function(t){return new E(this,"number"==typeof t?-t:[-1,t])},t.prototype.multiply=function(t){return new E([t,this])},t.prototype.divide=function(t){return new E([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}(),S=0,E=function(){function t(){var t=k(arguments);this.u=t.terms,this.l=t.constant}return t.prototype.terms=function(){return this.u},t.prototype.constant=function(){return this.l},t.prototype.value=function(){for(var t=this.l,i=0,n=this.u.size();i<n;i++){var s=this.u.itemAt(i);t+=s.first.value()*s.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.u.size()},t.prototype.toString=function(){var t=this.u.array.map((t=>t.second+"*"+t.first)).join(" + ");return this.isConstant()||0===this.l||(t+=" + "),t+this.l},t}();function k(t){for(var i=0,n=()=>0,s=y(),o=0,e=t.length;o<e;++o){var r=t[o];if("number"==typeof r)i+=r;else if(r instanceof C)s.setDefault(r,n).second+=1;else if(r instanceof E){i+=r.constant();for(var h=0,u=(d=r.terms()).size();h<u;h++){var l=d.itemAt(h);s.setDefault(l.first,n).second+=l.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],c=r[1];if("number"!=typeof a)throw Error("array item 0 must be a number");if(c instanceof C)s.setDefault(c,n).second+=a;else{if(!(c instanceof E))throw Error("array item 1 must be a variable or expression");var d;for(i+=c.constant()*a,h=0,u=(d=c.terms()).size();h<u;h++)l=d.itemAt(h),s.setDefault(l.first,n).second+=l.second*a}}}return{terms:s,constant:i}}var O,T=(()=>{function t(){}return t.create=(t,i,n,s)=>{void 0===s&&(s=1);var o=0;return o+=1e6*Math.max(0,Math.min(1e3,t*s)),(o+=1e3*Math.max(0,Math.min(1e3,i*s)))+Math.max(0,Math.min(1e3,n*s))},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"})(O||(O={}));var M,P=function(){function t(t,i,n,s){void 0===s&&(s=T.required),this.o=D++,this.v=i,this.p=T.clip(s),this.m=void 0===n&&t instanceof E?t:t.minus(n)}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}(),D=0,I=function(){function t(){this.C=y(),this.S=y(),this.k=y(),this.O=y(),this.T=[],this.M=new F,this.P=null,this.D=0}return t.prototype.createConstraint=function(t,i,n,s){void 0===s&&(s=T.required);var o=new P(t,i,n,s);return this.addConstraint(o),o},t.prototype.addConstraint=function(t){if(void 0!==this.C.find(t))throw Error("duplicate constraint");var i=this.I(t),n=i.row,s=i.tag,o=this.$(n,s);if(o.type()===M.Invalid&&n.allDummies()){if(!$(n.constant()))throw Error("unsatisfiable constraint");o=s.marker}if(o.type()===M.Invalid){if(!this.A(n))throw Error("unsatisfiable constraint")}else n.solveFor(o),this.F(o,n),this.S.insert(o,n);this.C.insert(t,s),this.j(this.M)},t.prototype.removeConstraint=function(t){var i=this.C.erase(t);if(void 0===i)throw Error("unknown constraint");this.U(t,i.second);var n=i.second.marker,s=this.S.erase(n);if(void 0===s){var o=this.B(n);if(o.type()===M.Invalid)throw Error("failed to find leaving row");(s=this.S.erase(o)).second.solveForEx(o,n),this.F(n,s.second)}this.j(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=T.clip(i))===T.required)throw Error("bad required strength");var n=new E(t),s=new P(n,O.Eq,void 0,i);this.addConstraint(s);var o=this.C.find(s).second;this.O.insert(t,{tag:o,constraint:s,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 n=this.O.find(t);if(void 0===n)throw Error("unknown edit variable");var s=this.S,o=n.second,e=i-o.constant;o.constant=i;var r=o.tag.marker,h=s.find(r);if(void 0!==h)return h.second.add(-e)<0&&this.T.push(r),void this.H();var u=o.tag.other;if(void 0!==(h=s.find(u)))return h.second.add(e)<0&&this.T.push(u),void this.H();for(var l=0,a=s.size();l<a;++l){var c=s.itemAt(l),d=c.second,v=d.coefficientFor(r);0!==v&&d.add(e*v)<0&&c.first.type()!==M.External&&this.T.push(c.first)}this.H()},t.prototype.updateVariables=function(){for(var t=this.k,i=this.S,n=0,s=t.size();n<s;++n){var o=t.itemAt(n),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.L(M.External))).second},t.prototype.I=function(t){for(var i=t.expression(),n=new F(i.constant()),s=i.terms(),o=0,e=s.size();o<e;++o){var r=s.itemAt(o);if(!$(r.second)){var h=this.V(r.first),u=this.S.find(h);void 0!==u?n.insertRow(u.second,r.second):n.insertSymbol(h,r.second)}}var l=this.M,a=t.strength(),c={marker:A,other:A};switch(t.op()){case O.Le:case O.Ge:var d=t.op()===O.Le?1:-1,v=this.L(M.Slack);if(c.marker=v,n.insertSymbol(v,d),a<T.required){var f=this.L(M.Error);c.other=f,n.insertSymbol(f,-d),l.insertSymbol(f,a)}break;case O.Eq:if(a<T.required){var w=this.L(M.Error),p=this.L(M.Error);c.marker=w,c.other=p,n.insertSymbol(w,-1),n.insertSymbol(p,1),l.insertSymbol(w,a),l.insertSymbol(p,a)}else{var g=this.L(M.Dummy);c.marker=g,n.insertSymbol(g)}}return n.constant()<0&&n.reverseSign(),{row:n,tag:c}},t.prototype.$=(t,i)=>{for(var n=t.cells(),s=0,o=n.size();s<o;++s){var e=n.itemAt(s);if(e.first.type()===M.External)return e.first}var r=i.marker.type();return(r===M.Slack||r===M.Error)&&t.coefficientFor(i.marker)<0?i.marker:((r=i.other.type())===M.Slack||r===M.Error)&&t.coefficientFor(i.other)<0?i.other:A},t.prototype.A=function(t){var i=this.L(M.Slack);this.S.insert(i,t.copy()),this.P=t.copy(),this.j(this.P);var n=$(this.P.constant());this.P=null;var s=this.S.erase(i);if(void 0!==s){var o=s.second;if(o.isConstant())return n;var e=this.R(o);if(e.type()===M.Invalid)return 0;o.solveForEx(i,e),this.F(e,o),this.S.insert(e,o)}for(var r=this.S,h=0,u=r.size();h<u;++h)r.itemAt(h).second.removeSymbol(i);return this.M.removeSymbol(i),n},t.prototype.F=function(t,i){for(var n=this.S,s=0,o=n.size();s<o;++s){var e=n.itemAt(s);e.second.substitute(t,i),e.second.constant()<0&&e.first.type()!==M.External&&this.T.push(e.first)}this.M.substitute(t,i),this.P&&this.P.substitute(t,i)},t.prototype.j=function(t){for(;;){var i=this.K(t);if(i.type()===M.Invalid)return;var n=this._(i);if(n.type()===M.Invalid)throw Error("the objective is unbounded");var s=this.S.erase(n).second;s.solveForEx(n,i),this.F(i,s),this.S.insert(i,s)}},t.prototype.H=function(){for(var t=this.S,i=this.T;0!==i.length;){var n=i.pop(),s=t.find(n);if(void 0!==s&&s.second.constant()<0){var o=this.N(s.second);if(o.type()===M.Invalid)throw Error("dual optimize failed");var e=s.second;t.erase(n),e.solveForEx(n,o),this.F(o,e),t.insert(o,e)}}},t.prototype.K=t=>{for(var i=t.cells(),n=0,s=i.size();n<s;++n){var o=i.itemAt(n),e=o.first;if(o.second<0&&e.type()!==M.Dummy)return e}return A},t.prototype.N=function(t){for(var i=Number.MAX_VALUE,n=A,s=t.cells(),o=0,e=s.size();o<e;++o){var r=s.itemAt(o),h=r.first,u=r.second;if(u>0&&h.type()!==M.Dummy){var l=this.M.coefficientFor(h)/u;l<i&&(i=l,n=h)}}return n},t.prototype._=function(t){for(var i=Number.MAX_VALUE,n=A,s=this.S,o=0,e=s.size();o<e;++o){var r=s.itemAt(o),h=r.first;if(h.type()!==M.External){var u=r.second,l=u.coefficientFor(t);if(l<0){var a=-u.constant()/l;a<i&&(i=a,n=h)}}}return n},t.prototype.B=function(t){for(var i=Number.MAX_VALUE,n=i,s=i,o=A,e=o,r=o,h=o,u=this.S,l=0,a=u.size();l<a;++l){var c=u.itemAt(l),d=c.second,v=d.coefficientFor(t);if(0!==v){var f=c.first;if(f.type()===M.External)h=f;else if(v<0)(w=-d.constant()/v)<n&&(n=w,e=f);else{var w;(w=d.constant()/v)<s&&(s=w,r=f)}}}return e!==o?e:r!==o?r:h},t.prototype.U=function(t,i){i.marker.type()===M.Error&&this.X(i.marker,t.strength()),i.other.type()===M.Error&&this.X(i.other,t.strength())},t.prototype.X=function(t,i){var n=this.S.find(t);void 0!==n?this.M.insertRow(n.second,-i):this.M.insertSymbol(t,-i)},t.prototype.R=t=>{for(var i=t.cells(),n=0,s=i.size();n<s;++n){var o=i.itemAt(n),e=o.first.type();if(e===M.Slack||e===M.Error)return o.first}return A},t.prototype.L=function(t){return new z(t,this.D++)},t}();function $(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"})(M||(M={}));var z=function(){function t(t,i){this.o=i,this.q=t}return t.prototype.id=function(){return this.o},t.prototype.type=function(){return this.q},t}(),A=new z(M.Invalid,-1),F=function(){function t(t){void 0===t&&(t=0),this.W=y(),this.l=t}return t.prototype.cells=function(){return this.W},t.prototype.constant=function(){return this.l},t.prototype.isConstant=function(){return this.W.empty()},t.prototype.allDummies=function(){for(var t=this.W,i=0,n=t.size();i<n;++i)if(t.itemAt(i).first.type()!==M.Dummy)return 0;return 1},t.prototype.copy=function(){var i=new t(this.l);return i.W=this.W.copy(),i},t.prototype.add=function(t){return this.l+=t},t.prototype.insertSymbol=function(t,i){void 0===i&&(i=1),$(this.W.setDefault(t,(()=>0)).second+=i)&&this.W.erase(t)},t.prototype.insertRow=function(t,i){void 0===i&&(i=1),this.l+=t.l*i;for(var n=t.W,s=0,o=n.size();s<o;++s){var e=n.itemAt(s);this.insertSymbol(e.first,e.second*i)}},t.prototype.removeSymbol=function(t){this.W.erase(t)},t.prototype.reverseSign=function(){this.l=-this.l;for(var t=this.W,i=0,n=t.size();i<n;++i){var s=t.itemAt(i);s.second=-s.second}},t.prototype.solveFor=function(t){var i=this.W,n=-1/i.erase(t).second;this.l*=n;for(var s=0,o=i.size();s<o;++s)i.itemAt(s).second*=n},t.prototype.solveForEx=function(t,i){this.insertSymbol(t,-1),this.solveFor(i)},t.prototype.coefficientFor=function(t){var i=this.W.find(t);return void 0!==i?i.second:0},t.prototype.substitute=function(t,i){var n=this.W.erase(t);void 0!==n&&this.insertRow(i,n.second)},t}();const j=Symbol("xSymbol"),U=Symbol("ySymbol"),B=Symbol("widthSymbol"),H=Symbol("heightSymbol"),V=Symbol("addUIElementSymbol"),L=Symbol("removeUIElementSymbol"),R=Symbol("addConstraintSymbol"),K=Symbol("removeUIConstraintSymbol"),_=Symbol("addConstraintSymbol"),N=Symbol("removeConstraintSymbol"),X=Symbol("addVariableSymbol"),q=Symbol("removeVariableSymbol"),W=Symbol("suggestVariableSymbol"),Y=Symbol("disableConstraintSymbol"),G=Symbol("enableConstraintSymbol"),Q=Symbol("needsRecalculation"),J=Symbol("renderSymbol"),Z=Symbol("clickSymbol");var tt,it,nt;function st(t){return null!==t&&Object.values(tt).some((i=>i===t))}function ot(t){return null!=t?t:tt.ALWAYS}(t=>{t[t.LANDSCAPE=0]="LANDSCAPE",t[t.PORTRAIT=1]="PORTRAIT",t[t.ALWAYS=2]="ALWAYS"})(tt||(tt={}));class et{constructor(t,i){this.layer=t,this.name="",this.layer[R](this,i)}destroy(){this.layer[K](this)}}function rt(t){return null!==t&&Object.values(it).some((i=>i===t))}function ht(t){return null!=t?t:it.P0}function ut(t){switch(t){case it.P0:return T.create(1e3,1e3,1e3);case it.P1:return T.create(100,0,0);case it.P2:return T.create(10,0,0);case it.P3:return T.create(0,100,0);case it.P4:return T.create(0,10,0);case it.P5:return T.create(0,0,100);case it.P6:return T.create(0,0,10);case it.P7:return T.create(0,0,1);default:return T.create(1e3,1e3,1e3)}}function lt(t){return null!==t&&Object.values(nt).some((i=>i===t))}function at(t){return null!=t?t:nt.EQUAL}function ct(t){switch(t){case nt.EQUAL:return O.Eq;case nt.LESS:return O.Le;case nt.GREATER:return O.Ge;default:return O.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"})(it||(it={})),(t=>{t[t.EQUAL=2]="EQUAL",t[t.LESS=0]="LESS",t[t.GREATER=1]="GREATER"})(nt||(nt={}));class dt extends et{constructor(t,i){var n;super(t.layer,new Set([t])),this.element=t,this.options={height:null!==(n=null==i?void 0:i.height)&&void 0!==n?n:t.height,power:ht(null==i?void 0:i.power),rule:at(null==i?void 0:i.rule),orientation:ot(null==i?void 0:i.orientation)},this.options.orientation!==tt.ALWAYS&&this.options.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.options.orientation!==tt.ALWAYS&&t!==this.options.orientation&&this.destroyConstraints()}[G](t){this.options.orientation!==tt.ALWAYS&&t===this.options.orientation&&this.buildConstraints()}buildConstraints(){this.constraint=new P(new E(this.element[H]),ct(this.options.rule),this.options.height,ut(this.options.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class vt{constructor(){this.listeners=new Map}on(t,i,n,s=100){return this.addListener(t,i,n,s,0),this}once(t,i,n,s=100){return this.addListener(t,i,n,s,1),this}off(t,i,n){const s=this.listeners.get(t);if(!s)return this;if(!i)return this.listeners.delete(t),this;const o=s.filter((t=>t.callback!==i||void 0!==n&&t.context!==n));return o.length?this.listeners.set(t,o):this.listeners.delete(t),this}emit(t,...i){const n=this.listeners.get(t);if(!(null==n?void 0:n.length))return 0;for(const s of[...n])s.callback.apply(s.context,i),s.once&&this.off(t,s.callback,s.context);return 1}addListener(t,i,n,s,o){let e=this.listeners.get(t);if(e||(e=[],this.listeners.set(t,e)),e.some((t=>t.callback===i&&t.context===n)))throw Error("Event listener already exists");const r={callback:i,context:n,priority:s,once:o};let h=0;for(;h<e.length&&e[h].priority<=s;)h++;e.splice(h,0,r)}}const ft=new t,wt=new i;var pt,gt;(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE"})(pt||(pt={}));const mt=.5;class yt{constructor(){this[gt]=0,this.positionXInternal=0,this.positionYInternal=0,this.anchorXInternal=mt,this.anchorYInternal=mt,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 n.radToDeg(this.rotationInternal)}get rotation(){return this.rotationInternal}set x(t){this.positionXInternal=t,this[Q]=1}set y(t){this.positionYInternal=t,this[Q]=1}set anchorX(t){this.anchorXInternal=t,this[Q]=1}set anchorY(t){this.anchorYInternal=t,this[Q]=1}set scaleX(t){this.scaleXInternal=t,this[Q]=1}set scaleY(t){this.scaleYInternal=t,this[Q]=1}set angle(t){this.rotationInternal=n.degToRad(t),this[Q]=1}set rotation(t){this.rotationInternal=t,this[Q]=1}reset(){this.positionXInternal=0,this.positionYInternal=0,this.anchorXInternal=mt,this.anchorYInternal=mt,this.scaleXInternal=1,this.scaleYInternal=1,this.rotationInternal=0,this[Q]=1}}gt=Q;class bt extends s{constructor(t){super({uniforms:o.merge([{map:{value:t},opacity:{value:1},color:{value:new e(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 xt=new r(1,1).translate(.5,.5,0),Ct=new h,St=new u(xt);Ct.add(St);class Et{constructor(t=0,i=0){this.paddingHorizontalInternal=t,this.paddingVerticalInternal=i,this.camera=new l(-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){St.material=i,t.render(Ct,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 kt{constructor(){this.passes=[],this.defaultMaterial=new bt,this.screen=new Et,this.needsUpdateInternal=0,this.lastPaddingHasChangedInternal=0,this.lastPaddingInternal=0;const t={format:v,minFilter:d,magFilter:d,type:c,depthBuffer:0,stencilBuffer:0};this.fromRenderTarget=new a(1,1,t),this.toRenderTarget=new a(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,n,s,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:s;const r=this.calculatePadding();this.lastPaddingHasChangedInternal=this.lastPaddingInternal!==r,this.lastPaddingInternal=r;const h=i+2*r,u=n+2*r;this.fromRenderTarget.setSize(h,u),this.toRenderTarget.setSize(h,u),this.setScreenPadding(i,n,r),t.setClearColor(0,0),t.setRenderTarget(this.toRenderTarget),t.clear(1,0,0);const l=s.blending;o&&(s.blending=f),this.screen.render(t,s),s.blending=l;const a={width:i,height:n,padding:r};for(let i=0;i<this.passes.length;i++){const n=this.passes[i];(n.needsUpdate||n.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,n){this.screen.paddingHorizontal=n/t,this.screen.paddingVertical=n/i}reverseRenderTargets(){const t=this.fromRenderTarget;this.fromRenderTarget=this.toRenderTarget,this.toRenderTarget=t}}var Ot,Tt,Mt,Pt,Dt,It,$t,zt,At,Ft;(t=>{t.CLICK="click"})(It||(It={}));class jt extends vt{constructor(t,i,n,s,o,e){super(),this.layer=t,this.object=i,this.name="",this.micro=new yt,this[Ot]=new C("x"),this[Tt]=new C("y"),this[Mt]=new C("width"),this[Pt]=new C("height"),this[Dt]=0,this.behaviorInternal=pt.VISIBLE,this.composer=new kt,this.lastPadding=0,this.layer[V](this,this.object),this.layer[X](this,this[j],ut(it.P7)),this.layer[X](this,this[U],ut(it.P7)),this.layer[X](this,this[B],ut(it.P5)),this.layer[X](this,this[H],ut(it.P5)),this[j].setValue(n),this[U].setValue(s),this[B].setValue(o),this[H].setValue(e),this.layer[W](this,this[j],n),this.layer[W](this,this[U],s),this.layer[W](this,this[B],o),this.layer[W](this,this[H],e)}get passes(){return this.composer.passes}get x(){return this[j].value()}get y(){return this[U].value()}get width(){return this[B].value()}get height(){return this[H].value()}get zIndex(){return this.object.position.z}get behavior(){return this.behaviorInternal}set x(t){this.layer[W](this,this[j],t)}set y(t){this.layer[W](this,this[U],t)}set width(t){this.layer[W](this,this[B],t)}set height(t){this.layer[W](this,this[H],t)}set zIndex(t){this.object.position.z=t}set behavior(t){this.behaviorInternal=t,this.object.visible=t!==pt.HIDDEN}destroy(){this.composer.destroy(),this.layer[q](this,this[H]),this.layer[q](this,this[B]),this.layer[q](this,this[U]),this.layer[q](this,this[j]),this.layer[L](this)}[(Ot=j,Tt=U,Mt=B,Pt=H,Dt=Q,Z)](t,i){return this.behavior!==pt.INTERACTIVE?0:(this.flushTransform(),n=this.x,s=this.y,o=this.width,e=this.height,ft.set(t,i),wt.min.set(n,s),wt.max.set(o,e).add(wt.min),wt.containsPoint(ft)?(this.emit(It.CLICK,this),1):0);var n,s,o,e}flushTransform(){(this[Q]||this.micro[Q]||this.composer.lastPaddingHasChanged)&&(((t,i,n,s,o,e,r)=>{const h=this.x-r,u=this.y-r,l=this.width+2*r,a=this.height+2*r,c=h+l*i.anchorX,d=u+a*i.anchorY;let v=h-c,f=u-d;v*=i.scaleX,f*=i.scaleY;const w=Math.cos(i.rotation),p=Math.sin(i.rotation);v=v*w-f*p,f=v*p+f*w,v+=i.x,f+=i.y,t.position.x=v+c,t.position.y=f+d,t.rotation.z=i.rotation,t.scale.x=l*i.scaleX,t.scale.y=a*i.scaleY})(this.object,this.micro,0,0,0,0,this.composer.lastPadding),this[Q]=0,this.micro[Q]=0)}}const Ut=new e(0);class Bt{constructor(){this.behavior=pt.VISIBLE,this[$t]=new C,this[zt]=new C,this[At]=new C,this[Ft]=new C,this.scene=new h,this.camera=new l,this.solver=new I,this.elements=new Map,this.constraints=new Map,this.orientationPrivate=tt.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()}[($t=j,zt=U,At=B,Ft=H,V)](t,i){if(this.elements.has(t))throw Error("Element already added");this.elements.set(t,{object:i,variables:new Map,constraints:new Set}),this.scene.add(i)}[L](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)}[R](t,i){if(this.constraints.has(t))throw Error("Constraint already added");for(const n of i){const i=this.elements.get(n);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})}[K](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 n of i.elements){const i=this.elements.get(n);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)}[_](t,i){var n;const s=this.constraints.get(t);if(void 0===s)throw Error("Before adding constraint you need to add it's owner");if(s.constraints.has(i))throw Error("Constraint already exists");s.constraints.add(i),null===(n=this.solver)||void 0===n||n.addConstraint(i),this.needsRecalculation=1}[N](t,i){var n;const s=this.constraints.get(t);if(void 0===s)throw Error("Before removing constraint you need to add it's owner");if(!s.constraints.has(i))throw Error("Constraint not found");s.constraints.delete(i),null===(n=this.solver)||void 0===n||n.removeConstraint(i),this.needsRecalculation=1}[X](t,i,n){var s;const o=t instanceof jt?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:n,suggestedValue:i.value()}),null===(s=this.solver)||void 0===s||s.addEditVariable(i,n),this.needsRecalculation=1}[q](t,i){var n;const s=t instanceof jt?this.elements.get(t):this.constraints.get(t);if(void 0===s)throw Error("Before removing variable you need to add it's owner");if(!s.variables.has(i))throw Error("Variable does not exist");s.variables.delete(i),null===(n=this.solver)||void 0===n||n.removeEditVariable(i),this.needsRecalculation=1}[W](t,i,n){var s;const o=t instanceof jt?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!==n&&(e.suggestedValue=n,null===(s=this.solver)||void 0===s||s.suggestValue(i,n),this.needsRecalculation=1)}render(t){var i;if(this.behavior===pt.HIDDEN)return;const n=t.getRenderTarget(),s=t.getClearColor(Ut),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[Q]=1}for(const i of this.elements.keys())i[J](t);t.setRenderTarget(n),t.setClearColor(s),t.setClearAlpha(o),t.render(this.scene,this.camera)}clickInternal(t,i){if(this.behavior!==pt.INTERACTIVE)return;const n=[...this.elements.keys()].filter((t=>t.behavior===pt.INTERACTIVE)).sort(((t,i)=>t.zIndex-i.zIndex));for(const s of n)if(s[Z](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 n,s,o,e,r,h,u,l;this.constraintX&&(null===(n=this.solver)||void 0===n||n.removeConstraint(this.constraintX),this.constraintX=void 0),this.constraintY&&(null===(s=this.solver)||void 0===s||s.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 P(new E(this[j]),O.Eq,0,T.required),this.constraintY=new P(new E(this[U]),O.Eq,0,T.required),this.constraintW=new P(new E(this[B]),O.Eq,t,T.required),this.constraintH=new P(new E(this[H]),O.Eq,i,T.required),null===(r=this.solver)||void 0===r||r.addConstraint(this.constraintX),null===(h=this.solver)||void 0===h||h.addConstraint(this.constraintY),null===(u=this.solver)||void 0===u||u.addConstraint(this.constraintW),null===(l=this.solver)||void 0===l||l.addConstraint(this.constraintH)}updateOrientation(t,i){const n=this.orientationPrivate;if(this.orientationPrivate=t>i?tt.LANDSCAPE:tt.PORTRAIT,n!==this.orientationPrivate){this.solver=void 0;for(const t of this.constraints.keys())t[G](this.orientationPrivate);for(const t of this.constraints.keys())t[Y](this.orientationPrivate);this.solver=new I;const t=[...this.elements.values(),...this.constraints.values()];for(const i of t)for(const[t,n]of i.variables.entries())this.solver.addEditVariable(t,n.strength),this.solver.suggestValue(t,n.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)}}}function Ht(t,i){if((t instanceof Bt?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 Vt(t,i,n){if(t<=0||i<=0)throw Error(null!=n?n:`Invalid dimensions: width (${t}) and height (${i}) must both be positive numbers greater than 0`)}class Lt extends et{constructor(t,i,n){var s,o,e;Ht(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={anchorOne:null!==(s=null==n?void 0:n.anchorOne)&&void 0!==s?s:.5,anchorTwo:null!==(o=null==n?void 0:n.anchorTwo)&&void 0!==o?o:.5,distance:null!==(e=null==n?void 0:n.distance)&&void 0!==e?e:0,power:ht(null==n?void 0:n.power),rule:at(null==n?void 0:n.rule),orientation:ot(null==n?void 0:n.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.elementOne[j]).plus(new E(this.elementOne[B]).multiply(this.parameters.anchorOne)),i=new E(this.elementTwo[j]).plus(new E(this.elementTwo[B]).multiply(this.parameters.anchorTwo));this.constraint=new P(i.minus(t),ct(this.parameters.rule),this.parameters.distance,ut(this.parameters.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class Rt extends et{constructor(t,i,n){var s;Ht(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={proportion:null!==(s=null==n?void 0:n.proportion)&&void 0!==s?s:1,power:ht(null==n?void 0:n.power),rule:at(null==n?void 0:n.rule),orientation:ot(null==n?void 0:n.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.elementOne[B]).multiply(this.parameters.proportion),i=new E(this.elementTwo[B]);this.constraint=new P(t.minus(i),ct(this.parameters.rule),0,ut(this.parameters.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class Kt extends et{constructor(t,i,n){var s,o,e;Ht(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={anchorOne:null!==(s=null==n?void 0:n.anchorOne)&&void 0!==s?s:.5,anchorTwo:null!==(o=null==n?void 0:n.anchorTwo)&&void 0!==o?o:.5,distance:null!==(e=null==n?void 0:n.distance)&&void 0!==e?e:0,power:ht(null==n?void 0:n.power),rule:at(null==n?void 0:n.rule),orientation:ot(null==n?void 0:n.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.elementOne[U]).plus(new E(this.elementOne[H]).multiply(this.parameters.anchorOne)),i=new E(this.elementTwo[U]).plus(new E(this.elementTwo[H]).multiply(this.parameters.anchorTwo));this.constraint=new P(i.minus(t),ct(this.parameters.rule),this.parameters.distance,ut(this.parameters.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class _t extends et{constructor(t,i,n){var s;Ht(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={proportion:null!==(s=null==n?void 0:n.proportion)&&void 0!==s?s:1,power:ht(null==n?void 0:n.power),rule:at(null==n?void 0:n.rule),orientation:ot(null==n?void 0:n.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.elementOne[H]).multiply(this.parameters.proportion),i=new E(this.elementTwo[H]);this.constraint=new P(t.minus(i),ct(this.parameters.rule),0,ut(this.parameters.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class Nt extends et{constructor(t,i){var n;super(t.layer,new Set([t])),this.element=t,this.options={width:null!==(n=null==i?void 0:i.width)&&void 0!==n?n:t.width,power:ht(null==i?void 0:i.power),rule:at(null==i?void 0:i.rule),orientation:ot(null==i?void 0:i.orientation)},this.options.orientation!==tt.ALWAYS&&this.options.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.options.orientation!==tt.ALWAYS&&t!==this.options.orientation&&this.destroyConstraints()}[G](t){this.options.orientation!==tt.ALWAYS&&t===this.options.orientation&&this.buildConstraints()}buildConstraints(){this.constraint=new P(new E(this.element[B]),ct(this.options.rule),this.options.width,ut(this.options.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class Xt{static size(t,i){var n,s,o,e,r,h,u,l;return{x:new Nt(t,{width:null===(n=i.size)||void 0===n?void 0:n.x,power:null===(s=i.power)||void 0===s?void 0:s.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 dt(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===(u=i.rule)||void 0===u?void 0:u.y,orientation:null===(l=i.orientation)||void 0===l?void 0:l.y})}}static distance(t,i,n){var s,o,e,r,h,u,l,a,c,d,v,f;return{x:new Lt(t,i,{anchorOne:null===(s=n.anchorOne)||void 0===s?void 0:s.x,anchorTwo:null===(o=n.anchorTwo)||void 0===o?void 0:o.x,distance:null===(e=n.distance)||void 0===e?void 0:e.x,power:null===(r=n.power)||void 0===r?void 0:r.x,rule:null===(h=n.rule)||void 0===h?void 0:h.x,orientation:null===(u=n.orientation)||void 0===u?void 0:u.x}),y:new Kt(t,i,{anchorOne:null===(l=n.anchorOne)||void 0===l?void 0:l.y,anchorTwo:null===(a=n.anchorTwo)||void 0===a?void 0:a.y,distance:null===(c=n.distance)||void 0===c?void 0:c.y,power:null===(d=n.power)||void 0===d?void 0:d.y,rule:null===(v=n.rule)||void 0===v?void 0:v.y,orientation:null===(f=n.orientation)||void 0===f?void 0:f.y})}}static proportion(t,i,n){var s,o,e,r,h,u,l,a;return{x:new Rt(t,i,{proportion:null===(s=n.proportion)||void 0===s?void 0:s.x,power:null===(o=n.power)||void 0===o?void 0:o.x,rule:null===(e=n.rule)||void 0===e?void 0:e.x,orientation:null===(r=n.orientation)||void 0===r?void 0:r.x}),y:new _t(t,i,{proportion:null===(h=n.proportion)||void 0===h?void 0:h.y,power:null===(u=n.power)||void 0===u?void 0:u.y,rule:null===(l=n.rule)||void 0===l?void 0:l.y,orientation:null===(a=n.orientation)||void 0===a?void 0:a.y})}}}class qt extends et{constructor(t,i){var n;super(t.layer,new Set([t])),this.element=t,this.parameters={aspect:null!==(n=null==i?void 0:i.aspect)&&void 0!==n?n:this.element.width/this.element.height,power:ht(null==i?void 0:i.power),rule:at(null==i?void 0:i.rule),orientation:ot(null==i?void 0:i.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.element[B]).plus(new E(this.element[H]).multiply(-this.parameters.aspect));this.constraint=new P(t,ct(this.parameters.rule),0,ut(this.parameters.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class Wt extends et{constructor(t,i,n){var s,o,e;Ht(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={isStrict:null!==(s=null==n?void 0:n.isStrict)&&void 0!==s?s:1,horizontalAnchor:null!==(o=null==n?void 0:n.horizontalAnchor)&&void 0!==o?o:.5,verticalAnchor:null!==(e=null==n?void 0:n.verticalAnchor)&&void 0!==e?e:.5,orientation:ot(null==n?void 0:n.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){this.constraintX=new P(new E(this.elementOne[j]).plus(new E(this.elementOne[B]).multiply(this.parameters.horizontalAnchor)),O.Eq,new E(this.elementTwo[j]).plus(new E(this.elementTwo[B]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new P(new E(this.elementOne[U]).plus(new E(this.elementOne[H]).multiply(this.parameters.verticalAnchor)),O.Eq,new E(this.elementTwo[U]).plus(new E(this.elementTwo[H]).multiply(this.parameters.verticalAnchor))),this.constraintW=new P(new E(this.elementOne[B]),O.Le,new E(this.elementTwo[B])),this.constraintH=new P(new E(this.elementOne[H]),O.Le,new E(this.elementTwo[H])),this.layer[_](this,this.constraintX),this.layer[_](this,this.constraintY),this.layer[_](this,this.constraintW),this.layer[_](this,this.constraintH),this.parameters.isStrict||(this.constraintStrict=new P(new E(this.elementOne[H]),O.Eq,new E(this.elementTwo[H]),T.strong),this.layer[_](this,this.constraintStrict))}destroyConstraints(){this.constraintX&&(this.layer[N](this,this.constraintX),this.constraintX=void 0),this.constraintY&&(this.layer[N](this,this.constraintY),this.constraintY=void 0),this.constraintW&&(this.layer[N](this,this.constraintW),this.constraintW=void 0),this.constraintH&&(this.layer[N](this,this.constraintH),this.constraintH=void 0),this.constraintStrict&&(this.layer[N](this,this.constraintStrict),this.constraintStrict=void 0)}}function Yt(t){return null!==t&&"object"==typeof t&&("x"in t&&"number"==typeof t.x||"y"in t&&"number"==typeof t.y)}function Gt(t){return null!==t&&"object"==typeof t&&("x"in t&&rt(t.x)||"y"in t&&rt(t.y))}function Qt(t){return null!==t&&"object"==typeof t&&("x"in t&&lt(t.x)||"y"in t&&lt(t.y))}function Jt(t){return null!==t&&"object"==typeof t&&"elementOne"in t&&"elementTwo"in t&&(t.elementOne instanceof jt||t.elementOne instanceof Bt)&&t.elementTwo instanceof jt}function Zt(t){return Jt(t)&&"distance"in t&&Yt(t.distance)&&(!("anchorOne"in t)||"anchorOne"in t&&Yt(t.anchorOne))&&(!("anchorTwo"in t)||"anchorTwo"in t&&Yt(t.anchorTwo))&&(!("power"in t)||Gt(t.power))&&(!("rule"in t)||Qt(t.rule))&&(!("orientation"in t)||st(t.orientation))}function ti(t){return Jt(t)&&"proportion"in t&&Yt(t.proportion)&&(!("power"in t)||Gt(t.power))&&(!("rule"in t)||Qt(t.rule))&&(!("orientation"in t)||st(t.orientation))}function ii(t){return Jt(t)&&"isStrict"in t&&"boolean"==typeof t.isStrict&&(!("anchor"in t)||"anchor"in t&&Yt(t.anchor))}function ni(t){return null!==t&&"object"==typeof t&&"element"in t&&t.element instanceof jt&&(!("power"in t)||rt(t.power))&&(!("rule"in t)||lt(t.rule))}function si(t){return ni(t)&&"height"in t&&"number"==typeof t.height}function oi(t){return ni(t)&&"keepAspect"in t&&"boolean"==typeof t.keepAspect}function ei(t){return ni(t)&&"keepSize"in t&&"boolean"==typeof t.keepSize}class ri{static fromDescription(t){const i=t instanceof Map?t.entries():Object.entries(t),n=new Map;for(const[t,o]of i){if(n.has(t))throw Error(`Duplicate constraint key "${t}" - each constraint must have a unique identifier`);if(ni(s=o)&&"width"in s&&"number"==typeof s.width)ri.buildWidthConstraint(t,o,n);else if(si(o))ri.buildHeightConstraint(t,o,n);else if(oi(o))ri.buildKeepAspectConstraint(t,o,n);else if(ei(o))ri.buildKeepSizeConstraint(t,o,n);else if(Zt(o))ri.buildDistanceConstraint(t,o,n);else if(ti(o))ri.buildProportionalConstraint(t,o,n);else{if(!ii(o))throw Error(`Invalid constraint type for "${t}". Expected one of: Width, Height, KeepAspect, KeepSize, Distance, Proportional, or Cover constraint`);ri.buildCoverConstraint(t,o,n)}}var s;return Object.fromEntries(n)}static buildWidthConstraint(t,i,n){n.set(t,new Nt(i.element,{width:i.width,power:i.power,rule:i.rule,orientation:i.orientation}))}static buildHeightConstraint(t,i,n){n.set(t,new dt(i.element,{height:i.height,power:i.power,rule:i.rule,orientation:i.orientation}))}static buildKeepAspectConstraint(t,i,n){n.set(t,new qt(i.element,{power:i.power,rule:i.rule,orientation:i.orientation}))}static buildKeepSizeConstraint(t,i,n){const s=t.replace(/(KeepSize|Keep)$/,"")+"KeepWidth",o=t.replace(/(KeepSize|Keep)$/,"")+"KeepHeight";n.set(s,new Nt(i.element,{power:i.power,rule:i.rule,orientation:i.orientation})),n.set(o,new dt(i.element,{power:i.power,rule:i.rule,orientation:i.orientation}))}static buildDistanceConstraint(t,i,n){var s,o,e,r,h,u,l,a;if("number"==typeof i.distance.x){const h=t.replace(/(HorizontalDistance|Distance)$/,"")+"HorizontalDistance";n.set(h,new Lt(i.elementOne,i.elementTwo,{distance:i.distance.x,anchorOne:null===(s=i.anchorOne)||void 0===s?void 0:s.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 s=t.replace(/(VerticalDistance|Distance)$/,"")+"VerticalDistance";n.set(s,new Kt(i.elementOne,i.elementTwo,{distance:i.distance.y,anchorOne:null===(h=i.anchorOne)||void 0===h?void 0:h.y,anchorTwo:null===(u=i.anchorTwo)||void 0===u?void 0:u.y,power:null===(l=i.power)||void 0===l?void 0:l.y,rule:null===(a=i.rule)||void 0===a?void 0:a.y,orientation:i.orientation}))}}static buildProportionalConstraint(t,i,n){var s,o,e,r;if("number"==typeof i.proportion.x){const e=t.replace(/(HorizontalProportional|HorizontalProportion|Proportional|Proportion)$/,"")+"HorizontalProportion";n.set(e,new Rt(i.elementOne,i.elementTwo,{proportion:i.proportion.x,power:null===(s=i.power)||void 0===s?void 0:s.x,rule:null===(o=i.rule)||void 0===o?void 0:o.x,orientation:i.orientation}))}if("number"==typeof i.proportion.y){const s=t.replace(/(VerticalProportional|VerticalProportion|Proportional|Proportion)$/,"")+"VerticalProportion";n.set(s,new _t(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,n){var s,o;n.set(t,new Wt(i.elementOne,i.elementTwo,{isStrict:i.isStrict,horizontalAnchor:null===(s=i.anchor)||void 0===s?void 0:s.x,verticalAnchor:null===(o=i.anchor)||void 0===o?void 0:o.y}))}}var hi;(t=>{t[t.FROM_LEFT_TOP=0]="FROM_LEFT_TOP",t[t.FROM_LEFT_BOTTOM=1]="FROM_LEFT_BOTTOM"})(hi||(hi={}));class ui{static build(t,i,n,s={}){var o;const e=null!==(o=s.direction)&&void 0!==o?o:hi.FROM_LEFT_TOP,r=[],h=[];r.push(new Lt(t,i,{anchorOne:0,anchorTwo:0,distance:0,power:s.power,orientation:s.orientation}),new Lt(t,n,{anchorOne:1,anchorTwo:1,distance:0,power:s.power,orientation:s.orientation}));const u=e===hi.FROM_LEFT_TOP?1:0,l=e===hi.FROM_LEFT_TOP?0:1;return h.push(new Kt(t,i,{anchorOne:u,anchorTwo:u,distance:0,power:s.power,orientation:s.orientation}),new Kt(t,n,{anchorOne:l,anchorTwo:l,distance:0,power:s.power,orientation:s.orientation})),{horizontalDistances:r,verticalDistances:h}}}class li{static buildHorizontal(t,i){return this.buildStack(t,i,{distanceConstraint:Lt,proportionConstraint:Rt,centerDistanceConstraint:Kt})}static buildVertical(t,i){return this.buildStack(t,i,{distanceConstraint:Kt,proportionConstraint:_t,centerDistanceConstraint:Lt})}static buildStack(t,i,n){const s=[],o=[],e=[];for(let r=0;r<t.length-1;r++){const h=t[r],u=t[r+1];s.push(new n.distanceConstraint(h,u,{anchorOne:1,anchorTwo:0,distance:i.distance,power:i.power,orientation:i.orientation})),0!=i.keepProportions&&o.push(new n.proportionConstraint(h,u,{power:i.power,orientation:i.orientation})),0!=i.keepAlignment&&e.push(new n.centerDistanceConstraint(h,u,{power:i.power,anchorOne:0,anchorTwo:0,orientation:i.orientation}))}return{distanceConstraints:s,proportionConstraints:o,alignmentConstraints:e}}}class ai extends jt{constructor(t,i=1e3,n=1e3){super(t,new w,0,0,i,n),this.flushTransform()}[J](){this.flushTransform()}}class ci extends jt{constructor(t,i){var n,s;const o=null===(n=i.image)||void 0===n?void 0:n.width,e=null===(s=i.image)||void 0===s?void 0:s.height;Vt(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 bt(i);super(t,new u(xt,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()}[J](t){this.object.material=this.composer.compose(t,this.textureInternal.image.width,this.textureInternal.image.height,this.material),this.flushTransform()}}class di extends s{constructor(t,i){super({uniforms:o.merge([{background:{value:i},foreground:{value:t},progress:{value:1},backgroundColor:{value:new e(1,1,1)},foregroundColor:{value:new e(1,1,1)},color:{value:new e(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 vi extends jt{constructor(t,i,s,o={}){var e,r,h,l;const a=null===(e=i.image)||void 0===e?void 0:e.width,c=null===(r=i.image)||void 0===r?void 0:r.height;Vt(a,c,`Invalid image dimensions - texture "${i.name||"unnamed"}" has invalid width (${a}) or height (${c}). Image dimensions must be non-zero positive numbers.`);const d=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&&Vt(d,v,`Invalid image dimensions - texture "${s.name||"unnamed"}" has invalid width (${d}) or height (${v}). Image dimensions must be non-zero positive numbers.`);const f=new di(i,s),w=new u(xt,f);o.progress&&f.setProgress(o.progress),o.isForegroundDirection&&f.setIsForwardDirection(o.isForegroundDirection),o.angle&&f.setAngle(n.degToRad(o.angle)),o.color&&f.setColor(o.color),o.opacity&&f.setOpacity(o.opacity),o.backgroundColor&&f.setBackgroundColor(o.backgroundColor),o.foregroundColor&&f.setForegroundColor(o.foregroundColor),o.backgroundOpacity&&f.setBackgroundOpacity(o.backgroundOpacity),o.foregroundOpacity&&f.setForegroundOpacity(o.foregroundOpacity);const p=null!=d?d:a,g=null!=c?c: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 n.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(n.degToRad(t)),this.composer.requestUpdate()}set isForwardDirection(t){this.material.setIsForwardDirection(t),this.composer.requestUpdate()}destroy(){this.material.dispose(),super.destroy()}[J](t){this.object.material=this.composer.compose(t,this.imageWidth,this.imageHeight,this.material),this.flushTransform()}}function fi(t,i){var n,s,o,e,r,h,u,l,a,c,d,v,f,w,p,g,m,y,b,x,C,S,E,k,O,T,M,P;const D=Math.max(null!==(s=null!==(n=null==t?void 0:t.fontSize)&&void 0!==n?n:null==i?void 0:i.fontSize)&&void 0!==s?s:16,1),I=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*D,$=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),z=Math.max(null!==(l=null!==(u=null==t?void 0:t.strokeWidth)&&void 0!==u?u:null==i?void 0:i.strokeWidth)&&void 0!==l?l:0,0);return{color:null!==(c=null!==(a=null==t?void 0:t.color)&&void 0!==a?a:null==i?void 0:i.color)&&void 0!==c?c:"#000000",fontFamily:null!==(v=null!==(d=null==t?void 0:t.fontFamily)&&void 0!==d?d:null==i?void 0:i.fontFamily)&&void 0!==v?v:"Arial",fontSize:D,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:I,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:$,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:z}}function wi(t){return t.match(/\S+|\s|\n/g)||[]}function pi(t,i,n){if(t.font=`${n.fontStyle} ${n.fontWeight} ${n.fontSize}px ${n.fontFamily}`,"\n"===i)return{width:0,height:n.lineHeight,baseline:0,lineHeight:n.lineHeight};const s=t.measureText(i),o=s.width,e=Math.ceil(s.actualBoundingBoxAscent+s.actualBoundingBoxDescent);return{width:Math.ceil(o),height:e,baseline:s.actualBoundingBoxDescent,lineHeight:n.lineHeight}}function gi(t,i,n,s,o){o.font=`${s.fontStyle} ${s.fontWeight} ${s.fontSize}px ${s.fontFamily}`,s.enableShadow&&(o.shadowOffsetX=s.shadowOffsetX,o.shadowOffsetY=s.shadowOffsetY,o.shadowBlur=s.shadowBlur,o.shadowColor=s.shadowColor),s.enableStroke&&(o.strokeStyle=s.strokeColor,o.lineWidth=s.strokeWidth,o.strokeText(n,t,i)),o.fillStyle=s.color,o.fillText(n,t,i)}class mi extends jt{constructor(t,i,n={}){var s;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,s=i?t:t.text,o=fi(i?void 0:t.style,n.defaultStyle);for(const t of wi(s)){const i=pi(e,t,o);r.push({text:t,style:o,metrics:i})}}const l=((t,i)=>{const n=[];let s=[],o=0,e=0,r=0,h=0;for(const u of i)"\n"!==u.text?o+u.metrics.width<=t||0===s.length?(s.push(u),o+=u.metrics.width,e=Math.max(e,u.metrics.height),r=Math.max(r,u.metrics.baseline),h=Math.max(h,u.metrics.lineHeight)):(n.push({chunks:s,width:o,height:e,baseline:r,lineHeight:h}),s=[u],o=u.metrics.width,e=u.metrics.height,r=u.metrics.baseline,h=u.metrics.lineHeight):(s.length>0&&n.push({chunks:s,width:o,height:e,baseline:r,lineHeight:h}),s=[],o=0,e=0,r=0,h=0);return s.length>0&&n.push({chunks:s,width:o,height:e,baseline:r,lineHeight:h}),n})(null!==(s=n.maxWidth)&&void 0!==s?s:1024,r),a=(t=>{if(0===t.length)return{width:0,height:0};const i=Math.max(...t.map((t=>t.width)));let n=0;for(let i=0;i<t.length;i++){const s=t[i];n+=0===i?s.height:s.lineHeight,i===t.length-1&&(n+=s.baseline)}return{width:i,height:n}})(l),c=(t=>{var i,n,s,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!==(n=null==t?void 0:t.right)&&void 0!==n?n:0,0),top:Math.max(null!==(s=null==t?void 0:t.top)&&void 0!==s?s:0,0),bottom:Math.max(null!==(o=null==t?void 0:t.bottom)&&void 0!==o?o:0,0)}})(n.padding);o.width=a.width+c.left+c.right,o.height=a.height+c.top+c.bottom;const d=new p(o),v=new bt(d);super(t,new u(xt,v),0,0,a.width,a.height),this.lastSuggestedAspect=0,this.material=v,this.texture=d,this.canvas=o,this.context=e,this.textBlockSize=a,this.padding=c,((t,i,n,s)=>{let o=this.padding.top;for(let t=0;t<n.length;t++){const e=n[t];let r=i;o+=0===t?e.height:e.lineHeight;for(const t of e.chunks)gi(r,o,t.text,t.style,s),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[W](this,this[H],this.width/((this.textBlockSize.width+this.padding.left+this.padding.right)/(this.textBlockSize.height+this.padding.top+this.padding.bottom))))}[J](t){this.object.material=this.composer.compose(t,this.texture.image.width,this.texture.image.height,this.material),this.flushTransform()}}function yi(t){return null!==t&&"object"==typeof t&&"background"in t&&t.background instanceof g&&"foreground"in t&&t.foreground instanceof g}function bi(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text}function xi(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 Ci(t){return!(null===t||"object"!=typeof t||"width"in t&&"number"!=typeof t.width||"height"in t&&"number"!=typeof t.height)}class Si{static fromDescription(t,i){const n=i instanceof Map?i.entries():Object.entries(i),s=new Map;for(const[i,e]of n){if(s.has(i))throw Error(`Duplicate element key "${i}" - each UI element must have a unique identifier`);let n;if(e instanceof g)n=new ci(t,e);else if(null!==(o=e)&&"object"==typeof o&&"texture"in o&&o.texture instanceof g)n=new ci(t,e.texture);else if("string"==typeof e)n=new mi(t,[e]);else if(yi(e))n=new vi(t,e.background,e.foreground);else if(bi(e))n=new mi(t,[e.text],{defaultStyle:e.style});else if(xi(e))n=new mi(t,e.spans,{defaultStyle:e.defaultStyle});else{if(!Ci(e))throw Error(`Invalid UI element type for "${i}". Expected one of: Texture, UIImage, String, UITextDescription, or UITextEnhancedDescription`);n=new ai(t,e.width,e.height)}s.set(i,n)}var o;return Object.fromEntries(s)}}class Ei extends et{constructor(t,i,n){var s,o,e;super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,Ht(t,i),this.parameters={isStrict:null!==(s=null==n?void 0:n.isStrict)&&void 0!==s?s:1,horizontalAnchor:null!==(o=null==n?void 0:n.horizontalAnchor)&&void 0!==o?o:.5,verticalAnchor:null!==(e=null==n?void 0:n.verticalAnchor)&&void 0!==e?e:.5,orientation:ot(null==n?void 0:n.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){this.constraintX=new P(new E(this.elementOne[j]).plus(new E(this.elementOne[B]).multiply(this.parameters.horizontalAnchor)),O.Eq,new E(this.elementTwo[j]).plus(new E(this.elementTwo[B]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new P(new E(this.elementOne[U]).plus(new E(this.elementOne[H]).multiply(this.parameters.verticalAnchor)),O.Eq,new E(this.elementTwo[U]).plus(new E(this.elementTwo[H]).multiply(this.parameters.verticalAnchor))),this.constraintW=new P(new E(this.elementOne[B]),O.Ge,new E(this.elementTwo[B])),this.constraintH=new P(new E(this.elementOne[H]),O.Ge,new E(this.elementTwo[H])),this.layer[_](this,this.constraintX),this.layer[_](this,this.constraintY),this.layer[_](this,this.constraintW),this.layer[_](this,this.constraintH),0!=this.parameters.isStrict&&(this.constraintStrict=new P(new E(this.elementOne[H]),O.Eq,new E(this.elementTwo[H]),T.strong),this.layer[_](this,this.constraintStrict))}destroyConstraints(){this.constraintX&&(this.layer[N](this,this.constraintX),this.constraintX=void 0),this.constraintY&&(this.layer[N](this,this.constraintY),this.constraintY=void 0),this.constraintW&&(this.layer[N](this,this.constraintW),this.constraintW=void 0),this.constraintH&&(this.layer[N](this,this.constraintH),this.constraintH=void 0),this.constraintStrict&&(this.layer[N](this,this.constraintStrict),this.constraintStrict=void 0)}}const ki=512;class Oi extends jt{constructor(t,i){var n,s;const{resolution:o=ki}=i,e="number"==typeof o?o:o.x,r="number"==typeof o?o:o.y;Vt(e,r,`Invalid resolution dimensions: width (${e}) and height (${r}) must both be greater than 0.`);const l=new a(e,r,{format:v,minFilter:d,magFilter:d,type:c,depthBuffer:0,stencilBuffer:0}),f=new bt(l.texture);super(t,new u(xt,f),0,0,e,r),this.needsRenderInternal=0,this.sceneInternal=null!==(n=i.scene)&&void 0!==n?n:new h,this.cameraInternal=null!==(s=i.camera)&&void 0!==s?s:new m,i.renderedByDefault&&(this.needsRenderInternal=1),this.resolutionX=e,this.resolutionY=r,this.renderTarget=l,this.material=f,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 resolution(){return new t(this.resolutionX,this.resolutionY)}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}set camera(t){this.cameraInternal=t}set resolution(t){const i="number"==typeof t?t:t.x,n="number"==typeof t?t:t.y;this.renderTarget.width===i&&this.renderTarget.height===n||(this.resolutionX=i,this.resolutionY=n,this.renderTarget.setSize(i,n))}destroy(){this.material.dispose(),this.renderTarget.dispose(),super.destroy()}requestRender(){this.needsRenderInternal=1,this.composer.requestUpdate()}[J](t){this.needsRenderInternal&&(t.setClearColor(0,1),t.setRenderTarget(this.renderTarget),t.clear(1,1,0),t.render(this.sceneInternal,this.cameraInternal)),this.object.material=this.composer.compose(t,this.resolutionX,this.resolutionY,this.material),this.flushTransform()}}class Ti extends Bt{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!==pt.INTERACTIVE)return;const i=t.target instanceof HTMLElement?t.target.getBoundingClientRect():null,n=i?t.clientX-i.left:t.clientX,s=i?i.bottom-t.clientY:window.innerHeight-t.clientY,o=this.calculateScale();this.clickInternal(n*o,s*o)},window.addEventListener("resize",this.onResize),window.addEventListener("click",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("click",this.onClick),super.destroy()}calculateScale(){var t;return(null!==(t=this.tergetScreenHeight)&&void 0!==t?t:window.innerHeight)/window.innerHeight}}class Mi extends Bt{click(t,i){this.clickInternal(t,i)}resize(t,i){this.resizeInternal(t,i)}}class Pi{}export{qt as UIAspectConstraint,pt as UIBehavior,Xt as UIConstraint2DBuilder,ri as UIConstraintBuilder,ui as UIConstraintContainerBuilder,hi as UIConstraintContainerDirection,it as UIConstraintPower,nt as UIConstraintRule,li as UIConstraintStackBuilder,Wt as UICoverConstraint,ai as UIDummy,Si as UIElementBuilder,It as UIElementEvent,Ei as UIFitConstraint,Ti as UIFullScreenLayer,Et as UIFullScreenQuad,dt as UIHeightConstraint,Lt as UIHorizontalDistanceConstraint,Rt as UIHorizontalProportionConstraint,ci as UIImage,Mi as UIManualLayer,tt as UIOrientation,Pi as UIPass,vi as UIProgress,Oi as UIScene,mi as UIText,Kt as UIVerticalDistanceConstraint,_t as UIVerticalProportionConstraint,Nt as UIWidthConstraint};
1
+ import{Vector2 as t,Box2 as i,MathUtils as n,ShaderMaterial as s,UniformsUtils as o,Color as e,PlaneGeometry as r,Scene as h,Mesh as u,OrthographicCamera as l,WebGLRenderTarget as a,UnsignedByteType as d,LinearFilter as c,RGBAFormat as v,NoBlending as f,Object3D as w,CanvasTexture as p,Texture as g,Camera as m}from"three";function y(){return new b}var b=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 n=this.index[t.id()];if(void 0===n){var s=new x(t,i());return this.index[t.id()]=this.array.length,this.array.push(s),s}return this.array[n]},t.prototype.insert=function(t,i){var n=new x(t,i),s=this.index[t.id()];return void 0===s?(this.index[t.id()]=this.array.length,this.array.push(n)):this.array[s]=n,n},t.prototype.erase=function(t){var i=this.index[t.id()];if(void 0!==i){this.index[t.id()]=void 0;var n=this.array[i],s=this.array.pop();return n!==s&&(this.array[i]=s,this.index[s.first.id()]=i),n}},t.prototype.copy=function(){for(var i=new t,n=0;n<this.array.length;n++){var s=this.array[n].copy();i.array[n]=s,i.index[s.first.id()]=n}return i},t}(),x=function(){function t(t,i){this.first=t,this.second=i}return t.prototype.copy=function(){return new t(this.first,this.second)},t}(),C=function(){function t(t){void 0===t&&(t=""),this.t=0,this.i=null,this.o=S++,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 E(this,t)},t.prototype.minus=function(t){return new E(this,"number"==typeof t?-t:[-1,t])},t.prototype.multiply=function(t){return new E([t,this])},t.prototype.divide=function(t){return new E([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}(),S=0,E=function(){function t(){var t=k(arguments);this.u=t.terms,this.l=t.constant}return t.prototype.terms=function(){return this.u},t.prototype.constant=function(){return this.l},t.prototype.value=function(){for(var t=this.l,i=0,n=this.u.size();i<n;i++){var s=this.u.itemAt(i);t+=s.first.value()*s.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.u.size()},t.prototype.toString=function(){var t=this.u.array.map((t=>t.second+"*"+t.first)).join(" + ");return this.isConstant()||0===this.l||(t+=" + "),t+this.l},t}();function k(t){for(var i=0,n=()=>0,s=y(),o=0,e=t.length;o<e;++o){var r=t[o];if("number"==typeof r)i+=r;else if(r instanceof C)s.setDefault(r,n).second+=1;else if(r instanceof E){i+=r.constant();for(var h=0,u=(c=r.terms()).size();h<u;h++){var l=c.itemAt(h);s.setDefault(l.first,n).second+=l.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 C)s.setDefault(d,n).second+=a;else{if(!(d instanceof E))throw Error("array item 1 must be a variable or expression");var c;for(i+=d.constant()*a,h=0,u=(c=d.terms()).size();h<u;h++)l=c.itemAt(h),s.setDefault(l.first,n).second+=l.second*a}}}return{terms:s,constant:i}}var O,T=(()=>{function t(){}return t.create=(t,i,n,s)=>{void 0===s&&(s=1);var o=0;return o+=1e6*Math.max(0,Math.min(1e3,t*s)),(o+=1e3*Math.max(0,Math.min(1e3,i*s)))+Math.max(0,Math.min(1e3,n*s))},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"})(O||(O={}));var M,P=function(){function t(t,i,n,s){void 0===s&&(s=T.required),this.o=D++,this.v=i,this.p=T.clip(s),this.m=void 0===n&&t instanceof E?t:t.minus(n)}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}(),D=0,I=function(){function t(){this.C=y(),this.S=y(),this.k=y(),this.O=y(),this.T=[],this.M=new F,this.P=null,this.D=0}return t.prototype.createConstraint=function(t,i,n,s){void 0===s&&(s=T.required);var o=new P(t,i,n,s);return this.addConstraint(o),o},t.prototype.addConstraint=function(t){if(void 0!==this.C.find(t))throw Error("duplicate constraint");var i=this.I(t),n=i.row,s=i.tag,o=this.$(n,s);if(o.type()===M.Invalid&&n.allDummies()){if(!$(n.constant()))throw Error("unsatisfiable constraint");o=s.marker}if(o.type()===M.Invalid){if(!this.A(n))throw Error("unsatisfiable constraint")}else n.solveFor(o),this.F(o,n),this.S.insert(o,n);this.C.insert(t,s),this.j(this.M)},t.prototype.removeConstraint=function(t){var i=this.C.erase(t);if(void 0===i)throw Error("unknown constraint");this.U(t,i.second);var n=i.second.marker,s=this.S.erase(n);if(void 0===s){var o=this.B(n);if(o.type()===M.Invalid)throw Error("failed to find leaving row");(s=this.S.erase(o)).second.solveForEx(o,n),this.F(n,s.second)}this.j(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=T.clip(i))===T.required)throw Error("bad required strength");var n=new E(t),s=new P(n,O.Eq,void 0,i);this.addConstraint(s);var o=this.C.find(s).second;this.O.insert(t,{tag:o,constraint:s,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 n=this.O.find(t);if(void 0===n)throw Error("unknown edit variable");var s=this.S,o=n.second,e=i-o.constant;o.constant=i;var r=o.tag.marker,h=s.find(r);if(void 0!==h)return h.second.add(-e)<0&&this.T.push(r),void this.H();var u=o.tag.other;if(void 0!==(h=s.find(u)))return h.second.add(e)<0&&this.T.push(u),void this.H();for(var l=0,a=s.size();l<a;++l){var d=s.itemAt(l),c=d.second,v=c.coefficientFor(r);0!==v&&c.add(e*v)<0&&d.first.type()!==M.External&&this.T.push(d.first)}this.H()},t.prototype.updateVariables=function(){for(var t=this.k,i=this.S,n=0,s=t.size();n<s;++n){var o=t.itemAt(n),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.L(M.External))).second},t.prototype.I=function(t){for(var i=t.expression(),n=new F(i.constant()),s=i.terms(),o=0,e=s.size();o<e;++o){var r=s.itemAt(o);if(!$(r.second)){var h=this.V(r.first),u=this.S.find(h);void 0!==u?n.insertRow(u.second,r.second):n.insertSymbol(h,r.second)}}var l=this.M,a=t.strength(),d={marker:A,other:A};switch(t.op()){case O.Le:case O.Ge:var c=t.op()===O.Le?1:-1,v=this.L(M.Slack);if(d.marker=v,n.insertSymbol(v,c),a<T.required){var f=this.L(M.Error);d.other=f,n.insertSymbol(f,-c),l.insertSymbol(f,a)}break;case O.Eq:if(a<T.required){var w=this.L(M.Error),p=this.L(M.Error);d.marker=w,d.other=p,n.insertSymbol(w,-1),n.insertSymbol(p,1),l.insertSymbol(w,a),l.insertSymbol(p,a)}else{var g=this.L(M.Dummy);d.marker=g,n.insertSymbol(g)}}return n.constant()<0&&n.reverseSign(),{row:n,tag:d}},t.prototype.$=(t,i)=>{for(var n=t.cells(),s=0,o=n.size();s<o;++s){var e=n.itemAt(s);if(e.first.type()===M.External)return e.first}var r=i.marker.type();return(r===M.Slack||r===M.Error)&&t.coefficientFor(i.marker)<0?i.marker:((r=i.other.type())===M.Slack||r===M.Error)&&t.coefficientFor(i.other)<0?i.other:A},t.prototype.A=function(t){var i=this.L(M.Slack);this.S.insert(i,t.copy()),this.P=t.copy(),this.j(this.P);var n=$(this.P.constant());this.P=null;var s=this.S.erase(i);if(void 0!==s){var o=s.second;if(o.isConstant())return n;var e=this.R(o);if(e.type()===M.Invalid)return 0;o.solveForEx(i,e),this.F(e,o),this.S.insert(e,o)}for(var r=this.S,h=0,u=r.size();h<u;++h)r.itemAt(h).second.removeSymbol(i);return this.M.removeSymbol(i),n},t.prototype.F=function(t,i){for(var n=this.S,s=0,o=n.size();s<o;++s){var e=n.itemAt(s);e.second.substitute(t,i),e.second.constant()<0&&e.first.type()!==M.External&&this.T.push(e.first)}this.M.substitute(t,i),this.P&&this.P.substitute(t,i)},t.prototype.j=function(t){for(;;){var i=this.K(t);if(i.type()===M.Invalid)return;var n=this._(i);if(n.type()===M.Invalid)throw Error("the objective is unbounded");var s=this.S.erase(n).second;s.solveForEx(n,i),this.F(i,s),this.S.insert(i,s)}},t.prototype.H=function(){for(var t=this.S,i=this.T;0!==i.length;){var n=i.pop(),s=t.find(n);if(void 0!==s&&s.second.constant()<0){var o=this.N(s.second);if(o.type()===M.Invalid)throw Error("dual optimize failed");var e=s.second;t.erase(n),e.solveForEx(n,o),this.F(o,e),t.insert(o,e)}}},t.prototype.K=t=>{for(var i=t.cells(),n=0,s=i.size();n<s;++n){var o=i.itemAt(n),e=o.first;if(o.second<0&&e.type()!==M.Dummy)return e}return A},t.prototype.N=function(t){for(var i=Number.MAX_VALUE,n=A,s=t.cells(),o=0,e=s.size();o<e;++o){var r=s.itemAt(o),h=r.first,u=r.second;if(u>0&&h.type()!==M.Dummy){var l=this.M.coefficientFor(h)/u;l<i&&(i=l,n=h)}}return n},t.prototype._=function(t){for(var i=Number.MAX_VALUE,n=A,s=this.S,o=0,e=s.size();o<e;++o){var r=s.itemAt(o),h=r.first;if(h.type()!==M.External){var u=r.second,l=u.coefficientFor(t);if(l<0){var a=-u.constant()/l;a<i&&(i=a,n=h)}}}return n},t.prototype.B=function(t){for(var i=Number.MAX_VALUE,n=i,s=i,o=A,e=o,r=o,h=o,u=this.S,l=0,a=u.size();l<a;++l){var d=u.itemAt(l),c=d.second,v=c.coefficientFor(t);if(0!==v){var f=d.first;if(f.type()===M.External)h=f;else if(v<0)(w=-c.constant()/v)<n&&(n=w,e=f);else{var w;(w=c.constant()/v)<s&&(s=w,r=f)}}}return e!==o?e:r!==o?r:h},t.prototype.U=function(t,i){i.marker.type()===M.Error&&this.X(i.marker,t.strength()),i.other.type()===M.Error&&this.X(i.other,t.strength())},t.prototype.X=function(t,i){var n=this.S.find(t);void 0!==n?this.M.insertRow(n.second,-i):this.M.insertSymbol(t,-i)},t.prototype.R=t=>{for(var i=t.cells(),n=0,s=i.size();n<s;++n){var o=i.itemAt(n),e=o.first.type();if(e===M.Slack||e===M.Error)return o.first}return A},t.prototype.L=function(t){return new z(t,this.D++)},t}();function $(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"})(M||(M={}));var z=function(){function t(t,i){this.o=i,this.q=t}return t.prototype.id=function(){return this.o},t.prototype.type=function(){return this.q},t}(),A=new z(M.Invalid,-1),F=function(){function t(t){void 0===t&&(t=0),this.W=y(),this.l=t}return t.prototype.cells=function(){return this.W},t.prototype.constant=function(){return this.l},t.prototype.isConstant=function(){return this.W.empty()},t.prototype.allDummies=function(){for(var t=this.W,i=0,n=t.size();i<n;++i)if(t.itemAt(i).first.type()!==M.Dummy)return 0;return 1},t.prototype.copy=function(){var i=new t(this.l);return i.W=this.W.copy(),i},t.prototype.add=function(t){return this.l+=t},t.prototype.insertSymbol=function(t,i){void 0===i&&(i=1),$(this.W.setDefault(t,(()=>0)).second+=i)&&this.W.erase(t)},t.prototype.insertRow=function(t,i){void 0===i&&(i=1),this.l+=t.l*i;for(var n=t.W,s=0,o=n.size();s<o;++s){var e=n.itemAt(s);this.insertSymbol(e.first,e.second*i)}},t.prototype.removeSymbol=function(t){this.W.erase(t)},t.prototype.reverseSign=function(){this.l=-this.l;for(var t=this.W,i=0,n=t.size();i<n;++i){var s=t.itemAt(i);s.second=-s.second}},t.prototype.solveFor=function(t){var i=this.W,n=-1/i.erase(t).second;this.l*=n;for(var s=0,o=i.size();s<o;++s)i.itemAt(s).second*=n},t.prototype.solveForEx=function(t,i){this.insertSymbol(t,-1),this.solveFor(i)},t.prototype.coefficientFor=function(t){var i=this.W.find(t);return void 0!==i?i.second:0},t.prototype.substitute=function(t,i){var n=this.W.erase(t);void 0!==n&&this.insertRow(i,n.second)},t}();const j=Symbol("xSymbol"),U=Symbol("ySymbol"),B=Symbol("widthSymbol"),H=Symbol("heightSymbol"),V=Symbol("addUIElementSymbol"),L=Symbol("removeUIElementSymbol"),R=Symbol("addConstraintSymbol"),K=Symbol("removeUIConstraintSymbol"),_=Symbol("addConstraintSymbol"),N=Symbol("removeConstraintSymbol"),X=Symbol("addVariableSymbol"),q=Symbol("removeVariableSymbol"),W=Symbol("suggestVariableSymbol"),Y=Symbol("disableConstraintSymbol"),G=Symbol("enableConstraintSymbol"),Q=Symbol("needsRecalculation"),J=Symbol("renderSymbol"),Z=Symbol("clickSymbol");var tt,it,nt;function st(t){return null!==t&&Object.values(tt).some((i=>i===t))}function ot(t){return null!=t?t:tt.ALWAYS}(t=>{t[t.LANDSCAPE=0]="LANDSCAPE",t[t.PORTRAIT=1]="PORTRAIT",t[t.ALWAYS=2]="ALWAYS"})(tt||(tt={}));class et{constructor(t,i){this.layer=t,this.name="",this.layer[R](this,i)}destroy(){this.layer[K](this)}}function rt(t){return null!==t&&Object.values(it).some((i=>i===t))}function ht(t){return null!=t?t:it.P0}function ut(t){switch(t){case it.P0:return T.create(1e3,1e3,1e3);case it.P1:return T.create(100,0,0);case it.P2:return T.create(10,0,0);case it.P3:return T.create(0,100,0);case it.P4:return T.create(0,10,0);case it.P5:return T.create(0,0,100);case it.P6:return T.create(0,0,10);case it.P7:return T.create(0,0,1);default:return T.create(1e3,1e3,1e3)}}function lt(t){return null!==t&&Object.values(nt).some((i=>i===t))}function at(t){return null!=t?t:nt.EQUAL}function dt(t){switch(t){case nt.EQUAL:return O.Eq;case nt.LESS:return O.Le;case nt.GREATER:return O.Ge;default:return O.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"})(it||(it={})),(t=>{t[t.EQUAL=2]="EQUAL",t[t.LESS=0]="LESS",t[t.GREATER=1]="GREATER"})(nt||(nt={}));class ct extends et{constructor(t,i){var n;super(t.layer,new Set([t])),this.element=t,this.options={height:null!==(n=null==i?void 0:i.height)&&void 0!==n?n:t.height,power:ht(null==i?void 0:i.power),rule:at(null==i?void 0:i.rule),orientation:ot(null==i?void 0:i.orientation)},this.options.orientation!==tt.ALWAYS&&this.options.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.options.orientation!==tt.ALWAYS&&t!==this.options.orientation&&this.destroyConstraints()}[G](t){this.options.orientation!==tt.ALWAYS&&t===this.options.orientation&&this.buildConstraints()}buildConstraints(){this.constraint=new P(new E(this.element[H]),dt(this.options.rule),this.options.height,ut(this.options.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class vt{constructor(){this.listeners=new Map}on(t,i,n,s=100){return this.addListener(t,i,n,s,0),this}once(t,i,n,s=100){return this.addListener(t,i,n,s,1),this}off(t,i,n){const s=this.listeners.get(t);if(!s)return this;if(!i)return this.listeners.delete(t),this;const o=s.filter((t=>t.callback!==i||void 0!==n&&t.context!==n));return o.length?this.listeners.set(t,o):this.listeners.delete(t),this}emit(t,...i){const n=this.listeners.get(t);if(!(null==n?void 0:n.length))return 0;for(const s of[...n])s.callback.apply(s.context,i),s.once&&this.off(t,s.callback,s.context);return 1}addListener(t,i,n,s,o){let e=this.listeners.get(t);if(e||(e=[],this.listeners.set(t,e)),e.some((t=>t.callback===i&&t.context===n)))throw Error("Event listener already exists");const r={callback:i,context:n,priority:s,once:o};let h=0;for(;h<e.length&&e[h].priority<=s;)h++;e.splice(h,0,r)}}const ft=new t,wt=new i;var pt,gt;(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE"})(pt||(pt={}));const mt=.5;class yt{constructor(){this[gt]=0,this.positionXInternal=0,this.positionYInternal=0,this.anchorXInternal=mt,this.anchorYInternal=mt,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 n.radToDeg(this.rotationInternal)}get rotation(){return this.rotationInternal}set x(t){this.positionXInternal=t,this[Q]=1}set y(t){this.positionYInternal=t,this[Q]=1}set anchorX(t){this.anchorXInternal=t,this[Q]=1}set anchorY(t){this.anchorYInternal=t,this[Q]=1}set scaleX(t){this.scaleXInternal=t,this[Q]=1}set scaleY(t){this.scaleYInternal=t,this[Q]=1}set angle(t){this.rotationInternal=n.degToRad(t),this[Q]=1}set rotation(t){this.rotationInternal=t,this[Q]=1}reset(){this.positionXInternal=0,this.positionYInternal=0,this.anchorXInternal=mt,this.anchorYInternal=mt,this.scaleXInternal=1,this.scaleYInternal=1,this.rotationInternal=0,this[Q]=1}}gt=Q;class bt extends s{constructor(t){super({uniforms:o.merge([{map:{value:t},opacity:{value:1},color:{value:new e(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 xt=new r(1,1).translate(.5,.5,0),Ct=new h,St=new u(xt);Ct.add(St);class Et{constructor(t=0,i=0){this.paddingHorizontalInternal=t,this.paddingVerticalInternal=i,this.camera=new l(-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){St.material=i,t.render(Ct,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 kt{constructor(){this.passes=[],this.defaultMaterial=new bt,this.screen=new Et,this.needsUpdateInternal=0,this.lastPaddingHasChangedInternal=0,this.lastPaddingInternal=0;const t={format:v,minFilter:c,magFilter:c,type:d,depthBuffer:0,stencilBuffer:0};this.fromRenderTarget=new a(1,1,t),this.toRenderTarget=new a(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,n,s,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:s;const r=this.calculatePadding();this.lastPaddingHasChangedInternal=this.lastPaddingInternal!==r,this.lastPaddingInternal=r;const h=i+2*r,u=n+2*r;this.fromRenderTarget.setSize(h,u),this.toRenderTarget.setSize(h,u),this.setScreenPadding(i,n,r),t.setClearColor(0,0),t.setRenderTarget(this.toRenderTarget),t.clear(1,0,0);const l=s.blending;o&&(s.blending=f),this.screen.render(t,s),s.blending=l;const a={width:i,height:n,padding:r};for(let i=0;i<this.passes.length;i++){const n=this.passes[i];(n.needsUpdate||n.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,n){this.screen.paddingHorizontal=n/t,this.screen.paddingVertical=n/i}reverseRenderTargets(){const t=this.fromRenderTarget;this.fromRenderTarget=this.toRenderTarget,this.toRenderTarget=t}}var Ot,Tt,Mt,Pt,Dt,It,$t,zt,At,Ft;(t=>{t.CLICK="click"})(It||(It={}));class jt extends vt{constructor(t,i,n,s,o,e){super(),this.layer=t,this.object=i,this.name="",this.micro=new yt,this[Ot]=new C("x"),this[Tt]=new C("y"),this[Mt]=new C("width"),this[Pt]=new C("height"),this[Dt]=0,this.behaviorInternal=pt.VISIBLE,this.composer=new kt,this.lastPadding=0,this.layer[V](this,this.object),this.layer[X](this,this[j],ut(it.P7)),this.layer[X](this,this[U],ut(it.P7)),this.layer[X](this,this[B],ut(it.P5)),this.layer[X](this,this[H],ut(it.P5)),this[j].setValue(n),this[U].setValue(s),this[B].setValue(o),this[H].setValue(e),this.layer[W](this,this[j],n),this.layer[W](this,this[U],s),this.layer[W](this,this[B],o),this.layer[W](this,this[H],e)}get passes(){return this.composer.passes}get x(){return this[j].value()}get y(){return this[U].value()}get width(){return this[B].value()}get height(){return this[H].value()}get zIndex(){return this.object.position.z}get behavior(){return this.behaviorInternal}set x(t){this.layer[W](this,this[j],t)}set y(t){this.layer[W](this,this[U],t)}set width(t){this.layer[W](this,this[B],t)}set height(t){this.layer[W](this,this[H],t)}set zIndex(t){this.object.position.z=t}set behavior(t){this.behaviorInternal=t,this.object.visible=t!==pt.HIDDEN}destroy(){this.composer.destroy(),this.layer[q](this,this[H]),this.layer[q](this,this[B]),this.layer[q](this,this[U]),this.layer[q](this,this[j]),this.layer[L](this)}[(Ot=j,Tt=U,Mt=B,Pt=H,Dt=Q,Z)](t,i){return this.behavior!==pt.INTERACTIVE?0:(this.flushTransform(),n=this.x,s=this.y,o=this.width,e=this.height,ft.set(t,i),wt.min.set(n,s),wt.max.set(o,e).add(wt.min),wt.containsPoint(ft)?(this.emit(It.CLICK,this),1):0);var n,s,o,e}flushTransform(){(this[Q]||this.micro[Q]||this.composer.lastPaddingHasChanged)&&(((t,i,n,s,o,e,r)=>{const h=this.x-r,u=this.y-r,l=this.width+2*r,a=this.height+2*r,d=h+l*i.anchorX,c=u+a*i.anchorY;let v=h-d,f=u-c;v*=i.scaleX,f*=i.scaleY;const w=Math.cos(i.rotation),p=Math.sin(i.rotation);v=v*w-f*p,f=v*p+f*w,v+=i.x,f+=i.y,t.position.x=v+d,t.position.y=f+c,t.rotation.z=i.rotation,t.scale.x=l*i.scaleX,t.scale.y=a*i.scaleY})(this.object,this.micro,0,0,0,0,this.composer.lastPadding),this[Q]=0,this.micro[Q]=0)}}const Ut=new e(0);class Bt{constructor(){this.behavior=pt.VISIBLE,this[$t]=new C,this[zt]=new C,this[At]=new C,this[Ft]=new C,this.scene=new h,this.camera=new l,this.solver=new I,this.elements=new Map,this.constraints=new Map,this.orientationPrivate=tt.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()}[($t=j,zt=U,At=B,Ft=H,V)](t,i){if(this.elements.has(t))throw Error("Element already added");this.elements.set(t,{object:i,variables:new Map,constraints:new Set}),this.scene.add(i)}[L](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)}[R](t,i){if(this.constraints.has(t))throw Error("Constraint already added");for(const n of i){const i=this.elements.get(n);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})}[K](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 n of i.elements){const i=this.elements.get(n);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)}[_](t,i){var n;const s=this.constraints.get(t);if(void 0===s)throw Error("Before adding constraint you need to add it's owner");if(s.constraints.has(i))throw Error("Constraint already exists");s.constraints.add(i),null===(n=this.solver)||void 0===n||n.addConstraint(i),this.needsRecalculation=1}[N](t,i){var n;const s=this.constraints.get(t);if(void 0===s)throw Error("Before removing constraint you need to add it's owner");if(!s.constraints.has(i))throw Error("Constraint not found");s.constraints.delete(i),null===(n=this.solver)||void 0===n||n.removeConstraint(i),this.needsRecalculation=1}[X](t,i,n){var s;const o=t instanceof jt?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:n,suggestedValue:i.value()}),null===(s=this.solver)||void 0===s||s.addEditVariable(i,n),this.needsRecalculation=1}[q](t,i){var n;const s=t instanceof jt?this.elements.get(t):this.constraints.get(t);if(void 0===s)throw Error("Before removing variable you need to add it's owner");if(!s.variables.has(i))throw Error("Variable does not exist");s.variables.delete(i),null===(n=this.solver)||void 0===n||n.removeEditVariable(i),this.needsRecalculation=1}[W](t,i,n){var s;const o=t instanceof jt?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!==n&&(e.suggestedValue=n,null===(s=this.solver)||void 0===s||s.suggestValue(i,n),this.needsRecalculation=1)}render(t){var i;if(this.behavior===pt.HIDDEN)return;const n=t.getRenderTarget(),s=t.getClearColor(Ut),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[Q]=1}for(const i of this.elements.keys())i[J](t);t.setRenderTarget(n),t.setClearColor(s),t.setClearAlpha(o),t.render(this.scene,this.camera)}clickInternal(t,i){if(this.behavior!==pt.INTERACTIVE)return;const n=[...this.elements.keys()].filter((t=>t.behavior===pt.INTERACTIVE)).sort(((t,i)=>t.zIndex-i.zIndex));for(const s of n)if(s[Z](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 n,s,o,e,r,h,u,l;this.constraintX&&(null===(n=this.solver)||void 0===n||n.removeConstraint(this.constraintX),this.constraintX=void 0),this.constraintY&&(null===(s=this.solver)||void 0===s||s.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 P(new E(this[j]),O.Eq,0,T.required),this.constraintY=new P(new E(this[U]),O.Eq,0,T.required),this.constraintW=new P(new E(this[B]),O.Eq,t,T.required),this.constraintH=new P(new E(this[H]),O.Eq,i,T.required),null===(r=this.solver)||void 0===r||r.addConstraint(this.constraintX),null===(h=this.solver)||void 0===h||h.addConstraint(this.constraintY),null===(u=this.solver)||void 0===u||u.addConstraint(this.constraintW),null===(l=this.solver)||void 0===l||l.addConstraint(this.constraintH)}updateOrientation(t,i){const n=this.orientationPrivate;if(this.orientationPrivate=t>i?tt.LANDSCAPE:tt.PORTRAIT,n!==this.orientationPrivate){this.solver=void 0;for(const t of this.constraints.keys())t[G](this.orientationPrivate);for(const t of this.constraints.keys())t[Y](this.orientationPrivate);this.solver=new I;const t=[...this.elements.values(),...this.constraints.values()];for(const i of t)for(const[t,n]of i.variables.entries())this.solver.addEditVariable(t,n.strength),this.solver.suggestValue(t,n.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)}}}function Ht(t,i){if((t instanceof Bt?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 Vt(t,i,n){if(t<=0||i<=0)throw Error(null!=n?n:`Invalid dimensions: width (${t}) and height (${i}) must both be positive numbers greater than 0`)}class Lt extends et{constructor(t,i,n){var s,o,e;Ht(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={anchorOne:null!==(s=null==n?void 0:n.anchorOne)&&void 0!==s?s:.5,anchorTwo:null!==(o=null==n?void 0:n.anchorTwo)&&void 0!==o?o:.5,distance:null!==(e=null==n?void 0:n.distance)&&void 0!==e?e:0,power:ht(null==n?void 0:n.power),rule:at(null==n?void 0:n.rule),orientation:ot(null==n?void 0:n.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.elementOne[j]).plus(new E(this.elementOne[B]).multiply(this.parameters.anchorOne)),i=new E(this.elementTwo[j]).plus(new E(this.elementTwo[B]).multiply(this.parameters.anchorTwo));this.constraint=new P(i.minus(t),dt(this.parameters.rule),this.parameters.distance,ut(this.parameters.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class Rt extends et{constructor(t,i,n){var s;Ht(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={proportion:null!==(s=null==n?void 0:n.proportion)&&void 0!==s?s:1,power:ht(null==n?void 0:n.power),rule:at(null==n?void 0:n.rule),orientation:ot(null==n?void 0:n.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.elementOne[B]).multiply(this.parameters.proportion),i=new E(this.elementTwo[B]);this.constraint=new P(t.minus(i),dt(this.parameters.rule),0,ut(this.parameters.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class Kt extends et{constructor(t,i,n){var s,o,e;Ht(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={anchorOne:null!==(s=null==n?void 0:n.anchorOne)&&void 0!==s?s:.5,anchorTwo:null!==(o=null==n?void 0:n.anchorTwo)&&void 0!==o?o:.5,distance:null!==(e=null==n?void 0:n.distance)&&void 0!==e?e:0,power:ht(null==n?void 0:n.power),rule:at(null==n?void 0:n.rule),orientation:ot(null==n?void 0:n.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.elementOne[U]).plus(new E(this.elementOne[H]).multiply(this.parameters.anchorOne)),i=new E(this.elementTwo[U]).plus(new E(this.elementTwo[H]).multiply(this.parameters.anchorTwo));this.constraint=new P(i.minus(t),dt(this.parameters.rule),this.parameters.distance,ut(this.parameters.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class _t extends et{constructor(t,i,n){var s;Ht(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={proportion:null!==(s=null==n?void 0:n.proportion)&&void 0!==s?s:1,power:ht(null==n?void 0:n.power),rule:at(null==n?void 0:n.rule),orientation:ot(null==n?void 0:n.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.elementOne[H]).multiply(this.parameters.proportion),i=new E(this.elementTwo[H]);this.constraint=new P(t.minus(i),dt(this.parameters.rule),0,ut(this.parameters.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class Nt extends et{constructor(t,i){var n;super(t.layer,new Set([t])),this.element=t,this.options={width:null!==(n=null==i?void 0:i.width)&&void 0!==n?n:t.width,power:ht(null==i?void 0:i.power),rule:at(null==i?void 0:i.rule),orientation:ot(null==i?void 0:i.orientation)},this.options.orientation!==tt.ALWAYS&&this.options.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.options.orientation!==tt.ALWAYS&&t!==this.options.orientation&&this.destroyConstraints()}[G](t){this.options.orientation!==tt.ALWAYS&&t===this.options.orientation&&this.buildConstraints()}buildConstraints(){this.constraint=new P(new E(this.element[B]),dt(this.options.rule),this.options.width,ut(this.options.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class Xt{static size(t,i){var n,s,o,e,r,h,u,l;return{x:new Nt(t,{width:null===(n=i.size)||void 0===n?void 0:n.x,power:null===(s=i.power)||void 0===s?void 0:s.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 ct(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===(u=i.rule)||void 0===u?void 0:u.y,orientation:null===(l=i.orientation)||void 0===l?void 0:l.y})}}static distance(t,i,n){var s,o,e,r,h,u,l,a,d,c,v,f;return{x:new Lt(t,i,{anchorOne:null===(s=n.anchorOne)||void 0===s?void 0:s.x,anchorTwo:null===(o=n.anchorTwo)||void 0===o?void 0:o.x,distance:null===(e=n.distance)||void 0===e?void 0:e.x,power:null===(r=n.power)||void 0===r?void 0:r.x,rule:null===(h=n.rule)||void 0===h?void 0:h.x,orientation:null===(u=n.orientation)||void 0===u?void 0:u.x}),y:new Kt(t,i,{anchorOne:null===(l=n.anchorOne)||void 0===l?void 0:l.y,anchorTwo:null===(a=n.anchorTwo)||void 0===a?void 0:a.y,distance:null===(d=n.distance)||void 0===d?void 0:d.y,power:null===(c=n.power)||void 0===c?void 0:c.y,rule:null===(v=n.rule)||void 0===v?void 0:v.y,orientation:null===(f=n.orientation)||void 0===f?void 0:f.y})}}static proportion(t,i,n){var s,o,e,r,h,u,l,a;return{x:new Rt(t,i,{proportion:null===(s=n.proportion)||void 0===s?void 0:s.x,power:null===(o=n.power)||void 0===o?void 0:o.x,rule:null===(e=n.rule)||void 0===e?void 0:e.x,orientation:null===(r=n.orientation)||void 0===r?void 0:r.x}),y:new _t(t,i,{proportion:null===(h=n.proportion)||void 0===h?void 0:h.y,power:null===(u=n.power)||void 0===u?void 0:u.y,rule:null===(l=n.rule)||void 0===l?void 0:l.y,orientation:null===(a=n.orientation)||void 0===a?void 0:a.y})}}}class qt extends et{constructor(t,i){var n;super(t.layer,new Set([t])),this.element=t,this.parameters={aspect:null!==(n=null==i?void 0:i.aspect)&&void 0!==n?n:this.element.width/this.element.height,power:ht(null==i?void 0:i.power),rule:at(null==i?void 0:i.rule),orientation:ot(null==i?void 0:i.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.element[B]).plus(new E(this.element[H]).multiply(-this.parameters.aspect));this.constraint=new P(t,dt(this.parameters.rule),0,ut(this.parameters.power)),this.layer[_](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[N](this,this.constraint),this.constraint=void 0)}}class Wt extends et{constructor(t,i,n){var s,o,e;Ht(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={isStrict:null!==(s=null==n?void 0:n.isStrict)&&void 0!==s?s:1,horizontalAnchor:null!==(o=null==n?void 0:n.horizontalAnchor)&&void 0!==o?o:.5,verticalAnchor:null!==(e=null==n?void 0:n.verticalAnchor)&&void 0!==e?e:.5,orientation:ot(null==n?void 0:n.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){this.constraintX=new P(new E(this.elementOne[j]).plus(new E(this.elementOne[B]).multiply(this.parameters.horizontalAnchor)),O.Eq,new E(this.elementTwo[j]).plus(new E(this.elementTwo[B]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new P(new E(this.elementOne[U]).plus(new E(this.elementOne[H]).multiply(this.parameters.verticalAnchor)),O.Eq,new E(this.elementTwo[U]).plus(new E(this.elementTwo[H]).multiply(this.parameters.verticalAnchor))),this.constraintW=new P(new E(this.elementOne[B]),O.Le,new E(this.elementTwo[B])),this.constraintH=new P(new E(this.elementOne[H]),O.Le,new E(this.elementTwo[H])),this.layer[_](this,this.constraintX),this.layer[_](this,this.constraintY),this.layer[_](this,this.constraintW),this.layer[_](this,this.constraintH),this.parameters.isStrict||(this.constraintStrict=new P(new E(this.elementOne[H]),O.Eq,new E(this.elementTwo[H]),T.strong),this.layer[_](this,this.constraintStrict))}destroyConstraints(){this.constraintX&&(this.layer[N](this,this.constraintX),this.constraintX=void 0),this.constraintY&&(this.layer[N](this,this.constraintY),this.constraintY=void 0),this.constraintW&&(this.layer[N](this,this.constraintW),this.constraintW=void 0),this.constraintH&&(this.layer[N](this,this.constraintH),this.constraintH=void 0),this.constraintStrict&&(this.layer[N](this,this.constraintStrict),this.constraintStrict=void 0)}}function Yt(t){return null!==t&&"object"==typeof t&&("x"in t&&"number"==typeof t.x||"y"in t&&"number"==typeof t.y)}function Gt(t){return null!==t&&"object"==typeof t&&("x"in t&&rt(t.x)||"y"in t&&rt(t.y))}function Qt(t){return null!==t&&"object"==typeof t&&("x"in t&&lt(t.x)||"y"in t&&lt(t.y))}function Jt(t){return null!==t&&"object"==typeof t&&"elementOne"in t&&"elementTwo"in t&&(t.elementOne instanceof jt||t.elementOne instanceof Bt)&&t.elementTwo instanceof jt}function Zt(t){return Jt(t)&&"distance"in t&&Yt(t.distance)&&(!("anchorOne"in t)||"anchorOne"in t&&Yt(t.anchorOne))&&(!("anchorTwo"in t)||"anchorTwo"in t&&Yt(t.anchorTwo))&&(!("power"in t)||Gt(t.power))&&(!("rule"in t)||Qt(t.rule))&&(!("orientation"in t)||st(t.orientation))}function ti(t){return Jt(t)&&"proportion"in t&&Yt(t.proportion)&&(!("power"in t)||Gt(t.power))&&(!("rule"in t)||Qt(t.rule))&&(!("orientation"in t)||st(t.orientation))}function ii(t){return Jt(t)&&"isStrict"in t&&"boolean"==typeof t.isStrict&&(!("anchor"in t)||"anchor"in t&&Yt(t.anchor))}function ni(t){return null!==t&&"object"==typeof t&&"element"in t&&t.element instanceof jt&&(!("power"in t)||rt(t.power))&&(!("rule"in t)||lt(t.rule))}function si(t){return ni(t)&&"height"in t&&"number"==typeof t.height}function oi(t){return ni(t)&&"keepAspect"in t&&"boolean"==typeof t.keepAspect}function ei(t){return ni(t)&&"keepSize"in t&&"boolean"==typeof t.keepSize}class ri{static fromDescription(t){const i=t instanceof Map?t.entries():Object.entries(t),n=new Map;for(const[t,o]of i){if(n.has(t))throw Error(`Duplicate constraint key "${t}" - each constraint must have a unique identifier`);if(ni(s=o)&&"width"in s&&"number"==typeof s.width)ri.buildWidthConstraint(t,o,n);else if(si(o))ri.buildHeightConstraint(t,o,n);else if(oi(o))ri.buildKeepAspectConstraint(t,o,n);else if(ei(o))ri.buildKeepSizeConstraint(t,o,n);else if(Zt(o))ri.buildDistanceConstraint(t,o,n);else if(ti(o))ri.buildProportionalConstraint(t,o,n);else{if(!ii(o))throw Error(`Invalid constraint type for "${t}". Expected one of: Width, Height, KeepAspect, KeepSize, Distance, Proportional, or Cover constraint`);ri.buildCoverConstraint(t,o,n)}}var s;return Object.fromEntries(n)}static buildWidthConstraint(t,i,n){n.set(t,new Nt(i.element,{width:i.width,power:i.power,rule:i.rule,orientation:i.orientation}))}static buildHeightConstraint(t,i,n){n.set(t,new ct(i.element,{height:i.height,power:i.power,rule:i.rule,orientation:i.orientation}))}static buildKeepAspectConstraint(t,i,n){n.set(t,new qt(i.element,{power:i.power,rule:i.rule,orientation:i.orientation}))}static buildKeepSizeConstraint(t,i,n){const s=t.replace(/(KeepSize|Keep)$/,"")+"KeepWidth",o=t.replace(/(KeepSize|Keep)$/,"")+"KeepHeight";n.set(s,new Nt(i.element,{power:i.power,rule:i.rule,orientation:i.orientation})),n.set(o,new ct(i.element,{power:i.power,rule:i.rule,orientation:i.orientation}))}static buildDistanceConstraint(t,i,n){var s,o,e,r,h,u,l,a;if("number"==typeof i.distance.x){const h=t.replace(/(HorizontalDistance|Distance)$/,"")+"HorizontalDistance";n.set(h,new Lt(i.elementOne,i.elementTwo,{distance:i.distance.x,anchorOne:null===(s=i.anchorOne)||void 0===s?void 0:s.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 s=t.replace(/(VerticalDistance|Distance)$/,"")+"VerticalDistance";n.set(s,new Kt(i.elementOne,i.elementTwo,{distance:i.distance.y,anchorOne:null===(h=i.anchorOne)||void 0===h?void 0:h.y,anchorTwo:null===(u=i.anchorTwo)||void 0===u?void 0:u.y,power:null===(l=i.power)||void 0===l?void 0:l.y,rule:null===(a=i.rule)||void 0===a?void 0:a.y,orientation:i.orientation}))}}static buildProportionalConstraint(t,i,n){var s,o,e,r;if("number"==typeof i.proportion.x){const e=t.replace(/(HorizontalProportional|HorizontalProportion|Proportional|Proportion)$/,"")+"HorizontalProportion";n.set(e,new Rt(i.elementOne,i.elementTwo,{proportion:i.proportion.x,power:null===(s=i.power)||void 0===s?void 0:s.x,rule:null===(o=i.rule)||void 0===o?void 0:o.x,orientation:i.orientation}))}if("number"==typeof i.proportion.y){const s=t.replace(/(VerticalProportional|VerticalProportion|Proportional|Proportion)$/,"")+"VerticalProportion";n.set(s,new _t(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,n){var s,o;n.set(t,new Wt(i.elementOne,i.elementTwo,{isStrict:i.isStrict,horizontalAnchor:null===(s=i.anchor)||void 0===s?void 0:s.x,verticalAnchor:null===(o=i.anchor)||void 0===o?void 0:o.y}))}}var hi;(t=>{t[t.FROM_LEFT_TOP=0]="FROM_LEFT_TOP",t[t.FROM_LEFT_BOTTOM=1]="FROM_LEFT_BOTTOM"})(hi||(hi={}));class ui{static build(t,i,n,s={}){var o;const e=null!==(o=s.direction)&&void 0!==o?o:hi.FROM_LEFT_TOP,r=[],h=[];r.push(new Lt(t,i,{anchorOne:0,anchorTwo:0,distance:0,power:s.power,orientation:s.orientation}),new Lt(t,n,{anchorOne:1,anchorTwo:1,distance:0,power:s.power,orientation:s.orientation}));const u=e===hi.FROM_LEFT_TOP?1:0,l=e===hi.FROM_LEFT_TOP?0:1;return h.push(new Kt(t,i,{anchorOne:u,anchorTwo:u,distance:0,power:s.power,orientation:s.orientation}),new Kt(t,n,{anchorOne:l,anchorTwo:l,distance:0,power:s.power,orientation:s.orientation})),{horizontalDistances:r,verticalDistances:h}}}class li{static buildHorizontal(t,i){return this.buildStack(t,i,{distanceConstraint:Lt,proportionConstraint:Rt,centerDistanceConstraint:Kt})}static buildVertical(t,i){return this.buildStack(t,i,{distanceConstraint:Kt,proportionConstraint:_t,centerDistanceConstraint:Lt})}static buildStack(t,i,n){const s=[],o=[],e=[];for(let r=0;r<t.length-1;r++){const h=t[r],u=t[r+1];s.push(new n.distanceConstraint(h,u,{anchorOne:1,anchorTwo:0,distance:i.distance,power:i.power,orientation:i.orientation})),0!=i.keepProportions&&o.push(new n.proportionConstraint(h,u,{power:i.power,orientation:i.orientation})),0!=i.keepAlignment&&e.push(new n.centerDistanceConstraint(h,u,{power:i.power,anchorOne:0,anchorTwo:0,orientation:i.orientation}))}return{distanceConstraints:s,proportionConstraints:o,alignmentConstraints:e}}}class ai extends jt{constructor(t,i=1e3,n=1e3){super(t,new w,0,0,i,n),this.flushTransform()}[J](){this.flushTransform()}}class di extends jt{constructor(t,i){var n,s;const o=null===(n=i.image)||void 0===n?void 0:n.width,e=null===(s=i.image)||void 0===s?void 0:s.height;Vt(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 bt(i);super(t,new u(xt,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()}[J](t){this.object.material=this.composer.compose(t,this.textureInternal.image.width,this.textureInternal.image.height,this.material),this.flushTransform()}}class ci extends s{constructor(t,i){super({uniforms:o.merge([{background:{value:i},foreground:{value:t},progress:{value:1},backgroundColor:{value:new e(1,1,1)},foregroundColor:{value:new e(1,1,1)},color:{value:new e(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 vi extends jt{constructor(t,i,s,o={}){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;Vt(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&&Vt(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(xt,f);o.progress&&f.setProgress(o.progress),o.isForegroundDirection&&f.setIsForwardDirection(o.isForegroundDirection),o.angle&&f.setAngle(n.degToRad(o.angle)),o.color&&f.setColor(o.color),o.opacity&&f.setOpacity(o.opacity),o.backgroundColor&&f.setBackgroundColor(o.backgroundColor),o.foregroundColor&&f.setForegroundColor(o.foregroundColor),o.backgroundOpacity&&f.setBackgroundOpacity(o.backgroundOpacity),o.foregroundOpacity&&f.setForegroundOpacity(o.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 n.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(n.degToRad(t)),this.composer.requestUpdate()}set isForwardDirection(t){this.material.setIsForwardDirection(t),this.composer.requestUpdate()}destroy(){this.material.dispose(),super.destroy()}[J](t){this.object.material=this.composer.compose(t,this.imageWidth,this.imageHeight,this.material),this.flushTransform()}}function fi(t,i){var n,s,o,e,r,h,u,l,a,d,c,v,f,w,p,g,m,y,b,x,C,S,E,k,O,T,M,P;const D=Math.max(null!==(s=null!==(n=null==t?void 0:t.fontSize)&&void 0!==n?n:null==i?void 0:i.fontSize)&&void 0!==s?s:16,1),I=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*D,$=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),z=Math.max(null!==(l=null!==(u=null==t?void 0:t.strokeWidth)&&void 0!==u?u:null==i?void 0:i.strokeWidth)&&void 0!==l?l: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:D,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:I,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:$,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:z}}function wi(t){return t.match(/\S+|\s|\n/g)||[]}function pi(t,i,n){if(t.font=`${n.fontStyle} ${n.fontWeight} ${n.fontSize}px ${n.fontFamily}`,"\n"===i)return{width:0,height:n.lineHeight,baseline:0,lineHeight:n.lineHeight};const s=t.measureText(i),o=s.width,e=Math.ceil(s.actualBoundingBoxAscent+s.actualBoundingBoxDescent);return{width:Math.ceil(o),height:e,baseline:s.actualBoundingBoxDescent,lineHeight:n.lineHeight}}function gi(t,i,n,s,o){o.font=`${s.fontStyle} ${s.fontWeight} ${s.fontSize}px ${s.fontFamily}`,s.enableShadow&&(o.shadowOffsetX=s.shadowOffsetX,o.shadowOffsetY=s.shadowOffsetY,o.shadowBlur=s.shadowBlur,o.shadowColor=s.shadowColor),s.enableStroke&&(o.strokeStyle=s.strokeColor,o.lineWidth=s.strokeWidth,o.strokeText(n,t,i)),o.fillStyle=s.color,o.fillText(n,t,i)}class mi extends jt{constructor(t,i,n={}){var s;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,s=i?t:t.text,o=fi(i?void 0:t.style,n.defaultStyle);for(const t of wi(s)){const i=pi(e,t,o);r.push({text:t,style:o,metrics:i})}}const l=((t,i)=>{const n=[];let s=[],o=0,e=0,r=0,h=0;for(const u of i)"\n"!==u.text?o+u.metrics.width<=t||0===s.length?(s.push(u),o+=u.metrics.width,e=Math.max(e,u.metrics.height),r=Math.max(r,u.metrics.baseline),h=Math.max(h,u.metrics.lineHeight)):(n.push({chunks:s,width:o,height:e,baseline:r,lineHeight:h}),s=[u],o=u.metrics.width,e=u.metrics.height,r=u.metrics.baseline,h=u.metrics.lineHeight):(s.length>0&&n.push({chunks:s,width:o,height:e,baseline:r,lineHeight:h}),s=[],o=0,e=0,r=0,h=0);return s.length>0&&n.push({chunks:s,width:o,height:e,baseline:r,lineHeight:h}),n})(null!==(s=n.maxWidth)&&void 0!==s?s:1024,r),a=(t=>{if(0===t.length)return{width:0,height:0};const i=Math.max(...t.map((t=>t.width)));let n=0;for(let i=0;i<t.length;i++){const s=t[i];n+=0===i?s.height:s.lineHeight,i===t.length-1&&(n+=s.baseline)}return{width:i,height:n}})(l),d=(t=>{var i,n,s,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!==(n=null==t?void 0:t.right)&&void 0!==n?n:0,0),top:Math.max(null!==(s=null==t?void 0:t.top)&&void 0!==s?s:0,0),bottom:Math.max(null!==(o=null==t?void 0:t.bottom)&&void 0!==o?o:0,0)}})(n.padding);o.width=a.width+d.left+d.right,o.height=a.height+d.top+d.bottom;const c=new p(o),v=new bt(c);super(t,new u(xt,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,n,s)=>{let o=this.padding.top;for(let t=0;t<n.length;t++){const e=n[t];let r=i;o+=0===t?e.height:e.lineHeight;for(const t of e.chunks)gi(r,o,t.text,t.style,s),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[W](this,this[H],this.width/((this.textBlockSize.width+this.padding.left+this.padding.right)/(this.textBlockSize.height+this.padding.top+this.padding.bottom))))}[J](t){this.object.material=this.composer.compose(t,this.texture.image.width,this.texture.image.height,this.material),this.flushTransform()}}function yi(t){return null!==t&&"object"==typeof t&&"background"in t&&t.background instanceof g&&"foreground"in t&&t.foreground instanceof g}function bi(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text}function xi(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 Ci(t){return!(null===t||"object"!=typeof t||"width"in t&&"number"!=typeof t.width||"height"in t&&"number"!=typeof t.height)}class Si{static fromDescription(t,i){const n=i instanceof Map?i.entries():Object.entries(i),s=new Map;for(const[i,e]of n){if(s.has(i))throw Error(`Duplicate element key "${i}" - each UI element must have a unique identifier`);let n;if(e instanceof g)n=new di(t,e);else if(null!==(o=e)&&"object"==typeof o&&"texture"in o&&o.texture instanceof g)n=new di(t,e.texture);else if("string"==typeof e)n=new mi(t,[e]);else if(yi(e))n=new vi(t,e.background,e.foreground);else if(bi(e))n=new mi(t,[e.text],{defaultStyle:e.style});else if(xi(e))n=new mi(t,e.spans,{defaultStyle:e.defaultStyle});else{if(!Ci(e))throw Error(`Invalid UI element type for "${i}". Expected one of: Texture, UIImage, String, UITextDescription, or UITextEnhancedDescription`);n=new ai(t,e.width,e.height)}s.set(i,n)}var o;return Object.fromEntries(s)}}class Ei extends et{constructor(t,i,n){var s,o,e;super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,Ht(t,i),this.parameters={isStrict:null!==(s=null==n?void 0:n.isStrict)&&void 0!==s?s:1,horizontalAnchor:null!==(o=null==n?void 0:n.horizontalAnchor)&&void 0!==o?o:.5,verticalAnchor:null!==(e=null==n?void 0:n.verticalAnchor)&&void 0!==e?e:.5,orientation:ot(null==n?void 0:n.orientation)},this.parameters.orientation!==tt.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Y](t){this.parameters.orientation!==tt.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[G](t){this.parameters.orientation!==tt.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){this.constraintX=new P(new E(this.elementOne[j]).plus(new E(this.elementOne[B]).multiply(this.parameters.horizontalAnchor)),O.Eq,new E(this.elementTwo[j]).plus(new E(this.elementTwo[B]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new P(new E(this.elementOne[U]).plus(new E(this.elementOne[H]).multiply(this.parameters.verticalAnchor)),O.Eq,new E(this.elementTwo[U]).plus(new E(this.elementTwo[H]).multiply(this.parameters.verticalAnchor))),this.constraintW=new P(new E(this.elementOne[B]),O.Ge,new E(this.elementTwo[B])),this.constraintH=new P(new E(this.elementOne[H]),O.Ge,new E(this.elementTwo[H])),this.layer[_](this,this.constraintX),this.layer[_](this,this.constraintY),this.layer[_](this,this.constraintW),this.layer[_](this,this.constraintH),0!=this.parameters.isStrict&&(this.constraintStrict=new P(new E(this.elementOne[H]),O.Eq,new E(this.elementTwo[H]),T.strong),this.layer[_](this,this.constraintStrict))}destroyConstraints(){this.constraintX&&(this.layer[N](this,this.constraintX),this.constraintX=void 0),this.constraintY&&(this.layer[N](this,this.constraintY),this.constraintY=void 0),this.constraintW&&(this.layer[N](this,this.constraintW),this.constraintW=void 0),this.constraintH&&(this.layer[N](this,this.constraintH),this.constraintH=void 0),this.constraintStrict&&(this.layer[N](this,this.constraintStrict),this.constraintStrict=void 0)}}const ki=512;class Oi extends jt{constructor(t,i){var n,s;const{resolution:o=ki}=i,e="number"==typeof o?o:o.x,r="number"==typeof o?o:o.y;Vt(e,r,`Invalid resolution dimensions: width (${e}) and height (${r}) must both be greater than 0.`);const l=new a(e,r,{format:v,minFilter:c,magFilter:c,type:d,depthBuffer:0,stencilBuffer:0}),f=new bt(l.texture);super(t,new u(xt,f),0,0,e,r),this.needsRenderInternal=0,this.sceneInternal=null!==(n=i.scene)&&void 0!==n?n:new h,this.cameraInternal=null!==(s=i.camera)&&void 0!==s?s:new m,i.renderedByDefault&&(this.needsRenderInternal=1),this.resolutionX=e,this.resolutionY=r,this.renderTarget=l,this.material=f,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 resolution(){return new t(this.resolutionX,this.resolutionY)}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}set camera(t){this.cameraInternal=t}set resolution(t){const i="number"==typeof t?t:t.x,n="number"==typeof t?t:t.y;this.renderTarget.width===i&&this.renderTarget.height===n||(this.resolutionX=i,this.resolutionY=n,this.renderTarget.setSize(i,n))}destroy(){this.material.dispose(),this.renderTarget.dispose(),super.destroy()}requestRender(){this.needsRenderInternal=1,this.composer.requestUpdate()}[J](t){this.needsRenderInternal&&(t.setClearColor(0,1),t.setRenderTarget(this.renderTarget),t.clear(1,1,0),t.render(this.sceneInternal,this.cameraInternal)),this.object.material=this.composer.compose(t,this.resolutionX,this.resolutionY,this.material),this.flushTransform()}}class Ti extends Bt{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!==pt.INTERACTIVE)return;const i=t.target instanceof HTMLElement?t.target.getBoundingClientRect():null,n=i?t.clientX-i.left:t.clientX,s=i?i.bottom-t.clientY:window.innerHeight-t.clientY,o=this.calculateScale();this.clickInternal(n*o,s*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 Mi extends Bt{click(t,i){this.clickInternal(t,i)}resize(t,i){this.resizeInternal(t,i)}}class Pi{}export{qt as UIAspectConstraint,pt as UIBehavior,Xt as UIConstraint2DBuilder,ri as UIConstraintBuilder,ui as UIConstraintContainerBuilder,hi as UIConstraintContainerDirection,it as UIConstraintPower,nt as UIConstraintRule,li as UIConstraintStackBuilder,Wt as UICoverConstraint,ai as UIDummy,Si as UIElementBuilder,It as UIElementEvent,Ei as UIFitConstraint,Ti as UIFullScreenLayer,Et as UIFullScreenQuad,ct as UIHeightConstraint,Lt as UIHorizontalDistanceConstraint,Rt as UIHorizontalProportionConstraint,di as UIImage,Mi as UIManualLayer,tt as UIOrientation,Pi as UIPass,vi as UIProgress,Oi as UIScene,mi as UIText,Kt as UIVerticalDistanceConstraint,_t as UIVerticalProportionConstraint,Nt as UIWidthConstraint};
2
2
  //# sourceMappingURL=index.js.map