laymur 0.1.26 → 0.1.27

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.
@@ -1,16 +1,32 @@
1
- import type { Texture } from "three";
1
+ import type { Color, Texture, WebGLRenderer } from "three";
2
2
  import type { UILayer } from "../Layers/UILayer";
3
3
  import { renderSymbol } from "../Miscellaneous/symbols";
4
4
  import { UIElement } from "./UIElement";
5
5
  export declare class UIProgress extends UIElement {
6
6
  private readonly material;
7
- private readonly textureBackground;
8
- private readonly textureForeground;
9
7
  constructor(layer: UILayer, textureBackground: Texture, textureForeground: Texture);
10
- get background(): Texture;
11
- get foreground(): Texture;
12
8
  get progress(): number;
9
+ get backgroundTexture(): Texture;
10
+ get foregroundTexture(): Texture;
11
+ get backgroundColor(): Color;
12
+ get foregroundColor(): Color;
13
+ get color(): Color;
14
+ get backgroundOpacity(): number;
15
+ get foregroundOpacity(): number;
16
+ get commonOpacity(): number;
17
+ get angle(): number;
18
+ get isForwardDirection(): boolean;
13
19
  set progress(value: number);
20
+ set backgroundTexture(value: Texture);
21
+ set foregroundTexture(value: Texture);
22
+ set backgroundColor(value: Color);
23
+ set foregroundColor(value: Color);
24
+ set color(value: Color);
25
+ set backgroundOpacity(value: number);
26
+ set foregroundOpacity(value: number);
27
+ set commonOpacity(value: number);
28
+ set angle(value: number);
29
+ set isForwardDirection(value: boolean);
14
30
  destroy(): void;
15
- [renderSymbol](): void;
31
+ [renderSymbol](renderer: WebGLRenderer): void;
16
32
  }
@@ -0,0 +1,7 @@
1
+ import type { Texture } from "three";
2
+ import { ShaderMaterial } from "three";
3
+ export declare class UIClearMaterial extends ShaderMaterial {
4
+ constructor(map?: Texture);
5
+ getTexture(): Texture;
6
+ setTexture(value: Texture): void;
7
+ }
@@ -0,0 +1,27 @@
1
+ import type { Texture } from "three";
2
+ import { Color, ShaderMaterial } from "three";
3
+ export declare class UIProgressMaterial extends ShaderMaterial {
4
+ constructor(backgroundTexture: Texture, foregroundTexture: Texture);
5
+ getProgress(): number;
6
+ getBackgroundTexture(): Texture;
7
+ getForegroundTexture(): Texture;
8
+ getBackgroundColor(): Color;
9
+ getForegroundColor(): Color;
10
+ getColor(): Color;
11
+ getBackgroundOpacity(): number;
12
+ getForegroundOpacity(): number;
13
+ getOpacity(): number;
14
+ getAngle(): number;
15
+ getIsForwardDirection(): boolean;
16
+ setProgress(value: number): void;
17
+ setBackgroundTexture(value: Texture): void;
18
+ setForegroundTexture(value: Texture): void;
19
+ setBackgroundColor(value: Color): void;
20
+ setForegroundColor(value: Color): void;
21
+ setColor(value: Color): void;
22
+ setBackgroundOpacity(value: number): void;
23
+ setForegroundOpacity(value: number): void;
24
+ setOpacity(value: number): void;
25
+ setAngle(value: number): void;
26
+ setIsForwardDirection(value: boolean): void;
27
+ }
@@ -1,13 +1,20 @@
1
- import type { Texture, WebGLRenderer } from "three";
1
+ import type { Material, Texture, WebGLRenderer } from "three";
2
+ import { UIClearMaterial } from "../Materials/UIClearMaterial";
2
3
  import type { UIPass } from "./UIPass";
3
4
  export declare class UIComposer {
5
+ readonly defaultMaterial: UIClearMaterial;
4
6
  readonly passes: UIPass[];
5
- private readonly drawPass;
6
7
  private fromRenderTarget;
7
8
  private toRenderTarget;
9
+ private readonly screen;
10
+ private needsUpdateInternal;
8
11
  constructor();
12
+ get needsUpdate(): boolean;
13
+ requestUpdate(): void;
9
14
  calculatePadding(): number;
10
- render(renderer: WebGLRenderer, texture: Texture): Texture;
15
+ renderByMaterial(renderer: WebGLRenderer, width: number, height: number, material: Material): Material;
16
+ renderByTexture(renderer: WebGLRenderer, texture: Texture): Texture;
11
17
  destroy(): void;
18
+ private setPadding;
12
19
  private reverseTargets;
13
20
  }
