lone-format 0.12.2 → 0.14.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.
Files changed (32) hide show
  1. package/dist/_chunks/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
  2. package/dist/_chunks/index-5wbkWClK.js +1006 -0
  3. package/dist/_chunks/index-AlOFzpXl.js +795 -0
  4. package/dist/_chunks/index-BAEkF-Fh.js +1785 -0
  5. package/dist/components/JsonFormat/JsonNode.vue.d.ts +29 -0
  6. package/dist/components/JsonFormat/index.d.ts +2 -0
  7. package/dist/components/JsonFormat/index.js +4 -0
  8. package/dist/components/JsonFormat/index.vue.d.ts +51 -0
  9. package/dist/components/JsonFormat/themes.d.ts +29 -0
  10. package/dist/components/JsonFormat/types.d.ts +97 -0
  11. package/dist/components/SqlFormat/SqlClauseNode.vue.d.ts +13 -0
  12. package/dist/components/SqlFormat/index.d.ts +5 -0
  13. package/dist/components/SqlFormat/index.js +5 -0
  14. package/dist/components/SqlFormat/index.vue.d.ts +44 -0
  15. package/dist/components/SqlFormat/parser.d.ts +34 -0
  16. package/dist/components/SqlFormat/themes.d.ts +33 -0
  17. package/dist/components/SqlFormat/types.d.ts +100 -0
  18. package/dist/components/XmlFormat/XmlNode.vue.d.ts +37 -0
  19. package/dist/components/XmlFormat/index.d.ts +7 -0
  20. package/dist/components/XmlFormat/index.js +27 -0
  21. package/dist/components/XmlFormat/index.vue.d.ts +58 -0
  22. package/dist/components/XmlFormat/parser.d.ts +93 -0
  23. package/dist/components/XmlFormat/themes.d.ts +29 -0
  24. package/dist/components/XmlFormat/types.d.ts +114 -0
  25. package/dist/components/index.d.ts +6 -0
  26. package/dist/index.d.ts +6 -1
  27. package/dist/lone-format.css +1 -1
  28. package/dist/lone-format.js +13 -32008
  29. package/dist/lone-format.umd.cjs +50 -50
  30. package/dist/types/components.d.ts +1 -0
  31. package/dist/types/index.d.ts +6 -0
  32. package/package.json +8 -3
