hudini 0.6.0 → 0.8.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/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +2 -0
- package/dist/components/index.js.map +1 -1
- package/dist/components/linear-progress/index.d.ts +2 -0
- package/dist/components/linear-progress/index.d.ts.map +1 -0
- package/dist/components/linear-progress/index.js +2 -0
- package/dist/components/linear-progress/index.js.map +1 -0
- package/dist/components/linear-progress/linear-progress.d.ts +93 -0
- package/dist/components/linear-progress/linear-progress.d.ts.map +1 -0
- package/dist/components/linear-progress/linear-progress.js +231 -0
- package/dist/components/linear-progress/linear-progress.js.map +1 -0
- package/dist/components/linear-progress/linear-progress.spec.d.ts +2 -0
- package/dist/components/linear-progress/linear-progress.spec.d.ts.map +1 -0
- package/dist/components/linear-progress/linear-progress.spec.js +288 -0
- package/dist/components/linear-progress/linear-progress.spec.js.map +1 -0
- package/dist/components/text-button/index.d.ts +2 -0
- package/dist/components/text-button/index.d.ts.map +1 -0
- package/dist/components/text-button/index.js +2 -0
- package/dist/components/text-button/index.js.map +1 -0
- package/dist/components/text-button/text-button.d.ts +52 -0
- package/dist/components/text-button/text-button.d.ts.map +1 -0
- package/dist/components/text-button/text-button.js +217 -0
- package/dist/components/text-button/text-button.js.map +1 -0
- package/dist/components/text-button/text-button.spec.d.ts +2 -0
- package/dist/components/text-button/text-button.spec.d.ts.map +1 -0
- package/dist/components/text-button/text-button.spec.js +196 -0
- package/dist/components/text-button/text-button.spec.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC"}
|
package/dist/components/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/linear-progress/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/linear-progress/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { GameObjects, Scene } from 'phaser';
|
|
2
|
+
import { type ColorToken, type RadiusKey } from 'phaser-wind';
|
|
3
|
+
export type LinearProgressParams = {
|
|
4
|
+
/** The scene this progress bar belongs to */
|
|
5
|
+
scene: Scene;
|
|
6
|
+
/** X coordinate of the progress bar */
|
|
7
|
+
x: number;
|
|
8
|
+
/** Y coordinate of the progress bar */
|
|
9
|
+
y: number;
|
|
10
|
+
/** Width of the progress bar in pixels */
|
|
11
|
+
width: number;
|
|
12
|
+
/** Height of the progress bar in pixels */
|
|
13
|
+
height: number;
|
|
14
|
+
/** Background color of the progress bar track */
|
|
15
|
+
backgroundColor?: ColorToken;
|
|
16
|
+
/** Color of the progress bar fill */
|
|
17
|
+
progressColor?: ColorToken;
|
|
18
|
+
/** Border radius in px (number) or a Phaser Wind radius token (string). Defaults to 'default'.
|
|
19
|
+
* Note: The effective radius is automatically limited to half of the smallest dimension to prevent visual artifacts. */
|
|
20
|
+
borderRadius?: RadiusKey | number;
|
|
21
|
+
/** Initial progress value (0-100) */
|
|
22
|
+
progress?: number;
|
|
23
|
+
/** Whether this is an indeterminate progress bar */
|
|
24
|
+
indeterminate?: boolean;
|
|
25
|
+
/** Duration of the indeterminate animation in milliseconds */
|
|
26
|
+
indeterminateAnimationDuration?: number;
|
|
27
|
+
};
|
|
28
|
+
export declare class LinearProgress extends GameObjects.Container {
|
|
29
|
+
backgroundProgressBar: GameObjects.Graphics;
|
|
30
|
+
progressBar: GameObjects.Graphics;
|
|
31
|
+
private pw;
|
|
32
|
+
private progressWidth;
|
|
33
|
+
private progressHeight;
|
|
34
|
+
private borderRadiusPx;
|
|
35
|
+
private backgroundColor;
|
|
36
|
+
private progressColor;
|
|
37
|
+
private currentProgress;
|
|
38
|
+
private isIndeterminate;
|
|
39
|
+
private indeterminateAnimation?;
|
|
40
|
+
private indeterminateAnimationDuration;
|
|
41
|
+
constructor({ scene, x, y, width, height, backgroundColor, progressColor, borderRadius, progress, indeterminate, indeterminateAnimationDuration, }: LinearProgressParams);
|
|
42
|
+
/**
|
|
43
|
+
* Sets the progress value (0-100)
|
|
44
|
+
* @param progress Progress value between 0 and 100
|
|
45
|
+
* @param animate Whether to animate the change (default: true)
|
|
46
|
+
*/
|
|
47
|
+
setProgress(progress: number, animate?: boolean): this;
|
|
48
|
+
/**
|
|
49
|
+
* Gets the current progress value
|
|
50
|
+
* @returns Current progress value (0-100)
|
|
51
|
+
*/
|
|
52
|
+
getProgress(): number;
|
|
53
|
+
/**
|
|
54
|
+
* Sets whether the progress bar is indeterminate
|
|
55
|
+
* @param indeterminate Whether to show indeterminate animation
|
|
56
|
+
*/
|
|
57
|
+
setIndeterminate(indeterminate: boolean): this;
|
|
58
|
+
/**
|
|
59
|
+
* Sets the border radius of the progress bar
|
|
60
|
+
* @param borderRadius Border radius in px (number) or a Phaser Wind radius token (string)
|
|
61
|
+
* Note: The effective radius is automatically limited to half of the smallest dimension to prevent visual artifacts.
|
|
62
|
+
*/
|
|
63
|
+
setBorderRadius(borderRadius: RadiusKey | number): this;
|
|
64
|
+
/**
|
|
65
|
+
* Sets the background color of the progress bar
|
|
66
|
+
* @param color Background color token
|
|
67
|
+
*/
|
|
68
|
+
setBackgroundColor(color: ColorToken): this;
|
|
69
|
+
/**
|
|
70
|
+
* Sets the progress color of the progress bar
|
|
71
|
+
* @param color Progress color token
|
|
72
|
+
*/
|
|
73
|
+
setProgressColor(color: ColorToken): this;
|
|
74
|
+
/**
|
|
75
|
+
* Destroys the component and cleans up animations
|
|
76
|
+
*/
|
|
77
|
+
destroy(): void;
|
|
78
|
+
private createBackgroundSprite;
|
|
79
|
+
private createProgressSprite;
|
|
80
|
+
private setupContainer;
|
|
81
|
+
private calculateProgressDimensions;
|
|
82
|
+
private updateProgressBar;
|
|
83
|
+
private startIndeterminateAnimation;
|
|
84
|
+
private stopIndeterminateAnimation;
|
|
85
|
+
private recreateSprites;
|
|
86
|
+
/**
|
|
87
|
+
* Calculates the effective border radius, ensuring it doesn't exceed
|
|
88
|
+
* half of the smallest dimension to prevent visual artifacts
|
|
89
|
+
* @returns Limited border radius in pixels
|
|
90
|
+
*/
|
|
91
|
+
private getEffectiveBorderRadius;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=linear-progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linear-progress.d.ts","sourceRoot":"","sources":["../../../src/components/linear-progress/linear-progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AAIrB,MAAM,MAAM,oBAAoB,GAAG;IACjC,6CAA6C;IAC7C,KAAK,EAAE,KAAK,CAAC;IACb,uCAAuC;IACvC,CAAC,EAAE,MAAM,CAAC;IACV,uCAAuC;IACvC,CAAC,EAAE,MAAM,CAAC;IACV,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B,qCAAqC;IACrC,aAAa,CAAC,EAAE,UAAU,CAAC;IAC3B;4HACwH;IACxH,YAAY,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAClC,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,8DAA8D;IAC9D,8BAA8B,CAAC,EAAE,MAAM,CAAC;CACzC,CAAC;AAKF,qBAAa,cAAe,SAAQ,WAAW,CAAC,SAAS;IAChD,qBAAqB,EAAG,WAAW,CAAC,QAAQ,CAAC;IAC7C,WAAW,EAAG,WAAW,CAAC,QAAQ,CAAC;IAE1C,OAAO,CAAC,EAAE,CAAuB;IACjC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,eAAe,CAAa;IACpC,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,sBAAsB,CAAC,CAAkC;IACjE,OAAO,CAAC,8BAA8B,CAAS;gBAEnC,EACV,KAAK,EACL,CAAC,EACD,CAAC,EACD,KAAK,EACL,MAAM,EACN,eAA4B,EAC5B,aAA0B,EAC1B,YAAwB,EACxB,QAAY,EACZ,aAAqB,EACrB,8BAAiE,GAClE,EAAE,oBAAoB;IA2BvB;;;;OAIG;IACI,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,OAAc,GAAG,IAAI;IA8BnE;;;OAGG;IACI,WAAW,IAAI,MAAM;IAI5B;;;OAGG;IACI,gBAAgB,CAAC,aAAa,EAAE,OAAO,GAAG,IAAI;IAkBrD;;;;OAIG;IACI,eAAe,CAAC,YAAY,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI;IAe9D;;;OAGG;IACI,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAUlD;;;OAGG;IACI,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAUhD;;OAEG;IACa,OAAO,IAAI,IAAI;IAK/B,OAAO,CAAC,sBAAsB;IAc9B,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,2BAA2B;IAMnC,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,2BAA2B;IA0BnC,OAAO,CAAC,0BAA0B;IAOlC,OAAO,CAAC,eAAe;IAmBvB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;CAIjC"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { GameObjects } from 'phaser';
|
|
2
|
+
import { Color, } from 'phaser-wind';
|
|
3
|
+
import { getPWFromScene } from '../../utils/get-pw-from-scene';
|
|
4
|
+
const A_HUNDRED = 100;
|
|
5
|
+
const INDETERMINATE_ANIMATION_DURATION = 1500; // 1.5 seconds
|
|
6
|
+
export class LinearProgress extends GameObjects.Container {
|
|
7
|
+
backgroundProgressBar;
|
|
8
|
+
progressBar;
|
|
9
|
+
pw;
|
|
10
|
+
progressWidth;
|
|
11
|
+
progressHeight;
|
|
12
|
+
borderRadiusPx;
|
|
13
|
+
backgroundColor;
|
|
14
|
+
progressColor;
|
|
15
|
+
currentProgress;
|
|
16
|
+
isIndeterminate;
|
|
17
|
+
indeterminateAnimation;
|
|
18
|
+
indeterminateAnimationDuration;
|
|
19
|
+
constructor({ scene, x, y, width, height, backgroundColor = 'gray-200', progressColor = 'blue-500', borderRadius = 'default', progress = 0, indeterminate = false, indeterminateAnimationDuration = INDETERMINATE_ANIMATION_DURATION, }) {
|
|
20
|
+
super(scene, x, y);
|
|
21
|
+
this.pw = getPWFromScene(scene);
|
|
22
|
+
this.progressWidth = width;
|
|
23
|
+
this.progressHeight = height;
|
|
24
|
+
this.backgroundColor = backgroundColor;
|
|
25
|
+
this.progressColor = progressColor;
|
|
26
|
+
this.currentProgress = Math.max(0, Math.min(A_HUNDRED, progress));
|
|
27
|
+
this.isIndeterminate = indeterminate;
|
|
28
|
+
this.indeterminateAnimationDuration = indeterminateAnimationDuration;
|
|
29
|
+
this.borderRadiusPx =
|
|
30
|
+
typeof borderRadius === 'number'
|
|
31
|
+
? borderRadius
|
|
32
|
+
: this.pw.radius.px(borderRadius);
|
|
33
|
+
this.createBackgroundSprite();
|
|
34
|
+
this.createProgressSprite();
|
|
35
|
+
this.setupContainer();
|
|
36
|
+
if (this.isIndeterminate) {
|
|
37
|
+
this.startIndeterminateAnimation();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.updateProgressBar();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Sets the progress value (0-100)
|
|
45
|
+
* @param progress Progress value between 0 and 100
|
|
46
|
+
* @param animate Whether to animate the change (default: true)
|
|
47
|
+
*/
|
|
48
|
+
setProgress(progress, animate = true) {
|
|
49
|
+
if (this.isIndeterminate) {
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
const newProgress = Math.max(0, Math.min(A_HUNDRED, progress));
|
|
53
|
+
if (this.currentProgress === newProgress) {
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
if (animate) {
|
|
57
|
+
const target = { value: this.currentProgress };
|
|
58
|
+
this.scene.tweens.add({
|
|
59
|
+
targets: target,
|
|
60
|
+
value: newProgress,
|
|
61
|
+
duration: 300,
|
|
62
|
+
ease: 'Power2',
|
|
63
|
+
onUpdate: () => {
|
|
64
|
+
this.currentProgress = target.value;
|
|
65
|
+
this.updateProgressBar();
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.currentProgress = newProgress;
|
|
71
|
+
this.updateProgressBar();
|
|
72
|
+
}
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Gets the current progress value
|
|
77
|
+
* @returns Current progress value (0-100)
|
|
78
|
+
*/
|
|
79
|
+
getProgress() {
|
|
80
|
+
return this.currentProgress;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Sets whether the progress bar is indeterminate
|
|
84
|
+
* @param indeterminate Whether to show indeterminate animation
|
|
85
|
+
*/
|
|
86
|
+
setIndeterminate(indeterminate) {
|
|
87
|
+
if (this.isIndeterminate === indeterminate) {
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
this.isIndeterminate = indeterminate;
|
|
91
|
+
if (this.isIndeterminate) {
|
|
92
|
+
this.stopIndeterminateAnimation();
|
|
93
|
+
this.startIndeterminateAnimation();
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this.stopIndeterminateAnimation();
|
|
97
|
+
this.updateProgressBar();
|
|
98
|
+
}
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Sets the border radius of the progress bar
|
|
103
|
+
* @param borderRadius Border radius in px (number) or a Phaser Wind radius token (string)
|
|
104
|
+
* Note: The effective radius is automatically limited to half of the smallest dimension to prevent visual artifacts.
|
|
105
|
+
*/
|
|
106
|
+
setBorderRadius(borderRadius) {
|
|
107
|
+
const newRadiusPx = typeof borderRadius === 'number'
|
|
108
|
+
? borderRadius
|
|
109
|
+
: this.pw.radius.px(borderRadius);
|
|
110
|
+
if (this.borderRadiusPx === newRadiusPx) {
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
this.borderRadiusPx = newRadiusPx;
|
|
114
|
+
this.recreateSprites();
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Sets the background color of the progress bar
|
|
119
|
+
* @param color Background color token
|
|
120
|
+
*/
|
|
121
|
+
setBackgroundColor(color) {
|
|
122
|
+
if (this.backgroundColor === color) {
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
this.backgroundColor = color;
|
|
126
|
+
this.recreateSprites();
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Sets the progress color of the progress bar
|
|
131
|
+
* @param color Progress color token
|
|
132
|
+
*/
|
|
133
|
+
setProgressColor(color) {
|
|
134
|
+
if (this.progressColor === color) {
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
this.progressColor = color;
|
|
138
|
+
this.recreateSprites();
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Destroys the component and cleans up animations
|
|
143
|
+
*/
|
|
144
|
+
destroy() {
|
|
145
|
+
this.stopIndeterminateAnimation();
|
|
146
|
+
super.destroy();
|
|
147
|
+
}
|
|
148
|
+
createBackgroundSprite() {
|
|
149
|
+
const bgGraphic = this.scene.add.graphics();
|
|
150
|
+
bgGraphic.fillStyle(Color.hex(this.backgroundColor), 1);
|
|
151
|
+
bgGraphic.fillRoundedRect(-this.progressWidth / 2, -this.progressHeight / 2, this.progressWidth, this.progressHeight, this.getEffectiveBorderRadius());
|
|
152
|
+
this.backgroundProgressBar = bgGraphic;
|
|
153
|
+
}
|
|
154
|
+
createProgressSprite() {
|
|
155
|
+
const progressBar = this.scene.add.graphics();
|
|
156
|
+
progressBar.fillStyle(Color.hex(this.progressColor), 1);
|
|
157
|
+
progressBar.fillRoundedRect(-this.progressWidth / 2, -this.progressHeight / 2, this.progressWidth, this.progressHeight, this.getEffectiveBorderRadius());
|
|
158
|
+
this.progressBar = progressBar;
|
|
159
|
+
}
|
|
160
|
+
setupContainer() {
|
|
161
|
+
this.add([this.backgroundProgressBar, this.progressBar]);
|
|
162
|
+
}
|
|
163
|
+
calculateProgressDimensions() {
|
|
164
|
+
const progressWidth = (this.progressWidth * this.currentProgress) / A_HUNDRED;
|
|
165
|
+
const leftOffset = (progressWidth - this.progressWidth) / 2;
|
|
166
|
+
return { progressWidth, leftOffset };
|
|
167
|
+
}
|
|
168
|
+
updateProgressBar(force = false) {
|
|
169
|
+
if (this.isIndeterminate && !force) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const { progressWidth, leftOffset } = this.calculateProgressDimensions();
|
|
173
|
+
this.progressBar.setScale(progressWidth / this.progressWidth, 1);
|
|
174
|
+
this.progressBar.setX(leftOffset);
|
|
175
|
+
}
|
|
176
|
+
startIndeterminateAnimation() {
|
|
177
|
+
if (!this.isIndeterminate) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
this.currentProgress = 40;
|
|
181
|
+
this.updateProgressBar(true);
|
|
182
|
+
const { progressWidth } = this.calculateProgressDimensions();
|
|
183
|
+
// Calculate the movement range: the bar should move within the background bounds
|
|
184
|
+
// The bar center can move from left edge + half bar width to right edge - half bar width
|
|
185
|
+
const maxX = (this.progressWidth / 2) - (progressWidth / 2);
|
|
186
|
+
const minX = -(this.progressWidth / 2) + (progressWidth / 2);
|
|
187
|
+
// Start from the left
|
|
188
|
+
this.progressBar.setX(minX);
|
|
189
|
+
this.indeterminateAnimation = this.scene.tweens.add({
|
|
190
|
+
targets: this.progressBar,
|
|
191
|
+
x: maxX,
|
|
192
|
+
duration: this.indeterminateAnimationDuration,
|
|
193
|
+
ease: 'Sine.easeInOut',
|
|
194
|
+
yoyo: true,
|
|
195
|
+
repeat: -1,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
stopIndeterminateAnimation() {
|
|
199
|
+
if (this.indeterminateAnimation) {
|
|
200
|
+
this.indeterminateAnimation.destroy();
|
|
201
|
+
this.indeterminateAnimation = undefined;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
recreateSprites() {
|
|
205
|
+
// Remove old sprites
|
|
206
|
+
this.remove([this.backgroundProgressBar, this.progressBar]);
|
|
207
|
+
this.backgroundProgressBar.destroy();
|
|
208
|
+
this.progressBar.destroy();
|
|
209
|
+
// Create new sprites with updated properties
|
|
210
|
+
this.createBackgroundSprite();
|
|
211
|
+
this.createProgressSprite();
|
|
212
|
+
this.setupContainer();
|
|
213
|
+
// Restore state
|
|
214
|
+
if (this.isIndeterminate) {
|
|
215
|
+
this.startIndeterminateAnimation();
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
this.updateProgressBar();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Calculates the effective border radius, ensuring it doesn't exceed
|
|
223
|
+
* half of the smallest dimension to prevent visual artifacts
|
|
224
|
+
* @returns Limited border radius in pixels
|
|
225
|
+
*/
|
|
226
|
+
getEffectiveBorderRadius() {
|
|
227
|
+
const maxRadius = Math.min(this.progressWidth, this.progressHeight) / 2;
|
|
228
|
+
return Math.min(this.borderRadiusPx, maxRadius);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=linear-progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linear-progress.js","sourceRoot":"","sources":["../../../src/components/linear-progress/linear-progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAS,MAAM,QAAQ,CAAC;AAC5C,OAAO,EACL,KAAK,GAIN,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,cAAc,EAA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AAI,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linear-progress.spec.d.ts","sourceRoot":"","sources":["../../../src/components/linear-progress/linear-progress.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/* eslint-disable no-magic-numbers */
|
|
2
|
+
/* eslint-disable max-lines-per-function */
|
|
3
|
+
import { Scene } from 'phaser';
|
|
4
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
// Mock Phaser to avoid canvas dependency in runtime
|
|
6
|
+
vi.mock('phaser', () => {
|
|
7
|
+
class Scene {
|
|
8
|
+
add = {
|
|
9
|
+
graphics: () => ({
|
|
10
|
+
fillStyle: vi.fn(),
|
|
11
|
+
fillRoundedRect: vi.fn(),
|
|
12
|
+
generateTexture: vi.fn(),
|
|
13
|
+
destroy: vi.fn(),
|
|
14
|
+
setScale: vi.fn(),
|
|
15
|
+
setX: vi.fn(),
|
|
16
|
+
}),
|
|
17
|
+
sprite: vi.fn(() => ({
|
|
18
|
+
setOrigin: vi.fn(),
|
|
19
|
+
setScale: vi.fn(),
|
|
20
|
+
setX: vi.fn(),
|
|
21
|
+
destroy: vi.fn(),
|
|
22
|
+
})),
|
|
23
|
+
};
|
|
24
|
+
textures = {
|
|
25
|
+
exists: vi.fn(() => false),
|
|
26
|
+
};
|
|
27
|
+
tweens = {
|
|
28
|
+
add: vi.fn(() => ({
|
|
29
|
+
destroy: vi.fn(),
|
|
30
|
+
})),
|
|
31
|
+
};
|
|
32
|
+
constructor() {
|
|
33
|
+
// Ensure textures is properly bound to this instance
|
|
34
|
+
this.textures = {
|
|
35
|
+
exists: vi.fn(() => false),
|
|
36
|
+
};
|
|
37
|
+
this.tweens = {
|
|
38
|
+
add: vi.fn(() => ({
|
|
39
|
+
destroy: vi.fn(),
|
|
40
|
+
})),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class Container {
|
|
45
|
+
list = [];
|
|
46
|
+
x;
|
|
47
|
+
y;
|
|
48
|
+
width = 0;
|
|
49
|
+
height = 0;
|
|
50
|
+
scene;
|
|
51
|
+
constructor(scene, x, y) {
|
|
52
|
+
this.scene = scene;
|
|
53
|
+
this.x = x;
|
|
54
|
+
this.y = y;
|
|
55
|
+
}
|
|
56
|
+
add(child) {
|
|
57
|
+
if (Array.isArray(child)) {
|
|
58
|
+
this.list.push(...child);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.list.push(child);
|
|
62
|
+
}
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
remove(child) {
|
|
66
|
+
if (Array.isArray(child)) {
|
|
67
|
+
child.forEach(c => {
|
|
68
|
+
const index = this.list.indexOf(c);
|
|
69
|
+
if (index !== -1)
|
|
70
|
+
this.list.splice(index, 1);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const index = this.list.indexOf(child);
|
|
75
|
+
if (index !== -1)
|
|
76
|
+
this.list.splice(index, 1);
|
|
77
|
+
}
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
destroy() {
|
|
81
|
+
this.list = [];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const GameObjects = { Container };
|
|
85
|
+
return { GameObjects, Scene };
|
|
86
|
+
});
|
|
87
|
+
// Mock the getPWFromScene utility
|
|
88
|
+
vi.mock('../../utils/get-pw-from-scene', () => ({
|
|
89
|
+
getPWFromScene: () => ({
|
|
90
|
+
radius: {
|
|
91
|
+
px: (key) => {
|
|
92
|
+
const radiusMap = {
|
|
93
|
+
none: 0,
|
|
94
|
+
sm: 2,
|
|
95
|
+
default: 4,
|
|
96
|
+
md: 6,
|
|
97
|
+
lg: 8,
|
|
98
|
+
xl: 12,
|
|
99
|
+
'2xl': 16,
|
|
100
|
+
'3xl': 24,
|
|
101
|
+
full: 9999,
|
|
102
|
+
};
|
|
103
|
+
return radiusMap[key] ?? 4;
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
}));
|
|
108
|
+
// Mock Color utility
|
|
109
|
+
vi.mock('phaser-wind', () => ({
|
|
110
|
+
Color: {
|
|
111
|
+
hex: vi.fn(() => 0x000000),
|
|
112
|
+
},
|
|
113
|
+
}));
|
|
114
|
+
import { LinearProgress } from './linear-progress';
|
|
115
|
+
describe('LinearProgress', () => {
|
|
116
|
+
let linearProgress;
|
|
117
|
+
let scene;
|
|
118
|
+
beforeEach(() => {
|
|
119
|
+
vi.clearAllMocks();
|
|
120
|
+
scene = new Scene();
|
|
121
|
+
});
|
|
122
|
+
describe('constructor', () => {
|
|
123
|
+
it('should create a linear progress bar with default parameters', () => {
|
|
124
|
+
linearProgress = new LinearProgress({
|
|
125
|
+
scene,
|
|
126
|
+
x: 100,
|
|
127
|
+
y: 100,
|
|
128
|
+
width: 200,
|
|
129
|
+
height: 8,
|
|
130
|
+
});
|
|
131
|
+
expect(linearProgress).toBeInstanceOf(LinearProgress);
|
|
132
|
+
expect(linearProgress.getProgress()).toBe(0);
|
|
133
|
+
});
|
|
134
|
+
it('should create a linear progress bar with custom parameters', () => {
|
|
135
|
+
linearProgress = new LinearProgress({
|
|
136
|
+
scene,
|
|
137
|
+
x: 100,
|
|
138
|
+
y: 100,
|
|
139
|
+
width: 300,
|
|
140
|
+
height: 12,
|
|
141
|
+
backgroundColor: 'gray-300',
|
|
142
|
+
progressColor: 'green-500',
|
|
143
|
+
borderRadius: 'lg',
|
|
144
|
+
progress: 50,
|
|
145
|
+
});
|
|
146
|
+
expect(linearProgress).toBeInstanceOf(LinearProgress);
|
|
147
|
+
expect(linearProgress.getProgress()).toBe(50);
|
|
148
|
+
});
|
|
149
|
+
it('should create an indeterminate progress bar', () => {
|
|
150
|
+
linearProgress = new LinearProgress({
|
|
151
|
+
scene,
|
|
152
|
+
x: 100,
|
|
153
|
+
y: 100,
|
|
154
|
+
width: 200,
|
|
155
|
+
height: 8,
|
|
156
|
+
indeterminate: true,
|
|
157
|
+
});
|
|
158
|
+
expect(linearProgress).toBeInstanceOf(LinearProgress);
|
|
159
|
+
expect(scene.tweens.add).toHaveBeenCalled();
|
|
160
|
+
});
|
|
161
|
+
it('should create indeterminate progress bar with correct positioning bounds', () => {
|
|
162
|
+
const width = 300;
|
|
163
|
+
linearProgress = new LinearProgress({
|
|
164
|
+
scene,
|
|
165
|
+
x: 100,
|
|
166
|
+
y: 100,
|
|
167
|
+
width,
|
|
168
|
+
height: 8,
|
|
169
|
+
indeterminate: true,
|
|
170
|
+
});
|
|
171
|
+
// Verify that tween was called with correct positioning
|
|
172
|
+
expect(scene.tweens.add).toHaveBeenCalled();
|
|
173
|
+
const tweenCall = vi.mocked(scene.tweens.add).mock.calls[0]?.[0];
|
|
174
|
+
// The indeterminate bar should move within bounds
|
|
175
|
+
// Bar width is 40% of total width = 120px
|
|
176
|
+
// Max X should be (300/2) - (120/2) = 150 - 60 = 90
|
|
177
|
+
// Min X should be -(300/2) + (120/2) = -150 + 60 = -90
|
|
178
|
+
expect(tweenCall.x).toBe(90); // maxX position
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
describe('setProgress', () => {
|
|
182
|
+
beforeEach(() => {
|
|
183
|
+
linearProgress = new LinearProgress({
|
|
184
|
+
scene,
|
|
185
|
+
x: 100,
|
|
186
|
+
y: 100,
|
|
187
|
+
width: 200,
|
|
188
|
+
height: 8,
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
it('should set progress value within valid range', () => {
|
|
192
|
+
linearProgress.setProgress(75, false);
|
|
193
|
+
expect(linearProgress.getProgress()).toBe(75);
|
|
194
|
+
});
|
|
195
|
+
it('should clamp progress value to 0-100 range', () => {
|
|
196
|
+
linearProgress.setProgress(-10, false);
|
|
197
|
+
expect(linearProgress.getProgress()).toBe(0);
|
|
198
|
+
linearProgress.setProgress(150, false);
|
|
199
|
+
expect(linearProgress.getProgress()).toBe(100);
|
|
200
|
+
});
|
|
201
|
+
it('should animate progress change by default', () => {
|
|
202
|
+
linearProgress.setProgress(50);
|
|
203
|
+
expect(scene.tweens.add).toHaveBeenCalled();
|
|
204
|
+
});
|
|
205
|
+
it('should not change progress for indeterminate progress bar', () => {
|
|
206
|
+
linearProgress.setIndeterminate(true);
|
|
207
|
+
const initialProgress = linearProgress.getProgress();
|
|
208
|
+
linearProgress.setProgress(75);
|
|
209
|
+
expect(linearProgress.getProgress()).toBe(initialProgress);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
describe('setIndeterminate', () => {
|
|
213
|
+
beforeEach(() => {
|
|
214
|
+
linearProgress = new LinearProgress({
|
|
215
|
+
scene,
|
|
216
|
+
x: 100,
|
|
217
|
+
y: 100,
|
|
218
|
+
width: 200,
|
|
219
|
+
height: 8,
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
it('should start indeterminate animation when set to true', () => {
|
|
223
|
+
linearProgress.setIndeterminate(true);
|
|
224
|
+
expect(scene.tweens.add).toHaveBeenCalled();
|
|
225
|
+
});
|
|
226
|
+
it('should stop indeterminate animation when set to false', () => {
|
|
227
|
+
linearProgress.setIndeterminate(true);
|
|
228
|
+
const tweenMock = { destroy: vi.fn() };
|
|
229
|
+
vi.mocked(scene.tweens.add).mockReturnValue(tweenMock);
|
|
230
|
+
linearProgress.setIndeterminate(false);
|
|
231
|
+
// Animation should be stopped when switching back to determinate
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
describe('setBorderRadius', () => {
|
|
235
|
+
beforeEach(() => {
|
|
236
|
+
linearProgress = new LinearProgress({
|
|
237
|
+
scene,
|
|
238
|
+
x: 100,
|
|
239
|
+
y: 100,
|
|
240
|
+
width: 200,
|
|
241
|
+
height: 8,
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
it('should accept numeric border radius', () => {
|
|
245
|
+
expect(() => linearProgress.setBorderRadius(10)).not.toThrow();
|
|
246
|
+
});
|
|
247
|
+
it('should accept string border radius token', () => {
|
|
248
|
+
expect(() => linearProgress.setBorderRadius('lg')).not.toThrow();
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
describe('color setters', () => {
|
|
252
|
+
beforeEach(() => {
|
|
253
|
+
linearProgress = new LinearProgress({
|
|
254
|
+
scene,
|
|
255
|
+
x: 100,
|
|
256
|
+
y: 100,
|
|
257
|
+
width: 200,
|
|
258
|
+
height: 8,
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
it('should set background color', () => {
|
|
262
|
+
expect(() => linearProgress.setBackgroundColor('red-200')).not.toThrow();
|
|
263
|
+
});
|
|
264
|
+
it('should set progress color', () => {
|
|
265
|
+
expect(() => linearProgress.setProgressColor('blue-600')).not.toThrow();
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
describe('destroy', () => {
|
|
269
|
+
beforeEach(() => {
|
|
270
|
+
linearProgress = new LinearProgress({
|
|
271
|
+
scene,
|
|
272
|
+
x: 100,
|
|
273
|
+
y: 100,
|
|
274
|
+
width: 200,
|
|
275
|
+
height: 8,
|
|
276
|
+
indeterminate: true,
|
|
277
|
+
indeterminateAnimationDuration: 1000,
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
it('should clean up animations when destroyed', () => {
|
|
281
|
+
const tweenMock = { destroy: vi.fn() };
|
|
282
|
+
vi.mocked(scene.tweens.add).mockReturnValue(tweenMock);
|
|
283
|
+
linearProgress.destroy();
|
|
284
|
+
// Should clean up any running animations
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
//# sourceMappingURL=linear-progress.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linear-progress.spec.js","sourceRoot":"","sources":["../../../src/components/linear-progress/linear-progress.spec.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,2CAA2C;AAC3C,OAAO,EAAE,KAAK,EAAU,MAAM,Q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AAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,eAAe,CAAC,SAAoC,CAAC,CAAC;YAElF,cAAc,CAAC,OAAO,EAAE,CAAC;YACzB,yCAAyC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/text-button/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/text-button/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { GameObjects, Scene } from 'phaser';
|
|
2
|
+
import { type ColorKey, type FontKey, type FontSizeKey, type RadiusKey, type SpacingKey } from 'phaser-wind';
|
|
3
|
+
export type TextButtonParams = {
|
|
4
|
+
scene: Scene;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
text: string;
|
|
8
|
+
/** Font size in px (number) or a Phaser Wind font size token (string). Defaults to 'md'. */
|
|
9
|
+
textSize?: FontSizeKey | number;
|
|
10
|
+
/** Font family. Defaults to 'sans'. */
|
|
11
|
+
font?: FontKey | string;
|
|
12
|
+
/** Background color. Defaults to 'blue'. */
|
|
13
|
+
backgroundColor?: ColorKey | string;
|
|
14
|
+
/** Text color. Defaults to 'white'. */
|
|
15
|
+
textColor?: ColorKey | string;
|
|
16
|
+
/** Border radius in px (number) or a Phaser Wind radius token (string). Defaults to 'md'. */
|
|
17
|
+
borderRadius?: RadiusKey | number;
|
|
18
|
+
/** Margin/padding in px (number) or a Phaser Wind spacing token (string). Defaults to 'md'. */
|
|
19
|
+
margin?: SpacingKey | number;
|
|
20
|
+
onClick?: () => void;
|
|
21
|
+
};
|
|
22
|
+
export declare class TextButton extends GameObjects.Container {
|
|
23
|
+
backgroundSprite: GameObjects.Sprite;
|
|
24
|
+
shadowSprite: GameObjects.Sprite;
|
|
25
|
+
buttonText: GameObjects.Text;
|
|
26
|
+
private pw;
|
|
27
|
+
private textSizePx;
|
|
28
|
+
private marginPx;
|
|
29
|
+
private borderRadiusPx;
|
|
30
|
+
private backgroundColorValue;
|
|
31
|
+
private textColorValue;
|
|
32
|
+
private fontValue;
|
|
33
|
+
private textValue;
|
|
34
|
+
constructor({ scene, x, y, text, textSize, font, backgroundColor, textColor, borderRadius, margin, onClick, }: TextButtonParams);
|
|
35
|
+
setText(text: string): this;
|
|
36
|
+
setTextSize(textSize: FontSizeKey | number): this;
|
|
37
|
+
setFont(font: FontKey | string): this;
|
|
38
|
+
setBackgroundColor(color: ColorKey | string): this;
|
|
39
|
+
setTextColor(color: ColorKey | string): this;
|
|
40
|
+
setBorderRadius(borderRadius: RadiusKey | number): this;
|
|
41
|
+
setMargin(margin: SpacingKey | number): this;
|
|
42
|
+
private createButtonText;
|
|
43
|
+
private createShadowSprite;
|
|
44
|
+
private createBackgroundSprite;
|
|
45
|
+
private regenerateSprites;
|
|
46
|
+
private getButtonDimensions;
|
|
47
|
+
private createShadowTexture;
|
|
48
|
+
private createBackgroundTexture;
|
|
49
|
+
private setupContainer;
|
|
50
|
+
private setupInteractivity;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=text-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-button.d.ts","sourceRoot":"","sources":["../../../src/components/text-button/text-button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,UAAU,EAChB,MAAM,aAAa,CAAC;AAIrB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,KAAK,CAAC;IAC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AAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI;IAUrC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI;IAMlD,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI;IAM5C,eAAe,CAAC,YAAY,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI;IASvD,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI;IASnD,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,sBAAsB;IAM9B,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,mBAAmB;IA+B3B,OAAO,CAAC,uBAAuB;IAyB/B,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,kBAAkB;CA4C3B"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { GameObjects } from 'phaser';
|
|
2
|
+
import { Color, } from 'phaser-wind';
|
|
3
|
+
import { getPWFromScene } from '../../utils/get-pw-from-scene';
|
|
4
|
+
const durations = {
|
|
5
|
+
click: 100,
|
|
6
|
+
hover: 150,
|
|
7
|
+
};
|
|
8
|
+
const HOVER_SCALE = 1.05;
|
|
9
|
+
const CLICK_OFFSET = 2;
|
|
10
|
+
const SHADOW_OFFSET = 4;
|
|
11
|
+
const SHADOW_OPACITY = 0.15;
|
|
12
|
+
export class TextButton extends GameObjects.Container {
|
|
13
|
+
backgroundSprite;
|
|
14
|
+
shadowSprite;
|
|
15
|
+
buttonText;
|
|
16
|
+
pw;
|
|
17
|
+
textSizePx;
|
|
18
|
+
marginPx;
|
|
19
|
+
borderRadiusPx;
|
|
20
|
+
backgroundColorValue;
|
|
21
|
+
textColorValue;
|
|
22
|
+
fontValue;
|
|
23
|
+
textValue;
|
|
24
|
+
constructor({ scene, x, y, text, textSize, font, backgroundColor = 'blue', textColor = 'white', borderRadius = 'md', margin = '4', onClick, }) {
|
|
25
|
+
super(scene, x, y);
|
|
26
|
+
this.pw = getPWFromScene(scene);
|
|
27
|
+
// Store values
|
|
28
|
+
this.textValue = text;
|
|
29
|
+
this.textSizePx =
|
|
30
|
+
typeof textSize === 'number'
|
|
31
|
+
? textSize
|
|
32
|
+
: this.pw.fontSize.px(textSize ?? 'md');
|
|
33
|
+
this.marginPx =
|
|
34
|
+
typeof margin === 'number'
|
|
35
|
+
? margin
|
|
36
|
+
: this.pw.spacing.px(margin ?? '4');
|
|
37
|
+
this.borderRadiusPx =
|
|
38
|
+
typeof borderRadius === 'number'
|
|
39
|
+
? borderRadius
|
|
40
|
+
: this.pw.radius.px(borderRadius ?? 'md');
|
|
41
|
+
this.backgroundColorValue = Color.rgb(backgroundColor);
|
|
42
|
+
this.textColorValue = Color.rgb(textColor);
|
|
43
|
+
this.fontValue =
|
|
44
|
+
typeof font === 'string'
|
|
45
|
+
? font
|
|
46
|
+
: this.pw.font.family(font ?? 'primary');
|
|
47
|
+
this.createButtonText(scene);
|
|
48
|
+
this.createShadowSprite(scene);
|
|
49
|
+
this.createBackgroundSprite(scene);
|
|
50
|
+
this.setupContainer();
|
|
51
|
+
this.setupInteractivity(onClick);
|
|
52
|
+
}
|
|
53
|
+
// API Methods
|
|
54
|
+
setText(text) {
|
|
55
|
+
this.textValue = text;
|
|
56
|
+
this.buttonText.setText(text);
|
|
57
|
+
this.regenerateSprites();
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
setTextSize(textSize) {
|
|
61
|
+
this.textSizePx =
|
|
62
|
+
typeof textSize === 'number'
|
|
63
|
+
? textSize
|
|
64
|
+
: this.pw.fontSize.px(textSize ?? 'md');
|
|
65
|
+
this.buttonText.setFontSize(this.textSizePx);
|
|
66
|
+
this.regenerateSprites();
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
setFont(font) {
|
|
70
|
+
this.fontValue =
|
|
71
|
+
typeof font === 'string'
|
|
72
|
+
? font
|
|
73
|
+
: this.pw.font.family(font ?? 'primary');
|
|
74
|
+
this.buttonText.setFontFamily(this.fontValue);
|
|
75
|
+
this.regenerateSprites();
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
setBackgroundColor(color) {
|
|
79
|
+
this.backgroundColorValue = Color.rgb(color);
|
|
80
|
+
this.regenerateSprites();
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
setTextColor(color) {
|
|
84
|
+
this.textColorValue = Color.rgb(color);
|
|
85
|
+
this.buttonText.setColor(this.textColorValue);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
setBorderRadius(borderRadius) {
|
|
89
|
+
this.borderRadiusPx =
|
|
90
|
+
typeof borderRadius === 'number'
|
|
91
|
+
? borderRadius
|
|
92
|
+
: this.pw.radius.px(borderRadius ?? 'md');
|
|
93
|
+
this.regenerateSprites();
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
setMargin(margin) {
|
|
97
|
+
this.marginPx =
|
|
98
|
+
typeof margin === 'number'
|
|
99
|
+
? margin
|
|
100
|
+
: this.pw.spacing.px(margin ?? '4');
|
|
101
|
+
this.regenerateSprites();
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
createButtonText(scene) {
|
|
105
|
+
this.buttonText = scene.add.text(0, 0, this.textValue, {
|
|
106
|
+
fontSize: `${this.textSizePx}px`,
|
|
107
|
+
fontFamily: this.fontValue,
|
|
108
|
+
color: this.textColorValue,
|
|
109
|
+
});
|
|
110
|
+
this.buttonText.setOrigin(0.5, 0.5);
|
|
111
|
+
}
|
|
112
|
+
createShadowSprite(scene) {
|
|
113
|
+
const shadowTexture = this.createShadowTexture(scene);
|
|
114
|
+
this.shadowSprite = scene.add.sprite(0, SHADOW_OFFSET, shadowTexture);
|
|
115
|
+
this.shadowSprite.setOrigin(0.5, 0.5);
|
|
116
|
+
}
|
|
117
|
+
createBackgroundSprite(scene) {
|
|
118
|
+
const backgroundTexture = this.createBackgroundTexture(scene);
|
|
119
|
+
this.backgroundSprite = scene.add.sprite(0, 0, backgroundTexture);
|
|
120
|
+
this.backgroundSprite.setOrigin(0.5, 0.5);
|
|
121
|
+
}
|
|
122
|
+
regenerateSprites() {
|
|
123
|
+
// Update text bounds after text/font changes
|
|
124
|
+
this.buttonText.setText(this.textValue);
|
|
125
|
+
// Regenerate textures
|
|
126
|
+
const shadowTexture = this.createShadowTexture(this.scene);
|
|
127
|
+
const backgroundTexture = this.createBackgroundTexture(this.scene);
|
|
128
|
+
this.shadowSprite.setTexture(shadowTexture);
|
|
129
|
+
this.backgroundSprite.setTexture(backgroundTexture);
|
|
130
|
+
}
|
|
131
|
+
getButtonDimensions() {
|
|
132
|
+
const textBounds = this.buttonText.getBounds();
|
|
133
|
+
const width = textBounds.width + this.marginPx * 2;
|
|
134
|
+
const height = textBounds.height + this.marginPx * 2;
|
|
135
|
+
return { width, height };
|
|
136
|
+
}
|
|
137
|
+
createShadowTexture(scene) {
|
|
138
|
+
const { width, height } = this.getButtonDimensions();
|
|
139
|
+
const textureKey = `textButton_shadow_${this.backgroundColorValue}_${this.borderRadiusPx}_${width}_${height}`;
|
|
140
|
+
// Add some padding for shadow
|
|
141
|
+
const shadowPadding = 8;
|
|
142
|
+
const textureWidth = width + shadowPadding * 2;
|
|
143
|
+
const textureHeight = height + shadowPadding * 2;
|
|
144
|
+
const graphics = scene.add.graphics();
|
|
145
|
+
// Limit radius to maximum possible for the button dimensions
|
|
146
|
+
const maxRadius = Math.min(width / 2, height / 2);
|
|
147
|
+
const effectiveRadius = Math.min(this.borderRadiusPx, maxRadius);
|
|
148
|
+
// Shadow
|
|
149
|
+
graphics.fillStyle(Color.hex('black'), SHADOW_OPACITY);
|
|
150
|
+
graphics.fillRoundedRect(shadowPadding, shadowPadding + SHADOW_OFFSET, width, height, effectiveRadius);
|
|
151
|
+
graphics.generateTexture(textureKey, textureWidth, textureHeight);
|
|
152
|
+
graphics.destroy();
|
|
153
|
+
return textureKey;
|
|
154
|
+
}
|
|
155
|
+
createBackgroundTexture(scene) {
|
|
156
|
+
const { width, height } = this.getButtonDimensions();
|
|
157
|
+
const textureKey = `textButton_bg_${this.backgroundColorValue}_${this.borderRadiusPx}_${width}_${height}`;
|
|
158
|
+
// Add some padding for texture
|
|
159
|
+
const padding = 8;
|
|
160
|
+
const textureWidth = width + padding * 2;
|
|
161
|
+
const textureHeight = height + padding * 2;
|
|
162
|
+
const graphics = scene.add.graphics();
|
|
163
|
+
// Limit radius to maximum possible for the button dimensions
|
|
164
|
+
const maxRadius = Math.min(width / 2, height / 2);
|
|
165
|
+
const effectiveRadius = Math.min(this.borderRadiusPx, maxRadius);
|
|
166
|
+
// Main background
|
|
167
|
+
graphics.fillStyle(Color.hex(this.backgroundColorValue), 1);
|
|
168
|
+
graphics.fillRoundedRect(padding, padding, width, height, effectiveRadius);
|
|
169
|
+
graphics.generateTexture(textureKey, textureWidth, textureHeight);
|
|
170
|
+
graphics.destroy();
|
|
171
|
+
return textureKey;
|
|
172
|
+
}
|
|
173
|
+
setupContainer() {
|
|
174
|
+
this.add([this.shadowSprite, this.backgroundSprite, this.buttonText]);
|
|
175
|
+
}
|
|
176
|
+
setupInteractivity(onClick) {
|
|
177
|
+
this.backgroundSprite.setInteractive({ useHandCursor: true });
|
|
178
|
+
// Hover effects
|
|
179
|
+
this.backgroundSprite.on('pointerover', () => {
|
|
180
|
+
this.scene.tweens.add({
|
|
181
|
+
targets: this,
|
|
182
|
+
scaleX: HOVER_SCALE,
|
|
183
|
+
scaleY: HOVER_SCALE,
|
|
184
|
+
duration: durations.hover,
|
|
185
|
+
ease: 'Back.easeOut',
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
this.backgroundSprite.on('pointerout', () => {
|
|
189
|
+
this.scene.tweens.add({
|
|
190
|
+
targets: this,
|
|
191
|
+
scaleX: 1,
|
|
192
|
+
scaleY: 1,
|
|
193
|
+
duration: durations.hover,
|
|
194
|
+
ease: 'Back.easeOut',
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
// Click effects
|
|
198
|
+
this.backgroundSprite.on('pointerdown', () => {
|
|
199
|
+
this.scene.tweens.add({
|
|
200
|
+
targets: [this.backgroundSprite, this.buttonText],
|
|
201
|
+
y: CLICK_OFFSET,
|
|
202
|
+
duration: durations.click,
|
|
203
|
+
ease: 'Linear',
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
this.backgroundSprite.on('pointerup', () => {
|
|
207
|
+
this.scene.tweens.add({
|
|
208
|
+
targets: [this.backgroundSprite, this.buttonText],
|
|
209
|
+
y: 0,
|
|
210
|
+
duration: durations.click,
|
|
211
|
+
ease: 'Linear',
|
|
212
|
+
});
|
|
213
|
+
onClick?.();
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=text-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-button.js","sourceRoot":"","sources":["../../../src/components/text-button/text-button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAS,MAAM,QAAQ,CAAC;AAC5C,OAAO,EACL,KAAK,GAON,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAsB/D,MAAM,SAAS,GAAG;IAChB,KAAK,EAAE,GAAG;IACV,KAAK,EAAE,GAAG;CACX,CAAC;AAEF,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B,MAAM,OAAO,UAAW,SAAQ,WAAW,CAAC,SAAS;IAC5C,gBAAgB,CAAsB;IACtC,YAAY,CAAsB;IAClC,UAAU,CAAoB;IAE7B,EAAE,CAAuB;IACzB,UAAU,CAAU;IACpB,QAAQ,CAAU;IAClB,cAAc,CAAU;IACxB,oBAAoB,CAAU;IAC9B,cAAc,CAAU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SAAS,CAAC,KAAK;gBACzB,IAAI,EAAE,QAAQ;aACf,CAAC,CAAC;YACH,OAAO,EAAE,EAAE,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-button.spec.d.ts","sourceRoot":"","sources":["../../../src/components/text-button/text-button.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/* eslint-disable sonarjs/no-duplicate-string */
|
|
2
|
+
/* eslint-disable max-lines-per-function */
|
|
3
|
+
/* eslint-disable no-magic-numbers */
|
|
4
|
+
import { Scene } from 'phaser';
|
|
5
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
6
|
+
// Mock phaser-wind
|
|
7
|
+
vi.mock('phaser-wind', () => ({
|
|
8
|
+
Color: {
|
|
9
|
+
rgb: vi.fn((color) => `rgb-${color}`),
|
|
10
|
+
hex: vi.fn((color) => `hex-${color}`),
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
13
|
+
// Mock the getPWFromScene utility
|
|
14
|
+
vi.mock('../../utils/get-pw-from-scene', () => ({
|
|
15
|
+
getPWFromScene: vi.fn(() => ({
|
|
16
|
+
fontSize: {
|
|
17
|
+
px: vi.fn((size) => {
|
|
18
|
+
const sizes = { xs: 12, sm: 14, md: 16, lg: 18, xl: 20 };
|
|
19
|
+
return sizes[size] || 16;
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
spacing: {
|
|
23
|
+
px: vi.fn((spacing) => {
|
|
24
|
+
const spacings = { xs: 4, sm: 8, md: 12, lg: 16, xl: 20 };
|
|
25
|
+
return spacings[spacing] || 12;
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
radius: {
|
|
29
|
+
px: vi.fn((radius) => {
|
|
30
|
+
const radiuses = { none: 0, sm: 4, md: 8, lg: 12, xl: 16, full: 9999 };
|
|
31
|
+
return radiuses[radius] || 8;
|
|
32
|
+
}),
|
|
33
|
+
},
|
|
34
|
+
font: {
|
|
35
|
+
family: vi.fn((font) => {
|
|
36
|
+
const fonts = {
|
|
37
|
+
sans: 'Arial, sans-serif',
|
|
38
|
+
serif: 'Georgia, serif',
|
|
39
|
+
mono: 'Courier, monospace',
|
|
40
|
+
};
|
|
41
|
+
return fonts[font] || 'Arial, sans-serif';
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
})),
|
|
45
|
+
}));
|
|
46
|
+
// Mock Phaser
|
|
47
|
+
vi.mock('phaser', () => {
|
|
48
|
+
class MockText {
|
|
49
|
+
text;
|
|
50
|
+
style;
|
|
51
|
+
constructor(_x, _y, text, style) {
|
|
52
|
+
this.text = text;
|
|
53
|
+
this.style = style;
|
|
54
|
+
}
|
|
55
|
+
setText(text) {
|
|
56
|
+
this.text = text;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
setOrigin() {
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
setFontSize(size) {
|
|
63
|
+
this.style['fontSize'] = size;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
setFontFamily(family) {
|
|
67
|
+
this.style['fontFamily'] = family;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
setColor(color) {
|
|
71
|
+
this.style['color'] = color;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
getBounds() {
|
|
75
|
+
const charWidth = 10;
|
|
76
|
+
const lineHeight = parseInt(this.style['fontSize']) || 16;
|
|
77
|
+
return {
|
|
78
|
+
width: this.text.length * charWidth,
|
|
79
|
+
height: lineHeight,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
class MockSprite {
|
|
84
|
+
// eslint-disable-next-line no-unused-vars
|
|
85
|
+
constructor(_x, _y, _texture) { }
|
|
86
|
+
setOrigin() {
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
setInteractive() {
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
setTexture() {
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
on() {
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
class MockGraphics {
|
|
100
|
+
fillStyle() {
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
fillRoundedRect() {
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
generateTexture() {
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
destroy() {
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
class MockContainer {
|
|
114
|
+
// eslint-disable-next-line no-unused-vars
|
|
115
|
+
constructor(_scene, _x, _y) {
|
|
116
|
+
this.scene = _scene;
|
|
117
|
+
}
|
|
118
|
+
add() {
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
scene;
|
|
122
|
+
}
|
|
123
|
+
class Scene {
|
|
124
|
+
add = {
|
|
125
|
+
text: vi.fn((x, y, text, style) => new MockText(x, y, text, style)),
|
|
126
|
+
sprite: vi.fn((x, y, texture) => new MockSprite(x, y, texture)),
|
|
127
|
+
graphics: vi.fn(() => new MockGraphics()),
|
|
128
|
+
};
|
|
129
|
+
tweens = { add: vi.fn() };
|
|
130
|
+
}
|
|
131
|
+
class BasePlugin {
|
|
132
|
+
constructor() { }
|
|
133
|
+
}
|
|
134
|
+
const GameObjects = { Container: MockContainer };
|
|
135
|
+
const Plugins = { BasePlugin };
|
|
136
|
+
return { GameObjects, Scene, Plugins };
|
|
137
|
+
});
|
|
138
|
+
import { TextButton } from './text-button';
|
|
139
|
+
describe('TextButton', () => {
|
|
140
|
+
it('should create a TextButton instance', () => {
|
|
141
|
+
const scene = new Scene();
|
|
142
|
+
const textButton = new TextButton({
|
|
143
|
+
scene,
|
|
144
|
+
x: 100,
|
|
145
|
+
y: 100,
|
|
146
|
+
text: 'Click Me',
|
|
147
|
+
});
|
|
148
|
+
expect(textButton).toBeInstanceOf(TextButton);
|
|
149
|
+
});
|
|
150
|
+
it('should create with custom properties', () => {
|
|
151
|
+
const scene = new Scene();
|
|
152
|
+
const textButton = new TextButton({
|
|
153
|
+
scene,
|
|
154
|
+
x: 100,
|
|
155
|
+
y: 100,
|
|
156
|
+
text: 'Custom Button',
|
|
157
|
+
textSize: 'lg',
|
|
158
|
+
backgroundColor: 'red',
|
|
159
|
+
textColor: 'white',
|
|
160
|
+
borderRadius: 'lg',
|
|
161
|
+
margin: '4',
|
|
162
|
+
});
|
|
163
|
+
expect(textButton).toBeInstanceOf(TextButton);
|
|
164
|
+
});
|
|
165
|
+
it('should support method chaining', () => {
|
|
166
|
+
const scene = new Scene();
|
|
167
|
+
const textButton = new TextButton({
|
|
168
|
+
scene,
|
|
169
|
+
x: 100,
|
|
170
|
+
y: 100,
|
|
171
|
+
text: 'Test',
|
|
172
|
+
});
|
|
173
|
+
const result = textButton
|
|
174
|
+
.setText('Chained')
|
|
175
|
+
.setTextSize('lg')
|
|
176
|
+
.setBackgroundColor('green')
|
|
177
|
+
.setBorderRadius('lg')
|
|
178
|
+
.setMargin('4');
|
|
179
|
+
expect(result).toBe(textButton);
|
|
180
|
+
});
|
|
181
|
+
it('should handle borderRadius full correctly', () => {
|
|
182
|
+
const scene = new Scene();
|
|
183
|
+
const textButton = new TextButton({
|
|
184
|
+
scene,
|
|
185
|
+
x: 100,
|
|
186
|
+
y: 100,
|
|
187
|
+
text: 'Full Radius Test',
|
|
188
|
+
borderRadius: 'full',
|
|
189
|
+
});
|
|
190
|
+
expect(textButton).toBeInstanceOf(TextButton);
|
|
191
|
+
// Test setBorderRadius with 'full'
|
|
192
|
+
const result = textButton.setBorderRadius('full');
|
|
193
|
+
expect(result).toBe(textButton);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
//# sourceMappingURL=text-button.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-button.spec.js","sourceRoot":"","sources":["../../../src/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