@playcanvas/web-components 0.9.0 → 0.10.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 (74) hide show
  1. package/README.md +18 -0
  2. package/dist/app.d.ts +55 -9
  3. package/dist/asset.d.ts +25 -1
  4. package/dist/async-element.d.ts +15 -2
  5. package/dist/components/button-component.d.ts +1 -1
  6. package/dist/components/camera-component.d.ts +1 -1
  7. package/dist/components/collision-component.d.ts +1 -1
  8. package/dist/components/component.d.ts +6 -5
  9. package/dist/components/element-component.d.ts +1 -1
  10. package/dist/components/gsplat-component.d.ts +1 -1
  11. package/dist/components/layoutchild-component.d.ts +1 -1
  12. package/dist/components/layoutgroup-component.d.ts +1 -1
  13. package/dist/components/light-component.d.ts +1 -1
  14. package/dist/components/particlesystem-component.d.ts +1 -1
  15. package/dist/components/render-component.d.ts +1 -1
  16. package/dist/components/rigidbody-component.d.ts +1 -1
  17. package/dist/components/screen-component.d.ts +1 -1
  18. package/dist/components/script.d.ts +8 -1
  19. package/dist/components/scrollbar-component.d.ts +1 -1
  20. package/dist/components/scrollview-component.d.ts +1 -1
  21. package/dist/components/sound-component.d.ts +1 -1
  22. package/dist/components/sound-slot.d.ts +9 -1
  23. package/dist/custom-elements.json +16704 -0
  24. package/dist/entity.d.ts +24 -5
  25. package/dist/loading-bar.d.ts +35 -0
  26. package/dist/material.d.ts +972 -4
  27. package/dist/model.d.ts +1 -1
  28. package/dist/module.d.ts +10 -0
  29. package/dist/{utils.d.ts → parse.d.ts} +63 -33
  30. package/dist/pwc.cjs +3070 -699
  31. package/dist/pwc.cjs.map +1 -1
  32. package/dist/pwc.js +3070 -699
  33. package/dist/pwc.js.map +1 -1
  34. package/dist/pwc.min.js +1 -1
  35. package/dist/pwc.min.js.map +1 -1
  36. package/dist/pwc.min.mjs +2 -0
  37. package/dist/pwc.min.mjs.map +1 -0
  38. package/dist/pwc.mjs +3071 -700
  39. package/dist/pwc.mjs.map +1 -1
  40. package/dist/scene.d.ts +12 -4
  41. package/dist/sky.d.ts +1 -1
  42. package/dist/vscode.html-custom-data.json +1800 -0
  43. package/dist/web-types.json +3836 -0
  44. package/package.json +29 -11
  45. package/src/app.ts +178 -78
  46. package/src/asset.ts +44 -2
  47. package/src/async-element.ts +17 -4
  48. package/src/components/button-component.ts +6 -6
  49. package/src/components/camera-component.ts +2 -2
  50. package/src/components/collision-component.ts +2 -2
  51. package/src/components/component.ts +8 -7
  52. package/src/components/element-component.ts +6 -6
  53. package/src/components/gsplat-component.ts +3 -3
  54. package/src/components/layoutchild-component.ts +2 -2
  55. package/src/components/layoutgroup-component.ts +2 -2
  56. package/src/components/light-component.ts +2 -2
  57. package/src/components/particlesystem-component.ts +2 -2
  58. package/src/components/render-component.ts +10 -5
  59. package/src/components/rigidbody-component.ts +2 -2
  60. package/src/components/screen-component.ts +2 -2
  61. package/src/components/script-component.ts +4 -4
  62. package/src/components/script.ts +9 -2
  63. package/src/components/scrollbar-component.ts +3 -3
  64. package/src/components/scrollview-component.ts +6 -6
  65. package/src/components/sound-component.ts +2 -2
  66. package/src/components/sound-slot.ts +31 -9
  67. package/src/entity.ts +56 -22
  68. package/src/loading-bar.ts +122 -0
  69. package/src/material.ts +2402 -59
  70. package/src/model.ts +2 -2
  71. package/src/module.ts +10 -0
  72. package/src/{utils.ts → parse.ts} +104 -65
  73. package/src/scene.ts +51 -21
  74. package/src/sky.ts +3 -3
package/dist/model.d.ts CHANGED
@@ -24,7 +24,7 @@ declare class ModelElement extends AsyncElement {
24
24
  */
25
25
  get asset(): string;
26
26
  static get observedAttributes(): string[];
27
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
27
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
28
28
  }
