@playcanvas/web-components 0.12.0 → 0.13.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 (95) hide show
  1. package/README.md +1 -1
  2. package/dist/app.d.cts +281 -0
  3. package/dist/app.d.ts +61 -3
  4. package/dist/asset.d.cts +224 -0
  5. package/dist/asset.d.ts +8 -2
  6. package/dist/async-element.d.cts +103 -0
  7. package/dist/async-element.d.ts +6 -4
  8. package/dist/colors.d.cts +1 -0
  9. package/dist/components/button-component.d.cts +186 -0
  10. package/dist/components/button-component.d.ts +1 -1
  11. package/dist/components/camera-component.d.cts +253 -0
  12. package/dist/components/camera-component.d.ts +1 -1
  13. package/dist/components/collision-component.d.cts +73 -0
  14. package/dist/components/collision-component.d.ts +1 -1
  15. package/dist/components/component.d.cts +82 -0
  16. package/dist/components/component.d.ts +1 -1
  17. package/dist/components/element-component.d.cts +316 -0
  18. package/dist/components/element-component.d.ts +1 -1
  19. package/dist/components/gsplat-component.d.cts +108 -0
  20. package/dist/components/gsplat-component.d.ts +1 -1
  21. package/dist/components/layoutchild-component.d.cts +110 -0
  22. package/dist/components/layoutchild-component.d.ts +1 -1
  23. package/dist/components/layoutgroup-component.d.cts +136 -0
  24. package/dist/components/layoutgroup-component.d.ts +1 -1
  25. package/dist/components/light-component.d.cts +264 -0
  26. package/dist/components/light-component.d.ts +1 -1
  27. package/dist/components/listener-component.d.cts +20 -0
  28. package/dist/components/listener-component.d.ts +1 -1
  29. package/dist/components/particlesystem-component.d.cts +52 -0
  30. package/dist/components/particlesystem-component.d.ts +1 -1
  31. package/dist/components/render-component.d.cts +76 -0
  32. package/dist/components/render-component.d.ts +1 -1
  33. package/dist/components/rigidbody-component.d.cts +88 -0
  34. package/dist/components/rigidbody-component.d.ts +1 -1
  35. package/dist/components/screen-component.d.cts +70 -0
  36. package/dist/components/screen-component.d.ts +1 -1
  37. package/dist/components/script-component.d.cts +163 -0
  38. package/dist/components/script-component.d.ts +1 -1
  39. package/dist/components/script.d.cts +94 -0
  40. package/dist/components/script.d.ts +1 -1
  41. package/dist/components/scrollbar-component.d.cts +69 -0
  42. package/dist/components/scrollbar-component.d.ts +1 -1
  43. package/dist/components/scrollview-component.d.cts +178 -0
  44. package/dist/components/scrollview-component.d.ts +1 -1
  45. package/dist/components/sound-component.d.cts +108 -0
  46. package/dist/components/sound-component.d.ts +1 -1
  47. package/dist/components/sound-slot.d.cts +134 -0
  48. package/dist/components/sound-slot.d.ts +2 -2
  49. package/dist/custom-elements.json +80 -22
  50. package/dist/entity-base.d.cts +67 -0
  51. package/dist/entity-base.d.ts +2 -2
  52. package/dist/entity.d.cts +131 -0
  53. package/dist/entity.d.ts +1 -1
  54. package/dist/index.d.cts +79 -0
  55. package/dist/index.d.ts +33 -33
  56. package/dist/loading-bar.d.cts +35 -0
  57. package/dist/material.d.cts +1011 -0
  58. package/dist/model.d.cts +72 -0
  59. package/dist/model.d.ts +1 -1
  60. package/dist/module.d.cts +29 -0
  61. package/dist/module.d.ts +16 -10
  62. package/dist/node.d.cts +253 -0
  63. package/dist/node.d.ts +1 -1
  64. package/dist/parse.d.cts +147 -0
  65. package/dist/pwc.cjs +285 -92
  66. package/dist/pwc.cjs.map +1 -1
  67. package/dist/pwc.js +286 -93
  68. package/dist/pwc.js.map +1 -1
  69. package/dist/pwc.min.js +1 -1
  70. package/dist/pwc.min.js.map +1 -1
  71. package/dist/pwc.min.mjs +1 -1
  72. package/dist/pwc.min.mjs.map +1 -1
  73. package/dist/pwc.mjs +286 -93
  74. package/dist/pwc.mjs.map +1 -1
  75. package/dist/scene.d.cts +117 -0
  76. package/dist/scene.d.ts +1 -1
  77. package/dist/sky.d.cts +121 -0
  78. package/dist/sky.d.ts +1 -1
  79. package/dist/vscode.html-custom-data.json +3 -3
  80. package/dist/web-types.json +42 -6
  81. package/package.json +16 -7
  82. package/src/app.ts +211 -49
  83. package/src/asset.ts +34 -2
  84. package/src/async-element.ts +4 -2
  85. package/src/components/button-component.ts +7 -7
  86. package/src/components/element-component.ts +7 -7
  87. package/src/components/gsplat-component.ts +3 -3
  88. package/src/components/particlesystem-component.ts +7 -8
  89. package/src/components/script-component.ts +2 -2
  90. package/src/components/sound-slot.ts +2 -2
  91. package/src/loading-bar.ts +2 -2
  92. package/src/material.ts +2 -2
  93. package/src/model.ts +2 -5
  94. package/src/module.ts +39 -20
  95. package/src/sky.ts +2 -3
