@playcanvas/web-components 0.5.0 → 0.7.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 (36) hide show
  1. package/dist/asset.d.ts +8 -0
  2. package/dist/components/button-component.d.ts +184 -0
  3. package/dist/components/camera-component.d.ts +1 -1
  4. package/dist/components/element-component.d.ts +162 -16
  5. package/dist/components/gsplat-component.d.ts +79 -0
  6. package/dist/components/layoutchild-component.d.ts +110 -0
  7. package/dist/components/layoutgroup-component.d.ts +134 -0
  8. package/dist/components/light-component.d.ts +1 -1
  9. package/dist/components/scrollbar-component.d.ts +68 -0
  10. package/dist/components/scrollview-component.d.ts +173 -0
  11. package/dist/entity.d.ts +4 -0
  12. package/dist/index.d.ts +7 -2
  13. package/dist/pwc.cjs +1957 -59
  14. package/dist/pwc.cjs.map +1 -1
  15. package/dist/pwc.js +1957 -59
  16. package/dist/pwc.js.map +1 -1
  17. package/dist/pwc.min.js +1 -1
  18. package/dist/pwc.min.js.map +1 -1
  19. package/dist/pwc.mjs +1953 -60
  20. package/dist/pwc.mjs.map +1 -1
  21. package/dist/utils.d.ts +20 -1
  22. package/package.json +9 -9
  23. package/src/app.ts +5 -0
  24. package/src/asset.ts +75 -2
  25. package/src/components/button-component.ts +450 -0
  26. package/src/components/element-component.ts +415 -5
  27. package/src/components/gsplat-component.ts +161 -0
  28. package/src/components/layoutchild-component.ts +232 -0
  29. package/src/components/layoutgroup-component.ts +297 -0
  30. package/src/components/scrollbar-component.ts +166 -0
  31. package/src/components/scrollview-component.ts +427 -0
  32. package/src/entity.ts +15 -1
  33. package/src/index.ts +12 -2
  34. package/src/utils.ts +49 -1
  35. package/dist/components/splat-component.d.ts +0 -48
  36. package/src/components/splat-component.ts +0 -102
