autumnnote 1.6.0 → 1.6.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.
Files changed (47) hide show
  1. package/README.md +4 -4
  2. package/dist/autumnnote.css +0 -2
  3. package/dist/autumnnote.es.js +348 -342
  4. package/dist/autumnnote.es.js.map +1 -1
  5. package/dist/autumnnote.umd.js +341 -336
  6. package/dist/autumnnote.umd.js.map +1 -1
  7. package/package.json +21 -3
  8. package/src/js/Context.js +16 -14
  9. package/src/js/core/dom.js +9 -9
  10. package/src/js/core/env.js +1 -1
  11. package/src/js/core/func.js +1 -1
  12. package/src/js/core/lists.js +1 -1
  13. package/src/js/core/markdown.js +18 -18
  14. package/src/js/core/range.js +6 -6
  15. package/src/js/editing/History.js +4 -4
  16. package/src/js/editing/Style.js +32 -32
  17. package/src/js/editing/Table.js +2 -2
  18. package/src/js/editing/Typing.js +15 -15
  19. package/src/js/module/AutoSaveRestore.js +2 -4
  20. package/src/js/module/BubbleToolbar.js +25 -25
  21. package/src/js/module/Buttons.js +4 -4
  22. package/src/js/module/Clipboard.js +12 -13
  23. package/src/js/module/CodeTooltip.js +14 -16
  24. package/src/js/module/Codeview.js +3 -5
  25. package/src/js/module/ContextMenu.js +27 -27
  26. package/src/js/module/Editor.js +17 -18
  27. package/src/js/module/EmojiDialog.js +5 -5
  28. package/src/js/module/FindReplace.js +8 -7
  29. package/src/js/module/IconDialog.js +13 -15
  30. package/src/js/module/ImageCropOverlay.js +7 -7
  31. package/src/js/module/ImageDialog.js +1 -1
  32. package/src/js/module/ImageResizer.js +4 -4
  33. package/src/js/module/ImageTooltip.js +14 -14
  34. package/src/js/module/LinkDialog.js +2 -2
  35. package/src/js/module/LinkTooltip.js +12 -12
  36. package/src/js/module/MarkdownShortcuts.js +11 -14
  37. package/src/js/module/Mention.js +8 -10
  38. package/src/js/module/Placeholder.js +1 -1
  39. package/src/js/module/ShortcutsDialog.js +2 -4
  40. package/src/js/module/Statusbar.js +3 -5
  41. package/src/js/module/TableTooltip.js +30 -32
  42. package/src/js/module/Toolbar.js +21 -21
  43. package/src/js/module/VideoDialog.js +8 -8
  44. package/src/js/module/VideoResizer.js +5 -7
  45. package/src/js/module/VideoTooltip.js +7 -7
  46. package/src/js/renderer.js +1 -1
  47. package/src/styles/autumnnote.scss +0 -3
