@onerjs/gui 8.31.6 → 8.31.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -112,10 +112,10 @@ export class ValueAndUnit {
112
112
  let width = 0;
113
113
  let height = 0;
114
114
  if (host.idealWidth) {
115
- width = +((this._value * host.getSize().width) / host.idealWidth).toFixed(this.valueDecimals);
115
+ width = +((this._value * host.getSize().width) / host.idealWidth);
116
116
  }
117
117
  if (host.idealHeight) {
118
- height = +((this._value * host.getSize().height) / host.idealHeight).toFixed(this.valueDecimals);
118
+ height = +((this._value * host.getSize().height) / host.idealHeight);
119
119
  }
120
120
  if (host.useSmallestIdeal && host.idealWidth && host.idealHeight) {
121
121
  return window.innerWidth < window.innerHeight ? width : height;
@@ -1 +1 @@
1
- {"version":3,"file":"valueAndUnit.js","sourceRoot":"","sources":["../../../../dev/gui/src/2D/valueAndUnit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,wCAA6B;AAGlD;;GAEG;AACH,MAAM,OAAO,YAAY;IAiBrB;;;;;OAKG;IACH,YACI,KAAa;IACb,gCAAgC;IAChC,IAAI,GAAG,YAAY,CAAC,cAAc;IAClC,gEAAgE;IACzD,uBAAuB,IAAI;QAA3B,yBAAoB,GAApB,oBAAoB,CAAO;QA3B9B,WAAM,GAAG,CAAC,CAAC;QACX,UAAK,GAAG,YAAY,CAAC,cAAc,CAAC;QAEpC,mBAAc,GAAW,CAAC,CAAC;QAEnC;;;WAGG;QACI,0BAAqB,GAAG,KAAK,CAAC;QAErC;;WAEG;QACI,wBAAmB,GAAG,IAAI,UAAU,EAAQ,CAAC;QAehD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED,6DAA6D;IAC7D,IAAW,YAAY;QACnB,OAAO,IAAI,CAAC,KAAK,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icTexture } from \"./advancedDynamicTexture\";\r\n\r\n/**\r\n * Class used to specific a value and its associated unit\r\n */\r\nexport class ValueAndUnit {\r\n private _value = 1;\r\n private _unit = ValueAndUnit.UNITMODE_PIXEL;\r\n private _originalUnit: number;\r\n private _valueDecimals: number = 3;\r\n\r\n /**\r\n * Gets or sets a value indicating that this value will not scale accordingly with adaptive scaling property\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#adaptive-scaling\r\n */\r\n public ignoreAdaptiveScaling = false;\r\n\r\n /**\r\n * Observable event triggered each time the value or unit changes\r\n */\r\n public onChangedObservable = new Observable<void>();\r\n\r\n /**\r\n * Creates a new ValueAndUnit\r\n * @param value defines the value to store\r\n * @param unit defines the unit to store - defaults to ValueAndUnit.UNITMODE_PIXEL\r\n * @param negativeValueAllowed defines a boolean indicating if the value can be negative\r\n */\r\n public constructor(\r\n value: number,\r\n /** defines the unit to store */\r\n unit = ValueAndUnit.UNITMODE_PIXEL,\r\n /** defines a boolean indicating if the value can be negative */\r\n public negativeValueAllowed = true\r\n ) {\r\n this._value = value;\r\n this._unit = unit;\r\n this._originalUnit = unit;\r\n }\r\n\r\n /** Gets a boolean indicating if the value is a percentage */\r\n public get isPercentage(): boolean {\r\n return this._unit === ValueAndUnit.UNITMODE_PERCENTAGE;\r\n }\r\n\r\n /** Gets a boolean indicating if the value is store as pixel */\r\n public get isPixel(): boolean {\r\n return this._unit === ValueAndUnit.UNITMODE_PIXEL;\r\n }\r\n\r\n /** Gets the decimals when process the value **/\r\n public get valueDecimals(): number {\r\n return this._valueDecimals;\r\n }\r\n\r\n public set valueDecimals(valueDecimals: number) {\r\n this._valueDecimals = valueDecimals;\r\n }\r\n\r\n /**\r\n * Gets value (without units)\r\n * @deprecated use value property instead\r\n */\r\n public get internalValue(): number {\r\n return this._value;\r\n }\r\n\r\n /** Gets value (without units) */\r\n public get value(): number {\r\n return this._value;\r\n }\r\n\r\n /** Sets value (without units) */\r\n public set value(value: number) {\r\n if (value !== this._value) {\r\n this._value = value;\r\n this.onChangedObservable.notifyObservers();\r\n }\r\n }\r\n\r\n /** Gets units (without value) */\r\n public get unit(): number {\r\n return this._unit;\r\n }\r\n\r\n /** Sets units (without value) */\r\n public set unit(value: number) {\r\n if (value !== this._unit) {\r\n this._unit = value;\r\n this.onChangedObservable.notifyObservers();\r\n }\r\n }\r\n\r\n /**\r\n * Gets value as pixel\r\n * @param host defines the root host\r\n * @param refValue defines the reference value for percentages\r\n * @returns the value as pixel\r\n */\r\n public getValueInPixel(host: AdvancedDynamicTexture, refValue: number): number {\r\n if (this.isPixel) {\r\n return this.getValue(host);\r\n }\r\n\r\n return this.getValue(host) * refValue;\r\n }\r\n\r\n /**\r\n * Update the current value and unit.\r\n * @param value defines the value to store\r\n * @param unit defines the unit to store\r\n * @returns the current ValueAndUnit\r\n */\r\n public updateInPlace(value: number, unit = ValueAndUnit.UNITMODE_PIXEL): ValueAndUnit {\r\n if (this.value !== value || this.unit !== unit) {\r\n // set member variables to notify only once\r\n this._value = value;\r\n this._unit = unit;\r\n this.onChangedObservable.notifyObservers();\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the value accordingly to its unit\r\n * @param host defines the root host\r\n * @returns the value\r\n */\r\n public getValue(host: AdvancedDynamicTexture): number {\r\n if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {\r\n let width: number = 0;\r\n let height: number = 0;\r\n\r\n if (host.idealWidth) {\r\n width = +((this._value * host.getSize().width) / host.idealWidth).toFixed(this.valueDecimals);\r\n }\r\n\r\n if (host.idealHeight) {\r\n height = +((this._value * host.getSize().height) / host.idealHeight).toFixed(this.valueDecimals);\r\n }\r\n\r\n if (host.useSmallestIdeal && host.idealWidth && host.idealHeight) {\r\n return window.innerWidth < window.innerHeight ? width : height;\r\n }\r\n\r\n if (host.idealWidth) {\r\n // horizontal\r\n return width;\r\n }\r\n\r\n if (host.idealHeight) {\r\n // vertical\r\n return height;\r\n }\r\n }\r\n return this._value;\r\n }\r\n\r\n /**\r\n * Gets a string representation of the value\r\n * @param host defines the root host\r\n * @param decimals defines an optional number of decimals to display\r\n * @returns a string\r\n */\r\n public toString(host: AdvancedDynamicTexture, decimals?: number): string {\r\n switch (this._unit) {\r\n case ValueAndUnit.UNITMODE_PERCENTAGE: {\r\n const percentage = this.getValue(host) * 100;\r\n return (decimals ? percentage.toFixed(decimals) : percentage) + \"%\";\r\n }\r\n case ValueAndUnit.UNITMODE_PIXEL: {\r\n const pixels = this.getValue(host);\r\n return (decimals ? pixels.toFixed(decimals) : pixels) + \"px\";\r\n }\r\n }\r\n\r\n return this._unit.toString();\r\n }\r\n\r\n /**\r\n * Store a value parsed from a string\r\n * @param source defines the source string\r\n * @returns true if the value was successfully parsed and updated\r\n */\r\n public fromString(source: string | number): boolean {\r\n const match = ValueAndUnit._Regex.exec(source.toString());\r\n\r\n if (!match || match.length === 0) {\r\n return false;\r\n }\r\n\r\n let sourceValue = parseFloat(match[1]);\r\n let sourceUnit = this._originalUnit;\r\n\r\n if (!this.negativeValueAllowed) {\r\n if (sourceValue < 0) {\r\n sourceValue = 0;\r\n }\r\n }\r\n\r\n if (match.length === 4) {\r\n switch (match[3]) {\r\n case \"px\":\r\n sourceUnit = ValueAndUnit.UNITMODE_PIXEL;\r\n break;\r\n case \"%\":\r\n sourceUnit = ValueAndUnit.UNITMODE_PERCENTAGE;\r\n sourceValue /= 100.0;\r\n break;\r\n }\r\n }\r\n\r\n if (sourceValue === this._value && sourceUnit === this._unit) {\r\n return false;\r\n }\r\n\r\n this._value = sourceValue;\r\n this._unit = sourceUnit;\r\n this.onChangedObservable.notifyObservers();\r\n\r\n return true;\r\n }\r\n\r\n // Static\r\n private static _Regex = /(^-?\\d*(\\.\\d+)?)(%|px)?/;\r\n private static _UNITMODE_PERCENTAGE = 0;\r\n private static _UNITMODE_PIXEL = 1;\r\n\r\n /** UNITMODE_PERCENTAGE */\r\n public static get UNITMODE_PERCENTAGE(): number {\r\n return ValueAndUnit._UNITMODE_PERCENTAGE;\r\n }\r\n\r\n /** UNITMODE_PIXEL */\r\n public static get UNITMODE_PIXEL(): number {\r\n return ValueAndUnit._UNITMODE_PIXEL;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"valueAndUnit.js","sourceRoot":"","sources":["../../../../dev/gui/src/2D/valueAndUnit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,wCAA6B;AAGlD;;GAEG;AACH,MAAM,OAAO,YAAY;IAiBrB;;;;;OAKG;IACH,YACI,KAAa;IACb,gCAAgC;IAChC,IAAI,GAAG,YAAY,CAAC,cAAc;IAClC,gEAAgE;IACzD,uBAAuB,IAAI;QAA3B,yBAAoB,GAApB,oBAAoB,CAAO;QA3B9B,WAAM,GAAG,CAAC,CAAC;QACX,UAAK,GAAG,YAAY,CAAC,cAAc,CAAC;QAEpC,mBAAc,GAAW,CAAC,CAAC;QAEnC;;;WAGG;QACI,0BAAqB,GAAG,KAAK,CAAC;QAErC;;WAEG;QACI,wBAAmB,GAAG,IAAI,UAAU,EAAQ,CAAC;QAehD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED,6DAA6D;IAC7D,IAAW,YAAY;QACnB,OAAO,IAAI,CAAC,KAAK,KAAK,YAAY,CAAC,mBAAmB,CAAC;IAC3D,CAAC;IAED,+DAA+D;IAC/D,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,KAAK,KAAK,YAAY,CAAC,cAAc,CAAC;IACtD,CAAC;IAED,gDAAgD;IAChD,IAAW,aAAa;QACpB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAED,IAAW,aAAa,CAAC,aAAqB;QAC1C,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,IAAW,aAAa;QAC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C,MAAM;gBACV,KAAK,GAAG;oBACJ,UAAU,GAAG,YAAY,CAAC,mBAAmB,CAAC;oBAC9C,WAAW,IAAI,KAAK,CAAC;oBACrB,MAAM;YACd,CAAC;QACL,CAAC;QAED,IAAI,WAAW,KAAK,IAAI,CAAC,MAAM,IAAI,UAAU,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;YAC3D,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC;QACxB,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE,CAAC;QAE3C,OAAO,IAAI,CAAC;IAChB,CAAC;IAOD,0BAA0B;IACnB,MAAM,KAAK,mBAAmB;QACjC,OAAO,YAAY,CAAC,oBAAoB,CAAC;IAC7C,CAAC;IAED,qBAAqB;IACd,MAAM,KAAK,cAAc;QAC5B,OAAO,YAAY,CAAC,eAAe,CAAC;IACxC,CAAC;;AAbD,SAAS;AACM,mBAAM,GAAG,yBAAyB,AAA5B,CAA6B;AACnC,iCAAoB,GAAG,CAAC,AAAJ,CAAK;AACzB,4BAAe,GAAG,CAAC,AAAJ,CAAK","sourcesContent":["import { Observable } from \"core/Misc/observable\";\r\nimport type { AdvancedDynamicTexture } from \"./advancedDynamicTexture\";\r\n\r\n/**\r\n * Class used to specific a value and its associated unit\r\n */\r\nexport class ValueAndUnit {\r\n private _value = 1;\r\n private _unit = ValueAndUnit.UNITMODE_PIXEL;\r\n private _originalUnit: number;\r\n private _valueDecimals: number = 3;\r\n\r\n /**\r\n * Gets or sets a value indicating that this value will not scale accordingly with adaptive scaling property\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#adaptive-scaling\r\n */\r\n public ignoreAdaptiveScaling = false;\r\n\r\n /**\r\n * Observable event triggered each time the value or unit changes\r\n */\r\n public onChangedObservable = new Observable<void>();\r\n\r\n /**\r\n * Creates a new ValueAndUnit\r\n * @param value defines the value to store\r\n * @param unit defines the unit to store - defaults to ValueAndUnit.UNITMODE_PIXEL\r\n * @param negativeValueAllowed defines a boolean indicating if the value can be negative\r\n */\r\n public constructor(\r\n value: number,\r\n /** defines the unit to store */\r\n unit = ValueAndUnit.UNITMODE_PIXEL,\r\n /** defines a boolean indicating if the value can be negative */\r\n public negativeValueAllowed = true\r\n ) {\r\n this._value = value;\r\n this._unit = unit;\r\n this._originalUnit = unit;\r\n }\r\n\r\n /** Gets a boolean indicating if the value is a percentage */\r\n public get isPercentage(): boolean {\r\n return this._unit === ValueAndUnit.UNITMODE_PERCENTAGE;\r\n }\r\n\r\n /** Gets a boolean indicating if the value is store as pixel */\r\n public get isPixel(): boolean {\r\n return this._unit === ValueAndUnit.UNITMODE_PIXEL;\r\n }\r\n\r\n /** Gets the decimals when process the value **/\r\n public get valueDecimals(): number {\r\n return this._valueDecimals;\r\n }\r\n\r\n public set valueDecimals(valueDecimals: number) {\r\n this._valueDecimals = valueDecimals;\r\n }\r\n\r\n /**\r\n * Gets value (without units)\r\n * @deprecated use value property instead\r\n */\r\n public get internalValue(): number {\r\n return this._value;\r\n }\r\n\r\n /** Gets value (without units) */\r\n public get value(): number {\r\n return this._value;\r\n }\r\n\r\n /** Sets value (without units) */\r\n public set value(value: number) {\r\n if (value !== this._value) {\r\n this._value = value;\r\n this.onChangedObservable.notifyObservers();\r\n }\r\n }\r\n\r\n /** Gets units (without value) */\r\n public get unit(): number {\r\n return this._unit;\r\n }\r\n\r\n /** Sets units (without value) */\r\n public set unit(value: number) {\r\n if (value !== this._unit) {\r\n this._unit = value;\r\n this.onChangedObservable.notifyObservers();\r\n }\r\n }\r\n\r\n /**\r\n * Gets value as pixel\r\n * @param host defines the root host\r\n * @param refValue defines the reference value for percentages\r\n * @returns the value as pixel\r\n */\r\n public getValueInPixel(host: AdvancedDynamicTexture, refValue: number): number {\r\n if (this.isPixel) {\r\n return this.getValue(host);\r\n }\r\n\r\n return this.getValue(host) * refValue;\r\n }\r\n\r\n /**\r\n * Update the current value and unit.\r\n * @param value defines the value to store\r\n * @param unit defines the unit to store\r\n * @returns the current ValueAndUnit\r\n */\r\n public updateInPlace(value: number, unit = ValueAndUnit.UNITMODE_PIXEL): ValueAndUnit {\r\n if (this.value !== value || this.unit !== unit) {\r\n // set member variables to notify only once\r\n this._value = value;\r\n this._unit = unit;\r\n this.onChangedObservable.notifyObservers();\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the value accordingly to its unit\r\n * @param host defines the root host\r\n * @returns the value\r\n */\r\n public getValue(host: AdvancedDynamicTexture): number {\r\n if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {\r\n let width: number = 0;\r\n let height: number = 0;\r\n\r\n if (host.idealWidth) {\r\n width = +((this._value * host.getSize().width) / host.idealWidth);\r\n }\r\n\r\n if (host.idealHeight) {\r\n height = +((this._value * host.getSize().height) / host.idealHeight);\r\n }\r\n\r\n if (host.useSmallestIdeal && host.idealWidth && host.idealHeight) {\r\n return window.innerWidth < window.innerHeight ? width : height;\r\n }\r\n\r\n if (host.idealWidth) {\r\n // horizontal\r\n return width;\r\n }\r\n\r\n if (host.idealHeight) {\r\n // vertical\r\n return height;\r\n }\r\n }\r\n return this._value;\r\n }\r\n\r\n /**\r\n * Gets a string representation of the value\r\n * @param host defines the root host\r\n * @param decimals defines an optional number of decimals to display\r\n * @returns a string\r\n */\r\n public toString(host: AdvancedDynamicTexture, decimals?: number): string {\r\n switch (this._unit) {\r\n case ValueAndUnit.UNITMODE_PERCENTAGE: {\r\n const percentage = this.getValue(host) * 100;\r\n return (decimals ? percentage.toFixed(decimals) : percentage) + \"%\";\r\n }\r\n case ValueAndUnit.UNITMODE_PIXEL: {\r\n const pixels = this.getValue(host);\r\n return (decimals ? pixels.toFixed(decimals) : pixels) + \"px\";\r\n }\r\n }\r\n\r\n return this._unit.toString();\r\n }\r\n\r\n /**\r\n * Store a value parsed from a string\r\n * @param source defines the source string\r\n * @returns true if the value was successfully parsed and updated\r\n */\r\n public fromString(source: string | number): boolean {\r\n const match = ValueAndUnit._Regex.exec(source.toString());\r\n\r\n if (!match || match.length === 0) {\r\n return false;\r\n }\r\n\r\n let sourceValue = parseFloat(match[1]);\r\n let sourceUnit = this._originalUnit;\r\n\r\n if (!this.negativeValueAllowed) {\r\n if (sourceValue < 0) {\r\n sourceValue = 0;\r\n }\r\n }\r\n\r\n if (match.length === 4) {\r\n switch (match[3]) {\r\n case \"px\":\r\n sourceUnit = ValueAndUnit.UNITMODE_PIXEL;\r\n break;\r\n case \"%\":\r\n sourceUnit = ValueAndUnit.UNITMODE_PERCENTAGE;\r\n sourceValue /= 100.0;\r\n break;\r\n }\r\n }\r\n\r\n if (sourceValue === this._value && sourceUnit === this._unit) {\r\n return false;\r\n }\r\n\r\n this._value = sourceValue;\r\n this._unit = sourceUnit;\r\n this.onChangedObservable.notifyObservers();\r\n\r\n return true;\r\n }\r\n\r\n // Static\r\n private static _Regex = /(^-?\\d*(\\.\\d+)?)(%|px)?/;\r\n private static _UNITMODE_PERCENTAGE = 0;\r\n private static _UNITMODE_PIXEL = 1;\r\n\r\n /** UNITMODE_PERCENTAGE */\r\n public static get UNITMODE_PERCENTAGE(): number {\r\n return ValueAndUnit._UNITMODE_PERCENTAGE;\r\n }\r\n\r\n /** UNITMODE_PIXEL */\r\n public static get UNITMODE_PIXEL(): number {\r\n return ValueAndUnit._UNITMODE_PIXEL;\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onerjs/gui",
3
- "version": "8.31.6",
3
+ "version": "8.31.7",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "postcompile": "build-tools -c add-js-to-es6"
19
19
  },
20
20
  "devDependencies": {
21
- "@onerjs/core": "^8.31.6",
21
+ "@onerjs/core": "^8.31.7",
22
22
  "@dev/build-tools": "^1.0.0",
23
23
  "@lts/gui": "1.0.0"
24
24
  },