@playcanvas/web-components 0.6.0 → 0.7.1

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/pwc.cjs CHANGED
@@ -146,6 +146,10 @@ class AppElement extends AsyncElement {
146
146
  createOptions.graphicsDevice = device;
147
147
  createOptions.keyboard = new playcanvas.Keyboard(window);
148
148
  createOptions.mouse = new playcanvas.Mouse(this._canvas);
149
+ createOptions.elementInput = new playcanvas.ElementInput(this._canvas, {
150
+ useMouse: true,
151
+ useTouch: true
152
+ });
149
153
  createOptions.componentSystems = [
150
154
  playcanvas.AnimComponentSystem,
151
155
  playcanvas.AnimationComponentSystem,
@@ -745,6 +749,50 @@ const parseVec4 = (value) => {
745
749
  const components = value.split(' ').map(Number);
746
750
  return new playcanvas.Vec4(components);
747
751
  };
752
+ /**
753
+ * Resolves an enum value supplied as either a named string (looked up in `map`) or a numeric
754
+ * string. Falls back to `defaultValue` when the value is neither a known name nor a finite number.
755
+ *
756
+ * @param value - The attribute value to parse.
757
+ * @param map - A map of named values to their numeric enum equivalents.
758
+ * @param defaultValue - The value to return when parsing fails.
759
+ * @returns The resolved numeric enum value.
760
+ */
761
+ const parseEnum = (value, map, defaultValue) => {
762
+ const named = map.get(value);
763
+ if (named !== undefined) {
764
+ return named;
765
+ }
766
+ const numeric = Number(value);
767
+ return Number.isFinite(numeric) ? numeric : defaultValue;
768
+ };
769
+ /**
770
+ * Resolves a reference string to the {@link Entity} backing a `<pc-entity>` element. The reference
771
+ * can be a CSS selector (e.g. `#my-id`, `pc-entity[name="Foo"]`), a bare element id, or a bare
772
+ * entity name. Returns `null` if no matching element (or backing entity) is found.
773
+ *
774
+ * @param ref - The reference string to resolve.
775
+ * @returns The resolved entity, or `null`.
776
+ */
777
+ const getEntity = (ref) => {
778
+ var _a, _b;
779
+ if (!ref) {
780
+ return null;
781
+ }
782
+ let element = null;
783
+ // Try the reference as a CSS selector. An invalid selector (e.g. a bare name containing
784
+ // spaces) throws, in which case we fall back to id/name lookups below.
785
+ try {
786
+ element = document.querySelector(ref);
787
+ }
788
+ catch (_c) {
789
+ element = null;
790
+ }
791
+ if (!element) {
792
+ element = (_a = document.getElementById(ref)) !== null && _a !== void 0 ? _a : document.querySelector(`pc-entity[name="${ref}"]`);
793
+ }
794
+ return (_b = element === null || element === void 0 ? void 0 : element.entity) !== null && _b !== void 0 ? _b : null;
795
+ };
748
796
 
749
797
  /**
750
798
  * The EntityElement interface provides properties and methods for manipulating
@@ -783,12 +831,22 @@ class EntityElement extends AsyncElement {
783
831
  * The pointer event listeners for the entity.
784
832
  */
785
833
  this._listeners = {};
834
+ /**
835
+ * Whether the hierarchy has been built for this entity.
836
+ */
837
+ this._built = false;
786
838
  /**
787
839
  * The PlayCanvas entity instance.
788
840
  */
789
841
  this.entity = null;
790
842
  }
791
843
  createEntity(app) {
844
+ // Guard against double creation. When a subtree is inserted at runtime (e.g. cloning a
845
+ // `<template>`), an ancestor's connectedCallback eagerly creates descendant entities; the
846
+ // descendants' own connectedCallbacks would otherwise create them a second time.
847
+ if (this.entity) {
848
+ return;
849
+ }
792
850
  // Create a new entity
793
851
  this.entity = new playcanvas.Entity(this.getAttribute('name') || this._name, app);
794
852
  const enabled = this.getAttribute('enabled');
@@ -837,8 +895,9 @@ class EntityElement extends AsyncElement {
837
895
  });
838
896
  }
