lone-format 0.14.0 → 0.16.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.
@@ -0,0 +1,1035 @@
1
+ import { defineComponent as M, computed as q, resolveComponent as z, createElementBlock as N, openBlock as C, createElementVNode as _, createCommentVNode as Y, normalizeClass as $, Fragment as U, renderList as D, createBlock as W, useCssVars as X, ref as B, watch as P, toDisplayString as Z } from "vue";
2
+ import { format as F, supportedDialects as ee } from "sql-formatter";
3
+ import { _ as K } from "./_plugin-vue_export-helper-CHgC5LLL.js";
4
+ const te = {
5
+ name: "github-light",
6
+ colors: {
7
+ // 背景色
8
+ background: "#ffffff",
9
+ surfaceBackground: "#f6f8fa",
10
+ hoverBackground: "#f3f4f6",
11
+ // 边框色
12
+ border: "#d0d7de",
13
+ // 文本色
14
+ text: "#24292f",
15
+ textSecondary: "#57606a",
16
+ // 按钮样式
17
+ buttonBackground: "#f6f8fa",
18
+ buttonBackgroundHover: "#f3f4f6",
19
+ buttonBorder: "#d0d7de",
20
+ buttonText: "#24292f",
21
+ buttonPrimary: "#1f883d",
22
+ buttonPrimaryHover: "#1a7f37",
23
+ // 状态指示
24
+ success: "#1f883d",
25
+ successBackground: "#dafbe1",
26
+ error: "#cf222e",
27
+ errorBackground: "#ffebe9",
28
+ // SQL 语法高亮
29
+ sqlKeyword: "#cf222e",
30
+ // 关键字 - 红色
31
+ sqlFunction: "#8250df",
32
+ // 函数 - 紫色
33
+ sqlString: "#0a3069",
34
+ // 字符串 - 深蓝
35
+ sqlNumber: "#0550ae",
36
+ // 数字 - 蓝色
37
+ sqlComment: "#6e7781",
38
+ // 注释 - 灰色
39
+ sqlOperator: "#cf222e",
40
+ // 操作符 - 红色
41
+ sqlIdentifier: "#24292f",
42
+ // 标识符 - 黑色
43
+ sqlPunctuation: "#24292f",
44
+ // 标点 - 黑色
45
+ // 折叠效果
46
+ collapsedBackground: "#ddf4ff",
47
+ // 折叠信息背景色 - 浅蓝
48
+ collapsedText: "#0969da",
49
+ // 折叠信息文本色 - 蓝色
50
+ // 缩进指示线
51
+ indentLine: "#d0d7de"
52
+ // 对齐线 - 灰色
53
+ }
54
+ }, se = {
55
+ name: "github-dark",
56
+ colors: {
57
+ // 背景色
58
+ background: "#0d1117",
59
+ surfaceBackground: "#161b22",
60
+ hoverBackground: "#30363d",
61
+ // 边框色
62
+ border: "#30363d",
63
+ // 文本色
64
+ text: "#c9d1d9",
65
+ textSecondary: "#8b949e",
66
+ // 按钮样式
67
+ buttonBackground: "#21262d",
68
+ buttonBackgroundHover: "#30363d",
69
+ buttonBorder: "#30363d",
70
+ buttonText: "#c9d1d9",
71
+ buttonPrimary: "#238636",
72
+ buttonPrimaryHover: "#2ea043",
73
+ // 状态指示
74
+ success: "#3fb950",
75
+ successBackground: "#0f2e1c",
76
+ error: "#f85149",
77
+ errorBackground: "#3d1319",
78
+ // SQL 语法高亮
79
+ sqlKeyword: "#ff7b72",
80
+ // 关键字 - 红色
81
+ sqlFunction: "#d2a8ff",
82
+ // 函数 - 紫色
83
+ sqlString: "#a5d6ff",
84
+ // 字符串 - 淡蓝色
85
+ sqlNumber: "#79c0ff",
86
+ // 数字 - 亮蓝色
87
+ sqlComment: "#8b949e",
88
+ // 注释 - 灰色
89
+ sqlOperator: "#ff7b72",
90
+ // 操作符 - 红色
91
+ sqlIdentifier: "#c9d1d9",
92
+ // 标识符 - 白色
93
+ sqlPunctuation: "#c9d1d9",
94
+ // 标点 - 白色
95
+ // 折叠效果
96
+ collapsedBackground: "#1c2d41",
97
+ // 折叠信息背景色 - 深蓝
98
+ collapsedText: "#58a6ff",
99
+ // 折叠信息文本色 - 蓝色
100
+ // 缩进指示线
101
+ indentLine: "#30363d"
102
+ // 对齐线 - 灰色
103
+ }
104
+ }, ne = {
105
+ name: "min-light",
106
+ colors: {
107
+ // 背景色 - 纯白简洁
108
+ background: "#ffffff",
109
+ surfaceBackground: "#fafafa",
110
+ hoverBackground: "#f9f9f9",
111
+ // 边框色 - 极浅灰
112
+ border: "#e5e5e5",
113
+ // 文本色 - 深灰而非纯黑
114
+ text: "#333333",
115
+ textSecondary: "#888888",
116
+ // 按钮样式 - 简约设计
117
+ buttonBackground: "#f8f8f8",
118
+ buttonBackgroundHover: "#eeeeee",
119
+ buttonBorder: "#e0e0e0",
120
+ buttonText: "#333333",
121
+ buttonPrimary: "#007acc",
122
+ buttonPrimaryHover: "#005a9e",
123
+ // 状态指示 - 柔和色彩
124
+ success: "#22c55e",
125
+ successBackground: "#f0fdf4",
126
+ error: "#ef4444",
127
+ errorBackground: "#fef2f2",
128
+ // SQL 语法高亮 - 简约配色(与 JSON 对应)
129
+ sqlKeyword: "#22c55e",
130
+ // 关键字 - 对应 Boolean 红色系
131
+ sqlFunction: "#8b5cf6",
132
+ // 函数 - 对应 Boolean 紫色
133
+ sqlString: "#ef4444",
134
+ // 字符串 - 对应 String 绿色
135
+ sqlNumber: "#3b82f6",
136
+ // 数字 - 对应 Number 蓝色
137
+ sqlComment: "#6b7280",
138
+ // 注释 - 对应 Null 灰色
139
+ sqlOperator: "#ef4444",
140
+ // 操作符 - 红色
141
+ sqlIdentifier: "#1f2937",
142
+ // 标识符 - 对应 Key 深灰
143
+ sqlPunctuation: "#374151",
144
+ // 标点 - 对应 Bracket 灰色
145
+ // 折叠效果
146
+ collapsedBackground: "#e0f2fe",
147
+ // 折叠信息背景色 - 浅蓝
148
+ collapsedText: "#0284c7",
149
+ // 折叠信息文本色 - 蓝色
150
+ // 缩进指示线
151
+ indentLine: "#e5e7eb"
152
+ // 对齐线 - 灰色
153
+ }
154
+ }, re = {
155
+ name: "min-dark",
156
+ colors: {
157
+ // 背景色 - 极简暗色
158
+ background: "#111111",
159
+ surfaceBackground: "#1a1a1a",
160
+ hoverBackground: "#1f1f1f",
161
+ // 边框色 - 柔和深灰
162
+ border: "#2a2a2a",
163
+ // 文本色 - 柔和浅灰
164
+ text: "#e5e5e5",
165
+ textSecondary: "#a3a3a3",
166
+ // 按钮样式 - 简约暗色
167
+ buttonBackground: "#1f1f1f",
168
+ buttonBackgroundHover: "#2a2a2a",
169
+ buttonBorder: "#333333",
170
+ buttonText: "#e5e5e5",
171
+ buttonPrimary: "#3b82f6",
172
+ buttonPrimaryHover: "#2563eb",
173
+ // 状态指示 - 暗色可读性
174
+ success: "#22c55e",
175
+ successBackground: "#052e16",
176
+ error: "#f87171",
177
+ errorBackground: "#450a0a",
178
+ // SQL 语法高亮 - 极简暗色配色
179
+ sqlKeyword: "#4ade80",
180
+ // 关键字 - 绿色
181
+ sqlFunction: "#c084fc",
182
+ // 函数 - 紫色
183
+ sqlString: "#f87171",
184
+ // 字符串 - 红色
185
+ sqlNumber: "#60a5fa",
186
+ // 数字 - 蓝色
187
+ sqlComment: "#9ca3af",
188
+ // 注释 - 灰色
189
+ sqlOperator: "#f87171",
190
+ // 操作符 - 红色
191
+ sqlIdentifier: "#f3f4f6",
192
+ // 标识符 - 浅灰
193
+ sqlPunctuation: "#d1d5db",
194
+ // 标点 - 浅灰
195
+ // 折叠效果
196
+ collapsedBackground: "#1e293b",
197
+ // 折叠信息背景色 - 深蓝灰
198
+ collapsedText: "#60a5fa",
199
+ // 折叠信息文本色 - 蓝色
200
+ // 缩进指示线
201
+ indentLine: "#374151"
202
+ // 对齐线 - 深灰
203
+ }
204
+ }, oe = {
205
+ name: "slack-ochin",
206
+ colors: {
207
+ // 背景色
208
+ background: "#fef5ed",
209
+ surfaceBackground: "#fef9f3",
210
+ hoverBackground: "#f9f0e5",
211
+ // 边框色
212
+ border: "#e9dcc9",
213
+ // 文本色
214
+ text: "#3d3c40",
215
+ textSecondary: "#616061",
216
+ // 按钮样式
217
+ buttonBackground: "#fef9f3",
218
+ buttonBackgroundHover: "#f9f0e5",
219
+ buttonBorder: "#e9dcc9",
220
+ buttonText: "#3d3c40",
221
+ buttonPrimary: "#007a5a",
222
+ buttonPrimaryHover: "#006644",
223
+ // 状态指示
224
+ success: "#007a5a",
225
+ successBackground: "#d1f4e0",
226
+ error: "#e01e5a",
227
+ errorBackground: "#ffdbea",
228
+ // SQL 语法高亮
229
+ sqlKeyword: "#e01e5a",
230
+ // 关键字 - 红色
231
+ sqlFunction: "#8b2eff",
232
+ // 函数 - 紫色
233
+ sqlString: "#0b4c8c",
234
+ // 字符串 - 深蓝
235
+ sqlNumber: "#1264a3",
236
+ // 数字 - 蓝色
237
+ sqlComment: "#616061",
238
+ // 注释 - 灰色
239
+ sqlOperator: "#e01e5a",
240
+ // 操作符 - 红色
241
+ sqlIdentifier: "#3d3c40",
242
+ // 标识符 - 深色
243
+ sqlPunctuation: "#3d3c40",
244
+ // 标点 - 深色
245
+ // 折叠效果
246
+ collapsedBackground: "#d8eaf5",
247
+ // 折叠信息背景色 - 浅蓝
248
+ collapsedText: "#0b4c8c",
249
+ // 折叠信息文本色 - 深蓝
250
+ // 缩进指示线
251
+ indentLine: "#3e4348"
252
+ // 对齐线 - 灰色
253
+ }
254
+ }, H = {
255
+ "github-light": te,
256
+ "github-dark": se,
257
+ "min-light": ne,
258
+ "min-dark": re,
259
+ "slack-ochin": oe
260
+ }, le = (l) => H[l] || H["github-light"], j = [
261
+ "SELECT",
262
+ "FROM",
263
+ "WHERE",
264
+ "JOIN",
265
+ "INNER",
266
+ "LEFT",
267
+ "RIGHT",
268
+ "FULL",
269
+ "OUTER",
270
+ "ON",
271
+ "GROUP",
272
+ "BY",
273
+ "HAVING",
274
+ "ORDER",
275
+ "LIMIT",
276
+ "OFFSET",
277
+ "INSERT",
278
+ "INTO",
279
+ "VALUES",
280
+ "UPDATE",
281
+ "SET",
282
+ "DELETE",
283
+ "CREATE",
284
+ "ALTER",
285
+ "DROP",
286
+ "TABLE",
287
+ "DATABASE",
288
+ "INDEX",
289
+ "VIEW",
290
+ "AND",
291
+ "OR",
292
+ "NOT",
293
+ "IN",
294
+ "BETWEEN",
295
+ "LIKE",
296
+ "IS",
297
+ "NULL",
298
+ "AS",
299
+ "DISTINCT",
300
+ "UNION",
301
+ "ALL",
302
+ "EXISTS",
303
+ "CASE",
304
+ "WHEN",
305
+ "THEN",
306
+ "ELSE",
307
+ "END"
308
+ ], ae = [
309
+ "WITH",
310
+ "SELECT",
311
+ "FROM",
312
+ "WHERE",
313
+ "GROUP BY",
314
+ "HAVING",
315
+ "ORDER BY",
316
+ "LIMIT",
317
+ "INSERT INTO",
318
+ "UPDATE",
319
+ "SET",
320
+ "DELETE FROM",
321
+ "CREATE",
322
+ "ALTER",
323
+ "DROP",
324
+ "INNER JOIN",
325
+ "LEFT JOIN",
326
+ "RIGHT JOIN",
327
+ "FULL JOIN",
328
+ "CROSS JOIN",
329
+ "OUTER JOIN",
330
+ "JOIN",
331
+ "UNION ALL",
332
+ "UNION",
333
+ "INTERSECT",
334
+ "EXCEPT"
335
+ ], A = "sql", ce = new Set(ee), Q = (l = A) => {
336
+ const t = String(l).trim().toLowerCase();
337
+ if (!ce.has(t))
338
+ throw new Error(`Unsupported SQL dialect: ${l}`);
339
+ return t;
340
+ }, ie = (l, t = A) => {
341
+ try {
342
+ if (!l || !l.trim())
343
+ return { valid: !1, error: "SQL string is empty" };
344
+ const e = l.toUpperCase().trim();
345
+ if (!j.some((h) => new RegExp(`\\b${h}\\b`).test(e)))
346
+ return { valid: !1, error: "No valid SQL keywords found" };
347
+ let s = 0, u = !1, n = "";
348
+ for (let h = 0; h < l.length; h++) {
349
+ const r = l[h], d = h > 0 ? l[h - 1] : "";
350
+ if ((r === "'" || r === '"') && d !== "\\" && (u ? r === n && (u = !1, n = "") : (u = !0, n = r)), !u && (r === "(" && s++, r === ")" && s--, s < 0))
351
+ return { valid: !1, error: "Mismatched parentheses: unexpected closing parenthesis" };
352
+ }
353
+ if (s !== 0)
354
+ return { valid: !1, error: `Mismatched parentheses: ${s} unclosed opening parenthesis` };
355
+ const i = Q(t);
356
+ return F(l, { language: i }), { valid: !0 };
357
+ } catch (e) {
358
+ return {
359
+ valid: !1,
360
+ error: e instanceof Error ? e.message : "Unknown validation error"
361
+ };
362
+ }
363
+ }, ue = (l, t) => {
364
+ const e = l.match(/\bVALUES\s*/i);
365
+ if (!e || e.index === void 0) return l;
366
+ const f = l.slice(0, e.index + e[0].length), s = l.slice(e.index + e[0].length), u = [];
367
+ let n = 0, i = "", h = !1, r = "", d = 0;
368
+ for (; d < s.length; ) {
369
+ const o = s[d], k = d > 0 ? s[d - 1] : "";
370
+ if ((o === "'" || o === '"') && k !== "\\" && (h ? o === r && (h = !1) : (h = !0, r = o)), h)
371
+ n > 0 && (i += o);
372
+ else if (o === "(")
373
+ n === 0 ? i = o : i += o, n++;
374
+ else if (o === ")")
375
+ i += o, n--, n === 0 && i.trim() && (u.push(i.trim()), i = "");
376
+ else {
377
+ if (o === ";" && n === 0)
378
+ break;
379
+ n > 0 && (i += o);
380
+ }
381
+ d++;
382
+ }
383
+ if (u.length === 0)
384
+ return l;
385
+ const g = " ".repeat(t), v = u.map((o) => {
386
+ const k = o.slice(1, -1), E = [];
387
+ let S = "", I = 0, L = !1, x = "";
388
+ for (let c = 0; c < k.length; c++) {
389
+ const b = k[c], y = c > 0 ? k[c - 1] : "";
390
+ if ((b === "'" || b === '"') && y !== "\\" && (L ? b === x && (L = !1) : (L = !0, x = b)), !L && (b === "(" && I++, b === ")" && I--, b === "," && I === 0)) {
391
+ E.push(S.trim()), S = "";
392
+ continue;
393
+ }
394
+ S += b;
395
+ }
396
+ S.trim() && E.push(S.trim());
397
+ const O = E.map((c, b) => {
398
+ const y = b < E.length - 1 ? "," : "";
399
+ return `${g}${g}${c}${y}`;
400
+ }).join(`
401
+ `);
402
+ return `${g}(
403
+ ${O}
404
+ ${g})`;
405
+ }), m = v.map((o, k) => {
406
+ const E = k < v.length - 1 ? "," : ";";
407
+ return o + E;
408
+ }).join(`
409
+ `);
410
+ let a = d;
411
+ a < s.length && s[a] === ";" && a++;
412
+ const p = s.slice(a);
413
+ return f.trimEnd() + `
414
+ ` + m + p;
415
+ }, V = (l, t) => {
416
+ try {
417
+ const e = Q(t?.dialect ?? A), f = t?.tabWidth || 2, s = t?.keywordCase || "upper", u = t?.useTabs || !1, n = t?.linesBetweenQueries || 1;
418
+ let i = F(l, {
419
+ language: e,
420
+ tabWidth: f,
421
+ keywordCase: s,
422
+ useTabs: u,
423
+ linesBetweenQueries: n,
424
+ // 其他默认配置
425
+ indentStyle: "standard"
426
+ });
427
+ return /\bINSERT\s+INTO\b/i.test(i) && /\bVALUES\b/i.test(i) && (i = ue(i, f)), i;
428
+ } catch (e) {
429
+ const f = e instanceof Error ? e.message : "Unknown formatting error";
430
+ throw new Error(`SQL formatting error: ${f}`);
431
+ }
432
+ }, de = (l) => {
433
+ try {
434
+ const t = [];
435
+ let e = l.replace(/(["'])(?:(?=(\\?))\2.)*?\1/g, (f) => (t.push(f), `__STR_${t.length - 1}__`));
436
+ return e = e.replace(/--[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, ""), e = e.replace(/\s+/g, " ").trim(), t.forEach((f, s) => {
437
+ e = e.replace(`__STR_${s}__`, f);
438
+ }), e;
439
+ } catch (t) {
440
+ return console.error("SQL compression error:", t), l;
441
+ }
442
+ }, fe = (l, t) => {
443
+ const e = [], f = l.match(/^(.*?\bVALUES\b)/is);
444
+ if (!f) return [];
445
+ const s = f[1].trim();
446
+ e.push({
447
+ type: "VALUES",
448
+ content: s,
449
+ raw: s,
450
+ collapsible: !1,
451
+ path: `clause-${t}`
452
+ });
453
+ let n = l.slice(f[1].length).trim(), i = 0, h = 0, r = "", d = !1, g = "";
454
+ for (let v = 0; v < n.length; v++) {
455
+ const m = n[v], a = v > 0 ? n[v - 1] : "";
456
+ if ((m === "'" || m === '"') && a !== "\\" && (d ? m === g && (d = !1) : (d = !0, g = m)), d)
457
+ h > 0 && (r += m);
458
+ else if (m === "(" && h === 0)
459
+ h++, r = m;
460
+ else if (m === "(")
461
+ h++, r += m;
462
+ else if (m === ")") {
463
+ if (r += m, h--, h === 0) {
464
+ let p = v + 1, o = "";
465
+ for (; p < n.length; ) {
466
+ const E = n[p];
467
+ if (E === "," || E === ";") {
468
+ o = E;
469
+ break;
470
+ } else if (!/\s/.test(E))
471
+ break;
472
+ p++;
473
+ }
474
+ const k = r.trim();
475
+ k && (e.push({
476
+ type: "VALUE_TUPLE",
477
+ content: k + o,
478
+ raw: k + o,
479
+ collapsible: !0,
480
+ path: `clause-${t}-value-${i}`
481
+ }), i++), r = "", o && (v = p);
482
+ }
483
+ } else h > 0 && (r += m);
484
+ }
485
+ return e;
486
+ }, pe = (l, t) => /\n\s*ON\b/i.test(t) ? t : t.replace(
487
+ /^(\s*)((?:INNER|LEFT|RIGHT|FULL|CROSS|OUTER)?\s*JOIN\b[^\n]*?)\s+ON\b\s*/gim,
488
+ `$1$2
489
+ $1ON `
490
+ ), he = (l) => {
491
+ let t = 0, e = !1, f = "";
492
+ for (let s = 0; s < l.length; s++) {
493
+ const u = l[s], n = s > 0 ? l[s - 1] : "";
494
+ if ((u === "'" || u === '"') && n !== "\\") {
495
+ e ? u === f && (e = !1, f = "") : (e = !0, f = u);
496
+ continue;
497
+ }
498
+ e || (u === "(" && t++, u === ")" && t--);
499
+ }
500
+ return t;
501
+ }, me = (l) => {
502
+ const t = [];
503
+ let e = 0, f = -1, s = !1, u = "";
504
+ for (let n = 0; n < l.length; n++) {
505
+ const i = l[n], h = n > 0 ? l[n - 1] : "";
506
+ if ((i === "'" || i === '"') && h !== "\\") {
507
+ s ? i === u && (s = !1, u = "") : (s = !0, u = i);
508
+ continue;
509
+ }
510
+ s || (i === "(" ? (e === 0 && (f = n), e++) : i === ")" && (e--, e === 0 && f >= 0 && (t.push({ open: f, close: n }), f = -1)));
511
+ }
512
+ return t;
513
+ }, ge = (l) => {
514
+ const t = l.trim();
515
+ return t ? /^(SELECT|WITH)\b/i.test(t) ? !0 : /\n\s*(SELECT|FROM|WHERE|JOIN|UNION|INTERSECT|EXCEPT)\b/i.test(l) : !1;
516
+ }, be = (l) => {
517
+ const t = l.content.split(`
518
+ `);
519
+ let e = -1;
520
+ for (let r = 0; r < t.length; r++)
521
+ if (t[r].trim()) {
522
+ e = r;
523
+ break;
524
+ }
525
+ if (e < 0) return;
526
+ const f = t.slice(e + 1).join(`
527
+ `);
528
+ if (!f) return;
529
+ const u = me(f).filter(
530
+ (r) => ge(f.slice(r.open + 1, r.close))
531
+ );
532
+ if (u.length === 0) return;
533
+ const n = [];
534
+ let i = 0;
535
+ const h = l.path || "clause";
536
+ u.forEach((r, d) => {
537
+ r.open + 1 > i && n.push({ kind: "text", text: f.slice(i, r.open + 1) });
538
+ const g = f.lastIndexOf(`
539
+ `, r.close - 1) + 1, v = g > r.open, m = v ? g - 1 : r.close, a = f.slice(r.open + 1, m), p = J(a, `${h}-sub${d}-`);
540
+ for (const o of p)
541
+ n.push({ kind: "clause", clause: o });
542
+ i = v ? g : r.close;
543
+ }), i < f.length && n.push({ kind: "text", text: f.slice(i) }), l.body = n;
544
+ }, J = (l, t) => {
545
+ const e = [], f = l.split(`
546
+ `);
547
+ let s = null, u = [], n = [], i = 0;
548
+ const h = [...ae].sort((d, g) => g.length - d.length), r = () => {
549
+ if (!s || u.length === 0) return;
550
+ let d = u.join(`
551
+ `);
552
+ if (d = pe(s.type, d), s.content = d, s.raw = d, s.type === "INSERT INTO" && /\bVALUES\b/i.test(d)) {
553
+ const g = d.match(/^(.*?\bINSERT\s+INTO\s+[^(]+\s*\([^)]+\))/is);
554
+ if (g) {
555
+ const v = {
556
+ type: "INSERT INTO",
557
+ content: g[1].trim(),
558
+ raw: g[1].trim(),
559
+ collapsible: !0,
560
+ path: `${t}clause-${e.length}`
561
+ };
562
+ e.push(v);
563
+ const m = d.slice(g[1].length).trim(), a = e.length, p = fe(m, a);
564
+ for (let o = 0; o < p.length; o++)
565
+ p[o].path = `${t}clause-${a + o}`;
566
+ e.push(...p);
567
+ return;
568
+ }
569
+ }
570
+ be(s), e.push(s);
571
+ };
572
+ for (const d of f) {
573
+ const g = d.trim();
574
+ if (!g) {
575
+ s && u.push(d);
576
+ continue;
577
+ }
578
+ if (g.startsWith("--") || g.startsWith("/*")) {
579
+ s ? u.push(d) : n.push(d);
580
+ continue;
581
+ }
582
+ let m = !1, a = "UNKNOWN";
583
+ if (i === 0) {
584
+ for (const p of h)
585
+ if (new RegExp(`^${p}\\b`, "i").test(g)) {
586
+ m = !0, a = p.toUpperCase();
587
+ break;
588
+ }
589
+ }
590
+ m ? (r(), n.length > 0 && (e.push({
591
+ type: "UNKNOWN",
592
+ content: n.join(`
593
+ `),
594
+ raw: n.join(`
595
+ `),
596
+ collapsible: !1,
597
+ path: `${t}clause-${e.length}`
598
+ }), n = []), u = [d], s = {
599
+ type: a,
600
+ content: "",
601
+ raw: "",
602
+ collapsible: !0,
603
+ path: `${t}clause-${e.length}`
604
+ }) : s ? u.push(d) : (u = [...n, d], n = [], s = {
605
+ type: "UNKNOWN",
606
+ content: "",
607
+ raw: "",
608
+ collapsible: !1,
609
+ path: `${t}clause-${e.length}`
610
+ }), i = Math.max(0, i + he(d));
611
+ }
612
+ return r(), n.length > 0 && e.push({
613
+ type: "UNKNOWN",
614
+ content: n.join(`
615
+ `),
616
+ raw: n.join(`
617
+ `),
618
+ collapsible: !1,
619
+ path: `${t}clause-${e.length}`
620
+ }), e;
621
+ }, ve = (l, t = A) => {
622
+ const e = V(l, { dialect: t, keywordCase: "upper" });
623
+ return { clauses: J(e, ""), raw: l };
624
+ }, G = (l) => {
625
+ const t = [];
626
+ let e = l;
627
+ const f = [
628
+ "COUNT",
629
+ "SUM",
630
+ "AVG",
631
+ "MAX",
632
+ "MIN",
633
+ "UPPER",
634
+ "LOWER",
635
+ "SUBSTRING",
636
+ "CONCAT",
637
+ "LENGTH",
638
+ "TRIM",
639
+ "NOW",
640
+ "DATE",
641
+ "YEAR",
642
+ "MONTH",
643
+ "DAY",
644
+ "COALESCE",
645
+ "CAST",
646
+ "CONVERT",
647
+ "ROUND",
648
+ "ABS",
649
+ "FLOOR",
650
+ "CEIL"
651
+ ], s = ["=", "!=", "<>", "<", ">", "<=", ">=", "+", "-", "*", "/", "%", "||"], u = ["(", ")", ",", ";", "."];
652
+ for (; e.length > 0; ) {
653
+ let n = !1;
654
+ const i = e.match(/^(\s+)/);
655
+ if (i) {
656
+ t.push({ type: "whitespace", value: i[1] }), e = e.slice(i[1].length);
657
+ continue;
658
+ }
659
+ const h = e.match(/^(--[^\n]*)/);
660
+ if (h) {
661
+ t.push({ type: "comment", value: h[1] }), e = e.slice(h[1].length);
662
+ continue;
663
+ }
664
+ const r = e.match(/^(\/\*[\s\S]*?\*\/)/);
665
+ if (r) {
666
+ t.push({ type: "comment", value: r[1] }), e = e.slice(r[1].length);
667
+ continue;
668
+ }
669
+ const d = e.match(/^(["'])(?:(?=(\\?))\2.)*?\1/);
670
+ if (d) {
671
+ t.push({ type: "string", value: d[0] }), e = e.slice(d[0].length);
672
+ continue;
673
+ }
674
+ const g = e.match(/^(\d+\.?\d*|\.\d+)/);
675
+ if (g) {
676
+ t.push({ type: "number", value: g[1] }), e = e.slice(g[1].length);
677
+ continue;
678
+ }
679
+ for (const m of s)
680
+ if (e.startsWith(m)) {
681
+ t.push({ type: "operator", value: m }), e = e.slice(m.length), n = !0;
682
+ break;
683
+ }
684
+ if (n) continue;
685
+ for (const m of u)
686
+ if (e.startsWith(m)) {
687
+ t.push({ type: "punctuation", value: m }), e = e.slice(m.length), n = !0;
688
+ break;
689
+ }
690
+ if (n) continue;
691
+ const v = e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)/);
692
+ if (v) {
693
+ const m = v[1], a = m.toUpperCase();
694
+ j.includes(a) ? t.push({ type: "keyword", value: m }) : f.includes(a) ? t.push({ type: "function", value: m }) : t.push({ type: "identifier", value: m }), e = e.slice(m.length);
695
+ continue;
696
+ }
697
+ t.push({ type: "punctuation", value: e[0] }), e = e.slice(1);
698
+ }
699
+ return t;
700
+ }, ke = { class: "sql-clause-node" }, Ee = ["title"], ye = { class: "sql-clause-node__code" }, Se = ["innerHTML"], Te = {
701
+ key: 0,
702
+ class: "sql-clause-node__body"
703
+ }, Ce = ["title"], Ne = ["innerHTML"], qe = ["title"], _e = ["innerHTML"], Ie = /* @__PURE__ */ M({
704
+ __name: "SqlClauseNode",
705
+ props: {
706
+ clause: {},
707
+ expandedClauses: {},
708
+ theme: {}
709
+ },
710
+ emits: ["toggle"],
711
+ setup(l, { emit: t }) {
712
+ const e = l, f = t, s = q(() => e.clause.path || ""), u = q(() => e.expandedClauses.has(s.value)), n = q(() => {
713
+ const a = e.clause.content.split(`
714
+ `);
715
+ for (const p of a)
716
+ if (p.trim()) return p;
717
+ return "";
718
+ }), i = q(() => {
719
+ const a = e.clause.content.split(`
720
+ `);
721
+ if (a.length <= 1) return "";
722
+ let p = 0;
723
+ for (let o = 0; o < a.length; o++)
724
+ if (a[o].trim()) {
725
+ p = o;
726
+ break;
727
+ }
728
+ return a.slice(p + 1).join(`
729
+ `);
730
+ }), h = q(() => e.clause.body && e.clause.body.length > 0 ? !0 : !!i.value), r = (a) => {
731
+ const p = G(a), o = e.theme.colors;
732
+ return p.map((k) => {
733
+ let E = o.text;
734
+ switch (k.type) {
735
+ case "keyword":
736
+ E = o.sqlKeyword;
737
+ break;
738
+ case "function":
739
+ E = o.sqlFunction;
740
+ break;
741
+ case "string":
742
+ E = o.sqlString;
743
+ break;
744
+ case "number":
745
+ E = o.sqlNumber;
746
+ break;
747
+ case "comment":
748
+ E = o.sqlComment;
749
+ break;
750
+ case "operator":
751
+ E = o.sqlOperator;
752
+ break;
753
+ case "identifier":
754
+ E = o.sqlIdentifier;
755
+ break;
756
+ case "punctuation":
757
+ E = o.sqlPunctuation;
758
+ break;
759
+ case "whitespace":
760
+ return k.value.replace(/ /g, "&nbsp;").replace(/\n/g, `
761
+ `);
762
+ }
763
+ const S = k.value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
764
+ return `<span style="color: ${E}">${S}</span>`;
765
+ }).join("");
766
+ }, d = q(() => {
767
+ const a = e.clause.body;
768
+ if (!a || a.length === 0) return null;
769
+ let p = "", o = !1;
770
+ for (const c of a)
771
+ if (c.kind === "text") {
772
+ const b = c.text.indexOf("(");
773
+ if (b >= 0) {
774
+ p += c.text.slice(0, b), o = !0;
775
+ break;
776
+ }
777
+ p += c.text;
778
+ } else
779
+ return null;
780
+ if (!o) return null;
781
+ let k = "";
782
+ for (let c = a.length - 1; c >= 0; c--) {
783
+ const b = a[c];
784
+ if (b.kind === "text") {
785
+ const y = b.text.lastIndexOf(")");
786
+ if (y >= 0) {
787
+ k = b.text.slice(y + 1) + k;
788
+ break;
789
+ }
790
+ k = b.text + k;
791
+ } else
792
+ break;
793
+ }
794
+ const E = p.replace(/\s+/g, " ").trim(), S = k.replace(/\s+/g, " ").trim(), I = n.value, L = (I.match(/^\s*/) || [""])[0], O = [I.trimStart()];
795
+ return E && O.push(E), O.push("(...)"), S && O.push(S), `${L}${O.join(" ")}`;
796
+ }), g = q(() => {
797
+ if (e.clause.collapsible && !u.value && h.value) {
798
+ const a = d.value;
799
+ if (a)
800
+ return r(a);
801
+ const p = r(n.value), o = e.theme.colors.textSecondary;
802
+ return `${p}<span style="color: ${o}; opacity: 0.6; font-style: italic; margin-left: 4px;"> ...</span>`;
803
+ }
804
+ return r(n.value);
805
+ }), v = () => {
806
+ e.clause.collapsible && f("toggle", s.value);
807
+ }, m = (a) => {
808
+ if (!e.clause.collapsible) return;
809
+ const p = a.target;
810
+ if (!p) return;
811
+ const o = (p.textContent || "").trim();
812
+ (o === "(" || o === ")") && f("toggle", s.value);
813
+ };
814
+ return (a, p) => {
815
+ const o = z("SqlClauseNode", !0);
816
+ return C(), N("div", ke, [
817
+ _("div", {
818
+ class: $(["sql-clause-node__header", { "sql-clause-node__header--collapsible": a.clause.collapsible }]),
819
+ title: a.clause.collapsible ? u.value ? "Click to collapse" : "Click to expand" : "",
820
+ onClick: v
821
+ }, [
822
+ _("pre", ye, [
823
+ _("code", { innerHTML: g.value }, null, 8, Se)
824
+ ])
825
+ ], 10, Ee),
826
+ u.value && h.value ? (C(), N("div", Te, [
827
+ a.clause.body && a.clause.body.length > 0 ? (C(!0), N(U, { key: 0 }, D(a.clause.body, (k, E) => (C(), N(U, { key: E }, [
828
+ k.kind === "text" ? (C(), N("pre", {
829
+ key: 0,
830
+ class: $(["sql-clause-node__code sql-clause-node__text-segment", { "sql-clause-node__text-segment--clickable": a.clause.collapsible }]),
831
+ title: a.clause.collapsible ? "Click ( or ) to collapse" : "",
832
+ onClick: p[0] || (p[0] = (S) => m(S))
833
+ }, [
834
+ _("code", {
835
+ innerHTML: r(k.text)
836
+ }, null, 8, Ne)
837
+ ], 10, Ce)) : (C(), W(o, {
838
+ key: 1,
839
+ clause: k.clause,
840
+ "expanded-clauses": a.expandedClauses,
841
+ theme: a.theme,
842
+ onToggle: p[1] || (p[1] = (S) => a.$emit("toggle", S))
843
+ }, null, 8, ["clause", "expanded-clauses", "theme"]))
844
+ ], 64))), 128)) : (C(), N("pre", {
845
+ key: 1,
846
+ class: $(["sql-clause-node__code sql-clause-node__rest", { "sql-clause-node__rest--clickable": a.clause.collapsible }]),
847
+ title: a.clause.collapsible ? "Click ( or ) to collapse" : "",
848
+ onClick: p[2] || (p[2] = (k) => m(k))
849
+ }, [
850
+ _("code", {
851
+ innerHTML: r(i.value)
852
+ }, null, 8, _e)
853
+ ], 10, qe))
854
+ ])) : Y("", !0)
855
+ ]);
856
+ };
857
+ }
858
+ }), Le = /* @__PURE__ */ K(Ie, [["__scopeId", "data-v-8b9383dc"]]), Oe = { class: "sql-format__content" }, xe = {
859
+ key: 0,
860
+ class: "sql-format__error"
861
+ }, we = {
862
+ key: 1,
863
+ class: "sql-format__viewer"
864
+ }, Be = {
865
+ key: 0,
866
+ class: "sql-format__clauses"
867
+ }, Re = {
868
+ key: 1,
869
+ class: "sql-format__code"
870
+ }, $e = ["innerHTML"], Ae = /* @__PURE__ */ M({
871
+ __name: "index",
872
+ props: {
873
+ modelValue: { default: "" },
874
+ readonly: { type: Boolean, default: !1 },
875
+ theme: { default: "github-light" },
876
+ dialect: { default: "sql" },
877
+ tabWidth: { default: 2 }
878
+ },
879
+ emits: ["update:modelValue", "copy-success", "copy-error", "expand-all", "collapse-all", "compress", "format"],
880
+ setup(l, { expose: t, emit: e }) {
881
+ X((c) => ({
882
+ eb378acc: v.value.colors.background,
883
+ f6f4a8ce: v.value.colors.text,
884
+ "151cb76a": v.value.colors.errorBackground,
885
+ "0b62391c": v.value.colors.error
886
+ }));
887
+ const f = (c) => {
888
+ const b = [], y = (w) => {
889
+ for (const T of w)
890
+ if (T.path && b.push(T.path), T.body)
891
+ for (const R of T.body)
892
+ R.kind === "clause" && y([R.clause]);
893
+ };
894
+ return y(c), b;
895
+ }, s = l, u = e, n = B(""), i = B(s.dialect), h = B([]), r = B(/* @__PURE__ */ new Set()), d = B(""), g = q(() => n.value === ""), v = q(() => le(s.theme)), m = (c) => {
896
+ if (!c || !c.trim()) {
897
+ n.value = "", h.value = [], r.value.clear();
898
+ return;
899
+ }
900
+ try {
901
+ const b = ie(c, i.value);
902
+ if (!b.valid) {
903
+ n.value = b.error || "Invalid SQL", h.value = [], d.value = "";
904
+ return;
905
+ }
906
+ const y = ve(c, i.value);
907
+ h.value = y.clauses, d.value = V(c, {
908
+ dialect: i.value,
909
+ tabWidth: s.tabWidth
910
+ }), r.value = new Set(f(y.clauses)), n.value = "";
911
+ } catch (b) {
912
+ n.value = b instanceof Error ? b.message : "Unknown parse error", h.value = [], d.value = "";
913
+ }
914
+ }, a = (c) => {
915
+ const b = G(c), y = v.value.colors;
916
+ return b.map((w) => {
917
+ let T = y.text;
918
+ switch (w.type) {
919
+ case "keyword":
920
+ T = y.sqlKeyword;
921
+ break;
922
+ case "function":
923
+ T = y.sqlFunction;
924
+ break;
925
+ case "string":
926
+ T = y.sqlString;
927
+ break;
928
+ case "number":
929
+ T = y.sqlNumber;
930
+ break;
931
+ case "comment":
932
+ T = y.sqlComment;
933
+ break;
934
+ case "operator":
935
+ T = y.sqlOperator;
936
+ break;
937
+ case "identifier":
938
+ T = y.sqlIdentifier;
939
+ break;
940
+ case "punctuation":
941
+ T = y.sqlPunctuation;
942
+ break;
943
+ case "whitespace":
944
+ return w.value.replace(/ /g, "&nbsp;").replace(/\n/g, `
945
+ `);
946
+ }
947
+ const R = w.value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
948
+ return `<span style="color: ${T}">${R}</span>`;
949
+ }).join("");
950
+ }, p = (c) => {
951
+ r.value.has(c) ? r.value.delete(c) : r.value.add(c), r.value = new Set(r.value);
952
+ }, o = () => {
953
+ r.value = new Set(f(h.value)), u("expand-all");
954
+ }, k = () => {
955
+ r.value = /* @__PURE__ */ new Set(), u("collapse-all");
956
+ }, E = () => d.value || s.modelValue, S = async () => {
957
+ if (g.value)
958
+ try {
959
+ const c = E();
960
+ await navigator.clipboard.writeText(c), u("copy-success", c);
961
+ } catch (c) {
962
+ const b = c instanceof Error ? c : new Error("Failed to copy");
963
+ u("copy-error", b);
964
+ }
965
+ }, I = () => {
966
+ if (g.value)
967
+ try {
968
+ const c = V(s.modelValue, {
969
+ dialect: i.value,
970
+ tabWidth: s.tabWidth
971
+ });
972
+ u("update:modelValue", c), u("format", c);
973
+ } catch (c) {
974
+ console.error("Format error:", c);
975
+ }
976
+ }, L = () => {
977
+ if (g.value)
978
+ try {
979
+ const c = de(s.modelValue);
980
+ u("update:modelValue", c), u("compress", c);
981
+ } catch (c) {
982
+ console.error("Compress error:", c);
983
+ }
984
+ }, x = () => null, O = () => n.value;
985
+ return P(
986
+ () => s.modelValue,
987
+ (c) => {
988
+ m(c);
989
+ },
990
+ { immediate: !0 }
991
+ ), P(
992
+ () => s.dialect,
993
+ (c) => {
994
+ i.value = c, m(s.modelValue);
995
+ }
996
+ ), t({
997
+ copySql: S,
998
+ formatSource: I,
999
+ compressSource: L,
1000
+ expandAll: o,
1001
+ collapseAll: k,
1002
+ toggleExpand: p,
1003
+ isValidSql: () => g.value,
1004
+ getParsedSql: x,
1005
+ getParseError: O,
1006
+ getValue: E
1007
+ }), (c, b) => (C(), N("div", {
1008
+ class: $(["sql-format", `sql-format--${v.value.name}`])
1009
+ }, [
1010
+ _("div", Oe, [
1011
+ g.value ? (C(), N("div", we, [
1012
+ h.value.length > 0 ? (C(), N("div", Be, [
1013
+ (C(!0), N(U, null, D(h.value, (y) => (C(), W(Le, {
1014
+ key: y.path,
1015
+ clause: y,
1016
+ "expanded-clauses": r.value,
1017
+ theme: v.value,
1018
+ onToggle: p
1019
+ }, null, 8, ["clause", "expanded-clauses", "theme"]))), 128))
1020
+ ])) : (C(), N("pre", Re, [
1021
+ _("code", {
1022
+ innerHTML: a(s.modelValue)
1023
+ }, null, 8, $e)
1024
+ ]))
1025
+ ])) : (C(), N("div", xe, [
1026
+ b[0] || (b[0] = _("h4", null, "SQL Parse Error:", -1)),
1027
+ _("pre", null, Z(n.value), 1)
1028
+ ]))
1029
+ ])
1030
+ ], 2));
1031
+ }
1032
+ }), He = /* @__PURE__ */ K(Ae, [["__scopeId", "data-v-d9005677"]]);
1033
+ export {
1034
+ He as S
1035
+ };