@playcanvas/web-components 0.10.1 → 0.11.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.
Files changed (78) hide show
  1. package/README.md +1 -1
  2. package/dist/app.d.ts +102 -51
  3. package/dist/asset.d.ts +8 -7
  4. package/dist/async-element.d.ts +21 -5
  5. package/dist/components/button-component.d.ts +3 -7
  6. package/dist/components/camera-component.d.ts +16 -20
  7. package/dist/components/collision-component.d.ts +3 -7
  8. package/dist/components/component.d.ts +22 -4
  9. package/dist/components/element-component.d.ts +4 -8
  10. package/dist/components/gsplat-component.d.ts +2 -7
  11. package/dist/components/layoutchild-component.d.ts +2 -7
  12. package/dist/components/layoutgroup-component.d.ts +3 -7
  13. package/dist/components/light-component.d.ts +3 -7
  14. package/dist/components/listener-component.d.ts +1 -6
  15. package/dist/components/particlesystem-component.d.ts +2 -7
  16. package/dist/components/render-component.d.ts +2 -7
  17. package/dist/components/rigidbody-component.d.ts +3 -7
  18. package/dist/components/screen-component.d.ts +28 -11
  19. package/dist/components/script-component.d.ts +8 -20
  20. package/dist/components/script.d.ts +2 -22
  21. package/dist/components/scrollbar-component.d.ts +2 -7
  22. package/dist/components/scrollview-component.d.ts +9 -11
  23. package/dist/components/sound-component.d.ts +2 -7
  24. package/dist/components/sound-slot.d.ts +8 -6
  25. package/dist/custom-elements.json +5191 -10695
  26. package/dist/entity.d.ts +16 -9
  27. package/dist/index.d.ts +37 -0
  28. package/dist/material.d.ts +12 -12
  29. package/dist/model.d.ts +21 -5
  30. package/dist/module.d.ts +0 -6
  31. package/dist/parse.d.ts +6 -3
  32. package/dist/pwc.cjs +799 -287
  33. package/dist/pwc.cjs.map +1 -1
  34. package/dist/pwc.js +799 -287
  35. package/dist/pwc.js.map +1 -1
  36. package/dist/pwc.min.js +1 -1
  37. package/dist/pwc.min.js.map +1 -1
  38. package/dist/pwc.min.mjs +1 -1
  39. package/dist/pwc.min.mjs.map +1 -1
  40. package/dist/pwc.mjs +800 -288
  41. package/dist/pwc.mjs.map +1 -1
  42. package/dist/scene.d.ts +4 -7
  43. package/dist/sky.d.ts +25 -16
  44. package/dist/vscode.html-custom-data.json +65 -45
  45. package/dist/web-types.json +585 -557
  46. package/package.json +8 -7
  47. package/src/app.ts +326 -144
  48. package/src/asset.ts +34 -28
  49. package/src/async-element.ts +34 -8
  50. package/src/components/button-component.ts +5 -9
  51. package/src/components/camera-component.ts +55 -36
  52. package/src/components/collision-component.ts +26 -15
  53. package/src/components/component.ts +58 -8
  54. package/src/components/element-component.ts +26 -30
  55. package/src/components/gsplat-component.ts +4 -9
  56. package/src/components/layoutchild-component.ts +4 -9
  57. package/src/components/layoutgroup-component.ts +14 -9
  58. package/src/components/light-component.ts +42 -12
  59. package/src/components/listener-component.ts +1 -7
  60. package/src/components/particlesystem-component.ts +7 -15
  61. package/src/components/render-component.ts +5 -10
  62. package/src/components/rigidbody-component.ts +23 -16
  63. package/src/components/screen-component.ts +46 -20
  64. package/src/components/script-component.ts +108 -46
  65. package/src/components/script.ts +38 -33
  66. package/src/components/scrollbar-component.ts +6 -16
  67. package/src/components/scrollview-component.ts +22 -15
  68. package/src/components/sound-component.ts +10 -15
  69. package/src/components/sound-slot.ts +30 -20
  70. package/src/entity.ts +75 -34
  71. package/src/index.ts +45 -1
  72. package/src/loading-bar.ts +8 -8
  73. package/src/material.ts +63 -37
  74. package/src/model.ts +69 -14
  75. package/src/module.ts +8 -7
  76. package/src/parse.ts +67 -20
  77. package/src/scene.ts +12 -9
  78. package/src/sky.ts +76 -34
