lone-format 0.12.1 → 0.13.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-13rwh2MK.js +788 -0
  3. package/dist/_chunks/index-DfjCsqDT.js +1005 -0
  4. package/dist/_chunks/index-DvNM7Tl4.js +1784 -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 +50 -0
  9. package/dist/components/JsonFormat/themes.d.ts +29 -0
  10. package/dist/components/JsonFormat/types.d.ts +96 -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 +43 -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 +99 -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 +57 -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 +113 -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 -31862
  29. package/dist/lone-format.umd.cjs +53 -49
  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,788 @@
1
+ import { defineComponent as ue, useCssVars as ce, ref as B, computed as b, resolveComponent as ve, createElementBlock as p, openBlock as m, createElementVNode as j, createCommentVNode as w, withKeys as R, withModifiers as le, toDisplayString as $, Fragment as pe, renderList as me, createVNode as ie, normalizeClass as de, nextTick as G, watch as ge } from "vue";
2
+ import { JSONPath as _e } from "jsonpath-plus";
3
+ import { _ as fe } from "./_plugin-vue_export-helper-CHgC5LLL.js";
4
+ const be = { class: "json-node" }, ke = {
5
+ key: 0,
6
+ class: "json-node__container"
7
+ }, he = { class: "json-node__line" }, Be = ["contenteditable", "onKeydown"], xe = {
8
+ key: 1,
9
+ class: "json-node__colon"
10
+ }, Ne = ["title"], je = ["title"], Se = {
11
+ key: 4,
12
+ class: "json-node__comma"
13
+ }, Ae = {
14
+ key: 0,
15
+ class: "json-node__children"
16
+ }, Ee = { class: "json-node__children-content" }, we = { class: "json-node__line json-node__closing-bracket" }, Oe = { class: "json-node__bracket" }, Je = {
17
+ key: 0,
18
+ class: "json-node__comma"
19
+ }, Te = {
20
+ key: 1,
21
+ class: "json-node__primitive"
22
+ }, $e = ["contenteditable", "onKeydown"], Ve = {
23
+ key: 1,
24
+ class: "json-node__colon"
25
+ }, Pe = ["title"], Ce = ["contenteditable", "onKeydown"], Fe = {
26
+ key: 0,
27
+ class: "json-node__comma"
28
+ }, De = /* @__PURE__ */ ue({
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(U, { emit: re }) {
42
+ ce((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 = U, V = re, g = B(!1), f = B(!1), x = 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 = 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"), P = b(() => a.expanded.has(h.value)), Q = b(() => a.keyName), oe = b(() => F.value ? "[" : "{"), D = b(() => F.value ? "]" : "}"), M = 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
+ }), X = 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
+ }), se = 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)), ae = b(() => "Double-click to edit"), L = (n) => a.level === 0 ? n : h.value ? `${h.value}.${n}` : n, Y = (n) => {
66
+ const c = Object.keys(a.value);
67
+ return c.indexOf(n) === c.length - 1;
68
+ }, W = () => {
69
+ V("toggle-expand", h.value);
70
+ }, z = () => {
71
+ a.level !== 0 && (g.value = !0, x.value = a.keyName, G(() => {
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
+ }, H = () => {
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) ? _.value = E(a.value) : typeof a.value == "string" ? _.value = a.value : _.value = String(a.value), G(() => {
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
+ Z();
95
+ return;
96
+ }
97
+ if (n === a.keyName) {
98
+ g.value = !1;
99
+ return;
100
+ }
101
+ g.value = !1, V("update:key", h.value, n);
102
+ }, ee = () => {
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 O = Number(c);
117
+ !Number.isSafeInteger(O) || c.length > 15 ? n = { __protected_number__: c } : n = O;
118
+ } else
119
+ n = c;
120
+ V("update:value", h.value, n), f.value = !1;
121
+ } catch (n) {
122
+ console.error("Failed to parse value:", n), f.value = !1;
123
+ }
124
+ }, Z = () => {
125
+ g.value = !1, x.value = a.keyName;
126
+ }, te = () => {
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 O = ve("JsonNode", !0);
131
+ return m(), p("div", be, [
132
+ C.value ? (m(), p("div", ke, [
133
+ j("div", he, [
134
+ n.keyName ? (m(), p("span", {
135
+ key: 0,
136
+ class: "json-node__key",
137
+ contenteditable: g.value,
138
+ onDblclick: z,
139
+ onKeydown: [
140
+ R(le(K, ["prevent"]), ["enter"]),
141
+ R(Z, ["escape"])
142
+ ],
143
+ onBlur: K,
144
+ ref_key: "keyRef",
145
+ ref: v,
146
+ title: "Double-click to edit key"
147
+ }, $(g.value ? x.value : `"${Q.value}"`), 41, Be)) : w("", !0),
148
+ n.keyName ? (m(), p("span", xe, ": ")) : w("", !0),
149
+ j("span", {
150
+ class: "json-node__bracket json-node__bracket--clickable",
151
+ onClick: W,
152
+ title: P.value ? "Click to collapse" : "Click to expand"
153
+ }, $(oe.value), 9, Ne),
154
+ P.value ? w("", !0) : (m(), p("span", {
155
+ key: 2,
156
+ class: "json-node__collapsed-info",
157
+ onClick: W,
158
+ title: `Click to expand ${M.value.trim()}`
159
+ }, $(M.value), 9, je)),
160
+ P.value ? w("", !0) : (m(), p("span", {
161
+ key: 3,
162
+ class: "json-node__bracket json-node__bracket--clickable",
163
+ onClick: W,
164
+ title: "Click to expand"
165
+ }, $(D.value), 1)),
166
+ !P.value && !n.isLast ? (m(), p("span", Se, ",")) : w("", !0)
167
+ ]),
168
+ P.value ? (m(), p("div", Ae, [
169
+ j("div", Ee, [
170
+ (m(!0), p(pe, null, me(n.value, (ne, I) => (m(), p("div", {
171
+ key: I,
172
+ class: "json-node__child"
173
+ }, [
174
+ ie(O, {
175
+ value: ne,
176
+ "key-name": F.value ? "" : String(I),
177
+ level: n.level + 1,
178
+ path: L(String(I)),
179
+ expanded: n.expanded,
180
+ theme: n.theme,
181
+ "onUpdate:value": c[0] || (c[0] = (J, e) => n.$emit("update:value", J, e)),
182
+ onToggleExpand: c[1] || (c[1] = (J) => n.$emit("toggle-expand", J)),
183
+ onCopy: c[2] || (c[2] = (J) => n.$emit("copy", J)),
184
+ "onUpdate:key": c[3] || (c[3] = (J, e) => n.$emit("update:key", J, e)),
185
+ "is-last": Y(String(I))
186
+ }, null, 8, ["value", "key-name", "level", "path", "expanded", "theme", "is-last"])
187
+ ]))), 128))
188
+ ]),
189
+ j("div", we, [
190
+ j("span", Oe, $(D.value), 1),
191
+ n.isLast ? w("", !0) : (m(), p("span", Je, ","))
192
+ ])
193
+ ])) : w("", !0)
194
+ ])) : (m(), p("div", Te, [
195
+ n.keyName ? (m(), p("span", {
196
+ key: 0,
197
+ class: "json-node__key",
198
+ contenteditable: g.value,
199
+ onDblclick: z,
200
+ onKeydown: [
201
+ R(le(K, ["prevent"]), ["enter"]),
202
+ R(Z, ["escape"])
203
+ ],
204
+ onBlur: K,
205
+ ref_key: "keyRef",
206
+ ref: v,
207
+ title: "Double-click to edit key"
208
+ }, $(g.value ? x.value : `"${Q.value}"`), 41, $e)) : w("", !0),
209
+ n.keyName ? (m(), p("span", Ve, ": ")) : w("", !0),
210
+ j("span", {
211
+ class: de(["json-node__value-wrapper", X.value]),
212
+ onDblclick: H,
213
+ title: ae.value
214
+ }, [
215
+ j("span", {
216
+ class: "json-node__value",
217
+ contenteditable: f.value,
218
+ onKeydown: [
219
+ R(le(ee, ["prevent"]), ["enter"]),
220
+ R(te, ["escape"])
221
+ ],
222
+ onBlur: ee,
223
+ ref_key: "valueRef",
224
+ ref: A
225
+ }, $(f.value ? _.value : se.value), 41, Ce),
226
+ n.isLast ? w("", !0) : (m(), p("span", Fe, ","))
227
+ ], 42, Pe)
228
+ ]))
229
+ ]);
230
+ };
231
+ }
232
+ }), Le = /* @__PURE__ */ fe(De, [["__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
+ }, He = {
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
+ }, Ke = {
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
+ }, Ie = {
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
+ }, Re = {
397
+ "github-light": ye,
398
+ "github-dark": He,
399
+ "min-light": Ke,
400
+ "slack-ochin": Ie
401
+ };
402
+ function Ue(U = "github-light") {
403
+ return Re[U] || ye;
404
+ }
405
+ const Me = { class: "json-format__content" }, We = {
406
+ key: 0,
407
+ class: "json-format__error"
408
+ }, ze = {
409
+ key: 1,
410
+ class: "json-format__error"
411
+ }, Ze = {
412
+ key: 2,
413
+ class: "json-format__viewer"
414
+ }, qe = /* @__PURE__ */ ue({
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(U, { expose: re, emit: a }) {
425
+ ce((e) => ({
426
+ "1909cc0c": E.value.colors.background,
427
+ "1d49ba8b": E.value.colors.text,
428
+ e9bfef2c: E.value.colors.error,
429
+ "16d23d38": E.value.colors.errorBackground
430
+ }));
431
+ const V = U, g = a, f = B(null), x = B(""), _ = B(/* @__PURE__ */ new Set()), y = B(null), v = B(""), A = B(!1), N = b(() => x.value === ""), E = b(() => Ue(V.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 = y.value !== null ? y.value : f.value;
445
+ return !e || !A.value ? e : C(e);
446
+ }), h = b(() => v.value ? null : F.value), P = (e) => {
447
+ if (!e.trim()) {
448
+ f.value = null, x.value = "", y.value = null, v.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 = "", y.value = null, v.value = "", G(() => {
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 T = r[k];
466
+ if (i)
467
+ d ? d = !1 : T === "\\" ? d = !0 : T === '"' && (i = !1), l += T, k++;
468
+ else if (T === '"')
469
+ i = !0, l += T, 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 += T, k++;
482
+ }
483
+ }
484
+ return l;
485
+ })(t), f.value = JSON.parse(t), x.value = "", y.value = null, v.value = "", G(() => {
486
+ h.value !== null && H();
487
+ });
488
+ } catch (t) {
489
+ x.value = t instanceof Error ? t.message : "Unknown parsing error", f.value = null, y.value = null, v.value = "";
490
+ }
491
+ }, Q = (e) => {
492
+ if (!e || !e.expression.trim()) {
493
+ X();
494
+ return;
495
+ }
496
+ if (!f.value) {
497
+ v.value = "No valid JSON data to filter";
498
+ return;
499
+ }
500
+ try {
501
+ let t;
502
+ if (e.type === "jsonpath")
503
+ 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;
504
+ else if (e.type === "js") {
505
+ const { proxyData: s, indexMap: o } = oe(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), y.value = t;
513
+ } else
514
+ throw new Error(`Unsupported filter type: ${e.type}`);
515
+ v.value = "", G(() => {
516
+ H();
517
+ });
518
+ } catch (t) {
519
+ v.value = t instanceof Error ? t.message : "Filter execution error", y.value = null;
520
+ }
521
+ }, oe = (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 T = `${l}[${k}]`, q = o(d, T);
532
+ return s.set(q, T), 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 = M(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 = M(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
+ }, M = (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
+ }, X = () => {
587
+ y.value = null, v.value = "";
588
+ }, se = () => {
589
+ A.value = !0;
590
+ }, ae = () => {
591
+ A.value = !1;
592
+ };
593
+ ge(() => V.modelValue, (e) => {
594
+ P(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
+ }, Y = (e, t) => {
611
+ if (!V.readonly)
612
+ try {
613
+ const s = W(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
+ }, W = (e, t, s) => {
619
+ if (!t || t === "root") return s;
620
+ const o = t.split("."), u = O(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
+ }, ee = 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
+ }, Z = () => {
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
+ }, te = async (e) => {
660
+ try {
661
+ let t;
662
+ typeof e == "object" && e !== null && !Array.isArray(e) && "__protected_number__" in e && Object.keys(e).length === 1 ? t = e.__protected_number__ : typeof e == "string" ? t = `"${e}"` : t = JSON.stringify(e), await navigator.clipboard.writeText(t);
663
+ } catch (t) {
664
+ console.error("Failed to copy value:", t);
665
+ }
666
+ }, n = (e, t) => {
667
+ if (!V.readonly)
668
+ try {
669
+ const s = c(f.value, e, t), o = L(s, null, 2);
670
+ g("update:modelValue", o), J(e, t);
671
+ } catch (s) {
672
+ console.error("Failed to rename key:", s);
673
+ }
674
+ }, c = (e, t, s) => {
675
+ if (!t || t === "root") return e;
676
+ const o = t.split("."), u = O(e, o.slice(0, -1));
677
+ if (o.length === 1) {
678
+ const i = o[0];
679
+ return u && typeof u == "object" && !Array.isArray(u) ? ne(u, i, s) : u;
680
+ }
681
+ let r = u;
682
+ for (let i = 0; i < o.length - 1; i++) {
683
+ const d = o[i];
684
+ Array.isArray(r) ? r = r[parseInt(d)] : r = r[d];
685
+ }
686
+ const l = o[o.length - 1];
687
+ if (!Array.isArray(r) && r && typeof r == "object") {
688
+ const i = ne(r, l, s), d = o.slice(0, -1);
689
+ d.length > 0 && I(u, d, i);
690
+ }
691
+ return u;
692
+ }, O = (e, t) => {
693
+ if (t.length === 0) return e;
694
+ if (Array.isArray(e)) {
695
+ const s = [...e], o = t[0], u = parseInt(o);
696
+ return t.length === 1 || (s[u] = O(e[u], t.slice(1))), s;
697
+ } else if (e && typeof e == "object") {
698
+ const s = { ...e }, o = t[0];
699
+ return t.length === 1 || (s[o] = O(e[o], t.slice(1))), s;
700
+ }
701
+ return e;
702
+ }, ne = (e, t, s) => {
703
+ if (!e || typeof e != "object" || Array.isArray(e))
704
+ return e;
705
+ const o = Object.keys(e), u = {};
706
+ for (const r of o)
707
+ r === t ? u[s] = e[r] : u[r] = e[r];
708
+ return u;
709
+ }, I = (e, t, s) => {
710
+ let o = e;
711
+ for (let r = 0; r < t.length - 1; r++) {
712
+ const l = t[r];
713
+ Array.isArray(o) ? o = o[parseInt(l)] : o = o[l];
714
+ }
715
+ const u = t[t.length - 1];
716
+ Array.isArray(o) ? o[parseInt(u)] = s : o[u] = s;
717
+ }, J = (e, t) => {
718
+ const s = /* @__PURE__ */ new Set();
719
+ _.value.forEach((o) => {
720
+ if (o === e) {
721
+ const u = e.split(".");
722
+ u[u.length - 1] = t, s.add(u.join("."));
723
+ } else if (o.startsWith(e + ".")) {
724
+ const u = e.split(".");
725
+ u[u.length - 1] = t;
726
+ const r = u.join("."), l = o.substring(e.length);
727
+ s.add(r + l);
728
+ } else
729
+ s.add(o);
730
+ }), _.value = s;
731
+ };
732
+ return re({
733
+ // 核心操作方法
734
+ copyJson: ee,
735
+ compressSource: Z,
736
+ expandAll: H,
737
+ collapseAll: K,
738
+ toggleExpand: z,
739
+ updateValue: Y,
740
+ updateKey: n,
741
+ // Filter 相关方法
742
+ filter: Q,
743
+ clearFilter: X,
744
+ // Key 排序相关方法
745
+ sortKeys: se,
746
+ clearSortKeys: ae,
747
+ isSorted: () => A.value,
748
+ // 状态访问方法
749
+ isValidJson: () => N.value,
750
+ getParsedJson: () => f.value,
751
+ getFilteredJson: () => y.value,
752
+ getExpandedNodes: () => _.value,
753
+ getParseError: () => x.value,
754
+ getFilterError: () => v.value,
755
+ // 工具方法
756
+ parseJson: (e) => P(e),
757
+ copyValue: (e) => te(e)
758
+ }), (e, t) => (m(), p("div", {
759
+ class: de(["json-format", `json-format--${E.value.name}`])
760
+ }, [
761
+ j("div", Me, [
762
+ N.value ? v.value ? (m(), p("div", ze, [
763
+ t[1] || (t[1] = j("h4", null, "Filter Error:", -1)),
764
+ j("pre", null, $(v.value), 1)
765
+ ])) : (m(), p("div", Ze, [
766
+ ie(Le, {
767
+ value: h.value,
768
+ "key-name": "",
769
+ level: 0,
770
+ expanded: _.value,
771
+ "is-last": !0,
772
+ theme: E.value,
773
+ "onUpdate:value": Y,
774
+ onToggleExpand: z,
775
+ onCopy: te,
776
+ "onUpdate:key": n
777
+ }, null, 8, ["value", "expanded", "theme"])
778
+ ])) : (m(), p("div", We, [
779
+ t[0] || (t[0] = j("h4", null, "JSON Parse Error:", -1)),
780
+ j("pre", null, $(x.value), 1)
781
+ ]))
782
+ ])
783
+ ], 2));
784
+ }
785
+ }), Ye = /* @__PURE__ */ fe(qe, [["__scopeId", "data-v-a802c0ac"]]);
786
+ export {
787
+ Ye as J
788
+ };