29
29
  declare global {
30
30
  interface HTMLElementTagNameMap {
package/dist/module.d.ts CHANGED
@@ -3,6 +3,16 @@
3
3
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-module/ | `<pc-module>`} elements.
4
4
  * The ModuleElement interface also inherits the properties and methods of the
5
5
  * {@link HTMLElement} interface.
6
+ *
7
+ * Note that these attributes are read once when the element is created, so changing them later
8
+ * has no effect.
9
+ *
10
+ * @attribute {string} name - The name of the WebAssembly module to configure, e.g. `Basis` or
11
+ * `Ammo`.
12
+ * @attribute {string} glue - The URL of the module's glue script.
13
+ * @attribute {string} wasm - The URL of the module's WebAssembly binary.
14
+ * @attribute {string} fallback - The URL of the module's asm.js fallback script, used when
15
+ * WebAssembly is unavailable.
6
16
  */
7
17
  declare class ModuleElement extends HTMLElement {
8
18
  private loadPromise;
@@ -1,17 +1,21 @@
1
- import { Color, Entity, Quat, Vec2, Vec3, Vec4 } from 'playcanvas';
2
1
  /**
3
- * Parse a boolean attribute value. The same rules apply to every boolean attribute:
2
+ * Converts HTML attribute values into the values the engine expects. Every element's
3
+ * `attributeChangedCallback` funnels through this module.
4
4
  *
5
- * - Attribute absent (or removed): the supplied default is used.
6
- * - Attribute set to the string 'false': `false`.
7
- * - Attribute present with any other value, including the empty string of a bare boolean
8
- * attribute (e.g. `<pc-light cast-shadows>`): `true`.
5
+ * The parsers share one contract:
9
6
  *
10
- * @param value - The attribute value to parse (`null` when the attribute is absent).
11
- * @param defaultValue - The value to use when the attribute is absent or removed.
12
- * @returns The parsed boolean.
7
+ * - A `null` value means the attribute is absent or was removed, and yields the supplied default.
8
+ * - A malformed value yields the same default and logs exactly one `console.warn` naming the
9
+ * attribute, so misuse is reported rather than thrown — nothing here throws or rejects.
10
+ * - A math-type default is cloned on the way out, which is what makes it safe to pass the engine's
11
+ * shared frozen constants (`Vec3.ZERO`, `Color.WHITE`) as defaults.
12
+ * - `parseBool` and `parseTags` take no attribute name, because every value is valid for them and
13
+ * so they never warn.
14
+ *
15
+ * `getEntity` is the exception: it resolves a reference to a live entity rather than parsing a
16
+ * literal, and returns `null` instead of falling back to a default.
13
17
  */
14
- export declare const parseBool: (value: string | null, defaultValue: boolean) => boolean;
18
+ import { Color, Entity, Quat, Vec2, Vec3, Vec4 } from 'playcanvas';
15
19
  /**
16
20
  * Splits an attribute value into exactly `count` numeric components. Returns `null` when the
17
21
  * value does not consist of exactly `count` whitespace-separated finite numbers.
@@ -22,6 +26,19 @@ export declare const parseBool: (value: string | null, defaultValue: boolean) =>
22
26
  * @ignore
23
27
  */
24
28
  export declare const parseComponents: (value: string, count: number) => number[] | null;
29
+ /**
30
+ * Parse a boolean attribute value. The same rules apply to every boolean attribute:
31
+ *
32
+ * - Attribute absent (or removed): the supplied default is used.
33
+ * - Attribute set to the string 'false': `false`.
34
+ * - Attribute present with any other value, including the empty string of a bare boolean
35
+ * attribute (e.g. `<pc-light cast-shadows>`): `true`.
36
+ *
37
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
38
+ * @param defaultValue - The value to use when the attribute is absent or removed.
39
+ * @returns The parsed boolean.
40
+ */
41
+ export declare const parseBool: (value: string | null, defaultValue: boolean) => boolean;
25
42
  /**
26
43
  * Parse a color attribute value. The expected format is a CSS color name (e.g. 'rebeccapurple'),
27
44
  * a hex color (e.g. '#ff0000' or '#f00'), or 3 or 4 space-separated numbers in the range 0 to 1
@@ -35,6 +52,29 @@ export declare const parseComponents: (value: string, count: number) => number[]
35
52
  * @returns The parsed Color object.
36
53
  */
37
54
  export declare const parseColor: <T extends Color | null>(value: string | null, defaultValue: T, attribute: string) => Color | T;
55
+ /**
56
+ * Resolves an enum attribute value against its set of valid names. Returns the value when it is
57
+ * one of the valid names. Returns `defaultValue` when the attribute is absent (`null`), or when
58
+ * the value is invalid — the latter also logs a warning listing the valid names.
59
+ *
60
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
61
+ * @param valid - The valid names: an array, or a map whose keys are the valid names.
62
+ * @param defaultValue - The value to use when the attribute is absent or invalid.
63
+ * @param attribute - The attribute name, used in the warning message.
64
+ * @returns The resolved enum name.
65
+ */
66
+ export declare const parseEnum: <T extends string>(value: string | null, valid: readonly T[] | ReadonlyMap<T, number>, defaultValue: T, attribute: string) => T;
67
+ /**
68
+ * Parses a number attribute value. Returns the parsed number when the value is a finite number.
69
+ * Returns `defaultValue` when the attribute is absent (`null`), or when the value is not a
70
+ * finite number — the latter also logs a warning.
71
+ *
72
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
73
+ * @param defaultValue - The value to use when the attribute is absent or invalid.
74
+ * @param attribute - The attribute name, used in the warning message.
75
+ * @returns The parsed number.
76
+ */
77
+ export declare const parseNumber: <T extends number | null>(value: string | null, defaultValue: T, attribute: string) => number | T;
38
78
  /**
39
79
  * Parse an Euler-angles attribute value into a quaternion. The expected format is 3
40
80
  * space-separated angles in degrees (e.g. '0 90 0'). Returns `defaultValue` (cloned, when it is
@@ -47,6 +87,19 @@ export declare const parseColor: <T extends Color | null>(value: string | null,
47
87
  * @returns The parsed Quat object.
48
88
  */
49
89
  export declare const parseQuat: <T extends Quat | null>(value: string | null, defaultValue: T, attribute: string) => Quat | T;
90
+ /**
91
+ * Parse a tags attribute value. The expected format is a comma-separated list of tag names
92
+ * (e.g. 'enemy, flying'). Surrounding whitespace is trimmed from each name and empty names are
93
+ * discarded, so a trailing comma or a doubled separator does not produce a blank tag. Returns a
94
+ * copy of `defaultValue` when the attribute is absent or removed (`null`).
95
+ *
96
+ * Every value is valid, so this never warns.
97
+ *
98
+ * @param value - The attribute value to parse (`null` when the attribute is absent).
99
+ * @param defaultValue - The value to use when the attribute is absent or removed.
100
+ * @returns The parsed tag names.
101
+ */
102
+ export declare const parseTags: (value: string | null, defaultValue?: string[]) => string[];
50
103
  /**
51
104
  * Parse a Vec2 attribute value. The expected format is 2 space-separated numbers (e.g. '1 2').
52
105
  * Returns `defaultValue` (cloned, when it is a vector) when the attribute is absent (`null`),
@@ -80,29 +133,6 @@ export declare const parseVec3: <T extends Vec3 | null>(value: string | null, de
80
133
  * @returns The parsed Vec4 object.
81
134
  */
82
135
  export declare const parseVec4: <T extends Vec4 | null>(value: string | null, defaultValue: T, attribute: string) => Vec4 | T;
83
- /**
84
- * Resolves an enum attribute value against its set of valid names. Returns the value when it is
85
- * one of the valid names. Returns `defaultValue` when the attribute is absent (`null`), or when
86
- * the value is invalid — the latter also logs a warning listing the valid names.
87
- *
88
- * @param value - The attribute value to parse (`null` when the attribute is absent).
89
- * @param valid - The valid names: an array, or a map whose keys are the valid names.
90
- * @param defaultValue - The value to use when the attribute is absent or invalid.
91
- * @param attribute - The attribute name, used in the warning message.
92
- * @returns The resolved enum name.
93
- */
94
- export declare const parseEnum: <T extends string>(value: string | null, valid: readonly T[] | ReadonlyMap<T, number>, defaultValue: T, attribute: string) => T;
95
- /**
96
- * Parses a number attribute value. Returns the parsed number when the value is a finite number.
97
- * Returns `defaultValue` when the attribute is absent (`null`), or when the value is not a
98
- * finite number — the latter also logs a warning.
99
- *
100
- * @param value - The attribute value to parse (`null` when the attribute is absent).
101
- * @param defaultValue - The value to use when the attribute is absent or invalid.
102
- * @param attribute - The attribute name, used in the warning message.
103
- * @returns The parsed number.
104
- */
105
- export declare const parseNumber: <T extends number | null>(value: string | null, defaultValue: T, attribute: string) => number | T;
106
136
  /**
107
137
  * Resolves a reference string to the {@link Entity} backing a `<pc-entity>` element. The reference
108
138
  * can be a CSS selector (e.g. `#my-id`, `pc-entity[name="Foo"]`), a bare element id, or a bare