package/dist/entity.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AppBase, Entity, Vec3 } from 'playcanvas';
1
+ import { Entity, Vec3 } from 'playcanvas';
2
2
  import { AsyncElement } from './async-element';
3
3
  /**
4
4
  * The EntityElement interface provides properties and methods for manipulating
@@ -62,6 +62,11 @@ declare class EntityElement extends AsyncElement {
62
62
  */
63
63
  private _built;
64
64
  private _entity;
65
+ /**
66
+ * The application element this entity is registered with, cached at creation time so the
67
+ * entity can be unregistered even once this element has left the DOM.
68
+ */
69
+ private _appElement;
65
70
  /**
66
71
  * The PlayCanvas entity instance. `null` until the element is ready, and again once it has
67
72
  * been removed from the document — await {@link whenReady} or the element's `ready()`
@@ -69,8 +74,16 @@ declare class EntityElement extends AsyncElement {
69
74
  * @returns The entity instance, or `null`.
70
75
  */
71
76
  get entity(): Entity | null;
72
- createEntity(app: AppBase): void;
73
- buildHierarchy(app: AppBase): void;
77
+ /**
78
+ * Handles the destruction of the backing entity. Resets the element so a later re-insertion
79
+ * starts clean: `_built` must be cleared alongside `_entity`, or _buildHierarchy would bail
80
+ * and a re-created entity would never be parented. Readiness is re-armed for the same
81
+ * reason — with the entity gone, a resolved ready promise would resume its awaiters against
82
+ * a null `entity`.
83
+ *
84
+ * @param entity - The entity that was destroyed.
85
+ */
86
+ private _onEntityDestroy;
74
87
  connectedCallback(): void;
75
88
  disconnectedCallback(): void;