@@ -0,0 +1,72 @@
1
+ import type { Entity } from 'playcanvas';
2
+ import { AsyncElement } from './async-element.cjs';
3
+ /**
4
+ * The ModelElement interface provides properties and methods for manipulating
5
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-model/ | `<pc-model>`} elements.
6
+ * The ModelElement interface also inherits the properties and methods of the
7
+ * {@link HTMLElement} interface.
8
+ *
9
+ * The element becomes ready once its container asset has loaded and the instantiated hierarchy has
10
+ * been added to the scene — `entity` is non-null by then. A failed load also settles readiness,
11
+ * with `entity` remaining `null`: readiness means the load settled, not that it succeeded — listen
12
+ * for `error`, or check `entity`, to tell the outcomes apart. Changing `asset` re-arms readiness
13
+ * and instantiates anew, so a `ready()` obtained after the change resolves against the new
14
+ * hierarchy. A `pc-model` outside a `pc-app`, or referencing an unknown asset id, warns and never
15
+ * becomes ready.
16
+ *
17
+ * @fires {Event} load - Fired each time a container asset finishes instantiating, including
18
+ * re-instantiation after `asset` changes. Does not bubble — listen on this element, or use a
19
+ * capture-phase listener on an ancestor.
20
+ * @fires {ErrorEvent} error - Fired when the container asset fails to load, with the engine's
21
+ * error in `message`. Does not bubble. The element still becomes ready — readiness means the load
22
+ * settled, not that it succeeded.
23
+ */
24
+ declare class ModelElement extends AsyncElement {
25
+ private _asset;
26
+ private _entity;
27
+ /**
28
+ * Incremented on every new load and on disconnect, and captured by a load when it starts. A
29
+ * load that resumes from an await or a load callback abandons itself if the value has moved
30
+ * on, so a superseded load can neither instantiate a second entity nor parent one that has
31
+ * since been destroyed.
32
+ */
33
+ private _loadGeneration;
34
+ /**
35
+ * The pending asset subscriptions of the current load, if it is waiting for its asset. Held
36
+ * so that whatever supersedes the load can detach the handlers from the asset, rather than
37
+ * leave them registered until the asset settles (or forever, if it never does).
38
+ */
39
+ private _loadHandle;
40
+ private _errorHandle;
41
+ /**
42
+ * The root entity of the instantiated model. `null` until the container asset has loaded
43
+ * and been instantiated, and again once the element has been removed from the document.
44
+ * @returns The model's root entity, or `null`.
45
+ */
46
+ get entity(): Entity | null;
47
+ connectedCallback(): void;
48
+ disconnectedCallback(): void;
49
+ private _detachLoadHandlers;
50
+ /**
51
+ * Resolves readiness and dispatches the `load` event. Called once the instantiated hierarchy
52
+ * has been parented — readiness means "in the scene graph", matching `pc-entity`, so a ready
53
+ * model's entity always has world transforms.
54
+ */
55
+ private _announceLoad;
56
+ private _instantiate;
57
+ private _loadModel;
58
+ private _unloadModel;
59
+ /**
60
+ * Sets the id of the `pc-asset` to use for the model.
61
+ * @param value - The asset ID.
62
+ */
63
+ set asset(value: string);
64
+ /**
65
+ * Gets the id of the `pc-asset` to use for the model.
66
+ * @returns The asset ID.
67
+ */
68
+ get asset(): string;
69
+ static get observedAttributes(): string[];
70
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
71
+ }
72
+ export { ModelElement };
package/dist/model.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Entity } from 'playcanvas';
2
- import { AsyncElement } from './async-element';
2
+ import { AsyncElement } from './async-element.js';
3
3
  /**
4
4
  * The ModelElement interface provides properties and methods for manipulating
5
5
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-model/ | `<pc-model>`} elements.
@@ -0,0 +1,29 @@
1
+ import { AsyncElement } from './async-element.cjs';
2
+ /**
3
+ * The ModuleElement interface provides properties and methods for manipulating
4
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-module/ | `<pc-module>`}
5
+ * elements. The ModuleElement interface also inherits the properties and methods of the
6
+ * {@link AsyncElement} interface.
7
+ *
8
+ * The attributes are read once, when the module starts loading - on the element's first
9
+ * connection, or earlier if a containing `<pc-app>` boots first and collects it - so changing
10
+ * them later has no effect. The element becomes ready once the module has loaded. WebAssembly
11
+ * modules configure engine-global state that never unloads, so readiness is not re-armed by
12
+ * removing the element, and a re-inserted element does not load again.
13
+ *
14
+ * A `<pc-module>` without a `name` warns and never becomes ready; a containing `<pc-app>` still
15
+ * boots.
16
+ *
17
+ * @attribute {string} name - The name of the WebAssembly module to configure, e.g. `Basis` or
18
+ * `Ammo`.
19
+ * @attribute {string} glue - The URL of the module's glue script.
20
+ * @attribute {string} wasm - The URL of the module's WebAssembly binary.
21
+ * @attribute {string} fallback - The URL of the module's asm.js fallback script, used when
22
+ * WebAssembly is unavailable.
23
+ */
24
+ declare class ModuleElement extends AsyncElement {
25
+ private _loadPromise;
26
+ connectedCallback(): void;
27
+ private _loadModule;
28
+ }
29
+ export { ModuleElement };
package/dist/module.d.ts CHANGED
@@ -1,11 +1,18 @@
1
+ import { AsyncElement } from './async-element.js';
1
2
  /**
2
3
  * The ModuleElement interface provides properties and methods for manipulating
3
- * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-module/ | `<pc-module>`} elements.
4
- * The ModuleElement interface also inherits the properties and methods of the
5
- * {@link HTMLElement} interface.
4
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-module/ | `<pc-module>`}
5
+ * elements. The ModuleElement interface also inherits the properties and methods of the
6
+ * {@link AsyncElement} interface.
6
7
  *
7
- * Note that these attributes are read once when the element is created, so changing them later
8
- * has no effect.
8
+ * The attributes are read once, when the module starts loading - on the element's first
9
+ * connection, or earlier if a containing `<pc-app>` boots first and collects it - so changing
10
+ * them later has no effect. The element becomes ready once the module has loaded. WebAssembly
11
+ * modules configure engine-global state that never unloads, so readiness is not re-armed by
12
+ * removing the element, and a re-inserted element does not load again.
13
+ *
14
+ * A `<pc-module>` without a `name` warns and never becomes ready; a containing `<pc-app>` still
15
+ * boots.
9
16
  *
10
17
  * @attribute {string} name - The name of the WebAssembly module to configure, e.g. `Basis` or
11
18
  * `Ammo`.
@@ -14,10 +21,9 @@
14
21
  * @attribute {string} fallback - The URL of the module's asm.js fallback script, used when
15
22
  * WebAssembly is unavailable.
16
23
  */
