autumnnote 1.6.3 → 1.6.5

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.
@@ -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,7 +672,7 @@ 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;
675
+ const wasCollapsed = !sel?.rangeCount || sel.getRangeAt(0).collapsed;
676
676
  if (wasCollapsed && sel && sel.rangeCount > 0) {
677
677
  try {
678
678
  const range = sel.getRangeAt(0);
@@ -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
@@ -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);
@@ -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);
@@ -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";
@@ -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;
@@ -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,7 @@ 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
+ const label = typeof item === "object" ? def.name === "paragraphStyle" ? this.context.locale.toolbar.paragraphItems?.[item.value] || item.label : item.label : item;
6438
6438
  const isHeader = typeof item === "object" && !!item.disabled;
6439
6439
  const attrs = { value };
6440
6440
  if (isHeader) attrs.disabled = "";
@@ -6446,7 +6446,7 @@ var Toolbar = class {
6446
6446
  let _savedRange = null;
6447
6447
  const dMousedown = on(select, "mousedown", () => {
6448
6448
  const sel = globalThis.getSelection();
6449
- _savedRange = sel && sel.rangeCount ? sel.getRangeAt(0).cloneRange() : null;
6449
+ _savedRange = sel?.rangeCount ? sel.getRangeAt(0).cloneRange() : null;
6450
6450
  });
6451
6451
  const disposer = on(select, "change", (e) => {
6452
6452
  const value = e.target.value;
@@ -7321,7 +7321,7 @@ var BaseDialog = class {
7321
7321
  if (this._dialog) {
7322
7322
  this._dialog.style.display = "flex";
7323
7323
  this._removeTrap = trapFocus(this._dialog, () => this._close());
7324
- setTimeout(() => this._firstInput && this._firstInput.focus(), 50);
7324
+ setTimeout(() => this._firstInput?.focus(), 50);
7325
7325
  }
7326
7326
  }
7327
7327
  _close() {
@@ -7973,7 +7973,7 @@ var ImageResizer = class {
7973
7973
  const containerRect = offsetParent.getBoundingClientRect();
7974
7974
  const rect = this._activeImg.getBoundingClientRect();
7975
7975
  const p = this._lastOverlayPos;
7976
- if (p && p.l === rect.left && p.t === rect.top && p.w === rect.width && p.h === rect.height) return;
7976
+ if (p?.l === rect.left && p.t === rect.top && p.w === rect.width && p.h === rect.height) return;
7977
7977
  this._lastOverlayPos = {
7978
7978
  l: rect.left,
7979
7979
  t: rect.top,
@@ -9018,7 +9018,7 @@ function getCellAfterVisualCol(row, visualIdx) {
9018
9018
  vIdx += c.colSpan || 1;
9019
9019
  if (vIdx > visualIdx) {
9020
9020
  const next = c.nextElementSibling;
9021
- return next && next.tagName === "TD" || next && next.tagName === "TH" ? next : null;
9021
+ return next?.tagName === "TD" || next?.tagName === "TH" ? next : null;
9022
9022
  }
9023
9023
  }
9024
9024
  return null;
@@ -9308,9 +9308,9 @@ var TableTooltip = class {
9308
9308
  this._disposers = [];
9309
9309
  if (this._el && this._el.parentNode) this._el.remove();
9310
9310
  this._el = null;
9311
- if (this._sizePopover && this._sizePopover.parentNode) this._sizePopover.remove();
9311
+ if (this._sizePopover?.parentNode) this._sizePopover.remove();
9312
9312
  this._sizePopover = null;
9313
- if (this._shadePopover && this._shadePopover.parentNode) this._shadePopover.remove();
9313
+ if (this._shadePopover?.parentNode) this._shadePopover.remove();
9314
9314
  this._shadePopover = null;
9315
9315
  }
9316
9316
  _buildTooltip() {
@@ -9457,7 +9457,7 @@ var TableTooltip = class {
9457
9457
  }
9458
9458
  _getCell() {
9459
9459
  const sel = globalThis.getSelection();
9460
- if (sel && sel.rangeCount) {
9460
+ if (sel?.rangeCount) {
9461
9461
  let container = sel.getRangeAt(0).commonAncestorContainer;
9462
9462
  if (container.nodeType === 3) container = container.parentElement;
9463
9463
  const cellFromSel = container?.closest("td, th");
@@ -9494,7 +9494,7 @@ var TableTooltip = class {
9494
9494
  if (!startCell) return [];
9495
9495
  if (!endCell || startCell === endCell) return [startCell];
9496
9496
  const table = startCell.closest("table");
9497
- if (!table || !table.contains(endCell)) return [startCell];
9497
+ if (!table?.contains(endCell)) return [startCell];
9498
9498
  const { gridMap, cellPos } = buildGridMap(table);
9499
9499
  const sp = cellPos.get(startCell);
9500
9500
  const ep = cellPos.get(endCell);
@@ -9574,8 +9574,8 @@ var TableTooltip = class {
9574
9574
  for (let i = 0; i < colCount; i++) {
9575
9575
  const td = createElement("td", {}, ["\xA0"]);
9576
9576
  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;
9577
+ if (ref?.style.width) td.style.width = ref.style.width;
9578
+ if (ref?.style.minWidth) td.style.minWidth = ref.style.minWidth;
9579
9579
  newRow.appendChild(td);
9580
9580
  }
9581
9581
  if (position === "above") refRow.parentElement?.insertBefore(newRow, refRow);
@@ -13373,7 +13373,7 @@ var IconDialog = class extends BaseDialog {
13373
13373
  }
13374
13374
  range.insertNode(iconEl);
13375
13375
  let caretTextNode = iconEl.nextSibling;
13376
- if (!caretTextNode || caretTextNode.nodeType !== Node.TEXT_NODE) {
13376
+ if (caretTextNode?.nodeType !== Node.TEXT_NODE) {
13377
13377
  caretTextNode = document.createTextNode("​");
13378
13378
  iconEl.parentNode.insertBefore(caretTextNode, iconEl.nextSibling);
13379
13379
  } else if (!caretTextNode.textContent) caretTextNode.textContent = "​";
@@ -14896,7 +14896,7 @@ var ImageCropOverlay = class {
14896
14896
  const startY = e.clientY;
14897
14897
  const orig = { ...this._box };
14898
14898
  const r = this._imgRect;
14899
- const lockAR = this._arCheck && this._arCheck.checked;
14899
+ const lockAR = this._arCheck?.checked;
14900
14900
  const aspect = orig.w / (orig.h || 1);
14901
14901
  const onMove = (me) => {
14902
14902
  const dx = me.clientX - startX;
@@ -15722,14 +15722,14 @@ var BubbleToolbar = class {
15722
15722
  if (!this._btnCache) return;
15723
15723
  this._btnCache.forEach((btn) => {
15724
15724
  const activeFn = _ACTIVE[btn.dataset.name];
15725
- btn.classList.toggle("an-active", !!(activeFn && activeFn()));
15725
+ btn.classList.toggle("an-active", !!activeFn?.());
15726
15726
  });
15727
15727
  }
15728
15728
  /** Read the current selection's color and update the color-strip indicators. */
15729
15729
  _syncColorStrips() {
15730
15730
  if (!this._el) return;
15731
15731
  const sel = globalThis.getSelection();
15732
- if (!sel || !sel.rangeCount) return;
15732
+ if (!sel?.rangeCount) return;
15733
15733
  let node = sel.getRangeAt(0).startContainer;
15734
15734
  if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
15735
15735
  if (!node) return;
@@ -15957,7 +15957,7 @@ var Mention = class {
15957
15957
  }
15958
15958
  } catch (_) {}
15959
15959
  const sel = globalThis.getSelection();
15960
- if (!sel || !sel.rangeCount) return;
15960
+ if (!sel?.rangeCount) return;
15961
15961
  const rects = sel.getRangeAt(0).getClientRects();
15962
15962
  if (rects.length > 0) this._caretRect = rects[rects.length - 1];
15963
15963
  }
@@ -16707,7 +16707,7 @@ var AutumnNote = {
16707
16707
  return this;
16708
16708
  },
16709
16709
  /** Library version */
16710
- version: "1.6.3"
16710
+ version: "1.6.5"
16711
16711
  };
16712
16712
  /**
16713
16713
  * @param {string|Element|NodeList|Element[]} selector