@playcanvas/web-components 0.1.8 → 0.1.9

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 (55) hide show
  1. package/dist/app.d.ts +10 -1
  2. package/dist/asset.d.ts +3 -1
  3. package/dist/async-element.d.ts +2 -1
  4. package/dist/components/camera-component.d.ts +4 -4
  5. package/dist/components/collision-component.d.ts +4 -4
  6. package/dist/components/component.d.ts +3 -1
  7. package/dist/components/element-component.d.ts +4 -1
  8. package/dist/components/gsplat-component.d.ts +4 -1
  9. package/dist/components/light-component.d.ts +4 -4
  10. package/dist/components/listener-component.d.ts +4 -1
  11. package/dist/components/render-component.d.ts +4 -1
  12. package/dist/components/rigidbody-component.d.ts +4 -4
  13. package/dist/components/screen-component.d.ts +4 -1
  14. package/dist/components/script-component.d.ts +4 -1
  15. package/dist/components/script.d.ts +3 -1
  16. package/dist/components/sound-component.d.ts +4 -1
  17. package/dist/components/sound-slot.d.ts +3 -1
  18. package/dist/entity.d.ts +7 -3
  19. package/dist/material.d.ts +3 -1
  20. package/dist/model.d.ts +3 -1
  21. package/dist/module.d.ts +6 -0
  22. package/dist/pwc.cjs +161 -77
  23. package/dist/pwc.cjs.map +1 -1
  24. package/dist/pwc.js +161 -77
  25. package/dist/pwc.js.map +1 -1
  26. package/dist/pwc.min.js +1 -1
  27. package/dist/pwc.min.js.map +1 -1
  28. package/dist/pwc.mjs +161 -77
  29. package/dist/pwc.mjs.map +1 -1
  30. package/dist/scene.d.ts +3 -1
  31. package/dist/sky.d.ts +3 -1
  32. package/package.json +8 -8
  33. package/src/app.ts +28 -1
  34. package/src/asset.ts +3 -1
  35. package/src/async-element.ts +2 -1
  36. package/src/components/camera-component.ts +4 -4
  37. package/src/components/collision-component.ts +4 -4
  38. package/src/components/component.ts +3 -1
  39. package/src/components/element-component.ts +4 -2
  40. package/src/components/gsplat-component.ts +4 -1
  41. package/src/components/light-component.ts +4 -4
  42. package/src/components/listener-component.ts +4 -1
  43. package/src/components/render-component.ts +4 -1
  44. package/src/components/rigidbody-component.ts +4 -4
  45. package/src/components/screen-component.ts +4 -1
  46. package/src/components/script-component.ts +4 -1
  47. package/src/components/script.ts +3 -1
  48. package/src/components/sound-component.ts +4 -1
  49. package/src/components/sound-slot.ts +3 -1
  50. package/src/entity.ts +61 -31
  51. package/src/material.ts +3 -1
  52. package/src/model.ts +3 -1
  53. package/src/module.ts +6 -0
  54. package/src/scene.ts +13 -11
  55. package/src/sky.ts +3 -1
@@ -4,7 +4,9 @@ import { ComponentElement } from './component';
4
4
  import { parseColor } from '../utils';
5
5
 
6
6
  /**
7
- * Represents a light component in the PlayCanvas engine.
7
+ * The LightComponentElement interface provides properties and methods for manipulating
8
+ * `<pc-light>` elements. The LightComponentElement interface also inherits the properties and
9
+ * methods of the {@link HTMLElement} interface.
8
10
  *
9
11
  * @category Components
10
12
  */
