@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,11 @@
1
- import { Color, ElementComponent, Vec2, Vec4 } from 'playcanvas';
1
+ import type { ElementComponent } from 'playcanvas';
2
+ import { Color, Vec2, Vec4 } from 'playcanvas';
2
3
 
3
4
  import { AssetElement } from '../asset';
4
- import { ComponentElement } from './component';
5
5
  import { parseBool, parseColor, parseEnum, parseNumber, parseVec2, parseVec4 } from '../parse';
6
6
 
7
+ import { ComponentElement } from './component';
8
+
7
9
  /**
8
10
  * The ElementComponentElement interface provides properties and methods for manipulating
9
11
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-element/ | `<pc-element>`} elements.
@@ -15,62 +17,62 @@ import { parseBool, parseColor, parseEnum, parseNumber, parseVec2, parseVec4 } f
15
17
  class ElementComponentElement extends ComponentElement {
16
18
  private _anchor: Vec4 = new Vec4(0.5, 0.5, 0.5, 0.5);
17
19
 
18
- private _autoWidth: boolean = true;
20
+ private _autoWidth = true;
19
21
 
20
- private _autoHeight: boolean = true;
22
+ private _autoHeight = true;
21
23
 
22
- private _autoFitWidth: boolean = false;
24
+ private _autoFitWidth = false;
23
25
 
24
- private _autoFitHeight: boolean = false;
26
+ private _autoFitHeight = false;
25
27
 
26
28
  private _color: Color = new Color(1, 1, 1, 1);
27
29
 
28
- private _enableMarkup: boolean = false;
30
+ private _enableMarkup = false;
29
31
 
30
- private _fontAsset: string = '';
32
+ private _fontAsset = '';
31
33
 
32
- private _fontSize: number = 32;
34
+ private _fontSize = 32;
33
35
 
34
- private _maxFontSize: number = 32;
36
+ private _maxFontSize = 32;
35
37
 
36
- private _minFontSize: number = 8;
38
+ private _minFontSize = 8;
37
39
 
38
- private _height: number = 0;
40
+ private _height = 0;
39
41
 
40
- private _lineHeight: number = 32;
42
+ private _lineHeight = 32;
41
43
 
42
44
  private _margin: Vec4 | null = null;
43
45
 
44
- private _mask: boolean = false;
46
+ private _mask = false;
45
47
 
46
- private _opacity: number = 1;
48
+ private _opacity = 1;
47
49
 
48
50
  private _pivot: Vec2 = new Vec2(0.5, 0.5);
49
51
 
50
52
  private _pixelsPerUnit: number | null = null;
51
53
 
52
- private _spriteAsset: string = '';
54
+ private _spriteAsset = '';
53
55
 
54
- private _spriteFrame: number = 0;
56
+ private _spriteFrame = 0;
55
57
 
56
- private _text: string = '';
58
+ private _text = '';
57
59
 
58
- private _textureAsset: string = '';
60
+ private _textureAsset = '';
59
61
 
60
62
  private _type: 'group' | 'image' | 'text' = 'group';
61
63
 
62
- private _useInput: boolean = false;
64
+ private _useInput = false;
63
65
 
64
- private _width: number = 0;
66
+ private _width = 0;
65
67
 
66
- private _wrapLines: boolean = false;
68
+ private _wrapLines = false;
67
69
 
68
70
  /** @ignore */
69
71
  constructor() {
70
72
  super('element');
71
73
  }
72
74
 
