autumnnote 2.5.0 → 2.7.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.
@@ -63,68 +63,78 @@ function y(e, t, n) {
63
63
  }
64
64
  return null;
65
65
  }
66
- function ae(e, t) {
66
+ function b(e, t) {
67
67
  return y(e, g, t);
68
68
  }
69
- function oe(e, t) {
69
+ function ae(e, t) {
70
70
  let n = [], r = e.parentNode;
71
71
  for (; r && r !== t;) n.push(r), r = r.parentNode;
72
72
  return n;
73
73
  }
74
- function se(e) {
74
+ function oe(e) {
75
75
  return Array.from(e.childNodes);
76
76
  }
77
- function ce(e) {
77
+ function se(e) {
78
78
  let t = e.previousSibling;
79
79
  for (; t && !p(t);) t = t.previousSibling;
80
80
  return t;
81
81
  }
82
- function le(e) {
82
+ function ce(e) {
83
83
  let t = e.nextSibling;
84
84
  for (; t && !p(t);) t = t.nextSibling;
85
85
  return t;
86
86
  }
87
- function b(e, t = {}, n = []) {
87
+ function x(e, t = {}, n = []) {
88
88
  let r = document.createElement(e);
89
89
  for (let [e, n] of Object.entries(t)) r.setAttribute(e, n);
90
90
  for (let e of n) typeof e == "string" ? r.appendChild(document.createTextNode(e)) : r.appendChild(e);
91
91
  return r;
92
92
  }
93
- function x(e) {
93
+ function S(e) {
94
94
  e?.parentNode && e.remove();
95
95
  }
96
- function ue(e) {
96
+ function le(e) {
97
97
  let t = e.parentNode;
98
98
  if (t) {
99
99
  for (; e.firstChild;) t.insertBefore(e.firstChild, e);
100
100
  e.remove();
101
101
  }
102
102
  }
103
- function de(e, t) {
103
+ function ue(e, t) {
104
104
  return e.parentNode.insertBefore(t, e), t.appendChild(e), t;
105
105
  }
106
- function fe(e, t) {
106
+ function de(e, t) {
107
107
  t.nextSibling ? t.parentNode.insertBefore(e, t.nextSibling) : t.parentNode.appendChild(e);
108
108
  }
109
- function pe(e) {
109
+ function fe(e) {
110
110
  return m(e) ? e.nodeValue : e.textContent || "";
111
111
  }
112
- function me(e) {
112
+ function pe(e) {
113
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
114
  }
115
- function he(e) {
115
+ function me(e) {
116
116
  return e.outerHTML;
117
117
  }
118
- function ge(e) {
118
+ function he(e) {
119
119
  let t = document.createRange();
120
120
  t.selectNodeContents(e), t.collapse(!1);
121
121
  let n = globalThis.getSelection();
122
122
  n && (n.removeAllRanges(), n.addRange(t));
123
123
  }
124
+ function ge(e) {
125
+ if (e?.querySelectorAll) for (let t of e.querySelectorAll("ul > ul, ul > ol, ol > ul, ol > ol")) {
126
+ let e = t.previousElementSibling;
127
+ if (e && e.nodeName === "LI") e.appendChild(t);
128
+ else if (t.parentNode) {
129
+ let e = t.ownerDocument.createElement("li");
130
+ t.parentNode.insertBefore(e, t), e.appendChild(t);
131
+ }
132
+ }
133
+ }
124
134
  function _e(e) {
125
135
  return !!y(e, v);
126
136
  }
127
- function S(e, t, n, r) {
137
+ function C(e, t, n, r) {
128
138
  return e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r);
129
139
  }
130
140
  function ve(e, t) {
@@ -163,7 +173,7 @@ function ye(e, t) {
163
173
  }
164
174
  //#endregion
165
175
  //#region src/js/core/range.js
166
- var C = class {
176
+ var w = class {
167
177
  constructor(e, t, n, r) {
168
178
  this.sc = e, this.so = t, this.ec = n, this.eo = r;
169
179
  }
@@ -200,7 +210,7 @@ var C = class {
200
210
  }
201
211
  };
202
212
  function be(e) {
203
- return new C(e.startContainer, e.startOffset, e.endContainer, e.endOffset);
213
+ return new w(e.startContainer, e.startOffset, e.endContainer, e.endOffset);
204
214
  }
205
215
  function xe(e) {
206
216
  let t = globalThis.getSelection();
@@ -209,10 +219,10 @@ function xe(e) {
209
219
  return e && !e.contains(n.commonAncestorContainer) ? null : be(n);
210
220
  }
211
221
  function Se(e) {
212
- return new C(e, 0, e, e.childNodes.length);
222
+ return new w(e, 0, e, e.childNodes.length);
213
223
  }
214
224
  function Ce(e, t = 0) {
215
- return new C(e, t, e, t);
225
+ return new w(e, t, e, t);
216
226
  }
217
227
  function we(e) {
218
228
  let t = globalThis.getSelection();
@@ -267,13 +277,16 @@ function je(e, t) {
267
277
  if (!n) return !1;
268
278
  n.deleteContents();
269
279
  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) => {
280
+ !r.includes("\n") || Ne(n.startContainer, t) ? i.appendChild(document.createTextNode(r)) : r.split("\n").forEach((e, t) => {
271
281
  t > 0 && i.appendChild(document.createElement("br")), e && i.appendChild(document.createTextNode(e));
272
282
  });
273
283
  let a = i.lastChild;
274
284
  return n.insertNode(i), a && ke(a), !0;
275
285
  }
276
- function Me(e, t) {
286
+ function Me(e) {
287
+ return je("\n", e);
288
+ }
289
+ function Ne(e, t) {
277
290
  let n = e.nodeType === 1 ? e : e.parentElement;
278
291
  for (; n && n !== t;) {
279
292
  if (n.tagName === "PRE" || n.tagName === "TEXTAREA") return !0;
@@ -283,12 +296,12 @@ function Me(e, t) {
283
296
  }
284
297
  return !1;
285
298
  }
286
- function Ne(e) {
299
+ function Pe(e) {
287
300
  let t = Oe(e);
288
301
  if (!t) return !1;
289
302
  let n = document.createElement("hr");
290
303
  t.deleteContents();
291
- let r = Fe(t.startContainer, e);
304
+ let r = Ie(t.startContainer, e);
292
305
  r && r.parentNode ? r.parentNode.insertBefore(n, r.nextSibling) : t.insertNode(n);
293
306
  let i = n.nextElementSibling;
294
307
  if (!i || i.tagName === "HR") {
@@ -302,7 +315,7 @@ function Ne(e) {
302
315
  }
303
316
  return !0;
304
317
  }
305
- var Pe = /* @__PURE__ */ new Set([
318
+ var Fe = /* @__PURE__ */ new Set([
306
319
  "P",
307
320
  "DIV",
308
321
  "H1",
@@ -315,21 +328,21 @@ var Pe = /* @__PURE__ */ new Set([
315
328
  "PRE",
316
329
  "LI"
317
330
  ]);
318
- function Fe(e, t) {
331
+ function Ie(e, t) {
319
332
  let n = e.nodeType === 1 ? e : e.parentElement;
320
333
  for (; n && n !== t;) {
321
- if (Pe.has(n.tagName)) return n;
334
+ if (Fe.has(n.tagName)) return n;
322
335
  n = n.parentElement;
323
336
  }
324
337
  return null;
325
338
  }
326
339
  //#endregion
327
340
  //#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);
341
+ function T(e, t = null) {
342
+ return e === "insertHTML" && Ae(String(t ?? "")) || e === "insertText" && je(String(t ?? "")) || e === "insertLineBreak" && Me() || e === "insertHorizontalRule" && Pe() ? !0 : document.execCommand(e, !1, t);
330
343
  }
331
- var Ie = () => w("bold"), Le = () => w("italic");
332
- function Re() {
344
+ var Le = () => T("bold"), Re = () => T("italic");
345
+ function ze() {
333
346
  let e = globalThis.getSelection();
334
347
  if (!e?.rangeCount) return;
335
348
  let t = e.getRangeAt(0).commonAncestorContainer;
@@ -341,9 +354,9 @@ function Re() {
341
354
  n.remove();
342
355
  return;
343
356
  }
344
- w("underline");
357
+ T("underline");
345
358
  }
346
- function ze() {
359
+ function Be() {
347
360
  let e = globalThis.getSelection();
348
361
  if (!e?.rangeCount) return;
349
362
  let t = e.getRangeAt(0).startContainer;
@@ -355,10 +368,10 @@ function ze() {
355
368
  n.remove();
356
369
  return;
357
370
  }
358
- w("strikeThrough");
371
+ T("strikeThrough");
359
372
  }
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) {
373
+ var Ve = () => T("superscript"), He = () => T("subscript"), Ue = (e) => T("foreColor", e), We = (e) => T("hiliteColor", e), Ge = (e) => T("fontName", e);
374
+ function Ke(e, t = document) {
362
375
  let n = globalThis.getSelection(), r = !n?.rangeCount || n.getRangeAt(0).collapsed;
363
376
  if (r && n?.rangeCount > 0) {
364
377
  try {
@@ -371,7 +384,7 @@ function Ge(e, t = document) {
371
384
  } catch {}
372
385
  return;
373
386
  }
374
- w("fontSize", "7");
387
+ T("fontSize", "7");
375
388
  let i = t instanceof HTMLElement ? t : document, a = [];
376
389
  if (i.querySelectorAll("font[size=\"7\"]").forEach((t) => {
377
390
  let n = document.createElement("span");
@@ -385,21 +398,52 @@ function Ge(e, t = document) {
385
398
  } catch {}
386
399
  }
387
400
  }
388
- var Ke = (e) => w("formatBlock", `<${e}>`), qe = () => w("justifyLeft"), Je = () => w("justifyCenter"), Ye = () => w("justifyRight"), Xe = () => w("justifyFull"), Ze = () => w("indent");
401
+ var qe = (e) => T("formatBlock", `<${e}>`), Je = () => T("justifyLeft"), Ye = () => T("justifyCenter"), Xe = () => T("justifyRight"), Ze = () => T("justifyFull");
389
402
  function Qe() {
403
+ T("indent"), ge($e());
404
+ }
405
+ function $e() {
406
+ let e = globalThis.getSelection();
407
+ if (!e?.rangeCount) return null;
408
+ let t = e.getRangeAt(0).commonAncestorContainer;
409
+ t.nodeType === 3 && (t = t.parentElement);
410
+ let n = null;
411
+ for (let e = t; e; e = e.parentElement) (e.nodeName === "UL" || e.nodeName === "OL") && (n = e);
412
+ return n;
413
+ }
414
+ function et() {
390
415
  let e = globalThis.getSelection();
391
416
  if (e?.rangeCount) {
392
417
  let t = e.getRangeAt(0).commonAncestorContainer;
393
418
  t.nodeType === 3 && (t = t.parentElement);
394
419
  let n = t?.closest(".an-checklist li");
395
420
  if (n) {
396
- $e(n);
421
+ nt(n);
397
422
  return;
398
423
  }
399
424
  }
400
- w("outdent");
425
+ tt() || T("outdent");
401
426
  }
402
- function $e(e) {
427
+ function tt() {
428
+ let e = globalThis.getSelection();
429
+ if (!e?.rangeCount) return !1;
430
+ let t = e.getRangeAt(0).startContainer;
431
+ t.nodeType === 3 && (t = t.parentElement);
432
+ let n = t?.closest?.("li");
433
+ if (!n) return !1;
434
+ let r = n.parentElement;
435
+ if (!r || r.nodeName !== "UL" && r.nodeName !== "OL") return !1;
436
+ let i = r.parentElement;
437
+ if (!i || i.nodeName !== "LI" || !i.parentNode) return !1;
438
+ let a = [];
439
+ for (let e = n.nextElementSibling; e; e = e.nextElementSibling) a.push(e);
440
+ if (a.length) {
441
+ let e = n.ownerDocument.createElement(r.nodeName.toLowerCase());
442
+ a.forEach((t) => e.appendChild(t)), n.appendChild(e);
443
+ }
444
+ return i.parentNode.insertBefore(n, i.nextSibling), r.children.length || r.remove(), !0;
445
+ }
446
+ function nt(e) {
403
447
  let t = e.closest(".an-checklist");
404
448
  if (!t) return;
405
449
  let n = Array.from(t.children), r = n.indexOf(e), i = n.slice(r + 1), a = document.createElement("p");
@@ -416,24 +460,24 @@ function $e(e) {
416
460
  n && (n.removeAllRanges(), n.addRange(e));
417
461
  } catch {}
418
462
  }
419
- function et() {
463
+ function rt() {
420
464
  let e = globalThis.getSelection();
421
465
  if (!e?.rangeCount) return null;
422
466
  let t = e.getRangeAt(0).commonAncestorContainer;
423
467
  return t.nodeType === 3 && (t = t.parentElement), t?.closest("ul, ol") || null;
424
468
  }
425
- function tt(e) {
469
+ function it(e) {
426
470
  e.classList.remove("an-checklist"), e.querySelectorAll("input[type=\"checkbox\"]").forEach((e) => e.remove());
427
471
  }
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");
472
+ function at() {
473
+ let e = rt();
474
+ e ? e.classList.contains("an-checklist") ? (it(e), e.tagName === "OL" && E(e, "ul")) : e.tagName === "OL" ? E(e, "ul") : T("insertUnorderedList") : T("insertUnorderedList");
431
475
  }
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");
476
+ function ot() {
477
+ let e = rt();
478
+ e ? e.classList.contains("an-checklist") ? (it(e), E(e, "ol")) : e.tagName === "UL" ? E(e, "ol") : T("insertOrderedList") : T("insertOrderedList");
435
479
  }
436
- function it(e) {
480
+ function st(e) {
437
481
  let t = globalThis.getSelection();
438
482
  if (!t || t.rangeCount === 0) return;
439
483
  let n = t.getRangeAt(0), r = /* @__PURE__ */ new Set([
@@ -476,7 +520,7 @@ function it(e) {
476
520
  t.style.lineHeight = e;
477
521
  });
478
522
  }
479
- function at(e) {
523
+ function ct(e) {
480
524
  let t = globalThis.getSelection();
481
525
  if (!t?.rangeCount) return;
482
526
  let n = t.getRangeAt(0), r = n.commonAncestorContainer;
@@ -508,7 +552,7 @@ function at(e) {
508
552
  }
509
553
  }
510
554
  }
511
- function ot() {
555
+ function lt() {
512
556
  let e = globalThis.getSelection();
513
557
  if (!e?.rangeCount) return !1;
514
558
  let t = e.getRangeAt(0).startContainer;
@@ -516,13 +560,13 @@ function ot() {
516
560
  let n = t?.closest("code");
517
561
  return !!(n && !n.closest("pre"));
518
562
  }
519
- function T(e, t) {
563
+ function E(e, t) {
520
564
  let n = document.createElement(t);
521
565
  for (let t of e.attributes) n.setAttribute(t.name, t.value);
522
566
  for (; e.firstChild;) n.appendChild(e.firstChild);
523
567
  return e.parentNode.replaceChild(n, e), n;
524
568
  }
525
- function st(e) {
569
+ function ut(e) {
526
570
  e.querySelectorAll("li").forEach((e) => {
527
571
  if (!e.querySelector("input[type=\"checkbox\"]")) {
528
572
  let t = document.createElement("input");
@@ -530,7 +574,7 @@ function st(e) {
530
574
  }
531
575
  });
532
576
  }
533
- function ct() {
577
+ function dt() {
534
578
  let e = globalThis.getSelection();
535
579
  if (!e?.rangeCount) return;
536
580
  let t = e.getRangeAt(0), n = t.commonAncestorContainer;
@@ -549,8 +593,8 @@ function ct() {
549
593
  }
550
594
  }
551
595
  } else {
552
- let t = T(r, "ul");
553
- t.classList.add("an-checklist"), st(t);
596
+ let t = E(r, "ul");
597
+ t.classList.add("an-checklist"), ut(t);
554
598
  let n = t.querySelector("li");
555
599
  if (n) {
556
600
  let t = document.createRange();
@@ -623,7 +667,7 @@ function ct() {
623
667
  }
624
668
  }
625
669
  }
626
- function lt() {
670
+ function ft() {
627
671
  let e = globalThis.getSelection();
628
672
  if (!e?.rangeCount) return !1;
629
673
  let t = e.getRangeAt(0).commonAncestorContainer;
@@ -631,7 +675,7 @@ function lt() {
631
675
  }
632
676
  //#endregion
633
677
  //#region src/js/module/Buttons.js
634
- function E(e, t, n, r, i, a) {
678
+ function D(e, t, n, r, i, a) {
635
679
  return {
636
680
  name: e,
637
681
  icon: t,
@@ -641,24 +685,24 @@ function E(e, t, n, r, i, a) {
641
685
  isDisabled: a
642
686
  };
643
687
  }
644
- var D = /* @__PURE__ */ new Map();
645
- function O(e) {
688
+ var O = /* @__PURE__ */ new Map();
689
+ function k(e) {
646
690
  if (!e || typeof e.name != "string") {
647
691
  console.warn("[AutumnNote] registerButton: btnDef must have a string `name` property.");
648
692
  return;
649
693
  }
650
- D.has(e.name) && console.warn(`[AutumnNote] registerButton: overwriting existing button "${e.name}".`), D.set(e.name, e);
694
+ O.has(e.name) && console.warn(`[AutumnNote] registerButton: overwriting existing button "${e.name}".`), O.set(e.name, e);
651
695
  }
652
- function ut(e) {
653
- return D.get(e);
696
+ function pt(e) {
697
+ return O.get(e);
654
698
  }
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(), () => {
699
+ var mt = D("bold", "bold", "Bold (Ctrl+B)", () => Le(), () => document.queryCommandState("bold")), ht = D("italic", "italic", "Italic (Ctrl+I)", () => Re(), () => document.queryCommandState("italic")), gt = D("underline", "underline", "Underline (Ctrl+U)", () => ze(), () => {
656
700
  if (document.queryCommandState("underline")) return !0;
657
701
  let e = globalThis.getSelection();
658
702
  if (!e?.rangeCount) return !1;
659
703
  let t = e.getRangeAt(0).startContainer;
660
704
  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 = {
705
+ }), _t = D("strikethrough", "strikethrough", "Strikethrough", () => Be(), () => document.queryCommandState("strikeThrough")), vt = D("superscript", "superscript", "Superscript", () => Ve(), () => document.queryCommandState("superscript")), yt = D("subscript", "subscript", "Subscript", () => He(), () => document.queryCommandState("subscript")), bt = D("alignLeft", "align-left", "Align Left", () => Je()), xt = D("alignCenter", "align-center", "Align Center", () => Ye()), St = D("alignRight", "align-right", "Align Right", () => Xe()), Ct = D("alignJustify", "align-justify", "Justify", () => Ze()), wt = D("ul", "list-ul", "Unordered List", () => at()), Tt = D("ol", "list-ol", "Ordered List", () => ot()), Et = D("indent", "indent", "Indent", () => Qe()), Dt = D("outdent", "outdent", "Outdent", () => et()), Ot = D("undo", "undo", "Undo (Ctrl+Z)", (e) => e.invoke("editor.undo"), void 0, (e) => !e.invoke("editor.canUndo")), kt = D("redo", "redo", "Redo (Ctrl+Y)", (e) => e.invoke("editor.redo"), void 0, (e) => !e.invoke("editor.canRedo")), At = D("hr", "minus", "Horizontal Rule", () => T("insertHorizontalRule")), jt = D("link", "link", "Insert Link", (e) => e.invoke("linkDialog.show")), Mt = D("image", "image", "Insert Image", (e) => e.invoke("imageDialog.show")), Nt = D("video", "video", "Insert Video", (e) => e.invoke("videoDialog.show")), Pt = D("emoji", "emoji", "Insert Emoji", (e) => e.invoke("emojiDialog.show")), Ft = D("icon", "icon", "Insert FA Icon", (e) => e.invoke("iconDialog.show")), It = {
662
706
  name: "table",
663
707
  type: "grid",
664
708
  icon: "table",
@@ -666,7 +710,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
666
710
  action: (e, t, n) => {
667
711
  e.invoke("editor.insertTable", n, t), e.invoke("editor.afterCommand");
668
712
  }
669
- }, Pt = {
713
+ }, Lt = {
670
714
  name: "fontSize",
671
715
  type: "select",
672
716
  tooltip: "Font Size",
@@ -689,7 +733,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
689
733
  "48px",
690
734
  "72px"
691
735
  ],
692
- action: (e, t) => Ge(t, e.layoutInfo.editable),
736
+ action: (e, t) => Ke(t, e.layoutInfo.editable),
693
737
  getValue: (e) => {
694
738
  try {
695
739
  let t = globalThis.getSelection();
@@ -705,14 +749,14 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
705
749
  return "";
706
750
  }
707
751
  }
708
- }, Ft = E("removeFormat", "remove-format", "Remove Format", () => w("removeFormat")), It = E("direction", "direction", "Toggle Text Direction (LTR / RTL)", (e) => {
752
+ }, Rt = D("removeFormat", "remove-format", "Remove Format", () => T("removeFormat")), zt = D("direction", "direction", "Toggle Text Direction (LTR / RTL)", (e) => {
709
753
  let t = e.layoutInfo.editable, n = (t.getAttribute("dir") || "ltr") === "ltr" ? "rtl" : "ltr";
710
754
  t.setAttribute("dir", n), t.style.textAlign = n === "rtl" ? "right" : "left", e.invoke("editor.afterCommand");
711
- }), Lt = {
755
+ }), Bt = {
712
756
  name: "fontFamily",
713
757
  type: "select",
714
758
  tooltip: "Font Family",
715
- action: (e, t) => We(t),
759
+ action: (e, t) => Ge(t),
716
760
  getValue: () => {
717
761
  try {
718
762
  return document.queryCommandValue("fontName") || "";
@@ -720,7 +764,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
720
764
  return "";
721
765
  }
722
766
  }
723
- }, Rt = {
767
+ }, Vt = {
724
768
  name: "paragraphStyle",
725
769
  type: "select",
726
770
  tooltip: "Paragraph Style",
@@ -764,7 +808,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
764
808
  label: "Code"
765
809
  }
766
810
  ],
767
- action: (e, t) => Ke(t),
811
+ action: (e, t) => qe(t),
768
812
  getValue: () => {
769
813
  try {
770
814
  let e = document.queryCommandValue("formatBlock").toLowerCase().replace(/[<>]/g, "");
@@ -773,7 +817,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
773
817
  return "";
774
818
  }
775
819
  }
776
- }, zt = {
820
+ }, Ht = {
777
821
  name: "lineHeight",
778
822
  type: "select",
779
823
  tooltip: "Line Height",
@@ -788,7 +832,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
788
832
  "2.5",
789
833
  "3.0"
790
834
  ],
791
- action: (e, t) => it(t),
835
+ action: (e, t) => st(t),
792
836
  getValue: () => {
793
837
  try {
794
838
  let e = globalThis.getSelection();
@@ -814,116 +858,116 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
814
858
  return "";
815
859
  }
816
860
  }
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 = {
861
+ }, Ut = D("codeview", "code", "HTML Code View", (e) => e.invoke("codeview.toggle"), (e) => e.invoke("codeview.isActive")), Wt = D("fullscreen", "expand", "Fullscreen", (e) => e.invoke("fullscreen.toggle"), (e) => e.invoke("fullscreen.isActive")), Gt = D("shortcuts", "keyboard", "Keyboard Shortcuts (Ctrl+Shift+/)", (e) => e.invoke("shortcutsDialog.show")), Kt = D("find", "search", "Find (Ctrl+F)", (e) => e.invoke("findReplace.show", "find")), qt = D("findReplace", "find-replace", "Find & Replace (Ctrl+H)", (e) => e.invoke("findReplace.show", "replace")), Jt = D("inlineCode", "inline-code", "Inline Code (Ctrl+`)", (e) => e.invoke("editor.inlineCode"), () => lt()), Yt = D("checklist", "checklist", "Checklist", (e) => e.invoke("editor.toggleChecklist"), () => ft()), Xt = D("print", "print", "Print", (e) => e.invoke("editor.print")), Zt = {
818
862
  name: "foreColor",
819
863
  type: "colorpicker",
820
864
  icon: "foreColor",
821
865
  tooltip: "Text Color",
822
866
  defaultColor: "#e11d48",
823
- action: (e, t) => He(t)
824
- }, Yt = {
867
+ action: (e, t) => Ue(t)
868
+ }, Qt = {
825
869
  name: "backColor",
826
870
  type: "colorpicker",
827
871
  icon: "backColor",
828
872
  tooltip: "Highlight Color",
829
873
  defaultColor: "#fbbf24",
830
- action: (e, t) => Ue(t)
831
- }, Xt = [
874
+ action: (e, t) => We(t)
875
+ }, $t = [
832
876
  [
833
- Rt,
877
+ Vt,
878
+ Bt,
834
879
  Lt,
835
- Pt,
836
- zt
880
+ Ht
837
881
  ],
838
- [Tt, Et],
882
+ [Ot, kt],
839
883
  [
840
- dt,
841
- ft,
842
- pt,
843
884
  mt,
844
- Gt
845
- ],
846
- [ht, gt],
847
- [Jt, Yt],
848
- [
885
+ ht,
886
+ gt,
849
887
  _t,
850
- vt,
851
- yt,
852
- bt
888
+ Jt
853
889
  ],
890
+ [vt, yt],
891
+ [Zt, Qt],
854
892
  [
893
+ bt,
855
894
  xt,
856
895
  St,
857
- Kt,
858
- Ct,
859
- wt
896
+ Ct
897
+ ],
898
+ [
899
+ wt,
900
+ Tt,
901
+ Yt,
902
+ Et,
903
+ Dt
860
904
  ],
861
905
  [
862
- Dt,
863
- Ot,
864
- kt,
865
906
  At,
866
- Nt,
867
907
  jt,
868
- Mt
908
+ Mt,
909
+ Nt,
910
+ It,
911
+ Pt,
912
+ Ft
869
913
  ],
870
914
  [
871
- Ft,
872
- Bt,
873
- Vt,
915
+ Rt,
874
916
  Ut,
875
- qt,
876
- Ht
917
+ Wt,
918
+ Kt,
919
+ Xt,
920
+ Gt
877
921
  ]
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 = {
922
+ ], en = {
923
+ boldBtn: mt,
924
+ italicBtn: ht,
925
+ underlineBtn: gt,
926
+ strikeBtn: _t,
927
+ superscriptBtn: vt,
928
+ subscriptBtn: yt,
929
+ alignLeftBtn: bt,
930
+ alignCenterBtn: xt,
931
+ alignRightBtn: St,
932
+ alignJustifyBtn: Ct,
933
+ ulBtn: wt,
934
+ olBtn: Tt,
935
+ indentBtn: Et,
936
+ outdentBtn: Dt,
937
+ undoBtn: Ot,
938
+ redoBtn: kt,
939
+ hrBtn: At,
940
+ linkBtn: jt,
941
+ imageBtn: Mt,
942
+ videoBtn: Nt,
943
+ emojiBtn: Pt,
944
+ iconBtn: Ft,
945
+ tableBtn: It,
946
+ fontSizeBtn: Lt,
947
+ removeFormatBtn: Rt,
948
+ directionBtn: zt,
949
+ fontFamilyBtn: Bt,
950
+ paragraphStyleBtn: Vt,
951
+ lineHeightBtn: Ht,
952
+ codeviewBtn: Ut,
953
+ fullscreenBtn: Wt,
954
+ shortcutsBtn: Gt,
955
+ findBtn: Kt,
956
+ findReplaceBtn: qt,
957
+ inlineCodeBtn: Jt,
958
+ checklistBtn: Yt,
959
+ printBtn: Xt,
960
+ foreColorBtn: Zt,
961
+ backColorBtn: Qt,
962
+ defaultToolbar: $t
963
+ }, A = {
920
964
  placeholder: "",
921
965
  height: 200,
922
966
  minHeight: 100,
923
967
  maxHeight: 0,
924
968
  focus: !1,
925
969
  resizable: !0,
926
- toolbar: Xt,
970
+ toolbar: $t,
927
971
  useBootstrap: !1,
928
972
  toolbarButtonClass: "btn btn-sm btn-light",
929
973
  useFontAwesome: !0,
@@ -947,6 +991,9 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
947
991
  theme: "light",
948
992
  codeHighlight: !0,
949
993
  codeHighlightCDN: "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0",
994
+ cspNonce: "",
995
+ externalAssetCrossOrigin: "anonymous",
996
+ externalAssetReferrerPolicy: "no-referrer",
950
997
  markdownPaste: !0,
951
998
  historyLimit: 100,
952
999
  historyMaxBytes: 10 * 1024 * 1024,
@@ -1007,7 +1054,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
1007
1054
  "removeFormat"
1008
1055
  ],
1009
1056
  mention: null
1010
- }, A = {
1057
+ }, j = {
1011
1058
  toolbar: {
1012
1059
  bold: "Bold (Ctrl+B)",
1013
1060
  italic: "Italic (Ctrl+I)",
@@ -1374,23 +1421,23 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
1374
1421
  table: "Table",
1375
1422
  image: "Image"
1376
1423
  }
1377
- }, Qt = { en: A };
1378
- function $t(e, t) {
1424
+ }, tn = { en: j };
1425
+ function nn(e, t) {
1379
1426
  if (typeof e != "string" || !e) throw TypeError("[AutumnNote] registerLocale: code must be a non-empty string.");
1380
1427
  if (!t || typeof t != "object") throw TypeError(`[AutumnNote] registerLocale: locale for "${e}" must be an object.`);
1381
- Qt[e] = t;
1428
+ tn[e] = t;
1382
1429
  }
1383
- function en(e) {
1384
- if (!e || e === "en") return A;
1430
+ function rn(e) {
1431
+ if (!e || e === "en") return j;
1385
1432
  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);
1433
+ let t = tn[e];
1434
+ return t ? c(c({}, j), 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});`), j);
1388
1435
  }
1389
- return typeof e == "object" ? c(c({}, A), e) : A;
1436
+ return typeof e == "object" ? c(c({}, j), e) : j;
1390
1437
  }
1391
1438
  //#endregion
1392
1439
  //#region src/js/core/sanitise.js
1393
- var tn = [
1440
+ var an = [
1394
1441
  "script",
1395
1442
  "style",
1396
1443
  "iframe",
@@ -1413,7 +1460,7 @@ var tn = [
1413
1460
  "mglyph",
1414
1461
  "malignmark",
1415
1462
  "annotation-xml"
1416
- ], nn = /* @__PURE__ */ new Set(["button"]), rn = [
1463
+ ], on = /* @__PURE__ */ new Set(["button"]), sn = [
1417
1464
  "href",
1418
1465
  "src",
1419
1466
  "action",
@@ -1422,11 +1469,11 @@ var tn = [
1422
1469
  "poster",
1423
1470
  "background",
1424
1471
  "srcset"
1425
- ], an = /* @__PURE__ */ new Set([
1472
+ ], cn = /* @__PURE__ */ new Set([
1426
1473
  "poster",
1427
1474
  "background",
1428
1475
  "srcset"
1429
- ]), on = /* @__PURE__ */ new Set(["ping"]), sn = /* @__PURE__ */ new Set([
1476
+ ]), ln = /* @__PURE__ */ new Set(["ping"]), un = /* @__PURE__ */ new Set([
1430
1477
  "color",
1431
1478
  "background-color",
1432
1479
  "font-size",
@@ -1442,28 +1489,31 @@ var tn = [
1442
1489
  "border-color",
1443
1490
  "padding",
1444
1491
  "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([
1492
+ ]), dn = /url\s*\(|image-set\s*\(|src\s*\(|expression\s*\(|@import|javascript:|vbscript:|behavior\s*:|-moz-binding/i, fn = /* @__PURE__ */ new Set([
1446
1493
  "www.youtube.com",
1447
1494
  "youtube.com",
1448
1495
  "m.youtube.com",
1449
1496
  "www.youtube-nocookie.com",
1450
1497
  "youtube-nocookie.com",
1451
1498
  "player.vimeo.com"
1452
- ]), un = /* @__PURE__ */ new Set([
1499
+ ]), pn = /* @__PURE__ */ new Set([
1453
1500
  "http:",
1454
1501
  "https:",
1455
1502
  "mailto:",
1456
1503
  "tel:"
1457
- ]), dn = /* @__PURE__ */ new Set([
1504
+ ]), mn = /* @__PURE__ */ new Set([
1458
1505
  "http:",
1459
1506
  "https:",
1460
1507
  "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);
1508
+ ]), hn = /^data:image\/(?:png|jpe?g|gif|webp|avif|bmp);base64,[a-z0-9+/=\s]+$/i, gn = "https://autumnnote.invalid/";
1509
+ function M(e, t) {
1510
+ return _n(e, t).innerHTML;
1511
+ }
1512
+ function _n(e, { allowIframes: t = !1 } = {}) {
1513
+ let n = new DOMParser().parseFromString(`<body>${e || ""}</body>`, "text/html"), r = Array.from(n.querySelectorAll("*")), i = new Set(t ? an.filter((e) => e !== "iframe") : an);
1464
1514
  for (let e of r) {
1465
1515
  let t = e.tagName.toLowerCase();
1466
- if (nn.has(t)) {
1516
+ if (on.has(t)) {
1467
1517
  e.replaceWith(...e.childNodes);
1468
1518
  continue;
1469
1519
  }
@@ -1473,7 +1523,7 @@ function j(e, { allowIframes: t = !1 } = {}) {
1473
1523
  }
1474
1524
  if (t === "iframe") {
1475
1525
  let t = e.getAttribute("src");
1476
- if (!t || !gn(t)) {
1526
+ if (!t || !bn(t)) {
1477
1527
  e.remove();
1478
1528
  continue;
1479
1529
  }
@@ -1484,22 +1534,22 @@ function j(e, { allowIframes: t = !1 } = {}) {
1484
1534
  continue;
1485
1535
  }
1486
1536
  if (t.name === "style") {
1487
- let n = mn(t.value);
1537
+ let n = vn(t.value);
1488
1538
  n ? e.setAttribute("style", n) : e.removeAttribute("style");
1489
1539
  continue;
1490
1540
  }
1491
- if (on.has(t.name)) {
1541
+ if (ln.has(t.name)) {
1492
1542
  e.removeAttribute(t.name);
1493
1543
  continue;
1494
1544
  }
1495
- if (rn.includes(t.name)) {
1496
- let n = t.value.trim(), r = an.has(t.name) || t.name === "src" && [
1545
+ if (sn.includes(t.name)) {
1546
+ let n = t.value.trim(), r = cn.has(t.name) || t.name === "src" && [
1497
1547
  "IMG",
1498
1548
  "VIDEO",
1499
1549
  "AUDIO",
1500
1550
  "SOURCE"
1501
1551
  ].includes(e.tagName), i = e.tagName === "IMG";
1502
- if (!(t.name === "srcset" ? hn(n, { allowData: i }) : _n(n, {
1552
+ if (!(t.name === "srcset" ? yn(n, { allowData: i }) : xn(n, {
1503
1553
  media: r,
1504
1554
  allowData: i
1505
1555
  }))) {
@@ -1512,7 +1562,7 @@ function j(e, { allowIframes: t = !1 } = {}) {
1512
1562
  e.removeAttribute(t.name);
1513
1563
  continue;
1514
1564
  }
1515
- t.name === "src" && !gn(t.value) && e.removeAttribute(t.name);
1565
+ t.name === "src" && !bn(t.value) && e.removeAttribute(t.name);
1516
1566
  }
1517
1567
  }
1518
1568
  if (t === "a" && e.getAttribute("target") === "_blank" && e.setAttribute("rel", "noopener noreferrer"), t === "input") if (!(e.closest("ul.an-checklist") !== null && e.closest("li") !== null) || e.getAttribute("type") !== "checkbox") e.remove();
@@ -1522,61 +1572,61 @@ function j(e, { allowIframes: t = !1 } = {}) {
1522
1572
  "contenteditable"
1523
1573
  ].includes(t.name) || e.removeAttribute(t.name);
1524
1574
  }
1525
- return n.body.innerHTML;
1575
+ return n.body;
1526
1576
  }
1527
- function mn(e) {
1577
+ function vn(e) {
1528
1578
  let t = [];
1529
1579
  for (let n of (e || "").split(";")) {
1530
1580
  let e = n.indexOf(":");
1531
1581
  if (e === -1) continue;
1532
1582
  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}`));
1583
+ !r || !i || un.has(r) && (dn.test(i) || t.push(`${r}: ${i}`));
1534
1584
  }
1535
1585
  return t.join("; ");
1536
1586
  }
1537
- function hn(e, { allowData: t = !1 } = {}) {
1587
+ function yn(e, { allowData: t = !1 } = {}) {
1538
1588
  let n = (e || "").trim().split(/\s+/).filter(Boolean);
1539
1589
  for (let e of n) {
1540
1590
  if (/^[\d.]+[xw],?$/i.test(e)) continue;
1541
1591
  let n = e.replace(/,+$/, "");
1542
- if (n && !_n(n, {
1592
+ if (n && !xn(n, {
1543
1593
  media: !0,
1544
1594
  allowData: t
1545
1595
  })) return !1;
1546
1596
  }
1547
1597
  return !0;
1548
1598
  }
1549
- function gn(e) {
1599
+ function bn(e) {
1550
1600
  let t = (e || "").trim();
1551
1601
  if (!t || t.startsWith("//") || t.startsWith("/")) return !1;
1552
1602
  try {
1553
1603
  let e = new URL(t);
1554
- return e.protocol === "https:" && ln.has(e.hostname.toLowerCase());
1604
+ return e.protocol === "https:" && fn.has(e.hostname.toLowerCase());
1555
1605
  } catch {
1556
1606
  return !1;
1557
1607
  }
1558
1608
  }
1559
- function M(e, { allowData: t = !1, media: n = t } = {}) {
1609
+ function N(e, { allowData: t = !1, media: n = t } = {}) {
1560
1610
  let r = (e || "").trim();
1561
- return !r && e == null ? null : _n(r, {
1611
+ return !r && e == null ? null : xn(r, {
1562
1612
  media: n,
1563
1613
  allowData: t
1564
1614
  }) ? e : null;
1565
1615
  }
1566
- function _n(e, { media: t = !1, allowData: n = !1 } = {}) {
1616
+ function xn(e, { media: t = !1, allowData: n = !1 } = {}) {
1567
1617
  let r = (e || "").trim();
1568
- if (!r || n && fn.test(r)) return !0;
1618
+ if (!r || n && hn.test(r)) return !0;
1569
1619
  try {
1570
- let e = new URL(r, pn);
1571
- return (t ? dn : un).has(e.protocol);
1620
+ let e = new URL(r, gn);
1621
+ return (t ? mn : pn).has(e.protocol);
1572
1622
  } catch {
1573
1623
  return !1;
1574
1624
  }
1575
1625
  }
1576
1626
  //#endregion
1577
1627
  //#region src/js/renderer.js
1578
- function vn(e, t) {
1579
- let n = b("div", { class: "an-container" }), r = b("div", {
1628
+ function Sn(e, t) {
1629
+ let n = x("div", { class: "an-container" }), r = x("div", {
1580
1630
  class: "an-editable",
1581
1631
  contenteditable: t.readOnly ? "false" : "true",
1582
1632
  spellcheck: String(t.spellcheck !== !1),
@@ -1587,7 +1637,7 @@ function vn(e, t) {
1587
1637
  if (t.autoSave && t.autoSaveKey) try {
1588
1638
  i = localStorage.getItem(t.autoSaveKey) || "";
1589
1639
  } catch {}
1590
- i ||= e.tagName === "TEXTAREA" ? (e.value || "").trim() : (e.innerHTML || "").trim(), r.innerHTML = j(i, { allowIframes: !0 });
1640
+ i ||= e.tagName === "TEXTAREA" ? (e.value || "").trim() : (e.innerHTML || "").trim(), r.innerHTML = M(i, { allowIframes: !0 });
1591
1641
  let a = t.defaultFontFamily || t.fontFamilies?.[0];
1592
1642
  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
1643
  e.setAttribute("disabled", "");
@@ -1598,16 +1648,16 @@ function vn(e, t) {
1598
1648
  }
1599
1649
  //#endregion
1600
1650
  //#region src/js/Context.js
1601
- var yn = /* @__PURE__ */ new Map(), bn = [];
1602
- function xn(e) {
1603
- bn = Array.isArray(e) ? e : [];
1651
+ var Cn = /* @__PURE__ */ new Map(), wn = [];
1652
+ function Tn(e) {
1653
+ wn = Array.isArray(e) ? e : [];
1604
1654
  }
1605
- var N = /* @__PURE__ */ new Map(), Sn = class {
1655
+ var P = /* @__PURE__ */ new Map(), En = class {
1606
1656
  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;
1657
+ this.targetEl = e, this.options = c(A, t), this.locale = rn(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, this._releaseInstance = null;
1608
1658
  }
1609
1659
  initialize() {
1610
- let { container: e, editable: t } = vn(this.targetEl, this.options);
1660
+ let { container: e, editable: t } = Sn(this.targetEl, this.options);
1611
1661
  this.layoutInfo.container = e, this.layoutInfo.editable = t, this._registerModules();
1612
1662
  let n = this._modules.get("toolbar");
1613
1663
  n?.el && (e.insertBefore(n.el, t), this.layoutInfo.toolbar = n.el);
@@ -1619,11 +1669,11 @@ var N = /* @__PURE__ */ new Map(), Sn = class {
1619
1669
  let n = new t(this);
1620
1670
  this._modules.set(e, n), n.initialize();
1621
1671
  };
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);
1672
+ for (let { name: t, Class: n, enabled: r } of wn) typeof r == "function" && !r(this.options) || e(t, n);
1673
+ if (Cn.size > 0) for (let [t, n] of Cn) e(t, n);
1624
1674
  }
1625
1675
  _syncOptionalModules() {
1626
- for (let { name: e, Class: t, enabled: n } of bn) {
1676
+ for (let { name: e, Class: t, enabled: n } of wn) {
1627
1677
  if (typeof n != "function") continue;
1628
1678
  let r = n(this.options);
1629
1679
  if (r !== this._modules.has(e)) if (r) {
@@ -1646,7 +1696,7 @@ var N = /* @__PURE__ */ new Map(), Sn = class {
1646
1696
  return n >= 0 ? t[n] = e : t.push(e), this.invoke("slashMenu.refresh"), this;
1647
1697
  }
1648
1698
  use(e, t = {}) {
1649
- return Array.isArray(e.buttons) && e.buttons.forEach((e) => O(e)), this._installPlugin(e, t), this;
1699
+ return Array.isArray(e.buttons) && e.buttons.forEach((e) => k(e)), this._installPlugin(e, t), this;
1650
1700
  }
1651
1701
  getPlugin(e) {
1652
1702
  return this._plugins.get(e)?.publicApi ?? null;
@@ -1668,12 +1718,12 @@ var N = /* @__PURE__ */ new Map(), Sn = class {
1668
1718
  });
1669
1719
  }
1670
1720
  _applyGlobalPlugins() {
1671
- if (N.size !== 0) for (let { plugin: e, options: t } of N.values()) this._installPlugin(e, t);
1721
+ if (P.size !== 0) for (let { plugin: e, options: t } of P.values()) this._installPlugin(e, t);
1672
1722
  }
1673
1723
  _bindEditorEvents(e) {
1674
- let t = S(e, "input", () => this._syncToTarget()), n = S(e, "focus", () => {
1724
+ let t = C(e, "input", () => this._syncToTarget()), n = C(e, "focus", () => {
1675
1725
  this.layoutInfo.container.classList.add("an-focused"), typeof this.options.onFocus == "function" && this.options.onFocus(this);
1676
- }), r = S(e, "blur", () => {
1726
+ }), r = C(e, "blur", () => {
1677
1727
  this.layoutInfo.container.classList.remove("an-focused"), this._syncToTarget(), typeof this.options.onBlur == "function" && this.options.onBlur(this);
1678
1728
  }), i = this.on("change", (e) => this._syncToTarget(e)), a = this.on("change", (e) => {
1679
1729
  if (this.options.blockIds && (this.ensureBlockIds(), e = this.getHTML()), e === this._suppressedRemoteHTML) {
@@ -1914,14 +1964,22 @@ var N = /* @__PURE__ */ new Map(), Sn = class {
1914
1964
  } catch {}
1915
1965
  this._plugins.clear(), this._disposers.forEach((e) => e()), this._disposers = [];
1916
1966
  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(() => {
1967
+ 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._releaseInstance?.(), this._releaseInstance = null, this._destroyPromise = Promise.resolve(e).then(() => {
1918
1968
  this._listeners.clear();
1919
1969
  }), this._destroyPromise;
1920
1970
  }
1921
1971
  _syncToTarget(e) {
1922
1972
  (this.targetEl.tagName === "TEXTAREA" || this.targetEl.tagName === "INPUT") && (this.targetEl.value = typeof e == "string" ? e : this.getHTML());
1923
1973
  }
1924
- }, Cn = class {
1974
+ };
1975
+ //#endregion
1976
+ //#region src/js/editing/History.js
1977
+ function Dn(e, t) {
1978
+ let n = Math.min(e.length, t.length), r = 0;
1979
+ for (; r < n && e.charCodeAt(r) === t.charCodeAt(r);) r++;
1980
+ return r;
1981
+ }
1982
+ var On = class {
1925
1983
  constructor(e, t = 100, n = 10 * 1024 * 1024) {
1926
1984
  this.editable = e, this._limit = t, this._maxBytes = n, this._bytes = 0, this.stack = [], this.stackOffset = -1, this._savePoint();
1927
1985
  }
@@ -1943,12 +2001,12 @@ var N = /* @__PURE__ */ new Map(), Sn = class {
1943
2001
  } : null;
1944
2002
  }
1945
2003
  _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;
2004
+ try {
2005
+ let n = document.createRange();
2006
+ return n.selectNodeContents(this.editable), n.setEnd(e, t), n.toString().length;
2007
+ } catch {
2008
+ return 0;
1950
2009
  }
1951
- return 0;
1952
2010
  }
1953
2011
  _restoreSelection(e) {
1954
2012
  if (!e) return;
@@ -1995,7 +2053,18 @@ var N = /* @__PURE__ */ new Map(), Sn = class {
1995
2053
  this.stackOffset = this.stack.length - 1;
1996
2054
  }
1997
2055
  _restore(e) {
1998
- e && (this.editable.innerHTML = this._detokenizeImages(e), this._restoreSelection(e.sel));
2056
+ if (!e) return;
2057
+ let t = this.editable.textContent || "";
2058
+ this.editable.innerHTML = this._detokenizeImages(e);
2059
+ let n = e.sel;
2060
+ if (!n) {
2061
+ let e = Dn(t, this.editable.textContent || "");
2062
+ n = {
2063
+ start: e,
2064
+ end: e
2065
+ };
2066
+ }
2067
+ this._restoreSelection(n);
1999
2068
  }
2000
2069
  _tokenizeImages(e) {
2001
2070
  if (!e.includes("data:")) return {
@@ -2042,31 +2111,31 @@ var N = /* @__PURE__ */ new Map(), Sn = class {
2042
2111
  };
2043
2112
  //#endregion
2044
2113
  //#region src/js/editing/Table.js
2045
- function wn(e, t, n = {}) {
2046
- let { headerRow: r = !1 } = n, i = b("table", { class: "an-table" });
2114
+ function kn(e, t, n = {}) {
2115
+ let { headerRow: r = !1 } = n, i = x("table", { class: "an-table" });
2047
2116
  if (r && t > 0) {
2048
- let t = b("thead"), n = b("tr");
2117
+ let t = x("thead"), n = x("tr");
2049
2118
  for (let t = 0; t < e; t++) {
2050
- let e = b("th", {}, [document.createElement("br")]);
2119
+ let e = x("th", {}, [document.createElement("br")]);
2051
2120
  n.appendChild(e);
2052
2121
  }
2053
2122
  t.appendChild(n), i.appendChild(t);
2054
2123
  }
2055
- let a = r ? Math.max(t - 1, 1) : t, o = b("tbody");
2124
+ let a = r ? Math.max(t - 1, 1) : t, o = x("tbody");
2056
2125
  i.appendChild(o);
2057
2126
  for (let t = 0; t < a; t++) {
2058
- let t = b("tr");
2127
+ let t = x("tr");
2059
2128
  for (let n = 0; n < e; n++) {
2060
- let e = b("td", {}, [document.createElement("br")]);
2129
+ let e = x("td", {}, [document.createElement("br")]);
2061
2130
  t.appendChild(e);
2062
2131
  }
2063
2132
  o.appendChild(t);
2064
2133
  }
2065
2134
  return i;
2066
2135
  }
2067
- function Tn(e, t, n = {}) {
2136
+ function An(e, t, n = {}) {
2068
2137
  if (e <= 0 || t <= 0) return;
2069
- let r = wn(e, t, n), i = globalThis.getSelection();
2138
+ let r = kn(e, t, n), i = globalThis.getSelection();
2070
2139
  if (!i || i.rangeCount === 0) return;
2071
2140
  let a = i.getRangeAt(0);
2072
2141
  try {
@@ -2107,7 +2176,7 @@ function Tn(e, t, n = {}) {
2107
2176
  }
2108
2177
  //#endregion
2109
2178
  //#region src/js/core/key.js
2110
- var P = {
2179
+ var F = {
2111
2180
  BACKSPACE: "Backspace",
2112
2181
  TAB: "Tab",
2113
2182
  ENTER: "Enter",
@@ -2146,16 +2215,36 @@ var P = {
2146
2215
  SLASH: "/",
2147
2216
  PERIOD: "."
2148
2217
  };
2149
- function F(e, t) {
2218
+ function I(e, t) {
2150
2219
  return e.key === t || e.key === t.toUpperCase();
2151
2220
  }
2152
- function I(e, t) {
2153
- return (e.ctrlKey || e.metaKey) && F(e, t);
2221
+ function L(e, t) {
2222
+ return (e.ctrlKey || e.metaKey) && I(e, t);
2154
2223
  }
2155
2224
  //#endregion
2156
2225
  //#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) {
2226
+ var jn = /\bfa-/, R = (e) => !!(e?.nodeName === "I" && jn.test(e.className || "")), z = (e) => e?.nodeType === Node.TEXT_NODE && (e.textContent === "​" || e.textContent === "");
2227
+ function Mn(e, t, n) {
2228
+ let r = (e?.nodeType === Node.ELEMENT_NODE ? e : e?.parentElement ?? null)?.closest("td, th") ?? null;
2229
+ if (!r || !t.contains(r)) return !1;
2230
+ let i = r.closest("table");
2231
+ if (!i || !t.contains(i)) return !1;
2232
+ let a = Array.from(i.querySelectorAll("td, th")), o = a[a.indexOf(r) + (n ? -1 : 1)];
2233
+ if (o) return he(o), !0;
2234
+ if (n) return !0;
2235
+ let s = Nn(r.closest("tr"))?.firstElementChild ?? null;
2236
+ return s && he(s), !0;
2237
+ }
2238
+ function Nn(e) {
2239
+ if (!e?.parentNode) return null;
2240
+ let t = document.createElement("tr");
2241
+ for (let n of e.cells) {
2242
+ let e = document.createElement("td");
2243
+ e.appendChild(document.createElement("br")), n.hasAttribute("style") && e.setAttribute("style", n.getAttribute("style")), t.appendChild(e);
2244
+ }
2245
+ return e.parentNode.insertBefore(t, e.nextSibling), t;
2246
+ }
2247
+ function Pn(e, t) {
2159
2248
  try {
2160
2249
  let n = document.createRange();
2161
2250
  return n.setStart(e.startContainer, e.startOffset), n.setEnd(t, t.childNodes.length), n.extractContents();
@@ -2163,21 +2252,21 @@ function Dn(e, t) {
2163
2252
  return document.createDocumentFragment();
2164
2253
  }
2165
2254
  }
2166
- function On(e, t, n = {}) {
2255
+ function Fn(e, t, n = {}) {
2167
2256
  let r = (e) => {
2168
2257
  let t = globalThis.getSelection();
2169
2258
  if (!t) return !1;
2170
2259
  let n = document.createRange();
2171
2260
  return e(n), n.collapse(!0), t.removeAllRanges(), t.addRange(n), !0;
2172
2261
  };
2173
- if (F(e, P.BACKSPACE)) {
2262
+ if (I(e, F.BACKSPACE)) {
2174
2263
  let t = globalThis.getSelection();
2175
2264
  if (t?.rangeCount > 0) {
2176
2265
  let n = t.getRangeAt(0);
2177
2266
  if (n.collapsed && n.startContainer.nodeType === Node.TEXT_NODE) {
2178
2267
  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)) {
2268
+ if (n.startOffset === 0 && R(r.previousSibling)) return e.preventDefault(), r.previousSibling.remove(), !0;
2269
+ if (n.startOffset === 1 && r.textContent === "​" && R(r.previousSibling)) {
2181
2270
  e.preventDefault();
2182
2271
  let n = r.parentNode, i = r.previousSibling, a = i.previousSibling;
2183
2272
  i.remove(), r.remove();
@@ -2188,17 +2277,17 @@ function On(e, t, n = {}) {
2188
2277
  }
2189
2278
  return !1;
2190
2279
  }
2191
- if (F(e, P.LEFT) || F(e, P.RIGHT)) {
2280
+ if (I(e, F.LEFT) || I(e, F.RIGHT)) {
2192
2281
  let t = globalThis.getSelection();
2193
2282
  if (!t || t.rangeCount === 0) return !1;
2194
2283
  let n = t.getRangeAt(0);
2195
2284
  if (!n.collapsed) return !1;
2196
- let i = n.startContainer, a = F(e, P.LEFT);
2285
+ let i = n.startContainer, a = I(e, F.LEFT);
2197
2286
  if (i.nodeType === Node.TEXT_NODE) {
2198
2287
  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)) {
2288
+ if (a && n.startOffset === 1 && t.textContent === "​" && R(t.previousSibling) || a && n.startOffset === 0 && R(t.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(t.previousSibling));
2289
+ if (a && n.startOffset === 0 && z(t.previousSibling) && R(t.previousSibling.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(t.previousSibling.previousSibling));
2290
+ if (!a && n.startOffset === t.textContent.length && R(t.nextSibling)) {
2202
2291
  let n = t.nextSibling, i = n.nextSibling;
2203
2292
  if (e.preventDefault(), i?.nodeType === Node.TEXT_NODE) {
2204
2293
  let e = +!!(i.textContent || "").startsWith("​");
@@ -2206,7 +2295,7 @@ function On(e, t, n = {}) {
2206
2295
  }
2207
2296
  return r((e) => e.setStartAfter(n));
2208
2297
  }
2209
- if (!a && n.startOffset === t.textContent.length && R(t.nextSibling) && L(t.nextSibling.nextSibling)) {
2298
+ if (!a && n.startOffset === t.textContent.length && z(t.nextSibling) && R(t.nextSibling.nextSibling)) {
2210
2299
  let n = t.nextSibling.nextSibling, i = n.nextSibling;
2211
2300
  if (e.preventDefault(), i?.nodeType === Node.TEXT_NODE) {
2212
2301
  let e = +!!(i.textContent || "").startsWith("​");
@@ -2219,12 +2308,12 @@ function On(e, t, n = {}) {
2219
2308
  let t = i;
2220
2309
  if (a && n.startOffset > 0) {
2221
2310
  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));
2311
+ if (R(i)) return e.preventDefault(), r((e) => e.setStartBefore(i));
2312
+ if (z(i) && R(i.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(i.previousSibling));
2224
2313
  }
2225
2314
  if (!a && n.startOffset < t.childNodes.length) {
2226
2315
  let i = t.childNodes[n.startOffset];
2227
- if (L(i)) {
2316
+ if (R(i)) {
2228
2317
  let t = i.nextSibling;
2229
2318
  if (e.preventDefault(), t?.nodeType === Node.TEXT_NODE) {
2230
2319
  let e = +!!(t.textContent || "").startsWith("​");
@@ -2232,7 +2321,7 @@ function On(e, t, n = {}) {
2232
2321
  }
2233
2322
  return r((e) => e.setStartAfter(i));
2234
2323
  }
2235
- if (R(i) && L(i.nextSibling)) {
2324
+ if (z(i) && R(i.nextSibling)) {
2236
2325
  let t = i.nextSibling, n = t.nextSibling;
2237
2326
  if (e.preventDefault(), n?.nodeType === Node.TEXT_NODE) {
2238
2327
  let e = +!!(n.textContent || "").startsWith("​");
@@ -2243,16 +2332,17 @@ function On(e, t, n = {}) {
2243
2332
  }
2244
2333
  }
2245
2334
  }
2246
- if (F(e, P.TAB)) {
2335
+ if (I(e, F.TAB)) {
2247
2336
  let r = xe(t);
2248
2337
  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) {
2338
+ if (Mn(r.sc, t, e.shiftKey)) return e.preventDefault(), !0;
2339
+ let i = b(r.sc, t);
2340
+ if (i && ee(i)) return e.preventDefault(), e.shiftKey ? et() : Qe(), !0;
2341
+ if (i?.nodeName.toUpperCase() === "PRE") return e.shiftKey ? !1 : (e.preventDefault(), T("insertText", " ".repeat(n.tabSize || 4)), !0);
2342
+ if (n.tabSize) return e.shiftKey ? !1 : (e.preventDefault(), T("insertText", " ".repeat(n.tabSize)), !0);
2343
+ }
2344
+ if (I(e, F.ENTER) && e.shiftKey) return e.preventDefault(), T("insertLineBreak"), !0;
2345
+ if (I(e, F.ENTER) && !e.shiftKey) {
2256
2346
  let n = xe(t);
2257
2347
  if (!n) return !1;
2258
2348
  let r = n.sc, i = r.nodeType === 3 ? r.parentElement : r;
@@ -2286,31 +2376,115 @@ function On(e, t, n = {}) {
2286
2376
  if (r.deleteContents(), n.rangeCount === 0 || !o.isConnected) return !0;
2287
2377
  r = n.getRangeAt(0);
2288
2378
  }
2289
- let i = Dn(r, o), a = document.createElement("li"), s = document.createElement("input");
2379
+ let i = Pn(r, o), a = document.createElement("li"), s = document.createElement("input");
2290
2380
  s.type = "checkbox", s.setAttribute("contenteditable", "false"), a.appendChild(s), i.textContent.replace(/[\u00a0\u200B]/g, "").length > 0 && a.appendChild(i);
2291
2381
  let c = a.childNodes[1];
2292
2382
  c?.nodeType !== Node.TEXT_NODE && (c = document.createTextNode("​"), a.appendChild(c)), o.after(a);
2293
2383
  let l = document.createRange();
2294
2384
  return l.setStart(c, 0), l.collapse(!0), n.removeAllRanges(), n.addRange(l), !0;
2295
2385
  }
2296
- let s = ae(n.sc, t);
2297
- if (s?.nodeName.toUpperCase() === "PRE") return e.preventDefault(), w("insertText", "\n"), !0;
2386
+ let s = b(n.sc, t);
2387
+ if (s?.nodeName.toUpperCase() === "PRE") return e.preventDefault(), T("insertText", "\n"), !0;
2298
2388
  if (s?.nodeName.toUpperCase() === "BLOCKQUOTE") {
2299
2389
  let t = n.toNativeRange();
2300
- if (t.setEnd(s, s.childNodes.length), t.toString() === "" && n.isCollapsed()) return e.preventDefault(), w("formatBlock", "<p>"), !0;
2390
+ if (t.setEnd(s, s.childNodes.length), t.toString() === "" && n.isCollapsed()) return e.preventDefault(), T("formatBlock", "<p>"), !0;
2301
2391
  }
2302
2392
  }
2303
2393
  return !1;
2304
2394
  }
2305
2395
  //#endregion
2396
+ //#region src/js/core/count.js
2397
+ var B = typeof Intl < "u" && typeof Intl.Segmenter == "function" ? new Intl.Segmenter(void 0, { granularity: "word" }) : null;
2398
+ function In(e) {
2399
+ let t = e.trim();
2400
+ if (!t) return 0;
2401
+ if (B) {
2402
+ let e = 0;
2403
+ for (let n of B.segment(t)) n.isWordLike && e++;
2404
+ return e;
2405
+ }
2406
+ return t.split(/\s+/).length;
2407
+ }
2408
+ var Ln = /* @__PURE__ */ new Set(/* @__PURE__ */ "ADDRESS.ARTICLE.ASIDE.BLOCKQUOTE.BR.DD.DIV.DL.DT.FIELDSET.FIGCAPTION.FIGURE.FOOTER.FORM.H1.H2.H3.H4.H5.H6.HEADER.HR.LI.MAIN.NAV.OL.P.PRE.SECTION.TABLE.TBODY.TD.TFOOT.TH.THEAD.TR.UL".split("."));
2409
+ function Rn(e, t, n) {
2410
+ for (let r = e.firstChild; r; r = r.nextSibling) if (r.nodeType === 3) {
2411
+ let e = r.data;
2412
+ t.push(e), n.push(e);
2413
+ } else if (r.nodeType === 1) {
2414
+ let e = Ln.has(r.tagName);
2415
+ e && t.push("\n"), Rn(r, t, n), e && t.push("\n");
2416
+ }
2417
+ }
2418
+ function zn(e) {
2419
+ if (e.nodeType === 3) {
2420
+ let t = e.data;
2421
+ return {
2422
+ lines: t,
2423
+ flat: t
2424
+ };
2425
+ }
2426
+ let t = [], n = [];
2427
+ return Rn(e, t, n), {
2428
+ lines: t.join(""),
2429
+ flat: n.join("")
2430
+ };
2431
+ }
2432
+ var Bn = class {
2433
+ constructor() {
2434
+ this._cache = /* @__PURE__ */ new WeakMap();
2435
+ }
2436
+ counts(e) {
2437
+ let t = 0, n = 0, r = [], i = [], a = 0;
2438
+ for (let o = e.firstChild; o; o = o.nextSibling) {
2439
+ let e = this._cache.get(o);
2440
+ if (e && e.key === (o.textContent || "")) {
2441
+ t += e.words, n += e.chars;
2442
+ continue;
2443
+ }
2444
+ let { lines: s, flat: c } = zn(o);
2445
+ r.push({
2446
+ node: o,
2447
+ key: c,
2448
+ text: s,
2449
+ start: a
2450
+ }), i.push(s), a += s.length + 1;
2451
+ }
2452
+ if (r.length) {
2453
+ let e = Vn(r, i.join("\n"));
2454
+ r.forEach((r, i) => {
2455
+ let a = {
2456
+ key: r.key,
2457
+ words: e[i],
2458
+ chars: r.key.replaceAll("\n", "").length
2459
+ };
2460
+ this._cache.set(r.node, a), t += a.words, n += a.chars;
2461
+ });
2462
+ }
2463
+ return {
2464
+ words: t,
2465
+ chars: n
2466
+ };
2467
+ }
2468
+ };
2469
+ function Vn(e, t) {
2470
+ if (!B) return e.map((e) => In(e.text));
2471
+ let n = Array(e.length).fill(0), r = 0;
2472
+ for (let i of B.segment(t)) if (i.isWordLike) {
2473
+ for (; r < e.length - 1 && i.index >= e[r + 1].start;) r++;
2474
+ n[r]++;
2475
+ }
2476
+ return n;
2477
+ }
2478
+ //#endregion
2306
2479
  //#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();
2480
+ function Hn(e) {
2481
+ let t = new DOMParser().parseFromString(`<body>${e || ""}</body>`, "text/html");
2482
+ return ge(t.body), Yn(t.body).replace(/\n{3,}/g, "\n\n").trim();
2309
2483
  }
2310
- function z(e, t) {
2484
+ function V(e, t) {
2311
2485
  return Array.from(e.children).filter((e) => e.tagName === t.toUpperCase());
2312
2486
  }
2313
- function An(e) {
2487
+ function Un(e) {
2314
2488
  let t = "";
2315
2489
  for (let n of e.childNodes) {
2316
2490
  if (n.nodeType === 3) {
@@ -2324,40 +2498,40 @@ function An(e) {
2324
2498
  continue;
2325
2499
  }
2326
2500
  if (e === "div" || e === "p") {
2327
- t && !t.endsWith("\n") && (t += "\n"), t += An(n), t += "\n";
2501
+ t && !t.endsWith("\n") && (t += "\n"), t += Un(n), t += "\n";
2328
2502
  continue;
2329
2503
  }
2330
- t += An(n);
2504
+ t += Un(n);
2331
2505
  }
2332
2506
  return t;
2333
2507
  }
2334
- function jn(e) {
2508
+ function Wn(e) {
2335
2509
  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
2510
  }
2337
- function Mn(e) {
2511
+ function Gn(e) {
2338
2512
  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
2513
  }
2340
- function Nn(e) {
2341
- return e.split("\n").map(Mn).join("\n");
2514
+ function Kn(e) {
2515
+ return e.split("\n").map(Gn).join("\n");
2342
2516
  }
2343
- function Pn(e, t) {
2517
+ function qn(e, t) {
2344
2518
  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");
2519
+ return Yn(e, t + 1).trim().split("\n").map((e, t) => t === 0 || e.trim() === "" || e.startsWith(n) ? e : n + e).join("\n");
2346
2520
  }
2347
- function Fn(e, t) {
2521
+ function Jn(e, t) {
2348
2522
  let n = e.getAttribute(t) || "", r = /[\s()]/.test(n) ? `<${n}>` : n, i = e.getAttribute("title");
2349
2523
  return i ? `${r} "${i.replaceAll("\"", String.raw`\"`)}"` : r;
2350
2524
  }
2351
- function In(e, t = 0) {
2525
+ function Yn(e, t = 0) {
2352
2526
  if (e.nodeType === 3) {
2353
2527
  let t = e.textContent.replace(/\s+/g, " ");
2354
- return e.parentElement?.closest("pre, code") ? t : jn(t);
2528
+ return e.parentElement?.closest("pre, code") ? t : Wn(t);
2355
2529
  }
2356
2530
  if (e.nodeType !== 1) return "";
2357
- let n = e, r = n.nodeName.toLowerCase(), i = () => Array.from(n.childNodes).map((e) => In(e, t)).join("");
2531
+ let n = e, r = n.nodeName.toLowerCase(), i = () => Array.from(n.childNodes).map((e) => Yn(e, t)).join("");
2358
2532
  switch (r) {
2359
2533
  case "p":
2360
- case "div": return `\n\n${Nn(i())}\n\n`;
2534
+ case "div": return `\n\n${Kn(i())}\n\n`;
2361
2535
  case "br": return " \n";
2362
2536
  case "h1": return `\n\n# ${i()}\n\n`;
2363
2537
  case "h2": return `\n\n## ${i()}\n\n`;
@@ -2386,27 +2560,27 @@ function In(e, t = 0) {
2386
2560
  }
2387
2561
  case "pre": {
2388
2562
  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`;
2563
+ return `\n\n\`\`\`${t ? t[1] : ""}\n${Un(e || n).replace(/\n$/, "")}\n\`\`\`\n\n`;
2390
2564
  }
2391
2565
  case "blockquote": {
2392
2566
  let e = i().trim().split("\n");
2393
2567
  return `\n\n${e.filter((t, n) => t.trim() !== "" || (e[n - 1] ?? "").trim() !== "").map((e) => e.trim() === "" ? ">" : `> ${e}`).join("\n")}\n\n`;
2394
2568
  }
2395
- case "a": return `[${i()}](${Fn(n, "href")})`;
2396
- case "img": return `![${jn(n.getAttribute("alt") || "")}](${Fn(n, "src")})`;
2569
+ case "a": return `[${i()}](${Jn(n, "href")})`;
2570
+ case "img": return `![${Wn(n.getAttribute("alt") || "")}](${Jn(n, "src")})`;
2397
2571
  case "ul": {
2398
- let e = z(n, "li");
2572
+ let e = V(n, "li");
2399
2573
  if (!e.length) return i();
2400
2574
  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)}`;
2575
+ let n = V(e, "input").find((e) => e.getAttribute("type") === "checkbox"), i = "- ";
2576
+ return (a || n) && (i = n && n.checked ? "- [x] " : "- [ ] "), `${r}${i}${qn(e, t)}`;
2403
2577
  }).join("\n");
2404
2578
  return t === 0 ? `\n\n${o}\n\n` : `\n${o}`;
2405
2579
  }
2406
2580
  case "ol": {
2407
- let e = z(n, "li");
2581
+ let e = V(n, "li");
2408
2582
  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");
2583
+ 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}. ${qn(e, t)}`).join("\n");
2410
2584
  return t === 0 ? `\n\n${s}\n\n` : `\n${s}`;
2411
2585
  }
2412
2586
  case "li": return i();
@@ -2414,7 +2588,7 @@ function In(e, t = 0) {
2414
2588
  case "table": {
2415
2589
  let e = Array.from(n.querySelectorAll("tr"));
2416
2590
  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) => {
2591
+ let t = !!V(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) => Wn(e.textContent.trim()).replaceAll("|", String.raw`\|`))), a = Math.max(...r.map((e) => e.length)), o = (e) => {
2418
2592
  let t = [...e];
2419
2593
  for (; t.length < a;) t.push("");
2420
2594
  return t;
@@ -2429,16 +2603,16 @@ function In(e, t = 0) {
2429
2603
  default: return i();
2430
2604
  }
2431
2605
  }
2432
- function Ln(e) {
2606
+ function Xn(e) {
2433
2607
  return String(e ?? "").replace(/^\ufeff/, "");
2434
2608
  }
2435
- function Rn(e) {
2436
- let t = Ln(e);
2609
+ function Zn(e) {
2610
+ let t = Xn(e);
2437
2611
  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
2612
  }
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);
2613
+ var H = /^ {0,3}>( ?)(.*)$/, Qn = /^(?: {4}|\t)\s*\S/, $n = /^( {0,3})(`{3,}|~{3,})[ \t]*([^\s`~][^\n]*)?$/;
2614
+ function U(e) {
2615
+ let t = $n.exec(e);
2442
2616
  if (!t) return null;
2443
2617
  let [, n, r, i = ""] = t;
2444
2618
  return r[0] === "`" && i.includes("`") ? null : {
@@ -2448,7 +2622,7 @@ function V(e) {
2448
2622
  lang: i.trim().split(/\s+/)[0] || ""
2449
2623
  };
2450
2624
  }
2451
- function Vn(e, t) {
2625
+ function er(e, t) {
2452
2626
  let n = 0, r = 0;
2453
2627
  for (; r < e.length && n < t;) {
2454
2628
  if (e[r] === " ") {
@@ -2465,40 +2639,40 @@ function Vn(e, t) {
2465
2639
  }
2466
2640
  return e.slice(r);
2467
2641
  }
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);
2642
+ var tr = /^ {0,3}([-*_])( *\1){2,}\s*$/, nr = "";
2643
+ function rr(e) {
2644
+ let t = Xn(e).replaceAll("\r\n", "\n").replaceAll("\r", "\n").split("\n");
2645
+ t = sr(t);
2646
+ let n = cr(t);
2647
+ return t = n.clean, ar = n.linkDefs, or = n.footnoteIds, ir(t);
2474
2648
  }
2475
- function Wn(e) {
2649
+ function ir(e) {
2476
2650
  let t = [], n = 0;
2477
2651
  for (; n < e.length;) {
2478
- let r = e[n], i = V(r);
2652
+ let r = e[n], i = U(r);
2479
2653
  if (i) {
2480
2654
  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++;
2655
+ for (n++; n < e.length && !r.test(e[n]);) a.push(Ar(er(e[n], i.indent))), n++;
2482
2656
  let o = i.lang ? ` class="language-${q(i.lang)}"` : "";
2483
2657
  t.push(`<pre><code${o}>${a.join("\n")}</code></pre>`), n++;
2484
2658
  continue;
2485
2659
  }
2486
- if (zn.test(r)) {
2660
+ if (Qn.test(r)) {
2487
2661
  let r = [];
2488
- for (; n < e.length && (zn.test(e[n]) || e[n].trim() === "");) {
2662
+ for (; n < e.length && (Qn.test(e[n]) || e[n].trim() === "");) {
2489
2663
  if (e[n].trim() === "") {
2490
2664
  let t = n;
2491
2665
  for (; t < e.length && e[t].trim() === "";) t++;
2492
- if (t >= e.length || !zn.test(e[t])) break;
2666
+ if (t >= e.length || !Qn.test(e[t])) break;
2493
2667
  for (; n < t; n++) r.push("");
2494
2668
  continue;
2495
2669
  }
2496
- r.push(mr(Vn(e[n], 4))), n++;
2670
+ r.push(Ar(er(e[n], 4))), n++;
2497
2671
  }
2498
2672
  t.push(`<pre><code>${r.join("\n")}</code></pre>`);
2499
2673
  continue;
2500
2674
  }
2501
- if (r.trim() && !Hn.test(r) && !/^#{1,6} /.test(r) && n + 1 < e.length) {
2675
+ if (r.trim() && !tr.test(r) && !/^#{1,6} /.test(r) && n + 1 < e.length) {
2502
2676
  if (/^=+\s*$/.test(e[n + 1])) {
2503
2677
  t.push(`<h1>${K(r.trim())}</h1>`), n += 2;
2504
2678
  continue;
@@ -2508,7 +2682,7 @@ function Wn(e) {
2508
2682
  continue;
2509
2683
  }
2510
2684
  }
2511
- if (Hn.test(r)) {
2685
+ if (tr.test(r)) {
2512
2686
  t.push("<hr>"), n++;
2513
2687
  continue;
2514
2688
  }
@@ -2518,19 +2692,19 @@ function Wn(e) {
2518
2692
  t.push(`<h${e}>${K(r)}</h${e}>`), n++;
2519
2693
  continue;
2520
2694
  }
2521
- if (B.test(r)) {
2695
+ if (H.test(r)) {
2522
2696
  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>`);
2697
+ for (; n < e.length && H.test(e[n]);) r.push(H.exec(e[n])[2]), n++;
2698
+ t.push(`<blockquote>${ir(r)}</blockquote>`);
2525
2699
  continue;
2526
2700
  }
2527
2701
  if (/^[-*+] /.test(r)) {
2528
- let { html: r, endIdx: i } = Qn(e, n);
2702
+ let { html: r, endIdx: i } = pr(e, n);
2529
2703
  t.push(r), n = i;
2530
2704
  continue;
2531
2705
  }
2532
2706
  if (/^\d+[.)] /.test(r)) {
2533
- let { html: r, endIdx: i } = Qn(e, n);
2707
+ let { html: r, endIdx: i } = pr(e, n);
2534
2708
  t.push(r), n = i;
2535
2709
  continue;
2536
2710
  }
@@ -2538,23 +2712,23 @@ function Wn(e) {
2538
2712
  n++;
2539
2713
  continue;
2540
2714
  }
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);
2715
+ if (fr(e, n)) {
2716
+ let i = W(r), a = W(e[n + 1]).map((e) => e.startsWith(":") && e.endsWith(":") ? "center" : e.endsWith(":") ? "right" : e.startsWith(":") ? "left" : null);
2543
2717
  n += 2;
2544
2718
  let o = [];
2545
- for (; n < e.length && e[n].trim() !== "" && Xn(e[n]) > 1;) o.push(U(e[n])), n++;
2719
+ for (; n < e.length && e[n].trim() !== "" && dr(e[n]);) o.push(W(e[n])), n++;
2546
2720
  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
2721
  t.push(`<table>${c}${l}</table>`);
2548
2722
  continue;
2549
2723
  }
2550
2724
  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++);
2725
+ for (; n < e.length && e[n].trim() !== "" && !/^(#{1,6} |[-*+] |\d+[.)] )/.test(e[n]) && !U(e[n]) && !H.test(e[n]) && !tr.test(e[n]) && !fr(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++;
2726
+ o.length ? t.push(`<p>${K(lr(o)).replaceAll(nr, "<br>")}</p>`) : (t.push(`<p>${K(r)}</p>`), n++);
2553
2727
  }
2554
2728
  return t.join("");
2555
2729
  }
2556
- var Gn = /* @__PURE__ */ new Map(), Kn = /* @__PURE__ */ new Set();
2557
- function qn(e) {
2730
+ var ar = /* @__PURE__ */ new Map(), or = /* @__PURE__ */ new Set();
2731
+ function sr(e) {
2558
2732
  if ((e[0] || "").trim() !== "---") return e;
2559
2733
  let t = -1;
2560
2734
  for (let n = 1; n < e.length; n++) {
@@ -2568,14 +2742,14 @@ function qn(e) {
2568
2742
  let n = t + 1;
2569
2743
  return e[n] !== void 0 && e[n].trim() === "" && n++, e.slice(n);
2570
2744
  }
2571
- function Jn(e) {
2745
+ function cr(e) {
2572
2746
  let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = [], i = !1, a = /^\[([^\]]+)\]:\s*(\S+)(?:\s+"([^"]*)")?\s*$/, o = /^\[\^([^\]]+)\]:[ \t]*(\S.*)$/;
2573
2747
  for (let s of e) {
2574
2748
  if (i) {
2575
2749
  /^ {0,3}(?:`{3,}|~{3,})[ \t]*$/.test(s) && (i = !1), r.push(s);
2576
2750
  continue;
2577
2751
  }
2578
- if (V(s)) {
2752
+ if (U(s)) {
2579
2753
  i = !0, r.push(s);
2580
2754
  continue;
2581
2755
  }
@@ -2602,33 +2776,36 @@ function Jn(e) {
2602
2776
  footnoteIds: n
2603
2777
  };
2604
2778
  }
2605
- function Yn(e) {
2779
+ function lr(e) {
2606
2780
  let t = "";
2607
2781
  for (let n = 0; n < e.length; n++) {
2608
2782
  let r = n === e.length - 1, i = e[n].replace(/^[ \t]+/, "");
2609
2783
  if (!r && /\\$/.test(i)) {
2610
- t += i.replace(/\\$/, "") + Un;
2784
+ t += i.replace(/\\$/, "") + nr;
2611
2785
  continue;
2612
2786
  }
2613
2787
  if (!r && / {2,}$/.test(i)) {
2614
- t += i.replace(/ {2,}$/, "") + Un;
2788
+ t += i.replace(/ {2,}$/, "") + nr;
2615
2789
  continue;
2616
2790
  }
2617
2791
  t += i + (r ? "" : " ");
2618
2792
  }
2619
2793
  return t;
2620
2794
  }
2621
- function Xn(e) {
2622
- return U(e).length;
2795
+ function ur(e) {
2796
+ return W(e).length;
2797
+ }
2798
+ function dr(e) {
2799
+ return e.includes("|") ? /^\s*\|/.test(e) || ur(e) > 1 : !1;
2623
2800
  }
2624
- function Zn(e, t) {
2801
+ function fr(e, t) {
2625
2802
  let n = e[t], r = e[t + 1];
2626
2803
  if (r === void 0 || !n.includes("|")) return !1;
2627
2804
  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;
2805
+ let i = W(r);
2806
+ return i.length < 2 || !i.every((e) => /^:?-+:?$/.test(e)) ? !1 : ur(n) === i.length;
2630
2807
  }
2631
- function U(e) {
2808
+ function W(e) {
2632
2809
  let t = e.replace(/^\|/, "").replace(/\|$/, ""), n = [], r = "";
2633
2810
  for (let e = 0; e < t.length; e++) {
2634
2811
  if (t[e] === "\\" && t[e + 1] === "|") {
@@ -2643,7 +2820,7 @@ function U(e) {
2643
2820
  }
2644
2821
  return n.push(r), n.map((e) => e.trim());
2645
2822
  }
2646
- function Qn(e, t) {
2823
+ function pr(e, t) {
2647
2824
  let n = e[t].match(/^(\s*)/)[1].length, r = /^\s*\d+[.)] /.test(e[t]), i = [], a = null, o = !1, s = !1, c = t;
2648
2825
  for (; c < e.length;) {
2649
2826
  let t = e[c];
@@ -2671,15 +2848,15 @@ function Qn(e, t) {
2671
2848
  c++;
2672
2849
  continue;
2673
2850
  }
2674
- let n = (e) => Vn(e, l), r = V(n(t));
2851
+ let n = (e) => er(e, l), r = U(n(t));
2675
2852
  if (r) {
2676
2853
  let t = RegExp(`^ {0,3}\\${r.marker}{${r.length},}[ \t]*$`), a = [n(e[c])];
2677
2854
  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;
2855
+ c < e.length && (a.push(n(e[c])), c++), i[i.length - 1].sub += ir(a), s = !1;
2679
2856
  continue;
2680
2857
  }
2681
2858
  if (/^\s*(?:[-*+]|\d+[.)]) /.test(t)) {
2682
- let t = Qn(e, c);
2859
+ let t = pr(e, c);
2683
2860
  i[i.length - 1].sub += t.html, c = t.endIdx, s = !1;
2684
2861
  } else if (s) i[i.length - 1].paras.push(t.trim()), s = !1, c++;
2685
2862
  else {
@@ -2697,32 +2874,32 @@ function Qn(e, t) {
2697
2874
  endIdx: c
2698
2875
  };
2699
2876
  }
2700
- var $n = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g, W = "\0", G = "", er = /(`+)([^]*?)\1/g;
2701
- function tr(e) {
2877
+ var mr = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g, G = "\0", hr = "", gr = /(`+)([^]*?)\1/g;
2878
+ function _r(e) {
2702
2879
  let t = [];
2703
2880
  return {
2704
- text: e.replace(er, (e, n, r) => r === "" ? e : (t.push(r), `${G}${t.length - 1}${G}`)),
2881
+ text: e.replace(gr, (e, n, r) => r === "" ? e : (t.push(r), `${hr}${t.length - 1}${hr}`)),
2705
2882
  codes: t
2706
2883
  };
2707
2884
  }
2708
- function nr(e, t, n) {
2709
- return e.replace(RegExp(`${G}(\\d+)${G}`, "g"), (e, r) => {
2885
+ function vr(e, t, n) {
2886
+ return e.replace(RegExp(`${hr}(\\d+)${hr}`, "g"), (e, r) => {
2710
2887
  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>`;
2888
+ return i = i.replace(RegExp(`${G}(\\d+)${G}`, "g"), (e, t) => `\\${n[Number(t)]}`), i.length > 2 && i.startsWith(" ") && i.endsWith(" ") && i.trim() !== "" && (i = i.slice(1, -1)), `<code>${Ar(i)}</code>`;
2712
2889
  });
2713
2890
  }
2714
- function rr(e) {
2891
+ function yr(e) {
2715
2892
  let t = [];
2716
2893
  return {
2717
- text: e.replace($n, (e, n) => (t.push(n), `${W}${t.length - 1}${W}`)),
2894
+ text: e.replace(mr, (e, n) => (t.push(n), `${G}${t.length - 1}${G}`)),
2718
2895
  literals: t
2719
2896
  };
2720
2897
  }
2721
- function ir(e, t) {
2722
- return e.replace(RegExp(`${W}(\\d+)${W}`, "g"), (e, n) => pr(t[Number(n)]));
2898
+ function br(e, t) {
2899
+ return e.replace(RegExp(`${G}(\\d+)${G}`, "g"), (e, n) => kr(t[Number(n)]));
2723
2900
  }
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) {
2901
+ var xr = String.raw`(&lt;.*?&gt;(?:\s+(?:"[^"]*"|'[^']*'))?|[^)]*)`, Sr = new RegExp(String.raw`!\[([^\]]*)\]\(${xr}\)`, "g"), Cr = new RegExp(String.raw`\[([^\]]+)\]\(${xr}\)`, "g");
2902
+ function wr(e) {
2726
2903
  let t = e.trim(), n = /^&lt;([\s\S]*?)&gt;(?:[ \t]*(?:"([^"]*)"|'([^']*)'))?[ \t]*$/.exec(t);
2727
2904
  if (n) return {
2728
2905
  href: n[1],
@@ -2737,26 +2914,26 @@ function cr(e) {
2737
2914
  title: ""
2738
2915
  };
2739
2916
  }
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)}"` : "";
2917
+ function Tr(e) {
2918
+ return e = e.replace(Sr, (e, t, n) => {
2919
+ let { href: r, title: i } = wr(n), a = i ? ` title="${J(i)}"` : "";
2743
2920
  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)}"` : "";
2921
+ }), e = e.replace(Cr, (e, t, n) => {
2922
+ let { href: r, title: i } = wr(n), a = i ? ` title="${J(i)}"` : "";
2746
2923
  return `<a href="${J(r)}"${a}>${t}</a>`;
2747
2924
  }), e = e.replace(/\[([^\]]+)\]\[([^\]]*)\]/g, (e, t, n) => {
2748
- let r = Gn.get(hr(n || t).trim().toLowerCase());
2925
+ let r = ar.get(jr(n || t).trim().toLowerCase());
2749
2926
  if (!r) return e;
2750
2927
  let i = r.title ? ` title="${q(r.title)}"` : "";
2751
2928
  return `<a href="${q(r.href)}"${i}>${t}</a>`;
2752
2929
  }), e = e.replace(/\[([^\]]+)\]/g, (e, t) => {
2753
- let n = Gn.get(hr(t).trim().toLowerCase());
2930
+ let n = ar.get(jr(t).trim().toLowerCase());
2754
2931
  if (!n) return e;
2755
2932
  let r = n.title ? ` title="${q(n.title)}"` : "";
2756
2933
  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;
2934
+ }), e = e.replace(/\[\^([^\]]+)\]/g, (e, t) => or.has(jr(t)) ? `<sup>[${t}]</sup>` : e), e;
2758
2935
  }
2759
- function ur(e) {
2936
+ function Er(e) {
2760
2937
  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
2938
  let r = /[.,;:!?)]+$/.exec(n), i = r ? n.slice(0, -r[0].length) : n;
2762
2939
  if (!i) return e;
@@ -2764,18 +2941,18 @@ function ur(e) {
2764
2941
  return `${t}<a href="${J(i)}">${i}</a>${a}`;
2765
2942
  }), e;
2766
2943
  }
2767
- function dr(e) {
2944
+ function Dr(e) {
2768
2945
  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
2946
  }
2770
2947
  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);
2948
+ let { text: t, literals: n } = yr(e), { text: r, codes: i } = _r(t), a = kr(r);
2949
+ return a = Tr(a), a = Er(a), a = Dr(a), vr(br(a, n), i, n);
2773
2950
  }
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;");
2951
+ var Or = /&(?!#\d+;|#[xX][0-9a-fA-F]+;|[a-zA-Z][a-zA-Z0-9]*;)/g;
2952
+ function kr(e) {
2953
+ return String(e).replace(Or, "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2777
2954
  }
2778
- function mr(e) {
2955
+ function Ar(e) {
2779
2956
  return String(e).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2780
2957
  }
2781
2958
  function q(e) {
@@ -2784,16 +2961,16 @@ function q(e) {
2784
2961
  function J(e) {
2785
2962
  return String(e).replaceAll("\"", "&quot;").replaceAll("'", "&#39;");
2786
2963
  }
2787
- function hr(e) {
2964
+ function jr(e) {
2788
2965
  return String(e).replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&amp;", "&");
2789
2966
  }
2790
2967
  //#endregion
2791
2968
  //#region src/js/core/detectLang.js
2792
- var gr = 5, _r = 2, vr = [
2969
+ var Mr = 5, Nr = 2, Pr = [
2793
2970
  ["typescript", "javascript"],
2794
2971
  ["scss", "css"],
2795
2972
  ["cpp", "c"]
2796
- ], yr = [
2973
+ ], Fr = [
2797
2974
  "javascript",
2798
2975
  "typescript",
2799
2976
  "python",
@@ -2816,7 +2993,7 @@ var gr = 5, _r = 2, vr = [
2816
2993
  "scss",
2817
2994
  "css",
2818
2995
  "bash"
2819
- ], br = [
2996
+ ], Ir = [
2820
2997
  {
2821
2998
  lang: "php",
2822
2999
  w: 10,
@@ -3382,33 +3559,41 @@ var gr = 5, _r = 2, vr = [
3382
3559
  w: 3,
3383
3560
  re: /\s\|[ \t]*\w|\s&&\s|\s2>&1|\s-[\w-]+\s/
3384
3561
  }
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");
3562
+ ], Lr = 4e3;
3563
+ function Rr(e) {
3564
+ if (e.length <= Lr) return e;
3565
+ let t = e.slice(0, Lr), n = t.lastIndexOf("\n");
3389
3566
  return n > 0 ? t.slice(0, n) : t;
3390
3567
  }
3391
- function Cr(e) {
3568
+ function zr(e) {
3392
3569
  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);
3570
+ let t = Rr(e.trim()), n = /* @__PURE__ */ new Map();
3571
+ for (let { lang: e, re: r, w: i } of Ir) r.test(t) && n.set(e, (n.get(e) || 0) + i);
3395
3572
  if (n.size === 0) return null;
3396
- for (let [e, t] of vr) {
3573
+ for (let [e, t] of Pr) {
3397
3574
  let r = n.get(e);
3398
3575
  r && n.set(e, r + (n.get(t) || 0));
3399
3576
  }
3400
3577
  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;
3578
+ return a < Mr || a - o < Nr ? null : i;
3402
3579
  }
3403
3580
  //#endregion
3404
3581
  //#region src/js/module/Editor.js
3405
- var wr = class {
3582
+ var Br = /* @__PURE__ */ new Set([
3583
+ "PRE",
3584
+ "BLOCKQUOTE",
3585
+ "TABLE",
3586
+ "FIGURE",
3587
+ "UL",
3588
+ "OL",
3589
+ "HR"
3590
+ ]), Vr = class {
3406
3591
  constructor(e) {
3407
- this.context = e, this.options = e.options, this._history = null, this._disposers = [], this._snapshotTimer = null;
3592
+ this.context = e, this.options = e.options, this._history = null, this._disposers = [], this._snapshotTimer = null, this._limitCounter = null;
3408
3593
  }
3409
3594
  initialize() {
3410
3595
  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;
3596
+ return this._history = new On(e, this.options.historyLimit || 100, this.options.historyMaxBytes || 10 * 1024 * 1024), this._bindEvents(e), this;
3412
3597
  }
3413
3598
  destroy() {
3414
3599
  this._disposers.forEach((e) => e()), this._disposers = [], this._history = null, clearTimeout(this._snapshotTimer), this._snapshotTimer = null;
@@ -3450,18 +3635,18 @@ var wr = class {
3450
3635
  }
3451
3636
  l ? c.setStart(l, 0) : c.setStartAfter(s), c.collapse(!0), n.removeAllRanges(), n.addRange(c);
3452
3637
  }, 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) => {
3638
+ this._disposers.push(C(e, "keydown", t), C(e, "beforeinput", r), C(e, "input", n), C(document, "selectionchange", i), C(e, "click", a), C(e, "mouseup", o), C(e, "keyup", o), C(e, "dragstart", (e) => {
3454
3639
  if (s()) {
3455
3640
  e.preventDefault();
3456
3641
  return;
3457
3642
  }
3458
3643
  let t = e.target;
3459
3644
  t && (t.nodeName === "IFRAME" || t.closest(".an-video-wrapper")) && e.preventDefault();
3460
- }), S(e, "drop", (e) => {
3645
+ }), C(e, "drop", (e) => {
3461
3646
  s() && e.preventDefault();
3462
3647
  }));
3463
3648
  let c = null;
3464
- this._disposers.push(S(e, "compositionstart", () => {
3649
+ this._disposers.push(C(e, "compositionstart", () => {
3465
3650
  let e = globalThis.getSelection();
3466
3651
  if (!e?.rangeCount) {
3467
3652
  c = null;
@@ -3472,7 +3657,7 @@ var wr = class {
3472
3657
  let e = t;
3473
3658
  c = e.closest("sup") ? "superscript" : e.closest("sub") ? "subscript" : null;
3474
3659
  }
3475
- }), S(e, "compositionend", () => {
3660
+ }), C(e, "compositionend", () => {
3476
3661
  let e = c;
3477
3662
  if (c = null, !e) return;
3478
3663
  let t = globalThis.getSelection();
@@ -3485,32 +3670,32 @@ var wr = class {
3485
3670
  }
3486
3671
  _onKeydown(e) {
3487
3672
  let t = this.context.layoutInfo.editable;
3488
- if (!On(e, t, this.options)) {
3489
- if (I(e, "z") && !e.shiftKey) {
3673
+ if (!Fn(e, t, this.options)) {
3674
+ if (L(e, "z") && !e.shiftKey) {
3490
3675
  e.preventDefault(), this.undo();
3491
3676
  return;
3492
3677
  }
3493
- if (I(e, "z") && e.shiftKey || I(e, "y")) {
3678
+ if (L(e, "z") && e.shiftKey || L(e, "y")) {
3494
3679
  e.preventDefault(), this.redo();
3495
3680
  return;
3496
3681
  }
3497
- if (I(e, "b")) {
3682
+ if (L(e, "b")) {
3498
3683
  e.preventDefault(), this.bold();
3499
3684
  return;
3500
3685
  }
3501
- if (I(e, "i")) {
3686
+ if (L(e, "i")) {
3502
3687
  e.preventDefault(), this.italic();
3503
3688
  return;
3504
3689
  }
3505
- if (I(e, "u")) {
3690
+ if (L(e, "u")) {
3506
3691
  e.preventDefault(), this.underline();
3507
3692
  return;
3508
3693
  }
3509
- if (I(e, "k")) {
3694
+ if (L(e, "k")) {
3510
3695
  e.preventDefault(), this.context.invoke("linkDialog.show");
3511
3696
  return;
3512
3697
  }
3513
- if (I(e, "v") && e.shiftKey) {
3698
+ if (L(e, "v") && e.shiftKey) {
3514
3699
  this.context.invoke("clipboard.setForcePlain", !0);
3515
3700
  return;
3516
3701
  }
@@ -3518,24 +3703,25 @@ var wr = class {
3518
3703
  e.preventDefault(), this.context.invoke("shortcutsDialog.show");
3519
3704
  return;
3520
3705
  }
3521
- if (I(e, "f")) {
3706
+ if (L(e, "f")) {
3522
3707
  e.preventDefault(), this.context.invoke("findReplace.show", "find");
3523
3708
  return;
3524
3709
  }
3525
- I(e, "h") && (e.preventDefault(), this.context.invoke("findReplace.show", "replace")), I(e, "`") && (e.preventDefault(), this.inlineCode());
3710
+ L(e, "h") && (e.preventDefault(), this.context.invoke("findReplace.show", "replace")), L(e, "`") && (e.preventDefault(), this.inlineCode());
3526
3711
  }
3527
3712
  }
3528
3713
  _enforceLimit(e) {
3529
3714
  let t = this.options.maxChars || 0, n = this.options.maxWords || 0;
3530
3715
  if (!t && !n) return;
3716
+ this._limitCounter ??= new Bn();
3531
3717
  let r = e.inputType || "";
3532
3718
  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;
3719
+ let { words: i, chars: a } = this._limitCounter.counts(this.context.layoutInfo.editable);
3534
3720
  if (t && a >= t) {
3535
3721
  e.preventDefault(), typeof this.options.onCharLimitReached == "function" && this.options.onCharLimitReached(this.context);
3536
3722
  return;
3537
3723
  }
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));
3724
+ n && (e.data === " " || r === "insertParagraph" || r === "insertLineBreak") && i >= n && (e.preventDefault(), typeof this.options.onWordLimitReached == "function" && this.options.onWordLimitReached(this.context));
3539
3725
  }
3540
3726
  afterCommand() {
3541
3727
  this._cleanOrphanedFigures(), this._ensureTrailingParagraph(), this.context.invoke("toolbar.refresh"), this.context.invoke("statusbar.update"), this._scheduleSnapshot();
@@ -3554,15 +3740,7 @@ var wr = class {
3554
3740
  let e = this.context.layoutInfo.editable;
3555
3741
  if (!e) return;
3556
3742
  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)) {
3743
+ if (t && Br.has(t.nodeName)) {
3566
3744
  let t = document.createElement("p");
3567
3745
  t.innerHTML = "<br>", e.appendChild(t);
3568
3746
  }
@@ -3575,7 +3753,8 @@ var wr = class {
3575
3753
  return this.context.invoke("clipboard.resolveImages", e) ?? e;
3576
3754
  }
3577
3755
  setHTML(e) {
3578
- this.context.layoutInfo.editable.innerHTML = j(e, { allowIframes: !0 }), this._history && this._history.reset(), this.afterCommand();
3756
+ let t = _n(e, { allowIframes: !0 });
3757
+ this.context.layoutInfo.editable.replaceChildren(...t.childNodes), this._history && this._history.reset(), this.afterCommand();
3579
3758
  }
3580
3759
  getText() {
3581
3760
  return this.context.layoutInfo.editable.innerText || "";
@@ -3594,16 +3773,16 @@ var wr = class {
3594
3773
  return !e && !t;
3595
3774
  }
3596
3775
  insertHTML(e) {
3597
- e && (w("insertHTML", j(e)), this.afterCommand());
3776
+ e && (T("insertHTML", M(e)), this.afterCommand());
3598
3777
  }
3599
3778
  insertText(e) {
3600
- e && (w("insertText", e), this.afterCommand());
3779
+ e && (T("insertText", e), this.afterCommand());
3601
3780
  }
3602
3781
  setMarkdown(e) {
3603
- this.setHTML(H(e || ""));
3782
+ this.setHTML(rr(e || ""));
3604
3783
  }
3605
3784
  getMarkdown() {
3606
- return kn(this.getHTML());
3785
+ return Hn(this.getHTML());
3607
3786
  }
3608
3787
  undo() {
3609
3788
  this._history && (this._flushPendingSnapshot(), this._history.undo(), this.context.invoke("toolbar.refresh"), this.context.invoke("statusbar.update"), this.context.triggerEvent("change", this.getHTML()));
@@ -3633,63 +3812,63 @@ var wr = class {
3633
3812
  return !e || !this._history ? !1 : (this._history._restoreSelection(e), !0);
3634
3813
  }
3635
3814
  bold() {
3636
- Ie(), this.afterCommand();
3815
+ Le(), this.afterCommand();
3637
3816
  }
3638
3817
  italic() {
3639
- Le(), this.afterCommand();
3818
+ Re(), this.afterCommand();
3640
3819
  }
3641
3820
  underline() {
3642
- Re(), this.afterCommand();
3821
+ ze(), this.afterCommand();
3643
3822
  }
3644
3823
  strikethrough() {
3645
- ze(), this.afterCommand();
3824
+ Be(), this.afterCommand();
3646
3825
  }
3647
3826
  superscript() {
3648
- Be(), this.afterCommand();
3827
+ Ve(), this.afterCommand();
3649
3828
  }
3650
3829
  subscript() {
3651
- Ve(), this.afterCommand();
3830
+ He(), this.afterCommand();
3652
3831
  }
3653
3832
  justifyLeft() {
3654
- qe(), this.afterCommand();
3833
+ Je(), this.afterCommand();
3655
3834
  }
3656
3835
  justifyCenter() {
3657
- Je(), this.afterCommand();
3836
+ Ye(), this.afterCommand();
3658
3837
  }
3659
3838
  justifyRight() {
3660
- Ye(), this.afterCommand();
3839
+ Xe(), this.afterCommand();
3661
3840
  }
3662
3841
  justifyFull() {
3663
- Xe(), this.afterCommand();
3842
+ Ze(), this.afterCommand();
3664
3843
  }
3665
3844
  indent() {
3666
- Ze(), this.afterCommand();
3845
+ Qe(), this.afterCommand();
3667
3846
  }
3668
3847
  outdent() {
3669
- Qe(), this.afterCommand();
3848
+ et(), this.afterCommand();
3670
3849
  }
3671
3850
  insertUL() {
3672
- nt(), this.afterCommand();
3851
+ at(), this.afterCommand();
3673
3852
  }
3674
3853
  insertOL() {
3675
- rt(), this.afterCommand();
3854
+ ot(), this.afterCommand();
3676
3855
  }
3677
3856
  inlineCode() {
3678
- at(this.context.layoutInfo.editable), this.afterCommand();
3857
+ ct(this.context.layoutInfo.editable), this.afterCommand();
3679
3858
  }
3680
3859
  toggleChecklist() {
3681
- ct(), this.afterCommand();
3860
+ dt(), this.afterCommand();
3682
3861
  }
3683
3862
  print() {
3684
3863
  this.context.print();
3685
3864
  }
3686
3865
  formatBlock(e) {
3687
- if (Ke(e), e === "pre") {
3866
+ if (qe(e), e === "pre") {
3688
3867
  let e = globalThis.getSelection();
3689
3868
  if (e?.rangeCount > 0) {
3690
3869
  let t = e.getRangeAt(0).commonAncestorContainer, n = t.nodeType === 1 ? t.closest("pre") : t.parentElement?.closest("pre");
3691
3870
  if (n && !n.dataset.language) {
3692
- let e = Cr(n.textContent || "");
3871
+ let e = zr(n.textContent || "");
3693
3872
  if (e) {
3694
3873
  this.context.invoke("codeTooltip.applyLanguage", n, e);
3695
3874
  return;
@@ -3700,55 +3879,55 @@ var wr = class {
3700
3879
  this.afterCommand();
3701
3880
  }
3702
3881
  foreColor(e) {
3703
- He(e), this.afterCommand();
3882
+ Ue(e), this.afterCommand();
3704
3883
  }
3705
3884
  backColor(e) {
3706
- Ue(e), this.afterCommand();
3885
+ We(e), this.afterCommand();
3707
3886
  }
3708
3887
  fontName(e) {
3709
- We(e), this.afterCommand();
3888
+ Ge(e), this.afterCommand();
3710
3889
  }
3711
3890
  fontSize(e) {
3712
- Ge(e, this.context.layoutInfo.editable), this.afterCommand();
3891
+ Ke(e, this.context.layoutInfo.editable), this.afterCommand();
3713
3892
  }
3714
3893
  insertHr() {
3715
- w("insertHorizontalRule"), this.afterCommand();
3894
+ T("insertHorizontalRule"), this.afterCommand();
3716
3895
  }
3717
3896
  insertLink(e, t, n = !1) {
3718
3897
  let r = globalThis.getSelection();
3719
3898
  if (!r || r.rangeCount === 0) return;
3720
- let i = M(e);
3899
+ let i = N(e);
3721
3900
  if (i) {
3722
3901
  if (r.toString().trim().length > 0) {
3723
- if (w("createLink", i), n) {
3902
+ if (T("createLink", i), n) {
3724
3903
  let e = this._getClosestAnchor();
3725
3904
  e && (e.setAttribute("target", "_blank"), e.setAttribute("rel", "noopener noreferrer"));
3726
3905
  }
3727
3906
  } else {
3728
3907
  let e = this._escapeAttr(t || i);
3729
- w("insertHTML", `<a href="${this._escapeAttr(i)}"${n ? " target=\"_blank\" rel=\"noopener noreferrer\"" : ""}>${e}</a>`);
3908
+ T("insertHTML", `<a href="${this._escapeAttr(i)}"${n ? " target=\"_blank\" rel=\"noopener noreferrer\"" : ""}>${e}</a>`);
3730
3909
  }
3731
3910
  this.afterCommand();
3732
3911
  }
3733
3912
  }
3734
3913
  unlink() {
3735
- w("unlink"), this.afterCommand();
3914
+ T("unlink"), this.afterCommand();
3736
3915
  }
3737
3916
  insertImage(e, t = "", n = "") {
3738
- let r = M(e, { allowData: !0 });
3917
+ let r = N(e, { allowData: !0 });
3739
3918
  if (!r) return;
3740
3919
  let i = {
3741
3920
  left: "float:left;margin:0 1em 1em 0",
3742
3921
  center: "display:block;margin:0 auto",
3743
3922
  right: "float:right;margin:0 0 1em 1em"
3744
3923
  }[n] || "", a = i ? ` style="${i}"` : "";
3745
- w("insertHTML", `<img src="${this._escapeAttr(r)}" alt="${this._escapeAttr(t)}" class="an-image"${a}>`), this.afterCommand();
3924
+ T("insertHTML", `<img src="${this._escapeAttr(r)}" alt="${this._escapeAttr(t)}" class="an-image"${a}>`), this.afterCommand();
3746
3925
  }
3747
3926
  insertVideo(e) {
3748
- e && (w("insertHTML", e), this.afterCommand());
3927
+ e && (T("insertHTML", e), this.afterCommand());
3749
3928
  }
3750
3929
  insertTable(e, t) {
3751
- Tn(e, t, { headerRow: this.context.options.tableHeaderRow }), this.afterCommand();
3930
+ An(e, t, { headerRow: this.context.options.tableHeaderRow }), this.afterCommand();
3752
3931
  }
3753
3932
  _getClosestAnchor() {
3754
3933
  let e = globalThis.getSelection();
@@ -3763,7 +3942,7 @@ var wr = class {
3763
3942
  _escapeAttr(e) {
3764
3943
  return String(e ?? "").replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
3765
3944
  }
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([
3945
+ }, Hr = (e) => typeof e == "string" ? pt(e) : e, Y = null, Ur = "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" ${Ur} style="display:block">${e}</svg>`, Z = /* @__PURE__ */ new Map([
3767
3946
  ["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
3947
  ["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
3948
  ["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\"/>")],
@@ -3800,7 +3979,7 @@ var wr = class {
3800
3979
  ["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
3980
  ["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
3981
  ["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([
3982
+ ]), Wr = /* @__PURE__ */ new Map([
3804
3983
  ["bold", "fa-bold"],
3805
3984
  ["italic", "fa-italic"],
3806
3985
  ["underline", "fa-underline"],
@@ -3834,17 +4013,17 @@ var wr = class {
3834
4013
  ["inline-code", "fa-code"],
3835
4014
  ["checklist", "fa-list-check"],
3836
4015
  ["print", "fa-print"]
3837
- ]), Or = class {
4016
+ ]), Gr = class {
3838
4017
  constructor(e) {
3839
4018
  this.context = e, this.options = e.options, this.el = null, this._disposers = [], this._colorPickerClosers = [], this._refreshRaf = null;
3840
4019
  }
3841
4020
  initialize() {
3842
- return this.el = b("div", {
4021
+ return this.el = x("div", {
3843
4022
  class: "an-toolbar",
3844
4023
  role: "toolbar",
3845
4024
  "aria-orientation": "horizontal",
3846
4025
  "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;
4026
+ }), this._faReady = this._detectFontAwesome(), this._buildButtons(), this._initRovingFocus(), this._btnMap = new Map((this.options.toolbar || []).flat().map(Hr).filter(Boolean).map((e) => [e.name, e])), this;
3848
4027
  }
3849
4028
  destroy() {
3850
4029
  this._refreshRaf && cancelAnimationFrame(this._refreshRaf), this._refreshRaf = null, this._disposers.forEach((e) => e()), this._disposers = [], this.el?.parentNode && this.el.remove(), this.el = null;
@@ -3852,9 +4031,9 @@ var wr = class {
3852
4031
  _buildButtons() {
3853
4032
  let e = this.options.toolbar || [], t = document.createDocumentFragment();
3854
4033
  e.forEach((e) => {
3855
- let n = b("div", { class: "an-btn-group" });
4034
+ let n = x("div", { class: "an-btn-group" });
3856
4035
  e.forEach((e) => {
3857
- let t = Tr(e);
4036
+ let t = Hr(e);
3858
4037
  if (!t) {
3859
4038
  console.warn(`[AutumnNote] Toolbar: button "${e}" not found in registry. Skipped.`);
3860
4039
  return;
@@ -3865,7 +4044,7 @@ var wr = class {
3865
4044
  }), this.el.appendChild(t);
3866
4045
  }
3867
4046
  _createGridPicker(e) {
3868
- let t = b("div", { class: "an-table-picker-wrap" }), n = b("button", {
4047
+ let t = x("div", { class: "an-table-picker-wrap" }), n = x("button", {
3869
4048
  type: "button",
3870
4049
  class: this.options.useBootstrap ? this.options.toolbarButtonClass || "btn btn-sm btn-light" : "an-btn",
3871
4050
  title: this.context.locale.toolbar[e.name] || e.tooltip || "",
@@ -3875,15 +4054,15 @@ var wr = class {
3875
4054
  "aria-expanded": "false"
3876
4055
  });
3877
4056
  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", {
4057
+ let r = x("div", {
3879
4058
  class: "an-table-picker-popup",
3880
4059
  role: "dialog",
3881
4060
  "aria-label": "Select table size"
3882
- }), i = b("div", { class: "an-table-grid" }), a = b("div", { class: "an-table-label" });
4061
+ }), i = x("div", { class: "an-table-grid" }), a = x("div", { class: "an-table-label" });
3883
4062
  a.textContent = this.context.locale.toolbar.insertTableLabel || "Insert Table";
3884
4063
  let o = [];
3885
4064
  for (let e = 1; e <= 10; e++) for (let t = 1; t <= 10; t++) {
3886
- let n = b("div", {
4065
+ let n = x("div", {
3887
4066
  class: "an-table-cell",
3888
4067
  "data-row": String(e),
3889
4068
  "data-col": String(t)
@@ -3904,17 +4083,17 @@ var wr = class {
3904
4083
  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
4084
  }, u = () => {
3906
4085
  s = !1, r.style.display = "none", n.setAttribute("aria-expanded", "false"), c(0, 0);
3907
- }, d = S(n, "click", (e) => {
4086
+ }, d = C(n, "click", (e) => {
3908
4087
  e.stopPropagation(), s ? u() : l();
3909
- }), f = S(i, "mouseover", (e) => {
4088
+ }), f = C(i, "mouseover", (e) => {
3910
4089
  let t = e.target?.closest(".an-table-cell");
3911
4090
  t && c(+t.dataset.row, +t.dataset.col);
3912
- }), p = S(i, "mouseleave", () => c(0, 0)), m = S(i, "click", (t) => {
4091
+ }), p = C(i, "mouseleave", () => c(0, 0)), m = C(i, "click", (t) => {
3913
4092
  let n = t.target?.closest(".an-table-cell");
3914
4093
  if (!n) return;
3915
4094
  let r = +n.dataset.row, i = +n.dataset.col;
3916
4095
  u(), this.context.invoke("editor.focus"), e.action(this.context, r, i);
3917
- }), h = S(document, "click", () => {
4096
+ }), h = C(document, "click", () => {
3918
4097
  s && u();
3919
4098
  });
3920
4099
  return this._disposers.push(d, f, p, m, h, () => {
@@ -3947,7 +4126,7 @@ var wr = class {
3947
4126
  "#c9daf8",
3948
4127
  "#d9d2e9",
3949
4128
  "#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", {
4129
+ ], n = e.defaultColor || "#000000", r = x("div", { class: "an-color-picker-wrap" }), i = this.options.useBootstrap ? this.options.toolbarButtonClass || "btn btn-sm btn-light" : "an-btn", a = x("button", {
3951
4130
  type: "button",
3952
4131
  class: `${i} an-color-btn`,
3953
4132
  title: this.context.locale.toolbar[e.name] || e.tooltip || "",
@@ -3955,9 +4134,9 @@ var wr = class {
3955
4134
  "aria-label": this.context.locale.toolbar[e.name] || e.tooltip || e.name
3956
4135
  }), o = "stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"";
3957
4136
  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" });
4137
+ let s = x("span", { class: "an-color-strip" });
3959
4138
  s.style.background = n, a.appendChild(s);
3960
- let c = b("button", {
4139
+ let c = x("button", {
3961
4140
  type: "button",
3962
4141
  class: `${i} an-color-arrow`,
3963
4142
  title: e.name === "foreColor" ? this.context.locale.toolbar.chooseTextColor || "Choose text color" : this.context.locale.toolbar.chooseHighlightColor || "Choose highlight color",
@@ -3965,22 +4144,22 @@ var wr = class {
3965
4144
  "aria-expanded": "false"
3966
4145
  });
3967
4146
  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" });
4147
+ let l = x("div", { class: "an-color-popup" });
3969
4148
  l.style.display = "none";
3970
- let u = b("div", { class: "an-color-swatches" }), d = Array.isArray(this.options.colorSwatches) ? this.options.colorSwatches : [];
4149
+ let u = x("div", { class: "an-color-swatches" }), d = Array.isArray(this.options.colorSwatches) ? this.options.colorSwatches : [];
3971
4150
  [.../* @__PURE__ */ new Set([...d, ...t])].forEach((e) => {
3972
- let t = b("div", {
4151
+ let t = x("div", {
3973
4152
  class: "an-color-swatch",
3974
4153
  title: e,
3975
4154
  "data-color": e
3976
4155
  });
3977
4156
  t.style.background = e, u.appendChild(t);
3978
4157
  });
3979
- let f = b("div", { class: "an-color-custom" }), p = b("input", {
4158
+ let f = x("div", { class: "an-color-custom" }), p = x("input", {
3980
4159
  type: "color",
3981
4160
  value: n,
3982
4161
  title: this.context.locale.toolbar.customColor || "Custom color"
3983
- }), m = b("span", {}, [this.context.locale.toolbar.customColor || "Custom color"]);
4162
+ }), m = x("span", {}, [this.context.locale.toolbar.customColor || "Custom color"]);
3984
4163
  f.appendChild(p), f.appendChild(m), l.appendChild(u), l.appendChild(f);
3985
4164
  let h = !1, g = null, ee = () => {
3986
4165
  let e = globalThis.getSelection();
@@ -4001,28 +4180,28 @@ var wr = class {
4001
4180
  h = !1, l.style.display = "none", l.style.top = "", l.style.left = "", c.setAttribute("aria-expanded", "false");
4002
4181
  }, v = (t) => {
4003
4182
  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) => {
4183
+ }, re = C(a, "click", (t) => {
4005
4184
  t.preventDefault(), te(), e.action(this.context, n), this.context.invoke("editor.afterCommand");
4006
- }), ie = S(c, "mousedown", (e) => {
4185
+ }), ie = C(c, "mousedown", (e) => {
4007
4186
  e.preventDefault();
4008
- }), y = S(c, "click", (e) => {
4187
+ }), y = C(c, "click", (e) => {
4009
4188
  e.stopPropagation(), h ? _() : ne();
4010
- }), ae = S(u, "mousedown", (e) => {
4189
+ }), b = C(u, "mousedown", (e) => {
4011
4190
  e.preventDefault();
4012
- }), oe = S(u, "click", (e) => {
4191
+ }), ae = C(u, "click", (e) => {
4013
4192
  let t = e.target?.closest(".an-color-swatch");
4014
4193
  t && v(t.dataset.color);
4015
- }), se = S(p, "change", (e) => {
4194
+ }), oe = C(p, "change", (e) => {
4016
4195
  v(e.target.value);
4017
- }), ce = S(document, "click", (e) => {
4196
+ }), se = C(document, "click", (e) => {
4018
4197
  h && !r.contains(e.target) && !l.contains(e.target) && _();
4019
- }), le = S(l, "click", (e) => e.stopPropagation()), x = () => {
4198
+ }), ce = C(l, "click", (e) => e.stopPropagation()), S = () => {
4020
4199
  h && _();
4021
4200
  };
4022
- return document.addEventListener("scroll", x, {
4201
+ return document.addEventListener("scroll", S, {
4023
4202
  passive: !0,
4024
4203
  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), () => {
4204
+ }), globalThis.addEventListener("resize", S, { passive: !0 }), this._disposers.push(re, ie, y, b, ae, oe, se, ce, () => document.removeEventListener("scroll", S, { capture: !0 }), () => globalThis.removeEventListener("resize", S), () => {
4026
4205
  l.parentNode && l.remove();
4027
4206
  }), this._colorPickerClosers.push(_), this._disposers.push(() => {
4028
4207
  let e = this._colorPickerClosers.indexOf(_);
@@ -4030,12 +4209,12 @@ var wr = class {
4030
4209
  }), r.appendChild(a), r.appendChild(c), document.body.appendChild(l), r;
4031
4210
  }
4032
4211
  _createSelect(e) {
4033
- let t = e.name === "fontFamily" ? this.options.fontFamilies || [] : e.items || [], n = b("select", {
4212
+ let t = e.name === "fontFamily" ? this.options.fontFamilies || [] : e.items || [], n = x("select", {
4034
4213
  class: e.selectClass ? `an-select ${e.selectClass}` : "an-select",
4035
4214
  title: this.context.locale.toolbar[e.name] || e.tooltip || "",
4036
4215
  "data-btn": e.name,
4037
4216
  "aria-label": this.context.locale.toolbar[e.name] || e.tooltip || e.name
4038
- }), r = b("option", {
4217
+ }), r = x("option", {
4039
4218
  value: "",
4040
4219
  disabled: "",
4041
4220
  hidden: ""
@@ -4045,13 +4224,13 @@ var wr = class {
4045
4224
  i = typeof t == "object" ? e.name === "paragraphStyle" && this.context.locale.toolbar.paragraphItems?.[t.value] || t.label : t;
4046
4225
  let a = typeof t == "object" && !!t.disabled, o = { value: r };
4047
4226
  a && (o.disabled = "");
4048
- let s = b("option", o, [i]);
4227
+ let s = x("option", o, [i]);
4049
4228
  e.name === "fontFamily" && !a && (s.style.fontFamily = r), n.appendChild(s);
4050
4229
  });
4051
- let i = null, a = S(n, "mousedown", () => {
4230
+ let i = null, a = C(n, "mousedown", () => {
4052
4231
  let e = globalThis.getSelection();
4053
4232
  i = e?.rangeCount ? e.getRangeAt(0).cloneRange() : null;
4054
- }), o = S(n, "change", (t) => {
4233
+ }), o = C(n, "change", (t) => {
4055
4234
  let n = t.target.value, r = t.target.options[t.target.selectedIndex];
4056
4235
  if (!(!n || r.disabled)) {
4057
4236
  if (this.context.invoke("editor.focus"), i) try {
@@ -4064,7 +4243,7 @@ var wr = class {
4064
4243
  return this._disposers.push(a, o), n;
4065
4244
  }
4066
4245
  _createButton(e) {
4067
- let t = b("button", {
4246
+ let t = x("button", {
4068
4247
  type: "button",
4069
4248
  class: `${this.options.useBootstrap ? this.options.toolbarButtonClass || "btn btn-sm btn-light" : "an-btn"}${e.className ? ` ${e.className}` : ""}`,
4070
4249
  title: this.context.locale.toolbar[e.name] || e.tooltip || "",
@@ -4073,10 +4252,10 @@ var wr = class {
4073
4252
  ...typeof e.isActive == "function" ? { "aria-pressed": "false" } : {}
4074
4253
  }), n = this.options.fontAwesomeClass || "fas";
4075
4254
  if (this._faReady) {
4076
- let r = Dr.get(e.icon) || Dr.get(e.name) || null;
4255
+ let r = Wr.get(e.icon) || Wr.get(e.name) || null;
4077
4256
  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
4257
  } 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) => {
4258
+ let r = C(t, "click", (t) => {
4080
4259
  t.preventDefault(), this.context.invoke("editor.focus"), e.action(this.context), this.context.invoke("editor.afterCommand"), this.refresh();
4081
4260
  });
4082
4261
  return this._disposers.push(r), t;
@@ -4094,7 +4273,7 @@ var wr = class {
4094
4273
  t.forEach((e) => e.setAttribute("tabindex", e === r ? "0" : "-1"));
4095
4274
  }
4096
4275
  _initRovingFocus() {
4097
- this.el && (this._syncRovingTabindex(), this._disposers.push(S(this.el, "keydown", (e) => this._onToolbarKeydown(e)), S(this.el, "focusin", (e) => {
4276
+ this.el && (this._syncRovingTabindex(), this._disposers.push(C(this.el, "keydown", (e) => this._onToolbarKeydown(e)), C(this.el, "focusin", (e) => {
4098
4277
  let t = e.target?.closest?.("button, select");
4099
4278
  t && this._syncRovingTabindex(t);
4100
4279
  })));
@@ -4155,449 +4334,449 @@ var wr = class {
4155
4334
  this.el && (this.el.style.display = "none");
4156
4335
  }
4157
4336
  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;
4337
+ 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(Hr).filter(Boolean).map((e) => [e.name, e])), this.refresh();
4168
4338
  }
4169
- return t.split(/\s+/).length;
4170
- }
4171
- function jr(e, t, n) {
4339
+ };
4340
+ //#endregion
4341
+ //#region src/js/module/Statusbar.js
4342
+ function Kr(e, t, n) {
4172
4343
  if (!n) {
4173
4344
  e.classList.remove("an-count-warn", "an-count-exceeded");
4174
4345
  return;
4175
4346
  }
4176
4347
  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
4348
  }
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
- }
4349
+ var qr = class {
4350
+ constructor(e) {
4351
+ this.context = e, this.options = e.options, this.el = null, this._disposers = [], this._wordCountEl = null, this._charCountEl = null, this._counter = new Bn();
4352
+ }
4353
+ initialize() {
4354
+ if (this.el = x("div", { class: "an-statusbar" }), this.options.resizable !== !1) {
4355
+ let e = x("div", {
4356
+ class: "an-resize-handle",
4357
+ title: this.context.locale.statusbar.resizeHandle,
4358
+ "aria-hidden": "true"
4359
+ });
4360
+ this._bindResize(e), this.el.appendChild(e);
4254
4361
  }
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;");
4362
+ this._wordCountEl = x("span", {
4363
+ class: "an-word-count",
4364
+ role: "status",
4365
+ "aria-live": "polite",
4366
+ "aria-atomic": "true"
4367
+ }), this._charCountEl = x("span", {
4368
+ class: "an-char-count",
4369
+ "aria-live": "polite",
4370
+ "aria-atomic": "true"
4371
+ });
4372
+ let e = x("div", {
4373
+ class: "an-status-info",
4374
+ "aria-label": "Editor statistics"
4375
+ });
4376
+ return e.appendChild(this._wordCountEl), e.appendChild(this._charCountEl), this.el.appendChild(e), this.update(), this;
4377
+ }
4378
+ destroy() {
4379
+ this._disposers.forEach((e) => e()), this._disposers = [], this._dragDisposers &&= (this._dragDisposers.forEach((e) => e()), null), this.el?.remove(), this.el = null;
4380
+ }
4381
+ _bindResize(e) {
4382
+ let t = 0, n = 0, r = this.context.layoutInfo.container, i = (e) => {
4383
+ 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);
4384
+ r.style.height = `${Math.max(o, n + i)}px`;
4385
+ }, a = (e) => i(e.clientY), o = () => {
4386
+ document.removeEventListener("mousemove", a), document.removeEventListener("mouseup", o), this._dragDisposers = null;
4387
+ }, s = (e) => {
4388
+ 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();
4389
+ }, c = (e) => {
4390
+ let t = e.touches[0];
4391
+ t && (e.preventDefault(), i(t.clientY));
4392
+ }, l = () => {
4393
+ document.removeEventListener("touchmove", c), document.removeEventListener("touchend", l), this._dragDisposers = null;
4394
+ }, u = (e) => {
4395
+ let i = e.touches[0];
4396
+ 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)]);
4397
+ }, d = C(e, "mousedown", s), f = C(e, "touchstart", u);
4398
+ this._disposers.push(d, f);
4399
+ }
4400
+ _counts() {
4401
+ return this._counter.counts(this.context.layoutInfo.editable);
4402
+ }
4403
+ update() {
4404
+ if (!this._wordCountEl || !this._charCountEl) return;
4405
+ let { words: e, chars: t } = this._counts(), n = this.options.maxWords || 0, r = this.options.maxChars || 0, i = this.context.locale.statusbar;
4406
+ this._wordCountEl.textContent = n ? i.wordsLimit(e, n) : i.words(e), this._charCountEl.textContent = r ? i.charsLimit(t, r) : i.chars(t), Kr(this._wordCountEl, e, n), Kr(this._charCountEl, t, r);
4407
+ }
4408
+ getWordCount() {
4409
+ return this._counts().words;
4410
+ }
4411
+ getCharCount() {
4412
+ return this._counts().chars;
4413
+ }
4414
+ }, Jr = class {
4415
+ constructor(e) {
4416
+ this.context = e, this.options = e.options, this._disposers = [];
4417
+ }
4418
+ initialize() {
4419
+ this._blobRegistry = /* @__PURE__ */ new Map(), this._forcePlain = !1;
4420
+ let e = this.context.layoutInfo.editable;
4421
+ return this._disposers.push(C(e, "paste", (e) => this._onPaste(e)), C(e, "dragover", (e) => this._onDragover(e)), C(e, "drop", (e) => this._onDrop(e))), this._mutationObserver = new MutationObserver((e) => {
4422
+ for (let t of e) for (let e of t.removedNodes) this._revokeRemovedBlobs(e);
4423
+ }), this._mutationObserver.observe(e, {
4424
+ childList: !0,
4425
+ subtree: !0
4426
+ }), this;
4427
+ }
4428
+ destroy() {
4429
+ 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());
4430
+ }
4431
+ _revokeRemovedBlobs(e) {
4432
+ if (!this._blobRegistry?.size) return;
4433
+ let t = [];
4434
+ e.nodeName === "IMG" ? t.push(e) : e.querySelectorAll && t.push(...e.querySelectorAll("img")), t.forEach((e) => {
4435
+ let t = e.getAttribute("src") || "";
4436
+ t.startsWith("blob:") && this._blobRegistry.has(t) && (URL.revokeObjectURL(t), this._blobRegistry.delete(t));
4437
+ });
4438
+ }
4439
+ _cleanWordHtml(e) {
4440
+ 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) => {
4441
+ 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("; ");
4442
+ return n ? ` style="${n}"` : "";
4443
+ }).replace(/<p[^>]*>\s*(&nbsp;)?\s*<\/p>/gi, "");
4444
+ }
4445
+ _cleanSocialHtml(e) {
4446
+ let t = new DOMParser().parseFromString(`<body>${e}</body>`, "text/html"), n = Array.from(t.querySelectorAll("span, div"));
4447
+ for (let e = n.length - 1; e >= 0; e--) {
4448
+ let t = n[e];
4449
+ 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;
4450
+ let r = t.parentNode;
4451
+ for (; t.firstChild;) r.insertBefore(t.firstChild, t);
4452
+ t.remove();
4453
+ }
4454
+ return t.querySelectorAll("*").forEach((e) => {
4455
+ 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));
4456
+ }), t.body.innerHTML;
4457
+ }
4458
+ _stripAttributes(e) {
4459
+ let t = new DOMParser().parseFromString(`<body>${e}</body>`, "text/html"), n = /* @__PURE__ */ new Set([
4460
+ "href",
4461
+ "src",
4462
+ "alt",
4463
+ "target",
4464
+ "rel",
4465
+ "colspan",
4466
+ "rowspan",
4467
+ "type"
4468
+ ]);
4469
+ return t.querySelectorAll("*").forEach((e) => {
4470
+ Array.from(e.attributes).filter((e) => !n.has(e.name)).forEach((t) => e.removeAttribute(t.name));
4471
+ }), t.body.innerHTML;
4472
+ }
4473
+ _normalizeExternalTaskLists(e) {
4474
+ let t = new DOMParser().parseFromString(`<body>${e}</body>`, "text/html");
4475
+ for (let e of t.querySelectorAll("input[type=\"checkbox\"]")) {
4476
+ let t = e.closest("li"), n = t?.closest("ul");
4477
+ if (!(!t || !n || n.classList.contains("an-checklist"))) {
4478
+ n.classList.add("an-checklist"), e.removeAttribute("disabled"), e.setAttribute("contenteditable", "false");
4479
+ for (let t of Array.from(e.attributes)) [
4480
+ "type",
4481
+ "checked",
4482
+ "contenteditable"
4483
+ ].includes(t.name) || e.removeAttribute(t.name);
4467
4484
  }
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
- });
4485
+ }
4486
+ return t.body.innerHTML;
4487
+ }
4488
+ _isTriviallyPlainHtml(e) {
4489
+ 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");
4490
+ }
4491
+ setForcePlain(e) {
4492
+ this._forcePlain = !!e;
4493
+ }
4494
+ _onPaste(e) {
4495
+ let t = e.clipboardData || globalThis.clipboardData;
4496
+ if (!t) return;
4497
+ let n = this._forcePlain;
4498
+ this._forcePlain = !1;
4499
+ let r = (this.options.maxPasteSize ?? 5) * 1024 * 1024;
4500
+ if (r > 0) {
4501
+ let n = t.getData("text/plain") || "", i = t.getData("text/html") || "", a = Math.max(n.length, i.length);
4502
+ if (a > r) {
4503
+ e.preventDefault();
4504
+ let t = `Pasted content (${a} bytes) exceeds the ${this.options.maxPasteSize ?? 5} MB paste size limit.`;
4505
+ this.context.triggerEvent("pasteError", {
4506
+ size: a,
4507
+ maxBytes: r,
4508
+ message: t
4509
+ }), console.warn(`[AutumnNote] ${t}`);
4510
+ return;
4492
4511
  }
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;
4512
+ }
4513
+ if (t.items) {
4514
+ let n = Array.from(t.items).filter((e) => e.kind === "file" && e.type.startsWith("image/"));
4515
+ if (n.length > 0) {
4516
+ e.preventDefault();
4517
+ let t = n.map((e) => e.getAsFile()).filter(Boolean);
4518
+ this._insertImageFiles(t);
4519
+ return;
4501
4520
  }
4502
- _findPlaceholder(e) {
4503
- return this.context.layoutInfo.editable?.querySelector(`img[data-an-upload="${e}"]`) ?? null;
4521
+ }
4522
+ if (typeof this.options.onPaste == "function" && this.options.onPaste({
4523
+ text: t.getData("text/plain") || "",
4524
+ html: t.types.includes("text/html") ? t.getData("text/html") : null
4525
+ }), n || this.options.pasteAsPlainText) {
4526
+ e.preventDefault(), T("insertHTML", t.getData("text/plain").split(/\r?\n/).map((e) => `<p>${this._escapeHTML(e) || "<br>"}</p>`).join("")), this.context.invoke("editor.afterCommand");
4527
+ return;
4528
+ }
4529
+ if (this.options.markdownPaste !== !1) {
4530
+ let n = t.types.includes("text/html"), r = n ? t.getData("text/html") : "", i = !n || this._isTriviallyPlainHtml(r), a = t.getData("text/plain");
4531
+ if (a && i && Zn(a)) {
4532
+ e.preventDefault(), T("insertHTML", M(rr(a))), this.context.invoke("editor.afterCommand");
4533
+ return;
4504
4534
  }
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");
4535
+ }
4536
+ if (this.options.pasteCleanHTML !== !1 && t.types.includes("text/html")) {
4537
+ e.preventDefault();
4538
+ 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;
4539
+ r ? a = this._cleanWordHtml(a) : i && (a = this._cleanSocialHtml(a)), a = this._normalizeExternalTaskLists(a), a = M(a), this.options.pasteStripAttributes && (a = this._stripAttributes(a)), T("insertHTML", a), this.context.invoke("editor.afterCommand");
4540
+ }
4541
+ }
4542
+ _onDragover(e) {
4543
+ e.dataTransfer && Array.from(e.dataTransfer.types || []).includes("Files") && (e.preventDefault(), e.dataTransfer.dropEffect = "copy");
4544
+ }
4545
+ _onDrop(e) {
4546
+ let t = e.dataTransfer;
4547
+ if (!t?.files?.length) return;
4548
+ let n = Array.from(t.files).filter((e) => e.type.startsWith("image/"));
4549
+ if (n.length > 0) {
4550
+ e.preventDefault(), e.stopPropagation(), this._placeCaretAtPoint(e.clientX, e.clientY), this._insertImageFiles(n);
4551
+ return;
4552
+ }
4553
+ if (this.options.markdownPaste !== !1) {
4554
+ let n = Array.from(t.files).find((e) => /\.md$/i.test(e.name) || e.type === "text/markdown");
4555
+ n && (e.preventDefault(), e.stopPropagation(), this._placeCaretAtPoint(e.clientX, e.clientY), this._insertMarkdownFile(n));
4556
+ }
4557
+ }
4558
+ _insertMarkdownFile(e) {
4559
+ let t = (this.options.maxPasteSize ?? 5) * 1024 * 1024;
4560
+ if (t > 0 && e.size > t) {
4561
+ let n = `Dropped file "${e.name}" (${e.size} bytes) exceeds the ${this.options.maxPasteSize ?? 5} MB paste size limit.`;
4562
+ this.context.triggerEvent("pasteError", {
4563
+ size: e.size,
4564
+ maxBytes: t,
4565
+ message: n
4566
+ }), console.warn(`[AutumnNote] ${n}`);
4567
+ return;
4568
+ }
4569
+ let n = new FileReader();
4570
+ n.onload = (e) => {
4571
+ T("insertHTML", M(rr(e.target.result || ""))), this.context.invoke("editor.afterCommand");
4572
+ }, n.onerror = () => {
4573
+ let t = `Failed to read dropped markdown file "${e.name}".`;
4574
+ console.warn(`[AutumnNote] ${t}`), this.context.triggerEvent("pasteError", { message: t });
4575
+ }, n.readAsText(e);
4576
+ }
4577
+ _insertImageFiles(e) {
4578
+ if (!e || e.length === 0) return;
4579
+ if (typeof this.options.onImageUpload == "function") {
4580
+ this._runUploadHandler(e);
4581
+ return;
4582
+ }
4583
+ let t = /* @__PURE__ */ new Set([
4584
+ "image/tiff",
4585
+ "image/x-tiff",
4586
+ "image/bmp",
4587
+ "image/x-bmp",
4588
+ "image/x-ms-bmp"
4589
+ ]), n = (this.options.maxImageSize || 5) * 1024 * 1024;
4590
+ e.forEach((e) => {
4591
+ if (!e?.type?.startsWith("image/")) return;
4592
+ if (t.has(e.type)) {
4593
+ let t = `Image format "${e.type}" is not supported for display in web browsers. Please convert to PNG, JPEG, or WebP first.`;
4594
+ this.context.triggerEvent("imageError", {
4595
+ file: e,
4596
+ message: t
4597
+ }), console.warn("[AutumnNote]", t);
4598
+ return;
4516
4599
  }
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
- });
4600
+ if (e.size > n) {
4601
+ let t = `Image "${e.name}" exceeds the ${this.options.maxImageSize || 5} MB size limit.`;
4602
+ this.context.triggerEvent("imageError", {
4603
+ file: e,
4604
+ message: t
4605
+ }), console.warn(`[AutumnNote] ${t}`);
4606
+ return;
4529
4607
  }
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],
4608
+ let r = e.name.replace(/\.[^.]+$/, "");
4609
+ this.compressAndRegister(e).then((e) => {
4610
+ this.context.invoke("editor.insertImage", e, r);
4611
+ }).catch((t) => {
4612
+ let n = `Image "${e.name}" could not be processed.`;
4613
+ this.context.triggerEvent("imageError", {
4614
+ file: e,
4534
4615
  message: n,
4535
4616
  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 });
4617
+ }), console.warn("[AutumnNote]", n, t);
4618
+ });
4619
+ });
4620
+ }
4621
+ _escapeAttr(e) {
4622
+ return String(e).replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
4623
+ }
4624
+ async _runUploadHandler(e) {
4625
+ let t = {
4626
+ context: this.context,
4627
+ setProgress: (e, t) => this._setUploadProgress(e, t)
4628
+ }, n;
4629
+ try {
4630
+ n = this.options.onImageUpload(e, t);
4631
+ } catch (t) {
4632
+ this._reportUploadError(e, t);
4633
+ return;
4634
+ }
4635
+ if (n === void 0) return;
4636
+ let r = e.map((e) => this._insertUploadPlaceholder(e)), i;
4637
+ try {
4638
+ i = await n;
4639
+ } catch (t) {
4640
+ r.forEach((n, r) => this._failUpload(n, e[r], t));
4641
+ return;
4642
+ }
4643
+ let a = Array.isArray(i) ? i : [i];
4644
+ r.forEach((t, n) => {
4645
+ let r = a[n];
4646
+ typeof r == "string" && r ? this._resolveUpload(t, r) : this._failUpload(t, e[n], /* @__PURE__ */ Error("No URL returned for this file."));
4647
+ });
4648
+ }
4649
+ _insertUploadPlaceholder(e) {
4650
+ let t = `an-up-${Date.now().toString(36)}-${this._uploadSeq = (this._uploadSeq || 0) + 1}`, n = URL.createObjectURL(e);
4651
+ this._uploadPreviews = this._uploadPreviews || /* @__PURE__ */ new Map(), this._uploadPreviews.set(t, {
4652
+ previewUrl: n,
4653
+ file: e
4654
+ });
4655
+ let r = this._escapeAttr(e.name.replace(/\.[^.]+$/, ""));
4656
+ return T("insertHTML", `<img src="${this._escapeAttr(n)}" alt="${r}" class="an-image an-image-uploading" data-an-upload="${t}">`), this.context.invoke("editor.afterCommand"), t;
4657
+ }
4658
+ _findPlaceholder(e) {
4659
+ return this.context.layoutInfo.editable?.querySelector(`img[data-an-upload="${e}"]`) ?? null;
4660
+ }
4661
+ _resolveUpload(e, t) {
4662
+ let n = this._findPlaceholder(e), r = this._uploadPreviews?.get(e);
4663
+ if (n) {
4664
+ let i = N(t, { allowData: !0 });
4665
+ if (i) n.setAttribute("src", i), n.classList.remove("an-image-uploading"), n.removeAttribute("data-an-upload"), n.style.removeProperty("--an-upload-progress");
4666
+ else {
4667
+ this._failUpload(e, r?.file, /* @__PURE__ */ Error(`Rejected image URL: ${t}`));
4668
+ return;
4559
4669
  }
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
- });
4670
+ }
4671
+ r && (URL.revokeObjectURL(r.previewUrl), this._uploadPreviews.delete(e)), this.context.invoke("editor.afterCommand");
4672
+ }
4673
+ _failUpload(e, t, n) {
4674
+ let r = this._findPlaceholder(e);
4675
+ r && (r.classList.remove("an-image-uploading"), r.classList.add("an-image-failed"), r.style.removeProperty("--an-upload-progress"));
4676
+ let i = `Image "${t?.name ?? "unknown"}" could not be uploaded.`;
4677
+ console.warn("[AutumnNote]", i, n), this.context.triggerEvent("imageError", {
4678
+ file: t,
4679
+ message: i,
4680
+ error: n,
4681
+ retry: () => {
4682
+ r?.remove(), this._uploadPreviews?.delete(e), t && this._runUploadHandler([t]);
4585
4683
  }
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));
4684
+ });
4685
+ }
4686
+ _reportUploadError(e, t) {
4687
+ let n = "The image upload handler threw before any file was sent.";
4688
+ console.warn("[AutumnNote]", n, t), this.context.triggerEvent("imageError", {
4689
+ file: e[0],
4690
+ message: n,
4691
+ error: t
4692
+ });
4693
+ }
4694
+ _setUploadProgress(e, t) {
4695
+ if (!this._uploadPreviews) return;
4696
+ let n = Math.max(0, Math.min(1, Number(t) || 0));
4697
+ for (let [t, r] of this._uploadPreviews) {
4698
+ if (r.file !== e) continue;
4699
+ let i = this._findPlaceholder(t);
4700
+ i && i.style.setProperty("--an-upload-progress", String(n));
4701
+ return;
4702
+ }
4703
+ }
4704
+ async compressAndRegister(e) {
4705
+ 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);
4706
+ return this._blobRegistry.set(i, n), i;
4707
+ }
4708
+ resolveImages(e) {
4709
+ return this._blobRegistry?.size ? e.replace(/blob:[^"'> \t\n\r]*/g, (e) => this._blobRegistry.get(e) || e) : e;
4710
+ }
4711
+ _dataUrlToBlob(e) {
4712
+ let [t, n] = e.split(","), r = /:(.*?);/.exec(t)?.[1] ?? "image/png", i = atob(n), a = new Uint8Array(i.length);
4713
+ for (let e = 0; e < i.length; e++) a[e] = i.charCodeAt(e);
4714
+ return new Blob([a], { type: r });
4715
+ }
4716
+ _compressImage(e) {
4717
+ let t = 1920, n = .85;
4718
+ return new Promise((r, i) => {
4719
+ let a = URL.createObjectURL(e), o = new Image();
4720
+ o.onload = () => {
4721
+ URL.revokeObjectURL(a);
4722
+ let { width: s, height: c } = o;
4723
+ (s > t || c > t) && (s >= c ? (c = Math.round(c * t / s), s = t) : (s = Math.round(s * t / c), c = t));
4724
+ let l = document.createElement("canvas");
4725
+ l.width = s, l.height = c;
4726
+ let u = l.getContext("2d");
4727
+ if (!u) {
4728
+ let t = new FileReader();
4729
+ t.onload = (e) => r(e.target.result), t.onerror = () => i(/* @__PURE__ */ Error("FileReader failed")), t.readAsDataURL(e);
4730
+ return;
4592
4731
  }
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
- }
4732
+ u.drawImage(o, 0, 0, s, c);
4733
+ let d = l.toDataURL("image/webp", n);
4734
+ r(d.startsWith("data:image/webp") ? d : l.toDataURL("image/jpeg", n));
4735
+ }, o.onerror = () => {
4736
+ URL.revokeObjectURL(a);
4737
+ let t = new FileReader();
4738
+ t.onload = (e) => r(e.target.result), t.onerror = () => i(/* @__PURE__ */ Error("FileReader failed")), t.readAsDataURL(e);
4739
+ }, o.src = a;
4740
+ });
4741
+ }
4742
+ _placeCaretAtPoint(e, t) {
4743
+ let n;
4744
+ if (document.caretRangeFromPoint) n = document.caretRangeFromPoint(e, t);
4745
+ else if (document.caretPositionFromPoint) {
4746
+ let r = document.caretPositionFromPoint(e, t);
4747
+ r && (n = document.createRange(), n.setStart(r.offsetNode, r.offset), n.collapse(!0));
4600
4748
  }
4749
+ if (!n) return;
4750
+ let r = globalThis.getSelection();
4751
+ r && (r.removeAllRanges(), r.addRange(n));
4752
+ }
4753
+ _escapeHTML(e) {
4754
+ return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&#039;");
4755
+ }
4756
+ }, Yr = /[^\s\u200B]/;
4757
+ function Xr(e) {
4758
+ let t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
4759
+ for (let e = t.nextNode(); e; e = t.nextNode()) if (Yr.test(e.data)) return !0;
4760
+ return !1;
4761
+ }
4762
+ //#endregion
4763
+ //#region src/js/presets/core.js
4764
+ var Zr = [
4765
+ {
4766
+ name: "editor",
4767
+ Class: Vr
4768
+ },
4769
+ {
4770
+ name: "toolbar",
4771
+ Class: Gr
4772
+ },
4773
+ {
4774
+ name: "statusbar",
4775
+ Class: qr
4776
+ },
4777
+ {
4778
+ name: "clipboard",
4779
+ Class: Jr
4601
4780
  },
4602
4781
  {
4603
4782
  name: "placeholder",
@@ -4608,54 +4787,54 @@ var Mr = [
4608
4787
  initialize() {
4609
4788
  let e = this.context.layoutInfo.editable, t = this.options.placeholder || "";
4610
4789
  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);
4790
+ let n = () => this._update(), r = C(e, "input", n), i = C(e, "focus", n), a = C(e, "blur", n);
4612
4791
  return this._disposers.push(r, i, a), this._update(), this;
4613
4792
  }
4614
4793
  destroy() {
4615
4794
  this._disposers.forEach((e) => e()), this._disposers = [];
4616
4795
  }
4617
4796
  _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");
4797
+ let e = this.context.layoutInfo.editable, t = document.activeElement === e, n = !Xr(e) && !e.querySelector("img, table, hr, .an-video-wrapper");
4619
4798
  e.classList.toggle("an-placeholder", n && !t);
4620
4799
  }
4621
4800
  }
4622
4801
  }
4623
- ];
4802
+ ], Qr = "2.7.0";
4624
4803
  //#endregion
4625
4804
  //#region src/js/core/lists.js
4626
- function Nr(e) {
4805
+ function $r(e) {
4627
4806
  return e[e.length - 1];
4628
4807
  }
4629
- function Pr(e) {
4808
+ function ei(e) {
4630
4809
  return e[0];
4631
4810
  }
4632
- function Fr(e, t = 1) {
4811
+ function ti(e, t = 1) {
4633
4812
  return e.slice(0, e.length - t);
4634
4813
  }
4635
- function Ir(e, t = 1) {
4814
+ function ni(e, t = 1) {
4636
4815
  return e.slice(t);
4637
4816
  }
4638
- function Lr(e) {
4817
+ function ri(e) {
4639
4818
  return e.flat();
4640
4819
  }
4641
- function Rr(e) {
4820
+ function ii(e) {
4642
4821
  return [...new Set(e)];
4643
4822
  }
4644
- function zr(e, t) {
4823
+ function ai(e, t) {
4645
4824
  let n = [];
4646
4825
  for (let r = 0; r < e.length; r += t) n.push(e.slice(r, r + t));
4647
4826
  return n;
4648
4827
  }
4649
- function Br(e, t) {
4828
+ function oi(e, t) {
4650
4829
  return e.reduce((e, n) => {
4651
4830
  let r = t(n);
4652
4831
  return e[r] || (e[r] = []), e[r].push(n), e;
4653
4832
  }, {});
4654
4833
  }
4655
- function Vr(e, t) {
4834
+ function si(e, t) {
4656
4835
  return e.every(t);
4657
4836
  }
4658
- function Hr(e, t) {
4837
+ function ci(e, t) {
4659
4838
  return e.some(t);
4660
4839
  }
4661
4840
  //#endregion
@@ -4663,7 +4842,7 @@ function Hr(e, t) {
4663
4842
  function Q() {
4664
4843
  return globalThis.navigator?.userAgent ?? "";
4665
4844
  }
4666
- var Ur = {
4845
+ var li = {
4667
4846
  get isChrome() {
4668
4847
  return /Chrome\//.test(Q()) && !/Edg\//.test(Q());
4669
4848
  },
@@ -4688,17 +4867,19 @@ var Ur = {
4688
4867
  get modifierKey() {
4689
4868
  return /Macintosh/.test(Q()) ? "metaKey" : "ctrlKey";
4690
4869
  }
4691
- }, Wr = { ...k }, $ = /* @__PURE__ */ new WeakMap(), Gr = {
4870
+ }, ui = { ...A }, $ = /* @__PURE__ */ new WeakMap(), di = {
4692
4871
  create(e, t = {}) {
4693
- let n = Kr(e).map((e) => {
4872
+ let n = fi(e).map((e) => {
4694
4873
  if ($.has(e)) return $.get(e);
4695
- let n = new Sn(e, t);
4696
- return n.initialize(), $.set(e, n), n;
4874
+ let n = new En(e, t);
4875
+ return n._releaseInstance = () => {
4876
+ $.get(e) === n && $.delete(e);
4877
+ }, n.initialize(), $.set(e, n), n;
4697
4878
  });
4698
4879
  return n.length === 1 ? n[0] : n;
4699
4880
  },
4700
4881
  destroy(e) {
4701
- Kr(e).forEach((e) => {
4882
+ fi(e).forEach((e) => {
4702
4883
  let t = $.get(e);
4703
4884
  t && (t.destroy(), $.delete(e));
4704
4885
  });
@@ -4708,48 +4889,48 @@ var Ur = {
4708
4889
  return t && $.get(t) || null;
4709
4890
  },
4710
4891
  get defaults() {
4711
- return { ...k };
4892
+ return { ...A };
4712
4893
  },
4713
4894
  setDefaults(e) {
4714
- Object.assign(k, e);
4895
+ Object.assign(A, e);
4715
4896
  },
4716
4897
  resetDefaults() {
4717
- Object.keys(k).forEach((e) => delete k[e]), Object.assign(k, Wr);
4898
+ Object.keys(A).forEach((e) => delete A[e]), Object.assign(A, ui);
4718
4899
  },
4719
4900
  registerModule(e, t) {
4720
- yn.set(e, t);
4901
+ Cn.set(e, t);
4721
4902
  },
4722
4903
  use(e, t = {}) {
4723
4904
  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, {
4905
+ return P.has(e.name) ? (console.warn(`[AutumnNote] Plugin "${e.name}" already registered globally. Skipping.`), this) : (Array.isArray(e.buttons) && e.buttons.forEach((e) => k(e)), P.set(e.name, {
4725
4906
  plugin: e,
4726
4907
  options: t
4727
4908
  }), this);
4728
4909
  },
4729
4910
  hasPlugin(e) {
4730
- return N.has(e);
4911
+ return P.has(e);
4731
4912
  },
4732
4913
  registerButton(e) {
4733
- return O(e), this;
4914
+ return k(e), this;
4734
4915
  },
4735
4916
  registerLocale(e, t) {
4736
- return $t(e, t), this;
4917
+ return nn(e, t), this;
4737
4918
  },
4738
4919
  registerSlashCommand(e) {
4739
4920
  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);
4921
+ let t = A.slashCommands, n = t.findIndex((t) => t.id === e.id);
4741
4922
  return n >= 0 ? t[n] = e : t.push(e), this;
4742
4923
  },
4743
- buttons: Zt,
4744
- version: "2.5.0"
4924
+ buttons: en,
4925
+ version: Qr
4745
4926
  };
4746
- function Kr(e) {
4927
+ function fi(e) {
4747
4928
  return typeof e == "string" ? Array.from(document.querySelectorAll(e)) : e instanceof Element ? [e] : e instanceof NodeList || Array.isArray(e) ? Array.from(e) : [];
4748
4929
  }
4749
4930
  //#endregion
4750
4931
  //#region src/js/core.js
4751
- xn(Mr);
4932
+ Tn(Zr);
4752
4933
  //#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 };
4934
+ export { En as Context, d as ELEMENT_NODE, Fr as SUPPORTED_LANGS, f as TEXT_NODE, w as WrappedRange, O as _buttonRegistry, xt as alignCenterBtn, Ct as alignJustifyBtn, bt as alignLeftBtn, St as alignRightBtn, si as all, ae as ancestors, ci as any, Qt as backColorBtn, mt as boldBtn, en as buttons, Yt as checklistBtn, oe as children, ai as chunk, e as clamp, y as closest, b as closestPara, Ut as codeviewBtn, Ce as collapsedRange, r as compose, x as createElement, xe as currentRange, t as debounce, di as default, A as defaultOptions, $t as defaultToolbar, zr as detectLang, zt as directionBtn, Pt as emojiBtn, li as env, Kt as findBtn, qt as findReplaceBtn, ei as first, ri as flatten, Bt as fontFamilyBtn, Lt as fontSizeBtn, Zt as foreColorBtn, be as fromNativeRange, Wt as fullscreenBtn, pt as getButton, oi as groupBy, At as hrBtn, Hn as htmlToMarkdown, Ft as iconBtn, i as identity, Mt as imageBtn, Et as indentBtn, ti as initial, Jt as inlineCodeBtn, de as insertAfter, re as isAnchor, v as isEditable, p as isElement, pe as isEmpty, s as isFunction, ie as isImage, _ as isInline, _e as isInsideEditable, I as isKey, ee as isLi, te as isList, Zn as isMarkdown, L 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, ht as italicBtn, F as key, $r as last, Ht as lineHeightBtn, jt as linkBtn, tn as locales, ye as makeDraggable, rr as markdownToHTML, c as mergeDeep, ce as nextElement, fe as nodeValue, Tt as olBtn, C as on, Dt as outdentBtn, me as outerHtml, Vt as paragraphStyleBtn, he as placeCaret, se as prevElement, Xt as printBtn, Se as rangeFromElement, u as rect2bnd, kt as redoBtn, k as registerButton, nn as registerLocale, S as remove, Rt as removeFormatBtn, ge as repairListNesting, rn as resolveLocale, M as sanitiseHTML, _n as sanitiseToBody, N as sanitiseUrl, Gt as shortcutsBtn, Ee as splitText, _t as strikeBtn, yt as subscriptBtn, vt as superscriptBtn, It as tableBtn, ni as tail, n as throttle, ve as trapFocus, wt as ulBtn, gt as underlineBtn, Ot as undoBtn, ii as unique, le as unwrap, Nt as videoBtn, Te as withSavedRange, ue as wrap };
4754
4935
 
4755
4936
  //# sourceMappingURL=autumnnote.core.es.js.map