76
89
  /**
@@ -149,11 +162,5 @@ declare class EntityElement extends AsyncElement {
149
162
  attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
150
163
  addEventListener(type: string, listener: EventListener, options?: boolean | AddEventListenerOptions): void;
151
164
  removeEventListener(type: string, listener: EventListener, options?: boolean | EventListenerOptions): void;
152
- hasListeners(type: string): boolean;
153
- }
154
- declare global {
155
- interface HTMLElementTagNameMap {
156
- 'pc-entity': EntityElement;
157
- }
158
165
  }
159
166
  export { EntityElement };
package/dist/index.d.ts CHANGED
@@ -35,5 +35,42 @@ import { MaterialElement } from './material';
35
35
  import { ModelElement } from './model';
36
36
  import { SceneElement } from './scene';
37
37
  import { SkyElement } from './sky';
38
+ import type { ScriptAttributesChangeEvent, ScriptEnableChangeEvent, ScriptNameChangeEvent } from './components/script-component';
39
+ declare global {
40
+ interface HTMLElementEventMap {
41
+ scriptattributeschange: ScriptAttributesChangeEvent;
42
+ scriptenablechange: ScriptEnableChangeEvent;
43
+ scriptnamechange: ScriptNameChangeEvent;
44
+ }
45
+ interface HTMLElementTagNameMap {
46
+ 'pc-app': AppElement;
47
+ 'pc-asset': AssetElement;
48
+ 'pc-button': ButtonComponentElement;
49
+ 'pc-camera': CameraComponentElement;
50
+ 'pc-collision': CollisionComponentElement;
51
+ 'pc-element': ElementComponentElement;
52
+ 'pc-entity': EntityElement;
53
+ 'pc-gsplat': GSplatComponentElement;
54
+ 'pc-layoutchild': LayoutChildComponentElement;
55
+ 'pc-layoutgroup': LayoutGroupComponentElement;
56
+ 'pc-light': LightComponentElement;
57
+ 'pc-listener': ListenerComponentElement;
58
+ 'pc-material': MaterialElement;
59
+ 'pc-model': ModelElement;
60
+ 'pc-module': ModuleElement;
61
+ 'pc-particles': ParticleSystemComponentElement;
62
+ 'pc-render': RenderComponentElement;
63
+ 'pc-rigidbody': RigidBodyComponentElement;
64
+ 'pc-scene': SceneElement;
65
+ 'pc-screen': ScreenComponentElement;
66
+ 'pc-script': ScriptElement;
67
+ 'pc-scripts': ScriptComponentElement;
68
+ 'pc-scrollbar': ScrollbarComponentElement;
69
+ 'pc-scrollview': ScrollViewComponentElement;
70
+ 'pc-sky': SkyElement;
71
+ 'pc-sound': SoundSlotElement;
72
+ 'pc-sounds': SoundComponentElement;
73
+ }
74
+ }
38
75
  export { AsyncElement, ModuleElement, AppElement, EntityElement, AssetElement, ButtonComponentElement, CameraComponentElement, CollisionComponentElement, ComponentElement, ElementComponentElement, LayoutChildComponentElement, LayoutGroupComponentElement, ParticleSystemComponentElement, LightComponentElement, ListenerComponentElement, RenderComponentElement, RigidBodyComponentElement, ScreenComponentElement, ScrollbarComponentElement, ScrollViewComponentElement, ScriptComponentElement, ScriptElement, SoundComponentElement, SoundSlotElement, GSplatComponentElement, MaterialElement, ModelElement, SceneElement, SkyElement, whenReady };
39
76
  export type { AsyncElementTagName } from './async-element';
@@ -6,11 +6,6 @@ type OccludeSpecular = 'none' | 'ao' | 'gloss-dependent';
6
6
  type OpacityDither = 'none' | 'bayer8' | 'bluenoise' | 'ignnoise';
7
7
  type ColorChannel = 'r' | 'g' | 'b' | 'a' | 'rgb';
8
8
  type ScalarChannel = 'r' | 'g' | 'b' | 'a';
9
- /**
10
- * The texture slots a `pc-material` can populate. Each is backed by a `pc-asset` id rather than a
11
- * `Texture`, so the element can be authored before the asset has loaded.
12
- */
13
- type TextureSlot = 'aoMap' | 'diffuseMap' | 'emissiveMap' | 'glossMap' | 'heightMap' | 'metalnessMap' | 'normalMap' | 'opacityMap';
14
9
  /**
15
10
  * The MaterialElement interface provides properties and methods for manipulating
16
11
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-material/ | `<pc-material>`} elements.
@@ -130,9 +125,12 @@ declare class MaterialElement extends HTMLElement {
130
125
  private _mapHandles;
131
126
  private _updateScheduled;
132
127
  private _glossConflictWarned;
128
+ /**
129
+ * The material. `null` until the containing application has created it — an element present
130
+ * at startup has its material once the application is ready.
131
+ */
133
132
  material: StandardMaterial | null;
134
133
  connectedCallback(): Promise<void>;
135
- createMaterial(): void;
136
134
  disconnectedCallback(): void;
137
135
  /**
138
136
  * Coalesces `material.update()` across a burst of attribute or property writes, so that setting
@@ -159,7 +157,7 @@ declare class MaterialElement extends HTMLElement {
159
157
  * @param id - The id of the `pc-asset`, or an empty string to clear the slot.
160
158
  * @param slot - The material property to write.
161
159
  */
162
- setMap(id: string, slot: TextureSlot): void;
160
+ private _setMap;
163
161
  /**
164
162
  * @param slot - The material property to write.
165
163
  * @param texture - The loaded texture.
@@ -998,13 +996,15 @@ declare class MaterialElement extends HTMLElement {
998
996
  * @returns The use tonemap flag.
999
997
  */
1000
998
  get useTonemap(): boolean;
999
+ /**
1000
+ * Returns the {@link StandardMaterial} created by the `<pc-material>` element with the given
1001
+ * `id`, or `undefined` if there is no such element or its material has not been created yet.
1002
+ *
1003
+ * @param id - The `id` of the `<pc-material>` element.
1004
+ * @returns The material, or `undefined`.
1005
+ */
1001
1006
  static get(id: string): StandardMaterial | null | undefined;
1002
1007
  static get observedAttributes(): string[];
1003
1008
  attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
1004
1009
  }
1005
- declare global {
1006
- interface HTMLElementTagNameMap {
1007
- 'pc-material': MaterialElement;
1008
- }
1009
- }
1010
1010
  export { MaterialElement };
package/dist/model.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Entity } from 'playcanvas';
1
2
  import { AsyncElement } from './async-element';