73
- initComponent() {
75
+ protected initComponent() {
74
76
  const component = this.component as any;
75
77
  if (!component) {
76
78
  return;
@@ -89,7 +91,7 @@ class ElementComponentElement extends ComponentElement {
89
91
  component._dirtifyMask?.();
90
92
  }
91
93
 
92
- getInitialComponentData() {
94
+ protected getInitialComponentData() {
93
95
  const data: Record<string, any> = {
94
96
  anchor: this._anchor,
95
97
  autoWidth: this._autoWidth,
@@ -774,10 +776,4 @@ class ElementComponentElement extends ComponentElement {
774
776
 
775
777
  customElements.define('pc-element', ElementComponentElement);
776
778
 
777
- declare global {
778
- interface HTMLElementTagNameMap {
779
- 'pc-element': ElementComponentElement;
780
- }
781
- }
782
-
783
779
  export { ElementComponentElement };
@@ -1,9 +1,10 @@
1
- import { GSplatComponent } from 'playcanvas';
1
+ import type { GSplatComponent } from 'playcanvas';
2
2
 
3
- import { ComponentElement } from './component';
4
3
  import { AssetElement } from '../asset';
5
4
  import { parseBool, parseNumber } from '../parse';
6
5
 
6
+ import { ComponentElement } from './component';
7
+
7
8
  /**
8
9
  * The GSplatComponentElement interface provides properties and methods for manipulating
9
10
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-gsplat/ | `<pc-gsplat>`} elements.
@@ -30,7 +31,7 @@ class GSplatComponentElement extends ComponentElement {
30
31
  super('gsplat');
31
32
  }
32
33
 
33
- getInitialComponentData() {
34
+ protected getInitialComponentData() {
34
35
  return {
35
36
  asset: AssetElement.get(this._asset),
36
37
  castShadows: this._castShadows,
@@ -216,10 +217,4 @@ class GSplatComponentElement extends ComponentElement {
216
217
 
217
218
  customElements.define('pc-gsplat', GSplatComponentElement);
218
219
 
219
- declare global {
220
- interface HTMLElementTagNameMap {
221
- 'pc-gsplat': GSplatComponentElement;
222
- }
223
- }
224
-
225
220
  export { GSplatComponentElement };
@@ -1,8 +1,9 @@
1
- import { LayoutChildComponent } from 'playcanvas';
1
+ import type { LayoutChildComponent } from 'playcanvas';
2
2
 
3
- import { ComponentElement } from './component';
4
3
  import { parseBool, parseNumber } from '../parse';
5
4
 
5
+ import { ComponentElement } from './component';
6
+
6
7
  /**
7
8
  * The LayoutChildComponentElement interface provides properties and methods for manipulating
8
9
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-layoutchild/ | `<pc-layoutchild>`} elements.
@@ -31,7 +32,7 @@ class LayoutChildComponentElement extends ComponentElement {
31
32
  super('layoutchild');
32
33
  }
33
34
 
34
- getInitialComponentData() {
35
+ protected getInitialComponentData() {
35
36
  return {
36
37
  minWidth: this._minWidth,
37
38
  minHeight: this._minHeight,
@@ -230,10 +231,4 @@ class LayoutChildComponentElement extends ComponentElement {
230
231
 
231
232
  customElements.define('pc-layoutchild', LayoutChildComponentElement);
232
233
 
233
- declare global {
234
- interface HTMLElementTagNameMap {
235
- 'pc-layoutchild': LayoutChildComponentElement;
236
- }
237
- }
238
-
239
234
  export { LayoutChildComponentElement };
@@ -1,8 +1,19 @@
1
- import { FITTING_NONE, FITTING_STRETCH, FITTING_SHRINK, FITTING_BOTH, LayoutGroupComponent, ORIENTATION_HORIZONTAL, ORIENTATION_VERTICAL, Vec2, Vec4 } from 'playcanvas';
1
+ import type { LayoutGroupComponent } from 'playcanvas';
2
+ import {
3
+ FITTING_NONE,
4
+ FITTING_STRETCH,
5
+ FITTING_SHRINK,
6
+ FITTING_BOTH,
7
+ ORIENTATION_HORIZONTAL,
8
+ ORIENTATION_VERTICAL,
9
+ Vec2,
10
+ Vec4
11
+ } from 'playcanvas';
2
12
 
3
- import { ComponentElement } from './component';
4
13
  import { parseBool, parseEnum, parseVec2, parseVec4 } from '../parse';
5
14
 
15
+ import { ComponentElement } from './component';
16
+
6
17
  const orientations = new Map<'horizontal' | 'vertical', number>([
7
18
  ['horizontal', ORIENTATION_HORIZONTAL],
8
19
  ['vertical', ORIENTATION_VERTICAL]
@@ -47,7 +58,7 @@ class LayoutGroupComponentElement extends ComponentElement {
47
58
  super('layoutgroup');
48
59
  }
49
60
 
50
- getInitialComponentData() {
61
+ protected getInitialComponentData() {
51
62
  return {
52
63
  orientation: orientations.get(this._orientation),
53
64
  reverseX: this._reverseX,
@@ -295,10 +306,4 @@ class LayoutGroupComponentElement extends ComponentElement {
295
306
 
296
307
  customElements.define('pc-layoutgroup', LayoutGroupComponentElement);
297
308
 
298
- declare global {
299
- interface HTMLElementTagNameMap {
300
- 'pc-layoutgroup': LayoutGroupComponentElement;
301
- }
302
- }
303
-
304
309
  export { LayoutGroupComponentElement };
@@ -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,7 +1,18 @@
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';
3
+
4
+ import { parseBool, parseEnum, parseNumber, parseVec2 } from '../parse';
2
5
 
3
6
  import { ComponentElement } from './component';
4
- import { parseBool, parseNumber, parseVec2 } from '../parse';
7
+
8
+ // The engine's SCALEMODE_* constants are the strings 'none' and 'blend', so this map happens to be
9
+ // an identity. It is still the right shape: it supplies parseEnum's valid-name list, it is what the
10
+ // manifest generator reads the enum values from, and it keeps the attribute vocabulary independent
11
+ // of constants the engine is free to change.
12
+ const scaleModes = new Map<'none' | 'blend', string>([
13
+ ['none', SCALEMODE_NONE],
14
+ ['blend', SCALEMODE_BLEND]
15
+ ]);
5
16
 
6
17
  /**
7
18
  * The ScreenComponentElement interface provides properties and methods for manipulating
@@ -20,7 +31,7 @@ class ScreenComponentElement extends ComponentElement {
20
31
 
21
32
  private _priority = 0;
22
33
 
23
- private _blend = false;
34
+ private _scaleMode: 'none' | 'blend' = 'none';
24
35
 
25
36
  private _scaleBlend = 0.5;
26
37
 
@@ -29,13 +40,13 @@ class ScreenComponentElement extends ComponentElement {
29
40
  super('screen');
30
41
  }
31
42
 
32
- getInitialComponentData() {
43
+ protected getInitialComponentData() {
33
44
  return {
34
45
  priority: this._priority,
35
46
  referenceResolution: this._referenceResolution,
36
47
  resolution: this._resolution,
37
48
  scaleBlend: this._scaleBlend,
38
- scaleMode: this._blend ? SCALEMODE_BLEND : SCALEMODE_NONE,
49
+ scaleMode: scaleModes.get(this._scaleMode) ?? SCALEMODE_NONE,
39
50
  screenSpace: this._screenSpace
40
51
  };
41
52
  }
@@ -81,6 +92,12 @@ class ScreenComponentElement extends ComponentElement {
81
92
  return this._resolution;
82
93
  }
83
94
 
95
+ /**
96
+ * Sets how the screen's `resolution` and `referenceResolution` are weighted against each other
97
+ * when `scaleMode` is `blend`, from 0 (follow the resolution) to 1 (follow the reference
98
+ * resolution). Ignored while `scaleMode` is `none`.
99
+ * @param value - The scale blend factor.
100
+ */
84
101
  set scaleBlend(value: number) {
85
102
  this._scaleBlend = value;
86
103
  if (this.component) {
@@ -88,19 +105,34 @@ class ScreenComponentElement extends ComponentElement {
88
105
  }
89
106
  }
90
107
 
108
+ /**
109
+ * Gets how the screen's resolutions are weighted against each other.
110
+ * @returns The scale blend factor.
111
+ */
91
112
  get scaleBlend() {
92
113
  return this._scaleBlend;
93
114
  }
94
115
 
95
- set blend(value: boolean) {
96
- this._blend = value;
116
+ /**
117
+ * Sets how the screen scales its contents. `none` renders at `resolution` and ignores
118
+ * `referenceResolution`; `blend` scales between the two, weighted by `scaleBlend`, which is what
119
+ * keeps a UI laid out at one resolution usable at another. Requires `screenSpace` - the engine
120
+ * forces `none` on a world-space screen, which does not support scaling.
121
+ * @param value - The scale mode ('none' or 'blend').
122
+ */
123
+ set scaleMode(value: 'none' | 'blend') {
124
+ this._scaleMode = value;
97
125
  if (this.component) {
98
- this.component.scaleMode = this._blend ? SCALEMODE_BLEND : SCALEMODE_NONE;
126
+ this.component.scaleMode = scaleModes.get(value) ?? SCALEMODE_NONE;
99
127
  }
100
128
  }
101
129
 
102
- get blend() {
103
- return this._blend;
130
+ /**
131
+ * Gets how the screen scales its contents.
132
+ * @returns The scale mode.
133
+ */
134
+ get scaleMode() {
135
+ return this._scaleMode;
104
136
  }
105
137
 
106
138
  set screenSpace(value: boolean) {
@@ -117,12 +149,12 @@ class ScreenComponentElement extends ComponentElement {
117
149
  static get observedAttributes() {
118
150
  return [
119
151
  ...super.observedAttributes,
120
- 'blend',
121
152
  'screen-space',
122
153
  'resolution',
123
154
  'reference-resolution',
124
155
  'priority',
125
- 'scale-blend'
156
+ 'scale-blend',
157
+ 'scale-mode'
126
158
  ];
127
159
  }
128
160
 
@@ -142,8 +174,8 @@ class ScreenComponentElement extends ComponentElement {
142
174
  case 'scale-blend':
143
175
  this.scaleBlend = parseNumber(newValue, 0.5, name);
144
176
  break;
145
- case 'blend':
146
- this.blend = parseBool(newValue, false);
177
+ case 'scale-mode':
178
+ this.scaleMode = parseEnum(newValue, scaleModes, 'none', name);
147
179
  break;
148
180
  case 'screen-space':
149
181
  this.screenSpace = parseBool(newValue, false);
@@ -154,10 +186,4 @@ class ScreenComponentElement extends ComponentElement {
154
186
 
155
187
  customElements.define('pc-screen', ScreenComponentElement);
156
188
 
157
- declare global {
158
- interface HTMLElementTagNameMap {
159
- 'pc-screen': ScreenComponentElement;
160
- }
161
- }
162
-
163
189
  export { ScreenComponentElement };