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