(()=>{"use strict";var e={};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}();const t={fontFamily:null,fontSize:.05,fontKerning:"auto",fontStyle:"normal",fontWeight:"normal",offset:.005,lineHeight:1.2,lineBreak:"- ,.:?!\n",whiteSpace:"pre-line",flexDirection:"column",justifyContent:"start",alignItems:"start",backgroundImage:null,textAlign:"left",boxSizing:"content-box",position:"static",color:16777215,fontColor:16777215,fontOpacity:1,opacity:1,fontPXRange:4,fontSupersampling:!0,fontSmooth:"antialiased",borderRadius:0,borderWidth:0,borderColor:"black",borderOpacity:1,backgroundSize:"cover",backgroundColor:0,backgroundOpacity:0,overflow:"visible",letterSpacing:0,invertAlpha:!1,segments:1};class i{constructor(e,t=null,i=!0){this._id=e,this._value=t,this._needsUpdate=!0,this._needsProcess=!1,this._needsRender=!1,this._isPrimitive=i}get id(){return this._id}get value(){return this._value}set value(e){this.isValid(e)&&this._value!==e&&(this._value=e,this._needsUpdate=!0)}update(e,t){this.output(t)}output(e){}_outputValue(e){e[this._id]=this._value}process(e){}render(e){}getInheritedInput(e){if("inherit"!==this._value)return this._value;const t=e._parent._value;return t&&t[`_${this._id}`]?t[`_${this._id}`].getInheritedInput(t):this.getDefaultValue()}getDefaultValue(){return e=this._id,Object.prototype.hasOwnProperty.call(t,e)||console.warn(`ThreeMeshUI::DefaultValues is trying to retrieve non-existing property '${e}'`),t[e];var e}isValid(e){return!0}emptyStrategyLogic(){throw new Error(`ThreeMeshUI::${this.constructor.name} has empty strategy. Update has not been processed.`)}requestUpdate(){this._needsUpdate=!0}requestProcess(){this._needsProcess=!1}requestRender(){this._needsRender=!1}}class n extends i{constructor(){super("renderOrder","auto",!0),this.output=this._outputValue,this._actualValue=0}set value(e){this.isValid(e)&&(this._value=e,this._needsUpdate=!0)}update(e,t){if("auto"!==this._value)this._actualValue=this._value;else{const t=e._parent._value;if(null!==t){const i=t._renderOrder._actualValue,n=1+t._children._uis.indexOf(e);this._actualValue=i+n}}for(const t of e._children._uis){"auto"===t._renderOrder._value&&(t._renderOrder._needsUpdate=!0)}this._outputValue(t)}_outputValue(e){e[this._id]=this._actualValue}get value(){return this._value}}class s extends i{constructor(e,t=null,i=!0){super(e,t,i),this.output=this._outputValue,this._notInheritedValue=null}update(e,t){this._notInheritedValue=this._value,"inherit"===this._notInheritedValue&&(this._notInheritedValue=this.getInheritedInput(e)),this.propagate(e),this._outputValue(t)}propagate(e){for(const t of e._children._uis){const e=t[`_${this._id}`];void 0!==e&&"inherit"===e._value&&(t[`_${this._id}`]._needsUpdate=!0)}}_outputValue(e){e[this._id]=this._notInheritedValue}set value(e){this.isValid(e)&&this._value!==e&&(this._value=e,this._needsUpdate=!0)}get value(){return"inherit"===this._value?this._notInheritedValue:this._value}}class r extends s{constructor(){super("offset","inherit",!1)}update(e,t){super.update(e,t),null!==e._parent._value&&(e.position.z=this._notInheritedValue)}}class o extends s{constructor(){super("fontSmooth","inherit",!0),this._needsUpdate=!1,this.isValid=h,this.output=this._outputValue}}const a=["inherit","none","antialiased"];function h(e){return-1!==a.indexOf(e)||(console.warn(`.fontSmoothing value '${e}' is not valid. Aborted`),!1)}const l=THREE;class u extends i{constructor(e,t,i=!0){super(e,"unset",i),this._input="inherit",this._allowsInherit=!0,this._inheritedInput=void 0,this._inline=void 0}update(e,t){this._allowsInherit||(this._inheritedInput=this.getInheritedInput(e)),this.computeOutputValue(e);for(const t of e._children._uis){const e=t[`_${this._id}`];"inherit"===(e._input?e._input:e._value)&&(t[`_${this._id}`]._needsUpdate=!0)}this.output(t)}computeOutputValue(e){this._value=this._input}_computeFromInherited(e){this._value=this._inheritedInput}set value(e){console.warn(".(style) sub-property cannot be directly set. It must comes from inline or computed setter.")}set inline(e){this.isValidValue(e)&&e!==this._inline&&(this._input=this._inline=e,this._needsUpdate=!0)}get inline(){return this._inline}isValidValue(e){return!0}getInheritedInput(e){if("inherit"!==this._input)return this._input;const t=e._parent._value;return t?t[`_${this._id}`].getInheritedInput(t):this.getDefaultValue()}}class d extends u{constructor(e,t){super(e,t,!1),this._input=new l.Vector4(0,0,0,0),this._inline=null,this._value=new l.Vector4(0,0,0,0)}get value(){return this._value}computeOutputValue(e){this._vector4ValueSetter(this._value,this._input)}set inline(e){this._vector4ValueSetter(this._input,e),this._input.equals(this._value)||(this._needsUpdate=!0)}set top(e){this._input.x!==e&&(this._input.x=e,this._needsUpdate=!0)}get top(){return this._input.x}set right(e){this._input.y!==e&&(this._input.y=e,this._needsUpdate=!0)}get right(){return this._input.y}set bottom(e){this._input.z!==e&&(this._input.z=e,this._needsUpdate=!0)}get bottom(){return this._input.z}set left(e){this._input.w!==e&&(this._input.w=e,this._needsUpdate=!0)}get left(){return this._input.w}dispose(){this._computed=null,this._inline=null,this._input=null,this._output=null}_vector4ValueSetter(e,t){if(t instanceof l.Vector4)e.copy(t);else{if(("string"==typeof t||t instanceof String)&&(t=t.split(" ")),Array.isArray(t))switch((t=t.map((e=>parseFloat(e)))).length){case 1:return void e.setScalar(t[0]);case 2:return e.x=e.z=t[0],void(e.y=e.w=t[1]);case 3:return e.x=t[0],e.y=t[1],void(e.z=t[2]);case 4:return e.x=t[0],e.y=t[1],e.z=t[2],void(e.w=t[3]);default:return void console.error("StyleVector4Property::set() Four Dimension property had more than four values")}isNaN(t)||e.setScalar(t)}}}class c extends d{constructor(){super("padding",new l.Vector4(0,0,0,0))}computeOutputValue(e){super.computeOutputValue(e),e._bounds._needsUpdate=!0,e._bounds._needsRender=!0,e._layouter._needsProcess=!0,e._renderer._needsRender=!0,e._parent._value&&(e._parent._value._layouter._needsProcess=!0)}}class _ extends d{constructor(){super("margin",new l.Vector4(0,0,0,0))}computeOutputValue(e){super.computeOutputValue(e),e._renderer._needsRender=!0,e._parent._value&&(e._parent._value._flexDirection._needsProcess=!0)}}const f=function(e,t,i){e[t]=i},p=function(e,t,i){null!==i&&(e[t]=i)};class g{constructor(e){this._definition=e}set definition(e){this._definition=e}mediate(e,t,i,n=null){for(const e in this._definition){const s=this._definition[e];if(void 0!==i[e]){const r=s.t?s.t:f;r(t,s.m,i[e]),n&&r(n,s.m,i[e])}}}static mediate(e,t,i,n,s=null){if(t)for(const e in n){const r=n[e];if(void 0!==i[e]){const n=r.t?r.t:f;n(t,r.m,i[e]),s&&n(s,r.m,i[e])}}}}class m extends i{constructor(){super("parent",null,!1)}update(e,t){e.parent&&e.parent.isUI?this._value=e.parent:this._value=null}set value(e){console.warn("ParentProperty is readonly")}get value(){return this._value}find(e){return this._value?e(this._value)?this._value:this._value._parent.find(e):null}dispose(){this._value=null}}const v=function(e,t,i=6){return e.toFixed(i)===t.toFixed(i)};class b extends i{constructor(e,t){super(e,t,!0),this.output=this._outputValue}set value(e){this.isValid(e)&&(v(this._value,e)||(this._value=e,this._needsUpdate=!0))}get value(){return this._value}}class y extends s{constructor(e){super(e,"inherit",!0),this.isValid=w}}const x=[l.FrontSide,l.BackSide,l.DoubleSide];function w(e){return-1!==x.indexOf(e)||(console.warn(`SideProperty value '${e}' is not valid. Abort`),!1)}class S{constructor(){this._offsetX=0,this._offsetY=0,this._lineBreak=null,this._kerning=0,this._fontFactor=1,this._fontSize=0,this._cumulativeWidth=0,this._paddingLeft=0,this._paddingRight=0,this._marginLeft=0,this._marginRight=0}resetOffsets(){this._offsetX=this._offsetY=0,this._cumulativeWidth=0}get xadvance(){return 0}get xoffset(){return 0}get yoffset(){return 0}get width(){return 0}get height(){return 0}set lineBreak(e){this._lineBreak=e}get lineBreak(){return this._lineBreak}get anchor(){return 0}get kerning(){return this._kerning*this._fontFactor}set kerning(e){this._kerning=e}get fontSize(){return this._fontSize}set fontSize(e){this._fontSize=e}get lineHeight(){return 0}get offsetX(){return this._offsetX}set offsetX(e){this._offsetX=e}get offsetY(){return this._offsetY}set offsetY(e){this._offsetY=e}get cumulativeWidth(){return this._cumulativeWidth}set cumulativeWidth(e){this._cumulativeWidth=e}get marginLeft(){return this._marginLeft}set marginLeft(e){this._marginLeft=e}get marginRight(){return this._marginRight}set marginRight(e){this._marginRight=e}get paddingLeft(){return this._paddingLeft}set paddingLeft(e){this._paddingLeft=e}get paddingRight(){return this._paddingRight}set paddingRight(e){this._paddingRight=e}get lineBase(){return 0}set fontFactor(e){this._fontFactor=e}get fontFactor(){return this._fontFactor}}class V{constructor(e){this._char="",this._width=1,this._heigth=1,this._xadvance=1,this._xoffset=0,this._yoffset=0,this._font=e}get font(){return this._font}get char(){return this._char}get width(){return this._width}get height(){return this._heigth}get xadvance(){return this._xadvance}get xoffset(){return this._xoffset}get yoffset(){return this._yoffset}set yoffset(e){this._yoffset=e}clone(e){throw new Error("Abstract... Need to be implemented")}asInlineGlyph(){throw new Error("Abstract... Need to be implemented")}}class k extends S{constructor(e){super(),this._typographic=e}get typographic(){return this._typographic}get xadvance(){return this._typographic.xadvance*this._fontFactor}get xoffset(){return this._typographic.xoffset*this._fontFactor}get yoffset(){return this._typographic.yoffset*this._fontFactor}get width(){return this._typographic.width*this._fontFactor}get height(){return this._typographic.height*this._fontFactor}get char(){return this._typographic.char}get anchor(){return this.yoffset}get lineHeight(){return this._typographic.font.lineHeight*this._fontFactor}get lineBase(){return this._typographic.font.lineBase*this._fontFactor}}const R={light:"100",normal:"400",bold:"700",bolder:"900"};function U(e){if(!isNaN(e))return e.toString();const t=R[e];return t||e}class C extends l.EventDispatcher{constructor(e,t){super(),this._isReady=!1,this._weight=U(e),this._style=t,this._size=42,this._lineHeight=42,this._lineBase=42,this._font=null}get typographic(){return this._font}get isReady(){return this._isReady}get weight(){return this._weight}get style(){return this._style}get texture(){return this._texture}set fontMaterial(e){throw Error(`FontVariant('${this.id}')::fontMaterial - is abstract.`)}get fontMaterial(){throw Error(`FontVariant('${this.id}')::fontMaterial - is abstract.`)}get id(){return`${this._name}(w:${this.weight},s:${this.style})`}getTypographicGlyph(e){let t=this._chars[e];if(t)return t;if(e.match(/\s/))return this._chars[" "];const i=this._getFallbackCharacter(e);if(i&&(t=this._chars[i],t))return t;throw Error(`FontVariant('${this.id}')::getTypographicGlyph() - character('${e}') and/or fallback character were not found in provided msdf charset.`)}_getFallbackCharacter(e){throw new Error(`FontVariant(${typeof this})::_getFallbackCharacter() is abstract and should therefore be overridden.`)}getGeometricGlyph(e,t){throw new Error(`FontVariant(${typeof this})::getGeometryCharacter() is abstract and should therefore be overridden.`)}getKerningAmount(e){return this._kernings[e]?this._kernings[e]:0}adjustTypographicGlyphs(e){for(const t in e){const i=this.getTypographicGlyph(t),n=e[t];for(const s in n)i["_"+s]=e[t][s]}}_checkReadiness(){var e;this._readyCondition()&&((e=this)._isReady=!0,e.dispatchEvent(M))}_alterElementProperties(e){throw new Error(`FontVariant(${typeof this})::_alterElementProperties() is abstract and should therefore be overridden.`)}_readyCondition(){throw new Error(`FontVariant(${typeof this})::_readyCondition() is abstract and should therefore be overridden.`)}}const M={type:"ready"};const I=C;class B extends i{constructor(e=null){super("font",e,!1),this._needsUpdate=!1,this._fontVariant=null,this._handleFontReadyClosure=null,this.isValid=P}output(e){e[this._id]=this._fontVariant}update(e,t){if(this._fontVariant&&!this._fontVariant.isReady&&this._fontVariant.removeEventListener("ready",this._handleFontReadyClosure),this._value&&this._value instanceof I)this._fontVariant=this._value;else{const t=e._fontFamily._value;t&&(this._fontVariant=t.getVariant(e._fontWeight._value,e._fontStyle._value))}this._fontVariant&&(this._fontVariant._alterElementProperties(e),this._handleFontReadyClosure=function(e,t){return function(){t._needsUpdate=!0,e._glyphs._needsProcess=!0,t._fontVariant.removeEventListener("ready",t._handleFontReadyClosure),t._handleFontReadyClosure=null}}(e,this),this._fontVariant.isReady?this._handleFontReadyClosure():this._fontVariant.addEventListener("ready",this._handleFontReadyClosure),e._fontMaterial._defaultMaterial&&e._fontMaterial._defaultMaterial instanceof this._fontVariant.fontMaterial||(e._fontMaterial._defaultMaterial=new this._fontVariant.fontMaterial,e._fontMaterial._needsUpdate=!0))}set value(e){this.isValid(e)&&this._value!==e&&(this._value=e,this._needsUpdate=!0)}get value(){return this._value}get fontVariant(){return this._fontVariant}dispose(){this._handleFontReadyClosure&&(this._fontVariant.removeEventListener("ready",this._handleFontReadyClosure),this._handleFontReadyClosure=null),this._value=null,this._fontVariant=null}}function P(e){return e instanceof I||(console.warn(`.font value '${e}' is not valid. It requires a FontVariant instance. Aborted`),!1)}class T extends u{constructor(e){super("display",e),this._value="flex",this._allowsInherit=!1,this._needsUpdate=!1,this.isValidValue=z}computeOutputValue(e){e._visible._value="none"!==this._output}}const F=["none","flex"];function z(e){return-1!==F.indexOf(e)||(console.warn(`(.style) display value '${e}' is not valid. Aborted`),!1)}class O extends u{constructor(e){super("boxSizing",e),this._allowsInherit=!1,this.isValidValue=W}computeOutputValue(e){this._value=this._inheritedInput,e._bounds._needsUpdate=!0}}const A=["border-box","content-box"];function W(e){return-1!==A.indexOf(e)||(console.warn(`(.style) boxSizing value '${e}' is not valid. Aborted`),!1)}class D extends u{constructor(e,t){super(e,t,!1),this._value=new l.Color,this.output=this._outputValue}computeOutputValue(e){"inherit"!==this._input&&this._value.set(this._input)}set inline(e){this._input=this._inline=e,this._needsUpdate=!0}}class E extends u{constructor(e,t){super(e,t,!0),this.isValidValue=L,this._allowsInherit=!1,this._input=t,this._value=t,this.output=this._outputValue,this.computeOutputValue=this._computeFromInherited}_outputValue(e){e[this._id]=this._inheritedInput}}function L(e){return!(e<0&&e>1)||(console.warn(`(.style) styleFactorProperty('${this.id}') value '${e}' is not valid)`),!1)}class H extends u{constructor(e){super("backgroundImage",e,!0),this._input=null,this._allowsInherit=!1,this._textureSize=new l.Vector2(1,1),this.isValidValue=G}get value(){return this._value}output(e){e[this._id]=this._value,e.tSize=this._textureSize}computeOutputValue(e){this._value=this._inheritedInput,this._value instanceof l.Texture&&!this._value.image?console.warn("ThreeMeshUI - .backgroundImage :: Please provide preloaded texture in order to have accurate sizing."):this._needsProcess=!0}process(e){this._value?this._textureSize.set(this._value.image.width,this._value.image.height):this._textureSize.set(1,1)}}function G(e){return!0}class $ extends u{constructor(e){super("backgroundSize",e,!0),this.isValidValue=X,this.output=this._outputValue}}const j=["cover","contain","stretch"];function X(e){return-1!==j.indexOf(e)||(console.warn(`(.style) backgroundSize value '${e}' is not valid. Aborted`),!1)}class N extends u{constructor(e){super("overflow",e,!0),this.isValidValue=K,this._clippingPlanes=null,this._renderStrategy=this._emptyRender}update(e,t){void 0!==this._inline&&"unset"!==this._inline?this._input=this._inline:void 0!==this._computed&&(this._input=this._computed),this._allowsInherit||(this._inheritedInput=this.getInheritedInput(e)),this.computeOutputValue(e);for(const t of e._children._uis)t._overflow._needsUpdate=!0;this.output(t)}output(e){e.clippingPlanes=this._clippingPlanes}computeOutputValue(e){super.computeOutputValue(e),"hidden"===this._value?this._renderStrategy=this._propagateRender:(this._renderStrategy=this._emptyRender,this._clippingPlanes=null);const t=e._parent._value;if(null!==t){const e=t._overflow;if("hidden"!==e._value&&null===e._clippingPlanes||this._clippingPlanes)"visible"!==e._value&&null!==e._clippingPlanes||null===this._clippingPlanes||(this._clippingPlanes=null,this._renderStrategy=this._emptyRender,this._needsRender=!0);else{this._clippingPlanes=[new l.Plane(new l.Vector3(0,-1,0),1),new l.Plane(new l.Vector3(-1,0,0),1),new l.Plane(new l.Vector3(0,1,0),1),new l.Plane(new l.Vector3(1,0,0),1)];for(let e=0;ee.computeValue())),this._sideMediators.sort(((e,t)=>e.value1&&this._sideMediators[0].mediate()}while(this._sideMediators[0].value>1);let n=t>i?i/t:1,s=ti?i/t:1;this._valueUV.y*=e,this._valueUV.w*=e}if(0!==i){const e=t{switch(e._alignItems._value){case"inherit":case"start":return t/2;case"end":return n-t/2;case"stretch":case"center":return n/2}})();const r=e._padding._value,o=e._borderWidth._value;s+=(-r.x+r.z)/2+(-o.x+o.z)/2,i.forEach((e=>{e.y+=s,e.forEach((e=>{e.offsetY+=s}))}))}}const ae=["start","center","end","stretch"],he=function(e){return-1!==ae.indexOf(e)||(console.warn(`(.style) alignItems value '${e}' is not valid. Aborted`),!1)};class le extends u{constructor(){super("alignItems","inherit",!0),this.isValidValue=he}}class ue extends u{constructor(){super("textAlign","inherit",!0),this.isValidValue=ce}}const de=["left","right","center","justify","justify-left","justify-right","justify-center"],ce=function(e){return-1!==de.indexOf(e)||(console.warn(`(.style) textAlign value '${e}' is not valid. Aborted`),!1)};class _e extends u{constructor(){super("flexDirection","inherit",!0),this.isValid=pe}}const fe=["row","row-reverse","column","column-reverse"];function pe(e){return-1!==fe.indexOf(e)||(console.warn(`(.style) flexDirection value '${e}' is not valid. Aborted`),!1)}class ge extends u{constructor(){super("justifyContent","inherit",!0),this.isValidValue=ve}}const me=["start","center","end","space-between","space-around","space-evenly"];function ve(e){return-1!==me.indexOf(e)||(console.warn(`(.style) justifyContent value '${e}' is not valid. Aborted`),!1)}class be extends u{constructor(){super("order",0,!0),this._value=0,this._input=0,this._allowsInherit=!1}computeOutputValue(e){this._value=this._inheritedInput,e._parent._value&&(e._parent._value._children._needsProcess=!0)}}class ye extends u{constructor(){super("position","static",!0),this._allowsInherit=!1,this._value="static",this._needsUpdate=!1,this.computeOutputValue=this._computeFromInherited,this.isValidValue=we}_computeFromInherited(e){super._computeFromInherited(e),e._parent._value&&(e._parent._value._children._needsProcess=!0)}}const xe=["static","absolute"];function we(e){return-1!==xe.indexOf(e)||(console.warn(`(.style) position value '${e}' is not valid. Aborted`),!1)}class Se extends u{constructor(e,t=null){super(e,t,!0),this._input="auto",this._auto=!0,this._relative=!1,this._updateRequired=!0}set inline(e){this.isValidValue(e)&&e!==this._inline&&(this._inline=e,this._input!==this._inline&&this._parseInput())}get inline(){return this._inline}_parseInput(){let e=!0;if(void 0!==this._inline&&"unset"!==this._inline?this._input=this._inline:void 0!==this._computed?(this._computed===this._input&&(e=!1),this._input=this._computed):e="inherit"===this._input,e){if(this._auto=!this._input||"auto"===this._input,this._auto)this._relative=!1;else if(("string"==typeof this._input||this._input instanceof String)&&this._input.endsWith("%")){this._relative=!0,this._value=0;const e=parseFloat(this._input.replace("%","").trim());isNaN(e)||(this._value=e/100)}else this._relative=!1,this._value=this._input;this._needsUpdate=this._updateRequired=e}}update(e,t){if(this._updateRequired){this._updateRequired=!1,this._allowsInherit||(this._inheritedInput=this.getInheritedInput(e)),this.computeOutputValue(e);for(const t of e._children._uis)t[`_${this._id}`]._needsUpdate=!0;this.output(t),e._parent._value&&(e._parent._value._layouter._needsProcess=!0)}}computeOutputValue(e){e._bounds._needsUpdate=!0,e._renderer._needsRender=!0}getInheritedInput(e){if("inherit"!==this._input&&!this._auto)return this._input;const t=e._parent._value;return t?t[`_${this._id}`].getInheritedInput(t):this.getDefaultValue()}getDefaultValue(){return 0}get value(){return this._value}}class Ve extends Se{constructor(){super("width")}}class ke extends Se{constructor(){super("height")}computeOutputValue(e){super.computeOutputValue(e)}}class Re extends re{constructor(){super("textContent"),this._needsUpdate=!1}set value(e){}process(e){let t="";for(let i=0;ie.char)).join("")}get textureWidth(){return this._textureWidth}get textureHeight(){return this._textureHeight}}class ze extends k{constructor(e){super(e)}get uv(){return this.typographic.uv}}class Oe extends V{constructor(e,t){super(e),this._char=t.char,this._width=t.width,this._heigth=t.height,this._xadvance=t.xadvance?t.xadvance:this._width,this._xoffset=t.xoffset?t.xoffset:0,this._yoffset=t.yoffset?t.yoffset:0,this._uv=t.uv?t.uv:null,isNaN(t.x)||(this._uv={left:t.x/e.textureWidth,right:(t.x+t.width)/e.textureWidth,top:1-(t.y+t.height)/e.textureHeight,bottom:1-t.y/e.textureHeight})}get uv(){return this._uv}clone(e){return new Oe(this._font,{char:e,width:this._width,height:this._heigth,xadvance:this._xadvance,xoffset:this._xoffset,yoffset:this._yoffset,uv:null})}asInlineGlyph(){return new ze(this)}}class Ae extends l.PlaneGeometry{constructor(e,t){let i=1,n=1;const s=e.typographic.font.size,r=t._segments.value;i=Math.ceil(e.typographic.width/s*r),n=Math.ceil(e.typographic.height/s*r),super(e.width,e.height,i,n),e.uv?(this._mapUVs(e),this._transformGeometry(e)):(this._nullifyUVs(),this.scale(0,0,1),this.translate(0,e.fontSize/2,0)),this.name="GlyphGeometry"}_mapUVs(e){const t=e.uv.right-e.uv.left,i=e.uv.bottom-e.uv.top,n=this.getAttribute("uv").array.slice(),s=[];for(let r=0;r0)},$e=function(e,t,i){e.defines&&(i?void 0===e.defines[t]&&(e.defines[t]="",e.needsUpdate=!0):void 0!==e.defines[t]&&(delete e.defines[t],e.needsUpdate=!0))},je=function(e,t,i){e.userData[t]?e.userData[t].value=i:e.uniforms[t].value=i};class Xe{static ensureMaterialOptions(e){e.transparent=!0,e.alphaTest=e.alphaTest||.02}static ensureDefines(e){e.defines||(e.defines={})}static ensureUserData(e,t){e.userData.glyphMap={value:t.glyphMap},e.userData.unitRange={value:new l.Vector2}}static bindUniformsWithUserData(e,t){e.uniforms.glyphMap=t.userData.glyphMap,e.uniforms.unitRange=t.userData.unitRange}static injectShaderChunks(e){Xe.injectVertexShaderChunks(e),Xe.injectFragmentShaderChunks(e)}static injectVertexShaderChunks(e){e.vertexShader=e.vertexShader.replace("#include ","#include \n"+We),e.vertexShader=e.vertexShader.replace("#include ","#include \n"+De),e.vertexShader=e.vertexShader.replace("#include ","#include \n"+Ee)}static injectFragmentShaderChunks(e){e.fragmentShader=e.fragmentShader.replace("#include ","#include \n"+Le),e.fragmentShader=e.fragmentShader.replace("#include ","#include \n"+He)}static from(e){return class extends e{static get fontMaterialProperties(){return Xe.mediation}constructor(e={}){Xe.ensureMaterialOptions(e),super(e),Xe.ensureDefines(this),Xe.ensureUserData(this,e),this._userDefinedOnBeforeCompile=e=>{},this._onBeforeCompile=this._cumulativeOnBeforeCompile}set onBeforeCompile(e){this._userDefinedOnBeforeCompile=e}get onBeforeCompile(){return this._onBeforeCompile}_cumulativeOnBeforeCompile=e=>{Xe.bindUniformsWithUserData(e,this),Xe.injectShaderChunks(e),this._userDefinedOnBeforeCompile(e)}}}static get mediation(){return Ne}}const Ne={clippingPlanes:{m:"clippingPlanes"},fontAlphaTest:{m:"alphaTest",t:Ge},fontSide:{m:"side"},font:{m:"glyphMap",t:function(e,t,i){const n=i?i.texture:null,s=i?i.unitRange:new l.Vector2;if(void 0!==e[t])return e.glyphMap=n,void(e.unitRange=s);e.userData&&e.userData.glyphMap&&(e.userData.glyphMap.value=n,e.userData.unitRange.value=s)}},color:{m:"color"},fontOpacity:{m:"opacity"},fontSmooth:{m:"NO_RGSS",t:function(e,t,i){i&&"antialiased"!==i?e.defines.NO_RGSS="":delete e.defines.NO_RGSS,e.needsUpdate=!0}},invertAlpha:{m:"INVERT_ALPHA",t:$e}},Ye=`\n${We}\n#include \nvoid main() {\n\t${De}\n\t#include \n\t#include \n\t${Ee}\n\t#include \n}\n`,Ke=`\nuniform vec3 diffuse;\nuniform float opacity;\n${Le}\n#include \n#include \nvoid main() {\n\t// instead of : vec4 diffuseColor\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t${He}\n\t#include \n\t// instead of \n\tgl_FragColor = diffuseColor;\n\t#include \n}\n`;class qe extends l.ShaderMaterial{static get mediation(){return Xe.mediation}constructor(e={}){super({uniforms:{glyphMap:{value:null},diffuse:{value:null},opacity:{value:1},unitRange:{value:new l.Vector2(0,0)},alphaTest:{value:.02}},transparent:!0,clipping:!0,vertexShader:Ye,fragmentShader:Ke,extensions:{derivatives:!0}}),this.defines.USE_ALPHATEST="",this.needsUpdate=!0,this.noRGSS=e.noRGSS||!1}get color(){return this.uniforms.diffuse.value}set color(e){this.uniforms.diffuse.value=e}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}get opacity(){return this.uniforms.opacity.value}get unitRange(){return this.uniforms.unitRange.value}set unitRange(e){this.uniforms.unitRange.value.copy(e)}get glyphMap(){return this.uniforms.glyphMap.value}set glyphMap(e){this.uniforms.glyphMap.value=e}get isDefault(){return this.constructor===qe}get alphaTest(){return this.uniforms.alphaTest.value}set alphaTest(e){this.uniforms.alphaTest.value=e}}class Je extends I{constructor(e,t,i,n){var s,r;if(super(e,t),this._unitRange=new l.Vector2(1,1),i.pages?this._buildData(i):(s=this,r=i,(new l.FileLoader).setResponseType("json").load(r,(e=>{s._buildData(e),s._checkReadiness()}))),n instanceof l.Texture)this._texture=n,this._buildTexture(n);else{if(!("string"==typeof n||n instanceof String))throw new Error(`ThreeMeshUI::MSDFVariant provided 'texture' parameter is '${typeof n}'. Only Texture and String allowed.`);!function(e,t){e._texture=(new l.TextureLoader).load(t,(t=>{e._buildTexture(t),e._checkReadiness()}))}(this,n)}this._defaultMaterialClass=qe,this._checkReadiness()}get texture(){return this._texture}get unitRange(){return this._unitRange}set fontMaterial(e){this._defaultMaterialClass=e}get fontMaterial(){return this._defaultMaterialClass}_buildData(e){this._font=new Fe(e),this._kernings=this._buildKerningPairs(e),this._chars=this._buildCharacters(e),this._chars[" "]=this._buildCharacterWhite(e),this._chars["\n"]=this._buildCharacterWhite(e,"\n",.001,1),this._chars["\t"]=this._buildCharacterWhite(e,"\t",4,1),this._size=e.info.size,this._lineHeight=e.common.lineHeight,this._lineBase=e.common.base,this._distanceRange=e.distanceField.distanceRange,this._unitRange=new l.Vector2(this._distanceRange,this._distanceRange).divide(new l.Vector2(e.common.scaleW,e.common.scaleH))}_buildTexture(e){e.generateMipmaps=!1,e.minFilter=l.LinearFilter,e.magFilter=l.LinearFilter,e.needsUpdate=!0}_getFallbackCharacter(e){return it.missingCharacter(this,e)}getGeometricGlyph(e,t){return new Ae(e,t)}_readyCondition(){return this._chars&&this._texture&&this._texture.image}_buildKerningPairs(e){const t={};for(let i=0;ii.weight===e&&i.style===t))}get name(){return this._name}_checkReadiness=()=>{var e;this._variants.every((e=>e.isReady))&&((e=this)._isReady=!0,e.dispatchEvent(Ze))}}const Ze={type:"ready"};const et={};let tt=function(e,t){return console.error(`The character '${t}' is not included in the font characters set.`)," "};const it={addFontFamily:function(e){return et[e]&&console.error(`FontLibrary::addFontFamily - Font('${e}') is already registered`),et[e]=new Qe(e),et[e]},getFontFamily:function(e){return et[e]},prepare:function(e){const t=[...arguments];t.forEach((e=>{if(!(e instanceof Qe))throw new Error(`FontLibrary::prepare() - One of the provided parameter is not a FontFamily. Instead ${typeof e} given.`)}));const i=function(){return t.every((e=>e.isReady))};return new Promise(((e,n)=>{if(i())e();else for(let n=0;n{i()&&e()}))}}))},setMissingCharacterHandler:function(e){tt=e},missingCharacter:function(e,t){return tt(e,t)}};class nt extends u{constructor(){super("fontFamily","inherit",!0)}computeOutputValue(e){if(this._input instanceof Qe)this._value=this._input;else if("inherit"===this._input);else if("string"==typeof this._input){const e=it.getFontFamily(this._input);e?this._value=e:console.warn(`(.style) fontFamily, the font '${this._input}' is not registered. Aborted.`)}else console.warn("(.style) fontFamily requires a registered fontFamily instance, or the id of a registered fontFamily."),console.warn("If you want to set a specific font, please use .font property instead.")}get value(){return this._value}getInheritedInput(e){if("inherit"!==this._input)return this._input;const t=e._parent._value;return t?t[`_${this._id}`].getInheritedInput(t):this.getDefaultValue()}}class st extends u{constructor(){super("lineHeight","inherit",!0)}update(e,t){super.update(e,t),e._layouter._needsProcess=!0}}class rt extends u{constructor(){super("whiteSpace","inherit"),this.isValidValue=at}}const ot=["normal","nowrap","pre","pre-line","pre-wrap"];function at(e){return-1!==ot.indexOf(e)||(console.warn(`(.style) whiteSpace value '${e}' is not valid. Aborted`),!1)}class ht extends u{constructor(){super("letterSpacing","inherit",!0)}}class lt extends u{constructor(){super("fontSize","inherit",!0)}}class ut extends i{constructor(){super("segments",1,!1)}}class dt extends s{constructor(){super("invertAlpha","inherit")}}class ct extends u{constructor(){super("fontKerning","inherit"),this.isValidValue=ft}}const _t=["normal","none","inherit"];function ft(e){return-1!==_t.indexOf(e)||(console.warn(`(.style) fontKerning value '${e}' is not valid. Aborted`),!1)}class pt extends s{constructor(e){super(e,"inherit",!0)}}class gt extends s{constructor(e){super(e,"inherit",!1),this._mediation={},this._defaultMaterial=null}update(e,t){this._notInheritedValue=this._value,"inherit"===this._notInheritedValue?this._notInheritedValue=this.getInheritedInput(e):this.propagate(e),this._notInheritedValue?this._notInheritedValue.constructor.mediation?this._mediation={...this._notInheritedValue.constructor.mediation}:this._mediation={clippingPlanes:{m:"clippingPlanes"},fontAlphaTest:{m:"alphaTest",t:Ge},fontSide:{m:"side"},color:{m:"color"},fontOpacity:{m:"opacity"}}:this._mediation={},e._transferToFontMaterial(),this._outputValue(t)}getInheritedInput(e){if("inherit"!==this._value)return this._value;let t=e,i=null;for(;t._parent._value;)if(t=t._parent._value,"inherit"!==t[`_${this._id}`]._value){i=t[`_${this._id}`]._value;break}return null!==i?i:this.getDefaultValue()}getDefaultValue(){return this._defaultMaterial}}const mt=function(e,t,i){e.traverse((e=>{e.renderOrder=i}))};class vt extends l.Object3D{constructor(e,t){super(),Object.defineProperties(this,{isUI:{configurable:!1,enumerable:!0,value:!0}}),this._backgroundMesh=null,this._backgroundMaterial=null,this._backgroundCustomDepthMaterial=null,this._backgroundMaterialMediation={},this._backgroundMeshMediation={backgroundCastShadow:{m:"castShadow"},backgroundReceiveShadow:{m:"receiveShadow"},renderOrder:{m:"renderOrder",t:mt}},this._fontMesh=null,this._fontMaterial=new gt("fontMaterial"),this._fontCustomDepthMaterial=new gt("fontCustomDepthMaterial"),this._fontMeshMediation={fontMaterial:{m:"material"},fontCustomDepthMaterial:{m:"customDepthMaterial",t:p},fontCastShadow:{m:"castShadow"},fontReceiveShadow:{m:"receiveShadow"},renderOrder:{m:"renderOrder"}},this._children=e.children?new e.children:new re("children"),this._parent=new m,this.addEventListener("added",this._rebuildParentUI),this.addEventListener("removed",this._rebuildParentUI),this._backgroundSide=new y("backgroundSide"),this._fontSide=new y("fontSide"),this._backgroundAlphaTest=new b("backgroundAlphaTest",.02),this._fontAlphaTest=new b("fontAlphaTest",.02),this._visible=new ne("visible",!0),this._backgroundCastShadow=new pt("backgroundCastShadow"),this._fontCastShadow=new pt("fontCastShadow"),this._backgroundReceiveShadow=new pt("backgroundReceiveShadow"),this._fontReceiveShadow=new pt("fontReceiveShadow"),this._renderOrder=new n,this._segments=e.segments?new e.segments:new ut,this._bounds=e.bounds?new e.bounds:new re("bounds"),this._order=new be,this._padding=new c,this._margin=new _,this._position=new ye,this._flexDirection=e.flexDirection?new e.flexDirection:new _e,this._justifyContent=e.justifyContent?new e.justifyContent:new ge,this._alignItems=e.alignItems?new e.alignItems:new le,this._display=new T("flex"),this._boxSizing=new O("border-box"),this._width=new Ve,this._height=new ke,this._backgroundColor=e.backgroundColor?new e.backgroundColor:new se,this._backgroundOpacity=new E("backgroundOpacity",.5),this._backgroundImage=new H,this._backgroundSize=new $("cover"),this._color=e.color?new e.color:new D("color","inherit"),this._fontOpacity=new E("fontOpacity","inherit"),this._whiteSpace=e.whiteSpace?new e.whiteSpace:new rt,this._fontFamily=e.fontFamily?new e.fontFamily:new nt,this._fontStyle=e.fontStyle?new e.fontStyle:new Ue("normal"),this._fontWeight=e.fontWeight?new e.fontWeight:new Ie,this._fontSize=e.fontSize?new e.fontSize:new lt,this._lineHeight=e.lineHeight?new e.lineHeight:new st,this._fontKerning=e.fontKerning?new e.fontKerning:new ct,this._letterSpacing=e.letterSpacing?new e.letterSpacing:new ht,this._overflow=new N("visible"),this._borderRadius=new ee(0),this._borderWidth=new ie(0),this._borderColor=new D("borderColor",16711935),this._borderOpacity=new E("borderOpacity",1),this._font=new B,this._lineBreak=e.lineBreak?new e.lineBreak:new re("lineBreak"),this._textContent=e.textContent?new e.textContent:new Re,this._glyphs=e.glyphs?new e.glyphs:new re("glyphs"),this._inlines=e.inlines?new e.inlines:new re("inlines"),this._layouter=e.layouter?new e.layouter:new re("layouter"),this._inlineJustificator=new oe,this._textAlign=e.textAlign?new e.textAlign:new ue,this._autoSize=e.autoSize?new e.autoSize:new re("autoSize"),this._renderer=e.renderer?new e.renderer:new re("renderer"),this._offset=new r,this._invertAlpha=new dt,this._fontSmooth=e.fontSmooth?new e.fontSmooth:new o,this._components=[this._textContent,this._children,this._parent,this._autoSize,this._fontFamily,this._fontStyle,this._fontWeight,this._font,this._whiteSpace,this._glyphs,this._inlines,this._visible,this._backgroundSide,this._fontSide,this._backgroundAlphaTest,this._fontAlphaTest,this._backgroundCastShadow,this._fontCastShadow,this._backgroundReceiveShadow,this._fontReceiveShadow,this._renderOrder,this._segments,this._padding,this._margin,this._width,this._height,this._borderWidth,this._boxSizing,this._bounds,this._position,this._flexDirection,this._justifyContent,this._alignItems,this._order,this._display,this._backgroundColor,this._backgroundOpacity,this._backgroundImage,this._backgroundSize,this._fontOpacity,this._color,this._fontSize,this._lineHeight,this._fontKerning,this._letterSpacing,this._borderRadius,this._borderColor,this._borderOpacity,this._lineBreak,this._offset,this._layouter,this._inlineJustificator,this._textAlign,this._invertAlpha,this._fontSmooth,this._fontMaterial,this._fontCustomDepthMaterial,this._overflow,this._renderer],this._onAfterUpdates=[],t.backgroundSide||(t.backgroundSide=0),t&&this.set(t)}update(){const e={};for(const t of this._components)t._needsUpdate&&(t.update(this,e),t._needsUpdate=!1);this._transferToBackgroundMesh(e),this._transferToFontMesh(e),this._transferToBackgroundMaterial(e),this._transferToFontMaterial(e);for(const e of this._children._uis)e.update()}process(){for(const e of this._children._uis)e.process();for(const e of this._components)e._needsProcess&&(e.process(this),e._needsProcess=!1)}render(){for(let e=0;e{this._parent._needsUpdate=!0,this.parent&&!this.parent.isUI?(bt.register(this),this.activatePseudoState("root")):(bt.remove(this),this.deactivatePseudoState("root"))};add(e){let t=!1;for(let e=0;e{e.material&&e.material.dispose(),e.geometry&&e.geometry.dispose()})),super.clear(),this._backgroundMesh=null,this._backgroundMaterial=null,this._backgroundMaterialMediation=null,this._backgroundMeshMediation=null,this._children.dispose(),this._children=null,this._parent.dispose(),this._parent=null,this._backgroundSide=null,this._backgroundAlphaTest=null,this._visible=null,this._backgroundCastShadow=null,this._backgroundReceiveShadow=null,this._renderOrder=null,this._segments=null,this._bounds=null,this._boxSizing=null,this._padding=null,this._margin=null,this._position=null,this._flexDirection=null,this._justifyContent=null,this._alignItems=null,this._display=null,this._backgroundColor=null,this._backgroundOpacity=null,this._backgroundSize=null,this._fontOpacity=null,this._color=null,this._whiteSpace=null,this._fontFamily=null,this._fontStyle=null,this._fontWeight=null,this._lineHeight=null,this._fontKerning=null,this._letterSpacing=null,this._overflow=null,this._textAlign=null,this._font=null,this._lineBreak=null,this._layouter=null,this}get textContent(){return this._textContent.process(this),this._textContent._value}get backgroundMaterial(){return this._backgroundMaterial}set backgroundMaterial(e){this._backgroundMaterial=e,this._backgroundMaterialMediation={...e.constructor.mediation},this._transferToBackgroundMaterial(),this._backgroundMesh&&(this._backgroundMesh.material=this._backgroundMaterial,je(e,"frameSize",this._backgroundMesh.scale))}set backgroundCustomDepthMaterial(e){this._backgroundCustomDepthMaterial=e,this._transferToBackgroundMaterial(),this._backgroundMesh&&(this._backgroundMesh.customDepthMaterial=this._backgroundCustomDepthMaterial)}get backgroundCustomDepthMaterial(){return this._backgroundCustomDepthMaterial}_transferToBackgroundMaterial(e=null){if(!e){e={};for(const t of this._components)t.output(e)}g.mediate(this,this._backgroundMaterial,e,this._backgroundMaterialMediation,this._backgroundCustomDepthMaterial)}set backgroundSide(e){this._backgroundSide.value=e,this._backgroundMaterial&&(this._backgroundMaterial.side=e)}get backgroundSide(){return this._backgroundSide.value}set backgroundAlphaTest(e){this._backgroundAlphaTest.value=e,this._backgroundMaterial&&(this._backgroundMaterial.alphaTest=e)}get backgroundAlphaTest(){return this._backgroundAlphaTest.value}get fontMaterial(){return this._fontMaterial.value}set fontMaterial(e){this._fontMaterial.value=e}set fontCustomDepthMaterial(e){this._fontCustomDepthMaterial.value=e}get fontCustomDepthMaterial(){return this._fontCustomDepthMaterial.value}_transferToFontMaterial(e=null){const t=this._fontMaterial.value;if(t){if(!e){e={};for(const t of this._components)t.output(e)}g.mediate(this,t,e,this._fontMaterial._mediation,this._fontCustomDepthMaterial.value)}}set fontSide(e){this._fontSide.value=e}get fontSide(){return this._fontSide.value}set fontAlphaTest(e){this._fontAlphaTest.value=e}get fontAlphaTest(){return this._fontAlphaTest.value}_transferToBackgroundMesh(e=null){if(!e){e={};for(const t of this._components)t.output(e)}g.mediate(this,this._backgroundMesh,e,this._backgroundMeshMediation)}setBackgroundMesh(e){this._backgroundMesh&&(this.remove(this._backgroundMesh),this.unbindBackgroundMeshProperties()),this._backgroundMesh=e,this._backgroundMesh&&(this.bindBackgroundMeshProperties(),this._backgroundCustomDepthMaterial&&(this._backgroundMesh.customDepthMaterial=this._backgroundCustomDepthMaterial),this._backgroundMaterial&&je(this._backgroundMaterial,"frameSize",this._backgroundMesh.scale),this._transferToBackgroundMesh(),this.add(this._backgroundMesh))}bindBackgroundMeshProperties(){}unbindBackgroundMeshProperties(){}activatePseudoState(e){}deactivatePseudoState(e){}togglePseudoState(e){}hasPseudoState(e){return!1}set borderRadiusMediation(e){this._borderRadius.mediation=e}set backgroundCastShadow(e){this._backgroundCastShadow&&(this._backgroundCastShadow.value=e)}get backgroundCastShadow(){return this._backgroundCastShadow}set backgroundReceiveShadow(e){this._backgroundReceiveShadow&&(this._backgroundReceiveShadow.value=e)}get backgroundReceiveShadow(){return this._backgroundReceiveShadow}set renderOrder(e){this._renderOrder&&(this._renderOrder.value=e)}get renderOrder(){return this._renderOrder.value}_transferToFontMesh(e=null){if(this._fontMesh){if(!e){e={};for(const t of this._components)t.output(e)}g.mediate(this,this._fontMesh,e,this._fontMeshMediation)}}setFontMesh(e){this._fontMesh&&(this.remove(this._fontMesh),this._fontMesh.material&&this._fontMesh.material.dispose(),this._fontMesh.geometry&&this._fontMesh.geometry.dispose(),this._fontMesh=null,this.unbindFontMeshProperties()),this._fontMesh=e,this._fontMesh&&(this._fontMesh.raycast=()=>{},this.bindFontMeshProperties(),this._transferToFontMaterial(),this._transferToFontMesh(),this.add(this._fontMesh))}bindFontMeshProperties(){}unbindFontMeshProperties(){}set fontCastShadow(e){this._fontCastShadow&&(this._fontCastShadow.value=e)}get fontCastShadow(){return this._fontCastShadow}set fontReceiveShadow(e){this._fontReceiveShadow&&(this._fontReceiveShadow.value=e)}get fontReceiveShadow(){return this._fontReceiveShadow}set segments(e){this._segments.value=e}get segments(){return this._segments.value}set onAfterUpdate(e){console.warn("ThreeMeshUI v7xx : `onAfterUpdate()` property has been deprecated, please rely on `addAfterUpdate` instead."),this.addAfterUpdate(e)}addAfterUpdate(e){this._onAfterUpdates.push(e)}removeAfterUpdate(e){const t=this._onAfterUpdates.indexOf(e);-1!==t&&this._onAfterUpdates.splice(t,1)}performAfterUpdate(){for(let e=0;e\n\nvoid main() {\n\n\t#ifdef USE_MAP\n\tvUv = uv;\n\t#endif\n\n\t${xt}\n\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\tgl_Position = projectionMatrix * mvPosition;\n\n\t#include \n\n}\n`,Mt=`\n\n// Basic\nuniform vec3 diffuse;\nuniform float opacity;\n\n#ifdef USE_ALPHATEST\n\tuniform float alphaTest;\n#endif\n\n${Vt}\n\n${wt}\n\n\n#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif\n\n${kt}\n\n#include \n\nvoid main() {\n\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\n\t// map\n\t${Rt}\n\n\t${St}\n\n\t#ifdef USE_ALPHATEST\n\n\tif ( diffuseColor.a < alphaTest ) discard;\n\n\t#endif\n\n\t// output\n\tgl_FragColor = diffuseColor;\n\n\n\t#include \n}\n`;class It{static get mediation(){return Bt}static ensureMaterialOptions(e){e.transparent=!0,e.alphaTest=e.alphaTest||.02}static ensureDefines(e){e.defines||(e.defines={})}static ensureUserData(e,t){e.userData.borderColor={value:null},e.userData.borderRadius={value:new l.Vector4(0,0,0,0)},e.userData.cornerTL={value:new l.Vector2(0,1)},e.userData.cornerTR={value:new l.Vector2(1,1)},e.userData.cornerBR={value:new l.Vector2(1,0)},e.userData.cornerBL={value:new l.Vector2(0,0)},e.userData.borderWidth={value:new l.Vector4(0,0,0,0)},e.userData.borderOpacity={value:null},e.userData.frameSize={value:new l.Vector3(1,1,1)},e.userData.textureSize={value:new l.Vector2(1,1)}}static bindUniformsWithUserData(e,t){e.uniforms.borderColor=t.userData.borderColor,e.uniforms.borderRadius=t.userData.borderRadius,e.uniforms.cornerTL=t.userData.cornerTL,e.uniforms.cornerTR=t.userData.cornerTR,e.uniforms.cornerBR=t.userData.cornerBR,e.uniforms.cornerBL=t.userData.cornerBL,e.uniforms.borderWidth=t.userData.borderWidth,e.uniforms.borderOpacity=t.userData.borderOpacity,e.uniforms.frameSize=t.userData.frameSize,e.uniforms.textureSize=t.userData.textureSize}static injectShaderChunks(e){It.injectVertexShaderChunks(e),It.injectFragmentShaderChunks(e)}static injectVertexShaderChunks(e){e.vertexShader=e.vertexShader.replace("#include ","#include \n"+yt),e.vertexShader=e.vertexShader.replace("#include ","#include \n"+xt)}static injectFragmentShaderChunks(e){e.fragmentShader=e.fragmentShader.replace("#include ","#include \n"+kt),e.fragmentShader=e.fragmentShader.replace("#include ","#include \n"+wt),e.fragmentShader=e.fragmentShader.replace("#include ","#include \n"+Vt),e.fragmentShader=e.fragmentShader.replace("#include ",Rt),e.fragmentShader=e.fragmentShader.replace("#include ",St+"\n#include ")}}const Bt={clippingPlanes:{m:"clippingPlanes"},backgroundAlphaTest:{m:"alphaTest",t:Ge},backgroundSide:{m:"side"},backgroundImage:{m:"map"},backgroundColor:{m:"color"},backgroundOpacity:{m:"opacity"},backgroundSize:{m:"computedBackgroundSize",t:function(e,t,i){!function(e,t,i){e.defines[t]&&e.defines[t]===i||(e.defines[t]=i,e.needsUpdate=!0)}(e,"BACKGROUND_MAPPING",i=["stretch","contain","cover"].indexOf(i))}},borderWidth:{m:"borderWidth",t:je},borderColor:{m:"borderColor",t:je},cornerTL:{m:"cornerTL",t:je},cornerTR:{m:"cornerTR",t:je},cornerBR:{m:"cornerBR",t:je},cornerBL:{m:"cornerBL",t:je},borderOpacity:{m:"borderOpacity",t:je},size:{m:"frameSize",t:je},tSize:{m:"textureSize",t:je}};class Pt extends l.ShaderMaterial{static get mediation(){return It.mediation}constructor(){super({uniforms:{alphaTest:{value:.02},map:{value:null},diffuse:{value:new l.Color(16777215)},opacity:{value:1},borderColor:{value:new l.Color(0)},borderOpacity:{value:0},borderRadius:{value:new l.Vector4(0,0,0,0)},cornerTL:{value:new l.Vector2(0,1)},cornerTR:{value:new l.Vector2(1,1)},cornerBR:{value:new l.Vector2(1,0)},cornerBL:{value:new l.Vector2(0,0)},borderWidth:{value:new l.Vector4(0,0,0,0)},frameSize:{value:new l.Vector3(1,1,1)},textureSize:{value:new l.Vector2(1,1)}},side:l.FrontSide,transparent:!0,clipping:!0,vertexShader:Ct,fragmentShader:Mt,extensions:{derivatives:!0}}),this.defines.USE_ALPHATEST="",this.needsUpdate=!0}set map(e){this.uniforms.map.value=e,e?void 0===this.defines.USE_UV&&(this.defines.USE_UV="",this.needsUpdate=!0):void 0!==this.defines.USE_UV&&(delete this.defines.USE_UV,this.needsUpdate=!0),this.needsUpdate=!0}get map(){return this.uniforms.map.value}get alphaTest(){return this.uniforms.alphaTest.value}set alphaTest(e){this.uniforms.alphaTest.value=e}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}get opacity(){return this.uniforms.opacity.value}get color(){return this.uniforms.diffuse.value}set color(e){this.uniforms.diffuse.value=e}}class Tt extends i{constructor(){super("children",null,!1),this._uis=[],this._boxes=[]}update(e,t){this._compute(e),e._layouter._needsUpdate=!0,e._renderOrder._needsUpdate=!0}process(e){this._compute(e),e._flexDirection._needsProcess=!0,e._layouter._needsProcess=!0,e._overflow._needsRender=!0}_compute(e){this._uis=e.children.filter((e=>e.visible&&e.isUI)),this._boxes=this._uis.filter((e=>e.isBox)).sort(this._sortOrder)}dispose(){this._uis=null,this._boxes=null}_sortOrder=(e,t)=>e._order._valuet._order._value?1:this._uis.indexOf(e){const i=t._margin._value;return e+(t._bounds._offsetWidth+i.y+i.w)}),0)}(e)}_computeChildrenSideHeight(e){return function(e){return e._children._boxes.reduce(((e,t)=>{const i=t._margin._value;return e+(t._bounds._offsetHeight+i.x+i.z)}),0)}(e)}_propagateWidth(e){for(let t=0;t{let n=0,s=0;"top"===t?s=-i._margin._value.x:"bottom"===t?s=i._margin._value.z:"left"===t?n=i._margin._value.w:"right"===t?n=-i._margin._value.y:"centerX"===t?n=(i._margin._value.w-i._margin._value.y)/2:"centerY"===t&&(s=(-i._margin._value.x+i._margin._value.z)/2),e._layouter._childrenPos[i.id].x+=a+n,e._layouter._childrenPos[i.id].y+=o+s}))}}function Wt(){return 0}function Dt(e,t){return-t+e._bounds._offsetHeight/2}function Et(e,t){return t-e._bounds._offsetHeight/2}function Lt(e,t){return t-e._bounds._offsetWidth/2}function Ht(e,t){return-t+e._bounds._offsetWidth/2}function Gt(e,t){const i=e._bounds._innerWidth/2;e._children._boxes.forEach((n=>{e._layouter._childrenPos[n.id].x=t(n,i)}))}function $t(e,t){const i=e._bounds._innerHeight/2;e._children._boxes.forEach((n=>{e._layouter._childrenPos[n.id].y=t(n,i)}))}class jt extends _e{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0,this._offset=0,this._reverse=1,this._process=this.emptyStrategyLogic}computeOutputValue(e){switch(this._value=this._inheritedInput,this._value){case"row":this._process=Xt;break;case"row-reverse":this._process=Nt;break;case"column":this._process=Yt;break;case"column-reverse":this._process=Kt}e._justifyContent._needsUpdate||e._justifyContent.computeOutputValue(e),e._alignItems._needsUpdate||e._alignItems.computeOutputValue(e),this._needsProcess=!0}process(e){switch(this._value){case"row":this._offset=-e._bounds._innerWidth/2;break;case"row-reverse":this._offset=e._bounds._innerWidth/2;break;case"column":this._offset=e._bounds._innerHeight/2;break;case"column-reverse":this._offset=-e._bounds._innerHeight/2}this._reverse=-Math.sign(this._offset),0===this._reverse&&(this._reverse=1),this._process(e),e._justifyContent._needsProcess=!0,e._layouter._needsProcess=!0}}function Xt(e){let t=e._flexDirection._offset;const i=e._flexDirection._reverse,n=e._children._boxes;for(let s=0;s{e._layouter._childrenPos[t.id].x-=r-o[i]}))}function Qt(e){const t=e._flexDirection._offset,{usedDirectionSpace:i,remainingSpace:n}=function(e){const t=e._bounds._computeChildrenSideHeight(e);return{usedDirectionSpace:t,remainingSpace:e._bounds._innerHeight-t}}(e),s=2*t-i*Math.sign(t),r=this._computeOffset(s),o=this._computeMargin(e,n,e._flexDirection._reverse);e._children._boxes.forEach(((t,i)=>{e._layouter._childrenPos[t.id].y-=r-o[i]}))}function Zt(e){return 0}function ei(e){return e}function ti(e){return e/2}function ii(e,t=0,i=1){return Array(e._children._boxes.length).fill(0)}function ni(e,t=0,i=1){const n=e._children._boxes.length,s=Array(n).fill(0);if(t>0&&n>1){const e=t/(n-1)*i;s[0]=0;for(let t=1;t0){const e=t/(n+1)*i;for(let t=0;t0){const e=t/n*i,r=e/2;s[0]=r;for(let t=1;tt&&(t=n)}return t}(e)}}(e))}(e),e._height._auto&&function(e){e._bounds.setChildrenHeight(e,function(e){switch(e._flexDirection._value){case"row":case"row-reverse":return function(e){let t=0;for(const i of e._children._boxes){if("static"!==i._position._value)continue;const e=i._margin._value,n=i._bounds._offsetHeight+e.x+e.z;n>t&&(t=n)}return t}(e);case"column":case"column-reverse":return function(e){let t=0;for(const i of e._children._boxes){if("static"!==i._position._value)continue;const e=i._margin._value;t+=i._bounds._offsetHeight+e.x+e.z}return t}(e)}}(e))}(e);const t="stretch"===e._alignItems._value,i=t&&-1!==e._flexDirection._value.indexOf("column"),n=t&&!i;for(const t of e._children._boxes)(t._width._auto&&i||t._width._relative)&&t._bounds.setReferenceWidth(t,e._bounds._innerWidth),(t._height._auto&&n||t._height._relative)&&t._bounds.setReferenceHeight(t,e._bounds._innerHeight)}}class fi extends vt{constructor(e,t){fi.definePropertiesValues(e,t),super(e,t),fi.init(this)}bindBackgroundMeshProperties(){this._bounds._size=this._backgroundMesh.scale,this._bounds._needsProcess=!0}unbindBackgroundMeshProperties(){this._bounds._size=new l.Vector3(1,1,1),this._bounds._needsProcess=!0}static definePropertiesValues(e,t){e.children||(e.children=Tt),e.bounds||(e.bounds=Ft),e.flexDirection||(e.flexDirection=jt),e.justifyContent||(e.justifyContent=qt),e.alignItems||(e.alignItems=At),e.position||(e.position=ci),e.autoSize||(e.autoSize=_i),e.renderer||(e.renderer=di),t.fontSide||(t.fontSide=0),t.invertAlpha||(t.invertAlpha=!1),t.fontCastShadow||(t.fontCastShadow=!1),t.fontReceiveShadow||(t.fontReceiveShadow=!1),t.backgroundCastShadow||(t.backgroundCastShadow=!1),t.backgroundReceiveShadow||(t.backgroundReceiveShadow=!1)}static init(e){Object.defineProperties(e,{isBox:{configurable:!1,enumerable:!0,value:!0}}),e.backgroundMaterial=new Pt,e._renderer.render(e),e._backgroundMesh.visible=!1}}class pi extends Array{constructor(...e){super(...e),this.width=0,this.lineBase=0,this.lineHeight=0,this.y=0}}class gi extends i{constructor(){super("layouter",null,!1),this._needsUpdate=!0,this._childrenPos={}}update(e,t){this._childrenPos={};for(const t of e._children._boxes)"static"===t._position._value&&(this._childrenPos[t.id]=t.position)}process(e){}}class mi extends fi{constructor(e={}){const t={};mi.definePropertiesValues(t,e),super(t,e),mi.init(this)}add(e){const t=[];for(let e=0;ee.asInlineGlyph())),this._value.length){this._value[0].paddingLeft=e._padding._value.w,this._value[0].marginLeft=e._margin._value.w;const t=this._value.length-1;this._value[t].paddingRight=e._padding._value.y,this._value[t].marginRight=e._margin._value.y}e._fontSize._needsProcess=!0,e._lineBreak._needsProcess=!0,e._fontKerning._needsProcess=!0,e._layouter._needsProcess=!0}get value(){return this._value}}class yi extends i{constructor(){super("glyphs",null,!1),this._needsUpdate=!1,this._value=null}process(e){e._font._fontVariant&&e._font._fontVariant.isReady&&(this._value=e._whiteSpace._whiteSpacedContent.split("").map((t=>e._font._fontVariant.getTypographicGlyph(t))),this._value&&(e._inlines._needsProcess=!0))}get value(){return this._value}}class xi extends D{constructor(){super("color","inherit",!1),this.output=this._outputValue}computeOutputValue(e){"inherit"===this._input?this._value.set(this.getInheritedInput(e)):this._value.set(this._input)}}class wi extends i{constructor(e="- ,.:?!\n"){super("lineBreak",e,!0),this._newLineBreakability=null}update(e,t){this._needsProcess=!0}process(e){const t=e._whiteSpace._newLineBreakability;if(e._inlines._value)for(let i=0;ie.isUI&&e.isText)),this._needsProcess=!0}process(e){this._value&&(this._value._layouter._needsProcess=!0)}}class Vi extends D{constructor(e){super("backgroundColor",e,!1),this._allowsInherit=!1,this._input=0}computeOutputValue(e){"inherit"===this._input?this._value.set(this.getInheritedInput(e)):this._value.set(this._input)}}class ki extends Ue{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class Ri extends Ie{constructor(){super()}computeOutputValue(e){this._value=U(this.getInheritedInput(e))}}class Ui extends nt{constructor(){super("fontFamily","inherit",!0),this._input="inherit",this._needsUpdate=!0,this._allowsInherit=!1}computeOutputValue(e){let t=this._inheritedInput;if("inherit"===t&&(t=this.getInheritedInput(e)),t instanceof Qe)this._value=t,e._font._needsUpdate=!0;else if("string"==typeof t){const i=it.getFontFamily(t);i?(this._value=i,e._font._needsUpdate=!0):console.warn(`(.style) fontFamily, the font '${t}' is not registered. Aborted.`)}else console.warn("(.style) fontFamily requires a registered fontFamily instance, or the id of a registered fontFamily."),console.warn("If you want to set a specific font, please use .font property instead.")}get value(){return this._value}}class Ci extends rt{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited,this._whiteSpacedContent="",this._stringCollapser=this.emptyStrategyLogic,this._inlineCollapser=this.emptyStrategyLogic,this._inlineWrapper=this.emptyStrategyLogic}_computeFromInherited(e){switch(super._computeFromInherited(e),this._newLineBreakability=Ii(this._value),this._value){case"nowrap":case"normal":this._stringCollapser=Bi;break;case"pre-line":this._stringCollapser=Pi;break;default:this._stringCollapser=Ti}switch(this._value){case"pre-line":case"nowrap":case"normal":this._inlineCollapser=Wi;break;case"pre-wrap":this._inlineCollapser=Ai;break;default:this._inlineCollapser=Di}switch(this._value){case"pre-line":case"pre-wrap":case"normal":this._inlineWrapper=Fi;break;case"pre":this._inlineWrapper=zi;break;default:this._inlineWrapper=Oi}this._needsProcess=!0}process(e){e.isInline&&!e.isInlineBlock&&(this._whiteSpacedContent=this._stringCollapser(e._textContent._value),e._glyphs._needsProcess=!0)}}const Mi={"\t":"\t","\n":"\n","\r":"\r"," ":" "},Ii=function(e){switch(e){case"pre":case"pre-wrap":case"pre-line":return"mandatory"}return null};function Bi(e){return Pi(e.replace(/\n/g," "))}function Pi(e){return e.replace(/[ ]{2,}/g," ")}function Ti(e){return e}function Fi(e,t,i,n){const s=e[t];if("mandatory"===s.lineBreak)return!0;if(i+s.xadvance+s.xoffset+s.kerning>n.INNER_WIDTH)return!0;const r=Hi(e,t,n);return function(e,t,i,n){return!(!e||!e.char)&&(!(t+i-1)}(e[t-1],i,r,n)}function zi(e,t,i,n){return"mandatory"===e[t].lineBreak}function Oi(){return!1}function Ai(e){if(!e[0])return 0;const t=e[0],i=e[e.length-1];return t.char&&"\n"===t.char&&e.length>1&&Li([t],e[1]),i.char&&"\n"===i.char&&e.length>1&&Ei([i],e[e.length-2]),t.offsetX}function Wi(e){if(!e[0])return 0;let t,i=[];for(let n=0;nn))break;i.push(s),t=e[n+1]}Li(i,t),i=[],t=null;for(let n=e.length-1;n>0;n--){const s=e[n];if(!(s.char&&Mi[s.char]&&n>0))break;i.push(s),t=e[n-1]}return Ei(i,t),e[0].offsetX}function Di(e){return e[0]?e[0].offsetX:0}function Ei(e,t){if(t)for(let i=0;ie._font._fontVariant.getGeometricGlyph(t,e).translate(t.offsetX,t.offsetY,0))));e.setFontMesh(new l.Mesh(t,e.fontMaterial)),e._fontMesh.renderOrder=1/0}}class Ji extends ue{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(e){this._value=this._inheritedInput,e._layouter._needsProcess=!0}}class Qi extends vt{constructor(e={}){const t={};Qi.definePropertiesValues(t,e),super(t,e),Qi.init(this)}add(e){const t=[];for(let e=0;e{super._rebuildParentUI(),this._layouter._needsUpdate=!0};set textContent(e){this._textContent.value=e}get textContent(){return this._textContent._value}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(e,t){e.children||(e.children=Yi),e.textContent||(e.textContent=vi),e.glyphs||(e.glyphs=yi),e.inlines||(e.inlines=bi),e.layouter||(e.layouter=Si),e.renderer||(e.renderer=qi),e.fontFamily||(e.fontFamily=Ui),e.fontWeight||(e.fontWeight=Ri),e.fontStyle||(e.fontStyle=ki),e.fontSize||(e.fontSize=$i),e.color||(e.color=xi),e.backgroundColor||(e.backgroundColor=Vi),e.lineBreak||(e.lineBreak=wi),e.letterSpacing||(e.letterSpacing=Gi),e.whiteSpace||(e.whiteSpace=Ci),e.segments||(e.segments=Xi),e.textAlign||(e.textAlign=Ji),e.fontKerning||(e.fontKerning=Ni)}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class Zi extends Re{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}update(e,t){this._needsUpdate=!1;for(let t=e.children.length-1;t>=0;t--){const i=e.children[t];i.isUI&&(e.remove(i),i.clear())}e._children._uis=[],this._value&&e.add(new Qi({name:"anonymousInline",textContent:this._value}))}}class en extends Array{constructor(...e){super(...e),this.width=0,this.height=0}}class tn extends i{constructor(){super("layouter",null,!1),this._value=null}update(e,t){}process(e){let t=e._width._value;t=e._width._auto?1/0:e._bounds._innerWidth;const i=e._lineHeight._value,n=new en(new pi);let s=0;e._children._inlines.forEach((e=>{if(!e._inlines.value)return;this._resetInlines(e);const i=e._fontSize._value,r=e._letterSpacing._value*i,o=e._whiteSpace._value,a=e._lineBreak._value,h={WHITESPACE:o,LETTERSPACING:r,BREAKON:a,INNER_WIDTH:t},l=e._whiteSpace._inlineWrapper;s+=e._margin._value.w+e._padding._value.w,e._inlines.value.forEach(((e,t,i)=>{const o=n[n.length-1];if(l(i,t,s,h))return n.push(new pi(e)),e.offsetX=e.xoffset,0===e.width?void(s=0):(e.cumulativeWidth=e.xadvance+r,void(s=e.cumulativeWidth));n[n.length-1].push(e),e.offsetX=s+e.xoffset+e.kerning,e.cumulativeWidth=e.xadvance+e.kerning+r,s+=e.cumulativeWidth,o.length-1==1&&0===o[o.length-2].width&&(e.offsetX-=e.xoffset,s-=e.xoffset)})),s+=e._margin._value.y+e._padding._value.y}));const r=e._whiteSpace._inlineCollapser;let o=0,a=0,h=0;n.forEach(((e,t)=>{const s=r(e);let l=0,u=0;if(e.forEach((e=>{l=Math.max(l,e.lineHeight),u=Math.max(u,e.lineBase),e.offsetX-=s})),e.lineHeight=l,e.lineBase=u,0===t?h=.5*-(l*i-l):h-=n[t-1].lineHeight*i,e.y=h,e.x=0,e.forEach((t=>{t.offsetY=h-t.anchor,t.lineHeighte.visible&&e.isUI)),this._inlines=this._uis.filter((e=>e.isInline)).sort(this._sortOrder)}dispose(){this._inlines=null}_sortOrder=(e,t)=>e._order._valuet._order._value?1:this._uis.indexOf(e)0&&super.add(...t),i&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(e){this._textContent.value=e}get textContent(){return super.textContent}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(e,t){e.flexDirection=rn,e.justifyContent=ge,e.alignItems=le,e.bounds=hn,e.autoSize=un,e.renderer=dn,e.children||(e.children=ln),e.textContent||(e.textContent=Zi),e.layouter||(e.layouter=tn),e.lineHeight||(e.lineHeight=on),e.textAlign||(e.textAlign=nn),e.whiteSpace||(e.whiteSpace=Ci),e.fontKerning||(e.fontKerning=an),e.segments||(e.segments=ji),t.width||(t.width="100%"),t.fontSide||(t.fontSide=0)}static init(e){Object.defineProperties(e,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class _n extends i{constructor(){super("inlines",null,!1),this._value=[]}process(e){this._value[0].paddingLeft=e._padding._value.w,this._value[0].marginLeft=e._margin._value.w;const t=this._value.length-1;this._value[t].paddingRight=e._padding._value.y,this._value[t].marginRight=e._margin._value.y}}class fn extends i{constructor(){super("renderer")}render(e){e._backgroundMesh||e.setBackgroundMesh(new ai(e)),e._backgroundMesh.position.x=e._inlines._value[0].offsetX+e._inlines._value[0].width/2,e._backgroundMesh.position.y=e._inlines._value[0].offsetY+e._inlines._value[0].lineBase/2,e._bounds.render(e)}}class pn extends i{constructor(){super("bounds",null,!1),this._size=new l.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(e,t){this.output(t),this._needsProcess=!0}process(e){this._offsetWidth=this._innerWidth=e._inlines._value[0].width,this._offsetHeight=this._innerHeight=e._inlines._value[0].height,this._needsRender=!0,e._borderWidth._needsRender=!0,e._borderRadius._needsRender=!0}render(e){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(e){e.size=this._size}}class gn extends vt{constructor(e={}){const t={};gn.definePropertiesValues(t,e),super(t,e),gn.init(this)}clear(){for(const e of this._inlines._value)e.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new l.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(e){const t=[];for(let e=0;ebt.update(),MSDFFontMaterialUtils:Xe,ShaderChunkUI:Ut,Behavior:class{constructor(e){this._subject=e}attach(){console.error(`Behavior::attach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}act(){throw new Error(`Behavior::act() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}detach(){console.error(`Behavior::detach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}clear(){}},FontVariant:I};void 0!==e.g&&(e.g.ThreeMeshUI=vn)})();