@@ -114,14 +114,14 @@
114
114
  const handler = (e) => {
115
115
  if (e.key === "Escape") {
116
116
  e.stopPropagation();
117
- onEscape && onEscape();
117
+ onEscape?.();
118
118
  return;
119
119
  }
120
120
  if (e.key !== "Tab") return;
121
121
  const els = getFocusable();
122
122
  if (!els.length) return;
123
123
  const first = els[0];
124
- const last = els[els.length - 1];
124
+ const last = els.at(-1);
125
125
  if (e.shiftKey) {
126
126
  if (document.activeElement === first) {
127
127
  e.preventDefault();
@@ -159,14 +159,14 @@
159
159
  box.style.top = `${r.top}px`;
160
160
  box.dataset.anDragPinned = "1";
161
161
  }
162
- const startX = e.clientX - parseFloat(box.style.left);
163
- const startY = e.clientY - parseFloat(box.style.top);
162
+ const startX = e.clientX - Number.parseFloat(box.style.left);
163
+ const startY = e.clientY - Number.parseFloat(box.style.top);
164
164
  handle.style.cursor = "grabbing";
165
165
  const onMove = (ev) => {
166
166
  const bw = box.offsetWidth;
167
167
  const bh = box.offsetHeight;
168
- box.style.left = `${Math.max(0, Math.min(ev.clientX - startX, window.innerWidth - bw))}px`;
169
- box.style.top = `${Math.max(0, Math.min(ev.clientY - startY, window.innerHeight - bh))}px`;
168
+ box.style.left = `${Math.max(0, Math.min(ev.clientX - startX, globalThis.innerWidth - bw))}px`;
169
+ box.style.top = `${Math.max(0, Math.min(ev.clientY - startY, globalThis.innerHeight - bh))}px`;
170
170
  };
171
171
  const onUp = () => {
172
172
  handle.style.cursor = "grab";
@@ -212,10 +212,10 @@
212
212
  return range;
213
213
  }
214
214
  /**
215
- * Select this wrapped range in the window.
215
+ * Select this wrapped range in the globalThis.
216
216
  */
217
217
  select() {
218
- const sel = window.getSelection();
218
+ const sel = globalThis.getSelection();
219
219
  if (!sel) return;
220
220
  sel.removeAllRanges();
221
221
  sel.addRange(this.toNativeRange());
@@ -268,13 +268,13 @@
268
268
  return new WrappedRange(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
269
269
  }
270
270
  /**
271
- * Returns a WrappedRange for the current window selection,
271
+ * Returns a WrappedRange for the current globalThis selection,
272
272
  * optionally restricted to a given editable element.
273
273
  * @param {HTMLElement} [editable]
274
274
  * @returns {WrappedRange|null}
275
275
  */
276
276
  function currentRange(editable) {
277
- const sel = window.getSelection();
277
+ const sel = globalThis.getSelection();
278
278
  if (!sel || sel.rangeCount === 0) return null;
279
279
  const native = sel.getRangeAt(0);
280
280
  if (editable && !editable.contains(native.commonAncestorContainer)) return null;
@@ -285,7 +285,7 @@
285
285
  * @param {Function} fn
286
286
  */
287
287
  function withSavedRange(fn) {
288
- const sel = window.getSelection();
288
+ const sel = globalThis.getSelection();
289
289
  if (!sel || sel.rangeCount === 0) {
290
290
  fn(null);
291
291
  return;
@@ -320,16 +320,16 @@
320
320
  * execCommand's state detection is unreliable.
321
321
  */
322
322
  function underline() {
323
- const sel = window.getSelection();
323
+ const sel = globalThis.getSelection();
324
324
  if (!sel || !sel.rangeCount) return;
325
325
  let container = sel.getRangeAt(0).commonAncestorContainer;
326
326
  if (container.nodeType === 3) container = container.parentElement;
327
- const uEl = container && container.closest("u");
327
+ const uEl = container?.closest("u");
328
328
  const nativeState = document.queryCommandState("underline");
329
329
  if (uEl && !nativeState) {
330
330
  const parent = uEl.parentNode;
331
331
  while (uEl.firstChild) parent.insertBefore(uEl.firstChild, uEl);
332
- parent.removeChild(uEl);
332
+ uEl.remove();
333
333
  return;
334
334
  }
335
335
  execCommand("underline");
@@ -340,16 +340,16 @@
340
340
  * execCommand's state detection is unreliable (mirrors underline() logic).
341
341
  */
342
342
  function strikethrough() {
343
- const sel = window.getSelection();
343
+ const sel = globalThis.getSelection();
344
344
  if (!sel || !sel.rangeCount) return;
345
345
  let sc = sel.getRangeAt(0).startContainer;
346
346
  if (sc.nodeType === 3) sc = sc.parentElement;
347
- const sEl = sc && (sc.closest("s") || sc.closest("strike"));
347
+ const sEl = sc?.closest("s") || sc?.closest("strike");
348
348
  const nativeState = document.queryCommandState("strikeThrough");
349
349
  if (sEl && !nativeState) {
350
350
  const parent = sEl.parentNode;
351
351
  while (sEl.firstChild) parent.insertBefore(sEl.firstChild, sEl);
352
- parent.removeChild(sEl);
352
+ sEl.remove();
353
353
  return;
354
354
  }
355
355
  execCommand("strikeThrough");
@@ -384,7 +384,7 @@
384
384
  * @param {HTMLElement|Document} [editable] - scoping element to avoid touching nodes outside this editor
385
385
  */
386
386
  function fontSize(size, editable = document) {
387
- const sel = window.getSelection();
387
+ const sel = globalThis.getSelection();
388
388
  const wasCollapsed = !sel || !sel.rangeCount || sel.getRangeAt(0).collapsed;
389
389
  if (wasCollapsed && sel && sel.rangeCount > 0) {
390
390
  try {
@@ -410,12 +410,12 @@
410
410
  span.style.fontSize = size;
411
411
  el.parentNode.insertBefore(span, el);
412
412
  while (el.firstChild) span.appendChild(el.firstChild);
413
- el.parentNode.removeChild(el);
413
+ el.remove();
414
414
  newSpans.push(span);
415
415
  });
416
416
  if (!wasCollapsed && sel && newSpans.length > 0) {
417
417
  const first = newSpans[0];
418
- const last = newSpans[newSpans.length - 1];
418
+ const last = newSpans.at(-1);
419
419
  try {
420
420
  const nr = document.createRange();
421
421
  const startNode = first.firstChild || first;
@@ -459,11 +459,11 @@
459
459
  * (which would destroy the ul > li checklist structure).
460
460
  */
461
461
  function outdent() {
462
- const sel = window.getSelection();
462
+ const sel = globalThis.getSelection();
463
463
  if (sel && sel.rangeCount) {
464
464
  let container = sel.getRangeAt(0).commonAncestorContainer;
465
465
  if (container.nodeType === 3) container = container.parentElement;
466
- const checkLi = container && container.closest(".an-checklist li");
466
+ const checkLi = container?.closest(".an-checklist li");
467
467
  if (checkLi) {
468
468
  _checklistItemToP(checkLi);
469
469
  return;
@@ -493,7 +493,7 @@
493
493
  if (child.nodeType === 1 && child.tagName === "INPUT") continue;
494
494
  p.appendChild(child.cloneNode(true));
495
495
  }
496
- p.innerHTML = p.innerHTML.replace(/\u200B/g, "");
496
+ p.innerHTML = p.innerHTML.replaceAll("​", "");
497
497
  if (!p.hasChildNodes() || !p.textContent.trim()) {
498
498
  p.innerHTML = "";
499
499
  p.appendChild(document.createTextNode("\xA0"));
@@ -505,14 +505,14 @@
505
505
  checkUl.parentNode.insertBefore(newUl, checkUl.nextSibling);
506
506
  }
507
507
  checkUl.parentNode.insertBefore(p, checkUl.nextSibling);
508
- checkUl.removeChild(checkLi);
509
- if (checkUl.children.length === 0) checkUl.parentNode.removeChild(checkUl);
508
+ checkLi.remove();
509
+ if (checkUl.children.length === 0) checkUl.remove();
510
510
  try {
511
511
  const nr = document.createRange();
512
512
  const firstChild = p.firstChild;
513
513
  nr.setStart(firstChild && firstChild.nodeType === 3 ? firstChild : p, 0);
514
514
  nr.collapse(true);
515
- const s = window.getSelection();
515
+ const s = globalThis.getSelection();
516
516
  if (s) {
517
517
  s.removeAllRanges();
518
518
  s.addRange(nr);
@@ -536,7 +536,7 @@
536
536
  * @param {string} value - Line-height value to apply; typically a unitless multiplier (for example, "1.5").
537
537
  */
538
538
  function lineHeight(value) {
539
- const sel = window.getSelection();
539
+ const sel = globalThis.getSelection();
540
540
  if (!sel || sel.rangeCount === 0) return;
541
541
  const range = sel.getRangeAt(0);
542
542
  const BLOCK_TAGS = new Set([
@@ -588,22 +588,22 @@
588
588
  * @param {HTMLElement} [_editable]
589
589
  */
590
590
  function toggleInlineCode(_editable) {
591
- const sel = window.getSelection();
591
+ const sel = globalThis.getSelection();
592
592
  if (!sel || !sel.rangeCount) return;
593
593
  const range = sel.getRangeAt(0);
594
594
  let container = range.commonAncestorContainer;
595
595
  if (container.nodeType === 3) container = container.parentElement;
596
- const codeEl = container && container.closest("code");
596
+ const codeEl = container?.closest("code");
597
597
  if (codeEl && !codeEl.closest("pre")) {
598
598
  const parent = codeEl.parentNode;
599
599
  const prevSibling = codeEl.previousSibling;
600
600
  const movedChildren = Array.from(codeEl.childNodes);
601
601
  while (codeEl.firstChild) parent.insertBefore(codeEl.firstChild, codeEl);
602
- parent.removeChild(codeEl);
603
- if (parent && parent.normalize) parent.normalize();
602
+ codeEl.remove();
603
+ parent?.normalize();
604
604
  if (movedChildren.length > 0) try {
605
605
  const firstMoved = movedChildren[0];
606
- const lastMoved = movedChildren[movedChildren.length - 1];
606
+ const lastMoved = movedChildren.at(-1);
607
607
  const nr = document.createRange();
608
608
  const anchorNode = firstMoved.parentNode === parent ? firstMoved : prevSibling ? prevSibling.nextSibling : parent.firstChild;
609
609
  if (anchorNode) {
@@ -644,11 +644,11 @@
644
644
  * @returns {boolean}
645
645
  */
646
646
  function isInlineCode() {
647
- const sel = window.getSelection();
647
+ const sel = globalThis.getSelection();
648
648
  if (!sel || !sel.rangeCount) return false;
649
649
  let sc = sel.getRangeAt(0).startContainer;
650
650
  if (sc.nodeType === 3) sc = sc.parentElement;
651
- const code = sc && sc.closest("code");
651
+ const code = sc?.closest("code");
652
652
  return !!(code && !code.closest("pre"));
653
653
  }
654
654
  /**
@@ -666,12 +666,12 @@
666
666
  * Empty or whitespace-only selections do not create a checklist.
667
667
  */
668
668
  function toggleChecklist() {
669
- const sel = window.getSelection();
669
+ const sel = globalThis.getSelection();
670
670
  if (!sel || !sel.rangeCount) return;
671
671
  const range = sel.getRangeAt(0);
672
672
  let container = range.commonAncestorContainer;
673
673
  if (container.nodeType === 3) container = container.parentElement;
674
- const ul = container && container.closest(".an-checklist");
674
+ const ul = container?.closest(".an-checklist");
675
675
  if (ul) {
676
676
  const selectedLis = Array.from(ul.querySelectorAll("li")).filter((li) => sel.containsNode(li, true));
677
677
  if (selectedLis.length > 0) {
@@ -682,14 +682,14 @@
682
682
  if (child.nodeType === 1 && child.tagName === "INPUT") continue;
683
683
  p.appendChild(child.cloneNode(true));
684
684
  }
685
- p.innerHTML = p.innerHTML.replace(/\u200b/g, "");
685
+ p.innerHTML = p.innerHTML.replaceAll("​", "");
686
686
  if (!p.hasChildNodes() || !p.textContent.trim()) {
687
687
  p.innerHTML = "";
688
688
  p.appendChild(document.createTextNode("\xA0"));
689
689
  }
690
690
  ul.parentNode.insertBefore(p, ul);
691
691
  if (!firstP) firstP = p;
692
- ul.removeChild(li);
692
+ li.remove();
693
693
  });
694
694
  if (ul.children.length === 0) ul.remove();
695
695
  if (firstP) {
@@ -717,7 +717,7 @@
717
717
  ]);
718
718
  let block = container;
719
719
  while (block && block.parentNode && !BLOCK_TAGS.has(block.tagName)) block = block.parentNode;
720
- const itemText = block && BLOCK_TAGS.has(block.tagName) ? Array.from(block.childNodes).map((n) => n.textContent).join("").replace(/\u00a0/g, " ") : "";
720
+ const itemText = block && BLOCK_TAGS.has(block.tagName) ? Array.from(block.childNodes).map((n) => n.textContent).join("").replaceAll("\xA0", " ") : "";
721
721
  const ul = document.createElement("ul");
722
722
  ul.className = "an-checklist";
723
723
  const li = document.createElement("li");
@@ -788,7 +788,7 @@
788
788
  });
789
789
  const firstBlock = blocks[0];
790
790
  firstBlock.parentNode.insertBefore(newUl, firstBlock);
791
- blocks.forEach((block) => block.parentNode && block.parentNode.removeChild(block));
791
+ blocks.forEach((block) => block.remove());
792
792
  if (lastTextNode) {
793
793
  const nr = document.createRange();
794
794
  nr.setStart(lastTextNode, lastTextNode.textContent.length);
@@ -802,11 +802,11 @@
802
802
  * @returns {boolean}
803
803
  */
804
804
  function isInChecklist() {
805
- const sel = window.getSelection();
805
+ const sel = globalThis.getSelection();
806
806
  if (!sel || !sel.rangeCount) return false;
807
807
  let container = sel.getRangeAt(0).commonAncestorContainer;
808
808
  if (container.nodeType === 3) container = container.parentElement;
809
- return !!(container && container.closest(".an-checklist li"));
809
+ return !!container?.closest(".an-checklist li");
810
810
  }
811
811
  //#endregion
812
812
  //#region src/js/module/Buttons.js
@@ -888,7 +888,7 @@
888
888
  var italicBtn = btn("italic", "italic", "Italic (Ctrl+I)", () => italic(), () => document.queryCommandState("italic"));
889
889
  var underlineBtn = btn("underline", "underline", "Underline (Ctrl+U)", () => underline(), () => {
890
890
  if (document.queryCommandState("underline")) return true;
891
- const sel = window.getSelection();
891
+ const sel = globalThis.getSelection();
892
892
  if (!sel || !sel.rangeCount) return false;
893
893
  let sc = sel.getRangeAt(0).startContainer;
894
894
  if (sc.nodeType === 3) sc = sc.parentElement;
@@ -951,7 +951,7 @@
951
951
  action: (ctx, value) => fontSize(value, ctx.layoutInfo.editable),
952
952
  getValue: (ctx) => {
953
953
  try {
954
- const sel = window.getSelection();
954
+ const sel = globalThis.getSelection();
955
955
  if (sel && sel.rangeCount) {
956
956
  let el = sel.getRangeAt(0).startContainer;
957
957
  if (el && el.nodeType === 3) el = el.parentElement;
@@ -959,7 +959,7 @@
959
959
  const size = el && el.style.fontSize ? el.style.fontSize : "";
960
960
  if (size) return size;
961
961
  }
962
- const editable = ctx && ctx.layoutInfo && ctx.layoutInfo.editable;
962
+ const editable = ctx?.layoutInfo?.editable;
963
963
  if (editable) return editable.style.fontSize || "";
964
964
  return "";
965
965
  } catch {
@@ -1056,7 +1056,7 @@
1056
1056
  action: (_ctx, value) => lineHeight(value),
1057
1057
  getValue: () => {
1058
1058
  try {
1059
- const sel = window.getSelection();
1059
+ const sel = globalThis.getSelection();
1060
1060
  if (!sel || !sel.rangeCount) return "";
1061
1061
  const BLOCKS = new Set([
1062
1062
  "P",
@@ -4171,7 +4171,7 @@
4171
4171
  } catch (_) {}
4172
4172
  if (!initialContent) initialContent = targetEl.tagName === "TEXTAREA" ? (targetEl.value || "").trim() : (targetEl.innerHTML || "").trim();
4173
4173
  editable.innerHTML = sanitiseHTML(initialContent, { allowIframes: true });
4174
- const defaultFont = options.defaultFontFamily || options.fontFamilies && options.fontFamilies[0];
4174
+ const defaultFont = options.defaultFontFamily || options.fontFamilies?.[0];
4175
4175
  if (defaultFont) editable.style.fontFamily = defaultFont;
4176
4176
  if (options.defaultFontSize) editable.style.fontSize = options.defaultFontSize;
4177
4177
  if (options.height) editable.style.minHeight = `${options.height}px`;
@@ -4233,7 +4233,7 @@
4233
4233
  * @returns {{ start: number, end: number }|null}
4234
4234
  */
4235
4235
  _serializeSelection() {
4236
- const sel = window.getSelection();
4236
+ const sel = globalThis.getSelection();
4237
4237
  if (!sel || sel.rangeCount === 0) return null;
4238
4238
  const range = sel.getRangeAt(0);
4239
4239
  if (!this.editable.contains(range.startContainer)) return null;
@@ -4299,7 +4299,7 @@
4299
4299
  const range = document.createRange();
4300
4300
  range.setStart(startNode, startOff);
4301
4301
  range.setEnd(endNode, endOff);
4302
- const sel = window.getSelection();
4302
+ const sel = globalThis.getSelection();
4303
4303
  sel.removeAllRanges();
4304
4304
  sel.addRange(range);
4305
4305
  } catch (_) {
@@ -4307,7 +4307,7 @@
4307
4307
  const fb = document.createRange();
4308
4308
  fb.setStart(this.editable, 0);
4309
4309
  fb.collapse(true);
4310
- const s = window.getSelection();
4310
+ const s = globalThis.getSelection();
4311
4311
  if (s) {
4312
4312
  s.removeAllRanges();
4313
4313
  s.addRange(fb);
@@ -4371,8 +4371,7 @@
4371
4371
  recordUndo() {
4372
4372
  const current = this._serialize();
4373
4373
  const { html: tokenized } = this._tokenizeImages(current);
4374
- const prev = this.stack[this.stackOffset];
4375
- if (prev && prev.html === tokenized) return;
4374
+ if (this.stack[this.stackOffset]?.html === tokenized) return;
4376
4375
  this._savePoint();
4377
4376
  }
4378
4377
  /**
@@ -4456,7 +4455,7 @@
4456
4455
  function insertTable(cols, rows, opts = {}) {
4457
4456
  if (cols <= 0 || rows <= 0) return;
4458
4457
  const table = createTable(cols, rows, opts);
4459
- const sel = window.getSelection();
4458
+ const sel = globalThis.getSelection();
4460
4459
  if (!sel || sel.rangeCount === 0) return;
4461
4460
  const range = sel.getRangeAt(0);
4462
4461
  range.deleteContents();
@@ -4474,7 +4473,7 @@
4474
4473
  "PRE"
4475
4474
  ]);
4476
4475
  let anchor = range.startContainer;
4477
- if (anchor && anchor.nodeType === 3) anchor = anchor.parentElement;
4476
+ if (anchor?.nodeType === 3) anchor = anchor.parentElement;
4478
4477
  while (anchor && !BLOCK.has(anchor.tagName?.toUpperCase()) && anchor.parentElement) anchor = anchor.parentElement;
4479
4478
  if (anchor && BLOCK.has(anchor.tagName?.toUpperCase()) && anchor.parentNode) {
4480
4479
  anchor.after(table);
@@ -4564,8 +4563,8 @@
4564
4563
  * Inspired by Summernote's Typing module
4565
4564
  */
4566
4565
  var _FA_PATTERN = /\bfa-/;
4567
- var isFAIcon = (n) => !!(n && n.nodeName === "I" && _FA_PATTERN.test(n.className || ""));
4568
- var isZwsAnchor = (n) => !!(n && n.nodeType === Node.TEXT_NODE && (n.textContent === "​" || n.textContent === ""));
4566
+ var isFAIcon = (n) => !!(n?.nodeName === "I" && _FA_PATTERN.test(n.className || ""));
4567
+ var isZwsAnchor = (n) => !!(n?.nodeType === Node.TEXT_NODE && (n.textContent === "​" || n.textContent === ""));
4569
4568
  /**
4570
4569
  * Handles special keydown behaviour inside the editor.
4571
4570
  * @param {KeyboardEvent} event
@@ -4575,7 +4574,7 @@
4575
4574
  */
4576
4575
  function handleKeydown(event, editable, options = {}) {
4577
4576
  const moveCaret = (setFn) => {
4578
- const sel = window.getSelection();
4577
+ const sel = globalThis.getSelection();
4579
4578
  if (!sel) return false;
4580
4579
  const nr = document.createRange();
4581
4580
  setFn(nr);
@@ -4585,8 +4584,8 @@
4585
4584
  return true;
4586
4585
  };
4587
4586
  if (isKey(event, key.BACKSPACE)) {
4588
- const sel = window.getSelection();
4589
- if (sel && sel.rangeCount > 0) {
4587
+ const sel = globalThis.getSelection();
4588
+ if (sel?.rangeCount > 0) {
4590
4589
  const r = sel.getRangeAt(0);
4591
4590
  if (r.collapsed && r.startContainer.nodeType === Node.TEXT_NODE) {
4592
4591
  const textNode = r.startContainer;
@@ -4616,7 +4615,7 @@
4616
4615
  return false;
4617
4616
  }
4618
4617
  if (isKey(event, key.LEFT) || isKey(event, key.RIGHT)) {
4619
- const sel = window.getSelection();
4618
+ const sel = globalThis.getSelection();
4620
4619
  if (!sel || sel.rangeCount === 0) return false;
4621
4620
  const r = sel.getRangeAt(0);
4622
4621
  if (!r.collapsed) return false;
@@ -4704,7 +4703,7 @@
4704
4703
  else execCommand("indent");
4705
4704
  return true;
4706
4705
  }
4707
- if (para && para.nodeName.toUpperCase() === "PRE") {
4706
+ if (para?.nodeName.toUpperCase() === "PRE") {
4708
4707
  if (event.shiftKey) return false;
4709
4708
  event.preventDefault();
4710
4709
  execCommand("insertText", " ".repeat(options.tabSize || 4));
@@ -4727,18 +4726,18 @@
4727
4726
  if (!range) return false;
4728
4727
  const sc = range.sc;
4729
4728
  const el = sc.nodeType === 3 ? sc.parentElement : sc;
4730
- if (el && el.nodeName === "I" && /\bfa-/.test(el.className || "")) {
4729
+ if (el?.nodeName === "I" && /\bfa-/.test(el.className || "")) {
4731
4730
  const nr = document.createRange();
4732
4731
  nr.setStartAfter(el);
4733
4732
  nr.collapse(true);
4734
- const selI = window.getSelection();
4733
+ const selI = globalThis.getSelection();
4735
4734
  if (selI) {
4736
4735
  selI.removeAllRanges();
4737
4736
  selI.addRange(nr);
4738
4737
  }
4739
4738
  return false;
4740
4739
  }
4741
- const videoWrapper = el && el.closest(".an-video-wrapper");
4740
+ const videoWrapper = el?.closest(".an-video-wrapper");
4742
4741
  if (videoWrapper) {
4743
4742
  event.preventDefault();
4744
4743
  const p = document.createElement("p");
@@ -4747,16 +4746,16 @@
4747
4746
  const nr = document.createRange();
4748
4747
  nr.setStart(p, 0);
4749
4748
  nr.collapse(true);
4750
- const sel = window.getSelection();
4749
+ const sel = globalThis.getSelection();
4751
4750
  sel.removeAllRanges();
4752
4751
  sel.addRange(nr);
4753
4752
  return true;
4754
4753
  }
4755
- const checkLi = el && el.closest(".an-checklist li");
4754
+ const checkLi = el?.closest(".an-checklist li");
4756
4755
  if (checkLi) {
4757
4756
  event.preventDefault();
4758
4757
  const ul = checkLi.closest(".an-checklist");
4759
- const sel = window.getSelection();
4758
+ const sel = globalThis.getSelection();
4760
4759
  let nativeRange = sel.getRangeAt(0);
4761
4760
  const liText = (li) => Array.from(li.childNodes).filter((n) => !(n.nodeType === 1 && n.tagName === "INPUT")).map((n) => n.textContent).join("").replace(/[\u00a0\u200B]/g, " ").trim();
4762
4761
  if (!liText(checkLi)) {
@@ -4800,12 +4799,12 @@
4800
4799
  return true;
4801
4800
  }
4802
4801
  const para = closestPara(range.sc, editable);
4803
- if (para && para.nodeName.toUpperCase() === "PRE") {
4802
+ if (para?.nodeName.toUpperCase() === "PRE") {
4804
4803
  event.preventDefault();
4805
4804
  execCommand("insertText", "\n");
4806
4805
  return true;
4807
4806
  }
4808
- if (para && para.nodeName.toUpperCase() === "BLOCKQUOTE") {
4807
+ if (para?.nodeName.toUpperCase() === "BLOCKQUOTE") {
4809
4808
  const native = range.toNativeRange();
4810
4809
  native.setEnd(para, para.childNodes.length);
4811
4810
  if (native.toString() === "" && range.isCollapsed()) {
@@ -4879,7 +4878,7 @@
4879
4878
  return `\`${inner()}\``;
4880
4879
  case "pre": {
4881
4880
  const codeEl = el.querySelector("code");
4882
- const langMatch = (codeEl && codeEl.className || "").match(/language-(\S+)/);
4881
+ const langMatch = /language-(\S+)/.exec(codeEl && codeEl.className || "");
4883
4882
  return `\n\n\`\`\`${langMatch ? langMatch[1] : ""}\n${(codeEl || el).textContent || ""}\n\`\`\`\n\n`;
4884
4883
  }
4885
4884
  case "blockquote": return `\n\n${inner().trim().split("\n").map((l) => `> ${l}`).join("\n")}\n\n`;
@@ -4910,7 +4909,7 @@
4910
4909
  case "table": {
4911
4910
  const rows = Array.from(el.querySelectorAll("tr"));
4912
4911
  if (!rows.length) return inner();
4913
- const cellTexts = rows.map((tr) => Array.from(tr.querySelectorAll("th, td")).map((c) => c.textContent.trim().replace(/\|/g, "\\|")));
4912
+ const cellTexts = rows.map((tr) => Array.from(tr.querySelectorAll("th, td")).map((c) => c.textContent.trim().replaceAll("|", "\\|")));
4914
4913
  const cols = Math.max(...cellTexts.map((r) => r.length));
4915
4914
  const padRow = (row) => {
4916
4915
  const r = [...row];
@@ -4919,7 +4918,7 @@
4919
4918
  };
4920
4919
  let md = "\n\n";
4921
4920
  md += `| ${padRow(cellTexts[0]).join(" | ")} |\n`;
4922
- md += `| ${Array(cols).fill("---").join(" | ")} |\n`;
4921
+ md += `| ${new Array(cols).fill("---").join(" | ")} |\n`;
4923
4922
  for (let r = 1; r < cellTexts.length; r++) md += `| ${padRow(cellTexts[r]).join(" | ")} |\n`;
4924
4923
  return md + "\n";
4925
4924
  }
@@ -4943,12 +4942,12 @@
4943
4942
  * @returns {string}
4944
4943
  */
4945
4944
  function markdownToHTML(text) {
4946
- const lines = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
4945
+ const lines = text.replaceAll("\r\n", "\n").replaceAll("\r", "\n").split("\n");
4947
4946
  const out = [];
4948
4947
  let i = 0;
4949
4948
  while (i < lines.length) {
4950
4949
  const line = lines[i];
4951
- const fenceMatch = line.match(/^```(\S*)$/);
4950
+ const fenceMatch = /^```(\S*)$/.exec(line);
4952
4951
  if (fenceMatch) {
4953
4952
  const lang = fenceMatch[1];
4954
4953
  const codeLines = [];
@@ -4967,7 +4966,7 @@
4967
4966
  i++;
4968
4967
  continue;
4969
4968
  }
4970
- const hMatch = line.match(/^(#{1,6})\s+(.+)$/);
4969
+ const hMatch = /^(#{1,6})\s+(.+)$/.exec(line);
4971
4970
  if (hMatch) {
4972
4971
  const level = hMatch[1].length;
4973
4972
  out.push(`<h${level}>${_inline(hMatch[2])}</h${level}>`);
@@ -5014,7 +5013,8 @@
5014
5013
  i++;
5015
5014
  }
5016
5015
  const thead = `<thead><tr>${headerCells.map((c) => `<th>${_inline(c)}</th>`).join("")}</tr></thead>`;
5017
- const tbody = bodyRows.length ? `<tbody>${bodyRows.map((row) => `<tr>${row.map((c) => `<td>${_inline(c)}</td>`).join("")}</tr>`).join("")}</tbody>` : "";
5016
+ const renderRow = (row) => `<tr>${row.map((c) => `<td>${_inline(c)}</td>`).join("")}</tr>`;
5017
+ const tbody = bodyRows.length ? `<tbody>${bodyRows.map(renderRow).join("")}</tbody>` : "";
5018
5018
  out.push(`<table>${thead}${tbody}</table>`);
5019
5019
  continue;
5020
5020
  }
@@ -5050,10 +5050,10 @@
5050
5050
  return text;
5051
5051
  }
5052
5052
  function _esc(v) {
5053
- return String(v).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
5053
+ return String(v).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
5054
5054
  }
5055
5055
  function _escAttr(v) {
5056
- return String(v).replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
5056
+ return String(v).replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("'", "&#39;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
5057
5057
  }
5058
5058
  //#endregion
5059
5059
  //#region src/js/core/detectLang.js
@@ -5135,7 +5135,7 @@
5135
5135
  const onBeforeInput = (event) => this._enforceLimit(event);
5136
5136
  const onSelChange = () => {
5137
5137
  if (!this.context._alive) return;
5138
- const sel = window.getSelection();
5138
+ const sel = globalThis.getSelection();
5139
5139
  if (sel && sel.rangeCount > 0 && editable.contains(sel.anchorNode)) {
5140
5140
  this.context.invoke("toolbar.refresh");
5141
5141
  if (typeof this.options.onSelectionChange === "function") this.options.onSelectionChange(this.context);
@@ -5145,7 +5145,7 @@
5145
5145
  if (e.target.type === "checkbox" && e.target.closest(".an-checklist")) this.afterCommand();
5146
5146
  };
5147
5147
  const fixChecklistCursor = (event) => {
5148
- const sel = window.getSelection();
5148
+ const sel = globalThis.getSelection();
5149
5149
  if (!sel || !sel.rangeCount) return;
5150
5150
  const r = sel.getRangeAt(0);
5151
5151
  if (!r.collapsed) return;
@@ -5199,7 +5199,7 @@
5199
5199
  /** @type {string|null} 'superscript' | 'subscript' | null */
5200
5200
  let _compositionSupSub = null;
5201
5201
  const onCompositionStart = () => {
5202
- const sel = window.getSelection();
5202
+ const sel = globalThis.getSelection();
5203
5203
  if (!sel || !sel.rangeCount) {
5204
5204
  _compositionSupSub = null;
5205
5205
  return;
@@ -5217,12 +5217,12 @@
5217
5217
  const tag = _compositionSupSub;
5218
5218
  _compositionSupSub = null;
5219
5219
  if (!tag) return;
5220
- const sel = window.getSelection();
5220
+ const sel = globalThis.getSelection();
5221
5221
  if (!sel || !sel.rangeCount) return;
5222
5222
  let node = sel.getRangeAt(0).startContainer;
5223
5223
  if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
5224
5224
  const el = node;
5225
- if (!(el && (tag === "superscript" ? el.closest("sup") : el.closest("sub")))) document.execCommand(tag);
5225
+ if (!(tag === "superscript" ? el?.closest("sup") : el?.closest("sub"))) document.execCommand(tag);
5226
5226
  };
5227
5227
  this._disposers.push(on(editable, "compositionstart", onCompositionStart), on(editable, "compositionend", onCompositionEnd));
5228
5228
  }
@@ -5296,7 +5296,7 @@
5296
5296
  if (type === "insertFromPaste" || type === "insertFromDrop") return;
5297
5297
  if (!type.startsWith("insert")) return;
5298
5298
  const text = this.context.layoutInfo.editable.innerText || "";
5299
- const chars = text.replace(/\n/g, "").length;
5299
+ const chars = text.replaceAll("\n", "").length;
5300
5300
  if (maxChars && chars >= maxChars) {
5301
5301
  event.preventDefault();
5302
5302
  if (typeof this.options.onCharLimitReached === "function") this.options.onCharLimitReached(this.context);
@@ -5335,7 +5335,7 @@
5335
5335
  */
5336
5336
  _cleanOrphanedFigures() {
5337
5337
  this.context.layoutInfo.editable.querySelectorAll("figure.an-figure").forEach((fig) => {
5338
- if (!fig.querySelector("img")) fig.parentNode.removeChild(fig);
5338
+ if (!fig.querySelector("img")) fig.remove();
5339
5339
  });
5340
5340
  }
5341
5341
  /**
@@ -5371,7 +5371,7 @@
5371
5371
  * @returns {string}
5372
5372
  */
5373
5373
  getHTML() {
5374
- const raw = this.context.layoutInfo.editable.innerHTML.replace(/\u200B/g, "");
5374
+ const raw = this.context.layoutInfo.editable.innerHTML.replaceAll("​", "");
5375
5375
  return this.context.invoke("clipboard.resolveImages", raw) ?? raw;
5376
5376
  }
5377
5377
  /**
@@ -5416,7 +5416,7 @@
5416
5416
  * @returns {boolean}
5417
5417
  */
5418
5418
  isEmpty() {
5419
- const text = (this.context.layoutInfo.editable.innerText || "").trim().replace(/\u00a0/g, "");
5419
+ const text = (this.context.layoutInfo.editable.innerText || "").trim().replaceAll("\xA0", "");
5420
5420
  const hasMedia = !!this.context.layoutInfo.editable.querySelector("img, video, iframe, table");
5421
5421
  return !text && !hasMedia;
5422
5422
  }
@@ -5551,11 +5551,11 @@
5551
5551
  formatBlock(tagName) {
5552
5552
  formatBlock(tagName);
5553
5553
  if (tagName === "pre") {
5554
- const sel = window.getSelection();
5554
+ const sel = globalThis.getSelection();
5555
5555
  if (sel && sel.rangeCount > 0) {
5556
5556
  const container = sel.getRangeAt(0).commonAncestorContainer;
5557
5557
  const pre = container.nodeType === 1 ? container.closest("pre") : container.parentElement?.closest("pre");
5558
- if (pre && !pre.getAttribute("data-language")) {
5558
+ if (pre && !pre.dataset.language) {
5559
5559
  const lang = detectLang(pre.textContent || "");
5560
5560
  if (lang) {
5561
5561
  this.context.invoke("codeTooltip.applyLanguage", pre, lang);
@@ -5608,7 +5608,7 @@
5608
5608
  * @param {boolean} [openInNewTab=false]
5609
5609
  */
5610
5610
  insertLink(url, text, openInNewTab = false) {
5611
- const sel = window.getSelection();
5611
+ const sel = globalThis.getSelection();
5612
5612
  if (!sel || sel.rangeCount === 0) return;
5613
5613
  const safeUrl = sanitiseUrl(url);
5614
5614
  if (!safeUrl) return;
@@ -5671,7 +5671,7 @@
5671
5671
  this.afterCommand();
5672
5672
  }
5673
5673
  _getClosestAnchor() {
5674
- const sel = window.getSelection();
5674
+ const sel = globalThis.getSelection();
5675
5675
  if (!sel || sel.rangeCount === 0) return null;
5676
5676
  let node = sel.getRangeAt(0).startContainer;
5677
5677
  while (node) {
@@ -5686,7 +5686,7 @@
5686
5686
  * @returns {string}
5687
5687
  */
5688
5688
  _escapeAttr(str) {
5689
- return String(str ?? "").replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
5689
+ return String(str ?? "").replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
5690
5690
  }
5691
5691
  };
5692
5692
  //#endregion
@@ -5801,7 +5801,7 @@
5801
5801
  this._refreshRaf = null;
5802
5802
  this._disposers.forEach((d) => d());
5803
5803
  this._disposers = [];
5804
- if (this.el && this.el.parentNode) this.el.parentNode.removeChild(this.el);
5804
+ if (this.el && this.el.parentNode) this.el.remove();
5805
5805
  this.el = null;
5806
5806
  }
5807
5807
  _buildButtons() {
@@ -5869,8 +5869,8 @@
5869
5869
  let isOpen = false;
5870
5870
  const setHighlight = (rows, cols) => {
5871
5871
  cells.forEach((cell) => {
5872
- const r = +cell.getAttribute("data-row");
5873
- const c = +cell.getAttribute("data-col");
5872
+ const r = +cell.dataset.row;
5873
+ const c = +cell.dataset.col;
5874
5874
  cell.classList.toggle("active", r <= rows && c <= cols);
5875
5875
  });
5876
5876
  label.textContent = rows && cols ? `${rows} × ${cols}` : this.context.locale.toolbar.insertTableLabel || "Insert Table";
@@ -5884,8 +5884,8 @@
5884
5884
  const ph = popup.offsetHeight;
5885
5885
  let left = rect.left;
5886
5886
  let top = rect.bottom + 4;
5887
- if (left + pw > window.innerWidth - 8) left = Math.max(8, window.innerWidth - pw - 8);
5888
- if (top + ph > window.innerHeight - 8) top = rect.top - ph - 4;
5887
+ if (left + pw > globalThis.innerWidth - 8) left = Math.max(8, globalThis.innerWidth - pw - 8);
5888
+ if (top + ph > globalThis.innerHeight - 8) top = rect.top - ph - 4;
5889
5889
  popup.style.left = `${left}px`;
5890
5890
  popup.style.top = `${top}px`;
5891
5891
  popup.style.visibility = "";
@@ -5905,14 +5905,14 @@
5905
5905
  const d2 = on(grid, "mouseover", (e) => {
5906
5906
  const cell = e.target?.closest(".an-table-cell");
5907
5907
  if (!cell) return;
5908
- setHighlight(+cell.getAttribute("data-row"), +cell.getAttribute("data-col"));
5908
+ setHighlight(+cell.dataset.row, +cell.dataset.col);
5909
5909
  });
5910
5910
  const d3 = on(grid, "mouseleave", () => setHighlight(0, 0));
5911
5911
  const d4 = on(grid, "click", (e) => {
5912
5912
  const cell = e.target?.closest(".an-table-cell");
5913
5913
  if (!cell) return;
5914
- const rows = +cell.getAttribute("data-row");
5915
- const cols = +cell.getAttribute("data-col");
5914
+ const rows = +cell.dataset.row;
5915
+ const cols = +cell.dataset.col;
5916
5916
  closePopup();
5917
5917
  this.context.invoke("editor.focus");
5918
5918
  def.action(this.context, rows, cols);
@@ -5921,7 +5921,7 @@
5921
5921
  if (isOpen) closePopup();
5922
5922
  });
5923
5923
  this._disposers.push(d1, d2, d3, d4, d5, () => {
5924
- if (popup.parentNode) popup.parentNode.removeChild(popup);
5924
+ if (popup.parentNode) popup.remove();
5925
5925
  });
5926
5926
  wrap.appendChild(btn);
5927
5927
  document.body.appendChild(popup);
@@ -6011,13 +6011,13 @@
6011
6011
  /** @type {Range|null} saved selection range before popup opens */
6012
6012
  let savedRange = null;
6013
6013
  const saveSelection = () => {
6014
- const sel = window.getSelection();
6014
+ const sel = globalThis.getSelection();
6015
6015
  savedRange = sel && sel.rangeCount ? sel.getRangeAt(0).cloneRange() : null;
6016
6016
  };
6017
6017
  const restoreSelection = () => {
6018
6018
  if (!savedRange) return;
6019
6019
  try {
6020
- const sel = window.getSelection();
6020
+ const sel = globalThis.getSelection();
6021
6021
  if (!sel) return;
6022
6022
  sel.removeAllRanges();
6023
6023
  sel.addRange(savedRange);
@@ -6032,7 +6032,7 @@
6032
6032
  const rect = arrowBtn.getBoundingClientRect();
6033
6033
  const popupMinW = 184;
6034
6034
  let left = rect.left;
6035
- if (left + popupMinW > window.innerWidth) left = rect.right - popupMinW;
6035
+ if (left + popupMinW > globalThis.innerWidth) left = rect.right - popupMinW;
6036
6036
  popup.style.top = `${rect.bottom + 4}px`;
6037
6037
  popup.style.left = `${Math.max(4, left)}px`;
6038
6038
  popup.style.display = "block";
@@ -6095,9 +6095,9 @@
6095
6095
  passive: true,
6096
6096
  capture: true
6097
6097
  });
6098
- window.addEventListener("resize", onScrollResize, { passive: true });
6099
- this._disposers.push(d1, d2, d2b, d3, d3b, d4, d5, d6, () => document.removeEventListener("scroll", onScrollResize, { capture: true }), () => window.removeEventListener("resize", onScrollResize), () => {
6100
- if (popup.parentNode) popup.parentNode.removeChild(popup);
6098
+ globalThis.addEventListener("resize", onScrollResize, { passive: true });
6099
+ this._disposers.push(d1, d2, d2b, d3, d3b, d4, d5, d6, () => document.removeEventListener("scroll", onScrollResize, { capture: true }), () => globalThis.removeEventListener("resize", onScrollResize), () => {
6100
+ if (popup.parentNode) popup.remove();
6101
6101
  });
6102
6102
  this._colorPickerClosers.push(closePopup);
6103
6103
  this._disposers.push(() => {
@@ -6141,7 +6141,7 @@
6141
6141
  /** @type {Range|null} */
6142
6142
  let _savedRange = null;
6143
6143
  const dMousedown = on(select, "mousedown", () => {
6144
- const sel = window.getSelection();
6144
+ const sel = globalThis.getSelection();
6145
6145
  _savedRange = sel && sel.rangeCount ? sel.getRangeAt(0).cloneRange() : null;
6146
6146
  });
6147
6147
  const disposer = on(select, "change", (e) => {
@@ -6150,7 +6150,7 @@
6150
6150
  if (!value || selectedOpt.disabled) return;
6151
6151
  this.context.invoke("editor.focus");
6152
6152
  if (_savedRange) try {
6153
- const sel = window.getSelection();
6153
+ const sel = globalThis.getSelection();
6154
6154
  if (sel) {
6155
6155
  sel.removeAllRanges();
6156
6156
  sel.addRange(_savedRange);
@@ -6215,13 +6215,19 @@
6215
6215
  if (!this.el) return;
6216
6216
  const btnMap = this._btnMap || /* @__PURE__ */ new Map();
6217
6217
  this.el.querySelectorAll("button[data-btn]").forEach((btn) => {
6218
- const def = btnMap.get(btn.getAttribute("data-btn"));
6218
+ const def = btnMap.get(
6219
+ /** @type {HTMLElement} */
6220
+ btn.dataset.btn
6221
+ );
6219
6222
  if (def && typeof def.isActive === "function") btn.classList.toggle("active", !!def.isActive(this.context));
6220
6223
  if (def && typeof def.isDisabled === "function")
6221
6224
  /** @type {HTMLButtonElement} */ btn.disabled = !!def.isDisabled(this.context);
6222
6225
  });
6223
6226
  this.el.querySelectorAll("select[data-btn]").forEach((select) => {
6224
- const def = btnMap.get(select.getAttribute("data-btn"));
6227
+ const def = btnMap.get(
6228
+ /** @type {HTMLElement} */
6229
+ select.dataset.btn
6230
+ );
6225
6231
  if (!def || typeof def.getValue !== "function") return;
6226
6232
  let raw = (def.getValue(this.context) || "").replace(/["']/g, "").trim();
6227
6233
  if (!raw) raw = this.options.defaultFontFamily || this.options.fontFamilies && this.options.fontFamilies[0] || "";
@@ -6347,7 +6353,7 @@
6347
6353
  this._dragDisposers.forEach((d) => d());
6348
6354
  this._dragDisposers = null;
6349
6355
  }
6350
- if (this.el && this.el.parentNode) this.el.parentNode.removeChild(this.el);
6356
+ this.el?.remove();
6351
6357
  this.el = null;
6352
6358
  }
6353
6359
  _bindResize(handle) {
@@ -6411,7 +6417,7 @@
6411
6417
  if (!this._wordCountEl || !this._charCountEl) return;
6412
6418
  const text = this.context.layoutInfo.editable.textContent || "";
6413
6419
  const words = _countWords(text);
6414
- const chars = text.replace(/\n/g, "").length;
6420
+ const chars = text.replaceAll("\n", "").length;
6415
6421
  const maxWords = this.options.maxWords || 0;
6416
6422
  const maxChars = this.options.maxChars || 0;
6417
6423
  const LS = this.context.locale.statusbar;
@@ -6433,7 +6439,7 @@
6433
6439
  * @returns {number}
6434
6440
  */
6435
6441
  getCharCount() {
6436
- return (this.context.layoutInfo.editable.innerText || "").replace(/\n/g, "").length;
6442
+ return (this.context.layoutInfo.editable.innerText || "").replaceAll("\n", "").length;
6437
6443
  }
6438
6444
  };
6439
6445
  //#endregion
@@ -6526,7 +6532,7 @@
6526
6532
  if (el.querySelector("a, strong, em, b, i, ul, ol, li, table, img, blockquote, pre, code, h1, h2, h3, h4, h5, h6")) continue;
6527
6533
  const parent = el.parentNode;
6528
6534
  while (el.firstChild) parent.insertBefore(el.firstChild, el);
6529
- parent.removeChild(el);
6535
+ el.remove();
6530
6536
  }
6531
6537
  doc.querySelectorAll("*").forEach((el) => {
6532
6538
  el.removeAttribute("class");
@@ -6568,7 +6574,7 @@
6568
6574
  this._forcePlain = !!val;
6569
6575
  }
6570
6576
  _onPaste(event) {
6571
- const clipboardData = event.clipboardData || window.clipboardData;
6577
+ const clipboardData = event.clipboardData || globalThis.clipboardData;
6572
6578
  if (!clipboardData) return;
6573
6579
  const forcePlain = this._forcePlain;
6574
6580
  this._forcePlain = false;
@@ -6612,7 +6618,6 @@
6612
6618
  if (this.options.pasteStripAttributes) html = this._stripAttributes(html);
6613
6619
  execCommand("insertHTML", html);
6614
6620
  this.context.invoke("editor.afterCommand");
6615
- return;
6616
6621
  }
6617
6622
  }
6618
6623
  _onDragover(event) {
@@ -6644,17 +6649,17 @@
6644
6649
  this.options.onImageUpload(files);
6645
6650
  return;
6646
6651
  }
6647
- const UNSUPPORTED = [
6652
+ const UNSUPPORTED = new Set([
6648
6653
  "image/tiff",
6649
6654
  "image/x-tiff",
6650
6655
  "image/bmp",
6651
6656
  "image/x-bmp",
6652
6657
  "image/x-ms-bmp"
6653
- ];
6658
+ ]);
6654
6659
  const maxBytes = (this.options.maxImageSize || 5) * 1024 * 1024;
6655
6660
  files.forEach((file) => {
6656
6661
  if (!file || !file.type.startsWith("image/")) return;
6657
- if (UNSUPPORTED.includes(file.type)) {
6662
+ if (UNSUPPORTED.has(file.type)) {
6658
6663
  const message = `Image format "${file.type}" is not supported for display in web browsers. Please convert to PNG, JPEG, or WebP first.`;
6659
6664
  this.context.triggerEvent("imageError", {
6660
6665
  file,
@@ -6706,10 +6711,10 @@
6706
6711
  */
6707
6712
  _dataUrlToBlob(dataUrl) {
6708
6713
  const [header, b64] = dataUrl.split(",");
6709
- const mime = header.match(/:(.*?);/)?.[1] ?? "image/png";
6714
+ const mime = /:(.*?);/.exec(header)?.[1] ?? "image/png";
6710
6715
  const binary = atob(b64);
6711
6716
  const arr = new Uint8Array(binary.length);
6712
- for (let i = 0; i < binary.length; i++) arr[i] = binary.charCodeAt(i);
6717
+ for (let i = 0; i < binary.length; i++) arr[i] = binary.codePointAt(i);
6713
6718
  return new Blob([arr], { type: mime });
6714
6719
  }
6715
6720
  /**
@@ -6777,7 +6782,7 @@
6777
6782
  }
6778
6783
  }
6779
6784
  if (!range) return;
6780
- const sel = window.getSelection();
6785
+ const sel = globalThis.getSelection();
6781
6786
  if (sel) {
6782
6787
  sel.removeAllRanges();
6783
6788
  sel.addRange(range);
@@ -6789,7 +6794,7 @@
6789
6794
  * @returns {string}
6790
6795
  */
6791
6796
  _escapeHTML(str) {
6792
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
6797
+ return str.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&#039;");
6793
6798
  }
6794
6799
  };
6795
6800
  //#endregion
@@ -6826,7 +6831,7 @@
6826
6831
  _update() {
6827
6832
  const editable = this.context.layoutInfo.editable;
6828
6833
  const isFocused = document.activeElement === editable;
6829
- const isEmpty = !(editable.textContent.replace(/\u200B/g, "").trim().length > 0) && !editable.querySelector("img, table, hr, .an-video-wrapper");
6834
+ const isEmpty = !(editable.textContent.replaceAll("​", "").trim().length > 0) && !editable.querySelector("img, table, hr, .an-video-wrapper");
6830
6835
  editable.classList.toggle("an-placeholder", isEmpty && !isFocused);
6831
6836
  }
6832
6837
  };
@@ -6854,7 +6859,7 @@
6854
6859
  destroy() {
6855
6860
  this._disposers.forEach((d) => d());
6856
6861
  this._disposers = [];
6857
- if (this._textarea && this._textarea.parentNode) this._textarea.parentNode.removeChild(this._textarea);
6862
+ this._textarea?.remove();
6858
6863
  this._textarea = null;
6859
6864
  }
6860
6865
  toggle() {
@@ -6885,7 +6890,7 @@
6885
6890
  if (!this._active || !this._textarea) return;
6886
6891
  const { editable } = this.context.layoutInfo;
6887
6892
  editable.innerHTML = sanitiseHTML(this._textarea.value, { allowIframes: true });
6888
- this._textarea.parentNode.removeChild(this._textarea);
6893
+ this._textarea.remove();
6889
6894
  this._textarea = null;
6890
6895
  editable.style.display = "";
6891
6896
  this._active = false;
@@ -6909,7 +6914,7 @@
6909
6914
  }).split("\n").map((line) => {
6910
6915
  const stripped = line.trim();
6911
6916
  if (!stripped) return "";
6912
- if (/^<\//.test(stripped)) indent = Math.max(0, indent - 1);
6917
+ if (stripped.startsWith("</")) indent = Math.max(0, indent - 1);
6913
6918
  const out = " ".repeat(indent) + stripped;
6914
6919
  if (/^<[^/!][^>]*[^/]>/.test(stripped) && !INLINE_RE.test(stripped) && !/^<(br|hr|img|input|link|meta)/.test(stripped)) indent++;
6915
6920
  return out;
@@ -6998,7 +7003,7 @@
6998
7003
  destroy() {
6999
7004
  this._disposers.forEach((d) => d());
7000
7005
  this._disposers = [];
7001
- if (this._dialog && this._dialog.parentNode) this._dialog.parentNode.removeChild(this._dialog);
7006
+ if (this._dialog && this._dialog.parentNode) this._dialog.remove();
7002
7007
  this._dialog = null;
7003
7008
  }
7004
7009
  /**
@@ -7096,7 +7101,7 @@
7096
7101
  return overlay;
7097
7102
  }
7098
7103
  _prefill() {
7099
- const sel = window.getSelection();
7104
+ const sel = globalThis.getSelection();
7100
7105
  let anchor = null;
7101
7106
  if (sel && sel.rangeCount > 0) {
7102
7107
  let node = sel.getRangeAt(0).startContainer;
@@ -7183,7 +7188,7 @@
7183
7188
  destroy() {
7184
7189
  this._disposers.forEach((d) => d());
7185
7190
  this._disposers = [];
7186
- if (this._dialog && this._dialog.parentNode) this._dialog.parentNode.removeChild(this._dialog);
7191
+ if (this._dialog && this._dialog.parentNode) this._dialog.remove();
7187
7192
  this._dialog = null;
7188
7193
  }
7189
7194
  show() {
@@ -7415,7 +7420,7 @@
7415
7420
  destroy() {
7416
7421
  this._disposers.forEach((d) => d());
7417
7422
  this._disposers = [];
7418
- if (this._dialog && this._dialog.parentNode) this._dialog.parentNode.removeChild(this._dialog);
7423
+ if (this._dialog && this._dialog.parentNode) this._dialog.remove();
7419
7424
  this._dialog = null;
7420
7425
  }
7421
7426
  show() {
@@ -7501,7 +7506,7 @@
7501
7506
  }
7502
7507
  _onInsert() {
7503
7508
  const rawUrl = this._urlInput.value.trim();
7504
- const width = Math.max(80, parseInt(this._widthInput.value, 10) || 560);
7509
+ const width = Math.max(80, Number.parseInt(this._widthInput.value, 10) || 560);
7505
7510
  if (!rawUrl) {
7506
7511
  this._urlInput.focus();
7507
7512
  return;
@@ -7544,22 +7549,22 @@
7544
7549
  } catch {
7545
7550
  return null;
7546
7551
  }
7547
- const ytWatch = url.match(/(?:youtube\.com\/watch\?(?:.*&)?v=|youtube\.com\/embed\/)([a-zA-Z0-9_-]{11})/);
7552
+ const ytWatch = /(?:youtube\.com\/watch\?(?:.*&)?v=|youtube\.com\/embed\/)([a-zA-Z0-9_-]{11})/.exec(url);
7548
7553
  if (ytWatch) return {
7549
7554
  type: "YouTube",
7550
7555
  embedUrl: `https://www.youtube.com/embed/${ytWatch[1]}`
7551
7556
  };
7552
- const ytShort = url.match(/youtu\.be\/([a-zA-Z0-9_-]{11})/);
7557
+ const ytShort = /youtu\.be\/([a-zA-Z0-9_-]{11})/.exec(url);
7553
7558
  if (ytShort) return {
7554
7559
  type: "YouTube",
7555
7560
  embedUrl: `https://www.youtube.com/embed/${ytShort[1]}`
7556
7561
  };
7557
- const ytShorts = url.match(/youtube\.com\/shorts\/([a-zA-Z0-9_-]{11})/);
7562
+ const ytShorts = /youtube\.com\/shorts\/([a-zA-Z0-9_-]{11})/.exec(url);
7558
7563
  if (ytShorts) return {
7559
7564
  type: "YouTube Shorts",
7560
7565
  embedUrl: `https://www.youtube.com/embed/${ytShorts[1]}`
7561
7566
  };
7562
- const vimeo = url.match(/vimeo\.com\/(\d+)/);
7567
+ const vimeo = /vimeo\.com\/(\d+)/.exec(url);
7563
7568
  if (vimeo) return {
7564
7569
  type: "Vimeo",
7565
7570
  embedUrl: `https://player.vimeo.com/video/${vimeo[1]}`
@@ -7583,7 +7588,7 @@
7583
7588
  const iframeTitle = `${info.type} video player`;
7584
7589
  return `<div class="an-video-wrapper" style="position:relative;display:block;width:${width}px;max-width:100%"><iframe src="${info.embedUrl}" width="${width}" height="${height}" title="${iframeTitle}" frameborder="0" allowfullscreen allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" style="display:block;max-width:100%"></iframe><div class="an-video-shield"></div></div>`;
7585
7590
  }
7586
- if (info && info.type === "Direct video") return `<div class="an-video-wrapper" style="position:relative;display:block;width:${width}px;max-width:100%"><video src="${info.embedUrl.replace(/"/g, "%22")}" width="${width}" height="${height}" controls style="display:block;max-width:100%"></video><div class="an-video-shield"></div></div>`;
7591
+ if (info && info.type === "Direct video") return `<div class="an-video-wrapper" style="position:relative;display:block;width:${width}px;max-width:100%"><video src="${info.embedUrl.replaceAll("\"", "%22")}" width="${width}" height="${height}" controls style="display:block;max-width:100%"></video><div class="an-video-shield"></div></div>`;
7587
7592
  const safeSrc = (() => {
7588
7593
  try {
7589
7594
  const p = new URL(url);
@@ -7594,7 +7599,7 @@
7594
7599
  }
7595
7600
  })();
7596
7601
  if (!safeSrc) return null;
7597
- return `<div class="an-video-wrapper" style="position:relative;display:block;width:${width}px;max-width:100%"><video src="${safeSrc.replace(/"/g, "%22")}" width="${width}" height="${height}" controls style="display:block;max-width:100%"></video><div class="an-video-shield"></div></div>`;
7602
+ return `<div class="an-video-wrapper" style="position:relative;display:block;width:${width}px;max-width:100%"><video src="${safeSrc.replaceAll("\"", "%22")}" width="${width}" height="${height}" controls style="display:block;max-width:100%"></video><div class="an-video-shield"></div></div>`;
7598
7603
  }
7599
7604
  };
7600
7605
  //#endregion
@@ -7665,7 +7670,7 @@
7665
7670
  if (this.context.layoutInfo.container.classList.contains("an-disabled")) return;
7666
7671
  const img = e.target?.closest("img");
7667
7672
  if (img) this._select(img);
7668
- }), on(document, "click", (e) => this._onDocClick(e)), on(window, "scroll", () => this._updateOverlayPosition(), { passive: true }), on(window, "resize", onWindowResize, { passive: true }), on(editable, "scroll", () => this._updateOverlayPosition(), { passive: true }));
7673
+ }), on(document, "click", (e) => this._onDocClick(e)), on(globalThis, "scroll", () => this._updateOverlayPosition(), { passive: true }), on(globalThis, "resize", onWindowResize, { passive: true }), on(editable, "scroll", () => this._updateOverlayPosition(), { passive: true }));
7669
7674
  return this;
7670
7675
  }
7671
7676
  destroy() {
@@ -7680,7 +7685,7 @@
7680
7685
  this._positionRaf = null;
7681
7686
  }
7682
7687
  this._deselect();
7683
- if (this._overlay && this._overlay.parentNode) this._overlay.parentNode.removeChild(this._overlay);
7688
+ if (this._overlay && this._overlay.parentNode) this._overlay.remove();
7684
7689
  this._overlay = null;
7685
7690
  }
7686
7691
  /** @returns {HTMLImageElement|null} */
@@ -7882,7 +7887,7 @@
7882
7887
  if (this.context.layoutInfo.container.classList.contains("an-disabled")) return;
7883
7888
  const wrapper = this._findWrapper(e.target);
7884
7889
  if (wrapper) this._select(wrapper);
7885
- }), on(document, "click", (e) => this._onDocClick(e)), on(window, "scroll", () => this._updateOverlayPosition(), { passive: true }), on(window, "resize", onWindowResize), on(editable, "scroll", () => this._updateOverlayPosition(), { passive: true }), on(editable, "dragstart", (e) => {
7890
+ }), on(document, "click", (e) => this._onDocClick(e)), on(globalThis, "scroll", () => this._updateOverlayPosition(), { passive: true }), on(globalThis, "resize", onWindowResize), on(editable, "scroll", () => this._updateOverlayPosition(), { passive: true }), on(editable, "dragstart", (e) => {
7886
7891
  if (e.target instanceof Element && e.target.closest(".an-video-wrapper")) e.preventDefault();
7887
7892
  }));
7888
7893
  return this;
@@ -7899,7 +7904,7 @@
7899
7904
  this._positionRaf = null;
7900
7905
  }
7901
7906
  this._deselect();
7902
- if (this._overlay && this._overlay.parentNode) this._overlay.parentNode.removeChild(this._overlay);
7907
+ this._overlay?.remove();
7903
7908
  this._overlay = null;
7904
7909
  }
7905
7910
  /** @returns {HTMLElement|null} */
@@ -7920,7 +7925,7 @@
7920
7925
  */
7921
7926
  _findWrapper(el) {
7922
7927
  if (!el || !(el instanceof Element)) return null;
7923
- if (el.classList && el.classList.contains("an-video-wrapper")) return el;
7928
+ if (el.classList?.contains("an-video-wrapper")) return el;
7924
7929
  const w = el.closest(".an-video-wrapper");
7925
7930
  if (w) return w;
7926
7931
  return null;
@@ -7953,7 +7958,7 @@
7953
7958
  _onDocClick(e) {
7954
7959
  if (!this._activeWrapper) return;
7955
7960
  if (this._activeWrapper.contains(e.target)) return;
7956
- if (this._overlay && this._overlay.contains(e.target)) return;
7961
+ if (this._overlay?.contains(e.target)) return;
7957
7962
  if (e.target.closest(".an-contextmenu")) return;
7958
7963
  this._deselect();
7959
7964
  }
@@ -8078,14 +8083,14 @@
8078
8083
  }), on(editable, "mouseout", (e) => {
8079
8084
  const to = e.relatedTarget;
8080
8085
  if (!to || !editable.contains(to) && !this._el.contains(to)) this._scheduleHide();
8081
- }), on(window, "scroll", () => this._hide(), { passive: true }), on(window, "resize", () => this._hide(), { passive: true }));
8086
+ }), on(globalThis, "scroll", () => this._hide(), { passive: true }), on(globalThis, "resize", () => this._hide(), { passive: true }));
8082
8087
  return this;
8083
8088
  }
8084
8089
  destroy() {
8085
8090
  this._clearTimers();
8086
8091
  this._disposers.forEach((d) => d());
8087
8092
  this._disposers = [];
8088
- if (this._el && this._el.parentNode) this._el.parentNode.removeChild(this._el);
8093
+ if (this._el && this._el.parentNode) this._el.remove();
8089
8094
  this._el = null;
8090
8095
  }
8091
8096
  _buildTooltip() {
@@ -8170,8 +8175,8 @@
8170
8175
  const margin = 6;
8171
8176
  let top = rect.bottom + margin;
8172
8177
  let left = rect.left;
8173
- if (top + tipH > window.innerHeight - margin) top = rect.top - tipH - margin;
8174
- if (left + tipW > window.innerWidth - margin) left = window.innerWidth - tipW - margin;
8178
+ if (top + tipH > globalThis.innerHeight - margin) top = rect.top - tipH - margin;
8179
+ if (left + tipW > globalThis.innerWidth - margin) left = globalThis.innerWidth - tipW - margin;
8175
8180
  if (left < margin) left = margin;
8176
8181
  this._el.style.top = `${top}px`;
8177
8182
  this._el.style.left = `${left}px`;
@@ -8186,12 +8191,12 @@
8186
8191
  }
8187
8192
  }
8188
8193
  _openLink() {
8189
- const url = this._activeAnchor && this._activeAnchor.getAttribute("href");
8190
- if (url) window.open(url, "_blank", "noopener,noreferrer");
8194
+ const url = this._activeAnchor?.getAttribute("href");
8195
+ if (url) globalThis.open(url, "_blank", "noopener,noreferrer");
8191
8196
  this._hide();
8192
8197
  }
8193
8198
  _copyLink() {
8194
- const url = this._activeAnchor && this._activeAnchor.getAttribute("href");
8199
+ const url = this._activeAnchor?.getAttribute("href");
8195
8200
  if (url) navigator.clipboard.writeText(url).catch(() => {
8196
8201
  const ta = document.createElement("textarea");
8197
8202
  ta.value = url;
@@ -8200,7 +8205,7 @@
8200
8205
  document.body.appendChild(ta);
8201
8206
  ta.select();
8202
8207
  document.execCommand("copy");
8203
- document.body.removeChild(ta);
8208
+ ta.remove();
8204
8209
  });
8205
8210
  if (this._copyBtn) {
8206
8211
  this._copyBtn.classList.add("an-link-tooltip-btn--copied");
@@ -8211,7 +8216,7 @@
8211
8216
  const anchor = this._activeAnchor;
8212
8217
  if (!anchor) return;
8213
8218
  this._hide();
8214
- const sel = window.getSelection();
8219
+ const sel = globalThis.getSelection();
8215
8220
  const range = document.createRange();
8216
8221
  range.selectNodeContents(anchor);
8217
8222
  sel.removeAllRanges();
@@ -8222,7 +8227,7 @@
8222
8227
  const anchor = this._activeAnchor;
8223
8228
  if (!anchor) return;
8224
8229
  this._hide();
8225
- const sel = window.getSelection();
8230
+ const sel = globalThis.getSelection();
8226
8231
  const range = document.createRange();
8227
8232
  range.selectNode(anchor);
8228
8233
  sel.removeAllRanges();
@@ -8271,14 +8276,14 @@
8271
8276
  }, { passive: true }), on(document, "click", (e) => {
8272
8277
  const et = e.target;
8273
8278
  if (this._activeImg && !this._activeImg.contains(et) && !this._el.contains(et)) this._hide();
8274
- }), on(window, "scroll", () => this._hide(), { passive: true }), on(window, "resize", () => this._hide(), { passive: true }));
8279
+ }), on(globalThis, "scroll", () => this._hide(), { passive: true }), on(globalThis, "resize", () => this._hide(), { passive: true }));
8275
8280
  return this;
8276
8281
  }
8277
8282
  destroy() {
8278
8283
  this._clearTimers();
8279
8284
  this._disposers.forEach((d) => d());
8280
8285
  this._disposers = [];
8281
- if (this._el && this._el.parentNode) this._el.parentNode.removeChild(this._el);
8286
+ this._el?.remove();
8282
8287
  this._el = null;
8283
8288
  }
8284
8289
  _buildTooltip() {
@@ -8379,8 +8384,8 @@
8379
8384
  const margin = 6;
8380
8385
  let top = rect.bottom + margin;
8381
8386
  let left = rect.left + (rect.width - tipW) / 2;
8382
- if (top + tipH > window.innerHeight - margin) top = rect.top - tipH - margin;
8383
- if (left + tipW > window.innerWidth - margin) left = window.innerWidth - tipW - margin;
8387
+ if (top + tipH > globalThis.innerHeight - margin) top = rect.top - tipH - margin;
8388
+ if (left + tipW > globalThis.innerWidth - margin) left = globalThis.innerWidth - tipW - margin;
8384
8389
  if (left < margin) left = margin;
8385
8390
  this._el.style.top = `${top}px`;
8386
8391
  this._el.style.left = `${left}px`;
@@ -8436,8 +8441,8 @@
8436
8441
  const img = this._activeImg;
8437
8442
  if (!img) return;
8438
8443
  const current = img.style.transform || "";
8439
- const match = current.match(/rotate\((-?[\d.]+)deg\)/);
8440
- const next = ((match ? parseFloat(match[1]) : 0) + delta + 360) % 360;
8444
+ const match = /rotate\((-?[\d.]+)deg\)/.exec(current);
8445
+ const next = ((match ? Number.parseFloat(match[1]) : 0) + delta + 360) % 360;
8441
8446
  const cleaned = current.replace(/rotate\(-?[\d.]+deg\)/, "").trim();
8442
8447
  img.style.transform = cleaned ? `${cleaned} rotate(${next}deg)` : next === 0 ? "" : `rotate(${next}deg)`;
8443
8448
  this.context.invoke("editor.afterCommand");
@@ -8452,8 +8457,8 @@
8452
8457
  this._hide();
8453
8458
  this.context.invoke("imageResizer.deselect");
8454
8459
  const figure = img.closest("figure.an-figure");
8455
- if (figure && figure.parentNode) figure.parentNode.removeChild(figure);
8456
- else if (img.parentNode) img.parentNode.removeChild(img);
8460
+ if (figure) figure.remove();
8461
+ else img.remove();
8457
8462
  this.context.invoke("editor.afterCommand");
8458
8463
  }
8459
8464
  _crop() {
@@ -8472,7 +8477,7 @@
8472
8477
  this._hide();
8473
8478
  const range = document.createRange();
8474
8479
  range.selectNodeContents(cap);
8475
- const sel = window.getSelection();
8480
+ const sel = globalThis.getSelection();
8476
8481
  if (sel) {
8477
8482
  sel.removeAllRanges();
8478
8483
  sel.addRange(range);
@@ -8506,7 +8511,7 @@
8506
8511
  figure.appendChild(figcaption);
8507
8512
  const range = document.createRange();
8508
8513
  range.selectNodeContents(figcaption);
8509
- const sel = window.getSelection();
8514
+ const sel = globalThis.getSelection();
8510
8515
  if (sel) {
8511
8516
  sel.removeAllRanges();
8512
8517
  sel.addRange(range);
@@ -8547,8 +8552,7 @@
8547
8552
  const editable = this.context.layoutInfo.editable;
8548
8553
  this._disposers.push(on(editable, "mouseover", (e) => {
8549
8554
  if (this.context.layoutInfo.container.classList.contains("an-disabled")) return;
8550
- const target = e.target;
8551
- const wrapper = target && target.closest ? target.closest(".an-video-wrapper") : null;
8555
+ const wrapper = e.target?.closest(".an-video-wrapper");
8552
8556
  if (wrapper && editable.contains(wrapper)) this._scheduleShow(wrapper);
8553
8557
  }, { passive: true }), on(editable, "mouseout", (e) => {
8554
8558
  const to = e.relatedTarget;
@@ -8556,7 +8560,7 @@
8556
8560
  }, { passive: true }), on(document, "click", (e) => {
8557
8561
  const target = e.target;
8558
8562
  if (this._activeWrapper && !this._activeWrapper.contains(target) && !this._el.contains(target)) this._hide();
8559
- }), on(window, "scroll", () => this._hide(), { passive: true }), on(window, "resize", () => this._hide(), { passive: true }));
8563
+ }), on(globalThis, "scroll", () => this._hide(), { passive: true }), on(globalThis, "resize", () => this._hide(), { passive: true }));
8560
8564
  return this;
8561
8565
  }
8562
8566
  destroy() {
@@ -8564,7 +8568,7 @@
8564
8568
  this._clearTimers();
8565
8569
  this._disposers.forEach((d) => d());
8566
8570
  this._disposers = [];
8567
- if (this._el && this._el.parentNode) this._el.parentNode.removeChild(this._el);
8571
+ this._el?.remove();
8568
8572
  this._el = null;
8569
8573
  }
8570
8574
  _buildTooltip() {
@@ -8661,8 +8665,8 @@
8661
8665
  const margin = 6;
8662
8666
  let top = rect.bottom + margin;
8663
8667
  let left = rect.left + (rect.width - tipW) / 2;
8664
- if (top + tipH > window.innerHeight - margin) top = rect.top - tipH - margin;
8665
- if (left + tipW > window.innerWidth - margin) left = window.innerWidth - tipW - margin;
8668
+ if (top + tipH > globalThis.innerHeight - margin) top = rect.top - tipH - margin;
8669
+ if (left + tipW > globalThis.innerWidth - margin) left = globalThis.innerWidth - tipW - margin;
8666
8670
  if (left < margin) left = margin;
8667
8671
  this._el.style.top = `${top}px`;
8668
8672
  this._el.style.left = `${left}px`;
@@ -8716,7 +8720,7 @@
8716
8720
  if (!wrapper) return;
8717
8721
  this._hide();
8718
8722
  this.context.invoke("videoResizer.deselect");
8719
- if (wrapper.parentNode) wrapper.parentNode.removeChild(wrapper);
8723
+ wrapper.remove();
8720
8724
  this.context.invoke("editor.afterCommand");
8721
8725
  }
8722
8726
  _togglePreview() {
@@ -8958,12 +8962,12 @@
8958
8962
  }, { passive: true }), on(editable, "mouseout", (e) => {
8959
8963
  if (this._selectMode) return;
8960
8964
  const to = e.relatedTarget;
8961
- if (!to || !editable.contains(to) && !this._el.contains(to) && !(this._sizePopover && this._sizePopover.contains(to))) this._scheduleHide();
8965
+ if (!to || !editable.contains(to) && !this._el.contains(to) && !this._sizePopover?.contains(to)) this._scheduleHide();
8962
8966
  }, { passive: true }), on(document, "click", (e) => {
8963
8967
  const et = e.target;
8964
- if (this._selectMode && this._activeTable && this._activeTable.contains(et)) return;
8965
- if (this._activeTable && !this._activeTable.contains(et) && !this._el.contains(et) && !(this._sizePopover && this._sizePopover.contains(et))) this._hide();
8966
- }), on(document, "selectionchange", () => this._syncShadeStrip()), on(window, "scroll", () => this._hide(), { passive: true }), on(window, "resize", () => this._hide(), { passive: true }));
8968
+ if (this._selectMode && this._activeTable?.contains(et)) return;
8969
+ if (this._activeTable && !this._activeTable.contains(et) && !this._el.contains(et) && !this._sizePopover?.contains(et)) this._hide();
8970
+ }), on(document, "selectionchange", () => this._syncShadeStrip()), on(globalThis, "scroll", () => this._hide(), { passive: true }), on(globalThis, "resize", () => this._hide(), { passive: true }));
8967
8971
  this._initResize();
8968
8972
  return this;
8969
8973
  }
@@ -9089,11 +9093,11 @@
9089
9093
  this._clearTimers();
9090
9094
  this._disposers.forEach((d) => d());
9091
9095
  this._disposers = [];
9092
- if (this._el && this._el.parentNode) this._el.parentNode.removeChild(this._el);
9096
+ if (this._el && this._el.parentNode) this._el.remove();
9093
9097
  this._el = null;
9094
- if (this._sizePopover && this._sizePopover.parentNode) this._sizePopover.parentNode.removeChild(this._sizePopover);
9098
+ if (this._sizePopover && this._sizePopover.parentNode) this._sizePopover.remove();
9095
9099
  this._sizePopover = null;
9096
- if (this._shadePopover && this._shadePopover.parentNode) this._shadePopover.parentNode.removeChild(this._shadePopover);
9100
+ if (this._shadePopover && this._shadePopover.parentNode) this._shadePopover.remove();
9097
9101
  this._shadePopover = null;
9098
9102
  }
9099
9103
  _buildTooltip() {
@@ -9203,7 +9207,7 @@
9203
9207
  _syncShadeStrip() {
9204
9208
  if (!this._shadeColorStrip || !this._el || this._el.style.display === "none") return;
9205
9209
  const cell = this._getCell();
9206
- this._shadeColorStrip.style.background = cell && cell.style.backgroundColor || "transparent";
9210
+ this._shadeColorStrip.style.background = cell?.style.backgroundColor || "transparent";
9207
9211
  }
9208
9212
  _hide() {
9209
9213
  this._el.style.display = "none";
@@ -9233,20 +9237,20 @@
9233
9237
  let left = rect.left + (rect.width - tipW) / 2;
9234
9238
  let top = rect.top - tipH - margin;
9235
9239
  if (top < margin) top = rect.bottom + margin;
9236
- if (left + tipW > window.innerWidth - margin) left = window.innerWidth - tipW - margin;
9240
+ if (left + tipW > globalThis.innerWidth - margin) left = globalThis.innerWidth - tipW - margin;
9237
9241
  if (left < margin) left = margin;
9238
9242
  this._el.style.left = `${left}px`;
9239
9243
  this._el.style.top = `${top}px`;
9240
9244
  }
9241
9245
  _getCell() {
9242
- const sel = window.getSelection();
9246
+ const sel = globalThis.getSelection();
9243
9247
  if (sel && sel.rangeCount) {
9244
9248
  let container = sel.getRangeAt(0).commonAncestorContainer;
9245
9249
  if (container.nodeType === 3) container = container.parentElement;
9246
- const cellFromSel = container && container.closest("td, th");
9247
- if (cellFromSel && this._activeTable && this._activeTable.contains(cellFromSel)) return cellFromSel;
9250
+ const cellFromSel = container?.closest("td, th");
9251
+ if (cellFromSel && this._activeTable?.contains(cellFromSel)) return cellFromSel;
9248
9252
  }
9249
- return this._activeCell || this._activeTable && this._activeTable.querySelector("td, th");
9253
+ return this._activeCell || this._activeTable?.querySelector("td, th");
9250
9254
  }
9251
9255
  _toggleSelectMode() {
9252
9256
  this._selectMode = !this._selectMode;
@@ -9345,11 +9349,12 @@
9345
9349
  const table = cells[0].closest("table");
9346
9350
  if (!table) return;
9347
9351
  const allRows = Array.from(table.querySelectorAll("tr"));
9348
- const refRow = [...new Set(cells.map((c) => c.closest("tr")).filter(Boolean))].reduce((best, r) => {
9352
+ const selectedRows = [...new Set(cells.map((c) => c.closest("tr")).filter(Boolean))];
9353
+ const refRow = selectedRows.reduce((best, r) => {
9349
9354
  const bi = allRows.indexOf(best);
9350
9355
  const ri = allRows.indexOf(r);
9351
9356
  return position === "above" ? ri < bi ? r : best : ri > bi ? r : best;
9352
- });
9357
+ }, selectedRows[0]);
9353
9358
  const colCount = Array.from(refRow.cells).reduce((sum, c) => sum + (c.colSpan || 1), 0);
9354
9359
  const newRow = document.createElement("tr");
9355
9360
  const refCells = Array.from(refRow.cells);
@@ -9392,7 +9397,7 @@
9392
9397
  if (selectedRows.filter((r) => r.closest("tbody")).length >= totalBodyRows) return;
9393
9398
  this._activeCell = null;
9394
9399
  this._clearSelection();
9395
- selectedRows.forEach((r) => r.parentElement?.removeChild(r));
9400
+ selectedRows.forEach((r) => r.remove());
9396
9401
  requestAnimationFrame(() => this._positionNear(this._activeTable));
9397
9402
  this.context.invoke("editor.afterCommand");
9398
9403
  }
@@ -9414,7 +9419,7 @@
9414
9419
  });
9415
9420
  this._activeCell = null;
9416
9421
  this._clearSelection();
9417
- cellsToDelete.forEach((c) => c.parentElement?.removeChild(c));
9422
+ cellsToDelete.forEach((c) => c.remove());
9418
9423
  requestAnimationFrame(() => this._positionNear(this._activeTable));
9419
9424
  this.context.invoke("editor.afterCommand");
9420
9425
  }
@@ -9425,7 +9430,7 @@
9425
9430
  if (!table) return;
9426
9431
  let selected = this._getSelectedCells().filter((c) => table.contains(c));
9427
9432
  if (selected.length < 2) {
9428
- const sel = window.getSelection();
9433
+ const sel = globalThis.getSelection();
9429
9434
  if (!sel || sel.rangeCount === 0) return;
9430
9435
  const range = sel.getRangeAt(0);
9431
9436
  selected = Array.from(table.querySelectorAll("td, th")).filter((c) => {
@@ -9467,7 +9472,7 @@
9467
9472
  first.rowSpan = maxR - minR + 1;
9468
9473
  first.style.verticalAlign = "middle";
9469
9474
  first.innerHTML = rectCells.map((c) => c.innerHTML).join("");
9470
- rectCells.slice(1).forEach((c) => c.parentElement?.removeChild(c));
9475
+ rectCells.slice(1).forEach((c) => c.remove());
9471
9476
  this._clearSelection();
9472
9477
  this.context.invoke("editor.afterCommand");
9473
9478
  }
@@ -9475,7 +9480,7 @@
9475
9480
  const table = this._activeTable;
9476
9481
  if (!table) return;
9477
9482
  this._hide();
9478
- if (table.parentNode) table.parentNode.removeChild(table);
9483
+ if (table.parentNode) table.remove();
9479
9484
  this.context.invoke("editor.afterCommand");
9480
9485
  }
9481
9486
  _unmergeCells() {
@@ -9564,7 +9569,7 @@
9564
9569
  this._sizeInputEl = inputEl;
9565
9570
  this._sizeApply = null;
9566
9571
  const d1 = on(applyBtn, "click", () => {
9567
- const val = parseInt(this._sizeInputEl.value, 10);
9572
+ const val = Number.parseInt(this._sizeInputEl.value, 10);
9568
9573
  if (val > 0 && typeof this._sizeApply === "function") this._sizeApply(val);
9569
9574
  this._hideSizePopover();
9570
9575
  });
@@ -9593,7 +9598,7 @@
9593
9598
  const table = cell.closest("table");
9594
9599
  if (!table) return;
9595
9600
  const firstCell = table.querySelector("td, th");
9596
- const currentPx = firstCell ? parseInt(firstCell.style.borderWidth, 10) || parseInt(window.getComputedStyle(firstCell).borderWidth, 10) || 1 : 1;
9601
+ const currentPx = firstCell ? Number.parseInt(firstCell.style.borderWidth, 10) || Number.parseInt(globalThis.getComputedStyle(firstCell).borderWidth, 10) || 1 : 1;
9597
9602
  this._sizeTitleEl.textContent = this.context.locale.tooltips.table.tableBorderWidthPx;
9598
9603
  this._sizeInputEl.min = "0";
9599
9604
  this._sizeInputEl.max = "10";
@@ -9652,8 +9657,8 @@
9652
9657
  const ph = this._sizePopover.offsetHeight || 110;
9653
9658
  let left = tipRect.left;
9654
9659
  let top = tipRect.bottom + 6;
9655
- if (left + pw > window.innerWidth - 8) left = window.innerWidth - pw - 8;
9656
- if (top + ph > window.innerHeight - 8) top = tipRect.top - ph - 6;
9660
+ if (left + pw > globalThis.innerWidth - 8) left = globalThis.innerWidth - pw - 8;
9661
+ if (top + ph > globalThis.innerHeight - 8) top = tipRect.top - ph - 6;
9657
9662
  this._sizePopover.style.left = `${left}px`;
9658
9663
  this._sizePopover.style.top = `${top}px`;
9659
9664
  if (this._sizeInputEl) {
@@ -9707,11 +9712,10 @@
9707
9712
  customRow.appendChild(colorInput);
9708
9713
  customRow.appendChild(customLabel);
9709
9714
  pop.appendChild(customRow);
9710
- this._disposers.push(on(pop, "mousedown", (e) => e.preventDefault()));
9711
- this._disposers.push(on(pop, "mouseenter", () => this._clearTimers()), on(pop, "mouseleave", () => this._scheduleHide()));
9715
+ this._disposers.push(on(pop, "mousedown", (e) => e.preventDefault()), on(pop, "mouseenter", () => this._clearTimers()), on(pop, "mouseleave", () => this._scheduleHide()));
9712
9716
  this._disposers.push(on(document, "click", (e) => {
9713
9717
  const et = e.target;
9714
- if (this._shadePopover && this._shadePopover.style.display !== "none" && !this._shadePopover.contains(et) && !(this._el && this._el.contains(et))) this._hideCellShadePopover();
9718
+ if (this._shadePopover && this._shadePopover.style.display !== "none" && !this._shadePopover.contains(et) && !this._el?.contains(et)) this._hideCellShadePopover();
9715
9719
  }));
9716
9720
  return pop;
9717
9721
  }
@@ -9728,8 +9732,8 @@
9728
9732
  const tipRect = this._el.getBoundingClientRect();
9729
9733
  let left = tipRect.left;
9730
9734
  let top = tipRect.bottom + 6;
9731
- if (left + pw > window.innerWidth - 8) left = window.innerWidth - pw - 8;
9732
- if (top + ph > window.innerHeight - 8) top = tipRect.top - ph - 6;
9735
+ if (left + pw > globalThis.innerWidth - 8) left = globalThis.innerWidth - pw - 8;
9736
+ if (top + ph > globalThis.innerHeight - 8) top = tipRect.top - ph - 6;
9733
9737
  this._shadePopover.style.left = `${Math.max(8, left)}px`;
9734
9738
  this._shadePopover.style.top = `${Math.max(8, top)}px`;
9735
9739
  });
@@ -9792,7 +9796,7 @@
9792
9796
  this._clearTimers();
9793
9797
  this._disposers.forEach((d) => d());
9794
9798
  this._disposers = [];
9795
- if (this._el && this._el.parentNode) this._el.parentNode.removeChild(this._el);
9799
+ this._el?.remove();
9796
9800
  this._el = null;
9797
9801
  }
9798
9802
  _buildTooltip() {
@@ -9918,21 +9922,21 @@
9918
9922
  let top = rect.top - tipH - margin;
9919
9923
  let left = rect.left + (rect.width - tipW) / 2;
9920
9924
  if (top < margin) top = rect.bottom + margin;
9921
- if (left + tipW > window.innerWidth - margin) left = window.innerWidth - tipW - margin;
9925
+ if (left + tipW > globalThis.innerWidth - margin) left = globalThis.innerWidth - tipW - margin;
9922
9926
  if (left < margin) left = margin;
9923
9927
  this._el.style.top = `${top}px`;
9924
9928
  this._el.style.left = `${left}px`;
9925
9929
  }
9926
9930
  _syncWrapBtn() {
9927
9931
  if (!this._activePre || !this._wrapBtn) return;
9928
- const wrapped = (this._activePre.style.whiteSpace || "").includes("pre-wrap") || window.getComputedStyle(this._activePre).whiteSpace === "pre-wrap";
9932
+ const wrapped = (this._activePre.style.whiteSpace || "").includes("pre-wrap") || globalThis.getComputedStyle(this._activePre).whiteSpace === "pre-wrap";
9929
9933
  this._wrapBtn.classList.toggle("active", wrapped);
9930
9934
  this._wrapBtn.title = wrapped ? this.context.locale.tooltips.code.disableWordWrap : this.context.locale.tooltips.code.enableWordWrap;
9931
9935
  }
9932
9936
  _syncLangSelect() {
9933
9937
  if (!this._activePre || !this._langSelect) return;
9934
9938
  const codeEl = this._activePre.querySelector("code");
9935
- const fromAttr = this._activePre.getAttribute("data-language") || "";
9939
+ const fromAttr = this._activePre.dataset.language || "";
9936
9940
  const fromClass = codeEl ? (_LANG_CLASS_RE.exec(codeEl.className) || [])[1] || "" : "";
9937
9941
  this._langSelect.value = fromAttr || fromClass || "";
9938
9942
  }
@@ -9951,7 +9955,7 @@
9951
9955
  document.execCommand("copy");
9952
9956
  this._flashCopied();
9953
9957
  } catch (_) {}
9954
- document.body.removeChild(ta);
9958
+ ta.remove();
9955
9959
  }
9956
9960
  }
9957
9961
  _flashCopied() {
@@ -9984,7 +9988,6 @@
9984
9988
  applyLanguage(pre, lang) {
9985
9989
  if (!pre || !lang) return;
9986
9990
  const savedPre = this._activePre;
9987
- this._langSelect && this._langSelect.value;
9988
9991
  this._activePre = pre;
9989
9992
  if (this._langSelect) this._langSelect.value = lang;
9990
9993
  this._onLangChange();
@@ -9995,7 +9998,7 @@
9995
9998
  const pre = this._activePre;
9996
9999
  if (!pre) return;
9997
10000
  const lang = this._langSelect.value;
9998
- const _w = window;
10001
+ const _w = globalThis;
9999
10002
  let codeEl = pre.querySelector("code");
10000
10003
  if (!codeEl) {
10001
10004
  codeEl = document.createElement("code");
@@ -10005,15 +10008,15 @@
10005
10008
  }
10006
10009
  codeEl.className = lang ? `language-${lang}` : "";
10007
10010
  pre.className = lang ? `language-${lang}` : "";
10008
- if (lang) pre.setAttribute("data-language", lang);
10009
- else pre.removeAttribute("data-language");
10011
+ if (lang) pre.dataset.language = lang;
10012
+ else delete pre.dataset.language;
10010
10013
  const applyPrism = () => {
10011
10014
  codeEl.querySelectorAll("br").forEach((br) => br.replaceWith("\n"));
10012
10015
  _w.Prism.highlightElement(codeEl);
10013
10016
  this.context.invoke("editor.afterCommand");
10014
10017
  };
10015
10018
  if (lang) {
10016
- if (typeof _w.Prism !== "undefined") {
10019
+ if (_w.Prism !== void 0) {
10017
10020
  if (_w.Prism.languages[lang]) {
10018
10021
  applyPrism();
10019
10022
  return;
@@ -10035,7 +10038,7 @@
10035
10038
  * Called once at initialize time. Fire-and-forget; errors are silent.
10036
10039
  */
10037
10040
  _ensurePrism() {
10038
- const _w = window;
10041
+ const _w = globalThis;
10039
10042
  if (!this.context.options.codeHighlight || _w.Prism) return;
10040
10043
  const cdn = this.context.options.codeHighlightCDN;
10041
10044
  const themeHref = `${cdn}/themes/prism-tomorrow.min.css`;
@@ -10068,11 +10071,11 @@
10068
10071
  * @param {Function} cb – called once the grammar is ready
10069
10072
  */
10070
10073
  _loadPrismComponent(lang, cb) {
10071
- const _w = window;
10074
+ const _w = globalThis;
10072
10075
  const src = `${this.context.options.codeHighlightCDN}/components/prism-${lang}.min.js`;
10073
10076
  if (document.querySelector(`script[src="${src}"]`)) {
10074
10077
  const poll = setInterval(() => {
10075
- if (_w.Prism && _w.Prism.languages[lang]) {
10078
+ if (_w.Prism?.languages[lang]) {
10076
10079
  clearInterval(poll);
10077
10080
  cb();
10078
10081
  }
@@ -10103,7 +10106,7 @@
10103
10106
  const pre = this._activePre;
10104
10107
  if (!pre) return;
10105
10108
  this._hide();
10106
- if (pre.parentNode) pre.parentNode.removeChild(pre);
10109
+ pre.remove();
10107
10110
  this.context.invoke("editor.afterCommand");
10108
10111
  }
10109
10112
  };
@@ -12458,7 +12461,7 @@
12458
12461
  destroy() {
12459
12462
  this._disposers.forEach((d) => d());
12460
12463
  this._disposers = [];
12461
- if (this._dialog && this._dialog.parentNode) this._dialog.parentNode.removeChild(this._dialog);
12464
+ if (this._dialog && this._dialog.parentNode) this._dialog.remove();
12462
12465
  this._dialog = null;
12463
12466
  }
12464
12467
  show() {
@@ -12519,7 +12522,7 @@
12519
12522
  class: "an-icon-cat",
12520
12523
  "data-cat": id
12521
12524
  });
12522
- tab.textContent = L.categories && L.categories[id] || label;
12525
+ tab.textContent = L.categories?.[id] || label;
12523
12526
  catBar.appendChild(tab);
12524
12527
  });
12525
12528
  this._catBar = catBar;
@@ -12600,7 +12603,7 @@
12600
12603
  const savedRange = this._savedRange;
12601
12604
  const editable = this.context.layoutInfo.editable;
12602
12605
  if (savedRange) savedRange.select();
12603
- const sel = window.getSelection();
12606
+ const sel = globalThis.getSelection();
12604
12607
  let range = sel && sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
12605
12608
  if (!range) {
12606
12609
  range = document.createRange();
@@ -12610,7 +12613,7 @@
12610
12613
  const _sc = range.startContainer;
12611
12614
  const _tdAnchor = (_sc.nodeType === 1 ? _sc : _sc.parentElement)?.closest("td, th");
12612
12615
  range.deleteContents();
12613
- if (_tdAnchor && _tdAnchor.isConnected && !_tdAnchor.contains(range.startContainer)) {
12616
+ if (_tdAnchor?.isConnected && !_tdAnchor.contains(range.startContainer)) {
12614
12617
  range.setStart(_tdAnchor, 0);
12615
12618
  range.collapse(true);
12616
12619
  }
@@ -12630,7 +12633,7 @@
12630
12633
  if (this._dialog) {
12631
12634
  this._dialog.style.display = "flex";
12632
12635
  this._removeTrap = trapFocus(this._dialog, () => this._close());
12633
- setTimeout(() => this._searchInput && this._searchInput.focus(), 50);
12636
+ setTimeout(() => this._searchInput?.focus(), 50);
12634
12637
  }
12635
12638
  }
12636
12639
  _close() {
@@ -12937,7 +12940,7 @@
12937
12940
  destroy() {
12938
12941
  this._disposers.forEach((d) => d());
12939
12942
  this._disposers = [];
12940
- if (this._dialog && this._dialog.parentNode) this._dialog.parentNode.removeChild(this._dialog);
12943
+ this._dialog?.remove();
12941
12944
  this._dialog = null;
12942
12945
  }
12943
12946
  show() {
@@ -13002,7 +13005,7 @@
13002
13005
  class: "an-icon-cat",
13003
13006
  "data-cat": id
13004
13007
  });
13005
- tab.textContent = L.categories && L.categories[id] || label;
13008
+ tab.textContent = L.categories?.[id] || label;
13006
13009
  catBar.appendChild(tab);
13007
13010
  });
13008
13011
  this._catBar = catBar;
@@ -13170,17 +13173,17 @@
13170
13173
  this._preview.innerHTML = "<span class=\"an-icon-preview-hint\">Select an icon</span>";
13171
13174
  return;
13172
13175
  }
13173
- const cls = this._styleSelect && this._styleSelect.value || "fa-solid";
13174
- const size = this._sizeSelect && this._sizeSelect.value || "1em";
13175
- const color = (this._useColorCb ? this._useColorCb.checked : false) && this._colorInput ? this._colorInput.value : "";
13176
+ const cls = this._styleSelect?.value || "fa-solid";
13177
+ const size = this._sizeSelect?.value || "1em";
13178
+ const color = this._useColorCb?.checked ?? false ? this._colorInput?.value ?? "" : "";
13176
13179
  const styleAttr = [size ? `font-size:${size}` : "", color ? `color:${color}` : ""].filter(Boolean).join(";");
13177
13180
  this._preview.innerHTML = `<i class="${cls} fa-${name}" aria-hidden="true"${styleAttr ? ` style="${styleAttr}"` : ""}></i><div class="an-icon-preview-name">${cls} fa-${name}</div>`;
13178
13181
  }
13179
13182
  _onInsert() {
13180
13183
  if (!this._selectedIcon) return;
13181
- const cls = this._styleSelect && this._styleSelect.value || "fa-solid";
13182
- const size = this._sizeSelect && this._sizeSelect.value || "";
13183
- const color = (this._useColorCb ? this._useColorCb.checked : false) && this._colorInput ? this._colorInput.value : "";
13184
+ const cls = this._styleSelect?.value || "fa-solid";
13185
+ const size = this._sizeSelect?.value || "";
13186
+ const color = this._useColorCb?.checked ?? false ? this._colorInput?.value ?? "" : "";
13184
13187
  const styleParts = [size ? `font-size:${size}` : "", color ? `color:${color}` : ""].filter(Boolean);
13185
13188
  const iconEl = document.createElement("i");
13186
13189
  iconEl.className = `${cls} fa-${this._selectedIcon}`;
@@ -13190,8 +13193,8 @@
13190
13193
  const savedRange = this._savedRange;
13191
13194
  const editable = this.context.layoutInfo.editable;
13192
13195
  if (savedRange) savedRange.select();
13193
- const sel = window.getSelection();
13194
- let range = sel && sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
13196
+ const sel = globalThis.getSelection();
13197
+ let range = (sel?.rangeCount ?? 0) > 0 ? sel.getRangeAt(0) : null;
13195
13198
  if (!range) {
13196
13199
  range = document.createRange();
13197
13200
  range.selectNodeContents(editable);
@@ -13230,7 +13233,7 @@
13230
13233
  if (this._dialog) {
13231
13234
  this._dialog.style.display = "flex";
13232
13235
  this._removeTrap = trapFocus(this._dialog, () => this._close());
13233
- setTimeout(() => this._searchInput && this._searchInput.focus(), 50);
13236
+ setTimeout(() => this._searchInput?.focus(), 50);
13234
13237
  }
13235
13238
  }
13236
13239
  _close() {
@@ -13331,7 +13334,7 @@
13331
13334
  icon: ICONS.paste,
13332
13335
  action: (ctx) => {
13333
13336
  if (!navigator.clipboard) return;
13334
- const editable = ctx.layoutInfo && ctx.layoutInfo.editable;
13337
+ const editable = ctx.layoutInfo?.editable;
13335
13338
  if (!editable) return;
13336
13339
  const doInsert = (html, text) => {
13337
13340
  editable.focus();
@@ -13456,13 +13459,13 @@
13456
13459
  this.el.style.display = "none";
13457
13460
  document.body.appendChild(this.el);
13458
13461
  this._renderItems(this._items);
13459
- const editable = this.context.layoutInfo && this.context.layoutInfo.editable;
13462
+ const editable = this.context.layoutInfo?.editable;
13460
13463
  if (editable) this._disposers.push(on(editable, "contextmenu", (e) => this._onContextMenu(e)));
13461
13464
  this._disposers.push(on(document, "click", (e) => this._maybeHide(e)));
13462
13465
  this._disposers.push(on(document, "keydown", (e) => {
13463
13466
  if (e.key === "Escape") this.hide();
13464
13467
  }));
13465
- this._disposers.push(on(window, "scroll", () => this.hide(), { passive: true }));
13468
+ this._disposers.push(on(globalThis, "scroll", () => this.hide(), { passive: true }));
13466
13469
  return this;
13467
13470
  }
13468
13471
  destroy() {
@@ -13478,7 +13481,7 @@
13478
13481
  } catch (_e) {}
13479
13482
  });
13480
13483
  this._disposers = [];
13481
- if (this.el && this.el.parentNode) this.el.parentNode.removeChild(this.el);
13484
+ if (this.el) this.el.remove();
13482
13485
  this.el = null;
13483
13486
  }
13484
13487
  _renderItems(items) {
@@ -13506,8 +13509,8 @@
13506
13509
  backBtn.appendChild(createElement("span", { class: "an-context-label" }, [backLabel]));
13507
13510
  const off = on(backBtn, "click", (e) => {
13508
13511
  e.stopPropagation();
13509
- const curLeft = parseFloat(this.el.style.left);
13510
- const curTop = parseFloat(this.el.style.top);
13512
+ const curLeft = Number.parseFloat(this.el.style.left);
13513
+ const curTop = Number.parseFloat(this.el.style.top);
13511
13514
  this._renderItems(it.navigate());
13512
13515
  this._reposition(curLeft, curTop);
13513
13516
  });
@@ -13550,8 +13553,8 @@
13550
13553
  btn.appendChild(chevron);
13551
13554
  const off = on(btn, "click", (e) => {
13552
13555
  e.stopPropagation();
13553
- const curLeft = parseFloat(this.el.style.left);
13554
- const curTop = parseFloat(this.el.style.top);
13556
+ const curLeft = Number.parseFloat(this.el.style.left);
13557
+ const curTop = Number.parseFloat(this.el.style.top);
13555
13558
  this._renderItems(it.navigate());
13556
13559
  this._reposition(curLeft, curTop);
13557
13560
  });
@@ -13676,10 +13679,10 @@
13676
13679
  if (!cell) return;
13677
13680
  const rows = +cell.dataset.row;
13678
13681
  const cols = +cell.dataset.col;
13679
- const editable = this.context.layoutInfo && this.context.layoutInfo.editable;
13682
+ const editable = this.context.layoutInfo?.editable;
13680
13683
  if (editable && this._savedRange) {
13681
13684
  editable.focus();
13682
- const sel = window.getSelection();
13685
+ const sel = globalThis.getSelection();
13683
13686
  sel.removeAllRanges();
13684
13687
  sel.addRange(this._savedRange.cloneRange());
13685
13688
  }
@@ -13721,12 +13724,12 @@
13721
13724
  });
13722
13725
  }
13723
13726
  _onContextMenu(event) {
13724
- const editable = this.context.layoutInfo && this.context.layoutInfo.editable;
13727
+ const editable = this.context.layoutInfo?.editable;
13725
13728
  if (!editable) return;
13726
13729
  if (!editable.contains(event.target)) return;
13727
13730
  if (this.context.layoutInfo.container.classList.contains("an-disabled")) return;
13728
13731
  event.preventDefault();
13729
- const winSel = window.getSelection();
13732
+ const winSel = globalThis.getSelection();
13730
13733
  this._savedRange = winSel && winSel.rangeCount > 0 ? winSel.getRangeAt(0).cloneRange() : null;
13731
13734
  this._renderItems(this._items);
13732
13735
  const openX = event.clientX;
@@ -13758,9 +13761,9 @@
13758
13761
  const h = this.el.offsetHeight;
13759
13762
  let left = rx;
13760
13763
  let top = ry;
13761
- if (left + w > window.innerWidth - 8) left = window.innerWidth - w - 8;
13764
+ if (left + w > globalThis.innerWidth - 8) left = globalThis.innerWidth - w - 8;
13762
13765
  if (left < 8) left = 8;
13763
- if (top + h > window.innerHeight - 8) top = window.innerHeight - h - 8;
13766
+ if (top + h > globalThis.innerHeight - 8) top = globalThis.innerHeight - h - 8;
13764
13767
  if (top < 8) top = 8;
13765
13768
  this.el.style.left = `${left}px`;
13766
13769
  this.el.style.top = `${top}px`;
@@ -13781,17 +13784,17 @@
13781
13784
  let node = range.startContainer;
13782
13785
  if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
13783
13786
  if (!node) return type === "foreColor" ? "#000000" : "transparent";
13784
- const cs = window.getComputedStyle(node);
13787
+ const cs = globalThis.getComputedStyle(node);
13785
13788
  if (type === "foreColor") return cs.color || "#000000";
13786
13789
  const bg = cs.backgroundColor;
13787
13790
  return !bg || bg === "rgba(0, 0, 0, 0)" || bg === "transparent" ? "transparent" : bg;
13788
13791
  }
13789
13792
  /** Restore selection, apply a color command, then hide the menu. */
13790
13793
  _applyColor(type, color) {
13791
- const editable = this.context.layoutInfo && this.context.layoutInfo.editable;
13794
+ const editable = this.context.layoutInfo?.editable;
13792
13795
  if (!editable || !this._savedRange) return;
13793
13796
  editable.focus();
13794
- const sel = window.getSelection();
13797
+ const sel = globalThis.getSelection();
13795
13798
  sel.removeAllRanges();
13796
13799
  sel.addRange(this._savedRange.cloneRange());
13797
13800
  document.execCommand(type, false, color);
@@ -13806,15 +13809,15 @@
13806
13809
  copyFormat() {
13807
13810
  const range = this._savedRange;
13808
13811
  if (!range) return;
13809
- const editable = this.context.layoutInfo && this.context.layoutInfo.editable;
13812
+ const editable = this.context.layoutInfo?.editable;
13810
13813
  let node = range.startContainer;
13811
13814
  if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
13812
13815
  if (!node || !editable || !editable.contains(node)) return;
13813
- const cs = window.getComputedStyle(node);
13816
+ const cs = globalThis.getComputedStyle(node);
13814
13817
  const explicitFontFamily = this._findExplicitStyle(node, editable, "fontFamily");
13815
13818
  const explicitFontSize = this._findExplicitStyle(node, editable, "fontSize");
13816
13819
  this._copiedFormat = {
13817
- bold: parseInt(cs.fontWeight, 10) >= 700,
13820
+ bold: Number.parseInt(cs.fontWeight, 10) >= 700,
13818
13821
  italic: cs.fontStyle === "italic" || cs.fontStyle === "oblique",
13819
13822
  underline: (cs.textDecorationLine || "").includes("underline"),
13820
13823
  strikethrough: (cs.textDecorationLine || "").includes("line-through"),
@@ -13845,10 +13848,10 @@
13845
13848
  pasteFormat() {
13846
13849
  if (!this._copiedFormat || !this._savedRange) return;
13847
13850
  const fmt = this._copiedFormat;
13848
- const editable = this.context.layoutInfo && this.context.layoutInfo.editable;
13851
+ const editable = this.context.layoutInfo?.editable;
13849
13852
  if (!editable) return;
13850
13853
  editable.focus();
13851
- const sel = window.getSelection();
13854
+ const sel = globalThis.getSelection();
13852
13855
  sel.removeAllRanges();
13853
13856
  sel.addRange(this._savedRange.cloneRange());
13854
13857
  document.execCommand("removeFormat");
@@ -13865,14 +13868,14 @@
13865
13868
  const preExisting = new Set(editable.querySelectorAll("font[size=\"7\"]"));
13866
13869
  document.execCommand("fontSize", false, "7");
13867
13870
  editable.querySelectorAll("font[size=\"7\"]").forEach((el) => {
13868
- if (!preExisting.has(el)) el.setAttribute("data-an-tmp", marker);
13871
+ if (!preExisting.has(el)) /** @type {HTMLElement} */ el.dataset.anTmp = marker;
13869
13872
  });
13870
13873
  editable.querySelectorAll(`[data-an-tmp="${marker}"]`).forEach((el) => {
13871
13874
  const span = document.createElement("span");
13872
13875
  span.style.fontSize = fmt.fontSize;
13873
13876
  el.parentNode.insertBefore(span, el);
13874
13877
  while (el.firstChild) span.appendChild(el.firstChild);
13875
- el.parentNode.removeChild(el);
13878
+ el.remove();
13876
13879
  });
13877
13880
  }
13878
13881
  this.context.invoke("editor.afterCommand");
@@ -13880,10 +13883,10 @@
13880
13883
  /** Strip all inline formatting from the saved selection. */
13881
13884
  removeFormat() {
13882
13885
  if (!this._savedRange) return;
13883
- const editable = this.context.layoutInfo && this.context.layoutInfo.editable;
13886
+ const editable = this.context.layoutInfo?.editable;
13884
13887
  if (!editable) return;
13885
13888
  editable.focus();
13886
- const sel = window.getSelection();
13889
+ const sel = globalThis.getSelection();
13887
13890
  sel.removeAllRanges();
13888
13891
  sel.addRange(this._savedRange.cloneRange());
13889
13892
  document.execCommand("removeFormat");
@@ -13997,14 +14000,14 @@
13997
14000
  destroy() {
13998
14001
  this._disposers.forEach((d) => d());
13999
14002
  this._disposers = [];
14000
- if (this._dialog && this._dialog.parentNode) this._dialog.parentNode.removeChild(this._dialog);
14003
+ this._dialog?.remove();
14001
14004
  this._dialog = null;
14002
14005
  }
14003
14006
  show() {
14004
14007
  if (this._dialog) {
14005
14008
  this._dialog.style.display = "flex";
14006
14009
  this._removeTrap = trapFocus(this._dialog, () => this._close());
14007
- setTimeout(() => this._closeBtn && this._closeBtn.focus(), 50);
14010
+ setTimeout(() => this._closeBtn?.focus(), 50);
14008
14011
  }
14009
14012
  }
14010
14013
  _close() {
@@ -14110,7 +14113,7 @@
14110
14113
  this._clearHighlights();
14111
14114
  this._disposers.forEach((d) => d());
14112
14115
  this._disposers = [];
14113
- if (this._dialog && this._dialog.parentNode) this._dialog.parentNode.removeChild(this._dialog);
14116
+ if (this._dialog && this._dialog.parentNode) this._dialog.remove();
14114
14117
  this._dialog = null;
14115
14118
  }
14116
14119
  /**
@@ -14353,15 +14356,19 @@
14353
14356
  const re = this._queryRegex;
14354
14357
  const MAX_RESULTS = 500;
14355
14358
  const walker = document.createTreeWalker(root, 4);
14356
- let node;
14357
- while ((node = walker.nextNode()) && results.length < MAX_RESULTS) {
14359
+ let node = walker.nextNode();
14360
+ while (node && results.length < MAX_RESULTS) {
14358
14361
  re.lastIndex = 0;
14359
14362
  let m;
14360
- while ((m = re.exec(node.textContent)) !== null && results.length < MAX_RESULTS) results.push({
14363
+ while ((m = re.exec(
14364
+ /** @type {Text} */
14365
+ node.textContent
14366
+ )) !== null && results.length < MAX_RESULTS) results.push({
14361
14367
  node,
14362
14368
  start: m.index,
14363
14369
  end: m.index + m[0].length
14364
14370
  });
14371
+ node = walker.nextNode();
14365
14372
  }
14366
14373
  return results;
14367
14374
  }
@@ -14396,7 +14403,7 @@
14396
14403
  const parent = match.mark.parentNode;
14397
14404
  const textNode = document.createTextNode(replacement);
14398
14405
  parent.insertBefore(textNode, match.mark);
14399
- parent.removeChild(match.mark);
14406
+ match.mark.remove();
14400
14407
  parent.normalize();
14401
14408
  this.context.invoke("editor.afterCommand");
14402
14409
  const savedIndex = this._currentIndex;
@@ -14414,7 +14421,7 @@
14414
14421
  if (!mark || !mark.parentNode) return;
14415
14422
  const textNode = document.createTextNode(replacement);
14416
14423
  mark.parentNode.insertBefore(textNode, mark);
14417
- mark.parentNode.removeChild(mark);
14424
+ mark.remove();
14418
14425
  });
14419
14426
  if (this.context.layoutInfo.editable) this.context.layoutInfo.editable.normalize();
14420
14427
  this._matches = [];
@@ -14433,7 +14440,7 @@
14433
14440
  const parent = mark.parentNode;
14434
14441
  if (!parent) return;
14435
14442
  while (mark.firstChild) parent.insertBefore(mark.firstChild, mark);
14436
- parent.removeChild(mark);
14443
+ mark.remove();
14437
14444
  });
14438
14445
  editable.normalize();
14439
14446
  this._matches = [];
@@ -14484,7 +14491,7 @@
14484
14491
  resolve(null);
14485
14492
  }
14486
14493
  };
14487
- if (img.src.startsWith("data:") || img.src.startsWith("blob:") || img.src.startsWith(window.location.origin)) {
14494
+ if (img.src.startsWith("data:") || img.src.startsWith("blob:") || img.src.startsWith(globalThis.location.origin)) {
14488
14495
  tryDraw(img);
14489
14496
  return;
14490
14497
  }
@@ -14742,8 +14749,8 @@
14742
14749
  this._cropBox.style.top = `${y}px`;
14743
14750
  this._cropBox.style.width = `${w}px`;
14744
14751
  this._cropBox.style.height = `${h}px`;
14745
- const vw = window.innerWidth;
14746
- const vh = window.innerHeight;
14752
+ const vw = globalThis.innerWidth;
14753
+ const vh = globalThis.innerHeight;
14747
14754
  this._scrim.style.clipPath = [
14748
14755
  `polygon(`,
14749
14756
  `0 0, ${vw}px 0, ${vw}px ${vh}px, 0 ${vh}px, 0 0,`,
@@ -14767,7 +14774,7 @@
14767
14774
  }
14768
14775
  const margin = 8;
14769
14776
  let tbTop = y + h + margin;
14770
- if (tbTop + 40 > window.innerHeight - margin) tbTop = y - 40 - margin;
14777
+ if (tbTop + 40 > globalThis.innerHeight - margin) tbTop = y - 40 - margin;
14771
14778
  this._toolbar.style.left = `${x}px`;
14772
14779
  this._toolbar.style.top = `${tbTop}px`;
14773
14780
  }
@@ -14894,7 +14901,7 @@
14894
14901
  this._close(false);
14895
14902
  return;
14896
14903
  }
14897
- const fmt = img.src.match(/^data:image\/(jpe?g)/i) ? "image/jpeg" : "image/png";
14904
+ const fmt = /^data:image\/(jpe?g)/i.exec(img.src) ? "image/jpeg" : "image/png";
14898
14905
  const quality = fmt === "image/jpeg" ? .92 : void 0;
14899
14906
  const newSrc = canvas.toDataURL(fmt, quality);
14900
14907
  this._close(false);
@@ -14934,7 +14941,7 @@
14934
14941
  banner.textContent = msg;
14935
14942
  document.body.appendChild(banner);
14936
14943
  setTimeout(() => {
14937
- if (banner.parentNode) banner.parentNode.removeChild(banner);
14944
+ banner.remove();
14938
14945
  }, 4e3);
14939
14946
  }
14940
14947
  /**
@@ -14949,7 +14956,7 @@
14949
14956
  this._cropBox,
14950
14957
  this._toolbar
14951
14958
  ].forEach((el) => {
14952
- if (el && el.parentNode) el.parentNode.removeChild(el);
14959
+ el?.remove();
14953
14960
  });
14954
14961
  this._scrim = null;
14955
14962
  this._cropBox = null;
@@ -14970,7 +14977,7 @@
14970
14977
  *
14971
14978
  * Activated when both `autoSave` and `autoSaveRestore` options are true.
14972
14979
  * On initialize it checks localStorage for a draft that is within the
14973
- * `autoSaveRestoreTimeout` day window. If one is found a dismissible banner
14980
+ * `autoSaveRestoreTimeout` day globalThis. If one is found a dismissible banner
14974
14981
  * is prepended to the editor container.
14975
14982
  */
14976
14983
  var AutoSaveRestore = class {
@@ -15056,7 +15063,7 @@
15056
15063
  this._removeBanner();
15057
15064
  }
15058
15065
  _removeBanner() {
15059
- if (this._banner && this._banner.parentNode) this._banner.parentNode.removeChild(this._banner);
15066
+ this._banner?.remove();
15060
15067
  this._banner = null;
15061
15068
  }
15062
15069
  };
@@ -15119,8 +15126,8 @@
15119
15126
  * @returns {{ text: string, range: Range, lineNode: Node } | null}
15120
15127
  */
15121
15128
  _getLineContext() {
15122
- const sel = window.getSelection();
15123
- if (!sel || !sel.rangeCount) return null;
15129
+ const sel = globalThis.getSelection();
15130
+ if (!sel?.rangeCount) return null;
15124
15131
  const range = sel.getRangeAt(0);
15125
15132
  if (!range.collapsed) return null;
15126
15133
  const editable = this.context.layoutInfo.editable;
@@ -15139,7 +15146,7 @@
15139
15146
  }
15140
15147
  _isBlock(node) {
15141
15148
  if (node.nodeType !== Node.ELEMENT_NODE) return false;
15142
- const display = window.getComputedStyle(node).display;
15149
+ const display = globalThis.getComputedStyle(node).display;
15143
15150
  return display === "block" || display === "list-item" || display === "table-cell";
15144
15151
  }
15145
15152
  /** Applies block rule on Space key. Returns true if a rule fired. */
@@ -15170,7 +15177,7 @@
15170
15177
  }
15171
15178
  ];
15172
15179
  for (const { re, handler } of blockPatterns) {
15173
- const m = text.match(re);
15180
+ const m = re.exec(text);
15174
15181
  if (m) {
15175
15182
  handler(m);
15176
15183
  return true;
@@ -15194,8 +15201,8 @@
15194
15201
  return false;
15195
15202
  }
15196
15203
  _selectLineAndDelete() {
15197
- const sel = window.getSelection();
15198
- if (!sel || !sel.rangeCount) return;
15204
+ const sel = globalThis.getSelection();
15205
+ if (!sel?.rangeCount) return;
15199
15206
  const range = sel.getRangeAt(0);
15200
15207
  const startRange = document.createRange();
15201
15208
  startRange.setStart(range.startContainer.parentNode || range.startContainer, 0);
@@ -15233,8 +15240,8 @@
15233
15240
  this.context.triggerEvent("change", this.context.getHTML());
15234
15241
  }
15235
15242
  _onInput() {
15236
- const sel = window.getSelection();
15237
- if (!sel || !sel.rangeCount) return;
15243
+ const sel = globalThis.getSelection();
15244
+ if (!sel?.rangeCount) return;
15238
15245
  const range = sel.getRangeAt(0);
15239
15246
  if (!range.collapsed) return;
15240
15247
  if (!this.context.layoutInfo.editable.contains(range.startContainer)) return;
@@ -15262,7 +15269,7 @@
15262
15269
  ];
15263
15270
  const upToCursor = text.slice(0, offset);
15264
15271
  for (const { re, tag } of inlineRules) {
15265
- const m = upToCursor.match(re);
15272
+ const m = re.exec(upToCursor);
15266
15273
  if (!m) continue;
15267
15274
  const matchStart = upToCursor.length - m[0].length;
15268
15275
  const matchEnd = offset;
@@ -15273,11 +15280,8 @@
15273
15280
  el.textContent = innerText;
15274
15281
  const beforeNode = document.createTextNode(before);
15275
15282
  const afterNode = document.createTextNode("​" + after);
15276
- const parent = node.parentNode;
15277
- parent.insertBefore(beforeNode, node);
15278
- parent.insertBefore(el, node);
15279
- parent.insertBefore(afterNode, node);
15280
- parent.removeChild(node);
15283
+ /** @type {ChildNode} */ node.before(beforeNode, el, afterNode);
15284
+ /** @type {ChildNode} */ node.remove();
15281
15285
  const newRange = document.createRange();
15282
15286
  newRange.setStart(afterNode, 1);
15283
15287
  newRange.collapse(true);
@@ -15348,12 +15352,12 @@
15348
15352
  strikethrough: (ctx) => ctx.invoke("editor.strikethrough"),
15349
15353
  link: (ctx) => ctx.invoke("linkDialog.show"),
15350
15354
  removeFormat: (ctx) => {
15351
- const editable = ctx.layoutInfo && ctx.layoutInfo.editable;
15355
+ const editable = ctx.layoutInfo?.editable;
15352
15356
  if (!editable) return;
15353
15357
  editable.focus();
15354
15358
  document.execCommand("removeFormat");
15355
- const sel = window.getSelection();
15356
- if (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed) {
15359
+ const sel = globalThis.getSelection();
15360
+ if (sel?.rangeCount > 0 && !sel.getRangeAt(0).collapsed) {
15357
15361
  const range = sel.getRangeAt(0);
15358
15362
  const ancestor = range.commonAncestorContainer;
15359
15363
  const root = ancestor.nodeType === 1 ? ancestor : ancestor.parentElement;
@@ -15411,15 +15415,15 @@
15411
15415
  const d6 = this.context.on("contextMenu:hide", () => {
15412
15416
  this._contextMenuOpen = false;
15413
15417
  });
15414
- const d7 = on(window, "scroll", () => this._hide(), { passive: true });
15415
- const d8 = on(window, "resize", () => this._hide(), { passive: true });
15418
+ const d7 = on(globalThis, "scroll", () => this._hide(), { passive: true });
15419
+ const d8 = on(globalThis, "resize", () => this._hide(), { passive: true });
15416
15420
  this._disposers.push(d1, d2, d3, d4, d5, d6, d7, d8);
15417
15421
  return this;
15418
15422
  }
15419
15423
  destroy() {
15420
- if (this._el && this._el.parentNode) this._el.parentNode.removeChild(this._el);
15424
+ this._el?.remove();
15421
15425
  this._el = null;
15422
- if (this._picker && this._picker.parentNode) this._picker.parentNode.removeChild(this._picker);
15426
+ this._picker?.remove();
15423
15427
  this._picker = null;
15424
15428
  this._disposers.forEach((d) => d());
15425
15429
  this._disposers = [];
@@ -15533,15 +15537,15 @@
15533
15537
  pickerAny._colorInput = colorInput;
15534
15538
  }
15535
15539
  _openColorPicker(type, anchorBtn) {
15536
- const sel = window.getSelection();
15537
- if (sel && sel.rangeCount > 0) this._savedRange = sel.getRangeAt(0).cloneRange();
15540
+ const sel = globalThis.getSelection();
15541
+ if (sel?.rangeCount > 0) this._savedRange = sel.getRangeAt(0).cloneRange();
15538
15542
  this._pickerType = type;
15539
15543
  const pickerAny = this._picker;
15540
15544
  const palette = pickerAny._paletteEl;
15541
15545
  const noColorBtn = pickerAny._noColorBtn;
15542
15546
  if (type === "hiliteColor") {
15543
15547
  if (!palette.contains(noColorBtn)) palette.appendChild(noColorBtn);
15544
- } else if (palette.contains(noColorBtn)) palette.removeChild(noColorBtn);
15548
+ } else if (palette.contains(noColorBtn)) noColorBtn.remove();
15545
15549
  /** @type {any} */ this._picker._colorInput.value = type === "foreColor" ? "#000000" : "#ffff00";
15546
15550
  this._picker.style.display = "block";
15547
15551
  const pw = this._picker.offsetWidth;
@@ -15550,7 +15554,7 @@
15550
15554
  let top = toolbarRect.top - ph - 6;
15551
15555
  if (top < 8) top = toolbarRect.bottom + 6;
15552
15556
  let left = anchorBtn.getBoundingClientRect().left;
15553
- left = Math.max(8, Math.min(left, window.innerWidth - pw - 8));
15557
+ left = Math.max(8, Math.min(left, globalThis.innerWidth - pw - 8));
15554
15558
  this._picker.style.left = `${left}px`;
15555
15559
  this._picker.style.top = `${top}px`;
15556
15560
  }
@@ -15560,10 +15564,10 @@
15560
15564
  }
15561
15565
  /** Restore the saved selection, apply execCommand, update the color strip, then close the picker. */
15562
15566
  _applyColor(type, color) {
15563
- const editable = this.context.layoutInfo && this.context.layoutInfo.editable;
15567
+ const editable = this.context.layoutInfo?.editable;
15564
15568
  if (!editable || !this._savedRange) return;
15565
15569
  editable.focus();
15566
- const sel = window.getSelection();
15570
+ const sel = globalThis.getSelection();
15567
15571
  sel.removeAllRanges();
15568
15572
  try {
15569
15573
  sel.addRange(this._savedRange.cloneRange());
@@ -15574,8 +15578,7 @@
15574
15578
  if (!document.execCommand(cmd, false, color) && cmd === "hiliteColor") document.execCommand("backColor", false, color);
15575
15579
  this.context.invoke("editor.afterCommand");
15576
15580
  const name = type === "hiliteColor" ? "hiliteColor" : "foreColor";
15577
- const btn = this._el && this._el.querySelector(`[data-name="${name}"]`);
15578
- const strip = btn && btn.querySelector(".an-bubble-color-strip");
15581
+ const strip = (this._el?.querySelector(`[data-name="${name}"]`))?.querySelector(".an-bubble-color-strip");
15579
15582
  if (strip) /** @type {HTMLElement} */ strip.style.background = color === "transparent" ? "transparent" : color;
15580
15583
  this._closeColorPicker();
15581
15584
  this._syncActive();
@@ -15590,14 +15593,14 @@
15590
15593
  const gap = 8;
15591
15594
  let left = rect.left + rect.width / 2 - bw / 2;
15592
15595
  let top = rect.top - bh - gap;
15593
- left = Math.max(8, Math.min(left, window.innerWidth - bw - 8));
15596
+ left = Math.max(8, Math.min(left, globalThis.innerWidth - bw - 8));
15594
15597
  if (top < 8) top = rect.bottom + gap;
15595
15598
  const tableTooltipEl = document.querySelector(".an-table-tooltip");
15596
15599
  if (tableTooltipEl && tableTooltipEl.style.display !== "none") {
15597
15600
  const ttRect = tableTooltipEl.getBoundingClientRect();
15598
15601
  if (top < ttRect.bottom + gap && top + bh > ttRect.top - gap) {
15599
15602
  top = rect.bottom + gap;
15600
- if (top + bh > window.innerHeight - 8) top = ttRect.bottom + gap;
15603
+ if (top + bh > globalThis.innerHeight - 8) top = ttRect.bottom + gap;
15601
15604
  }
15602
15605
  }
15603
15606
  el.style.top = `${top}px`;
@@ -15623,17 +15626,15 @@
15623
15626
  /** Read the current selection's color and update the color-strip indicators. */
15624
15627
  _syncColorStrips() {
15625
15628
  if (!this._el) return;
15626
- const sel = window.getSelection();
15629
+ const sel = globalThis.getSelection();
15627
15630
  if (!sel || !sel.rangeCount) return;
15628
15631
  let node = sel.getRangeAt(0).startContainer;
15629
15632
  if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
15630
15633
  if (!node) return;
15631
- const cs = window.getComputedStyle(node);
15632
- const foreBtn = this._el.querySelector("[data-name=\"foreColor\"]");
15633
- const foreStrip = foreBtn && foreBtn.querySelector(".an-bubble-color-strip");
15634
+ const cs = globalThis.getComputedStyle(node);
15635
+ const foreStrip = this._el.querySelector("[data-name=\"foreColor\"]")?.querySelector(".an-bubble-color-strip");
15634
15636
  if (foreStrip) /** @type {HTMLElement} */ foreStrip.style.background = cs.color || "#000000";
15635
- const hiliteBtn = this._el.querySelector("[data-name=\"hiliteColor\"]");
15636
- const hiliteStrip = hiliteBtn && hiliteBtn.querySelector(".an-bubble-color-strip");
15637
+ const hiliteStrip = this._el.querySelector("[data-name=\"hiliteColor\"]")?.querySelector(".an-bubble-color-strip");
15637
15638
  if (hiliteStrip) {
15638
15639
  const bg = cs.backgroundColor;
15639
15640
  /** @type {HTMLElement} */ hiliteStrip.style.background = !bg || bg === "rgba(0, 0, 0, 0)" || bg === "transparent" ? "transparent" : bg;
@@ -15644,7 +15645,7 @@
15644
15645
  this._rafId = requestAnimationFrame(() => {
15645
15646
  if (this._contextMenuOpen) return;
15646
15647
  if (this._picker && this._picker.style.display !== "none") return;
15647
- const sel = window.getSelection();
15648
+ const sel = globalThis.getSelection();
15648
15649
  if (!sel || sel.isCollapsed || !sel.rangeCount) {
15649
15650
  this._hide();
15650
15651
  return;
@@ -15667,8 +15668,8 @@
15667
15668
  }
15668
15669
  _onMousedown(e) {
15669
15670
  if (!this._visible) return;
15670
- if (this._el && this._el.contains(e.target)) return;
15671
- if (this._picker && this._picker.contains(e.target)) return;
15671
+ if (this._el?.contains(e.target)) return;
15672
+ if (this._picker?.contains(e.target)) return;
15672
15673
  if (this.context.layoutInfo.editable.contains(e.target)) return;
15673
15674
  this._hide();
15674
15675
  }
@@ -15753,7 +15754,7 @@
15753
15754
  }
15754
15755
  destroy() {
15755
15756
  clearTimeout(this._debounceTimer);
15756
- if (this._dropdown && this._dropdown.parentNode) this._dropdown.parentNode.removeChild(this._dropdown);
15757
+ this._dropdown?.remove();
15757
15758
  this._dropdown = null;
15758
15759
  this._disposers.forEach((d) => d());
15759
15760
  this._disposers = [];
@@ -15817,8 +15818,8 @@
15817
15818
  const ddw = dd.offsetWidth;
15818
15819
  let top = rect.bottom + 4;
15819
15820
  let left = rect.left;
15820
- if (rect.bottom + ddh + 8 > window.innerHeight) top = rect.top - ddh - 4;
15821
- left = Math.max(8, Math.min(left, window.innerWidth - ddw - 8));
15821
+ if (rect.bottom + ddh + 8 > globalThis.innerHeight) top = rect.top - ddh - 4;
15822
+ left = Math.max(8, Math.min(left, globalThis.innerWidth - ddw - 8));
15822
15823
  dd.style.top = `${top}px`;
15823
15824
  dd.style.left = `${left}px`;
15824
15825
  dd.style.visibility = "";
@@ -15842,7 +15843,7 @@
15842
15843
  * collapsed range is reliable at this point but often empty inside async callbacks.
15843
15844
  */
15844
15845
  _captureCaretRect() {
15845
- if (this._triggerNode && this._triggerNode.isConnected) try {
15846
+ if (this._triggerNode?.isConnected) try {
15846
15847
  const r = document.createRange();
15847
15848
  const end = Math.min(this._triggerOffset + 1, this._triggerNode.textContent.length);
15848
15849
  r.setStart(this._triggerNode, this._triggerOffset);
@@ -15853,13 +15854,13 @@
15853
15854
  return;
15854
15855
  }
15855
15856
  } catch (_) {}
15856
- const sel = window.getSelection();
15857
+ const sel = globalThis.getSelection();
15857
15858
  if (!sel || !sel.rangeCount) return;
15858
15859
  const rects = sel.getRangeAt(0).getClientRects();
15859
15860
  if (rects.length > 0) this._caretRect = rects[rects.length - 1];
15860
15861
  }
15861
15862
  _getQueryAtCursor() {
15862
- const sel = window.getSelection();
15863
+ const sel = globalThis.getSelection();
15863
15864
  if (!sel || !sel.rangeCount) return null;
15864
15865
  const range = sel.getRangeAt(0);
15865
15866
  if (!range.collapsed) return null;
@@ -15916,7 +15917,7 @@
15916
15917
  }
15917
15918
  _onDocClick(e) {
15918
15919
  if (!this._open) return;
15919
- if (this._dropdown && this._dropdown.contains(e.target)) return;
15920
+ if (this._dropdown?.contains(e.target)) return;
15920
15921
  this._hideDropdown();
15921
15922
  }
15922
15923
  _select(index) {
@@ -15925,7 +15926,7 @@
15925
15926
  if (this._triggerNode) {
15926
15927
  const node = this._triggerNode;
15927
15928
  node.textContent = node.textContent.slice(0, this._triggerOffset) + node.textContent.slice(this._triggerOffset + this._cfg.trigger.length + this._query.length);
15928
- const sel = window.getSelection();
15929
+ const sel = globalThis.getSelection();
15929
15930
  const range = document.createRange();
15930
15931
  range.setStart(node, this._triggerOffset);
15931
15932
  range.collapse(true);
@@ -16286,23 +16287,27 @@
16286
16287
  a.style.display = "none";
16287
16288
  document.body.appendChild(a);
16288
16289
  a.click();
16289
- document.body.removeChild(a);
16290
+ a.remove();
16290
16291
  URL.revokeObjectURL(url);
16291
16292
  }
16292
16293
  /**
16293
- * Opens the editor content in a new window and triggers the browser print dialog.
16294
+ * Opens the editor content in a new globalThis and triggers the browser print dialog.
16294
16295
  * @param {string} [title='']
16295
16296
  */
16296
16297
  print(title = "") {
16297
16298
  const content = this.getHTML();
16298
- const safeTitle = (title || "").replace(/</g, "&lt;").replace(/>/g, "&gt;");
16299
- const w = window.open("", "_blank");
16300
- if (!w) return;
16301
- w.document.write(`<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>${safeTitle}</title><style>body{font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;font-size:14px;line-height:1.6;padding:20mm;color:#111827;}ul.an-checklist{list-style:none;padding-left:0;}ul.an-checklist li{padding-left:24px;position:relative;margin:2px 0;}ul.an-checklist li input[type="checkbox"]{position:absolute;left:0;top:3px;}code{background:#f3f4f6;border-radius:3px;padding:.1em .35em;font-family:monospace;}pre{background:#f3f4f6;padding:.75em 1em;border-radius:4px;overflow-x:auto;}table{border-collapse:collapse;}td,th{border:1px solid #d1d5db;padding:4px 8px;}</style></head><body>${content}</body></html>`);
16302
- w.document.close();
16303
- w.onload = () => {
16299
+ const markup = `<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>${(title || "").replace(/[<>&"']/g, (c) => `&#${c.charCodeAt(0)};`)}</title><style>body{font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;font-size:14px;line-height:1.6;padding:20mm;color:#111827;}ul.an-checklist{list-style:none;padding-left:0;}ul.an-checklist li{padding-left:24px;position:relative;margin:2px 0;}ul.an-checklist li input[type="checkbox"]{position:absolute;left:0;top:3px;}code{background:#f3f4f6;border-radius:3px;padding:.1em .35em;font-family:monospace;}pre{background:#f3f4f6;padding:.75em 1em;border-radius:4px;overflow-x:auto;}table{border-collapse:collapse;}td,th{border:1px solid #d1d5db;padding:4px 8px;}</style></head><body>${content}</body></html>`;
16300
+ const blob = new Blob([markup], { type: "text/html" });
16301
+ const url = URL.createObjectURL(blob);
16302
+ const w = globalThis.open(url, "_blank");
16303
+ if (!w) {
16304
+ URL.revokeObjectURL(url);
16305
+ return;
16306
+ }
16307
+ w.addEventListener("load", () => {
16304
16308
  w.print();
16305
- };
16309
+ URL.revokeObjectURL(url);
16310
+ });
16306
16311
  }
16307
16312
  /**
16308
16313
  * Sets whether the editor is disabled (readonly).
@@ -16340,10 +16345,10 @@
16340
16345
  this._disposers.forEach((d) => d());
16341
16346
  this._disposers = [];
16342
16347
  const container = this.layoutInfo.container;
16343
- const wasDark = container && container.classList.contains("an-theme-dark");
16344
- if (container && container.parentNode) {
16348
+ const wasDark = container?.classList.contains("an-theme-dark");
16349
+ if (container?.parentNode) {
16345
16350
  this.targetEl.style.display = "";
16346
- container.parentNode.removeChild(container);
16351
+ container.remove();
16347
16352
  }
16348
16353
  if (wasDark && !document.querySelector(".an-container.an-theme-dark")) document.body.classList.remove("an-theme-dark");
16349
16354
  if (typeof this.options.onDestroy === "function") this.options.onDestroy(this);
@@ -16365,7 +16370,7 @@
16365
16370
  * Inspired by Summernote's env.js
16366
16371
  */
16367
16372
  var userAgent = navigator.userAgent;
16368
- /Chrome\//.test(userAgent), /Firefox\//.test(userAgent), /^((?!chrome|android).)*safari/i.test(userAgent), /Edg\//.test(userAgent), /Macintosh/.test(userAgent), /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent), "ontouchstart" in window || navigator.maxTouchPoints, /Macintosh/.test(userAgent);
16373
+ /Chrome\//.test(userAgent), /Firefox\//.test(userAgent), /^((?!chrome|android).)*safari/i.test(userAgent), /Edg\//.test(userAgent), /Macintosh/.test(userAgent), /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent), "ontouchstart" in globalThis || navigator.maxTouchPoints, /Macintosh/.test(userAgent);
16369
16374
  //#endregion
16370
16375
  //#region src/js/index.js
16371
16376
  var _originalDefaults = { ...defaultOptions };