@@ -31,9 +33,7 @@ class LightComponentElement extends ComponentElement {
31
33
 
32
34
  private _type = 'directional';
33
35
 
34
- /**
35
- * Creates a new LightComponentElement.
36
- */
36
+ /** @ignore */
37
37
  constructor() {
38
38
  super('light');
39
39
  }
@@ -3,11 +3,14 @@ import { AudioListenerComponent } from 'playcanvas';
3
3
  import { ComponentElement } from './component';
4
4
 
5
5
  /**
6
- * Represents a audio listener component in the PlayCanvas engine.
6
+ * The ListenerComponentElement interface provides properties and methods for manipulating
7
+ * `<pc-listener>` elements. The ListenerComponentElement interface also inherits the properties
8
+ * and methods of the {@link HTMLElement} interface.
7
9
  *
8
10
  * @category Components
9
11
  */
10
12
  class ListenerComponentElement extends ComponentElement {
13
+ /** @ignore */
11
14
  constructor() {
12
15
  super('audiolistener');
13
16
  }
@@ -4,7 +4,9 @@ import { ComponentElement } from './component';
4
4
  import { MaterialElement } from '../material';
5
5
 
6
6
  /**
7
- * Represents a render component in the PlayCanvas engine.
7
+ * The RenderComponentElement interface provides properties and methods for manipulating
8
+ * `<pc-render>` elements. The RenderComponentElement interface also inherits the properties and
9
+ * methods of the {@link HTMLElement} interface.
8
10
  *
9
11
  * @category Components
10
12
  */
@@ -17,6 +19,7 @@ class RenderComponentElement extends ComponentElement {
17
19
 
18
20
  private _type: 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere' = 'asset';
19
21
 
22
+ /** @ignore */
20
23
  constructor() {
21
24
  super('render');
22
25
  }
@@ -4,7 +4,9 @@ import { ComponentElement } from './component';
4
4
  import { parseVec3 } from '../utils';
5
5
 
6
6
  /**
7
- * Represents a rigidbody component in the PlayCanvas engine.
7
+ * The RigidBodyComponentElement interface provides properties and methods for manipulating
8
+ * `<pc-rigidbody>` elements. The RigidBodyComponentElement interface also inherits the properties
9
+ * and methods of the {@link HTMLElement} interface.
8
10
  *
9
11
  * @category Components
10
12
  */
@@ -54,9 +56,7 @@ class RigidBodyComponentElement extends ComponentElement {
54
56
  */
55
57
  private _type: string = 'static';
56
58
 
57
- /**
58
- * Creates a new RigidBodyComponentElement.
59
- */
59
+ /** @ignore */
60
60
  constructor() {
61
61
  super('rigidbody');
62
62
  }
@@ -4,7 +4,9 @@ import { ComponentElement } from './component';
4
4
  import { parseVec2 } from '../utils';
5
5
 
6
6
  /**
7
- * Represents a screen component in the PlayCanvas engine.
7
+ * The ScreenComponentElement interface provides properties and methods for manipulating
8
+ * `<pc-screen>` elements. The ScreenComponentElement interface also inherits the properties and
9
+ * methods of the {@link HTMLElement} interface.
8
10
  *
9
11
  * @category Components
10
12
  */
@@ -21,6 +23,7 @@ class ScreenComponentElement extends ComponentElement {
21
23
 
22
24
  private _scaleBlend = 0.5;
23
25
 
26
+ /** @ignore */
24
27
  constructor() {
25
28
  super('screen');
26
29
  }
@@ -26,13 +26,16 @@ declare global {
26
26
  }
27
27
 
28
28
  /**
29
- * Represents a script component in the PlayCanvas engine.
29
+ * The ScriptComponentElement interface provides properties and methods for manipulating
30
+ * `<pc-scripts>` elements. The ScriptComponentElement interface also inherits the properties and
31
+ * methods of the {@link HTMLElement} interface.
30
32
  *
31
33
  * @category Components
32
34
  */
33
35
  class ScriptComponentElement extends ComponentElement {
34
36
  private observer: MutationObserver;
35
37
 
38
+ /** @ignore */
36
39
  constructor() {
37
40
  super('script');
38
41
 
@@ -1,5 +1,7 @@
1
1
  /**
2
- * Represents a script in the PlayCanvas engine.
2
+ * The ScriptElement interface provides properties and methods for manipulating
3
+ * `<pc-script>` elements. The ScriptElement interface also inherits the properties and
4
+ * methods of the {@link HTMLElement} interface.
3
5
  */
4
6
  class ScriptElement extends HTMLElement {
5
7
  private _attributes: string = '{}';
@@ -3,7 +3,9 @@ import { SoundComponent } from 'playcanvas';
3
3
  import { ComponentElement } from './component';
4
4
 
5
5
  /**
6
- * Represents a sound component in the PlayCanvas engine.
6
+ * The SoundComponentElement interface provides properties and methods for manipulating
7
+ * `<pc-sounds>` elements. The SoundComponentElement interface also inherits the properties and
8
+ * methods of the {@link HTMLElement} interface.
7
9
  *
8
10
  * @category Components
9
11
  */
@@ -22,6 +24,7 @@ class SoundComponentElement extends ComponentElement {
22
24
 
23
25
  private _volume: number = 1;
24
26
 
27
+ /** @ignore */
25
28
  constructor() {
26
29
  super('sound');
27
30
  }
@@ -5,7 +5,9 @@ import { AsyncElement } from '../async-element';
5
5
  import { SoundComponentElement } from './sound-component';
6
6
 
7
7
  /**
8
- * Represents a sound slot in the PlayCanvas engine.
8
+ * The SoundSlotElement interface provides properties and methods for manipulating
9
+ * `<pc-sound>` elements. The SoundSlotElement interface also inherits the properties and
10
+ * methods of the {@link AsyncElement} interface.
9
11
  */
10
12
  class SoundSlotElement extends AsyncElement {
11
13
  private _asset: string = '';
package/src/entity.ts CHANGED
@@ -1,10 +1,12 @@
1
- import { Entity, Vec3 } from 'playcanvas';
1
+ import { Application, Entity, Vec3 } from 'playcanvas';
2
2
 
3
3
  import { AsyncElement } from './async-element';
4
4
  import { parseVec3 } from './utils';
5
5
 
6
6
  /**
7
- * Represents an entity in the PlayCanvas engine.
7
+ * The EntityElement interface provides properties and methods for manipulating
8
+ * `<pc-entity>` elements. The EntityElement interface also inherits the properties and
9
+ * methods of the {@link HTMLElement} interface.
8
10
  */
9
11
  class EntityElement extends AsyncElement {
10
12
  /**
@@ -42,42 +44,69 @@ class EntityElement extends AsyncElement {
42
44
  */
43
45
  entity: Entity | null = null;
44
46
 
45
- async connectedCallback() {
46
- const closestApp = this.closestApp;
47
- if (!closestApp) return;
47
+ createEntity(app: Application) {
48
+ // Create a new entity
49
+ this.entity = new Entity(this.getAttribute('name') || this._name, app);
48
50
 
49
- // Wait for the app to complete initialization
50
- await closestApp.ready();
51
+ const enabled = this.getAttribute('enabled');
52
+ if (enabled) {
53
+ this.entity.enabled = enabled !== 'false';
54
+ }
51
55
 
52
- const app = closestApp.app!;
56
+ const position = this.getAttribute('position');
57
+ if (position) {
58
+ this.entity.setLocalPosition(parseVec3(position));
59
+ }
53
60
 
54
- // Create a new entity
55
- this.entity = new Entity(this._name, app);
56
-
57
- // Initialize from attributes
58
- const enabledAttr = this.getAttribute('enabled');
59
- const nameAttr = this.getAttribute('name');
60
- const positionAttr = this.getAttribute('position');
61
- const rotationAttr = this.getAttribute('rotation');
62
- const scaleAttr = this.getAttribute('scale');
63
- const tagsAttr = this.getAttribute('tags');
64
-
65
- if (enabledAttr) this.enabled = enabledAttr !== 'false';
66
- if (nameAttr) this.name = nameAttr;
67
- if (positionAttr) this.position = parseVec3(positionAttr);
68
- if (rotationAttr) this.rotation = parseVec3(rotationAttr);
69
- if (scaleAttr) this.scale = parseVec3(scaleAttr);
70
- if (tagsAttr) this.tags = tagsAttr.split(',').map(tag => tag.trim());
61
+ const rotation = this.getAttribute('rotation');
62
+ if (rotation) {
63
+ this.entity.setLocalEulerAngles(parseVec3(rotation));
64
+ }
65
+
66
+ const scale = this.getAttribute('scale');
67
+ if (scale) {
68
+ this.entity.setLocalScale(parseVec3(scale));
69
+ }
70
+
71
+ const tags = this.getAttribute('tags');
72
+ if (tags) {
73
+ this.entity.tags.add(tags.split(',').map(tag => tag.trim()));
74
+ }
75
+ }
76
+
77
+ buildHierarchy(app: Application) {
78
+ if (!this.entity) return;
71
79
 
72
80
  const closestEntity = this.closestEntity;
73
- if (closestEntity) {
74
- closestEntity.ready().then(() => {
75
- closestEntity.entity!.addChild(this.entity!);
76
- this._onReady();
77
- });
81
+ if (closestEntity?.entity) {
82
+ closestEntity.entity.addChild(this.entity);
78
83
  } else {
79
84
  app.root.addChild(this.entity);
80
- this._onReady();
85
+ }
86
+
87
+ this._onReady();
88
+ }
89
+
90
+ connectedCallback() {
91
+ // Wait for app to be ready
92
+ const closestApp = this.closestApp;
93
+ if (!closestApp) return;
94
+
95
+ // If app is already running, create entity immediately
96
+ if (closestApp.hierarchyReady) {
97
+ const app = closestApp.app!;
98
+
99
+ this.createEntity(app);
100
+ this.buildHierarchy(app);
101
+
102
+ // Handle any child entities that might exist
103
+ const childEntities = this.querySelectorAll<EntityElement>('pc-entity');
104
+ childEntities.forEach((child) => {
105
+ child.createEntity(app);
106
+ });
107
+ childEntities.forEach((child) => {
108
+ child.buildHierarchy(app);
109
+ });
81
110
  }
82
111
  }
83
112
 
@@ -89,6 +118,7 @@ class EntityElement extends AsyncElement {
89
118
  (child as EntityElement).entity = null;
90
119
  });
91
120
 
121
+ // Destroy the entity
92
122
  this.entity.destroy();
93
123
  this.entity = null;
94
124
  }
package/src/material.ts CHANGED
@@ -4,7 +4,9 @@ import { AssetElement } from './asset';
4
4
  import { parseColor } from './utils';
5
5
 
6
6
  /**
7
- * Represents a material in the PlayCanvas engine.
7
+ * The MaterialElement interface provides properties and methods for manipulating
8
+ * `<pc-material>` elements. The MaterialElement interface also inherits the properties and
9
+ * methods of the {@link HTMLElement} interface.
8
10
  */
9
11
  class MaterialElement extends HTMLElement {
10
12
  private _diffuse = new Color(1, 1, 1);
package/src/model.ts CHANGED
@@ -4,7 +4,9 @@ import { AssetElement } from './asset';
4
4
  import { AsyncElement } from './async-element';
5
5
 
6
6
  /**
7
- * Represents a model in the PlayCanvas engine.
7
+ * The ModelElement interface provides properties and methods for manipulating
8
+ * `<pc-model>` elements. The ModelElement interface also inherits the properties and
9
+ * methods of the {@link HTMLElement} interface.
8
10
  */
9
11
  class ModelElement extends AsyncElement {
10
12
  private _asset: string = '';
package/src/module.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  import { basisInitialize, WasmModule } from 'playcanvas';
2
2
 
3
+ /**
4
+ * The ModuleElement interface provides properties and methods for manipulating
5
+ * `<pc-module>` elements. The ModuleElement interface also inherits the properties and
6
+ * methods of the {@link HTMLElement} interface.
7
+ */
3
8
  class ModuleElement extends HTMLElement {
4
9
  private loadPromise: Promise<void>;
5
10
 
11
+ /** @ignore */
6
12
  constructor() {
7
13
  super();
8
14
  this.loadPromise = this.loadModule();
package/src/scene.ts CHANGED
@@ -4,7 +4,9 @@ import { AsyncElement } from './async-element';
4
4
  import { parseColor } from './utils';
5
5
 
6
6
  /**
7
- * Represents a scene in the PlayCanvas engine.
7
+ * The SceneElement interface provides properties and methods for manipulating
8
+ * `<pc-scene>` elements. The SceneElement interface also inherits the properties and
9
+ * methods of the {@link HTMLElement} interface.
8
10
  */
9
11
  class SceneElement extends AsyncElement {
10
12
  /**
@@ -48,11 +50,11 @@ class SceneElement extends AsyncElement {
48
50
 
49
51
  updateSceneSettings() {
50
52
  if (this.scene) {
51
- this.scene.rendering.fog = this._fog;
52
- this.scene.rendering.fogColor = this._fogColor;
53
- this.scene.rendering.fogDensity = this._fogDensity;
54
- this.scene.rendering.fogStart = this._fogStart;
55
- this.scene.rendering.fogEnd = this._fogEnd;
53
+ this.scene.fog.type = this._fog;
54
+ this.scene.fog.color = this._fogColor;
55
+ this.scene.fog.density = this._fogDensity;
56
+ this.scene.fog.start = this._fogStart;
57
+ this.scene.fog.end = this._fogEnd;
56
58
  // ... set other properties on the scene as well
57
59
  }
58
60
  }
@@ -64,7 +66,7 @@ class SceneElement extends AsyncElement {
64
66
  set fog(value) {
65
67
  this._fog = value;
66
68
  if (this.scene) {
67
- this.scene.rendering.fog = value;
69
+ this.scene.fog.type = value;
68
70
  }
69
71
  }
70
72
 
@@ -83,7 +85,7 @@ class SceneElement extends AsyncElement {
83
85
  set fogColor(value: Color) {
84
86
  this._fogColor = value;
85
87
  if (this.scene) {
86
- this.scene.rendering.fogColor = value;
88
+ this.scene.fog.color = value;
87
89
  }
88
90
  }
89
91
 
@@ -102,7 +104,7 @@ class SceneElement extends AsyncElement {
102
104
  set fogDensity(value: number) {
103
105
  this._fogDensity = value;
104
106
  if (this.scene) {
105
- this.scene.rendering.fogDensity = value;
107
+ this.scene.fog.density = value;
106
108
  }
107
109
  }
108
110
 
@@ -121,7 +123,7 @@ class SceneElement extends AsyncElement {
121
123
  set fogStart(value: number) {
122
124
  this._fogStart = value;
123
125
  if (this.scene) {
124
- this.scene.rendering.fogStart = value;
126
+ this.scene.fog.start = value;
125
127
  }
126
128
  }
127
129
 
@@ -140,7 +142,7 @@ class SceneElement extends AsyncElement {
140
142
  set fogEnd(value: number) {
141
143
  this._fogEnd = value;
142
144
  if (this.scene) {
143
- this.scene.rendering.fogEnd = value;
145
+ this.scene.fog.end = value;
144
146
  }
145
147
  }
146
148
 
package/src/sky.ts CHANGED
@@ -5,7 +5,9 @@ import { AsyncElement } from './async-element';
5
5
  import { parseVec3 } from './utils';
6
6
 
7
7
  /**
8
- * Represents a sky in the PlayCanvas engine.
8
+ * The SkyElement interface provides properties and methods for manipulating
9
+ * `<pc-sky>` elements. The SkyElement interface also inherits the properties and
10
+ * methods of the {@link HTMLElement} interface.
9
11
  */
10
12
  class SkyElement extends AsyncElement {
11
13
  private _asset = '';