@synclineapi/editor 2.0.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,4466 @@
1
+ var De = Object.defineProperty;
2
+ var He = (s, e, t) => e in s ? De(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var u = (s, e, t) => He(s, typeof e != "symbol" ? e + "" : e, t);
4
+ const Re = {
5
+ typescript: "//",
6
+ javascript: "//",
7
+ css: "//",
8
+ json: "",
9
+ markdown: "",
10
+ text: ""
11
+ }, se = /* @__PURE__ */ new Set([
12
+ "function",
13
+ "const",
14
+ "let",
15
+ "var",
16
+ "return",
17
+ "if",
18
+ "else",
19
+ "for",
20
+ "while",
21
+ "class",
22
+ "import",
23
+ "export",
24
+ "default",
25
+ "async",
26
+ "await",
27
+ "new",
28
+ "this",
29
+ "typeof",
30
+ "instanceof",
31
+ "try",
32
+ "catch",
33
+ "finally",
34
+ "throw",
35
+ "extends",
36
+ "interface",
37
+ "type",
38
+ "readonly",
39
+ "private",
40
+ "public",
41
+ "protected",
42
+ "static",
43
+ "override",
44
+ "implements",
45
+ "enum",
46
+ "namespace",
47
+ "declare",
48
+ "abstract",
49
+ "as",
50
+ "from",
51
+ "of",
52
+ "in",
53
+ "void",
54
+ "switch",
55
+ "case",
56
+ "break",
57
+ "continue",
58
+ "do",
59
+ "delete",
60
+ "yield",
61
+ "super",
62
+ "null",
63
+ "true",
64
+ "false",
65
+ "undefined",
66
+ "require",
67
+ "constructor"
68
+ ]), Be = /* @__PURE__ */ new Set([
69
+ "function",
70
+ "const",
71
+ "let",
72
+ "var",
73
+ "return",
74
+ "if",
75
+ "else",
76
+ "for",
77
+ "while",
78
+ "class",
79
+ "import",
80
+ "export",
81
+ "default",
82
+ "async",
83
+ "await",
84
+ "new",
85
+ "this",
86
+ "typeof",
87
+ "instanceof",
88
+ "try",
89
+ "catch",
90
+ "finally",
91
+ "throw",
92
+ "extends",
93
+ "as",
94
+ "from",
95
+ "of",
96
+ "in",
97
+ "void",
98
+ "switch",
99
+ "case",
100
+ "break",
101
+ "continue",
102
+ "do",
103
+ "delete",
104
+ "yield",
105
+ "super",
106
+ "null",
107
+ "true",
108
+ "false",
109
+ "undefined",
110
+ "require",
111
+ "constructor",
112
+ "static"
113
+ ]), je = /* @__PURE__ */ new Set([
114
+ // At-rules (without @)
115
+ "media",
116
+ "keyframes",
117
+ "import",
118
+ "charset",
119
+ "supports",
120
+ "layer",
121
+ "container",
122
+ "namespace",
123
+ "page",
124
+ // Position values
125
+ "static",
126
+ "relative",
127
+ "absolute",
128
+ "fixed",
129
+ "sticky",
130
+ // Display values
131
+ "block",
132
+ "inline",
133
+ "flex",
134
+ "grid",
135
+ "none",
136
+ "contents",
137
+ "table",
138
+ // Overflow / visibility
139
+ "hidden",
140
+ "visible",
141
+ "scroll",
142
+ "clip",
143
+ "auto",
144
+ // Text / font values
145
+ "bold",
146
+ "normal",
147
+ "italic",
148
+ "underline",
149
+ "uppercase",
150
+ "lowercase",
151
+ "capitalize",
152
+ "left",
153
+ "right",
154
+ "center",
155
+ "justify",
156
+ // Sizing keywords
157
+ "inherit",
158
+ "initial",
159
+ "unset",
160
+ "revert",
161
+ // Misc values
162
+ "pointer",
163
+ "default",
164
+ "transparent",
165
+ "solid",
166
+ "dashed",
167
+ "dotted",
168
+ "double",
169
+ "cover",
170
+ "contain",
171
+ "no-repeat",
172
+ "repeat",
173
+ // CSS functions (used as values)
174
+ "var",
175
+ "calc",
176
+ "min",
177
+ "max",
178
+ "clamp"
179
+ ]), Pe = /* @__PURE__ */ new Set(["null", "true", "false"]), he = /* @__PURE__ */ new Set(), ae = /* @__PURE__ */ new Set([
180
+ "number",
181
+ "string",
182
+ "boolean",
183
+ "any",
184
+ "never",
185
+ "unknown",
186
+ "object",
187
+ "Promise",
188
+ "Array",
189
+ "Map",
190
+ "Set",
191
+ "Record",
192
+ "Partial",
193
+ "Required",
194
+ "Readonly",
195
+ "HTMLElement",
196
+ "KeyboardEvent",
197
+ "Float64Array",
198
+ "EventListener",
199
+ "Document",
200
+ "Window",
201
+ "Node",
202
+ "Element",
203
+ "Event",
204
+ "MouseEvent",
205
+ "CustomEvent"
206
+ ]), $e = /* @__PURE__ */ new Set([
207
+ "number",
208
+ "string",
209
+ "boolean",
210
+ "object",
211
+ "Promise",
212
+ "Array",
213
+ "Map",
214
+ "Set",
215
+ "HTMLElement",
216
+ "KeyboardEvent",
217
+ "Float64Array",
218
+ "EventListener",
219
+ "Document",
220
+ "Window",
221
+ "Node",
222
+ "Element",
223
+ "Event",
224
+ "MouseEvent",
225
+ "CustomEvent"
226
+ ]), We = /* @__PURE__ */ new Set(), Ne = /* @__PURE__ */ new Set(), pe = /* @__PURE__ */ new Set(), Ee = {
227
+ typescript: se,
228
+ javascript: Be,
229
+ css: je,
230
+ json: Pe,
231
+ markdown: he,
232
+ text: he
233
+ }, Se = {
234
+ typescript: ae,
235
+ javascript: $e,
236
+ css: We,
237
+ json: Ne,
238
+ markdown: pe,
239
+ text: pe
240
+ };
241
+ function ue(s, e) {
242
+ return {
243
+ fileId: s,
244
+ doc: [...e],
245
+ cur: { row: 0, col: 0 },
246
+ sel: null,
247
+ dirty: !1,
248
+ undoStack: [],
249
+ redoStack: [],
250
+ scrollTop: 0
251
+ };
252
+ }
253
+ function E(s, e = 300) {
254
+ const t = {
255
+ doc: [...s.doc],
256
+ cur: { ...s.cur },
257
+ sel: s.sel ? { ...s.sel } : null
258
+ };
259
+ s.undoStack.push(t), s.undoStack.length > e && s.undoStack.shift(), s.redoStack = [], s.dirty = !0;
260
+ }
261
+ function Oe(s) {
262
+ if (!s.undoStack.length) return !1;
263
+ const e = {
264
+ doc: [...s.doc],
265
+ cur: { ...s.cur },
266
+ sel: s.sel ? { ...s.sel } : null
267
+ };
268
+ s.redoStack.push(e);
269
+ const t = s.undoStack.pop();
270
+ return s.doc = t.doc, s.cur = t.cur, s.sel = t.sel, !0;
271
+ }
272
+ function Fe(s) {
273
+ if (!s.redoStack.length) return !1;
274
+ const e = {
275
+ doc: [...s.doc],
276
+ cur: { ...s.cur },
277
+ sel: s.sel ? { ...s.sel } : null
278
+ };
279
+ s.undoStack.push(e);
280
+ const t = s.redoStack.pop();
281
+ return s.doc = t.doc, s.cur = t.cur, s.sel = t.sel, !0;
282
+ }
283
+ function A(s) {
284
+ const { doc: e, cur: t } = s;
285
+ t.row = Math.max(0, Math.min(e.length - 1, t.row)), t.col = Math.max(0, Math.min((e[t.row] ?? "").length, t.col));
286
+ }
287
+ function P(s) {
288
+ const { ar: e, ac: t, fr: i, fc: r } = s;
289
+ return e < i || e === i && t <= r ? s : { ar: i, ac: r, fr: e, fc: t };
290
+ }
291
+ function fe(s, e, t) {
292
+ if (!s) return null;
293
+ const i = P(s);
294
+ return e < i.ar || e > i.fr ? null : {
295
+ start: e === i.ar ? i.ac : 0,
296
+ end: e === i.fr ? i.fc : t
297
+ };
298
+ }
299
+ function Ue(s) {
300
+ if (!s.sel) return 0;
301
+ const e = P(s.sel);
302
+ let t = 0;
303
+ for (let i = e.ar; i <= e.fr; i++) {
304
+ const r = s.doc[i] ?? "", n = i === e.ar ? e.ac : 0, a = i === e.fr ? e.fc : r.length;
305
+ t += a - n;
306
+ }
307
+ return t;
308
+ }
309
+ function ge(s) {
310
+ if (!s.sel) return "";
311
+ const e = P(s.sel), t = [];
312
+ for (let i = e.ar; i <= e.fr; i++) {
313
+ const r = s.doc[i] ?? "";
314
+ t.push(r.slice(i === e.ar ? e.ac : 0, i === e.fr ? e.fc : r.length));
315
+ }
316
+ return t.join(`
317
+ `);
318
+ }
319
+ function O(s) {
320
+ const e = s.sel;
321
+ if (!e) return s.cur;
322
+ const t = P(e), i = (s.doc[t.ar] ?? "").slice(0, t.ac), r = (s.doc[t.fr] ?? "").slice(t.fc);
323
+ return s.doc.splice(t.ar, t.fr - t.ar + 1, i + r), s.sel = null, { row: t.ar, col: t.ac };
324
+ }
325
+ function ze(s, e, t) {
326
+ if (!t || s.length <= e) return [s];
327
+ const i = [];
328
+ let r = 0;
329
+ for (; r < s.length; ) {
330
+ if (s.length - r <= e) {
331
+ i.push(s.slice(r));
332
+ break;
333
+ }
334
+ const n = r + e;
335
+ let a = -1;
336
+ for (let l = n; l > r; l--)
337
+ if (s[l - 1] === " ") {
338
+ a = l;
339
+ break;
340
+ }
341
+ a === -1 ? (i.push(s.slice(r, n)), r = n) : (i.push(s.slice(r, a)), r = a);
342
+ }
343
+ return i;
344
+ }
345
+ function Ge(s, e, t, i) {
346
+ const r = [], n = [], a = [];
347
+ let l = -1;
348
+ for (let o = 0; o < s.length; o++) {
349
+ if (o > 0 && o <= l) {
350
+ a.push(n.length), r.push([s[o] ?? ""]);
351
+ continue;
352
+ }
353
+ a.push(n.length);
354
+ const c = ze(s[o] ?? "", e, t);
355
+ r.push(c), c.forEach((d, p) => n.push({ docLine: o, segIdx: p, text: d })), i.has(o) && (l = i.get(o));
356
+ }
357
+ return { segments: r, visualRows: n, docToVisArr: a };
358
+ }
359
+ function F(s, e, t) {
360
+ const i = s.segments[e] ?? [""];
361
+ let r = t;
362
+ for (let n = 0; n < i.length; n++) {
363
+ if (r <= i[n].length || n === i.length - 1)
364
+ return {
365
+ visRow: s.docToVisArr[e] + n,
366
+ colInSeg: Math.min(r, i[n].length)
367
+ };
368
+ r -= i[n].length;
369
+ }
370
+ return { visRow: s.docToVisArr[e] ?? 0, colInSeg: 0 };
371
+ }
372
+ function Y(s, e, t) {
373
+ var a;
374
+ const i = s.visualRows[e];
375
+ if (!i) return { row: 0, col: 0 };
376
+ const r = s.segments[i.docLine] ?? [""];
377
+ let n = Math.min(t, ((a = r[i.segIdx]) == null ? void 0 : a.length) ?? 0);
378
+ for (let l = 0; l < i.segIdx; l++) n += r[l].length;
379
+ return { row: i.docLine, col: n };
380
+ }
381
+ function oe(s, e = {}) {
382
+ var d, p;
383
+ const t = [], i = s.length;
384
+ let r = 0;
385
+ const n = (h, g, y) => {
386
+ y > g && t.push({ cls: h, start: g, end: y });
387
+ }, a = Ee[e.language ?? "typescript"] ?? se, l = Se[e.language ?? "typescript"] ?? ae, o = (d = e.extraKeywords) != null && d.size ? /* @__PURE__ */ new Set([...a, ...e.extraKeywords]) : a, c = (p = e.extraTypes) != null && p.size ? /* @__PURE__ */ new Set([...l, ...e.extraTypes]) : l;
388
+ for (; r < i; ) {
389
+ if (s[r] === "/" && s[r + 1] === "/") {
390
+ n("cmt", r, i);
391
+ break;
392
+ }
393
+ if (s[r] === "*" || s[r] === "/" && s[r + 1] === "*") {
394
+ n("cmt", r, i);
395
+ break;
396
+ }
397
+ if (s[r] === "@") {
398
+ let h = r + 1;
399
+ for (; h < i && /\w/.test(s[h]); ) h++;
400
+ n("dec", r, h), r = h;
401
+ continue;
402
+ }
403
+ if (s[r] === '"' || s[r] === "'" || s[r] === "`") {
404
+ const h = s[r];
405
+ let g = r + 1;
406
+ for (; g < i; ) {
407
+ if (s[g] === "\\") {
408
+ g += 2;
409
+ continue;
410
+ }
411
+ if (s[g] === h) {
412
+ g++;
413
+ break;
414
+ }
415
+ g++;
416
+ }
417
+ n("str", r, g), r = g;
418
+ continue;
419
+ }
420
+ if (/\d/.test(s[r]) && (r === 0 || !/\w/.test(s[r - 1]))) {
421
+ let h = r;
422
+ for (; h < i && /[\d._xXa-fA-F]/.test(s[h]); ) h++;
423
+ n("num", r, h), r = h;
424
+ continue;
425
+ }
426
+ if (/[a-zA-Z_$]/.test(s[r])) {
427
+ let h = r;
428
+ for (; h < i && /[\w$]/.test(s[h]); ) h++;
429
+ const g = s.slice(r, h);
430
+ o.has(g) ? n("kw", r, h) : c.has(g) ? n("typ", r, h) : h < i && s[h] === "(" ? n("fn", r, h) : /^[A-Z]/.test(g) && n("cls", r, h), r = h;
431
+ continue;
432
+ }
433
+ if (/[=<>!&|+\-*/%^~?:,;.[\]{}()]/.test(s[r])) {
434
+ n("op", r, r + 1), r++;
435
+ continue;
436
+ }
437
+ r++;
438
+ }
439
+ return t;
440
+ }
441
+ function Ie(s, e) {
442
+ const t = new Array(s.length).fill("");
443
+ for (const i of e)
444
+ for (let r = i.start; r < i.end; r++) t[r] = i.cls;
445
+ return t;
446
+ }
447
+ class Ke {
448
+ constructor(e = 5e3) {
449
+ u(this, "_cache", /* @__PURE__ */ new Map());
450
+ u(this, "_maxSize");
451
+ // ── Performance counters ──────────────────────────────────
452
+ u(this, "_hits", 0);
453
+ u(this, "_misses", 0);
454
+ u(this, "_evictions", 0);
455
+ this._maxSize = e;
456
+ }
457
+ /** Live snapshot of cache performance. Useful for observability. */
458
+ get metrics() {
459
+ return {
460
+ hits: this._hits,
461
+ misses: this._misses,
462
+ evictions: this._evictions,
463
+ size: this._cache.size
464
+ };
465
+ }
466
+ get(e, t) {
467
+ const i = this._cache.get(e);
468
+ return i && i.src === t ? (this._hits++, i.segs) : (this._misses++, null);
469
+ }
470
+ set(e, t, i) {
471
+ this._cache.size >= this._maxSize && (this._cache.delete(this._cache.keys().next().value), this._evictions++), this._cache.set(e, { src: t, segs: i });
472
+ }
473
+ invalidateLine(e, t) {
474
+ for (let i = 0; i < t; i++)
475
+ this._cache.delete(`${e}:${i}`);
476
+ }
477
+ /** Clear all cached entries and reset performance counters. */
478
+ clear() {
479
+ this._cache.clear(), this._hits = 0, this._misses = 0, this._evictions = 0;
480
+ }
481
+ /** Reset performance counters without clearing cached entries. */
482
+ resetMetrics() {
483
+ this._hits = 0, this._misses = 0, this._evictions = 0;
484
+ }
485
+ }
486
+ const qe = {
487
+ id: "",
488
+ name: "VR Dark",
489
+ description: "Default deep dark theme",
490
+ light: !1,
491
+ tokens: {
492
+ bg0: "#0d0d0f",
493
+ bg1: "#111115",
494
+ bg2: "#16161b",
495
+ bg3: "#1d1d24",
496
+ bg4: "#24242d",
497
+ border: "rgba(255,255,255,.07)",
498
+ border2: "rgba(255,255,255,.12)",
499
+ border3: "rgba(255,255,255,.19)",
500
+ text: "#c9c7c0",
501
+ text2: "#8b8994",
502
+ text3: "#4e4c58",
503
+ accent: "#6e9fff",
504
+ accent2: "#2f5db0",
505
+ green: "#4ec9a0",
506
+ orange: "#d4976e",
507
+ purple: "#b48eff",
508
+ red: "#f28b82",
509
+ yellow: "#e8c97a",
510
+ cur: "#6e9fff",
511
+ curGlow: "rgba(110,159,255,.65)",
512
+ curLineBg: "rgba(255,255,255,.032)",
513
+ curLineGutter: "#181820",
514
+ gutterBg: "#0f0f12",
515
+ gutterHover: "#181820",
516
+ gutterBorder: "rgba(255,255,255,.06)",
517
+ gutterNum: "#4e4c58",
518
+ gutterNumAct: "#9997a2",
519
+ selBg: "rgba(110,159,255,.22)",
520
+ wordHlBg: "rgba(200,198,210,.09)",
521
+ wordHlBorder: "rgba(200,198,210,.28)",
522
+ bmBorder: "rgba(110,159,255,.65)",
523
+ foldBg: "rgba(110,159,255,.07)",
524
+ foldBorder: "rgba(110,159,255,.30)",
525
+ findBg: "rgba(234,180,86,.18)",
526
+ findBorder: "rgba(234,180,86,.50)",
527
+ findCurBg: "rgba(234,180,86,.80)",
528
+ findCurBorder: "rgba(234,180,86,.95)",
529
+ findCurText: "#1a1000",
530
+ fileActiveBg: "rgba(110,159,255,.11)",
531
+ fileActiveText: "#6e9fff",
532
+ mmBg: "#0d0d0f",
533
+ mmSlider: "rgba(255,255,255,.07)",
534
+ mmDim: "rgba(0,0,0,.30)",
535
+ mmEdge: "rgba(255,255,255,.18)",
536
+ indentGuide: "rgba(255,255,255,.06)",
537
+ tokKw: "#6e9fff",
538
+ tokStr: "#4ec9a0",
539
+ tokCmt: "#4e4c58",
540
+ tokFn: "#d4976e",
541
+ tokNum: "#b48eff",
542
+ tokCls: "#e8c97a",
543
+ tokOp: "#55536a",
544
+ tokTyp: "#6ec9d4",
545
+ tokDec: "#f28b82"
546
+ }
547
+ }, Ve = {
548
+ id: "vscode-dark",
549
+ name: "VSCode Dark+",
550
+ description: "Visual Studio Code dark",
551
+ light: !1,
552
+ tokens: {
553
+ bg0: "#1e1e1e",
554
+ bg1: "#252526",
555
+ bg2: "#1e1e1e",
556
+ bg3: "#2d2d30",
557
+ bg4: "#3a3a3d",
558
+ border: "rgba(255,255,255,.09)",
559
+ border2: "rgba(255,255,255,.15)",
560
+ border3: "rgba(255,255,255,.24)",
561
+ text: "#d4d4d4",
562
+ text2: "#9a9a9a",
563
+ text3: "#505050",
564
+ accent: "#569cd6",
565
+ accent2: "#0e639c",
566
+ green: "#4ec9b0",
567
+ orange: "#ce9178",
568
+ purple: "#c586c0",
569
+ red: "#f44747",
570
+ yellow: "#dcdcaa",
571
+ cur: "#aeafad",
572
+ curGlow: "rgba(174,175,173,.40)",
573
+ curLineBg: "rgba(255,255,255,.038)",
574
+ curLineGutter: "#282828",
575
+ gutterBg: "#1e1e1e",
576
+ gutterHover: "#282828",
577
+ gutterBorder: "rgba(255,255,255,.07)",
578
+ gutterNum: "#838383",
579
+ gutterNumAct: "#c8c8c8",
580
+ selBg: "rgba(38,79,120,.65)",
581
+ wordHlBg: "rgba(173,214,255,.06)",
582
+ wordHlBorder: "rgba(173,214,255,.28)",
583
+ bmBorder: "rgba(86,156,214,.70)",
584
+ foldBg: "rgba(86,156,214,.07)",
585
+ foldBorder: "rgba(86,156,214,.35)",
586
+ findBg: "rgba(255,215,0,.13)",
587
+ findBorder: "rgba(255,215,0,.52)",
588
+ findCurBg: "#f6f6a0",
589
+ findCurBorder: "#d4d400",
590
+ findCurText: "#000",
591
+ fileActiveBg: "rgba(255,255,255,.07)",
592
+ fileActiveText: "#d4d4d4",
593
+ mmBg: "#1e1e1e",
594
+ mmSlider: "rgba(255,255,255,.07)",
595
+ mmDim: "rgba(0,0,0,.32)",
596
+ mmEdge: "rgba(255,255,255,.20)",
597
+ indentGuide: "rgba(255,255,255,.07)",
598
+ tokKw: "#569cd6",
599
+ tokStr: "#ce9178",
600
+ tokCmt: "#6a9955",
601
+ tokFn: "#dcdcaa",
602
+ tokNum: "#b5cea8",
603
+ tokCls: "#4ec9b0",
604
+ tokOp: "#d4d4d4",
605
+ tokTyp: "#4ec9b0",
606
+ tokDec: "#9cdcfe"
607
+ }
608
+ }, Ye = {
609
+ id: "monokai",
610
+ name: "Monokai",
611
+ description: "Classic Sublime Text theme",
612
+ light: !1,
613
+ tokens: {
614
+ bg0: "#272822",
615
+ bg1: "#1e1f1c",
616
+ bg2: "#272822",
617
+ bg3: "#3a3930",
618
+ bg4: "#48473d",
619
+ border: "rgba(255,255,255,.08)",
620
+ border2: "rgba(255,255,255,.13)",
621
+ border3: "rgba(255,255,255,.20)",
622
+ text: "#f8f8f2",
623
+ text2: "#a8a7a0",
624
+ text3: "#58574e",
625
+ accent: "#a6e22e",
626
+ accent2: "#3d5a10",
627
+ green: "#a6e22e",
628
+ orange: "#fd971f",
629
+ purple: "#ae81ff",
630
+ red: "#f92672",
631
+ yellow: "#e6db74",
632
+ cur: "#f8f8f2",
633
+ curGlow: "rgba(248,248,242,.25)",
634
+ curLineBg: "rgba(255,255,255,.042)",
635
+ curLineGutter: "#2c2d27",
636
+ gutterBg: "#1e1f1c",
637
+ gutterHover: "#2c2d27",
638
+ gutterBorder: "rgba(255,255,255,.06)",
639
+ gutterNum: "#6e6d64",
640
+ gutterNumAct: "#cccac0",
641
+ selBg: "rgba(73,72,62,.80)",
642
+ wordHlBg: "rgba(248,248,242,.06)",
643
+ wordHlBorder: "rgba(248,248,242,.22)",
644
+ bmBorder: "rgba(166,226,46,.65)",
645
+ foldBg: "rgba(166,226,46,.07)",
646
+ foldBorder: "rgba(166,226,46,.30)",
647
+ findBg: "rgba(230,219,116,.16)",
648
+ findBorder: "rgba(230,219,116,.52)",
649
+ findCurBg: "#e6db74",
650
+ findCurBorder: "#c9be50",
651
+ findCurText: "#272822",
652
+ fileActiveBg: "rgba(166,226,46,.10)",
653
+ fileActiveText: "#a6e22e",
654
+ mmBg: "#1e1f1c",
655
+ mmSlider: "rgba(255,255,255,.06)",
656
+ mmDim: "rgba(0,0,0,.32)",
657
+ mmEdge: "rgba(255,255,255,.18)",
658
+ indentGuide: "rgba(255,255,255,.06)",
659
+ tokKw: "#f92672",
660
+ tokStr: "#e6db74",
661
+ tokCmt: "#75715e",
662
+ tokFn: "#a6e22e",
663
+ tokNum: "#ae81ff",
664
+ tokCls: "#66d9e8",
665
+ tokOp: "#f8f8f2",
666
+ tokTyp: "#66d9e8",
667
+ tokDec: "#fd971f"
668
+ }
669
+ }, Je = {
670
+ id: "dracula",
671
+ name: "Dracula",
672
+ description: "Purple-tinted dark theme",
673
+ light: !1,
674
+ tokens: {
675
+ bg0: "#282a36",
676
+ bg1: "#21222c",
677
+ bg2: "#282a36",
678
+ bg3: "#333545",
679
+ bg4: "#44475a",
680
+ border: "rgba(255,255,255,.08)",
681
+ border2: "rgba(255,255,255,.14)",
682
+ border3: "rgba(255,255,255,.22)",
683
+ text: "#f8f8f2",
684
+ text2: "#b2b5c8",
685
+ text3: "#5a5e78",
686
+ accent: "#bd93f9",
687
+ accent2: "#5b3fa8",
688
+ green: "#50fa7b",
689
+ orange: "#ffb86c",
690
+ purple: "#bd93f9",
691
+ red: "#ff5555",
692
+ yellow: "#f1fa8c",
693
+ cur: "#f8f8f2",
694
+ curGlow: "rgba(189,147,249,.55)",
695
+ curLineBg: "rgba(255,255,255,.045)",
696
+ curLineGutter: "#2f3144",
697
+ gutterBg: "#21222c",
698
+ gutterHover: "#2f3144",
699
+ gutterBorder: "rgba(255,255,255,.07)",
700
+ gutterNum: "#5e638a",
701
+ gutterNumAct: "#f8f8f2",
702
+ selBg: "rgba(68,71,90,.85)",
703
+ wordHlBg: "rgba(248,248,242,.05)",
704
+ wordHlBorder: "rgba(248,248,242,.20)",
705
+ bmBorder: "rgba(189,147,249,.70)",
706
+ foldBg: "rgba(189,147,249,.08)",
707
+ foldBorder: "rgba(189,147,249,.35)",
708
+ findBg: "rgba(241,250,140,.14)",
709
+ findBorder: "rgba(241,250,140,.52)",
710
+ findCurBg: "#f1fa8c",
711
+ findCurBorder: "#d4dc50",
712
+ findCurText: "#282a36",
713
+ fileActiveBg: "rgba(189,147,249,.12)",
714
+ fileActiveText: "#bd93f9",
715
+ mmBg: "#21222c",
716
+ mmSlider: "rgba(255,255,255,.07)",
717
+ mmDim: "rgba(0,0,0,.32)",
718
+ mmEdge: "rgba(255,255,255,.20)",
719
+ indentGuide: "rgba(255,255,255,.07)",
720
+ tokKw: "#ff79c6",
721
+ tokStr: "#f1fa8c",
722
+ tokCmt: "#6272a4",
723
+ tokFn: "#50fa7b",
724
+ tokNum: "#bd93f9",
725
+ tokCls: "#8be9fd",
726
+ tokOp: "#f8f8f2",
727
+ tokTyp: "#8be9fd",
728
+ tokDec: "#ffb86c"
729
+ }
730
+ }, Xe = {
731
+ id: "github-light",
732
+ name: "GitHub Light",
733
+ description: "GitHub's clean light theme",
734
+ light: !0,
735
+ tokens: {
736
+ bg0: "#ffffff",
737
+ bg1: "#f6f8fa",
738
+ bg2: "#ffffff",
739
+ bg3: "#f0f3f6",
740
+ bg4: "#e7eaee",
741
+ border: "#d0d7de",
742
+ border2: "#bdc4cc",
743
+ border3: "#aab1ba",
744
+ text: "#1f2328",
745
+ text2: "#57606a",
746
+ text3: "#8c959f",
747
+ accent: "#0969da",
748
+ accent2: "#0550ae",
749
+ green: "#1a7f37",
750
+ orange: "#bc4c00",
751
+ purple: "#8250df",
752
+ red: "#cf222e",
753
+ yellow: "#7d4e00",
754
+ cur: "#0969da",
755
+ curGlow: "rgba(9,105,218,.30)",
756
+ curLineBg: "rgba(9,105,218,.055)",
757
+ curLineGutter: "#ebf0f8",
758
+ gutterBg: "#f6f8fa",
759
+ gutterHover: "#eaedf1",
760
+ gutterBorder: "#d0d7de",
761
+ gutterNum: "#9da5b0",
762
+ gutterNumAct: "#1f2328",
763
+ selBg: "rgba(9,105,218,.15)",
764
+ wordHlBg: "rgba(9,105,218,.07)",
765
+ wordHlBorder: "rgba(9,105,218,.28)",
766
+ bmBorder: "rgba(9,105,218,.60)",
767
+ foldBg: "rgba(9,105,218,.06)",
768
+ foldBorder: "rgba(9,105,218,.28)",
769
+ findBg: "rgba(180,100,0,.09)",
770
+ findBorder: "rgba(180,100,0,.42)",
771
+ findCurBg: "rgba(180,100,0,.75)",
772
+ findCurBorder: "rgba(180,100,0,.95)",
773
+ findCurText: "#fff",
774
+ fileActiveBg: "rgba(9,105,218,.09)",
775
+ fileActiveText: "#0969da",
776
+ mmBg: "#f6f8fa",
777
+ mmSlider: "rgba(0,0,0,.06)",
778
+ mmDim: "rgba(0,0,0,.055)",
779
+ mmEdge: "rgba(0,0,0,.18)",
780
+ indentGuide: "rgba(0,0,0,.09)",
781
+ tokKw: "#cf222e",
782
+ tokStr: "#0a3069",
783
+ tokCmt: "#6e7781",
784
+ tokFn: "#8250df",
785
+ tokNum: "#0550ae",
786
+ tokCls: "#953800",
787
+ tokOp: "#1f2328",
788
+ tokTyp: "#0550ae",
789
+ tokDec: "#0969da"
790
+ }
791
+ }, Ze = {
792
+ id: "solarized-light",
793
+ name: "Solarized Light",
794
+ description: "Warm precision light theme",
795
+ light: !0,
796
+ tokens: {
797
+ bg0: "#fdf6e3",
798
+ bg1: "#eee8d5",
799
+ bg2: "#fdf6e3",
800
+ bg3: "#e5dfcc",
801
+ bg4: "#dad4c1",
802
+ border: "#cdc7b4",
803
+ border2: "#bab4a2",
804
+ border3: "#a9a390",
805
+ text: "#002b36",
806
+ text2: "#586e75",
807
+ text3: "#93a1a1",
808
+ accent: "#268bd2",
809
+ accent2: "#1a6fa8",
810
+ green: "#859900",
811
+ orange: "#cb4b16",
812
+ purple: "#6c71c4",
813
+ red: "#dc322f",
814
+ yellow: "#b58900",
815
+ cur: "#268bd2",
816
+ curGlow: "rgba(38,139,210,.32)",
817
+ curLineBg: "rgba(38,139,210,.07)",
818
+ curLineGutter: "#e2dcc8",
819
+ gutterBg: "#eee8d5",
820
+ gutterHover: "#e2dcc8",
821
+ gutterBorder: "#cdc7b4",
822
+ gutterNum: "#93a1a1",
823
+ gutterNumAct: "#002b36",
824
+ selBg: "rgba(38,139,210,.18)",
825
+ wordHlBg: "rgba(38,139,210,.08)",
826
+ wordHlBorder: "rgba(38,139,210,.28)",
827
+ bmBorder: "rgba(38,139,210,.58)",
828
+ foldBg: "rgba(38,139,210,.07)",
829
+ foldBorder: "rgba(38,139,210,.28)",
830
+ findBg: "rgba(181,137,0,.11)",
831
+ findBorder: "rgba(181,137,0,.42)",
832
+ findCurBg: "rgba(181,137,0,.75)",
833
+ findCurBorder: "rgba(181,137,0,.95)",
834
+ findCurText: "#fff",
835
+ fileActiveBg: "rgba(38,139,210,.10)",
836
+ fileActiveText: "#268bd2",
837
+ mmBg: "#eee8d5",
838
+ mmSlider: "rgba(0,0,0,.06)",
839
+ mmDim: "rgba(0,0,0,.055)",
840
+ mmEdge: "rgba(0,0,0,.16)",
841
+ indentGuide: "rgba(0,0,0,.08)",
842
+ tokKw: "#859900",
843
+ tokStr: "#2aa198",
844
+ tokCmt: "#93a1a1",
845
+ tokFn: "#268bd2",
846
+ tokNum: "#d33682",
847
+ tokCls: "#b58900",
848
+ tokOp: "#657b83",
849
+ tokTyp: "#268bd2",
850
+ tokDec: "#cb4b16"
851
+ }
852
+ }, Qe = {
853
+ id: "mdx-dark",
854
+ name: "MDX Dark",
855
+ description: "Catppuccin Mocha — matches .smdx-dark MDX editor chrome, single-colour tokens",
856
+ light: !1,
857
+ tokens: {
858
+ bg0: "#181825",
859
+ bg1: "#1e1e2e",
860
+ bg2: "#1e1e2e",
861
+ bg3: "#2a2a3c",
862
+ bg4: "#313147",
863
+ border: "#374151",
864
+ border2: "rgba(129,140,248,.22)",
865
+ border3: "rgba(129,140,248,.40)",
866
+ text: "#e2e8f0",
867
+ text2: "#94a3b8",
868
+ text3: "#475569",
869
+ accent: "#818cf8",
870
+ accent2: "#6366f1",
871
+ green: "#c3e88d",
872
+ orange: "#f78c6c",
873
+ purple: "#c792ea",
874
+ red: "#f07178",
875
+ yellow: "#ffcb6b",
876
+ cur: "#818cf8",
877
+ curGlow: "rgba(129,140,248,.55)",
878
+ curLineBg: "rgba(129,140,248,.055)",
879
+ curLineGutter: "#252540",
880
+ gutterBg: "#181825",
881
+ gutterHover: "#252540",
882
+ gutterBorder: "#374151",
883
+ gutterNum: "#475569",
884
+ gutterNumAct: "#94a3b8",
885
+ selBg: "rgba(129,140,248,.24)",
886
+ wordHlBg: "rgba(226,232,240,.07)",
887
+ wordHlBorder: "rgba(226,232,240,.25)",
888
+ bmBorder: "rgba(137,221,255,.70)",
889
+ foldBg: "rgba(129,140,248,.07)",
890
+ foldBorder: "rgba(129,140,248,.30)",
891
+ findBg: "rgba(251,191,36,.16)",
892
+ findBorder: "rgba(251,191,36,.50)",
893
+ findCurBg: "rgba(251,191,36,.85)",
894
+ findCurBorder: "rgba(251,191,36,.95)",
895
+ findCurText: "#1a1000",
896
+ fileActiveBg: "rgba(129,140,248,.12)",
897
+ fileActiveText: "#818cf8",
898
+ mmBg: "#181825",
899
+ mmSlider: "rgba(255,255,255,.07)",
900
+ mmDim: "rgba(0,0,0,.30)",
901
+ mmEdge: "rgba(255,255,255,.18)",
902
+ indentGuide: "rgba(255,255,255,.06)",
903
+ // All tokens match prose text — single-colour, distraction-free editing
904
+ tokKw: "#e2e8f0",
905
+ tokStr: "#e2e8f0",
906
+ tokCmt: "#e2e8f0",
907
+ tokFn: "#e2e8f0",
908
+ tokNum: "#e2e8f0",
909
+ tokCls: "#e2e8f0",
910
+ tokOp: "#e2e8f0",
911
+ tokTyp: "#e2e8f0",
912
+ tokDec: "#e2e8f0"
913
+ }
914
+ }, et = {
915
+ id: "mdx-light",
916
+ name: "MDX Light",
917
+ description: "Clean light — matches default .smdx-editor MDX chrome, single-colour tokens",
918
+ light: !0,
919
+ tokens: {
920
+ bg0: "#f1f5f9",
921
+ bg1: "#ffffff",
922
+ bg2: "#ffffff",
923
+ bg3: "#f8fafc",
924
+ bg4: "#f1f5f9",
925
+ border: "#e2e8f0",
926
+ border2: "rgba(99,102,241,.20)",
927
+ border3: "rgba(99,102,241,.40)",
928
+ text: "#1e293b",
929
+ text2: "#64748b",
930
+ text3: "#94a3b8",
931
+ accent: "#6366f1",
932
+ accent2: "#4f46e5",
933
+ green: "#15803d",
934
+ orange: "#c2410c",
935
+ purple: "#7c3aed",
936
+ red: "#dc2626",
937
+ yellow: "#b45309",
938
+ cur: "#6366f1",
939
+ curGlow: "rgba(99,102,241,.35)",
940
+ curLineBg: "rgba(99,102,241,.05)",
941
+ curLineGutter: "#eef2ff",
942
+ gutterBg: "#f8fafc",
943
+ gutterHover: "#eef2ff",
944
+ gutterBorder: "#e2e8f0",
945
+ gutterNum: "#94a3b8",
946
+ gutterNumAct: "#475569",
947
+ selBg: "rgba(99,102,241,.18)",
948
+ wordHlBg: "rgba(99,102,241,.07)",
949
+ wordHlBorder: "rgba(99,102,241,.30)",
950
+ bmBorder: "rgba(14,116,144,.60)",
951
+ foldBg: "rgba(99,102,241,.06)",
952
+ foldBorder: "rgba(99,102,241,.28)",
953
+ findBg: "rgba(180,83,9,.09)",
954
+ findBorder: "rgba(180,83,9,.40)",
955
+ findCurBg: "rgba(180,83,9,.75)",
956
+ findCurBorder: "rgba(180,83,9,.95)",
957
+ findCurText: "#ffffff",
958
+ fileActiveBg: "rgba(99,102,241,.10)",
959
+ fileActiveText: "#6366f1",
960
+ mmBg: "#f8fafc",
961
+ mmSlider: "rgba(0,0,0,.06)",
962
+ mmDim: "rgba(0,0,0,.05)",
963
+ mmEdge: "rgba(0,0,0,.18)",
964
+ indentGuide: "rgba(0,0,0,.08)",
965
+ // All tokens match prose text — single-colour, distraction-free editing
966
+ tokKw: "#1e293b",
967
+ tokStr: "#1e293b",
968
+ tokCmt: "#1e293b",
969
+ tokFn: "#1e293b",
970
+ tokNum: "#1e293b",
971
+ tokCls: "#1e293b",
972
+ tokOp: "#1e293b",
973
+ tokTyp: "#1e293b",
974
+ tokDec: "#1e293b"
975
+ }
976
+ }, tt = [
977
+ qe,
978
+ Ve,
979
+ Ye,
980
+ Je,
981
+ Xe,
982
+ Ze,
983
+ Qe,
984
+ et
985
+ ], it = {
986
+ bg0: "--bg0",
987
+ bg1: "--bg1",
988
+ bg2: "--bg2",
989
+ bg3: "--bg3",
990
+ bg4: "--bg4",
991
+ border: "--border",
992
+ border2: "--border2",
993
+ border3: "--border3",
994
+ text: "--text",
995
+ text2: "--text2",
996
+ text3: "--text3",
997
+ accent: "--accent",
998
+ accent2: "--accent2",
999
+ green: "--green",
1000
+ orange: "--orange",
1001
+ purple: "--purple",
1002
+ red: "--red",
1003
+ yellow: "--yellow",
1004
+ cur: "--cur",
1005
+ curGlow: "--cur-glow",
1006
+ curLineBg: "--cur-line-bg",
1007
+ curLineGutter: "--cur-line-gutter",
1008
+ gutterBg: "--gutter-bg",
1009
+ gutterHover: "--gutter-hover",
1010
+ gutterBorder: "--gutter-border",
1011
+ gutterNum: "--gutter-num",
1012
+ gutterNumAct: "--gutter-num-act",
1013
+ selBg: "--sel-bg",
1014
+ wordHlBg: "--word-hl-bg",
1015
+ wordHlBorder: "--word-hl-border",
1016
+ bmBorder: "--bm-border",
1017
+ foldBg: "--fold-bg",
1018
+ foldBorder: "--fold-border",
1019
+ findBg: "--find-bg",
1020
+ findBorder: "--find-border",
1021
+ findCurBg: "--find-cur-bg",
1022
+ findCurBorder: "--find-cur-border",
1023
+ findCurText: "--find-cur-text",
1024
+ fileActiveBg: "--file-active-bg",
1025
+ fileActiveText: "--file-active-text",
1026
+ mmBg: "--mm-bg",
1027
+ mmSlider: "--mm-slider",
1028
+ mmDim: "--mm-dim",
1029
+ mmEdge: "--mm-edge",
1030
+ indentGuide: "--indent-guide",
1031
+ tokKw: "--tok-kw",
1032
+ tokStr: "--tok-str",
1033
+ tokCmt: "--tok-cmt",
1034
+ tokFn: "--tok-fn",
1035
+ tokNum: "--tok-num",
1036
+ tokCls: "--tok-cls",
1037
+ tokOp: "--tok-op",
1038
+ tokTyp: "--tok-typ",
1039
+ tokDec: "--tok-dec"
1040
+ };
1041
+ class rt {
1042
+ constructor(e) {
1043
+ u(this, "_registry", /* @__PURE__ */ new Map());
1044
+ u(this, "_activeId", "");
1045
+ u(this, "_root");
1046
+ this._root = e;
1047
+ for (const t of tt)
1048
+ this._registry.set(t.id, t);
1049
+ }
1050
+ /** Register a custom or override theme. */
1051
+ register(e) {
1052
+ this._registry.set(e.id, e);
1053
+ }
1054
+ /** Apply a theme by id or by definition. */
1055
+ apply(e) {
1056
+ let t;
1057
+ typeof e == "string" ? (t = this._registry.get(e), t || (console.warn(`[syncline-editor] Unknown theme: "${e}". Falling back to VR Dark.`), t = this._registry.get(""))) : (t = e, this._registry.set(t.id, t)), this._activeId = t.id, this._applyTokens(t.tokens);
1058
+ }
1059
+ get activeId() {
1060
+ return this._activeId;
1061
+ }
1062
+ get activeTheme() {
1063
+ return this._registry.get(this._activeId);
1064
+ }
1065
+ get allIds() {
1066
+ return [...this._registry.keys()];
1067
+ }
1068
+ get all() {
1069
+ return [...this._registry.values()];
1070
+ }
1071
+ _applyTokens(e) {
1072
+ const t = this._root.style;
1073
+ for (const [i, r] of Object.entries(it))
1074
+ t.setProperty(r, e[i]);
1075
+ }
1076
+ }
1077
+ const nt = `
1078
+ /* ── Reset ── */
1079
+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
1080
+
1081
+ /* ── Host element ── */
1082
+ :host,.sl-host{
1083
+ display:flex;flex-direction:column;
1084
+ height:100%;overflow:hidden;
1085
+ font-family:var(--sans,'Geist',system-ui,sans-serif);
1086
+ color:var(--text,#c9c7c0);
1087
+ background:var(--bg0,#0d0d0f);
1088
+
1089
+ /* Default token vars (can be overridden by theme) */
1090
+ --sans:'Geist',system-ui,sans-serif;
1091
+ --mono:'JetBrains Mono',monospace;
1092
+
1093
+ /* ── VR Dark defaults ── */
1094
+ --bg0:#0d0d0f; --bg1:#111115; --bg2:#16161b; --bg3:#1d1d24; --bg4:#24242d;
1095
+ --border:rgba(255,255,255,.07);
1096
+ --border2:rgba(255,255,255,.12);
1097
+ --border3:rgba(255,255,255,.19);
1098
+ --text:#c9c7c0; --text2:#8b8994; --text3:#4e4c58;
1099
+ --accent:#6e9fff; --accent2:#2f5db0;
1100
+ --green:#4ec9a0; --orange:#d4976e; --purple:#b48eff;
1101
+ --red:#f28b82; --yellow:#e8c97a;
1102
+ --cur:#6e9fff; --cur-glow:rgba(110,159,255,.65);
1103
+ --cur-line-bg:rgba(255,255,255,.032);
1104
+ --cur-line-gutter:#181820;
1105
+ --gutter-bg:#0f0f12; --gutter-hover:#181820;
1106
+ --gutter-border:rgba(255,255,255,.06);
1107
+ --gutter-num:#4e4c58; --gutter-num-act:#9997a2;
1108
+ --sel-bg:rgba(110,159,255,.22);
1109
+ --word-hl-bg:rgba(200,198,210,.09);
1110
+ --word-hl-border:rgba(200,198,210,.28);
1111
+ --bm-border:rgba(110,159,255,.65);
1112
+ --fold-bg:rgba(110,159,255,.07);
1113
+ --fold-border:rgba(110,159,255,.30);
1114
+ --find-bg:rgba(234,180,86,.18);
1115
+ --find-border:rgba(234,180,86,.50);
1116
+ --find-cur-bg:rgba(234,180,86,.80);
1117
+ --find-cur-border:rgba(234,180,86,.95);
1118
+ --find-cur-text:#1a1000;
1119
+ --file-active-bg:rgba(110,159,255,.11);
1120
+ --file-active-text:#6e9fff;
1121
+ --mm-bg:#0d0d0f; --mm-slider:rgba(255,255,255,.07);
1122
+ --mm-dim:rgba(0,0,0,.30); --mm-edge:rgba(255,255,255,.18);
1123
+ --indent-guide:rgba(255,255,255,.06);
1124
+ --tok-kw:#6e9fff; --tok-str:#4ec9a0; --tok-cmt:#4e4c58;
1125
+ --tok-fn:#d4976e; --tok-num:#b48eff; --tok-cls:#e8c97a;
1126
+ --tok-op:#55536a; --tok-typ:#6ec9d4; --tok-dec:#f28b82;
1127
+ }
1128
+
1129
+ /* ── Layout ── */
1130
+ .sl-layout{display:flex;flex:1;overflow:hidden}
1131
+ .sl-ed-pane{flex:1;display:flex;flex-direction:column;overflow:hidden;position:relative;background:var(--bg2)}
1132
+
1133
+ /* ── Hidden textarea (input capture) ── */
1134
+ .sl-input{position:fixed;left:-9999px;top:0;width:200px;height:40px;
1135
+ opacity:0;resize:none;border:none;outline:none;padding:0;margin:0;
1136
+ font-size:16px;background:transparent;color:transparent;
1137
+ caret-color:transparent;pointer-events:none}
1138
+
1139
+ /* ── Editor scroll container ── */
1140
+ .sl-editor{flex:1;overflow-y:scroll;overflow-x:auto;position:relative;
1141
+ cursor:text;scrollbar-width:thin;scrollbar-color:var(--border3) transparent}
1142
+ .sl-editor::-webkit-scrollbar{width:10px;height:8px}
1143
+ .sl-editor::-webkit-scrollbar-track{background:transparent}
1144
+ .sl-editor::-webkit-scrollbar-thumb{background:var(--border3);border-radius:5px;border:2px solid var(--bg2)}
1145
+ .sl-spacer{position:absolute;left:0;top:0;width:1px;pointer-events:none}
1146
+ .sl-vp{position:absolute;left:0;right:0;will-change:transform}
1147
+
1148
+ /* ── Editor row ── */
1149
+ .sl-er{display:flex;align-items:stretch;position:relative}
1150
+ .sl-er:hover .sl-eg{background:var(--gutter-hover)}
1151
+ .sl-er.sl-cur-row{background:var(--cur-line-bg)}
1152
+ .sl-er.sl-cur-row .sl-eg{background:var(--cur-line-gutter)!important}
1153
+ .sl-eg{min-width:60px;font-family:var(--mono);font-size:11px;color:var(--gutter-num);
1154
+ user-select:none;border-right:1px solid var(--gutter-border);
1155
+ background:var(--gutter-bg);flex-shrink:0;position:sticky;left:0;z-index:2;
1156
+ display:flex;flex-direction:column;justify-content:flex-start;
1157
+ transition:background .12s,color .12s}
1158
+ .sl-er.sl-cur-row .sl-eg{color:var(--gutter-num-act)}
1159
+ .sl-egn{height:22px;line-height:22px;padding-right:10px;text-align:right;display:block}
1160
+ .sl-er.sl-wrap-cont .sl-egn{visibility:hidden}
1161
+ .sl-el{flex:1;font-family:var(--mono);font-size:13px;line-height:22px;
1162
+ color:var(--text);position:relative;min-width:0}
1163
+ .sl-cl{display:block;height:22px;line-height:22px;
1164
+ padding:0 20px 0 14px;white-space:pre;position:relative}
1165
+ .sl-wrap-mode .sl-cl{white-space:pre-wrap;word-break:break-all;height:auto;overflow-wrap:anywhere}
1166
+
1167
+ /* ── Cursor ── */
1168
+ .sl-cur{display:inline;width:0;height:0;position:relative}
1169
+ .sl-cur::after{content:'';position:absolute;left:0;top:2px;width:2px;height:18px;
1170
+ background:var(--cur);border-radius:1px;
1171
+ box-shadow:0 0 8px var(--cur-glow);
1172
+ animation:sl-blink 1.05s step-end infinite;pointer-events:none}
1173
+ @keyframes sl-blink{0%,100%{opacity:1}45%,55%{opacity:0}}
1174
+
1175
+ /* ── Multi-cursor extra beams ── */
1176
+ .sl-cur-extra{display:inline;width:0;height:0;position:relative}
1177
+ .sl-cur-extra::after{content:'';position:absolute;left:0;top:2px;width:2px;height:18px;
1178
+ background:var(--cur);border-radius:1px;
1179
+ box-shadow:0 0 8px var(--cur-glow);
1180
+ animation:sl-blink 1.05s step-end infinite;pointer-events:none}
1181
+
1182
+ /* ── Overlays ── */
1183
+ .sl-sh{background:var(--sel-bg);border-radius:2px}
1184
+ .sl-fh{background:var(--find-bg);border:1px solid var(--find-border);border-radius:2px}
1185
+ .sl-fh.sl-fh-cur{background:var(--find-cur-bg);border:1px solid var(--find-cur-border);color:var(--find-cur-text)}
1186
+ .sl-wh{background:var(--word-hl-bg);border:1px solid var(--word-hl-border);border-radius:2px}
1187
+ .sl-bm{box-shadow:0 0 0 1px var(--bm-border);border-radius:2px}
1188
+ .sl-ig{position:absolute;top:0;bottom:0;width:1px;background:var(--indent-guide);pointer-events:none}
1189
+
1190
+ /* ── Code folding ── */
1191
+ .sl-fold-btn{position:absolute;left:3px;top:4px;width:13px;height:13px;border-radius:3px;
1192
+ display:flex;align-items:center;justify-content:center;font-size:9px;
1193
+ color:var(--gutter-num);cursor:pointer;opacity:0;
1194
+ transition:opacity .15s,background .1s;user-select:none;line-height:1}
1195
+ .sl-er:hover .sl-fold-btn{opacity:1}
1196
+ .sl-fold-btn:hover{background:var(--border3);color:var(--gutter-num-act)}
1197
+ .sl-folded{background:var(--fold-bg);border-bottom:1px dashed var(--fold-border)}
1198
+
1199
+ /* ── Syntax tokens ── */
1200
+ .kw{color:var(--tok-kw)}.str{color:var(--tok-str)}.cmt{color:var(--tok-cmt);font-style:italic}
1201
+ .fn{color:var(--tok-fn)}.num{color:var(--tok-num)}.cls{color:var(--tok-cls)}
1202
+ .op{color:var(--tok-op)}.typ{color:var(--tok-typ)}.dec{color:var(--tok-dec)}
1203
+
1204
+ /* ── Minimap ── */
1205
+ .sl-minimap{background:var(--mm-bg);border-left:1px solid var(--border);
1206
+ overflow:hidden;position:relative;flex-shrink:0;cursor:pointer;user-select:none}
1207
+ .sl-minimap canvas{display:block;position:absolute;top:0;left:0}
1208
+ .sl-mm-slider{position:absolute;left:0;right:0;pointer-events:none}
1209
+
1210
+ /* ── Status bar ── */
1211
+ .sl-statusbar{height:26px;background:var(--accent2);display:flex;align-items:center;
1212
+ padding:0 6px;font-size:11px;color:rgba(255,255,255,.85);flex-shrink:0;gap:0}
1213
+ .sl-sb-item{display:flex;align-items:center;gap:4px;padding:0 8px;height:100%;
1214
+ cursor:pointer;transition:background .1s;white-space:nowrap;border-radius:3px}
1215
+ .sl-sb-item:hover{background:rgba(255,255,255,.15)}
1216
+ .sl-sb-item.sl-no-click{cursor:default}
1217
+ .sl-sb-item.sl-no-click:hover{background:transparent}
1218
+ .sl-sb-sep{width:1px;height:14px;background:rgba(255,255,255,.22);margin:0 1px;flex-shrink:0}
1219
+ .sl-sb-right{margin-left:auto;display:flex;align-items:center}
1220
+ .sl-sb-wrap.sl-on{font-weight:700}
1221
+
1222
+ /* ── Find + Replace bar ── */
1223
+ .sl-find-bar{position:absolute;top:0;right:125px;z-index:50;background:var(--bg3);
1224
+ border:1px solid var(--border3);border-top:none;border-radius:0 0 10px 10px;
1225
+ display:flex;flex-direction:column;overflow:hidden;
1226
+ transform:translateY(-100%);transition:transform .18s,box-shadow .18s;pointer-events:none}
1227
+ .sl-find-bar.sl-open{transform:translateY(0);pointer-events:all;box-shadow:0 8px 28px rgba(0,0,0,.4)}
1228
+ .sl-find-row{display:flex;align-items:center;gap:6px;padding:7px 10px}
1229
+ .sl-find-row+.sl-find-row{border-top:1px solid var(--border)}
1230
+ .sl-find-bar input{width:180px;background:var(--bg4);border:1px solid var(--border3);
1231
+ border-radius:5px;padding:4px 8px;font-size:12px;font-family:var(--mono);
1232
+ color:var(--text);outline:none;transition:border-color .15s}
1233
+ .sl-find-bar input:focus{border-color:var(--accent)}
1234
+ .sl-find-btn{padding:3px 8px;font-size:11px;border:1px solid var(--border3);
1235
+ border-radius:4px;background:transparent;color:var(--text2);cursor:pointer;
1236
+ transition:background .1s;white-space:nowrap}
1237
+ .sl-find-btn:hover{background:var(--border3);color:var(--text)}
1238
+ .sl-find-btn.sl-active{background:var(--accent);border-color:var(--accent);color:#fff}
1239
+ .sl-find-count{font-size:11px;color:var(--text3);font-family:var(--mono);min-width:52px}
1240
+ .sl-find-x{font-size:14px;color:var(--text3);cursor:pointer;padding:2px 5px;
1241
+ border-radius:3px;margin-left:2px}
1242
+ .sl-find-x:hover{color:var(--text);background:var(--border3)}
1243
+
1244
+ /* ── Autocomplete popup (VS Code-style with optional description panel) ── */
1245
+ .sl-ac-popup{position:fixed;z-index:400;background:var(--bg3);
1246
+ border:1px solid var(--border3);border-radius:8px;overflow:hidden;
1247
+ box-shadow:0 12px 40px rgba(0,0,0,.55);
1248
+ display:flex;flex-direction:row;
1249
+ animation:sl-acIn .1s ease;pointer-events:all}
1250
+ @keyframes sl-acIn{from{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:none}}
1251
+ /* Left: item list */
1252
+ .sl-ac-list{min-width:240px;max-width:300px;max-height:320px;overflow-y:auto;flex-shrink:0}
1253
+ .sl-ac-list::-webkit-scrollbar{width:4px}
1254
+ .sl-ac-list::-webkit-scrollbar-thumb{background:var(--border3);border-radius:2px}
1255
+ .sl-ac-item{display:flex;align-items:center;gap:8px;padding:4px 10px;font-size:12px;
1256
+ font-family:var(--mono);cursor:pointer;color:var(--text2);transition:background .07s;
1257
+ white-space:nowrap}
1258
+ .sl-ac-item:hover,.sl-ac-item.sl-sel{background:var(--bg4);color:var(--text)}
1259
+ .sl-ac-badge{width:18px;height:18px;border-radius:4px;display:flex;align-items:center;
1260
+ justify-content:center;font-size:9px;font-weight:700;flex-shrink:0;font-family:var(--sans)}
1261
+ .sl-ac-badge.kw{background:rgba(110,159,255,.18);color:var(--tok-kw)}
1262
+ .sl-ac-badge.fn{background:rgba(212,151,110,.18);color:var(--tok-fn)}
1263
+ .sl-ac-badge.typ{background:rgba(110,201,212,.18);color:var(--tok-typ)}
1264
+ .sl-ac-badge.cls{background:rgba(232,201,122,.18);color:var(--tok-cls)}
1265
+ .sl-ac-badge.var{background:rgba(78,201,160,.18);color:var(--tok-str)}
1266
+ .sl-ac-badge.snip{background:rgba(155,100,255,.18);color:#a78bfa}
1267
+ .sl-ac-badge.emmet{background:rgba(255,140,0,.18);color:#fb923c}
1268
+ .sl-ac-label{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1269
+ .sl-ac-detail{font-size:10px;color:var(--text3);flex-shrink:0;max-width:120px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-left:4px}
1270
+ /* Right: description / docs panel */
1271
+ .sl-ac-desc{width:260px;max-height:320px;overflow-y:auto;
1272
+ border-left:1px solid var(--border3);padding:10px 12px;flex-shrink:0}
1273
+ .sl-ac-desc::-webkit-scrollbar{width:4px}
1274
+ .sl-ac-desc::-webkit-scrollbar-thumb{background:var(--border3);border-radius:2px}
1275
+ .sl-ac-desc-body{margin:0;font-size:11.5px;font-family:var(--mono);
1276
+ color:var(--text2);line-height:1.6;white-space:pre-wrap;word-break:break-word}
1277
+
1278
+ /* ── Hover documentation tooltip ── */
1279
+ .sl-hover-tip{position:fixed;z-index:500;background:var(--bg3);
1280
+ border:1px solid var(--border3);border-radius:8px;
1281
+ box-shadow:0 8px 32px rgba(0,0,0,.55);
1282
+ max-width:380px;min-width:180px;padding:10px 14px;
1283
+ pointer-events:all;cursor:default;
1284
+ animation:sl-hoverIn .12s ease}
1285
+ @keyframes sl-hoverIn{from{opacity:0;transform:translateY(3px)}to{opacity:1;transform:none}}
1286
+ .sl-ht-sig{display:flex;align-items:baseline;flex-wrap:wrap;gap:8px;margin-bottom:5px}
1287
+ .sl-ht-title{font-size:12.5px;font-family:var(--mono);font-weight:600;color:var(--tok-fn)}
1288
+ .sl-ht-type{font-size:11px;font-family:var(--mono);color:var(--tok-typ);opacity:.9;word-break:break-all}
1289
+ .sl-ht-body{font-size:12px;font-family:var(--sans);color:var(--text2);line-height:1.55;
1290
+ max-height:120px;overflow-y:auto}
1291
+ .sl-ht-body::-webkit-scrollbar{width:3px}
1292
+ .sl-ht-body::-webkit-scrollbar-thumb{background:var(--border3);border-radius:2px}
1293
+ .sl-hover-tip .sl-ht-divider{height:1px;background:var(--border);margin:6px 0}
1294
+
1295
+ /* ── Emmet tooltip ── */
1296
+ .sl-emmet-tip{position:fixed;z-index:600;background:var(--bg3);
1297
+ border:1px solid var(--border3);border-radius:6px;padding:4px 10px;
1298
+ font-size:11px;font-family:var(--mono);color:var(--accent);
1299
+ pointer-events:none;box-shadow:0 4px 16px rgba(0,0,0,.45);
1300
+ white-space:nowrap;max-width:400px;overflow:hidden;text-overflow:ellipsis}
1301
+
1302
+ /* ── Theme picker ── */
1303
+ .sl-theme-overlay{position:fixed;inset:0;z-index:700;
1304
+ background:rgba(0,0,0,.50);backdrop-filter:blur(2px)}
1305
+ .sl-theme-panel{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);
1306
+ z-index:701;background:var(--bg2);border:1px solid var(--border3);
1307
+ border-radius:14px;overflow:hidden;width:420px;
1308
+ box-shadow:0 32px 80px rgba(0,0,0,.65),0 0 0 1px var(--border2)}
1309
+ .sl-theme-header{padding:16px 20px 12px;display:flex;align-items:center;
1310
+ justify-content:space-between;border-bottom:1px solid var(--border)}
1311
+ .sl-theme-title{font-size:13px;font-weight:600;color:var(--text);letter-spacing:.01em}
1312
+ .sl-theme-close{width:24px;height:24px;border-radius:6px;display:flex;align-items:center;
1313
+ justify-content:center;font-size:14px;color:var(--text3);cursor:pointer;
1314
+ transition:background .1s,color .1s}
1315
+ .sl-theme-close:hover{background:var(--border3);color:var(--text)}
1316
+ .sl-theme-list{padding:8px 8px 10px}
1317
+ .sl-theme-item{display:flex;align-items:center;gap:14px;padding:10px 12px;
1318
+ border-radius:9px;cursor:pointer;transition:background .1s;
1319
+ border:1px solid transparent;margin-bottom:2px}
1320
+ .sl-theme-item:hover{background:var(--bg4)}
1321
+ .sl-theme-item.sl-active{background:var(--bg4);border-color:var(--border3)}
1322
+ .sl-theme-check{width:18px;height:18px;margin-left:auto;color:var(--accent);
1323
+ font-size:13px;font-weight:700;flex-shrink:0;opacity:0}
1324
+ .sl-theme-item.sl-active .sl-theme-check{opacity:1}
1325
+ .sl-theme-swatch{width:46px;height:30px;border-radius:7px;flex-shrink:0;
1326
+ overflow:hidden;border:1px solid rgba(0,0,0,.15);
1327
+ display:grid;grid-template-columns:1fr 1fr;grid-template-rows:1fr 1fr}
1328
+ .sl-theme-swatch span{display:block}
1329
+ .sl-theme-name{font-size:13px;color:var(--text);font-weight:500;line-height:1.3}
1330
+ .sl-theme-desc{font-size:11px;color:var(--text3);margin-top:2px}
1331
+ .sl-theme-tag{display:inline-block;font-size:9px;font-weight:600;letter-spacing:.08em;
1332
+ text-transform:uppercase;padding:1px 5px;border-radius:3px;margin-left:6px;
1333
+ background:var(--border3);color:var(--text3);vertical-align:middle}
1334
+ .sl-theme-tag.sl-light{background:rgba(255,200,50,.15);color:#b58900}
1335
+
1336
+ /* ── Empty state ── */
1337
+ .sl-empty{flex:1;display:flex;flex-direction:column;align-items:center;
1338
+ justify-content:center;gap:10px;color:var(--text3);font-size:13px}
1339
+ `;
1340
+ function L(s, e, t) {
1341
+ const i = document.createElement(s);
1342
+ return e && (i.className = e), i;
1343
+ }
1344
+ function q(s) {
1345
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1346
+ }
1347
+ function X(s, e = document.documentElement) {
1348
+ return getComputedStyle(e).getPropertyValue(s).trim();
1349
+ }
1350
+ function be(s, e) {
1351
+ const t = s.replace("#", ""), i = parseInt(t.slice(0, 2), 16), r = parseInt(t.slice(2, 4), 16), n = parseInt(t.slice(4, 6), 16);
1352
+ return `rgba(${i},${r},${n},${e})`;
1353
+ }
1354
+ function me(s) {
1355
+ return s.split(`
1356
+ `);
1357
+ }
1358
+ function D(s) {
1359
+ return s.join(`
1360
+ `);
1361
+ }
1362
+ function _e(s) {
1363
+ return (s.match(/^(\s*)/) ?? ["", ""])[1];
1364
+ }
1365
+ function J(s) {
1366
+ return " ".repeat(Math.max(0, s));
1367
+ }
1368
+ function Ae(s) {
1369
+ return /[\w$]/.test(s);
1370
+ }
1371
+ function le(s, e, t = Ae) {
1372
+ let i = e;
1373
+ for (; i > 0 && t(s[i - 1]); ) i--;
1374
+ return i;
1375
+ }
1376
+ function ce(s, e, t = Ae) {
1377
+ let i = e;
1378
+ for (; i < s.length && t(s[i]); ) i++;
1379
+ return i;
1380
+ }
1381
+ function Z(s, e) {
1382
+ let t = 0, i = null;
1383
+ return (...r) => {
1384
+ const n = Date.now(), a = e - (n - t);
1385
+ a <= 0 ? (i !== null && (clearTimeout(i), i = null), t = n, s(...r)) : i === null && (i = setTimeout(() => {
1386
+ t = Date.now(), i = null, s(...r);
1387
+ }, a));
1388
+ };
1389
+ }
1390
+ const st = {
1391
+ fontSize: [8, 72, 13],
1392
+ lineHeight: [14, 64, 22],
1393
+ tabSize: [1, 16, 2],
1394
+ wrapColumn: [20, 500, 80],
1395
+ maxCompletions: [1, 50, 14],
1396
+ autocompletePrefixLength: [1, 10, 2],
1397
+ gutterWidth: [30, 200, 60],
1398
+ minimapWidth: [60, 300, 120],
1399
+ cursorBlinkRate: [200, 5e3, 1050],
1400
+ maxUndoHistory: [10, 5e3, 300],
1401
+ undoBatchMs: [0, 5e3, 700]
1402
+ };
1403
+ function at(s, e, t, i) {
1404
+ const r = Number(s);
1405
+ return Number.isFinite(r) ? Math.max(e, Math.min(t, Math.round(r))) : i;
1406
+ }
1407
+ function ye(s) {
1408
+ const e = { ...s };
1409
+ for (const [t, i] of Object.entries(st))
1410
+ if (t in s && s[t] !== void 0) {
1411
+ const [r, n, a] = i;
1412
+ e[t] = at(s[t], r, n, a);
1413
+ }
1414
+ return e;
1415
+ }
1416
+ const Q = { "(": ")", "{": "}", "[": "]" }, ee = { ")": "(", "}": "{", "]": "[" };
1417
+ function ot(s, e) {
1418
+ const { row: t, col: i } = e, r = s[t] ?? "";
1419
+ let n = r[i], a = i;
1420
+ if (!Q[n] && !ee[n] && (n = r[i - 1], a = i - 1), !n) return null;
1421
+ if (Q[n]) {
1422
+ const l = Q[n];
1423
+ let o = 0;
1424
+ for (let c = t; c < Math.min(s.length, t + 500); c++) {
1425
+ const d = s[c] ?? "", p = c === t ? a : 0;
1426
+ for (let h = p; h < d.length; h++)
1427
+ if (d[h] === n) o++;
1428
+ else if (d[h] === l && (o--, o === 0))
1429
+ return {
1430
+ open: { row: t, col: a },
1431
+ close: { row: c, col: h }
1432
+ };
1433
+ }
1434
+ } else if (ee[n]) {
1435
+ const l = ee[n];
1436
+ let o = 0;
1437
+ for (let c = t; c >= Math.max(0, t - 500); c--) {
1438
+ const d = s[c] ?? "", p = c === t ? a : d.length - 1;
1439
+ for (let h = p; h >= 0; h--)
1440
+ if (d[h] === n) o++;
1441
+ else if (d[h] === l && (o--, o === 0))
1442
+ return {
1443
+ open: { row: c, col: h },
1444
+ close: { row: t, col: a }
1445
+ };
1446
+ }
1447
+ }
1448
+ return null;
1449
+ }
1450
+ function lt(s, e) {
1451
+ const t = s[e] ?? "";
1452
+ let i = 0;
1453
+ for (const r of t)
1454
+ r === "{" ? i++ : r === "}" && i--;
1455
+ return i > 0;
1456
+ }
1457
+ function ct(s, e) {
1458
+ let t = 0;
1459
+ for (let i = e; i < s.length; i++)
1460
+ for (const r of s[i] ?? "")
1461
+ if (r === "{") t++;
1462
+ else if (r === "}" && (t--, t === 0))
1463
+ return i;
1464
+ return null;
1465
+ }
1466
+ function dt(s, e, t) {
1467
+ const i = new Map(s);
1468
+ if (i.has(t))
1469
+ i.delete(t);
1470
+ else {
1471
+ const r = ct(e, t);
1472
+ r !== null && r > t && i.set(t, r);
1473
+ }
1474
+ return i;
1475
+ }
1476
+ const ht = /* @__PURE__ */ new Set([
1477
+ "img",
1478
+ "input",
1479
+ "br",
1480
+ "hr",
1481
+ "meta",
1482
+ "link",
1483
+ "area",
1484
+ "base",
1485
+ "col",
1486
+ "embed",
1487
+ "param",
1488
+ "source",
1489
+ "track",
1490
+ "wbr"
1491
+ ]);
1492
+ function ve(s) {
1493
+ const e = s.trim();
1494
+ if (!e) return null;
1495
+ try {
1496
+ const t = re(e);
1497
+ return t === e ? null : t;
1498
+ } catch {
1499
+ return null;
1500
+ }
1501
+ }
1502
+ function re(s) {
1503
+ if (s.includes(">")) {
1504
+ const t = s.indexOf(">");
1505
+ return te(s.slice(0, t), re(s.slice(t + 1)));
1506
+ }
1507
+ if (s.includes("+"))
1508
+ return s.split("+").map((t) => re(t.trim())).join(`
1509
+ `);
1510
+ const e = s.match(/^(.+)\*(\d+)$/);
1511
+ if (e) {
1512
+ const t = parseInt(e[2], 10);
1513
+ return Array.from({ length: t }, (i, r) => te(e[1], `$${r + 1}`)).join(`
1514
+ `);
1515
+ }
1516
+ return te(s, "$1");
1517
+ }
1518
+ function te(s, e) {
1519
+ const t = s.match(/#([\w-]+)/), i = s.match(/\.([\w.-]+)/g), r = s.match(/\[([^\]]+)\]/);
1520
+ let n = s.replace(/#[\w-]+/g, "").replace(/\.[\w.-]+/g, "").replace(/\[[^\]]+\]/g, "").trim() || "div", a = "";
1521
+ return t && (a += ` id="${t[1]}"`), i && (a += ` class="${i.map((l) => l.slice(1)).join(" ")}"`), r && (a += ` ${r[1]}`), ht.has(n) ? `<${n}${a}>` : `<${n}${a}>${e}</${n}>`;
1522
+ }
1523
+ function we(s, e) {
1524
+ let t = e;
1525
+ for (; t > 0 && /[\w#.[\]*>+{}()$@:-]/.test(s[t - 1]); ) t--;
1526
+ const i = s.slice(t, e);
1527
+ return i.length < 2 ? null : { abbr: i, start: t };
1528
+ }
1529
+ const pt = [
1530
+ {
1531
+ label: "fn",
1532
+ kind: "snip",
1533
+ detail: "function declaration",
1534
+ description: `Declares a named function.
1535
+
1536
+ function name(params) {
1537
+ // body
1538
+ }`,
1539
+ body: `function $1($2) {
1540
+ $3
1541
+ }`
1542
+ },
1543
+ {
1544
+ label: "afn",
1545
+ kind: "snip",
1546
+ detail: "arrow function",
1547
+ description: `Declares a const arrow function.
1548
+
1549
+ const name = (params) => {
1550
+ // body
1551
+ };`,
1552
+ body: `const $1 = ($2) => {
1553
+ $3
1554
+ };`
1555
+ },
1556
+ {
1557
+ label: "asyncfn",
1558
+ kind: "snip",
1559
+ detail: "async function",
1560
+ description: `Declares an async function returning a Promise.
1561
+
1562
+ async function name(params): Promise<T> {
1563
+ // body
1564
+ }`,
1565
+ body: `async function $1($2): Promise<$3> {
1566
+ $4
1567
+ }`
1568
+ },
1569
+ {
1570
+ label: "cl",
1571
+ kind: "snip",
1572
+ detail: "class declaration",
1573
+ description: `Declares a class with a constructor.
1574
+
1575
+ class Name {
1576
+ constructor(params) { ... }
1577
+ }`,
1578
+ body: `class $1 {
1579
+ constructor($2) {
1580
+ $3
1581
+ }
1582
+ }`
1583
+ },
1584
+ {
1585
+ label: "forof",
1586
+ kind: "snip",
1587
+ detail: "for…of loop",
1588
+ description: `Iterates over the values of an iterable (array, string, Map, etc.).
1589
+
1590
+ for (const item of iterable) { ... }`,
1591
+ body: `for (const $1 of $2) {
1592
+ $3
1593
+ }`
1594
+ },
1595
+ {
1596
+ label: "forin",
1597
+ kind: "snip",
1598
+ detail: "for…in loop",
1599
+ description: `Iterates over the enumerable property keys of an object.
1600
+
1601
+ for (const key in object) { ... }`,
1602
+ body: `for (const $1 in $2) {
1603
+ $3
1604
+ }`
1605
+ },
1606
+ {
1607
+ label: "trycatch",
1608
+ kind: "snip",
1609
+ detail: "try / catch block",
1610
+ description: `Wraps code in a try/catch to handle runtime errors.
1611
+
1612
+ try {
1613
+ ...
1614
+ } catch (error) {
1615
+ ...
1616
+ }`,
1617
+ body: `try {
1618
+ $1
1619
+ } catch ($2error) {
1620
+ $3
1621
+ }`
1622
+ },
1623
+ {
1624
+ label: "promise",
1625
+ kind: "snip",
1626
+ detail: "new Promise",
1627
+ description: `Creates a new Promise with resolve and reject handlers.
1628
+
1629
+ new Promise<T>((resolve, reject) => { ... })`,
1630
+ body: `new Promise<$1>((resolve, reject) => {
1631
+ $2
1632
+ })`
1633
+ },
1634
+ {
1635
+ label: "imp",
1636
+ kind: "snip",
1637
+ detail: "import statement",
1638
+ description: `Adds a named import from a module.
1639
+
1640
+ import { name } from 'module';`,
1641
+ body: "import { $1 } from '$2';"
1642
+ },
1643
+ {
1644
+ label: "iface",
1645
+ kind: "snip",
1646
+ detail: "interface (TypeScript)",
1647
+ description: `Declares a TypeScript interface.
1648
+
1649
+ interface Name {
1650
+ field: Type;
1651
+ }`,
1652
+ body: `interface $1 {
1653
+ $2: $3;
1654
+ }`,
1655
+ language: ["typescript"]
1656
+ },
1657
+ {
1658
+ label: "ife",
1659
+ kind: "snip",
1660
+ detail: "immediately-invoked function expression",
1661
+ description: `An IIFE — defines and immediately calls a function.
1662
+
1663
+ ((params) => {
1664
+ ...
1665
+ })(args);`,
1666
+ body: `(($1) => {
1667
+ $2
1668
+ })($3);`
1669
+ },
1670
+ {
1671
+ label: "sw",
1672
+ kind: "snip",
1673
+ detail: "switch statement",
1674
+ description: `A switch/case statement with a default branch.
1675
+
1676
+ switch (expr) {
1677
+ case value:
1678
+ ...
1679
+ break;
1680
+ default:
1681
+ ...
1682
+ }`,
1683
+ body: `switch ($1) {
1684
+ case $2:
1685
+ $3
1686
+ break;
1687
+ default:
1688
+ $4
1689
+ }`
1690
+ }
1691
+ ], ut = [
1692
+ {
1693
+ label: "flex",
1694
+ kind: "snip",
1695
+ detail: "flexbox container",
1696
+ description: `Sets up a flex container with centered alignment.
1697
+
1698
+ display: flex;
1699
+ align-items: center;
1700
+ justify-content: center;`,
1701
+ body: `display: flex;
1702
+ align-items: $1center;
1703
+ justify-content: $2center;`,
1704
+ language: ["css"]
1705
+ },
1706
+ {
1707
+ label: "grid",
1708
+ kind: "snip",
1709
+ detail: "CSS grid",
1710
+ description: `Sets up a CSS grid with equal columns and gap.
1711
+
1712
+ display: grid;
1713
+ grid-template-columns: repeat(3, 1fr);
1714
+ gap: 16px;`,
1715
+ body: `display: grid;
1716
+ grid-template-columns: $1repeat(3, 1fr);
1717
+ gap: $2;`,
1718
+ language: ["css"]
1719
+ },
1720
+ {
1721
+ label: "media",
1722
+ kind: "snip",
1723
+ detail: "@media query",
1724
+ description: `A responsive media query breakpoint.
1725
+
1726
+ @media (max-width: 768px) {
1727
+ ...
1728
+ }`,
1729
+ body: `@media ($1max-width: 768px) {
1730
+ $2
1731
+ }`,
1732
+ language: ["css"]
1733
+ },
1734
+ {
1735
+ label: "anim",
1736
+ kind: "snip",
1737
+ detail: "@keyframes animation",
1738
+ description: `A CSS keyframes animation block.
1739
+
1740
+ @keyframes name {
1741
+ from { ... }
1742
+ to { ... }
1743
+ }`,
1744
+ body: `@keyframes $1 {
1745
+ from { $2 }
1746
+ to { $3 }
1747
+ }`,
1748
+ language: ["css"]
1749
+ },
1750
+ {
1751
+ label: "var",
1752
+ kind: "snip",
1753
+ detail: "CSS custom property",
1754
+ description: `Declares a CSS custom property (variable).
1755
+
1756
+ --name: value;`,
1757
+ body: "--$1: $2;",
1758
+ language: ["css"]
1759
+ }
1760
+ ], ft = [
1761
+ {
1762
+ label: "accordion",
1763
+ kind: "snip",
1764
+ detail: "HTML details/summary",
1765
+ description: `An accessible accordion using the native <details> and <summary> elements.
1766
+
1767
+ <details>
1768
+ <summary>Title</summary>
1769
+ <div>content</div>
1770
+ </details>`,
1771
+ body: `<details>
1772
+ <summary>$1Title</summary>
1773
+ <div>
1774
+ $2
1775
+ </div>
1776
+ </details>`
1777
+ },
1778
+ {
1779
+ label: "card",
1780
+ kind: "snip",
1781
+ detail: "card component",
1782
+ description: "A generic card component with header, body, and footer sections.",
1783
+ body: `<div class="card">
1784
+ <div class="card-header">$1</div>
1785
+ <div class="card-body">$2</div>
1786
+ <div class="card-footer">$3</div>
1787
+ </div>`
1788
+ },
1789
+ {
1790
+ label: "navbar",
1791
+ kind: "snip",
1792
+ detail: "navigation bar",
1793
+ description: `A simple navigation bar with anchor links.
1794
+
1795
+ <nav class="navbar">
1796
+ <a href="#">Home</a> ...
1797
+ </nav>`,
1798
+ body: `<nav class="navbar">
1799
+ <a href="$1#">Home</a>
1800
+ <a href="$2#">About</a>
1801
+ <a href="$3#">Contact</a>
1802
+ </nav>`
1803
+ },
1804
+ {
1805
+ label: "modal",
1806
+ kind: "snip",
1807
+ detail: "modal dialog",
1808
+ description: `A modal dialog layout with header, body, and footer.
1809
+
1810
+ <div class="modal">
1811
+ <div class="modal-dialog"> ... </div>
1812
+ </div>`,
1813
+ body: `<div class="modal">
1814
+ <div class="modal-dialog">
1815
+ <div class="modal-header">$1</div>
1816
+ <div class="modal-body">$2</div>
1817
+ <div class="modal-footer">$3</div>
1818
+ </div>
1819
+ </div>`
1820
+ },
1821
+ {
1822
+ label: "table",
1823
+ kind: "snip",
1824
+ detail: "HTML table",
1825
+ description: `A semantic HTML table with thead and tbody.
1826
+
1827
+ <table>
1828
+ <thead><tr><th>...</th></tr></thead>
1829
+ <tbody><tr><td>...</td></tr></tbody>
1830
+ </table>`,
1831
+ body: `<table>
1832
+ <thead>
1833
+ <tr>
1834
+ <th>$1</th>
1835
+ </tr>
1836
+ </thead>
1837
+ <tbody>
1838
+ <tr>
1839
+ <td>$2</td>
1840
+ </tr>
1841
+ </tbody>
1842
+ </table>`
1843
+ }
1844
+ ];
1845
+ function gt(s) {
1846
+ const e = [...ft];
1847
+ return (s === "typescript" || s === "javascript") && e.push(...pt.filter((t) => !t.language || (Array.isArray(t.language) ? t.language.includes(s) : t.language === s))), s === "css" && e.push(...ut), e;
1848
+ }
1849
+ function bt(s, e, t) {
1850
+ let i = e;
1851
+ for (; i > 0 && /\w/.test(s[i - 1]); ) i--;
1852
+ const r = s.slice(i, e);
1853
+ if (!r) return null;
1854
+ const n = t.find((a) => a.kind === "snip" && a.label === r);
1855
+ return n ? { snippet: n, start: i } : null;
1856
+ }
1857
+ function mt() {
1858
+ return { cursors: [], searchWord: "", lastMatchRow: -1, lastMatchCol: -1 };
1859
+ }
1860
+ function ke(s, e, t, i) {
1861
+ s.cursors.some((n) => n.row === e && n.col === t) || s.cursors.push({ row: e, col: t, sel: i });
1862
+ }
1863
+ function xe(s) {
1864
+ s.cursors = [], s.searchWord = "", s.lastMatchRow = -1, s.lastMatchCol = -1;
1865
+ }
1866
+ function _t(s, e, t, i, r) {
1867
+ const n = [
1868
+ { row: e, col: t, isPrimary: !0, idx: 0 },
1869
+ ...i.map((d, p) => ({ row: d.row, col: d.col, isPrimary: !1, idx: p + 1 }))
1870
+ ];
1871
+ n.sort((d, p) => p.row !== d.row ? p.row - d.row : p.col - d.col);
1872
+ const a = s.map((d) => d);
1873
+ let l = e, o = t;
1874
+ const c = i.map((d) => ({ ...d }));
1875
+ for (const d of n) {
1876
+ const p = a[d.row] ?? "";
1877
+ a[d.row] = p.slice(0, d.col) + r + p.slice(d.col);
1878
+ for (const h of n)
1879
+ h !== d && h.row === d.row && h.col >= d.col && (h.col += r.length);
1880
+ d.col += r.length, d.isPrimary ? (l = d.row, o = d.col) : (c[d.idx - 1].row = d.row, c[d.idx - 1].col = d.col);
1881
+ }
1882
+ return { doc: a, primaryRow: l, primaryCol: o, extraCursors: c };
1883
+ }
1884
+ function yt(s, e, t, i) {
1885
+ const r = [
1886
+ { row: e, col: t, isPrimary: !0, idx: 0 },
1887
+ ...i.map((c, d) => ({ row: c.row, col: c.col, isPrimary: !1, idx: d + 1 }))
1888
+ ];
1889
+ r.sort((c, d) => d.row !== c.row ? d.row - c.row : d.col - c.col);
1890
+ const n = s.map((c) => c);
1891
+ let a = e, l = t;
1892
+ const o = i.map((c) => ({ ...c }));
1893
+ for (const c of r) {
1894
+ if (c.col <= 0) continue;
1895
+ const d = n[c.row] ?? "";
1896
+ n[c.row] = d.slice(0, c.col - 1) + d.slice(c.col);
1897
+ for (const p of r)
1898
+ p !== c && p.row === c.row && p.col > c.col && p.col--;
1899
+ c.col--, c.isPrimary ? (a = c.row, l = c.col) : o[c.idx - 1].col = c.col;
1900
+ }
1901
+ return { doc: n, primaryRow: a, primaryCol: l, extraCursors: o };
1902
+ }
1903
+ function vt(s, e, t, i, r) {
1904
+ let n = s.searchWord;
1905
+ if (!n) {
1906
+ if (r && r.ar === r.fr && (n = (e[r.ar] ?? "").slice(r.ac, r.fc)), !n) {
1907
+ const o = e[t] ?? "", c = le(o, i), d = ce(o, i);
1908
+ n = o.slice(c, d);
1909
+ }
1910
+ if (!n) return null;
1911
+ s.searchWord = n, s.lastMatchRow = t, s.lastMatchCol = i;
1912
+ }
1913
+ const a = s.lastMatchRow, l = s.lastMatchCol;
1914
+ for (let o = a; o < e.length; o++) {
1915
+ const c = e[o] ?? "";
1916
+ let p = o === a ? l : 0;
1917
+ for (; p <= c.length - n.length; ) {
1918
+ const h = c.indexOf(n, p);
1919
+ if (h < 0) break;
1920
+ const g = h === 0 || !/\w/.test(c[h - 1]), y = h + n.length >= c.length || !/\w/.test(c[h + n.length]);
1921
+ if (g && y)
1922
+ return s.lastMatchRow = o, s.lastMatchCol = h + n.length, {
1923
+ word: n,
1924
+ sel: { ar: o, ac: h, fr: o, fc: h + n.length },
1925
+ row: o,
1926
+ col: h + n.length
1927
+ };
1928
+ p = h + 1;
1929
+ }
1930
+ }
1931
+ for (let o = 0; o <= a; o++) {
1932
+ const c = e[o] ?? "", d = o === a ? l : c.length;
1933
+ let p = 0;
1934
+ for (; p < d; ) {
1935
+ const h = c.indexOf(n, p);
1936
+ if (h < 0 || h >= d) break;
1937
+ const g = h === 0 || !/\w/.test(c[h - 1]), y = h + n.length >= c.length || !/\w/.test(c[h + n.length]);
1938
+ if (g && y)
1939
+ return s.lastMatchRow = o, s.lastMatchCol = h + n.length, {
1940
+ word: n,
1941
+ sel: { ar: o, ac: h, fr: o, fc: h + n.length },
1942
+ row: o,
1943
+ col: h + n.length
1944
+ };
1945
+ p = h + 1;
1946
+ }
1947
+ }
1948
+ return null;
1949
+ }
1950
+ function wt(s, e, t) {
1951
+ if (!e) return [];
1952
+ const i = [];
1953
+ for (let r = 0; r < s.length; r++) {
1954
+ const n = s[r] ?? "";
1955
+ if (t.useRegex)
1956
+ try {
1957
+ const a = new RegExp(e, t.caseSensitive ? "g" : "gi");
1958
+ let l;
1959
+ for (; (l = a.exec(n)) !== null && (i.push({ row: r, col: l.index, len: l[0].length }), !!l[0].length); )
1960
+ ;
1961
+ } catch {
1962
+ }
1963
+ else {
1964
+ const a = t.caseSensitive ? n : n.toLowerCase(), l = t.caseSensitive ? e : e.toLowerCase();
1965
+ let o = 0;
1966
+ for (; ; ) {
1967
+ const c = a.indexOf(l, o);
1968
+ if (c === -1) break;
1969
+ i.push({ row: r, col: c, len: e.length }), o = c + 1;
1970
+ }
1971
+ }
1972
+ }
1973
+ return i;
1974
+ }
1975
+ function kt(s, e, t, i) {
1976
+ const r = e[t];
1977
+ if (!r) return s;
1978
+ const n = [...s], a = n[r.row] ?? "";
1979
+ return n[r.row] = a.slice(0, r.col) + i + a.slice(r.col + r.len), n;
1980
+ }
1981
+ function xt(s, e, t) {
1982
+ const i = [...s];
1983
+ for (let r = e.length - 1; r >= 0; r--) {
1984
+ const n = e[r], a = i[n.row] ?? "";
1985
+ i[n.row] = a.slice(0, n.col) + t + a.slice(n.col + n.len);
1986
+ }
1987
+ return i;
1988
+ }
1989
+ function Tt(s, e, t) {
1990
+ return s.length ? (e + t + s.length) % s.length : -1;
1991
+ }
1992
+ function Ct(s, e, t, i) {
1993
+ if (i) return [];
1994
+ const r = s[e] ?? "", n = le(r, t), a = ce(r, t), l = r.slice(n, a);
1995
+ if (!l || l.length < 2) return [];
1996
+ const o = [];
1997
+ for (let c = 0; c < s.length; c++) {
1998
+ const d = s[c] ?? "";
1999
+ let p = 0;
2000
+ for (; p <= d.length - l.length; ) {
2001
+ const h = d.indexOf(l, p);
2002
+ if (h < 0) break;
2003
+ const g = h === 0 || !/\w/.test(d[h - 1]), y = h + l.length >= d.length || !/\w/.test(d[h + l.length]);
2004
+ g && y && !(c === e && h === n) && o.push({ row: c, col: h, len: l.length }), p = h + 1;
2005
+ }
2006
+ }
2007
+ return o;
2008
+ }
2009
+ const ne = [
2010
+ { label: "console.log", kind: "fn", detail: "void" },
2011
+ { label: "console.error", kind: "fn", detail: "void" },
2012
+ { label: "console.warn", kind: "fn", detail: "void" },
2013
+ { label: "console.info", kind: "fn", detail: "void" },
2014
+ { label: "console.table", kind: "fn", detail: "void" },
2015
+ { label: "document.getElementById", kind: "fn", detail: "HTMLElement | null" },
2016
+ { label: "document.querySelector", kind: "fn", detail: "Element | null" },
2017
+ { label: "document.querySelectorAll", kind: "fn", detail: "NodeList" },
2018
+ { label: "document.createElement", kind: "fn", detail: "HTMLElement" },
2019
+ { label: "document.createTextNode", kind: "fn", detail: "Text" },
2020
+ { label: "addEventListener", kind: "fn", detail: "(ev, cb) => void" },
2021
+ { label: "removeEventListener", kind: "fn", detail: "(ev, cb) => void" },
2022
+ { label: "requestAnimationFrame", kind: "fn", detail: "(cb) => number" },
2023
+ { label: "cancelAnimationFrame", kind: "fn", detail: "(id) => void" },
2024
+ { label: "setTimeout", kind: "fn", detail: "(cb, ms) => id" },
2025
+ { label: "clearTimeout", kind: "fn", detail: "(id) => void" },
2026
+ { label: "setInterval", kind: "fn", detail: "(cb, ms) => id" },
2027
+ { label: "clearInterval", kind: "fn", detail: "(id) => void" },
2028
+ { label: "JSON.stringify", kind: "fn", detail: "string" },
2029
+ { label: "JSON.parse", kind: "fn", detail: "any" },
2030
+ { label: "Math.max", kind: "fn", detail: "number" },
2031
+ { label: "Math.min", kind: "fn", detail: "number" },
2032
+ { label: "Math.floor", kind: "fn", detail: "number" },
2033
+ { label: "Math.ceil", kind: "fn", detail: "number" },
2034
+ { label: "Math.round", kind: "fn", detail: "number" },
2035
+ { label: "Math.abs", kind: "fn", detail: "number" },
2036
+ { label: "Math.pow", kind: "fn", detail: "number" },
2037
+ { label: "Math.sqrt", kind: "fn", detail: "number" },
2038
+ { label: "Math.random", kind: "fn", detail: "number" },
2039
+ { label: "Object.keys", kind: "fn", detail: "string[]" },
2040
+ { label: "Object.values", kind: "fn", detail: "any[]" },
2041
+ { label: "Object.entries", kind: "fn", detail: "[string, any][]" },
2042
+ { label: "Object.assign", kind: "fn", detail: "T & U" },
2043
+ { label: "Object.freeze", kind: "fn", detail: "Readonly<T>" },
2044
+ { label: "Object.create", kind: "fn", detail: "object" },
2045
+ { label: "Array.from", kind: "fn", detail: "T[]" },
2046
+ { label: "Array.isArray", kind: "fn", detail: "boolean" },
2047
+ { label: "Promise.all", kind: "fn", detail: "Promise<T[]>" },
2048
+ { label: "Promise.resolve", kind: "fn", detail: "Promise<T>" },
2049
+ { label: "Promise.reject", kind: "fn", detail: "Promise<never>" },
2050
+ { label: "Promise.allSettled", kind: "fn", detail: "Promise<...>" },
2051
+ { label: "parseInt", kind: "fn", detail: "number" },
2052
+ { label: "parseFloat", kind: "fn", detail: "number" },
2053
+ { label: "isNaN", kind: "fn", detail: "boolean" },
2054
+ { label: "isFinite", kind: "fn", detail: "boolean" },
2055
+ { label: "encodeURIComponent", kind: "fn", detail: "string" },
2056
+ { label: "decodeURIComponent", kind: "fn", detail: "string" },
2057
+ { label: "structuredClone", kind: "fn", detail: "T" },
2058
+ { label: "queueMicrotask", kind: "fn", detail: "void" },
2059
+ { label: "fetch", kind: "fn", detail: "Promise<Response>" }
2060
+ ], Mt = [
2061
+ // ── Layout ────────────────────────────────────────────────
2062
+ { label: "display", kind: "var", detail: "property" },
2063
+ { label: "position", kind: "var", detail: "property" },
2064
+ { label: "top", kind: "var", detail: "property" },
2065
+ { label: "right", kind: "var", detail: "property" },
2066
+ { label: "bottom", kind: "var", detail: "property" },
2067
+ { label: "left", kind: "var", detail: "property" },
2068
+ { label: "width", kind: "var", detail: "property" },
2069
+ { label: "height", kind: "var", detail: "property" },
2070
+ { label: "min-width", kind: "var", detail: "property" },
2071
+ { label: "max-width", kind: "var", detail: "property" },
2072
+ { label: "min-height", kind: "var", detail: "property" },
2073
+ { label: "max-height", kind: "var", detail: "property" },
2074
+ { label: "z-index", kind: "var", detail: "property" },
2075
+ { label: "overflow", kind: "var", detail: "property" },
2076
+ { label: "overflow-x", kind: "var", detail: "property" },
2077
+ { label: "overflow-y", kind: "var", detail: "property" },
2078
+ { label: "box-sizing", kind: "var", detail: "property" },
2079
+ // ── Flexbox ───────────────────────────────────────────────
2080
+ { label: "flex", kind: "var", detail: "property" },
2081
+ { label: "flex-direction", kind: "var", detail: "property" },
2082
+ { label: "flex-wrap", kind: "var", detail: "property" },
2083
+ { label: "flex-grow", kind: "var", detail: "property" },
2084
+ { label: "flex-shrink", kind: "var", detail: "property" },
2085
+ { label: "flex-basis", kind: "var", detail: "property" },
2086
+ { label: "flex-flow", kind: "var", detail: "property" },
2087
+ { label: "align-items", kind: "var", detail: "property" },
2088
+ { label: "align-content", kind: "var", detail: "property" },
2089
+ { label: "align-self", kind: "var", detail: "property" },
2090
+ { label: "justify-content", kind: "var", detail: "property" },
2091
+ { label: "justify-items", kind: "var", detail: "property" },
2092
+ { label: "justify-self", kind: "var", detail: "property" },
2093
+ { label: "gap", kind: "var", detail: "property" },
2094
+ { label: "row-gap", kind: "var", detail: "property" },
2095
+ { label: "column-gap", kind: "var", detail: "property" },
2096
+ // ── Grid ──────────────────────────────────────────────────
2097
+ { label: "grid", kind: "var", detail: "property" },
2098
+ { label: "grid-template", kind: "var", detail: "property" },
2099
+ { label: "grid-template-columns", kind: "var", detail: "property" },
2100
+ { label: "grid-template-rows", kind: "var", detail: "property" },
2101
+ { label: "grid-template-areas", kind: "var", detail: "property" },
2102
+ { label: "grid-column", kind: "var", detail: "property" },
2103
+ { label: "grid-row", kind: "var", detail: "property" },
2104
+ { label: "grid-area", kind: "var", detail: "property" },
2105
+ { label: "grid-auto-flow", kind: "var", detail: "property" },
2106
+ // ── Spacing ───────────────────────────────────────────────
2107
+ { label: "margin", kind: "var", detail: "property" },
2108
+ { label: "margin-top", kind: "var", detail: "property" },
2109
+ { label: "margin-right", kind: "var", detail: "property" },
2110
+ { label: "margin-bottom", kind: "var", detail: "property" },
2111
+ { label: "margin-left", kind: "var", detail: "property" },
2112
+ { label: "padding", kind: "var", detail: "property" },
2113
+ { label: "padding-top", kind: "var", detail: "property" },
2114
+ { label: "padding-right", kind: "var", detail: "property" },
2115
+ { label: "padding-bottom", kind: "var", detail: "property" },
2116
+ { label: "padding-left", kind: "var", detail: "property" },
2117
+ // ── Typography ────────────────────────────────────────────
2118
+ { label: "color", kind: "var", detail: "property" },
2119
+ { label: "font", kind: "var", detail: "property" },
2120
+ { label: "font-family", kind: "var", detail: "property" },
2121
+ { label: "font-size", kind: "var", detail: "property" },
2122
+ { label: "font-weight", kind: "var", detail: "property" },
2123
+ { label: "font-style", kind: "var", detail: "property" },
2124
+ { label: "line-height", kind: "var", detail: "property" },
2125
+ { label: "text-align", kind: "var", detail: "property" },
2126
+ { label: "text-decoration", kind: "var", detail: "property" },
2127
+ { label: "text-transform", kind: "var", detail: "property" },
2128
+ { label: "letter-spacing", kind: "var", detail: "property" },
2129
+ { label: "word-spacing", kind: "var", detail: "property" },
2130
+ { label: "white-space", kind: "var", detail: "property" },
2131
+ { label: "word-break", kind: "var", detail: "property" },
2132
+ { label: "word-wrap", kind: "var", detail: "property" },
2133
+ { label: "text-overflow", kind: "var", detail: "property" },
2134
+ // ── Background ────────────────────────────────────────────
2135
+ { label: "background", kind: "var", detail: "property" },
2136
+ { label: "background-color", kind: "var", detail: "property" },
2137
+ { label: "background-image", kind: "var", detail: "property" },
2138
+ { label: "background-size", kind: "var", detail: "property" },
2139
+ { label: "background-position", kind: "var", detail: "property" },
2140
+ { label: "background-repeat", kind: "var", detail: "property" },
2141
+ { label: "background-clip", kind: "var", detail: "property" },
2142
+ { label: "background-attachment", kind: "var", detail: "property" },
2143
+ // ── Border ────────────────────────────────────────────────
2144
+ { label: "border", kind: "var", detail: "property" },
2145
+ { label: "border-width", kind: "var", detail: "property" },
2146
+ { label: "border-style", kind: "var", detail: "property" },
2147
+ { label: "border-color", kind: "var", detail: "property" },
2148
+ { label: "border-radius", kind: "var", detail: "property" },
2149
+ { label: "border-top", kind: "var", detail: "property" },
2150
+ { label: "border-right", kind: "var", detail: "property" },
2151
+ { label: "border-bottom", kind: "var", detail: "property" },
2152
+ { label: "border-left", kind: "var", detail: "property" },
2153
+ { label: "outline", kind: "var", detail: "property" },
2154
+ { label: "outline-width", kind: "var", detail: "property" },
2155
+ { label: "outline-style", kind: "var", detail: "property" },
2156
+ { label: "outline-color", kind: "var", detail: "property" },
2157
+ { label: "outline-offset", kind: "var", detail: "property" },
2158
+ // ── Effects ───────────────────────────────────────────────
2159
+ { label: "opacity", kind: "var", detail: "property" },
2160
+ { label: "box-shadow", kind: "var", detail: "property" },
2161
+ { label: "text-shadow", kind: "var", detail: "property" },
2162
+ { label: "filter", kind: "var", detail: "property" },
2163
+ { label: "backdrop-filter", kind: "var", detail: "property" },
2164
+ { label: "transform", kind: "var", detail: "property" },
2165
+ { label: "transform-origin", kind: "var", detail: "property" },
2166
+ { label: "transition", kind: "var", detail: "property" },
2167
+ { label: "animation", kind: "var", detail: "property" },
2168
+ { label: "animation-name", kind: "var", detail: "property" },
2169
+ { label: "animation-duration", kind: "var", detail: "property" },
2170
+ { label: "animation-timing-function", kind: "var", detail: "property" },
2171
+ { label: "animation-delay", kind: "var", detail: "property" },
2172
+ { label: "animation-iteration-count", kind: "var", detail: "property" },
2173
+ { label: "animation-fill-mode", kind: "var", detail: "property" },
2174
+ // ── Interaction ───────────────────────────────────────────
2175
+ { label: "cursor", kind: "var", detail: "property" },
2176
+ { label: "pointer-events", kind: "var", detail: "property" },
2177
+ { label: "user-select", kind: "var", detail: "property" },
2178
+ { label: "resize", kind: "var", detail: "property" },
2179
+ // ── Misc ──────────────────────────────────────────────────
2180
+ { label: "visibility", kind: "var", detail: "property" },
2181
+ { label: "content", kind: "var", detail: "property" },
2182
+ { label: "list-style", kind: "var", detail: "property" },
2183
+ { label: "will-change", kind: "var", detail: "property" },
2184
+ { label: "appearance", kind: "var", detail: "property" },
2185
+ { label: "clip-path", kind: "var", detail: "property" },
2186
+ { label: "object-fit", kind: "var", detail: "property" },
2187
+ { label: "object-position", kind: "var", detail: "property" },
2188
+ { label: "scroll-behavior", kind: "var", detail: "property" },
2189
+ { label: "aspect-ratio", kind: "var", detail: "property" },
2190
+ // ── CSS functions ─────────────────────────────────────────
2191
+ { label: "var", kind: "fn", detail: "css fn" },
2192
+ { label: "calc", kind: "fn", detail: "css fn" },
2193
+ { label: "min", kind: "fn", detail: "css fn" },
2194
+ { label: "max", kind: "fn", detail: "css fn" },
2195
+ { label: "clamp", kind: "fn", detail: "css fn" },
2196
+ { label: "rgb", kind: "fn", detail: "css fn" },
2197
+ { label: "rgba", kind: "fn", detail: "css fn" },
2198
+ { label: "hsl", kind: "fn", detail: "css fn" },
2199
+ { label: "hsla", kind: "fn", detail: "css fn" },
2200
+ { label: "oklch", kind: "fn", detail: "css fn" },
2201
+ { label: "linear-gradient", kind: "fn", detail: "css fn" },
2202
+ { label: "radial-gradient", kind: "fn", detail: "css fn" },
2203
+ { label: "conic-gradient", kind: "fn", detail: "css fn" },
2204
+ { label: "translate", kind: "fn", detail: "css fn" },
2205
+ { label: "scale", kind: "fn", detail: "css fn" },
2206
+ { label: "rotate", kind: "fn", detail: "css fn" },
2207
+ { label: "skew", kind: "fn", detail: "css fn" },
2208
+ { label: "matrix", kind: "fn", detail: "css fn" },
2209
+ { label: "perspective", kind: "fn", detail: "css fn" },
2210
+ { label: "url", kind: "fn", detail: "css fn" },
2211
+ { label: "attr", kind: "fn", detail: "css fn" },
2212
+ { label: "env", kind: "fn", detail: "css fn" },
2213
+ { label: "repeat", kind: "fn", detail: "css fn" },
2214
+ { label: "minmax", kind: "fn", detail: "css fn" },
2215
+ { label: "fit-content", kind: "fn", detail: "css fn" }
2216
+ ], Et = {
2217
+ typescript: ne,
2218
+ javascript: ne,
2219
+ css: Mt,
2220
+ json: [],
2221
+ markdown: [],
2222
+ text: []
2223
+ };
2224
+ function Te(s, e, t) {
2225
+ const i = Ee[s] ?? se, r = Se[s] ?? ae, n = Et[s] ?? ne;
2226
+ return [
2227
+ ...[...i, ...e].map((a) => ({ label: a, kind: "kw", detail: "keyword" })),
2228
+ ...[...r, ...t].map((a) => ({ label: a, kind: "typ", detail: "type" })),
2229
+ ...n
2230
+ ];
2231
+ }
2232
+ function St(s, e) {
2233
+ const t = /* @__PURE__ */ new Set();
2234
+ for (const i of s) {
2235
+ const r = i.match(/[a-zA-Z_$][\w$]*/g) ?? [];
2236
+ for (const n of r)
2237
+ n !== e && n.length > 2 && t.add(n);
2238
+ }
2239
+ return t;
2240
+ }
2241
+ function Ce(s, e) {
2242
+ return s.language ? Array.isArray(s.language) ? s.language.includes(e) : s.language === e : !0;
2243
+ }
2244
+ function It(s, e, t = {}, i = 0, r = 0) {
2245
+ if (e.length < 2) return [];
2246
+ const n = e.toLowerCase(), {
2247
+ language: a = "typescript",
2248
+ extraKeywords: l = [],
2249
+ extraTypes: o = [],
2250
+ completions: c = [],
2251
+ replaceBuiltins: d = !1,
2252
+ maxResults: p = 14
2253
+ } = t, h = c.filter((m) => m.kind === "snip" && !!m.body && Ce(m, a)), g = c.filter((m) => !(m.kind === "snip" && m.body) && Ce(m, a)), y = h.filter((m) => m.label.toLowerCase().startsWith(n));
2254
+ let v;
2255
+ if (t.provideCompletions) {
2256
+ const m = {
2257
+ line: s[i] ?? "",
2258
+ col: r,
2259
+ prefix: e,
2260
+ language: a,
2261
+ doc: s
2262
+ };
2263
+ let S;
2264
+ try {
2265
+ S = t.provideCompletions(m);
2266
+ } catch (I) {
2267
+ console.error("[syncline-editor] provideCompletions threw an error:", I), S = null;
2268
+ }
2269
+ v = S != null ? [...S, ...g] : [...d ? [] : Te(a, l, o), ...g];
2270
+ } else
2271
+ v = d ? g : [...Te(a, l, o), ...g];
2272
+ const f = new Set(v.map((m) => m.label)), b = v.filter(
2273
+ (m) => m.label.toLowerCase().startsWith(n) && m.label !== e
2274
+ ), T = new Set(y.map((m) => m.label)), x = [...St(s, e)].filter((m) => m.toLowerCase().startsWith(n) && !f.has(m) && !T.has(m)).slice(0, 8).map((m) => ({ label: m, kind: "var", detail: "in file" }));
2275
+ return [
2276
+ ...y,
2277
+ ...b.filter((m) => !T.has(m.label)),
2278
+ ...x
2279
+ ].slice(0, p);
2280
+ }
2281
+ function At(s, e, t = !1) {
2282
+ let i = e;
2283
+ for (; i > 0 && (t ? /[\w$.\-]/ : /[\w$.]/).test(s[i - 1]); ) i--;
2284
+ return { prefix: s.slice(i, e), start: i };
2285
+ }
2286
+ function Lt(s, e) {
2287
+ const t = (n) => /[\w$]/.test(n);
2288
+ let i = e;
2289
+ for (; i < s.length && t(s[i]); ) i++;
2290
+ let r = e;
2291
+ for (; r > 0 && t(s[r - 1]); ) r--;
2292
+ if (r === i) return "";
2293
+ if (r > 0 && s[r - 1] === ".") {
2294
+ let n = r - 1, a = n;
2295
+ for (; a > 0 && t(s[a - 1]); ) a--;
2296
+ if (a < n)
2297
+ return s.slice(a, i);
2298
+ }
2299
+ return s.slice(r, i);
2300
+ }
2301
+ const Dt = {
2302
+ // ── console ───────────────────────────────────────────────
2303
+ console: {
2304
+ title: "console",
2305
+ type: "Console",
2306
+ body: "Provides access to the browser's debugging console. Useful for logging, timing, profiling, and inspecting values during development.",
2307
+ language: ["typescript", "javascript"]
2308
+ },
2309
+ "console.log": {
2310
+ title: "console.log()",
2311
+ type: "(...data: any[]) => void",
2312
+ body: "Outputs a message to the web console. Accepts any number of arguments — objects are logged as expandable trees, primitives as their string form.",
2313
+ language: ["typescript", "javascript"]
2314
+ },
2315
+ "console.error": {
2316
+ title: "console.error()",
2317
+ type: "(...data: any[]) => void",
2318
+ body: "Logs an error message to the console, typically rendered in red with a stack trace. Use for unrecoverable failures.",
2319
+ language: ["typescript", "javascript"]
2320
+ },
2321
+ "console.warn": {
2322
+ title: "console.warn()",
2323
+ type: "(...data: any[]) => void",
2324
+ body: "Logs a warning message to the console, typically rendered in yellow. Use for non-fatal issues or deprecation notices.",
2325
+ language: ["typescript", "javascript"]
2326
+ },
2327
+ "console.info": {
2328
+ title: "console.info()",
2329
+ type: "(...data: any[]) => void",
2330
+ body: "Logs an informational message. Behaves identically to console.log in most environments.",
2331
+ language: ["typescript", "javascript"]
2332
+ },
2333
+ "console.table": {
2334
+ title: "console.table()",
2335
+ type: "(data: any, columns?: string[]) => void",
2336
+ body: "Displays an array or object as a formatted table in the console. Optionally restrict displayed columns.",
2337
+ language: ["typescript", "javascript"]
2338
+ },
2339
+ "console.time": {
2340
+ title: "console.time()",
2341
+ type: "(label?: string) => void",
2342
+ body: "Starts a timer with the given label. Call console.timeEnd() with the same label to log the elapsed time.",
2343
+ language: ["typescript", "javascript"]
2344
+ },
2345
+ "console.timeEnd": {
2346
+ title: "console.timeEnd()",
2347
+ type: "(label?: string) => void",
2348
+ body: "Stops the timer started by console.time() and logs the elapsed duration in milliseconds.",
2349
+ language: ["typescript", "javascript"]
2350
+ },
2351
+ "console.group": {
2352
+ title: "console.group()",
2353
+ type: "(...label: any[]) => void",
2354
+ body: "Creates a new inline group in the console output, indenting subsequent messages until console.groupEnd() is called.",
2355
+ language: ["typescript", "javascript"]
2356
+ },
2357
+ "console.groupEnd": {
2358
+ title: "console.groupEnd()",
2359
+ type: "() => void",
2360
+ body: "Closes the current inline group in the console, exiting the indented group created by console.group().",
2361
+ language: ["typescript", "javascript"]
2362
+ },
2363
+ // ── Math ──────────────────────────────────────────────────
2364
+ Math: {
2365
+ title: "Math",
2366
+ type: "namespace Math",
2367
+ body: "A built-in object with properties and methods for mathematical constants and functions. Not a constructor — all properties and methods are static.",
2368
+ language: ["typescript", "javascript"]
2369
+ },
2370
+ "Math.max": {
2371
+ title: "Math.max()",
2372
+ type: "(...values: number[]) => number",
2373
+ body: "Returns the largest of the given numbers. Returns -Infinity if no arguments, or NaN if any argument is not a number.",
2374
+ language: ["typescript", "javascript"]
2375
+ },
2376
+ "Math.min": {
2377
+ title: "Math.min()",
2378
+ type: "(...values: number[]) => number",
2379
+ body: "Returns the smallest of the given numbers. Returns Infinity if no arguments, or NaN if any argument is not a number.",
2380
+ language: ["typescript", "javascript"]
2381
+ },
2382
+ "Math.floor": {
2383
+ title: "Math.floor()",
2384
+ type: "(x: number) => number",
2385
+ body: "Returns the largest integer less than or equal to x. Rounds toward negative infinity.",
2386
+ language: ["typescript", "javascript"]
2387
+ },
2388
+ "Math.ceil": {
2389
+ title: "Math.ceil()",
2390
+ type: "(x: number) => number",
2391
+ body: "Returns the smallest integer greater than or equal to x. Rounds toward positive infinity.",
2392
+ language: ["typescript", "javascript"]
2393
+ },
2394
+ "Math.round": {
2395
+ title: "Math.round()",
2396
+ type: "(x: number) => number",
2397
+ body: "Returns the value of x rounded to the nearest integer. Values with a fractional part of exactly 0.5 round up.",
2398
+ language: ["typescript", "javascript"]
2399
+ },
2400
+ "Math.abs": {
2401
+ title: "Math.abs()",
2402
+ type: "(x: number) => number",
2403
+ body: "Returns the absolute (non-negative) value of x.",
2404
+ language: ["typescript", "javascript"]
2405
+ },
2406
+ "Math.sqrt": {
2407
+ title: "Math.sqrt()",
2408
+ type: "(x: number) => number",
2409
+ body: "Returns the square root of x. Returns NaN if x is negative.",
2410
+ language: ["typescript", "javascript"]
2411
+ },
2412
+ "Math.pow": {
2413
+ title: "Math.pow()",
2414
+ type: "(base: number, exponent: number) => number",
2415
+ body: "Returns base raised to the power of exponent. Equivalent to the ** operator.",
2416
+ language: ["typescript", "javascript"]
2417
+ },
2418
+ "Math.random": {
2419
+ title: "Math.random()",
2420
+ type: "() => number",
2421
+ body: "Returns a pseudo-random floating-point number in the range [0, 1). Not cryptographically secure — use crypto.getRandomValues() for security-sensitive code.",
2422
+ language: ["typescript", "javascript"]
2423
+ },
2424
+ "Math.PI": {
2425
+ title: "Math.PI",
2426
+ type: "number",
2427
+ body: "The ratio of a circle's circumference to its diameter: approximately 3.14159265358979.",
2428
+ language: ["typescript", "javascript"]
2429
+ },
2430
+ "Math.trunc": {
2431
+ title: "Math.trunc()",
2432
+ type: "(x: number) => number",
2433
+ body: "Returns the integer part of x by removing any fractional digits. Does not round — simply truncates toward zero.",
2434
+ language: ["typescript", "javascript"]
2435
+ },
2436
+ "Math.sign": {
2437
+ title: "Math.sign()",
2438
+ type: "(x: number) => number",
2439
+ body: "Returns 1 if x is positive, -1 if x is negative, 0 if x is zero, or NaN if x is not a number.",
2440
+ language: ["typescript", "javascript"]
2441
+ },
2442
+ "Math.clamp": {
2443
+ title: "Math.clamp()",
2444
+ type: "(value: number, min: number, max: number) => number",
2445
+ body: "Clamps value between min and max. Note: not yet standard — use Math.min(Math.max(value, min), max) for compatibility.",
2446
+ language: ["typescript", "javascript"]
2447
+ },
2448
+ // ── JSON ──────────────────────────────────────────────────
2449
+ JSON: {
2450
+ title: "JSON",
2451
+ type: "namespace JSON",
2452
+ body: "Provides methods for parsing and serializing JSON (JavaScript Object Notation). All methods are static.",
2453
+ language: ["typescript", "javascript"]
2454
+ },
2455
+ "JSON.stringify": {
2456
+ title: "JSON.stringify()",
2457
+ type: "(value: any, replacer?: any, space?: string | number) => string",
2458
+ body: "Converts a JavaScript value to a JSON string. Pass a number or string as the third argument to pretty-print with indentation. Throws on circular references.",
2459
+ language: ["typescript", "javascript"]
2460
+ },
2461
+ "JSON.parse": {
2462
+ title: "JSON.parse()",
2463
+ type: "(text: string, reviver?: (key: string, value: any) => any) => any",
2464
+ body: "Parses a JSON string and returns the corresponding JavaScript value. Throws SyntaxError if the string is not valid JSON.",
2465
+ language: ["typescript", "javascript"]
2466
+ },
2467
+ // ── Array ─────────────────────────────────────────────────
2468
+ Array: {
2469
+ title: "Array",
2470
+ type: "interface Array<T>",
2471
+ body: "Represents an ordered list of values. Provides methods for traversal, mutation, searching, and transformation.",
2472
+ language: ["typescript", "javascript"]
2473
+ },
2474
+ "Array.from": {
2475
+ title: "Array.from()",
2476
+ type: "<T>(arrayLike: Iterable<T> | ArrayLike<T>, mapFn?: (v: T, i: number) => T) => T[]",
2477
+ body: "Creates a new Array from an array-like or iterable object (e.g. NodeList, Set, Map, string). Optionally applies a mapping function.",
2478
+ language: ["typescript", "javascript"]
2479
+ },
2480
+ "Array.isArray": {
2481
+ title: "Array.isArray()",
2482
+ type: "(value: unknown) => value is any[]",
2483
+ body: "Returns true if the given value is an Array. More reliable than instanceof Array across iframe boundaries.",
2484
+ language: ["typescript", "javascript"]
2485
+ },
2486
+ // ── Object ────────────────────────────────────────────────
2487
+ Object: {
2488
+ title: "Object",
2489
+ type: "interface Object",
2490
+ body: "The base class of all JavaScript objects. Provides static methods for working with object properties, prototypes, and descriptors.",
2491
+ language: ["typescript", "javascript"]
2492
+ },
2493
+ "Object.keys": {
2494
+ title: "Object.keys()",
2495
+ type: "(obj: object) => string[]",
2496
+ body: "Returns an array of an object's own enumerable string-keyed property names, in insertion order.",
2497
+ language: ["typescript", "javascript"]
2498
+ },
2499
+ "Object.values": {
2500
+ title: "Object.values()",
2501
+ type: "(obj: object) => any[]",
2502
+ body: "Returns an array of an object's own enumerable string-keyed property values, in insertion order.",
2503
+ language: ["typescript", "javascript"]
2504
+ },
2505
+ "Object.entries": {
2506
+ title: "Object.entries()",
2507
+ type: "(obj: object) => [string, any][]",
2508
+ body: "Returns an array of [key, value] pairs for all own enumerable string-keyed properties of an object.",
2509
+ language: ["typescript", "javascript"]
2510
+ },
2511
+ "Object.assign": {
2512
+ title: "Object.assign()",
2513
+ type: "<T, U>(target: T, source: U) => T & U",
2514
+ body: "Copies own enumerable properties from one or more source objects into a target object. Returns the modified target. Does a shallow copy.",
2515
+ language: ["typescript", "javascript"]
2516
+ },
2517
+ "Object.freeze": {
2518
+ title: "Object.freeze()",
2519
+ type: "<T>(obj: T) => Readonly<T>",
2520
+ body: "Freezes an object — prevents adding, removing, or changing its properties. Returns the same object. Shallow — nested objects are not frozen.",
2521
+ language: ["typescript", "javascript"]
2522
+ },
2523
+ "Object.create": {
2524
+ title: "Object.create()",
2525
+ type: "(proto: object | null, propertiesObject?: PropertyDescriptorMap) => any",
2526
+ body: "Creates a new object with the specified prototype object and optional property descriptors.",
2527
+ language: ["typescript", "javascript"]
2528
+ },
2529
+ "Object.fromEntries": {
2530
+ title: "Object.fromEntries()",
2531
+ type: "<T>(entries: Iterable<[string, T]>) => Record<string, T>",
2532
+ body: "Creates an object from an array of [key, value] pairs or any iterable of key-value entries. The inverse of Object.entries().",
2533
+ language: ["typescript", "javascript"]
2534
+ },
2535
+ // ── Promise ───────────────────────────────────────────────
2536
+ Promise: {
2537
+ title: "Promise",
2538
+ type: "interface Promise<T>",
2539
+ body: "Represents an asynchronous operation that will eventually complete (or fail) and produce a value. Use .then(), .catch(), and .finally() to handle outcomes.",
2540
+ language: ["typescript", "javascript"]
2541
+ },
2542
+ "Promise.all": {
2543
+ title: "Promise.all()",
2544
+ type: "<T>(promises: Iterable<Promise<T>>) => Promise<T[]>",
2545
+ body: "Waits for all promises to resolve and returns an array of results. If any promise rejects, the entire result rejects immediately (fail-fast).",
2546
+ language: ["typescript", "javascript"]
2547
+ },
2548
+ "Promise.allSettled": {
2549
+ title: "Promise.allSettled()",
2550
+ type: "<T>(promises: Iterable<Promise<T>>) => Promise<PromiseSettledResult<T>[]>",
2551
+ body: 'Waits for all promises to settle (resolve or reject) and returns an array of result objects, each with a status of "fulfilled" or "rejected". Never rejects.',
2552
+ language: ["typescript", "javascript"]
2553
+ },
2554
+ "Promise.race": {
2555
+ title: "Promise.race()",
2556
+ type: "<T>(promises: Iterable<Promise<T>>) => Promise<T>",
2557
+ body: "Returns a promise that resolves or rejects as soon as one of the given promises resolves or rejects, with that value or reason.",
2558
+ language: ["typescript", "javascript"]
2559
+ },
2560
+ "Promise.resolve": {
2561
+ title: "Promise.resolve()",
2562
+ type: "<T>(value: T | PromiseLike<T>) => Promise<T>",
2563
+ body: "Returns a Promise object that is resolved with the given value. If the value is a thenable, the returned promise follows it.",
2564
+ language: ["typescript", "javascript"]
2565
+ },
2566
+ "Promise.reject": {
2567
+ title: "Promise.reject()",
2568
+ type: "(reason?: any) => Promise<never>",
2569
+ body: "Returns a Promise that is rejected with the given reason. Useful for creating pre-rejected promises in control flow.",
2570
+ language: ["typescript", "javascript"]
2571
+ },
2572
+ // ── Timers ────────────────────────────────────────────────
2573
+ setTimeout: {
2574
+ title: "setTimeout()",
2575
+ type: "(callback: () => void, delay?: number, ...args: any[]) => number",
2576
+ body: "Executes a function after a specified delay in milliseconds. Returns a timer ID that can be passed to clearTimeout() to cancel.",
2577
+ language: ["typescript", "javascript"]
2578
+ },
2579
+ clearTimeout: {
2580
+ title: "clearTimeout()",
2581
+ type: "(id: number) => void",
2582
+ body: "Cancels a timeout previously established by setTimeout(), preventing its callback from running.",
2583
+ language: ["typescript", "javascript"]
2584
+ },
2585
+ setInterval: {
2586
+ title: "setInterval()",
2587
+ type: "(callback: () => void, delay?: number, ...args: any[]) => number",
2588
+ body: "Repeatedly executes a function with a fixed time delay between each call. Returns a timer ID for cancellation via clearInterval().",
2589
+ language: ["typescript", "javascript"]
2590
+ },
2591
+ clearInterval: {
2592
+ title: "clearInterval()",
2593
+ type: "(id: number) => void",
2594
+ body: "Cancels a repeating timer established by setInterval().",
2595
+ language: ["typescript", "javascript"]
2596
+ },
2597
+ requestAnimationFrame: {
2598
+ title: "requestAnimationFrame()",
2599
+ type: "(callback: (timestamp: DOMHighResTimeStamp) => void) => number",
2600
+ body: "Schedules a callback to run before the next browser repaint. Ideal for animations — the browser can batch and throttle calls to 60fps or the display refresh rate.",
2601
+ language: ["typescript", "javascript"]
2602
+ },
2603
+ cancelAnimationFrame: {
2604
+ title: "cancelAnimationFrame()",
2605
+ type: "(id: number) => void",
2606
+ body: "Cancels an animation frame request previously scheduled with requestAnimationFrame().",
2607
+ language: ["typescript", "javascript"]
2608
+ },
2609
+ queueMicrotask: {
2610
+ title: "queueMicrotask()",
2611
+ type: "(callback: () => void) => void",
2612
+ body: "Queues a microtask to be executed before the next task in the event loop. Runs after the current JavaScript execution but before any setTimeout callbacks.",
2613
+ language: ["typescript", "javascript"]
2614
+ },
2615
+ // ── Network ───────────────────────────────────────────────
2616
+ fetch: {
2617
+ title: "fetch()",
2618
+ type: "(input: RequestInfo | URL, init?: RequestInit) => Promise<Response>",
2619
+ body: "Fetches a resource from the network. Returns a Promise that resolves to a Response. Use .json(), .text(), or .blob() on the response to read the body.",
2620
+ language: ["typescript", "javascript"]
2621
+ },
2622
+ // ── Global utils ──────────────────────────────────────────
2623
+ parseInt: {
2624
+ title: "parseInt()",
2625
+ type: "(string: string, radix?: number) => number",
2626
+ body: "Parses a string and returns an integer in the specified radix (base). Always provide the radix (typically 10) to avoid unexpected behavior with leading zeros.",
2627
+ language: ["typescript", "javascript"]
2628
+ },
2629
+ parseFloat: {
2630
+ title: "parseFloat()",
2631
+ type: "(string: string) => number",
2632
+ body: "Parses a string and returns a floating-point number. Returns NaN if the string cannot be converted.",
2633
+ language: ["typescript", "javascript"]
2634
+ },
2635
+ isNaN: {
2636
+ title: "isNaN()",
2637
+ type: "(value: number) => boolean",
2638
+ body: "Returns true if the value is NaN (Not a Number). Note: coerces the argument to number first — use Number.isNaN() for strict checking without coercion.",
2639
+ language: ["typescript", "javascript"]
2640
+ },
2641
+ isFinite: {
2642
+ title: "isFinite()",
2643
+ type: "(value: number) => boolean",
2644
+ body: "Returns true if the value is a finite number. Returns false for ±Infinity and NaN. Coerces the argument to number first.",
2645
+ language: ["typescript", "javascript"]
2646
+ },
2647
+ encodeURIComponent: {
2648
+ title: "encodeURIComponent()",
2649
+ type: "(uriComponent: string | number | boolean) => string",
2650
+ body: "Encodes a URI component by replacing special characters with their UTF-8 escape sequences. Use for encoding query string values before appending to a URL.",
2651
+ language: ["typescript", "javascript"]
2652
+ },
2653
+ decodeURIComponent: {
2654
+ title: "decodeURIComponent()",
2655
+ type: "(encodedURIComponent: string) => string",
2656
+ body: "Decodes a URI component that was previously encoded with encodeURIComponent(). Throws URIError on malformed sequences.",
2657
+ language: ["typescript", "javascript"]
2658
+ },
2659
+ structuredClone: {
2660
+ title: "structuredClone()",
2661
+ type: "<T>(value: T, options?: StructuredSerializeOptions) => T",
2662
+ body: "Creates a deep clone of the given value using the structured clone algorithm. Handles cycles, Maps, Sets, Dates, and typed arrays. Does not clone functions or class instances.",
2663
+ language: ["typescript", "javascript"]
2664
+ },
2665
+ // ── DOM ───────────────────────────────────────────────────
2666
+ "document.getElementById": {
2667
+ title: "document.getElementById()",
2668
+ type: "(elementId: string) => HTMLElement | null",
2669
+ body: "Returns the first element in the document with the specified ID, or null if not found. IDs must be unique per document.",
2670
+ language: ["typescript", "javascript"]
2671
+ },
2672
+ "document.querySelector": {
2673
+ title: "document.querySelector()",
2674
+ type: "(selectors: string) => Element | null",
2675
+ body: "Returns the first Element matching the given CSS selector string, or null if no match. Use querySelectorAll() for all matches.",
2676
+ language: ["typescript", "javascript"]
2677
+ },
2678
+ "document.querySelectorAll": {
2679
+ title: "document.querySelectorAll()",
2680
+ type: "(selectors: string) => NodeListOf<Element>",
2681
+ body: "Returns a static NodeList of all Elements matching the given CSS selector string. Does not update as the document changes.",
2682
+ language: ["typescript", "javascript"]
2683
+ },
2684
+ "document.createElement": {
2685
+ title: "document.createElement()",
2686
+ type: "<K extends keyof HTMLElementTagNameMap>(tagName: K) => HTMLElementTagNameMap[K]",
2687
+ body: "Creates a new HTML element with the specified tag name. The element is not attached to the DOM until you call appendChild() or similar.",
2688
+ language: ["typescript", "javascript"]
2689
+ },
2690
+ addEventListener: {
2691
+ title: "addEventListener()",
2692
+ type: "(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void",
2693
+ body: "Registers an event listener on the target element. The listener is called whenever the specified event fires. Remember to call removeEventListener() to clean up.",
2694
+ language: ["typescript", "javascript"]
2695
+ },
2696
+ removeEventListener: {
2697
+ title: "removeEventListener()",
2698
+ type: "(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => void",
2699
+ body: "Removes an event listener previously added with addEventListener(). The listener reference must be the same function object.",
2700
+ language: ["typescript", "javascript"]
2701
+ },
2702
+ // ── TypeScript keywords ────────────────────────────────────
2703
+ const: {
2704
+ title: "const",
2705
+ type: "keyword",
2706
+ body: "Declares a block-scoped variable that cannot be reassigned. The binding is immutable — but for objects and arrays, their contents can still be mutated.",
2707
+ language: ["typescript", "javascript"]
2708
+ },
2709
+ let: {
2710
+ title: "let",
2711
+ type: "keyword",
2712
+ body: "Declares a block-scoped variable that can be reassigned. Prefer const for bindings that never change.",
2713
+ language: ["typescript", "javascript"]
2714
+ },
2715
+ var: {
2716
+ title: "var",
2717
+ type: "keyword",
2718
+ body: "Declares a function-scoped (or globally-scoped) variable. Hoisted to the top of its scope. Prefer const or let in modern code.",
2719
+ language: ["typescript", "javascript"]
2720
+ },
2721
+ function: {
2722
+ title: "function",
2723
+ type: "keyword",
2724
+ body: "Defines a named function declaration, or introduces a function expression. Function declarations are hoisted; expressions are not.",
2725
+ language: ["typescript", "javascript"]
2726
+ },
2727
+ class: {
2728
+ title: "class",
2729
+ type: "keyword",
2730
+ body: "Declares a class — a blueprint for creating objects with shared methods and properties. Classes support extends, implements, constructors, getters, setters, and static members.",
2731
+ language: ["typescript", "javascript"]
2732
+ },
2733
+ async: {
2734
+ title: "async",
2735
+ type: "keyword",
2736
+ body: "Marks a function as asynchronous, making it return a Promise implicitly. Enables the use of the await keyword inside the function body.",
2737
+ language: ["typescript", "javascript"]
2738
+ },
2739
+ await: {
2740
+ title: "await",
2741
+ type: "keyword",
2742
+ body: "Pauses execution of an async function until the Promise settles, then returns the resolved value. Must be used inside an async function.",
2743
+ language: ["typescript", "javascript"]
2744
+ },
2745
+ return: {
2746
+ title: "return",
2747
+ type: "keyword",
2748
+ body: "Exits the current function and optionally returns a value to the caller. In an async function, the value is wrapped in a resolved Promise.",
2749
+ language: ["typescript", "javascript"]
2750
+ },
2751
+ interface: {
2752
+ title: "interface",
2753
+ type: "keyword",
2754
+ body: "Defines a TypeScript interface — a named contract describing the shape of an object. Interfaces can be extended, merged (declaration merging), and implemented by classes.",
2755
+ language: ["typescript"]
2756
+ },
2757
+ type: {
2758
+ title: "type",
2759
+ type: "keyword",
2760
+ body: "Declares a TypeScript type alias — a name for any type expression including unions, intersections, tuples, mapped types, and conditional types.",
2761
+ language: ["typescript"]
2762
+ },
2763
+ extends: {
2764
+ title: "extends",
2765
+ type: "keyword",
2766
+ body: "Establishes inheritance (class extends Base) or constrains a generic type parameter (T extends object). Also used in conditional types (T extends U ? X : Y).",
2767
+ language: ["typescript", "javascript"]
2768
+ },
2769
+ implements: {
2770
+ title: "implements",
2771
+ type: "keyword",
2772
+ body: "Declares that a class satisfies the shape of one or more interfaces. TypeScript verifies at compile time that all required members are present.",
2773
+ language: ["typescript"]
2774
+ },
2775
+ export: {
2776
+ title: "export",
2777
+ type: "keyword",
2778
+ body: "Makes a declaration (variable, function, class, type, interface) available for import in other modules. Use export default for a single primary export.",
2779
+ language: ["typescript", "javascript"]
2780
+ },
2781
+ import: {
2782
+ title: "import",
2783
+ type: "keyword",
2784
+ body: "Imports bindings from another module. Supports named imports ({ foo, bar }), default imports (Foo), namespace imports (* as Foo), and side-effect imports.",
2785
+ language: ["typescript", "javascript"]
2786
+ },
2787
+ typeof: {
2788
+ title: "typeof",
2789
+ type: "keyword",
2790
+ body: 'Returns a string describing the type of its operand at runtime ("string", "number", "boolean", "object", "function", "undefined", "symbol", "bigint"). In TypeScript, also used as a type operator to capture the type of a value.',
2791
+ language: ["typescript", "javascript"]
2792
+ },
2793
+ instanceof: {
2794
+ title: "instanceof",
2795
+ type: "keyword",
2796
+ body: "Tests whether an object has a given constructor in its prototype chain. Returns true if the object is an instance of the constructor.",
2797
+ language: ["typescript", "javascript"]
2798
+ },
2799
+ new: {
2800
+ title: "new",
2801
+ type: "keyword",
2802
+ body: "Creates a new instance of a class or constructor function. Allocates memory, sets the prototype, calls the constructor with `this` bound to the new object, and returns it.",
2803
+ language: ["typescript", "javascript"]
2804
+ },
2805
+ throw: {
2806
+ title: "throw",
2807
+ type: "keyword",
2808
+ body: "Throws a user-defined exception, stopping execution of the current function and propagating up the call stack until caught by a try...catch block.",
2809
+ language: ["typescript", "javascript"]
2810
+ },
2811
+ try: {
2812
+ title: "try...catch...finally",
2813
+ type: "keyword",
2814
+ body: "Wraps code that might throw an exception. The catch block handles errors; the finally block always runs whether or not an error occurred.",
2815
+ language: ["typescript", "javascript"]
2816
+ },
2817
+ // ── TypeScript built-in types ──────────────────────────────
2818
+ string: {
2819
+ title: "string",
2820
+ type: "primitive type",
2821
+ body: 'Represents a sequence of UTF-16 code units. In TypeScript, the string type accepts any text value. Literal types like "hello" narrow to specific string values.',
2822
+ language: ["typescript"]
2823
+ },
2824
+ number: {
2825
+ title: "number",
2826
+ type: "primitive type",
2827
+ body: "Represents a double-precision 64-bit IEEE 754 floating-point value. Includes integers, decimals, NaN, and Infinity. TypeScript does not have a separate int type.",
2828
+ language: ["typescript"]
2829
+ },
2830
+ boolean: {
2831
+ title: "boolean",
2832
+ type: "primitive type",
2833
+ body: "Represents a logical true or false value. Literal types true and false narrow to specific boolean values.",
2834
+ language: ["typescript"]
2835
+ },
2836
+ any: {
2837
+ title: "any",
2838
+ type: "TypeScript type",
2839
+ body: "Disables type checking for a value — allows any operation without compile errors. Avoid using any; prefer unknown when the type is genuinely uncertain.",
2840
+ language: ["typescript"]
2841
+ },
2842
+ unknown: {
2843
+ title: "unknown",
2844
+ type: "TypeScript type",
2845
+ body: "The type-safe alternative to any. You cannot perform operations on an unknown value without first narrowing its type with typeof, instanceof, or a type guard.",
2846
+ language: ["typescript"]
2847
+ },
2848
+ void: {
2849
+ title: "void",
2850
+ type: "TypeScript type",
2851
+ body: "Represents the absence of a value, typically used as the return type of functions that do not return anything meaningful.",
2852
+ language: ["typescript"]
2853
+ },
2854
+ never: {
2855
+ title: "never",
2856
+ type: "TypeScript type",
2857
+ body: "A type with no values — used for functions that never return (throw or infinite loop) and for exhaustive checks in union type switches.",
2858
+ language: ["typescript"]
2859
+ },
2860
+ Record: {
2861
+ title: "Record<K, V>",
2862
+ type: "type Record<K extends keyof any, T> = { [P in K]: T }",
2863
+ body: "A utility type that constructs an object type whose keys are of type K and values are of type V. Useful for dictionaries and lookup tables.",
2864
+ language: ["typescript"]
2865
+ },
2866
+ Partial: {
2867
+ title: "Partial<T>",
2868
+ type: "type Partial<T> = { [P in keyof T]?: T[P] }",
2869
+ body: "A utility type that makes all properties of T optional. Useful for update payloads, patches, and configuration objects with defaults.",
2870
+ language: ["typescript"]
2871
+ },
2872
+ Required: {
2873
+ title: "Required<T>",
2874
+ type: "type Required<T> = { [P in keyof T]-?: T[P] }",
2875
+ body: "A utility type that makes all properties of T required (removes optionality). The inverse of Partial<T>.",
2876
+ language: ["typescript"]
2877
+ },
2878
+ Readonly: {
2879
+ title: "Readonly<T>",
2880
+ type: "type Readonly<T> = { readonly [P in keyof T]: T[P] }",
2881
+ body: "A utility type that makes all properties of T readonly. Prevents property reassignment at the type level.",
2882
+ language: ["typescript"]
2883
+ },
2884
+ ReturnType: {
2885
+ title: "ReturnType<T>",
2886
+ type: "type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any",
2887
+ body: "A utility type that extracts the return type of a function type T.",
2888
+ language: ["typescript"]
2889
+ },
2890
+ Omit: {
2891
+ title: "Omit<T, K>",
2892
+ type: "type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>",
2893
+ body: "A utility type that constructs a type by picking all properties from T then removing those in K.",
2894
+ language: ["typescript"]
2895
+ },
2896
+ Pick: {
2897
+ title: "Pick<T, K>",
2898
+ type: "type Pick<T, K extends keyof T> = { [P in K]: T[P] }",
2899
+ body: "A utility type that constructs a type by picking the set of properties K from T.",
2900
+ language: ["typescript"]
2901
+ },
2902
+ NonNullable: {
2903
+ title: "NonNullable<T>",
2904
+ type: "type NonNullable<T> = T extends null | undefined ? never : T",
2905
+ body: "A utility type that removes null and undefined from the type T.",
2906
+ language: ["typescript"]
2907
+ },
2908
+ keyof: {
2909
+ title: "keyof",
2910
+ type: "TypeScript type operator",
2911
+ body: 'Produces a union type of all property keys of an object type. keyof { a: string; b: number } is "a" | "b".',
2912
+ language: ["typescript"]
2913
+ }
2914
+ };
2915
+ function Ht(s, e) {
2916
+ const t = Dt[s];
2917
+ return !t || t.language && !(Array.isArray(t.language) ? t.language : [t.language]).includes(e) ? null : t;
2918
+ }
2919
+ function Rt(s) {
2920
+ var G, K, C, R;
2921
+ const { vr: e, visIdx: t, curVisRow: i, wm: r, foldedLines: n, isFoldable: a, opts: l } = s, { docLine: o, segIdx: c, text: d } = e, p = t === i, h = o === ((G = r.visualRows[i]) == null ? void 0 : G.docLine), g = c > 0, y = ((K = r.segments[o]) == null ? void 0 : K.slice(0, c).reduce((w, k) => w + k.length, 0)) ?? 0, v = s.docSel ? fe(s.docSel, o, ((C = (r.segments[o] ?? [""])[c]) == null ? void 0 : C.length) ?? 0) : null;
2922
+ let f = null;
2923
+ if (v) {
2924
+ const w = ((R = (r.segments[o] ?? [""])[c]) == null ? void 0 : R.length) ?? 0, k = fe(s.docSel, o, w + y);
2925
+ if (k) {
2926
+ const M = k.start - y, H = k.end - y;
2927
+ H > 0 && M < d.length && (f = { start: Math.max(0, M), end: Math.min(d.length, H) });
2928
+ }
2929
+ }
2930
+ const b = s.findMatches.filter((w) => w.row === o).map((w) => {
2931
+ var j, B;
2932
+ const k = w.col - y, M = w.col + w.len - y;
2933
+ if (M <= 0 || k >= d.length) return null;
2934
+ const H = s.findIdx >= 0 && ((j = s.findMatches[s.findIdx]) == null ? void 0 : j.row) === w.row && ((B = s.findMatches[s.findIdx]) == null ? void 0 : B.col) === w.col;
2935
+ return { start: Math.max(0, k), end: Math.min(d.length, M), isCur: H };
2936
+ }).filter(Boolean), T = s.wordHighlights.filter((w) => w.row === o).map((w) => {
2937
+ const k = w.col - y, M = w.col + w.len - y;
2938
+ return M <= 0 || k >= d.length ? null : { start: Math.max(0, k), end: Math.min(d.length, M) };
2939
+ }).filter(Boolean), _ = [];
2940
+ if (s.bracketMatch) {
2941
+ for (const w of [s.bracketMatch.open, s.bracketMatch.close])
2942
+ if (w.row === o) {
2943
+ const k = w.col - y;
2944
+ k >= 0 && k < d.length && _.push({ start: k, end: k + 1 });
2945
+ }
2946
+ }
2947
+ const x = [], m = [];
2948
+ for (const w of s.extraCursors) {
2949
+ const k = F(r, w.row, w.col);
2950
+ if (k.visRow === t && x.push(k.colInSeg), w.sel) {
2951
+ const M = jt(w.sel);
2952
+ if (o >= M.ar && o <= M.fr) {
2953
+ const H = o === M.ar ? M.ac - y : -y, j = o === M.fr ? M.fc - y : d.length + 999;
2954
+ j > 0 && H < d.length && m.push({ start: Math.max(0, H), end: Math.min(d.length, j) });
2955
+ }
2956
+ }
2957
+ }
2958
+ const S = Bt(d, l.renderWhitespace), I = p || f || b.length || x.length || T.length || _.length || m.length;
2959
+ let U;
2960
+ if (I)
2961
+ U = $t(
2962
+ S,
2963
+ p ? s.curColInSeg : -1,
2964
+ f,
2965
+ b,
2966
+ x,
2967
+ T,
2968
+ _,
2969
+ m,
2970
+ l.tokeniserOpts
2971
+ );
2972
+ else {
2973
+ const w = `${o}:${c}:${l.renderWhitespace}`;
2974
+ let k = s.tokenCache.get(w, S);
2975
+ k || (k = oe(S, l.tokeniserOpts), s.tokenCache.set(w, S, k)), U = Pt(S, k) || "&#8203;";
2976
+ }
2977
+ let V = "";
2978
+ if (c === 0 && l.showIndentGuides) {
2979
+ const w = (d.match(/^(\s*)/) ?? ["", ""])[1].length, k = Math.floor(w / l.tabSize);
2980
+ for (let M = 1; M < k; M++) {
2981
+ const H = l.codePaddingLeft + M * l.tabSize * l.charWidth;
2982
+ V += `<span class="sl-ig" style="left:${H}px"></span>`;
2983
+ }
2984
+ }
2985
+ let $ = "";
2986
+ if (c === 0 && a) {
2987
+ const w = n.has(o);
2988
+ $ = `<span class="sl-fold-btn" data-row="${o}">${w ? "▸" : "▾"}</span>`;
2989
+ }
2990
+ const W = n.has(o) && c === 0, N = c === 0 ? String(o + 1) : "";
2991
+ return `<div class="${[
2992
+ "sl-er",
2993
+ l.highlightActiveLine && h ? "sl-cur-row" : "",
2994
+ g ? "sl-wrap-cont" : "",
2995
+ W ? "sl-folded" : ""
2996
+ ].filter(Boolean).join(" ")}" style="height:${l.lineHeight}px" data-v="${t}" data-doc="${o}"><div class="sl-eg" style="position:relative">${$}<span class="sl-egn">${N}</span></div><div class="sl-el"><span class="sl-cl">${V}${U}</span></div></div>`;
2997
+ }
2998
+ function Bt(s, e) {
2999
+ if (e === "none") return s;
3000
+ if (e === "all")
3001
+ return s.replace(/ /g, "·").replace(/\t/g, "→");
3002
+ const t = (s.match(/^ +/) ?? [""])[0].length, i = (s.match(/ +$/) ?? [""])[0].length;
3003
+ let r = s;
3004
+ return t && (r = "·".repeat(t) + r.slice(t)), i && (r = r.slice(0, r.length - i) + "·".repeat(i)), r.replace(/\t/g, "→");
3005
+ }
3006
+ function jt(s) {
3007
+ return s.ar < s.fr || s.ar === s.fr && s.ac <= s.fc ? s : { ar: s.fr, ac: s.fc, fr: s.ar, fc: s.ac };
3008
+ }
3009
+ function Pt(s, e) {
3010
+ if (!s) return "";
3011
+ const t = Ie(s, e);
3012
+ let i = "", r = 0, n = t[0];
3013
+ const a = (l) => {
3014
+ if (l <= r) return;
3015
+ const o = q(s.slice(r, l));
3016
+ i += n ? `<span class="${n}">${o}</span>` : o;
3017
+ };
3018
+ for (let l = 1; l <= s.length; l++) {
3019
+ const o = l < s.length ? t[l] : null;
3020
+ o !== n && (a(l), r = l, n = o ?? "");
3021
+ }
3022
+ return i;
3023
+ }
3024
+ function $t(s, e, t, i, r, n, a, l, o) {
3025
+ if (s.length === 0) {
3026
+ let f = e >= 0 ? '<span class="sl-cur"></span>' : "";
3027
+ for (const b of r) f += '<span class="sl-cur-extra"></span>';
3028
+ return f || "&#8203;";
3029
+ }
3030
+ const c = oe(s, o), d = Ie(s, c);
3031
+ let p = "", h = 0, g = "", y = "";
3032
+ const v = (f) => {
3033
+ if (f <= h) return;
3034
+ const b = q(s.slice(h, f)), T = [g, y].filter(Boolean).join(" ");
3035
+ p += T ? `<span class="${T}">${b}</span>` : b;
3036
+ };
3037
+ for (let f = 0; f <= s.length; f++) {
3038
+ e === f && (v(f), h = f, p += '<span class="sl-cur"></span>');
3039
+ for (const I of r)
3040
+ I === f && (v(f), h = f, p += '<span class="sl-cur-extra"></span>');
3041
+ if (f === s.length) {
3042
+ v(f);
3043
+ break;
3044
+ }
3045
+ const b = d[f], T = i.find((I) => f >= I.start && f < I.end), _ = t && f >= t.start && f < t.end || l.some((I) => f >= I.start && f < I.end), x = !_ && !T && n.some((I) => f >= I.start && f < I.end), m = !_ && !T && a.some((I) => f >= I.start && f < I.end);
3046
+ let S = "";
3047
+ _ ? S = "sl-sh" : T ? S = "sl-fh" + (T.isCur ? " sl-fh-cur" : "") : m ? S = "sl-bm" : x && (S = "sl-wh"), (S !== g || b !== y) && (v(f), h = f, g = S, y = b);
3048
+ }
3049
+ return p || "&#8203;";
3050
+ }
3051
+ function ie(s, e, t, i, r) {
3052
+ const n = Math.max(0, s * r - t), a = Math.max(0, s * 2 - i), o = (n > 0 ? e / n : 0) * a, c = Math.max(20, t / r * 2), d = e / r * 2 - o;
3053
+ return { mmScroll: o, sliderTop: d, sliderHeight: c };
3054
+ }
3055
+ function Wt(s, e, t, i, r) {
3056
+ const n = Math.max(0, e * r - t), a = Math.max(0, e * 2 - i);
3057
+ if (n <= 0) return 0;
3058
+ const l = 2 / r - a / n;
3059
+ if (Math.abs(l) < 1e-9) {
3060
+ const o = Math.max(20, t / r * 2);
3061
+ return Math.max(0, Math.min(n, s / Math.max(1, i - o) * n));
3062
+ }
3063
+ return Math.max(0, Math.min(n, s / l));
3064
+ }
3065
+ function Nt(s, e, t, i, r, n) {
3066
+ const a = Math.max(0, e * n - i), l = Math.max(0, e * 2 - r);
3067
+ if (a <= 0) return 0;
3068
+ const o = t / a * l, c = (s + o) / 2;
3069
+ return Math.max(0, Math.min(a, c * n - i / 2));
3070
+ }
3071
+ function Me(s) {
3072
+ const e = (t) => {
3073
+ const i = s(t);
3074
+ return i.startsWith("#") && i.length === 7 ? be(i, 0.85) : i;
3075
+ };
3076
+ return {
3077
+ kw: e("--tok-kw"),
3078
+ fn: e("--tok-fn"),
3079
+ cls: e("--tok-cls"),
3080
+ typ: e("--tok-typ"),
3081
+ str: e("--tok-str"),
3082
+ num: e("--tok-num"),
3083
+ cmt: e("--tok-cmt"),
3084
+ dec: e("--tok-dec"),
3085
+ op: e("--tok-op"),
3086
+ txt: (() => {
3087
+ const t = s("--text2");
3088
+ return t.startsWith("#") && t.length === 7 ? be(t, 0.28) : "rgba(150,148,140,0.28)";
3089
+ })()
3090
+ };
3091
+ }
3092
+ function Ot(s) {
3093
+ var G, K;
3094
+ const {
3095
+ canvas: e,
3096
+ doc: t,
3097
+ firstLine: i,
3098
+ lastLine: r,
3099
+ subPx: n,
3100
+ wrapperWidth: a,
3101
+ canvasHeight: l,
3102
+ cursorRow: o,
3103
+ sel: c,
3104
+ findMatches: d,
3105
+ findIdx: p,
3106
+ sliderTop: h,
3107
+ sliderHeight: g,
3108
+ colors: y,
3109
+ getCssVar: v,
3110
+ dpr: f
3111
+ } = s, b = e.getContext("2d");
3112
+ if (!b) return;
3113
+ b.setTransform(f, 0, 0, f, 0, 0);
3114
+ const T = v("--mm-bg") || "#0d0d0f", _ = v("--mm-dim") || "rgba(0,0,0,.30)", x = v("--mm-edge") || "rgba(255,255,255,.18)", m = v("--mm-slider") || "rgba(255,255,255,.07)", S = v("--sel-bg") || "rgba(110,159,255,.22)", I = v("--cur-line-bg") || "rgba(255,255,255,.05)", U = v("--find-border") || "rgba(234,180,86,.50)", V = v("--find-cur-bg") || "rgba(234,180,86,.80)", $ = (C) => (C - i) * 2;
3115
+ if (b.fillStyle = T, b.fillRect(0, 0, a, l), o >= i && o < r && (b.fillStyle = I, b.fillRect(0, $(o), a, 2)), c) {
3116
+ const C = Math.max(i, c.ar), R = Math.min(r - 1, c.fr);
3117
+ R >= C && (b.fillStyle = S, b.fillRect(0, $(C), a, (R - C + 1) * 2));
3118
+ }
3119
+ for (const C of d) {
3120
+ if (C.row < i || C.row >= r) continue;
3121
+ const R = p >= 0 && ((G = d[p]) == null ? void 0 : G.row) === C.row && ((K = d[p]) == null ? void 0 : K.col) === C.col;
3122
+ b.fillStyle = R ? V : U, b.fillRect(
3123
+ 3 + C.col * 1.1,
3124
+ $(C.row),
3125
+ Math.max(3, C.len * 1.1),
3126
+ 2
3127
+ );
3128
+ }
3129
+ const W = Math.floor((a - 3) / 1.1);
3130
+ for (let C = i; C < r; C++) {
3131
+ const R = t[C] ?? "";
3132
+ if (!R.trim()) continue;
3133
+ const w = $(C), k = 1.5, M = oe(R);
3134
+ let H = 0;
3135
+ for (const B of M) {
3136
+ if (B.start >= W) break;
3137
+ B.start > H && (b.fillStyle = y.txt, b.fillRect(3 + H * 1.1, w, (Math.min(B.start, W) - H) * 1.1, k));
3138
+ const Le = y[B.cls] ?? y.txt, de = Math.min(B.end, W) - B.start;
3139
+ de > 0 && (b.fillStyle = Le, b.fillRect(3 + B.start * 1.1, w, de * 1.1, k)), H = Math.max(H, Math.min(B.end, W));
3140
+ }
3141
+ const j = Math.min(R.length, W);
3142
+ H < j && (b.fillStyle = y.txt, b.fillRect(3 + H * 1.1, w, (j - H) * 1.1, k));
3143
+ }
3144
+ const N = h + n, z = N + g;
3145
+ b.fillStyle = _, N > 0 && b.fillRect(0, 0, a, N), z < l && b.fillRect(0, z, a, l - z), b.fillStyle = m, b.fillRect(0, N, a, g), b.fillStyle = x, b.fillRect(0, Math.max(0, N), a, 1), b.fillRect(0, Math.max(0, z - 1), a, 1);
3146
+ }
3147
+ const Ft = {
3148
+ value: "",
3149
+ language: "typescript",
3150
+ theme: "",
3151
+ showGutter: !0,
3152
+ showMinimap: !0,
3153
+ showStatusBar: !0,
3154
+ wordWrap: !1,
3155
+ wrapColumn: 80,
3156
+ fontFamily: "'JetBrains Mono', monospace",
3157
+ fontSize: 13,
3158
+ lineHeight: 22,
3159
+ tabSize: 2,
3160
+ insertSpaces: !0,
3161
+ maxUndoHistory: 300,
3162
+ showIndentGuides: !0,
3163
+ bracketMatching: !0,
3164
+ codeFolding: !0,
3165
+ emmet: !0,
3166
+ snippetExpansion: !0,
3167
+ autocomplete: !0,
3168
+ multiCursor: !0,
3169
+ find: !0,
3170
+ findReplace: !0,
3171
+ wordSelection: !0,
3172
+ wordHighlight: !0,
3173
+ highlightActiveLine: !0,
3174
+ autocompletePrefixLength: 2,
3175
+ readOnly: !1,
3176
+ extraKeywords: [],
3177
+ extraTypes: [],
3178
+ completions: [],
3179
+ replaceBuiltins: !1,
3180
+ maxCompletions: 14,
3181
+ autoClosePairs: { "(": ")", "[": "]", "{": "}", '"': '"', "'": "'", "`": "`" },
3182
+ lineCommentToken: "",
3183
+ wordSeparators: "",
3184
+ undoBatchMs: 700,
3185
+ gutterWidth: 60,
3186
+ minimapWidth: 120,
3187
+ cursorBlinkRate: 1050,
3188
+ cursorStyle: "line",
3189
+ renderWhitespace: "none",
3190
+ tokenColors: {},
3191
+ hover: !0
3192
+ };
3193
+ class Ut {
3194
+ // ── Constructor ───────────────────────────────────────────
3195
+ constructor(e, t = {}) {
3196
+ // ── DOM ───────────────────────────────────────────────────
3197
+ u(this, "_host");
3198
+ u(this, "_shadow");
3199
+ u(this, "_editorEl");
3200
+ u(this, "_spacerEl");
3201
+ u(this, "_vpEl");
3202
+ u(this, "_inputEl");
3203
+ u(this, "_minimapWrap");
3204
+ u(this, "_mmCanvas");
3205
+ u(this, "_mmSlider");
3206
+ u(this, "_statusBar");
3207
+ u(this, "_findBar");
3208
+ u(this, "_findInput");
3209
+ u(this, "_replaceInput");
3210
+ u(this, "_findCount");
3211
+ u(this, "_replaceRow");
3212
+ u(this, "_acPopup");
3213
+ u(this, "_emmetTip");
3214
+ u(this, "_snippetTip");
3215
+ u(this, "_hoverTip");
3216
+ u(this, "_themeOverlay");
3217
+ u(this, "_themePanel");
3218
+ // ── State ─────────────────────────────────────────────────
3219
+ u(this, "_config");
3220
+ u(this, "_tab", ue(1, [""]));
3221
+ u(this, "_wm", { segments: [[""]], visualRows: [{ docLine: 0, segIdx: 0, text: "" }], docToVisArr: [0] });
3222
+ u(this, "_foldedLines", /* @__PURE__ */ new Map());
3223
+ u(this, "_tokenCache", new Ke());
3224
+ u(this, "_themeManager");
3225
+ // Find
3226
+ u(this, "_findMatches", []);
3227
+ u(this, "_findIdx", -1);
3228
+ u(this, "_findCaseSensitive", !1);
3229
+ u(this, "_findRegex", !1);
3230
+ // Highlights
3231
+ u(this, "_wordHighlights", []);
3232
+ u(this, "_bracketMatch", null);
3233
+ // Autocomplete
3234
+ u(this, "_acItems", []);
3235
+ u(this, "_acSel", 0);
3236
+ u(this, "_acPrefix", "");
3237
+ u(this, "_acStartCol", 0);
3238
+ u(this, "_emmetAcStartCol", 0);
3239
+ // start col of the emmet abbreviation (may differ from _acStartCol)
3240
+ // Multi-cursor
3241
+ u(this, "_mc", mt());
3242
+ u(this, "_extraCursors", []);
3243
+ // Mouse drag
3244
+ u(this, "_isDragging", !1);
3245
+ u(this, "_dragAnchor", null);
3246
+ // Hover
3247
+ u(this, "_hoverTimer", null);
3248
+ u(this, "_hoverPinned", !1);
3249
+ // Minimap drag
3250
+ u(this, "_mmDragMode", "none");
3251
+ u(this, "_mmDragStartY", 0);
3252
+ u(this, "_mmDragStartScroll", 0);
3253
+ u(this, "_mmSliderOffset", 0);
3254
+ u(this, "_mmColors");
3255
+ // Undo batching
3256
+ u(this, "_lastInputTime", 0);
3257
+ // Dynamic styles
3258
+ u(this, "_dynamicStyleEl");
3259
+ // Emmet
3260
+ u(this, "_emmetExpanded", null);
3261
+ // Snippets
3262
+ u(this, "_snippetExpanded", null);
3263
+ // ── Lifecycle / performance ───────────────────────────────
3264
+ /** Pending debounce timer ID for autocomplete re-computation. */
3265
+ u(this, "_acDebounceTimer", null);
3266
+ /** Pending requestAnimationFrame ID for coalesced renders. */
3267
+ u(this, "_rafId", null);
3268
+ // ── Bound window listener refs ────────────────────────────
3269
+ // Stored as named references so they can be removed precisely in destroy().
3270
+ u(this, "_onWinMouseUp");
3271
+ u(this, "_onWinResize");
3272
+ u(this, "_onEditorScroll");
3273
+ u(this, "_onWinMmMouseMove");
3274
+ u(this, "_onWinMmMouseUp");
3275
+ // ── ResizeObserver — tracks container size changes ────────
3276
+ u(this, "_ro", null);
3277
+ u(this, "_onFoldBtnClick", (e) => {
3278
+ const t = e.target.closest(".sl-fold-btn");
3279
+ if (!t) return;
3280
+ e.preventDefault(), e.stopPropagation();
3281
+ const i = parseInt(t.dataset.row ?? "0", 10);
3282
+ this._foldedLines = dt(this._foldedLines, this._tab.doc, i), this._tokenCache.clear(), this._rebuildWrapMap(), this._render();
3283
+ });
3284
+ this._config = { ...Ft, ...ye(t) }, this._onWinMouseUp = () => {
3285
+ this._isDragging = !1, this._dragAnchor = null;
3286
+ }, this._onEditorScroll = Z(() => {
3287
+ this._hideHover(), this._scheduleRender(), this._updateMinimap();
3288
+ }, 16), this._onWinResize = Z(() => {
3289
+ this._config.wordWrap && this._rebuildWrapMap(), this._scheduleRender();
3290
+ }, 100), this._onWinMmMouseMove = (o) => {
3291
+ if (this._mmDragMode === "none") return;
3292
+ const c = this._minimapWrap.clientHeight;
3293
+ if (this._mmDragMode === "slider") {
3294
+ const d = o.clientY - this._minimapWrap.getBoundingClientRect().top;
3295
+ this._editorEl.scrollTop = Wt(
3296
+ d - this._mmSliderOffset,
3297
+ this._tab.doc.length,
3298
+ this._editorEl.clientHeight,
3299
+ c,
3300
+ this._config.lineHeight
3301
+ );
3302
+ } else {
3303
+ const d = o.clientY - this._mmDragStartY, p = Math.max(0, this._tab.doc.length * this._config.lineHeight - this._editorEl.clientHeight);
3304
+ this._editorEl.scrollTop = Math.max(0, Math.min(p, this._mmDragStartScroll + d / 2 * this._config.lineHeight));
3305
+ }
3306
+ this._render();
3307
+ }, this._onWinMmMouseUp = () => {
3308
+ this._mmDragMode !== "none" && (this._mmDragMode = "none", this._minimapWrap.style.cursor = "pointer");
3309
+ }, this._host = e, this._host.classList.add("sl-host"), this._shadow = this._host.attachShadow({ mode: "open" });
3310
+ const i = L("style");
3311
+ i.textContent = nt, this._shadow.appendChild(i), this._dynamicStyleEl = L("style"), this._shadow.appendChild(this._dynamicStyleEl), this._themeManager = new rt(this._host);
3312
+ const r = typeof this._config.theme == "string" ? this._config.theme : this._config.theme;
3313
+ this._themeManager.apply(r);
3314
+ const n = L("div", "sl-layout"), a = L("div", "sl-ed-pane");
3315
+ this._inputEl = L("textarea", "sl-input"), this._inputEl.setAttribute("autocomplete", "off"), this._inputEl.setAttribute("autocorrect", "off"), this._inputEl.setAttribute("autocapitalize", "off"), this._inputEl.setAttribute("spellcheck", "false"), this._inputEl.setAttribute("role", "textbox"), this._inputEl.setAttribute("aria-multiline", "true"), this._inputEl.setAttribute("aria-label", "Code editor"), this._inputEl.setAttribute("aria-readonly", String(!!this._config.readOnly)), this._inputEl.setAttribute("aria-haspopup", "listbox"), this._editorEl = L("div", "sl-editor"), this._spacerEl = L("div", "sl-spacer"), this._vpEl = L("div", "sl-vp"), this._editorEl.appendChild(this._spacerEl), this._editorEl.appendChild(this._vpEl), this._findBar = this._buildFindBar(), this._findInput = this._findBar.querySelector(".sl-find-input"), this._replaceInput = this._findBar.querySelector(".sl-find-replace-input"), this._findCount = this._findBar.querySelector(".sl-find-count"), this._replaceRow = this._findBar.querySelector(".sl-replace-row"), a.appendChild(this._inputEl), a.appendChild(this._findBar), a.appendChild(this._editorEl), this._minimapWrap = L("div", "sl-minimap"), this._minimapWrap.style.width = `${this._config.minimapWidth}px`, this._mmCanvas = L("canvas", ""), this._mmSlider = L("div", "sl-mm-slider"), this._minimapWrap.appendChild(this._mmCanvas), this._minimapWrap.appendChild(this._mmSlider), n.appendChild(a), this._config.showMinimap && n.appendChild(this._minimapWrap), this._statusBar = this._buildStatusBar(), this._acPopup = L("div", "sl-ac-popup"), this._acPopup.setAttribute("role", "listbox"), this._acPopup.setAttribute("aria-label", "Code suggestions"), this._acPopup.style.display = "none", this._emmetTip = L("div", "sl-emmet-tip"), this._emmetTip.style.display = "none", this._snippetTip = L("div", "sl-emmet-tip"), this._snippetTip.style.display = "none", this._hoverTip = L("div", "sl-hover-tip"), this._hoverTip.style.display = "none", this._hoverTip.addEventListener("mouseenter", () => {
3316
+ this._hoverPinned = !0;
3317
+ }), this._hoverTip.addEventListener("mouseleave", () => {
3318
+ this._hoverPinned = !1, this._hideHover();
3319
+ }), this._themeOverlay = L("div", "sl-theme-overlay"), this._themeOverlay.style.display = "none", this._themePanel = L("div", "sl-theme-panel"), this._themeOverlay.appendChild(this._themePanel), this._shadow.appendChild(n), this._config.showStatusBar && this._shadow.appendChild(this._statusBar), this._shadow.appendChild(this._acPopup), this._shadow.appendChild(this._emmetTip), this._shadow.appendChild(this._snippetTip), this._shadow.appendChild(this._hoverTip), this._shadow.appendChild(this._themeOverlay);
3320
+ const l = typeof this._config.value == "string" ? me(this._config.value) : this._config.value;
3321
+ this._tab = ue(1, l.length ? l : [""]), this._mmColors = Me((o) => X(o, this._host)), this._bindEditorEvents(), this._bindMinimapEvents(), this._bindFindEvents(), this._applyDynamicStyles(), typeof ResizeObserver < "u" && (this._ro = new ResizeObserver(Z(() => {
3322
+ this._config.wordWrap && (this._rebuildWrapMap(), this._scheduleRender());
3323
+ }, 60)), this._ro.observe(this._host)), this._rebuildWrapMap(), this._render();
3324
+ }
3325
+ // ── Public API ────────────────────────────────────────────
3326
+ getValue() {
3327
+ return D(this._tab.doc);
3328
+ }
3329
+ setValue(e) {
3330
+ var t, i;
3331
+ E(this._tab, this._config.maxUndoHistory), this._tab.doc = me(e), this._tab.cur = { row: 0, col: 0 }, this._tab.sel = null, this._tokenCache.clear(), this._foldedLines.clear(), this._rebuildWrapMap(), this._render(), (i = (t = this._config).onChange) == null || i.call(t, e);
3332
+ }
3333
+ getCursor() {
3334
+ return { ...this._tab.cur };
3335
+ }
3336
+ setCursor(e) {
3337
+ this._tab.cur = { ...e }, A(this._tab), this._scrollIntoView(), this._render();
3338
+ }
3339
+ getSelection() {
3340
+ return this._tab.sel ? { ...this._tab.sel } : null;
3341
+ }
3342
+ setSelection(e) {
3343
+ this._tab.sel = e, this._render();
3344
+ }
3345
+ insertText(e) {
3346
+ this._config.readOnly || (this._insertStr(e, !1), this._rebuildWrapMap(), A(this._tab), this._scrollIntoView(), this._render());
3347
+ }
3348
+ setTheme(e) {
3349
+ this._themeManager.apply(e), this._applyTokenOverrides(), this._mmColors = Me((t) => X(t, this._host)), this._tokenCache.clear(), this._render();
3350
+ }
3351
+ updateConfig(e) {
3352
+ const t = ye(e);
3353
+ if (t.autoClosePairs !== void 0) {
3354
+ const i = t.autoClosePairs;
3355
+ this._config.autoClosePairs = Object.keys(i).length === 0 ? {} : { ...this._config.autoClosePairs, ...i };
3356
+ const { autoClosePairs: r, ...n } = t;
3357
+ Object.assign(this._config, n);
3358
+ } else
3359
+ Object.assign(this._config, t);
3360
+ if (t.readOnly !== void 0 && this._inputEl.setAttribute("aria-readonly", String(!!t.readOnly)), e.theme !== void 0 && this.setTheme(e.theme), (e.wordWrap !== void 0 || e.wrapColumn !== void 0) && this._rebuildWrapMap(), e.showMinimap !== void 0) {
3361
+ const i = this._shadow.querySelector(".sl-layout");
3362
+ e.showMinimap ? i.contains(this._minimapWrap) || i.appendChild(this._minimapWrap) : this._minimapWrap.remove();
3363
+ }
3364
+ e.showStatusBar !== void 0 && (e.showStatusBar ? this._shadow.contains(this._statusBar) || this._shadow.appendChild(this._statusBar) : this._statusBar.remove()), (e.fontFamily !== void 0 || e.fontSize !== void 0 || e.lineHeight !== void 0 || e.cursorBlinkRate !== void 0 || e.cursorStyle !== void 0 || e.gutterWidth !== void 0 || e.minimapWidth !== void 0 || e.showGutter !== void 0 || e.tokenColors !== void 0) && this._applyDynamicStyles(), (e.language !== void 0 || e.extraKeywords !== void 0 || e.extraTypes !== void 0 || e.renderWhitespace !== void 0 || e.completions !== void 0) && this._tokenCache.clear(), e.find === !1 ? this._closeFind() : e.findReplace === !1 && (this._replaceRow.style.display = "none"), this._render();
3365
+ }
3366
+ focus() {
3367
+ this._focusInput();
3368
+ }
3369
+ getThemes() {
3370
+ return this._themeManager.allIds;
3371
+ }
3372
+ registerTheme(e) {
3373
+ this._themeManager.register(e);
3374
+ }
3375
+ undo() {
3376
+ var e, t;
3377
+ Oe(this._tab) && (this._tokenCache.clear(), this._rebuildWrapMap(), A(this._tab), this._scrollIntoView(), this._render(), (t = (e = this._config).onChange) == null || t.call(e, D(this._tab.doc)));
3378
+ }
3379
+ redo() {
3380
+ var e, t;
3381
+ Fe(this._tab) && (this._tokenCache.clear(), this._rebuildWrapMap(), A(this._tab), this._scrollIntoView(), this._render(), (t = (e = this._config).onChange) == null || t.call(e, D(this._tab.doc)));
3382
+ }
3383
+ executeCommand(e) {
3384
+ const t = this._config.readOnly;
3385
+ switch (e) {
3386
+ case "undo":
3387
+ t || this.undo();
3388
+ break;
3389
+ case "redo":
3390
+ t || this.redo();
3391
+ break;
3392
+ case "selectAll":
3393
+ this._selectAll();
3394
+ break;
3395
+ case "copy":
3396
+ this._doCopy();
3397
+ break;
3398
+ case "cut":
3399
+ t || this._doCut();
3400
+ break;
3401
+ case "toggleComment":
3402
+ t || this._toggleComment();
3403
+ break;
3404
+ case "duplicateLine":
3405
+ t || this._duplicateLine();
3406
+ break;
3407
+ case "deleteLine":
3408
+ t || this._deleteLine();
3409
+ break;
3410
+ case "toggleWordWrap":
3411
+ this._toggleWrap();
3412
+ break;
3413
+ case "find":
3414
+ this._config.find && this._openFind(!1);
3415
+ break;
3416
+ case "findReplace":
3417
+ this._config.find && this._config.findReplace && this._openFind(!0);
3418
+ break;
3419
+ case "indentLine":
3420
+ t || this._indentSel();
3421
+ break;
3422
+ case "outdentLine":
3423
+ t || this._unindentSel();
3424
+ break;
3425
+ default:
3426
+ console.warn(`[syncline-editor] executeCommand: unknown command "${e}"`);
3427
+ break;
3428
+ }
3429
+ }
3430
+ destroy() {
3431
+ var t;
3432
+ this._acDebounceTimer !== null && (clearTimeout(this._acDebounceTimer), this._acDebounceTimer = null), this._hoverTimer !== null && (clearTimeout(this._hoverTimer), this._hoverTimer = null), this._rafId !== null && (cancelAnimationFrame(this._rafId), this._rafId = null), window.removeEventListener("mouseup", this._onWinMouseUp), window.removeEventListener("resize", this._onWinResize), window.removeEventListener("mousemove", this._onWinMmMouseMove), window.removeEventListener("mouseup", this._onWinMmMouseUp), (t = this._ro) == null || t.disconnect();
3433
+ const e = this._mmCanvas.getContext("2d");
3434
+ e && e.clearRect(0, 0, this._mmCanvas.width, this._mmCanvas.height), this._shadow.innerHTML = "", this._host.classList.remove("sl-host");
3435
+ }
3436
+ // ── DOM builders ──────────────────────────────────────────
3437
+ _buildFindBar() {
3438
+ const e = L("div", "sl-find-bar");
3439
+ return e.innerHTML = `
3440
+ <div class="sl-find-row">
3441
+ <input class="sl-find-input" placeholder="Find…" autocomplete="off" spellcheck="false">
3442
+ <span class="sl-find-count">–</span>
3443
+ <button class="sl-find-btn sl-find-prev" title="Previous">↑</button>
3444
+ <button class="sl-find-btn sl-find-next" title="Next">↓</button>
3445
+ <button class="sl-find-btn sl-find-case" title="Match case">Aa</button>
3446
+ <button class="sl-find-btn sl-find-regex" title="Regex">.*</button>
3447
+ <span class="sl-find-x sl-find-close">✕</span>
3448
+ </div>
3449
+ <div class="sl-find-row sl-replace-row" style="display:none">
3450
+ <input class="sl-find-replace-input" placeholder="Replace…" autocomplete="off" spellcheck="false">
3451
+ <button class="sl-find-btn sl-replace-one">Replace</button>
3452
+ <button class="sl-find-btn sl-replace-all">All</button>
3453
+ </div>
3454
+ `, e;
3455
+ }
3456
+ _buildStatusBar() {
3457
+ const e = L("div", "sl-statusbar");
3458
+ return e.innerHTML = `
3459
+ <div class="sl-sb-item sl-no-click sl-sb-lang">⬡ TypeScript</div>
3460
+ <div class="sl-sb-sep"></div>
3461
+ <div class="sl-sb-item sl-no-click sl-sb-pos">Ln 1, Col 1</div>
3462
+ <div class="sl-sb-sep"></div>
3463
+ <div class="sl-sb-item sl-no-click sl-sb-sel"></div>
3464
+ <div class="sl-sb-sep sl-sb-sel-sep" style="display:none"></div>
3465
+ <div class="sl-sb-item sl-no-click sl-sb-lines">1 line</div>
3466
+ <div class="sl-sb-sep"></div>
3467
+ <div class="sl-sb-item sl-no-click">UTF-8 LF</div>
3468
+ <div class="sl-sb-right">
3469
+ <div class="sl-sb-item sl-no-click sl-sb-mc" style="display:none">⊕ <span class="sl-sb-mc-count">1</span> cursors</div>
3470
+ <div class="sl-sb-item sl-sb-wrap sl-sb-wrap-btn">⇥ Wrap: OFF</div>
3471
+ <div class="sl-sb-sep"></div>
3472
+ <div class="sl-sb-item sl-sb-theme-btn">🎨 Theme</div>
3473
+ <div class="sl-sb-sep"></div>
3474
+ <div class="sl-sb-item sl-no-click sl-sb-undo">↩0 ↪0</div>
3475
+ </div>
3476
+ `, e.querySelector(".sl-sb-wrap-btn").addEventListener("click", () => this._toggleWrap()), e.querySelector(".sl-sb-theme-btn").addEventListener("click", () => this._openThemePicker()), e;
3477
+ }
3478
+ // ── Dynamic styles ────────────────────────────────────────
3479
+ _applyDynamicStyles() {
3480
+ const {
3481
+ fontFamily: e,
3482
+ fontSize: t,
3483
+ lineHeight: i,
3484
+ cursorBlinkRate: r,
3485
+ cursorStyle: n,
3486
+ gutterWidth: a,
3487
+ minimapWidth: l,
3488
+ showGutter: o
3489
+ } = this._config, c = Math.max(2, i - 4), d = Math.floor((i - c) / 2);
3490
+ let p = "";
3491
+ n === "block" ? p = `width:${7.82}px;opacity:.5;border-radius:1px;` : n === "underline" && (p = `width:${7.82}px;height:2px;top:${i - 2}px;border-radius:0;`);
3492
+ const h = o ? a : 0;
3493
+ this._dynamicStyleEl.textContent = `
3494
+ .sl-el{font-family:${e};font-size:${t}px;line-height:${i}px}
3495
+ .sl-cl{height:${i}px;line-height:${i}px}
3496
+ .sl-egn{height:${i}px;line-height:${i}px}
3497
+ .sl-eg{min-width:${h}px;width:${h}px;${o ? "" : "display:none"}}
3498
+ .sl-cur::after{height:${c}px;top:${d}px;animation-duration:${r}ms;${p}}
3499
+ .sl-cur-extra::after{height:${c}px;top:${d}px;animation-duration:${r}ms;${p}}
3500
+ `, this._applyTokenOverrides(), this._minimapWrap.style.width = `${l}px`;
3501
+ }
3502
+ /**
3503
+ * Apply tokenColors overrides as inline styles on the host element.
3504
+ * Must be called AFTER the theme has applied its own inline styles so
3505
+ * our values win (last writer wins for element.style.setProperty).
3506
+ * When a token field is empty/absent, restore the active theme's value.
3507
+ */
3508
+ _applyTokenOverrides() {
3509
+ const e = this._config.tokenColors ?? {}, t = this._themeManager.activeTheme, i = this._host.style, r = (a, l, o) => {
3510
+ i.setProperty(a, l || o);
3511
+ }, n = t == null ? void 0 : t.tokens;
3512
+ r("--tok-kw", e.keyword, (n == null ? void 0 : n.tokKw) ?? ""), r("--tok-str", e.string, (n == null ? void 0 : n.tokStr) ?? ""), r("--tok-cmt", e.comment, (n == null ? void 0 : n.tokCmt) ?? ""), r("--tok-fn", e.function, (n == null ? void 0 : n.tokFn) ?? ""), r("--tok-num", e.number, (n == null ? void 0 : n.tokNum) ?? ""), r("--tok-cls", e.class, (n == null ? void 0 : n.tokCls) ?? ""), r("--tok-op", e.operator, (n == null ? void 0 : n.tokOp) ?? ""), r("--tok-typ", e.type, (n == null ? void 0 : n.tokTyp) ?? ""), r("--tok-dec", e.decorator, (n == null ? void 0 : n.tokDec) ?? "");
3513
+ }
3514
+ // ── Core render ───────────────────────────────────────────
3515
+ /**
3516
+ * Schedule a render on the next animation frame.
3517
+ * Multiple calls within a single frame are coalesced into one render —
3518
+ * ideal for scroll and resize handlers which can fire at 60+ Hz.
3519
+ */
3520
+ _scheduleRender() {
3521
+ this._rafId === null && (this._rafId = requestAnimationFrame(() => {
3522
+ this._rafId = null, this._render();
3523
+ }));
3524
+ }
3525
+ _render() {
3526
+ const { doc: e, cur: t, sel: i } = this._tab, { lineHeight: r } = this._config;
3527
+ this._wordHighlights = this._config.wordHighlight ? Ct(e, t.row, t.col, i) : [], this._bracketMatch = this._config.bracketMatching ? ot(e, t) : null;
3528
+ const n = this._wm.visualRows.length;
3529
+ this._spacerEl.style.height = `${n * r}px`;
3530
+ const a = this._editorEl.scrollTop, l = this._editorEl.clientHeight, o = Math.max(0, Math.floor(a / r) - 6), c = Math.min(n - 1, Math.ceil((a + l) / r) + 6);
3531
+ this._vpEl.style.transform = `translateY(${o * r}px)`;
3532
+ const d = F(this._wm, t.row, t.col);
3533
+ let p = "";
3534
+ for (let h = o; h <= c; h++) {
3535
+ const g = this._wm.visualRows[h];
3536
+ g && (p += Rt({
3537
+ vr: g,
3538
+ visIdx: h,
3539
+ curVisRow: d.visRow,
3540
+ curColInSeg: d.colInSeg,
3541
+ docSel: i,
3542
+ findMatches: this._findMatches,
3543
+ findIdx: this._findIdx,
3544
+ wordHighlights: this._wordHighlights,
3545
+ bracketMatch: this._bracketMatch,
3546
+ extraCursors: this._extraCursors,
3547
+ foldedLines: this._foldedLines,
3548
+ isFoldable: this._config.codeFolding && lt(e, g.docLine),
3549
+ wm: this._wm,
3550
+ tokenCache: this._tokenCache,
3551
+ opts: {
3552
+ tokeniserOpts: {
3553
+ language: this._config.language,
3554
+ extraKeywords: new Set(this._config.extraKeywords),
3555
+ extraTypes: new Set(this._config.extraTypes)
3556
+ },
3557
+ showIndentGuides: this._config.showIndentGuides,
3558
+ highlightActiveLine: this._config.highlightActiveLine,
3559
+ charWidth: 7.82,
3560
+ codePaddingLeft: 14,
3561
+ tabSize: this._config.tabSize,
3562
+ lineHeight: r,
3563
+ renderWhitespace: this._config.renderWhitespace
3564
+ }
3565
+ }));
3566
+ }
3567
+ this._vpEl.innerHTML = p, this._updateStatusBar(), this._updateMinimap();
3568
+ }
3569
+ // ── Status bar ────────────────────────────────────────────
3570
+ _updateStatusBar() {
3571
+ if (!this._config.showStatusBar) return;
3572
+ const { cur: e, doc: t, undoStack: i, redoStack: r } = this._tab, n = this._config.language, a = {
3573
+ typescript: "TypeScript",
3574
+ javascript: "JavaScript",
3575
+ css: "CSS",
3576
+ json: "JSON",
3577
+ markdown: "Markdown",
3578
+ text: "Text"
3579
+ }, l = (h) => this._statusBar.querySelector(h);
3580
+ l(".sl-sb-lang").textContent = `⬡ ${a[n] ?? n}`, l(".sl-sb-pos").textContent = `Ln ${e.row + 1}, Col ${e.col + 1}`, l(".sl-sb-lines").textContent = `${t.length.toLocaleString()} lines`;
3581
+ const o = Ue(this._tab), c = l(".sl-sb-sel"), d = l(".sl-sb-sel-sep");
3582
+ c.textContent = o ? `${o.toLocaleString()} selected` : "", d.style.display = o ? "" : "none", l(".sl-sb-undo").textContent = `↩${i.length} ↪${r.length}`;
3583
+ const p = l(".sl-sb-mc");
3584
+ this._extraCursors.length ? (p.style.display = "", l(".sl-sb-mc-count").textContent = String(this._extraCursors.length + 1)) : p.style.display = "none";
3585
+ }
3586
+ // ── Minimap ───────────────────────────────────────────────
3587
+ _updateMinimap() {
3588
+ if (!this._config.showMinimap) return;
3589
+ const e = this._minimapWrap.clientWidth, t = this._minimapWrap.clientHeight;
3590
+ if (!e || !t) return;
3591
+ const i = this._tab.doc, r = i.length, n = Math.min(window.devicePixelRatio || 1, 2), a = this._config.lineHeight, { mmScroll: l, sliderTop: o, sliderHeight: c } = ie(
3592
+ r,
3593
+ this._editorEl.scrollTop,
3594
+ this._editorEl.clientHeight,
3595
+ t,
3596
+ a
3597
+ ), d = l / 2, p = Math.floor(d), h = Math.ceil(t / 2) + 2, g = Math.min(r, p + h), y = (g - p) * 2, v = (d - p) * 2, f = Math.round(e * n), b = Math.round(y * n);
3598
+ (this._mmCanvas.width !== f || this._mmCanvas.height !== b) && (this._mmCanvas.width = f, this._mmCanvas.height = b, this._mmCanvas.style.width = `${e}px`, this._mmCanvas.style.height = `${y}px`), this._mmCanvas.style.transform = `translateY(${-v}px)`, Ot({
3599
+ canvas: this._mmCanvas,
3600
+ doc: i,
3601
+ firstLine: p,
3602
+ lastLine: g,
3603
+ subPx: v,
3604
+ wrapperWidth: e,
3605
+ canvasHeight: y,
3606
+ cursorRow: this._tab.cur.row,
3607
+ sel: this._tab.sel,
3608
+ findMatches: this._findMatches,
3609
+ findIdx: this._findIdx,
3610
+ sliderTop: o,
3611
+ sliderHeight: c,
3612
+ colors: this._mmColors,
3613
+ getCssVar: (T) => X(T, this._host),
3614
+ dpr: n
3615
+ }), this._mmSlider.style.top = `${Math.max(0, Math.min(t - c, o))}px`, this._mmSlider.style.height = `${c}px`;
3616
+ }
3617
+ // ── WrapMap ───────────────────────────────────────────────
3618
+ _rebuildWrapMap() {
3619
+ let e;
3620
+ if (this._config.wordWrap) {
3621
+ const t = this._config.showGutter ? this._config.gutterWidth : 0, i = this._editorEl.clientWidth;
3622
+ if (i > 0) {
3623
+ const r = i - t - 14 - 20;
3624
+ e = Math.max(20, Math.floor(r / 7.82));
3625
+ } else
3626
+ e = this._config.wrapColumn;
3627
+ } else
3628
+ e = 9999;
3629
+ this._wm = Ge(
3630
+ this._tab.doc,
3631
+ e,
3632
+ this._config.wordWrap,
3633
+ this._foldedLines
3634
+ );
3635
+ }
3636
+ // ── Scroll ────────────────────────────────────────────────
3637
+ _scrollIntoView() {
3638
+ const e = this._tab.cur, i = F(this._wm, e.row, e.col).visRow * this._config.lineHeight, r = i + this._config.lineHeight, n = this._editorEl.scrollTop, a = this._editorEl.clientHeight, l = this._config.lineHeight * 3;
3639
+ i < n + l ? this._editorEl.scrollTop = Math.max(0, i - l) : r > n + a - l && (this._editorEl.scrollTop = r - a + l);
3640
+ }
3641
+ // ── Input helpers ─────────────────────────────────────────
3642
+ _focusInput() {
3643
+ this._inputEl.style.pointerEvents = "auto", this._inputEl.focus(), this._inputEl.style.pointerEvents = "none";
3644
+ }
3645
+ _insertStr(e, t) {
3646
+ var d, p;
3647
+ const i = Date.now();
3648
+ (!t || i - this._lastInputTime > this._config.undoBatchMs) && E(this._tab, this._config.maxUndoHistory), this._lastInputTime = i, this._tab.sel && (this._tab.cur = O(this._tab));
3649
+ const { doc: r, cur: n } = this._tab, a = e.split(`
3650
+ `), l = r[n.row] ?? "", o = l.slice(0, n.col), c = l.slice(n.col);
3651
+ if (a.length === 1)
3652
+ r[n.row] = o + e + c, n.col += e.length;
3653
+ else {
3654
+ const h = [o + a[0]];
3655
+ for (let g = 1; g < a.length - 1; g++) h.push(a[g]);
3656
+ h.push(a[a.length - 1] + c), r.splice(n.row, 1, ...h), n.row += a.length - 1, n.col = a[a.length - 1].length;
3657
+ }
3658
+ this._tokenCache.invalidateLine(n.row, (this._wm.segments[n.row] ?? [""]).length), this._tab.dirty = !0, (p = (d = this._config).onChange) == null || p.call(d, D(r));
3659
+ }
3660
+ _doBackspace() {
3661
+ var i;
3662
+ if (E(this._tab, this._config.maxUndoHistory), this._tab.sel) {
3663
+ this._tab.cur = O(this._tab), this._tokenCache.clear(), this._tab.dirty = !0;
3664
+ return;
3665
+ }
3666
+ const { doc: e, cur: t } = this._tab;
3667
+ if (t.col > 0) {
3668
+ const r = e[t.row] ?? "", n = r.slice(0, t.col), a = n.length >= 2 && n.endsWith(" ") && !n.trim() ? 2 : 1;
3669
+ e[t.row] = r.slice(0, t.col - a) + r.slice(t.col), t.col -= a, this._tokenCache.invalidateLine(t.row, ((i = this._wm.segments[t.row]) == null ? void 0 : i.length) ?? 1);
3670
+ } else if (t.row > 0) {
3671
+ const r = (e[t.row - 1] ?? "").length;
3672
+ e[t.row - 1] += e[t.row] ?? "", e.splice(t.row, 1), t.row--, t.col = r, this._tokenCache.clear();
3673
+ }
3674
+ this._tab.dirty = !0;
3675
+ }
3676
+ _doEnter() {
3677
+ E(this._tab, this._config.maxUndoHistory), this._tab.sel && (this._tab.cur = O(this._tab));
3678
+ const { doc: e, cur: t } = this._tab, i = e[t.row] ?? "", r = i.slice(0, t.col), n = i.slice(t.col), a = _e(i), l = r.trimEnd().endsWith("{") ? J(this._config.tabSize) : "";
3679
+ e[t.row] = r, r.trimEnd().endsWith("{") && n.trimStart() === "}" ? e.splice(t.row + 1, 0, a + l, a + n) : e.splice(t.row + 1, 0, a + l + n), t.row++, t.col = a.length + l.length, this._tokenCache.clear(), this._tab.dirty = !0;
3680
+ }
3681
+ _doDelete() {
3682
+ var r;
3683
+ if (E(this._tab, this._config.maxUndoHistory), this._tab.sel) {
3684
+ this._tab.cur = O(this._tab), this._tokenCache.clear(), this._tab.dirty = !0;
3685
+ return;
3686
+ }
3687
+ const { doc: e, cur: t } = this._tab, i = e[t.row] ?? "";
3688
+ t.col < i.length ? (e[t.row] = i.slice(0, t.col) + i.slice(t.col + 1), this._tokenCache.invalidateLine(t.row, ((r = this._wm.segments[t.row]) == null ? void 0 : r.length) ?? 1)) : t.row < e.length - 1 && (e[t.row] = i + (e[t.row + 1] ?? ""), e.splice(t.row + 1, 1), this._tokenCache.clear()), this._tab.dirty = !0;
3689
+ }
3690
+ // ── Editing commands ──────────────────────────────────────
3691
+ _selectAll() {
3692
+ const e = this._tab.doc, t = e.length - 1;
3693
+ this._tab.sel = { ar: 0, ac: 0, fr: t, fc: (e[t] ?? "").length }, this._tab.cur = { row: t, col: (e[t] ?? "").length }, this._render();
3694
+ }
3695
+ _doCopy() {
3696
+ var t;
3697
+ const e = ge(this._tab);
3698
+ e && ((t = navigator.clipboard) == null || t.writeText(e).catch(() => {
3699
+ }));
3700
+ }
3701
+ _doCut() {
3702
+ var t, i, r;
3703
+ const e = ge(this._tab);
3704
+ e && ((t = navigator.clipboard) == null || t.writeText(e).catch(() => {
3705
+ }), E(this._tab, this._config.maxUndoHistory), this._tab.cur = O(this._tab), this._tokenCache.clear(), this._tab.dirty = !0, this._rebuildWrapMap(), this._render(), (r = (i = this._config).onChange) == null || r.call(i, D(this._tab.doc)));
3706
+ }
3707
+ _toggleComment() {
3708
+ var n, a;
3709
+ E(this._tab, this._config.maxUndoHistory);
3710
+ const e = this._getSelRows(), t = this._config.lineCommentToken || Re[this._config.language] || "";
3711
+ if (!t) return;
3712
+ const i = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), r = e.every((l) => (this._tab.doc[l] ?? "").trimStart().startsWith(t));
3713
+ e.forEach((l) => {
3714
+ var c;
3715
+ const o = this._tab.doc[l] ?? "";
3716
+ this._tab.doc[l] = r ? o.replace(new RegExp(`^(\\s*)${i}\\s?`), "$1") : o.replace(/^(\s*)/, `$1${t} `), this._tokenCache.invalidateLine(l, ((c = this._wm.segments[l]) == null ? void 0 : c.length) ?? 1);
3717
+ }), this._tab.dirty = !0, this._rebuildWrapMap(), this._render(), (a = (n = this._config).onChange) == null || a.call(n, D(this._tab.doc));
3718
+ }
3719
+ _duplicateLine() {
3720
+ var t, i;
3721
+ E(this._tab, this._config.maxUndoHistory);
3722
+ const e = this._tab.cur.row;
3723
+ this._tab.doc.splice(e + 1, 0, this._tab.doc[e] ?? ""), this._tab.cur.row++, this._tokenCache.clear(), this._tab.dirty = !0, this._rebuildWrapMap(), this._render(), (i = (t = this._config).onChange) == null || i.call(t, D(this._tab.doc));
3724
+ }
3725
+ _deleteLine() {
3726
+ var i, r;
3727
+ E(this._tab, this._config.maxUndoHistory);
3728
+ const { doc: e, cur: t } = this._tab;
3729
+ e.length > 1 ? e.splice(t.row, 1) : (e[0] = "", t.col = 0), this._tokenCache.clear(), this._tab.dirty = !0, A(this._tab), this._rebuildWrapMap(), this._render(), (r = (i = this._config).onChange) == null || r.call(i, D(this._tab.doc));
3730
+ }
3731
+ _indentSel() {
3732
+ var t, i;
3733
+ if (!this._tab.sel) {
3734
+ this._insertStr(J(this._config.tabSize), !1);
3735
+ return;
3736
+ }
3737
+ E(this._tab, this._config.maxUndoHistory);
3738
+ const e = J(this._config.tabSize);
3739
+ this._getSelRows().forEach((r) => {
3740
+ var n;
3741
+ this._tab.doc[r] = e + (this._tab.doc[r] ?? ""), this._tokenCache.invalidateLine(r, ((n = this._wm.segments[r]) == null ? void 0 : n.length) ?? 1);
3742
+ }), this._tab.dirty = !0, this._rebuildWrapMap(), this._render(), (i = (t = this._config).onChange) == null || i.call(t, D(this._tab.doc));
3743
+ }
3744
+ _unindentSel() {
3745
+ var t, i;
3746
+ E(this._tab, this._config.maxUndoHistory);
3747
+ const e = this._config.tabSize;
3748
+ this._getSelRows().forEach((r) => {
3749
+ var a;
3750
+ const n = this._tab.doc[r] ?? "";
3751
+ n.startsWith(J(e)) ? this._tab.doc[r] = n.slice(e) : n.startsWith(" ") && (this._tab.doc[r] = n.slice(1)), this._tokenCache.invalidateLine(r, ((a = this._wm.segments[r]) == null ? void 0 : a.length) ?? 1);
3752
+ }), this._tab.dirty = !0, this._rebuildWrapMap(), this._render(), (i = (t = this._config).onChange) == null || i.call(t, D(this._tab.doc));
3753
+ }
3754
+ _toggleWrap() {
3755
+ this._config.wordWrap = !this._config.wordWrap, this._vpEl.classList.toggle("sl-wrap-mode", this._config.wordWrap);
3756
+ const e = this._statusBar.querySelector(".sl-sb-wrap-btn");
3757
+ e && (e.textContent = `⇥ Wrap: ${this._config.wordWrap ? "ON" : "OFF"}`, e.classList.toggle("sl-on", this._config.wordWrap)), this._tokenCache.clear(), this._rebuildWrapMap(), this._render();
3758
+ }
3759
+ _getSelRows() {
3760
+ if (!this._tab.sel) return [this._tab.cur.row];
3761
+ const e = P(this._tab.sel), t = [];
3762
+ for (let i = e.ar; i <= e.fr; i++) t.push(i);
3763
+ return t;
3764
+ }
3765
+ // ── Mouse position helper ─────────────────────────────────
3766
+ _posFromMouse(e) {
3767
+ var c;
3768
+ const t = this._editorEl.getBoundingClientRect(), i = e.clientY - t.top + this._editorEl.scrollTop, r = this._config.showGutter ? this._config.gutterWidth : 0, n = e.clientX - t.left - r - 14, a = this._config.lineHeight, l = Math.max(0, Math.min(this._wm.visualRows.length - 1, Math.floor(i / a))), o = Math.max(0, Math.min(
3769
+ (((c = this._wm.visualRows[l]) == null ? void 0 : c.text) ?? "").length,
3770
+ Math.round(n / 7.82)
3771
+ ));
3772
+ return Y(this._wm, l, o);
3773
+ }
3774
+ // ── Find ──────────────────────────────────────────────────
3775
+ _openFind(e) {
3776
+ this._findBar.classList.add("sl-open"), this._replaceRow.style.display = e && this._config.findReplace ? "" : "none", this._findInput.focus(), this._findInput.select(), this._runFind(this._findInput.value), this._findMatches.length ? (this._findIdx = -1, this._navFind(1)) : this._render();
3777
+ }
3778
+ _closeFind() {
3779
+ this._findBar.classList.remove("sl-open"), this._findMatches = [], this._findIdx = -1, this._findCount.textContent = "–", this._focusInput(), this._render();
3780
+ }
3781
+ _runFind(e) {
3782
+ this._findMatches = wt(this._tab.doc, e, {
3783
+ caseSensitive: this._findCaseSensitive,
3784
+ useRegex: this._findRegex
3785
+ });
3786
+ }
3787
+ _navFind(e) {
3788
+ if (!this._findMatches.length) {
3789
+ this._findCount.textContent = "0/0";
3790
+ return;
3791
+ }
3792
+ this._findIdx = Tt(this._findMatches, this._findIdx, e);
3793
+ const t = this._findMatches[this._findIdx];
3794
+ this._tab.cur = { row: t.row, col: t.col }, this._tab.sel = { ar: t.row, ac: t.col, fr: t.row, fc: t.col + t.len }, this._scrollIntoView(), this._render(), this._findCount.textContent = `${this._findIdx + 1}/${this._findMatches.length}`;
3795
+ }
3796
+ // ── Autocomplete ──────────────────────────────────────────
3797
+ _acVisible() {
3798
+ return this._acPopup.style.display !== "none";
3799
+ }
3800
+ _acHide() {
3801
+ this._acPopup.style.display = "none", this._acItems = [];
3802
+ }
3803
+ /**
3804
+ * Schedule an autocomplete refresh after a brief debounce pause.
3805
+ * Prevents the suggestion engine running on every single keystroke —
3806
+ * only fires when the user pauses for `AC_DEBOUNCE_MS` milliseconds.
3807
+ * Call `_acTriggerNow()` directly when an immediate refresh is required
3808
+ * (e.g., on explicit Ctrl+Space or arrow-key navigation).
3809
+ */
3810
+ _acTrigger() {
3811
+ if (!this._config.autocomplete) {
3812
+ this._acHide();
3813
+ return;
3814
+ }
3815
+ this._acDebounceTimer !== null && clearTimeout(this._acDebounceTimer), this._acDebounceTimer = setTimeout(() => {
3816
+ this._acDebounceTimer = null, this._acTriggerNow();
3817
+ }, 120);
3818
+ }
3819
+ /** Run an autocomplete refresh immediately (no debounce). */
3820
+ _acTriggerNow() {
3821
+ if (!this._config.autocomplete) {
3822
+ this._acHide();
3823
+ return;
3824
+ }
3825
+ const { cur: e, doc: t } = this._tab, i = t[e.row] ?? "", r = this._config.language === "css", { prefix: n, start: a } = At(i, e.col, r);
3826
+ this._acPrefix = n, this._acStartCol = a;
3827
+ const l = [];
3828
+ if (this._config.emmet) {
3829
+ const c = we(i, e.col);
3830
+ if (c) {
3831
+ const d = ve(c.abbr);
3832
+ if (d) {
3833
+ this._emmetAcStartCol = c.start;
3834
+ const p = d.replace(/\n/g, "↵ ").slice(0, 60);
3835
+ l.push({ label: c.abbr, kind: "emmet", detail: p, body: d });
3836
+ }
3837
+ }
3838
+ }
3839
+ const o = n.length >= this._config.autocompletePrefixLength ? It(t, n, {
3840
+ language: this._config.language,
3841
+ extraKeywords: this._config.extraKeywords,
3842
+ extraTypes: this._config.extraTypes,
3843
+ completions: this._allCompletions(),
3844
+ replaceBuiltins: this._config.replaceBuiltins,
3845
+ maxResults: this._config.maxCompletions,
3846
+ provideCompletions: this._config.provideCompletions
3847
+ }, e.row, e.col) : [];
3848
+ if (this._acItems = [...l, ...o], !this._acItems.length) {
3849
+ this._acHide();
3850
+ return;
3851
+ }
3852
+ this._acSel = 0, this._renderAcPopup();
3853
+ }
3854
+ _renderAcPopup() {
3855
+ const e = (o) => {
3856
+ switch (o) {
3857
+ case "kw":
3858
+ return "K";
3859
+ case "fn":
3860
+ return "f";
3861
+ case "typ":
3862
+ return "T";
3863
+ case "cls":
3864
+ return "C";
3865
+ case "snip":
3866
+ return "S";
3867
+ case "emmet":
3868
+ return "E";
3869
+ default:
3870
+ return "·";
3871
+ }
3872
+ }, t = this._acItems[this._acSel];
3873
+ let i = "";
3874
+ t != null && t.description ? i = t.description : (t == null ? void 0 : t.kind) === "snip" && t.body ? i = t.body.replace(/\$\d/g, "▌") : (t == null ? void 0 : t.kind) === "emmet" && t.body && (i = t.body);
3875
+ const r = this._acItems.map((o, c) => {
3876
+ const d = c === this._acSel;
3877
+ return `<div class="sl-ac-item${d ? " sl-sel" : ""}" data-i="${c}" role="option" aria-selected="${d}"><span class="sl-ac-badge ${o.kind}">${e(o.kind)}</span><span class="sl-ac-label">${o.label}</span><span class="sl-ac-detail">${o.detail ?? ""}</span></div>`;
3878
+ }).join(""), n = i ? `<div class="sl-ac-desc"><pre class="sl-ac-desc-body">${i.replace(/</g, "&lt;")}</pre></div>` : "";
3879
+ this._acPopup.innerHTML = `<div class="sl-ac-list">${r}</div>` + n, this._acPopup.style.display = "flex", this._posAcPopup();
3880
+ const a = this._acPopup.querySelector(".sl-ac-list"), l = this._acPopup.querySelector(".sl-ac-item.sl-sel");
3881
+ if (a && l) {
3882
+ const o = l.offsetTop, c = o + l.offsetHeight;
3883
+ c > a.scrollTop + a.clientHeight ? a.scrollTop = c - a.clientHeight : o < a.scrollTop && (a.scrollTop = o);
3884
+ }
3885
+ this._acPopup.querySelectorAll(".sl-ac-item").forEach((o) => {
3886
+ o.addEventListener("mousedown", (c) => {
3887
+ c.preventDefault(), this._acSel = parseInt(o.dataset.i ?? "0", 10), this._acAccept();
3888
+ });
3889
+ });
3890
+ }
3891
+ _posAcPopup() {
3892
+ const e = this._editorEl.getBoundingClientRect(), t = F(this._wm, this._tab.cur.row, this._tab.cur.col), i = this._config.showGutter ? this._config.gutterWidth : 0, r = e.left + i + 14 + this._acStartCol * 7.82, n = e.top + (t.visRow * this._config.lineHeight - this._editorEl.scrollTop) + this._config.lineHeight + 2, l = !!this._acPopup.querySelector(".sl-ac-desc") ? 620 : 300, o = Math.min(this._acItems.length * 28 + 8, 320), c = n + o > window.innerHeight - 16;
3893
+ this._acPopup.style.left = `${Math.min(r, window.innerWidth - l - 16)}px`, this._acPopup.style.top = `${c ? n - this._config.lineHeight - 2 - o : n}px`;
3894
+ }
3895
+ _acAccept() {
3896
+ const e = this._acItems[this._acSel];
3897
+ if (!e) return;
3898
+ if (this._acHide(), e.kind === "emmet" && e.body) {
3899
+ E(this._tab, this._config.maxUndoHistory), this._expandBodyAt(e.body, this._emmetAcStartCol);
3900
+ return;
3901
+ }
3902
+ if (e.body) {
3903
+ E(this._tab, this._config.maxUndoHistory), this._expandBodyAt(e.body, this._acStartCol);
3904
+ return;
3905
+ }
3906
+ const t = e.label.slice(this._acPrefix.length);
3907
+ this._insertStr(t, !1), this._rebuildWrapMap(), A(this._tab), this._scrollIntoView(), this._render();
3908
+ }
3909
+ // ── Emmet ─────────────────────────────────────────────────
3910
+ _emmetCheck() {
3911
+ if (this._emmetTip.style.display = "none", !this._config.emmet) {
3912
+ this._emmetExpanded = null;
3913
+ return;
3914
+ }
3915
+ const { cur: e, doc: t } = this._tab, i = t[e.row] ?? "", r = we(i, e.col);
3916
+ if (!r) {
3917
+ this._emmetExpanded = null;
3918
+ return;
3919
+ }
3920
+ const n = ve(r.abbr);
3921
+ if (!n) {
3922
+ this._emmetExpanded = null;
3923
+ return;
3924
+ }
3925
+ this._emmetExpanded = { abbr: r.abbr, result: n, start: r.start };
3926
+ }
3927
+ _emmetAccept() {
3928
+ if (!this._emmetExpanded || this._emmetTip.style.display === "none") return !1;
3929
+ const { abbr: e, result: t, start: i } = this._emmetExpanded;
3930
+ return E(this._tab, this._config.maxUndoHistory), this._emmetExpanded = null, this._emmetTip.style.display = "none", this._expandBodyAt(t, i), !0;
3931
+ }
3932
+ // ── Snippets / Completions ────────────────────────────────
3933
+ /** Returns built-in snippets for the current language merged with user completions.
3934
+ * When `replaceBuiltins` is true the language built-ins are suppressed so only
3935
+ * the caller-supplied completions (e.g. MDX_SNIPPETS) are active. */
3936
+ _allCompletions() {
3937
+ return [...this._config.replaceBuiltins ? [] : gt(this._config.language), ...this._config.completions];
3938
+ }
3939
+ _snippetCheck() {
3940
+ if (this._snippetTip.style.display = "none", !this._config.snippetExpansion) {
3941
+ this._snippetExpanded = null;
3942
+ return;
3943
+ }
3944
+ const { cur: e, doc: t } = this._tab, i = t[e.row] ?? "", r = bt(i, e.col, this._allCompletions());
3945
+ if (!r) {
3946
+ this._snippetExpanded = null;
3947
+ return;
3948
+ }
3949
+ this._snippetExpanded = { snippet: r.snippet, start: r.start };
3950
+ }
3951
+ _snippetAccept() {
3952
+ if (!this._snippetExpanded || this._snippetTip.style.display === "none") return !1;
3953
+ const { snippet: e, start: t } = this._snippetExpanded;
3954
+ return e.body ? (E(this._tab, this._config.maxUndoHistory), this._snippetExpanded = null, this._snippetTip.style.display = "none", this._expandBodyAt(e.body, t), !0) : !1;
3955
+ }
3956
+ /**
3957
+ * Expand a snippet/emmet body template at the current cursor position.
3958
+ * `triggerStart` is the column where the trigger word begins.
3959
+ * `cur.col` must be at the end of the trigger (emmet) or at `triggerStart`
3960
+ * when the prefix was already stripped (snippet accepted from popup).
3961
+ * Everything between `triggerStart` and `cur.col` is replaced by `body`.
3962
+ */
3963
+ _expandBodyAt(e, t) {
3964
+ var y, v;
3965
+ const { doc: i, cur: r } = this._tab, n = i[r.row] ?? "", a = n.slice(0, t), l = n.slice(r.col), o = _e(n), c = e.split(`
3966
+ `).map((f, b) => b === 0 ? f : o + f), d = c.join(`
3967
+ `), p = d.indexOf("$1"), h = c.map((f) => f.replace(/\$\d+/g, "")), g = h.length === 1 ? [a + h[0] + l] : [a + h[0], ...h.slice(1, -1), h[h.length - 1] + l];
3968
+ if (i.splice(r.row, 1, ...g), p >= 0) {
3969
+ const f = d.slice(0, p).split(`
3970
+ `), b = f.length - 1, T = f[b].length, _ = (f[b].match(/\$\d+/g) ?? []).join("").length;
3971
+ r.row += b, r.col = (b === 0 ? t : o.length) + (T - _);
3972
+ } else
3973
+ r.row += g.length - 1, r.col = (g[g.length - 1] ?? "").length - l.length;
3974
+ this._tokenCache.clear(), this._tab.dirty = !0, this._rebuildWrapMap(), A(this._tab), this._scrollIntoView(), this._render(), (v = (y = this._config).onChange) == null || v.call(y, D(this._tab.doc));
3975
+ }
3976
+ // ── Theme picker ──────────────────────────────────────────
3977
+ _openThemePicker() {
3978
+ var t;
3979
+ const e = this._themeManager.all;
3980
+ this._themePanel.innerHTML = `
3981
+ <div class="sl-theme-header">
3982
+ <div class="sl-theme-title">Color Theme</div>
3983
+ <div class="sl-theme-close">✕</div>
3984
+ </div>
3985
+ <div class="sl-theme-list">
3986
+ ${e.map((i) => `
3987
+ <div class="sl-theme-item${i.id === this._themeManager.activeId ? " sl-active" : ""}" data-id="${i.id}">
3988
+ <div class="sl-theme-swatch">
3989
+ ${i.tokens.bg0 ? `<span style="background:${i.tokens.bg0}"></span>` : ""}
3990
+ <span style="background:${i.tokens.accent}"></span>
3991
+ <span style="background:${i.tokens.tokStr}"></span>
3992
+ <span style="background:${i.tokens.tokFn}"></span>
3993
+ </div>
3994
+ <div>
3995
+ <div class="sl-theme-name">${i.name}<span class="sl-theme-tag${i.light ? " sl-light" : ""}">${i.light ? "Light" : "Dark"}</span></div>
3996
+ <div class="sl-theme-desc">${i.description}</div>
3997
+ </div>
3998
+ <div class="sl-theme-check">✓</div>
3999
+ </div>
4000
+ `).join("")}
4001
+ </div>
4002
+ `, this._themeOverlay.style.display = "block", (t = this._themePanel.querySelector(".sl-theme-close")) == null || t.addEventListener("click", () => {
4003
+ this._themeOverlay.style.display = "none";
4004
+ }), this._themeOverlay.addEventListener("click", (i) => {
4005
+ i.target === this._themeOverlay && (this._themeOverlay.style.display = "none");
4006
+ }, { once: !0 }), this._themePanel.querySelectorAll(".sl-theme-item").forEach((i) => {
4007
+ i.addEventListener("click", () => {
4008
+ const r = i.dataset.id ?? "";
4009
+ this.setTheme(r), this._themePanel.querySelectorAll(".sl-theme-item").forEach((n) => n.classList.remove("sl-active")), i.classList.add("sl-active");
4010
+ });
4011
+ });
4012
+ }
4013
+ // ── Event binding ─────────────────────────────────────────
4014
+ _bindEditorEvents() {
4015
+ this._vpEl.addEventListener("mousedown", this._onFoldBtnClick), this._editorEl.addEventListener("mousedown", (e) => {
4016
+ if (e.button !== 0) return;
4017
+ e.preventDefault(), this._focusInput(), this._acHide(), this._emmetTip.style.display = "none", e.altKey || (xe(this._mc), this._extraCursors = []);
4018
+ const t = this._posFromMouse(e);
4019
+ if (this._tab.cur = { ...t }, e.detail === 3)
4020
+ this._tab.sel = { ar: t.row, ac: 0, fr: t.row, fc: (this._tab.doc[t.row] ?? "").length }, this._tab.cur.col = this._tab.sel.fc;
4021
+ else if (e.detail === 2 && this._config.wordSelection) {
4022
+ const i = this._tab.doc[t.row] ?? "", r = le(i, t.col, this._isWordChar.bind(this)), n = ce(i, t.col, this._isWordChar.bind(this));
4023
+ r !== n ? (this._tab.sel = { ar: t.row, ac: r, fr: t.row, fc: n }, this._tab.cur.col = n) : this._tab.sel = null;
4024
+ } else {
4025
+ if (e.altKey && this._config.multiCursor) {
4026
+ ke(this._mc, t.row, t.col, null), this._extraCursors = [...this._mc.cursors], this._render();
4027
+ return;
4028
+ }
4029
+ this._tab.sel = null, this._isDragging = !0, this._dragAnchor = { ...t };
4030
+ }
4031
+ A(this._tab), this._render();
4032
+ }), this._editorEl.addEventListener("mousemove", (e) => {
4033
+ if (this._config.hover && !this._hoverPinned && !this._isDragging && this._scheduleHover(e), !this._isDragging || !this._dragAnchor) return;
4034
+ const t = this._posFromMouse(e);
4035
+ this._tab.cur = { ...t }, t.row !== this._dragAnchor.row || t.col !== this._dragAnchor.col ? this._tab.sel = { ar: this._dragAnchor.row, ac: this._dragAnchor.col, fr: t.row, fc: t.col } : this._tab.sel = null, A(this._tab), this._render();
4036
+ }), this._editorEl.addEventListener("mouseleave", () => {
4037
+ this._hoverPinned || this._hideHover();
4038
+ }), window.addEventListener("mouseup", this._onWinMouseUp), this._editorEl.addEventListener("scroll", this._onEditorScroll, { passive: !0 }), window.addEventListener("resize", this._onWinResize), this._inputEl.addEventListener("keydown", (e) => this._onKeyDown(e)), this._inputEl.addEventListener("input", (e) => this._onInput(e)), this._inputEl.addEventListener("paste", (e) => {
4039
+ var i;
4040
+ if (e.preventDefault(), this._config.readOnly) return;
4041
+ const t = (i = e.clipboardData ?? window.clipboardData) == null ? void 0 : i.getData("text/plain");
4042
+ t && (this._insertStr(t, !1), this._tokenCache.clear(), this._rebuildWrapMap(), A(this._tab), this._scrollIntoView(), this._render());
4043
+ }), this._editorEl.addEventListener("mousedown", () => setTimeout(() => this._focusInput(), 0)), this._inputEl.addEventListener("focus", () => {
4044
+ var e, t;
4045
+ return (t = (e = this._config).onFocus) == null ? void 0 : t.call(e);
4046
+ }), this._inputEl.addEventListener("blur", () => {
4047
+ var e, t;
4048
+ return (t = (e = this._config).onBlur) == null ? void 0 : t.call(e);
4049
+ });
4050
+ }
4051
+ _onKeyDown(e) {
4052
+ var a, l, o, c, d, p, h, g, y;
4053
+ const t = e.ctrlKey || e.metaKey, i = e.shiftKey, r = e.altKey, n = this._config.readOnly;
4054
+ if (this._hideHover(), this._acVisible()) {
4055
+ if (e.key === "ArrowDown") {
4056
+ e.preventDefault(), this._acSel = Math.min(this._acItems.length - 1, this._acSel + 1), this._renderAcPopup();
4057
+ return;
4058
+ }
4059
+ if (e.key === "ArrowUp") {
4060
+ e.preventDefault(), this._acSel = Math.max(0, this._acSel - 1), this._renderAcPopup();
4061
+ return;
4062
+ }
4063
+ if (e.key === "Tab" || e.key === "Enter") {
4064
+ e.preventDefault(), this._acAccept();
4065
+ return;
4066
+ }
4067
+ if (e.key === "Escape") {
4068
+ this._acHide();
4069
+ return;
4070
+ }
4071
+ }
4072
+ if (r && (e.key === "z" || e.key === "Z" || e.key === "Ω")) {
4073
+ e.preventDefault(), this._toggleWrap();
4074
+ return;
4075
+ }
4076
+ if (t && e.key === "z" && !i) {
4077
+ e.preventDefault(), n || this.undo();
4078
+ return;
4079
+ }
4080
+ if (t && (e.key === "y" || i && e.key === "z")) {
4081
+ e.preventDefault(), n || this.redo();
4082
+ return;
4083
+ }
4084
+ if (t && e.key === "a") {
4085
+ e.preventDefault(), this._selectAll();
4086
+ return;
4087
+ }
4088
+ if (t && e.key === "c") {
4089
+ e.preventDefault(), this._doCopy();
4090
+ return;
4091
+ }
4092
+ if (t && e.key === "x") {
4093
+ e.preventDefault(), n || this._doCut();
4094
+ return;
4095
+ }
4096
+ if (t && e.key === "f") {
4097
+ e.preventDefault(), this._config.find && this._openFind(!1);
4098
+ return;
4099
+ }
4100
+ if (t && e.key === "h") {
4101
+ e.preventDefault(), this._config.find && this._config.findReplace && this._openFind(!0);
4102
+ return;
4103
+ }
4104
+ if (t && e.key === "d") {
4105
+ e.preventDefault(), !n && this._config.multiCursor && this._ctrlD();
4106
+ return;
4107
+ }
4108
+ if (t && i && e.key === "d") {
4109
+ e.preventDefault(), n || this._duplicateLine();
4110
+ return;
4111
+ }
4112
+ if (t && e.key === "/") {
4113
+ e.preventDefault(), n || this._toggleComment();
4114
+ return;
4115
+ }
4116
+ if (t && e.key === "k") {
4117
+ e.preventDefault(), n || this._deleteLine();
4118
+ return;
4119
+ }
4120
+ if (e.key === "Escape") {
4121
+ this._tab.sel = null, this._acHide(), this._closeFind(), this._emmetTip.style.display = "none", this._snippetTip.style.display = "none", this._snippetExpanded = null, xe(this._mc), this._extraCursors = [], this._mc.searchWord = "", this._render();
4122
+ return;
4123
+ }
4124
+ if (n) {
4125
+ this._handleArrowKeys(e, t, i);
4126
+ return;
4127
+ }
4128
+ if (e.key === "Tab") {
4129
+ if (e.preventDefault(), !i && this._emmetAccept() || !i && this._snippetAccept()) return;
4130
+ i ? this._unindentSel() : this._indentSel(), A(this._tab), this._scrollIntoView(), this._rebuildWrapMap(), this._render();
4131
+ return;
4132
+ }
4133
+ if (e.key === "Backspace") {
4134
+ if (e.preventDefault(), this._extraCursors.length) {
4135
+ const v = yt(
4136
+ this._tab.doc,
4137
+ this._tab.cur.row,
4138
+ this._tab.cur.col,
4139
+ this._extraCursors
4140
+ );
4141
+ this._tab.doc = v.doc, this._tab.cur.row = v.primaryRow, this._tab.cur.col = v.primaryCol, this._extraCursors = v.extraCursors, this._mc.cursors = v.extraCursors;
4142
+ } else
4143
+ this._doBackspace();
4144
+ this._tokenCache.clear(), this._rebuildWrapMap(), A(this._tab), this._scrollIntoView(), this._render(), this._acTrigger(), this._emmetCheck(), this._snippetCheck(), (l = (a = this._config).onChange) == null || l.call(a, D(this._tab.doc));
4145
+ return;
4146
+ }
4147
+ if (e.key === "Delete") {
4148
+ e.preventDefault(), this._doDelete(), this._tokenCache.clear(), this._rebuildWrapMap(), A(this._tab), this._scrollIntoView(), this._render(), (c = (o = this._config).onChange) == null || c.call(o, D(this._tab.doc));
4149
+ return;
4150
+ }
4151
+ if (e.key === "Enter") {
4152
+ e.preventDefault(), this._doEnter(), this._tokenCache.clear(), this._rebuildWrapMap(), A(this._tab), this._scrollIntoView(), this._render(), (p = (d = this._config).onChange) == null || p.call(d, D(this._tab.doc));
4153
+ return;
4154
+ }
4155
+ if (!t && !r && this._config.autoClosePairs[e.key]) {
4156
+ e.preventDefault(), E(this._tab, this._config.maxUndoHistory), this._tab.sel && (this._tab.cur = O(this._tab));
4157
+ const { doc: v, cur: f } = this._tab, b = v[f.row] ?? "";
4158
+ v[f.row] = b.slice(0, f.col) + e.key + this._config.autoClosePairs[e.key] + b.slice(f.col), f.col++, this._tokenCache.invalidateLine(f.row, ((h = this._wm.segments[f.row]) == null ? void 0 : h.length) ?? 1), this._tab.dirty = !0, this._rebuildWrapMap(), A(this._tab), this._scrollIntoView(), this._render(), (y = (g = this._config).onChange) == null || y.call(g, D(this._tab.doc));
4159
+ return;
4160
+ }
4161
+ if (!t && !r && Object.values(this._config.autoClosePairs).includes(e.key)) {
4162
+ const { doc: v, cur: f } = this._tab;
4163
+ if ((v[f.row] ?? "")[f.col] === e.key) {
4164
+ e.preventDefault(), f.col++, A(this._tab), this._scrollIntoView(), this._render();
4165
+ return;
4166
+ }
4167
+ }
4168
+ if (r && !t && (e.key === "ArrowUp" || e.key === "ArrowDown")) {
4169
+ e.preventDefault(), this._moveLines(e.key === "ArrowUp");
4170
+ return;
4171
+ }
4172
+ this._handleArrowKeys(e, t, i);
4173
+ }
4174
+ _handleArrowKeys(e, t, i) {
4175
+ var g, y, v, f, b, T;
4176
+ const { doc: r, cur: n } = this._tab, a = this._config.lineHeight, l = e.metaKey, o = e.ctrlKey, c = e.altKey, d = (_, x) => {
4177
+ if (i) {
4178
+ this._tab.sel || (this._tab.sel = { ar: n.row, ac: n.col, fr: n.row, fc: n.col }), n.row = _, n.col = x;
4179
+ const m = this._tab.sel;
4180
+ m.fr = _, m.fc = x, m.ar === m.fr && m.ac === m.fc && (this._tab.sel = null);
4181
+ } else
4182
+ this._tab.sel = null, n.row = _, n.col = x;
4183
+ }, p = (_) => {
4184
+ const m = (r[_] ?? "").search(/\S/);
4185
+ return m === -1 || n.col === m ? 0 : m;
4186
+ }, h = () => ({ row: r.length - 1, col: (r[r.length - 1] ?? "").length });
4187
+ switch (e.key) {
4188
+ case "ArrowRight":
4189
+ if (e.preventDefault(), this._tab.sel && !i) {
4190
+ const _ = P(this._tab.sel);
4191
+ n.row = _.fr, n.col = _.fc, this._tab.sel = null;
4192
+ break;
4193
+ }
4194
+ if (l)
4195
+ d(n.row, (r[n.row] ?? "").length);
4196
+ else if (o || c) {
4197
+ const _ = this._wordSkipRight(r[n.row] ?? "", n.col);
4198
+ d(n.row, _);
4199
+ } else n.col < (r[n.row] ?? "").length ? d(n.row, n.col + 1) : n.row < r.length - 1 && d(n.row + 1, 0);
4200
+ break;
4201
+ case "ArrowLeft":
4202
+ if (e.preventDefault(), this._tab.sel && !i) {
4203
+ const _ = P(this._tab.sel);
4204
+ n.row = _.ar, n.col = _.ac, this._tab.sel = null;
4205
+ break;
4206
+ }
4207
+ if (l)
4208
+ d(n.row, p(n.row));
4209
+ else if (o || c) {
4210
+ const _ = this._wordSkipLeft(r[n.row] ?? "", n.col);
4211
+ d(n.row, _);
4212
+ } else n.col > 0 ? d(n.row, n.col - 1) : n.row > 0 && d(n.row - 1, (r[n.row - 1] ?? "").length);
4213
+ break;
4214
+ case "ArrowDown":
4215
+ if (e.preventDefault(), l) {
4216
+ const _ = h();
4217
+ d(_.row, _.col);
4218
+ } else if (this._config.wordWrap) {
4219
+ const _ = F(this._wm, n.row, n.col), x = Math.min(this._wm.visualRows.length - 1, _.visRow + 1), m = Y(this._wm, x, Math.min(_.colInSeg, (((g = this._wm.visualRows[x]) == null ? void 0 : g.text) ?? "").length));
4220
+ d(m.row, m.col);
4221
+ } else {
4222
+ const _ = Math.min(r.length - 1, n.row + 1);
4223
+ d(_, Math.min(n.col, (r[_] ?? "").length));
4224
+ }
4225
+ break;
4226
+ case "ArrowUp":
4227
+ if (e.preventDefault(), l)
4228
+ d(0, 0);
4229
+ else if (this._config.wordWrap) {
4230
+ const _ = F(this._wm, n.row, n.col), x = Math.max(0, _.visRow - 1), m = Y(this._wm, x, Math.min(_.colInSeg, (((y = this._wm.visualRows[x]) == null ? void 0 : y.text) ?? "").length));
4231
+ d(m.row, m.col);
4232
+ } else {
4233
+ const _ = Math.max(0, n.row - 1);
4234
+ d(_, Math.min(n.col, (r[_] ?? "").length));
4235
+ }
4236
+ break;
4237
+ case "Home":
4238
+ e.preventDefault(), o ? d(0, 0) : d(n.row, p(n.row));
4239
+ break;
4240
+ case "End":
4241
+ if (e.preventDefault(), o) {
4242
+ const _ = h();
4243
+ d(_.row, _.col);
4244
+ } else
4245
+ d(n.row, (r[n.row] ?? "").length);
4246
+ break;
4247
+ case "PageDown":
4248
+ e.preventDefault();
4249
+ {
4250
+ const _ = Math.max(1, Math.floor(this._editorEl.clientHeight / a) - 1), x = Math.min(r.length - 1, n.row + _);
4251
+ d(x, Math.min(n.col, (r[x] ?? "").length)), this._editorEl.scrollTop += this._editorEl.clientHeight - a;
4252
+ break;
4253
+ }
4254
+ case "PageUp":
4255
+ e.preventDefault();
4256
+ {
4257
+ const _ = Math.max(1, Math.floor(this._editorEl.clientHeight / a) - 1), x = Math.max(0, n.row - _);
4258
+ d(x, Math.min(n.col, (r[x] ?? "").length)), this._editorEl.scrollTop -= this._editorEl.clientHeight - a;
4259
+ break;
4260
+ }
4261
+ default:
4262
+ return;
4263
+ }
4264
+ A(this._tab), this._scrollIntoView(), this._acHide(), (f = (v = this._config).onCursorChange) == null || f.call(v, { ...this._tab.cur }), (T = (b = this._config).onSelectionChange) == null || T.call(b, this._tab.sel ? { ...this._tab.sel } : null), this._render();
4265
+ }
4266
+ _isWordChar(e) {
4267
+ const t = this._config.wordSeparators;
4268
+ return t ? e.trim() !== "" && !t.includes(e) : /[\w$]/.test(e);
4269
+ }
4270
+ _wordSkipRight(e, t) {
4271
+ let i = t;
4272
+ for (; i < e.length && /\s/.test(e[i]); ) i++;
4273
+ for (; i < e.length && /\S/.test(e[i]); ) i++;
4274
+ return i;
4275
+ }
4276
+ _wordSkipLeft(e, t) {
4277
+ let i = t;
4278
+ for (; i > 0 && /\s/.test(e[i - 1]); ) i--;
4279
+ for (; i > 0 && /\S/.test(e[i - 1]); ) i--;
4280
+ return i;
4281
+ }
4282
+ // ── Move lines ────────────────────────────────────────────
4283
+ _moveLines(e) {
4284
+ var l, o, c, d;
4285
+ const { doc: t, cur: i } = this._tab, r = this._tab.sel;
4286
+ let n = i.row, a = i.row;
4287
+ if (r) {
4288
+ const p = P(r);
4289
+ n = p.ar, a = p.fr, p.fc === 0 && p.fr > p.ar && a--;
4290
+ }
4291
+ if (e) {
4292
+ if (n === 0) return;
4293
+ E(this._tab, this._config.maxUndoHistory);
4294
+ const p = t.splice(n, a - n + 1);
4295
+ t.splice(n - 1, 0, ...p), i.row--, r && (r.ar--, r.fr--);
4296
+ } else {
4297
+ if (a >= t.length - 1) return;
4298
+ E(this._tab, this._config.maxUndoHistory);
4299
+ const p = t.splice(n, a - n + 1);
4300
+ t.splice(n + 1, 0, ...p), i.row++, r && (r.ar++, r.fr++);
4301
+ }
4302
+ this._tab.dirty = !0, this._tokenCache.clear(), this._rebuildWrapMap(), A(this._tab), this._scrollIntoView(), this._render(), (o = (l = this._config).onChange) == null || o.call(l, D(this._tab.doc)), (d = (c = this._config).onCursorChange) == null || d.call(c, { ...this._tab.cur });
4303
+ }
4304
+ // ── Hover documentation ────────────────────────────────────
4305
+ _scheduleHover(e) {
4306
+ this._hoverTip.style.display !== "none" && (this._hoverTip.style.display = "none"), this._hoverTimer !== null && (clearTimeout(this._hoverTimer), this._hoverTimer = null);
4307
+ const { clientX: t, clientY: i } = e;
4308
+ this._hoverTimer = setTimeout(() => {
4309
+ this._hoverTimer = null, this._doHover(t, i);
4310
+ }, 500);
4311
+ }
4312
+ _doHover(e, t) {
4313
+ var y, v, f;
4314
+ if (!this._config.hover) return;
4315
+ const i = this._editorEl.getBoundingClientRect(), r = t - i.top + this._editorEl.scrollTop, n = this._config.showGutter ? this._config.gutterWidth : 0, a = e - i.left - n - 14, l = this._config.lineHeight, o = Math.max(0, Math.min(this._wm.visualRows.length - 1, Math.floor(r / l))), c = Math.max(0, Math.min(
4316
+ (((y = this._wm.visualRows[o]) == null ? void 0 : y.text) ?? "").length,
4317
+ Math.round(a / 7.82)
4318
+ )), d = Y(this._wm, o, c), p = this._tab.doc[d.row] ?? "", h = Lt(p, d.col);
4319
+ if (!h) return;
4320
+ let g = Ht(h, this._config.language);
4321
+ if (!g) {
4322
+ const b = this._config.completions.find((T) => T.label === h);
4323
+ b && (b.description || b.detail) && (g = {
4324
+ title: b.label,
4325
+ type: b.detail,
4326
+ body: b.description ?? ""
4327
+ });
4328
+ }
4329
+ if (!g) {
4330
+ const b = (f = (v = this._config).provideHover) == null ? void 0 : f.call(v, {
4331
+ word: h,
4332
+ row: d.row,
4333
+ col: d.col,
4334
+ line: p,
4335
+ language: this._config.language,
4336
+ doc: this._tab.doc
4337
+ });
4338
+ b && (g = b);
4339
+ }
4340
+ g && this._showHoverTip(g, e, t);
4341
+ }
4342
+ _showHoverTip(e, t, i) {
4343
+ const r = this._hoverTip;
4344
+ let n = '<div class="sl-ht-sig">';
4345
+ n += `<span class="sl-ht-title">${q(e.title)}</span>`, e.type && (n += `<code class="sl-ht-type">${q(e.type)}</code>`), n += "</div>", e.title && e.body && (n += '<div class="sl-ht-divider"></div>'), e.body && (n += `<div class="sl-ht-body">${q(e.body)}</div>`), r.innerHTML = n, r.style.display = "block";
4346
+ const a = 12, l = 18, o = r.offsetWidth || 300, c = r.offsetHeight || 80;
4347
+ let d = t, p = i + l;
4348
+ p + c > window.innerHeight - a && (p = i - c - 8), d + o > window.innerWidth - a && (d = window.innerWidth - o - a), d < a && (d = a), r.style.left = `${d}px`, r.style.top = `${Math.max(a, p)}px`;
4349
+ }
4350
+ _hideHover() {
4351
+ this._hoverTimer !== null && (clearTimeout(this._hoverTimer), this._hoverTimer = null), this._hoverPinned = !1, this._hoverTip.style.display = "none";
4352
+ }
4353
+ _onInput(e) {
4354
+ var n, a, l, o;
4355
+ if (this._config.readOnly) {
4356
+ e.target.value = "";
4357
+ return;
4358
+ }
4359
+ const t = e.target, i = t.value;
4360
+ if (t.value = "", !i || i === "Ω") return;
4361
+ const r = i.replace(/[\x00-\x08\x0a-\x1f\x7f]/g, "");
4362
+ if (r) {
4363
+ if (this._extraCursors.length) {
4364
+ const c = _t(
4365
+ this._tab.doc,
4366
+ this._tab.cur.row,
4367
+ this._tab.cur.col,
4368
+ this._extraCursors,
4369
+ r
4370
+ );
4371
+ this._tab.doc = c.doc, this._tab.cur.row = c.primaryRow, this._tab.cur.col = c.primaryCol, this._extraCursors = c.extraCursors, this._mc.cursors = c.extraCursors, this._tab.dirty = !0, (a = (n = this._config).onChange) == null || a.call(n, D(this._tab.doc));
4372
+ } else
4373
+ this._insertStr(r, !0);
4374
+ this._tokenCache.clear(), this._rebuildWrapMap(), A(this._tab), this._scrollIntoView(), this._render(), this._acTrigger(), this._emmetCheck(), this._snippetCheck(), (o = (l = this._config).onCursorChange) == null || o.call(l, { ...this._tab.cur });
4375
+ }
4376
+ }
4377
+ _ctrlD() {
4378
+ if (!this._config.multiCursor) return;
4379
+ const e = vt(
4380
+ this._mc,
4381
+ this._tab.doc,
4382
+ this._tab.cur.row,
4383
+ this._tab.cur.col,
4384
+ this._tab.sel
4385
+ );
4386
+ e && (!this._mc.cursors.length || e.word !== this._mc.searchWord ? (this._tab.sel = e.sel, this._tab.cur.col = e.col) : (ke(this._mc, e.row, e.col, e.sel), this._extraCursors = [...this._mc.cursors]), this._mc.searchWord = e.word, this._mc.lastMatchRow = e.row, this._mc.lastMatchCol = e.col, this._scrollIntoView(), this._render());
4387
+ }
4388
+ // ── Find event binding ────────────────────────────────────
4389
+ _bindFindEvents() {
4390
+ var e, t, i, r, n, a, l;
4391
+ this._findInput.addEventListener("input", () => {
4392
+ this._runFind(this._findInput.value), this._findIdx = -1, this._findMatches.length ? this._navFind(1) : (this._findCount.textContent = "0/0", this._render());
4393
+ }), this._findInput.addEventListener("keydown", (o) => {
4394
+ o.key === "Enter" ? o.shiftKey ? this._navFind(-1) : this._navFind(1) : o.key === "Escape" && this._closeFind(), o.stopPropagation();
4395
+ }), this._replaceInput.addEventListener("keydown", (o) => {
4396
+ o.key === "Enter" ? this._doReplaceOne() : o.key === "Escape" && this._closeFind(), o.stopPropagation();
4397
+ }), (e = this._findBar.querySelector(".sl-find-prev")) == null || e.addEventListener("click", () => this._navFind(-1)), (t = this._findBar.querySelector(".sl-find-next")) == null || t.addEventListener("click", () => this._navFind(1)), (i = this._findBar.querySelector(".sl-find-close")) == null || i.addEventListener("click", () => this._closeFind()), (r = this._findBar.querySelector(".sl-find-case")) == null || r.addEventListener("click", (o) => {
4398
+ this._findCaseSensitive = !this._findCaseSensitive, o.target.classList.toggle("sl-active", this._findCaseSensitive), this._runFind(this._findInput.value), this._findIdx = -1, this._findMatches.length ? this._navFind(1) : (this._findCount.textContent = "0/0", this._render());
4399
+ }), (n = this._findBar.querySelector(".sl-find-regex")) == null || n.addEventListener("click", (o) => {
4400
+ this._findRegex = !this._findRegex, o.target.classList.toggle("sl-active", this._findRegex), this._runFind(this._findInput.value), this._findIdx = -1, this._findMatches.length ? this._navFind(1) : (this._findCount.textContent = "0/0", this._render());
4401
+ }), (a = this._findBar.querySelector(".sl-replace-one")) == null || a.addEventListener("click", () => this._doReplaceOne()), (l = this._findBar.querySelector(".sl-replace-all")) == null || l.addEventListener("click", () => this._doReplaceAll());
4402
+ }
4403
+ _doReplaceOne() {
4404
+ var e, t;
4405
+ this._findIdx < 0 || !this._findMatches.length || (E(this._tab, this._config.maxUndoHistory), this._tab.doc = kt(this._tab.doc, this._findMatches, this._findIdx, this._replaceInput.value), this._tokenCache.clear(), this._tab.dirty = !0, this._runFind(this._findInput.value), this._findMatches.length ? (this._findIdx >= this._findMatches.length && (this._findIdx = 0), this._navFind(0)) : (this._findCount.textContent = "0/0", this._rebuildWrapMap(), this._render()), (t = (e = this._config).onChange) == null || t.call(e, D(this._tab.doc)));
4406
+ }
4407
+ _doReplaceAll() {
4408
+ var t, i;
4409
+ if (!this._findMatches.length) return;
4410
+ const e = this._findMatches.length;
4411
+ E(this._tab, this._config.maxUndoHistory), this._tab.doc = xt(this._tab.doc, this._findMatches, this._replaceInput.value), this._tokenCache.clear(), this._tab.dirty = !0, this._findMatches = [], this._findIdx = -1, this._findCount.textContent = `0/0 (${e} replaced)`, this._rebuildWrapMap(), this._render(), (i = (t = this._config).onChange) == null || i.call(t, D(this._tab.doc));
4412
+ }
4413
+ // ── Minimap events ────────────────────────────────────────
4414
+ _bindMinimapEvents() {
4415
+ const e = this._minimapWrap;
4416
+ e.addEventListener("mousemove", (t) => {
4417
+ if (this._mmDragMode !== "none") return;
4418
+ const i = t.clientY - e.getBoundingClientRect().top, { sliderTop: r, sliderHeight: n } = ie(
4419
+ this._tab.doc.length,
4420
+ this._editorEl.scrollTop,
4421
+ this._editorEl.clientHeight,
4422
+ e.clientHeight,
4423
+ this._config.lineHeight
4424
+ );
4425
+ e.style.cursor = i >= r && i <= r + n ? "grab" : "pointer";
4426
+ }), e.addEventListener("mousedown", (t) => {
4427
+ t.preventDefault();
4428
+ const i = e.clientHeight, r = t.clientY - e.getBoundingClientRect().top, { sliderTop: n, sliderHeight: a } = ie(
4429
+ this._tab.doc.length,
4430
+ this._editorEl.scrollTop,
4431
+ this._editorEl.clientHeight,
4432
+ i,
4433
+ this._config.lineHeight
4434
+ );
4435
+ if (r >= n && r <= n + a)
4436
+ this._mmDragMode = "slider", this._mmSliderOffset = r - n, this._mmDragStartY = t.clientY, this._mmDragStartScroll = this._editorEl.scrollTop, e.style.cursor = "grabbing";
4437
+ else {
4438
+ this._mmDragMode = "jump";
4439
+ const l = Nt(
4440
+ r,
4441
+ this._tab.doc.length,
4442
+ this._editorEl.scrollTop,
4443
+ this._editorEl.clientHeight,
4444
+ i,
4445
+ this._config.lineHeight
4446
+ );
4447
+ this._editorEl.scrollTop = l, this._mmDragStartY = t.clientY, this._mmDragStartScroll = l, this._render();
4448
+ }
4449
+ }), window.addEventListener("mousemove", this._onWinMmMouseMove), window.addEventListener("mouseup", this._onWinMmMouseUp);
4450
+ }
4451
+ }
4452
+ function Gt(s, e) {
4453
+ return new Ut(s, e);
4454
+ }
4455
+ export {
4456
+ tt as BUILT_IN_THEMES,
4457
+ Ut as SynclineEditor,
4458
+ Je as THEME_DRACULA,
4459
+ Xe as THEME_GITHUB_LIGHT,
4460
+ Ye as THEME_MONOKAI,
4461
+ Ze as THEME_SOLARIZED_LIGHT,
4462
+ qe as THEME_VR_DARK,
4463
+ Ve as THEME_VSCODE_DARK,
4464
+ Gt as createEditor
4465
+ };
4466
+ //# sourceMappingURL=syncline-editor.es.js.map