@cascivo/editor 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1278 @@
1
+ "use client";
2
+ import { cn as e, useControllableSignal as t, useSignal as n, useSignalEffect as r, useSignals as i } from "@cascivo/core";
3
+ import { builtin as a, t as o } from "@cascivo/i18n";
4
+ import { forwardRef as s, useImperativeHandle as c, useRef as l } from "react";
5
+ import { jsx as u, jsxs as d } from "react/jsx-runtime";
6
+ //#region src/engine/tokenize.ts
7
+ var f = /* @__PURE__ */ new Map(), p = "\0", ee = 0;
8
+ function m(e, t, n) {
9
+ let r = `${e.name}${p}${n}${p}${t}`, i = f.get(r);
10
+ if (i) return i;
11
+ ee++;
12
+ let { tokens: a, state: o } = e.tokenizeLine(t, n), s = {
13
+ tokens: a,
14
+ endState: o
15
+ };
16
+ return f.set(r, s), s;
17
+ }
18
+ function h(e, t) {
19
+ let n = t.split("\n"), r = [], i = e.initialState;
20
+ for (let t of n) {
21
+ let n = m(e, t, i);
22
+ r.push(n.tokens), i = n.endState;
23
+ }
24
+ return r;
25
+ }
26
+ function te(e, t, n, r, i) {
27
+ let a = Math.max(0, Math.min(n, t.length)), o = Math.max(a, Math.min(r, t.length)), s = i.startStateOf(t, a), c = [];
28
+ for (let n = a; n < o; n++) {
29
+ let r = m(e, t[n], s);
30
+ c.push(r.tokens), i.setEndState(n, r.endState), s = r.endState;
31
+ }
32
+ return c;
33
+ }
34
+ //#endregion
35
+ //#region src/engine/line-state.ts
36
+ function ne(e) {
37
+ let t = [], n = (n, r) => {
38
+ let i = Math.min(r, n.length - 1), a = t.length;
39
+ if (a > i) return;
40
+ let o = a === 0 ? e.initialState : t[a - 1];
41
+ for (; a <= i; a++) {
42
+ let r = m(e, n[a], o);
43
+ t[a] = r.endState, o = r.endState;
44
+ }
45
+ };
46
+ return {
47
+ grammar: e,
48
+ get length() {
49
+ return t.length;
50
+ },
51
+ ensure: n,
52
+ startStateOf: (r, i) => i <= 0 ? e.initialState : (n(r, i - 1), t[i - 1]),
53
+ setEndState: (e, n) => {
54
+ t[e] = n;
55
+ },
56
+ invalidateFrom: (e) => {
57
+ let n = Math.max(0, e);
58
+ n < t.length && (t.length = n);
59
+ }
60
+ };
61
+ }
62
+ //#endregion
63
+ //#region src/engine/registry.ts
64
+ var g = /* @__PURE__ */ new Map(), _ = {
65
+ name: "plaintext",
66
+ initialState: "default",
67
+ tokenizeLine: (e) => ({
68
+ tokens: e.length > 0 ? [{
69
+ kind: "plain",
70
+ value: e
71
+ }] : [],
72
+ state: "default"
73
+ })
74
+ };
75
+ g.set(_.name, _);
76
+ function v(e) {
77
+ g.set(e.name, e);
78
+ }
79
+ function re(e) {
80
+ if (e !== void 0) {
81
+ let t = g.get(e);
82
+ if (t) return t;
83
+ }
84
+ return g.get("plaintext");
85
+ }
86
+ function y() {
87
+ return [...g.keys()];
88
+ }
89
+ //#endregion
90
+ //#region src/grammars/rules.ts
91
+ function b(e) {
92
+ let t = {};
93
+ for (let [n, r] of Object.entries(e.states)) t[n] = r.map((e) => {
94
+ let t = `${e.match.flags.replace(/[gy]/g, "")}y`, n = {
95
+ re: new RegExp(e.match.source, t),
96
+ kind: e.kind
97
+ };
98
+ return e.push !== void 0 && (n.push = e.push), e.pop !== void 0 && (n.pop = e.pop), n;
99
+ });
100
+ return {
101
+ name: e.name,
102
+ initialState: "default",
103
+ tokenizeLine(e, n) {
104
+ let r = t[n] ? n : "default", i = [], a = -1, o = 0, s = (t) => {
105
+ a >= 0 && (i.push({
106
+ kind: "plain",
107
+ value: e.slice(a, t)
108
+ }), a = -1);
109
+ };
110
+ for (; o < e.length;) {
111
+ let n = t[r], c = !1;
112
+ for (let a of n) {
113
+ a.re.lastIndex = o;
114
+ let n = a.re.exec(e);
115
+ if (n !== null && n.index === o && n[0].length > 0) {
116
+ s(o), i.push({
117
+ kind: a.kind,
118
+ value: n[0]
119
+ }), o += n[0].length, a.pop ? r = "default" : a.push && t[a.push] && (r = a.push), c = !0;
120
+ break;
121
+ }
122
+ }
123
+ c || (a < 0 && (a = o), o++);
124
+ }
125
+ return s(e.length), {
126
+ tokens: i,
127
+ state: r
128
+ };
129
+ }
130
+ };
131
+ }
132
+ //#endregion
133
+ //#region src/grammars/plaintext.ts
134
+ var x = {
135
+ name: "plaintext",
136
+ initialState: "default",
137
+ tokenizeLine: (e) => ({
138
+ tokens: e.length > 0 ? [{
139
+ kind: "plain",
140
+ value: e
141
+ }] : [],
142
+ state: "default"
143
+ })
144
+ };
145
+ v(x);
146
+ //#endregion
147
+ //#region src/grammars/json.ts
148
+ var S = b({
149
+ name: "json",
150
+ states: { default: [
151
+ {
152
+ match: /"(?:[^"\\]|\\.)*"(?=\s*:)/,
153
+ kind: "property"
154
+ },
155
+ {
156
+ match: /"(?:[^"\\]|\\.)*"/,
157
+ kind: "string"
158
+ },
159
+ {
160
+ match: /\b(?:true|false|null)\b/,
161
+ kind: "boolean"
162
+ },
163
+ {
164
+ match: /-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/,
165
+ kind: "number"
166
+ },
167
+ {
168
+ match: /[{}[\],]/,
169
+ kind: "punctuation"
170
+ },
171
+ {
172
+ match: /:/,
173
+ kind: "operator"
174
+ }
175
+ ] }
176
+ });
177
+ v(S);
178
+ //#endregion
179
+ //#region src/grammars/clike.ts
180
+ var C = /* @__PURE__ */ "async.await.break.case.catch.class.const.continue.debugger.default.delete.do.else.export.extends.finally.for.function.if.import.in.instanceof.let.new.of.return.static.super.switch.this.throw.try.typeof.var.void.while.with.yield.as.from.get.set".split(".");
181
+ function w(e) {
182
+ return RegExp(`(?:${e.join("|")})\\b`);
183
+ }
184
+ function T(e, t, n = []) {
185
+ let r = [
186
+ {
187
+ match: /\/\/.*/,
188
+ kind: "comment"
189
+ },
190
+ {
191
+ match: /\/\*/,
192
+ kind: "comment",
193
+ push: "block"
194
+ },
195
+ {
196
+ match: /`/,
197
+ kind: "string",
198
+ push: "template"
199
+ },
200
+ {
201
+ match: /'(?:[^'\\]|\\.)*'/,
202
+ kind: "string"
203
+ },
204
+ {
205
+ match: /"(?:[^"\\]|\\.)*"/,
206
+ kind: "string"
207
+ },
208
+ {
209
+ match: /0[xX][0-9a-fA-F]+|0[bB][01]+|0[oO][0-7]+|(?:\d[\d_]*\.?\d*|\.\d+)(?:[eE][+-]?\d+)?n?/,
210
+ kind: "number"
211
+ },
212
+ {
213
+ match: /\b(?:true|false|null|undefined|NaN|Infinity)\b/,
214
+ kind: "boolean"
215
+ }
216
+ ];
217
+ return n.length > 0 && r.push({
218
+ match: w(n),
219
+ kind: "type"
220
+ }), r.push({
221
+ match: w(t),
222
+ kind: "keyword"
223
+ }, {
224
+ match: /[A-Za-z_$][\w$]*(?=\s*\()/,
225
+ kind: "function"
226
+ }, {
227
+ match: /[A-Z][\w$]*/,
228
+ kind: "type"
229
+ }, {
230
+ match: /[A-Za-z_$][\w$]*/,
231
+ kind: "variable"
232
+ }, {
233
+ match: /[+\-*/%=<>!&|^~?]+/,
234
+ kind: "operator"
235
+ }, {
236
+ match: /[{}()[\];,.:]/,
237
+ kind: "punctuation"
238
+ }), b({
239
+ name: e,
240
+ states: {
241
+ default: r,
242
+ block: [
243
+ {
244
+ match: /\*\//,
245
+ kind: "comment",
246
+ pop: !0
247
+ },
248
+ {
249
+ match: /[^*]+/,
250
+ kind: "comment"
251
+ },
252
+ {
253
+ match: /\*/,
254
+ kind: "comment"
255
+ }
256
+ ],
257
+ template: [
258
+ {
259
+ match: /\\./,
260
+ kind: "string"
261
+ },
262
+ {
263
+ match: /`/,
264
+ kind: "string",
265
+ pop: !0
266
+ },
267
+ {
268
+ match: /\$\{/,
269
+ kind: "punctuation"
270
+ },
271
+ {
272
+ match: /[^`\\$]+/,
273
+ kind: "string"
274
+ },
275
+ {
276
+ match: /\$/,
277
+ kind: "string"
278
+ }
279
+ ]
280
+ }
281
+ });
282
+ }
283
+ //#endregion
284
+ //#region src/grammars/javascript.ts
285
+ var ie = T("javascript", C);
286
+ v(ie);
287
+ var ae = T("typescript", C, [
288
+ "interface",
289
+ "type",
290
+ "enum",
291
+ "implements",
292
+ "namespace",
293
+ "declare",
294
+ "abstract",
295
+ "readonly",
296
+ "public",
297
+ "private",
298
+ "protected",
299
+ "keyof",
300
+ "infer",
301
+ "satisfies",
302
+ "is",
303
+ "asserts",
304
+ "override",
305
+ "string",
306
+ "number",
307
+ "boolean",
308
+ "any",
309
+ "unknown",
310
+ "never",
311
+ "object"
312
+ ]);
313
+ v(ae);
314
+ //#endregion
315
+ //#region src/grammars/css.ts
316
+ var oe = b({
317
+ name: "css",
318
+ states: {
319
+ default: [
320
+ {
321
+ match: /\/\*/,
322
+ kind: "comment",
323
+ push: "block"
324
+ },
325
+ {
326
+ match: /@[\w-]+/,
327
+ kind: "keyword"
328
+ },
329
+ {
330
+ match: /"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/,
331
+ kind: "string"
332
+ },
333
+ {
334
+ match: /#[0-9a-fA-F]{3,8}\b/,
335
+ kind: "number"
336
+ },
337
+ {
338
+ match: /-?\d+(?:\.\d+)?(?:px|rem|em|%|vh|vw|s|ms|deg|fr|ch|ex)?/,
339
+ kind: "number"
340
+ },
341
+ {
342
+ match: /--[\w-]+/,
343
+ kind: "variable"
344
+ },
345
+ {
346
+ match: /[.#][\w-]+/,
347
+ kind: "tag"
348
+ },
349
+ {
350
+ match: /&|::?[\w-]+/,
351
+ kind: "tag"
352
+ },
353
+ {
354
+ match: /[\w-]+(?=\s*:)/,
355
+ kind: "property"
356
+ },
357
+ {
358
+ match: /[\w-]+(?=\s*\()/,
359
+ kind: "function"
360
+ },
361
+ {
362
+ match: /[{}();,:]/,
363
+ kind: "punctuation"
364
+ }
365
+ ],
366
+ block: [
367
+ {
368
+ match: /\*\//,
369
+ kind: "comment",
370
+ pop: !0
371
+ },
372
+ {
373
+ match: /[^*]+/,
374
+ kind: "comment"
375
+ },
376
+ {
377
+ match: /\*/,
378
+ kind: "comment"
379
+ }
380
+ ]
381
+ }
382
+ });
383
+ v(oe);
384
+ //#endregion
385
+ //#region src/grammars/html.ts
386
+ var se = b({
387
+ name: "html",
388
+ states: {
389
+ default: [
390
+ {
391
+ match: /<!--/,
392
+ kind: "comment",
393
+ push: "comment"
394
+ },
395
+ {
396
+ match: /<!?\/?[A-Za-z][\w-]*/,
397
+ kind: "tag",
398
+ push: "tag"
399
+ },
400
+ {
401
+ match: /&[a-zA-Z#0-9]+;/,
402
+ kind: "boolean"
403
+ }
404
+ ],
405
+ comment: [
406
+ {
407
+ match: /-->/,
408
+ kind: "comment",
409
+ pop: !0
410
+ },
411
+ {
412
+ match: /[^-]+/,
413
+ kind: "comment"
414
+ },
415
+ {
416
+ match: /-/,
417
+ kind: "comment"
418
+ }
419
+ ],
420
+ tag: [
421
+ {
422
+ match: /\/?>/,
423
+ kind: "tag",
424
+ pop: !0
425
+ },
426
+ {
427
+ match: /"(?:[^"\\]|\\.)*"|'[^']*'/,
428
+ kind: "string"
429
+ },
430
+ {
431
+ match: /[\w-]+(?=\s*=)/,
432
+ kind: "attr"
433
+ },
434
+ {
435
+ match: /=/,
436
+ kind: "operator"
437
+ },
438
+ {
439
+ match: /[\w-]+/,
440
+ kind: "attr"
441
+ }
442
+ ]
443
+ }
444
+ });
445
+ v(se);
446
+ //#endregion
447
+ //#region src/grammars/markdown.ts
448
+ var ce = b({
449
+ name: "markdown",
450
+ states: {
451
+ default: [
452
+ {
453
+ match: /^```.*/,
454
+ kind: "keyword",
455
+ push: "fence"
456
+ },
457
+ {
458
+ match: /^~~~.*/,
459
+ kind: "keyword",
460
+ push: "fenceTilde"
461
+ },
462
+ {
463
+ match: /^\s*([-*_])(?:[ \t]*\1){2,}[ \t]*$/,
464
+ kind: "comment"
465
+ },
466
+ {
467
+ match: /^#{1,6}\s.*/,
468
+ kind: "keyword"
469
+ },
470
+ {
471
+ match: /^\s*[-*+]\s+\[[ xX]\]/,
472
+ kind: "boolean"
473
+ },
474
+ {
475
+ match: /^\s*(?:[-*+]|\d+\.)\s/,
476
+ kind: "operator"
477
+ },
478
+ {
479
+ match: /^\s*>\s?.*/,
480
+ kind: "comment"
481
+ },
482
+ {
483
+ match: /`[^`]+`/,
484
+ kind: "string"
485
+ },
486
+ {
487
+ match: /~~[^~]+~~/,
488
+ kind: "comment"
489
+ },
490
+ {
491
+ match: /\*\*[^*]+\*\*|__[^_]+__/,
492
+ kind: "keyword"
493
+ },
494
+ {
495
+ match: /\*[^*\s][^*]*\*|_[^_\s][^_]*_/,
496
+ kind: "type"
497
+ },
498
+ {
499
+ match: /!?\[[^\]]*\]\([^)]*\)/,
500
+ kind: "function"
501
+ }
502
+ ],
503
+ fence: [{
504
+ match: /^```.*/,
505
+ kind: "keyword",
506
+ pop: !0
507
+ }, {
508
+ match: /.+/,
509
+ kind: "string"
510
+ }],
511
+ fenceTilde: [{
512
+ match: /^~~~.*/,
513
+ kind: "keyword",
514
+ pop: !0
515
+ }, {
516
+ match: /.+/,
517
+ kind: "string"
518
+ }]
519
+ }
520
+ });
521
+ v(ce);
522
+ //#endregion
523
+ //#region src/grammars/bash.ts
524
+ var le = b({
525
+ name: "bash",
526
+ states: { default: [
527
+ {
528
+ match: /#.*/,
529
+ kind: "comment"
530
+ },
531
+ {
532
+ match: /"(?:[^"\\]|\\.)*"/,
533
+ kind: "string"
534
+ },
535
+ {
536
+ match: /'[^']*'/,
537
+ kind: "string"
538
+ },
539
+ {
540
+ match: /\b(?:if|then|else|elif|fi|for|while|until|do|done|case|esac|in|function|select|return|exit|break|continue|local|export|readonly|declare|echo|cd|source|set|unset)\b/,
541
+ kind: "keyword"
542
+ },
543
+ {
544
+ match: /\$\{[^}]*\}|\$[A-Za-z_]\w*|\$[0-9@*#?$!]/,
545
+ kind: "variable"
546
+ },
547
+ {
548
+ match: /-?\b\d+\b/,
549
+ kind: "number"
550
+ },
551
+ {
552
+ match: /[A-Za-z_][\w-]*(?=\s*\(\s*\))/,
553
+ kind: "function"
554
+ },
555
+ {
556
+ match: /[|&;<>()]+|&&|\|\||=/,
557
+ kind: "operator"
558
+ }
559
+ ] }
560
+ });
561
+ v(le);
562
+ var E = {
563
+ root: "_root_1m6ns_2",
564
+ gutter: "_gutter_1m6ns_17",
565
+ gutterLine: "_gutterLine_1m6ns_28",
566
+ gutterActive: "_gutterActive_1m6ns_35",
567
+ pre: "_pre_1m6ns_45",
568
+ code: "_code_1m6ns_57",
569
+ line: "_line_1m6ns_62",
570
+ plain: "_plain_1m6ns_77",
571
+ keyword: "_keyword_1m6ns_80",
572
+ string: "_string_1m6ns_83",
573
+ number: "_number_1m6ns_86",
574
+ comment: "_comment_1m6ns_89",
575
+ function: "_function_1m6ns_93",
576
+ type: "_type_1m6ns_96",
577
+ operator: "_operator_1m6ns_99",
578
+ punctuation: "_punctuation_1m6ns_102",
579
+ variable: "_variable_1m6ns_105",
580
+ tag: "_tag_1m6ns_108",
581
+ attr: "_attr_1m6ns_111",
582
+ regexp: "_regexp_1m6ns_114",
583
+ boolean: "_boolean_1m6ns_117",
584
+ property: "_property_1m6ns_120",
585
+ match: "_match_1m6ns_125",
586
+ matchCurrent: "_matchCurrent_1m6ns_129",
587
+ bracketMatch: "_bracketMatch_1m6ns_133"
588
+ };
589
+ //#endregion
590
+ //#region src/editor/view.tsx
591
+ function ue(e, t) {
592
+ let n = "";
593
+ for (let r of t) e >= r.start && e < r.end && (n = n ? `${n} ${r.className}` : r.className);
594
+ return n;
595
+ }
596
+ function de(t, n, r, i) {
597
+ let a = n + t.value.length, o = new Set([n, a]);
598
+ for (let e of r) e.start > n && e.start < a && o.add(e.start), e.end > n && e.end < a && o.add(e.end);
599
+ if (o.size === 2) {
600
+ let a = ue(n, r);
601
+ return /* @__PURE__ */ u("span", {
602
+ className: a ? e(E[t.kind], a) : E[t.kind],
603
+ children: t.value
604
+ }, i);
605
+ }
606
+ let s = [...o].sort((e, t) => e - t), c = [];
607
+ for (let i = 0; i < s.length - 1; i++) {
608
+ let a = s[i], o = s[i + 1], l = ue(a, r);
609
+ c.push(/* @__PURE__ */ u("span", {
610
+ className: l ? e(E[t.kind], l) : E[t.kind],
611
+ children: t.value.slice(a - n, o - n)
612
+ }, a));
613
+ }
614
+ return /* @__PURE__ */ u("span", { children: c }, i);
615
+ }
616
+ function fe(e, t = 0, n = t + e.length, r) {
617
+ let i = [];
618
+ for (let a = t; a < n; a++) {
619
+ let n = e[a - t], o = r?.filter((e) => e.line === a);
620
+ i.push(/* @__PURE__ */ u("span", {
621
+ className: E.line,
622
+ children: n.length === 0 ? "​" : o && o.length > 0 ? (() => {
623
+ let e = 0;
624
+ return n.map((t, n) => {
625
+ let r = de(t, e, o, n);
626
+ return e += t.value.length, r;
627
+ });
628
+ })() : n.map((e, t) => /* @__PURE__ */ u("span", {
629
+ className: E[e.kind],
630
+ children: e.value
631
+ }, t))
632
+ }, a));
633
+ }
634
+ return i;
635
+ }
636
+ function pe({ count: e, className: t, gutterRef: n, start: r = 0, end: i = e, topPad: a = 0, bottomPad: o = 0, activeLine: s = !1 }) {
637
+ let c = [];
638
+ for (let e = r + 1; e <= i; e++) c.push(/* @__PURE__ */ u("span", {
639
+ className: E.gutterLine,
640
+ children: e
641
+ }, e));
642
+ return /* @__PURE__ */ d("div", {
643
+ ref: n,
644
+ className: t,
645
+ "aria-hidden": "true",
646
+ children: [
647
+ s && /* @__PURE__ */ u("div", { className: E.gutterActive }),
648
+ a > 0 && /* @__PURE__ */ u("div", { style: { blockSize: a } }),
649
+ c,
650
+ o > 0 && /* @__PURE__ */ u("div", { style: { blockSize: o } })
651
+ ]
652
+ });
653
+ }
654
+ var D = {
655
+ root: "_root_18xci_2",
656
+ textarea: "_textarea_18xci_18",
657
+ gutter: "_gutter_18xci_23",
658
+ codeArea: "_codeArea_18xci_36",
659
+ pre: "_pre_18xci_43",
660
+ currentLine: "_currentLine_18xci_58"
661
+ }, O = {
662
+ panel: "_panel_hawkv_2",
663
+ row: "_row_hawkv_20",
664
+ input: "_input_hawkv_26",
665
+ count: "_count_hawkv_44",
666
+ button: "_button_hawkv_52",
667
+ toggle: "_toggle_hawkv_53",
668
+ active: "_active_hawkv_80"
669
+ };
670
+ //#endregion
671
+ //#region src/editor/code-editor/find-panel.tsx
672
+ function me(t) {
673
+ i();
674
+ let n = t.matchCount === 0 ? o(a.editor.noMatches) : o(a.editor.findCount, {
675
+ current: t.currentIndex + 1,
676
+ total: t.matchCount
677
+ });
678
+ return /* @__PURE__ */ d("div", {
679
+ className: O.panel,
680
+ role: "search",
681
+ "aria-label": o(a.editor.find),
682
+ children: [/* @__PURE__ */ d("div", {
683
+ className: O.row,
684
+ children: [
685
+ /* @__PURE__ */ u("button", {
686
+ type: "button",
687
+ className: O.toggle,
688
+ "aria-label": o(a.editor.toggleReplace),
689
+ "aria-expanded": t.replaceMode,
690
+ onClick: t.onToggleReplace,
691
+ children: t.replaceMode ? "▾" : "▸"
692
+ }),
693
+ /* @__PURE__ */ u("input", {
694
+ className: O.input,
695
+ value: t.query,
696
+ placeholder: o(a.editor.findPlaceholder),
697
+ "aria-label": o(a.editor.find),
698
+ autoFocus: !0,
699
+ autoComplete: "off",
700
+ spellCheck: !1,
701
+ onChange: (e) => t.onQueryChange(e.currentTarget.value),
702
+ onKeyDown: (e) => {
703
+ e.key === "Enter" ? (e.preventDefault(), e.shiftKey ? t.onPrev() : t.onNext()) : e.key === "Escape" && (e.preventDefault(), t.onClose());
704
+ }
705
+ }),
706
+ /* @__PURE__ */ u("span", {
707
+ className: O.count,
708
+ "aria-live": "polite",
709
+ children: n
710
+ }),
711
+ /* @__PURE__ */ u("button", {
712
+ type: "button",
713
+ className: O.button,
714
+ "aria-label": o(a.editor.previous),
715
+ onClick: t.onPrev,
716
+ children: "‹"
717
+ }),
718
+ /* @__PURE__ */ u("button", {
719
+ type: "button",
720
+ className: O.button,
721
+ "aria-label": o(a.editor.next),
722
+ onClick: t.onNext,
723
+ children: "›"
724
+ }),
725
+ /* @__PURE__ */ u("button", {
726
+ type: "button",
727
+ className: e(O.button, t.caseSensitive && O.active),
728
+ "aria-pressed": t.caseSensitive,
729
+ "aria-label": o(a.editor.matchCase),
730
+ onClick: t.onToggleCase,
731
+ children: "Aa"
732
+ }),
733
+ /* @__PURE__ */ u("button", {
734
+ type: "button",
735
+ className: O.button,
736
+ "aria-label": o(a.editor.close),
737
+ onClick: t.onClose,
738
+ children: "×"
739
+ })
740
+ ]
741
+ }), t.replaceMode && /* @__PURE__ */ d("div", {
742
+ className: O.row,
743
+ children: [
744
+ /* @__PURE__ */ u("input", {
745
+ className: O.input,
746
+ value: t.replaceQuery,
747
+ placeholder: o(a.editor.replacePlaceholder),
748
+ "aria-label": o(a.editor.replace),
749
+ autoComplete: "off",
750
+ spellCheck: !1,
751
+ onChange: (e) => t.onReplaceChange(e.currentTarget.value),
752
+ onKeyDown: (e) => {
753
+ e.key === "Escape" ? (e.preventDefault(), t.onClose()) : e.key === "Enter" && (e.preventDefault(), t.onReplace());
754
+ }
755
+ }),
756
+ /* @__PURE__ */ u("button", {
757
+ type: "button",
758
+ className: O.button,
759
+ onClick: t.onReplace,
760
+ children: o(a.editor.replaceOne)
761
+ }),
762
+ /* @__PURE__ */ u("button", {
763
+ type: "button",
764
+ className: O.button,
765
+ onClick: t.onReplaceAll,
766
+ children: o(a.editor.replaceAll)
767
+ })
768
+ ]
769
+ })]
770
+ });
771
+ }
772
+ //#endregion
773
+ //#region src/editor/code-editor/find.ts
774
+ var he = /\w/;
775
+ function k(e) {
776
+ return e !== void 0 && he.test(e);
777
+ }
778
+ function ge(e, t, n = {}) {
779
+ if (t.length === 0) return [];
780
+ let r = n.caseSensitive ? e : e.toLowerCase(), i = n.caseSensitive ? t : t.toLowerCase(), a = [], o = 0;
781
+ for (;;) {
782
+ let t = r.indexOf(i, o);
783
+ if (t === -1) break;
784
+ let s = t + i.length;
785
+ (!n.wholeWord || !k(e[t - 1]) && !k(e[s])) && a.push({
786
+ start: t,
787
+ end: s
788
+ }), o = s > t ? s : t + 1;
789
+ }
790
+ return a;
791
+ }
792
+ function _e(e, t) {
793
+ let n = 0, r = 0;
794
+ for (let i = 0; i < t && i < e.length; i++) e[i] === "\n" && (n++, r = i + 1);
795
+ return {
796
+ line: n,
797
+ col: t - r
798
+ };
799
+ }
800
+ function ve(e, t, n, r) {
801
+ return t.map((t, i) => {
802
+ let { line: a, col: o } = _e(e, t.start);
803
+ return {
804
+ line: a,
805
+ start: o,
806
+ end: o + (t.end - t.start),
807
+ className: i === n ? r.current : r.match
808
+ };
809
+ });
810
+ }
811
+ function ye(e, t, n) {
812
+ let r = e;
813
+ for (let e = t.length - 1; e >= 0; e--) {
814
+ let i = t[e];
815
+ r = r.slice(0, i.start) + n + r.slice(i.end);
816
+ }
817
+ return r;
818
+ }
819
+ //#endregion
820
+ //#region src/editor/code-editor/brackets.ts
821
+ var A = {
822
+ "(": ")",
823
+ "[": "]",
824
+ "{": "}"
825
+ }, j = {
826
+ ")": "(",
827
+ "]": "[",
828
+ "}": "}"
829
+ };
830
+ function M(e, t, n, r) {
831
+ let i = 0;
832
+ for (let a = t; a < e.length; a++) {
833
+ let t = e[a];
834
+ if (t === n) i++;
835
+ else if (t === r && --i === 0) return a;
836
+ }
837
+ return -1;
838
+ }
839
+ function N(e, t, n, r) {
840
+ let i = 0;
841
+ for (let a = t; a >= 0; a--) {
842
+ let t = e[a];
843
+ if (t === r) i++;
844
+ else if (t === n && --i === 0) return a;
845
+ }
846
+ return -1;
847
+ }
848
+ function be(e, t) {
849
+ let n = e[t];
850
+ if (n && n in A) {
851
+ let r = M(e, t, n, A[n]);
852
+ if (r !== -1) return {
853
+ open: t,
854
+ close: r
855
+ };
856
+ }
857
+ let r = e[t - 1];
858
+ if (r && r in j) {
859
+ let n = N(e, t - 1, j[r], r);
860
+ if (n !== -1) return {
861
+ open: n,
862
+ close: t - 1
863
+ };
864
+ }
865
+ if (r && r in A) {
866
+ let n = M(e, t - 1, r, A[r]);
867
+ if (n !== -1) return {
868
+ open: t - 1,
869
+ close: n
870
+ };
871
+ }
872
+ if (n && n in j) {
873
+ let r = N(e, t, j[n], n);
874
+ if (r !== -1) return {
875
+ open: r,
876
+ close: t
877
+ };
878
+ }
879
+ }
880
+ function xe(e, t, n) {
881
+ return [t.open, t.close].map((t) => {
882
+ let { line: r, col: i } = _e(e, t);
883
+ return {
884
+ line: r,
885
+ start: i,
886
+ end: i + 1,
887
+ className: n
888
+ };
889
+ });
890
+ }
891
+ //#endregion
892
+ //#region src/editor/code-editor/history.ts
893
+ function Se(e = 200) {
894
+ let t = [], n = -1, r = !1;
895
+ return {
896
+ record(i, a) {
897
+ let o = a?.coalesce ?? !1;
898
+ n < t.length - 1 && (t = t.slice(0, n + 1)), o && r && n >= 0 ? t[n] = i : (t.push(i), n = t.length - 1, t.length > e && (t.shift(), n--)), r = o;
899
+ },
900
+ undo() {
901
+ if (!(n <= 0)) return n--, r = !1, t[n];
902
+ },
903
+ redo() {
904
+ if (!(n >= t.length - 1)) return n++, r = !1, t[n];
905
+ },
906
+ reset(e) {
907
+ t = [e], n = 0, r = !1;
908
+ },
909
+ canUndo() {
910
+ return n > 0;
911
+ },
912
+ canRedo() {
913
+ return n < t.length - 1;
914
+ }
915
+ };
916
+ }
917
+ //#endregion
918
+ //#region src/editor/code-editor/keymap.ts
919
+ var P = typeof navigator < "u" && /Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent || "");
920
+ function F(e) {
921
+ let t = [];
922
+ (P ? e.metaKey : e.ctrlKey) && t.push("Mod"), e.altKey && t.push("Alt"), e.shiftKey && t.push("Shift");
923
+ let n = e.key;
924
+ return n.length === 1 && (n = n.toLowerCase()), t.push(n), t.join("-");
925
+ }
926
+ function Ce(e, t) {
927
+ let n = new Map(Object.entries(e));
928
+ if (t) for (let [e, r] of Object.entries(t)) n.set(e, r);
929
+ return n;
930
+ }
931
+ function we(e, t) {
932
+ let n = e.get(F(t.event));
933
+ return n ? n(t) : !1;
934
+ }
935
+ function Te(e) {
936
+ let t = () => e.insertSpaces ? " ".repeat(e.tabSize) : " ";
937
+ return {
938
+ indent: ({ textarea: e, setText: n }) => {
939
+ let { selectionStart: r, selectionEnd: i, value: a } = e, o = a.lastIndexOf("\n", r - 1) + 1;
940
+ if (r === i) e.setRangeText(t(), r, i, "end");
941
+ else {
942
+ let n = a.slice(o, i).replace(/^/gm, t());
943
+ e.setRangeText(n, o, i, "select");
944
+ }
945
+ return n(e.value), !0;
946
+ },
947
+ dedent: ({ textarea: t, setText: n }) => {
948
+ let { selectionStart: r, selectionEnd: i, value: a } = t, o = a.lastIndexOf("\n", r - 1) + 1, s = a.slice(o, i).replace(RegExp(`^(?:\\t| {1,${e.tabSize}})`, "gm"), "");
949
+ return t.setRangeText(s, o, i, "select"), n(t.value), !0;
950
+ }
951
+ };
952
+ }
953
+ //#endregion
954
+ //#region src/editor/code-editor/sync.ts
955
+ function Ee(e, t) {
956
+ if (e === t) return {
957
+ from: e.length,
958
+ to: e.length,
959
+ insert: ""
960
+ };
961
+ let n = Math.min(e.length, t.length), r = 0;
962
+ for (; r < n && e[r] === t[r];) r++;
963
+ let i = e.length, a = t.length;
964
+ for (; i > r && a > r && e[i - 1] === t[a - 1];) i--, a--;
965
+ return {
966
+ from: r,
967
+ to: i,
968
+ insert: t.slice(r, a)
969
+ };
970
+ }
971
+ function I(e, t) {
972
+ return e <= t.from ? e : e >= t.to ? e + (t.insert.length - (t.to - t.from)) : t.from + t.insert.length;
973
+ }
974
+ function De(e, t, n) {
975
+ return {
976
+ start: I(e, n),
977
+ end: I(t, n)
978
+ };
979
+ }
980
+ var L = s(function({ value: s, defaultValue: f, onValueChange: p, language: ee = "plaintext", lineNumbers: m = !0, tabSize: h = 2, insertSpaces: g = !0, wrap: _ = !1, virtualize: v, readOnly: y = !1, disabled: b = !1, spellCheck: x = !1, label: S, onSave: C, keymap: w, decorations: T, theme: ie, bracketMatching: ae = !1, className: oe, style: se, onKeyDown: ce, ...le }, ue) {
981
+ i();
982
+ let de = l(C);
983
+ de.current = C;
984
+ let [O, he] = t({
985
+ value: s,
986
+ defaultValue: f ?? "",
987
+ onChange: p
988
+ }), k = l(null), A = l(null), j = l(null), M = l(null), N = l(null);
989
+ N.current === null && (N.current = Se(), N.current.reset({
990
+ text: O.value,
991
+ selectionStart: 0,
992
+ selectionEnd: 0
993
+ }));
994
+ let P = N.current, F = l(null), I = l(void 0), L = l(O.value), R = l(void 0), z = l(!1), B = l({
995
+ start: 0,
996
+ end: 0
997
+ }), V = (e, t, n) => {
998
+ R.current = e, L.current = e, P.record({
999
+ text: e,
1000
+ selectionStart: t.start,
1001
+ selectionEnd: t.end
1002
+ }, { coalesce: n }), he(e);
1003
+ }, Oe = (e) => {
1004
+ let t = M.current;
1005
+ V(e, t ? {
1006
+ start: t.selectionStart,
1007
+ end: t.selectionEnd
1008
+ } : B.current, !1);
1009
+ }, ke = (e) => {
1010
+ let t = M.current;
1011
+ if (!t) return;
1012
+ z.current = !0, t.value = e.text, t.setSelectionRange(e.selectionStart, e.selectionEnd), he(e.text), R.current = e.text, L.current = e.text, B.current = {
1013
+ start: e.selectionStart,
1014
+ end: e.selectionEnd
1015
+ }, Ie.value = e.selectionStart;
1016
+ let n = e.text.slice(0, e.selectionStart).split("\n").length - 1;
1017
+ k.current?.style.setProperty("--cascivo-editor-caret-line", String(n)), z.current = !1;
1018
+ }, Ae = () => {
1019
+ let e = P.undo();
1020
+ e && ke(e);
1021
+ }, je = () => {
1022
+ let e = P.redo();
1023
+ e && ke(e);
1024
+ }, H = n(O.value), Me = n(0), Ne = n(0), Pe = n(0), U = n(!1), Fe = n(""), W = n(""), G = n(!1), K = n(!1), q = n(0), Ie = n(0);
1025
+ r(() => {
1026
+ let e = O.value;
1027
+ if (typeof requestAnimationFrame != "function") {
1028
+ H.value = e;
1029
+ return;
1030
+ }
1031
+ let t = requestAnimationFrame(() => {
1032
+ H.value = e;
1033
+ });
1034
+ return () => cancelAnimationFrame(t);
1035
+ }), r(() => {
1036
+ let e = O.value;
1037
+ if (z.current || e === L.current) return;
1038
+ if (e === R.current) {
1039
+ L.current = e;
1040
+ return;
1041
+ }
1042
+ let t = M.current, n = Ee(L.current, e), r = De(B.current.start, B.current.end, n);
1043
+ t && (z.current = !0, t.value !== e && (t.value = e), t.setSelectionRange(r.start, r.end), z.current = !1), B.current = r, P.reset({
1044
+ text: e,
1045
+ selectionStart: r.start,
1046
+ selectionEnd: r.end
1047
+ }), L.current = e;
1048
+ }), r(() => {
1049
+ let e = M.current;
1050
+ if (!e) return;
1051
+ let t = () => {
1052
+ let t = Number.parseFloat(getComputedStyle(e).lineHeight);
1053
+ Pe.value = Number.isFinite(t) && t > 0 ? t : 0, Ne.value = e.clientHeight;
1054
+ }, n = () => {
1055
+ Me.value = e.scrollTop, Ne.value = e.clientHeight, A.current && (A.current.scrollTop = e.scrollTop, A.current.scrollLeft = e.scrollLeft), j.current && (j.current.scrollTop = e.scrollTop);
1056
+ }, r = () => {
1057
+ let t = e.value.slice(0, e.selectionStart).split("\n").length - 1;
1058
+ k.current?.style.setProperty("--cascivo-editor-caret-line", String(t)), B.current = {
1059
+ start: e.selectionStart,
1060
+ end: e.selectionEnd
1061
+ }, Ie.value = e.selectionStart;
1062
+ }, i = () => {
1063
+ document.activeElement === e && r();
1064
+ };
1065
+ return t(), r(), e.addEventListener("scroll", n), e.addEventListener("keyup", r), e.addEventListener("click", r), e.addEventListener("input", r), document.addEventListener("selectionchange", i), () => {
1066
+ e.removeEventListener("scroll", n), e.removeEventListener("keyup", r), e.removeEventListener("click", r), e.removeEventListener("input", r), document.removeEventListener("selectionchange", i);
1067
+ };
1068
+ });
1069
+ let Le = re(ee);
1070
+ (F.current === null || F.current.grammar !== Le) && (F.current = ne(Le), I.current = void 0);
1071
+ let Re = F.current, ze = H.value.split("\n"), J = ze.length, Be = H.value, Y = I.current;
1072
+ if (Be !== Y) {
1073
+ let e = Y === void 0 ? 0 : (() => {
1074
+ let e = Ee(Y, Be);
1075
+ return Y.slice(0, e.from).split("\n").length - 1;
1076
+ })();
1077
+ Re.invalidateFrom(e), I.current = Be;
1078
+ }
1079
+ let X = Pe.value, Ve = (v ?? J > 1e3) && !_ && X > 0, Z = 0, Q = J;
1080
+ if (Ve) {
1081
+ Z = Math.max(0, Math.floor(Me.value / X) - 12);
1082
+ let e = Math.ceil(Ne.value / X);
1083
+ Q = Math.min(J, Z + e + 24);
1084
+ }
1085
+ let He = te(Le, ze, Z, Q, Re), Ue = Z * X, We = (J - Q) * X, $ = U.value ? ge(H.value, Fe.value, { caseSensitive: G.value }) : [];
1086
+ q.value >= $.length && (q.value = Math.max(0, $.length - 1));
1087
+ let Ge = $.length > 0 ? ve(H.value, $, q.value, {
1088
+ match: E.match,
1089
+ current: E.matchCurrent
1090
+ }) : [], Ke = typeof T == "function" ? T(H.value) : T ?? [], qe = [];
1091
+ if (ae) {
1092
+ let e = be(H.value, Ie.value);
1093
+ e && (qe = xe(H.value, e, E.bracketMatch));
1094
+ }
1095
+ let Je = [
1096
+ ...Ke,
1097
+ ...qe,
1098
+ ...Ge
1099
+ ], Ye = Je.length > 0 ? Je : void 0, Xe = (e) => {
1100
+ let t = $[e], n = M.current;
1101
+ if (!(!t || !n) && (n.focus(), n.setSelectionRange(t.start, t.end), B.current = {
1102
+ start: t.start,
1103
+ end: t.end
1104
+ }, X > 0)) {
1105
+ let { line: e } = _e(n.value, t.start), r = e * X;
1106
+ (r < n.scrollTop || r > n.scrollTop + n.clientHeight - X) && (n.scrollTop = Math.max(0, r - n.clientHeight / 2));
1107
+ }
1108
+ }, Ze = () => {
1109
+ $.length !== 0 && (q.value = (q.value + 1) % $.length, Xe(q.value));
1110
+ }, Qe = () => {
1111
+ $.length !== 0 && (q.value = (q.value - 1 + $.length) % $.length, Xe(q.value));
1112
+ }, $e = () => {
1113
+ let e = $[q.value], t = M.current;
1114
+ !e || !t || y || b || (t.setRangeText(W.value, e.start, e.end, "end"), V(t.value, {
1115
+ start: t.selectionStart,
1116
+ end: t.selectionEnd
1117
+ }, !1));
1118
+ }, et = () => {
1119
+ if ($.length === 0 || y || b) return;
1120
+ let e = ye(H.value, $, W.value), t = M.current;
1121
+ t && (t.value = e), V(e, {
1122
+ start: t?.selectionStart ?? 0,
1123
+ end: t?.selectionEnd ?? 0
1124
+ }, !1);
1125
+ }, tt = (e) => {
1126
+ K.value = e, U.value = !0;
1127
+ }, nt = () => {
1128
+ U.value = !1, M.current?.focus();
1129
+ };
1130
+ c(ue, () => ({
1131
+ applyEdit: ({ from: e, to: t }, n) => {
1132
+ let r = M.current;
1133
+ r && (r.setRangeText(n, e, t, "end"), V(r.value, {
1134
+ start: r.selectionStart,
1135
+ end: r.selectionEnd
1136
+ }, !1));
1137
+ },
1138
+ getSelection: () => {
1139
+ let e = M.current;
1140
+ return e ? {
1141
+ start: e.selectionStart,
1142
+ end: e.selectionEnd
1143
+ } : { ...B.current };
1144
+ },
1145
+ focus: () => M.current?.focus(),
1146
+ undo: Ae,
1147
+ redo: je,
1148
+ openFind: () => tt(!1)
1149
+ }));
1150
+ let rt = (e) => {
1151
+ let t = e.currentTarget, n = !y && !b, r = {};
1152
+ if (n) {
1153
+ let { indent: e, dedent: t } = Te({
1154
+ tabSize: h,
1155
+ insertSpaces: g
1156
+ });
1157
+ r.Tab = e, r["Shift-Tab"] = t, r["Mod-z"] = () => (Ae(), !0);
1158
+ let n = () => (je(), !0);
1159
+ r["Mod-Shift-z"] = n, r["Mod-y"] = n;
1160
+ }
1161
+ r["Mod-f"] = () => (tt(!1), !0), r["Mod-Alt-f"] = () => (tt(!0), !0), r["Mod-s"] = () => {
1162
+ let e = de.current;
1163
+ return e ? (e(O.value), !0) : !1;
1164
+ }, U.value && (r.Escape = () => (nt(), !0)), we(Ce(r, w), {
1165
+ textarea: t,
1166
+ event: e,
1167
+ setText: Oe
1168
+ }) && e.preventDefault(), ce?.(e);
1169
+ }, it = {
1170
+ "--cascivo-editor-tab-size": h,
1171
+ ...ie,
1172
+ ...se
1173
+ };
1174
+ return /* @__PURE__ */ d("div", {
1175
+ ref: k,
1176
+ className: e(D.root, oe),
1177
+ "data-wrap": _,
1178
+ "data-line-numbers": m,
1179
+ style: it,
1180
+ children: [m && /* @__PURE__ */ u(pe, {
1181
+ count: J,
1182
+ className: D.gutter,
1183
+ gutterRef: j,
1184
+ start: Z,
1185
+ end: Q,
1186
+ topPad: Ue,
1187
+ bottomPad: We,
1188
+ activeLine: !0
1189
+ }), /* @__PURE__ */ d("div", {
1190
+ className: D.codeArea,
1191
+ children: [
1192
+ /* @__PURE__ */ d("pre", {
1193
+ ref: A,
1194
+ className: D.pre,
1195
+ "aria-hidden": "true",
1196
+ children: [
1197
+ /* @__PURE__ */ u("div", { className: D.currentLine }),
1198
+ Ue > 0 && /* @__PURE__ */ u("div", { style: { blockSize: Ue } }),
1199
+ /* @__PURE__ */ u("code", { children: fe(He, Z, Q, Ye) }),
1200
+ We > 0 && /* @__PURE__ */ u("div", { style: { blockSize: We } })
1201
+ ]
1202
+ }),
1203
+ /* @__PURE__ */ u("textarea", {
1204
+ ref: M,
1205
+ className: D.textarea,
1206
+ value: O.value,
1207
+ onChange: (e) => {
1208
+ let t = e.currentTarget, n = t.value, r = Math.abs(n.length - L.current.length) === 1;
1209
+ V(n, {
1210
+ start: t.selectionStart,
1211
+ end: t.selectionEnd
1212
+ }, r);
1213
+ },
1214
+ onKeyDown: rt,
1215
+ readOnly: y,
1216
+ disabled: b,
1217
+ spellCheck: x,
1218
+ "aria-label": S ?? o(a.editor.label),
1219
+ autoCapitalize: "off",
1220
+ autoCorrect: "off",
1221
+ autoComplete: "off",
1222
+ wrap: _ ? "soft" : "off",
1223
+ ...le
1224
+ }),
1225
+ U.value && /* @__PURE__ */ u(me, {
1226
+ query: Fe.value,
1227
+ replaceQuery: W.value,
1228
+ replaceMode: K.value,
1229
+ caseSensitive: G.value,
1230
+ matchCount: $.length,
1231
+ currentIndex: $.length > 0 ? q.value : -1,
1232
+ onQueryChange: (e) => {
1233
+ Fe.value = e, q.value = 0;
1234
+ },
1235
+ onReplaceChange: (e) => W.value = e,
1236
+ onNext: Ze,
1237
+ onPrev: Qe,
1238
+ onReplace: $e,
1239
+ onReplaceAll: et,
1240
+ onToggleCase: () => G.value = !G.value,
1241
+ onToggleReplace: () => K.value = !K.value,
1242
+ onClose: nt
1243
+ })
1244
+ ]
1245
+ })]
1246
+ });
1247
+ });
1248
+ //#endregion
1249
+ //#region src/editor/highlight/highlight.tsx
1250
+ function R({ value: t, language: n = "plaintext", lineNumbers: r = !1, wrap: a = !1, tabSize: o = 2, label: s, className: c, preRef: l, gutterRef: f, style: p, ...ee }) {
1251
+ i();
1252
+ let m = re(n), h = t.split("\n"), g = te(m, h, 0, h.length, ne(m)), _ = {
1253
+ "--cascivo-editor-tab-size": o,
1254
+ ...p
1255
+ };
1256
+ return /* @__PURE__ */ d("div", {
1257
+ className: e(E.root, c),
1258
+ "data-wrap": a,
1259
+ "data-line-numbers": r,
1260
+ style: _,
1261
+ "aria-label": s,
1262
+ ...ee,
1263
+ children: [r && /* @__PURE__ */ u(pe, {
1264
+ count: g.length,
1265
+ className: E.gutter,
1266
+ gutterRef: f
1267
+ }), /* @__PURE__ */ u("pre", {
1268
+ ref: l,
1269
+ className: E.pre,
1270
+ children: /* @__PURE__ */ u("code", {
1271
+ className: E.code,
1272
+ children: fe(g)
1273
+ })
1274
+ })]
1275
+ });
1276
+ }
1277
+ //#endregion
1278
+ export { L as CodeEditor, R as Highlight, le as bash, ne as createLineStateIndex, b as createRuleGrammar, oe as css, re as getGrammar, se as html, ie as javascript, S as json, y as listGrammars, ce as markdown, x as plaintext, v as registerGrammar, m as tokenize, h as tokenizeDocument, te as tokenizeRange, ae as typescript };