@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
@@ -1,6 +1,6 @@
1
1
  import type { ParticleSystemComponent } from 'playcanvas';
2
2
 
3
- import { AssetElement } from '../asset';
3
+ import { useAsset } from '../asset';
4
4
 
5
5
  import { ComponentElement } from './component';
6
6
 
@@ -21,14 +21,15 @@ class ParticleSystemComponentElement extends ComponentElement {
21
21
  }
22
22
 
23
23
  protected getInitialComponentData() {
24
- const asset = AssetElement.get(this._asset);
25
- if (!asset) {
24
+ const asset = useAsset(this._asset);
25
+ // A lazy config has no resource yet - _loadAsset applies it once the load completes
26
+ if (!asset || !asset.resource) {
26
27
  return {};
27
28
  }
28
29
 
29
30
  if ((asset.resource as any).colorMapAsset) {
30
31
  const id = (asset.resource as any).colorMapAsset;
31
- const colorMapAsset = AssetElement.get(id)?.id;
32
+ const colorMapAsset = useAsset(id)?.id;
32
33
  if (colorMapAsset) {
33
34
  (asset.resource as any).colorMapAsset = colorMapAsset;
34
35
  }
@@ -59,10 +60,9 @@ class ParticleSystemComponentElement extends ComponentElement {
59
60
  }
60
61
 
61
62
  private async _loadAsset() {
62
- const appElement = await this.closestApp?.ready();
63
- const app = appElement?.app;
63
+ await this.closestApp?.ready();
64
64
 
65
- const asset = AssetElement.get(this._asset);
65
+ const asset = useAsset(this._asset);
66
66
  if (!asset) {
67
67
  return;
68
68
  }
@@ -73,7 +73,6 @@ class ParticleSystemComponentElement extends ComponentElement {
73
73
  asset.once('load', () => {
74
74
  this.applyConfig(asset.resource);
75
75
  });
76
- app!.assets.load(asset);
77
76
  }
78
77
  }
79
78
 
@@ -1,7 +1,7 @@
1
1
  import type { ScriptComponent, Script } from 'playcanvas';
2
2
  import { Color, Quat, Vec2, Vec3, Vec4 } from 'playcanvas';
3
3
 
4
- import { AssetElement } from '../asset';
4
+ import { useAsset } from '../asset';
5
5
  import {
6
6
  getEntity,
7
7
  parseBool,
@@ -119,7 +119,7 @@ type Conversion = (rest: string, raw: string) => any;
119
119
  * @returns The asset, or `raw`.
120
120
  */
121
121
  const assetConversion: Conversion = (rest, raw) => {
122
- const asset = AssetElement.get(rest);
122
+ const asset = useAsset(rest);
123
123
  if (asset) {
124
124
  return asset;
125
125
  }
@@ -1,6 +1,6 @@
1
1
  import type { SoundSlot } from 'playcanvas';
2
2
 
3
- import { AssetElement } from '../asset';
3
+ import { useAsset } from '../asset';
4
4
  import { AsyncElement } from '../async-element';
5
5
  import { parseBool, parseNumber } from '../parse';
6
6
 
@@ -120,7 +120,7 @@ class SoundSlotElement extends AsyncElement {
120
120
  set asset(value: string) {
121
121
  this._asset = value;
122
122
  if (this.soundSlot) {
123
- const id = AssetElement.get(value)?.id;
123
+ const id = useAsset(value)?.id;
124
124
  if (id) {
125
125
  this.soundSlot.asset = id;
126
126
  }
@@ -28,9 +28,9 @@ class LoadingBar {
28
28
  this._track.setAttribute('aria-label', 'Loading');
29
29
  this._track.setAttribute('aria-valuemin', '0');
30
30
  this._track.setAttribute('aria-valuemax', '100');
31
- // Fixed positioning matches the canvas, which always fills the window (FILLMODE_FILL_WINDOW)
31
+ // Anchored to the pc-app element, which the library's base styles make a positioned box
32
32
  this._track.style.cssText = [
33
- 'position: fixed',
33
+ 'position: absolute',
34
34
  'top: 0',
35
35
  'left: 0',
36
36
  'width: 100%',
package/src/material.ts CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  import type { EventHandle, Texture } from 'playcanvas';
27
27
 
28
28
  import type { AppElement } from './app';
29
- import { AssetElement } from './asset';
29
+ import { useAsset } from './asset';
30
30
  import { parseBool, parseColor, parseEnum, parseNumber, parseVec2 } from './parse';
31
31
 
32
32
  type BlendType =
@@ -523,7 +523,7 @@ class MaterialElement extends HTMLElement {
523
523
  return;
524
524
  }
525
525
 
526
- const asset = AssetElement.get(id);
526
+ const asset = useAsset(id);
527
527
  if (!asset) return;
528
528
 
529
529
  if (asset.loaded) {
package/src/model.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ContainerResource, Entity, EventHandle } from 'playcanvas';
2
2
 
3
- import { AssetElement } from './asset';
3
+ import { useAsset } from './asset';
4
4
  import { AsyncElement } from './async-element';
5
5
 
6
6
  /**
@@ -154,9 +154,7 @@ class ModelElement extends AsyncElement {
154
154
  return;
155
155
  }
156
156
 
157
- const app = appElement.app;
158
-
159
- const asset = AssetElement.get(this._asset);
157
+ const asset = useAsset(this._asset);
160
158
  if (!asset) {
161
159
  // An empty id is a legitimate transient (the asset may be assigned later); a
162
160
  // non-empty one that resolves to nothing is a dead end - say so rather than staying
@@ -194,7 +192,6 @@ class ModelElement extends AsyncElement {
194
192
  );
195
193
  this._onReady();
196
194
  });
197
- app!.assets.load(asset);
198
195
  }
199
196
  }
200
197
 
package/src/module.ts CHANGED
@@ -1,13 +1,21 @@
1
1
  import { basisInitialize, WasmModule } from 'playcanvas';
2
2
 
3
+ import { AsyncElement } from './async-element';
4
+
3
5
  /**
4
6
  * The ModuleElement interface provides properties and methods for manipulating
5
- * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-module/ | `<pc-module>`} elements.
6
- * The ModuleElement interface also inherits the properties and methods of the
7
- * {@link HTMLElement} interface.
7
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-module/ | `<pc-module>`}
8
+ * elements. The ModuleElement interface also inherits the properties and methods of the
9
+ * {@link AsyncElement} interface.
10
+ *
11
+ * The attributes are read once, when the module starts loading - on the element's first
12
+ * connection, or earlier if a containing `<pc-app>` boots first and collects it - so changing
13
+ * them later has no effect. The element becomes ready once the module has loaded. WebAssembly
14
+ * modules configure engine-global state that never unloads, so readiness is not re-armed by
15
+ * removing the element, and a re-inserted element does not load again.
8
16
  *
9
- * Note that these attributes are read once when the element is created, so changing them later
10
- * has no effect.
17
+ * A `<pc-module>` without a `name` warns and never becomes ready; a containing `<pc-app>` still
18
+ * boots.
11
19
  *
12
20
  * @attribute {string} name - The name of the WebAssembly module to configure, e.g. `Basis` or
13
21
  * `Ammo`.
@@ -16,21 +24,25 @@ import { basisInitialize, WasmModule } from 'playcanvas';
16
24
  * @attribute {string} fallback - The URL of the module's asm.js fallback script, used when
17
25
  * WebAssembly is unavailable.
18
26
  */
19
- class ModuleElement extends HTMLElement {
20
- private loadPromise: Promise<void>;
27
+ class ModuleElement extends AsyncElement {
28
+ private _loadPromise: Promise<void> | null = null;
21
29
 
22
- /** @ignore */
23
- constructor() {
24
- super();
25
- this.loadPromise = this.loadModule();
30
+ connectedCallback() {
31
+ this._getLoadPromise();
26
32
  }
27
33
 
28
- private async loadModule(): Promise<void> {
29
- const name = this.getAttribute('name')!;
30
- const glueUrl = this.getAttribute('glue')!;
31
- const wasmUrl = this.getAttribute('wasm')!;
32
- const fallbackUrl = this.getAttribute('fallback')!;
33
- const config = { glueUrl, wasmUrl, fallbackUrl };
34
+ private async _loadModule(): Promise<void> {
35
+ const name = this.getAttribute('name');
36
+ if (!name) {
37
+ console.warn("pc-module requires a 'name' attribute - no module was configured");
38
+ return;
39
+ }
40
+
41
+ const config = {
42
+ glueUrl: this.getAttribute('glue') ?? undefined,
43
+ wasmUrl: this.getAttribute('wasm') ?? undefined,
44
+ fallbackUrl: this.getAttribute('fallback') ?? undefined
45
+ };
34
46
 
35
47
  if (name === 'Basis') {
36
48
  basisInitialize(config);
@@ -41,17 +53,24 @@ class ModuleElement extends HTMLElement {
41
53
  WasmModule.getInstance(name, () => resolve());
42
54
  });
43
55
  }
56
+
57
+ this._onReady();
44
58
  }
45
59
 
46
60
  /**
47
- * Returns the promise that settles when the module has loaded. Awaited by the containing
48
- * `<pc-app>` element before it creates its graphics device.
61
+ * Returns the promise that settles when the module has loaded, starting the load if it has
62
+ * not already started - a containing `<pc-app>` boots in document order, so it may collect
63
+ * this element before the element's own connectedCallback has run. A missing `name` resolves
64
+ * the promise without configuring anything, so a misconfigured module never blocks the app.
49
65
  *
50
66
  * @returns The load promise.
51
67
  * @internal
52
68
  */
53
69
  _getLoadPromise(): Promise<void> {
54
- return this.loadPromise;
70
+ if (!this._loadPromise) {
71
+ this._loadPromise = this._loadModule();
72
+ }
73
+ return this._loadPromise;
55
74
  }
56
75
  }
57
76
 
package/src/sky.ts CHANGED
@@ -2,7 +2,7 @@ import type { Asset, EventHandle, Scene, Texture } from 'playcanvas';
2
2
  import { EnvLighting, LAYERID_SKYBOX, Quat, Vec3 } from 'playcanvas';
3
3
 
4
4
  import type { AppElement } from './app';
5
- import { AssetElement } from './asset';
5
+ import { useAsset } from './asset';
6
6
  import { AsyncElement } from './async-element';
7
7
  import { parseBool, parseEnum, parseNumber, parseVec3 } from './parse';
8
8
 
@@ -116,7 +116,7 @@ class SkyElement extends AsyncElement {
116
116
 
117
117
  this._appElement = appElement;
118
118
 
119
- const asset = AssetElement.get(this._asset);
119
+ const asset = useAsset(this._asset);
120
120
  if (!asset) {
121
121
  return;
122
122
  }
@@ -136,7 +136,6 @@ class SkyElement extends AsyncElement {
136
136
  }
137
137
  this._generateSkybox(asset);
138
138
  });
139
- app.assets.load(asset);
140
139
  }
141
140
  }
142
141