2
3
  /**
3
4
  * The ModelElement interface provides properties and methods for manipulating
@@ -8,8 +9,28 @@ import { AsyncElement } from './async-element';
8
9
  declare class ModelElement extends AsyncElement {
9
10
  private _asset;
10
11
  private _entity;
12
+ /**
13
+ * Incremented on every new load and on disconnect, and captured by a load when it starts. A
14
+ * load that resumes from an await or a load callback abandons itself if the value has moved
15
+ * on, so a superseded load can neither instantiate a second entity nor parent one that has
16
+ * since been destroyed.
17
+ */
18
+ private _loadGeneration;
19
+ /**
20
+ * The pending asset-load subscription of the current load, if it is waiting for its asset.
21
+ * Held so that whatever supersedes the load can detach the handler from the asset, rather
22
+ * than leave it registered until the asset loads (or forever, if it never does).
23
+ */
24
+ private _loadHandle;
25
+ /**
26
+ * The root entity of the instantiated model. `null` until the container asset has loaded
27
+ * and been instantiated, and again once the element has been removed from the document.
28
+ * @returns The model's root entity, or `null`.
29
+ */
30
+ get entity(): Entity | null;
11
31
  connectedCallback(): void;
12
32
  disconnectedCallback(): void;
33
+ private _detachLoadHandler;
13
34
  private _instantiate;
14
35
  private _loadModel;
15
36
  private _unloadModel;
@@ -26,9 +47,4 @@ declare class ModelElement extends AsyncElement {
26
47
  static get observedAttributes(): string[];
27
48
  attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
28
49
  }
29
- declare global {
30
- interface HTMLElementTagNameMap {
31
- 'pc-model': ModelElement;
32
- }
33
- }
34
50
  export { ModelElement };
package/dist/module.d.ts CHANGED
@@ -19,11 +19,5 @@ declare class ModuleElement extends HTMLElement {
19
19
  /** @ignore */
20
20
  constructor();
21
21
  private loadModule;
22
- getLoadPromise(): Promise<void>;
23
- }
24
- declare global {
25
- interface HTMLElementTagNameMap {
26
- 'pc-module': ModuleElement;
27
- }
28
22
  }
29
23
  export { ModuleElement };
package/dist/parse.d.ts CHANGED
@@ -15,7 +15,8 @@
15
15
  * `getEntity` is the exception: it resolves a reference to a live entity rather than parsing a
16
16
  * literal, and returns `null` instead of falling back to a default.
17
17
  */
18
- import { Color, Entity, Quat, Vec2, Vec3, Vec4 } from 'playcanvas';
18
+ import type { Entity } from 'playcanvas';
19
+ import { Color, Quat, Vec2, Vec3, Vec4 } from 'playcanvas';
19
20
  /**
20
21
  * Splits an attribute value into exactly `count` numeric components. Returns `null` when the
21
22
  * value does not consist of exactly `count` whitespace-separated finite numbers.
@@ -58,12 +59,14 @@ export declare const parseColor: <T extends Color | null>(value: string | null,
58
59
  * the value is invalid — the latter also logs a warning listing the valid names.
59
60
  *
60
61
  * @param value - The attribute value to parse (`null` when the attribute is absent).
61
- * @param valid - The valid names: an array, or a map whose keys are the valid names.
62
+ * @param valid - The valid names: an array, or a map whose keys are the valid names. Only the keys
63
+ * are read, so the map's value type is unconstrained - engine enums are mostly numeric constants,
64
+ * but some (e.g. `SCALEMODE_BLEND`) are strings.
62
65
  * @param defaultValue - The value to use when the attribute is absent or invalid.
63
66
  * @param attribute - The attribute name, used in the warning message.
64
67
  * @returns The resolved enum name.
65
68
  */
66
- export declare const parseEnum: <T extends string>(value: string | null, valid: readonly T[] | ReadonlyMap<T, number>, defaultValue: T, attribute: string) => T;
69
+ export declare const parseEnum: <T extends string>(value: string | null, valid: readonly T[] | ReadonlyMap<T, unknown>, defaultValue: T, attribute: string) => T;
67
70
  /**
68
71
  * Parses a number attribute value. Returns the parsed number when the value is a finite number.
69
72
  * Returns `defaultValue` when the attribute is absent (`null`), or when the value is not a