@playcanvas/web-components 0.11.0 → 0.11.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 (78) hide show
  1. package/README.md +1 -1
  2. package/dist/app.d.ts +18 -38
  3. package/dist/asset.d.ts +8 -7
  4. package/dist/async-element.d.ts +21 -5
  5. package/dist/components/button-component.d.ts +3 -7
  6. package/dist/components/camera-component.d.ts +3 -7
  7. package/dist/components/collision-component.d.ts +3 -7
  8. package/dist/components/component.d.ts +22 -4
  9. package/dist/components/element-component.d.ts +4 -8
  10. package/dist/components/gsplat-component.d.ts +2 -7
  11. package/dist/components/layoutchild-component.d.ts +2 -7
  12. package/dist/components/layoutgroup-component.d.ts +3 -7
  13. package/dist/components/light-component.d.ts +3 -7
  14. package/dist/components/listener-component.d.ts +1 -6
  15. package/dist/components/particlesystem-component.d.ts +2 -7
  16. package/dist/components/render-component.d.ts +2 -7
  17. package/dist/components/rigidbody-component.d.ts +3 -7
  18. package/dist/components/screen-component.d.ts +3 -7
  19. package/dist/components/script-component.d.ts +8 -20
  20. package/dist/components/script.d.ts +2 -22
  21. package/dist/components/scrollbar-component.d.ts +2 -7
  22. package/dist/components/scrollview-component.d.ts +3 -7
  23. package/dist/components/sound-component.d.ts +2 -7
  24. package/dist/components/sound-slot.d.ts +8 -6
  25. package/dist/custom-elements.json +5049 -10696
  26. package/dist/entity.d.ts +5 -11
  27. package/dist/index.d.ts +37 -0
  28. package/dist/material.d.ts +12 -12
  29. package/dist/model.d.ts +21 -5
  30. package/dist/module.d.ts +0 -6
  31. package/dist/parse.d.ts +2 -1
  32. package/dist/pwc.cjs +496 -136
  33. package/dist/pwc.cjs.map +1 -1
  34. package/dist/pwc.js +496 -136
  35. package/dist/pwc.js.map +1 -1
  36. package/dist/pwc.min.js +1 -1
  37. package/dist/pwc.min.js.map +1 -1
  38. package/dist/pwc.min.mjs +1 -1
  39. package/dist/pwc.min.mjs.map +1 -1
  40. package/dist/pwc.mjs +496 -136
  41. package/dist/pwc.mjs.map +1 -1
  42. package/dist/scene.d.ts +4 -7
  43. package/dist/sky.d.ts +13 -5
  44. package/dist/vscode.html-custom-data.json +26 -26
  45. package/dist/web-types.json +545 -536
  46. package/package.json +8 -7
  47. package/src/app.ts +142 -70
  48. package/src/asset.ts +34 -28
  49. package/src/async-element.ts +34 -8
  50. package/src/components/button-component.ts +5 -9
  51. package/src/components/camera-component.ts +24 -10
  52. package/src/components/collision-component.ts +26 -15
  53. package/src/components/component.ts +58 -8
  54. package/src/components/element-component.ts +26 -30
  55. package/src/components/gsplat-component.ts +4 -9
  56. package/src/components/layoutchild-component.ts +4 -9
  57. package/src/components/layoutgroup-component.ts +14 -9
  58. package/src/components/light-component.ts +42 -12
  59. package/src/components/listener-component.ts +1 -7
  60. package/src/components/particlesystem-component.ts +7 -15
  61. package/src/components/render-component.ts +5 -10
  62. package/src/components/rigidbody-component.ts +23 -16
  63. package/src/components/screen-component.ts +5 -9
  64. package/src/components/script-component.ts +108 -46
  65. package/src/components/script.ts +38 -33
  66. package/src/components/scrollbar-component.ts +6 -16
  67. package/src/components/scrollview-component.ts +16 -11
  68. package/src/components/sound-component.ts +10 -15
  69. package/src/components/sound-slot.ts +30 -20
  70. package/src/entity.ts +42 -19
  71. package/src/index.ts +45 -1
  72. package/src/loading-bar.ts +8 -8
  73. package/src/material.ts +63 -37
  74. package/src/model.ts +69 -14
  75. package/src/module.ts +8 -7
  76. package/src/parse.ts +62 -17
  77. package/src/scene.ts +12 -9
  78. package/src/sky.ts +50 -9
