@playcanvas/web-components 0.10.1 → 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 +102 -51
  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 +16 -20
  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 +28 -11
  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 +9 -11
  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 +5191 -10695
  26. package/dist/entity.d.ts +16 -9
  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 +6 -3
  32. package/dist/pwc.cjs +799 -287
  33. package/dist/pwc.cjs.map +1 -1
  34. package/dist/pwc.js +799 -287
  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 +800 -288
  41. package/dist/pwc.mjs.map +1 -1
  42. package/dist/scene.d.ts +4 -7
  43. package/dist/sky.d.ts +25 -16
  44. package/dist/vscode.html-custom-data.json +65 -45
  45. package/dist/web-types.json +585 -557
  46. package/package.json +8 -7
  47. package/src/app.ts +326 -144
  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 +55 -36
  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 +46 -20
  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 +22 -15
  68. package/src/components/sound-component.ts +10 -15
  69. package/src/components/sound-slot.ts +30 -20
  70. package/src/entity.ts +75 -34
  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 +67 -20
  77. package/src/scene.ts +12 -9
  78. package/src/sky.ts +76 -34
@@ -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 };
@@ -1,4 +1,4 @@
1
- import { Script } from 'playcanvas';
1
+ import type { Script } from 'playcanvas';
2
2
 
3
3
  import { AsyncElement } from '../async-element';
4
4
  import { parseBool } from '../parse';
