@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,341 +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 _fontSize: number = 32;
25
-
26
- private _lineHeight: number = 32;
27
-
28
- private _pivot: Vec2 = new Vec2(0.5, 0.5);
29
-
30
- private _text: string = '';
31
-
32
- private _type: 'group' | 'image' | 'text' = 'group';
33
-
34
- private _width: number = 0;
35
-
36
- private _wrapLines: boolean = false;
37
-
38
- /** @ignore */
39
- constructor() {
40
- super('element');
41
- }
42
-
43
- initComponent() {
44
- this.component!._text._material.useFog = true;
45
- }
46
-
47
- getInitialComponentData() {
48
- return {
49
- anchor: this._anchor,
50
- autoWidth: this._autoWidth,
51
- color: this._color,
52
- fontAsset: AssetElement.get(this._asset)!.id,
53
- fontSize: this._fontSize,
54
- lineHeight: this._lineHeight,
55
- pivot: this._pivot,
56
- type: this._type,
57
- text: this._text,
58
- width: this._width,
59
- wrapLines: this._wrapLines
60
- };
61
- }
62
-
63
- /**
64
- * Gets the underlying PlayCanvas element component.
65
- * @returns The element component.
66
- */
67
- get component(): ElementComponent | null {
68
- return super.component as ElementComponent | null;
69
- }
70
-
71
- /**
72
- * Sets the anchor of the element component.
73
- * @param value - The anchor.
74
- */
75
- set anchor(value: Vec4) {
76
- this._anchor = value;
77
- if (this.component) {
78
- this.component.anchor = value;
79
- }
80
- }
81
-
82
- /**
83
- * Gets the anchor of the element component.
84
- * @returns The anchor.
85
- */
86
- get anchor() {
87
- return this._anchor;
88
- }
89
-
90
- /**
91
- * Sets the id of the `pc-asset` to use for the font.
92
- * @param value - The asset ID.
93
- */
94
- set asset(value: string) {
95
- this._asset = value;
96
- const asset = AssetElement.get(value);
97
- if (this.component && asset) {
98
- this.component.fontAsset = asset.id;
99
- }
100
- }
101
-
102
- /**
103
- * Gets the id of the `pc-asset` to use for the font.
104
- * @returns The asset ID.
105
- */
106
- get asset() {
107
- return this._asset;
108
- }
109
-
110
- /**
111
- * Sets whether the element component should automatically adjust its width.
112
- * @param value - Whether to automatically adjust the width.
113
- */
114
- set autoWidth(value: boolean) {
115
- this._autoWidth = value;
116
- if (this.component) {
117
- this.component.autoWidth = value;
118
- }
119
- }
120
-
121
- /**
122
- * Gets whether the element component should automatically adjust its width.
123
- * @returns Whether to automatically adjust the width.
124
- */
125
- get autoWidth() {
126
- return this._autoWidth;
127
- }
128
-
129
- /**
130
- * Sets the color of the element component.
131
- * @param value - The color.
132
- */
133
- set color(value: Color) {
134
- this._color = value;
135
- if (this.component) {
136
- this.component.color = value;
137
- }
138
- }
139
-
140
- /**
141
- * Gets the color of the element component.
142
- * @returns The color.
143
- */
144
- get color() {
145
- return this._color;
146
- }
147
-
148
- /**
149
- * Sets the font size of the element component.
150
- * @param value - The font size.
151
- */
152
- set fontSize(value: number) {
153
- this._fontSize = value;
154
- if (this.component) {
155
- this.component.fontSize = value;
156
- }
157
- }
158
-
159
- /**
160
- * Gets the font size of the element component.
161
- * @returns The font size.
162
- */
163
- get fontSize() {
164
- return this._fontSize;
165
- }
166
-
167
- /**
168
- * Sets the line height of the element component.
169
- * @param value - The line height.
170
- */
171
- set lineHeight(value: number) {
172
- this._lineHeight = value;
173
- if (this.component) {
174
- this.component.lineHeight = value;
175
- }
176
- }
177
-
178
- /**
179
- * Gets the line height of the element component.
180
- * @returns The line height.
181
- */
182
- get lineHeight() {
183
- return this._lineHeight;
184
- }
185
-
186
- /**
187
- * Sets the pivot of the element component.
188
- * @param value - The pivot.
189
- */
190
- set pivot(value: Vec2) {
191
- this._pivot = value;
192
- if (this.component) {
193
- this.component.pivot = value;
194
- }
195
- }
196
-
197
- /**
198
- * Gets the pivot of the element component.
199
- * @returns The pivot.
200
- */
201
- get pivot() {
202
- return this._pivot;
203
- }
204
-
205
- /**
206
- * Sets the text of the element component.
207
- * @param value - The text.
208
- */
209
- set text(value: string) {
210
- this._text = value;
211
- if (this.component) {
212
- this.component.text = value;
213
- }
214
- }
215
-
216
- /**
217
- * Gets the text of the element component.
218
- * @returns The text.
219
- */
220
- get text() {
221
- return this._text;
222
- }
223
-
224
- /**
225
- * Sets the type of the element component.
226
- * @param value - The type.
227
- */
228
- set type(value: 'group' | 'image' | 'text') {
229
- this._type = value;
230
- if (this.component) {
231
- this.component.type = value;
232
- }
233
- }
234
-
235
- /**
236
- * Gets the type of the element component.
237
- * @returns The type.
238
- */
239
- get type(): 'group' | 'image' | 'text' {
240
- return this._type;
241
- }
242
-
243
- /**
244
- * Sets the width of the element component.
245
- * @param value - The width.
246
- */
247
- set width(value: number) {
248
- this._width = value;
249
- if (this.component) {
250
- this.component.width = value;
251
- }
252
- }
253
-
254
- /**
255
- * Gets the width of the element component.
256
- * @returns The width.
257
- */
258
- get width() {
259
- return this._width;
260
- }
261
-
262
- /**
263
- * Sets whether the element component should wrap lines.
264
- * @param value - Whether to wrap lines.
265
- */
266
- set wrapLines(value: boolean) {
267
- this._wrapLines = value;
268
- if (this.component) {
269
- this.component.wrapLines = value;
270
- }
271
- }
272
-
273
- /**
274
- * Gets whether the element component should wrap lines.
275
- * @returns Whether to wrap lines.
276
- */
277
- get wrapLines() {
278
- return this._wrapLines;
279
- }
280
-
281
- static get observedAttributes() {
282
- return [
283
- ...super.observedAttributes,
284
- 'anchor',
285
- 'asset',
286
- 'auto-width',
287
- 'color',
288
- 'font-size',
289
- 'line-height',
290
- 'pivot',
291
- 'text',
292
- 'type',
293
- 'width',
294
- 'wrap-lines'
295
- ];
296
- }
297
-
298
- attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
299
- super.attributeChangedCallback(name, _oldValue, newValue);
300
-
301
- switch (name) {
302
- case 'anchor':
303
- this.anchor = parseVec4(newValue);
304
- break;
305
- case 'asset':
306
- this.asset = newValue;
307
- break;
308
- case 'auto-width':
309
- this.autoWidth = newValue !== 'false';
310
- break;
311
- case 'color':
312
- this.color = parseColor(newValue);
313
- break;
314
- case 'font-size':
315
- this.fontSize = Number(newValue);
316
- break;
317
- case 'line-height':
318
- this.lineHeight = Number(newValue);
319
- break;
320
- case 'pivot':
321
- this.pivot = parseVec2(newValue);
322
- break;
323
- case 'text':
324
- this.text = newValue;
325
- break;
326
- case 'type':
327
- this.type = newValue as 'group' | 'image' | 'text';
328
- break;
329
- case 'width':
330
- this.width = Number(newValue);
331
- break;
332
- case 'wrap-lines':
333
- this.wrapLines = this.hasAttribute(name);
334
- break;
335
- }
336
- }
337
- }
338
-
339
- customElements.define('pc-element', ElementComponentElement);
340
-
341
- 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 };