@@ -1,9 +1,25 @@
1
- import { Color, LightComponent, SHADOW_PCF1_16F, SHADOW_PCF1_32F, SHADOW_PCF3_16F, SHADOW_PCF3_32F, SHADOW_PCF5_16F, SHADOW_PCF5_32F, SHADOW_PCSS_32F, SHADOW_VSM_16F, SHADOW_VSM_32F } from 'playcanvas';
1
+ import type { LightComponent } from 'playcanvas';
2
+ import {
3
+ Color,
4
+ SHADOW_PCF1_16F,
5
+ SHADOW_PCF1_32F,
6
+ SHADOW_PCF3_16F,
7
+ SHADOW_PCF3_32F,
8
+ SHADOW_PCF5_16F,
9
+ SHADOW_PCF5_32F,
10
+ SHADOW_PCSS_32F,
11
+ SHADOW_VSM_16F,
12
+ SHADOW_VSM_32F
13
+ } from 'playcanvas';
2
14
 
3
- import { ComponentElement } from './component';
4
15
  import { parseBool, parseColor, parseEnum, parseNumber } from '../parse';
5
16
 
6
- const shadowTypes = new Map<'pcf1-16f' | 'pcf1-32f' | 'pcf3-16f' | 'pcf3-32f' | 'pcf5-16f' | 'pcf5-32f' | 'vsm-16f' | 'vsm-32f' | 'pcss-32f', number>([
17
+ import { ComponentElement } from './component';
18
+
19
+ const shadowTypes = new Map<
20
+ 'pcf1-16f' | 'pcf1-32f' | 'pcf3-16f' | 'pcf3-32f' | 'pcf5-16f' | 'pcf5-32f' | 'vsm-16f' | 'vsm-32f' | 'pcss-32f',
21
+ number
22
+ >([
7
23
  ['pcf1-16f', SHADOW_PCF1_16F],
8
24
  ['pcf1-32f', SHADOW_PCF1_32F],
9
25
  ['pcf3-16f', SHADOW_PCF3_16F],
@@ -46,7 +62,16 @@ class LightComponentElement extends ComponentElement {
46
62
 
47
63
  private _shadowResolution = 1024;
48
64
 
49
- private _shadowType: 'pcf1-16f' | 'pcf1-32f' | 'pcf3-16f' | 'pcf3-32f' | 'pcf5-16f' | 'pcf5-32f' | 'vsm-16f' | 'vsm-32f' | 'pcss-32f' = 'pcf3-32f';
65
+ private _shadowType:
66
+ | 'pcf1-16f'
67
+ | 'pcf1-32f'
68
+ | 'pcf3-16f'
69
+ | 'pcf3-32f'
70
+ | 'pcf5-16f'
71
+ | 'pcf5-32f'
72
+ | 'vsm-16f'
73
+ | 'vsm-32f'
74
+ | 'pcss-32f' = 'pcf3-32f';
50
75
 
51
76
  private _type: 'directional' | 'omni' | 'spot' = 'directional';
52
77
 
@@ -67,7 +92,7 @@ class LightComponentElement extends ComponentElement {
67
92
  super('light');
68
93
  }
69
94
 
70
- getInitialComponentData() {
95
+ protected getInitialComponentData() {
71
96
  return {
72
97
  castShadows: this._castShadows,
73
98
  color: this._color,
@@ -322,7 +347,18 @@ class LightComponentElement extends ComponentElement {
322
347
  * - `vsm-32f` - Variance shadow map with 32-bit depth.
323
348
  * - `pcss-32f` - Percentage-closer soft shadow with 32-bit depth.
324
349
  */
325
- set shadowType(value: 'pcf1-16f' | 'pcf1-32f' | 'pcf3-16f' | 'pcf3-32f' | 'pcf5-16f' | 'pcf5-32f' | 'vsm-16f' | 'vsm-32f' | 'pcss-32f') {
350
+ set shadowType(
351
+ value:
352
+ | 'pcf1-16f'
353
+ | 'pcf1-32f'
354
+ | 'pcf3-16f'
355
+ | 'pcf3-32f'
356
+ | 'pcf5-16f'
357
+ | 'pcf5-32f'
358
+ | 'vsm-16f'
359
+ | 'vsm-32f'
360
+ | 'pcss-32f'
361
+ ) {
326
362
  this._shadowType = value;
327
363
  if (this.component) {
328
364
  this.component.shadowType = shadowTypes.get(value) ?? SHADOW_PCF3_32F;
@@ -563,10 +599,4 @@ class LightComponentElement extends ComponentElement {
563
599
 
564
600
  customElements.define('pc-light', LightComponentElement);
565
601
 
566
- declare global {
567
- interface HTMLElementTagNameMap {
568
- 'pc-light': LightComponentElement;
569
- }
570
- }
571
-
572
602
  export { LightComponentElement };
@@ -1,4 +1,4 @@
1
- import { AudioListenerComponent } from 'playcanvas';
1
+ import type { AudioListenerComponent } from 'playcanvas';
2
2
 
3
3
  import { ComponentElement } from './component';
4
4
 
@@ -27,10 +27,4 @@ class ListenerComponentElement extends ComponentElement {
27
27
 
28
28
  customElements.define('pc-listener', ListenerComponentElement);
29
29
 
30
- declare global {
31
- interface HTMLElementTagNameMap {
32
- 'pc-listener': ListenerComponentElement;
33
- }
34
- }
35
-
36
30
  export { ListenerComponentElement };
@@ -1,8 +1,9 @@
1
- import { ParticleSystemComponent } from 'playcanvas';
1
+ import type { ParticleSystemComponent } from 'playcanvas';
2
2
 
3
- import { ComponentElement } from './component';
4
3
  import { AssetElement } from '../asset';
5
4
 
5
+ import { ComponentElement } from './component';
6
+
6
7
  /**
7
8
  * The ParticleSystemComponentElement interface provides properties and methods for manipulating
8
9
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-particles/ | `<pc-particles>`} elements.
@@ -12,14 +13,14 @@ import { AssetElement } from '../asset';
12
13
  * @category Components
13
14
  */
14
15
  class ParticleSystemComponentElement extends ComponentElement {
15
- private _asset: string = '';
16
+ private _asset = '';
16
17
 
17
18
  /** @ignore */
18
19
  constructor() {
19
20
  super('particlesystem');
20
21
  }
21
22
 
22
- getInitialComponentData() {
23
+ protected getInitialComponentData() {
23
24
  const asset = AssetElement.get(this._asset);
24
25
  if (!asset) {
25
26
  return {};
@@ -51,7 +52,7 @@ class ParticleSystemComponentElement extends ComponentElement {
51
52
 
52
53
  // Set all the config properties on the component
53
54
  for (const key in resource) {
54
- if (resource.hasOwnProperty(key)) {
55
+ if (Object.hasOwn(resource, key)) {
55
56
  (this.component as any)[key] = resource[key];
56
57
  }
57
58
  }
@@ -133,10 +134,7 @@ class ParticleSystemComponentElement extends ComponentElement {
133
134
  }
134
135
 
135
136
  static get observedAttributes() {
136
- return [
137
- ...super.observedAttributes,
138
- 'asset'
139
- ];
137
+ return [...super.observedAttributes, 'asset'];
140
138
  }
141
139
 
142
140
  attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {
@@ -152,10 +150,4 @@ class ParticleSystemComponentElement extends ComponentElement {
152
150
 
153
151
  customElements.define('pc-particles', ParticleSystemComponentElement);
154
152
 
155
- declare global {
156
- interface HTMLElementTagNameMap {
157
- 'pc-particles': ParticleSystemComponentElement;
158
- }
159
- }
160
-
161
153
  export { ParticleSystemComponentElement };
@@ -1,9 +1,10 @@
1
- import { RenderComponent, StandardMaterial } from 'playcanvas';
1
+ import type { RenderComponent, StandardMaterial } from 'playcanvas';
2
2
 
3
- import { ComponentElement } from './component';
4
3
  import { MaterialElement } from '../material';
5
4
  import { parseBool, parseEnum } from '../parse';
6
5
 
6
+ import { ComponentElement } from './component';
7
+
7
8
  /**
8
9
  * The RenderComponentElement interface provides properties and methods for manipulating
9
10
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-render/ | `<pc-render>`} elements.
@@ -19,7 +20,7 @@ import { parseBool, parseEnum } from '../parse';
19
20
  class RenderComponentElement extends ComponentElement {
20
21
  private _castShadows = true;
21
22
 
22
- private _material: string = '';
23
+ private _material = '';
23
24
 
24
25
  private _receiveShadows = true;
25
26
 
@@ -30,7 +31,7 @@ class RenderComponentElement extends ComponentElement {
30
31
  super('render');
31
32
  }
32
33
 
33
- getInitialComponentData() {
34
+ protected getInitialComponentData() {
34
35
  return {
35
36
  type: this._type,
36
37
  castShadows: this._castShadows,
@@ -154,10 +155,4 @@ class RenderComponentElement extends ComponentElement {
154
155
 
155
156
  customElements.define('pc-render', RenderComponentElement);
156
157
 
157
- declare global {
158
- interface HTMLElementTagNameMap {
159
- 'pc-render': RenderComponentElement;
160
- }
161
- }
162
-
163
158
  export { RenderComponentElement };
@@ -1,8 +1,10 @@
1
- import { RigidBodyComponent, Vec3 } from 'playcanvas';
1
+ import type { RigidBodyComponent } from 'playcanvas';
2
+ import { Vec3 } from 'playcanvas';
2
3
 
3
- import { ComponentElement } from './component';
4
4
  import { parseEnum, parseNumber, parseVec3 } from '../parse';
5
5
 
6
+ import { ComponentElement } from './component';
7
+
6
8
  /**
7
9
  * The RigidBodyComponentElement interface provides properties and methods for manipulating
8
10
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-rigidbody/ | `<pc-rigidbody>`} elements.
@@ -15,7 +17,7 @@ class RigidBodyComponentElement extends ComponentElement {
15
17
  /**
16
18
  * The angular damping of the rigidbody.
17
19
  */
18
- private _angularDamping: number = 0;
20
+ private _angularDamping = 0;
19
21
 
20
22
  /**
21
23
  * The angular factor of the rigidbody.
@@ -25,12 +27,12 @@ class RigidBodyComponentElement extends ComponentElement {
25
27
  /**
26
28
  * The friction of the rigidbody.
27
29
  */
28
- private _friction: number = 0.5;
30
+ private _friction = 0.5;
29
31
 
30
32
  /**
31
33
  * The linear damping of the rigidbody.
32
34
  */
33
- private _linearDamping: number = 0;
35
+ private _linearDamping = 0;
34
36
 
35
37
  /**
36
38
  * The linear factor of the rigidbody.
@@ -40,17 +42,17 @@ class RigidBodyComponentElement extends ComponentElement {
40
42
  /**
41
43
  * The mass of the rigidbody.
42
44
  */
43
- private _mass: number = 1;
45
+ private _mass = 1;
44
46
 
45
47
  /**
46
48
  * The restitution of the rigidbody.
47
49
  */
48
- private _restitution: number = 0;
50
+ private _restitution = 0;
49
51
 
50
52
  /**
51
53
  * The rolling friction of the rigidbody.
52
54
  */
53
- private _rollingFriction: number = 0;
55
+ private _rollingFriction = 0;
54
56
 
55
57
  /**
56
58
  * The type of the rigidbody.
@@ -62,7 +64,7 @@ class RigidBodyComponentElement extends ComponentElement {
62
64
  super('rigidbody');
63
65
  }
64
66
 
65
- getInitialComponentData() {
67
+ protected getInitialComponentData() {
66
68
  return {
67
69
  angularDamping: this._angularDamping,
68
70
  angularFactor: this._angularFactor,
@@ -184,7 +186,18 @@ class RigidBodyComponentElement extends ComponentElement {
184
186
  }
185
187
 
186
188
  static get observedAttributes() {
187
- return [...super.observedAttributes, 'angular-damping', 'angular-factor', 'friction', 'linear-damping', 'linear-factor', 'mass', 'restitution', 'rolling-friction', 'type'];
189
+ return [
190
+ ...super.observedAttributes,
191
+ 'angular-damping',
192
+ 'angular-factor',
193
+ 'friction',
194
+ 'linear-damping',
195
+ 'linear-factor',
196
+ 'mass',
197
+ 'restitution',
198
+ 'rolling-friction',
199
+ 'type'
200
+ ];
188
201
  }
189
202
 
190
203
  attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {
@@ -224,10 +237,4 @@ class RigidBodyComponentElement extends ComponentElement {
224
237
 
225
238
  customElements.define('pc-rigidbody', RigidBodyComponentElement);
226
239
 
227
- declare global {
228
- interface HTMLElementTagNameMap {
229
- 'pc-rigidbody': RigidBodyComponentElement;
230
- }
231
- }
232
-
233
240
  export { RigidBodyComponentElement };
@@ -1,8 +1,10 @@
1
- import { SCALEMODE_BLEND, SCALEMODE_NONE, ScreenComponent, Vec2 } from 'playcanvas';
1
+ import type { ScreenComponent } from 'playcanvas';
2
+ import { SCALEMODE_BLEND, SCALEMODE_NONE, Vec2 } from 'playcanvas';
2
3
 
3
- import { ComponentElement } from './component';
4
4
  import { parseBool, parseEnum, parseNumber, parseVec2 } from '../parse';
5
5
 
6
+ import { ComponentElement } from './component';
7
+
6
8
  // The engine's SCALEMODE_* constants are the strings 'none' and 'blend', so this map happens to be
7
9
  // an identity. It is still the right shape: it supplies parseEnum's valid-name list, it is what the
8
10
  // manifest generator reads the enum values from, and it keeps the attribute vocabulary independent
@@ -38,7 +40,7 @@ class ScreenComponentElement extends ComponentElement {
38
40
  super('screen');
39
41
  }
40
42
 
41
- getInitialComponentData() {
43
+ protected getInitialComponentData() {
42
44
  return {
43
45
  priority: this._priority,
44
46
  referenceResolution: this._referenceResolution,
@@ -184,10 +186,4 @@ class ScreenComponentElement extends ComponentElement {
184
186
 
185
187
  customElements.define('pc-screen', ScreenComponentElement);
186
188
 
187
- declare global {
188
- interface HTMLElementTagNameMap {
189
- 'pc-screen': ScreenComponentElement;
190
- }
191
- }
192
-
193
189
  export { ScreenComponentElement };
@@ -1,9 +1,21 @@
1
- import { Color, Quat, ScriptComponent, Script, Vec2, Vec3, Vec4 } from 'playcanvas';
1
+ import type { ScriptComponent, Script } from 'playcanvas';
2
+ import { Color, Quat, Vec2, Vec3, Vec4 } from 'playcanvas';
2
3
 
3
4
  import { AssetElement } from '../asset';
5
+ import {
6
+ getEntity,
7
+ parseBool,
8
+ parseColor,
9
+ parseComponents,
10
+ parseNumber,
11
+ parseQuat,
12
+ parseVec2,
13
+ parseVec3,
14
+ parseVec4
15
+ } from '../parse';
16
+
4
17
  import { ComponentElement } from './component';
5
18
  import { ScriptElement } from './script';
6
- import { getEntity, parseBool, parseColor, parseComponents, parseNumber, parseQuat, parseVec2, parseVec3, parseVec4 } from '../parse';
7
19
 
8
20
  /**
9
21
  * Attributes on `pc-script` that never map to script attributes: the element's own API (derived
@@ -11,10 +23,34 @@ import { getEntity, parseBool, parseColor, parseComponents, parseNumber, parseQu
11
23
  */
12
24
  const RESERVED_ATTRIBUTES = new Set([
13
25
  ...ScriptElement.observedAttributes,
14
- 'accesskey', 'autocapitalize', 'autofocus', 'class', 'contenteditable', 'dir', 'draggable',
15
- 'exportparts', 'hidden', 'id', 'inert', 'is', 'itemid', 'itemprop', 'itemref', 'itemscope',
16
- 'itemtype', 'lang', 'nonce', 'part', 'popover', 'role', 'slot', 'spellcheck', 'style',
17
- 'tabindex', 'title', 'translate'
26
+ 'accesskey',
27
+ 'autocapitalize',
28
+ 'autofocus',
29
+ 'class',
30
+ 'contenteditable',
31
+ 'dir',
32
+ 'draggable',
33
+ 'exportparts',
34
+ 'hidden',
35
+ 'id',
36
+ 'inert',
37
+ 'is',
38
+ 'itemid',
39
+ 'itemprop',
40
+ 'itemref',
41
+ 'itemscope',
42
+ 'itemtype',
43
+ 'lang',
44
+ 'nonce',
45
+ 'part',
46
+ 'popover',
47
+ 'role',
48
+ 'slot',
49
+ 'spellcheck',
50
+ 'style',
51
+ 'tabindex',
52
+ 'title',
53
+ 'translate'
18
54
  ]);
19
55
 
20
56
  /**
@@ -27,11 +63,13 @@ const RESERVED_ATTRIBUTES = new Set([
27
63
  * @returns Whether the attribute name is reserved.
28
64
  */
29
65
  const isReservedAttribute = (name: string): boolean => {
30
- return RESERVED_ATTRIBUTES.has(name) ||
66
+ return (
67
+ RESERVED_ATTRIBUTES.has(name) ||
31
68
  name.startsWith('data-') ||
32
69
  name.startsWith('aria-') ||
33
70
  name.startsWith('_') ||
34
- (name.startsWith('on') && name in HTMLElement.prototype);
71
+ (name.startsWith('on') && name in HTMLElement.prototype)
72
+ );
35
73
  };
36
74
 
37
75
  /**
@@ -39,7 +77,14 @@ const isReservedAttribute = (name: string): boolean => {
39
77
  * the (optional, so possibly undefined) lifecycle methods.
40
78
  */
41
79
  const SCRIPT_API_MEMBERS = new Set([
42
- 'app', 'entity', 'destroy', 'initialize', 'postInitialize', 'postUpdate', 'swap', 'update'
80
+ 'app',
81
+ 'entity',
82
+ 'destroy',
83
+ 'initialize',
84
+ 'postInitialize',
85
+ 'postUpdate',
86
+ 'swap',
87
+ 'update'
43
88
  ]);
44
89
 
45
90
  /**
@@ -57,7 +102,7 @@ const kebabToCamel = (name: string): string => {
57
102
  * @returns The kebab-case name.
58
103
  */
59
104
  const camelToKebab = (name: string): string => {
60
- return name.replace(/[A-Z]/g, char => `-${char.toLowerCase()}`);
105
+ return name.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);
61
106
  };
62
107
 
63
108
  /**
@@ -110,7 +155,9 @@ const vectorConversion = (length: 2 | 3 | 4, Ctor: new (components: number[]) =>
110
155
  if (components) {
111
156
  return new Ctor(components);
112
157
  }
113
- console.warn(`Invalid script attribute value '${raw}'. Expected ${length} space-separated numbers after 'vec${length}:'.`);
158
+ console.warn(
159
+ `Invalid script attribute value '${raw}'. Expected ${length} space-separated numbers after 'vec${length}:'.`
160
+ );
114
161
  return raw;
115
162
  };
116
163
  };
@@ -183,27 +230,17 @@ const findCaseMatch = (script: any, key: string): string | null => {
183
230
  return null;
184
231
  };
185
232
 
186
- // Add these interfaces at the top of the file, after the imports
187
- interface ScriptAttributesChangeEvent extends CustomEvent {
233
+ export type ScriptAttributesChangeEvent = {
188
234
  detail: { attributes: Record<string, any> };
189
- }
235
+ } & CustomEvent;
190
236
 
191
- interface ScriptEnableChangeEvent extends CustomEvent {
237
+ export type ScriptEnableChangeEvent = {
192
238
  detail: { enabled: boolean };
193
- }
194
-
195
- interface ScriptNameChangeEvent extends CustomEvent {
196
- detail: { oldName: string, newName: string };
197
- }
239
+ } & CustomEvent;
198
240
 
199
- // Add this interface before the ScriptComponentElement class
200
- declare global {
201
- interface HTMLElementEventMap {
202
- 'scriptattributeschange': ScriptAttributesChangeEvent;
203
- 'scriptenablechange': ScriptEnableChangeEvent;
204
- 'scriptnamechange': ScriptNameChangeEvent;
205
- }
206
- }
241
+ export type ScriptNameChangeEvent = {
242
+ detail: { oldName: string; newName: string };
243
+ } & CustomEvent;
207
244
 
208
245
  /**
209
246
  * The ScriptComponentElement interface provides properties and methods for manipulating
@@ -237,7 +274,7 @@ class ScriptComponentElement extends ComponentElement {
237
274
  return super.connectedCallback();
238
275
  }
239
276
 
240
- initComponent() {
277
+ protected initComponent() {
241
278
  // Handle initial script elements
242
279
  this.querySelectorAll<ScriptElement>(':scope > pc-script').forEach((scriptElement) => {
243
280
  this.createScript(scriptElement);
@@ -303,7 +340,12 @@ class ScriptComponentElement extends ComponentElement {
303
340
  // Only recurse into plain objects. Class instances (Vec3, Color, Asset, Entity...)
304
341
  // are leaf values assigned whole, so accessor-typed script attributes receive them
305
342
  // through their setters instead of having a getter's returned copy mutated.
306
- if (value && typeof value === 'object' && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype) {
343
+ if (
344
+ value &&
345
+ typeof value === 'object' &&
346
+ !Array.isArray(value) &&
347
+ Object.getPrototypeOf(value) === Object.prototype
348
+ ) {
307
349
  if (!current || typeof current !== 'object') {
308
350
  target[key] = {};
309
351
  }
@@ -321,7 +363,13 @@ class ScriptComponentElement extends ComponentElement {
321
363
  * @returns Whether the value is a math type.
322
364
  */
323
365
  private isMathType(value: any): value is Vec2 | Vec3 | Vec4 | Color | Quat {
324
- return value instanceof Vec2 || value instanceof Vec3 || value instanceof Vec4 || value instanceof Color || value instanceof Quat;
366
+ return (
367
+ value instanceof Vec2 ||
368
+ value instanceof Vec3 ||
369
+ value instanceof Vec4 ||
370
+ value instanceof Color ||
371
+ value instanceof Quat
372
+ );
325
373
  }
326
374
 
327
375
  /**
@@ -334,15 +382,22 @@ class ScriptComponentElement extends ComponentElement {
334
382
  * @param key - The property name, used in the warning message.
335
383
  * @returns The converted value, or `null`.
336
384
  */
337
- private arrayToMathType(current: Vec2 | Vec3 | Vec4 | Color | Quat, value: any[], key: string): Vec2 | Vec3 | Vec4 | Color | Quat | null {
338
- if (value.every(component => typeof component === 'number' && Number.isFinite(component))) {
385
+ private arrayToMathType(
386
+ current: Vec2 | Vec3 | Vec4 | Color | Quat,
387
+ value: any[],
388
+ key: string
389
+ ): Vec2 | Vec3 | Vec4 | Color | Quat | null {
390
+ if (value.every((component) => typeof component === 'number' && Number.isFinite(component))) {
339
391
  if (current instanceof Vec2 && value.length === 2) return new Vec2(value);
340
392
  if (current instanceof Vec3 && value.length === 3) return new Vec3(value);
341
393
  if (current instanceof Vec4 && value.length === 4) return new Vec4(value);
342
394
  if (current instanceof Color && (value.length === 3 || value.length === 4)) return new Color(value);
343
- if (current instanceof Quat && value.length === 3) return new Quat().setFromEulerAngles(value[0], value[1], value[2]);
395
+ if (current instanceof Quat && value.length === 3)
396
+ return new Quat().setFromEulerAngles(value[0], value[1], value[2]);
344
397
  }
345
- console.warn(`Cannot convert script attribute '${key}' array [${value}] to ${current.constructor.name}. Keeping the current value.`);
398
+ console.warn(
399
+ `Cannot convert script attribute '${key}' array [${value}] to ${current.constructor.name}. Keeping the current value.`
400
+ );
346
401
  return null;
347
402
  }
348
403
 
@@ -540,7 +595,9 @@ class ScriptComponentElement extends ComponentElement {
540
595
  const current = script[key];
541
596
 
542
597
  if (typeof current === 'function' || SCRIPT_API_MEMBERS.has(key)) {
543
- console.warn(`Ignoring attribute '${attributeName}' on pc-script '${scriptName}' - '${key}' is part of the Script API.`);
598
+ console.warn(
599
+ `Ignoring attribute '${attributeName}' on pc-script '${scriptName}' - '${key}' is part of the Script API.`
600
+ );
544
601
  return;
545
602
  }
546
603
 
@@ -570,14 +627,20 @@ class ScriptComponentElement extends ComponentElement {
570
627
  } else {
571
628
  const match = findCaseMatch(script, key);
572
629
  if (match) {
573
- console.warn(`Script '${scriptName}' has no attribute '${key}' - did you mean '${camelToKebab(match)}'? Attribute names are kebab-case.`);
630
+ console.warn(
631
+ `Script '${scriptName}' has no attribute '${key}' - did you mean '${camelToKebab(match)}'? Attribute names are kebab-case.`
632
+ );
574
633
  return;
575
634
  }
576
- console.warn(`Script '${scriptName}' has no typed attribute '${key}' - assigning the raw string from '${attributeName}'.`);
635
+ console.warn(
636
+ `Script '${scriptName}' has no typed attribute '${key}' - assigning the raw string from '${attributeName}'.`
637
+ );
577
638
  script[key] = value;
578
639
  }
579
640
  } catch (error) {
580
- console.warn(`Error applying attribute '${attributeName}' to script '${scriptName}': ${(error as Error).message}`);
641
+ console.warn(
642
+ `Error applying attribute '${attributeName}' to script '${scriptName}': ${(error as Error).message}`
643
+ );
581
644
  }
582
645
  }
583
646
 
@@ -616,7 +679,12 @@ class ScriptComponentElement extends ComponentElement {
616
679
  mutation.removedNodes.forEach((node) => {
617
680
  if (node instanceof ScriptElement) {
618
681
  const scriptName = node.getAttribute('name');
619
- if (scriptName && node._script && this.component && this.component.get(scriptName) === node._script) {
682
+ if (
683
+ scriptName &&
684
+ node._script &&
685
+ this.component &&
686
+ this.component.get(scriptName) === node._script
687
+ ) {
620
688
  this.destroyScript(scriptName);
621
689
  }
622
690
  node._script = null;
@@ -648,10 +716,4 @@ class ScriptComponentElement extends ComponentElement {
648
716
 
649
717
  customElements.define('pc-scripts', ScriptComponentElement);
650
718
 
651
- declare global {
652
- interface HTMLElementTagNameMap {
653
- 'pc-scripts': ScriptComponentElement;
654
- }
655
- }
656
-
657
719
  export { ScriptComponentElement };