@playcanvas/web-components 0.2.12 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +84 -84
  3. package/dist/components/element-component.d.ts +12 -0
  4. package/dist/components/light-component.d.ts +48 -0
  5. package/dist/components/splat-component.d.ts +0 -13
  6. package/dist/pwc.cjs +298 -207
  7. package/dist/pwc.cjs.map +1 -1
  8. package/dist/pwc.js +298 -207
  9. package/dist/pwc.js.map +1 -1
  10. package/dist/pwc.min.js +1 -1
  11. package/dist/pwc.min.js.map +1 -1
  12. package/dist/pwc.mjs +299 -208
  13. package/dist/pwc.mjs.map +1 -1
  14. package/package.json +76 -64
  15. package/src/app.ts +612 -606
  16. package/src/asset.ts +159 -159
  17. package/src/async-element.ts +46 -46
  18. package/src/colors.ts +150 -150
  19. package/src/components/camera-component.ts +557 -557
  20. package/src/components/collision-component.ts +183 -183
  21. package/src/components/component.ts +97 -97
  22. package/src/components/element-component.ts +367 -341
  23. package/src/components/light-component.ts +570 -466
  24. package/src/components/listener-component.ts +30 -30
  25. package/src/components/particlesystem-component.ts +155 -155
  26. package/src/components/render-component.ts +147 -147
  27. package/src/components/rigidbody-component.ts +227 -227
  28. package/src/components/screen-component.ts +157 -157
  29. package/src/components/script-component.ts +270 -270
  30. package/src/components/script.ts +90 -90
  31. package/src/components/sound-component.ts +230 -230
  32. package/src/components/sound-slot.ts +288 -288
  33. package/src/components/splat-component.ts +102 -133
  34. package/src/entity.ts +360 -360
  35. package/src/index.ts +63 -63
  36. package/src/material.ts +141 -141
  37. package/src/model.ts +111 -111
  38. package/src/module.ts +43 -43
  39. package/src/scene.ts +217 -217
  40. package/src/sky.ts +293 -293
  41. package/src/utils.ts +71 -71
