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