@hrnec06/react_utils 1.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.
- package/dist/index.d.mts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +934 -0
- package/dist/index.mjs +891 -0
- package/package.json +44 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,934 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.tsx
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
Debugger: () => Debug,
|
|
34
|
+
useKeyListener: () => useKeyListener,
|
|
35
|
+
useListener: () => useListener,
|
|
36
|
+
useSignal: () => useSignal,
|
|
37
|
+
useUpdateEffect: () => useUpdateEffect,
|
|
38
|
+
useUpdatedRef: () => useUpdatedRef,
|
|
39
|
+
useWindowSize: () => useWindowSize
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(index_exports);
|
|
42
|
+
|
|
43
|
+
// src/hooks/useKeyListener.ts
|
|
44
|
+
var import_react = require("react");
|
|
45
|
+
function useKeyListener(key, options) {
|
|
46
|
+
const [pressing, setPressing] = (0, import_react.useState)(false);
|
|
47
|
+
const keyMatching = (e, strict) => {
|
|
48
|
+
if (strict && options?.ctrl && !e.ctrlKey)
|
|
49
|
+
return false;
|
|
50
|
+
if (strict && options?.shift && !e.shiftKey)
|
|
51
|
+
return false;
|
|
52
|
+
if (strict && options?.alt && !e.altKey)
|
|
53
|
+
return false;
|
|
54
|
+
return e.code == key;
|
|
55
|
+
};
|
|
56
|
+
(0, import_react.useEffect)(() => {
|
|
57
|
+
const downListener = (e) => {
|
|
58
|
+
if (!keyMatching(e, true)) return;
|
|
59
|
+
setPressing(true);
|
|
60
|
+
};
|
|
61
|
+
const upListener = (e) => {
|
|
62
|
+
if (!keyMatching(e, false)) return;
|
|
63
|
+
setPressing(false);
|
|
64
|
+
};
|
|
65
|
+
window.addEventListener("keydown", downListener);
|
|
66
|
+
window.addEventListener("keyup", upListener);
|
|
67
|
+
return () => {
|
|
68
|
+
window.removeEventListener("keydown", downListener);
|
|
69
|
+
window.removeEventListener("keyup", upListener);
|
|
70
|
+
};
|
|
71
|
+
}, []);
|
|
72
|
+
return pressing;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/hooks/useListener.ts
|
|
76
|
+
var import_react2 = require("react");
|
|
77
|
+
function useListener(element, event, listener, deps) {
|
|
78
|
+
(0, import_react2.useEffect)(() => {
|
|
79
|
+
element.addEventListener(event, listener);
|
|
80
|
+
return () => {
|
|
81
|
+
element.removeEventListener(event, listener);
|
|
82
|
+
};
|
|
83
|
+
}, deps);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/hooks/useUpdatedRef.ts
|
|
87
|
+
var import_react4 = require("react");
|
|
88
|
+
|
|
89
|
+
// src/hooks/useUpdateEffect.ts
|
|
90
|
+
var import_react3 = require("react");
|
|
91
|
+
function useUpdateEffect(callback, value) {
|
|
92
|
+
const isFirstRun = (0, import_react3.useRef)(true);
|
|
93
|
+
(0, import_react3.useEffect)(() => {
|
|
94
|
+
if (isFirstRun.current) {
|
|
95
|
+
isFirstRun.current = false;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
return callback();
|
|
99
|
+
}, value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/hooks/useUpdatedRef.ts
|
|
103
|
+
function useUpdatedRef(value) {
|
|
104
|
+
const ref = (0, import_react4.useRef)(value);
|
|
105
|
+
useUpdateEffect(() => {
|
|
106
|
+
ref.current = value;
|
|
107
|
+
}, [value]);
|
|
108
|
+
return ref;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/hooks/useWindowSize.ts
|
|
112
|
+
var import_react5 = require("react");
|
|
113
|
+
function useWindowSize() {
|
|
114
|
+
const [dimensions, setDimensions] = (0, import_react5.useState)([1920, 1080]);
|
|
115
|
+
(0, import_react5.useEffect)(() => {
|
|
116
|
+
setDimensions([window.innerWidth, window.innerHeight]);
|
|
117
|
+
const listener = () => {
|
|
118
|
+
setDimensions([window.innerWidth, window.innerHeight]);
|
|
119
|
+
};
|
|
120
|
+
window.addEventListener("resize", listener);
|
|
121
|
+
return () => {
|
|
122
|
+
window.removeEventListener("resize", listener);
|
|
123
|
+
};
|
|
124
|
+
}, []);
|
|
125
|
+
return dimensions;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/hooks/useSignal.ts
|
|
129
|
+
var import_react6 = require("react");
|
|
130
|
+
function useSignal(value) {
|
|
131
|
+
const [_value, _setValue] = (0, import_react6.useState)(value);
|
|
132
|
+
const signal = new Signal(_value, _setValue);
|
|
133
|
+
return signal;
|
|
134
|
+
}
|
|
135
|
+
var Signal = class {
|
|
136
|
+
constructor(_value, setState) {
|
|
137
|
+
this._value = _value;
|
|
138
|
+
this.setState = setState;
|
|
139
|
+
}
|
|
140
|
+
set value(value) {
|
|
141
|
+
this.setState(value);
|
|
142
|
+
}
|
|
143
|
+
get value() {
|
|
144
|
+
return this._value;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// src/debugger/Debugger.tsx
|
|
149
|
+
var import_util4 = require("@hrnec06/util");
|
|
150
|
+
var import_react12 = require("react");
|
|
151
|
+
|
|
152
|
+
// src/debugger/DebuggerContext.ts
|
|
153
|
+
var import_react7 = require("react");
|
|
154
|
+
var DebuggerContext = (0, import_react7.createContext)(void 0);
|
|
155
|
+
function useDebugger() {
|
|
156
|
+
const ctx = (0, import_react7.useContext)(DebuggerContext);
|
|
157
|
+
if (!ctx)
|
|
158
|
+
throw new Error(`useDebugger may be used only within DebuggerContext.Provider!`);
|
|
159
|
+
return ctx;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/debugger/Debugger.tsx
|
|
163
|
+
var import_clsx3 = __toESM(require("clsx"));
|
|
164
|
+
|
|
165
|
+
// src/debugger/DebuggerWindowResize.tsx
|
|
166
|
+
var import_util = require("@hrnec06/util");
|
|
167
|
+
var import_react8 = require("react");
|
|
168
|
+
var import_clsx = __toESM(require("clsx"));
|
|
169
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
170
|
+
function ResizeBorder() {
|
|
171
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
172
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
173
|
+
ResizeBar,
|
|
174
|
+
{
|
|
175
|
+
className: "-top-1.5 h-3 w-full cursor-ns-resize",
|
|
176
|
+
applyReposition: true,
|
|
177
|
+
onMove: ([, y]) => [0, y]
|
|
178
|
+
}
|
|
179
|
+
),
|
|
180
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
181
|
+
ResizeBar,
|
|
182
|
+
{
|
|
183
|
+
className: "-right-1.5 h-full w-3 cursor-ew-resize",
|
|
184
|
+
onMove: ([x]) => [-x, 0]
|
|
185
|
+
}
|
|
186
|
+
),
|
|
187
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
188
|
+
ResizeBar,
|
|
189
|
+
{
|
|
190
|
+
className: "-bottom-1.5 h-3 w-full cursor-ns-resize",
|
|
191
|
+
onMove: ([, y]) => [0, -y]
|
|
192
|
+
}
|
|
193
|
+
),
|
|
194
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
195
|
+
ResizeBar,
|
|
196
|
+
{
|
|
197
|
+
className: "-left-1.5 h-full w-3 cursor-ew-resize",
|
|
198
|
+
applyReposition: true,
|
|
199
|
+
onMove: ([x]) => [x, 0]
|
|
200
|
+
}
|
|
201
|
+
),
|
|
202
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
203
|
+
ResizeBar,
|
|
204
|
+
{
|
|
205
|
+
className: "-top-1.5 -left-1.5 size-3 cursor-nwse-resize",
|
|
206
|
+
applyReposition: true,
|
|
207
|
+
onMove: ([x, y]) => [x, y]
|
|
208
|
+
}
|
|
209
|
+
),
|
|
210
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
211
|
+
ResizeBar,
|
|
212
|
+
{
|
|
213
|
+
className: "-top-1.5 -right-1.5 size-3 cursor-nesw-resize",
|
|
214
|
+
applyReposition: "y",
|
|
215
|
+
onMove: ([x, y]) => [-x, y]
|
|
216
|
+
}
|
|
217
|
+
),
|
|
218
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
219
|
+
ResizeBar,
|
|
220
|
+
{
|
|
221
|
+
className: "-bottom-1.5 -right-1.5 size-3 cursor-nwse-resize",
|
|
222
|
+
onMove: ([x, y]) => [-x, -y]
|
|
223
|
+
}
|
|
224
|
+
),
|
|
225
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
226
|
+
ResizeBar,
|
|
227
|
+
{
|
|
228
|
+
className: "-bottom-1.5 -left-1.5 size-3 cursor-nesw-resize",
|
|
229
|
+
applyReposition: "x",
|
|
230
|
+
onMove: ([x, y]) => [x, -y]
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
] });
|
|
234
|
+
}
|
|
235
|
+
function ResizeBar({
|
|
236
|
+
className,
|
|
237
|
+
applyReposition = false,
|
|
238
|
+
onMove
|
|
239
|
+
}) {
|
|
240
|
+
const debug = useDebugger();
|
|
241
|
+
const [drag, setDrag] = (0, import_react8.useState)(null);
|
|
242
|
+
(0, import_react8.useEffect)(() => {
|
|
243
|
+
const mouseUp = () => {
|
|
244
|
+
if (!drag) return;
|
|
245
|
+
setDrag(null);
|
|
246
|
+
};
|
|
247
|
+
const mouseMove = (e) => {
|
|
248
|
+
if (!drag) return;
|
|
249
|
+
const offset = [
|
|
250
|
+
e.clientX - drag.dragOrigin[0],
|
|
251
|
+
e.clientY - drag.dragOrigin[1]
|
|
252
|
+
];
|
|
253
|
+
const newSize = onMove(
|
|
254
|
+
offset,
|
|
255
|
+
drag.originalSize,
|
|
256
|
+
drag.originalPosition
|
|
257
|
+
);
|
|
258
|
+
newSize[0] = drag.originalSize[0] - newSize[0];
|
|
259
|
+
newSize[1] = drag.originalSize[1] - newSize[1];
|
|
260
|
+
if (applyReposition !== false) {
|
|
261
|
+
const repositionOffset = (0, import_util.cloneVector2)(newSize);
|
|
262
|
+
(0, import_util.removeVector2)(repositionOffset, drag.originalSize);
|
|
263
|
+
debug.placement.reposition([
|
|
264
|
+
drag.originalPosition[0] - (applyReposition === true || applyReposition === "x" ? repositionOffset[0] : 0),
|
|
265
|
+
drag.originalPosition[1] - (applyReposition === true || applyReposition === "y" ? repositionOffset[1] : 0)
|
|
266
|
+
]);
|
|
267
|
+
}
|
|
268
|
+
debug.window.resize(newSize);
|
|
269
|
+
};
|
|
270
|
+
document.addEventListener("mouseup", mouseUp);
|
|
271
|
+
document.addEventListener("mousemove", mouseMove);
|
|
272
|
+
return () => {
|
|
273
|
+
document.removeEventListener("mouseup", mouseUp);
|
|
274
|
+
document.removeEventListener("mousemove", mouseMove);
|
|
275
|
+
};
|
|
276
|
+
}, [drag]);
|
|
277
|
+
const handleMouseDown = (e) => {
|
|
278
|
+
e.preventDefault();
|
|
279
|
+
setDrag({
|
|
280
|
+
dragOrigin: [e.clientX, e.clientY],
|
|
281
|
+
originalSize: debug.window.size,
|
|
282
|
+
originalPosition: debug.placement.position
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
286
|
+
"div",
|
|
287
|
+
{
|
|
288
|
+
onMouseDown: handleMouseDown,
|
|
289
|
+
className: (0, import_clsx.default)(
|
|
290
|
+
"absolute",
|
|
291
|
+
className
|
|
292
|
+
)
|
|
293
|
+
}
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// src/debugger/DebugParser.tsx
|
|
298
|
+
var import_react9 = require("react");
|
|
299
|
+
|
|
300
|
+
// src/debugger/DebuggerLogic.ts
|
|
301
|
+
function matchPath(_path, openPaths) {
|
|
302
|
+
for (const openPath of openPaths) {
|
|
303
|
+
const matchers = openPath.split(".");
|
|
304
|
+
const path = [..._path];
|
|
305
|
+
let passed = true;
|
|
306
|
+
while (path.length && passed) {
|
|
307
|
+
const pathItem = path.shift();
|
|
308
|
+
const matcher = matchers.shift();
|
|
309
|
+
if (matcher === "**")
|
|
310
|
+
return true;
|
|
311
|
+
if (matcher === "*") {
|
|
312
|
+
if (path.length > 1)
|
|
313
|
+
passed = false;
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (pathItem !== matcher)
|
|
317
|
+
passed = false;
|
|
318
|
+
}
|
|
319
|
+
if (path.length === 0 && passed)
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// src/debugger/DebugParser.tsx
|
|
326
|
+
var import_util2 = require("@hrnec06/util");
|
|
327
|
+
var import_react10 = __toESM(require("react"));
|
|
328
|
+
|
|
329
|
+
// src/debugger/DebuggerSymbols.tsx
|
|
330
|
+
var import_clsx2 = __toESM(require("clsx"));
|
|
331
|
+
var import_lucide_react = require("lucide-react");
|
|
332
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
333
|
+
function Char_Colon() {
|
|
334
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-[#ccccab]", children: ": " });
|
|
335
|
+
}
|
|
336
|
+
function Char_Comma() {
|
|
337
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-[#ccccab]", children: ", " });
|
|
338
|
+
}
|
|
339
|
+
function Char_Bracket({
|
|
340
|
+
text
|
|
341
|
+
}) {
|
|
342
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-[#da70d6]", children: text });
|
|
343
|
+
}
|
|
344
|
+
function Chevron_Toggle({
|
|
345
|
+
expanded,
|
|
346
|
+
onToggle
|
|
347
|
+
}) {
|
|
348
|
+
const handleClick = () => {
|
|
349
|
+
onToggle?.(!expanded);
|
|
350
|
+
};
|
|
351
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
352
|
+
"button",
|
|
353
|
+
{
|
|
354
|
+
onClick: handleClick,
|
|
355
|
+
className: (0, import_clsx2.default)(
|
|
356
|
+
"absolute",
|
|
357
|
+
"left-1 translate-y-0.5"
|
|
358
|
+
),
|
|
359
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
360
|
+
import_lucide_react.ChevronDown,
|
|
361
|
+
{
|
|
362
|
+
className: (0, import_clsx2.default)(
|
|
363
|
+
"size-4 text-primary-400 hover:text-zinc-500",
|
|
364
|
+
!expanded && "-rotate-90"
|
|
365
|
+
)
|
|
366
|
+
}
|
|
367
|
+
)
|
|
368
|
+
}
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/debugger/DebugParser.tsx
|
|
373
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
374
|
+
function ParseValue({
|
|
375
|
+
value,
|
|
376
|
+
path = []
|
|
377
|
+
}) {
|
|
378
|
+
const debug = useDebugger();
|
|
379
|
+
switch (typeof value) {
|
|
380
|
+
case "string":
|
|
381
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_String, { value });
|
|
382
|
+
case "bigint":
|
|
383
|
+
case "number":
|
|
384
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Number, { value });
|
|
385
|
+
case "boolean":
|
|
386
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Boolean, { value });
|
|
387
|
+
case "undefined":
|
|
388
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Keyword, { value: "undefined" });
|
|
389
|
+
case "function":
|
|
390
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Function, { value });
|
|
391
|
+
case "symbol":
|
|
392
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Symbol, { value });
|
|
393
|
+
case "object": {
|
|
394
|
+
if (value === null)
|
|
395
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Keyword, { value: "null" });
|
|
396
|
+
const isRootObject = path.length === 0;
|
|
397
|
+
const shouldBeExpanded = isRootObject && debug.options.openRoot || matchPath(path, debug.paths.open) && !matchPath(path, debug.paths.exclude);
|
|
398
|
+
if (Array.isArray(value)) {
|
|
399
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Array, { value, path, defaultExpanded: shouldBeExpanded });
|
|
400
|
+
}
|
|
401
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Object, { value, path, defaultExpanded: shouldBeExpanded });
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
function Value_String({
|
|
406
|
+
value,
|
|
407
|
+
noEncase = false
|
|
408
|
+
}) {
|
|
409
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-[#ce9178]", children: (0, import_util2.padString)(value, noEncase ? 0 : 1, '"') });
|
|
410
|
+
}
|
|
411
|
+
function Value_Number({
|
|
412
|
+
value
|
|
413
|
+
}) {
|
|
414
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-[#a7ce9b]", children: value });
|
|
415
|
+
}
|
|
416
|
+
function Value_Boolean({
|
|
417
|
+
value
|
|
418
|
+
}) {
|
|
419
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Keyword, { value: value ? "true" : "false" });
|
|
420
|
+
}
|
|
421
|
+
function Value_Function({
|
|
422
|
+
value
|
|
423
|
+
}) {
|
|
424
|
+
const argsMatch = value.toString().match(/^[^(]*\(\s*([^)]*)\)/);
|
|
425
|
+
let args = "";
|
|
426
|
+
if (argsMatch && argsMatch.length > 1) {
|
|
427
|
+
args = argsMatch[1];
|
|
428
|
+
}
|
|
429
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
430
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-[#f2824a]", children: "\u0192 " }),
|
|
431
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: `${value.name}(${args})` })
|
|
432
|
+
] });
|
|
433
|
+
}
|
|
434
|
+
function Value_Keyword({
|
|
435
|
+
value
|
|
436
|
+
}) {
|
|
437
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-[#439ccb]", children: value });
|
|
438
|
+
}
|
|
439
|
+
function Value_Object({
|
|
440
|
+
value,
|
|
441
|
+
path,
|
|
442
|
+
defaultExpanded = false
|
|
443
|
+
}) {
|
|
444
|
+
const debug = useDebugger();
|
|
445
|
+
const [expanded, setExpanded] = (0, import_react9.useState)(defaultExpanded);
|
|
446
|
+
const objectEntries = (0, import_util2.entries)(value);
|
|
447
|
+
const collapsedPreview = (0, import_react9.useMemo)(() => {
|
|
448
|
+
const children = [];
|
|
449
|
+
const keyList = (0, import_util2.keys)(value);
|
|
450
|
+
for (let i = 0; i < Math.min(keyList.length, 6); i++) {
|
|
451
|
+
children.push(
|
|
452
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react10.default.Fragment, { children: [
|
|
453
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Object_Key, { text: keyList[i] }),
|
|
454
|
+
i < keyList.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Comma, {})
|
|
455
|
+
] }, i)
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
if (keyList.length > 6)
|
|
459
|
+
children.push(/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-zinc-500", children: "..." }, "rest"));
|
|
460
|
+
return children;
|
|
461
|
+
}, [value]);
|
|
462
|
+
(0, import_react9.useLayoutEffect)(() => {
|
|
463
|
+
debug.event.expand(path, expanded);
|
|
464
|
+
}, [expanded]);
|
|
465
|
+
const handleExpand = (state) => {
|
|
466
|
+
setExpanded(state);
|
|
467
|
+
};
|
|
468
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
469
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Chevron_Toggle, { expanded, onToggle: handleExpand }),
|
|
470
|
+
Object.getPrototypeOf(value) !== Object.prototype && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
|
|
471
|
+
"(",
|
|
472
|
+
value.constructor.name,
|
|
473
|
+
") "
|
|
474
|
+
] }),
|
|
475
|
+
expanded ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
476
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Bracket, { text: "{" }),
|
|
477
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("ul", { className: "pl-4 ml-1 border-l border-l-primary-400", children: objectEntries.map(([key, value2], ix) => {
|
|
478
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { children: [
|
|
479
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Object_Key, { text: key }),
|
|
480
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Colon, {}),
|
|
481
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParseValue, { value: value2, path: [...path, `${key}`] }),
|
|
482
|
+
ix < objectEntries.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Comma, {})
|
|
483
|
+
] }, ix);
|
|
484
|
+
}) }),
|
|
485
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Bracket, { text: "}" })
|
|
486
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
487
|
+
"div",
|
|
488
|
+
{
|
|
489
|
+
className: "inline-block cursor-pointer",
|
|
490
|
+
onClick: () => setExpanded(true),
|
|
491
|
+
children: [
|
|
492
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Bracket, { text: "{" }),
|
|
493
|
+
" ",
|
|
494
|
+
collapsedPreview,
|
|
495
|
+
" ",
|
|
496
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Bracket, { text: "}" })
|
|
497
|
+
]
|
|
498
|
+
}
|
|
499
|
+
)
|
|
500
|
+
] });
|
|
501
|
+
}
|
|
502
|
+
function Value_Array({
|
|
503
|
+
value,
|
|
504
|
+
path,
|
|
505
|
+
defaultExpanded = false
|
|
506
|
+
}) {
|
|
507
|
+
const debug = useDebugger();
|
|
508
|
+
const [expanded, setExpanded] = (0, import_react9.useState)(defaultExpanded);
|
|
509
|
+
const children = (0, import_react9.useMemo)(() => {
|
|
510
|
+
const children2 = [];
|
|
511
|
+
let ix = 0;
|
|
512
|
+
while (ix < value.length) {
|
|
513
|
+
const nextTarget = Math.min(ix + debug.options.compactArrays, value.length);
|
|
514
|
+
children2.push(
|
|
515
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("li", { children: (() => {
|
|
516
|
+
const children3 = [];
|
|
517
|
+
for (; ix < nextTarget; ix++) {
|
|
518
|
+
children3.push(
|
|
519
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react10.default.Fragment, { children: [
|
|
520
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParseValue, { value: value[ix], path: [...path, `${ix}`] }),
|
|
521
|
+
ix < value.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Comma, {})
|
|
522
|
+
] }, ix)
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
return children3;
|
|
526
|
+
})() }, ix)
|
|
527
|
+
);
|
|
528
|
+
ix = nextTarget;
|
|
529
|
+
}
|
|
530
|
+
return children2;
|
|
531
|
+
}, [debug.options.compactArrays, value]);
|
|
532
|
+
const collapsedPreview = (0, import_react9.useMemo)(() => {
|
|
533
|
+
const children2 = [];
|
|
534
|
+
for (let i = 0; i < Math.min(value.length, 6); i++) {
|
|
535
|
+
children2.push(
|
|
536
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react10.default.Fragment, { children: [
|
|
537
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParseValue_ToSimple, { value: value[i] }),
|
|
538
|
+
i < value.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Comma, {})
|
|
539
|
+
] }, i)
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
if (value.length > 6)
|
|
543
|
+
children2.push(/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-zinc-500", children: "..." }, "rest"));
|
|
544
|
+
return children2;
|
|
545
|
+
}, [value]);
|
|
546
|
+
(0, import_react9.useLayoutEffect)(() => {
|
|
547
|
+
debug.event.expand(path, expanded);
|
|
548
|
+
}, [expanded]);
|
|
549
|
+
const handleExpand = (state) => {
|
|
550
|
+
setExpanded(state);
|
|
551
|
+
};
|
|
552
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
553
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Chevron_Toggle, { expanded, onToggle: handleExpand }),
|
|
554
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: `(${value.length}) ` }),
|
|
555
|
+
expanded ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
556
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Bracket, { text: "[" }),
|
|
557
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("ul", { className: "pl-4 ml-1 border-l border-l-primary-400", children }),
|
|
558
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Bracket, { text: "]" })
|
|
559
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
560
|
+
"div",
|
|
561
|
+
{
|
|
562
|
+
className: "inline-block cursor-pointer",
|
|
563
|
+
onClick: () => setExpanded(true),
|
|
564
|
+
children: [
|
|
565
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Bracket, { text: "[" }),
|
|
566
|
+
collapsedPreview,
|
|
567
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Bracket, { text: "]" })
|
|
568
|
+
]
|
|
569
|
+
}
|
|
570
|
+
)
|
|
571
|
+
] });
|
|
572
|
+
}
|
|
573
|
+
function Value_Object_Key({
|
|
574
|
+
text
|
|
575
|
+
}) {
|
|
576
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-[#9CDCF0]", children: text });
|
|
577
|
+
}
|
|
578
|
+
function Value_Symbol({
|
|
579
|
+
value
|
|
580
|
+
}) {
|
|
581
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
582
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Keyword, { value: "Symbol" }),
|
|
583
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Bracket, { text: "(" }),
|
|
584
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: value.description }),
|
|
585
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Char_Bracket, { text: ")" })
|
|
586
|
+
] });
|
|
587
|
+
}
|
|
588
|
+
function ParseValue_ToSimple({
|
|
589
|
+
value
|
|
590
|
+
}) {
|
|
591
|
+
const MAX_LENGTH = 16;
|
|
592
|
+
switch (typeof value) {
|
|
593
|
+
case "bigint":
|
|
594
|
+
case "number": {
|
|
595
|
+
const numStr = value.toString();
|
|
596
|
+
if (numStr.length > MAX_LENGTH)
|
|
597
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Keyword, { value: typeof value });
|
|
598
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Number, { value });
|
|
599
|
+
}
|
|
600
|
+
case "boolean":
|
|
601
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Boolean, { value });
|
|
602
|
+
case "function":
|
|
603
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Function, { value });
|
|
604
|
+
case "object": {
|
|
605
|
+
if (value === null)
|
|
606
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Keyword, { value: "null" });
|
|
607
|
+
const className = Object.getPrototypeOf(value) !== Object.prototype ? value.constructor.name : null;
|
|
608
|
+
if (className === null || className.length > MAX_LENGTH)
|
|
609
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Keyword, { value: "object" });
|
|
610
|
+
return className;
|
|
611
|
+
}
|
|
612
|
+
case "string": {
|
|
613
|
+
if (value.length > MAX_LENGTH)
|
|
614
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_String, { value: "string", noEncase: true });
|
|
615
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_String, { value });
|
|
616
|
+
}
|
|
617
|
+
case "symbol": {
|
|
618
|
+
if (!value.description || value.description.length > MAX_LENGTH)
|
|
619
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Keyword, { value: "Symbol" });
|
|
620
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Symbol, { value });
|
|
621
|
+
}
|
|
622
|
+
case "undefined":
|
|
623
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Value_Keyword, { value: "undefined" });
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// src/debugger/DebuggerScrollBar.tsx
|
|
628
|
+
var import_util3 = require("@hrnec06/util");
|
|
629
|
+
var import_react11 = require("react");
|
|
630
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
631
|
+
function ScrollBar({
|
|
632
|
+
containerHeight,
|
|
633
|
+
scrollHeight
|
|
634
|
+
}) {
|
|
635
|
+
const debug = useDebugger();
|
|
636
|
+
const [wrapperHeight, setWrapperHeight] = (0, import_react11.useState)(0);
|
|
637
|
+
const barHeight = containerHeight / (scrollHeight + containerHeight) * wrapperHeight;
|
|
638
|
+
const barTop = (wrapperHeight - barHeight) * debug.scroll.progress;
|
|
639
|
+
const [grab, setGrab] = (0, import_react11.useState)(null);
|
|
640
|
+
const [grabOffset, setGrabOffset] = (0, import_react11.useState)(null);
|
|
641
|
+
const wrapperRef = (0, import_react11.useRef)(null);
|
|
642
|
+
(0, import_react11.useEffect)(() => {
|
|
643
|
+
if (!wrapperRef.current) return;
|
|
644
|
+
const observer = new ResizeObserver(() => updateWrapperHeight());
|
|
645
|
+
observer.observe(wrapperRef.current);
|
|
646
|
+
updateWrapperHeight();
|
|
647
|
+
return () => {
|
|
648
|
+
observer.disconnect();
|
|
649
|
+
};
|
|
650
|
+
}, [wrapperRef]);
|
|
651
|
+
useListener(document, "mouseup", (event) => {
|
|
652
|
+
if (!grab) return;
|
|
653
|
+
setGrab(null);
|
|
654
|
+
setGrabOffset(null);
|
|
655
|
+
}, [grab]);
|
|
656
|
+
useListener(document, "mousemove", (event) => {
|
|
657
|
+
if (!grab) return;
|
|
658
|
+
setGrabOffset(event.clientY - (grab.windowOrigin - grab.positionOrigin * (wrapperHeight - barHeight)));
|
|
659
|
+
}, [grab]);
|
|
660
|
+
(0, import_react11.useEffect)(() => {
|
|
661
|
+
if (grabOffset === null) return;
|
|
662
|
+
const fixedOffset = (0, import_util3.minmax)(grabOffset, 0, wrapperHeight - barHeight) / (wrapperHeight - barHeight);
|
|
663
|
+
debug.scroll.setProgress(fixedOffset);
|
|
664
|
+
}, [grabOffset]);
|
|
665
|
+
const updateWrapperHeight = () => {
|
|
666
|
+
if (!wrapperRef.current) return;
|
|
667
|
+
setWrapperHeight(wrapperRef.current.clientHeight);
|
|
668
|
+
};
|
|
669
|
+
const handleWraperMouseDown = (e) => {
|
|
670
|
+
e.preventDefault();
|
|
671
|
+
if (grab) return;
|
|
672
|
+
};
|
|
673
|
+
const handleMouseDown = (e) => {
|
|
674
|
+
e.preventDefault();
|
|
675
|
+
if (grab) return;
|
|
676
|
+
setGrab({
|
|
677
|
+
positionOrigin: debug.scroll.progress,
|
|
678
|
+
windowOrigin: e.clientY
|
|
679
|
+
});
|
|
680
|
+
};
|
|
681
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "p-1 border-l border-l-primary-600", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
682
|
+
"div",
|
|
683
|
+
{
|
|
684
|
+
onMouseDown: handleWraperMouseDown,
|
|
685
|
+
ref: wrapperRef,
|
|
686
|
+
className: "h-full flex-shrink-0",
|
|
687
|
+
children: debug.scroll.isScrollable && wrapperHeight > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
688
|
+
"div",
|
|
689
|
+
{
|
|
690
|
+
onMouseDown: handleMouseDown,
|
|
691
|
+
className: "bg-primary-500 hover:bg-primary-400 w-2 rounded-lg",
|
|
692
|
+
style: {
|
|
693
|
+
transform: `translateY(${barTop}px)`,
|
|
694
|
+
height: `${barHeight}px`
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
)
|
|
698
|
+
}
|
|
699
|
+
) });
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// src/debugger/Debugger.tsx
|
|
703
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
704
|
+
function Debug({
|
|
705
|
+
value,
|
|
706
|
+
openPaths,
|
|
707
|
+
excludePaths,
|
|
708
|
+
size = "normal",
|
|
709
|
+
compactArrays = 1,
|
|
710
|
+
autoHeight = false,
|
|
711
|
+
openRoot = true
|
|
712
|
+
}) {
|
|
713
|
+
const LS_POS_KEY = "debugger_position";
|
|
714
|
+
const LS_SIZE_KEY = "debugger_size";
|
|
715
|
+
const LS_EXPAND_KEY = "debugger_expanded";
|
|
716
|
+
const f9_pressed = useKeyListener("F9");
|
|
717
|
+
const [position, setPosition] = (0, import_react12.useState)([0, 0]);
|
|
718
|
+
const [grab, setGrab] = (0, import_react12.useState)(null);
|
|
719
|
+
const [grabOffset, setGrabOffset] = (0, import_react12.useState)(null);
|
|
720
|
+
const [windowSize, setWindowSize] = (0, import_react12.useState)([500, 500]);
|
|
721
|
+
const [scrollHeight, setScrollHeight] = (0, import_react12.useState)(0);
|
|
722
|
+
const [containerHeight, setContainerHeight] = (0, import_react12.useState)(0);
|
|
723
|
+
const [scrollProgress, setScrollProgress] = (0, import_react12.useState)(0);
|
|
724
|
+
const font = (0, import_react12.useMemo)(() => {
|
|
725
|
+
switch (size) {
|
|
726
|
+
case "tiny":
|
|
727
|
+
return { fontSize: 12, lineHeight: 16 };
|
|
728
|
+
case "normal":
|
|
729
|
+
return { fontSize: 14, lineHeight: 20 };
|
|
730
|
+
case "big":
|
|
731
|
+
return { fontSize: 16, lineHeight: 24 };
|
|
732
|
+
}
|
|
733
|
+
}, [size]);
|
|
734
|
+
const containerRef = (0, import_react12.useRef)(null);
|
|
735
|
+
(0, import_react12.useEffect)(() => {
|
|
736
|
+
const mouseUp = (e) => {
|
|
737
|
+
if (!grab) return;
|
|
738
|
+
setPosition(finalPositionRef.current);
|
|
739
|
+
setGrab(null);
|
|
740
|
+
setGrabOffset(null);
|
|
741
|
+
};
|
|
742
|
+
const mouseMove = (e) => {
|
|
743
|
+
if (!grab) return;
|
|
744
|
+
setGrabOffset([
|
|
745
|
+
e.clientX - grab.windowOrigin[0],
|
|
746
|
+
e.clientY - grab.windowOrigin[1]
|
|
747
|
+
]);
|
|
748
|
+
};
|
|
749
|
+
document.addEventListener("mouseup", mouseUp);
|
|
750
|
+
document.addEventListener("mousemove", mouseMove);
|
|
751
|
+
return () => {
|
|
752
|
+
document.removeEventListener("mouseup", mouseUp);
|
|
753
|
+
document.removeEventListener("mousemove", mouseMove);
|
|
754
|
+
};
|
|
755
|
+
}, [grab]);
|
|
756
|
+
(0, import_react12.useLayoutEffect)(() => {
|
|
757
|
+
updateScrollHeight();
|
|
758
|
+
}, [windowSize, value, size, containerRef]);
|
|
759
|
+
const isScrollable = (0, import_react12.useMemo)(() => scrollHeight > 0, [scrollHeight]);
|
|
760
|
+
(0, import_react12.useEffect)(() => {
|
|
761
|
+
try {
|
|
762
|
+
const saved_position = localStorage.getItem(LS_POS_KEY);
|
|
763
|
+
if (saved_position) {
|
|
764
|
+
const [v1, v2] = saved_position.split(",");
|
|
765
|
+
if (v1 === void 0 || v2 === void 0)
|
|
766
|
+
throw new Error("Invalid vector: " + saved_position);
|
|
767
|
+
const [v1_p, v2_p] = [parseInt(v1), parseInt(v2)];
|
|
768
|
+
if (isNaN(v1_p) || isNaN(v2_p))
|
|
769
|
+
throw new Error("Invalid vector values: " + saved_position);
|
|
770
|
+
setPosition([v1_p, v2_p]);
|
|
771
|
+
}
|
|
772
|
+
} catch (error) {
|
|
773
|
+
console.error(`Error loading saved position: `, error);
|
|
774
|
+
localStorage.removeItem(LS_POS_KEY);
|
|
775
|
+
}
|
|
776
|
+
}, []);
|
|
777
|
+
(0, import_react12.useEffect)(() => {
|
|
778
|
+
try {
|
|
779
|
+
const saved_size = localStorage.getItem(LS_SIZE_KEY);
|
|
780
|
+
if (saved_size) {
|
|
781
|
+
const [v1, v2] = saved_size.split(",");
|
|
782
|
+
if (v1 === void 0 || v2 === void 0)
|
|
783
|
+
throw new Error("Invalid vector: " + saved_size);
|
|
784
|
+
const [v1_p, v2_p] = [parseInt(v1), parseInt(v2)];
|
|
785
|
+
if (isNaN(v1_p) || isNaN(v2_p))
|
|
786
|
+
throw new Error("Invalid vector values: " + saved_size);
|
|
787
|
+
setWindowSize([v1_p, v2_p]);
|
|
788
|
+
}
|
|
789
|
+
} catch (error) {
|
|
790
|
+
console.error(`Error loading saved size: `, error);
|
|
791
|
+
localStorage.removeItem(LS_POS_KEY);
|
|
792
|
+
}
|
|
793
|
+
}, []);
|
|
794
|
+
useUpdateEffect(() => {
|
|
795
|
+
localStorage.setItem(LS_POS_KEY, `${position[0]},${position[1]}`);
|
|
796
|
+
}, [position]);
|
|
797
|
+
useUpdateEffect(() => {
|
|
798
|
+
localStorage.setItem(LS_SIZE_KEY, `${windowSize[0]},${windowSize[1]}`);
|
|
799
|
+
}, [windowSize]);
|
|
800
|
+
(0, import_react12.useEffect)(() => {
|
|
801
|
+
if (!f9_pressed)
|
|
802
|
+
return;
|
|
803
|
+
setPosition([0, 0]);
|
|
804
|
+
}, [f9_pressed]);
|
|
805
|
+
const finalPosition = (0, import_react12.useMemo)(() => {
|
|
806
|
+
return [
|
|
807
|
+
position[0] + (grabOffset?.[0] ?? 0),
|
|
808
|
+
position[1] + (grabOffset?.[1] ?? 0)
|
|
809
|
+
];
|
|
810
|
+
}, [position, grabOffset]);
|
|
811
|
+
const finalPositionRef = useUpdatedRef(finalPosition);
|
|
812
|
+
const calculateContainerHeight = () => {
|
|
813
|
+
if (!containerRef.current) return 0;
|
|
814
|
+
return containerRef.current.clientHeight;
|
|
815
|
+
};
|
|
816
|
+
const calculateScrollHeight = () => {
|
|
817
|
+
if (!containerRef.current) return 0;
|
|
818
|
+
return containerRef.current.scrollHeight - calculateContainerHeight();
|
|
819
|
+
};
|
|
820
|
+
const updateScrollHeight = () => {
|
|
821
|
+
if (!containerRef.current) return;
|
|
822
|
+
setScrollHeight(calculateScrollHeight());
|
|
823
|
+
setContainerHeight(calculateContainerHeight());
|
|
824
|
+
};
|
|
825
|
+
const handleMouseDown = (e) => {
|
|
826
|
+
e.preventDefault();
|
|
827
|
+
setGrab({
|
|
828
|
+
positionOrigin: position,
|
|
829
|
+
windowOrigin: [e.clientX, e.clientY]
|
|
830
|
+
});
|
|
831
|
+
};
|
|
832
|
+
const handleExpandChange = (path, state) => {
|
|
833
|
+
if (!containerRef.current) return;
|
|
834
|
+
setScrollProgress((0, import_util4.minmax)(scrollProgress * scrollHeight / calculateScrollHeight(), 0, 1));
|
|
835
|
+
updateScrollHeight();
|
|
836
|
+
};
|
|
837
|
+
const handleWheel = (e) => {
|
|
838
|
+
const moveByPX = font.lineHeight * 3;
|
|
839
|
+
let addProgress = moveByPX / scrollHeight;
|
|
840
|
+
if (e.deltaY < 0)
|
|
841
|
+
addProgress *= -1;
|
|
842
|
+
setScrollProgress((p) => (0, import_util4.minmax)(p + addProgress, 0, 1));
|
|
843
|
+
};
|
|
844
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
845
|
+
DebuggerContext.Provider,
|
|
846
|
+
{
|
|
847
|
+
value: {
|
|
848
|
+
paths: {
|
|
849
|
+
exclude: excludePaths ?? [],
|
|
850
|
+
open: openPaths ?? []
|
|
851
|
+
},
|
|
852
|
+
options: {
|
|
853
|
+
compactArrays,
|
|
854
|
+
autoHeight,
|
|
855
|
+
openRoot
|
|
856
|
+
},
|
|
857
|
+
window: {
|
|
858
|
+
resize: setWindowSize,
|
|
859
|
+
size: windowSize
|
|
860
|
+
},
|
|
861
|
+
placement: {
|
|
862
|
+
reposition: setPosition,
|
|
863
|
+
position
|
|
864
|
+
},
|
|
865
|
+
event: {
|
|
866
|
+
expand: handleExpandChange
|
|
867
|
+
},
|
|
868
|
+
scroll: {
|
|
869
|
+
setProgress: setScrollProgress,
|
|
870
|
+
progress: scrollProgress,
|
|
871
|
+
isScrollable
|
|
872
|
+
}
|
|
873
|
+
},
|
|
874
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "fixed pointer-events-none w-full h-full left-0 top-0 overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
875
|
+
"div",
|
|
876
|
+
{
|
|
877
|
+
className: (0, import_clsx3.default)(
|
|
878
|
+
"absolute font-jetbrains pointer-events-auto",
|
|
879
|
+
size === "tiny" && "text-xs",
|
|
880
|
+
size === "normal" && "text-sm",
|
|
881
|
+
size === "big" && "text-base"
|
|
882
|
+
),
|
|
883
|
+
style: {
|
|
884
|
+
left: finalPosition[0],
|
|
885
|
+
top: finalPosition[1],
|
|
886
|
+
width: windowSize[0],
|
|
887
|
+
height: windowSize[1]
|
|
888
|
+
},
|
|
889
|
+
children: [
|
|
890
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ResizeBorder, {}),
|
|
891
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
892
|
+
"div",
|
|
893
|
+
{
|
|
894
|
+
onWheel: handleWheel,
|
|
895
|
+
className: "bg-[#1f1f1f] shadow-lg rounded-md border border-primary-400 w-full h-full overflow-hidden flex",
|
|
896
|
+
children: [
|
|
897
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
898
|
+
"div",
|
|
899
|
+
{
|
|
900
|
+
ref: containerRef,
|
|
901
|
+
onMouseDown: handleMouseDown,
|
|
902
|
+
className: " cursor-grab w-full",
|
|
903
|
+
style: {
|
|
904
|
+
transform: `translateY(${-(scrollProgress * scrollHeight)}px)`
|
|
905
|
+
},
|
|
906
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "p-3 pl-5", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ParseValue, { value }) })
|
|
907
|
+
}
|
|
908
|
+
),
|
|
909
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
910
|
+
ScrollBar,
|
|
911
|
+
{
|
|
912
|
+
containerHeight,
|
|
913
|
+
scrollHeight
|
|
914
|
+
}
|
|
915
|
+
)
|
|
916
|
+
]
|
|
917
|
+
}
|
|
918
|
+
)
|
|
919
|
+
]
|
|
920
|
+
}
|
|
921
|
+
) })
|
|
922
|
+
}
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
926
|
+
0 && (module.exports = {
|
|
927
|
+
Debugger,
|
|
928
|
+
useKeyListener,
|
|
929
|
+
useListener,
|
|
930
|
+
useSignal,
|
|
931
|
+
useUpdateEffect,
|
|
932
|
+
useUpdatedRef,
|
|
933
|
+
useWindowSize
|
|
934
|
+
});
|