@playcanvas/web-components 0.16.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-component.d.cts +33 -5
- package/dist/components/anim-component.d.ts +33 -5
- 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 +1603 -986
- 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 +22 -21
- package/dist/index.d.ts +22 -21
- package/dist/model.d.cts +67 -24
- package/dist/model.d.ts +67 -24
- package/dist/pwc.cjs +526 -268
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +526 -268
- 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 +523 -266
- package/dist/pwc.mjs.map +1 -1
- package/dist/vscode.html-custom-data.json +145 -90
- 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 +378 -250
- package/package.json +7 -7
- package/src/app.ts +45 -35
- package/src/async-element.ts +14 -14
- package/src/components/anim-component.ts +84 -14
- 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 +26 -24
- package/src/model.ts +159 -72
- package/src/node.ts +9 -5
- package/src/{module.ts → wasm.ts} +8 -8
|
@@ -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 };
|
|
@@ -25,10 +25,12 @@ const visibilities = new Map<'always' | 'when-required', number>([
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* The ScrollViewComponentElement interface provides properties and methods for manipulating
|
|
28
|
-
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-
|
|
28
|
+
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-scroll-view/ | `<pc-scroll-view>`} elements.
|
|
29
29
|
* The ScrollViewComponentElement interface also inherits the properties and methods of the
|
|
30
30
|
* {@link HTMLElement} interface.
|
|
31
31
|
*
|
|
32
|
+
* Engine component: {@link ScrollViewComponent} (`scrollview`).
|
|
33
|
+
*
|
|
32
34
|
* @category Components
|
|
33
35
|
*/
|
|
34
36
|
class ScrollViewComponentElement extends ComponentElement {
|
|
@@ -437,6 +439,6 @@ class ScrollViewComponentElement extends ComponentElement {
|
|
|
437
439
|
}
|
|
438
440
|
}
|
|
439
441
|
|
|
440
|
-
customElements.define('pc-
|
|
442
|
+
customElements.define('pc-scroll-view', ScrollViewComponentElement);
|
|
441
443
|
|
|
442
444
|
export { ScrollViewComponentElement };
|
|
@@ -16,6 +16,8 @@ const orientations = new Map<'horizontal' | 'vertical', number>([
|
|
|
16
16
|
* The ScrollbarComponentElement interface also inherits the properties and methods of the
|
|
17
17
|
* {@link HTMLElement} interface.
|
|
18
18
|
*
|
|
19
|
+
* Engine component: {@link ScrollbarComponent} (`scrollbar`).
|
|
20
|
+
*
|
|
19
21
|
* @category Components
|
|
20
22
|
*/
|
|
21
23
|
class ScrollbarComponentElement extends ComponentElement {
|
|
@@ -6,10 +6,12 @@ import { ComponentElement } from './component';
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The SoundComponentElement 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-sound/ | `<pc-sound>`} elements.
|
|
10
10
|
* The SoundComponentElement interface also inherits the properties and methods of the
|
|
11
11
|
* {@link HTMLElement} interface.
|
|
12
12
|
*
|
|
13
|
+
* Engine component: {@link SoundComponent} (`sound`).
|
|
14
|
+
*
|
|
13
15
|
* @category Components
|
|
14
16
|
*/
|
|
15
17
|
class SoundComponentElement extends ComponentElement {
|
|
@@ -227,6 +229,6 @@ class SoundComponentElement extends ComponentElement {
|
|
|
227
229
|
}
|
|
228
230
|
}
|
|
229
231
|
|
|
230
|
-
customElements.define('pc-
|
|
232
|
+
customElements.define('pc-sound', SoundComponentElement);
|
|
231
233
|
|
|
232
234
|
export { SoundComponentElement };
|
|
@@ -8,7 +8,7 @@ import { SoundComponentElement } from './sound-component';
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* The SoundSlotElement interface provides properties and methods for manipulating
|
|
11
|
-
* `<pc-sound>` elements. The SoundSlotElement interface also inherits the properties and
|
|
11
|
+
* `<pc-sound-slot>` elements. The SoundSlotElement interface also inherits the properties and
|
|
12
12
|
* methods of the {@link AsyncElement} interface.
|
|
13
13
|
*/
|
|
14
14
|
class SoundSlotElement extends AsyncElement {
|
|
@@ -31,7 +31,7 @@ class SoundSlotElement extends AsyncElement {
|
|
|
31
31
|
private _volume = 1;
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* The `<pc-
|
|
34
|
+
* The `<pc-sound>` this slot was added to, captured at connect time.
|
|
35
35
|
*
|
|
36
36
|
* `disconnectedCallback` cannot rediscover it: by the time the element is disconnected its
|
|
37
37
|
* `parentElement` is already `null`, so a lookup would both fail to find the component and
|
|
@@ -106,7 +106,7 @@ class SoundSlotElement extends AsyncElement {
|
|
|
106
106
|
const soundElement = this.parentElement as SoundComponentElement;
|
|
107
107
|
|
|
108
108
|
if (!(soundElement instanceof SoundComponentElement)) {
|
|
109
|
-
console.warn('pc-sound must be a direct child of a pc-
|
|
109
|
+
console.warn('pc-sound-slot must be a direct child of a pc-sound element');
|
|
110
110
|
return null;
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -324,6 +324,6 @@ class SoundSlotElement extends AsyncElement {
|
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
-
customElements.define('pc-sound', SoundSlotElement);
|
|
327
|
+
customElements.define('pc-sound-slot', SoundSlotElement);
|
|
328
328
|
|
|
329
329
|
export { SoundSlotElement };
|
package/src/entity-base.ts
CHANGED
|
@@ -17,11 +17,12 @@ export const POINTER_ATTRIBUTES = [
|
|
|
17
17
|
] as const;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* The base class for elements that front an engine {@link Entity}: `<pc-entity
|
|
21
|
-
* one, and `<pc-node>`, which binds to one inside a model's
|
|
22
|
-
* what
|
|
23
|
-
* picked scene nodes back to elements by identity,
|
|
24
|
-
* bookkeeping that lets the application lazily attach
|
|
20
|
+
* The base class for elements that front an engine {@link Entity}: `<pc-entity>` and
|
|
21
|
+
* `<pc-model>`, which create one, and `<pc-node>`, which binds to one inside a model's
|
|
22
|
+
* instantiated hierarchy. It carries what all of them need — the `entity` contract, registration
|
|
23
|
+
* with the owning application (which joins picked scene nodes back to elements by identity,
|
|
24
|
+
* never by name), and the pointer listener bookkeeping that lets the application lazily attach
|
|
25
|
+
* its canvas handlers.
|
|
25
26
|
*/
|
|
26
27
|
class EntityBaseElement extends AsyncElement {
|
|
27
28
|
protected _entity: Entity | null = null;
|