@playcanvas/web-components 0.3.0 → 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 (40) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +84 -84
  3. package/dist/components/light-component.d.ts +48 -0
  4. package/dist/components/splat-component.d.ts +0 -13
  5. package/dist/pwc.cjs +275 -207
  6. package/dist/pwc.cjs.map +1 -1
  7. package/dist/pwc.js +275 -207
  8. package/dist/pwc.js.map +1 -1
  9. package/dist/pwc.min.js +1 -1
  10. package/dist/pwc.min.js.map +1 -1
  11. package/dist/pwc.mjs +276 -208
  12. package/dist/pwc.mjs.map +1 -1
  13. package/package.json +76 -66
  14. package/src/app.ts +612 -606
  15. package/src/asset.ts +159 -159
  16. package/src/async-element.ts +46 -46
  17. package/src/colors.ts +150 -150
  18. package/src/components/camera-component.ts +557 -557
  19. package/src/components/collision-component.ts +183 -183
  20. package/src/components/component.ts +97 -97
  21. package/src/components/element-component.ts +367 -367
  22. package/src/components/light-component.ts +570 -466
  23. package/src/components/listener-component.ts +30 -30
  24. package/src/components/particlesystem-component.ts +155 -155
  25. package/src/components/render-component.ts +147 -147
  26. package/src/components/rigidbody-component.ts +227 -227
  27. package/src/components/screen-component.ts +157 -157
  28. package/src/components/script-component.ts +270 -270
  29. package/src/components/script.ts +90 -90
  30. package/src/components/sound-component.ts +230 -230
  31. package/src/components/sound-slot.ts +288 -288
  32. package/src/components/splat-component.ts +102 -133
  33. package/src/entity.ts +360 -360
  34. package/src/index.ts +63 -63
  35. package/src/material.ts +141 -141
  36. package/src/model.ts +111 -111
  37. package/src/module.ts +43 -43
  38. package/src/scene.ts +217 -217
  39. package/src/sky.ts +293 -293
  40. package/src/utils.ts +71 -71
