@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
package/README.md CHANGED
@@ -30,7 +30,7 @@ PlayCanvas Web Components are a set of custom HTML elements for building 3D inte
30
30
 
31
31
  ## Examples
32
32
 
33
- <img width="3840" height="2160" alt="image" src="https://github.com/user-attachments/assets/e113cd2a-300d-4713-a1f4-ada647a8f04c" />
33
+ <img width="5120" height="2160" alt="examples" src="https://github.com/user-attachments/assets/92cf1156-c93f-46b5-8d05-e576967ceaf3" />
34
34
 
35
35
  See PlayCanvas Web Components in action here: https://playcanvas.github.io/web-components/examples
36
36
 
package/dist/app.d.cts ADDED
@@ -0,0 +1,281 @@
1
+ import type { Entity } from 'playcanvas';
2
+ import { AppBase } from 'playcanvas';
3
+ import { AsyncElement } from './async-element.cjs';
4
+ import type { EntityBaseElement } from './entity-base.cjs';
5
+ /**
6
+ * The AppElement interface provides properties and methods for manipulating
7
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-app/ | `<pc-app>`} elements.
8
+ * The AppElement interface also inherits the properties and methods of the
9
+ * {@link HTMLElement} interface.
10
+ *
11
+ * The element is sized like a replaced element such as `<video>`: a block-level box that the
12
+ * page's CSS controls, 300x150 by default. The application's canvas always fills the element,
13
+ * and the drawing buffer resolution follows the element's size (capped by `max-pixel-ratio`),
14
+ * tracked live via a ResizeObserver — so the element can be embedded at any size, resized by
15
+ * its container, or made fullscreen with ordinary CSS such as `width: 100vw; height: 100dvh`.
16
+ *
17
+ * @fires {ProgressEvent} progress - Fired while the application preloads its assets. `loaded` and
18
+ * `total` are asset counts, not bytes, and an asset that fails to load still counts as loaded.
19
+ * Fired at least once per boot, and the final event always has `loaded` equal to `total`. Does
20
+ * not bubble.
21
+ *
22
+ * @fires {ErrorEvent} error - Fired when the application cannot boot because no graphics device
23
+ * could be created (for example, a browser with WebGL disabled). `message` names the requested
24
+ * backends and `error` holds the underlying failure. The element never becomes ready
25
+ * and `app` stays `null` — listen for this event to show a fallback UI. Removing the element and
26
+ * re-inserting it retries the boot with its current attributes. Does not bubble.
27
+ */
28
+ declare class AppElement extends AsyncElement {
29
+ /**
30
+ * The canvas element.
31
+ */
32
+ private _canvas;
33
+ private _alpha;
34
+ private _backend;
35
+ private _antialias;
36
+ private _depthBuffer;
37
+ private _stencilBuffer;
38
+ private _maxPixelRatio;
39
+ private _loadingBar;
40
+ /**
41
+ * Set once the graphics options above have been handed to `createGraphicsDevice`, after which
42
+ * writing any of them changes nothing. Guards the warning in {@link _warnIfBooted}, and is
43
+ * cleared on disconnect so a re-connected element boots from its current attributes.
44
+ */
45
+ private _optionsLocked;
46
+ private _bar;
47
+ /**
48
+ * Incremented on every connect and disconnect. Boot captures the value on entry and abandons
49
+ * itself wherever it resumes from an await if the value has moved on — so a boot whose
50
+ * element was removed cannot complete against a torn-down element, and a boot whose element
51
+ * was removed and re-inserted (which starts a boot of its own) cannot race the newer one.
52
+ */
53
+ private _bootGeneration;
54
+ /**
55
+ * The elements backing this application's entities, keyed by the entity itself. Registered
56
+ * by EntityElement at creation (and NodeElement at binding) and removed when an entity is
57
+ * destroyed or unbound, this joins engine scene nodes back to their owning elements by
58
+ * identity - never by name.
59
+ */
60
+ private _entityElements;
61
+ private _picker;
62
+ private _hasPointerListeners;
63
+ private _hoveredEntity;
64
+ private _pickToken;
65
+ private _pointerHandlers;
66
+ private _app;
67
+ private _loadProgress;
68
+ /**
69
+ * Tracks the element's box so the drawing buffer and picker follow it. Created per boot once
70
+ * the application exists, and disconnected on teardown. `null` where ResizeObserver is
71
+ * unavailable (jsdom), where the boot-time resolution set is the only sizing that happens.
72
+ */
73
+ private _resizeObserver;
74
+ /**
75
+ * The PlayCanvas application instance. `null` until the element is ready, and again once it
76
+ * has been removed from the document — await {@link whenReady} or the element's `ready()`
77
+ * promise before accessing it.
78
+ * @returns The application instance, or `null`.
79
+ */
80
+ get app(): AppBase | null;
81
+ /**
82
+ * The asset preload progress of the application, as a fraction from 0 to 1. It is 0 until
83
+ * preloading begins (and again once the element has been removed from the document), and 1
84
+ * once preloading has finished — including when there was nothing to preload. Read this to
85
+ * initialize a loading UI; subsequent updates arrive via the `progress` event.
86
+ * @returns The preload progress.
87
+ */
88
+ get loadProgress(): number;
89
+ /**
90
+ * Creates a new AppElement instance.
91
+ *
92
+ * @ignore
93
+ */
94
+ constructor();
95
+ connectedCallback(): Promise<void>;
96
+ disconnectedCallback(): void;
97
+ /**
98
+ * Syncs the drawing buffer and the picker to the canvas's current CSS size. The picker must
99
+ * track the buffer, or picks would land at stale coordinates after a resize. Skipped while
100
+ * an XR session presents - the session owns the buffer size.
101
+ */
102
+ private _syncCanvasSize;
103
+ private _pickerCreate;
104
+ private _pickerDestroy;
105
+ /**
106
+ * Returns the `<pc-entity>` or `<pc-node>` element whose backing entity is `entity`, or
107
+ * `null` if the entity is not fronted by an element of this application - for example, an
108
+ * unbound node inside a model's instantiated hierarchy, or an entity created through the
109
+ * engine API.
110
+ *
111
+ * @param entity - The entity to look up.
112
+ * @returns The element fronting the entity, or `null`.
113
+ */
114
+ elementFromEntity(entity: Entity): EntityBaseElement | null;
115
+ /**
116
+ * Resolves the element that owns a picked node: the nearest node up the parent chain -
117
+ * starting with the node itself - that is fronted by a `<pc-entity>` or `<pc-node>` of this
118
+ * application. A hit inside a model's instantiated hierarchy therefore resolves to the
119
+ * nearest bound `<pc-node>`, or failing that the element hosting the model.
120
+ *
121
+ * @param node - The picked node, or `null`.
122
+ * @returns The owning element, or `null`.
123
+ */
124
+ private _elementFromNode;
125
+ /**
126
+ * Like {@link _elementFromNode}, but skips elements without a listener for `type`, so a hit
127
+ * on an unlistened child still reaches a listening ancestor.
128
+ *
129
+ * @param node - The picked node, or `null`.
130
+ * @param type - The pointer event type a listener is required for.
131
+ * @returns The nearest listening element, or `null`.
132
+ */
133
+ private _elementWithListener;
134
+ /**
135
+ * Converts a pointer event's client coordinates into drawing-buffer coordinates - the space
136
+ * the pick buffer and the camera viewports are laid out in. When the canvas has no CSS box
137
+ * to map through (jsdom; a hidden canvas receives no pointer events in a browser), the
138
+ * client coordinates are passed through unmapped and `mapped` is false, so callers know the
139
+ * coordinates correspond to no real geometry.
140
+ *
141
+ * @param event - The pointer event to convert.
142
+ * @param canvas - The canvas the event was dispatched on.
143
+ * @returns The buffer-space coordinates, and whether they were actually mapped.
144
+ */
145
+ private _getPickerCoordinates;
146
+ /**
147
+ * Whether a camera's viewport contains the point. A camera renders into its normalized
148
+ * `rect`, whose origin is the bottom-left of the canvas while buffer coordinates run from
149
+ * the top-left - so the vertical test flips, as the engine's ElementInput flips it for UI
150
+ * input. The right and bottom edges are exclusive: a viewport rasterizes the half-open
151
+ * pixel range [left, right) x [top, bottom), so a coordinate on a shared edge belongs to
152
+ * the viewport whose first pixel it is - never to the one it just left, whose pick buffer
153
+ * holds nothing there.
154
+ *
155
+ * @param camera - The camera to test.
156
+ * @param x - The x coordinate, in buffer space.
157
+ * @param y - The y coordinate, in buffer space.
158
+ * @param canvas - The canvas the coordinates are relative to.
159
+ * @returns Whether the camera's viewport contains the point.
160
+ */
161
+ private _cameraContains;
162
+ /**
163
+ * Picks the scene under the pointer and returns the graph node that was hit, or `null`.
164
+ *
165
+ * The camera is resolved the way the engine's ElementInput resolves it for UI input:
166
+ * enabled cameras are tried topmost-first (they render in ascending `priority` order),
167
+ * skipping cameras that render to a texture and cameras whose viewport `rect` does not
168
+ * contain the pointer. A camera that picks nothing ends the search if it clears the color
169
+ * buffer - its background visually owns the pixel - and otherwise cedes to the cameras
170
+ * beneath it, so an overlay camera only intercepts picks where it actually drew something.
171
+ * The pick buffer is prepared per camera, so each camera picks from its own layers.
172
+ *
173
+ * The read back is asynchronous because the synchronous {@link Picker.getSelection} is not
174
+ * supported on WebGPU, where it returns an empty selection rather than failing - which
175
+ * silently disabled every `onpointer*` handler once WebGPU became the resolved backend. The
176
+ * async variant works on both backends and does not block the main thread on a GPU read.
177
+ *
178
+ * @param event - The pointer event to pick under.
179
+ * @returns The graph node under the pointer, or `null` if nothing was hit.
180
+ */
181
+ private _pickNode;
182
+ private _onPointerMove;
183
+ private _onPointerDown;
184
+ private _onPointerUp;
185
+ private _onPointerListenerAdded;
186
+ private _onPointerListenerRemoved;
187
+ /**
188
+ * Warns that a graphics option was written too late to have any effect. These options are read
189
+ * once, when the element connects and creates its graphics device, so a later write updates
190
+ * only the element's own property - silently, without this.
191
+ *
192
+ * @param name - The name of the option, as its attribute.
193
+ */
194
+ private _warnIfBooted;
195
+ /**
196
+ * Sets whether the frame buffer has an alpha channel, which is what lets the page show through
197
+ * wherever the scene has not drawn. Read only when the application boots.
198
+ * @param value - The alpha flag.
199
+ */
200
+ set alpha(value: boolean);
201
+ /**
202
+ * Gets whether the frame buffer has an alpha channel.
203
+ * @returns The alpha flag.
204
+ */
205
+ get alpha(): boolean;
206
+ /**
207
+ * Sets whether the frame buffer is anti-aliased. Read only when the application boots.
208
+ * @param value - The antialias flag.
209
+ */
210
+ set antialias(value: boolean);
211
+ /**
212
+ * Gets whether the frame buffer is anti-aliased.
213
+ * @returns The antialias flag.
214
+ */
215
+ get antialias(): boolean;
216
+ /**
217
+ * Sets the graphics backend. Defaults to 'webgpu', which falls back to 'webgl2' if WebGPU
218
+ * is not supported by the browser. Read only when the application boots.
219
+ * @param value - The graphics backend ('webgpu', 'webgl2', or 'null').
220
+ */
221
+ set backend(value: 'webgpu' | 'webgl2' | 'null');
222
+ /**
223
+ * Gets the graphics backend.
224
+ * @returns The graphics backend.
225
+ */
226
+ get backend(): "webgpu" | "webgl2" | "null";
227
+ /**
228
+ * Sets whether the frame buffer has a depth buffer, which the renderer needs to resolve which
229
+ * surface is nearest the camera. Read only when the application boots.
230
+ * @param value - The depth buffer flag.
231
+ */
232
+ set depthBuffer(value: boolean);
233
+ /**
234
+ * Gets whether the frame buffer has a depth buffer.
235
+ * @returns The depth buffer flag.
236
+ */
237
+ get depthBuffer(): boolean;
238
+ /**
239
+ * Sets whether the application shows its built-in loading bar while it boots and preloads its
240
+ * assets. Enabled by default; setting `false` removes the bar immediately, while setting
241
+ * `true` has no effect until the element is next connected. The bar can be themed with the
242
+ * CSS custom properties `--pc-loading-bar-color`, `--pc-loading-bar-background` and
243
+ * `--pc-loading-bar-height`.
244
+ * @param value - The loading bar flag.
245
+ */
246
+ set loadingBar(value: boolean);
247
+ /**
248
+ * Gets whether the application shows its built-in loading bar while it boots and preloads
249
+ * its assets.
250
+ * @returns The loading bar flag.
251
+ */
252
+ get loadingBar(): boolean;
253
+ /**
254
+ * Sets the cap on the pixel ratio the application renders at. The canvas is sized by the
255
+ * smaller of this value and the display's own device pixel ratio, so the default of `Infinity`
256
+ * renders at full physical resolution, `1` renders at CSS resolution, and an intermediate
257
+ * value such as `2` keeps a dense display sharp without paying for every one of its pixels.
258
+ * Must be greater than 0. Unlike the other graphics options, this applies immediately.
259
+ * @param value - The maximum pixel ratio.
260
+ */
261
+ set maxPixelRatio(value: number);
262
+ /**
263
+ * Gets the cap on the pixel ratio the application renders at.
264
+ * @returns The maximum pixel ratio.
265
+ */
266
+ get maxPixelRatio(): number;
267
+ /**
268
+ * Sets whether the frame buffer has a stencil buffer, which stencil-based effects and UI
269
+ * masking need. Read only when the application boots.
270
+ * @param value - The stencil buffer flag.
271
+ */
272
+ set stencilBuffer(value: boolean);
273
+ /**
274
+ * Gets whether the frame buffer has a stencil buffer.
275
+ * @returns The stencil buffer flag.
276
+ */
277
+ get stencilBuffer(): boolean;
278
+ static get observedAttributes(): string[];
279
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
280
+ }
281
+ export { AppElement };
package/dist/app.d.ts CHANGED
@@ -1,17 +1,29 @@
1
1
  import type { Entity } from 'playcanvas';
