autumnnote 2.6.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.
@@ -122,12 +122,22 @@ function he(e) {
122
122
  n && (n.removeAllRanges(), n.addRange(t));
123
123
  }
124
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
+ }
134
+ function _e(e) {
125
135
  return !!y(e, v);
126
136
  }
127
137
  function C(e, t, n, r) {
128
138
  return e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r);
129
139
  }
130
- function _e(e, t) {
140
+ function ve(e, t) {
131
141
  let n = () => Array.from(e.querySelectorAll("a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])")).filter((e) => !e.closest("[style*=\"display: none\"]") && !e.closest("[style*=\"display:none\"]")), r = (e) => {
132
142
  if (e.key === "Escape") {
133
143
  e.stopPropagation(), t?.();
@@ -141,7 +151,7 @@ function _e(e, t) {
141
151
  };
142
152
  return document.addEventListener("keydown", r), () => document.removeEventListener("keydown", r);
143
153
  }
144
- function ve(e, t) {
154
+ function ye(e, t) {
145
155
  e.style.cursor = "grab";
146
156
  let n = (n) => {
147
157
  if (n.button !== 0 || n.target.closest("button, input, select, textarea, a")) return;
@@ -163,7 +173,7 @@ function ve(e, t) {
163
173
  }
164
174
  //#endregion
165
175
  //#region src/js/core/range.js
166
- var ye = 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 ye = class {
200
210
  }
201
211
  };
202
212
  function be(e) {
203
- return new ye(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 ye(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 ye(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,31 +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, t) {
1463
- return mn(e, t).innerHTML;
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;
1464
1511
  }
1465
- function mn(e, { allowIframes: t = !1 } = {}) {
1466
- let n = new DOMParser().parseFromString(`<body>${e || ""}</body>`, "text/html"), r = Array.from(n.querySelectorAll("*")), i = new Set(t ? tn.filter((e) => e !== "iframe") : tn);
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);
1467
1514
  for (let e of r) {
1468
1515
  let t = e.tagName.toLowerCase();
1469
- if (nn.has(t)) {
1516
+ if (on.has(t)) {
1470
1517
  e.replaceWith(...e.childNodes);
1471
1518
  continue;
1472
1519
  }
@@ -1476,7 +1523,7 @@ function mn(e, { allowIframes: t = !1 } = {}) {
1476
1523
  }
1477
1524
  if (t === "iframe") {
1478
1525
  let t = e.getAttribute("src");
1479
- if (!t || !_n(t)) {
1526
+ if (!t || !bn(t)) {
1480
1527
  e.remove();
1481
1528
  continue;
1482
1529
  }
@@ -1487,22 +1534,22 @@ function mn(e, { allowIframes: t = !1 } = {}) {
1487
1534
  continue;
1488
1535
  }
1489
1536
  if (t.name === "style") {
1490
- let n = hn(t.value);
1537
+ let n = vn(t.value);
1491
1538
  n ? e.setAttribute("style", n) : e.removeAttribute("style");
1492
1539
  continue;
1493
1540
  }
1494
- if (on.has(t.name)) {
1541
+ if (ln.has(t.name)) {
1495
1542
  e.removeAttribute(t.name);
1496
1543
  continue;
1497
1544
  }
1498
- if (rn.includes(t.name)) {
1499
- 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" && [
1500
1547
  "IMG",
1501
1548
  "VIDEO",
1502
1549
  "AUDIO",
1503
1550
  "SOURCE"
1504
1551
  ].includes(e.tagName), i = e.tagName === "IMG";
1505
- if (!(t.name === "srcset" ? gn(n, { allowData: i }) : vn(n, {
1552
+ if (!(t.name === "srcset" ? yn(n, { allowData: i }) : xn(n, {
1506
1553
  media: r,
1507
1554
  allowData: i
1508
1555
  }))) {
@@ -1515,7 +1562,7 @@ function mn(e, { allowIframes: t = !1 } = {}) {
1515
1562
  e.removeAttribute(t.name);
1516
1563
  continue;
1517
1564
  }
1518
- t.name === "src" && !_n(t.value) && e.removeAttribute(t.name);
1565
+ t.name === "src" && !bn(t.value) && e.removeAttribute(t.name);
1519
1566
  }
1520
1567
  }
1521
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();
@@ -1527,58 +1574,58 @@ function mn(e, { allowIframes: t = !1 } = {}) {
1527
1574
  }
1528
1575
  return n.body;
1529
1576
  }
1530
- function hn(e) {
1577
+ function vn(e) {
1531
1578
  let t = [];
1532
1579
  for (let n of (e || "").split(";")) {
1533
1580
  let e = n.indexOf(":");
1534
1581
  if (e === -1) continue;
1535
1582
  let r = n.slice(0, e).trim().toLowerCase(), i = n.slice(e + 1).trim();
1536
- !r || !i || sn.has(r) && (cn.test(i) || t.push(`${r}: ${i}`));
1583
+ !r || !i || un.has(r) && (dn.test(i) || t.push(`${r}: ${i}`));
1537
1584
  }
1538
1585
  return t.join("; ");
1539
1586
  }
1540
- function gn(e, { allowData: t = !1 } = {}) {
1587
+ function yn(e, { allowData: t = !1 } = {}) {
1541
1588
  let n = (e || "").trim().split(/\s+/).filter(Boolean);
1542
1589
  for (let e of n) {
1543
1590
  if (/^[\d.]+[xw],?$/i.test(e)) continue;
1544
1591
  let n = e.replace(/,+$/, "");
1545
- if (n && !vn(n, {
1592
+ if (n && !xn(n, {
1546
1593
  media: !0,
1547
1594
  allowData: t
1548
1595
  })) return !1;
1549
1596
  }
1550
1597
  return !0;
1551
1598
  }
1552
- function _n(e) {
1599
+ function bn(e) {
1553
1600
  let t = (e || "").trim();
1554
1601
  if (!t || t.startsWith("//") || t.startsWith("/")) return !1;
1555
1602
  try {
1556
1603
  let e = new URL(t);
1557
- return e.protocol === "https:" && ln.has(e.hostname.toLowerCase());
1604
+ return e.protocol === "https:" && fn.has(e.hostname.toLowerCase());
1558
1605
  } catch {
1559
1606
  return !1;
1560
1607
  }
1561
1608
  }
1562
- function M(e, { allowData: t = !1, media: n = t } = {}) {
1609
+ function N(e, { allowData: t = !1, media: n = t } = {}) {
1563
1610
  let r = (e || "").trim();
1564
- return !r && e == null ? null : vn(r, {
1611
+ return !r && e == null ? null : xn(r, {
1565
1612
  media: n,
1566
1613
  allowData: t
1567
1614
  }) ? e : null;
1568
1615
  }
1569
- function vn(e, { media: t = !1, allowData: n = !1 } = {}) {
1616
+ function xn(e, { media: t = !1, allowData: n = !1 } = {}) {
1570
1617
  let r = (e || "").trim();
1571
- if (!r || n && fn.test(r)) return !0;
1618
+ if (!r || n && hn.test(r)) return !0;
1572
1619
  try {
1573
- let e = new URL(r, pn);
1574
- return (t ? dn : un).has(e.protocol);
1620
+ let e = new URL(r, gn);
1621
+ return (t ? mn : pn).has(e.protocol);
1575
1622
  } catch {
1576
1623
  return !1;
1577
1624
  }
1578
1625
  }
1579
1626
  //#endregion
1580
1627
  //#region src/js/renderer.js
1581
- function yn(e, t) {
1628
+ function Sn(e, t) {
1582
1629
  let n = x("div", { class: "an-container" }), r = x("div", {
1583
1630
  class: "an-editable",
1584
1631
  contenteditable: t.readOnly ? "false" : "true",
@@ -1590,7 +1637,7 @@ function yn(e, t) {
1590
1637
  if (t.autoSave && t.autoSaveKey) try {
1591
1638
  i = localStorage.getItem(t.autoSaveKey) || "";
1592
1639
  } catch {}
1593
- 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 });
1594
1641
  let a = t.defaultFontFamily || t.fontFamilies?.[0];
1595
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) => {
1596
1643
  e.setAttribute("disabled", "");
@@ -1601,16 +1648,16 @@ function yn(e, t) {
1601
1648
  }
1602
1649
  //#endregion
1603
1650
  //#region src/js/Context.js
1604
- var bn = /* @__PURE__ */ new Map(), xn = [];
1605
- function Sn(e) {
1606
- xn = Array.isArray(e) ? e : [];
1651
+ var Cn = /* @__PURE__ */ new Map(), wn = [];
1652
+ function Tn(e) {
1653
+ wn = Array.isArray(e) ? e : [];
1607
1654
  }
1608
- var N = /* @__PURE__ */ new Map(), Cn = class {
1655
+ var P = /* @__PURE__ */ new Map(), En = class {
1609
1656
  constructor(e, t = {}) {
1610
- this.targetEl = e, this.options = c(k, t), this.locale = en(this.options.lang), this.layoutInfo = {}, this._listeners = /* @__PURE__ */ new Map(), this._modules = /* @__PURE__ */ new Map(), this._plugins = /* @__PURE__ */ new Map(), this._disposers = [], this._alive = !1, this._autoSaveTimer = null, this._pendingAutoSave = null, this._suppressedRemoteHTML = null, this._destroyPromise = null;
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;
1611
1658
  }
1612
1659
  initialize() {
1613
- let { container: e, editable: t } = yn(this.targetEl, this.options);
1660
+ let { container: e, editable: t } = Sn(this.targetEl, this.options);
1614
1661
  this.layoutInfo.container = e, this.layoutInfo.editable = t, this._registerModules();
1615
1662
  let n = this._modules.get("toolbar");
1616
1663
  n?.el && (e.insertBefore(n.el, t), this.layoutInfo.toolbar = n.el);
@@ -1622,11 +1669,11 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
1622
1669
  let n = new t(this);
1623
1670
  this._modules.set(e, n), n.initialize();
1624
1671
  };
1625
- for (let { name: t, Class: n, enabled: r } of xn) typeof r == "function" && !r(this.options) || e(t, n);
1626
- if (bn.size > 0) for (let [t, n] of bn) e(t, n);
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);
1627
1674
  }
1628
1675
  _syncOptionalModules() {
1629
- for (let { name: e, Class: t, enabled: n } of xn) {
1676
+ for (let { name: e, Class: t, enabled: n } of wn) {
1630
1677
  if (typeof n != "function") continue;
1631
1678
  let r = n(this.options);
1632
1679
  if (r !== this._modules.has(e)) if (r) {
@@ -1649,7 +1696,7 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
1649
1696
  return n >= 0 ? t[n] = e : t.push(e), this.invoke("slashMenu.refresh"), this;
1650
1697
  }
1651
1698
  use(e, t = {}) {
1652
- 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;
1653
1700
  }
1654
1701
  getPlugin(e) {
1655
1702
  return this._plugins.get(e)?.publicApi ?? null;
@@ -1671,7 +1718,7 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
1671
1718
  });
1672
1719
  }
1673
1720
  _applyGlobalPlugins() {
1674
- 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);
1675
1722
  }
1676
1723
  _bindEditorEvents(e) {
1677
1724
  let t = C(e, "input", () => this._syncToTarget()), n = C(e, "focus", () => {
@@ -1917,14 +1964,22 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
1917
1964
  } catch {}
1918
1965
  this._plugins.clear(), this._disposers.forEach((e) => e()), this._disposers = [];
1919
1966
  let t = this.layoutInfo.container, n = t?.classList.contains("an-theme-dark"), r = t?.classList.contains("an-theme-auto");
1920
- return t?.parentNode && (this.targetEl.style.display = "", t.remove()), n && !document.querySelector(".an-container.an-theme-dark") && document.body.classList.remove("an-theme-dark"), r && !document.querySelector(".an-container.an-theme-auto") && document.body.classList.remove("an-theme-auto"), typeof this.options.onDestroy == "function" && this.options.onDestroy(this), this._alive = !1, this._destroyPromise = Promise.resolve(e).then(() => {
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(() => {
1921
1968
  this._listeners.clear();
1922
1969
  }), this._destroyPromise;
1923
1970
  }
1924
1971
  _syncToTarget(e) {
1925
1972
  (this.targetEl.tagName === "TEXTAREA" || this.targetEl.tagName === "INPUT") && (this.targetEl.value = typeof e == "string" ? e : this.getHTML());
1926
1973
  }
1927
- }, wn = 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 {
1928
1983
  constructor(e, t = 100, n = 10 * 1024 * 1024) {
1929
1984
  this.editable = e, this._limit = t, this._maxBytes = n, this._bytes = 0, this.stack = [], this.stackOffset = -1, this._savePoint();
1930
1985
  }
@@ -1946,12 +2001,12 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
1946
2001
  } : null;
1947
2002
  }
1948
2003
  _charOffset(e, t) {
1949
- let n = 0, r = document.createTreeWalker(this.editable, NodeFilter.SHOW_TEXT, null), i;
1950
- for (; i = r.nextNode();) {
1951
- if (i === e) return n + t;
1952
- n += i.length;
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;
1953
2009
  }
1954
- return 0;
1955
2010
  }
1956
2011
  _restoreSelection(e) {
1957
2012
  if (!e) return;
@@ -1998,7 +2053,18 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
1998
2053
  this.stackOffset = this.stack.length - 1;
1999
2054
  }
2000
2055
  _restore(e) {
2001
- 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);
2002
2068
  }
2003
2069
  _tokenizeImages(e) {
2004
2070
  if (!e.includes("data:")) return {
@@ -2045,7 +2111,7 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
2045
2111
  };
2046
2112
  //#endregion
2047
2113
  //#region src/js/editing/Table.js
2048
- function Tn(e, t, n = {}) {
2114
+ function kn(e, t, n = {}) {
2049
2115
  let { headerRow: r = !1 } = n, i = x("table", { class: "an-table" });
2050
2116
  if (r && t > 0) {
2051
2117
  let t = x("thead"), n = x("tr");
@@ -2067,9 +2133,9 @@ function Tn(e, t, n = {}) {
2067
2133
  }
2068
2134
  return i;
2069
2135
  }
2070
- function En(e, t, n = {}) {
2136
+ function An(e, t, n = {}) {
2071
2137
  if (e <= 0 || t <= 0) return;
2072
- let r = Tn(e, t, n), i = globalThis.getSelection();
2138
+ let r = kn(e, t, n), i = globalThis.getSelection();
2073
2139
  if (!i || i.rangeCount === 0) return;
2074
2140
  let a = i.getRangeAt(0);
2075
2141
  try {
@@ -2110,7 +2176,7 @@ function En(e, t, n = {}) {
2110
2176
  }
2111
2177
  //#endregion
2112
2178
  //#region src/js/core/key.js
2113
- var P = {
2179
+ var F = {
2114
2180
  BACKSPACE: "Backspace",
2115
2181
  TAB: "Tab",
2116
2182
  ENTER: "Enter",
@@ -2149,16 +2215,36 @@ var P = {
2149
2215
  SLASH: "/",
2150
2216
  PERIOD: "."
2151
2217
  };
2152
- function F(e, t) {
2218
+ function I(e, t) {
2153
2219
  return e.key === t || e.key === t.toUpperCase();
2154
2220
  }
2155
- function I(e, t) {
2156
- return (e.ctrlKey || e.metaKey) && F(e, t);
2221
+ function L(e, t) {
2222
+ return (e.ctrlKey || e.metaKey) && I(e, t);
2157
2223
  }
2158
2224
  //#endregion
2159
2225
  //#region src/js/editing/Typing.js
2160
- var Dn = /\bfa-/, L = (e) => !!(e?.nodeName === "I" && Dn.test(e.className || "")), R = (e) => e?.nodeType === Node.TEXT_NODE && (e.textContent === "​" || e.textContent === "");
2161
- function On(e, t) {
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) {
2162
2248
  try {
2163
2249
  let n = document.createRange();
2164
2250
  return n.setStart(e.startContainer, e.startOffset), n.setEnd(t, t.childNodes.length), n.extractContents();
@@ -2166,21 +2252,21 @@ function On(e, t) {
2166
2252
  return document.createDocumentFragment();
2167
2253
  }
2168
2254
  }
2169
- function kn(e, t, n = {}) {
2255
+ function Fn(e, t, n = {}) {
2170
2256
  let r = (e) => {
2171
2257
  let t = globalThis.getSelection();
2172
2258
  if (!t) return !1;
2173
2259
  let n = document.createRange();
2174
2260
  return e(n), n.collapse(!0), t.removeAllRanges(), t.addRange(n), !0;
2175
2261
  };
2176
- if (F(e, P.BACKSPACE)) {
2262
+ if (I(e, F.BACKSPACE)) {
2177
2263
  let t = globalThis.getSelection();
2178
2264
  if (t?.rangeCount > 0) {
2179
2265
  let n = t.getRangeAt(0);
2180
2266
  if (n.collapsed && n.startContainer.nodeType === Node.TEXT_NODE) {
2181
2267
  let r = n.startContainer;
2182
- if (n.startOffset === 0 && L(r.previousSibling)) return e.preventDefault(), r.previousSibling.remove(), !0;
2183
- if (n.startOffset === 1 && r.textContent === "​" && L(r.previousSibling)) {
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)) {
2184
2270
  e.preventDefault();
2185
2271
  let n = r.parentNode, i = r.previousSibling, a = i.previousSibling;
2186
2272
  i.remove(), r.remove();
@@ -2191,17 +2277,17 @@ function kn(e, t, n = {}) {
2191
2277
  }
2192
2278
  return !1;
2193
2279
  }
2194
- if (F(e, P.LEFT) || F(e, P.RIGHT)) {
2280
+ if (I(e, F.LEFT) || I(e, F.RIGHT)) {
2195
2281
  let t = globalThis.getSelection();
2196
2282
  if (!t || t.rangeCount === 0) return !1;
2197
2283
  let n = t.getRangeAt(0);
2198
2284
  if (!n.collapsed) return !1;
2199
- let i = n.startContainer, a = F(e, P.LEFT);
2285
+ let i = n.startContainer, a = I(e, F.LEFT);
2200
2286
  if (i.nodeType === Node.TEXT_NODE) {
2201
2287
  let t = i;
2202
- if (a && n.startOffset === 1 && t.textContent === "​" && L(t.previousSibling) || a && n.startOffset === 0 && L(t.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(t.previousSibling));
2203
- if (a && n.startOffset === 0 && R(t.previousSibling) && L(t.previousSibling.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(t.previousSibling.previousSibling));
2204
- if (!a && n.startOffset === t.textContent.length && L(t.nextSibling)) {
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)) {
2205
2291
  let n = t.nextSibling, i = n.nextSibling;
2206
2292
  if (e.preventDefault(), i?.nodeType === Node.TEXT_NODE) {
2207
2293
  let e = +!!(i.textContent || "").startsWith("​");
@@ -2209,7 +2295,7 @@ function kn(e, t, n = {}) {
2209
2295
  }
2210
2296
  return r((e) => e.setStartAfter(n));
2211
2297
  }
2212
- 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)) {
2213
2299
  let n = t.nextSibling.nextSibling, i = n.nextSibling;
2214
2300
  if (e.preventDefault(), i?.nodeType === Node.TEXT_NODE) {
2215
2301
  let e = +!!(i.textContent || "").startsWith("​");
@@ -2222,12 +2308,12 @@ function kn(e, t, n = {}) {
2222
2308
  let t = i;
2223
2309
  if (a && n.startOffset > 0) {
2224
2310
  let i = t.childNodes[n.startOffset - 1];
2225
- if (L(i)) return e.preventDefault(), r((e) => e.setStartBefore(i));
2226
- if (R(i) && L(i.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(i.previousSibling));
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));
2227
2313
  }
2228
2314
  if (!a && n.startOffset < t.childNodes.length) {
2229
2315
  let i = t.childNodes[n.startOffset];
2230
- if (L(i)) {
2316
+ if (R(i)) {
2231
2317
  let t = i.nextSibling;
2232
2318
  if (e.preventDefault(), t?.nodeType === Node.TEXT_NODE) {
2233
2319
  let e = +!!(t.textContent || "").startsWith("​");
@@ -2235,7 +2321,7 @@ function kn(e, t, n = {}) {
2235
2321
  }
2236
2322
  return r((e) => e.setStartAfter(i));
2237
2323
  }
2238
- if (R(i) && L(i.nextSibling)) {
2324
+ if (z(i) && R(i.nextSibling)) {
2239
2325
  let t = i.nextSibling, n = t.nextSibling;
2240
2326
  if (e.preventDefault(), n?.nodeType === Node.TEXT_NODE) {
2241
2327
  let e = +!!(n.textContent || "").startsWith("​");
@@ -2246,16 +2332,17 @@ function kn(e, t, n = {}) {
2246
2332
  }
2247
2333
  }
2248
2334
  }
2249
- if (F(e, P.TAB)) {
2335
+ if (I(e, F.TAB)) {
2250
2336
  let r = xe(t);
2251
2337
  if (!r) return !1;
2338
+ if (Mn(r.sc, t, e.shiftKey)) return e.preventDefault(), !0;
2252
2339
  let i = b(r.sc, t);
2253
- if (i && ee(i)) return e.preventDefault(), e.shiftKey ? Qe() : w("indent"), !0;
2254
- if (i?.nodeName.toUpperCase() === "PRE") return e.shiftKey ? !1 : (e.preventDefault(), w("insertText", " ".repeat(n.tabSize || 4)), !0);
2255
- if (n.tabSize) return e.shiftKey ? !1 : (e.preventDefault(), w("insertText", " ".repeat(n.tabSize)), !0);
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);
2256
2343
  }
2257
- if (F(e, P.ENTER) && e.shiftKey) return e.preventDefault(), w("insertLineBreak"), !0;
2258
- if (F(e, P.ENTER) && !e.shiftKey) {
2344
+ if (I(e, F.ENTER) && e.shiftKey) return e.preventDefault(), T("insertLineBreak"), !0;
2345
+ if (I(e, F.ENTER) && !e.shiftKey) {
2259
2346
  let n = xe(t);
2260
2347
  if (!n) return !1;
2261
2348
  let r = n.sc, i = r.nodeType === 3 ? r.parentElement : r;
@@ -2289,7 +2376,7 @@ function kn(e, t, n = {}) {
2289
2376
  if (r.deleteContents(), n.rangeCount === 0 || !o.isConnected) return !0;
2290
2377
  r = n.getRangeAt(0);
2291
2378
  }
2292
- let i = On(r, o), a = document.createElement("li"), s = document.createElement("input");
2379
+ let i = Pn(r, o), a = document.createElement("li"), s = document.createElement("input");
2293
2380
  s.type = "checkbox", s.setAttribute("contenteditable", "false"), a.appendChild(s), i.textContent.replace(/[\u00a0\u200B]/g, "").length > 0 && a.appendChild(i);
2294
2381
  let c = a.childNodes[1];
2295
2382
  c?.nodeType !== Node.TEXT_NODE && (c = document.createTextNode("​"), a.appendChild(c)), o.after(a);
@@ -2297,23 +2384,107 @@ function kn(e, t, n = {}) {
2297
2384
  return l.setStart(c, 0), l.collapse(!0), n.removeAllRanges(), n.addRange(l), !0;
2298
2385
  }
2299
2386
  let s = b(n.sc, t);
2300
- if (s?.nodeName.toUpperCase() === "PRE") return e.preventDefault(), w("insertText", "\n"), !0;
2387
+ if (s?.nodeName.toUpperCase() === "PRE") return e.preventDefault(), T("insertText", "\n"), !0;
2301
2388
  if (s?.nodeName.toUpperCase() === "BLOCKQUOTE") {
2302
2389
  let t = n.toNativeRange();
2303
- 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;
2304
2391
  }
2305
2392
  }
2306
2393
  return !1;
2307
2394
  }
2308
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
2309
2479
  //#region src/js/core/markdown.js
2310
- function An(e) {
2311
- return Ln(new DOMParser().parseFromString(`<body>${e || ""}</body>`, "text/html").body).replace(/\n{3,}/g, "\n\n").trim();
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();
2312
2483
  }
2313
- function z(e, t) {
2484
+ function V(e, t) {
2314
2485
  return Array.from(e.children).filter((e) => e.tagName === t.toUpperCase());
2315
2486
  }
2316
- function jn(e) {
2487
+ function Un(e) {
2317
2488
  let t = "";
2318
2489
  for (let n of e.childNodes) {
2319
2490
  if (n.nodeType === 3) {
@@ -2327,40 +2498,40 @@ function jn(e) {
2327
2498
  continue;
2328
2499
  }
2329
2500
  if (e === "div" || e === "p") {
2330
- t && !t.endsWith("\n") && (t += "\n"), t += jn(n), t += "\n";
2501
+ t && !t.endsWith("\n") && (t += "\n"), t += Un(n), t += "\n";
2331
2502
  continue;
2332
2503
  }
2333
- t += jn(n);
2504
+ t += Un(n);
2334
2505
  }
2335
2506
  return t;
2336
2507
  }
2337
- function Mn(e) {
2508
+ function Wn(e) {
2338
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`\~`);
2339
2510
  }
2340
- function Nn(e) {
2511
+ function Gn(e) {
2341
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}`);
2342
2513
  }
2343
- function Pn(e) {
2344
- return e.split("\n").map(Nn).join("\n");
2514
+ function Kn(e) {
2515
+ return e.split("\n").map(Gn).join("\n");
2345
2516
  }
2346
- function Fn(e, t) {
2517
+ function qn(e, t) {
2347
2518
  let n = " ".repeat(t + 1);
2348
- return Ln(e, t + 1).trim().split("\n").map((e, t) => t === 0 || e.trim() === "" || e.startsWith(n) ? e : n + e).join("\n");
2519
+ return Yn(e, t + 1).trim().split("\n").map((e, t) => t === 0 || e.trim() === "" || e.startsWith(n) ? e : n + e).join("\n");
2349
2520
  }
2350
- function In(e, t) {
2521
+ function Jn(e, t) {
2351
2522
  let n = e.getAttribute(t) || "", r = /[\s()]/.test(n) ? `<${n}>` : n, i = e.getAttribute("title");
2352
2523
  return i ? `${r} "${i.replaceAll("\"", String.raw`\"`)}"` : r;
2353
2524
  }
2354
- function Ln(e, t = 0) {
2525
+ function Yn(e, t = 0) {
2355
2526
  if (e.nodeType === 3) {
2356
2527
  let t = e.textContent.replace(/\s+/g, " ");
2357
- return e.parentElement?.closest("pre, code") ? t : Mn(t);
2528
+ return e.parentElement?.closest("pre, code") ? t : Wn(t);
2358
2529
  }
2359
2530
  if (e.nodeType !== 1) return "";
2360
- let n = e, r = n.nodeName.toLowerCase(), i = () => Array.from(n.childNodes).map((e) => Ln(e, t)).join("");
2531
+ let n = e, r = n.nodeName.toLowerCase(), i = () => Array.from(n.childNodes).map((e) => Yn(e, t)).join("");
2361
2532
  switch (r) {
2362
2533
  case "p":
2363
- case "div": return `\n\n${Pn(i())}\n\n`;
2534
+ case "div": return `\n\n${Kn(i())}\n\n`;
2364
2535
  case "br": return " \n";
2365
2536
  case "h1": return `\n\n# ${i()}\n\n`;
2366
2537
  case "h2": return `\n\n## ${i()}\n\n`;
@@ -2389,27 +2560,27 @@ function Ln(e, t = 0) {
2389
2560
  }
2390
2561
  case "pre": {
2391
2562
  let e = n.querySelector("code"), t = /language-(\S+)/.exec(e?.className || "");
2392
- return `\n\n\`\`\`${t ? t[1] : ""}\n${jn(e || n).replace(/\n$/, "")}\n\`\`\`\n\n`;
2563
+ return `\n\n\`\`\`${t ? t[1] : ""}\n${Un(e || n).replace(/\n$/, "")}\n\`\`\`\n\n`;
2393
2564
  }
2394
2565
  case "blockquote": {
2395
2566
  let e = i().trim().split("\n");
2396
2567
  return `\n\n${e.filter((t, n) => t.trim() !== "" || (e[n - 1] ?? "").trim() !== "").map((e) => e.trim() === "" ? ">" : `> ${e}`).join("\n")}\n\n`;
2397
2568
  }
2398
- case "a": return `[${i()}](${In(n, "href")})`;
2399
- case "img": return `![${Mn(n.getAttribute("alt") || "")}](${In(n, "src")})`;
2569
+ case "a": return `[${i()}](${Jn(n, "href")})`;
2570
+ case "img": return `![${Wn(n.getAttribute("alt") || "")}](${Jn(n, "src")})`;
2400
2571
  case "ul": {
2401
- let e = z(n, "li");
2572
+ let e = V(n, "li");
2402
2573
  if (!e.length) return i();
2403
2574
  let r = " ".repeat(t), a = n.classList.contains("an-checklist"), o = e.map((e) => {
2404
- let n = z(e, "input").find((e) => e.getAttribute("type") === "checkbox"), i = "- ";
2405
- return (a || n) && (i = n && n.checked ? "- [x] " : "- [ ] "), `${r}${i}${Fn(e, t)}`;
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)}`;
2406
2577
  }).join("\n");
2407
2578
  return t === 0 ? `\n\n${o}\n\n` : `\n${o}`;
2408
2579
  }
2409
2580
  case "ol": {
2410
- let e = z(n, "li");
2581
+ let e = V(n, "li");
2411
2582
  if (!e.length) return i();
2412
- let r = " ".repeat(t), a = Number.parseInt(n.getAttribute("start") || "1", 10), o = Number.isFinite(a) ? a : 1, s = e.map((e, n) => `${r}${o + n}. ${Fn(e, t)}`).join("\n");
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");
2413
2584
  return t === 0 ? `\n\n${s}\n\n` : `\n${s}`;
2414
2585
  }
2415
2586
  case "li": return i();
@@ -2417,7 +2588,7 @@ function Ln(e, t = 0) {
2417
2588
  case "table": {
2418
2589
  let e = Array.from(n.querySelectorAll("tr"));
2419
2590
  if (!e.length) return i();
2420
- let t = !!z(n, "thead")[0] || e[0].children.length > 0 && Array.from(e[0].children).every((e) => e.tagName === "TH"), r = e.map((e) => Array.from(e.querySelectorAll("th, td")).map((e) => Mn(e.textContent.trim()).replaceAll("|", String.raw`\|`))), a = Math.max(...r.map((e) => e.length)), o = (e) => {
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) => {
2421
2592
  let t = [...e];
2422
2593
  for (; t.length < a;) t.push("");
2423
2594
  return t;
@@ -2432,16 +2603,16 @@ function Ln(e, t = 0) {
2432
2603
  default: return i();
2433
2604
  }
2434
2605
  }
2435
- function Rn(e) {
2606
+ function Xn(e) {
2436
2607
  return String(e ?? "").replace(/^\ufeff/, "");
2437
2608
  }
2438
- function zn(e) {
2439
- let t = Rn(e);
2609
+ function Zn(e) {
2610
+ let t = Xn(e);
2440
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);
2441
2612
  }
2442
- var B = /^ {0,3}>( ?)(.*)$/, Bn = /^(?: {4}|\t)\s*\S/, Vn = /^( {0,3})(`{3,}|~{3,})[ \t]*([^\s`~][^\n]*)?$/;
2443
- function V(e) {
2444
- let t = Vn.exec(e);
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);
2445
2616
  if (!t) return null;
2446
2617
  let [, n, r, i = ""] = t;
2447
2618
  return r[0] === "`" && i.includes("`") ? null : {
@@ -2451,7 +2622,7 @@ function V(e) {
2451
2622
  lang: i.trim().split(/\s+/)[0] || ""
2452
2623
  };
2453
2624
  }
2454
- function Hn(e, t) {
2625
+ function er(e, t) {
2455
2626
  let n = 0, r = 0;
2456
2627
  for (; r < e.length && n < t;) {
2457
2628
  if (e[r] === " ") {
@@ -2468,40 +2639,40 @@ function Hn(e, t) {
2468
2639
  }
2469
2640
  return e.slice(r);
2470
2641
  }
2471
- var Un = /^ {0,3}([-*_])( *\1){2,}\s*$/, Wn = "";
2472
- function H(e) {
2473
- let t = Rn(e).replaceAll("\r\n", "\n").replaceAll("\r", "\n").split("\n");
2474
- t = Jn(t);
2475
- let n = Yn(t);
2476
- return t = n.clean, Kn = n.linkDefs, qn = n.footnoteIds, Gn(t);
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);
2477
2648
  }
2478
- function Gn(e) {
2649
+ function ir(e) {
2479
2650
  let t = [], n = 0;
2480
2651
  for (; n < e.length;) {
2481
- let r = e[n], i = V(r);
2652
+ let r = e[n], i = U(r);
2482
2653
  if (i) {
2483
2654
  let r = RegExp(`^ {0,3}\\${i.marker}{${i.length},}[ \t]*$`), a = [];
2484
- for (n++; n < e.length && !r.test(e[n]);) a.push(hr(Hn(e[n], i.indent))), n++;
2655
+ for (n++; n < e.length && !r.test(e[n]);) a.push(Ar(er(e[n], i.indent))), n++;
2485
2656
  let o = i.lang ? ` class="language-${q(i.lang)}"` : "";
2486
2657
  t.push(`<pre><code${o}>${a.join("\n")}</code></pre>`), n++;
2487
2658
  continue;
2488
2659
  }
2489
- if (Bn.test(r)) {
2660
+ if (Qn.test(r)) {
2490
2661
  let r = [];
2491
- for (; n < e.length && (Bn.test(e[n]) || e[n].trim() === "");) {
2662
+ for (; n < e.length && (Qn.test(e[n]) || e[n].trim() === "");) {
2492
2663
  if (e[n].trim() === "") {
2493
2664
  let t = n;
2494
2665
  for (; t < e.length && e[t].trim() === "";) t++;
2495
- if (t >= e.length || !Bn.test(e[t])) break;
2666
+ if (t >= e.length || !Qn.test(e[t])) break;
2496
2667
  for (; n < t; n++) r.push("");
2497
2668
  continue;
2498
2669
  }
2499
- r.push(hr(Hn(e[n], 4))), n++;
2670
+ r.push(Ar(er(e[n], 4))), n++;
2500
2671
  }
2501
2672
  t.push(`<pre><code>${r.join("\n")}</code></pre>`);
2502
2673
  continue;
2503
2674
  }
2504
- if (r.trim() && !Un.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) {
2505
2676
  if (/^=+\s*$/.test(e[n + 1])) {
2506
2677
  t.push(`<h1>${K(r.trim())}</h1>`), n += 2;
2507
2678
  continue;
@@ -2511,7 +2682,7 @@ function Gn(e) {
2511
2682
  continue;
2512
2683
  }
2513
2684
  }
2514
- if (Un.test(r)) {
2685
+ if (tr.test(r)) {
2515
2686
  t.push("<hr>"), n++;
2516
2687
  continue;
2517
2688
  }
@@ -2521,19 +2692,19 @@ function Gn(e) {
2521
2692
  t.push(`<h${e}>${K(r)}</h${e}>`), n++;
2522
2693
  continue;
2523
2694
  }
2524
- if (B.test(r)) {
2695
+ if (H.test(r)) {
2525
2696
  let r = [];
2526
- for (; n < e.length && B.test(e[n]);) r.push(B.exec(e[n])[2]), n++;
2527
- t.push(`<blockquote>${Gn(r)}</blockquote>`);
2697
+ for (; n < e.length && H.test(e[n]);) r.push(H.exec(e[n])[2]), n++;
2698
+ t.push(`<blockquote>${ir(r)}</blockquote>`);
2528
2699
  continue;
2529
2700
  }
2530
2701
  if (/^[-*+] /.test(r)) {
2531
- let { html: r, endIdx: i } = $n(e, n);
2702
+ let { html: r, endIdx: i } = pr(e, n);
2532
2703
  t.push(r), n = i;
2533
2704
  continue;
2534
2705
  }
2535
2706
  if (/^\d+[.)] /.test(r)) {
2536
- let { html: r, endIdx: i } = $n(e, n);
2707
+ let { html: r, endIdx: i } = pr(e, n);
2537
2708
  t.push(r), n = i;
2538
2709
  continue;
2539
2710
  }
@@ -2541,23 +2712,23 @@ function Gn(e) {
2541
2712
  n++;
2542
2713
  continue;
2543
2714
  }
2544
- if (Qn(e, n)) {
2545
- let i = U(r), a = U(e[n + 1]).map((e) => e.startsWith(":") && e.endsWith(":") ? "center" : e.endsWith(":") ? "right" : e.startsWith(":") ? "left" : null);
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);
2546
2717
  n += 2;
2547
2718
  let o = [];
2548
- for (; n < e.length && e[n].trim() !== "" && Zn(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++;
2549
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>` : "";
2550
2721
  t.push(`<table>${c}${l}</table>`);
2551
2722
  continue;
2552
2723
  }
2553
2724
  let o = [];
2554
- for (; n < e.length && e[n].trim() !== "" && !/^(#{1,6} |[-*+] |\d+[.)] )/.test(e[n]) && !V(e[n]) && !B.test(e[n]) && !Un.test(e[n]) && !Qn(e, n) && !(n + 1 < e.length && /^=+\s*$/.test(e[n + 1])) && !(n + 1 < e.length && /^-{2,}\s*$/.test(e[n + 1]));) o.push(e[n]), n++;
2555
- o.length ? t.push(`<p>${K(Xn(o)).replaceAll(Wn, "<br>")}</p>`) : (t.push(`<p>${K(r)}</p>`), n++);
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++);
2556
2727
  }
2557
2728
  return t.join("");
2558
2729
  }
2559
- var Kn = /* @__PURE__ */ new Map(), qn = /* @__PURE__ */ new Set();
2560
- function Jn(e) {
2730
+ var ar = /* @__PURE__ */ new Map(), or = /* @__PURE__ */ new Set();
2731
+ function sr(e) {
2561
2732
  if ((e[0] || "").trim() !== "---") return e;
2562
2733
  let t = -1;
2563
2734
  for (let n = 1; n < e.length; n++) {
@@ -2571,14 +2742,14 @@ function Jn(e) {
2571
2742
  let n = t + 1;
2572
2743
  return e[n] !== void 0 && e[n].trim() === "" && n++, e.slice(n);
2573
2744
  }
2574
- function Yn(e) {
2745
+ function cr(e) {
2575
2746
  let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = [], i = !1, a = /^\[([^\]]+)\]:\s*(\S+)(?:\s+"([^"]*)")?\s*$/, o = /^\[\^([^\]]+)\]:[ \t]*(\S.*)$/;
2576
2747
  for (let s of e) {
2577
2748
  if (i) {
2578
2749
  /^ {0,3}(?:`{3,}|~{3,})[ \t]*$/.test(s) && (i = !1), r.push(s);
2579
2750
  continue;
2580
2751
  }
2581
- if (V(s)) {
2752
+ if (U(s)) {
2582
2753
  i = !0, r.push(s);
2583
2754
  continue;
2584
2755
  }
@@ -2605,33 +2776,36 @@ function Yn(e) {
2605
2776
  footnoteIds: n
2606
2777
  };
2607
2778
  }
2608
- function Xn(e) {
2779
+ function lr(e) {
2609
2780
  let t = "";
2610
2781
  for (let n = 0; n < e.length; n++) {
2611
2782
  let r = n === e.length - 1, i = e[n].replace(/^[ \t]+/, "");
2612
2783
  if (!r && /\\$/.test(i)) {
2613
- t += i.replace(/\\$/, "") + Wn;
2784
+ t += i.replace(/\\$/, "") + nr;
2614
2785
  continue;
2615
2786
  }
2616
2787
  if (!r && / {2,}$/.test(i)) {
2617
- t += i.replace(/ {2,}$/, "") + Wn;
2788
+ t += i.replace(/ {2,}$/, "") + nr;
2618
2789
  continue;
2619
2790
  }
2620
2791
  t += i + (r ? "" : " ");
2621
2792
  }
2622
2793
  return t;
2623
2794
  }
2624
- function Zn(e) {
2625
- return U(e).length;
2795
+ function ur(e) {
2796
+ return W(e).length;
2626
2797
  }
2627
- function Qn(e, t) {
2798
+ function dr(e) {
2799
+ return e.includes("|") ? /^\s*\|/.test(e) || ur(e) > 1 : !1;
2800
+ }
2801
+ function fr(e, t) {
2628
2802
  let n = e[t], r = e[t + 1];
2629
2803
  if (r === void 0 || !n.includes("|")) return !1;
2630
2804
  if (/^\|.+\|/.test(n)) return /^\|[\s|:-]+\|/.test(r);
2631
- let i = U(r);
2632
- return i.length < 2 || !i.every((e) => /^:?-+:?$/.test(e)) ? !1 : Zn(n) === i.length;
2805
+ let i = W(r);
2806
+ return i.length < 2 || !i.every((e) => /^:?-+:?$/.test(e)) ? !1 : ur(n) === i.length;
2633
2807
  }
2634
- function U(e) {
2808
+ function W(e) {
2635
2809
  let t = e.replace(/^\|/, "").replace(/\|$/, ""), n = [], r = "";
2636
2810
  for (let e = 0; e < t.length; e++) {
2637
2811
  if (t[e] === "\\" && t[e + 1] === "|") {
@@ -2646,7 +2820,7 @@ function U(e) {
2646
2820
  }
2647
2821
  return n.push(r), n.map((e) => e.trim());
2648
2822
  }
2649
- function $n(e, t) {
2823
+ function pr(e, t) {
2650
2824
  let n = e[t].match(/^(\s*)/)[1].length, r = /^\s*\d+[.)] /.test(e[t]), i = [], a = null, o = !1, s = !1, c = t;
2651
2825
  for (; c < e.length;) {
2652
2826
  let t = e[c];
@@ -2674,15 +2848,15 @@ function $n(e, t) {
2674
2848
  c++;
2675
2849
  continue;
2676
2850
  }
2677
- let n = (e) => Hn(e, l), r = V(n(t));
2851
+ let n = (e) => er(e, l), r = U(n(t));
2678
2852
  if (r) {
2679
2853
  let t = RegExp(`^ {0,3}\\${r.marker}{${r.length},}[ \t]*$`), a = [n(e[c])];
2680
2854
  for (c++; c < e.length && !t.test(n(e[c]));) a.push(n(e[c])), c++;
2681
- c < e.length && (a.push(n(e[c])), c++), i[i.length - 1].sub += Gn(a), s = !1;
2855
+ c < e.length && (a.push(n(e[c])), c++), i[i.length - 1].sub += ir(a), s = !1;
2682
2856
  continue;
2683
2857
  }
2684
2858
  if (/^\s*(?:[-*+]|\d+[.)]) /.test(t)) {
2685
- let t = $n(e, c);
2859
+ let t = pr(e, c);
2686
2860
  i[i.length - 1].sub += t.html, c = t.endIdx, s = !1;
2687
2861
  } else if (s) i[i.length - 1].paras.push(t.trim()), s = !1, c++;
2688
2862
  else {
@@ -2700,32 +2874,32 @@ function $n(e, t) {
2700
2874
  endIdx: c
2701
2875
  };
2702
2876
  }
2703
- var er = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g, W = "\0", G = "", tr = /(`+)([^]*?)\1/g;
2704
- function nr(e) {
2877
+ var mr = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g, G = "\0", hr = "", gr = /(`+)([^]*?)\1/g;
2878
+ function _r(e) {
2705
2879
  let t = [];
2706
2880
  return {
2707
- text: e.replace(tr, (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}`)),
2708
2882
  codes: t
2709
2883
  };
2710
2884
  }
2711
- function rr(e, t, n) {
2712
- 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) => {
2713
2887
  let i = t[Number(r)];
2714
- return i = i.replace(RegExp(`${W}(\\d+)${W}`, "g"), (e, t) => `\\${n[Number(t)]}`), i.length > 2 && i.startsWith(" ") && i.endsWith(" ") && i.trim() !== "" && (i = i.slice(1, -1)), `<code>${hr(i)}</code>`;
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>`;
2715
2889
  });
2716
2890
  }
2717
- function ir(e) {
2891
+ function yr(e) {
2718
2892
  let t = [];
2719
2893
  return {
2720
- text: e.replace(er, (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}`)),
2721
2895
  literals: t
2722
2896
  };
2723
2897
  }
2724
- function ar(e, t) {
2725
- return e.replace(RegExp(`${W}(\\d+)${W}`, "g"), (e, n) => mr(t[Number(n)]));
2898
+ function br(e, t) {
2899
+ return e.replace(RegExp(`${G}(\\d+)${G}`, "g"), (e, n) => kr(t[Number(n)]));
2726
2900
  }
2727
- var or = String.raw`(&lt;.*?&gt;(?:\s+(?:"[^"]*"|'[^']*'))?|[^)]*)`, sr = new RegExp(String.raw`!\[([^\]]*)\]\(${or}\)`, "g"), cr = new RegExp(String.raw`\[([^\]]+)\]\(${or}\)`, "g");
2728
- function lr(e) {
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) {
2729
2903
  let t = e.trim(), n = /^&lt;([\s\S]*?)&gt;(?:[ \t]*(?:"([^"]*)"|'([^']*)'))?[ \t]*$/.exec(t);
2730
2904
  if (n) return {
2731
2905
  href: n[1],
@@ -2740,26 +2914,26 @@ function lr(e) {
2740
2914
  title: ""
2741
2915
  };
2742
2916
  }
2743
- function ur(e) {
2744
- return e = e.replace(sr, (e, t, n) => {
2745
- let { href: r, title: i } = lr(n), a = i ? ` title="${J(i)}"` : "";
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)}"` : "";
2746
2920
  return `<img src="${J(r)}" alt="${J(t)}"${a} class="an-image">`;
2747
- }), e = e.replace(cr, (e, t, n) => {
2748
- let { href: r, title: i } = lr(n), a = i ? ` title="${J(i)}"` : "";
2921
+ }), e = e.replace(Cr, (e, t, n) => {
2922
+ let { href: r, title: i } = wr(n), a = i ? ` title="${J(i)}"` : "";
2749
2923
  return `<a href="${J(r)}"${a}>${t}</a>`;
2750
2924
  }), e = e.replace(/\[([^\]]+)\]\[([^\]]*)\]/g, (e, t, n) => {
2751
- let r = Kn.get(gr(n || t).trim().toLowerCase());
2925
+ let r = ar.get(jr(n || t).trim().toLowerCase());
2752
2926
  if (!r) return e;
2753
2927
  let i = r.title ? ` title="${q(r.title)}"` : "";
2754
2928
  return `<a href="${q(r.href)}"${i}>${t}</a>`;
2755
2929
  }), e = e.replace(/\[([^\]]+)\]/g, (e, t) => {
2756
- let n = Kn.get(gr(t).trim().toLowerCase());
2930
+ let n = ar.get(jr(t).trim().toLowerCase());
2757
2931
  if (!n) return e;
2758
2932
  let r = n.title ? ` title="${q(n.title)}"` : "";
2759
2933
  return `<a href="${q(n.href)}"${r}>${t}</a>`;
2760
- }), e = e.replace(/\[\^([^\]]+)\]/g, (e, t) => qn.has(gr(t)) ? `<sup>[${t}]</sup>` : e), e;
2934
+ }), e = e.replace(/\[\^([^\]]+)\]/g, (e, t) => or.has(jr(t)) ? `<sup>[${t}]</sup>` : e), e;
2761
2935
  }
2762
- function dr(e) {
2936
+ function Er(e) {
2763
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) => {
2764
2938
  let r = /[.,;:!?)]+$/.exec(n), i = r ? n.slice(0, -r[0].length) : n;
2765
2939
  if (!i) return e;
@@ -2767,18 +2941,18 @@ function dr(e) {
2767
2941
  return `${t}<a href="${J(i)}">${i}</a>${a}`;
2768
2942
  }), e;
2769
2943
  }
2770
- function fr(e) {
2944
+ function Dr(e) {
2771
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;
2772
2946
  }
2773
2947
  function K(e) {
2774
- let { text: t, literals: n } = ir(e), { text: r, codes: i } = nr(t), a = mr(r);
2775
- return a = ur(a), a = dr(a), a = fr(a), rr(ar(a, n), i, n);
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);
2776
2950
  }
2777
- var pr = /&(?!#\d+;|#[xX][0-9a-fA-F]+;|[a-zA-Z][a-zA-Z0-9]*;)/g;
2778
- function mr(e) {
2779
- return String(e).replace(pr, "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
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;");
2780
2954
  }
2781
- function hr(e) {
2955
+ function Ar(e) {
2782
2956
  return String(e).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2783
2957
  }
2784
2958
  function q(e) {
@@ -2787,16 +2961,16 @@ function q(e) {
2787
2961
  function J(e) {
2788
2962
  return String(e).replaceAll("\"", "&quot;").replaceAll("'", "&#39;");
2789
2963
  }
2790
- function gr(e) {
2964
+ function jr(e) {
2791
2965
  return String(e).replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&amp;", "&");
2792
2966
  }
2793
2967
  //#endregion
2794
2968
  //#region src/js/core/detectLang.js
2795
- var _r = 5, vr = 2, yr = [
2969
+ var Mr = 5, Nr = 2, Pr = [
2796
2970
  ["typescript", "javascript"],
2797
2971
  ["scss", "css"],
2798
2972
  ["cpp", "c"]
2799
- ], br = [
2973
+ ], Fr = [
2800
2974
  "javascript",
2801
2975
  "typescript",
2802
2976
  "python",
@@ -2819,7 +2993,7 @@ var _r = 5, vr = 2, yr = [
2819
2993
  "scss",
2820
2994
  "css",
2821
2995
  "bash"
2822
- ], xr = [
2996
+ ], Ir = [
2823
2997
  {
2824
2998
  lang: "php",
2825
2999
  w: 10,
@@ -3385,27 +3559,27 @@ var _r = 5, vr = 2, yr = [
3385
3559
  w: 3,
3386
3560
  re: /\s\|[ \t]*\w|\s&&\s|\s2>&1|\s-[\w-]+\s/
3387
3561
  }
3388
- ], Sr = 4e3;
3389
- function Cr(e) {
3390
- if (e.length <= Sr) return e;
3391
- let t = e.slice(0, Sr), n = t.lastIndexOf("\n");
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");
3392
3566
  return n > 0 ? t.slice(0, n) : t;
3393
3567
  }
3394
- function wr(e) {
3568
+ function zr(e) {
3395
3569
  if (!e?.trim()) return null;
3396
- let t = Cr(e.trim()), n = /* @__PURE__ */ new Map();
3397
- for (let { lang: e, re: r, w: i } of xr) r.test(t) && n.set(e, (n.get(e) || 0) + i);
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);
3398
3572
  if (n.size === 0) return null;
3399
- for (let [e, t] of yr) {
3573
+ for (let [e, t] of Pr) {
3400
3574
  let r = n.get(e);
3401
3575
  r && n.set(e, r + (n.get(t) || 0));
3402
3576
  }
3403
3577
  let r = [...n.entries()].sort((e, t) => t[1] - e[1]), [i, a] = r[0], o = r[1]?.[1] ?? 0;
3404
- return a < _r || a - o < vr ? null : i;
3578
+ return a < Mr || a - o < Nr ? null : i;
3405
3579
  }
3406
3580
  //#endregion
3407
3581
  //#region src/js/module/Editor.js
3408
- var Tr = /* @__PURE__ */ new Set([
3582
+ var Br = /* @__PURE__ */ new Set([
3409
3583
  "PRE",
3410
3584
  "BLOCKQUOTE",
3411
3585
  "TABLE",
@@ -3413,13 +3587,13 @@ var Tr = /* @__PURE__ */ new Set([
3413
3587
  "UL",
3414
3588
  "OL",
3415
3589
  "HR"
3416
- ]), Er = class {
3590
+ ]), Vr = class {
3417
3591
  constructor(e) {
3418
- 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;
3419
3593
  }
3420
3594
  initialize() {
3421
3595
  let e = this.context.layoutInfo.editable;
3422
- return this._history = new wn(e, this.options.historyLimit || 100, this.options.historyMaxBytes || 10 * 1024 * 1024), this._bindEvents(e), this;
3596
+ return this._history = new On(e, this.options.historyLimit || 100, this.options.historyMaxBytes || 10 * 1024 * 1024), this._bindEvents(e), this;
3423
3597
  }
3424
3598
  destroy() {
3425
3599
  this._disposers.forEach((e) => e()), this._disposers = [], this._history = null, clearTimeout(this._snapshotTimer), this._snapshotTimer = null;
@@ -3496,32 +3670,32 @@ var Tr = /* @__PURE__ */ new Set([
3496
3670
  }
3497
3671
  _onKeydown(e) {
3498
3672
  let t = this.context.layoutInfo.editable;
3499
- if (!kn(e, t, this.options)) {
3500
- if (I(e, "z") && !e.shiftKey) {
3673
+ if (!Fn(e, t, this.options)) {
3674
+ if (L(e, "z") && !e.shiftKey) {
3501
3675
  e.preventDefault(), this.undo();
3502
3676
  return;
3503
3677
  }
3504
- if (I(e, "z") && e.shiftKey || I(e, "y")) {
3678
+ if (L(e, "z") && e.shiftKey || L(e, "y")) {
3505
3679
  e.preventDefault(), this.redo();
3506
3680
  return;
3507
3681
  }
3508
- if (I(e, "b")) {
3682
+ if (L(e, "b")) {
3509
3683
  e.preventDefault(), this.bold();
3510
3684
  return;
3511
3685
  }
3512
- if (I(e, "i")) {
3686
+ if (L(e, "i")) {
3513
3687
  e.preventDefault(), this.italic();
3514
3688
  return;
3515
3689
  }
3516
- if (I(e, "u")) {
3690
+ if (L(e, "u")) {
3517
3691
  e.preventDefault(), this.underline();
3518
3692
  return;
3519
3693
  }
3520
- if (I(e, "k")) {
3694
+ if (L(e, "k")) {
3521
3695
  e.preventDefault(), this.context.invoke("linkDialog.show");
3522
3696
  return;
3523
3697
  }
3524
- if (I(e, "v") && e.shiftKey) {
3698
+ if (L(e, "v") && e.shiftKey) {
3525
3699
  this.context.invoke("clipboard.setForcePlain", !0);
3526
3700
  return;
3527
3701
  }
@@ -3529,24 +3703,25 @@ var Tr = /* @__PURE__ */ new Set([
3529
3703
  e.preventDefault(), this.context.invoke("shortcutsDialog.show");
3530
3704
  return;
3531
3705
  }
3532
- if (I(e, "f")) {
3706
+ if (L(e, "f")) {
3533
3707
  e.preventDefault(), this.context.invoke("findReplace.show", "find");
3534
3708
  return;
3535
3709
  }
3536
- 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());
3537
3711
  }
3538
3712
  }
3539
3713
  _enforceLimit(e) {
3540
3714
  let t = this.options.maxChars || 0, n = this.options.maxWords || 0;
3541
3715
  if (!t && !n) return;
3716
+ this._limitCounter ??= new Bn();
3542
3717
  let r = e.inputType || "";
3543
3718
  if (r.startsWith("delete") || r === "historyUndo" || r === "historyRedo" || r === "insertFromPaste" || r === "insertFromDrop" || !r.startsWith("insert")) return;
3544
- let i = this.context.layoutInfo.editable.innerText || "", a = i.replaceAll("\n", "").length;
3719
+ let { words: i, chars: a } = this._limitCounter.counts(this.context.layoutInfo.editable);
3545
3720
  if (t && a >= t) {
3546
3721
  e.preventDefault(), typeof this.options.onCharLimitReached == "function" && this.options.onCharLimitReached(this.context);
3547
3722
  return;
3548
3723
  }
3549
- n && (e.data === " " || r === "insertParagraph" || r === "insertLineBreak") && (i.trim() ? i.trim().split(/\s+/).length : 0) >= n && (e.preventDefault(), typeof this.options.onWordLimitReached == "function" && this.options.onWordLimitReached(this.context));
3724
+ n && (e.data === " " || r === "insertParagraph" || r === "insertLineBreak") && i >= n && (e.preventDefault(), typeof this.options.onWordLimitReached == "function" && this.options.onWordLimitReached(this.context));
3550
3725
  }
3551
3726
  afterCommand() {
3552
3727
  this._cleanOrphanedFigures(), this._ensureTrailingParagraph(), this.context.invoke("toolbar.refresh"), this.context.invoke("statusbar.update"), this._scheduleSnapshot();
@@ -3565,7 +3740,7 @@ var Tr = /* @__PURE__ */ new Set([
3565
3740
  let e = this.context.layoutInfo.editable;
3566
3741
  if (!e) return;
3567
3742
  let t = e.lastElementChild;
3568
- if (t && Tr.has(t.nodeName)) {
3743
+ if (t && Br.has(t.nodeName)) {
3569
3744
  let t = document.createElement("p");
3570
3745
  t.innerHTML = "<br>", e.appendChild(t);
3571
3746
  }
@@ -3578,7 +3753,7 @@ var Tr = /* @__PURE__ */ new Set([
3578
3753
  return this.context.invoke("clipboard.resolveImages", e) ?? e;
3579
3754
  }
3580
3755
  setHTML(e) {
3581
- let t = mn(e, { allowIframes: !0 });
3756
+ let t = _n(e, { allowIframes: !0 });
3582
3757
  this.context.layoutInfo.editable.replaceChildren(...t.childNodes), this._history && this._history.reset(), this.afterCommand();
3583
3758
  }
3584
3759
  getText() {
@@ -3598,16 +3773,16 @@ var Tr = /* @__PURE__ */ new Set([
3598
3773
  return !e && !t;
3599
3774
  }
3600
3775
  insertHTML(e) {
3601
- e && (w("insertHTML", j(e)), this.afterCommand());
3776
+ e && (T("insertHTML", M(e)), this.afterCommand());
3602
3777
  }
3603
3778
  insertText(e) {
3604
- e && (w("insertText", e), this.afterCommand());
3779
+ e && (T("insertText", e), this.afterCommand());
3605
3780
  }
3606
3781
  setMarkdown(e) {
3607
- this.setHTML(H(e || ""));
3782
+ this.setHTML(rr(e || ""));
3608
3783
  }
3609
3784
  getMarkdown() {
3610
- return An(this.getHTML());
3785
+ return Hn(this.getHTML());
3611
3786
  }
3612
3787
  undo() {
3613
3788
  this._history && (this._flushPendingSnapshot(), this._history.undo(), this.context.invoke("toolbar.refresh"), this.context.invoke("statusbar.update"), this.context.triggerEvent("change", this.getHTML()));
@@ -3637,63 +3812,63 @@ var Tr = /* @__PURE__ */ new Set([
3637
3812
  return !e || !this._history ? !1 : (this._history._restoreSelection(e), !0);
3638
3813
  }
3639
3814
  bold() {
3640
- Ie(), this.afterCommand();
3815
+ Le(), this.afterCommand();
3641
3816
  }
3642
3817
  italic() {
3643
- Le(), this.afterCommand();
3818
+ Re(), this.afterCommand();
3644
3819
  }
3645
3820
  underline() {
3646
- Re(), this.afterCommand();
3821
+ ze(), this.afterCommand();
3647
3822
  }
3648
3823
  strikethrough() {
3649
- ze(), this.afterCommand();
3824
+ Be(), this.afterCommand();
3650
3825
  }
3651
3826
  superscript() {
3652
- Be(), this.afterCommand();
3827
+ Ve(), this.afterCommand();
3653
3828
  }
3654
3829
  subscript() {
3655
- Ve(), this.afterCommand();
3830
+ He(), this.afterCommand();
3656
3831
  }
3657
3832
  justifyLeft() {
3658
- qe(), this.afterCommand();
3833
+ Je(), this.afterCommand();
3659
3834
  }
3660
3835
  justifyCenter() {
3661
- Je(), this.afterCommand();
3836
+ Ye(), this.afterCommand();
3662
3837
  }
3663
3838
  justifyRight() {
3664
- Ye(), this.afterCommand();
3839
+ Xe(), this.afterCommand();
3665
3840
  }
3666
3841
  justifyFull() {
3667
- Xe(), this.afterCommand();
3842
+ Ze(), this.afterCommand();
3668
3843
  }
3669
3844
  indent() {
3670
- Ze(), this.afterCommand();
3845
+ Qe(), this.afterCommand();
3671
3846
  }
3672
3847
  outdent() {
3673
- Qe(), this.afterCommand();
3848
+ et(), this.afterCommand();
3674
3849
  }
3675
3850
  insertUL() {
3676
- nt(), this.afterCommand();
3851
+ at(), this.afterCommand();
3677
3852
  }
3678
3853
  insertOL() {
3679
- rt(), this.afterCommand();
3854
+ ot(), this.afterCommand();
3680
3855
  }
3681
3856
  inlineCode() {
3682
- at(this.context.layoutInfo.editable), this.afterCommand();
3857
+ ct(this.context.layoutInfo.editable), this.afterCommand();
3683
3858
  }
3684
3859
  toggleChecklist() {
3685
- ct(), this.afterCommand();
3860
+ dt(), this.afterCommand();
3686
3861
  }
3687
3862
  print() {
3688
3863
  this.context.print();
3689
3864
  }
3690
3865
  formatBlock(e) {
3691
- if (Ke(e), e === "pre") {
3866
+ if (qe(e), e === "pre") {
3692
3867
  let e = globalThis.getSelection();
3693
3868
  if (e?.rangeCount > 0) {
3694
3869
  let t = e.getRangeAt(0).commonAncestorContainer, n = t.nodeType === 1 ? t.closest("pre") : t.parentElement?.closest("pre");
3695
3870
  if (n && !n.dataset.language) {
3696
- let e = wr(n.textContent || "");
3871
+ let e = zr(n.textContent || "");
3697
3872
  if (e) {
3698
3873
  this.context.invoke("codeTooltip.applyLanguage", n, e);
3699
3874
  return;
@@ -3704,55 +3879,55 @@ var Tr = /* @__PURE__ */ new Set([
3704
3879
  this.afterCommand();
3705
3880
  }
3706
3881
  foreColor(e) {
3707
- He(e), this.afterCommand();
3882
+ Ue(e), this.afterCommand();
3708
3883
  }
3709
3884
  backColor(e) {
3710
- Ue(e), this.afterCommand();
3885
+ We(e), this.afterCommand();
3711
3886
  }
3712
3887
  fontName(e) {
3713
- We(e), this.afterCommand();
3888
+ Ge(e), this.afterCommand();
3714
3889
  }
3715
3890
  fontSize(e) {
3716
- Ge(e, this.context.layoutInfo.editable), this.afterCommand();
3891
+ Ke(e, this.context.layoutInfo.editable), this.afterCommand();
3717
3892
  }
3718
3893
  insertHr() {
3719
- w("insertHorizontalRule"), this.afterCommand();
3894
+ T("insertHorizontalRule"), this.afterCommand();
3720
3895
  }
3721
3896
  insertLink(e, t, n = !1) {
3722
3897
  let r = globalThis.getSelection();
3723
3898
  if (!r || r.rangeCount === 0) return;
3724
- let i = M(e);
3899
+ let i = N(e);
3725
3900
  if (i) {
3726
3901
  if (r.toString().trim().length > 0) {
3727
- if (w("createLink", i), n) {
3902
+ if (T("createLink", i), n) {
3728
3903
  let e = this._getClosestAnchor();
3729
3904
  e && (e.setAttribute("target", "_blank"), e.setAttribute("rel", "noopener noreferrer"));
3730
3905
  }
3731
3906
  } else {
3732
3907
  let e = this._escapeAttr(t || i);
3733
- 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>`);
3734
3909
  }
3735
3910
  this.afterCommand();
3736
3911
  }
3737
3912
  }
3738
3913
  unlink() {
3739
- w("unlink"), this.afterCommand();
3914
+ T("unlink"), this.afterCommand();
3740
3915
  }
3741
3916
  insertImage(e, t = "", n = "") {
3742
- let r = M(e, { allowData: !0 });
3917
+ let r = N(e, { allowData: !0 });
3743
3918
  if (!r) return;
3744
3919
  let i = {
3745
3920
  left: "float:left;margin:0 1em 1em 0",
3746
3921
  center: "display:block;margin:0 auto",
3747
3922
  right: "float:right;margin:0 0 1em 1em"
3748
3923
  }[n] || "", a = i ? ` style="${i}"` : "";
3749
- 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();
3750
3925
  }
3751
3926
  insertVideo(e) {
3752
- e && (w("insertHTML", e), this.afterCommand());
3927
+ e && (T("insertHTML", e), this.afterCommand());
3753
3928
  }
3754
3929
  insertTable(e, t) {
3755
- En(e, t, { headerRow: this.context.options.tableHeaderRow }), this.afterCommand();
3930
+ An(e, t, { headerRow: this.context.options.tableHeaderRow }), this.afterCommand();
3756
3931
  }
3757
3932
  _getClosestAnchor() {
3758
3933
  let e = globalThis.getSelection();
@@ -3767,7 +3942,7 @@ var Tr = /* @__PURE__ */ new Set([
3767
3942
  _escapeAttr(e) {
3768
3943
  return String(e ?? "").replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
3769
3944
  }
3770
- }, Dr = (e) => typeof e == "string" ? ut(e) : e, Y = null, Or = "stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"", X = (e) => `<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" ${Or} style="display:block">${e}</svg>`, Z = /* @__PURE__ */ new Map([
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([
3771
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\"/>")],
3772
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\"/>")],
3773
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\"/>")],
@@ -3804,7 +3979,7 @@ var Tr = /* @__PURE__ */ new Set([
3804
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\"/>")],
3805
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\"/>")],
3806
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\"/>")]
3807
- ]), kr = /* @__PURE__ */ new Map([
3982
+ ]), Wr = /* @__PURE__ */ new Map([
3808
3983
  ["bold", "fa-bold"],
3809
3984
  ["italic", "fa-italic"],
3810
3985
  ["underline", "fa-underline"],
@@ -3838,7 +4013,7 @@ var Tr = /* @__PURE__ */ new Set([
3838
4013
  ["inline-code", "fa-code"],
3839
4014
  ["checklist", "fa-list-check"],
3840
4015
  ["print", "fa-print"]
3841
- ]), Ar = class {
4016
+ ]), Gr = class {
3842
4017
  constructor(e) {
3843
4018
  this.context = e, this.options = e.options, this.el = null, this._disposers = [], this._colorPickerClosers = [], this._refreshRaf = null;
3844
4019
  }
@@ -3848,7 +4023,7 @@ var Tr = /* @__PURE__ */ new Set([
3848
4023
  role: "toolbar",
3849
4024
  "aria-orientation": "horizontal",
3850
4025
  "aria-label": "Editor toolbar"
3851
- }), this._faReady = this._detectFontAwesome(), this._buildButtons(), this._initRovingFocus(), this._btnMap = new Map((this.options.toolbar || []).flat().map(Dr).filter(Boolean).map((e) => [e.name, e])), this;
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;
3852
4027
  }
3853
4028
  destroy() {
3854
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;
@@ -3858,7 +4033,7 @@ var Tr = /* @__PURE__ */ new Set([
3858
4033
  e.forEach((e) => {
3859
4034
  let n = x("div", { class: "an-btn-group" });
3860
4035
  e.forEach((e) => {
3861
- let t = Dr(e);
4036
+ let t = Hr(e);
3862
4037
  if (!t) {
3863
4038
  console.warn(`[AutumnNote] Toolbar: button "${e}" not found in registry. Skipped.`);
3864
4039
  return;
@@ -4077,7 +4252,7 @@ var Tr = /* @__PURE__ */ new Set([
4077
4252
  ...typeof e.isActive == "function" ? { "aria-pressed": "false" } : {}
4078
4253
  }), n = this.options.fontAwesomeClass || "fas";
4079
4254
  if (this._faReady) {
4080
- let r = kr.get(e.icon) || kr.get(e.name) || null;
4255
+ let r = Wr.get(e.icon) || Wr.get(e.name) || null;
4081
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;
4082
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;
4083
4258
  let r = C(t, "click", (t) => {
@@ -4159,53 +4334,21 @@ var Tr = /* @__PURE__ */ new Set([
4159
4334
  this.el && (this.el.style.display = "none");
4160
4335
  }
4161
4336
  rebuild() {
4162
- this._refreshRaf &&= (cancelAnimationFrame(this._refreshRaf), null), this._disposers.forEach((e) => e()), this._disposers = [], this.el && (this.el.innerHTML = ""), this._faReady = this._detectFontAwesome(), this._buildButtons(), this._initRovingFocus(), this._btnMap = new Map((this.options.toolbar || []).flat().map(Dr).filter(Boolean).map((e) => [e.name, e])), this.refresh();
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();
4163
4338
  }
4164
- }, jr = typeof Intl < "u" && typeof Intl.Segmenter == "function" ? new Intl.Segmenter(void 0, { granularity: "word" }) : null;
4165
- function Mr(e) {
4166
- let t = e.trim();
4167
- if (!t) return 0;
4168
- if (jr) {
4169
- let e = 0;
4170
- for (let n of jr.segment(t)) n.isWordLike && e++;
4171
- return e;
4172
- }
4173
- return t.split(/\s+/).length;
4174
- }
4175
- var Nr = /* @__PURE__ */ new Set(/* @__PURE__ */ "ADDRESS.ARTICLE.ASIDE.BLOCKQUOTE.BR.DD.DIV.DL.DT.FIELDSET.FIGCAPTION.FIGURE.FOOTER.FORM.H1.H2.H3.H4.H5.H6.HEADER.HR.LI.MAIN.NAV.OL.P.PRE.SECTION.TABLE.TBODY.TD.TFOOT.TH.THEAD.TR.UL".split("."));
4176
- function Pr(e, t, n) {
4177
- for (let r = e.firstChild; r; r = r.nextSibling) if (r.nodeType === 3) {
4178
- let e = r.data;
4179
- t.push(e), n.push(e);
4180
- } else if (r.nodeType === 1) {
4181
- let e = Nr.has(r.tagName);
4182
- e && t.push("\n"), Pr(r, t, n), e && t.push("\n");
4183
- }
4184
- }
4185
- function Fr(e) {
4186
- if (e.nodeType === 3) {
4187
- let t = e.data;
4188
- return {
4189
- lines: t,
4190
- flat: t
4191
- };
4192
- }
4193
- let t = [], n = [];
4194
- return Pr(e, t, n), {
4195
- lines: t.join(""),
4196
- flat: n.join("")
4197
- };
4198
- }
4199
- function Ir(e, t, n) {
4339
+ };
4340
+ //#endregion
4341
+ //#region src/js/module/Statusbar.js
4342
+ function Kr(e, t, n) {
4200
4343
  if (!n) {
4201
4344
  e.classList.remove("an-count-warn", "an-count-exceeded");
4202
4345
  return;
4203
4346
  }
4204
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");
4205
4348
  }
4206
- var Lr = class {
4349
+ var qr = class {
4207
4350
  constructor(e) {
4208
- this.context = e, this.options = e.options, this.el = null, this._disposers = [], this._wordCountEl = null, this._charCountEl = null, this._countCache = /* @__PURE__ */ new WeakMap();
4351
+ this.context = e, this.options = e.options, this.el = null, this._disposers = [], this._wordCountEl = null, this._charCountEl = null, this._counter = new Bn();
4209
4352
  }
4210
4353
  initialize() {
4211
4354
  if (this.el = x("div", { class: "an-statusbar" }), this.options.resizable !== !1) {
@@ -4255,50 +4398,12 @@ var Lr = class {
4255
4398
  this._disposers.push(d, f);
4256
4399
  }
4257
4400
  _counts() {
4258
- let e = this.context.layoutInfo.editable, t = 0, n = 0, r = [], i = [], a = 0;
4259
- for (let o = e.firstChild; o; o = o.nextSibling) {
4260
- let e = this._countCache.get(o);
4261
- if (e && e.key === (o.textContent || "")) {
4262
- t += e.words, n += e.chars;
4263
- continue;
4264
- }
4265
- let { lines: s, flat: c } = Fr(o);
4266
- r.push({
4267
- node: o,
4268
- key: c,
4269
- text: s,
4270
- start: a
4271
- }), i.push(s), a += s.length + 1;
4272
- }
4273
- if (r.length) {
4274
- let e = this._countBatch(r, i.join("\n"));
4275
- r.forEach((r, i) => {
4276
- let a = {
4277
- key: r.key,
4278
- words: e[i],
4279
- chars: r.key.replaceAll("\n", "").length
4280
- };
4281
- this._countCache.set(r.node, a), t += a.words, n += a.chars;
4282
- });
4283
- }
4284
- return {
4285
- words: t,
4286
- chars: n
4287
- };
4288
- }
4289
- _countBatch(e, t) {
4290
- if (!jr) return e.map((e) => Mr(e.text));
4291
- let n = Array(e.length).fill(0), r = 0;
4292
- for (let i of jr.segment(t)) if (i.isWordLike) {
4293
- for (; r < e.length - 1 && i.index >= e[r + 1].start;) r++;
4294
- n[r]++;
4295
- }
4296
- return n;
4401
+ return this._counter.counts(this.context.layoutInfo.editable);
4297
4402
  }
4298
4403
  update() {
4299
4404
  if (!this._wordCountEl || !this._charCountEl) return;
4300
4405
  let { words: e, chars: t } = this._counts(), n = this.options.maxWords || 0, r = this.options.maxChars || 0, i = this.context.locale.statusbar;
4301
- this._wordCountEl.textContent = n ? i.wordsLimit(e, n) : i.words(e), this._charCountEl.textContent = r ? i.charsLimit(t, r) : i.chars(t), Ir(this._wordCountEl, e, n), Ir(this._charCountEl, t, r);
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);
4302
4407
  }
4303
4408
  getWordCount() {
4304
4409
  return this._counts().words;
@@ -4306,7 +4411,7 @@ var Lr = class {
4306
4411
  getCharCount() {
4307
4412
  return this._counts().chars;
4308
4413
  }
4309
- }, Rr = class {
4414
+ }, Jr = class {
4310
4415
  constructor(e) {
4311
4416
  this.context = e, this.options = e.options, this._disposers = [];
4312
4417
  }
@@ -4418,20 +4523,20 @@ var Lr = class {
4418
4523
  text: t.getData("text/plain") || "",
4419
4524
  html: t.types.includes("text/html") ? t.getData("text/html") : null
4420
4525
  }), n || this.options.pasteAsPlainText) {
4421
- e.preventDefault(), w("insertHTML", t.getData("text/plain").split(/\r?\n/).map((e) => `<p>${this._escapeHTML(e) || "<br>"}</p>`).join("")), this.context.invoke("editor.afterCommand");
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");
4422
4527
  return;
4423
4528
  }
4424
4529
  if (this.options.markdownPaste !== !1) {
4425
4530
  let n = t.types.includes("text/html"), r = n ? t.getData("text/html") : "", i = !n || this._isTriviallyPlainHtml(r), a = t.getData("text/plain");
4426
- if (a && i && zn(a)) {
4427
- e.preventDefault(), w("insertHTML", j(H(a))), this.context.invoke("editor.afterCommand");
4531
+ if (a && i && Zn(a)) {
4532
+ e.preventDefault(), T("insertHTML", M(rr(a))), this.context.invoke("editor.afterCommand");
4428
4533
  return;
4429
4534
  }
4430
4535
  }
4431
4536
  if (this.options.pasteCleanHTML !== !1 && t.types.includes("text/html")) {
4432
4537
  e.preventDefault();
4433
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;
4434
- r ? a = this._cleanWordHtml(a) : i && (a = this._cleanSocialHtml(a)), a = this._normalizeExternalTaskLists(a), a = j(a), this.options.pasteStripAttributes && (a = this._stripAttributes(a)), w("insertHTML", a), this.context.invoke("editor.afterCommand");
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");
4435
4540
  }
4436
4541
  }
4437
4542
  _onDragover(e) {
@@ -4463,7 +4568,7 @@ var Lr = class {
4463
4568
  }
4464
4569
  let n = new FileReader();
4465
4570
  n.onload = (e) => {
4466
- w("insertHTML", j(H(e.target.result || ""))), this.context.invoke("editor.afterCommand");
4571
+ T("insertHTML", M(rr(e.target.result || ""))), this.context.invoke("editor.afterCommand");
4467
4572
  }, n.onerror = () => {
4468
4573
  let t = `Failed to read dropped markdown file "${e.name}".`;
4469
4574
  console.warn(`[AutumnNote] ${t}`), this.context.triggerEvent("pasteError", { message: t });
@@ -4548,7 +4653,7 @@ var Lr = class {
4548
4653
  file: e
4549
4654
  });
4550
4655
  let r = this._escapeAttr(e.name.replace(/\.[^.]+$/, ""));
4551
- return w("insertHTML", `<img src="${this._escapeAttr(n)}" alt="${r}" class="an-image an-image-uploading" data-an-upload="${t}">`), this.context.invoke("editor.afterCommand"), t;
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;
4552
4657
  }
4553
4658
  _findPlaceholder(e) {
4554
4659
  return this.context.layoutInfo.editable?.querySelector(`img[data-an-upload="${e}"]`) ?? null;
@@ -4556,7 +4661,7 @@ var Lr = class {
4556
4661
  _resolveUpload(e, t) {
4557
4662
  let n = this._findPlaceholder(e), r = this._uploadPreviews?.get(e);
4558
4663
  if (n) {
4559
- let i = M(t, { allowData: !0 });
4664
+ let i = N(t, { allowData: !0 });
4560
4665
  if (i) n.setAttribute("src", i), n.classList.remove("an-image-uploading"), n.removeAttribute("data-an-upload"), n.style.removeProperty("--an-upload-progress");
4561
4666
  else {
4562
4667
  this._failUpload(e, r?.file, /* @__PURE__ */ Error(`Rejected image URL: ${t}`));
@@ -4648,30 +4753,30 @@ var Lr = class {
4648
4753
  _escapeHTML(e) {
4649
4754
  return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&#039;");
4650
4755
  }
4651
- }, zr = /[^\s\u200B]/;
4652
- function Br(e) {
4756
+ }, Yr = /[^\s\u200B]/;
4757
+ function Xr(e) {
4653
4758
  let t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
4654
- for (let e = t.nextNode(); e; e = t.nextNode()) if (zr.test(e.data)) return !0;
4759
+ for (let e = t.nextNode(); e; e = t.nextNode()) if (Yr.test(e.data)) return !0;
4655
4760
  return !1;
4656
4761
  }
4657
4762
  //#endregion
4658
4763
  //#region src/js/presets/core.js
4659
- var Vr = [
4764
+ var Zr = [
4660
4765
  {
4661
4766
  name: "editor",
4662
- Class: Er
4767
+ Class: Vr
4663
4768
  },
4664
4769
  {
4665
4770
  name: "toolbar",
4666
- Class: Ar
4771
+ Class: Gr
4667
4772
  },
4668
4773
  {
4669
4774
  name: "statusbar",
4670
- Class: Lr
4775
+ Class: qr
4671
4776
  },
4672
4777
  {
4673
4778
  name: "clipboard",
4674
- Class: Rr
4779
+ Class: Jr
4675
4780
  },
4676
4781
  {
4677
4782
  name: "placeholder",
@@ -4689,47 +4794,47 @@ var Vr = [
4689
4794
  this._disposers.forEach((e) => e()), this._disposers = [];
4690
4795
  }
4691
4796
  _update() {
4692
- let e = this.context.layoutInfo.editable, t = document.activeElement === e, n = !Br(e) && !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");
4693
4798
  e.classList.toggle("an-placeholder", n && !t);
4694
4799
  }
4695
4800
  }
4696
4801
  }
4697
- ];
4802
+ ], Qr = "2.7.0";
4698
4803
  //#endregion
4699
4804
  //#region src/js/core/lists.js
4700
- function Hr(e) {
4805
+ function $r(e) {
4701
4806
  return e[e.length - 1];
4702
4807
  }
4703
- function Ur(e) {
4808
+ function ei(e) {
4704
4809
  return e[0];
4705
4810
  }
4706
- function Wr(e, t = 1) {
4811
+ function ti(e, t = 1) {
4707
4812
  return e.slice(0, e.length - t);
4708
4813
  }
4709
- function Gr(e, t = 1) {
4814
+ function ni(e, t = 1) {
4710
4815
  return e.slice(t);
4711
4816
  }
4712
- function Kr(e) {
4817
+ function ri(e) {
4713
4818
  return e.flat();
4714
4819
  }
4715
- function qr(e) {
4820
+ function ii(e) {
4716
4821
  return [...new Set(e)];
4717
4822
  }
4718
- function Jr(e, t) {
4823
+ function ai(e, t) {
4719
4824
  let n = [];
4720
4825
  for (let r = 0; r < e.length; r += t) n.push(e.slice(r, r + t));
4721
4826
  return n;
4722
4827
  }
4723
- function Yr(e, t) {
4828
+ function oi(e, t) {
4724
4829
  return e.reduce((e, n) => {
4725
4830
  let r = t(n);
4726
4831
  return e[r] || (e[r] = []), e[r].push(n), e;
4727
4832
  }, {});
4728
4833
  }
4729
- function Xr(e, t) {
4834
+ function si(e, t) {
4730
4835
  return e.every(t);
4731
4836
  }
4732
- function Zr(e, t) {
4837
+ function ci(e, t) {
4733
4838
  return e.some(t);
4734
4839
  }
4735
4840
  //#endregion
@@ -4737,7 +4842,7 @@ function Zr(e, t) {
4737
4842
  function Q() {
4738
4843
  return globalThis.navigator?.userAgent ?? "";
4739
4844
  }
4740
- var Qr = {
4845
+ var li = {
4741
4846
  get isChrome() {
4742
4847
  return /Chrome\//.test(Q()) && !/Edg\//.test(Q());
4743
4848
  },
@@ -4762,17 +4867,19 @@ var Qr = {
4762
4867
  get modifierKey() {
4763
4868
  return /Macintosh/.test(Q()) ? "metaKey" : "ctrlKey";
4764
4869
  }
4765
- }, $r = { ...k }, $ = /* @__PURE__ */ new WeakMap(), ei = {
4870
+ }, ui = { ...A }, $ = /* @__PURE__ */ new WeakMap(), di = {
4766
4871
  create(e, t = {}) {
4767
- let n = ti(e).map((e) => {
4872
+ let n = fi(e).map((e) => {
4768
4873
  if ($.has(e)) return $.get(e);
4769
- let n = new Cn(e, t);
4770
- 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;
4771
4878
  });
4772
4879
  return n.length === 1 ? n[0] : n;
4773
4880
  },
4774
4881
  destroy(e) {
4775
- ti(e).forEach((e) => {
4882
+ fi(e).forEach((e) => {
4776
4883
  let t = $.get(e);
4777
4884
  t && (t.destroy(), $.delete(e));
4778
4885
  });
@@ -4782,48 +4889,48 @@ var Qr = {
4782
4889
  return t && $.get(t) || null;
4783
4890
  },
4784
4891
  get defaults() {
4785
- return { ...k };
4892
+ return { ...A };
4786
4893
  },
4787
4894
  setDefaults(e) {
4788
- Object.assign(k, e);
4895
+ Object.assign(A, e);
4789
4896
  },
4790
4897
  resetDefaults() {
4791
- Object.keys(k).forEach((e) => delete k[e]), Object.assign(k, $r);
4898
+ Object.keys(A).forEach((e) => delete A[e]), Object.assign(A, ui);
4792
4899
  },
4793
4900
  registerModule(e, t) {
4794
- bn.set(e, t);
4901
+ Cn.set(e, t);
4795
4902
  },
4796
4903
  use(e, t = {}) {
4797
4904
  if (!e || typeof e.name != "string") throw TypeError("[AutumnNote] AutumnNote.use: plugin must have a string `name` property.");
4798
- return N.has(e.name) ? (console.warn(`[AutumnNote] Plugin "${e.name}" already registered globally. Skipping.`), this) : (Array.isArray(e.buttons) && e.buttons.forEach((e) => O(e)), N.set(e.name, {
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, {
4799
4906
  plugin: e,
4800
4907
  options: t
4801
4908
  }), this);
4802
4909
  },
4803
4910
  hasPlugin(e) {
4804
- return N.has(e);
4911
+ return P.has(e);
4805
4912
  },
4806
4913
  registerButton(e) {
4807
- return O(e), this;
4914
+ return k(e), this;
4808
4915
  },
4809
4916
  registerLocale(e, t) {
4810
- return $t(e, t), this;
4917
+ return nn(e, t), this;
4811
4918
  },
4812
4919
  registerSlashCommand(e) {
4813
4920
  if (!e?.id || typeof e.run != "function") throw TypeError("[AutumnNote] Slash command requires an id and run(context) function.");
4814
- let t = k.slashCommands, n = t.findIndex((t) => t.id === e.id);
4921
+ let t = A.slashCommands, n = t.findIndex((t) => t.id === e.id);
4815
4922
  return n >= 0 ? t[n] = e : t.push(e), this;
4816
4923
  },
4817
- buttons: Zt,
4818
- version: "2.5.0"
4924
+ buttons: en,
4925
+ version: Qr
4819
4926
  };
4820
- function ti(e) {
4927
+ function fi(e) {
4821
4928
  return typeof e == "string" ? Array.from(document.querySelectorAll(e)) : e instanceof Element ? [e] : e instanceof NodeList || Array.isArray(e) ? Array.from(e) : [];
4822
4929
  }
4823
4930
  //#endregion
4824
4931
  //#region src/js/core.js
4825
- Sn(Vr);
4932
+ Tn(Zr);
4826
4933
  //#endregion
4827
- export { Cn as Context, d as ELEMENT_NODE, br as SUPPORTED_LANGS, f as TEXT_NODE, ye as WrappedRange, D as _buttonRegistry, vt as alignCenterBtn, bt as alignJustifyBtn, _t as alignLeftBtn, yt as alignRightBtn, Xr as all, ae as ancestors, Zr as any, Yt as backColorBtn, dt as boldBtn, Zt as buttons, Kt as checklistBtn, oe as children, Jr as chunk, e as clamp, y as closest, b as closestPara, Bt as codeviewBtn, Ce as collapsedRange, r as compose, x as createElement, xe as currentRange, t as debounce, ei as default, k as defaultOptions, Xt as defaultToolbar, wr as detectLang, It as directionBtn, jt as emojiBtn, Qr as env, Ut as findBtn, Wt as findReplaceBtn, Ur as first, Kr as flatten, Lt as fontFamilyBtn, Pt as fontSizeBtn, Jt as foreColorBtn, be as fromNativeRange, Vt as fullscreenBtn, ut as getButton, Yr as groupBy, Dt as hrBtn, An as htmlToMarkdown, Mt as iconBtn, i as identity, kt as imageBtn, Ct as indentBtn, Wr as initial, Gt as inlineCodeBtn, de as insertAfter, re as isAnchor, v as isEditable, p as isElement, pe as isEmpty, s as isFunction, ie as isImage, _ as isInline, ge as isInsideEditable, F as isKey, ee as isLi, te as isList, zn as isMarkdown, I as isModifier, a as isNil, g as isPara, l as isPlainObject, we as isSelectionInside, o as isString, ne as isTable, m as isText, h as isVoid, ft as italicBtn, P as key, Hr as last, zt as lineHeightBtn, Ot as linkBtn, Qt as locales, ve as makeDraggable, H as markdownToHTML, c as mergeDeep, ce as nextElement, fe as nodeValue, St as olBtn, C as on, wt as outdentBtn, me as outerHtml, Rt as paragraphStyleBtn, he as placeCaret, se as prevElement, qt as printBtn, Se as rangeFromElement, u as rect2bnd, Et as redoBtn, O as registerButton, $t as registerLocale, S as remove, Ft as removeFormatBtn, en as resolveLocale, j as sanitiseHTML, mn as sanitiseToBody, M as sanitiseUrl, Ht as shortcutsBtn, Ee as splitText, mt as strikeBtn, gt as subscriptBtn, ht as superscriptBtn, Nt as tableBtn, Gr as tail, n as throttle, _e as trapFocus, xt as ulBtn, pt as underlineBtn, Tt as undoBtn, qr as unique, le as unwrap, At as videoBtn, Te as withSavedRange, ue as wrap };
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 };
4828
4935
 
4829
4936
  //# sourceMappingURL=autumnnote.core.es.js.map