autumnnote 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4829 @@
1
+ //#region src/js/core/func.js
2
+ function e(e, t, n) {
3
+ return Math.min(Math.max(e, t), n);
4
+ }
5
+ function t(e, t) {
6
+ let n;
7
+ return function(...r) {
8
+ clearTimeout(n), n = setTimeout(() => e.apply(this, r), t);
9
+ };
10
+ }
11
+ function n(e, t) {
12
+ let n = -Infinity, r = null;
13
+ return function(...i) {
14
+ let a = performance.now(), o = a - n;
15
+ if (o >= t) return n = a, clearTimeout(r), r = null, e.apply(this, i);
16
+ clearTimeout(r), r = setTimeout(() => {
17
+ n = performance.now(), r = null, e.apply(this, i);
18
+ }, t - o);
19
+ };
20
+ }
21
+ function r(...e) {
22
+ return (t) => e.reduceRight((e, t) => t(e), t);
23
+ }
24
+ function i(e) {
25
+ return e;
26
+ }
27
+ function a(e) {
28
+ return e == null;
29
+ }
30
+ function o(e) {
31
+ return typeof e == "string";
32
+ }
33
+ function s(e) {
34
+ return typeof e == "function";
35
+ }
36
+ function c(e, t) {
37
+ let n = {};
38
+ for (let t of Object.keys(e)) n[t] = Array.isArray(e[t]) ? [...e[t]] : e[t];
39
+ if (l(e) && l(t)) for (let r of Object.keys(t)) l(t[r]) ? n[r] = c(l(e[r]) ? e[r] : {}, t[r]) : Array.isArray(t[r]) ? n[r] = [...t[r]] : n[r] = t[r];
40
+ return n;
41
+ }
42
+ function l(e) {
43
+ return typeof e == "object" && !!e && !Array.isArray(e);
44
+ }
45
+ function u(e) {
46
+ return e ? {
47
+ top: e.top,
48
+ left: e.left,
49
+ width: e.width,
50
+ height: e.height,
51
+ bottom: e.bottom,
52
+ right: e.right
53
+ } : null;
54
+ }
55
+ //#endregion
56
+ //#region src/js/core/dom.js
57
+ var d = 1, f = 3, p = (e) => e?.nodeType === 1, m = (e) => e?.nodeType === 3, h = (e) => p(e) && /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/i.test(e.nodeName), g = (e) => p(e) && /^(p|div|li|h[1-6]|blockquote|td|th|pre)$/i.test(e.nodeName), ee = (e) => p(e) && /^(li)$/i.test(e.nodeName), te = (e) => p(e) && /^(ul|ol)$/i.test(e.nodeName), ne = (e) => p(e) && e.nodeName.toUpperCase() === "TABLE", _ = (e) => p(e) && /^(a|abbr|acronym|b|bdo|big|br|button|cite|code|dfn|em|i|img|input|kbd|label|map|object|output|q|s|samp|select|small|span|strong|sub|sup|textarea|time|tt|u|var)$/i.test(e.nodeName), v = (e) => p(e) && e.isContentEditable, re = (e) => p(e) && e.nodeName.toUpperCase() === "A", ie = (e) => p(e) && e.nodeName.toUpperCase() === "IMG";
58
+ function y(e, t, n) {
59
+ let r = e;
60
+ for (; r && r !== n;) {
61
+ if (t(r)) return r;
62
+ r = r.parentNode;
63
+ }
64
+ return null;
65
+ }
66
+ function b(e, t) {
67
+ return y(e, g, t);
68
+ }
69
+ function ae(e, t) {
70
+ let n = [], r = e.parentNode;
71
+ for (; r && r !== t;) n.push(r), r = r.parentNode;
72
+ return n;
73
+ }
74
+ function oe(e) {
75
+ return Array.from(e.childNodes);
76
+ }
77
+ function se(e) {
78
+ let t = e.previousSibling;
79
+ for (; t && !p(t);) t = t.previousSibling;
80
+ return t;
81
+ }
82
+ function ce(e) {
83
+ let t = e.nextSibling;
84
+ for (; t && !p(t);) t = t.nextSibling;
85
+ return t;
86
+ }
87
+ function x(e, t = {}, n = []) {
88
+ let r = document.createElement(e);
89
+ for (let [e, n] of Object.entries(t)) r.setAttribute(e, n);
90
+ for (let e of n) typeof e == "string" ? r.appendChild(document.createTextNode(e)) : r.appendChild(e);
91
+ return r;
92
+ }
93
+ function S(e) {
94
+ e?.parentNode && e.remove();
95
+ }
96
+ function le(e) {
97
+ let t = e.parentNode;
98
+ if (t) {
99
+ for (; e.firstChild;) t.insertBefore(e.firstChild, e);
100
+ e.remove();
101
+ }
102
+ }
103
+ function ue(e, t) {
104
+ return e.parentNode.insertBefore(t, e), t.appendChild(e), t;
105
+ }
106
+ function de(e, t) {
107
+ t.nextSibling ? t.parentNode.insertBefore(e, t.nextSibling) : t.parentNode.appendChild(e);
108
+ }
109
+ function fe(e) {
110
+ return m(e) ? e.nodeValue : e.textContent || "";
111
+ }
112
+ function pe(e) {
113
+ return m(e) ? !e.nodeValue : h(e) ? !1 : e.childNodes.length === 1 && e.firstChild?.nodeName === "BR" || !e.textContent.trim() && !e.querySelector("img, video, hr, table");
114
+ }
115
+ function me(e) {
116
+ return e.outerHTML;
117
+ }
118
+ function he(e) {
119
+ let t = document.createRange();
120
+ t.selectNodeContents(e), t.collapse(!1);
121
+ let n = globalThis.getSelection();
122
+ n && (n.removeAllRanges(), n.addRange(t));
123
+ }
124
+ function ge(e) {
125
+ return !!y(e, v);
126
+ }
127
+ function C(e, t, n, r) {
128
+ return e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r);
129
+ }
130
+ function _e(e, t) {
131
+ let n = () => Array.from(e.querySelectorAll("a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])")).filter((e) => !e.closest("[style*=\"display: none\"]") && !e.closest("[style*=\"display:none\"]")), r = (e) => {
132
+ if (e.key === "Escape") {
133
+ e.stopPropagation(), t?.();
134
+ return;
135
+ }
136
+ if (e.key !== "Tab") return;
137
+ let r = n();
138
+ if (!r.length) return;
139
+ let i = r[0], a = r.at(-1);
140
+ e.shiftKey ? document.activeElement === i && (e.preventDefault(), a.focus()) : document.activeElement === a && (e.preventDefault(), i.focus());
141
+ };
142
+ return document.addEventListener("keydown", r), () => document.removeEventListener("keydown", r);
143
+ }
144
+ function ve(e, t) {
145
+ e.style.cursor = "grab";
146
+ let n = (n) => {
147
+ if (n.button !== 0 || n.target.closest("button, input, select, textarea, a")) return;
148
+ if (n.preventDefault(), !t.dataset.anDragPinned) {
149
+ let e = t.getBoundingClientRect();
150
+ t.style.position = "fixed", t.style.margin = "0", t.style.left = `${e.left}px`, t.style.top = `${e.top}px`, t.dataset.anDragPinned = "1";
151
+ }
152
+ let r = n.clientX - Number.parseFloat(t.style.left), i = n.clientY - Number.parseFloat(t.style.top);
153
+ e.style.cursor = "grabbing";
154
+ let a = (e) => {
155
+ let n = t.offsetWidth, a = t.offsetHeight;
156
+ t.style.left = `${Math.max(0, Math.min(e.clientX - r, globalThis.innerWidth - n))}px`, t.style.top = `${Math.max(0, Math.min(e.clientY - i, globalThis.innerHeight - a))}px`;
157
+ }, o = () => {
158
+ e.style.cursor = "grab", document.removeEventListener("mousemove", a), document.removeEventListener("mouseup", o);
159
+ };
160
+ document.addEventListener("mousemove", a), document.addEventListener("mouseup", o);
161
+ };
162
+ return e.addEventListener("mousedown", n), () => e.removeEventListener("mousedown", n);
163
+ }
164
+ //#endregion
165
+ //#region src/js/core/range.js
166
+ var ye = class {
167
+ constructor(e, t, n, r) {
168
+ this.sc = e, this.so = t, this.ec = n, this.eo = r;
169
+ }
170
+ isCollapsed() {
171
+ return this.sc === this.ec && this.so === this.eo;
172
+ }
173
+ toNativeRange() {
174
+ let e = document.createRange();
175
+ try {
176
+ e.setStart(this.sc, this.so), e.setEnd(this.ec, this.eo);
177
+ } catch {}
178
+ return e;
179
+ }
180
+ select() {
181
+ let e = globalThis.getSelection();
182
+ e && (e.removeAllRanges(), e.addRange(this.toNativeRange()));
183
+ }
184
+ commonAncestor() {
185
+ let e = this.toNativeRange().commonAncestorContainer;
186
+ return p(e) ? e : e.parentElement;
187
+ }
188
+ blockNode(e) {
189
+ return y(this.sc, (t) => p(t) && t !== e, e);
190
+ }
191
+ toString() {
192
+ return this.toNativeRange().toString();
193
+ }
194
+ getClientRects() {
195
+ let e = this.toNativeRange().getClientRects();
196
+ return e.length > 0 ? e[e.length - 1] : null;
197
+ }
198
+ insertNode(e) {
199
+ this.toNativeRange().insertNode(e);
200
+ }
201
+ };
202
+ function be(e) {
203
+ return new ye(e.startContainer, e.startOffset, e.endContainer, e.endOffset);
204
+ }
205
+ function xe(e) {
206
+ let t = globalThis.getSelection();
207
+ if (!t || t.rangeCount === 0) return null;
208
+ let n = t.getRangeAt(0);
209
+ return e && !e.contains(n.commonAncestorContainer) ? null : be(n);
210
+ }
211
+ function Se(e) {
212
+ return new ye(e, 0, e, e.childNodes.length);
213
+ }
214
+ function Ce(e, t = 0) {
215
+ return new ye(e, t, e, t);
216
+ }
217
+ function we(e) {
218
+ let t = globalThis.getSelection();
219
+ return !t || t.rangeCount === 0 ? !1 : e.contains(t.getRangeAt(0).commonAncestorContainer);
220
+ }
221
+ function Te(e) {
222
+ let t = globalThis.getSelection();
223
+ if (!t || t.rangeCount === 0) {
224
+ e(null);
225
+ return;
226
+ }
227
+ let n = t.getRangeAt(0).cloneRange();
228
+ e(be(n)), t.removeAllRanges(), t.addRange(n);
229
+ }
230
+ function Ee(e, t) {
231
+ return [e, e.splitText(t)];
232
+ }
233
+ //#endregion
234
+ //#region src/js/editing/insert.js
235
+ function De(e) {
236
+ let t = e && e.nodeType === 1 ? e : e?.parentElement;
237
+ for (; t;) {
238
+ let e = t.getAttribute?.("contenteditable") ?? t.contentEditable;
239
+ if (e === "false") return null;
240
+ if (e != null && e !== "inherit") return t;
241
+ t = t.parentElement;
242
+ }
243
+ return null;
244
+ }
245
+ function Oe(e) {
246
+ let t = globalThis.getSelection?.();
247
+ if (!t || t.rangeCount === 0) return null;
248
+ let n = t.getRangeAt(0);
249
+ return e && e !== document ? e.contains(n.commonAncestorContainer) ? n : null : De(n.commonAncestorContainer) ? n : null;
250
+ }
251
+ function ke(e) {
252
+ let t = globalThis.getSelection?.();
253
+ if (!t) return;
254
+ let n = document.createRange();
255
+ n.setStartAfter(e), n.collapse(!0), t.removeAllRanges(), t.addRange(n);
256
+ }
257
+ function Ae(e, t) {
258
+ let n = Oe(t);
259
+ if (!n) return !1;
260
+ let r = document.createElement("template");
261
+ r.innerHTML = e;
262
+ let i = r.content, a = i.lastChild;
263
+ return n.deleteContents(), n.insertNode(i), a && ke(a), !0;
264
+ }
265
+ function je(e, t) {
266
+ let n = Oe(t);
267
+ if (!n) return !1;
268
+ n.deleteContents();
269
+ let r = String(e), i = document.createDocumentFragment();
270
+ !r.includes("\n") || Me(n.startContainer, t) ? i.appendChild(document.createTextNode(r)) : r.split("\n").forEach((e, t) => {
271
+ t > 0 && i.appendChild(document.createElement("br")), e && i.appendChild(document.createTextNode(e));
272
+ });
273
+ let a = i.lastChild;
274
+ return n.insertNode(i), a && ke(a), !0;
275
+ }
276
+ function Me(e, t) {
277
+ let n = e.nodeType === 1 ? e : e.parentElement;
278
+ for (; n && n !== t;) {
279
+ if (n.tagName === "PRE" || n.tagName === "TEXTAREA") return !0;
280
+ let e = globalThis.getComputedStyle?.(n)?.whiteSpace;
281
+ if (e && e.startsWith("pre")) return !0;
282
+ n = n.parentElement;
283
+ }
284
+ return !1;
285
+ }
286
+ function Ne(e) {
287
+ let t = Oe(e);
288
+ if (!t) return !1;
289
+ let n = document.createElement("hr");
290
+ t.deleteContents();
291
+ let r = Fe(t.startContainer, e);
292
+ r && r.parentNode ? r.parentNode.insertBefore(n, r.nextSibling) : t.insertNode(n);
293
+ let i = n.nextElementSibling;
294
+ if (!i || i.tagName === "HR") {
295
+ let e = document.createElement("p");
296
+ e.appendChild(document.createElement("br")), n.parentNode?.insertBefore(e, n.nextSibling), i = e;
297
+ }
298
+ let a = globalThis.getSelection?.();
299
+ if (a) {
300
+ let e = document.createRange();
301
+ e.setStart(i, 0), e.collapse(!0), a.removeAllRanges(), a.addRange(e);
302
+ }
303
+ return !0;
304
+ }
305
+ var Pe = /* @__PURE__ */ new Set([
306
+ "P",
307
+ "DIV",
308
+ "H1",
309
+ "H2",
310
+ "H3",
311
+ "H4",
312
+ "H5",
313
+ "H6",
314
+ "BLOCKQUOTE",
315
+ "PRE",
316
+ "LI"
317
+ ]);
318
+ function Fe(e, t) {
319
+ let n = e.nodeType === 1 ? e : e.parentElement;
320
+ for (; n && n !== t;) {
321
+ if (Pe.has(n.tagName)) return n;
322
+ n = n.parentElement;
323
+ }
324
+ return null;
325
+ }
326
+ //#endregion
327
+ //#region src/js/editing/Style.js
328
+ function w(e, t = null) {
329
+ return e === "insertHTML" && Ae(String(t ?? "")) || e === "insertText" && je(String(t ?? "")) || e === "insertHorizontalRule" && Ne() ? !0 : document.execCommand(e, !1, t);
330
+ }
331
+ var Ie = () => w("bold"), Le = () => w("italic");
332
+ function Re() {
333
+ let e = globalThis.getSelection();
334
+ if (!e?.rangeCount) return;
335
+ let t = e.getRangeAt(0).commonAncestorContainer;
336
+ t.nodeType === 3 && (t = t.parentElement);
337
+ let n = t?.closest("u"), r = document.queryCommandState("underline");
338
+ if (n && !r) {
339
+ let e = n.parentNode;
340
+ for (; n.firstChild;) e.insertBefore(n.firstChild, n);
341
+ n.remove();
342
+ return;
343
+ }
344
+ w("underline");
345
+ }
346
+ function ze() {
347
+ let e = globalThis.getSelection();
348
+ if (!e?.rangeCount) return;
349
+ let t = e.getRangeAt(0).startContainer;
350
+ t.nodeType === 3 && (t = t.parentElement);
351
+ let n = t?.closest("s") || t?.closest("strike"), r = document.queryCommandState("strikeThrough");
352
+ if (n && !r) {
353
+ let e = n.parentNode;
354
+ for (; n.firstChild;) e.insertBefore(n.firstChild, n);
355
+ n.remove();
356
+ return;
357
+ }
358
+ w("strikeThrough");
359
+ }
360
+ var Be = () => w("superscript"), Ve = () => w("subscript"), He = (e) => w("foreColor", e), Ue = (e) => w("hiliteColor", e), We = (e) => w("fontName", e);
361
+ function Ge(e, t = document) {
362
+ let n = globalThis.getSelection(), r = !n?.rangeCount || n.getRangeAt(0).collapsed;
363
+ if (r && n?.rangeCount > 0) {
364
+ try {
365
+ let t = n.getRangeAt(0), r = document.createElement("span");
366
+ r.style.fontSize = e;
367
+ let i = document.createTextNode("​");
368
+ r.appendChild(i), t.insertNode(r);
369
+ let a = document.createRange();
370
+ a.setStart(i, i.textContent.length), a.collapse(!0), n.removeAllRanges(), n.addRange(a);
371
+ } catch {}
372
+ return;
373
+ }
374
+ w("fontSize", "7");
375
+ let i = t instanceof HTMLElement ? t : document, a = [];
376
+ if (i.querySelectorAll("font[size=\"7\"]").forEach((t) => {
377
+ let n = document.createElement("span");
378
+ for (n.style.fontSize = e, t.parentNode.insertBefore(n, t); t.firstChild;) n.appendChild(t.firstChild);
379
+ t.remove(), a.push(n);
380
+ }), !r && n && a.length > 0) {
381
+ let e = a[0], t = a.at(-1);
382
+ try {
383
+ let r = document.createRange(), i = e.firstChild || e, a = t.lastChild || t;
384
+ r.setStart(i, 0), r.setEnd(a, a.nodeType === Node.TEXT_NODE ? a.textContent.length : a.childNodes.length), n.removeAllRanges(), n.addRange(r);
385
+ } catch {}
386
+ }
387
+ }
388
+ var Ke = (e) => w("formatBlock", `<${e}>`), qe = () => w("justifyLeft"), Je = () => w("justifyCenter"), Ye = () => w("justifyRight"), Xe = () => w("justifyFull"), Ze = () => w("indent");
389
+ function Qe() {
390
+ let e = globalThis.getSelection();
391
+ if (e?.rangeCount) {
392
+ let t = e.getRangeAt(0).commonAncestorContainer;
393
+ t.nodeType === 3 && (t = t.parentElement);
394
+ let n = t?.closest(".an-checklist li");
395
+ if (n) {
396
+ $e(n);
397
+ return;
398
+ }
399
+ }
400
+ w("outdent");
401
+ }
402
+ function $e(e) {
403
+ let t = e.closest(".an-checklist");
404
+ if (!t) return;
405
+ let n = Array.from(t.children), r = n.indexOf(e), i = n.slice(r + 1), a = document.createElement("p");
406
+ for (let t of e.childNodes) t.nodeType === 1 && t.tagName === "INPUT" || a.appendChild(t.cloneNode(!0));
407
+ if (a.innerHTML = a.innerHTML.replaceAll("​", ""), (!a.hasChildNodes() || !a.textContent.trim()) && (a.innerHTML = "", a.appendChild(document.createTextNode("\xA0"))), i.length > 0) {
408
+ let e = document.createElement("ul");
409
+ e.className = "an-checklist", i.forEach((t) => e.appendChild(t)), t.parentNode.insertBefore(e, t.nextSibling);
410
+ }
411
+ t.parentNode.insertBefore(a, t.nextSibling), e.remove(), t.children.length === 0 && t.remove();
412
+ try {
413
+ let e = document.createRange(), t = a.firstChild;
414
+ e.setStart(t?.nodeType === 3 ? t : a, 0), e.collapse(!0);
415
+ let n = globalThis.getSelection();
416
+ n && (n.removeAllRanges(), n.addRange(e));
417
+ } catch {}
418
+ }
419
+ function et() {
420
+ let e = globalThis.getSelection();
421
+ if (!e?.rangeCount) return null;
422
+ let t = e.getRangeAt(0).commonAncestorContainer;
423
+ return t.nodeType === 3 && (t = t.parentElement), t?.closest("ul, ol") || null;
424
+ }
425
+ function tt(e) {
426
+ e.classList.remove("an-checklist"), e.querySelectorAll("input[type=\"checkbox\"]").forEach((e) => e.remove());
427
+ }
428
+ function nt() {
429
+ let e = et();
430
+ e ? e.classList.contains("an-checklist") ? (tt(e), e.tagName === "OL" && T(e, "ul")) : e.tagName === "OL" ? T(e, "ul") : w("insertUnorderedList") : w("insertUnorderedList");
431
+ }
432
+ function rt() {
433
+ let e = et();
434
+ e ? e.classList.contains("an-checklist") ? (tt(e), T(e, "ol")) : e.tagName === "UL" ? T(e, "ol") : w("insertOrderedList") : w("insertOrderedList");
435
+ }
436
+ function it(e) {
437
+ let t = globalThis.getSelection();
438
+ if (!t || t.rangeCount === 0) return;
439
+ let n = t.getRangeAt(0), r = /* @__PURE__ */ new Set([
440
+ "P",
441
+ "DIV",
442
+ "H1",
443
+ "H2",
444
+ "H3",
445
+ "H4",
446
+ "H5",
447
+ "H6",
448
+ "LI",
449
+ "BLOCKQUOTE",
450
+ "PRE",
451
+ "TD",
452
+ "TH"
453
+ ]), i = (e) => {
454
+ let t = e instanceof Element ? e : e.parentElement;
455
+ for (; t;) {
456
+ if (r.has(t.tagName)) return t;
457
+ t = t.parentElement;
458
+ }
459
+ return null;
460
+ };
461
+ if (n.collapsed) {
462
+ let t = i(n.startContainer);
463
+ t && (t.style.lineHeight = e);
464
+ return;
465
+ }
466
+ let a = /* @__PURE__ */ new Set(), o = document.createTreeWalker(n.commonAncestorContainer, NodeFilter.SHOW_TEXT, { acceptNode: (e) => n.intersectsNode(e) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP }), s;
467
+ for (; s = o.nextNode();) {
468
+ let e = i(s);
469
+ e && a.add(e);
470
+ }
471
+ if (a.size === 0) {
472
+ let e = i(n.commonAncestorContainer);
473
+ e && a.add(e);
474
+ }
475
+ a.forEach((t) => {
476
+ t.style.lineHeight = e;
477
+ });
478
+ }
479
+ function at(e) {
480
+ let t = globalThis.getSelection();
481
+ if (!t?.rangeCount) return;
482
+ let n = t.getRangeAt(0), r = n.commonAncestorContainer;
483
+ r.nodeType === 3 && (r = r.parentElement);
484
+ let i = r?.closest("code");
485
+ if (i && !i.closest("pre")) {
486
+ let e = i.parentNode, n = i.previousSibling, r = Array.from(i.childNodes);
487
+ for (; i.firstChild;) e.insertBefore(i.firstChild, i);
488
+ if (i.remove(), e?.normalize(), r.length > 0) try {
489
+ let i = r[0], a = r.at(-1), o = document.createRange(), s = i.parentNode === e ? i : n ? n.nextSibling : e.firstChild;
490
+ if (s) {
491
+ o.setStart(s, 0);
492
+ let n = a.parentNode === e ? a : s;
493
+ o.setEnd(n, n.nodeType === Node.TEXT_NODE ? n.textContent.length : n.childNodes.length), t.removeAllRanges(), t.addRange(o);
494
+ }
495
+ } catch {}
496
+ } else {
497
+ if (n.collapsed) return;
498
+ try {
499
+ let e = document.createElement("code");
500
+ n.surroundContents(e);
501
+ let r = document.createRange();
502
+ r.selectNodeContents(e), t.removeAllRanges(), t.addRange(r);
503
+ } catch {
504
+ let e = n.extractContents(), r = document.createElement("code");
505
+ r.appendChild(e), n.insertNode(r);
506
+ let i = document.createRange();
507
+ i.selectNodeContents(r), t.removeAllRanges(), t.addRange(i);
508
+ }
509
+ }
510
+ }
511
+ function ot() {
512
+ let e = globalThis.getSelection();
513
+ if (!e?.rangeCount) return !1;
514
+ let t = e.getRangeAt(0).startContainer;
515
+ t.nodeType === 3 && (t = t.parentElement);
516
+ let n = t?.closest("code");
517
+ return !!(n && !n.closest("pre"));
518
+ }
519
+ function T(e, t) {
520
+ let n = document.createElement(t);
521
+ for (let t of e.attributes) n.setAttribute(t.name, t.value);
522
+ for (; e.firstChild;) n.appendChild(e.firstChild);
523
+ return e.parentNode.replaceChild(n, e), n;
524
+ }
525
+ function st(e) {
526
+ e.querySelectorAll("li").forEach((e) => {
527
+ if (!e.querySelector("input[type=\"checkbox\"]")) {
528
+ let t = document.createElement("input");
529
+ t.type = "checkbox", t.contentEditable = "false", e.insertBefore(t, e.firstChild);
530
+ }
531
+ });
532
+ }
533
+ function ct() {
534
+ let e = globalThis.getSelection();
535
+ if (!e?.rangeCount) return;
536
+ let t = e.getRangeAt(0), n = t.commonAncestorContainer;
537
+ n.nodeType === 3 && (n = n.parentElement);
538
+ let r = n?.closest("ul, ol");
539
+ if (r) if (r.classList.contains("an-checklist")) {
540
+ if (r.parentNode) {
541
+ let t = Array.from(r.children), n = null;
542
+ if (t.forEach((e) => {
543
+ let t = document.createElement("p");
544
+ for (let n of e.childNodes) n.nodeType === 1 && n.tagName === "INPUT" || t.appendChild(n.cloneNode(!0));
545
+ t.innerHTML = t.innerHTML.replaceAll("​", "").replaceAll("​", ""), (!t.hasChildNodes() || !t.textContent.trim()) && (t.innerHTML = "", t.appendChild(document.createTextNode("\xA0"))), r.before(t), n ||= t;
546
+ }), r.remove(), n) {
547
+ let t = document.createRange();
548
+ t.setStart(n.firstChild || n, 0), t.collapse(!0), e.removeAllRanges(), e.addRange(t);
549
+ }
550
+ }
551
+ } else {
552
+ let t = T(r, "ul");
553
+ t.classList.add("an-checklist"), st(t);
554
+ let n = t.querySelector("li");
555
+ if (n) {
556
+ let t = document.createRange();
557
+ t.selectNodeContents(n), t.collapse(!1), e.removeAllRanges(), e.addRange(t);
558
+ }
559
+ }
560
+ else {
561
+ let r = n?.closest("[contenteditable=\"true\"]");
562
+ if (t.collapsed) {
563
+ let t = /* @__PURE__ */ new Set([
564
+ "P",
565
+ "DIV",
566
+ "H1",
567
+ "H2",
568
+ "H3",
569
+ "H4",
570
+ "H5",
571
+ "H6",
572
+ "BLOCKQUOTE",
573
+ "LI"
574
+ ]), i = n;
575
+ for (; i?.parentNode && i !== r && !t.has(i.tagName);) i = i.parentNode;
576
+ i === r && (i = null);
577
+ let a = i && t.has(i.tagName) ? Array.from(i.childNodes).map((e) => e.textContent).join("").replaceAll("\xA0", " ") : "", o = document.createElement("ul");
578
+ o.className = "an-checklist";
579
+ let s = document.createElement("li"), c = document.createElement("input");
580
+ if (c.type = "checkbox", c.contentEditable = "false", s.appendChild(c), s.appendChild(document.createTextNode(a || "​")), o.appendChild(s), i && t.has(i.tagName)) i.parentNode.replaceChild(o, i);
581
+ else {
582
+ let t = e.getRangeAt(0);
583
+ t.deleteContents(), t.insertNode(o);
584
+ }
585
+ let l = s.lastChild, u = document.createRange(), d = l.nodeType === Node.TEXT_NODE ? l.textContent.length : 0;
586
+ u.setStart(l, d), u.collapse(!0), e.removeAllRanges(), e.addRange(u);
587
+ return;
588
+ }
589
+ if (!e.toString().replace(/[\u00a0\u200B]/g, " ").trim()) return;
590
+ let i = /* @__PURE__ */ new Set([
591
+ "P",
592
+ "DIV",
593
+ "H1",
594
+ "H2",
595
+ "H3",
596
+ "H4",
597
+ "H5",
598
+ "H6",
599
+ "BLOCKQUOTE",
600
+ "PRE",
601
+ "LI"
602
+ ]), a = [], o = /* @__PURE__ */ new Set(), s = t.commonAncestorContainer, c = document.createNodeIterator(s.nodeType === Node.TEXT_NODE ? s.parentNode : s, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT, null), l;
603
+ for (; l = c.nextNode();) {
604
+ if (!t.intersectsNode(l)) continue;
605
+ let e = l.nodeType === Node.TEXT_NODE ? l.parentElement : l;
606
+ for (; e && e !== r && !i.has(e.tagName);) e = e.parentElement;
607
+ e === r && (e = null), e && !o.has(e) && (o.add(e), a.push(e));
608
+ }
609
+ if (a.length === 0) return;
610
+ let u = document.createElement("ul");
611
+ u.className = "an-checklist";
612
+ let d = null;
613
+ a.forEach((e) => {
614
+ let t = document.createElement("li"), n = document.createElement("input");
615
+ n.type = "checkbox", n.contentEditable = "false", t.appendChild(n);
616
+ let r = Array.from(e.childNodes).map((e) => e.textContent).join("").replace(/[\u00a0\u200B]/g, " ").trim(), i = document.createTextNode(r || "​");
617
+ t.appendChild(i), u.appendChild(t), d = i;
618
+ });
619
+ let f = a[0];
620
+ if (f.parentNode.insertBefore(u, f), a.forEach((e) => e.remove()), d) {
621
+ let t = document.createRange();
622
+ t.setStart(d, d.textContent.length), t.collapse(!0), e.removeAllRanges(), e.addRange(t);
623
+ }
624
+ }
625
+ }
626
+ function lt() {
627
+ let e = globalThis.getSelection();
628
+ if (!e?.rangeCount) return !1;
629
+ let t = e.getRangeAt(0).commonAncestorContainer;
630
+ return t.nodeType === 3 && (t = t.parentElement), !!t?.closest(".an-checklist li");
631
+ }
632
+ //#endregion
633
+ //#region src/js/module/Buttons.js
634
+ function E(e, t, n, r, i, a) {
635
+ return {
636
+ name: e,
637
+ icon: t,
638
+ tooltip: n,
639
+ action: r,
640
+ isActive: i,
641
+ isDisabled: a
642
+ };
643
+ }
644
+ var D = /* @__PURE__ */ new Map();
645
+ function O(e) {
646
+ if (!e || typeof e.name != "string") {
647
+ console.warn("[AutumnNote] registerButton: btnDef must have a string `name` property.");
648
+ return;
649
+ }
650
+ D.has(e.name) && console.warn(`[AutumnNote] registerButton: overwriting existing button "${e.name}".`), D.set(e.name, e);
651
+ }
652
+ function ut(e) {
653
+ return D.get(e);
654
+ }
655
+ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryCommandState("bold")), ft = E("italic", "italic", "Italic (Ctrl+I)", () => Le(), () => document.queryCommandState("italic")), pt = E("underline", "underline", "Underline (Ctrl+U)", () => Re(), () => {
656
+ if (document.queryCommandState("underline")) return !0;
657
+ let e = globalThis.getSelection();
658
+ if (!e?.rangeCount) return !1;
659
+ let t = e.getRangeAt(0).startContainer;
660
+ return t.nodeType === 3 && (t = t.parentElement), !!t?.closest("u");
661
+ }), mt = E("strikethrough", "strikethrough", "Strikethrough", () => ze(), () => document.queryCommandState("strikeThrough")), ht = E("superscript", "superscript", "Superscript", () => Be(), () => document.queryCommandState("superscript")), gt = E("subscript", "subscript", "Subscript", () => Ve(), () => document.queryCommandState("subscript")), _t = E("alignLeft", "align-left", "Align Left", () => qe()), vt = E("alignCenter", "align-center", "Align Center", () => Je()), yt = E("alignRight", "align-right", "Align Right", () => Ye()), bt = E("alignJustify", "align-justify", "Justify", () => Xe()), xt = E("ul", "list-ul", "Unordered List", () => nt()), St = E("ol", "list-ol", "Ordered List", () => rt()), Ct = E("indent", "indent", "Indent", () => Ze()), wt = E("outdent", "outdent", "Outdent", () => Qe()), Tt = E("undo", "undo", "Undo (Ctrl+Z)", (e) => e.invoke("editor.undo"), void 0, (e) => !e.invoke("editor.canUndo")), Et = E("redo", "redo", "Redo (Ctrl+Y)", (e) => e.invoke("editor.redo"), void 0, (e) => !e.invoke("editor.canRedo")), Dt = E("hr", "minus", "Horizontal Rule", () => w("insertHorizontalRule")), Ot = E("link", "link", "Insert Link", (e) => e.invoke("linkDialog.show")), kt = E("image", "image", "Insert Image", (e) => e.invoke("imageDialog.show")), At = E("video", "video", "Insert Video", (e) => e.invoke("videoDialog.show")), jt = E("emoji", "emoji", "Insert Emoji", (e) => e.invoke("emojiDialog.show")), Mt = E("icon", "icon", "Insert FA Icon", (e) => e.invoke("iconDialog.show")), Nt = {
662
+ name: "table",
663
+ type: "grid",
664
+ icon: "table",
665
+ tooltip: "Insert Table",
666
+ action: (e, t, n) => {
667
+ e.invoke("editor.insertTable", n, t), e.invoke("editor.afterCommand");
668
+ }
669
+ }, Pt = {
670
+ name: "fontSize",
671
+ type: "select",
672
+ tooltip: "Font Size",
673
+ placeholder: "Size",
674
+ selectClass: "an-select-narrow",
675
+ items: [
676
+ "8px",
677
+ "10px",
678
+ "11px",
679
+ "12px",
680
+ "13px",
681
+ "14px",
682
+ "16px",
683
+ "18px",
684
+ "20px",
685
+ "24px",
686
+ "28px",
687
+ "32px",
688
+ "36px",
689
+ "48px",
690
+ "72px"
691
+ ],
692
+ action: (e, t) => Ge(t, e.layoutInfo.editable),
693
+ getValue: (e) => {
694
+ try {
695
+ let t = globalThis.getSelection();
696
+ if (t?.rangeCount) {
697
+ let e = t.getRangeAt(0).startContainer;
698
+ for (e?.nodeType === 3 && (e = e.parentElement); e?.nodeType === 1 && !e.style.fontSize;) e = e.parentElement;
699
+ let n = e?.style.fontSize || "";
700
+ if (n) return n;
701
+ }
702
+ let n = e?.layoutInfo?.editable;
703
+ return n && n.style.fontSize || "";
704
+ } catch {
705
+ return "";
706
+ }
707
+ }
708
+ }, Ft = E("removeFormat", "remove-format", "Remove Format", () => w("removeFormat")), It = E("direction", "direction", "Toggle Text Direction (LTR / RTL)", (e) => {
709
+ let t = e.layoutInfo.editable, n = (t.getAttribute("dir") || "ltr") === "ltr" ? "rtl" : "ltr";
710
+ t.setAttribute("dir", n), t.style.textAlign = n === "rtl" ? "right" : "left", e.invoke("editor.afterCommand");
711
+ }), Lt = {
712
+ name: "fontFamily",
713
+ type: "select",
714
+ tooltip: "Font Family",
715
+ action: (e, t) => We(t),
716
+ getValue: () => {
717
+ try {
718
+ return document.queryCommandValue("fontName") || "";
719
+ } catch {
720
+ return "";
721
+ }
722
+ }
723
+ }, Rt = {
724
+ name: "paragraphStyle",
725
+ type: "select",
726
+ tooltip: "Paragraph Style",
727
+ placeholder: "Style",
728
+ selectClass: "an-select-style",
729
+ items: [
730
+ {
731
+ value: "p",
732
+ label: "Normal"
733
+ },
734
+ {
735
+ value: "h1",
736
+ label: "H1"
737
+ },
738
+ {
739
+ value: "h2",
740
+ label: "H2"
741
+ },
742
+ {
743
+ value: "h3",
744
+ label: "H3"
745
+ },
746
+ {
747
+ value: "h4",
748
+ label: "H4"
749
+ },
750
+ {
751
+ value: "h5",
752
+ label: "H5"
753
+ },
754
+ {
755
+ value: "h6",
756
+ label: "H6"
757
+ },
758
+ {
759
+ value: "blockquote",
760
+ label: "Quote"
761
+ },
762
+ {
763
+ value: "pre",
764
+ label: "Code"
765
+ }
766
+ ],
767
+ action: (e, t) => Ke(t),
768
+ getValue: () => {
769
+ try {
770
+ let e = document.queryCommandValue("formatBlock").toLowerCase().replace(/[<>]/g, "");
771
+ return e === "div" ? "p" : e || "p";
772
+ } catch {
773
+ return "";
774
+ }
775
+ }
776
+ }, zt = {
777
+ name: "lineHeight",
778
+ type: "select",
779
+ tooltip: "Line Height",
780
+ placeholder: "↕ Line",
781
+ selectClass: "an-select-narrow",
782
+ items: [
783
+ "1.0",
784
+ "1.15",
785
+ "1.5",
786
+ "1.75",
787
+ "2.0",
788
+ "2.5",
789
+ "3.0"
790
+ ],
791
+ action: (e, t) => it(t),
792
+ getValue: () => {
793
+ try {
794
+ let e = globalThis.getSelection();
795
+ if (!e?.rangeCount) return "";
796
+ let t = /* @__PURE__ */ new Set([
797
+ "P",
798
+ "DIV",
799
+ "H1",
800
+ "H2",
801
+ "H3",
802
+ "H4",
803
+ "H5",
804
+ "H6",
805
+ "LI",
806
+ "BLOCKQUOTE",
807
+ "PRE",
808
+ "TD",
809
+ "TH"
810
+ ]), n = e.getRangeAt(0).startContainer;
811
+ for (n?.nodeType === 3 && (n = n.parentElement); n && !t.has(n.tagName);) n = n.parentElement;
812
+ return n && (n.style.lineHeight || getComputedStyle(n).lineHeight) || "";
813
+ } catch {
814
+ return "";
815
+ }
816
+ }
817
+ }, Bt = E("codeview", "code", "HTML Code View", (e) => e.invoke("codeview.toggle"), (e) => e.invoke("codeview.isActive")), Vt = E("fullscreen", "expand", "Fullscreen", (e) => e.invoke("fullscreen.toggle"), (e) => e.invoke("fullscreen.isActive")), Ht = E("shortcuts", "keyboard", "Keyboard Shortcuts (Ctrl+Shift+/)", (e) => e.invoke("shortcutsDialog.show")), Ut = E("find", "search", "Find (Ctrl+F)", (e) => e.invoke("findReplace.show", "find")), Wt = E("findReplace", "find-replace", "Find & Replace (Ctrl+H)", (e) => e.invoke("findReplace.show", "replace")), Gt = E("inlineCode", "inline-code", "Inline Code (Ctrl+`)", (e) => e.invoke("editor.inlineCode"), () => ot()), Kt = E("checklist", "checklist", "Checklist", (e) => e.invoke("editor.toggleChecklist"), () => lt()), qt = E("print", "print", "Print", (e) => e.invoke("editor.print")), Jt = {
818
+ name: "foreColor",
819
+ type: "colorpicker",
820
+ icon: "foreColor",
821
+ tooltip: "Text Color",
822
+ defaultColor: "#e11d48",
823
+ action: (e, t) => He(t)
824
+ }, Yt = {
825
+ name: "backColor",
826
+ type: "colorpicker",
827
+ icon: "backColor",
828
+ tooltip: "Highlight Color",
829
+ defaultColor: "#fbbf24",
830
+ action: (e, t) => Ue(t)
831
+ }, Xt = [
832
+ [
833
+ Rt,
834
+ Lt,
835
+ Pt,
836
+ zt
837
+ ],
838
+ [Tt, Et],
839
+ [
840
+ dt,
841
+ ft,
842
+ pt,
843
+ mt,
844
+ Gt
845
+ ],
846
+ [ht, gt],
847
+ [Jt, Yt],
848
+ [
849
+ _t,
850
+ vt,
851
+ yt,
852
+ bt
853
+ ],
854
+ [
855
+ xt,
856
+ St,
857
+ Kt,
858
+ Ct,
859
+ wt
860
+ ],
861
+ [
862
+ Dt,
863
+ Ot,
864
+ kt,
865
+ At,
866
+ Nt,
867
+ jt,
868
+ Mt
869
+ ],
870
+ [
871
+ Ft,
872
+ Bt,
873
+ Vt,
874
+ Ut,
875
+ qt,
876
+ Ht
877
+ ]
878
+ ], Zt = {
879
+ boldBtn: dt,
880
+ italicBtn: ft,
881
+ underlineBtn: pt,
882
+ strikeBtn: mt,
883
+ superscriptBtn: ht,
884
+ subscriptBtn: gt,
885
+ alignLeftBtn: _t,
886
+ alignCenterBtn: vt,
887
+ alignRightBtn: yt,
888
+ alignJustifyBtn: bt,
889
+ ulBtn: xt,
890
+ olBtn: St,
891
+ indentBtn: Ct,
892
+ outdentBtn: wt,
893
+ undoBtn: Tt,
894
+ redoBtn: Et,
895
+ hrBtn: Dt,
896
+ linkBtn: Ot,
897
+ imageBtn: kt,
898
+ videoBtn: At,
899
+ emojiBtn: jt,
900
+ iconBtn: Mt,
901
+ tableBtn: Nt,
902
+ fontSizeBtn: Pt,
903
+ removeFormatBtn: Ft,
904
+ directionBtn: It,
905
+ fontFamilyBtn: Lt,
906
+ paragraphStyleBtn: Rt,
907
+ lineHeightBtn: zt,
908
+ codeviewBtn: Bt,
909
+ fullscreenBtn: Vt,
910
+ shortcutsBtn: Ht,
911
+ findBtn: Ut,
912
+ findReplaceBtn: Wt,
913
+ inlineCodeBtn: Gt,
914
+ checklistBtn: Kt,
915
+ printBtn: qt,
916
+ foreColorBtn: Jt,
917
+ backColorBtn: Yt,
918
+ defaultToolbar: Xt
919
+ }, k = {
920
+ placeholder: "",
921
+ height: 200,
922
+ minHeight: 100,
923
+ maxHeight: 0,
924
+ focus: !1,
925
+ resizable: !0,
926
+ toolbar: Xt,
927
+ useBootstrap: !1,
928
+ toolbarButtonClass: "btn btn-sm btn-light",
929
+ useFontAwesome: !0,
930
+ fontAwesomeClass: "fas",
931
+ fontAwesomeAutoInject: !0,
932
+ fontAwesomeCDN: "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css",
933
+ pasteAsPlainText: !1,
934
+ pasteCleanHTML: !0,
935
+ pasteStripAttributes: !1,
936
+ allowImageUpload: !0,
937
+ maxImageSize: 5,
938
+ tabSize: 4,
939
+ onChange: null,
940
+ onFocus: null,
941
+ onBlur: null,
942
+ onInit: null,
943
+ onImageUpload: null,
944
+ onImageError: null,
945
+ stickyToolbar: !1,
946
+ stickyToolbarOffset: 0,
947
+ theme: "light",
948
+ codeHighlight: !0,
949
+ codeHighlightCDN: "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0",
950
+ markdownPaste: !0,
951
+ historyLimit: 100,
952
+ historyMaxBytes: 10 * 1024 * 1024,
953
+ defaultFontFamily: "Arial",
954
+ defaultFontSize: "14px",
955
+ fontFamilies: [
956
+ "Arial",
957
+ "Arial Black",
958
+ "Comic Sans MS",
959
+ "Courier New",
960
+ "Georgia",
961
+ "Impact",
962
+ "Tahoma",
963
+ "Times New Roman",
964
+ "Trebuchet MS",
965
+ "Verdana"
966
+ ],
967
+ readOnly: !1,
968
+ spellcheck: !0,
969
+ direction: "ltr",
970
+ toolbarOverflow: "wrap",
971
+ autoSave: !1,
972
+ autoSaveKey: "autumnnote-autosave",
973
+ autoSaveDelay: 400,
974
+ autoSaveAdapter: null,
975
+ maxChars: 0,
976
+ maxWords: 0,
977
+ tableHeaderRow: !1,
978
+ onSelectionChange: null,
979
+ colorSwatches: [],
980
+ onPaste: null,
981
+ onPasteError: null,
982
+ onDestroy: null,
983
+ onCharLimitReached: null,
984
+ onWordLimitReached: null,
985
+ focusColor: null,
986
+ lang: "en",
987
+ autoSaveRestore: !1,
988
+ autoSaveRestoreTimeout: 7,
989
+ onAutoSaveRestore: null,
990
+ markdownShortcuts: !0,
991
+ slashMenu: !0,
992
+ slashCommands: [],
993
+ documentAdapters: {},
994
+ collaborationAdapter: null,
995
+ imageProcessor: null,
996
+ blockIds: !1,
997
+ maxPasteSize: 5 * 1024 * 1024,
998
+ minImageSize: 20,
999
+ bubbleToolbar: !1,
1000
+ bubbleToolbarItems: [
1001
+ "bold",
1002
+ "italic",
1003
+ "underline",
1004
+ "link",
1005
+ "foreColor",
1006
+ "hiliteColor",
1007
+ "removeFormat"
1008
+ ],
1009
+ mention: null
1010
+ }, A = {
1011
+ toolbar: {
1012
+ bold: "Bold (Ctrl+B)",
1013
+ italic: "Italic (Ctrl+I)",
1014
+ underline: "Underline (Ctrl+U)",
1015
+ strikethrough: "Strikethrough",
1016
+ superscript: "Superscript",
1017
+ subscript: "Subscript",
1018
+ alignLeft: "Align Left",
1019
+ alignCenter: "Align Center",
1020
+ alignRight: "Align Right",
1021
+ alignJustify: "Justify",
1022
+ ul: "Unordered List",
1023
+ ol: "Ordered List",
1024
+ checklist: "Checklist",
1025
+ indent: "Indent",
1026
+ outdent: "Outdent",
1027
+ undo: "Undo (Ctrl+Z)",
1028
+ redo: "Redo (Ctrl+Y)",
1029
+ hr: "Horizontal Rule",
1030
+ link: "Insert Link",
1031
+ image: "Insert Image",
1032
+ video: "Insert Video",
1033
+ emoji: "Insert Emoji",
1034
+ icon: "Insert FA Icon",
1035
+ table: "Insert Table",
1036
+ fontSize: "Font Size",
1037
+ fontSizePlaceholder: "Size",
1038
+ removeFormat: "Remove Format",
1039
+ direction: "Toggle Text Direction (LTR / RTL)",
1040
+ fontFamily: "Font Family",
1041
+ paragraphStyle: "Paragraph Style",
1042
+ paragraphStylePlaceholder: "Style",
1043
+ lineHeight: "Line Height",
1044
+ lineHeightPlaceholder: "↕ Line",
1045
+ codeview: "HTML Code View",
1046
+ fullscreen: "Fullscreen",
1047
+ shortcuts: "Keyboard Shortcuts (Ctrl+Shift+/)",
1048
+ find: "Find (Ctrl+F)",
1049
+ findReplace: "Find & Replace (Ctrl+H)",
1050
+ inlineCode: "Inline Code (Ctrl+`)",
1051
+ print: "Print",
1052
+ foreColor: "Text Color",
1053
+ backColor: "Highlight Color",
1054
+ chooseTextColor: "Choose text color",
1055
+ chooseHighlightColor: "Choose highlight color",
1056
+ customColor: "Custom color",
1057
+ insertTableLabel: "Insert Table",
1058
+ paragraphItems: {
1059
+ p: "Normal",
1060
+ blockquote: "Quote",
1061
+ pre: "Code"
1062
+ }
1063
+ },
1064
+ linkDialog: {
1065
+ ariaLabel: "Insert link",
1066
+ title: "Insert Link",
1067
+ url: "URL",
1068
+ urlPlaceholder: "https://",
1069
+ displayText: "Display Text",
1070
+ textPlaceholder: "Link text",
1071
+ openInNewTab: "Open in new tab",
1072
+ insertBtn: "Insert",
1073
+ cancelBtn: "Cancel"
1074
+ },
1075
+ imageDialog: {
1076
+ ariaLabel: "Insert image",
1077
+ title: "Insert Image",
1078
+ imageUrl: "Image URL",
1079
+ urlPlaceholder: "https://example.com/image.png",
1080
+ altText: "Alt Text",
1081
+ altPlaceholder: "Describe the image",
1082
+ alignment: "Alignment",
1083
+ alignNone: "None",
1084
+ alignLeft: "Left",
1085
+ alignCenter: "Center",
1086
+ alignRight: "Right",
1087
+ uploadLabel: "Or upload a file",
1088
+ insertBtn: "Insert",
1089
+ cancelBtn: "Cancel"
1090
+ },
1091
+ videoDialog: {
1092
+ ariaLabel: "Insert video",
1093
+ title: "Insert Video",
1094
+ videoUrl: "Video URL",
1095
+ urlPlaceholder: "YouTube, Vimeo, or direct .mp4 URL",
1096
+ widthLabel: "Width (px)",
1097
+ widthPlaceholder: "560",
1098
+ insertBtn: "Insert",
1099
+ cancelBtn: "Cancel",
1100
+ detected: (e) => `Detected: ${e}`,
1101
+ unknownFormat: "Unknown format — will try direct video embed",
1102
+ invalidUrl: "Invalid URL — please enter a valid video link."
1103
+ },
1104
+ emojiDialog: {
1105
+ ariaLabel: "Insert emoji",
1106
+ title: "Insert Emoji",
1107
+ searchPlaceholder: "Search emojis…",
1108
+ all: "All",
1109
+ cancelBtn: "Cancel",
1110
+ close: "Close",
1111
+ categories: {
1112
+ smileys: "Smileys",
1113
+ people: "People",
1114
+ animals: "Animals",
1115
+ food: "Food",
1116
+ travel: "Travel",
1117
+ objects: "Objects",
1118
+ symbols: "Symbols"
1119
+ }
1120
+ },
1121
+ iconDialog: {
1122
+ ariaLabel: "Insert FA icon",
1123
+ title: "Insert FA Icon",
1124
+ searchPlaceholder: "Search icons…",
1125
+ all: "All",
1126
+ style: "Style",
1127
+ size: "Size",
1128
+ color: "Color",
1129
+ useColor: " Use color",
1130
+ selectHint: "Select an icon",
1131
+ insertBtn: "Insert FA Icon",
1132
+ cancelBtn: "Cancel",
1133
+ close: "Close",
1134
+ categories: {
1135
+ popular: "Popular",
1136
+ interface: "Interface",
1137
+ navigation: "Navigation",
1138
+ media: "Media",
1139
+ communication: "Communication",
1140
+ files: "Files",
1141
+ people: "People",
1142
+ objects: "Objects"
1143
+ }
1144
+ },
1145
+ findReplace: {
1146
+ findTitle: "Find",
1147
+ findReplaceTitle: "Find & Replace",
1148
+ findPlaceholder: "Find…",
1149
+ searchAriaLabel: "Search text",
1150
+ caseSensitive: "\xA0Case sensitive",
1151
+ wholeWord: "Whole Word",
1152
+ prevBtn: "← Prev",
1153
+ nextBtn: "Next →",
1154
+ replacePlaceholder: "Replace with…",
1155
+ replaceAriaLabel: "Replace with",
1156
+ replaceBtn: "Replace",
1157
+ replaceAllBtn: "Replace All",
1158
+ noResults: "No results",
1159
+ useRegex: "Use Regular Expression",
1160
+ close: "×"
1161
+ },
1162
+ autoSaveRestore: {
1163
+ found: "Draft found. Restore?",
1164
+ foundAt: "Draft from {date}. Restore?",
1165
+ restore: "Restore",
1166
+ discard: "Discard"
1167
+ },
1168
+ shortcutsDialog: {
1169
+ title: "Keyboard Shortcuts",
1170
+ ariaLabel: "Keyboard Shortcuts",
1171
+ close: "Close",
1172
+ shortcuts: [
1173
+ {
1174
+ category: "Text Formatting",
1175
+ items: [
1176
+ {
1177
+ keys: "Ctrl + B",
1178
+ action: "Bold"
1179
+ },
1180
+ {
1181
+ keys: "Ctrl + I",
1182
+ action: "Italic"
1183
+ },
1184
+ {
1185
+ keys: "Ctrl + U",
1186
+ action: "Underline"
1187
+ },
1188
+ {
1189
+ keys: "Ctrl + K",
1190
+ action: "Insert / edit link"
1191
+ }
1192
+ ]
1193
+ },
1194
+ {
1195
+ category: "History",
1196
+ items: [{
1197
+ keys: "Ctrl + Z",
1198
+ action: "Undo"
1199
+ }, {
1200
+ keys: "Ctrl + Y / Ctrl + Shift + Z",
1201
+ action: "Redo"
1202
+ }]
1203
+ },
1204
+ {
1205
+ category: "Selection & Navigation",
1206
+ items: [
1207
+ {
1208
+ keys: "Ctrl + A",
1209
+ action: "Select all content"
1210
+ },
1211
+ {
1212
+ keys: "Tab",
1213
+ action: "Indent list item / insert spaces"
1214
+ },
1215
+ {
1216
+ keys: "Shift + Tab",
1217
+ action: "Outdent list item"
1218
+ }
1219
+ ]
1220
+ },
1221
+ {
1222
+ category: "Clipboard",
1223
+ items: [{
1224
+ keys: "Ctrl + Shift + V",
1225
+ action: "Paste as plain text"
1226
+ }]
1227
+ },
1228
+ {
1229
+ category: "Find & Replace",
1230
+ items: [{
1231
+ keys: "Ctrl + F",
1232
+ action: "Find in document"
1233
+ }, {
1234
+ keys: "Ctrl + H",
1235
+ action: "Find & Replace"
1236
+ }]
1237
+ },
1238
+ {
1239
+ category: "Editor",
1240
+ items: [{
1241
+ keys: "Ctrl + Shift + /",
1242
+ action: "Show this keyboard shortcuts dialog"
1243
+ }]
1244
+ }
1245
+ ]
1246
+ },
1247
+ contextMenu: {
1248
+ cut: "Cut",
1249
+ copy: "Copy",
1250
+ paste: "Paste",
1251
+ bold: "Bold",
1252
+ italic: "Italic",
1253
+ underline: "Underline",
1254
+ textColor: "Text Color",
1255
+ highlightColor: "Highlight Color",
1256
+ copyFormat: "Copy Format",
1257
+ pasteFormat: "Paste Format",
1258
+ removeFormat: "Remove Format",
1259
+ link: "Insert Link",
1260
+ image: "Insert Image",
1261
+ video: "Insert Video",
1262
+ table: "Insert Table",
1263
+ back: "Back",
1264
+ noHighlight: "No highlight",
1265
+ customColor: "Custom color",
1266
+ customColorLabel: "Custom…"
1267
+ },
1268
+ statusbar: {
1269
+ resizeHandle: "Resize editor",
1270
+ words: (e) => `Words: ${e}`,
1271
+ wordsLimit: (e, t) => `Words: ${e}/${t}`,
1272
+ chars: (e) => `Chars: ${e}`,
1273
+ charsLimit: (e, t) => `Chars: ${e}/${t}`
1274
+ },
1275
+ tooltips: {
1276
+ link: {
1277
+ ariaLabel: "Link actions",
1278
+ openLink: "Open link",
1279
+ copyUrl: "Copy URL",
1280
+ editLink: "Edit link",
1281
+ removeLink: "Remove link"
1282
+ },
1283
+ image: {
1284
+ ariaLabel: "Image actions",
1285
+ label: "Image",
1286
+ floatLeft: "Float Left",
1287
+ noFloat: "No Float",
1288
+ alignCenter: "Align Center",
1289
+ floatRight: "Float Right",
1290
+ originalSize: "Original Size",
1291
+ rotateLeft: "Rotate Left",
1292
+ rotateRight: "Rotate Right",
1293
+ cropImage: "Crop Image",
1294
+ addCaption: "Add / Edit Caption",
1295
+ deleteImage: "Delete Image"
1296
+ },
1297
+ code: {
1298
+ ariaLabel: "Code block actions",
1299
+ label: "Code",
1300
+ syntaxLanguage: "Syntax Language",
1301
+ syntaxAriaLabel: "Syntax language",
1302
+ copyCode: "Copy Code",
1303
+ toggleWordWrap: "Toggle Word Wrap",
1304
+ enableWordWrap: "Enable Word Wrap",
1305
+ disableWordWrap: "Disable Word Wrap",
1306
+ convertToParagraph: "Convert to Paragraph",
1307
+ deleteCodeBlock: "Delete Code Block",
1308
+ lineNumbers: "Toggle Line Numbers"
1309
+ },
1310
+ table: {
1311
+ ariaLabel: "Table actions",
1312
+ label: "Table",
1313
+ selectCells: "Select Cells",
1314
+ addRowAbove: "Add Row Above",
1315
+ addRowBelow: "Add Row Below",
1316
+ deleteRow: "Delete Row",
1317
+ addColumnLeft: "Add Column Left",
1318
+ addColumnRight: "Add Column Right",
1319
+ deleteColumn: "Delete Column",
1320
+ mergeCells: "Merge Cells",
1321
+ unmergeCells: "Unmerge Cells",
1322
+ columnWidth: "Column Width",
1323
+ rowHeight: "Row Height",
1324
+ tableBorderWidth: "Table Border Width",
1325
+ tableBorderColor: "Table Border Color",
1326
+ deleteTable: "Delete Table",
1327
+ cellAlignLeft: "Align Left",
1328
+ cellAlignCenter: "Align Center",
1329
+ cellAlignRight: "Align Right",
1330
+ cellAlignJustify: "Align Justify",
1331
+ toggleHeaderRow: "Toggle Header Row",
1332
+ cellBackground: "Cell Background",
1333
+ noShading: "No Shading",
1334
+ noBorderColor: "No Border Color",
1335
+ columnWidthPx: "Column Width (px)",
1336
+ rowHeightPx: "Row Height (px)",
1337
+ tableBorderWidthPx: "Table Border Width (px)",
1338
+ cancelBtn: "Cancel",
1339
+ applyBtn: "Apply",
1340
+ sortAsc: "Sort Ascending",
1341
+ sortDesc: "Sort Descending",
1342
+ exportCSV: "Export as CSV",
1343
+ cellPadding: "Cell Padding",
1344
+ cellPaddingPx: "Cell Padding (px)"
1345
+ },
1346
+ video: {
1347
+ ariaLabel: "Video actions",
1348
+ label: "Video",
1349
+ floatLeft: "Float Left",
1350
+ noFloat: "No Float",
1351
+ alignCenter: "Align Center",
1352
+ floatRight: "Float Right",
1353
+ originalSize: "Original Size",
1354
+ previewVideo: "Preview Video",
1355
+ exitPreview: "Exit Preview",
1356
+ deleteVideo: "Delete Video"
1357
+ }
1358
+ },
1359
+ errors: {
1360
+ imageFormat: (e) => `Format "${e}" is not supported for display in web browsers. Please convert to JPEG, PNG, or WebP first.`,
1361
+ imageSize: (e) => `Image file is too large. Maximum allowed size is ${e} MB.`
1362
+ },
1363
+ slashMenu: {
1364
+ noResults: "No matching commands",
1365
+ heading1: "Heading 1",
1366
+ heading2: "Heading 2",
1367
+ heading3: "Heading 3",
1368
+ bulletList: "Bullet List",
1369
+ numberedList: "Numbered List",
1370
+ checklist: "Checklist",
1371
+ blockquote: "Blockquote",
1372
+ codeBlock: "Code Block",
1373
+ horizontalRule: "Horizontal Rule",
1374
+ table: "Table",
1375
+ image: "Image"
1376
+ }
1377
+ }, Qt = { en: A };
1378
+ function $t(e, t) {
1379
+ if (typeof e != "string" || !e) throw TypeError("[AutumnNote] registerLocale: code must be a non-empty string.");
1380
+ if (!t || typeof t != "object") throw TypeError(`[AutumnNote] registerLocale: locale for "${e}" must be an object.`);
1381
+ Qt[e] = t;
1382
+ }
1383
+ function en(e) {
1384
+ if (!e || e === "en") return A;
1385
+ if (typeof e == "string") {
1386
+ let t = Qt[e];
1387
+ return t ? c(c({}, A), t) : (console.warn(`[AutumnNote] Locale "${e}" is not registered, falling back to English. Import it first: import { ${e} } from 'autumnnote/i18n/${e}'; AutumnNote.registerLocale('${e}', ${e});`), A);
1388
+ }
1389
+ return typeof e == "object" ? c(c({}, A), e) : A;
1390
+ }
1391
+ //#endregion
1392
+ //#region src/js/core/sanitise.js
1393
+ var tn = [
1394
+ "script",
1395
+ "style",
1396
+ "iframe",
1397
+ "object",
1398
+ "embed",
1399
+ "form",
1400
+ "base",
1401
+ "template",
1402
+ "link",
1403
+ "meta",
1404
+ "noscript",
1405
+ "portal",
1406
+ "frame",
1407
+ "frameset",
1408
+ "applet",
1409
+ "animate",
1410
+ "set",
1411
+ "animatetransform",
1412
+ "animatemotion",
1413
+ "mglyph",
1414
+ "malignmark",
1415
+ "annotation-xml"
1416
+ ], nn = /* @__PURE__ */ new Set(["button"]), rn = [
1417
+ "href",
1418
+ "src",
1419
+ "action",
1420
+ "formaction",
1421
+ "xlink:href",
1422
+ "poster",
1423
+ "background",
1424
+ "srcset"
1425
+ ], an = /* @__PURE__ */ new Set([
1426
+ "poster",
1427
+ "background",
1428
+ "srcset"
1429
+ ]), on = /* @__PURE__ */ new Set(["ping"]), sn = /* @__PURE__ */ new Set([
1430
+ "color",
1431
+ "background-color",
1432
+ "font-size",
1433
+ "line-height",
1434
+ "text-align",
1435
+ "vertical-align",
1436
+ "width",
1437
+ "min-width",
1438
+ "height",
1439
+ "min-height",
1440
+ "border-width",
1441
+ "border-style",
1442
+ "border-color",
1443
+ "padding",
1444
+ "white-space"
1445
+ ]), cn = /url\s*\(|image-set\s*\(|src\s*\(|expression\s*\(|@import|javascript:|vbscript:|behavior\s*:|-moz-binding/i, ln = /* @__PURE__ */ new Set([
1446
+ "www.youtube.com",
1447
+ "youtube.com",
1448
+ "m.youtube.com",
1449
+ "www.youtube-nocookie.com",
1450
+ "youtube-nocookie.com",
1451
+ "player.vimeo.com"
1452
+ ]), un = /* @__PURE__ */ new Set([
1453
+ "http:",
1454
+ "https:",
1455
+ "mailto:",
1456
+ "tel:"
1457
+ ]), dn = /* @__PURE__ */ new Set([
1458
+ "http:",
1459
+ "https:",
1460
+ "blob:"
1461
+ ]), fn = /^data:image\/(?:png|jpe?g|gif|webp|avif|bmp);base64,[a-z0-9+/=\s]+$/i, pn = "https://autumnnote.invalid/";
1462
+ function j(e, t) {
1463
+ return mn(e, t).innerHTML;
1464
+ }
1465
+ function mn(e, { allowIframes: t = !1 } = {}) {
1466
+ let n = new DOMParser().parseFromString(`<body>${e || ""}</body>`, "text/html"), r = Array.from(n.querySelectorAll("*")), i = new Set(t ? tn.filter((e) => e !== "iframe") : tn);
1467
+ for (let e of r) {
1468
+ let t = e.tagName.toLowerCase();
1469
+ if (nn.has(t)) {
1470
+ e.replaceWith(...e.childNodes);
1471
+ continue;
1472
+ }
1473
+ if (i.has(t)) {
1474
+ e.remove();
1475
+ continue;
1476
+ }
1477
+ if (t === "iframe") {
1478
+ let t = e.getAttribute("src");
1479
+ if (!t || !_n(t)) {
1480
+ e.remove();
1481
+ continue;
1482
+ }
1483
+ }
1484
+ for (let t of Array.from(e.attributes)) {
1485
+ if (t.name.startsWith("on")) {
1486
+ e.removeAttribute(t.name);
1487
+ continue;
1488
+ }
1489
+ if (t.name === "style") {
1490
+ let n = hn(t.value);
1491
+ n ? e.setAttribute("style", n) : e.removeAttribute("style");
1492
+ continue;
1493
+ }
1494
+ if (on.has(t.name)) {
1495
+ e.removeAttribute(t.name);
1496
+ continue;
1497
+ }
1498
+ if (rn.includes(t.name)) {
1499
+ let n = t.value.trim(), r = an.has(t.name) || t.name === "src" && [
1500
+ "IMG",
1501
+ "VIDEO",
1502
+ "AUDIO",
1503
+ "SOURCE"
1504
+ ].includes(e.tagName), i = e.tagName === "IMG";
1505
+ if (!(t.name === "srcset" ? gn(n, { allowData: i }) : vn(n, {
1506
+ media: r,
1507
+ allowData: i
1508
+ }))) {
1509
+ e.removeAttribute(t.name);
1510
+ continue;
1511
+ }
1512
+ }
1513
+ if (e.tagName === "IFRAME") {
1514
+ if (t.name === "srcdoc") {
1515
+ e.removeAttribute(t.name);
1516
+ continue;
1517
+ }
1518
+ t.name === "src" && !_n(t.value) && e.removeAttribute(t.name);
1519
+ }
1520
+ }
1521
+ if (t === "a" && e.getAttribute("target") === "_blank" && e.setAttribute("rel", "noopener noreferrer"), t === "input") if (!(e.closest("ul.an-checklist") !== null && e.closest("li") !== null) || e.getAttribute("type") !== "checkbox") e.remove();
1522
+ else for (let t of Array.from(e.attributes)) [
1523
+ "type",
1524
+ "checked",
1525
+ "contenteditable"
1526
+ ].includes(t.name) || e.removeAttribute(t.name);
1527
+ }
1528
+ return n.body;
1529
+ }
1530
+ function hn(e) {
1531
+ let t = [];
1532
+ for (let n of (e || "").split(";")) {
1533
+ let e = n.indexOf(":");
1534
+ if (e === -1) continue;
1535
+ let r = n.slice(0, e).trim().toLowerCase(), i = n.slice(e + 1).trim();
1536
+ !r || !i || sn.has(r) && (cn.test(i) || t.push(`${r}: ${i}`));
1537
+ }
1538
+ return t.join("; ");
1539
+ }
1540
+ function gn(e, { allowData: t = !1 } = {}) {
1541
+ let n = (e || "").trim().split(/\s+/).filter(Boolean);
1542
+ for (let e of n) {
1543
+ if (/^[\d.]+[xw],?$/i.test(e)) continue;
1544
+ let n = e.replace(/,+$/, "");
1545
+ if (n && !vn(n, {
1546
+ media: !0,
1547
+ allowData: t
1548
+ })) return !1;
1549
+ }
1550
+ return !0;
1551
+ }
1552
+ function _n(e) {
1553
+ let t = (e || "").trim();
1554
+ if (!t || t.startsWith("//") || t.startsWith("/")) return !1;
1555
+ try {
1556
+ let e = new URL(t);
1557
+ return e.protocol === "https:" && ln.has(e.hostname.toLowerCase());
1558
+ } catch {
1559
+ return !1;
1560
+ }
1561
+ }
1562
+ function M(e, { allowData: t = !1, media: n = t } = {}) {
1563
+ let r = (e || "").trim();
1564
+ return !r && e == null ? null : vn(r, {
1565
+ media: n,
1566
+ allowData: t
1567
+ }) ? e : null;
1568
+ }
1569
+ function vn(e, { media: t = !1, allowData: n = !1 } = {}) {
1570
+ let r = (e || "").trim();
1571
+ if (!r || n && fn.test(r)) return !0;
1572
+ try {
1573
+ let e = new URL(r, pn);
1574
+ return (t ? dn : un).has(e.protocol);
1575
+ } catch {
1576
+ return !1;
1577
+ }
1578
+ }
1579
+ //#endregion
1580
+ //#region src/js/renderer.js
1581
+ function yn(e, t) {
1582
+ let n = x("div", { class: "an-container" }), r = x("div", {
1583
+ class: "an-editable",
1584
+ contenteditable: t.readOnly ? "false" : "true",
1585
+ spellcheck: String(t.spellcheck !== !1),
1586
+ "aria-multiline": "true",
1587
+ "aria-label": "Rich text editor",
1588
+ role: "textbox"
1589
+ }), i = "";
1590
+ if (t.autoSave && t.autoSaveKey) try {
1591
+ i = localStorage.getItem(t.autoSaveKey) || "";
1592
+ } catch {}
1593
+ i ||= e.tagName === "TEXTAREA" ? (e.value || "").trim() : (e.innerHTML || "").trim(), r.innerHTML = j(i, { allowIframes: !0 });
1594
+ let a = t.defaultFontFamily || t.fontFamilies?.[0];
1595
+ return a && (r.style.fontFamily = a), t.defaultFontSize && (r.style.fontSize = t.defaultFontSize), t.height ? r.style.minHeight = `${t.height}px` : t.minHeight && (r.style.minHeight = `${t.minHeight}px`), t.maxHeight && (r.style.maxHeight = `${t.maxHeight}px`), n.appendChild(r), t.theme === "dark" ? (n.classList.add("an-theme-dark"), document.body.classList.add("an-theme-dark")) : t.theme === "auto" && (n.classList.add("an-theme-auto"), document.body.classList.add("an-theme-auto")), t.readOnly && (n.classList.add("an-disabled"), r.querySelectorAll("ul.an-checklist input[type=\"checkbox\"]").forEach((e) => {
1596
+ e.setAttribute("disabled", "");
1597
+ })), t.direction === "rtl" && (r.setAttribute("dir", "rtl"), n.classList.add("an-dir-rtl")), t.toolbarOverflow === "scroll" && n.classList.add("an-toolbar-overflow-scroll"), t.stickyToolbar && (n.classList.add("an-sticky-toolbar"), t.stickyToolbarOffset && n.style.setProperty("--an-sticky-top", `${t.stickyToolbarOffset}px`)), t.focusColor && n.style.setProperty("--an-focus-color", t.focusColor), e.style.display = "none", e.after(n), {
1598
+ container: n,
1599
+ editable: r
1600
+ };
1601
+ }
1602
+ //#endregion
1603
+ //#region src/js/Context.js
1604
+ var bn = /* @__PURE__ */ new Map(), xn = [];
1605
+ function Sn(e) {
1606
+ xn = Array.isArray(e) ? e : [];
1607
+ }
1608
+ var N = /* @__PURE__ */ new Map(), Cn = class {
1609
+ constructor(e, t = {}) {
1610
+ this.targetEl = e, this.options = c(k, t), this.locale = en(this.options.lang), this.layoutInfo = {}, this._listeners = /* @__PURE__ */ new Map(), this._modules = /* @__PURE__ */ new Map(), this._plugins = /* @__PURE__ */ new Map(), this._disposers = [], this._alive = !1, this._autoSaveTimer = null, this._pendingAutoSave = null, this._suppressedRemoteHTML = null, this._destroyPromise = null;
1611
+ }
1612
+ initialize() {
1613
+ let { container: e, editable: t } = yn(this.targetEl, this.options);
1614
+ this.layoutInfo.container = e, this.layoutInfo.editable = t, this._registerModules();
1615
+ let n = this._modules.get("toolbar");
1616
+ n?.el && (e.insertBefore(n.el, t), this.layoutInfo.toolbar = n.el);
1617
+ let r = this._modules.get("statusbar");
1618
+ return r?.el && (e.appendChild(r.el), this.layoutInfo.statusbar = r.el), this._bindEditorEvents(t), this.options.focus && t.focus(), this._alive = !0, this.invoke("toolbar.refresh"), this._applyGlobalPlugins(), typeof this.options.onInit == "function" && this.options.onInit(this), this;
1619
+ }
1620
+ _registerModules() {
1621
+ let e = (e, t) => {
1622
+ let n = new t(this);
1623
+ this._modules.set(e, n), n.initialize();
1624
+ };
1625
+ for (let { name: t, Class: n, enabled: r } of xn) typeof r == "function" && !r(this.options) || e(t, n);
1626
+ if (bn.size > 0) for (let [t, n] of bn) e(t, n);
1627
+ }
1628
+ _syncOptionalModules() {
1629
+ for (let { name: e, Class: t, enabled: n } of xn) {
1630
+ if (typeof n != "function") continue;
1631
+ let r = n(this.options);
1632
+ if (r !== this._modules.has(e)) if (r) {
1633
+ let n = new t(this);
1634
+ this._modules.set(e, n), n.initialize();
1635
+ } else {
1636
+ let t = this._modules.get(e);
1637
+ typeof t?.destroy == "function" && t.destroy(), this._modules.delete(e);
1638
+ }
1639
+ }
1640
+ }
1641
+ registerModule(e, t) {
1642
+ if (this._modules.has(e)) return this;
1643
+ let n = new t(this);
1644
+ return n.initialize(), this._modules.set(e, n), this;
1645
+ }
1646
+ registerSlashCommand(e) {
1647
+ if (!e?.id || typeof e.run != "function") throw TypeError("[AutumnNote] Slash command requires an id and run(context) function.");
1648
+ let t = this.options.slashCommands || (this.options.slashCommands = []), n = t.findIndex((t) => t.id === e.id);
1649
+ return n >= 0 ? t[n] = e : t.push(e), this.invoke("slashMenu.refresh"), this;
1650
+ }
1651
+ use(e, t = {}) {
1652
+ return Array.isArray(e.buttons) && e.buttons.forEach((e) => O(e)), this._installPlugin(e, t), this;
1653
+ }
1654
+ getPlugin(e) {
1655
+ return this._plugins.get(e)?.publicApi ?? null;
1656
+ }
1657
+ _installPlugin(e, t = {}) {
1658
+ let { name: n } = e;
1659
+ if (!n || typeof n != "string") {
1660
+ console.warn("[AutumnNote] Plugin must have a string `name` property.");
1661
+ return;
1662
+ }
1663
+ if (this._plugins.has(n)) {
1664
+ console.warn(`[AutumnNote] Plugin "${n}" already installed on this instance. Skipping.`);
1665
+ return;
1666
+ }
1667
+ let r = typeof e.install == "function" ? e.install(this, t) ?? null : null;
1668
+ this._plugins.set(n, {
1669
+ plugin: e,
1670
+ publicApi: r
1671
+ });
1672
+ }
1673
+ _applyGlobalPlugins() {
1674
+ if (N.size !== 0) for (let { plugin: e, options: t } of N.values()) this._installPlugin(e, t);
1675
+ }
1676
+ _bindEditorEvents(e) {
1677
+ let t = C(e, "input", () => this._syncToTarget()), n = C(e, "focus", () => {
1678
+ this.layoutInfo.container.classList.add("an-focused"), typeof this.options.onFocus == "function" && this.options.onFocus(this);
1679
+ }), r = C(e, "blur", () => {
1680
+ this.layoutInfo.container.classList.remove("an-focused"), this._syncToTarget(), typeof this.options.onBlur == "function" && this.options.onBlur(this);
1681
+ }), i = this.on("change", (e) => this._syncToTarget(e)), a = this.on("change", (e) => {
1682
+ if (this.options.blockIds && (this.ensureBlockIds(), e = this.getHTML()), e === this._suppressedRemoteHTML) {
1683
+ this._suppressedRemoteHTML = null;
1684
+ return;
1685
+ }
1686
+ this.options.collaborationAdapter?.onLocalChange?.(e, this);
1687
+ });
1688
+ if (this._disposers.push(t, n, r, i, a), this.options.autoSave && this.options.autoSaveKey) {
1689
+ let e = this.on("change", (e) => this._scheduleAutoSave(e));
1690
+ this._disposers.push(e);
1691
+ }
1692
+ }
1693
+ _scheduleAutoSave(e) {
1694
+ this._pendingAutoSave = e, clearTimeout(this._autoSaveTimer), this._autoSaveTimer = setTimeout(() => this.flushAutoSave(), this.options.autoSaveDelay ?? 400);
1695
+ }
1696
+ async flushAutoSave() {
1697
+ if (clearTimeout(this._autoSaveTimer), this._autoSaveTimer = null, this._pendingAutoSave == null) return;
1698
+ let e = this._pendingAutoSave;
1699
+ this._pendingAutoSave = null;
1700
+ let t = this.options.autoSaveKey, n = Date.now();
1701
+ try {
1702
+ let r = this.options.autoSaveAdapter;
1703
+ typeof r?.save == "function" ? await r.save({
1704
+ key: t,
1705
+ html: e,
1706
+ savedAt: n,
1707
+ context: this
1708
+ }) : (localStorage.setItem(t, e), localStorage.setItem(t + ":asrmeta", JSON.stringify({ savedAt: n }))), this.triggerEvent("autoSave", {
1709
+ key: t,
1710
+ html: e,
1711
+ savedAt: n
1712
+ });
1713
+ } catch (e) {
1714
+ this.triggerEvent("autoSaveError", {
1715
+ key: t,
1716
+ error: e
1717
+ });
1718
+ }
1719
+ }
1720
+ async loadAutoSave() {
1721
+ let e = this.options.autoSaveAdapter;
1722
+ if (typeof e?.load == "function") return e.load({
1723
+ key: this.options.autoSaveKey,
1724
+ context: this
1725
+ });
1726
+ try {
1727
+ return localStorage.getItem(this.options.autoSaveKey);
1728
+ } catch {
1729
+ return null;
1730
+ }
1731
+ }
1732
+ invoke(e, ...t) {
1733
+ let [n, r] = e.split("."), i = this._modules.get(n);
1734
+ if (!i) {
1735
+ console.warn(`[AutumnNote] invoke: module "${n}" not found (path: "${e}")`);
1736
+ return;
1737
+ }
1738
+ if (typeof i[r] != "function") {
1739
+ console.warn(`[AutumnNote] invoke: method "${r}" not found on module "${n}" (path: "${e}")`);
1740
+ return;
1741
+ }
1742
+ return i[r](...t);
1743
+ }
1744
+ on(e, t) {
1745
+ return this._listeners.has(e) || this._listeners.set(e, []), this._listeners.get(e).push(t), () => this.off(e, t);
1746
+ }
1747
+ off(e, t) {
1748
+ let n = this._listeners.get(e);
1749
+ if (!n) return;
1750
+ let r = n.indexOf(t);
1751
+ r !== -1 && n.splice(r, 1);
1752
+ }
1753
+ triggerEvent(e, ...t) {
1754
+ (this._listeners.get(e) || []).forEach((e) => e(...t));
1755
+ let n = "on" + e.charAt(0).toUpperCase() + e.slice(1);
1756
+ typeof this.options[n] == "function" && this.options[n](...t);
1757
+ }
1758
+ updateOptions(e = {}) {
1759
+ let t = c(this.options, e);
1760
+ Object.keys(this.options).forEach((e) => delete this.options[e]), Object.assign(this.options, t);
1761
+ let { container: n, editable: r } = this.layoutInfo;
1762
+ if (Object.hasOwn(e, "readOnly") && this.setDisabled(!!this.options.readOnly), Object.hasOwn(e, "spellcheck") && (r.spellcheck = this.options.spellcheck !== !1), Object.hasOwn(e, "placeholder") && (r.dataset.placeholder = this.options.placeholder || ""), Object.hasOwn(e, "direction")) {
1763
+ let e = this.options.direction === "rtl";
1764
+ r.setAttribute("dir", e ? "rtl" : "ltr"), n.classList.toggle("an-dir-rtl", e);
1765
+ }
1766
+ if (Object.hasOwn(e, "height") || Object.hasOwn(e, "minHeight")) {
1767
+ let e = this.options.height || this.options.minHeight || 0;
1768
+ r.style.minHeight = e ? `${e}px` : "";
1769
+ }
1770
+ return Object.hasOwn(e, "maxHeight") && (r.style.maxHeight = this.options.maxHeight ? `${this.options.maxHeight}px` : ""), Object.hasOwn(e, "toolbar") && this.invoke("toolbar.rebuild"), this._syncOptionalModules(), this.invoke("statusbar.update"), this.triggerEvent("optionsChange", { ...e }), this;
1771
+ }
1772
+ getHTML() {
1773
+ let e = this.invoke("editor.getHTML");
1774
+ return typeof e == "string" ? e.replace(/​/g, "") : e;
1775
+ }
1776
+ setHTML(e) {
1777
+ this.invoke("editor.setHTML", e);
1778
+ }
1779
+ getText() {
1780
+ return this.invoke("editor.getText");
1781
+ }
1782
+ setText(e) {
1783
+ this.invoke("editor.setText", e);
1784
+ }
1785
+ clear() {
1786
+ this.invoke("editor.clear");
1787
+ }
1788
+ clearHistory() {
1789
+ this.invoke("editor.clearHistory");
1790
+ }
1791
+ getUndoCount() {
1792
+ return this.invoke("editor.getUndoCount") ?? 0;
1793
+ }
1794
+ getRedoCount() {
1795
+ return this.invoke("editor.getRedoCount") ?? 0;
1796
+ }
1797
+ isEmpty() {
1798
+ return this.invoke("editor.isEmpty");
1799
+ }
1800
+ insertHTML(e) {
1801
+ this.invoke("editor.insertHTML", e);
1802
+ }
1803
+ insertText(e) {
1804
+ this.invoke("editor.insertText", e);
1805
+ }
1806
+ setMarkdown(e) {
1807
+ this.invoke("editor.setMarkdown", e);
1808
+ }
1809
+ getMarkdown() {
1810
+ return this.invoke("editor.getMarkdown");
1811
+ }
1812
+ getSelectionBookmark() {
1813
+ return this.invoke("editor.getSelectionBookmark") ?? null;
1814
+ }
1815
+ restoreSelectionBookmark(e) {
1816
+ return this.invoke("editor.restoreSelectionBookmark", e);
1817
+ }
1818
+ async importDocument(e, t) {
1819
+ let n = this.options.documentAdapters?.[e], r;
1820
+ if (typeof n?.import == "function") r = await n.import(t, this);
1821
+ else if (e === "html") r = String(t ?? "");
1822
+ else if (e === "markdown") return this.setMarkdown(String(t ?? "")), this;
1823
+ else if (e === "text") return this.setText(String(t ?? "")), this;
1824
+ else throw Error(`[AutumnNote] No importer registered for "${e}".`);
1825
+ return this.setHTML(r), this;
1826
+ }
1827
+ async exportDocument(e) {
1828
+ let t = this.options.documentAdapters?.[e];
1829
+ if (typeof t?.export == "function") return t.export(this, this.getHTML());
1830
+ if (e === "html") return this.getHTML();
1831
+ if (e === "markdown") return this.getMarkdown();
1832
+ if (e === "text") return this.getText();
1833
+ throw Error(`[AutumnNote] No exporter registered for "${e}".`);
1834
+ }
1835
+ ensureBlockIds() {
1836
+ let e = this.layoutInfo.editable.children;
1837
+ for (let t of e) if (!t.hasAttribute("data-an-block-id")) {
1838
+ let e = globalThis.crypto?.randomUUID?.() || `an-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1839
+ t.setAttribute("data-an-block-id", e);
1840
+ }
1841
+ return this;
1842
+ }
1843
+ getDocument() {
1844
+ return this.options.blockIds && this.ensureBlockIds(), {
1845
+ version: 1,
1846
+ html: this.getHTML(),
1847
+ markdown: this.getMarkdown()
1848
+ };
1849
+ }
1850
+ loadDocument(e) {
1851
+ return this.setHTML(e?.html || ""), this.clearHistory(), this;
1852
+ }
1853
+ applyRemoteHTML(e) {
1854
+ return this.setHTML(e), this._suppressedRemoteHTML = this.getHTML(), this.clearHistory(), this;
1855
+ }
1856
+ getWordCount() {
1857
+ return this.invoke("statusbar.getWordCount") ?? 0;
1858
+ }
1859
+ getCharCount() {
1860
+ return this.invoke("statusbar.getCharCount") ?? 0;
1861
+ }
1862
+ downloadHTML(e = "document.html") {
1863
+ this._download(this.getHTML(), e, "text/html");
1864
+ }
1865
+ downloadText(e = "document.txt") {
1866
+ this._download(this.getText(), e, "text/plain");
1867
+ }
1868
+ downloadMarkdown(e = "document.md") {
1869
+ this._download(this.getMarkdown(), e, "text/markdown");
1870
+ }
1871
+ _download(e, t, n) {
1872
+ let r = new Blob([e], { type: n }), i = URL.createObjectURL(r), a = document.createElement("a");
1873
+ a.href = i, a.download = t, a.style.display = "none", document.body.appendChild(a), a.click(), a.remove(), URL.revokeObjectURL(i);
1874
+ }
1875
+ print(e = "") {
1876
+ let t = this.getHTML(), n = `<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>${(e || "").replace(/[<>&"']/g, (e) => `&#${e.charCodeAt(0)};`)}</title><style>body{font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;font-size:14px;line-height:1.6;padding:20mm;color:#111827;}ul.an-checklist{list-style:none;padding-left:0;}ul.an-checklist li{padding-left:24px;position:relative;margin:2px 0;}ul.an-checklist li input[type="checkbox"]{position:absolute;left:0;top:3px;}code{background:#f3f4f6;border-radius:3px;padding:.1em .35em;font-family:monospace;}pre{background:#f3f4f6;padding:.75em 1em;border-radius:4px;overflow-x:auto;}table{border-collapse:collapse;}td,th{border:1px solid #d1d5db;padding:4px 8px;}</style></head><body>${t}</body></html>`, r = new Blob([n], { type: "text/html" }), i = URL.createObjectURL(r), a = globalThis.open(i, "_blank");
1877
+ if (!a) {
1878
+ URL.revokeObjectURL(i);
1879
+ return;
1880
+ }
1881
+ a.addEventListener("load", () => {
1882
+ a.print(), URL.revokeObjectURL(i);
1883
+ });
1884
+ }
1885
+ getTableOfContents() {
1886
+ return Array.from(this.layoutInfo.editable.querySelectorAll("h1,h2,h3,h4,h5,h6")).map((e) => ({
1887
+ level: parseInt(e.tagName[1], 10),
1888
+ text: e.textContent?.trim() ?? "",
1889
+ element: e
1890
+ }));
1891
+ }
1892
+ focus() {
1893
+ this.layoutInfo.editable.focus();
1894
+ }
1895
+ blur() {
1896
+ this.layoutInfo.editable.blur();
1897
+ }
1898
+ isFullscreen() {
1899
+ return this.invoke("fullscreen.isActive") === !0;
1900
+ }
1901
+ setDisabled(e) {
1902
+ let t = this.layoutInfo.editable;
1903
+ e ? (t.setAttribute("contenteditable", "false"), this.layoutInfo.container.classList.add("an-disabled"), t.querySelectorAll("ul.an-checklist input[type=\"checkbox\"]").forEach((e) => {
1904
+ e.setAttribute("disabled", "");
1905
+ })) : (t.setAttribute("contenteditable", "true"), this.layoutInfo.container.classList.remove("an-disabled"), t.querySelectorAll("ul.an-checklist input[type=\"checkbox\"]").forEach((e) => {
1906
+ e.removeAttribute("disabled");
1907
+ }));
1908
+ }
1909
+ destroy() {
1910
+ if (!this._alive) return this._destroyPromise ?? Promise.resolve();
1911
+ let e = this._pendingAutoSave == null ? null : this.flushAutoSave().catch(() => {});
1912
+ this._modules.forEach((e) => {
1913
+ typeof e.destroy == "function" && e.destroy();
1914
+ }), this._modules.clear();
1915
+ for (let { plugin: e } of this._plugins.values()) if (typeof e.uninstall == "function") try {
1916
+ e.uninstall(this);
1917
+ } catch {}
1918
+ this._plugins.clear(), this._disposers.forEach((e) => e()), this._disposers = [];
1919
+ let t = this.layoutInfo.container, n = t?.classList.contains("an-theme-dark"), r = t?.classList.contains("an-theme-auto");
1920
+ return t?.parentNode && (this.targetEl.style.display = "", t.remove()), n && !document.querySelector(".an-container.an-theme-dark") && document.body.classList.remove("an-theme-dark"), r && !document.querySelector(".an-container.an-theme-auto") && document.body.classList.remove("an-theme-auto"), typeof this.options.onDestroy == "function" && this.options.onDestroy(this), this._alive = !1, this._destroyPromise = Promise.resolve(e).then(() => {
1921
+ this._listeners.clear();
1922
+ }), this._destroyPromise;
1923
+ }
1924
+ _syncToTarget(e) {
1925
+ (this.targetEl.tagName === "TEXTAREA" || this.targetEl.tagName === "INPUT") && (this.targetEl.value = typeof e == "string" ? e : this.getHTML());
1926
+ }
1927
+ }, wn = class {
1928
+ constructor(e, t = 100, n = 10 * 1024 * 1024) {
1929
+ this.editable = e, this._limit = t, this._maxBytes = n, this._bytes = 0, this.stack = [], this.stackOffset = -1, this._savePoint();
1930
+ }
1931
+ _entrySize(e) {
1932
+ let t = e.html.length;
1933
+ if (e.images) for (let n in e.images) t += e.images[n].length;
1934
+ return t;
1935
+ }
1936
+ _serialize() {
1937
+ return this.editable.innerHTML;
1938
+ }
1939
+ _serializeSelection() {
1940
+ let e = globalThis.getSelection();
1941
+ if (!e || e.rangeCount === 0) return null;
1942
+ let t = e.getRangeAt(0);
1943
+ return this.editable.contains(t.startContainer) ? {
1944
+ start: this._charOffset(t.startContainer, t.startOffset),
1945
+ end: this._charOffset(t.endContainer, t.endOffset)
1946
+ } : null;
1947
+ }
1948
+ _charOffset(e, t) {
1949
+ let n = 0, r = document.createTreeWalker(this.editable, NodeFilter.SHOW_TEXT, null), i;
1950
+ for (; i = r.nextNode();) {
1951
+ if (i === e) return n + t;
1952
+ n += i.length;
1953
+ }
1954
+ return 0;
1955
+ }
1956
+ _restoreSelection(e) {
1957
+ if (!e) return;
1958
+ let t = null, n = 0, r = null, i = 0, a = 0, o = document.createTreeWalker(this.editable, NodeFilter.SHOW_TEXT, null), s;
1959
+ for (; s = o.nextNode();) {
1960
+ let o = s.length;
1961
+ if (!t && a + o >= e.start && (t = s, n = e.start - a), !r && a + o >= e.end) {
1962
+ r = s, i = e.end - a;
1963
+ break;
1964
+ }
1965
+ a += o;
1966
+ }
1967
+ if (!t) {
1968
+ let e = document.createTreeWalker(this.editable, NodeFilter.SHOW_TEXT, null), a = null;
1969
+ for (; a = e.nextNode();) t = a;
1970
+ n = t ? t.length : 0, r = t, i = n;
1971
+ }
1972
+ r || (r = t, i = n);
1973
+ try {
1974
+ let e = document.createRange();
1975
+ e.setStart(t, n), e.setEnd(r, i);
1976
+ let a = globalThis.getSelection();
1977
+ a.removeAllRanges(), a.addRange(e);
1978
+ } catch {
1979
+ try {
1980
+ let e = document.createRange();
1981
+ e.setStart(this.editable, 0), e.collapse(!0);
1982
+ let t = globalThis.getSelection();
1983
+ t && (t.removeAllRanges(), t.addRange(e));
1984
+ } catch {}
1985
+ }
1986
+ }
1987
+ _savePoint() {
1988
+ if (this.stackOffset < this.stack.length - 1) {
1989
+ for (let e of this.stack.slice(this.stackOffset + 1)) this._bytes -= this._entrySize(e);
1990
+ this.stack = this.stack.slice(0, this.stackOffset + 1);
1991
+ }
1992
+ let e = this._serialize(), { html: t, images: n } = this._tokenizeImages(e), r = {
1993
+ html: t,
1994
+ images: n,
1995
+ sel: this._serializeSelection()
1996
+ };
1997
+ for (this.stack.push(r), this._bytes += this._entrySize(r); this.stack.length > 1 && (this.stack.length > this._limit || this._bytes > this._maxBytes);) this._bytes -= this._entrySize(this.stack.shift());
1998
+ this.stackOffset = this.stack.length - 1;
1999
+ }
2000
+ _restore(e) {
2001
+ e && (this.editable.innerHTML = this._detokenizeImages(e), this._restoreSelection(e.sel));
2002
+ }
2003
+ _tokenizeImages(e) {
2004
+ if (!e.includes("data:")) return {
2005
+ html: e,
2006
+ images: {}
2007
+ };
2008
+ let t = {}, n = 0;
2009
+ return {
2010
+ html: e.replace(/data:[^;]+;base64,[^"' >]*/g, (e) => {
2011
+ let r = `__asn_img_${n}__`;
2012
+ return t[r] = e, n++, r;
2013
+ }),
2014
+ images: t
2015
+ };
2016
+ }
2017
+ _detokenizeImages(e) {
2018
+ return !e.images || Object.keys(e.images).length === 0 ? e.html : e.html.replace(/__asn_img_\d+__/g, (t) => e.images[t] || t);
2019
+ }
2020
+ recordUndo() {
2021
+ let e = this._serialize(), { html: t } = this._tokenizeImages(e);
2022
+ this.stack[this.stackOffset]?.html !== t && this._savePoint();
2023
+ }
2024
+ undo() {
2025
+ this.stackOffset <= 0 || (this.stackOffset--, this._restore(this.stack[this.stackOffset]));
2026
+ }
2027
+ redo() {
2028
+ this.stackOffset >= this.stack.length - 1 || (this.stackOffset++, this._restore(this.stack[this.stackOffset]));
2029
+ }
2030
+ reset() {
2031
+ this.stack = [], this.stackOffset = -1, this._bytes = 0, this._savePoint();
2032
+ }
2033
+ canUndo() {
2034
+ return this.stackOffset > 0;
2035
+ }
2036
+ canRedo() {
2037
+ return this.stackOffset < this.stack.length - 1;
2038
+ }
2039
+ getUndoCount() {
2040
+ return Math.max(0, this.stackOffset);
2041
+ }
2042
+ getRedoCount() {
2043
+ return Math.max(0, this.stack.length - 1 - this.stackOffset);
2044
+ }
2045
+ };
2046
+ //#endregion
2047
+ //#region src/js/editing/Table.js
2048
+ function Tn(e, t, n = {}) {
2049
+ let { headerRow: r = !1 } = n, i = x("table", { class: "an-table" });
2050
+ if (r && t > 0) {
2051
+ let t = x("thead"), n = x("tr");
2052
+ for (let t = 0; t < e; t++) {
2053
+ let e = x("th", {}, [document.createElement("br")]);
2054
+ n.appendChild(e);
2055
+ }
2056
+ t.appendChild(n), i.appendChild(t);
2057
+ }
2058
+ let a = r ? Math.max(t - 1, 1) : t, o = x("tbody");
2059
+ i.appendChild(o);
2060
+ for (let t = 0; t < a; t++) {
2061
+ let t = x("tr");
2062
+ for (let n = 0; n < e; n++) {
2063
+ let e = x("td", {}, [document.createElement("br")]);
2064
+ t.appendChild(e);
2065
+ }
2066
+ o.appendChild(t);
2067
+ }
2068
+ return i;
2069
+ }
2070
+ function En(e, t, n = {}) {
2071
+ if (e <= 0 || t <= 0) return;
2072
+ let r = Tn(e, t, n), i = globalThis.getSelection();
2073
+ if (!i || i.rangeCount === 0) return;
2074
+ let a = i.getRangeAt(0);
2075
+ try {
2076
+ a.deleteContents();
2077
+ } catch {
2078
+ return;
2079
+ }
2080
+ let o = /* @__PURE__ */ new Set([
2081
+ "P",
2082
+ "DIV",
2083
+ "H1",
2084
+ "H2",
2085
+ "H3",
2086
+ "H4",
2087
+ "H5",
2088
+ "H6",
2089
+ "BLOCKQUOTE",
2090
+ "LI",
2091
+ "PRE"
2092
+ ]), s = a.startContainer;
2093
+ for (s?.nodeType === 3 && (s = s.parentElement); s && !o.has(s.tagName?.toUpperCase()) && s.parentElement;) s = s.parentElement;
2094
+ if (s && o.has(s.tagName?.toUpperCase()) && s.parentNode) {
2095
+ if (s.after(r), !r.nextElementSibling) {
2096
+ let e = document.createElement("p");
2097
+ e.appendChild(document.createElement("br")), r.after(e);
2098
+ }
2099
+ !s.textContent.trim() && !s.querySelector("img, video, table") && s.remove();
2100
+ } else try {
2101
+ a.insertNode(r);
2102
+ } catch {
2103
+ return;
2104
+ }
2105
+ let c = r.querySelector("td, th");
2106
+ if (c) {
2107
+ let e = document.createRange();
2108
+ e.setStart(c, 0), e.collapse(!0), i.removeAllRanges(), i.addRange(e);
2109
+ }
2110
+ }
2111
+ //#endregion
2112
+ //#region src/js/core/key.js
2113
+ var P = {
2114
+ BACKSPACE: "Backspace",
2115
+ TAB: "Tab",
2116
+ ENTER: "Enter",
2117
+ ESCAPE: "Escape",
2118
+ SPACE: " ",
2119
+ PAGE_UP: "PageUp",
2120
+ PAGE_DOWN: "PageDown",
2121
+ END: "End",
2122
+ HOME: "Home",
2123
+ LEFT: "ArrowLeft",
2124
+ UP: "ArrowUp",
2125
+ RIGHT: "ArrowRight",
2126
+ DOWN: "ArrowDown",
2127
+ DELETE: "Delete",
2128
+ NUM0: "0",
2129
+ NUM1: "1",
2130
+ NUM2: "2",
2131
+ NUM3: "3",
2132
+ NUM4: "4",
2133
+ NUM5: "5",
2134
+ NUM6: "6",
2135
+ NUM7: "7",
2136
+ NUM8: "8",
2137
+ B: "b",
2138
+ E: "e",
2139
+ I: "i",
2140
+ J: "j",
2141
+ K: "k",
2142
+ L: "l",
2143
+ R: "r",
2144
+ S: "s",
2145
+ U: "u",
2146
+ V: "v",
2147
+ Y: "y",
2148
+ Z: "z",
2149
+ SLASH: "/",
2150
+ PERIOD: "."
2151
+ };
2152
+ function F(e, t) {
2153
+ return e.key === t || e.key === t.toUpperCase();
2154
+ }
2155
+ function I(e, t) {
2156
+ return (e.ctrlKey || e.metaKey) && F(e, t);
2157
+ }
2158
+ //#endregion
2159
+ //#region src/js/editing/Typing.js
2160
+ var Dn = /\bfa-/, L = (e) => !!(e?.nodeName === "I" && Dn.test(e.className || "")), R = (e) => e?.nodeType === Node.TEXT_NODE && (e.textContent === "​" || e.textContent === "");
2161
+ function On(e, t) {
2162
+ try {
2163
+ let n = document.createRange();
2164
+ return n.setStart(e.startContainer, e.startOffset), n.setEnd(t, t.childNodes.length), n.extractContents();
2165
+ } catch {
2166
+ return document.createDocumentFragment();
2167
+ }
2168
+ }
2169
+ function kn(e, t, n = {}) {
2170
+ let r = (e) => {
2171
+ let t = globalThis.getSelection();
2172
+ if (!t) return !1;
2173
+ let n = document.createRange();
2174
+ return e(n), n.collapse(!0), t.removeAllRanges(), t.addRange(n), !0;
2175
+ };
2176
+ if (F(e, P.BACKSPACE)) {
2177
+ let t = globalThis.getSelection();
2178
+ if (t?.rangeCount > 0) {
2179
+ let n = t.getRangeAt(0);
2180
+ if (n.collapsed && n.startContainer.nodeType === Node.TEXT_NODE) {
2181
+ let r = n.startContainer;
2182
+ if (n.startOffset === 0 && L(r.previousSibling)) return e.preventDefault(), r.previousSibling.remove(), !0;
2183
+ if (n.startOffset === 1 && r.textContent === "​" && L(r.previousSibling)) {
2184
+ e.preventDefault();
2185
+ let n = r.parentNode, i = r.previousSibling, a = i.previousSibling;
2186
+ i.remove(), r.remove();
2187
+ let o = document.createRange();
2188
+ return a?.nodeType === Node.TEXT_NODE ? o.setStart(a, a.textContent.length) : a ? o.setStartAfter(a) : n && o.setStart(n, 0), o.collapse(!0), t.removeAllRanges(), t.addRange(o), !0;
2189
+ }
2190
+ }
2191
+ }
2192
+ return !1;
2193
+ }
2194
+ if (F(e, P.LEFT) || F(e, P.RIGHT)) {
2195
+ let t = globalThis.getSelection();
2196
+ if (!t || t.rangeCount === 0) return !1;
2197
+ let n = t.getRangeAt(0);
2198
+ if (!n.collapsed) return !1;
2199
+ let i = n.startContainer, a = F(e, P.LEFT);
2200
+ if (i.nodeType === Node.TEXT_NODE) {
2201
+ let t = i;
2202
+ if (a && n.startOffset === 1 && t.textContent === "​" && L(t.previousSibling) || a && n.startOffset === 0 && L(t.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(t.previousSibling));
2203
+ if (a && n.startOffset === 0 && R(t.previousSibling) && L(t.previousSibling.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(t.previousSibling.previousSibling));
2204
+ if (!a && n.startOffset === t.textContent.length && L(t.nextSibling)) {
2205
+ let n = t.nextSibling, i = n.nextSibling;
2206
+ if (e.preventDefault(), i?.nodeType === Node.TEXT_NODE) {
2207
+ let e = +!!(i.textContent || "").startsWith("​");
2208
+ return r((t) => t.setStart(i, Math.min(e, i.textContent.length)));
2209
+ }
2210
+ return r((e) => e.setStartAfter(n));
2211
+ }
2212
+ if (!a && n.startOffset === t.textContent.length && R(t.nextSibling) && L(t.nextSibling.nextSibling)) {
2213
+ let n = t.nextSibling.nextSibling, i = n.nextSibling;
2214
+ if (e.preventDefault(), i?.nodeType === Node.TEXT_NODE) {
2215
+ let e = +!!(i.textContent || "").startsWith("​");
2216
+ return r((t) => t.setStart(i, Math.min(e, i.textContent.length)));
2217
+ }
2218
+ return r((e) => e.setStartAfter(n));
2219
+ }
2220
+ }
2221
+ if (i.nodeType === Node.ELEMENT_NODE) {
2222
+ let t = i;
2223
+ if (a && n.startOffset > 0) {
2224
+ let i = t.childNodes[n.startOffset - 1];
2225
+ if (L(i)) return e.preventDefault(), r((e) => e.setStartBefore(i));
2226
+ if (R(i) && L(i.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(i.previousSibling));
2227
+ }
2228
+ if (!a && n.startOffset < t.childNodes.length) {
2229
+ let i = t.childNodes[n.startOffset];
2230
+ if (L(i)) {
2231
+ let t = i.nextSibling;
2232
+ if (e.preventDefault(), t?.nodeType === Node.TEXT_NODE) {
2233
+ let e = +!!(t.textContent || "").startsWith("​");
2234
+ return r((n) => n.setStart(t, Math.min(e, t.textContent.length)));
2235
+ }
2236
+ return r((e) => e.setStartAfter(i));
2237
+ }
2238
+ if (R(i) && L(i.nextSibling)) {
2239
+ let t = i.nextSibling, n = t.nextSibling;
2240
+ if (e.preventDefault(), n?.nodeType === Node.TEXT_NODE) {
2241
+ let e = +!!(n.textContent || "").startsWith("​");
2242
+ return r((t) => t.setStart(n, Math.min(e, n.textContent.length)));
2243
+ }
2244
+ return r((e) => e.setStartAfter(t));
2245
+ }
2246
+ }
2247
+ }
2248
+ }
2249
+ if (F(e, P.TAB)) {
2250
+ let r = xe(t);
2251
+ if (!r) return !1;
2252
+ let i = b(r.sc, t);
2253
+ if (i && ee(i)) return e.preventDefault(), e.shiftKey ? Qe() : w("indent"), !0;
2254
+ if (i?.nodeName.toUpperCase() === "PRE") return e.shiftKey ? !1 : (e.preventDefault(), w("insertText", " ".repeat(n.tabSize || 4)), !0);
2255
+ if (n.tabSize) return e.shiftKey ? !1 : (e.preventDefault(), w("insertText", " ".repeat(n.tabSize)), !0);
2256
+ }
2257
+ if (F(e, P.ENTER) && e.shiftKey) return e.preventDefault(), w("insertLineBreak"), !0;
2258
+ if (F(e, P.ENTER) && !e.shiftKey) {
2259
+ let n = xe(t);
2260
+ if (!n) return !1;
2261
+ let r = n.sc, i = r.nodeType === 3 ? r.parentElement : r;
2262
+ if (i?.nodeName === "I" && /\bfa-/.test(i.className || "")) {
2263
+ let e = document.createRange();
2264
+ e.setStartAfter(i), e.collapse(!0);
2265
+ let t = globalThis.getSelection();
2266
+ return t && (t.removeAllRanges(), t.addRange(e)), !1;
2267
+ }
2268
+ let a = i?.closest(".an-video-wrapper");
2269
+ if (a) {
2270
+ e.preventDefault();
2271
+ let t = document.createElement("p");
2272
+ t.innerHTML = "\xA0", a.parentNode.insertBefore(t, a.nextSibling);
2273
+ let n = document.createRange();
2274
+ n.setStart(t, 0), n.collapse(!0);
2275
+ let r = globalThis.getSelection();
2276
+ return r.removeAllRanges(), r.addRange(n), !0;
2277
+ }
2278
+ let o = i?.closest(".an-checklist li");
2279
+ if (o) {
2280
+ e.preventDefault();
2281
+ let t = o.closest(".an-checklist"), n = globalThis.getSelection(), r = n.getRangeAt(0);
2282
+ if (!((e) => Array.from(e.childNodes).filter((e) => !(e.nodeType === 1 && e.tagName === "INPUT")).map((e) => e.textContent).join("").replace(/[\u00a0\u200B]/g, " ").trim())(o)) {
2283
+ let e = document.createElement("p");
2284
+ e.innerHTML = "\xA0", t.parentNode.insertBefore(e, t.nextSibling), o.remove(), t.children.length === 0 && t.remove();
2285
+ let r = document.createRange();
2286
+ return r.setStart(e.firstChild, 0), r.collapse(!0), n.removeAllRanges(), n.addRange(r), !0;
2287
+ }
2288
+ if (!r.collapsed) {
2289
+ if (r.deleteContents(), n.rangeCount === 0 || !o.isConnected) return !0;
2290
+ r = n.getRangeAt(0);
2291
+ }
2292
+ let i = On(r, o), a = document.createElement("li"), s = document.createElement("input");
2293
+ s.type = "checkbox", s.setAttribute("contenteditable", "false"), a.appendChild(s), i.textContent.replace(/[\u00a0\u200B]/g, "").length > 0 && a.appendChild(i);
2294
+ let c = a.childNodes[1];
2295
+ c?.nodeType !== Node.TEXT_NODE && (c = document.createTextNode("​"), a.appendChild(c)), o.after(a);
2296
+ let l = document.createRange();
2297
+ return l.setStart(c, 0), l.collapse(!0), n.removeAllRanges(), n.addRange(l), !0;
2298
+ }
2299
+ let s = b(n.sc, t);
2300
+ if (s?.nodeName.toUpperCase() === "PRE") return e.preventDefault(), w("insertText", "\n"), !0;
2301
+ if (s?.nodeName.toUpperCase() === "BLOCKQUOTE") {
2302
+ let t = n.toNativeRange();
2303
+ if (t.setEnd(s, s.childNodes.length), t.toString() === "" && n.isCollapsed()) return e.preventDefault(), w("formatBlock", "<p>"), !0;
2304
+ }
2305
+ }
2306
+ return !1;
2307
+ }
2308
+ //#endregion
2309
+ //#region src/js/core/markdown.js
2310
+ function An(e) {
2311
+ return Ln(new DOMParser().parseFromString(`<body>${e || ""}</body>`, "text/html").body).replace(/\n{3,}/g, "\n\n").trim();
2312
+ }
2313
+ function z(e, t) {
2314
+ return Array.from(e.children).filter((e) => e.tagName === t.toUpperCase());
2315
+ }
2316
+ function jn(e) {
2317
+ let t = "";
2318
+ for (let n of e.childNodes) {
2319
+ if (n.nodeType === 3) {
2320
+ t += n.textContent;
2321
+ continue;
2322
+ }
2323
+ if (n.nodeType !== 1) continue;
2324
+ let e = n.nodeName.toLowerCase();
2325
+ if (e === "br") {
2326
+ t += "\n";
2327
+ continue;
2328
+ }
2329
+ if (e === "div" || e === "p") {
2330
+ t && !t.endsWith("\n") && (t += "\n"), t += jn(n), t += "\n";
2331
+ continue;
2332
+ }
2333
+ t += jn(n);
2334
+ }
2335
+ return t;
2336
+ }
2337
+ function Mn(e) {
2338
+ return e.replaceAll("\\", "\\\\").replace(/&(?=#\d+;|#[xX][0-9a-fA-F]+;|[a-zA-Z][a-zA-Z0-9]*;)/g, "&amp;").replace(/!(?=\[)/g, String.raw`\!`).replace(/([`*[\]])/g, String.raw`\$1`).replace(/(?<!\w)_|_(?!\w)/g, String.raw`\_`).replace(/~(?=~)|(?<=~)~/g, String.raw`\~`);
2339
+ }
2340
+ function Nn(e) {
2341
+ return /^\s*(?:-{2,}|={2,}|\*{3,}|_{3,}|(?:[-*_] +){2,}[-*_])\s*$/.test(e) ? e.replace(/[-=*_]/, (e) => `\\${e}`) : e.replace(/^(\s*)(#{1,6})(?=\s|$)/, (e, t, n) => `${t}\\${n}`).replace(/^(\s*)>/, (e, t) => `${t}\\>`).replace(/^(\s*)([-*+])(?=\s)/, (e, t, n) => `${t}\\${n}`).replace(/^(\s*)(\d+)([.)])(?=\s)/, (e, t, n, r) => `${t}${n}\\${r}`);
2342
+ }
2343
+ function Pn(e) {
2344
+ return e.split("\n").map(Nn).join("\n");
2345
+ }
2346
+ function Fn(e, t) {
2347
+ let n = " ".repeat(t + 1);
2348
+ return Ln(e, t + 1).trim().split("\n").map((e, t) => t === 0 || e.trim() === "" || e.startsWith(n) ? e : n + e).join("\n");
2349
+ }
2350
+ function In(e, t) {
2351
+ let n = e.getAttribute(t) || "", r = /[\s()]/.test(n) ? `<${n}>` : n, i = e.getAttribute("title");
2352
+ return i ? `${r} "${i.replaceAll("\"", String.raw`\"`)}"` : r;
2353
+ }
2354
+ function Ln(e, t = 0) {
2355
+ if (e.nodeType === 3) {
2356
+ let t = e.textContent.replace(/\s+/g, " ");
2357
+ return e.parentElement?.closest("pre, code") ? t : Mn(t);
2358
+ }
2359
+ if (e.nodeType !== 1) return "";
2360
+ let n = e, r = n.nodeName.toLowerCase(), i = () => Array.from(n.childNodes).map((e) => Ln(e, t)).join("");
2361
+ switch (r) {
2362
+ case "p":
2363
+ case "div": return `\n\n${Pn(i())}\n\n`;
2364
+ case "br": return " \n";
2365
+ case "h1": return `\n\n# ${i()}\n\n`;
2366
+ case "h2": return `\n\n## ${i()}\n\n`;
2367
+ case "h3": return `\n\n### ${i()}\n\n`;
2368
+ case "h4": return `\n\n#### ${i()}\n\n`;
2369
+ case "h5": return `\n\n##### ${i()}\n\n`;
2370
+ case "h6": return `\n\n###### ${i()}\n\n`;
2371
+ case "strong":
2372
+ case "b": return `**${i()}**`;
2373
+ case "em":
2374
+ case "i": return `*${i()}*`;
2375
+ case "del":
2376
+ case "s":
2377
+ case "strike": return `~~${i()}~~`;
2378
+ case "sup": return `^${i()}^`;
2379
+ case "sub": return `~${i()}~`;
2380
+ case "u": return `<u>${i()}</u>`;
2381
+ case "span": {
2382
+ let e = n.getAttribute("style") || "";
2383
+ return /\b(color|background-color|font-size)\s*:/.test(e) ? `<span style="${q(e)}">${i()}</span>` : i();
2384
+ }
2385
+ case "code": {
2386
+ if (n.closest("pre")) return i();
2387
+ let e = i(), t = Math.max(0, ...Array.from(e.matchAll(/`+/g), (e) => e[0].length)), r = "`".repeat(t + 1), a = /^`|`$/.test(e) ? " " : "";
2388
+ return `${r}${a}${e}${a}${r}`;
2389
+ }
2390
+ case "pre": {
2391
+ let e = n.querySelector("code"), t = /language-(\S+)/.exec(e?.className || "");
2392
+ return `\n\n\`\`\`${t ? t[1] : ""}\n${jn(e || n).replace(/\n$/, "")}\n\`\`\`\n\n`;
2393
+ }
2394
+ case "blockquote": {
2395
+ let e = i().trim().split("\n");
2396
+ return `\n\n${e.filter((t, n) => t.trim() !== "" || (e[n - 1] ?? "").trim() !== "").map((e) => e.trim() === "" ? ">" : `> ${e}`).join("\n")}\n\n`;
2397
+ }
2398
+ case "a": return `[${i()}](${In(n, "href")})`;
2399
+ case "img": return `![${Mn(n.getAttribute("alt") || "")}](${In(n, "src")})`;
2400
+ case "ul": {
2401
+ let e = z(n, "li");
2402
+ if (!e.length) return i();
2403
+ let r = " ".repeat(t), a = n.classList.contains("an-checklist"), o = e.map((e) => {
2404
+ let n = z(e, "input").find((e) => e.getAttribute("type") === "checkbox"), i = "- ";
2405
+ return (a || n) && (i = n && n.checked ? "- [x] " : "- [ ] "), `${r}${i}${Fn(e, t)}`;
2406
+ }).join("\n");
2407
+ return t === 0 ? `\n\n${o}\n\n` : `\n${o}`;
2408
+ }
2409
+ case "ol": {
2410
+ let e = z(n, "li");
2411
+ if (!e.length) return i();
2412
+ let r = " ".repeat(t), a = Number.parseInt(n.getAttribute("start") || "1", 10), o = Number.isFinite(a) ? a : 1, s = e.map((e, n) => `${r}${o + n}. ${Fn(e, t)}`).join("\n");
2413
+ return t === 0 ? `\n\n${s}\n\n` : `\n${s}`;
2414
+ }
2415
+ case "li": return i();
2416
+ case "hr": return "\n\n---\n\n";
2417
+ case "table": {
2418
+ let e = Array.from(n.querySelectorAll("tr"));
2419
+ if (!e.length) return i();
2420
+ let t = !!z(n, "thead")[0] || e[0].children.length > 0 && Array.from(e[0].children).every((e) => e.tagName === "TH"), r = e.map((e) => Array.from(e.querySelectorAll("th, td")).map((e) => Mn(e.textContent.trim()).replaceAll("|", String.raw`\|`))), a = Math.max(...r.map((e) => e.length)), o = (e) => {
2421
+ let t = [...e];
2422
+ for (; t.length < a;) t.push("");
2423
+ return t;
2424
+ }, s = +!!t, c = t ? o(r[0]) : Array(a).fill(""), l = Array.from({ length: a }, (t, n) => {
2425
+ let r = e[0]?.children[n], i = /text-align:\s*(left|center|right)/.exec(r?.getAttribute("style") || "")?.[1];
2426
+ return i === "center" ? ":---:" : i === "right" ? "---:" : i === "left" ? ":---" : "---";
2427
+ }), u = "\n\n";
2428
+ u += `| ${c.join(" | ")} |\n`, u += `| ${l.join(" | ")} |\n`;
2429
+ for (let e = s; e < r.length; e++) u += `| ${o(r[e]).join(" | ")} |\n`;
2430
+ return u + "\n";
2431
+ }
2432
+ default: return i();
2433
+ }
2434
+ }
2435
+ function Rn(e) {
2436
+ return String(e ?? "").replace(/^\ufeff/, "");
2437
+ }
2438
+ function zn(e) {
2439
+ let t = Rn(e);
2440
+ return /^#{1,6} [^\s]|^[ \t]*[-*+] [^\s]|^[ \t]*\d+[.)] [^\s]|^> ?[^\s]|^ {0,3}(?:`{3,}|~{3,})|^\*{2}[^*\n]+\*{2}/m.test(t) || /^.+\n=+\s*$/m.test(t) || /^.+\n-{2,}\s*$/m.test(t) || /^---[ \t]*\n(?:[\s\S]*?\n)?(?:---|\.\.\.)[ \t]*(?:\n|$)/.test(t) || /^\|.+\|[ \t]*\n\|[ \t:|-]+\|/m.test(t) || /^[^\n|]*\|[^\n]*\n[ \t]*:?-+:?[ \t]*(?:\|[ \t]*:?-+:?[ \t]*)+$/m.test(t) || /!?\[[^\]\n]*\]\([^)\n]*\)/.test(t) && /`[^`\n]+`|\*\*[^*\n]+\*\*|^#{1,6} |^[-*+] /m.test(t);
2441
+ }
2442
+ var B = /^ {0,3}>( ?)(.*)$/, Bn = /^(?: {4}|\t)\s*\S/, Vn = /^( {0,3})(`{3,}|~{3,})[ \t]*([^\s`~][^\n]*)?$/;
2443
+ function V(e) {
2444
+ let t = Vn.exec(e);
2445
+ if (!t) return null;
2446
+ let [, n, r, i = ""] = t;
2447
+ return r[0] === "`" && i.includes("`") ? null : {
2448
+ marker: r[0],
2449
+ length: r.length,
2450
+ indent: n.length,
2451
+ lang: i.trim().split(/\s+/)[0] || ""
2452
+ };
2453
+ }
2454
+ function Hn(e, t) {
2455
+ let n = 0, r = 0;
2456
+ for (; r < e.length && n < t;) {
2457
+ if (e[r] === " ") {
2458
+ n += 1, r += 1;
2459
+ continue;
2460
+ }
2461
+ if (e[r] === " ") {
2462
+ let e = 4 - n % 4;
2463
+ if (n + e > t) break;
2464
+ n += e, r += 1;
2465
+ continue;
2466
+ }
2467
+ break;
2468
+ }
2469
+ return e.slice(r);
2470
+ }
2471
+ var Un = /^ {0,3}([-*_])( *\1){2,}\s*$/, Wn = "";
2472
+ function H(e) {
2473
+ let t = Rn(e).replaceAll("\r\n", "\n").replaceAll("\r", "\n").split("\n");
2474
+ t = Jn(t);
2475
+ let n = Yn(t);
2476
+ return t = n.clean, Kn = n.linkDefs, qn = n.footnoteIds, Gn(t);
2477
+ }
2478
+ function Gn(e) {
2479
+ let t = [], n = 0;
2480
+ for (; n < e.length;) {
2481
+ let r = e[n], i = V(r);
2482
+ if (i) {
2483
+ let r = RegExp(`^ {0,3}\\${i.marker}{${i.length},}[ \t]*$`), a = [];
2484
+ for (n++; n < e.length && !r.test(e[n]);) a.push(hr(Hn(e[n], i.indent))), n++;
2485
+ let o = i.lang ? ` class="language-${q(i.lang)}"` : "";
2486
+ t.push(`<pre><code${o}>${a.join("\n")}</code></pre>`), n++;
2487
+ continue;
2488
+ }
2489
+ if (Bn.test(r)) {
2490
+ let r = [];
2491
+ for (; n < e.length && (Bn.test(e[n]) || e[n].trim() === "");) {
2492
+ if (e[n].trim() === "") {
2493
+ let t = n;
2494
+ for (; t < e.length && e[t].trim() === "";) t++;
2495
+ if (t >= e.length || !Bn.test(e[t])) break;
2496
+ for (; n < t; n++) r.push("");
2497
+ continue;
2498
+ }
2499
+ r.push(hr(Hn(e[n], 4))), n++;
2500
+ }
2501
+ t.push(`<pre><code>${r.join("\n")}</code></pre>`);
2502
+ continue;
2503
+ }
2504
+ if (r.trim() && !Un.test(r) && !/^#{1,6} /.test(r) && n + 1 < e.length) {
2505
+ if (/^=+\s*$/.test(e[n + 1])) {
2506
+ t.push(`<h1>${K(r.trim())}</h1>`), n += 2;
2507
+ continue;
2508
+ }
2509
+ if (/^-{2,}\s*$/.test(e[n + 1])) {
2510
+ t.push(`<h2>${K(r.trim())}</h2>`), n += 2;
2511
+ continue;
2512
+ }
2513
+ }
2514
+ if (Un.test(r)) {
2515
+ t.push("<hr>"), n++;
2516
+ continue;
2517
+ }
2518
+ let a = /^(#{1,6})[ \t]+(.*)$/.exec(r);
2519
+ if (a) {
2520
+ let e = a[1].length, r = a[2].replace(/(?:^|\s)#+\s*$/, "");
2521
+ t.push(`<h${e}>${K(r)}</h${e}>`), n++;
2522
+ continue;
2523
+ }
2524
+ if (B.test(r)) {
2525
+ let r = [];
2526
+ for (; n < e.length && B.test(e[n]);) r.push(B.exec(e[n])[2]), n++;
2527
+ t.push(`<blockquote>${Gn(r)}</blockquote>`);
2528
+ continue;
2529
+ }
2530
+ if (/^[-*+] /.test(r)) {
2531
+ let { html: r, endIdx: i } = $n(e, n);
2532
+ t.push(r), n = i;
2533
+ continue;
2534
+ }
2535
+ if (/^\d+[.)] /.test(r)) {
2536
+ let { html: r, endIdx: i } = $n(e, n);
2537
+ t.push(r), n = i;
2538
+ continue;
2539
+ }
2540
+ if (r.trim() === "") {
2541
+ n++;
2542
+ continue;
2543
+ }
2544
+ if (Qn(e, n)) {
2545
+ let i = U(r), a = U(e[n + 1]).map((e) => e.startsWith(":") && e.endsWith(":") ? "center" : e.endsWith(":") ? "right" : e.startsWith(":") ? "left" : null);
2546
+ n += 2;
2547
+ let o = [];
2548
+ for (; n < e.length && e[n].trim() !== "" && Zn(e[n]) > 1;) o.push(U(e[n])), n++;
2549
+ let s = (e, t, n) => `<${e}${n ? ` style="text-align:${n}"` : ""}>${K(t)}</${e}>`, c = `<thead><tr>${i.map((e, t) => s("th", e, a[t])).join("")}</tr></thead>`, l = o.length ? `<tbody>${o.map((e) => `<tr>${e.map((e, t) => s("td", e, a[t])).join("")}</tr>`).join("")}</tbody>` : "";
2550
+ t.push(`<table>${c}${l}</table>`);
2551
+ continue;
2552
+ }
2553
+ let o = [];
2554
+ for (; n < e.length && e[n].trim() !== "" && !/^(#{1,6} |[-*+] |\d+[.)] )/.test(e[n]) && !V(e[n]) && !B.test(e[n]) && !Un.test(e[n]) && !Qn(e, n) && !(n + 1 < e.length && /^=+\s*$/.test(e[n + 1])) && !(n + 1 < e.length && /^-{2,}\s*$/.test(e[n + 1]));) o.push(e[n]), n++;
2555
+ o.length ? t.push(`<p>${K(Xn(o)).replaceAll(Wn, "<br>")}</p>`) : (t.push(`<p>${K(r)}</p>`), n++);
2556
+ }
2557
+ return t.join("");
2558
+ }
2559
+ var Kn = /* @__PURE__ */ new Map(), qn = /* @__PURE__ */ new Set();
2560
+ function Jn(e) {
2561
+ if ((e[0] || "").trim() !== "---") return e;
2562
+ let t = -1;
2563
+ for (let n = 1; n < e.length; n++) {
2564
+ let r = e[n].trim();
2565
+ if (r === "---" || r === "...") {
2566
+ t = n;
2567
+ break;
2568
+ }
2569
+ }
2570
+ if (t === -1 || !e.slice(1, t).every((e) => e.trim() === "" || /^[ \t]*[\w$.-]+\s*:(\s|$)/.test(e) || /^[ \t]*-\s+\S/.test(e) || /^[ \t]+\S/.test(e))) return e;
2571
+ let n = t + 1;
2572
+ return e[n] !== void 0 && e[n].trim() === "" && n++, e.slice(n);
2573
+ }
2574
+ function Yn(e) {
2575
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = [], i = !1, a = /^\[([^\]]+)\]:\s*(\S+)(?:\s+"([^"]*)")?\s*$/, o = /^\[\^([^\]]+)\]:[ \t]*(\S.*)$/;
2576
+ for (let s of e) {
2577
+ if (i) {
2578
+ /^ {0,3}(?:`{3,}|~{3,})[ \t]*$/.test(s) && (i = !1), r.push(s);
2579
+ continue;
2580
+ }
2581
+ if (V(s)) {
2582
+ i = !0, r.push(s);
2583
+ continue;
2584
+ }
2585
+ {
2586
+ let e = o.exec(s);
2587
+ if (e) {
2588
+ n.add(e[1]);
2589
+ continue;
2590
+ }
2591
+ let r = a.exec(s);
2592
+ if (r) {
2593
+ t.set(r[1].trim().toLowerCase(), {
2594
+ href: r[2],
2595
+ title: r[3]
2596
+ });
2597
+ continue;
2598
+ }
2599
+ }
2600
+ r.push(s);
2601
+ }
2602
+ return {
2603
+ clean: r,
2604
+ linkDefs: t,
2605
+ footnoteIds: n
2606
+ };
2607
+ }
2608
+ function Xn(e) {
2609
+ let t = "";
2610
+ for (let n = 0; n < e.length; n++) {
2611
+ let r = n === e.length - 1, i = e[n].replace(/^[ \t]+/, "");
2612
+ if (!r && /\\$/.test(i)) {
2613
+ t += i.replace(/\\$/, "") + Wn;
2614
+ continue;
2615
+ }
2616
+ if (!r && / {2,}$/.test(i)) {
2617
+ t += i.replace(/ {2,}$/, "") + Wn;
2618
+ continue;
2619
+ }
2620
+ t += i + (r ? "" : " ");
2621
+ }
2622
+ return t;
2623
+ }
2624
+ function Zn(e) {
2625
+ return U(e).length;
2626
+ }
2627
+ function Qn(e, t) {
2628
+ let n = e[t], r = e[t + 1];
2629
+ if (r === void 0 || !n.includes("|")) return !1;
2630
+ if (/^\|.+\|/.test(n)) return /^\|[\s|:-]+\|/.test(r);
2631
+ let i = U(r);
2632
+ return i.length < 2 || !i.every((e) => /^:?-+:?$/.test(e)) ? !1 : Zn(n) === i.length;
2633
+ }
2634
+ function U(e) {
2635
+ let t = e.replace(/^\|/, "").replace(/\|$/, ""), n = [], r = "";
2636
+ for (let e = 0; e < t.length; e++) {
2637
+ if (t[e] === "\\" && t[e + 1] === "|") {
2638
+ r += "|", e++;
2639
+ continue;
2640
+ }
2641
+ if (t[e] === "|") {
2642
+ n.push(r), r = "";
2643
+ continue;
2644
+ }
2645
+ r += t[e];
2646
+ }
2647
+ return n.push(r), n.map((e) => e.trim());
2648
+ }
2649
+ function $n(e, t) {
2650
+ let n = e[t].match(/^(\s*)/)[1].length, r = /^\s*\d+[.)] /.test(e[t]), i = [], a = null, o = !1, s = !1, c = t;
2651
+ for (; c < e.length;) {
2652
+ let t = e[c];
2653
+ if (t.trim() === "") {
2654
+ let t = e[c + 1], a = t === void 0 ? -1 : t.match(/^(\s*)/)[1].length, l = t !== void 0 && /^\s*(?:[-*+]|\d+[.)]) /.test(t) && /^\s*\d+[.)] /.test(t) === r && a === n, u = t !== void 0 && t.trim() !== "" && a > n;
2655
+ if (!i.length || !l && !u) break;
2656
+ o = !0, s = !0, c++;
2657
+ continue;
2658
+ }
2659
+ let l = t.match(/^(\s*)/)[1].length;
2660
+ if (l < n) break;
2661
+ if (l === n) {
2662
+ if (!/^\s*(?:[-*+]|\d+[.)]) /.test(t) || /^\s*\d+[.)] /.test(t) !== r) break;
2663
+ let e = r ? t.replace(/^\s*\d+[.)] /, "") : t.replace(/^\s*[-*+] /, ""), n = !r && /^\[[ xX]\]\s+/.test(e);
2664
+ if (a === null && (a = n), n !== a) break;
2665
+ let o = n && e[1].toLowerCase() === "x", l = n ? e.replace(/^\[[ xX]\]\s+/, "") : e;
2666
+ i.push({
2667
+ paras: [l],
2668
+ isCB: n,
2669
+ checked: o,
2670
+ sub: ""
2671
+ }), s = !1, c++;
2672
+ } else {
2673
+ if (!i.length) {
2674
+ c++;
2675
+ continue;
2676
+ }
2677
+ let n = (e) => Hn(e, l), r = V(n(t));
2678
+ if (r) {
2679
+ let t = RegExp(`^ {0,3}\\${r.marker}{${r.length},}[ \t]*$`), a = [n(e[c])];
2680
+ for (c++; c < e.length && !t.test(n(e[c]));) a.push(n(e[c])), c++;
2681
+ c < e.length && (a.push(n(e[c])), c++), i[i.length - 1].sub += Gn(a), s = !1;
2682
+ continue;
2683
+ }
2684
+ if (/^\s*(?:[-*+]|\d+[.)]) /.test(t)) {
2685
+ let t = $n(e, c);
2686
+ i[i.length - 1].sub += t.html, c = t.endIdx, s = !1;
2687
+ } else if (s) i[i.length - 1].paras.push(t.trim()), s = !1, c++;
2688
+ else {
2689
+ let e = i[i.length - 1].paras;
2690
+ e[e.length - 1] += " " + t.trim(), c++;
2691
+ }
2692
+ }
2693
+ }
2694
+ let l = !r && a === !0, u = r ? /^\s*(\d+)[.)] /.exec(e[t]) : null, d = u ? Number.parseInt(u[1], 10) : 1, f = r ? d === 1 ? "<ol>" : `<ol start="${d}">` : l ? "<ul class=\"an-checklist\">" : "<ul>", p = r ? "</ol>" : "</ul>";
2695
+ return {
2696
+ html: `${f}${i.map(({ paras: e, isCB: t, checked: n, sub: r }) => {
2697
+ let i = t ? `<input type="checkbox" contenteditable="false"${n ? " checked" : ""}>` : "";
2698
+ return `<li>${o ? e.map((e, t) => `<p>${t === 0 ? i : ""}${K(e)}</p>`).join("") : `${i}${K(e[0])}`}${r}</li>`;
2699
+ }).join("")}${p}`,
2700
+ endIdx: c
2701
+ };
2702
+ }
2703
+ var er = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g, W = "\0", G = "", tr = /(`+)([^]*?)\1/g;
2704
+ function nr(e) {
2705
+ let t = [];
2706
+ return {
2707
+ text: e.replace(tr, (e, n, r) => r === "" ? e : (t.push(r), `${G}${t.length - 1}${G}`)),
2708
+ codes: t
2709
+ };
2710
+ }
2711
+ function rr(e, t, n) {
2712
+ return e.replace(RegExp(`${G}(\\d+)${G}`, "g"), (e, r) => {
2713
+ let i = t[Number(r)];
2714
+ return i = i.replace(RegExp(`${W}(\\d+)${W}`, "g"), (e, t) => `\\${n[Number(t)]}`), i.length > 2 && i.startsWith(" ") && i.endsWith(" ") && i.trim() !== "" && (i = i.slice(1, -1)), `<code>${hr(i)}</code>`;
2715
+ });
2716
+ }
2717
+ function ir(e) {
2718
+ let t = [];
2719
+ return {
2720
+ text: e.replace(er, (e, n) => (t.push(n), `${W}${t.length - 1}${W}`)),
2721
+ literals: t
2722
+ };
2723
+ }
2724
+ function ar(e, t) {
2725
+ return e.replace(RegExp(`${W}(\\d+)${W}`, "g"), (e, n) => mr(t[Number(n)]));
2726
+ }
2727
+ var or = String.raw`(&lt;.*?&gt;(?:\s+(?:"[^"]*"|'[^']*'))?|[^)]*)`, sr = new RegExp(String.raw`!\[([^\]]*)\]\(${or}\)`, "g"), cr = new RegExp(String.raw`\[([^\]]+)\]\(${or}\)`, "g");
2728
+ function lr(e) {
2729
+ let t = e.trim(), n = /^&lt;([\s\S]*?)&gt;(?:[ \t]*(?:"([^"]*)"|'([^']*)'))?[ \t]*$/.exec(t);
2730
+ if (n) return {
2731
+ href: n[1],
2732
+ title: n[2] ?? n[3] ?? ""
2733
+ };
2734
+ let r = /^(\S+)\s+(?:"([^"]*)"|'([^']*)')\s*$/.exec(t);
2735
+ return r ? {
2736
+ href: r[1],
2737
+ title: r[2] ?? r[3] ?? ""
2738
+ } : {
2739
+ href: t,
2740
+ title: ""
2741
+ };
2742
+ }
2743
+ function ur(e) {
2744
+ return e = e.replace(sr, (e, t, n) => {
2745
+ let { href: r, title: i } = lr(n), a = i ? ` title="${J(i)}"` : "";
2746
+ return `<img src="${J(r)}" alt="${J(t)}"${a} class="an-image">`;
2747
+ }), e = e.replace(cr, (e, t, n) => {
2748
+ let { href: r, title: i } = lr(n), a = i ? ` title="${J(i)}"` : "";
2749
+ return `<a href="${J(r)}"${a}>${t}</a>`;
2750
+ }), e = e.replace(/\[([^\]]+)\]\[([^\]]*)\]/g, (e, t, n) => {
2751
+ let r = Kn.get(gr(n || t).trim().toLowerCase());
2752
+ if (!r) return e;
2753
+ let i = r.title ? ` title="${q(r.title)}"` : "";
2754
+ return `<a href="${q(r.href)}"${i}>${t}</a>`;
2755
+ }), e = e.replace(/\[([^\]]+)\]/g, (e, t) => {
2756
+ let n = Kn.get(gr(t).trim().toLowerCase());
2757
+ if (!n) return e;
2758
+ let r = n.title ? ` title="${q(n.title)}"` : "";
2759
+ return `<a href="${q(n.href)}"${r}>${t}</a>`;
2760
+ }), e = e.replace(/\[\^([^\]]+)\]/g, (e, t) => qn.has(gr(t)) ? `<sup>[${t}]</sup>` : e), e;
2761
+ }
2762
+ function dr(e) {
2763
+ return e = e.replace(/&lt;(https?:\/\/[^\s&]+?)&gt;/g, (e, t) => `<a href="${J(t)}">${t}</a>`), e = e.replace(/&lt;([\w.!#$%&'*+/=?^`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+)&gt;/g, (e, t) => `<a href="mailto:${J(t)}">${t}</a>`), e = e.replace(/(^|[\s(])(https?:\/\/[^\s()]+)/g, (e, t, n) => {
2764
+ let r = /[.,;:!?)]+$/.exec(n), i = r ? n.slice(0, -r[0].length) : n;
2765
+ if (!i) return e;
2766
+ let a = r ? r[0] : "";
2767
+ return `${t}<a href="${J(i)}">${i}</a>${a}`;
2768
+ }), e;
2769
+ }
2770
+ function fr(e) {
2771
+ return e = e.replace(/\*{3}([^*\n]+?)\*{3}/g, (e, t) => `<strong><em>${t}</em></strong>`), e = e.replace(/(?<!\w)_{3}([^_\n]+?)_{3}(?!\w)/g, (e, t) => `<strong><em>${t}</em></strong>`), e = e.replace(/\*{2}([^*\n]+?)\*{2}/g, (e, t) => `<strong>${t}</strong>`), e = e.replace(/(?<!\w)_{2}([^_\n]+?)_{2}(?!\w)/g, (e, t) => `<strong>${t}</strong>`), e = e.replace(/\*([^*\n]+?)\*/g, (e, t) => `<em>${t}</em>`), e = e.replace(/(?<!\w)_([^_\n]+?)_(?!\w)/g, (e, t) => `<em>${t}</em>`), e = e.replace(/~~([^~\n]+?)~~/g, (e, t) => `<del>${t}</del>`), e;
2772
+ }
2773
+ function K(e) {
2774
+ let { text: t, literals: n } = ir(e), { text: r, codes: i } = nr(t), a = mr(r);
2775
+ return a = ur(a), a = dr(a), a = fr(a), rr(ar(a, n), i, n);
2776
+ }
2777
+ var pr = /&(?!#\d+;|#[xX][0-9a-fA-F]+;|[a-zA-Z][a-zA-Z0-9]*;)/g;
2778
+ function mr(e) {
2779
+ return String(e).replace(pr, "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2780
+ }
2781
+ function hr(e) {
2782
+ return String(e).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2783
+ }
2784
+ function q(e) {
2785
+ return String(e).replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("'", "&#39;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2786
+ }
2787
+ function J(e) {
2788
+ return String(e).replaceAll("\"", "&quot;").replaceAll("'", "&#39;");
2789
+ }
2790
+ function gr(e) {
2791
+ return String(e).replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&amp;", "&");
2792
+ }
2793
+ //#endregion
2794
+ //#region src/js/core/detectLang.js
2795
+ var _r = 5, vr = 2, yr = [
2796
+ ["typescript", "javascript"],
2797
+ ["scss", "css"],
2798
+ ["cpp", "c"]
2799
+ ], br = [
2800
+ "javascript",
2801
+ "typescript",
2802
+ "python",
2803
+ "java",
2804
+ "go",
2805
+ "rust",
2806
+ "csharp",
2807
+ "kotlin",
2808
+ "swift",
2809
+ "cpp",
2810
+ "c",
2811
+ "ruby",
2812
+ "php",
2813
+ "html",
2814
+ "xml",
2815
+ "json",
2816
+ "yaml",
2817
+ "markdown",
2818
+ "sql",
2819
+ "scss",
2820
+ "css",
2821
+ "bash"
2822
+ ], xr = [
2823
+ {
2824
+ lang: "php",
2825
+ w: 10,
2826
+ re: /<\?php\b|<\?=/
2827
+ },
2828
+ {
2829
+ lang: "bash",
2830
+ w: 10,
2831
+ re: /^#!.*\/(?:ba|z|da|fi|k)?sh\b/m
2832
+ },
2833
+ {
2834
+ lang: "rust",
2835
+ w: 10,
2836
+ re: /\b(?:println!|print!|format!|vec!|panic!)\s*[([]/
2837
+ },
2838
+ {
2839
+ lang: "go",
2840
+ w: 10,
2841
+ re: /\bfmt\.(?:Print|Println|Printf|Sprintf|Errorf|Fprintf)\s*\(/
2842
+ },
2843
+ {
2844
+ lang: "java",
2845
+ w: 10,
2846
+ re: /\bSystem\.out\.(?:print|println)\s*\(/
2847
+ },
2848
+ {
2849
+ lang: "csharp",
2850
+ w: 10,
2851
+ re: /\bConsole\.(?:Write|WriteLine)\s*\(/
2852
+ },
2853
+ {
2854
+ lang: "cpp",
2855
+ w: 10,
2856
+ re: /\b(?:cout|cerr)\s*<<|\bcin\s*>>|\busing\s+namespace\s+std\b|\bstd::\w/
2857
+ },
2858
+ {
2859
+ lang: "python",
2860
+ w: 10,
2861
+ re: /\bdef[ \t]+\w+[ \t]*\([^)]*\)[ \t]*(?:->[^:\n]*)?:|\bif[ \t]+__name__[ \t]*==[ \t]*['"]__main__['"]/
2862
+ },
2863
+ {
2864
+ lang: "html",
2865
+ w: 10,
2866
+ re: /^\s*<!DOCTYPE\s+html/i
2867
+ },
2868
+ {
2869
+ lang: "xml",
2870
+ w: 10,
2871
+ re: /^\s*<\?xml\s/i
2872
+ },
2873
+ {
2874
+ lang: "javascript",
2875
+ w: 6,
2876
+ re: /\bconsole\.(?:log|error|warn|info|debug)\s*\(/
2877
+ },
2878
+ {
2879
+ lang: "javascript",
2880
+ w: 6,
2881
+ re: /\b(?:const|let)\s+\w+\s*=|(?:^|\n)\s*var\s+\w+\s*=/
2882
+ },
2883
+ {
2884
+ lang: "javascript",
2885
+ w: 8,
2886
+ re: /\bexport\s+(?:default|const|function|class|async|\{|\*)|\bmodule\.exports\b|\brequire\s*\(\s*['"]/
2887
+ },
2888
+ {
2889
+ lang: "javascript",
2890
+ w: 5,
2891
+ re: /\bfunction(?:[ \t]+\w+)?[ \t]*\([^)]*\)[ \t]*\{|=>[ \t]*[{([`\w'"]/
2892
+ },
2893
+ {
2894
+ lang: "javascript",
2895
+ w: 5,
2896
+ re: /\bimport\b[^'"\n]*[ \t]from[ \t]*['"]/
2897
+ },
2898
+ {
2899
+ lang: "javascript",
2900
+ w: 4,
2901
+ re: /\.(?:map|filter|forEach|reduce|then|catch|find|some|every)\s*\(/
2902
+ },
2903
+ {
2904
+ lang: "javascript",
2905
+ w: 4,
2906
+ re: /\b(?:document|window|globalThis)\.\w/
2907
+ },
2908
+ {
2909
+ lang: "javascript",
2910
+ w: 4,
2911
+ re: /\baddEventListener\s*\(|\bquerySelector(?:All)?\s*\(|\bgetElementById\s*\(/
2912
+ },
2913
+ {
2914
+ lang: "javascript",
2915
+ w: 3,
2916
+ re: /\.(?:innerHTML|textContent|classList|dataset|style)\b|\bJSON\.(?:parse|stringify)\s*\(/
2917
+ },
2918
+ {
2919
+ lang: "javascript",
2920
+ w: 4,
2921
+ re: /\bawait\s+\w|\basync\s+(?:function|\(|\w+\s*=>)|\bnew\s+Promise\s*\(/
2922
+ },
2923
+ {
2924
+ lang: "javascript",
2925
+ w: 3,
2926
+ re: /\bReact\.|\buseState\s*\(|\buseEffect\s*\(/
2927
+ },
2928
+ {
2929
+ lang: "typescript",
2930
+ w: 8,
2931
+ re: /\binterface\s+\w+(?:<[^>]*>)?\s*(?:extends\s[\w<>, ]+)?\{/
2932
+ },
2933
+ {
2934
+ lang: "typescript",
2935
+ w: 8,
2936
+ re: /\btype\s+\w+(?:<[^>]*>)?\s*=/
2937
+ },
2938
+ {
2939
+ lang: "typescript",
2940
+ w: 7,
2941
+ re: /:\s*(?:string|number|boolean|void|never|any|unknown|object)\b/
2942
+ },
2943
+ {
2944
+ lang: "typescript",
2945
+ w: 6,
2946
+ re: /\benum\s+\w+\s*\{|\breadonly\s+\w|\bimplements\s+\w|\bnamespace\s+\w+\s*\{/
2947
+ },
2948
+ {
2949
+ lang: "typescript",
2950
+ w: 6,
2951
+ re: /\b(?:private|public|protected)\s+(?:readonly\s+)?\w+\s*[:?]/
2952
+ },
2953
+ {
2954
+ lang: "typescript",
2955
+ w: 5,
2956
+ re: /\)\s*:\s*[A-Z]\w*(?:<[^>]*>)?\s*(?:\{|=>)|\)\s*:\s*(?:string|number|boolean|void)\b/
2957
+ },
2958
+ {
2959
+ lang: "typescript",
2960
+ w: 4,
2961
+ re: /\bfunction\s+\w+\s*<[^>]+>\s*\(|\bas\s+(?:const\b|[A-Z]\w*)/
2962
+ },
2963
+ {
2964
+ lang: "typescript",
2965
+ w: 3,
2966
+ re: /\w\?\s*:\s*\w|\bimport\s+type\b|\bsatisfies\b/
2967
+ },
2968
+ {
2969
+ lang: "python",
2970
+ w: 6,
2971
+ re: /(?:^|\n)\s*(?:from\s+[\w.]+\s+import\s|import\s+\w+(?:\s*,\s*\w+)*\s*$)/m
2972
+ },
2973
+ {
2974
+ lang: "python",
2975
+ w: 6,
2976
+ re: /(?:^|\n)\s*class\s+\w+(?:\([\w., ]*\))?\s*:/
2977
+ },
2978
+ {
2979
+ lang: "python",
2980
+ w: 5,
2981
+ re: /(?:^|\n)\s*(?:with|elif|except|finally|async\s+def)\b[^\n]*:/
2982
+ },
2983
+ {
2984
+ lang: "python",
2985
+ w: 5,
2986
+ re: /\bself\.\w|\b__init__\b|\bf["'][^"']*\{/
2987
+ },
2988
+ {
2989
+ lang: "python",
2990
+ w: 4,
2991
+ re: /(?:^|\n)[ \t]*for[ \t]+\w+[ \t]+in[ \t][^\n:]*:|\bfor[ \t]+\w+[ \t]+in[ \t]+range[ \t]*\(/
2992
+ },
2993
+ {
2994
+ lang: "python",
2995
+ w: 4,
2996
+ re: /\bprint\s*\(|\blen\s*\(|\brange\s*\(/
2997
+ },
2998
+ {
2999
+ lang: "python",
3000
+ w: 3,
3001
+ re: /\[[^\]\n]*\bfor\s+\w+\s+in\s[^\]\n]*\]|\bNone\b|\bTrue\b|\bFalse\b/
3002
+ },
3003
+ {
3004
+ lang: "python",
3005
+ w: 3,
3006
+ re: /\*\*\w|\bdict[ \t]*\(|\blambda(?:[ \t]+\w+)?[ \t]*:/
3007
+ },
3008
+ {
3009
+ lang: "go",
3010
+ w: 8,
3011
+ re: /(?:^|\n)\s*package\s+\w+\s*$/m
3012
+ },
3013
+ {
3014
+ lang: "go",
3015
+ w: 6,
3016
+ re: /\btype\s+\w+\s+struct\s*\{|\btype\s+\w+\s+interface\s*\{/
3017
+ },
3018
+ {
3019
+ lang: "go",
3020
+ w: 6,
3021
+ re: /\bfunc(?:[ \t]*\([^)]*\))?(?:[ \t]+\w+)?[ \t]*\([^)]*\)[^\n{]{0,40}\{/
3022
+ },
3023
+ {
3024
+ lang: "go",
3025
+ w: 5,
3026
+ re: /\bif\s+err\s*!=\s*nil\b|\berr\s*:=\s|\bdefer\s+\w/
3027
+ },
3028
+ {
3029
+ lang: "go",
3030
+ w: 4,
3031
+ re: /\w+\s*:=\s*\S|\bchan\s+\w|\bgo\s+func\b|\bnil\b/
3032
+ },
3033
+ {
3034
+ lang: "rust",
3035
+ w: 7,
3036
+ re: /\bfn[ \t]+\w+(?:<[^>]*>)?[ \t]*\([^)]*\)[^\n{]{0,40}\{/
3037
+ },
3038
+ {
3039
+ lang: "rust",
3040
+ w: 7,
3041
+ re: /\blet\s+mut\s+\w|\bpub\s+(?:fn|struct|enum|mod|use)\b|\bimpl\s+\w/
3042
+ },
3043
+ {
3044
+ lang: "rust",
3045
+ w: 5,
3046
+ re: /\buse\s+(?:std|crate|self|super)::|\bmatch\s+\w+\s*\{[^}]*=>/
3047
+ },
3048
+ {
3049
+ lang: "rust",
3050
+ w: 4,
3051
+ re: /\b(?:Option|Result|Vec|Box|Rc|Arc|HashMap)\s*<|&(?:mut\s+)?self\b|\b\w+::<|->\s*Result</
3052
+ },
3053
+ {
3054
+ lang: "rust",
3055
+ w: 3,
3056
+ re: /\b(?:i8|i16|i32|i64|u8|u16|u32|u64|usize|isize|f32|f64)\b|\bunwrap\s*\(\)|\bderive\s*\(/
3057
+ },
3058
+ {
3059
+ lang: "java",
3060
+ w: 7,
3061
+ re: /\b(?:public|private|protected)\s+(?:static\s+)?(?:final\s+)?(?:void|int|long|double|boolean|String|[A-Z]\w*(?:<[^>]*>)?)\s+\w+\s*[({]/
3062
+ },
3063
+ {
3064
+ lang: "java",
3065
+ w: 7,
3066
+ re: /\bimport\s+(?:java|javax|org\.springframework)\.[\w.]+;/
3067
+ },
3068
+ {
3069
+ lang: "java",
3070
+ w: 6,
3071
+ re: /@(?:Override|Autowired|Component|Service|Controller|RestController|Entity|Test|SpringBootApplication)\b/
3072
+ },
3073
+ {
3074
+ lang: "java",
3075
+ w: 5,
3076
+ re: /\bnew\s+(?:ArrayList|HashMap|HashSet|LinkedList|StringBuilder)\s*<[^>]*>\s*\(|\bthrows\s+\w*Exception/
3077
+ },
3078
+ {
3079
+ lang: "java",
3080
+ w: 4,
3081
+ re: /\bpublic\s+(?:class|interface|enum)\s+\w|\bextends\s+\w+\s*\{|\bList<\w|\bMap<\w/
3082
+ },
3083
+ {
3084
+ lang: "csharp",
3085
+ w: 8,
3086
+ re: /\busing\s+System(?:\.[\w.]+)?\s*;|\bnamespace\s+[\w.]+\s*[{;]/
3087
+ },
3088
+ {
3089
+ lang: "csharp",
3090
+ w: 8,
3091
+ re: /\{\s*get;\s*(?:private\s+)?set;\s*\}|\b(?:public|private|protected|internal)\s+(?:static\s+)?async\s+Task(?:<[^>]*>)?\s+\w/
3092
+ },
3093
+ {
3094
+ lang: "csharp",
3095
+ w: 6,
3096
+ re: /\basync\s+Task(?:<[^>]*>)?\s+\w|\bawait\s+\w+\.\w+Async\s*\(/
3097
+ },
3098
+ {
3099
+ lang: "csharp",
3100
+ w: 5,
3101
+ re: /\bIEnumerable<|\bvar\s+\w+\s*=\s*new\s+\w|\bpublic\s+override\b|\[\s*(?:HttpGet|HttpPost|Serializable|Required)\s*\]/
3102
+ },
3103
+ {
3104
+ lang: "csharp",
3105
+ w: 3,
3106
+ re: /\.(?:Select|Where|FirstOrDefault|ToList|Any)\s*\(|\bstring\[\]\s+args\b/
3107
+ },
3108
+ {
3109
+ lang: "kotlin",
3110
+ w: 8,
3111
+ re: /\bfun\s+\w+\s*\([^)]*\)\s*(?::\s*[\w<>?.]+\s*)?[={]|\bdata\s+class\s+\w/
3112
+ },
3113
+ {
3114
+ lang: "kotlin",
3115
+ w: 6,
3116
+ re: /\bval[ \t]+\w+(?:[ \t]*:[ \t]*[\w<>?.]+)?[ \t]*=|\bcompanion[ \t]+object\b|\bsuspend[ \t]+fun\b/
3117
+ },
3118
+ {
3119
+ lang: "kotlin",
3120
+ w: 4,
3121
+ re: /\bprintln\s*\(|\bwhen\s*\([^)]*\)\s*\{|\bobject\s+\w+\s*[:{]|\?:\s*\w/
3122
+ },
3123
+ {
3124
+ lang: "swift",
3125
+ w: 8,
3126
+ re: /\bguard\s+(?:let|var)\s[^\n]*\belse\b|\bfunc\s+\w+\s*\([^)]*\)\s*(?:async\s+)?(?:throws\s+)?->\s*[\w<>?[\]]/
3127
+ },
3128
+ {
3129
+ lang: "swift",
3130
+ w: 6,
3131
+ re: /\bprotocol[ \t]+\w+[^\n{]{0,40}\{|\bextension[ \t]+\w+[^\n{]{0,40}\{|\bimport[ \t]+(?:SwiftUI|UIKit|Foundation)\b/
3132
+ },
3133
+ {
3134
+ lang: "swift",
3135
+ w: 6,
3136
+ re: /\b(?:let|var)\s+\w+\s*:\s*(?:Int|String|Double|Float|Bool|Character|Any|\[[A-Z])|@(?:State|Binding|Published|IBOutlet|objc)\b/
3137
+ },
3138
+ {
3139
+ lang: "swift",
3140
+ w: 4,
3141
+ re: /\\\(\w|\bif[ \t]+let[ \t]+\w|\bstruct[ \t]+\w+[ \t]*:[ \t]*View\b|\bfunc[ \t]+\w+[ \t]*\([^)]*:[ \t]*[A-Z]/
3142
+ },
3143
+ {
3144
+ lang: "swift",
3145
+ w: 3,
3146
+ re: /\?\?\s*\w|\b\w+\?\.\w|\bself\.\w+\s*=/
3147
+ },
3148
+ {
3149
+ lang: "cpp",
3150
+ w: 8,
3151
+ re: /#include\s*<(?:iostream|vector|map|set|algorithm|string|memory|utility)>/
3152
+ },
3153
+ {
3154
+ lang: "cpp",
3155
+ w: 6,
3156
+ re: /\btemplate\s*<\s*(?:typename|class)\b|\bnullptr\b|\bnamespace\s+\w+\s*\{/
3157
+ },
3158
+ {
3159
+ lang: "c",
3160
+ w: 8,
3161
+ re: /#include\s*<(?:stdio|stdlib|string|math|time|ctype|unistd)\.h>/
3162
+ },
3163
+ {
3164
+ lang: "c",
3165
+ w: 6,
3166
+ re: /\b(?:printf|scanf|malloc|calloc|free|memcpy|strlen)\s*\(/
3167
+ },
3168
+ {
3169
+ lang: "c",
3170
+ w: 4,
3171
+ re: /\bint\s+main\s*\(\s*(?:void|int\s+argc|\)\s*\{)/
3172
+ },
3173
+ {
3174
+ lang: "c",
3175
+ w: 3,
3176
+ re: /\btypedef\s+struct\b|\bsizeof\s*\(|\bNULL\b/
3177
+ },
3178
+ {
3179
+ lang: "ruby",
3180
+ w: 8,
3181
+ re: /\bdo[ \t]*\|[ \t]*\w[\w, ]*\|/
3182
+ },
3183
+ {
3184
+ lang: "ruby",
3185
+ w: 7,
3186
+ re: /\battr_(?:accessor|reader|writer)\s+:|\brequire(?:_relative)?\s+['"]|\bputs\s+\S/
3187
+ },
3188
+ {
3189
+ lang: "ruby",
3190
+ w: 4,
3191
+ re: /(?:^|\n)[ \t]*def[ \t]+\w/
3192
+ },
3193
+ {
3194
+ lang: "ruby",
3195
+ w: 4,
3196
+ re: /(?:^|\n)[ \t]*end[ \t]*$/m
3197
+ },
3198
+ {
3199
+ lang: "ruby",
3200
+ w: 4,
3201
+ re: /\bnil\?\b|\b\w+\.new\b|=>\s*['"\w]|\bmodule\s+[A-Z]\w*\s*$/m
3202
+ },
3203
+ {
3204
+ lang: "ruby",
3205
+ w: 3,
3206
+ re: /:\w+[ \t]*=>|\bend[ \t]*$/m
3207
+ },
3208
+ {
3209
+ lang: "php",
3210
+ w: 7,
3211
+ re: /\$this->\w|\bfunction\s+\w+\s*\([^)]*\$\w/
3212
+ },
3213
+ {
3214
+ lang: "php",
3215
+ w: 6,
3216
+ re: /\$\w+\s*=\s*\S|\bforeach\s*\(\s*\$\w+\s+as\s+\$/
3217
+ },
3218
+ {
3219
+ lang: "php",
3220
+ w: 5,
3221
+ re: /\becho[ \t][^;\n]*[$'"]|\bnamespace[ \t]+[\w\\]+;|\buse[ \t]+[\w\\]+\\\w+;/
3222
+ },
3223
+ {
3224
+ lang: "php",
3225
+ w: 8,
3226
+ re: /\b(?:public|private|protected)\s+(?:static\s+)?function\s+\w/
3227
+ },
3228
+ {
3229
+ lang: "php",
3230
+ w: 3,
3231
+ re: /->\w+\s*\(|::\w+\s*\(/
3232
+ },
3233
+ {
3234
+ lang: "html",
3235
+ w: 7,
3236
+ re: /<(?:html|head|body|nav|section|article|header|footer|main|form)\b[^>]*>/i
3237
+ },
3238
+ {
3239
+ lang: "html",
3240
+ w: 5,
3241
+ re: /<(?:div|p|span|a|img|ul|ol|li|table|tr|td|input|button|h[1-6])\b[^>]*>[\s\S]*<\/(?:div|p|span|a|ul|ol|li|table|tr|td|button|h[1-6])>/i
3242
+ },
3243
+ {
3244
+ lang: "html",
3245
+ w: 4,
3246
+ re: /<\w+\s+(?:class|id|href|src|type|style)\s*=\s*["']/i
3247
+ },
3248
+ {
3249
+ lang: "xml",
3250
+ w: 6,
3251
+ re: /\bxmlns(?::\w+)?\s*=\s*["']|<\/\w+:\w+>|<\w+:\w+[\s>]/
3252
+ },
3253
+ {
3254
+ lang: "json",
3255
+ w: 8,
3256
+ re: /^\s*[{[][\s\S]*"[\w-]+"\s*:\s*(?:"[^"]*"|-?\d|\{|\[|true|false|null)/
3257
+ },
3258
+ {
3259
+ lang: "json",
3260
+ w: 3,
3261
+ re: /^\s*\{[\s\S]*\}\s*$|^\s*\[[\s\S]*\]\s*$/
3262
+ },
3263
+ {
3264
+ lang: "yaml",
3265
+ w: 8,
3266
+ re: /^---\s*$/m
3267
+ },
3268
+ {
3269
+ lang: "yaml",
3270
+ w: 6,
3271
+ re: /^[ \t]*-\s+\w+\s*:\s*\S/m
3272
+ },
3273
+ {
3274
+ lang: "yaml",
3275
+ w: 5,
3276
+ re: /^[a-z_][\w-]*[ \t]*:(?:[ \t]*$|[ \t]+(?:[|>][-+]?[ \t]*$|['"\w[{]))/im
3277
+ },
3278
+ {
3279
+ lang: "yaml",
3280
+ w: 4,
3281
+ re: /^[ \t]+[a-z_][\w-]*[ \t]*:[ \t]*\S/im
3282
+ },
3283
+ {
3284
+ lang: "yaml",
3285
+ w: 3,
3286
+ re: /^[ \t]*-\s+\S/m
3287
+ },
3288
+ {
3289
+ lang: "markdown",
3290
+ w: 7,
3291
+ re: /^#{1,6}\s+\S/m
3292
+ },
3293
+ {
3294
+ lang: "markdown",
3295
+ w: 6,
3296
+ re: /^```|^\|[^\n|]+\|[^\n]*\n\s*\|[\s:|-]+\|/m
3297
+ },
3298
+ {
3299
+ lang: "markdown",
3300
+ w: 4,
3301
+ re: /\[[^\]\n]+\]\([^)\n]+\)|!\[[^\]\n]*\]\(/
3302
+ },
3303
+ {
3304
+ lang: "markdown",
3305
+ w: 3,
3306
+ re: /\*\*[^*\n]+\*\*|^>\s+\S|^[-*+]\s+\S/m
3307
+ },
3308
+ {
3309
+ lang: "sql",
3310
+ w: 9,
3311
+ re: /(?:^|\n)\s*(?:SELECT\s+[\w*]|INSERT\s+INTO\s|UPDATE\s+\w+\s+SET\s|DELETE\s+FROM\s)/i
3312
+ },
3313
+ {
3314
+ lang: "sql",
3315
+ w: 8,
3316
+ re: /(?:^|\n)\s*(?:CREATE|ALTER|DROP)\s+(?:TABLE|DATABASE|INDEX|VIEW|SCHEMA)\b/i
3317
+ },
3318
+ {
3319
+ lang: "sql",
3320
+ w: 4,
3321
+ re: /\b(?:INNER|LEFT|RIGHT|FULL)\s+(?:OUTER\s+)?JOIN\b|\bGROUP\s+BY\b|\bORDER\s+BY\b|\bWITH\s+\w+\s+AS\s*\(/i
3322
+ },
3323
+ {
3324
+ lang: "scss",
3325
+ w: 9,
3326
+ re: /^[ \t]*\$[\w-]+[ \t]*:[^;\n]+;|@(?:mixin|include|extend|use|forward)[ \t]+[\w"'-]/m
3327
+ },
3328
+ {
3329
+ lang: "scss",
3330
+ w: 7,
3331
+ re: /^[ \t]*&[\s.:[&>+~]|#\{[^}]*\}/m
3332
+ },
3333
+ {
3334
+ lang: "scss",
3335
+ w: 4,
3336
+ re: /^[ \t]*\/\/[ \t]*\S/m
3337
+ },
3338
+ {
3339
+ lang: "css",
3340
+ w: 6,
3341
+ re: /^[ \t]*(?!(?:export|import|return|function|const|let|var|val|if|else|for|while|switch|case|class|new|public|private|protected|internal|def|func|fun|fn|pub|package|type|interface|enum|struct|impl|trait|mod|use|using|namespace|module|data|object|async|await|guard|extension|protocol|template|typedef)\b)[.#]?[\w-]+[^{}\n]{0,60}\{[^{}:]*:[^{};]+[;}]/m
3342
+ },
3343
+ {
3344
+ lang: "css",
3345
+ w: 5,
3346
+ re: /@(?:media|supports|keyframes|font-face|import|charset)\b/
3347
+ },
3348
+ {
3349
+ lang: "css",
3350
+ w: 4,
3351
+ re: /:\s*(?:#[\da-f]{3,8}|\d+(?:px|rem|em|%|vh|vw)|flex|grid|block|none|absolute|relative)\s*[;}]/i
3352
+ },
3353
+ {
3354
+ lang: "css",
3355
+ w: 3,
3356
+ re: /::?(?:hover|focus|active|before|after|first-child|last-child|nth-child)\b/
3357
+ },
3358
+ {
3359
+ lang: "bash",
3360
+ w: 7,
3361
+ re: /(?:^|\n|&&|\|\|)\s*(?:sudo\s+)?(?:apt(?:-get)?|yum|brew|npm|pnpm|yarn|pip3?|docker|kubectl|git|systemctl|curl|wget|chmod|chown|mkdir|rm|cp|mv|tar|ssh|scp)\s+[\w./-]/
3362
+ },
3363
+ {
3364
+ lang: "bash",
3365
+ w: 6,
3366
+ re: /^\s*(?:export|source|alias)\s+\w+|^\s*\w+=\S+\s*$/m
3367
+ },
3368
+ {
3369
+ lang: "bash",
3370
+ w: 6,
3371
+ re: /\bfi[ \t]*$|(?:^|\n)[ \t]*(?:if|for|while)[ \t][^\n]*;[ \t]*(?:then|do)\b|(?:^|\n)[ \t]*done\b/m
3372
+ },
3373
+ {
3374
+ lang: "bash",
3375
+ w: 5,
3376
+ re: /\$\{?\w+\}?[/:]|"\$\w|\becho\s+["'$]|\$\(\w/
3377
+ },
3378
+ {
3379
+ lang: "bash",
3380
+ w: 4,
3381
+ re: /(?:^|\n|\|)\s*(?:grep|awk|sed|cat|ls|cd|pwd|find|xargs|head|tail|sort|uniq|wc)\s+[-\w$'"./]/
3382
+ },
3383
+ {
3384
+ lang: "bash",
3385
+ w: 3,
3386
+ re: /\s\|[ \t]*\w|\s&&\s|\s2>&1|\s-[\w-]+\s/
3387
+ }
3388
+ ], Sr = 4e3;
3389
+ function Cr(e) {
3390
+ if (e.length <= Sr) return e;
3391
+ let t = e.slice(0, Sr), n = t.lastIndexOf("\n");
3392
+ return n > 0 ? t.slice(0, n) : t;
3393
+ }
3394
+ function wr(e) {
3395
+ if (!e?.trim()) return null;
3396
+ let t = Cr(e.trim()), n = /* @__PURE__ */ new Map();
3397
+ for (let { lang: e, re: r, w: i } of xr) r.test(t) && n.set(e, (n.get(e) || 0) + i);
3398
+ if (n.size === 0) return null;
3399
+ for (let [e, t] of yr) {
3400
+ let r = n.get(e);
3401
+ r && n.set(e, r + (n.get(t) || 0));
3402
+ }
3403
+ let r = [...n.entries()].sort((e, t) => t[1] - e[1]), [i, a] = r[0], o = r[1]?.[1] ?? 0;
3404
+ return a < _r || a - o < vr ? null : i;
3405
+ }
3406
+ //#endregion
3407
+ //#region src/js/module/Editor.js
3408
+ var Tr = /* @__PURE__ */ new Set([
3409
+ "PRE",
3410
+ "BLOCKQUOTE",
3411
+ "TABLE",
3412
+ "FIGURE",
3413
+ "UL",
3414
+ "OL",
3415
+ "HR"
3416
+ ]), Er = class {
3417
+ constructor(e) {
3418
+ this.context = e, this.options = e.options, this._history = null, this._disposers = [], this._snapshotTimer = null;
3419
+ }
3420
+ initialize() {
3421
+ let e = this.context.layoutInfo.editable;
3422
+ return this._history = new wn(e, this.options.historyLimit || 100, this.options.historyMaxBytes || 10 * 1024 * 1024), this._bindEvents(e), this;
3423
+ }
3424
+ destroy() {
3425
+ this._disposers.forEach((e) => e()), this._disposers = [], this._history = null, clearTimeout(this._snapshotTimer), this._snapshotTimer = null;
3426
+ }
3427
+ _bindEvents(e) {
3428
+ let t = (e) => this._onKeydown(e), n = () => this.afterCommand(), r = (e) => this._enforceLimit(e), i = () => {
3429
+ if (!this.context._alive) return;
3430
+ let t = globalThis.getSelection();
3431
+ t?.rangeCount > 0 && e.contains(t.anchorNode) && (this.context.invoke("toolbar.refresh"), typeof this.options.onSelectionChange == "function" && this.options.onSelectionChange(this.context));
3432
+ }, a = (e) => {
3433
+ e.target.type === "checkbox" && e.target.closest(".an-checklist") && this.afterCommand();
3434
+ }, o = (t) => {
3435
+ let n = globalThis.getSelection();
3436
+ if (!n?.rangeCount) return;
3437
+ let r = n.getRangeAt(0);
3438
+ if (!r.collapsed) return;
3439
+ let i = r.startContainer;
3440
+ if (i.nodeType !== Node.ELEMENT_NODE) return;
3441
+ let a = i, o = a.matches(".an-checklist li") ? a : null;
3442
+ if (!o) return;
3443
+ let s = o.querySelector("input[type=\"checkbox\"]");
3444
+ if (!s) return;
3445
+ if (t?.type === "mouseup") {
3446
+ let r = null;
3447
+ if (document.caretRangeFromPoint) r = document.caretRangeFromPoint(t.clientX, t.clientY);
3448
+ else if (document.caretPositionFromPoint) {
3449
+ let e = document.caretPositionFromPoint(t.clientX, t.clientY);
3450
+ e && (r = document.createRange(), r.setStart(e.offsetNode, e.offset));
3451
+ }
3452
+ if (r && e.contains(r.startContainer) && r.startContainer !== o) {
3453
+ r.collapse(!0), n.removeAllRanges(), n.addRange(r);
3454
+ return;
3455
+ }
3456
+ }
3457
+ let c = document.createRange(), l = null;
3458
+ for (let e of o.childNodes) if (e !== s && e.nodeType === Node.TEXT_NODE) {
3459
+ l = e;
3460
+ break;
3461
+ }
3462
+ l ? c.setStart(l, 0) : c.setStartAfter(s), c.collapse(!0), n.removeAllRanges(), n.addRange(c);
3463
+ }, s = () => this.context.layoutInfo.container.classList.contains("an-disabled");
3464
+ this._disposers.push(C(e, "keydown", t), C(e, "beforeinput", r), C(e, "input", n), C(document, "selectionchange", i), C(e, "click", a), C(e, "mouseup", o), C(e, "keyup", o), C(e, "dragstart", (e) => {
3465
+ if (s()) {
3466
+ e.preventDefault();
3467
+ return;
3468
+ }
3469
+ let t = e.target;
3470
+ t && (t.nodeName === "IFRAME" || t.closest(".an-video-wrapper")) && e.preventDefault();
3471
+ }), C(e, "drop", (e) => {
3472
+ s() && e.preventDefault();
3473
+ }));
3474
+ let c = null;
3475
+ this._disposers.push(C(e, "compositionstart", () => {
3476
+ let e = globalThis.getSelection();
3477
+ if (!e?.rangeCount) {
3478
+ c = null;
3479
+ return;
3480
+ }
3481
+ let t = e.getRangeAt(0).startContainer;
3482
+ if (t.nodeType === Node.TEXT_NODE && (t = t.parentElement), t) {
3483
+ let e = t;
3484
+ c = e.closest("sup") ? "superscript" : e.closest("sub") ? "subscript" : null;
3485
+ }
3486
+ }), C(e, "compositionend", () => {
3487
+ let e = c;
3488
+ if (c = null, !e) return;
3489
+ let t = globalThis.getSelection();
3490
+ if (!t?.rangeCount) return;
3491
+ let n = t.getRangeAt(0).startContainer;
3492
+ n.nodeType === Node.TEXT_NODE && (n = n.parentElement);
3493
+ let r = n;
3494
+ (e === "superscript" ? r?.closest("sup") : r?.closest("sub")) || document.execCommand(e);
3495
+ }));
3496
+ }
3497
+ _onKeydown(e) {
3498
+ let t = this.context.layoutInfo.editable;
3499
+ if (!kn(e, t, this.options)) {
3500
+ if (I(e, "z") && !e.shiftKey) {
3501
+ e.preventDefault(), this.undo();
3502
+ return;
3503
+ }
3504
+ if (I(e, "z") && e.shiftKey || I(e, "y")) {
3505
+ e.preventDefault(), this.redo();
3506
+ return;
3507
+ }
3508
+ if (I(e, "b")) {
3509
+ e.preventDefault(), this.bold();
3510
+ return;
3511
+ }
3512
+ if (I(e, "i")) {
3513
+ e.preventDefault(), this.italic();
3514
+ return;
3515
+ }
3516
+ if (I(e, "u")) {
3517
+ e.preventDefault(), this.underline();
3518
+ return;
3519
+ }
3520
+ if (I(e, "k")) {
3521
+ e.preventDefault(), this.context.invoke("linkDialog.show");
3522
+ return;
3523
+ }
3524
+ if (I(e, "v") && e.shiftKey) {
3525
+ this.context.invoke("clipboard.setForcePlain", !0);
3526
+ return;
3527
+ }
3528
+ if (e.key === "/" && e.shiftKey && e.ctrlKey && !e.metaKey) {
3529
+ e.preventDefault(), this.context.invoke("shortcutsDialog.show");
3530
+ return;
3531
+ }
3532
+ if (I(e, "f")) {
3533
+ e.preventDefault(), this.context.invoke("findReplace.show", "find");
3534
+ return;
3535
+ }
3536
+ I(e, "h") && (e.preventDefault(), this.context.invoke("findReplace.show", "replace")), I(e, "`") && (e.preventDefault(), this.inlineCode());
3537
+ }
3538
+ }
3539
+ _enforceLimit(e) {
3540
+ let t = this.options.maxChars || 0, n = this.options.maxWords || 0;
3541
+ if (!t && !n) return;
3542
+ let r = e.inputType || "";
3543
+ if (r.startsWith("delete") || r === "historyUndo" || r === "historyRedo" || r === "insertFromPaste" || r === "insertFromDrop" || !r.startsWith("insert")) return;
3544
+ let i = this.context.layoutInfo.editable.innerText || "", a = i.replaceAll("\n", "").length;
3545
+ if (t && a >= t) {
3546
+ e.preventDefault(), typeof this.options.onCharLimitReached == "function" && this.options.onCharLimitReached(this.context);
3547
+ return;
3548
+ }
3549
+ n && (e.data === " " || r === "insertParagraph" || r === "insertLineBreak") && (i.trim() ? i.trim().split(/\s+/).length : 0) >= n && (e.preventDefault(), typeof this.options.onWordLimitReached == "function" && this.options.onWordLimitReached(this.context));
3550
+ }
3551
+ afterCommand() {
3552
+ this._cleanOrphanedFigures(), this._ensureTrailingParagraph(), this.context.invoke("toolbar.refresh"), this.context.invoke("statusbar.update"), this._scheduleSnapshot();
3553
+ }
3554
+ _scheduleSnapshot() {
3555
+ clearTimeout(this._snapshotTimer), this._snapshotTimer = setTimeout(() => {
3556
+ this._snapshotTimer = null, this._history && this._history.recordUndo(), this.context.triggerEvent("change", this.getHTML());
3557
+ }, 400);
3558
+ }
3559
+ _cleanOrphanedFigures() {
3560
+ this.context.layoutInfo.editable.querySelectorAll("figure.an-figure").forEach((e) => {
3561
+ e.querySelector("img") || e.remove();
3562
+ });
3563
+ }
3564
+ _ensureTrailingParagraph() {
3565
+ let e = this.context.layoutInfo.editable;
3566
+ if (!e) return;
3567
+ let t = e.lastElementChild;
3568
+ if (t && Tr.has(t.nodeName)) {
3569
+ let t = document.createElement("p");
3570
+ t.innerHTML = "<br>", e.appendChild(t);
3571
+ }
3572
+ }
3573
+ focus() {
3574
+ this.context.layoutInfo.editable.focus();
3575
+ }
3576
+ getHTML() {
3577
+ let e = this.context.layoutInfo.editable.innerHTML.replaceAll("​", "");
3578
+ return this.context.invoke("clipboard.resolveImages", e) ?? e;
3579
+ }
3580
+ setHTML(e) {
3581
+ let t = mn(e, { allowIframes: !0 });
3582
+ this.context.layoutInfo.editable.replaceChildren(...t.childNodes), this._history && this._history.reset(), this.afterCommand();
3583
+ }
3584
+ getText() {
3585
+ return this.context.layoutInfo.editable.innerText || "";
3586
+ }
3587
+ setText(e) {
3588
+ this.context.layoutInfo.editable.textContent = e, this._history && this._history.reset(), this.afterCommand();
3589
+ }
3590
+ clear() {
3591
+ this.setHTML("");
3592
+ }
3593
+ clearHistory() {
3594
+ this._history && this._history.reset();
3595
+ }
3596
+ isEmpty() {
3597
+ let e = (this.context.layoutInfo.editable.innerText || "").trim().replaceAll("\xA0", ""), t = !!this.context.layoutInfo.editable.querySelector("img, video, iframe, table");
3598
+ return !e && !t;
3599
+ }
3600
+ insertHTML(e) {
3601
+ e && (w("insertHTML", j(e)), this.afterCommand());
3602
+ }
3603
+ insertText(e) {
3604
+ e && (w("insertText", e), this.afterCommand());
3605
+ }
3606
+ setMarkdown(e) {
3607
+ this.setHTML(H(e || ""));
3608
+ }
3609
+ getMarkdown() {
3610
+ return An(this.getHTML());
3611
+ }
3612
+ undo() {
3613
+ this._history && (this._flushPendingSnapshot(), this._history.undo(), this.context.invoke("toolbar.refresh"), this.context.invoke("statusbar.update"), this.context.triggerEvent("change", this.getHTML()));
3614
+ }
3615
+ redo() {
3616
+ this._history && (this._flushPendingSnapshot(), this._history.redo(), this.context.invoke("toolbar.refresh"), this.context.invoke("statusbar.update"), this.context.triggerEvent("change", this.getHTML()));
3617
+ }
3618
+ _flushPendingSnapshot() {
3619
+ this._snapshotTimer !== null && (clearTimeout(this._snapshotTimer), this._snapshotTimer = null, this._history?.recordUndo());
3620
+ }
3621
+ canUndo() {
3622
+ return this._history ? this._history.canUndo() : !1;
3623
+ }
3624
+ canRedo() {
3625
+ return this._history ? this._history.canRedo() : !1;
3626
+ }
3627
+ getUndoCount() {
3628
+ return this._history ? this._history.getUndoCount() : 0;
3629
+ }
3630
+ getRedoCount() {
3631
+ return this._history ? this._history.getRedoCount() : 0;
3632
+ }
3633
+ getSelectionBookmark() {
3634
+ return this._history?._serializeSelection() ?? null;
3635
+ }
3636
+ restoreSelectionBookmark(e) {
3637
+ return !e || !this._history ? !1 : (this._history._restoreSelection(e), !0);
3638
+ }
3639
+ bold() {
3640
+ Ie(), this.afterCommand();
3641
+ }
3642
+ italic() {
3643
+ Le(), this.afterCommand();
3644
+ }
3645
+ underline() {
3646
+ Re(), this.afterCommand();
3647
+ }
3648
+ strikethrough() {
3649
+ ze(), this.afterCommand();
3650
+ }
3651
+ superscript() {
3652
+ Be(), this.afterCommand();
3653
+ }
3654
+ subscript() {
3655
+ Ve(), this.afterCommand();
3656
+ }
3657
+ justifyLeft() {
3658
+ qe(), this.afterCommand();
3659
+ }
3660
+ justifyCenter() {
3661
+ Je(), this.afterCommand();
3662
+ }
3663
+ justifyRight() {
3664
+ Ye(), this.afterCommand();
3665
+ }
3666
+ justifyFull() {
3667
+ Xe(), this.afterCommand();
3668
+ }
3669
+ indent() {
3670
+ Ze(), this.afterCommand();
3671
+ }
3672
+ outdent() {
3673
+ Qe(), this.afterCommand();
3674
+ }
3675
+ insertUL() {
3676
+ nt(), this.afterCommand();
3677
+ }
3678
+ insertOL() {
3679
+ rt(), this.afterCommand();
3680
+ }
3681
+ inlineCode() {
3682
+ at(this.context.layoutInfo.editable), this.afterCommand();
3683
+ }
3684
+ toggleChecklist() {
3685
+ ct(), this.afterCommand();
3686
+ }
3687
+ print() {
3688
+ this.context.print();
3689
+ }
3690
+ formatBlock(e) {
3691
+ if (Ke(e), e === "pre") {
3692
+ let e = globalThis.getSelection();
3693
+ if (e?.rangeCount > 0) {
3694
+ let t = e.getRangeAt(0).commonAncestorContainer, n = t.nodeType === 1 ? t.closest("pre") : t.parentElement?.closest("pre");
3695
+ if (n && !n.dataset.language) {
3696
+ let e = wr(n.textContent || "");
3697
+ if (e) {
3698
+ this.context.invoke("codeTooltip.applyLanguage", n, e);
3699
+ return;
3700
+ }
3701
+ }
3702
+ }
3703
+ }
3704
+ this.afterCommand();
3705
+ }
3706
+ foreColor(e) {
3707
+ He(e), this.afterCommand();
3708
+ }
3709
+ backColor(e) {
3710
+ Ue(e), this.afterCommand();
3711
+ }
3712
+ fontName(e) {
3713
+ We(e), this.afterCommand();
3714
+ }
3715
+ fontSize(e) {
3716
+ Ge(e, this.context.layoutInfo.editable), this.afterCommand();
3717
+ }
3718
+ insertHr() {
3719
+ w("insertHorizontalRule"), this.afterCommand();
3720
+ }
3721
+ insertLink(e, t, n = !1) {
3722
+ let r = globalThis.getSelection();
3723
+ if (!r || r.rangeCount === 0) return;
3724
+ let i = M(e);
3725
+ if (i) {
3726
+ if (r.toString().trim().length > 0) {
3727
+ if (w("createLink", i), n) {
3728
+ let e = this._getClosestAnchor();
3729
+ e && (e.setAttribute("target", "_blank"), e.setAttribute("rel", "noopener noreferrer"));
3730
+ }
3731
+ } else {
3732
+ let e = this._escapeAttr(t || i);
3733
+ w("insertHTML", `<a href="${this._escapeAttr(i)}"${n ? " target=\"_blank\" rel=\"noopener noreferrer\"" : ""}>${e}</a>`);
3734
+ }
3735
+ this.afterCommand();
3736
+ }
3737
+ }
3738
+ unlink() {
3739
+ w("unlink"), this.afterCommand();
3740
+ }
3741
+ insertImage(e, t = "", n = "") {
3742
+ let r = M(e, { allowData: !0 });
3743
+ if (!r) return;
3744
+ let i = {
3745
+ left: "float:left;margin:0 1em 1em 0",
3746
+ center: "display:block;margin:0 auto",
3747
+ right: "float:right;margin:0 0 1em 1em"
3748
+ }[n] || "", a = i ? ` style="${i}"` : "";
3749
+ w("insertHTML", `<img src="${this._escapeAttr(r)}" alt="${this._escapeAttr(t)}" class="an-image"${a}>`), this.afterCommand();
3750
+ }
3751
+ insertVideo(e) {
3752
+ e && (w("insertHTML", e), this.afterCommand());
3753
+ }
3754
+ insertTable(e, t) {
3755
+ En(e, t, { headerRow: this.context.options.tableHeaderRow }), this.afterCommand();
3756
+ }
3757
+ _getClosestAnchor() {
3758
+ let e = globalThis.getSelection();
3759
+ if (!e || e.rangeCount === 0) return null;
3760
+ let t = e.getRangeAt(0).startContainer;
3761
+ for (; t;) {
3762
+ if (t.nodeName === "A") return t;
3763
+ t = t.parentNode;
3764
+ }
3765
+ return null;
3766
+ }
3767
+ _escapeAttr(e) {
3768
+ return String(e ?? "").replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
3769
+ }
3770
+ }, Dr = (e) => typeof e == "string" ? ut(e) : e, Y = null, Or = "stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"", X = (e) => `<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" ${Or} style="display:block">${e}</svg>`, Z = /* @__PURE__ */ new Map([
3771
+ ["bold", X("<path d=\"M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z\"/><path d=\"M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z\"/>")],
3772
+ ["italic", X("<line x1=\"19\" y1=\"4\" x2=\"10\" y2=\"4\"/><line x1=\"14\" y1=\"20\" x2=\"5\" y2=\"20\"/><line x1=\"15\" y1=\"4\" x2=\"9\" y2=\"20\"/>")],
3773
+ ["underline", X("<path d=\"M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3\"/><line x1=\"4\" y1=\"21\" x2=\"20\" y2=\"21\"/>")],
3774
+ ["strikethrough", X("<path d=\"M17.3 12H6.7\"/><path d=\"M10 6.5C10 5.1 11.1 4 12.5 4c1.4 0 2.5 1.1 2.5 2.5 0 .8-.4 1.5-1 2\"/><path d=\"M14 17.5C14 19 12.9 20 11.5 20 10.1 20 9 18.9 9 17.5c0-.8.4-1.5 1-2\"/>")],
3775
+ ["superscript", X("<path d=\"m4 19 8-8\"/><path d=\"m12 19-8-8\"/><path d=\"M20 12h-4c0-1.5.44-2 1.5-2.5S20 8.33 20 7.25C20 6 19 5 17.5 5S15 6 15 7\"/>")],
3776
+ ["subscript", X("<path d=\"m4 5 8 8\"/><path d=\"m12 5-8 8\"/><path d=\"M20 21h-4c0-1.5.44-2 1.5-2.5S20 17.33 20 16.25C20 15 19 14 17.5 14S15 15 15 16\"/>")],
3777
+ ["align-left", X("<line x1=\"21\" y1=\"6\" x2=\"3\" y2=\"6\"/><line x1=\"15\" y1=\"12\" x2=\"3\" y2=\"12\"/><line x1=\"17\" y1=\"18\" x2=\"3\" y2=\"18\"/>")],
3778
+ ["align-center", X("<line x1=\"21\" y1=\"6\" x2=\"3\" y2=\"6\"/><line x1=\"18\" y1=\"12\" x2=\"6\" y2=\"12\"/><line x1=\"21\" y1=\"18\" x2=\"3\" y2=\"18\"/>")],
3779
+ ["align-right", X("<line x1=\"21\" y1=\"6\" x2=\"3\" y2=\"6\"/><line x1=\"21\" y1=\"12\" x2=\"9\" y2=\"12\"/><line x1=\"21\" y1=\"18\" x2=\"7\" y2=\"18\"/>")],
3780
+ ["align-justify", X("<line x1=\"21\" y1=\"6\" x2=\"3\" y2=\"6\"/><line x1=\"21\" y1=\"12\" x2=\"3\" y2=\"12\"/><line x1=\"21\" y1=\"18\" x2=\"3\" y2=\"18\"/>")],
3781
+ ["list-ul", X("<line x1=\"9\" y1=\"6\" x2=\"20\" y2=\"6\"/><line x1=\"9\" y1=\"12\" x2=\"20\" y2=\"12\"/><line x1=\"9\" y1=\"18\" x2=\"20\" y2=\"18\"/><circle cx=\"4\" cy=\"6\" r=\"1\" fill=\"currentColor\" stroke=\"none\"/><circle cx=\"4\" cy=\"12\" r=\"1\" fill=\"currentColor\" stroke=\"none\"/><circle cx=\"4\" cy=\"18\" r=\"1\" fill=\"currentColor\" stroke=\"none\"/>")],
3782
+ ["list-ol", X("<line x1=\"10\" y1=\"6\" x2=\"21\" y2=\"6\"/><line x1=\"10\" y1=\"12\" x2=\"21\" y2=\"12\"/><line x1=\"10\" y1=\"18\" x2=\"21\" y2=\"18\"/><path d=\"M4 6h1V3\"/><path d=\"M4 10h2l-2 2h2\"/><path d=\"M4 16.5A1.5 1.5 0 0 1 5.5 15a1.5 1.5 0 0 1 0 3H4\"/>")],
3783
+ ["indent", X("<polyline points=\"3 8 7 12 3 16\"/><line x1=\"21\" y1=\"12\" x2=\"11\" y2=\"12\"/><line x1=\"21\" y1=\"6\" x2=\"11\" y2=\"6\"/><line x1=\"21\" y1=\"18\" x2=\"11\" y2=\"18\"/>")],
3784
+ ["outdent", X("<polyline points=\"7 8 3 12 7 16\"/><line x1=\"21\" y1=\"12\" x2=\"11\" y2=\"12\"/><line x1=\"21\" y1=\"6\" x2=\"11\" y2=\"6\"/><line x1=\"21\" y1=\"18\" x2=\"11\" y2=\"18\"/>")],
3785
+ ["undo", X("<path d=\"M3 7v6h6\"/><path d=\"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13\"/>")],
3786
+ ["redo", X("<path d=\"M21 7v6h-6\"/><path d=\"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13\"/>")],
3787
+ ["minus", X("<line x1=\"5\" y1=\"12\" x2=\"19\" y2=\"12\"/>")],
3788
+ ["link", X("<path d=\"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71\"/><path d=\"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71\"/>")],
3789
+ ["image", X("<rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2\"/><circle cx=\"8.5\" cy=\"8.5\" r=\"1.5\"/><polyline points=\"21 15 16 10 5 21\"/>")],
3790
+ ["video", X("<polygon points=\"23 7 16 12 23 17 23 7\"/><rect x=\"1\" y=\"5\" width=\"15\" height=\"14\" rx=\"2\"/>")],
3791
+ ["table", X("<rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"1\"/><line x1=\"3\" y1=\"9\" x2=\"21\" y2=\"9\"/><line x1=\"3\" y1=\"15\" x2=\"21\" y2=\"15\"/><line x1=\"9\" y1=\"3\" x2=\"9\" y2=\"21\"/><line x1=\"15\" y1=\"3\" x2=\"15\" y2=\"21\"/>")],
3792
+ ["emoji", X("<circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"M8.5 14.5s1.5 2.5 3.5 2.5 3.5-2.5 3.5-2.5\"/><circle cx=\"9\" cy=\"9\" r=\"1.5\" fill=\"currentColor\" stroke=\"none\"/><circle cx=\"15\" cy=\"9\" r=\"1.5\" fill=\"currentColor\" stroke=\"none\"/>")],
3793
+ ["icon", X("<circle cx=\"8\" cy=\"8\" r=\"3\"/><circle cx=\"16\" cy=\"8\" r=\"3\"/><rect x=\"5\" y=\"13\" width=\"6\" height=\"6\" rx=\"1\"/><rect x=\"13\" y=\"13\" width=\"6\" height=\"6\" rx=\"1\"/>")],
3794
+ ["code", X("<polyline points=\"16 18 22 12 16 6\"/><polyline points=\"8 6 2 12 8 18\"/>")],
3795
+ ["expand", X("<polyline points=\"15 3 21 3 21 9\"/><polyline points=\"9 21 3 21 3 15\"/><line x1=\"21\" y1=\"3\" x2=\"14\" y2=\"10\"/><line x1=\"3\" y1=\"21\" x2=\"10\" y2=\"14\"/>")],
3796
+ ["foreColor", X("<path d=\"M4 20L12 4L20 20\"/><line x1=\"7.5\" y1=\"14\" x2=\"16.5\" y2=\"14\"/>")],
3797
+ ["backColor", X("<path d=\"M3 21v-4l9-9 4 4-9 9z\"/><path d=\"M12 8l4 4\"/>")],
3798
+ ["keyboard", X("<rect x=\"2\" y=\"6\" width=\"20\" height=\"12\" rx=\"2\"/><line x1=\"6\" y1=\"10\" x2=\"6\" y2=\"10\" stroke-width=\"2.5\"/><line x1=\"10\" y1=\"10\" x2=\"10\" y2=\"10\" stroke-width=\"2.5\"/><line x1=\"14\" y1=\"10\" x2=\"14\" y2=\"10\" stroke-width=\"2.5\"/><line x1=\"18\" y1=\"10\" x2=\"18\" y2=\"10\" stroke-width=\"2.5\"/><line x1=\"8\" y1=\"14\" x2=\"16\" y2=\"14\" stroke-width=\"2\"/>")],
3799
+ ["caption", X("<rect x=\"3\" y=\"3\" width=\"18\" height=\"11\" rx=\"2\"/><line x1=\"6\" y1=\"18\" x2=\"18\" y2=\"18\"/><line x1=\"9\" y1=\"21\" x2=\"15\" y2=\"21\"/>")],
3800
+ ["remove-format", X("<path d=\"m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21\"/><path d=\"M22 21H7\"/><path d=\"m5 11 9 9\"/>")],
3801
+ ["direction", X("<path d=\"M12 20V4\"/><path d=\"m9 7-3 3 3 3\"/><path d=\"M4 10h8\"/><path d=\"m15 7 3 3-3 3\"/><path d=\"M20 10h-8\"/>")],
3802
+ ["search", X("<circle cx=\"11\" cy=\"11\" r=\"7\"/><line x1=\"21\" y1=\"21\" x2=\"16.65\" y2=\"16.65\"/>")],
3803
+ ["find-replace", X("<circle cx=\"10\" cy=\"10\" r=\"6\"/><line x1=\"18\" y1=\"18\" x2=\"14.35\" y2=\"14.35\"/><path d=\"M16 19h6\"/><path d=\"M19 16v6\"/>")],
3804
+ ["inline-code", X("<path d=\"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1\"/><path d=\"M16 3h1a2 2 0 0 1 2 2v5c0 1.1.9 2 2 2a2 2 0 0 1-2 2v5a2 2 0 0 1-2 2h-1\"/>")],
3805
+ ["checklist", X("<rect x=\"3\" y=\"4\" width=\"5\" height=\"5\" rx=\"1\"/><path d=\"m4 6.5 1 1 2-2\"/><rect x=\"3\" y=\"13\" width=\"5\" height=\"5\" rx=\"1\"/><line x1=\"10\" y1=\"6.5\" x2=\"21\" y2=\"6.5\"/><line x1=\"10\" y1=\"15.5\" x2=\"21\" y2=\"15.5\"/>")],
3806
+ ["print", X("<path d=\"M6 9V2h12v7\"/><path d=\"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2\"/><rect x=\"6\" y=\"14\" width=\"12\" height=\"8\"/>")]
3807
+ ]), kr = /* @__PURE__ */ new Map([
3808
+ ["bold", "fa-bold"],
3809
+ ["italic", "fa-italic"],
3810
+ ["underline", "fa-underline"],
3811
+ ["strikethrough", "fa-strikethrough"],
3812
+ ["superscript", "fa-superscript"],
3813
+ ["subscript", "fa-subscript"],
3814
+ ["align-left", "fa-align-left"],
3815
+ ["align-center", "fa-align-center"],
3816
+ ["align-right", "fa-align-right"],
3817
+ ["align-justify", "fa-align-justify"],
3818
+ ["list-ul", "fa-list-ul"],
3819
+ ["list-ol", "fa-list-ol"],
3820
+ ["indent", "fa-indent"],
3821
+ ["outdent", "fa-outdent"],
3822
+ ["undo", "fa-rotate-left"],
3823
+ ["redo", "fa-rotate-right"],
3824
+ ["minus", "fa-minus"],
3825
+ ["link", "fa-link"],
3826
+ ["image", "fa-image"],
3827
+ ["code", "fa-code"],
3828
+ ["expand", "fa-expand"],
3829
+ ["emoji", "fa-face-smile"],
3830
+ ["icon", "fa-icons"],
3831
+ ["foreColor", "fa-font"],
3832
+ ["backColor", "fa-highlighter"],
3833
+ ["keyboard", "fa-keyboard"],
3834
+ ["remove-format", "fa-remove-format"],
3835
+ ["direction", "fa-arrow-right-arrow-left"],
3836
+ ["search", "fa-magnifying-glass"],
3837
+ ["find-replace", "fa-magnifying-glass-plus"],
3838
+ ["inline-code", "fa-code"],
3839
+ ["checklist", "fa-list-check"],
3840
+ ["print", "fa-print"]
3841
+ ]), Ar = class {
3842
+ constructor(e) {
3843
+ this.context = e, this.options = e.options, this.el = null, this._disposers = [], this._colorPickerClosers = [], this._refreshRaf = null;
3844
+ }
3845
+ initialize() {
3846
+ return this.el = x("div", {
3847
+ class: "an-toolbar",
3848
+ role: "toolbar",
3849
+ "aria-orientation": "horizontal",
3850
+ "aria-label": "Editor toolbar"
3851
+ }), this._faReady = this._detectFontAwesome(), this._buildButtons(), this._initRovingFocus(), this._btnMap = new Map((this.options.toolbar || []).flat().map(Dr).filter(Boolean).map((e) => [e.name, e])), this;
3852
+ }
3853
+ destroy() {
3854
+ this._refreshRaf && cancelAnimationFrame(this._refreshRaf), this._refreshRaf = null, this._disposers.forEach((e) => e()), this._disposers = [], this.el?.parentNode && this.el.remove(), this.el = null;
3855
+ }
3856
+ _buildButtons() {
3857
+ let e = this.options.toolbar || [], t = document.createDocumentFragment();
3858
+ e.forEach((e) => {
3859
+ let n = x("div", { class: "an-btn-group" });
3860
+ e.forEach((e) => {
3861
+ let t = Dr(e);
3862
+ if (!t) {
3863
+ console.warn(`[AutumnNote] Toolbar: button "${e}" not found in registry. Skipped.`);
3864
+ return;
3865
+ }
3866
+ let r;
3867
+ r = t.type === "select" ? this._createSelect(t) : t.type === "grid" ? this._createGridPicker(t) : t.type === "colorpicker" ? this._createColorPicker(t) : this._createButton(t), n.appendChild(r);
3868
+ }), t.appendChild(n);
3869
+ }), this.el.appendChild(t);
3870
+ }
3871
+ _createGridPicker(e) {
3872
+ let t = x("div", { class: "an-table-picker-wrap" }), n = x("button", {
3873
+ type: "button",
3874
+ class: this.options.useBootstrap ? this.options.toolbarButtonClass || "btn btn-sm btn-light" : "an-btn",
3875
+ title: this.context.locale.toolbar[e.name] || e.tooltip || "",
3876
+ "data-btn": e.name,
3877
+ "aria-label": this.context.locale.toolbar[e.name] || e.tooltip || e.name,
3878
+ "aria-haspopup": "true",
3879
+ "aria-expanded": "false"
3880
+ });
3881
+ this._faReady ? n.innerHTML = `<i class="${this.options.fontAwesomeClass || "fas"} fa-table" aria-hidden="true"></i>` : n.innerHTML = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" style=\"display:block\"><rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"1\"/><line x1=\"3\" y1=\"9\" x2=\"21\" y2=\"9\"/><line x1=\"3\" y1=\"15\" x2=\"21\" y2=\"15\"/><line x1=\"9\" y1=\"3\" x2=\"9\" y2=\"21\"/><line x1=\"15\" y1=\"3\" x2=\"15\" y2=\"21\"/></svg>";
3882
+ let r = x("div", {
3883
+ class: "an-table-picker-popup",
3884
+ role: "dialog",
3885
+ "aria-label": "Select table size"
3886
+ }), i = x("div", { class: "an-table-grid" }), a = x("div", { class: "an-table-label" });
3887
+ a.textContent = this.context.locale.toolbar.insertTableLabel || "Insert Table";
3888
+ let o = [];
3889
+ for (let e = 1; e <= 10; e++) for (let t = 1; t <= 10; t++) {
3890
+ let n = x("div", {
3891
+ class: "an-table-cell",
3892
+ "data-row": String(e),
3893
+ "data-col": String(t)
3894
+ });
3895
+ o.push(n), i.appendChild(n);
3896
+ }
3897
+ r.appendChild(i), r.appendChild(a);
3898
+ let s = !1, c = (e, t) => {
3899
+ o.forEach((n) => {
3900
+ let r = +n.dataset.row, i = +n.dataset.col;
3901
+ n.classList.toggle("active", r <= e && i <= t);
3902
+ }), a.textContent = e && t ? `${e} × ${t}` : this.context.locale.toolbar.insertTableLabel || "Insert Table";
3903
+ }, l = () => {
3904
+ s = !0;
3905
+ let e = n.getBoundingClientRect();
3906
+ r.style.visibility = "hidden", r.style.display = "block";
3907
+ let t = r.offsetWidth, i = r.offsetHeight, a = e.left, o = e.bottom + 4;
3908
+ a + t > globalThis.innerWidth - 8 && (a = Math.max(8, globalThis.innerWidth - t - 8)), o + i > globalThis.innerHeight - 8 && (o = e.top - i - 4), r.style.left = `${a}px`, r.style.top = `${o}px`, r.style.visibility = "", n.setAttribute("aria-expanded", "true");
3909
+ }, u = () => {
3910
+ s = !1, r.style.display = "none", n.setAttribute("aria-expanded", "false"), c(0, 0);
3911
+ }, d = C(n, "click", (e) => {
3912
+ e.stopPropagation(), s ? u() : l();
3913
+ }), f = C(i, "mouseover", (e) => {
3914
+ let t = e.target?.closest(".an-table-cell");
3915
+ t && c(+t.dataset.row, +t.dataset.col);
3916
+ }), p = C(i, "mouseleave", () => c(0, 0)), m = C(i, "click", (t) => {
3917
+ let n = t.target?.closest(".an-table-cell");
3918
+ if (!n) return;
3919
+ let r = +n.dataset.row, i = +n.dataset.col;
3920
+ u(), this.context.invoke("editor.focus"), e.action(this.context, r, i);
3921
+ }), h = C(document, "click", () => {
3922
+ s && u();
3923
+ });
3924
+ return this._disposers.push(d, f, p, m, h, () => {
3925
+ r.parentNode && r.remove();
3926
+ }), t.appendChild(n), document.body.appendChild(r), t;
3927
+ }
3928
+ _createColorPicker(e) {
3929
+ let t = [
3930
+ "#000000",
3931
+ "#434343",
3932
+ "#666666",
3933
+ "#999999",
3934
+ "#b7b7b7",
3935
+ "#cccccc",
3936
+ "#efefef",
3937
+ "#ffffff",
3938
+ "#ff0000",
3939
+ "#ff9900",
3940
+ "#ffff00",
3941
+ "#00ff00",
3942
+ "#00ffff",
3943
+ "#4a86e8",
3944
+ "#9900ff",
3945
+ "#ff00ff",
3946
+ "#f4cccc",
3947
+ "#fce5cd",
3948
+ "#fff2cc",
3949
+ "#d9ead3",
3950
+ "#d0e0e3",
3951
+ "#c9daf8",
3952
+ "#d9d2e9",
3953
+ "#ead1dc"
3954
+ ], n = e.defaultColor || "#000000", r = x("div", { class: "an-color-picker-wrap" }), i = this.options.useBootstrap ? this.options.toolbarButtonClass || "btn btn-sm btn-light" : "an-btn", a = x("button", {
3955
+ type: "button",
3956
+ class: `${i} an-color-btn`,
3957
+ title: this.context.locale.toolbar[e.name] || e.tooltip || "",
3958
+ "data-btn": e.name,
3959
+ "aria-label": this.context.locale.toolbar[e.name] || e.tooltip || e.name
3960
+ }), o = "stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"";
3961
+ a.innerHTML = e.name === "foreColor" ? `<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" ${o} style="display:block"><path d="M4 20L12 4L20 20"/><line x1="7.5" y1="14" x2="16.5" y2="14"/></svg>` : `<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" ${o} style="display:block"><path d="M3 21v-4l9-9 4 4-9 9z"/><path d="M12 8l4 4"/></svg>`;
3962
+ let s = x("span", { class: "an-color-strip" });
3963
+ s.style.background = n, a.appendChild(s);
3964
+ let c = x("button", {
3965
+ type: "button",
3966
+ class: `${i} an-color-arrow`,
3967
+ title: e.name === "foreColor" ? this.context.locale.toolbar.chooseTextColor || "Choose text color" : this.context.locale.toolbar.chooseHighlightColor || "Choose highlight color",
3968
+ "aria-haspopup": "true",
3969
+ "aria-expanded": "false"
3970
+ });
3971
+ c.innerHTML = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"8\" height=\"8\" viewBox=\"0 0 24 24\" fill=\"currentColor\" stroke=\"none\" style=\"display:block\"><path d=\"M7 10l5 5 5-5H7z\"/></svg>";
3972
+ let l = x("div", { class: "an-color-popup" });
3973
+ l.style.display = "none";
3974
+ let u = x("div", { class: "an-color-swatches" }), d = Array.isArray(this.options.colorSwatches) ? this.options.colorSwatches : [];
3975
+ [.../* @__PURE__ */ new Set([...d, ...t])].forEach((e) => {
3976
+ let t = x("div", {
3977
+ class: "an-color-swatch",
3978
+ title: e,
3979
+ "data-color": e
3980
+ });
3981
+ t.style.background = e, u.appendChild(t);
3982
+ });
3983
+ let f = x("div", { class: "an-color-custom" }), p = x("input", {
3984
+ type: "color",
3985
+ value: n,
3986
+ title: this.context.locale.toolbar.customColor || "Custom color"
3987
+ }), m = x("span", {}, [this.context.locale.toolbar.customColor || "Custom color"]);
3988
+ f.appendChild(p), f.appendChild(m), l.appendChild(u), l.appendChild(f);
3989
+ let h = !1, g = null, ee = () => {
3990
+ let e = globalThis.getSelection();
3991
+ g = e?.rangeCount ? e.getRangeAt(0).cloneRange() : null;
3992
+ }, te = () => {
3993
+ if (g) try {
3994
+ let e = globalThis.getSelection();
3995
+ if (!e) return;
3996
+ e.removeAllRanges(), e.addRange(g);
3997
+ } catch {}
3998
+ }, ne = () => {
3999
+ this._colorPickerClosers.forEach((e) => {
4000
+ e !== _ && e();
4001
+ }), ee(), h = !0;
4002
+ let e = c.getBoundingClientRect(), t = e.left;
4003
+ t + 184 > globalThis.innerWidth && (t = e.right - 184), l.style.top = `${e.bottom + 4}px`, l.style.left = `${Math.max(4, t)}px`, l.style.display = "block", c.setAttribute("aria-expanded", "true");
4004
+ }, _ = () => {
4005
+ h = !1, l.style.display = "none", l.style.top = "", l.style.left = "", c.setAttribute("aria-expanded", "false");
4006
+ }, v = (t) => {
4007
+ n = t, s.style.background = t, p.value = t, te(), e.action(this.context, t), this.context.invoke("editor.afterCommand"), _();
4008
+ }, re = C(a, "click", (t) => {
4009
+ t.preventDefault(), te(), e.action(this.context, n), this.context.invoke("editor.afterCommand");
4010
+ }), ie = C(c, "mousedown", (e) => {
4011
+ e.preventDefault();
4012
+ }), y = C(c, "click", (e) => {
4013
+ e.stopPropagation(), h ? _() : ne();
4014
+ }), b = C(u, "mousedown", (e) => {
4015
+ e.preventDefault();
4016
+ }), ae = C(u, "click", (e) => {
4017
+ let t = e.target?.closest(".an-color-swatch");
4018
+ t && v(t.dataset.color);
4019
+ }), oe = C(p, "change", (e) => {
4020
+ v(e.target.value);
4021
+ }), se = C(document, "click", (e) => {
4022
+ h && !r.contains(e.target) && !l.contains(e.target) && _();
4023
+ }), ce = C(l, "click", (e) => e.stopPropagation()), S = () => {
4024
+ h && _();
4025
+ };
4026
+ return document.addEventListener("scroll", S, {
4027
+ passive: !0,
4028
+ capture: !0
4029
+ }), globalThis.addEventListener("resize", S, { passive: !0 }), this._disposers.push(re, ie, y, b, ae, oe, se, ce, () => document.removeEventListener("scroll", S, { capture: !0 }), () => globalThis.removeEventListener("resize", S), () => {
4030
+ l.parentNode && l.remove();
4031
+ }), this._colorPickerClosers.push(_), this._disposers.push(() => {
4032
+ let e = this._colorPickerClosers.indexOf(_);
4033
+ e !== -1 && this._colorPickerClosers.splice(e, 1);
4034
+ }), r.appendChild(a), r.appendChild(c), document.body.appendChild(l), r;
4035
+ }
4036
+ _createSelect(e) {
4037
+ let t = e.name === "fontFamily" ? this.options.fontFamilies || [] : e.items || [], n = x("select", {
4038
+ class: e.selectClass ? `an-select ${e.selectClass}` : "an-select",
4039
+ title: this.context.locale.toolbar[e.name] || e.tooltip || "",
4040
+ "data-btn": e.name,
4041
+ "aria-label": this.context.locale.toolbar[e.name] || e.tooltip || e.name
4042
+ }), r = x("option", {
4043
+ value: "",
4044
+ disabled: "",
4045
+ hidden: ""
4046
+ }, [this.context.locale.toolbar[e.name + "Placeholder"] || e.placeholder || "Font"]);
4047
+ n.appendChild(r), t.forEach((t) => {
4048
+ let r = typeof t == "object" ? t.value : t, i;
4049
+ i = typeof t == "object" ? e.name === "paragraphStyle" && this.context.locale.toolbar.paragraphItems?.[t.value] || t.label : t;
4050
+ let a = typeof t == "object" && !!t.disabled, o = { value: r };
4051
+ a && (o.disabled = "");
4052
+ let s = x("option", o, [i]);
4053
+ e.name === "fontFamily" && !a && (s.style.fontFamily = r), n.appendChild(s);
4054
+ });
4055
+ let i = null, a = C(n, "mousedown", () => {
4056
+ let e = globalThis.getSelection();
4057
+ i = e?.rangeCount ? e.getRangeAt(0).cloneRange() : null;
4058
+ }), o = C(n, "change", (t) => {
4059
+ let n = t.target.value, r = t.target.options[t.target.selectedIndex];
4060
+ if (!(!n || r.disabled)) {
4061
+ if (this.context.invoke("editor.focus"), i) try {
4062
+ let e = globalThis.getSelection();
4063
+ e && (e.removeAllRanges(), e.addRange(i));
4064
+ } catch {}
4065
+ e.action(this.context, n), this.context.invoke("editor.afterCommand");
4066
+ }
4067
+ });
4068
+ return this._disposers.push(a, o), n;
4069
+ }
4070
+ _createButton(e) {
4071
+ let t = x("button", {
4072
+ type: "button",
4073
+ class: `${this.options.useBootstrap ? this.options.toolbarButtonClass || "btn btn-sm btn-light" : "an-btn"}${e.className ? ` ${e.className}` : ""}`,
4074
+ title: this.context.locale.toolbar[e.name] || e.tooltip || "",
4075
+ "data-btn": e.name,
4076
+ "aria-label": this.context.locale.toolbar[e.name] || e.tooltip || e.name,
4077
+ ...typeof e.isActive == "function" ? { "aria-pressed": "false" } : {}
4078
+ }), n = this.options.fontAwesomeClass || "fas";
4079
+ if (this._faReady) {
4080
+ let r = kr.get(e.icon) || kr.get(e.name) || null;
4081
+ r ? t.innerHTML = `<i class="${n} ${r}" aria-hidden="true"></i>` : Z.has(e.icon) ? t.innerHTML = Z.get(e.icon) : t.textContent = e.icon || e.name;
4082
+ } else Z.has(e.icon) ? t.innerHTML = Z.get(e.icon) : Z.has(e.name) ? t.innerHTML = Z.get(e.name) : t.textContent = e.icon || e.name;
4083
+ let r = C(t, "click", (t) => {
4084
+ t.preventDefault(), this.context.invoke("editor.focus"), e.action(this.context), this.context.invoke("editor.afterCommand"), this.refresh();
4085
+ });
4086
+ return this._disposers.push(r), t;
4087
+ }
4088
+ _controls() {
4089
+ return this.el ? Array.from(this.el.querySelectorAll("button, select")) : [];
4090
+ }
4091
+ _navigable() {
4092
+ return this._controls().filter((e) => !e.disabled);
4093
+ }
4094
+ _syncRovingTabindex(e) {
4095
+ let t = this._controls(), n = this._navigable();
4096
+ if (!n.length) return;
4097
+ let r = e && n.includes(e) ? e : n.find((e) => e.getAttribute("tabindex") === "0") || n[0];
4098
+ t.forEach((e) => e.setAttribute("tabindex", e === r ? "0" : "-1"));
4099
+ }
4100
+ _initRovingFocus() {
4101
+ this.el && (this._syncRovingTabindex(), this._disposers.push(C(this.el, "keydown", (e) => this._onToolbarKeydown(e)), C(this.el, "focusin", (e) => {
4102
+ let t = e.target?.closest?.("button, select");
4103
+ t && this._syncRovingTabindex(t);
4104
+ })));
4105
+ }
4106
+ _onToolbarKeydown(e) {
4107
+ if (![
4108
+ "ArrowRight",
4109
+ "ArrowLeft",
4110
+ "Home",
4111
+ "End"
4112
+ ].includes(e.key)) return;
4113
+ let t = this._navigable(), n = e.target?.closest?.("button, select"), r = n ? t.indexOf(n) : -1;
4114
+ if (r === -1) return;
4115
+ let i;
4116
+ if (e.key === "Home") i = t[0];
4117
+ else if (e.key === "End") i = t.at(-1);
4118
+ else {
4119
+ let n = this.options.direction === "rtl";
4120
+ i = t[(r + (e.key === "ArrowRight" === n ? -1 : 1) + t.length) % t.length];
4121
+ }
4122
+ i && (e.preventDefault(), this._syncRovingTabindex(i), i.focus());
4123
+ }
4124
+ _detectFontAwesome() {
4125
+ if (!this.options.useFontAwesome) return !1;
4126
+ if (Y !== null) return Y;
4127
+ if (document.querySelector(".fa, .fas, .far, .fal, .fab, .fa-solid")) return Y = !0, !0;
4128
+ let e = Array.from(document.querySelectorAll("link[rel=\"stylesheet\"]")).filter((e) => e.id !== "an-fontawesome-css").map((e) => e.href || "").join(" ");
4129
+ return Y = /fontawesome|font-awesome|use\.fontawesome|all\.css/.test(e), Y;
4130
+ }
4131
+ refresh() {
4132
+ this._refreshRaf && cancelAnimationFrame(this._refreshRaf), this._refreshRaf = requestAnimationFrame(() => {
4133
+ this._refreshRaf = null, this._doRefresh();
4134
+ });
4135
+ }
4136
+ _doRefresh() {
4137
+ if (!this.el) return;
4138
+ let e = this._btnMap || /* @__PURE__ */ new Map();
4139
+ this.el.querySelectorAll("button[data-btn]").forEach((t) => {
4140
+ let n = e.get(t.dataset.btn);
4141
+ if (n && typeof n.isActive == "function") {
4142
+ let e = !!n.isActive(this.context);
4143
+ t.classList.toggle("active", e), t.setAttribute("aria-pressed", String(e));
4144
+ }
4145
+ n && typeof n.isDisabled == "function" && (t.disabled = !!n.isDisabled(this.context));
4146
+ }), this._syncRovingTabindex(), this.el.querySelectorAll("select[data-btn]").forEach((t) => {
4147
+ let n = e.get(t.dataset.btn);
4148
+ if (!n || typeof n.getValue != "function") return;
4149
+ let r = (n.getValue(this.context) || "").replace(/["']/g, "").trim();
4150
+ r ||= this.options.defaultFontFamily || this.options.fontFamilies?.[0] || "";
4151
+ let i = t, a = Array.from(i.options).find((e) => e.value?.toLowerCase() === r.toLowerCase());
4152
+ i.value = a ? a.value : "";
4153
+ });
4154
+ }
4155
+ show() {
4156
+ this.el && (this.el.style.display = "");
4157
+ }
4158
+ hide() {
4159
+ this.el && (this.el.style.display = "none");
4160
+ }
4161
+ rebuild() {
4162
+ this._refreshRaf &&= (cancelAnimationFrame(this._refreshRaf), null), this._disposers.forEach((e) => e()), this._disposers = [], this.el && (this.el.innerHTML = ""), this._faReady = this._detectFontAwesome(), this._buildButtons(), this._initRovingFocus(), this._btnMap = new Map((this.options.toolbar || []).flat().map(Dr).filter(Boolean).map((e) => [e.name, e])), this.refresh();
4163
+ }
4164
+ }, jr = typeof Intl < "u" && typeof Intl.Segmenter == "function" ? new Intl.Segmenter(void 0, { granularity: "word" }) : null;
4165
+ function Mr(e) {
4166
+ let t = e.trim();
4167
+ if (!t) return 0;
4168
+ if (jr) {
4169
+ let e = 0;
4170
+ for (let n of jr.segment(t)) n.isWordLike && e++;
4171
+ return e;
4172
+ }
4173
+ return t.split(/\s+/).length;
4174
+ }
4175
+ var Nr = /* @__PURE__ */ new Set(/* @__PURE__ */ "ADDRESS.ARTICLE.ASIDE.BLOCKQUOTE.BR.DD.DIV.DL.DT.FIELDSET.FIGCAPTION.FIGURE.FOOTER.FORM.H1.H2.H3.H4.H5.H6.HEADER.HR.LI.MAIN.NAV.OL.P.PRE.SECTION.TABLE.TBODY.TD.TFOOT.TH.THEAD.TR.UL".split("."));
4176
+ function Pr(e, t, n) {
4177
+ for (let r = e.firstChild; r; r = r.nextSibling) if (r.nodeType === 3) {
4178
+ let e = r.data;
4179
+ t.push(e), n.push(e);
4180
+ } else if (r.nodeType === 1) {
4181
+ let e = Nr.has(r.tagName);
4182
+ e && t.push("\n"), Pr(r, t, n), e && t.push("\n");
4183
+ }
4184
+ }
4185
+ function Fr(e) {
4186
+ if (e.nodeType === 3) {
4187
+ let t = e.data;
4188
+ return {
4189
+ lines: t,
4190
+ flat: t
4191
+ };
4192
+ }
4193
+ let t = [], n = [];
4194
+ return Pr(e, t, n), {
4195
+ lines: t.join(""),
4196
+ flat: n.join("")
4197
+ };
4198
+ }
4199
+ function Ir(e, t, n) {
4200
+ if (!n) {
4201
+ e.classList.remove("an-count-warn", "an-count-exceeded");
4202
+ return;
4203
+ }
4204
+ t > n ? (e.classList.add("an-count-exceeded"), e.classList.remove("an-count-warn")) : t >= n * .9 ? (e.classList.add("an-count-warn"), e.classList.remove("an-count-exceeded")) : e.classList.remove("an-count-warn", "an-count-exceeded");
4205
+ }
4206
+ var Lr = class {
4207
+ constructor(e) {
4208
+ this.context = e, this.options = e.options, this.el = null, this._disposers = [], this._wordCountEl = null, this._charCountEl = null, this._countCache = /* @__PURE__ */ new WeakMap();
4209
+ }
4210
+ initialize() {
4211
+ if (this.el = x("div", { class: "an-statusbar" }), this.options.resizable !== !1) {
4212
+ let e = x("div", {
4213
+ class: "an-resize-handle",
4214
+ title: this.context.locale.statusbar.resizeHandle,
4215
+ "aria-hidden": "true"
4216
+ });
4217
+ this._bindResize(e), this.el.appendChild(e);
4218
+ }
4219
+ this._wordCountEl = x("span", {
4220
+ class: "an-word-count",
4221
+ role: "status",
4222
+ "aria-live": "polite",
4223
+ "aria-atomic": "true"
4224
+ }), this._charCountEl = x("span", {
4225
+ class: "an-char-count",
4226
+ "aria-live": "polite",
4227
+ "aria-atomic": "true"
4228
+ });
4229
+ let e = x("div", {
4230
+ class: "an-status-info",
4231
+ "aria-label": "Editor statistics"
4232
+ });
4233
+ return e.appendChild(this._wordCountEl), e.appendChild(this._charCountEl), this.el.appendChild(e), this.update(), this;
4234
+ }
4235
+ destroy() {
4236
+ this._disposers.forEach((e) => e()), this._disposers = [], this._dragDisposers &&= (this._dragDisposers.forEach((e) => e()), null), this.el?.remove(), this.el = null;
4237
+ }
4238
+ _bindResize(e) {
4239
+ let t = 0, n = 0, r = this.context.layoutInfo.container, i = (e) => {
4240
+ let i = e - t, a = Array.from(r.children).filter((e) => !e.classList.contains("an-editable")).reduce((e, t) => e + t.offsetHeight, 0), o = Math.max(this.options.minHeight || 100, a + 40);
4241
+ r.style.height = `${Math.max(o, n + i)}px`;
4242
+ }, a = (e) => i(e.clientY), o = () => {
4243
+ document.removeEventListener("mousemove", a), document.removeEventListener("mouseup", o), this._dragDisposers = null;
4244
+ }, s = (e) => {
4245
+ t = e.clientY, n = r.offsetHeight, this.context.layoutInfo.editable.style.minHeight = "", document.addEventListener("mousemove", a), document.addEventListener("mouseup", o), this._dragDisposers = [() => document.removeEventListener("mousemove", a), () => document.removeEventListener("mouseup", o)], e.preventDefault();
4246
+ }, c = (e) => {
4247
+ let t = e.touches[0];
4248
+ t && (e.preventDefault(), i(t.clientY));
4249
+ }, l = () => {
4250
+ document.removeEventListener("touchmove", c), document.removeEventListener("touchend", l), this._dragDisposers = null;
4251
+ }, u = (e) => {
4252
+ let i = e.touches[0];
4253
+ i && (t = i.clientY, n = r.offsetHeight, this.context.layoutInfo.editable.style.minHeight = "", document.addEventListener("touchmove", c, { passive: !1 }), document.addEventListener("touchend", l), this._dragDisposers = [() => document.removeEventListener("touchmove", c), () => document.removeEventListener("touchend", l)]);
4254
+ }, d = C(e, "mousedown", s), f = C(e, "touchstart", u);
4255
+ this._disposers.push(d, f);
4256
+ }
4257
+ _counts() {
4258
+ let e = this.context.layoutInfo.editable, t = 0, n = 0, r = [], i = [], a = 0;
4259
+ for (let o = e.firstChild; o; o = o.nextSibling) {
4260
+ let e = this._countCache.get(o);
4261
+ if (e && e.key === (o.textContent || "")) {
4262
+ t += e.words, n += e.chars;
4263
+ continue;
4264
+ }
4265
+ let { lines: s, flat: c } = Fr(o);
4266
+ r.push({
4267
+ node: o,
4268
+ key: c,
4269
+ text: s,
4270
+ start: a
4271
+ }), i.push(s), a += s.length + 1;
4272
+ }
4273
+ if (r.length) {
4274
+ let e = this._countBatch(r, i.join("\n"));
4275
+ r.forEach((r, i) => {
4276
+ let a = {
4277
+ key: r.key,
4278
+ words: e[i],
4279
+ chars: r.key.replaceAll("\n", "").length
4280
+ };
4281
+ this._countCache.set(r.node, a), t += a.words, n += a.chars;
4282
+ });
4283
+ }
4284
+ return {
4285
+ words: t,
4286
+ chars: n
4287
+ };
4288
+ }
4289
+ _countBatch(e, t) {
4290
+ if (!jr) return e.map((e) => Mr(e.text));
4291
+ let n = Array(e.length).fill(0), r = 0;
4292
+ for (let i of jr.segment(t)) if (i.isWordLike) {
4293
+ for (; r < e.length - 1 && i.index >= e[r + 1].start;) r++;
4294
+ n[r]++;
4295
+ }
4296
+ return n;
4297
+ }
4298
+ update() {
4299
+ if (!this._wordCountEl || !this._charCountEl) return;
4300
+ let { words: e, chars: t } = this._counts(), n = this.options.maxWords || 0, r = this.options.maxChars || 0, i = this.context.locale.statusbar;
4301
+ this._wordCountEl.textContent = n ? i.wordsLimit(e, n) : i.words(e), this._charCountEl.textContent = r ? i.charsLimit(t, r) : i.chars(t), Ir(this._wordCountEl, e, n), Ir(this._charCountEl, t, r);
4302
+ }
4303
+ getWordCount() {
4304
+ return this._counts().words;
4305
+ }
4306
+ getCharCount() {
4307
+ return this._counts().chars;
4308
+ }
4309
+ }, Rr = class {
4310
+ constructor(e) {
4311
+ this.context = e, this.options = e.options, this._disposers = [];
4312
+ }
4313
+ initialize() {
4314
+ this._blobRegistry = /* @__PURE__ */ new Map(), this._forcePlain = !1;
4315
+ let e = this.context.layoutInfo.editable;
4316
+ return this._disposers.push(C(e, "paste", (e) => this._onPaste(e)), C(e, "dragover", (e) => this._onDragover(e)), C(e, "drop", (e) => this._onDrop(e))), this._mutationObserver = new MutationObserver((e) => {
4317
+ for (let t of e) for (let e of t.removedNodes) this._revokeRemovedBlobs(e);
4318
+ }), this._mutationObserver.observe(e, {
4319
+ childList: !0,
4320
+ subtree: !0
4321
+ }), this;
4322
+ }
4323
+ destroy() {
4324
+ this._disposers.forEach((e) => e()), this._disposers = [], this._mutationObserver &&= (this._mutationObserver.disconnect(), null), this._blobRegistry && (this._blobRegistry.forEach((e, t) => URL.revokeObjectURL(t)), this._blobRegistry.clear()), this._uploadPreviews && (this._uploadPreviews.forEach(({ previewUrl: e }) => URL.revokeObjectURL(e)), this._uploadPreviews.clear());
4325
+ }
4326
+ _revokeRemovedBlobs(e) {
4327
+ if (!this._blobRegistry?.size) return;
4328
+ let t = [];
4329
+ e.nodeName === "IMG" ? t.push(e) : e.querySelectorAll && t.push(...e.querySelectorAll("img")), t.forEach((e) => {
4330
+ let t = e.getAttribute("src") || "";
4331
+ t.startsWith("blob:") && this._blobRegistry.has(t) && (URL.revokeObjectURL(t), this._blobRegistry.delete(t));
4332
+ });
4333
+ }
4334
+ _cleanWordHtml(e) {
4335
+ return e.replace(/<!--\[if[\s\S]*?\[endif\]-->/gi, "").replace(/<xml[\s\S]*?<\/xml>/gi, "").replace(/<\?xml[\s\S]*?\?>/gi, "").replace(/<\/?(o|w|m|v|st1):[a-z][^>]*>/gi, "").replace(/\s+class="Mso[^"]*"/gi, "").replace(/\s+style="([^"]*)"/gi, (e, t) => {
4336
+ let n = t.split(";").map((e) => e.trim()).filter((e) => e && !/^mso-/i.test(e) && !/^(tab-stops|margin-[a-z]+-alt)/i.test(e)).join("; ");
4337
+ return n ? ` style="${n}"` : "";
4338
+ }).replace(/<p[^>]*>\s*(&nbsp;)?\s*<\/p>/gi, "");
4339
+ }
4340
+ _cleanSocialHtml(e) {
4341
+ let t = new DOMParser().parseFromString(`<body>${e}</body>`, "text/html"), n = Array.from(t.querySelectorAll("span, div"));
4342
+ for (let e = n.length - 1; e >= 0; e--) {
4343
+ let t = n[e];
4344
+ if (!t.parentNode || t.querySelector("a, strong, em, b, i, ul, ol, li, table, img, blockquote, pre, code, h1, h2, h3, h4, h5, h6")) continue;
4345
+ let r = t.parentNode;
4346
+ for (; t.firstChild;) r.insertBefore(t.firstChild, t);
4347
+ t.remove();
4348
+ }
4349
+ return t.querySelectorAll("*").forEach((e) => {
4350
+ e.removeAttribute("class"), e.removeAttribute("id"), Array.from(e.attributes).filter((e) => e.name.startsWith("data-") || e.name.startsWith("aria-")).forEach((t) => e.removeAttribute(t.name));
4351
+ }), t.body.innerHTML;
4352
+ }
4353
+ _stripAttributes(e) {
4354
+ let t = new DOMParser().parseFromString(`<body>${e}</body>`, "text/html"), n = /* @__PURE__ */ new Set([
4355
+ "href",
4356
+ "src",
4357
+ "alt",
4358
+ "target",
4359
+ "rel",
4360
+ "colspan",
4361
+ "rowspan",
4362
+ "type"
4363
+ ]);
4364
+ return t.querySelectorAll("*").forEach((e) => {
4365
+ Array.from(e.attributes).filter((e) => !n.has(e.name)).forEach((t) => e.removeAttribute(t.name));
4366
+ }), t.body.innerHTML;
4367
+ }
4368
+ _normalizeExternalTaskLists(e) {
4369
+ let t = new DOMParser().parseFromString(`<body>${e}</body>`, "text/html");
4370
+ for (let e of t.querySelectorAll("input[type=\"checkbox\"]")) {
4371
+ let t = e.closest("li"), n = t?.closest("ul");
4372
+ if (!(!t || !n || n.classList.contains("an-checklist"))) {
4373
+ n.classList.add("an-checklist"), e.removeAttribute("disabled"), e.setAttribute("contenteditable", "false");
4374
+ for (let t of Array.from(e.attributes)) [
4375
+ "type",
4376
+ "checked",
4377
+ "contenteditable"
4378
+ ].includes(t.name) || e.removeAttribute(t.name);
4379
+ }
4380
+ }
4381
+ return t.body.innerHTML;
4382
+ }
4383
+ _isTriviallyPlainHtml(e) {
4384
+ return !new DOMParser().parseFromString(`<body>${e}</body>`, "text/html").body.querySelector("a,img,table,ul,ol,li,blockquote,pre,code,h1,h2,h3,h4,h5,h6,strong,b,em,i,u,s,del,strike,hr,br");
4385
+ }
4386
+ setForcePlain(e) {
4387
+ this._forcePlain = !!e;
4388
+ }
4389
+ _onPaste(e) {
4390
+ let t = e.clipboardData || globalThis.clipboardData;
4391
+ if (!t) return;
4392
+ let n = this._forcePlain;
4393
+ this._forcePlain = !1;
4394
+ let r = (this.options.maxPasteSize ?? 5) * 1024 * 1024;
4395
+ if (r > 0) {
4396
+ let n = t.getData("text/plain") || "", i = t.getData("text/html") || "", a = Math.max(n.length, i.length);
4397
+ if (a > r) {
4398
+ e.preventDefault();
4399
+ let t = `Pasted content (${a} bytes) exceeds the ${this.options.maxPasteSize ?? 5} MB paste size limit.`;
4400
+ this.context.triggerEvent("pasteError", {
4401
+ size: a,
4402
+ maxBytes: r,
4403
+ message: t
4404
+ }), console.warn(`[AutumnNote] ${t}`);
4405
+ return;
4406
+ }
4407
+ }
4408
+ if (t.items) {
4409
+ let n = Array.from(t.items).filter((e) => e.kind === "file" && e.type.startsWith("image/"));
4410
+ if (n.length > 0) {
4411
+ e.preventDefault();
4412
+ let t = n.map((e) => e.getAsFile()).filter(Boolean);
4413
+ this._insertImageFiles(t);
4414
+ return;
4415
+ }
4416
+ }
4417
+ if (typeof this.options.onPaste == "function" && this.options.onPaste({
4418
+ text: t.getData("text/plain") || "",
4419
+ html: t.types.includes("text/html") ? t.getData("text/html") : null
4420
+ }), n || this.options.pasteAsPlainText) {
4421
+ e.preventDefault(), w("insertHTML", t.getData("text/plain").split(/\r?\n/).map((e) => `<p>${this._escapeHTML(e) || "<br>"}</p>`).join("")), this.context.invoke("editor.afterCommand");
4422
+ return;
4423
+ }
4424
+ if (this.options.markdownPaste !== !1) {
4425
+ let n = t.types.includes("text/html"), r = n ? t.getData("text/html") : "", i = !n || this._isTriviallyPlainHtml(r), a = t.getData("text/plain");
4426
+ if (a && i && zn(a)) {
4427
+ e.preventDefault(), w("insertHTML", j(H(a))), this.context.invoke("editor.afterCommand");
4428
+ return;
4429
+ }
4430
+ }
4431
+ if (this.options.pasteCleanHTML !== !1 && t.types.includes("text/html")) {
4432
+ e.preventDefault();
4433
+ let n = t.getData("text/html"), r = /<[a-z]+:[a-z]/i.test(n) || /class="Mso/i.test(n) || /\bmso-/i.test(n), i = /class="[^"]*\b(?:x[a-z0-9]{6,}|r-[a-z0-9]{3,})\b/.test(n), a = n;
4434
+ r ? a = this._cleanWordHtml(a) : i && (a = this._cleanSocialHtml(a)), a = this._normalizeExternalTaskLists(a), a = j(a), this.options.pasteStripAttributes && (a = this._stripAttributes(a)), w("insertHTML", a), this.context.invoke("editor.afterCommand");
4435
+ }
4436
+ }
4437
+ _onDragover(e) {
4438
+ e.dataTransfer && Array.from(e.dataTransfer.types || []).includes("Files") && (e.preventDefault(), e.dataTransfer.dropEffect = "copy");
4439
+ }
4440
+ _onDrop(e) {
4441
+ let t = e.dataTransfer;
4442
+ if (!t?.files?.length) return;
4443
+ let n = Array.from(t.files).filter((e) => e.type.startsWith("image/"));
4444
+ if (n.length > 0) {
4445
+ e.preventDefault(), e.stopPropagation(), this._placeCaretAtPoint(e.clientX, e.clientY), this._insertImageFiles(n);
4446
+ return;
4447
+ }
4448
+ if (this.options.markdownPaste !== !1) {
4449
+ let n = Array.from(t.files).find((e) => /\.md$/i.test(e.name) || e.type === "text/markdown");
4450
+ n && (e.preventDefault(), e.stopPropagation(), this._placeCaretAtPoint(e.clientX, e.clientY), this._insertMarkdownFile(n));
4451
+ }
4452
+ }
4453
+ _insertMarkdownFile(e) {
4454
+ let t = (this.options.maxPasteSize ?? 5) * 1024 * 1024;
4455
+ if (t > 0 && e.size > t) {
4456
+ let n = `Dropped file "${e.name}" (${e.size} bytes) exceeds the ${this.options.maxPasteSize ?? 5} MB paste size limit.`;
4457
+ this.context.triggerEvent("pasteError", {
4458
+ size: e.size,
4459
+ maxBytes: t,
4460
+ message: n
4461
+ }), console.warn(`[AutumnNote] ${n}`);
4462
+ return;
4463
+ }
4464
+ let n = new FileReader();
4465
+ n.onload = (e) => {
4466
+ w("insertHTML", j(H(e.target.result || ""))), this.context.invoke("editor.afterCommand");
4467
+ }, n.onerror = () => {
4468
+ let t = `Failed to read dropped markdown file "${e.name}".`;
4469
+ console.warn(`[AutumnNote] ${t}`), this.context.triggerEvent("pasteError", { message: t });
4470
+ }, n.readAsText(e);
4471
+ }
4472
+ _insertImageFiles(e) {
4473
+ if (!e || e.length === 0) return;
4474
+ if (typeof this.options.onImageUpload == "function") {
4475
+ this._runUploadHandler(e);
4476
+ return;
4477
+ }
4478
+ let t = /* @__PURE__ */ new Set([
4479
+ "image/tiff",
4480
+ "image/x-tiff",
4481
+ "image/bmp",
4482
+ "image/x-bmp",
4483
+ "image/x-ms-bmp"
4484
+ ]), n = (this.options.maxImageSize || 5) * 1024 * 1024;
4485
+ e.forEach((e) => {
4486
+ if (!e?.type?.startsWith("image/")) return;
4487
+ if (t.has(e.type)) {
4488
+ let t = `Image format "${e.type}" is not supported for display in web browsers. Please convert to PNG, JPEG, or WebP first.`;
4489
+ this.context.triggerEvent("imageError", {
4490
+ file: e,
4491
+ message: t
4492
+ }), console.warn("[AutumnNote]", t);
4493
+ return;
4494
+ }
4495
+ if (e.size > n) {
4496
+ let t = `Image "${e.name}" exceeds the ${this.options.maxImageSize || 5} MB size limit.`;
4497
+ this.context.triggerEvent("imageError", {
4498
+ file: e,
4499
+ message: t
4500
+ }), console.warn(`[AutumnNote] ${t}`);
4501
+ return;
4502
+ }
4503
+ let r = e.name.replace(/\.[^.]+$/, "");
4504
+ this.compressAndRegister(e).then((e) => {
4505
+ this.context.invoke("editor.insertImage", e, r);
4506
+ }).catch((t) => {
4507
+ let n = `Image "${e.name}" could not be processed.`;
4508
+ this.context.triggerEvent("imageError", {
4509
+ file: e,
4510
+ message: n,
4511
+ error: t
4512
+ }), console.warn("[AutumnNote]", n, t);
4513
+ });
4514
+ });
4515
+ }
4516
+ _escapeAttr(e) {
4517
+ return String(e).replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
4518
+ }
4519
+ async _runUploadHandler(e) {
4520
+ let t = {
4521
+ context: this.context,
4522
+ setProgress: (e, t) => this._setUploadProgress(e, t)
4523
+ }, n;
4524
+ try {
4525
+ n = this.options.onImageUpload(e, t);
4526
+ } catch (t) {
4527
+ this._reportUploadError(e, t);
4528
+ return;
4529
+ }
4530
+ if (n === void 0) return;
4531
+ let r = e.map((e) => this._insertUploadPlaceholder(e)), i;
4532
+ try {
4533
+ i = await n;
4534
+ } catch (t) {
4535
+ r.forEach((n, r) => this._failUpload(n, e[r], t));
4536
+ return;
4537
+ }
4538
+ let a = Array.isArray(i) ? i : [i];
4539
+ r.forEach((t, n) => {
4540
+ let r = a[n];
4541
+ typeof r == "string" && r ? this._resolveUpload(t, r) : this._failUpload(t, e[n], /* @__PURE__ */ Error("No URL returned for this file."));
4542
+ });
4543
+ }
4544
+ _insertUploadPlaceholder(e) {
4545
+ let t = `an-up-${Date.now().toString(36)}-${this._uploadSeq = (this._uploadSeq || 0) + 1}`, n = URL.createObjectURL(e);
4546
+ this._uploadPreviews = this._uploadPreviews || /* @__PURE__ */ new Map(), this._uploadPreviews.set(t, {
4547
+ previewUrl: n,
4548
+ file: e
4549
+ });
4550
+ let r = this._escapeAttr(e.name.replace(/\.[^.]+$/, ""));
4551
+ return w("insertHTML", `<img src="${this._escapeAttr(n)}" alt="${r}" class="an-image an-image-uploading" data-an-upload="${t}">`), this.context.invoke("editor.afterCommand"), t;
4552
+ }
4553
+ _findPlaceholder(e) {
4554
+ return this.context.layoutInfo.editable?.querySelector(`img[data-an-upload="${e}"]`) ?? null;
4555
+ }
4556
+ _resolveUpload(e, t) {
4557
+ let n = this._findPlaceholder(e), r = this._uploadPreviews?.get(e);
4558
+ if (n) {
4559
+ let i = M(t, { allowData: !0 });
4560
+ if (i) n.setAttribute("src", i), n.classList.remove("an-image-uploading"), n.removeAttribute("data-an-upload"), n.style.removeProperty("--an-upload-progress");
4561
+ else {
4562
+ this._failUpload(e, r?.file, /* @__PURE__ */ Error(`Rejected image URL: ${t}`));
4563
+ return;
4564
+ }
4565
+ }
4566
+ r && (URL.revokeObjectURL(r.previewUrl), this._uploadPreviews.delete(e)), this.context.invoke("editor.afterCommand");
4567
+ }
4568
+ _failUpload(e, t, n) {
4569
+ let r = this._findPlaceholder(e);
4570
+ r && (r.classList.remove("an-image-uploading"), r.classList.add("an-image-failed"), r.style.removeProperty("--an-upload-progress"));
4571
+ let i = `Image "${t?.name ?? "unknown"}" could not be uploaded.`;
4572
+ console.warn("[AutumnNote]", i, n), this.context.triggerEvent("imageError", {
4573
+ file: t,
4574
+ message: i,
4575
+ error: n,
4576
+ retry: () => {
4577
+ r?.remove(), this._uploadPreviews?.delete(e), t && this._runUploadHandler([t]);
4578
+ }
4579
+ });
4580
+ }
4581
+ _reportUploadError(e, t) {
4582
+ let n = "The image upload handler threw before any file was sent.";
4583
+ console.warn("[AutumnNote]", n, t), this.context.triggerEvent("imageError", {
4584
+ file: e[0],
4585
+ message: n,
4586
+ error: t
4587
+ });
4588
+ }
4589
+ _setUploadProgress(e, t) {
4590
+ if (!this._uploadPreviews) return;
4591
+ let n = Math.max(0, Math.min(1, Number(t) || 0));
4592
+ for (let [t, r] of this._uploadPreviews) {
4593
+ if (r.file !== e) continue;
4594
+ let i = this._findPlaceholder(t);
4595
+ i && i.style.setProperty("--an-upload-progress", String(n));
4596
+ return;
4597
+ }
4598
+ }
4599
+ async compressAndRegister(e) {
4600
+ let t = this.options.imageProcessor, n = typeof t == "function" ? await t(e, { context: this.context }) : await this._compressImage(e), r = this._dataUrlToBlob(n), i = URL.createObjectURL(r);
4601
+ return this._blobRegistry.set(i, n), i;
4602
+ }
4603
+ resolveImages(e) {
4604
+ return this._blobRegistry?.size ? e.replace(/blob:[^"'> \t\n\r]*/g, (e) => this._blobRegistry.get(e) || e) : e;
4605
+ }
4606
+ _dataUrlToBlob(e) {
4607
+ let [t, n] = e.split(","), r = /:(.*?);/.exec(t)?.[1] ?? "image/png", i = atob(n), a = new Uint8Array(i.length);
4608
+ for (let e = 0; e < i.length; e++) a[e] = i.charCodeAt(e);
4609
+ return new Blob([a], { type: r });
4610
+ }
4611
+ _compressImage(e) {
4612
+ let t = 1920, n = .85;
4613
+ return new Promise((r, i) => {
4614
+ let a = URL.createObjectURL(e), o = new Image();
4615
+ o.onload = () => {
4616
+ URL.revokeObjectURL(a);
4617
+ let { width: s, height: c } = o;
4618
+ (s > t || c > t) && (s >= c ? (c = Math.round(c * t / s), s = t) : (s = Math.round(s * t / c), c = t));
4619
+ let l = document.createElement("canvas");
4620
+ l.width = s, l.height = c;
4621
+ let u = l.getContext("2d");
4622
+ if (!u) {
4623
+ let t = new FileReader();
4624
+ t.onload = (e) => r(e.target.result), t.onerror = () => i(/* @__PURE__ */ Error("FileReader failed")), t.readAsDataURL(e);
4625
+ return;
4626
+ }
4627
+ u.drawImage(o, 0, 0, s, c);
4628
+ let d = l.toDataURL("image/webp", n);
4629
+ r(d.startsWith("data:image/webp") ? d : l.toDataURL("image/jpeg", n));
4630
+ }, o.onerror = () => {
4631
+ URL.revokeObjectURL(a);
4632
+ let t = new FileReader();
4633
+ t.onload = (e) => r(e.target.result), t.onerror = () => i(/* @__PURE__ */ Error("FileReader failed")), t.readAsDataURL(e);
4634
+ }, o.src = a;
4635
+ });
4636
+ }
4637
+ _placeCaretAtPoint(e, t) {
4638
+ let n;
4639
+ if (document.caretRangeFromPoint) n = document.caretRangeFromPoint(e, t);
4640
+ else if (document.caretPositionFromPoint) {
4641
+ let r = document.caretPositionFromPoint(e, t);
4642
+ r && (n = document.createRange(), n.setStart(r.offsetNode, r.offset), n.collapse(!0));
4643
+ }
4644
+ if (!n) return;
4645
+ let r = globalThis.getSelection();
4646
+ r && (r.removeAllRanges(), r.addRange(n));
4647
+ }
4648
+ _escapeHTML(e) {
4649
+ return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&#039;");
4650
+ }
4651
+ }, zr = /[^\s\u200B]/;
4652
+ function Br(e) {
4653
+ let t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
4654
+ for (let e = t.nextNode(); e; e = t.nextNode()) if (zr.test(e.data)) return !0;
4655
+ return !1;
4656
+ }
4657
+ //#endregion
4658
+ //#region src/js/presets/core.js
4659
+ var Vr = [
4660
+ {
4661
+ name: "editor",
4662
+ Class: Er
4663
+ },
4664
+ {
4665
+ name: "toolbar",
4666
+ Class: Ar
4667
+ },
4668
+ {
4669
+ name: "statusbar",
4670
+ Class: Lr
4671
+ },
4672
+ {
4673
+ name: "clipboard",
4674
+ Class: Rr
4675
+ },
4676
+ {
4677
+ name: "placeholder",
4678
+ Class: class {
4679
+ constructor(e) {
4680
+ this.context = e, this.options = e.options, this._disposers = [];
4681
+ }
4682
+ initialize() {
4683
+ let e = this.context.layoutInfo.editable, t = this.options.placeholder || "";
4684
+ t && (e.dataset.placeholder = t);
4685
+ let n = () => this._update(), r = C(e, "input", n), i = C(e, "focus", n), a = C(e, "blur", n);
4686
+ return this._disposers.push(r, i, a), this._update(), this;
4687
+ }
4688
+ destroy() {
4689
+ this._disposers.forEach((e) => e()), this._disposers = [];
4690
+ }
4691
+ _update() {
4692
+ let e = this.context.layoutInfo.editable, t = document.activeElement === e, n = !Br(e) && !e.querySelector("img, table, hr, .an-video-wrapper");
4693
+ e.classList.toggle("an-placeholder", n && !t);
4694
+ }
4695
+ }
4696
+ }
4697
+ ];
4698
+ //#endregion
4699
+ //#region src/js/core/lists.js
4700
+ function Hr(e) {
4701
+ return e[e.length - 1];
4702
+ }
4703
+ function Ur(e) {
4704
+ return e[0];
4705
+ }
4706
+ function Wr(e, t = 1) {
4707
+ return e.slice(0, e.length - t);
4708
+ }
4709
+ function Gr(e, t = 1) {
4710
+ return e.slice(t);
4711
+ }
4712
+ function Kr(e) {
4713
+ return e.flat();
4714
+ }
4715
+ function qr(e) {
4716
+ return [...new Set(e)];
4717
+ }
4718
+ function Jr(e, t) {
4719
+ let n = [];
4720
+ for (let r = 0; r < e.length; r += t) n.push(e.slice(r, r + t));
4721
+ return n;
4722
+ }
4723
+ function Yr(e, t) {
4724
+ return e.reduce((e, n) => {
4725
+ let r = t(n);
4726
+ return e[r] || (e[r] = []), e[r].push(n), e;
4727
+ }, {});
4728
+ }
4729
+ function Xr(e, t) {
4730
+ return e.every(t);
4731
+ }
4732
+ function Zr(e, t) {
4733
+ return e.some(t);
4734
+ }
4735
+ //#endregion
4736
+ //#region src/js/core/env.js
4737
+ function Q() {
4738
+ return globalThis.navigator?.userAgent ?? "";
4739
+ }
4740
+ var Qr = {
4741
+ get isChrome() {
4742
+ return /Chrome\//.test(Q()) && !/Edg\//.test(Q());
4743
+ },
4744
+ get isFF() {
4745
+ return /Firefox\//.test(Q());
4746
+ },
4747
+ get isSafari() {
4748
+ return /^((?!chrome|android).)*safari/i.test(Q());
4749
+ },
4750
+ get isEdge() {
4751
+ return /Edg\//.test(Q());
4752
+ },
4753
+ get isMac() {
4754
+ return /Macintosh/.test(Q());
4755
+ },
4756
+ get isMobile() {
4757
+ return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(Q());
4758
+ },
4759
+ get isTouch() {
4760
+ return "ontouchstart" in globalThis || (globalThis.navigator?.maxTouchPoints ?? 0) > 0;
4761
+ },
4762
+ get modifierKey() {
4763
+ return /Macintosh/.test(Q()) ? "metaKey" : "ctrlKey";
4764
+ }
4765
+ }, $r = { ...k }, $ = /* @__PURE__ */ new WeakMap(), ei = {
4766
+ create(e, t = {}) {
4767
+ let n = ti(e).map((e) => {
4768
+ if ($.has(e)) return $.get(e);
4769
+ let n = new Cn(e, t);
4770
+ return n.initialize(), $.set(e, n), n;
4771
+ });
4772
+ return n.length === 1 ? n[0] : n;
4773
+ },
4774
+ destroy(e) {
4775
+ ti(e).forEach((e) => {
4776
+ let t = $.get(e);
4777
+ t && (t.destroy(), $.delete(e));
4778
+ });
4779
+ },
4780
+ getInstance(e) {
4781
+ let t = typeof e == "string" ? document.querySelector(e) : e;
4782
+ return t && $.get(t) || null;
4783
+ },
4784
+ get defaults() {
4785
+ return { ...k };
4786
+ },
4787
+ setDefaults(e) {
4788
+ Object.assign(k, e);
4789
+ },
4790
+ resetDefaults() {
4791
+ Object.keys(k).forEach((e) => delete k[e]), Object.assign(k, $r);
4792
+ },
4793
+ registerModule(e, t) {
4794
+ bn.set(e, t);
4795
+ },
4796
+ use(e, t = {}) {
4797
+ if (!e || typeof e.name != "string") throw TypeError("[AutumnNote] AutumnNote.use: plugin must have a string `name` property.");
4798
+ return N.has(e.name) ? (console.warn(`[AutumnNote] Plugin "${e.name}" already registered globally. Skipping.`), this) : (Array.isArray(e.buttons) && e.buttons.forEach((e) => O(e)), N.set(e.name, {
4799
+ plugin: e,
4800
+ options: t
4801
+ }), this);
4802
+ },
4803
+ hasPlugin(e) {
4804
+ return N.has(e);
4805
+ },
4806
+ registerButton(e) {
4807
+ return O(e), this;
4808
+ },
4809
+ registerLocale(e, t) {
4810
+ return $t(e, t), this;
4811
+ },
4812
+ registerSlashCommand(e) {
4813
+ if (!e?.id || typeof e.run != "function") throw TypeError("[AutumnNote] Slash command requires an id and run(context) function.");
4814
+ let t = k.slashCommands, n = t.findIndex((t) => t.id === e.id);
4815
+ return n >= 0 ? t[n] = e : t.push(e), this;
4816
+ },
4817
+ buttons: Zt,
4818
+ version: "2.5.0"
4819
+ };
4820
+ function ti(e) {
4821
+ return typeof e == "string" ? Array.from(document.querySelectorAll(e)) : e instanceof Element ? [e] : e instanceof NodeList || Array.isArray(e) ? Array.from(e) : [];
4822
+ }
4823
+ //#endregion
4824
+ //#region src/js/core.js
4825
+ Sn(Vr);
4826
+ //#endregion
4827
+ export { Cn as Context, d as ELEMENT_NODE, br as SUPPORTED_LANGS, f as TEXT_NODE, ye as WrappedRange, D as _buttonRegistry, vt as alignCenterBtn, bt as alignJustifyBtn, _t as alignLeftBtn, yt as alignRightBtn, Xr as all, ae as ancestors, Zr as any, Yt as backColorBtn, dt as boldBtn, Zt as buttons, Kt as checklistBtn, oe as children, Jr as chunk, e as clamp, y as closest, b as closestPara, Bt as codeviewBtn, Ce as collapsedRange, r as compose, x as createElement, xe as currentRange, t as debounce, ei as default, k as defaultOptions, Xt as defaultToolbar, wr as detectLang, It as directionBtn, jt as emojiBtn, Qr as env, Ut as findBtn, Wt as findReplaceBtn, Ur as first, Kr as flatten, Lt as fontFamilyBtn, Pt as fontSizeBtn, Jt as foreColorBtn, be as fromNativeRange, Vt as fullscreenBtn, ut as getButton, Yr as groupBy, Dt as hrBtn, An as htmlToMarkdown, Mt as iconBtn, i as identity, kt as imageBtn, Ct as indentBtn, Wr as initial, Gt as inlineCodeBtn, de as insertAfter, re as isAnchor, v as isEditable, p as isElement, pe as isEmpty, s as isFunction, ie as isImage, _ as isInline, ge as isInsideEditable, F as isKey, ee as isLi, te as isList, zn as isMarkdown, I as isModifier, a as isNil, g as isPara, l as isPlainObject, we as isSelectionInside, o as isString, ne as isTable, m as isText, h as isVoid, ft as italicBtn, P as key, Hr as last, zt as lineHeightBtn, Ot as linkBtn, Qt as locales, ve as makeDraggable, H as markdownToHTML, c as mergeDeep, ce as nextElement, fe as nodeValue, St as olBtn, C as on, wt as outdentBtn, me as outerHtml, Rt as paragraphStyleBtn, he as placeCaret, se as prevElement, qt as printBtn, Se as rangeFromElement, u as rect2bnd, Et as redoBtn, O as registerButton, $t as registerLocale, S as remove, Ft as removeFormatBtn, en as resolveLocale, j as sanitiseHTML, mn as sanitiseToBody, M as sanitiseUrl, Ht as shortcutsBtn, Ee as splitText, mt as strikeBtn, gt as subscriptBtn, ht as superscriptBtn, Nt as tableBtn, Gr as tail, n as throttle, _e as trapFocus, xt as ulBtn, pt as underlineBtn, Tt as undoBtn, qr as unique, le as unwrap, At as videoBtn, Te as withSavedRange, ue as wrap };
4828
+
4829
+ //# sourceMappingURL=autumnnote.core.es.js.map