lone-format 0.16.0 → 0.16.1

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,853 @@
1
+ import { defineComponent as ye, useCssVars as ve, ref as B, computed as _, resolveComponent as Be, createElementBlock as p, openBlock as m, createElementVNode as N, createCommentVNode as O, withKeys as W, withModifiers as ue, toDisplayString as V, Fragment as xe, renderList as Ne, createVNode as pe, normalizeClass as me, nextTick as Q, watch as Ee } from "vue";
2
+ import { JSONPath as Se } from "jsonpath-plus";
3
+ import { _ as ge } from "./_plugin-vue_export-helper-CHgC5LLL.js";
4
+ const ie = "__protected_number__", ke = Symbol("JsonFormatProtectedNumber"), ce = (k) => {
5
+ const I = { [ie]: k };
6
+ return Object.defineProperty(I, ke, {
7
+ value: !0,
8
+ enumerable: !1
9
+ }), I;
10
+ }, A = (k) => k !== null && typeof k == "object" && !Array.isArray(k) && k[ke] === !0 && ie in k && Object.keys(k).length === 1, z = (k) => A(k) ? k[ie] : "", je = { class: "json-node" }, Oe = {
11
+ key: 0,
12
+ class: "json-node__container"
13
+ }, Ae = { class: "json-node__line" }, we = ["contenteditable", "onKeydown"], Te = {
14
+ key: 1,
15
+ class: "json-node__colon"
16
+ }, Je = ["title"], $e = ["title"], Pe = {
17
+ key: 4,
18
+ class: "json-node__comma"
19
+ }, Ve = {
20
+ key: 0,
21
+ class: "json-node__children"
22
+ }, Ce = { class: "json-node__children-content" }, De = { class: "json-node__line json-node__closing-bracket" }, Fe = { class: "json-node__bracket" }, Re = {
23
+ key: 0,
24
+ class: "json-node__comma"
25
+ }, He = {
26
+ key: 1,
27
+ class: "json-node__primitive"
28
+ }, Le = ["contenteditable", "onKeydown"], Ke = {
29
+ key: 1,
30
+ class: "json-node__colon"
31
+ }, Ie = ["title"], Ue = ["contenteditable", "onKeydown"], Me = {
32
+ key: 0,
33
+ class: "json-node__comma"
34
+ }, We = /* @__PURE__ */ ye({
35
+ name: "JsonNode",
36
+ __name: "JsonNode",
37
+ props: {
38
+ value: {},
39
+ keyName: {},
40
+ level: {},
41
+ path: { default: "" },
42
+ expanded: {},
43
+ isLast: { type: Boolean, default: !1 },
44
+ theme: {}
45
+ },
46
+ emits: ["update:value", "toggle-expand", "copy", "update:key"],
47
+ setup(k, { emit: I }) {
48
+ ve((o) => ({
49
+ "4f4db4bc": o.level,
50
+ "186d1fa5": o.theme.colors.syntaxKey,
51
+ "8d641e1a": o.theme.colors.hoverBackground,
52
+ "10ce1aee": o.theme.colors.syntaxBracket,
53
+ "4ad6c066": o.theme.colors.collapsedText,
54
+ "659f9064": o.theme.colors.collapsedBackground,
55
+ "2f0b520e": o.theme.colors.collapsedBackgroundHover,
56
+ dd63ddea: o.theme.colors.syntaxString,
57
+ ee5ce77a: o.theme.colors.syntaxNumber,
58
+ "0c78da6e": o.theme.colors.syntaxBoolean,
59
+ "158f25fe": o.theme.colors.syntaxNull,
60
+ e5bff3b6: o.theme.colors.background,
61
+ "51d4ce7a": o.theme.colors.selectionBackground,
62
+ "0dd4e092": o.theme.colors.indentLine
63
+ }));
64
+ const a = k, C = I, g = B(!1), f = B(!1), x = B(""), b = B(""), y = B("string"), v = B(null), j = B(null), U = _(() => A(a.value) ? !1 : a.value !== null && typeof a.value == "object"), w = _(() => Array.isArray(a.value)), h = _(() => a.path ? a.path : a.keyName ? a.keyName : "root"), T = _(() => a.expanded.has(h.value)), X = _(() => a.keyName), D = _(() => w.value ? "[" : "{"), Y = _(() => w.value ? "]" : "}"), ee = _(() => {
65
+ if (!a.value) return "";
66
+ const c = Object.keys(a.value).length;
67
+ return w.value ? c > 0 ? ` ${c} items ` : " " : c > 0 ? ` ${c} keys ` : " ";
68
+ }), se = _(() => {
69
+ const o = typeof a.value;
70
+ return a.value === null ? "json-node__value--null" : o === "boolean" ? "json-node__value--boolean" : o === "number" || A(a.value) ? "json-node__value--number" : o === "string" ? "json-node__value--string" : "";
71
+ }), Z = _(() => a.value === null ? "null" : typeof a.value == "boolean" || typeof a.value == "number" ? String(a.value) : A(a.value) ? z(a.value) : typeof a.value == "string" ? `"${a.value}"` : String(a.value)), te = _(() => "Double-click to edit"), ne = (o) => a.level === 0 ? o : h.value ? `${h.value}.${o}` : o, ae = (o) => {
72
+ const c = Object.keys(a.value);
73
+ return c.indexOf(o) === c.length - 1;
74
+ }, q = () => {
75
+ C("toggle-expand", h.value);
76
+ }, H = () => {
77
+ a.level !== 0 && (g.value = !0, x.value = a.keyName, Q(() => {
78
+ if (v.value) {
79
+ v.value.focus();
80
+ const o = document.createRange();
81
+ o.selectNodeContents(v.value);
82
+ const c = window.getSelection();
83
+ c?.removeAllRanges(), c?.addRange(o);
84
+ }
85
+ }));
86
+ }, re = () => {
87
+ U.value || (f.value = !0, a.value === null ? y.value = "null" : A(a.value) ? y.value = "protected-number" : typeof a.value == "string" ? y.value = "string" : typeof a.value == "number" ? y.value = "number" : typeof a.value == "boolean" && (y.value = "boolean"), A(a.value) ? b.value = z(a.value) : typeof a.value == "string" ? b.value = a.value : b.value = String(a.value), Q(() => {
88
+ if (j.value) {
89
+ j.value.focus();
90
+ const o = document.createRange();
91
+ o.selectNodeContents(j.value);
92
+ const c = window.getSelection();
93
+ c?.removeAllRanges(), c?.addRange(o);
94
+ }
95
+ }));
96
+ }, M = () => {
97
+ if (a.level === 0 || !g.value) return;
98
+ const o = v.value?.innerText.trim() || "";
99
+ if (!o) {
100
+ F();
101
+ return;
102
+ }
103
+ if (o === a.keyName) {
104
+ g.value = !1;
105
+ return;
106
+ }
107
+ g.value = !1, C("update:key", h.value, o);
108
+ }, G = () => {
109
+ if (f.value)
110
+ try {
111
+ let o;
112
+ const c = j.value?.innerText.trim() || "";
113
+ if (y.value === "string")
114
+ c === "null" ? o = null : c === "true" || c === "false" ? o = c === "true" : o = c;
115
+ else if (y.value === "protected-number")
116
+ o = ce(c);
117
+ else if (c === "null")
118
+ o = null;
119
+ else if (c === "true" || c === "false")
120
+ o = c === "true";
121
+ else if (!isNaN(Number(c)) && c !== "") {
122
+ const L = Number(c);
123
+ !Number.isSafeInteger(L) || c.length > 15 ? o = ce(c) : o = L;
124
+ } else
125
+ o = c;
126
+ C("update:value", h.value, o), f.value = !1;
127
+ } catch (o) {
128
+ console.error("Failed to parse value:", o), f.value = !1;
129
+ }
130
+ }, F = () => {
131
+ g.value = !1, x.value = a.keyName;
132
+ }, le = () => {
133
+ f.value = !1, A(a.value) ? b.value = z(a.value) : typeof a.value == "string" ? b.value = a.value : b.value = String(a.value);
134
+ };
135
+ return (o, c) => {
136
+ const L = Be("JsonNode", !0);
137
+ return m(), p("div", je, [
138
+ U.value ? (m(), p("div", Oe, [
139
+ N("div", Ae, [
140
+ o.keyName ? (m(), p("span", {
141
+ key: 0,
142
+ class: "json-node__key",
143
+ contenteditable: g.value,
144
+ onDblclick: H,
145
+ onKeydown: [
146
+ W(ue(M, ["prevent"]), ["enter"]),
147
+ W(F, ["escape"])
148
+ ],
149
+ onBlur: M,
150
+ ref_key: "keyRef",
151
+ ref: v,
152
+ title: "Double-click to edit key"
153
+ }, V(g.value ? x.value : `"${X.value}"`), 41, we)) : O("", !0),
154
+ o.keyName ? (m(), p("span", Te, ": ")) : O("", !0),
155
+ N("span", {
156
+ class: "json-node__bracket json-node__bracket--clickable",
157
+ onClick: q,
158
+ title: T.value ? "Click to collapse" : "Click to expand"
159
+ }, V(D.value), 9, Je),
160
+ T.value ? O("", !0) : (m(), p("span", {
161
+ key: 2,
162
+ class: "json-node__collapsed-info",
163
+ onClick: q,
164
+ title: `Click to expand ${ee.value.trim()}`
165
+ }, V(ee.value), 9, $e)),
166
+ T.value ? O("", !0) : (m(), p("span", {
167
+ key: 3,
168
+ class: "json-node__bracket json-node__bracket--clickable",
169
+ onClick: q,
170
+ title: "Click to expand"
171
+ }, V(Y.value), 1)),
172
+ !T.value && !o.isLast ? (m(), p("span", Pe, ",")) : O("", !0)
173
+ ]),
174
+ T.value ? (m(), p("div", Ve, [
175
+ N("div", Ce, [
176
+ (m(!0), p(xe, null, Ne(o.value, (oe, K) => (m(), p("div", {
177
+ key: K,
178
+ class: "json-node__child"
179
+ }, [
180
+ pe(L, {
181
+ value: oe,
182
+ "key-name": w.value ? "" : String(K),
183
+ level: o.level + 1,
184
+ path: ne(String(K)),
185
+ expanded: o.expanded,
186
+ theme: o.theme,
187
+ "onUpdate:value": c[0] || (c[0] = (J, R) => o.$emit("update:value", J, R)),
188
+ onToggleExpand: c[1] || (c[1] = (J) => o.$emit("toggle-expand", J)),
189
+ onCopy: c[2] || (c[2] = (J) => o.$emit("copy", J)),
190
+ "onUpdate:key": c[3] || (c[3] = (J, R) => o.$emit("update:key", J, R)),
191
+ "is-last": ae(String(K))
192
+ }, null, 8, ["value", "key-name", "level", "path", "expanded", "theme", "is-last"])
193
+ ]))), 128))
194
+ ]),
195
+ N("div", De, [
196
+ N("span", Fe, V(Y.value), 1),
197
+ o.isLast ? O("", !0) : (m(), p("span", Re, ","))
198
+ ])
199
+ ])) : O("", !0)
200
+ ])) : (m(), p("div", He, [
201
+ o.keyName ? (m(), p("span", {
202
+ key: 0,
203
+ class: "json-node__key",
204
+ contenteditable: g.value,
205
+ onDblclick: H,
206
+ onKeydown: [
207
+ W(ue(M, ["prevent"]), ["enter"]),
208
+ W(F, ["escape"])
209
+ ],
210
+ onBlur: M,
211
+ ref_key: "keyRef",
212
+ ref: v,
213
+ title: "Double-click to edit key"
214
+ }, V(g.value ? x.value : `"${X.value}"`), 41, Le)) : O("", !0),
215
+ o.keyName ? (m(), p("span", Ke, ": ")) : O("", !0),
216
+ N("span", {
217
+ class: me(["json-node__value-wrapper", se.value]),
218
+ onDblclick: re,
219
+ title: te.value
220
+ }, [
221
+ N("span", {
222
+ class: "json-node__value",
223
+ contenteditable: f.value,
224
+ onKeydown: [
225
+ W(ue(G, ["prevent"]), ["enter"]),
226
+ W(le, ["escape"])
227
+ ],
228
+ onBlur: G,
229
+ ref_key: "valueRef",
230
+ ref: j
231
+ }, V(f.value ? b.value : Z.value), 41, Ue),
232
+ o.isLast ? O("", !0) : (m(), p("span", Me, ","))
233
+ ], 42, Ie)
234
+ ]))
235
+ ]);
236
+ };
237
+ }
238
+ }), ze = /* @__PURE__ */ ge(We, [["__scopeId", "data-v-a58815b6"]]), be = {
239
+ name: "github-light",
240
+ colors: {
241
+ // 背景色
242
+ background: "#ffffff",
243
+ surfaceBackground: "#f6f8fa",
244
+ // 边框色
245
+ border: "#d0d7de",
246
+ // 文本色
247
+ text: "#24292f",
248
+ textSecondary: "#656d76",
249
+ // 按钮样式
250
+ buttonBackground: "#f6f8fa",
251
+ buttonBackgroundHover: "#f3f4f6",
252
+ buttonBorder: "#d0d7de",
253
+ buttonText: "#24292f",
254
+ buttonPrimary: "#2da44e",
255
+ buttonPrimaryHover: "#2c974b",
256
+ // 状态指示
257
+ success: "#1a7f37",
258
+ successBackground: "#dafbe1",
259
+ error: "#cf222e",
260
+ errorBackground: "#ffebe9",
261
+ // JSON 语法高亮
262
+ syntaxString: "#0a3069",
263
+ syntaxNumber: "#0969da",
264
+ syntaxBoolean: "#8250df",
265
+ syntaxNull: "#656d76",
266
+ syntaxKey: "#0969da",
267
+ syntaxBracket: "#24292f",
268
+ // 悬停效果
269
+ hoverBackground: "#f6f8fa",
270
+ // 选中背景色
271
+ selectionBackground: "rgba(9, 105, 218, 0.2)",
272
+ // 折叠信息样式
273
+ collapsedBackground: "#ddf4ff",
274
+ collapsedBackgroundHover: "#b6e3ff",
275
+ collapsedText: "#0969da",
276
+ // 缩进线
277
+ indentLine: "#d0d7de"
278
+ }
279
+ }, Ye = {
280
+ name: "github-dark",
281
+ colors: {
282
+ // 背景色
283
+ background: "#0d1117",
284
+ surfaceBackground: "#161b22",
285
+ // 边框色
286
+ border: "#30363d",
287
+ // 文本色
288
+ text: "#e6edf3",
289
+ textSecondary: "#7d8590",
290
+ // 按钮样式
291
+ buttonBackground: "#21262d",
292
+ buttonBackgroundHover: "#30363d",
293
+ buttonBorder: "#30363d",
294
+ buttonText: "#e6edf3",
295
+ buttonPrimary: "#238636",
296
+ buttonPrimaryHover: "#2ea043",
297
+ // 状态指示
298
+ success: "#3fb950",
299
+ successBackground: "#0f2419",
300
+ error: "#f85149",
301
+ errorBackground: "#381921",
302
+ // JSON 语法高亮
303
+ syntaxString: "#a5d6ff",
304
+ syntaxNumber: "#79c0ff",
305
+ syntaxBoolean: "#d2a8ff",
306
+ syntaxNull: "#7d8590",
307
+ syntaxKey: "#79c0ff",
308
+ syntaxBracket: "#e6edf3",
309
+ // 悬停效果
310
+ hoverBackground: "#161b22",
311
+ // 选中背景色
312
+ selectionBackground: "rgba(121, 192, 255, 0.2)",
313
+ // 折叠信息样式
314
+ collapsedBackground: "#1c2128",
315
+ collapsedBackgroundHover: "#2d333b",
316
+ collapsedText: "#79c0ff",
317
+ // 缩进线
318
+ indentLine: "#30363d"
319
+ }
320
+ }, Ze = {
321
+ name: "min-light",
322
+ colors: {
323
+ // 背景色 - 纯白简洁
324
+ background: "#ffffff",
325
+ surfaceBackground: "#fafafa",
326
+ // 边框色 - 极浅灰
327
+ border: "#e5e5e5",
328
+ // 文本色 - 深灰而非纯黑
329
+ text: "#333333",
330
+ textSecondary: "#888888",
331
+ // 按钮样式 - 简约设计
332
+ buttonBackground: "#f8f8f8",
333
+ buttonBackgroundHover: "#eeeeee",
334
+ buttonBorder: "#e0e0e0",
335
+ buttonText: "#333333",
336
+ buttonPrimary: "#007acc",
337
+ buttonPrimaryHover: "#005a9e",
338
+ // 状态指示 - 柔和色彩
339
+ success: "#22c55e",
340
+ successBackground: "#f0fdf4",
341
+ error: "#ef4444",
342
+ errorBackground: "#fef2f2",
343
+ // JSON 语法高亮 - 简约配色
344
+ syntaxString: "#22c55e",
345
+ syntaxNumber: "#3b82f6",
346
+ syntaxBoolean: "#8b5cf6",
347
+ syntaxNull: "#6b7280",
348
+ syntaxKey: "#1f2937",
349
+ syntaxBracket: "#374151",
350
+ // 悬停效果
351
+ hoverBackground: "#f9f9f9",
352
+ // 选中背景色
353
+ selectionBackground: "rgba(59, 130, 246, 0.2)",
354
+ // 折叠信息样式
355
+ collapsedBackground: "#e0f2fe",
356
+ collapsedBackgroundHover: "#bae6fd",
357
+ collapsedText: "#0284c7",
358
+ // 缩进线
359
+ indentLine: "#e5e7eb"
360
+ }
361
+ }, qe = {
362
+ name: "min-dark",
363
+ colors: {
364
+ // 背景色 - 低对比暗色
365
+ background: "#111111",
366
+ surfaceBackground: "#1a1a1a",
367
+ // 边框色 - 柔和深灰
368
+ border: "#2a2a2a",
369
+ // 文本色 - 柔和浅灰
370
+ text: "#e5e5e5",
371
+ textSecondary: "#a3a3a3",
372
+ // 按钮样式 - 简约暗色
373
+ buttonBackground: "#1f1f1f",
374
+ buttonBackgroundHover: "#2a2a2a",
375
+ buttonBorder: "#333333",
376
+ buttonText: "#e5e5e5",
377
+ buttonPrimary: "#3b82f6",
378
+ buttonPrimaryHover: "#2563eb",
379
+ // 状态指示 - 暗色可读性
380
+ success: "#22c55e",
381
+ successBackground: "#052e16",
382
+ error: "#f87171",
383
+ errorBackground: "#450a0a",
384
+ // JSON 语法高亮 - 极简暗色配色
385
+ syntaxString: "#4ade80",
386
+ syntaxNumber: "#60a5fa",
387
+ syntaxBoolean: "#c084fc",
388
+ syntaxNull: "#9ca3af",
389
+ syntaxKey: "#f3f4f6",
390
+ syntaxBracket: "#d1d5db",
391
+ // 悬停效果
392
+ hoverBackground: "#1f1f1f",
393
+ // 选中背景色
394
+ selectionBackground: "rgba(96, 165, 250, 0.25)",
395
+ // 折叠信息样式
396
+ collapsedBackground: "#1e293b",
397
+ collapsedBackgroundHover: "#334155",
398
+ collapsedText: "#60a5fa",
399
+ // 缩进线
400
+ indentLine: "#374151"
401
+ }
402
+ }, Ge = {
403
+ name: "slack-ochin",
404
+ colors: {
405
+ // 背景色 - 温暖的米色调
406
+ background: "#fefbf6",
407
+ surfaceBackground: "#faf6f0",
408
+ // 边框色 - 暖橙色调
409
+ border: "#e8d5b7",
410
+ // 文本色 - 深棕色
411
+ text: "#4a3b2a",
412
+ textSecondary: "#8b7355",
413
+ // 按钮样式 - Slack 风格橙色
414
+ buttonBackground: "#f4ede4",
415
+ buttonBackgroundHover: "#efe5d8",
416
+ buttonBorder: "#e8d5b7",
417
+ buttonText: "#4a3b2a",
418
+ buttonPrimary: "#ff6b35",
419
+ buttonPrimaryHover: "#e55a2b",
420
+ // 状态指示 - 暖色调
421
+ success: "#ff9500",
422
+ successBackground: "#fff8f0",
423
+ error: "#d73502",
424
+ errorBackground: "#ffeee8",
425
+ // JSON 语法高亮 - 温暖配色
426
+ syntaxString: "#d73502",
427
+ syntaxNumber: "#ff6b35",
428
+ syntaxBoolean: "#b7472a",
429
+ syntaxNull: "#8b7355",
430
+ syntaxKey: "#4a3b2a",
431
+ syntaxBracket: "#6b5444",
432
+ // 悬停效果
433
+ hoverBackground: "#f8f2eb",
434
+ // 选中背景色
435
+ selectionBackground: "rgba(255, 107, 53, 0.2)",
436
+ // 折叠信息样式
437
+ collapsedBackground: "#ffe8d6",
438
+ collapsedBackgroundHover: "#ffd4b0",
439
+ collapsedText: "#d73502",
440
+ // 缩进线
441
+ indentLine: "#e8d5b7"
442
+ }
443
+ }, Qe = {
444
+ "github-light": be,
445
+ "github-dark": Ye,
446
+ "min-light": Ze,
447
+ "min-dark": qe,
448
+ "slack-ochin": Ge
449
+ };
450
+ function Xe(k = "github-light") {
451
+ return Qe[k] || be;
452
+ }
453
+ const et = { class: "json-format__content" }, tt = {
454
+ key: 0,
455
+ class: "json-format__error"
456
+ }, nt = {
457
+ key: 1,
458
+ class: "json-format__error"
459
+ }, rt = {
460
+ key: 2,
461
+ class: "json-format__viewer"
462
+ }, ot = /* @__PURE__ */ ye({
463
+ name: "JsonFormat",
464
+ __name: "index",
465
+ props: {
466
+ modelValue: { default: "" },
467
+ readonly: { type: Boolean, default: !1 },
468
+ maxDepth: { default: 10 },
469
+ theme: { default: "github-light" }
470
+ },
471
+ emits: ["update:modelValue", "copy-success", "copy-error", "expand-all", "collapse-all", "compress"],
472
+ setup(k, { expose: I, emit: a }) {
473
+ ve((e) => ({
474
+ "326003a4": h.value.colors.background,
475
+ b9b0f7ba: h.value.colors.text,
476
+ "7e091c5c": h.value.colors.error,
477
+ "412704a0": h.value.colors.errorBackground
478
+ }));
479
+ const C = k, g = a, f = B(null), x = B(""), b = B(/* @__PURE__ */ new Set()), y = B(null), v = B(""), j = B(!1), U = (e, t) => {
480
+ if (e === null || typeof e != "object")
481
+ return e;
482
+ if (Array.isArray(e))
483
+ return e.map((n) => U(n, t));
484
+ if (Object.prototype.hasOwnProperty.call(e, t) && Object.keys(e).length === 1 && typeof e[t] == "string")
485
+ return ce(e[t]);
486
+ for (const n of Object.keys(e))
487
+ e[n] = U(e[n], t);
488
+ return e;
489
+ }, w = _(() => x.value === ""), h = _(() => Xe(C.theme)), T = (e) => {
490
+ if (e == null)
491
+ return e;
492
+ if (Array.isArray(e))
493
+ return e.map((t) => T(t));
494
+ if (typeof e == "object") {
495
+ const t = {}, n = Object.keys(e).sort();
496
+ for (const s of n)
497
+ t[s] = T(e[s]);
498
+ return t;
499
+ }
500
+ return e;
501
+ }, X = _(() => {
502
+ const e = y.value !== null ? y.value : f.value;
503
+ return !e || !j.value ? e : T(e);
504
+ }), D = _(() => v.value ? null : X.value), Y = (e) => {
505
+ if (!e.trim()) {
506
+ f.value = null, x.value = "", y.value = null, v.value = "";
507
+ return;
508
+ }
509
+ try {
510
+ let t = e;
511
+ const n = `__json_format_protected_number_${Date.now()}_${Math.random().toString(36).slice(2)}__`, s = /(:\s*|,\s*|\[\s*)-?\d{16,}/.test(t), l = /(:\s*|,\s*|\[\s*)-?\d+\.\d*0+\s*[,}\]\s]*/.test(t);
512
+ if (!s && !l)
513
+ try {
514
+ f.value = JSON.parse(t), x.value = "", y.value = null, v.value = "", Q(() => {
515
+ D.value !== null && F();
516
+ });
517
+ return;
518
+ } catch {
519
+ }
520
+ t = ((u) => {
521
+ let i = "", d = !1, $ = !1, E = 0;
522
+ for (; E < u.length; ) {
523
+ const P = u[E];
524
+ if (d)
525
+ $ ? $ = !1 : P === "\\" ? $ = !0 : P === '"' && (d = !1), i += P, E++;
526
+ else if (P === '"')
527
+ d = !0, i += P, E++;
528
+ else {
529
+ const fe = u.slice(E);
530
+ let S = fe.match(/^([:,\[\s]*)(-?\d{16,})(\s*[,\}\]\s]|$)/);
531
+ if (S) {
532
+ i += S[1] + '{"' + n + '":"' + S[2] + '"}' + S[3], E += S[0].length;
533
+ continue;
534
+ }
535
+ if (S = fe.match(/^([:,\[\s]*)(-?\d+\.\d*0+)(\s*[,\}\]\s]|$)/), S) {
536
+ i += S[1] + '{"' + n + '":"' + S[2] + '"}' + S[3], E += S[0].length;
537
+ continue;
538
+ }
539
+ i += P, E++;
540
+ }
541
+ }
542
+ return i;
543
+ })(t), f.value = U(JSON.parse(t), n), x.value = "", y.value = null, v.value = "", Q(() => {
544
+ D.value !== null && F();
545
+ });
546
+ } catch (t) {
547
+ x.value = t instanceof Error ? t.message : "Unknown parsing error", f.value = null, y.value = null, v.value = "";
548
+ }
549
+ }, ee = (e) => {
550
+ if (!e || !e.expression.trim()) {
551
+ ne();
552
+ return;
553
+ }
554
+ if (!f.value) {
555
+ v.value = "No valid JSON data to filter";
556
+ return;
557
+ }
558
+ try {
559
+ let t;
560
+ if (e.type === "jsonpath")
561
+ t = Se({ path: e.expression, json: f.value }), t.length === 1 && e.expression.includes("$[") === !1 && !e.expression.endsWith("[*]") ? y.value = t[0] : y.value = t;
562
+ else if (e.type === "js") {
563
+ const { proxyData: n, indexMap: s } = se(f.value), r = new Function("$", `
564
+ try {
565
+ return ${e.expression};
566
+ } catch (error) {
567
+ throw new Error('JavaScript expression error: ' + error.message);
568
+ }
569
+ `)(n);
570
+ t = Z(f.value, r, s), y.value = t;
571
+ } else
572
+ throw new Error(`Unsupported filter type: ${e.type}`);
573
+ v.value = "", Q(() => {
574
+ F();
575
+ });
576
+ } catch (t) {
577
+ v.value = t instanceof Error ? t.message : "Filter execution error", y.value = null;
578
+ }
579
+ }, se = (e, t = "root") => {
580
+ const n = /* @__PURE__ */ new Map(), s = (r, u) => {
581
+ if (r == null)
582
+ return r;
583
+ if (A(r)) {
584
+ const i = parseFloat(z(r));
585
+ return n.set(i, u), i;
586
+ }
587
+ if (Array.isArray(r)) {
588
+ const i = r.map((d, $) => {
589
+ const E = `${u}[${$}]`, P = s(d, E);
590
+ return n.set(P, E), P;
591
+ });
592
+ return n.set(i, u), i;
593
+ }
594
+ if (typeof r == "object") {
595
+ const i = {};
596
+ for (const d in r)
597
+ if (Object.prototype.hasOwnProperty.call(r, d)) {
598
+ const $ = u === "root" ? d : `${u}.${d}`;
599
+ i[d] = s(r[d], $);
600
+ }
601
+ return n.set(i, u), i;
602
+ }
603
+ return r;
604
+ };
605
+ return { proxyData: s(e, t), indexMap: n };
606
+ }, Z = (e, t, n) => {
607
+ if (t === null || typeof t != "object")
608
+ return t;
609
+ if (Array.isArray(t))
610
+ return t.map((r) => {
611
+ const u = n.get(r);
612
+ if (u) {
613
+ const i = te(e, u);
614
+ if (i !== void 0)
615
+ return i;
616
+ }
617
+ return Z(e, r, n);
618
+ });
619
+ const s = n.get(t);
620
+ if (s) {
621
+ const r = te(e, s);
622
+ if (r !== void 0)
623
+ return r;
624
+ }
625
+ const l = {};
626
+ for (const r in t)
627
+ Object.prototype.hasOwnProperty.call(t, r) && (l[r] = Z(e, t[r], n));
628
+ return l;
629
+ }, te = (e, t) => {
630
+ if (t === "root") return e;
631
+ const n = [];
632
+ let s = t.replace(/^root\.?/, "");
633
+ const l = /([^\[\].]+)|\[(\d+)\]/g;
634
+ let r;
635
+ for (; (r = l.exec(s)) !== null; )
636
+ r[1] ? n.push(r[1]) : r[2] !== void 0 && n.push(parseInt(r[2]));
637
+ let u = e;
638
+ for (const i of n) {
639
+ if (u == null)
640
+ return;
641
+ u = u[i];
642
+ }
643
+ return u;
644
+ }, ne = () => {
645
+ y.value = null, v.value = "";
646
+ }, ae = () => {
647
+ j.value = !0;
648
+ }, q = () => {
649
+ j.value = !1;
650
+ };
651
+ Ee(() => C.modelValue, (e) => {
652
+ Y(e);
653
+ }, { immediate: !0 });
654
+ const H = (e, t, n) => {
655
+ const s = (u) => {
656
+ if (u === null || typeof u != "object")
657
+ return u;
658
+ if (A(u))
659
+ return `__PROTECTED_NUMBER_${z(u)}_PROTECTED_NUMBER__`;
660
+ if (Array.isArray(u))
661
+ return u.map((d) => s(d));
662
+ const i = {};
663
+ for (const [d, $] of Object.entries(u))
664
+ i[d] = s($);
665
+ return i;
666
+ }, l = s(e);
667
+ return JSON.stringify(l, t, n).replace(/"__PROTECTED_NUMBER_(.+?)_PROTECTED_NUMBER__"/g, "$1");
668
+ }, re = (e, t) => {
669
+ if (!C.readonly)
670
+ try {
671
+ const n = M(f.value, e, t), s = H(n, null, 2);
672
+ g("update:modelValue", s);
673
+ } catch (n) {
674
+ console.error("Failed to update JSON:", n);
675
+ }
676
+ }, M = (e, t, n) => {
677
+ if (!t || t === "root") return n;
678
+ const s = t.split("."), l = R(e, s.slice(0, -1));
679
+ let r = l;
680
+ for (let i = 0; i < s.length - 1; i++) {
681
+ const d = s[i];
682
+ d !== "root" && (Array.isArray(r) ? r = r[parseInt(d)] : r = r[d]);
683
+ }
684
+ const u = s[s.length - 1];
685
+ return u === "root" ? n : (Array.isArray(r) ? r[parseInt(u)] = n : r[u] = n, l);
686
+ }, G = (e) => {
687
+ b.value.has(e) ? b.value.delete(e) : b.value.add(e);
688
+ }, F = () => {
689
+ const e = /* @__PURE__ */ new Set(), t = (n, s = "") => {
690
+ n !== null && typeof n == "object" && (e.add(s || "root"), Array.isArray(n) ? n.forEach((l, r) => {
691
+ const u = s ? `${s}.${r}` : `${r}`;
692
+ t(l, u);
693
+ }) : Object.keys(n).forEach((l) => {
694
+ const r = s ? `${s}.${l}` : l;
695
+ t(n[l], r);
696
+ }));
697
+ };
698
+ t(D.value), b.value = e, g("expand-all");
699
+ }, le = () => {
700
+ b.value = /* @__PURE__ */ new Set(), g("collapse-all");
701
+ }, o = async () => {
702
+ if (w.value)
703
+ try {
704
+ const e = D.value, t = H(e, null, 2);
705
+ await navigator.clipboard.writeText(t), g("copy-success", t);
706
+ } catch (e) {
707
+ console.error("Failed to copy JSON:", e), g("copy-error", e instanceof Error ? e : new Error("Failed to copy JSON"));
708
+ }
709
+ }, c = () => {
710
+ if (w.value)
711
+ try {
712
+ const e = D.value, t = H(e);
713
+ g("update:modelValue", t), g("compress", t);
714
+ } catch (e) {
715
+ console.error("Failed to compress JSON:", e);
716
+ }
717
+ }, L = (e) => {
718
+ if (A(e))
719
+ return z(e);
720
+ if (typeof e == "string")
721
+ return `"${e}"`;
722
+ const t = JSON.stringify(e);
723
+ return t === void 0 ? "undefined" : t;
724
+ }, oe = async (e) => {
725
+ try {
726
+ await navigator.clipboard.writeText(L(e));
727
+ } catch (t) {
728
+ console.error("Failed to copy value:", t);
729
+ }
730
+ }, K = (e, t) => {
731
+ if (!C.readonly)
732
+ try {
733
+ const n = J(f.value, e, t), s = H(n, null, 2);
734
+ g("update:modelValue", s), he(e, t);
735
+ } catch (n) {
736
+ console.error("Failed to rename key:", n);
737
+ }
738
+ }, J = (e, t, n) => {
739
+ if (!t || t === "root") return e;
740
+ const s = t.split("."), l = R(e, s.slice(0, -1));
741
+ if (s.length === 1) {
742
+ const i = s[0];
743
+ return l && typeof l == "object" && !Array.isArray(l) ? de(l, i, n) : l;
744
+ }
745
+ let r = l;
746
+ for (let i = 0; i < s.length - 1; i++) {
747
+ const d = s[i];
748
+ Array.isArray(r) ? r = r[parseInt(d)] : r = r[d];
749
+ }
750
+ const u = s[s.length - 1];
751
+ if (!Array.isArray(r) && r && typeof r == "object") {
752
+ const i = de(r, u, n), d = s.slice(0, -1);
753
+ d.length > 0 && _e(l, d, i);
754
+ }
755
+ return l;
756
+ }, R = (e, t) => {
757
+ if (t.length === 0) return e;
758
+ if (Array.isArray(e)) {
759
+ const n = [...e], s = t[0], l = parseInt(s);
760
+ return t.length === 1 || (n[l] = R(e[l], t.slice(1))), n;
761
+ } else if (e && typeof e == "object") {
762
+ const n = { ...e }, s = t[0];
763
+ return t.length === 1 || (n[s] = R(e[s], t.slice(1))), n;
764
+ }
765
+ return e;
766
+ }, de = (e, t, n) => {
767
+ if (!e || typeof e != "object" || Array.isArray(e))
768
+ return e;
769
+ const s = Object.keys(e), l = {};
770
+ for (const r of s)
771
+ r === t ? l[n] = e[r] : l[r] = e[r];
772
+ return l;
773
+ }, _e = (e, t, n) => {
774
+ let s = e;
775
+ for (let r = 0; r < t.length - 1; r++) {
776
+ const u = t[r];
777
+ Array.isArray(s) ? s = s[parseInt(u)] : s = s[u];
778
+ }
779
+ const l = t[t.length - 1];
780
+ Array.isArray(s) ? s[parseInt(l)] = n : s[l] = n;
781
+ }, he = (e, t) => {
782
+ const n = /* @__PURE__ */ new Set();
783
+ b.value.forEach((s) => {
784
+ if (s === e) {
785
+ const l = e.split(".");
786
+ l[l.length - 1] = t, n.add(l.join("."));
787
+ } else if (s.startsWith(e + ".")) {
788
+ const l = e.split(".");
789
+ l[l.length - 1] = t;
790
+ const r = l.join("."), u = s.substring(e.length);
791
+ n.add(r + u);
792
+ } else
793
+ n.add(s);
794
+ }), b.value = n;
795
+ };
796
+ return I({
797
+ // 核心操作方法
798
+ copyJson: o,
799
+ compressSource: c,
800
+ expandAll: F,
801
+ collapseAll: le,
802
+ toggleExpand: G,
803
+ updateValue: re,
804
+ updateKey: K,
805
+ // Filter 相关方法
806
+ filter: ee,
807
+ clearFilter: ne,
808
+ // Key 排序相关方法
809
+ sortKeys: ae,
810
+ clearSortKeys: q,
811
+ isSorted: () => j.value,
812
+ // 状态访问方法
813
+ isValidJson: () => w.value,
814
+ getParsedJson: () => f.value,
815
+ getFilteredJson: () => y.value,
816
+ getExpandedNodes: () => b.value,
817
+ getParseError: () => x.value,
818
+ getFilterError: () => v.value,
819
+ // 工具方法
820
+ parseJson: (e) => Y(e),
821
+ copyValue: (e) => oe(e),
822
+ getValue: (e) => L(e)
823
+ }), (e, t) => (m(), p("div", {
824
+ class: me(["json-format", `json-format--${h.value.name}`])
825
+ }, [
826
+ N("div", et, [
827
+ w.value ? v.value ? (m(), p("div", nt, [
828
+ t[1] || (t[1] = N("h4", null, "Filter Error:", -1)),
829
+ N("pre", null, V(v.value), 1)
830
+ ])) : (m(), p("div", rt, [
831
+ pe(ze, {
832
+ value: D.value,
833
+ "key-name": "",
834
+ level: 0,
835
+ expanded: b.value,
836
+ "is-last": !0,
837
+ theme: h.value,
838
+ "onUpdate:value": re,
839
+ onToggleExpand: G,
840
+ onCopy: oe,
841
+ "onUpdate:key": K
842
+ }, null, 8, ["value", "expanded", "theme"])
843
+ ])) : (m(), p("div", tt, [
844
+ t[0] || (t[0] = N("h4", null, "JSON Parse Error:", -1)),
845
+ N("pre", null, V(x.value), 1)
846
+ ]))
847
+ ])
848
+ ], 2));
849
+ }
850
+ }), ut = /* @__PURE__ */ ge(ot, [["__scopeId", "data-v-404434be"]]);
851
+ export {
852
+ ut as J
853
+ };