stilo-editor 0.2.1 → 0.3.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.
@@ -0,0 +1,2351 @@
1
+ import { V as e, _ as t, a as n, f as r, i, nt as a } from "./src-DxTXpULc.js";
2
+ import { ALargeSmall as o, Bold as s, CaseSensitive as c, ChevronDown as l, ChevronUp as u, Code as d, ExternalLink as f, FaceSlightlySmilingPlus as p, Grip as m, GripHorizontal as h, GripVertical as g, Highlighter as _, Italic as v, Link as y, List as b, ListChevronsUpDown as x, ListOrdered as S, ListTodo as C, Minus as w, Pencil as T, Plus as E, Quote as D, Redo2 as O, RemoveFormatting as k, Search as A, SquareCode as j, Strikethrough as M, Subscript as N, Superscript as P, Table as F, TextAlignCenter as I, TextAlignEnd as L, TextAlignJustify as R, TextAlignStart as z, Type as ee, Underline as te, Undo2 as ne, Unlink as re, WholeWord as ie, X as ae, createElement as oe } from "lucide";
3
+ import { autoUpdate as se, computePosition as ce, flip as le, hide as ue, offset as B, shift as de } from "@floating-ui/dom";
4
+ //#region src/ui/components/shortcut.ts
5
+ function fe() {
6
+ return /Mac|iPhone|iPad/.test(navigator.platform);
7
+ }
8
+ function V(e, t) {
9
+ let n = e.split("-"), r = n.pop(), i = [];
10
+ if (t) return n.includes("Ctrl") && i.push("⌃"), n.includes("Alt") && i.push("⌥"), n.includes("Shift") && i.push("⇧"), n.includes("Mod") && i.push("⌘"), i.join("") + (r.length === 1 ? r.toUpperCase() : r);
11
+ let a = n.includes("Mod"), o = n.includes("Ctrl");
12
+ return (o || a && !o) && i.push("Ctrl"), n.includes("Alt") && i.push("Alt"), n.includes("Shift") && i.push("Shift"), i.join("+") + (i.length > 0 ? "+" : "") + (r.length === 1 ? r.toUpperCase() : r);
13
+ }
14
+ //#endregion
15
+ //#region src/ui/i18n/en.ts
16
+ var H = {
17
+ "toolbar.label": "Formatting",
18
+ "toolbar.undo": "Undo",
19
+ "toolbar.redo": "Redo",
20
+ "toolbar.bold": "Bold",
21
+ "toolbar.italic": "Italic",
22
+ "toolbar.underline": "Underline",
23
+ "toolbar.strike": "Strikethrough",
24
+ "toolbar.subscript": "Subscript",
25
+ "toolbar.superscript": "Superscript",
26
+ "toolbar.code": "Code",
27
+ "toolbar.clearFormatting": "Clear formatting",
28
+ "toolbar.textCase": "Text case",
29
+ "toolbar.bulletList": "Bulleted list",
30
+ "toolbar.orderedList": "Numbered list",
31
+ "toolbar.taskList": "Checklist",
32
+ "toolbar.blockquote": "Quote",
33
+ "toolbar.codeBlock": "Code block",
34
+ "toolbar.horizontalRule": "Horizontal line",
35
+ "toolbar.link": "Link",
36
+ "toolbar.heading": "Text style",
37
+ "toolbar.fontFamily": "Font",
38
+ "toolbar.fontSize": "Font size",
39
+ "fontSize.decrease": "Decrease font size",
40
+ "fontSize.increase": "Increase font size",
41
+ "toolbar.textAlign": "Alignment",
42
+ "align.left": "Align left",
43
+ "align.center": "Center",
44
+ "align.right": "Align right",
45
+ "align.justify": "Justify",
46
+ "toolbar.lineHeight": "Line spacing",
47
+ "lineHeight.default": "Default",
48
+ "textCase.upper": "UPPERCASE",
49
+ "textCase.lower": "lowercase",
50
+ "textCase.title": "Title Case",
51
+ "textCase.sentence": "Sentence case",
52
+ "textCase.toggle": "tOGGLE cASE",
53
+ "font.default": "Default",
54
+ "font.sansSerif": "Sans serif",
55
+ "font.serif": "Serif",
56
+ "font.monospace": "Monospace",
57
+ "heading.paragraph": "Paragraph",
58
+ "heading.h1": "Heading 1",
59
+ "heading.h2": "Heading 2",
60
+ "heading.h3": "Heading 3",
61
+ "heading.h4": "Heading 4",
62
+ "heading.h5": "Heading 5",
63
+ "heading.h6": "Heading 6",
64
+ "link.url": "URL",
65
+ "link.newTab": "Open in new tab",
66
+ "link.apply": "Apply",
67
+ "link.remove": "Remove link",
68
+ "link.edit": "Edit link",
69
+ "link.open": "Open link in a new tab",
70
+ "toolbar.characters": "Insert character",
71
+ "characters.search": "Search",
72
+ "characters.noResults": "No results",
73
+ "characters.symbols": "Symbols",
74
+ "characters.emoji": "Emoji",
75
+ "characters.punctuation": "Punctuation",
76
+ "characters.currency": "Currency",
77
+ "characters.math": "Math",
78
+ "characters.arrows": "Arrows",
79
+ "characters.greek": "Greek",
80
+ "characters.latin": "Accented letters",
81
+ "characters.signs": "Signs and shapes",
82
+ "characters.smileys": "Smileys",
83
+ "characters.people": "People and gestures",
84
+ "characters.nature": "Animals and nature",
85
+ "characters.food": "Food and drink",
86
+ "characters.travel": "Travel and places",
87
+ "characters.activities": "Activities",
88
+ "characters.objects": "Objects",
89
+ "characters.emojiSymbols": "Symbols",
90
+ "toolbar.textColor": "Text color",
91
+ "toolbar.highlight": "Highlight",
92
+ "color.more": "more colors",
93
+ "color.default": "Default",
94
+ "color.none": "No color",
95
+ "color.pick": "Pick a color",
96
+ "color.custom": "Custom color",
97
+ "color.apply": "Apply",
98
+ "color.black": "Black",
99
+ "color.darkGray2": "Dark gray 2",
100
+ "color.darkGray1": "Dark gray 1",
101
+ "color.gray": "Gray",
102
+ "color.lightGray1": "Light gray 1",
103
+ "color.lightGray2": "Light gray 2",
104
+ "color.lightGray3": "Light gray 3",
105
+ "color.white": "White",
106
+ "color.red": "Red",
107
+ "color.orange": "Orange",
108
+ "color.yellow": "Yellow",
109
+ "color.green": "Green",
110
+ "color.cyan": "Cyan",
111
+ "color.blue": "Blue",
112
+ "color.purple": "Purple",
113
+ "color.pink": "Pink",
114
+ "color.lightRed": "Light red",
115
+ "color.lightOrange": "Light orange",
116
+ "color.lightYellow": "Light yellow",
117
+ "color.lightGreen": "Light green",
118
+ "color.lightCyan": "Light cyan",
119
+ "color.lightBlue": "Light blue",
120
+ "color.lightPurple": "Light purple",
121
+ "color.lightPink": "Light pink",
122
+ "color.darkRed": "Dark red",
123
+ "color.darkOrange": "Dark orange",
124
+ "color.darkYellow": "Dark yellow",
125
+ "color.darkGreen": "Dark green",
126
+ "color.darkCyan": "Dark cyan",
127
+ "color.darkBlue": "Dark blue",
128
+ "color.darkPurple": "Dark purple",
129
+ "color.darkPink": "Dark pink",
130
+ "toolbar.table": "Table",
131
+ "table.insert": "Insert table",
132
+ "table.size": "{columns} × {rows}",
133
+ "table.row": "Row",
134
+ "table.column": "Column",
135
+ "table.headerRow": "Header row",
136
+ "table.headerColumn": "Header column",
137
+ "table.addRowBefore": "Insert row above",
138
+ "table.addRowAfter": "Insert row below",
139
+ "table.deleteRow": "Delete row",
140
+ "table.addColumnBefore": "Insert column left",
141
+ "table.addColumnAfter": "Insert column right",
142
+ "table.deleteColumn": "Delete column",
143
+ "table.mergeCells": "Merge cells",
144
+ "table.splitCell": "Split cell",
145
+ "table.deleteTable": "Delete table",
146
+ "toolbar.find": "Find and replace",
147
+ "find.find": "Find",
148
+ "find.replace": "Replace with",
149
+ "find.previous": "Previous match",
150
+ "find.next": "Next match",
151
+ "find.matchCase": "Match case",
152
+ "find.wholeWord": "Whole word",
153
+ "find.replaceOne": "Replace",
154
+ "find.replaceAll": "Replace all",
155
+ "find.close": "Close",
156
+ "find.position": "{current} of {total}",
157
+ "find.results": "Results: {total}",
158
+ "find.noResults": "No results",
159
+ "status.words": "Words",
160
+ "status.characters": "Characters"
161
+ }, pe = 500;
162
+ function me(t, n) {
163
+ let { container: r, messages: i = H } = n, a = document.createElement("div");
164
+ a.className = "stilo-status-bar";
165
+ let o = document.createElement("span");
166
+ o.className = "stilo-status-bar__words";
167
+ let s = document.createElement("span");
168
+ s.className = "stilo-status-bar__characters", a.append(o, s), r.append(a);
169
+ let c = 0, l = !1;
170
+ function u() {
171
+ clearTimeout(c), c = 0;
172
+ let n = e(t);
173
+ o.textContent = `${i["status.words"]}: ${n.words.toLocaleString()}`, s.textContent = `${i["status.characters"]}: ${n.characters.toLocaleString()}`;
174
+ }
175
+ let d = () => {
176
+ clearTimeout(c), c = window.setTimeout(u, pe);
177
+ };
178
+ function f() {
179
+ l || (l = !0, clearTimeout(c), t.off("input", d), t.off("destroy", f), a.remove());
180
+ }
181
+ return t.on("input", d), t.on("destroy", f), u(), {
182
+ element: a,
183
+ update: u,
184
+ destroy: f
185
+ };
186
+ }
187
+ //#endregion
188
+ //#region src/ui/i18n/it.ts
189
+ var he = {
190
+ "toolbar.label": "Formattazione",
191
+ "toolbar.undo": "Annulla",
192
+ "toolbar.redo": "Ripeti",
193
+ "toolbar.bold": "Grassetto",
194
+ "toolbar.italic": "Corsivo",
195
+ "toolbar.underline": "Sottolineato",
196
+ "toolbar.strike": "Barrato",
197
+ "toolbar.subscript": "Pedice",
198
+ "toolbar.superscript": "Apice",
199
+ "toolbar.code": "Codice",
200
+ "toolbar.clearFormatting": "Cancella formattazione",
201
+ "toolbar.textCase": "Maiuscole e minuscole",
202
+ "toolbar.bulletList": "Elenco puntato",
203
+ "toolbar.orderedList": "Elenco numerato",
204
+ "toolbar.taskList": "Elenco di controllo",
205
+ "toolbar.blockquote": "Citazione",
206
+ "toolbar.codeBlock": "Blocco di codice",
207
+ "toolbar.horizontalRule": "Linea orizzontale",
208
+ "toolbar.link": "Collegamento",
209
+ "toolbar.heading": "Stile testo",
210
+ "toolbar.fontFamily": "Carattere",
211
+ "toolbar.fontSize": "Dimensione carattere",
212
+ "fontSize.decrease": "Riduci dimensione carattere",
213
+ "fontSize.increase": "Aumenta dimensione carattere",
214
+ "toolbar.textAlign": "Allineamento",
215
+ "align.left": "Allinea a sinistra",
216
+ "align.center": "Centra",
217
+ "align.right": "Allinea a destra",
218
+ "align.justify": "Giustifica",
219
+ "toolbar.lineHeight": "Interlinea",
220
+ "lineHeight.default": "Predefinita",
221
+ "textCase.upper": "MAIUSCOLO",
222
+ "textCase.lower": "minuscolo",
223
+ "textCase.title": "Iniziali Maiuscole",
224
+ "textCase.sentence": "Tipo frase",
225
+ "textCase.toggle": "iNVERTI mAIUSCOLE",
226
+ "font.default": "Predefinito",
227
+ "font.sansSerif": "Senza grazie",
228
+ "font.serif": "Con grazie",
229
+ "font.monospace": "Monospaziato",
230
+ "heading.paragraph": "Paragrafo",
231
+ "heading.h1": "Titolo 1",
232
+ "heading.h2": "Titolo 2",
233
+ "heading.h3": "Titolo 3",
234
+ "heading.h4": "Titolo 4",
235
+ "heading.h5": "Titolo 5",
236
+ "heading.h6": "Titolo 6",
237
+ "link.url": "URL",
238
+ "link.newTab": "Apri in una nuova scheda",
239
+ "link.apply": "Applica",
240
+ "link.remove": "Rimuovi collegamento",
241
+ "link.edit": "Modifica collegamento",
242
+ "link.open": "Apri il collegamento in una nuova scheda",
243
+ "toolbar.characters": "Inserisci carattere",
244
+ "characters.search": "Cerca",
245
+ "characters.noResults": "Nessun risultato",
246
+ "characters.symbols": "Simboli",
247
+ "characters.emoji": "Emoji",
248
+ "characters.punctuation": "Punteggiatura",
249
+ "characters.currency": "Valute",
250
+ "characters.math": "Matematica",
251
+ "characters.arrows": "Frecce",
252
+ "characters.greek": "Greco",
253
+ "characters.latin": "Lettere accentate",
254
+ "characters.signs": "Segni e forme",
255
+ "characters.smileys": "Faccine",
256
+ "characters.people": "Persone e gesti",
257
+ "characters.nature": "Animali e natura",
258
+ "characters.food": "Cibo e bevande",
259
+ "characters.travel": "Viaggi e luoghi",
260
+ "characters.activities": "Attività",
261
+ "characters.objects": "Oggetti",
262
+ "characters.emojiSymbols": "Simboli",
263
+ "toolbar.textColor": "Colore testo",
264
+ "toolbar.highlight": "Evidenziatore",
265
+ "color.more": "altri colori",
266
+ "color.default": "Predefinito",
267
+ "color.none": "Nessun colore",
268
+ "color.pick": "Scegli un colore",
269
+ "color.custom": "Colore personalizzato",
270
+ "color.apply": "Applica",
271
+ "color.black": "Nero",
272
+ "color.darkGray2": "Grigio scuro 2",
273
+ "color.darkGray1": "Grigio scuro 1",
274
+ "color.gray": "Grigio",
275
+ "color.lightGray1": "Grigio chiaro 1",
276
+ "color.lightGray2": "Grigio chiaro 2",
277
+ "color.lightGray3": "Grigio chiaro 3",
278
+ "color.white": "Bianco",
279
+ "color.red": "Rosso",
280
+ "color.orange": "Arancione",
281
+ "color.yellow": "Giallo",
282
+ "color.green": "Verde",
283
+ "color.cyan": "Ciano",
284
+ "color.blue": "Blu",
285
+ "color.purple": "Viola",
286
+ "color.pink": "Rosa",
287
+ "color.lightRed": "Rosso chiaro",
288
+ "color.lightOrange": "Arancione chiaro",
289
+ "color.lightYellow": "Giallo chiaro",
290
+ "color.lightGreen": "Verde chiaro",
291
+ "color.lightCyan": "Ciano chiaro",
292
+ "color.lightBlue": "Blu chiaro",
293
+ "color.lightPurple": "Viola chiaro",
294
+ "color.lightPink": "Rosa chiaro",
295
+ "color.darkRed": "Rosso scuro",
296
+ "color.darkOrange": "Arancione scuro",
297
+ "color.darkYellow": "Giallo scuro",
298
+ "color.darkGreen": "Verde scuro",
299
+ "color.darkCyan": "Ciano scuro",
300
+ "color.darkBlue": "Blu scuro",
301
+ "color.darkPurple": "Viola scuro",
302
+ "color.darkPink": "Rosa scuro",
303
+ "toolbar.table": "Tabella",
304
+ "table.insert": "Inserisci tabella",
305
+ "table.size": "{columns} × {rows}",
306
+ "table.row": "Riga",
307
+ "table.column": "Colonna",
308
+ "table.headerRow": "Riga di intestazione",
309
+ "table.headerColumn": "Colonna di intestazione",
310
+ "table.addRowBefore": "Inserisci riga sopra",
311
+ "table.addRowAfter": "Inserisci riga sotto",
312
+ "table.deleteRow": "Elimina riga",
313
+ "table.addColumnBefore": "Inserisci colonna a sinistra",
314
+ "table.addColumnAfter": "Inserisci colonna a destra",
315
+ "table.deleteColumn": "Elimina colonna",
316
+ "table.mergeCells": "Unisci celle",
317
+ "table.splitCell": "Dividi cella",
318
+ "table.deleteTable": "Elimina tabella",
319
+ "toolbar.find": "Trova e sostituisci",
320
+ "find.find": "Trova",
321
+ "find.replace": "Sostituisci con",
322
+ "find.previous": "Risultato precedente",
323
+ "find.next": "Risultato successivo",
324
+ "find.matchCase": "Maiuscole/minuscole",
325
+ "find.wholeWord": "Parola intera",
326
+ "find.replaceOne": "Sostituisci",
327
+ "find.replaceAll": "Sostituisci tutto",
328
+ "find.close": "Chiudi",
329
+ "find.position": "{current} di {total}",
330
+ "find.results": "Risultati: {total}",
331
+ "find.noResults": "Nessun risultato",
332
+ "status.words": "Parole",
333
+ "status.characters": "Caratteri"
334
+ }, ge = [
335
+ {
336
+ fontFamily: "sans-serif",
337
+ labelKey: "font.sansSerif"
338
+ },
339
+ {
340
+ fontFamily: "serif",
341
+ labelKey: "font.serif"
342
+ },
343
+ {
344
+ fontFamily: "monospace",
345
+ labelKey: "font.monospace"
346
+ },
347
+ {
348
+ fontFamily: "Arial, Helvetica, sans-serif",
349
+ labelKey: "Arial"
350
+ },
351
+ {
352
+ fontFamily: "Verdana, Geneva, sans-serif",
353
+ labelKey: "Verdana"
354
+ },
355
+ {
356
+ fontFamily: "Tahoma, Geneva, sans-serif",
357
+ labelKey: "Tahoma"
358
+ },
359
+ {
360
+ fontFamily: "'Trebuchet MS', Helvetica, sans-serif",
361
+ labelKey: "Trebuchet MS"
362
+ },
363
+ {
364
+ fontFamily: "Georgia, serif",
365
+ labelKey: "Georgia"
366
+ },
367
+ {
368
+ fontFamily: "'Times New Roman', Times, serif",
369
+ labelKey: "Times New Roman"
370
+ },
371
+ {
372
+ fontFamily: "'Courier New', Courier, monospace",
373
+ labelKey: "Courier New"
374
+ }
375
+ ], _e = {
376
+ pt: [
377
+ 8,
378
+ 9,
379
+ 10,
380
+ 11,
381
+ 12,
382
+ 14,
383
+ 18,
384
+ 24,
385
+ 36,
386
+ 48,
387
+ 72
388
+ ],
389
+ px: [
390
+ 10,
391
+ 12,
392
+ 14,
393
+ 16,
394
+ 18,
395
+ 20,
396
+ 24,
397
+ 32,
398
+ 48,
399
+ 64,
400
+ 96
401
+ ]
402
+ };
403
+ //#endregion
404
+ //#region src/ui/components/popover.ts
405
+ function U(e) {
406
+ let { anchor: t, content: n, container: r, placement: i = "bottom-start", offset: a = 4, onClose: o } = e, s = !1, c = !1, l, u = 0;
407
+ n.classList.add("stilo-popover"), n.setAttribute("hidden", ""), r.classList.add("stilo-popover-host"), r.appendChild(n);
408
+ function d() {
409
+ let e = ++u;
410
+ Promise.resolve(ce(t, n, {
411
+ strategy: "absolute",
412
+ placement: i,
413
+ middleware: [
414
+ B(a),
415
+ le(),
416
+ de({ padding: 8 })
417
+ ]
418
+ }).then((t) => {
419
+ s || u !== e || (n.style.left = `${t.x}px`, n.style.top = `${t.y}px`);
420
+ }));
421
+ }
422
+ function f() {
423
+ c || s || (c = !0, n.removeAttribute("hidden"), l = se(t, n, () => {
424
+ c && d();
425
+ }), document.addEventListener("pointerdown", h, !0), document.addEventListener("keydown", g, !0));
426
+ }
427
+ function p(e = "api") {
428
+ c && !s && (c = !1, n.setAttribute("hidden", ""), l?.(), l = void 0, document.removeEventListener("pointerdown", h, !0), document.removeEventListener("keydown", g, !0), o?.(e));
429
+ }
430
+ function m() {
431
+ s || (s = !0, c && (c = !1, n.setAttribute("hidden", ""), l?.(), l = void 0, document.removeEventListener("pointerdown", h, !0), document.removeEventListener("keydown", g, !0), o?.("api")), r.contains(n) && r.removeChild(n), r.querySelector(":scope > .stilo-popover") || r.classList.remove("stilo-popover-host"));
432
+ }
433
+ function h(e) {
434
+ if (!c || s) return;
435
+ let r = e.target;
436
+ n.contains(r) || typeof t == "object" && "nodeType" in t && t.nodeType === 1 && t.contains(r) || p("outside");
437
+ }
438
+ function g(e) {
439
+ c && !s && e.key === "Escape" && (e.preventDefault(), p("escape"));
440
+ }
441
+ return {
442
+ get isOpen() {
443
+ return c;
444
+ },
445
+ open: f,
446
+ close: p,
447
+ destroy: m
448
+ };
449
+ }
450
+ //#endregion
451
+ //#region src/ui/components/link-popover.ts
452
+ var ve = "https://example.com";
453
+ function ye(e) {
454
+ return e.isEditable && (e.isActive("link") || e.commands.setLink.can({ href: ve }));
455
+ }
456
+ function be(e, t) {
457
+ let { container: n, messages: r } = t, i = {
458
+ contextElement: e.view.dom,
459
+ getBoundingClientRect: () => {
460
+ let { from: t, to: n } = e.state.selection, r = e.view.coordsAtPos(t), i = e.view.coordsAtPos(n), a = Math.min(r.left, i.left), o = Math.max(r.right, i.right), { top: s } = r, { bottom: c } = i;
461
+ return {
462
+ x: a,
463
+ y: s,
464
+ left: a,
465
+ top: s,
466
+ right: o,
467
+ bottom: c,
468
+ width: o - a,
469
+ height: c - s
470
+ };
471
+ }
472
+ }, a = document.createElement("div");
473
+ a.className = "stilo-link-popover", a.setAttribute("role", "dialog"), a.setAttribute("aria-label", r["toolbar.link"]);
474
+ let o = document.createElement("form");
475
+ o.className = "stilo-link-popover__form";
476
+ let s = document.createElement("input");
477
+ s.type = "text", s.inputMode = "url", s.className = "stilo-link-popover__url", s.placeholder = "https://", s.autocomplete = "off", s.spellcheck = !1, s.setAttribute("aria-label", r["link.url"]);
478
+ let c = document.createElement("label");
479
+ c.className = "stilo-link-popover__new-tab";
480
+ let l = document.createElement("input");
481
+ l.type = "checkbox", c.append(l, r["link.newTab"]);
482
+ let u = document.createElement("div");
483
+ u.className = "stilo-link-popover__actions";
484
+ let d = xe("submit", r["link.apply"]);
485
+ d.classList.add("stilo-link-popover__button--primary");
486
+ let f = xe("button", r["link.remove"]);
487
+ u.append(d, f), o.append(s, c, u), a.append(o);
488
+ let p = U({
489
+ anchor: i,
490
+ content: a,
491
+ container: n,
492
+ onClose: (t) => {
493
+ t === "escape" && e.focus();
494
+ }
495
+ });
496
+ function m() {
497
+ p.close(), e.focus();
498
+ }
499
+ let h = (t) => {
500
+ t.preventDefault();
501
+ let n = s.value.trim();
502
+ (n ? e.commands.setLink({
503
+ href: n,
504
+ target: l.checked ? "_blank" : null
505
+ }) : !e.isActive("link") || e.commands.unsetLink()) ? m() : (s.setAttribute("aria-invalid", "true"), s.focus());
506
+ }, g = () => {
507
+ e.commands.unsetLink(), m();
508
+ }, _ = () => {
509
+ s.removeAttribute("aria-invalid");
510
+ };
511
+ o.addEventListener("submit", h), f.addEventListener("click", g), s.addEventListener("input", _);
512
+ function v() {
513
+ if (p.isOpen || !ye(e)) return;
514
+ let { href: t, target: n } = e.getAttributes("link");
515
+ s.value = typeof t == "string" ? t : "", s.removeAttribute("aria-invalid"), l.checked = n === "_blank", f.hidden = !e.isActive("link"), p.open(), s.focus({ preventScroll: !0 }), s.select();
516
+ }
517
+ function y() {
518
+ o.removeEventListener("submit", h), f.removeEventListener("click", g), s.removeEventListener("input", _), p.destroy();
519
+ }
520
+ return {
521
+ get isOpen() {
522
+ return p.isOpen;
523
+ },
524
+ open: v,
525
+ close: () => p.close(),
526
+ destroy: y
527
+ };
528
+ }
529
+ function xe(e, t) {
530
+ let n = document.createElement("button");
531
+ return n.type = e, n.className = "stilo-link-popover__button", n.textContent = t, n;
532
+ }
533
+ //#endregion
534
+ //#region src/ui/toolbar/palette.ts
535
+ function W(e, t) {
536
+ return {
537
+ color: e,
538
+ labelKey: t
539
+ };
540
+ }
541
+ var G = [
542
+ W("#000000", "color.black"),
543
+ W("#404040", "color.darkGray2"),
544
+ W("#737373", "color.darkGray1"),
545
+ W("#a3a3a3", "color.gray"),
546
+ W("#d4d4d4", "color.lightGray1"),
547
+ W("#e5e5e5", "color.lightGray2"),
548
+ W("#f5f5f5", "color.lightGray3"),
549
+ W("#ffffff", "color.white"),
550
+ W("#ef4444", "color.red"),
551
+ W("#f97316", "color.orange"),
552
+ W("#eab308", "color.yellow"),
553
+ W("#22c55e", "color.green"),
554
+ W("#06b6d4", "color.cyan"),
555
+ W("#3b82f6", "color.blue"),
556
+ W("#a855f7", "color.purple"),
557
+ W("#ec4899", "color.pink"),
558
+ W("#fecaca", "color.lightRed"),
559
+ W("#fed7aa", "color.lightOrange"),
560
+ W("#fef08a", "color.lightYellow"),
561
+ W("#bbf7d0", "color.lightGreen"),
562
+ W("#a5f3fc", "color.lightCyan"),
563
+ W("#bfdbfe", "color.lightBlue"),
564
+ W("#e9d5ff", "color.lightPurple"),
565
+ W("#fbcfe8", "color.lightPink"),
566
+ W("#991b1b", "color.darkRed"),
567
+ W("#9a3412", "color.darkOrange"),
568
+ W("#854d0e", "color.darkYellow"),
569
+ W("#166534", "color.darkGreen"),
570
+ W("#155e75", "color.darkCyan"),
571
+ W("#1e40af", "color.darkBlue"),
572
+ W("#6b21a8", "color.darkPurple"),
573
+ W("#9d174d", "color.darkPink")
574
+ ], Se = [
575
+ ["undo", "redo"],
576
+ ["heading"],
577
+ ["fontFamily", "fontSize"],
578
+ [
579
+ "bold",
580
+ "italic",
581
+ "underline",
582
+ "strike",
583
+ "code",
584
+ "subscript",
585
+ "superscript",
586
+ "link",
587
+ "clearFormatting",
588
+ "textCase"
589
+ ],
590
+ ["textColor", "highlight"],
591
+ ["textAlign", "lineHeight"],
592
+ [
593
+ "bulletList",
594
+ "orderedList",
595
+ "taskList",
596
+ "blockquote",
597
+ "codeBlock",
598
+ "horizontalRule",
599
+ "table",
600
+ "characters"
601
+ ],
602
+ ["find"]
603
+ ], Ce = {
604
+ undo: {
605
+ id: "undo",
606
+ kind: "button",
607
+ icon: ne,
608
+ labelKey: "toolbar.undo",
609
+ shortcut: "Mod-z",
610
+ run: (e) => {
611
+ e.commands.undo();
612
+ },
613
+ isEnabled: (e) => e.isEditable && e.commands.undo.can()
614
+ },
615
+ redo: {
616
+ id: "redo",
617
+ kind: "button",
618
+ icon: O,
619
+ labelKey: "toolbar.redo",
620
+ shortcut: "Mod-Shift-z",
621
+ run: (e) => {
622
+ e.commands.redo();
623
+ },
624
+ isEnabled: (e) => e.isEditable && e.commands.redo.can()
625
+ },
626
+ bold: {
627
+ id: "bold",
628
+ kind: "button",
629
+ icon: s,
630
+ labelKey: "toolbar.bold",
631
+ shortcut: "Mod-b",
632
+ run: (e) => {
633
+ e.commands.toggleBold();
634
+ },
635
+ isActive: (e) => e.isActive("bold"),
636
+ isEnabled: (e) => e.isEditable && "toggleBold" in e.commands && e.commands.toggleBold.can(),
637
+ isAvailable: (e) => "toggleBold" in e.commands
638
+ },
639
+ italic: {
640
+ id: "italic",
641
+ kind: "button",
642
+ icon: v,
643
+ labelKey: "toolbar.italic",
644
+ shortcut: "Mod-i",
645
+ run: (e) => {
646
+ e.commands.toggleItalic();
647
+ },
648
+ isActive: (e) => e.isActive("italic"),
649
+ isEnabled: (e) => e.isEditable && "toggleItalic" in e.commands && e.commands.toggleItalic.can(),
650
+ isAvailable: (e) => "toggleItalic" in e.commands
651
+ },
652
+ underline: {
653
+ id: "underline",
654
+ kind: "button",
655
+ icon: te,
656
+ labelKey: "toolbar.underline",
657
+ shortcut: "Mod-u",
658
+ run: (e) => {
659
+ e.commands.toggleUnderline();
660
+ },
661
+ isActive: (e) => e.isActive("underline"),
662
+ isEnabled: (e) => e.isEditable && "toggleUnderline" in e.commands && e.commands.toggleUnderline.can(),
663
+ isAvailable: (e) => "toggleUnderline" in e.commands
664
+ },
665
+ strike: {
666
+ id: "strike",
667
+ kind: "button",
668
+ icon: M,
669
+ labelKey: "toolbar.strike",
670
+ shortcut: "Mod-Shift-s",
671
+ run: (e) => {
672
+ e.commands.toggleStrike();
673
+ },
674
+ isActive: (e) => e.isActive("strike"),
675
+ isEnabled: (e) => e.isEditable && "toggleStrike" in e.commands && e.commands.toggleStrike.can(),
676
+ isAvailable: (e) => "toggleStrike" in e.commands
677
+ },
678
+ code: {
679
+ id: "code",
680
+ kind: "button",
681
+ icon: d,
682
+ labelKey: "toolbar.code",
683
+ shortcut: "Mod-e",
684
+ run: (e) => {
685
+ e.commands.toggleCode();
686
+ },
687
+ isActive: (e) => e.isActive("code"),
688
+ isEnabled: (e) => e.isEditable && "toggleCode" in e.commands && e.commands.toggleCode.can(),
689
+ isAvailable: (e) => "toggleCode" in e.commands
690
+ },
691
+ subscript: {
692
+ id: "subscript",
693
+ kind: "button",
694
+ icon: N,
695
+ labelKey: "toolbar.subscript",
696
+ shortcut: "Mod-,",
697
+ run: (e) => {
698
+ e.commands.toggleSubscript();
699
+ },
700
+ isActive: (e) => e.isActive("subscript"),
701
+ isEnabled: (e) => e.isEditable && "toggleSubscript" in e.commands && e.commands.toggleSubscript.can(),
702
+ isAvailable: (e) => "toggleSubscript" in e.commands
703
+ },
704
+ superscript: {
705
+ id: "superscript",
706
+ kind: "button",
707
+ icon: P,
708
+ labelKey: "toolbar.superscript",
709
+ shortcut: "Mod-.",
710
+ run: (e) => {
711
+ e.commands.toggleSuperscript();
712
+ },
713
+ isActive: (e) => e.isActive("superscript"),
714
+ isEnabled: (e) => e.isEditable && "toggleSuperscript" in e.commands && e.commands.toggleSuperscript.can(),
715
+ isAvailable: (e) => "toggleSuperscript" in e.commands
716
+ },
717
+ link: {
718
+ id: "link",
719
+ kind: "button",
720
+ icon: y,
721
+ labelKey: "toolbar.link",
722
+ shortcut: "Mod-k",
723
+ run: (e, t) => {
724
+ t.openLinkPopover();
725
+ },
726
+ isActive: (e) => e.isActive("link"),
727
+ isEnabled: (e) => "setLink" in e.commands && ye(e),
728
+ isAvailable: (e) => "setLink" in e.commands
729
+ },
730
+ clearFormatting: {
731
+ id: "clearFormatting",
732
+ kind: "button",
733
+ icon: k,
734
+ labelKey: "toolbar.clearFormatting",
735
+ shortcut: "Mod-\\",
736
+ run: (e) => {
737
+ e.commands.clearFormatting();
738
+ },
739
+ isEnabled: (e) => e.isEditable && "clearFormatting" in e.commands && e.commands.clearFormatting.can(),
740
+ isAvailable: (e) => "clearFormatting" in e.commands
741
+ },
742
+ textCase: {
743
+ id: "textCase",
744
+ kind: "dropdown",
745
+ labelKey: "toolbar.textCase",
746
+ icon: o,
747
+ options: [
748
+ "upper",
749
+ "lower",
750
+ "title",
751
+ "sentence",
752
+ "toggle"
753
+ ].map((e) => ({
754
+ id: e,
755
+ labelKey: `textCase.${e}`,
756
+ run: (t) => {
757
+ t.commands.setTextCase(e);
758
+ },
759
+ isEnabled: (t) => t.isEditable && t.commands.setTextCase.can(e)
760
+ })),
761
+ isAvailable: (e) => "setTextCase" in e.commands
762
+ },
763
+ bulletList: {
764
+ id: "bulletList",
765
+ kind: "button",
766
+ icon: b,
767
+ labelKey: "toolbar.bulletList",
768
+ shortcut: "Mod-Shift-8",
769
+ run: (e) => {
770
+ e.commands.toggleBulletList();
771
+ },
772
+ isActive: (e) => e.isActive("bulletList"),
773
+ isEnabled: (e) => e.isEditable && "toggleBulletList" in e.commands && e.commands.toggleBulletList.can(),
774
+ isAvailable: (e) => "toggleBulletList" in e.commands
775
+ },
776
+ orderedList: {
777
+ id: "orderedList",
778
+ kind: "button",
779
+ icon: S,
780
+ labelKey: "toolbar.orderedList",
781
+ shortcut: "Mod-Shift-7",
782
+ run: (e) => {
783
+ e.commands.toggleOrderedList();
784
+ },
785
+ isActive: (e) => e.isActive("orderedList"),
786
+ isEnabled: (e) => e.isEditable && "toggleOrderedList" in e.commands && e.commands.toggleOrderedList.can(),
787
+ isAvailable: (e) => "toggleOrderedList" in e.commands
788
+ },
789
+ taskList: {
790
+ id: "taskList",
791
+ kind: "button",
792
+ icon: C,
793
+ labelKey: "toolbar.taskList",
794
+ shortcut: "Mod-Shift-9",
795
+ run: (e) => {
796
+ e.commands.toggleTaskList();
797
+ },
798
+ isActive: (e) => e.isActive("taskList"),
799
+ isEnabled: (e) => e.isEditable && "toggleTaskList" in e.commands && e.commands.toggleTaskList.can(),
800
+ isAvailable: (e) => "toggleTaskList" in e.commands
801
+ },
802
+ blockquote: {
803
+ id: "blockquote",
804
+ kind: "button",
805
+ icon: D,
806
+ labelKey: "toolbar.blockquote",
807
+ shortcut: "Mod-Shift-b",
808
+ run: (e) => {
809
+ e.commands.toggleBlockquote();
810
+ },
811
+ isActive: (e) => e.isActive("blockquote"),
812
+ isEnabled: (e) => e.isEditable && "toggleBlockquote" in e.commands && e.commands.toggleBlockquote.can(),
813
+ isAvailable: (e) => "toggleBlockquote" in e.commands
814
+ },
815
+ codeBlock: {
816
+ id: "codeBlock",
817
+ kind: "button",
818
+ icon: j,
819
+ labelKey: "toolbar.codeBlock",
820
+ shortcut: "Mod-Alt-c",
821
+ run: (e) => {
822
+ e.commands.toggleCodeBlock();
823
+ },
824
+ isActive: (e) => e.isActive("codeBlock"),
825
+ isEnabled: (e) => e.isEditable && "toggleCodeBlock" in e.commands && e.commands.toggleCodeBlock.can(),
826
+ isAvailable: (e) => "toggleCodeBlock" in e.commands
827
+ },
828
+ horizontalRule: {
829
+ id: "horizontalRule",
830
+ kind: "button",
831
+ icon: w,
832
+ labelKey: "toolbar.horizontalRule",
833
+ run: (e) => {
834
+ e.commands.setHorizontalRule();
835
+ },
836
+ isEnabled: (e) => e.isEditable && "setHorizontalRule" in e.commands && e.commands.setHorizontalRule.can(),
837
+ isAvailable: (e) => "setHorizontalRule" in e.commands
838
+ },
839
+ table: {
840
+ id: "table",
841
+ kind: "button",
842
+ icon: F,
843
+ labelKey: "toolbar.table",
844
+ run: (e, t) => {
845
+ t.toggleTableMenu();
846
+ },
847
+ isEnabled: (e) => e.isEditable && (e.isActive("table") || e.commands.insertTable.can()),
848
+ isAvailable: (e) => "insertTable" in e.commands
849
+ },
850
+ characters: {
851
+ id: "characters",
852
+ kind: "button",
853
+ icon: p,
854
+ labelKey: "toolbar.characters",
855
+ run: (e, t) => {
856
+ t.toggleCharacterPicker();
857
+ },
858
+ isEnabled: (e) => e.isEditable,
859
+ isAvailable: (e) => "insertText" in e.commands
860
+ },
861
+ find: {
862
+ id: "find",
863
+ kind: "button",
864
+ icon: A,
865
+ labelKey: "toolbar.find",
866
+ shortcut: "Mod-f",
867
+ run: (e, t) => {
868
+ t.toggleFindBar();
869
+ },
870
+ isAvailable: (e) => "setSearch" in e.commands
871
+ },
872
+ heading: Ie(),
873
+ fontFamily: Ae(),
874
+ fontSize: je(),
875
+ textAlign: Ne(),
876
+ lineHeight: Fe(),
877
+ textColor: Te(),
878
+ highlight: Ee()
879
+ };
880
+ function we(e, t) {
881
+ let { color: n } = e.getAttributes(t);
882
+ return typeof n == "string" ? n : null;
883
+ }
884
+ function Te(e = G) {
885
+ return {
886
+ id: "textColor",
887
+ kind: "color",
888
+ icon: ee,
889
+ labelKey: "toolbar.textColor",
890
+ palette: e,
891
+ defaultColor: "#000000",
892
+ setColor: (e, t) => t !== null && e.commands.setColor(t),
893
+ unsetColor: (e) => {
894
+ e.commands.unsetColor();
895
+ },
896
+ hasColor: (e, t) => e.isActive("textStyle", { color: t }),
897
+ getColor: (e) => we(e, "textStyle"),
898
+ isEnabled: (e) => e.isEditable && "setColor" in e.commands && e.commands.setColor.can("#000000"),
899
+ isAvailable: (e) => "setColor" in e.commands
900
+ };
901
+ }
902
+ function Ee(e = G) {
903
+ return {
904
+ id: "highlight",
905
+ kind: "color",
906
+ icon: _,
907
+ labelKey: "toolbar.highlight",
908
+ palette: e,
909
+ defaultColor: null,
910
+ defaultChoice: !0,
911
+ setColor: (e, t) => e.commands.setHighlight({ color: t }),
912
+ unsetColor: (e) => {
913
+ e.commands.unsetHighlight();
914
+ },
915
+ hasColor: (e, t) => e.isActive("highlight", { color: t }),
916
+ getColor: (e) => we(e, "highlight"),
917
+ isEnabled: (e) => e.isEditable && "setHighlight" in e.commands && e.commands.setHighlight.can(),
918
+ isAvailable: (e) => "setHighlight" in e.commands
919
+ };
920
+ }
921
+ function De(e) {
922
+ return e.split(",")[0].replace(/'/g, "").trim();
923
+ }
924
+ function Oe(e) {
925
+ return De(e).toLowerCase().replace(/[^a-z0-9]+/g, "-");
926
+ }
927
+ function ke(e) {
928
+ let { fontFamily: t } = e.getAttributes("textStyle");
929
+ return typeof t == "string" && e.isActive("textStyle", { fontFamily: t }) ? t : null;
930
+ }
931
+ function Ae(e = ge) {
932
+ return {
933
+ id: "fontFamily",
934
+ kind: "dropdown",
935
+ labelKey: "toolbar.fontFamily",
936
+ options: [{
937
+ id: "default",
938
+ labelKey: "font.default",
939
+ run: (e) => {
940
+ e.commands.unsetFontFamily();
941
+ },
942
+ isActive: () => !1,
943
+ isEnabled: (e) => e.isEditable && e.commands.setFontFamily.can("serif")
944
+ }, ...e.map(({ fontFamily: e, labelKey: t }) => ({
945
+ id: Oe(e),
946
+ labelKey: t,
947
+ fontFamily: e,
948
+ run: (t) => {
949
+ t.commands.setFontFamily(e);
950
+ },
951
+ isActive: (t) => t.isActive("textStyle", { fontFamily: e }),
952
+ isEnabled: (t) => t.isEditable && t.commands.setFontFamily.can(e)
953
+ }))],
954
+ getValueLabel: (e) => {
955
+ let t = ke(e);
956
+ return t === null ? null : De(t);
957
+ },
958
+ isAvailable: (e) => "setFontFamily" in e.commands
959
+ };
960
+ }
961
+ function je(e = {}) {
962
+ let { unit: t = "pt", sizes: n = _e[t === "pt" ? "pt" : "px"] } = e;
963
+ return {
964
+ id: "fontSize",
965
+ kind: "fontSize",
966
+ labelKey: "toolbar.fontSize",
967
+ unit: t,
968
+ sizes: n,
969
+ isAvailable: (e) => "stepFontSize" in e.commands
970
+ };
971
+ }
972
+ function Me(e) {
973
+ let t = e.getAttributes("heading").textAlign ?? e.getAttributes("paragraph").textAlign;
974
+ return typeof t == "string" ? t : "left";
975
+ }
976
+ function Ne() {
977
+ return {
978
+ id: "textAlign",
979
+ kind: "iconMenu",
980
+ labelKey: "toolbar.textAlign",
981
+ options: [
982
+ [
983
+ "left",
984
+ z,
985
+ "Mod-Shift-l"
986
+ ],
987
+ [
988
+ "center",
989
+ I,
990
+ "Mod-Shift-e"
991
+ ],
992
+ [
993
+ "right",
994
+ L,
995
+ "Mod-Shift-r"
996
+ ],
997
+ [
998
+ "justify",
999
+ R,
1000
+ "Mod-Shift-j"
1001
+ ]
1002
+ ].map(([e, t, n]) => ({
1003
+ id: e,
1004
+ icon: t,
1005
+ labelKey: `align.${e}`,
1006
+ shortcut: n,
1007
+ run: (t) => {
1008
+ t.commands.setTextAlign(e);
1009
+ },
1010
+ isActive: (t) => Me(t) === e,
1011
+ isEnabled: (t) => t.isEditable && t.commands.setTextAlign.can(e)
1012
+ })),
1013
+ isAvailable: (e) => "setTextAlign" in e.commands
1014
+ };
1015
+ }
1016
+ function Pe(e) {
1017
+ return e.getAttributes("heading").lineHeight ?? e.getAttributes("paragraph").lineHeight;
1018
+ }
1019
+ function Fe(e = [
1020
+ 1,
1021
+ 1.15,
1022
+ 1.5,
1023
+ 2
1024
+ ]) {
1025
+ return {
1026
+ id: "lineHeight",
1027
+ kind: "dropdown",
1028
+ labelKey: "toolbar.lineHeight",
1029
+ icon: x,
1030
+ options: [{
1031
+ id: "default",
1032
+ labelKey: "lineHeight.default",
1033
+ run: (e) => {
1034
+ e.commands.unsetLineHeight();
1035
+ },
1036
+ isActive: (e) => Pe(e) == null,
1037
+ isEnabled: (e) => e.isEditable && e.commands.unsetLineHeight.can()
1038
+ }, ...e.map((e) => ({
1039
+ id: String(e).replace(".", "-"),
1040
+ labelKey: String(e),
1041
+ run: (t) => {
1042
+ t.commands.setLineHeight(e);
1043
+ },
1044
+ isActive: (t) => Pe(t) === String(e),
1045
+ isEnabled: (t) => t.isEditable && t.commands.setLineHeight.can(e)
1046
+ }))],
1047
+ isAvailable: (e) => "setLineHeight" in e.commands
1048
+ };
1049
+ }
1050
+ function Ie(e = [
1051
+ 1,
1052
+ 2,
1053
+ 3,
1054
+ 4,
1055
+ 5,
1056
+ 6
1057
+ ]) {
1058
+ return {
1059
+ id: "heading",
1060
+ kind: "dropdown",
1061
+ labelKey: "toolbar.heading",
1062
+ options: [{
1063
+ id: "paragraph",
1064
+ labelKey: "heading.paragraph",
1065
+ shortcut: "Mod-Alt-0",
1066
+ run: (e) => {
1067
+ e.commands.setParagraph();
1068
+ },
1069
+ isActive: (e) => e.isActive("paragraph"),
1070
+ isEnabled: (e) => e.isEditable && (e.isActive("paragraph") || e.commands.setParagraph.can())
1071
+ }, ...e.map((e) => ({
1072
+ id: `h${e}`,
1073
+ labelKey: `heading.h${e}`,
1074
+ shortcut: `Mod-Alt-${e}`,
1075
+ run: (t) => {
1076
+ t.commands.setHeading({ level: e });
1077
+ },
1078
+ isActive: (t) => t.isActive("heading", { level: e }),
1079
+ isEnabled: (t) => t.isEditable && (t.isActive("heading", { level: e }) || t.commands.setHeading.can({ level: e }))
1080
+ }))],
1081
+ isAvailable: (e) => "setHeading" in e.commands
1082
+ };
1083
+ }
1084
+ //#endregion
1085
+ //#region src/ui/components/character-picker.ts
1086
+ var Le = 10;
1087
+ async function Re() {
1088
+ let { SYMBOLS: e, EMOJI: t } = await import("./characters--8h5uTeF.js");
1089
+ return {
1090
+ symbols: e,
1091
+ emoji: t
1092
+ };
1093
+ }
1094
+ function ze(e, t) {
1095
+ let { anchor: n, container: r, messages: i } = t, a = document.createElement("div");
1096
+ a.className = "stilo-char-picker", a.setAttribute("role", "dialog"), a.setAttribute("aria-label", i["toolbar.characters"]);
1097
+ let o = document.createElement("input");
1098
+ o.type = "search", o.className = "stilo-char-picker__search", o.placeholder = i["characters.search"], o.autocomplete = "off", o.spellcheck = !1, o.setAttribute("aria-label", i["characters.search"]);
1099
+ let s = document.createElement("div");
1100
+ s.className = "stilo-char-picker__tabs", s.setAttribute("role", "tablist");
1101
+ let c = /* @__PURE__ */ new Map();
1102
+ for (let e of ["symbols", "emoji"]) {
1103
+ let t = document.createElement("button");
1104
+ t.type = "button", t.className = "stilo-char-picker__tab", t.setAttribute("role", "tab"), t.textContent = i[`characters.${e}`], c.set(e, t), s.append(t);
1105
+ }
1106
+ let l = document.createElement("div");
1107
+ l.className = "stilo-char-picker__panel", l.setAttribute("role", "tabpanel"), a.append(o, s, l), n.setAttribute("aria-haspopup", "dialog"), n.setAttribute("aria-expanded", "false");
1108
+ let u = U({
1109
+ anchor: n,
1110
+ content: a,
1111
+ container: r,
1112
+ onClose: (t) => {
1113
+ n.setAttribute("aria-expanded", "false"), t === "escape" && e.focus();
1114
+ }
1115
+ }), d = null, f = "symbols", p = [], m = [];
1116
+ function h(e) {
1117
+ f = e;
1118
+ for (let [t, n] of c) {
1119
+ let r = t === e;
1120
+ n.setAttribute("aria-selected", String(r)), n.tabIndex = r ? 0 : -1;
1121
+ }
1122
+ }
1123
+ function g(e, t) {
1124
+ let n = document.createElement("div");
1125
+ n.className = "stilo-char-picker__grid", n.setAttribute("role", "group"), n.setAttribute("aria-label", t);
1126
+ let r = e.map(([e, t]) => {
1127
+ let n = document.createElement("button");
1128
+ return n.type = "button", n.className = "stilo-char-picker__char", n.tabIndex = -1, n.title = t, n.setAttribute("aria-label", t), n.dataset.character = e, n.textContent = e, n;
1129
+ });
1130
+ n.append(...r), p.push(...r);
1131
+ for (let e = 0; e < r.length; e += Le) m.push(r.slice(e, e + Le));
1132
+ return n;
1133
+ }
1134
+ function _() {
1135
+ if (!d) return;
1136
+ p = [], m = [], l.replaceChildren();
1137
+ let e = o.value.trim().toLowerCase();
1138
+ if (s.hidden = e !== "", e) {
1139
+ let t = [...d.symbols, ...d.emoji].flatMap((e) => e.characters).filter(([t, n]) => t === e || n.toLowerCase().includes(e));
1140
+ if (t.length > 0) l.append(g(t, i["characters.search"]));
1141
+ else {
1142
+ let e = document.createElement("p");
1143
+ e.className = "stilo-char-picker__empty", e.textContent = i["characters.noResults"], l.append(e);
1144
+ }
1145
+ } else for (let e of d[f]) {
1146
+ let t = i[e.labelKey], n = document.createElement("div");
1147
+ n.className = "stilo-char-picker__heading", n.textContent = t, l.append(n, g(e.characters, t));
1148
+ }
1149
+ p[0] && (p[0].tabIndex = 0);
1150
+ }
1151
+ function v(e) {
1152
+ if (e) {
1153
+ for (let e of p) e.tabIndex = -1;
1154
+ e.tabIndex = 0, e.focus();
1155
+ }
1156
+ }
1157
+ function y(e, t) {
1158
+ if (t === "ArrowLeft") return p[p.indexOf(e) - 1];
1159
+ if (t === "ArrowRight") return p[p.indexOf(e) + 1];
1160
+ let n = m.findIndex((t) => t.includes(e)), r = m[n].indexOf(e), i = m[t === "ArrowUp" ? n - 1 : n + 1];
1161
+ return i?.[Math.min(r, i.length - 1)];
1162
+ }
1163
+ let b = () => _(), x = (e) => {
1164
+ e.key === "ArrowDown" && p[0] && (e.preventDefault(), v(p[0]));
1165
+ }, S = (e) => {
1166
+ let t = [...c].find(([, t]) => t === e.target)?.[0];
1167
+ t && (h(t), _());
1168
+ }, C = (e) => {
1169
+ if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
1170
+ e.preventDefault();
1171
+ let t = f === "symbols" ? "emoji" : "symbols";
1172
+ h(t), _(), c.get(t).focus();
1173
+ }, w = (t) => {
1174
+ let n = t.target.closest(".stilo-char-picker__char");
1175
+ n?.dataset.character && (e.commands.insertText(n.dataset.character), v(n));
1176
+ }, T = (e) => {
1177
+ let t = e.target.closest(".stilo-char-picker__char");
1178
+ t && [
1179
+ "ArrowLeft",
1180
+ "ArrowRight",
1181
+ "ArrowUp",
1182
+ "ArrowDown"
1183
+ ].includes(e.key) && (e.preventDefault(), v(y(t, e.key)));
1184
+ };
1185
+ o.addEventListener("input", b), o.addEventListener("keydown", x), s.addEventListener("click", S), s.addEventListener("keydown", C), l.addEventListener("click", w), l.addEventListener("keydown", T), h(f);
1186
+ async function E() {
1187
+ u.isOpen || (u.open(), n.setAttribute("aria-expanded", "true"), d ??= await Re(), u.isOpen && (o.value = "", _(), o.focus({ preventScroll: !0 })));
1188
+ }
1189
+ function D() {
1190
+ u.isOpen && (u.close(), e.focus());
1191
+ }
1192
+ function O() {
1193
+ o.removeEventListener("input", b), o.removeEventListener("keydown", x), s.removeEventListener("click", S), s.removeEventListener("keydown", C), l.removeEventListener("click", w), l.removeEventListener("keydown", T), u.destroy(), n.removeAttribute("aria-haspopup"), n.removeAttribute("aria-expanded");
1194
+ }
1195
+ return {
1196
+ get isOpen() {
1197
+ return u.isOpen;
1198
+ },
1199
+ open: E,
1200
+ close: D,
1201
+ toggle: () => u.isOpen ? D() : void E(),
1202
+ destroy: O
1203
+ };
1204
+ }
1205
+ //#endregion
1206
+ //#region src/ui/components/icon.ts
1207
+ function K(e) {
1208
+ return oe(e, {
1209
+ class: "stilo-icon",
1210
+ "aria-hidden": "true"
1211
+ });
1212
+ }
1213
+ //#endregion
1214
+ //#region src/ui/components/color-button.ts
1215
+ var Be = 8, Ve = "Mark", He = /^#[0-9a-f]{6}$/;
1216
+ function q(e, t) {
1217
+ let n = document.createElement(e);
1218
+ return n.className = t, n;
1219
+ }
1220
+ function J(e, t) {
1221
+ let n = q("button", e);
1222
+ return n.type = "button", n.setAttribute("aria-label", t), n.title = t, n;
1223
+ }
1224
+ function Ue(e, t, n) {
1225
+ let { container: r, messages: i } = n, a = i[t.labelKey] ?? t.labelKey, o = t.defaultColor, s = q("span", "stilo-split"), c = J("stilo-toolbar__button stilo-split__main", a), u = q("span", "stilo-split__color");
1226
+ c.append(K(t.icon), u);
1227
+ let d = J("stilo-toolbar__button stilo-split__arrow", `${a}: ${i["color.more"]}`);
1228
+ d.append(K(l));
1229
+ for (let e of [c, d]) e.dataset.item = t.id, e.tabIndex = -1;
1230
+ c.setAttribute("aria-pressed", "false"), d.setAttribute("aria-haspopup", "dialog"), d.setAttribute("aria-expanded", "false"), s.append(c, d);
1231
+ let f = q("div", "stilo-color-picker");
1232
+ f.setAttribute("role", "dialog"), f.setAttribute("aria-label", a);
1233
+ let p = q("div", "stilo-color-picker__actions"), m = q("button", "stilo-color-picker__none");
1234
+ m.type = "button", m.textContent = i["color.none"], p.append(m);
1235
+ let h = null;
1236
+ if (t.defaultChoice) {
1237
+ let e = q("span", "stilo-color-picker__separator");
1238
+ e.setAttribute("aria-hidden", "true"), h = q("button", "stilo-color-picker__default"), h.type = "button";
1239
+ let t = document.createElement("mark");
1240
+ t.textContent = i["color.default"], h.append(t), p.append(e, h);
1241
+ }
1242
+ let g = q("div", "stilo-color-picker__grid");
1243
+ g.setAttribute("role", "group"), g.setAttribute("aria-label", a);
1244
+ let _ = t.palette.map(({ color: e, labelKey: t }) => {
1245
+ let n = J("stilo-color-picker__swatch", i[t] ?? t);
1246
+ return n.tabIndex = -1, n.dataset.color = e, n.style.backgroundColor = e, n;
1247
+ });
1248
+ g.append(..._);
1249
+ let v = q("form", "stilo-color-picker__custom"), y = q("input", "stilo-color-picker__native");
1250
+ y.type = "color", y.setAttribute("aria-label", i["color.pick"]);
1251
+ let b = q("input", "stilo-color-picker__value");
1252
+ b.type = "text", b.placeholder = "#000000", b.autocomplete = "off", b.spellcheck = !1, b.setAttribute("aria-label", i["color.custom"]);
1253
+ let x = q("button", "stilo-color-picker__apply");
1254
+ x.type = "submit", x.textContent = i["color.apply"], v.append(y, b, x), f.append(p, g, v);
1255
+ let S = U({
1256
+ anchor: s,
1257
+ content: f,
1258
+ container: r,
1259
+ onClose: (t) => {
1260
+ d.setAttribute("aria-expanded", "false"), t === "escape" && e.focus();
1261
+ }
1262
+ });
1263
+ function C() {
1264
+ u.style.backgroundColor = o ?? Ve;
1265
+ }
1266
+ function w() {
1267
+ return t.isEnabled?.(e) ?? !0;
1268
+ }
1269
+ function T() {
1270
+ let n = w();
1271
+ for (let e of [c, d]) n ? e.removeAttribute("aria-disabled") : e.setAttribute("aria-disabled", "true");
1272
+ let r = n && t.hasColor(e, o);
1273
+ c.setAttribute("aria-pressed", String(r)), c.classList.toggle("stilo-toolbar__button--active", r);
1274
+ }
1275
+ function E(e, t) {
1276
+ if (e) {
1277
+ for (let e of _) e.tabIndex = -1;
1278
+ e.tabIndex = 0, e.focus(t);
1279
+ }
1280
+ }
1281
+ function D() {
1282
+ let n = t.getColor(e);
1283
+ for (let e of _) e.setAttribute("aria-pressed", String(e.dataset.color === n));
1284
+ h?.setAttribute("aria-pressed", String(t.hasColor(e, null))), b.value = n ?? "", b.removeAttribute("aria-invalid"), y.value = n && He.test(n) ? n : "#000000", S.open(), d.setAttribute("aria-expanded", "true");
1285
+ let r = _.find((e) => e.getAttribute("aria-pressed") === "true");
1286
+ !r && h?.getAttribute("aria-pressed") === "true" ? h.focus({ preventScroll: !0 }) : E(r ?? _[0], { preventScroll: !0 });
1287
+ }
1288
+ function O() {
1289
+ S.close(), e.focus();
1290
+ }
1291
+ function k(n) {
1292
+ return t.setColor(e, n) ? (o = t.getColor(e), C(), !0) : !1;
1293
+ }
1294
+ let A = () => {
1295
+ w() && (S.close(), e.focus(), t.hasColor(e, o) ? t.unsetColor(e) : k(o));
1296
+ }, j = () => {
1297
+ S.isOpen ? O() : w() && D();
1298
+ }, M = () => {
1299
+ t.unsetColor(e), o = t.defaultColor, C(), O();
1300
+ }, N = () => {
1301
+ k(null), O();
1302
+ }, P = (e) => {
1303
+ let t = e.target.closest(".stilo-color-picker__swatch");
1304
+ t?.dataset.color && (k(t.dataset.color), O());
1305
+ }, F = (e) => {
1306
+ let t = {
1307
+ ArrowLeft: -1,
1308
+ ArrowRight: 1,
1309
+ ArrowUp: -8,
1310
+ ArrowDown: Be
1311
+ }[e.key], n = _.indexOf(e.target);
1312
+ t !== void 0 && n !== -1 && (e.preventDefault(), E(_[n + t]));
1313
+ }, I = () => {
1314
+ b.value = y.value, b.removeAttribute("aria-invalid");
1315
+ }, L = () => b.removeAttribute("aria-invalid"), R = (e) => {
1316
+ e.preventDefault(), k(b.value.trim()) ? O() : (b.setAttribute("aria-invalid", "true"), b.focus());
1317
+ };
1318
+ c.addEventListener("click", A), d.addEventListener("click", j), m.addEventListener("click", M), h?.addEventListener("click", N), g.addEventListener("click", P), g.addEventListener("keydown", F), y.addEventListener("input", I), b.addEventListener("input", L), v.addEventListener("submit", R), C();
1319
+ function z() {
1320
+ c.removeEventListener("click", A), d.removeEventListener("click", j), m.removeEventListener("click", M), h?.removeEventListener("click", N), g.removeEventListener("click", P), g.removeEventListener("keydown", F), y.removeEventListener("input", I), b.removeEventListener("input", L), v.removeEventListener("submit", R), S.destroy(), s.remove();
1321
+ }
1322
+ return {
1323
+ element: s,
1324
+ main: c,
1325
+ arrow: d,
1326
+ update: T,
1327
+ destroy: z
1328
+ };
1329
+ }
1330
+ //#endregion
1331
+ //#region src/ui/components/dropdown.ts
1332
+ function We(e) {
1333
+ let { label: t, options: n, icon: r, container: i, onSelect: a } = e, o = document.createElement("button");
1334
+ o.type = "button", o.className = `stilo-toolbar__button stilo-dropdown__trigger${r ? " stilo-dropdown__trigger--icon" : ""}`, o.setAttribute("aria-haspopup", "menu"), o.setAttribute("aria-expanded", "false"), o.setAttribute("title", t), o.setAttribute("tabindex", "-1");
1335
+ let s = document.createElement("span");
1336
+ s.className = "stilo-dropdown__value", o.appendChild(r ? K(r) : s);
1337
+ let c = K(l);
1338
+ o.appendChild(c);
1339
+ let u = document.createElement("div");
1340
+ u.className = "stilo-dropdown__menu stilo-popover", u.setAttribute("role", "menu"), u.setAttribute("aria-label", t), u.setAttribute("hidden", "");
1341
+ let d = [];
1342
+ for (let e of n) {
1343
+ let t = document.createElement("div");
1344
+ t.className = `stilo-dropdown__option stilo-dropdown__option--${e.id}`, t.setAttribute("role", e.action ? "menuitem" : "menuitemradio"), t.setAttribute("tabindex", "-1"), t.setAttribute("data-option", e.id), e.action || t.setAttribute("aria-checked", "false");
1345
+ let n = document.createElement("span");
1346
+ if (n.className = "stilo-dropdown__label", n.textContent = e.label, e.fontFamily && (n.style.fontFamily = e.fontFamily), t.appendChild(n), e.shortcut) {
1347
+ let n = document.createElement("span");
1348
+ n.className = "stilo-dropdown__shortcut", n.textContent = e.shortcut, t.appendChild(n);
1349
+ }
1350
+ d.push(t), u.appendChild(t);
1351
+ }
1352
+ let f;
1353
+ i.appendChild(u);
1354
+ function p() {
1355
+ if (f) return;
1356
+ f = U({
1357
+ anchor: o,
1358
+ content: u,
1359
+ container: i,
1360
+ onClose(e) {
1361
+ e === "escape" && o.focus(), o.setAttribute("aria-expanded", "false"), f = void 0;
1362
+ }
1363
+ }), o.setAttribute("aria-expanded", "true"), f.open();
1364
+ let e = d.findIndex((e) => e.getAttribute("aria-checked") === "true");
1365
+ if (e >= 0) d[e].focus();
1366
+ else {
1367
+ let e = d.findIndex((e) => e.getAttribute("aria-disabled") !== "true");
1368
+ e >= 0 && d[e].focus();
1369
+ }
1370
+ }
1371
+ function m() {
1372
+ f && (f.close(), o.setAttribute("aria-expanded", "false"));
1373
+ }
1374
+ function h() {
1375
+ o.getAttribute("aria-disabled") !== "true" && (f ? m() : p());
1376
+ }
1377
+ o.addEventListener("click", h);
1378
+ function g(e) {
1379
+ if (o.getAttribute("aria-disabled") !== "true") switch (e.key) {
1380
+ case "ArrowDown": {
1381
+ e.preventDefault(), p();
1382
+ let t = d.findIndex((e) => e.getAttribute("aria-disabled") !== "true");
1383
+ t >= 0 && d[t].focus();
1384
+ break;
1385
+ }
1386
+ case "ArrowUp":
1387
+ e.preventDefault(), p();
1388
+ for (let e = d.length - 1; e >= 0; e--) if (d[e].getAttribute("aria-disabled") !== "true") {
1389
+ d[e].focus();
1390
+ break;
1391
+ }
1392
+ }
1393
+ }
1394
+ o.addEventListener("keydown", g);
1395
+ function _(e) {
1396
+ let t = document.activeElement;
1397
+ if (!t || !u.contains(t)) return;
1398
+ let n = d.filter((e) => e.getAttribute("aria-disabled") !== "true"), r = n.indexOf(t);
1399
+ switch (e.key) {
1400
+ case "ArrowDown":
1401
+ e.preventDefault(), n[(r + 1) % n.length].focus();
1402
+ break;
1403
+ case "ArrowUp":
1404
+ e.preventDefault(), n[(r - 1 + n.length) % n.length].focus();
1405
+ break;
1406
+ case "Home":
1407
+ e.preventDefault(), n[0].focus();
1408
+ break;
1409
+ case "End":
1410
+ e.preventDefault(), n[n.length - 1].focus();
1411
+ break;
1412
+ case "Enter":
1413
+ if (e.preventDefault(), t === document.activeElement && t !== o) {
1414
+ let e = t.getAttribute("data-option");
1415
+ e && t.getAttribute("aria-disabled") !== "true" && (a(e), m());
1416
+ }
1417
+ break;
1418
+ case " ":
1419
+ if (e.preventDefault(), t === document.activeElement && t !== o) {
1420
+ let e = t.getAttribute("data-option");
1421
+ e && t.getAttribute("aria-disabled") !== "true" && a(e);
1422
+ }
1423
+ break;
1424
+ case "Escape":
1425
+ e.preventDefault(), m(), o.focus();
1426
+ break;
1427
+ case "Tab": m();
1428
+ }
1429
+ }
1430
+ u.addEventListener("keydown", _);
1431
+ for (let e of d) e.addEventListener("click", () => {
1432
+ let t = e.getAttribute("data-option");
1433
+ t && e.getAttribute("aria-disabled") !== "true" && (a(t), m());
1434
+ });
1435
+ let v = !1;
1436
+ function y(e) {
1437
+ let { activeId: r, disabledIds: i, valueLabel: a } = e, c = n.find((e) => e.id === r)?.label ?? a ?? t;
1438
+ s.textContent = c;
1439
+ let l = n.every((e) => e.action);
1440
+ o.setAttribute("aria-label", l ? t : `${t}: ${c}`), i.size === n.length ? o.setAttribute("aria-disabled", "true") : o.removeAttribute("aria-disabled");
1441
+ for (let e of d) {
1442
+ let t = e.getAttribute("data-option");
1443
+ i.has(t) ? e.setAttribute("aria-disabled", "true") : e.removeAttribute("aria-disabled"), e.getAttribute("role") === "menuitemradio" && e.setAttribute("aria-checked", t === r ? "true" : "false");
1444
+ }
1445
+ }
1446
+ function b() {
1447
+ v || (v = !0, f?.destroy(), f = void 0, o.removeEventListener("click", h), o.removeEventListener("keydown", g), u.removeEventListener("keydown", _));
1448
+ }
1449
+ return {
1450
+ get trigger() {
1451
+ return o;
1452
+ },
1453
+ update: y,
1454
+ destroy: b
1455
+ };
1456
+ }
1457
+ //#endregion
1458
+ //#region src/ui/components/find-bar.ts
1459
+ var Ge = 350, Ke = 2;
1460
+ function qe(e, n) {
1461
+ let { container: r, messages: i, button: a } = n, o = fe(), s = document.createElement("div");
1462
+ s.className = "stilo-find-bar", s.setAttribute("role", "search"), s.setAttribute("aria-label", i["toolbar.find"]), s.hidden = !0, a?.setAttribute("aria-expanded", "false");
1463
+ function d(e, t) {
1464
+ let n = document.createElement("input");
1465
+ return n.type = "text", n.className = `stilo-find-bar__input stilo-find-bar__input--${t}`, n.placeholder = i[e], n.autocomplete = "off", n.spellcheck = !1, n.setAttribute("aria-label", i[e]), n;
1466
+ }
1467
+ function f(e, t, n) {
1468
+ let r = document.createElement("button");
1469
+ return r.type = "button", r.className = "stilo-find-bar__button", t ? (r.append(K(t)), r.setAttribute("aria-label", i[e]), r.title = n ?? i[e]) : (r.classList.add("stilo-find-bar__button--text"), r.textContent = i[e]), r;
1470
+ }
1471
+ function p(e, t) {
1472
+ let n = f(e, t);
1473
+ return n.classList.add("stilo-find-bar__toggle"), n.setAttribute("aria-pressed", "false"), n;
1474
+ }
1475
+ let m = d("find.find", "find"), h = document.createElement("span");
1476
+ h.className = "stilo-find-bar__count", h.setAttribute("aria-live", "polite");
1477
+ let g = f("find.previous", u, `${i["find.previous"]} (Shift+Enter)`), _ = f("find.next", l, `${i["find.next"]} (Enter)`), v = p("find.matchCase", c), y = p("find.wholeWord", ie), b = f("find.close", ae, `${i["find.close"]} (Esc)`), x = d("find.replace", "replace"), S = f("find.replaceOne", null), C = f("find.replaceAll", null), w = document.createElement("div");
1478
+ w.className = "stilo-find-bar__row", w.append(m, h, g, _, v, y, b);
1479
+ let T = document.createElement("div");
1480
+ T.className = "stilo-find-bar__row", T.append(x, S, C), s.append(w, T), r.append(s), r.classList.add("stilo-find-bar-host");
1481
+ let E = 0, D = "";
1482
+ function O(e) {
1483
+ return e.getAttribute("aria-pressed") === "true";
1484
+ }
1485
+ function k() {
1486
+ clearTimeout(E), E = 0, D = m.value.length >= Ke ? m.value : "", D ? e.commands.setSearch({
1487
+ text: D,
1488
+ caseSensitive: O(v),
1489
+ wholeWord: O(y)
1490
+ }) : e.commands.clearSearch(), j();
1491
+ }
1492
+ function A() {
1493
+ E && k();
1494
+ }
1495
+ function j() {
1496
+ if (!D) {
1497
+ h.textContent = "";
1498
+ return;
1499
+ }
1500
+ let n = t(e), r = n.count.toLocaleString();
1501
+ h.textContent = n.count === 0 ? i["find.noResults"] : n.current > 0 ? i["find.position"].replace("{current}", n.current.toLocaleString()).replace("{total}", r) : i["find.results"].replace("{total}", r);
1502
+ }
1503
+ function M() {
1504
+ let { $from: t, $to: n, empty: r } = e.state.selection;
1505
+ return r || !t.sameParent(n) || !t.parent.isTextblock ? "" : e.state.doc.textBetween(t.pos, n.pos);
1506
+ }
1507
+ function N() {
1508
+ let t = M();
1509
+ s.hidden = !1, a?.setAttribute("aria-expanded", "true"), T.hidden = !e.isEditable, t && (m.value = t), m.focus({ preventScroll: !0 }), m.select(), k();
1510
+ }
1511
+ function P() {
1512
+ s.hidden || (clearTimeout(E), E = 0, s.hidden = !0, a?.setAttribute("aria-expanded", "false"), D = "", e.commands.clearSearch(), e.focus());
1513
+ }
1514
+ let F = () => {
1515
+ clearTimeout(E), E = window.setTimeout(k, Ge);
1516
+ }, I = (t) => {
1517
+ let n = o ? t.metaKey : t.ctrlKey;
1518
+ t.key === "Escape" ? (t.preventDefault(), P()) : n && !t.altKey && !t.shiftKey && t.key.toLowerCase() === "f" ? (t.preventDefault(), m.focus(), m.select()) : t.key === "Enter" && t.target === m ? (t.preventDefault(), A(), t.shiftKey ? e.commands.findPrevious() : e.commands.findNext()) : t.key === "Enter" && t.target === x && (t.preventDefault(), A(), e.commands.replaceNext(x.value));
1519
+ }, L = (t) => {
1520
+ let n = t.target.closest("button");
1521
+ n === v || n === y ? (n.setAttribute("aria-pressed", String(!O(n))), k()) : (A(), n === g ? e.commands.findPrevious() : n === _ ? e.commands.findNext() : n === S ? e.commands.replaceNext(x.value) : n === C ? e.commands.replaceAll(x.value) : n === b && P());
1522
+ }, R = () => {
1523
+ s.hidden || (T.hidden = !e.isEditable, j());
1524
+ };
1525
+ return m.addEventListener("input", F), s.addEventListener("keydown", I), s.addEventListener("click", L), e.on("transaction", R), {
1526
+ element: s,
1527
+ get isOpen() {
1528
+ return !s.hidden;
1529
+ },
1530
+ open: N,
1531
+ close: P,
1532
+ toggle: () => s.hidden ? N() : P(),
1533
+ destroy() {
1534
+ clearTimeout(E), m.removeEventListener("input", F), s.removeEventListener("keydown", I), s.removeEventListener("click", L), e.off("transaction", R), s.remove(), r.classList.remove("stilo-find-bar-host"), a?.removeAttribute("aria-expanded");
1535
+ }
1536
+ };
1537
+ }
1538
+ //#endregion
1539
+ //#region src/ui/components/font-size-input.ts
1540
+ var Je = /^(\d+(?:[.,]\d+)?)\s*(px|pt|em|rem|%)?$/i, Ye = 1, Xe = 400;
1541
+ function Ze(e) {
1542
+ let { from: t, to: n, empty: r } = e.state.selection;
1543
+ if (r) return !1;
1544
+ let i = /* @__PURE__ */ new Set();
1545
+ return e.state.doc.nodesBetween(t, n, (e) => (e.isText && i.add(e.marks.find((e) => e.type.name === "textStyle")?.attrs.fontSize ?? null), i.size < 2)), i.size > 1;
1546
+ }
1547
+ function Qe(e, t) {
1548
+ let n = document.createElement("button");
1549
+ return n.type = "button", n.className = `stilo-toolbar__button ${e}`, n.setAttribute("aria-label", t), n.title = t, n;
1550
+ }
1551
+ function $e(e, t, r) {
1552
+ let { container: a, messages: o } = r, { unit: s, sizes: c } = t, l = o[t.labelKey] ?? t.labelKey, u = document.createElement("span");
1553
+ u.className = "stilo-font-size";
1554
+ let d = Qe("stilo-font-size__decrease", o["fontSize.decrease"]);
1555
+ d.append(K(w));
1556
+ let f = Qe("stilo-font-size__increase", o["fontSize.increase"]);
1557
+ f.append(K(E));
1558
+ let p = document.createElement("input");
1559
+ p.type = "text", p.className = "stilo-font-size__input", p.inputMode = "decimal", p.autocomplete = "off", p.spellcheck = !1, p.setAttribute("role", "combobox"), p.setAttribute("aria-label", l), p.setAttribute("aria-autocomplete", "none"), p.setAttribute("aria-expanded", "false"), p.title = l;
1560
+ let m = [
1561
+ d,
1562
+ p,
1563
+ f
1564
+ ];
1565
+ for (let e of m) e.dataset.item = t.id, e.tabIndex = -1;
1566
+ u.append(...m);
1567
+ let h = document.createElement("div");
1568
+ h.className = "stilo-font-size__list", h.id = `stilo-font-size-${Math.random().toString(36).slice(2)}`, h.setAttribute("role", "listbox"), h.setAttribute("aria-label", l), p.setAttribute("aria-controls", h.id);
1569
+ let g = c.map((e, t) => {
1570
+ let n = document.createElement("div");
1571
+ return n.className = "stilo-font-size__option", n.id = `${h.id}-${t}`, n.setAttribute("role", "option"), n.setAttribute("aria-selected", "false"), n.dataset.size = String(e), n.textContent = String(e), n;
1572
+ });
1573
+ h.append(...g);
1574
+ let _ = U({
1575
+ anchor: p,
1576
+ content: h,
1577
+ container: a,
1578
+ onClose: () => {
1579
+ p.setAttribute("aria-expanded", "false"), x(-1);
1580
+ }
1581
+ }), v = "", y = -1;
1582
+ function b() {
1583
+ return e.isEditable && e.commands.setFontSize.can("12pt");
1584
+ }
1585
+ function x(e) {
1586
+ y = e, g.forEach((t, n) => {
1587
+ t.classList.toggle("stilo-font-size__option--active", n === e);
1588
+ }), e >= 0 ? p.setAttribute("aria-activedescendant", g[e].id) : p.removeAttribute("aria-activedescendant");
1589
+ }
1590
+ function S() {
1591
+ let t = b();
1592
+ for (let e of m) t ? e.removeAttribute("aria-disabled") : e.setAttribute("aria-disabled", "true");
1593
+ p.readOnly = !t, v = t && !Ze(e) ? String(i(e, s)) : "", document.activeElement !== p && (p.value = v);
1594
+ }
1595
+ function C() {
1596
+ if (!_.isOpen && b()) {
1597
+ for (let e of g) e.setAttribute("aria-selected", String(e.dataset.size === v));
1598
+ _.open(), p.setAttribute("aria-expanded", "true");
1599
+ }
1600
+ }
1601
+ function T() {
1602
+ _.close(), p.removeAttribute("aria-invalid"), e.focus(), S();
1603
+ }
1604
+ function D(t) {
1605
+ let r = Je.exec(t.trim());
1606
+ if (!r) return null;
1607
+ let i = Number(r[1].replace(",", ".")), a = r[2]?.toLowerCase();
1608
+ return i === 0 || (!a || a === "px" || a === "pt") && (i < Ye || i > Xe) ? null : a ? `${i}${a}` : n(e, i, s);
1609
+ }
1610
+ function O(t) {
1611
+ let n = D(t);
1612
+ n && e.commands.setFontSize(n) ? T() : p.setAttribute("aria-invalid", "true");
1613
+ }
1614
+ let k = (t) => () => {
1615
+ b() && (_.close(), e.focus(), e.commands.stepFontSize(t, s));
1616
+ }, A = k(-1), j = k(1), M = () => p.select(), N = () => C(), P = () => {
1617
+ p.removeAttribute("aria-invalid"), x(-1);
1618
+ }, F = (e) => {
1619
+ switch (e.key) {
1620
+ case "ArrowDown":
1621
+ case "ArrowUp": {
1622
+ e.preventDefault(), C();
1623
+ let t = e.key === "ArrowDown" ? 1 : -1, n = y === -1 ? g.findIndex((e) => e.dataset.size === v) : y, r = n === -1 ? t > 0 ? 0 : g.length - 1 : n + t;
1624
+ x(Math.min(g.length - 1, Math.max(0, r))), g[y]?.scrollIntoView?.({ block: "nearest" });
1625
+ break;
1626
+ }
1627
+ case "Enter":
1628
+ e.preventDefault(), O(y >= 0 ? g[y].dataset.size : p.value);
1629
+ break;
1630
+ case "Escape": e.preventDefault(), T();
1631
+ }
1632
+ }, I = () => {
1633
+ _.close(), p.removeAttribute("aria-invalid"), p.value = v;
1634
+ }, L = (e) => e.preventDefault(), R = (e) => {
1635
+ let t = e.target.closest(".stilo-font-size__option");
1636
+ t?.dataset.size && O(t.dataset.size);
1637
+ };
1638
+ d.addEventListener("click", A), f.addEventListener("click", j), p.addEventListener("focus", M), p.addEventListener("click", N), p.addEventListener("input", P), p.addEventListener("keydown", F), p.addEventListener("blur", I), h.addEventListener("pointerdown", L), h.addEventListener("click", R);
1639
+ let z = !1;
1640
+ function ee() {
1641
+ z || (z = !0, d.removeEventListener("click", A), f.removeEventListener("click", j), p.removeEventListener("focus", M), p.removeEventListener("click", N), p.removeEventListener("input", P), p.removeEventListener("keydown", F), p.removeEventListener("blur", I), h.removeEventListener("pointerdown", L), h.removeEventListener("click", R), _.destroy());
1642
+ }
1643
+ return S(), {
1644
+ element: u,
1645
+ parts: m,
1646
+ update: S,
1647
+ destroy: ee
1648
+ };
1649
+ }
1650
+ //#endregion
1651
+ //#region src/ui/components/icon-menu.ts
1652
+ function et(e, t, n) {
1653
+ let { container: r, messages: i, mac: a } = n, o = i[t.labelKey] ?? t.labelKey, s = (e, t) => {
1654
+ let n = i[e] ?? e;
1655
+ return t ? `${n} (${V(t, a)})` : n;
1656
+ }, c = document.createElement("button");
1657
+ c.type = "button", c.className = "stilo-toolbar__button stilo-icon-menu__trigger", c.dataset.item = t.id, c.tabIndex = -1, c.title = o, c.setAttribute("aria-haspopup", "menu"), c.setAttribute("aria-expanded", "false");
1658
+ let u = t.options.map((e) => K(e.icon)), d = u[0];
1659
+ c.append(d, K(l));
1660
+ let f = document.createElement("div");
1661
+ f.className = "stilo-icon-menu", f.setAttribute("role", "menu"), f.setAttribute("aria-label", o), f.setAttribute("aria-orientation", "horizontal");
1662
+ let p = t.options.map((e) => {
1663
+ let t = document.createElement("button");
1664
+ t.type = "button", t.className = `stilo-toolbar__button stilo-icon-menu__option stilo-icon-menu__option--${e.id}`, t.dataset.option = e.id, t.tabIndex = -1, t.setAttribute("role", "menuitemradio"), t.setAttribute("aria-checked", "false");
1665
+ let n = s(e.labelKey, e.shortcut);
1666
+ return t.setAttribute("aria-label", i[e.labelKey] ?? e.labelKey), t.title = n, t.append(K(e.icon)), t;
1667
+ });
1668
+ f.append(...p);
1669
+ let m = U({
1670
+ anchor: c,
1671
+ content: f,
1672
+ container: r,
1673
+ onClose: (e) => {
1674
+ c.setAttribute("aria-expanded", "false"), e === "escape" && c.focus();
1675
+ }
1676
+ }), h = (n) => t.options[n].isEnabled?.(e) ?? !0;
1677
+ function g() {
1678
+ let n = t.options.findIndex((t) => t.isActive(e)), r = Math.max(n, 0);
1679
+ d.replaceWith(u[r]), d = u[r];
1680
+ let a = i[t.options[r].labelKey] ?? t.options[r].labelKey;
1681
+ c.setAttribute("aria-label", `${o}: ${a}`), p.forEach((e, t) => {
1682
+ e.setAttribute("aria-checked", String(t === n)), e.classList.toggle("stilo-toolbar__button--active", t === n), h(t) ? e.removeAttribute("aria-disabled") : e.setAttribute("aria-disabled", "true");
1683
+ }), t.options.some((e, t) => h(t)) ? c.removeAttribute("aria-disabled") : c.setAttribute("aria-disabled", "true");
1684
+ }
1685
+ function _(e) {
1686
+ p[e]?.focus({ preventScroll: !0 });
1687
+ }
1688
+ function v() {
1689
+ if (m.isOpen || c.getAttribute("aria-disabled") === "true") return;
1690
+ m.open(), c.setAttribute("aria-expanded", "true");
1691
+ let e = p.findIndex((e) => e.getAttribute("aria-checked") === "true");
1692
+ _(Math.max(e, 0));
1693
+ }
1694
+ function y(n) {
1695
+ h(n) && (m.close(), e.focus(), t.options[n].run(e));
1696
+ }
1697
+ let b = () => {
1698
+ m.isOpen ? m.close() : v();
1699
+ }, x = (e) => {
1700
+ e.key === "ArrowDown" && (e.preventDefault(), v());
1701
+ }, S = (e) => {
1702
+ let t = e.target.closest(".stilo-icon-menu__option");
1703
+ t && y(p.indexOf(t));
1704
+ }, C = (e) => {
1705
+ let t = p.indexOf(e.target);
1706
+ if (t === -1) return;
1707
+ let n = p.length - 1, r = {
1708
+ ArrowRight: t === n ? 0 : t + 1,
1709
+ ArrowLeft: t === 0 ? n : t - 1,
1710
+ Home: 0,
1711
+ End: n
1712
+ }[e.key];
1713
+ r === void 0 ? e.key === "Tab" && m.close() : (e.preventDefault(), _(r));
1714
+ };
1715
+ c.addEventListener("click", b), c.addEventListener("keydown", x), f.addEventListener("click", S), f.addEventListener("keydown", C);
1716
+ let w = !1;
1717
+ function T() {
1718
+ w || (w = !0, c.removeEventListener("click", b), c.removeEventListener("keydown", x), f.removeEventListener("click", S), f.removeEventListener("keydown", C), m.destroy());
1719
+ }
1720
+ return g(), {
1721
+ trigger: c,
1722
+ update: g,
1723
+ destroy: T
1724
+ };
1725
+ }
1726
+ //#endregion
1727
+ //#region src/ui/components/link-bubble.ts
1728
+ function tt(e, t) {
1729
+ let { container: n, messages: r, onEdit: i } = t, a = null, o = {
1730
+ contextElement: e.view.dom,
1731
+ getBoundingClientRect: () => (a ?? e.view.dom).getBoundingClientRect()
1732
+ }, s = document.createElement("div");
1733
+ s.className = "stilo-link-bubble", s.setAttribute("role", "group"), s.setAttribute("aria-label", r["toolbar.link"]);
1734
+ let c = document.createElement("a");
1735
+ c.className = "stilo-link-bubble__button", c.target = "_blank", c.rel = "noopener noreferrer", c.setAttribute("aria-label", r["link.open"]), c.append(K(f));
1736
+ let l = Y(T, r["link.edit"]), u = Y(re, r["link.remove"]);
1737
+ s.append(c, l, u);
1738
+ let d = U({
1739
+ anchor: o,
1740
+ content: s,
1741
+ container: n
1742
+ }), p = (e) => {
1743
+ e.preventDefault();
1744
+ }, m = () => {
1745
+ d.close(), i();
1746
+ }, h = () => {
1747
+ e.commands.unsetLink();
1748
+ };
1749
+ s.addEventListener("mousedown", p), l.addEventListener("click", m), u.addEventListener("click", h), e.on("transaction", _), e.on("focus", _), e.on("blur", _);
1750
+ function g() {
1751
+ let { selection: t } = e.state;
1752
+ if (!t.empty || !e.isActive("link") || !e.view.hasFocus()) return null;
1753
+ let { node: n } = e.view.domAtPos(t.from);
1754
+ return (n instanceof Element ? n : n.parentElement)?.closest("a") ?? null;
1755
+ }
1756
+ function _() {
1757
+ let t = g();
1758
+ if (t !== a && d.close(), a = t, !a) return;
1759
+ let n = String(e.getAttributes("link").href ?? "");
1760
+ c.href = n, c.title = `${r["link.open"]}: ${n}`, d.open();
1761
+ }
1762
+ function v() {
1763
+ e.off("transaction", _), e.off("focus", _), e.off("blur", _), s.removeEventListener("mousedown", p), l.removeEventListener("click", m), u.removeEventListener("click", h), d.destroy();
1764
+ }
1765
+ return {
1766
+ get isOpen() {
1767
+ return d.isOpen;
1768
+ },
1769
+ update: _,
1770
+ destroy: v
1771
+ };
1772
+ }
1773
+ function Y(e, t) {
1774
+ let n = document.createElement("button");
1775
+ return n.type = "button", n.className = "stilo-link-bubble__button", n.setAttribute("aria-label", t), n.title = t, n.append(K(e)), n;
1776
+ }
1777
+ //#endregion
1778
+ //#region src/ui/components/table-actions.ts
1779
+ var nt = {
1780
+ addRowBefore: "table.addRowBefore",
1781
+ addRowAfter: "table.addRowAfter",
1782
+ deleteRow: "table.deleteRow",
1783
+ addColumnBefore: "table.addColumnBefore",
1784
+ addColumnAfter: "table.addColumnAfter",
1785
+ deleteColumn: "table.deleteColumn",
1786
+ mergeCells: "table.mergeCells",
1787
+ splitCell: "table.splitCell",
1788
+ toggleHeaderRow: "table.headerRow",
1789
+ toggleHeaderColumn: "table.headerColumn",
1790
+ deleteTable: "table.deleteTable"
1791
+ };
1792
+ function rt(e, t) {
1793
+ let { groups: n, label: i, messages: a, close: o } = t, s = document.createElement("div");
1794
+ s.className = "stilo-table-menu__actions", s.setAttribute("role", "menu"), s.setAttribute("aria-label", i);
1795
+ let c = /* @__PURE__ */ new Map();
1796
+ n.forEach((e, t) => {
1797
+ if (t > 0) {
1798
+ let e = document.createElement("div");
1799
+ e.className = "stilo-table-menu__separator", e.setAttribute("role", "separator"), s.append(e);
1800
+ }
1801
+ for (let t of e) {
1802
+ let e = document.createElement("div");
1803
+ e.className = `stilo-dropdown__option stilo-table-menu__item--${t}`, e.tabIndex = -1;
1804
+ let n = t === "toggleHeaderRow" || t === "toggleHeaderColumn";
1805
+ e.setAttribute("role", n ? "menuitemcheckbox" : "menuitem"), e.textContent = a[nt[t]], c.set(e, t), s.append(e);
1806
+ }
1807
+ });
1808
+ let l = () => [...c.keys()].filter((e) => e.getAttribute("aria-disabled") !== "true");
1809
+ function u() {
1810
+ let t = r(e);
1811
+ for (let [n, r] of c) e.commands[r].can() ? n.removeAttribute("aria-disabled") : n.setAttribute("aria-disabled", "true"), r === "toggleHeaderRow" && n.setAttribute("aria-checked", String(!!t?.row)), r === "toggleHeaderColumn" && n.setAttribute("aria-checked", String(!!t?.column));
1812
+ }
1813
+ function d(t) {
1814
+ let n = c.get(t);
1815
+ n && t.getAttribute("aria-disabled") !== "true" && (o(), e.focus(), e.commands[n]());
1816
+ }
1817
+ let f = (e) => {
1818
+ let t = e.target.closest("[role^=\"menuitem\"]");
1819
+ t && d(t);
1820
+ }, p = (e) => {
1821
+ let t = l(), n = t.indexOf(e.target), r;
1822
+ switch (e.key) {
1823
+ case "ArrowDown":
1824
+ r = t[(n + 1) % t.length];
1825
+ break;
1826
+ case "ArrowUp":
1827
+ r = t[(n - 1 + t.length) % t.length];
1828
+ break;
1829
+ case "Home":
1830
+ r = t[0];
1831
+ break;
1832
+ case "End":
1833
+ r = t.at(-1);
1834
+ break;
1835
+ case "Enter":
1836
+ case " ":
1837
+ e.preventDefault(), d(e.target);
1838
+ return;
1839
+ case "Tab":
1840
+ o();
1841
+ return;
1842
+ default: return;
1843
+ }
1844
+ e.preventDefault(), r?.focus();
1845
+ };
1846
+ return s.addEventListener("click", f), s.addEventListener("keydown", p), {
1847
+ element: s,
1848
+ refresh: u,
1849
+ focusFirst: () => l()[0]?.focus({ preventScroll: !0 }),
1850
+ destroy() {
1851
+ s.removeEventListener("click", f), s.removeEventListener("keydown", p);
1852
+ }
1853
+ };
1854
+ }
1855
+ //#endregion
1856
+ //#region src/ui/components/table-handles.ts
1857
+ var X = 4, Z = 32, it = [
1858
+ {
1859
+ kind: "row",
1860
+ labelKey: "table.row",
1861
+ icon: g,
1862
+ placement: "left",
1863
+ groups: [["addRowBefore", "addRowAfter"], ["deleteRow"]]
1864
+ },
1865
+ {
1866
+ kind: "column",
1867
+ labelKey: "table.column",
1868
+ icon: h,
1869
+ placement: "top",
1870
+ groups: [["addColumnBefore", "addColumnAfter"], ["deleteColumn"]]
1871
+ },
1872
+ {
1873
+ kind: "table",
1874
+ labelKey: "toolbar.table",
1875
+ icon: m,
1876
+ placement: "top-end",
1877
+ groups: [["mergeCells", "splitCell"], ["deleteTable"]]
1878
+ }
1879
+ ];
1880
+ function Q(e, t, n, r) {
1881
+ return {
1882
+ x: e,
1883
+ y: t,
1884
+ width: n,
1885
+ height: r,
1886
+ left: e,
1887
+ top: t,
1888
+ right: e + n,
1889
+ bottom: t + r
1890
+ };
1891
+ }
1892
+ function at(e, t) {
1893
+ let { container: n, messages: r } = t, { view: i } = e, a = null, o = null, s = (e) => Math.max(e.getBoundingClientRect().left, e.parentElement?.getBoundingClientRect().left ?? -Infinity);
1894
+ function c(e) {
1895
+ let t = a?.closest("table");
1896
+ if (!a || !t) return Q(0, 0, 0, 0);
1897
+ let n = a.getBoundingClientRect(), r = t.getBoundingClientRect().top, i = s(t);
1898
+ return e === "row" ? Q(i, n.top, Math.max(n.right - i, 0), n.height) : e === "column" ? Q(n.left, r, n.width, n.bottom - r) : Q(i - X, r, 0, 0);
1899
+ }
1900
+ let l = it.map(({ kind: t, labelKey: i, icon: o, placement: s, groups: l }) => {
1901
+ let u = r[i], d = document.createElement("button");
1902
+ d.type = "button", d.className = `stilo-table-handle stilo-table-handle--${t}`, d.tabIndex = -1, d.title = u, d.setAttribute("aria-label", u), d.setAttribute("aria-haspopup", "menu"), d.setAttribute("aria-expanded", "false"), d.hidden = !0, d.append(K(o)), n.append(d);
1903
+ let f = rt(e, {
1904
+ groups: l,
1905
+ label: u,
1906
+ messages: r,
1907
+ close: () => p.close()
1908
+ });
1909
+ f.element.classList.add("stilo-table-handle-menu");
1910
+ let p = U({
1911
+ anchor: d,
1912
+ content: f.element,
1913
+ container: n,
1914
+ onClose: (t) => {
1915
+ d.setAttribute("aria-expanded", "false"), t === "escape" && e.focus(), m();
1916
+ }
1917
+ });
1918
+ return {
1919
+ kind: t,
1920
+ button: d,
1921
+ anchor: {
1922
+ getBoundingClientRect: () => c(t),
1923
+ get contextElement() {
1924
+ return a ?? void 0;
1925
+ }
1926
+ },
1927
+ placement: s,
1928
+ actions: f,
1929
+ popover: p,
1930
+ generation: 0
1931
+ };
1932
+ }), u = () => l.some((e) => e.popover.isOpen);
1933
+ function d(e) {
1934
+ let t = ++e.generation;
1935
+ Promise.resolve(ce(e.anchor, e.button, {
1936
+ strategy: "absolute",
1937
+ placement: e.placement,
1938
+ middleware: e.kind === "table" ? [B(X)] : [B(X), ue()]
1939
+ }).then(({ x: n, y: r, middlewareData: i }) => {
1940
+ e.generation === t && (e.button.style.left = `${n}px`, e.button.style.top = `${r}px`, e.button.style.visibility = i.hide?.referenceHidden ? "hidden" : "");
1941
+ }));
1942
+ }
1943
+ function f() {
1944
+ let { node: t, offset: n } = i.domAtPos(e.state.selection.head), r = t.childNodes[n], a = (r instanceof Element ? r : t instanceof Element ? t : t.parentElement)?.closest("td, th");
1945
+ return a && i.dom.contains(a) ? a : null;
1946
+ }
1947
+ function p(e) {
1948
+ if (e !== a) {
1949
+ a = e;
1950
+ for (let e of l) e.stopAutoUpdate?.(), e.stopAutoUpdate = void 0, e.generation++, e.button.hidden = !a, a && (e.stopAutoUpdate = se(e.anchor, e.button, () => d(e)));
1951
+ }
1952
+ }
1953
+ function m() {
1954
+ if (u()) return;
1955
+ o && !o.isConnected && (o = null);
1956
+ let t = i.hasFocus() ? f() : null;
1957
+ p(e.isEditable ? o ?? t : null);
1958
+ }
1959
+ function h(e, t) {
1960
+ let n = e.closest("table")?.getBoundingClientRect();
1961
+ if (!n) return !1;
1962
+ let { clientX: r, clientY: i } = t;
1963
+ return r >= n.left - Z && r <= n.right + Z && i >= n.top - Z && i <= n.bottom + Z;
1964
+ }
1965
+ function g(t) {
1966
+ if (!a) return;
1967
+ let n = a.closest("table"), r = i.posAtDOM(a, 0);
1968
+ o = a, t.kind === "row" ? e.commands.selectRow(r) : t.kind === "column" ? e.commands.selectColumn(r) : f()?.closest("table") !== n && e.commands.selectTable(r), t.popover.open(), t.button.setAttribute("aria-expanded", "true"), t.actions.refresh(), t.actions.focusFirst();
1969
+ }
1970
+ let _ = (e) => {
1971
+ let t = e.target;
1972
+ if (u() || t.closest(".stilo-table-handle")) return;
1973
+ let n = t.closest("td, th");
1974
+ n && i.dom.contains(n) ? o = n : o && !h(o, e) && (o = null), m();
1975
+ }, v = () => {
1976
+ o = null, m();
1977
+ }, y = (e) => {
1978
+ e.target.closest(".stilo-table-handle") && e.preventDefault();
1979
+ }, b = (t) => {
1980
+ let n = t.target.closest(".stilo-table-handle"), r = l.find((e) => e.button === n);
1981
+ r && (r.popover.isOpen ? (r.popover.close(), e.focus()) : g(r));
1982
+ };
1983
+ n.addEventListener("mousemove", _), n.addEventListener("mouseleave", v), n.addEventListener("mousedown", y), n.addEventListener("click", b), e.on("transaction", m), e.on("focus", m), e.on("blur", m);
1984
+ function x() {
1985
+ n.removeEventListener("mousemove", _), n.removeEventListener("mouseleave", v), n.removeEventListener("mousedown", y), n.removeEventListener("click", b), e.off("transaction", m), e.off("focus", m), e.off("blur", m);
1986
+ for (let e of l) e.popover.destroy();
1987
+ p(null);
1988
+ for (let e of l) e.actions.destroy(), e.button.remove();
1989
+ }
1990
+ return {
1991
+ update: m,
1992
+ destroy: x
1993
+ };
1994
+ }
1995
+ //#endregion
1996
+ //#region src/ui/components/table-menu.ts
1997
+ var ot = 8, $ = 10, st = [
1998
+ [
1999
+ "addRowBefore",
2000
+ "addRowAfter",
2001
+ "deleteRow"
2002
+ ],
2003
+ [
2004
+ "addColumnBefore",
2005
+ "addColumnAfter",
2006
+ "deleteColumn"
2007
+ ],
2008
+ ["mergeCells", "splitCell"],
2009
+ ["toggleHeaderRow", "toggleHeaderColumn"],
2010
+ ["deleteTable"]
2011
+ ];
2012
+ function ct(e, t) {
2013
+ let { anchor: n, container: r, messages: i } = t, a = document.createElement("div");
2014
+ a.className = "stilo-table-menu", a.setAttribute("role", "dialog");
2015
+ let o = document.createElement("div");
2016
+ o.className = "stilo-table-menu__picker";
2017
+ let s = document.createElement("div");
2018
+ s.className = "stilo-table-menu__grid", s.setAttribute("role", "group"), s.setAttribute("aria-label", i["table.insert"]);
2019
+ let c = [];
2020
+ for (let e = 1; e <= ot; e++) for (let t = 1; t <= $; t++) {
2021
+ let n = document.createElement("button");
2022
+ n.type = "button", n.className = "stilo-table-menu__cell", n.tabIndex = -1, n.dataset.rows = String(e), n.dataset.columns = String(t), n.setAttribute("aria-label", h(e, t)), c.push(n);
2023
+ }
2024
+ s.append(...c);
2025
+ let l = document.createElement("div");
2026
+ l.className = "stilo-table-menu__size", l.setAttribute("aria-hidden", "true");
2027
+ let u = document.createElement("label");
2028
+ u.className = "stilo-table-menu__header";
2029
+ let d = document.createElement("input");
2030
+ d.type = "checkbox", d.checked = !0, u.append(d, ` ${i["table.headerRow"]}`), o.append(s, l, u);
2031
+ let f = rt(e, {
2032
+ groups: st,
2033
+ label: i["toolbar.table"],
2034
+ messages: i,
2035
+ close: () => m.close()
2036
+ }), p = f.element;
2037
+ a.append(o, p), n.setAttribute("aria-haspopup", "dialog"), n.setAttribute("aria-expanded", "false");
2038
+ let m = U({
2039
+ anchor: n,
2040
+ content: a,
2041
+ container: r,
2042
+ onClose: (t) => {
2043
+ n.setAttribute("aria-expanded", "false"), t === "escape" && e.focus();
2044
+ }
2045
+ });
2046
+ function h(e, t) {
2047
+ return i["table.size"].replace("{rows}", String(e)).replace("{columns}", String(t));
2048
+ }
2049
+ function g(e, t, n) {
2050
+ for (let n of c) {
2051
+ let r = Number(n.dataset.rows) <= e && Number(n.dataset.columns) <= t;
2052
+ n.classList.toggle("stilo-table-menu__cell--active", r), n.tabIndex = -1;
2053
+ }
2054
+ let r = c[(e - 1) * $ + t - 1];
2055
+ r.tabIndex = 0, n && r.focus({ preventScroll: !0 }), l.textContent = h(e, t);
2056
+ }
2057
+ function _(t) {
2058
+ let n = Number(t.dataset.rows), r = Number(t.dataset.columns);
2059
+ m.close(), e.focus(), e.commands.insertTable({
2060
+ rows: n,
2061
+ cols: r,
2062
+ withHeaderRow: d.checked
2063
+ });
2064
+ }
2065
+ let v = (e) => e.closest(".stilo-table-menu__cell"), y = (e) => {
2066
+ let t = v(e.target);
2067
+ t && g(Number(t.dataset.rows), Number(t.dataset.columns), !1);
2068
+ }, b = (e) => {
2069
+ let t = v(e.target);
2070
+ t && _(t);
2071
+ }, x = (e) => {
2072
+ let t = v(e.target);
2073
+ if (!t) return;
2074
+ let n = Number(t.dataset.rows), r = Number(t.dataset.columns);
2075
+ if (e.key === "ArrowDown") n = Math.min(n + 1, ot);
2076
+ else if (e.key === "ArrowUp") n = Math.max(n - 1, 1);
2077
+ else if (e.key === "ArrowRight") r = Math.min(r + 1, $);
2078
+ else if (e.key === "ArrowLeft") r = Math.max(r - 1, 1);
2079
+ else return;
2080
+ e.preventDefault(), g(n, r, !0);
2081
+ };
2082
+ s.addEventListener("mouseover", y), s.addEventListener("click", b), s.addEventListener("keydown", x);
2083
+ function S() {
2084
+ if (m.isOpen) return;
2085
+ let t = e.isActive("table");
2086
+ o.hidden = t, p.hidden = !t, a.setAttribute("aria-label", t ? i["toolbar.table"] : i["table.insert"]), m.open(), n.setAttribute("aria-expanded", "true"), t ? (f.refresh(), f.focusFirst()) : g(1, 1, !0);
2087
+ }
2088
+ function C() {
2089
+ m.isOpen && (m.close(), e.focus());
2090
+ }
2091
+ function w() {
2092
+ s.removeEventListener("mouseover", y), s.removeEventListener("click", b), s.removeEventListener("keydown", x), f.destroy(), m.destroy(), n.removeAttribute("aria-haspopup"), n.removeAttribute("aria-expanded");
2093
+ }
2094
+ return {
2095
+ get isOpen() {
2096
+ return m.isOpen;
2097
+ },
2098
+ open: S,
2099
+ close: C,
2100
+ toggle: () => m.isOpen ? C() : S(),
2101
+ destroy: w
2102
+ };
2103
+ }
2104
+ //#endregion
2105
+ //#region src/ui/toolbar/toolbar.ts
2106
+ function lt(e, t) {
2107
+ if (typeof e == "string") {
2108
+ let n = Ce[e];
2109
+ if (!n) throw new a(`Toolbar: unknown item "${e}"`);
2110
+ return n.isAvailable && !n.isAvailable(t) ? void 0 : n;
2111
+ }
2112
+ if (!e.isAvailable || e.isAvailable(t)) return e;
2113
+ }
2114
+ function ut(e, t) {
2115
+ let { selectionStart: n, selectionEnd: r, value: i } = t;
2116
+ switch (e.key) {
2117
+ case "Home":
2118
+ case "End": return !0;
2119
+ case "ArrowLeft": return n !== 0 || r !== 0;
2120
+ case "ArrowRight": return n !== i.length || r !== i.length;
2121
+ default: return !1;
2122
+ }
2123
+ }
2124
+ function dt(e, t) {
2125
+ let { container: n, items: r = Se, messages: i = H, sticky: a = !0 } = t, o = fe(), s = [];
2126
+ for (let t of r) {
2127
+ let n = [];
2128
+ for (let r of t) {
2129
+ let t = lt(r, e);
2130
+ t && n.push(t);
2131
+ }
2132
+ n.length > 0 && s.push(n);
2133
+ }
2134
+ let c = document.createElement("div");
2135
+ c.className = "stilo-toolbar", c.setAttribute("role", "toolbar"), c.setAttribute("aria-label", i?.["toolbar.label"] ?? "Formatting"), c.setAttribute("aria-orientation", "horizontal");
2136
+ let l = [], u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), f = [], p = [], m = [];
2137
+ for (let t of s) {
2138
+ let n = document.createElement("div");
2139
+ n.className = "stilo-toolbar__group", n.setAttribute("role", "group");
2140
+ for (let r of t) if (r.kind === "dropdown") {
2141
+ let t = r, a = t.options.map((e) => {
2142
+ let t = i[e.labelKey] ?? e.labelKey, n = e.shortcut ? V(e.shortcut, o) : void 0;
2143
+ return {
2144
+ id: e.id,
2145
+ label: t,
2146
+ shortcut: n,
2147
+ fontFamily: e.fontFamily,
2148
+ action: !e.isActive
2149
+ };
2150
+ }), s = We({
2151
+ label: i[t.labelKey] ?? t.labelKey,
2152
+ options: a,
2153
+ icon: t.icon,
2154
+ container: c,
2155
+ onSelect: (n) => {
2156
+ let r = t.options.find((e) => e.id === n);
2157
+ r && (r.run(e), e.focus());
2158
+ }
2159
+ });
2160
+ s.trigger.setAttribute("data-item", t.id), n.appendChild(s.trigger), l.push(s.trigger), u.set(s.trigger, t), d.set(t.id, s);
2161
+ } else if (r.kind === "iconMenu") {
2162
+ let t = et(e, r, {
2163
+ container: c,
2164
+ messages: i,
2165
+ mac: o
2166
+ });
2167
+ n.appendChild(t.trigger), l.push(t.trigger), u.set(t.trigger, r), m.push(t);
2168
+ } else if (r.kind === "fontSize") {
2169
+ let t = $e(e, r, {
2170
+ container: c,
2171
+ messages: i
2172
+ });
2173
+ n.appendChild(t.element);
2174
+ for (let e of t.parts) l.push(e), u.set(e, r);
2175
+ p.push(t);
2176
+ } else if (r.kind === "color") {
2177
+ let t = Ue(e, r, {
2178
+ container: c,
2179
+ messages: i
2180
+ });
2181
+ n.appendChild(t.element);
2182
+ for (let e of [t.main, t.arrow]) l.push(e), u.set(e, r);
2183
+ f.push(t);
2184
+ } else {
2185
+ let e = r, t = i[e.labelKey] ?? e.labelKey, a = e.shortcut === void 0 ? t : `${t} (${V(e.shortcut, o)})`, s = document.createElement("button");
2186
+ s.type = "button", s.className = "stilo-toolbar__button", s.setAttribute("data-item", e.id), s.setAttribute("aria-label", t), s.setAttribute("title", a), s.setAttribute("tabindex", "-1"), e.isActive && s.setAttribute("aria-pressed", "false");
2187
+ let c = K(e.icon);
2188
+ s.appendChild(c), n.appendChild(s), l.push(s), u.set(s, e);
2189
+ }
2190
+ c.appendChild(n);
2191
+ }
2192
+ let h = e.view.dom.parentElement ?? c, g = "setLink" in e.commands ? be(e, {
2193
+ container: h,
2194
+ messages: i
2195
+ }) : null, _ = g ? tt(e, {
2196
+ container: h,
2197
+ messages: i,
2198
+ onEdit: () => g.open()
2199
+ }) : null, v = "selectRow" in e.commands ? at(e, {
2200
+ container: h,
2201
+ messages: i
2202
+ }) : null, y = c.querySelector("[data-item=\"characters\"]"), b = y ? ze(e, {
2203
+ anchor: y,
2204
+ container: c,
2205
+ messages: i
2206
+ }) : null, x = c.querySelector("[data-item=\"table\"]"), S = x ? ct(e, {
2207
+ anchor: x,
2208
+ container: c,
2209
+ messages: i
2210
+ }) : null, C = {
2211
+ openLinkPopover: () => g?.open(),
2212
+ toggleCharacterPicker: () => b?.toggle(),
2213
+ toggleFindBar: () => T?.toggle(),
2214
+ toggleTableMenu: () => S?.toggle()
2215
+ };
2216
+ n.appendChild(c);
2217
+ let w = c.querySelector("[data-item=\"find\"]"), T = "setSearch" in e.commands ? qe(e, {
2218
+ container: n,
2219
+ messages: i,
2220
+ button: w
2221
+ }) : null, E = null;
2222
+ if (a) {
2223
+ n.classList.add("stilo-toolbar-host");
2224
+ let t = () => {
2225
+ let t = n.offsetHeight + 5;
2226
+ e.view.setProps({ scrollMargin: {
2227
+ top: t,
2228
+ right: 5,
2229
+ bottom: 5,
2230
+ left: 5
2231
+ } });
2232
+ };
2233
+ t(), typeof ResizeObserver < "u" && (E = new ResizeObserver(t), E.observe(n));
2234
+ }
2235
+ let D = 0, O = !1, k = 0;
2236
+ function A(e) {
2237
+ l.forEach((t, n) => {
2238
+ t.setAttribute("tabindex", n === e ? "0" : "-1");
2239
+ }), k = e;
2240
+ }
2241
+ A(0);
2242
+ function j() {
2243
+ for (let e of f) e.update();
2244
+ for (let e of p) e.update();
2245
+ for (let e of m) e.update();
2246
+ for (let t of l) {
2247
+ let n = u.get(t);
2248
+ if (n && n.kind !== "color" && n.kind !== "fontSize" && n.kind !== "iconMenu") {
2249
+ if (n.kind === "dropdown") {
2250
+ let t = n, r = null, i = /* @__PURE__ */ new Set();
2251
+ for (let n of t.options) {
2252
+ let t = n.isActive?.(e) ?? !1;
2253
+ n.isEnabled !== void 0 && !n.isEnabled(e) && i.add(n.id), t && r === null && (r = n.id);
2254
+ }
2255
+ let a = d.get(t.id), o = r === null ? t.getValueLabel?.(e) ?? null : null;
2256
+ a?.update({
2257
+ activeId: r,
2258
+ disabledIds: i,
2259
+ valueLabel: o
2260
+ });
2261
+ } else {
2262
+ let r = t, i = n;
2263
+ if (i.isActive) {
2264
+ let t = i.isActive(e);
2265
+ r.setAttribute("aria-pressed", t ? "true" : "false"), t ? r.classList.add("stilo-toolbar__button--active") : r.classList.remove("stilo-toolbar__button--active");
2266
+ } else r.removeAttribute("aria-pressed"), r.classList.remove("stilo-toolbar__button--active");
2267
+ i.isEnabled ? i.isEnabled(e) ? r.removeAttribute("aria-disabled") : r.setAttribute("aria-disabled", "true") : r.removeAttribute("aria-disabled");
2268
+ }
2269
+ }
2270
+ }
2271
+ }
2272
+ j();
2273
+ let M = () => {
2274
+ O || (D ||= requestAnimationFrame(() => {
2275
+ O || (D = 0, j());
2276
+ }));
2277
+ };
2278
+ e.on("transaction", M);
2279
+ let N = (e) => {
2280
+ O || e.target.closest(".stilo-char-picker, .stilo-color-picker, .stilo-font-size__input") || e.preventDefault();
2281
+ };
2282
+ c.addEventListener("mousedown", N);
2283
+ let P = (t) => {
2284
+ if (O) return;
2285
+ let n = t.target.closest("[data-item]");
2286
+ if (!n) return;
2287
+ let r = u.get(n);
2288
+ r && r.kind === "button" && (!r.isEnabled || r.isEnabled(e)) && (e.focus(), r.run(e, C));
2289
+ };
2290
+ c.addEventListener("click", P);
2291
+ let F = (t) => {
2292
+ if (O) return;
2293
+ let n = t.target.closest("[data-item]");
2294
+ if (!n) return;
2295
+ let r = l.indexOf(n);
2296
+ if (!(r === -1 || n instanceof HTMLInputElement && ut(t, n))) switch (t.key) {
2297
+ case "ArrowRight": {
2298
+ t.preventDefault();
2299
+ let e = (r + 1) % l.length;
2300
+ A(e), l[e].focus();
2301
+ break;
2302
+ }
2303
+ case "ArrowLeft": {
2304
+ t.preventDefault();
2305
+ let e = (r - 1 + l.length) % l.length;
2306
+ A(e), l[e].focus();
2307
+ break;
2308
+ }
2309
+ case "Home":
2310
+ t.preventDefault(), A(0), l[0].focus();
2311
+ break;
2312
+ case "End": {
2313
+ t.preventDefault();
2314
+ let e = l.length - 1;
2315
+ A(e), l[e].focus();
2316
+ break;
2317
+ }
2318
+ case "Escape": t.preventDefault(), e.focus();
2319
+ }
2320
+ };
2321
+ c.addEventListener("keydown", F);
2322
+ let I = (t) => {
2323
+ if (O) return;
2324
+ let n = o ? t.metaKey : t.ctrlKey;
2325
+ g && n && !t.altKey && !t.shiftKey && t.key.toLowerCase() === "k" ? (t.preventDefault(), g.open()) : T && n && !t.altKey && !t.shiftKey && t.key.toLowerCase() === "f" ? (t.preventDefault(), T.open()) : t.key === "F10" && t.altKey && (t.preventDefault(), e.focus(), k >= 0 && k < l.length && l[k].focus());
2326
+ };
2327
+ e.view.dom.addEventListener("keydown", I);
2328
+ let L = () => {
2329
+ R();
2330
+ };
2331
+ e.on("destroy", L);
2332
+ function R() {
2333
+ if (!O) {
2334
+ O = !0, D &&= (cancelAnimationFrame(D), 0), e.off("transaction", M), e.off("destroy", L), c.removeEventListener("mousedown", N), c.removeEventListener("click", P), c.removeEventListener("keydown", F), e.view.dom.removeEventListener("keydown", I);
2335
+ for (let e of d.values()) e.destroy();
2336
+ for (let e of f) e.destroy();
2337
+ for (let e of p) e.destroy();
2338
+ for (let e of m) e.destroy();
2339
+ g?.destroy(), _?.destroy(), v?.destroy(), b?.destroy(), S?.destroy(), T?.destroy(), n.contains(c) && n.removeChild(c), a && (E?.disconnect(), n.classList.remove("stilo-toolbar-host"), e.view.setProps({ scrollMargin: void 0 }));
2340
+ }
2341
+ }
2342
+ return {
2343
+ get element() {
2344
+ return c;
2345
+ },
2346
+ update: j,
2347
+ destroy: R
2348
+ };
2349
+ }
2350
+ //#endregion
2351
+ export { V as _, je as a, Fe as c, G as d, ge as f, H as g, me as h, Ae as i, Ne as l, he as m, Ce as n, Ie as o, _e as p, Se as r, Ee as s, dt as t, Te as u };