laymur 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Elements/UIElement.d.ts +1 -0
- package/dist/Elements/UIImage.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -14,6 +14,7 @@ export declare enum UIElementEvent {
|
|
|
14
14
|
export declare abstract class UIElement extends Eventail {
|
|
15
15
|
readonly layer: UILayer;
|
|
16
16
|
protected readonly object: Object3D;
|
|
17
|
+
name: string;
|
|
17
18
|
readonly micro: UIMicroTransformations;
|
|
18
19
|
[xSymbol]: Variable;
|
|
19
20
|
[ySymbol]: Variable;
|
|
@@ -4,10 +4,12 @@ import { renderSymbol } from "../Miscellaneous/symbols";
|
|
|
4
4
|
import { UIElement } from "./UIElement";
|
|
5
5
|
export declare class UIImage extends UIElement {
|
|
6
6
|
private readonly material;
|
|
7
|
-
private readonly
|
|
7
|
+
private readonly textureInternal;
|
|
8
8
|
constructor(layer: UILayer, texture: Texture);
|
|
9
|
+
get texture(): Texture;
|
|
9
10
|
get color(): Color;
|
|
10
11
|
get opacity(): number;
|
|
12
|
+
set texture(value: Texture);
|
|
11
13
|
set color(value: Color);
|
|
12
14
|
set opacity(value: number);
|
|
13
15
|
destroy(): void;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Vector2 as t,Box2 as i,MathUtils as s,PlaneGeometry as n,Scene as r,Mesh as o,OrthographicCamera as e,ShaderMaterial as h,UniformsUtils as l,Matrix3 as a,Color as u,WebGLRenderTarget as c,UnsignedByteType as d,LinearFilter as v,RGBAFormat as f,Object3D as w,CanvasTexture as p,Texture as m}from"three";function y(){return new b}var b=function(){function t(){this.index={},this.array=[]}return t.prototype.size=function(){return this.array.length},t.prototype.empty=function(){return 0===this.array.length},t.prototype.itemAt=function(t){return this.array[t]},t.prototype.contains=function(t){return void 0!==this.index[t.id()]},t.prototype.find=function(t){var i=this.index[t.id()];return void 0===i?void 0:this.array[i]},t.prototype.setDefault=function(t,i){var s=this.index[t.id()];if(void 0===s){var n=new g(t,i());return this.index[t.id()]=this.array.length,this.array.push(n),n}return this.array[s]},t.prototype.insert=function(t,i){var s=new g(t,i),n=this.index[t.id()];return void 0===n?(this.index[t.id()]=this.array.length,this.array.push(s)):this.array[n]=s,s},t.prototype.erase=function(t){var i=this.index[t.id()];if(void 0!==i){this.index[t.id()]=void 0;var s=this.array[i],n=this.array.pop();return s!==n&&(this.array[i]=n,this.index[n.first.id()]=i),s}},t.prototype.copy=function(){for(var i=new t,s=0;s<this.array.length;s++){var n=this.array[s].copy();i.array[s]=n,i.index[n.first.id()]=s}return i},t}(),g=function(){function t(t,i){this.first=t,this.second=i}return t.prototype.copy=function(){return new t(this.first,this.second)},t}(),S=function(){function t(t){void 0===t&&(t=""),this.t=0,this.i=null,this.o=E++,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 x(this,t)},t.prototype.minus=function(t){return new x(this,"number"==typeof t?-t:[-1,t])},t.prototype.multiply=function(t){return new x([t,this])},t.prototype.divide=function(t){return new x([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}(),E=0,x=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,s=this.l.size();i<s;i++){var n=this.l.itemAt(i);t+=n.first.value()*n.second}return t},t.prototype.plus=function(i){return new t(this,i)},t.prototype.minus=function(i){return new t(this,"number"==typeof i?-i:[-1,i])},t.prototype.multiply=function(i){return new t([i,this])},t.prototype.divide=function(i){return new t([1/i,this])},t.prototype.isConstant=function(){return 0==this.l.size()},t.prototype.toString=function(){var t=this.l.array.map((t=>t.second+"*"+t.first)).join(" + ");return this.isConstant()||0===this.u||(t+=" + "),t+this.u},t}();function C(t){for(var i=0,s=()=>0,n=y(),r=0,o=t.length;r<o;++r){var e=t[r];if("number"==typeof e)i+=e;else if(e instanceof S)n.setDefault(e,s).second+=1;else if(e instanceof x){i+=e.constant();for(var h=0,l=(d=e.terms()).size();h<l;h++){var a=d.itemAt(h);n.setDefault(a.first,s).second+=a.second}}else{if(!(e instanceof Array))throw Error("invalid Expression argument: "+e);if(2!==e.length)throw Error("array must have length 2");var u=e[0],c=e[1];if("number"!=typeof u)throw Error("array item 0 must be a number");if(c instanceof S)n.setDefault(c,s).second+=u;else{if(!(c instanceof x))throw Error("array item 1 must be a variable or expression");var d;for(i+=c.constant()*u,h=0,l=(d=c.terms()).size();h<l;h++)a=d.itemAt(h),n.setDefault(a.first,s).second+=a.second*u}}}return{terms:n,constant:i}}var T,M=(()=>{function t(){}return t.create=(t,i,s,n)=>{void 0===n&&(n=1);var r=0;return r+=1e6*Math.max(0,Math.min(1e3,t*n)),(r+=1e3*Math.max(0,Math.min(1e3,i*n)))+Math.max(0,Math.min(1e3,s*n))},t.clip=i=>Math.max(0,Math.min(t.required,i)),t.required=t.create(1e3,1e3,1e3),t.strong=t.create(1,0,0),t.medium=t.create(0,1,0),t.weak=t.create(0,0,1),t})();(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(T||(T={}));var z,O=function(){function t(t,i,s,n){void 0===n&&(n=M.required),this.o=D++,this.v=i,this.p=M.clip(n),this.m=void 0===s&&t instanceof x?t:t.minus(s)}return t.prototype.id=function(){return this.o},t.prototype.expression=function(){return this.m},t.prototype.op=function(){return this.v},t.prototype.strength=function(){return this.p},t.prototype.toString=function(){return this.m+" "+["<=",">=","="][this.v]+" 0 ("+this.p+")"},t}(),D=0,P=function(){function t(){this.S=y(),this.C=y(),this.T=y(),this.M=y(),this.O=[],this.D=new V,this.P=null,this.I=0}return t.prototype.createConstraint=function(t,i,s,n){void 0===n&&(n=M.required);var r=new O(t,i,s,n);return this.addConstraint(r),r},t.prototype.addConstraint=function(t){if(void 0!==this.S.find(t))throw Error("duplicate constraint");var i=this.k(t),s=i.row,n=i.tag,r=this.$(s,n);if(r.type()===z.Invalid&&s.allDummies()){if(!I(s.constant()))throw Error("unsatisfiable constraint");r=n.marker}if(r.type()===z.Invalid){if(!this.V(s))throw Error("unsatisfiable constraint")}else s.solveFor(r),this.j(r,s),this.C.insert(r,s);this.S.insert(t,n),this.H(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 s=i.second.marker,n=this.C.erase(s);if(void 0===n){var r=this.U(s);if(r.type()===z.Invalid)throw Error("failed to find leaving row");(n=this.C.erase(r)).second.solveForEx(r,s),this.j(s,n.second)}this.H(this.D)},t.prototype.hasConstraint=function(t){return this.S.contains(t)},t.prototype.addEditVariable=function(t,i){if(void 0!==this.M.find(t))throw Error("duplicate edit variable");if((i=M.clip(i))===M.required)throw Error("bad required strength");var s=new x(t),n=new O(s,T.Eq,void 0,i);this.addConstraint(n);var r=this.S.find(n).second;this.M.insert(t,{tag:r,constraint:n,constant:0})},t.prototype.removeEditVariable=function(t){var i=this.M.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)},t.prototype.hasEditVariable=function(t){return this.M.contains(t)},t.prototype.suggestValue=function(t,i){var s=this.M.find(t);if(void 0===s)throw Error("unknown edit variable");var n=this.C,r=s.second,o=i-r.constant;r.constant=i;var e=r.tag.marker,h=n.find(e);if(void 0!==h)return h.second.add(-o)<0&&this.O.push(e),void this.K();var l=r.tag.other;if(void 0!==(h=n.find(l)))return h.second.add(o)<0&&this.O.push(l),void this.K();for(var a=0,u=n.size();a<u;++a){var c=n.itemAt(a),d=c.second,v=d.coefficientFor(e);0!==v&&d.add(o*v)<0&&c.first.type()!==z.External&&this.O.push(c.first)}this.K()},t.prototype.updateVariables=function(){for(var t=this.T,i=this.C,s=0,n=t.size();s<n;++s){var r=t.itemAt(s),o=i.find(r.second);r.first.setValue(void 0!==o?o.second.constant():0)}},t.prototype.B=function(t){var i=this;return this.T.setDefault(t,(()=>i.L(z.External))).second},t.prototype.k=function(t){for(var i=t.expression(),s=new V(i.constant()),n=i.terms(),r=0,o=n.size();r<o;++r){var e=n.itemAt(r);if(!I(e.second)){var h=this.B(e.first),l=this.C.find(h);void 0!==l?s.insertRow(l.second,e.second):s.insertSymbol(h,e.second)}}var a=this.D,u=t.strength(),c={marker:$,other:$};switch(t.op()){case T.Le:case T.Ge:var d=t.op()===T.Le?1:-1,v=this.L(z.Slack);if(c.marker=v,s.insertSymbol(v,d),u<M.required){var f=this.L(z.Error);c.other=f,s.insertSymbol(f,-d),a.insertSymbol(f,u)}break;case T.Eq:if(u<M.required){var w=this.L(z.Error),p=this.L(z.Error);c.marker=w,c.other=p,s.insertSymbol(w,-1),s.insertSymbol(p,1),a.insertSymbol(w,u),a.insertSymbol(p,u)}else{var m=this.L(z.Dummy);c.marker=m,s.insertSymbol(m)}}return s.constant()<0&&s.reverseSign(),{row:s,tag:c}},t.prototype.$=(t,i)=>{for(var s=t.cells(),n=0,r=s.size();n<r;++n){var o=s.itemAt(n);if(o.first.type()===z.External)return o.first}var e=i.marker.type();return(e===z.Slack||e===z.Error)&&t.coefficientFor(i.marker)<0?i.marker:((e=i.other.type())===z.Slack||e===z.Error)&&t.coefficientFor(i.other)<0?i.other:$},t.prototype.V=function(t){var i=this.L(z.Slack);this.C.insert(i,t.copy()),this.P=t.copy(),this.H(this.P);var s=I(this.P.constant());this.P=null;var n=this.C.erase(i);if(void 0!==n){var r=n.second;if(r.isConstant())return s;var o=this.F(r);if(o.type()===z.Invalid)return 0;r.solveForEx(i,o),this.j(o,r),this.C.insert(o,r)}for(var e=this.C,h=0,l=e.size();h<l;++h)e.itemAt(h).second.removeSymbol(i);return this.D.removeSymbol(i),s},t.prototype.j=function(t,i){for(var s=this.C,n=0,r=s.size();n<r;++n){var o=s.itemAt(n);o.second.substitute(t,i),o.second.constant()<0&&o.first.type()!==z.External&&this.O.push(o.first)}this.D.substitute(t,i),this.P&&this.P.substitute(t,i)},t.prototype.H=function(t){for(;;){var i=this.N(t);if(i.type()===z.Invalid)return;var s=this.R(i);if(s.type()===z.Invalid)throw Error("the objective is unbounded");var n=this.C.erase(s).second;n.solveForEx(s,i),this.j(i,n),this.C.insert(i,n)}},t.prototype.K=function(){for(var t=this.C,i=this.O;0!==i.length;){var s=i.pop(),n=t.find(s);if(void 0!==n&&n.second.constant()<0){var r=this.W(n.second);if(r.type()===z.Invalid)throw Error("dual optimize failed");var o=n.second;t.erase(s),o.solveForEx(s,r),this.j(r,o),t.insert(r,o)}}},t.prototype.N=t=>{for(var i=t.cells(),s=0,n=i.size();s<n;++s){var r=i.itemAt(s),o=r.first;if(r.second<0&&o.type()!==z.Dummy)return o}return $},t.prototype.W=function(t){for(var i=Number.MAX_VALUE,s=$,n=t.cells(),r=0,o=n.size();r<o;++r){var e=n.itemAt(r),h=e.first,l=e.second;if(l>0&&h.type()!==z.Dummy){var a=this.D.coefficientFor(h)/l;a<i&&(i=a,s=h)}}return s},t.prototype.R=function(t){for(var i=Number.MAX_VALUE,s=$,n=this.C,r=0,o=n.size();r<o;++r){var e=n.itemAt(r),h=e.first;if(h.type()!==z.External){var l=e.second,a=l.coefficientFor(t);if(a<0){var u=-l.constant()/a;u<i&&(i=u,s=h)}}}return s},t.prototype.U=function(t){for(var i=Number.MAX_VALUE,s=i,n=i,r=$,o=r,e=r,h=r,l=this.C,a=0,u=l.size();a<u;++a){var c=l.itemAt(a),d=c.second,v=d.coefficientFor(t);if(0!==v){var f=c.first;if(f.type()===z.External)h=f;else if(v<0)(w=-d.constant()/v)<s&&(s=w,o=f);else{var w;(w=d.constant()/v)<n&&(n=w,e=f)}}}return o!==r?o:e!==r?e:h},t.prototype.A=function(t,i){i.marker.type()===z.Error&&this.Y(i.marker,t.strength()),i.other.type()===z.Error&&this.Y(i.other,t.strength())},t.prototype.Y=function(t,i){var s=this.C.find(t);void 0!==s?this.D.insertRow(s.second,-i):this.D.insertSymbol(t,-i)},t.prototype.F=t=>{for(var i=t.cells(),s=0,n=i.size();s<n;++s){var r=i.itemAt(s),o=r.first.type();if(o===z.Slack||o===z.Error)return r.first}return $},t.prototype.L=function(t){return new k(t,this.I++)},t}();function I(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"})(z||(z={}));var k=function(){function t(t,i){this.o=i,this._=t}return t.prototype.id=function(){return this.o},t.prototype.type=function(){return this._},t}(),$=new k(z.Invalid,-1),V=function(){function t(t){void 0===t&&(t=0),this.X=y(),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,s=t.size();i<s;++i)if(t.itemAt(i).first.type()!==z.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),I(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 s=t.X,n=0,r=s.size();n<r;++n){var o=s.itemAt(n);this.insertSymbol(o.first,o.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,s=t.size();i<s;++i){var n=t.itemAt(i);n.second=-n.second}},t.prototype.solveFor=function(t){var i=this.X,s=-1/i.erase(t).second;this.u*=s;for(var n=0,r=i.size();n<r;++n)i.itemAt(n).second*=s},t.prototype.solveForEx=function(t,i){this.insertSymbol(t,-1),this.solveFor(i)},t.prototype.coefficientFor=function(t){var i=this.X.find(t);return void 0!==i?i.second:0},t.prototype.substitute=function(t,i){var s=this.X.erase(t);void 0!==s&&this.insertRow(i,s.second)},t}();const j=Symbol("xSymbol"),H=Symbol("ySymbol"),A=Symbol("widthSymbol"),U=Symbol("heightSymbol"),K=Symbol("addUIElementSymbol"),B=Symbol("removeUIElementSymbol"),L=Symbol("addConstraintSymbol"),F=Symbol("removeUIConstraintSymbol"),N=Symbol("addConstraintSymbol"),R=Symbol("removeConstraintSymbol"),W=Symbol("addVariableSymbol"),Y=Symbol("removeVariableSymbol"),_=Symbol("suggestVariableSymbol"),X=Symbol("disableConstraintSymbol"),q=Symbol("enableConstraintSymbol"),G=Symbol("needsRecalculation"),Q=Symbol("renderSymbol"),J=Symbol("clickSymbol");var Z,tt,it;function st(t){return null!==t&&Object.values(Z).some((i=>i===t))}function nt(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 rt{constructor(t,i){this.layer=t,this.layer[L](this,i)}destroy(){this.layer[F](this)}}function ot(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 M.create(1e3,1e3,1e3);case tt.P1:return M.create(100,0,0);case tt.P2:return M.create(10,0,0);case tt.P3:return M.create(0,100,0);case tt.P4:return M.create(0,10,0);case tt.P5:return M.create(0,0,100);case tt.P6:return M.create(0,0,10);case tt.P7:return M.create(0,0,1);default:return M.create(1e3,1e3,1e3)}}function lt(t){return null!==t&&Object.values(it).some((i=>i===t))}function at(t){return null!=t?t:it.EQUAL}function ut(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 rt{constructor(t,i){var s;super(t.layer,new Set([t])),this.element=t,this.parameters={height:null!==(s=null==i?void 0:i.height)&&void 0!==s?s:100,power:et(null==i?void 0:i.power),rule:at(null==i?void 0:i.rule),orientation:nt(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(){this.constraint=new O(new x(this.element[U]),ut(this.parameters.rule),this.parameters.height,ht(this.parameters.power)),this.layer[N](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,s,n=100){return this.addListener(t,i,s,n,0),this}once(t,i,s,n=100){return this.addListener(t,i,s,n,1),this}off(t,i,s){const n=this.listeners.get(t);if(!n)return this;if(!i)return this.listeners.delete(t),this;const r=n.filter((t=>t.callback!==i||void 0!==s&&t.context!==s));return r.length?this.listeners.set(t,r):this.listeners.delete(t),this}emit(t,...i){const s=this.listeners.get(t);if(!(null==s?void 0:s.length))return 0;for(const n of[...s])n.callback.apply(n.context,i),n.once&&this.off(t,n.callback,n.context);return 1}addListener(t,i,s,n,r){let o=this.listeners.get(t);if(o||(o=[],this.listeners.set(t,o)),o.some((t=>t.callback===i&&t.context===s)))throw Error("Event listener already exists");const e={callback:i,context:s,priority:n,once:r};let h=0;for(;h<o.length&&o[h].priority<=n;)h++;o.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 yt{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 s.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=s.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 n(1,1).translate(.5,.5,0),gt=new r,St=new o(bt);gt.add(St);class Et{constructor(t,i=0,s=0){this.materialInternal=t,this.paddingHorizontalInternal=i,this.paddingVerticalInternal=s,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){St.material=this.materialInternal,t.render(gt,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 xt{constructor(){this.screen=new Et(new h({uniforms:l.merge([{map:{value:null},opacity:{value:1},color:{value:new u(1,1,1)},uvTransform:{value:new a}}]),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,s){s<=0?(this.screen.paddingHorizontal=0,this.screen.paddingVertical=0):(this.screen.paddingHorizontal=s/t,this.screen.paddingVertical=s/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 xt;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 s=this.calculatePadding(),n=i.image.width,r=i.image.height,o=n+2*s,e=r+2*s;this.fromRenderTarget.setSize(o,e),this.toRenderTarget.setSize(o,e),this.drawPass.setPadding(n,r,s),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:n,height:r,padding:s}),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 Tt,Mt,zt,Ot,Dt,Pt,It,kt,$t,Vt;(t=>{t.CLICK="click"})(Pt||(Pt={}));class jt extends dt{constructor(t,i,s,n,r,o){super(),this.layer=t,this.object=i,this.micro=new yt,this[Tt]=new S("x"),this[Mt]=new S("y"),this[zt]=new S("width"),this[Ot]=new S("height"),this[Dt]=0,this.behaviorInternal=wt.VISIBLE,this.composer=new Ct,this.layer[K](this,this.object),this.layer[W](this,this[j],ht(tt.P7)),this.layer[W](this,this[H],ht(tt.P7)),this.layer[W](this,this[A],ht(tt.P5)),this.layer[W](this,this[U],ht(tt.P5)),this[j].setValue(s),this[H].setValue(n),this[A].setValue(r),this[U].setValue(o),this.layer[_](this,this[j],s),this.layer[_](this,this[H],n),this.layer[_](this,this[A],r),this.layer[_](this,this[U],o)}get passes(){return this.composer.passes}get x(){return this[j].value()}get y(){return this[H].value()}get width(){return this[A].value()}get height(){return this[U].value()}get zIndex(){return this.object.position.z}get behavior(){return this.behaviorInternal}set x(t){this.layer[_](this,this[j],t)}set y(t){this.layer[_](this,this[H],t)}set width(t){this.layer[_](this,this[A],t)}set height(t){this.layer[_](this,this[U],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[j]),this.layer[Y](this,this[H]),this.layer[Y](this,this[A]),this.layer[Y](this,this[U]),this.layer[B](this)}[(Tt=j,Mt=H,zt=A,Ot=U,Dt=G,J)](t,i){return this.behavior!==wt.INTERACTIVE?0:(this.flushTransform(),s=this.x,n=this.y,r=this.width,o=this.height,vt.set(t,i),ft.min.set(s,n),ft.max.set(r,o).add(ft.min),ft.containsPoint(vt)?(this.emit(Pt.CLICK,this),1):0);var s,n,r,o}flushTransform(){(this[G]||this.micro[G])&&(((t,i,s,n,r,o,e)=>{const h=s-e,l=n-e,a=r+2*e,u=o+2*e,c=h+a*i.anchorX,d=l+u*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=a*i.scaleX,t.scale.y=u*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 Ht=new u(0);class At{constructor(){this.behavior=wt.VISIBLE,this[It]=new S,this[kt]=new S,this[$t]=new S,this[Vt]=new S,this.scene=new r,this.camera=new e,this.solver=new P,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()}[(It=j,kt=H,$t=A,Vt=U,K)](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)}[B](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 s of i){const i=this.elements.get(s);if(void 0===i)throw Error("Element not found");if(i.constraints.has(t))throw Error("Something went wrong");i.constraints.add(t)}this.constraints.set(t,{elements:i,variables:new Map,constraints:new Set})}[F](t){const i=this.constraints.get(t);if(void 0===i)throw Error("Constraint not found");if(i.variables.size>0)throw Error("Variables should be removed before removing constraint");if(i.constraints.size>0)throw Error("Constraints should be removed before removing constraint");for(const s of i.elements){const i=this.elements.get(s);if(void 0===i)throw Error("Element not found");if(!i.constraints.has(t))throw Error("Something went wrong");i.constraints.delete(t)}this.constraints.delete(t)}[N](t,i){var s;const n=this.constraints.get(t);if(void 0===n)throw Error("Before adding constraint you need to add it's owner");if(n.constraints.has(i))throw Error("Constraint already exists");n.constraints.add(i),null===(s=this.solver)||void 0===s||s.addConstraint(i),this.needsRecalculation=1}[R](t,i){var s;const n=this.constraints.get(t);if(void 0===n)throw Error("Before removing constraint you need to add it's owner");if(!n.constraints.has(i))throw Error("Constraint not found");n.constraints.delete(i),null===(s=this.solver)||void 0===s||s.removeConstraint(i),this.needsRecalculation=1}[W](t,i,s){var n;const r=t instanceof jt?this.elements.get(t):this.constraints.get(t);if(void 0===r)throw Error("Before adding variable you need to add it's owner");if(r.variables.has(i))throw Error("Variable already exists");r.variables.set(i,{strength:s,suggestedValue:i.value()}),null===(n=this.solver)||void 0===n||n.addEditVariable(i,s)}[Y](t,i){var s;const n=t instanceof jt?this.elements.get(t):this.constraints.get(t);if(void 0===n)throw Error("Before removing variable you need to add it's owner");if(!n.variables.has(i))throw Error("Variable does not exist");n.variables.delete(i),null===(s=this.solver)||void 0===s||s.removeEditVariable(i)}[_](t,i,s){var n;const r=t instanceof jt?this.elements.get(t):this.constraints.get(t);if(void 0===r)throw Error("Before suggesting variable you need to add it's owner");const o=r.variables.get(i);if(!o)throw Error("Variable does not exist");o.suggestedValue!==s&&(o.suggestedValue=s,null===(n=this.solver)||void 0===n||n.suggestValue(i,s),this.needsRecalculation=1)}render(t){var i;if(this.behavior===wt.HIDDEN)return;const s=t.getRenderTarget(),n=t.getClearColor(Ht),r=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(s),t.setClearColor(n),t.setClearAlpha(r),t.render(this.scene,this.camera)}clickInternal(t,i){if(this.behavior!==wt.INTERACTIVE)return;const s=[...this.elements.keys()].filter((t=>t.behavior===wt.INTERACTIVE)).sort(((t,i)=>t.zIndex-i.zIndex));for(const n of s)if(n[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 s,n,r,o,e,h,l,a;this.constraintX&&(null===(s=this.solver)||void 0===s||s.removeConstraint(this.constraintX),this.constraintX=void 0),this.constraintY&&(null===(n=this.solver)||void 0===n||n.removeConstraint(this.constraintY),this.constraintY=void 0),this.constraintW&&(null===(r=this.solver)||void 0===r||r.removeConstraint(this.constraintW),this.constraintW=void 0),this.constraintH&&(null===(o=this.solver)||void 0===o||o.removeConstraint(this.constraintH),this.constraintH=void 0),this.constraintX=new O(new x(this[j]),T.Eq,0,M.required),this.constraintY=new O(new x(this[H]),T.Eq,0,M.required),this.constraintW=new O(new x(this[A]),T.Eq,t,M.required),this.constraintH=new O(new x(this[U]),T.Eq,i,M.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===(a=this.solver)||void 0===a||a.addConstraint(this.constraintH)}updateOrientation(t,i){const s=this.orientationPrivate;if(this.orientationPrivate=t>i?Z.LANDSCAPE:Z.PORTRAIT,s!==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 P;const t=[...this.elements.values(),...this.constraints.values()];for(const i of t)for(const[t,s]of i.variables.entries())this.solver.addEditVariable(t,s.strength),this.solver.suggestValue(t,s.suggestedValue);this.constraintX&&this.solver.addConstraint(this.constraintX),this.constraintY&&this.solver.addConstraint(this.constraintY),this.constraintW&&this.solver.addConstraint(this.constraintW),this.constraintH&&this.solver.addConstraint(this.constraintH);for(const t of this.constraints.values())for(const i of t.constraints.values())this.solver.addConstraint(i)}}}function Ut(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`)}class Kt extends rt{constructor(t,i,s){var n,r,o;Ut(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={anchorOne:null!==(n=null==s?void 0:s.anchorOne)&&void 0!==n?n:.5,anchorTwo:null!==(r=null==s?void 0:s.anchorTwo)&&void 0!==r?r:.5,distance:null!==(o=null==s?void 0:s.distance)&&void 0!==o?o:0,power:et(null==s?void 0:s.power),rule:at(null==s?void 0:s.rule),orientation:nt(null==s?void 0:s.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 x(this.elementOne[j]).plus(new x(this.elementOne[A]).multiply(this.parameters.anchorOne)),i=new x(this.elementTwo[j]).plus(new x(this.elementTwo[A]).multiply(this.parameters.anchorTwo));this.constraint=new O(i.minus(t),ut(this.parameters.rule),this.parameters.distance,ht(this.parameters.power)),this.layer[N](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Bt extends rt{constructor(t,i,s){var n;Ut(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={proportion:null!==(n=null==s?void 0:s.proportion)&&void 0!==n?n:1,power:et(null==s?void 0:s.power),rule:at(null==s?void 0:s.rule),orientation:nt(null==s?void 0:s.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 x(this.elementOne[A]).multiply(this.parameters.proportion),i=new x(this.elementTwo[A]);this.constraint=new O(t.minus(i),ut(this.parameters.rule),0,ht(this.parameters.power)),this.layer[N](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Lt extends rt{constructor(t,i,s){var n,r,o;Ut(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={anchorOne:null!==(n=null==s?void 0:s.anchorOne)&&void 0!==n?n:.5,anchorTwo:null!==(r=null==s?void 0:s.anchorTwo)&&void 0!==r?r:.5,distance:null!==(o=null==s?void 0:s.distance)&&void 0!==o?o:0,power:et(null==s?void 0:s.power),rule:at(null==s?void 0:s.rule),orientation:nt(null==s?void 0:s.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 x(this.elementOne[H]).plus(new x(this.elementOne[U]).multiply(this.parameters.anchorOne)),i=new x(this.elementTwo[H]).plus(new x(this.elementTwo[U]).multiply(this.parameters.anchorTwo));this.constraint=new O(i.minus(t),ut(this.parameters.rule),this.parameters.distance,ht(this.parameters.power)),this.layer[N](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Ft extends rt{constructor(t,i,s){var n;Ut(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={proportion:null!==(n=null==s?void 0:s.proportion)&&void 0!==n?n:1,power:et(null==s?void 0:s.power),rule:at(null==s?void 0:s.rule),orientation:nt(null==s?void 0:s.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 x(this.elementOne[U]).multiply(this.parameters.proportion),i=new x(this.elementTwo[U]);this.constraint=new O(t.minus(i),ut(this.parameters.rule),0,ht(this.parameters.power)),this.layer[N](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Nt extends rt{constructor(t,i){var s;super(t.layer,new Set([t])),this.element=t,this.parameters={width:null!==(s=null==i?void 0:i.width)&&void 0!==s?s:100,power:et(null==i?void 0:i.power),rule:at(null==i?void 0:i.rule),orientation:nt(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(){this.constraint=new O(new x(this.element[A]),ut(this.parameters.rule),this.parameters.width,ht(this.parameters.power)),this.layer[N](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Rt{static size2D(t){return{width:new Nt(t.element,{width:t.width,power:t.powerHorizontal,rule:t.ruleHorizontal,orientation:t.orientationHorizontal}),height:new ct(t.element,{height:t.height,power:t.powerVertical,rule:t.ruleVertical,orientation:t.orientationVertical})}}static distance2D(t){return{horizontal:new Kt(t.elementOne,t.elementTwo,{anchorOne:t.anchorHorizontalOne,anchorTwo:t.anchorHorizontalTwo,distance:t.distanceHorizontal,power:t.powerHorizontal,rule:t.ruleHorizontal,orientation:t.orientationHorizontal}),vertical:new Lt(t.elementOne,t.elementTwo,{anchorOne:t.anchorVerticalOne,anchorTwo:t.anchorVerticalTwo,distance:t.distanceVertical,power:t.powerVertical,rule:t.ruleVertical,orientation:t.orientationVertical})}}static proportional2D(t){return{horizontal:new Bt(t.elementOne,t.elementTwo,{proportion:t.proportionHorizontal,power:t.powerHorizontal,rule:t.ruleHorizontal,orientation:t.orientationHorizontal}),vertical:new Ft(t.elementOne,t.elementTwo,{proportion:t.proportionVertical,power:t.powerVertical,rule:t.ruleVertical,orientation:t.orientationVertical})}}}class Wt extends rt{constructor(t,i){var s;super(t.layer,new Set([t])),this.element=t,this.parameters={aspect:null!==(s=null==i?void 0:i.aspect)&&void 0!==s?s:this.element.width/this.element.height,power:et(null==i?void 0:i.power),rule:at(null==i?void 0:i.rule),orientation:nt(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 x(this.element[A]).plus(new x(this.element[U]).multiply(-this.parameters.aspect));this.constraint=new O(t,ut(this.parameters.rule),0,ht(this.parameters.power)),this.layer[N](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Yt extends rt{constructor(t,i,s){var n,r,o;Ut(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={isStrict:null!==(n=null==s?void 0:s.isStrict)&&void 0!==n?n:1,horizontalAnchor:null!==(r=null==s?void 0:s.horizontalAnchor)&&void 0!==r?r:.5,verticalAnchor:null!==(o=null==s?void 0:s.verticalAnchor)&&void 0!==o?o:.5,orientation:nt(null==s?void 0:s.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 O(new x(this.elementOne[j]).plus(new x(this.elementOne[A]).multiply(this.parameters.horizontalAnchor)),T.Eq,new x(this.elementTwo[j]).plus(new x(this.elementTwo[A]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new O(new x(this.elementOne[H]).plus(new x(this.elementOne[U]).multiply(this.parameters.verticalAnchor)),T.Eq,new x(this.elementTwo[H]).plus(new x(this.elementTwo[U]).multiply(this.parameters.verticalAnchor))),this.constraintW=new O(new x(this.elementOne[A]),T.Le,new x(this.elementTwo[A])),this.constraintH=new O(new x(this.elementOne[U]),T.Le,new x(this.elementTwo[U])),this.layer[N](this,this.constraintX),this.layer[N](this,this.constraintY),this.layer[N](this,this.constraintW),this.layer[N](this,this.constraintH),this.parameters.isStrict||(this.constraintStrict=new O(new x(this.elementOne[U]),T.Eq,new x(this.elementTwo[U]),M.strong),this.layer[N](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 _t(t){return null!==t&&"object"==typeof t&&("x"in t&&"number"==typeof t.x||"y"in t&&"number"==typeof t.y)}function Xt(t){return null!==t&&"object"==typeof t&&("x"in t&&ot(t.x)||"y"in t&&ot(t.y))}function qt(t){return null!==t&&"object"==typeof t&&("x"in t&<(t.x)||"y"in t&<(t.y))}function Gt(t){return null!==t&&"object"==typeof t&&"elementOne"in t&&"elementTwo"in t&&(t.elementOne instanceof jt||t.elementOne instanceof At)&&t.elementTwo instanceof jt}function Qt(t){return Gt(t)&&"distance"in t&&_t(t.distance)&&(!("anchorOne"in t)||"anchorOne"in t&&_t(t.anchorOne))&&(!("anchorTwo"in t)||"anchorTwo"in t&&_t(t.anchorTwo))&&(!("power"in t)||Xt(t.power))&&(!("rule"in t)||qt(t.rule))&&(!("orientation"in t)||st(t.orientation))}function Jt(t){return Gt(t)&&"proportion"in t&&_t(t.proportion)&&(!("power"in t)||Xt(t.power))&&(!("rule"in t)||qt(t.rule))&&(!("orientation"in t)||st(t.orientation))}function Zt(t){return Gt(t)&&"isStrict"in t&&"boolean"==typeof t.isStrict&&(!("anchor"in t)||"anchor"in t&&_t(t.anchor))}function ti(t){return null!==t&&"object"==typeof t&&"element"in t&&t.element instanceof jt&&(!("power"in t)||ot(t.power))&&(!("rule"in t)||lt(t.rule))}function ii(t){return ti(t)&&"height"in t&&"number"==typeof t.height}function si(t){return ti(t)&&"keepAspect"in t&&"boolean"==typeof t.keepAspect}function ni(t){return ti(t)&&"keepSize"in t&&"boolean"==typeof t.keepSize}class ri{static fromDescription(t){const i=t instanceof Map?t.entries():Object.entries(t),s=new Map;for(const[t,r]of i){if(s.has(t))throw Error(`Duplicate constraint key "${t}" - each constraint must have a unique identifier`);if(ti(n=r)&&"width"in n&&"number"==typeof n.width)ri.buildWidthConstraint(t,r,s);else if(ii(r))ri.buildHeightConstraint(t,r,s);else if(si(r))ri.buildKeepAspectConstraint(t,r,s);else if(ni(r))ri.buildKeepSizeConstraint(t,r,s);else if(Qt(r))ri.buildDistanceConstraint(t,r,s);else if(Jt(r))ri.buildProportionalConstraint(t,r,s);else{if(!Zt(r))throw Error(`Invalid constraint type for "${t}". Expected one of: Width, Height, KeepAspect, KeepSize, Distance, Proportional, or Cover constraint`);ri.buildCoverConstraint(t,r,s)}}var n;return Object.fromEntries(s)}static buildWidthConstraint(t,i,s){s.set(t,new Nt(i.element,{width:i.width,power:i.power,rule:i.rule,orientation:i.orientation}))}static buildHeightConstraint(t,i,s){s.set(t,new ct(i.element,{height:i.height,power:i.power,rule:i.rule,orientation:i.orientation}))}static buildKeepAspectConstraint(t,i,s){s.set(t,new Wt(i.element,{power:i.power,rule:i.rule,orientation:i.orientation}))}static buildKeepSizeConstraint(t,i,s){const n=t.replace(/(KeepSize|Keep)$/,"")+"KeepWidth",r=t.replace(/(KeepSize|Keep)$/,"")+"KeepHeight";s.set(n,new Nt(i.element,{power:i.power,rule:i.rule,orientation:i.orientation})),s.set(r,new ct(i.element,{power:i.power,rule:i.rule,orientation:i.orientation}))}static buildDistanceConstraint(t,i,s){var n,r,o,e,h,l,a,u;if("number"==typeof i.distance.x){const h=t.replace(/(HorizontalDistance|Distance)$/,"")+"HorizontalDistance";s.set(h,new Kt(i.elementOne,i.elementTwo,{distance:i.distance.x,anchorOne:null===(n=i.anchorOne)||void 0===n?void 0:n.x,anchorTwo:null===(r=i.anchorTwo)||void 0===r?void 0:r.x,power:null===(o=i.power)||void 0===o?void 0:o.x,rule:null===(e=i.rule)||void 0===e?void 0:e.x,orientation:i.orientation}))}if("number"==typeof i.distance.y){const n=t.replace(/(VerticalDistance|Distance)$/,"")+"VerticalDistance";s.set(n,new Lt(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===(a=i.power)||void 0===a?void 0:a.y,rule:null===(u=i.rule)||void 0===u?void 0:u.y,orientation:i.orientation}))}}static buildProportionalConstraint(t,i,s){var n,r,o,e;if("number"==typeof i.proportion.x){const o=t.replace(/(HorizontalProportional|HorizontalProportion|Proportional|Proportion)$/,"")+"HorizontalProportion";s.set(o,new Bt(i.elementOne,i.elementTwo,{proportion:i.proportion.x,power:null===(n=i.power)||void 0===n?void 0:n.x,rule:null===(r=i.rule)||void 0===r?void 0:r.x,orientation:i.orientation}))}if("number"==typeof i.proportion.y){const n=t.replace(/(VerticalProportional|VerticalProportion|Proportional|Proportion)$/,"")+"VerticalProportion";s.set(n,new Ft(i.elementOne,i.elementTwo,{proportion:i.proportion.y,power:null===(o=i.power)||void 0===o?void 0:o.y,rule:null===(e=i.rule)||void 0===e?void 0:e.y,orientation:i.orientation}))}}static buildCoverConstraint(t,i,s){var n,r;s.set(t,new Yt(i.elementOne,i.elementTwo,{isStrict:i.isStrict,horizontalAnchor:null===(n=i.anchor)||void 0===n?void 0:n.x,verticalAnchor:null===(r=i.anchor)||void 0===r?void 0:r.y}))}}class oi extends jt{constructor(t,i=100,s=100){super(t,new w,0,0,i,s),this.flushTransform()}[Q](){}}class ei extends h{constructor(t){super({uniforms:l.merge([{map:{value:t},opacity:{value:1},color:{value:new u(1,1,1)},uvTransform:{value:new a}}]),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 hi extends jt{constructor(t,i){var s,n;const r=null===(s=i.image)||void 0===s?void 0:s.width,e=null===(n=i.image)||void 0===n?void 0:n.height;((t,i,s)=>{if(t<=0||i<=0)throw Error(null!=s?s:`Invalid dimensions: width (${t}) and height (${i}) must both be positive numbers greater than 0`)})(r,e,`Invalid image dimensions - texture "${i.name||"unnamed"}" has invalid width (${r}) or height (${e}). Image dimensions must be non-zero positive numbers.`);const h=new ei(i);super(t,new o(bt,h),0,0,r,e),this.material=h,this.texture=i,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(),super.destroy()}[Q](t){this.flushTransform(),this.material.setTexture(this.composer.render(t,this.texture))}}function li(t,i){var s,n,r,o,e,h,l,a,u,c,d,v,f,w,p,m,y,b,g,S,E,x,C,T,M,z,O,D;const P=Math.max(null!==(n=null!==(s=null==t?void 0:t.fontSize)&&void 0!==s?s:null==i?void 0:i.fontSize)&&void 0!==n?n:16,1),I=null!==(o=null!==(r=null==t?void 0:t.lineHeight)&&void 0!==r?r:null==i?void 0:i.lineHeight)&&void 0!==o?o:1.2*P,k=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!==(a=null!==(l=null==t?void 0:t.strokeWidth)&&void 0!==l?l:null==i?void 0:i.strokeWidth)&&void 0!==a?a:0,0);return{color:null!==(c=null!==(u=null==t?void 0:t.color)&&void 0!==u?u: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:P,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:I,enableShadow:null!==(b=null!==(y=null==t?void 0:t.enableShadow)&&void 0!==y?y:null==i?void 0:i.enableShadow)&&void 0!==b?b:0,shadowOffsetX:null!==(S=null!==(g=null==t?void 0:t.shadowOffsetX)&&void 0!==g?g:null==i?void 0:i.shadowOffsetX)&&void 0!==S?S:0,shadowOffsetY:null!==(x=null!==(E=null==t?void 0:t.shadowOffsetY)&&void 0!==E?E:null==i?void 0:i.shadowOffsetY)&&void 0!==x?x:0,shadowBlur:k,shadowColor:null!==(T=null!==(C=null==t?void 0:t.shadowColor)&&void 0!==C?C:null==i?void 0:i.shadowColor)&&void 0!==T?T:"transparent",enableStroke:null!==(z=null!==(M=null==t?void 0:t.enableStroke)&&void 0!==M?M:null==i?void 0:i.enableStroke)&&void 0!==z?z:0,strokeColor:null!==(D=null!==(O=null==t?void 0:t.strokeColor)&&void 0!==O?O:null==i?void 0:i.strokeColor)&&void 0!==D?D:"transparent",strokeWidth:$}}function ai(t){return t.match(/\S+|\s|\n/g)||[]}function ui(t,i,s){if(t.font=`${s.fontStyle} ${s.fontWeight} ${s.fontSize}px ${s.fontFamily}`,"\n"===i)return{width:0,height:s.lineHeight,baseline:0,lineHeight:s.lineHeight};const n=t.measureText(i),r=n.width,o=Math.ceil(n.actualBoundingBoxAscent+n.actualBoundingBoxDescent);return{width:Math.ceil(r),height:o,baseline:n.actualBoundingBoxDescent,lineHeight:s.lineHeight}}function ci(t,i,s,n,r){r.font=`${n.fontStyle} ${n.fontWeight} ${n.fontSize}px ${n.fontFamily}`,n.enableShadow&&(r.shadowOffsetX=n.shadowOffsetX,r.shadowOffsetY=n.shadowOffsetY,r.shadowBlur=n.shadowBlur,r.shadowColor=n.shadowColor),n.enableStroke&&(r.strokeStyle=n.strokeColor,r.lineWidth=n.strokeWidth,r.strokeText(s,t,i)),r.fillStyle=n.color,r.fillText(s,t,i)}class di extends jt{constructor(t,i,s={}){var n;const r=document.createElement("canvas"),e=r.getContext("2d");if(!e)throw Error("Failed to create canvas context");const h=[];for(const t of i){const i="string"==typeof t,n=i?t:t.text,r=li(i?void 0:t.style,s.defaultStyle);for(const t of ai(n)){const i=ui(e,t,r);h.push({text:t,style:r,metrics:i})}}const l=((t,i)=>{const s=[];let n=[],r=0,o=0,e=0,h=0;for(const l of i)"\n"!==l.text?r+l.metrics.width<=t||0===n.length?(n.push(l),r+=l.metrics.width,o=Math.max(o,l.metrics.height),e=Math.max(e,l.metrics.baseline),h=Math.max(h,l.metrics.lineHeight)):(s.push({chunks:n,width:r,height:o,baseline:e,lineHeight:h}),n=[l],r=l.metrics.width,o=l.metrics.height,e=l.metrics.baseline,h=l.metrics.lineHeight):(n.length>0&&s.push({chunks:n,width:r,height:o,baseline:e,lineHeight:h}),n=[],r=0,o=0,e=0,h=0);return n.length>0&&s.push({chunks:n,width:r,height:o,baseline:e,lineHeight:h}),s})(null!==(n=s.maxWidth)&&void 0!==n?n:1024,h),a=(t=>{if(0===t.length)return{width:0,height:0};const i=Math.max(...t.map((t=>t.width)));let s=0;for(let i=0;i<t.length;i++){const n=t[i];s+=0===i?n.height:n.lineHeight,i===t.length-1&&(s+=n.baseline)}return{width:i,height:s}})(l),u=(t=>{var i,s,n,r;return"number"==typeof t?{left:t,right:t,top:t,bottom:t}:{left:Math.max(null!==(i=null==t?void 0:t.left)&&void 0!==i?i:0,0),right:Math.max(null!==(s=null==t?void 0:t.right)&&void 0!==s?s:0,0),top:Math.max(null!==(n=null==t?void 0:t.top)&&void 0!==n?n:0,0),bottom:Math.max(null!==(r=null==t?void 0:t.bottom)&&void 0!==r?r:0,0)}})(s.padding);r.width=a.width+u.left+u.right,r.height=a.height+u.top+u.bottom;const c=new p(r),d=new ei(c);super(t,new o(bt,d),0,0,a.width,a.height),this.lastSuggestedAspect=0,this.material=d,this.texture=c,this.canvas=r,this.context=e,this.textBlockSize=a,this.padding=u,((t,i,s,n)=>{let r=this.padding.top;for(let t=0;t<s.length;t++){const o=s[t];let e=i;r+=0===t?o.height:o.lineHeight;for(const t of o.chunks)ci(e,r,t.text,t.style,n),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[_](this,this[U],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 vi(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text}function fi(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 wi(t){return!(null===t||"object"!=typeof t||"width"in t&&"number"!=typeof t.width||"height"in t&&"number"!=typeof t.height)}class pi{static fromDescription(t,i){const s=i instanceof Map?i.entries():Object.entries(i),n=new Map;for(const[i,o]of s){if(n.has(i))throw Error(`Duplicate element key "${i}" - each UI element must have a unique identifier`);let s;if(o instanceof m)s=new hi(t,o);else if(null!==(r=o)&&"object"==typeof r&&"texture"in r&&r.texture instanceof m)s=new hi(t,o.texture);else if("string"==typeof o)s=new di(t,[o]);else if(vi(o))s=new di(t,[o.text],{defaultStyle:o.style});else if(fi(o))s=new di(t,o.spans,{defaultStyle:o.defaultStyle});else{if(!wi(o))throw Error(`Invalid UI element type for "${i}". Expected one of: Texture, UIImage, String, UITextDescription, or UITextEnhancedDescription`);s=new oi(t,o.width,o.height)}n.set(i,s)}var r;return Object.fromEntries(n)}}class mi{static buildHorizontal(t){const i=[],s=[],n=[];for(let r=0;r<t.elements.length-1;r++){const o=t.elements[r],e=t.elements[r+1];i.push(new Kt(o,e,{anchorOne:1,anchorTwo:0,distance:t.offset,power:t.power})),s.push(new Bt(o,e,{power:t.power})),0!=t.keepAlignment&&n.push(new Lt(o,e,{power:t.power,anchorOne:0,anchorTwo:0}))}return{dummy:0!=t.createDummy?mi.createDummy(t.elements[0],t.elements[t.elements.length-1]):void 0,distanceConstraints:i,proportionConstraints:s,centerConstraints:n}}static buildVertical(t){const i=[],s=[],n=[];for(let r=0;r<t.elements.length-1;r++){const o=t.elements[r],e=t.elements[r+1];i.push(new Lt(o,e,{anchorOne:1,anchorTwo:0,distance:t.offset,power:t.power})),s.push(new Ft(o,e,{power:t.power})),0!=t.keepAlignment&&n.push(new Kt(o,e,{power:t.power}))}return{dummy:0!=t.createDummy?mi.createDummy(t.elements[0],t.elements[t.elements.length-1]):void 0,distanceConstraints:i,proportionConstraints:s,centerConstraints:n}}static createDummy(t,i){const s=new oi(i.layer);return new Kt(s,t,{distance:0,anchorOne:0,anchorTwo:0}),new Lt(s,t,{distance:0,anchorOne:0,anchorTwo:0}),new Kt(s,i,{distance:0,anchorOne:1,anchorTwo:1}),new Lt(s,i,{distance:0,anchorOne:1,anchorTwo:1}),s}}class yi extends rt{constructor(t,i,s){var n,r,o;super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,Ut(t,i),this.parameters={isStrict:null!==(n=null==s?void 0:s.isStrict)&&void 0!==n?n:1,horizontalAnchor:null!==(r=null==s?void 0:s.horizontalAnchor)&&void 0!==r?r:.5,verticalAnchor:null!==(o=null==s?void 0:s.verticalAnchor)&&void 0!==o?o:.5,orientation:nt(null==s?void 0:s.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 O(new x(this.elementOne[j]).plus(new x(this.elementOne[A]).multiply(this.parameters.horizontalAnchor)),T.Eq,new x(this.elementTwo[j]).plus(new x(this.elementTwo[A]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new O(new x(this.elementOne[H]).plus(new x(this.elementOne[U]).multiply(this.parameters.verticalAnchor)),T.Eq,new x(this.elementTwo[H]).plus(new x(this.elementTwo[U]).multiply(this.parameters.verticalAnchor))),this.constraintW=new O(new x(this.elementOne[A]),T.Ge,new x(this.elementTwo[A])),this.constraintH=new O(new x(this.elementOne[U]),T.Ge,new x(this.elementTwo[U])),this.layer[N](this,this.constraintX),this.layer[N](this,this.constraintY),this.layer[N](this,this.constraintW),this.layer[N](this,this.constraintH),0!=this.parameters.isStrict&&(this.constraintStrict=new O(new x(this.elementOne[U]),T.Eq,new x(this.elementTwo[U]),M.strong),this.layer[N](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 bi 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,s=i?t.clientX-i.left:t.clientX,n=i?i.bottom-t.clientY:window.innerHeight-t.clientY,r=this.calculateScale();this.clickInternal(s*r,n*r)},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 gi extends At{click(t,i){this.clickInternal(t,i)}resize(t,i){this.resizeInternal(t,i)}}class Si{}export{Wt as UIAspectConstraint,wt as UIBehavior,ri as UIConstraintBuilder,Rt as UIConstraintBuilder2D,tt as UIConstraintPower,it as UIConstraintRule,Yt as UICoverConstraint,oi as UIDummy,pi as UIElementBuilder,Pt as UIElementEvent,yi as UIFitConstraint,bi as UIFullScreenLayer,Et as UIFullScreenQuad,ct as UIHeightConstraint,Kt as UIHorizontalDistanceConstraint,Bt as UIHorizontalProportionConstraint,hi as UIImage,gi as UIManualLayer,Z as UIOrientation,Si as UIPass,mi as UIStackConstraintBuilder,di as UIText,Lt as UIVerticalDistanceConstraint,Ft as UIVerticalProportionConstraint,Nt as UIWidthConstraint};
|
|
1
|
+
import{Vector2 as t,Box2 as i,MathUtils as s,PlaneGeometry as n,Scene as r,Mesh as e,OrthographicCamera as o,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 y(){return new b}var b=function(){function t(){this.index={},this.array=[]}return t.prototype.size=function(){return this.array.length},t.prototype.empty=function(){return 0===this.array.length},t.prototype.itemAt=function(t){return this.array[t]},t.prototype.contains=function(t){return void 0!==this.index[t.id()]},t.prototype.find=function(t){var i=this.index[t.id()];return void 0===i?void 0:this.array[i]},t.prototype.setDefault=function(t,i){var s=this.index[t.id()];if(void 0===s){var n=new g(t,i());return this.index[t.id()]=this.array.length,this.array.push(n),n}return this.array[s]},t.prototype.insert=function(t,i){var s=new g(t,i),n=this.index[t.id()];return void 0===n?(this.index[t.id()]=this.array.length,this.array.push(s)):this.array[n]=s,s},t.prototype.erase=function(t){var i=this.index[t.id()];if(void 0!==i){this.index[t.id()]=void 0;var s=this.array[i],n=this.array.pop();return s!==n&&(this.array[i]=n,this.index[n.first.id()]=i),s}},t.prototype.copy=function(){for(var i=new t,s=0;s<this.array.length;s++){var n=this.array[s].copy();i.array[s]=n,i.index[n.first.id()]=s}return i},t}(),g=function(){function t(t,i){this.first=t,this.second=i}return t.prototype.copy=function(){return new t(this.first,this.second)},t}(),S=function(){function t(t){void 0===t&&(t=""),this.t=0,this.i=null,this.o=x++,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}(),x=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,s=this.l.size();i<s;i++){var n=this.l.itemAt(i);t+=n.first.value()*n.second}return t},t.prototype.plus=function(i){return new t(this,i)},t.prototype.minus=function(i){return new t(this,"number"==typeof i?-i:[-1,i])},t.prototype.multiply=function(i){return new t([i,this])},t.prototype.divide=function(i){return new t([1/i,this])},t.prototype.isConstant=function(){return 0==this.l.size()},t.prototype.toString=function(){var t=this.l.array.map((t=>t.second+"*"+t.first)).join(" + ");return this.isConstant()||0===this.u||(t+=" + "),t+this.u},t}();function C(t){for(var i=0,s=()=>0,n=y(),r=0,e=t.length;r<e;++r){var o=t[r];if("number"==typeof o)i+=o;else if(o instanceof S)n.setDefault(o,s).second+=1;else if(o instanceof E){i+=o.constant();for(var h=0,l=(d=o.terms()).size();h<l;h++){var u=d.itemAt(h);n.setDefault(u.first,s).second+=u.second}}else{if(!(o instanceof Array))throw Error("invalid Expression argument: "+o);if(2!==o.length)throw Error("array must have length 2");var a=o[0],c=o[1];if("number"!=typeof a)throw Error("array item 0 must be a number");if(c instanceof S)n.setDefault(c,s).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),n.setDefault(u.first,s).second+=u.second*a}}}return{terms:n,constant:i}}var T,M=(()=>{function t(){}return t.create=(t,i,s,n)=>{void 0===n&&(n=1);var r=0;return r+=1e6*Math.max(0,Math.min(1e3,t*n)),(r+=1e3*Math.max(0,Math.min(1e3,i*n)))+Math.max(0,Math.min(1e3,s*n))},t.clip=i=>Math.max(0,Math.min(t.required,i)),t.required=t.create(1e3,1e3,1e3),t.strong=t.create(1,0,0),t.medium=t.create(0,1,0),t.weak=t.create(0,0,1),t})();(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(T||(T={}));var z,O=function(){function t(t,i,s,n){void 0===n&&(n=M.required),this.o=D++,this.v=i,this.p=M.clip(n),this.m=void 0===s&&t instanceof E?t:t.minus(s)}return t.prototype.id=function(){return this.o},t.prototype.expression=function(){return this.m},t.prototype.op=function(){return this.v},t.prototype.strength=function(){return this.p},t.prototype.toString=function(){return this.m+" "+["<=",">=","="][this.v]+" 0 ("+this.p+")"},t}(),D=0,P=function(){function t(){this.S=y(),this.C=y(),this.T=y(),this.M=y(),this.O=[],this.D=new V,this.P=null,this.I=0}return t.prototype.createConstraint=function(t,i,s,n){void 0===n&&(n=M.required);var r=new O(t,i,s,n);return this.addConstraint(r),r},t.prototype.addConstraint=function(t){if(void 0!==this.S.find(t))throw Error("duplicate constraint");var i=this.k(t),s=i.row,n=i.tag,r=this.$(s,n);if(r.type()===z.Invalid&&s.allDummies()){if(!I(s.constant()))throw Error("unsatisfiable constraint");r=n.marker}if(r.type()===z.Invalid){if(!this.V(s))throw Error("unsatisfiable constraint")}else s.solveFor(r),this.j(r,s),this.C.insert(r,s);this.S.insert(t,n),this.H(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 s=i.second.marker,n=this.C.erase(s);if(void 0===n){var r=this.U(s);if(r.type()===z.Invalid)throw Error("failed to find leaving row");(n=this.C.erase(r)).second.solveForEx(r,s),this.j(s,n.second)}this.H(this.D)},t.prototype.hasConstraint=function(t){return this.S.contains(t)},t.prototype.addEditVariable=function(t,i){if(void 0!==this.M.find(t))throw Error("duplicate edit variable");if((i=M.clip(i))===M.required)throw Error("bad required strength");var s=new E(t),n=new O(s,T.Eq,void 0,i);this.addConstraint(n);var r=this.S.find(n).second;this.M.insert(t,{tag:r,constraint:n,constant:0})},t.prototype.removeEditVariable=function(t){var i=this.M.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)},t.prototype.hasEditVariable=function(t){return this.M.contains(t)},t.prototype.suggestValue=function(t,i){var s=this.M.find(t);if(void 0===s)throw Error("unknown edit variable");var n=this.C,r=s.second,e=i-r.constant;r.constant=i;var o=r.tag.marker,h=n.find(o);if(void 0!==h)return h.second.add(-e)<0&&this.O.push(o),void this.K();var l=r.tag.other;if(void 0!==(h=n.find(l)))return h.second.add(e)<0&&this.O.push(l),void this.K();for(var u=0,a=n.size();u<a;++u){var c=n.itemAt(u),d=c.second,v=d.coefficientFor(o);0!==v&&d.add(e*v)<0&&c.first.type()!==z.External&&this.O.push(c.first)}this.K()},t.prototype.updateVariables=function(){for(var t=this.T,i=this.C,s=0,n=t.size();s<n;++s){var r=t.itemAt(s),e=i.find(r.second);r.first.setValue(void 0!==e?e.second.constant():0)}},t.prototype.B=function(t){var i=this;return this.T.setDefault(t,(()=>i.L(z.External))).second},t.prototype.k=function(t){for(var i=t.expression(),s=new V(i.constant()),n=i.terms(),r=0,e=n.size();r<e;++r){var o=n.itemAt(r);if(!I(o.second)){var h=this.B(o.first),l=this.C.find(h);void 0!==l?s.insertRow(l.second,o.second):s.insertSymbol(h,o.second)}}var u=this.D,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.L(z.Slack);if(c.marker=v,s.insertSymbol(v,d),a<M.required){var f=this.L(z.Error);c.other=f,s.insertSymbol(f,-d),u.insertSymbol(f,a)}break;case T.Eq:if(a<M.required){var w=this.L(z.Error),p=this.L(z.Error);c.marker=w,c.other=p,s.insertSymbol(w,-1),s.insertSymbol(p,1),u.insertSymbol(w,a),u.insertSymbol(p,a)}else{var m=this.L(z.Dummy);c.marker=m,s.insertSymbol(m)}}return s.constant()<0&&s.reverseSign(),{row:s,tag:c}},t.prototype.$=(t,i)=>{for(var s=t.cells(),n=0,r=s.size();n<r;++n){var e=s.itemAt(n);if(e.first.type()===z.External)return e.first}var o=i.marker.type();return(o===z.Slack||o===z.Error)&&t.coefficientFor(i.marker)<0?i.marker:((o=i.other.type())===z.Slack||o===z.Error)&&t.coefficientFor(i.other)<0?i.other:$},t.prototype.V=function(t){var i=this.L(z.Slack);this.C.insert(i,t.copy()),this.P=t.copy(),this.H(this.P);var s=I(this.P.constant());this.P=null;var n=this.C.erase(i);if(void 0!==n){var r=n.second;if(r.isConstant())return s;var e=this.F(r);if(e.type()===z.Invalid)return 0;r.solveForEx(i,e),this.j(e,r),this.C.insert(e,r)}for(var o=this.C,h=0,l=o.size();h<l;++h)o.itemAt(h).second.removeSymbol(i);return this.D.removeSymbol(i),s},t.prototype.j=function(t,i){for(var s=this.C,n=0,r=s.size();n<r;++n){var e=s.itemAt(n);e.second.substitute(t,i),e.second.constant()<0&&e.first.type()!==z.External&&this.O.push(e.first)}this.D.substitute(t,i),this.P&&this.P.substitute(t,i)},t.prototype.H=function(t){for(;;){var i=this.N(t);if(i.type()===z.Invalid)return;var s=this.R(i);if(s.type()===z.Invalid)throw Error("the objective is unbounded");var n=this.C.erase(s).second;n.solveForEx(s,i),this.j(i,n),this.C.insert(i,n)}},t.prototype.K=function(){for(var t=this.C,i=this.O;0!==i.length;){var s=i.pop(),n=t.find(s);if(void 0!==n&&n.second.constant()<0){var r=this.W(n.second);if(r.type()===z.Invalid)throw Error("dual optimize failed");var e=n.second;t.erase(s),e.solveForEx(s,r),this.j(r,e),t.insert(r,e)}}},t.prototype.N=t=>{for(var i=t.cells(),s=0,n=i.size();s<n;++s){var r=i.itemAt(s),e=r.first;if(r.second<0&&e.type()!==z.Dummy)return e}return $},t.prototype.W=function(t){for(var i=Number.MAX_VALUE,s=$,n=t.cells(),r=0,e=n.size();r<e;++r){var o=n.itemAt(r),h=o.first,l=o.second;if(l>0&&h.type()!==z.Dummy){var u=this.D.coefficientFor(h)/l;u<i&&(i=u,s=h)}}return s},t.prototype.R=function(t){for(var i=Number.MAX_VALUE,s=$,n=this.C,r=0,e=n.size();r<e;++r){var o=n.itemAt(r),h=o.first;if(h.type()!==z.External){var l=o.second,u=l.coefficientFor(t);if(u<0){var a=-l.constant()/u;a<i&&(i=a,s=h)}}}return s},t.prototype.U=function(t){for(var i=Number.MAX_VALUE,s=i,n=i,r=$,e=r,o=r,h=r,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()===z.External)h=f;else if(v<0)(w=-d.constant()/v)<s&&(s=w,e=f);else{var w;(w=d.constant()/v)<n&&(n=w,o=f)}}}return e!==r?e:o!==r?o:h},t.prototype.A=function(t,i){i.marker.type()===z.Error&&this.Y(i.marker,t.strength()),i.other.type()===z.Error&&this.Y(i.other,t.strength())},t.prototype.Y=function(t,i){var s=this.C.find(t);void 0!==s?this.D.insertRow(s.second,-i):this.D.insertSymbol(t,-i)},t.prototype.F=t=>{for(var i=t.cells(),s=0,n=i.size();s<n;++s){var r=i.itemAt(s),e=r.first.type();if(e===z.Slack||e===z.Error)return r.first}return $},t.prototype.L=function(t){return new k(t,this.I++)},t}();function I(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"})(z||(z={}));var k=function(){function t(t,i){this.o=i,this._=t}return t.prototype.id=function(){return this.o},t.prototype.type=function(){return this._},t}(),$=new k(z.Invalid,-1),V=function(){function t(t){void 0===t&&(t=0),this.X=y(),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,s=t.size();i<s;++i)if(t.itemAt(i).first.type()!==z.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),I(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 s=t.X,n=0,r=s.size();n<r;++n){var e=s.itemAt(n);this.insertSymbol(e.first,e.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,s=t.size();i<s;++i){var n=t.itemAt(i);n.second=-n.second}},t.prototype.solveFor=function(t){var i=this.X,s=-1/i.erase(t).second;this.u*=s;for(var n=0,r=i.size();n<r;++n)i.itemAt(n).second*=s},t.prototype.solveForEx=function(t,i){this.insertSymbol(t,-1),this.solveFor(i)},t.prototype.coefficientFor=function(t){var i=this.X.find(t);return void 0!==i?i.second:0},t.prototype.substitute=function(t,i){var s=this.X.erase(t);void 0!==s&&this.insertRow(i,s.second)},t}();const j=Symbol("xSymbol"),H=Symbol("ySymbol"),A=Symbol("widthSymbol"),U=Symbol("heightSymbol"),K=Symbol("addUIElementSymbol"),B=Symbol("removeUIElementSymbol"),L=Symbol("addConstraintSymbol"),F=Symbol("removeUIConstraintSymbol"),N=Symbol("addConstraintSymbol"),R=Symbol("removeConstraintSymbol"),W=Symbol("addVariableSymbol"),Y=Symbol("removeVariableSymbol"),_=Symbol("suggestVariableSymbol"),X=Symbol("disableConstraintSymbol"),q=Symbol("enableConstraintSymbol"),G=Symbol("needsRecalculation"),Q=Symbol("renderSymbol"),J=Symbol("clickSymbol");var Z,tt,it;function st(t){return null!==t&&Object.values(Z).some((i=>i===t))}function nt(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 rt{constructor(t,i){this.layer=t,this.layer[L](this,i)}destroy(){this.layer[F](this)}}function et(t){return null!==t&&Object.values(tt).some((i=>i===t))}function ot(t){return null!=t?t:tt.P0}function ht(t){switch(t){case tt.P0:return M.create(1e3,1e3,1e3);case tt.P1:return M.create(100,0,0);case tt.P2:return M.create(10,0,0);case tt.P3:return M.create(0,100,0);case tt.P4:return M.create(0,10,0);case tt.P5:return M.create(0,0,100);case tt.P6:return M.create(0,0,10);case tt.P7:return M.create(0,0,1);default:return M.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 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 rt{constructor(t,i){var s;super(t.layer,new Set([t])),this.element=t,this.parameters={height:null!==(s=null==i?void 0:i.height)&&void 0!==s?s:100,power:ot(null==i?void 0:i.power),rule:ut(null==i?void 0:i.rule),orientation:nt(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(){this.constraint=new O(new E(this.element[U]),at(this.parameters.rule),this.parameters.height,ht(this.parameters.power)),this.layer[N](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,s,n=100){return this.addListener(t,i,s,n,0),this}once(t,i,s,n=100){return this.addListener(t,i,s,n,1),this}off(t,i,s){const n=this.listeners.get(t);if(!n)return this;if(!i)return this.listeners.delete(t),this;const r=n.filter((t=>t.callback!==i||void 0!==s&&t.context!==s));return r.length?this.listeners.set(t,r):this.listeners.delete(t),this}emit(t,...i){const s=this.listeners.get(t);if(!(null==s?void 0:s.length))return 0;for(const n of[...s])n.callback.apply(n.context,i),n.once&&this.off(t,n.callback,n.context);return 1}addListener(t,i,s,n,r){let e=this.listeners.get(t);if(e||(e=[],this.listeners.set(t,e)),e.some((t=>t.callback===i&&t.context===s)))throw Error("Event listener already exists");const o={callback:i,context:s,priority:n,once:r};let h=0;for(;h<e.length&&e[h].priority<=n;)h++;e.splice(h,0,o)}}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 yt{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 s.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=s.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 n(1,1).translate(.5,.5,0),gt=new r,St=new e(bt);gt.add(St);class xt{constructor(t,i=0,s=0){this.materialInternal=t,this.paddingHorizontalInternal=i,this.paddingVerticalInternal=s,this.camera=new o(-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){St.material=this.materialInternal,t.render(gt,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 xt(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,s){s<=0?(this.screen.paddingHorizontal=0,this.screen.paddingVertical=0):(this.screen.paddingHorizontal=s/t,this.screen.paddingVertical=s/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 s=this.calculatePadding(),n=i.image.width,r=i.image.height,e=n+2*s,o=r+2*s;this.fromRenderTarget.setSize(e,o),this.toRenderTarget.setSize(e,o),this.drawPass.setPadding(n,r,s),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:n,height:r,padding:s}),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 Tt,Mt,zt,Ot,Dt,Pt,It,kt,$t,Vt;(t=>{t.CLICK="click"})(Pt||(Pt={}));class jt extends dt{constructor(t,i,s,n,r,e){super(),this.layer=t,this.object=i,this.name="",this.micro=new yt,this[Tt]=new S("x"),this[Mt]=new S("y"),this[zt]=new S("width"),this[Ot]=new S("height"),this[Dt]=0,this.behaviorInternal=wt.VISIBLE,this.composer=new Ct,this.layer[K](this,this.object),this.layer[W](this,this[j],ht(tt.P7)),this.layer[W](this,this[H],ht(tt.P7)),this.layer[W](this,this[A],ht(tt.P5)),this.layer[W](this,this[U],ht(tt.P5)),this[j].setValue(s),this[H].setValue(n),this[A].setValue(r),this[U].setValue(e),this.layer[_](this,this[j],s),this.layer[_](this,this[H],n),this.layer[_](this,this[A],r),this.layer[_](this,this[U],e)}get passes(){return this.composer.passes}get x(){return this[j].value()}get y(){return this[H].value()}get width(){return this[A].value()}get height(){return this[U].value()}get zIndex(){return this.object.position.z}get behavior(){return this.behaviorInternal}set x(t){this.layer[_](this,this[j],t)}set y(t){this.layer[_](this,this[H],t)}set width(t){this.layer[_](this,this[A],t)}set height(t){this.layer[_](this,this[U],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[j]),this.layer[Y](this,this[H]),this.layer[Y](this,this[A]),this.layer[Y](this,this[U]),this.layer[B](this)}[(Tt=j,Mt=H,zt=A,Ot=U,Dt=G,J)](t,i){return this.behavior!==wt.INTERACTIVE?0:(this.flushTransform(),s=this.x,n=this.y,r=this.width,e=this.height,vt.set(t,i),ft.min.set(s,n),ft.max.set(r,e).add(ft.min),ft.containsPoint(vt)?(this.emit(Pt.CLICK,this),1):0);var s,n,r,e}flushTransform(){(this[G]||this.micro[G])&&(((t,i,s,n,r,e,o)=>{const h=s-o,l=n-o,u=r+2*o,a=e+2*o,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 Ht=new a(0);class At{constructor(){this.behavior=wt.VISIBLE,this[It]=new S,this[kt]=new S,this[$t]=new S,this[Vt]=new S,this.scene=new r,this.camera=new o,this.solver=new P,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()}[(It=j,kt=H,$t=A,Vt=U,K)](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)}[B](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 s of i){const i=this.elements.get(s);if(void 0===i)throw Error("Element not found");if(i.constraints.has(t))throw Error("Something went wrong");i.constraints.add(t)}this.constraints.set(t,{elements:i,variables:new Map,constraints:new Set})}[F](t){const i=this.constraints.get(t);if(void 0===i)throw Error("Constraint not found");if(i.variables.size>0)throw Error("Variables should be removed before removing constraint");if(i.constraints.size>0)throw Error("Constraints should be removed before removing constraint");for(const s of i.elements){const i=this.elements.get(s);if(void 0===i)throw Error("Element not found");if(!i.constraints.has(t))throw Error("Something went wrong");i.constraints.delete(t)}this.constraints.delete(t)}[N](t,i){var s;const n=this.constraints.get(t);if(void 0===n)throw Error("Before adding constraint you need to add it's owner");if(n.constraints.has(i))throw Error("Constraint already exists");n.constraints.add(i),null===(s=this.solver)||void 0===s||s.addConstraint(i),this.needsRecalculation=1}[R](t,i){var s;const n=this.constraints.get(t);if(void 0===n)throw Error("Before removing constraint you need to add it's owner");if(!n.constraints.has(i))throw Error("Constraint not found");n.constraints.delete(i),null===(s=this.solver)||void 0===s||s.removeConstraint(i),this.needsRecalculation=1}[W](t,i,s){var n;const r=t instanceof jt?this.elements.get(t):this.constraints.get(t);if(void 0===r)throw Error("Before adding variable you need to add it's owner");if(r.variables.has(i))throw Error("Variable already exists");r.variables.set(i,{strength:s,suggestedValue:i.value()}),null===(n=this.solver)||void 0===n||n.addEditVariable(i,s)}[Y](t,i){var s;const n=t instanceof jt?this.elements.get(t):this.constraints.get(t);if(void 0===n)throw Error("Before removing variable you need to add it's owner");if(!n.variables.has(i))throw Error("Variable does not exist");n.variables.delete(i),null===(s=this.solver)||void 0===s||s.removeEditVariable(i)}[_](t,i,s){var n;const r=t instanceof jt?this.elements.get(t):this.constraints.get(t);if(void 0===r)throw Error("Before suggesting variable you need to add it's owner");const e=r.variables.get(i);if(!e)throw Error("Variable does not exist");e.suggestedValue!==s&&(e.suggestedValue=s,null===(n=this.solver)||void 0===n||n.suggestValue(i,s),this.needsRecalculation=1)}render(t){var i;if(this.behavior===wt.HIDDEN)return;const s=t.getRenderTarget(),n=t.getClearColor(Ht),r=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(s),t.setClearColor(n),t.setClearAlpha(r),t.render(this.scene,this.camera)}clickInternal(t,i){if(this.behavior!==wt.INTERACTIVE)return;const s=[...this.elements.keys()].filter((t=>t.behavior===wt.INTERACTIVE)).sort(((t,i)=>t.zIndex-i.zIndex));for(const n of s)if(n[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 s,n,r,e,o,h,l,u;this.constraintX&&(null===(s=this.solver)||void 0===s||s.removeConstraint(this.constraintX),this.constraintX=void 0),this.constraintY&&(null===(n=this.solver)||void 0===n||n.removeConstraint(this.constraintY),this.constraintY=void 0),this.constraintW&&(null===(r=this.solver)||void 0===r||r.removeConstraint(this.constraintW),this.constraintW=void 0),this.constraintH&&(null===(e=this.solver)||void 0===e||e.removeConstraint(this.constraintH),this.constraintH=void 0),this.constraintX=new O(new E(this[j]),T.Eq,0,M.required),this.constraintY=new O(new E(this[H]),T.Eq,0,M.required),this.constraintW=new O(new E(this[A]),T.Eq,t,M.required),this.constraintH=new O(new E(this[U]),T.Eq,i,M.required),null===(o=this.solver)||void 0===o||o.addConstraint(this.constraintX),null===(h=this.solver)||void 0===h||h.addConstraint(this.constraintY),null===(l=this.solver)||void 0===l||l.addConstraint(this.constraintW),null===(u=this.solver)||void 0===u||u.addConstraint(this.constraintH)}updateOrientation(t,i){const s=this.orientationPrivate;if(this.orientationPrivate=t>i?Z.LANDSCAPE:Z.PORTRAIT,s!==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 P;const t=[...this.elements.values(),...this.constraints.values()];for(const i of t)for(const[t,s]of i.variables.entries())this.solver.addEditVariable(t,s.strength),this.solver.suggestValue(t,s.suggestedValue);this.constraintX&&this.solver.addConstraint(this.constraintX),this.constraintY&&this.solver.addConstraint(this.constraintY),this.constraintW&&this.solver.addConstraint(this.constraintW),this.constraintH&&this.solver.addConstraint(this.constraintH);for(const t of this.constraints.values())for(const i of t.constraints.values())this.solver.addConstraint(i)}}}function Ut(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`)}class Kt extends rt{constructor(t,i,s){var n,r,e;Ut(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={anchorOne:null!==(n=null==s?void 0:s.anchorOne)&&void 0!==n?n:.5,anchorTwo:null!==(r=null==s?void 0:s.anchorTwo)&&void 0!==r?r:.5,distance:null!==(e=null==s?void 0:s.distance)&&void 0!==e?e:0,power:ot(null==s?void 0:s.power),rule:ut(null==s?void 0:s.rule),orientation:nt(null==s?void 0:s.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[A]).multiply(this.parameters.anchorOne)),i=new E(this.elementTwo[j]).plus(new E(this.elementTwo[A]).multiply(this.parameters.anchorTwo));this.constraint=new O(i.minus(t),at(this.parameters.rule),this.parameters.distance,ht(this.parameters.power)),this.layer[N](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Bt extends rt{constructor(t,i,s){var n;Ut(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={proportion:null!==(n=null==s?void 0:s.proportion)&&void 0!==n?n:1,power:ot(null==s?void 0:s.power),rule:ut(null==s?void 0:s.rule),orientation:nt(null==s?void 0:s.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 O(t.minus(i),at(this.parameters.rule),0,ht(this.parameters.power)),this.layer[N](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Lt extends rt{constructor(t,i,s){var n,r,e;Ut(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={anchorOne:null!==(n=null==s?void 0:s.anchorOne)&&void 0!==n?n:.5,anchorTwo:null!==(r=null==s?void 0:s.anchorTwo)&&void 0!==r?r:.5,distance:null!==(e=null==s?void 0:s.distance)&&void 0!==e?e:0,power:ot(null==s?void 0:s.power),rule:ut(null==s?void 0:s.rule),orientation:nt(null==s?void 0:s.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]).plus(new E(this.elementOne[U]).multiply(this.parameters.anchorOne)),i=new E(this.elementTwo[H]).plus(new E(this.elementTwo[U]).multiply(this.parameters.anchorTwo));this.constraint=new O(i.minus(t),at(this.parameters.rule),this.parameters.distance,ht(this.parameters.power)),this.layer[N](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Ft extends rt{constructor(t,i,s){var n;Ut(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={proportion:null!==(n=null==s?void 0:s.proportion)&&void 0!==n?n:1,power:ot(null==s?void 0:s.power),rule:ut(null==s?void 0:s.rule),orientation:nt(null==s?void 0:s.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[U]).multiply(this.parameters.proportion),i=new E(this.elementTwo[U]);this.constraint=new O(t.minus(i),at(this.parameters.rule),0,ht(this.parameters.power)),this.layer[N](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Nt extends rt{constructor(t,i){var s;super(t.layer,new Set([t])),this.element=t,this.parameters={width:null!==(s=null==i?void 0:i.width)&&void 0!==s?s:100,power:ot(null==i?void 0:i.power),rule:ut(null==i?void 0:i.rule),orientation:nt(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(){this.constraint=new O(new E(this.element[A]),at(this.parameters.rule),this.parameters.width,ht(this.parameters.power)),this.layer[N](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Rt{static size2D(t){return{width:new Nt(t.element,{width:t.width,power:t.powerHorizontal,rule:t.ruleHorizontal,orientation:t.orientationHorizontal}),height:new ct(t.element,{height:t.height,power:t.powerVertical,rule:t.ruleVertical,orientation:t.orientationVertical})}}static distance2D(t){return{horizontal:new Kt(t.elementOne,t.elementTwo,{anchorOne:t.anchorHorizontalOne,anchorTwo:t.anchorHorizontalTwo,distance:t.distanceHorizontal,power:t.powerHorizontal,rule:t.ruleHorizontal,orientation:t.orientationHorizontal}),vertical:new Lt(t.elementOne,t.elementTwo,{anchorOne:t.anchorVerticalOne,anchorTwo:t.anchorVerticalTwo,distance:t.distanceVertical,power:t.powerVertical,rule:t.ruleVertical,orientation:t.orientationVertical})}}static proportional2D(t){return{horizontal:new Bt(t.elementOne,t.elementTwo,{proportion:t.proportionHorizontal,power:t.powerHorizontal,rule:t.ruleHorizontal,orientation:t.orientationHorizontal}),vertical:new Ft(t.elementOne,t.elementTwo,{proportion:t.proportionVertical,power:t.powerVertical,rule:t.ruleVertical,orientation:t.orientationVertical})}}}class Wt extends rt{constructor(t,i){var s;super(t.layer,new Set([t])),this.element=t,this.parameters={aspect:null!==(s=null==i?void 0:i.aspect)&&void 0!==s?s:this.element.width/this.element.height,power:ot(null==i?void 0:i.power),rule:ut(null==i?void 0:i.rule),orientation:nt(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[U]).multiply(-this.parameters.aspect));this.constraint=new O(t,at(this.parameters.rule),0,ht(this.parameters.power)),this.layer[N](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[R](this,this.constraint),this.constraint=void 0)}}class Yt extends rt{constructor(t,i,s){var n,r,e;Ut(t,i),super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={isStrict:null!==(n=null==s?void 0:s.isStrict)&&void 0!==n?n:1,horizontalAnchor:null!==(r=null==s?void 0:s.horizontalAnchor)&&void 0!==r?r:.5,verticalAnchor:null!==(e=null==s?void 0:s.verticalAnchor)&&void 0!==e?e:.5,orientation:nt(null==s?void 0:s.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 O(new E(this.elementOne[j]).plus(new E(this.elementOne[A]).multiply(this.parameters.horizontalAnchor)),T.Eq,new E(this.elementTwo[j]).plus(new E(this.elementTwo[A]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new O(new E(this.elementOne[H]).plus(new E(this.elementOne[U]).multiply(this.parameters.verticalAnchor)),T.Eq,new E(this.elementTwo[H]).plus(new E(this.elementTwo[U]).multiply(this.parameters.verticalAnchor))),this.constraintW=new O(new E(this.elementOne[A]),T.Le,new E(this.elementTwo[A])),this.constraintH=new O(new E(this.elementOne[U]),T.Le,new E(this.elementTwo[U])),this.layer[N](this,this.constraintX),this.layer[N](this,this.constraintY),this.layer[N](this,this.constraintW),this.layer[N](this,this.constraintH),this.parameters.isStrict||(this.constraintStrict=new O(new E(this.elementOne[U]),T.Eq,new E(this.elementTwo[U]),M.strong),this.layer[N](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 _t(t){return null!==t&&"object"==typeof t&&("x"in t&&"number"==typeof t.x||"y"in t&&"number"==typeof t.y)}function Xt(t){return null!==t&&"object"==typeof t&&("x"in t&&et(t.x)||"y"in t&&et(t.y))}function qt(t){return null!==t&&"object"==typeof t&&("x"in t&<(t.x)||"y"in t&<(t.y))}function Gt(t){return null!==t&&"object"==typeof t&&"elementOne"in t&&"elementTwo"in t&&(t.elementOne instanceof jt||t.elementOne instanceof At)&&t.elementTwo instanceof jt}function Qt(t){return Gt(t)&&"distance"in t&&_t(t.distance)&&(!("anchorOne"in t)||"anchorOne"in t&&_t(t.anchorOne))&&(!("anchorTwo"in t)||"anchorTwo"in t&&_t(t.anchorTwo))&&(!("power"in t)||Xt(t.power))&&(!("rule"in t)||qt(t.rule))&&(!("orientation"in t)||st(t.orientation))}function Jt(t){return Gt(t)&&"proportion"in t&&_t(t.proportion)&&(!("power"in t)||Xt(t.power))&&(!("rule"in t)||qt(t.rule))&&(!("orientation"in t)||st(t.orientation))}function Zt(t){return Gt(t)&&"isStrict"in t&&"boolean"==typeof t.isStrict&&(!("anchor"in t)||"anchor"in t&&_t(t.anchor))}function ti(t){return null!==t&&"object"==typeof t&&"element"in t&&t.element instanceof jt&&(!("power"in t)||et(t.power))&&(!("rule"in t)||lt(t.rule))}function ii(t){return ti(t)&&"height"in t&&"number"==typeof t.height}function si(t){return ti(t)&&"keepAspect"in t&&"boolean"==typeof t.keepAspect}function ni(t){return ti(t)&&"keepSize"in t&&"boolean"==typeof t.keepSize}class ri{static fromDescription(t){const i=t instanceof Map?t.entries():Object.entries(t),s=new Map;for(const[t,r]of i){if(s.has(t))throw Error(`Duplicate constraint key "${t}" - each constraint must have a unique identifier`);if(ti(n=r)&&"width"in n&&"number"==typeof n.width)ri.buildWidthConstraint(t,r,s);else if(ii(r))ri.buildHeightConstraint(t,r,s);else if(si(r))ri.buildKeepAspectConstraint(t,r,s);else if(ni(r))ri.buildKeepSizeConstraint(t,r,s);else if(Qt(r))ri.buildDistanceConstraint(t,r,s);else if(Jt(r))ri.buildProportionalConstraint(t,r,s);else{if(!Zt(r))throw Error(`Invalid constraint type for "${t}". Expected one of: Width, Height, KeepAspect, KeepSize, Distance, Proportional, or Cover constraint`);ri.buildCoverConstraint(t,r,s)}}var n;return Object.fromEntries(s)}static buildWidthConstraint(t,i,s){s.set(t,new Nt(i.element,{width:i.width,power:i.power,rule:i.rule,orientation:i.orientation}))}static buildHeightConstraint(t,i,s){s.set(t,new ct(i.element,{height:i.height,power:i.power,rule:i.rule,orientation:i.orientation}))}static buildKeepAspectConstraint(t,i,s){s.set(t,new Wt(i.element,{power:i.power,rule:i.rule,orientation:i.orientation}))}static buildKeepSizeConstraint(t,i,s){const n=t.replace(/(KeepSize|Keep)$/,"")+"KeepWidth",r=t.replace(/(KeepSize|Keep)$/,"")+"KeepHeight";s.set(n,new Nt(i.element,{power:i.power,rule:i.rule,orientation:i.orientation})),s.set(r,new ct(i.element,{power:i.power,rule:i.rule,orientation:i.orientation}))}static buildDistanceConstraint(t,i,s){var n,r,e,o,h,l,u,a;if("number"==typeof i.distance.x){const h=t.replace(/(HorizontalDistance|Distance)$/,"")+"HorizontalDistance";s.set(h,new Kt(i.elementOne,i.elementTwo,{distance:i.distance.x,anchorOne:null===(n=i.anchorOne)||void 0===n?void 0:n.x,anchorTwo:null===(r=i.anchorTwo)||void 0===r?void 0:r.x,power:null===(e=i.power)||void 0===e?void 0:e.x,rule:null===(o=i.rule)||void 0===o?void 0:o.x,orientation:i.orientation}))}if("number"==typeof i.distance.y){const n=t.replace(/(VerticalDistance|Distance)$/,"")+"VerticalDistance";s.set(n,new Lt(i.elementOne,i.elementTwo,{distance:i.distance.y,anchorOne:null===(h=i.anchorOne)||void 0===h?void 0:h.y,anchorTwo:null===(l=i.anchorTwo)||void 0===l?void 0:l.y,power:null===(u=i.power)||void 0===u?void 0:u.y,rule:null===(a=i.rule)||void 0===a?void 0:a.y,orientation:i.orientation}))}}static buildProportionalConstraint(t,i,s){var n,r,e,o;if("number"==typeof i.proportion.x){const e=t.replace(/(HorizontalProportional|HorizontalProportion|Proportional|Proportion)$/,"")+"HorizontalProportion";s.set(e,new Bt(i.elementOne,i.elementTwo,{proportion:i.proportion.x,power:null===(n=i.power)||void 0===n?void 0:n.x,rule:null===(r=i.rule)||void 0===r?void 0:r.x,orientation:i.orientation}))}if("number"==typeof i.proportion.y){const n=t.replace(/(VerticalProportional|VerticalProportion|Proportional|Proportion)$/,"")+"VerticalProportion";s.set(n,new Ft(i.elementOne,i.elementTwo,{proportion:i.proportion.y,power:null===(e=i.power)||void 0===e?void 0:e.y,rule:null===(o=i.rule)||void 0===o?void 0:o.y,orientation:i.orientation}))}}static buildCoverConstraint(t,i,s){var n,r;s.set(t,new Yt(i.elementOne,i.elementTwo,{isStrict:i.isStrict,horizontalAnchor:null===(n=i.anchor)||void 0===n?void 0:n.x,verticalAnchor:null===(r=i.anchor)||void 0===r?void 0:r.y}))}}class ei extends jt{constructor(t,i=100,s=100){super(t,new w,0,0,i,s),this.flushTransform()}[Q](){}}class oi 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 hi extends jt{constructor(t,i){var s,n;const r=null===(s=i.image)||void 0===s?void 0:s.width,o=null===(n=i.image)||void 0===n?void 0:n.height;((t,i,s)=>{if(t<=0||i<=0)throw Error(null!=s?s:`Invalid dimensions: width (${t}) and height (${i}) must both be positive numbers greater than 0`)})(r,o,`Invalid image dimensions - texture "${i.name||"unnamed"}" has invalid width (${r}) or height (${o}). Image dimensions must be non-zero positive numbers.`);const h=new oi(i);super(t,new e(bt,h),0,0,r,o),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 texture(t){this.material.setTexture(t)}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))}}function li(t,i){var s,n,r,e,o,h,l,u,a,c,d,v,f,w,p,m,y,b,g,S,x,E,C,T,M,z,O,D;const P=Math.max(null!==(n=null!==(s=null==t?void 0:t.fontSize)&&void 0!==s?s:null==i?void 0:i.fontSize)&&void 0!==n?n:16,1),I=null!==(e=null!==(r=null==t?void 0:t.lineHeight)&&void 0!==r?r:null==i?void 0:i.lineHeight)&&void 0!==e?e:1.2*P,k=Math.max(null!==(h=null!==(o=null==t?void 0:t.shadowBlur)&&void 0!==o?o:null==i?void 0:i.shadowBlur)&&void 0!==h?h:0,0),$=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:P,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:I,enableShadow:null!==(b=null!==(y=null==t?void 0:t.enableShadow)&&void 0!==y?y:null==i?void 0:i.enableShadow)&&void 0!==b?b:0,shadowOffsetX:null!==(S=null!==(g=null==t?void 0:t.shadowOffsetX)&&void 0!==g?g:null==i?void 0:i.shadowOffsetX)&&void 0!==S?S:0,shadowOffsetY:null!==(E=null!==(x=null==t?void 0:t.shadowOffsetY)&&void 0!==x?x:null==i?void 0:i.shadowOffsetY)&&void 0!==E?E:0,shadowBlur:k,shadowColor:null!==(T=null!==(C=null==t?void 0:t.shadowColor)&&void 0!==C?C:null==i?void 0:i.shadowColor)&&void 0!==T?T:"transparent",enableStroke:null!==(z=null!==(M=null==t?void 0:t.enableStroke)&&void 0!==M?M:null==i?void 0:i.enableStroke)&&void 0!==z?z:0,strokeColor:null!==(D=null!==(O=null==t?void 0:t.strokeColor)&&void 0!==O?O:null==i?void 0:i.strokeColor)&&void 0!==D?D:"transparent",strokeWidth:$}}function ui(t){return t.match(/\S+|\s|\n/g)||[]}function ai(t,i,s){if(t.font=`${s.fontStyle} ${s.fontWeight} ${s.fontSize}px ${s.fontFamily}`,"\n"===i)return{width:0,height:s.lineHeight,baseline:0,lineHeight:s.lineHeight};const n=t.measureText(i),r=n.width,e=Math.ceil(n.actualBoundingBoxAscent+n.actualBoundingBoxDescent);return{width:Math.ceil(r),height:e,baseline:n.actualBoundingBoxDescent,lineHeight:s.lineHeight}}function ci(t,i,s,n,r){r.font=`${n.fontStyle} ${n.fontWeight} ${n.fontSize}px ${n.fontFamily}`,n.enableShadow&&(r.shadowOffsetX=n.shadowOffsetX,r.shadowOffsetY=n.shadowOffsetY,r.shadowBlur=n.shadowBlur,r.shadowColor=n.shadowColor),n.enableStroke&&(r.strokeStyle=n.strokeColor,r.lineWidth=n.strokeWidth,r.strokeText(s,t,i)),r.fillStyle=n.color,r.fillText(s,t,i)}class di extends jt{constructor(t,i,s={}){var n;const r=document.createElement("canvas"),o=r.getContext("2d");if(!o)throw Error("Failed to create canvas context");const h=[];for(const t of i){const i="string"==typeof t,n=i?t:t.text,r=li(i?void 0:t.style,s.defaultStyle);for(const t of ui(n)){const i=ai(o,t,r);h.push({text:t,style:r,metrics:i})}}const l=((t,i)=>{const s=[];let n=[],r=0,e=0,o=0,h=0;for(const l of i)"\n"!==l.text?r+l.metrics.width<=t||0===n.length?(n.push(l),r+=l.metrics.width,e=Math.max(e,l.metrics.height),o=Math.max(o,l.metrics.baseline),h=Math.max(h,l.metrics.lineHeight)):(s.push({chunks:n,width:r,height:e,baseline:o,lineHeight:h}),n=[l],r=l.metrics.width,e=l.metrics.height,o=l.metrics.baseline,h=l.metrics.lineHeight):(n.length>0&&s.push({chunks:n,width:r,height:e,baseline:o,lineHeight:h}),n=[],r=0,e=0,o=0,h=0);return n.length>0&&s.push({chunks:n,width:r,height:e,baseline:o,lineHeight:h}),s})(null!==(n=s.maxWidth)&&void 0!==n?n:1024,h),u=(t=>{if(0===t.length)return{width:0,height:0};const i=Math.max(...t.map((t=>t.width)));let s=0;for(let i=0;i<t.length;i++){const n=t[i];s+=0===i?n.height:n.lineHeight,i===t.length-1&&(s+=n.baseline)}return{width:i,height:s}})(l),a=(t=>{var i,s,n,r;return"number"==typeof t?{left:t,right:t,top:t,bottom:t}:{left:Math.max(null!==(i=null==t?void 0:t.left)&&void 0!==i?i:0,0),right:Math.max(null!==(s=null==t?void 0:t.right)&&void 0!==s?s:0,0),top:Math.max(null!==(n=null==t?void 0:t.top)&&void 0!==n?n:0,0),bottom:Math.max(null!==(r=null==t?void 0:t.bottom)&&void 0!==r?r:0,0)}})(s.padding);r.width=u.width+a.left+a.right,r.height=u.height+a.top+a.bottom;const c=new p(r),d=new oi(c);super(t,new e(bt,d),0,0,u.width,u.height),this.lastSuggestedAspect=0,this.material=d,this.texture=c,this.canvas=r,this.context=o,this.textBlockSize=u,this.padding=a,((t,i,s,n)=>{let r=this.padding.top;for(let t=0;t<s.length;t++){const e=s[t];let o=i;r+=0===t?e.height:e.lineHeight;for(const t of e.chunks)ci(o,r,t.text,t.style,n),o+=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[_](this,this[U],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 vi(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text}function fi(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 wi(t){return!(null===t||"object"!=typeof t||"width"in t&&"number"!=typeof t.width||"height"in t&&"number"!=typeof t.height)}class pi{static fromDescription(t,i){const s=i instanceof Map?i.entries():Object.entries(i),n=new Map;for(const[i,e]of s){if(n.has(i))throw Error(`Duplicate element key "${i}" - each UI element must have a unique identifier`);let s;if(e instanceof m)s=new hi(t,e);else if(null!==(r=e)&&"object"==typeof r&&"texture"in r&&r.texture instanceof m)s=new hi(t,e.texture);else if("string"==typeof e)s=new di(t,[e]);else if(vi(e))s=new di(t,[e.text],{defaultStyle:e.style});else if(fi(e))s=new di(t,e.spans,{defaultStyle:e.defaultStyle});else{if(!wi(e))throw Error(`Invalid UI element type for "${i}". Expected one of: Texture, UIImage, String, UITextDescription, or UITextEnhancedDescription`);s=new ei(t,e.width,e.height)}n.set(i,s)}var r;return Object.fromEntries(n)}}class mi{static buildHorizontal(t){const i=[],s=[],n=[];for(let r=0;r<t.elements.length-1;r++){const e=t.elements[r],o=t.elements[r+1];i.push(new Kt(e,o,{anchorOne:1,anchorTwo:0,distance:t.offset,power:t.power})),s.push(new Bt(e,o,{power:t.power})),0!=t.keepAlignment&&n.push(new Lt(e,o,{power:t.power,anchorOne:0,anchorTwo:0}))}return{dummy:0!=t.createDummy?mi.createDummy(t.elements[0],t.elements[t.elements.length-1]):void 0,distanceConstraints:i,proportionConstraints:s,centerConstraints:n}}static buildVertical(t){const i=[],s=[],n=[];for(let r=0;r<t.elements.length-1;r++){const e=t.elements[r],o=t.elements[r+1];i.push(new Lt(e,o,{anchorOne:1,anchorTwo:0,distance:t.offset,power:t.power})),s.push(new Ft(e,o,{power:t.power})),0!=t.keepAlignment&&n.push(new Kt(e,o,{power:t.power}))}return{dummy:0!=t.createDummy?mi.createDummy(t.elements[0],t.elements[t.elements.length-1]):void 0,distanceConstraints:i,proportionConstraints:s,centerConstraints:n}}static createDummy(t,i){const s=new ei(i.layer);return new Kt(s,t,{distance:0,anchorOne:0,anchorTwo:0}),new Lt(s,t,{distance:0,anchorOne:0,anchorTwo:0}),new Kt(s,i,{distance:0,anchorOne:1,anchorTwo:1}),new Lt(s,i,{distance:0,anchorOne:1,anchorTwo:1}),s}}class yi extends rt{constructor(t,i,s){var n,r,e;super(i.layer,new Set(t instanceof jt?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,Ut(t,i),this.parameters={isStrict:null!==(n=null==s?void 0:s.isStrict)&&void 0!==n?n:1,horizontalAnchor:null!==(r=null==s?void 0:s.horizontalAnchor)&&void 0!==r?r:.5,verticalAnchor:null!==(e=null==s?void 0:s.verticalAnchor)&&void 0!==e?e:.5,orientation:nt(null==s?void 0:s.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 O(new E(this.elementOne[j]).plus(new E(this.elementOne[A]).multiply(this.parameters.horizontalAnchor)),T.Eq,new E(this.elementTwo[j]).plus(new E(this.elementTwo[A]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new O(new E(this.elementOne[H]).plus(new E(this.elementOne[U]).multiply(this.parameters.verticalAnchor)),T.Eq,new E(this.elementTwo[H]).plus(new E(this.elementTwo[U]).multiply(this.parameters.verticalAnchor))),this.constraintW=new O(new E(this.elementOne[A]),T.Ge,new E(this.elementTwo[A])),this.constraintH=new O(new E(this.elementOne[U]),T.Ge,new E(this.elementTwo[U])),this.layer[N](this,this.constraintX),this.layer[N](this,this.constraintY),this.layer[N](this,this.constraintW),this.layer[N](this,this.constraintH),0!=this.parameters.isStrict&&(this.constraintStrict=new O(new E(this.elementOne[U]),T.Eq,new E(this.elementTwo[U]),M.strong),this.layer[N](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 bi 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,s=i?t.clientX-i.left:t.clientX,n=i?i.bottom-t.clientY:window.innerHeight-t.clientY,r=this.calculateScale();this.clickInternal(s*r,n*r)},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 gi extends At{click(t,i){this.clickInternal(t,i)}resize(t,i){this.resizeInternal(t,i)}}class Si{}export{Wt as UIAspectConstraint,wt as UIBehavior,ri as UIConstraintBuilder,Rt as UIConstraintBuilder2D,tt as UIConstraintPower,it as UIConstraintRule,Yt as UICoverConstraint,ei as UIDummy,pi as UIElementBuilder,Pt as UIElementEvent,yi as UIFitConstraint,bi as UIFullScreenLayer,xt as UIFullScreenQuad,ct as UIHeightConstraint,Kt as UIHorizontalDistanceConstraint,Bt as UIHorizontalProportionConstraint,hi as UIImage,gi as UIManualLayer,Z as UIOrientation,Si as UIPass,mi as UIStackConstraintBuilder,di as UIText,Lt as UIVerticalDistanceConstraint,Ft as UIVerticalProportionConstraint,Nt as UIWidthConstraint};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|