@@ -0,0 +1,232 @@
1
+ import { LayoutChildComponent } from 'playcanvas';
2
+
3
+ import { ComponentElement } from './component';
4
+
5
+ /**
6
+ * The LayoutChildComponentElement interface provides properties and methods for manipulating
7
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-layoutchild/ | `<pc-layoutchild>`} elements.
8
+ * The LayoutChildComponentElement interface also inherits the properties and methods of the
9
+ * {@link HTMLElement} interface.
10
+ *
11
+ * @category Components
12
+ */
13
+ class LayoutChildComponentElement extends ComponentElement {
14
+ private _minWidth = 0;
15
+
16
+ private _minHeight = 0;
17
+
18
+ private _maxWidth: number | null = null;
19
+
20
+ private _maxHeight: number | null = null;
21
+
22
+ private _fitWidthProportion = 0;
23
+
24
+ private _fitHeightProportion = 0;
25
+
26
+ private _excludeFromLayout = false;
27
+
28
+ /** @ignore */
29
+ constructor() {
30
+ super('layoutchild');
31
+ }
32
+
33
+ getInitialComponentData() {
34
+ return {
35
+ minWidth: this._minWidth,
36
+ minHeight: this._minHeight,
37
+ maxWidth: this._maxWidth,
38
+ maxHeight: this._maxHeight,
39
+ fitWidthProportion: this._fitWidthProportion,
40
+ fitHeightProportion: this._fitHeightProportion,
41
+ excludeFromLayout: this._excludeFromLayout
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Gets the underlying PlayCanvas layout child component.
47
+ * @returns The layout child component.
48
+ */
49
+ get component(): LayoutChildComponent | null {
50
+ return super.component as LayoutChildComponent | null;
51
+ }
52
+
53
+ /**
54
+ * Sets the minimum width the element should be laid out with.
55
+ * @param value - The minimum width.
56
+ */
57
+ set minWidth(value: number) {
58
+ this._minWidth = value;
59
+ if (this.component) {
60
+ this.component.minWidth = value;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Gets the minimum width the element should be laid out with.
66
+ * @returns The minimum width.
67
+ */
68
+ get minWidth() {
69
+ return this._minWidth;
70
+ }
71
+
72
+ /**
73
+ * Sets the minimum height the element should be laid out with.
74
+ * @param value - The minimum height.
75
+ */
76
+ set minHeight(value: number) {
77
+ this._minHeight = value;
78
+ if (this.component) {
79
+ this.component.minHeight = value;
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Gets the minimum height the element should be laid out with.
85
+ * @returns The minimum height.
86
+ */
87
+ get minHeight() {
88
+ return this._minHeight;
89
+ }
90
+
91
+ /**
92
+ * Sets the maximum width the element should be laid out with (or `null` for no limit).
93
+ * @param value - The maximum width.
94
+ */
95
+ set maxWidth(value: number | null) {
96
+ this._maxWidth = value;
97
+ if (this.component) {
98
+ this.component.maxWidth = value as number;
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Gets the maximum width the element should be laid out with.
104
+ * @returns The maximum width.
105
+ */
106
+ get maxWidth() {
107
+ return this._maxWidth;
108
+ }
109
+
110
+ /**
111
+ * Sets the maximum height the element should be laid out with (or `null` for no limit).
112
+ * @param value - The maximum height.
113
+ */
114
+ set maxHeight(value: number | null) {
115
+ this._maxHeight = value;
116
+ if (this.component) {
117
+ this.component.maxHeight = value as number;
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Gets the maximum height the element should be laid out with.
123
+ * @returns The maximum height.
124
+ */
125
+ get maxHeight() {
126
+ return this._maxHeight;
127
+ }
128
+
129
+ /**
130
+ * Sets the proportion of the container's spare width this element should take (when the layout
131
+ * group's `width-fitting` is set to stretch or shrink).
132
+ * @param value - The fit width proportion.
133
+ */
134
+ set fitWidthProportion(value: number) {
135
+ this._fitWidthProportion = value;
136
+ if (this.component) {
137
+ this.component.fitWidthProportion = value;
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Gets the proportion of the container's spare width this element should take.
143
+ * @returns The fit width proportion.
144
+ */
145
+ get fitWidthProportion() {
146
+ return this._fitWidthProportion;
147
+ }
148
+
149
+ /**
150
+ * Sets the proportion of the container's spare height this element should take (when the layout
151
+ * group's `height-fitting` is set to stretch or shrink).
152
+ * @param value - The fit height proportion.
153
+ */
154
+ set fitHeightProportion(value: number) {
155
+ this._fitHeightProportion = value;
156
+ if (this.component) {
157
+ this.component.fitHeightProportion = value;
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Gets the proportion of the container's spare height this element should take.
163
+ * @returns The fit height proportion.
164
+ */
165
+ get fitHeightProportion() {
166
+ return this._fitHeightProportion;
167
+ }
168
+
169
+ /**
170
+ * Sets whether the element should be excluded from the layout (and thus not take up space).
171
+ * @param value - Whether to exclude the element from layout.
172
+ */
173
+ set excludeFromLayout(value: boolean) {
174
+ this._excludeFromLayout = value;
175
+ if (this.component) {
176
+ this.component.excludeFromLayout = value;
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Gets whether the element is excluded from the layout.
182
+ * @returns Whether the element is excluded from layout.
183
+ */
184
+ get excludeFromLayout() {
185
+ return this._excludeFromLayout;
186
+ }
187
+
188
+ static get observedAttributes() {
189
+ return [
190
+ ...super.observedAttributes,
191
+ 'min-width',
192
+ 'min-height',
193
+ 'max-width',
194
+ 'max-height',
195
+ 'fit-width-proportion',
196
+ 'fit-height-proportion',
197
+ 'exclude-from-layout'
198
+ ];
199
+ }
200
+
201
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
202
+ super.attributeChangedCallback(name, _oldValue, newValue);
203
+
204
+ switch (name) {
205
+ case 'min-width':
206
+ this.minWidth = Number(newValue);
207
+ break;
208
+ case 'min-height':
209
+ this.minHeight = Number(newValue);
210
+ break;
211
+ case 'max-width':
212
+ this.maxWidth = newValue === '' ? null : Number(newValue);
213
+ break;
214
+ case 'max-height':
215
+ this.maxHeight = newValue === '' ? null : Number(newValue);
216
+ break;
217
+ case 'fit-width-proportion':
218
+ this.fitWidthProportion = Number(newValue);
219
+ break;
220
+ case 'fit-height-proportion':
221
+ this.fitHeightProportion = Number(newValue);
222
+ break;
223
+ case 'exclude-from-layout':
224
+ this.excludeFromLayout = newValue !== 'false';
225
+ break;
226
+ }
227
+ }
228
+ }
229
+
230
+ customElements.define('pc-layoutchild', LayoutChildComponentElement);
231
+
232
+ export { LayoutChildComponentElement };
@@ -0,0 +1,297 @@
1
+ import { FITTING_NONE, FITTING_STRETCH, FITTING_SHRINK, FITTING_BOTH, LayoutGroupComponent, ORIENTATION_HORIZONTAL, ORIENTATION_VERTICAL, Vec2, Vec4 } from 'playcanvas';
2
+
3
+ import { ComponentElement } from './component';
4
+ import { parseEnum, parseVec2, parseVec4 } from '../utils';
5
+
6
+ const orientations = new Map<string, number>([
7
+ ['horizontal', ORIENTATION_HORIZONTAL],
8
+ ['vertical', ORIENTATION_VERTICAL]
9
+ ]);
10
+
11
+ const fittings = new Map<string, number>([
12
+ ['none', FITTING_NONE],
13
+ ['stretch', FITTING_STRETCH],
14
+ ['shrink', FITTING_SHRINK],
15
+ ['both', FITTING_BOTH]
16
+ ]);
17
+
18
+ /**
19
+ * The LayoutGroupComponentElement interface provides properties and methods for manipulating
20
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-layoutgroup/ | `<pc-layoutgroup>`} elements.
21
+ * The LayoutGroupComponentElement interface also inherits the properties and methods of the
22
+ * {@link HTMLElement} interface.
23
+ *
24
+ * @category Components
25
+ */
26
+ class LayoutGroupComponentElement extends ComponentElement {
27
+ private _orientation: number = ORIENTATION_HORIZONTAL;
28
+
29
+ private _reverseX = false;
30
+
31
+ private _reverseY = false;
32
+
33
+ private _alignment = new Vec2(0, 1);
34
+
35
+ private _padding = new Vec4(0, 0, 0, 0);
36
+
37
+ private _spacing = new Vec2(0, 0);
38
+
39
+ private _widthFitting: number = FITTING_NONE;
40
+
41
+ private _heightFitting: number = FITTING_NONE;
42
+
43
+ private _wrap = false;
44
+
45
+ /** @ignore */
46
+ constructor() {
47
+ super('layoutgroup');
48
+ }
49
+
50
+ getInitialComponentData() {
51
+ return {
52
+ orientation: this._orientation,
53
+ reverseX: this._reverseX,
54
+ reverseY: this._reverseY,
55
+ alignment: this._alignment,
56
+ padding: this._padding,
57
+ spacing: this._spacing,
58
+ widthFitting: this._widthFitting,
59
+ heightFitting: this._heightFitting,
60
+ wrap: this._wrap
61
+ };
62
+ }
63
+
64
+ /**
65
+ * Gets the underlying PlayCanvas layout group component.
66
+ * @returns The layout group component.
67
+ */
68
+ get component(): LayoutGroupComponent | null {
69
+ return super.component as LayoutGroupComponent | null;
70
+ }
71
+
72
+ /**
73
+ * Sets the orientation of the layout group. Can be `horizontal` (0) or `vertical` (1).
74
+ * @param value - The orientation.
75
+ */
76
+ set orientation(value: number) {
77
+ this._orientation = value;
78
+ if (this.component) {
79
+ this.component.orientation = value;
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Gets the orientation of the layout group.
85
+ * @returns The orientation.
86
+ */
87
+ get orientation() {
88
+ return this._orientation;
89
+ }
90
+
91
+ /**
92
+ * Sets whether the order of children is reversed along the horizontal axis.
93
+ * @param value - Whether to reverse the horizontal order.
94
+ */
95
+ set reverseX(value: boolean) {
96
+ this._reverseX = value;
97
+ if (this.component) {
98
+ this.component.reverseX = value;
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Gets whether the order of children is reversed along the horizontal axis.
104
+ * @returns Whether the horizontal order is reversed.
105
+ */
106
+ get reverseX() {
107
+ return this._reverseX;
108
+ }
109
+
110
+ /**
111
+ * Sets whether the order of children is reversed along the vertical axis.
112
+ * @param value - Whether to reverse the vertical order.
113
+ */
114
+ set reverseY(value: boolean) {
115
+ this._reverseY = value;
116
+ if (this.component) {
117
+ this.component.reverseY = value;
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Gets whether the order of children is reversed along the vertical axis.
123
+ * @returns Whether the vertical order is reversed.
124
+ */
125
+ get reverseY() {
126
+ return this._reverseY;
127
+ }
128
+
129
+ /**
130
+ * Sets the horizontal and vertical alignment of the child elements (each component 0 to 1).
131
+ * @param value - The alignment.
132
+ */
133
+ set alignment(value: Vec2) {
134
+ this._alignment = value;
135
+ if (this.component) {
136
+ this.component.alignment = value;
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Gets the alignment of the child elements.
142
+ * @returns The alignment.
143
+ */
144
+ get alignment() {
145
+ return this._alignment;
146
+ }
147
+
148
+ /**
149
+ * Sets the padding around the layout group, as a Vec4 (left, bottom, right, top).
150
+ * @param value - The padding.
151
+ */
152
+ set padding(value: Vec4) {
153
+ this._padding = value;
154
+ if (this.component) {
155
+ this.component.padding = value;
156
+ }
157
+ }
158
+
159
+ /**
160
+ * Gets the padding around the layout group.
161
+ * @returns The padding.
162
+ */
163
+ get padding() {
164
+ return this._padding;
165
+ }
166
+
167
+ /**
168
+ * Sets the spacing between child elements, as a Vec2 (x, y).
169
+ * @param value - The spacing.
170
+ */
171
+ set spacing(value: Vec2) {
172
+ this._spacing = value;
173
+ if (this.component) {
174
+ this.component.spacing = value;
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Gets the spacing between child elements.
180
+ * @returns The spacing.
181
+ */
182
+ get spacing() {
183
+ return this._spacing;
184
+ }
185
+
186
+ /**
187
+ * Sets the fitting mode along the horizontal axis. Can be `none` (0), `stretch` (1), `shrink`
188
+ * (2) or `both` (3).
189
+ * @param value - The width fitting mode.
190
+ */
191
+ set widthFitting(value: number) {
192
+ this._widthFitting = value;
193
+ if (this.component) {
194
+ this.component.widthFitting = value;
195
+ }
196
+ }
197
+
198
+ /**
199
+ * Gets the fitting mode along the horizontal axis.
200
+ * @returns The width fitting mode.
201
+ */
202
+ get widthFitting() {
203
+ return this._widthFitting;
204
+ }
205
+
206
+ /**
207
+ * Sets the fitting mode along the vertical axis. Can be `none` (0), `stretch` (1), `shrink` (2)
208
+ * or `both` (3).
209
+ * @param value - The height fitting mode.
210
+ */
211
+ set heightFitting(value: number) {
212
+ this._heightFitting = value;
213
+ if (this.component) {
214
+ this.component.heightFitting = value;
215
+ }
216
+ }
217
+
218
+ /**
219
+ * Gets the fitting mode along the vertical axis.
220
+ * @returns The height fitting mode.
221
+ */
222
+ get heightFitting() {
223
+ return this._heightFitting;
224
+ }
225
+
226
+ /**
227
+ * Sets whether children wrap onto a new line/column when they overflow the group.
228
+ * @param value - Whether to wrap children.
229
+ */
230
+ set wrap(value: boolean) {
231
+ this._wrap = value;
232
+ if (this.component) {
233
+ this.component.wrap = value;
234
+ }
235
+ }
236
+
237
+ /**
238
+ * Gets whether children wrap onto a new line/column when they overflow the group.
239
+ * @returns Whether children wrap.
240
+ */
241
+ get wrap() {
242
+ return this._wrap;
243
+ }
244
+
245
+ static get observedAttributes() {
246
+ return [
247
+ ...super.observedAttributes,
248
+ 'orientation',
249
+ 'reverse-x',
250
+ 'reverse-y',
251
+ 'alignment',
252
+ 'padding',
253
+ 'spacing',
254
+ 'width-fitting',
255
+ 'height-fitting',
256
+ 'wrap'
257
+ ];
258
+ }
259
+
260
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
261
+ super.attributeChangedCallback(name, _oldValue, newValue);
262
+
263
+ switch (name) {
264
+ case 'orientation':
265
+ this.orientation = parseEnum(newValue, orientations, ORIENTATION_HORIZONTAL);
266
+ break;
267
+ case 'reverse-x':
268
+ this.reverseX = newValue !== 'false';
269
+ break;
270
+ case 'reverse-y':
271
+ this.reverseY = newValue !== 'false';
272
+ break;
273
+ case 'alignment':
274
+ this.alignment = parseVec2(newValue);
275
+ break;
276
+ case 'padding':
277
+ this.padding = parseVec4(newValue);
278
+ break;
279
+ case 'spacing':
280
+ this.spacing = parseVec2(newValue);
281
+ break;
282
+ case 'width-fitting':
283
+ this.widthFitting = parseEnum(newValue, fittings, FITTING_NONE);
284
+ break;
285
+ case 'height-fitting':
286
+ this.heightFitting = parseEnum(newValue, fittings, FITTING_NONE);
287
+ break;
288
+ case 'wrap':
289
+ this.wrap = newValue !== 'false';
290
+ break;
291
+ }
292
+ }
293
+ }
294
+
295
+ customElements.define('pc-layoutgroup', LayoutGroupComponentElement);
296
+
297
+ export { LayoutGroupComponentElement };
@@ -0,0 +1,166 @@
1
+ import { ORIENTATION_HORIZONTAL, ORIENTATION_VERTICAL, ScrollbarComponent } from 'playcanvas';
2
+
3
+ import { ComponentElement } from './component';
4
+ import { getEntity, parseEnum } from '../utils';
5
+
6
+ const orientations = new Map<string, number>([
7
+ ['horizontal', ORIENTATION_HORIZONTAL],
8
+ ['vertical', ORIENTATION_VERTICAL]
9
+ ]);
10
+
11
+ /**
12
+ * The ScrollbarComponentElement interface provides properties and methods for manipulating
13
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-scrollbar/ | `<pc-scrollbar>`} elements.
14
+ * The ScrollbarComponentElement interface also inherits the properties and methods of the
15
+ * {@link HTMLElement} interface.
16
+ *
17
+ * @category Components
18
+ */
19
+ class ScrollbarComponentElement extends ComponentElement {
20
+ private _orientation: number = ORIENTATION_HORIZONTAL;
21
+
22
+ private _value = 0;
23
+
24
+ private _handleSize = 0.5;
25
+
26
+ private _handle = '';
27
+
28
+ /** @ignore */
29
+ constructor() {
30
+ super('scrollbar');
31
+ }
32
+
33
+ getInitialComponentData() {
34
+ const data: Record<string, any> = {
35
+ orientation: this._orientation,
36
+ value: this._value,
37
+ handleSize: this._handleSize
38
+ };
39
+
40
+ const handle = getEntity(this._handle);
41
+ if (handle) {
42
+ data.handleEntity = handle;
43
+ }
44
+
45
+ return data;
46
+ }
47
+
48
+ /**
49
+ * Gets the underlying PlayCanvas scrollbar component.
50
+ * @returns The scrollbar component.
51
+ */
52
+ get component(): ScrollbarComponent | null {
53
+ return super.component as ScrollbarComponent | null;
54
+ }
55
+
56
+ /**
57
+ * Sets the orientation of the scrollbar. Can be `horizontal` (0) or `vertical` (1).
58
+ * @param value - The orientation.
59
+ */
60
+ set orientation(value: number) {
61
+ this._orientation = value;
62
+ if (this.component) {
63
+ this.component.orientation = value;
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Gets the orientation of the scrollbar.
69
+ * @returns The orientation.
70
+ */
71
+ get orientation() {
72
+ return this._orientation;
73
+ }
74
+
75
+ /**
76
+ * Sets the current position value of the scrollbar, in the range 0 to 1.
77
+ * @param value - The scrollbar value.
78
+ */
79
+ set value(value: number) {
80
+ this._value = value;
81
+ if (this.component) {
82
+ this.component.value = value;
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Gets the current position value of the scrollbar.
88
+ * @returns The scrollbar value.
89
+ */
90
+ get value() {
91
+ return this._value;
92
+ }
93
+
94
+ /**
95
+ * Sets the size of the handle relative to the size of the track, in the range 0 to 1.
96
+ * @param value - The handle size.
97
+ */
98
+ set handleSize(value: number) {
99
+ this._handleSize = value;
100
+ if (this.component) {
101
+ this.component.handleSize = value;
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Gets the size of the handle relative to the size of the track.
107
+ * @returns The handle size.
108
+ */
109
+ get handleSize() {
110
+ return this._handleSize;
111
+ }
112
+
113
+ /**
114
+ * Sets the reference (CSS selector, element id or entity name) to the `<pc-entity>` used as the
115
+ * scrollbar handle.
116
+ * @param value - The handle entity reference.
117
+ */
118
+ set handle(value: string) {
119
+ this._handle = value;
120
+ const entity = getEntity(value);
121
+ if (this.component && entity) {
122
+ this.component.handleEntity = entity;
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Gets the reference to the `<pc-entity>` used as the scrollbar handle.
128
+ * @returns The handle entity reference.
129
+ */
130
+ get handle() {
131
+ return this._handle;
132
+ }
133
+
134
+ static get observedAttributes() {
135
+ return [
136
+ ...super.observedAttributes,
137
+ 'orientation',
138
+ 'value',
139
+ 'handle-size',
140
+ 'handle'
141
+ ];
142
+ }
143
+
144
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
145
+ super.attributeChangedCallback(name, _oldValue, newValue);
146
+
147
+ switch (name) {
148
+ case 'orientation':
149
+ this.orientation = parseEnum(newValue, orientations, ORIENTATION_HORIZONTAL);
150
+ break;
151
+ case 'value':
152
+ this.value = Number(newValue);
153
+ break;
154
+ case 'handle-size':
155
+ this.handleSize = Number(newValue);
156
+ break;
157
+ case 'handle':
158
+ this.handle = newValue;
159
+ break;
160
+ }
161
+ }
162
+ }
163
+
164
+ customElements.define('pc-scrollbar', ScrollbarComponentElement);
165
+
166
+ export { ScrollbarComponentElement };