@vforsh/phaser-dev-ui 0.1.0 → 0.3.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/README.md CHANGED
@@ -70,6 +70,15 @@ The system is designed with a fluent, chainable API and dark-theme defaults matc
70
70
  - **`createGridContainer`**: Arranges children in a grid with configurable columns, cell size, and spacing.
71
71
  - **Usage**: Group related UI elements. After adding items via `addItem()` or `addItems()`, call `.layout()` to reposition children. Containers are invisible positioning helpers and can be nested.
72
72
 
73
+ ### Utility Helpers
74
+
75
+ - **`bindDebugControl`**: Two-way model binding helper for debug controls.
76
+ - Supports model access via object path (`target` + `path`) or custom getter/setter.
77
+ - Polls model on `preupdate` and pushes control changes back through control events.
78
+ - **`anchorToViewport`**: Anchors any game object to viewport edges/corners/center with optional safe-area insets and resize updates.
79
+ - **`getSafeAreaInsets`**: Resolves safe-area insets in game units (CSS env insets + optional extra insets).
80
+ - **`layoutAuto`**: Dirty layout scheduler; batches `.layout()` calls and flushes once per frame.
81
+
73
82
  ## Example: Creating a Settings Popup
74
83
 
75
84
  ```typescript
@@ -0,0 +1,42 @@
1
+ import type { HexColor, Position } from "./types.js";
2
+ export interface CreateDebugSeparatorOptions {
3
+ /** Total width of the separator line (default: 200). */
4
+ width?: number;
5
+ /** Line thickness in px (default: 1). */
6
+ thickness?: number;
7
+ /** Line color (default: "#a3a3a3"). */
8
+ color?: HexColor;
9
+ /** Optional centered label text (e.g. "Physics"). Omit for a plain line. */
10
+ label?: string;
11
+ /** Label font size (default: 12). */
12
+ labelFontSize?: number;
13
+ /** Label text color (default: same as line color). */
14
+ labelColor?: HexColor;
15
+ /** Gap in px between label edges and line segments (default: 8). */
16
+ labelGap?: number;
17
+ /** Position (optional). */
18
+ position?: Position;
19
+ }
20
+ /**
21
+ * A thin horizontal divider line with an optional centered label.
22
+ *
23
+ * Use inside panels or layout containers to visually separate sections.
24
+ * Chainable API.
25
+ */
26
+ export declare class DebugSeparator extends Phaser.GameObjects.Container {
27
+ private _line;
28
+ private _label;
29
+ private _separatorWidth;
30
+ private _thickness;
31
+ private _color;
32
+ private _labelGap;
33
+ constructor(scene: Phaser.Scene, options?: CreateDebugSeparatorOptions);
34
+ setLineColor(color: HexColor): this;
35
+ setLabel(text: string): this;
36
+ setThickness(thickness: number): this;
37
+ setSeparatorWidth(width: number): this;
38
+ setStyle(options: Partial<Pick<CreateDebugSeparatorOptions, "width" | "thickness" | "color" | "labelGap">>): this;
39
+ private redraw;
40
+ }
41
+ export declare function createDebugSeparator(scene: Phaser.Scene, options?: CreateDebugSeparatorOptions): DebugSeparator;
42
+ //# sourceMappingURL=DebugSeparator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DebugSeparator.d.ts","sourceRoot":"","sources":["../src/DebugSeparator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGpD,MAAM,WAAW,2BAA2B;IAC3C,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,uCAAuC;IACvC,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,qCAAqC;IACrC,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,sDAAsD;IACtD,UAAU,CAAC,EAAE,QAAQ,CAAA;IACrB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACnB;AAED;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,MAAM,CAAC,WAAW,CAAC,SAAS;IAC/D,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,SAAS,CAAQ;gBAEb,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,GAAE,2BAAgC;IAyC1E,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAMnC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAmB5B,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAMrC,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAOtC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,2BAA2B,EAAE,OAAO,GAAG,WAAW,GAAG,OAAO,GAAG,UAAU,CAAC,CAAC,GAAG,IAAI;IASjH,OAAO,CAAC,MAAM;CAsBd;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,GAAE,2BAAgC,GAAG,cAAc,CAEnH"}
@@ -0,0 +1,109 @@
1
+ import { getDevicePixelRatio, hexToColorAlpha } from "./utils.js";
2
+ /**
3
+ * A thin horizontal divider line with an optional centered label.
4
+ *
5
+ * Use inside panels or layout containers to visually separate sections.
6
+ * Chainable API.
7
+ */
8
+ export class DebugSeparator extends Phaser.GameObjects.Container {
9
+ _line;
10
+ _label = null;
11
+ _separatorWidth;
12
+ _thickness;
13
+ _color;
14
+ _labelGap;
15
+ constructor(scene, options = {}) {
16
+ const { width = 200, thickness = 1, color = "#a3a3a3", label, labelFontSize = 12, labelColor, labelGap = 8, position, } = options;
17
+ super(scene, position?.x ?? 0, position?.y ?? 0);
18
+ this._separatorWidth = width;
19
+ this._thickness = thickness;
20
+ this._color = color;
21
+ this._labelGap = labelGap;
22
+ this._line = new Phaser.GameObjects.Graphics(scene);
23
+ this.add(this._line);
24
+ if (label !== undefined && label !== "") {
25
+ const lc = hexToColorAlpha(labelColor ?? color);
26
+ this._label = new Phaser.GameObjects.Text(scene, 0, 0, label, {
27
+ fontFamily: "Verdana",
28
+ fontSize: `${labelFontSize}px`,
29
+ color: `#${lc.color.toString(16).padStart(6, "0")}`,
30
+ resolution: getDevicePixelRatio(),
31
+ });
32
+ this._label.setOrigin(0.5, 0.5);
33
+ this._label.setAlpha(lc.alpha);
34
+ this.add(this._label);
35
+ }
36
+ this.redraw();
37
+ this.setSize(width, Math.max(thickness, this._label?.displayHeight ?? 0));
38
+ scene.add.existing(this);
39
+ }
40
+ setLineColor(color) {
41
+ this._color = color;
42
+ this.redraw();
43
+ return this;
44
+ }
45
+ setLabel(text) {
46
+ if (!this._label) {
47
+ const lc = hexToColorAlpha(this._color);
48
+ this._label = new Phaser.GameObjects.Text(this.scene, 0, 0, text, {
49
+ fontFamily: "Verdana",
50
+ fontSize: "12px",
51
+ color: `#${lc.color.toString(16).padStart(6, "0")}`,
52
+ resolution: getDevicePixelRatio(),
53
+ });
54
+ this._label.setOrigin(0.5, 0.5);
55
+ this._label.setAlpha(lc.alpha);
56
+ this.add(this._label);
57
+ }
58
+ else {
59
+ this._label.setText(text);
60
+ }
61
+ this.redraw();
62
+ return this;
63
+ }
64
+ setThickness(thickness) {
65
+ this._thickness = Math.max(1, thickness);
66
+ this.redraw();
67
+ return this;
68
+ }
69
+ setSeparatorWidth(width) {
70
+ this._separatorWidth = width;
71
+ this.setSize(width, this.height);
72
+ this.redraw();
73
+ return this;
74
+ }
75
+ setStyle(options) {
76
+ if (options.width !== undefined)
77
+ this._separatorWidth = options.width;
78
+ if (options.thickness !== undefined)
79
+ this._thickness = Math.max(1, options.thickness);
80
+ if (options.color !== undefined)
81
+ this._color = options.color;
82
+ if (options.labelGap !== undefined)
83
+ this._labelGap = options.labelGap;
84
+ this.redraw();
85
+ return this;
86
+ }
87
+ redraw() {
88
+ const halfW = this._separatorWidth / 2;
89
+ const c = hexToColorAlpha(this._color);
90
+ this._line.clear();
91
+ this._line.lineStyle(this._thickness, c.color, c.alpha);
92
+ if (!this._label || this._label.text === "") {
93
+ this._line.lineBetween(-halfW, 0, halfW, 0);
94
+ this.setSize(this._separatorWidth, this._thickness);
95
+ return;
96
+ }
97
+ const labelHalfW = this._label.displayWidth / 2;
98
+ const gap = this._labelGap;
99
+ const lineLeftEnd = -(labelHalfW + gap);
100
+ const lineRightStart = labelHalfW + gap;
101
+ this._line.lineBetween(-halfW, 0, lineLeftEnd, 0);
102
+ this._line.lineBetween(lineRightStart, 0, halfW, 0);
103
+ this.setSize(this._separatorWidth, Math.max(this._thickness, this._label.displayHeight));
104
+ }
105
+ }
106
+ export function createDebugSeparator(scene, options = {}) {
107
+ return new DebugSeparator(scene, options);
108
+ }
109
+ //# sourceMappingURL=DebugSeparator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DebugSeparator.js","sourceRoot":"","sources":["../src/DebugSeparator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAqBjE;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,MAAM,CAAC,WAAW,CAAC,SAAS;IACvD,KAAK,CAA6B;IAClC,MAAM,GAAmC,IAAI,CAAA;IAC7C,eAAe,CAAQ;IACvB,UAAU,CAAQ;IAClB,MAAM,CAAU;IAChB,SAAS,CAAQ;IAEzB,YAAY,KAAmB,EAAE,UAAuC,EAAE;QACzE,MAAM,EACL,KAAK,GAAG,GAAG,EACX,SAAS,GAAG,CAAC,EACb,KAAK,GAAG,SAAS,EACjB,KAAK,EACL,aAAa,GAAG,EAAE,EAClB,UAAU,EACV,QAAQ,GAAG,CAAC,EACZ,QAAQ,GACR,GAAG,OAAO,CAAA;QAEX,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;QAEhD,IAAI,CAAC,eAAe,GAAG,KAAK,CAAA;QAC5B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;QAC3B,IAAI,CAAC,MAAM,GAAG,K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,OAAM;QACP,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,CAAC,CAAA;QAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAA;QAC1B,MAAM,WAAW,GAAG,CAAC,CAAC,UAAU,GAAG,GAAG,CAAC,CAAA;QACvC,MAAM,cAAc,GAAG,UAAU,GAAG,GAAG,CAAA;QAEvC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAA;QACjD,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,cAAc,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;QACnD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAA;IACzF,CAAC;CACD;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAmB,EAAE,UAAuC,EAAE;IAClG,OAAO,IAAI,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;AAC1C,CAAC"}
@@ -0,0 +1,79 @@
1
+ import type { HexColor, Position } from "./types.js";
2
+ export interface DebugSliderStyleOptions {
3
+ width?: number;
4
+ height?: number;
5
+ trackHeight?: number;
6
+ thumbRadius?: number;
7
+ trackColor?: HexColor;
8
+ fillColor?: HexColor;
9
+ thumbColor?: HexColor;
10
+ }
11
+ export interface CreateDebugSliderOptions extends DebugSliderStyleOptions {
12
+ /** Current value (default: 0, clamped to min–max range). */
13
+ value?: number;
14
+ /** Minimum value (default: 0). */
15
+ min?: number;
16
+ /** Maximum value (default: 1). */
17
+ max?: number;
18
+ /** Step size — 0 = continuous (default: 0). */
19
+ step?: number;
20
+ /** Whether the slider accepts input (default: true). */
21
+ enabled?: boolean;
22
+ /** Called when the value changes. */
23
+ onChange?: (value: number, slider: DebugSlider) => void;
24
+ /** Position (optional). */
25
+ position?: Position;
26
+ }
27
+ /**
28
+ * An interactive horizontal slider for debug HUD.
29
+ *
30
+ * Supports min/max range, step snapping, and drag interaction.
31
+ * Emits `"value-changed"` event. Chainable API.
32
+ */
33
+ export declare class DebugSlider extends Phaser.GameObjects.Container {
34
+ private _track;
35
+ private _fill;
36
+ private _thumb;
37
+ private _hitZone;
38
+ private _value;
39
+ private _min;
40
+ private _max;
41
+ private _step;
42
+ private _isEnabled;
43
+ private _isDragging;
44
+ private _sliderWidth;
45
+ private _sliderHeight;
46
+ private _trackHeight;
47
+ private _thumbRadius;
48
+ private _trackColor;
49
+ private _fillColor;
50
+ private _thumbColor;
51
+ private _onChangeCallbacks;
52
+ private _boundOnPointerMove;
53
+ private _boundOnPointerUp;
54
+ constructor(scene: Phaser.Scene, options?: CreateDebugSliderOptions);
55
+ getValue(): number;
56
+ setValue(value: number): this;
57
+ isEnabled(): boolean;
58
+ setEnabled(enabled: boolean): this;
59
+ onValueChanged(handler: (value: number, slider: DebugSlider) => void): this;
60
+ setTrackColor(color: HexColor): this;
61
+ setFillColor(color: HexColor): this;
62
+ setThumbColor(color: HexColor): this;
63
+ setRange(min: number, max: number): this;
64
+ setStep(step: number): this;
65
+ setSliderSize(width: number, height: number): this;
66
+ setStyle(options: DebugSliderStyleOptions): this;
67
+ destroy(fromScene?: boolean): void;
68
+ private handlePointerDown;
69
+ private handlePointerMove;
70
+ private handlePointerUp;
71
+ private stopDragging;
72
+ private updateValueFromPointer;
73
+ private clampAndSnap;
74
+ private fireOnChange;
75
+ private applyEnabledState;
76
+ private redraw;
77
+ }
78
+ export declare function createDebugSlider(scene: Phaser.Scene, options?: CreateDebugSliderOptions): DebugSlider;
79
+ //# sourceMappingURL=DebugSlider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DebugSlider.d.ts","sourceRoot":"","sources":["../src/DebugSlider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAA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IAMpB,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,MAAM;CAiCd;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,GAAE,wBAA6B,GAAG,WAAW,CAE1G"}
@@ -0,0 +1,233 @@
1
+ import { hexToColorAlpha } from "./utils.js";
2
+ /**
3
+ * An interactive horizontal slider for debug HUD.
4
+ *
5
+ * Supports min/max range, step snapping, and drag interaction.
6
+ * Emits `"value-changed"` event. Chainable API.
7
+ */
8
+ export class DebugSlider extends Phaser.GameObjects.Container {
9
+ _track;
10
+ _fill;
11
+ _thumb;
12
+ _hitZone;
13
+ _value;
14
+ _min;
15
+ _max;
16
+ _step;
17
+ _isEnabled;
18
+ _isDragging = false;
19
+ _sliderWidth;
20
+ _sliderHeight;
21
+ _trackHeight;
22
+ _thumbRadius;
23
+ _trackColor;
24
+ _fillColor;
25
+ _thumbColor;
26
+ _onChangeCallbacks = [];
27
+ _boundOnPointerMove;
28
+ _boundOnPointerUp;
29
+ constructor(scene, options = {}) {
30
+ const { value = 0, min = 0, max = 1, step = 0, enabled = true, width = 200, height = 24, trackHeight = 6, thumbRadius = 10, trackColor = "#333333", fillColor = "#4caf50", thumbColor = "#ffffff", onChange, position, } = options;
31
+ super(scene, position?.x ?? 0, position?.y ?? 0);
32
+ this._min = min;
33
+ this._max = max;
34
+ this._step = step;
35
+ this._isEnabled = enabled;
36
+ this._sliderWidth = width;
37
+ this._sliderHeight = height;
38
+ this._trackHeight = trackHeight;
39
+ this._thumbRadius = thumbRadius;
40
+ this._trackColor = trackColor;
41
+ this._fillColor = fillColor;
42
+ this._thumbColor = thumbColor;
43
+ this._value = this.clampAndSnap(value);
44
+ if (onChange)
45
+ this._onChangeCallbacks.push(onChange);
46
+ this._track = new Phaser.GameObjects.Graphics(scene);
47
+ this._fill = new Phaser.GameObjects.Graphics(scene);
48
+ this._thumb = new Phaser.GameObjects.Graphics(scene);
49
+ this._hitZone = new Phaser.GameObjects.Zone(scene, 0, 0, width, height);
50
+ this._hitZone.setInteractive({ useHandCursor: true });
51
+ this._hitZone.on("pointerdown", this.handlePointerDown, this);
52
+ this._boundOnPointerMove = this.handlePointerMove.bind(this);
53
+ this._boundOnPointerUp = this.handlePointerUp.bind(this);
54
+ this.add([this._track, this._fill, this._thumb, this._hitZone]);
55
+ this.setSize(width, height);
56
+ this.applyEnabledState();
57
+ this.redraw();
58
+ scene.add.existing(this);
59
+ }
60
+ getValue() {
61
+ return this._value;
62
+ }
63
+ setValue(value) {
64
+ const clamped = this.clampAndSnap(value);
65
+ if (clamped === this._value)
66
+ return this;
67
+ const prev = this._value;
68
+ this._value = clamped;
69
+ this.redraw();
70
+ this.emit("value-changed", clamped, prev);
71
+ this.fireOnChange();
72
+ return this;
73
+ }
74
+ isEnabled() {
75
+ return this._isEnabled;
76
+ }
77
+ setEnabled(enabled) {
78
+ this._isEnabled = enabled;
79
+ this.applyEnabledState();
80
+ return this;
81
+ }
82
+ onValueChanged(handler) {
83
+ this._onChangeCallbacks.push(handler);
84
+ return this;
85
+ }
86
+ setTrackColor(color) {
87
+ this._trackColor = color;
88
+ this.redraw();
89
+ return this;
90
+ }
91
+ setFillColor(color) {
92
+ this._fillColor = color;
93
+ this.redraw();
94
+ return this;
95
+ }
96
+ setThumbColor(color) {
97
+ this._thumbColor = color;
98
+ this.redraw();
99
+ return this;
100
+ }
101
+ setRange(min, max) {
102
+ this._min = min;
103
+ this._max = max;
104
+ this._value = this.clampAndSnap(this._value);
105
+ this.redraw();
106
+ return this;
107
+ }
108
+ setStep(step) {
109
+ this._step = Math.max(0, step);
110
+ this._value = this.clampAndSnap(this._value);
111
+ this.redraw();
112
+ return this;
113
+ }
114
+ setSliderSize(width, height) {
115
+ this._sliderWidth = width;
116
+ this._sliderHeight = height;
117
+ this._hitZone.setSize(width, height);
118
+ this.setSize(width, height);
119
+ this.redraw();
120
+ return this;
121
+ }
122
+ setStyle(options) {
123
+ if (options.trackColor !== undefined)
124
+ this._trackColor = options.trackColor;
125
+ if (options.fillColor !== undefined)
126
+ this._fillColor = options.fillColor;
127
+ if (options.thumbColor !== undefined)
128
+ this._thumbColor = options.thumbColor;
129
+ if (options.trackHeight !== undefined)
130
+ this._trackHeight = options.trackHeight;
131
+ if (options.thumbRadius !== undefined)
132
+ this._thumbRadius = options.thumbRadius;
133
+ if (options.width !== undefined || options.height !== undefined) {
134
+ this._sliderWidth = options.width ?? this._sliderWidth;
135
+ this._sliderHeight = options.height ?? this._sliderHeight;
136
+ this._hitZone.setSize(this._sliderWidth, this._sliderHeight);
137
+ this.setSize(this._sliderWidth, this._sliderHeight);
138
+ }
139
+ this.redraw();
140
+ return this;
141
+ }
142
+ destroy(fromScene) {
143
+ this.stopDragging();
144
+ super.destroy(fromScene);
145
+ }
146
+ handlePointerDown(pointer) {
147
+ if (!this._isEnabled)
148
+ return;
149
+ this._isDragging = true;
150
+ this.updateValueFromPointer(pointer);
151
+ this.scene.input.on("pointermove", this._boundOnPointerMove);
152
+ this.scene.input.on("pointerup", this._boundOnPointerUp);
153
+ }
154
+ handlePointerMove(pointer) {
155
+ if (!this._isDragging)
156
+ return;
157
+ this.updateValueFromPointer(pointer);
158
+ }
159
+ handlePointerUp() {
160
+ this.stopDragging();
161
+ }
162
+ stopDragging() {
163
+ if (!this._isDragging)
164
+ return;
165
+ this._isDragging = false;
166
+ this.scene?.input?.off("pointermove", this._boundOnPointerMove);
167
+ this.scene?.input?.off("pointerup", this._boundOnPointerUp);
168
+ }
169
+ updateValueFromPointer(pointer) {
170
+ const matrix = this.getWorldTransformMatrix();
171
+ const tmp = new Phaser.Math.Vector2();
172
+ matrix.applyInverse(pointer.worldX, pointer.worldY, tmp);
173
+ const halfW = this._sliderWidth / 2;
174
+ const ratio = Phaser.Math.Clamp((tmp.x + halfW) / this._sliderWidth, 0, 1);
175
+ const rawValue = this._min + ratio * (this._max - this._min);
176
+ this.setValue(rawValue);
177
+ }
178
+ clampAndSnap(value) {
179
+ let v = Phaser.Math.Clamp(value, this._min, this._max);
180
+ if (this._step > 0) {
181
+ v = Math.round((v - this._min) / this._step) * this._step + this._min;
182
+ v = Phaser.Math.Clamp(v, this._min, this._max);
183
+ }
184
+ return v;
185
+ }
186
+ fireOnChange() {
187
+ for (const cb of this._onChangeCallbacks) {
188
+ cb(this._value, this);
189
+ }
190
+ }
191
+ applyEnabledState() {
192
+ this.setAlpha(this._isEnabled ? 1 : 0.5);
193
+ if (this._isEnabled) {
194
+ this._hitZone.setInteractive({ useHandCursor: true });
195
+ }
196
+ else {
197
+ this._hitZone.disableInteractive();
198
+ }
199
+ }
200
+ redraw() {
201
+ const w = this._sliderWidth;
202
+ const halfW = w / 2;
203
+ const th = this._trackHeight;
204
+ const halfTH = th / 2;
205
+ const trackRadius = halfTH;
206
+ // Normalized position 0–1
207
+ const range = this._max - this._min;
208
+ const ratio = range > 0 ? (this._value - this._min) / range : 0;
209
+ const thumbX = -halfW + ratio * w;
210
+ // Track
211
+ const tc = hexToColorAlpha(this._trackColor);
212
+ this._track.clear();
213
+ this._track.fillStyle(tc.color, tc.alpha);
214
+ this._track.fillRoundedRect(-halfW, -halfTH, w, th, trackRadius);
215
+ // Fill
216
+ const fc = hexToColorAlpha(this._fillColor);
217
+ const fillWidth = ratio * w;
218
+ this._fill.clear();
219
+ if (fillWidth > 0) {
220
+ this._fill.fillStyle(fc.color, fc.alpha);
221
+ this._fill.fillRect(-halfW, -halfTH, fillWidth, th);
222
+ }
223
+ // Thumb
224
+ const thumbC = hexToColorAlpha(this._thumbColor);
225
+ this._thumb.clear();
226
+ this._thumb.fillStyle(thumbC.color, thumbC.alpha);
227
+ this._thumb.fillCircle(thumbX, 0, this._thumbRadius);
228
+ }
229
+ }
230
+ export function createDebugSlider(scene, options = {}) {
231
+ return new DebugSlider(scene, options);
232
+ }
233
+ //# sourceMappingURL=DebugSlider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DebugSlider.js","sourceRoot":"","sources":["../src/DebugSlider.ts"],"names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AAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,CAAA;QACpD,CAAC;QAED,QAAQ;QACR,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QAChD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QACnB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;QACjD,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;IACrD,CAAC;CACD;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAmB,EAAE,UAAoC,EAAE;IAC5F,OAAO,IAAI,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;AACvC,CAAC"}
@@ -0,0 +1,57 @@
1
+ import type { HexColor, Position } from "./types.js";
2
+ export interface DebugToggleStyleOptions {
3
+ width?: number;
4
+ height?: number;
5
+ onColor?: HexColor;
6
+ offColor?: HexColor;
7
+ thumbColor?: HexColor;
8
+ thumbPadding?: number;
9
+ }
10
+ export interface CreateDebugToggleOptions extends DebugToggleStyleOptions {
11
+ /** Initial value (default: false). */
12
+ value?: boolean;
13
+ /** Whether the toggle accepts input (default: true). */
14
+ enabled?: boolean;
15
+ /** Called when the value changes. */
16
+ onChange?: (value: boolean, toggle: DebugToggle) => void;
17
+ /** Position (optional). */
18
+ position?: Position;
19
+ }
20
+ /**
21
+ * A boolean on/off pill toggle switch for debug HUD.
22
+ *
23
+ * Click to flip state. Emits `"value-changed"` event.
24
+ * Supports enabled/disabled state and chainable API.
25
+ */
26
+ export declare class DebugToggle extends Phaser.GameObjects.Container {
27
+ private _track;
28
+ private _thumb;
29
+ private _hitZone;
30
+ private _isOn;
31
+ private _isEnabled;
32
+ private _onColor;
33
+ private _offColor;
34
+ private _thumbColor;
35
+ private _toggleWidth;
36
+ private _toggleHeight;
37
+ private _thumbPadding;
38
+ private _onChangeCallbacks;
39
+ constructor(scene: Phaser.Scene, options?: CreateDebugToggleOptions);
40
+ getValue(): boolean;
41
+ setValue(value: boolean): this;
42
+ toggle(): this;
43
+ isEnabled(): boolean;
44
+ setEnabled(enabled: boolean): this;
45
+ onValueChanged(handler: (value: boolean, toggle: DebugToggle) => void): this;
46
+ setOnColor(color: HexColor): this;
47
+ setOffColor(color: HexColor): this;
48
+ setThumbColor(color: HexColor): this;
49
+ setToggleSize(width: number, height: number): this;
50
+ setStyle(options: DebugToggleStyleOptions): this;
51
+ private handleClick;
52
+ private fireOnChange;
53
+ private applyEnabledState;
54
+ private redraw;
55
+ }
56
+ export declare function createDebugToggle(scene: Phaser.Scene, options?: CreateDebugToggleOptions): DebugToggle;
57
+ //# sourceMappingURL=DebugToggle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DebugToggle.d.ts","sourceRoot":"","sources":["../src/DebugToggle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGpD,MAAM,WAAW,uBAAuB;IACvC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,QAAQ,CAAA;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,UAAU,CAAC,EAAE,QAAQ,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,wBAAyB,SAAQ,uBAAuB;IACxE,sCAAsC;IACtC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,wDAAwD;IACxD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,KAAK,IAAI,CAAA;IACxD,2BAA2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