@@ -39,18 +39,11 @@ import { parseBool } from '../parse';
39
39
  class ScriptElement extends AsyncElement {
40
40
  private _attributes: Record<string, any> = {};
41
41
 
42
- private _enabled: boolean = true;
43
-
44
- /**
45
- * Whether readiness has been signalled. Creation can happen more than once over an
46
- * element's life (a runtime `name` change recreates the instance), but `ready` is a
47
- * one-shot signal, so only the first successful creation fires it.
48
- */
49
- private _readySignalled: boolean = false;
42
+ private _enabled = true;
50
43
 
51
44
  /**
52
45
  * The Script instance created for this element by its parent `<pc-scripts>` element.
53
- * @ignore
46
+ * @internal
54
47
  */
55
48
  _script: Script | null = null;
56
49
 
@@ -64,10 +57,12 @@ class ScriptElement extends AsyncElement {
64
57
  */
65
58
  set scriptAttributes(value: Record<string, any>) {
66
59
  this._attributes = value ?? {};
67
- this.dispatchEvent(new CustomEvent('scriptattributeschange', {
68
- detail: { attributes: this._attributes },
69
- bubbles: true
70
- }));
60
+ this.dispatchEvent(
61
+ new CustomEvent('scriptattributeschange', {
62
+ detail: { attributes: this._attributes },
63
+ bubbles: true
64
+ })
65
+ );
71
66
  }
72
67
 
73
68
  /**
@@ -84,10 +79,12 @@ class ScriptElement extends AsyncElement {
84
79
  */
85
80
  set enabled(value: boolean) {
86
81
  this._enabled = value;
87
- this.dispatchEvent(new CustomEvent('scriptenablechange', {
88
- detail: { enabled: value },
89
- bubbles: true
90
- }));
82
+ this.dispatchEvent(
83
+ new CustomEvent('scriptenablechange', {
84
+ detail: { enabled: value },
85
+ bubbles: true
86
+ })
87
+ );
91
88
  }
92
89
 
93
90
  /**
@@ -137,17 +134,27 @@ class ScriptElement extends AsyncElement {
137
134
  // Script instances are created by the parent pc-scripts element, so an element placed
138
135
  // anywhere else is inert and never becomes ready - warn rather than hang silently
139
136
  if (this.parentElement?.tagName !== 'PC-SCRIPTS') {
140
- console.warn(`pc-script '${this.getAttribute('name')}' must be a direct child of pc-scripts - script not created`);
137
+ console.warn(
138
+ `pc-script '${this.getAttribute('name')}' must be a direct child of pc-scripts - script not created`
139
+ );
141
140
  }
142
141
  }
143
142
 
143
+ disconnectedCallback() {
144
+ // Re-arm readiness so a re-inserted element announces the instance created for it then.
145
+ // `_script` is deliberately NOT cleared here: the parent's mutation observer processes
146
+ // this removal afterwards and reads it to establish which engine script this element
147
+ // owned - the parent is what clears it.
148
+ this._resetReady();
149
+ }
150
+
144
151
  /**
145
152
  * Called by the parent `<pc-scripts>` element when the script instance has been created.
146
- * @ignore
153
+ * Creation can happen more than once per connection (a runtime `name` change recreates the
154
+ * instance), but `_onReady` signals readiness at most once per cycle.
155
+ * @internal
147
156
  */
148
157
  _onScriptCreated() {
149
- if (this._readySignalled) return;
150
- this._readySignalled = true;
151
158
  this._onReady();
152
159
  }
153
160
 
@@ -165,7 +172,9 @@ class ScriptElement extends AsyncElement {
165
172
  try {
166
173
  this.scriptAttributes = JSON.parse(newValue);
167
174
  } catch (error) {
168
- console.warn(`Invalid 'attributes' JSON on pc-script '${this.getAttribute('name')}': ${(error as Error).message}`);
175
+ console.warn(
176
+ `Invalid 'attributes' JSON on pc-script '${this.getAttribute('name')}': ${(error as Error).message}`
177
+ );
169
178
  }
170
179
  break;
171
180
  case 'enabled':
@@ -176,10 +185,12 @@ class ScriptElement extends AsyncElement {
176
185
  // the added-node mutation), so only a genuine rename is signalled here. Note
177
186
  // that setAttribute fires this callback even when the value is unchanged.
178
187
  if (oldValue !== null && oldValue !== newValue) {
179
- this.dispatchEvent(new CustomEvent('scriptnamechange', {
180
- detail: { oldName: oldValue, newName: newValue },
181
- bubbles: true
182
- }));
188
+ this.dispatchEvent(
189
+ new CustomEvent('scriptnamechange', {
190
+ detail: { oldName: oldValue, newName: newValue },
191
+ bubbles: true
192
+ })
193
+ );
183
194
  }
184
195
  break;
185
196
  }
@@ -188,10 +199,4 @@ class ScriptElement extends AsyncElement {
188
199
 
189
200
  customElements.define('pc-script', ScriptElement);
190
201
 
191
- declare global {
192
- interface HTMLElementTagNameMap {
193
- 'pc-script': ScriptElement;
194
- }
195
- }
196
-
197
202
  export { ScriptElement };
@@ -1,8 +1,10 @@
1
- import { ORIENTATION_HORIZONTAL, ORIENTATION_VERTICAL, ScrollbarComponent } from 'playcanvas';
1
+ import type { ScrollbarComponent } from 'playcanvas';
2
+ import { ORIENTATION_HORIZONTAL, ORIENTATION_VERTICAL } from 'playcanvas';
2
3
 
3
- import { ComponentElement } from './component';
4
4
  import { getEntity, parseEnum, parseNumber } from '../parse';
5
5
 
6
+ import { ComponentElement } from './component';
7
+
6
8
  const orientations = new Map<'horizontal' | 'vertical', number>([
7
9
  ['horizontal', ORIENTATION_HORIZONTAL],
8
10
  ['vertical', ORIENTATION_VERTICAL]
@@ -30,7 +32,7 @@ class ScrollbarComponentElement extends ComponentElement {
30
32
  super('scrollbar');
31
33
  }
32
34
 
33
- getInitialComponentData() {
35
+ protected getInitialComponentData() {
34
36
  const data: Record<string, any> = {
35
37
  orientation: orientations.get(this._orientation),
36
38
  value: this._value,
@@ -133,13 +135,7 @@ class ScrollbarComponentElement extends ComponentElement {
133
135
  }
134
136
 
135
137
  static get observedAttributes() {
136
- return [
137
- ...super.observedAttributes,
138
- 'orientation',
139
- 'value',
140
- 'handle-size',
141
- 'handle'
142
- ];
138
+ return [...super.observedAttributes, 'orientation', 'value', 'handle-size', 'handle'];
143
139
  }
144
140
 
145
141
  attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {
@@ -164,10 +160,4 @@ class ScrollbarComponentElement extends ComponentElement {
164
160
 
165
161
  customElements.define('pc-scrollbar', ScrollbarComponentElement);
166
162
 
167
- declare global {
168
- interface HTMLElementTagNameMap {
169
- 'pc-scrollbar': ScrollbarComponentElement;
170
- }
171
- }
172
-
173
163
  export { ScrollbarComponentElement };
@@ -1,8 +1,17 @@
1
- import { SCROLL_MODE_BOUNCE, SCROLL_MODE_CLAMP, SCROLL_MODE_INFINITE, SCROLLBAR_VISIBILITY_SHOW_ALWAYS, SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED, ScrollViewComponent, Vec2 } from 'playcanvas';
1
+ import type { ScrollViewComponent } from 'playcanvas';
2
+ import {
3
+ SCROLL_MODE_BOUNCE,
4
+ SCROLL_MODE_CLAMP,
5
+ SCROLL_MODE_INFINITE,
6
+ SCROLLBAR_VISIBILITY_SHOW_ALWAYS,
7
+ SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED,
8
+ Vec2
9
+ } from 'playcanvas';
2
10
 
3
- import { ComponentElement } from './component';
4
11
  import { getEntity, parseBool, parseEnum, parseNumber, parseVec2 } from '../parse';
5
12
 
13
+ import { ComponentElement } from './component';
14
+
6
15
  const scrollModes = new Map<'clamp' | 'bounce' | 'infinite', number>([
7
16
  ['clamp', SCROLL_MODE_CLAMP],
8
17
  ['bounce', SCROLL_MODE_BOUNCE],
@@ -54,7 +63,7 @@ class ScrollViewComponentElement extends ComponentElement {
54
63
  super('scrollview');
55
64
  }
56
65
 
57
- getInitialComponentData() {
66
+ protected getInitialComponentData() {
58
67
  const data: Record<string, any> = {
59
68
  horizontal: this._horizontal,
60
69
  vertical: this._vertical,
@@ -99,7 +108,8 @@ class ScrollViewComponentElement extends ComponentElement {
99
108
  }
100
109
 
101
110
  /**
102
- * Sets whether horizontal scrolling is enabled.
111
+ * Sets whether scrolling along the horizontal axis is enabled. This is a toggle, unlike the
112
+ * `orientation` of a `<pc-scrollbar>`, for which `horizontal` is one of the accepted values.
103
113
  * @param value - Whether horizontal scrolling is enabled.
104
114
  */
105
115
  set horizontal(value: boolean) {
@@ -110,7 +120,7 @@ class ScrollViewComponentElement extends ComponentElement {
110
120
  }
111
121
 
112
122
  /**
113
- * Gets whether horizontal scrolling is enabled.
123
+ * Gets whether scrolling along the horizontal axis is enabled.
114
124
  * @returns Whether horizontal scrolling is enabled.
115
125
  */
116
126
  get horizontal() {
@@ -118,7 +128,8 @@ class ScrollViewComponentElement extends ComponentElement {
118
128
  }
119
129
 
120
130
  /**
121
- * Sets whether vertical scrolling is enabled.
131
+ * Sets whether scrolling along the vertical axis is enabled. This is a toggle, unlike the
132
+ * `orientation` of a `<pc-scrollbar>`, for which `vertical` is one of the accepted values.
122
133
  * @param value - Whether vertical scrolling is enabled.
123
134
  */
124
135
  set vertical(value: boolean) {
@@ -129,7 +140,7 @@ class ScrollViewComponentElement extends ComponentElement {
129
140
  }
130
141
 
131
142
  /**
132
- * Gets whether vertical scrolling is enabled.
143
+ * Gets whether scrolling along the vertical axis is enabled.
133
144
  * @returns Whether vertical scrolling is enabled.
134
145
  */
135
146
  get vertical() {
@@ -242,7 +253,8 @@ class ScrollViewComponentElement extends ComponentElement {
242
253
  set horizontalScrollbarVisibility(value: 'always' | 'when-required') {
243
254
  this._horizontalScrollbarVisibility = value;
244
255
  if (this.component) {
245
- this.component.horizontalScrollbarVisibility = visibilities.get(value) ?? SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED;
256
+ this.component.horizontalScrollbarVisibility =
257
+ visibilities.get(value) ?? SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED;
246
258
  }
247
259
  }
248
260
 
@@ -262,7 +274,8 @@ class ScrollViewComponentElement extends ComponentElement {
262
274
  set verticalScrollbarVisibility(value: 'always' | 'when-required') {
263
275
  this._verticalScrollbarVisibility = value;
264
276
  if (this.component) {
265
- this.component.verticalScrollbarVisibility = visibilities.get(value) ?? SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED;
277
+ this.component.verticalScrollbarVisibility =
278
+ visibilities.get(value) ?? SCROLLBAR_VISIBILITY_SHOW_WHEN_REQUIRED;
266
279
  }
267
280
  }
268
281
 
@@ -426,10 +439,4 @@ class ScrollViewComponentElement extends ComponentElement {
426
439
 
427
440
  customElements.define('pc-scrollview', ScrollViewComponentElement);
428
441
 
429
- declare global {
430
- interface HTMLElementTagNameMap {
431
- 'pc-scrollview': ScrollViewComponentElement;
432
- }
433
- }
434
-
435
442
  export { ScrollViewComponentElement };
@@ -1,8 +1,9 @@
1
- import { SoundComponent } from 'playcanvas';
1
+ import type { SoundComponent } from 'playcanvas';
2
2
 
3
- import { ComponentElement } from './component';
4
3
  import { parseBool, parseEnum, parseNumber } from '../parse';
5
4
 
5
+ import { ComponentElement } from './component';
6
+
6
7
  /**
7
8
  * The SoundComponentElement interface provides properties and methods for manipulating
8
9
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-sounds/ | `<pc-sounds>`} elements.
@@ -14,24 +15,24 @@ import { parseBool, parseEnum, parseNumber } from '../parse';
14
15
  class SoundComponentElement extends ComponentElement {
15
16
  private _distanceModel: 'exponential' | 'inverse' | 'linear' = 'linear';
16
17
 
17
- private _maxDistance: number = 10000;
18
+ private _maxDistance = 10000;
18
19
 
19
- private _pitch: number = 1;
20
+ private _pitch = 1;
20
21
 
21
- private _positional: boolean = false;
22
+ private _positional = false;
22
23
 
23
- private _refDistance: number = 1;
24
+ private _refDistance = 1;
24
25
 
25
- private _rollOffFactor: number = 1;
26
+ private _rollOffFactor = 1;
26
27
 
27
- private _volume: number = 1;
28
+ private _volume = 1;
28
29
 
29
30
  /** @ignore */
30
31
  constructor() {
31
32
  super('sound');
32
33
  }
33
34
 
34
- getInitialComponentData() {
35
+ protected getInitialComponentData() {
35
36
  return {
36
37
  distanceModel: this._distanceModel,
37
38
  maxDistance: this._maxDistance,
@@ -228,10 +229,4 @@ class SoundComponentElement extends ComponentElement {
228
229
 
229
230
  customElements.define('pc-sounds', SoundComponentElement);
230
231
 
231
- declare global {
232
- interface HTMLElementTagNameMap {
233
- 'pc-sounds': SoundComponentElement;
234
- }
235
- }
236
-
237
232
  export { SoundComponentElement };