@@ -1,367 +1,367 @@
1
- import { Color, ElementComponent, Vec2, Vec4 } from 'playcanvas';
2
-
3
- import { AssetElement } from '../asset';
4
- import { ComponentElement } from './component';
5
- import { parseColor, parseVec2, parseVec4 } from '../utils';
6
-
7
- /**
8
- * The ElementComponentElement interface provides properties and methods for manipulating
9
- * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-element/ | `<pc-element>`} elements.
10
- * The ElementComponentElement interface also inherits the properties and methods of the
11
- * {@link HTMLElement} interface.
12
- *
13
- * @category Components
14
- */
15
- class ElementComponentElement extends ComponentElement {
16
- private _anchor: Vec4 = new Vec4(0.5, 0.5, 0.5, 0.5);
17
-
18
- private _asset: string = '';
19
-
20
- private _autoWidth: boolean = true;
21
-
22
- private _color: Color = new Color(1, 1, 1, 1);
23
-
24
- private _enableMarkup: boolean = false;
25
-
26
- private _fontSize: number = 32;
27
-
28
- private _lineHeight: number = 32;
29
-
30
- private _pivot: Vec2 = new Vec2(0.5, 0.5);
31
-
32
- private _text: string = '';
33
-
34
- private _type: 'group' | 'image' | 'text' = 'group';
35
-
36
- private _width: number = 0;
37
-
38
- private _wrapLines: boolean = false;
39
-
40
- /** @ignore */
41
- constructor() {
42
- super('element');
43
- }
44
-
45
- initComponent() {
46
- this.component!._text._material.useFog = true;
47
- }
48
-
49
- getInitialComponentData() {
50
- return {
51
- anchor: this._anchor,
52
- autoWidth: this._autoWidth,
53
- color: this._color,
54
- enableMarkup: this._enableMarkup,
55
- fontAsset: AssetElement.get(this._asset)!.id,
56
- fontSize: this._fontSize,
57
- lineHeight: this._lineHeight,
58
- pivot: this._pivot,
59
- type: this._type,
60
- text: this._text,
61
- width: this._width,
62
- wrapLines: this._wrapLines
63
- };
64
- }
65
-
66
- /**
67
- * Gets the underlying PlayCanvas element component.
68
- * @returns The element component.
69
- */
70
- get component(): ElementComponent | null {
71
- return super.component as ElementComponent | null;
72
- }
73
-
74
- /**
75
- * Sets the anchor of the element component.
76
- * @param value - The anchor.
77
- */
78
- set anchor(value: Vec4) {
79
- this._anchor = value;
80
- if (this.component) {
81
- this.component.anchor = value;
82
- }
83
- }
84
-
85
- /**
86
- * Gets the anchor of the element component.
87
- * @returns The anchor.
88
- */
89
- get anchor() {
90
- return this._anchor;
91
- }
92
-
93
- /**
94
- * Sets the id of the `pc-asset` to use for the font.
95
- * @param value - The asset ID.
96
- */
97
- set asset(value: string) {
98
- this._asset = value;
99
- const asset = AssetElement.get(value);
100
- if (this.component && asset) {
101
- this.component.fontAsset = asset.id;
102
- }
103
- }
104
-
105
- /**
106
- * Gets the id of the `pc-asset` to use for the font.
107
- * @returns The asset ID.
108
- */
109
- get asset() {
110
- return this._asset;
111
- }
112
-
113
- /**
114
- * Sets whether the element component should automatically adjust its width.
115
- * @param value - Whether to automatically adjust the width.
116
- */
117
- set autoWidth(value: boolean) {
118
- this._autoWidth = value;
119
- if (this.component) {
120
- this.component.autoWidth = value;
121
- }
122
- }
123
-
124
- /**
125
- * Gets whether the element component should automatically adjust its width.
126
- * @returns Whether to automatically adjust the width.
127
- */
128
- get autoWidth() {
129
- return this._autoWidth;
130
- }
131
-
132
- /**
133
- * Sets the color of the element component.
134
- * @param value - The color.
135
- */
136
- set color(value: Color) {
137
- this._color = value;
138
- if (this.component) {
139
- this.component.color = value;
140
- }
141
- }
142
-
143
- /**
144
- * Gets the color of the element component.
145
- * @returns The color.
146
- */
147
- get color() {
148
- return this._color;
149
- }
150
-
151
- /**
152
- * Sets whether the element component should use markup.
153
- * @param value - Whether to enable markup.
154
- */
155
- set enableMarkup(value: boolean) {
156
- this._enableMarkup = value;
157
- if (this.component) {
158
- this.component.enableMarkup = value;
159
- }
160
- }
161
-
162
- /**
163
- * Gets whether the element component should use markup.
164
- * @returns Whether markup is enabled.
165
- */
166
- get enableMarkup() {
167
- return this._enableMarkup;
168
- }
169
-
170
- /**
171
- * Sets the font size of the element component.
172
- * @param value - The font size.
173
- */
174
- set fontSize(value: number) {
175
- this._fontSize = value;
176
- if (this.component) {
177
- this.component.fontSize = value;
178
- }
179
- }
180
-
181
- /**
182
- * Gets the font size of the element component.
183
- * @returns The font size.
184
- */
185
- get fontSize() {
186
- return this._fontSize;
187
- }
188
-
189
- /**
190
- * Sets the line height of the element component.
191
- * @param value - The line height.
192
- */
193
- set lineHeight(value: number) {
194
- this._lineHeight = value;
195
- if (this.component) {
196
- this.component.lineHeight = value;
197
- }
198
- }
199
-
200
- /**
201
- * Gets the line height of the element component.
202
- * @returns The line height.
203
- */
204
- get lineHeight() {
205
- return this._lineHeight;
206
- }
207
-
208
- /**
209
- * Sets the pivot of the element component.
210
- * @param value - The pivot.
211
- */
212
- set pivot(value: Vec2) {
213
- this._pivot = value;
214
- if (this.component) {
215
- this.component.pivot = value;
216
- }
217
- }
218
-
219
- /**
220
- * Gets the pivot of the element component.
221
- * @returns The pivot.
222
- */
223
- get pivot() {
224
- return this._pivot;
225
- }
226
-
227
- /**
228
- * Sets the text of the element component.
229
- * @param value - The text.
230
- */
231
- set text(value: string) {
232
- this._text = value;
233
- if (this.component) {
234
- this.component.text = value;
235
- }
236
- }
237
-
238
- /**
239
- * Gets the text of the element component.
240
- * @returns The text.
241
- */
242
- get text() {
243
- return this._text;
244
- }
245
-
246
- /**
247
- * Sets the type of the element component.
248
- * @param value - The type.
249
- */
250
- set type(value: 'group' | 'image' | 'text') {
251
- this._type = value;
252
- if (this.component) {
253
- this.component.type = value;
254
- }
255
- }
256
-
257
- /**
258
- * Gets the type of the element component.
259
- * @returns The type.
260
- */
261
- get type(): 'group' | 'image' | 'text' {
262
- return this._type;
263
- }
264
-
265
- /**
266
- * Sets the width of the element component.
267
- * @param value - The width.
268
- */
269
- set width(value: number) {
270
- this._width = value;
271
- if (this.component) {
272
- this.component.width = value;
273
- }
274
- }
275
-
276
- /**
277
- * Gets the width of the element component.
278
- * @returns The width.
279
- */
280
- get width() {
281
- return this._width;
282
- }
283
-
284
- /**
285
- * Sets whether the element component should wrap lines.
286
- * @param value - Whether to wrap lines.
287
- */
288
- set wrapLines(value: boolean) {
289
- this._wrapLines = value;
290
- if (this.component) {
291
- this.component.wrapLines = value;
292
- }
293
- }
294
-
295
- /**
296
- * Gets whether the element component should wrap lines.
297
- * @returns Whether to wrap lines.
298
- */
299
- get wrapLines() {
300
- return this._wrapLines;
301
- }
302
-
303
- static get observedAttributes() {
304
- return [
305
- ...super.observedAttributes,
306
- 'anchor',
307
- 'asset',
308
- 'auto-width',
309
- 'color',
310
- 'enable-markup',
311
- 'font-size',
312
- 'line-height',
313
- 'pivot',
314
- 'text',
315
- 'type',
316
- 'width',
317
- 'wrap-lines'
318
- ];
319
- }
320
-
321
- attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
322
- super.attributeChangedCallback(name, _oldValue, newValue);
323
-
324
- switch (name) {
325
- case 'anchor':
326
- this.anchor = parseVec4(newValue);
327
- break;
328
- case 'asset':
329
- this.asset = newValue;
330
- break;
331
- case 'auto-width':
332
- this.autoWidth = newValue !== 'false';
333
- break;
334
- case 'color':
335
- this.color = parseColor(newValue);
336
- break;
337
- case 'enable-markup':
338
- this.enableMarkup = this.hasAttribute(name);
339
- break;
340
- case 'font-size':
341
- this.fontSize = Number(newValue);
342
- break;
343
- case 'line-height':
344
- this.lineHeight = Number(newValue);
345
- break;
346
- case 'pivot':
347
- this.pivot = parseVec2(newValue);
348
- break;
349
- case 'text':
350
- this.text = newValue;
351
- break;
352
- case 'type':
353
- this.type = newValue as 'group' | 'image' | 'text';
354
- break;
355
- case 'width':
356
- this.width = Number(newValue);
357
- break;
358
- case 'wrap-lines':
359
- this.wrapLines = this.hasAttribute(name);
360
- break;
361
- }
362
- }
363
- }
364
-
365
- customElements.define('pc-element', ElementComponentElement);
366
-
367
- export { ElementComponentElement };
1
+ import { Color, ElementComponent, Vec2, Vec4 } from 'playcanvas';
2
+
3
+ import { AssetElement } from '../asset';
4
+ import { ComponentElement } from './component';
5
+ import { parseColor, parseVec2, parseVec4 } from '../utils';
6
+
7
+ /**
8
+ * The ElementComponentElement interface provides properties and methods for manipulating
9
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-element/ | `<pc-element>`} elements.
10
+ * The ElementComponentElement interface also inherits the properties and methods of the
11
+ * {@link HTMLElement} interface.
12
+ *
13
+ * @category Components
14
+ */
15
+ class ElementComponentElement extends ComponentElement {
16
+ private _anchor: Vec4 = new Vec4(0.5, 0.5, 0.5, 0.5);
17
+
18
+ private _asset: string = '';
19
+
20
+ private _autoWidth: boolean = true;
21
+
22
+ private _color: Color = new Color(1, 1, 1, 1);
23
+
24
+ private _enableMarkup: boolean = false;
25
+
26
+ private _fontSize: number = 32;
27
+
28
+ private _lineHeight: number = 32;
29
+
30
+ private _pivot: Vec2 = new Vec2(0.5, 0.5);
31
+
32
+ private _text: string = '';
33
+
34
+ private _type: 'group' | 'image' | 'text' = 'group';
35
+
36
+ private _width: number = 0;
37
+
38
+ private _wrapLines: boolean = false;
39
+
40
+ /** @ignore */
41
+ constructor() {
42
+ super('element');
43
+ }
44
+
45
+ initComponent() {
46
+ this.component!._text._material.useFog = true;
47
+ }
48
+
49
+ getInitialComponentData() {
50
+ return {
51
+ anchor: this._anchor,
52
+ autoWidth: this._autoWidth,
53
+ color: this._color,
54
+ enableMarkup: this._enableMarkup,
55
+ fontAsset: AssetElement.get(this._asset)!.id,
56
+ fontSize: this._fontSize,
57
+ lineHeight: this._lineHeight,
58
+ pivot: this._pivot,
59
+ type: this._type,
60
+ text: this._text,
61
+ width: this._width,
62
+ wrapLines: this._wrapLines
63
+ };
64
+ }
65
+
66
+ /**
67
+ * Gets the underlying PlayCanvas element component.
68
+ * @returns The element component.
69
+ */
70
+ get component(): ElementComponent | null {
71
+ return super.component as ElementComponent | null;
72
+ }
73
+
74
+ /**
75
+ * Sets the anchor of the element component.
76
+ * @param value - The anchor.
77
+ */
78
+ set anchor(value: Vec4) {
79
+ this._anchor = value;
80
+ if (this.component) {
81
+ this.component.anchor = value;
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Gets the anchor of the element component.
87
+ * @returns The anchor.
88
+ */
89
+ get anchor() {
90
+ return this._anchor;
91
+ }
92
+
93
+ /**
94
+ * Sets the id of the `pc-asset` to use for the font.
95
+ * @param value - The asset ID.
96
+ */
97
+ set asset(value: string) {
98
+ this._asset = value;
99
+ const asset = AssetElement.get(value);
100
+ if (this.component && asset) {
101
+ this.component.fontAsset = asset.id;
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Gets the id of the `pc-asset` to use for the font.
107
+ * @returns The asset ID.
108
+ */
109
+ get asset() {
110
+ return this._asset;
111
+ }
112
+
113
+ /**
114
+ * Sets whether the element component should automatically adjust its width.
115
+ * @param value - Whether to automatically adjust the width.
116
+ */
117
+ set autoWidth(value: boolean) {
118
+ this._autoWidth = value;
119
+ if (this.component) {
120
+ this.component.autoWidth = value;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Gets whether the element component should automatically adjust its width.
126
+ * @returns Whether to automatically adjust the width.
127
+ */
128
+ get autoWidth() {
129
+ return this._autoWidth;
130
+ }
131
+
132
+ /**
133
+ * Sets the color of the element component.
134
+ * @param value - The color.
135
+ */
136
+ set color(value: Color) {
137
+ this._color = value;
138
+ if (this.component) {
139
+ this.component.color = value;
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Gets the color of the element component.
145
+ * @returns The color.
146
+ */
147
+ get color() {
148
+ return this._color;
149
+ }
150
+
151
+ /**
152
+ * Sets whether the element component should use markup.
153
+ * @param value - Whether to enable markup.
154
+ */
155
+ set enableMarkup(value: boolean) {
156
+ this._enableMarkup = value;
157
+ if (this.component) {
158
+ this.component.enableMarkup = value;
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Gets whether the element component should use markup.
164
+ * @returns Whether markup is enabled.
165
+ */
166
+ get enableMarkup() {
167
+ return this._enableMarkup;
168
+ }
169
+
170
+ /**
171
+ * Sets the font size of the element component.
172
+ * @param value - The font size.
173
+ */
174
+ set fontSize(value: number) {
175
+ this._fontSize = value;
176
+ if (this.component) {
177
+ this.component.fontSize = value;
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Gets the font size of the element component.
183
+ * @returns The font size.
184
+ */
185
+ get fontSize() {
186
+ return this._fontSize;
187
+ }
188
+
189
+ /**
190
+ * Sets the line height of the element component.
191
+ * @param value - The line height.
192
+ */
193
+ set lineHeight(value: number) {
194
+ this._lineHeight = value;
195
+ if (this.component) {
196
+ this.component.lineHeight = value;
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Gets the line height of the element component.
202
+ * @returns The line height.
203
+ */
204
+ get lineHeight() {
205
+ return this._lineHeight;
206
+ }
207
+
208
+ /**
209
+ * Sets the pivot of the element component.
210
+ * @param value - The pivot.
211
+ */
212
+ set pivot(value: Vec2) {
213
+ this._pivot = value;
214
+ if (this.component) {
215
+ this.component.pivot = value;
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Gets the pivot of the element component.
221
+ * @returns The pivot.
222
+ */
223
+ get pivot() {
224
+ return this._pivot;
225
+ }
226
+
227
+ /**
228
+ * Sets the text of the element component.
229
+ * @param value - The text.
230
+ */
231
+ set text(value: string) {
232
+ this._text = value;
233
+ if (this.component) {
234
+ this.component.text = value;
235
+ }
236
+ }
237
+
238
+ /**
239
+ * Gets the text of the element component.
240
+ * @returns The text.
241
+ */
242
+ get text() {
243
+ return this._text;
244
+ }
245
+
246
+ /**
247
+ * Sets the type of the element component.
248
+ * @param value - The type.
249
+ */
250
+ set type(value: 'group' | 'image' | 'text') {
251
+ this._type = value;
252
+ if (this.component) {
253
+ this.component.type = value;
254
+ }
255
+ }
256
+
257
+ /**
258
+ * Gets the type of the element component.
259
+ * @returns The type.
260
+ */
261
+ get type(): 'group' | 'image' | 'text' {
262
+ return this._type;
263
+ }
264
+
265
+ /**
266
+ * Sets the width of the element component.
267
+ * @param value - The width.
268
+ */
269
+ set width(value: number) {
270
+ this._width = value;
271
+ if (this.component) {
272
+ this.component.width = value;
273
+ }
274
+ }
275
+
276
+ /**
277
+ * Gets the width of the element component.
278
+ * @returns The width.
279
+ */
280
+ get width() {
281
+ return this._width;
282
+ }
283
+
284
+ /**
285
+ * Sets whether the element component should wrap lines.
286
+ * @param value - Whether to wrap lines.
287
+ */
288
+ set wrapLines(value: boolean) {
289
+ this._wrapLines = value;
290
+ if (this.component) {
291
+ this.component.wrapLines = value;
292
+ }
293
+ }
294
+
295
+ /**
296
+ * Gets whether the element component should wrap lines.
297
+ * @returns Whether to wrap lines.
298
+ */
299
+ get wrapLines() {
300
+ return this._wrapLines;
301
+ }
302
+
303
+ static get observedAttributes() {
304
+ return [
305
+ ...super.observedAttributes,
306
+ 'anchor',
307
+ 'asset',
308
+ 'auto-width',
309
+ 'color',
310
+ 'enable-markup',
311
+ 'font-size',
312
+ 'line-height',
313
+ 'pivot',
314
+ 'text',
315
+ 'type',
316
+ 'width',
317
+ 'wrap-lines'
318
+ ];
319
+ }
320
+
321
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
322
+ super.attributeChangedCallback(name, _oldValue, newValue);
323
+
324
+ switch (name) {
325
+ case 'anchor':
326
+ this.anchor = parseVec4(newValue);
327
+ break;
328
+ case 'asset':
329
+ this.asset = newValue;
330
+ break;
331
+ case 'auto-width':
332
+ this.autoWidth = newValue !== 'false';
333
+ break;
334
+ case 'color':
335
+ this.color = parseColor(newValue);
336
+ break;
337
+ case 'enable-markup':
338
+ this.enableMarkup = this.hasAttribute(name);
339
+ break;
340
+ case 'font-size':
341
+ this.fontSize = Number(newValue);
342
+ break;
343
+ case 'line-height':
344
+ this.lineHeight = Number(newValue);
345
+ break;
346
+ case 'pivot':
347
+ this.pivot = parseVec2(newValue);
348
+ break;
349
+ case 'text':
350
+ this.text = newValue;
351
+ break;
352
+ case 'type':
353
+ this.type = newValue as 'group' | 'image' | 'text';
354
+ break;
355
+ case 'width':
356
+ this.width = Number(newValue);
357
+ break;
358
+ case 'wrap-lines':
359
+ this.wrapLines = this.hasAttribute(name);
360
+ break;
361
+ }
362
+ }
363
+ }
364
+
365
+ customElements.define('pc-element', ElementComponentElement);
366
+
367
+ export { ElementComponentElement };