@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 +8 -0
- package/dist/components/button-component.d.ts +184 -0
- package/dist/components/camera-component.d.ts +1 -1
- package/dist/components/element-component.d.ts +162 -16
- package/dist/components/layoutchild-component.d.ts +110 -0
- package/dist/components/layoutgroup-component.d.ts +134 -0
- package/dist/components/light-component.d.ts +1 -1
- package/dist/components/scrollbar-component.d.ts +68 -0
- package/dist/components/scrollview-component.d.ts +173 -0
- package/dist/entity.d.ts +4 -0
- package/dist/index.d.ts +6 -1
- package/dist/pwc.cjs +1905 -60
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +1905 -60
- package/dist/pwc.js.map +1 -1
- package/dist/pwc.min.js +1 -1
- package/dist/pwc.min.js.map +1 -1
- package/dist/pwc.mjs +1902 -62
- package/dist/pwc.mjs.map +1 -1
- package/dist/utils.d.ts +20 -1
- package/package.json +6 -6
- package/src/app.ts +5 -0
- package/src/asset.ts +75 -2
- package/src/components/button-component.ts +450 -0
- package/src/components/element-component.ts +415 -5
- package/src/components/layoutchild-component.ts +232 -0
- package/src/components/layoutgroup-component.ts +297 -0
- package/src/components/scrollbar-component.ts +166 -0
- package/src/components/scrollview-component.ts +427 -0
- package/src/entity.ts +15 -1
- package/src/index.ts +10 -0
- package/src/utils.ts +49 -1
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color, Quat, Vec2, Vec3, Vec4 } from 'playcanvas';
|
|
1
|
+
import { Color, Entity, Quat, Vec2, Vec3, Vec4 } from 'playcanvas';
|
|
2
2
|
/**
|
|
3
3
|
* Parse a color string into a Color object. String can be in the format of '#rgb', '#rgba',
|
|
4
4
|
* '#rrggbb', '#rrggbbaa', or a string of 3 or 4 comma-delimited numbers.
|
|
@@ -35,3 +35,22 @@ export declare const parseVec3: (value: string) => Vec3;
|
|
|
35
35
|
* @returns The parsed Vec4 object.
|
|
36
36
|
*/
|
|
37
37
|
export declare const parseVec4: (value: string) => Vec4;
|
|
38
|
+
/**
|
|
39
|
+
* Resolves an enum value supplied as either a named string (looked up in `map`) or a numeric
|
|
40
|
+
* string. Falls back to `defaultValue` when the value is neither a known name nor a finite number.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The attribute value to parse.
|
|
43
|
+
* @param map - A map of named values to their numeric enum equivalents.
|
|
44
|
+
* @param defaultValue - The value to return when parsing fails.
|
|
45
|
+
* @returns The resolved numeric enum value.
|
|
46
|
+
*/
|
|
47
|
+
export declare const parseEnum: (value: string, map: Map<string, number>, defaultValue: number) => number;
|
|
48
|
+
/**
|
|
49
|
+
* Resolves a reference string to the {@link Entity} backing a `<pc-entity>` element. The reference
|
|
50
|
+
* can be a CSS selector (e.g. `#my-id`, `pc-entity[name="Foo"]`), a bare element id, or a bare
|
|
51
|
+
* entity name. Returns `null` if no matching element (or backing entity) is found.
|
|
52
|
+
*
|
|
53
|
+
* @param ref - The reference string to resolve.
|
|
54
|
+
* @returns The resolved entity, or `null`.
|
|
55
|
+
*/
|
|
56
|
+
export declare const getEntity: (ref: string) => Entity | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playcanvas/web-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"author": "PlayCanvas <support@playcanvas.com>",
|
|
5
5
|
"homepage": "https://playcanvas.com",
|
|
6
6
|
"description": "Web Components for the PlayCanvas Engine",
|
|
@@ -55,18 +55,18 @@
|
|
|
55
55
|
"@rollup/plugin-terser": "1.0.0",
|
|
56
56
|
"@rollup/plugin-typescript": "12.3.0",
|
|
57
57
|
"@tweenjs/tween.js": "25.0.0",
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
59
|
-
"@typescript-eslint/parser": "8.
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "8.62.0",
|
|
59
|
+
"@typescript-eslint/parser": "8.62.0",
|
|
60
60
|
"concurrently": "10.0.3",
|
|
61
61
|
"earcut": "3.0.2",
|
|
62
62
|
"eslint": "9.39.4",
|
|
63
63
|
"eslint-import-resolver-typescript": "4.4.5",
|
|
64
|
-
"globals": "17.
|
|
65
|
-
"mediabunny": "1.
|
|
64
|
+
"globals": "17.7.0",
|
|
65
|
+
"mediabunny": "1.49.0",
|
|
66
66
|
"opentype.js": "2.0.0",
|
|
67
67
|
"playcanvas": "2.19.7",
|
|
68
68
|
"publint": "0.3.21",
|
|
69
|
-
"rollup": "4.62.
|
|
69
|
+
"rollup": "4.62.2",
|
|
70
70
|
"serve": "14.2.6",
|
|
71
71
|
"tslib": "2.8.1",
|
|
72
72
|
"typedoc": "0.28.19",
|
package/src/app.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
AppOptions,
|
|
4
4
|
CameraComponent,
|
|
5
5
|
createGraphicsDevice,
|
|
6
|
+
ElementInput,
|
|
6
7
|
FILLMODE_FILL_WINDOW,
|
|
7
8
|
GraphNode,
|
|
8
9
|
Keyboard,
|
|
@@ -165,6 +166,10 @@ class AppElement extends AsyncElement {
|
|
|
165
166
|
createOptions.graphicsDevice = device;
|
|
166
167
|
createOptions.keyboard = new Keyboard(window);
|
|
167
168
|
createOptions.mouse = new Mouse(this._canvas);
|
|
169
|
+
createOptions.elementInput = new ElementInput(this._canvas, {
|
|
170
|
+
useMouse: true,
|
|
171
|
+
useTouch: true
|
|
172
|
+
});
|
|
168
173
|
createOptions.componentSystems = [
|
|
169
174
|
AnimComponentSystem,
|
|
170
175
|
AnimationComponentSystem,
|
package/src/asset.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { Asset } from 'playcanvas';
|
|
1
|
+
import { Asset, SPRITE_RENDERMODE_SIMPLE, SPRITE_RENDERMODE_SLICED, SPRITE_RENDERMODE_TILED } from 'playcanvas';
|
|
2
2
|
|
|
3
|
+
import { parseEnum } from './utils';
|
|
3
4
|
import { MeshoptDecoder } from '../lib/meshopt_decoder.module.js';
|
|
4
5
|
|
|
6
|
+
const renderModes = new Map<string, number>([
|
|
7
|
+
['simple', SPRITE_RENDERMODE_SIMPLE],
|
|
8
|
+
['sliced', SPRITE_RENDERMODE_SLICED],
|
|
9
|
+
['tiled', SPRITE_RENDERMODE_TILED]
|
|
10
|
+
]);
|
|
11
|
+
|
|
5
12
|
const extToType = new Map([
|
|
6
13
|
['bin', 'binary'],
|
|
7
14
|
['css', 'css'],
|
|
@@ -96,6 +103,10 @@ class AssetElement extends HTMLElement {
|
|
|
96
103
|
return;
|
|
97
104
|
}
|
|
98
105
|
|
|
106
|
+
// Optional inline asset data, used by data-driven assets such as texture atlases (frame
|
|
107
|
+
// definitions) and sprites (atlas reference, frame keys, etc.).
|
|
108
|
+
const data = this._buildData(type);
|
|
109
|
+
|
|
99
110
|
if (type === 'container') {
|
|
100
111
|
this.asset = new Asset(id, type, { url: src }, undefined, {
|
|
101
112
|
// @ts-ignore TODO no definition in pc
|
|
@@ -103,14 +114,76 @@ class AssetElement extends HTMLElement {
|
|
|
103
114
|
processAsync: processBufferView.bind(this)
|
|
104
115
|
}
|
|
105
116
|
});
|
|
117
|
+
} else if (type === 'sprite') {
|
|
118
|
+
// Sprite assets have no file of their own; their data references a texture atlas asset.
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
this.asset = new Asset(id, type, null, data);
|
|
106
121
|
} else {
|
|
107
122
|
// @ts-ignore
|
|
108
|
-
this.asset = new Asset(id, type, { url: src });
|
|
123
|
+
this.asset = new Asset(id, type, src ? { url: src } : null, data);
|
|
109
124
|
}
|
|
110
125
|
|
|
111
126
|
this.asset.preload = !this._lazy;
|
|
112
127
|
}
|
|
113
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Builds the `data` object for the asset from an optional inline `data` attribute (JSON) and,
|
|
131
|
+
* for sprites, from the convenience attributes (`atlas`, `frame-keys`, `pixels-per-unit`,
|
|
132
|
+
* `render-mode`). Returns `undefined` when there is no data to apply.
|
|
133
|
+
* @param type - The resolved asset type.
|
|
134
|
+
* @returns The asset data, or `undefined`.
|
|
135
|
+
*/
|
|
136
|
+
private _buildData(type: string): Record<string, any> | undefined {
|
|
137
|
+
let data: Record<string, any> | undefined;
|
|
138
|
+
|
|
139
|
+
const dataAttr = this.getAttribute('data');
|
|
140
|
+
if (dataAttr) {
|
|
141
|
+
try {
|
|
142
|
+
data = JSON.parse(dataAttr);
|
|
143
|
+
} catch (e) {
|
|
144
|
+
console.warn(`Invalid 'data' JSON on pc-asset: ${dataAttr}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (type === 'sprite') {
|
|
149
|
+
data = data ?? {};
|
|
150
|
+
|
|
151
|
+
// Resolve the referenced texture atlas to its (numeric) asset id. The atlas must be
|
|
152
|
+
// declared before the sprite so its asset already exists in the registry.
|
|
153
|
+
const atlas = this.getAttribute('atlas') ?? data.textureAtlasAsset;
|
|
154
|
+
if (typeof atlas === 'string') {
|
|
155
|
+
const atlasAsset = AssetElement.get(atlas);
|
|
156
|
+
if (atlasAsset) {
|
|
157
|
+
data.textureAtlasAsset = atlasAsset.id;
|
|
158
|
+
} else {
|
|
159
|
+
console.warn(`pc-asset sprite '${this.getAttribute('id')}' could not find atlas '${atlas}'`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const frameKeys = this.getAttribute('frame-keys');
|
|
164
|
+
if (frameKeys !== null) {
|
|
165
|
+
data.frameKeys = frameKeys.split(/[\s,]+/).filter(Boolean);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const pixelsPerUnit = this.getAttribute('pixels-per-unit');
|
|
169
|
+
if (pixelsPerUnit !== null) {
|
|
170
|
+
data.pixelsPerUnit = Number(pixelsPerUnit);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const renderMode = this.getAttribute('render-mode');
|
|
174
|
+
if (renderMode !== null) {
|
|
175
|
+
data.renderMode = parseEnum(renderMode, renderModes, SPRITE_RENDERMODE_SIMPLE);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Apply engine defaults for any values not supplied.
|
|
179
|
+
data.renderMode = data.renderMode ?? SPRITE_RENDERMODE_SIMPLE;
|
|
180
|
+
data.pixelsPerUnit = data.pixelsPerUnit ?? 1;
|
|
181
|
+
data.frameKeys = data.frameKeys ?? [];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return data;
|
|
185
|
+
}
|
|
186
|
+
|
|
114
187
|
|
|
115
188
|
destroyAsset() {
|
|
116
189
|
if (this.asset) {
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { BUTTON_TRANSITION_MODE_SPRITE_CHANGE, BUTTON_TRANSITION_MODE_TINT, ButtonComponent, Color, Vec4 } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { AssetElement } from '../asset';
|
|
4
|
+
import { ComponentElement } from './component';
|
|
5
|
+
import { getEntity, parseColor, parseEnum, parseVec4 } from '../utils';
|
|
6
|
+
|
|
7
|
+
const transitionModes = new Map<string, number>([
|
|
8
|
+
['tint', BUTTON_TRANSITION_MODE_TINT],
|
|
9
|
+
['sprite', BUTTON_TRANSITION_MODE_SPRITE_CHANGE]
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The ButtonComponentElement interface provides properties and methods for manipulating
|
|
14
|
+
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-button/ | `<pc-button>`} elements.
|
|
15
|
+
* The ButtonComponentElement interface also inherits the properties and methods of the
|
|
16
|
+
* {@link HTMLElement} interface.
|
|
17
|
+
*
|
|
18
|
+
* @category Components
|
|
19
|
+
*/
|
|
20
|
+
class ButtonComponentElement extends ComponentElement {
|
|
21
|
+
private _active = true;
|
|
22
|
+
|
|
23
|
+
private _image = '';
|
|
24
|
+
|
|
25
|
+
private _hitPadding = new Vec4(0, 0, 0, 0);
|
|
26
|
+
|
|
27
|
+
private _transitionMode: number = BUTTON_TRANSITION_MODE_TINT;
|
|
28
|
+
|
|
29
|
+
private _hoverTint = new Color(1, 1, 1, 1);
|
|
30
|
+
|
|
31
|
+
private _pressedTint = new Color(1, 1, 1, 1);
|
|
32
|
+
|
|
33
|
+
private _inactiveTint = new Color(1, 1, 1, 1);
|
|
34
|
+
|
|
35
|
+
private _fadeDuration = 0;
|
|
36
|
+
|
|
37
|
+
private _hoverSpriteAsset = '';
|
|
38
|
+
|
|
39
|
+
private _hoverSpriteFrame = 0;
|
|
40
|
+
|
|
41
|
+
private _pressedSpriteAsset = '';
|
|
42
|
+
|
|
43
|
+
private _pressedSpriteFrame = 0;
|
|
44
|
+
|
|
45
|
+
private _inactiveSpriteAsset = '';
|
|
46
|
+
|
|
47
|
+
private _inactiveSpriteFrame = 0;
|
|
48
|
+
|
|
49
|
+
/** @ignore */
|
|
50
|
+
constructor() {
|
|
51
|
+
super('button');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getInitialComponentData() {
|
|
55
|
+
const data: Record<string, any> = {
|
|
56
|
+
active: this._active,
|
|
57
|
+
hitPadding: this._hitPadding,
|
|
58
|
+
transitionMode: this._transitionMode,
|
|
59
|
+
hoverTint: this._hoverTint,
|
|
60
|
+
pressedTint: this._pressedTint,
|
|
61
|
+
inactiveTint: this._inactiveTint,
|
|
62
|
+
fadeDuration: this._fadeDuration,
|
|
63
|
+
hoverSpriteFrame: this._hoverSpriteFrame,
|
|
64
|
+
pressedSpriteFrame: this._pressedSpriteFrame,
|
|
65
|
+
inactiveSpriteFrame: this._inactiveSpriteFrame
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// The image entity defaults to the button's own entity (which carries the image element)
|
|
69
|
+
// when no explicit reference is provided.
|
|
70
|
+
const imageEntity = this._image ? getEntity(this._image) : this.closestEntity?.entity;
|
|
71
|
+
if (imageEntity) {
|
|
72
|
+
data.imageEntity = imageEntity;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const hoverSpriteAsset = AssetElement.get(this._hoverSpriteAsset);
|
|
76
|
+
if (hoverSpriteAsset) {
|
|
77
|
+
data.hoverSpriteAsset = hoverSpriteAsset.id;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const pressedSpriteAsset = AssetElement.get(this._pressedSpriteAsset);
|
|
81
|
+
if (pressedSpriteAsset) {
|
|
82
|
+
data.pressedSpriteAsset = pressedSpriteAsset.id;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const inactiveSpriteAsset = AssetElement.get(this._inactiveSpriteAsset);
|
|
86
|
+
if (inactiveSpriteAsset) {
|
|
87
|
+
data.inactiveSpriteAsset = inactiveSpriteAsset.id;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Gets the underlying PlayCanvas button component.
|
|
95
|
+
* @returns The button component.
|
|
96
|
+
*/
|
|
97
|
+
get component(): ButtonComponent | null {
|
|
98
|
+
return super.component as ButtonComponent | null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Sets whether the button is active and responds to input.
|
|
103
|
+
* @param value - Whether the button is active.
|
|
104
|
+
*/
|
|
105
|
+
set active(value: boolean) {
|
|
106
|
+
this._active = value;
|
|
107
|
+
if (this.component) {
|
|
108
|
+
this.component.active = value;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Gets whether the button is active.
|
|
114
|
+
* @returns Whether the button is active.
|
|
115
|
+
*/
|
|
116
|
+
get active() {
|
|
117
|
+
return this._active;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Sets the reference (CSS selector, element id or entity name) to the `<pc-entity>` whose image
|
|
122
|
+
* element is used for visual transitions. Defaults to the button's own entity.
|
|
123
|
+
* @param value - The image entity reference.
|
|
124
|
+
*/
|
|
125
|
+
set image(value: string) {
|
|
126
|
+
this._image = value;
|
|
127
|
+
const entity = getEntity(value);
|
|
128
|
+
if (this.component && entity) {
|
|
129
|
+
this.component.imageEntity = entity;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Gets the reference to the `<pc-entity>` whose image element is used for visual transitions.
|
|
135
|
+
* @returns The image entity reference.
|
|
136
|
+
*/
|
|
137
|
+
get image() {
|
|
138
|
+
return this._image;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Sets the padding used to expand the button's hit area, as a Vec4 (left, bottom, right, top).
|
|
143
|
+
* @param value - The hit padding.
|
|
144
|
+
*/
|
|
145
|
+
set hitPadding(value: Vec4) {
|
|
146
|
+
this._hitPadding = value;
|
|
147
|
+
if (this.component) {
|
|
148
|
+
this.component.hitPadding = value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Gets the padding used to expand the button's hit area.
|
|
154
|
+
* @returns The hit padding.
|
|
155
|
+
*/
|
|
156
|
+
get hitPadding() {
|
|
157
|
+
return this._hitPadding;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Sets how the button reacts to being hovered/pressed. Can be `tint` (0) or `sprite` (1).
|
|
162
|
+
* @param value - The transition mode.
|
|
163
|
+
*/
|
|
164
|
+
set transitionMode(value: number) {
|
|
165
|
+
this._transitionMode = value;
|
|
166
|
+
if (this.component) {
|
|
167
|
+
this.component.transitionMode = value;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Gets how the button reacts to being hovered/pressed.
|
|
173
|
+
* @returns The transition mode.
|
|
174
|
+
*/
|
|
175
|
+
get transitionMode() {
|
|
176
|
+
return this._transitionMode;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Sets the tint color applied to the image entity when the button is hovered (tint transition
|
|
181
|
+
* mode).
|
|
182
|
+
* @param value - The hover tint.
|
|
183
|
+
*/
|
|
184
|
+
set hoverTint(value: Color) {
|
|
185
|
+
this._hoverTint = value;
|
|
186
|
+
if (this.component) {
|
|
187
|
+
this.component.hoverTint = value;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Gets the hover tint color.
|
|
193
|
+
* @returns The hover tint.
|
|
194
|
+
*/
|
|
195
|
+
get hoverTint() {
|
|
196
|
+
return this._hoverTint;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Sets the tint color applied to the image entity when the button is pressed (tint transition
|
|
201
|
+
* mode).
|
|
202
|
+
* @param value - The pressed tint.
|
|
203
|
+
*/
|
|
204
|
+
set pressedTint(value: Color) {
|
|
205
|
+
this._pressedTint = value;
|
|
206
|
+
if (this.component) {
|
|
207
|
+
this.component.pressedTint = value;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Gets the pressed tint color.
|
|
213
|
+
* @returns The pressed tint.
|
|
214
|
+
*/
|
|
215
|
+
get pressedTint() {
|
|
216
|
+
return this._pressedTint;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Sets the tint color applied to the image entity when the button is inactive (tint transition
|
|
221
|
+
* mode).
|
|
222
|
+
* @param value - The inactive tint.
|
|
223
|
+
*/
|
|
224
|
+
set inactiveTint(value: Color) {
|
|
225
|
+
this._inactiveTint = value;
|
|
226
|
+
if (this.component) {
|
|
227
|
+
this.component.inactiveTint = value;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Gets the inactive tint color.
|
|
233
|
+
* @returns The inactive tint.
|
|
234
|
+
*/
|
|
235
|
+
get inactiveTint() {
|
|
236
|
+
return this._inactiveTint;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Sets the duration (in milliseconds) over which tint transitions are applied.
|
|
241
|
+
* @param value - The fade duration.
|
|
242
|
+
*/
|
|
243
|
+
set fadeDuration(value: number) {
|
|
244
|
+
this._fadeDuration = value;
|
|
245
|
+
if (this.component) {
|
|
246
|
+
this.component.fadeDuration = value;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Gets the duration over which tint transitions are applied.
|
|
252
|
+
* @returns The fade duration.
|
|
253
|
+
*/
|
|
254
|
+
get fadeDuration() {
|
|
255
|
+
return this._fadeDuration;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Sets the id of the `pc-asset` sprite shown when the button is hovered (sprite transition
|
|
260
|
+
* mode).
|
|
261
|
+
* @param value - The hover sprite asset id.
|
|
262
|
+
*/
|
|
263
|
+
set hoverSpriteAsset(value: string) {
|
|
264
|
+
this._hoverSpriteAsset = value;
|
|
265
|
+
const asset = AssetElement.get(value);
|
|
266
|
+
if (this.component && asset) {
|
|
267
|
+
this.component.hoverSpriteAsset = asset.id as any;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Gets the id of the `pc-asset` sprite shown when the button is hovered.
|
|
273
|
+
* @returns The hover sprite asset id.
|
|
274
|
+
*/
|
|
275
|
+
get hoverSpriteAsset() {
|
|
276
|
+
return this._hoverSpriteAsset;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Sets the frame of the hover sprite to show.
|
|
281
|
+
* @param value - The hover sprite frame.
|
|
282
|
+
*/
|
|
283
|
+
set hoverSpriteFrame(value: number) {
|
|
284
|
+
this._hoverSpriteFrame = value;
|
|
285
|
+
if (this.component) {
|
|
286
|
+
this.component.hoverSpriteFrame = value;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Gets the frame of the hover sprite to show.
|
|
292
|
+
* @returns The hover sprite frame.
|
|
293
|
+
*/
|
|
294
|
+
get hoverSpriteFrame() {
|
|
295
|
+
return this._hoverSpriteFrame;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Sets the id of the `pc-asset` sprite shown when the button is pressed (sprite transition
|
|
300
|
+
* mode).
|
|
301
|
+
* @param value - The pressed sprite asset id.
|
|
302
|
+
*/
|
|
303
|
+
set pressedSpriteAsset(value: string) {
|
|
304
|
+
this._pressedSpriteAsset = value;
|
|
305
|
+
const asset = AssetElement.get(value);
|
|
306
|
+
if (this.component && asset) {
|
|
307
|
+
this.component.pressedSpriteAsset = asset.id as any;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Gets the id of the `pc-asset` sprite shown when the button is pressed.
|
|
313
|
+
* @returns The pressed sprite asset id.
|
|
314
|
+
*/
|
|
315
|
+
get pressedSpriteAsset() {
|
|
316
|
+
return this._pressedSpriteAsset;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Sets the frame of the pressed sprite to show.
|
|
321
|
+
* @param value - The pressed sprite frame.
|
|
322
|
+
*/
|
|
323
|
+
set pressedSpriteFrame(value: number) {
|
|
324
|
+
this._pressedSpriteFrame = value;
|
|
325
|
+
if (this.component) {
|
|
326
|
+
this.component.pressedSpriteFrame = value;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Gets the frame of the pressed sprite to show.
|
|
332
|
+
* @returns The pressed sprite frame.
|
|
333
|
+
*/
|
|
334
|
+
get pressedSpriteFrame() {
|
|
335
|
+
return this._pressedSpriteFrame;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Sets the id of the `pc-asset` sprite shown when the button is inactive (sprite transition
|
|
340
|
+
* mode).
|
|
341
|
+
* @param value - The inactive sprite asset id.
|
|
342
|
+
*/
|
|
343
|
+
set inactiveSpriteAsset(value: string) {
|
|
344
|
+
this._inactiveSpriteAsset = value;
|
|
345
|
+
const asset = AssetElement.get(value);
|
|
346
|
+
if (this.component && asset) {
|
|
347
|
+
this.component.inactiveSpriteAsset = asset.id as any;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Gets the id of the `pc-asset` sprite shown when the button is inactive.
|
|
353
|
+
* @returns The inactive sprite asset id.
|
|
354
|
+
*/
|
|
355
|
+
get inactiveSpriteAsset() {
|
|
356
|
+
return this._inactiveSpriteAsset;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Sets the frame of the inactive sprite to show.
|
|
361
|
+
* @param value - The inactive sprite frame.
|
|
362
|
+
*/
|
|
363
|
+
set inactiveSpriteFrame(value: number) {
|
|
364
|
+
this._inactiveSpriteFrame = value;
|
|
365
|
+
if (this.component) {
|
|
366
|
+
this.component.inactiveSpriteFrame = value;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Gets the frame of the inactive sprite to show.
|
|
372
|
+
* @returns The inactive sprite frame.
|
|
373
|
+
*/
|
|
374
|
+
get inactiveSpriteFrame() {
|
|
375
|
+
return this._inactiveSpriteFrame;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
static get observedAttributes() {
|
|
379
|
+
return [
|
|
380
|
+
...super.observedAttributes,
|
|
381
|
+
'active',
|
|
382
|
+
'image',
|
|
383
|
+
'hit-padding',
|
|
384
|
+
'transition-mode',
|
|
385
|
+
'hover-tint',
|
|
386
|
+
'pressed-tint',
|
|
387
|
+
'inactive-tint',
|
|
388
|
+
'fade-duration',
|
|
389
|
+
'hover-sprite-asset',
|
|
390
|
+
'hover-sprite-frame',
|
|
391
|
+
'pressed-sprite-asset',
|
|
392
|
+
'pressed-sprite-frame',
|
|
393
|
+
'inactive-sprite-asset',
|
|
394
|
+
'inactive-sprite-frame'
|
|
395
|
+
];
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
399
|
+
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
400
|
+
|
|
401
|
+
switch (name) {
|
|
402
|
+
case 'active':
|
|
403
|
+
this.active = newValue !== 'false';
|
|
404
|
+
break;
|
|
405
|
+
case 'image':
|
|
406
|
+
this.image = newValue;
|
|
407
|
+
break;
|
|
408
|
+
case 'hit-padding':
|
|
409
|
+
this.hitPadding = parseVec4(newValue);
|
|
410
|
+
break;
|
|
411
|
+
case 'transition-mode':
|
|
412
|
+
this.transitionMode = parseEnum(newValue, transitionModes, BUTTON_TRANSITION_MODE_TINT);
|
|
413
|
+
break;
|
|
414
|
+
case 'hover-tint':
|
|
415
|
+
this.hoverTint = parseColor(newValue);
|
|
416
|
+
break;
|
|
417
|
+
case 'pressed-tint':
|
|
418
|
+
this.pressedTint = parseColor(newValue);
|
|
419
|
+
break;
|
|
420
|
+
case 'inactive-tint':
|
|
421
|
+
this.inactiveTint = parseColor(newValue);
|
|
422
|
+
break;
|
|
423
|
+
case 'fade-duration':
|
|
424
|
+
this.fadeDuration = Number(newValue);
|
|
425
|
+
break;
|
|
426
|
+
case 'hover-sprite-asset':
|
|
427
|
+
this.hoverSpriteAsset = newValue;
|
|
428
|
+
break;
|
|
429
|
+
case 'hover-sprite-frame':
|
|
430
|
+
this.hoverSpriteFrame = Number(newValue);
|
|
431
|
+
break;
|
|
432
|
+
case 'pressed-sprite-asset':
|
|
433
|
+
this.pressedSpriteAsset = newValue;
|
|
434
|
+
break;
|
|
435
|
+
case 'pressed-sprite-frame':
|
|
436
|
+
this.pressedSpriteFrame = Number(newValue);
|
|
437
|
+
break;
|
|
438
|
+
case 'inactive-sprite-asset':
|
|
439
|
+
this.inactiveSpriteAsset = newValue;
|
|
440
|
+
break;
|
|
441
|
+
case 'inactive-sprite-frame':
|
|
442
|
+
this.inactiveSpriteFrame = Number(newValue);
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
customElements.define('pc-button', ButtonComponentElement);
|
|
449
|
+
|
|
450
|
+
export { ButtonComponentElement };
|