@playcanvas/web-components 0.9.0 → 0.10.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.
Files changed (72) hide show
  1. package/README.md +18 -0
  2. package/dist/app.d.ts +3 -2
  3. package/dist/asset.d.ts +16 -1
  4. package/dist/async-element.d.ts +3 -0
  5. package/dist/components/button-component.d.ts +1 -1
  6. package/dist/components/camera-component.d.ts +1 -1
  7. package/dist/components/collision-component.d.ts +1 -1
  8. package/dist/components/component.d.ts +1 -1
  9. package/dist/components/element-component.d.ts +1 -1
  10. package/dist/components/gsplat-component.d.ts +1 -1
  11. package/dist/components/layoutchild-component.d.ts +1 -1
  12. package/dist/components/layoutgroup-component.d.ts +1 -1
  13. package/dist/components/light-component.d.ts +1 -1
  14. package/dist/components/particlesystem-component.d.ts +1 -1
  15. package/dist/components/render-component.d.ts +1 -1
  16. package/dist/components/rigidbody-component.d.ts +1 -1
  17. package/dist/components/screen-component.d.ts +1 -1
  18. package/dist/components/script.d.ts +8 -1
  19. package/dist/components/scrollbar-component.d.ts +1 -1
  20. package/dist/components/scrollview-component.d.ts +1 -1
  21. package/dist/components/sound-component.d.ts +1 -1
  22. package/dist/components/sound-slot.d.ts +9 -1
  23. package/dist/custom-elements.json +16231 -0
  24. package/dist/entity.d.ts +19 -1
  25. package/dist/material.d.ts +966 -4
  26. package/dist/model.d.ts +1 -1
  27. package/dist/module.d.ts +10 -0
  28. package/dist/{utils.d.ts → parse.d.ts} +63 -33
  29. package/dist/pwc.cjs +2677 -586
  30. package/dist/pwc.cjs.map +1 -1
  31. package/dist/pwc.js +2677 -586
  32. package/dist/pwc.js.map +1 -1
  33. package/dist/pwc.min.js +1 -1
  34. package/dist/pwc.min.js.map +1 -1
  35. package/dist/pwc.min.mjs +2 -0
  36. package/dist/pwc.min.mjs.map +1 -0
  37. package/dist/pwc.mjs +2678 -587
  38. package/dist/pwc.mjs.map +1 -1
  39. package/dist/scene.d.ts +1 -1
  40. package/dist/sky.d.ts +1 -1
  41. package/dist/vscode.html-custom-data.json +1795 -0
  42. package/dist/web-types.json +3592 -0
  43. package/package.json +29 -11
  44. package/src/app.ts +6 -5
  45. package/src/asset.ts +19 -2
  46. package/src/async-element.ts +3 -0
  47. package/src/components/button-component.ts +6 -6
  48. package/src/components/camera-component.ts +2 -2
  49. package/src/components/collision-component.ts +2 -2
  50. package/src/components/component.ts +2 -2
  51. package/src/components/element-component.ts +6 -6
  52. package/src/components/gsplat-component.ts +3 -3
  53. package/src/components/layoutchild-component.ts +2 -2
  54. package/src/components/layoutgroup-component.ts +2 -2
  55. package/src/components/light-component.ts +2 -2
  56. package/src/components/particlesystem-component.ts +2 -2
  57. package/src/components/render-component.ts +10 -5
  58. package/src/components/rigidbody-component.ts +2 -2
  59. package/src/components/screen-component.ts +2 -2
  60. package/src/components/script-component.ts +4 -4
  61. package/src/components/script.ts +9 -2
  62. package/src/components/scrollbar-component.ts +3 -3
  63. package/src/components/scrollview-component.ts +6 -6
  64. package/src/components/sound-component.ts +2 -2
  65. package/src/components/sound-slot.ts +31 -9
  66. package/src/entity.ts +25 -7
  67. package/src/material.ts +2396 -59
  68. package/src/model.ts +2 -2
  69. package/src/module.ts +10 -0
  70. package/src/{utils.ts → parse.ts} +104 -65
  71. package/src/scene.ts +2 -2
  72. package/src/sky.ts +3 -3
