UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.

2,061 lines • 178 kB
var It = Object.defineProperty; var Ct = (i, e, t) => e in i ? It(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t; var I = (i, e, t) => Ct(i, typeof e != "symbol" ? e + "" : e, t); import { Vector4 as Rt, Vector3 as Bt, Vector2 as Ut, TextureLoader as At, Texture as Tt, ShaderMaterial as Mt, PlaneGeometry as Ft, Plane as Ot, Object3D as Lt, MeshBasicMaterial as zt, Mesh as Wt, LinearFilter as Et, FrontSide as Dt, FileLoader as Ht, EventDispatcher as Gt, DoubleSide as $t, Color as Nt, BufferGeometry as Xt, BufferAttribute as jt, BackSide as Yt } from "./three-Bz6X1mrw.js"; var V = {}; V.d = (i, e) => { for (var t in e) V.o(e, t) && !V.o(i, t) && Object.defineProperty(i, t, { enumerable: !0, get: e[t] }); }; V.o = (i, e) => Object.prototype.hasOwnProperty.call(i, e); V.r = (i) => { typeof Symbol < "u" && Symbol.toStringTag && Object.defineProperty(i, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(i, "__esModule", { value: !0 }); }; var m = {}; V.d(m, { ti: () => ( /* reexport */ p ), nS: () => ( /* reexport */ bt ), eB: () => ( /* reexport */ M ), Yp: () => ( /* reexport */ oe ), VB: () => ( /* reexport */ C ), BC: () => ( /* reexport */ L ), zN: () => ( /* reexport */ R ), cV: () => ( /* reexport */ U ), hW: () => ( /* reexport */ O ), k2: () => ( /* reexport */ We ), K6: () => ( /* reexport */ w ), M7: () => ( /* reexport */ ae ), ls: () => ( /* reexport */ z ), Hi: () => ( /* reexport */ it ), EY: () => ( /* reexport */ F ), MR: () => ( /* reexport */ Ye ), zf: () => ( /* reexport */ ze ), Ay: () => ( /* binding */ ln ), yo: () => ( /* binding */ xt ) }); var oe = {}; V.r(oe); V.d(oe, { get: () => Oe, set: () => Kt }); var ae = {}; V.r(ae); V.d(ae, { alphaTestTransformer: () => K, asPreprocessorValueTransformer: () => Ke, toPreprocessorTriggerTransformer: () => ve, toUserDataTransformer: () => os, uniformOrUserDataTransformer: () => x }); const re = { fontFamily: null, fontSize: 0.05, fontKerning: "auto", fontStyle: "normal", fontWeight: "normal", offset: 5e-3, lineHeight: 1.2, lineBreak: `- ,.:?! `, // added '\n' to also acts as friendly breaks when white-space:normal 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 }, Kt = function(i) { for (const e in i) re[e] = i[e]; }, Oe = function(i) { return Object.prototype.hasOwnProperty.call(re, i) || console.warn(`ThreeMeshUI::DefaultValues is trying to retrieve non-existing property '${i}'`), re[i]; }; class p { /** * * @param {string} propertyId * @param {any} [value=null] * @param primitive */ constructor(e, t = null, s = !0) { this._id = e, this._value = t, this._needsUpdate = !0, this._needsProcess = !1, this._needsRender = !1, this._isPrimitive = s; } /** * * @return {string} */ get id() { return this._id; } /** * * @return {any} */ get value() { return this._value; } /** * * @param {any} value */ set value(e) { this.isValid(e) && this._value !== e && (this._value = e, this._needsUpdate = !0); } /* eslint-disable no-unused-vars */ /** * * @param element * @param {Object.<string,any>} out */ update(e, t) { this.output(t); } /* eslint-disable no-unused-vars */ /** * Output this property in a dictionnary * @param {Object.<string,any>} out */ output(e) { } /** * * @param {Out} out */ _outputValue(e) { e[this._id] = this._value; } /* eslint-disable no-unused-vars */ /** * Execute additional process after all properties have been updated * @param {MeshUIBaseElement} element */ process(e) { } /* eslint-disable no-unused-vars */ /** * Execute additional process after all properties have been updated * @param {MeshUIBaseElement} element */ render(e) { } /** * * @param {MeshUIBaseElement} element */ getInheritedInput(e) { if (this._value !== "inherit") return this._value; const t = e._parent._value; return t && t[`_${this._id}`] ? t[`_${this._id}`].getInheritedInput(t) : this.getDefaultValue(); } /** * * @return {any} */ getDefaultValue() { return Oe(this._id); } /* eslint-disable no-unused-vars */ /** * * @param {any} value * @return {boolean} */ 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 qt extends p { constructor() { super("renderOrder", "auto", !0), this.output = this._outputValue, this._actualValue = 0; } /** * * @param {number} value */ set value(e) { this.isValid(e) && (this._value = e, this._needsUpdate = !0); } update(e, t) { if (this._value !== "auto") this._actualValue = this._value; else { const s = e._parent._value; if (s !== null) { const r = s._renderOrder._actualValue, n = 1 + s._children._uis.indexOf(e); this._actualValue = r + n; } } for (const s of e._children._uis) s._renderOrder._value === "auto" && (s._renderOrder._needsUpdate = !0); this._outputValue(t); } _outputValue(e) { e[this._id] = this._actualValue; } /** * * @return {number} */ get value() { return this._value; } } class R extends p { /** * * @param {string} propertyId * @param {any} [value=null] * @param primitive */ constructor(e, t = null, s = !0) { super(e, t, s), this.output = this._outputValue, this._notInheritedValue = null; } update(e, t) { this._notInheritedValue = this._value, this._notInheritedValue === "inherit" && (this._notInheritedValue = this.getInheritedInput(e)), this.propagate(e), this._outputValue(t); } propagate(e) { for (const t of e._children._uis) { const s = t[`_${this._id}`]; s !== void 0 && s._value === "inherit" && (t[`_${this._id}`]._needsUpdate = !0); } } /** * Output this property in a dictionnary * @override */ _outputValue(e) { e[this._id] = this._notInheritedValue; } set value(e) { this.isValid(e) && this._value !== e && (this._value = e, this._needsUpdate = !0); } /** * * @override * @return {any|"inherit"} */ get value() { return this._value === "inherit" ? this._notInheritedValue : this._value; } } class Jt extends R { constructor() { super("offset", "inherit", !1); } /* eslint-disable no-unused-vars */ update(e, t) { super.update(e, t), e._parent._value !== null && (e.position.z = this._notInheritedValue); } } class Zt extends R { constructor() { super("fontSmooth", "inherit", !0), this._needsUpdate = !1, this.isValid = ei, this.output = this._outputValue; } } const Qt = ["inherit", "none", "antialiased"]; function ei(i) { return Qt.indexOf(i) === -1 ? (console.warn(`.fontSmoothing value '${i}' is not valid. Aborted`), !1) : !0; } var ti = (i) => { var e = {}; return V.d(e, i), e; }; const u = ti({ BackSide: () => Yt, BufferAttribute: () => jt, BufferGeometry: () => Xt, Color: () => Nt, DoubleSide: () => $t, EventDispatcher: () => Gt, FileLoader: () => Ht, FrontSide: () => Dt, LinearFilter: () => Et, Mesh: () => Wt, MeshBasicMaterial: () => zt, Object3D: () => Lt, Plane: () => Ot, PlaneGeometry: () => Ft, ShaderMaterial: () => Mt, Texture: () => Tt, TextureLoader: () => At, Vector2: () => Ut, Vector3: () => Bt, Vector4: () => Rt }); class g extends p { /** * * @param {string} propertyId * @param {boolean} [primitive=true] * @param {any} defaultValue */ constructor(e, t, s = !0) { super(e, "unset", s), this._input = "inherit", this._allowsInherit = !0, this._inheritedInput = void 0, this._inline = void 0; } /** * * @param {MeshUIBaseElement} element * @param {Object.<string,any> } out */ update(e, t) { this._allowsInherit || (this._inheritedInput = this.getInheritedInput(e)), this.computeOutputValue(e); for (const s of e._children._uis) { const r = s[`_${this._id}`]; (r._input ? r._input : r._value) === "inherit" && (s[`_${this._id}`]._needsUpdate = !0); } this.output(t); } /** * * @param {MeshUIBaseElement} element */ computeOutputValue(e) { this._value = this._input; } /** * * @param {MeshUIBaseElement} element */ _computeFromInherited(e) { this._value = this._inheritedInput; } /** * @override * @deprecated * @param {any} v */ set value(e) { console.warn(".(style) sub-property cannot be directly set. It must comes from inline or computed setter."); } /** * * @param {any} value */ set inline(e) { this.isValidValue(e) && e !== this._inline && (this._input = this._inline = e, this._needsUpdate = !0); } /** * * @return {any} */ get inline() { return this._inline; } /** * * @param {any} value * @return {boolean} */ isValidValue(e) { return !0; } /** * @param {MeshUIBaseElement} element */ getInheritedInput(e) { if (this._input !== "inherit") return this._input; const t = e._parent._value; return t ? t[`_${this._id}`].getInheritedInput(t) : this.getDefaultValue(); } } class Y extends g { constructor(e, t) { super(e, t, !1), this._input = new u.Vector4(0, 0, 0, 0), this._inline = null, this._value = new u.Vector4(0, 0, 0, 0); } /** * @override * @return {Vector4} */ get value() { return this._value; } /* eslint-disable no-unused-vars */ /** * @override */ computeOutputValue(e) { this._vector4ValueSetter(this._value, this._input); } set inline(e) { this._vector4ValueSetter(this._input, e), !this._input.equals(this._value) && (this._needsUpdate = !0); } /** * * @param {Number} v */ set top(e) { this._input.x !== e && (this._input.x = e, this._needsUpdate = !0); } /** * * @returns {number} */ get top() { return this._input.x; } /** * * @param {Number} v */ set right(e) { this._input.y !== e && (this._input.y = e, this._needsUpdate = !0); } /** * * @returns {number} */ get right() { return this._input.y; } /** * * @param {Number} v */ set bottom(e) { this._input.z !== e && (this._input.z = e, this._needsUpdate = !0); } /** * * @returns {number} */ get bottom() { return this._input.z; } /** * * @param {Number} v */ set left(e) { this._input.w !== e && (this._input.w = e, this._needsUpdate = !0); } /** * * @returns {number} */ get left() { return this._input.w; } dispose() { this._computed = null, this._inline = null, this._input = null, this._output = null; } /** * * @param {Vector4} vector4 * @param {Vector4|Array.<Number>|Number|String} value * @protected */ _vector4ValueSetter(e, t) { if (t instanceof u.Vector4) { e.copy(t); return; } if ((typeof t == "string" || t instanceof String) && (t = t.split(" ")), Array.isArray(t)) switch (t = t.map((s) => parseFloat(s)), t.length) { case 1: e.setScalar(t[0]); return; case 2: e.x = e.z = t[0], e.y = e.w = t[1]; return; case 3: e.x = t[0], e.y = t[1], e.z = t[2]; return; case 4: e.x = t[0], e.y = t[1], e.z = t[2], e.w = t[3]; return; default: console.error("StyleVector4Property::set() Four Dimension property had more than four values"); return; } isNaN(t) || e.setScalar(t); } } class ii extends Y { constructor() { super("padding", new u.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 si extends Y { constructor() { super("margin", new u.Vector4(0, 0, 0, 0)); } computeOutputValue(e) { super.computeOutputValue(e), e._renderer._needsRender = !0, e._parent._value && (e._parent._value._flexDirection._needsProcess = !0); } } const Ce = function(i, e, t) { i[e] = t; }, ri = function(i, e, t) { t !== null && (i[e] = t); }; class W { /** * @constructor * @param {MediationDefinition} definition */ constructor(e) { this._definition = e; } /** * * @param {MediationDefinition} value */ set definition(e) { this._definition = e; } /** * * @param {MeshUIBaseElement} subject * @param {any} target * @param {Object.<(string|number), any>} options * @param {any} [secondTarget=null] */ mediate(e, t, s, r = null) { for (const n in this._definition) { const o = this._definition[n]; if (s[n] !== void 0) { const a = o.t ? o.t : Ce; a(t, o.m, s[n]), r && a(r, o.m, s[n]); } } } /*********************************************************************************************************************** * STATIC **********************************************************************************************************************/ /** * * @param {MeshUIComponent} subject * @param {any} target * @param {Object.<(string|number), any>} options * @param {Object.<{subjectProperty:string, t?:(target:any, targetProperty:string, value:any) => void}>} mediationDefinitions * @param {any} [secondTarget=null] */ static mediate(e, t, s, r, n = null) { if (t) for (const o in r) { const a = r[o]; if (s[o] !== void 0) { const l = a.t ? a.t : Ce; l(t, a.m, s[o]), n && l(n, a.m, s[o]); } } } } class ni extends p { constructor() { super("parent", null, !1); } /* eslint-disable no-unused-vars */ /** * Update when : * - element has been added * - element has been removed * * @param element * @param out */ update(e, t) { e.parent && e.parent.isUI ? this._value = e.parent : this._value = null; } set value(e) { console.warn("ParentProperty is readonly"); } /** * * @return {MeshUIBaseElement} */ get value() { return this._value; } /** * * @param {(p:Object3D)=>boolean } conditionCallback */ find(e) { return this._value ? e(this._value) ? this._value : this._value._parent.find(e) : null; } /** * */ dispose() { this._value = null; } } const ne = function(i, e, t = 6) { return i.toFixed(t) === e.toFixed(t); }; class Re extends p { /** * * @param {string} propertyId * @param {number} [value] */ constructor(e, t) { super(e, t, !0), this.output = this._outputValue; } /** * * @param {number} value */ set value(e) { this.isValid(e) && (ne(this._value, e) || (this._value = e, this._needsUpdate = !0)); } /** * * @return {number} */ get value() { return this._value; } } class Be extends R { /** * * @param {string} propertyId */ constructor(e) { super(e, "inherit", !0), this.isValid = ai; } } const oi = [u.FrontSide, u.BackSide, u.DoubleSide]; function ai(i) { return oi.indexOf(i) === -1 ? (console.warn(`SideProperty value '${i}' is not valid. Abort`), !1) : !0; } class Le { 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; } /** * @returns {void} */ resetOffsets() { this._offsetX = this._offsetY = 0, this._cumulativeWidth = 0; } /** * The horizontal distance this inline fills * @returns {number} */ get xadvance() { return 0; } /** * The offset x of this inline in a line * @returns {number} */ get xoffset() { return 0; } /** * The offset y of this inline in a line * @returns {number} */ get yoffset() { return 0; } /** * * @returns {number} */ get width() { return 0; } /** * * @returns {number} */ get height() { return 0; } /** * * @param {string|null} value */ set lineBreak(e) { this._lineBreak = e; } /** * * @returns {string|null} */ get lineBreak() { return this._lineBreak; } /** * * @returns {number} */ get anchor() { return 0; } /** * * @returns {number} */ get kerning() { return this._kerning * this._fontFactor; } /** * * @param {number} value */ set kerning(e) { this._kerning = e; } /** * * @returns {number} */ get fontSize() { return this._fontSize; } /** * * @param {number} value */ set fontSize(e) { this._fontSize = e; } /** * * @returns {number} */ get lineHeight() { return 0; } /** * * @returns {number} */ get offsetX() { return this._offsetX; } /** * * @param value */ set offsetX(e) { this._offsetX = e; } /** * * @returns {number} */ get offsetY() { return this._offsetY; } /** * * @param {number} value */ set offsetY(e) { this._offsetY = e; } /** * * @return {number} */ get cumulativeWidth() { return this._cumulativeWidth; } /** * * @param {number} value */ set cumulativeWidth(e) { this._cumulativeWidth = e; } /** * * @return {number} */ get marginLeft() { return this._marginLeft; } /** * * @param {number} value */ set marginLeft(e) { this._marginLeft = e; } /** * * @return {number} */ get marginRight() { return this._marginRight; } /** * * @param {number} value */ set marginRight(e) { this._marginRight = e; } /** * * @return {number} */ get paddingLeft() { return this._paddingLeft; } /** * * @param {number} value */ set paddingLeft(e) { this._paddingLeft = e; } /** * * @return {number} */ get paddingRight() { return this._paddingRight; } /** * * @param {number} value */ set paddingRight(e) { this._paddingRight = e; } /** * * @returns {number} */ get lineBase() { return 0; } /** * * @param {number} value */ set fontFactor(e) { this._fontFactor = e; } /** * * @returns {number} */ get fontFactor() { return this._fontFactor; } } class ze { /** * * @param {TypographicFont} typographicFont */ constructor(e) { this._char = "", this._width = 1, this._heigth = 1, this._xadvance = 1, this._xoffset = 0, this._yoffset = 0, this._font = e; } /** * * @returns {TypographicFont} */ get font() { return this._font; } /** * * @return {string} */ get char() { return this._char; } /** * * @returns {number} */ get width() { return this._width; } /** * * @returns {number} */ get height() { return this._heigth; } /** * * @returns {number} */ get xadvance() { return this._xadvance; } /** * * @returns {number} */ get xoffset() { return this._xoffset; } /** * * @returns {number} */ get yoffset() { return this._yoffset; } /** * * @param value */ set yoffset(e) { this._yoffset = e; } /** * * @abstract * @param {string} otherChar * @returns {TypographicGlyph} */ /* eslint-disable no-unused-vars */ clone(e) { throw new Error("Abstract... Need to be implemented"); } /** * * @abstract * @returns {InlineGlyph} */ asInlineGlyph() { throw new Error("Abstract... Need to be implemented"); } } class We extends Le { /** * * @param {TypographicGlyph} characterDesc */ constructor(e) { super(), this._typographic = e; } /** * * @returns {TypographicGlyph} */ get typographic() { return this._typographic; } /********************************************************************************************************************* * GETTERS FROM CHARACTER DESCRIPTION ********************************************************************************************************************/ /** * @override * @returns {number} */ get xadvance() { return this._typographic.xadvance * this._fontFactor; } /** * @override * @returns {number} */ get xoffset() { return this._typographic.xoffset * this._fontFactor; } /** * @override * @returns {number} */ get yoffset() { return this._typographic.yoffset * this._fontFactor; } /** * @override * @returns {number} */ get width() { return this._typographic.width * this._fontFactor; } /** * @override * @returns {number} */ get height() { return this._typographic.height * this._fontFactor; } /** * * @return {string} */ get char() { return this._typographic.char; } /** * @override * @returns {number} */ get anchor() { return this.yoffset; } /** * @override * @returns {number} */ get lineHeight() { return this._typographic.font.lineHeight * this._fontFactor; } /** * @override * @returns {number} */ get lineBase() { return this._typographic.font.lineBase * this._fontFactor; } } const ui = { light: "100", normal: "400", bold: "700", bolder: "900" }; function ue(i) { if (!isNaN(i)) return i.toString(); const e = ui[i]; return e || i; } class hi extends u.EventDispatcher { /** * * @param {import('./../core/elements/MeshUIBaseElement').FontWeightFormat} weight * @param {"normal"|"italic"} style */ constructor(e, t) { super(), this._isReady = !1, this._weight = ue(e), this._style = t, this._size = 42, this._lineHeight = 42, this._lineBase = 42, this._font = null; } /** * * @returns {TypographicFont} */ get typographic() { return this._font; } /** * * @returns {boolean} */ get isReady() { return this._isReady; } /** * * @returns {string} */ get weight() { return this._weight; } /** * * @returns {string} */ get style() { return this._style; } /** * * @returns {Texture} */ get texture() { return this._texture; } /** * @param {Function.<ShaderMaterial|Material>} v * @abstract */ set fontMaterial(e) { throw Error(`FontVariant('${this.id}')::fontMaterial - is abstract.`); } /** * @return {Function.<ShaderMaterial|Material>} * @abstract */ get fontMaterial() { throw Error(`FontVariant('${this.id}')::fontMaterial - is abstract.`); } /** * * @returns {string} */ get id() { return `${this._name}(w:${this.weight},s:${this.style})`; } /** * * @param {string} character * @returns {TypographicGlyph} */ getTypographicGlyph(e) { let t = this._chars[e]; if (t) return t; if (e.match(/\s/)) return this._chars[" "]; const s = this._getFallbackCharacter(e); if (s && (t = this._chars[s], t)) return t; throw Error(`FontVariant('${this.id}')::getTypographicGlyph() - character('${e}') and/or fallback character were not found in provided msdf charset.`); } /* eslint-disable no-unused-vars */ /** * @abstract * @protected * @param {string} missingChar * @returns {string|null} */ _getFallbackCharacter(e) { throw new Error(`FontVariant(${typeof this})::_getFallbackCharacter() is abstract and should therefore be overridden.`); } /* eslint-disable no-unused-vars */ /** * Convert an InlineCharacter to a geometry * * @abstract * @param {InlineGlyph} inline * @param {MeshUIBaseElement} element * @returns {BufferGeometry|Array.<BufferGeometry>} */ getGeometricGlyph(e, t) { throw new Error(`FontVariant(${typeof this})::getGeometryCharacter() is abstract and should therefore be overridden.`); } /* eslint-enable no-unused-vars */ /** * Obtain the kerning amount of a glyphPair * @param {string} glyphPair * @returns {number} */ getKerningAmount(e) { return this._kernings[e] ? this._kernings[e] : 0; } /** * Perform some changes on the character description of this font * @param {Object.<string,Object.<string,number|string>>} adjustmentObject */ adjustTypographicGlyphs(e) { for (const t in e) { const s = this.getTypographicGlyph(t), r = e[t]; for (const n in r) s["_" + n] = e[t][n]; } } /** * * @private */ _checkReadiness() { this._readyCondition() && ci(this); } /* eslint-disable no-unused-vars */ /** * @abstract * @param element * @internal */ _alterElementProperties(e) { throw new Error(`FontVariant(${typeof this})::_alterElementProperties() is abstract and should therefore be overridden.`); } /** * * @abstract * @returns {boolean} * @protected */ _readyCondition() { throw new Error(`FontVariant(${typeof this})::_readyCondition() is abstract and should therefore be overridden.`); } } const li = { type: "ready" }; function ci(i) { i._isReady = !0, i.dispatchEvent(li); } const L = hi; class di extends p { /** * * @param {FontVariant} [value=null] */ constructor(e = null) { super("font", e, !1), this._needsUpdate = !1, this._fontVariant = null, this._handleFontReadyClosure = null, this.isValid = _i; } output(e) { e[this._id] = this._fontVariant; } /* eslint-disable no-unused-vars */ /** * * @override */ update(e, t) { if (this._fontVariant && !this._fontVariant.isReady && this._fontVariant.removeEventListener("ready", this._handleFontReadyClosure), this._value && this._value instanceof L) this._fontVariant = this._value; else { const s = e._fontFamily._value; s && (this._fontVariant = s.getVariant( e._fontWeight._value, e._fontStyle._value )); } this._fontVariant && (this._fontVariant._alterElementProperties(e), this._handleFontReadyClosure = fi(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)); } /** * @override * @param {FontVariant} value */ set value(e) { this.isValid(e) && this._value !== e && (this._value = e, this._needsUpdate = !0); } /** * * @return {FontVariant} */ get value() { return this._value; } /** * * @return {FontVariant|null} */ get fontVariant() { return this._fontVariant; } /** * */ dispose() { this._handleFontReadyClosure && (this._fontVariant.removeEventListener("ready", this._handleFontReadyClosure), this._handleFontReadyClosure = null), this._value = null, this._fontVariant = null; } } function _i(i) { return i instanceof L ? !0 : (console.warn(`.font value '${i}' is not valid. It requires a FontVariant instance. Aborted`), !1); } function fi(i, e) { return function() { e._needsUpdate = !0, i._glyphs._needsProcess = !0, e._fontVariant.removeEventListener("ready", e._handleFontReadyClosure), e._handleFontReadyClosure = null; }; } class pi extends g { constructor(e) { super("display", e), this._value = "flex", this._allowsInherit = !1, this._needsUpdate = !1, this.isValidValue = mi; } computeOutputValue(e) { e._visible._value = this._output !== "none"; } } const gi = ["none", "flex"]; function mi(i) { return gi.indexOf(i) === -1 ? (console.warn(`(.style) display value '${i}' is not valid. Aborted`), !1) : !0; } class vi extends g { constructor(e) { super("boxSizing", e), this._allowsInherit = !1, this.isValidValue = bi; } computeOutputValue(e) { this._value = this._inheritedInput, e._bounds._needsUpdate = !0; } } const yi = ["border-box", "content-box"]; function bi(i) { return yi.indexOf(i) === -1 ? (console.warn(`(.style) boxSizing value '${i}' is not valid. Aborted`), !1) : !0; } class A extends g { constructor(e, t) { super(e, t, !1), this._value = new u.Color(), this.output = this._outputValue; } /* eslint-disable no-unused-vars */ /** * @override */ computeOutputValue(e) { this._input !== "inherit" && this._value.set(this._input); } set inline(e) { this._input = this._inline = e, this._needsUpdate = !0; } } class Q extends g { /** * * @param {string} propertyId * @param {any} defaultValue */ constructor(e, t) { super(e, t, !0), this.isValidValue = xi, 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 xi(i) { return i < 0 && i > 1 ? (console.warn(`(.style) styleFactorProperty('${this.id}') value '${i}' is not valid)`), !1) : !0; } class wi extends g { constructor(e) { super("backgroundImage", e, !0), this._input = null, this._allowsInherit = !1, this._textureSize = new u.Vector2(1, 1), this.isValidValue = Si; } /** * @override * @return {any|Texture|null} */ get value() { return this._value; } output(e) { e[this._id] = this._value, e.tSize = this._textureSize; } /* eslint-disable no-unused-vars */ computeOutputValue(e) { if (this._value = this._inheritedInput, this._value instanceof u.Texture && !this._value.image) { console.warn("ThreeMeshUI - .backgroundImage :: Please provide preloaded texture in order to have accurate sizing."); return; } this._needsProcess = !0; } /* eslint-disable no-unused-vars */ /** * * @param element */ process(e) { this._value ? this._textureSize.set(this._value.image.width, this._value.image.height) : this._textureSize.set(1, 1); } } function Si(i) { return !0; } class Vi extends g { constructor(e) { super("backgroundSize", e, !0), this.isValidValue = Pi, this.output = this._outputValue; } } const ki = ["cover", "contain", "stretch"]; function Pi(i) { return ki.indexOf(i) === -1 ? (console.warn(`(.style) backgroundSize value '${i}' is not valid. Aborted`), !1) : !0; } class Ii extends g { constructor(e) { super("overflow", e, !0), this.isValidValue = Ri, this._clippingPlanes = null, this._renderStrategy = this._emptyRender; } /** * Update of overflow is a bit different, as parent may trigger changes on it * @override */ update(e, t) { this._inline !== void 0 && this._inline !== "unset" ? this._input = this._inline : this._computed !== void 0 && (this._input = this._computed), this._allowsInherit || (this._inheritedInput = this.getInheritedInput(e)), this.computeOutputValue(e); for (const s of e._children._uis) s._overflow._needsUpdate = !0; this.output(t); } output(e) { e.clippingPlanes = this._clippingPlanes; } computeOutputValue(e) { super.computeOutputValue(e), this._value === "hidden" ? this._renderStrategy = this._propagateRender : (this._renderStrategy = this._emptyRender, this._clippingPlanes = null); const t = e._parent._value; if (t !== null) { const s = t._overflow; if ((s._value === "hidden" || s._clippingPlanes !== null) && !this._clippingPlanes) { this._clippingPlanes = [ // top new u.Plane(new u.Vector3(0, -1, 0), 1), // right new u.Plane(new u.Vector3(-1, 0, 0), 1), // bottom new u.Plane(new u.Vector3(0, 1, 0), 1), // left new u.Plane(new u.Vector3(1, 0, 0), 1) ]; for (let r = 0; r < this._clippingPlanes.length; r++) this._clippingPlanes[r].parent = t; s._clippingPlanes !== null && this._clippingPlanes.push(...s._clippingPlanes), this._renderStrategy = this._hiddenRender, this._needsRender = !0; } else (s._value === "visible" || s._clippingPlanes === null) && this._clippingPlanes !== null && (this._clippingPlanes = null, this._renderStrategy = this._emptyRender, this._needsRender = !0); } } render(e) { this._renderStrategy(e); } /* eslint-disable no-unused-vars */ _emptyRender(e) { } _hiddenRender(e) { const t = e._parent._value, s = t._bounds._offsetHeight, r = t._bounds._offsetWidth, n = t._padding._value, o = t._borderWidth._value; for (let a = 0; a < 4 && a < this._clippingPlanes.length; a++) { const l = this._clippingPlanes[a]; switch (a % 4) { // top case 0: l.constant = s / 2 - (n.x + o.x); break; // right case 1: l.constant = r / 2 - (n.y + o.y); break; // bottom case 2: l.constant = s / 2 - (n.z + o.z); break; // left case 3: l.constant = r / 2 - (n.w + o.w); break; } l.applyMatrix4(t.matrixWorld); } for (let a = 0; a < e._children._uis.length; a++) { const l = e._children._uis[a]; l._overflow._needsRender = !0; } } _propagateRender(e) { for (let t = 0; t < e._children._uis.length; t++) { const s = e._children._uis[t]; s._overflow._needsRender = !0; } } } const Ci = ["visible", "hidden"]; function Ri(i) { return Ci.indexOf(i) === -1 ? (console.warn(`(.style) overflow value '${i}' is not valid. Aborted`), !1) : !0; } const B = "rem", Ee = "em", $ = "%", Bi = [B, Ee, $], De = function(i) { return Bi.indexOf(i) === -1 ? B : i; }; class Ui extends Y { /** * * @param {Vector4} defaultValue */ constructor(e) { super("borderRadius", e), this._valueUV = this._value.clone(), this._input = new u.Vector4(0, 0, 0, 0), this._mediation = !0, this._cornerTL = new u.Vector2(0, 1), this._cornerTR = new u.Vector2(1, 1), this._cornerBR = new u.Vector2(1, 0), this._cornerBL = new u.Vector2(0, 0); const t = new E(this._valueUV, ["x", "y"]), s = new E(this._valueUV, ["z", "w"]), r = new E(this._valueUV, ["x", "w"]), n = new E(this._valueUV, ["y", "z"]); t.complementaryMediation = s, s.complementaryMediation = t, r.complementaryMediation = n, n.complementaryMediation = r, this._sideMediators = [t, s, r, n], this._units = B; } /** * * @param {string} units */ set units(e) { this._units = De(e), this._needsProcess = !0; } /** * * @returns {string} */ get units() { return this._units; } /** * * @param {boolean} v */ set mediation(e) { e !== this._mediation && (this._mediation = e, this._needsUpdate = !0); } /** * * @returns {boolean} */ get mediation() { return this._mediation; } /** * * @param {Object.<string,any>} out */ output(e) { e.cornerTL = this._cornerTL, e.cornerTR = this._cornerTR, e.cornerBR = this._cornerBR, e.cornerBL = this._cornerBL; } /** * * @override */ /* eslint-disable no-unused-vars */ computeOutputValue(e) { this._vector4ValueSetter(this._value, this._input), this._needsProcess = !0; } /* eslint-disable no-unused-vars */ /** * * @override */ process(e) { this._needsRender = !0; } /** * * @override */ render(e) { this._valueUV.copy(this._value); const t = e._bounds._offsetWidth, s = e._bounds._offsetHeight; if (this._units === $ && this._valueUV.divideScalar(100), this._units === B && this._valueUV.divideScalar(Math.min(t, s)), this._mediation) do this._sideMediators.forEach((o) => o.computeValue()), this._sideMediators.sort((o, a) => o.value < a.value ? 1 : -1), this._sideMediators[0].value > 1 && this._sideMediators[0].mediate(); while (this._sideMediators[0].value > 1); let r = t > s ? s / t : 1, n = t < s ? t / s : 1; this._units === $ && (r = n = 1), this._cornerTL.x = this._valueUV.x * r, this._cornerTL.y = 1 - this._valueUV.x * n, this._cornerTR.x = 1 - this._valueUV.y * r, this._cornerTR.y = 1 - this._valueUV.y * n, this._cornerBR.x = 1 - this._valueUV.z * r, this._cornerBR.y = this._valueUV.z * n, this._cornerBL.x = this._valueUV.w * r, this._cornerBL.y = this._valueUV.w * n; } /** * */ dispose() { for (const e of this._sideMediators) e.dispose(); this._sideMediators = null, this._cornerTL = null, this._cornerTR = null, this._cornerBR = null, this._cornerBL = null, super.dispose(); } /** * * @param {Number} v */ set topLeft(e) { this._input.x !== e && (this._input.x = e, this._needsUpdate = !0); } /** * * @returns {number} */ get topLeft() { return this._input.x; } /** * * @param {Number} v */ set topRight(e) { this._input.y !== e && (this._input.y = e, this._needsUpdate = !0); } /** * * @returns {number} */ get topRight() { return this._input.y; } /** * * @param {Number} v */ set bottomRight(e) { this._input.z !== e && (this._input.z = e, this._needsUpdate = !0); } /** * * @returns {number} */ get bottomRight() { return this._input.z; } /** * * @param {Number} v */ set bottomLeft(e) { this._input.w !== e && (this._input.w = e, this._needsUpdate = !0); } /** * * @returns {number} */ get bottomLeft() { return this._input.w; } /** * @override * @param {Number} v */ set top(e) { this._input.x === e && this._input.y === e || (this._input.x = this._input.y = e, this._needsUpdate = !0); } /** * @override * @returns {number} */ get top() { return (this._input.x + this._input.y) / 2; } /** * @override * @param {Number} v */ set right(e) { this._input.y === e && this._input.z === e || (this._input.y = this._input.z = e, this._needsUpdate = !0); } /** * @override * @returns {number} */ get right() { return (this._input.y + this._input.z) / 2; } /** * @override * @param {Number} v */ set bottom(e) { this._input.z === e && this._input.w === e || (this._input.z = this._input.w = e, this._needsUpdate = !0); } /** * @override * @returns {number} */ get bottom() { return (this._input.z + this._input.w) / 2; } /** * @override * @param {Number} v */ set left(e) { this._input.w === e && this._input.x === e || (this._input.w = this._input.x = e, this._needsUpdate = !0); } /** * @override * @returns {number} */ get left() { return (this._input.w + this._input.x) / 2; } } class E { /** * * @param {Vector4} borderRadiuses * @param {Array.<string>} sideProperties */ constructor(e, t) { this._borderRadiuses = e, this._sideProperties = t, this._complementaryMediation = null, this._value = 0; } /** * The sum of the border radius of that side * @returns {number} */ get value() { return this._value; } /** * A complementary side mediation ie: For top, complementary is bottom * @param {BorderRadiusMediator} brm */ set complementaryMediation(e) { this._complementaryMediation = e; } /** * Adds all side property to compute the value of that side */ computeValue() { let e = 0; for (const t of this._sideProperties) e += this._borderRadiuses[t]; this._value = e; } /** * * @param {boolean} [mediateOpposite=true] */ mediate(e = !0) { if (!(this._value < 1)) { for (const t of this._sideProperties) this._borderRadiuses[t] /= this._value; e && this._complementaryMediation.mediate(!1); } } /** * */ dispose() { this._complementaryMediation = null, this._borderRadiuses = null; } } class Ai extends Y { /** * * @param defaultValue */ constructor(e) { super("borderWidth", e, !1), this._valueUV = this._value.clone(), this.output = this._outputValue, this._units = B; } /** * * @param {string} units */ set units(e) { this._units = De(e), this._needsUpdate = !0; } /** * * @returns {string} */ get units() { return this._units; } /* eslint-disable no-unused-vars */ /** * * @override */ computeOutputValue(e) { this._vector4ValueSetter(this._value, this._input), this._needsProcess = !0, e._bounds._needsUpdate = !0, e._layouter._needsUpdate = !0; } _outputValue(e) { e[this._id] = this._valueUV; } /** * * @override */ process(e) { this._needsRender = !0, e._borderRadius._needsRender = !0; } /** * @override */ render(e) { this._valueUV.copy(this._value); const t = e._bounds._offsetWidth, s = e._bounds._offsetHeight; if (this._units === $ && (console.log("Percent"), console.log(this._valueUV)), this._units === B) t !== 0 && (this._valueUV.w /= t, this._valueUV.y /= t), s !== 0 && (this._valueUV.x /= s, this._valueUV.z /= s); else if (this._units === Ee) { if (t !== 0) { const r = t > s ? s / t : 1; this._valueUV.y *= r, this._valueUV.w *= r; } if (s !== 0) { const r = t < s ? t / s : 1; this._valueUV.x *= r, this._valueUV.z *= r; } } } } class Ti extends p { /** * * @param {string} propertyId * @param {any} [value=null] */ constructor(e, t = !0) { super("visible", t, !0), this._needsUpdate = !1; } /* eslint-disable no-unused-vars */ update(e, t) { e.visible = this._value, e._parent._value && (e._parent._value._children._needsUpdate = !0); } set value(e) { this.isValid(e) && this._value !== e && (this._value = e, this._needsUpdate = !0); } /** * * @return {boolean} */ get value() { return this._value; } } class He extends A { constructor(e) { super("backgroundColor", e, !1), this._input = "transparent", this._allowsInherit = !1; } /* eslint-disable no-unused-vars */ /** * * @param {MeshUIBaseElement} element */ computeOutputValue(e) { e._backgroundMesh.visible = !(this._input === "none" || this._input === "transparent"), this._input === "inherit" ? this._value.set(this.getInheritedInput(e)) : this._input === "transparent" || this._input === "none" || this._value.set(this._input); } } class P extends p { /** * * @param {string} propertyId */ constructor(e = "untitled") { super(e, void 0, !1); } /* eslint-disable no-unused-vars */ /** * * @param element * @param {Object.<string,any>} out */ update(e, t) { } /* eslint-disable no-unused-vars */ /** * Output this property in a dictionnary * @param {Object.<string,any>} out */ output(e) { } } class Mi extends p { constructor() { super("inlineJustificator", null, !1), this._value = null; } /* eslint-disable no-unused-vars */ update(e, t) { } /** * * @override */ process(e) { const t = e._bounds._innerHeight, s = e._layouter._value, r = Math.abs(s.height); let n = (() => { switch (e._alignItems._value) { case "inherit": case "start": return t / 2; case "end": return r - t / 2; case "stretch": // @TODO : Stretch should trigger an error in own property case "center": return r / 2; } })(); const o = e._padding._value, a = e._borderWidth._value; n += (-o.x + o.z) / 2 + (-a.x + a.z) / 2, s.forEach((l) => { l.y += n, l.forEach((d) => { d.offsetY += n; }); }); } } const Fi = ["start", "center", "end", "stretch"], Oi = function(i) { return Fi.indexOf(i) === -1 ? (console.warn(`(.style) alignItems value '${i}' is not valid. Aborted`), !1) : !0; }; class he extends g { constructor() { super("alignItems", "inherit", !0), this.isValidValue = Oi; } } class le extends g { constructor() { super("textAlign", "inherit", !0), this.isValidValue = zi; } } const Li = ["left", "right", "center", "justify", "justify-left", "justify-right", "justify-center"], zi = function(i) { return Li.indexOf(i) === -1 ? (console.warn(`(.style) textAlign value '${i}' is not valid. Aborted`), !1) : !0; }; class ce extends g { constructor() { super("flexDirection", "inherit", !0), this.isValid = Ei; } } const Wi = ["row", "row-reverse", "column", "column-reverse"]; function Ei(i) { return Wi.indexOf(i) === -1 ? (console.warn(`(.style) flexDirection value '${i}' is not valid. Aborted`), !1) : !0; } class de extends g { constructor() { super("justifyContent", "inherit", !0), this.isValidValue = Hi; } } const Di = ["start", "center", "end", "space-between", "space-around", "space-evenly"]; function Hi(i) { return Di.indexOf(i) === -1 ? (console.warn(`(.style) justifyContent value '${i}' is not valid. Aborted`), !1) : !0; } class Gi extends g { constructor() { super("order", 0, !0), this._value = 0, this._input = 0, this._allowsInherit = !1; } /* eslint-disable no-unused-vars */ computeOutputValue(e) { this._value = this._inheritedInput, e._parent._value && (e._parent._value._children._needsProcess = !0); } } class Ge extends g { constructor() { super("position", "static", !0), this._allowsInherit = !1, this._value = "static", this._needsUpdate = !1, this.computeOutputValue = this._computeFromInherited, this.isValidValue = Ni; } _computeFromInherited(e) { super._computeFromInherited(e), e._parent._value && (e._parent._value._children._needsProcess = !0); } } const $i = ["static", "absolute"]; function Ni(i) { return $i.indexOf(i) === -1 ? (console.warn(`(.style) position value '${i}' is not valid. Aborted`), !1) : !0; } class $e extends g { /** * * @param {string} propertyId * @param {number} defaultValue */ constructor(e, t = null) { super(e, t, !0), this._input = "auto", this._auto = !0, this._relative = !1, this._updateRequired = !0; } /** * * @param {any} value */ 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 (this._inline !== void 0 && this._inline !== "unset" ? this._input = this._inline : this._computed !== void 0 ? (this._computed === this._input && (e = !1), this._input = this._computed) : e = this._input === "inherit", e) { if (this._auto = !this._input || this._input === "auto", this._auto) this._relative = !1; else if ((typeof this._input == "string" || this._input instanceof String) && this._input.endsWith("%")) { this._relative = !0, this._value = 0; const t = parseFloat(this._input.replace("%", "").trim()); isNaN(t) || (this._value = t / 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 s of e._children._uis) s[`_${this._id}`]._needsUpdate = !0; this.output(t), e._parent._value && (e._parent._value._layouter._needsProcess = !0); } } /* eslint-disable no-unused-vars */ computeOutputValue(e) { e._bounds._needsUpdate = !0, e._renderer._needsRender = !0; } getInheritedInput(e) { if (this._input !== "inherit" && !this._auto) return this._input; const t = e._parent._value; return t ? t[`_${this._id}`].getInheritedInput(t) : this.getDefaultValue(); } getDefaultValue() { return 0; } /** * * @return {number} */ get value() { return this._value; } } class Xi extends $e { constructor() { super("width"); } } class ji extends $e { constructor() { super("height"); } computeOutputValue(e) { super.computeOutputValue(e); } } class Ne extends P { constructor() { super("textContent"), this._needsUpdate = !1; } /* eslint-disable no-unused-vars */ set value(e) { } /* eslint-disable no-unused-vars */ process(e) { let t = ""; for (let s = 0; s < e.children.length; s++) { const r = e.children[s]; r.isUI && (t += r.textContent); } this._value = t; } } class Xe extends g { constructor(e) { super("fontStyle", e, !0), this.isValidValue = Ki; } } const Yi = ["normal", "italic"]; function Ki(i) { return Yi.indexOf(i) === -1 ? (console.warn(`(.style) fontStyle value '${i}' is not valid. Aborted`), !1) : !0; } class je extends g { constructor() { super("fontWeight", "inherit", !0), this.isValid = Ji; } } const qi = ["100", "200", "300", "400", "500", "600", "700", "800", "900", "light", "normal", "bold", "bolder"]; function Ji(i) { return qi.indexOf(i.toString()) === -