@playcanvas/web-components 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/app.d.ts CHANGED
@@ -1,10 +1,16 @@
1
- import { AppBase } from 'playcanvas';
1
+ import { AppBase, Entity } from 'playcanvas';
2
2
  import { AsyncElement } from './async-element';
3
+ import { EntityElement } from './entity';
3
4
  /**
4
5
  * The AppElement interface provides properties and methods for manipulating
5
6
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-app/ | `<pc-app>`} elements.
6
7
  * The AppElement interface also inherits the properties and methods of the
7
8
  * {@link HTMLElement} interface.
9
+ *
10
+ * @fires {ProgressEvent} progress - Fired while the application preloads its assets. `loaded` and
11
+ * `total` are asset counts, not bytes, and an asset that fails to load still counts as loaded.
12
+ * Fired at least once per boot, and the final event always has `loaded` equal to `total`. Does
13
+ * not bubble.
8
14
  */
9
15
  declare class AppElement extends AsyncElement {
10
16
  /**
@@ -14,21 +20,46 @@ declare class AppElement extends AsyncElement {
14
20
  private _alpha;
15
21
  private _backend;
16
22
  private _antialias;
17
- private _depth;
18
- private _stencil;
19
- private _highResolution;
23
+ private _depthBuffer;
24
+ private _stencilBuffer;
25
+ private _maxPixelRatio;
26
+ private _loadingBar;
27
+ /**
28
+ * Set once the graphics options above have been handed to `createGraphicsDevice`, after which
29
+ * writing any of them changes nothing. Guards the warning in {@link _warnIfBooted}, and is
30
+ * cleared on disconnect so a re-connected element boots from its current attributes.
31
+ */
32
+ private _optionsLocked;
33
+ private _bar;
20
34
  private _hierarchyReady;
35
+ /**
36
+ * The elements backing this application's entities, keyed by the entity itself. Registered
37
+ * by EntityElement at creation and removed when an entity is destroyed, this joins engine
38
+ * scene nodes back to their owning elements by identity - never by name.
39
+ */
40
+ private _entityElements;
21
41
  private _picker;
22
42
  private _hasPointerListeners;
23
43
  private _hoveredEntity;
44
+ private _pickToken;
24
45
  private _pointerHandlers;
25
46
  private _app;
47
+ private _loadProgress;
26
48
  /**
27
- * The PlayCanvas application instance. Available once the element is ready await
28
- * {@link whenReady} or the element's `ready()` promise before accessing it.
29
- * @returns The application instance.
49
+ * The PlayCanvas application instance. `null` until the element is ready, and again once it
50
+ * has been removed from the document — await {@link whenReady} or the element's `ready()`
51
+ * promise before accessing it.
52
+ * @returns The application instance, or `null`.
30
53
  */
31
- get app(): AppBase;
54
+ get app(): AppBase | null;
55
+ /**
56
+ * The asset preload progress of the application, as a fraction from 0 to 1. It is 0 until
57
+ * preloading begins (and again once the element has been removed from the document), and 1
58
+ * once preloading has finished — including when there was nothing to preload. Read this to
59
+ * initialize a loading UI; subsequent updates arrive via the `progress` event.
60
+ * @returns The preload progress.
61
+ */
62
+ get loadProgress(): number;
32
63
  /**
33
64
  * Creates a new AppElement instance.
34
65
  *
@@ -40,35 +71,100 @@ declare class AppElement extends AsyncElement {
40
71
  _onWindowResize(): void;
41
72
  _pickerCreate(): void;
42
73
  _pickerDestroy(): void;
74
+ /**
75
+ * Registers the element that created an entity. Called by EntityElement when it creates its
76
+ * entity.
77
+ *
78
+ * @param entity - The entity.
79
+ * @param element - The element that created it.
80
+ * @ignore
81
+ */
82
+ _registerEntityElement(entity: Entity, element: EntityElement): void;
83
+ /**
84
+ * Removes the registration for a destroyed entity. Called by EntityElement.
85
+ *
86
+ * @param entity - The entity.
87
+ * @ignore
88
+ */
89
+ _unregisterEntityElement(entity: Entity): void;
90
+ /**
91
+ * Returns the `<pc-entity>` element whose backing entity is `entity`, or `null` if the
92
+ * entity was not created by an element of this application - for example, a node inside a
93
+ * model's instantiated hierarchy, or an entity created through the engine API.
94
+ *
95
+ * @param entity - The entity to look up.
96
+ * @returns The element backing the entity, or `null`.
97
+ */
98
+ elementFromEntity(entity: Entity): EntityElement | null;
99
+ /**
100
+ * Resolves the element that owns a picked node: the nearest node up the parent chain -
101
+ * starting with the node itself - that was created by a `<pc-entity>` of this application.
102
+ * A hit inside a model's instantiated hierarchy therefore resolves to the element hosting
103
+ * the model.
104
+ *
105
+ * @param node - The picked node, or `null`.
106
+ * @returns The owning element, or `null`.
107
+ */
108
+ private _elementFromNode;
109
+ /**
110
+ * Like {@link _elementFromNode}, but skips elements without a listener for `type`, so a hit
111
+ * on an unlistened child still reaches a listening ancestor.
112
+ *
113
+ * @param node - The picked node, or `null`.
114
+ * @param type - The pointer event type a listener is required for.
115
+ * @returns The nearest listening element, or `null`.
116
+ */
117
+ private _elementWithListener;
43
118
  private _getPickerCoordinates;
44
- _onPointerMove(event: PointerEvent): void;
45
- _onPointerDown(event: PointerEvent): void;
46
- _onPointerUp(event: PointerEvent): void;
119
+ /**
120
+ * Picks the scene under the pointer and returns the graph node that was hit, or `null`.
121
+ *
122
+ * The read back is asynchronous because the synchronous {@link Picker.getSelection} is not
123
+ * supported on WebGPU, where it returns an empty selection rather than failing - which
124
+ * silently disabled every `onpointer*` handler once WebGPU became the resolved backend. The
125
+ * async variant works on both backends and does not block the main thread on a GPU read.
126
+ *
127
+ * @param event - The pointer event to pick under.
128
+ * @returns The graph node under the pointer, or `null` if nothing was hit.
129
+ */
130
+ private _pickNode;
131
+ _onPointerMove(event: PointerEvent): Promise<void>;
132
+ _onPointerDown(event: PointerEvent): Promise<void>;
133
+ _onPointerUp(event: PointerEvent): Promise<void>;
47
134
  _onPointerListenerAdded(type: string): void;
48
135
  _onPointerListenerRemoved(type: string): void;
49
136
  /**
50
- * Sets the alpha flag.
137
+ * Warns that a graphics option was written too late to have any effect. These options are read
138
+ * once, when the element connects and creates its graphics device, so a later write updates
139
+ * only the element's own property - silently, without this.
140
+ *
141
+ * @param name - The name of the option, as its attribute.
142
+ */
143
+ private _warnIfBooted;
144
+ /**
145
+ * Sets whether the frame buffer has an alpha channel, which is what lets the page show through
146
+ * wherever the scene has not drawn. Read only when the application boots.
51
147
  * @param value - The alpha flag.
52
148
  */
53
149
  set alpha(value: boolean);
54
150
  /**
55
- * Gets the alpha flag.
151
+ * Gets whether the frame buffer has an alpha channel.
56
152
  * @returns The alpha flag.
57
153
  */
58
154
  get alpha(): boolean;
59
155
  /**
60
- * Sets the antialias flag.
156
+ * Sets whether the frame buffer is anti-aliased. Read only when the application boots.
61
157
  * @param value - The antialias flag.
62
158
  */
63
159
  set antialias(value: boolean);
64
160
  /**
65
- * Gets the antialias flag.
161
+ * Gets whether the frame buffer is anti-aliased.
66
162
  * @returns The antialias flag.
67
163
  */
68
164
  get antialias(): boolean;
69
165
  /**
70
166
  * Sets the graphics backend. Defaults to 'webgpu', which falls back to 'webgl2' if WebGPU
71
- * is not supported by the browser.
167
+ * is not supported by the browser. Read only when the application boots.
72
168
  * @param value - The graphics backend ('webgpu', 'webgl2', or 'null').
73
169
  */
74
170
  set backend(value: 'webgpu' | 'webgl2' | 'null');
@@ -78,15 +174,16 @@ declare class AppElement extends AsyncElement {
78
174
  */
79
175
  get backend(): "webgpu" | "webgl2" | "null";
80
176
  /**
81
- * Sets the depth flag.
82
- * @param value - The depth flag.
177
+ * Sets whether the frame buffer has a depth buffer, which the renderer needs to resolve which
178
+ * surface is nearest the camera. Read only when the application boots.
179
+ * @param value - The depth buffer flag.
83
180
  */
84
- set depth(value: boolean);
181
+ set depthBuffer(value: boolean);
85
182
  /**
86
- * Gets the depth flag.
87
- * @returns The depth flag.
183
+ * Gets whether the frame buffer has a depth buffer.
184
+ * @returns The depth buffer flag.
88
185
  */
89
- get depth(): boolean;
186
+ get depthBuffer(): boolean;
90
187
  /**
91
188
  * Gets the hierarchy ready flag.
92
189
  * @returns The hierarchy ready flag.
@@ -94,26 +191,45 @@ declare class AppElement extends AsyncElement {
94
191
  */
95
192
  get hierarchyReady(): boolean;
96
193
  /**
97
- * Sets the high resolution flag. When true, the application will render at the device's
98
- * physical resolution. When false, the application will render at CSS resolution.
99
- * @param value - The high resolution flag.
194
+ * Sets whether the application shows its built-in loading bar while it boots and preloads its
195
+ * assets. Enabled by default; setting `false` removes the bar immediately, while setting
196
+ * `true` has no effect until the element is next connected. The bar can be themed with the
197
+ * CSS custom properties `--pc-loading-bar-color`, `--pc-loading-bar-background` and
198
+ * `--pc-loading-bar-height`.
199
+ * @param value - The loading bar flag.
200
+ */
201
+ set loadingBar(value: boolean);
202
+ /**
203
+ * Gets whether the application shows its built-in loading bar while it boots and preloads
204
+ * its assets.
205
+ * @returns The loading bar flag.
206
+ */
207
+ get loadingBar(): boolean;
208
+ /**
209
+ * Sets the cap on the pixel ratio the application renders at. The canvas is sized by the
210
+ * smaller of this value and the display's own device pixel ratio, so the default of `Infinity`
211
+ * renders at full physical resolution, `1` renders at CSS resolution, and an intermediate
212
+ * value such as `2` keeps a dense display sharp without paying for every one of its pixels.
213
+ * Must be greater than 0. Unlike the other graphics options, this applies immediately.
214
+ * @param value - The maximum pixel ratio.
100
215
  */
101
- set highResolution(value: boolean);
216
+ set maxPixelRatio(value: number);
102
217
  /**
103
- * Gets the high resolution flag.
104
- * @returns The high resolution flag.
218
+ * Gets the cap on the pixel ratio the application renders at.
219
+ * @returns The maximum pixel ratio.
105
220
  */
106
- get highResolution(): boolean;
221
+ get maxPixelRatio(): number;
107
222
  /**
108
- * Sets the stencil flag.
109
- * @param value - The stencil flag.
223
+ * Sets whether the frame buffer has a stencil buffer, which stencil-based effects and UI
224
+ * masking need. Read only when the application boots.
225
+ * @param value - The stencil buffer flag.
110
226
  */
111
- set stencil(value: boolean);
227
+ set stencilBuffer(value: boolean);
112
228
  /**
113
- * Gets the stencil flag.
114
- * @returns The stencil flag.
229
+ * Gets whether the frame buffer has a stencil buffer.
230
+ * @returns The stencil buffer flag.
115
231
  */
116
- get stencil(): boolean;
232
+ get stencilBuffer(): boolean;
117
233
  static get observedAttributes(): string[];
118
234
  attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
119
235
  }
package/dist/asset.d.ts CHANGED
@@ -27,6 +27,13 @@ import { AsyncElement } from './async-element';
27
27
  * @attribute {number} pixels-per-unit - For a `sprite` asset, the number of pixels per world unit.
28
28
  * @attribute {'simple' | 'sliced' | 'tiled'} render-mode - For a `sprite` asset, how the sprite is
29
29
  * rendered when resized.
30
+ *
31
+ * @fires {Event} load - Fired each time the asset finishes loading, including a `lazy` asset
32
+ * loaded later and any subsequent reloads. Does not bubble — listen on this element, or use a
33
+ * capture-phase listener on an ancestor to observe every asset.
34
+ * @fires {ErrorEvent} error - Fired when the asset fails to load, with the engine's error in
35
+ * `message`. Does not bubble. The element still becomes ready — readiness means the load settled,
36
+ * not that it succeeded.
30
37
  */
31
38
  declare class AssetElement extends AsyncElement {
32
39
  private _lazy;
@@ -37,6 +44,8 @@ declare class AssetElement extends AsyncElement {
37
44
  asset: Asset | null;
38
45
  connectedCallback(): Promise<void>;
39
46
  disconnectedCallback(): void;
47
+ private _onAssetLoad;
48
+ private _onAssetError;
40
49
  createAsset(): void;
41
50
  /**
42
51
  * Builds the `data` object for the asset from an optional inline `data` attribute (JSON) and,
@@ -11,8 +11,18 @@ declare class AsyncElement extends HTMLElement {
11
11
  private _readyResolve;
12
12
  /** @ignore */
13
13
  constructor();
14
- get closestApp(): AppElement;
15
- get closestEntity(): EntityElement;
14
+ /**
15
+ * The nearest ancestor `<pc-app>` element, or `null` if this element has no `<pc-app>`
16
+ * ancestor. The search starts at the parent, so an element never resolves to itself.
17
+ * @returns The closest app element, or `null`.
18
+ */
19
+ get closestApp(): AppElement | null;
20
+ /**
21
+ * The nearest ancestor `<pc-entity>` element, or `null` if this element has no `<pc-entity>`
22
+ * ancestor. The search starts at the parent, so an element never resolves to itself.
23
+ * @returns The closest entity element, or `null`.
24
+ */
25
+ get closestEntity(): EntityElement | null;
16
26
  /**
17
27
  * Called when the element is fully initialized and ready. Subclasses should call this when
18
28
  * they're ready. Resolves the ready promise and dispatches a bubbling, composed `ready`
@@ -21,7 +21,7 @@ declare class CameraComponentElement extends ComponentElement {
21
21
  private _gamma;
22
22
  private _horizontalFov;
23
23
  private _nearClip;
24
- private _orthographic;
24
+ private _projection;
25
25
  private _orthoHeight;
26
26
  private _priority;
27
27
  private _rect;
@@ -42,12 +42,12 @@ declare class CameraComponentElement extends ComponentElement {
42
42
  gammaCorrection: 0 | 1;
43
43
  horizontalFov: boolean;
44
44
  nearClip: number;
45
- projection: 0 | 1;
45
+ projection: number;
46
46
  orthoHeight: number;
47
47
  priority: number;
48
48
  rect: Vec4;
49
49
  scissorRect: Vec4;
50
- toneMapping: number | undefined;
50
+ toneMapping: number;
51
51
  };
52
52
  get xrAvailable(): boolean | null;
53
53
  /**
@@ -186,16 +186,6 @@ declare class CameraComponentElement extends ComponentElement {
186
186
  * @returns The near clip distance.
187
187
  */
188
188
  get nearClip(): number;
189
- /**
190
- * Sets the orthographic projection of the camera.
191
- * @param value - The orthographic projection.
192
- */
193
- set orthographic(value: boolean);
194
- /**
195
- * Gets the orthographic projection of the camera.
196
- * @returns The orthographic projection.
197
- */
198
- get orthographic(): boolean;
199
189
  /**
200
190
  * Sets the orthographic height of the camera.
201
191
  * @param value - The orthographic height.
@@ -216,6 +206,16 @@ declare class CameraComponentElement extends ComponentElement {
216
206
  * @returns The priority.
217
207
  */
218
208
  get priority(): number;
209
+ /**
210
+ * Sets the projection of the camera. Use `orthoHeight` to size an orthographic projection.
211
+ * @param value - The projection ('perspective' or 'orthographic').
212
+ */
213
+ set projection(value: 'perspective' | 'orthographic');
214
+ /**
215
+ * Gets the projection of the camera.
216
+ * @returns The projection.
217
+ */
218
+ get projection(): "perspective" | "orthographic";
219
219
  /**
220
220
  * Sets the rect of the camera.
221
221
  * @param value - The rect.
@@ -23,11 +23,12 @@ declare class ComponentElement extends AsyncElement {
23
23
  connectedCallback(): Promise<void>;
24
24
  disconnectedCallback(): void;
25
25
  /**
26
- * The PlayCanvas component instance. Available once the element is ready await
27
- * {@link whenReady} or the element's `ready()` promise before accessing it.
28
- * @returns The component instance.
26
+ * The PlayCanvas component instance. `null` until the element is ready, and also for an
27
+ * element that is not a descendant of a `<pc-entity>` — await {@link whenReady} or the
28
+ * element's `ready()` promise before accessing it.
29
+ * @returns The component instance, or `null`.
29
30
  */
30
- get component(): Component;
31
+ get component(): Component | null;
31
32
  /**
32
33
  * Sets the enabled state of the component.
33
34
  * @param value - The enabled state of the component.
@@ -13,7 +13,7 @@ declare class ScreenComponentElement extends ComponentElement {
13
13
  private _resolution;
14
14
  private _referenceResolution;
15
15
  private _priority;
16
- private _blend;
16
+ private _scaleMode;
17
17
  private _scaleBlend;
18
18
  /** @ignore */
19
19
  constructor();
@@ -22,7 +22,7 @@ declare class ScreenComponentElement extends ComponentElement {
22
22
  referenceResolution: Vec2;
23
23
  resolution: Vec2;
24
24
  scaleBlend: number;
25
- scaleMode: "none" | "blend";
25
+ scaleMode: string;
26
26
  screenSpace: boolean;
27
27
  };
28
28
  /**
@@ -36,10 +36,31 @@ declare class ScreenComponentElement extends ComponentElement {
36
36
  get referenceResolution(): Vec2;
37
37
  set resolution(value: Vec2);
38
38
  get resolution(): Vec2;
39
+ /**
40
+ * Sets how the screen's `resolution` and `referenceResolution` are weighted against each other
41
+ * when `scaleMode` is `blend`, from 0 (follow the resolution) to 1 (follow the reference
42
+ * resolution). Ignored while `scaleMode` is `none`.
43
+ * @param value - The scale blend factor.
44
+ */
39
45
  set scaleBlend(value: number);
46
+ /**
47
+ * Gets how the screen's resolutions are weighted against each other.
48
+ * @returns The scale blend factor.
49
+ */
40
50
  get scaleBlend(): number;
41
- set blend(value: boolean);
42
- get blend(): boolean;
51
+ /**
52
+ * Sets how the screen scales its contents. `none` renders at `resolution` and ignores
53
+ * `referenceResolution`; `blend` scales between the two, weighted by `scaleBlend`, which is what
54
+ * keeps a UI laid out at one resolution usable at another. Requires `screenSpace` - the engine
55
+ * forces `none` on a world-space screen, which does not support scaling.
56
+ * @param value - The scale mode ('none' or 'blend').
57
+ */
58
+ set scaleMode(value: 'none' | 'blend');
59
+ /**
60
+ * Gets how the screen scales its contents.
61
+ * @returns The scale mode.
62
+ */
63
+ get scaleMode(): "none" | "blend";
43
64
  set screenSpace(value: boolean);
44
65
  get screenSpace(): boolean;
45
66
  static get observedAttributes(): string[];
@@ -31,22 +31,24 @@ declare class ScrollViewComponentElement extends ComponentElement {
31
31
  */
32
32
  get component(): ScrollViewComponent;
33
33
  /**
34
- * Sets whether horizontal scrolling is enabled.
34
+ * Sets whether scrolling along the horizontal axis is enabled. This is a toggle, unlike the
35
+ * `orientation` of a `<pc-scrollbar>`, for which `horizontal` is one of the accepted values.
35
36
  * @param value - Whether horizontal scrolling is enabled.
36
37
  */
37
38
  set horizontal(value: boolean);
38
39
  /**
39
- * Gets whether horizontal scrolling is enabled.
40
+ * Gets whether scrolling along the horizontal axis is enabled.
40
41
  * @returns Whether horizontal scrolling is enabled.
41
42
  */
42
43
  get horizontal(): boolean;
43
44
  /**
44
- * Sets whether vertical scrolling is enabled.
45
+ * Sets whether scrolling along the vertical axis is enabled. This is a toggle, unlike the
46
+ * `orientation` of a `<pc-scrollbar>`, for which `vertical` is one of the accepted values.
45
47
  * @param value - Whether vertical scrolling is enabled.
46
48
  */
47
49
  set vertical(value: boolean);
48
50
  /**
49
- * Gets whether vertical scrolling is enabled.
51
+ * Gets whether scrolling along the vertical axis is enabled.
50
52
  * @returns Whether vertical scrolling is enabled.
51
53
  */
52
54
  get vertical(): boolean;