@playcanvas/web-components 0.10.0 → 0.10.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.
package/dist/app.d.ts CHANGED
@@ -5,6 +5,11 @@ import { AsyncElement } from './async-element';
5
5
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-app/ | `<pc-app>`} elements.
6
6
  * The AppElement interface also inherits the properties and methods of the
7
7
  * {@link HTMLElement} interface.
8
+ *
9
+ * @fires {ProgressEvent} progress - Fired while the application preloads its assets. `loaded` and
10
+ * `total` are asset counts, not bytes, and an asset that fails to load still counts as loaded.
11
+ * Fired at least once per boot, and the final event always has `loaded` equal to `total`. Does
12
+ * not bubble.
8
13
  */
9
14
  declare class AppElement extends AsyncElement {
10
15
  /**
@@ -17,18 +22,31 @@ declare class AppElement extends AsyncElement {
17
22
  private _depth;
18
23
  private _stencil;
19
24
  private _highResolution;
25
+ private _loadingBar;
26
+ private _bar;
20
27
  private _hierarchyReady;
21
28
  private _picker;
22
29
  private _hasPointerListeners;
23
30
  private _hoveredEntity;
31
+ private _pickToken;
24
32
  private _pointerHandlers;
25
33
  private _app;
34
+ private _loadProgress;
26
35
  /**
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.
36
+ * The PlayCanvas application instance. `null` until the element is ready, and again once it
37
+ * has been removed from the document — await {@link whenReady} or the element's `ready()`
38
+ * promise before accessing it.
39
+ * @returns The application instance, or `null`.
30
40
  */
31
- get app(): AppBase;
41
+ get app(): AppBase | null;
42
+ /**
43
+ * The asset preload progress of the application, as a fraction from 0 to 1. It is 0 until
44
+ * preloading begins (and again once the element has been removed from the document), and 1
45
+ * once preloading has finished — including when there was nothing to preload. Read this to
46
+ * initialize a loading UI; subsequent updates arrive via the `progress` event.
47
+ * @returns The preload progress.
48
+ */
49
+ get loadProgress(): number;
32
50
  /**
33
51
  * Creates a new AppElement instance.
34
52
  *
@@ -41,9 +59,21 @@ declare class AppElement extends AsyncElement {
41
59
  _pickerCreate(): void;
42
60
  _pickerDestroy(): void;
43
61
  private _getPickerCoordinates;
44
- _onPointerMove(event: PointerEvent): void;
45
- _onPointerDown(event: PointerEvent): void;
46
- _onPointerUp(event: PointerEvent): void;
62
+ /**
63
+ * Picks the scene under the pointer and returns the graph node that was hit, or `null`.
64
+ *
65
+ * The read back is asynchronous because the synchronous {@link Picker.getSelection} is not
66
+ * supported on WebGPU, where it returns an empty selection rather than failing - which
67
+ * silently disabled every `onpointer*` handler once WebGPU became the resolved backend. The
68
+ * async variant works on both backends and does not block the main thread on a GPU read.
69
+ *
70
+ * @param event - The pointer event to pick under.
71
+ * @returns The graph node under the pointer, or `null` if nothing was hit.
72
+ */
73
+ private _pickNode;
74
+ _onPointerMove(event: PointerEvent): Promise<void>;
75
+ _onPointerDown(event: PointerEvent): Promise<void>;
76
+ _onPointerUp(event: PointerEvent): Promise<void>;
47
77
  _onPointerListenerAdded(type: string): void;
48
78
  _onPointerListenerRemoved(type: string): void;
49
79
  /**
@@ -104,6 +134,21 @@ declare class AppElement extends AsyncElement {
104
134
  * @returns The high resolution flag.
105
135
  */
106
136
  get highResolution(): boolean;
137
+ /**
138
+ * Sets whether the application shows its built-in loading bar while it boots and preloads its
139
+ * assets. Enabled by default; setting `false` removes the bar immediately, while setting
140
+ * `true` has no effect until the element is next connected. The bar can be themed with the
141
+ * CSS custom properties `--pc-loading-bar-color`, `--pc-loading-bar-background` and
142
+ * `--pc-loading-bar-height`.
143
+ * @param value - The loading bar flag.
144
+ */
145
+ set loadingBar(value: boolean);
146
+ /**
147
+ * Gets whether the application shows its built-in loading bar while it boots and preloads
148
+ * its assets.
149
+ * @returns The loading bar flag.
150
+ */
151
+ get loadingBar(): boolean;
107
152
  /**
108
153
  * Sets the stencil flag.
109
154
  * @param value - The stencil flag.
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`
@@ -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.