laymur 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1815,12 +1815,7 @@ function resolvePriority(priority) {
1815
1815
  return priority ?? UIPriority.P0;
1816
1816
  }
1817
1817
 
1818
- /**
1819
- * Database of predefined color names mapped to their hexadecimal RGB values.
1820
- * Used for creating UIColor instances from named colors.
1821
- */
1822
- const COLOR_NAMES = {
1823
- // Basic colors
1818
+ const COLORS = {
1824
1819
  black: 0x000000,
1825
1820
  white: 0xffffff,
1826
1821
  red: 0xff0000,
@@ -1829,7 +1824,6 @@ const COLOR_NAMES = {
1829
1824
  yellow: 0xffff00,
1830
1825
  cyan: 0x00ffff,
1831
1826
  magenta: 0xff00ff,
1832
- // Extended colors
1833
1827
  gray: 0x808080,
1834
1828
  grey: 0x808080,
1835
1829
  silver: 0xc0c0c0,
@@ -1841,7 +1835,6 @@ const COLOR_NAMES = {
1841
1835
  navy: 0x000080,
1842
1836
  fuchsia: 0xff00ff,
1843
1837
  purple: 0x800080,
1844
- // Additional common colors
1845
1838
  orange: 0xffa500,
1846
1839
  pink: 0xffc0cb,
1847
1840
  brown: 0xa52a2a,
@@ -1863,44 +1856,30 @@ const COLOR_NAMES = {
1863
1856
  snow: 0xfffafa,
1864
1857
  };
1865
1858
  /**
1866
- * Events that can be emitted by UIColor instances.
1859
+ * Events emitted by UIColor.
1867
1860
  */
1868
1861
  var UIColorEvent;
1869
1862
  (function (UIColorEvent) {
1870
- /** Emitted when any color property (r, g, b, a) changes. */
1863
+ /** Emitted when color components change. */
1871
1864
  UIColorEvent["CHANGE"] = "change";
1872
1865
  })(UIColorEvent || (UIColorEvent = {}));
1873
1866
  /**
1874
- * Event-based RGBA color class with support for multiple color formats and named colors.
1875
- *
1876
- * UIColor provides a comprehensive color management system with support for RGB, HSL,
1877
- * hexadecimal formats, and named colors. It extends Eventail to emit change events
1878
- * when color properties are modified, enabling reactive color updates throughout
1879
- * the UI system.
1880
- *
1881
- * Color components are stored as normalized values (0-1) for precision and
1882
- * compatibility with graphics APIs.
1883
- *
1884
- * @see {@link UIColorEvent} - Events emitted by color instances
1885
- * @see {@link UIColorName} - Supported named color values
1867
+ * Event-based RGBA color with support for RGB, HSL, hex, and named colors.
1868
+ * Color components are stored as normalized values (0-1).
1886
1869
  */
1887
1870
  class UIColor extends i {
1888
1871
  constructor(...args) {
1889
1872
  super();
1890
- /** Internal storage for the red component (0-1). */
1891
- this.rInternal = 1;
1892
- /** Internal storage for the green component (0-1). */
1893
- this.gInternal = 1;
1894
- /** Internal storage for the blue component (0-1). */
1895
- this.bInternal = 1;
1896
- /** Internal storage for the alpha component (0-1). */
1897
- this.aInternal = 1;
1873
+ this._private_rInternal = 1;
1874
+ this._private_gInternal = 1;
1875
+ this._private_bInternal = 1;
1876
+ this._private_aInternal = 1;
1898
1877
  if (args.length >= 3 && typeof args[0] === "number") {
1899
1878
  const [r, g, b, a = 1] = args;
1900
- this.rInternal = r;
1901
- this.gInternal = g;
1902
- this.bInternal = b;
1903
- this.aInternal = a;
1879
+ this._private_rInternal = r;
1880
+ this._private_gInternal = g;
1881
+ this._private_bInternal = b;
1882
+ this._private_aInternal = a;
1904
1883
  }
1905
1884
  else if (args.length >= 1) {
1906
1885
  const [first, a = 1] = args;
@@ -1912,107 +1891,92 @@ class UIColor extends i {
1912
1891
  }
1913
1892
  }
1914
1893
  }
1915
- /**
1916
- * Gets the red component value.
1917
- * @returns The red component (0-1)
1918
- */
1894
+ /** Red component (0-1). */
1919
1895
  get r() {
1920
- return this.rInternal;
1896
+ return this._private_rInternal;
1921
1897
  }
1922
- /**
1923
- * Gets the green component value.
1924
- * @returns The green component (0-1)
1925
- */
1898
+ /** Green component (0-1). */
1926
1899
  get g() {
1927
- return this.gInternal;
1900
+ return this._private_gInternal;
1928
1901
  }
1929
- /**
1930
- * Gets the blue component value.
1931
- * @returns The blue component (0-1)
1932
- */
1902
+ /** Blue component (0-1). */
1933
1903
  get b() {
1934
- return this.bInternal;
1904
+ return this._private_bInternal;
1935
1905
  }
1936
- /**
1937
- * Gets the alpha component value.
1938
- * @returns The alpha component (0-1)
1939
- */
1906
+ /** Alpha component (0-1). */
1940
1907
  get a() {
1941
- return this.aInternal;
1908
+ return this._private_aInternal;
1942
1909
  }
1943
- /**
1944
- * Sets the red component value and emits change event.
1945
- * @param value - The red component (0-1)
1946
- */
1947
1910
  set r(value) {
1948
- this.rInternal = value;
1949
- this.emit(UIColorEvent.CHANGE, this);
1911
+ if (value !== this._private_rInternal) {
1912
+ this._private_rInternal = value;
1913
+ this.emit(UIColorEvent.CHANGE, this);
1914
+ }
1950
1915
  }
1951
- /**
1952
- * Sets the green component value and emits change event.
1953
- * @param value - The green component (0-1)
1954
- */
1955
1916
  set g(value) {
1956
- this.gInternal = value;
1957
- this.emit(UIColorEvent.CHANGE, this);
1917
+ if (value !== this._private_gInternal) {
1918
+ this._private_gInternal = value;
1919
+ this.emit(UIColorEvent.CHANGE, this);
1920
+ }
1958
1921
  }
1959
- /**
1960
- * Sets the blue component value and emits change event.
1961
- * @param value - The blue component (0-1)
1962
- */
1963
1922
  set b(value) {
1964
- this.bInternal = value;
1965
- this.emit(UIColorEvent.CHANGE, this);
1923
+ if (value !== this._private_bInternal) {
1924
+ this._private_bInternal = value;
1925
+ this.emit(UIColorEvent.CHANGE, this);
1926
+ }
1927
+ }
1928
+ set a(value) {
1929
+ if (value !== this._private_aInternal) {
1930
+ this._private_aInternal = value;
1931
+ this.emit(UIColorEvent.CHANGE, this);
1932
+ }
1966
1933
  }
1967
1934
  /**
1968
- * Sets the alpha component value and emits change event.
1969
- * @param value - The alpha component (0-1)
1935
+ * Sets all color components.
1936
+ *
1937
+ * @param r - Red (0-1)
1938
+ * @param g - Green (0-1)
1939
+ * @param b - Blue (0-1)
1940
+ * @param a - Alpha (0-1)
1941
+ * @returns This instance
1970
1942
  */
1971
- set a(value) {
1972
- this.aInternal = value;
1973
- this.emit(UIColorEvent.CHANGE, this);
1974
- }
1975
- /**
1976
- * Sets all color components at once and emits change event.
1977
- * @param r - Red component (0-1)
1978
- * @param g - Green component (0-1)
1979
- * @param b - Blue component (0-1)
1980
- * @param a - Alpha component (0-1), defaults to current alpha value
1981
- * @returns This UIColor instance for method chaining
1982
- */
1983
- set(r, g, b, a = this.aInternal) {
1984
- this.rInternal = r;
1985
- this.gInternal = g;
1986
- this.bInternal = b;
1987
- this.aInternal = a;
1988
- this.emit(UIColorEvent.CHANGE, this);
1943
+ set(r, g, b, a = this._private_aInternal) {
1944
+ if (r !== this._private_rInternal ||
1945
+ g !== this._private_gInternal ||
1946
+ b !== this._private_bInternal ||
1947
+ a !== this._private_aInternal) {
1948
+ this._private_rInternal = r;
1949
+ this._private_gInternal = g;
1950
+ this._private_bInternal = b;
1951
+ this._private_aInternal = a;
1952
+ this.emit(UIColorEvent.CHANGE, this);
1953
+ }
1989
1954
  return this;
1990
1955
  }
1991
1956
  /**
1992
- * Converts the color to a 32-bit hexadecimal RGBA value.
1993
- * @returns Hexadecimal RGBA value with alpha in the most significant byte
1957
+ * Returns 32-bit hex RGBA value (alpha in MSB).
1994
1958
  */
1995
1959
  getHexRGBA() {
1996
- return ((Math.round(this.rInternal * 255) << 24) |
1997
- (Math.round(this.gInternal * 255) << 16) |
1998
- (Math.round(this.bInternal * 255) << 8) |
1999
- Math.round(this.aInternal * 255));
1960
+ return ((Math.round(this._private_rInternal * 255) << 24) |
1961
+ (Math.round(this._private_gInternal * 255) << 16) |
1962
+ (Math.round(this._private_bInternal * 255) << 8) |
1963
+ Math.round(this._private_aInternal * 255));
2000
1964
  }
2001
1965
  /**
2002
- * Converts the color to a 24-bit hexadecimal RGB value (ignores alpha).
2003
- * @returns Hexadecimal RGB value (e.g., 0xFF0000 for red)
1966
+ * Returns 24-bit hex RGB value.
2004
1967
  */
2005
1968
  getHexRGB() {
2006
- return ((Math.round(this.rInternal * 255) << 16) |
2007
- (Math.round(this.gInternal * 255) << 8) |
2008
- Math.round(this.bInternal * 255));
1969
+ return ((Math.round(this._private_rInternal * 255) << 16) |
1970
+ (Math.round(this._private_gInternal * 255) << 8) |
1971
+ Math.round(this._private_bInternal * 255));
2009
1972
  }
2010
1973
  /**
2011
- * Converts the color to HSL (Hue, Saturation, Lightness) format.
2012
- * @returns Object containing h (0-360), s (0-1), and l (0-1) values
1974
+ * Converts to HSL format.
1975
+ *
1976
+ * @returns Object with h (0-360), s (0-1), l (0-1)
2013
1977
  */
2014
1978
  getHSL() {
2015
- const { rInternal: r, gInternal: g, bInternal: b } = this;
1979
+ const { _private_rInternal: r, _private_gInternal: g, _private_bInternal: b } = this;
2016
1980
  const max = Math.max(r, g, b);
2017
1981
  const min = Math.min(r, g, b);
2018
1982
  const d = max - min;
@@ -2034,41 +1998,61 @@ class UIColor extends i {
2034
1998
  return { h, s, l };
2035
1999
  }
2036
2000
  /**
2037
- * Sets the color from a 32-bit hexadecimal RGBA value and emits change event.
2038
- * @param hex - Hexadecimal RGBA value with alpha in the most significant byte
2039
- * @returns This UIColor instance for method chaining
2001
+ * Sets color from 32-bit hex RGBA value.
2002
+ *
2003
+ * @param hex - Hex RGBA (alpha in MSB)
2004
+ * @returns This instance
2040
2005
  */
2041
2006
  setHexRGBA(hex) {
2042
- this.rInternal = ((hex >> 16) & 0xff) / 255;
2043
- this.gInternal = ((hex >> 8) & 0xff) / 255;
2044
- this.bInternal = (hex & 0xff) / 255;
2045
- this.aInternal = ((hex >> 24) & 0xff) / 255;
2046
- this.emit(UIColorEvent.CHANGE, this);
2007
+ const r = ((hex >> 16) & 0xff) / 255;
2008
+ const g = ((hex >> 8) & 0xff) / 255;
2009
+ const b = (hex & 0xff) / 255;
2010
+ const a = ((hex >> 24) & 0xff) / 255;
2011
+ if (r !== this._private_rInternal ||
2012
+ g !== this._private_gInternal ||
2013
+ b !== this._private_bInternal ||
2014
+ a !== this._private_aInternal) {
2015
+ this._private_rInternal = r;
2016
+ this._private_gInternal = g;
2017
+ this._private_bInternal = b;
2018
+ this._private_aInternal = a;
2019
+ this.emit(UIColorEvent.CHANGE, this);
2020
+ }
2047
2021
  return this;
2048
2022
  }
2049
2023
  /**
2050
- * Sets the color from a 24-bit hexadecimal RGB value and emits change event.
2051
- * @param hex - Hexadecimal RGB value (e.g., 0xFF0000 for red)
2052
- * @param a - Alpha value (0-1), defaults to current alpha
2053
- * @returns This UIColor instance for method chaining
2024
+ * Sets color from 24-bit hex RGB value.
2025
+ *
2026
+ * @param hex - Hex RGB (e.g., 0xFF0000)
2027
+ * @param a - Alpha (0-1)
2028
+ * @returns This instance
2054
2029
  */
2055
- setHexRGB(hex, a = this.aInternal) {
2056
- this.rInternal = ((hex >> 16) & 0xff) / 255;
2057
- this.gInternal = ((hex >> 8) & 0xff) / 255;
2058
- this.bInternal = (hex & 0xff) / 255;
2059
- this.aInternal = a;
2060
- this.emit(UIColorEvent.CHANGE, this);
2030
+ setHexRGB(hex, a = this._private_aInternal) {
2031
+ const r = ((hex >> 16) & 0xff) / 255;
2032
+ const g = ((hex >> 8) & 0xff) / 255;
2033
+ const b = (hex & 0xff) / 255;
2034
+ if (r !== this._private_rInternal ||
2035
+ g !== this._private_gInternal ||
2036
+ b !== this._private_bInternal ||
2037
+ a !== this._private_aInternal) {
2038
+ this._private_rInternal = r;
2039
+ this._private_gInternal = g;
2040
+ this._private_bInternal = b;
2041
+ this._private_aInternal = a;
2042
+ this.emit(UIColorEvent.CHANGE, this);
2043
+ }
2061
2044
  return this;
2062
2045
  }
2063
2046
  /**
2064
- * Sets the color from HSL (Hue, Saturation, Lightness) values and emits change event.
2065
- * @param h - Hue value (0-360)
2066
- * @param s - Saturation value (0-1)
2067
- * @param l - Lightness value (0-1)
2068
- * @param a - Alpha value (0-1), defaults to current alpha
2069
- * @returns This UIColor instance for method chaining
2047
+ * Sets color from HSL values.
2048
+ *
2049
+ * @param h - Hue (0-360)
2050
+ * @param s - Saturation (0-1)
2051
+ * @param l - Lightness (0-1)
2052
+ * @param a - Alpha (0-1)
2053
+ * @returns This instance
2070
2054
  */
2071
- setHSL(h, s, l, a = this.aInternal) {
2055
+ setHSL(h, s, l, a = this._private_aInternal) {
2072
2056
  const c = (1 - Math.abs(2 * l - 1)) * s;
2073
2057
  const hp = h / 60;
2074
2058
  const x = c * (1 - Math.abs((hp % 2) - 1));
@@ -2087,68 +2071,68 @@ class UIColor extends i {
2087
2071
  return this.set(r + m, g + m, b + m, a);
2088
2072
  }
2089
2073
  /**
2090
- * Sets the color from a predefined color name and emits change event.
2091
- * @param colorName - Name of the color from the predefined color database
2092
- * @param a - Alpha value (0-1), defaults to current alpha
2093
- * @returns This UIColor instance for method chaining
2094
- * @throws Will throw an error if the color name is not recognized
2074
+ * Sets color from predefined name.
2075
+ *
2076
+ * @param colorName - Color name
2077
+ * @param a - Alpha (0-1)
2078
+ * @returns This instance
2079
+ * @throws Error if color name is unknown
2095
2080
  */
2096
- setName(colorName, a = this.aInternal) {
2081
+ setName(colorName, a = this._private_aInternal) {
2097
2082
  const normalizedName = colorName.toLowerCase().trim();
2098
- const hex = COLOR_NAMES[normalizedName];
2083
+ const hex = COLORS[normalizedName];
2099
2084
  if (hex === undefined) {
2100
2085
  throw new Error(`Unknown color name: "${colorName}".`);
2101
2086
  }
2102
2087
  return this.setHexRGB(hex, a);
2103
2088
  }
2104
2089
  /**
2105
- * Copies color values from another UIColor or Three.js Color instance and emits change event.
2106
- * @param color - The color to copy from (UIColor or Three.js Color)
2107
- * @returns This UIColor instance for method chaining
2090
+ * Returns CSS rgba() string.
2091
+ */
2092
+ toCSSColor() {
2093
+ const r = Math.round(this._private_rInternal * 255);
2094
+ const g = Math.round(this._private_gInternal * 255);
2095
+ const b = Math.round(this._private_bInternal * 255);
2096
+ return `rgba(${r}, ${g}, ${b}, ${this._private_aInternal})`;
2097
+ }
2098
+ /**
2099
+ * Copies values from another color.
2100
+ *
2101
+ * @param color - UIColor or Three.js Color
2102
+ * @returns This instance
2108
2103
  */
2109
2104
  copy(color) {
2110
2105
  if (color instanceof UIColor) {
2111
- if (this.rInternal !== color.rInternal &&
2112
- this.gInternal !== color.gInternal &&
2113
- this.bInternal !== color.bInternal &&
2114
- this.aInternal !== color.aInternal) {
2115
- this.rInternal = color.rInternal;
2116
- this.gInternal = color.gInternal;
2117
- this.bInternal = color.bInternal;
2118
- this.aInternal = color.aInternal;
2106
+ if (this._private_rInternal !== color._private_rInternal ||
2107
+ this._private_gInternal !== color._private_gInternal ||
2108
+ this._private_bInternal !== color._private_bInternal ||
2109
+ this._private_aInternal !== color._private_aInternal) {
2110
+ this._private_rInternal = color._private_rInternal;
2111
+ this._private_gInternal = color._private_gInternal;
2112
+ this._private_bInternal = color._private_bInternal;
2113
+ this._private_aInternal = color._private_aInternal;
2119
2114
  this.emit(UIColorEvent.CHANGE, this);
2120
2115
  }
2121
2116
  }
2122
2117
  else {
2123
- if (this.rInternal !== color.r &&
2124
- this.gInternal !== color.g &&
2125
- this.bInternal !== color.b &&
2126
- this.aInternal !== 1) {
2127
- this.rInternal = color.r;
2128
- this.gInternal = color.g;
2129
- this.bInternal = color.b;
2130
- this.aInternal = 1;
2118
+ if (this._private_rInternal !== color.r ||
2119
+ this._private_gInternal !== color.g ||
2120
+ this._private_bInternal !== color.b ||
2121
+ this._private_aInternal !== 1) {
2122
+ this._private_rInternal = color.r;
2123
+ this._private_gInternal = color.g;
2124
+ this._private_bInternal = color.b;
2125
+ this._private_aInternal = 1;
2131
2126
  this.emit(UIColorEvent.CHANGE, this);
2132
2127
  }
2133
2128
  }
2134
2129
  return this;
2135
2130
  }
2136
2131
  /**
2137
- * Converts the color to a CSS rgba() string.
2138
- * @returns CSS rgba string (e.g., "rgba(255, 0, 0, 1)")
2139
- */
2140
- toCSSColor() {
2141
- const r = Math.round(this.rInternal * 255);
2142
- const g = Math.round(this.gInternal * 255);
2143
- const b = Math.round(this.bInternal * 255);
2144
- return `rgba(${r}, ${g}, ${b}, ${this.aInternal})`;
2145
- }
2146
- /**
2147
- * Creates a new UIColor instance with identical color values.
2148
- * @returns A new UIColor instance with the same RGBA values
2132
+ * Creates a copy of this color.
2149
2133
  */
2150
2134
  clone() {
2151
- return new UIColor(this.rInternal, this.gInternal, this.bInternal, this.aInternal);
2135
+ return new UIColor(this._private_rInternal, this._private_gInternal, this._private_bInternal, this._private_aInternal);
2152
2136
  }
2153
2137
  }
2154
2138
 
@@ -6707,6 +6691,7 @@ class UIResizePolicyNone extends UIResizePolicy {
6707
6691
  }
6708
6692
  }
6709
6693
 
6694
+ const TEMP_POSITION = new Vector3();
6710
6695
  /**
6711
6696
  * UI layer that covers the full browser window.
6712
6697
  *
@@ -6792,10 +6777,24 @@ class UIFullscreenLayer extends UILayer {
6792
6777
  * @returns 2D position in layer space
6793
6778
  */
6794
6779
  projectWorldPosition(position, camera) {
6795
- const projectedPosition = position.project(camera);
6780
+ const projectedPosition = TEMP_POSITION.copy(position).project(camera);
6796
6781
  projectedPosition.x = MathUtils.mapLinear(projectedPosition.x, -1, 1, this.x, this.width);
6797
6782
  projectedPosition.y = MathUtils.mapLinear(projectedPosition.y, -1, 1, this.y, this.height);
6798
- return projectedPosition;
6783
+ return new Vector2(projectedPosition.x, projectedPosition.y);
6784
+ }
6785
+ /**
6786
+ * Projects 2D layer position to 3D world coordinates.
6787
+ *
6788
+ * @param position - 2D position in layer space
6789
+ * @param camera - Camera for unprojection
6790
+ * @param z - Z depth in camera space (defaults to 1)
6791
+ * @returns 3D position in world space
6792
+ */
6793
+ projectLayerPosition(position, camera, z = -1) {
6794
+ TEMP_POSITION.x = MathUtils.mapLinear(position.x, this.x, this.width, -1, 1);
6795
+ TEMP_POSITION.y = MathUtils.mapLinear(position.y, this.y, this.height, -1, 1);
6796
+ TEMP_POSITION.z = z;
6797
+ return TEMP_POSITION.unproject(camera);
6799
6798
  }
6800
6799
  _private_handleWindowInput(event, pointerFunctionName, inputEvent) {
6801
6800
  const rect = event.target instanceof HTMLElement
@@ -6808,8 +6807,10 @@ class UIFullscreenLayer extends UILayer {
6808
6807
  const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
6809
6808
  const scaledX = x * scale;
6810
6809
  const scaledY = y * scale;
6810
+ if (this.mode === UIMode.INTERACTIVE) {
6811
+ this.emit(inputEvent, scaledX, scaledY, event.pointerId);
6812
+ }
6811
6813
  this[pointerFunctionName](scaledX, scaledY, event.pointerId);
6812
- this.emit(inputEvent, scaledX, scaledY, event.pointerId);
6813
6814
  }
6814
6815
  }
6815
6816
 
@@ -6982,9 +6983,6 @@ function buildMaterial(source, uniformLayout, varyingLayout, transparency) {
6982
6983
  gl_FragColor = linearToOutputTexel(diffuseColor);
6983
6984
  }
6984
6985
  `;
6985
- console.log(vertexShader);
6986
- console.log(fragmentShader);
6987
- console.log(uniforms);
6988
6986
  return new ShaderMaterial({
6989
6987
  uniforms,
6990
6988
  vertexShader,