839
897
  buildHierarchy(app) {
840
- if (!this.entity)
898
+ if (!this.entity || this._built)
841
899
  return;
900
+ this._built = true;
842
901
  const closestEntity = this.closestEntity;
843
902
  if (closestEntity === null || closestEntity === void 0 ? void 0 : closestEntity.entity) {
844
903
  closestEntity.entity.addChild(this.entity);
@@ -878,6 +937,7 @@ class EntityElement extends AsyncElement {
878
937
  // Destroy the entity
879
938
  this.entity.destroy();
880
939
  this.entity = null;
940
+ this._built = false;
881
941
  }
882
942
  }
883
943
  /**
@@ -1243,6 +1303,11 @@ var MeshoptDecoder = (function() {
1243
1303
  };
1244
1304
  })();
1245
1305
 
1306
+ const renderModes = new Map([
1307
+ ['simple', playcanvas.SPRITE_RENDERMODE_SIMPLE],
1308
+ ['sliced', playcanvas.SPRITE_RENDERMODE_SLICED],
1309
+ ['tiled', playcanvas.SPRITE_RENDERMODE_TILED]
1310
+ ]);
1246
1311
  const extToType = new Map([
1247
1312
  ['bin', 'binary'],
1248
1313
  ['css', 'css'],
@@ -1316,6 +1381,9 @@ class AssetElement extends HTMLElement {
1316
1381
  console.warn(`Unsupported asset type: ${src}`);
1317
1382
  return;
1318
1383
  }
1384
+ // Optional inline asset data, used by data-driven assets such as texture atlases (frame
1385
+ // definitions) and sprites (atlas reference, frame keys, etc.).
1386
+ const data = this._buildData(type);
1319
1387
  if (type === 'container') {
1320
1388
  this.asset = new playcanvas.Asset(id, type, { url: src }, undefined, {
1321
1389
  // @ts-ignore TODO no definition in pc
@@ -1324,12 +1392,69 @@ class AssetElement extends HTMLElement {
1324
1392
  }
1325
1393
  });
1326
1394
  }
1395
+ else if (type === 'sprite') {
1396
+ // Sprite assets have no file of their own; their data references a texture atlas asset.
1397
+ // @ts-ignore
1398
+ this.asset = new playcanvas.Asset(id, type, null, data);
1399
+ }
1327
1400
  else {
1328
1401
  // @ts-ignore
1329
- this.asset = new playcanvas.Asset(id, type, { url: src });
1402
+ this.asset = new playcanvas.Asset(id, type, src ? { url: src } : null, data);
1330
1403
  }
1331
1404
  this.asset.preload = !this._lazy;
1332
1405
  }
1406
+ /**
1407
+ * Builds the `data` object for the asset from an optional inline `data` attribute (JSON) and,
1408
+ * for sprites, from the convenience attributes (`atlas`, `frame-keys`, `pixels-per-unit`,
1409
+ * `render-mode`). Returns `undefined` when there is no data to apply.
1410
+ * @param type - The resolved asset type.
1411
+ * @returns The asset data, or `undefined`.
1412
+ */
1413
+ _buildData(type) {
1414
+ var _a, _b, _c, _d;
1415
+ let data;
1416
+ const dataAttr = this.getAttribute('data');
1417
+ if (dataAttr) {
1418
+ try {
1419
+ data = JSON.parse(dataAttr);
1420
+ }
1421
+ catch (e) {
1422
+ console.warn(`Invalid 'data' JSON on pc-asset: ${dataAttr}`);
1423
+ }
1424
+ }
1425
+ if (type === 'sprite') {
1426
+ data = data !== null && data !== void 0 ? data : {};
1427
+ // Resolve the referenced texture atlas to its (numeric) asset id. The atlas must be
1428
+ // declared before the sprite so its asset already exists in the registry.
1429
+ const atlas = (_a = this.getAttribute('atlas')) !== null && _a !== void 0 ? _a : data.textureAtlasAsset;
1430
+ if (typeof atlas === 'string') {
1431
+ const atlasAsset = AssetElement.get(atlas);
1432
+ if (atlasAsset) {
1433
+ data.textureAtlasAsset = atlasAsset.id;
1434
+ }
1435
+ else {
1436
+ console.warn(`pc-asset sprite '${this.getAttribute('id')}' could not find atlas '${atlas}'`);
1437
+ }
1438
+ }
1439
+ const frameKeys = this.getAttribute('frame-keys');
1440
+ if (frameKeys !== null) {
1441
+ data.frameKeys = frameKeys.split(/[\s,]+/).filter(Boolean);
1442
+ }
1443
+ const pixelsPerUnit = this.getAttribute('pixels-per-unit');
1444
+ if (pixelsPerUnit !== null) {
1445
+ data.pixelsPerUnit = Number(pixelsPerUnit);
1446
+ }
1447
+ const renderMode = this.getAttribute('render-mode');
1448
+ if (renderMode !== null) {
1449
+ data.renderMode = parseEnum(renderMode, renderModes, playcanvas.SPRITE_RENDERMODE_SIMPLE);
1450
+ }
1451
+ // Apply engine defaults for any values not supplied.
1452
+ data.renderMode = (_b = data.renderMode) !== null && _b !== void 0 ? _b : playcanvas.SPRITE_RENDERMODE_SIMPLE;
1453
+ data.pixelsPerUnit = (_c = data.pixelsPerUnit) !== null && _c !== void 0 ? _c : 1;
1454
+ data.frameKeys = (_d = data.frameKeys) !== null && _d !== void 0 ? _d : [];
1455
+ }
1456
+ return data;
1457
+ }
1333
1458
  destroyAsset() {
1334
1459
  if (this.asset) {
1335
1460
  this.asset.unload();
@@ -1469,6 +1594,396 @@ class ListenerComponentElement extends ComponentElement {
1469
1594
  }
1470
1595
  customElements.define('pc-listener', ListenerComponentElement);
1471
1596
 
1597
+ const transitionModes = new Map([
1598
+ ['tint', playcanvas.BUTTON_TRANSITION_MODE_TINT],
1599
+ ['sprite', playcanvas.BUTTON_TRANSITION_MODE_SPRITE_CHANGE]
1600
+ ]);
1601
+ /**
1602
+ * The ButtonComponentElement interface provides properties and methods for manipulating
1603
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-button/ | `<pc-button>`} elements.
1604
+ * The ButtonComponentElement interface also inherits the properties and methods of the
1605
+ * {@link HTMLElement} interface.
1606
+ *
1607
+ * @category Components
1608
+ */
1609
+ class ButtonComponentElement extends ComponentElement {
1610
+ /** @ignore */
1611
+ constructor() {
1612
+ super('button');
1613
+ this._active = true;
1614
+ this._image = '';
1615
+ this._hitPadding = new playcanvas.Vec4(0, 0, 0, 0);
1616
+ this._transitionMode = playcanvas.BUTTON_TRANSITION_MODE_TINT;
1617
+ this._hoverTint = new playcanvas.Color(1, 1, 1, 1);
1618
+ this._pressedTint = new playcanvas.Color(1, 1, 1, 1);
1619
+ this._inactiveTint = new playcanvas.Color(1, 1, 1, 1);
1620
+ this._fadeDuration = 0;
1621
+ this._hoverSpriteAsset = '';
1622
+ this._hoverSpriteFrame = 0;
1623
+ this._pressedSpriteAsset = '';
1624
+ this._pressedSpriteFrame = 0;
1625
+ this._inactiveSpriteAsset = '';
1626
+ this._inactiveSpriteFrame = 0;
1627
+ }
1628
+ getInitialComponentData() {
1629
+ var _a;
1630
+ const data = {
1631
+ active: this._active,
1632
+ hitPadding: this._hitPadding,
1633
+ transitionMode: this._transitionMode,
1634
+ hoverTint: this._hoverTint,
1635
+ pressedTint: this._pressedTint,
1636
+ inactiveTint: this._inactiveTint,
1637
+ fadeDuration: this._fadeDuration,
1638
+ hoverSpriteFrame: this._hoverSpriteFrame,
1639
+ pressedSpriteFrame: this._pressedSpriteFrame,
1640
+ inactiveSpriteFrame: this._inactiveSpriteFrame
1641
+ };
1642
+ // The image entity defaults to the button's own entity (which carries the image element)
1643
+ // when no explicit reference is provided.
1644
+ const imageEntity = this._image ? getEntity(this._image) : (_a = this.closestEntity) === null || _a === void 0 ? void 0 : _a.entity;
1645
+ if (imageEntity) {
1646
+ data.imageEntity = imageEntity;
1647
+ }
1648
+ const hoverSpriteAsset = AssetElement.get(this._hoverSpriteAsset);
1649
+ if (hoverSpriteAsset) {
1650
+ data.hoverSpriteAsset = hoverSpriteAsset.id;
1651
+ }
1652
+ const pressedSpriteAsset = AssetElement.get(this._pressedSpriteAsset);
1653
+ if (pressedSpriteAsset) {
1654
+ data.pressedSpriteAsset = pressedSpriteAsset.id;
1655
+ }
1656
+ const inactiveSpriteAsset = AssetElement.get(this._inactiveSpriteAsset);
1657
+ if (inactiveSpriteAsset) {
1658
+ data.inactiveSpriteAsset = inactiveSpriteAsset.id;
1659
+ }
1660
+ return data;
1661
+ }
1662
+ /**
1663
+ * Gets the underlying PlayCanvas button component.
1664
+ * @returns The button component.
1665
+ */
1666
+ get component() {
1667
+ return super.component;
1668
+ }
1669
+ /**
1670
+ * Sets whether the button is active and responds to input.
1671
+ * @param value - Whether the button is active.
1672
+ */
1673
+ set active(value) {
1674
+ this._active = value;
1675
+ if (this.component) {
1676
+ this.component.active = value;
1677
+ }
1678
+ }
1679
+ /**
1680
+ * Gets whether the button is active.
1681
+ * @returns Whether the button is active.
1682
+ */
1683
+ get active() {
1684
+ return this._active;
1685
+ }
1686
+ /**
1687
+ * Sets the reference (CSS selector, element id or entity name) to the `<pc-entity>` whose image
1688
+ * element is used for visual transitions. Defaults to the button's own entity.
1689
+ * @param value - The image entity reference.
1690
+ */
1691
+ set image(value) {
1692
+ this._image = value;
1693
+ const entity = getEntity(value);
1694
+ if (this.component && entity) {
1695
+ this.component.imageEntity = entity;
1696
+ }
1697
+ }
1698
+ /**
1699
+ * Gets the reference to the `<pc-entity>` whose image element is used for visual transitions.
1700
+ * @returns The image entity reference.
1701
+ */
1702
+ get image() {
1703
+ return this._image;
1704
+ }
1705
+ /**
1706
+ * Sets the padding used to expand the button's hit area, as a Vec4 (left, bottom, right, top).
1707
+ * @param value - The hit padding.
1708
+ */
1709
+ set hitPadding(value) {
1710
+ this._hitPadding = value;
1711
+ if (this.component) {
1712
+ this.component.hitPadding = value;
1713
+ }
1714
+ }
1715
+ /**
1716
+ * Gets the padding used to expand the button's hit area.
1717
+ * @returns The hit padding.
1718
+ */
1719
+ get hitPadding() {
1720
+ return this._hitPadding;
1721
+ }
1722
+ /**
1723
+ * Sets how the button reacts to being hovered/pressed. Can be `tint` (0) or `sprite` (1).
1724
+ * @param value - The transition mode.
1725
+ */
1726
+ set transitionMode(value) {
1727
+ this._transitionMode = value;
1728
+ if (this.component) {
1729
+ this.component.transitionMode = value;
1730
+ }
1731
+ }
1732
+ /**
1733
+ * Gets how the button reacts to being hovered/pressed.
1734
+ * @returns The transition mode.
1735
+ */
1736
+ get transitionMode() {
1737
+ return this._transitionMode;
1738
+ }
1739
+ /**
1740
+ * Sets the tint color applied to the image entity when the button is hovered (tint transition
1741
+ * mode).
1742
+ * @param value - The hover tint.
1743
+ */
1744
+ set hoverTint(value) {
1745
+ this._hoverTint = value;
1746
+ if (this.component) {
1747
+ this.component.hoverTint = value;
1748
+ }
1749
+ }
1750
+ /**
1751
+ * Gets the hover tint color.
1752
+ * @returns The hover tint.
1753
+ */
1754
+ get hoverTint() {
1755
+ return this._hoverTint;
1756
+ }
1757
+ /**
1758
+ * Sets the tint color applied to the image entity when the button is pressed (tint transition
1759
+ * mode).
1760
+ * @param value - The pressed tint.
1761
+ */
1762
+ set pressedTint(value) {
1763
+ this._pressedTint = value;
1764
+ if (this.component) {
1765
+ this.component.pressedTint = value;
1766
+ }
1767
+ }
1768
+ /**
1769
+ * Gets the pressed tint color.
1770
+ * @returns The pressed tint.
1771
+ */
1772
+ get pressedTint() {
1773
+ return this._pressedTint;
1774
+ }
1775
+ /**
1776
+ * Sets the tint color applied to the image entity when the button is inactive (tint transition
1777
+ * mode).
1778
+ * @param value - The inactive tint.
1779
+ */
1780
+ set inactiveTint(value) {
1781
+ this._inactiveTint = value;
1782
+ if (this.component) {
1783
+ this.component.inactiveTint = value;
1784
+ }
1785
+ }
1786
+ /**
1787
+ * Gets the inactive tint color.
1788
+ * @returns The inactive tint.
1789
+ */
1790
+ get inactiveTint() {
1791
+ return this._inactiveTint;
1792
+ }
1793
+ /**
1794
+ * Sets the duration (in milliseconds) over which tint transitions are applied.
1795
+ * @param value - The fade duration.
1796
+ */
1797
+ set fadeDuration(value) {
1798
+ this._fadeDuration = value;
1799
+ if (this.component) {
1800
+ this.component.fadeDuration = value;
1801
+ }
1802
+ }
1803
+ /**
1804
+ * Gets the duration over which tint transitions are applied.
1805
+ * @returns The fade duration.
1806
+ */
1807
+ get fadeDuration() {
1808
+ return this._fadeDuration;
1809
+ }
1810
+ /**
1811
+ * Sets the id of the `pc-asset` sprite shown when the button is hovered (sprite transition
1812
+ * mode).
1813
+ * @param value - The hover sprite asset id.
1814
+ */
1815
+ set hoverSpriteAsset(value) {
1816
+ this._hoverSpriteAsset = value;
1817
+ const asset = AssetElement.get(value);
1818
+ if (this.component && asset) {
1819
+ this.component.hoverSpriteAsset = asset.id;
1820
+ }
1821
+ }
1822
+ /**
1823
+ * Gets the id of the `pc-asset` sprite shown when the button is hovered.
1824
+ * @returns The hover sprite asset id.
1825
+ */
1826
+ get hoverSpriteAsset() {
1827
+ return this._hoverSpriteAsset;
1828
+ }
1829
+ /**
1830
+ * Sets the frame of the hover sprite to show.
1831
+ * @param value - The hover sprite frame.
1832
+ */
1833
+ set hoverSpriteFrame(value) {
1834
+ this._hoverSpriteFrame = value;
1835
+ if (this.component) {
1836
+ this.component.hoverSpriteFrame = value;
1837
+ }
1838
+ }
1839
+ /**
1840
+ * Gets the frame of the hover sprite to show.
1841
+ * @returns The hover sprite frame.
1842
+ */
1843
+ get hoverSpriteFrame() {
1844
+ return this._hoverSpriteFrame;
1845
+ }
1846
+ /**
1847
+ * Sets the id of the `pc-asset` sprite shown when the button is pressed (sprite transition
1848
+ * mode).
1849
+ * @param value - The pressed sprite asset id.
1850
+ */
1851
+ set pressedSpriteAsset(value) {
1852
+ this._pressedSpriteAsset = value;
1853
+ const asset = AssetElement.get(value);
1854
+ if (this.component && asset) {
1855
+ this.component.pressedSpriteAsset = asset.id;
1856
+ }
1857
+ }
1858
+ /**
1859
+ * Gets the id of the `pc-asset` sprite shown when the button is pressed.
1860
+ * @returns The pressed sprite asset id.
1861
+ */
1862
+ get pressedSpriteAsset() {
1863
+ return this._pressedSpriteAsset;
1864
+ }
1865
+ /**
1866
+ * Sets the frame of the pressed sprite to show.
1867
+ * @param value - The pressed sprite frame.
1868
+ */
1869
+ set pressedSpriteFrame(value) {
1870
+ this._pressedSpriteFrame = value;
1871
+ if (this.component) {
1872
+ this.component.pressedSpriteFrame = value;
1873
+ }
1874
+ }
1875
+ /**
1876
+ * Gets the frame of the pressed sprite to show.
1877
+ * @returns The pressed sprite frame.
1878
+ */
1879
+ get pressedSpriteFrame() {
1880
+ return this._pressedSpriteFrame;
1881
+ }
1882
+ /**
1883
+ * Sets the id of the `pc-asset` sprite shown when the button is inactive (sprite transition
1884
+ * mode).
1885
+ * @param value - The inactive sprite asset id.
1886
+ */
1887
+ set inactiveSpriteAsset(value) {
1888
+ this._inactiveSpriteAsset = value;
1889
+ const asset = AssetElement.get(value);
1890
+ if (this.component && asset) {
1891
+ this.component.inactiveSpriteAsset = asset.id;
1892
+ }
1893
+ }
1894
+ /**
1895
+ * Gets the id of the `pc-asset` sprite shown when the button is inactive.
1896
+ * @returns The inactive sprite asset id.
1897
+ */
1898
+ get inactiveSpriteAsset() {
1899
+ return this._inactiveSpriteAsset;
1900
+ }
1901
+ /**
1902
+ * Sets the frame of the inactive sprite to show.
1903
+ * @param value - The inactive sprite frame.
1904
+ */
1905
+ set inactiveSpriteFrame(value) {
1906
+ this._inactiveSpriteFrame = value;
1907
+ if (this.component) {
1908
+ this.component.inactiveSpriteFrame = value;
1909
+ }
1910
+ }
1911
+ /**
1912
+ * Gets the frame of the inactive sprite to show.
1913
+ * @returns The inactive sprite frame.
1914
+ */
1915
+ get inactiveSpriteFrame() {
1916
+ return this._inactiveSpriteFrame;
1917
+ }
1918
+ static get observedAttributes() {
1919
+ return [
1920
+ ...super.observedAttributes,
1921
+ 'active',
1922
+ 'image',
1923
+ 'hit-padding',
1924
+ 'transition-mode',
1925
+ 'hover-tint',
1926
+ 'pressed-tint',
1927
+ 'inactive-tint',
1928
+ 'fade-duration',
1929
+ 'hover-sprite-asset',
1930
+ 'hover-sprite-frame',
1931
+ 'pressed-sprite-asset',
1932
+ 'pressed-sprite-frame',
1933
+ 'inactive-sprite-asset',
1934
+ 'inactive-sprite-frame'
1935
+ ];
1936
+ }
1937
+ attributeChangedCallback(name, _oldValue, newValue) {
1938
+ super.attributeChangedCallback(name, _oldValue, newValue);
1939
+ switch (name) {
1940
+ case 'active':
1941
+ this.active = newValue !== 'false';
1942
+ break;
1943
+ case 'image':
1944
+ this.image = newValue;
1945
+ break;
1946
+ case 'hit-padding':
1947
+ this.hitPadding = parseVec4(newValue);
1948
+ break;
1949
+ case 'transition-mode':
1950
+ this.transitionMode = parseEnum(newValue, transitionModes, playcanvas.BUTTON_TRANSITION_MODE_TINT);
1951
+ break;
1952
+ case 'hover-tint':
1953
+ this.hoverTint = parseColor(newValue);
1954
+ break;
1955
+ case 'pressed-tint':
1956
+ this.pressedTint = parseColor(newValue);
1957
+ break;
1958
+ case 'inactive-tint':
1959
+ this.inactiveTint = parseColor(newValue);
1960
+ break;
1961
+ case 'fade-duration':
1962
+ this.fadeDuration = Number(newValue);
1963
+ break;
1964
+ case 'hover-sprite-asset':
1965
+ this.hoverSpriteAsset = newValue;
1966
+ break;
1967
+ case 'hover-sprite-frame':
1968
+ this.hoverSpriteFrame = Number(newValue);
1969
+ break;
1970
+ case 'pressed-sprite-asset':
1971
+ this.pressedSpriteAsset = newValue;
1972
+ break;
1973
+ case 'pressed-sprite-frame':
1974
+ this.pressedSpriteFrame = Number(newValue);
1975
+ break;
1976
+ case 'inactive-sprite-asset':
1977
+ this.inactiveSpriteAsset = newValue;
1978
+ break;
1979
+ case 'inactive-sprite-frame':
1980
+ this.inactiveSpriteFrame = Number(newValue);
1981
+ break;
1982
+ }
1983
+ }
1984
+ }
1985
+ customElements.define('pc-button', ButtonComponentElement);
1986
+
1472
1987
  const tonemaps = new Map([
1473
1988
  ['none', playcanvas.TONEMAP_NONE],
1474
1989
  ['linear', playcanvas.TONEMAP_LINEAR],
@@ -2121,34 +2636,94 @@ class ElementComponentElement extends ComponentElement {
2121
2636
  this._anchor = new playcanvas.Vec4(0.5, 0.5, 0.5, 0.5);
2122
2637
  this._asset = '';
2123
2638
  this._autoWidth = true;
2639
+ this._autoHeight = true;
2640
+ this._autoFitWidth = false;
2641
+ this._autoFitHeight = false;
2124
2642
  this._color = new playcanvas.Color(1, 1, 1, 1);
2125
2643
  this._enableMarkup = false;
2126
2644
  this._fontSize = 32;
2645
+ this._maxFontSize = 32;
2646
+ this._minFontSize = 8;
2647
+ this._height = 0;
2127
2648
  this._lineHeight = 32;
2649
+ this._margin = null;
2650
+ this._mask = false;
2651
+ this._opacity = 1;
2128
2652
  this._pivot = new playcanvas.Vec2(0.5, 0.5);
2653
+ this._pixelsPerUnit = null;
2654
+ this._spriteAsset = '';
2655
+ this._spriteFrame = 0;
2129
2656
  this._text = '';
2657
+ this._textureAsset = '';
2130
2658
  this._type = 'group';
2659
+ this._useInput = false;
2131
2660
  this._width = 0;
2132
2661
  this._wrapLines = false;
2133
2662
  }
2134
2663
  initComponent() {
2135
- this.component._text._material.useFog = true;
2664
+ var _a, _b;
2665
+ const component = this.component;
2666
+ if (!component) {
2667
+ return;
2668
+ }
2669
+ // Text elements render through their own material; enable fog on it so 3D text respects
2670
+ // scene fog. Image/group elements have no text material, so guard the access.
2671
+ if ((_a = component._text) === null || _a === void 0 ? void 0 : _a._material) {
2672
+ component._text._material.useFog = true;
2673
+ }
2674
+ // The engine establishes element masking in ElementComponent._onInsert, which fires when an
2675
+ // entity is inserted into the hierarchy. Web-components inserts the entity first and adds
2676
+ // the element component afterwards, so that pass is missed. Re-dirty the mask state here so
2677
+ // masks (e.g. a scroll view viewport) correctly clip this element and any added at runtime.
2678
+ (_b = component._dirtifyMask) === null || _b === void 0 ? void 0 : _b.call(component);
2136
2679
  }
2137
2680
  getInitialComponentData() {
2138
- return {
2681
+ const data = {
2139
2682
  anchor: this._anchor,
2140
2683
  autoWidth: this._autoWidth,
2684
+ autoHeight: this._autoHeight,
2685
+ autoFitWidth: this._autoFitWidth,
2686
+ autoFitHeight: this._autoFitHeight,
2141
2687
  color: this._color,
2142
2688
  enableMarkup: this._enableMarkup,
2143
- fontAsset: AssetElement.get(this._asset).id,
2144
2689
  fontSize: this._fontSize,
2690
+ maxFontSize: this._maxFontSize,
2691
+ minFontSize: this._minFontSize,
2692
+ height: this._height,
2145
2693
  lineHeight: this._lineHeight,
2694
+ mask: this._mask,
2695
+ opacity: this._opacity,
2146
2696
  pivot: this._pivot,
2697
+ spriteFrame: this._spriteFrame,
2147
2698
  type: this._type,
2148
2699
  text: this._text,
2700
+ useInput: this._useInput,
2149
2701
  width: this._width,
2150
2702
  wrapLines: this._wrapLines
2151
2703
  };
2704
+ // Asset references are resolved from `<pc-asset>` element ids to engine asset ids. They are
2705
+ // only included when they resolve, so image/group elements (with no font) don't error.
2706
+ const fontAsset = AssetElement.get(this._asset);
2707
+ if (fontAsset) {
2708
+ data.fontAsset = fontAsset.id;
2709
+ }
2710
+ const spriteAsset = AssetElement.get(this._spriteAsset);
2711
+ if (spriteAsset) {
2712
+ data.spriteAsset = spriteAsset.id;
2713
+ }
2714
+ const textureAsset = AssetElement.get(this._textureAsset);
2715
+ if (textureAsset) {
2716
+ data.textureAsset = textureAsset.id;
2717
+ }
2718
+ // Margin is only applied when explicitly set. For stretched (split) anchors it governs the
2719
+ // element size; for point anchors width/height take over (handled by the engine).
2720
+ if (this._margin) {
2721
+ data.margin = this._margin;
2722
+ }
2723
+ if (this._pixelsPerUnit !== null) {
2724
+ data.pixelsPerUnit = this._pixelsPerUnit;
2725
+ }
2726
+ return data;
2152
2727
  }
2153
2728
  /**
2154
2729
  * Gets the underlying PlayCanvas element component.
@@ -2175,7 +2750,7 @@ class ElementComponentElement extends ComponentElement {
2175
2750
  return this._anchor;
2176
2751
  }
2177
2752
  /**
2178
- * Sets the id of the `pc-asset` to use for the font.
2753
+ * Sets the id of the `pc-asset` to use for the font (text elements).
2179
2754
  * @param value - The asset ID.
2180
2755
  */
2181
2756
  set asset(value) {
@@ -2193,7 +2768,8 @@ class ElementComponentElement extends ComponentElement {
2193
2768
  return this._asset;
2194
2769
  }
2195
2770
  /**
2196
- * Sets whether the element component should automatically adjust its width.
2771
+ * Sets whether the element component should automatically adjust its width to the text content
2772
+ * (text elements only).
2197
2773
  * @param value - Whether to automatically adjust the width.
2198
2774
  */
2199
2775
  set autoWidth(value) {
@@ -2209,6 +2785,24 @@ class ElementComponentElement extends ComponentElement {
2209
2785
  get autoWidth() {
2210
2786
  return this._autoWidth;
2211
2787
  }
2788
+ /**
2789
+ * Sets whether the element component should automatically adjust its height to the text content
2790
+ * (text elements only).
2791
+ * @param value - Whether to automatically adjust the height.
2792
+ */
2793
+ set autoHeight(value) {
2794
+ this._autoHeight = value;
2795
+ if (this.component) {
2796
+ this.component.autoHeight = value;
2797
+ }
2798
+ }
2799
+ /**
2800
+ * Gets whether the element component should automatically adjust its height.
2801
+ * @returns Whether to automatically adjust the height.
2802
+ */
2803
+ get autoHeight() {
2804
+ return this._autoHeight;
2805
+ }
2212
2806
  /**
2213
2807
  * Sets the color of the element component.
2214
2808
  * @param value - The color.
@@ -2260,6 +2854,23 @@ class ElementComponentElement extends ComponentElement {
2260
2854
  get fontSize() {
2261
2855
  return this._fontSize;
2262
2856
  }
2857
+ /**
2858
+ * Sets the height of the element component.
2859
+ * @param value - The height.
2860
+ */
2861
+ set height(value) {
2862
+ this._height = value;
2863
+ if (this.component) {
2864
+ this.component.height = value;
2865
+ }
2866
+ }
2867
+ /**
2868
+ * Gets the height of the element component.
2869
+ * @returns The height.
2870
+ */
2871
+ get height() {
2872
+ return this._height;
2873
+ }
2263
2874
  /**
2264
2875
  * Sets the line height of the element component.
2265
2876
  * @param value - The line height.
@@ -2278,56 +2889,195 @@ class ElementComponentElement extends ComponentElement {
2278
2889
  return this._lineHeight;
2279
2890
  }
2280
2891
  /**
2281
- * Sets the pivot of the element component.
2282
- * @param value - The pivot.
2892
+ * Sets the margin of the element component (used to inset the element from stretched anchors).
2893
+ * @param value - The margin as a Vec4 (left, bottom, right, top).
2283
2894
  */
2284
- set pivot(value) {
2285
- this._pivot = value;
2286
- if (this.component) {
2287
- this.component.pivot = value;
2895
+ set margin(value) {
2896
+ this._margin = value;
2897
+ if (this.component && value) {
2898
+ this.component.margin = value;
2288
2899
  }
2289
2900
  }
2290
2901
  /**
2291
- * Gets the pivot of the element component.
2292
- * @returns The pivot.
2902
+ * Gets the margin of the element component.
2903
+ * @returns The margin.
2293
2904
  */
2294
- get pivot() {
2295
- return this._pivot;
2905
+ get margin() {
2906
+ return this._margin;
2296
2907
  }
2297
2908
  /**
2298
- * Sets the text of the element component.
2299
- * @param value - The text.
2909
+ * Sets whether the element component is a mask, clipping its descendants to its bounds (image
2910
+ * elements only).
2911
+ * @param value - Whether the element is a mask.
2300
2912
  */
2301
- set text(value) {
2302
- this._text = value;
2913
+ set mask(value) {
2914
+ this._mask = value;
2303
2915
  if (this.component) {
2304
- this.component.text = value;
2916
+ this.component.mask = value;
2305
2917
  }
2306
2918
  }
2307
2919
  /**
2308
- * Gets the text of the element component.
2309
- * @returns The text.
2920
+ * Gets whether the element component is a mask.
2921
+ * @returns Whether the element is a mask.
2310
2922
  */
2311
- get text() {
2312
- return this._text;
2923
+ get mask() {
2924
+ return this._mask;
2313
2925
  }
2314
2926
  /**
2315
- * Sets the type of the element component.
2316
- * @param value - The type.
2927
+ * Sets the opacity of the element component.
2928
+ * @param value - The opacity (0 to 1).
2317
2929
  */
2318
- set type(value) {
2319
- this._type = value;
2930
+ set opacity(value) {
2931
+ this._opacity = value;
2320
2932
  if (this.component) {
2321
- this.component.type = value;
2933
+ this.component.opacity = value;
2322
2934
  }
2323
2935
  }
2324
2936
  /**
2325
- * Gets the type of the element component.
2937
+ * Gets the opacity of the element component.
2938
+ * @returns The opacity.
2939
+ */
2940
+ get opacity() {
2941
+ return this._opacity;
2942
+ }
2943
+ /**
2944
+ * Sets the pivot of the element component.
2945
+ * @param value - The pivot.
2946
+ */
2947
+ set pivot(value) {
2948
+ this._pivot = value;
2949
+ if (this.component) {
2950
+ this.component.pivot = value;
2951
+ }
2952
+ }
2953
+ /**
2954
+ * Gets the pivot of the element component.
2955
+ * @returns The pivot.
2956
+ */
2957
+ get pivot() {
2958
+ return this._pivot;
2959
+ }
2960
+ /**
2961
+ * Sets the number of pixels per unit to use when rendering a sprite (image elements only).
2962
+ * @param value - The pixels per unit.
2963
+ */
2964
+ set pixelsPerUnit(value) {
2965
+ this._pixelsPerUnit = value;
2966
+ if (this.component && value !== null) {
2967
+ this.component.pixelsPerUnit = value;
2968
+ }
2969
+ }
2970
+ /**
2971
+ * Gets the number of pixels per unit used when rendering a sprite.
2972
+ * @returns The pixels per unit.
2973
+ */
2974
+ get pixelsPerUnit() {
2975
+ return this._pixelsPerUnit;
2976
+ }
2977
+ /**
2978
+ * Sets the id of the `pc-asset` to use for the sprite (image elements only).
2979
+ * @param value - The sprite asset ID.
2980
+ */
2981
+ set spriteAsset(value) {
2982
+ this._spriteAsset = value;
2983
+ const asset = AssetElement.get(value);
2984
+ if (this.component && asset) {
2985
+ this.component.spriteAsset = asset.id;
2986
+ }
2987
+ }
2988
+ /**
2989
+ * Gets the id of the `pc-asset` to use for the sprite.
2990
+ * @returns The sprite asset ID.
2991
+ */
2992
+ get spriteAsset() {
2993
+ return this._spriteAsset;
2994
+ }
2995
+ /**
2996
+ * Sets the frame of the sprite to render (image elements only).
2997
+ * @param value - The sprite frame index.
2998
+ */
2999
+ set spriteFrame(value) {
3000
+ this._spriteFrame = value;
3001
+ if (this.component) {
3002
+ this.component.spriteFrame = value;
3003
+ }
3004
+ }
3005
+ /**
3006
+ * Gets the frame of the sprite to render.
3007
+ * @returns The sprite frame index.
3008
+ */
3009
+ get spriteFrame() {
3010
+ return this._spriteFrame;
3011
+ }
3012
+ /**
3013
+ * Sets the text of the element component.
3014
+ * @param value - The text.
3015
+ */
3016
+ set text(value) {
3017
+ this._text = value;
3018
+ if (this.component) {
3019
+ this.component.text = value;
3020
+ }
3021
+ }
3022
+ /**
3023
+ * Gets the text of the element component.
3024
+ * @returns The text.
3025
+ */
3026
+ get text() {
3027
+ return this._text;
3028
+ }
3029
+ /**
3030
+ * Sets the id of the `pc-asset` to use for the texture (image elements only).
3031
+ * @param value - The texture asset ID.
3032
+ */
3033
+ set textureAsset(value) {
3034
+ this._textureAsset = value;
3035
+ const asset = AssetElement.get(value);
3036
+ if (this.component && asset) {
3037
+ this.component.textureAsset = asset.id;
3038
+ }
3039
+ }
3040
+ /**
3041
+ * Gets the id of the `pc-asset` to use for the texture.
3042
+ * @returns The texture asset ID.
3043
+ */
3044
+ get textureAsset() {
3045
+ return this._textureAsset;
3046
+ }
3047
+ /**
3048
+ * Sets the type of the element component.
3049
+ * @param value - The type.
3050
+ */
3051
+ set type(value) {
3052
+ this._type = value;
3053
+ if (this.component) {
3054
+ this.component.type = value;
3055
+ }
3056
+ }
3057
+ /**
3058
+ * Gets the type of the element component.
2326
3059
  * @returns The type.
2327
3060
  */
2328
3061
  get type() {
2329
3062
  return this._type;
2330
3063
  }
3064
+ /**
3065
+ * Sets whether the element component accepts input events (required for buttons and scrolling).
3066
+ * @param value - Whether the element accepts input.
3067
+ */
3068
+ set useInput(value) {
3069
+ this._useInput = value;
3070
+ if (this.component) {
3071
+ this.component.useInput = value;
3072
+ }
3073
+ }
3074
+ /**
3075
+ * Gets whether the element component accepts input events.
3076
+ * @returns Whether the element accepts input.
3077
+ */
3078
+ get useInput() {
3079
+ return this._useInput;
3080
+ }
2331
3081
  /**
2332
3082
  * Sets the width of the element component.
2333
3083
  * @param value - The width.
@@ -2362,19 +3112,103 @@ class ElementComponentElement extends ComponentElement {
2362
3112
  get wrapLines() {
2363
3113
  return this._wrapLines;
2364
3114
  }
3115
+ /**
3116
+ * Sets whether a text element should automatically reduce its font size (down to `min-font-size`)
3117
+ * so the text fits within the element's width. Requires `auto-width` to be `false`.
3118
+ * @param value - Whether to auto-fit the width.
3119
+ */
3120
+ set autoFitWidth(value) {
3121
+ this._autoFitWidth = value;
3122
+ if (this.component) {
3123
+ this.component.autoFitWidth = value;
3124
+ }
3125
+ }
3126
+ /**
3127
+ * Gets whether a text element automatically reduces its font size to fit its width.
3128
+ * @returns Whether the width is auto-fit.
3129
+ */
3130
+ get autoFitWidth() {
3131
+ return this._autoFitWidth;
3132
+ }
3133
+ /**
3134
+ * Sets whether a text element should automatically reduce its font size (down to `min-font-size`)
3135
+ * so the text fits within the element's height. Requires `auto-height` to be `false`.
3136
+ * @param value - Whether to auto-fit the height.
3137
+ */
3138
+ set autoFitHeight(value) {
3139
+ this._autoFitHeight = value;
3140
+ if (this.component) {
3141
+ this.component.autoFitHeight = value;
3142
+ }
3143
+ }
3144
+ /**
3145
+ * Gets whether a text element automatically reduces its font size to fit its height.
3146
+ * @returns Whether the height is auto-fit.
3147
+ */
3148
+ get autoFitHeight() {
3149
+ return this._autoFitHeight;
3150
+ }
3151
+ /**
3152
+ * Sets the smallest font size a text element may use when auto-fitting.
3153
+ * @param value - The minimum font size.
3154
+ */
3155
+ set minFontSize(value) {
3156
+ this._minFontSize = value;
3157
+ if (this.component) {
3158
+ this.component.minFontSize = value;
3159
+ }
3160
+ }
3161
+ /**
3162
+ * Gets the smallest font size a text element may use when auto-fitting.
3163
+ * @returns The minimum font size.
3164
+ */
3165
+ get minFontSize() {
3166
+ return this._minFontSize;
3167
+ }
3168
+ /**
3169
+ * Sets the largest font size a text element may use when auto-fitting.
3170
+ * @param value - The maximum font size.
3171
+ */
3172
+ set maxFontSize(value) {
3173
+ this._maxFontSize = value;
3174
+ if (this.component) {
3175
+ this.component.maxFontSize = value;
3176
+ }
3177
+ }
3178
+ /**
3179
+ * Gets the largest font size a text element may use when auto-fitting.
3180
+ * @returns The maximum font size.
3181
+ */
3182
+ get maxFontSize() {
3183
+ return this._maxFontSize;
3184
+ }
2365
3185
  static get observedAttributes() {
2366
3186
  return [
2367
3187
  ...super.observedAttributes,
2368
3188
  'anchor',
2369
3189
  'asset',
2370
3190
  'auto-width',
3191
+ 'auto-height',
3192
+ 'auto-fit-width',
3193
+ 'auto-fit-height',
2371
3194
  'color',
2372
3195
  'enable-markup',
2373
3196
  'font-size',
3197
+ 'max-font-size',
3198
+ 'min-font-size',
3199
+ 'height',
2374
3200
  'line-height',
3201
+ 'margin',
3202
+ 'mask',
3203
+ 'opacity',
2375
3204
  'pivot',
3205
+ 'pixels-per-unit',
3206
+ 'sprite-asset',
3207
+ 'sprite-frame',
2376
3208
  'text',
3209
+ 'texture-asset',
2377
3210
  'type',
3211
+ 'use-input',
2378
3212
  'width',
2379
3213
  'wrap-lines'
2380
3214
  ];
@@ -2382,46 +3216,544 @@ class ElementComponentElement extends ComponentElement {
2382
3216
  attributeChangedCallback(name, _oldValue, newValue) {
2383
3217
  super.attributeChangedCallback(name, _oldValue, newValue);
2384
3218
  switch (name) {
2385
- case 'anchor':
2386
- this.anchor = parseVec4(newValue);
2387
- break;
2388
- case 'asset':
2389
- this.asset = newValue;
2390
- break;
2391
- case 'auto-width':
2392
- this.autoWidth = newValue !== 'false';
2393
- break;
2394
- case 'color':
2395
- this.color = parseColor(newValue);
3219
+ case 'anchor':
3220
+ this.anchor = parseVec4(newValue);
3221
+ break;
3222
+ case 'asset':
3223
+ this.asset = newValue;
3224
+ break;
3225
+ case 'auto-width':
3226
+ this.autoWidth = newValue !== 'false';
3227
+ break;
3228
+ case 'auto-height':
3229
+ this.autoHeight = newValue !== 'false';
3230
+ break;
3231
+ case 'auto-fit-width':
3232
+ this.autoFitWidth = newValue !== 'false';
3233
+ break;
3234
+ case 'auto-fit-height':
3235
+ this.autoFitHeight = newValue !== 'false';
3236
+ break;
3237
+ case 'color':
3238
+ this.color = parseColor(newValue);
3239
+ break;
3240
+ case 'enable-markup':
3241
+ this.enableMarkup = this.hasAttribute(name);
3242
+ break;
3243
+ case 'font-size':
3244
+ this.fontSize = Number(newValue);
3245
+ break;
3246
+ case 'max-font-size':
3247
+ this.maxFontSize = Number(newValue);
3248
+ break;
3249
+ case 'min-font-size':
3250
+ this.minFontSize = Number(newValue);
3251
+ break;
3252
+ case 'height':
3253
+ this.height = Number(newValue);
3254
+ break;
3255
+ case 'line-height':
3256
+ this.lineHeight = Number(newValue);
3257
+ break;
3258
+ case 'margin':
3259
+ this.margin = parseVec4(newValue);
3260
+ break;
3261
+ case 'mask':
3262
+ this.mask = this.hasAttribute(name);
3263
+ break;
3264
+ case 'opacity':
3265
+ this.opacity = Number(newValue);
3266
+ break;
3267
+ case 'pivot':
3268
+ this.pivot = parseVec2(newValue);
3269
+ break;
3270
+ case 'pixels-per-unit':
3271
+ this.pixelsPerUnit = Number(newValue);
3272
+ break;
3273
+ case 'sprite-asset':
3274
+ this.spriteAsset = newValue;
3275
+ break;
3276
+ case 'sprite-frame':
3277
+ this.spriteFrame = Number(newValue);
3278
+ break;
3279
+ case 'text':
3280
+ this.text = newValue;
3281
+ break;
3282
+ case 'texture-asset':
3283
+ this.textureAsset = newValue;
3284
+ break;
3285
+ case 'type':
3286
+ this.type = newValue;
3287
+ break;
3288
+ case 'use-input':
3289
+ this.useInput = this.hasAttribute(name);
3290
+ break;
3291
+ case 'width':
3292
+ this.width = Number(newValue);
3293
+ break;
3294
+ case 'wrap-lines':
3295
+ this.wrapLines = this.hasAttribute(name);
3296
+ break;
3297
+ }
3298
+ }
3299
+ }
3300
+ customElements.define('pc-element', ElementComponentElement);
3301
+
3302
+ /**
3303
+ * The LayoutChildComponentElement interface provides properties and methods for manipulating
3304
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-layoutchild/ | `<pc-layoutchild>`} elements.
3305
+ * The LayoutChildComponentElement interface also inherits the properties and methods of the
3306
+ * {@link HTMLElement} interface.
3307
+ *
3308
+ * @category Components
3309
+ */
3310
+ class LayoutChildComponentElement extends ComponentElement {
3311
+ /** @ignore */
3312
+ constructor() {
3313
+ super('layoutchild');
3314
+ this._minWidth = 0;
3315
+ this._minHeight = 0;
3316
+ this._maxWidth = null;
3317
+ this._maxHeight = null;
3318
+ this._fitWidthProportion = 0;
3319
+ this._fitHeightProportion = 0;
3320
+ this._excludeFromLayout = false;
3321
+ }
3322
+ getInitialComponentData() {
3323
+ return {
3324
+ minWidth: this._minWidth,
3325
+ minHeight: this._minHeight,
3326
+ maxWidth: this._maxWidth,
3327
+ maxHeight: this._maxHeight,
3328
+ fitWidthProportion: this._fitWidthProportion,
3329
+ fitHeightProportion: this._fitHeightProportion,
3330
+ excludeFromLayout: this._excludeFromLayout
3331
+ };
3332
+ }
3333
+ /**
3334
+ * Gets the underlying PlayCanvas layout child component.
3335
+ * @returns The layout child component.
3336
+ */
3337
+ get component() {
3338
+ return super.component;
3339
+ }
3340
+ /**
3341
+ * Sets the minimum width the element should be laid out with.
3342
+ * @param value - The minimum width.
3343
+ */
3344
+ set minWidth(value) {
3345
+ this._minWidth = value;
3346
+ if (this.component) {
3347
+ this.component.minWidth = value;
3348
+ }
3349
+ }
3350
+ /**
3351
+ * Gets the minimum width the element should be laid out with.
3352
+ * @returns The minimum width.
3353
+ */
3354
+ get minWidth() {
3355
+ return this._minWidth;
3356
+ }
3357
+ /**
3358
+ * Sets the minimum height the element should be laid out with.
3359
+ * @param value - The minimum height.
3360
+ */
3361
+ set minHeight(value) {
3362
+ this._minHeight = value;
3363
+ if (this.component) {
3364
+ this.component.minHeight = value;
3365
+ }
3366
+ }
3367
+ /**
3368
+ * Gets the minimum height the element should be laid out with.
3369
+ * @returns The minimum height.
3370
+ */
3371
+ get minHeight() {
3372
+ return this._minHeight;
3373
+ }
3374
+ /**
3375
+ * Sets the maximum width the element should be laid out with (or `null` for no limit).
3376
+ * @param value - The maximum width.
3377
+ */
3378
+ set maxWidth(value) {
3379
+ this._maxWidth = value;
3380
+ if (this.component) {
3381
+ this.component.maxWidth = value;
3382
+ }
3383
+ }
3384
+ /**
3385
+ * Gets the maximum width the element should be laid out with.
3386
+ * @returns The maximum width.
3387
+ */
3388
+ get maxWidth() {
3389
+ return this._maxWidth;
3390
+ }
3391
+ /**
3392
+ * Sets the maximum height the element should be laid out with (or `null` for no limit).
3393
+ * @param value - The maximum height.
3394
+ */
3395
+ set maxHeight(value) {
3396
+ this._maxHeight = value;
3397
+ if (this.component) {
3398
+ this.component.maxHeight = value;
3399
+ }
3400
+ }
3401
+ /**
3402
+ * Gets the maximum height the element should be laid out with.
3403
+ * @returns The maximum height.
3404
+ */
3405
+ get maxHeight() {
3406
+ return this._maxHeight;
3407
+ }
3408
+ /**
3409
+ * Sets the proportion of the container's spare width this element should take (when the layout
3410
+ * group's `width-fitting` is set to stretch or shrink).
3411
+ * @param value - The fit width proportion.
3412
+ */
3413
+ set fitWidthProportion(value) {
3414
+ this._fitWidthProportion = value;
3415
+ if (this.component) {
3416
+ this.component.fitWidthProportion = value;
3417
+ }
3418
+ }
3419
+ /**
3420
+ * Gets the proportion of the container's spare width this element should take.
3421
+ * @returns The fit width proportion.
3422
+ */
3423
+ get fitWidthProportion() {
3424
+ return this._fitWidthProportion;
3425
+ }
3426
+ /**
3427
+ * Sets the proportion of the container's spare height this element should take (when the layout
3428
+ * group's `height-fitting` is set to stretch or shrink).
3429
+ * @param value - The fit height proportion.
3430
+ */
3431
+ set fitHeightProportion(value) {
3432
+ this._fitHeightProportion = value;
3433
+ if (this.component) {
3434
+ this.component.fitHeightProportion = value;
3435
+ }
3436
+ }
3437
+ /**
3438
+ * Gets the proportion of the container's spare height this element should take.
3439
+ * @returns The fit height proportion.
3440
+ */
3441
+ get fitHeightProportion() {
3442
+ return this._fitHeightProportion;
3443
+ }
3444
+ /**
3445
+ * Sets whether the element should be excluded from the layout (and thus not take up space).
3446
+ * @param value - Whether to exclude the element from layout.
3447
+ */
3448
+ set excludeFromLayout(value) {
3449
+ this._excludeFromLayout = value;
3450
+ if (this.component) {
3451
+ this.component.excludeFromLayout = value;
3452
+ }
3453
+ }
3454
+ /**
3455
+ * Gets whether the element is excluded from the layout.
3456
+ * @returns Whether the element is excluded from layout.
3457
+ */
3458
+ get excludeFromLayout() {
3459
+ return this._excludeFromLayout;
3460
+ }
3461
+ static get observedAttributes() {
3462
+ return [
3463
+ ...super.observedAttributes,
3464
+ 'min-width',
3465
+ 'min-height',
3466
+ 'max-width',
3467
+ 'max-height',
3468
+ 'fit-width-proportion',
3469
+ 'fit-height-proportion',
3470
+ 'exclude-from-layout'
3471
+ ];
3472
+ }
3473
+ attributeChangedCallback(name, _oldValue, newValue) {
3474
+ super.attributeChangedCallback(name, _oldValue, newValue);
3475
+ switch (name) {
3476
+ case 'min-width':
3477
+ this.minWidth = Number(newValue);
3478
+ break;
3479
+ case 'min-height':
3480
+ this.minHeight = Number(newValue);
3481
+ break;
3482
+ case 'max-width':
3483
+ this.maxWidth = newValue === '' ? null : Number(newValue);
3484
+ break;
3485
+ case 'max-height':
3486
+ this.maxHeight = newValue === '' ? null : Number(newValue);
3487
+ break;
3488
+ case 'fit-width-proportion':
3489
+ this.fitWidthProportion = Number(newValue);
3490
+ break;
3491
+ case 'fit-height-proportion':
3492
+ this.fitHeightProportion = Number(newValue);
3493
+ break;
3494
+ case 'exclude-from-layout':
3495
+ this.excludeFromLayout = newValue !== 'false';
3496
+ break;
3497
+ }
3498
+ }
3499
+ }
3500
+ customElements.define('pc-layoutchild', LayoutChildComponentElement);
3501
+
3502
+ const orientations$1 = new Map([
3503
+ ['horizontal', playcanvas.ORIENTATION_HORIZONTAL],
3504
+ ['vertical', playcanvas.ORIENTATION_VERTICAL]
3505
+ ]);
3506
+ const fittings = new Map([
3507
+ ['none', playcanvas.FITTING_NONE],
3508
+ ['stretch', playcanvas.FITTING_STRETCH],
3509
+ ['shrink', playcanvas.FITTING_SHRINK],
3510
+ ['both', playcanvas.FITTING_BOTH]
3511
+ ]);
3512
+ /**
3513
+ * The LayoutGroupComponentElement interface provides properties and methods for manipulating
3514
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-layoutgroup/ | `<pc-layoutgroup>`} elements.
3515
+ * The LayoutGroupComponentElement interface also inherits the properties and methods of the
3516
+ * {@link HTMLElement} interface.
3517
+ *
3518
+ * @category Components
3519
+ */
3520
+ class LayoutGroupComponentElement extends ComponentElement {
3521
+ /** @ignore */
3522
+ constructor() {
3523
+ super('layoutgroup');
3524
+ this._orientation = playcanvas.ORIENTATION_HORIZONTAL;
3525
+ this._reverseX = false;
3526
+ this._reverseY = false;
3527
+ this._alignment = new playcanvas.Vec2(0, 1);
3528
+ this._padding = new playcanvas.Vec4(0, 0, 0, 0);
3529
+ this._spacing = new playcanvas.Vec2(0, 0);
3530
+ this._widthFitting = playcanvas.FITTING_NONE;
3531
+ this._heightFitting = playcanvas.FITTING_NONE;
3532
+ this._wrap = false;
3533
+ }
3534
+ getInitialComponentData() {
3535
+ return {
3536
+ orientation: this._orientation,
3537
+ reverseX: this._reverseX,
3538
+ reverseY: this._reverseY,
3539
+ alignment: this._alignment,
3540
+ padding: this._padding,
3541
+ spacing: this._spacing,
3542
+ widthFitting: this._widthFitting,
3543
+ heightFitting: this._heightFitting,
3544
+ wrap: this._wrap
3545
+ };
3546
+ }
3547
+ /**
3548
+ * Gets the underlying PlayCanvas layout group component.
3549
+ * @returns The layout group component.
3550
+ */
3551
+ get component() {
3552
+ return super.component;
3553
+ }
3554
+ /**
3555
+ * Sets the orientation of the layout group. Can be `horizontal` (0) or `vertical` (1).
3556
+ * @param value - The orientation.
3557
+ */
3558
+ set orientation(value) {
3559
+ this._orientation = value;
3560
+ if (this.component) {
3561
+ this.component.orientation = value;
3562
+ }
3563
+ }
3564
+ /**
3565
+ * Gets the orientation of the layout group.
3566
+ * @returns The orientation.
3567
+ */
3568
+ get orientation() {
3569
+ return this._orientation;
3570
+ }
3571
+ /**
3572
+ * Sets whether the order of children is reversed along the horizontal axis.
3573
+ * @param value - Whether to reverse the horizontal order.
3574
+ */
3575
+ set reverseX(value) {
3576
+ this._reverseX = value;
3577
+ if (this.component) {
3578
+ this.component.reverseX = value;
3579
+ }
3580
+ }
3581
+ /**
3582
+ * Gets whether the order of children is reversed along the horizontal axis.
3583
+ * @returns Whether the horizontal order is reversed.
3584
+ */
3585
+ get reverseX() {
3586
+ return this._reverseX;
3587
+ }
3588
+ /**
3589
+ * Sets whether the order of children is reversed along the vertical axis.
3590
+ * @param value - Whether to reverse the vertical order.
3591
+ */
3592
+ set reverseY(value) {
3593
+ this._reverseY = value;
3594
+ if (this.component) {
3595
+ this.component.reverseY = value;
3596
+ }
3597
+ }
3598
+ /**
3599
+ * Gets whether the order of children is reversed along the vertical axis.
3600
+ * @returns Whether the vertical order is reversed.
3601
+ */
3602
+ get reverseY() {
3603
+ return this._reverseY;
3604
+ }
3605
+ /**
3606
+ * Sets the horizontal and vertical alignment of the child elements (each component 0 to 1).
3607
+ * @param value - The alignment.
3608
+ */
3609
+ set alignment(value) {
3610
+ this._alignment = value;
3611
+ if (this.component) {
3612
+ this.component.alignment = value;
3613
+ }
3614
+ }
3615
+ /**
3616
+ * Gets the alignment of the child elements.
3617
+ * @returns The alignment.
3618
+ */
3619
+ get alignment() {
3620
+ return this._alignment;
3621
+ }
3622
+ /**
3623
+ * Sets the padding around the layout group, as a Vec4 (left, bottom, right, top).
3624
+ * @param value - The padding.
3625
+ */
3626
+ set padding(value) {
3627
+ this._padding = value;
3628
+ if (this.component) {
3629
+ this.component.padding = value;
3630
+ }
3631
+ }
3632
+ /**
3633
+ * Gets the padding around the layout group.
3634
+ * @returns The padding.
3635
+ */
3636
+ get padding() {
3637
+ return this._padding;
3638
+ }
3639
+ /**
3640
+ * Sets the spacing between child elements, as a Vec2 (x, y).
3641
+ * @param value - The spacing.
3642
+ */
3643
+ set spacing(value) {
3644
+ this._spacing = value;
3645
+ if (this.component) {
3646
+ this.component.spacing = value;
3647
+ }
3648
+ }
3649
+ /**
3650
+ * Gets the spacing between child elements.
3651
+ * @returns The spacing.
3652
+ */
3653
+ get spacing() {
3654
+ return this._spacing;
3655
+ }
3656
+ /**
3657
+ * Sets the fitting mode along the horizontal axis. Can be `none` (0), `stretch` (1), `shrink`
3658
+ * (2) or `both` (3).
3659
+ * @param value - The width fitting mode.
3660
+ */
3661
+ set widthFitting(value) {
3662
+ this._widthFitting = value;
3663
+ if (this.component) {
3664
+ this.component.widthFitting = value;
3665
+ }
3666
+ }
3667
+ /**
3668
+ * Gets the fitting mode along the horizontal axis.
3669
+ * @returns The width fitting mode.
3670
+ */
3671
+ get widthFitting() {
3672
+ return this._widthFitting;
3673
+ }
3674
+ /**
3675
+ * Sets the fitting mode along the vertical axis. Can be `none` (0), `stretch` (1), `shrink` (2)
3676
+ * or `both` (3).
3677
+ * @param value - The height fitting mode.
3678
+ */
3679
+ set heightFitting(value) {
3680
+ this._heightFitting = value;
3681
+ if (this.component) {
3682
+ this.component.heightFitting = value;
3683
+ }
3684
+ }
3685
+ /**
3686
+ * Gets the fitting mode along the vertical axis.
3687
+ * @returns The height fitting mode.
3688
+ */
3689
+ get heightFitting() {
3690
+ return this._heightFitting;
3691
+ }
3692
+ /**
3693
+ * Sets whether children wrap onto a new line/column when they overflow the group.
3694
+ * @param value - Whether to wrap children.
3695
+ */
3696
+ set wrap(value) {
3697
+ this._wrap = value;
3698
+ if (this.component) {
3699
+ this.component.wrap = value;
3700
+ }
3701
+ }
3702
+ /**
3703
+ * Gets whether children wrap onto a new line/column when they overflow the group.
3704
+ * @returns Whether children wrap.
3705
+ */
3706
+ get wrap() {
3707
+ return this._wrap;
3708
+ }
3709
+ static get observedAttributes() {
3710
+ return [
3711
+ ...super.observedAttributes,
3712
+ 'orientation',
3713
+ 'reverse-x',
3714
+ 'reverse-y',
3715
+ 'alignment',
3716
+ 'padding',
3717
+ 'spacing',
3718
+ 'width-fitting',
3719
+ 'height-fitting',
3720
+ 'wrap'
3721
+ ];
3722
+ }
3723
+ attributeChangedCallback(name, _oldValue, newValue) {
3724
+ super.attributeChangedCallback(name, _oldValue, newValue);
3725
+ switch (name) {
3726
+ case 'orientation':
3727
+ this.orientation = parseEnum(newValue, orientations$1, playcanvas.ORIENTATION_HORIZONTAL);
2396
3728
  break;
2397
- case 'enable-markup':
2398
- this.enableMarkup = this.hasAttribute(name);
3729
+ case 'reverse-x':
3730
+ this.reverseX = newValue !== 'false';
2399
3731
  break;
2400
- case 'font-size':
2401
- this.fontSize = Number(newValue);
3732
+ case 'reverse-y':
3733
+ this.reverseY = newValue !== 'false';
2402
3734
  break;
2403
- case 'line-height':
2404
- this.lineHeight = Number(newValue);
3735
+ case 'alignment':
3736
+ this.alignment = parseVec2(newValue);
2405
3737
  break;
2406
- case 'pivot':
2407
- this.pivot = parseVec2(newValue);
3738
+ case 'padding':
3739
+ this.padding = parseVec4(newValue);
2408
3740
  break;
2409
- case 'text':
2410
- this.text = newValue;
3741
+ case 'spacing':
3742
+ this.spacing = parseVec2(newValue);
2411
3743
  break;
2412
- case 'type':
2413
- this.type = newValue;
3744
+ case 'width-fitting':
3745
+ this.widthFitting = parseEnum(newValue, fittings, playcanvas.FITTING_NONE);
2414
3746
  break;
2415
- case 'width':
2416
- this.width = Number(newValue);
3747
+ case 'height-fitting':
3748
+ this.heightFitting = parseEnum(newValue, fittings, playcanvas.FITTING_NONE);
2417
3749
  break;
2418
- case 'wrap-lines':
2419
- this.wrapLines = this.hasAttribute(name);
3750
+ case 'wrap':
3751
+ this.wrap = newValue !== 'false';
2420
3752
  break;
2421
3753
  }
2422
3754
  }
2423
3755
  }
2424
- customElements.define('pc-element', ElementComponentElement);
3756
+ customElements.define('pc-layoutgroup', LayoutGroupComponentElement);
2425
3757
 
2426
3758
  const shadowTypes = new Map([
2427
3759
  ['pcf1-16f', playcanvas.SHADOW_PCF1_16F],
@@ -3610,6 +4942,514 @@ class ScreenComponentElement extends ComponentElement {
3610
4942
  }
3611
4943
  customElements.define('pc-screen', ScreenComponentElement);
3612
4944
 
4945
+ const orientations = new Map([
4946
+ ['horizontal', playcanvas.ORIENTATION_HORIZONTAL],
4947
+ ['vertical', playcanvas.ORIENTATION_VERTICAL]
4948
+ ]);
4949
+ /**
4950
+ * The ScrollbarComponentElement interface provides properties and methods for manipulating
4951
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-scrollbar/ | `<pc-scrollbar>`} elements.
4952
+ * The ScrollbarComponentElement interface also inherits the properties and methods of the
4953
+ * {@link HTMLElement} interface.
4954
+ *
4955
+ * @category Components
4956
+ */
4957
+ class ScrollbarComponentElement extends ComponentElement {
4958
+ /** @ignore */
4959
+ constructor() {
4960
+ super('scrollbar');
4961
+ this._orientation = playcanvas.ORIENTATION_HORIZONTAL;
4962
+ this._value = 0;
4963
+ this._handleSize = 0.5;
4964
+ this._handle = '';
4965
+ }
4966
+ getInitialComponentData() {
4967
+ const data = {
4968
+ orientation: this._orientation,
4969
+ value: this._value,
4970
+ handleSize: this._handleSize
4971
+ };
4972
+ const handle = getEntity(this._handle);
4973
+ if (handle) {
4974
+ data.handleEntity = handle;
4975
+ }
4976
+ return data;
4977
+ }
4978
+ /**
4979
+ * Gets the underlying PlayCanvas scrollbar component.
4980
+ * @returns The scrollbar component.
4981
+ */
4982
+ get component() {
4983
+ return super.component;
4984
+ }
4985
+ /**
4986
+ * Sets the orientation of the scrollbar. Can be `horizontal` (0) or `vertical` (1).
4987
+ * @param value - The orientation.
4988
+ */
4989
+ set orientation(value) {
4990
+ this._orientation = value;
4991
+ if (this.component) {
4992
+ this.component.orientation = value;
4993
+ }
4994
+ }
4995
+ /**
4996
+ * Gets the orientation of the scrollbar.
4997
+ * @returns The orientation.
4998
+ */
4999
+ get orientation() {
5000
+ return this._orientation;
5001
+ }
5002
+ /**
5003
+ * Sets the current position value of the scrollbar, in the range 0 to 1.
5004
+ * @param value - The scrollbar value.
5005
+ */
5006
+ set value(value) {
5007
+ this._value = value;
5008
+ if (this.component) {
5009
+ this.component.value = value;
5010
+ }
5011
+ }
5012
+ /**
5013
+ * Gets the current position value of the scrollbar.
5014
+ * @returns The scrollbar value.
5015
+ */
5016
+ get value() {
5017
+ return this._value;
5018
+ }
5019
+ /**
5020
+ * Sets the size of the handle relative to the size of the track, in the range 0 to 1.
5021
+ * @param value - The handle size.
5022
+ */
5023
+ set handleSize(value) {
5024
+ this._handleSize = value;
5025
+ if (this.component) {
5026
+ this.component.handleSize = value;
5027
+ }
5028
+ }
5029
+ /**
5030
+ * Gets the size of the handle relative to the size of the track.
5031
+ * @returns The handle size.
5032
+ */
5033
+ get handleSize() {
5034
+ return this._handleSize;
5035
+ }
5036
+ /**
5037
+ * Sets the reference (CSS selector, element id or entity name) to the `<pc-entity>` used as the
5038
+ * scrollbar handle.
5039
+ * @param value - The handle entity reference.
5040
+ */
5041
+ set handle(value) {
5042
+ this._handle = value;
5043
+ const entity = getEntity(value);
5044
+ if (this.component && entity) {
5045
+ this.component.handleEntity = entity;
5046
+ }
5047
+ }
5048
+ /**
5049
+ * Gets the reference to the `<pc-entity>` used as the scrollbar handle.
5050
+ * @returns The handle entity reference.
5051
+ */
5052
+ get handle() {
5053
+ return this._handle;
5054
+ }
5055
+ static get observedAttributes() {
5056
+ return [
5057
+ ...super.observedAttributes,
5058
+ 'orientation',
5059
+ 'value',
5060
+ 'handle-size',
5061
+ 'handle'
5062
+ ];
5063
+ }
5064
+ attributeChangedCallback(name, _oldValue, newValue) {
5065
+ super.attributeChangedCallback(name, _oldValue, newValue);
5066
+ switch (name) {
5067
+ case 'orientation':
5068
+ this.orientation = parseEnum(newValue, orientations, playcanvas.ORIENTATION_HORIZONTAL);
5069
+ break;
5070
+ case 'value':
5071
+ this.value = Number(newValue);
5072
+ break;
5073
+ case 'handle-size':
5074
+ this.handleSize = Number(newValue);
5075
+ break;
5076
+ case 'handle':
5077
+ this.handle = newValue;
5078
+ break;
5079
+ }
5080
+ }
5081
+ }
5082
+ customElements.define('pc-scrollbar', ScrollbarComponentElement);
5083
+
5084
+ const scrollModes = new Map([
5085
+ ['clamp', playcanvas.SCROLL_MODE_CLAMP],
5086
+ ['bounce', playcanvas.SCROLL_MODE_BOUNCE],
5087
+ ['infinite', playcanvas.SCROLL_MODE_INFINITE]
5088
+ ]);
5089
+ const visibilities = new Map([
5090
+ ['always', playcanvas.SCROLLBAR_VISIBILITY_SHOW_ALWAYS],
5091
+ ['when-required', playcanvas.SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED]
5092
+ ]);
5093
+ /**
5094
+ * The ScrollViewComponentElement interface provides properties and methods for manipulating
5095
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-scrollview/ | `<pc-scrollview>`} elements.
5096
+ * The ScrollViewComponentElement interface also inherits the properties and methods of the
5097
+ * {@link HTMLElement} interface.
5098
+ *
5099
+ * @category Components
5100
+ */
5101
+ class ScrollViewComponentElement extends ComponentElement {
5102
+ /** @ignore */
5103
+ constructor() {
5104
+ super('scrollview');
5105
+ this._horizontal = true;
5106
+ this._vertical = true;
5107
+ this._scrollMode = playcanvas.SCROLL_MODE_BOUNCE;
5108
+ this._bounceAmount = 0.1;
5109
+ this._friction = 0.05;
5110
+ this._useMouseWheel = true;
5111
+ this._mouseWheelSensitivity = new playcanvas.Vec2(1, 1);
5112
+ this._horizontalScrollbarVisibility = playcanvas.SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED;
5113
+ this._verticalScrollbarVisibility = playcanvas.SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED;
5114
+ this._viewport = '';
5115
+ this._content = '';
5116
+ this._horizontalScrollbar = '';
5117
+ this._verticalScrollbar = '';
5118
+ }
5119
+ getInitialComponentData() {
5120
+ const data = {
5121
+ horizontal: this._horizontal,
5122
+ vertical: this._vertical,
5123
+ scrollMode: this._scrollMode,
5124
+ bounceAmount: this._bounceAmount,
5125
+ friction: this._friction,
5126
+ useMouseWheel: this._useMouseWheel,
5127
+ mouseWheelSensitivity: this._mouseWheelSensitivity,
5128
+ horizontalScrollbarVisibility: this._horizontalScrollbarVisibility,
5129
+ verticalScrollbarVisibility: this._verticalScrollbarVisibility
5130
+ };
5131
+ const viewport = getEntity(this._viewport);
5132
+ if (viewport) {
5133
+ data.viewportEntity = viewport;
5134
+ }
5135
+ const content = getEntity(this._content);
5136
+ if (content) {
5137
+ data.contentEntity = content;
5138
+ }
5139
+ const horizontalScrollbar = getEntity(this._horizontalScrollbar);
5140
+ if (horizontalScrollbar) {
5141
+ data.horizontalScrollbarEntity = horizontalScrollbar;
5142
+ }
5143
+ const verticalScrollbar = getEntity(this._verticalScrollbar);
5144
+ if (verticalScrollbar) {
5145
+ data.verticalScrollbarEntity = verticalScrollbar;
5146
+ }
5147
+ return data;
5148
+ }
5149
+ /**
5150
+ * Gets the underlying PlayCanvas scroll view component.
5151
+ * @returns The scroll view component.
5152
+ */
5153
+ get component() {
5154
+ return super.component;
5155
+ }
5156
+ /**
5157
+ * Sets whether horizontal scrolling is enabled.
5158
+ * @param value - Whether horizontal scrolling is enabled.
5159
+ */
5160
+ set horizontal(value) {
5161
+ this._horizontal = value;
5162
+ if (this.component) {
5163
+ this.component.horizontal = value;
5164
+ }
5165
+ }
5166
+ /**
5167
+ * Gets whether horizontal scrolling is enabled.
5168
+ * @returns Whether horizontal scrolling is enabled.
5169
+ */
5170
+ get horizontal() {
5171
+ return this._horizontal;
5172
+ }
5173
+ /**
5174
+ * Sets whether vertical scrolling is enabled.
5175
+ * @param value - Whether vertical scrolling is enabled.
5176
+ */
5177
+ set vertical(value) {
5178
+ this._vertical = value;
5179
+ if (this.component) {
5180
+ this.component.vertical = value;
5181
+ }
5182
+ }
5183
+ /**
5184
+ * Gets whether vertical scrolling is enabled.
5185
+ * @returns Whether vertical scrolling is enabled.
5186
+ */
5187
+ get vertical() {
5188
+ return this._vertical;
5189
+ }
5190
+ /**
5191
+ * Sets how the scroll view should behave when the content is scrolled beyond its bounds. Can be
5192
+ * `clamp` (0), `bounce` (1) or `infinite` (2).
5193
+ * @param value - The scroll mode.
5194
+ */
5195
+ set scrollMode(value) {
5196
+ this._scrollMode = value;
5197
+ if (this.component) {
5198
+ this.component.scrollMode = value;
5199
+ }
5200
+ }
5201
+ /**
5202
+ * Gets how the scroll view behaves when the content is scrolled beyond its bounds.
5203
+ * @returns The scroll mode.
5204
+ */
5205
+ get scrollMode() {
5206
+ return this._scrollMode;
5207
+ }
5208
+ /**
5209
+ * Sets how far the content is allowed to bounce beyond its bounds when `scroll-mode` is
5210
+ * `bounce`, in the range 0 to 1.
5211
+ * @param value - The bounce amount.
5212
+ */
5213
+ set bounceAmount(value) {
5214
+ this._bounceAmount = value;
5215
+ if (this.component) {
5216
+ this.component.bounceAmount = value;
5217
+ }
5218
+ }
5219
+ /**
5220
+ * Gets the bounce amount.
5221
+ * @returns The bounce amount.
5222
+ */
5223
+ get bounceAmount() {
5224
+ return this._bounceAmount;
5225
+ }
5226
+ /**
5227
+ * Sets how freely the content moves once thrown, in the range 0 (no friction) to 1.
5228
+ * @param value - The friction.
5229
+ */
5230
+ set friction(value) {
5231
+ this._friction = value;
5232
+ if (this.component) {
5233
+ this.component.friction = value;
5234
+ }
5235
+ }
5236
+ /**
5237
+ * Gets the friction.
5238
+ * @returns The friction.
5239
+ */
5240
+ get friction() {
5241
+ return this._friction;
5242
+ }
5243
+ /**
5244
+ * Sets whether the scroll view responds to mouse wheel events.
5245
+ * @param value - Whether to use the mouse wheel.
5246
+ */
5247
+ set useMouseWheel(value) {
5248
+ this._useMouseWheel = value;
5249
+ if (this.component) {
5250
+ this.component.useMouseWheel = value;
5251
+ }
5252
+ }
5253
+ /**
5254
+ * Gets whether the scroll view responds to mouse wheel events.
5255
+ * @returns Whether the mouse wheel is used.
5256
+ */
5257
+ get useMouseWheel() {
5258
+ return this._useMouseWheel;
5259
+ }
5260
+ /**
5261
+ * Sets the mouse wheel sensitivity as a Vec2 (horizontal, vertical). A value of 0 on an axis
5262
+ * disables mouse wheel scrolling for that axis.
5263
+ * @param value - The mouse wheel sensitivity.
5264
+ */
5265
+ set mouseWheelSensitivity(value) {
5266
+ this._mouseWheelSensitivity = value;
5267
+ if (this.component) {
5268
+ this.component.mouseWheelSensitivity = value;
5269
+ }
5270
+ }
5271
+ /**
5272
+ * Gets the mouse wheel sensitivity.
5273
+ * @returns The mouse wheel sensitivity.
5274
+ */
5275
+ get mouseWheelSensitivity() {
5276
+ return this._mouseWheelSensitivity;
5277
+ }
5278
+ /**
5279
+ * Sets the visibility of the horizontal scrollbar. Can be `always` (0) or `when-required` (1).
5280
+ * @param value - The horizontal scrollbar visibility.
5281
+ */
5282
+ set horizontalScrollbarVisibility(value) {
5283
+ this._horizontalScrollbarVisibility = value;
5284
+ if (this.component) {
5285
+ this.component.horizontalScrollbarVisibility = value;
5286
+ }
5287
+ }
5288
+ /**
5289
+ * Gets the visibility of the horizontal scrollbar.
5290
+ * @returns The horizontal scrollbar visibility.
5291
+ */
5292
+ get horizontalScrollbarVisibility() {
5293
+ return this._horizontalScrollbarVisibility;
5294
+ }
5295
+ /**
5296
+ * Sets the visibility of the vertical scrollbar. Can be `always` (0) or `when-required` (1).
5297
+ * @param value - The vertical scrollbar visibility.
5298
+ */
5299
+ set verticalScrollbarVisibility(value) {
5300
+ this._verticalScrollbarVisibility = value;
5301
+ if (this.component) {
5302
+ this.component.verticalScrollbarVisibility = value;
5303
+ }
5304
+ }
5305
+ /**
5306
+ * Gets the visibility of the vertical scrollbar.
5307
+ * @returns The vertical scrollbar visibility.
5308
+ */
5309
+ get verticalScrollbarVisibility() {
5310
+ return this._verticalScrollbarVisibility;
5311
+ }
5312
+ /**
5313
+ * Sets the reference (CSS selector, element id or entity name) to the `<pc-entity>` used as the
5314
+ * viewport, which clips the content to the scroll view's bounds.
5315
+ * @param value - The viewport entity reference.
5316
+ */
5317
+ set viewport(value) {
5318
+ this._viewport = value;
5319
+ const entity = getEntity(value);
5320
+ if (this.component && entity) {
5321
+ this.component.viewportEntity = entity;
5322
+ }
5323
+ }
5324
+ /**
5325
+ * Gets the reference to the `<pc-entity>` used as the viewport.
5326
+ * @returns The viewport entity reference.
5327
+ */
5328
+ get viewport() {
5329
+ return this._viewport;
5330
+ }
5331
+ /**
5332
+ * Sets the reference (CSS selector, element id or entity name) to the `<pc-entity>` used as the
5333
+ * content, which is moved as the scroll view is scrolled.
5334
+ * @param value - The content entity reference.
5335
+ */
5336
+ set content(value) {
5337
+ this._content = value;
5338
+ const entity = getEntity(value);
5339
+ if (this.component && entity) {
5340
+ this.component.contentEntity = entity;
5341
+ }
5342
+ }
5343
+ /**
5344
+ * Gets the reference to the `<pc-entity>` used as the content.
5345
+ * @returns The content entity reference.
5346
+ */
5347
+ get content() {
5348
+ return this._content;
5349
+ }
5350
+ /**
5351
+ * Sets the reference (CSS selector, element id or entity name) to the `<pc-entity>` containing
5352
+ * the horizontal `<pc-scrollbar>`.
5353
+ * @param value - The horizontal scrollbar entity reference.
5354
+ */
5355
+ set horizontalScrollbar(value) {
5356
+ this._horizontalScrollbar = value;
5357
+ const entity = getEntity(value);
5358
+ if (this.component && entity) {
5359
+ this.component.horizontalScrollbarEntity = entity;
5360
+ }
5361
+ }
5362
+ /**
5363
+ * Gets the reference to the `<pc-entity>` containing the horizontal scrollbar.
5364
+ * @returns The horizontal scrollbar entity reference.
5365
+ */
5366
+ get horizontalScrollbar() {
5367
+ return this._horizontalScrollbar;
5368
+ }
5369
+ /**
5370
+ * Sets the reference (CSS selector, element id or entity name) to the `<pc-entity>` containing
5371
+ * the vertical `<pc-scrollbar>`.
5372
+ * @param value - The vertical scrollbar entity reference.
5373
+ */
5374
+ set verticalScrollbar(value) {
5375
+ this._verticalScrollbar = value;
5376
+ const entity = getEntity(value);
5377
+ if (this.component && entity) {
5378
+ this.component.verticalScrollbarEntity = entity;
5379
+ }
5380
+ }
5381
+ /**
5382
+ * Gets the reference to the `<pc-entity>` containing the vertical scrollbar.
5383
+ * @returns The vertical scrollbar entity reference.
5384
+ */
5385
+ get verticalScrollbar() {
5386
+ return this._verticalScrollbar;
5387
+ }
5388
+ static get observedAttributes() {
5389
+ return [
5390
+ ...super.observedAttributes,
5391
+ 'horizontal',
5392
+ 'vertical',
5393
+ 'scroll-mode',
5394
+ 'bounce-amount',
5395
+ 'friction',
5396
+ 'use-mouse-wheel',
5397
+ 'mouse-wheel-sensitivity',
5398
+ 'horizontal-scrollbar-visibility',
5399
+ 'vertical-scrollbar-visibility',
5400
+ 'viewport',
5401
+ 'content',
5402
+ 'horizontal-scrollbar',
5403
+ 'vertical-scrollbar'
5404
+ ];
5405
+ }
5406
+ attributeChangedCallback(name, _oldValue, newValue) {
5407
+ super.attributeChangedCallback(name, _oldValue, newValue);
5408
+ switch (name) {
5409
+ case 'horizontal':
5410
+ this.horizontal = newValue !== 'false';
5411
+ break;
5412
+ case 'vertical':
5413
+ this.vertical = newValue !== 'false';
5414
+ break;
5415
+ case 'scroll-mode':
5416
+ this.scrollMode = parseEnum(newValue, scrollModes, playcanvas.SCROLL_MODE_BOUNCE);
5417
+ break;
5418
+ case 'bounce-amount':
5419
+ this.bounceAmount = Number(newValue);
5420
+ break;
5421
+ case 'friction':
5422
+ this.friction = Number(newValue);
5423
+ break;
5424
+ case 'use-mouse-wheel':
5425
+ this.useMouseWheel = newValue !== 'false';
5426
+ break;
5427
+ case 'mouse-wheel-sensitivity':
5428
+ this.mouseWheelSensitivity = parseVec2(newValue);
5429
+ break;
5430
+ case 'horizontal-scrollbar-visibility':
5431
+ this.horizontalScrollbarVisibility = parseEnum(newValue, visibilities, playcanvas.SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED);
5432
+ break;
5433
+ case 'vertical-scrollbar-visibility':
5434
+ this.verticalScrollbarVisibility = parseEnum(newValue, visibilities, playcanvas.SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED);
5435
+ break;
5436
+ case 'viewport':
5437
+ this.viewport = newValue;
5438
+ break;
5439
+ case 'content':
5440
+ this.content = newValue;
5441
+ break;
5442
+ case 'horizontal-scrollbar':
5443
+ this.horizontalScrollbar = newValue;
5444
+ break;
5445
+ case 'vertical-scrollbar':
5446
+ this.verticalScrollbar = newValue;
5447
+ break;
5448
+ }
5449
+ }
5450
+ }
5451
+ customElements.define('pc-scrollview', ScrollViewComponentElement);
5452
+
3613
5453
  /**
3614
5454
  * The ScriptComponentElement interface provides properties and methods for manipulating
3615
5455
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-scripts/ | `<pc-scripts>`} elements.
@@ -5040,12 +6880,15 @@ customElements.define('pc-sky', SkyElement);
5040
6880
  exports.AppElement = AppElement;
5041
6881
  exports.AssetElement = AssetElement;
5042
6882
  exports.AsyncElement = AsyncElement;
6883
+ exports.ButtonComponentElement = ButtonComponentElement;
5043
6884
  exports.CameraComponentElement = CameraComponentElement;
5044
6885
  exports.CollisionComponentElement = CollisionComponentElement;
5045
6886
  exports.ComponentElement = ComponentElement;
5046
6887
  exports.ElementComponentElement = ElementComponentElement;
5047
6888
  exports.EntityElement = EntityElement;
5048
6889
  exports.GSplatComponentElement = GSplatComponentElement;
6890
+ exports.LayoutChildComponentElement = LayoutChildComponentElement;
6891
+ exports.LayoutGroupComponentElement = LayoutGroupComponentElement;
5049
6892
  exports.LightComponentElement = LightComponentElement;
5050
6893
  exports.ListenerComponentElement = ListenerComponentElement;
5051
6894
  exports.MaterialElement = MaterialElement;
@@ -5058,6 +6901,8 @@ exports.SceneElement = SceneElement;
5058
6901
  exports.ScreenComponentElement = ScreenComponentElement;
5059
6902
  exports.ScriptComponentElement = ScriptComponentElement;
5060
6903
  exports.ScriptElement = ScriptElement;
6904
+ exports.ScrollViewComponentElement = ScrollViewComponentElement;
6905
+ exports.ScrollbarComponentElement = ScrollbarComponentElement;
5061
6906
  exports.SkyElement = SkyElement;
5062
6907
  exports.SoundComponentElement = SoundComponentElement;
5063
6908
  exports.SoundSlotElement = SoundSlotElement;