2
2
  import { AppBase } from 'playcanvas';
3
- import { AsyncElement } from './async-element';
4
- import type { EntityBaseElement } from './entity-base';
3
+ import { AsyncElement } from './async-element.js';
4
+ import type { EntityBaseElement } from './entity-base.js';
5
5
  /**
6
6
  * The AppElement interface provides properties and methods for manipulating
7
7
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-app/ | `<pc-app>`} elements.
8
8
  * The AppElement interface also inherits the properties and methods of the
9
9
  * {@link HTMLElement} interface.
10
10
  *
11
+ * The element is sized like a replaced element such as `<video>`: a block-level box that the
12
+ * page's CSS controls, 300x150 by default. The application's canvas always fills the element,
13
+ * and the drawing buffer resolution follows the element's size (capped by `max-pixel-ratio`),
14
+ * tracked live via a ResizeObserver — so the element can be embedded at any size, resized by
15
+ * its container, or made fullscreen with ordinary CSS such as `width: 100vw; height: 100dvh`.
16
+ *
11
17
  * @fires {ProgressEvent} progress - Fired while the application preloads its assets. `loaded` and
12
18
  * `total` are asset counts, not bytes, and an asset that fails to load still counts as loaded.
13
19
  * Fired at least once per boot, and the final event always has `loaded` equal to `total`. Does
14
20
  * not bubble.
21
+ *
22
+ * @fires {ErrorEvent} error - Fired when the application cannot boot because no graphics device
23
+ * could be created (for example, a browser with WebGL disabled). `message` names the requested
24
+ * backends and `error` holds the underlying failure. The element never becomes ready
25
+ * and `app` stays `null` — listen for this event to show a fallback UI. Removing the element and
26
+ * re-inserting it retries the boot with its current attributes. Does not bubble.
15
27
  */
