autumnnote 1.6.3 → 1.6.6

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.
@@ -145,9 +145,9 @@ function rect2bnd(rect) {
145
145
  var ELEMENT_NODE = 1;
146
146
  var TEXT_NODE = 3;
147
147
  /** @param {Node} node */
148
- var isElement = (node) => node && node.nodeType === 1;
148
+ var isElement = (node) => node?.nodeType === 1;
149
149
  /** @param {Node} node */
150
- var isText = (node) => node && node.nodeType === 3;
150
+ var isText = (node) => node?.nodeType === 3;
151
151
  /** @param {Node} node */
152
152
  var isVoid = (node) => isElement(node) && /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/i.test(node.nodeName);
153
153
  /** @param {Node} node */
@@ -252,7 +252,7 @@ function createElement(tag, attrs = {}, childNodes = []) {
252
252
  * @param {Node} node
253
253
  */
254
254
  function remove(node) {
255
- if (node && node.parentNode)
255
+ if (node?.parentNode)
256
256
  /** @type {ChildNode} */ node.remove();
257
257
  }
258
258
  /**
@@ -608,7 +608,7 @@ var italic = () => execCommand("italic");
608
608
  */
609
609
  function underline() {
610
610
  const sel = globalThis.getSelection();
611
- if (!sel || !sel.rangeCount) return;
611
+ if (!sel?.rangeCount) return;
612
612
  let container = sel.getRangeAt(0).commonAncestorContainer;
613
613
  if (container.nodeType === 3) container = container.parentElement;
614
614
  const uEl = container?.closest("u");
@@ -628,7 +628,7 @@ function underline() {
628
628
  */
629
629
  function strikethrough() {
630
630
  const sel = globalThis.getSelection();
631
- if (!sel || !sel.rangeCount) return;
631
+ if (!sel?.rangeCount) return;
632
632
  let sc = sel.getRangeAt(0).startContainer;
633
633
  if (sc.nodeType === 3) sc = sc.parentElement;
634
634
  const sEl = sc?.closest("s") || sc?.closest("strike");
@@ -672,8 +672,8 @@ var fontName = (name) => execCommand("fontName", name);
672
672
  */
673
673
  function fontSize(size, editable = document) {
674
674
  const sel = globalThis.getSelection();
675
- const wasCollapsed = !sel || !sel.rangeCount || sel.getRangeAt(0).collapsed;
676
- if (wasCollapsed && sel && sel.rangeCount > 0) {
675
+ const wasCollapsed = !sel?.rangeCount || sel.getRangeAt(0).collapsed;
676
+ if (wasCollapsed && sel?.rangeCount > 0) {
677
677
  try {
678
678
  const range = sel.getRangeAt(0);
679
679
  const span = document.createElement("span");
@@ -747,7 +747,7 @@ var indent = () => execCommand("indent");
747
747
  */
748
748
  function outdent() {
749
749
  const sel = globalThis.getSelection();
750
- if (sel && sel.rangeCount) {
750
+ if (sel?.rangeCount) {
751
751
  let container = sel.getRangeAt(0).commonAncestorContainer;
752
752
  if (container.nodeType === 3) container = container.parentElement;
753
753
  const checkLi = container?.closest(".an-checklist li");
@@ -797,7 +797,7 @@ function _checklistItemToP(checkLi) {
797
797
  try {
798
798
  const nr = document.createRange();
799
799
  const firstChild = p.firstChild;
800
- nr.setStart(firstChild && firstChild.nodeType === 3 ? firstChild : p, 0);
800
+ nr.setStart(firstChild?.nodeType === 3 ? firstChild : p, 0);
801
801
  nr.collapse(true);
802
802
  const s = globalThis.getSelection();
803
803
  if (s) {
@@ -876,7 +876,7 @@ function lineHeight(value) {
876
876
  */
877
877
  function toggleInlineCode(_editable) {
878
878
  const sel = globalThis.getSelection();
879
- if (!sel || !sel.rangeCount) return;
879
+ if (!sel?.rangeCount) return;
880
880
  const range = sel.getRangeAt(0);
881
881
  let container = range.commonAncestorContainer;
882
882
  if (container.nodeType === 3) container = container.parentElement;
@@ -932,7 +932,7 @@ function toggleInlineCode(_editable) {
932
932
  */
933
933
  function isInlineCode() {
934
934
  const sel = globalThis.getSelection();
935
- if (!sel || !sel.rangeCount) return false;
935
+ if (!sel?.rangeCount) return false;
936
936
  let sc = sel.getRangeAt(0).startContainer;
937
937
  if (sc.nodeType === 3) sc = sc.parentElement;
938
938
  const code = sc?.closest("code");
@@ -954,7 +954,7 @@ function isInlineCode() {
954
954
  */
955
955
  function toggleChecklist() {
956
956
  const sel = globalThis.getSelection();
957
- if (!sel || !sel.rangeCount) return;
957
+ if (!sel?.rangeCount) return;
958
958
  const range = sel.getRangeAt(0);
959
959
  let container = range.commonAncestorContainer;
960
960
  if (container.nodeType === 3) container = container.parentElement;
@@ -1003,7 +1003,7 @@ function toggleChecklist() {
1003
1003
  "LI"
1004
1004
  ]);
1005
1005
  let block = container;
1006
- while (block && block.parentNode && !BLOCK_TAGS.has(block.tagName)) block = block.parentNode;
1006
+ while (block?.parentNode && !BLOCK_TAGS.has(block.tagName)) block = block.parentNode;
1007
1007
  const itemText = block && BLOCK_TAGS.has(block.tagName) ? Array.from(block.childNodes).map((n) => n.textContent).join("").replaceAll("\xA0", " ") : "";
1008
1008
  const ul = document.createElement("ul");
1009
1009
  ul.className = "an-checklist";
@@ -1090,7 +1090,7 @@ function toggleChecklist() {
1090
1090
  */
1091
1091
  function isInChecklist() {
1092
1092
  const sel = globalThis.getSelection();
1093
- if (!sel || !sel.rangeCount) return false;
1093
+ if (!sel?.rangeCount) return false;
1094
1094
  let container = sel.getRangeAt(0).commonAncestorContainer;
1095
1095
  if (container.nodeType === 3) container = container.parentElement;
1096
1096
  return !!container?.closest(".an-checklist li");
@@ -1176,10 +1176,10 @@ var italicBtn = btn("italic", "italic", "Italic (Ctrl+I)", () => italic(), () =>
1176
1176
  var underlineBtn = btn("underline", "underline", "Underline (Ctrl+U)", () => underline(), () => {
1177
1177
  if (document.queryCommandState("underline")) return true;
1178
1178
  const sel = globalThis.getSelection();
1179
- if (!sel || !sel.rangeCount) return false;
1179
+ if (!sel?.rangeCount) return false;
1180
1180
  let sc = sel.getRangeAt(0).startContainer;
1181
1181
  if (sc.nodeType === 3) sc = sc.parentElement;
1182
- return !!(sc && sc.closest("u"));
1182
+ return !!sc?.closest("u");
1183
1183
  });
1184
1184
  var strikeBtn = btn("strikethrough", "strikethrough", "Strikethrough", () => strikethrough(), () => document.queryCommandState("strikeThrough"));
1185
1185
  var superscriptBtn = btn("superscript", "superscript", "Superscript", () => superscript(), () => document.queryCommandState("superscript"));
@@ -1239,11 +1239,11 @@ var fontSizeBtn = {
1239
1239
  getValue: (ctx) => {
1240
1240
  try {
1241
1241
  const sel = globalThis.getSelection();
1242
- if (sel && sel.rangeCount) {
1242
+ if (sel?.rangeCount) {
1243
1243
  let el = sel.getRangeAt(0).startContainer;
1244
- if (el && el.nodeType === 3) el = el.parentElement;
1245
- while (el && el.nodeType === 1 && !el.style.fontSize) el = el.parentElement;
1246
- const size = el && el.style.fontSize ? el.style.fontSize : "";
1244
+ if (el?.nodeType === 3) el = el.parentElement;
1245
+ while (el?.nodeType === 1 && !el.style.fontSize) el = el.parentElement;
1246
+ const size = el?.style.fontSize || "";
1247
1247
  if (size) return size;
1248
1248
  }
1249
1249
  const editable = ctx?.layoutInfo?.editable;
@@ -1351,7 +1351,7 @@ var lineHeightBtn = {
1351
1351
  getValue: () => {
1352
1352
  try {
1353
1353
  const sel = globalThis.getSelection();
1354
- if (!sel || !sel.rangeCount) return "";
1354
+ if (!sel?.rangeCount) return "";
1355
1355
  const BLOCKS = new Set([
1356
1356
  "P",
1357
1357
  "DIV",
@@ -1368,7 +1368,7 @@ var lineHeightBtn = {
1368
1368
  "TH"
1369
1369
  ]);
1370
1370
  let el = sel.getRangeAt(0).startContainer;
1371
- if (el && el.nodeType === 3) el = el.parentElement;
1371
+ if (el?.nodeType === 3) el = el.parentElement;
1372
1372
  while (el && !BLOCKS.has(
1373
1373
  /** @type {Element} */
1374
1374
  el.tagName
@@ -4503,7 +4503,7 @@ function renderLayout(targetEl, options) {
4503
4503
  }
4504
4504
  if (options.focusColor) container.style.setProperty("--an-focus-color", options.focusColor);
4505
4505
  targetEl.style.display = "none";
4506
- targetEl.insertAdjacentElement("afterend", container);
4506
+ targetEl.after(container);
4507
4507
  return {
4508
4508
  container,
4509
4509
  editable
@@ -4906,7 +4906,7 @@ function handleKeydown(event, editable, options = {}) {
4906
4906
  icon.remove();
4907
4907
  textNode.remove();
4908
4908
  const nr = document.createRange();
4909
- if (prevNode && prevNode.nodeType === Node.TEXT_NODE) nr.setStart(prevNode, prevNode.textContent.length);
4909
+ if (prevNode?.nodeType === Node.TEXT_NODE) nr.setStart(prevNode, prevNode.textContent.length);
4910
4910
  else if (prevNode) nr.setStartAfter(prevNode);
4911
4911
  else if (parent) nr.setStart(parent, 0);
4912
4912
  nr.collapse(true);
@@ -4943,7 +4943,7 @@ function handleKeydown(event, editable, options = {}) {
4943
4943
  const icon = textNode.nextSibling;
4944
4944
  const after = icon.nextSibling;
4945
4945
  event.preventDefault();
4946
- if (after && after.nodeType === Node.TEXT_NODE) {
4946
+ if (after?.nodeType === Node.TEXT_NODE) {
4947
4947
  const offset = (after.textContent || "").startsWith("​") ? 1 : 0;
4948
4948
  return moveCaret((nr) => nr.setStart(after, Math.min(offset, after.textContent.length)));
4949
4949
  }
@@ -4953,7 +4953,7 @@ function handleKeydown(event, editable, options = {}) {
4953
4953
  const icon = textNode.nextSibling.nextSibling;
4954
4954
  const after = icon.nextSibling;
4955
4955
  event.preventDefault();
4956
- if (after && after.nodeType === Node.TEXT_NODE) {
4956
+ if (after?.nodeType === Node.TEXT_NODE) {
4957
4957
  const offset = (after.textContent || "").startsWith("​") ? 1 : 0;
4958
4958
  return moveCaret((nr) => nr.setStart(after, Math.min(offset, after.textContent.length)));
4959
4959
  }
@@ -4978,7 +4978,7 @@ function handleKeydown(event, editable, options = {}) {
4978
4978
  if (isFAIcon(next)) {
4979
4979
  const after = next.nextSibling;
4980
4980
  event.preventDefault();
4981
- if (after && after.nodeType === Node.TEXT_NODE) {
4981
+ if (after?.nodeType === Node.TEXT_NODE) {
4982
4982
  const offset = (after.textContent || "").startsWith("​") ? 1 : 0;
4983
4983
  return moveCaret((nr) => nr.setStart(after, Math.min(offset, after.textContent.length)));
4984
4984
  }
@@ -4988,7 +4988,7 @@ function handleKeydown(event, editable, options = {}) {
4988
4988
  const icon = next.nextSibling;
4989
4989
  const after = icon.nextSibling;
4990
4990
  event.preventDefault();
4991
- if (after && after.nodeType === Node.TEXT_NODE) {
4991
+ if (after?.nodeType === Node.TEXT_NODE) {
4992
4992
  const offset = (after.textContent || "").startsWith("​") ? 1 : 0;
4993
4993
  return moveCaret((nr) => nr.setStart(after, Math.min(offset, after.textContent.length)));
4994
4994
  }
@@ -5090,11 +5090,11 @@ function handleKeydown(event, editable, options = {}) {
5090
5090
  newLi.appendChild(cb);
5091
5091
  if (afterFrag.textContent.replace(/[\u00a0\u200B]/g, "").length > 0) newLi.appendChild(afterFrag);
5092
5092
  let cursorNode = newLi.childNodes[1];
5093
- if (!cursorNode || cursorNode.nodeType !== Node.TEXT_NODE) {
5093
+ if (cursorNode?.nodeType !== Node.TEXT_NODE) {
5094
5094
  cursorNode = document.createTextNode("​");
5095
5095
  newLi.appendChild(cursorNode);
5096
5096
  }
5097
- checkLi.insertAdjacentElement("afterend", newLi);
5097
+ checkLi.after(newLi);
5098
5098
  const nr = document.createRange();
5099
5099
  nr.setStart(cursorNode, 0);
5100
5100
  nr.collapse(true);
@@ -5182,7 +5182,7 @@ function _domToMd(node, depth = 0) {
5182
5182
  return `\`${inner()}\``;
5183
5183
  case "pre": {
5184
5184
  const codeEl = el.querySelector("code");
5185
- const langMatch = /language-(\S+)/.exec(codeEl && codeEl.className || "");
5185
+ const langMatch = /language-(\S+)/.exec(codeEl?.className || "");
5186
5186
  return `\n\n\`\`\`${langMatch ? langMatch[1] : ""}\n${(codeEl || el).textContent || ""}\n\`\`\`\n\n`;
5187
5187
  }
5188
5188
  case "blockquote": return `\n\n${inner().trim().split("\n").map((l) => `> ${l}`).join("\n")}\n\n`;
@@ -5213,7 +5213,7 @@ function _domToMd(node, depth = 0) {
5213
5213
  case "table": {
5214
5214
  const rows = Array.from(el.querySelectorAll("tr"));
5215
5215
  if (!rows.length) return inner();
5216
- const cellTexts = rows.map((tr) => Array.from(tr.querySelectorAll("th, td")).map((c) => c.textContent.trim().replaceAll("|", "\\|")));
5216
+ const cellTexts = rows.map((tr) => Array.from(tr.querySelectorAll("th, td")).map((c) => c.textContent.trim().replaceAll("|", String.raw`\|`)));
5217
5217
  const cols = Math.max(...cellTexts.map((r) => r.length));
5218
5218
  const padRow = (row) => {
5219
5219
  const r = [...row];
@@ -5376,7 +5376,7 @@ function _escAttr(v) {
5376
5376
  * @returns {string|null}
5377
5377
  */
5378
5378
  function detectLang(code) {
5379
- if (!code || !code.trim()) return null;
5379
+ if (!code?.trim()) return null;
5380
5380
  const s = code.trim();
5381
5381
  if (/(:\s*(string|number|boolean|void|never|any|unknown)\b|interface\s+\w+\s*\{|type\s+\w+\s*[=<(]|<\w+>\s*[;,)]|readonly\s+\w|enum\s+\w+\s*\{|\?\s*:\s*\w|as\s+\w+\s*[;,)\]])/.test(s)) return "typescript";
5382
5382
  if (/\bprintln!\s*\(|\bprint!\s*\(|\bfn\s+\w+\s*(<[^>]*>)?\s*\(|\blet\s+mut\s|\bpub\s+fn\s|\buse\s+std::|\bimpl\s+\w+|\bOption<|\bResult<\w+/.test(s)) return "rust";
@@ -5440,7 +5440,7 @@ var Editor = class {
5440
5440
  const onSelChange = () => {
5441
5441
  if (!this.context._alive) return;
5442
5442
  const sel = globalThis.getSelection();
5443
- if (sel && sel.rangeCount > 0 && editable.contains(sel.anchorNode)) {
5443
+ if (sel?.rangeCount > 0 && editable.contains(sel.anchorNode)) {
5444
5444
  this.context.invoke("toolbar.refresh");
5445
5445
  if (typeof this.options.onSelectionChange === "function") this.options.onSelectionChange(this.context);
5446
5446
  }
@@ -5450,7 +5450,7 @@ var Editor = class {
5450
5450
  };
5451
5451
  const fixChecklistCursor = (event) => {
5452
5452
  const sel = globalThis.getSelection();
5453
- if (!sel || !sel.rangeCount) return;
5453
+ if (!sel?.rangeCount) return;
5454
5454
  const r = sel.getRangeAt(0);
5455
5455
  if (!r.collapsed) return;
5456
5456
  const sc = r.startContainer;
@@ -5460,7 +5460,7 @@ var Editor = class {
5460
5460
  if (!li) return;
5461
5461
  const cb = li.querySelector("input[type=\"checkbox\"]");
5462
5462
  if (!cb) return;
5463
- if (event && event.type === "mouseup") {
5463
+ if (event?.type === "mouseup") {
5464
5464
  let caret = null;
5465
5465
  if (document.caretRangeFromPoint) caret = document.caretRangeFromPoint(event.clientX, event.clientY);
5466
5466
  else if (document.caretPositionFromPoint) {
@@ -5504,7 +5504,7 @@ var Editor = class {
5504
5504
  let _compositionSupSub = null;
5505
5505
  const onCompositionStart = () => {
5506
5506
  const sel = globalThis.getSelection();
5507
- if (!sel || !sel.rangeCount) {
5507
+ if (!sel?.rangeCount) {
5508
5508
  _compositionSupSub = null;
5509
5509
  return;
5510
5510
  }
@@ -5522,7 +5522,7 @@ var Editor = class {
5522
5522
  _compositionSupSub = null;
5523
5523
  if (!tag) return;
5524
5524
  const sel = globalThis.getSelection();
5525
- if (!sel || !sel.rangeCount) return;
5525
+ if (!sel?.rangeCount) return;
5526
5526
  let node = sel.getRangeAt(0).startContainer;
5527
5527
  if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
5528
5528
  const el = node;
@@ -5856,7 +5856,7 @@ var Editor = class {
5856
5856
  formatBlock(tagName);
5857
5857
  if (tagName === "pre") {
5858
5858
  const sel = globalThis.getSelection();
5859
- if (sel && sel.rangeCount > 0) {
5859
+ if (sel?.rangeCount > 0) {
5860
5860
  const container = sel.getRangeAt(0).commonAncestorContainer;
5861
5861
  const pre = container.nodeType === 1 ? container.closest("pre") : container.parentElement?.closest("pre");
5862
5862
  if (pre && !pre.dataset.language) {
@@ -5916,10 +5916,7 @@ var Editor = class {
5916
5916
  if (!sel || sel.rangeCount === 0) return;
5917
5917
  const safeUrl = sanitiseUrl(url);
5918
5918
  if (!safeUrl) return;
5919
- if (!(sel.toString().trim().length > 0)) {
5920
- const displayText = this._escapeAttr(text || safeUrl);
5921
- execCommand("insertHTML", `<a href="${this._escapeAttr(safeUrl)}"${openInNewTab ? " target=\"_blank\" rel=\"noopener noreferrer\"" : ""}>${displayText}</a>`);
5922
- } else {
5919
+ if (sel.toString().trim().length > 0) {
5923
5920
  execCommand("createLink", safeUrl);
5924
5921
  if (openInNewTab) {
5925
5922
  const link = this._getClosestAnchor();
@@ -5928,6 +5925,9 @@ var Editor = class {
5928
5925
  /** @type {Element} */ link.setAttribute("rel", "noopener noreferrer");
5929
5926
  }
5930
5927
  }
5928
+ } else {
5929
+ const displayText = this._escapeAttr(text || safeUrl);
5930
+ execCommand("insertHTML", `<a href="${this._escapeAttr(safeUrl)}"${openInNewTab ? " target=\"_blank\" rel=\"noopener noreferrer\"" : ""}>${displayText}</a>`);
5931
5931
  }
5932
5932
  this.afterCommand();
5933
5933
  }
@@ -6105,7 +6105,7 @@ var Toolbar = class {
6105
6105
  this._refreshRaf = null;
6106
6106
  this._disposers.forEach((d) => d());
6107
6107
  this._disposers = [];
6108
- if (this.el && this.el.parentNode) this.el.remove();
6108
+ if (this.el?.parentNode) this.el.remove();
6109
6109
  this.el = null;
6110
6110
  }
6111
6111
  _buildButtons() {
@@ -6316,7 +6316,7 @@ var Toolbar = class {
6316
6316
  let savedRange = null;
6317
6317
  const saveSelection = () => {
6318
6318
  const sel = globalThis.getSelection();
6319
- savedRange = sel && sel.rangeCount ? sel.getRangeAt(0).cloneRange() : null;
6319
+ savedRange = sel?.rangeCount ? sel.getRangeAt(0).cloneRange() : null;
6320
6320
  };
6321
6321
  const restoreSelection = () => {
6322
6322
  if (!savedRange) return;
@@ -6434,7 +6434,10 @@ var Toolbar = class {
6434
6434
  select.appendChild(placeholder);
6435
6435
  items.forEach((item) => {
6436
6436
  const value = typeof item === "object" ? item.value : item;
6437
- const label = typeof item === "object" ? def.name === "paragraphStyle" ? (this.context.locale.toolbar.paragraphItems || {})[item.value] || item.label : item.label : item;
6437
+ let label;
6438
+ if (typeof item !== "object") label = item;
6439
+ else if (def.name === "paragraphStyle") label = this.context.locale.toolbar.paragraphItems?.[item.value] || item.label;
6440
+ else label = item.label;
6438
6441
  const isHeader = typeof item === "object" && !!item.disabled;
6439
6442
  const attrs = { value };
6440
6443
  if (isHeader) attrs.disabled = "";
@@ -6446,7 +6449,7 @@ var Toolbar = class {
6446
6449
  let _savedRange = null;
6447
6450
  const dMousedown = on(select, "mousedown", () => {
6448
6451
  const sel = globalThis.getSelection();
6449
- _savedRange = sel && sel.rangeCount ? sel.getRangeAt(0).cloneRange() : null;
6452
+ _savedRange = sel?.rangeCount ? sel.getRangeAt(0).cloneRange() : null;
6450
6453
  });
6451
6454
  const disposer = on(select, "change", (e) => {
6452
6455
  const value = e.target.value;
@@ -6534,9 +6537,9 @@ var Toolbar = class {
6534
6537
  );
6535
6538
  if (!def || typeof def.getValue !== "function") return;
6536
6539
  let raw = (def.getValue(this.context) || "").replace(/["']/g, "").trim();
6537
- if (!raw) raw = this.options.defaultFontFamily || this.options.fontFamilies && this.options.fontFamilies[0] || "";
6540
+ if (!raw) raw = this.options.defaultFontFamily || this.options.fontFamilies?.[0] || "";
6538
6541
  const sel = select;
6539
- const matched = Array.from(sel.options).find((opt) => opt.value && opt.value.toLowerCase() === raw.toLowerCase());
6542
+ const matched = Array.from(sel.options).find((opt) => opt.value?.toLowerCase() === raw.toLowerCase());
6540
6543
  sel.value = matched ? matched.value : "";
6541
6544
  });
6542
6545
  }
@@ -6795,7 +6798,7 @@ var Clipboard = class {
6795
6798
  * @param {Node} node
6796
6799
  */
6797
6800
  _revokeRemovedBlobs(node) {
6798
- if (!this._blobRegistry || !this._blobRegistry.size) return;
6801
+ if (!this._blobRegistry?.size) return;
6799
6802
  const imgs = [];
6800
6803
  if (node.nodeName === "IMG") imgs.push(node);
6801
6804
  else if (node.querySelectorAll) imgs.push(...node.querySelectorAll("img"));
@@ -6933,7 +6936,7 @@ var Clipboard = class {
6933
6936
  }
6934
6937
  _onDrop(event) {
6935
6938
  const dt = event.dataTransfer;
6936
- if (!dt || !dt.files || dt.files.length === 0) return;
6939
+ if (!dt?.files?.length) return;
6937
6940
  const imageFiles = Array.from(dt.files).filter((f) => f.type.startsWith("image/"));
6938
6941
  if (imageFiles.length === 0) return;
6939
6942
  event.preventDefault();
@@ -6962,7 +6965,7 @@ var Clipboard = class {
6962
6965
  ]);
6963
6966
  const maxBytes = (this.options.maxImageSize || 5) * 1024 * 1024;
6964
6967
  files.forEach((file) => {
6965
- if (!file || !file.type.startsWith("image/")) return;
6968
+ if (!file?.type?.startsWith("image/")) return;
6966
6969
  if (UNSUPPORTED.has(file.type)) {
6967
6970
  const message = `Image format "${file.type}" is not supported for display in web browsers. Please convert to PNG, JPEG, or WebP first.`;
6968
6971
  this.context.triggerEvent("imageError", {
@@ -7005,7 +7008,7 @@ var Clipboard = class {
7005
7008
  * @returns {string}
7006
7009
  */
7007
7010
  resolveImages(html) {
7008
- if (!this._blobRegistry || !this._blobRegistry.size) return html;
7011
+ if (!this._blobRegistry?.size) return html;
7009
7012
  return html.replace(/blob:[^"'> \t\n\r]*/g, (url) => this._blobRegistry.get(url) || url);
7010
7013
  }
7011
7014
  /**
@@ -7321,7 +7324,7 @@ var BaseDialog = class {
7321
7324
  if (this._dialog) {
7322
7325
  this._dialog.style.display = "flex";
7323
7326
  this._removeTrap = trapFocus(this._dialog, () => this._close());
7324
- setTimeout(() => this._firstInput && this._firstInput.focus(), 50);
7327
+ setTimeout(() => this._firstInput?.focus(), 50);
7325
7328
  }
7326
7329
  }
7327
7330
  _close() {
@@ -7467,7 +7470,7 @@ var LinkDialog = class extends BaseDialog {
7467
7470
  _prefill() {
7468
7471
  const sel = globalThis.getSelection();
7469
7472
  let anchor = null;
7470
- if (sel && sel.rangeCount > 0) {
7473
+ if (sel?.rangeCount > 0) {
7471
7474
  let node = sel.getRangeAt(0).startContainer;
7472
7475
  while (node) {
7473
7476
  if (node.nodeName === "A") {
@@ -7620,8 +7623,8 @@ var ImageDialog = class extends BaseDialog {
7620
7623
  return overlay;
7621
7624
  }
7622
7625
  _onFileChange() {
7623
- const file = this._fileInput && this._fileInput.files && this._fileInput.files[0];
7624
- if (!file || !file.type.startsWith("image/")) return;
7626
+ const file = this._fileInput?.files?.[0];
7627
+ if (!file?.type?.startsWith("image/")) return;
7625
7628
  if (!new Set([
7626
7629
  "image/jpeg",
7627
7630
  "image/png",
@@ -7661,7 +7664,7 @@ var ImageDialog = class extends BaseDialog {
7661
7664
  _onInsert() {
7662
7665
  const src = this._urlInput.value.trim();
7663
7666
  const alt = this._altInput.value.trim();
7664
- const alignRadio = this._alignRow && this._alignRow.querySelector("input[name=\"an-img-align\"]:checked");
7667
+ const alignRadio = this._alignRow?.querySelector("input[name=\"an-img-align\"]:checked");
7665
7668
  const align = alignRadio ? alignRadio.value : "";
7666
7669
  if (!src) {
7667
7670
  this._urlInput.focus();
@@ -7721,7 +7724,10 @@ var VideoDialog = class extends BaseDialog {
7721
7724
  box.append(urlLabel, urlInput, hintEl, widthLabel, widthInput, btnRow);
7722
7725
  const d0 = on(urlInput, "input", () => {
7723
7726
  const info = this._parseVideoUrl(urlInput.value.trim());
7724
- hintEl.textContent = info ? this.context.locale.videoDialog.detected(info.type) : urlInput.value ? this.context.locale.videoDialog.unknownFormat : "";
7727
+ let hint = "";
7728
+ if (info) hint = this.context.locale.videoDialog.detected(info.type);
7729
+ else if (urlInput.value) hint = this.context.locale.videoDialog.unknownFormat;
7730
+ hintEl.textContent = hint;
7725
7731
  });
7726
7732
  const d4 = on(urlInput, "keydown", (e) => {
7727
7733
  if (e.key === "Enter") {
@@ -7801,7 +7807,7 @@ var VideoDialog = class extends BaseDialog {
7801
7807
  const iframeTitle = `${info.type} video player`;
7802
7808
  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>`;
7803
7809
  }
7804
- 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>`;
7810
+ if (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>`;
7805
7811
  const safeSrc = (() => {
7806
7812
  try {
7807
7813
  const p = new URL(url);
@@ -7898,7 +7904,7 @@ var ImageResizer = class {
7898
7904
  this._positionRaf = null;
7899
7905
  }
7900
7906
  this._deselect();
7901
- if (this._overlay && this._overlay.parentNode) this._overlay.remove();
7907
+ if (this._overlay?.parentNode) this._overlay.remove();
7902
7908
  this._overlay = null;
7903
7909
  }
7904
7910
  /** @returns {HTMLImageElement|null} */
@@ -7941,7 +7947,7 @@ var ImageResizer = class {
7941
7947
  _onDocClick(e) {
7942
7948
  if (!this._activeImg) return;
7943
7949
  if (e.target === this._activeImg) return;
7944
- if (this._overlay && this._overlay.contains(e.target)) return;
7950
+ if (this._overlay?.contains(e.target)) return;
7945
7951
  if (e.target.closest(".an-contextmenu")) return;
7946
7952
  this._deselect();
7947
7953
  }
@@ -7973,7 +7979,7 @@ var ImageResizer = class {
7973
7979
  const containerRect = offsetParent.getBoundingClientRect();
7974
7980
  const rect = this._activeImg.getBoundingClientRect();
7975
7981
  const p = this._lastOverlayPos;
7976
- if (p && p.l === rect.left && p.t === rect.top && p.w === rect.width && p.h === rect.height) return;
7982
+ if (p?.l === rect.left && p.t === rect.top && p.w === rect.width && p.h === rect.height) return;
7977
7983
  this._lastOverlayPos = {
7978
7984
  l: rect.left,
7979
7985
  t: rect.top,
@@ -8303,7 +8309,7 @@ var LinkTooltip = class {
8303
8309
  this._clearTimers();
8304
8310
  this._disposers.forEach((d) => d());
8305
8311
  this._disposers = [];
8306
- if (this._el && this._el.parentNode) this._el.remove();
8312
+ if (this._el?.parentNode) this._el.remove();
8307
8313
  this._el = null;
8308
8314
  }
8309
8315
  _buildTooltip() {
@@ -8397,7 +8403,7 @@ var LinkTooltip = class {
8397
8403
  _truncateUrl(url) {
8398
8404
  try {
8399
8405
  const u = new URL(url);
8400
- const display = u.host + (u.pathname !== "/" ? u.pathname : "");
8406
+ const display = u.host + (u.pathname === "/" ? "" : u.pathname);
8401
8407
  return display.length > 48 ? display.slice(0, 48) + "…" : display;
8402
8408
  } catch {
8403
8409
  return url.length > 48 ? url.slice(0, 48) + "…" : url;
@@ -8422,7 +8428,7 @@ var LinkTooltip = class {
8422
8428
  });
8423
8429
  if (this._copyBtn) {
8424
8430
  this._copyBtn.classList.add("an-link-tooltip-btn--copied");
8425
- setTimeout(() => this._copyBtn && this._copyBtn.classList.remove("an-link-tooltip-btn--copied"), 1e3);
8431
+ setTimeout(() => this._copyBtn?.classList.remove("an-link-tooltip-btn--copied"), 1e3);
8426
8432
  }
8427
8433
  }
8428
8434
  _editLink() {
@@ -8657,7 +8663,8 @@ var ImageTooltip = class {
8657
8663
  const match = /rotate\((-?[\d.]+)deg\)/.exec(current);
8658
8664
  const next = ((match ? Number.parseFloat(match[1]) : 0) + delta + 360) % 360;
8659
8665
  const cleaned = current.replace(/rotate\(-?[\d.]+deg\)/, "").trim();
8660
- img.style.transform = cleaned ? `${cleaned} rotate(${next}deg)` : next === 0 ? "" : `rotate(${next}deg)`;
8666
+ if (cleaned) img.style.transform = `${cleaned} rotate(${next}deg)`;
8667
+ else img.style.transform = next === 0 ? "" : `rotate(${next}deg)`;
8661
8668
  this.context.invoke("editor.afterCommand");
8662
8669
  this.context.invoke("imageResizer.updateOverlay");
8663
8670
  requestAnimationFrame(() => {
@@ -9018,7 +9025,7 @@ function getCellAfterVisualCol(row, visualIdx) {
9018
9025
  vIdx += c.colSpan || 1;
9019
9026
  if (vIdx > visualIdx) {
9020
9027
  const next = c.nextElementSibling;
9021
- return next && next.tagName === "TD" || next && next.tagName === "TH" ? next : null;
9028
+ return next?.tagName === "TD" || next?.tagName === "TH" ? next : null;
9022
9029
  }
9023
9030
  }
9024
9031
  return null;
@@ -9160,8 +9167,7 @@ var TableTooltip = class {
9160
9167
  const onSelMouseup = () => {
9161
9168
  this._selectDragging = false;
9162
9169
  };
9163
- this._disposers.push(on(editable, "mousedown", onSelMousedown), on(editable, "mousemove", onSelMousemove), on(document, "mouseup", onSelMouseup));
9164
- this._disposers.push(on(editable, "mouseover", (e) => {
9170
+ this._disposers.push(on(editable, "mousedown", onSelMousedown), on(editable, "mousemove", onSelMousemove), on(document, "mouseup", onSelMouseup), on(editable, "mouseover", (e) => {
9165
9171
  if (this.context.layoutInfo.container.classList.contains("an-disabled")) return;
9166
9172
  const table = e.target?.closest("table");
9167
9173
  if (table && editable.contains(table)) {
@@ -9249,12 +9255,14 @@ var TableTooltip = class {
9249
9255
  _startY = e.clientY;
9250
9256
  _table = _nearCell.closest("table");
9251
9257
  if (_edge === "col") {
9252
- _startW = _nearCell.offsetWidth;
9253
- _colIdx = getVisualColIndex(_nearCell);
9258
+ _colIdx = getVisualColIndex(_nearCell) + (_nearCell.colSpan || 1) - 1;
9254
9259
  _colCells = _colIdx >= 0 ? Array.from(_table.querySelectorAll("tr")).map((r) => getCellAtVisualCol(r, _colIdx)).filter(Boolean).filter((c) => (c.colSpan || 1) === 1) : [];
9260
+ _startW = _colCells.length > 0 ? _colCells[0].offsetWidth : Math.max(30, Math.round(_nearCell.offsetWidth / (_nearCell.colSpan || 1)));
9255
9261
  document.body.style.cursor = "col-resize";
9256
9262
  } else {
9257
- _row = _nearCell.closest("tr");
9263
+ const tr = _nearCell.closest("tr");
9264
+ const lastRowIdx = (tr ? Array.from(_table.rows).indexOf(tr) : 0) + (_nearCell.rowSpan || 1) - 1;
9265
+ _row = _table.rows[lastRowIdx] || tr;
9258
9266
  _startH = _row ? _row.offsetHeight : 40;
9259
9267
  document.body.style.cursor = "row-resize";
9260
9268
  }
@@ -9306,11 +9314,11 @@ var TableTooltip = class {
9306
9314
  this._clearTimers();
9307
9315
  this._disposers.forEach((d) => d());
9308
9316
  this._disposers = [];
9309
- if (this._el && this._el.parentNode) this._el.remove();
9317
+ if (this._el?.parentNode) this._el.remove();
9310
9318
  this._el = null;
9311
- if (this._sizePopover && this._sizePopover.parentNode) this._sizePopover.remove();
9319
+ if (this._sizePopover?.parentNode) this._sizePopover.remove();
9312
9320
  this._sizePopover = null;
9313
- if (this._shadePopover && this._shadePopover.parentNode) this._shadePopover.remove();
9321
+ if (this._shadePopover?.parentNode) this._shadePopover.remove();
9314
9322
  this._shadePopover = null;
9315
9323
  }
9316
9324
  _buildTooltip() {
@@ -9457,7 +9465,7 @@ var TableTooltip = class {
9457
9465
  }
9458
9466
  _getCell() {
9459
9467
  const sel = globalThis.getSelection();
9460
- if (sel && sel.rangeCount) {
9468
+ if (sel?.rangeCount) {
9461
9469
  let container = sel.getRangeAt(0).commonAncestorContainer;
9462
9470
  if (container.nodeType === 3) container = container.parentElement;
9463
9471
  const cellFromSel = container?.closest("td, th");
@@ -9494,7 +9502,7 @@ var TableTooltip = class {
9494
9502
  if (!startCell) return [];
9495
9503
  if (!endCell || startCell === endCell) return [startCell];
9496
9504
  const table = startCell.closest("table");
9497
- if (!table || !table.contains(endCell)) return [startCell];
9505
+ if (!table?.contains(endCell)) return [startCell];
9498
9506
  const { gridMap, cellPos } = buildGridMap(table);
9499
9507
  const sp = cellPos.get(startCell);
9500
9508
  const ep = cellPos.get(endCell);
@@ -9566,7 +9574,8 @@ var TableTooltip = class {
9566
9574
  const refRow = selectedRows.reduce((best, r) => {
9567
9575
  const bi = allRows.indexOf(best);
9568
9576
  const ri = allRows.indexOf(r);
9569
- return position === "above" ? ri < bi ? r : best : ri > bi ? r : best;
9577
+ if (position === "above") return ri < bi ? r : best;
9578
+ return ri > bi ? r : best;
9570
9579
  }, selectedRows[0]);
9571
9580
  const colCount = Array.from(refRow.cells).reduce((sum, c) => sum + (c.colSpan || 1), 0);
9572
9581
  const newRow = document.createElement("tr");
@@ -9574,12 +9583,12 @@ var TableTooltip = class {
9574
9583
  for (let i = 0; i < colCount; i++) {
9575
9584
  const td = createElement("td", {}, ["\xA0"]);
9576
9585
  const ref = refCells[i];
9577
- if (ref && ref.style.width) td.style.width = ref.style.width;
9578
- if (ref && ref.style.minWidth) td.style.minWidth = ref.style.minWidth;
9586
+ if (ref?.style.width) td.style.width = ref.style.width;
9587
+ if (ref?.style.minWidth) td.style.minWidth = ref.style.minWidth;
9579
9588
  newRow.appendChild(td);
9580
9589
  }
9581
9590
  if (position === "above") refRow.parentElement?.insertBefore(newRow, refRow);
9582
- else refRow.insertAdjacentElement("afterend", newRow);
9591
+ else refRow.after(newRow);
9583
9592
  requestAnimationFrame(() => this._positionNear(this._activeTable));
9584
9593
  this.context.invoke("editor.afterCommand");
9585
9594
  }
@@ -9684,8 +9693,15 @@ var TableTooltip = class {
9684
9693
  first.colSpan = maxC - minC + 1;
9685
9694
  first.rowSpan = maxR - minR + 1;
9686
9695
  first.style.verticalAlign = "middle";
9687
- first.innerHTML = rectCells.map((c) => c.innerHTML).join("");
9688
- rectCells.slice(1).forEach((c) => c.remove());
9696
+ first.style.height = "";
9697
+ first.style.minHeight = "";
9698
+ const parts = rectCells.map((c) => c.innerHTML.replace(/^(<br\s*\/?>|\s)+$/i, "").trim()).filter((h) => h !== "");
9699
+ first.innerHTML = parts.length ? parts.join("<br>") : "<br>";
9700
+ rectCells.slice(1).forEach((c) => {
9701
+ const row = c.parentElement;
9702
+ c.remove();
9703
+ if (row && row.cells.length === 0) row.remove();
9704
+ });
9689
9705
  this._clearSelection();
9690
9706
  this.context.invoke("editor.afterCommand");
9691
9707
  }
@@ -9737,12 +9753,9 @@ var TableTooltip = class {
9737
9753
  const targetRow = tableRows[r + dr];
9738
9754
  if (!targetRow) continue;
9739
9755
  let ref = null;
9740
- for (const tc of targetRow.cells) {
9741
- const tp = cellPos.get(tc);
9742
- if (tp && tp.c > c) {
9743
- ref = tc;
9744
- break;
9745
- }
9756
+ for (const tc of targetRow.cells) if (cellPos.get(tc)?.c > c) {
9757
+ ref = tc;
9758
+ break;
9746
9759
  }
9747
9760
  for (let dc = 0; dc < cs; dc++) targetRow.insertBefore(createElement(tag, {}, ["\xA0"]), ref);
9748
9761
  }
@@ -9837,7 +9850,11 @@ var TableTooltip = class {
9837
9850
  this._sizeTitleEl.textContent = isCol ? this.context.locale.tooltips.table.columnWidthPx : this.context.locale.tooltips.table.rowHeightPx;
9838
9851
  this._sizeInputEl.min = "1";
9839
9852
  this._sizeInputEl.max = "2000";
9840
- this._sizeInputEl.value = isCol ? cell.offsetWidth || 120 : cell.closest("tr") ? cell.closest("tr").offsetHeight || 40 : 40;
9853
+ if (isCol) this._sizeInputEl.value = cell.offsetWidth || 120;
9854
+ else {
9855
+ const refRow = cell.closest("tr");
9856
+ this._sizeInputEl.value = refRow ? refRow.offsetHeight || 40 : 40;
9857
+ }
9841
9858
  this._sizeApply = (val) => {
9842
9859
  const table = cell.closest("table");
9843
9860
  if (!table) return;
@@ -9925,8 +9942,7 @@ var TableTooltip = class {
9925
9942
  customRow.appendChild(colorInput);
9926
9943
  customRow.appendChild(customLabel);
9927
9944
  pop.appendChild(customRow);
9928
- this._disposers.push(on(pop, "mousedown", (e) => e.preventDefault()), on(pop, "mouseenter", () => this._clearTimers()), on(pop, "mouseleave", () => this._scheduleHide()));
9929
- this._disposers.push(on(document, "click", (e) => {
9945
+ this._disposers.push(on(pop, "mousedown", (e) => e.preventDefault()), on(pop, "mouseenter", () => this._clearTimers()), on(pop, "mouseleave", () => this._scheduleHide()), on(document, "click", (e) => {
9930
9946
  const et = e.target;
9931
9947
  if (this._shadePopover && this._shadePopover.style.display !== "none" && !this._shadePopover.contains(et) && !this._el?.contains(et)) this._hideCellShadePopover();
9932
9948
  }));
@@ -12800,7 +12816,7 @@ var EmojiDialog = class extends BaseDialog {
12800
12816
  const editable = this.context.layoutInfo.editable;
12801
12817
  if (savedRange) savedRange.select();
12802
12818
  const sel = globalThis.getSelection();
12803
- let range = sel && sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
12819
+ let range = sel?.rangeCount > 0 ? sel.getRangeAt(0) : null;
12804
12820
  if (!range) {
12805
12821
  range = document.createRange();
12806
12822
  range.selectNodeContents(editable);
@@ -13367,13 +13383,13 @@ var IconDialog = class extends BaseDialog {
13367
13383
  const _sc = range.startContainer;
13368
13384
  const _tdAnchor = (_sc.nodeType === 1 ? _sc : _sc.parentElement)?.closest("td, th");
13369
13385
  range.deleteContents();
13370
- if (_tdAnchor && _tdAnchor.isConnected && !_tdAnchor.contains(range.startContainer)) {
13386
+ if (_tdAnchor?.isConnected && !_tdAnchor.contains(range.startContainer)) {
13371
13387
  range.setStart(_tdAnchor, 0);
13372
13388
  range.collapse(true);
13373
13389
  }
13374
13390
  range.insertNode(iconEl);
13375
13391
  let caretTextNode = iconEl.nextSibling;
13376
- if (!caretTextNode || caretTextNode.nodeType !== Node.TEXT_NODE) {
13392
+ if (caretTextNode?.nodeType !== Node.TEXT_NODE) {
13377
13393
  caretTextNode = document.createTextNode("​");
13378
13394
  iconEl.parentNode.insertBefore(caretTextNode, iconEl.nextSibling);
13379
13395
  } else if (!caretTextNode.textContent) caretTextNode.textContent = "​";
@@ -13593,7 +13609,7 @@ var ContextMenu = class {
13593
13609
  constructor(context) {
13594
13610
  this.context = context;
13595
13611
  this.options = context.options || {};
13596
- this._items = this.options.contextMenu && this.options.contextMenu.items || defaultItems;
13612
+ this._items = this.options.contextMenu?.items || defaultItems;
13597
13613
  this.el = null;
13598
13614
  this._disposers = [];
13599
13615
  this._menuDisposers = [];
@@ -13613,11 +13629,9 @@ var ContextMenu = class {
13613
13629
  this._renderItems(this._items);
13614
13630
  const editable = this.context.layoutInfo?.editable;
13615
13631
  if (editable) this._disposers.push(on(editable, "contextmenu", (e) => this._onContextMenu(e)));
13616
- this._disposers.push(on(document, "click", (e) => this._maybeHide(e)));
13617
- this._disposers.push(on(document, "keydown", (e) => {
13632
+ this._disposers.push(on(document, "click", (e) => this._maybeHide(e)), on(document, "keydown", (e) => {
13618
13633
  if (e.key === "Escape") this.hide();
13619
- }));
13620
- this._disposers.push(on(globalThis, "scroll", () => this.hide(), { passive: true }));
13634
+ }), on(globalThis, "scroll", () => this.hide(), { passive: true }));
13621
13635
  return this;
13622
13636
  }
13623
13637
  destroy() {
@@ -13882,7 +13896,7 @@ var ContextMenu = class {
13882
13896
  if (this.context.layoutInfo.container.classList.contains("an-disabled")) return;
13883
13897
  event.preventDefault();
13884
13898
  const winSel = globalThis.getSelection();
13885
- this._savedRange = winSel && winSel.rangeCount > 0 ? winSel.getRangeAt(0).cloneRange() : null;
13899
+ this._savedRange = winSel?.rangeCount > 0 ? winSel.getRangeAt(0).cloneRange() : null;
13886
13900
  this._renderItems(this._items);
13887
13901
  const openX = event.clientX;
13888
13902
  let openY = event.clientY;
@@ -13907,8 +13921,8 @@ var ContextMenu = class {
13907
13921
  }
13908
13922
  _reposition(x, y) {
13909
13923
  if (!this.el) return;
13910
- const rx = x !== void 0 ? x : this._lastX;
13911
- const ry = y !== void 0 ? y : this._lastY;
13924
+ const rx = x === void 0 ? this._lastX : x;
13925
+ const ry = y === void 0 ? this._lastY : y;
13912
13926
  const w = this.el.offsetWidth;
13913
13927
  const h = this.el.offsetHeight;
13914
13928
  let left = rx;
@@ -13964,7 +13978,7 @@ var ContextMenu = class {
13964
13978
  const editable = this.context.layoutInfo?.editable;
13965
13979
  let node = range.startContainer;
13966
13980
  if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
13967
- if (!node || !editable || !editable.contains(node)) return;
13981
+ if (!node || !editable?.contains(node)) return;
13968
13982
  const cs = globalThis.getComputedStyle(node);
13969
13983
  const explicitFontFamily = this._findExplicitStyle(node, editable, "fontFamily");
13970
13984
  const explicitFontSize = this._findExplicitStyle(node, editable, "fontSize");
@@ -13983,7 +13997,7 @@ var ContextMenu = class {
13983
13997
  _findExplicitStyle(node, boundary, prop) {
13984
13998
  let el = node;
13985
13999
  while (el && el !== boundary && el !== document.body) {
13986
- if (el.style && el.style[prop]) return el.style[prop];
14000
+ if (el.style?.[prop]) return el.style[prop];
13987
14001
  if (el.nodeName === "FONT") {
13988
14002
  if (prop === "fontFamily" && el.getAttribute("face")) return el.getAttribute("face");
13989
14003
  if (prop === "fontSize" && el.getAttribute("size")) return null;
@@ -14432,7 +14446,7 @@ var FindReplace = class extends BaseDialog {
14432
14446
  this._matches = this._matches.filter((m) => m.mark);
14433
14447
  this._currentIndex = 0;
14434
14448
  if (this._matches.length === 0) return;
14435
- if (this._matches[0] && this._matches[0].mark) {
14449
+ if (this._matches[0]?.mark) {
14436
14450
  this._matches[0].mark.className = "an-highlight an-highlight-current";
14437
14451
  this._matches[0].mark.scrollIntoView({
14438
14452
  block: "center",
@@ -14450,7 +14464,7 @@ var FindReplace = class extends BaseDialog {
14450
14464
  const results = [];
14451
14465
  if (this._lastQuery !== query || this._lastCaseSensitive !== this._caseSensitive) {
14452
14466
  const flags = this._caseSensitive ? "g" : "gi";
14453
- const escaped = query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
14467
+ const escaped = query.replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
14454
14468
  this._queryRegex = new RegExp(escaped, flags);
14455
14469
  this._lastQuery = query;
14456
14470
  this._lastCaseSensitive = this._caseSensitive;
@@ -14488,7 +14502,7 @@ var FindReplace = class extends BaseDialog {
14488
14502
  }
14489
14503
  _scrollToMatch(index) {
14490
14504
  const match = this._matches[index];
14491
- if (!match || !match.mark) return;
14505
+ if (!match?.mark) return;
14492
14506
  this._matches.forEach((m, i) => {
14493
14507
  if (m.mark) m.mark.className = i === index ? "an-highlight an-highlight-current" : "an-highlight";
14494
14508
  });
@@ -14500,7 +14514,7 @@ var FindReplace = class extends BaseDialog {
14500
14514
  _replace() {
14501
14515
  if (this._matches.length === 0 || this._currentIndex < 0) return;
14502
14516
  const match = this._matches[this._currentIndex];
14503
- if (!match || !match.mark || !match.mark.parentNode) return;
14517
+ if (!match?.mark?.parentNode) return;
14504
14518
  const replacement = this._replaceInput ? this._replaceInput.value : "";
14505
14519
  const parent = match.mark.parentNode;
14506
14520
  const textNode = document.createTextNode(replacement);
@@ -14520,7 +14534,7 @@ var FindReplace = class extends BaseDialog {
14520
14534
  if (this._matches.length === 0) return;
14521
14535
  const replacement = this._replaceInput ? this._replaceInput.value : "";
14522
14536
  this._matches.forEach(({ mark }) => {
14523
- if (!mark || !mark.parentNode) return;
14537
+ if (!mark?.parentNode) return;
14524
14538
  const textNode = document.createTextNode(replacement);
14525
14539
  mark.parentNode.insertBefore(textNode, mark);
14526
14540
  mark.remove();
@@ -14896,7 +14910,7 @@ var ImageCropOverlay = class {
14896
14910
  const startY = e.clientY;
14897
14911
  const orig = { ...this._box };
14898
14912
  const r = this._imgRect;
14899
- const lockAR = this._arCheck && this._arCheck.checked;
14913
+ const lockAR = this._arCheck?.checked;
14900
14914
  const aspect = orig.w / (orig.h || 1);
14901
14915
  const onMove = (me) => {
14902
14916
  const dx = me.clientX - startX;
@@ -15722,14 +15736,14 @@ var BubbleToolbar = class {
15722
15736
  if (!this._btnCache) return;
15723
15737
  this._btnCache.forEach((btn) => {
15724
15738
  const activeFn = _ACTIVE[btn.dataset.name];
15725
- btn.classList.toggle("an-active", !!(activeFn && activeFn()));
15739
+ btn.classList.toggle("an-active", !!activeFn?.());
15726
15740
  });
15727
15741
  }
15728
15742
  /** Read the current selection's color and update the color-strip indicators. */
15729
15743
  _syncColorStrips() {
15730
15744
  if (!this._el) return;
15731
15745
  const sel = globalThis.getSelection();
15732
- if (!sel || !sel.rangeCount) return;
15746
+ if (!sel?.rangeCount) return;
15733
15747
  let node = sel.getRangeAt(0).startContainer;
15734
15748
  if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
15735
15749
  if (!node) return;
@@ -15957,13 +15971,13 @@ var Mention = class {
15957
15971
  }
15958
15972
  } catch (_) {}
15959
15973
  const sel = globalThis.getSelection();
15960
- if (!sel || !sel.rangeCount) return;
15974
+ if (!sel?.rangeCount) return;
15961
15975
  const rects = sel.getRangeAt(0).getClientRects();
15962
15976
  if (rects.length > 0) this._caretRect = rects[rects.length - 1];
15963
15977
  }
15964
15978
  _getQueryAtCursor() {
15965
15979
  const sel = globalThis.getSelection();
15966
- if (!sel || !sel.rangeCount) return null;
15980
+ if (!sel?.rangeCount) return null;
15967
15981
  const range = sel.getRangeAt(0);
15968
15982
  if (!range.collapsed) return null;
15969
15983
  const node = range.startContainer;
@@ -16081,12 +16095,12 @@ var Context = class {
16081
16095
  this.layoutInfo.editable = editable;
16082
16096
  this._registerModules();
16083
16097
  const toolbar = this._modules.get("toolbar");
16084
- if (toolbar && toolbar.el) {
16098
+ if (toolbar?.el) {
16085
16099
  container.insertBefore(toolbar.el, editable);
16086
16100
  this.layoutInfo.toolbar = toolbar.el;
16087
16101
  }
16088
16102
  const statusbar = this._modules.get("statusbar");
16089
- if (statusbar && statusbar.el) {
16103
+ if (statusbar?.el) {
16090
16104
  container.appendChild(statusbar.el);
16091
16105
  this.layoutInfo.statusbar = statusbar.el;
16092
16106
  }
@@ -16707,7 +16721,7 @@ var AutumnNote = {
16707
16721
  return this;
16708
16722
  },
16709
16723
  /** Library version */
16710
- version: "1.6.3"
16724
+ version: "1.6.6"
16711
16725
  };
16712
16726
  /**
16713
16727
  * @param {string|Element|NodeList|Element[]} selector