@@ -1,288 +1,288 @@
1
- import { SoundSlot } from 'playcanvas';
2
-
3
- import { AssetElement } from '../asset';
4
- import { AsyncElement } from '../async-element';
5
- import { SoundComponentElement } from './sound-component';
6
-
7
- /**
8
- * The SoundSlotElement interface provides properties and methods for manipulating
9
- * `<pc-sound>` elements. The SoundSlotElement interface also inherits the properties and
10
- * methods of the {@link AsyncElement} interface.
11
- */
12
- class SoundSlotElement extends AsyncElement {
13
- private _asset: string = '';
14
-
15
- private _autoPlay: boolean = false;
16
-
17
- private _duration: number | null = null;
18
-
19
- private _loop: boolean = false;
20
-
21
- private _name: string = '';
22
-
23
- private _overlap: boolean = false;
24
-
25
- private _pitch: number = 1;
26
-
27
- private _startTime: number = 0;
28
-
29
- private _volume: number = 1;
30
-
31
- /**
32
- * The sound slot.
33
- */
34
- soundSlot: SoundSlot | null = null;
35
-
36
- async connectedCallback() {
37
- await this.soundElement?.ready();
38
-
39
- const options = {
40
- autoPlay: this._autoPlay,
41
- loop: this._loop,
42
- overlap: this._overlap,
43
- pitch: this._pitch,
44
- startTime: this._startTime,
45
- volume: this._volume
46
- } as any;
47
- if (this._duration) {
48
- options.duration = this._duration;
49
- }
50
-
51
- this.soundSlot = this.soundElement!.component!.addSlot(this._name, options);
52
- this.asset = this._asset;
53
- if (this._autoPlay) {
54
- this.soundSlot!.play();
55
- }
56
-
57
- this._onReady();
58
- }
59
-
60
- disconnectedCallback() {
61
- this.soundElement!.component!.removeSlot(this._name);
62
- }
63
-
64
- protected get soundElement(): SoundComponentElement | null {
65
- const soundElement = this.parentElement as SoundComponentElement;
66
-
67
- if (!(soundElement instanceof SoundComponentElement)) {
68
- console.warn('pc-sound-slot must be a direct child of a pc-sound element');
69
- return null;
70
- }
71
-
72
- return soundElement;
73
- }
74
-
75
- /**
76
- * Sets the id of the `pc-asset` to use for the sound slot.
77
- * @param value - The asset.
78
- */
79
- set asset(value: string) {
80
- this._asset = value;
81
- if (this.soundSlot) {
82
- const id = AssetElement.get(value)?.id;
83
- if (id) {
84
- this.soundSlot.asset = id;
85
- }
86
- }
87
- }
88
-
89
- /**
90
- * Gets the id of the `pc-asset` to use for the sound slot.
91
- * @returns The asset.
92
- */
93
- get asset() {
94
- return this._asset;
95
- }
96
-
97
- /**
98
- * Sets the auto play flag of the sound slot.
99
- * @param value - The auto play flag.
100
- */
101
- set autoPlay(value: boolean) {
102
- this._autoPlay = value;
103
- if (this.soundSlot) {
104
- this.soundSlot.autoPlay = value;
105
- }
106
- }
107
-
108
- /**
109
- * Gets the auto play flag of the sound slot.
110
- * @returns The auto play flag.
111
- */
112
- get autoPlay() {
113
- return this._autoPlay;
114
- }
115
-
116
- /**
117
- * Sets the duration of the sound slot.
118
- * @param value - The duration.
119
- */
120
- set duration(value: number) {
121
- this._duration = value;
122
- if (this.soundSlot) {
123
- this.soundSlot.duration = value;
124
- }
125
- }
126
-
127
- /**
128
- * Gets the duration of the sound slot.
129
- * @returns The duration.
130
- */
131
- get duration() {
132
- return this._duration as number;
133
- }
134
-
135
- /**
136
- * Sets the loop flag of the sound slot.
137
- * @param value - The loop flag.
138
- */
139
- set loop(value: boolean) {
140
- this._loop = value;
141
- if (this.soundSlot) {
142
- this.soundSlot.loop = value;
143
- }
144
- }
145
-
146
- /**
147
- * Gets the loop flag of the sound slot.
148
- * @returns The loop flag.
149
- */
150
- get loop() {
151
- return this._loop;
152
- }
153
-
154
- /**
155
- * Sets the name of the sound slot.
156
- * @param value - The name.
157
- */
158
- set name(value: string) {
159
- this._name = value;
160
- if (this.soundSlot) {
161
- this.soundSlot.name = value;
162
- }
163
- }
164
-
165
- /**
166
- * Gets the name of the sound slot.
167
- * @returns The name.
168
- */
169
- get name() {
170
- return this._name;
171
- }
172
-
173
- /**
174
- * Sets the overlap flag of the sound slot.
175
- * @param value - The overlap flag.
176
- */
177
- set overlap(value: boolean) {
178
- this._overlap = value;
179
- if (this.soundSlot) {
180
- this.soundSlot.overlap = value;
181
- }
182
- }
183
-
184
- /**
185
- * Gets the overlap flag of the sound slot.
186
- * @returns The overlap flag.
187
- */
188
- get overlap() {
189
- return this._overlap;
190
- }
191
-
192
- /**
193
- * Sets the pitch of the sound slot.
194
- * @param value - The pitch.
195
- */
196
- set pitch(value: number) {
197
- this._pitch = value;
198
- if (this.soundSlot) {
199
- this.soundSlot.pitch = value;
200
- }
201
- }
202
-
203
- /**
204
- * Gets the pitch of the sound slot.
205
- * @returns The pitch.
206
- */
207
- get pitch() {
208
- return this._pitch;
209
- }
210
-
211
- /**
212
- * Sets the start time of the sound slot.
213
- * @param value - The start time.
214
- */
215
- set startTime(value: number) {
216
- this._startTime = value;
217
- if (this.soundSlot) {
218
- this.soundSlot.startTime = value;
219
- }
220
- }
221
-
222
- /**
223
- * Gets the start time of the sound slot.
224
- * @returns The start time.
225
- */
226
- get startTime() {
227
- return this._startTime;
228
- }
229
-
230
- /**
231
- * Sets the volume of the sound slot.
232
- * @param value - The volume.
233
- */
234
- set volume(value: number) {
235
- this._volume = value;
236
- if (this.soundSlot) {
237
- this.soundSlot.volume = value;
238
- }
239
- }
240
-
241
- /**
242
- * Gets the volume of the sound slot.
243
- * @returns The volume.
244
- */
245
- get volume() {
246
- return this._volume;
247
- }
248
-
249
- static get observedAttributes() {
250
- return ['asset', 'auto-play', 'duration', 'loop', 'name', 'overlap', 'pitch', 'start-time', 'volume'];
251
- }
252
-
253
- attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
254
- switch (name) {
255
- case 'asset':
256
- this.asset = newValue;
257
- break;
258
- case 'auto-play':
259
- this.autoPlay = this.hasAttribute('auto-play');
260
- break;
261
- case 'duration':
262
- this.duration = parseFloat(newValue);
263
- break;
264
- case 'loop':
265
- this.loop = this.hasAttribute('loop');
266
- break;
267
- case 'name':
268
- this.name = newValue;
269
- break;
270
- case 'overlap':
271
- this.overlap = this.hasAttribute('overlap');
272
- break;
273
- case 'pitch':
274
- this.pitch = parseFloat(newValue);
275
- break;
276
- case 'start-time':
277
- this.startTime = parseFloat(newValue);
278
- break;
279
- case 'volume':
280
- this.volume = parseFloat(newValue);
281
- break;
282
- }
283
- }
284
- }
285
-
286
- customElements.define('pc-sound', SoundSlotElement);
287
-
288
- export { SoundSlotElement };
1
+ import { SoundSlot } from 'playcanvas';
2
+
3
+ import { AssetElement } from '../asset';
4
+ import { AsyncElement } from '../async-element';
5
+ import { SoundComponentElement } from './sound-component';
6
+
7
+ /**
8
+ * The SoundSlotElement interface provides properties and methods for manipulating
9
+ * `<pc-sound>` elements. The SoundSlotElement interface also inherits the properties and
10
+ * methods of the {@link AsyncElement} interface.
11
+ */
12
+ class SoundSlotElement extends AsyncElement {
13
+ private _asset: string = '';
14
+
15
+ private _autoPlay: boolean = false;
16
+
17
+ private _duration: number | null = null;
18
+
19
+ private _loop: boolean = false;
20
+
21
+ private _name: string = '';
22
+
23
+ private _overlap: boolean = false;
24
+
25
+ private _pitch: number = 1;
26
+
27
+ private _startTime: number = 0;
28
+
29
+ private _volume: number = 1;
30
+
31
+ /**
32
+ * The sound slot.
33
+ */
34
+ soundSlot: SoundSlot | null = null;
35
+
36
+ async connectedCallback() {
37
+ await this.soundElement?.ready();
38
+
39
+ const options = {
40
+ autoPlay: this._autoPlay,
41
+ loop: this._loop,
42
+ overlap: this._overlap,
43
+ pitch: this._pitch,
44
+ startTime: this._startTime,
45
+ volume: this._volume
46
+ } as any;
47
+ if (this._duration) {
48
+ options.duration = this._duration;
49
+ }
50
+
51
+ this.soundSlot = this.soundElement!.component!.addSlot(this._name, options);
52
+ this.asset = this._asset;
53
+ if (this._autoPlay) {
54
+ this.soundSlot!.play();
55
+ }
56
+
57
+ this._onReady();
58
+ }
59
+
60
+ disconnectedCallback() {
61
+ this.soundElement!.component!.removeSlot(this._name);
62
+ }
63
+
64
+ protected get soundElement(): SoundComponentElement | null {
65
+ const soundElement = this.parentElement as SoundComponentElement;
66
+
67
+ if (!(soundElement instanceof SoundComponentElement)) {
68
+ console.warn('pc-sound-slot must be a direct child of a pc-sound element');
69
+ return null;
70
+ }
71
+
72
+ return soundElement;
73
+ }
74
+
75
+ /**
76
+ * Sets the id of the `pc-asset` to use for the sound slot.
77
+ * @param value - The asset.
78
+ */
79
+ set asset(value: string) {
80
+ this._asset = value;
81
+ if (this.soundSlot) {
82
+ const id = AssetElement.get(value)?.id;
83
+ if (id) {
84
+ this.soundSlot.asset = id;
85
+ }
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Gets the id of the `pc-asset` to use for the sound slot.
91
+ * @returns The asset.
92
+ */
93
+ get asset() {
94
+ return this._asset;
95
+ }
96
+
97
+ /**
98
+ * Sets the auto play flag of the sound slot.
99
+ * @param value - The auto play flag.
100
+ */
101
+ set autoPlay(value: boolean) {
102
+ this._autoPlay = value;
103
+ if (this.soundSlot) {
104
+ this.soundSlot.autoPlay = value;
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Gets the auto play flag of the sound slot.
110
+ * @returns The auto play flag.
111
+ */
112
+ get autoPlay() {
113
+ return this._autoPlay;
114
+ }
115
+
116
+ /**
117
+ * Sets the duration of the sound slot.
118
+ * @param value - The duration.
119
+ */
120
+ set duration(value: number) {
121
+ this._duration = value;
122
+ if (this.soundSlot) {
123
+ this.soundSlot.duration = value;
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Gets the duration of the sound slot.
129
+ * @returns The duration.
130
+ */
131
+ get duration() {
132
+ return this._duration as number;
133
+ }
134
+
135
+ /**
136
+ * Sets the loop flag of the sound slot.
137
+ * @param value - The loop flag.
138
+ */
139
+ set loop(value: boolean) {
140
+ this._loop = value;
141
+ if (this.soundSlot) {
142
+ this.soundSlot.loop = value;
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Gets the loop flag of the sound slot.
148
+ * @returns The loop flag.
149
+ */
150
+ get loop() {
151
+ return this._loop;
152
+ }
153
+
154
+ /**
155
+ * Sets the name of the sound slot.
156
+ * @param value - The name.
157
+ */
158
+ set name(value: string) {
159
+ this._name = value;
160
+ if (this.soundSlot) {
161
+ this.soundSlot.name = value;
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Gets the name of the sound slot.
167
+ * @returns The name.
168
+ */
169
+ get name() {
170
+ return this._name;
171
+ }
172
+
173
+ /**
174
+ * Sets the overlap flag of the sound slot.
175
+ * @param value - The overlap flag.
176
+ */
177
+ set overlap(value: boolean) {
178
+ this._overlap = value;
179
+ if (this.soundSlot) {
180
+ this.soundSlot.overlap = value;
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Gets the overlap flag of the sound slot.
186
+ * @returns The overlap flag.
187
+ */
188
+ get overlap() {
189
+ return this._overlap;
190
+ }
191
+
192
+ /**
193
+ * Sets the pitch of the sound slot.
194
+ * @param value - The pitch.
195
+ */
196
+ set pitch(value: number) {
197
+ this._pitch = value;
198
+ if (this.soundSlot) {
199
+ this.soundSlot.pitch = value;
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Gets the pitch of the sound slot.
205
+ * @returns The pitch.
206
+ */
207
+ get pitch() {
208
+ return this._pitch;
209
+ }
210
+
211
+ /**
212
+ * Sets the start time of the sound slot.
213
+ * @param value - The start time.
214
+ */
215
+ set startTime(value: number) {
216
+ this._startTime = value;
217
+ if (this.soundSlot) {
218
+ this.soundSlot.startTime = value;
219
+ }
220
+ }
221
+
222
+ /**
223
+ * Gets the start time of the sound slot.
224
+ * @returns The start time.
225
+ */
226
+ get startTime() {
227
+ return this._startTime;
228
+ }
229
+
230
+ /**
231
+ * Sets the volume of the sound slot.
232
+ * @param value - The volume.
233
+ */
234
+ set volume(value: number) {
235
+ this._volume = value;
236
+ if (this.soundSlot) {
237
+ this.soundSlot.volume = value;
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Gets the volume of the sound slot.
243
+ * @returns The volume.
244
+ */
245
+ get volume() {
246
+ return this._volume;
247
+ }
248
+
249
+ static get observedAttributes() {
250
+ return ['asset', 'auto-play', 'duration', 'loop', 'name', 'overlap', 'pitch', 'start-time', 'volume'];
251
+ }
252
+
253
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
254
+ switch (name) {
255
+ case 'asset':
256
+ this.asset = newValue;
257
+ break;
258
+ case 'auto-play':
259
+ this.autoPlay = this.hasAttribute('auto-play');
260
+ break;
261
+ case 'duration':
262
+ this.duration = parseFloat(newValue);
263
+ break;
264
+ case 'loop':
265
+ this.loop = this.hasAttribute('loop');
266
+ break;
267
+ case 'name':
268
+ this.name = newValue;
269
+ break;
270
+ case 'overlap':
271
+ this.overlap = this.hasAttribute('overlap');
272
+ break;
273
+ case 'pitch':
274
+ this.pitch = parseFloat(newValue);
275
+ break;
276
+ case 'start-time':
277
+ this.startTime = parseFloat(newValue);
278
+ break;
279
+ case 'volume':
280
+ this.volume = parseFloat(newValue);
281
+ break;
282
+ }
283
+ }
284
+ }
285
+
286
+ customElements.define('pc-sound', SoundSlotElement);
287
+
288
+ export { SoundSlotElement };