package/README.md CHANGED
@@ -38,6 +38,24 @@ See PlayCanvas Web Components in action here: https://playcanvas.github.io/web-c
38
38
 
39
39
  Please see the [Getting Started Guide](https://developer.playcanvas.com/user-manual/web-components/getting-started/) for installation and usage instructions.
40
40
 
41
+ ## Editor Support
42
+
43
+ The package ships a [Custom Elements Manifest](https://github.com/webcomponents/custom-elements-manifest), which editors use to offer tag and attribute completions, valid attribute values and hover documentation when authoring HTML.
44
+
45
+ **VS Code** — add the following to your workspace `.vscode/settings.json`:
46
+
47
+ ```json
48
+ {
49
+ "html.customData": [
50
+ "./node_modules/@playcanvas/web-components/dist/vscode.html-custom-data.json"
51
+ ]
52
+ }
53
+ ```
54
+
55
+ **JetBrains IDEs** (WebStorm, IntelliJ IDEA) — no setup required. The IDE discovers the bundled `web-types.json` automatically.
56
+
57
+ **Other tooling** — the manifest itself is at `@playcanvas/web-components/dist/custom-elements.json` and is declared in the package's `customElements` field, which is how tools such as `lit-analyzer` and Storybook locate it.
58
+
41
59
  ## Development
42
60
 
43
61
  ### Setting Up Local Development
package/dist/app.d.ts CHANGED
@@ -67,7 +67,8 @@ declare class AppElement extends AsyncElement {
67
67
  */
68
68
  get antialias(): boolean;
69
69
  /**
70
- * Sets the graphics backend.
70
+ * Sets the graphics backend. Defaults to 'webgpu', which falls back to 'webgl2' if WebGPU
71
+ * is not supported by the browser.
71
72
  * @param value - The graphics backend ('webgpu', 'webgl2', or 'null').
72
73
  */
73
74
  set backend(value: 'webgpu' | 'webgl2' | 'null');
@@ -114,7 +115,7 @@ declare class AppElement extends AsyncElement {
114
115
  */
115
116
  get stencil(): boolean;
116
117
  static get observedAttributes(): string[];
117
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
118
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
118
119
  }
119
120
  declare global {
120
121
  interface HTMLElementTagNameMap {
package/dist/asset.d.ts CHANGED
@@ -12,6 +12,21 @@ import { AsyncElement } from './async-element';
12
12
  * while the application is running are created and registered on insertion, and begin loading
13
13
  * immediately unless `lazy`. A `pc-asset` must be a direct child of `pc-app` — elements placed
14
14
  * elsewhere, or with an unsupported asset type, never become ready.
15
+ *
16
+ * Apart from `lazy`, these attributes are read once when the asset is created, so changing them
17
+ * later has no effect.
18
+ *
19
+ * @attribute {string} id - The identifier used to reference the asset from other elements.
20
+ * @attribute {string} src - The URL of the asset to load.
21
+ * @attribute {string} type - The asset type. Inferred from the `src` file extension when omitted.
22
+ * @attribute {string} data - Additional asset data, as a JSON object.
23
+ * @attribute {string} atlas - For a `sprite` asset, the `id` of the texture atlas asset it uses.
24
+ * The atlas must be declared before the sprite.
25
+ * @attribute {string} frame-keys - For a `sprite` asset, the atlas frame keys it uses, separated
26
+ * by spaces or commas.
27
+ * @attribute {number} pixels-per-unit - For a `sprite` asset, the number of pixels per world unit.
28
+ * @attribute {'simple' | 'sliced' | 'tiled'} render-mode - For a `sprite` asset, how the sprite is
29
+ * rendered when resized.
15
30
  */
16
31
  declare class AssetElement extends AsyncElement {
17
32
  private _lazy;
@@ -44,7 +59,7 @@ declare class AssetElement extends AsyncElement {
44
59
  get lazy(): boolean;
45
60
  static get(id: string): Asset | null | undefined;
46
61
  static get observedAttributes(): string[];
47
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
62
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
48
63
  }
49
64
  declare global {
50
65
  interface HTMLElementTagNameMap {
@@ -2,6 +2,9 @@ import { AppElement } from './app';
2
2
  import { EntityElement } from './entity';
3
3
  /**
4
4
  * Base class for all PlayCanvas Web Components that initialize asynchronously.
5
+ *
6
+ * @fires {CustomEvent} ready - Fired once the element is fully initialized. Bubbles and is
7
+ * composed.
5
8
  */
6
9
  declare class AsyncElement extends HTMLElement {
7
10
  private _readyPromise;
@@ -180,7 +180,7 @@ declare class ButtonComponentElement extends ComponentElement {
180
180
  */
181
181
  get inactiveSpriteFrame(): number;
182
182
  static get observedAttributes(): string[];
183
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
183
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
184
184
  }
185
185
  declare global {
186
186
  interface HTMLElementTagNameMap {
@@ -247,7 +247,7 @@ declare class CameraComponentElement extends ComponentElement {
247
247
  */
248
248
  get tonemap(): 'none' | 'linear' | 'filmic' | 'hejl' | 'aces' | 'aces2' | 'neutral';
249
249
  static get observedAttributes(): string[];
250
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
250
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
251
251
  }
252
252
  declare global {
253
253
  interface HTMLElementTagNameMap {
@@ -51,7 +51,7 @@ declare class CollisionComponentElement extends ComponentElement {
51
51
  set type(value: 'box' | 'capsule' | 'compound' | 'cone' | 'cylinder' | 'mesh' | 'sphere');
52
52
  get type(): "box" | "capsule" | "compound" | "cone" | "cylinder" | "mesh" | "sphere";
53
53
  static get observedAttributes(): string[];
54
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
54
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
55
55
  }
56
56
  declare global {
57
57
  interface HTMLElementTagNameMap {
@@ -39,6 +39,6 @@ declare class ComponentElement extends AsyncElement {
39
39
  */
40
40
  get enabled(): boolean;
41
41
  static get observedAttributes(): string[];
42
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
42
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
43
43
  }
44
44
  export { ComponentElement };
@@ -310,7 +310,7 @@ declare class ElementComponentElement extends ComponentElement {
310
310
  */
311
311
  get maxFontSize(): number;
312
312
  static get observedAttributes(): string[];
313
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
313
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
314
314
  }
315
315
  declare global {
316
316
  interface HTMLElementTagNameMap {
@@ -103,7 +103,7 @@ declare class GSplatComponentElement extends ComponentElement {
103
103
  */
104
104
  get lodRangeMax(): number;
105
105
  static get observedAttributes(): string[];
106
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
106
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
107
107
  }
108
108
  declare global {
109
109
  interface HTMLElementTagNameMap {
@@ -105,7 +105,7 @@ declare class LayoutChildComponentElement extends ComponentElement {
105
105
  */
106
106
  get excludeFromLayout(): boolean;
107
107
  static get observedAttributes(): string[];
108
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
108
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
109
109
  }
110
110
  declare global {
111
111
  interface HTMLElementTagNameMap {
@@ -130,7 +130,7 @@ declare class LayoutGroupComponentElement extends ComponentElement {
130
130
  */
131
131
  get wrap(): boolean;
132
132
  static get observedAttributes(): string[];
133
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
133
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
134
134
  }
135
135
  declare global {
136
136
  interface HTMLElementTagNameMap {
@@ -258,7 +258,7 @@ declare class LightComponentElement extends ComponentElement {
258
258
  */
259
259
  get shadowBlockerSamples(): number;
260
260
  static get observedAttributes(): string[];
261
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
261
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
262
262
  }
263
263
  declare global {
264
264
  interface HTMLElementTagNameMap {
@@ -47,7 +47,7 @@ declare class ParticleSystemComponentElement extends ComponentElement {
47
47
  */
48
48
  stop(): void;
49
49
  static get observedAttributes(): string[];
50
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
50
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
51
51
  }
52
52
  declare global {
53
53
  interface HTMLElementTagNameMap {
@@ -71,7 +71,7 @@ declare class RenderComponentElement extends ComponentElement {
71
71
  */
72
72
  get receiveShadows(): boolean;
73
73
  static get observedAttributes(): string[];
74
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
74
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
75
75
  }
76
76
  declare global {
77
77
  interface HTMLElementTagNameMap {
@@ -82,7 +82,7 @@ declare class RigidBodyComponentElement extends ComponentElement {
82
82
  set type(value: 'static' | 'dynamic' | 'kinematic');
83
83
  get type(): "static" | "dynamic" | "kinematic";
84
84
  static get observedAttributes(): string[];
85
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
85
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
86
86
  }
87
87
  declare global {
88
88
  interface HTMLElementTagNameMap {
@@ -43,7 +43,7 @@ declare class ScreenComponentElement extends ComponentElement {
43
43
  set screenSpace(value: boolean);
44
44
  get screenSpace(): boolean;
45
45
  static get observedAttributes(): string[];
46
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
46
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
47
47
  }
48
48
  declare global {
49
49
  interface HTMLElementTagNameMap {
@@ -25,6 +25,13 @@ import { AsyncElement } from '../async-element';
25
25
  *
26
26
  * The element becomes ready once its script instance has been created by the parent
27
27
  * `<pc-scripts>` element.
28
+ *
29
+ * @fires {CustomEvent} scriptattributeschange - Fired when the script's attributes change. The
30
+ * `detail` carries the new `attributes` object. Bubbles.
31
+ * @fires {CustomEvent} scriptenablechange - Fired when the script's enabled state changes. The
32
+ * `detail` carries the new `enabled` state. Bubbles.
33
+ * @fires {CustomEvent} scriptnamechange - Fired when the script is renamed on a live element. The
34
+ * `detail` carries `oldName` and `newName`. Bubbles.
28
35
  */
29
36
  declare class ScriptElement extends AsyncElement {
30
37
  private _attributes;
@@ -97,7 +104,7 @@ declare class ScriptElement extends AsyncElement {
97
104
  */
98
105
  _onScriptCreated(): void;
99
106
  static get observedAttributes(): string[];
100
- attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
107
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
101
108
  }
102
109
  declare global {
103
110
  interface HTMLElementTagNameMap {
@@ -64,7 +64,7 @@ declare class ScrollbarComponentElement extends ComponentElement {
64
64
  */
65
65
  get handle(): string;
66
66
  static get observedAttributes(): string[];
67
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
67
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
68
68
  }
69
69
  declare global {
70
70
  interface HTMLElementTagNameMap {
@@ -170,7 +170,7 @@ declare class ScrollViewComponentElement extends ComponentElement {
170
170
  */
171
171
  get verticalScrollbar(): string;
172
172
  static get observedAttributes(): string[];
173
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
173
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
174
174
  }
175
175
  declare global {
176
176
  interface HTMLElementTagNameMap {
@@ -103,7 +103,7 @@ declare class SoundComponentElement extends ComponentElement {
103
103
  */
104
104
  get volume(): number;
105
105
  static get observedAttributes(): string[];
106
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
106
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
107
107
  }
108
108
  declare global {
109
109
  interface HTMLElementTagNameMap {
@@ -16,6 +16,14 @@ declare class SoundSlotElement extends AsyncElement {
16
16
  private _pitch;
17
17
  private _startTime;
18
18
  private _volume;
19
+ /**
20
+ * The `<pc-sounds>` this slot was added to, captured at connect time.
21
+ *
22
+ * `disconnectedCallback` cannot rediscover it: by the time the element is disconnected its
23
+ * `parentElement` is already `null`, so a lookup would both fail to find the component and
24
+ * emit a misleading "must be a direct child" warning for what is an ordinary removal.
25
+ */
26
+ private _soundElement;
19
27
  /**
20
28
  * The sound slot.
21
29
  */
@@ -114,7 +122,7 @@ declare class SoundSlotElement extends AsyncElement {
114
122
  */
115
123
  get volume(): number;
116
124
  static get observedAttributes(): string[];
117
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
125
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
118
126
  }
119
127
  declare global {
120
128
  interface HTMLElementTagNameMap {