16
28
  declare class AppElement extends AsyncElement {
17
29
  /**
@@ -53,6 +65,12 @@ declare class AppElement extends AsyncElement {
53
65
  private _pointerHandlers;
54
66
  private _app;
55
67
  private _loadProgress;
68
+ /**
69
+ * Tracks the element's box so the drawing buffer and picker follow it. Created per boot once
70
+ * the application exists, and disconnected on teardown. `null` where ResizeObserver is
71
+ * unavailable (jsdom), where the boot-time resolution set is the only sizing that happens.
72
+ */
73
+ private _resizeObserver;
56
74
  /**
57
75
  * The PlayCanvas application instance. `null` until the element is ready, and again once it
58
76
  * has been removed from the document — await {@link whenReady} or the element's `ready()`
@@ -76,7 +94,12 @@ declare class AppElement extends AsyncElement {
76
94
  constructor();
77
95
  connectedCallback(): Promise<void>;
78
96
  disconnectedCallback(): void;
79
- private _onWindowResize;
97
+ /**
98
+ * Syncs the drawing buffer and the picker to the canvas's current CSS size. The picker must
99
+ * track the buffer, or picks would land at stale coordinates after a resize. Skipped while
100
+ * an XR session presents - the session owns the buffer size.
101
+ */
102
+ private _syncCanvasSize;
80
103
  private _pickerCreate;
81
104
  private _pickerDestroy;
82
105
  /**
@@ -108,10 +131,45 @@ declare class AppElement extends AsyncElement {
108
131
  * @returns The nearest listening element, or `null`.
109
132
  */
110
133
  private _elementWithListener;
134
+ /**
135
+ * Converts a pointer event's client coordinates into drawing-buffer coordinates - the space
136
+ * the pick buffer and the camera viewports are laid out in. When the canvas has no CSS box
137
+ * to map through (jsdom; a hidden canvas receives no pointer events in a browser), the
138
+ * client coordinates are passed through unmapped and `mapped` is false, so callers know the
139
+ * coordinates correspond to no real geometry.
140
+ *
141
+ * @param event - The pointer event to convert.
142
+ * @param canvas - The canvas the event was dispatched on.
143
+ * @returns The buffer-space coordinates, and whether they were actually mapped.
144
+ */
111
145
  private _getPickerCoordinates;
146
+ /**
147
+ * Whether a camera's viewport contains the point. A camera renders into its normalized
148
+ * `rect`, whose origin is the bottom-left of the canvas while buffer coordinates run from
149
+ * the top-left - so the vertical test flips, as the engine's ElementInput flips it for UI
150
+ * input. The right and bottom edges are exclusive: a viewport rasterizes the half-open
151
+ * pixel range [left, right) x [top, bottom), so a coordinate on a shared edge belongs to
152
+ * the viewport whose first pixel it is - never to the one it just left, whose pick buffer
153
+ * holds nothing there.
154
+ *
155
+ * @param camera - The camera to test.
156
+ * @param x - The x coordinate, in buffer space.
157
+ * @param y - The y coordinate, in buffer space.
158
+ * @param canvas - The canvas the coordinates are relative to.
159
+ * @returns Whether the camera's viewport contains the point.
160
+ */
161
+ private _cameraContains;
112
162
  /**
113
163
  * Picks the scene under the pointer and returns the graph node that was hit, or `null`.
114
164
  *
165
+ * The camera is resolved the way the engine's ElementInput resolves it for UI input:
166
+ * enabled cameras are tried topmost-first (they render in ascending `priority` order),
167
+ * skipping cameras that render to a texture and cameras whose viewport `rect` does not
168
+ * contain the pointer. A camera that picks nothing ends the search if it clears the color
169
+ * buffer - its background visually owns the pixel - and otherwise cedes to the cameras
170
+ * beneath it, so an overlay camera only intercepts picks where it actually drew something.
171
+ * The pick buffer is prepared per camera, so each camera picks from its own layers.
172
+ *
115
173
  * The read back is asynchronous because the synchronous {@link Picker.getSelection} is not
116
174
  * supported on WebGPU, where it returns an empty selection rather than failing - which
117
175
  * silently disabled every `onpointer*` handler once WebGPU became the resolved backend. The
@@ -0,0 +1,224 @@
1
+ import { Asset } from 'playcanvas';
2
+ import { AsyncElement } from './async-element.cjs';
3
+ type AddressMode = 'repeat' | 'clamp' | 'mirror';
4
+ type MinFilterMode = 'nearest' | 'linear' | 'nearest-mip-nearest' | 'linear-mip-nearest' | 'nearest-mip-linear' | 'linear-mip-linear';
5
+ type MagFilterMode = 'nearest' | 'linear';
6
+ /**
7
+ * The AssetElement interface provides properties and methods for manipulating
8
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-asset/ | `<pc-asset>`} elements.
9
+ * The AssetElement interface also inherits the properties and methods of the
10
+ * {@link HTMLElement} interface.
11
+ *
12
+ * The element becomes ready once the containing application has started and the asset is in the
13
+ * state declared by the markup: loaded for preloaded assets (even if loading failed — check the
14
+ * asset's `resource`), or registered and awaiting a load for `lazy` assets. Elements inserted
15
+ * while the application is running are created and registered on insertion, and begin loading
16
+ * immediately unless `lazy`. A `pc-asset` must be a direct child of `pc-app` — elements placed
17
+ * elsewhere, or with an unsupported asset type, never become ready.
18
+ *
19
+ * A `lazy` asset loads on first use: the first time any element resolves it by `id` — a model,
20
+ * a material map, a sky, a script `asset:` reference — or when the `lazy` attribute is removed,
21
+ * whichever comes first. Until then it stays registered and unloaded.
22
+ *
23
+ * For `texture` and `textureatlas` assets, the texture options (`address-u`, `address-v`,
24
+ * `min-filter`, `mag-filter`, `anisotropy`, `mipmaps`, `srgb`, `flip-y`) apply when the texture is
25
+ * created and — like `lazy` — are observed: changing one updates a texture that has already
26
+ * loaded, and removing one restores the engine default. Changing `srgb` or `mipmaps` on a loaded
27
+ * texture recreates the underlying GPU resource, so prefer declaring those up front. Each option
28
+ * overrides the matching key in the `data` JSON; options left unset write nothing, leaving the
29
+ * engine's per-format defaults in force.
30
+ *
31
+ * Apart from `lazy` and the texture options, these attributes are read once when the asset is
32
+ * created, so changing them later has no effect.
33
+ *
34
+ * @attribute {string} id - The identifier used to reference the asset from other elements.
35
+ * @attribute {string} src - The URL of the asset to load.
36
+ * @attribute {string} type - The asset type. Inferred from the `src` file extension when omitted.
37
+ * @attribute {string} data - Additional asset data, as a JSON object.
38
+ * @attribute {string} atlas - For a `sprite` asset, the `id` of the texture atlas asset it uses.
39
+ * The atlas must be declared before the sprite.
40
+ * @attribute {string} frame-keys - For a `sprite` asset, the atlas frame keys it uses, separated
41
+ * by spaces or commas.
42
+ * @attribute {number} pixels-per-unit - For a `sprite` asset, the number of pixels per world unit.
43
+ * @attribute {'simple' | 'sliced' | 'tiled'} render-mode - For a `sprite` asset, how the sprite is
44
+ * rendered when resized.
45
+ *
46
+ * @fires {Event} load - Fired each time the asset finishes loading, including a `lazy` asset
47
+ * loaded later and any subsequent reloads. Does not bubble — listen on this element, or use a
48
+ * capture-phase listener on an ancestor to observe every asset.
49
+ * @fires {ErrorEvent} error - Fired when the asset fails to load, with the engine's error in
50
+ * `message`. Does not bubble. The element still becomes ready — readiness means the load settled,
51
+ * not that it succeeded.
52
+ */
53
+ declare class AssetElement extends AsyncElement {
54
+ private _addressU;
55
+ private _addressV;
56
+ private _anisotropy;
57
+ private _flipY;
58
+ private _lazy;
59
+ private _magFilter;
60
+ private _minFilter;
61
+ private _mipmaps;
62
+ private _srgb;
63
+ /**
64
+ * The asset that is loaded. Available once the element is ready — await
65
+ * {@link whenReady} or the element's `ready()` promise before accessing it.
66
+ */
67
+ asset: Asset | null;
68
+ connectedCallback(): Promise<void>;
69
+ disconnectedCallback(): void;
70
+ private _onAssetLoad;
71
+ private _onAssetError;
72
+ /**
73
+ * Builds the `data` object for the asset from an optional inline `data` attribute (JSON), the
74
+ * texture option attributes (for `texture` and `textureatlas` assets), and the sprite
75
+ * convenience attributes (`atlas`, `frame-keys`, `pixels-per-unit`, `render-mode`). An
76
+ * attribute overrides the matching `data` JSON key. Returns `undefined` when there is no data
77
+ * to apply.
78
+ * @param type - The resolved asset type.
79
+ * @returns The asset data, or `undefined`.
80
+ */
81
+ private _buildData;
82
+ /**
83
+ * Returns the engine texture behind this asset, when there is one: the resource itself for a
84
+ * `texture` asset, the atlas's texture for a `textureatlas` asset, `null` otherwise
85
+ * (including before the asset has loaded).
86
+ * @returns The texture, or `null`.
87
+ */
88
+ private _texture;
89
+ /**
90
+ * Writes one texture option through to the created asset, if any. The engine-JSON key is
91
+ * written into `asset.data`, mutated in place - replacing the whole object would make the
92
+ * registry re-patch every key, and a re-patched `srgb` or `mipmaps` recreates the texture
93
+ * even when unchanged. The in-place key is what a not-yet-started load reads at texture
94
+ * construction, and what any later reload reads. When the texture already exists, the
95
+ * corresponding property is assigned directly; `null` (attribute removed) deletes the key
96
+ * and restores the engine default. Assets of any other type are left untouched.
97
+ *
98
+ * @param key - The engine texture JSON key in `asset.data`.
99
+ * @param property - The Texture property to assign.
100
+ * @param dataValue - The engine-JSON value for `asset.data`, or `null` to delete the key.
101
+ * @param textureValue - The value for the Texture property, or `null` for the engine default.
102
+ */
103
+ private _applyTextureOption;
104
+ private _destroyAsset;
105
+ /**
106
+ * Sets the texture's horizontal (U) address mode: how texture coordinates outside the 0 to 1
107
+ * range sample the texture. Applies to `texture` and `textureatlas` assets, both when the
108
+ * texture is created and after it has loaded.
109
+ * @param value - The address mode, or `null` to use the engine default of 'repeat'.
110
+ */
111
+ set addressU(value: AddressMode | null);
112
+ /**
113
+ * Gets the texture's horizontal (U) address mode.
114
+ * @returns The address mode, or `null` when unset.
115
+ */
116
+ get addressU(): AddressMode | null;
117
+ /**
118
+ * Sets the texture's vertical (V) address mode: how texture coordinates outside the 0 to 1
119
+ * range sample the texture. Applies to `texture` and `textureatlas` assets, both when the
120
+ * texture is created and after it has loaded.
121
+ * @param value - The address mode, or `null` to use the engine default of 'repeat'.
122
+ */
123
+ set addressV(value: AddressMode | null);
124
+ /**
125
+ * Gets the texture's vertical (V) address mode.
126
+ * @returns The address mode, or `null` when unset.
127
+ */
128
+ get addressV(): AddressMode | null;
129
+ /**
130
+ * Sets the texture's maximum anisotropic filtering level, which improves quality at oblique
131
+ * viewing angles. Applies to `texture` and `textureatlas` assets, both when the texture is
132
+ * created and after it has loaded.
133
+ * @param value - The anisotropy level, or `null` to use the engine default of 1.
134
+ */
135
+ set anisotropy(value: number | null);
136
+ /**
137
+ * Gets the texture's maximum anisotropic filtering level.
138
+ * @returns The anisotropy level, or `null` when unset.
139
+ */
140
+ get anisotropy(): number | null;
141
+ /**
142
+ * Sets whether the texture's image data is flipped vertically at upload. Applies to `texture`
143
+ * and `textureatlas` assets, both when the texture is created and after it has loaded.
144
+ * @param value - The flip flag, or `null` to use the engine default of `false`.
145
+ */
146
+ set flipY(value: boolean | null);
147
+ /**
148
+ * Gets whether the texture's image data is flipped vertically at upload.
149
+ * @returns The flip flag, or `null` when unset.
150
+ */
151
+ get flipY(): boolean | null;
152
+ /**
153
+ * Sets whether the asset should be loaded lazily. A lazy asset is registered without being
154
+ * loaded; it loads on first use - the first time any element resolves it by `id` - or when
155
+ * this flag is cleared on a registered asset, whichever comes first.
156
+ * @param value - The lazy loading flag.
157
+ */
158
+ set lazy(value: boolean);
159
+ /**
160
+ * Gets whether the asset should be loaded lazily.
161
+ * @returns The lazy loading flag.
162
+ */
163
+ get lazy(): boolean;
164
+ /**
165
+ * Sets the texture's magnification filter, used when the texture is displayed larger than its
166
+ * source size. Applies to `texture` and `textureatlas` assets, both when the texture is
167
+ * created and after it has loaded.
168
+ * @param value - The filter, or `null` to use the engine default of 'linear'.
169
+ */
170
+ set magFilter(value: MagFilterMode | null);
171
+ /**
172
+ * Gets the texture's magnification filter.
173
+ * @returns The filter, or `null` when unset.
174
+ */
175
+ get magFilter(): MagFilterMode | null;
176
+ /**
177
+ * Sets the texture's minification filter, used when the texture is displayed smaller than its
178
+ * source size. The mip variants blend within (and, for the second `linear`, between) mipmap
179
+ * levels. Applies to `texture` and `textureatlas` assets, both when the texture is created
180
+ * and after it has loaded.
181
+ * @param value - The filter, or `null` to use the engine default of 'linear-mip-linear'.
182
+ */
183
+ set minFilter(value: MinFilterMode | null);
184
+ /**
185
+ * Gets the texture's minification filter.
186
+ * @returns The filter, or `null` when unset.
187
+ */
188
+ get minFilter(): MinFilterMode | null;
189
+ /**
190
+ * Sets whether the texture generates and uses mipmaps. Changing this on a loaded texture
191
+ * recreates the underlying GPU resource, so prefer declaring it up front. Applies to
192
+ * `texture` and `textureatlas` assets.
193
+ * @param value - The mipmaps flag, or `null` to use the engine default of `true`.
194
+ */
195
+ set mipmaps(value: boolean | null);
196
+ /**
197
+ * Gets whether the texture generates and uses mipmaps.
198
+ * @returns The mipmaps flag, or `null` when unset.
199
+ */
200
+ get mipmaps(): boolean | null;
201
+ /**
202
+ * Sets whether the texture holds sRGB (gamma-encoded) color data, enabling hardware gamma
203
+ * decode. Free when set before the texture loads; changing it on a loaded texture recreates
204
+ * the underlying GPU resource. Applies to `texture` and `textureatlas` assets.
205
+ * @param value - The sRGB flag, or `null` to use the engine default of `false`.
206
+ */
207
+ set srgb(value: boolean | null);
208
+ /**
209
+ * Gets whether the texture holds sRGB (gamma-encoded) color data.
210
+ * @returns The sRGB flag, or `null` when unset.
211
+ */
212
+ get srgb(): boolean | null;
213
+ /**
214
+ * Returns the {@link Asset} created by the `<pc-asset>` element with the given `id`, or
215
+ * `undefined` if there is no such element or its asset has not been created yet.
216
+ *
217
+ * @param id - The `id` of the `<pc-asset>` element.
218
+ * @returns The asset, or `undefined`.
219
+ */
220
+ static get(id: string): Asset | null | undefined;
221
+ static get observedAttributes(): string[];
222
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
223
+ }
224
+ export { AssetElement };
package/dist/asset.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Asset } from 'playcanvas';
2
- import { AsyncElement } from './async-element';
2
+ import { AsyncElement } from './async-element.js';
3
3
  type AddressMode = 'repeat' | 'clamp' | 'mirror';
