autumnnote 2.3.0 → 2.5.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,4755 @@
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 ae(e, t) {
67
+ return y(e, g, t);
68
+ }
69
+ function oe(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 se(e) {
75
+ return Array.from(e.childNodes);
76
+ }
77
+ function ce(e) {
78
+ let t = e.previousSibling;
79
+ for (; t && !p(t);) t = t.previousSibling;
80
+ return t;
81
+ }
82
+ function le(e) {
83
+ let t = e.nextSibling;
84
+ for (; t && !p(t);) t = t.nextSibling;
85
+ return t;
86
+ }
87
+ function b(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 x(e) {
94
+ e?.parentNode && e.remove();
95
+ }
96
+ function ue(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 de(e, t) {
104
+ return e.parentNode.insertBefore(t, e), t.appendChild(e), t;
105
+ }
106
+ function fe(e, t) {
107
+ t.nextSibling ? t.parentNode.insertBefore(e, t.nextSibling) : t.parentNode.appendChild(e);
108
+ }
109
+ function pe(e) {
110
+ return m(e) ? e.nodeValue : e.textContent || "";
111
+ }
112
+ function me(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 he(e) {
116
+ return e.outerHTML;
117
+ }
118
+ function ge(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 _e(e) {
125
+ return !!y(e, v);
126
+ }
127
+ function S(e, t, n, r) {
128
+ return e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r);
129
+ }
130
+ function ve(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 ye(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 C = 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 C(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 C(e, 0, e, e.childNodes.length);
213
+ }
214
+ function Ce(e, t = 0) {
215
+ return new C(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, { allowIframes: t = !1 } = {}) {
1463
+ 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);
1464
+ for (let e of r) {
1465
+ let t = e.tagName.toLowerCase();
1466
+ if (nn.has(t)) {
1467
+ e.replaceWith(...e.childNodes);
1468
+ continue;
1469
+ }
1470
+ if (i.has(t)) {
1471
+ e.remove();
1472
+ continue;
1473
+ }
1474
+ if (t === "iframe") {
1475
+ let t = e.getAttribute("src");
1476
+ if (!t || !gn(t)) {
1477
+ e.remove();
1478
+ continue;
1479
+ }
1480
+ }
1481
+ for (let t of Array.from(e.attributes)) {
1482
+ if (t.name.startsWith("on")) {
1483
+ e.removeAttribute(t.name);
1484
+ continue;
1485
+ }
1486
+ if (t.name === "style") {
1487
+ let n = mn(t.value);
1488
+ n ? e.setAttribute("style", n) : e.removeAttribute("style");
1489
+ continue;
1490
+ }
1491
+ if (on.has(t.name)) {
1492
+ e.removeAttribute(t.name);
1493
+ continue;
1494
+ }
1495
+ if (rn.includes(t.name)) {
1496
+ let n = t.value.trim(), r = an.has(t.name) || t.name === "src" && [
1497
+ "IMG",
1498
+ "VIDEO",
1499
+ "AUDIO",
1500
+ "SOURCE"
1501
+ ].includes(e.tagName), i = e.tagName === "IMG";
1502
+ if (!(t.name === "srcset" ? hn(n, { allowData: i }) : _n(n, {
1503
+ media: r,
1504
+ allowData: i
1505
+ }))) {
1506
+ e.removeAttribute(t.name);
1507
+ continue;
1508
+ }
1509
+ }
1510
+ if (e.tagName === "IFRAME") {
1511
+ if (t.name === "srcdoc") {
1512
+ e.removeAttribute(t.name);
1513
+ continue;
1514
+ }
1515
+ t.name === "src" && !gn(t.value) && e.removeAttribute(t.name);
1516
+ }
1517
+ }
1518
+ 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();
1519
+ else for (let t of Array.from(e.attributes)) [
1520
+ "type",
1521
+ "checked",
1522
+ "contenteditable"
1523
+ ].includes(t.name) || e.removeAttribute(t.name);
1524
+ }
1525
+ return n.body.innerHTML;
1526
+ }
1527
+ function mn(e) {
1528
+ let t = [];
1529
+ for (let n of (e || "").split(";")) {
1530
+ let e = n.indexOf(":");
1531
+ if (e === -1) continue;
1532
+ let r = n.slice(0, e).trim().toLowerCase(), i = n.slice(e + 1).trim();
1533
+ !r || !i || sn.has(r) && (cn.test(i) || t.push(`${r}: ${i}`));
1534
+ }
1535
+ return t.join("; ");
1536
+ }
1537
+ function hn(e, { allowData: t = !1 } = {}) {
1538
+ let n = (e || "").trim().split(/\s+/).filter(Boolean);
1539
+ for (let e of n) {
1540
+ if (/^[\d.]+[xw],?$/i.test(e)) continue;
1541
+ let n = e.replace(/,+$/, "");
1542
+ if (n && !_n(n, {
1543
+ media: !0,
1544
+ allowData: t
1545
+ })) return !1;
1546
+ }
1547
+ return !0;
1548
+ }
1549
+ function gn(e) {
1550
+ let t = (e || "").trim();
1551
+ if (!t || t.startsWith("//") || t.startsWith("/")) return !1;
1552
+ try {
1553
+ let e = new URL(t);
1554
+ return e.protocol === "https:" && ln.has(e.hostname.toLowerCase());
1555
+ } catch {
1556
+ return !1;
1557
+ }
1558
+ }
1559
+ function M(e, { allowData: t = !1, media: n = t } = {}) {
1560
+ let r = (e || "").trim();
1561
+ return !r && e == null ? null : _n(r, {
1562
+ media: n,
1563
+ allowData: t
1564
+ }) ? e : null;
1565
+ }
1566
+ function _n(e, { media: t = !1, allowData: n = !1 } = {}) {
1567
+ let r = (e || "").trim();
1568
+ if (!r || n && fn.test(r)) return !0;
1569
+ try {
1570
+ let e = new URL(r, pn);
1571
+ return (t ? dn : un).has(e.protocol);
1572
+ } catch {
1573
+ return !1;
1574
+ }
1575
+ }
1576
+ //#endregion
1577
+ //#region src/js/renderer.js
1578
+ function vn(e, t) {
1579
+ let n = b("div", { class: "an-container" }), r = b("div", {
1580
+ class: "an-editable",
1581
+ contenteditable: t.readOnly ? "false" : "true",
1582
+ spellcheck: String(t.spellcheck !== !1),
1583
+ "aria-multiline": "true",
1584
+ "aria-label": "Rich text editor",
1585
+ role: "textbox"
1586
+ }), i = "";
1587
+ if (t.autoSave && t.autoSaveKey) try {
1588
+ i = localStorage.getItem(t.autoSaveKey) || "";
1589
+ } catch {}
1590
+ i ||= e.tagName === "TEXTAREA" ? (e.value || "").trim() : (e.innerHTML || "").trim(), r.innerHTML = j(i, { allowIframes: !0 });
1591
+ let a = t.defaultFontFamily || t.fontFamilies?.[0];
1592
+ 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) => {
1593
+ e.setAttribute("disabled", "");
1594
+ })), 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), {
1595
+ container: n,
1596
+ editable: r
1597
+ };
1598
+ }
1599
+ //#endregion
1600
+ //#region src/js/Context.js
1601
+ var yn = /* @__PURE__ */ new Map(), bn = [];
1602
+ function xn(e) {
1603
+ bn = Array.isArray(e) ? e : [];
1604
+ }
1605
+ var N = /* @__PURE__ */ new Map(), Sn = class {
1606
+ constructor(e, t = {}) {
1607
+ 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;
1608
+ }
1609
+ initialize() {
1610
+ let { container: e, editable: t } = vn(this.targetEl, this.options);
1611
+ this.layoutInfo.container = e, this.layoutInfo.editable = t, this._registerModules();
1612
+ let n = this._modules.get("toolbar");
1613
+ n?.el && (e.insertBefore(n.el, t), this.layoutInfo.toolbar = n.el);
1614
+ let r = this._modules.get("statusbar");
1615
+ 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;
1616
+ }
1617
+ _registerModules() {
1618
+ let e = (e, t) => {
1619
+ let n = new t(this);
1620
+ this._modules.set(e, n), n.initialize();
1621
+ };
1622
+ for (let { name: t, Class: n, enabled: r } of bn) typeof r == "function" && !r(this.options) || e(t, n);
1623
+ if (yn.size > 0) for (let [t, n] of yn) e(t, n);
1624
+ }
1625
+ _syncOptionalModules() {
1626
+ for (let { name: e, Class: t, enabled: n } of bn) {
1627
+ if (typeof n != "function") continue;
1628
+ let r = n(this.options);
1629
+ if (r !== this._modules.has(e)) if (r) {
1630
+ let n = new t(this);
1631
+ this._modules.set(e, n), n.initialize();
1632
+ } else {
1633
+ let t = this._modules.get(e);
1634
+ typeof t?.destroy == "function" && t.destroy(), this._modules.delete(e);
1635
+ }
1636
+ }
1637
+ }
1638
+ registerModule(e, t) {
1639
+ if (this._modules.has(e)) return this;
1640
+ let n = new t(this);
1641
+ return n.initialize(), this._modules.set(e, n), this;
1642
+ }
1643
+ registerSlashCommand(e) {
1644
+ if (!e?.id || typeof e.run != "function") throw TypeError("[AutumnNote] Slash command requires an id and run(context) function.");
1645
+ let t = this.options.slashCommands || (this.options.slashCommands = []), n = t.findIndex((t) => t.id === e.id);
1646
+ return n >= 0 ? t[n] = e : t.push(e), this.invoke("slashMenu.refresh"), this;
1647
+ }
1648
+ use(e, t = {}) {
1649
+ return Array.isArray(e.buttons) && e.buttons.forEach((e) => O(e)), this._installPlugin(e, t), this;
1650
+ }
1651
+ getPlugin(e) {
1652
+ return this._plugins.get(e)?.publicApi ?? null;
1653
+ }
1654
+ _installPlugin(e, t = {}) {
1655
+ let { name: n } = e;
1656
+ if (!n || typeof n != "string") {
1657
+ console.warn("[AutumnNote] Plugin must have a string `name` property.");
1658
+ return;
1659
+ }
1660
+ if (this._plugins.has(n)) {
1661
+ console.warn(`[AutumnNote] Plugin "${n}" already installed on this instance. Skipping.`);
1662
+ return;
1663
+ }
1664
+ let r = typeof e.install == "function" ? e.install(this, t) ?? null : null;
1665
+ this._plugins.set(n, {
1666
+ plugin: e,
1667
+ publicApi: r
1668
+ });
1669
+ }
1670
+ _applyGlobalPlugins() {
1671
+ if (N.size !== 0) for (let { plugin: e, options: t } of N.values()) this._installPlugin(e, t);
1672
+ }
1673
+ _bindEditorEvents(e) {
1674
+ let t = S(e, "input", () => this._syncToTarget()), n = S(e, "focus", () => {
1675
+ this.layoutInfo.container.classList.add("an-focused"), typeof this.options.onFocus == "function" && this.options.onFocus(this);
1676
+ }), r = S(e, "blur", () => {
1677
+ this.layoutInfo.container.classList.remove("an-focused"), this._syncToTarget(), typeof this.options.onBlur == "function" && this.options.onBlur(this);
1678
+ }), i = this.on("change", (e) => this._syncToTarget(e)), a = this.on("change", (e) => {
1679
+ if (this.options.blockIds && (this.ensureBlockIds(), e = this.getHTML()), e === this._suppressedRemoteHTML) {
1680
+ this._suppressedRemoteHTML = null;
1681
+ return;
1682
+ }
1683
+ this.options.collaborationAdapter?.onLocalChange?.(e, this);
1684
+ });
1685
+ if (this._disposers.push(t, n, r, i, a), this.options.autoSave && this.options.autoSaveKey) {
1686
+ let e = this.on("change", (e) => this._scheduleAutoSave(e));
1687
+ this._disposers.push(e);
1688
+ }
1689
+ }
1690
+ _scheduleAutoSave(e) {
1691
+ this._pendingAutoSave = e, clearTimeout(this._autoSaveTimer), this._autoSaveTimer = setTimeout(() => this.flushAutoSave(), this.options.autoSaveDelay ?? 400);
1692
+ }
1693
+ async flushAutoSave() {
1694
+ if (clearTimeout(this._autoSaveTimer), this._autoSaveTimer = null, this._pendingAutoSave == null) return;
1695
+ let e = this._pendingAutoSave;
1696
+ this._pendingAutoSave = null;
1697
+ let t = this.options.autoSaveKey, n = Date.now();
1698
+ try {
1699
+ let r = this.options.autoSaveAdapter;
1700
+ typeof r?.save == "function" ? await r.save({
1701
+ key: t,
1702
+ html: e,
1703
+ savedAt: n,
1704
+ context: this
1705
+ }) : (localStorage.setItem(t, e), localStorage.setItem(t + ":asrmeta", JSON.stringify({ savedAt: n }))), this.triggerEvent("autoSave", {
1706
+ key: t,
1707
+ html: e,
1708
+ savedAt: n
1709
+ });
1710
+ } catch (e) {
1711
+ this.triggerEvent("autoSaveError", {
1712
+ key: t,
1713
+ error: e
1714
+ });
1715
+ }
1716
+ }
1717
+ async loadAutoSave() {
1718
+ let e = this.options.autoSaveAdapter;
1719
+ if (typeof e?.load == "function") return e.load({
1720
+ key: this.options.autoSaveKey,
1721
+ context: this
1722
+ });
1723
+ try {
1724
+ return localStorage.getItem(this.options.autoSaveKey);
1725
+ } catch {
1726
+ return null;
1727
+ }
1728
+ }
1729
+ invoke(e, ...t) {
1730
+ let [n, r] = e.split("."), i = this._modules.get(n);
1731
+ if (!i) {
1732
+ console.warn(`[AutumnNote] invoke: module "${n}" not found (path: "${e}")`);
1733
+ return;
1734
+ }
1735
+ if (typeof i[r] != "function") {
1736
+ console.warn(`[AutumnNote] invoke: method "${r}" not found on module "${n}" (path: "${e}")`);
1737
+ return;
1738
+ }
1739
+ return i[r](...t);
1740
+ }
1741
+ on(e, t) {
1742
+ return this._listeners.has(e) || this._listeners.set(e, []), this._listeners.get(e).push(t), () => this.off(e, t);
1743
+ }
1744
+ off(e, t) {
1745
+ let n = this._listeners.get(e);
1746
+ if (!n) return;
1747
+ let r = n.indexOf(t);
1748
+ r !== -1 && n.splice(r, 1);
1749
+ }
1750
+ triggerEvent(e, ...t) {
1751
+ (this._listeners.get(e) || []).forEach((e) => e(...t));
1752
+ let n = "on" + e.charAt(0).toUpperCase() + e.slice(1);
1753
+ typeof this.options[n] == "function" && this.options[n](...t);
1754
+ }
1755
+ updateOptions(e = {}) {
1756
+ let t = c(this.options, e);
1757
+ Object.keys(this.options).forEach((e) => delete this.options[e]), Object.assign(this.options, t);
1758
+ let { container: n, editable: r } = this.layoutInfo;
1759
+ 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")) {
1760
+ let e = this.options.direction === "rtl";
1761
+ r.setAttribute("dir", e ? "rtl" : "ltr"), n.classList.toggle("an-dir-rtl", e);
1762
+ }
1763
+ if (Object.hasOwn(e, "height") || Object.hasOwn(e, "minHeight")) {
1764
+ let e = this.options.height || this.options.minHeight || 0;
1765
+ r.style.minHeight = e ? `${e}px` : "";
1766
+ }
1767
+ 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;
1768
+ }
1769
+ getHTML() {
1770
+ let e = this.invoke("editor.getHTML");
1771
+ return typeof e == "string" ? e.replace(/​/g, "") : e;
1772
+ }
1773
+ setHTML(e) {
1774
+ this.invoke("editor.setHTML", e);
1775
+ }
1776
+ getText() {
1777
+ return this.invoke("editor.getText");
1778
+ }
1779
+ setText(e) {
1780
+ this.invoke("editor.setText", e);
1781
+ }
1782
+ clear() {
1783
+ this.invoke("editor.clear");
1784
+ }
1785
+ clearHistory() {
1786
+ this.invoke("editor.clearHistory");
1787
+ }
1788
+ getUndoCount() {
1789
+ return this.invoke("editor.getUndoCount") ?? 0;
1790
+ }
1791
+ getRedoCount() {
1792
+ return this.invoke("editor.getRedoCount") ?? 0;
1793
+ }
1794
+ isEmpty() {
1795
+ return this.invoke("editor.isEmpty");
1796
+ }
1797
+ insertHTML(e) {
1798
+ this.invoke("editor.insertHTML", e);
1799
+ }
1800
+ insertText(e) {
1801
+ this.invoke("editor.insertText", e);
1802
+ }
1803
+ setMarkdown(e) {
1804
+ this.invoke("editor.setMarkdown", e);
1805
+ }
1806
+ getMarkdown() {
1807
+ return this.invoke("editor.getMarkdown");
1808
+ }
1809
+ getSelectionBookmark() {
1810
+ return this.invoke("editor.getSelectionBookmark") ?? null;
1811
+ }
1812
+ restoreSelectionBookmark(e) {
1813
+ return this.invoke("editor.restoreSelectionBookmark", e);
1814
+ }
1815
+ async importDocument(e, t) {
1816
+ let n = this.options.documentAdapters?.[e], r;
1817
+ if (typeof n?.import == "function") r = await n.import(t, this);
1818
+ else if (e === "html") r = String(t ?? "");
1819
+ else if (e === "markdown") return this.setMarkdown(String(t ?? "")), this;
1820
+ else if (e === "text") return this.setText(String(t ?? "")), this;
1821
+ else throw Error(`[AutumnNote] No importer registered for "${e}".`);
1822
+ return this.setHTML(r), this;
1823
+ }
1824
+ async exportDocument(e) {
1825
+ let t = this.options.documentAdapters?.[e];
1826
+ if (typeof t?.export == "function") return t.export(this, this.getHTML());
1827
+ if (e === "html") return this.getHTML();
1828
+ if (e === "markdown") return this.getMarkdown();
1829
+ if (e === "text") return this.getText();
1830
+ throw Error(`[AutumnNote] No exporter registered for "${e}".`);
1831
+ }
1832
+ ensureBlockIds() {
1833
+ let e = this.layoutInfo.editable.children;
1834
+ for (let t of e) if (!t.hasAttribute("data-an-block-id")) {
1835
+ let e = globalThis.crypto?.randomUUID?.() || `an-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1836
+ t.setAttribute("data-an-block-id", e);
1837
+ }
1838
+ return this;
1839
+ }
1840
+ getDocument() {
1841
+ return this.options.blockIds && this.ensureBlockIds(), {
1842
+ version: 1,
1843
+ html: this.getHTML(),
1844
+ markdown: this.getMarkdown()
1845
+ };
1846
+ }
1847
+ loadDocument(e) {
1848
+ return this.setHTML(e?.html || ""), this.clearHistory(), this;
1849
+ }
1850
+ applyRemoteHTML(e) {
1851
+ return this.setHTML(e), this._suppressedRemoteHTML = this.getHTML(), this.clearHistory(), this;
1852
+ }
1853
+ getWordCount() {
1854
+ return this.invoke("statusbar.getWordCount") ?? 0;
1855
+ }
1856
+ getCharCount() {
1857
+ return this.invoke("statusbar.getCharCount") ?? 0;
1858
+ }
1859
+ downloadHTML(e = "document.html") {
1860
+ this._download(this.getHTML(), e, "text/html");
1861
+ }
1862
+ downloadText(e = "document.txt") {
1863
+ this._download(this.getText(), e, "text/plain");
1864
+ }
1865
+ downloadMarkdown(e = "document.md") {
1866
+ this._download(this.getMarkdown(), e, "text/markdown");
1867
+ }
1868
+ _download(e, t, n) {
1869
+ let r = new Blob([e], { type: n }), i = URL.createObjectURL(r), a = document.createElement("a");
1870
+ a.href = i, a.download = t, a.style.display = "none", document.body.appendChild(a), a.click(), a.remove(), URL.revokeObjectURL(i);
1871
+ }
1872
+ print(e = "") {
1873
+ 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");
1874
+ if (!a) {
1875
+ URL.revokeObjectURL(i);
1876
+ return;
1877
+ }
1878
+ a.addEventListener("load", () => {
1879
+ a.print(), URL.revokeObjectURL(i);
1880
+ });
1881
+ }
1882
+ getTableOfContents() {
1883
+ return Array.from(this.layoutInfo.editable.querySelectorAll("h1,h2,h3,h4,h5,h6")).map((e) => ({
1884
+ level: parseInt(e.tagName[1], 10),
1885
+ text: e.textContent?.trim() ?? "",
1886
+ element: e
1887
+ }));
1888
+ }
1889
+ focus() {
1890
+ this.layoutInfo.editable.focus();
1891
+ }
1892
+ blur() {
1893
+ this.layoutInfo.editable.blur();
1894
+ }
1895
+ isFullscreen() {
1896
+ return this.invoke("fullscreen.isActive") === !0;
1897
+ }
1898
+ setDisabled(e) {
1899
+ let t = this.layoutInfo.editable;
1900
+ e ? (t.setAttribute("contenteditable", "false"), this.layoutInfo.container.classList.add("an-disabled"), t.querySelectorAll("ul.an-checklist input[type=\"checkbox\"]").forEach((e) => {
1901
+ e.setAttribute("disabled", "");
1902
+ })) : (t.setAttribute("contenteditable", "true"), this.layoutInfo.container.classList.remove("an-disabled"), t.querySelectorAll("ul.an-checklist input[type=\"checkbox\"]").forEach((e) => {
1903
+ e.removeAttribute("disabled");
1904
+ }));
1905
+ }
1906
+ destroy() {
1907
+ if (!this._alive) return this._destroyPromise ?? Promise.resolve();
1908
+ let e = this._pendingAutoSave == null ? null : this.flushAutoSave().catch(() => {});
1909
+ this._modules.forEach((e) => {
1910
+ typeof e.destroy == "function" && e.destroy();
1911
+ }), this._modules.clear();
1912
+ for (let { plugin: e } of this._plugins.values()) if (typeof e.uninstall == "function") try {
1913
+ e.uninstall(this);
1914
+ } catch {}
1915
+ this._plugins.clear(), this._disposers.forEach((e) => e()), this._disposers = [];
1916
+ let t = this.layoutInfo.container, n = t?.classList.contains("an-theme-dark"), r = t?.classList.contains("an-theme-auto");
1917
+ 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(() => {
1918
+ this._listeners.clear();
1919
+ }), this._destroyPromise;
1920
+ }
1921
+ _syncToTarget(e) {
1922
+ (this.targetEl.tagName === "TEXTAREA" || this.targetEl.tagName === "INPUT") && (this.targetEl.value = typeof e == "string" ? e : this.getHTML());
1923
+ }
1924
+ }, Cn = class {
1925
+ constructor(e, t = 100, n = 10 * 1024 * 1024) {
1926
+ this.editable = e, this._limit = t, this._maxBytes = n, this._bytes = 0, this.stack = [], this.stackOffset = -1, this._savePoint();
1927
+ }
1928
+ _entrySize(e) {
1929
+ let t = e.html.length;
1930
+ if (e.images) for (let n in e.images) t += e.images[n].length;
1931
+ return t;
1932
+ }
1933
+ _serialize() {
1934
+ return this.editable.innerHTML;
1935
+ }
1936
+ _serializeSelection() {
1937
+ let e = globalThis.getSelection();
1938
+ if (!e || e.rangeCount === 0) return null;
1939
+ let t = e.getRangeAt(0);
1940
+ return this.editable.contains(t.startContainer) ? {
1941
+ start: this._charOffset(t.startContainer, t.startOffset),
1942
+ end: this._charOffset(t.endContainer, t.endOffset)
1943
+ } : null;
1944
+ }
1945
+ _charOffset(e, t) {
1946
+ let n = 0, r = document.createTreeWalker(this.editable, NodeFilter.SHOW_TEXT, null), i;
1947
+ for (; i = r.nextNode();) {
1948
+ if (i === e) return n + t;
1949
+ n += i.length;
1950
+ }
1951
+ return 0;
1952
+ }
1953
+ _restoreSelection(e) {
1954
+ if (!e) return;
1955
+ let t = null, n = 0, r = null, i = 0, a = 0, o = document.createTreeWalker(this.editable, NodeFilter.SHOW_TEXT, null), s;
1956
+ for (; s = o.nextNode();) {
1957
+ let o = s.length;
1958
+ if (!t && a + o >= e.start && (t = s, n = e.start - a), !r && a + o >= e.end) {
1959
+ r = s, i = e.end - a;
1960
+ break;
1961
+ }
1962
+ a += o;
1963
+ }
1964
+ if (!t) {
1965
+ let e = document.createTreeWalker(this.editable, NodeFilter.SHOW_TEXT, null), a = null;
1966
+ for (; a = e.nextNode();) t = a;
1967
+ n = t ? t.length : 0, r = t, i = n;
1968
+ }
1969
+ r || (r = t, i = n);
1970
+ try {
1971
+ let e = document.createRange();
1972
+ e.setStart(t, n), e.setEnd(r, i);
1973
+ let a = globalThis.getSelection();
1974
+ a.removeAllRanges(), a.addRange(e);
1975
+ } catch {
1976
+ try {
1977
+ let e = document.createRange();
1978
+ e.setStart(this.editable, 0), e.collapse(!0);
1979
+ let t = globalThis.getSelection();
1980
+ t && (t.removeAllRanges(), t.addRange(e));
1981
+ } catch {}
1982
+ }
1983
+ }
1984
+ _savePoint() {
1985
+ if (this.stackOffset < this.stack.length - 1) {
1986
+ for (let e of this.stack.slice(this.stackOffset + 1)) this._bytes -= this._entrySize(e);
1987
+ this.stack = this.stack.slice(0, this.stackOffset + 1);
1988
+ }
1989
+ let e = this._serialize(), { html: t, images: n } = this._tokenizeImages(e), r = {
1990
+ html: t,
1991
+ images: n,
1992
+ sel: this._serializeSelection()
1993
+ };
1994
+ 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());
1995
+ this.stackOffset = this.stack.length - 1;
1996
+ }
1997
+ _restore(e) {
1998
+ e && (this.editable.innerHTML = this._detokenizeImages(e), this._restoreSelection(e.sel));
1999
+ }
2000
+ _tokenizeImages(e) {
2001
+ if (!e.includes("data:")) return {
2002
+ html: e,
2003
+ images: {}
2004
+ };
2005
+ let t = {}, n = 0;
2006
+ return {
2007
+ html: e.replace(/data:[^;]+;base64,[^"' >]*/g, (e) => {
2008
+ let r = `__asn_img_${n}__`;
2009
+ return t[r] = e, n++, r;
2010
+ }),
2011
+ images: t
2012
+ };
2013
+ }
2014
+ _detokenizeImages(e) {
2015
+ return !e.images || Object.keys(e.images).length === 0 ? e.html : e.html.replace(/__asn_img_\d+__/g, (t) => e.images[t] || t);
2016
+ }
2017
+ recordUndo() {
2018
+ let e = this._serialize(), { html: t } = this._tokenizeImages(e);
2019
+ this.stack[this.stackOffset]?.html !== t && this._savePoint();
2020
+ }
2021
+ undo() {
2022
+ this.stackOffset <= 0 || (this.stackOffset--, this._restore(this.stack[this.stackOffset]));
2023
+ }
2024
+ redo() {
2025
+ this.stackOffset >= this.stack.length - 1 || (this.stackOffset++, this._restore(this.stack[this.stackOffset]));
2026
+ }
2027
+ reset() {
2028
+ this.stack = [], this.stackOffset = -1, this._bytes = 0, this._savePoint();
2029
+ }
2030
+ canUndo() {
2031
+ return this.stackOffset > 0;
2032
+ }
2033
+ canRedo() {
2034
+ return this.stackOffset < this.stack.length - 1;
2035
+ }
2036
+ getUndoCount() {
2037
+ return Math.max(0, this.stackOffset);
2038
+ }
2039
+ getRedoCount() {
2040
+ return Math.max(0, this.stack.length - 1 - this.stackOffset);
2041
+ }
2042
+ };
2043
+ //#endregion
2044
+ //#region src/js/editing/Table.js
2045
+ function wn(e, t, n = {}) {
2046
+ let { headerRow: r = !1 } = n, i = b("table", { class: "an-table" });
2047
+ if (r && t > 0) {
2048
+ let t = b("thead"), n = b("tr");
2049
+ for (let t = 0; t < e; t++) {
2050
+ let e = b("th", {}, [document.createElement("br")]);
2051
+ n.appendChild(e);
2052
+ }
2053
+ t.appendChild(n), i.appendChild(t);
2054
+ }
2055
+ let a = r ? Math.max(t - 1, 1) : t, o = b("tbody");
2056
+ i.appendChild(o);
2057
+ for (let t = 0; t < a; t++) {
2058
+ let t = b("tr");
2059
+ for (let n = 0; n < e; n++) {
2060
+ let e = b("td", {}, [document.createElement("br")]);
2061
+ t.appendChild(e);
2062
+ }
2063
+ o.appendChild(t);
2064
+ }
2065
+ return i;
2066
+ }
2067
+ function Tn(e, t, n = {}) {
2068
+ if (e <= 0 || t <= 0) return;
2069
+ let r = wn(e, t, n), i = globalThis.getSelection();
2070
+ if (!i || i.rangeCount === 0) return;
2071
+ let a = i.getRangeAt(0);
2072
+ try {
2073
+ a.deleteContents();
2074
+ } catch {
2075
+ return;
2076
+ }
2077
+ let o = /* @__PURE__ */ new Set([
2078
+ "P",
2079
+ "DIV",
2080
+ "H1",
2081
+ "H2",
2082
+ "H3",
2083
+ "H4",
2084
+ "H5",
2085
+ "H6",
2086
+ "BLOCKQUOTE",
2087
+ "LI",
2088
+ "PRE"
2089
+ ]), s = a.startContainer;
2090
+ for (s?.nodeType === 3 && (s = s.parentElement); s && !o.has(s.tagName?.toUpperCase()) && s.parentElement;) s = s.parentElement;
2091
+ if (s && o.has(s.tagName?.toUpperCase()) && s.parentNode) {
2092
+ if (s.after(r), !r.nextElementSibling) {
2093
+ let e = document.createElement("p");
2094
+ e.appendChild(document.createElement("br")), r.after(e);
2095
+ }
2096
+ !s.textContent.trim() && !s.querySelector("img, video, table") && s.remove();
2097
+ } else try {
2098
+ a.insertNode(r);
2099
+ } catch {
2100
+ return;
2101
+ }
2102
+ let c = r.querySelector("td, th");
2103
+ if (c) {
2104
+ let e = document.createRange();
2105
+ e.setStart(c, 0), e.collapse(!0), i.removeAllRanges(), i.addRange(e);
2106
+ }
2107
+ }
2108
+ //#endregion
2109
+ //#region src/js/core/key.js
2110
+ var P = {
2111
+ BACKSPACE: "Backspace",
2112
+ TAB: "Tab",
2113
+ ENTER: "Enter",
2114
+ ESCAPE: "Escape",
2115
+ SPACE: " ",
2116
+ PAGE_UP: "PageUp",
2117
+ PAGE_DOWN: "PageDown",
2118
+ END: "End",
2119
+ HOME: "Home",
2120
+ LEFT: "ArrowLeft",
2121
+ UP: "ArrowUp",
2122
+ RIGHT: "ArrowRight",
2123
+ DOWN: "ArrowDown",
2124
+ DELETE: "Delete",
2125
+ NUM0: "0",
2126
+ NUM1: "1",
2127
+ NUM2: "2",
2128
+ NUM3: "3",
2129
+ NUM4: "4",
2130
+ NUM5: "5",
2131
+ NUM6: "6",
2132
+ NUM7: "7",
2133
+ NUM8: "8",
2134
+ B: "b",
2135
+ E: "e",
2136
+ I: "i",
2137
+ J: "j",
2138
+ K: "k",
2139
+ L: "l",
2140
+ R: "r",
2141
+ S: "s",
2142
+ U: "u",
2143
+ V: "v",
2144
+ Y: "y",
2145
+ Z: "z",
2146
+ SLASH: "/",
2147
+ PERIOD: "."
2148
+ };
2149
+ function F(e, t) {
2150
+ return e.key === t || e.key === t.toUpperCase();
2151
+ }
2152
+ function I(e, t) {
2153
+ return (e.ctrlKey || e.metaKey) && F(e, t);
2154
+ }
2155
+ //#endregion
2156
+ //#region src/js/editing/Typing.js
2157
+ var En = /\bfa-/, L = (e) => !!(e?.nodeName === "I" && En.test(e.className || "")), R = (e) => e?.nodeType === Node.TEXT_NODE && (e.textContent === "​" || e.textContent === "");
2158
+ function Dn(e, t) {
2159
+ try {
2160
+ let n = document.createRange();
2161
+ return n.setStart(e.startContainer, e.startOffset), n.setEnd(t, t.childNodes.length), n.extractContents();
2162
+ } catch {
2163
+ return document.createDocumentFragment();
2164
+ }
2165
+ }
2166
+ function On(e, t, n = {}) {
2167
+ let r = (e) => {
2168
+ let t = globalThis.getSelection();
2169
+ if (!t) return !1;
2170
+ let n = document.createRange();
2171
+ return e(n), n.collapse(!0), t.removeAllRanges(), t.addRange(n), !0;
2172
+ };
2173
+ if (F(e, P.BACKSPACE)) {
2174
+ let t = globalThis.getSelection();
2175
+ if (t?.rangeCount > 0) {
2176
+ let n = t.getRangeAt(0);
2177
+ if (n.collapsed && n.startContainer.nodeType === Node.TEXT_NODE) {
2178
+ let r = n.startContainer;
2179
+ if (n.startOffset === 0 && L(r.previousSibling)) return e.preventDefault(), r.previousSibling.remove(), !0;
2180
+ if (n.startOffset === 1 && r.textContent === "​" && L(r.previousSibling)) {
2181
+ e.preventDefault();
2182
+ let n = r.parentNode, i = r.previousSibling, a = i.previousSibling;
2183
+ i.remove(), r.remove();
2184
+ let o = document.createRange();
2185
+ 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;
2186
+ }
2187
+ }
2188
+ }
2189
+ return !1;
2190
+ }
2191
+ if (F(e, P.LEFT) || F(e, P.RIGHT)) {
2192
+ let t = globalThis.getSelection();
2193
+ if (!t || t.rangeCount === 0) return !1;
2194
+ let n = t.getRangeAt(0);
2195
+ if (!n.collapsed) return !1;
2196
+ let i = n.startContainer, a = F(e, P.LEFT);
2197
+ if (i.nodeType === Node.TEXT_NODE) {
2198
+ let t = i;
2199
+ 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));
2200
+ if (a && n.startOffset === 0 && R(t.previousSibling) && L(t.previousSibling.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(t.previousSibling.previousSibling));
2201
+ if (!a && n.startOffset === t.textContent.length && L(t.nextSibling)) {
2202
+ let n = t.nextSibling, i = n.nextSibling;
2203
+ if (e.preventDefault(), i?.nodeType === Node.TEXT_NODE) {
2204
+ let e = +!!(i.textContent || "").startsWith("​");
2205
+ return r((t) => t.setStart(i, Math.min(e, i.textContent.length)));
2206
+ }
2207
+ return r((e) => e.setStartAfter(n));
2208
+ }
2209
+ if (!a && n.startOffset === t.textContent.length && R(t.nextSibling) && L(t.nextSibling.nextSibling)) {
2210
+ let n = t.nextSibling.nextSibling, i = n.nextSibling;
2211
+ if (e.preventDefault(), i?.nodeType === Node.TEXT_NODE) {
2212
+ let e = +!!(i.textContent || "").startsWith("​");
2213
+ return r((t) => t.setStart(i, Math.min(e, i.textContent.length)));
2214
+ }
2215
+ return r((e) => e.setStartAfter(n));
2216
+ }
2217
+ }
2218
+ if (i.nodeType === Node.ELEMENT_NODE) {
2219
+ let t = i;
2220
+ if (a && n.startOffset > 0) {
2221
+ let i = t.childNodes[n.startOffset - 1];
2222
+ if (L(i)) return e.preventDefault(), r((e) => e.setStartBefore(i));
2223
+ if (R(i) && L(i.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(i.previousSibling));
2224
+ }
2225
+ if (!a && n.startOffset < t.childNodes.length) {
2226
+ let i = t.childNodes[n.startOffset];
2227
+ if (L(i)) {
2228
+ let t = i.nextSibling;
2229
+ if (e.preventDefault(), t?.nodeType === Node.TEXT_NODE) {
2230
+ let e = +!!(t.textContent || "").startsWith("​");
2231
+ return r((n) => n.setStart(t, Math.min(e, t.textContent.length)));
2232
+ }
2233
+ return r((e) => e.setStartAfter(i));
2234
+ }
2235
+ if (R(i) && L(i.nextSibling)) {
2236
+ let t = i.nextSibling, n = t.nextSibling;
2237
+ if (e.preventDefault(), n?.nodeType === Node.TEXT_NODE) {
2238
+ let e = +!!(n.textContent || "").startsWith("​");
2239
+ return r((t) => t.setStart(n, Math.min(e, n.textContent.length)));
2240
+ }
2241
+ return r((e) => e.setStartAfter(t));
2242
+ }
2243
+ }
2244
+ }
2245
+ }
2246
+ if (F(e, P.TAB)) {
2247
+ let r = xe(t);
2248
+ if (!r) return !1;
2249
+ let i = ae(r.sc, t);
2250
+ if (i && ee(i)) return e.preventDefault(), e.shiftKey ? Qe() : w("indent"), !0;
2251
+ if (i?.nodeName.toUpperCase() === "PRE") return e.shiftKey ? !1 : (e.preventDefault(), w("insertText", " ".repeat(n.tabSize || 4)), !0);
2252
+ if (n.tabSize) return e.shiftKey ? !1 : (e.preventDefault(), w("insertText", " ".repeat(n.tabSize)), !0);
2253
+ }
2254
+ if (F(e, P.ENTER) && e.shiftKey) return e.preventDefault(), w("insertLineBreak"), !0;
2255
+ if (F(e, P.ENTER) && !e.shiftKey) {
2256
+ let n = xe(t);
2257
+ if (!n) return !1;
2258
+ let r = n.sc, i = r.nodeType === 3 ? r.parentElement : r;
2259
+ if (i?.nodeName === "I" && /\bfa-/.test(i.className || "")) {
2260
+ let e = document.createRange();
2261
+ e.setStartAfter(i), e.collapse(!0);
2262
+ let t = globalThis.getSelection();
2263
+ return t && (t.removeAllRanges(), t.addRange(e)), !1;
2264
+ }
2265
+ let a = i?.closest(".an-video-wrapper");
2266
+ if (a) {
2267
+ e.preventDefault();
2268
+ let t = document.createElement("p");
2269
+ t.innerHTML = "\xA0", a.parentNode.insertBefore(t, a.nextSibling);
2270
+ let n = document.createRange();
2271
+ n.setStart(t, 0), n.collapse(!0);
2272
+ let r = globalThis.getSelection();
2273
+ return r.removeAllRanges(), r.addRange(n), !0;
2274
+ }
2275
+ let o = i?.closest(".an-checklist li");
2276
+ if (o) {
2277
+ e.preventDefault();
2278
+ let t = o.closest(".an-checklist"), n = globalThis.getSelection(), r = n.getRangeAt(0);
2279
+ 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)) {
2280
+ let e = document.createElement("p");
2281
+ e.innerHTML = "\xA0", t.parentNode.insertBefore(e, t.nextSibling), o.remove(), t.children.length === 0 && t.remove();
2282
+ let r = document.createRange();
2283
+ return r.setStart(e.firstChild, 0), r.collapse(!0), n.removeAllRanges(), n.addRange(r), !0;
2284
+ }
2285
+ if (!r.collapsed) {
2286
+ if (r.deleteContents(), n.rangeCount === 0 || !o.isConnected) return !0;
2287
+ r = n.getRangeAt(0);
2288
+ }
2289
+ let i = Dn(r, o), a = document.createElement("li"), s = document.createElement("input");
2290
+ s.type = "checkbox", s.setAttribute("contenteditable", "false"), a.appendChild(s), i.textContent.replace(/[\u00a0\u200B]/g, "").length > 0 && a.appendChild(i);
2291
+ let c = a.childNodes[1];
2292
+ c?.nodeType !== Node.TEXT_NODE && (c = document.createTextNode("​"), a.appendChild(c)), o.after(a);
2293
+ let l = document.createRange();
2294
+ return l.setStart(c, 0), l.collapse(!0), n.removeAllRanges(), n.addRange(l), !0;
2295
+ }
2296
+ let s = ae(n.sc, t);
2297
+ if (s?.nodeName.toUpperCase() === "PRE") return e.preventDefault(), w("insertText", "\n"), !0;
2298
+ if (s?.nodeName.toUpperCase() === "BLOCKQUOTE") {
2299
+ let t = n.toNativeRange();
2300
+ if (t.setEnd(s, s.childNodes.length), t.toString() === "" && n.isCollapsed()) return e.preventDefault(), w("formatBlock", "<p>"), !0;
2301
+ }
2302
+ }
2303
+ return !1;
2304
+ }
2305
+ //#endregion
2306
+ //#region src/js/core/markdown.js
2307
+ function kn(e) {
2308
+ return In(new DOMParser().parseFromString(`<body>${e || ""}</body>`, "text/html").body).replace(/\n{3,}/g, "\n\n").trim();
2309
+ }
2310
+ function z(e, t) {
2311
+ return Array.from(e.children).filter((e) => e.tagName === t.toUpperCase());
2312
+ }
2313
+ function An(e) {
2314
+ let t = "";
2315
+ for (let n of e.childNodes) {
2316
+ if (n.nodeType === 3) {
2317
+ t += n.textContent;
2318
+ continue;
2319
+ }
2320
+ if (n.nodeType !== 1) continue;
2321
+ let e = n.nodeName.toLowerCase();
2322
+ if (e === "br") {
2323
+ t += "\n";
2324
+ continue;
2325
+ }
2326
+ if (e === "div" || e === "p") {
2327
+ t && !t.endsWith("\n") && (t += "\n"), t += An(n), t += "\n";
2328
+ continue;
2329
+ }
2330
+ t += An(n);
2331
+ }
2332
+ return t;
2333
+ }
2334
+ function jn(e) {
2335
+ 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`\~`);
2336
+ }
2337
+ function Mn(e) {
2338
+ 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}`);
2339
+ }
2340
+ function Nn(e) {
2341
+ return e.split("\n").map(Mn).join("\n");
2342
+ }
2343
+ function Pn(e, t) {
2344
+ let n = " ".repeat(t + 1);
2345
+ return In(e, t + 1).trim().split("\n").map((e, t) => t === 0 || e.trim() === "" || e.startsWith(n) ? e : n + e).join("\n");
2346
+ }
2347
+ function Fn(e, t) {
2348
+ let n = e.getAttribute(t) || "", r = /[\s()]/.test(n) ? `<${n}>` : n, i = e.getAttribute("title");
2349
+ return i ? `${r} "${i.replaceAll("\"", String.raw`\"`)}"` : r;
2350
+ }
2351
+ function In(e, t = 0) {
2352
+ if (e.nodeType === 3) {
2353
+ let t = e.textContent.replace(/\s+/g, " ");
2354
+ return e.parentElement?.closest("pre, code") ? t : jn(t);
2355
+ }
2356
+ if (e.nodeType !== 1) return "";
2357
+ let n = e, r = n.nodeName.toLowerCase(), i = () => Array.from(n.childNodes).map((e) => In(e, t)).join("");
2358
+ switch (r) {
2359
+ case "p":
2360
+ case "div": return `\n\n${Nn(i())}\n\n`;
2361
+ case "br": return " \n";
2362
+ case "h1": return `\n\n# ${i()}\n\n`;
2363
+ case "h2": return `\n\n## ${i()}\n\n`;
2364
+ case "h3": return `\n\n### ${i()}\n\n`;
2365
+ case "h4": return `\n\n#### ${i()}\n\n`;
2366
+ case "h5": return `\n\n##### ${i()}\n\n`;
2367
+ case "h6": return `\n\n###### ${i()}\n\n`;
2368
+ case "strong":
2369
+ case "b": return `**${i()}**`;
2370
+ case "em":
2371
+ case "i": return `*${i()}*`;
2372
+ case "del":
2373
+ case "s":
2374
+ case "strike": return `~~${i()}~~`;
2375
+ case "sup": return `^${i()}^`;
2376
+ case "sub": return `~${i()}~`;
2377
+ case "u": return `<u>${i()}</u>`;
2378
+ case "span": {
2379
+ let e = n.getAttribute("style") || "";
2380
+ return /\b(color|background-color|font-size)\s*:/.test(e) ? `<span style="${q(e)}">${i()}</span>` : i();
2381
+ }
2382
+ case "code": {
2383
+ if (n.closest("pre")) return i();
2384
+ let e = i(), t = Math.max(0, ...Array.from(e.matchAll(/`+/g), (e) => e[0].length)), r = "`".repeat(t + 1), a = /^`|`$/.test(e) ? " " : "";
2385
+ return `${r}${a}${e}${a}${r}`;
2386
+ }
2387
+ case "pre": {
2388
+ let e = n.querySelector("code"), t = /language-(\S+)/.exec(e?.className || "");
2389
+ return `\n\n\`\`\`${t ? t[1] : ""}\n${An(e || n).replace(/\n$/, "")}\n\`\`\`\n\n`;
2390
+ }
2391
+ case "blockquote": {
2392
+ let e = i().trim().split("\n");
2393
+ return `\n\n${e.filter((t, n) => t.trim() !== "" || (e[n - 1] ?? "").trim() !== "").map((e) => e.trim() === "" ? ">" : `> ${e}`).join("\n")}\n\n`;
2394
+ }
2395
+ case "a": return `[${i()}](${Fn(n, "href")})`;
2396
+ case "img": return `![${jn(n.getAttribute("alt") || "")}](${Fn(n, "src")})`;
2397
+ case "ul": {
2398
+ let e = z(n, "li");
2399
+ if (!e.length) return i();
2400
+ let r = " ".repeat(t), a = n.classList.contains("an-checklist"), o = e.map((e) => {
2401
+ let n = z(e, "input").find((e) => e.getAttribute("type") === "checkbox"), i = "- ";
2402
+ return (a || n) && (i = n && n.checked ? "- [x] " : "- [ ] "), `${r}${i}${Pn(e, t)}`;
2403
+ }).join("\n");
2404
+ return t === 0 ? `\n\n${o}\n\n` : `\n${o}`;
2405
+ }
2406
+ case "ol": {
2407
+ let e = z(n, "li");
2408
+ if (!e.length) return i();
2409
+ 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}. ${Pn(e, t)}`).join("\n");
2410
+ return t === 0 ? `\n\n${s}\n\n` : `\n${s}`;
2411
+ }
2412
+ case "li": return i();
2413
+ case "hr": return "\n\n---\n\n";
2414
+ case "table": {
2415
+ let e = Array.from(n.querySelectorAll("tr"));
2416
+ if (!e.length) return i();
2417
+ 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) => jn(e.textContent.trim()).replaceAll("|", String.raw`\|`))), a = Math.max(...r.map((e) => e.length)), o = (e) => {
2418
+ let t = [...e];
2419
+ for (; t.length < a;) t.push("");
2420
+ return t;
2421
+ }, s = +!!t, c = t ? o(r[0]) : Array(a).fill(""), l = Array.from({ length: a }, (t, n) => {
2422
+ let r = e[0]?.children[n], i = /text-align:\s*(left|center|right)/.exec(r?.getAttribute("style") || "")?.[1];
2423
+ return i === "center" ? ":---:" : i === "right" ? "---:" : i === "left" ? ":---" : "---";
2424
+ }), u = "\n\n";
2425
+ u += `| ${c.join(" | ")} |\n`, u += `| ${l.join(" | ")} |\n`;
2426
+ for (let e = s; e < r.length; e++) u += `| ${o(r[e]).join(" | ")} |\n`;
2427
+ return u + "\n";
2428
+ }
2429
+ default: return i();
2430
+ }
2431
+ }
2432
+ function Ln(e) {
2433
+ return String(e ?? "").replace(/^\ufeff/, "");
2434
+ }
2435
+ function Rn(e) {
2436
+ let t = Ln(e);
2437
+ 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);
2438
+ }
2439
+ var B = /^ {0,3}>( ?)(.*)$/, zn = /^(?: {4}|\t)\s*\S/, Bn = /^( {0,3})(`{3,}|~{3,})[ \t]*([^\s`~][^\n]*)?$/;
2440
+ function V(e) {
2441
+ let t = Bn.exec(e);
2442
+ if (!t) return null;
2443
+ let [, n, r, i = ""] = t;
2444
+ return r[0] === "`" && i.includes("`") ? null : {
2445
+ marker: r[0],
2446
+ length: r.length,
2447
+ indent: n.length,
2448
+ lang: i.trim().split(/\s+/)[0] || ""
2449
+ };
2450
+ }
2451
+ function Vn(e, t) {
2452
+ let n = 0, r = 0;
2453
+ for (; r < e.length && n < t;) {
2454
+ if (e[r] === " ") {
2455
+ n += 1, r += 1;
2456
+ continue;
2457
+ }
2458
+ if (e[r] === " ") {
2459
+ let e = 4 - n % 4;
2460
+ if (n + e > t) break;
2461
+ n += e, r += 1;
2462
+ continue;
2463
+ }
2464
+ break;
2465
+ }
2466
+ return e.slice(r);
2467
+ }
2468
+ var Hn = /^ {0,3}([-*_])( *\1){2,}\s*$/, Un = "";
2469
+ function H(e) {
2470
+ let t = Ln(e).replaceAll("\r\n", "\n").replaceAll("\r", "\n").split("\n");
2471
+ t = qn(t);
2472
+ let n = Jn(t);
2473
+ return t = n.clean, Gn = n.linkDefs, Kn = n.footnoteIds, Wn(t);
2474
+ }
2475
+ function Wn(e) {
2476
+ let t = [], n = 0;
2477
+ for (; n < e.length;) {
2478
+ let r = e[n], i = V(r);
2479
+ if (i) {
2480
+ let r = RegExp(`^ {0,3}\\${i.marker}{${i.length},}[ \t]*$`), a = [];
2481
+ for (n++; n < e.length && !r.test(e[n]);) a.push(mr(Vn(e[n], i.indent))), n++;
2482
+ let o = i.lang ? ` class="language-${q(i.lang)}"` : "";
2483
+ t.push(`<pre><code${o}>${a.join("\n")}</code></pre>`), n++;
2484
+ continue;
2485
+ }
2486
+ if (zn.test(r)) {
2487
+ let r = [];
2488
+ for (; n < e.length && (zn.test(e[n]) || e[n].trim() === "");) {
2489
+ if (e[n].trim() === "") {
2490
+ let t = n;
2491
+ for (; t < e.length && e[t].trim() === "";) t++;
2492
+ if (t >= e.length || !zn.test(e[t])) break;
2493
+ for (; n < t; n++) r.push("");
2494
+ continue;
2495
+ }
2496
+ r.push(mr(Vn(e[n], 4))), n++;
2497
+ }
2498
+ t.push(`<pre><code>${r.join("\n")}</code></pre>`);
2499
+ continue;
2500
+ }
2501
+ if (r.trim() && !Hn.test(r) && !/^#{1,6} /.test(r) && n + 1 < e.length) {
2502
+ if (/^=+\s*$/.test(e[n + 1])) {
2503
+ t.push(`<h1>${K(r.trim())}</h1>`), n += 2;
2504
+ continue;
2505
+ }
2506
+ if (/^-{2,}\s*$/.test(e[n + 1])) {
2507
+ t.push(`<h2>${K(r.trim())}</h2>`), n += 2;
2508
+ continue;
2509
+ }
2510
+ }
2511
+ if (Hn.test(r)) {
2512
+ t.push("<hr>"), n++;
2513
+ continue;
2514
+ }
2515
+ let a = /^(#{1,6})[ \t]+(.*)$/.exec(r);
2516
+ if (a) {
2517
+ let e = a[1].length, r = a[2].replace(/(?:^|\s)#+\s*$/, "");
2518
+ t.push(`<h${e}>${K(r)}</h${e}>`), n++;
2519
+ continue;
2520
+ }
2521
+ if (B.test(r)) {
2522
+ let r = [];
2523
+ for (; n < e.length && B.test(e[n]);) r.push(B.exec(e[n])[2]), n++;
2524
+ t.push(`<blockquote>${Wn(r)}</blockquote>`);
2525
+ continue;
2526
+ }
2527
+ if (/^[-*+] /.test(r)) {
2528
+ let { html: r, endIdx: i } = Qn(e, n);
2529
+ t.push(r), n = i;
2530
+ continue;
2531
+ }
2532
+ if (/^\d+[.)] /.test(r)) {
2533
+ let { html: r, endIdx: i } = Qn(e, n);
2534
+ t.push(r), n = i;
2535
+ continue;
2536
+ }
2537
+ if (r.trim() === "") {
2538
+ n++;
2539
+ continue;
2540
+ }
2541
+ if (Zn(e, n)) {
2542
+ let i = U(r), a = U(e[n + 1]).map((e) => e.startsWith(":") && e.endsWith(":") ? "center" : e.endsWith(":") ? "right" : e.startsWith(":") ? "left" : null);
2543
+ n += 2;
2544
+ let o = [];
2545
+ for (; n < e.length && e[n].trim() !== "" && Xn(e[n]) > 1;) o.push(U(e[n])), n++;
2546
+ 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>` : "";
2547
+ t.push(`<table>${c}${l}</table>`);
2548
+ continue;
2549
+ }
2550
+ let o = [];
2551
+ for (; n < e.length && e[n].trim() !== "" && !/^(#{1,6} |[-*+] |\d+[.)] )/.test(e[n]) && !V(e[n]) && !B.test(e[n]) && !Hn.test(e[n]) && !Zn(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++;
2552
+ o.length ? t.push(`<p>${K(Yn(o)).replaceAll(Un, "<br>")}</p>`) : (t.push(`<p>${K(r)}</p>`), n++);
2553
+ }
2554
+ return t.join("");
2555
+ }
2556
+ var Gn = /* @__PURE__ */ new Map(), Kn = /* @__PURE__ */ new Set();
2557
+ function qn(e) {
2558
+ if ((e[0] || "").trim() !== "---") return e;
2559
+ let t = -1;
2560
+ for (let n = 1; n < e.length; n++) {
2561
+ let r = e[n].trim();
2562
+ if (r === "---" || r === "...") {
2563
+ t = n;
2564
+ break;
2565
+ }
2566
+ }
2567
+ 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;
2568
+ let n = t + 1;
2569
+ return e[n] !== void 0 && e[n].trim() === "" && n++, e.slice(n);
2570
+ }
2571
+ function Jn(e) {
2572
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = [], i = !1, a = /^\[([^\]]+)\]:\s*(\S+)(?:\s+"([^"]*)")?\s*$/, o = /^\[\^([^\]]+)\]:[ \t]*(\S.*)$/;
2573
+ for (let s of e) {
2574
+ if (i) {
2575
+ /^ {0,3}(?:`{3,}|~{3,})[ \t]*$/.test(s) && (i = !1), r.push(s);
2576
+ continue;
2577
+ }
2578
+ if (V(s)) {
2579
+ i = !0, r.push(s);
2580
+ continue;
2581
+ }
2582
+ {
2583
+ let e = o.exec(s);
2584
+ if (e) {
2585
+ n.add(e[1]);
2586
+ continue;
2587
+ }
2588
+ let r = a.exec(s);
2589
+ if (r) {
2590
+ t.set(r[1].trim().toLowerCase(), {
2591
+ href: r[2],
2592
+ title: r[3]
2593
+ });
2594
+ continue;
2595
+ }
2596
+ }
2597
+ r.push(s);
2598
+ }
2599
+ return {
2600
+ clean: r,
2601
+ linkDefs: t,
2602
+ footnoteIds: n
2603
+ };
2604
+ }
2605
+ function Yn(e) {
2606
+ let t = "";
2607
+ for (let n = 0; n < e.length; n++) {
2608
+ let r = n === e.length - 1, i = e[n].replace(/^[ \t]+/, "");
2609
+ if (!r && /\\$/.test(i)) {
2610
+ t += i.replace(/\\$/, "") + Un;
2611
+ continue;
2612
+ }
2613
+ if (!r && / {2,}$/.test(i)) {
2614
+ t += i.replace(/ {2,}$/, "") + Un;
2615
+ continue;
2616
+ }
2617
+ t += i + (r ? "" : " ");
2618
+ }
2619
+ return t;
2620
+ }
2621
+ function Xn(e) {
2622
+ return U(e).length;
2623
+ }
2624
+ function Zn(e, t) {
2625
+ let n = e[t], r = e[t + 1];
2626
+ if (r === void 0 || !n.includes("|")) return !1;
2627
+ if (/^\|.+\|/.test(n)) return /^\|[\s|:-]+\|/.test(r);
2628
+ let i = U(r);
2629
+ return i.length < 2 || !i.every((e) => /^:?-+:?$/.test(e)) ? !1 : Xn(n) === i.length;
2630
+ }
2631
+ function U(e) {
2632
+ let t = e.replace(/^\|/, "").replace(/\|$/, ""), n = [], r = "";
2633
+ for (let e = 0; e < t.length; e++) {
2634
+ if (t[e] === "\\" && t[e + 1] === "|") {
2635
+ r += "|", e++;
2636
+ continue;
2637
+ }
2638
+ if (t[e] === "|") {
2639
+ n.push(r), r = "";
2640
+ continue;
2641
+ }
2642
+ r += t[e];
2643
+ }
2644
+ return n.push(r), n.map((e) => e.trim());
2645
+ }
2646
+ function Qn(e, t) {
2647
+ let n = e[t].match(/^(\s*)/)[1].length, r = /^\s*\d+[.)] /.test(e[t]), i = [], a = null, o = !1, s = !1, c = t;
2648
+ for (; c < e.length;) {
2649
+ let t = e[c];
2650
+ if (t.trim() === "") {
2651
+ 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;
2652
+ if (!i.length || !l && !u) break;
2653
+ o = !0, s = !0, c++;
2654
+ continue;
2655
+ }
2656
+ let l = t.match(/^(\s*)/)[1].length;
2657
+ if (l < n) break;
2658
+ if (l === n) {
2659
+ if (!/^\s*(?:[-*+]|\d+[.)]) /.test(t) || /^\s*\d+[.)] /.test(t) !== r) break;
2660
+ let e = r ? t.replace(/^\s*\d+[.)] /, "") : t.replace(/^\s*[-*+] /, ""), n = !r && /^\[[ xX]\]\s+/.test(e);
2661
+ if (a === null && (a = n), n !== a) break;
2662
+ let o = n && e[1].toLowerCase() === "x", l = n ? e.replace(/^\[[ xX]\]\s+/, "") : e;
2663
+ i.push({
2664
+ paras: [l],
2665
+ isCB: n,
2666
+ checked: o,
2667
+ sub: ""
2668
+ }), s = !1, c++;
2669
+ } else {
2670
+ if (!i.length) {
2671
+ c++;
2672
+ continue;
2673
+ }
2674
+ let n = (e) => Vn(e, l), r = V(n(t));
2675
+ if (r) {
2676
+ let t = RegExp(`^ {0,3}\\${r.marker}{${r.length},}[ \t]*$`), a = [n(e[c])];
2677
+ for (c++; c < e.length && !t.test(n(e[c]));) a.push(n(e[c])), c++;
2678
+ c < e.length && (a.push(n(e[c])), c++), i[i.length - 1].sub += Wn(a), s = !1;
2679
+ continue;
2680
+ }
2681
+ if (/^\s*(?:[-*+]|\d+[.)]) /.test(t)) {
2682
+ let t = Qn(e, c);
2683
+ i[i.length - 1].sub += t.html, c = t.endIdx, s = !1;
2684
+ } else if (s) i[i.length - 1].paras.push(t.trim()), s = !1, c++;
2685
+ else {
2686
+ let e = i[i.length - 1].paras;
2687
+ e[e.length - 1] += " " + t.trim(), c++;
2688
+ }
2689
+ }
2690
+ }
2691
+ 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>";
2692
+ return {
2693
+ html: `${f}${i.map(({ paras: e, isCB: t, checked: n, sub: r }) => {
2694
+ let i = t ? `<input type="checkbox" contenteditable="false"${n ? " checked" : ""}>` : "";
2695
+ return `<li>${o ? e.map((e, t) => `<p>${t === 0 ? i : ""}${K(e)}</p>`).join("") : `${i}${K(e[0])}`}${r}</li>`;
2696
+ }).join("")}${p}`,
2697
+ endIdx: c
2698
+ };
2699
+ }
2700
+ var $n = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g, W = "\0", G = "", er = /(`+)([^]*?)\1/g;
2701
+ function tr(e) {
2702
+ let t = [];
2703
+ return {
2704
+ text: e.replace(er, (e, n, r) => r === "" ? e : (t.push(r), `${G}${t.length - 1}${G}`)),
2705
+ codes: t
2706
+ };
2707
+ }
2708
+ function nr(e, t, n) {
2709
+ return e.replace(RegExp(`${G}(\\d+)${G}`, "g"), (e, r) => {
2710
+ let i = t[Number(r)];
2711
+ 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>${mr(i)}</code>`;
2712
+ });
2713
+ }
2714
+ function rr(e) {
2715
+ let t = [];
2716
+ return {
2717
+ text: e.replace($n, (e, n) => (t.push(n), `${W}${t.length - 1}${W}`)),
2718
+ literals: t
2719
+ };
2720
+ }
2721
+ function ir(e, t) {
2722
+ return e.replace(RegExp(`${W}(\\d+)${W}`, "g"), (e, n) => pr(t[Number(n)]));
2723
+ }
2724
+ var ar = String.raw`(&lt;.*?&gt;(?:\s+(?:"[^"]*"|'[^']*'))?|[^)]*)`, or = new RegExp(String.raw`!\[([^\]]*)\]\(${ar}\)`, "g"), sr = new RegExp(String.raw`\[([^\]]+)\]\(${ar}\)`, "g");
2725
+ function cr(e) {
2726
+ let t = e.trim(), n = /^&lt;([\s\S]*?)&gt;(?:[ \t]*(?:"([^"]*)"|'([^']*)'))?[ \t]*$/.exec(t);
2727
+ if (n) return {
2728
+ href: n[1],
2729
+ title: n[2] ?? n[3] ?? ""
2730
+ };
2731
+ let r = /^(\S+)\s+(?:"([^"]*)"|'([^']*)')\s*$/.exec(t);
2732
+ return r ? {
2733
+ href: r[1],
2734
+ title: r[2] ?? r[3] ?? ""
2735
+ } : {
2736
+ href: t,
2737
+ title: ""
2738
+ };
2739
+ }
2740
+ function lr(e) {
2741
+ return e = e.replace(or, (e, t, n) => {
2742
+ let { href: r, title: i } = cr(n), a = i ? ` title="${J(i)}"` : "";
2743
+ return `<img src="${J(r)}" alt="${J(t)}"${a} class="an-image">`;
2744
+ }), e = e.replace(sr, (e, t, n) => {
2745
+ let { href: r, title: i } = cr(n), a = i ? ` title="${J(i)}"` : "";
2746
+ return `<a href="${J(r)}"${a}>${t}</a>`;
2747
+ }), e = e.replace(/\[([^\]]+)\]\[([^\]]*)\]/g, (e, t, n) => {
2748
+ let r = Gn.get(hr(n || t).trim().toLowerCase());
2749
+ if (!r) return e;
2750
+ let i = r.title ? ` title="${q(r.title)}"` : "";
2751
+ return `<a href="${q(r.href)}"${i}>${t}</a>`;
2752
+ }), e = e.replace(/\[([^\]]+)\]/g, (e, t) => {
2753
+ let n = Gn.get(hr(t).trim().toLowerCase());
2754
+ if (!n) return e;
2755
+ let r = n.title ? ` title="${q(n.title)}"` : "";
2756
+ return `<a href="${q(n.href)}"${r}>${t}</a>`;
2757
+ }), e = e.replace(/\[\^([^\]]+)\]/g, (e, t) => Kn.has(hr(t)) ? `<sup>[${t}]</sup>` : e), e;
2758
+ }
2759
+ function ur(e) {
2760
+ 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) => {
2761
+ let r = /[.,;:!?)]+$/.exec(n), i = r ? n.slice(0, -r[0].length) : n;
2762
+ if (!i) return e;
2763
+ let a = r ? r[0] : "";
2764
+ return `${t}<a href="${J(i)}">${i}</a>${a}`;
2765
+ }), e;
2766
+ }
2767
+ function dr(e) {
2768
+ 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;
2769
+ }
2770
+ function K(e) {
2771
+ let { text: t, literals: n } = rr(e), { text: r, codes: i } = tr(t), a = pr(r);
2772
+ return a = lr(a), a = ur(a), a = dr(a), nr(ir(a, n), i, n);
2773
+ }
2774
+ var fr = /&(?!#\d+;|#[xX][0-9a-fA-F]+;|[a-zA-Z][a-zA-Z0-9]*;)/g;
2775
+ function pr(e) {
2776
+ return String(e).replace(fr, "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2777
+ }
2778
+ function mr(e) {
2779
+ return String(e).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2780
+ }
2781
+ function q(e) {
2782
+ return String(e).replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("'", "&#39;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2783
+ }
2784
+ function J(e) {
2785
+ return String(e).replaceAll("\"", "&quot;").replaceAll("'", "&#39;");
2786
+ }
2787
+ function hr(e) {
2788
+ return String(e).replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&amp;", "&");
2789
+ }
2790
+ //#endregion
2791
+ //#region src/js/core/detectLang.js
2792
+ var gr = 5, _r = 2, vr = [
2793
+ ["typescript", "javascript"],
2794
+ ["scss", "css"],
2795
+ ["cpp", "c"]
2796
+ ], yr = [
2797
+ "javascript",
2798
+ "typescript",
2799
+ "python",
2800
+ "java",
2801
+ "go",
2802
+ "rust",
2803
+ "csharp",
2804
+ "kotlin",
2805
+ "swift",
2806
+ "cpp",
2807
+ "c",
2808
+ "ruby",
2809
+ "php",
2810
+ "html",
2811
+ "xml",
2812
+ "json",
2813
+ "yaml",
2814
+ "markdown",
2815
+ "sql",
2816
+ "scss",
2817
+ "css",
2818
+ "bash"
2819
+ ], br = [
2820
+ {
2821
+ lang: "php",
2822
+ w: 10,
2823
+ re: /<\?php\b|<\?=/
2824
+ },
2825
+ {
2826
+ lang: "bash",
2827
+ w: 10,
2828
+ re: /^#!.*\/(?:ba|z|da|fi|k)?sh\b/m
2829
+ },
2830
+ {
2831
+ lang: "rust",
2832
+ w: 10,
2833
+ re: /\b(?:println!|print!|format!|vec!|panic!)\s*[([]/
2834
+ },
2835
+ {
2836
+ lang: "go",
2837
+ w: 10,
2838
+ re: /\bfmt\.(?:Print|Println|Printf|Sprintf|Errorf|Fprintf)\s*\(/
2839
+ },
2840
+ {
2841
+ lang: "java",
2842
+ w: 10,
2843
+ re: /\bSystem\.out\.(?:print|println)\s*\(/
2844
+ },
2845
+ {
2846
+ lang: "csharp",
2847
+ w: 10,
2848
+ re: /\bConsole\.(?:Write|WriteLine)\s*\(/
2849
+ },
2850
+ {
2851
+ lang: "cpp",
2852
+ w: 10,
2853
+ re: /\b(?:cout|cerr)\s*<<|\bcin\s*>>|\busing\s+namespace\s+std\b|\bstd::\w/
2854
+ },
2855
+ {
2856
+ lang: "python",
2857
+ w: 10,
2858
+ re: /\bdef[ \t]+\w+[ \t]*\([^)]*\)[ \t]*(?:->[^:\n]*)?:|\bif[ \t]+__name__[ \t]*==[ \t]*['"]__main__['"]/
2859
+ },
2860
+ {
2861
+ lang: "html",
2862
+ w: 10,
2863
+ re: /^\s*<!DOCTYPE\s+html/i
2864
+ },
2865
+ {
2866
+ lang: "xml",
2867
+ w: 10,
2868
+ re: /^\s*<\?xml\s/i
2869
+ },
2870
+ {
2871
+ lang: "javascript",
2872
+ w: 6,
2873
+ re: /\bconsole\.(?:log|error|warn|info|debug)\s*\(/
2874
+ },
2875
+ {
2876
+ lang: "javascript",
2877
+ w: 6,
2878
+ re: /\b(?:const|let)\s+\w+\s*=|(?:^|\n)\s*var\s+\w+\s*=/
2879
+ },
2880
+ {
2881
+ lang: "javascript",
2882
+ w: 8,
2883
+ re: /\bexport\s+(?:default|const|function|class|async|\{|\*)|\bmodule\.exports\b|\brequire\s*\(\s*['"]/
2884
+ },
2885
+ {
2886
+ lang: "javascript",
2887
+ w: 5,
2888
+ re: /\bfunction(?:[ \t]+\w+)?[ \t]*\([^)]*\)[ \t]*\{|=>[ \t]*[{([`\w'"]/
2889
+ },
2890
+ {
2891
+ lang: "javascript",
2892
+ w: 5,
2893
+ re: /\bimport\b[^'"\n]*[ \t]from[ \t]*['"]/
2894
+ },
2895
+ {
2896
+ lang: "javascript",
2897
+ w: 4,
2898
+ re: /\.(?:map|filter|forEach|reduce|then|catch|find|some|every)\s*\(/
2899
+ },
2900
+ {
2901
+ lang: "javascript",
2902
+ w: 4,
2903
+ re: /\b(?:document|window|globalThis)\.\w/
2904
+ },
2905
+ {
2906
+ lang: "javascript",
2907
+ w: 4,
2908
+ re: /\baddEventListener\s*\(|\bquerySelector(?:All)?\s*\(|\bgetElementById\s*\(/
2909
+ },
2910
+ {
2911
+ lang: "javascript",
2912
+ w: 3,
2913
+ re: /\.(?:innerHTML|textContent|classList|dataset|style)\b|\bJSON\.(?:parse|stringify)\s*\(/
2914
+ },
2915
+ {
2916
+ lang: "javascript",
2917
+ w: 4,
2918
+ re: /\bawait\s+\w|\basync\s+(?:function|\(|\w+\s*=>)|\bnew\s+Promise\s*\(/
2919
+ },
2920
+ {
2921
+ lang: "javascript",
2922
+ w: 3,
2923
+ re: /\bReact\.|\buseState\s*\(|\buseEffect\s*\(/
2924
+ },
2925
+ {
2926
+ lang: "typescript",
2927
+ w: 8,
2928
+ re: /\binterface\s+\w+(?:<[^>]*>)?\s*(?:extends\s[\w<>, ]+)?\{/
2929
+ },
2930
+ {
2931
+ lang: "typescript",
2932
+ w: 8,
2933
+ re: /\btype\s+\w+(?:<[^>]*>)?\s*=/
2934
+ },
2935
+ {
2936
+ lang: "typescript",
2937
+ w: 7,
2938
+ re: /:\s*(?:string|number|boolean|void|never|any|unknown|object)\b/
2939
+ },
2940
+ {
2941
+ lang: "typescript",
2942
+ w: 6,
2943
+ re: /\benum\s+\w+\s*\{|\breadonly\s+\w|\bimplements\s+\w|\bnamespace\s+\w+\s*\{/
2944
+ },
2945
+ {
2946
+ lang: "typescript",
2947
+ w: 6,
2948
+ re: /\b(?:private|public|protected)\s+(?:readonly\s+)?\w+\s*[:?]/
2949
+ },
2950
+ {
2951
+ lang: "typescript",
2952
+ w: 5,
2953
+ re: /\)\s*:\s*[A-Z]\w*(?:<[^>]*>)?\s*(?:\{|=>)|\)\s*:\s*(?:string|number|boolean|void)\b/
2954
+ },
2955
+ {
2956
+ lang: "typescript",
2957
+ w: 4,
2958
+ re: /\bfunction\s+\w+\s*<[^>]+>\s*\(|\bas\s+(?:const\b|[A-Z]\w*)/
2959
+ },
2960
+ {
2961
+ lang: "typescript",
2962
+ w: 3,
2963
+ re: /\w\?\s*:\s*\w|\bimport\s+type\b|\bsatisfies\b/
2964
+ },
2965
+ {
2966
+ lang: "python",
2967
+ w: 6,
2968
+ re: /(?:^|\n)\s*(?:from\s+[\w.]+\s+import\s|import\s+\w+(?:\s*,\s*\w+)*\s*$)/m
2969
+ },
2970
+ {
2971
+ lang: "python",
2972
+ w: 6,
2973
+ re: /(?:^|\n)\s*class\s+\w+(?:\([\w., ]*\))?\s*:/
2974
+ },
2975
+ {
2976
+ lang: "python",
2977
+ w: 5,
2978
+ re: /(?:^|\n)\s*(?:with|elif|except|finally|async\s+def)\b[^\n]*:/
2979
+ },
2980
+ {
2981
+ lang: "python",
2982
+ w: 5,
2983
+ re: /\bself\.\w|\b__init__\b|\bf["'][^"']*\{/
2984
+ },
2985
+ {
2986
+ lang: "python",
2987
+ w: 4,
2988
+ re: /(?:^|\n)[ \t]*for[ \t]+\w+[ \t]+in[ \t][^\n:]*:|\bfor[ \t]+\w+[ \t]+in[ \t]+range[ \t]*\(/
2989
+ },
2990
+ {
2991
+ lang: "python",
2992
+ w: 4,
2993
+ re: /\bprint\s*\(|\blen\s*\(|\brange\s*\(/
2994
+ },
2995
+ {
2996
+ lang: "python",
2997
+ w: 3,
2998
+ re: /\[[^\]\n]*\bfor\s+\w+\s+in\s[^\]\n]*\]|\bNone\b|\bTrue\b|\bFalse\b/
2999
+ },
3000
+ {
3001
+ lang: "python",
3002
+ w: 3,
3003
+ re: /\*\*\w|\bdict[ \t]*\(|\blambda(?:[ \t]+\w+)?[ \t]*:/
3004
+ },
3005
+ {
3006
+ lang: "go",
3007
+ w: 8,
3008
+ re: /(?:^|\n)\s*package\s+\w+\s*$/m
3009
+ },
3010
+ {
3011
+ lang: "go",
3012
+ w: 6,
3013
+ re: /\btype\s+\w+\s+struct\s*\{|\btype\s+\w+\s+interface\s*\{/
3014
+ },
3015
+ {
3016
+ lang: "go",
3017
+ w: 6,
3018
+ re: /\bfunc(?:[ \t]*\([^)]*\))?(?:[ \t]+\w+)?[ \t]*\([^)]*\)[^\n{]{0,40}\{/
3019
+ },
3020
+ {
3021
+ lang: "go",
3022
+ w: 5,
3023
+ re: /\bif\s+err\s*!=\s*nil\b|\berr\s*:=\s|\bdefer\s+\w/
3024
+ },
3025
+ {
3026
+ lang: "go",
3027
+ w: 4,
3028
+ re: /\w+\s*:=\s*\S|\bchan\s+\w|\bgo\s+func\b|\bnil\b/
3029
+ },
3030
+ {
3031
+ lang: "rust",
3032
+ w: 7,
3033
+ re: /\bfn[ \t]+\w+(?:<[^>]*>)?[ \t]*\([^)]*\)[^\n{]{0,40}\{/
3034
+ },
3035
+ {
3036
+ lang: "rust",
3037
+ w: 7,
3038
+ re: /\blet\s+mut\s+\w|\bpub\s+(?:fn|struct|enum|mod|use)\b|\bimpl\s+\w/
3039
+ },
3040
+ {
3041
+ lang: "rust",
3042
+ w: 5,
3043
+ re: /\buse\s+(?:std|crate|self|super)::|\bmatch\s+\w+\s*\{[^}]*=>/
3044
+ },
3045
+ {
3046
+ lang: "rust",
3047
+ w: 4,
3048
+ re: /\b(?:Option|Result|Vec|Box|Rc|Arc|HashMap)\s*<|&(?:mut\s+)?self\b|\b\w+::<|->\s*Result</
3049
+ },
3050
+ {
3051
+ lang: "rust",
3052
+ w: 3,
3053
+ re: /\b(?:i8|i16|i32|i64|u8|u16|u32|u64|usize|isize|f32|f64)\b|\bunwrap\s*\(\)|\bderive\s*\(/
3054
+ },
3055
+ {
3056
+ lang: "java",
3057
+ w: 7,
3058
+ re: /\b(?:public|private|protected)\s+(?:static\s+)?(?:final\s+)?(?:void|int|long|double|boolean|String|[A-Z]\w*(?:<[^>]*>)?)\s+\w+\s*[({]/
3059
+ },
3060
+ {
3061
+ lang: "java",
3062
+ w: 7,
3063
+ re: /\bimport\s+(?:java|javax|org\.springframework)\.[\w.]+;/
3064
+ },
3065
+ {
3066
+ lang: "java",
3067
+ w: 6,
3068
+ re: /@(?:Override|Autowired|Component|Service|Controller|RestController|Entity|Test|SpringBootApplication)\b/
3069
+ },
3070
+ {
3071
+ lang: "java",
3072
+ w: 5,
3073
+ re: /\bnew\s+(?:ArrayList|HashMap|HashSet|LinkedList|StringBuilder)\s*<[^>]*>\s*\(|\bthrows\s+\w*Exception/
3074
+ },
3075
+ {
3076
+ lang: "java",
3077
+ w: 4,
3078
+ re: /\bpublic\s+(?:class|interface|enum)\s+\w|\bextends\s+\w+\s*\{|\bList<\w|\bMap<\w/
3079
+ },
3080
+ {
3081
+ lang: "csharp",
3082
+ w: 8,
3083
+ re: /\busing\s+System(?:\.[\w.]+)?\s*;|\bnamespace\s+[\w.]+\s*[{;]/
3084
+ },
3085
+ {
3086
+ lang: "csharp",
3087
+ w: 8,
3088
+ re: /\{\s*get;\s*(?:private\s+)?set;\s*\}|\b(?:public|private|protected|internal)\s+(?:static\s+)?async\s+Task(?:<[^>]*>)?\s+\w/
3089
+ },
3090
+ {
3091
+ lang: "csharp",
3092
+ w: 6,
3093
+ re: /\basync\s+Task(?:<[^>]*>)?\s+\w|\bawait\s+\w+\.\w+Async\s*\(/
3094
+ },
3095
+ {
3096
+ lang: "csharp",
3097
+ w: 5,
3098
+ re: /\bIEnumerable<|\bvar\s+\w+\s*=\s*new\s+\w|\bpublic\s+override\b|\[\s*(?:HttpGet|HttpPost|Serializable|Required)\s*\]/
3099
+ },
3100
+ {
3101
+ lang: "csharp",
3102
+ w: 3,
3103
+ re: /\.(?:Select|Where|FirstOrDefault|ToList|Any)\s*\(|\bstring\[\]\s+args\b/
3104
+ },
3105
+ {
3106
+ lang: "kotlin",
3107
+ w: 8,
3108
+ re: /\bfun\s+\w+\s*\([^)]*\)\s*(?::\s*[\w<>?.]+\s*)?[={]|\bdata\s+class\s+\w/
3109
+ },
3110
+ {
3111
+ lang: "kotlin",
3112
+ w: 6,
3113
+ re: /\bval[ \t]+\w+(?:[ \t]*:[ \t]*[\w<>?.]+)?[ \t]*=|\bcompanion[ \t]+object\b|\bsuspend[ \t]+fun\b/
3114
+ },
3115
+ {
3116
+ lang: "kotlin",
3117
+ w: 4,
3118
+ re: /\bprintln\s*\(|\bwhen\s*\([^)]*\)\s*\{|\bobject\s+\w+\s*[:{]|\?:\s*\w/
3119
+ },
3120
+ {
3121
+ lang: "swift",
3122
+ w: 8,
3123
+ re: /\bguard\s+(?:let|var)\s[^\n]*\belse\b|\bfunc\s+\w+\s*\([^)]*\)\s*(?:async\s+)?(?:throws\s+)?->\s*[\w<>?[\]]/
3124
+ },
3125
+ {
3126
+ lang: "swift",
3127
+ w: 6,
3128
+ re: /\bprotocol[ \t]+\w+[^\n{]{0,40}\{|\bextension[ \t]+\w+[^\n{]{0,40}\{|\bimport[ \t]+(?:SwiftUI|UIKit|Foundation)\b/
3129
+ },
3130
+ {
3131
+ lang: "swift",
3132
+ w: 6,
3133
+ re: /\b(?:let|var)\s+\w+\s*:\s*(?:Int|String|Double|Float|Bool|Character|Any|\[[A-Z])|@(?:State|Binding|Published|IBOutlet|objc)\b/
3134
+ },
3135
+ {
3136
+ lang: "swift",
3137
+ w: 4,
3138
+ re: /\\\(\w|\bif[ \t]+let[ \t]+\w|\bstruct[ \t]+\w+[ \t]*:[ \t]*View\b|\bfunc[ \t]+\w+[ \t]*\([^)]*:[ \t]*[A-Z]/
3139
+ },
3140
+ {
3141
+ lang: "swift",
3142
+ w: 3,
3143
+ re: /\?\?\s*\w|\b\w+\?\.\w|\bself\.\w+\s*=/
3144
+ },
3145
+ {
3146
+ lang: "cpp",
3147
+ w: 8,
3148
+ re: /#include\s*<(?:iostream|vector|map|set|algorithm|string|memory|utility)>/
3149
+ },
3150
+ {
3151
+ lang: "cpp",
3152
+ w: 6,
3153
+ re: /\btemplate\s*<\s*(?:typename|class)\b|\bnullptr\b|\bnamespace\s+\w+\s*\{/
3154
+ },
3155
+ {
3156
+ lang: "c",
3157
+ w: 8,
3158
+ re: /#include\s*<(?:stdio|stdlib|string|math|time|ctype|unistd)\.h>/
3159
+ },
3160
+ {
3161
+ lang: "c",
3162
+ w: 6,
3163
+ re: /\b(?:printf|scanf|malloc|calloc|free|memcpy|strlen)\s*\(/
3164
+ },
3165
+ {
3166
+ lang: "c",
3167
+ w: 4,
3168
+ re: /\bint\s+main\s*\(\s*(?:void|int\s+argc|\)\s*\{)/
3169
+ },
3170
+ {
3171
+ lang: "c",
3172
+ w: 3,
3173
+ re: /\btypedef\s+struct\b|\bsizeof\s*\(|\bNULL\b/
3174
+ },
3175
+ {
3176
+ lang: "ruby",
3177
+ w: 8,
3178
+ re: /\bdo[ \t]*\|[ \t]*\w[\w, ]*\|/
3179
+ },
3180
+ {
3181
+ lang: "ruby",
3182
+ w: 7,
3183
+ re: /\battr_(?:accessor|reader|writer)\s+:|\brequire(?:_relative)?\s+['"]|\bputs\s+\S/
3184
+ },
3185
+ {
3186
+ lang: "ruby",
3187
+ w: 4,
3188
+ re: /(?:^|\n)[ \t]*def[ \t]+\w/
3189
+ },
3190
+ {
3191
+ lang: "ruby",
3192
+ w: 4,
3193
+ re: /(?:^|\n)[ \t]*end[ \t]*$/m
3194
+ },
3195
+ {
3196
+ lang: "ruby",
3197
+ w: 4,
3198
+ re: /\bnil\?\b|\b\w+\.new\b|=>\s*['"\w]|\bmodule\s+[A-Z]\w*\s*$/m
3199
+ },
3200
+ {
3201
+ lang: "ruby",
3202
+ w: 3,
3203
+ re: /:\w+[ \t]*=>|\bend[ \t]*$/m
3204
+ },
3205
+ {
3206
+ lang: "php",
3207
+ w: 7,
3208
+ re: /\$this->\w|\bfunction\s+\w+\s*\([^)]*\$\w/
3209
+ },
3210
+ {
3211
+ lang: "php",
3212
+ w: 6,
3213
+ re: /\$\w+\s*=\s*\S|\bforeach\s*\(\s*\$\w+\s+as\s+\$/
3214
+ },
3215
+ {
3216
+ lang: "php",
3217
+ w: 5,
3218
+ re: /\becho[ \t][^;\n]*[$'"]|\bnamespace[ \t]+[\w\\]+;|\buse[ \t]+[\w\\]+\\\w+;/
3219
+ },
3220
+ {
3221
+ lang: "php",
3222
+ w: 8,
3223
+ re: /\b(?:public|private|protected)\s+(?:static\s+)?function\s+\w/
3224
+ },
3225
+ {
3226
+ lang: "php",
3227
+ w: 3,
3228
+ re: /->\w+\s*\(|::\w+\s*\(/
3229
+ },
3230
+ {
3231
+ lang: "html",
3232
+ w: 7,
3233
+ re: /<(?:html|head|body|nav|section|article|header|footer|main|form)\b[^>]*>/i
3234
+ },
3235
+ {
3236
+ lang: "html",
3237
+ w: 5,
3238
+ 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
3239
+ },
3240
+ {
3241
+ lang: "html",
3242
+ w: 4,
3243
+ re: /<\w+\s+(?:class|id|href|src|type|style)\s*=\s*["']/i
3244
+ },
3245
+ {
3246
+ lang: "xml",
3247
+ w: 6,
3248
+ re: /\bxmlns(?::\w+)?\s*=\s*["']|<\/\w+:\w+>|<\w+:\w+[\s>]/
3249
+ },
3250
+ {
3251
+ lang: "json",
3252
+ w: 8,
3253
+ re: /^\s*[{[][\s\S]*"[\w-]+"\s*:\s*(?:"[^"]*"|-?\d|\{|\[|true|false|null)/
3254
+ },
3255
+ {
3256
+ lang: "json",
3257
+ w: 3,
3258
+ re: /^\s*\{[\s\S]*\}\s*$|^\s*\[[\s\S]*\]\s*$/
3259
+ },
3260
+ {
3261
+ lang: "yaml",
3262
+ w: 8,
3263
+ re: /^---\s*$/m
3264
+ },
3265
+ {
3266
+ lang: "yaml",
3267
+ w: 6,
3268
+ re: /^[ \t]*-\s+\w+\s*:\s*\S/m
3269
+ },
3270
+ {
3271
+ lang: "yaml",
3272
+ w: 5,
3273
+ re: /^[a-z_][\w-]*[ \t]*:(?:[ \t]*$|[ \t]+(?:[|>][-+]?[ \t]*$|['"\w[{]))/im
3274
+ },
3275
+ {
3276
+ lang: "yaml",
3277
+ w: 4,
3278
+ re: /^[ \t]+[a-z_][\w-]*[ \t]*:[ \t]*\S/im
3279
+ },
3280
+ {
3281
+ lang: "yaml",
3282
+ w: 3,
3283
+ re: /^[ \t]*-\s+\S/m
3284
+ },
3285
+ {
3286
+ lang: "markdown",
3287
+ w: 7,
3288
+ re: /^#{1,6}\s+\S/m
3289
+ },
3290
+ {
3291
+ lang: "markdown",
3292
+ w: 6,
3293
+ re: /^```|^\|[^\n|]+\|[^\n]*\n\s*\|[\s:|-]+\|/m
3294
+ },
3295
+ {
3296
+ lang: "markdown",
3297
+ w: 4,
3298
+ re: /\[[^\]\n]+\]\([^)\n]+\)|!\[[^\]\n]*\]\(/
3299
+ },
3300
+ {
3301
+ lang: "markdown",
3302
+ w: 3,
3303
+ re: /\*\*[^*\n]+\*\*|^>\s+\S|^[-*+]\s+\S/m
3304
+ },
3305
+ {
3306
+ lang: "sql",
3307
+ w: 9,
3308
+ re: /(?:^|\n)\s*(?:SELECT\s+[\w*]|INSERT\s+INTO\s|UPDATE\s+\w+\s+SET\s|DELETE\s+FROM\s)/i
3309
+ },
3310
+ {
3311
+ lang: "sql",
3312
+ w: 8,
3313
+ re: /(?:^|\n)\s*(?:CREATE|ALTER|DROP)\s+(?:TABLE|DATABASE|INDEX|VIEW|SCHEMA)\b/i
3314
+ },
3315
+ {
3316
+ lang: "sql",
3317
+ w: 4,
3318
+ 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
3319
+ },
3320
+ {
3321
+ lang: "scss",
3322
+ w: 9,
3323
+ re: /^[ \t]*\$[\w-]+[ \t]*:[^;\n]+;|@(?:mixin|include|extend|use|forward)[ \t]+[\w"'-]/m
3324
+ },
3325
+ {
3326
+ lang: "scss",
3327
+ w: 7,
3328
+ re: /^[ \t]*&[\s.:[&>+~]|#\{[^}]*\}/m
3329
+ },
3330
+ {
3331
+ lang: "scss",
3332
+ w: 4,
3333
+ re: /^[ \t]*\/\/[ \t]*\S/m
3334
+ },
3335
+ {
3336
+ lang: "css",
3337
+ w: 6,
3338
+ 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
3339
+ },
3340
+ {
3341
+ lang: "css",
3342
+ w: 5,
3343
+ re: /@(?:media|supports|keyframes|font-face|import|charset)\b/
3344
+ },
3345
+ {
3346
+ lang: "css",
3347
+ w: 4,
3348
+ re: /:\s*(?:#[\da-f]{3,8}|\d+(?:px|rem|em|%|vh|vw)|flex|grid|block|none|absolute|relative)\s*[;}]/i
3349
+ },
3350
+ {
3351
+ lang: "css",
3352
+ w: 3,
3353
+ re: /::?(?:hover|focus|active|before|after|first-child|last-child|nth-child)\b/
3354
+ },
3355
+ {
3356
+ lang: "bash",
3357
+ w: 7,
3358
+ 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./-]/
3359
+ },
3360
+ {
3361
+ lang: "bash",
3362
+ w: 6,
3363
+ re: /^\s*(?:export|source|alias)\s+\w+|^\s*\w+=\S+\s*$/m
3364
+ },
3365
+ {
3366
+ lang: "bash",
3367
+ w: 6,
3368
+ re: /\bfi[ \t]*$|(?:^|\n)[ \t]*(?:if|for|while)[ \t][^\n]*;[ \t]*(?:then|do)\b|(?:^|\n)[ \t]*done\b/m
3369
+ },
3370
+ {
3371
+ lang: "bash",
3372
+ w: 5,
3373
+ re: /\$\{?\w+\}?[/:]|"\$\w|\becho\s+["'$]|\$\(\w/
3374
+ },
3375
+ {
3376
+ lang: "bash",
3377
+ w: 4,
3378
+ re: /(?:^|\n|\|)\s*(?:grep|awk|sed|cat|ls|cd|pwd|find|xargs|head|tail|sort|uniq|wc)\s+[-\w$'"./]/
3379
+ },
3380
+ {
3381
+ lang: "bash",
3382
+ w: 3,
3383
+ re: /\s\|[ \t]*\w|\s&&\s|\s2>&1|\s-[\w-]+\s/
3384
+ }
3385
+ ], xr = 4e3;
3386
+ function Sr(e) {
3387
+ if (e.length <= xr) return e;
3388
+ let t = e.slice(0, xr), n = t.lastIndexOf("\n");
3389
+ return n > 0 ? t.slice(0, n) : t;
3390
+ }
3391
+ function Cr(e) {
3392
+ if (!e?.trim()) return null;
3393
+ let t = Sr(e.trim()), n = /* @__PURE__ */ new Map();
3394
+ for (let { lang: e, re: r, w: i } of br) r.test(t) && n.set(e, (n.get(e) || 0) + i);
3395
+ if (n.size === 0) return null;
3396
+ for (let [e, t] of vr) {
3397
+ let r = n.get(e);
3398
+ r && n.set(e, r + (n.get(t) || 0));
3399
+ }
3400
+ let r = [...n.entries()].sort((e, t) => t[1] - e[1]), [i, a] = r[0], o = r[1]?.[1] ?? 0;
3401
+ return a < gr || a - o < _r ? null : i;
3402
+ }
3403
+ //#endregion
3404
+ //#region src/js/module/Editor.js
3405
+ var wr = class {
3406
+ constructor(e) {
3407
+ this.context = e, this.options = e.options, this._history = null, this._disposers = [], this._snapshotTimer = null;
3408
+ }
3409
+ initialize() {
3410
+ let e = this.context.layoutInfo.editable;
3411
+ return this._history = new Cn(e, this.options.historyLimit || 100, this.options.historyMaxBytes || 10 * 1024 * 1024), this._bindEvents(e), this;
3412
+ }
3413
+ destroy() {
3414
+ this._disposers.forEach((e) => e()), this._disposers = [], this._history = null, clearTimeout(this._snapshotTimer), this._snapshotTimer = null;
3415
+ }
3416
+ _bindEvents(e) {
3417
+ let t = (e) => this._onKeydown(e), n = () => this.afterCommand(), r = (e) => this._enforceLimit(e), i = () => {
3418
+ if (!this.context._alive) return;
3419
+ let t = globalThis.getSelection();
3420
+ t?.rangeCount > 0 && e.contains(t.anchorNode) && (this.context.invoke("toolbar.refresh"), typeof this.options.onSelectionChange == "function" && this.options.onSelectionChange(this.context));
3421
+ }, a = (e) => {
3422
+ e.target.type === "checkbox" && e.target.closest(".an-checklist") && this.afterCommand();
3423
+ }, o = (t) => {
3424
+ let n = globalThis.getSelection();
3425
+ if (!n?.rangeCount) return;
3426
+ let r = n.getRangeAt(0);
3427
+ if (!r.collapsed) return;
3428
+ let i = r.startContainer;
3429
+ if (i.nodeType !== Node.ELEMENT_NODE) return;
3430
+ let a = i, o = a.matches(".an-checklist li") ? a : null;
3431
+ if (!o) return;
3432
+ let s = o.querySelector("input[type=\"checkbox\"]");
3433
+ if (!s) return;
3434
+ if (t?.type === "mouseup") {
3435
+ let r = null;
3436
+ if (document.caretRangeFromPoint) r = document.caretRangeFromPoint(t.clientX, t.clientY);
3437
+ else if (document.caretPositionFromPoint) {
3438
+ let e = document.caretPositionFromPoint(t.clientX, t.clientY);
3439
+ e && (r = document.createRange(), r.setStart(e.offsetNode, e.offset));
3440
+ }
3441
+ if (r && e.contains(r.startContainer) && r.startContainer !== o) {
3442
+ r.collapse(!0), n.removeAllRanges(), n.addRange(r);
3443
+ return;
3444
+ }
3445
+ }
3446
+ let c = document.createRange(), l = null;
3447
+ for (let e of o.childNodes) if (e !== s && e.nodeType === Node.TEXT_NODE) {
3448
+ l = e;
3449
+ break;
3450
+ }
3451
+ l ? c.setStart(l, 0) : c.setStartAfter(s), c.collapse(!0), n.removeAllRanges(), n.addRange(c);
3452
+ }, s = () => this.context.layoutInfo.container.classList.contains("an-disabled");
3453
+ this._disposers.push(S(e, "keydown", t), S(e, "beforeinput", r), S(e, "input", n), S(document, "selectionchange", i), S(e, "click", a), S(e, "mouseup", o), S(e, "keyup", o), S(e, "dragstart", (e) => {
3454
+ if (s()) {
3455
+ e.preventDefault();
3456
+ return;
3457
+ }
3458
+ let t = e.target;
3459
+ t && (t.nodeName === "IFRAME" || t.closest(".an-video-wrapper")) && e.preventDefault();
3460
+ }), S(e, "drop", (e) => {
3461
+ s() && e.preventDefault();
3462
+ }));
3463
+ let c = null;
3464
+ this._disposers.push(S(e, "compositionstart", () => {
3465
+ let e = globalThis.getSelection();
3466
+ if (!e?.rangeCount) {
3467
+ c = null;
3468
+ return;
3469
+ }
3470
+ let t = e.getRangeAt(0).startContainer;
3471
+ if (t.nodeType === Node.TEXT_NODE && (t = t.parentElement), t) {
3472
+ let e = t;
3473
+ c = e.closest("sup") ? "superscript" : e.closest("sub") ? "subscript" : null;
3474
+ }
3475
+ }), S(e, "compositionend", () => {
3476
+ let e = c;
3477
+ if (c = null, !e) return;
3478
+ let t = globalThis.getSelection();
3479
+ if (!t?.rangeCount) return;
3480
+ let n = t.getRangeAt(0).startContainer;
3481
+ n.nodeType === Node.TEXT_NODE && (n = n.parentElement);
3482
+ let r = n;
3483
+ (e === "superscript" ? r?.closest("sup") : r?.closest("sub")) || document.execCommand(e);
3484
+ }));
3485
+ }
3486
+ _onKeydown(e) {
3487
+ let t = this.context.layoutInfo.editable;
3488
+ if (!On(e, t, this.options)) {
3489
+ if (I(e, "z") && !e.shiftKey) {
3490
+ e.preventDefault(), this.undo();
3491
+ return;
3492
+ }
3493
+ if (I(e, "z") && e.shiftKey || I(e, "y")) {
3494
+ e.preventDefault(), this.redo();
3495
+ return;
3496
+ }
3497
+ if (I(e, "b")) {
3498
+ e.preventDefault(), this.bold();
3499
+ return;
3500
+ }
3501
+ if (I(e, "i")) {
3502
+ e.preventDefault(), this.italic();
3503
+ return;
3504
+ }
3505
+ if (I(e, "u")) {
3506
+ e.preventDefault(), this.underline();
3507
+ return;
3508
+ }
3509
+ if (I(e, "k")) {
3510
+ e.preventDefault(), this.context.invoke("linkDialog.show");
3511
+ return;
3512
+ }
3513
+ if (I(e, "v") && e.shiftKey) {
3514
+ this.context.invoke("clipboard.setForcePlain", !0);
3515
+ return;
3516
+ }
3517
+ if (e.key === "/" && e.shiftKey && e.ctrlKey && !e.metaKey) {
3518
+ e.preventDefault(), this.context.invoke("shortcutsDialog.show");
3519
+ return;
3520
+ }
3521
+ if (I(e, "f")) {
3522
+ e.preventDefault(), this.context.invoke("findReplace.show", "find");
3523
+ return;
3524
+ }
3525
+ I(e, "h") && (e.preventDefault(), this.context.invoke("findReplace.show", "replace")), I(e, "`") && (e.preventDefault(), this.inlineCode());
3526
+ }
3527
+ }
3528
+ _enforceLimit(e) {
3529
+ let t = this.options.maxChars || 0, n = this.options.maxWords || 0;
3530
+ if (!t && !n) return;
3531
+ let r = e.inputType || "";
3532
+ if (r.startsWith("delete") || r === "historyUndo" || r === "historyRedo" || r === "insertFromPaste" || r === "insertFromDrop" || !r.startsWith("insert")) return;
3533
+ let i = this.context.layoutInfo.editable.innerText || "", a = i.replaceAll("\n", "").length;
3534
+ if (t && a >= t) {
3535
+ e.preventDefault(), typeof this.options.onCharLimitReached == "function" && this.options.onCharLimitReached(this.context);
3536
+ return;
3537
+ }
3538
+ 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));
3539
+ }
3540
+ afterCommand() {
3541
+ this._cleanOrphanedFigures(), this._ensureTrailingParagraph(), this.context.invoke("toolbar.refresh"), this.context.invoke("statusbar.update"), this._scheduleSnapshot();
3542
+ }
3543
+ _scheduleSnapshot() {
3544
+ clearTimeout(this._snapshotTimer), this._snapshotTimer = setTimeout(() => {
3545
+ this._snapshotTimer = null, this._history && this._history.recordUndo(), this.context.triggerEvent("change", this.getHTML());
3546
+ }, 400);
3547
+ }
3548
+ _cleanOrphanedFigures() {
3549
+ this.context.layoutInfo.editable.querySelectorAll("figure.an-figure").forEach((e) => {
3550
+ e.querySelector("img") || e.remove();
3551
+ });
3552
+ }
3553
+ _ensureTrailingParagraph() {
3554
+ let e = this.context.layoutInfo.editable;
3555
+ if (!e) return;
3556
+ let t = e.lastElementChild;
3557
+ if (t && (/* @__PURE__ */ new Set([
3558
+ "PRE",
3559
+ "BLOCKQUOTE",
3560
+ "TABLE",
3561
+ "FIGURE",
3562
+ "UL",
3563
+ "OL",
3564
+ "HR"
3565
+ ])).has(t.nodeName)) {
3566
+ let t = document.createElement("p");
3567
+ t.innerHTML = "<br>", e.appendChild(t);
3568
+ }
3569
+ }
3570
+ focus() {
3571
+ this.context.layoutInfo.editable.focus();
3572
+ }
3573
+ getHTML() {
3574
+ let e = this.context.layoutInfo.editable.innerHTML.replaceAll("​", "");
3575
+ return this.context.invoke("clipboard.resolveImages", e) ?? e;
3576
+ }
3577
+ setHTML(e) {
3578
+ this.context.layoutInfo.editable.innerHTML = j(e, { allowIframes: !0 }), this._history && this._history.reset(), this.afterCommand();
3579
+ }
3580
+ getText() {
3581
+ return this.context.layoutInfo.editable.innerText || "";
3582
+ }
3583
+ setText(e) {
3584
+ this.context.layoutInfo.editable.textContent = e, this._history && this._history.reset(), this.afterCommand();
3585
+ }
3586
+ clear() {
3587
+ this.setHTML("");
3588
+ }
3589
+ clearHistory() {
3590
+ this._history && this._history.reset();
3591
+ }
3592
+ isEmpty() {
3593
+ let e = (this.context.layoutInfo.editable.innerText || "").trim().replaceAll("\xA0", ""), t = !!this.context.layoutInfo.editable.querySelector("img, video, iframe, table");
3594
+ return !e && !t;
3595
+ }
3596
+ insertHTML(e) {
3597
+ e && (w("insertHTML", j(e)), this.afterCommand());
3598
+ }
3599
+ insertText(e) {
3600
+ e && (w("insertText", e), this.afterCommand());
3601
+ }
3602
+ setMarkdown(e) {
3603
+ this.setHTML(H(e || ""));
3604
+ }
3605
+ getMarkdown() {
3606
+ return kn(this.getHTML());
3607
+ }
3608
+ undo() {
3609
+ this._history && (this._flushPendingSnapshot(), this._history.undo(), this.context.invoke("toolbar.refresh"), this.context.invoke("statusbar.update"), this.context.triggerEvent("change", this.getHTML()));
3610
+ }
3611
+ redo() {
3612
+ this._history && (this._flushPendingSnapshot(), this._history.redo(), this.context.invoke("toolbar.refresh"), this.context.invoke("statusbar.update"), this.context.triggerEvent("change", this.getHTML()));
3613
+ }
3614
+ _flushPendingSnapshot() {
3615
+ this._snapshotTimer !== null && (clearTimeout(this._snapshotTimer), this._snapshotTimer = null, this._history?.recordUndo());
3616
+ }
3617
+ canUndo() {
3618
+ return this._history ? this._history.canUndo() : !1;
3619
+ }
3620
+ canRedo() {
3621
+ return this._history ? this._history.canRedo() : !1;
3622
+ }
3623
+ getUndoCount() {
3624
+ return this._history ? this._history.getUndoCount() : 0;
3625
+ }
3626
+ getRedoCount() {
3627
+ return this._history ? this._history.getRedoCount() : 0;
3628
+ }
3629
+ getSelectionBookmark() {
3630
+ return this._history?._serializeSelection() ?? null;
3631
+ }
3632
+ restoreSelectionBookmark(e) {
3633
+ return !e || !this._history ? !1 : (this._history._restoreSelection(e), !0);
3634
+ }
3635
+ bold() {
3636
+ Ie(), this.afterCommand();
3637
+ }
3638
+ italic() {
3639
+ Le(), this.afterCommand();
3640
+ }
3641
+ underline() {
3642
+ Re(), this.afterCommand();
3643
+ }
3644
+ strikethrough() {
3645
+ ze(), this.afterCommand();
3646
+ }
3647
+ superscript() {
3648
+ Be(), this.afterCommand();
3649
+ }
3650
+ subscript() {
3651
+ Ve(), this.afterCommand();
3652
+ }
3653
+ justifyLeft() {
3654
+ qe(), this.afterCommand();
3655
+ }
3656
+ justifyCenter() {
3657
+ Je(), this.afterCommand();
3658
+ }
3659
+ justifyRight() {
3660
+ Ye(), this.afterCommand();
3661
+ }
3662
+ justifyFull() {
3663
+ Xe(), this.afterCommand();
3664
+ }
3665
+ indent() {
3666
+ Ze(), this.afterCommand();
3667
+ }
3668
+ outdent() {
3669
+ Qe(), this.afterCommand();
3670
+ }
3671
+ insertUL() {
3672
+ nt(), this.afterCommand();
3673
+ }
3674
+ insertOL() {
3675
+ rt(), this.afterCommand();
3676
+ }
3677
+ inlineCode() {
3678
+ at(this.context.layoutInfo.editable), this.afterCommand();
3679
+ }
3680
+ toggleChecklist() {
3681
+ ct(), this.afterCommand();
3682
+ }
3683
+ print() {
3684
+ this.context.print();
3685
+ }
3686
+ formatBlock(e) {
3687
+ if (Ke(e), e === "pre") {
3688
+ let e = globalThis.getSelection();
3689
+ if (e?.rangeCount > 0) {
3690
+ let t = e.getRangeAt(0).commonAncestorContainer, n = t.nodeType === 1 ? t.closest("pre") : t.parentElement?.closest("pre");
3691
+ if (n && !n.dataset.language) {
3692
+ let e = Cr(n.textContent || "");
3693
+ if (e) {
3694
+ this.context.invoke("codeTooltip.applyLanguage", n, e);
3695
+ return;
3696
+ }
3697
+ }
3698
+ }
3699
+ }
3700
+ this.afterCommand();
3701
+ }
3702
+ foreColor(e) {
3703
+ He(e), this.afterCommand();
3704
+ }
3705
+ backColor(e) {
3706
+ Ue(e), this.afterCommand();
3707
+ }
3708
+ fontName(e) {
3709
+ We(e), this.afterCommand();
3710
+ }
3711
+ fontSize(e) {
3712
+ Ge(e, this.context.layoutInfo.editable), this.afterCommand();
3713
+ }
3714
+ insertHr() {
3715
+ w("insertHorizontalRule"), this.afterCommand();
3716
+ }
3717
+ insertLink(e, t, n = !1) {
3718
+ let r = globalThis.getSelection();
3719
+ if (!r || r.rangeCount === 0) return;
3720
+ let i = M(e);
3721
+ if (i) {
3722
+ if (r.toString().trim().length > 0) {
3723
+ if (w("createLink", i), n) {
3724
+ let e = this._getClosestAnchor();
3725
+ e && (e.setAttribute("target", "_blank"), e.setAttribute("rel", "noopener noreferrer"));
3726
+ }
3727
+ } else {
3728
+ let e = this._escapeAttr(t || i);
3729
+ w("insertHTML", `<a href="${this._escapeAttr(i)}"${n ? " target=\"_blank\" rel=\"noopener noreferrer\"" : ""}>${e}</a>`);
3730
+ }
3731
+ this.afterCommand();
3732
+ }
3733
+ }
3734
+ unlink() {
3735
+ w("unlink"), this.afterCommand();
3736
+ }
3737
+ insertImage(e, t = "", n = "") {
3738
+ let r = M(e, { allowData: !0 });
3739
+ if (!r) return;
3740
+ let i = {
3741
+ left: "float:left;margin:0 1em 1em 0",
3742
+ center: "display:block;margin:0 auto",
3743
+ right: "float:right;margin:0 0 1em 1em"
3744
+ }[n] || "", a = i ? ` style="${i}"` : "";
3745
+ w("insertHTML", `<img src="${this._escapeAttr(r)}" alt="${this._escapeAttr(t)}" class="an-image"${a}>`), this.afterCommand();
3746
+ }
3747
+ insertVideo(e) {
3748
+ e && (w("insertHTML", e), this.afterCommand());
3749
+ }
3750
+ insertTable(e, t) {
3751
+ Tn(e, t, { headerRow: this.context.options.tableHeaderRow }), this.afterCommand();
3752
+ }
3753
+ _getClosestAnchor() {
3754
+ let e = globalThis.getSelection();
3755
+ if (!e || e.rangeCount === 0) return null;
3756
+ let t = e.getRangeAt(0).startContainer;
3757
+ for (; t;) {
3758
+ if (t.nodeName === "A") return t;
3759
+ t = t.parentNode;
3760
+ }
3761
+ return null;
3762
+ }
3763
+ _escapeAttr(e) {
3764
+ return String(e ?? "").replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
3765
+ }
3766
+ }, Tr = (e) => typeof e == "string" ? ut(e) : e, Y = null, Er = "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" ${Er} style="display:block">${e}</svg>`, Z = /* @__PURE__ */ new Map([
3767
+ ["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\"/>")],
3768
+ ["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\"/>")],
3769
+ ["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\"/>")],
3770
+ ["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\"/>")],
3771
+ ["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\"/>")],
3772
+ ["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\"/>")],
3773
+ ["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\"/>")],
3774
+ ["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\"/>")],
3775
+ ["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\"/>")],
3776
+ ["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\"/>")],
3777
+ ["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\"/>")],
3778
+ ["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\"/>")],
3779
+ ["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\"/>")],
3780
+ ["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\"/>")],
3781
+ ["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\"/>")],
3782
+ ["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\"/>")],
3783
+ ["minus", X("<line x1=\"5\" y1=\"12\" x2=\"19\" y2=\"12\"/>")],
3784
+ ["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\"/>")],
3785
+ ["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\"/>")],
3786
+ ["video", X("<polygon points=\"23 7 16 12 23 17 23 7\"/><rect x=\"1\" y=\"5\" width=\"15\" height=\"14\" rx=\"2\"/>")],
3787
+ ["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\"/>")],
3788
+ ["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\"/>")],
3789
+ ["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\"/>")],
3790
+ ["code", X("<polyline points=\"16 18 22 12 16 6\"/><polyline points=\"8 6 2 12 8 18\"/>")],
3791
+ ["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\"/>")],
3792
+ ["foreColor", X("<path d=\"M4 20L12 4L20 20\"/><line x1=\"7.5\" y1=\"14\" x2=\"16.5\" y2=\"14\"/>")],
3793
+ ["backColor", X("<path d=\"M3 21v-4l9-9 4 4-9 9z\"/><path d=\"M12 8l4 4\"/>")],
3794
+ ["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\"/>")],
3795
+ ["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\"/>")],
3796
+ ["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\"/>")],
3797
+ ["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\"/>")],
3798
+ ["search", X("<circle cx=\"11\" cy=\"11\" r=\"7\"/><line x1=\"21\" y1=\"21\" x2=\"16.65\" y2=\"16.65\"/>")],
3799
+ ["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\"/>")],
3800
+ ["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\"/>")],
3801
+ ["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\"/>")],
3802
+ ["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\"/>")]
3803
+ ]), Dr = /* @__PURE__ */ new Map([
3804
+ ["bold", "fa-bold"],
3805
+ ["italic", "fa-italic"],
3806
+ ["underline", "fa-underline"],
3807
+ ["strikethrough", "fa-strikethrough"],
3808
+ ["superscript", "fa-superscript"],
3809
+ ["subscript", "fa-subscript"],
3810
+ ["align-left", "fa-align-left"],
3811
+ ["align-center", "fa-align-center"],
3812
+ ["align-right", "fa-align-right"],
3813
+ ["align-justify", "fa-align-justify"],
3814
+ ["list-ul", "fa-list-ul"],
3815
+ ["list-ol", "fa-list-ol"],
3816
+ ["indent", "fa-indent"],
3817
+ ["outdent", "fa-outdent"],
3818
+ ["undo", "fa-rotate-left"],
3819
+ ["redo", "fa-rotate-right"],
3820
+ ["minus", "fa-minus"],
3821
+ ["link", "fa-link"],
3822
+ ["image", "fa-image"],
3823
+ ["code", "fa-code"],
3824
+ ["expand", "fa-expand"],
3825
+ ["emoji", "fa-face-smile"],
3826
+ ["icon", "fa-icons"],
3827
+ ["foreColor", "fa-font"],
3828
+ ["backColor", "fa-highlighter"],
3829
+ ["keyboard", "fa-keyboard"],
3830
+ ["remove-format", "fa-remove-format"],
3831
+ ["direction", "fa-arrow-right-arrow-left"],
3832
+ ["search", "fa-magnifying-glass"],
3833
+ ["find-replace", "fa-magnifying-glass-plus"],
3834
+ ["inline-code", "fa-code"],
3835
+ ["checklist", "fa-list-check"],
3836
+ ["print", "fa-print"]
3837
+ ]), Or = class {
3838
+ constructor(e) {
3839
+ this.context = e, this.options = e.options, this.el = null, this._disposers = [], this._colorPickerClosers = [], this._refreshRaf = null;
3840
+ }
3841
+ initialize() {
3842
+ return this.el = b("div", {
3843
+ class: "an-toolbar",
3844
+ role: "toolbar",
3845
+ "aria-orientation": "horizontal",
3846
+ "aria-label": "Editor toolbar"
3847
+ }), this._faReady = this._detectFontAwesome(), this._buildButtons(), this._initRovingFocus(), this._btnMap = new Map((this.options.toolbar || []).flat().map(Tr).filter(Boolean).map((e) => [e.name, e])), this;
3848
+ }
3849
+ destroy() {
3850
+ this._refreshRaf && cancelAnimationFrame(this._refreshRaf), this._refreshRaf = null, this._disposers.forEach((e) => e()), this._disposers = [], this.el?.parentNode && this.el.remove(), this.el = null;
3851
+ }
3852
+ _buildButtons() {
3853
+ let e = this.options.toolbar || [], t = document.createDocumentFragment();
3854
+ e.forEach((e) => {
3855
+ let n = b("div", { class: "an-btn-group" });
3856
+ e.forEach((e) => {
3857
+ let t = Tr(e);
3858
+ if (!t) {
3859
+ console.warn(`[AutumnNote] Toolbar: button "${e}" not found in registry. Skipped.`);
3860
+ return;
3861
+ }
3862
+ let r;
3863
+ 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);
3864
+ }), t.appendChild(n);
3865
+ }), this.el.appendChild(t);
3866
+ }
3867
+ _createGridPicker(e) {
3868
+ let t = b("div", { class: "an-table-picker-wrap" }), n = b("button", {
3869
+ type: "button",
3870
+ class: this.options.useBootstrap ? this.options.toolbarButtonClass || "btn btn-sm btn-light" : "an-btn",
3871
+ title: this.context.locale.toolbar[e.name] || e.tooltip || "",
3872
+ "data-btn": e.name,
3873
+ "aria-label": this.context.locale.toolbar[e.name] || e.tooltip || e.name,
3874
+ "aria-haspopup": "true",
3875
+ "aria-expanded": "false"
3876
+ });
3877
+ 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>";
3878
+ let r = b("div", {
3879
+ class: "an-table-picker-popup",
3880
+ role: "dialog",
3881
+ "aria-label": "Select table size"
3882
+ }), i = b("div", { class: "an-table-grid" }), a = b("div", { class: "an-table-label" });
3883
+ a.textContent = this.context.locale.toolbar.insertTableLabel || "Insert Table";
3884
+ let o = [];
3885
+ for (let e = 1; e <= 10; e++) for (let t = 1; t <= 10; t++) {
3886
+ let n = b("div", {
3887
+ class: "an-table-cell",
3888
+ "data-row": String(e),
3889
+ "data-col": String(t)
3890
+ });
3891
+ o.push(n), i.appendChild(n);
3892
+ }
3893
+ r.appendChild(i), r.appendChild(a);
3894
+ let s = !1, c = (e, t) => {
3895
+ o.forEach((n) => {
3896
+ let r = +n.dataset.row, i = +n.dataset.col;
3897
+ n.classList.toggle("active", r <= e && i <= t);
3898
+ }), a.textContent = e && t ? `${e} × ${t}` : this.context.locale.toolbar.insertTableLabel || "Insert Table";
3899
+ }, l = () => {
3900
+ s = !0;
3901
+ let e = n.getBoundingClientRect();
3902
+ r.style.visibility = "hidden", r.style.display = "block";
3903
+ let t = r.offsetWidth, i = r.offsetHeight, a = e.left, o = e.bottom + 4;
3904
+ 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");
3905
+ }, u = () => {
3906
+ s = !1, r.style.display = "none", n.setAttribute("aria-expanded", "false"), c(0, 0);
3907
+ }, d = S(n, "click", (e) => {
3908
+ e.stopPropagation(), s ? u() : l();
3909
+ }), f = S(i, "mouseover", (e) => {
3910
+ let t = e.target?.closest(".an-table-cell");
3911
+ t && c(+t.dataset.row, +t.dataset.col);
3912
+ }), p = S(i, "mouseleave", () => c(0, 0)), m = S(i, "click", (t) => {
3913
+ let n = t.target?.closest(".an-table-cell");
3914
+ if (!n) return;
3915
+ let r = +n.dataset.row, i = +n.dataset.col;
3916
+ u(), this.context.invoke("editor.focus"), e.action(this.context, r, i);
3917
+ }), h = S(document, "click", () => {
3918
+ s && u();
3919
+ });
3920
+ return this._disposers.push(d, f, p, m, h, () => {
3921
+ r.parentNode && r.remove();
3922
+ }), t.appendChild(n), document.body.appendChild(r), t;
3923
+ }
3924
+ _createColorPicker(e) {
3925
+ let t = [
3926
+ "#000000",
3927
+ "#434343",
3928
+ "#666666",
3929
+ "#999999",
3930
+ "#b7b7b7",
3931
+ "#cccccc",
3932
+ "#efefef",
3933
+ "#ffffff",
3934
+ "#ff0000",
3935
+ "#ff9900",
3936
+ "#ffff00",
3937
+ "#00ff00",
3938
+ "#00ffff",
3939
+ "#4a86e8",
3940
+ "#9900ff",
3941
+ "#ff00ff",
3942
+ "#f4cccc",
3943
+ "#fce5cd",
3944
+ "#fff2cc",
3945
+ "#d9ead3",
3946
+ "#d0e0e3",
3947
+ "#c9daf8",
3948
+ "#d9d2e9",
3949
+ "#ead1dc"
3950
+ ], n = e.defaultColor || "#000000", r = b("div", { class: "an-color-picker-wrap" }), i = this.options.useBootstrap ? this.options.toolbarButtonClass || "btn btn-sm btn-light" : "an-btn", a = b("button", {
3951
+ type: "button",
3952
+ class: `${i} an-color-btn`,
3953
+ title: this.context.locale.toolbar[e.name] || e.tooltip || "",
3954
+ "data-btn": e.name,
3955
+ "aria-label": this.context.locale.toolbar[e.name] || e.tooltip || e.name
3956
+ }), o = "stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"";
3957
+ 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>`;
3958
+ let s = b("span", { class: "an-color-strip" });
3959
+ s.style.background = n, a.appendChild(s);
3960
+ let c = b("button", {
3961
+ type: "button",
3962
+ class: `${i} an-color-arrow`,
3963
+ title: e.name === "foreColor" ? this.context.locale.toolbar.chooseTextColor || "Choose text color" : this.context.locale.toolbar.chooseHighlightColor || "Choose highlight color",
3964
+ "aria-haspopup": "true",
3965
+ "aria-expanded": "false"
3966
+ });
3967
+ 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>";
3968
+ let l = b("div", { class: "an-color-popup" });
3969
+ l.style.display = "none";
3970
+ let u = b("div", { class: "an-color-swatches" }), d = Array.isArray(this.options.colorSwatches) ? this.options.colorSwatches : [];
3971
+ [.../* @__PURE__ */ new Set([...d, ...t])].forEach((e) => {
3972
+ let t = b("div", {
3973
+ class: "an-color-swatch",
3974
+ title: e,
3975
+ "data-color": e
3976
+ });
3977
+ t.style.background = e, u.appendChild(t);
3978
+ });
3979
+ let f = b("div", { class: "an-color-custom" }), p = b("input", {
3980
+ type: "color",
3981
+ value: n,
3982
+ title: this.context.locale.toolbar.customColor || "Custom color"
3983
+ }), m = b("span", {}, [this.context.locale.toolbar.customColor || "Custom color"]);
3984
+ f.appendChild(p), f.appendChild(m), l.appendChild(u), l.appendChild(f);
3985
+ let h = !1, g = null, ee = () => {
3986
+ let e = globalThis.getSelection();
3987
+ g = e?.rangeCount ? e.getRangeAt(0).cloneRange() : null;
3988
+ }, te = () => {
3989
+ if (g) try {
3990
+ let e = globalThis.getSelection();
3991
+ if (!e) return;
3992
+ e.removeAllRanges(), e.addRange(g);
3993
+ } catch {}
3994
+ }, ne = () => {
3995
+ this._colorPickerClosers.forEach((e) => {
3996
+ e !== _ && e();
3997
+ }), ee(), h = !0;
3998
+ let e = c.getBoundingClientRect(), t = e.left;
3999
+ 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");
4000
+ }, _ = () => {
4001
+ h = !1, l.style.display = "none", l.style.top = "", l.style.left = "", c.setAttribute("aria-expanded", "false");
4002
+ }, v = (t) => {
4003
+ n = t, s.style.background = t, p.value = t, te(), e.action(this.context, t), this.context.invoke("editor.afterCommand"), _();
4004
+ }, re = S(a, "click", (t) => {
4005
+ t.preventDefault(), te(), e.action(this.context, n), this.context.invoke("editor.afterCommand");
4006
+ }), ie = S(c, "mousedown", (e) => {
4007
+ e.preventDefault();
4008
+ }), y = S(c, "click", (e) => {
4009
+ e.stopPropagation(), h ? _() : ne();
4010
+ }), ae = S(u, "mousedown", (e) => {
4011
+ e.preventDefault();
4012
+ }), oe = S(u, "click", (e) => {
4013
+ let t = e.target?.closest(".an-color-swatch");
4014
+ t && v(t.dataset.color);
4015
+ }), se = S(p, "change", (e) => {
4016
+ v(e.target.value);
4017
+ }), ce = S(document, "click", (e) => {
4018
+ h && !r.contains(e.target) && !l.contains(e.target) && _();
4019
+ }), le = S(l, "click", (e) => e.stopPropagation()), x = () => {
4020
+ h && _();
4021
+ };
4022
+ return document.addEventListener("scroll", x, {
4023
+ passive: !0,
4024
+ capture: !0
4025
+ }), globalThis.addEventListener("resize", x, { passive: !0 }), this._disposers.push(re, ie, y, ae, oe, se, ce, le, () => document.removeEventListener("scroll", x, { capture: !0 }), () => globalThis.removeEventListener("resize", x), () => {
4026
+ l.parentNode && l.remove();
4027
+ }), this._colorPickerClosers.push(_), this._disposers.push(() => {
4028
+ let e = this._colorPickerClosers.indexOf(_);
4029
+ e !== -1 && this._colorPickerClosers.splice(e, 1);
4030
+ }), r.appendChild(a), r.appendChild(c), document.body.appendChild(l), r;
4031
+ }
4032
+ _createSelect(e) {
4033
+ let t = e.name === "fontFamily" ? this.options.fontFamilies || [] : e.items || [], n = b("select", {
4034
+ class: e.selectClass ? `an-select ${e.selectClass}` : "an-select",
4035
+ title: this.context.locale.toolbar[e.name] || e.tooltip || "",
4036
+ "data-btn": e.name,
4037
+ "aria-label": this.context.locale.toolbar[e.name] || e.tooltip || e.name
4038
+ }), r = b("option", {
4039
+ value: "",
4040
+ disabled: "",
4041
+ hidden: ""
4042
+ }, [this.context.locale.toolbar[e.name + "Placeholder"] || e.placeholder || "Font"]);
4043
+ n.appendChild(r), t.forEach((t) => {
4044
+ let r = typeof t == "object" ? t.value : t, i;
4045
+ i = typeof t == "object" ? e.name === "paragraphStyle" && this.context.locale.toolbar.paragraphItems?.[t.value] || t.label : t;
4046
+ let a = typeof t == "object" && !!t.disabled, o = { value: r };
4047
+ a && (o.disabled = "");
4048
+ let s = b("option", o, [i]);
4049
+ e.name === "fontFamily" && !a && (s.style.fontFamily = r), n.appendChild(s);
4050
+ });
4051
+ let i = null, a = S(n, "mousedown", () => {
4052
+ let e = globalThis.getSelection();
4053
+ i = e?.rangeCount ? e.getRangeAt(0).cloneRange() : null;
4054
+ }), o = S(n, "change", (t) => {
4055
+ let n = t.target.value, r = t.target.options[t.target.selectedIndex];
4056
+ if (!(!n || r.disabled)) {
4057
+ if (this.context.invoke("editor.focus"), i) try {
4058
+ let e = globalThis.getSelection();
4059
+ e && (e.removeAllRanges(), e.addRange(i));
4060
+ } catch {}
4061
+ e.action(this.context, n), this.context.invoke("editor.afterCommand");
4062
+ }
4063
+ });
4064
+ return this._disposers.push(a, o), n;
4065
+ }
4066
+ _createButton(e) {
4067
+ let t = b("button", {
4068
+ type: "button",
4069
+ class: `${this.options.useBootstrap ? this.options.toolbarButtonClass || "btn btn-sm btn-light" : "an-btn"}${e.className ? ` ${e.className}` : ""}`,
4070
+ title: this.context.locale.toolbar[e.name] || e.tooltip || "",
4071
+ "data-btn": e.name,
4072
+ "aria-label": this.context.locale.toolbar[e.name] || e.tooltip || e.name,
4073
+ ...typeof e.isActive == "function" ? { "aria-pressed": "false" } : {}
4074
+ }), n = this.options.fontAwesomeClass || "fas";
4075
+ if (this._faReady) {
4076
+ let r = Dr.get(e.icon) || Dr.get(e.name) || null;
4077
+ 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;
4078
+ } 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;
4079
+ let r = S(t, "click", (t) => {
4080
+ t.preventDefault(), this.context.invoke("editor.focus"), e.action(this.context), this.context.invoke("editor.afterCommand"), this.refresh();
4081
+ });
4082
+ return this._disposers.push(r), t;
4083
+ }
4084
+ _controls() {
4085
+ return this.el ? Array.from(this.el.querySelectorAll("button, select")) : [];
4086
+ }
4087
+ _navigable() {
4088
+ return this._controls().filter((e) => !e.disabled);
4089
+ }
4090
+ _syncRovingTabindex(e) {
4091
+ let t = this._controls(), n = this._navigable();
4092
+ if (!n.length) return;
4093
+ let r = e && n.includes(e) ? e : n.find((e) => e.getAttribute("tabindex") === "0") || n[0];
4094
+ t.forEach((e) => e.setAttribute("tabindex", e === r ? "0" : "-1"));
4095
+ }
4096
+ _initRovingFocus() {
4097
+ this.el && (this._syncRovingTabindex(), this._disposers.push(S(this.el, "keydown", (e) => this._onToolbarKeydown(e)), S(this.el, "focusin", (e) => {
4098
+ let t = e.target?.closest?.("button, select");
4099
+ t && this._syncRovingTabindex(t);
4100
+ })));
4101
+ }
4102
+ _onToolbarKeydown(e) {
4103
+ if (![
4104
+ "ArrowRight",
4105
+ "ArrowLeft",
4106
+ "Home",
4107
+ "End"
4108
+ ].includes(e.key)) return;
4109
+ let t = this._navigable(), n = e.target?.closest?.("button, select"), r = n ? t.indexOf(n) : -1;
4110
+ if (r === -1) return;
4111
+ let i;
4112
+ if (e.key === "Home") i = t[0];
4113
+ else if (e.key === "End") i = t.at(-1);
4114
+ else {
4115
+ let n = this.options.direction === "rtl";
4116
+ i = t[(r + (e.key === "ArrowRight" === n ? -1 : 1) + t.length) % t.length];
4117
+ }
4118
+ i && (e.preventDefault(), this._syncRovingTabindex(i), i.focus());
4119
+ }
4120
+ _detectFontAwesome() {
4121
+ if (!this.options.useFontAwesome) return !1;
4122
+ if (Y !== null) return Y;
4123
+ if (document.querySelector(".fa, .fas, .far, .fal, .fab, .fa-solid")) return Y = !0, !0;
4124
+ let e = Array.from(document.querySelectorAll("link[rel=\"stylesheet\"]")).filter((e) => e.id !== "an-fontawesome-css").map((e) => e.href || "").join(" ");
4125
+ return Y = /fontawesome|font-awesome|use\.fontawesome|all\.css/.test(e), Y;
4126
+ }
4127
+ refresh() {
4128
+ this._refreshRaf && cancelAnimationFrame(this._refreshRaf), this._refreshRaf = requestAnimationFrame(() => {
4129
+ this._refreshRaf = null, this._doRefresh();
4130
+ });
4131
+ }
4132
+ _doRefresh() {
4133
+ if (!this.el) return;
4134
+ let e = this._btnMap || /* @__PURE__ */ new Map();
4135
+ this.el.querySelectorAll("button[data-btn]").forEach((t) => {
4136
+ let n = e.get(t.dataset.btn);
4137
+ if (n && typeof n.isActive == "function") {
4138
+ let e = !!n.isActive(this.context);
4139
+ t.classList.toggle("active", e), t.setAttribute("aria-pressed", String(e));
4140
+ }
4141
+ n && typeof n.isDisabled == "function" && (t.disabled = !!n.isDisabled(this.context));
4142
+ }), this._syncRovingTabindex(), this.el.querySelectorAll("select[data-btn]").forEach((t) => {
4143
+ let n = e.get(t.dataset.btn);
4144
+ if (!n || typeof n.getValue != "function") return;
4145
+ let r = (n.getValue(this.context) || "").replace(/["']/g, "").trim();
4146
+ r ||= this.options.defaultFontFamily || this.options.fontFamilies?.[0] || "";
4147
+ let i = t, a = Array.from(i.options).find((e) => e.value?.toLowerCase() === r.toLowerCase());
4148
+ i.value = a ? a.value : "";
4149
+ });
4150
+ }
4151
+ show() {
4152
+ this.el && (this.el.style.display = "");
4153
+ }
4154
+ hide() {
4155
+ this.el && (this.el.style.display = "none");
4156
+ }
4157
+ rebuild() {
4158
+ 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(Tr).filter(Boolean).map((e) => [e.name, e])), this.refresh();
4159
+ }
4160
+ }, kr = typeof Intl < "u" && typeof Intl.Segmenter == "function" ? new Intl.Segmenter(void 0, { granularity: "word" }) : null;
4161
+ function Ar(e) {
4162
+ let t = e.trim();
4163
+ if (!t) return 0;
4164
+ if (kr) {
4165
+ let e = 0;
4166
+ for (let n of kr.segment(t)) n.isWordLike && e++;
4167
+ return e;
4168
+ }
4169
+ return t.split(/\s+/).length;
4170
+ }
4171
+ function jr(e, t, n) {
4172
+ if (!n) {
4173
+ e.classList.remove("an-count-warn", "an-count-exceeded");
4174
+ return;
4175
+ }
4176
+ 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");
4177
+ }
4178
+ //#endregion
4179
+ //#region src/js/presets/core.js
4180
+ var Mr = [
4181
+ {
4182
+ name: "editor",
4183
+ Class: wr
4184
+ },
4185
+ {
4186
+ name: "toolbar",
4187
+ Class: Or
4188
+ },
4189
+ {
4190
+ name: "statusbar",
4191
+ Class: class {
4192
+ constructor(e) {
4193
+ this.context = e, this.options = e.options, this.el = null, this._disposers = [], this._wordCountEl = null, this._charCountEl = null;
4194
+ }
4195
+ initialize() {
4196
+ if (this.el = b("div", { class: "an-statusbar" }), this.options.resizable !== !1) {
4197
+ let e = b("div", {
4198
+ class: "an-resize-handle",
4199
+ title: this.context.locale.statusbar.resizeHandle,
4200
+ "aria-hidden": "true"
4201
+ });
4202
+ this._bindResize(e), this.el.appendChild(e);
4203
+ }
4204
+ this._wordCountEl = b("span", {
4205
+ class: "an-word-count",
4206
+ role: "status",
4207
+ "aria-live": "polite",
4208
+ "aria-atomic": "true"
4209
+ }), this._charCountEl = b("span", {
4210
+ class: "an-char-count",
4211
+ "aria-live": "polite",
4212
+ "aria-atomic": "true"
4213
+ });
4214
+ let e = b("div", {
4215
+ class: "an-status-info",
4216
+ "aria-label": "Editor statistics"
4217
+ });
4218
+ return e.appendChild(this._wordCountEl), e.appendChild(this._charCountEl), this.el.appendChild(e), this.update(), this;
4219
+ }
4220
+ destroy() {
4221
+ this._disposers.forEach((e) => e()), this._disposers = [], this._dragDisposers &&= (this._dragDisposers.forEach((e) => e()), null), this.el?.remove(), this.el = null;
4222
+ }
4223
+ _bindResize(e) {
4224
+ let t = 0, n = 0, r = this.context.layoutInfo.container, i = (e) => {
4225
+ 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);
4226
+ r.style.height = `${Math.max(o, n + i)}px`;
4227
+ }, a = (e) => i(e.clientY), o = () => {
4228
+ document.removeEventListener("mousemove", a), document.removeEventListener("mouseup", o), this._dragDisposers = null;
4229
+ }, s = (e) => {
4230
+ 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();
4231
+ }, c = (e) => {
4232
+ let t = e.touches[0];
4233
+ t && (e.preventDefault(), i(t.clientY));
4234
+ }, l = () => {
4235
+ document.removeEventListener("touchmove", c), document.removeEventListener("touchend", l), this._dragDisposers = null;
4236
+ }, u = (e) => {
4237
+ let i = e.touches[0];
4238
+ 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)]);
4239
+ }, d = S(e, "mousedown", s), f = S(e, "touchstart", u);
4240
+ this._disposers.push(d, f);
4241
+ }
4242
+ update() {
4243
+ if (!this._wordCountEl || !this._charCountEl) return;
4244
+ let e = this.context.layoutInfo.editable.textContent || "", t = Ar(e), n = e.replaceAll("\n", "").length, r = this.options.maxWords || 0, i = this.options.maxChars || 0, a = this.context.locale.statusbar;
4245
+ this._wordCountEl.textContent = r ? a.wordsLimit(t, r) : a.words(t), this._charCountEl.textContent = i ? a.charsLimit(n, i) : a.chars(n), jr(this._wordCountEl, t, r), jr(this._charCountEl, n, i);
4246
+ }
4247
+ getWordCount() {
4248
+ let e = this.context.layoutInfo.editable;
4249
+ return Ar(e.innerText || "");
4250
+ }
4251
+ getCharCount() {
4252
+ return (this.context.layoutInfo.editable.innerText || "").replaceAll("\n", "").length;
4253
+ }
4254
+ }
4255
+ },
4256
+ {
4257
+ name: "clipboard",
4258
+ Class: class {
4259
+ constructor(e) {
4260
+ this.context = e, this.options = e.options, this._disposers = [];
4261
+ }
4262
+ initialize() {
4263
+ this._blobRegistry = /* @__PURE__ */ new Map(), this._forcePlain = !1;
4264
+ let e = this.context.layoutInfo.editable;
4265
+ return this._disposers.push(S(e, "paste", (e) => this._onPaste(e)), S(e, "dragover", (e) => this._onDragover(e)), S(e, "drop", (e) => this._onDrop(e))), this._mutationObserver = new MutationObserver((e) => {
4266
+ for (let t of e) for (let e of t.removedNodes) this._revokeRemovedBlobs(e);
4267
+ }), this._mutationObserver.observe(e, {
4268
+ childList: !0,
4269
+ subtree: !0
4270
+ }), this;
4271
+ }
4272
+ destroy() {
4273
+ 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());
4274
+ }
4275
+ _revokeRemovedBlobs(e) {
4276
+ if (!this._blobRegistry?.size) return;
4277
+ let t = [];
4278
+ e.nodeName === "IMG" ? t.push(e) : e.querySelectorAll && t.push(...e.querySelectorAll("img")), t.forEach((e) => {
4279
+ let t = e.getAttribute("src") || "";
4280
+ t.startsWith("blob:") && this._blobRegistry.has(t) && (URL.revokeObjectURL(t), this._blobRegistry.delete(t));
4281
+ });
4282
+ }
4283
+ _cleanWordHtml(e) {
4284
+ 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) => {
4285
+ 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("; ");
4286
+ return n ? ` style="${n}"` : "";
4287
+ }).replace(/<p[^>]*>\s*(&nbsp;)?\s*<\/p>/gi, "");
4288
+ }
4289
+ _cleanSocialHtml(e) {
4290
+ let t = new DOMParser().parseFromString(`<body>${e}</body>`, "text/html"), n = Array.from(t.querySelectorAll("span, div"));
4291
+ for (let e = n.length - 1; e >= 0; e--) {
4292
+ let t = n[e];
4293
+ 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;
4294
+ let r = t.parentNode;
4295
+ for (; t.firstChild;) r.insertBefore(t.firstChild, t);
4296
+ t.remove();
4297
+ }
4298
+ return t.querySelectorAll("*").forEach((e) => {
4299
+ 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));
4300
+ }), t.body.innerHTML;
4301
+ }
4302
+ _stripAttributes(e) {
4303
+ let t = new DOMParser().parseFromString(`<body>${e}</body>`, "text/html"), n = /* @__PURE__ */ new Set([
4304
+ "href",
4305
+ "src",
4306
+ "alt",
4307
+ "target",
4308
+ "rel",
4309
+ "colspan",
4310
+ "rowspan",
4311
+ "type"
4312
+ ]);
4313
+ return t.querySelectorAll("*").forEach((e) => {
4314
+ Array.from(e.attributes).filter((e) => !n.has(e.name)).forEach((t) => e.removeAttribute(t.name));
4315
+ }), t.body.innerHTML;
4316
+ }
4317
+ _normalizeExternalTaskLists(e) {
4318
+ let t = new DOMParser().parseFromString(`<body>${e}</body>`, "text/html");
4319
+ for (let e of t.querySelectorAll("input[type=\"checkbox\"]")) {
4320
+ let t = e.closest("li"), n = t?.closest("ul");
4321
+ if (!(!t || !n || n.classList.contains("an-checklist"))) {
4322
+ n.classList.add("an-checklist"), e.removeAttribute("disabled"), e.setAttribute("contenteditable", "false");
4323
+ for (let t of Array.from(e.attributes)) [
4324
+ "type",
4325
+ "checked",
4326
+ "contenteditable"
4327
+ ].includes(t.name) || e.removeAttribute(t.name);
4328
+ }
4329
+ }
4330
+ return t.body.innerHTML;
4331
+ }
4332
+ _isTriviallyPlainHtml(e) {
4333
+ 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");
4334
+ }
4335
+ setForcePlain(e) {
4336
+ this._forcePlain = !!e;
4337
+ }
4338
+ _onPaste(e) {
4339
+ let t = e.clipboardData || globalThis.clipboardData;
4340
+ if (!t) return;
4341
+ let n = this._forcePlain;
4342
+ this._forcePlain = !1;
4343
+ let r = (this.options.maxPasteSize ?? 5) * 1024 * 1024;
4344
+ if (r > 0) {
4345
+ let n = t.getData("text/plain") || "", i = t.getData("text/html") || "", a = Math.max(n.length, i.length);
4346
+ if (a > r) {
4347
+ e.preventDefault();
4348
+ let t = `Pasted content (${a} bytes) exceeds the ${this.options.maxPasteSize ?? 5} MB paste size limit.`;
4349
+ this.context.triggerEvent("pasteError", {
4350
+ size: a,
4351
+ maxBytes: r,
4352
+ message: t
4353
+ }), console.warn(`[AutumnNote] ${t}`);
4354
+ return;
4355
+ }
4356
+ }
4357
+ if (t.items) {
4358
+ let n = Array.from(t.items).filter((e) => e.kind === "file" && e.type.startsWith("image/"));
4359
+ if (n.length > 0) {
4360
+ e.preventDefault();
4361
+ let t = n.map((e) => e.getAsFile()).filter(Boolean);
4362
+ this._insertImageFiles(t);
4363
+ return;
4364
+ }
4365
+ }
4366
+ if (typeof this.options.onPaste == "function" && this.options.onPaste({
4367
+ text: t.getData("text/plain") || "",
4368
+ html: t.types.includes("text/html") ? t.getData("text/html") : null
4369
+ }), n || this.options.pasteAsPlainText) {
4370
+ 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");
4371
+ return;
4372
+ }
4373
+ if (this.options.markdownPaste !== !1) {
4374
+ let n = t.types.includes("text/html"), r = n ? t.getData("text/html") : "", i = !n || this._isTriviallyPlainHtml(r), a = t.getData("text/plain");
4375
+ if (a && i && Rn(a)) {
4376
+ e.preventDefault(), w("insertHTML", j(H(a))), this.context.invoke("editor.afterCommand");
4377
+ return;
4378
+ }
4379
+ }
4380
+ if (this.options.pasteCleanHTML !== !1 && t.types.includes("text/html")) {
4381
+ e.preventDefault();
4382
+ 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;
4383
+ 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");
4384
+ }
4385
+ }
4386
+ _onDragover(e) {
4387
+ e.dataTransfer && Array.from(e.dataTransfer.types || []).includes("Files") && (e.preventDefault(), e.dataTransfer.dropEffect = "copy");
4388
+ }
4389
+ _onDrop(e) {
4390
+ let t = e.dataTransfer;
4391
+ if (!t?.files?.length) return;
4392
+ let n = Array.from(t.files).filter((e) => e.type.startsWith("image/"));
4393
+ if (n.length > 0) {
4394
+ e.preventDefault(), e.stopPropagation(), this._placeCaretAtPoint(e.clientX, e.clientY), this._insertImageFiles(n);
4395
+ return;
4396
+ }
4397
+ if (this.options.markdownPaste !== !1) {
4398
+ let n = Array.from(t.files).find((e) => /\.md$/i.test(e.name) || e.type === "text/markdown");
4399
+ n && (e.preventDefault(), e.stopPropagation(), this._placeCaretAtPoint(e.clientX, e.clientY), this._insertMarkdownFile(n));
4400
+ }
4401
+ }
4402
+ _insertMarkdownFile(e) {
4403
+ let t = (this.options.maxPasteSize ?? 5) * 1024 * 1024;
4404
+ if (t > 0 && e.size > t) {
4405
+ let n = `Dropped file "${e.name}" (${e.size} bytes) exceeds the ${this.options.maxPasteSize ?? 5} MB paste size limit.`;
4406
+ this.context.triggerEvent("pasteError", {
4407
+ size: e.size,
4408
+ maxBytes: t,
4409
+ message: n
4410
+ }), console.warn(`[AutumnNote] ${n}`);
4411
+ return;
4412
+ }
4413
+ let n = new FileReader();
4414
+ n.onload = (e) => {
4415
+ w("insertHTML", j(H(e.target.result || ""))), this.context.invoke("editor.afterCommand");
4416
+ }, n.onerror = () => {
4417
+ let t = `Failed to read dropped markdown file "${e.name}".`;
4418
+ console.warn(`[AutumnNote] ${t}`), this.context.triggerEvent("pasteError", { message: t });
4419
+ }, n.readAsText(e);
4420
+ }
4421
+ _insertImageFiles(e) {
4422
+ if (!e || e.length === 0) return;
4423
+ if (typeof this.options.onImageUpload == "function") {
4424
+ this._runUploadHandler(e);
4425
+ return;
4426
+ }
4427
+ let t = /* @__PURE__ */ new Set([
4428
+ "image/tiff",
4429
+ "image/x-tiff",
4430
+ "image/bmp",
4431
+ "image/x-bmp",
4432
+ "image/x-ms-bmp"
4433
+ ]), n = (this.options.maxImageSize || 5) * 1024 * 1024;
4434
+ e.forEach((e) => {
4435
+ if (!e?.type?.startsWith("image/")) return;
4436
+ if (t.has(e.type)) {
4437
+ let t = `Image format "${e.type}" is not supported for display in web browsers. Please convert to PNG, JPEG, or WebP first.`;
4438
+ this.context.triggerEvent("imageError", {
4439
+ file: e,
4440
+ message: t
4441
+ }), console.warn("[AutumnNote]", t);
4442
+ return;
4443
+ }
4444
+ if (e.size > n) {
4445
+ let t = `Image "${e.name}" exceeds the ${this.options.maxImageSize || 5} MB size limit.`;
4446
+ this.context.triggerEvent("imageError", {
4447
+ file: e,
4448
+ message: t
4449
+ }), console.warn(`[AutumnNote] ${t}`);
4450
+ return;
4451
+ }
4452
+ let r = e.name.replace(/\.[^.]+$/, "");
4453
+ this.compressAndRegister(e).then((e) => {
4454
+ this.context.invoke("editor.insertImage", e, r);
4455
+ }).catch((t) => {
4456
+ let n = `Image "${e.name}" could not be processed.`;
4457
+ this.context.triggerEvent("imageError", {
4458
+ file: e,
4459
+ message: n,
4460
+ error: t
4461
+ }), console.warn("[AutumnNote]", n, t);
4462
+ });
4463
+ });
4464
+ }
4465
+ _escapeAttr(e) {
4466
+ return String(e).replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
4467
+ }
4468
+ async _runUploadHandler(e) {
4469
+ let t = {
4470
+ context: this.context,
4471
+ setProgress: (e, t) => this._setUploadProgress(e, t)
4472
+ }, n;
4473
+ try {
4474
+ n = this.options.onImageUpload(e, t);
4475
+ } catch (t) {
4476
+ this._reportUploadError(e, t);
4477
+ return;
4478
+ }
4479
+ if (n === void 0) return;
4480
+ let r = e.map((e) => this._insertUploadPlaceholder(e)), i;
4481
+ try {
4482
+ i = await n;
4483
+ } catch (t) {
4484
+ r.forEach((n, r) => this._failUpload(n, e[r], t));
4485
+ return;
4486
+ }
4487
+ let a = Array.isArray(i) ? i : [i];
4488
+ r.forEach((t, n) => {
4489
+ let r = a[n];
4490
+ typeof r == "string" && r ? this._resolveUpload(t, r) : this._failUpload(t, e[n], /* @__PURE__ */ Error("No URL returned for this file."));
4491
+ });
4492
+ }
4493
+ _insertUploadPlaceholder(e) {
4494
+ let t = `an-up-${Date.now().toString(36)}-${this._uploadSeq = (this._uploadSeq || 0) + 1}`, n = URL.createObjectURL(e);
4495
+ this._uploadPreviews = this._uploadPreviews || /* @__PURE__ */ new Map(), this._uploadPreviews.set(t, {
4496
+ previewUrl: n,
4497
+ file: e
4498
+ });
4499
+ let r = this._escapeAttr(e.name.replace(/\.[^.]+$/, ""));
4500
+ 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;
4501
+ }
4502
+ _findPlaceholder(e) {
4503
+ return this.context.layoutInfo.editable?.querySelector(`img[data-an-upload="${e}"]`) ?? null;
4504
+ }
4505
+ _resolveUpload(e, t) {
4506
+ let n = this._findPlaceholder(e), r = this._uploadPreviews?.get(e);
4507
+ if (n) {
4508
+ let i = M(t, { allowData: !0 });
4509
+ if (i) n.setAttribute("src", i), n.classList.remove("an-image-uploading"), n.removeAttribute("data-an-upload"), n.style.removeProperty("--an-upload-progress");
4510
+ else {
4511
+ this._failUpload(e, r?.file, /* @__PURE__ */ Error(`Rejected image URL: ${t}`));
4512
+ return;
4513
+ }
4514
+ }
4515
+ r && (URL.revokeObjectURL(r.previewUrl), this._uploadPreviews.delete(e)), this.context.invoke("editor.afterCommand");
4516
+ }
4517
+ _failUpload(e, t, n) {
4518
+ let r = this._findPlaceholder(e);
4519
+ r && (r.classList.remove("an-image-uploading"), r.classList.add("an-image-failed"), r.style.removeProperty("--an-upload-progress"));
4520
+ let i = `Image "${t?.name ?? "unknown"}" could not be uploaded.`;
4521
+ console.warn("[AutumnNote]", i, n), this.context.triggerEvent("imageError", {
4522
+ file: t,
4523
+ message: i,
4524
+ error: n,
4525
+ retry: () => {
4526
+ r?.remove(), this._uploadPreviews?.delete(e), t && this._runUploadHandler([t]);
4527
+ }
4528
+ });
4529
+ }
4530
+ _reportUploadError(e, t) {
4531
+ let n = "The image upload handler threw before any file was sent.";
4532
+ console.warn("[AutumnNote]", n, t), this.context.triggerEvent("imageError", {
4533
+ file: e[0],
4534
+ message: n,
4535
+ error: t
4536
+ });
4537
+ }
4538
+ _setUploadProgress(e, t) {
4539
+ if (!this._uploadPreviews) return;
4540
+ let n = Math.max(0, Math.min(1, Number(t) || 0));
4541
+ for (let [t, r] of this._uploadPreviews) {
4542
+ if (r.file !== e) continue;
4543
+ let i = this._findPlaceholder(t);
4544
+ i && i.style.setProperty("--an-upload-progress", String(n));
4545
+ return;
4546
+ }
4547
+ }
4548
+ async compressAndRegister(e) {
4549
+ 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);
4550
+ return this._blobRegistry.set(i, n), i;
4551
+ }
4552
+ resolveImages(e) {
4553
+ return this._blobRegistry?.size ? e.replace(/blob:[^"'> \t\n\r]*/g, (e) => this._blobRegistry.get(e) || e) : e;
4554
+ }
4555
+ _dataUrlToBlob(e) {
4556
+ let [t, n] = e.split(","), r = /:(.*?);/.exec(t)?.[1] ?? "image/png", i = atob(n), a = new Uint8Array(i.length);
4557
+ for (let e = 0; e < i.length; e++) a[e] = i.charCodeAt(e);
4558
+ return new Blob([a], { type: r });
4559
+ }
4560
+ _compressImage(e) {
4561
+ let t = 1920, n = .85;
4562
+ return new Promise((r, i) => {
4563
+ let a = URL.createObjectURL(e), o = new Image();
4564
+ o.onload = () => {
4565
+ URL.revokeObjectURL(a);
4566
+ let { width: s, height: c } = o;
4567
+ (s > t || c > t) && (s >= c ? (c = Math.round(c * t / s), s = t) : (s = Math.round(s * t / c), c = t));
4568
+ let l = document.createElement("canvas");
4569
+ l.width = s, l.height = c;
4570
+ let u = l.getContext("2d");
4571
+ if (!u) {
4572
+ let t = new FileReader();
4573
+ t.onload = (e) => r(e.target.result), t.onerror = () => i(/* @__PURE__ */ Error("FileReader failed")), t.readAsDataURL(e);
4574
+ return;
4575
+ }
4576
+ u.drawImage(o, 0, 0, s, c);
4577
+ let d = l.toDataURL("image/webp", n);
4578
+ r(d.startsWith("data:image/webp") ? d : l.toDataURL("image/jpeg", n));
4579
+ }, o.onerror = () => {
4580
+ URL.revokeObjectURL(a);
4581
+ let t = new FileReader();
4582
+ t.onload = (e) => r(e.target.result), t.onerror = () => i(/* @__PURE__ */ Error("FileReader failed")), t.readAsDataURL(e);
4583
+ }, o.src = a;
4584
+ });
4585
+ }
4586
+ _placeCaretAtPoint(e, t) {
4587
+ let n;
4588
+ if (document.caretRangeFromPoint) n = document.caretRangeFromPoint(e, t);
4589
+ else if (document.caretPositionFromPoint) {
4590
+ let r = document.caretPositionFromPoint(e, t);
4591
+ r && (n = document.createRange(), n.setStart(r.offsetNode, r.offset), n.collapse(!0));
4592
+ }
4593
+ if (!n) return;
4594
+ let r = globalThis.getSelection();
4595
+ r && (r.removeAllRanges(), r.addRange(n));
4596
+ }
4597
+ _escapeHTML(e) {
4598
+ return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&#039;");
4599
+ }
4600
+ }
4601
+ },
4602
+ {
4603
+ name: "placeholder",
4604
+ Class: class {
4605
+ constructor(e) {
4606
+ this.context = e, this.options = e.options, this._disposers = [];
4607
+ }
4608
+ initialize() {
4609
+ let e = this.context.layoutInfo.editable, t = this.options.placeholder || "";
4610
+ t && (e.dataset.placeholder = t);
4611
+ let n = () => this._update(), r = S(e, "input", n), i = S(e, "focus", n), a = S(e, "blur", n);
4612
+ return this._disposers.push(r, i, a), this._update(), this;
4613
+ }
4614
+ destroy() {
4615
+ this._disposers.forEach((e) => e()), this._disposers = [];
4616
+ }
4617
+ _update() {
4618
+ let e = this.context.layoutInfo.editable, t = document.activeElement === e, n = !(e.textContent.replaceAll("​", "").trim().length > 0) && !e.querySelector("img, table, hr, .an-video-wrapper");
4619
+ e.classList.toggle("an-placeholder", n && !t);
4620
+ }
4621
+ }
4622
+ }
4623
+ ];
4624
+ //#endregion
4625
+ //#region src/js/core/lists.js
4626
+ function Nr(e) {
4627
+ return e[e.length - 1];
4628
+ }
4629
+ function Pr(e) {
4630
+ return e[0];
4631
+ }
4632
+ function Fr(e, t = 1) {
4633
+ return e.slice(0, e.length - t);
4634
+ }
4635
+ function Ir(e, t = 1) {
4636
+ return e.slice(t);
4637
+ }
4638
+ function Lr(e) {
4639
+ return e.flat();
4640
+ }
4641
+ function Rr(e) {
4642
+ return [...new Set(e)];
4643
+ }
4644
+ function zr(e, t) {
4645
+ let n = [];
4646
+ for (let r = 0; r < e.length; r += t) n.push(e.slice(r, r + t));
4647
+ return n;
4648
+ }
4649
+ function Br(e, t) {
4650
+ return e.reduce((e, n) => {
4651
+ let r = t(n);
4652
+ return e[r] || (e[r] = []), e[r].push(n), e;
4653
+ }, {});
4654
+ }
4655
+ function Vr(e, t) {
4656
+ return e.every(t);
4657
+ }
4658
+ function Hr(e, t) {
4659
+ return e.some(t);
4660
+ }
4661
+ //#endregion
4662
+ //#region src/js/core/env.js
4663
+ function Q() {
4664
+ return globalThis.navigator?.userAgent ?? "";
4665
+ }
4666
+ var Ur = {
4667
+ get isChrome() {
4668
+ return /Chrome\//.test(Q()) && !/Edg\//.test(Q());
4669
+ },
4670
+ get isFF() {
4671
+ return /Firefox\//.test(Q());
4672
+ },
4673
+ get isSafari() {
4674
+ return /^((?!chrome|android).)*safari/i.test(Q());
4675
+ },
4676
+ get isEdge() {
4677
+ return /Edg\//.test(Q());
4678
+ },
4679
+ get isMac() {
4680
+ return /Macintosh/.test(Q());
4681
+ },
4682
+ get isMobile() {
4683
+ return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(Q());
4684
+ },
4685
+ get isTouch() {
4686
+ return "ontouchstart" in globalThis || (globalThis.navigator?.maxTouchPoints ?? 0) > 0;
4687
+ },
4688
+ get modifierKey() {
4689
+ return /Macintosh/.test(Q()) ? "metaKey" : "ctrlKey";
4690
+ }
4691
+ }, Wr = { ...k }, $ = /* @__PURE__ */ new WeakMap(), Gr = {
4692
+ create(e, t = {}) {
4693
+ let n = Kr(e).map((e) => {
4694
+ if ($.has(e)) return $.get(e);
4695
+ let n = new Sn(e, t);
4696
+ return n.initialize(), $.set(e, n), n;
4697
+ });
4698
+ return n.length === 1 ? n[0] : n;
4699
+ },
4700
+ destroy(e) {
4701
+ Kr(e).forEach((e) => {
4702
+ let t = $.get(e);
4703
+ t && (t.destroy(), $.delete(e));
4704
+ });
4705
+ },
4706
+ getInstance(e) {
4707
+ let t = typeof e == "string" ? document.querySelector(e) : e;
4708
+ return t && $.get(t) || null;
4709
+ },
4710
+ get defaults() {
4711
+ return { ...k };
4712
+ },
4713
+ setDefaults(e) {
4714
+ Object.assign(k, e);
4715
+ },
4716
+ resetDefaults() {
4717
+ Object.keys(k).forEach((e) => delete k[e]), Object.assign(k, Wr);
4718
+ },
4719
+ registerModule(e, t) {
4720
+ yn.set(e, t);
4721
+ },
4722
+ use(e, t = {}) {
4723
+ if (!e || typeof e.name != "string") throw TypeError("[AutumnNote] AutumnNote.use: plugin must have a string `name` property.");
4724
+ 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, {
4725
+ plugin: e,
4726
+ options: t
4727
+ }), this);
4728
+ },
4729
+ hasPlugin(e) {
4730
+ return N.has(e);
4731
+ },
4732
+ registerButton(e) {
4733
+ return O(e), this;
4734
+ },
4735
+ registerLocale(e, t) {
4736
+ return $t(e, t), this;
4737
+ },
4738
+ registerSlashCommand(e) {
4739
+ if (!e?.id || typeof e.run != "function") throw TypeError("[AutumnNote] Slash command requires an id and run(context) function.");
4740
+ let t = k.slashCommands, n = t.findIndex((t) => t.id === e.id);
4741
+ return n >= 0 ? t[n] = e : t.push(e), this;
4742
+ },
4743
+ buttons: Zt,
4744
+ version: "2.5.0"
4745
+ };
4746
+ function Kr(e) {
4747
+ return typeof e == "string" ? Array.from(document.querySelectorAll(e)) : e instanceof Element ? [e] : e instanceof NodeList || Array.isArray(e) ? Array.from(e) : [];
4748
+ }
4749
+ //#endregion
4750
+ //#region src/js/core.js
4751
+ xn(Mr);
4752
+ //#endregion
4753
+ export { Sn as Context, d as ELEMENT_NODE, yr as SUPPORTED_LANGS, f as TEXT_NODE, C as WrappedRange, D as _buttonRegistry, vt as alignCenterBtn, bt as alignJustifyBtn, _t as alignLeftBtn, yt as alignRightBtn, Vr as all, oe as ancestors, Hr as any, Yt as backColorBtn, dt as boldBtn, Zt as buttons, Kt as checklistBtn, se as children, zr as chunk, e as clamp, y as closest, ae as closestPara, Bt as codeviewBtn, Ce as collapsedRange, r as compose, b as createElement, xe as currentRange, t as debounce, Gr as default, k as defaultOptions, Xt as defaultToolbar, Cr as detectLang, It as directionBtn, jt as emojiBtn, Ur as env, Ut as findBtn, Wt as findReplaceBtn, Pr as first, Lr as flatten, Lt as fontFamilyBtn, Pt as fontSizeBtn, Jt as foreColorBtn, be as fromNativeRange, Vt as fullscreenBtn, ut as getButton, Br as groupBy, Dt as hrBtn, kn as htmlToMarkdown, Mt as iconBtn, i as identity, kt as imageBtn, Ct as indentBtn, Fr as initial, Gt as inlineCodeBtn, fe as insertAfter, re as isAnchor, v as isEditable, p as isElement, me as isEmpty, s as isFunction, ie as isImage, _ as isInline, _e as isInsideEditable, F as isKey, ee as isLi, te as isList, Rn 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, Nr as last, zt as lineHeightBtn, Ot as linkBtn, Qt as locales, ye as makeDraggable, H as markdownToHTML, c as mergeDeep, le as nextElement, pe as nodeValue, St as olBtn, S as on, wt as outdentBtn, he as outerHtml, Rt as paragraphStyleBtn, ge as placeCaret, ce as prevElement, qt as printBtn, Se as rangeFromElement, u as rect2bnd, Et as redoBtn, O as registerButton, $t as registerLocale, x as remove, Ft as removeFormatBtn, en as resolveLocale, j as sanitiseHTML, M as sanitiseUrl, Ht as shortcutsBtn, Ee as splitText, mt as strikeBtn, gt as subscriptBtn, ht as superscriptBtn, Nt as tableBtn, Ir as tail, n as throttle, ve as trapFocus, xt as ulBtn, pt as underlineBtn, Tt as undoBtn, Rr as unique, ue as unwrap, At as videoBtn, Te as withSavedRange, de as wrap };
4754
+
4755
+ //# sourceMappingURL=autumnnote.core.es.js.map