@onerjs/code-input 0.0.0-stage → 0.1.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.
- package/README.md +289 -2
- package/dist/code-input.cjs +20 -0
- package/dist/code-input.es.js +1222 -0
- package/dist/components/CodeEditor.vue.d.ts +61 -0
- package/dist/core/builtins.d.ts +2 -0
- package/dist/core/completion.d.ts +12 -0
- package/dist/core/hover.d.ts +6 -0
- package/dist/core/keywords.d.ts +3 -0
- package/dist/core/parser.d.ts +2 -0
- package/dist/core/template.d.ts +6 -0
- package/dist/core/tokenizer.d.ts +13 -0
- package/dist/core/types.d.ts +22 -0
- package/dist/index.d.ts +12 -0
- package/dist/style.css +1 -0
- package/package.json +49 -5
|
@@ -0,0 +1,1222 @@
|
|
|
1
|
+
import { defineComponent as mt, ref as $, computed as P, watch as Ie, nextTick as O, onMounted as ht, onBeforeUnmount as bt, openBlock as T, createElementBlock as C, normalizeStyle as te, normalizeClass as ne, createElementVNode as I, Fragment as Me, renderList as He, toDisplayString as F, createCommentVNode as z, withModifiers as gt, createTextVNode as vt } from "vue";
|
|
2
|
+
const yt = [
|
|
3
|
+
{
|
|
4
|
+
label: "Math",
|
|
5
|
+
kind: "class",
|
|
6
|
+
detail: "Math",
|
|
7
|
+
type: `interface Math {
|
|
8
|
+
readonly PI: number
|
|
9
|
+
readonly E: number
|
|
10
|
+
abs(x: number): number
|
|
11
|
+
round(x: number): number
|
|
12
|
+
max(...values: number[]): number
|
|
13
|
+
random(): number
|
|
14
|
+
}`,
|
|
15
|
+
documentation: "内置数学对象",
|
|
16
|
+
members: [
|
|
17
|
+
{ label: "PI", kind: "property", detail: "number" },
|
|
18
|
+
{ label: "E", kind: "property", detail: "number" },
|
|
19
|
+
{ label: "abs", kind: "function", detail: "(x: number) => number" },
|
|
20
|
+
{ label: "ceil", kind: "function", detail: "(x: number) => number" },
|
|
21
|
+
{ label: "floor", kind: "function", detail: "(x: number) => number" },
|
|
22
|
+
{ label: "round", kind: "function", detail: "(x: number) => number" },
|
|
23
|
+
{ label: "max", kind: "function", detail: "(...values: number[]) => number" },
|
|
24
|
+
{ label: "min", kind: "function", detail: "(...values: number[]) => number" },
|
|
25
|
+
{ label: "pow", kind: "function", detail: "(base: number, exp: number) => number" },
|
|
26
|
+
{ label: "random", kind: "function", detail: "() => number" },
|
|
27
|
+
{ label: "sqrt", kind: "function", detail: "(x: number) => number" },
|
|
28
|
+
{ label: "trunc", kind: "function", detail: "(x: number) => number" }
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: "JSON",
|
|
33
|
+
kind: "class",
|
|
34
|
+
detail: "JSON",
|
|
35
|
+
members: [
|
|
36
|
+
{ label: "parse", kind: "function", detail: "(text: string) => any" },
|
|
37
|
+
{ label: "stringify", kind: "function", detail: "(value: any, space?: number) => string" }
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
label: "console",
|
|
42
|
+
kind: "variable",
|
|
43
|
+
detail: "Console",
|
|
44
|
+
members: [
|
|
45
|
+
{ label: "log", kind: "function", detail: "(...data: any[]) => void" },
|
|
46
|
+
{ label: "info", kind: "function", detail: "(...data: any[]) => void" },
|
|
47
|
+
{ label: "warn", kind: "function", detail: "(...data: any[]) => void" },
|
|
48
|
+
{ label: "error", kind: "function", detail: "(...data: any[]) => void" },
|
|
49
|
+
{ label: "debug", kind: "function", detail: "(...data: any[]) => void" },
|
|
50
|
+
{ label: "table", kind: "function", detail: "(data: any) => void" },
|
|
51
|
+
{ label: "time", kind: "function", detail: "(label: string) => void" },
|
|
52
|
+
{ label: "timeEnd", kind: "function", detail: "(label: string) => void" }
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
label: "Object",
|
|
57
|
+
kind: "class",
|
|
58
|
+
detail: "Object",
|
|
59
|
+
members: [
|
|
60
|
+
{ label: "keys", kind: "function", detail: "(o: object) => string[]" },
|
|
61
|
+
{ label: "values", kind: "function", detail: "(o: object) => any[]" },
|
|
62
|
+
{ label: "entries", kind: "function", detail: "(o: object) => [string, any][]" },
|
|
63
|
+
{ label: "assign", kind: "function", detail: "(target: object, ...sources: object[]) => object" },
|
|
64
|
+
{ label: "freeze", kind: "function", detail: "(o: object) => object" }
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
label: "Array",
|
|
69
|
+
kind: "class",
|
|
70
|
+
detail: "Array",
|
|
71
|
+
members: [
|
|
72
|
+
{ label: "isArray", kind: "function", detail: "(value: any) => boolean" },
|
|
73
|
+
{ label: "from", kind: "function", detail: "(iterable: any) => any[]" },
|
|
74
|
+
{ label: "of", kind: "function", detail: "(...items: any[]) => any[]" }
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
label: "Promise",
|
|
79
|
+
kind: "class",
|
|
80
|
+
detail: "Promise",
|
|
81
|
+
members: [
|
|
82
|
+
{ label: "resolve", kind: "function", detail: "(value?: any) => Promise<any>" },
|
|
83
|
+
{ label: "reject", kind: "function", detail: "(reason?: any) => Promise<never>" },
|
|
84
|
+
{ label: "all", kind: "function", detail: "(values: any[]) => Promise<any[]>" },
|
|
85
|
+
{ label: "race", kind: "function", detail: "(values: any[]) => Promise<any>" }
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
label: "Date",
|
|
90
|
+
kind: "class",
|
|
91
|
+
detail: "Date",
|
|
92
|
+
members: [
|
|
93
|
+
{ label: "now", kind: "function", detail: "() => number" },
|
|
94
|
+
{ label: "parse", kind: "function", detail: "(dateString: string) => number" }
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
label: "String",
|
|
99
|
+
kind: "class",
|
|
100
|
+
detail: "String",
|
|
101
|
+
members: [
|
|
102
|
+
{ label: "fromCharCode", kind: "function", detail: "(...codes: number[]) => string" },
|
|
103
|
+
{ label: "from", kind: "function", detail: "(value: any) => string" }
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
label: "Number",
|
|
108
|
+
kind: "class",
|
|
109
|
+
detail: "Number",
|
|
110
|
+
members: [
|
|
111
|
+
{ label: "isNaN", kind: "function", detail: "(value: any) => boolean" },
|
|
112
|
+
{ label: "isInteger", kind: "function", detail: "(value: any) => boolean" },
|
|
113
|
+
{ label: "parseFloat", kind: "function", detail: "(value: string) => number" },
|
|
114
|
+
{ label: "parseInt", kind: "function", detail: "(value: string, radix?: number) => number" }
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
label: "setTimeout",
|
|
119
|
+
kind: "function",
|
|
120
|
+
detail: "(callback: Function, ms?: number) => number"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
label: "clearTimeout",
|
|
124
|
+
kind: "function",
|
|
125
|
+
detail: "(id: number) => void"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
label: "setInterval",
|
|
129
|
+
kind: "function",
|
|
130
|
+
detail: "(callback: Function, ms?: number) => number"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
label: "clearInterval",
|
|
134
|
+
kind: "function",
|
|
135
|
+
detail: "(id: number) => void"
|
|
136
|
+
}
|
|
137
|
+
], Ae = [
|
|
138
|
+
"break",
|
|
139
|
+
"case",
|
|
140
|
+
"catch",
|
|
141
|
+
"class",
|
|
142
|
+
"const",
|
|
143
|
+
"continue",
|
|
144
|
+
"debugger",
|
|
145
|
+
"default",
|
|
146
|
+
"delete",
|
|
147
|
+
"do",
|
|
148
|
+
"else",
|
|
149
|
+
"export",
|
|
150
|
+
"extends",
|
|
151
|
+
"finally",
|
|
152
|
+
"for",
|
|
153
|
+
"from",
|
|
154
|
+
"function",
|
|
155
|
+
"if",
|
|
156
|
+
"import",
|
|
157
|
+
"in",
|
|
158
|
+
"instanceof",
|
|
159
|
+
"let",
|
|
160
|
+
"new",
|
|
161
|
+
"of",
|
|
162
|
+
"return",
|
|
163
|
+
"super",
|
|
164
|
+
"switch",
|
|
165
|
+
"this",
|
|
166
|
+
"throw",
|
|
167
|
+
"try",
|
|
168
|
+
"typeof",
|
|
169
|
+
"var",
|
|
170
|
+
"void",
|
|
171
|
+
"while",
|
|
172
|
+
"with",
|
|
173
|
+
"yield",
|
|
174
|
+
"async",
|
|
175
|
+
"await",
|
|
176
|
+
"true",
|
|
177
|
+
"false",
|
|
178
|
+
"null",
|
|
179
|
+
"undefined",
|
|
180
|
+
"NaN",
|
|
181
|
+
"Infinity"
|
|
182
|
+
], kt = [
|
|
183
|
+
"abstract",
|
|
184
|
+
"any",
|
|
185
|
+
"as",
|
|
186
|
+
"asserts",
|
|
187
|
+
"bigint",
|
|
188
|
+
"boolean",
|
|
189
|
+
"declare",
|
|
190
|
+
"enum",
|
|
191
|
+
"implements",
|
|
192
|
+
"infer",
|
|
193
|
+
"interface",
|
|
194
|
+
"is",
|
|
195
|
+
"keyof",
|
|
196
|
+
"namespace",
|
|
197
|
+
"never",
|
|
198
|
+
"number",
|
|
199
|
+
"object",
|
|
200
|
+
"override",
|
|
201
|
+
"private",
|
|
202
|
+
"protected",
|
|
203
|
+
"public",
|
|
204
|
+
"readonly",
|
|
205
|
+
"satisfies",
|
|
206
|
+
"static",
|
|
207
|
+
"string",
|
|
208
|
+
"symbol",
|
|
209
|
+
"type",
|
|
210
|
+
"unknown"
|
|
211
|
+
];
|
|
212
|
+
function Fe(o) {
|
|
213
|
+
return o === "typescript" ? [...Ae, ...kt] : Ae;
|
|
214
|
+
}
|
|
215
|
+
function Le(o) {
|
|
216
|
+
return new Set(Fe(o));
|
|
217
|
+
}
|
|
218
|
+
const wt = /((?:[A-Za-z_$][\w$]*\??\.)*)([A-Za-z_$][\w$]*)?$/, Be = /\b(?:const|let|var|function|class)\s+([A-Za-z_$][\w$]*)/g, xt = /^[A-Za-z_$]/;
|
|
219
|
+
function $t(o, r) {
|
|
220
|
+
const i = o.slice(0, r), n = wt.exec(i);
|
|
221
|
+
if (!n) return { prefix: "", chain: [] };
|
|
222
|
+
const l = n[1] ?? "", c = n[2] ?? "", u = l.split(".").filter(Boolean).map((d) => d.replace(/\?$/, ""));
|
|
223
|
+
return { prefix: c, chain: u };
|
|
224
|
+
}
|
|
225
|
+
function Oe(o, r) {
|
|
226
|
+
const i = [], n = /* @__PURE__ */ new Set();
|
|
227
|
+
let l;
|
|
228
|
+
for (Be.lastIndex = 0; (l = Be.exec(o)) && !(l.index >= r); ) {
|
|
229
|
+
const c = l[1];
|
|
230
|
+
if (n.has(c)) continue;
|
|
231
|
+
n.add(c);
|
|
232
|
+
const u = l[0].slice(0, l[0].indexOf(c)).trim();
|
|
233
|
+
i.push({
|
|
234
|
+
label: c,
|
|
235
|
+
kind: u === "function" ? "function" : u === "class" ? "class" : "variable",
|
|
236
|
+
detail: "当前文件"
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return i;
|
|
240
|
+
}
|
|
241
|
+
function Ve(o, r) {
|
|
242
|
+
let i = r;
|
|
243
|
+
for (const n of o) {
|
|
244
|
+
if (!i) return null;
|
|
245
|
+
const l = i.find((c) => c.label === n);
|
|
246
|
+
if (!l) return null;
|
|
247
|
+
i = l.members ?? [];
|
|
248
|
+
}
|
|
249
|
+
return i;
|
|
250
|
+
}
|
|
251
|
+
function Tt(o, r) {
|
|
252
|
+
const i = o.toLowerCase(), n = r.toLowerCase(), l = i.indexOf(n);
|
|
253
|
+
if (l === 0) return 1e3 - i.length;
|
|
254
|
+
if (l > 0) return 800 - l;
|
|
255
|
+
let c = 0, u = 0, d = -1;
|
|
256
|
+
for (let a = 0; a < i.length && c < n.length; a++)
|
|
257
|
+
i[a] === n[c] && (d >= 0 && (u += a - d - 1), d = a, c++);
|
|
258
|
+
return c !== n.length ? null : 400 - u - i.length;
|
|
259
|
+
}
|
|
260
|
+
function Ct(o, r) {
|
|
261
|
+
if (!r) return o;
|
|
262
|
+
const i = [];
|
|
263
|
+
for (const n of o) {
|
|
264
|
+
const l = Tt(n.label, r);
|
|
265
|
+
l !== null && i.push({ item: n, score: l });
|
|
266
|
+
}
|
|
267
|
+
return i.sort((n, l) => l.score - n.score || n.item.label.localeCompare(l.item.label)), i.map((n) => n.item);
|
|
268
|
+
}
|
|
269
|
+
function St(o) {
|
|
270
|
+
const r = /* @__PURE__ */ new Set(), i = [];
|
|
271
|
+
for (const n of o)
|
|
272
|
+
r.has(n.label) || (r.add(n.label), i.push(n));
|
|
273
|
+
return i;
|
|
274
|
+
}
|
|
275
|
+
function Et(o, r, i) {
|
|
276
|
+
const { prefix: n, chain: l } = $t(o, r);
|
|
277
|
+
if (i.auto && (!n && l.length === 0 || n && !xt.test(n)))
|
|
278
|
+
return null;
|
|
279
|
+
const c = i.declared ?? [], u = [...c, ...i.completions];
|
|
280
|
+
let d;
|
|
281
|
+
if (l.length > 0) {
|
|
282
|
+
const f = Ve(l, u);
|
|
283
|
+
if (!f || f.length === 0) return null;
|
|
284
|
+
d = f;
|
|
285
|
+
} else
|
|
286
|
+
d = [
|
|
287
|
+
...i.completions,
|
|
288
|
+
...c,
|
|
289
|
+
...Fe(i.language).map((f) => ({
|
|
290
|
+
label: f,
|
|
291
|
+
kind: "keyword"
|
|
292
|
+
}))
|
|
293
|
+
];
|
|
294
|
+
const a = Ct(St(d), n);
|
|
295
|
+
return a.length === 0 ? null : {
|
|
296
|
+
items: a,
|
|
297
|
+
start: r - n.length,
|
|
298
|
+
end: r
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
const _t = /([A-Za-z_$][\w$]*(?:\??\.[A-Za-z_$][\w$]*)*)\??\.\s*$/;
|
|
302
|
+
function Rt(o, r, i, n) {
|
|
303
|
+
const l = o.slice(r, i);
|
|
304
|
+
if (!l) return null;
|
|
305
|
+
const c = [...n.declared ?? [], ...n.completions], u = _t.exec(o.slice(0, r));
|
|
306
|
+
if (u) {
|
|
307
|
+
const d = u[1].split(".").filter(Boolean).map((b) => b.replace(/\?$/, "")), a = Ve(d, c), f = a == null ? void 0 : a.find((b) => b.label === l);
|
|
308
|
+
if (f) return f;
|
|
309
|
+
}
|
|
310
|
+
return c.find((d) => d.label === l) ?? null;
|
|
311
|
+
}
|
|
312
|
+
const V = "[A-Za-z_$][\\w$]*", Ne = "(?:readonly\\s+|public\\s+|private\\s+|protected\\s+|static\\s+|abstract\\s+)*";
|
|
313
|
+
function We(o, r) {
|
|
314
|
+
let i = 0, n = !1, l = r;
|
|
315
|
+
for (let c = r; c < o.length; c++) {
|
|
316
|
+
const u = o[c];
|
|
317
|
+
for (let d = 0; d < u.length; d++) {
|
|
318
|
+
const a = u[d];
|
|
319
|
+
a === "{" ? (i++, n = !0) : a === "}" && i--;
|
|
320
|
+
}
|
|
321
|
+
if (n && i <= 0) {
|
|
322
|
+
l = c;
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return { end: l, body: o.slice(r + 1, l) };
|
|
327
|
+
}
|
|
328
|
+
function ze(o) {
|
|
329
|
+
return o.trim().replace(/[,;]$/, "").trim();
|
|
330
|
+
}
|
|
331
|
+
function De(o) {
|
|
332
|
+
const r = [], i = /* @__PURE__ */ new Set(), n = new RegExp(`^${Ne}(${V})(\\?)?\\s*\\((.*)\\)\\s*:\\s*(.+?);?$`), l = new RegExp(`^${Ne}(${V})(\\?)?\\s*:\\s*(.+?);?$`);
|
|
333
|
+
for (const c of o) {
|
|
334
|
+
const u = c.trim();
|
|
335
|
+
if (!u || u.startsWith("//") || u.startsWith("/*") || u.startsWith("*") || u.startsWith("}"))
|
|
336
|
+
continue;
|
|
337
|
+
const d = n.exec(u);
|
|
338
|
+
if (d) {
|
|
339
|
+
const f = d[1];
|
|
340
|
+
if (i.has(f)) continue;
|
|
341
|
+
i.add(f), r.push({
|
|
342
|
+
label: f,
|
|
343
|
+
kind: "function",
|
|
344
|
+
detail: `(${d[3].trim()}) => ${ze(d[4])}`
|
|
345
|
+
});
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const a = l.exec(u);
|
|
349
|
+
if (a) {
|
|
350
|
+
const f = a[1];
|
|
351
|
+
if (i.has(f)) continue;
|
|
352
|
+
i.add(f);
|
|
353
|
+
const b = ze(a[3]), y = /^\(|=>/.test(b) ? "function" : "property";
|
|
354
|
+
r.push({ label: f, kind: y, detail: b });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return r;
|
|
358
|
+
}
|
|
359
|
+
function Ke(o) {
|
|
360
|
+
const r = o.replace(/\[\]/g, "").replace(/<[^>]*>/g, "").replace(/\s*\|\s*null\s*/g, "").trim(), i = new RegExp(`^(${V})$`).exec(r);
|
|
361
|
+
return i ? i[1] : null;
|
|
362
|
+
}
|
|
363
|
+
function It(o) {
|
|
364
|
+
const r = o.trim();
|
|
365
|
+
if (!r || r.endsWith(";")) return !1;
|
|
366
|
+
const i = (r.match(/[(<[{]/g) ?? []).length, n = (r.match(/[)>\]}]/g) ?? []).length;
|
|
367
|
+
return /[|&,(<]\s*$/.test(r) || i > n;
|
|
368
|
+
}
|
|
369
|
+
function Ze(o, r, i, n = 0) {
|
|
370
|
+
return n > 6 ? o : o.map((l) => {
|
|
371
|
+
if (l.kind !== "property" || !l.detail) return l;
|
|
372
|
+
const c = Ke(l.detail), u = c ? r.get(c) : void 0;
|
|
373
|
+
if (!u || i.has(u.label)) return l;
|
|
374
|
+
const d = new Set(i);
|
|
375
|
+
return d.add(u.label), {
|
|
376
|
+
...l,
|
|
377
|
+
type: u.type,
|
|
378
|
+
members: Ze(u.members, r, d, n + 1)
|
|
379
|
+
};
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
function Mt(o) {
|
|
383
|
+
if (!o || !o.trim()) return [];
|
|
384
|
+
const r = o.split(`
|
|
385
|
+
`), i = /* @__PURE__ */ new Map(), n = new RegExp(`^(?:export\\s+)?(?:declare\\s+)?interface\\s+(${V})`), l = new RegExp(`^(?:export\\s+)?(?:declare\\s+)?(?:abstract\\s+)?class\\s+(${V})`), c = new RegExp(`^(?:export\\s+)?(?:declare\\s+)?type\\s+(${V})\\s*=`);
|
|
386
|
+
for (let b = 0; b < r.length; b++) {
|
|
387
|
+
const y = r[b].trim();
|
|
388
|
+
if (!y || y.startsWith("//") || y.startsWith("/*") || y.startsWith("*")) continue;
|
|
389
|
+
const A = n.exec(y);
|
|
390
|
+
if (A && y.includes("{")) {
|
|
391
|
+
const { end: w, body: x } = We(r, b), g = A[1];
|
|
392
|
+
i.set(g, {
|
|
393
|
+
label: g,
|
|
394
|
+
type: r.slice(b, w + 1).join(`
|
|
395
|
+
`).replace(/^\s*export\s+/, "").trim(),
|
|
396
|
+
members: De(x),
|
|
397
|
+
kind: "interface"
|
|
398
|
+
}), b = w;
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
const L = l.exec(y);
|
|
402
|
+
if (L && y.includes("{")) {
|
|
403
|
+
const { end: w, body: x } = We(r, b), g = L[1];
|
|
404
|
+
i.set(g, {
|
|
405
|
+
label: g,
|
|
406
|
+
type: r.slice(b, w + 1).join(`
|
|
407
|
+
`).replace(/^\s*export\s+/, "").trim(),
|
|
408
|
+
members: De(x),
|
|
409
|
+
kind: "class"
|
|
410
|
+
}), b = w;
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
const S = c.exec(y);
|
|
414
|
+
if (S) {
|
|
415
|
+
const w = [r[b]];
|
|
416
|
+
let x = b;
|
|
417
|
+
for (; It(w.join(`
|
|
418
|
+
`)) && x + 1 < r.length; )
|
|
419
|
+
x++, w.push(r[x]);
|
|
420
|
+
const g = w.join(`
|
|
421
|
+
`).replace(/^\s*export\s+/, "").replace(/;\s*$/, "").trim();
|
|
422
|
+
i.set(S[1], {
|
|
423
|
+
label: S[1],
|
|
424
|
+
type: g,
|
|
425
|
+
members: [],
|
|
426
|
+
kind: "type"
|
|
427
|
+
}), b = x;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
const u = [], d = /* @__PURE__ */ new Set(), a = new RegExp(
|
|
431
|
+
`^(?:export\\s+)?(?:declare\\s+)?function\\s+(${V})\\s*\\(([^)]*)\\)\\s*:\\s*([^;{]+)`
|
|
432
|
+
), f = new RegExp(
|
|
433
|
+
`^(?:export\\s+)?(?:declare\\s+)?(?:const|let|var)\\s+(${V})\\s*:\\s*([^=;]+)`
|
|
434
|
+
);
|
|
435
|
+
for (const b of r) {
|
|
436
|
+
const y = b.trim();
|
|
437
|
+
if (!y || y.startsWith("//") || y.startsWith("/*") || y.startsWith("*")) continue;
|
|
438
|
+
const A = a.exec(y);
|
|
439
|
+
if (A) {
|
|
440
|
+
const S = A[1];
|
|
441
|
+
d.has(S) || (d.add(S), u.push({
|
|
442
|
+
label: S,
|
|
443
|
+
kind: "function",
|
|
444
|
+
detail: `(${A[2].trim()}) => ${A[3].trim()}`
|
|
445
|
+
}));
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
const L = f.exec(y);
|
|
449
|
+
if (L) {
|
|
450
|
+
const S = L[1];
|
|
451
|
+
if (d.has(S)) continue;
|
|
452
|
+
d.add(S);
|
|
453
|
+
const w = L[2].trim(), x = Ke(w), g = x ? i.get(x) : void 0, N = (g == null ? void 0 : g.kind) === "class" ? "class" : /^\(|=>/.test(w) ? "function" : "variable";
|
|
454
|
+
u.push({
|
|
455
|
+
label: S,
|
|
456
|
+
kind: N,
|
|
457
|
+
detail: w,
|
|
458
|
+
type: g == null ? void 0 : g.type,
|
|
459
|
+
members: g ? Ze(g.members, i, /* @__PURE__ */ new Set([g.label])) : void 0
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return u;
|
|
464
|
+
}
|
|
465
|
+
function pe(o, r, i, n) {
|
|
466
|
+
if (!i || !n) return null;
|
|
467
|
+
const l = Math.max(0, r - 1), c = o.lastIndexOf(i, l);
|
|
468
|
+
if (c === -1 || o.lastIndexOf(n, l) > c) return null;
|
|
469
|
+
const d = o.indexOf(n, c + i.length);
|
|
470
|
+
return {
|
|
471
|
+
start: c + i.length,
|
|
472
|
+
end: d === -1 ? o.length : d
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
function tn(o, r, i, n) {
|
|
476
|
+
return pe(o, r, i, n) !== null;
|
|
477
|
+
}
|
|
478
|
+
const je = /[A-Za-z_$]/, Ht = /[\w$]/, Pe = /\s/;
|
|
479
|
+
function le(o, r) {
|
|
480
|
+
const i = [], n = o.length;
|
|
481
|
+
let l = 0;
|
|
482
|
+
for (; l < n; ) {
|
|
483
|
+
const c = o[l], u = o[l + 1];
|
|
484
|
+
if (Pe.test(c)) {
|
|
485
|
+
l++;
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
if (c === "/" && u === "/") {
|
|
489
|
+
let a = o.indexOf(`
|
|
490
|
+
`, l);
|
|
491
|
+
a === -1 && (a = n), i.push({ start: l, end: a, type: "comment" }), l = a;
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
if (c === "/" && u === "*") {
|
|
495
|
+
const a = o.indexOf("*/", l + 2), f = a === -1 ? n : a + 2;
|
|
496
|
+
i.push({ start: l, end: f, type: "comment" }), l = f;
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
if (c === '"' || c === "'") {
|
|
500
|
+
let a = l + 1;
|
|
501
|
+
for (; a < n; ) {
|
|
502
|
+
if (o[a] === "\\") {
|
|
503
|
+
a += 2;
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
if (o[a] === `
|
|
507
|
+
`) break;
|
|
508
|
+
if (o[a] === c) {
|
|
509
|
+
a++;
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
a++;
|
|
513
|
+
}
|
|
514
|
+
i.push({ start: l, end: a, type: "string" }), l = a;
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (c === "`") {
|
|
518
|
+
let a = l + 1;
|
|
519
|
+
for (; a < n; ) {
|
|
520
|
+
if (o[a] === "\\") {
|
|
521
|
+
a += 2;
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (o[a] === "`") {
|
|
525
|
+
a++;
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
a++;
|
|
529
|
+
}
|
|
530
|
+
i.push({ start: l, end: a, type: "template" }), l = a;
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (/[0-9]/.test(c) || c === "." && /[0-9]/.test(u ?? "")) {
|
|
534
|
+
let a = l + 1;
|
|
535
|
+
for (; a < n && /[\w.]/.test(o[a]); ) a++;
|
|
536
|
+
i.push({ start: l, end: a, type: "number" }), l = a;
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
if (je.test(c)) {
|
|
540
|
+
let a = l + 1;
|
|
541
|
+
for (; a < n && Ht.test(o[a]); ) a++;
|
|
542
|
+
const f = o.slice(l, a), b = r.keywords.has(f) ? "keyword" : r.builtins.has(f) ? "builtin" : "identifier";
|
|
543
|
+
i.push({ start: l, end: a, type: b }), l = a;
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
let d = l + 1;
|
|
547
|
+
for (; d < n; ) {
|
|
548
|
+
const a = o[d];
|
|
549
|
+
if (Pe.test(a) || je.test(a) || /[0-9]/.test(a) || a === '"' || a === "'" || a === "`" || a === "/") break;
|
|
550
|
+
d++;
|
|
551
|
+
}
|
|
552
|
+
i.push({ start: l, end: d, type: "punctuation" }), l = d;
|
|
553
|
+
}
|
|
554
|
+
return i;
|
|
555
|
+
}
|
|
556
|
+
const At = {
|
|
557
|
+
"&": "&",
|
|
558
|
+
"<": "<",
|
|
559
|
+
">": ">"
|
|
560
|
+
};
|
|
561
|
+
function Z(o) {
|
|
562
|
+
return o.replace(/[&<>]/g, (r) => At[r] ?? r);
|
|
563
|
+
}
|
|
564
|
+
function oe(o, r, i = 0) {
|
|
565
|
+
let n = "", l = 0;
|
|
566
|
+
for (const c of r) {
|
|
567
|
+
c.start > l && (n += Z(o.slice(l, c.start)));
|
|
568
|
+
const u = Z(o.slice(c.start, c.end));
|
|
569
|
+
n += `<span class="tok-${c.type}" data-start="${c.start + i}" data-end="${c.end + i}">${u}</span>`, l = c.end;
|
|
570
|
+
}
|
|
571
|
+
return l < o.length && (n += Z(o.slice(l))), n;
|
|
572
|
+
}
|
|
573
|
+
function Lt(o, r, i, n) {
|
|
574
|
+
if (!i || !n) return oe(o, le(o, r));
|
|
575
|
+
let l = "", c = 0;
|
|
576
|
+
for (; c < o.length; ) {
|
|
577
|
+
const u = o.indexOf(i, c);
|
|
578
|
+
if (u === -1) {
|
|
579
|
+
l += Z(o.slice(c));
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
l += Z(o.slice(c, u));
|
|
583
|
+
const d = o.indexOf(n, u + i.length), a = d === -1 ? o.length : d, f = o.slice(u + i.length, a);
|
|
584
|
+
l += `<span class="tok-brace">${Z(i)}</span>`, l += oe(f, le(f, r), u + i.length), d === -1 ? c = a : (l += `<span class="tok-brace">${Z(n)}</span>`, c = d + n.length);
|
|
585
|
+
}
|
|
586
|
+
return l;
|
|
587
|
+
}
|
|
588
|
+
const Bt = {
|
|
589
|
+
key: 0,
|
|
590
|
+
class: "gutter",
|
|
591
|
+
"aria-hidden": "true"
|
|
592
|
+
}, Ot = ["innerHTML"], Nt = ["value", "readonly", "placeholder"], Wt = ["onMouseenter", "onClick"], zt = { class: "popup-label" }, Dt = {
|
|
593
|
+
key: 0,
|
|
594
|
+
class: "popup-detail"
|
|
595
|
+
}, jt = { class: "hover-head" }, Pt = { class: "hover-name" }, Ft = {
|
|
596
|
+
key: 0,
|
|
597
|
+
class: "hover-colon"
|
|
598
|
+
}, Vt = {
|
|
599
|
+
key: 0,
|
|
600
|
+
class: "hover-type"
|
|
601
|
+
}, Kt = {
|
|
602
|
+
key: 0,
|
|
603
|
+
class: "hover-doc"
|
|
604
|
+
}, Zt = {
|
|
605
|
+
key: 1,
|
|
606
|
+
class: "hover-def"
|
|
607
|
+
}, qt = ["innerHTML"], Ut = ["title", "aria-label"], Yt = {
|
|
608
|
+
key: 0,
|
|
609
|
+
viewBox: "0 0 16 16",
|
|
610
|
+
width: "14",
|
|
611
|
+
height: "14",
|
|
612
|
+
"aria-hidden": "true"
|
|
613
|
+
}, Jt = {
|
|
614
|
+
key: 1,
|
|
615
|
+
viewBox: "0 0 16 16",
|
|
616
|
+
width: "14",
|
|
617
|
+
height: "14",
|
|
618
|
+
"aria-hidden": "true"
|
|
619
|
+
}, Gt = /* @__PURE__ */ mt({
|
|
620
|
+
__name: "CodeEditor",
|
|
621
|
+
props: {
|
|
622
|
+
modelValue: {},
|
|
623
|
+
mode: { default: "code" },
|
|
624
|
+
language: { default: "javascript" },
|
|
625
|
+
completions: { default: () => [] },
|
|
626
|
+
tsTypes: { default: "" },
|
|
627
|
+
templateCompletions: { default: () => [] },
|
|
628
|
+
templateOpen: { default: "{{" },
|
|
629
|
+
templateClose: { default: "}}" },
|
|
630
|
+
placeholder: { default: "" },
|
|
631
|
+
readonly: { type: Boolean, default: !1 },
|
|
632
|
+
lineNumbers: { type: Boolean, default: !0 },
|
|
633
|
+
hover: { type: Boolean, default: !0 },
|
|
634
|
+
theme: { default: "light" },
|
|
635
|
+
collapsible: { type: Boolean, default: !1 },
|
|
636
|
+
defaultExpanded: { type: Boolean, default: !1 },
|
|
637
|
+
collapsedHeight: { default: "34px" },
|
|
638
|
+
collapseOnBlur: { type: Boolean, default: !1 },
|
|
639
|
+
minHeight: { default: "260px" }
|
|
640
|
+
},
|
|
641
|
+
emits: ["update:modelValue", "change", "expand", "collapse"],
|
|
642
|
+
setup(o, { expose: r, emit: i }) {
|
|
643
|
+
const n = o, l = i, c = {
|
|
644
|
+
variable: "变量",
|
|
645
|
+
function: "函数",
|
|
646
|
+
property: "属性",
|
|
647
|
+
class: "对象",
|
|
648
|
+
keyword: "关键字"
|
|
649
|
+
}, u = {
|
|
650
|
+
"(": ")",
|
|
651
|
+
"[": "]",
|
|
652
|
+
"{": "}",
|
|
653
|
+
'"': '"',
|
|
654
|
+
"'": "'"
|
|
655
|
+
}, d = /* @__PURE__ */ new Set([
|
|
656
|
+
"ArrowLeft",
|
|
657
|
+
"ArrowRight",
|
|
658
|
+
"ArrowUp",
|
|
659
|
+
"ArrowDown",
|
|
660
|
+
"Home",
|
|
661
|
+
"End",
|
|
662
|
+
"PageUp",
|
|
663
|
+
"PageDown"
|
|
664
|
+
]), a = $(n.modelValue), f = $(), b = $(), y = $(), A = $(), L = $(), S = $(), w = $(), x = $([]), g = $(0), N = $(!1), ie = $({ start: 0, end: 0 }), me = $({}), E = $(null), he = $({}), qe = P(
|
|
665
|
+
() => n.tsTypes ? Mt(n.tsTypes) : []
|
|
666
|
+
), be = P(() => [
|
|
667
|
+
...yt,
|
|
668
|
+
...qe.value,
|
|
669
|
+
...n.completions
|
|
670
|
+
]), ae = P(
|
|
671
|
+
() => n.mode === "template" ? [...n.templateCompletions, ...be.value] : be.value
|
|
672
|
+
), Ue = P(() => {
|
|
673
|
+
const e = {
|
|
674
|
+
keywords: Le(n.language),
|
|
675
|
+
builtins: new Set(ae.value.map((t) => t.label))
|
|
676
|
+
};
|
|
677
|
+
return n.mode === "template" ? `${Lt(a.value, e, n.templateOpen, n.templateClose)}
|
|
678
|
+
` : `${oe(a.value, le(a.value, e))}
|
|
679
|
+
`;
|
|
680
|
+
}), Ye = P(() => a.value.split(`
|
|
681
|
+
`).length), W = $(n.defaultExpanded), q = P(() => n.collapsible && !W.value), Je = P(() => q.value ? { "--ce-collapsed-height": n.collapsedHeight } : { height: n.minHeight }), Ge = P(
|
|
682
|
+
() => q.value ? { height: n.collapsedHeight } : {}
|
|
683
|
+
);
|
|
684
|
+
let ge = 0;
|
|
685
|
+
function ve(e) {
|
|
686
|
+
if (W.value === e) return;
|
|
687
|
+
const t = f.value;
|
|
688
|
+
e && t && (ge = t.scrollTop), W.value = e, l(e ? "expand" : "collapse"), _(), H(), O(() => {
|
|
689
|
+
if (se(), !W.value && t) {
|
|
690
|
+
const s = Math.max(0, t.scrollHeight - t.clientHeight);
|
|
691
|
+
t.scrollTop = Math.max(0, Math.min(ge, s)), B(!0), document.activeElement === t && Y();
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
B(!0), e && n.collapseOnBlur && t && document.activeElement !== t && t.focus();
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
function Xe() {
|
|
698
|
+
ve(!W.value);
|
|
699
|
+
}
|
|
700
|
+
Ie(
|
|
701
|
+
() => n.modelValue,
|
|
702
|
+
(e) => {
|
|
703
|
+
e !== a.value && (a.value = e, _());
|
|
704
|
+
}
|
|
705
|
+
), Ie(a, () => {
|
|
706
|
+
O(() => B(!0));
|
|
707
|
+
});
|
|
708
|
+
function ye(e) {
|
|
709
|
+
return c[e];
|
|
710
|
+
}
|
|
711
|
+
function Qe(e) {
|
|
712
|
+
return e ? oe(
|
|
713
|
+
e,
|
|
714
|
+
le(e, { keywords: Le("typescript"), builtins: /* @__PURE__ */ new Set() })
|
|
715
|
+
) : "";
|
|
716
|
+
}
|
|
717
|
+
let U = { top: 14, bottom: 14, lineHeight: 22 };
|
|
718
|
+
function se() {
|
|
719
|
+
const e = f.value;
|
|
720
|
+
if (!e) return;
|
|
721
|
+
const t = window.getComputedStyle(e);
|
|
722
|
+
U = {
|
|
723
|
+
top: parseFloat(t.paddingTop) || 0,
|
|
724
|
+
bottom: parseFloat(t.paddingBottom) || 0,
|
|
725
|
+
lineHeight: parseFloat(t.lineHeight) || 22
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
function B(e = !1) {
|
|
729
|
+
const t = f.value;
|
|
730
|
+
if (!t) return;
|
|
731
|
+
const s = A.value;
|
|
732
|
+
if (s && (s.style.transform = `translate(${-t.scrollLeft}px, ${-t.scrollTop}px)`), L.value && (L.value.style.transform = `translateY(${-t.scrollTop}px)`), e) {
|
|
733
|
+
const m = `${a.value}|${n.mode}|${t.clientWidth}|${t.clientHeight}`;
|
|
734
|
+
m !== we && (we = m, et());
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
function Y() {
|
|
738
|
+
const e = f.value;
|
|
739
|
+
if (!e || !q.value) return;
|
|
740
|
+
const t = xe();
|
|
741
|
+
if (!t) return;
|
|
742
|
+
const s = e.clientHeight - U.top - U.bottom, h = t.top + e.scrollTop - U.top - Math.max(0, (s - t.lineHeight) / 2), p = Math.max(0, e.scrollHeight - e.clientHeight), k = Math.max(0, Math.min(h, p));
|
|
743
|
+
Math.abs(k - e.scrollTop) > 0.5 && (e.scrollTop = k, B());
|
|
744
|
+
}
|
|
745
|
+
let ke = [], we = "", Q = 0, re = -1, ce = -1, ue = { x: 0, y: 0 };
|
|
746
|
+
function et() {
|
|
747
|
+
const e = f.value, t = y.value;
|
|
748
|
+
if (!e || !t) return;
|
|
749
|
+
const s = e.getBoundingClientRect(), m = [];
|
|
750
|
+
t.querySelectorAll("[data-start]").forEach((h) => {
|
|
751
|
+
const p = h.getBoundingClientRect();
|
|
752
|
+
m.push({
|
|
753
|
+
start: Number(h.dataset.start),
|
|
754
|
+
end: Number(h.dataset.end),
|
|
755
|
+
left: p.left - s.left + e.scrollLeft,
|
|
756
|
+
right: p.right - s.left + e.scrollLeft,
|
|
757
|
+
top: p.top - s.top + e.scrollTop,
|
|
758
|
+
bottom: p.bottom - s.top + e.scrollTop
|
|
759
|
+
});
|
|
760
|
+
}), ke = m;
|
|
761
|
+
}
|
|
762
|
+
function tt(e, t) {
|
|
763
|
+
for (const s of ke)
|
|
764
|
+
if (e >= s.left - 1 && e <= s.right + 1 && t >= s.top && t <= s.bottom)
|
|
765
|
+
return s;
|
|
766
|
+
return null;
|
|
767
|
+
}
|
|
768
|
+
function H() {
|
|
769
|
+
E.value = null, Q = 0, re = -1, ce = -1;
|
|
770
|
+
}
|
|
771
|
+
function nt(e) {
|
|
772
|
+
const t = w.value, s = f.value;
|
|
773
|
+
if (!t || !s) return;
|
|
774
|
+
const m = s.getBoundingClientRect(), h = m.left + e.left - s.scrollLeft, p = m.left + e.right - s.scrollLeft, k = m.top + e.top - s.scrollTop, v = m.top + e.bottom - s.scrollTop, R = 12, M = 8, D = t.offsetWidth, G = t.offsetHeight;
|
|
775
|
+
let j = h, K = v + M;
|
|
776
|
+
j + D > window.innerWidth - R && (j = p - D), K + G > window.innerHeight - R && (K = k - G - M), j = Math.max(R, Math.min(j, window.innerWidth - R - D)), K = Math.max(R, K), he.value = { left: `${j}px`, top: `${K}px` };
|
|
777
|
+
}
|
|
778
|
+
function lt(e, t) {
|
|
779
|
+
const s = f.value;
|
|
780
|
+
if (!s || n.readonly || !n.hover || N.value) {
|
|
781
|
+
H();
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
if (s.selectionStart !== s.selectionEnd) {
|
|
785
|
+
H();
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
const m = w.value;
|
|
789
|
+
if (E.value && m) {
|
|
790
|
+
const v = m.getBoundingClientRect();
|
|
791
|
+
if (e >= v.left && e <= v.right && t >= v.top && t <= v.bottom)
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
const h = s.getBoundingClientRect(), p = tt(e - h.left + s.scrollLeft, t - h.top + s.scrollTop);
|
|
795
|
+
if (!p) {
|
|
796
|
+
H();
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
if (E.value && re === p.start && ce === p.end)
|
|
800
|
+
return;
|
|
801
|
+
const k = Rt(s.value, p.start, p.end, {
|
|
802
|
+
completions: ae.value,
|
|
803
|
+
declared: Oe(s.value, p.start)
|
|
804
|
+
});
|
|
805
|
+
if (!k) {
|
|
806
|
+
H();
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
E.value = k, re = p.start, ce = p.end, O(() => nt(p));
|
|
810
|
+
}
|
|
811
|
+
function ot(e) {
|
|
812
|
+
ue = { x: e.clientX, y: e.clientY }, !Q && (Q = requestAnimationFrame(() => {
|
|
813
|
+
Q = 0, lt(ue.x, ue.y);
|
|
814
|
+
}));
|
|
815
|
+
}
|
|
816
|
+
function xe() {
|
|
817
|
+
const e = f.value;
|
|
818
|
+
if (!e) return null;
|
|
819
|
+
const t = window.getComputedStyle(e), s = document.createElement("div"), m = parseFloat(t.paddingLeft) || 0, h = parseFloat(t.paddingRight) || 0, p = e.getBoundingClientRect();
|
|
820
|
+
Object.assign(s.style, {
|
|
821
|
+
position: "fixed",
|
|
822
|
+
left: `${p.left}px`,
|
|
823
|
+
top: `${p.top}px`,
|
|
824
|
+
visibility: "hidden",
|
|
825
|
+
pointerEvents: "none",
|
|
826
|
+
zIndex: "-1",
|
|
827
|
+
whiteSpace: "pre-wrap",
|
|
828
|
+
overflowWrap: "break-word",
|
|
829
|
+
wordBreak: "normal",
|
|
830
|
+
boxSizing: "content-box",
|
|
831
|
+
width: `${e.clientWidth - m - h}px`,
|
|
832
|
+
paddingTop: t.paddingTop,
|
|
833
|
+
paddingRight: t.paddingRight,
|
|
834
|
+
paddingBottom: t.paddingBottom,
|
|
835
|
+
paddingLeft: t.paddingLeft,
|
|
836
|
+
border: "0",
|
|
837
|
+
fontFamily: t.fontFamily,
|
|
838
|
+
fontSize: t.fontSize,
|
|
839
|
+
fontWeight: t.fontWeight,
|
|
840
|
+
fontStyle: t.fontStyle,
|
|
841
|
+
fontVariant: t.fontVariant,
|
|
842
|
+
letterSpacing: t.letterSpacing,
|
|
843
|
+
lineHeight: t.lineHeight,
|
|
844
|
+
textTransform: t.textTransform,
|
|
845
|
+
tabSize: t.tabSize
|
|
846
|
+
}), s.textContent = e.value.slice(0, e.selectionStart);
|
|
847
|
+
const k = document.createElement("span");
|
|
848
|
+
k.textContent = "", s.appendChild(k), document.body.appendChild(s);
|
|
849
|
+
const v = k.getBoundingClientRect();
|
|
850
|
+
document.body.removeChild(s);
|
|
851
|
+
const R = parseFloat(t.lineHeight) || 22, M = v.height, D = M > 0 && M < R ? (R - M) / 2 : 0;
|
|
852
|
+
return {
|
|
853
|
+
left: v.left - p.left - e.scrollLeft,
|
|
854
|
+
top: v.top - p.top - e.scrollTop - D,
|
|
855
|
+
lineHeight: R
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
async function it() {
|
|
859
|
+
await O();
|
|
860
|
+
const e = b.value, t = S.value, s = xe();
|
|
861
|
+
if (!e || !t || !s) return;
|
|
862
|
+
const m = 4, h = 8, p = window.innerWidth, k = window.innerHeight, v = e.getBoundingClientRect(), R = t.scrollHeight, M = k - (v.top + s.top + s.lineHeight) - m - h, D = v.top + s.top - m - h, G = M >= Math.min(R, 180) || M >= D, j = Math.min(248, Math.max(G ? M : D, 96)), K = Math.min(R, j), Re = t.offsetWidth || 280;
|
|
863
|
+
let X = s.left;
|
|
864
|
+
v.left + X + Re > p - h && (X = p - h - Re - v.left), X = Math.max(X, h - v.left), me.value = {
|
|
865
|
+
left: `${X}px`,
|
|
866
|
+
top: `${G ? s.top + s.lineHeight + m : s.top - m - K}px`,
|
|
867
|
+
maxHeight: `${j}px`
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
function _() {
|
|
871
|
+
N.value = !1, x.value = [], g.value = 0, H();
|
|
872
|
+
}
|
|
873
|
+
function J(e = !1) {
|
|
874
|
+
const t = f.value;
|
|
875
|
+
if (!t || n.readonly) return;
|
|
876
|
+
if (t.selectionStart !== t.selectionEnd) {
|
|
877
|
+
_();
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
const s = t.selectionStart;
|
|
881
|
+
let m = !e;
|
|
882
|
+
if (n.mode === "template") {
|
|
883
|
+
const p = pe(
|
|
884
|
+
t.value,
|
|
885
|
+
s,
|
|
886
|
+
n.templateOpen,
|
|
887
|
+
n.templateClose
|
|
888
|
+
);
|
|
889
|
+
if (!p) {
|
|
890
|
+
_();
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
e && t.value.slice(p.start, s).trim() === "" && (m = !0);
|
|
894
|
+
}
|
|
895
|
+
const h = Et(t.value, s, {
|
|
896
|
+
language: n.language,
|
|
897
|
+
completions: ae.value,
|
|
898
|
+
declared: Oe(t.value, s),
|
|
899
|
+
auto: !m
|
|
900
|
+
});
|
|
901
|
+
if (!h) {
|
|
902
|
+
_();
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
x.value = h.items, ie.value = { start: h.start, end: h.end }, g.value = 0, N.value = !0, it();
|
|
906
|
+
}
|
|
907
|
+
function at(e) {
|
|
908
|
+
a.value = e, l("update:modelValue", e), l("change", e);
|
|
909
|
+
}
|
|
910
|
+
function ee(e, t, s, m = e + s.length) {
|
|
911
|
+
const h = f.value;
|
|
912
|
+
if (!h) return;
|
|
913
|
+
const p = h.value.slice(0, e) + s + h.value.slice(t);
|
|
914
|
+
at(p), _(), O(() => {
|
|
915
|
+
h.value = p, h.setSelectionRange(m, m), h.focus(), B(!0), Y();
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
function $e(e = x.value[g.value]) {
|
|
919
|
+
if (!e) return;
|
|
920
|
+
const t = e.insertText ?? e.label;
|
|
921
|
+
ee(ie.value.start, ie.value.end, t), _();
|
|
922
|
+
}
|
|
923
|
+
function Te(e) {
|
|
924
|
+
const t = x.value.length;
|
|
925
|
+
t && (g.value = (g.value + e + t) % t, O(() => {
|
|
926
|
+
var s, m;
|
|
927
|
+
(m = (s = S.value) == null ? void 0 : s.querySelector(".is-active")) == null || m.scrollIntoView({ block: "nearest" });
|
|
928
|
+
}));
|
|
929
|
+
}
|
|
930
|
+
function st(e) {
|
|
931
|
+
const t = e.target;
|
|
932
|
+
a.value = t.value, l("update:modelValue", t.value), l("change", t.value), H(), B(), O(Y), J(!0);
|
|
933
|
+
}
|
|
934
|
+
function rt(e) {
|
|
935
|
+
if (_(), H(), !n.collapsible || !n.collapseOnBlur || !W.value) return;
|
|
936
|
+
const t = e.relatedTarget;
|
|
937
|
+
t && t.closest(".expand-toggle") || ve(!1);
|
|
938
|
+
}
|
|
939
|
+
function ct() {
|
|
940
|
+
Ce(), Y();
|
|
941
|
+
}
|
|
942
|
+
function Ce() {
|
|
943
|
+
const e = f.value;
|
|
944
|
+
if (!e || n.readonly) return;
|
|
945
|
+
if (e.selectionStart !== e.selectionEnd) {
|
|
946
|
+
_();
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
const t = e.selectionStart;
|
|
950
|
+
if (t > 0 && e.value[t - 1] === ".") {
|
|
951
|
+
J(!0);
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
if (n.mode === "template") {
|
|
955
|
+
const s = pe(
|
|
956
|
+
e.value,
|
|
957
|
+
t,
|
|
958
|
+
n.templateOpen,
|
|
959
|
+
n.templateClose
|
|
960
|
+
);
|
|
961
|
+
if (s && e.value.slice(s.start, t).trim() === "") {
|
|
962
|
+
J(!0);
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
_();
|
|
967
|
+
}
|
|
968
|
+
let de = 0;
|
|
969
|
+
function Se() {
|
|
970
|
+
window.clearTimeout(de), de = window.setTimeout(() => {
|
|
971
|
+
de = 0, Ce(), Y();
|
|
972
|
+
}, 0);
|
|
973
|
+
}
|
|
974
|
+
function Ee(e) {
|
|
975
|
+
e.target !== f.value && N.value && _();
|
|
976
|
+
}
|
|
977
|
+
function ut() {
|
|
978
|
+
H(), B(), q.value && dt();
|
|
979
|
+
}
|
|
980
|
+
let fe = 0;
|
|
981
|
+
function dt() {
|
|
982
|
+
window.clearTimeout(fe), fe = window.setTimeout(() => {
|
|
983
|
+
fe = 0, ft();
|
|
984
|
+
}, 120);
|
|
985
|
+
}
|
|
986
|
+
function ft() {
|
|
987
|
+
const e = f.value;
|
|
988
|
+
if (!e) return;
|
|
989
|
+
const t = U.lineHeight, s = e.scrollTop, m = Math.round(s / t) * t;
|
|
990
|
+
Math.abs(m - s) < 0.5 || (e.scrollTop = m, B());
|
|
991
|
+
}
|
|
992
|
+
function pt(e) {
|
|
993
|
+
var h;
|
|
994
|
+
const t = f.value;
|
|
995
|
+
if (!t) return;
|
|
996
|
+
const s = e.metaKey || e.ctrlKey, m = d.has(e.key);
|
|
997
|
+
if (e.key === " " && s) {
|
|
998
|
+
e.preventDefault(), J(!1);
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
if (N.value) {
|
|
1002
|
+
if (e.key === "ArrowDown") {
|
|
1003
|
+
e.preventDefault(), Te(1);
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
if (e.key === "ArrowUp") {
|
|
1007
|
+
e.preventDefault(), Te(-1);
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
if (e.key === "Enter" || e.key === "Tab") {
|
|
1011
|
+
e.preventDefault(), $e();
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if (e.key === "Escape") {
|
|
1015
|
+
e.preventDefault(), _();
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
if (m || s) {
|
|
1019
|
+
_(), m && !s && Se();
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
if (m && !s) {
|
|
1024
|
+
Se();
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
if (e.key === "Enter" && !s && !e.shiftKey) {
|
|
1028
|
+
const p = t.selectionStart;
|
|
1029
|
+
if (p !== t.selectionEnd) return;
|
|
1030
|
+
const k = t.value.lastIndexOf(`
|
|
1031
|
+
`, p - 1) + 1, v = t.value.slice(k, p), R = ((h = v.match(/^[ \t]*/)) == null ? void 0 : h[0]) ?? "", M = /[{[(]$/.test(v.trimEnd()) ? " " : "";
|
|
1032
|
+
e.preventDefault(), ee(p, p, `
|
|
1033
|
+
${R}${M}`);
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
if (e.key === "Tab") {
|
|
1037
|
+
e.preventDefault(), ee(t.selectionStart, t.selectionEnd, " ");
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
if (e.key.length === 1 && !s && !e.altKey && u[e.key]) {
|
|
1041
|
+
if (t.selectionStart !== t.selectionEnd) return;
|
|
1042
|
+
const p = t.selectionStart, k = t.value[p - 1], v = t.value[p];
|
|
1043
|
+
if ((e.key === '"' || e.key === "'") && k && /[\w$]/.test(k) || v !== void 0 && !/[\s)\]},;:]/.test(v)) return;
|
|
1044
|
+
e.preventDefault(), ee(p, p, e.key + u[e.key], p + 1), n.mode === "template" && O(() => J(!0));
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
function _e() {
|
|
1048
|
+
N.value && _(), H(), O(() => {
|
|
1049
|
+
se(), B(!0);
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
return ht(() => {
|
|
1053
|
+
window.addEventListener("resize", _e), window.addEventListener("scroll", Ee, !0), O(() => {
|
|
1054
|
+
se(), B(!0);
|
|
1055
|
+
});
|
|
1056
|
+
}), bt(() => {
|
|
1057
|
+
window.removeEventListener("resize", _e), window.removeEventListener("scroll", Ee, !0);
|
|
1058
|
+
}), r({ focus: () => {
|
|
1059
|
+
var e;
|
|
1060
|
+
return (e = f.value) == null ? void 0 : e.focus();
|
|
1061
|
+
} }), (e, t) => (T(), C("div", {
|
|
1062
|
+
class: ne(["code-editor", {
|
|
1063
|
+
"is-readonly": o.readonly,
|
|
1064
|
+
"is-dark": o.theme === "dark",
|
|
1065
|
+
"is-collapsed": q.value
|
|
1066
|
+
}]),
|
|
1067
|
+
style: te(Je.value)
|
|
1068
|
+
}, [
|
|
1069
|
+
o.lineNumbers && !q.value ? (T(), C("div", Bt, [
|
|
1070
|
+
I("div", {
|
|
1071
|
+
ref_key: "gutterInner",
|
|
1072
|
+
ref: L,
|
|
1073
|
+
class: "gutter-inner code-font"
|
|
1074
|
+
}, [
|
|
1075
|
+
(T(!0), C(Me, null, He(Ye.value, (s) => (T(), C("div", {
|
|
1076
|
+
key: s,
|
|
1077
|
+
class: "gutter-line"
|
|
1078
|
+
}, F(s), 1))), 128))
|
|
1079
|
+
], 512)
|
|
1080
|
+
])) : z("", !0),
|
|
1081
|
+
I("div", {
|
|
1082
|
+
ref_key: "stage",
|
|
1083
|
+
ref: b,
|
|
1084
|
+
class: "stage",
|
|
1085
|
+
style: te(Ge.value)
|
|
1086
|
+
}, [
|
|
1087
|
+
I("div", {
|
|
1088
|
+
ref_key: "highlightLayer",
|
|
1089
|
+
ref: y,
|
|
1090
|
+
class: "highlight code-font"
|
|
1091
|
+
}, [
|
|
1092
|
+
I("pre", {
|
|
1093
|
+
ref_key: "highlightInner",
|
|
1094
|
+
ref: A,
|
|
1095
|
+
class: "code-font"
|
|
1096
|
+
}, [
|
|
1097
|
+
I("code", { innerHTML: Ue.value }, null, 8, Ot)
|
|
1098
|
+
], 512)
|
|
1099
|
+
], 512),
|
|
1100
|
+
I("textarea", {
|
|
1101
|
+
ref_key: "textarea",
|
|
1102
|
+
ref: f,
|
|
1103
|
+
class: "code-font input",
|
|
1104
|
+
value: a.value,
|
|
1105
|
+
readonly: o.readonly,
|
|
1106
|
+
placeholder: o.placeholder,
|
|
1107
|
+
spellcheck: "false",
|
|
1108
|
+
autocomplete: "off",
|
|
1109
|
+
autocapitalize: "off",
|
|
1110
|
+
autocorrect: "off",
|
|
1111
|
+
wrap: "soft",
|
|
1112
|
+
onInput: st,
|
|
1113
|
+
onKeydown: pt,
|
|
1114
|
+
onScroll: ut,
|
|
1115
|
+
onClick: ct,
|
|
1116
|
+
onMousemove: ot,
|
|
1117
|
+
onMouseleave: H,
|
|
1118
|
+
onBlur: rt
|
|
1119
|
+
}, null, 40, Nt),
|
|
1120
|
+
N.value ? (T(), C("ul", {
|
|
1121
|
+
key: 0,
|
|
1122
|
+
ref_key: "popup",
|
|
1123
|
+
ref: S,
|
|
1124
|
+
class: "popup",
|
|
1125
|
+
style: te(me.value),
|
|
1126
|
+
onMousedown: t[0] || (t[0] = gt(() => {
|
|
1127
|
+
}, ["prevent"]))
|
|
1128
|
+
}, [
|
|
1129
|
+
(T(!0), C(Me, null, He(x.value, (s, m) => (T(), C("li", {
|
|
1130
|
+
key: `${s.label}-${m}`,
|
|
1131
|
+
class: ne(["popup-item", { "is-active": m === g.value }]),
|
|
1132
|
+
onMouseenter: (h) => g.value = m,
|
|
1133
|
+
onClick: (h) => $e(s)
|
|
1134
|
+
}, [
|
|
1135
|
+
I("span", {
|
|
1136
|
+
class: ne(["badge", `badge-${s.kind}`])
|
|
1137
|
+
}, F(ye(s.kind)), 3),
|
|
1138
|
+
I("span", zt, F(s.label), 1),
|
|
1139
|
+
s.detail ? (T(), C("span", Dt, F(s.detail), 1)) : z("", !0)
|
|
1140
|
+
], 42, Wt))), 128))
|
|
1141
|
+
], 36)) : z("", !0),
|
|
1142
|
+
E.value ? (T(), C("div", {
|
|
1143
|
+
key: 1,
|
|
1144
|
+
ref_key: "hoverCard",
|
|
1145
|
+
ref: w,
|
|
1146
|
+
class: "hover-card",
|
|
1147
|
+
style: te(he.value)
|
|
1148
|
+
}, [
|
|
1149
|
+
I("div", jt, [
|
|
1150
|
+
I("span", {
|
|
1151
|
+
class: ne(["badge", `badge-${E.value.kind}`])
|
|
1152
|
+
}, F(ye(E.value.kind)), 3),
|
|
1153
|
+
I("span", Pt, [
|
|
1154
|
+
vt(F(E.value.label), 1),
|
|
1155
|
+
E.value.detail ? (T(), C("span", Ft, ":")) : z("", !0)
|
|
1156
|
+
]),
|
|
1157
|
+
E.value.detail ? (T(), C("span", Vt, F(E.value.detail), 1)) : z("", !0)
|
|
1158
|
+
]),
|
|
1159
|
+
E.value.documentation ? (T(), C("p", Kt, F(E.value.documentation), 1)) : z("", !0),
|
|
1160
|
+
E.value.type ? (T(), C("pre", Zt, [
|
|
1161
|
+
I("code", {
|
|
1162
|
+
innerHTML: Qe(E.value.type)
|
|
1163
|
+
}, null, 8, qt)
|
|
1164
|
+
])) : z("", !0)
|
|
1165
|
+
], 4)) : z("", !0)
|
|
1166
|
+
], 4),
|
|
1167
|
+
o.collapsible ? (T(), C("button", {
|
|
1168
|
+
key: 1,
|
|
1169
|
+
type: "button",
|
|
1170
|
+
class: "expand-toggle",
|
|
1171
|
+
title: W.value ? "收起" : "展开",
|
|
1172
|
+
"aria-label": W.value ? "收起编辑器" : "展开编辑器",
|
|
1173
|
+
onClick: Xe
|
|
1174
|
+
}, [
|
|
1175
|
+
W.value ? (T(), C("svg", Jt, [...t[2] || (t[2] = [
|
|
1176
|
+
I("path", {
|
|
1177
|
+
d: "M11 2 5 8 11 14",
|
|
1178
|
+
fill: "none",
|
|
1179
|
+
stroke: "currentColor",
|
|
1180
|
+
"stroke-width": "1.6",
|
|
1181
|
+
"stroke-linecap": "round",
|
|
1182
|
+
"stroke-linejoin": "round"
|
|
1183
|
+
}, null, -1)
|
|
1184
|
+
])])) : (T(), C("svg", Yt, [...t[1] || (t[1] = [
|
|
1185
|
+
I("path", {
|
|
1186
|
+
d: "M6 2 12 8 6 14",
|
|
1187
|
+
fill: "none",
|
|
1188
|
+
stroke: "currentColor",
|
|
1189
|
+
"stroke-width": "1.6",
|
|
1190
|
+
"stroke-linecap": "round",
|
|
1191
|
+
"stroke-linejoin": "round"
|
|
1192
|
+
}, null, -1)
|
|
1193
|
+
])]))
|
|
1194
|
+
], 8, Ut)) : z("", !0)
|
|
1195
|
+
], 6));
|
|
1196
|
+
}
|
|
1197
|
+
}), Xt = (o, r) => {
|
|
1198
|
+
const i = o.__vccOpts || o;
|
|
1199
|
+
for (const [n, l] of r)
|
|
1200
|
+
i[n] = l;
|
|
1201
|
+
return i;
|
|
1202
|
+
}, Qt = /* @__PURE__ */ Xt(Gt, [["__scopeId", "data-v-dc3651c9"]]), nn = {
|
|
1203
|
+
install(o) {
|
|
1204
|
+
o.component("CodeInput", Qt);
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
export {
|
|
1208
|
+
Qt as CodeEditor,
|
|
1209
|
+
Et as collectCompletions,
|
|
1210
|
+
nn as default,
|
|
1211
|
+
yt as defaultCompletions,
|
|
1212
|
+
pe as findTemplateRange,
|
|
1213
|
+
Le as getKeywordSet,
|
|
1214
|
+
Fe as getKeywords,
|
|
1215
|
+
oe as highlight,
|
|
1216
|
+
Lt as highlightTemplate,
|
|
1217
|
+
tn as isInsideTemplate,
|
|
1218
|
+
Mt as parseTsCompletions,
|
|
1219
|
+
Rt as resolveHoverItem,
|
|
1220
|
+
Oe as scanDeclarations,
|
|
1221
|
+
le as tokenize
|
|
1222
|
+
};
|