@@ -0,0 +1,795 @@
1
+ import { defineComponent as ce, useCssVars as ie, ref as B, computed as b, resolveComponent as pe, createElementBlock as p, openBlock as m, createElementVNode as j, createCommentVNode as w, withKeys as U, withModifiers as ue, toDisplayString as T, Fragment as me, renderList as ge, createVNode as de, normalizeClass as fe, nextTick as X, watch as _e } from "vue";
2
+ import { JSONPath as be } from "jsonpath-plus";
3
+ import { _ as ve } 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
+ }, je = ["title"], Se = ["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" }, Je = { class: "json-node__bracket" }, Te = {
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"], Fe = ["contenteditable", "onKeydown"], De = {
26
+ key: 0,
27
+ class: "json-node__comma"
28
+ }, Le = /* @__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(""), v = B("string"), y = 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 = b(() => N(a.value) ? !1 : a.value !== null && typeof a.value == "object"), F = b(() => Array.isArray(a.value)), h = b(() => a.path ? a.path : a.keyName ? a.keyName : "root"), V = b(() => a.expanded.has(h.value)), Y = b(() => a.keyName), se = b(() => F.value ? "[" : "{"), D = b(() => F.value ? "]" : "}"), W = b(() => {
59
+ if (!a.value) return "";
60
+ const c = Object.keys(a.value).length;
61
+ return F.value ? c > 0 ? ` ${c} items ` : " " : c > 0 ? ` ${c} keys ` : " ";
62
+ }), ee = b(() => {
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 = b(() => 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 = b(() => "Double-click to edit"), L = (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 (y.value) {
73
+ y.value.focus();
74
+ const n = document.createRange();
75
+ n.selectNodeContents(y.value);
76
+ const c = window.getSelection();
77
+ c?.removeAllRanges(), c?.addRange(n);
78
+ }
79
+ }));
80
+ }, H = () => {
81
+ C.value || (f.value = !0, a.value === null ? v.value = "null" : N(a.value) ? v.value = "protected-number" : typeof a.value == "string" ? v.value = "string" : typeof a.value == "number" ? v.value = "number" : typeof a.value == "boolean" && (v.value = "boolean"), N(a.value) ? _.value = E(a.value) : typeof a.value == "string" ? _.value = a.value : _.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 = y.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 (v.value === "string")
108
+ c === "null" ? n = null : c === "true" || c === "false" ? n = c === "true" : n = c;
109
+ else if (v.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) ? _.value = E(a.value) : typeof a.value == "string" ? _.value = a.value : _.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
+ j("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: y,
146
+ title: "Double-click to edit key"
147
+ }, T(g.value ? x.value : `"${Y.value}"`), 41, xe)) : w("", !0),
148
+ n.keyName ? (m(), p("span", Ne, ": ")) : w("", !0),
149
+ j("span", {
150
+ class: "json-node__bracket json-node__bracket--clickable",
151
+ onClick: z,
152
+ title: V.value ? "Click to collapse" : "Click to expand"
153
+ }, T(se.value), 9, je),
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
+ }, T(W.value), 9, Se)),
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
+ }, T(D.value), 1)),
166
+ !V.value && !n.isLast ? (m(), p("span", Ae, ",")) : w("", !0)
167
+ ]),
168
+ V.value ? (m(), p("div", Ee, [
169
+ j("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": F.value ? "" : String(P),
177
+ level: n.level + 1,
178
+ path: L(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
+ j("div", Oe, [
190
+ j("span", Je, T(D.value), 1),
191
+ n.isLast ? w("", !0) : (m(), p("span", Te, ","))
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: y,
207
+ title: "Double-click to edit key"
208
+ }, T(g.value ? x.value : `"${Y.value}"`), 41, Ve)) : w("", !0),
209
+ n.keyName ? (m(), p("span", Pe, ": ")) : w("", !0),
210
+ j("span", {
211
+ class: fe(["json-node__value-wrapper", ee.value]),
212
+ onDblclick: H,
213
+ title: le.value
214
+ }, [
215
+ j("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
+ }, T(f.value ? _.value : ae.value), 41, Fe),
226
+ n.isLast ? w("", !0) : (m(), p("span", De, ","))
227
+ ], 42, Ce)
228
+ ]))
229
+ ]);
230
+ };
231
+ }
232
+ }), He = /* @__PURE__ */ ve(Le, [["__scopeId", "data-v-1472a8af"]]), ye = {
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: "slack-ochin",
357
+ colors: {
358
+ // 背景色 - 温暖的米色调
359
+ background: "#fefbf6",
360
+ surfaceBackground: "#faf6f0",
361
+ // 边框色 - 暖橙色调
362
+ border: "#e8d5b7",
363
+ // 文本色 - 深棕色
364
+ text: "#4a3b2a",
365
+ textSecondary: "#8b7355",
366
+ // 按钮样式 - Slack 风格橙色
367
+ buttonBackground: "#f4ede4",
368
+ buttonBackgroundHover: "#efe5d8",
369
+ buttonBorder: "#e8d5b7",
370
+ buttonText: "#4a3b2a",
371
+ buttonPrimary: "#ff6b35",
372
+ buttonPrimaryHover: "#e55a2b",
373
+ // 状态指示 - 暖色调
374
+ success: "#ff9500",
375
+ successBackground: "#fff8f0",
376
+ error: "#d73502",
377
+ errorBackground: "#ffeee8",
378
+ // JSON 语法高亮 - 温暖配色
379
+ syntaxString: "#d73502",
380
+ syntaxNumber: "#ff6b35",
381
+ syntaxBoolean: "#b7472a",
382
+ syntaxNull: "#8b7355",
383
+ syntaxKey: "#4a3b2a",
384
+ syntaxBracket: "#6b5444",
385
+ // 悬停效果
386
+ hoverBackground: "#f8f2eb",
387
+ // 选中背景色
388
+ selectionBackground: "rgba(255, 107, 53, 0.2)",
389
+ // 折叠信息样式
390
+ collapsedBackground: "#ffe8d6",
391
+ collapsedBackgroundHover: "#ffd4b0",
392
+ collapsedText: "#d73502",
393
+ // 缩进线
394
+ indentLine: "#e8d5b7"
395
+ }
396
+ }, Ue = {
397
+ "github-light": ye,
398
+ "github-dark": Ke,
399
+ "min-light": Ie,
400
+ "slack-ochin": Re
401
+ };
402
+ function Me(M = "github-light") {
403
+ return Ue[M] || ye;
404
+ }
405
+ const We = { class: "json-format__content" }, ze = {
406
+ key: 0,
407
+ class: "json-format__error"
408
+ }, Ze = {
409
+ key: 1,
410
+ class: "json-format__error"
411
+ }, qe = {
412
+ key: 2,
413
+ class: "json-format__viewer"
414
+ }, Ge = /* @__PURE__ */ ce({
415
+ name: "JsonFormat",
416
+ __name: "index",
417
+ props: {
418
+ modelValue: { default: "" },
419
+ readonly: { type: Boolean, default: !1 },
420
+ maxDepth: { default: 10 },
421
+ theme: { default: "github-light" }
422
+ },
423
+ emits: ["update:modelValue", "copy-success", "copy-error", "expand-all", "collapse-all", "compress"],
424
+ setup(M, { expose: oe, emit: a }) {
425
+ ie((e) => ({
426
+ "4b6ab8f6": E.value.colors.background,
427
+ "37fbe0c4": E.value.colors.text,
428
+ "729aad5e": E.value.colors.error,
429
+ "640bad42": E.value.colors.errorBackground
430
+ }));
431
+ const $ = M, g = a, f = B(null), x = B(""), _ = B(/* @__PURE__ */ new Set()), v = B(null), y = B(""), A = B(!1), N = b(() => x.value === ""), E = b(() => Me($.theme)), C = (e) => {
432
+ if (e == null)
433
+ return e;
434
+ if (Array.isArray(e))
435
+ return e.map((t) => C(t));
436
+ if (typeof e == "object") {
437
+ const t = {}, s = Object.keys(e).sort();
438
+ for (const o of s)
439
+ t[o] = C(e[o]);
440
+ return t;
441
+ }
442
+ return e;
443
+ }, F = b(() => {
444
+ const e = v.value !== null ? v.value : f.value;
445
+ return !e || !A.value ? e : C(e);
446
+ }), h = b(() => y.value ? null : F.value), V = (e) => {
447
+ if (!e.trim()) {
448
+ f.value = null, x.value = "", v.value = null, y.value = "";
449
+ return;
450
+ }
451
+ try {
452
+ let t = e;
453
+ const s = /(:\s*|,\s*|\[\s*)-?\d{16,}/.test(t), o = /(:\s*|,\s*|\[\s*)-?\d+\.\d*0+\s*[,}\]\s]*/.test(t);
454
+ if (!s && !o)
455
+ try {
456
+ f.value = JSON.parse(t), x.value = "", v.value = null, y.value = "", X(() => {
457
+ h.value !== null && H();
458
+ });
459
+ return;
460
+ } catch {
461
+ }
462
+ t = ((r) => {
463
+ let l = "", i = !1, d = !1, k = 0;
464
+ for (; k < r.length; ) {
465
+ const J = r[k];
466
+ if (i)
467
+ d ? d = !1 : J === "\\" ? d = !0 : J === '"' && (i = !1), l += J, k++;
468
+ else if (J === '"')
469
+ i = !0, l += J, k++;
470
+ else {
471
+ const Q = r.slice(k);
472
+ let S = Q.match(/^([:,\[\s]*)(-?\d{16,})(\s*[,\}\]\s]|$)/);
473
+ if (S) {
474
+ l += S[1] + '{"__protected_number__":"' + S[2] + '"}' + S[3], k += S[0].length;
475
+ continue;
476
+ }
477
+ if (S = Q.match(/^([:,\[\s]*)(-?\d+\.\d*0+)(\s*[,\}\]\s]|$)/), S) {
478
+ l += S[1] + '{"__protected_number__":"' + S[2] + '"}' + S[3], k += S[0].length;
479
+ continue;
480
+ }
481
+ l += J, k++;
482
+ }
483
+ }
484
+ return l;
485
+ })(t), f.value = JSON.parse(t), x.value = "", v.value = null, y.value = "", X(() => {
486
+ h.value !== null && H();
487
+ });
488
+ } catch (t) {
489
+ x.value = t instanceof Error ? t.message : "Unknown parsing error", f.value = null, v.value = null, y.value = "";
490
+ }
491
+ }, Y = (e) => {
492
+ if (!e || !e.expression.trim()) {
493
+ ee();
494
+ return;
495
+ }
496
+ if (!f.value) {
497
+ y.value = "No valid JSON data to filter";
498
+ return;
499
+ }
500
+ try {
501
+ let t;
502
+ if (e.type === "jsonpath")
503
+ t = be({ path: e.expression, json: f.value }), t.length === 1 && e.expression.includes("$[") === !1 && !e.expression.endsWith("[*]") ? v.value = t[0] : v.value = t;
504
+ else if (e.type === "js") {
505
+ const { proxyData: s, indexMap: o } = se(f.value), r = new Function("$", `
506
+ try {
507
+ return ${e.expression};
508
+ } catch (error) {
509
+ throw new Error('JavaScript expression error: ' + error.message);
510
+ }
511
+ `)(s);
512
+ t = D(f.value, r, o), v.value = t;
513
+ } else
514
+ throw new Error(`Unsupported filter type: ${e.type}`);
515
+ y.value = "", X(() => {
516
+ H();
517
+ });
518
+ } catch (t) {
519
+ y.value = t instanceof Error ? t.message : "Filter execution error", v.value = null;
520
+ }
521
+ }, se = (e, t = "root") => {
522
+ const s = /* @__PURE__ */ new Map(), o = (r, l) => {
523
+ if (r == null)
524
+ return r;
525
+ if (typeof r == "object" && r.__protected_number__ !== void 0) {
526
+ const i = parseFloat(r.__protected_number__);
527
+ return s.set(i, l), i;
528
+ }
529
+ if (Array.isArray(r)) {
530
+ const i = r.map((d, k) => {
531
+ const J = `${l}[${k}]`, Q = o(d, J);
532
+ return s.set(Q, J), Q;
533
+ });
534
+ return s.set(i, l), i;
535
+ }
536
+ if (typeof r == "object") {
537
+ const i = {};
538
+ for (const d in r)
539
+ if (Object.prototype.hasOwnProperty.call(r, d)) {
540
+ const k = l === "root" ? d : `${l}.${d}`;
541
+ i[d] = o(r[d], k);
542
+ }
543
+ return s.set(i, l), i;
544
+ }
545
+ return r;
546
+ };
547
+ return { proxyData: o(e, t), indexMap: s };
548
+ }, D = (e, t, s) => {
549
+ if (t === null || typeof t != "object")
550
+ return t;
551
+ if (Array.isArray(t))
552
+ return t.map((r) => {
553
+ const l = s.get(r);
554
+ if (l) {
555
+ const i = W(e, l);
556
+ if (i !== void 0)
557
+ return i;
558
+ }
559
+ return D(e, r, s);
560
+ });
561
+ const o = s.get(t);
562
+ if (o) {
563
+ const r = W(e, o);
564
+ if (r !== void 0)
565
+ return r;
566
+ }
567
+ const u = {};
568
+ for (const r in t)
569
+ Object.prototype.hasOwnProperty.call(t, r) && (u[r] = D(e, t[r], s));
570
+ return u;
571
+ }, W = (e, t) => {
572
+ if (t === "root") return e;
573
+ const s = [];
574
+ let o = t.replace(/^root\.?/, "");
575
+ const u = /([^\[\].]+)|\[(\d+)\]/g;
576
+ let r;
577
+ for (; (r = u.exec(o)) !== null; )
578
+ r[1] ? s.push(r[1]) : r[2] !== void 0 && s.push(parseInt(r[2]));
579
+ let l = e;
580
+ for (const i of s) {
581
+ if (l == null)
582
+ return;
583
+ l = l[i];
584
+ }
585
+ return l;
586
+ }, ee = () => {
587
+ v.value = null, y.value = "";
588
+ }, ae = () => {
589
+ A.value = !0;
590
+ }, le = () => {
591
+ A.value = !1;
592
+ };
593
+ _e(() => $.modelValue, (e) => {
594
+ V(e);
595
+ }, { immediate: !0 });
596
+ const L = (e, t, s) => {
597
+ const o = (l) => {
598
+ if (l === null || typeof l != "object")
599
+ return l;
600
+ if (!Array.isArray(l) && "__protected_number__" in l && Object.keys(l).length === 1)
601
+ return `__PROTECTED_NUMBER_${l.__protected_number__}_PROTECTED_NUMBER__`;
602
+ if (Array.isArray(l))
603
+ return l.map((d) => o(d));
604
+ const i = {};
605
+ for (const [d, k] of Object.entries(l))
606
+ i[d] = o(k);
607
+ return i;
608
+ }, u = o(e);
609
+ return JSON.stringify(u, t, s).replace(/"__PROTECTED_NUMBER_(.+?)_PROTECTED_NUMBER__"/g, "$1");
610
+ }, te = (e, t) => {
611
+ if (!$.readonly)
612
+ try {
613
+ const s = z(f.value, e, t), o = L(s, null, 2);
614
+ g("update:modelValue", o);
615
+ } catch (s) {
616
+ console.error("Failed to update JSON:", s);
617
+ }
618
+ }, z = (e, t, s) => {
619
+ if (!t || t === "root") return s;
620
+ const o = t.split("."), u = R(e, o.slice(0, -1));
621
+ let r = u;
622
+ for (let i = 0; i < o.length - 1; i++) {
623
+ const d = o[i];
624
+ d !== "root" && (Array.isArray(r) ? r = r[parseInt(d)] : r = r[d]);
625
+ }
626
+ const l = o[o.length - 1];
627
+ return l === "root" ? s : (Array.isArray(r) ? r[parseInt(l)] = s : r[l] = s, u);
628
+ }, Z = (e) => {
629
+ _.value.has(e) ? _.value.delete(e) : _.value.add(e);
630
+ }, H = () => {
631
+ const e = /* @__PURE__ */ new Set(), t = (s, o = "") => {
632
+ s !== null && typeof s == "object" && (e.add(o || "root"), Array.isArray(s) ? s.forEach((u, r) => {
633
+ const l = o ? `${o}.${r}` : `${r}`;
634
+ t(u, l);
635
+ }) : Object.keys(s).forEach((u) => {
636
+ const r = o ? `${o}.${u}` : u;
637
+ t(s[u], r);
638
+ }));
639
+ };
640
+ t(h.value), _.value = e, g("expand-all");
641
+ }, K = () => {
642
+ _.value = /* @__PURE__ */ new Set(), g("collapse-all");
643
+ }, ne = async () => {
644
+ if (N.value)
645
+ try {
646
+ const e = h.value, t = L(e, null, 2);
647
+ await navigator.clipboard.writeText(t), g("copy-success", t);
648
+ } catch (e) {
649
+ console.error("Failed to copy JSON:", e), g("copy-error", e instanceof Error ? e : new Error("Failed to copy JSON"));
650
+ }
651
+ }, q = () => {
652
+ if (N.value)
653
+ try {
654
+ const e = h.value, t = L(e);
655
+ g("update:modelValue", t), g("compress", t);
656
+ } catch (e) {
657
+ console.error("Failed to compress JSON:", e);
658
+ }
659
+ }, re = (e) => {
660
+ if (typeof e == "object" && e !== null && !Array.isArray(e) && "__protected_number__" in e && Object.keys(e).length === 1)
661
+ return e.__protected_number__;
662
+ if (typeof e == "string")
663
+ return `"${e}"`;
664
+ const t = JSON.stringify(e);
665
+ return t === void 0 ? "undefined" : t;
666
+ }, n = async (e) => {
667
+ try {
668
+ await navigator.clipboard.writeText(re(e));
669
+ } catch (t) {
670
+ console.error("Failed to copy value:", t);
671
+ }
672
+ }, c = (e, t) => {
673
+ if (!$.readonly)
674
+ try {
675
+ const s = I(f.value, e, t), o = L(s, null, 2);
676
+ g("update:modelValue", o), G(e, t);
677
+ } catch (s) {
678
+ console.error("Failed to rename key:", s);
679
+ }
680
+ }, I = (e, t, s) => {
681
+ if (!t || t === "root") return e;
682
+ const o = t.split("."), u = R(e, o.slice(0, -1));
683
+ if (o.length === 1) {
684
+ const i = o[0];
685
+ return u && typeof u == "object" && !Array.isArray(u) ? P(u, i, s) : u;
686
+ }
687
+ let r = u;
688
+ for (let i = 0; i < o.length - 1; i++) {
689
+ const d = o[i];
690
+ Array.isArray(r) ? r = r[parseInt(d)] : r = r[d];
691
+ }
692
+ const l = o[o.length - 1];
693
+ if (!Array.isArray(r) && r && typeof r == "object") {
694
+ const i = P(r, l, s), d = o.slice(0, -1);
695
+ d.length > 0 && O(u, d, i);
696
+ }
697
+ return u;
698
+ }, R = (e, t) => {
699
+ if (t.length === 0) return e;
700
+ if (Array.isArray(e)) {
701
+ const s = [...e], o = t[0], u = parseInt(o);
702
+ return t.length === 1 || (s[u] = R(e[u], t.slice(1))), s;
703
+ } else if (e && typeof e == "object") {
704
+ const s = { ...e }, o = t[0];
705
+ return t.length === 1 || (s[o] = R(e[o], t.slice(1))), s;
706
+ }
707
+ return e;
708
+ }, P = (e, t, s) => {
709
+ if (!e || typeof e != "object" || Array.isArray(e))
710
+ return e;
711
+ const o = Object.keys(e), u = {};
712
+ for (const r of o)
713
+ r === t ? u[s] = e[r] : u[r] = e[r];
714
+ return u;
715
+ }, O = (e, t, s) => {
716
+ let o = e;
717
+ for (let r = 0; r < t.length - 1; r++) {
718
+ const l = t[r];
719
+ Array.isArray(o) ? o = o[parseInt(l)] : o = o[l];
720
+ }
721
+ const u = t[t.length - 1];
722
+ Array.isArray(o) ? o[parseInt(u)] = s : o[u] = s;
723
+ }, G = (e, t) => {
724
+ const s = /* @__PURE__ */ new Set();
725
+ _.value.forEach((o) => {
726
+ if (o === e) {
727
+ const u = e.split(".");
728
+ u[u.length - 1] = t, s.add(u.join("."));
729
+ } else if (o.startsWith(e + ".")) {
730
+ const u = e.split(".");
731
+ u[u.length - 1] = t;
732
+ const r = u.join("."), l = o.substring(e.length);
733
+ s.add(r + l);
734
+ } else
735
+ s.add(o);
736
+ }), _.value = s;
737
+ };
738
+ return oe({
739
+ // 核心操作方法
740
+ copyJson: ne,
741
+ compressSource: q,
742
+ expandAll: H,
743
+ collapseAll: K,
744
+ toggleExpand: Z,
745
+ updateValue: te,
746
+ updateKey: c,
747
+ // Filter 相关方法
748
+ filter: Y,
749
+ clearFilter: ee,
750
+ // Key 排序相关方法
751
+ sortKeys: ae,
752
+ clearSortKeys: le,
753
+ isSorted: () => A.value,
754
+ // 状态访问方法
755
+ isValidJson: () => N.value,
756
+ getParsedJson: () => f.value,
757
+ getFilteredJson: () => v.value,
758
+ getExpandedNodes: () => _.value,
759
+ getParseError: () => x.value,
760
+ getFilterError: () => y.value,
761
+ // 工具方法
762
+ parseJson: (e) => V(e),
763
+ copyValue: (e) => n(e),
764
+ getValue: (e) => re(e)
765
+ }), (e, t) => (m(), p("div", {
766
+ class: fe(["json-format", `json-format--${E.value.name}`])
767
+ }, [
768
+ j("div", We, [
769
+ N.value ? y.value ? (m(), p("div", Ze, [
770
+ t[1] || (t[1] = j("h4", null, "Filter Error:", -1)),
771
+ j("pre", null, T(y.value), 1)
772
+ ])) : (m(), p("div", qe, [
773
+ de(He, {
774
+ value: h.value,
775
+ "key-name": "",
776
+ level: 0,
777
+ expanded: _.value,
778
+ "is-last": !0,
779
+ theme: E.value,
780
+ "onUpdate:value": te,
781
+ onToggleExpand: Z,
782
+ onCopy: n,
783
+ "onUpdate:key": c
784
+ }, null, 8, ["value", "expanded", "theme"])
785
+ ])) : (m(), p("div", ze, [
786
+ t[0] || (t[0] = j("h4", null, "JSON Parse Error:", -1)),
787
+ j("pre", null, T(x.value), 1)
788
+ ]))
789
+ ])
790
+ ], 2));
791
+ }
792
+ }), et = /* @__PURE__ */ ve(Ge, [["__scopeId", "data-v-4559cb85"]]);
793
+ export {
794
+ et as J
795
+ };