4
4
  type MinFilterMode = 'nearest' | 'linear' | 'nearest-mip-nearest' | 'linear-mip-nearest' | 'nearest-mip-linear' | 'linear-mip-linear';
5
5
  type MagFilterMode = 'nearest' | 'linear';
@@ -16,6 +16,10 @@ type MagFilterMode = 'nearest' | 'linear';
16
16
  * immediately unless `lazy`. A `pc-asset` must be a direct child of `pc-app` — elements placed
17
17
  * elsewhere, or with an unsupported asset type, never become ready.
18
18
  *
19
+ * A `lazy` asset loads on first use: the first time any element resolves it by `id` — a model,
20
+ * a material map, a sky, a script `asset:` reference — or when the `lazy` attribute is removed,
21
+ * whichever comes first. Until then it stays registered and unloaded.
22
+ *
19
23
  * For `texture` and `textureatlas` assets, the texture options (`address-u`, `address-v`,
20
24
  * `min-filter`, `mag-filter`, `anisotropy`, `mipmaps`, `srgb`, `flip-y`) apply when the texture is
21
25
  * created and — like `lazy` — are observed: changing one updates a texture that has already
@@ -146,7 +150,9 @@ declare class AssetElement extends AsyncElement {
146
150
  */
147
151
  get flipY(): boolean | null;
148
152
  /**
149
- * Sets whether the asset should be loaded lazily.
153
+ * Sets whether the asset should be loaded lazily. A lazy asset is registered without being
154
+ * loaded; it loads on first use - the first time any element resolves it by `id` - or when
155
+ * this flag is cleared on a registered asset, whichever comes first.
150
156
  * @param value - The lazy loading flag.
151
157
  */
152
158
  set lazy(value: boolean);