autumnnote 2.6.0 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,7 +36,7 @@ function s(e) {
36
36
  function c(e, t) {
37
37
  let n = {};
38
38
  for (let t of Object.keys(e)) n[t] = Array.isArray(e[t]) ? [...e[t]] : e[t];
39
- if (l(e) && l(t)) for (let r of Object.keys(t)) l(t[r]) ? n[r] = c(l(e[r]) ? e[r] : {}, t[r]) : Array.isArray(t[r]) ? n[r] = [...t[r]] : n[r] = t[r];
39
+ if (l(e) && l(t)) for (let r of Object.keys(t)) n[r] = l(t[r]) ? c(l(e[r]) ? e[r] : {}, t[r]) : Array.isArray(t[r]) ? [...t[r]] : t[r];
40
40
  return n;
41
41
  }
42
42
  function l(e) {
@@ -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,25 +398,56 @@ 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");
406
- for (let t of e.childNodes) t.nodeType === 1 && t.tagName === "INPUT" || a.appendChild(t.cloneNode(!0));
450
+ for (let t of e.childNodes) (t.nodeType !== 1 || t.tagName !== "INPUT") && a.appendChild(t.cloneNode(!0));
407
451
  if (a.innerHTML = a.innerHTML.replaceAll("​", ""), (!a.hasChildNodes() || !a.textContent.trim()) && (a.innerHTML = "", a.appendChild(document.createTextNode("\xA0"))), i.length > 0) {
408
452
  let e = document.createElement("ul");
409
453
  e.className = "an-checklist", i.forEach((t) => e.appendChild(t)), t.parentNode.insertBefore(e, t.nextSibling);
@@ -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,34 +574,35 @@ 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;
537
581
  n.nodeType === 3 && (n = n.parentElement);
538
582
  let r = n?.closest("ul, ol");
539
- if (r) if (r.classList.contains("an-checklist")) {
540
- if (r.parentNode) {
541
- let t = Array.from(r.children), n = null;
542
- if (t.forEach((e) => {
543
- let t = document.createElement("p");
544
- for (let n of e.childNodes) n.nodeType === 1 && n.tagName === "INPUT" || t.appendChild(n.cloneNode(!0));
545
- t.innerHTML = t.innerHTML.replaceAll("​", "").replaceAll("​", ""), (!t.hasChildNodes() || !t.textContent.trim()) && (t.innerHTML = "", t.appendChild(document.createTextNode("\xA0"))), r.before(t), n ||= t;
546
- }), r.remove(), n) {
583
+ if (r) {
584
+ if (r.classList.contains("an-checklist")) {
585
+ if (r.parentNode) {
586
+ let t = Array.from(r.children), n = null;
587
+ if (t.forEach((e) => {
588
+ let t = document.createElement("p");
589
+ for (let n of e.childNodes) (n.nodeType !== 1 || n.tagName !== "INPUT") && t.appendChild(n.cloneNode(!0));
590
+ t.innerHTML = t.innerHTML.replaceAll("​", "").replaceAll("​", ""), (!t.hasChildNodes() || !t.textContent.trim()) && (t.innerHTML = "", t.appendChild(document.createTextNode("\xA0"))), r.before(t), n ||= t;
591
+ }), r.remove(), n) {
592
+ let t = document.createRange();
593
+ t.setStart(n.firstChild || n, 0), t.collapse(!0), e.removeAllRanges(), e.addRange(t);
594
+ }
595
+ }
596
+ } else {
597
+ let t = E(r, "ul");
598
+ t.classList.add("an-checklist"), ut(t);
599
+ let n = t.querySelector("li");
600
+ if (n) {
547
601
  let t = document.createRange();
548
- t.setStart(n.firstChild || n, 0), t.collapse(!0), e.removeAllRanges(), e.addRange(t);
602
+ t.selectNodeContents(n), t.collapse(!1), e.removeAllRanges(), e.addRange(t);
549
603
  }
550
604
  }
551
605
  } else {
552
- let t = T(r, "ul");
553
- t.classList.add("an-checklist"), st(t);
554
- let n = t.querySelector("li");
555
- if (n) {
556
- let t = document.createRange();
557
- t.selectNodeContents(n), t.collapse(!1), e.removeAllRanges(), e.addRange(t);
558
- }
559
- }
560
- else {
561
606
  let r = n?.closest("[contenteditable=\"true\"]");
562
607
  if (t.collapsed) {
563
608
  let t = /* @__PURE__ */ new Set([
@@ -623,7 +668,7 @@ function ct() {
623
668
  }
624
669
  }
625
670
  }
626
- function lt() {
671
+ function ft() {
627
672
  let e = globalThis.getSelection();
628
673
  if (!e?.rangeCount) return !1;
629
674
  let t = e.getRangeAt(0).commonAncestorContainer;
@@ -631,7 +676,7 @@ function lt() {
631
676
  }
632
677
  //#endregion
633
678
  //#region src/js/module/Buttons.js
634
- function E(e, t, n, r, i, a) {
679
+ function D(e, t, n, r, i, a) {
635
680
  return {
636
681
  name: e,
637
682
  icon: t,
@@ -641,24 +686,24 @@ function E(e, t, n, r, i, a) {
641
686
  isDisabled: a
642
687
  };
643
688
  }
644
- var D = /* @__PURE__ */ new Map();
645
- function O(e) {
689
+ var O = /* @__PURE__ */ new Map();
690
+ function k(e) {
646
691
  if (!e || typeof e.name != "string") {
647
692
  console.warn("[AutumnNote] registerButton: btnDef must have a string `name` property.");
648
693
  return;
649
694
  }
650
- D.has(e.name) && console.warn(`[AutumnNote] registerButton: overwriting existing button "${e.name}".`), D.set(e.name, e);
695
+ O.has(e.name) && console.warn(`[AutumnNote] registerButton: overwriting existing button "${e.name}".`), O.set(e.name, e);
651
696
  }
652
- function ut(e) {
653
- return D.get(e);
697
+ function pt(e) {
698
+ return O.get(e);
654
699
  }
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(), () => {
700
+ 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
701
  if (document.queryCommandState("underline")) return !0;
657
702
  let e = globalThis.getSelection();
658
703
  if (!e?.rangeCount) return !1;
659
704
  let t = e.getRangeAt(0).startContainer;
660
705
  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 = {
706
+ }), _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
707
  name: "table",
663
708
  type: "grid",
664
709
  icon: "table",
@@ -666,7 +711,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
666
711
  action: (e, t, n) => {
667
712
  e.invoke("editor.insertTable", n, t), e.invoke("editor.afterCommand");
668
713
  }
669
- }, Pt = {
714
+ }, Lt = {
670
715
  name: "fontSize",
671
716
  type: "select",
672
717
  tooltip: "Font Size",
@@ -689,7 +734,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
689
734
  "48px",
690
735
  "72px"
691
736
  ],
692
- action: (e, t) => Ge(t, e.layoutInfo.editable),
737
+ action: (e, t) => Ke(t, e.layoutInfo.editable),
693
738
  getValue: (e) => {
694
739
  try {
695
740
  let t = globalThis.getSelection();
@@ -705,14 +750,14 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
705
750
  return "";
706
751
  }
707
752
  }
708
- }, Ft = E("removeFormat", "remove-format", "Remove Format", () => w("removeFormat")), It = E("direction", "direction", "Toggle Text Direction (LTR / RTL)", (e) => {
753
+ }, Rt = D("removeFormat", "remove-format", "Remove Format", () => T("removeFormat")), zt = D("direction", "direction", "Toggle Text Direction (LTR / RTL)", (e) => {
709
754
  let t = e.layoutInfo.editable, n = (t.getAttribute("dir") || "ltr") === "ltr" ? "rtl" : "ltr";
710
755
  t.setAttribute("dir", n), t.style.textAlign = n === "rtl" ? "right" : "left", e.invoke("editor.afterCommand");
711
- }), Lt = {
756
+ }), Bt = {
712
757
  name: "fontFamily",
713
758
  type: "select",
714
759
  tooltip: "Font Family",
715
- action: (e, t) => We(t),
760
+ action: (e, t) => Ge(t),
716
761
  getValue: () => {
717
762
  try {
718
763
  return document.queryCommandValue("fontName") || "";
@@ -720,7 +765,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
720
765
  return "";
721
766
  }
722
767
  }
723
- }, Rt = {
768
+ }, Vt = {
724
769
  name: "paragraphStyle",
725
770
  type: "select",
726
771
  tooltip: "Paragraph Style",
@@ -764,7 +809,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
764
809
  label: "Code"
765
810
  }
766
811
  ],
767
- action: (e, t) => Ke(t),
812
+ action: (e, t) => qe(t),
768
813
  getValue: () => {
769
814
  try {
770
815
  let e = document.queryCommandValue("formatBlock").toLowerCase().replace(/[<>]/g, "");
@@ -773,7 +818,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
773
818
  return "";
774
819
  }
775
820
  }
776
- }, zt = {
821
+ }, Ht = {
777
822
  name: "lineHeight",
778
823
  type: "select",
779
824
  tooltip: "Line Height",
@@ -788,7 +833,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
788
833
  "2.5",
789
834
  "3.0"
790
835
  ],
791
- action: (e, t) => it(t),
836
+ action: (e, t) => st(t),
792
837
  getValue: () => {
793
838
  try {
794
839
  let e = globalThis.getSelection();
@@ -814,116 +859,116 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
814
859
  return "";
815
860
  }
816
861
  }
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 = {
862
+ }, 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
863
  name: "foreColor",
819
864
  type: "colorpicker",
820
865
  icon: "foreColor",
821
866
  tooltip: "Text Color",
822
867
  defaultColor: "#e11d48",
823
- action: (e, t) => He(t)
824
- }, Yt = {
868
+ action: (e, t) => Ue(t)
869
+ }, Qt = {
825
870
  name: "backColor",
826
871
  type: "colorpicker",
827
872
  icon: "backColor",
828
873
  tooltip: "Highlight Color",
829
874
  defaultColor: "#fbbf24",
830
- action: (e, t) => Ue(t)
831
- }, Xt = [
875
+ action: (e, t) => We(t)
876
+ }, $t = [
832
877
  [
833
- Rt,
878
+ Vt,
879
+ Bt,
834
880
  Lt,
835
- Pt,
836
- zt
881
+ Ht
837
882
  ],
838
- [Tt, Et],
883
+ [Ot, kt],
839
884
  [
840
- dt,
841
- ft,
842
- pt,
843
885
  mt,
844
- Gt
845
- ],
846
- [ht, gt],
847
- [Jt, Yt],
848
- [
886
+ ht,
887
+ gt,
849
888
  _t,
850
- vt,
851
- yt,
852
- bt
889
+ Jt
853
890
  ],
891
+ [vt, yt],
892
+ [Zt, Qt],
854
893
  [
894
+ bt,
855
895
  xt,
856
896
  St,
857
- Kt,
858
- Ct,
859
- wt
897
+ Ct
898
+ ],
899
+ [
900
+ wt,
901
+ Tt,
902
+ Yt,
903
+ Et,
904
+ Dt
860
905
  ],
861
906
  [
862
- Dt,
863
- Ot,
864
- kt,
865
907
  At,
866
- Nt,
867
908
  jt,
868
- Mt
909
+ Mt,
910
+ Nt,
911
+ It,
912
+ Pt,
913
+ Ft
869
914
  ],
870
915
  [
871
- Ft,
872
- Bt,
873
- Vt,
916
+ Rt,
874
917
  Ut,
875
- qt,
876
- Ht
918
+ Wt,
919
+ Kt,
920
+ Xt,
921
+ Gt
877
922
  ]
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 = {
923
+ ], en = {
924
+ boldBtn: mt,
925
+ italicBtn: ht,
926
+ underlineBtn: gt,
927
+ strikeBtn: _t,
928
+ superscriptBtn: vt,
929
+ subscriptBtn: yt,
930
+ alignLeftBtn: bt,
931
+ alignCenterBtn: xt,
932
+ alignRightBtn: St,
933
+ alignJustifyBtn: Ct,
934
+ ulBtn: wt,
935
+ olBtn: Tt,
936
+ indentBtn: Et,
937
+ outdentBtn: Dt,
938
+ undoBtn: Ot,
939
+ redoBtn: kt,
940
+ hrBtn: At,
941
+ linkBtn: jt,
942
+ imageBtn: Mt,
943
+ videoBtn: Nt,
944
+ emojiBtn: Pt,
945
+ iconBtn: Ft,
946
+ tableBtn: It,
947
+ fontSizeBtn: Lt,
948
+ removeFormatBtn: Rt,
949
+ directionBtn: zt,
950
+ fontFamilyBtn: Bt,
951
+ paragraphStyleBtn: Vt,
952
+ lineHeightBtn: Ht,
953
+ codeviewBtn: Ut,
954
+ fullscreenBtn: Wt,
955
+ shortcutsBtn: Gt,
956
+ findBtn: Kt,
957
+ findReplaceBtn: qt,
958
+ inlineCodeBtn: Jt,
959
+ checklistBtn: Yt,
960
+ printBtn: Xt,
961
+ foreColorBtn: Zt,
962
+ backColorBtn: Qt,
963
+ defaultToolbar: $t
964
+ }, A = {
920
965
  placeholder: "",
921
966
  height: 200,
922
967
  minHeight: 100,
923
968
  maxHeight: 0,
924
969
  focus: !1,
925
970
  resizable: !0,
926
- toolbar: Xt,
971
+ toolbar: $t,
927
972
  useBootstrap: !1,
928
973
  toolbarButtonClass: "btn btn-sm btn-light",
929
974
  useFontAwesome: !0,
@@ -947,9 +992,12 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
947
992
  theme: "light",
948
993
  codeHighlight: !0,
949
994
  codeHighlightCDN: "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0",
995
+ cspNonce: "",
996
+ externalAssetCrossOrigin: "anonymous",
997
+ externalAssetReferrerPolicy: "no-referrer",
950
998
  markdownPaste: !0,
951
999
  historyLimit: 100,
952
- historyMaxBytes: 10 * 1024 * 1024,
1000
+ historyMaxBytes: 10485760,
953
1001
  defaultFontFamily: "Arial",
954
1002
  defaultFontSize: "14px",
955
1003
  fontFamilies: [
@@ -994,7 +1042,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
994
1042
  collaborationAdapter: null,
995
1043
  imageProcessor: null,
996
1044
  blockIds: !1,
997
- maxPasteSize: 5 * 1024 * 1024,
1045
+ maxPasteSize: 5242880,
998
1046
  minImageSize: 20,
999
1047
  bubbleToolbar: !1,
1000
1048
  bubbleToolbarItems: [
@@ -1007,7 +1055,7 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
1007
1055
  "removeFormat"
1008
1056
  ],
1009
1057
  mention: null
1010
- }, A = {
1058
+ }, j = {
1011
1059
  toolbar: {
1012
1060
  bold: "Bold (Ctrl+B)",
1013
1061
  italic: "Italic (Ctrl+I)",
@@ -1374,23 +1422,23 @@ var dt = E("bold", "bold", "Bold (Ctrl+B)", () => Ie(), () => document.queryComm
1374
1422
  table: "Table",
1375
1423
  image: "Image"
1376
1424
  }
1377
- }, Qt = { en: A };
1378
- function $t(e, t) {
1425
+ }, tn = { en: j };
1426
+ function nn(e, t) {
1379
1427
  if (typeof e != "string" || !e) throw TypeError("[AutumnNote] registerLocale: code must be a non-empty string.");
1380
1428
  if (!t || typeof t != "object") throw TypeError(`[AutumnNote] registerLocale: locale for "${e}" must be an object.`);
1381
- Qt[e] = t;
1429
+ tn[e] = t;
1382
1430
  }
1383
- function en(e) {
1384
- if (!e || e === "en") return A;
1431
+ function rn(e) {
1432
+ if (!e || e === "en") return j;
1385
1433
  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);
1434
+ let t = tn[e];
1435
+ 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
1436
  }
1389
- return typeof e == "object" ? c(c({}, A), e) : A;
1437
+ return typeof e == "object" ? c(c({}, j), e) : j;
1390
1438
  }
1391
1439
  //#endregion
1392
1440
  //#region src/js/core/sanitise.js
1393
- var tn = [
1441
+ var an = [
1394
1442
  "script",
1395
1443
  "style",
1396
1444
  "iframe",
@@ -1413,7 +1461,7 @@ var tn = [
1413
1461
  "mglyph",
1414
1462
  "malignmark",
1415
1463
  "annotation-xml"
1416
- ], nn = /* @__PURE__ */ new Set(["button"]), rn = [
1464
+ ], on = /* @__PURE__ */ new Set(["button"]), sn = [
1417
1465
  "href",
1418
1466
  "src",
1419
1467
  "action",
@@ -1422,11 +1470,11 @@ var tn = [
1422
1470
  "poster",
1423
1471
  "background",
1424
1472
  "srcset"
1425
- ], an = /* @__PURE__ */ new Set([
1473
+ ], cn = /* @__PURE__ */ new Set([
1426
1474
  "poster",
1427
1475
  "background",
1428
1476
  "srcset"
1429
- ]), on = /* @__PURE__ */ new Set(["ping"]), sn = /* @__PURE__ */ new Set([
1477
+ ]), ln = /* @__PURE__ */ new Set(["ping"]), un = /* @__PURE__ */ new Set([
1430
1478
  "color",
1431
1479
  "background-color",
1432
1480
  "font-size",
@@ -1442,31 +1490,31 @@ var tn = [
1442
1490
  "border-color",
1443
1491
  "padding",
1444
1492
  "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([
1493
+ ]), dn = /url\s*\(|image-set\s*\(|src\s*\(|expression\s*\(|@import|javascript:|vbscript:|behavior\s*:|-moz-binding/i, fn = /* @__PURE__ */ new Set([
1446
1494
  "www.youtube.com",
1447
1495
  "youtube.com",
1448
1496
  "m.youtube.com",
1449
1497
  "www.youtube-nocookie.com",
1450
1498
  "youtube-nocookie.com",
1451
1499
  "player.vimeo.com"
1452
- ]), un = /* @__PURE__ */ new Set([
1500
+ ]), pn = /* @__PURE__ */ new Set([
1453
1501
  "http:",
1454
1502
  "https:",
1455
1503
  "mailto:",
1456
1504
  "tel:"
1457
- ]), dn = /* @__PURE__ */ new Set([
1505
+ ]), mn = /* @__PURE__ */ new Set([
1458
1506
  "http:",
1459
1507
  "https:",
1460
1508
  "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;
1509
+ ]), hn = /^data:image\/(?:png|jpe?g|gif|webp|avif|bmp);base64,[a-z0-9+/=\s]+$/i, gn = "https://autumnnote.invalid/";
1510
+ function M(e, t) {
1511
+ return _n(e, t).innerHTML;
1464
1512
  }
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);
1513
+ function _n(e, { allowIframes: t = !1 } = {}) {
1514
+ 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
1515
  for (let e of r) {
1468
1516
  let t = e.tagName.toLowerCase();
1469
- if (nn.has(t)) {
1517
+ if (on.has(t)) {
1470
1518
  e.replaceWith(...e.childNodes);
1471
1519
  continue;
1472
1520
  }
@@ -1476,7 +1524,7 @@ function mn(e, { allowIframes: t = !1 } = {}) {
1476
1524
  }
1477
1525
  if (t === "iframe") {
1478
1526
  let t = e.getAttribute("src");
1479
- if (!t || !_n(t)) {
1527
+ if (!t || !bn(t)) {
1480
1528
  e.remove();
1481
1529
  continue;
1482
1530
  }
@@ -1487,22 +1535,22 @@ function mn(e, { allowIframes: t = !1 } = {}) {
1487
1535
  continue;
1488
1536
  }
1489
1537
  if (t.name === "style") {
1490
- let n = hn(t.value);
1538
+ let n = vn(t.value);
1491
1539
  n ? e.setAttribute("style", n) : e.removeAttribute("style");
1492
1540
  continue;
1493
1541
  }
1494
- if (on.has(t.name)) {
1542
+ if (ln.has(t.name)) {
1495
1543
  e.removeAttribute(t.name);
1496
1544
  continue;
1497
1545
  }
1498
- if (rn.includes(t.name)) {
1499
- let n = t.value.trim(), r = an.has(t.name) || t.name === "src" && [
1546
+ if (sn.includes(t.name)) {
1547
+ let n = t.value.trim(), r = cn.has(t.name) || t.name === "src" && [
1500
1548
  "IMG",
1501
1549
  "VIDEO",
1502
1550
  "AUDIO",
1503
1551
  "SOURCE"
1504
1552
  ].includes(e.tagName), i = e.tagName === "IMG";
1505
- if (!(t.name === "srcset" ? gn(n, { allowData: i }) : vn(n, {
1553
+ if (!(t.name === "srcset" ? yn(n, { allowData: i }) : xn(n, {
1506
1554
  media: r,
1507
1555
  allowData: i
1508
1556
  }))) {
@@ -1515,70 +1563,72 @@ function mn(e, { allowIframes: t = !1 } = {}) {
1515
1563
  e.removeAttribute(t.name);
1516
1564
  continue;
1517
1565
  }
1518
- t.name === "src" && !_n(t.value) && e.removeAttribute(t.name);
1566
+ t.name === "src" && !bn(t.value) && e.removeAttribute(t.name);
1519
1567
  }
1520
1568
  }
1521
- if (t === "a" && e.getAttribute("target") === "_blank" && e.setAttribute("rel", "noopener noreferrer"), t === "input") if (!(e.closest("ul.an-checklist") !== null && e.closest("li") !== null) || e.getAttribute("type") !== "checkbox") e.remove();
1522
- else for (let t of Array.from(e.attributes)) [
1523
- "type",
1524
- "checked",
1525
- "contenteditable"
1526
- ].includes(t.name) || e.removeAttribute(t.name);
1569
+ if (t === "a" && e.getAttribute("target") === "_blank" && e.setAttribute("rel", "noopener noreferrer"), t === "input") {
1570
+ if (e.closest("ul.an-checklist") === null || e.closest("li") === null || e.getAttribute("type") !== "checkbox") e.remove();
1571
+ else for (let t of Array.from(e.attributes)) [
1572
+ "type",
1573
+ "checked",
1574
+ "contenteditable"
1575
+ ].includes(t.name) || e.removeAttribute(t.name);
1576
+ }
1527
1577
  }
1528
1578
  return n.body;
1529
1579
  }
1530
- function hn(e) {
1580
+ function vn(e) {
1531
1581
  let t = [];
1532
1582
  for (let n of (e || "").split(";")) {
1533
1583
  let e = n.indexOf(":");
1534
1584
  if (e === -1) continue;
1535
1585
  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}`));
1586
+ !r || !i || un.has(r) && (dn.test(i) || t.push(`${r}: ${i}`));
1537
1587
  }
1538
1588
  return t.join("; ");
1539
1589
  }
1540
- function gn(e, { allowData: t = !1 } = {}) {
1590
+ function yn(e, { allowData: t = !1 } = {}) {
1541
1591
  let n = (e || "").trim().split(/\s+/).filter(Boolean);
1542
1592
  for (let e of n) {
1543
1593
  if (/^[\d.]+[xw],?$/i.test(e)) continue;
1544
1594
  let n = e.replace(/,+$/, "");
1545
- if (n && !vn(n, {
1595
+ if (n && !xn(n, {
1546
1596
  media: !0,
1547
1597
  allowData: t
1548
1598
  })) return !1;
1549
1599
  }
1550
1600
  return !0;
1551
1601
  }
1552
- function _n(e) {
1602
+ function bn(e) {
1553
1603
  let t = (e || "").trim();
1554
1604
  if (!t || t.startsWith("//") || t.startsWith("/")) return !1;
1555
1605
  try {
1556
1606
  let e = new URL(t);
1557
- return e.protocol === "https:" && ln.has(e.hostname.toLowerCase());
1607
+ return e.protocol === "https:" && fn.has(e.hostname.toLowerCase());
1558
1608
  } catch {
1559
1609
  return !1;
1560
1610
  }
1561
1611
  }
1562
- function M(e, { allowData: t = !1, media: n = t } = {}) {
1612
+ function N(e, { allowData: t = !1, media: n = t } = {}) {
1563
1613
  let r = (e || "").trim();
1564
- return !r && e == null ? null : vn(r, {
1614
+ return !r && e == null ? null : xn(r, {
1565
1615
  media: n,
1566
1616
  allowData: t
1567
1617
  }) ? e : null;
1568
1618
  }
1569
- function vn(e, { media: t = !1, allowData: n = !1 } = {}) {
1619
+ function xn(e, { media: t = !1, allowData: n = !1 } = {}) {
1570
1620
  let r = (e || "").trim();
1571
- if (!r || n && fn.test(r)) return !0;
1621
+ if (!r || n && hn.test(r)) return !0;
1572
1622
  try {
1573
- let e = new URL(r, pn);
1574
- return (t ? dn : un).has(e.protocol);
1623
+ let e = new URL(r, gn);
1624
+ return (t ? mn : pn).has(e.protocol);
1575
1625
  } catch {
1576
1626
  return !1;
1577
1627
  }
1578
1628
  }
1579
1629
  //#endregion
1580
1630
  //#region src/js/renderer.js
1581
- function yn(e, t) {
1631
+ function Sn(e, t) {
1582
1632
  let n = x("div", { class: "an-container" }), r = x("div", {
1583
1633
  class: "an-editable",
1584
1634
  contenteditable: t.readOnly ? "false" : "true",
@@ -1590,7 +1640,7 @@ function yn(e, t) {
1590
1640
  if (t.autoSave && t.autoSaveKey) try {
1591
1641
  i = localStorage.getItem(t.autoSaveKey) || "";
1592
1642
  } catch {}
1593
- i ||= e.tagName === "TEXTAREA" ? (e.value || "").trim() : (e.innerHTML || "").trim(), r.innerHTML = j(i, { allowIframes: !0 });
1643
+ i ||= e.tagName === "TEXTAREA" ? (e.value || "").trim() : (e.innerHTML || "").trim(), r.innerHTML = M(i, { allowIframes: !0 });
1594
1644
  let a = t.defaultFontFamily || t.fontFamilies?.[0];
1595
1645
  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
1646
  e.setAttribute("disabled", "");
@@ -1601,16 +1651,16 @@ function yn(e, t) {
1601
1651
  }
1602
1652
  //#endregion
1603
1653
  //#region src/js/Context.js
1604
- var bn = /* @__PURE__ */ new Map(), xn = [];
1605
- function Sn(e) {
1606
- xn = Array.isArray(e) ? e : [];
1654
+ var Cn = /* @__PURE__ */ new Map(), wn = [];
1655
+ function Tn(e) {
1656
+ wn = Array.isArray(e) ? e : [];
1607
1657
  }
1608
- var N = /* @__PURE__ */ new Map(), Cn = class {
1658
+ var P = /* @__PURE__ */ new Map(), En = class {
1609
1659
  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;
1660
+ 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
1661
  }
1612
1662
  initialize() {
1613
- let { container: e, editable: t } = yn(this.targetEl, this.options);
1663
+ let { container: e, editable: t } = Sn(this.targetEl, this.options);
1614
1664
  this.layoutInfo.container = e, this.layoutInfo.editable = t, this._registerModules();
1615
1665
  let n = this._modules.get("toolbar");
1616
1666
  n?.el && (e.insertBefore(n.el, t), this.layoutInfo.toolbar = n.el);
@@ -1622,19 +1672,21 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
1622
1672
  let n = new t(this);
1623
1673
  this._modules.set(e, n), n.initialize();
1624
1674
  };
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);
1675
+ for (let { name: t, Class: n, enabled: r } of wn) typeof r == "function" && !r(this.options) || e(t, n);
1676
+ if (Cn.size > 0) for (let [t, n] of Cn) e(t, n);
1627
1677
  }
1628
1678
  _syncOptionalModules() {
1629
- for (let { name: e, Class: t, enabled: n } of xn) {
1679
+ for (let { name: e, Class: t, enabled: n } of wn) {
1630
1680
  if (typeof n != "function") continue;
1631
1681
  let r = n(this.options);
1632
- if (r !== this._modules.has(e)) if (r) {
1633
- let n = new t(this);
1634
- this._modules.set(e, n), n.initialize();
1635
- } else {
1636
- let t = this._modules.get(e);
1637
- typeof t?.destroy == "function" && t.destroy(), this._modules.delete(e);
1682
+ if (r !== this._modules.has(e)) {
1683
+ if (r) {
1684
+ let n = new t(this);
1685
+ this._modules.set(e, n), n.initialize();
1686
+ } else {
1687
+ let t = this._modules.get(e);
1688
+ typeof t?.destroy == "function" && t.destroy(), this._modules.delete(e);
1689
+ }
1638
1690
  }
1639
1691
  }
1640
1692
  }
@@ -1649,7 +1701,7 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
1649
1701
  return n >= 0 ? t[n] = e : t.push(e), this.invoke("slashMenu.refresh"), this;
1650
1702
  }
1651
1703
  use(e, t = {}) {
1652
- return Array.isArray(e.buttons) && e.buttons.forEach((e) => O(e)), this._installPlugin(e, t), this;
1704
+ return Array.isArray(e.buttons) && e.buttons.forEach((e) => k(e)), this._installPlugin(e, t), this;
1653
1705
  }
1654
1706
  getPlugin(e) {
1655
1707
  return this._plugins.get(e)?.publicApi ?? null;
@@ -1671,7 +1723,7 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
1671
1723
  });
1672
1724
  }
1673
1725
  _applyGlobalPlugins() {
1674
- if (N.size !== 0) for (let { plugin: e, options: t } of N.values()) this._installPlugin(e, t);
1726
+ if (P.size !== 0) for (let { plugin: e, options: t } of P.values()) this._installPlugin(e, t);
1675
1727
  }
1676
1728
  _bindEditorEvents(e) {
1677
1729
  let t = C(e, "input", () => this._syncToTarget()), n = C(e, "focus", () => {
@@ -1917,15 +1969,23 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
1917
1969
  } catch {}
1918
1970
  this._plugins.clear(), this._disposers.forEach((e) => e()), this._disposers = [];
1919
1971
  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(() => {
1972
+ 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
1973
  this._listeners.clear();
1922
1974
  }), this._destroyPromise;
1923
1975
  }
1924
1976
  _syncToTarget(e) {
1925
1977
  (this.targetEl.tagName === "TEXTAREA" || this.targetEl.tagName === "INPUT") && (this.targetEl.value = typeof e == "string" ? e : this.getHTML());
1926
1978
  }
1927
- }, wn = class {
1928
- constructor(e, t = 100, n = 10 * 1024 * 1024) {
1979
+ };
1980
+ //#endregion
1981
+ //#region src/js/editing/History.js
1982
+ function Dn(e, t) {
1983
+ let n = Math.min(e.length, t.length), r = 0;
1984
+ for (; r < n && e.charCodeAt(r) === t.charCodeAt(r);) r++;
1985
+ return r;
1986
+ }
1987
+ var On = class {
1988
+ constructor(e, t = 100, n = 10485760) {
1929
1989
  this.editable = e, this._limit = t, this._maxBytes = n, this._bytes = 0, this.stack = [], this.stackOffset = -1, this._savePoint();
1930
1990
  }
1931
1991
  _entrySize(e) {
@@ -1946,12 +2006,12 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
1946
2006
  } : null;
1947
2007
  }
1948
2008
  _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;
2009
+ try {
2010
+ let n = document.createRange();
2011
+ return n.selectNodeContents(this.editable), n.setEnd(e, t), n.toString().length;
2012
+ } catch {
2013
+ return 0;
1953
2014
  }
1954
- return 0;
1955
2015
  }
1956
2016
  _restoreSelection(e) {
1957
2017
  if (!e) return;
@@ -1998,7 +2058,18 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
1998
2058
  this.stackOffset = this.stack.length - 1;
1999
2059
  }
2000
2060
  _restore(e) {
2001
- e && (this.editable.innerHTML = this._detokenizeImages(e), this._restoreSelection(e.sel));
2061
+ if (!e) return;
2062
+ let t = this.editable.textContent || "";
2063
+ this.editable.innerHTML = this._detokenizeImages(e);
2064
+ let n = e.sel;
2065
+ if (!n) {
2066
+ let e = Dn(t, this.editable.textContent || "");
2067
+ n = {
2068
+ start: e,
2069
+ end: e
2070
+ };
2071
+ }
2072
+ this._restoreSelection(n);
2002
2073
  }
2003
2074
  _tokenizeImages(e) {
2004
2075
  if (!e.includes("data:")) return {
@@ -2045,7 +2116,7 @@ var N = /* @__PURE__ */ new Map(), Cn = class {
2045
2116
  };
2046
2117
  //#endregion
2047
2118
  //#region src/js/editing/Table.js
2048
- function Tn(e, t, n = {}) {
2119
+ function kn(e, t, n = {}) {
2049
2120
  let { headerRow: r = !1 } = n, i = x("table", { class: "an-table" });
2050
2121
  if (r && t > 0) {
2051
2122
  let t = x("thead"), n = x("tr");
@@ -2067,9 +2138,9 @@ function Tn(e, t, n = {}) {
2067
2138
  }
2068
2139
  return i;
2069
2140
  }
2070
- function En(e, t, n = {}) {
2141
+ function An(e, t, n = {}) {
2071
2142
  if (e <= 0 || t <= 0) return;
2072
- let r = Tn(e, t, n), i = globalThis.getSelection();
2143
+ let r = kn(e, t, n), i = globalThis.getSelection();
2073
2144
  if (!i || i.rangeCount === 0) return;
2074
2145
  let a = i.getRangeAt(0);
2075
2146
  try {
@@ -2110,7 +2181,7 @@ function En(e, t, n = {}) {
2110
2181
  }
2111
2182
  //#endregion
2112
2183
  //#region src/js/core/key.js
2113
- var P = {
2184
+ var F = {
2114
2185
  BACKSPACE: "Backspace",
2115
2186
  TAB: "Tab",
2116
2187
  ENTER: "Enter",
@@ -2149,16 +2220,36 @@ var P = {
2149
2220
  SLASH: "/",
2150
2221
  PERIOD: "."
2151
2222
  };
2152
- function F(e, t) {
2223
+ function I(e, t) {
2153
2224
  return e.key === t || e.key === t.toUpperCase();
2154
2225
  }
2155
- function I(e, t) {
2156
- return (e.ctrlKey || e.metaKey) && F(e, t);
2226
+ function L(e, t) {
2227
+ return (e.ctrlKey || e.metaKey) && I(e, t);
2157
2228
  }
2158
2229
  //#endregion
2159
2230
  //#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) {
2231
+ var jn = /\bfa-/, R = (e) => !!(e?.nodeName === "I" && jn.test(e.className || "")), z = (e) => !(e?.nodeType !== Node.TEXT_NODE || e.textContent !== "​" && e.textContent !== "");
2232
+ function Mn(e, t, n) {
2233
+ let r = (e?.nodeType === Node.ELEMENT_NODE ? e : e?.parentElement ?? null)?.closest("td, th") ?? null;
2234
+ if (!r || !t.contains(r)) return !1;
2235
+ let i = r.closest("table");
2236
+ if (!i || !t.contains(i)) return !1;
2237
+ let a = Array.from(i.querySelectorAll("td, th")), o = a[a.indexOf(r) + (n ? -1 : 1)];
2238
+ if (o) return he(o), !0;
2239
+ if (n) return !0;
2240
+ let s = Nn(r.closest("tr"))?.firstElementChild ?? null;
2241
+ return s && he(s), !0;
2242
+ }
2243
+ function Nn(e) {
2244
+ if (!e?.parentNode) return null;
2245
+ let t = document.createElement("tr");
2246
+ for (let n of e.cells) {
2247
+ let e = document.createElement("td");
2248
+ e.appendChild(document.createElement("br")), n.hasAttribute("style") && e.setAttribute("style", n.getAttribute("style")), t.appendChild(e);
2249
+ }
2250
+ return e.parentNode.insertBefore(t, e.nextSibling), t;
2251
+ }
2252
+ function Pn(e, t) {
2162
2253
  try {
2163
2254
  let n = document.createRange();
2164
2255
  return n.setStart(e.startContainer, e.startOffset), n.setEnd(t, t.childNodes.length), n.extractContents();
@@ -2166,21 +2257,21 @@ function On(e, t) {
2166
2257
  return document.createDocumentFragment();
2167
2258
  }
2168
2259
  }
2169
- function kn(e, t, n = {}) {
2260
+ function Fn(e, t, n = {}) {
2170
2261
  let r = (e) => {
2171
2262
  let t = globalThis.getSelection();
2172
2263
  if (!t) return !1;
2173
2264
  let n = document.createRange();
2174
2265
  return e(n), n.collapse(!0), t.removeAllRanges(), t.addRange(n), !0;
2175
2266
  };
2176
- if (F(e, P.BACKSPACE)) {
2267
+ if (I(e, F.BACKSPACE)) {
2177
2268
  let t = globalThis.getSelection();
2178
2269
  if (t?.rangeCount > 0) {
2179
2270
  let n = t.getRangeAt(0);
2180
2271
  if (n.collapsed && n.startContainer.nodeType === Node.TEXT_NODE) {
2181
2272
  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)) {
2273
+ if (n.startOffset === 0 && R(r.previousSibling)) return e.preventDefault(), r.previousSibling.remove(), !0;
2274
+ if (n.startOffset === 1 && r.textContent === "​" && R(r.previousSibling)) {
2184
2275
  e.preventDefault();
2185
2276
  let n = r.parentNode, i = r.previousSibling, a = i.previousSibling;
2186
2277
  i.remove(), r.remove();
@@ -2191,17 +2282,17 @@ function kn(e, t, n = {}) {
2191
2282
  }
2192
2283
  return !1;
2193
2284
  }
2194
- if (F(e, P.LEFT) || F(e, P.RIGHT)) {
2285
+ if (I(e, F.LEFT) || I(e, F.RIGHT)) {
2195
2286
  let t = globalThis.getSelection();
2196
2287
  if (!t || t.rangeCount === 0) return !1;
2197
2288
  let n = t.getRangeAt(0);
2198
2289
  if (!n.collapsed) return !1;
2199
- let i = n.startContainer, a = F(e, P.LEFT);
2290
+ let i = n.startContainer, a = I(e, F.LEFT);
2200
2291
  if (i.nodeType === Node.TEXT_NODE) {
2201
2292
  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)) {
2293
+ 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));
2294
+ if (a && n.startOffset === 0 && z(t.previousSibling) && R(t.previousSibling.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(t.previousSibling.previousSibling));
2295
+ if (!a && n.startOffset === t.textContent.length && R(t.nextSibling)) {
2205
2296
  let n = t.nextSibling, i = n.nextSibling;
2206
2297
  if (e.preventDefault(), i?.nodeType === Node.TEXT_NODE) {
2207
2298
  let e = +!!(i.textContent || "").startsWith("​");
@@ -2209,7 +2300,7 @@ function kn(e, t, n = {}) {
2209
2300
  }
2210
2301
  return r((e) => e.setStartAfter(n));
2211
2302
  }
2212
- if (!a && n.startOffset === t.textContent.length && R(t.nextSibling) && L(t.nextSibling.nextSibling)) {
2303
+ if (!a && n.startOffset === t.textContent.length && z(t.nextSibling) && R(t.nextSibling.nextSibling)) {
2213
2304
  let n = t.nextSibling.nextSibling, i = n.nextSibling;
2214
2305
  if (e.preventDefault(), i?.nodeType === Node.TEXT_NODE) {
2215
2306
  let e = +!!(i.textContent || "").startsWith("​");
@@ -2222,12 +2313,12 @@ function kn(e, t, n = {}) {
2222
2313
  let t = i;
2223
2314
  if (a && n.startOffset > 0) {
2224
2315
  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));
2316
+ if (R(i)) return e.preventDefault(), r((e) => e.setStartBefore(i));
2317
+ if (z(i) && R(i.previousSibling)) return e.preventDefault(), r((e) => e.setStartBefore(i.previousSibling));
2227
2318
  }
2228
2319
  if (!a && n.startOffset < t.childNodes.length) {
2229
2320
  let i = t.childNodes[n.startOffset];
2230
- if (L(i)) {
2321
+ if (R(i)) {
2231
2322
  let t = i.nextSibling;
2232
2323
  if (e.preventDefault(), t?.nodeType === Node.TEXT_NODE) {
2233
2324
  let e = +!!(t.textContent || "").startsWith("​");
@@ -2235,7 +2326,7 @@ function kn(e, t, n = {}) {
2235
2326
  }
2236
2327
  return r((e) => e.setStartAfter(i));
2237
2328
  }
2238
- if (R(i) && L(i.nextSibling)) {
2329
+ if (z(i) && R(i.nextSibling)) {
2239
2330
  let t = i.nextSibling, n = t.nextSibling;
2240
2331
  if (e.preventDefault(), n?.nodeType === Node.TEXT_NODE) {
2241
2332
  let e = +!!(n.textContent || "").startsWith("​");
@@ -2246,16 +2337,17 @@ function kn(e, t, n = {}) {
2246
2337
  }
2247
2338
  }
2248
2339
  }
2249
- if (F(e, P.TAB)) {
2340
+ if (I(e, F.TAB)) {
2250
2341
  let r = xe(t);
2251
2342
  if (!r) return !1;
2343
+ if (Mn(r.sc, t, e.shiftKey)) return e.preventDefault(), !0;
2252
2344
  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);
2345
+ if (i && ee(i)) return e.preventDefault(), e.shiftKey ? et() : Qe(), !0;
2346
+ if (i?.nodeName.toUpperCase() === "PRE") return !e.shiftKey && (e.preventDefault(), T("insertText", " ".repeat(n.tabSize || 4)), !0);
2347
+ if (n.tabSize) return !e.shiftKey && (e.preventDefault(), T("insertText", " ".repeat(n.tabSize)), !0);
2256
2348
  }
2257
- if (F(e, P.ENTER) && e.shiftKey) return e.preventDefault(), w("insertLineBreak"), !0;
2258
- if (F(e, P.ENTER) && !e.shiftKey) {
2349
+ if (I(e, F.ENTER) && e.shiftKey) return e.preventDefault(), T("insertLineBreak"), !0;
2350
+ if (I(e, F.ENTER) && !e.shiftKey) {
2259
2351
  let n = xe(t);
2260
2352
  if (!n) return !1;
2261
2353
  let r = n.sc, i = r.nodeType === 3 ? r.parentElement : r;
@@ -2279,7 +2371,7 @@ function kn(e, t, n = {}) {
2279
2371
  if (o) {
2280
2372
  e.preventDefault();
2281
2373
  let t = o.closest(".an-checklist"), n = globalThis.getSelection(), r = n.getRangeAt(0);
2282
- if (!((e) => Array.from(e.childNodes).filter((e) => !(e.nodeType === 1 && e.tagName === "INPUT")).map((e) => e.textContent).join("").replace(/[\u00a0\u200B]/g, " ").trim())(o)) {
2374
+ if (!((e) => Array.from(e.childNodes).filter((e) => e.nodeType !== 1 || e.tagName !== "INPUT").map((e) => e.textContent).join("").replace(/[\u00a0\u200B]/g, " ").trim())(o)) {
2283
2375
  let e = document.createElement("p");
2284
2376
  e.innerHTML = "\xA0", t.parentNode.insertBefore(e, t.nextSibling), o.remove(), t.children.length === 0 && t.remove();
2285
2377
  let r = document.createRange();
@@ -2289,7 +2381,7 @@ function kn(e, t, n = {}) {
2289
2381
  if (r.deleteContents(), n.rangeCount === 0 || !o.isConnected) return !0;
2290
2382
  r = n.getRangeAt(0);
2291
2383
  }
2292
- let i = On(r, o), a = document.createElement("li"), s = document.createElement("input");
2384
+ let i = Pn(r, o), a = document.createElement("li"), s = document.createElement("input");
2293
2385
  s.type = "checkbox", s.setAttribute("contenteditable", "false"), a.appendChild(s), i.textContent.replace(/[\u00a0\u200B]/g, "").length > 0 && a.appendChild(i);
2294
2386
  let c = a.childNodes[1];
2295
2387
  c?.nodeType !== Node.TEXT_NODE && (c = document.createTextNode("​"), a.appendChild(c)), o.after(a);
@@ -2297,23 +2389,107 @@ function kn(e, t, n = {}) {
2297
2389
  return l.setStart(c, 0), l.collapse(!0), n.removeAllRanges(), n.addRange(l), !0;
2298
2390
  }
2299
2391
  let s = b(n.sc, t);
2300
- if (s?.nodeName.toUpperCase() === "PRE") return e.preventDefault(), w("insertText", "\n"), !0;
2392
+ if (s?.nodeName.toUpperCase() === "PRE") return e.preventDefault(), T("insertText", "\n"), !0;
2301
2393
  if (s?.nodeName.toUpperCase() === "BLOCKQUOTE") {
2302
2394
  let t = n.toNativeRange();
2303
- if (t.setEnd(s, s.childNodes.length), t.toString() === "" && n.isCollapsed()) return e.preventDefault(), w("formatBlock", "<p>"), !0;
2395
+ if (t.setEnd(s, s.childNodes.length), t.toString() === "" && n.isCollapsed()) return e.preventDefault(), T("formatBlock", "<p>"), !0;
2304
2396
  }
2305
2397
  }
2306
2398
  return !1;
2307
2399
  }
2308
2400
  //#endregion
2401
+ //#region src/js/core/count.js
2402
+ var B = typeof Intl < "u" && typeof Intl.Segmenter == "function" ? new Intl.Segmenter(void 0, { granularity: "word" }) : null;
2403
+ function In(e) {
2404
+ let t = e.trim();
2405
+ if (!t) return 0;
2406
+ if (B) {
2407
+ let e = 0;
2408
+ for (let n of B.segment(t)) n.isWordLike && e++;
2409
+ return e;
2410
+ }
2411
+ return t.split(/\s+/).length;
2412
+ }
2413
+ 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("."));
2414
+ function Rn(e, t, n) {
2415
+ for (let r = e.firstChild; r; r = r.nextSibling) if (r.nodeType === 3) {
2416
+ let e = r.data;
2417
+ t.push(e), n.push(e);
2418
+ } else if (r.nodeType === 1) {
2419
+ let e = Ln.has(r.tagName);
2420
+ e && t.push("\n"), Rn(r, t, n), e && t.push("\n");
2421
+ }
2422
+ }
2423
+ function zn(e) {
2424
+ if (e.nodeType === 3) {
2425
+ let t = e.data;
2426
+ return {
2427
+ lines: t,
2428
+ flat: t
2429
+ };
2430
+ }
2431
+ let t = [], n = [];
2432
+ return Rn(e, t, n), {
2433
+ lines: t.join(""),
2434
+ flat: n.join("")
2435
+ };
2436
+ }
2437
+ var Bn = class {
2438
+ constructor() {
2439
+ this._cache = /* @__PURE__ */ new WeakMap();
2440
+ }
2441
+ counts(e) {
2442
+ let t = 0, n = 0, r = [], i = [], a = 0;
2443
+ for (let o = e.firstChild; o; o = o.nextSibling) {
2444
+ let e = this._cache.get(o);
2445
+ if (e && e.key === (o.textContent || "")) {
2446
+ t += e.words, n += e.chars;
2447
+ continue;
2448
+ }
2449
+ let { lines: s, flat: c } = zn(o);
2450
+ r.push({
2451
+ node: o,
2452
+ key: c,
2453
+ text: s,
2454
+ start: a
2455
+ }), i.push(s), a += s.length + 1;
2456
+ }
2457
+ if (r.length) {
2458
+ let e = Vn(r, i.join("\n"));
2459
+ r.forEach((r, i) => {
2460
+ let a = {
2461
+ key: r.key,
2462
+ words: e[i],
2463
+ chars: r.key.replaceAll("\n", "").length
2464
+ };
2465
+ this._cache.set(r.node, a), t += a.words, n += a.chars;
2466
+ });
2467
+ }
2468
+ return {
2469
+ words: t,
2470
+ chars: n
2471
+ };
2472
+ }
2473
+ };
2474
+ function Vn(e, t) {
2475
+ if (!B) return e.map((e) => In(e.text));
2476
+ let n = Array(e.length).fill(0), r = 0;
2477
+ for (let i of B.segment(t)) if (i.isWordLike) {
2478
+ for (; r < e.length - 1 && i.index >= e[r + 1].start;) r++;
2479
+ n[r]++;
2480
+ }
2481
+ return n;
2482
+ }
2483
+ //#endregion
2309
2484
  //#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();
2485
+ function Hn(e) {
2486
+ let t = new DOMParser().parseFromString(`<body>${e || ""}</body>`, "text/html");
2487
+ return ge(t.body), Yn(t.body).replace(/\n{3,}/g, "\n\n").trim();
2312
2488
  }
2313
- function z(e, t) {
2489
+ function V(e, t) {
2314
2490
  return Array.from(e.children).filter((e) => e.tagName === t.toUpperCase());
2315
2491
  }
2316
- function jn(e) {
2492
+ function Un(e) {
2317
2493
  let t = "";
2318
2494
  for (let n of e.childNodes) {
2319
2495
  if (n.nodeType === 3) {
@@ -2327,40 +2503,40 @@ function jn(e) {
2327
2503
  continue;
2328
2504
  }
2329
2505
  if (e === "div" || e === "p") {
2330
- t && !t.endsWith("\n") && (t += "\n"), t += jn(n), t += "\n";
2506
+ t && !t.endsWith("\n") && (t += "\n"), t += Un(n), t += "\n";
2331
2507
  continue;
2332
2508
  }
2333
- t += jn(n);
2509
+ t += Un(n);
2334
2510
  }
2335
2511
  return t;
2336
2512
  }
2337
- function Mn(e) {
2513
+ function Wn(e) {
2338
2514
  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
2515
  }
2340
- function Nn(e) {
2516
+ function Gn(e) {
2341
2517
  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
2518
  }
2343
- function Pn(e) {
2344
- return e.split("\n").map(Nn).join("\n");
2519
+ function Kn(e) {
2520
+ return e.split("\n").map(Gn).join("\n");
2345
2521
  }
2346
- function Fn(e, t) {
2522
+ function qn(e, t) {
2347
2523
  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");
2524
+ return Yn(e, t + 1).trim().split("\n").map((e, t) => t === 0 || e.trim() === "" || e.startsWith(n) ? e : n + e).join("\n");
2349
2525
  }
2350
- function In(e, t) {
2526
+ function Jn(e, t) {
2351
2527
  let n = e.getAttribute(t) || "", r = /[\s()]/.test(n) ? `<${n}>` : n, i = e.getAttribute("title");
2352
2528
  return i ? `${r} "${i.replaceAll("\"", String.raw`\"`)}"` : r;
2353
2529
  }
2354
- function Ln(e, t = 0) {
2530
+ function Yn(e, t = 0) {
2355
2531
  if (e.nodeType === 3) {
2356
2532
  let t = e.textContent.replace(/\s+/g, " ");
2357
- return e.parentElement?.closest("pre, code") ? t : Mn(t);
2533
+ return e.parentElement?.closest("pre, code") ? t : Wn(t);
2358
2534
  }
2359
2535
  if (e.nodeType !== 1) return "";
2360
- let n = e, r = n.nodeName.toLowerCase(), i = () => Array.from(n.childNodes).map((e) => Ln(e, t)).join("");
2536
+ let n = e, r = n.nodeName.toLowerCase(), i = () => Array.from(n.childNodes).map((e) => Yn(e, t)).join("");
2361
2537
  switch (r) {
2362
2538
  case "p":
2363
- case "div": return `\n\n${Pn(i())}\n\n`;
2539
+ case "div": return `\n\n${Kn(i())}\n\n`;
2364
2540
  case "br": return " \n";
2365
2541
  case "h1": return `\n\n# ${i()}\n\n`;
2366
2542
  case "h2": return `\n\n## ${i()}\n\n`;
@@ -2389,27 +2565,27 @@ function Ln(e, t = 0) {
2389
2565
  }
2390
2566
  case "pre": {
2391
2567
  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`;
2568
+ return `\n\n\`\`\`${t ? t[1] : ""}\n${Un(e || n).replace(/\n$/, "")}\n\`\`\`\n\n`;
2393
2569
  }
2394
2570
  case "blockquote": {
2395
2571
  let e = i().trim().split("\n");
2396
2572
  return `\n\n${e.filter((t, n) => t.trim() !== "" || (e[n - 1] ?? "").trim() !== "").map((e) => e.trim() === "" ? ">" : `> ${e}`).join("\n")}\n\n`;
2397
2573
  }
2398
- case "a": return `[${i()}](${In(n, "href")})`;
2399
- case "img": return `![${Mn(n.getAttribute("alt") || "")}](${In(n, "src")})`;
2574
+ case "a": return `[${i()}](${Jn(n, "href")})`;
2575
+ case "img": return `![${Wn(n.getAttribute("alt") || "")}](${Jn(n, "src")})`;
2400
2576
  case "ul": {
2401
- let e = z(n, "li");
2577
+ let e = V(n, "li");
2402
2578
  if (!e.length) return i();
2403
2579
  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)}`;
2580
+ let n = V(e, "input").find((e) => e.getAttribute("type") === "checkbox"), i = "- ";
2581
+ return (a || n) && (i = n && n.checked ? "- [x] " : "- [ ] "), `${r}${i}${qn(e, t)}`;
2406
2582
  }).join("\n");
2407
2583
  return t === 0 ? `\n\n${o}\n\n` : `\n${o}`;
2408
2584
  }
2409
2585
  case "ol": {
2410
- let e = z(n, "li");
2586
+ let e = V(n, "li");
2411
2587
  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");
2588
+ 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
2589
  return t === 0 ? `\n\n${s}\n\n` : `\n${s}`;
2414
2590
  }
2415
2591
  case "li": return i();
@@ -2417,7 +2593,7 @@ function Ln(e, t = 0) {
2417
2593
  case "table": {
2418
2594
  let e = Array.from(n.querySelectorAll("tr"));
2419
2595
  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) => {
2596
+ 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
2597
  let t = [...e];
2422
2598
  for (; t.length < a;) t.push("");
2423
2599
  return t;
@@ -2432,16 +2608,16 @@ function Ln(e, t = 0) {
2432
2608
  default: return i();
2433
2609
  }
2434
2610
  }
2435
- function Rn(e) {
2611
+ function Xn(e) {
2436
2612
  return String(e ?? "").replace(/^\ufeff/, "");
2437
2613
  }
2438
- function zn(e) {
2439
- let t = Rn(e);
2614
+ function Zn(e) {
2615
+ let t = Xn(e);
2440
2616
  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
2617
  }
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);
2618
+ var H = /^ {0,3}>( ?)(.*)$/, Qn = /^(?: {4}|\t)\s*\S/, $n = /^( {0,3})(`{3,}|~{3,})[ \t]*([^\s`~][^\n]*)?$/;
2619
+ function U(e) {
2620
+ let t = $n.exec(e);
2445
2621
  if (!t) return null;
2446
2622
  let [, n, r, i = ""] = t;
2447
2623
  return r[0] === "`" && i.includes("`") ? null : {
@@ -2451,7 +2627,7 @@ function V(e) {
2451
2627
  lang: i.trim().split(/\s+/)[0] || ""
2452
2628
  };
2453
2629
  }
2454
- function Hn(e, t) {
2630
+ function er(e, t) {
2455
2631
  let n = 0, r = 0;
2456
2632
  for (; r < e.length && n < t;) {
2457
2633
  if (e[r] === " ") {
@@ -2468,40 +2644,40 @@ function Hn(e, t) {
2468
2644
  }
2469
2645
  return e.slice(r);
2470
2646
  }
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);
2647
+ var tr = /^ {0,3}([-*_])( *\1){2,}\s*$/, nr = "";
2648
+ function rr(e) {
2649
+ let t = Xn(e).replaceAll("\r\n", "\n").replaceAll("\r", "\n").split("\n");
2650
+ t = sr(t);
2651
+ let n = cr(t);
2652
+ return t = n.clean, ar = n.linkDefs, or = n.footnoteIds, ir(t);
2477
2653
  }
2478
- function Gn(e) {
2654
+ function ir(e) {
2479
2655
  let t = [], n = 0;
2480
2656
  for (; n < e.length;) {
2481
- let r = e[n], i = V(r);
2657
+ let r = e[n], i = U(r);
2482
2658
  if (i) {
2483
2659
  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++;
2660
+ for (n++; n < e.length && !r.test(e[n]);) a.push(Ar(er(e[n], i.indent))), n++;
2485
2661
  let o = i.lang ? ` class="language-${q(i.lang)}"` : "";
2486
2662
  t.push(`<pre><code${o}>${a.join("\n")}</code></pre>`), n++;
2487
2663
  continue;
2488
2664
  }
2489
- if (Bn.test(r)) {
2665
+ if (Qn.test(r)) {
2490
2666
  let r = [];
2491
- for (; n < e.length && (Bn.test(e[n]) || e[n].trim() === "");) {
2667
+ for (; n < e.length && (Qn.test(e[n]) || e[n].trim() === "");) {
2492
2668
  if (e[n].trim() === "") {
2493
2669
  let t = n;
2494
2670
  for (; t < e.length && e[t].trim() === "";) t++;
2495
- if (t >= e.length || !Bn.test(e[t])) break;
2671
+ if (t >= e.length || !Qn.test(e[t])) break;
2496
2672
  for (; n < t; n++) r.push("");
2497
2673
  continue;
2498
2674
  }
2499
- r.push(hr(Hn(e[n], 4))), n++;
2675
+ r.push(Ar(er(e[n], 4))), n++;
2500
2676
  }
2501
2677
  t.push(`<pre><code>${r.join("\n")}</code></pre>`);
2502
2678
  continue;
2503
2679
  }
2504
- if (r.trim() && !Un.test(r) && !/^#{1,6} /.test(r) && n + 1 < e.length) {
2680
+ if (r.trim() && !tr.test(r) && !/^#{1,6} /.test(r) && n + 1 < e.length) {
2505
2681
  if (/^=+\s*$/.test(e[n + 1])) {
2506
2682
  t.push(`<h1>${K(r.trim())}</h1>`), n += 2;
2507
2683
  continue;
@@ -2511,7 +2687,7 @@ function Gn(e) {
2511
2687
  continue;
2512
2688
  }
2513
2689
  }
2514
- if (Un.test(r)) {
2690
+ if (tr.test(r)) {
2515
2691
  t.push("<hr>"), n++;
2516
2692
  continue;
2517
2693
  }
@@ -2521,19 +2697,19 @@ function Gn(e) {
2521
2697
  t.push(`<h${e}>${K(r)}</h${e}>`), n++;
2522
2698
  continue;
2523
2699
  }
2524
- if (B.test(r)) {
2700
+ if (H.test(r)) {
2525
2701
  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>`);
2702
+ for (; n < e.length && H.test(e[n]);) r.push(H.exec(e[n])[2]), n++;
2703
+ t.push(`<blockquote>${ir(r)}</blockquote>`);
2528
2704
  continue;
2529
2705
  }
2530
2706
  if (/^[-*+] /.test(r)) {
2531
- let { html: r, endIdx: i } = $n(e, n);
2707
+ let { html: r, endIdx: i } = pr(e, n);
2532
2708
  t.push(r), n = i;
2533
2709
  continue;
2534
2710
  }
2535
2711
  if (/^\d+[.)] /.test(r)) {
2536
- let { html: r, endIdx: i } = $n(e, n);
2712
+ let { html: r, endIdx: i } = pr(e, n);
2537
2713
  t.push(r), n = i;
2538
2714
  continue;
2539
2715
  }
@@ -2541,23 +2717,23 @@ function Gn(e) {
2541
2717
  n++;
2542
2718
  continue;
2543
2719
  }
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);
2720
+ if (fr(e, n)) {
2721
+ let i = W(r), a = W(e[n + 1]).map((e) => e.startsWith(":") && e.endsWith(":") ? "center" : e.endsWith(":") ? "right" : e.startsWith(":") ? "left" : null);
2546
2722
  n += 2;
2547
2723
  let o = [];
2548
- for (; n < e.length && e[n].trim() !== "" && Zn(e[n]) > 1;) o.push(U(e[n])), n++;
2724
+ for (; n < e.length && e[n].trim() !== "" && dr(e[n]);) o.push(W(e[n])), n++;
2549
2725
  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
2726
  t.push(`<table>${c}${l}</table>`);
2551
2727
  continue;
2552
2728
  }
2553
2729
  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++);
2730
+ 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++;
2731
+ o.length ? t.push(`<p>${K(lr(o)).replaceAll(nr, "<br>")}</p>`) : (t.push(`<p>${K(r)}</p>`), n++);
2556
2732
  }
2557
2733
  return t.join("");
2558
2734
  }
2559
- var Kn = /* @__PURE__ */ new Map(), qn = /* @__PURE__ */ new Set();
2560
- function Jn(e) {
2735
+ var ar = /* @__PURE__ */ new Map(), or = /* @__PURE__ */ new Set();
2736
+ function sr(e) {
2561
2737
  if ((e[0] || "").trim() !== "---") return e;
2562
2738
  let t = -1;
2563
2739
  for (let n = 1; n < e.length; n++) {
@@ -2571,14 +2747,14 @@ function Jn(e) {
2571
2747
  let n = t + 1;
2572
2748
  return e[n] !== void 0 && e[n].trim() === "" && n++, e.slice(n);
2573
2749
  }
2574
- function Yn(e) {
2750
+ function cr(e) {
2575
2751
  let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = [], i = !1, a = /^\[([^\]]+)\]:\s*(\S+)(?:\s+"([^"]*)")?\s*$/, o = /^\[\^([^\]]+)\]:[ \t]*(\S.*)$/;
2576
2752
  for (let s of e) {
2577
2753
  if (i) {
2578
2754
  /^ {0,3}(?:`{3,}|~{3,})[ \t]*$/.test(s) && (i = !1), r.push(s);
2579
2755
  continue;
2580
2756
  }
2581
- if (V(s)) {
2757
+ if (U(s)) {
2582
2758
  i = !0, r.push(s);
2583
2759
  continue;
2584
2760
  }
@@ -2605,33 +2781,36 @@ function Yn(e) {
2605
2781
  footnoteIds: n
2606
2782
  };
2607
2783
  }
2608
- function Xn(e) {
2784
+ function lr(e) {
2609
2785
  let t = "";
2610
2786
  for (let n = 0; n < e.length; n++) {
2611
2787
  let r = n === e.length - 1, i = e[n].replace(/^[ \t]+/, "");
2612
2788
  if (!r && /\\$/.test(i)) {
2613
- t += i.replace(/\\$/, "") + Wn;
2789
+ t += i.replace(/\\$/, "") + nr;
2614
2790
  continue;
2615
2791
  }
2616
2792
  if (!r && / {2,}$/.test(i)) {
2617
- t += i.replace(/ {2,}$/, "") + Wn;
2793
+ t += i.replace(/ {2,}$/, "") + nr;
2618
2794
  continue;
2619
2795
  }
2620
2796
  t += i + (r ? "" : " ");
2621
2797
  }
2622
2798
  return t;
2623
2799
  }
2624
- function Zn(e) {
2625
- return U(e).length;
2800
+ function ur(e) {
2801
+ return W(e).length;
2802
+ }
2803
+ function dr(e) {
2804
+ return e.includes("|") ? /^\s*\|/.test(e) || ur(e) > 1 : !1;
2626
2805
  }
2627
- function Qn(e, t) {
2806
+ function fr(e, t) {
2628
2807
  let n = e[t], r = e[t + 1];
2629
2808
  if (r === void 0 || !n.includes("|")) return !1;
2630
2809
  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;
2810
+ let i = W(r);
2811
+ return i.length < 2 || !i.every((e) => /^:?-+:?$/.test(e)) ? !1 : ur(n) === i.length;
2633
2812
  }
2634
- function U(e) {
2813
+ function W(e) {
2635
2814
  let t = e.replace(/^\|/, "").replace(/\|$/, ""), n = [], r = "";
2636
2815
  for (let e = 0; e < t.length; e++) {
2637
2816
  if (t[e] === "\\" && t[e + 1] === "|") {
@@ -2646,7 +2825,7 @@ function U(e) {
2646
2825
  }
2647
2826
  return n.push(r), n.map((e) => e.trim());
2648
2827
  }
2649
- function $n(e, t) {
2828
+ function pr(e, t) {
2650
2829
  let n = e[t].match(/^(\s*)/)[1].length, r = /^\s*\d+[.)] /.test(e[t]), i = [], a = null, o = !1, s = !1, c = t;
2651
2830
  for (; c < e.length;) {
2652
2831
  let t = e[c];
@@ -2674,15 +2853,15 @@ function $n(e, t) {
2674
2853
  c++;
2675
2854
  continue;
2676
2855
  }
2677
- let n = (e) => Hn(e, l), r = V(n(t));
2856
+ let n = (e) => er(e, l), r = U(n(t));
2678
2857
  if (r) {
2679
2858
  let t = RegExp(`^ {0,3}\\${r.marker}{${r.length},}[ \t]*$`), a = [n(e[c])];
2680
2859
  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;
2860
+ c < e.length && (a.push(n(e[c])), c++), i[i.length - 1].sub += ir(a), s = !1;
2682
2861
  continue;
2683
2862
  }
2684
2863
  if (/^\s*(?:[-*+]|\d+[.)]) /.test(t)) {
2685
- let t = $n(e, c);
2864
+ let t = pr(e, c);
2686
2865
  i[i.length - 1].sub += t.html, c = t.endIdx, s = !1;
2687
2866
  } else if (s) i[i.length - 1].paras.push(t.trim()), s = !1, c++;
2688
2867
  else {
@@ -2700,32 +2879,32 @@ function $n(e, t) {
2700
2879
  endIdx: c
2701
2880
  };
2702
2881
  }
2703
- var er = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g, W = "\0", G = "", tr = /(`+)([^]*?)\1/g;
2704
- function nr(e) {
2882
+ var mr = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g, G = "\0", hr = "", gr = /(`+)([^]*?)\1/g;
2883
+ function _r(e) {
2705
2884
  let t = [];
2706
2885
  return {
2707
- text: e.replace(tr, (e, n, r) => r === "" ? e : (t.push(r), `${G}${t.length - 1}${G}`)),
2886
+ text: e.replace(gr, (e, n, r) => r === "" ? e : (t.push(r), `${hr}${t.length - 1}${hr}`)),
2708
2887
  codes: t
2709
2888
  };
2710
2889
  }
2711
- function rr(e, t, n) {
2712
- return e.replace(RegExp(`${G}(\\d+)${G}`, "g"), (e, r) => {
2890
+ function vr(e, t, n) {
2891
+ return e.replace(RegExp(`${hr}(\\d+)${hr}`, "g"), (e, r) => {
2713
2892
  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>`;
2893
+ 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
2894
  });
2716
2895
  }
2717
- function ir(e) {
2896
+ function yr(e) {
2718
2897
  let t = [];
2719
2898
  return {
2720
- text: e.replace(er, (e, n) => (t.push(n), `${W}${t.length - 1}${W}`)),
2899
+ text: e.replace(mr, (e, n) => (t.push(n), `${G}${t.length - 1}${G}`)),
2721
2900
  literals: t
2722
2901
  };
2723
2902
  }
2724
- function ar(e, t) {
2725
- return e.replace(RegExp(`${W}(\\d+)${W}`, "g"), (e, n) => mr(t[Number(n)]));
2903
+ function br(e, t) {
2904
+ return e.replace(RegExp(`${G}(\\d+)${G}`, "g"), (e, n) => kr(t[Number(n)]));
2726
2905
  }
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) {
2906
+ var xr = String.raw`(&lt;.*?&gt;(?:\s+(?:"[^"]*"|'[^']*'))?|[^)]*)`, Sr = new RegExp(String.raw`!\[([^\]]*)\]\(${xr}\)`, "g"), Cr = new RegExp(String.raw`\[([^\]]+)\]\(${xr}\)`, "g");
2907
+ function wr(e) {
2729
2908
  let t = e.trim(), n = /^&lt;([\s\S]*?)&gt;(?:[ \t]*(?:"([^"]*)"|'([^']*)'))?[ \t]*$/.exec(t);
2730
2909
  if (n) return {
2731
2910
  href: n[1],
@@ -2740,26 +2919,26 @@ function lr(e) {
2740
2919
  title: ""
2741
2920
  };
2742
2921
  }
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)}"` : "";
2922
+ function Tr(e) {
2923
+ return e = e.replace(Sr, (e, t, n) => {
2924
+ let { href: r, title: i } = wr(n), a = i ? ` title="${J(i)}"` : "";
2746
2925
  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)}"` : "";
2926
+ }), e = e.replace(Cr, (e, t, n) => {
2927
+ let { href: r, title: i } = wr(n), a = i ? ` title="${J(i)}"` : "";
2749
2928
  return `<a href="${J(r)}"${a}>${t}</a>`;
2750
2929
  }), e = e.replace(/\[([^\]]+)\]\[([^\]]*)\]/g, (e, t, n) => {
2751
- let r = Kn.get(gr(n || t).trim().toLowerCase());
2930
+ let r = ar.get(jr(n || t).trim().toLowerCase());
2752
2931
  if (!r) return e;
2753
2932
  let i = r.title ? ` title="${q(r.title)}"` : "";
2754
2933
  return `<a href="${q(r.href)}"${i}>${t}</a>`;
2755
2934
  }), e = e.replace(/\[([^\]]+)\]/g, (e, t) => {
2756
- let n = Kn.get(gr(t).trim().toLowerCase());
2935
+ let n = ar.get(jr(t).trim().toLowerCase());
2757
2936
  if (!n) return e;
2758
2937
  let r = n.title ? ` title="${q(n.title)}"` : "";
2759
2938
  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;
2939
+ }), e = e.replace(/\[\^([^\]]+)\]/g, (e, t) => or.has(jr(t)) ? `<sup>[${t}]</sup>` : e), e;
2761
2940
  }
2762
- function dr(e) {
2941
+ function Er(e) {
2763
2942
  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
2943
  let r = /[.,;:!?)]+$/.exec(n), i = r ? n.slice(0, -r[0].length) : n;
2765
2944
  if (!i) return e;
@@ -2767,18 +2946,18 @@ function dr(e) {
2767
2946
  return `${t}<a href="${J(i)}">${i}</a>${a}`;
2768
2947
  }), e;
2769
2948
  }
2770
- function fr(e) {
2949
+ function Dr(e) {
2771
2950
  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
2951
  }
2773
2952
  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);
2953
+ let { text: t, literals: n } = yr(e), { text: r, codes: i } = _r(t), a = kr(r);
2954
+ return a = Tr(a), a = Er(a), a = Dr(a), vr(br(a, n), i, n);
2776
2955
  }
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;");
2956
+ var Or = /&(?!#\d+;|#[xX][0-9a-fA-F]+;|[a-zA-Z][a-zA-Z0-9]*;)/g;
2957
+ function kr(e) {
2958
+ return String(e).replace(Or, "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2780
2959
  }
2781
- function hr(e) {
2960
+ function Ar(e) {
2782
2961
  return String(e).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2783
2962
  }
2784
2963
  function q(e) {
@@ -2787,16 +2966,16 @@ function q(e) {
2787
2966
  function J(e) {
2788
2967
  return String(e).replaceAll("\"", "&quot;").replaceAll("'", "&#39;");
2789
2968
  }
2790
- function gr(e) {
2969
+ function jr(e) {
2791
2970
  return String(e).replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&amp;", "&");
2792
2971
  }
2793
2972
  //#endregion
2794
2973
  //#region src/js/core/detectLang.js
2795
- var _r = 5, vr = 2, yr = [
2974
+ var Mr = 5, Nr = 2, Pr = [
2796
2975
  ["typescript", "javascript"],
2797
2976
  ["scss", "css"],
2798
2977
  ["cpp", "c"]
2799
- ], br = [
2978
+ ], Fr = [
2800
2979
  "javascript",
2801
2980
  "typescript",
2802
2981
  "python",
@@ -2819,7 +2998,7 @@ var _r = 5, vr = 2, yr = [
2819
2998
  "scss",
2820
2999
  "css",
2821
3000
  "bash"
2822
- ], xr = [
3001
+ ], Ir = [
2823
3002
  {
2824
3003
  lang: "php",
2825
3004
  w: 10,
@@ -3385,27 +3564,27 @@ var _r = 5, vr = 2, yr = [
3385
3564
  w: 3,
3386
3565
  re: /\s\|[ \t]*\w|\s&&\s|\s2>&1|\s-[\w-]+\s/
3387
3566
  }
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");
3567
+ ], Lr = 4e3;
3568
+ function Rr(e) {
3569
+ if (e.length <= Lr) return e;
3570
+ let t = e.slice(0, Lr), n = t.lastIndexOf("\n");
3392
3571
  return n > 0 ? t.slice(0, n) : t;
3393
3572
  }
3394
- function wr(e) {
3573
+ function zr(e) {
3395
3574
  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);
3575
+ let t = Rr(e.trim()), n = /* @__PURE__ */ new Map();
3576
+ for (let { lang: e, re: r, w: i } of Ir) r.test(t) && n.set(e, (n.get(e) || 0) + i);
3398
3577
  if (n.size === 0) return null;
3399
- for (let [e, t] of yr) {
3578
+ for (let [e, t] of Pr) {
3400
3579
  let r = n.get(e);
3401
3580
  r && n.set(e, r + (n.get(t) || 0));
3402
3581
  }
3403
3582
  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;
3583
+ return a < Mr || a - o < Nr ? null : i;
3405
3584
  }
3406
3585
  //#endregion
3407
3586
  //#region src/js/module/Editor.js
3408
- var Tr = /* @__PURE__ */ new Set([
3587
+ var Br = /* @__PURE__ */ new Set([
3409
3588
  "PRE",
3410
3589
  "BLOCKQUOTE",
3411
3590
  "TABLE",
@@ -3413,13 +3592,13 @@ var Tr = /* @__PURE__ */ new Set([
3413
3592
  "UL",
3414
3593
  "OL",
3415
3594
  "HR"
3416
- ]), Er = class {
3595
+ ]), Vr = class {
3417
3596
  constructor(e) {
3418
- this.context = e, this.options = e.options, this._history = null, this._disposers = [], this._snapshotTimer = null;
3597
+ this.context = e, this.options = e.options, this._history = null, this._disposers = [], this._snapshotTimer = null, this._limitCounter = null;
3419
3598
  }
3420
3599
  initialize() {
3421
3600
  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;
3601
+ return this._history = new On(e, this.options.historyLimit || 100, this.options.historyMaxBytes || 10485760), this._bindEvents(e), this;
3423
3602
  }
3424
3603
  destroy() {
3425
3604
  this._disposers.forEach((e) => e()), this._disposers = [], this._history = null, clearTimeout(this._snapshotTimer), this._snapshotTimer = null;
@@ -3496,32 +3675,32 @@ var Tr = /* @__PURE__ */ new Set([
3496
3675
  }
3497
3676
  _onKeydown(e) {
3498
3677
  let t = this.context.layoutInfo.editable;
3499
- if (!kn(e, t, this.options)) {
3500
- if (I(e, "z") && !e.shiftKey) {
3678
+ if (!Fn(e, t, this.options)) {
3679
+ if (L(e, "z") && !e.shiftKey) {
3501
3680
  e.preventDefault(), this.undo();
3502
3681
  return;
3503
3682
  }
3504
- if (I(e, "z") && e.shiftKey || I(e, "y")) {
3683
+ if (L(e, "z") && e.shiftKey || L(e, "y")) {
3505
3684
  e.preventDefault(), this.redo();
3506
3685
  return;
3507
3686
  }
3508
- if (I(e, "b")) {
3687
+ if (L(e, "b")) {
3509
3688
  e.preventDefault(), this.bold();
3510
3689
  return;
3511
3690
  }
3512
- if (I(e, "i")) {
3691
+ if (L(e, "i")) {
3513
3692
  e.preventDefault(), this.italic();
3514
3693
  return;
3515
3694
  }
3516
- if (I(e, "u")) {
3695
+ if (L(e, "u")) {
3517
3696
  e.preventDefault(), this.underline();
3518
3697
  return;
3519
3698
  }
3520
- if (I(e, "k")) {
3699
+ if (L(e, "k")) {
3521
3700
  e.preventDefault(), this.context.invoke("linkDialog.show");
3522
3701
  return;
3523
3702
  }
3524
- if (I(e, "v") && e.shiftKey) {
3703
+ if (L(e, "v") && e.shiftKey) {
3525
3704
  this.context.invoke("clipboard.setForcePlain", !0);
3526
3705
  return;
3527
3706
  }
@@ -3529,24 +3708,25 @@ var Tr = /* @__PURE__ */ new Set([
3529
3708
  e.preventDefault(), this.context.invoke("shortcutsDialog.show");
3530
3709
  return;
3531
3710
  }
3532
- if (I(e, "f")) {
3711
+ if (L(e, "f")) {
3533
3712
  e.preventDefault(), this.context.invoke("findReplace.show", "find");
3534
3713
  return;
3535
3714
  }
3536
- I(e, "h") && (e.preventDefault(), this.context.invoke("findReplace.show", "replace")), I(e, "`") && (e.preventDefault(), this.inlineCode());
3715
+ L(e, "h") && (e.preventDefault(), this.context.invoke("findReplace.show", "replace")), L(e, "`") && (e.preventDefault(), this.inlineCode());
3537
3716
  }
3538
3717
  }
3539
3718
  _enforceLimit(e) {
3540
3719
  let t = this.options.maxChars || 0, n = this.options.maxWords || 0;
3541
3720
  if (!t && !n) return;
3721
+ this._limitCounter ??= new Bn();
3542
3722
  let r = e.inputType || "";
3543
3723
  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;
3724
+ let { words: i, chars: a } = this._limitCounter.counts(this.context.layoutInfo.editable);
3545
3725
  if (t && a >= t) {
3546
3726
  e.preventDefault(), typeof this.options.onCharLimitReached == "function" && this.options.onCharLimitReached(this.context);
3547
3727
  return;
3548
3728
  }
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));
3729
+ n && (e.data === " " || r === "insertParagraph" || r === "insertLineBreak") && i >= n && (e.preventDefault(), typeof this.options.onWordLimitReached == "function" && this.options.onWordLimitReached(this.context));
3550
3730
  }
3551
3731
  afterCommand() {
3552
3732
  this._cleanOrphanedFigures(), this._ensureTrailingParagraph(), this.context.invoke("toolbar.refresh"), this.context.invoke("statusbar.update"), this._scheduleSnapshot();
@@ -3565,7 +3745,7 @@ var Tr = /* @__PURE__ */ new Set([
3565
3745
  let e = this.context.layoutInfo.editable;
3566
3746
  if (!e) return;
3567
3747
  let t = e.lastElementChild;
3568
- if (t && Tr.has(t.nodeName)) {
3748
+ if (t && Br.has(t.nodeName)) {
3569
3749
  let t = document.createElement("p");
3570
3750
  t.innerHTML = "<br>", e.appendChild(t);
3571
3751
  }
@@ -3578,7 +3758,7 @@ var Tr = /* @__PURE__ */ new Set([
3578
3758
  return this.context.invoke("clipboard.resolveImages", e) ?? e;
3579
3759
  }
3580
3760
  setHTML(e) {
3581
- let t = mn(e, { allowIframes: !0 });
3761
+ let t = _n(e, { allowIframes: !0 });
3582
3762
  this.context.layoutInfo.editable.replaceChildren(...t.childNodes), this._history && this._history.reset(), this.afterCommand();
3583
3763
  }
3584
3764
  getText() {
@@ -3598,16 +3778,16 @@ var Tr = /* @__PURE__ */ new Set([
3598
3778
  return !e && !t;
3599
3779
  }
3600
3780
  insertHTML(e) {
3601
- e && (w("insertHTML", j(e)), this.afterCommand());
3781
+ e && (T("insertHTML", M(e)), this.afterCommand());
3602
3782
  }
3603
3783
  insertText(e) {
3604
- e && (w("insertText", e), this.afterCommand());
3784
+ e && (T("insertText", e), this.afterCommand());
3605
3785
  }
3606
3786
  setMarkdown(e) {
3607
- this.setHTML(H(e || ""));
3787
+ this.setHTML(rr(e || ""));
3608
3788
  }
3609
3789
  getMarkdown() {
3610
- return An(this.getHTML());
3790
+ return Hn(this.getHTML());
3611
3791
  }
3612
3792
  undo() {
3613
3793
  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 +3817,63 @@ var Tr = /* @__PURE__ */ new Set([
3637
3817
  return !e || !this._history ? !1 : (this._history._restoreSelection(e), !0);
3638
3818
  }
3639
3819
  bold() {
3640
- Ie(), this.afterCommand();
3820
+ Le(), this.afterCommand();
3641
3821
  }
3642
3822
  italic() {
3643
- Le(), this.afterCommand();
3823
+ Re(), this.afterCommand();
3644
3824
  }
3645
3825
  underline() {
3646
- Re(), this.afterCommand();
3826
+ ze(), this.afterCommand();
3647
3827
  }
3648
3828
  strikethrough() {
3649
- ze(), this.afterCommand();
3829
+ Be(), this.afterCommand();
3650
3830
  }
3651
3831
  superscript() {
3652
- Be(), this.afterCommand();
3832
+ Ve(), this.afterCommand();
3653
3833
  }
3654
3834
  subscript() {
3655
- Ve(), this.afterCommand();
3835
+ He(), this.afterCommand();
3656
3836
  }
3657
3837
  justifyLeft() {
3658
- qe(), this.afterCommand();
3838
+ Je(), this.afterCommand();
3659
3839
  }
3660
3840
  justifyCenter() {
3661
- Je(), this.afterCommand();
3841
+ Ye(), this.afterCommand();
3662
3842
  }
3663
3843
  justifyRight() {
3664
- Ye(), this.afterCommand();
3844
+ Xe(), this.afterCommand();
3665
3845
  }
3666
3846
  justifyFull() {
3667
- Xe(), this.afterCommand();
3847
+ Ze(), this.afterCommand();
3668
3848
  }
3669
3849
  indent() {
3670
- Ze(), this.afterCommand();
3850
+ Qe(), this.afterCommand();
3671
3851
  }
3672
3852
  outdent() {
3673
- Qe(), this.afterCommand();
3853
+ et(), this.afterCommand();
3674
3854
  }
3675
3855
  insertUL() {
3676
- nt(), this.afterCommand();
3856
+ at(), this.afterCommand();
3677
3857
  }
3678
3858
  insertOL() {
3679
- rt(), this.afterCommand();
3859
+ ot(), this.afterCommand();
3680
3860
  }
3681
3861
  inlineCode() {
3682
- at(this.context.layoutInfo.editable), this.afterCommand();
3862
+ ct(this.context.layoutInfo.editable), this.afterCommand();
3683
3863
  }
3684
3864
  toggleChecklist() {
3685
- ct(), this.afterCommand();
3865
+ dt(), this.afterCommand();
3686
3866
  }
3687
3867
  print() {
3688
3868
  this.context.print();
3689
3869
  }
3690
3870
  formatBlock(e) {
3691
- if (Ke(e), e === "pre") {
3871
+ if (qe(e), e === "pre") {
3692
3872
  let e = globalThis.getSelection();
3693
3873
  if (e?.rangeCount > 0) {
3694
3874
  let t = e.getRangeAt(0).commonAncestorContainer, n = t.nodeType === 1 ? t.closest("pre") : t.parentElement?.closest("pre");
3695
3875
  if (n && !n.dataset.language) {
3696
- let e = wr(n.textContent || "");
3876
+ let e = zr(n.textContent || "");
3697
3877
  if (e) {
3698
3878
  this.context.invoke("codeTooltip.applyLanguage", n, e);
3699
3879
  return;
@@ -3704,55 +3884,55 @@ var Tr = /* @__PURE__ */ new Set([
3704
3884
  this.afterCommand();
3705
3885
  }
3706
3886
  foreColor(e) {
3707
- He(e), this.afterCommand();
3887
+ Ue(e), this.afterCommand();
3708
3888
  }
3709
3889
  backColor(e) {
3710
- Ue(e), this.afterCommand();
3890
+ We(e), this.afterCommand();
3711
3891
  }
3712
3892
  fontName(e) {
3713
- We(e), this.afterCommand();
3893
+ Ge(e), this.afterCommand();
3714
3894
  }
3715
3895
  fontSize(e) {
3716
- Ge(e, this.context.layoutInfo.editable), this.afterCommand();
3896
+ Ke(e, this.context.layoutInfo.editable), this.afterCommand();
3717
3897
  }
3718
3898
  insertHr() {
3719
- w("insertHorizontalRule"), this.afterCommand();
3899
+ T("insertHorizontalRule"), this.afterCommand();
3720
3900
  }
3721
3901
  insertLink(e, t, n = !1) {
3722
3902
  let r = globalThis.getSelection();
3723
3903
  if (!r || r.rangeCount === 0) return;
3724
- let i = M(e);
3904
+ let i = N(e);
3725
3905
  if (i) {
3726
3906
  if (r.toString().trim().length > 0) {
3727
- if (w("createLink", i), n) {
3907
+ if (T("createLink", i), n) {
3728
3908
  let e = this._getClosestAnchor();
3729
3909
  e && (e.setAttribute("target", "_blank"), e.setAttribute("rel", "noopener noreferrer"));
3730
3910
  }
3731
3911
  } else {
3732
3912
  let e = this._escapeAttr(t || i);
3733
- w("insertHTML", `<a href="${this._escapeAttr(i)}"${n ? " target=\"_blank\" rel=\"noopener noreferrer\"" : ""}>${e}</a>`);
3913
+ T("insertHTML", `<a href="${this._escapeAttr(i)}"${n ? " target=\"_blank\" rel=\"noopener noreferrer\"" : ""}>${e}</a>`);
3734
3914
  }
3735
3915
  this.afterCommand();
3736
3916
  }
3737
3917
  }
3738
3918
  unlink() {
3739
- w("unlink"), this.afterCommand();
3919
+ T("unlink"), this.afterCommand();
3740
3920
  }
3741
3921
  insertImage(e, t = "", n = "") {
3742
- let r = M(e, { allowData: !0 });
3922
+ let r = N(e, { allowData: !0 });
3743
3923
  if (!r) return;
3744
3924
  let i = {
3745
3925
  left: "float:left;margin:0 1em 1em 0",
3746
3926
  center: "display:block;margin:0 auto",
3747
3927
  right: "float:right;margin:0 0 1em 1em"
3748
3928
  }[n] || "", a = i ? ` style="${i}"` : "";
3749
- w("insertHTML", `<img src="${this._escapeAttr(r)}" alt="${this._escapeAttr(t)}" class="an-image"${a}>`), this.afterCommand();
3929
+ T("insertHTML", `<img src="${this._escapeAttr(r)}" alt="${this._escapeAttr(t)}" class="an-image"${a}>`), this.afterCommand();
3750
3930
  }
3751
3931
  insertVideo(e) {
3752
- e && (w("insertHTML", e), this.afterCommand());
3932
+ e && (T("insertHTML", e), this.afterCommand());
3753
3933
  }
3754
3934
  insertTable(e, t) {
3755
- En(e, t, { headerRow: this.context.options.tableHeaderRow }), this.afterCommand();
3935
+ An(e, t, { headerRow: this.context.options.tableHeaderRow }), this.afterCommand();
3756
3936
  }
3757
3937
  _getClosestAnchor() {
3758
3938
  let e = globalThis.getSelection();
@@ -3767,7 +3947,7 @@ var Tr = /* @__PURE__ */ new Set([
3767
3947
  _escapeAttr(e) {
3768
3948
  return String(e ?? "").replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
3769
3949
  }
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([
3950
+ }, 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
3951
  ["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
3952
  ["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
3953
  ["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 +3984,7 @@ var Tr = /* @__PURE__ */ new Set([
3804
3984
  ["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
3985
  ["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
3986
  ["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([
3987
+ ]), Wr = /* @__PURE__ */ new Map([
3808
3988
  ["bold", "fa-bold"],
3809
3989
  ["italic", "fa-italic"],
3810
3990
  ["underline", "fa-underline"],
@@ -3838,7 +4018,7 @@ var Tr = /* @__PURE__ */ new Set([
3838
4018
  ["inline-code", "fa-code"],
3839
4019
  ["checklist", "fa-list-check"],
3840
4020
  ["print", "fa-print"]
3841
- ]), Ar = class {
4021
+ ]), Gr = class {
3842
4022
  constructor(e) {
3843
4023
  this.context = e, this.options = e.options, this.el = null, this._disposers = [], this._colorPickerClosers = [], this._refreshRaf = null;
3844
4024
  }
@@ -3848,7 +4028,7 @@ var Tr = /* @__PURE__ */ new Set([
3848
4028
  role: "toolbar",
3849
4029
  "aria-orientation": "horizontal",
3850
4030
  "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;
4031
+ }), 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
4032
  }
3853
4033
  destroy() {
3854
4034
  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 +4038,7 @@ var Tr = /* @__PURE__ */ new Set([
3858
4038
  e.forEach((e) => {
3859
4039
  let n = x("div", { class: "an-btn-group" });
3860
4040
  e.forEach((e) => {
3861
- let t = Dr(e);
4041
+ let t = Hr(e);
3862
4042
  if (!t) {
3863
4043
  console.warn(`[AutumnNote] Toolbar: button "${e}" not found in registry. Skipped.`);
3864
4044
  return;
@@ -3878,7 +4058,7 @@ var Tr = /* @__PURE__ */ new Set([
3878
4058
  "aria-haspopup": "true",
3879
4059
  "aria-expanded": "false"
3880
4060
  });
3881
- this._faReady ? n.innerHTML = `<i class="${this.options.fontAwesomeClass || "fas"} fa-table" aria-hidden="true"></i>` : n.innerHTML = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" style=\"display:block\"><rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"1\"/><line x1=\"3\" y1=\"9\" x2=\"21\" y2=\"9\"/><line x1=\"3\" y1=\"15\" x2=\"21\" y2=\"15\"/><line x1=\"9\" y1=\"3\" x2=\"9\" y2=\"21\"/><line x1=\"15\" y1=\"3\" x2=\"15\" y2=\"21\"/></svg>";
4061
+ n.innerHTML = this._faReady ? `<i class="${this.options.fontAwesomeClass || "fas"} fa-table" aria-hidden="true"></i>` : "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" style=\"display:block\"><rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"1\"/><line x1=\"3\" y1=\"9\" x2=\"21\" y2=\"9\"/><line x1=\"3\" y1=\"15\" x2=\"21\" y2=\"15\"/><line x1=\"9\" y1=\"3\" x2=\"9\" y2=\"21\"/><line x1=\"15\" y1=\"3\" x2=\"15\" y2=\"21\"/></svg>";
3882
4062
  let r = x("div", {
3883
4063
  class: "an-table-picker-popup",
3884
4064
  role: "dialog",
@@ -4077,7 +4257,7 @@ var Tr = /* @__PURE__ */ new Set([
4077
4257
  ...typeof e.isActive == "function" ? { "aria-pressed": "false" } : {}
4078
4258
  }), n = this.options.fontAwesomeClass || "fas";
4079
4259
  if (this._faReady) {
4080
- let r = kr.get(e.icon) || kr.get(e.name) || null;
4260
+ let r = Wr.get(e.icon) || Wr.get(e.name) || null;
4081
4261
  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
4262
  } 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
4263
  let r = C(t, "click", (t) => {
@@ -4159,53 +4339,21 @@ var Tr = /* @__PURE__ */ new Set([
4159
4339
  this.el && (this.el.style.display = "none");
4160
4340
  }
4161
4341
  rebuild() {
4162
- this._refreshRaf &&= (cancelAnimationFrame(this._refreshRaf), null), this._disposers.forEach((e) => e()), this._disposers = [], this.el && (this.el.innerHTML = ""), this._faReady = this._detectFontAwesome(), this._buildButtons(), this._initRovingFocus(), this._btnMap = new Map((this.options.toolbar || []).flat().map(Dr).filter(Boolean).map((e) => [e.name, e])), this.refresh();
4163
- }
4164
- }, jr = typeof Intl < "u" && typeof Intl.Segmenter == "function" ? new Intl.Segmenter(void 0, { granularity: "word" }) : null;
4165
- function Mr(e) {
4166
- let t = e.trim();
4167
- if (!t) return 0;
4168
- if (jr) {
4169
- let e = 0;
4170
- for (let n of jr.segment(t)) n.isWordLike && e++;
4171
- return e;
4172
- }
4173
- return t.split(/\s+/).length;
4174
- }
4175
- var Nr = /* @__PURE__ */ new Set(/* @__PURE__ */ "ADDRESS.ARTICLE.ASIDE.BLOCKQUOTE.BR.DD.DIV.DL.DT.FIELDSET.FIGCAPTION.FIGURE.FOOTER.FORM.H1.H2.H3.H4.H5.H6.HEADER.HR.LI.MAIN.NAV.OL.P.PRE.SECTION.TABLE.TBODY.TD.TFOOT.TH.THEAD.TR.UL".split("."));
4176
- function Pr(e, t, n) {
4177
- for (let r = e.firstChild; r; r = r.nextSibling) if (r.nodeType === 3) {
4178
- let e = r.data;
4179
- t.push(e), n.push(e);
4180
- } else if (r.nodeType === 1) {
4181
- let e = Nr.has(r.tagName);
4182
- e && t.push("\n"), Pr(r, t, n), e && t.push("\n");
4342
+ 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();
4183
4343
  }
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) {
4344
+ };
4345
+ //#endregion
4346
+ //#region src/js/module/Statusbar.js
4347
+ function Kr(e, t, n) {
4200
4348
  if (!n) {
4201
4349
  e.classList.remove("an-count-warn", "an-count-exceeded");
4202
4350
  return;
4203
4351
  }
4204
4352
  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
4353
  }
4206
- var Lr = class {
4354
+ var qr = class {
4207
4355
  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();
4356
+ this.context = e, this.options = e.options, this.el = null, this._disposers = [], this._wordCountEl = null, this._charCountEl = null, this._counter = new Bn();
4209
4357
  }
4210
4358
  initialize() {
4211
4359
  if (this.el = x("div", { class: "an-statusbar" }), this.options.resizable !== !1) {
@@ -4255,50 +4403,12 @@ var Lr = class {
4255
4403
  this._disposers.push(d, f);
4256
4404
  }
4257
4405
  _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;
4406
+ return this._counter.counts(this.context.layoutInfo.editable);
4297
4407
  }
4298
4408
  update() {
4299
4409
  if (!this._wordCountEl || !this._charCountEl) return;
4300
4410
  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);
4411
+ 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
4412
  }
4303
4413
  getWordCount() {
4304
4414
  return this._counts().words;
@@ -4306,7 +4416,7 @@ var Lr = class {
4306
4416
  getCharCount() {
4307
4417
  return this._counts().chars;
4308
4418
  }
4309
- }, Rr = class {
4419
+ }, Jr = class {
4310
4420
  constructor(e) {
4311
4421
  this.context = e, this.options = e.options, this._disposers = [];
4312
4422
  }
@@ -4418,20 +4528,20 @@ var Lr = class {
4418
4528
  text: t.getData("text/plain") || "",
4419
4529
  html: t.types.includes("text/html") ? t.getData("text/html") : null
4420
4530
  }), 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");
4531
+ 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
4532
  return;
4423
4533
  }
4424
4534
  if (this.options.markdownPaste !== !1) {
4425
4535
  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");
4536
+ if (a && i && Zn(a)) {
4537
+ e.preventDefault(), T("insertHTML", M(rr(a))), this.context.invoke("editor.afterCommand");
4428
4538
  return;
4429
4539
  }
4430
4540
  }
4431
4541
  if (this.options.pasteCleanHTML !== !1 && t.types.includes("text/html")) {
4432
4542
  e.preventDefault();
4433
4543
  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");
4544
+ 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
4545
  }
4436
4546
  }
4437
4547
  _onDragover(e) {
@@ -4463,7 +4573,7 @@ var Lr = class {
4463
4573
  }
4464
4574
  let n = new FileReader();
4465
4575
  n.onload = (e) => {
4466
- w("insertHTML", j(H(e.target.result || ""))), this.context.invoke("editor.afterCommand");
4576
+ T("insertHTML", M(rr(e.target.result || ""))), this.context.invoke("editor.afterCommand");
4467
4577
  }, n.onerror = () => {
4468
4578
  let t = `Failed to read dropped markdown file "${e.name}".`;
4469
4579
  console.warn(`[AutumnNote] ${t}`), this.context.triggerEvent("pasteError", { message: t });
@@ -4548,7 +4658,7 @@ var Lr = class {
4548
4658
  file: e
4549
4659
  });
4550
4660
  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;
4661
+ 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
4662
  }
4553
4663
  _findPlaceholder(e) {
4554
4664
  return this.context.layoutInfo.editable?.querySelector(`img[data-an-upload="${e}"]`) ?? null;
@@ -4556,7 +4666,7 @@ var Lr = class {
4556
4666
  _resolveUpload(e, t) {
4557
4667
  let n = this._findPlaceholder(e), r = this._uploadPreviews?.get(e);
4558
4668
  if (n) {
4559
- let i = M(t, { allowData: !0 });
4669
+ let i = N(t, { allowData: !0 });
4560
4670
  if (i) n.setAttribute("src", i), n.classList.remove("an-image-uploading"), n.removeAttribute("data-an-upload"), n.style.removeProperty("--an-upload-progress");
4561
4671
  else {
4562
4672
  this._failUpload(e, r?.file, /* @__PURE__ */ Error(`Rejected image URL: ${t}`));
@@ -4648,30 +4758,30 @@ var Lr = class {
4648
4758
  _escapeHTML(e) {
4649
4759
  return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&#039;");
4650
4760
  }
4651
- }, zr = /[^\s\u200B]/;
4652
- function Br(e) {
4761
+ }, Yr = /[^\s\u200B]/;
4762
+ function Xr(e) {
4653
4763
  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;
4764
+ for (let e = t.nextNode(); e; e = t.nextNode()) if (Yr.test(e.data)) return !0;
4655
4765
  return !1;
4656
4766
  }
4657
4767
  //#endregion
4658
4768
  //#region src/js/presets/core.js
4659
- var Vr = [
4769
+ var Zr = [
4660
4770
  {
4661
4771
  name: "editor",
4662
- Class: Er
4772
+ Class: Vr
4663
4773
  },
4664
4774
  {
4665
4775
  name: "toolbar",
4666
- Class: Ar
4776
+ Class: Gr
4667
4777
  },
4668
4778
  {
4669
4779
  name: "statusbar",
4670
- Class: Lr
4780
+ Class: qr
4671
4781
  },
4672
4782
  {
4673
4783
  name: "clipboard",
4674
- Class: Rr
4784
+ Class: Jr
4675
4785
  },
4676
4786
  {
4677
4787
  name: "placeholder",
@@ -4689,47 +4799,47 @@ var Vr = [
4689
4799
  this._disposers.forEach((e) => e()), this._disposers = [];
4690
4800
  }
4691
4801
  _update() {
4692
- let e = this.context.layoutInfo.editable, t = document.activeElement === e, n = !Br(e) && !e.querySelector("img, table, hr, .an-video-wrapper");
4802
+ let e = this.context.layoutInfo.editable, t = document.activeElement === e, n = !Xr(e) && !e.querySelector("img, table, hr, .an-video-wrapper");
4693
4803
  e.classList.toggle("an-placeholder", n && !t);
4694
4804
  }
4695
4805
  }
4696
4806
  }
4697
- ];
4807
+ ], Qr = "2.7.1";
4698
4808
  //#endregion
4699
4809
  //#region src/js/core/lists.js
4700
- function Hr(e) {
4810
+ function $r(e) {
4701
4811
  return e[e.length - 1];
4702
4812
  }
4703
- function Ur(e) {
4813
+ function ei(e) {
4704
4814
  return e[0];
4705
4815
  }
4706
- function Wr(e, t = 1) {
4816
+ function ti(e, t = 1) {
4707
4817
  return e.slice(0, e.length - t);
4708
4818
  }
4709
- function Gr(e, t = 1) {
4819
+ function ni(e, t = 1) {
4710
4820
  return e.slice(t);
4711
4821
  }
4712
- function Kr(e) {
4822
+ function ri(e) {
4713
4823
  return e.flat();
4714
4824
  }
4715
- function qr(e) {
4825
+ function ii(e) {
4716
4826
  return [...new Set(e)];
4717
4827
  }
4718
- function Jr(e, t) {
4828
+ function ai(e, t) {
4719
4829
  let n = [];
4720
4830
  for (let r = 0; r < e.length; r += t) n.push(e.slice(r, r + t));
4721
4831
  return n;
4722
4832
  }
4723
- function Yr(e, t) {
4833
+ function oi(e, t) {
4724
4834
  return e.reduce((e, n) => {
4725
4835
  let r = t(n);
4726
4836
  return e[r] || (e[r] = []), e[r].push(n), e;
4727
4837
  }, {});
4728
4838
  }
4729
- function Xr(e, t) {
4839
+ function si(e, t) {
4730
4840
  return e.every(t);
4731
4841
  }
4732
- function Zr(e, t) {
4842
+ function ci(e, t) {
4733
4843
  return e.some(t);
4734
4844
  }
4735
4845
  //#endregion
@@ -4737,7 +4847,7 @@ function Zr(e, t) {
4737
4847
  function Q() {
4738
4848
  return globalThis.navigator?.userAgent ?? "";
4739
4849
  }
4740
- var Qr = {
4850
+ var li = {
4741
4851
  get isChrome() {
4742
4852
  return /Chrome\//.test(Q()) && !/Edg\//.test(Q());
4743
4853
  },
@@ -4762,17 +4872,19 @@ var Qr = {
4762
4872
  get modifierKey() {
4763
4873
  return /Macintosh/.test(Q()) ? "metaKey" : "ctrlKey";
4764
4874
  }
4765
- }, $r = { ...k }, $ = /* @__PURE__ */ new WeakMap(), ei = {
4875
+ }, ui = { ...A }, $ = /* @__PURE__ */ new WeakMap(), di = {
4766
4876
  create(e, t = {}) {
4767
- let n = ti(e).map((e) => {
4877
+ let n = fi(e).map((e) => {
4768
4878
  if ($.has(e)) return $.get(e);
4769
- let n = new Cn(e, t);
4770
- return n.initialize(), $.set(e, n), n;
4879
+ let n = new En(e, t);
4880
+ return n._releaseInstance = () => {
4881
+ $.get(e) === n && $.delete(e);
4882
+ }, n.initialize(), $.set(e, n), n;
4771
4883
  });
4772
4884
  return n.length === 1 ? n[0] : n;
4773
4885
  },
4774
4886
  destroy(e) {
4775
- ti(e).forEach((e) => {
4887
+ fi(e).forEach((e) => {
4776
4888
  let t = $.get(e);
4777
4889
  t && (t.destroy(), $.delete(e));
4778
4890
  });
@@ -4782,48 +4894,48 @@ var Qr = {
4782
4894
  return t && $.get(t) || null;
4783
4895
  },
4784
4896
  get defaults() {
4785
- return { ...k };
4897
+ return { ...A };
4786
4898
  },
4787
4899
  setDefaults(e) {
4788
- Object.assign(k, e);
4900
+ Object.assign(A, e);
4789
4901
  },
4790
4902
  resetDefaults() {
4791
- Object.keys(k).forEach((e) => delete k[e]), Object.assign(k, $r);
4903
+ Object.keys(A).forEach((e) => delete A[e]), Object.assign(A, ui);
4792
4904
  },
4793
4905
  registerModule(e, t) {
4794
- bn.set(e, t);
4906
+ Cn.set(e, t);
4795
4907
  },
4796
4908
  use(e, t = {}) {
4797
4909
  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, {
4910
+ 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
4911
  plugin: e,
4800
4912
  options: t
4801
4913
  }), this);
4802
4914
  },
4803
4915
  hasPlugin(e) {
4804
- return N.has(e);
4916
+ return P.has(e);
4805
4917
  },
4806
4918
  registerButton(e) {
4807
- return O(e), this;
4919
+ return k(e), this;
4808
4920
  },
4809
4921
  registerLocale(e, t) {
4810
- return $t(e, t), this;
4922
+ return nn(e, t), this;
4811
4923
  },
4812
4924
  registerSlashCommand(e) {
4813
4925
  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);
4926
+ let t = A.slashCommands, n = t.findIndex((t) => t.id === e.id);
4815
4927
  return n >= 0 ? t[n] = e : t.push(e), this;
4816
4928
  },
4817
- buttons: Zt,
4818
- version: "2.5.0"
4929
+ buttons: en,
4930
+ version: Qr
4819
4931
  };
4820
- function ti(e) {
4932
+ function fi(e) {
4821
4933
  return typeof e == "string" ? Array.from(document.querySelectorAll(e)) : e instanceof Element ? [e] : e instanceof NodeList || Array.isArray(e) ? Array.from(e) : [];
4822
4934
  }
4823
4935
  //#endregion
4824
4936
  //#region src/js/core.js
4825
- Sn(Vr);
4937
+ Tn(Zr);
4826
4938
  //#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 };
4939
+ 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
4940
 
4829
4941
  //# sourceMappingURL=autumnnote.core.es.js.map