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