@vforsh/phaser-dev-ui 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +198 -0
  2. package/dist/DebugBadge.d.ts +62 -0
  3. package/dist/DebugBadge.d.ts.map +1 -0
  4. package/dist/DebugBadge.js +206 -0
  5. package/dist/DebugBadge.js.map +1 -0
  6. package/dist/DebugButton.d.ts +94 -0
  7. package/dist/DebugButton.d.ts.map +1 -0
  8. package/dist/DebugButton.js +311 -0
  9. package/dist/DebugButton.js.map +1 -0
  10. package/dist/DebugColumnContainer.d.ts +38 -0
  11. package/dist/DebugColumnContainer.d.ts.map +1 -0
  12. package/dist/DebugColumnContainer.js +69 -0
  13. package/dist/DebugColumnContainer.js.map +1 -0
  14. package/dist/DebugGridContainer.d.ts +44 -0
  15. package/dist/DebugGridContainer.d.ts.map +1 -0
  16. package/dist/DebugGridContainer.js +64 -0
  17. package/dist/DebugGridContainer.js.map +1 -0
  18. package/dist/DebugLabel.d.ts +33 -0
  19. package/dist/DebugLabel.d.ts.map +1 -0
  20. package/dist/DebugLabel.js +37 -0
  21. package/dist/DebugLabel.js.map +1 -0
  22. package/dist/DebugPanel.d.ts +67 -0
  23. package/dist/DebugPanel.d.ts.map +1 -0
  24. package/dist/DebugPanel.js +138 -0
  25. package/dist/DebugPanel.js.map +1 -0
  26. package/dist/DebugProgressBar.d.ts +47 -0
  27. package/dist/DebugProgressBar.d.ts.map +1 -0
  28. package/dist/DebugProgressBar.js +129 -0
  29. package/dist/DebugProgressBar.js.map +1 -0
  30. package/dist/DebugRowContainer.d.ts +40 -0
  31. package/dist/DebugRowContainer.d.ts.map +1 -0
  32. package/dist/DebugRowContainer.js +91 -0
  33. package/dist/DebugRowContainer.js.map +1 -0
  34. package/dist/DebugScrollContainer.d.ts +138 -0
  35. package/dist/DebugScrollContainer.d.ts.map +1 -0
  36. package/dist/DebugScrollContainer.js +413 -0
  37. package/dist/DebugScrollContainer.js.map +1 -0
  38. package/dist/DebugSwitchButton.d.ts +111 -0
  39. package/dist/DebugSwitchButton.d.ts.map +1 -0
  40. package/dist/DebugSwitchButton.js +317 -0
  41. package/dist/DebugSwitchButton.js.map +1 -0
  42. package/dist/index.d.ts +23 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +20 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/types.d.ts +37 -0
  47. package/dist/types.d.ts.map +1 -0
  48. package/dist/types.js +2 -0
  49. package/dist/types.js.map +1 -0
  50. package/dist/utils.d.ts +31 -0
  51. package/dist/utils.d.ts.map +1 -0
  52. package/dist/utils.js +62 -0
  53. package/dist/utils.js.map +1 -0
  54. package/package.json +44 -0