17
- declare class ModuleElement extends HTMLElement {
18
- private loadPromise;
19
- /** @ignore */
20
- constructor();
21
- private loadModule;
24
+ declare class ModuleElement extends AsyncElement {
25
+ private _loadPromise;
26
+ connectedCallback(): void;
27
+ private _loadModule;
22
28
  }
23
29
  export { ModuleElement };
@@ -0,0 +1,253 @@
1
+ import { Vec3 } from 'playcanvas';
2
+ import { EntityBaseElement } from './entity-base.cjs';
3
+ /**
4
+ * The binding states a `<pc-node>` element moves through. `pending` while the host has not yet
5
+ * instantiated (or no `name` is assigned), `bound` once a node has been resolved and decorated,
6
+ * `missing`/`ambiguous`/`duplicate` when resolution failed — each accompanied by a warning
7
+ * naming the cause.
8
+ */
9
+ type NodeBindingState = 'pending' | 'bound' | 'missing' | 'ambiguous' | 'duplicate';
10
+ /**
11
+ * The NodeElement interface provides properties and methods for manipulating
12
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-node/ | `<pc-node>`}
13
+ * elements. The NodeElement interface also inherits the properties and methods of the
14
+ * {@link HTMLElement} interface.
15
+ *
16
+ * A `pc-node` is an override element: where `pc-entity` creates an entity, `pc-node` binds to a
17
+ * node a `pc-model` loaded and declares overrides against the authored asset — components to
18
+ * add, properties to change, content to attach. Attributes present apply as overrides; attributes
19
+ * absent leave authored values untouched, and removing an attribute (or assigning `null` to the
20
+ * matching property) restores the authored value.
21
+ *
22
+ * `name` selects among the host model's nodes (first match in depth-first order), nesting a
23
+ * `pc-node` inside another scopes the search to that subtree, and `index` picks among identically
24
+ * named matches. When `name` matches more than one node and no `index` is given, the element
25
+ * warns and binds nothing.
26
+ *
27
+ * The element becomes ready once bound, and never while unresolved — a missing or ambiguous
28
+ * name warns and records the failure in `state`, readiness stays unresolved, and descendants
29
+ * wait with it.
30
+ *
31
+ * The pointer events below are dispatched by the containing `<pc-app>` element when the pointer
32
+ * intersects the bound node's geometry, exactly as for `<pc-entity>`.
33
+ *
34
+ * @attribute {string} name - The name of the node to bind, resolved within the nearest ancestor
35
+ * `pc-model` (or `pc-node`) once it has instantiated.
36
+ * @attribute {number} index - Which match to bind when `name` matches more than one node,
37
+ * 0-based in depth-first order. Optional for a unique match; required for an ambiguous one.
38
+ * @attribute {boolean} enabled - Overrides the node's enabled state.
39
+ * @attribute {string} position - Overrides the node's local position, as an "x y z" triple.
40
+ * @attribute {string} rotation - Overrides the node's local rotation (Euler angles), as an
41
+ * "x y z" triple.
42
+ * @attribute {string} scale - Overrides the node's local scale, as an "x y z" triple.
43
+ * @attribute {string} tags - Overrides the node's tags, separated by spaces or commas.
44
+ * @attribute {string} onpointerenter - Script to run when the pointer moves onto the node.
45
+ * @attribute {string} onpointerleave - Script to run when the pointer moves off the node.
46
+ * @attribute {string} onpointermove - Script to run when the pointer moves over the node.
47
+ * @attribute {string} onpointerdown - Script to run when a pointer button is pressed over the
48
+ * node.
49
+ * @attribute {string} onpointerup - Script to run when a pointer button is released over the
50
+ * node.
51
+ * @fires {PointerEvent} pointerenter - Fired when the pointer moves onto the node.
52
+ * @fires {PointerEvent} pointerleave - Fired when the pointer moves off the node.
53
+ * @fires {PointerEvent} pointermove - Fired when the pointer moves over the node.
54
+ * @fires {PointerEvent} pointerdown - Fired when a pointer button is pressed over the node.
55
+ * @fires {PointerEvent} pointerup - Fired when a pointer button is released over the node.
56
+ */
57
+ declare class NodeElement extends EntityBaseElement {
58
+ private _name;
59
+ private _index;
60
+ private _state;
61
+ private _path;
62
+ /**
63
+ * The element whose entity roots this element's search: the nearest ancestor `pc-node`, or
64
+ * failing that the nearest ancestor `pc-model`. Resolved on connection.
65
+ */
66
+ private _host;
67
+ /**
68
+ * The listener following the host's binding cycles. Both host kinds announce each cycle
69
+ * with a `ready` event — `pc-model` on every instantiation, `pc-node` on every bind.
70
+ */
71
+ private _hostListener;
72
+ /**
73
+ * The subscription to the bound entity's destruction, detached on unbind so a retargeted
74
+ * element cannot be reset by the eventual death of a node it no longer fronts.
75
+ */
76
+ private _destroyHandle;
77
+ /** The authored values displaced by this element's overrides, captured per property. */
78
+ private _authored;
79
+ private _enabled;
80
+ private _position;
81
+ private _rotation;
82
+ private _scale;
83
+ private _tags;
84
+ /**
85
+ * The binding state: `pending` until the host instantiates and `name` resolves, `bound`
86
+ * once decorated, `missing`/`ambiguous`/`duplicate` when resolution failed (each also
87
+ * warns). Useful for asserting a document's bindings programmatically.
88
+ * @returns The binding state.
89
+ */
90
+ get state(): NodeBindingState;
91
+ /**
92
+ * The path of the bound node below the search root, `/`-separated, or `null` while not
93
+ * bound.
94
+ * @returns The bound node's path, or `null`.
95
+ */
96
+ get path(): string | null;
97
+ connectedCallback(): void;
98
+ disconnectedCallback(): void;
99
+ /**
100
+ * Re-resolves the binding against the host's current hierarchy: on connection, on a `name`
101
+ * or `index` change, and on every host cycle (a model [re]instantiating, an enclosing
102
+ * `pc-node` [re]binding). When re-resolution yields the entity already bound, the binding
103
+ * is retained untouched — a redundant edit must not flicker overrides through a revert.
104
+ */
105
+ private _rebind;
106
+ /**
107
+ * Resolves `name` (and `index`) to an entity under `hostEntity`, warning and recording the
108
+ * failure state when it cannot.
109
+ *
110
+ * @param hostEntity - The root of the search.
111
+ * @returns The resolved entity, or `null`.
112
+ */
113
+ private _resolve;
114
+ /**
115
+ * Binds `target`: registers it (making it a pick target), hooks its destruction, applies
116
+ * this element's overrides, announces readiness and builds the deferred child subtree.
117
+ *
118
+ * @param target - The entity to bind.
119
+ * @param hostEntity - The search root, for the path.
120
+ */
121
+ private _bind;
122
+ /**
123
+ * Dissolves the current binding, restoring every authored value this element's overrides
124
+ * displaced and removing the decorations this binding hosts: attachment entities are
125
+ * destroyed (re-created against the next binding) and component decorations are removed
126
+ * from the abandoned node. Both sweeps are scoped by `closestEntity`, so a still-bound
127
+ * nested `pc-node` keeps its own decorations. Safe to call in any state.
128
+ */
129
+ private _unbind;
130
+ /**
131
+ * Handles the destruction of the bound entity - its model unloading, reloading, or a script
132
+ * destroying it. There is nothing to revert on a destroyed entity; the element returns to
133
+ * pending and the host's next cycle re-resolves it.
134
+ */
135
+ private _onEntityDestroy;
136
+ /**
137
+ * Creates and parents the entities of child `pc-entity` elements - the attachment points.
138
+ * Mirrors the runtime-insertion path in EntityElement.connectedCallback: children were
139
+ * deferred while this host was unresolved (or reset when a previous binding dissolved), and
140
+ * build here once it binds.
141
+ */
142
+ private _buildChildren;
143
+ /**
144
+ * Applies every override that is explicitly set, capturing the authored value it displaces.
145
+ */
146
+ private _applyOverrides;
147
+ /**
148
+ * Restores every authored value this element's overrides displaced. The override values
149
+ * themselves are kept - they re-apply on the next binding.
150
+ */
151
+ private _revertOverrides;
152
+ /**
153
+ * Renders the path of `node` below `root`, for the `path` property and the resolution
154
+ * warnings.
155
+ *
156
+ * @param node - The node to describe.
157
+ * @param root - The search root.
158
+ * @returns The `/`-separated path.
159
+ */
160
+ private _pathOf;
161
+ /**
162
+ * Describes the search root for warnings: the model's asset id, or the enclosing node's
163
+ * name.
164
+ * @returns The description.
165
+ */
166
+ private _describeHost;
167
+ /**
168
+ * Finds the node name nearest to the missing `name`, for the miss warning. The names are
169
+ * already in hand from resolution, so the suggestion is nearly free.
170
+ *
171
+ * @param hostEntity - The root of the search.
172
+ * @returns The closest name within an edit distance of 2, or `null`.
173
+ */
174
+ private _closestName;
175
+ /**
176
+ * Sets the name of the node to bind. A change retargets: the current binding's overrides
177
+ * revert and the new name resolves afresh. `name` on a `pc-node` is never a rename of the
178
+ * authored node - it is only ever a reference.
179
+ * @param value - The node name.
180
+ */
181
+ set name(value: string);
182
+ /**
183
+ * Gets the name of the node to bind.
184
+ * @returns The node name.
185
+ */
186
+ get name(): string;
187
+ /**
188
+ * Sets which match to bind when `name` matches more than one node, 0-based in depth-first
189
+ * order. A change retargets, like `name`. `null` means unset - required when the name is
190
+ * ambiguous, optional otherwise.
191
+ * @param value - The match index, or `null`.
192
+ */
193
+ set index(value: number | null);
194
+ /**
195
+ * Gets which match to bind.
196
+ * @returns The match index, or `null` when unset.
197
+ */
198
+ get index(): number | null;
199
+ /**
200
+ * Sets the enabled override. `null` clears it, restoring the authored state.
201
+ * @param value - The enabled state, or `null`.
202
+ */
203
+ set enabled(value: boolean | null);
204
+ /**
205
+ * Gets the enabled override.
206
+ * @returns The enabled state, or `null` while no override is set.
207
+ */
208
+ get enabled(): boolean | null;
209
+ /**
210
+ * Sets the local position override. `null` clears it, restoring the authored position.
211
+ * @param value - The position, or `null`.
212
+ */
213
+ set position(value: Vec3 | null);
214
+ /**
215
+ * Gets the local position override.
216
+ * @returns The position, or `null` while no override is set.
217
+ */
218
+ get position(): Vec3 | null;
219
+ /**
220
+ * Sets the local rotation override, as Euler angles in degrees. `null` clears it, restoring
221
+ * the authored rotation.
222
+ * @param value - The rotation, or `null`.
223
+ */
224
+ set rotation(value: Vec3 | null);
225
+ /**
226
+ * Gets the local rotation override.
227
+ * @returns The rotation, or `null` while no override is set.
228
+ */
229
+ get rotation(): Vec3 | null;
230
+ /**
231
+ * Sets the local scale override. `null` clears it, restoring the authored scale.
232
+ * @param value - The scale, or `null`.
233
+ */
234
+ set scale(value: Vec3 | null);
235
+ /**
236
+ * Gets the local scale override.
237
+ * @returns The scale, or `null` while no override is set.
238
+ */
239
+ get scale(): Vec3 | null;
240
+ /**
241
+ * Sets the tags override. `null` clears it, restoring the authored tags.
242
+ * @param value - The tags, or `null`.
243
+ */
244
+ set tags(value: string[] | null);
245
+ /**
246
+ * Gets the tags override.
247
+ * @returns The tags, or `null` while no override is set.
248
+ */
249
+ get tags(): string[] | null;
250
+ static get observedAttributes(): string[];
251
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
252
+ }
253
+ export { NodeElement };
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Vec3 } from 'playcanvas';
2
- import { EntityBaseElement } from './entity-base';
2
+ import { EntityBaseElement } from './entity-base.js';
3
3
  /**
4
4
  * The binding states a `<pc-node>` element moves through. `pending` while the host has not yet
5
5
  * instantiated (or no `name` is assigned), `bound` once a node has been resolved and decorated,
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Converts HTML attribute values into the values the engine expects. Every element's
3
+ * `attributeChangedCallback` funnels through this module.
4
+ *
5
+ * The parsers share one contract:
6
+ *
7
+ * - A `null` value means the attribute is absent or was removed, and yields the supplied default.
8
+ * - A malformed value yields the same default and logs exactly one `console.warn` naming the
9
+ * attribute, so misuse is reported rather than thrown — nothing here throws or rejects.
10
+ * - A math-type default is cloned on the way out, which is what makes it safe to pass the engine's
11
+ * shared frozen constants (`Vec3.ZERO`, `Color.WHITE`) as defaults.
12
+ * - `parseBool` and `parseTags` take no attribute name, because every value is valid for them and
13
+ * so they never warn.
14
+ *
15
+ * `getEntity` is the exception: it resolves a reference to a live entity rather than parsing a
16
+ * literal, and returns `null` instead of falling back to a default.
17
+ */
18
+ import type { Entity } from 'playcanvas';
19
+ import { Color, Quat, Vec2, Vec3, Vec4 } from 'playcanvas';
20
+ /**
21
+ * Splits an attribute value into exactly `count` numeric components. Returns `null` when the
22
+ * value does not consist of exactly `count` whitespace-separated finite numbers.
23
+ *
24
+ * @param value - The value to split.
25
+ * @param count - The required number of components.
26
+ * @returns The parsed components, or `null`.
27
+ * @ignore
28
+ */
29
+ export declare const parseComponents: (value: string, count: number) => number[] | null;
30
+ /**
31
+ * Parse a boolean attribute value. The same rules apply to every boolean attribute:
32
+ *
33
+ * - Attribute absent (or removed): the supplied default is used.
34
+ * - Attribute set to the string 'false': `false`.
35
+ * - Attribute present with any other value, including the empty string of a bare boolean
36
+ * attribute (e.g. `<pc-light cast-shadows>`): `true`.
37
+ *
38
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
39
+ * @param defaultValue - The value to use when the attribute is absent or removed.
40
+ * @returns The parsed boolean.
41
+ */
42
+ export declare const parseBool: (value: string | null, defaultValue: boolean) => boolean;
43
+ /**
44
+ * Parse a color attribute value. The expected format is a CSS color name (e.g. 'rebeccapurple'),
45
+ * a hex color (e.g. '#ff0000' or '#f00'), or 3 or 4 space-separated numbers in the range 0 to 1
46
+ * (e.g. '1 0.5 0.5' or '1 0.5 0.5 0.5'). Returns `defaultValue` (cloned, when it is a color)
47
+ * when the attribute is absent (`null`), or when the value is malformed — the latter also logs
48
+ * a warning.
49
+ *
50
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
51
+ * @param defaultValue - The value to use when the attribute is absent or invalid.
52
+ * @param attribute - The attribute name, used in the warning message.
53
+ * @returns The parsed Color object.
54
+ */
55
+ export declare const parseColor: <T extends Color | null>(value: string | null, defaultValue: T, attribute: string) => Color | T;
56
+ /**
57
+ * Resolves an enum attribute value against its set of valid names. Returns the value when it is
58
+ * one of the valid names. Returns `defaultValue` when the attribute is absent (`null`), or when
59
+ * the value is invalid — the latter also logs a warning listing the valid names.
60
+ *
61
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
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.
65
+ * @param defaultValue - The value to use when the attribute is absent or invalid.
66
+ * @param attribute - The attribute name, used in the warning message.
67
+ * @returns The resolved enum name.
68
+ */
69
+ export declare const parseEnum: <T extends string>(value: string | null, valid: readonly T[] | ReadonlyMap<T, unknown>, defaultValue: T, attribute: string) => T;
70
+ /**
71
+ * Parses a number attribute value. Returns the parsed number when the value is a finite number.
72
+ * Returns `defaultValue` when the attribute is absent (`null`), or when the value is not a
73
+ * finite number — the latter also logs a warning.
74
+ *
75
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
76
+ * @param defaultValue - The value to use when the attribute is absent or invalid.
77
+ * @param attribute - The attribute name, used in the warning message.
78
+ * @returns The parsed number.
79
+ */
80
+ export declare const parseNumber: <T extends number | null>(value: string | null, defaultValue: T, attribute: string) => number | T;
81
+ /**
82
+ * Parse an Euler-angles attribute value into a quaternion. The expected format is 3
83
+ * space-separated angles in degrees (e.g. '0 90 0'). Returns `defaultValue` (cloned, when it is
84
+ * a quaternion) when the attribute is absent (`null`), or when the value is malformed — the
85
+ * latter also logs a warning.
86
+ *
87
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
88
+ * @param defaultValue - The value to use when the attribute is absent or invalid.
89
+ * @param attribute - The attribute name, used in the warning message.
90
+ * @returns The parsed Quat object.
91
+ */
92
+ export declare const parseQuat: <T extends Quat | null>(value: string | null, defaultValue: T, attribute: string) => Quat | T;
93
+ /**
94
+ * Parse a tags attribute value. The expected format is a comma-separated list of tag names
95
+ * (e.g. 'enemy, flying'). Surrounding whitespace is trimmed from each name and empty names are
96
+ * discarded, so a trailing comma or a doubled separator does not produce a blank tag. Returns a
97
+ * copy of `defaultValue` when the attribute is absent or removed (`null`).
98
+ *
99
+ * Every value is valid, so this never warns.
100
+ *
101
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
102
+ * @param defaultValue - The value to use when the attribute is absent or removed.
103
+ * @returns The parsed tag names.
104
+ */
105
+ export declare const parseTags: (value: string | null, defaultValue?: string[]) => string[];
106
+ /**
107
+ * Parse a Vec2 attribute value. The expected format is 2 space-separated numbers (e.g. '1 2').
108
+ * Returns `defaultValue` (cloned, when it is a vector) when the attribute is absent (`null`),
109
+ * or when the value is malformed — the latter also logs a warning.
110
+ *
111
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
112
+ * @param defaultValue - The value to use when the attribute is absent or invalid.
113
+ * @param attribute - The attribute name, used in the warning message.
114
+ * @returns The parsed Vec2 object.
115
+ */
116
+ export declare const parseVec2: <T extends Vec2 | null>(value: string | null, defaultValue: T, attribute: string) => Vec2 | T;
117
+ /**
118
+ * Parse a Vec3 attribute value. The expected format is 3 space-separated numbers (e.g. '1 2 3').
119
+ * Returns `defaultValue` (cloned, when it is a vector) when the attribute is absent (`null`),
120
+ * or when the value is malformed — the latter also logs a warning.
121
+ *
122
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
123
+ * @param defaultValue - The value to use when the attribute is absent or invalid.
124
+ * @param attribute - The attribute name, used in the warning message.
125
+ * @returns The parsed Vec3 object.
126
+ */
127
+ export declare const parseVec3: <T extends Vec3 | null>(value: string | null, defaultValue: T, attribute: string) => Vec3 | T;
128
+ /**
129
+ * Parse a Vec4 attribute value. The expected format is 4 space-separated numbers
130
+ * (e.g. '1 2 3 4'). Returns `defaultValue` (cloned, when it is a vector) when the attribute is
131
+ * absent (`null`), or when the value is malformed — the latter also logs a warning.
132
+ *
133
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
134
+ * @param defaultValue - The value to use when the attribute is absent or invalid.
135
+ * @param attribute - The attribute name, used in the warning message.
136
+ * @returns The parsed Vec4 object.
137
+ */
138
+ export declare const parseVec4: <T extends Vec4 | null>(value: string | null, defaultValue: T, attribute: string) => Vec4 | T;
139
+ /**
140
+ * Resolves a reference string to the {@link Entity} backing a `<pc-entity>` element. The reference
141
+ * can be a CSS selector (e.g. `#my-id`, `pc-entity[name="Foo"]`), a bare element id, or a bare
142
+ * entity name. Returns `null` if no matching element (or backing entity) is found.
143
+ *
144
+ * @param ref - The reference string to resolve.
145
+ * @returns The resolved entity, or `null`.
146
+ */
147
+ export declare const getEntity: (ref: string) => Entity | null;