@playcanvas/web-components 0.6.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.
package/dist/asset.d.ts CHANGED
@@ -13,6 +13,14 @@ declare class AssetElement extends HTMLElement {
13
13
  asset: Asset | null;
14
14
  disconnectedCallback(): void;
15
15
  createAsset(): void;
16
+ /**
17
+ * Builds the `data` object for the asset from an optional inline `data` attribute (JSON) and,
18
+ * for sprites, from the convenience attributes (`atlas`, `frame-keys`, `pixels-per-unit`,
19
+ * `render-mode`). Returns `undefined` when there is no data to apply.
20
+ * @param type - The resolved asset type.
21
+ * @returns The asset data, or `undefined`.
22
+ */
23
+ private _buildData;
16
24
  destroyAsset(): void;
17
25
  /**
18
26
  * Sets whether the asset should be loaded lazily.
@@ -0,0 +1,184 @@
1
+ import { ButtonComponent, Color, Vec4 } from 'playcanvas';
2
+ import { ComponentElement } from './component';
3
+ /**
4
+ * The ButtonComponentElement interface provides properties and methods for manipulating
5
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-button/ | `<pc-button>`} elements.
6
+ * The ButtonComponentElement interface also inherits the properties and methods of the
7
+ * {@link HTMLElement} interface.
8
+ *
9
+ * @category Components
10
+ */
11
+ declare class ButtonComponentElement extends ComponentElement {
12
+ private _active;
13
+ private _image;
14
+ private _hitPadding;
15
+ private _transitionMode;
16
+ private _hoverTint;
17
+ private _pressedTint;
18
+ private _inactiveTint;
19
+ private _fadeDuration;
20
+ private _hoverSpriteAsset;
21
+ private _hoverSpriteFrame;
22
+ private _pressedSpriteAsset;
23
+ private _pressedSpriteFrame;
24
+ private _inactiveSpriteAsset;
25
+ private _inactiveSpriteFrame;
26
+ /** @ignore */
27
+ constructor();
28
+ getInitialComponentData(): Record<string, any>;
29
+ /**
30
+ * Gets the underlying PlayCanvas button component.
31
+ * @returns The button component.
32
+ */
33
+ get component(): ButtonComponent | null;
34
+ /**
35
+ * Sets whether the button is active and responds to input.
36
+ * @param value - Whether the button is active.
37
+ */
38
+ set active(value: boolean);
39
+ /**
40
+ * Gets whether the button is active.
41
+ * @returns Whether the button is active.
42
+ */
43
+ get active(): boolean;
44
+ /**
45
+ * Sets the reference (CSS selector, element id or entity name) to the `<pc-entity>` whose image
46
+ * element is used for visual transitions. Defaults to the button's own entity.
47
+ * @param value - The image entity reference.
48
+ */
49
+ set image(value: string);
50
+ /**
51
+ * Gets the reference to the `<pc-entity>` whose image element is used for visual transitions.
52
+ * @returns The image entity reference.
53
+ */
54
+ get image(): string;
55
+ /**
56
+ * Sets the padding used to expand the button's hit area, as a Vec4 (left, bottom, right, top).
57
+ * @param value - The hit padding.
58
+ */
59
+ set hitPadding(value: Vec4);
60
+ /**
61
+ * Gets the padding used to expand the button's hit area.
62
+ * @returns The hit padding.
63
+ */
64
+ get hitPadding(): Vec4;
65
+ /**
66
+ * Sets how the button reacts to being hovered/pressed. Can be `tint` (0) or `sprite` (1).
67
+ * @param value - The transition mode.
68
+ */
69
+ set transitionMode(value: number);
70
+ /**
71
+ * Gets how the button reacts to being hovered/pressed.
72
+ * @returns The transition mode.
73
+ */
74
+ get transitionMode(): number;
75
+ /**
76
+ * Sets the tint color applied to the image entity when the button is hovered (tint transition
77
+ * mode).
78
+ * @param value - The hover tint.
79
+ */
80
+ set hoverTint(value: Color);
81
+ /**
82
+ * Gets the hover tint color.
83
+ * @returns The hover tint.
84
+ */
85
+ get hoverTint(): Color;
86
+ /**
87
+ * Sets the tint color applied to the image entity when the button is pressed (tint transition
88
+ * mode).
89
+ * @param value - The pressed tint.
90
+ */
91
+ set pressedTint(value: Color);
92
+ /**
93
+ * Gets the pressed tint color.
94
+ * @returns The pressed tint.
95
+ */
96
+ get pressedTint(): Color;
97
+ /**
98
+ * Sets the tint color applied to the image entity when the button is inactive (tint transition
99
+ * mode).
100
+ * @param value - The inactive tint.
101
+ */
102
+ set inactiveTint(value: Color);
103
+ /**
104
+ * Gets the inactive tint color.
105
+ * @returns The inactive tint.
106
+ */
107
+ get inactiveTint(): Color;
108
+ /**
109
+ * Sets the duration (in milliseconds) over which tint transitions are applied.
110
+ * @param value - The fade duration.
111
+ */
112
+ set fadeDuration(value: number);
113
+ /**
114
+ * Gets the duration over which tint transitions are applied.
115
+ * @returns The fade duration.
116
+ */
117
+ get fadeDuration(): number;
118
+ /**
119
+ * Sets the id of the `pc-asset` sprite shown when the button is hovered (sprite transition
120
+ * mode).
121
+ * @param value - The hover sprite asset id.
122
+ */
123
+ set hoverSpriteAsset(value: string);
124
+ /**
125
+ * Gets the id of the `pc-asset` sprite shown when the button is hovered.
126
+ * @returns The hover sprite asset id.
127
+ */
128
+ get hoverSpriteAsset(): string;
129
+ /**
130
+ * Sets the frame of the hover sprite to show.
131
+ * @param value - The hover sprite frame.
132
+ */
133
+ set hoverSpriteFrame(value: number);
134
+ /**
135
+ * Gets the frame of the hover sprite to show.
136
+ * @returns The hover sprite frame.
137
+ */
138
+ get hoverSpriteFrame(): number;
139
+ /**
140
+ * Sets the id of the `pc-asset` sprite shown when the button is pressed (sprite transition
141
+ * mode).
142
+ * @param value - The pressed sprite asset id.
143
+ */
144
+ set pressedSpriteAsset(value: string);
145
+ /**
146
+ * Gets the id of the `pc-asset` sprite shown when the button is pressed.
147
+ * @returns The pressed sprite asset id.
148
+ */
149
+ get pressedSpriteAsset(): string;
150
+ /**
151
+ * Sets the frame of the pressed sprite to show.
152
+ * @param value - The pressed sprite frame.
153
+ */
154
+ set pressedSpriteFrame(value: number);
155
+ /**
156
+ * Gets the frame of the pressed sprite to show.
157
+ * @returns The pressed sprite frame.
158
+ */
159
+ get pressedSpriteFrame(): number;
160
+ /**
161
+ * Sets the id of the `pc-asset` sprite shown when the button is inactive (sprite transition
162
+ * mode).
163
+ * @param value - The inactive sprite asset id.
164
+ */
165
+ set inactiveSpriteAsset(value: string);
166
+ /**
167
+ * Gets the id of the `pc-asset` sprite shown when the button is inactive.
168
+ * @returns The inactive sprite asset id.
169
+ */
170
+ get inactiveSpriteAsset(): string;
171
+ /**
172
+ * Sets the frame of the inactive sprite to show.
173
+ * @param value - The inactive sprite frame.
174
+ */
175
+ set inactiveSpriteFrame(value: number);
176
+ /**
177
+ * Gets the frame of the inactive sprite to show.
178
+ * @returns The inactive sprite frame.
179
+ */
180
+ get inactiveSpriteFrame(): number;
181
+ static get observedAttributes(): string[];
182
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
183
+ }
184
+ export { ButtonComponentElement };
@@ -47,7 +47,7 @@ declare class CameraComponentElement extends ComponentElement {
47
47
  priority: number;
48
48
  rect: Vec4;
49
49
  scissorRect: Vec4;
50
- toneMapping: 0 | 2 | 1 | 3 | 4 | 5 | 6 | undefined;
50
+ toneMapping: 0 | 3 | 1 | 2 | 4 | 5 | 6 | undefined;
51
51
  };
52
52
  get xrAvailable(): boolean | null | undefined;
53
53
  /**
@@ -12,32 +12,33 @@ declare class ElementComponentElement extends ComponentElement {
12
12
  private _anchor;
13
13
  private _asset;
14
14
  private _autoWidth;
15
+ private _autoHeight;
16
+ private _autoFitWidth;
17
+ private _autoFitHeight;
15
18
  private _color;
16
19
  private _enableMarkup;
17
20
  private _fontSize;
21
+ private _maxFontSize;
22
+ private _minFontSize;
23
+ private _height;
18
24
  private _lineHeight;
25
+ private _margin;
26
+ private _mask;
27
+ private _opacity;
19
28
  private _pivot;
29
+ private _pixelsPerUnit;
30
+ private _spriteAsset;
31
+ private _spriteFrame;
20
32
  private _text;
33
+ private _textureAsset;
21
34
  private _type;
35
+ private _useInput;
22
36
  private _width;
23
37
  private _wrapLines;
24
38
  /** @ignore */
25
39
  constructor();
26
40
  initComponent(): void;
27
- getInitialComponentData(): {
28
- anchor: Vec4;
29
- autoWidth: boolean;
30
- color: Color;
31
- enableMarkup: boolean;
32
- fontAsset: number;
33
- fontSize: number;
34
- lineHeight: number;
35
- pivot: Vec2;
36
- type: "text" | "image" | "group";
37
- text: string;
38
- width: number;
39
- wrapLines: boolean;
40
- };
41
+ getInitialComponentData(): Record<string, any>;
41
42
  /**
42
43
  * Gets the underlying PlayCanvas element component.
43
44
  * @returns The element component.
@@ -54,7 +55,7 @@ declare class ElementComponentElement extends ComponentElement {
54
55
  */
55
56
  get anchor(): Vec4;
56
57
  /**
57
- * Sets the id of the `pc-asset` to use for the font.
58
+ * Sets the id of the `pc-asset` to use for the font (text elements).
58
59
  * @param value - The asset ID.
59
60
  */
60
61
  set asset(value: string);
@@ -64,7 +65,8 @@ declare class ElementComponentElement extends ComponentElement {
64
65
  */
65
66
  get asset(): string;
66
67
  /**
67
- * Sets whether the element component should automatically adjust its width.
68
+ * Sets whether the element component should automatically adjust its width to the text content
69
+ * (text elements only).
68
70
  * @param value - Whether to automatically adjust the width.
69
71
  */
70
72
  set autoWidth(value: boolean);
@@ -73,6 +75,17 @@ declare class ElementComponentElement extends ComponentElement {
73
75
  * @returns Whether to automatically adjust the width.
74
76
  */
75
77
  get autoWidth(): boolean;
78
+ /**
79
+ * Sets whether the element component should automatically adjust its height to the text content
80
+ * (text elements only).
81
+ * @param value - Whether to automatically adjust the height.
82
+ */
83
+ set autoHeight(value: boolean);
84
+ /**
85
+ * Gets whether the element component should automatically adjust its height.
86
+ * @returns Whether to automatically adjust the height.
87
+ */
88
+ get autoHeight(): boolean;
76
89
  /**
77
90
  * Sets the color of the element component.
78
91
  * @param value - The color.
@@ -103,6 +116,16 @@ declare class ElementComponentElement extends ComponentElement {
103
116
  * @returns The font size.
104
117
  */
105
118
  get fontSize(): number;
119
+ /**
120
+ * Sets the height of the element component.
121
+ * @param value - The height.
122
+ */
123
+ set height(value: number);
124
+ /**
125
+ * Gets the height of the element component.
126
+ * @returns The height.
127
+ */
128
+ get height(): number;
106
129
  /**
107
130
  * Sets the line height of the element component.
108
131
  * @param value - The line height.
@@ -113,6 +136,37 @@ declare class ElementComponentElement extends ComponentElement {
113
136
  * @returns The line height.
114
137
  */
115
138
  get lineHeight(): number;
139
+ /**
140
+ * Sets the margin of the element component (used to inset the element from stretched anchors).
141
+ * @param value - The margin as a Vec4 (left, bottom, right, top).
142
+ */
143
+ set margin(value: Vec4 | null);
144
+ /**
145
+ * Gets the margin of the element component.
146
+ * @returns The margin.
147
+ */
148
+ get margin(): Vec4 | null;
149
+ /**
150
+ * Sets whether the element component is a mask, clipping its descendants to its bounds (image
151
+ * elements only).
152
+ * @param value - Whether the element is a mask.
153
+ */
154
+ set mask(value: boolean);
155
+ /**
156
+ * Gets whether the element component is a mask.
157
+ * @returns Whether the element is a mask.
158
+ */
159
+ get mask(): boolean;
160
+ /**
161
+ * Sets the opacity of the element component.
162
+ * @param value - The opacity (0 to 1).
163
+ */
164
+ set opacity(value: number);
165
+ /**
166
+ * Gets the opacity of the element component.
167
+ * @returns The opacity.
168
+ */
169
+ get opacity(): number;
116
170
  /**
117
171
  * Sets the pivot of the element component.
118
172
  * @param value - The pivot.
@@ -123,6 +177,36 @@ declare class ElementComponentElement extends ComponentElement {
123
177
  * @returns The pivot.
124
178
  */
125
179
  get pivot(): Vec2;
180
+ /**
181
+ * Sets the number of pixels per unit to use when rendering a sprite (image elements only).
182
+ * @param value - The pixels per unit.
183
+ */
184
+ set pixelsPerUnit(value: number | null);
185
+ /**
186
+ * Gets the number of pixels per unit used when rendering a sprite.
187
+ * @returns The pixels per unit.
188
+ */
189
+ get pixelsPerUnit(): number | null;
190
+ /**
191
+ * Sets the id of the `pc-asset` to use for the sprite (image elements only).
192
+ * @param value - The sprite asset ID.
193
+ */
194
+ set spriteAsset(value: string);
195
+ /**
196
+ * Gets the id of the `pc-asset` to use for the sprite.
197
+ * @returns The sprite asset ID.
198
+ */
199
+ get spriteAsset(): string;
200
+ /**
201
+ * Sets the frame of the sprite to render (image elements only).
202
+ * @param value - The sprite frame index.
203
+ */
204
+ set spriteFrame(value: number);
205
+ /**
206
+ * Gets the frame of the sprite to render.
207
+ * @returns The sprite frame index.
208
+ */
209
+ get spriteFrame(): number;
126
210
  /**
127
211
  * Sets the text of the element component.
128
212
  * @param value - The text.
@@ -133,6 +217,16 @@ declare class ElementComponentElement extends ComponentElement {
133
217
  * @returns The text.
134
218
  */
135
219
  get text(): string;
220
+ /**
221
+ * Sets the id of the `pc-asset` to use for the texture (image elements only).
222
+ * @param value - The texture asset ID.
223
+ */
224
+ set textureAsset(value: string);
225
+ /**
226
+ * Gets the id of the `pc-asset` to use for the texture.
227
+ * @returns The texture asset ID.
228
+ */
229
+ get textureAsset(): string;
136
230
  /**
137
231
  * Sets the type of the element component.
138
232
  * @param value - The type.
@@ -143,6 +237,16 @@ declare class ElementComponentElement extends ComponentElement {
143
237
  * @returns The type.
144
238
  */
145
239
  get type(): 'group' | 'image' | 'text';
240
+ /**
241
+ * Sets whether the element component accepts input events (required for buttons and scrolling).
242
+ * @param value - Whether the element accepts input.
243
+ */
244
+ set useInput(value: boolean);
245
+ /**
246
+ * Gets whether the element component accepts input events.
247
+ * @returns Whether the element accepts input.
248
+ */
249
+ get useInput(): boolean;
146
250
  /**
147
251
  * Sets the width of the element component.
148
252
  * @param value - The width.
@@ -163,6 +267,48 @@ declare class ElementComponentElement extends ComponentElement {
163
267
  * @returns Whether to wrap lines.
164
268
  */
165
269
  get wrapLines(): boolean;
270
+ /**
271
+ * Sets whether a text element should automatically reduce its font size (down to `min-font-size`)
272
+ * so the text fits within the element's width. Requires `auto-width` to be `false`.
273
+ * @param value - Whether to auto-fit the width.
274
+ */
275
+ set autoFitWidth(value: boolean);
276
+ /**
277
+ * Gets whether a text element automatically reduces its font size to fit its width.
278
+ * @returns Whether the width is auto-fit.
279
+ */
280
+ get autoFitWidth(): boolean;
281
+ /**
282
+ * Sets whether a text element should automatically reduce its font size (down to `min-font-size`)
283
+ * so the text fits within the element's height. Requires `auto-height` to be `false`.
284
+ * @param value - Whether to auto-fit the height.
285
+ */
286
+ set autoFitHeight(value: boolean);
287
+ /**
288
+ * Gets whether a text element automatically reduces its font size to fit its height.
289
+ * @returns Whether the height is auto-fit.
290
+ */
291
+ get autoFitHeight(): boolean;
292
+ /**
293
+ * Sets the smallest font size a text element may use when auto-fitting.
294
+ * @param value - The minimum font size.
295
+ */
296
+ set minFontSize(value: number);
297
+ /**
298
+ * Gets the smallest font size a text element may use when auto-fitting.
299
+ * @returns The minimum font size.
300
+ */
301
+ get minFontSize(): number;
302
+ /**
303
+ * Sets the largest font size a text element may use when auto-fitting.
304
+ * @param value - The maximum font size.
305
+ */
306
+ set maxFontSize(value: number);
307
+ /**
308
+ * Gets the largest font size a text element may use when auto-fitting.
309
+ * @returns The maximum font size.
310
+ */
311
+ get maxFontSize(): number;
166
312
  static get observedAttributes(): string[];
167
313
  attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
168
314
  }
@@ -0,0 +1,110 @@
1
+ import { LayoutChildComponent } from 'playcanvas';
2
+ import { ComponentElement } from './component';
3
+ /**
4
+ * The LayoutChildComponentElement interface provides properties and methods for manipulating
5
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-layoutchild/ | `<pc-layoutchild>`} elements.
6
+ * The LayoutChildComponentElement interface also inherits the properties and methods of the
7
+ * {@link HTMLElement} interface.
8
+ *
9
+ * @category Components
10
+ */
11
+ declare class LayoutChildComponentElement extends ComponentElement {
12
+ private _minWidth;
13
+ private _minHeight;
14
+ private _maxWidth;
15
+ private _maxHeight;
16
+ private _fitWidthProportion;
17
+ private _fitHeightProportion;
18
+ private _excludeFromLayout;
19
+ /** @ignore */
20
+ constructor();
21
+ getInitialComponentData(): {
22
+ minWidth: number;
23
+ minHeight: number;
24
+ maxWidth: number | null;
25
+ maxHeight: number | null;
26
+ fitWidthProportion: number;
27
+ fitHeightProportion: number;
28
+ excludeFromLayout: boolean;
29
+ };
30
+ /**
31
+ * Gets the underlying PlayCanvas layout child component.
32
+ * @returns The layout child component.
33
+ */
34
+ get component(): LayoutChildComponent | null;
35
+ /**
36
+ * Sets the minimum width the element should be laid out with.
37
+ * @param value - The minimum width.
38
+ */
39
+ set minWidth(value: number);
40
+ /**
41
+ * Gets the minimum width the element should be laid out with.
42
+ * @returns The minimum width.
43
+ */
44
+ get minWidth(): number;
45
+ /**
46
+ * Sets the minimum height the element should be laid out with.
47
+ * @param value - The minimum height.
48
+ */
49
+ set minHeight(value: number);
50
+ /**
51
+ * Gets the minimum height the element should be laid out with.
52
+ * @returns The minimum height.
53
+ */
54
+ get minHeight(): number;
55
+ /**
56
+ * Sets the maximum width the element should be laid out with (or `null` for no limit).
57
+ * @param value - The maximum width.
58
+ */
59
+ set maxWidth(value: number | null);
60
+ /**
61
+ * Gets the maximum width the element should be laid out with.
62
+ * @returns The maximum width.
63
+ */
64
+ get maxWidth(): number | null;
65
+ /**
66
+ * Sets the maximum height the element should be laid out with (or `null` for no limit).
67
+ * @param value - The maximum height.
68
+ */
69
+ set maxHeight(value: number | null);
70
+ /**
71
+ * Gets the maximum height the element should be laid out with.
72
+ * @returns The maximum height.
73
+ */
74
+ get maxHeight(): number | null;
75
+ /**
76
+ * Sets the proportion of the container's spare width this element should take (when the layout
77
+ * group's `width-fitting` is set to stretch or shrink).
78
+ * @param value - The fit width proportion.
79
+ */
80
+ set fitWidthProportion(value: number);
81
+ /**
82
+ * Gets the proportion of the container's spare width this element should take.
83
+ * @returns The fit width proportion.
84
+ */
85
+ get fitWidthProportion(): number;
86
+ /**
87
+ * Sets the proportion of the container's spare height this element should take (when the layout
88
+ * group's `height-fitting` is set to stretch or shrink).
89
+ * @param value - The fit height proportion.
90
+ */
91
+ set fitHeightProportion(value: number);
92
+ /**
93
+ * Gets the proportion of the container's spare height this element should take.
94
+ * @returns The fit height proportion.
95
+ */
96
+ get fitHeightProportion(): number;
97
+ /**
98
+ * Sets whether the element should be excluded from the layout (and thus not take up space).
99
+ * @param value - Whether to exclude the element from layout.
100
+ */
101
+ set excludeFromLayout(value: boolean);
102
+ /**
103
+ * Gets whether the element is excluded from the layout.
104
+ * @returns Whether the element is excluded from layout.
105
+ */
106
+ get excludeFromLayout(): boolean;
107
+ static get observedAttributes(): string[];
108
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
109
+ }
110
+ export { LayoutChildComponentElement };