@@ -0,0 +1,111 @@
1
+ import type { HexColor, Position, Size } from "./types.js";
2
+ export interface SwitchButtonOption<K extends string | number = string> {
3
+ key: K;
4
+ value: string;
5
+ }
6
+ export type SwitchOptions<K extends string | number = string> = Array<SwitchButtonOption<K>>;
7
+ export interface CreateDebugSwitchButtonOptions<K extends string | number = string> {
8
+ /** Array of switch options with key-value pairs. */
9
+ options: SwitchOptions<K>;
10
+ /** Initial selected option index (default: 0). */
11
+ optionInitialIndex?: number;
12
+ /** Wrap around at ends (default: true). */
13
+ optionsWrap?: boolean;
14
+ /** Size (default: 200×40). */
15
+ size?: Size;
16
+ /** Background color (default: "#ffffff"). */
17
+ bgColor?: HexColor;
18
+ /** Stroke color (default: "#000000"). */
19
+ strokeColor?: HexColor;
20
+ /** Stroke thickness (default: 1). */
21
+ strokeThickness?: number;
22
+ /** Text color (default: "#000000"). */
23
+ textColor?: HexColor;
24
+ /** Arrow color (default: "#ffffff"). */
25
+ arrowColor?: HexColor;
26
+ /** Arrow size in px (default: auto from height). */
27
+ arrowSize?: number;
28
+ /** Arrow margin from edges (default: 10). */
29
+ arrowMargin?: number;
30
+ /** Font size in px (default: 16). */
31
+ fontSize?: number;
32
+ /** Font family (default: "Verdana"). */
33
+ fontFamily?: string;
34
+ /** Enabled (default: true). */
35
+ enabled?: boolean;
36
+ /** Position (optional). */
37
+ position?: Position;
38
+ }
39
+ /**
40
+ * A cycling switch button for debug HUD.
41
+ *
42
+ * Displays a list of key-value options with left/right arrow navigation.
43
+ * Supports wrap-around, enabled/disabled states, and emits "option-changed" events.
44
+ * Chainable API.
45
+ */
46
+ export declare class DebugSwitchButton<K extends string | number = string> extends Phaser.GameObjects.Container {
47
+ private _bg;
48
+ private _label;
49
+ private _leftArrow;
50
+ private _rightArrow;
51
+ private _leftZone;
52
+ private _rightZone;
53
+ private _options;
54
+ private _currentIndex;
55
+ private _optionsWrap;
56
+ private _isEnabled;
57
+ private _panelWidth;
58
+ private _panelHeight;
59
+ private _cornerRadius;
60
+ private _bgColor;
61
+ private _strokeColor;
62
+ private _strokeThickness;
63
+ private _textColor;
64
+ private _arrowColor;
65
+ private _arrowSize;
66
+ private _arrowMargin;
67
+ private _fontSize;
68
+ private _fontFamily;
69
+ constructor(scene: Phaser.Scene, options: CreateDebugSwitchButtonOptions<K>);
70
+ nextOption(): this;
71
+ previousOption(): this;
72
+ setOptionIndex(index: number): this;
73
+ setOptionByKey(key: K): this;
74
+ getCurrentOption(): SwitchButtonOption<K> | null;
75
+ getCurrentIndex(): number;
76
+ getOptions(): SwitchOptions<K>;
77
+ setOptions(options: SwitchOptions<K>): this;
78
+ setEnabled(enabled: boolean): this;
79
+ isEnabled(): boolean;
80
+ setOptionsWrap(wrap: boolean): this;
81
+ setBgColor(color: HexColor): this;
82
+ setTextColor(color: HexColor): this;
83
+ setArrowColor(color: HexColor): this;
84
+ setSwitchSize(width: number, height: number): this;
85
+ setFontSize(size: number): this;
86
+ setFontFamily(family: string): this;
87
+ setStyle(options: {
88
+ size?: Size;
89
+ bgColor?: HexColor;
90
+ strokeColor?: HexColor;
91
+ strokeThickness?: number;
92
+ textColor?: HexColor;
93
+ arrowColor?: HexColor;
94
+ arrowSize?: number;
95
+ arrowMargin?: number;
96
+ fontSize?: number;
97
+ fontFamily?: string;
98
+ }): this;
99
+ /** Listen for option changes. */
100
+ onOptionChanged(handler: (option: SwitchButtonOption<K>, index: number, prevOption: SwitchButtonOption<K> | null, prevIndex: number) => void): this;
101
+ private redraw;
102
+ private redrawBg;
103
+ private redrawArrows;
104
+ private positionArrows;
105
+ private updateDisplay;
106
+ private updateArrowStates;
107
+ private updateEnabledVisuals;
108
+ private emitChanged;
109
+ }
110
+ export declare function createDebugSwitchButton<K extends string | number = string>(scene: Phaser.Scene, options: CreateDebugSwitchButtonOptions<K>): DebugSwitchButton<K>;
111
+ //# sourceMappingURL=DebugSwitchButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DebugSwitchButton.d.ts","sourceRoot":"","sources":["../src/DebugSwitchButton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAG1D,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM;IACrE,GAAG,EAAE,CAAC,CAAA;IACN,KAAK,EAAE,MAAM,CAAA;CACb;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAA;AAE5F,MAAM,WAAW,8BAA8B,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM;IACjF,oDAAoD;IACpD,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;IACzB,kDAAkD;IAClD,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,2CAA2C;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,8BAA8B;IAC9B,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,6CAA6C;IAC7C,OAAO,CAAC,EAAE,QAAQ,CAAA;IAClB,yCAAyC;IACzC,WAAW,CAAC,EAAE,QAAQ,C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CAAA;QAClB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,UAAU,CAAC,EAAE,MAAM,CAAA;KACnB,GAAG,IAAI;IAeR,iCAAiC;IACjC,eAAe,CACd,OAAO,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,GAC1H,IAAI;IAOP,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,QAAQ;IAgBhB,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,oBAAoB;IAM5B,OAAO,CAAC,WAAW;CAOnB;AAED,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EACzE,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,OAAO,EAAE,8BAA8B,CAAC,CAAC,CAAC,GACxC,iBAAiB,CAAC,CAAC,CAAC,CAEtB"}
@@ -0,0 +1,317 @@
1
+ import { getDevicePixelRatio, hexToColorAlpha } from "./utils.js";
2
+ /**
3
+ * A cycling switch button for debug HUD.
4
+ *
5
+ * Displays a list of key-value options with left/right arrow navigation.
6
+ * Supports wrap-around, enabled/disabled states, and emits "option-changed" events.
7
+ * Chainable API.
8
+ */
9
+ export class DebugSwitchButton extends Phaser.GameObjects.Container {
10
+ _bg;
11
+ _label;
12
+ _leftArrow;
13
+ _rightArrow;
14
+ _leftZone;
15
+ _rightZone;
16
+ _options = [];
17
+ _currentIndex = 0;
18
+ _optionsWrap = true;
19
+ _isEnabled = true;
20
+ _panelWidth;
21
+ _panelHeight;
22
+ _cornerRadius = 6;
23
+ _bgColor;
24
+ _strokeColor;
25
+ _strokeThickness;
26
+ _textColor;
27
+ _arrowColor;
28
+ _arrowSize;
29
+ _arrowMargin;
30
+ _fontSize;
31
+ _fontFamily;
32
+ constructor(scene, options) {
33
+ const { options: switchOptions, optionInitialIndex = 0, optionsWrap = true, size = { width: 200, height: 40 }, bgColor = "#ffffff", strokeColor = "#000000", strokeThickness = 1, textColor = "#000000", arrowColor = "#ffffff", arrowSize, arrowMargin = 10, fontSize = 16, fontFamily = "Verdana", enabled = true, position, } = options;
34
+ super(scene, position?.x ?? 0, position?.y ?? 0);
35
+ this._panelWidth = size.width;
36
+ this._panelHeight = size.height;
37
+ this._bgColor = bgColor;
38
+ this._strokeColor = strokeColor;
39
+ this._strokeThickness = strokeThickness;
40
+ this._textColor = textColor;
41
+ this._arrowColor = arrowColor;
42
+ this._arrowSize = arrowSize ?? Math.min(20, size.height * 0.5);
43
+ this._arrowMargin = arrowMargin;
44
+ this._fontSize = fontSize;
45
+ this._fontFamily = fontFamily;
46
+ this._options = switchOptions;
47
+ this._currentIndex = Math.max(0, Math.min(optionInitialIndex, switchOptions.length - 1));
48
+ this._optionsWrap = optionsWrap;
49
+ this._isEnabled = enabled;
50
+ this.setSize(size.width, size.height);
51
+ // Panel bg
52
+ this._bg = scene.add.graphics();
53
+ // Label
54
+ const tc = hexToColorAlpha(textColor);
55
+ this._label = scene.add.text(0, 0, "", {
56
+ fontFamily: fontFamily,
57
+ fontSize: `${fontSize}px`,
58
+ fontStyle: "normal",
59
+ color: `#${tc.color.toString(16).padStart(6, "0")}`,
60
+ align: "center",
61
+ resolution: getDevicePixelRatio(),
62
+ });
63
+ this._label.setOrigin(0.5, 0.5);
64
+ // Arrows
65
+ this._leftArrow = scene.add.graphics();
66
+ this._rightArrow = scene.add.graphics();
67
+ // Hit zones for arrows
68
+ const zoneSize = this._arrowSize + this._arrowMargin;
69
+ this._leftZone = scene.add.zone(0, 0, zoneSize, this._panelHeight).setInteractive({ useHandCursor: true });
70
+ this._rightZone = scene.add.zone(0, 0, zoneSize, this._panelHeight).setInteractive({ useHandCursor: true });
71
+ this.add([this._bg, this._label, this._leftArrow, this._rightArrow, this._leftZone, this._rightZone]);
72
+ this._leftZone.on("pointerup", () => {
73
+ if (this._isEnabled)
74
+ this.previousOption();
75
+ });
76
+ this._rightZone.on("pointerup", () => {
77
+ if (this._isEnabled)
78
+ this.nextOption();
79
+ });
80
+ this.redraw();
81
+ this.updateDisplay();
82
+ this.updateArrowStates();
83
+ this.updateEnabledVisuals();
84
+ scene.add.existing(this);
85
+ }
86
+ // -- Navigation --
87
+ nextOption() {
88
+ if (this._options.length === 0)
89
+ return this;
90
+ const prevIdx = this._currentIndex;
91
+ const next = this._currentIndex + 1;
92
+ if (next >= this._options.length) {
93
+ if (this._optionsWrap)
94
+ this._currentIndex = 0;
95
+ else
96
+ return this;
97
+ }
98
+ else {
99
+ this._currentIndex = next;
100
+ }
101
+ this.updateDisplay();
102
+ this.updateArrowStates();
103
+ this.emitChanged(prevIdx);
104
+ return this;
105
+ }
106
+ previousOption() {
107
+ if (this._options.length === 0)
108
+ return this;
109
+ const prevIdx = this._currentIndex;
110
+ const next = this._currentIndex - 1;
111
+ if (next < 0) {
112
+ if (this._optionsWrap)
113
+ this._currentIndex = this._options.length - 1;
114
+ else
115
+ return this;
116
+ }
117
+ else {
118
+ this._currentIndex = next;
119
+ }
120
+ this.updateDisplay();
121
+ this.updateArrowStates();
122
+ this.emitChanged(prevIdx);
123
+ return this;
124
+ }
125
+ setOptionIndex(index) {
126
+ if (index < 0 || index >= this._options.length)
127
+ return this;
128
+ const prevIdx = this._currentIndex;
129
+ this._currentIndex = index;
130
+ this.updateDisplay();
131
+ this.updateArrowStates();
132
+ this.emitChanged(prevIdx);
133
+ return this;
134
+ }
135
+ setOptionByKey(key) {
136
+ const idx = this._options.findIndex((o) => o.key === key);
137
+ if (idx !== -1)
138
+ this.setOptionIndex(idx);
139
+ return this;
140
+ }
141
+ getCurrentOption() {
142
+ return this._options[this._currentIndex] ?? null;
143
+ }
144
+ getCurrentIndex() {
145
+ return this._currentIndex;
146
+ }
147
+ getOptions() {
148
+ return [...this._options];
149
+ }
150
+ setOptions(options) {
151
+ const prev = this.getCurrentOption();
152
+ this._options = [...options];
153
+ let newIdx = 0;
154
+ if (prev) {
155
+ const found = options.findIndex((o) => o.key === prev.key);
156
+ if (found !== -1)
157
+ newIdx = found;
158
+ }
159
+ this._currentIndex = Math.min(newIdx, this._options.length - 1);
160
+ this.updateDisplay();
161
+ this.updateArrowStates();
162
+ return this;
163
+ }
164
+ // -- Setters --
165
+ setEnabled(enabled) {
166
+ if (this._isEnabled === enabled)
167
+ return this;
168
+ this._isEnabled = enabled;
169
+ this.updateEnabledVisuals();
170
+ this.updateArrowStates();
171
+ return this;
172
+ }
173
+ isEnabled() {
174
+ return this._isEnabled;
175
+ }
176
+ setOptionsWrap(wrap) {
177
+ this._optionsWrap = wrap;
178
+ this.updateArrowStates();
179
+ return this;
180
+ }
181
+ setBgColor(color) {
182
+ this._bgColor = color;
183
+ this.redrawBg();
184
+ return this;
185
+ }
186
+ setTextColor(color) {
187
+ this._textColor = color;
188
+ const c = hexToColorAlpha(color);
189
+ this._label.setColor(`#${c.color.toString(16).padStart(6, "0")}`);
190
+ return this;
191
+ }
192
+ setArrowColor(color) {
193
+ this._arrowColor = color;
194
+ this.redrawArrows();
195
+ return this;
196
+ }
197
+ setSwitchSize(width, height) {
198
+ this._panelWidth = width;
199
+ this._panelHeight = height;
200
+ this.setSize(width, height);
201
+ this._arrowSize = Math.min(this._arrowSize, height * 0.5);
202
+ this.redraw();
203
+ return this;
204
+ }
205
+ setFontSize(size) {
206
+ this._fontSize = size;
207
+ this._label.setFontSize(`${size}px`);
208
+ return this;
209
+ }
210
+ setFontFamily(family) {
211
+ this._fontFamily = family;
212
+ this._label.setFontFamily(family);
213
+ return this;
214
+ }
215
+ setStyle(options) {
216
+ if (options.size)
217
+ this.setSwitchSize(options.size.width, options.size.height);
218
+ if (options.bgColor)
219
+ this._bgColor = options.bgColor;
220
+ if (options.strokeColor)
221
+ this._strokeColor = options.strokeColor;
222
+ if (options.strokeThickness !== undefined)
223
+ this._strokeThickness = options.strokeThickness;
224
+ if (options.textColor)
225
+ this.setTextColor(options.textColor);
226
+ if (options.arrowColor)
227
+ this._arrowColor = options.arrowColor;
228
+ if (options.arrowSize !== undefined)
229
+ this._arrowSize = options.arrowSize;
230
+ if (options.arrowMargin !== undefined)
231
+ this._arrowMargin = options.arrowMargin;
232
+ if (options.fontSize !== undefined)
233
+ this.setFontSize(options.fontSize);
234
+ if (options.fontFamily)
235
+ this.setFontFamily(options.fontFamily);
236
+ this.redraw();
237
+ return this;
238
+ }
239
+ /** Listen for option changes. */
240
+ onOptionChanged(handler) {
241
+ this.on("option-changed", handler);
242
+ return this;
243
+ }
244
+ // -- Internal --
245
+ redraw() {
246
+ this.redrawBg();
247
+ this.redrawArrows();
248
+ this.positionArrows();
249
+ }
250
+ redrawBg() {
251
+ const halfW = this._panelWidth / 2;
252
+ const halfH = this._panelHeight / 2;
253
+ const c = hexToColorAlpha(this._bgColor);
254
+ this._bg.clear();
255
+ this._bg.fillStyle(c.color, c.alpha);
256
+ this._bg.fillRoundedRect(-halfW, -halfH, this._panelWidth, this._panelHeight, this._cornerRadius);
257
+ if (this._strokeThickness > 0) {
258
+ const sc = hexToColorAlpha(this._strokeColor);
259
+ this._bg.lineStyle(this._strokeThickness, sc.color, sc.alpha);
260
+ this._bg.strokeRoundedRect(-halfW, -halfH, this._panelWidth, this._panelHeight, this._cornerRadius);
261
+ }
262
+ }
263
+ redrawArrows() {
264
+ const c = hexToColorAlpha(this._arrowColor);
265
+ const s = this._arrowSize;
266
+ const halfS = s / 2;
267
+ // Left arrow (triangle pointing left)
268
+ this._leftArrow.clear();
269
+ this._leftArrow.fillStyle(c.color, c.alpha);
270
+ this._leftArrow.fillTriangle(-halfS, 0, halfS, -halfS, halfS, halfS);
271
+ // Right arrow (triangle pointing right)
272
+ this._rightArrow.clear();
273
+ this._rightArrow.fillStyle(c.color, c.alpha);
274
+ this._rightArrow.fillTriangle(halfS, 0, -halfS, -halfS, -halfS, halfS);
275
+ }
276
+ positionArrows() {
277
+ const halfW = this._panelWidth / 2;
278
+ const leftX = -halfW + this._arrowSize / 2 + this._arrowMargin;
279
+ const rightX = halfW - this._arrowSize / 2 - this._arrowMargin;
280
+ this._leftArrow.setPosition(leftX, 0);
281
+ this._rightArrow.setPosition(rightX, 0);
282
+ this._leftZone.setPosition(leftX, 0);
283
+ this._rightZone.setPosition(rightX, 0);
284
+ }
285
+ updateDisplay() {
286
+ const opt = this._options[this._currentIndex];
287
+ if (opt)
288
+ this._label.setText(opt.value);
289
+ }
290
+ updateArrowStates() {
291
+ if (!this._isEnabled) {
292
+ this._leftArrow.setAlpha(0.2);
293
+ this._rightArrow.setAlpha(0.2);
294
+ return;
295
+ }
296
+ const canLeft = this._optionsWrap || this._currentIndex > 0;
297
+ const canRight = this._optionsWrap || this._currentIndex < this._options.length - 1;
298
+ this._leftArrow.setAlpha(canLeft ? 1 : 0.2);
299
+ this._rightArrow.setAlpha(canRight ? 1 : 0.2);
300
+ }
301
+ updateEnabledVisuals() {
302
+ const alpha = this._isEnabled ? 1 : 0.65;
303
+ this._bg.setAlpha(alpha);
304
+ this._label.setAlpha(alpha);
305
+ }
306
+ emitChanged(prevIndex) {
307
+ const current = this.getCurrentOption();
308
+ const prev = this._options[prevIndex] ?? null;
309
+ if (current) {
310
+ this.emit("option-changed", current, this._currentIndex, prev, prevIndex);
311
+ }
312
+ }
313
+ }
314
+ export function createDebugSwitchButton(scene, options) {
315
+ return new DebugSwitchButton(scene, options);
316
+ }
317
+ //# sourceMappingURL=DebugSwitchButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DebugSwitchButton.js","sourceRoot":"","sources":["../src/DebugSwitchButton.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AA0CjE;;;;;;GAMG;AACH,MAAM,OAAO,iBAAsD,SAAQ,M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C,CAAA;QAC1E,CAAC;IACF,CAAC;CACD;AAED,MAAM,UAAU,uBAAuB,CACtC,KAAmB,EACnB,OAA0C;IAE1C,OAAO,IAAI,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;AAC7C,CAAC"}
@@ -0,0 +1,23 @@
1
+ export type { HexColor, Position, Size, ClickHandler, DebugImageIconOptions, IconSide } from "./types.js";
2
+ export { parseHex, toColorInt, dimHex, hexToColorAlpha, estimateTextWidth, getDevicePixelRatio } from "./utils.js";
3
+ export { DebugPanel, createDebugPanel } from "./DebugPanel.js";
4
+ export type { CreateDebugPanelOptions } from "./DebugPanel.js";
5
+ export { DebugLabel, createDebugLabel } from "./DebugLabel.js";
6
+ export type { CreateDebugLabelOptions } from "./DebugLabel.js";
7
+ export { DebugButton, createDebugButton } from "./DebugButton.js";
8
+ export type { CreateDebugButtonOptions } from "./DebugButton.js";
9
+ export { DebugBadge, createDebugBadge } from "./DebugBadge.js";
10
+ export type { CreateDebugBadgeOptions, DebugBadgeStyleOptions } from "./DebugBadge.js";
11
+ export { DebugProgressBar, createDebugProgressBar } from "./DebugProgressBar.js";
12
+ export type { CreateDebugProgressBarOptions, DebugProgressBarStyleOptions } from "./DebugProgressBar.js";
13
+ export { DebugSwitchButton, createDebugSwitchButton } from "./DebugSwitchButton.js";
14
+ export type { CreateDebugSwitchButtonOptions, SwitchButtonOption, SwitchOptions } from "./DebugSwitchButton.js";
15
+ export { DebugRowContainer, createRowContainer } from "./DebugRowContainer.js";
16
+ export type { CreateRowContainerOptions } from "./DebugRowContainer.js";
17
+ export { DebugColumnContainer, createColumnContainer } from "./DebugColumnContainer.js";
18
+ export type { CreateColumnContainerOptions } from "./DebugColumnContainer.js";
19
+ export { DebugGridContainer, createGridContainer } from "./DebugGridContainer.js";
20
+ export type { CreateGridContainerOptions } from "./DebugGridContainer.js";
21
+ export { DebugScrollContainer, createDebugScrollContainer } from "./DebugScrollContainer.js";
22
+ export type { CreateDebugScrollContainerOptions, DebugScrollContainerStyleOptions } from "./DebugScrollContainer.js";
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGzG,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAGlH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC9D,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAG9D,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC9D,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAG9D,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACjE,YAAY,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAGhE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC9D,YAAY,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAGtF,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAChF,YAAY,EAAE,6BAA6B,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAA;AAGxG,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AACnF,YAAY,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAG/G,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC9E,YAAY,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAA;AAEvE,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACvF,YAAY,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAA;AAE7E,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AACjF,YAAY,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAA;AAEzE,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAA;AAC5F,YAAY,EAAE,iCAAiC,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ // Utilities
2
+ export { parseHex, toColorInt, dimHex, hexToColorAlpha, estimateTextWidth, getDevicePixelRatio } from "./utils.js";
3
+ // Panel
4
+ export { DebugPanel, createDebugPanel } from "./DebugPanel.js";
5
+ // Label
6
+ export { DebugLabel, createDebugLabel } from "./DebugLabel.js";
7
+ // Button
8
+ export { DebugButton, createDebugButton } from "./DebugButton.js";
9
+ // Badge
10
+ export { DebugBadge, createDebugBadge } from "./DebugBadge.js";
11
+ // Progress Bar
12
+ export { DebugProgressBar, createDebugProgressBar } from "./DebugProgressBar.js";
13
+ // Switch Button
14
+ export { DebugSwitchButton, createDebugSwitchButton } from "./DebugSwitchButton.js";
15
+ // Layout Containers
16
+ export { DebugRowContainer, createRowContainer } from "./DebugRowContainer.js";
17
+ export { DebugColumnContainer, createColumnContainer } from "./DebugColumnContainer.js";
18
+ export { DebugGridContainer, createGridContainer } from "./DebugGridContainer.js";
19
+ export { DebugScrollContainer, createDebugScrollContainer } from "./DebugScrollContainer.js";
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY;AACZ,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAElH,QAAQ;AACR,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAG9D,QAAQ;AACR,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAG9D,SAAS;AACT,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAGjE,QAAQ;AACR,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAG9D,eAAe;AACf,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAGhF,gBAAgB;AAChB,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAGnF,oBAAoB;AACpB,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAG9E,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AAGvF,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAGjF,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAA"}
@@ -0,0 +1,37 @@
1
+ export interface Position {
2
+ x?: number;
3
+ y?: number;
4
+ }
5
+ export interface Size {
6
+ width: number;
7
+ height: number;
8
+ }
9
+ /** Hex color string like "#ff0000" or "#ff000080" (with alpha). */
10
+ export type HexColor = string;
11
+ /** Callback receiving the component instance. */
12
+ export type ClickHandler<T> = (component: T) => void;
13
+ export type IconSide = "left" | "right";
14
+ /**
15
+ * Image-based icon config (Phaser texture key + optional layout/tint settings).
16
+ *
17
+ * Intended for monochrome (usually white) PNGs so tinting works predictably.
18
+ */
19
+ export interface DebugImageIconOptions {
20
+ /** Texture key (must be preloaded in the Scene). */
21
+ key: string;
22
+ /** Optional texture frame (atlas / spritesheet). */
23
+ frame?: string | number;
24
+ /** Icon side relative to text (default: "left"). */
25
+ side?: IconSide;
26
+ /** Gap between icon and text in px (default: 8). */
27
+ gap?: number;
28
+ /** Icon tint (default: follow text color for the current state). */
29
+ tint?: HexColor;
30
+ /** Hover-state icon tint override (button only). */
31
+ hoverTint?: HexColor;
32
+ /** Disabled-state icon tint override (button only). */
33
+ disabledTint?: HexColor;
34
+ /** Alpha multiplier applied after tint alpha (default: 1). */
35
+ alpha?: number;
36
+ }
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACxB,CAAC,CAAC,EAAE,MAAM,CAAA;IACV,CAAC,CAAC,EAAE,MAAM,CAAA;CACV;AAED,MAAM,WAAW,IAAI;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACd;AAED,mEAAmE;AACnE,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAE7B,iDAAiD;AACjD,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,IAAI,CAAA;AAEpD,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AAEvC;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACrC,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAA;IACX,oDAAoD;IACpD,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,oDAAoD;IACpD,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,oDAAoD;IACpD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,oEAAoE;IACpE,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,oDAAoD;IACpD,SAAS,CAAC,EAAE,QAAQ,CAAA;IACpB,uDAAuD;IACvD,YAAY,CAAC,EAAE,QAAQ,CAAA;IACvB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAA;CACd"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Parse a hex color string into numeric components.
3
+ * Supports "#rgb", "#rrggbb", "#rrggbbaa".
4
+ */
5
+ export declare function parseHex(hex: string): {
6
+ r: number;
7
+ g: number;
8
+ b: number;
9
+ a: number;
10
+ };
11
+ /** Convert {r,g,b,a} to a Phaser-compatible 0xRRGGBB number. */
12
+ export declare function toColorInt(c: {
13
+ r: number;
14
+ g: number;
15
+ b: number;
16
+ }): number;
17
+ /** Dim a hex color by a multiplier (0–1). */
18
+ export declare function dimHex(hex: string, multiplier: number): {
19
+ color: number;
20
+ alpha: number;
21
+ };
22
+ /** Parse hex to { color: 0xRRGGBB, alpha: 0–1 }. */
23
+ export declare function hexToColorAlpha(hex: string): {
24
+ color: number;
25
+ alpha: number;
26
+ };
27
+ /** Device pixel ratio for crisp text on high-DPI displays. */
28
+ export declare function getDevicePixelRatio(): number;
29
+ /** Rough monospace-ish text width estimator. */
30
+ export declare function estimateTextWidth(text: string, fontSize: number): number;
31
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAapF;AAED,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,CAAC,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAEzE;AAED,6CAA6C;AAC7C,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAUxF;AAED,oDAAoD;AACpD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAG7E;AAED,8DAA8D;AAC9D,wBAAgB,mBAAmB,IAAI,MAAM,CAG5C;AAED,gDAAgD;AAChD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAaxE"}
package/dist/utils.js ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Parse a hex color string into numeric components.
3
+ * Supports "#rgb", "#rrggbb", "#rrggbbaa".
4
+ */
5
+ export function parseHex(hex) {
6
+ let h = hex.startsWith("#") ? hex.slice(1) : hex;
7
+ if (h.length === 3) {
8
+ h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
9
+ }
10
+ const r = parseInt(h.slice(0, 2), 16);
11
+ const g = parseInt(h.slice(2, 4), 16);
12
+ const b = parseInt(h.slice(4, 6), 16);
13
+ const a = h.length >= 8 ? parseInt(h.slice(6, 8), 16) / 255 : 1;
14
+ return { r, g, b, a };
15
+ }
16
+ /** Convert {r,g,b,a} to a Phaser-compatible 0xRRGGBB number. */
17
+ export function toColorInt(c) {
18
+ return (c.r << 16) | (c.g << 8) | c.b;
19
+ }
20
+ /** Dim a hex color by a multiplier (0–1). */
21
+ export function dimHex(hex, multiplier) {
22
+ const c = parseHex(hex);
23
+ return {
24
+ color: toColorInt({
25
+ r: Math.round(c.r * multiplier),
26
+ g: Math.round(c.g * multiplier),
27
+ b: Math.round(c.b * multiplier),
28
+ }),
29
+ alpha: c.a,
30
+ };
31
+ }
32
+ /** Parse hex to { color: 0xRRGGBB, alpha: 0–1 }. */
33
+ export function hexToColorAlpha(hex) {
34
+ const c = parseHex(hex);
35
+ return { color: toColorInt(c), alpha: c.a };
36
+ }
37
+ /** Device pixel ratio for crisp text on high-DPI displays. */
38
+ export function getDevicePixelRatio() {
39
+ if (typeof window === "undefined")
40
+ return 1;
41
+ return window.devicePixelRatio ?? 1;
42
+ }
43
+ /** Rough monospace-ish text width estimator. */
44
+ export function estimateTextWidth(text, fontSize) {
45
+ if (text.length === 0)
46
+ return 0;
47
+ let width = 0;
48
+ for (const char of text) {
49
+ if (char === " ")
50
+ width += 0.34;
51
+ else if (/[0-9]/.test(char))
52
+ width += 0.64;
53
+ else if (/[A-Z]/.test(char))
54
+ width += 0.76;
55
+ else if (/[a-z]/.test(char))
56
+ width += 0.64;
57
+ else
58
+ width += 0.8;
59
+ }
60
+ return width * fontSize;
61
+ }
62
+ //# sourceMappingURL=utils.js.map