@playcanvas/web-components 0.15.0 → 0.17.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.cts +14 -13
- package/dist/app.d.ts +14 -13
- package/dist/async-element.d.cts +13 -13
- package/dist/async-element.d.ts +13 -13
- package/dist/components/anim-clip.d.cts +127 -0
- package/dist/components/anim-clip.d.ts +127 -0
- package/dist/components/anim-component.d.cts +235 -0
- package/dist/components/anim-component.d.ts +235 -0
- package/dist/components/{listener-component.d.cts → audio-listener-component.d.cts} +7 -5
- package/dist/components/{listener-component.d.ts → audio-listener-component.d.ts} +7 -5
- package/dist/components/button-component.d.cts +5 -1
- package/dist/components/button-component.d.ts +5 -1
- package/dist/components/camera-component.d.cts +2 -0
- package/dist/components/camera-component.d.ts +2 -0
- package/dist/components/collision-component.d.cts +5 -1
- package/dist/components/collision-component.d.ts +5 -1
- package/dist/components/component.d.cts +3 -2
- package/dist/components/component.d.ts +3 -2
- package/dist/components/element-component.d.cts +7 -0
- package/dist/components/element-component.d.ts +7 -0
- package/dist/components/gsplat-component.d.cts +2 -0
- package/dist/components/gsplat-component.d.ts +2 -0
- package/dist/components/joint-component.d.cts +2 -0
- package/dist/components/joint-component.d.ts +2 -0
- package/dist/components/{layoutchild-component.d.cts → layout-child-component.d.cts} +3 -1
- package/dist/components/{layoutchild-component.d.ts → layout-child-component.d.ts} +3 -1
- package/dist/components/{layoutgroup-component.d.cts → layout-group-component.d.cts} +3 -1
- package/dist/components/{layoutgroup-component.d.ts → layout-group-component.d.ts} +3 -1
- package/dist/components/light-component.d.cts +2 -0
- package/dist/components/light-component.d.ts +2 -0
- package/dist/components/{particlesystem-component.d.cts → particle-system-component.d.cts} +3 -1
- package/dist/components/{particlesystem-component.d.ts → particle-system-component.d.ts} +3 -1
- package/dist/components/render-component.d.cts +2 -0
- package/dist/components/render-component.d.ts +2 -0
- package/dist/components/{rigidbody-component.d.cts → rigid-body-component.d.cts} +3 -1
- package/dist/components/{rigidbody-component.d.ts → rigid-body-component.d.ts} +3 -1
- package/dist/components/screen-component.d.cts +2 -0
- package/dist/components/screen-component.d.ts +2 -0
- package/dist/components/script-component.d.cts +23 -12
- package/dist/components/script-component.d.ts +23 -12
- package/dist/components/{script.d.cts → script-instance.d.cts} +7 -7
- package/dist/components/{script.d.ts → script-instance.d.ts} +7 -7
- package/dist/components/{scrollview-component.d.cts → scroll-view-component.d.cts} +3 -1
- package/dist/components/{scrollview-component.d.ts → scroll-view-component.d.ts} +3 -1
- package/dist/components/scrollbar-component.d.cts +2 -0
- package/dist/components/scrollbar-component.d.ts +2 -0
- package/dist/components/sound-component.d.cts +3 -1
- package/dist/components/sound-component.d.ts +3 -1
- package/dist/components/sound-slot.d.cts +2 -2
- package/dist/components/sound-slot.d.ts +2 -2
- package/dist/custom-elements.json +3154 -2005
- package/dist/entity-base.d.cts +6 -5
- package/dist/entity-base.d.ts +6 -5
- package/dist/entity-owner.d.cts +118 -0
- package/dist/entity-owner.d.ts +118 -0
- package/dist/entity.d.cts +8 -101
- package/dist/entity.d.ts +8 -101
- package/dist/index.d.cts +26 -21
- package/dist/index.d.ts +26 -21
- package/dist/model.d.cts +67 -24
- package/dist/model.d.ts +67 -24
- package/dist/pwc.cjs +1766 -619
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +1766 -619
- package/dist/pwc.js.map +1 -1
- package/dist/pwc.min.js +1 -1
- package/dist/pwc.min.js.map +1 -1
- package/dist/pwc.min.mjs +1 -1
- package/dist/pwc.min.mjs.map +1 -1
- package/dist/pwc.mjs +1762 -618
- package/dist/pwc.mjs.map +1 -1
- package/dist/vscode.html-custom-data.json +203 -89
- package/dist/{module.d.cts → wasm.d.cts} +6 -6
- package/dist/{module.d.ts → wasm.d.ts} +6 -6
- package/dist/web-types.json +556 -273
- package/package.json +7 -7
- package/src/app.ts +45 -35
- package/src/async-element.ts +14 -14
- package/src/components/anim-clip.ts +395 -0
- package/src/components/anim-component.ts +719 -0
- package/src/components/{listener-component.ts → audio-listener-component.ts} +8 -6
- package/src/components/button-component.ts +5 -1
- package/src/components/camera-component.ts +2 -0
- package/src/components/collision-component.ts +5 -1
- package/src/components/component.ts +4 -3
- package/src/components/element-component.ts +7 -0
- package/src/components/gsplat-component.ts +2 -0
- package/src/components/joint-component.ts +2 -0
- package/src/components/{layoutchild-component.ts → layout-child-component.ts} +4 -2
- package/src/components/{layoutgroup-component.ts → layout-group-component.ts} +4 -2
- package/src/components/light-component.ts +2 -0
- package/src/components/{particlesystem-component.ts → particle-system-component.ts} +4 -2
- package/src/components/render-component.ts +2 -0
- package/src/components/{rigidbody-component.ts → rigid-body-component.ts} +4 -2
- package/src/components/screen-component.ts +2 -0
- package/src/components/script-component.ts +63 -42
- package/src/components/{script.ts → script-instance.ts} +14 -14
- package/src/components/{scrollview-component.ts → scroll-view-component.ts} +4 -2
- package/src/components/scrollbar-component.ts +2 -0
- package/src/components/sound-component.ts +4 -2
- package/src/components/sound-slot.ts +4 -4
- package/src/entity-base.ts +6 -5
- package/src/entity-owner.ts +298 -0
- package/src/entity.ts +15 -270
- package/src/index.ts +32 -24
- package/src/model.ts +159 -79
- package/src/node.ts +9 -5
- package/src/{module.ts → wasm.ts} +8 -8
|
@@ -3,14 +3,16 @@ import type { AudioListenerComponent } from 'playcanvas';
|
|
|
3
3
|
import { ComponentElement } from './component';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* The
|
|
7
|
-
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-listener/ | `<pc-listener>`} elements.
|
|
8
|
-
* The
|
|
6
|
+
* The AudioListenerComponentElement interface provides properties and methods for manipulating
|
|
7
|
+
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-audio-listener/ | `<pc-audio-listener>`} elements.
|
|
8
|
+
* The AudioListenerComponentElement interface also inherits the properties and methods of the
|
|
9
9
|
* {@link HTMLElement} interface.
|
|
10
10
|
*
|
|
11
|
+
* Engine component: {@link AudioListenerComponent} (`audiolistener`).
|
|
12
|
+
*
|
|
11
13
|
* @category Components
|
|
12
14
|
*/
|
|
13
|
-
class
|
|
15
|
+
class AudioListenerComponentElement extends ComponentElement {
|
|
14
16
|
/** @ignore */
|
|
15
17
|
constructor() {
|
|
16
18
|
super('audiolistener');
|
|
@@ -25,6 +27,6 @@ class ListenerComponentElement extends ComponentElement {
|
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
customElements.define('pc-listener',
|
|
30
|
+
customElements.define('pc-audio-listener', AudioListenerComponentElement);
|
|
29
31
|
|
|
30
|
-
export {
|
|
32
|
+
export { AudioListenerComponentElement };
|
|
@@ -17,6 +17,8 @@ const transitionModes = new Map<'tint' | 'sprite', number>([
|
|
|
17
17
|
* The ButtonComponentElement interface also inherits the properties and methods of the
|
|
18
18
|
* {@link HTMLElement} interface.
|
|
19
19
|
*
|
|
20
|
+
* Engine component: {@link ButtonComponent} (`button`).
|
|
21
|
+
*
|
|
20
22
|
* @category Components
|
|
21
23
|
*/
|
|
22
24
|
class ButtonComponentElement extends ComponentElement {
|
|
@@ -121,7 +123,9 @@ class ButtonComponentElement extends ComponentElement {
|
|
|
121
123
|
|
|
122
124
|
/**
|
|
123
125
|
* Sets the reference (CSS selector, element id or entity name) to the `<pc-entity>` whose image
|
|
124
|
-
* element is used for visual transitions. Defaults to the button's own entity
|
|
126
|
+
* element is used for visual transitions. Defaults to the button's own entity — inside a
|
|
127
|
+
* `<pc-model>`, that is the model's host entity, so supply an explicit reference to target a
|
|
128
|
+
* UI entity instead.
|
|
125
129
|
* @param value - The image entity reference.
|
|
126
130
|
*/
|
|
127
131
|
set image(value: string) {
|
|
@@ -41,6 +41,8 @@ const tonemaps = new Map<'none' | 'linear' | 'filmic' | 'hejl' | 'aces' | 'aces2
|
|
|
41
41
|
* The CameraComponentElement interface also inherits the properties and methods of the
|
|
42
42
|
* {@link HTMLElement} interface.
|
|
43
43
|
*
|
|
44
|
+
* Engine component: {@link CameraComponent} (`camera`).
|
|
45
|
+
*
|
|
44
46
|
* @category Components
|
|
45
47
|
*/
|
|
46
48
|
class CameraComponentElement extends ComponentElement {
|
|
@@ -17,6 +17,8 @@ import { ComponentElement } from './component';
|
|
|
17
17
|
* retargets or rebinds picks up the new node's geometry. An entity with no asset-backed render
|
|
18
18
|
* component warns, and the collider has no shape.
|
|
19
19
|
*
|
|
20
|
+
* Engine component: {@link CollisionComponent} (`collision`).
|
|
21
|
+
*
|
|
20
22
|
* @category Components
|
|
21
23
|
*/
|
|
22
24
|
class CollisionComponentElement extends ComponentElement {
|
|
@@ -64,7 +66,9 @@ class CollisionComponentElement extends ComponentElement {
|
|
|
64
66
|
* no attribute to supply it - so the host's visible geometry, the meaning a mesh collider
|
|
65
67
|
* on a glTF node carries, fills the gap. Runs on every application (so a rebound `pc-node`
|
|
66
68
|
* recomputes it) and on a runtime switch to `type="mesh"`; an explicitly assigned
|
|
67
|
-
* `renderAsset` is never overwritten.
|
|
69
|
+
* `renderAsset` is never overwritten. A `pc-model` host entity never carries a render
|
|
70
|
+
* component (the instantiated content beneath it does), so a mesh collider that should take
|
|
71
|
+
* an asset's geometry belongs on a bound `pc-node`.
|
|
68
72
|
*/
|
|
69
73
|
private _applyMeshGeometryDefault() {
|
|
70
74
|
const component = this.component;
|
|
@@ -109,7 +109,7 @@ class ComponentElement extends AsyncElement {
|
|
|
109
109
|
// It still becomes ready (with a null `component`), so warn rather than fail silently
|
|
110
110
|
const label = this.id ? ` '${this.id}'` : '';
|
|
111
111
|
console.warn(
|
|
112
|
-
`${this.tagName.toLowerCase()}${label} must be a descendant of pc-entity - component not added`
|
|
112
|
+
`${this.tagName.toLowerCase()}${label} must be a descendant of pc-entity, pc-model or pc-node - component not added`
|
|
113
113
|
);
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
@@ -214,8 +214,9 @@ class ComponentElement extends AsyncElement {
|
|
|
214
214
|
|
|
215
215
|
/**
|
|
216
216
|
* The PlayCanvas component instance. `null` until the element is ready, and also for an
|
|
217
|
-
* element that is not a descendant of
|
|
218
|
-
* element's `ready()` promise
|
|
217
|
+
* element that is not a descendant of an entity-fronting element (`<pc-entity>`,
|
|
218
|
+
* `<pc-model>` or `<pc-node>`) — await {@link whenReady} or the element's `ready()` promise
|
|
219
|
+
* before accessing it.
|
|
219
220
|
* @returns The component instance, or `null`.
|
|
220
221
|
*/
|
|
221
222
|
get component(): Component | null {
|
|
@@ -12,6 +12,13 @@ import { ComponentElement } from './component';
|
|
|
12
12
|
* The ElementComponentElement interface also inherits the properties and methods of the
|
|
13
13
|
* {@link HTMLElement} interface.
|
|
14
14
|
*
|
|
15
|
+
* Despite the name, this is not a base class or a generic wrapper: it is the engine's 2D UI
|
|
16
|
+
* component, which gives its host entity a rectangle in a `<pc-screen>` hierarchy that draws
|
|
17
|
+
* either an image, a line of text or nothing (`type="image"`, `"text"` or `"group"`). The tag
|
|
18
|
+
* spells the engine component it adds, as every component element does.
|
|
19
|
+
*
|
|
20
|
+
* Engine component: {@link ElementComponent} (`element`).
|
|
21
|
+
*
|
|
15
22
|
* @category Components
|
|
16
23
|
*/
|
|
17
24
|
class ElementComponentElement extends ComponentElement {
|
|
@@ -11,6 +11,8 @@ import { ComponentElement } from './component';
|
|
|
11
11
|
* The GSplatComponentElement interface also inherits the properties and methods of the
|
|
12
12
|
* {@link HTMLElement} interface.
|
|
13
13
|
*
|
|
14
|
+
* Engine component: {@link GSplatComponent} (`gsplat`).
|
|
15
|
+
*
|
|
14
16
|
* @category Components
|
|
15
17
|
*/
|
|
16
18
|
class GSplatComponentElement extends ComponentElement {
|
|
@@ -26,6 +26,8 @@ type MotionMode = 'locked' | 'limited' | 'free';
|
|
|
26
26
|
* constraint breaks. A broken joint no longer constrains its bodies; calling `refreshFrames()` on
|
|
27
27
|
* the underlying component re-attaches it. Bubbles and is composed.
|
|
28
28
|
*
|
|
29
|
+
* Engine component: {@link JointComponent} (`joint`).
|
|
30
|
+
*
|
|
29
31
|
* @category Components
|
|
30
32
|
*/
|
|
31
33
|
class JointComponentElement extends ComponentElement {
|
|
@@ -6,10 +6,12 @@ import { ComponentElement } from './component';
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The LayoutChildComponentElement interface provides properties and methods for manipulating
|
|
9
|
-
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-
|
|
9
|
+
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-layout-child/ | `<pc-layout-child>`} elements.
|
|
10
10
|
* The LayoutChildComponentElement interface also inherits the properties and methods of the
|
|
11
11
|
* {@link HTMLElement} interface.
|
|
12
12
|
*
|
|
13
|
+
* Engine component: {@link LayoutChildComponent} (`layoutchild`).
|
|
14
|
+
*
|
|
13
15
|
* @category Components
|
|
14
16
|
*/
|
|
15
17
|
class LayoutChildComponentElement extends ComponentElement {
|
|
@@ -229,6 +231,6 @@ class LayoutChildComponentElement extends ComponentElement {
|
|
|
229
231
|
}
|
|
230
232
|
}
|
|
231
233
|
|
|
232
|
-
customElements.define('pc-
|
|
234
|
+
customElements.define('pc-layout-child', LayoutChildComponentElement);
|
|
233
235
|
|
|
234
236
|
export { LayoutChildComponentElement };
|
|
@@ -28,10 +28,12 @@ const fittings = new Map<'none' | 'stretch' | 'shrink' | 'both', number>([
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* The LayoutGroupComponentElement interface provides properties and methods for manipulating
|
|
31
|
-
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-
|
|
31
|
+
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-layout-group/ | `<pc-layout-group>`} elements.
|
|
32
32
|
* The LayoutGroupComponentElement interface also inherits the properties and methods of the
|
|
33
33
|
* {@link HTMLElement} interface.
|
|
34
34
|
*
|
|
35
|
+
* Engine component: {@link LayoutGroupComponent} (`layoutgroup`).
|
|
36
|
+
*
|
|
35
37
|
* @category Components
|
|
36
38
|
*/
|
|
37
39
|
class LayoutGroupComponentElement extends ComponentElement {
|
|
@@ -304,6 +306,6 @@ class LayoutGroupComponentElement extends ComponentElement {
|
|
|
304
306
|
}
|
|
305
307
|
}
|
|
306
308
|
|
|
307
|
-
customElements.define('pc-
|
|
309
|
+
customElements.define('pc-layout-group', LayoutGroupComponentElement);
|
|
308
310
|
|
|
309
311
|
export { LayoutGroupComponentElement };
|
|
@@ -37,6 +37,8 @@ const shadowTypes = new Map<
|
|
|
37
37
|
* The LightComponentElement interface also inherits the properties and methods of the
|
|
38
38
|
* {@link HTMLElement} interface.
|
|
39
39
|
*
|
|
40
|
+
* Engine component: {@link LightComponent} (`light`).
|
|
41
|
+
*
|
|
40
42
|
* @category Components
|
|
41
43
|
*/
|
|
42
44
|
class LightComponentElement extends ComponentElement {
|
|
@@ -6,10 +6,12 @@ import { ComponentElement } from './component';
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The ParticleSystemComponentElement interface provides properties and methods for manipulating
|
|
9
|
-
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-
|
|
9
|
+
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-particle-system/ | `<pc-particle-system>`} elements.
|
|
10
10
|
* The ParticleSystemComponentElement interface also inherits the properties and methods of the
|
|
11
11
|
* {@link HTMLElement} interface.
|
|
12
12
|
*
|
|
13
|
+
* Engine component: {@link ParticleSystemComponent} (`particlesystem`).
|
|
14
|
+
*
|
|
13
15
|
* @category Components
|
|
14
16
|
*/
|
|
15
17
|
class ParticleSystemComponentElement extends ComponentElement {
|
|
@@ -147,6 +149,6 @@ class ParticleSystemComponentElement extends ComponentElement {
|
|
|
147
149
|
}
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
customElements.define('pc-
|
|
152
|
+
customElements.define('pc-particle-system', ParticleSystemComponentElement);
|
|
151
153
|
|
|
152
154
|
export { ParticleSystemComponentElement };
|
|
@@ -15,6 +15,8 @@ import { ComponentElement } from './component';
|
|
|
15
15
|
* to `box`). It does not cover the engine's `asset` render type, since there is no way to supply
|
|
16
16
|
* a render asset here — use `pc-model` for glTF content instead.
|
|
17
17
|
*
|
|
18
|
+
* Engine component: {@link RenderComponent} (`render`).
|
|
19
|
+
*
|
|
18
20
|
* @category Components
|
|
19
21
|
*/
|
|
20
22
|
class RenderComponentElement extends ComponentElement {
|
|
@@ -7,10 +7,12 @@ import { ComponentElement } from './component';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The RigidBodyComponentElement interface provides properties and methods for manipulating
|
|
10
|
-
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-
|
|
10
|
+
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-rigid-body/ | `<pc-rigid-body>`} elements.
|
|
11
11
|
* The RigidBodyComponentElement interface also inherits the properties and methods of the
|
|
12
12
|
* {@link HTMLElement} interface.
|
|
13
13
|
*
|
|
14
|
+
* Engine component: {@link RigidBodyComponent} (`rigidbody`).
|
|
15
|
+
*
|
|
14
16
|
* @category Components
|
|
15
17
|
*/
|
|
16
18
|
class RigidBodyComponentElement extends ComponentElement {
|
|
@@ -235,6 +237,6 @@ class RigidBodyComponentElement extends ComponentElement {
|
|
|
235
237
|
}
|
|
236
238
|
}
|
|
237
239
|
|
|
238
|
-
customElements.define('pc-
|
|
240
|
+
customElements.define('pc-rigid-body', RigidBodyComponentElement);
|
|
239
241
|
|
|
240
242
|
export { RigidBodyComponentElement };
|
|
@@ -20,6 +20,8 @@ const scaleModes = new Map<'none' | 'blend', string>([
|
|
|
20
20
|
* The ScreenComponentElement interface also inherits the properties and methods of the
|
|
21
21
|
* {@link HTMLElement} interface.
|
|
22
22
|
*
|
|
23
|
+
* Engine component: {@link ScreenComponent} (`screen`).
|
|
24
|
+
*
|
|
23
25
|
* @category Components
|
|
24
26
|
*/
|
|
25
27
|
class ScreenComponentElement extends ComponentElement {
|
|
@@ -15,14 +15,14 @@ import {
|
|
|
15
15
|
} from '../parse';
|
|
16
16
|
|
|
17
17
|
import { ComponentElement } from './component';
|
|
18
|
-
import {
|
|
18
|
+
import { ScriptInstanceElement } from './script-instance';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Attributes on `pc-script` that never map to script attributes: the element's own API (derived
|
|
21
|
+
* Attributes on `pc-script-instance` that never map to script attributes: the element's own API (derived
|
|
22
22
|
* from its observed attributes) plus reserved and global HTML attribute names.
|
|
23
23
|
*/
|
|
24
24
|
const RESERVED_ATTRIBUTES = new Set([
|
|
25
|
-
...
|
|
25
|
+
...ScriptInstanceElement.observedAttributes,
|
|
26
26
|
'accesskey',
|
|
27
27
|
'autocapitalize',
|
|
28
28
|
'autofocus',
|
|
@@ -54,7 +54,7 @@ const RESERVED_ATTRIBUTES = new Set([
|
|
|
54
54
|
]);
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* Checks whether a `pc-script` attribute name is reserved (and so never maps to a script
|
|
57
|
+
* Checks whether a `pc-script-instance` attribute name is reserved (and so never maps to a script
|
|
58
58
|
* attribute). Reserved names are the element's own API, global HTML attribute names, `data-*`
|
|
59
59
|
* and `aria-*` attributes, names starting with `_` (framework-stamped attributes), and real
|
|
60
60
|
* inline event handler names (`onclick` etc. — detected via the platform, so script attributes
|
|
@@ -244,10 +244,12 @@ export type ScriptNameChangeEvent = {
|
|
|
244
244
|
|
|
245
245
|
/**
|
|
246
246
|
* The ScriptComponentElement interface provides properties and methods for manipulating
|
|
247
|
-
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-
|
|
247
|
+
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-script/ | `<pc-script>`} elements.
|
|
248
248
|
* The ScriptComponentElement interface also inherits the properties and methods of the
|
|
249
249
|
* {@link HTMLElement} interface.
|
|
250
250
|
*
|
|
251
|
+
* Engine component: {@link ScriptComponent} (`script`).
|
|
252
|
+
*
|
|
251
253
|
* @category Components
|
|
252
254
|
*/
|
|
253
255
|
class ScriptComponentElement extends ComponentElement {
|
|
@@ -268,15 +270,24 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
268
270
|
|
|
269
271
|
connectedCallback() {
|
|
270
272
|
// (Re-)observe on every connection - disconnectedCallback disconnects the observer.
|
|
271
|
-
// Attribute changes on child pc-script elements are watched here too: per-property
|
|
273
|
+
// Attribute changes on child pc-script-instance elements are watched here too: per-property
|
|
272
274
|
// script attributes are not statically known, so they cannot use observedAttributes.
|
|
273
275
|
this.observer.observe(this, { childList: true, subtree: true, attributes: true });
|
|
274
276
|
return super.connectedCallback();
|
|
275
277
|
}
|
|
276
278
|
|
|
277
279
|
protected initComponent() {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
+
this.querySelectorAll<ScriptInstanceElement>(':scope > pc-script-instance').forEach((scriptElement) => {
|
|
281
|
+
// A host readiness cycle re-runs this against a component that can have survived it
|
|
282
|
+
// (a pc-model reloading content on its stable host entity). The engine rejects a
|
|
283
|
+
// duplicate create - returning null, silently in production builds - which would
|
|
284
|
+
// skip attribute application entirely. A surviving instance is re-asserted instead,
|
|
285
|
+
// so both cycle outcomes leave the component reflecting the element's declared state.
|
|
286
|
+
const script = this.scriptFor(scriptElement);
|
|
287
|
+
if (script) {
|
|
288
|
+
this.applyDeclaredState(script, scriptElement);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
280
291
|
this.createScript(scriptElement);
|
|
281
292
|
});
|
|
282
293
|
}
|
|
@@ -424,12 +435,12 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
424
435
|
}
|
|
425
436
|
|
|
426
437
|
/**
|
|
427
|
-
* Returns the camelCase keys of the per-property attributes present on a `pc-script`
|
|
438
|
+
* Returns the camelCase keys of the per-property attributes present on a `pc-script-instance`
|
|
428
439
|
* element.
|
|
429
|
-
* @param scriptElement - The `pc-script` element.
|
|
440
|
+
* @param scriptElement - The `pc-script-instance` element.
|
|
430
441
|
* @returns The camelCase keys.
|
|
431
442
|
*/
|
|
432
|
-
private inlineKeys(scriptElement:
|
|
443
|
+
private inlineKeys(scriptElement: ScriptInstanceElement): Set<string> {
|
|
433
444
|
const keys = new Set<string>();
|
|
434
445
|
for (const attr of Array.from(scriptElement.attributes)) {
|
|
435
446
|
if (!isReservedAttribute(attr.name)) {
|
|
@@ -440,13 +451,13 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
440
451
|
}
|
|
441
452
|
|
|
442
453
|
/**
|
|
443
|
-
* Resolves the script instance owned by a `pc-script` element. Returns `null` when the
|
|
454
|
+
* Resolves the script instance owned by a `pc-script-instance` element. Returns `null` when the
|
|
444
455
|
* element has no created script, or when its name resolves to a script created by a
|
|
445
456
|
* different element (e.g. a duplicate-named sibling).
|
|
446
|
-
* @param scriptElement - The `pc-script` element.
|
|
457
|
+
* @param scriptElement - The `pc-script-instance` element.
|
|
447
458
|
* @returns The owned script, or `null`.
|
|
448
459
|
*/
|
|
449
|
-
private scriptFor(scriptElement:
|
|
460
|
+
private scriptFor(scriptElement: ScriptInstanceElement): Script | null {
|
|
450
461
|
const name = scriptElement.getAttribute('name');
|
|
451
462
|
if (!name || !this.component) return null;
|
|
452
463
|
|
|
@@ -455,7 +466,7 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
455
466
|
}
|
|
456
467
|
|
|
457
468
|
private handleScriptAttributesChange(event: ScriptAttributesChangeEvent) {
|
|
458
|
-
const scriptElement = event.target as
|
|
469
|
+
const scriptElement = event.target as ScriptInstanceElement;
|
|
459
470
|
const script = this.scriptFor(scriptElement);
|
|
460
471
|
if (script) {
|
|
461
472
|
// Per-property attributes stay authoritative: keys they pin are excluded here
|
|
@@ -464,7 +475,7 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
464
475
|
}
|
|
465
476
|
|
|
466
477
|
private handleScriptEnableChange(event: ScriptEnableChangeEvent) {
|
|
467
|
-
const scriptElement = event.target as
|
|
478
|
+
const scriptElement = event.target as ScriptInstanceElement;
|
|
468
479
|
|
|
469
480
|
// Apply any queued per-property changes first, so that initialize() (fired by the
|
|
470
481
|
// engine on first effective enable) sees every attribute value set this tick
|
|
@@ -477,7 +488,7 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
477
488
|
}
|
|
478
489
|
|
|
479
490
|
/**
|
|
480
|
-
* Handles a runtime `name` change on a child `pc-script`, swapping the engine script instance
|
|
491
|
+
* Handles a runtime `name` change on a child `pc-script-instance`, swapping the engine script instance
|
|
481
492
|
* to match. Without this the element would keep pointing at the old-name instance: the old
|
|
482
493
|
* script would go on running while every subsequent update (attribute changes, enable
|
|
483
494
|
* changes, destruction on removal) resolved the new name and silently no-opped.
|
|
@@ -487,10 +498,10 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
487
498
|
* @param event - The name change event.
|
|
488
499
|
*/
|
|
489
500
|
private handleScriptNameChange(event: ScriptNameChangeEvent) {
|
|
490
|
-
const scriptElement = event.target as
|
|
501
|
+
const scriptElement = event.target as ScriptInstanceElement;
|
|
491
502
|
|
|
492
|
-
// Only direct children are managed, matching initComponent's ':scope > pc-script'
|
|
493
|
-
// contract - the event bubbles, so a deeper pc-script must not be created here
|
|
503
|
+
// Only direct children are managed, matching initComponent's ':scope > pc-script-instance'
|
|
504
|
+
// contract - the event bubbles, so a deeper pc-script-instance must not be created here
|
|
494
505
|
if (scriptElement.parentElement !== this) return;
|
|
495
506
|
|
|
496
507
|
// Before the component exists there is nothing to swap: initComponent creates from
|
|
@@ -509,14 +520,14 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
509
520
|
}
|
|
510
521
|
|
|
511
522
|
/**
|
|
512
|
-
* Creates the script instance for a `pc-script` element. The instance is created disabled,
|
|
523
|
+
* Creates the script instance for a `pc-script-instance` element. The instance is created disabled,
|
|
513
524
|
* the element's converted attributes are merged over the instance's defaults (which is what
|
|
514
525
|
* allows plain numeric arrays to be typed against those defaults), and only then is the
|
|
515
526
|
* declared enabled state applied — so `initialize()` runs with every attribute in place.
|
|
516
|
-
* @param scriptElement - The `pc-script` element to create the script instance for.
|
|
527
|
+
* @param scriptElement - The `pc-script-instance` element to create the script instance for.
|
|
517
528
|
* @returns The created script, or `null`.
|
|
518
529
|
*/
|
|
519
|
-
private createScript(scriptElement:
|
|
530
|
+
private createScript(scriptElement: ScriptInstanceElement): Script | null {
|
|
520
531
|
const name = scriptElement.getAttribute('name');
|
|
521
532
|
if (!name || !this.component) return null;
|
|
522
533
|
|
|
@@ -525,11 +536,7 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
525
536
|
|
|
526
537
|
scriptElement._script = script;
|
|
527
538
|
|
|
528
|
-
|
|
529
|
-
// attributes: each property is written exactly once and individual attributes win
|
|
530
|
-
this.applyAttributes(script, scriptElement.scriptAttributes, this.inlineKeys(scriptElement));
|
|
531
|
-
this.applyInlineAttributes(script, scriptElement);
|
|
532
|
-
script.enabled = scriptElement.enabled;
|
|
539
|
+
this.applyDeclaredState(script, scriptElement);
|
|
533
540
|
|
|
534
541
|
scriptElement._onScriptCreated();
|
|
535
542
|
|
|
@@ -537,14 +544,28 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
537
544
|
}
|
|
538
545
|
|
|
539
546
|
/**
|
|
540
|
-
* Applies
|
|
547
|
+
* Applies a `pc-script-instance` element's declared state to a script instance: the `attributes` JSON
|
|
548
|
+
* first with per-property-shadowed keys stripped, then the per-property attributes — each
|
|
549
|
+
* property is written exactly once and individual attributes win — and finally the declared
|
|
550
|
+
* enabled state, so `initialize()` runs with every attribute in place.
|
|
551
|
+
* @param script - The script instance.
|
|
552
|
+
* @param scriptElement - The `pc-script-instance` element holding the declared state.
|
|
553
|
+
*/
|
|
554
|
+
private applyDeclaredState(script: Script, scriptElement: ScriptInstanceElement) {
|
|
555
|
+
this.applyAttributes(script, scriptElement.scriptAttributes, this.inlineKeys(scriptElement));
|
|
556
|
+
this.applyInlineAttributes(script, scriptElement);
|
|
557
|
+
script.enabled = scriptElement.enabled;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Applies the per-property attributes present on a `pc-script-instance` element — any attribute that
|
|
541
562
|
* is not part of the element's own API or a reserved HTML attribute name. These are applied
|
|
542
563
|
* after the `attributes` JSON, so an individual attribute always takes precedence over the
|
|
543
564
|
* blob.
|
|
544
565
|
* @param script - The script to apply the attributes to.
|
|
545
|
-
* @param scriptElement - The `pc-script` element holding the attributes.
|
|
566
|
+
* @param scriptElement - The `pc-script-instance` element holding the attributes.
|
|
546
567
|
*/
|
|
547
|
-
private applyInlineAttributes(script: any, scriptElement:
|
|
568
|
+
private applyInlineAttributes(script: any, scriptElement: ScriptInstanceElement) {
|
|
548
569
|
const scriptName = scriptElement.getAttribute('name') ?? '';
|
|
549
570
|
for (const attr of Array.from(scriptElement.attributes)) {
|
|
550
571
|
if (!isReservedAttribute(attr.name)) {
|
|
@@ -554,13 +575,13 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
554
575
|
}
|
|
555
576
|
|
|
556
577
|
/**
|
|
557
|
-
* Applies a single per-property attribute change to the script of a `pc-script` element.
|
|
578
|
+
* Applies a single per-property attribute change to the script of a `pc-script-instance` element.
|
|
558
579
|
* When the attribute has been removed, the value from the `attributes` JSON (if any) takes
|
|
559
580
|
* effect again.
|
|
560
|
-
* @param scriptElement - The `pc-script` element whose attribute changed.
|
|
581
|
+
* @param scriptElement - The `pc-script-instance` element whose attribute changed.
|
|
561
582
|
* @param attributeName - The name of the changed attribute.
|
|
562
583
|
*/
|
|
563
|
-
private applyScriptProperty(scriptElement:
|
|
584
|
+
private applyScriptProperty(scriptElement: ScriptInstanceElement, attributeName: string) {
|
|
564
585
|
const script = this.scriptFor(scriptElement);
|
|
565
586
|
if (!script) return;
|
|
566
587
|
|
|
@@ -596,7 +617,7 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
596
617
|
|
|
597
618
|
if (typeof current === 'function' || SCRIPT_API_MEMBERS.has(key)) {
|
|
598
619
|
console.warn(
|
|
599
|
-
`Ignoring attribute '${attributeName}' on pc-script '${scriptName}' - '${key}' is part of the Script API.`
|
|
620
|
+
`Ignoring attribute '${attributeName}' on pc-script-instance '${scriptName}' - '${key}' is part of the Script API.`
|
|
600
621
|
);
|
|
601
622
|
return;
|
|
602
623
|
}
|
|
@@ -651,11 +672,11 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
651
672
|
|
|
652
673
|
private handleMutations(mutations: MutationRecord[]) {
|
|
653
674
|
for (const mutation of mutations) {
|
|
654
|
-
// Handle per-property attribute changes on child pc-script elements
|
|
675
|
+
// Handle per-property attribute changes on child pc-script-instance elements
|
|
655
676
|
if (mutation.type === 'attributes') {
|
|
656
677
|
const target = mutation.target;
|
|
657
678
|
if (
|
|
658
|
-
target instanceof
|
|
679
|
+
target instanceof ScriptInstanceElement &&
|
|
659
680
|
target.parentElement === this &&
|
|
660
681
|
mutation.attributeName &&
|
|
661
682
|
!isReservedAttribute(mutation.attributeName)
|
|
@@ -667,17 +688,17 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
667
688
|
|
|
668
689
|
// Only direct children are managed - the observer watches the subtree for attribute
|
|
669
690
|
// changes, but deeper childList records must not create or destroy scripts
|
|
670
|
-
// (matching initComponent's ':scope > pc-script' contract)
|
|
691
|
+
// (matching initComponent's ':scope > pc-script-instance' contract)
|
|
671
692
|
if (mutation.target !== this) {
|
|
672
693
|
continue;
|
|
673
694
|
}
|
|
674
695
|
|
|
675
|
-
// Handle removed nodes first, so that replacing a pc-script with a same-named one
|
|
696
|
+
// Handle removed nodes first, so that replacing a pc-script-instance with a same-named one
|
|
676
697
|
// destroys the old script before the replacement is created. Only destroy a script
|
|
677
698
|
// this element actually owns - a duplicate-named element whose own create() failed
|
|
678
699
|
// must not take down the live script on removal.
|
|
679
700
|
mutation.removedNodes.forEach((node) => {
|
|
680
|
-
if (node instanceof
|
|
701
|
+
if (node instanceof ScriptInstanceElement) {
|
|
681
702
|
const scriptName = node.getAttribute('name');
|
|
682
703
|
if (
|
|
683
704
|
scriptName &&
|
|
@@ -693,7 +714,7 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
693
714
|
|
|
694
715
|
// Handle added nodes
|
|
695
716
|
mutation.addedNodes.forEach((node) => {
|
|
696
|
-
if (node instanceof
|
|
717
|
+
if (node instanceof ScriptInstanceElement) {
|
|
697
718
|
this.createScript(node);
|
|
698
719
|
}
|
|
699
720
|
});
|
|
@@ -714,6 +735,6 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
714
735
|
}
|
|
715
736
|
}
|
|
716
737
|
|
|
717
|
-
customElements.define('pc-
|
|
738
|
+
customElements.define('pc-script', ScriptComponentElement);
|
|
718
739
|
|
|
719
740
|
export { ScriptComponentElement };
|
|
@@ -4,8 +4,8 @@ import { AsyncElement } from '../async-element';
|
|
|
4
4
|
import { parseBool } from '../parse';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* The
|
|
8
|
-
* `<pc-script>` elements. The
|
|
7
|
+
* The ScriptInstanceElement interface provides properties and methods for manipulating
|
|
8
|
+
* `<pc-script-instance>` elements. The ScriptInstanceElement interface also inherits the properties and
|
|
9
9
|
* methods of the {@link AsyncElement} interface.
|
|
10
10
|
*
|
|
11
11
|
* Script attributes can be supplied through two channels:
|
|
@@ -27,7 +27,7 @@ import { parseBool } from '../parse';
|
|
|
27
27
|
* new-name one, re-applying both attribute channels to it.
|
|
28
28
|
*
|
|
29
29
|
* The element becomes ready once its script instance has been created by the parent
|
|
30
|
-
* `<pc-
|
|
30
|
+
* `<pc-script>` element.
|
|
31
31
|
*
|
|
32
32
|
* @fires {CustomEvent} scriptattributeschange - Fired when the script's attributes change. The
|
|
33
33
|
* `detail` carries the new `attributes` object. Bubbles.
|
|
@@ -36,13 +36,13 @@ import { parseBool } from '../parse';
|
|
|
36
36
|
* @fires {CustomEvent} scriptnamechange - Fired when the script is renamed on a live element. The
|
|
37
37
|
* `detail` carries `oldName` and `newName`. Bubbles.
|
|
38
38
|
*/
|
|
39
|
-
class
|
|
39
|
+
class ScriptInstanceElement extends AsyncElement {
|
|
40
40
|
private _attributes: Record<string, any> = {};
|
|
41
41
|
|
|
42
42
|
private _enabled = true;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* The Script instance created for this element by its parent `<pc-
|
|
45
|
+
* The Script instance created for this element by its parent `<pc-script>` element.
|
|
46
46
|
* @internal
|
|
47
47
|
*/
|
|
48
48
|
_script: Script | null = null;
|
|
@@ -97,11 +97,11 @@ class ScriptElement extends AsyncElement {
|
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* Sets the name of the script to create. The `name` attribute is the single source of truth
|
|
100
|
-
* (it is what the parent `<pc-
|
|
100
|
+
* (it is what the parent `<pc-script>` element reads when creating the instance), so the
|
|
101
101
|
* property writes through to it — assigning before insertion works as expected:
|
|
102
102
|
*
|
|
103
103
|
* ```js
|
|
104
|
-
* const script = document.createElement('pc-script');
|
|
104
|
+
* const script = document.createElement('pc-script-instance');
|
|
105
105
|
* script.name = 'rotate';
|
|
106
106
|
* scriptsElement.appendChild(script);
|
|
107
107
|
* await script.ready();
|
|
@@ -131,11 +131,11 @@ class ScriptElement extends AsyncElement {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
connectedCallback() {
|
|
134
|
-
// Script instances are created by the parent pc-
|
|
134
|
+
// Script instances are created by the parent pc-script element, so an element placed
|
|
135
135
|
// anywhere else is inert and never becomes ready - warn rather than hang silently
|
|
136
|
-
if (this.parentElement?.tagName !== 'PC-
|
|
136
|
+
if (this.parentElement?.tagName !== 'PC-SCRIPT') {
|
|
137
137
|
console.warn(
|
|
138
|
-
`pc-script '${this.getAttribute('name')}' must be a direct child of pc-
|
|
138
|
+
`pc-script-instance '${this.getAttribute('name')}' must be a direct child of pc-script - script not created`
|
|
139
139
|
);
|
|
140
140
|
}
|
|
141
141
|
}
|
|
@@ -149,7 +149,7 @@ class ScriptElement extends AsyncElement {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
|
-
* Called by the parent `<pc-
|
|
152
|
+
* Called by the parent `<pc-script>` element when the script instance has been created.
|
|
153
153
|
* Creation can happen more than once per connection (a runtime `name` change recreates the
|
|
154
154
|
* instance), but `_onReady` signals readiness at most once per cycle.
|
|
155
155
|
* @internal
|
|
@@ -173,7 +173,7 @@ class ScriptElement extends AsyncElement {
|
|
|
173
173
|
this.scriptAttributes = JSON.parse(newValue);
|
|
174
174
|
} catch (error) {
|
|
175
175
|
console.warn(
|
|
176
|
-
`Invalid 'attributes' JSON on pc-script '${this.getAttribute('name')}': ${(error as Error).message}`
|
|
176
|
+
`Invalid 'attributes' JSON on pc-script-instance '${this.getAttribute('name')}': ${(error as Error).message}`
|
|
177
177
|
);
|
|
178
178
|
}
|
|
179
179
|
break;
|
|
@@ -197,6 +197,6 @@ class ScriptElement extends AsyncElement {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
customElements.define('pc-script',
|
|
200
|
+
customElements.define('pc-script-instance', ScriptInstanceElement);
|
|
201
201
|
|
|
202
|
-
export {
|
|
202
|
+
export { ScriptInstanceElement };
|