@@ -1,16 +1,16 @@
1
- import type { ShaderMaterial, WebGLRenderer } from "three";
1
+ import type { Material, WebGLRenderer } from "three";
2
2
  export declare class UIFullScreenQuad {
3
- private materialInternal;
3
+ private materialInternal?;
4
4
  private paddingHorizontalInternal;
5
5
  private paddingVerticalInternal;
6
6
  private readonly camera;
7
- constructor(materialInternal: ShaderMaterial, paddingHorizontalInternal?: number, paddingVerticalInternal?: number);
7
+ constructor(materialInternal?: Material | undefined, paddingHorizontalInternal?: number, paddingVerticalInternal?: number);
8
8
  get paddingHorizontal(): number;
9
9
  get paddingVertical(): number;
10
- get material(): ShaderMaterial;
10
+ get material(): Material | undefined;
11
11
  set paddingHorizontal(value: number);
12
12
  set paddingVertical(value: number);
13
- set material(value: ShaderMaterial);
14
- render(renderer: WebGLRenderer): void;
13
+ set material(value: Material);
14
+ render(renderer: WebGLRenderer, material?: Material): void;
15
15
  private updateCameraTransform;
16
16
  }
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{Vector2 as t,Box2 as i,MathUtils as n,PlaneGeometry as s,Scene as o,Mesh as r,OrthographicCamera as e,ShaderMaterial as h,UniformsUtils as l,Matrix3 as u,Color as a,WebGLRenderTarget as c,UnsignedByteType as d,LinearFilter as v,RGBAFormat as f,Object3D as w,CanvasTexture as p,Texture as m}from"three";function g(){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 y(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 y(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}(),y=function(){function t(t,i){this.first=t,this.second=i}return t.prototype.copy=function(){return new t(this.first,this.second)},t}(),x=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=C(arguments);this.l=t.terms,this.u=t.constant}return t.prototype.terms=function(){return this.l},t.prototype.constant=function(){return this.u},t.prototype.value=function(){for(var t=this.u,i=0,n=this.l.size();i<n;i++){var s=this.l.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.l.size()},t.prototype.toString=function(){var t=this.l.array.map((t=>t.second+"*"+t.first)).join(" + ");return this.isConstant()||0===this.u||(t+=" + "),t+this.u},t}();function C(t){for(var i=0,n=()=>0,s=g(),o=0,r=t.length;o<r;++o){var e=t[o];if("number"==typeof e)i+=e;else if(e instanceof x)s.setDefault(e,n).second+=1;else if(e instanceof E){i+=e.constant();for(var h=0,l=(d=e.terms()).size();h<l;h++){var u=d.itemAt(h);s.setDefault(u.first,n).second+=u.second}}else{if(!(e instanceof Array))throw Error("invalid Expression argument: "+e);if(2!==e.length)throw Error("array must have length 2");var a=e[0],c=e[1];if("number"!=typeof a)throw Error("array item 0 must be a number");if(c instanceof x)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,l=(d=c.terms()).size();h<l;h++)u=d.itemAt(h),s.setDefault(u.first,n).second+=u.second*a}}}return{terms:s,constant:i}}var M,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"})(M||(M={}));var O,z=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,$=function(){function t(){this.S=g(),this.C=g(),this.M=g(),this.T=g(),this.O=[],this.D=new U,this.$=null,this.k=0}return t.prototype.createConstraint=function(t,i,n,s){void 0===s&&(s=T.required);var o=new z(t,i,n,s);return this.addConstraint(o),o},t.prototype.addConstraint=function(t){if(void 0!==this.S.find(t))throw Error("duplicate constraint");var i=this.I(t),n=i.row,s=i.tag,o=this.P(n,s);if(o.type()===O.Invalid&&n.allDummies()){if(!k(n.constant()))throw Error("unsatisfiable constraint");o=s.marker}if(o.type()===O.Invalid){if(!this.U(n))throw Error("unsatisfiable constraint")}else n.solveFor(o),this.V(o,n),this.C.insert(o,n);this.S.insert(t,s),this.j(this.D)},t.prototype.removeConstraint=function(t){var i=this.S.erase(t);if(void 0===i)throw Error("unknown constraint");this.A(t,i.second);var n=i.second.marker,s=this.C.erase(n);if(void 0===s){var o=this.H(n);if(o.type()===O.Invalid)throw Error("failed to find leaving row");(s=this.C.erase(o)).second.solveForEx(o,n),this.V(n,s.second)}this.j(this.D)},t.prototype.hasConstraint=function(t){return this.S.contains(t)},t.prototype.addEditVariable=function(t,i){if(void 0!==this.T.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 z(n,M.Eq,void 0,i);this.addConstraint(s);var o=this.S.find(s).second;this.T.insert(t,{tag:o,constraint:s,constant:0})},t.prototype.removeEditVariable=function(t){var i=this.T.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)},t.prototype.hasEditVariable=function(t){return this.T.contains(t)},t.prototype.suggestValue=function(t,i){var n=this.T.find(t);if(void 0===n)throw Error("unknown edit variable");var s=this.C,o=n.second,r=i-o.constant;o.constant=i;var e=o.tag.marker,h=s.find(e);if(void 0!==h)return h.second.add(-r)<0&&this.O.push(e),void this._();var l=o.tag.other;if(void 0!==(h=s.find(l)))return h.second.add(r)<0&&this.O.push(l),void this._();for(var u=0,a=s.size();u<a;++u){var c=s.itemAt(u),d=c.second,v=d.coefficientFor(e);0!==v&&d.add(r*v)<0&&c.first.type()!==O.External&&this.O.push(c.first)}this._()},t.prototype.updateVariables=function(){for(var t=this.M,i=this.C,n=0,s=t.size();n<s;++n){var o=t.itemAt(n),r=i.find(o.second);o.first.setValue(void 0!==r?r.second.constant():0)}},t.prototype.F=function(t){var i=this;return this.M.setDefault(t,(()=>i.L(O.External))).second},t.prototype.I=function(t){for(var i=t.expression(),n=new U(i.constant()),s=i.terms(),o=0,r=s.size();o<r;++o){var e=s.itemAt(o);if(!k(e.second)){var h=this.F(e.first),l=this.C.find(h);void 0!==l?n.insertRow(l.second,e.second):n.insertSymbol(h,e.second)}}var u=this.D,a=t.strength(),c={marker:P,other:P};switch(t.op()){case M.Le:case M.Ge:var d=t.op()===M.Le?1:-1,v=this.L(O.Slack);if(c.marker=v,n.insertSymbol(v,d),a<T.required){var f=this.L(O.Error);c.other=f,n.insertSymbol(f,-d),u.insertSymbol(f,a)}break;case M.Eq:if(a<T.required){var w=this.L(O.Error),p=this.L(O.Error);c.marker=w,c.other=p,n.insertSymbol(w,-1),n.insertSymbol(p,1),u.insertSymbol(w,a),u.insertSymbol(p,a)}else{var m=this.L(O.Dummy);c.marker=m,n.insertSymbol(m)}}return n.constant()<0&&n.reverseSign(),{row:n,tag:c}},t.prototype.P=(t,i)=>{for(var n=t.cells(),s=0,o=n.size();s<o;++s){var r=n.itemAt(s);if(r.first.type()===O.External)return r.first}var e=i.marker.type();return(e===O.Slack||e===O.Error)&&t.coefficientFor(i.marker)<0?i.marker:((e=i.other.type())===O.Slack||e===O.Error)&&t.coefficientFor(i.other)<0?i.other:P},t.prototype.U=function(t){var i=this.L(O.Slack);this.C.insert(i,t.copy()),this.$=t.copy(),this.j(this.$);var n=k(this.$.constant());this.$=null;var s=this.C.erase(i);if(void 0!==s){var o=s.second;if(o.isConstant())return n;var r=this.B(o);if(r.type()===O.Invalid)return 0;o.solveForEx(i,r),this.V(r,o),this.C.insert(r,o)}for(var e=this.C,h=0,l=e.size();h<l;++h)e.itemAt(h).second.removeSymbol(i);return this.D.removeSymbol(i),n},t.prototype.V=function(t,i){for(var n=this.C,s=0,o=n.size();s<o;++s){var r=n.itemAt(s);r.second.substitute(t,i),r.second.constant()<0&&r.first.type()!==O.External&&this.O.push(r.first)}this.D.substitute(t,i),this.$&&this.$.substitute(t,i)},t.prototype.j=function(t){for(;;){var i=this.K(t);if(i.type()===O.Invalid)return;var n=this.R(i);if(n.type()===O.Invalid)throw Error("the objective is unbounded");var s=this.C.erase(n).second;s.solveForEx(n,i),this.V(i,s),this.C.insert(i,s)}},t.prototype._=function(){for(var t=this.C,i=this.O;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()===O.Invalid)throw Error("dual optimize failed");var r=s.second;t.erase(n),r.solveForEx(n,o),this.V(o,r),t.insert(o,r)}}},t.prototype.K=t=>{for(var i=t.cells(),n=0,s=i.size();n<s;++n){var o=i.itemAt(n),r=o.first;if(o.second<0&&r.type()!==O.Dummy)return r}return P},t.prototype.N=function(t){for(var i=Number.MAX_VALUE,n=P,s=t.cells(),o=0,r=s.size();o<r;++o){var e=s.itemAt(o),h=e.first,l=e.second;if(l>0&&h.type()!==O.Dummy){var u=this.D.coefficientFor(h)/l;u<i&&(i=u,n=h)}}return n},t.prototype.R=function(t){for(var i=Number.MAX_VALUE,n=P,s=this.C,o=0,r=s.size();o<r;++o){var e=s.itemAt(o),h=e.first;if(h.type()!==O.External){var l=e.second,u=l.coefficientFor(t);if(u<0){var a=-l.constant()/u;a<i&&(i=a,n=h)}}}return n},t.prototype.H=function(t){for(var i=Number.MAX_VALUE,n=i,s=i,o=P,r=o,e=o,h=o,l=this.C,u=0,a=l.size();u<a;++u){var c=l.itemAt(u),d=c.second,v=d.coefficientFor(t);if(0!==v){var f=c.first;if(f.type()===O.External)h=f;else if(v<0)(w=-d.constant()/v)<n&&(n=w,r=f);else{var w;(w=d.constant()/v)<s&&(s=w,e=f)}}}return r!==o?r:e!==o?e:h},t.prototype.A=function(t,i){i.marker.type()===O.Error&&this.W(i.marker,t.strength()),i.other.type()===O.Error&&this.W(i.other,t.strength())},t.prototype.W=function(t,i){var n=this.C.find(t);void 0!==n?this.D.insertRow(n.second,-i):this.D.insertSymbol(t,-i)},t.prototype.B=t=>{for(var i=t.cells(),n=0,s=i.size();n<s;++n){var o=i.itemAt(n),r=o.first.type();if(r===O.Slack||r===O.Error)return o.first}return P},t.prototype.L=function(t){return new I(t,this.k++)},t}();function k(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"})(O||(O={}));var I=function(){function t(t,i){this.o=i,this.Y=t}return t.prototype.id=function(){return this.o},t.prototype.type=function(){return this.Y},t}(),P=new I(O.Invalid,-1),U=function(){function t(t){void 0===t&&(t=0),this.X=g(),this.u=t}return t.prototype.cells=function(){return this.X},t.prototype.constant=function(){return this.u},t.prototype.isConstant=function(){return this.X.empty()},t.prototype.allDummies=function(){for(var t=this.X,i=0,n=t.size();i<n;++i)if(t.itemAt(i).first.type()!==O.Dummy)return 0;return 1},t.prototype.copy=function(){var i=new t(this.u);return i.X=this.X.copy(),i},t.prototype.add=function(t){return this.u+=t},t.prototype.insertSymbol=function(t,i){void 0===i&&(i=1),k(this.X.setDefault(t,(()=>0)).second+=i)&&this.X.erase(t)},t.prototype.insertRow=function(t,i){void 0===i&&(i=1),this.u+=t.u*i;for(var n=t.X,s=0,o=n.size();s<o;++s){var r=n.itemAt(s);this.insertSymbol(r.first,r.second*i)}},t.prototype.removeSymbol=function(t){this.X.erase(t)},t.prototype.reverseSign=function(){this.u=-this.u;for(var t=this.X,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.X,n=-1/i.erase(t).second;this.u*=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.X.find(t);return void 0!==i?i.second:0},t.prototype.substitute=function(t,i){var n=this.X.erase(t);void 0!==n&&this.insertRow(i,n.second)},t}();const V=Symbol("xSymbol"),j=Symbol("ySymbol"),A=Symbol("widthSymbol"),H=Symbol("heightSymbol"),_=Symbol("addUIElementSymbol"),F=Symbol("removeUIElementSymbol"),L=Symbol("addConstraintSymbol"),B=Symbol("removeUIConstraintSymbol"),K=Symbol("addConstraintSymbol"),R=Symbol("removeConstraintSymbol"),N=Symbol("addVariableSymbol"),W=Symbol("removeVariableSymbol"),Y=Symbol("suggestVariableSymbol"),X=Symbol("disableConstraintSymbol"),q=Symbol("enableConstraintSymbol"),G=Symbol("needsRecalculation"),Q=Symbol("renderSymbol"),J=Symbol("clickSymbol");var Z,tt,it;function nt(t){return null!==t&&Object.values(Z).some((i=>i===t))}function st(t){return null!=t?t:Z.ALWAYS}(t=>{t[t.LANDSCAPE=0]="LANDSCAPE",t[t.PORTRAIT=1]="PORTRAIT",t[t.ALWAYS=2]="ALWAYS"})(Z||(Z={}));class ot{constructor(t,i){this.layer=t,this.name="",this.layer[L](this,i)}destroy(){this.layer[B](this)}}function rt(t){return null!==t&&Object.values(tt).some((i=>i===t))}function et(t){return null!=t?t:tt.P0}function ht(t){switch(t){case tt.P0:return T.create(1e3,1e3,1e3);case tt.P1:return T.create(100,0,0);case tt.P2:return T.create(10,0,0);case tt.P3:return T.create(0,100,0);case tt.P4:return T.create(0,10,0);case tt.P5:return T.create(0,0,100);case tt.P6:return T.create(0,0,10);case tt.P7:return T.create(0,0,1);default:return T.create(1e3,1e3,1e3)}}function lt(t){return null!==t&&Object.values(it).some((i=>i===t))}function ut(t){return null!=t?t:it.EQUAL}function at(t){switch(t){case it.EQUAL:return M.Eq;case it.LESS:return M.Le;case it.GREATER:return M.Ge;default:return M.Eq}}(t=>{t[t.P0=0]="P0",t[t.P1=1]="P1",t[t.P2=2]="P2",t[t.P3=3]="P3",t[t.P4=4]="P4",t[t.P5=5]="P5",t[t.P6=6]="P6",t[t.P7=7]="P7"})(tt||(tt={})),(t=>{t[t.EQUAL=2]="EQUAL",t[t.LESS=0]="LESS",t[t.GREATER=1]="GREATER"})(it||(it={}));class ct extends ot{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:et(null==i?void 0:i.power),rule:ut(null==i?void 0:i.rule),orientation:st(null==i?void 0:i.orientation)},this.options.orientation!==Z.ALWAYS&&this.options.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[X](t){this.options.orientation!==Z.ALWAYS&&t!==this.options.orientation&&this.destroyConstraints()}[q](t){this.options.orientation!==Z.ALWAYS&&t===this.options.orientation&&this.buildConstraints()}buildConstraints(){this.constraint=new z(new E(this.element[H]),at(this.options.rule),this.options.height,ht(this.options.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class dt{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 r=this.listeners.get(t);if(r||(r=[],this.listeners.set(t,r)),r.some((t=>t.callback===i&&t.context===n)))throw Error("Event listener already exists");const e={callback:i,context:n,priority:s,once:o};let h=0;for(;h<r.length&&r[h].priority<=s;)h++;r.splice(h,0,e)}}const vt=new t,ft=new i;var wt,pt;(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE"})(wt||(wt={}));const mt=.5;class gt{constructor(){this[pt]=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[G]=1}set y(t){this.positionYInternal=t,this[G]=1}set anchorX(t){this.anchorXInternal=t,this[G]=1}set anchorY(t){this.anchorYInternal=t,this[G]=1}set scaleX(t){this.scaleXInternal=t,this[G]=1}set scaleY(t){this.scaleYInternal=t,this[G]=1}set angle(t){this.rotationInternal=n.degToRad(t),this[G]=1}set rotation(t){this.rotationInternal=t,this[G]=1}reset(){this.positionXInternal=0,this.positionYInternal=0,this.anchorXInternal=mt,this.anchorYInternal=mt,this.scaleXInternal=1,this.scaleYInternal=1,this.rotationInternal=0,this[G]=1}}pt=G;const bt=new s(1,1).translate(.5,.5,0),yt=new o,xt=new r(bt);yt.add(xt);class St{constructor(t,i=0,n=0){this.materialInternal=t,this.paddingHorizontalInternal=i,this.paddingVerticalInternal=n,this.camera=new e(-1,1,1,-1,0,1),this.updateCameraTransform()}get paddingHorizontal(){return this.paddingHorizontalInternal}get paddingVertical(){return this.paddingVerticalInternal}get material(){return this.materialInternal}set paddingHorizontal(t){this.paddingHorizontalInternal!==t&&(this.paddingHorizontalInternal=t,this.updateCameraTransform())}set paddingVertical(t){this.paddingVerticalInternal!==t&&(this.paddingVerticalInternal=t,this.updateCameraTransform())}set material(t){this.materialInternal=t}render(t){xt.material=this.materialInternal,t.render(yt,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 Et{constructor(){this.screen=new St(new h({uniforms:l.merge([{map:{value:null},opacity:{value:1},color:{value:new a(1,1,1)},uvTransform:{value:new u}}]),vertexShader:"\n uniform mat3 uvTransform;\n varying vec2 vUv;\n void main() {\n vUv = (uvTransform * vec3(uv, 1)).xy;\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,fog:0,lights:0}))}destroy(){this.screen.material.dispose()}setPadding(t,i,n){n<=0?(this.screen.paddingHorizontal=0,this.screen.paddingVertical=0):(this.screen.paddingHorizontal=n/t,this.screen.paddingVertical=n/i)}render(t,i){this.screen.material.uniforms.map.value=i,this.screen.material.uniformsNeedUpdate=1,this.screen.render(t)}}class Ct{constructor(){this.passes=[],this.drawPass=new Et;const t={format:f,minFilter:v,magFilter:v,type:d,depthBuffer:0,stencilBuffer:0};this.fromRenderTarget=new c(1,1,t),this.toRenderTarget=new c(1,1,t)}calculatePadding(){return this.passes.reduce(((t,i)=>Math.max(t,i.padding)),0)}render(t,i){if(0===this.passes.length)return i;if(this.passes.every((t=>!t.needsUpdate)))return this.fromRenderTarget.texture;const n=this.calculatePadding(),s=i.image.width,o=i.image.height,r=s+2*n,e=o+2*n;this.fromRenderTarget.setSize(r,e),this.toRenderTarget.setSize(r,e),this.drawPass.setPadding(s,o,n),t.setClearColor(0,0),t.setRenderTarget(this.fromRenderTarget),t.clearColor(),t.setRenderTarget(this.toRenderTarget),t.clearColor(),this.drawPass.render(t,i),this.reverseTargets();for(const i of this.passes)t.setRenderTarget(this.toRenderTarget),t.clearColor(),i.render(t,this.fromRenderTarget.texture,{width:s,height:o,padding:n}),this.reverseTargets();return this.fromRenderTarget.texture}destroy(){this.drawPass.destroy(),this.fromRenderTarget.dispose(),this.toRenderTarget.dispose()}reverseTargets(){const t=this.fromRenderTarget;this.fromRenderTarget=this.toRenderTarget,this.toRenderTarget=t}}var Mt,Tt,Ot,zt,Dt,$t,kt,It,Pt,Ut;(t=>{t.CLICK="click"})($t||($t={}));class Vt extends dt{constructor(t,i,n,s,o,r){super(),this.layer=t,this.object=i,this.name="",this.micro=new gt,this[Mt]=new x("x"),this[Tt]=new x("y"),this[Ot]=new x("width"),this[zt]=new x("height"),this[Dt]=0,this.behaviorInternal=wt.VISIBLE,this.composer=new Ct,this.layer[_](this,this.object),this.layer[N](this,this[V],ht(tt.P7)),this.layer[N](this,this[j],ht(tt.P7)),this.layer[N](this,this[A],ht(tt.P5)),this.layer[N](this,this[H],ht(tt.P5)),this[V].setValue(n),this[j].setValue(s),this[A].setValue(o),this[H].setValue(r),this.layer[Y](this,this[V],n),this.layer[Y](this,this[j],s),this.layer[Y](this,this[A],o),this.layer[Y](this,this[H],r)}get passes(){return this.composer.passes}get x(){return this[V].value()}get y(){return this[j].value()}get width(){return this[A].value()}get height(){return this[H].value()}get zIndex(){return this.object.position.z}get behavior(){return this.behaviorInternal}set x(t){this.layer[Y](this,this[V],t)}set y(t){this.layer[Y](this,this[j],t)}set width(t){this.layer[Y](this,this[A],t)}set height(t){this.layer[Y](this,this[H],t)}set zIndex(t){this.object.position.z=t}set behavior(t){this.behaviorInternal=t,this.object.visible=t!==wt.HIDDEN}destroy(){this.composer.destroy(),this.layer[W](this,this[H]),this.layer[W](this,this[A]),this.layer[W](this,this[j]),this.layer[W](this,this[V]),this.layer[F](this)}[(Mt=V,Tt=j,Ot=A,zt=H,Dt=G,J)](t,i){return this.behavior!==wt.INTERACTIVE?0:(this.flushTransform(),n=this.x,s=this.y,o=this.width,r=this.height,vt.set(t,i),ft.min.set(n,s),ft.max.set(o,r).add(ft.min),ft.containsPoint(vt)?(this.emit($t.CLICK,this),1):0);var n,s,o,r}flushTransform(){(this[G]||this.micro[G])&&(((t,i,n,s,o,r,e)=>{const h=n-e,l=s-e,u=o+2*e,a=r+2*e,c=h+u*i.anchorX,d=l+a*i.anchorY;let v=h-c,f=l-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=u*i.scaleX,t.scale.y=a*i.scaleY})(this.object,this.micro,this.x,this.y,this.width,this.height,this.composer.calculatePadding()),this[G]=0,this.micro[G]=0)}}const jt=new a(0);class At{constructor(){this.behavior=wt.VISIBLE,this[kt]=new x,this[It]=new x,this[Pt]=new x,this[Ut]=new x,this.scene=new o,this.camera=new e,this.solver=new $,this.elements=new Map,this.constraints=new Map,this.orientationPrivate=Z.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()}[(kt=V,It=j,Pt=A,Ut=H,_)](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)}[F](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)}[L](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})}[B](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)}[K](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}[R](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}[N](t,i,n){var s;const o=t instanceof Vt?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}[W](t,i){var n;const s=t instanceof Vt?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}[Y](t,i,n){var s;const o=t instanceof Vt?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 r=o.variables.get(i);if(!r)throw Error("Variable does not exist");r.suggestedValue!==n&&(r.suggestedValue=n,null===(s=this.solver)||void 0===s||s.suggestValue(i,n),this.needsRecalculation=1)}render(t){var i;if(this.behavior===wt.HIDDEN)return;const n=t.getRenderTarget(),s=t.getClearColor(jt),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[G]=1}for(const t of this.elements.keys())t[G]=1;for(const i of this.elements.keys())i[Q](t);t.setRenderTarget(n),t.setClearColor(s),t.setClearAlpha(o),t.render(this.scene,this.camera)}clickInternal(t,i){if(this.behavior!==wt.INTERACTIVE)return;const n=[...this.elements.keys()].filter((t=>t.behavior===wt.INTERACTIVE)).sort(((t,i)=>t.zIndex-i.zIndex));for(const s of n)if(s[J](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,r,e,h,l,u;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===(r=this.solver)||void 0===r||r.removeConstraint(this.constraintH),this.constraintH=void 0),this.constraintX=new z(new E(this[V]),M.Eq,0,T.required),this.constraintY=new z(new E(this[j]),M.Eq,0,T.required),this.constraintW=new z(new E(this[A]),M.Eq,t,T.required),this.constraintH=new z(new E(this[H]),M.Eq,i,T.required),null===(e=this.solver)||void 0===e||e.addConstraint(this.constraintX),null===(h=this.solver)||void 0===h||h.addConstraint(this.constraintY),null===(l=this.solver)||void 0===l||l.addConstraint(this.constraintW),null===(u=this.solver)||void 0===u||u.addConstraint(this.constraintH)}updateOrientation(t,i){const n=this.orientationPrivate;if(this.orientationPrivate=t>i?Z.LANDSCAPE:Z.PORTRAIT,n!==this.orientationPrivate){this.solver=void 0;for(const t of this.constraints.keys())t[q](this.orientationPrivate);for(const t of this.constraints.keys())t[X](this.orientationPrivate);this.solver=new $;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 At?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 _t(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 Ft extends ot{constructor(t,i,n){var s,o,r;Ht(t,i),super(i.layer,new Set(t instanceof Vt?[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!==(r=null==n?void 0:n.distance)&&void 0!==r?r:0,power:et(null==n?void 0:n.power),rule:ut(null==n?void 0:n.rule),orientation:st(null==n?void 0:n.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[X](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.elementOne[V]).plus(new E(this.elementOne[A]).multiply(this.parameters.anchorOne)),i=new E(this.elementTwo[V]).plus(new E(this.elementTwo[A]).multiply(this.parameters.anchorTwo));this.constraint=new z(i.minus(t),at(this.parameters.rule),this.parameters.distance,ht(this.parameters.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Lt extends ot{constructor(t,i,n){var s;Ht(t,i),super(i.layer,new Set(t instanceof Vt?[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:et(null==n?void 0:n.power),rule:ut(null==n?void 0:n.rule),orientation:st(null==n?void 0:n.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[X](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.elementOne[A]).multiply(this.parameters.proportion),i=new E(this.elementTwo[A]);this.constraint=new z(t.minus(i),at(this.parameters.rule),0,ht(this.parameters.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Bt extends ot{constructor(t,i,n){var s,o,r;Ht(t,i),super(i.layer,new Set(t instanceof Vt?[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!==(r=null==n?void 0:n.distance)&&void 0!==r?r:0,power:et(null==n?void 0:n.power),rule:ut(null==n?void 0:n.rule),orientation:st(null==n?void 0:n.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[X](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.elementOne[j]).plus(new E(this.elementOne[H]).multiply(this.parameters.anchorOne)),i=new E(this.elementTwo[j]).plus(new E(this.elementTwo[H]).multiply(this.parameters.anchorTwo));this.constraint=new z(i.minus(t),at(this.parameters.rule),this.parameters.distance,ht(this.parameters.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Kt extends ot{constructor(t,i,n){var s;Ht(t,i),super(i.layer,new Set(t instanceof Vt?[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:et(null==n?void 0:n.power),rule:ut(null==n?void 0:n.rule),orientation:st(null==n?void 0:n.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[X](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.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 z(t.minus(i),at(this.parameters.rule),0,ht(this.parameters.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Rt extends ot{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:et(null==i?void 0:i.power),rule:ut(null==i?void 0:i.rule),orientation:st(null==i?void 0:i.orientation)},this.options.orientation!==Z.ALWAYS&&this.options.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[X](t){this.options.orientation!==Z.ALWAYS&&t!==this.options.orientation&&this.destroyConstraints()}[q](t){this.options.orientation!==Z.ALWAYS&&t===this.options.orientation&&this.buildConstraints()}buildConstraints(){this.constraint=new z(new E(this.element[A]),at(this.options.rule),this.options.width,ht(this.options.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Nt{static size(t,i){var n,s,o,r,e,h,l,u;return{x:new Rt(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===(r=i.orientation)||void 0===r?void 0:r.x}),y:new ct(t,{height:null===(e=i.size)||void 0===e?void 0:e.y,power:null===(h=i.power)||void 0===h?void 0:h.y,rule:null===(l=i.rule)||void 0===l?void 0:l.y,orientation:null===(u=i.orientation)||void 0===u?void 0:u.y})}}static distance(t,i,n){var s,o,r,e,h,l,u,a,c,d,v,f;return{x:new Ft(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===(r=n.distance)||void 0===r?void 0:r.x,power:null===(e=n.power)||void 0===e?void 0:e.x,rule:null===(h=n.rule)||void 0===h?void 0:h.x,orientation:null===(l=n.orientation)||void 0===l?void 0:l.x}),y:new Bt(t,i,{anchorOne:null===(u=n.anchorOne)||void 0===u?void 0:u.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,r,e,h,l,u,a;return{x:new Lt(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===(r=n.rule)||void 0===r?void 0:r.x,orientation:null===(e=n.orientation)||void 0===e?void 0:e.x}),y:new Kt(t,i,{proportion:null===(h=n.proportion)||void 0===h?void 0:h.y,power:null===(l=n.power)||void 0===l?void 0:l.y,rule:null===(u=n.rule)||void 0===u?void 0:u.y,orientation:null===(a=n.orientation)||void 0===a?void 0:a.y})}}}class Wt extends ot{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:et(null==i?void 0:i.power),rule:ut(null==i?void 0:i.rule),orientation:st(null==i?void 0:i.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[X](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new E(this.element[A]).plus(new E(this.element[H]).multiply(-this.parameters.aspect));this.constraint=new z(t,at(this.parameters.rule),0,ht(this.parameters.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Yt extends ot{constructor(t,i,n){var s,o,r;Ht(t,i),super(i.layer,new Set(t instanceof Vt?[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!==(r=null==n?void 0:n.verticalAnchor)&&void 0!==r?r:.5,orientation:st(null==n?void 0:n.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[X](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){this.constraintX=new z(new E(this.elementOne[V]).plus(new E(this.elementOne[A]).multiply(this.parameters.horizontalAnchor)),M.Eq,new E(this.elementTwo[V]).plus(new E(this.elementTwo[A]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new z(new E(this.elementOne[j]).plus(new E(this.elementOne[H]).multiply(this.parameters.verticalAnchor)),M.Eq,new E(this.elementTwo[j]).plus(new E(this.elementTwo[H]).multiply(this.parameters.verticalAnchor))),this.constraintW=new z(new E(this.elementOne[A]),M.Le,new E(this.elementTwo[A])),this.constraintH=new z(new E(this.elementOne[H]),M.Le,new E(this.elementTwo[H])),this.layer[K](this,this.constraintX),this.layer[K](this,this.constraintY),this.layer[K](this,this.constraintW),this.layer[K](this,this.constraintH),this.parameters.isStrict||(this.constraintStrict=new z(new E(this.elementOne[H]),M.Eq,new E(this.elementTwo[H]),T.strong),this.layer[K](this,this.constraintStrict))}destroyConstraints(){this.constraintX&&(this.layer[R](this,this.constraintX),this.constraintX=void 0),this.constraintY&&(this.layer[R](this,this.constraintY),this.constraintY=void 0),this.constraintW&&(this.layer[R](this,this.constraintW),this.constraintW=void 0),this.constraintH&&(this.layer[R](this,this.constraintH),this.constraintH=void 0),this.constraintStrict&&(this.layer[R](this,this.constraintStrict),this.constraintStrict=void 0)}}function Xt(t){return null!==t&&"object"==typeof t&&("x"in t&&"number"==typeof t.x||"y"in t&&"number"==typeof t.y)}function qt(t){return null!==t&&"object"==typeof t&&("x"in t&&rt(t.x)||"y"in t&&rt(t.y))}function Gt(t){return null!==t&&"object"==typeof t&&("x"in t&&lt(t.x)||"y"in t&&lt(t.y))}function Qt(t){return null!==t&&"object"==typeof t&&"elementOne"in t&&"elementTwo"in t&&(t.elementOne instanceof Vt||t.elementOne instanceof At)&&t.elementTwo instanceof Vt}function Jt(t){return Qt(t)&&"distance"in t&&Xt(t.distance)&&(!("anchorOne"in t)||"anchorOne"in t&&Xt(t.anchorOne))&&(!("anchorTwo"in t)||"anchorTwo"in t&&Xt(t.anchorTwo))&&(!("power"in t)||qt(t.power))&&(!("rule"in t)||Gt(t.rule))&&(!("orientation"in t)||nt(t.orientation))}function Zt(t){return Qt(t)&&"proportion"in t&&Xt(t.proportion)&&(!("power"in t)||qt(t.power))&&(!("rule"in t)||Gt(t.rule))&&(!("orientation"in t)||nt(t.orientation))}function ti(t){return Qt(t)&&"isStrict"in t&&"boolean"==typeof t.isStrict&&(!("anchor"in t)||"anchor"in t&&Xt(t.anchor))}function ii(t){return null!==t&&"object"==typeof t&&"element"in t&&t.element instanceof Vt&&(!("power"in t)||rt(t.power))&&(!("rule"in t)||lt(t.rule))}function ni(t){return ii(t)&&"height"in t&&"number"==typeof t.height}function si(t){return ii(t)&&"keepAspect"in t&&"boolean"==typeof t.keepAspect}function oi(t){return ii(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(ii(s=o)&&"width"in s&&"number"==typeof s.width)ri.buildWidthConstraint(t,o,n);else if(ni(o))ri.buildHeightConstraint(t,o,n);else if(si(o))ri.buildKeepAspectConstraint(t,o,n);else if(oi(o))ri.buildKeepSizeConstraint(t,o,n);else if(Jt(o))ri.buildDistanceConstraint(t,o,n);else if(Zt(o))ri.buildProportionalConstraint(t,o,n);else{if(!ti(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 Rt(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 Wt(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 Rt(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,r,e,h,l,u,a;if("number"==typeof i.distance.x){const h=t.replace(/(HorizontalDistance|Distance)$/,"")+"HorizontalDistance";n.set(h,new Ft(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===(r=i.power)||void 0===r?void 0:r.x,rule:null===(e=i.rule)||void 0===e?void 0:e.x,orientation:i.orientation}))}if("number"==typeof i.distance.y){const s=t.replace(/(VerticalDistance|Distance)$/,"")+"VerticalDistance";n.set(s,new Bt(i.elementOne,i.elementTwo,{distance:i.distance.y,anchorOne:null===(h=i.anchorOne)||void 0===h?void 0:h.y,anchorTwo:null===(l=i.anchorTwo)||void 0===l?void 0:l.y,power:null===(u=i.power)||void 0===u?void 0:u.y,rule:null===(a=i.rule)||void 0===a?void 0:a.y,orientation:i.orientation}))}}static buildProportionalConstraint(t,i,n){var s,o,r,e;if("number"==typeof i.proportion.x){const r=t.replace(/(HorizontalProportional|HorizontalProportion|Proportional|Proportion)$/,"")+"HorizontalProportion";n.set(r,new Lt(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 Kt(i.elementOne,i.elementTwo,{proportion:i.proportion.y,power:null===(r=i.power)||void 0===r?void 0:r.y,rule:null===(e=i.rule)||void 0===e?void 0:e.y,orientation:i.orientation}))}}static buildCoverConstraint(t,i,n){var s,o;n.set(t,new Yt(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 ei;(t=>{t[t.FROM_LEFT_TOP=0]="FROM_LEFT_TOP",t[t.FROM_LEFT_BOTTOM=1]="FROM_LEFT_BOTTOM"})(ei||(ei={}));class hi{static build(t,i,n,s={}){var o;const r=null!==(o=s.direction)&&void 0!==o?o:ei.FROM_LEFT_TOP,e=[],h=[];e.push(new Ft(t,i,{anchorOne:0,anchorTwo:0,distance:0,power:s.power,orientation:s.orientation}),new Ft(t,n,{anchorOne:1,anchorTwo:1,distance:0,power:s.power,orientation:s.orientation}));const l=r===ei.FROM_LEFT_TOP?1:0,u=r===ei.FROM_LEFT_TOP?0:1;return h.push(new Bt(t,i,{anchorOne:l,anchorTwo:l,distance:0,power:s.power,orientation:s.orientation}),new Bt(t,n,{anchorOne:u,anchorTwo:u,distance:0,power:s.power,orientation:s.orientation})),{horizontalDistances:e,verticalDistances:h}}}class li{static buildHorizontal(t,i){return this.buildStack(t,i,{distanceConstraint:Ft,proportionConstraint:Lt,centerDistanceConstraint:Bt})}static buildVertical(t,i){return this.buildStack(t,i,{distanceConstraint:Bt,proportionConstraint:Kt,centerDistanceConstraint:Ft})}static buildStack(t,i,n){const s=[],o=[],r=[];for(let e=0;e<t.length-1;e++){const h=t[e],l=t[e+1];s.push(new n.distanceConstraint(h,l,{anchorOne:1,anchorTwo:0,distance:i.distance,power:i.power,orientation:i.orientation})),0!=i.keepProportions&&o.push(new n.proportionConstraint(h,l,{power:i.power,orientation:i.orientation})),0!=i.keepAlignment&&r.push(new n.centerDistanceConstraint(h,l,{power:i.power,anchorOne:0,anchorTwo:0,orientation:i.orientation}))}return{distanceConstraints:s,proportionConstraints:o,alignmentConstraints:r}}}class ui extends Vt{constructor(t,i=1e3,n=1e3){super(t,new w,0,0,i,n),this.flushTransform()}[Q](){this.flushTransform()}}class ai extends h{constructor(t){super({uniforms:l.merge([{map:{value:t},opacity:{value:1},color:{value:new a(1,1,1)},uvTransform:{value:new u}}]),vertexShader:"\n uniform mat3 uvTransform;\n varying vec2 vUv;\n void main() {\n vUv = (uvTransform * vec3(uv, 1)).xy;\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,fog:0,lights:0})}getTexture(){return this.uniforms.map.value}getColor(){return this.uniforms.color.value}getOpacity(){return this.uniforms.opacity.value}getUVTransform(){return this.uniforms.uvTransform.value}setTexture(t){this.uniforms.map.value=t,this.uniformsNeedUpdate=1}setColor(t){this.uniforms.color.value=t,this.uniformsNeedUpdate=1}setOpacity(t){this.uniforms.opacity.value=t,this.uniformsNeedUpdate=1}setUVTransform(t){this.uniforms.uvTransform.value=t,this.uniformsNeedUpdate=1}}class ci extends Vt{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;_t(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 h=new ai(i);super(t,new r(bt,h),0,0,o,e),this.material=h,this.textureInternal=i,this.flushTransform()}get texture(){return this.material.getTexture()}get color(){return this.material.getColor()}get opacity(){return this.material.getOpacity()}set color(t){this.material.setColor(t)}set opacity(t){this.material.setOpacity(t)}destroy(){this.material.dispose(),super.destroy()}[Q](t){this.flushTransform(),this.material.setTexture(this.composer.render(t,this.textureInternal))}}class di extends h{constructor(t,i){super({uniforms:l.merge([{map:{value:t},foreground:{value:i},progress:{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 map;\n uniform sampler2D foreground;\n uniform float progress;\n varying vec2 vUv;\n\n void main() {\n vec4 background = texture2D(map, vUv);\n vec4 foreground = texture2D(foreground, vUv);\n gl_FragColor = mix(background, foreground, step(vUv.x, progress));\n #include <colorspace_fragment>\n }\n ",transparent:1,fog:0,lights:0})}}class vi extends Vt{constructor(t,i,n){var s,o,e,h;const l=null===(s=i.image)||void 0===s?void 0:s.width,u=null===(o=i.image)||void 0===o?void 0:o.height;_t(l,u,`Invalid image dimensions - texture "${i.name||"unnamed"}" has invalid width (${l}) or height (${u}). Image dimensions must be non-zero positive numbers.`);const a=null===(e=n.image)||void 0===e?void 0:e.width,c=null===(h=n.image)||void 0===h?void 0:h.height;_t(a,c,`Invalid image dimensions - texture "${n.name||"unnamed"}" has invalid width (${a}) or height (${c}). Image dimensions must be non-zero positive numbers.`);const d=new di(i,n);super(t,new r(bt,d),0,0,l,u),this.material=d,this.textureBackground=i,this.textureForeground=n,this.flushTransform()}get background(){return this.textureBackground}get foreground(){return this.textureForeground}get progress(){return this.material.uniforms.progress.value}set progress(t){this.material.uniforms.progress.value=t,this.material.uniformsNeedUpdate=1}destroy(){this.material.dispose(),super.destroy()}[Q](){this.flushTransform()}}function fi(t,i){var n,s,o,r,e,h,l,u,a,c,d,v,f,w,p,m,g,b,y,x,S,E,C,M,T,O,z,D;const $=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),k=null!==(r=null!==(o=null==t?void 0:t.lineHeight)&&void 0!==o?o:null==i?void 0:i.lineHeight)&&void 0!==r?r:1.2*$,I=Math.max(null!==(h=null!==(e=null==t?void 0:t.shadowBlur)&&void 0!==e?e:null==i?void 0:i.shadowBlur)&&void 0!==h?h:0,0),P=Math.max(null!==(u=null!==(l=null==t?void 0:t.strokeWidth)&&void 0!==l?l:null==i?void 0:i.strokeWidth)&&void 0!==u?u:0,0);return{color:null!==(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:$,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!==(m=null!==(p=null==t?void 0:t.fontWeight)&&void 0!==p?p:null==i?void 0:i.fontWeight)&&void 0!==m?m:"normal",lineHeight:k,enableShadow:null!==(b=null!==(g=null==t?void 0:t.enableShadow)&&void 0!==g?g:null==i?void 0:i.enableShadow)&&void 0!==b?b:0,shadowOffsetX:null!==(x=null!==(y=null==t?void 0:t.shadowOffsetX)&&void 0!==y?y:null==i?void 0:i.shadowOffsetX)&&void 0!==x?x:0,shadowOffsetY:null!==(E=null!==(S=null==t?void 0:t.shadowOffsetY)&&void 0!==S?S:null==i?void 0:i.shadowOffsetY)&&void 0!==E?E:0,shadowBlur:I,shadowColor:null!==(M=null!==(C=null==t?void 0:t.shadowColor)&&void 0!==C?C:null==i?void 0:i.shadowColor)&&void 0!==M?M:"transparent",enableStroke:null!==(O=null!==(T=null==t?void 0:t.enableStroke)&&void 0!==T?T:null==i?void 0:i.enableStroke)&&void 0!==O?O:0,strokeColor:null!==(D=null!==(z=null==t?void 0:t.strokeColor)&&void 0!==z?z:null==i?void 0:i.strokeColor)&&void 0!==D?D:"transparent",strokeWidth:P}}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,r=Math.ceil(s.actualBoundingBoxAscent+s.actualBoundingBoxDescent);return{width:Math.ceil(o),height:r,baseline:s.actualBoundingBoxDescent,lineHeight:n.lineHeight}}function mi(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 gi extends Vt{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 h=[],l=Array.isArray(i)?i:[i];for(const t of l){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);h.push({text:t,style:o,metrics:i})}}const u=((t,i)=>{const n=[];let s=[],o=0,r=0,e=0,h=0;for(const l of i)"\n"!==l.text?o+l.metrics.width<=t||0===s.length?(s.push(l),o+=l.metrics.width,r=Math.max(r,l.metrics.height),e=Math.max(e,l.metrics.baseline),h=Math.max(h,l.metrics.lineHeight)):(n.push({chunks:s,width:o,height:r,baseline:e,lineHeight:h}),s=[l],o=l.metrics.width,r=l.metrics.height,e=l.metrics.baseline,h=l.metrics.lineHeight):(s.length>0&&n.push({chunks:s,width:o,height:r,baseline:e,lineHeight:h}),s=[],o=0,r=0,e=0,h=0);return s.length>0&&n.push({chunks:s,width:o,height:r,baseline:e,lineHeight:h}),n})(null!==(s=n.maxWidth)&&void 0!==s?s:1024,h),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}})(u),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 ai(d);super(t,new r(bt,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 r=n[t];let e=i;o+=0===t?r.height:r.lineHeight;for(const t of r.chunks)mi(e,o,t.text,t.style,s),e+=t.metrics.width}})(0,this.padding.left,u,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)}set opacity(t){this.material.setOpacity(t)}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[Y](this,this[H],this.width/((this.textBlockSize.width+this.padding.left+this.padding.right)/(this.textBlockSize.height+this.padding.top+this.padding.bottom))))}[Q](t){this.flushTransform(),this.material.setTexture(this.composer.render(t,this.texture))}}function bi(t){return null!==t&&"object"==typeof t&&"background"in t&&t.background instanceof m&&"foreground"in t&&t.foreground instanceof m}function yi(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 Si(t){return!(null===t||"object"!=typeof t||"width"in t&&"number"!=typeof t.width||"height"in t&&"number"!=typeof t.height)}class Ei{static fromDescription(t,i){const n=i instanceof Map?i.entries():Object.entries(i),s=new Map;for(const[i,r]of n){if(s.has(i))throw Error(`Duplicate element key "${i}" - each UI element must have a unique identifier`);let n;if(r instanceof m)n=new ci(t,r);else if(null!==(o=r)&&"object"==typeof o&&"texture"in o&&o.texture instanceof m)n=new ci(t,r.texture);else if("string"==typeof r)n=new gi(t,[r]);else if(bi(r))n=new vi(t,r.background,r.foreground);else if(yi(r))n=new gi(t,[r.text],{defaultStyle:r.style});else if(xi(r))n=new gi(t,r.spans,{defaultStyle:r.defaultStyle});else{if(!Si(r))throw Error(`Invalid UI element type for "${i}". Expected one of: Texture, UIImage, String, UITextDescription, or UITextEnhancedDescription`);n=new ui(t,r.width,r.height)}s.set(i,n)}var o;return Object.fromEntries(s)}}class Ci extends ot{constructor(t,i,n){var s,o,r;super(i.layer,new Set(t instanceof Vt?[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!==(r=null==n?void 0:n.verticalAnchor)&&void 0!==r?r:.5,orientation:st(null==n?void 0:n.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[X](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){this.constraintX=new z(new E(this.elementOne[V]).plus(new E(this.elementOne[A]).multiply(this.parameters.horizontalAnchor)),M.Eq,new E(this.elementTwo[V]).plus(new E(this.elementTwo[A]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new z(new E(this.elementOne[j]).plus(new E(this.elementOne[H]).multiply(this.parameters.verticalAnchor)),M.Eq,new E(this.elementTwo[j]).plus(new E(this.elementTwo[H]).multiply(this.parameters.verticalAnchor))),this.constraintW=new z(new E(this.elementOne[A]),M.Ge,new E(this.elementTwo[A])),this.constraintH=new z(new E(this.elementOne[H]),M.Ge,new E(this.elementTwo[H])),this.layer[K](this,this.constraintX),this.layer[K](this,this.constraintY),this.layer[K](this,this.constraintW),this.layer[K](this,this.constraintH),0!=this.parameters.isStrict&&(this.constraintStrict=new z(new E(this.elementOne[H]),M.Eq,new E(this.elementTwo[H]),T.strong),this.layer[K](this,this.constraintStrict))}destroyConstraints(){this.constraintX&&(this.layer[R](this,this.constraintX),this.constraintX=void 0),this.constraintY&&(this.layer[R](this,this.constraintY),this.constraintY=void 0),this.constraintW&&(this.layer[R](this,this.constraintW),this.constraintW=void 0),this.constraintH&&(this.layer[R](this,this.constraintH),this.constraintH=void 0),this.constraintStrict&&(this.layer[R](this,this.constraintStrict),this.constraintStrict=void 0)}}class Mi extends At{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!==wt.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 Ti extends At{click(t,i){this.clickInternal(t,i)}resize(t,i){this.resizeInternal(t,i)}}class Oi{}export{Wt as UIAspectConstraint,wt as UIBehavior,Nt as UIConstraint2DBuilder,ri as UIConstraintBuilder,hi as UIConstraintContainerBuilder,ei as UIConstraintContainerDirection,tt as UIConstraintPower,it as UIConstraintRule,li as UIConstraintStackBuilder,Yt as UICoverConstraint,ui as UIDummy,Ei as UIElementBuilder,$t as UIElementEvent,Ci as UIFitConstraint,Mi as UIFullScreenLayer,St as UIFullScreenQuad,ct as UIHeightConstraint,Ft as UIHorizontalDistanceConstraint,Lt as UIHorizontalProportionConstraint,ci as UIImage,Ti as UIManualLayer,Z as UIOrientation,Oi as UIPass,vi as UIProgress,gi as UIText,Bt as UIVerticalDistanceConstraint,Kt as UIVerticalProportionConstraint,Rt as UIWidthConstraint};
1
+ import{Vector2 as t,Box2 as i,MathUtils as n,ShaderMaterial as s,UniformsUtils as o,PlaneGeometry as r,Scene as e,Mesh as h,OrthographicCamera as u,WebGLRenderTarget as l,UnsignedByteType as a,LinearFilter as c,RGBAFormat as d,Color as v,Object3D as f,Matrix3 as w,CanvasTexture as p,Texture as g}from"three";function m(){return new y}var y=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 b(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 b(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}(),b=function(){function t(t,i){this.first=t,this.second=i}return t.prototype.copy=function(){return new t(this.first,this.second)},t}(),x=function(){function t(t){void 0===t&&(t=""),this.t=0,this.i=null,this.o=C++,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 S(this,t)},t.prototype.minus=function(t){return new S(this,"number"==typeof t?-t:[-1,t])},t.prototype.multiply=function(t){return new S([t,this])},t.prototype.divide=function(t){return new S([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}(),C=0,S=function(){function t(){var t=E(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 E(t){for(var i=0,n=()=>0,s=m(),o=0,r=t.length;o<r;++o){var e=t[o];if("number"==typeof e)i+=e;else if(e instanceof x)s.setDefault(e,n).second+=1;else if(e instanceof S){i+=e.constant();for(var h=0,u=(d=e.terms()).size();h<u;h++){var l=d.itemAt(h);s.setDefault(l.first,n).second+=l.second}}else{if(!(e instanceof Array))throw Error("invalid Expression argument: "+e);if(2!==e.length)throw Error("array must have length 2");var a=e[0],c=e[1];if("number"!=typeof a)throw Error("array item 0 must be a number");if(c instanceof x)s.setDefault(c,n).second+=a;else{if(!(c instanceof S))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 T,k=(()=>{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"})(T||(T={}));var O,M=function(){function t(t,i,n,s){void 0===s&&(s=k.required),this.o=D++,this.v=i,this.p=k.clip(s),this.m=void 0===n&&t instanceof S?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=m(),this.S=m(),this.T=m(),this.k=m(),this.O=[],this.M=new U,this.D=null,this.I=0}return t.prototype.createConstraint=function(t,i,n,s){void 0===s&&(s=k.required);var o=new M(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.P(t),n=i.row,s=i.tag,o=this.$(n,s);if(o.type()===O.Invalid&&n.allDummies()){if(!z(n.constant()))throw Error("unsatisfiable constraint");o=s.marker}if(o.type()===O.Invalid){if(!this.U(n))throw Error("unsatisfiable constraint")}else n.solveFor(o),this.A(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.F(t,i.second);var n=i.second.marker,s=this.S.erase(n);if(void 0===s){var o=this.V(n);if(o.type()===O.Invalid)throw Error("failed to find leaving row");(s=this.S.erase(o)).second.solveForEx(o,n),this.A(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.k.find(t))throw Error("duplicate edit variable");if((i=k.clip(i))===k.required)throw Error("bad required strength");var n=new S(t),s=new M(n,T.Eq,void 0,i);this.addConstraint(s);var o=this.C.find(s).second;this.k.insert(t,{tag:o,constraint:s,constant:0})},t.prototype.removeEditVariable=function(t){var i=this.k.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)},t.prototype.hasEditVariable=function(t){return this.k.contains(t)},t.prototype.suggestValue=function(t,i){var n=this.k.find(t);if(void 0===n)throw Error("unknown edit variable");var s=this.S,o=n.second,r=i-o.constant;o.constant=i;var e=o.tag.marker,h=s.find(e);if(void 0!==h)return h.second.add(-r)<0&&this.O.push(e),void this.B();var u=o.tag.other;if(void 0!==(h=s.find(u)))return h.second.add(r)<0&&this.O.push(u),void this.B();for(var l=0,a=s.size();l<a;++l){var c=s.itemAt(l),d=c.second,v=d.coefficientFor(e);0!==v&&d.add(r*v)<0&&c.first.type()!==O.External&&this.O.push(c.first)}this.B()},t.prototype.updateVariables=function(){for(var t=this.T,i=this.S,n=0,s=t.size();n<s;++n){var o=t.itemAt(n),r=i.find(o.second);o.first.setValue(void 0!==r?r.second.constant():0)}},t.prototype.H=function(t){var i=this;return this.T.setDefault(t,(()=>i._(O.External))).second},t.prototype.P=function(t){for(var i=t.expression(),n=new U(i.constant()),s=i.terms(),o=0,r=s.size();o<r;++o){var e=s.itemAt(o);if(!z(e.second)){var h=this.H(e.first),u=this.S.find(h);void 0!==u?n.insertRow(u.second,e.second):n.insertSymbol(h,e.second)}}var l=this.M,a=t.strength(),c={marker:$,other:$};switch(t.op()){case T.Le:case T.Ge:var d=t.op()===T.Le?1:-1,v=this._(O.Slack);if(c.marker=v,n.insertSymbol(v,d),a<k.required){var f=this._(O.Error);c.other=f,n.insertSymbol(f,-d),l.insertSymbol(f,a)}break;case T.Eq:if(a<k.required){var w=this._(O.Error),p=this._(O.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._(O.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 r=n.itemAt(s);if(r.first.type()===O.External)return r.first}var e=i.marker.type();return(e===O.Slack||e===O.Error)&&t.coefficientFor(i.marker)<0?i.marker:((e=i.other.type())===O.Slack||e===O.Error)&&t.coefficientFor(i.other)<0?i.other:$},t.prototype.U=function(t){var i=this._(O.Slack);this.S.insert(i,t.copy()),this.D=t.copy(),this.j(this.D);var n=z(this.D.constant());this.D=null;var s=this.S.erase(i);if(void 0!==s){var o=s.second;if(o.isConstant())return n;var r=this.L(o);if(r.type()===O.Invalid)return 0;o.solveForEx(i,r),this.A(r,o),this.S.insert(r,o)}for(var e=this.S,h=0,u=e.size();h<u;++h)e.itemAt(h).second.removeSymbol(i);return this.M.removeSymbol(i),n},t.prototype.A=function(t,i){for(var n=this.S,s=0,o=n.size();s<o;++s){var r=n.itemAt(s);r.second.substitute(t,i),r.second.constant()<0&&r.first.type()!==O.External&&this.O.push(r.first)}this.M.substitute(t,i),this.D&&this.D.substitute(t,i)},t.prototype.j=function(t){for(;;){var i=this.K(t);if(i.type()===O.Invalid)return;var n=this.R(i);if(n.type()===O.Invalid)throw Error("the objective is unbounded");var s=this.S.erase(n).second;s.solveForEx(n,i),this.A(i,s),this.S.insert(i,s)}},t.prototype.B=function(){for(var t=this.S,i=this.O;0!==i.length;){var n=i.pop(),s=t.find(n);if(void 0!==s&&s.second.constant()<0){var o=this.X(s.second);if(o.type()===O.Invalid)throw Error("dual optimize failed");var r=s.second;t.erase(n),r.solveForEx(n,o),this.A(o,r),t.insert(o,r)}}},t.prototype.K=t=>{for(var i=t.cells(),n=0,s=i.size();n<s;++n){var o=i.itemAt(n),r=o.first;if(o.second<0&&r.type()!==O.Dummy)return r}return $},t.prototype.X=function(t){for(var i=Number.MAX_VALUE,n=$,s=t.cells(),o=0,r=s.size();o<r;++o){var e=s.itemAt(o),h=e.first,u=e.second;if(u>0&&h.type()!==O.Dummy){var l=this.M.coefficientFor(h)/u;l<i&&(i=l,n=h)}}return n},t.prototype.R=function(t){for(var i=Number.MAX_VALUE,n=$,s=this.S,o=0,r=s.size();o<r;++o){var e=s.itemAt(o),h=e.first;if(h.type()!==O.External){var u=e.second,l=u.coefficientFor(t);if(l<0){var a=-u.constant()/l;a<i&&(i=a,n=h)}}}return n},t.prototype.V=function(t){for(var i=Number.MAX_VALUE,n=i,s=i,o=$,r=o,e=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()===O.External)h=f;else if(v<0)(w=-d.constant()/v)<n&&(n=w,r=f);else{var w;(w=d.constant()/v)<s&&(s=w,e=f)}}}return r!==o?r:e!==o?e:h},t.prototype.F=function(t,i){i.marker.type()===O.Error&&this.Y(i.marker,t.strength()),i.other.type()===O.Error&&this.Y(i.other,t.strength())},t.prototype.Y=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.L=t=>{for(var i=t.cells(),n=0,s=i.size();n<s;++n){var o=i.itemAt(n),r=o.first.type();if(r===O.Slack||r===O.Error)return o.first}return $},t.prototype._=function(t){return new P(t,this.I++)},t}();function z(t){return t<0?-t<1e-8:t<1e-8}(t=>{t[t.Invalid=0]="Invalid",t[t.External=1]="External",t[t.Slack=2]="Slack",t[t.Error=3]="Error",t[t.Dummy=4]="Dummy"})(O||(O={}));var P=function(){function t(t,i){this.o=i,this.N=t}return t.prototype.id=function(){return this.o},t.prototype.type=function(){return this.N},t}(),$=new P(O.Invalid,-1),U=function(){function t(t){void 0===t&&(t=0),this.W=m(),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()!==O.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),z(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 r=n.itemAt(s);this.insertSymbol(r.first,r.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 A=Symbol("xSymbol"),j=Symbol("ySymbol"),F=Symbol("widthSymbol"),V=Symbol("heightSymbol"),B=Symbol("addUIElementSymbol"),H=Symbol("removeUIElementSymbol"),_=Symbol("addConstraintSymbol"),L=Symbol("removeUIConstraintSymbol"),K=Symbol("addConstraintSymbol"),R=Symbol("removeConstraintSymbol"),X=Symbol("addVariableSymbol"),Y=Symbol("removeVariableSymbol"),N=Symbol("suggestVariableSymbol"),W=Symbol("disableConstraintSymbol"),q=Symbol("enableConstraintSymbol"),G=Symbol("needsRecalculation"),Q=Symbol("renderSymbol"),J=Symbol("clickSymbol");var Z,tt,it;function nt(t){return null!==t&&Object.values(Z).some((i=>i===t))}function st(t){return null!=t?t:Z.ALWAYS}(t=>{t[t.LANDSCAPE=0]="LANDSCAPE",t[t.PORTRAIT=1]="PORTRAIT",t[t.ALWAYS=2]="ALWAYS"})(Z||(Z={}));class ot{constructor(t,i){this.layer=t,this.name="",this.layer[_](this,i)}destroy(){this.layer[L](this)}}function rt(t){return null!==t&&Object.values(tt).some((i=>i===t))}function et(t){return null!=t?t:tt.P0}function ht(t){switch(t){case tt.P0:return k.create(1e3,1e3,1e3);case tt.P1:return k.create(100,0,0);case tt.P2:return k.create(10,0,0);case tt.P3:return k.create(0,100,0);case tt.P4:return k.create(0,10,0);case tt.P5:return k.create(0,0,100);case tt.P6:return k.create(0,0,10);case tt.P7:return k.create(0,0,1);default:return k.create(1e3,1e3,1e3)}}function ut(t){return null!==t&&Object.values(it).some((i=>i===t))}function lt(t){return null!=t?t:it.EQUAL}function at(t){switch(t){case it.EQUAL:return T.Eq;case it.LESS:return T.Le;case it.GREATER:return T.Ge;default:return T.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"})(tt||(tt={})),(t=>{t[t.EQUAL=2]="EQUAL",t[t.LESS=0]="LESS",t[t.GREATER=1]="GREATER"})(it||(it={}));class ct extends ot{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:et(null==i?void 0:i.power),rule:lt(null==i?void 0:i.rule),orientation:st(null==i?void 0:i.orientation)},this.options.orientation!==Z.ALWAYS&&this.options.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[W](t){this.options.orientation!==Z.ALWAYS&&t!==this.options.orientation&&this.destroyConstraints()}[q](t){this.options.orientation!==Z.ALWAYS&&t===this.options.orientation&&this.buildConstraints()}buildConstraints(){this.constraint=new M(new S(this.element[V]),at(this.options.rule),this.options.height,ht(this.options.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class dt{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 r=this.listeners.get(t);if(r||(r=[],this.listeners.set(t,r)),r.some((t=>t.callback===i&&t.context===n)))throw Error("Event listener already exists");const e={callback:i,context:n,priority:s,once:o};let h=0;for(;h<r.length&&r[h].priority<=s;)h++;r.splice(h,0,e)}}const vt=new t,ft=new i;var wt,pt;(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE"})(wt||(wt={}));const gt=.5;class mt{constructor(){this[pt]=0,this.positionXInternal=0,this.positionYInternal=0,this.anchorXInternal=gt,this.anchorYInternal=gt,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[G]=1}set y(t){this.positionYInternal=t,this[G]=1}set anchorX(t){this.anchorXInternal=t,this[G]=1}set anchorY(t){this.anchorYInternal=t,this[G]=1}set scaleX(t){this.scaleXInternal=t,this[G]=1}set scaleY(t){this.scaleYInternal=t,this[G]=1}set angle(t){this.rotationInternal=n.degToRad(t),this[G]=1}set rotation(t){this.rotationInternal=t,this[G]=1}reset(){this.positionXInternal=0,this.positionYInternal=0,this.anchorXInternal=gt,this.anchorYInternal=gt,this.scaleXInternal=1,this.scaleYInternal=1,this.rotationInternal=0,this[G]=1}}pt=G;class yt extends s{constructor(t){super({uniforms:o.merge([{map:{value:t}}]),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 varying vec2 vUv;\n\n void main() {\n gl_FragColor = texture2D(map, vUv);\n #include <colorspace_fragment>\n }\n ",transparent:1,fog:0,lights:0})}getTexture(){return this.uniforms.map.value}setTexture(t){this.uniforms.map.value=t,this.uniformsNeedUpdate=1}}const bt=new r(1,1).translate(.5,.5,0),xt=new e,Ct=new h(bt);xt.add(Ct);class St{constructor(t,i=0,n=0){this.materialInternal=t,this.paddingHorizontalInternal=i,this.paddingVerticalInternal=n,this.camera=new u(-1,1,1,-1,0,1),this.updateCameraTransform()}get paddingHorizontal(){return this.paddingHorizontalInternal}get paddingVertical(){return this.paddingVerticalInternal}get material(){return this.materialInternal}set paddingHorizontal(t){this.paddingHorizontalInternal!==t&&(this.paddingHorizontalInternal=t,this.updateCameraTransform())}set paddingVertical(t){this.paddingVerticalInternal!==t&&(this.paddingVerticalInternal=t,this.updateCameraTransform())}set material(t){this.materialInternal=t}render(t,i){const n=null!=i?i:this.materialInternal;if(!n)throw Error("You cannot render without a material");Ct.material=n,t.render(xt,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 Et{constructor(){this.defaultMaterial=new yt,this.passes=[],this.screen=new St,this.needsUpdateInternal=0;const t={format:d,minFilter:c,magFilter:c,type:a,depthBuffer:0,stencilBuffer:0};this.fromRenderTarget=new l(1,1,t),this.toRenderTarget=new l(1,1,t)}get needsUpdate(){return this.needsUpdateInternal||this.passes.some((t=>t.needsUpdate))}requestUpdate(){this.needsUpdateInternal=1}calculatePadding(){return this.passes.reduce(((t,i)=>Math.max(t,i.padding)),0)}renderByMaterial(t,i,n,s){if(!this.needsUpdate)return s;const o=this.calculatePadding(),r=i+2*o,e=n+2*o;this.fromRenderTarget.setSize(r,e),this.toRenderTarget.setSize(r,e),this.setPadding(i,n,o),t.setClearColor(0,0),t.setRenderTarget(this.fromRenderTarget),t.clearColor(),t.setRenderTarget(this.toRenderTarget),t.clearColor(),this.screen.render(t,s),this.reverseTargets();for(const s of this.passes)t.setRenderTarget(this.toRenderTarget),t.clearColor(),s.render(t,this.fromRenderTarget.texture,{width:i,height:n,padding:o}),this.reverseTargets();return this.defaultMaterial.setTexture(this.fromRenderTarget.texture),this.defaultMaterial}renderByTexture(t,i){if(!this.needsUpdate)return i;const n=this.calculatePadding(),s=i.image.width,o=i.image.height,r=s+2*n,e=o+2*n;this.fromRenderTarget.setSize(r,e),this.toRenderTarget.setSize(r,e),this.setPadding(s,o,n),t.setClearColor(0,0),t.setRenderTarget(this.fromRenderTarget),t.clearColor(),t.setRenderTarget(this.toRenderTarget),t.clearColor();const h={width:s,height:o,padding:n};for(let n=0;n<this.passes.length;n++){const s=0===n?i:this.fromRenderTarget.texture;t.setRenderTarget(this.toRenderTarget),t.clearColor(),this.passes[n].render(t,s,h),this.reverseTargets()}return this.fromRenderTarget.texture}destroy(){this.fromRenderTarget.dispose(),this.toRenderTarget.dispose()}setPadding(t,i,n){n<=0?(this.screen.paddingHorizontal=0,this.screen.paddingVertical=0):(this.screen.paddingHorizontal=n/t,this.screen.paddingVertical=n/i)}reverseTargets(){const t=this.fromRenderTarget;this.fromRenderTarget=this.toRenderTarget,this.toRenderTarget=t}}var Tt,kt,Ot,Mt,Dt,It,zt,Pt,$t,Ut;(t=>{t.CLICK="click"})(It||(It={}));class At extends dt{constructor(t,i,n,s,o,r){super(),this.layer=t,this.object=i,this.name="",this.micro=new mt,this[Tt]=new x("x"),this[kt]=new x("y"),this[Ot]=new x("width"),this[Mt]=new x("height"),this[Dt]=0,this.behaviorInternal=wt.VISIBLE,this.composer=new Et,this.layer[B](this,this.object),this.layer[X](this,this[A],ht(tt.P7)),this.layer[X](this,this[j],ht(tt.P7)),this.layer[X](this,this[F],ht(tt.P5)),this.layer[X](this,this[V],ht(tt.P5)),this[A].setValue(n),this[j].setValue(s),this[F].setValue(o),this[V].setValue(r),this.layer[N](this,this[A],n),this.layer[N](this,this[j],s),this.layer[N](this,this[F],o),this.layer[N](this,this[V],r)}get passes(){return this.composer.passes}get x(){return this[A].value()}get y(){return this[j].value()}get width(){return this[F].value()}get height(){return this[V].value()}get zIndex(){return this.object.position.z}get behavior(){return this.behaviorInternal}set x(t){this.layer[N](this,this[A],t)}set y(t){this.layer[N](this,this[j],t)}set width(t){this.layer[N](this,this[F],t)}set height(t){this.layer[N](this,this[V],t)}set zIndex(t){this.object.position.z=t}set behavior(t){this.behaviorInternal=t,this.object.visible=t!==wt.HIDDEN}destroy(){this.composer.destroy(),this.layer[Y](this,this[V]),this.layer[Y](this,this[F]),this.layer[Y](this,this[j]),this.layer[Y](this,this[A]),this.layer[H](this)}[(Tt=A,kt=j,Ot=F,Mt=V,Dt=G,J)](t,i){return this.behavior!==wt.INTERACTIVE?0:(this.flushTransform(),n=this.x,s=this.y,o=this.width,r=this.height,vt.set(t,i),ft.min.set(n,s),ft.max.set(o,r).add(ft.min),ft.containsPoint(vt)?(this.emit(It.CLICK,this),1):0);var n,s,o,r}flushTransform(){(this[G]||this.micro[G])&&(((t,i,n,s,o,r,e)=>{const h=n-e,u=s-e,l=o+2*e,a=r+2*e,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,this.x,this.y,this.width,this.height,this.composer.calculatePadding()),this[G]=0,this.micro[G]=0)}}const jt=new v(0);class Ft{constructor(){this.behavior=wt.VISIBLE,this[zt]=new x,this[Pt]=new x,this[$t]=new x,this[Ut]=new x,this.scene=new e,this.camera=new u,this.solver=new I,this.elements=new Map,this.constraints=new Map,this.orientationPrivate=Z.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()}[(zt=A,Pt=j,$t=F,Ut=V,B)](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)}[H](t){const i=this.elements.get(t);if(void 0===i)throw Error("Element not found");if(i.variables.size>0)throw Error("Variables should be removed before removing element");if(i.constraints.size>0)throw Error("Constraints should be removed before removing element");this.elements.delete(t),this.scene.remove(i.object)}[_](t,i){if(this.constraints.has(t))throw Error("Constraint already added");for(const 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})}[L](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)}[K](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}[R](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 At?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}[Y](t,i){var n;const s=t instanceof At?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}[N](t,i,n){var s;const o=t instanceof At?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 r=o.variables.get(i);if(!r)throw Error("Variable does not exist");r.suggestedValue!==n&&(r.suggestedValue=n,null===(s=this.solver)||void 0===s||s.suggestValue(i,n),this.needsRecalculation=1)}render(t){var i;if(this.behavior===wt.HIDDEN)return;const n=t.getRenderTarget(),s=t.getClearColor(jt),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[G]=1}for(const t of this.elements.keys())t[G]=1;for(const i of this.elements.keys())i[Q](t);t.setRenderTarget(n),t.setClearColor(s),t.setClearAlpha(o),t.render(this.scene,this.camera)}clickInternal(t,i){if(this.behavior!==wt.INTERACTIVE)return;const n=[...this.elements.keys()].filter((t=>t.behavior===wt.INTERACTIVE)).sort(((t,i)=>t.zIndex-i.zIndex));for(const s of n)if(s[J](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,r,e,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===(r=this.solver)||void 0===r||r.removeConstraint(this.constraintH),this.constraintH=void 0),this.constraintX=new M(new S(this[A]),T.Eq,0,k.required),this.constraintY=new M(new S(this[j]),T.Eq,0,k.required),this.constraintW=new M(new S(this[F]),T.Eq,t,k.required),this.constraintH=new M(new S(this[V]),T.Eq,i,k.required),null===(e=this.solver)||void 0===e||e.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?Z.LANDSCAPE:Z.PORTRAIT,n!==this.orientationPrivate){this.solver=void 0;for(const t of this.constraints.keys())t[q](this.orientationPrivate);for(const t of this.constraints.keys())t[W](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 Vt(t,i){if((t instanceof Ft?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 Bt(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 Ht extends ot{constructor(t,i,n){var s,o,r;Vt(t,i),super(i.layer,new Set(t instanceof At?[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!==(r=null==n?void 0:n.distance)&&void 0!==r?r:0,power:et(null==n?void 0:n.power),rule:lt(null==n?void 0:n.rule),orientation:st(null==n?void 0:n.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[W](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new S(this.elementOne[A]).plus(new S(this.elementOne[F]).multiply(this.parameters.anchorOne)),i=new S(this.elementTwo[A]).plus(new S(this.elementTwo[F]).multiply(this.parameters.anchorTwo));this.constraint=new M(i.minus(t),at(this.parameters.rule),this.parameters.distance,ht(this.parameters.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class _t extends ot{constructor(t,i,n){var s;Vt(t,i),super(i.layer,new Set(t instanceof At?[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:et(null==n?void 0:n.power),rule:lt(null==n?void 0:n.rule),orientation:st(null==n?void 0:n.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[W](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new S(this.elementOne[F]).multiply(this.parameters.proportion),i=new S(this.elementTwo[F]);this.constraint=new M(t.minus(i),at(this.parameters.rule),0,ht(this.parameters.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Lt extends ot{constructor(t,i,n){var s,o,r;Vt(t,i),super(i.layer,new Set(t instanceof At?[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!==(r=null==n?void 0:n.distance)&&void 0!==r?r:0,power:et(null==n?void 0:n.power),rule:lt(null==n?void 0:n.rule),orientation:st(null==n?void 0:n.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[W](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new S(this.elementOne[j]).plus(new S(this.elementOne[V]).multiply(this.parameters.anchorOne)),i=new S(this.elementTwo[j]).plus(new S(this.elementTwo[V]).multiply(this.parameters.anchorTwo));this.constraint=new M(i.minus(t),at(this.parameters.rule),this.parameters.distance,ht(this.parameters.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Kt extends ot{constructor(t,i,n){var s;Vt(t,i),super(i.layer,new Set(t instanceof At?[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:et(null==n?void 0:n.power),rule:lt(null==n?void 0:n.rule),orientation:st(null==n?void 0:n.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[W](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new S(this.elementOne[V]).multiply(this.parameters.proportion),i=new S(this.elementTwo[V]);this.constraint=new M(t.minus(i),at(this.parameters.rule),0,ht(this.parameters.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Rt extends ot{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:et(null==i?void 0:i.power),rule:lt(null==i?void 0:i.rule),orientation:st(null==i?void 0:i.orientation)},this.options.orientation!==Z.ALWAYS&&this.options.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[W](t){this.options.orientation!==Z.ALWAYS&&t!==this.options.orientation&&this.destroyConstraints()}[q](t){this.options.orientation!==Z.ALWAYS&&t===this.options.orientation&&this.buildConstraints()}buildConstraints(){this.constraint=new M(new S(this.element[F]),at(this.options.rule),this.options.width,ht(this.options.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Xt{static size(t,i){var n,s,o,r,e,h,u,l;return{x:new Rt(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===(r=i.orientation)||void 0===r?void 0:r.x}),y:new ct(t,{height:null===(e=i.size)||void 0===e?void 0:e.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,r,e,h,u,l,a,c,d,v,f;return{x:new Ht(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===(r=n.distance)||void 0===r?void 0:r.x,power:null===(e=n.power)||void 0===e?void 0:e.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 Lt(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,r,e,h,u,l,a;return{x:new _t(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===(r=n.rule)||void 0===r?void 0:r.x,orientation:null===(e=n.orientation)||void 0===e?void 0:e.x}),y:new Kt(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 Yt extends ot{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:et(null==i?void 0:i.power),rule:lt(null==i?void 0:i.rule),orientation:st(null==i?void 0:i.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[W](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new S(this.element[F]).plus(new S(this.element[V]).multiply(-this.parameters.aspect));this.constraint=new M(t,at(this.parameters.rule),0,ht(this.parameters.power)),this.layer[K](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Nt extends ot{constructor(t,i,n){var s,o,r;Vt(t,i),super(i.layer,new Set(t instanceof At?[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!==(r=null==n?void 0:n.verticalAnchor)&&void 0!==r?r:.5,orientation:st(null==n?void 0:n.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[W](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){this.constraintX=new M(new S(this.elementOne[A]).plus(new S(this.elementOne[F]).multiply(this.parameters.horizontalAnchor)),T.Eq,new S(this.elementTwo[A]).plus(new S(this.elementTwo[F]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new M(new S(this.elementOne[j]).plus(new S(this.elementOne[V]).multiply(this.parameters.verticalAnchor)),T.Eq,new S(this.elementTwo[j]).plus(new S(this.elementTwo[V]).multiply(this.parameters.verticalAnchor))),this.constraintW=new M(new S(this.elementOne[F]),T.Le,new S(this.elementTwo[F])),this.constraintH=new M(new S(this.elementOne[V]),T.Le,new S(this.elementTwo[V])),this.layer[K](this,this.constraintX),this.layer[K](this,this.constraintY),this.layer[K](this,this.constraintW),this.layer[K](this,this.constraintH),this.parameters.isStrict||(this.constraintStrict=new M(new S(this.elementOne[V]),T.Eq,new S(this.elementTwo[V]),k.strong),this.layer[K](this,this.constraintStrict))}destroyConstraints(){this.constraintX&&(this.layer[R](this,this.constraintX),this.constraintX=void 0),this.constraintY&&(this.layer[R](this,this.constraintY),this.constraintY=void 0),this.constraintW&&(this.layer[R](this,this.constraintW),this.constraintW=void 0),this.constraintH&&(this.layer[R](this,this.constraintH),this.constraintH=void 0),this.constraintStrict&&(this.layer[R](this,this.constraintStrict),this.constraintStrict=void 0)}}function Wt(t){return null!==t&&"object"==typeof t&&("x"in t&&"number"==typeof t.x||"y"in t&&"number"==typeof t.y)}function qt(t){return null!==t&&"object"==typeof t&&("x"in t&&rt(t.x)||"y"in t&&rt(t.y))}function Gt(t){return null!==t&&"object"==typeof t&&("x"in t&&ut(t.x)||"y"in t&&ut(t.y))}function Qt(t){return null!==t&&"object"==typeof t&&"elementOne"in t&&"elementTwo"in t&&(t.elementOne instanceof At||t.elementOne instanceof Ft)&&t.elementTwo instanceof At}function Jt(t){return Qt(t)&&"distance"in t&&Wt(t.distance)&&(!("anchorOne"in t)||"anchorOne"in t&&Wt(t.anchorOne))&&(!("anchorTwo"in t)||"anchorTwo"in t&&Wt(t.anchorTwo))&&(!("power"in t)||qt(t.power))&&(!("rule"in t)||Gt(t.rule))&&(!("orientation"in t)||nt(t.orientation))}function Zt(t){return Qt(t)&&"proportion"in t&&Wt(t.proportion)&&(!("power"in t)||qt(t.power))&&(!("rule"in t)||Gt(t.rule))&&(!("orientation"in t)||nt(t.orientation))}function ti(t){return Qt(t)&&"isStrict"in t&&"boolean"==typeof t.isStrict&&(!("anchor"in t)||"anchor"in t&&Wt(t.anchor))}function ii(t){return null!==t&&"object"==typeof t&&"element"in t&&t.element instanceof At&&(!("power"in t)||rt(t.power))&&(!("rule"in t)||ut(t.rule))}function ni(t){return ii(t)&&"height"in t&&"number"==typeof t.height}function si(t){return ii(t)&&"keepAspect"in t&&"boolean"==typeof t.keepAspect}function oi(t){return ii(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(ii(s=o)&&"width"in s&&"number"==typeof s.width)ri.buildWidthConstraint(t,o,n);else if(ni(o))ri.buildHeightConstraint(t,o,n);else if(si(o))ri.buildKeepAspectConstraint(t,o,n);else if(oi(o))ri.buildKeepSizeConstraint(t,o,n);else if(Jt(o))ri.buildDistanceConstraint(t,o,n);else if(Zt(o))ri.buildProportionalConstraint(t,o,n);else{if(!ti(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 Rt(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 Yt(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 Rt(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,r,e,h,u,l,a;if("number"==typeof i.distance.x){const h=t.replace(/(HorizontalDistance|Distance)$/,"")+"HorizontalDistance";n.set(h,new Ht(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===(r=i.power)||void 0===r?void 0:r.x,rule:null===(e=i.rule)||void 0===e?void 0:e.x,orientation:i.orientation}))}if("number"==typeof i.distance.y){const s=t.replace(/(VerticalDistance|Distance)$/,"")+"VerticalDistance";n.set(s,new Lt(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,r,e;if("number"==typeof i.proportion.x){const r=t.replace(/(HorizontalProportional|HorizontalProportion|Proportional|Proportion)$/,"")+"HorizontalProportion";n.set(r,new _t(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 Kt(i.elementOne,i.elementTwo,{proportion:i.proportion.y,power:null===(r=i.power)||void 0===r?void 0:r.y,rule:null===(e=i.rule)||void 0===e?void 0:e.y,orientation:i.orientation}))}}static buildCoverConstraint(t,i,n){var s,o;n.set(t,new Nt(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 ei;(t=>{t[t.FROM_LEFT_TOP=0]="FROM_LEFT_TOP",t[t.FROM_LEFT_BOTTOM=1]="FROM_LEFT_BOTTOM"})(ei||(ei={}));class hi{static build(t,i,n,s={}){var o;const r=null!==(o=s.direction)&&void 0!==o?o:ei.FROM_LEFT_TOP,e=[],h=[];e.push(new Ht(t,i,{anchorOne:0,anchorTwo:0,distance:0,power:s.power,orientation:s.orientation}),new Ht(t,n,{anchorOne:1,anchorTwo:1,distance:0,power:s.power,orientation:s.orientation}));const u=r===ei.FROM_LEFT_TOP?1:0,l=r===ei.FROM_LEFT_TOP?0:1;return h.push(new Lt(t,i,{anchorOne:u,anchorTwo:u,distance:0,power:s.power,orientation:s.orientation}),new Lt(t,n,{anchorOne:l,anchorTwo:l,distance:0,power:s.power,orientation:s.orientation})),{horizontalDistances:e,verticalDistances:h}}}class ui{static buildHorizontal(t,i){return this.buildStack(t,i,{distanceConstraint:Ht,proportionConstraint:_t,centerDistanceConstraint:Lt})}static buildVertical(t,i){return this.buildStack(t,i,{distanceConstraint:Lt,proportionConstraint:Kt,centerDistanceConstraint:Ht})}static buildStack(t,i,n){const s=[],o=[],r=[];for(let e=0;e<t.length-1;e++){const h=t[e],u=t[e+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&&r.push(new n.centerDistanceConstraint(h,u,{power:i.power,anchorOne:0,anchorTwo:0,orientation:i.orientation}))}return{distanceConstraints:s,proportionConstraints:o,alignmentConstraints:r}}}class li extends At{constructor(t,i=1e3,n=1e3){super(t,new f,0,0,i,n),this.flushTransform()}[Q](){this.flushTransform()}}class ai extends s{constructor(t){super({uniforms:o.merge([{map:{value:t},opacity:{value:1},color:{value:new v(1,1,1)},uvTransform:{value:new w}}]),vertexShader:"\n uniform mat3 uvTransform;\n varying vec2 vUv;\n void main() {\n vUv = (uvTransform * vec3(uv, 1)).xy;\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,fog:0,lights:0})}getTexture(){return this.uniforms.map.value}getColor(){return this.uniforms.color.value}getOpacity(){return this.uniforms.opacity.value}getUVTransform(){return this.uniforms.uvTransform.value}setTexture(t){this.uniforms.map.value=t,this.uniformsNeedUpdate=1}setColor(t){this.uniforms.color.value=t,this.uniformsNeedUpdate=1}setOpacity(t){this.uniforms.opacity.value=t,this.uniformsNeedUpdate=1}setUVTransform(t){this.uniforms.uvTransform.value=t,this.uniformsNeedUpdate=1}}class ci extends At{constructor(t,i){var n,s;const o=null===(n=i.image)||void 0===n?void 0:n.width,r=null===(s=i.image)||void 0===s?void 0:s.height;Bt(o,r,`Invalid image dimensions - texture "${i.name||"unnamed"}" has invalid width (${o}) or height (${r}). Image dimensions must be non-zero positive numbers.`);const e=new ai(i);super(t,new h(bt,e),0,0,o,r),this.material=e,this.textureInternal=i,this.flushTransform()}get texture(){return this.material.getTexture()}get color(){return this.material.getColor()}get opacity(){return this.material.getOpacity()}set color(t){this.material.setColor(t)}set opacity(t){this.material.setOpacity(t)}destroy(){this.material.dispose(),super.destroy()}[Q](t){this.flushTransform(),this.object.material=this.composer.renderByMaterial(t,this.textureInternal.image.width,this.textureInternal.image.height,this.material)}}class di extends s{constructor(t,i){super({uniforms:o.merge([{map:{value:t},foreground:{value:i},progress:{value:1},backgroundColor:{value:new v(1,1,1)},foregroundColor:{value:new v(1,1,1)},color:{value:new v(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 map;\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(map, 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,fog:0,lights:0})}getProgress(){return this.uniforms.progress.value}getBackgroundTexture(){return this.uniforms.map.value}getForegroundTexture(){return this.uniforms.foreground.value}getBackgroundColor(){return this.uniforms.backgroundColor.value}getForegroundColor(){return this.uniforms.foregroundColor.value}getColor(){return this.uniforms.color.value}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.map.value=t,this.uniformsNeedUpdate=1}setForegroundTexture(t){this.uniforms.foreground.value=t,this.uniformsNeedUpdate=1}setBackgroundColor(t){this.uniforms.backgroundColor.value=t,this.uniformsNeedUpdate=1}setForegroundColor(t){this.uniforms.foregroundColor.value=t,this.uniformsNeedUpdate=1}setColor(t){this.uniforms.color.value=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 At{constructor(t,i,n){var s,o,r,e;const u=null===(s=i.image)||void 0===s?void 0:s.width,l=null===(o=i.image)||void 0===o?void 0:o.height;Bt(u,l,`Invalid image dimensions - texture "${i.name||"unnamed"}" has invalid width (${u}) or height (${l}). Image dimensions must be non-zero positive numbers.`);const a=null===(r=n.image)||void 0===r?void 0:r.width,c=null===(e=n.image)||void 0===e?void 0:e.height;Bt(a,c,`Invalid image dimensions - texture "${n.name||"unnamed"}" has invalid width (${a}) or height (${c}). Image dimensions must be non-zero positive numbers.`);const d=new di(i,n);super(t,new h(bt,d),0,0,u,l),this.material=d,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 commonOpacity(){return this.material.getOpacity()}get angle(){return this.material.getAngle()}get isForwardDirection(){return this.material.getIsForwardDirection()}set progress(t){this.material.setProgress(t)}set backgroundTexture(t){this.material.setBackgroundTexture(t)}set foregroundTexture(t){this.material.setForegroundTexture(t)}set backgroundColor(t){this.material.setBackgroundColor(t)}set foregroundColor(t){this.material.setForegroundColor(t)}set color(t){this.material.setColor(t)}set backgroundOpacity(t){this.material.setBackgroundOpacity(t)}set foregroundOpacity(t){this.material.setForegroundOpacity(t)}set commonOpacity(t){this.material.setOpacity(t)}set angle(t){this.material.setAngle(t)}set isForwardDirection(t){this.material.setIsForwardDirection(t)}destroy(){this.material.dispose(),super.destroy()}[Q](t){this.flushTransform(),this.object.material=this.composer.renderByMaterial(t,this.material.getBackgroundTexture().image.width,this.material.getBackgroundTexture().image.height,this.material)}}function fi(t,i){var n,s,o,r,e,h,u,l,a,c,d,v,f,w,p,g,m,y,b,x,C,S,E,T,k,O,M,D;const I=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),z=null!==(r=null!==(o=null==t?void 0:t.lineHeight)&&void 0!==o?o:null==i?void 0:i.lineHeight)&&void 0!==r?r:1.2*I,P=Math.max(null!==(h=null!==(e=null==t?void 0:t.shadowBlur)&&void 0!==e?e:null==i?void 0:i.shadowBlur)&&void 0!==h?h:0,0),$=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:I,fontStyle:null!==(w=null!==(f=null==t?void 0:t.fontStyle)&&void 0!==f?f:null==i?void 0:i.fontStyle)&&void 0!==w?w:"normal",fontWeight:null!==(g=null!==(p=null==t?void 0:t.fontWeight)&&void 0!==p?p:null==i?void 0:i.fontWeight)&&void 0!==g?g:"normal",lineHeight:z,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:P,shadowColor:null!==(T=null!==(E=null==t?void 0:t.shadowColor)&&void 0!==E?E:null==i?void 0:i.shadowColor)&&void 0!==T?T:"transparent",enableStroke:null!==(O=null!==(k=null==t?void 0:t.enableStroke)&&void 0!==k?k:null==i?void 0:i.enableStroke)&&void 0!==O?O:0,strokeColor:null!==(D=null!==(M=null==t?void 0:t.strokeColor)&&void 0!==M?M:null==i?void 0:i.strokeColor)&&void 0!==D?D:"transparent",strokeWidth:$}}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,r=Math.ceil(s.actualBoundingBoxAscent+s.actualBoundingBoxDescent);return{width:Math.ceil(o),height:r,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 At{constructor(t,i,n={}){var s;const o=document.createElement("canvas"),r=o.getContext("2d");if(!r)throw Error("Failed to create canvas context");const e=[],u=Array.isArray(i)?i:[i];for(const t of u){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(r,t,o);e.push({text:t,style:o,metrics:i})}}const l=((t,i)=>{const n=[];let s=[],o=0,r=0,e=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,r=Math.max(r,u.metrics.height),e=Math.max(e,u.metrics.baseline),h=Math.max(h,u.metrics.lineHeight)):(n.push({chunks:s,width:o,height:r,baseline:e,lineHeight:h}),s=[u],o=u.metrics.width,r=u.metrics.height,e=u.metrics.baseline,h=u.metrics.lineHeight):(s.length>0&&n.push({chunks:s,width:o,height:r,baseline:e,lineHeight:h}),s=[],o=0,r=0,e=0,h=0);return s.length>0&&n.push({chunks:s,width:o,height:r,baseline:e,lineHeight:h}),n})(null!==(s=n.maxWidth)&&void 0!==s?s:1024,e),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 ai(d);super(t,new h(bt,v),0,0,a.width,a.height),this.lastSuggestedAspect=0,this.material=v,this.texture=d,this.canvas=o,this.context=r,this.textBlockSize=a,this.padding=c,((t,i,n,s)=>{let o=this.padding.top;for(let t=0;t<n.length;t++){const r=n[t];let e=i;o+=0===t?r.height:r.lineHeight;for(const t of r.chunks)gi(e,o,t.text,t.style,s),e+=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)}set opacity(t){this.material.setOpacity(t)}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[N](this,this[V],this.width/((this.textBlockSize.width+this.padding.left+this.padding.right)/(this.textBlockSize.height+this.padding.top+this.padding.bottom))))}[Q](t){this.flushTransform(),this.object.material=this.composer.renderByMaterial(t,this.texture.image.width,this.texture.image.height,this.material)}}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,r]of n){if(s.has(i))throw Error(`Duplicate element key "${i}" - each UI element must have a unique identifier`);let n;if(r instanceof g)n=new ci(t,r);else if(null!==(o=r)&&"object"==typeof o&&"texture"in o&&o.texture instanceof g)n=new ci(t,r.texture);else if("string"==typeof r)n=new mi(t,[r]);else if(yi(r))n=new vi(t,r.background,r.foreground);else if(bi(r))n=new mi(t,[r.text],{defaultStyle:r.style});else if(xi(r))n=new mi(t,r.spans,{defaultStyle:r.defaultStyle});else{if(!Ci(r))throw Error(`Invalid UI element type for "${i}". Expected one of: Texture, UIImage, String, UITextDescription, or UITextEnhancedDescription`);n=new li(t,r.width,r.height)}s.set(i,n)}var o;return Object.fromEntries(s)}}class Ei extends ot{constructor(t,i,n){var s,o,r;super(i.layer,new Set(t instanceof At?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,Vt(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!==(r=null==n?void 0:n.verticalAnchor)&&void 0!==r?r:.5,orientation:st(null==n?void 0:n.orientation)},this.parameters.orientation!==Z.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[W](t){this.parameters.orientation!==Z.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[q](t){this.parameters.orientation!==Z.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){this.constraintX=new M(new S(this.elementOne[A]).plus(new S(this.elementOne[F]).multiply(this.parameters.horizontalAnchor)),T.Eq,new S(this.elementTwo[A]).plus(new S(this.elementTwo[F]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new M(new S(this.elementOne[j]).plus(new S(this.elementOne[V]).multiply(this.parameters.verticalAnchor)),T.Eq,new S(this.elementTwo[j]).plus(new S(this.elementTwo[V]).multiply(this.parameters.verticalAnchor))),this.constraintW=new M(new S(this.elementOne[F]),T.Ge,new S(this.elementTwo[F])),this.constraintH=new M(new S(this.elementOne[V]),T.Ge,new S(this.elementTwo[V])),this.layer[K](this,this.constraintX),this.layer[K](this,this.constraintY),this.layer[K](this,this.constraintW),this.layer[K](this,this.constraintH),0!=this.parameters.isStrict&&(this.constraintStrict=new M(new S(this.elementOne[V]),T.Eq,new S(this.elementTwo[V]),k.strong),this.layer[K](this,this.constraintStrict))}destroyConstraints(){this.constraintX&&(this.layer[R](this,this.constraintX),this.constraintX=void 0),this.constraintY&&(this.layer[R](this,this.constraintY),this.constraintY=void 0),this.constraintW&&(this.layer[R](this,this.constraintW),this.constraintW=void 0),this.constraintH&&(this.layer[R](this,this.constraintH),this.constraintH=void 0),this.constraintStrict&&(this.layer[R](this,this.constraintStrict),this.constraintStrict=void 0)}}class Ti extends Ft{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!==wt.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 ki extends Ft{click(t,i){this.clickInternal(t,i)}resize(t,i){this.resizeInternal(t,i)}}class Oi{}export{Yt as UIAspectConstraint,wt as UIBehavior,Xt as UIConstraint2DBuilder,ri as UIConstraintBuilder,hi as UIConstraintContainerBuilder,ei as UIConstraintContainerDirection,tt as UIConstraintPower,it as UIConstraintRule,ui as UIConstraintStackBuilder,Nt as UICoverConstraint,li as UIDummy,Si as UIElementBuilder,It as UIElementEvent,Ei as UIFitConstraint,Ti as UIFullScreenLayer,St as UIFullScreenQuad,ct as UIHeightConstraint,Ht as UIHorizontalDistanceConstraint,_t as UIHorizontalProportionConstraint,ci as UIImage,ki as UIManualLayer,Z as UIOrientation,Oi as UIPass,vi as UIProgress,mi as UIText,Lt as UIVerticalDistanceConstraint,Kt as UIVerticalProportionConstraint,Rt as UIWidthConstraint};
2
2
  //# sourceMappingURL=index.js.map