@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.
@@ -0,0 +1,159 @@
1
+ import { hexToColorAlpha } from "./utils.js";
2
+ /**
3
+ * A boolean on/off pill toggle switch for debug HUD.
4
+ *
5
+ * Click to flip state. Emits `"value-changed"` event.
6
+ * Supports enabled/disabled state and chainable API.
7
+ */
8
+ export class DebugToggle extends Phaser.GameObjects.Container {
9
+ _track;
10
+ _thumb;
11
+ _hitZone;
12
+ _isOn;
13
+ _isEnabled;
14
+ _onColor;
15
+ _offColor;
16
+ _thumbColor;
17
+ _toggleWidth;
18
+ _toggleHeight;
19
+ _thumbPadding;
20
+ _onChangeCallbacks = [];
21
+ constructor(scene, options = {}) {
22
+ const { value = false, enabled = true, onColor = "#4caf50", offColor = "#555555", thumbColor = "#ffffff", width = 48, height = 26, thumbPadding = 3, onChange, position, } = options;
23
+ super(scene, position?.x ?? 0, position?.y ?? 0);
24
+ this._isOn = value;
25
+ this._isEnabled = enabled;
26
+ this._onColor = onColor;
27
+ this._offColor = offColor;
28
+ this._thumbColor = thumbColor;
29
+ this._toggleWidth = width;
30
+ this._toggleHeight = height;
31
+ this._thumbPadding = thumbPadding;
32
+ if (onChange)
33
+ this._onChangeCallbacks.push(onChange);
34
+ this._track = new Phaser.GameObjects.Graphics(scene);
35
+ this._thumb = new Phaser.GameObjects.Graphics(scene);
36
+ this._hitZone = new Phaser.GameObjects.Zone(scene, 0, 0, width, height);
37
+ this._hitZone.setInteractive({ useHandCursor: true });
38
+ this._hitZone.on("pointerup", this.handleClick, this);
39
+ this.add([this._track, this._thumb, this._hitZone]);
40
+ this.setSize(width, height);
41
+ this.applyEnabledState();
42
+ this.redraw();
43
+ scene.add.existing(this);
44
+ }
45
+ getValue() {
46
+ return this._isOn;
47
+ }
48
+ setValue(value) {
49
+ if (this._isOn === value)
50
+ return this;
51
+ this._isOn = value;
52
+ this.redraw();
53
+ this.emit("value-changed", value);
54
+ this.fireOnChange();
55
+ return this;
56
+ }
57
+ toggle() {
58
+ return this.setValue(!this._isOn);
59
+ }
60
+ isEnabled() {
61
+ return this._isEnabled;
62
+ }
63
+ setEnabled(enabled) {
64
+ this._isEnabled = enabled;
65
+ this.applyEnabledState();
66
+ return this;
67
+ }
68
+ onValueChanged(handler) {
69
+ this._onChangeCallbacks.push(handler);
70
+ return this;
71
+ }
72
+ setOnColor(color) {
73
+ this._onColor = color;
74
+ this.redraw();
75
+ return this;
76
+ }
77
+ setOffColor(color) {
78
+ this._offColor = color;
79
+ this.redraw();
80
+ return this;
81
+ }
82
+ setThumbColor(color) {
83
+ this._thumbColor = color;
84
+ this.redraw();
85
+ return this;
86
+ }
87
+ setToggleSize(width, height) {
88
+ this._toggleWidth = width;
89
+ this._toggleHeight = height;
90
+ this._hitZone.setSize(width, height);
91
+ this.setSize(width, height);
92
+ this.redraw();
93
+ return this;
94
+ }
95
+ setStyle(options) {
96
+ if (options.onColor !== undefined)
97
+ this._onColor = options.onColor;
98
+ if (options.offColor !== undefined)
99
+ this._offColor = options.offColor;
100
+ if (options.thumbColor !== undefined)
101
+ this._thumbColor = options.thumbColor;
102
+ if (options.thumbPadding !== undefined)
103
+ this._thumbPadding = options.thumbPadding;
104
+ if (options.width !== undefined || options.height !== undefined) {
105
+ this._toggleWidth = options.width ?? this._toggleWidth;
106
+ this._toggleHeight = options.height ?? this._toggleHeight;
107
+ this._hitZone.setSize(this._toggleWidth, this._toggleHeight);
108
+ this.setSize(this._toggleWidth, this._toggleHeight);
109
+ }
110
+ this.redraw();
111
+ return this;
112
+ }
113
+ handleClick() {
114
+ if (!this._isEnabled)
115
+ return;
116
+ this._isOn = !this._isOn;
117
+ this.redraw();
118
+ this.emit("value-changed", this._isOn);
119
+ this.fireOnChange();
120
+ }
121
+ fireOnChange() {
122
+ for (const cb of this._onChangeCallbacks) {
123
+ cb(this._isOn, this);
124
+ }
125
+ }
126
+ applyEnabledState() {
127
+ this.setAlpha(this._isEnabled ? 1 : 0.5);
128
+ if (this._isEnabled) {
129
+ this._hitZone.setInteractive({ useHandCursor: true });
130
+ }
131
+ else {
132
+ this._hitZone.disableInteractive();
133
+ }
134
+ }
135
+ redraw() {
136
+ const w = this._toggleWidth;
137
+ const h = this._toggleHeight;
138
+ const halfW = w / 2;
139
+ const halfH = h / 2;
140
+ const radius = halfH;
141
+ // Track (pill shape)
142
+ const trackColor = this._isOn ? this._onColor : this._offColor;
143
+ const tc = hexToColorAlpha(trackColor);
144
+ this._track.clear();
145
+ this._track.fillStyle(tc.color, tc.alpha);
146
+ this._track.fillRoundedRect(-halfW, -halfH, w, h, radius);
147
+ // Thumb (circle)
148
+ const thumbRadius = halfH - this._thumbPadding;
149
+ const thumbX = this._isOn ? halfW - halfH : -halfW + halfH;
150
+ const thumbC = hexToColorAlpha(this._thumbColor);
151
+ this._thumb.clear();
152
+ this._thumb.fillStyle(thumbC.color, thumbC.alpha);
153
+ this._thumb.fillCircle(thumbX, 0, thumbRadius);
154
+ }
155
+ }
156
+ export function createDebugToggle(scene, options = {}) {
157
+ return new DebugToggle(scene, options);
158
+ }
159
+ //# sourceMappingURL=DebugToggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DebugToggle.js","sourceRoot":"","sources":["../src/DebugToggle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAsB5C;;;;;GAKG;AACH,MAAM,OAAO,WAAY,SAAQ,MAAM,CAAC,WAAW,CAAC,SAAS;IACpD,MAAM,CAA6B;IACnC,MAAM,CAA6B;IACnC,QAAQ,CAAyB;IACjC,KAAK,CAAS;IACd,UAAU,CAAS;IACnB,QAAQ,CAAU;IAClB,SAAS,CAAU;IACnB,WAAW,CAAU;IACrB,YAAY,CAAQ;IACpB,aAAa,CAAQ;IACrB,aAAa,CAAQ;IACrB,kBAAkB,GAAyD,EAAE,CAAA;IAErF,YAAY,KAAmB,EAAE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W,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;AACvC,CAAC"}
@@ -0,0 +1,51 @@
1
+ export type ViewportAnchor = "top-left" | "top-center" | "top-right" | "center-left" | "center" | "center-right" | "bottom-left" | "bottom-center" | "bottom-right";
2
+ export interface SafeAreaInsets {
3
+ left: number;
4
+ right: number;
5
+ top: number;
6
+ bottom: number;
7
+ }
8
+ export interface SafeAreaOptions {
9
+ /** Merge extra insets in game units. */
10
+ extraInsets?: Partial<SafeAreaInsets>;
11
+ /** Read CSS env(safe-area-inset-*) values from the browser (default: true). */
12
+ useCssEnvInsets?: boolean;
13
+ }
14
+ export interface AnchorToViewportOptions {
15
+ /** Scene object for scale/resize events (auto-detected from target.scene when omitted). */
16
+ scene?: Phaser.Scene;
17
+ /** Target object to place in viewport coordinates. */
18
+ target: Phaser.GameObjects.GameObject;
19
+ /** Anchor point in viewport (default: "top-left"). */
20
+ anchor?: ViewportAnchor;
21
+ /** Offset from anchor in game units (default: 0). */
22
+ offsetX?: number;
23
+ offsetY?: number;
24
+ /** Apply safe-area insets (default: true). */
25
+ useSafeArea?: boolean;
26
+ /** Safe-area options (extra insets + css env toggle). */
27
+ safeArea?: SafeAreaOptions;
28
+ /** Update automatically on scale resize (default: true). */
29
+ autoResize?: boolean;
30
+ }
31
+ export interface ViewportAnchorHandle {
32
+ update(): void;
33
+ destroy(): void;
34
+ isDestroyed(): boolean;
35
+ getSafeAreaInsets(): SafeAreaInsets;
36
+ }
37
+ /**
38
+ * Anchor a game object to a viewport corner/edge/center.
39
+ *
40
+ * Position is computed in game coordinates and updated on resize.
41
+ * Assumes centered origin for best results (0.5, 0.5).
42
+ */
43
+ export declare function anchorToViewport(options: AnchorToViewportOptions): ViewportAnchorHandle;
44
+ /**
45
+ * Resolve safe-area insets in game units.
46
+ *
47
+ * Uses browser CSS env(safe-area-inset-*) values when available,
48
+ * then applies optional caller-provided extra insets.
49
+ */
50
+ export declare function getSafeAreaInsets(scene: Phaser.Scene, options?: SafeAreaOptions): SafeAreaInsets;
51
+ //# sourceMappingURL=anchorToViewport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchorToViewport.d.ts","sourceRoot":"","sources":["../src/anchorToViewport.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GACvB,UAAU,GACV,YAAY,GACZ,WAAW,GACX,aAAa,GACb,QAAQ,GACR,cAAc,GACd,aAAa,GACb,eAAe,GACf,cAAc,CAAA;AAEjB,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,eAAe;IAC/B,wCAAwC;IACxC,WAAW,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IACrC,+EAA+E;IAC/E,eAAe,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,uBAAuB;IACvC,2FAA2F;IAC3F,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,CAAA;IACpB,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,UAAU,CAAA;IACrC,sDAAsD;IACtD,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B,4DAA4D;IAC5D,UAAU,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,WAAW,oBAAoB;IACpC,MAAM,IAAI,IAAI,CAAA;IACd,OAAO,IAAI,IAAI,CAAA;IACf,WAAW,IAAI,OAAO,CAAA;IACtB,iBAAiB,IAAI,cAAc,CAAA;CACnC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,oBAAoB,CAwEvF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,GAAE,eAAoB,GAAG,cAAc,CAWpG"}
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Anchor a game object to a viewport corner/edge/center.
3
+ *
4
+ * Position is computed in game coordinates and updated on resize.
5
+ * Assumes centered origin for best results (0.5, 0.5).
6
+ */
7
+ export function anchorToViewport(options) {
8
+ const { target, scene: sceneFromOptions, anchor = "top-left", offsetX = 0, offsetY = 0, useSafeArea = true, safeArea, autoResize = true, } = options;
9
+ const scene = sceneFromOptions ?? target.scene;
10
+ if (!scene) {
11
+ throw new Error("anchorToViewport: scene not found. Pass options.scene or use a scene-owned target.");
12
+ }
13
+ let destroyed = false;
14
+ const placeTarget = () => {
15
+ if (destroyed)
16
+ return;
17
+ const viewport = getViewportRect(scene);
18
+ const insets = useSafeArea ? getSafeAreaInsets(scene, safeArea) : zeroInsets();
19
+ const left = viewport.x + insets.left;
20
+ const right = viewport.x + viewport.width - insets.right;
21
+ const top = viewport.y + insets.top;
22
+ const bottom = viewport.y + viewport.height - insets.bottom;
23
+ const availableWidth = Math.max(0, right - left);
24
+ const availableHeight = Math.max(0, bottom - top);
25
+ const size = getDisplaySize(target);
26
+ const halfW = size.width / 2;
27
+ const halfH = size.height / 2;
28
+ const x = computeAnchoredX(anchor, left, availableWidth, right, halfW) + offsetX;
29
+ const y = computeAnchoredY(anchor, top, availableHeight, bottom, halfH) + offsetY;
30
+ setTargetPosition(target, x, y);
31
+ };
32
+ const onResize = () => {
33
+ placeTarget();
34
+ };
35
+ if (autoResize) {
36
+ scene.scale.on("resize", onResize);
37
+ }
38
+ scene.events.once("shutdown", destroyHandle);
39
+ attachAutoDestroy(target, () => {
40
+ destroyHandle();
41
+ });
42
+ placeTarget();
43
+ function destroyHandle() {
44
+ if (destroyed)
45
+ return;
46
+ destroyed = true;
47
+ if (autoResize) {
48
+ scene.scale.off("resize", onResize);
49
+ }
50
+ scene.events.off("shutdown", destroyHandle);
51
+ }
52
+ return {
53
+ update: placeTarget,
54
+ destroy: destroyHandle,
55
+ isDestroyed: () => destroyed,
56
+ getSafeAreaInsets: () => (useSafeArea ? getSafeAreaInsets(scene, safeArea) : zeroInsets()),
57
+ };
58
+ }
59
+ /**
60
+ * Resolve safe-area insets in game units.
61
+ *
62
+ * Uses browser CSS env(safe-area-inset-*) values when available,
63
+ * then applies optional caller-provided extra insets.
64
+ */
65
+ export function getSafeAreaInsets(scene, options = {}) {
66
+ const { extraInsets, useCssEnvInsets = true } = options;
67
+ const cssInsetsPx = useCssEnvInsets ? getCssSafeAreaInsetsPx() : zeroInsets();
68
+ const scale = getCanvasToGameScale(scene);
69
+ return {
70
+ left: Math.max(0, cssInsetsPx.left * scale.x + (extraInsets?.left ?? 0)),
71
+ right: Math.max(0, cssInsetsPx.right * scale.x + (extraInsets?.right ?? 0)),
72
+ top: Math.max(0, cssInsetsPx.top * scale.y + (extraInsets?.top ?? 0)),
73
+ bottom: Math.max(0, cssInsetsPx.bottom * scale.y + (extraInsets?.bottom ?? 0)),
74
+ };
75
+ }
76
+ let safeAreaProbe = null;
77
+ function getCssSafeAreaInsetsPx() {
78
+ if (typeof document === "undefined")
79
+ return zeroInsets();
80
+ if (!safeAreaProbe) {
81
+ safeAreaProbe = document.createElement("div");
82
+ safeAreaProbe.style.position = "fixed";
83
+ safeAreaProbe.style.left = "0";
84
+ safeAreaProbe.style.top = "0";
85
+ safeAreaProbe.style.width = "0";
86
+ safeAreaProbe.style.height = "0";
87
+ safeAreaProbe.style.paddingLeft = "env(safe-area-inset-left)";
88
+ safeAreaProbe.style.paddingRight = "env(safe-area-inset-right)";
89
+ safeAreaProbe.style.paddingTop = "env(safe-area-inset-top)";
90
+ safeAreaProbe.style.paddingBottom = "env(safe-area-inset-bottom)";
91
+ safeAreaProbe.style.pointerEvents = "none";
92
+ safeAreaProbe.style.visibility = "hidden";
93
+ document.body.appendChild(safeAreaProbe);
94
+ }
95
+ const styles = getComputedStyle(safeAreaProbe);
96
+ return {
97
+ left: toFiniteNumber(styles.paddingLeft),
98
+ right: toFiniteNumber(styles.paddingRight),
99
+ top: toFiniteNumber(styles.paddingTop),
100
+ bottom: toFiniteNumber(styles.paddingBottom),
101
+ };
102
+ }
103
+ function getCanvasToGameScale(scene) {
104
+ const canvas = scene.game.canvas;
105
+ if (!canvas || typeof canvas.getBoundingClientRect !== "function")
106
+ return { x: 1, y: 1 };
107
+ const rect = canvas.getBoundingClientRect();
108
+ if (rect.width <= 0 || rect.height <= 0)
109
+ return { x: 1, y: 1 };
110
+ return {
111
+ x: scene.scale.width / rect.width,
112
+ y: scene.scale.height / rect.height,
113
+ };
114
+ }
115
+ function getViewportRect(scene) {
116
+ if (typeof scene.scale.getViewPort === "function") {
117
+ const out = scene.scale.getViewPort(scene.cameras.main);
118
+ if (out)
119
+ return out;
120
+ }
121
+ return new Phaser.Geom.Rectangle(0, 0, scene.scale.width, scene.scale.height);
122
+ }
123
+ function getDisplaySize(target) {
124
+ const withDisplay = target;
125
+ if (typeof withDisplay.displayWidth === "number" || typeof withDisplay.displayHeight === "number") {
126
+ return {
127
+ width: Math.max(0, withDisplay.displayWidth ?? 0),
128
+ height: Math.max(0, withDisplay.displayHeight ?? 0),
129
+ };
130
+ }
131
+ const withSize = target;
132
+ if (typeof withSize.width === "number" || typeof withSize.height === "number") {
133
+ return {
134
+ width: Math.max(0, withSize.width ?? 0),
135
+ height: Math.max(0, withSize.height ?? 0),
136
+ };
137
+ }
138
+ if (typeof target.getBounds === "function") {
139
+ const bounds = target.getBounds();
140
+ return { width: Math.max(0, bounds.width), height: Math.max(0, bounds.height) };
141
+ }
142
+ return { width: 0, height: 0 };
143
+ }
144
+ function setTargetPosition(target, x, y) {
145
+ const transform = target;
146
+ if (typeof transform.setPosition !== "function") {
147
+ throw new Error("anchorToViewport: target does not support setPosition(x, y)");
148
+ }
149
+ transform.setPosition(x, y);
150
+ }
151
+ function attachAutoDestroy(target, onDestroy) {
152
+ const emitter = target;
153
+ if (typeof emitter.once !== "function")
154
+ return;
155
+ emitter.once("destroy", onDestroy);
156
+ }
157
+ function computeAnchoredX(anchor, left, availableWidth, right, halfWidth) {
158
+ switch (anchor) {
159
+ case "top-left":
160
+ case "center-left":
161
+ case "bottom-left":
162
+ return left + halfWidth;
163
+ case "top-center":
164
+ case "center":
165
+ case "bottom-center":
166
+ return left + availableWidth / 2;
167
+ case "top-right":
168
+ case "center-right":
169
+ case "bottom-right":
170
+ return right - halfWidth;
171
+ default:
172
+ return left + halfWidth;
173
+ }
174
+ }
175
+ function computeAnchoredY(anchor, top, availableHeight, bottom, halfHeight) {
176
+ switch (anchor) {
177
+ case "top-left":
178
+ case "top-center":
179
+ case "top-right":
180
+ return top + halfHeight;
181
+ case "center-left":
182
+ case "center":
183
+ case "center-right":
184
+ return top + availableHeight / 2;
185
+ case "bottom-left":
186
+ case "bottom-center":
187
+ case "bottom-right":
188
+ return bottom - halfHeight;
189
+ default:
190
+ return top + halfHeight;
191
+ }
192
+ }
193
+ function toFiniteNumber(value) {
194
+ const parsed = Number.parseFloat(value);
195
+ return Number.isFinite(parsed) ? parsed : 0;
196
+ }
197
+ function zeroInsets() {
198
+ return { left: 0, right: 0, top: 0, bottom: 0 };
199
+ }
200
+ //# sourceMappingURL=anchorToViewport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchorToViewport.js","sourceRoot":"","sources":["../src/anchorToViewport.ts"],"names":[],"mappings":"AAkDA;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgC;IAChE,MAAM,EACL,MAAM,EACN,KAAK,EAAE,gBAAgB,EACvB,MAAM,GAAG,UAAU,EACnB,OAAO,GAAG,CAAC,EACX,OAAO,GAAG,CAAC,EACX,WAAW,GAAG,IAAI,EAClB,QAAQ,EACR,UAAU,GAAG,IAAI,GACjB,GAAG,OAAO,CAAA;IAEX,MAAM,K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
1
+ export interface DebugControlAdapter<TControl, TValue> {
2
+ read(control: TControl): TValue;
3
+ write(control: TControl, value: TValue): void;
4
+ subscribe?(control: TControl, onValue: (value: TValue) => void): (() => void) | void;
5
+ }
6
+ export interface BindDebugControlOptions<TControl, TValue> {
7
+ /** UI control instance to bind. */
8
+ control: TControl;
9
+ /** Optional explicit scene (auto-detected from control.scene when omitted). */
10
+ scene?: Phaser.Scene;
11
+ /** Model object used with `path` for get/set. */
12
+ target?: Record<string, unknown>;
13
+ /** Dot/bracket path (e.g. "player.speed" / "items[0].enabled"). */
14
+ path?: string;
15
+ /** Custom model getter (alternative to `target` + `path`). */
16
+ getValue?: () => TValue;
17
+ /** Custom model setter (alternative to `target` + `path`). */
18
+ setValue?: (value: TValue) => void;
19
+ /** Optional control adapter; inferred for known controls when omitted. */
20
+ adapter?: Partial<DebugControlAdapter<TControl, TValue>>;
21
+ /** Compare model/control values (default: Object.is). */
22
+ equals?: (a: TValue, b: TValue) => boolean;
23
+ /** Sync model -> control once at bind time (default: true). */
24
+ syncFromModelOnBind?: boolean;
25
+ /** Poll model each frame and push updates to control (default: true). */
26
+ syncFromModelEachFrame?: boolean;
27
+ }
28
+ export interface DebugControlBinding<TValue> {
29
+ syncFromModel(): void;
30
+ syncFromControl(): void;
31
+ getModelValue(): TValue;
32
+ destroy(): void;
33
+ isDestroyed(): boolean;
34
+ }
35
+ /**
36
+ * Two-way data binding between a debug control and a model source.
37
+ *
38
+ * Control -> model updates happen via control events.
39
+ * Model -> control updates happen on preupdate polling (or manual sync).
40
+ */
41
+ export declare function bindDebugControl<TControl, TValue>(options: BindDebugControlOptions<TControl, TValue>): DebugControlBinding<TValue>;
42
+ //# sourceMappingURL=bindDebugControl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindDebugControl.d.ts","sourceRoot":"","sources":["../src/bindDebugControl.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB,CAAC,QAAQ,EAAE,MAAM;IACpD,IAAI,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