@bytechain.cn/colamd 2.7.13-rc.1 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +5 -2
  2. package/README_CN.md +5 -2
  3. package/dist/lib/colamd-renderer.js +19817 -18358
  4. package/dist/lib/colamd.css +1 -1
  5. package/dist/renderer/assets/{2DXBBFLN-zwCk4Mxf.js → 2DXBBFLN-BcQoTXNK.js} +4 -4
  6. package/dist/renderer/assets/{46IJ22JX-CcgX9r7n.js → 46IJ22JX-Dvln4uUB.js} +5 -5
  7. package/dist/renderer/assets/{4TTDE5I4-DseEAfc2.js → 4TTDE5I4-LOG7xsNo.js} +3 -3
  8. package/dist/renderer/assets/{4UF3HTLV-B4wB5AKU.js → 4UF3HTLV-B5M4TbQl.js} +4 -4
  9. package/dist/renderer/assets/{AAXQQPKT-DWob5xGg.js → AAXQQPKT-S6Q6iTwj.js} +8 -8
  10. package/dist/renderer/assets/{AKE5O7KZ-vOSPM9bT.js → AKE5O7KZ-DgRxWRXD.js} +5 -5
  11. package/dist/renderer/assets/{BNMLP6AG-Cm5E3l75.js → BNMLP6AG-DSQgcgO4.js} +7 -7
  12. package/dist/renderer/assets/{DR6PKOQU-BY27B6Tm.js → DR6PKOQU-BSlXBi4M.js} +3 -3
  13. package/dist/renderer/assets/{E4RJ7UJB-B9Qt1DBg.js → E4RJ7UJB-AOICEUO8.js} +6 -6
  14. package/dist/renderer/assets/{ELSXBIJH-Dd46ncmF.js → ELSXBIJH-6yzOt2yu.js} +1 -1
  15. package/dist/renderer/assets/{ERTIBQVS-Ctuly7ru.js → ERTIBQVS-Bwlpwnl5.js} +4 -4
  16. package/dist/renderer/assets/{F653G4FO-BAG78YUI.js → F653G4FO-Bv18U9we.js} +8 -8
  17. package/dist/renderer/assets/{FKCDD66M-BYnIt2s5.js → FKCDD66M-BACYwspg.js} +1 -1
  18. package/dist/renderer/assets/{FP7KDXVC-1kxF0Go3.js → FP7KDXVC-CzGjSBpi.js} +6 -6
  19. package/dist/renderer/assets/{FT5I3RHX-DBz5zOl-.js → FT5I3RHX-S570rXpT.js} +7 -7
  20. package/dist/renderer/assets/{GY35JXOZ-FFtwzQYZ.js → GY35JXOZ-cSQ3vgtQ.js} +4 -4
  21. package/dist/renderer/assets/{H5EEJPP2-CzwQt4p_.js → H5EEJPP2-B5mRihtC.js} +9 -9
  22. package/dist/renderer/assets/{HWDLEDTA-BoEElC3j.js → HWDLEDTA-QxGhC7BD.js} +1 -1
  23. package/dist/renderer/assets/{JZWSX6AR-BJkYh7st.js → JZWSX6AR-D5J8dvEc.js} +2 -2
  24. package/dist/renderer/assets/{KQOEJWJY-B_gT6pV7.js → KQOEJWJY-B1H_7gPD.js} +1 -1
  25. package/dist/renderer/assets/{KS3BB3KE-Bp4Ml3CE.js → KS3BB3KE-DLlGsWQC.js} +5 -5
  26. package/dist/renderer/assets/{KXJRRZHI-Cpc8aBTp.js → KXJRRZHI-rxZ-n8Go.js} +3 -3
  27. package/dist/renderer/assets/{MFVI5XKI-tGMP0W95.js → MFVI5XKI-CQp2wV67.js} +1 -1
  28. package/dist/renderer/assets/{MWY2J62P-Dp5JIcym.js → MWY2J62P-CdKsEllR.js} +5 -5
  29. package/dist/renderer/assets/{MXGNCBL2-_tOBtwJ3.js → MXGNCBL2-CpHADYfy.js} +5 -5
  30. package/dist/renderer/assets/{N6DAJLIZ-B0Ni9aJP.js → N6DAJLIZ-z4bfft0m.js} +2 -2
  31. package/dist/renderer/assets/{NU5M23IW-Dq9-m-cn.js → NU5M23IW-BdEspGlf.js} +5 -5
  32. package/dist/renderer/assets/{NV4XNBIS-DrbQOkvO.js → NV4XNBIS-DwWAiQZN.js} +7 -7
  33. package/dist/renderer/assets/{OGLU4SIR-Dk2ltttF.js → OGLU4SIR-B4O60CC1.js} +5 -5
  34. package/dist/renderer/assets/{OUNS5N76-xZZw3I4z.js → OUNS5N76-DRQSAFpx.js} +6 -6
  35. package/dist/renderer/assets/{PU4ISKXV-C2MIDpGs.js → PU4ISKXV-CH7B9Xam.js} +5 -5
  36. package/dist/renderer/assets/{PUZGS23X-DFCoUCN_.js → PUZGS23X-Czec-t51.js} +1 -1
  37. package/dist/renderer/assets/{Q3IYVLG5-D3j0WKcV.js → Q3IYVLG5-ppP144xP.js} +5 -5
  38. package/dist/renderer/assets/{QYHQDLKZ-B0CE5fTR.js → QYHQDLKZ-BqPSAS2H.js} +9 -9
  39. package/dist/renderer/assets/{RZSVICHU-BSj4YQaY.js → RZSVICHU-_ZqNTL97.js} +1 -1
  40. package/dist/renderer/assets/{UEXXS2NB-CsxAjwQ4.js → UEXXS2NB-rgOpII99.js} +1 -1
  41. package/dist/renderer/assets/{UHTQJXKL-g4xFs4o0.js → UHTQJXKL-AI90fkq9.js} +5 -5
  42. package/dist/renderer/assets/{URA2L2QI-CaQCavyx.js → URA2L2QI-BDDmGORh.js} +1 -1
  43. package/dist/renderer/assets/{UXCHDUKG-SdHIAded.js → UXCHDUKG-DcMu-Kjz.js} +5 -5
  44. package/dist/renderer/assets/{VKNV3BUX-CAufMpR3.js → VKNV3BUX-BoFccAWM.js} +6 -6
  45. package/dist/renderer/assets/{VMV7XPHP-BTz-DDJE.js → VMV7XPHP-B4mGwDDN.js} +1 -1
  46. package/dist/renderer/assets/{WEVWDWVA-BTzIOcFk.js → WEVWDWVA-BM5eqE-B.js} +1 -1
  47. package/dist/renderer/assets/{XRRJ35LF-CqWXQoQc.js → XRRJ35LF-Cb6fWs_U.js} +4 -4
  48. package/dist/renderer/assets/{YFKBLVVN-CobClKiQ.js → YFKBLVVN-DJPx2596.js} +4 -4
  49. package/dist/renderer/assets/{YHRE5QGZ-DJVf9-VA.js → YHRE5QGZ-DA0Ne8ZS.js} +7 -7
  50. package/dist/renderer/assets/{ZF3OVT4B-4h2uC2Nf.js → ZF3OVT4B-CC3b1pZi.js} +3 -3
  51. package/dist/renderer/assets/{index-DsYLJ8It.js → index--lwcDMTj.js} +3 -3
  52. package/dist/renderer/assets/{index-CBD7Wlx8.js → index-5TWFI5jV.js} +1 -1
  53. package/dist/renderer/assets/{index-_-G3H01P.js → index-B-Tvkk_D.js} +1 -1
  54. package/dist/renderer/assets/{index-lPCBuTEj.js → index-B66yNs8z.js} +1 -1
  55. package/dist/renderer/assets/{index-D9fcCIeQ.js → index-BUO7yV_Q.js} +1 -1
  56. package/dist/renderer/assets/{index-DAwDMFVz.js → index-BjG9rVTb.js} +2345 -493
  57. package/dist/renderer/assets/{index-DgC9JAzE.js → index-CFKk8_-a.js} +3 -3
  58. package/dist/renderer/assets/{index-D6i0AdBR.js → index-CJQRWrTj.js} +1 -1
  59. package/dist/renderer/assets/{index-BZK9uVRR.js → index-CTBBXEX2.js} +1 -1
  60. package/dist/renderer/assets/{index-Gr-12Gzq.js → index-CcwQz0gI.js} +1 -1
  61. package/dist/renderer/assets/{index-BHqRO3CW.js → index-CipBATEm.js} +1 -1
  62. package/dist/renderer/assets/{index-De7RE4Mo.js → index-Co-0vhM1.js} +1 -1
  63. package/dist/renderer/assets/{index-BqpGj9MR.js → index-Cyi8NXI_.js} +1 -1
  64. package/dist/renderer/assets/{index-B6uVUc9e.js → index-D0d2vg7k.js} +3 -3
  65. package/dist/renderer/assets/{index-DkTSflhI.js → index-D4NskBFS.js} +1 -1
  66. package/dist/renderer/assets/{index-3SmJ-5Dc.js → index-DEjGaOKF.js} +1 -1
  67. package/dist/renderer/assets/{index-1hwQGecd.js → index-DI9_AaWi.js} +1 -1
  68. package/dist/renderer/assets/{index-BwFsNvvN.css → index-DM3GNRiR.css} +1158 -29
  69. package/dist/renderer/assets/{index-qlWwPzMe.js → index-Ditiw7Uj.js} +1 -1
  70. package/dist/renderer/assets/{index-CpAWIQHT.js → index-DypVmFXi.js} +1 -1
  71. package/dist/renderer/assets/{index-B0zpPg3h.js → index-pHq11714.js} +1 -1
  72. package/dist/renderer/assets/{index-OOnbRmFx.js → index-rA_KpISM.js} +1 -1
  73. package/dist/renderer/assets/{lazy-DReExUTA.js → lazy-C1NE8LhM.js} +3 -3
  74. package/dist/renderer/assets/{web-h4mYLq72.js → web-Bct4Qz8N.js} +1 -1
  75. package/dist/renderer/assets/{web-DErzcmb7.js → web-CI4szGaS.js} +2 -2
  76. package/dist/renderer/assets/{web-DocK2vhG.js → web-Db6-iOH9.js} +1 -1
  77. package/dist/renderer/index.html +3 -3
  78. package/package.json +11 -2
  79. package/themes/contract.json +3 -1
@@ -2957,10 +2957,10 @@ class RangeSet {
2957
2957
  for (; ; ) {
2958
2958
  let curTo = Math.min(cursor.to, to);
2959
2959
  if (cursor.point) {
2960
- let active = cursor.activeForPoint(cursor.to);
2961
- let openCount = cursor.pointFrom < from ? active.length + 1 : cursor.point.startSide < 0 ? active.length : Math.min(active.length, openRanges);
2962
- iterator.point(pos, curTo, cursor.point, active, openCount, cursor.pointRank);
2963
- openRanges = Math.min(cursor.openEnd(curTo), active.length);
2960
+ let active2 = cursor.activeForPoint(cursor.to);
2961
+ let openCount = cursor.pointFrom < from ? active2.length + 1 : cursor.point.startSide < 0 ? active2.length : Math.min(active2.length, openRanges);
2962
+ iterator.point(pos, curTo, cursor.point, active2, openCount, cursor.pointRank);
2963
+ openRanges = Math.min(cursor.openEnd(curTo), active2.length);
2964
2964
  } else if (curTo > pos) {
2965
2965
  iterator.span(pos, curTo, cursor.active, openRanges);
2966
2966
  openRanges = cursor.openEnd(curTo);
@@ -3374,14 +3374,14 @@ class SpanCursor {
3374
3374
  activeForPoint(to) {
3375
3375
  if (!this.active.length)
3376
3376
  return this.active;
3377
- let active = [];
3377
+ let active2 = [];
3378
3378
  for (let i = this.active.length - 1; i >= 0; i--) {
3379
3379
  if (this.activeRank[i] < this.pointRank)
3380
3380
  break;
3381
3381
  if (this.activeTo[i] > to || this.activeTo[i] == to && this.active[i].endSide >= this.point.endSide)
3382
- active.push(this.active[i]);
3382
+ active2.push(this.active[i]);
3383
3383
  }
3384
- return active.reverse();
3384
+ return active2.reverse();
3385
3385
  }
3386
3386
  openEnd(to) {
3387
3387
  let open2 = 0;
@@ -3710,7 +3710,7 @@ const ie_upto10 = /* @__PURE__ */ /MSIE \d/.test(nav.userAgent);
3710
3710
  const ie_11up = /* @__PURE__ */ /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(nav.userAgent);
3711
3711
  const ie = !!(ie_upto10 || ie_11up || ie_edge);
3712
3712
  const gecko = !ie && /* @__PURE__ */ /gecko\/(\d+)/i.test(nav.userAgent);
3713
- const chrome = !ie && /* @__PURE__ */ /Chrome\/(\d+)/.exec(nav.userAgent);
3713
+ const chrome$1 = !ie && /* @__PURE__ */ /Chrome\/(\d+)/.exec(nav.userAgent);
3714
3714
  const webkit = "webkitFontSmoothing" in doc.documentElement.style;
3715
3715
  const safari = !ie && /* @__PURE__ */ /Apple Computer/.test(nav.vendor);
3716
3716
  const ios = safari && (/* @__PURE__ */ /Mobile\/\w+/.test(nav.userAgent) || nav.maxTouchPoints > 2);
@@ -3722,8 +3722,8 @@ var browser = {
3722
3722
  ie_version: ie_upto10 ? doc.documentMode || 6 : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0,
3723
3723
  gecko,
3724
3724
  gecko_version: gecko ? +(/* @__PURE__ */ /Firefox\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,
3725
- chrome: !!chrome,
3726
- chrome_version: chrome ? +chrome[1] : 0,
3725
+ chrome: !!chrome$1,
3726
+ chrome_version: chrome$1 ? +chrome$1[1] : 0,
3727
3727
  ios,
3728
3728
  android: /* @__PURE__ */ /Android\b/.test(nav.userAgent),
3729
3729
  webkit,
@@ -4991,11 +4991,11 @@ function getIsolatedRanges(view, line) {
4991
4991
  RangeSet.spans(sets, line.from, line.to, {
4992
4992
  point() {
4993
4993
  },
4994
- span(fromDoc, toDoc, active, open2) {
4994
+ span(fromDoc, toDoc, active2, open2) {
4995
4995
  let from = fromDoc - line.from, to = toDoc - line.from;
4996
4996
  let level = result;
4997
- for (let i = active.length - 1; i >= 0; i--, open2--) {
4998
- let direction = active[i].spec.bidiIsolate, update;
4997
+ for (let i = active2.length - 1; i >= 0; i--, open2--) {
4998
+ let direction = active2[i].spec.bidiIsolate, update;
4999
4999
  if (direction == null)
5000
5000
  direction = autoDirection(line.text, from, to);
5001
5001
  if (open2 > 0 && level.length && (update = level[level.length - 1]).to == from && update.direction == direction) {
@@ -6225,7 +6225,7 @@ class TileUpdate {
6225
6225
  let pendingLineAttrs = null;
6226
6226
  let b = this.builder, markCount = -1;
6227
6227
  let openEnd = RangeSet.spans(this.decorations, from, to, {
6228
- point: (from2, to2, deco, active, openStart, index2) => {
6228
+ point: (from2, to2, deco, active2, openStart, index2) => {
6229
6229
  if (deco instanceof PointDecoration) {
6230
6230
  if (this.disallowBlockEffectsFor[index2]) {
6231
6231
  if (deco.block)
@@ -6233,8 +6233,8 @@ class TileUpdate {
6233
6233
  if (to2 > this.view.state.doc.lineAt(from2).to)
6234
6234
  throw new RangeError("Decorations that replace line breaks may not be specified via plugins");
6235
6235
  }
6236
- markCount = active.length;
6237
- if (openStart > active.length) {
6236
+ markCount = active2.length;
6237
+ if (openStart > active2.length) {
6238
6238
  b.continueWidget(to2 - from2);
6239
6239
  } else {
6240
6240
  let widget = deco.widget || (deco.block ? NullWidget.block : NullWidget.inline);
@@ -6246,7 +6246,7 @@ class TileUpdate {
6246
6246
  b.addBlockWidget(tile);
6247
6247
  } else {
6248
6248
  b.ensureLine(pendingLineAttrs);
6249
- b.addInlineWidget(tile, active, openStart);
6249
+ b.addInlineWidget(tile, active2, openStart);
6250
6250
  }
6251
6251
  }
6252
6252
  pendingLineAttrs = null;
@@ -6256,7 +6256,7 @@ class TileUpdate {
6256
6256
  if (to2 > from2)
6257
6257
  this.text.skip(to2 - from2);
6258
6258
  },
6259
- span: (from2, to2, active, openStart) => {
6259
+ span: (from2, to2, active2, openStart) => {
6260
6260
  for (let pos = from2; pos < to2; ) {
6261
6261
  let chars = this.text.next(Math.min(512, to2 - pos));
6262
6262
  if (chars == null) {
@@ -6265,12 +6265,12 @@ class TileUpdate {
6265
6265
  pos++;
6266
6266
  } else {
6267
6267
  b.ensureLine(pendingLineAttrs);
6268
- b.addText(chars, active, pos == from2 ? openStart : active.length);
6268
+ b.addText(chars, active2, pos == from2 ? openStart : active2.length);
6269
6269
  pos += chars.length;
6270
6270
  }
6271
6271
  pendingLineAttrs = null;
6272
6272
  }
6273
- markCount = active.length;
6273
+ markCount = active2.length;
6274
6274
  }
6275
6275
  });
6276
6276
  if (markCount > -1)
@@ -8258,9 +8258,9 @@ handlers.mousedown = (view, event) => {
8258
8258
  if (mustFocus)
8259
8259
  view.observer.ignore(() => {
8260
8260
  focusPreventScroll(view.contentDOM);
8261
- let active = view.root.activeElement;
8262
- if (active && !active.contains(view.contentDOM))
8263
- active.blur();
8261
+ let active2 = view.root.activeElement;
8262
+ if (active2 && !active2.contains(view.contentDOM))
8263
+ active2.blur();
8264
8264
  });
8265
8265
  let mouseSel = view.inputState.mouseSelection;
8266
8266
  if (mouseSel) {
@@ -32845,6 +32845,337 @@ function frontmatterRange(text2) {
32845
32845
  if (!MAPPING_ENTRY.test(body)) return null;
32846
32846
  return { from: 0, to: firstLineEnd + 1 + match.index + match[0].length };
32847
32847
  }
32848
+ const QUOTE_PREFIX_RE = /^(?:[ \t]*>[ \t]?)+/;
32849
+ const LIST_BODY_RE = /^([ \t]*)(?:([-*+])|(\d{1,9})([.)]))( +)(\[[ xX]\] +)?/;
32850
+ const ORDERED_INDENT = 4;
32851
+ const BULLET_INDENT = 2;
32852
+ const MAX_BLOCK_LINES = 5e3;
32853
+ function adjustLeadEdit(leadRaw, deltaCols) {
32854
+ if (deltaCols === 0) return { removeChars: 0, replaceWith: "" };
32855
+ if (deltaCols > 0) {
32856
+ if (!leadRaw.includes(" ")) {
32857
+ return { removeChars: 0, replaceWith: " ".repeat(deltaCols) };
32858
+ }
32859
+ const targetCols2 = expandIndent(leadRaw) + deltaCols;
32860
+ return { removeChars: leadRaw.length, replaceWith: " ".repeat(targetCols2) };
32861
+ }
32862
+ if (leadRaw.length === 0) return { removeChars: 0, replaceWith: "" };
32863
+ const totalCols = expandIndent(leadRaw);
32864
+ const targetCols = Math.max(0, totalCols + deltaCols);
32865
+ if (targetCols === 0) {
32866
+ return { removeChars: leadRaw.length, replaceWith: "" };
32867
+ }
32868
+ if (!leadRaw.includes(" ")) {
32869
+ return { removeChars: Math.min(leadRaw.length, -deltaCols), replaceWith: "" };
32870
+ }
32871
+ if (/^\t+$/.test(leadRaw) && targetCols % 4 === 0) {
32872
+ const keepTabs = targetCols / 4;
32873
+ return { removeChars: leadRaw.length - keepTabs, replaceWith: "" };
32874
+ }
32875
+ return { removeChars: leadRaw.length, replaceWith: " ".repeat(targetCols) };
32876
+ }
32877
+ function countQuotes(prefix) {
32878
+ let count2 = 0;
32879
+ for (let i = 0; i < prefix.length; i++) {
32880
+ if (prefix[i] === ">") count2++;
32881
+ }
32882
+ return count2;
32883
+ }
32884
+ function expandIndent(raw, startCol = 0) {
32885
+ let cols = startCol;
32886
+ for (let i = 0; i < raw.length; i++) {
32887
+ if (raw[i] === " ") cols += 4 - cols % 4;
32888
+ else cols += 1;
32889
+ }
32890
+ return cols - startCol;
32891
+ }
32892
+ function parseListLine(text2) {
32893
+ const quotePrefix = QUOTE_PREFIX_RE.exec(text2)?.[0] ?? "";
32894
+ const quoteLen = quotePrefix.length;
32895
+ const match = LIST_BODY_RE.exec(text2.slice(quoteLen));
32896
+ if (!match) return null;
32897
+ const leadRaw = match[1];
32898
+ const leadChars = leadRaw.length;
32899
+ const lead = expandIndent(leadRaw);
32900
+ const bullet = match[2] ?? "";
32901
+ const digits = match[3] ?? "";
32902
+ const delim = match[4] ?? "";
32903
+ const spaces2 = match[5];
32904
+ const box = match[6] ?? "";
32905
+ const kind = digits ? "ordered" : "bullet";
32906
+ const markerStart = quoteLen + leadChars;
32907
+ const markerLen = kind === "ordered" ? digits.length + delim.length : bullet.length;
32908
+ const markerEnd = markerStart + markerLen;
32909
+ const spaceEnd = markerEnd + spaces2.length;
32910
+ const contentOffset = spaceEnd + box.length;
32911
+ const markerWidth = markerLen + expandIndent(spaces2, lead + markerLen);
32912
+ const isEmpty = text2.slice(contentOffset).trim() === "";
32913
+ return {
32914
+ quotePrefix,
32915
+ quoteLen,
32916
+ quoteDepth: countQuotes(quotePrefix),
32917
+ leadChars,
32918
+ lead,
32919
+ kind,
32920
+ digits,
32921
+ delim,
32922
+ bullet,
32923
+ markerStart,
32924
+ markerEnd,
32925
+ spaceEnd,
32926
+ markerWidth,
32927
+ box,
32928
+ contentOffset,
32929
+ isEmpty
32930
+ };
32931
+ }
32932
+ const frontmatterEndCache = /* @__PURE__ */ new WeakMap();
32933
+ function frontmatterEnd(doc2) {
32934
+ const cached = frontmatterEndCache.get(doc2);
32935
+ if (cached !== void 0) return cached;
32936
+ let result = -1;
32937
+ if (doc2.lines >= 2 && doc2.line(1).text.trimEnd() === "---") {
32938
+ const cap = Math.min(doc2.length, 32768);
32939
+ const range = frontmatterRange(doc2.sliceString(0, cap));
32940
+ result = range ? range.to : -1;
32941
+ }
32942
+ frontmatterEndCache.set(doc2, result);
32943
+ return result;
32944
+ }
32945
+ function isActiveOrderedListLine(doc2, tree, lineNumber, fmEnd) {
32946
+ if (isExcludedLine(doc2, tree, lineNumber, fmEnd)) return null;
32947
+ const line = doc2.line(lineNumber);
32948
+ const parsed = parseListLine(line.text);
32949
+ if (!parsed || parsed.kind !== "ordered") return null;
32950
+ const markFrom = line.from + parsed.markerStart;
32951
+ const inner2 = tree.resolveInner(Math.min(markFrom, tree.length), 1);
32952
+ if (inner2.name === "ListMark") return parsed;
32953
+ if (parsed.isEmpty && !parsed.box && inner2.name === "Paragraph") return parsed;
32954
+ return null;
32955
+ }
32956
+ const EXCLUDED_NODES$1 = /* @__PURE__ */ new Set(["FencedCode", "HTMLBlock", "Table", "CommentBlock"]);
32957
+ function isExcludedLine(doc2, tree, lineNumber, fmEnd) {
32958
+ const line = doc2.line(lineNumber);
32959
+ const endOfFm = fmEnd ?? frontmatterEnd(doc2);
32960
+ if (endOfFm >= 0 && line.from <= endOfFm) return true;
32961
+ if (!tree) return false;
32962
+ const probe = Math.min(line.to, line.from + (QUOTE_PREFIX_RE.exec(line.text)?.[0].length ?? 0));
32963
+ let node = tree.resolveInner(Math.min(probe, tree.length), 1);
32964
+ while (node) {
32965
+ if (EXCLUDED_NODES$1.has(node.name)) return true;
32966
+ node = node.parent;
32967
+ }
32968
+ return false;
32969
+ }
32970
+ function isBlankAfterQuote(text2) {
32971
+ return text2.replace(QUOTE_PREFIX_RE, "").trim() === "";
32972
+ }
32973
+ function scanListBlock(doc2, anchorLine, tree, fmEnd, excludedFn) {
32974
+ if (anchorLine < 1 || anchorLine > doc2.lines) return null;
32975
+ const endOfFm = fmEnd ?? frontmatterEnd(doc2);
32976
+ const checkExcluded = excludedFn ?? ((n) => isExcludedLine(doc2, tree, n, endOfFm));
32977
+ if (checkExcluded(anchorLine)) return null;
32978
+ const anchor = doc2.line(anchorLine);
32979
+ const anchorQuotePrefix = QUOTE_PREFIX_RE.exec(anchor.text)?.[0] ?? "";
32980
+ const quoteDepth = countQuotes(anchorQuotePrefix);
32981
+ if (isBlankAfterQuote(anchor.text)) return null;
32982
+ const parsedCache = /* @__PURE__ */ new Map();
32983
+ const excludedCache = /* @__PURE__ */ new Map();
32984
+ const getExcluded = (n) => {
32985
+ let hit = excludedCache.get(n);
32986
+ if (hit === void 0) {
32987
+ hit = checkExcluded(n);
32988
+ excludedCache.set(n, hit);
32989
+ }
32990
+ return hit;
32991
+ };
32992
+ const getParsed = (n, text2) => {
32993
+ let hit = parsedCache.get(n);
32994
+ if (hit === void 0) {
32995
+ hit = parseListLine(text2);
32996
+ parsedCache.set(n, hit);
32997
+ }
32998
+ return hit;
32999
+ };
33000
+ const belongsToCluster = (n) => {
33001
+ if (n < 1 || n > doc2.lines) return "stop";
33002
+ const text2 = doc2.line(n).text;
33003
+ const qp = QUOTE_PREFIX_RE.exec(text2)?.[0] ?? "";
33004
+ if (countQuotes(qp) !== quoteDepth) return "stop";
33005
+ const rest = text2.slice(qp.length);
33006
+ if (rest.trim() === "") return "stop";
33007
+ if (getExcluded(n)) {
33008
+ return /^[ \t]/.test(rest) ? "indented" : "stop";
33009
+ }
33010
+ if (getParsed(n, text2)) return "list";
33011
+ if (/^[ \t]/.test(rest)) return "indented";
33012
+ return "stop";
33013
+ };
33014
+ const anchorKind = belongsToCluster(anchorLine);
33015
+ if (anchorKind === "stop") return null;
33016
+ let start = anchorLine;
33017
+ let seenListAbove = anchorKind === "list";
33018
+ let topListLine = anchorKind === "list" ? anchorLine : -1;
33019
+ for (let n = anchorLine - 1; n >= Math.max(1, anchorLine - MAX_BLOCK_LINES); n--) {
33020
+ const k = belongsToCluster(n);
33021
+ if (k === "stop") break;
33022
+ start = n;
33023
+ if (k === "list") {
33024
+ seenListAbove = true;
33025
+ topListLine = n;
33026
+ }
33027
+ }
33028
+ if (!seenListAbove) return null;
33029
+ if (topListLine > start) start = topListLine;
33030
+ let end = anchorLine;
33031
+ for (let n = anchorLine + 1; n <= Math.min(doc2.lines, start + MAX_BLOCK_LINES); n++) {
33032
+ const k = belongsToCluster(n);
33033
+ if (k === "stop") break;
33034
+ end = n;
33035
+ }
33036
+ return buildListBlock(doc2, start, end, quoteDepth, getExcluded, getParsed);
33037
+ }
33038
+ const FENCE_OPEN_RE = /^[ \t]*(`{3,}|~{3,})/;
33039
+ function buildListBlock(doc2, startLine, endLine, quoteDepth, getExcluded, getParsed) {
33040
+ const items = [];
33041
+ const itemIndexByLine = /* @__PURE__ */ new Map();
33042
+ const orderedGroups = [];
33043
+ const orderedGroupMap = /* @__PURE__ */ new Map();
33044
+ const stack = [];
33045
+ const lastSiblingByParent = /* @__PURE__ */ new Map();
33046
+ let nextGroupId = 1;
33047
+ let activeFence = null;
33048
+ for (let n = startLine; n <= endLine; n++) {
33049
+ const line = doc2.line(n);
33050
+ const qpLen = QUOTE_PREFIX_RE.exec(line.text)?.[0].length ?? 0;
33051
+ const body = line.text.slice(qpLen);
33052
+ if (activeFence) {
33053
+ const trimmed = body.trim();
33054
+ if (trimmed.length >= activeFence.len && trimmed[0] === activeFence.ch && /^[`~]+$/.test(trimmed) && trimmed.split("").every((c) => c === activeFence.ch)) {
33055
+ activeFence = null;
33056
+ }
33057
+ continue;
33058
+ }
33059
+ const fenceMatch = FENCE_OPEN_RE.exec(body);
33060
+ if (fenceMatch) {
33061
+ const marker = fenceMatch[1];
33062
+ const afterMarker = body.slice(fenceMatch[0].length);
33063
+ if (marker[0] !== "`" || !afterMarker.includes("`")) {
33064
+ activeFence = { ch: marker[0], len: marker.length };
33065
+ continue;
33066
+ }
33067
+ }
33068
+ if (getExcluded(n)) continue;
33069
+ const parsed = getParsed(n, line.text);
33070
+ if (!parsed) continue;
33071
+ while (stack.length > 0) {
33072
+ const top2 = stack[stack.length - 1].item;
33073
+ if (parsed.lead >= top2.parsed.lead + 2) break;
33074
+ stack.pop();
33075
+ }
33076
+ const parent = stack.length > 0 ? stack[stack.length - 1].item : null;
33077
+ const parentLine = parent ? parent.lineNumber : null;
33078
+ const depth = stack.length;
33079
+ const prevSib = lastSiblingByParent.get(parentLine);
33080
+ let groupId;
33081
+ if (prevSib && prevSib.parsed.kind === parsed.kind && prevSib.parsed.delim === parsed.delim && // 同一同级组缩进必须相容(允许 1 列容错,绝不把失去父项的 4 空格孤立子项和下方 0 空格项并组)
33082
+ Math.abs(prevSib.parsed.lead - parsed.lead) <= 1) {
33083
+ groupId = prevSib.groupId;
33084
+ } else {
33085
+ groupId = nextGroupId++;
33086
+ }
33087
+ const item = {
33088
+ lineNumber: n,
33089
+ lineFrom: line.from,
33090
+ lineTo: line.to,
33091
+ parsed,
33092
+ depth,
33093
+ parentLine,
33094
+ groupId,
33095
+ subtreeEndLine: n
33096
+ };
33097
+ itemIndexByLine.set(n, items.length);
33098
+ items.push(item);
33099
+ lastSiblingByParent.set(parentLine, item);
33100
+ for (const [key] of lastSiblingByParent) {
33101
+ if (key !== null && key !== parentLine) {
33102
+ const keyIdx = itemIndexByLine.get(key);
33103
+ const keyItem = keyIdx !== void 0 ? items[keyIdx] : void 0;
33104
+ if (keyItem && keyItem.depth >= depth) lastSiblingByParent.delete(key);
33105
+ }
33106
+ }
33107
+ if (parsed.kind === "ordered") {
33108
+ let group = orderedGroupMap.get(groupId);
33109
+ if (!group) {
33110
+ group = {
33111
+ id: groupId,
33112
+ parentLine,
33113
+ depth,
33114
+ delim: parsed.delim,
33115
+ items: []
33116
+ };
33117
+ orderedGroupMap.set(groupId, group);
33118
+ orderedGroups.push(group);
33119
+ }
33120
+ group.items.push(item);
33121
+ }
33122
+ stack.push({ item });
33123
+ }
33124
+ if (items.length === 0) return null;
33125
+ const endStack = [];
33126
+ for (let i = 0; i < items.length; i++) {
33127
+ const cur = items[i];
33128
+ while (endStack.length > 0 && endStack[endStack.length - 1].depth >= cur.depth) {
33129
+ const closed = endStack.pop();
33130
+ closed.subtreeEndLine = Math.max(closed.lineNumber, cur.lineNumber - 1);
33131
+ }
33132
+ endStack.push(cur);
33133
+ }
33134
+ while (endStack.length > 0) {
33135
+ const closed = endStack.pop();
33136
+ closed.subtreeEndLine = Math.max(closed.lineNumber, endLine);
33137
+ }
33138
+ return { startLine, endLine, quoteDepth, items, orderedGroups, itemIndexByLine };
33139
+ }
33140
+ function findPrevSibling(block, lineNumber) {
33141
+ const idx = block.itemIndexByLine.get(lineNumber);
33142
+ if (idx === void 0 || idx <= 0) return null;
33143
+ const self2 = block.items[idx];
33144
+ for (let i = idx - 1; i >= 0; i--) {
33145
+ const prev = block.items[i];
33146
+ if (prev.depth < self2.depth) return null;
33147
+ if (prev.depth === self2.depth && prev.parentLine === self2.parentLine) {
33148
+ return prev.groupId === self2.groupId ? prev : null;
33149
+ }
33150
+ }
33151
+ return null;
33152
+ }
33153
+ function findFirstDirectChild(block, lineNumber) {
33154
+ const idx = block.itemIndexByLine.get(lineNumber);
33155
+ if (idx === void 0 || idx + 1 >= block.items.length) return null;
33156
+ const self2 = block.items[idx];
33157
+ const next = block.items[idx + 1];
33158
+ return next.parentLine === self2.lineNumber ? next : null;
33159
+ }
33160
+ function findIndentParent(block, lineNumber, maxLead) {
33161
+ const idx = block.itemIndexByLine.get(lineNumber);
33162
+ if (idx === void 0 || idx <= 0) return null;
33163
+ for (let i = idx - 1; i >= 0; i--) {
33164
+ const prev = block.items[i];
33165
+ if (prev.parsed.lead <= maxLead) return prev;
33166
+ }
33167
+ return null;
33168
+ }
33169
+ function findOutdentTarget(block, lineNumber) {
33170
+ const idx = block.itemIndexByLine.get(lineNumber);
33171
+ if (idx === void 0) return null;
33172
+ const self2 = block.items[idx];
33173
+ for (let i = idx - 1; i >= 0; i--) {
33174
+ const prev = block.items[i];
33175
+ if (prev.parsed.lead < self2.parsed.lead) return prev;
33176
+ }
33177
+ return null;
33178
+ }
32848
33179
  const scriptRel = /* @__PURE__ */ (function detectScriptRel() {
32849
33180
  const relList = typeof document !== "undefined" && document.createElement("link").relList;
32850
33181
  return relList && relList.supports && relList.supports("modulepreload") ? "modulepreload" : "preload";
@@ -32954,7 +33285,7 @@ const PRINT_PALETTE = {
32954
33285
  };
32955
33286
  let pele = null;
32956
33287
  function loadPele() {
32957
- pele ??= __vitePreload(() => import("./lazy-DReExUTA.js").then((n) => n.l), true ? [] : void 0, import.meta.url);
33288
+ pele ??= __vitePreload(() => import("./lazy-C1NE8LhM.js").then((n) => n.l), true ? [] : void 0, import.meta.url);
32958
33289
  return pele;
32959
33290
  }
32960
33291
  function withPrintPalette(svg, palette) {
@@ -32978,43 +33309,49 @@ const zoomHosts = /* @__PURE__ */ new Set();
32978
33309
  function isZoomed(record) {
32979
33310
  return !!record.zoom && record.zoom.scale > record.zoom.fit * 1.001;
32980
33311
  }
32981
- function isDiagramZoomed(host) {
32982
- const record = zooms.get(host);
33312
+ function isDiagramZoomed(host2) {
33313
+ const record = zooms.get(host2);
32983
33314
  return !!record && isZoomed(record);
32984
33315
  }
32985
- function attachDiagramZoom(host) {
32986
- if (zooms.has(host)) return;
33316
+ function attachDiagramZoom(host2) {
33317
+ if (zooms.has(host2)) return;
32987
33318
  const record = { zoom: null };
32988
- zooms.set(host, record);
32989
- zoomHosts.add(host);
33319
+ zooms.set(host2, record);
33320
+ zoomHosts.add(host2);
32990
33321
  void loadPele().then(({ enableZoom }) => {
32991
- if (!host.isConnected) return;
32992
- record.zoom = enableZoom(host, {
33322
+ if (!host2.isConnected) return;
33323
+ record.zoom = enableZoom(host2, {
32993
33324
  labels: isChinese$1() ? { zoomIn: "放大", zoomOut: "缩小", reset: "还原到适合宽度" } : { zoomIn: "Zoom in", zoomOut: "Zoom out", reset: "Reset zoom" }
32994
33325
  });
32995
33326
  });
32996
33327
  }
32997
- function detachDiagramZoom(host) {
32998
- const record = zooms.get(host);
33328
+ function detachDiagramZoom(host2) {
33329
+ const record = zooms.get(host2);
32999
33330
  if (!record) return;
33000
- zooms.delete(host);
33001
- zoomHosts.delete(host);
33331
+ zooms.delete(host2);
33332
+ zoomHosts.delete(host2);
33002
33333
  record.zoom?.destroy();
33003
33334
  }
33004
- function withDiagramZoomPaused(run) {
33335
+ function pauseDiagramZoom() {
33005
33336
  const hidden = [];
33006
- for (const host of zoomHosts) {
33007
- zooms.get(host)?.zoom?.reset();
33008
- const controls = host.querySelector(".pele-zoom");
33337
+ for (const host2 of zoomHosts) {
33338
+ zooms.get(host2)?.zoom?.reset();
33339
+ const controls = host2.querySelector(".pele-zoom");
33009
33340
  if (controls && controls.style.display !== "none") {
33010
33341
  hidden.push({ element: controls, display: controls.style.display });
33011
33342
  controls.style.display = "none";
33012
33343
  }
33013
33344
  }
33345
+ return () => {
33346
+ for (const item of hidden) item.element.style.display = item.display;
33347
+ };
33348
+ }
33349
+ function withDiagramZoomPaused(run) {
33350
+ const restore = pauseDiagramZoom();
33014
33351
  try {
33015
33352
  return run();
33016
33353
  } finally {
33017
- for (const item of hidden) item.element.style.display = item.display;
33354
+ restore();
33018
33355
  }
33019
33356
  }
33020
33357
  const BLOCKED_TAGS = /* @__PURE__ */ new Set([
@@ -33123,15 +33460,16 @@ function pushBlockLines(state, from, to, className, ranges) {
33123
33460
  ranges.push({ from: lineFrom, to: lineFrom, deco: BLOCK(className) });
33124
33461
  }
33125
33462
  }
33126
- const QUOTE_PREFIX_RE$2 = /^(?:[ \t]*> ?)+/;
33127
33463
  function hasListSpace(state, markTo) {
33128
33464
  const ch = markTo < state.doc.length ? state.doc.sliceString(markTo, markTo + 1) : "";
33129
- return ch === " " || ch === " ";
33465
+ return ch === " ";
33130
33466
  }
33131
33467
  function pushListItemLines(state, node, ranges) {
33132
33468
  const selfMark = node.getChild("ListMark");
33133
33469
  if (!selfMark || !hasListSpace(state, selfMark.to)) return;
33134
- const className = `cm-md-li cm-md-li-${Math.min(listDepth$1(node), 6)}`;
33470
+ const afterMark = state.doc.sliceString(selfMark.to, Math.min(selfMark.to + 4, state.doc.length));
33471
+ const isOrdered2 = node.parent?.name === "OrderedList" && !/^ +\[[ xX]\]/.test(afterMark);
33472
+ const baseClass = `cm-md-li cm-md-li-${Math.min(listDepth$1(node), 6)}`;
33135
33473
  const tree = syntaxTree(state);
33136
33474
  const path2 = [];
33137
33475
  let quoted = false;
@@ -33153,16 +33491,17 @@ function pushListItemLines(state, node, ranges) {
33153
33491
  }
33154
33492
  }
33155
33493
  const first = state.doc.lineAt(node.from).number;
33156
- const ownLast = state.doc.lineAt(node.to).number;
33494
+ const ownLast = state.doc.lineAt(Math.max(node.from, node.to - 1)).number;
33157
33495
  const last2 = node.nextSibling?.name === "ListItem" ? state.doc.lineAt(node.nextSibling.from).number - 1 : ownLast;
33158
33496
  for (let n = first; n <= last2; n++) {
33159
33497
  const line = state.doc.line(n);
33498
+ const isBlank = line.text.replace(QUOTE_PREFIX_RE, "").trim() === "";
33160
33499
  if (n > first && n <= ownLast && line.to <= ownEnd) {
33161
- const body = line.text.replace(QUOTE_PREFIX_RE$2, "");
33500
+ const body = line.text.replace(QUOTE_PREFIX_RE, "");
33162
33501
  if (body.trim() !== "" && !/^[ \t]/.test(body)) break;
33163
33502
  }
33164
33503
  if (n <= ownLast && line.to > ownEnd) {
33165
- const quoteLen = QUOTE_PREFIX_RE$2.exec(line.text)?.[0].length ?? 0;
33504
+ const quoteLen = QUOTE_PREFIX_RE.exec(line.text)?.[0].length ?? 0;
33166
33505
  const indent = /^[ \t]*/.exec(line.text.slice(quoteLen))?.[0].length ?? 0;
33167
33506
  const at = Math.min(line.from + quoteLen + indent, line.to);
33168
33507
  let owner = tree.resolveInner(at, 1);
@@ -33172,10 +33511,12 @@ function pushListItemLines(state, node, ranges) {
33172
33511
  if (body.trim() !== "" && !/^[ \t]/.test(body)) break;
33173
33512
  }
33174
33513
  const paragraph = paragraphs.find((block) => block.from <= line.to && block.to > line.from);
33175
- ranges.push({ from: line.from, to: line.from, deco: Decoration.line({ class: className, attributes: {
33514
+ const lineAttrs = {
33176
33515
  ...attributes,
33177
33516
  ...paragraph ? { "data-list-paragraph": String(paragraph.from) } : {}
33178
- } }) });
33517
+ };
33518
+ const lineClass = n > first && isBlank ? `${baseClass} cm-md-li-blank` : isOrdered2 && n === first ? `${baseClass} cm-md-li-ordered` : baseClass;
33519
+ ranges.push({ from: line.from, to: line.from, deco: Decoration.line({ class: lineClass, attributes: lineAttrs }) });
33179
33520
  }
33180
33521
  }
33181
33522
  const hide = (from, to) => Decoration.replace({});
@@ -33184,13 +33525,13 @@ function hideMarker(state, from, to, ranges, visible = false) {
33184
33525
  const end = next === " " || next === " " ? to + 1 : to;
33185
33526
  ranges.push({ from, to: end, deco: visible ? MARK({ class: "cm-md-marker" }) : hide() });
33186
33527
  }
33187
- function inRange(range, pos) {
33528
+ function inRange$1(range, pos) {
33188
33529
  return !!range && pos >= range.from && pos < range.to;
33189
33530
  }
33190
- function iterateContent(state, front, enter) {
33531
+ function iterateContent$1(state, front, enter) {
33191
33532
  syntaxTree(state).iterate({
33192
33533
  enter: (node) => {
33193
- if (front && node.name !== "Document" && inRange(front, node.from)) return false;
33534
+ if (front && node.name !== "Document" && inRange$1(front, node.from)) return false;
33194
33535
  return enter(node);
33195
33536
  }
33196
33537
  });
@@ -33364,8 +33705,8 @@ function listDepth$1(node) {
33364
33705
  }
33365
33706
  return depth;
33366
33707
  }
33367
- function collectMath(state, text2, excluded, ranges, zones) {
33368
- for (const range of scanMath(text2, excluded)) {
33708
+ function collectMath(state, mathRanges, ranges, zones) {
33709
+ for (const range of mathRanges) {
33369
33710
  if (range.block) zones.push({ from: range.from, to: range.to, kind: "block" });
33370
33711
  if (isActiveLine(state, range.from) || range.block && isBlockActive(state, range.from, range.to)) {
33371
33712
  const delim = range.block ? 2 : 1;
@@ -33417,8 +33758,12 @@ class TaskCheckboxWidget extends WidgetType {
33417
33758
  }
33418
33759
  }
33419
33760
  function collectTaskItems(state, ranges, front) {
33420
- iterateContent(state, front, (node) => {
33761
+ iterateContent$1(state, front, (node) => {
33421
33762
  if (node.name !== "TaskMarker") return;
33763
+ let ancestor = node.node.parent;
33764
+ while (ancestor && ancestor.name !== "ListItem") ancestor = ancestor.parent;
33765
+ const selfMark = ancestor?.getChild("ListMark");
33766
+ if (selfMark && !hasListSpace(state, selfMark.to)) return;
33422
33767
  const raw = state.doc.sliceString(node.from, node.to);
33423
33768
  const checked = /x/i.test(raw);
33424
33769
  ranges.push({
@@ -33464,8 +33809,8 @@ class MermaidWidget extends WidgetType {
33464
33809
  const target = event.target;
33465
33810
  if (!(target instanceof Element)) return false;
33466
33811
  if (target.closest(".pele-zoom")) return true;
33467
- const host = target.closest(".cm-md-mermaid");
33468
- return !!host && isDiagramZoomed(host);
33812
+ const host2 = target.closest(".cm-md-mermaid");
33813
+ return !!host2 && isDiagramZoomed(host2);
33469
33814
  }
33470
33815
  }
33471
33816
  const POINTER_EVENTS = /* @__PURE__ */ new Set([
@@ -33479,7 +33824,7 @@ const POINTER_EVENTS = /* @__PURE__ */ new Set([
33479
33824
  "touchend"
33480
33825
  ]);
33481
33826
  function collectMermaid(state, text2, ranges, front, zones) {
33482
- iterateContent(state, front, (node) => {
33827
+ iterateContent$1(state, front, (node) => {
33483
33828
  if (node.name !== "FencedCode") return;
33484
33829
  const firstLineEnd = text2.indexOf("\n", node.from);
33485
33830
  if (firstLineEnd === -1) return;
@@ -33668,7 +34013,7 @@ function appendInline(parent, text2, base2) {
33668
34013
  if (last2 < text2.length) write(parent, last2, text2.length);
33669
34014
  }
33670
34015
  function collectTables(state, ranges, front, zones) {
33671
- iterateContent(state, front, (node) => {
34016
+ iterateContent$1(state, front, (node) => {
33672
34017
  if (node.name !== "Table") return;
33673
34018
  zones.push({ from: node.from, to: node.to, kind: "block" });
33674
34019
  if (isBlockActive(state, node.from, node.to)) {
@@ -33678,20 +34023,23 @@ function collectTables(state, ranges, front, zones) {
33678
34023
  ranges.push({
33679
34024
  from: node.from,
33680
34025
  to: node.to,
34026
+ // 表格恒为整行 → 恒为 block 装饰:跨行 inline replace 在增量更新时
34027
+ // widget 不会被重建,改完表格退出源码后整块会消失(见 collectMath)。
33681
34028
  deco: Decoration.replace({
33682
34029
  widget: new TableWidget(
33683
34030
  state.doc.sliceString(node.from, node.to),
33684
34031
  state.field(documentFileUrlField, false) ?? documentFileUrl,
33685
34032
  node.from,
33686
34033
  node.to
33687
- )
34034
+ ),
34035
+ block: true
33688
34036
  })
33689
34037
  });
33690
34038
  return false;
33691
34039
  });
33692
34040
  }
33693
34041
  function collectLinks(state, ranges, front) {
33694
- iterateContent(state, front, (node) => {
34042
+ iterateContent$1(state, front, (node) => {
33695
34043
  if (node.name !== "Link") return;
33696
34044
  const url = node.node.getChild("URL");
33697
34045
  if (!url) return false;
@@ -33737,7 +34085,7 @@ function collectFootnotes(state, text2, ranges, front) {
33737
34085
  while ((match = FOOTNOTE_REF_RE.exec(text2)) !== null) {
33738
34086
  const from = match.index;
33739
34087
  const to = from + match[0].length;
33740
- if (front && inRange(front, from)) continue;
34088
+ if (front && inRange$1(front, from)) continue;
33741
34089
  if (definitions.has(match[1]) === false && numbers.has(match[1]) === false) continue;
33742
34090
  ranges.push({
33743
34091
  from,
@@ -33748,7 +34096,7 @@ function collectFootnotes(state, text2, ranges, front) {
33748
34096
  for (let n = 1; n <= state.doc.lines; n++) {
33749
34097
  const line = state.doc.line(n);
33750
34098
  if (!/^ {0,3}\[\^[^\]\s]+\]:/.test(line.text)) continue;
33751
- if (front && inRange(front, line.from)) continue;
34099
+ if (front && inRange$1(front, line.from)) continue;
33752
34100
  ranges.push({ from: line.from, to: line.from, deco: BLOCK("cm-md-footnote-def") });
33753
34101
  }
33754
34102
  }
@@ -33773,7 +34121,7 @@ class HTMLWidget extends WidgetType {
33773
34121
  }
33774
34122
  function collectHTML(state, ranges, front, zones) {
33775
34123
  const paired = /* @__PURE__ */ new Set();
33776
- iterateContent(state, front, (node) => {
34124
+ iterateContent$1(state, front, (node) => {
33777
34125
  const block = node.name === "HTMLBlock";
33778
34126
  if (!block && node.name !== "HTMLTag") return;
33779
34127
  if (block) zones.push({ from: node.from, to: node.to, kind: "block" });
@@ -33794,7 +34142,12 @@ function collectHTML(state, ranges, front, zones) {
33794
34142
  ranges.push({
33795
34143
  from: node.from,
33796
34144
  to: node.to,
33797
- deco: Decoration.replace({ widget: new HTMLWidget(state.doc.sliceString(node.from, node.to), block, node.from, node.to) })
34145
+ // HTML 块跨行 → block 装饰:跨行 inline replace 在增量更新时 widget 不会
34146
+ // 被重建,退出源码后整块消失(见 collectMath)。行内标签不跨行,保持 inline。
34147
+ deco: Decoration.replace({
34148
+ widget: new HTMLWidget(state.doc.sliceString(node.from, node.to), block, node.from, node.to),
34149
+ block: block && state.doc.lineAt(node.from).from === node.from && state.doc.lineAt(Math.min(node.to, state.doc.length)).to === node.to
34150
+ })
33798
34151
  });
33799
34152
  return false;
33800
34153
  });
@@ -33843,7 +34196,7 @@ function codeInsideFence(state, node) {
33843
34196
  }
33844
34197
  function collectImages(state, ranges, front) {
33845
34198
  const base2 = state.field(documentFileUrlField, false) ?? documentFileUrl;
33846
- iterateContent(state, front, (node) => {
34199
+ iterateContent$1(state, front, (node) => {
33847
34200
  if (node.name !== "Image") return;
33848
34201
  if (isActiveRange(state, node.from, node.to)) ;
33849
34202
  const source = state.doc.sliceString(node.from, node.to);
@@ -33857,8 +34210,8 @@ function collectImages(state, ranges, front) {
33857
34210
  return false;
33858
34211
  });
33859
34212
  }
33860
- function collectBlocks(state, ranges, front) {
33861
- iterateContent(state, front, (node) => {
34213
+ function collectBlocks$1(state, ranges, front, mathRanges) {
34214
+ iterateContent$1(state, front, (node) => {
33862
34215
  switch (node.name) {
33863
34216
  case "Blockquote": {
33864
34217
  pushBlockLines(state, node.from, node.to, "cm-md-blockquote", ranges);
@@ -33875,12 +34228,14 @@ function collectBlocks(state, ranges, front) {
33875
34228
  case "ListMark": {
33876
34229
  if (!hasListSpace(state, node.to)) break;
33877
34230
  const line = state.doc.lineAt(node.from);
33878
- const quoteLen = QUOTE_PREFIX_RE$2.exec(state.doc.sliceString(line.from, node.from))?.[0].length ?? 0;
34231
+ const quoteLen = QUOTE_PREFIX_RE.exec(state.doc.sliceString(line.from, node.from))?.[0].length ?? 0;
34232
+ const beforeMark = state.doc.sliceString(line.from + quoteLen, node.from);
34233
+ if (/[^ \t]/.test(beforeMark)) break;
33879
34234
  const hideFrom = line.from + quoteLen;
33880
34235
  if (node.from > hideFrom) ranges.push({ from: hideFrom, to: node.from, deco: hide(hideFrom, node.from) });
33881
34236
  const raw = state.doc.sliceString(node.from, node.to).trim();
33882
34237
  const after = state.doc.sliceString(node.to, node.to + 4);
33883
- if (/^\s+\[[ xX]\]/.test(after)) {
34238
+ if (/^ +\[[ xX]\]/.test(after)) {
33884
34239
  hideMarker(state, node.from, node.to, ranges, isActiveLine(state, node.from));
33885
34240
  break;
33886
34241
  }
@@ -33901,6 +34256,36 @@ function collectBlocks(state, ranges, front) {
33901
34256
  pushListItemLines(state, node.node, ranges);
33902
34257
  break;
33903
34258
  }
34259
+ // CommonMark 规定空列表项(如紧跟普通段落下方刚敲完 `1. ` 或 `- ` 尚未打字)
34260
+ // 不能打断段落,因此语法树会把它归进 Paragraph,导致敲完空格不出列表格式、
34261
+ // 非得打字才出来。这里仅对顶层 Paragraph 里的空列表项立即补渲染,绝不误伤
34262
+ // 普通折行里的 `2026. 敬请期待`、跨行行内代码、块公式或 ListItem 续行。
34263
+ case "Paragraph": {
34264
+ if (node.node.parent?.name === "ListItem") break;
34265
+ const tree = syntaxTree(state);
34266
+ const startLine = state.doc.lineAt(node.from).number;
34267
+ const endLine = state.doc.lineAt(Math.max(node.from, node.to - 1)).number;
34268
+ for (let n = startLine; n <= endLine; n++) {
34269
+ const line = state.doc.line(n);
34270
+ const parsed = parseListLine(line.text);
34271
+ if (!parsed || !parsed.isEmpty || parsed.box) continue;
34272
+ const markFrom = line.from + parsed.markerStart;
34273
+ const markTo = line.from + parsed.markerEnd;
34274
+ const inner2 = tree.resolveInner(markFrom, 1);
34275
+ if (inner2.name !== "Paragraph") continue;
34276
+ if (mathRanges.some((m) => markFrom >= m.from && markFrom < m.to)) continue;
34277
+ const lineClass = parsed.kind === "ordered" ? "cm-md-li cm-md-li-0 cm-md-li-ordered" : "cm-md-li cm-md-li-0";
34278
+ ranges.push({ from: line.from, to: line.from, deco: Decoration.line({ class: lineClass }) });
34279
+ const hideFrom = line.from + parsed.quoteLen;
34280
+ if (markFrom > hideFrom) ranges.push({ from: hideFrom, to: markFrom, deco: hide() });
34281
+ if (parsed.kind === "bullet" && true) {
34282
+ ranges.push({ from: markFrom, to: markTo, deco: Decoration.replace({ widget: new ListBulletWidget() }) });
34283
+ } else {
34284
+ ranges.push({ from: markFrom, to: markTo, deco: MARK({ class: "cm-md-listmark" }) });
34285
+ }
34286
+ }
34287
+ break;
34288
+ }
33904
34289
  case "FencedCode": {
33905
34290
  const code = exportingCleanly(state) ? "" : codeInsideFence(state, node);
33906
34291
  if (code !== "") {
@@ -33937,10 +34322,10 @@ function collectBlocks(state, ranges, front) {
33937
34322
  }
33938
34323
  const URL_STOP = /[\u2E80-\u30FF\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF\u3000-\u303F\uFF00-\uFFEF]/;
33939
34324
  function collectInline(state, ranges, front) {
33940
- iterateContent(state, front, (node) => {
34325
+ iterateContent$1(state, front, (node) => {
33941
34326
  const from = node.from;
33942
34327
  const to = node.to;
33943
- const active = isActiveLine();
34328
+ const active2 = isActiveLine();
33944
34329
  switch (node.name) {
33945
34330
  case "ATXHeading1":
33946
34331
  case "ATXHeading2":
@@ -33966,7 +34351,8 @@ function collectInline(state, ranges, front) {
33966
34351
  break;
33967
34352
  }
33968
34353
  case "HeaderMark": {
33969
- hideMarker(state, from, to, ranges, active);
34354
+ if (!node.node.parent?.name.startsWith("ATXHeading")) break;
34355
+ hideMarker(state, from, to, ranges, active2);
33970
34356
  break;
33971
34357
  }
33972
34358
  case "InlineCode": {
@@ -33999,7 +34385,7 @@ const PAGE_CLASS_PREFIX = "cm-md-page-";
33999
34385
  const PAGE_START_CLASS = "cm-md-page-start";
34000
34386
  function collectPages(state, ranges, front) {
34001
34387
  const breaks = [];
34002
- iterateContent(state, front, (node) => {
34388
+ iterateContent$1(state, front, (node) => {
34003
34389
  if (node.name !== "HorizontalRule") return;
34004
34390
  breaks.push(state.doc.lineAt(node.from).number);
34005
34391
  });
@@ -34037,7 +34423,7 @@ function activeZonesKey(state, zones) {
34037
34423
  }
34038
34424
  return parts.join("|");
34039
34425
  }
34040
- function buildDecorations(state, flash) {
34426
+ function buildDecorations$1(state, flash) {
34041
34427
  const ranges = [];
34042
34428
  const zones = [];
34043
34429
  const text2 = state.doc.toString();
@@ -34046,7 +34432,8 @@ function buildDecorations(state, flash) {
34046
34432
  if (flash && flash.to <= state.doc.length) {
34047
34433
  ranges.push({ from: flash.from, to: flash.to, deco: MARK({ class: "cm-md-jump-flash" }) });
34048
34434
  }
34049
- collectBlocks(state, ranges, front);
34435
+ const mathRanges = scanMath(text2, excluded);
34436
+ collectBlocks$1(state, ranges, front, mathRanges);
34050
34437
  collectLinks(state, ranges, front);
34051
34438
  collectFootnotes(state, text2, ranges, front);
34052
34439
  collectHTML(state, ranges, front, zones);
@@ -34058,7 +34445,7 @@ function buildDecorations(state, flash) {
34058
34445
  collectTaskItems(state, ranges, front);
34059
34446
  collectMermaid(state, text2, ranges, front, zones);
34060
34447
  collectHighlight(state, text2, ranges, excluded);
34061
- collectMath(state, text2, excluded, ranges, zones);
34448
+ collectMath(state, mathRanges, ranges, zones);
34062
34449
  ranges.sort((a, b) => a.from - b.from || a.deco.startSide - b.deco.startSide || a.to - b.to);
34063
34450
  const builder = new RangeSetBuilder();
34064
34451
  for (const r of ranges) builder.add(r.from, r.to, r.deco);
@@ -34067,7 +34454,7 @@ function buildDecorations(state, flash) {
34067
34454
  return deco;
34068
34455
  }
34069
34456
  const livePreviewField = StateField.define({
34070
- create: (state) => buildDecorations(state, null),
34457
+ create: (state) => buildDecorations$1(state, null),
34071
34458
  update(deco, tr) {
34072
34459
  const flash = tr.effects.find((effect) => effect.is(headingFlashEffect));
34073
34460
  const flashValue = flash ? flash.value : currentFlash;
@@ -34083,7 +34470,7 @@ const livePreviewField = StateField.define({
34083
34470
  return deco;
34084
34471
  }
34085
34472
  }
34086
- return buildDecorations(tr.state, flashValue);
34473
+ return buildDecorations$1(tr.state, flashValue);
34087
34474
  },
34088
34475
  provide: (field) => EditorView.decorations.from(field)
34089
34476
  });
@@ -34469,9 +34856,9 @@ let fieldMarker = /* @__PURE__ */ Decoration.widget({ widget: /* @__PURE__ */ ne
34469
34856
  }() });
34470
34857
  let fieldRange = /* @__PURE__ */ Decoration.mark({ class: "cm-snippetField" });
34471
34858
  class ActiveSnippet {
34472
- constructor(ranges, active) {
34859
+ constructor(ranges, active2) {
34473
34860
  this.ranges = ranges;
34474
- this.active = active;
34861
+ this.active = active2;
34475
34862
  this.deco = Decoration.set(ranges.map((r) => (r.from == r.to ? fieldMarker : fieldRange).range(r.from, r.to)), true);
34476
34863
  }
34477
34864
  map(changes) {
@@ -34529,8 +34916,8 @@ function snippet(template) {
34529
34916
  if (ranges.length)
34530
34917
  spec.selection = fieldSelection(ranges, 0);
34531
34918
  if (ranges.some((r) => r.field > 0)) {
34532
- let active = new ActiveSnippet(ranges, 0);
34533
- let effects = spec.effects = [setActive.of(active)];
34919
+ let active2 = new ActiveSnippet(ranges, 0);
34920
+ let effects = spec.effects = [setActive.of(active2)];
34534
34921
  if (editor.state.field(snippetState, false) === void 0)
34535
34922
  effects.push(StateEffect.appendConfig.of([snippetState, addSnippetKeymap, snippetPointerHandler, baseTheme]));
34536
34923
  }
@@ -34539,21 +34926,21 @@ function snippet(template) {
34539
34926
  }
34540
34927
  function moveField(dir) {
34541
34928
  return ({ state, dispatch }) => {
34542
- let active = state.field(snippetState, false);
34543
- if (!active || dir < 0 && active.active == 0)
34929
+ let active2 = state.field(snippetState, false);
34930
+ if (!active2 || dir < 0 && active2.active == 0)
34544
34931
  return false;
34545
- let next = active.active + dir, last2 = dir > 0 && !active.ranges.some((r) => r.field == next + dir);
34932
+ let next = active2.active + dir, last2 = dir > 0 && !active2.ranges.some((r) => r.field == next + dir);
34546
34933
  dispatch(state.update({
34547
- selection: fieldSelection(active.ranges, next),
34548
- effects: setActive.of(last2 ? null : new ActiveSnippet(active.ranges, next)),
34934
+ selection: fieldSelection(active2.ranges, next),
34935
+ effects: setActive.of(last2 ? null : new ActiveSnippet(active2.ranges, next)),
34549
34936
  scrollIntoView: true
34550
34937
  }));
34551
34938
  return true;
34552
34939
  };
34553
34940
  }
34554
34941
  const clearSnippet = ({ state, dispatch }) => {
34555
- let active = state.field(snippetState, false);
34556
- if (!active)
34942
+ let active2 = state.field(snippetState, false);
34943
+ if (!active2)
34557
34944
  return false;
34558
34945
  dispatch(state.update({ effects: setActive.of(null) }));
34559
34946
  return true;
@@ -34575,15 +34962,15 @@ function snippetCompletion(template, completion) {
34575
34962
  }
34576
34963
  const snippetPointerHandler = /* @__PURE__ */ EditorView.domEventHandlers({
34577
34964
  mousedown(event, view) {
34578
- let active = view.state.field(snippetState, false), pos;
34579
- if (!active || (pos = view.posAtCoords({ x: event.clientX, y: event.clientY })) == null)
34965
+ let active2 = view.state.field(snippetState, false), pos;
34966
+ if (!active2 || (pos = view.posAtCoords({ x: event.clientX, y: event.clientY })) == null)
34580
34967
  return false;
34581
- let match = active.ranges.find((r) => r.from <= pos && r.to >= pos);
34582
- if (!match || match.field == active.active)
34968
+ let match = active2.ranges.find((r) => r.from <= pos && r.to >= pos);
34969
+ if (!match || match.field == active2.active)
34583
34970
  return false;
34584
34971
  view.dispatch({
34585
- selection: fieldSelection(active.ranges, match.field),
34586
- effects: setActive.of(active.ranges.some((r) => r.field > match.field) ? new ActiveSnippet(active.ranges, match.field) : null),
34972
+ selection: fieldSelection(active2.ranges, match.field),
34973
+ effects: setActive.of(active2.ranges.some((r) => r.field > match.field) ? new ActiveSnippet(active2.ranges, match.field) : null),
34587
34974
  scrollIntoView: true
34588
34975
  });
34589
34976
  return true;
@@ -41553,64 +41940,195 @@ const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
41553
41940
  markdownLanguage,
41554
41941
  pasteURLAsLink
41555
41942
  }, Symbol.toStringTag, { value: "Module" }));
41556
- const QUOTE_PREFIX_RE$1 = /^(?:[ \t]*> ?)+/;
41557
- const LIST_BODY_RE = /^([ \t]*)(?:([-*+])|(\d+)([.)]))([ \t]+)(\[[ xX]\][ \t]+)?/;
41558
- const INDENT = " ";
41559
- function countQuotes(prefix) {
41560
- let count2 = 0;
41561
- for (let i = 0; i < prefix.length; i++) {
41562
- if (prefix[i] === ">") count2++;
41563
- }
41564
- return count2;
41943
+ const continueMarkup = insertNewlineContinueMarkupCommand({ nonTightLists: false });
41944
+ function getTreeAndFm(state) {
41945
+ return { tree: syntaxTree(state), fmEnd: frontmatterEnd(state.doc) };
41565
41946
  }
41566
- function parseListLine(text2) {
41567
- const quotePrefix = QUOTE_PREFIX_RE$1.exec(text2)?.[0] ?? "";
41568
- const quoteLen = quotePrefix.length;
41569
- const match = LIST_BODY_RE.exec(text2.slice(quoteLen));
41570
- if (!match) return null;
41571
- const lead = match[1].length;
41572
- const box = match[6] ?? "";
41573
- const width = match[0].length - lead - box.length;
41574
- return {
41575
- quoteLen,
41576
- quoteDepth: countQuotes(quotePrefix),
41577
- lead,
41578
- width,
41579
- digits: match[3] ?? "",
41580
- box,
41581
- contentOffset: quoteLen + match[0].length
41582
- };
41947
+ function parseOrderDigits(digits) {
41948
+ const n = Number.parseInt(digits, 10);
41949
+ return Number.isFinite(n) && n >= 0 ? n : 1;
41583
41950
  }
41584
- const continueMarkup = insertNewlineContinueMarkupCommand({ nonTightLists: false });
41585
41951
  function handleEnter(view) {
41586
41952
  const { state } = view;
41953
+ if (state.selection.ranges.length > 1) return false;
41587
41954
  const range = state.selection.main;
41955
+ const { tree, fmEnd } = getTreeAndFm(state);
41956
+ const startLine = state.doc.lineAt(range.from);
41957
+ if (isExcludedLine(state.doc, tree, startLine.number, fmEnd)) return false;
41958
+ const startParsed = parseListLine(startLine.text);
41959
+ if (startParsed?.kind === "ordered") {
41960
+ if (!range.empty) {
41961
+ const endLine = state.doc.lineAt(range.to);
41962
+ if (endLine.number !== startLine.number) return false;
41963
+ return handleOrderedEnter(view, startLine, startParsed, range.from, range.to);
41964
+ }
41965
+ return handleOrderedEnter(view, startLine, startParsed, range.head, range.head);
41966
+ }
41588
41967
  if (!range.empty) return false;
41589
- const line = state.doc.lineAt(range.head);
41590
- if (/^[ \t]*(?:>[ \t]*)+$/.test(line.text)) {
41591
- const lastGt = line.text.lastIndexOf(">");
41592
- if (range.head >= line.from + lastGt + 1) {
41593
- const depth = countQuotes(line.text);
41594
- const delFrom = depth <= 1 ? line.from : line.from + line.text.slice(0, lastGt).replace(/[ \t]+$/, "").length;
41968
+ if (/^[ \t]*(?:>[ \t]*)+$/.test(startLine.text)) {
41969
+ const lastGt = startLine.text.lastIndexOf(">");
41970
+ if (range.head >= startLine.from + lastGt + 1) {
41971
+ const depth = countQuotes(startLine.text);
41972
+ if (depth <= 1) {
41973
+ view.dispatch({
41974
+ changes: { from: startLine.from, to: startLine.to, insert: "" },
41975
+ selection: { anchor: startLine.from },
41976
+ scrollIntoView: true,
41977
+ userEvent: "input"
41978
+ });
41979
+ } else {
41980
+ const beforeLast = startLine.text.slice(0, lastGt).replace(/[ \t]+$/, "");
41981
+ const kept = `${beforeLast} `;
41982
+ view.dispatch({
41983
+ changes: { from: startLine.from, to: startLine.to, insert: kept },
41984
+ selection: { anchor: startLine.from + kept.length },
41985
+ scrollIntoView: true,
41986
+ userEvent: "input"
41987
+ });
41988
+ }
41989
+ return true;
41990
+ }
41991
+ }
41992
+ if (!startParsed) {
41993
+ const quotePrefix = QUOTE_PREFIX_RE.exec(startLine.text)?.[0];
41994
+ if (!quotePrefix) return false;
41995
+ const insert2 = `
41996
+ ${quotePrefix}`;
41997
+ view.dispatch({
41998
+ changes: { from: range.head, to: range.head, insert: insert2 },
41999
+ selection: { anchor: range.head + insert2.length },
42000
+ scrollIntoView: true,
42001
+ userEvent: "input"
42002
+ });
42003
+ return true;
42004
+ }
42005
+ if (startParsed.kind === "bullet" && startParsed.isEmpty && range.head >= startLine.from + startParsed.contentOffset) {
42006
+ if (startParsed.lead > 0) return indentSingleLine(view, startLine.number, -1);
42007
+ const delFrom = startLine.from + startParsed.quoteLen;
42008
+ view.dispatch({
42009
+ changes: { from: delFrom, to: startLine.to, insert: "" },
42010
+ selection: { anchor: delFrom },
42011
+ scrollIntoView: true,
42012
+ userEvent: "input"
42013
+ });
42014
+ return true;
42015
+ }
42016
+ return continueMarkup(view);
42017
+ }
42018
+ function handleOrderedEnter(view, line, self2, selFrom, selTo) {
42019
+ const { state } = view;
42020
+ const { tree, fmEnd } = getTreeAndFm(state);
42021
+ const contentStart = line.from + self2.contentOffset;
42022
+ const block = scanListBlock(state.doc, line.number, tree, fmEnd);
42023
+ if (selFrom === selTo && self2.isEmpty) {
42024
+ if (self2.lead > 0) {
42025
+ return indentSingleLine(view, line.number, -1);
42026
+ }
42027
+ const prevSib = block ? findPrevSibling(block, line.number) : null;
42028
+ if (!prevSib) {
42029
+ const nextNum2 = parseOrderDigits(self2.digits) + 1;
42030
+ const nextPrefix2 = `${self2.quotePrefix}${nextNum2}${self2.delim} ${self2.box ? "[ ] " : ""}`;
42031
+ const insert22 = `
42032
+ ${nextPrefix2}`;
41595
42033
  view.dispatch({
41596
- changes: { from: delFrom, to: line.to, insert: "" },
41597
- selection: { anchor: delFrom },
42034
+ changes: { from: line.to, to: line.to, insert: insert22 },
42035
+ selection: { anchor: line.to + insert22.length },
41598
42036
  scrollIntoView: true,
41599
42037
  userEvent: "input"
41600
42038
  });
41601
42039
  return true;
41602
42040
  }
42041
+ const delFrom = line.from + self2.quoteLen;
42042
+ view.dispatch({
42043
+ changes: { from: delFrom, to: line.to, insert: "" },
42044
+ selection: { anchor: delFrom },
42045
+ scrollIntoView: true,
42046
+ userEvent: "input"
42047
+ });
42048
+ return true;
41603
42049
  }
41604
- if (!QUOTE_PREFIX_RE$1.test(line.text) && !parseListLine(line.text) && !/^[ \t]/.test(line.text)) {
41605
- return false;
42050
+ if (selFrom < selTo && selTo <= contentStart) return false;
42051
+ const cutFrom = Math.max(selFrom, contentStart);
42052
+ const cutTo = Math.max(selTo, cutFrom);
42053
+ const after = line.text.slice(cutTo - line.from);
42054
+ const indentStr = line.text.slice(self2.quoteLen, self2.quoteLen + self2.leadChars);
42055
+ const nextBox = self2.box ? "[ ] " : "";
42056
+ if (after === "" && block) {
42057
+ const firstChild = findFirstDirectChild(block, line.number);
42058
+ if (firstChild && firstChild.lineNumber === line.number + 1) {
42059
+ const childLine = state.doc.line(firstChild.lineNumber);
42060
+ const childIndent = childLine.text.slice(
42061
+ firstChild.parsed.quoteLen,
42062
+ firstChild.parsed.quoteLen + firstChild.parsed.leadChars
42063
+ );
42064
+ const childMarker = firstChild.parsed.kind === "ordered" ? `1${firstChild.parsed.delim} ` : `${firstChild.parsed.bullet} `;
42065
+ const childBox = firstChild.parsed.box ? "[ ] " : "";
42066
+ const insert22 = `
42067
+ ${firstChild.parsed.quotePrefix}${childIndent}${childMarker}${childBox}`;
42068
+ view.dispatch({
42069
+ changes: { from: cutFrom, to: cutTo, insert: insert22 },
42070
+ selection: { anchor: cutFrom + insert22.length },
42071
+ scrollIntoView: true,
42072
+ userEvent: "input"
42073
+ });
42074
+ return true;
42075
+ }
41606
42076
  }
41607
- return continueMarkup(view);
42077
+ if (cutFrom === contentStart && cutTo === contentStart && after !== "") {
42078
+ const num = parseOrderDigits(self2.digits);
42079
+ const upperLine = `${self2.quotePrefix}${indentStr}${num}${self2.delim} ${nextBox}
42080
+ `;
42081
+ const changes = state.changes({ from: line.from, to: line.from, insert: upperLine });
42082
+ view.dispatch({
42083
+ changes,
42084
+ selection: { anchor: changes.mapPos(contentStart, 1) },
42085
+ scrollIntoView: true,
42086
+ userEvent: "input"
42087
+ });
42088
+ return true;
42089
+ }
42090
+ const nextNum = parseOrderDigits(self2.digits) + 1;
42091
+ const nextPrefix = `${self2.quotePrefix}${indentStr}${nextNum}${self2.delim} ${nextBox}`;
42092
+ const insert2 = `
42093
+ ${nextPrefix}`;
42094
+ view.dispatch({
42095
+ changes: { from: cutFrom, to: cutTo, insert: insert2 },
42096
+ selection: { anchor: cutFrom + insert2.length },
42097
+ scrollIntoView: true,
42098
+ userEvent: "input"
42099
+ });
42100
+ return true;
42101
+ }
42102
+ function handleShiftEnter(view) {
42103
+ const { state } = view;
42104
+ if (state.selection.ranges.length > 1) return false;
42105
+ const range = state.selection.main;
42106
+ const { tree, fmEnd } = getTreeAndFm(state);
42107
+ const line = state.doc.lineAt(range.from);
42108
+ if (isExcludedLine(state.doc, tree, line.number, fmEnd)) return false;
42109
+ const self2 = parseListLine(line.text);
42110
+ if (!self2) return false;
42111
+ const pad3 = " ".repeat(self2.lead + self2.markerWidth);
42112
+ const insert2 = `
42113
+ ${self2.quotePrefix}${pad3}`;
42114
+ const cutFrom = Math.max(range.from, line.from + self2.contentOffset);
42115
+ const cutTo = Math.max(range.to, cutFrom);
42116
+ view.dispatch({
42117
+ changes: { from: cutFrom, to: cutTo, insert: insert2 },
42118
+ selection: { anchor: cutFrom + insert2.length },
42119
+ scrollIntoView: true,
42120
+ userEvent: "input"
42121
+ });
42122
+ return true;
41608
42123
  }
41609
42124
  function deleteTaskBox(view) {
41610
42125
  const { state } = view;
42126
+ if (state.selection.ranges.length > 1) return false;
41611
42127
  const range = state.selection.main;
41612
42128
  if (!range.empty) return false;
42129
+ const { tree, fmEnd } = getTreeAndFm(state);
41613
42130
  const line = state.doc.lineAt(range.head);
42131
+ if (isExcludedLine(state.doc, tree, line.number, fmEnd)) return false;
41614
42132
  const self2 = parseListLine(line.text);
41615
42133
  if (!self2 || !self2.box) return false;
41616
42134
  const contentStart = line.from + self2.contentOffset;
@@ -41625,22 +42143,51 @@ function deleteTaskBox(view) {
41625
42143
  }
41626
42144
  function deleteAtLineStart(view) {
41627
42145
  const { state } = view;
42146
+ if (state.selection.ranges.length > 1) return false;
41628
42147
  const range = state.selection.main;
41629
42148
  if (!range.empty) return false;
42149
+ const { tree, fmEnd } = getTreeAndFm(state);
41630
42150
  const line = state.doc.lineAt(range.head);
42151
+ if (isExcludedLine(state.doc, tree, line.number, fmEnd)) return false;
41631
42152
  const self2 = parseListLine(line.text);
41632
42153
  if (self2 && range.head <= line.from + self2.contentOffset) {
41633
- if (self2.lead > 0) return indentListItem(view, -1);
42154
+ if (self2.lead > 0) return indentSingleLine(view, line.number, -1);
42155
+ if (self2.kind === "ordered") {
42156
+ const block = scanListBlock(state.doc, line.number, tree, fmEnd);
42157
+ const prevSib = block ? findPrevSibling(block, line.number) : null;
42158
+ if (prevSib && line.number > 1) {
42159
+ const prevLine = state.doc.line(line.number - 1);
42160
+ const delFrom = prevLine.to;
42161
+ const delTo = line.from + self2.contentOffset;
42162
+ view.dispatch({
42163
+ changes: { from: delFrom, to: delTo, insert: "" },
42164
+ selection: { anchor: delFrom },
42165
+ scrollIntoView: true,
42166
+ userEvent: "delete"
42167
+ });
42168
+ return true;
42169
+ }
42170
+ const from2 = line.from + self2.quoteLen;
42171
+ const to2 = line.from + self2.contentOffset;
42172
+ view.dispatch({
42173
+ changes: { from: from2, to: to2, insert: "" },
42174
+ selection: { anchor: from2 },
42175
+ scrollIntoView: true,
42176
+ userEvent: "delete"
42177
+ });
42178
+ return true;
42179
+ }
41634
42180
  const from = line.from + self2.quoteLen;
41635
42181
  const to = line.from + self2.contentOffset;
41636
42182
  view.dispatch({
41637
42183
  changes: { from, to, insert: "" },
41638
42184
  selection: { anchor: from },
42185
+ scrollIntoView: true,
41639
42186
  userEvent: "delete"
41640
42187
  });
41641
42188
  return true;
41642
42189
  }
41643
- const quotePrefix = QUOTE_PREFIX_RE$1.exec(line.text)?.[0] ?? "";
42190
+ const quotePrefix = QUOTE_PREFIX_RE.exec(line.text)?.[0] ?? "";
41644
42191
  const quoteLen = quotePrefix.length;
41645
42192
  const head = /^#{1,6}[ \t]?/.exec(line.text.slice(quoteLen));
41646
42193
  if (head && head[0].length > 0 && range.head >= line.from + quoteLen && range.head <= line.from + quoteLen + head[0].length) {
@@ -41654,7 +42201,7 @@ function deleteAtLineStart(view) {
41654
42201
  }
41655
42202
  if (quoteLen > 0 && range.head <= line.from + quoteLen) {
41656
42203
  if (line.text.length > quoteLen || range.head > line.from) {
41657
- const innerMatch = /[ \t]*> ?$/.exec(quotePrefix);
42204
+ const innerMatch = />[ \t]?$/.exec(quotePrefix);
41658
42205
  const delFrom = innerMatch ? line.from + quoteLen - innerMatch[0].length : line.from;
41659
42206
  view.dispatch({
41660
42207
  changes: { from: delFrom, to: line.from + quoteLen, insert: "" },
@@ -41666,21 +42213,46 @@ function deleteAtLineStart(view) {
41666
42213
  }
41667
42214
  return false;
41668
42215
  }
41669
- function indentListItem(view, direction) {
42216
+ function handleTab(view, direction) {
41670
42217
  const { state } = view;
42218
+ if (state.selection.ranges.length > 1) return false;
41671
42219
  const range = state.selection.main;
41672
- if (!range.empty) return false;
41673
- const line = state.doc.lineAt(range.head);
42220
+ const { tree, fmEnd } = getTreeAndFm(state);
42221
+ const startLine = state.doc.lineAt(range.from);
42222
+ const endPos = range.empty ? range.to : Math.max(range.from, range.to - (range.to > range.from && state.doc.lineAt(range.to).from === range.to ? 1 : 0));
42223
+ const endLine = state.doc.lineAt(endPos);
42224
+ if (startLine.number === endLine.number) {
42225
+ if (isExcludedLine(state.doc, tree, startLine.number, fmEnd)) return false;
42226
+ return indentSingleLine(view, startLine.number, direction);
42227
+ }
42228
+ return indentMultiLineSelection(view, startLine.number, endLine.number, direction);
42229
+ }
42230
+ function indentSingleLine(view, lineNumber, direction) {
42231
+ const { state } = view;
42232
+ const { tree, fmEnd } = getTreeAndFm(state);
42233
+ const range = state.selection.main;
42234
+ const line = state.doc.line(lineNumber);
41674
42235
  const self2 = parseListLine(line.text);
41675
42236
  if (!self2) {
41676
- const quotePrefix = QUOTE_PREFIX_RE$1.exec(line.text)?.[0];
41677
- if (!quotePrefix) return false;
41678
- const bodyFrom2 = line.from + quotePrefix.length;
42237
+ const quotePrefix = QUOTE_PREFIX_RE.exec(line.text)?.[0];
42238
+ if (!quotePrefix) {
42239
+ if (direction === 1 && range.empty) {
42240
+ view.dispatch({
42241
+ changes: { from: range.head, to: range.head, insert: " " },
42242
+ selection: { anchor: range.head + 1 },
42243
+ scrollIntoView: true,
42244
+ userEvent: "input"
42245
+ });
42246
+ return true;
42247
+ }
42248
+ return false;
42249
+ }
42250
+ const bodyFrom = line.from + quotePrefix.length;
41679
42251
  if (direction === 1) {
41680
- const at = Math.max(range.head, bodyFrom2);
42252
+ const at = Math.max(range.head, bodyFrom);
41681
42253
  view.dispatch({
41682
- changes: { from: at, to: at, insert: INDENT },
41683
- selection: { anchor: at + INDENT.length },
42254
+ changes: { from: at, to: at, insert: " " },
42255
+ selection: { anchor: at + 1 },
41684
42256
  scrollIntoView: true,
41685
42257
  userEvent: "input"
41686
42258
  });
@@ -41688,83 +42260,235 @@ function indentListItem(view, direction) {
41688
42260
  }
41689
42261
  const spaces2 = /^[ \t]+/.exec(line.text.slice(quotePrefix.length))?.[0] ?? "";
41690
42262
  if (!spaces2) return true;
41691
- const remove2 = Math.min(spaces2.length, INDENT.length);
42263
+ const edit = adjustLeadEdit(spaces2, -BULLET_INDENT);
42264
+ if (edit.removeChars === 0 && edit.replaceWith === "") return true;
42265
+ const changes2 = state.changes({ from: bodyFrom, to: bodyFrom + edit.removeChars, insert: edit.replaceWith });
42266
+ const anchor = Math.min(changes2.newLength, Math.max(bodyFrom, changes2.mapPos(range.head, -1)));
41692
42267
  view.dispatch({
41693
- changes: { from: bodyFrom2, to: bodyFrom2 + remove2, insert: "" },
41694
- selection: { anchor: Math.max(bodyFrom2, range.head - remove2) },
42268
+ changes: changes2,
42269
+ selection: { anchor },
41695
42270
  scrollIntoView: true,
41696
42271
  userEvent: "input"
41697
42272
  });
41698
42273
  return true;
41699
42274
  }
41700
- const bodyFrom = line.from + self2.quoteLen;
42275
+ const block = scanListBlock(state.doc, lineNumber, tree, fmEnd);
42276
+ const blockIdx = block?.itemIndexByLine.get(lineNumber);
42277
+ const blockItem = block && blockIdx !== void 0 ? block.items[blockIdx] : null;
42278
+ const subtreeEnd = blockItem ? blockItem.subtreeEndLine : lineNumber;
41701
42279
  if (direction === 1) {
41702
- const parent2 = parentItem(state, line, self2.lead, self2.quoteDepth);
41703
- const target = parent2 ? parent2.lead + parent2.width : self2.lead + self2.width;
41704
- const lead2 = Math.max(target, self2.lead + INDENT.length);
41705
- const change = freshSublist(state, line, lead2, self2) ? { from: bodyFrom, to: bodyFrom + self2.lead + self2.digits.length, insert: `${" ".repeat(lead2)}1` } : { from: bodyFrom, insert: " ".repeat(lead2 - self2.lead) };
41706
- const changes = state.changes(change);
42280
+ const parent2 = block ? findIndentParent(block, lineNumber, self2.lead) : null;
42281
+ if (!parent2) return true;
42282
+ const step = parent2.parsed.kind === "ordered" ? ORDERED_INDENT : BULLET_INDENT;
42283
+ const targetLead2 = Math.max(parent2.parsed.lead + parent2.parsed.markerWidth, parent2.parsed.lead + step);
42284
+ const delta2 = targetLead2 - self2.lead;
42285
+ if (delta2 <= 0) return true;
42286
+ const specs2 = [];
42287
+ for (let ln = lineNumber; ln <= subtreeEnd; ln++) {
42288
+ const subLine = state.doc.line(ln);
42289
+ const qLen = QUOTE_PREFIX_RE.exec(subLine.text)?.[0].length ?? 0;
42290
+ const leadRaw = /^[ \t]*/.exec(subLine.text.slice(qLen))?.[0] ?? "";
42291
+ const edit = adjustLeadEdit(leadRaw, delta2);
42292
+ const at = subLine.from + qLen;
42293
+ specs2.push({ from: at, to: at + edit.removeChars, insert: edit.replaceWith });
42294
+ }
42295
+ const changes2 = state.changes(specs2);
42296
+ const anchor = Math.min(changes2.newLength, Math.max(0, changes2.mapPos(range.head, 1)));
41707
42297
  view.dispatch({
41708
- changes,
41709
- selection: { anchor: changes.mapPos(range.head, 1) },
42298
+ changes: changes2,
42299
+ selection: { anchor },
41710
42300
  scrollIntoView: true,
41711
42301
  userEvent: "input"
41712
42302
  });
41713
42303
  return true;
41714
42304
  }
41715
- const parent = parentItem(state, line, self2.lead - 1, self2.quoteDepth);
41716
- const lead = parent ? parent.lead : 0;
41717
- if (lead >= self2.lead) return false;
42305
+ if (self2.lead === 0) return true;
42306
+ const parent = block ? findOutdentTarget(block, lineNumber) : null;
42307
+ const targetLead = parent ? parent.parsed.lead : 0;
42308
+ const delta = self2.lead - targetLead;
42309
+ if (delta <= 0) return true;
42310
+ const specs = [];
42311
+ for (let ln = lineNumber; ln <= subtreeEnd; ln++) {
42312
+ const subLine = state.doc.line(ln);
42313
+ const qLen = QUOTE_PREFIX_RE.exec(subLine.text)?.[0].length ?? 0;
42314
+ const leadMatch = /^[ \t]*/.exec(subLine.text.slice(qLen))?.[0] ?? "";
42315
+ const edit = adjustLeadEdit(leadMatch, -delta);
42316
+ if (edit.removeChars > 0 || edit.replaceWith !== "") {
42317
+ specs.push({ from: subLine.from + qLen, to: subLine.from + qLen + edit.removeChars, insert: edit.replaceWith });
42318
+ }
42319
+ }
42320
+ if (specs.length === 0) return true;
42321
+ const changes = state.changes(specs);
42322
+ const lineStartInNew = changes.mapPos(state.doc.line(lineNumber).from, -1);
42323
+ const nextAnchor = Math.min(
42324
+ changes.newLength,
42325
+ Math.max(lineStartInNew + self2.quoteLen, changes.mapPos(range.head, -1))
42326
+ );
41718
42327
  view.dispatch({
41719
- changes: { from: bodyFrom, to: bodyFrom + self2.lead, insert: " ".repeat(lead) },
41720
- selection: { anchor: Math.max(bodyFrom + lead, range.head - (self2.lead - lead)) },
42328
+ changes,
42329
+ selection: { anchor: nextAnchor },
41721
42330
  scrollIntoView: true,
41722
42331
  userEvent: "input"
41723
42332
  });
41724
42333
  return true;
41725
42334
  }
41726
- function freshSublist(state, line, depth, self2) {
41727
- if (!self2.digits) return false;
41728
- for (let number2 = line.number - 1; number2 >= 1; number2--) {
41729
- const prev = state.doc.line(number2);
41730
- const prevQuote = QUOTE_PREFIX_RE$1.exec(prev.text)?.[0] ?? "";
41731
- if (countQuotes(prevQuote) !== self2.quoteDepth) break;
41732
- const rest = prev.text.slice(prevQuote.length);
41733
- if (rest.trim() === "") break;
41734
- const prevLine = parseListLine(prev.text);
41735
- if (!prevLine) {
41736
- if (/^[ \t]*/.exec(rest)[0].length > depth) continue;
42335
+ function indentMultiLineSelection(view, startLineNum, endLineNum, direction) {
42336
+ const { state } = view;
42337
+ const { tree, fmEnd } = getTreeAndFm(state);
42338
+ let firstListLine = -1;
42339
+ let firstParsed = null;
42340
+ for (let ln = startLineNum; ln <= endLineNum; ln++) {
42341
+ if (isExcludedLine(state.doc, tree, ln, fmEnd)) continue;
42342
+ const parsed = parseListLine(state.doc.line(ln).text);
42343
+ if (parsed) {
42344
+ firstListLine = ln;
42345
+ firstParsed = parsed;
41737
42346
  break;
41738
42347
  }
41739
- if (prevLine.lead === depth) return false;
41740
- if (prevLine.lead < depth) break;
41741
42348
  }
41742
- return true;
41743
- }
41744
- function parentItem(state, line, lead, quoteDepth) {
41745
- for (let number2 = line.number - 1; number2 >= 1; number2--) {
41746
- const prev = state.doc.line(number2);
41747
- const prevQuote = QUOTE_PREFIX_RE$1.exec(prev.text)?.[0] ?? "";
41748
- if (countQuotes(prevQuote) !== quoteDepth) return null;
41749
- const rest = prev.text.slice(prevQuote.length);
41750
- if (rest.trim() === "") return null;
41751
- const prevLine = parseListLine(prev.text);
41752
- if (prevLine) {
41753
- if (prevLine.lead <= lead) return prevLine;
41754
- continue;
42349
+ if (firstListLine < 0 || !firstParsed) return false;
42350
+ let indentStep = firstParsed.kind === "ordered" ? ORDERED_INDENT : BULLET_INDENT;
42351
+ if (direction === 1) {
42352
+ const block = scanListBlock(state.doc, firstListLine, tree, fmEnd);
42353
+ const parent = block ? findIndentParent(block, firstListLine, firstParsed.lead) : null;
42354
+ if (!parent) return true;
42355
+ const step = parent.parsed.kind === "ordered" ? ORDERED_INDENT : BULLET_INDENT;
42356
+ indentStep = Math.max(parent.parsed.lead + parent.parsed.markerWidth, parent.parsed.lead + step) - firstParsed.lead;
42357
+ if (indentStep <= 0) return true;
42358
+ }
42359
+ const specs = [];
42360
+ for (let ln = startLineNum; ln <= endLineNum; ln++) {
42361
+ if (isExcludedLine(state.doc, tree, ln, fmEnd)) continue;
42362
+ const line = state.doc.line(ln);
42363
+ const qLen = QUOTE_PREFIX_RE.exec(line.text)?.[0].length ?? 0;
42364
+ if (line.text.slice(qLen).trim() === "") continue;
42365
+ if (direction === 1) {
42366
+ const leadRaw = /^[ \t]*/.exec(line.text.slice(qLen))?.[0] ?? "";
42367
+ const edit = adjustLeadEdit(leadRaw, indentStep);
42368
+ const at = line.from + qLen;
42369
+ specs.push({ from: at, to: at + edit.removeChars, insert: edit.replaceWith });
42370
+ } else {
42371
+ const parsed = parseListLine(line.text);
42372
+ const step = parsed?.kind === "bullet" ? BULLET_INDENT : ORDERED_INDENT;
42373
+ const leadMatch = /^[ \t]*/.exec(line.text.slice(qLen))?.[0] ?? "";
42374
+ const edit = adjustLeadEdit(leadMatch, -step);
42375
+ if (edit.removeChars > 0 || edit.replaceWith !== "") {
42376
+ specs.push({ from: line.from + qLen, to: line.from + qLen + edit.removeChars, insert: edit.replaceWith });
42377
+ }
41755
42378
  }
41756
- if (/^[ \t]*/.exec(rest)[0].length <= lead) return null;
41757
42379
  }
41758
- return null;
42380
+ if (specs.length === 0) return true;
42381
+ const changes = state.changes(specs);
42382
+ const sel = state.selection.main;
42383
+ view.dispatch({
42384
+ changes,
42385
+ selection: EditorSelection.range(changes.mapPos(sel.anchor, 1), changes.mapPos(sel.head, 1)),
42386
+ scrollIntoView: true,
42387
+ userEvent: "input"
42388
+ });
42389
+ return true;
41759
42390
  }
41760
- const listInput = Prec.high(keymap.of([
41761
- { key: "Enter", run: handleEnter },
41762
- { key: "Backspace", run: deleteTaskBox },
41763
- { key: "Backspace", run: deleteAtLineStart },
41764
- { key: "Backspace", run: deleteMarkupBackward },
41765
- { key: "Tab", run: (view) => indentListItem(view, 1) },
41766
- { key: "Shift-Tab", run: (view) => indentListItem(view, -1) }
41767
- ]));
42391
+ function moveOrderedLineStart(view, select) {
42392
+ const { state } = view;
42393
+ if (state.selection.ranges.length > 1) return false;
42394
+ const range = state.selection.main;
42395
+ const { tree, fmEnd } = getTreeAndFm(state);
42396
+ const line = state.doc.lineAt(range.head);
42397
+ const self2 = isActiveOrderedListLine(state.doc, tree, line.number, fmEnd);
42398
+ if (!self2) return false;
42399
+ const boundary = view.moveToLineBoundary(range, false);
42400
+ if (boundary.head > line.from + self2.contentOffset) return false;
42401
+ const target = line.from + self2.contentOffset;
42402
+ view.dispatch({
42403
+ selection: select ? EditorSelection.range(range.anchor, target) : EditorSelection.cursor(target),
42404
+ scrollIntoView: true,
42405
+ userEvent: "select"
42406
+ });
42407
+ return true;
42408
+ }
42409
+ function moveOrderedLeft(view) {
42410
+ const { state } = view;
42411
+ if (state.selection.ranges.length > 1) return false;
42412
+ const range = state.selection.main;
42413
+ if (!range.empty) return false;
42414
+ const { tree, fmEnd } = getTreeAndFm(state);
42415
+ const line = state.doc.lineAt(range.head);
42416
+ const self2 = isActiveOrderedListLine(state.doc, tree, line.number, fmEnd);
42417
+ if (!self2) return false;
42418
+ const contentStart = line.from + self2.contentOffset;
42419
+ if (range.head > contentStart) return false;
42420
+ const target = line.number > 1 ? state.doc.line(line.number - 1).to : contentStart;
42421
+ view.dispatch({
42422
+ selection: EditorSelection.cursor(target),
42423
+ scrollIntoView: true,
42424
+ userEvent: "select"
42425
+ });
42426
+ return true;
42427
+ }
42428
+ function moveOrderedRight(view) {
42429
+ const { state } = view;
42430
+ if (state.selection.ranges.length > 1) return false;
42431
+ const range = state.selection.main;
42432
+ if (!range.empty) return false;
42433
+ const { tree, fmEnd } = getTreeAndFm(state);
42434
+ const line = state.doc.lineAt(range.head);
42435
+ if (range.head !== line.to || line.number >= state.doc.lines) return false;
42436
+ const nextLine = state.doc.line(line.number + 1);
42437
+ const nextSelf = isActiveOrderedListLine(state.doc, tree, nextLine.number, fmEnd);
42438
+ if (!nextSelf) return false;
42439
+ const target = nextLine.from + nextSelf.contentOffset;
42440
+ view.dispatch({
42441
+ selection: EditorSelection.cursor(target),
42442
+ scrollIntoView: true,
42443
+ userEvent: "select"
42444
+ });
42445
+ return true;
42446
+ }
42447
+ const orderedSelectionGuard = EditorState.transactionFilter.of((tr) => {
42448
+ if (tr.docChanged || !tr.selection) return tr;
42449
+ const event = tr.annotation(Transaction.userEvent);
42450
+ if (!event || !event.startsWith("select")) return tr;
42451
+ const doc2 = tr.startState.doc;
42452
+ const tree = syntaxTree(tr.startState);
42453
+ const fmEnd = frontmatterEnd(doc2);
42454
+ let changed = false;
42455
+ const nextRanges = tr.selection.ranges.map((r) => {
42456
+ if (!r.empty) return r;
42457
+ const line = doc2.lineAt(r.head);
42458
+ const self2 = isActiveOrderedListLine(doc2, tree, line.number, fmEnd);
42459
+ if (!self2) return r;
42460
+ const contentStart = line.from + self2.contentOffset;
42461
+ if (r.head >= contentStart) return r;
42462
+ changed = true;
42463
+ return EditorSelection.cursor(contentStart, r.assoc, r.bidiLevel ?? void 0, r.goalColumn);
42464
+ });
42465
+ if (!changed) return tr;
42466
+ return {
42467
+ selection: EditorSelection.create(nextRanges, tr.selection.mainIndex),
42468
+ effects: tr.effects,
42469
+ userEvent: event,
42470
+ scrollIntoView: tr.scrollIntoView
42471
+ };
42472
+ });
42473
+ const listInput = [
42474
+ orderedSelectionGuard,
42475
+ Prec.high(keymap.of([
42476
+ { key: "Enter", run: handleEnter },
42477
+ { key: "Shift-Enter", run: handleShiftEnter },
42478
+ { key: "Backspace", run: deleteTaskBox },
42479
+ { key: "Backspace", run: deleteAtLineStart },
42480
+ { key: "Backspace", run: deleteMarkupBackward },
42481
+ { key: "Tab", run: (view) => handleTab(view, 1) },
42482
+ { key: "Shift-Tab", run: (view) => handleTab(view, -1) },
42483
+ { key: "Home", run: (view) => moveOrderedLineStart(view, false) },
42484
+ { key: "Shift-Home", run: (view) => moveOrderedLineStart(view, true) },
42485
+ { key: "Mod-ArrowLeft", run: (view) => moveOrderedLineStart(view, false) },
42486
+ { key: "Shift-Mod-ArrowLeft", run: (view) => moveOrderedLineStart(view, true) },
42487
+ { key: "ArrowLeft", run: moveOrderedLeft },
42488
+ { key: "Alt-ArrowLeft", run: moveOrderedLeft },
42489
+ { key: "ArrowRight", run: moveOrderedRight }
42490
+ ]))
42491
+ ];
41768
42492
  const setSearchHighlight = StateEffect.define();
41769
42493
  const searchHighlightField = StateField.define({
41770
42494
  create: () => Decoration.none,
@@ -41780,7 +42504,7 @@ function legacy(parser2) {
41780
42504
  return new LanguageSupport(StreamLanguage.define(parser2));
41781
42505
  }
41782
42506
  function sql(dialectName) {
41783
- return __vitePreload(() => import("./index-CpAWIQHT.js"), true ? [] : void 0, import.meta.url).then((m) => m.sql({ dialect: m[dialectName] }));
42507
+ return __vitePreload(() => import("./index-DypVmFXi.js"), true ? [] : void 0, import.meta.url).then((m) => m.sql({ dialect: m[dialectName] }));
41784
42508
  }
41785
42509
  const languages = [
41786
42510
  // New-style language modes
@@ -41788,7 +42512,7 @@ const languages = [
41788
42512
  name: "C",
41789
42513
  extensions: ["c", "h", "ino"],
41790
42514
  load() {
41791
- return __vitePreload(() => import("./index-lPCBuTEj.js"), true ? [] : void 0, import.meta.url).then((m) => m.cpp());
42515
+ return __vitePreload(() => import("./index-B66yNs8z.js"), true ? [] : void 0, import.meta.url).then((m) => m.cpp());
41792
42516
  }
41793
42517
  }),
41794
42518
  /* @__PURE__ */ LanguageDescription.of({
@@ -41796,7 +42520,7 @@ const languages = [
41796
42520
  alias: ["cpp"],
41797
42521
  extensions: ["cpp", "c++", "cc", "cxx", "hpp", "h++", "hh", "hxx"],
41798
42522
  load() {
41799
- return __vitePreload(() => import("./index-lPCBuTEj.js"), true ? [] : void 0, import.meta.url).then((m) => m.cpp());
42523
+ return __vitePreload(() => import("./index-B66yNs8z.js"), true ? [] : void 0, import.meta.url).then((m) => m.cpp());
41800
42524
  }
41801
42525
  }),
41802
42526
  /* @__PURE__ */ LanguageDescription.of({
@@ -41818,7 +42542,7 @@ const languages = [
41818
42542
  name: "Go",
41819
42543
  extensions: ["go"],
41820
42544
  load() {
41821
- return __vitePreload(() => import("./index-Gr-12Gzq.js"), true ? [] : void 0, import.meta.url).then((m) => m.go());
42545
+ return __vitePreload(() => import("./index-CcwQz0gI.js"), true ? [] : void 0, import.meta.url).then((m) => m.go());
41822
42546
  }
41823
42547
  }),
41824
42548
  /* @__PURE__ */ LanguageDescription.of({
@@ -41833,7 +42557,7 @@ const languages = [
41833
42557
  name: "Java",
41834
42558
  extensions: ["java"],
41835
42559
  load() {
41836
- return __vitePreload(() => import("./index-BZK9uVRR.js"), true ? [] : void 0, import.meta.url).then((m) => m.java());
42560
+ return __vitePreload(() => import("./index-CTBBXEX2.js"), true ? [] : void 0, import.meta.url).then((m) => m.java());
41837
42561
  }
41838
42562
  }),
41839
42563
  /* @__PURE__ */ LanguageDescription.of({
@@ -41848,7 +42572,7 @@ const languages = [
41848
42572
  name: "Jinja",
41849
42573
  extensions: ["j2", "jinja", "jinja2"],
41850
42574
  load() {
41851
- return __vitePreload(() => import("./index-_-G3H01P.js"), true ? [] : void 0, import.meta.url).then((m) => m.jinja());
42575
+ return __vitePreload(() => import("./index-B-Tvkk_D.js"), true ? [] : void 0, import.meta.url).then((m) => m.jinja());
41852
42576
  }
41853
42577
  }),
41854
42578
  /* @__PURE__ */ LanguageDescription.of({
@@ -41856,7 +42580,7 @@ const languages = [
41856
42580
  alias: ["json5"],
41857
42581
  extensions: ["json", "map"],
41858
42582
  load() {
41859
- return __vitePreload(() => import("./index-DkTSflhI.js"), true ? [] : void 0, import.meta.url).then((m) => m.json());
42583
+ return __vitePreload(() => import("./index-D4NskBFS.js"), true ? [] : void 0, import.meta.url).then((m) => m.json());
41860
42584
  }
41861
42585
  }),
41862
42586
  /* @__PURE__ */ LanguageDescription.of({
@@ -41870,14 +42594,14 @@ const languages = [
41870
42594
  name: "LESS",
41871
42595
  extensions: ["less"],
41872
42596
  load() {
41873
- return __vitePreload(() => import("./index-D6i0AdBR.js"), true ? [] : void 0, import.meta.url).then((m) => m.less());
42597
+ return __vitePreload(() => import("./index-CJQRWrTj.js"), true ? [] : void 0, import.meta.url).then((m) => m.less());
41874
42598
  }
41875
42599
  }),
41876
42600
  /* @__PURE__ */ LanguageDescription.of({
41877
42601
  name: "Liquid",
41878
42602
  extensions: ["liquid"],
41879
42603
  load() {
41880
- return __vitePreload(() => import("./index-De7RE4Mo.js"), true ? [] : void 0, import.meta.url).then((m) => m.liquid());
42604
+ return __vitePreload(() => import("./index-Co-0vhM1.js"), true ? [] : void 0, import.meta.url).then((m) => m.liquid());
41881
42605
  }
41882
42606
  }),
41883
42607
  /* @__PURE__ */ LanguageDescription.of({
@@ -41909,7 +42633,7 @@ const languages = [
41909
42633
  name: "PHP",
41910
42634
  extensions: ["php", "php3", "php4", "php5", "php7", "phtml"],
41911
42635
  load() {
41912
- return __vitePreload(() => import("./index-qlWwPzMe.js"), true ? [] : void 0, import.meta.url).then((m) => m.php());
42636
+ return __vitePreload(() => import("./index-Ditiw7Uj.js"), true ? [] : void 0, import.meta.url).then((m) => m.php());
41913
42637
  }
41914
42638
  }),
41915
42639
  /* @__PURE__ */ LanguageDescription.of({
@@ -41930,28 +42654,28 @@ const languages = [
41930
42654
  extensions: ["BUILD", "bzl", "py", "pyw"],
41931
42655
  filename: /^(BUCK|BUILD)$/,
41932
42656
  load() {
41933
- return __vitePreload(() => import("./index-OOnbRmFx.js"), true ? [] : void 0, import.meta.url).then((m) => m.python());
42657
+ return __vitePreload(() => import("./index-rA_KpISM.js"), true ? [] : void 0, import.meta.url).then((m) => m.python());
41934
42658
  }
41935
42659
  }),
41936
42660
  /* @__PURE__ */ LanguageDescription.of({
41937
42661
  name: "Rust",
41938
42662
  extensions: ["rs"],
41939
42663
  load() {
41940
- return __vitePreload(() => import("./index-1hwQGecd.js"), true ? [] : void 0, import.meta.url).then((m) => m.rust());
42664
+ return __vitePreload(() => import("./index-DI9_AaWi.js"), true ? [] : void 0, import.meta.url).then((m) => m.rust());
41941
42665
  }
41942
42666
  }),
41943
42667
  /* @__PURE__ */ LanguageDescription.of({
41944
42668
  name: "Sass",
41945
42669
  extensions: ["sass"],
41946
42670
  load() {
41947
- return __vitePreload(() => import("./index-D9fcCIeQ.js"), true ? [] : void 0, import.meta.url).then((m) => m.sass({ indented: true }));
42671
+ return __vitePreload(() => import("./index-BUO7yV_Q.js"), true ? [] : void 0, import.meta.url).then((m) => m.sass({ indented: true }));
41948
42672
  }
41949
42673
  }),
41950
42674
  /* @__PURE__ */ LanguageDescription.of({
41951
42675
  name: "SCSS",
41952
42676
  extensions: ["scss"],
41953
42677
  load() {
41954
- return __vitePreload(() => import("./index-D9fcCIeQ.js"), true ? [] : void 0, import.meta.url).then((m) => m.sass());
42678
+ return __vitePreload(() => import("./index-BUO7yV_Q.js"), true ? [] : void 0, import.meta.url).then((m) => m.sass());
41955
42679
  }
41956
42680
  }),
41957
42681
  /* @__PURE__ */ LanguageDescription.of({
@@ -41986,7 +42710,7 @@ const languages = [
41986
42710
  name: "WebAssembly",
41987
42711
  extensions: ["wat", "wast"],
41988
42712
  load() {
41989
- return __vitePreload(() => import("./index-3SmJ-5Dc.js"), true ? [] : void 0, import.meta.url).then((m) => m.wast());
42713
+ return __vitePreload(() => import("./index-DEjGaOKF.js"), true ? [] : void 0, import.meta.url).then((m) => m.wast());
41990
42714
  }
41991
42715
  }),
41992
42716
  /* @__PURE__ */ LanguageDescription.of({
@@ -41994,7 +42718,7 @@ const languages = [
41994
42718
  alias: ["rss", "wsdl", "xsd"],
41995
42719
  extensions: ["xml", "xsl", "xsd", "svg"],
41996
42720
  load() {
41997
- return __vitePreload(() => import("./index-BqpGj9MR.js"), true ? [] : void 0, import.meta.url).then((m) => m.xml());
42721
+ return __vitePreload(() => import("./index-Cyi8NXI_.js"), true ? [] : void 0, import.meta.url).then((m) => m.xml());
41998
42722
  }
41999
42723
  }),
42000
42724
  /* @__PURE__ */ LanguageDescription.of({
@@ -42002,7 +42726,7 @@ const languages = [
42002
42726
  alias: ["yml"],
42003
42727
  extensions: ["yaml", "yml"],
42004
42728
  load() {
42005
- return __vitePreload(() => import("./index-BHqRO3CW.js"), true ? [] : void 0, import.meta.url).then((m) => m.yaml());
42729
+ return __vitePreload(() => import("./index-CipBATEm.js"), true ? [] : void 0, import.meta.url).then((m) => m.yaml());
42006
42730
  }
42007
42731
  }),
42008
42732
  // Legacy modes ported from CodeMirror 5
@@ -42791,13 +43515,13 @@ const languages = [
42791
43515
  name: "Vue",
42792
43516
  extensions: ["vue"],
42793
43517
  load() {
42794
- return __vitePreload(() => import("./index-CBD7Wlx8.js"), true ? [] : void 0, import.meta.url).then((m) => m.vue());
43518
+ return __vitePreload(() => import("./index-5TWFI5jV.js"), true ? [] : void 0, import.meta.url).then((m) => m.vue());
42795
43519
  }
42796
43520
  }),
42797
43521
  /* @__PURE__ */ LanguageDescription.of({
42798
43522
  name: "Angular Template",
42799
43523
  load() {
42800
- return __vitePreload(() => import("./index-B0zpPg3h.js"), true ? [] : void 0, import.meta.url).then((m) => m.angular());
43524
+ return __vitePreload(() => import("./index-pHq11714.js"), true ? [] : void 0, import.meta.url).then((m) => m.angular());
42801
43525
  }
42802
43526
  })
42803
43527
  ];
@@ -42856,205 +43580,271 @@ const editorTheme = EditorView.theme({
42856
43580
  ".cm-searchMatch": { backgroundColor: "var(--search-match-bg, color-mix(in srgb, var(--text-color) 16%, transparent))" },
42857
43581
  ".cm-searchMatch-selected": { backgroundColor: "var(--search-current-bg, color-mix(in srgb, var(--text-color) 26%, transparent))" }
42858
43582
  });
42859
- const QUOTE_PREFIX_RE = /^(?:[ \t]*> ?)+/;
42860
- const LIST_LINE = /^(?:[ \t]*> ?)*[ \t]*(?:[-*+]|\d+[.)])[ \t]/;
42861
- const INDENTED = /^(?:[ \t]*> ?)*[ \t]/;
42862
- const MAX_SCAN_LINES = 5e3;
43583
+ const EXCLUDED_NODES = /* @__PURE__ */ new Set(["FencedCode", "HTMLBlock", "Table", "CommentBlock"]);
43584
+ const FULL_PARSE_LIMIT = 65536;
43585
+ const WINDOW_PAD_LINES = 128;
42863
43586
  let patching = false;
42864
- const renumberLists = EditorState.transactionFilter.of((tr) => {
42865
- if (!tr.docChanged) return tr;
42866
- const event = tr.annotation(Transaction.userEvent);
42867
- if (!event || event.startsWith("undo") || event.startsWith("redo")) return tr;
42868
- const before = syntaxTree(tr.startState);
42869
- if (!touchesOrderedList(before, tr.changes)) return tr;
42870
- const { oldRange, newRange } = affectedRanges(tr, before);
42871
- const beforeSlice = tr.startState.doc.sliceString(oldRange.from, oldRange.to);
42872
- const oldLists = orderedLists(markdownParser.parse(beforeSlice), beforeSlice);
42873
- const slice = tr.newDoc.sliceString(newRange.from, newRange.to);
42874
- const changes = [];
42875
- for (const list of orderedLists(markdownParser.parse(slice), slice)) {
42876
- const plan = renumberPlan(list, oldLists, tr.changes, newRange.from, oldRange.from);
42877
- if (!plan.run) continue;
42878
- const start = plan.resetToOne ? 1 : Number.parseInt(slice.slice(list.marks[0].from, list.marks[0].to), 10);
42879
- if (!Number.isFinite(start)) continue;
42880
- list.marks.forEach((mark, index2) => {
42881
- const now = slice.slice(mark.from, mark.to);
42882
- const want = `${start + index2}${now.endsWith(")") ? ")" : "."}`;
42883
- if (now !== want) changes.push({ from: newRange.from + mark.from, to: newRange.from + mark.to, insert: want });
42884
- });
42885
- }
42886
- if (changes.length === 0) return tr;
42887
- if (patching) return tr;
42888
- const patch = ChangeSet.of(changes, tr.newDoc.length);
42889
- patching = true;
42890
- try {
42891
- return tr.startState.update({
42892
- changes: tr.changes.compose(patch),
42893
- selection: tr.selection ? tr.selection.map(patch) : void 0,
42894
- effects: tr.effects,
42895
- // `Transaction.annotations` 不是公开字段,这里只把 userEvent 传下去:
42896
- // 撤销分组和「这是一次编辑」的语义都靠它
42897
- userEvent: event,
42898
- scrollIntoView: tr.scrollIntoView
42899
- });
42900
- } finally {
42901
- patching = false;
42902
- }
42903
- });
42904
- function itemHasLazyBreak(item, slice) {
42905
- let ownEnd = item.to;
42906
- for (let child = item.firstChild; child; child = child.nextSibling) {
42907
- if (child.name === "BulletList" || child.name === "OrderedList") {
42908
- ownEnd = child.from;
42909
- break;
43587
+ function createRenumberLists(parser2) {
43588
+ return EditorState.transactionFilter.of((tr) => {
43589
+ if (!tr.docChanged || patching) return tr;
43590
+ const event = tr.annotation(Transaction.userEvent);
43591
+ if (!event || event.startsWith("undo") || event.startsWith("redo") || event.includes("compose")) return tr;
43592
+ const oldDoc = tr.startState.doc;
43593
+ const newDoc = tr.newDoc;
43594
+ const oldTree = syntaxTree(tr.startState);
43595
+ const oldFmEnd = frontmatterEnd(oldDoc);
43596
+ const newFmEnd = frontmatterEnd(newDoc);
43597
+ const oldSeedLines = collectSeedLines(oldDoc, tr.changes, true);
43598
+ const newSeedLines = collectSeedLines(newDoc, tr.changes, false);
43599
+ const hasOldOrdered = oldSeedLines.some(
43600
+ (n) => parseListLine(oldDoc.line(n).text)?.kind === "ordered" && !isExcludedLine(oldDoc, oldTree, n, oldFmEnd)
43601
+ );
43602
+ const hasNewOrderedCandidate = newSeedLines.some(
43603
+ (n) => parseListLine(newDoc.line(n).text)?.kind === "ordered"
43604
+ );
43605
+ if (!hasOldOrdered && !hasNewOrderedCandidate) return tr;
43606
+ const isExcludedInNew = buildNewDocExcluder(newDoc, newSeedLines, newFmEnd, parser2);
43607
+ const hasNewOrdered = hasNewOrderedCandidate && newSeedLines.some((n) => parseListLine(newDoc.line(n).text)?.kind === "ordered" && !isExcludedInNew(n));
43608
+ if (!hasOldOrdered && !hasNewOrdered) return tr;
43609
+ const oldBlocks = collectBlocks(oldDoc, oldSeedLines, oldTree, oldFmEnd);
43610
+ const oldRefByNewLine = mapSurvivingOldItems(oldBlocks, tr.changes, newDoc);
43611
+ const newBlocks = collectNewBlocks(newDoc, newSeedLines, newFmEnd, isExcludedInNew);
43612
+ if (newBlocks.length === 0) return tr;
43613
+ const markChanges = /* @__PURE__ */ new Map();
43614
+ const indentAddByLine = /* @__PURE__ */ new Map();
43615
+ for (const block of newBlocks) {
43616
+ for (const group of block.orderedGroups) {
43617
+ const plan = decideGroupRenumber(group, oldRefByNewLine);
43618
+ if (!plan.run) continue;
43619
+ const start = plan.start;
43620
+ group.items.forEach((item, idx) => {
43621
+ const line = newDoc.line(item.lineNumber);
43622
+ const wantDigits = String(start + idx);
43623
+ const wantMark = `${wantDigits}${item.parsed.delim}`;
43624
+ const currentDigits = item.parsed.digits;
43625
+ if (wantDigits !== currentDigits) {
43626
+ markChanges.set(item.lineNumber, {
43627
+ from: line.from + item.parsed.markerStart,
43628
+ to: line.from + item.parsed.markerEnd,
43629
+ insert: wantMark
43630
+ });
43631
+ }
43632
+ const ownAdded = indentAddByLine.get(item.lineNumber) ?? 0;
43633
+ const grew = wantDigits.length > currentDigits.length || ownAdded > 0;
43634
+ if (grew && item.subtreeEndLine > item.lineNumber) {
43635
+ const spacesRaw = line.text.slice(item.parsed.markerEnd, item.parsed.spaceEnd);
43636
+ const newParentLead = item.parsed.lead + ownAdded;
43637
+ const newMarkerWidth = wantMark.length + expandIndent(spacesRaw, newParentLead + wantMark.length);
43638
+ const minChildCol = newParentLead + newMarkerWidth;
43639
+ let minDirectChildLead = Infinity;
43640
+ const itemIdx = block.itemIndexByLine.get(item.lineNumber);
43641
+ if (itemIdx !== void 0) {
43642
+ for (let j = itemIdx + 1; j < block.items.length; j++) {
43643
+ const candidate = block.items[j];
43644
+ if (candidate.depth <= item.depth) break;
43645
+ if (candidate.parentLine === item.lineNumber) {
43646
+ const candLead = candidate.parsed.lead + (indentAddByLine.get(candidate.lineNumber) ?? 0);
43647
+ if (candLead < minDirectChildLead) minDirectChildLead = candLead;
43648
+ }
43649
+ }
43650
+ }
43651
+ if (Number.isFinite(minDirectChildLead) && minDirectChildLead < minChildCol) {
43652
+ const delta = minChildCol - minDirectChildLead;
43653
+ for (let ln = item.lineNumber + 1; ln <= item.subtreeEndLine; ln++) {
43654
+ indentAddByLine.set(ln, (indentAddByLine.get(ln) ?? 0) + delta);
43655
+ }
43656
+ }
43657
+ }
43658
+ });
43659
+ }
42910
43660
  }
42911
- }
42912
- const lines = slice.slice(item.from, ownEnd).split("\n");
42913
- for (let i = 1; i < lines.length; i++) {
42914
- const body = lines[i].replace(QUOTE_PREFIX_RE, "");
42915
- if (body.trim() !== "" && !/^[ \t]/.test(body)) return true;
42916
- }
42917
- return false;
42918
- }
42919
- function orderedLists(tree, slice) {
42920
- const lists = [];
42921
- tree.iterate({
42922
- enter(node) {
42923
- if (node.name !== "OrderedList") return;
42924
- let marks = [];
42925
- let segFrom = node.from;
42926
- let segTo = node.from;
42927
- let splitFromAbove = false;
42928
- const flush = (nextSplit) => {
42929
- if (marks.length > 0) lists.push({ from: segFrom, to: segTo, splitFromAbove, marks });
42930
- marks = [];
42931
- if (nextSplit) splitFromAbove = true;
42932
- };
42933
- for (let item = node.node.firstChild; item; item = item.nextSibling) {
42934
- if (item.name !== "ListItem") continue;
42935
- const mark = item.getChild("ListMark");
42936
- if (!mark) continue;
42937
- const after = slice[mark.to];
42938
- if (after !== " " && after !== " ") continue;
42939
- if (marks.length === 0) segFrom = item.from;
42940
- marks.push({ from: mark.from, to: mark.to });
42941
- segTo = item.to;
42942
- if (itemHasLazyBreak(item, slice)) flush(true);
42943
- }
42944
- flush(false);
43661
+ if (markChanges.size === 0 && indentAddByLine.size === 0) return tr;
43662
+ const changes = [];
43663
+ const affectedLines = /* @__PURE__ */ new Set([...markChanges.keys(), ...indentAddByLine.keys()]);
43664
+ const sortedLines = [...affectedLines].sort((a, b) => a - b);
43665
+ for (const ln of sortedLines) {
43666
+ const line = newDoc.line(ln);
43667
+ const addSpaces = indentAddByLine.get(ln) ?? 0;
43668
+ if (addSpaces > 0) {
43669
+ const quoteLen = QUOTE_PREFIX_RE.exec(line.text)?.[0].length ?? 0;
43670
+ const leadRaw = /^[ \t]*/.exec(line.text.slice(quoteLen))?.[0] ?? "";
43671
+ const edit = adjustLeadEdit(leadRaw, addSpaces);
43672
+ const at = line.from + quoteLen;
43673
+ changes.push({ from: at, to: at + edit.removeChars, insert: edit.replaceWith });
43674
+ }
43675
+ const mc = markChanges.get(ln);
43676
+ if (mc) changes.push(mc);
43677
+ }
43678
+ if (changes.length === 0) return tr;
43679
+ const patch = ChangeSet.of(changes, newDoc.length);
43680
+ patching = true;
43681
+ try {
43682
+ return tr.startState.update({
43683
+ changes: tr.changes.compose(patch),
43684
+ // assoc=1:光标贴在序号后面(如 `1. |`)时,序号变宽(如变成 `10. `)后光标仍留在空格后
43685
+ selection: tr.selection ? tr.selection.map(patch, 1) : void 0,
43686
+ effects: tr.effects,
43687
+ userEvent: event,
43688
+ scrollIntoView: tr.scrollIntoView
43689
+ });
43690
+ } finally {
43691
+ patching = false;
42945
43692
  }
42946
43693
  });
42947
- return lists;
42948
- }
42949
- function touchesOrderedList(tree, changes) {
42950
- let hit = false;
42951
- changes.iterChangedRanges((fromA, toA) => {
42952
- if (hit) return;
42953
- const last2 = Math.max(fromA, toA - 1);
42954
- for (const [pos, side] of [[fromA, -1], [fromA, 1], [last2, -1], [last2, 1]]) {
42955
- if (enclosingOrderedList(tree, pos, side)) {
42956
- hit = true;
42957
- return;
43694
+ }
43695
+ function collectSeedLines(doc2, changes, isOld) {
43696
+ const lines = /* @__PURE__ */ new Set();
43697
+ changes.iterChangedRanges((fromA, toA, fromB, toB) => {
43698
+ const from = isOld ? fromA : fromB;
43699
+ const to = isOld ? toA : toB;
43700
+ const startLine = Math.max(1, doc2.lineAt(Math.min(from, doc2.length)).number - 1);
43701
+ const endLine = Math.min(doc2.lines, doc2.lineAt(Math.min(to, doc2.length)).number + 1);
43702
+ for (let n = startLine; n <= endLine; n++) lines.add(n);
43703
+ });
43704
+ return [...lines].sort((a, b) => a - b);
43705
+ }
43706
+ function buildNewDocExcluder(newDoc, seedLines, newFmEnd, parser2) {
43707
+ let sliceFrom = 0;
43708
+ let sliceTo = newDoc.length;
43709
+ if (newDoc.length > FULL_PARSE_LIMIT && seedLines.length > 0) {
43710
+ const minLine = Math.max(1, seedLines[0] - WINDOW_PAD_LINES);
43711
+ const maxLine = Math.min(newDoc.lines, seedLines[seedLines.length - 1] + WINDOW_PAD_LINES);
43712
+ sliceFrom = newDoc.line(minLine).from;
43713
+ sliceTo = newDoc.line(maxLine).to;
43714
+ }
43715
+ const tree = parser2.parse(newDoc.sliceString(sliceFrom, sliceTo));
43716
+ const cache2 = /* @__PURE__ */ new Map();
43717
+ return (lineNumber) => {
43718
+ const hit = cache2.get(lineNumber);
43719
+ if (hit !== void 0) return hit;
43720
+ const line = newDoc.line(lineNumber);
43721
+ let excluded = false;
43722
+ if (newFmEnd >= 0 && line.from <= newFmEnd) {
43723
+ excluded = true;
43724
+ } else if (line.from >= sliceFrom && line.from <= sliceTo) {
43725
+ const qLen = QUOTE_PREFIX_RE.exec(line.text)?.[0].length ?? 0;
43726
+ const probe = Math.min(line.to, line.from + qLen) - sliceFrom;
43727
+ let node = tree.resolveInner(Math.min(Math.max(0, probe), tree.length), 1);
43728
+ while (node) {
43729
+ if (EXCLUDED_NODES.has(node.name)) {
43730
+ excluded = true;
43731
+ break;
43732
+ }
43733
+ node = node.parent;
42958
43734
  }
42959
43735
  }
42960
- });
42961
- return hit;
43736
+ cache2.set(lineNumber, excluded);
43737
+ return excluded;
43738
+ };
42962
43739
  }
42963
- function enclosingOrderedList(tree, pos, side) {
42964
- let node = tree.resolveInner(Math.min(Math.max(pos, 0), tree.length), side);
42965
- while (node) {
42966
- if (node.name === "OrderedList") return node;
42967
- node = node.parent;
43740
+ function collectBlocks(doc2, seedLines, tree, fmEnd) {
43741
+ const blocks = [];
43742
+ let coveredUntil = 0;
43743
+ for (const ln of seedLines) {
43744
+ if (ln <= coveredUntil) continue;
43745
+ const block = scanListBlock(doc2, ln, tree, fmEnd);
43746
+ if (!block) continue;
43747
+ blocks.push(block);
43748
+ coveredUntil = block.endLine;
42968
43749
  }
42969
- return null;
43750
+ return blocks;
42970
43751
  }
42971
- function affectedRanges(tr, before) {
42972
- let first = -1;
42973
- tr.changes.iterChangedRanges((fromA) => {
42974
- if (first < 0) first = fromA;
42975
- });
42976
- if (first < 0) {
42977
- return {
42978
- oldRange: { from: 0, to: tr.startState.doc.length },
42979
- newRange: { from: 0, to: tr.newDoc.length }
42980
- };
43752
+ function collectNewBlocks(newDoc, seedLines, newFmEnd, isExcludedInNew) {
43753
+ const blocks = [];
43754
+ let coveredUntil = 0;
43755
+ for (const ln of seedLines) {
43756
+ if (ln <= coveredUntil) continue;
43757
+ const block = scanListBlock(newDoc, ln, null, newFmEnd, isExcludedInNew);
43758
+ if (!block) continue;
43759
+ blocks.push(block);
43760
+ coveredUntil = block.endLine;
42981
43761
  }
42982
- let block = before.resolveInner(first, 1);
42983
- while (block && block.parent && block.parent.name !== "Document") block = block.parent;
42984
- const oldBase = block ? block.from : first;
42985
- const oldFrom = tr.startState.doc.lineAt(Math.min(Math.max(oldBase, 0), tr.startState.doc.length)).from;
42986
- const oldTo = listClusterEnd(tr.startState.doc, oldFrom);
42987
- const mapped = tr.changes.mapPos(oldBase, -1);
42988
- const newFrom = tr.newDoc.lineAt(Math.min(Math.max(mapped, 0), tr.newDoc.length)).from;
42989
- const newTo = listClusterEnd(tr.newDoc, newFrom);
42990
- return {
42991
- oldRange: { from: oldFrom, to: oldTo },
42992
- newRange: { from: newFrom, to: newTo }
42993
- };
43762
+ return blocks;
42994
43763
  }
42995
- function listClusterEnd(doc2, from) {
42996
- const first = doc2.lineAt(from);
42997
- let end = first.to;
42998
- let blank = false;
42999
- const stop = Math.min(doc2.lines, first.number + MAX_SCAN_LINES);
43000
- for (let number2 = first.number + 1; number2 <= stop; number2++) {
43001
- const line = doc2.line(number2);
43002
- const stripped = line.text.replace(QUOTE_PREFIX_RE, "");
43003
- if (stripped.trim() === "") {
43004
- blank = true;
43005
- end = line.to;
43006
- continue;
43764
+ function mapSurvivingOldItems(oldBlocks, changes, newDoc) {
43765
+ const map = /* @__PURE__ */ new Map();
43766
+ for (const block of oldBlocks) {
43767
+ for (const group of block.orderedGroups) {
43768
+ group.items.forEach((item, indexInGroup) => {
43769
+ const markFrom = item.lineFrom + item.parsed.markerStart;
43770
+ const markTo = item.lineFrom + item.parsed.markerEnd;
43771
+ if (wasItemDestroyed(changes, item, markFrom, markTo)) return;
43772
+ const mappedPos = changes.mapPos(markFrom, 1);
43773
+ if (mappedPos > newDoc.length) return;
43774
+ const newLine = newDoc.lineAt(mappedPos);
43775
+ const newParsed = parseListLine(newLine.text);
43776
+ if (!newParsed || newParsed.kind !== "ordered") return;
43777
+ const minOk = newLine.from + newParsed.quoteLen;
43778
+ const maxOk = newLine.from + newParsed.contentOffset;
43779
+ if (mappedPos < minOk || mappedPos > maxOk) return;
43780
+ if (!map.has(newLine.number)) {
43781
+ map.set(newLine.number, { item, group, indexInGroup });
43782
+ }
43783
+ });
43007
43784
  }
43008
- if (blank && !LIST_LINE.test(line.text) && !INDENTED.test(line.text)) break;
43009
- blank = false;
43010
- end = line.to;
43011
43785
  }
43012
- return end;
43786
+ return map;
43013
43787
  }
43014
- function renumberPlan(list, oldLists, changes, newOffset, oldOffset) {
43015
- const listNewFrom = newOffset + list.from;
43016
- const listNewTo = newOffset + list.to;
43017
- const old = oldLists.find((item) => {
43018
- const mappedFrom = changes.mapPos(oldOffset + item.from, 1);
43019
- const mappedTo = changes.mapPos(oldOffset + item.to, -1);
43020
- return mappedTo >= listNewFrom && mappedFrom <= listNewTo;
43788
+ function wasItemDestroyed(changes, item, markFrom, markTo) {
43789
+ let destroyed = false;
43790
+ changes.iterChangedRanges((fromA, toA, fromB, toB) => {
43791
+ if (destroyed) return;
43792
+ if (fromA <= markFrom && toA >= markTo) {
43793
+ if (toB === fromB || fromA < item.lineFrom || toA > item.lineTo) {
43794
+ destroyed = true;
43795
+ }
43796
+ }
43021
43797
  });
43022
- if (list.splitFromAbove && old) {
43023
- const oldFirstMapped = changes.mapPos(oldOffset + old.marks[0].from, 1);
43024
- if (oldFirstMapped < newOffset + list.marks[0].from) {
43025
- return { run: true, resetToOne: true };
43798
+ return destroyed;
43799
+ }
43800
+ function decideGroupRenumber(group, oldRefByNewLine) {
43801
+ const refs = group.items.map((item) => oldRefByNewLine.get(item.lineNumber) ?? null);
43802
+ const firstRef = refs[0];
43803
+ let needsRenumber = false;
43804
+ const distinctOldGroups = /* @__PURE__ */ new Set();
43805
+ for (let i = 0; i < group.items.length; i++) {
43806
+ const item = group.items[i];
43807
+ const ref = refs[i];
43808
+ if (!ref) {
43809
+ needsRenumber = true;
43810
+ continue;
43811
+ }
43812
+ distinctOldGroups.add(ref.group);
43813
+ if (ref.item.depth !== item.depth) {
43814
+ needsRenumber = true;
43815
+ }
43816
+ if (ref.item.parsed.digits !== item.parsed.digits || ref.item.parsed.delim !== item.parsed.delim) {
43817
+ needsRenumber = true;
43026
43818
  }
43027
43819
  }
43028
- let touchedThisSegment = false;
43029
- changes.iterChangedRanges((_fromA, _toA, fromB, toB) => {
43030
- if (toB >= listNewFrom - 1 && fromB <= listNewTo + 1) touchedThisSegment = true;
43031
- });
43032
- if (!touchedThisSegment) return { run: false, resetToOne: false };
43033
- if (!old) return { run: true, resetToOne: false };
43034
- if (old.marks.length !== list.marks.length) return { run: true, resetToOne: false };
43035
- return { run: touchedMark(changes, old, oldOffset), resetToOne: false };
43036
- }
43037
- function touchedMark(changes, list, oldOffset) {
43038
- let hit = false;
43039
- changes.iterChangedRanges((fromA, toA) => {
43040
- if (hit) return;
43041
- for (const raw of list.marks) {
43042
- const markFrom = oldOffset + raw.from;
43043
- const markTo = oldOffset + raw.to;
43044
- if (fromA <= markFrom && toA >= markFrom) {
43045
- hit = true;
43046
- return;
43047
- }
43048
- if (fromA < markTo && toA > markFrom) {
43049
- hit = true;
43050
- return;
43820
+ if (!needsRenumber) {
43821
+ if (distinctOldGroups.size !== 1) {
43822
+ needsRenumber = true;
43823
+ } else {
43824
+ const [onlyOldGroup] = distinctOldGroups;
43825
+ if (onlyOldGroup.items.length !== group.items.length) {
43826
+ needsRenumber = true;
43051
43827
  }
43052
43828
  }
43053
- });
43054
- return hit;
43829
+ }
43830
+ if (!needsRenumber) return { run: false, start: 1 };
43831
+ if (firstRef) {
43832
+ const firstItem = group.items[0];
43833
+ if (firstRef.indexInGroup > 0) {
43834
+ return { run: true, start: 1 };
43835
+ }
43836
+ if (firstItem.depth > firstRef.item.depth) {
43837
+ return { run: true, start: 1 };
43838
+ }
43839
+ }
43840
+ const parsedStart = Number.parseInt(group.items[0].parsed.digits, 10);
43841
+ return { run: true, start: Number.isFinite(parsedStart) && parsedStart >= 0 ? parsedStart : 1 };
43055
43842
  }
43056
43843
  const editableCompartment = new Compartment();
43057
- const markdownParser = commonmarkLanguage.parser.configure([GFM]);
43844
+ const markdownParser = commonmarkLanguage.parser.configure([
43845
+ GFM,
43846
+ { remove: ["SetextHeading"] }
43847
+ ]);
43058
43848
  const markdownBase = new Language(
43059
43849
  commonmarkLanguage.data,
43060
43850
  // `Language` 只把 parser 当 CodeMirror 自己的 Parser 接口看,不带 configure;
@@ -43072,7 +43862,7 @@ function stateExtensions() {
43072
43862
  // 看着像渲染故障。查找替换的高亮是 search 扩展自己的,不在这里。
43073
43863
  // 增删有序列表项时把序号排一遍(见 list-renumber.ts)。它是**写文件**的一层,
43074
43864
  // 所以只认用户自己的编辑,打开文件、外部写入、导出都不碰。
43075
- renumberLists,
43865
+ createRenumberLists(markdownParser),
43076
43866
  // markdown 语言支持 + 语法高亮(颜色走 CSS 变量,深浅主题自动跟随)
43077
43867
  markdown({ base: markdownBase, codeLanguages: languages, addKeymap: false }),
43078
43868
  syntaxHighlighting(markdownHighlightStyle),
@@ -43133,27 +43923,627 @@ const cursorColors = [
43133
43923
  return classes.length ? { class: classes.join(" ") } : {};
43134
43924
  })
43135
43925
  ];
43926
+ const LAYOUT_RE = /^<!--\s*slide\s*:\s*([a-z][a-z0-9-]*)\b([\s\S]*?)-->$/;
43927
+ const DECK_BLOCK_RE = /^<!--\s*deck(?:\s+([\s\S]*?))?-->$/;
43928
+ const PAGE_FIELD_RE = /^([a-z][a-z0-9-]*)\s*:\s*(.+)$/;
43929
+ const PAGE_FIELD_KEYS = /* @__PURE__ */ new Set(["kicker", "label", "chapter"]);
43930
+ const DECK_FIELD_KEYS = /* @__PURE__ */ new Set(["logo", "brand", "title", "meta"]);
43931
+ const CSS_RE = /^<!--\s*slide-css\b\s*([\s\S]*?)-->$/;
43932
+ const JS_RE = /^<!--\s*slide-js\b\s*([\s\S]*?)-->$/;
43933
+ const PAGE_KEY_RE = /^<!--\s*slide-(kicker|label|chapter)\s*:\s*([\s\S]*?)-->$/;
43934
+ const DECK_RE = /^<!--\s*deck-(logo|brand|title|meta)\s*:\s*([\s\S]*?)-->$/;
43935
+ function inRange(range, at) {
43936
+ return at >= range.from && at < range.to;
43937
+ }
43938
+ function iterateContent(state, front, enter) {
43939
+ syntaxTree(state).iterate({
43940
+ enter: (node) => {
43941
+ if (front && node.name !== "Document" && inRange(front, node.from)) return false;
43942
+ return enter(node);
43943
+ }
43944
+ });
43945
+ }
43946
+ function pageOfLines(state, front) {
43947
+ const breaks = [];
43948
+ iterateContent(state, front, (node) => {
43949
+ if (node.name !== "HorizontalRule") return;
43950
+ breaks.push(state.doc.lineAt(node.from).number);
43951
+ });
43952
+ const pageOf = new Array(state.doc.lines);
43953
+ let page = 0;
43954
+ let nextBreak = 0;
43955
+ for (let n = 1; n <= state.doc.lines; n++) {
43956
+ pageOf[n - 1] = page;
43957
+ if (nextBreak < breaks.length && breaks[nextBreak] === n) {
43958
+ page++;
43959
+ nextBreak++;
43960
+ }
43961
+ }
43962
+ return pageOf;
43963
+ }
43964
+ function firstContentLines(state, pageOf, commentLines) {
43965
+ const first = /* @__PURE__ */ new Map();
43966
+ for (let n = 1; n <= state.doc.lines; n++) {
43967
+ const page = pageOf[n - 1];
43968
+ if (first.has(page)) continue;
43969
+ if (state.doc.line(n).text.trim() === "") continue;
43970
+ if (/^ {0,3}(?:---|\*\*\*|___)\s*$/.test(state.doc.line(n).text)) continue;
43971
+ if (commentLines.has(n)) continue;
43972
+ first.set(page, n);
43973
+ }
43974
+ return first;
43975
+ }
43976
+ function lineRange(fromLine, toLine) {
43977
+ const lines = [];
43978
+ for (let n = fromLine; n <= toLine; n++) lines.push(n);
43979
+ return lines;
43980
+ }
43981
+ function isNestedBlock(node) {
43982
+ let parent = node.node.parent;
43983
+ while (parent) {
43984
+ if (parent.name === "ListItem" || parent.name === "Blockquote" || parent.name === "Table") return true;
43985
+ parent = parent.parent;
43986
+ }
43987
+ return false;
43988
+ }
43989
+ function collectRoles(state, front, pageOf, directives) {
43990
+ const headings = /* @__PURE__ */ new Map();
43991
+ const paragraphs = /* @__PURE__ */ new Map();
43992
+ iterateContent(state, front, (node) => {
43993
+ const isHeading2 = /^ATXHeading[1-6]$/.test(node.name);
43994
+ if (!isHeading2 && node.name !== "Paragraph") return;
43995
+ if (isNestedBlock(node)) return;
43996
+ const fromLine = state.doc.lineAt(node.from).number;
43997
+ const toLine = state.doc.lineAt(Math.max(node.from, node.to - 1)).number;
43998
+ const page = pageOf[fromLine - 1];
43999
+ const range = { from: node.from, to: node.to, fromLine, toLine };
44000
+ if (isHeading2) {
44001
+ if (!headings.has(page)) headings.set(page, range);
44002
+ return;
44003
+ }
44004
+ const list = paragraphs.get(page);
44005
+ if (list) list.push(range);
44006
+ else paragraphs.set(page, [range]);
44007
+ });
44008
+ const roles = /* @__PURE__ */ new Map();
44009
+ for (const [page, heading2] of headings) {
44010
+ const paras = paragraphs.get(page) ?? [];
44011
+ const lead = paras.find((p) => p.from > heading2.to);
44012
+ const before = paras.filter((p) => p.to < heading2.from).pop();
44013
+ const role = {
44014
+ titleLines: lineRange(heading2.fromLine, heading2.toLine),
44015
+ leadLines: lead ? lineRange(lead.fromLine, lead.toLine) : [],
44016
+ kickerLines: []
44017
+ };
44018
+ const dirs = directives.get(page);
44019
+ if (!dirs?.kicker && before) {
44020
+ const text2 = state.doc.lineAt(before.from).text.trim();
44021
+ if (text2) {
44022
+ ensure(directives, page).kicker = text2;
44023
+ role.kickerLines = lineRange(before.fromLine, before.toLine);
44024
+ }
44025
+ }
44026
+ roles.set(page, role);
44027
+ }
44028
+ return roles;
44029
+ }
44030
+ function applyFields(source, keys2, apply) {
44031
+ for (const raw of source.split("\n")) {
44032
+ const line = raw.trim();
44033
+ if (!line) continue;
44034
+ const hit = PAGE_FIELD_RE.exec(line);
44035
+ if (!hit || !keys2.has(hit[1])) continue;
44036
+ const value = hit[2].replace(/-->\s*$/, "").trim();
44037
+ if (value) apply(hit[1], value);
44038
+ }
44039
+ }
44040
+ function scanSlideDirectives(state) {
44041
+ const text2 = state.doc.toString();
44042
+ const front = frontmatterRange(text2);
44043
+ const pageOf = pageOfLines(state, front);
44044
+ const directives = /* @__PURE__ */ new Map();
44045
+ const linesByPage = /* @__PURE__ */ new Map();
44046
+ const directiveLines = [];
44047
+ const deck = {};
44048
+ const comments = [];
44049
+ const commentLines = /* @__PURE__ */ new Set();
44050
+ for (let n = 1; n <= state.doc.lines; n++) {
44051
+ const page = pageOf[n - 1];
44052
+ const list = linesByPage.get(page);
44053
+ if (list) list.push(n);
44054
+ else linesByPage.set(page, [n]);
44055
+ }
44056
+ iterateContent(state, front, (node) => {
44057
+ if (node.name !== "CommentBlock" && node.name !== "HTMLBlock") return;
44058
+ const source = state.doc.sliceString(node.from, node.to).trim();
44059
+ if (!source.startsWith("<!--")) return;
44060
+ const fromLine = state.doc.lineAt(node.from).number;
44061
+ const toLine = state.doc.lineAt(Math.max(node.from, node.to - 1)).number;
44062
+ comments.push({ source, from: node.from, to: node.to, fromLine, toLine, page: pageOf[fromLine - 1] });
44063
+ for (let n = fromLine; n <= toLine; n++) commentLines.add(n);
44064
+ });
44065
+ const firstContent = firstContentLines(state, pageOf, commentLines);
44066
+ for (const comment2 of comments) {
44067
+ const { source, fromLine, toLine, page } = comment2;
44068
+ const layout2 = LAYOUT_RE.exec(source);
44069
+ if (layout2) {
44070
+ pushAll(directiveLines, fromLine, toLine);
44071
+ const content2 = firstContent.get(page);
44072
+ if (content2 === void 0 || fromLine < content2) {
44073
+ const dirs = ensure(directives, page);
44074
+ dirs.layout = layout2[1];
44075
+ applyFields(layout2[2], PAGE_FIELD_KEYS, (key, value) => {
44076
+ dirs[key] = value;
44077
+ });
44078
+ }
44079
+ continue;
44080
+ }
44081
+ const deckBlock = DECK_BLOCK_RE.exec(source);
44082
+ if (deckBlock) {
44083
+ pushAll(directiveLines, fromLine, toLine);
44084
+ applyFields(deckBlock[1] ?? "", DECK_FIELD_KEYS, (key, value) => {
44085
+ deck[key] = value;
44086
+ });
44087
+ continue;
44088
+ }
44089
+ const pageKey = PAGE_KEY_RE.exec(source);
44090
+ if (pageKey) {
44091
+ pushAll(directiveLines, fromLine, toLine);
44092
+ ensure(directives, page)[pageKey[1]] = pageKey[2].replace(/\s+/g, " ").trim();
44093
+ continue;
44094
+ }
44095
+ const deckHit = DECK_RE.exec(source);
44096
+ if (deckHit) {
44097
+ pushAll(directiveLines, fromLine, toLine);
44098
+ deck[deckHit[1]] = deckHit[2].trim();
44099
+ continue;
44100
+ }
44101
+ const css2 = CSS_RE.exec(source);
44102
+ if (css2) {
44103
+ pushAll(directiveLines, fromLine, toLine);
44104
+ ensure(directives, page).css.push(css2[1].trim());
44105
+ continue;
44106
+ }
44107
+ const js = JS_RE.exec(source);
44108
+ if (js) {
44109
+ pushAll(directiveLines, fromLine, toLine);
44110
+ ensure(directives, page).js.push(js[1].trim());
44111
+ }
44112
+ }
44113
+ const roles = collectRoles(state, front, pageOf, directives);
44114
+ return { directives, linesByPage, directiveLines, deck, roles };
44115
+ }
44116
+ function pushAll(lines, fromLine, toLine) {
44117
+ for (let n = fromLine; n <= toLine; n++) lines.push(n);
44118
+ }
44119
+ function ensure(map, page) {
44120
+ let dirs = map.get(page);
44121
+ if (!dirs) {
44122
+ dirs = { css: [], js: [] };
44123
+ map.set(page, dirs);
44124
+ }
44125
+ return dirs;
44126
+ }
44127
+ let snapshot = /* @__PURE__ */ new Map();
44128
+ let deckSnapshot = {};
44129
+ let pageCountSnapshot = 0;
44130
+ let documentBaseSnapshot = null;
44131
+ function publishSlideDirectives(directives) {
44132
+ snapshot = directives;
44133
+ }
44134
+ function getSlideDirectives() {
44135
+ return snapshot;
44136
+ }
44137
+ function publishDeckChrome(deck, pageCount) {
44138
+ deckSnapshot = deck;
44139
+ pageCountSnapshot = pageCount;
44140
+ }
44141
+ function getDeckChrome() {
44142
+ return deckSnapshot;
44143
+ }
44144
+ function getDeckPageCount() {
44145
+ return pageCountSnapshot;
44146
+ }
44147
+ function publishDocumentBase(url) {
44148
+ documentBaseSnapshot = url;
44149
+ }
44150
+ function getDocumentBase() {
44151
+ return documentBaseSnapshot;
44152
+ }
44153
+ const SAFE_PROPERTY = /* @__PURE__ */ new Set([
44154
+ "text-align",
44155
+ "text-decoration",
44156
+ "text-transform",
44157
+ "text-indent",
44158
+ "text-shadow",
44159
+ "text-underline-offset",
44160
+ "text-justify",
44161
+ "text-orientation",
44162
+ "text-rendering",
44163
+ "color",
44164
+ "opacity",
44165
+ "visibility",
44166
+ "filter",
44167
+ "backdrop-filter",
44168
+ "mix-blend-mode",
44169
+ "isolation",
44170
+ "background",
44171
+ "background-color",
44172
+ "background-image",
44173
+ "background-size",
44174
+ "background-position",
44175
+ "background-repeat",
44176
+ "background-clip",
44177
+ "background-origin",
44178
+ "background-blend-mode",
44179
+ "font",
44180
+ "font-size",
44181
+ "font-family",
44182
+ "font-weight",
44183
+ "font-style",
44184
+ "font-variant",
44185
+ "font-stretch",
44186
+ "line-height",
44187
+ "letter-spacing",
44188
+ "word-spacing",
44189
+ "white-space",
44190
+ "word-break",
44191
+ "overflow-wrap",
44192
+ "margin",
44193
+ "margin-top",
44194
+ "margin-right",
44195
+ "margin-bottom",
44196
+ "margin-left",
44197
+ "padding",
44198
+ "padding-top",
44199
+ "padding-right",
44200
+ "padding-bottom",
44201
+ "padding-left",
44202
+ "border",
44203
+ "border-top",
44204
+ "border-right",
44205
+ "border-bottom",
44206
+ "border-left",
44207
+ "border-width",
44208
+ "border-style",
44209
+ "border-color",
44210
+ "border-radius",
44211
+ "border-image",
44212
+ "border-top-width",
44213
+ "border-right-width",
44214
+ "border-bottom-width",
44215
+ "border-left-width",
44216
+ "border-top-color",
44217
+ "border-right-color",
44218
+ "border-bottom-color",
44219
+ "border-left-color",
44220
+ "border-top-style",
44221
+ "border-right-style",
44222
+ "border-bottom-style",
44223
+ "border-left-style",
44224
+ "border-top-left-radius",
44225
+ "border-top-right-radius",
44226
+ "border-bottom-left-radius",
44227
+ "border-bottom-right-radius",
44228
+ "outline",
44229
+ "outline-width",
44230
+ "outline-style",
44231
+ "outline-color",
44232
+ "outline-offset",
44233
+ "width",
44234
+ "height",
44235
+ "min-width",
44236
+ "min-height",
44237
+ "max-width",
44238
+ "max-height",
44239
+ "top",
44240
+ "right",
44241
+ "bottom",
44242
+ "left",
44243
+ "inset",
44244
+ "position",
44245
+ "display",
44246
+ "float",
44247
+ "clear",
44248
+ "vertical-align",
44249
+ "overflow",
44250
+ "clip",
44251
+ "flex",
44252
+ "flex-direction",
44253
+ "flex-wrap",
44254
+ "flex-flow",
44255
+ "flex-grow",
44256
+ "flex-shrink",
44257
+ "flex-basis",
44258
+ "order",
44259
+ "align-items",
44260
+ "align-self",
44261
+ "align-content",
44262
+ "justify-content",
44263
+ "justify-items",
44264
+ "justify-self",
44265
+ "gap",
44266
+ "row-gap",
44267
+ "column-gap",
44268
+ "place-items",
44269
+ "place-content",
44270
+ "place-self",
44271
+ "grid",
44272
+ "grid-area",
44273
+ "grid-template",
44274
+ "grid-template-columns",
44275
+ "grid-template-rows",
44276
+ "grid-template-areas",
44277
+ "grid-auto-columns",
44278
+ "grid-auto-rows",
44279
+ "grid-auto-flow",
44280
+ "grid-column",
44281
+ "grid-row",
44282
+ "grid-column-start",
44283
+ "grid-column-end",
44284
+ "grid-row-start",
44285
+ "grid-row-end",
44286
+ "columns",
44287
+ "column-count",
44288
+ "column-width",
44289
+ "column-gap",
44290
+ "column-rule",
44291
+ "column-fill",
44292
+ "column-span",
44293
+ "transform",
44294
+ "transform-origin",
44295
+ "transform-style",
44296
+ "perspective",
44297
+ "perspective-origin",
44298
+ "rotate",
44299
+ "scale",
44300
+ "translate",
44301
+ "animation",
44302
+ "animation-name",
44303
+ "animation-duration",
44304
+ "animation-timing-function",
44305
+ "animation-delay",
44306
+ "animation-iteration-count",
44307
+ "animation-direction",
44308
+ "animation-fill-mode",
44309
+ "animation-play-state",
44310
+ "transition",
44311
+ "transition-property",
44312
+ "transition-duration",
44313
+ "transition-timing-function",
44314
+ "transition-delay",
44315
+ "box-shadow",
44316
+ "clip-path",
44317
+ "object-fit",
44318
+ "object-position",
44319
+ "list-style",
44320
+ "list-style-type",
44321
+ "list-style-position",
44322
+ "list-style-image",
44323
+ "counter-reset",
44324
+ "counter-increment",
44325
+ "content",
44326
+ "quotes",
44327
+ "aspect-ratio",
44328
+ "box-sizing",
44329
+ "resize",
44330
+ "user-select",
44331
+ "pointer-events",
44332
+ "touch-action",
44333
+ "mask",
44334
+ "mask-image",
44335
+ "mask-size",
44336
+ "mask-position",
44337
+ "mask-repeat"
44338
+ ]);
44339
+ const UNSAFE_VALUE = /expression\s*\(|javascript\s*:|vbscript\s*:|data:text\/html|behavior\s*:/i;
44340
+ const UNSAFE_POSITION = /^(?:absolute|fixed)$/i;
44341
+ function safeDeclaration(raw) {
44342
+ const colon2 = raw.indexOf(":");
44343
+ if (colon2 <= 0) return null;
44344
+ const prop = raw.slice(0, colon2).trim().toLowerCase();
44345
+ const value = raw.slice(colon2 + 1).trim();
44346
+ if (!prop || !value) return null;
44347
+ if (!SAFE_PROPERTY.has(prop)) return null;
44348
+ if (UNSAFE_VALUE.test(value)) return null;
44349
+ if (prop === "position" && UNSAFE_POSITION.test(value)) return null;
44350
+ return `${prop}: ${value}`;
44351
+ }
44352
+ function scopeDeclarations(body) {
44353
+ const kept = [];
44354
+ for (const raw of body.split(";")) {
44355
+ if (!raw.trim()) continue;
44356
+ const safe = safeDeclaration(raw);
44357
+ if (safe) kept.push(safe);
44358
+ }
44359
+ return kept.join(";\n");
44360
+ }
44361
+ function scopeSlideCSS(css2, pageClass, guard) {
44362
+ const out = scopeBlock(css2.trim(), pageClass, guard, 0);
44363
+ return out.filter(Boolean).join("\n");
44364
+ }
44365
+ function scopeBlock(css2, pageClass, guard, depth) {
44366
+ if (depth > 8) return [];
44367
+ const out = [];
44368
+ let i = 0;
44369
+ while (i < css2.length) {
44370
+ const open2 = css2.indexOf("{", i);
44371
+ if (open2 === -1) break;
44372
+ const head = css2.slice(i, open2).trim();
44373
+ let level = 1;
44374
+ let close2 = open2 + 1;
44375
+ while (close2 < css2.length && level > 0) {
44376
+ const ch = css2[close2];
44377
+ if (ch === "{") level++;
44378
+ else if (ch === "}") level--;
44379
+ close2++;
44380
+ }
44381
+ if (level !== 0) return [];
44382
+ const body = css2.slice(open2 + 1, close2 - 1);
44383
+ i = close2;
44384
+ if (head.startsWith("@")) {
44385
+ const at = head.toLowerCase();
44386
+ if (at.startsWith("@media") || at.startsWith("@supports")) {
44387
+ const inner2 = scopeBlock(body, pageClass, guard, depth + 1);
44388
+ if (inner2.length > 0) out.push(`${head} {
44389
+ ${inner2.join("\n")}
44390
+ }`);
44391
+ } else if (at.startsWith("@keyframes") || at.startsWith("@counter-style")) {
44392
+ const kept2 = scopeKeyframes(body);
44393
+ if (kept2) out.push(`${head} {
44394
+ ${kept2}
44395
+ }`);
44396
+ }
44397
+ continue;
44398
+ }
44399
+ const selectors = head.split(",").map((s) => s.trim()).filter(Boolean).map((s) => `${guard} .${pageClass} ${s}`);
44400
+ const kept = scopeDeclarations(body);
44401
+ if (selectors.length > 0 && kept) {
44402
+ out.push(`${selectors.join(", ")} {
44403
+ ${kept}
44404
+ }`);
44405
+ }
44406
+ }
44407
+ return out;
44408
+ }
44409
+ function scopeKeyframes(body) {
44410
+ const out = [];
44411
+ let i = 0;
44412
+ while (i < body.length) {
44413
+ const open2 = body.indexOf("{", i);
44414
+ if (open2 === -1) break;
44415
+ const head = body.slice(i, open2).trim();
44416
+ const close2 = body.indexOf("}", open2);
44417
+ if (close2 === -1) return null;
44418
+ const kept = scopeDeclarations(body.slice(open2 + 1, close2));
44419
+ if (head && kept) out.push(`${head} {
44420
+ ${kept}
44421
+ }`);
44422
+ i = close2 + 1;
44423
+ }
44424
+ return out.length > 0 ? out.join("\n") : null;
44425
+ }
44426
+ const SLIDE_CLASS_PREFIX = "cm-md-slide-";
44427
+ const DIRECTIVE_CLASS = "cm-md-slide-directive";
44428
+ function layoutClass(name2) {
44429
+ return /^[a-z][a-z0-9-]*$/.test(name2) ? `${SLIDE_CLASS_PREFIX}${name2}` : null;
44430
+ }
44431
+ function buildDecorations(state) {
44432
+ const scan = scanSlideDirectives(state);
44433
+ publishSlideDirectives(scan.directives);
44434
+ publishDeckChrome(scan.deck, scan.linesByPage.size);
44435
+ publishDocumentBase(state.field(documentFileUrlField, false) ?? null);
44436
+ const specs = /* @__PURE__ */ new Map();
44437
+ const add = (from, cls, attrs) => {
44438
+ let spec = specs.get(from);
44439
+ if (!spec) {
44440
+ spec = { classes: /* @__PURE__ */ new Set(), attributes: {} };
44441
+ specs.set(from, spec);
44442
+ }
44443
+ if (cls) spec.classes.add(cls);
44444
+ if (attrs) Object.assign(spec.attributes, attrs);
44445
+ };
44446
+ for (const [page, dirs] of scan.directives) {
44447
+ if (!dirs.layout) continue;
44448
+ const cls = layoutClass(dirs.layout);
44449
+ if (!cls) continue;
44450
+ const lines = scan.linesByPage.get(page);
44451
+ if (!lines) continue;
44452
+ for (const n of lines) add(state.doc.line(n).from, cls);
44453
+ }
44454
+ for (const [page, lines] of scan.linesByPage) {
44455
+ if (scan.directives.get(page)?.layout) continue;
44456
+ for (const n of lines) add(state.doc.line(n).from, "cm-md-page-default");
44457
+ }
44458
+ for (const n of scan.directiveLines) add(state.doc.line(n).from, DIRECTIVE_CLASS);
44459
+ for (const [page, role] of scan.roles) {
44460
+ const kicker = scan.directives.get(page)?.kicker?.replace(/\s+/g, " ").trim();
44461
+ for (const n of role.titleLines) {
44462
+ const from = state.doc.line(n).from;
44463
+ add(from, "cm-md-page-title", kicker ? { "data-slide-kicker": kicker } : void 0);
44464
+ }
44465
+ for (const n of role.leadLines) add(state.doc.line(n).from, "cm-md-page-lead");
44466
+ for (const n of role.kickerLines) add(state.doc.line(n).from, "cm-md-page-kicker");
44467
+ }
44468
+ const builder = new RangeSetBuilder();
44469
+ const pending = [...specs.entries()].sort((a, b) => a[0] - b[0]);
44470
+ for (const [from, spec] of pending) {
44471
+ builder.add(
44472
+ from,
44473
+ from,
44474
+ Decoration.line({
44475
+ class: [...spec.classes].join(" "),
44476
+ attributes: Object.keys(spec.attributes).length > 0 ? spec.attributes : void 0
44477
+ })
44478
+ );
44479
+ }
44480
+ return builder.finish();
44481
+ }
44482
+ const slideLayoutField = StateField.define({
44483
+ create: (state) => buildDecorations(state),
44484
+ update: (_value, tr) => {
44485
+ if (!tr.docChanged && !tr.effects.some((effect) => effect.is(decorationsRefreshEffect))) {
44486
+ return _value;
44487
+ }
44488
+ return buildDecorations(tr.state);
44489
+ },
44490
+ provide: (field) => EditorView.decorations.from(field)
44491
+ });
44492
+ const slideLayout = [slideLayoutField];
43136
44493
  let handle$1 = null;
43137
44494
  function getEditorHandle() {
43138
44495
  return handle$1;
43139
44496
  }
43140
44497
  const livePreviewCompartment = new Compartment();
43141
- const taskMarkerAtomicRanges = EditorView.atomicRanges.of((view) => {
44498
+ const listPrefixAtomicRanges = EditorView.atomicRanges.of((view) => {
43142
44499
  const doc2 = view.state.doc;
44500
+ const tree = syntaxTree(view.state);
44501
+ const fmEnd = frontmatterEnd(doc2);
43143
44502
  const ranges = [];
43144
- syntaxTree(view.state).iterate({
43145
- enter: (node) => {
43146
- if (node.name !== "TaskMarker") return;
43147
- const line = doc2.lineAt(node.from);
43148
- const prefix = doc2.sliceString(line.from, node.from);
43149
- const quoteLen = /^(?:[ \t]*> ?)+/.exec(prefix)?.[0].length ?? 0;
43150
- const listPart = prefix.slice(quoteLen);
43151
- const from = /^[ \t]*(?:[-*+]|\d+[.)])[ \t]+$/.test(listPart) ? line.from + quoteLen : node.from;
43152
- const trailing = doc2.sliceString(node.to, Math.min(node.to + 1, line.to)) === " " ? node.to + 1 : node.to;
43153
- ranges.push({ from, to: trailing });
44503
+ const seenLines = /* @__PURE__ */ new Set();
44504
+ for (const vp of view.visibleRanges) {
44505
+ const startLine = doc2.lineAt(vp.from).number;
44506
+ const endLine = doc2.lineAt(vp.to).number;
44507
+ for (let ln = startLine; ln <= endLine; ln++) {
44508
+ if (seenLines.has(ln)) continue;
44509
+ seenLines.add(ln);
44510
+ const parsed = isActiveOrderedListLine(doc2, tree, ln, fmEnd);
44511
+ if (!parsed) continue;
44512
+ const line = doc2.line(ln);
44513
+ const from = line.from + parsed.quoteLen;
44514
+ const to = line.from + parsed.contentOffset;
44515
+ if (to > from) ranges.push({ from, to });
44516
+ }
44517
+ }
44518
+ for (const vp of view.visibleRanges) {
44519
+ tree.iterate({
44520
+ from: vp.from,
44521
+ to: vp.to,
44522
+ enter: (node) => {
44523
+ if (node.name !== "TaskMarker") return;
44524
+ const line = doc2.lineAt(node.from);
44525
+ const parsed = parseListLine(line.text);
44526
+ if (!parsed || parsed.kind === "ordered") return;
44527
+ const prefix = doc2.sliceString(line.from, node.from);
44528
+ const quoteLen = QUOTE_PREFIX_RE.exec(prefix)?.[0].length ?? 0;
44529
+ const listPart = prefix.slice(quoteLen);
44530
+ const from = /^[ \t]*(?:[-*+]|\d+[.)]) +$/.test(listPart) ? line.from + quoteLen : node.from;
44531
+ const trailing = doc2.sliceString(node.to, Math.min(node.to + 1, line.to)) === " " ? node.to + 1 : node.to;
44532
+ if (trailing > from) ranges.push({ from, to: trailing });
44533
+ }
44534
+ });
44535
+ }
44536
+ ranges.sort((a, b) => a.from - b.from || a.to - b.to);
44537
+ const merged = [];
44538
+ for (const r of ranges) {
44539
+ const last2 = merged[merged.length - 1];
44540
+ if (last2 && r.from <= last2.to) {
44541
+ if (r.to > last2.to) last2.to = r.to;
44542
+ } else {
44543
+ merged.push({ ...r });
43154
44544
  }
43155
- });
43156
- return RangeSet.of(ranges.map((r) => ATOMIC_MARK.range(r.from, r.to)), true);
44545
+ }
44546
+ return RangeSet.of(merged.map((r) => ATOMIC_MARK.range(r.from, r.to)), true);
43157
44547
  });
43158
44548
  const ATOMIC_MARK = Decoration.replace({});
43159
44549
  function isSourceMode(state) {
@@ -43177,6 +44567,9 @@ function editorExtensions(sourceMode, editable2, onChange) {
43177
44567
  // 「没改过的字节不许变」这条纪律。源码模式把它收起来,剩下的就是带 markdown
43178
44568
  // 语法高亮的原文(高亮在 state.ts 的 markdown 扩展里,跟模式无关)。
43179
44569
  livePreviewCompartment.of(sourceMode ? [] : livePreview),
44570
+ // 幻灯片版式:独立于 live-preview 的行装饰(slide-layout.ts),给声明了版式的
44571
+ // 页打 cm-md-slide-* 类。常驻安装:样式只在放映/导出时命中,平时零影响。
44572
+ slideLayout,
43180
44573
  // 焦点变化要重算装饰:只有**正在编辑**的那一行才显示源码(见 live-preview 的 setEditorFocus)。
43181
44574
  // 用 DOM 事件而不是 EditorView.focusChangeEffect,是因为后者在创建时就已带焦点的编辑器上
43182
44575
  // 不会触发;下面创建完 view 之后补了一次初始值。
@@ -43195,10 +44588,8 @@ function editorExtensions(sourceMode, editable2, onChange) {
43195
44588
  // 检索高亮。面板靠 effect 改它,而 effect 得有 StateField 接住;
43196
44589
  // 不装这一条,检索面板会以为高亮画上了,实际什么也没发生。
43197
44590
  searchHighlightField,
43198
- // 任务项的复选框是一个 replace widget,但没声明成原子区间时,光标能停在
43199
- // `[ ]` 两个方框之间那一格里:左右键要一格一格挪过去,停在里面打字又把
43200
- // `- [ ]` 敲成 `- [x]` 之类的残骸(#164)。声明成原子区间后,光标一次跨过它。
43201
- taskMarkerAtomicRanges,
44591
+ // 列表前缀与任务复选框原子区间:一次跨过 `[ ] ` 与有序列表的 `1. ` 前缀。
44592
+ listPrefixAtomicRanges,
43202
44593
  editableCompartment.of(EditorView.editable.of(editable2)),
43203
44594
  // 文档变化的唯一出口:把新文本交给外壳
43204
44595
  EditorView.updateListener.of((update) => {
@@ -43302,6 +44693,17 @@ function lineKind(line, includeList = true) {
43302
44693
  if ((line.textContent ?? "").trim() === "" && line.querySelector("img") === null) return "empty";
43303
44694
  return "p";
43304
44695
  }
44696
+ function blockWidgetKind(node) {
44697
+ if (!(node instanceof HTMLElement)) return null;
44698
+ if (node.classList.contains("cm-md-table-widget")) return "table";
44699
+ if (node.classList.contains("cm-md-mermaid")) return "mermaid";
44700
+ if (node.classList.contains("cm-md-math-block")) return "math";
44701
+ return null;
44702
+ }
44703
+ function widgetIn(container, selector) {
44704
+ if (container.matches(selector)) return container;
44705
+ return container.querySelector(selector);
44706
+ }
43305
44707
  function listDepth(line) {
43306
44708
  for (let depth = 6; depth >= 0; depth--) {
43307
44709
  if (line.classList.contains(`cm-md-li-${depth}`)) return depth;
@@ -43426,11 +44828,11 @@ function renderCode(lines) {
43426
44828
  function renderGroup(kind, lines, ownerDepth = -1) {
43427
44829
  if (kind === "code") return renderCode(lines);
43428
44830
  if (kind === "mermaid") {
43429
- const widget = lines[0].querySelector(".cm-md-mermaid");
44831
+ const widget = widgetIn(lines[0], ".cm-md-mermaid");
43430
44832
  return widget ? `<div class="${widget.className}">${widget.innerHTML}</div>` : "";
43431
44833
  }
43432
44834
  if (kind === "math") {
43433
- const widget = lines[0].querySelector(".cm-md-math-block");
44835
+ const widget = widgetIn(lines[0], ".cm-md-math-block");
43434
44836
  return widget ? `<div>${widget.innerHTML}</div>` : "";
43435
44837
  }
43436
44838
  if (kind === "li") return renderList(lines);
@@ -43438,7 +44840,7 @@ function renderGroup(kind, lines, ownerDepth = -1) {
43438
44840
  return `<blockquote>${lines.map((line) => `<p>${lineHTML(line)}</p>`).join("")}</blockquote>`;
43439
44841
  }
43440
44842
  if (kind === "table") {
43441
- const table = lines[0].querySelector(".cm-md-table-widget");
44843
+ const table = widgetIn(lines[0], ".cm-md-table-widget");
43442
44844
  if (!table) return "";
43443
44845
  const clone = table.cloneNode(true);
43444
44846
  for (const shell of Array.from(clone.querySelectorAll(".cm-md-math, .cm-md-mermaid-ready"))) {
@@ -43446,6 +44848,7 @@ function renderGroup(kind, lines, ownerDepth = -1) {
43446
44848
  }
43447
44849
  for (const element of [clone, ...Array.from(clone.querySelectorAll("*"))]) {
43448
44850
  element.classList.remove(...Array.from(element.classList).filter((name2) => name2.startsWith("cm-md-")));
44851
+ if (element.classList.length === 0) element.removeAttribute("class");
43449
44852
  element.removeAttribute("contenteditable");
43450
44853
  for (const attribute of ["data-source-from", "data-source-to", "data-list-path", "data-line"]) {
43451
44854
  element.removeAttribute(attribute);
@@ -43507,6 +44910,12 @@ function blocksHTML(nodes, ownerDepth = -1) {
43507
44910
  continue;
43508
44911
  }
43509
44912
  if (!isLineElement(node)) {
44913
+ const widgetKind = blockWidgetKind(node);
44914
+ if (widgetKind) {
44915
+ html2 += renderGroup(widgetKind, [node], ownerDepth);
44916
+ index2 += 1;
44917
+ continue;
44918
+ }
43510
44919
  const inline = [];
43511
44920
  while (index2 < nodes.length && !isLineElement(nodes[index2])) {
43512
44921
  inline.push(inlineHTML(nodes[index2]));
@@ -43559,7 +44968,7 @@ body.${PAPER_CLASS} #editor .cm-scroller { display: block !important; height: au
43559
44968
  天生没有控件)。内联样式是 pele 自己写的,!important 才压得过。 */
43560
44969
  body.${PAPER_CLASS} .pele-zoom { display: none !important; }
43561
44970
  `;
43562
- function nextFrame() {
44971
+ function nextFrame$1() {
43563
44972
  return new Promise((resolve) => {
43564
44973
  requestAnimationFrame(() => resolve());
43565
44974
  });
@@ -43582,10 +44991,10 @@ function setFullRender(on) {
43582
44991
  }
43583
44992
  async function renderWholeDocument() {
43584
44993
  const ok = setFullRender(true);
43585
- await nextFrame();
44994
+ await nextFrame$1();
43586
44995
  const deadline = Date.now() + RENDER_TIMEOUT_MS;
43587
- while (!fullyRendered() && Date.now() < deadline) await nextFrame();
43588
- await nextFrame();
44996
+ while (!fullyRendered() && Date.now() < deadline) await nextFrame$1();
44997
+ await nextFrame$1();
43589
44998
  return ok;
43590
44999
  }
43591
45000
  function restoreViewport() {
@@ -44091,7 +45500,7 @@ function setupFootnotePreview(root) {
44091
45500
  }, { passive: true });
44092
45501
  window.addEventListener("resize", hide2);
44093
45502
  }
44094
- const TASK_RE = /^((?:[ \t]*> ?)*[ \t]*(?:[-*+]|\d+[.)])[ \t]+\[)([ xX])(\])/;
45503
+ const TASK_RE = /^((?:[ \t]*> ?)*[ \t]*(?:[-*+]|\d+[.)]) +\[)([ xX])(\])/;
44095
45504
  function sourceFromTaskClick(view, e) {
44096
45505
  if (!(e.target instanceof HTMLElement)) return null;
44097
45506
  if (!e.target.closest(".cm-md-task")) return null;
@@ -44465,10 +45874,11 @@ function readDocxStyle() {
44465
45874
  lineHeight: 1.75
44466
45875
  };
44467
45876
  }
44468
- const PRESENTING_CLASS = "presenting";
44469
- const RULE_STYLE_ID = "slideshow-rules";
45877
+ const PRESENTING_CLASS$1 = "presenting";
45878
+ const RULE_STYLE_ID$1 = "slideshow-rules";
44470
45879
  const DRAG_SLOP = 4;
44471
45880
  let presenting = false;
45881
+ let starting = false;
44472
45882
  let pages = [];
44473
45883
  let index = 0;
44474
45884
  let rules = null;
@@ -44497,6 +45907,9 @@ function pageNumbers(root) {
44497
45907
  const page = pageOfLine$1(line);
44498
45908
  if (page === null) continue;
44499
45909
  if (line.classList.contains("cm-md-hr")) continue;
45910
+ const text2 = (line.textContent ?? "").trim();
45911
+ const visual = line.querySelector("img, svg, .cm-md-mermaid, .cm-md-image, .katex");
45912
+ if (!text2 && !visual) continue;
44500
45913
  found.add(page);
44501
45914
  }
44502
45915
  return [...found].sort((a, b) => a - b);
@@ -44505,6 +45918,28 @@ function deckPages() {
44505
45918
  const root = documentRoot$1();
44506
45919
  return root ? pageNumbers(root) : [];
44507
45920
  }
45921
+ function tagBlockWidgets(root) {
45922
+ for (const child of Array.from(root.children)) {
45923
+ if (child.classList.contains("cm-line")) continue;
45924
+ for (const cls of Array.from(child.classList)) {
45925
+ if (cls.startsWith(PAGE_CLASS_PREFIX) || cls.startsWith(SLIDE_CLASS_PREFIX)) child.classList.remove(cls);
45926
+ }
45927
+ }
45928
+ let page = null;
45929
+ let layout2 = [];
45930
+ const pageNumber = new RegExp(`^${PAGE_CLASS_PREFIX}\\d+$`);
45931
+ for (const child of Array.from(root.children)) {
45932
+ const own = Array.from(child.classList);
45933
+ const ownPage = own.find((cls) => pageNumber.test(cls));
45934
+ if (ownPage) {
45935
+ page = ownPage;
45936
+ layout2 = own.filter((cls) => cls.startsWith(SLIDE_CLASS_PREFIX) && cls !== DIRECTIVE_CLASS);
45937
+ continue;
45938
+ }
45939
+ if (page) child.classList.add(page);
45940
+ for (const cls of layout2) child.classList.add(cls);
45941
+ }
45942
+ }
44508
45943
  function firstLineOf(page) {
44509
45944
  const root = documentRoot$1();
44510
45945
  if (!root) return null;
@@ -44523,7 +45958,7 @@ function pageAtCaret(root) {
44523
45958
  function applyPage() {
44524
45959
  if (!rules) return;
44525
45960
  const page = pages[index];
44526
- rules.textContent = `body.${PRESENTING_CLASS} #editor .cm-content > :not(.${PAGE_CLASS_PREFIX}${page}) { display: none !important; }
45961
+ rules.textContent = `body.${PRESENTING_CLASS$1} #editor .cm-content > :not(.${PAGE_CLASS_PREFIX}${page}) { display: none !important; }
44527
45962
  `;
44528
45963
  }
44529
45964
  function show(next) {
@@ -44599,13 +46034,26 @@ function onContextMenu(event) {
44599
46034
  event.stopPropagation();
44600
46035
  show(index - 1);
44601
46036
  }
44602
- function startSlideshow(next = {}) {
44603
- if (presenting) return true;
46037
+ async function startSlideshow(next = {}) {
46038
+ if (presenting || starting) return presenting;
46039
+ starting = true;
46040
+ try {
46041
+ return await beginSlideshow(next);
46042
+ } finally {
46043
+ starting = false;
46044
+ }
46045
+ }
46046
+ async function beginSlideshow(next = {}) {
44604
46047
  const editor = editorElement();
44605
46048
  const root = documentRoot$1();
44606
46049
  if (!editor || !root) return false;
46050
+ await renderWholeDocument();
46051
+ tagBlockWidgets(root);
44607
46052
  const deck = pageNumbers(root);
44608
- if (deck.length === 0) return false;
46053
+ if (deck.length === 0) {
46054
+ restoreViewport();
46055
+ return false;
46056
+ }
44609
46057
  pages = deck;
44610
46058
  options = next;
44611
46059
  index = pageAtCaret(root);
@@ -44615,10 +46063,10 @@ function startSlideshow(next = {}) {
44615
46063
  });
44616
46064
  watch.observe(root, { childList: true });
44617
46065
  rules = document.createElement("style");
44618
- rules.id = RULE_STYLE_ID;
46066
+ rules.id = RULE_STYLE_ID$1;
44619
46067
  document.head.appendChild(rules);
44620
46068
  applyPage();
44621
- document.body.classList.add(PRESENTING_CLASS);
46069
+ document.body.classList.add(PRESENTING_CLASS$1);
44622
46070
  layout();
44623
46071
  const scroll = scroller$1();
44624
46072
  if (scroll) scroll.scrollTop = 0;
@@ -44641,7 +46089,8 @@ function stopSlideshow() {
44641
46089
  window.removeEventListener("resize", layout);
44642
46090
  watch?.disconnect();
44643
46091
  watch = null;
44644
- document.body.classList.remove(PRESENTING_CLASS);
46092
+ restoreViewport();
46093
+ document.body.classList.remove(PRESENTING_CLASS$1);
44645
46094
  rules?.remove();
44646
46095
  rules = null;
44647
46096
  const editor = editorElement();
@@ -44658,15 +46107,33 @@ function stopSlideshow() {
44658
46107
  if (line) claimPage(line);
44659
46108
  }
44660
46109
  }
44661
- const PAGE_WIDTH_INCHES = 13.3333;
44662
- const PAGE_HEIGHT_INCHES = 7.5;
46110
+ const PAGE_WIDTH_INCHES = 20;
46111
+ const PAGE_HEIGHT_INCHES = 11.25;
44663
46112
  const PX_PER_INCH = 96;
44664
46113
  const PAGE_WIDTH_PX = Math.round(PAGE_WIDTH_INCHES * PX_PER_INCH);
44665
46114
  const PAGE_HEIGHT_PX = Math.round(PAGE_HEIGHT_INCHES * PX_PER_INCH);
44666
- const COLUMN_EM = 38;
44667
- const FONT_SIZE_PX = 20;
44668
46115
  const SAFETY_PX = 4;
44669
- const PRINT_CLASS = "slides-printing";
46116
+ const MIN_ZOOM = 0.08;
46117
+ const FIT_ROUNDS = 4;
46118
+ const PAPER = {
46119
+ /** clamp(17px, 1.35vw, 26px) @1920 */
46120
+ bodySize: 25.92,
46121
+ /** 6vw @1920 */
46122
+ padX: 115.2,
46123
+ /** clamp(11px, 0.72vw, 15px) @1920 */
46124
+ kicker: 13.824,
46125
+ /** clamp(20px, 3.2vh, 40px) @1080 */
46126
+ chromePadY: 34.56,
46127
+ /** clamp(18px, 1.6vw, 30px) @1920 */
46128
+ chromeLogoH: 30,
46129
+ /** clamp(16px, 2.4vh, 28px) @1080 */
46130
+ footPadY: 25.92,
46131
+ /** 72vh @1080 —— 与放映里 base.css 给 img/svg 的高度上限同一个比例 */
46132
+ imgMaxH: 777.6,
46133
+ /** 66vh @1080 */
46134
+ figureMaxH: 712.8
46135
+ };
46136
+ const PRINT_CLASS$1 = "slides-printing";
44670
46137
  const STYLE_ID = "slides-print-style";
44671
46138
  let sheetStyle = null;
44672
46139
  let restoreScrollTop = 0;
@@ -44680,78 +46147,159 @@ function pageOfLine(line) {
44680
46147
  const match = new RegExp(`(?:^|\\s)${PAGE_CLASS_PREFIX}(\\d+)(?:\\s|$)`).exec(line.className ?? "");
44681
46148
  return match ? Number(match[1]) : null;
44682
46149
  }
44683
- function layoutRules(background) {
46150
+ function nextFrame() {
46151
+ return new Promise((resolve) => {
46152
+ requestAnimationFrame(() => resolve());
46153
+ });
46154
+ }
46155
+ async function waitForDiagrams(root, timeoutMs = 15e3) {
46156
+ const pending = () => root.querySelectorAll(
46157
+ ".cm-md-mermaid:not(.cm-md-mermaid-ready):not(.cm-md-mermaid-failed)"
46158
+ ).length;
46159
+ const deadline = Date.now() + timeoutMs;
46160
+ while (pending() > 0 && Date.now() < deadline) await nextFrame();
46161
+ await nextFrame();
46162
+ }
46163
+ function themeColor(name2, fallback) {
46164
+ const onBody = getComputedStyle(document.body).getPropertyValue(name2).trim();
46165
+ if (onBody) return onBody;
46166
+ const onRoot = getComputedStyle(document.documentElement).getPropertyValue(name2).trim();
46167
+ return onRoot || fallback;
46168
+ }
46169
+ function layoutRules(background, accent2) {
46170
+ const softened = `color-mix(in srgb, ${background} 95%, ${accent2})`;
44684
46171
  return `/* The sheet is the page: what margins exist in here are the document's own. */
44685
- @page { size: ${PAGE_WIDTH_INCHES}in ${PAGE_HEIGHT_INCHES}in; margin: 0; background: ${background}; }
44686
- html, body { display: block !important; height: auto !important; overflow: visible !important; background: ${background} !important; }
44687
- body.${PRINT_CLASS} #editor {
46172
+ @page { size: ${PAGE_WIDTH_INCHES}in ${PAGE_HEIGHT_INCHES}in; margin: 0; background: ${softened}; }
46173
+ html, body { display: block !important; height: auto !important; overflow: visible !important; background: ${softened} !important; }
46174
+ /* 纸面是 1920×1080 的设计空间:跟着视口走的令牌在这里定死,屏幕上的视口再窄,
46175
+ 纸上落下来的版式也不变。 */
46176
+ body.${PRINT_CLASS$1} {
46177
+ --slide-page-pad-x: ${PAPER.padX}px;
46178
+ --slide-body-size: ${PAPER.bodySize}px;
46179
+ --slide-kicker-size: ${PAPER.kicker}px;
46180
+ --slide-chrome-pad-y: ${PAPER.chromePadY}px;
46181
+ --slide-chrome-logo-h: ${PAPER.chromeLogoH}px;
46182
+ --slide-foot-pad-y: ${PAPER.footPadY}px;
46183
+ --slide-img-max-h: ${PAPER.imgMaxH}px;
46184
+ --slide-figure-max-h: ${PAPER.figureMaxH}px;
46185
+ }
46186
+ body.${PRINT_CLASS$1} #editor {
44688
46187
  position: static !important;
44689
46188
  inset: auto !important;
44690
46189
  height: auto !important;
44691
46190
  overflow: visible !important;
44692
46191
  padding: 0 !important;
44693
- background: ${background} !important;
46192
+ background: ${softened} !important;
44694
46193
  }
44695
46194
  /* 纸是普通的块流:CM6 的编辑器/滚动容器都是 flex 或 auto 高度,强制断开的分页在
44696
46195
  它们里面不会生效,所以这里把它们摊平成块。 */
44697
- body.${PRINT_CLASS} #editor .cm-editor { height: auto !important; }
44698
- body.${PRINT_CLASS} #editor .cm-scroller { display: block !important; height: auto !important; overflow: visible !important; }
44699
- body.${PRINT_CLASS} #editor .cm-content {
46196
+ body.${PRINT_CLASS$1} #editor .cm-editor { height: auto !important; }
46197
+ body.${PRINT_CLASS$1} #editor .cm-scroller { display: block !important; height: auto !important; overflow: visible !important; }
46198
+ /* 版心就是纸面那么宽:屏幕上的窗口常常不到 1920,版心若跟着窗口走,量出来的
46199
+ 换行位置和纸上落下来的就不是一回事。 */
46200
+ body.${PRINT_CLASS$1} #editor .cm-content {
44700
46201
  display: block !important;
44701
- width: min(${COLUMN_EM}em, ${Math.round(PAGE_WIDTH_PX * 0.86)}px) !important;
46202
+ width: ${PAGE_WIDTH_PX}px !important;
44702
46203
  max-width: none !important;
44703
- margin: 0 auto !important;
44704
- padding: 0 !important;
44705
- font-size: ${FONT_SIZE_PX}px !important;
44706
- line-height: 1.6;
46204
+ margin: 0 !important;
46205
+ padding: 0 ${PAPER.padX}px !important;
44707
46206
  }
44708
46207
  /* 分隔线是分页边界,不是正文里的一行。 */
44709
- body.${PRINT_CLASS} #editor .cm-line.cm-md-hr { display: none !important; }
44710
- /* Nothing may be cut off at the sheet's edge: code and cells wrap, a diagram or
44711
- a photo shrinks to fit the page it landed on. */
44712
- body.${PRINT_CLASS} #editor .cm-md-codeblock { white-space: pre-wrap !important; overflow-wrap: anywhere !important; }
44713
- body.${PRINT_CLASS} #editor .cm-md-table-widget th, body.${PRINT_CLASS} #editor .cm-md-table-widget td { overflow-wrap: anywhere !important; word-break: break-word !important; }
44714
- body.${PRINT_CLASS} #editor img, body.${PRINT_CLASS} #editor svg { max-height: ${Math.round(PAGE_HEIGHT_PX * 0.72)}px; }
46208
+ body.${PRINT_CLASS$1} #editor .cm-line.cm-md-hr { display: none !important; }
46209
+ /* Nothing may be cut off at the sheet's edge: code and cells wrap. */
46210
+ body.${PRINT_CLASS$1} #editor .cm-md-codeblock { white-space: pre-wrap !important; overflow-wrap: anywhere !important; }
46211
+ body.${PRINT_CLASS$1} #editor .cm-md-table-widget th, body.${PRINT_CLASS$1} #editor .cm-md-table-widget td { overflow-wrap: anywhere !important; word-break: break-word !important; }
44715
46212
  `;
44716
46213
  }
46214
+ const CENTERED_LAYOUTS = ["cm-md-slide-cover", "cm-md-slide-section", "cm-md-slide-closing"];
46215
+ function isCenteredLayout(first) {
46216
+ return CENTERED_LAYOUTS.some((cls) => first.classList.contains(cls));
46217
+ }
46218
+ function measurePage(root, page) {
46219
+ const first = root.querySelector(`.${PAGE_CLASS_PREFIX}${page}.${PAGE_START_CLASS}`);
46220
+ const lines = Array.from(root.children).filter(
46221
+ (line) => pageOfLine(line) === page && !line.classList.contains("cm-md-hr")
46222
+ );
46223
+ const last2 = lines[lines.length - 1];
46224
+ if (!first || !last2) return null;
46225
+ const ownMargin = parseFloat(getComputedStyle(first).marginTop);
46226
+ const owned = last2.getBoundingClientRect().bottom - first.getBoundingClientRect().top;
46227
+ const used = owned + (Number.isFinite(ownMargin) ? ownMargin : 0);
46228
+ return { lines, used, centered: isCenteredLayout(first) };
46229
+ }
46230
+ function applySheet(sheet, background, accent2, plans, spacers) {
46231
+ const rules2 = [];
46232
+ plans.forEach((plan, order) => {
46233
+ const start = `.cm-content > .${PAGE_CLASS_PREFIX}${plan.page}.${PAGE_START_CLASS}`;
46234
+ if (order > 0) rules2.push(`body.${PRINT_CLASS$1} #editor ${start} { break-before: page; }`);
46235
+ if (plan.zoom < 1) {
46236
+ rules2.push(`body.${PRINT_CLASS$1} #editor .${PAGE_CLASS_PREFIX}${plan.page} { zoom: ${plan.zoom}; }`);
46237
+ }
46238
+ });
46239
+ if (spacers) {
46240
+ for (const plan of plans) {
46241
+ const above = spacers.get(plan.page) ?? 0;
46242
+ if (above <= 0) continue;
46243
+ const start = `.cm-content > .${PAGE_CLASS_PREFIX}${plan.page}.${PAGE_START_CLASS}`;
46244
+ const css2 = plan.zoom < 1 ? above / plan.zoom : above;
46245
+ rules2.push(`body.${PRINT_CLASS$1} #editor ${start}::before { content: ''; display: block; height: ${css2}px; }`);
46246
+ }
46247
+ }
46248
+ sheet.textContent = layoutRules(background, accent2) + rules2.join("\n") + "\n";
46249
+ }
44717
46250
  async function enterPrintLayout$1() {
44718
46251
  if (sheetStyle) return { width: PAGE_WIDTH_INCHES, height: PAGE_HEIGHT_INCHES };
44719
46252
  const root = documentRoot();
44720
46253
  if (!root) return false;
44721
- const background = getComputedStyle(document.body).backgroundColor;
46254
+ const background = themeColor("--bg-color", "#ffffff");
46255
+ const accent2 = themeColor("--pele-accent", themeColor("--link-color", "#0969da"));
44722
46256
  const sheet = document.createElement("style");
44723
46257
  sheet.id = STYLE_ID;
44724
- sheet.textContent = layoutRules(background);
46258
+ sheet.textContent = layoutRules(background, accent2);
44725
46259
  document.head.appendChild(sheet);
44726
- document.body.classList.add(PRINT_CLASS);
46260
+ document.body.classList.add(PRINT_CLASS$1);
44727
46261
  sheetStyle = sheet;
44728
46262
  restoreScrollTop = scroller()?.scrollTop ?? 0;
44729
46263
  root.getBoundingClientRect();
44730
46264
  await renderWholeDocument();
46265
+ tagBlockWidgets(root);
46266
+ await waitForDiagrams(root);
44731
46267
  const deck = deckPages();
44732
46268
  if (deck.length === 0) {
44733
46269
  exitPrintLayout();
44734
46270
  return false;
44735
46271
  }
44736
- const rules2 = [];
44737
- deck.forEach((page, order) => {
44738
- const first = root.querySelector(`.${PAGE_CLASS_PREFIX}${page}.${PAGE_START_CLASS}`);
44739
- const lines = Array.from(root.children).filter(
44740
- (line) => pageOfLine(line) === page && !line.classList.contains("cm-md-hr")
44741
- );
44742
- const last2 = lines[lines.length - 1];
44743
- if (!first || !last2) return;
44744
- const ownMargin = parseFloat(getComputedStyle(first).marginTop);
44745
- const owned = last2.getBoundingClientRect().bottom - first.getBoundingClientRect().top;
44746
- const used = owned + (Number.isFinite(ownMargin) ? ownMargin : 0);
44747
- const above = Math.max(0, Math.floor((PAGE_HEIGHT_PX - SAFETY_PX - used) / 2));
44748
- const target = `.cm-content > .${PAGE_CLASS_PREFIX}${page}.${PAGE_START_CLASS}`;
44749
- if (order > 0) rules2.push(`body.${PRINT_CLASS} #editor ${target} { break-before: page; }`);
44750
- if (above > 0) {
44751
- rules2.push(`body.${PRINT_CLASS} #editor ${target}::before { content: ''; display: block; height: ${above}px; }`);
46272
+ const target = PAGE_HEIGHT_PX - SAFETY_PX;
46273
+ const plans = [];
46274
+ for (const page of deck) {
46275
+ const measured = measurePage(root, page);
46276
+ if (measured) plans.push({ page, lines: measured.lines, used: measured.used, zoom: 1, centered: measured.centered });
46277
+ }
46278
+ for (let round = 0; round < FIT_ROUNDS; round++) {
46279
+ const over = plans.filter((plan) => plan.used > target);
46280
+ if (over.length === 0) break;
46281
+ let changed = false;
46282
+ for (const plan of over) {
46283
+ const next = Math.max(MIN_ZOOM, plan.zoom * (target / plan.used));
46284
+ if (next < plan.zoom - 1e-3) {
46285
+ plan.zoom = next;
46286
+ changed = true;
46287
+ }
44752
46288
  }
44753
- });
44754
- sheet.textContent = layoutRules(background) + rules2.join("\n") + "\n";
46289
+ if (!changed) break;
46290
+ applySheet(sheet, background, accent2, plans, null);
46291
+ for (const plan of plans) {
46292
+ const measured = measurePage(root, plan.page);
46293
+ if (measured) plan.used = measured.used;
46294
+ }
46295
+ }
46296
+ const spacers = /* @__PURE__ */ new Map();
46297
+ for (const plan of plans) {
46298
+ if (!plan.centered) continue;
46299
+ const above = Math.max(0, Math.floor((target - plan.used) / 2));
46300
+ if (above > 0) spacers.set(plan.page, above);
46301
+ }
46302
+ applySheet(sheet, background, accent2, plans, spacers);
44755
46303
  return { width: PAGE_WIDTH_INCHES, height: PAGE_HEIGHT_INCHES };
44756
46304
  }
44757
46305
  function exitPrintLayout() {
@@ -44759,7 +46307,7 @@ function exitPrintLayout() {
44759
46307
  if (!sheetStyle) return;
44760
46308
  sheetStyle.remove();
44761
46309
  sheetStyle = null;
44762
- document.body.classList.remove(PRINT_CLASS);
46310
+ document.body.classList.remove(PRINT_CLASS$1);
44763
46311
  const scroll = scroller();
44764
46312
  if (scroll) scroll.scrollTop = restoreScrollTop;
44765
46313
  }
@@ -44998,10 +46546,10 @@ function applyTheme(name2, customCSS) {
44998
46546
  window.electronAPI?.reportTheme?.(name2);
44999
46547
  const bar = document.getElementById("titlebar");
45000
46548
  if (bar) {
45001
- const surface = getComputedStyle(bar).backgroundColor;
46549
+ const surface2 = getComputedStyle(bar).backgroundColor;
45002
46550
  const iconEl = document.getElementById("file-toggle-btn") ?? document.body;
45003
46551
  const icon = getComputedStyle(iconEl).color;
45004
- const surfaceHex = painted(surface, "#ffffff");
46552
+ const surfaceHex = painted(surface2, "#ffffff");
45005
46553
  window.electronAPI?.reportTitlebarColors?.({ background: surfaceHex, symbol: painted(icon, surfaceHex) });
45006
46554
  }
45007
46555
  window.dispatchEvent(new CustomEvent("colamd:theme-applied"));
@@ -45277,6 +46825,302 @@ function showFontSettingsModal() {
45277
46825
  });
45278
46826
  familyInput.focus();
45279
46827
  }
46828
+ const PRESENTING_CLASS = "presenting";
46829
+ const PRINT_CLASS = "slides-printing";
46830
+ const RULE_STYLE_ID = "slideshow-rules";
46831
+ const PAGE_CSS_ID = "slideshow-page-css";
46832
+ const PRINT_CSS_ID = "slides-page-css";
46833
+ const PAGE_IN_RULES = /cm-md-page-(\d+)/;
46834
+ function surface() {
46835
+ return document.getElementById("editor");
46836
+ }
46837
+ const SAFE_NAME = /^[a-zA-Z][a-zA-Z0-9-]*$/;
46838
+ let active = false;
46839
+ let printing = false;
46840
+ let currentPage = 0;
46841
+ let pageStyle = null;
46842
+ let printStyle = null;
46843
+ let host = null;
46844
+ let hostUrl = null;
46845
+ const appliedClasses = /* @__PURE__ */ new Set();
46846
+ const appliedVars = /* @__PURE__ */ new Set();
46847
+ let initialized = false;
46848
+ function initSlidesEnhance() {
46849
+ if (initialized) return;
46850
+ initialized = true;
46851
+ const onBodyClass = () => {
46852
+ const presenting2 = document.body.classList.contains(PRESENTING_CLASS);
46853
+ if (presenting2 && !active) enterPresentation();
46854
+ if (!presenting2 && active) exitPresentation();
46855
+ const printingNow = document.body.classList.contains(PRINT_CLASS);
46856
+ if (printingNow && !printing) mountPrintCss();
46857
+ if (!printingNow && printing) unmountPrintCss();
46858
+ };
46859
+ new MutationObserver(onBodyClass).observe(document.body, {
46860
+ attributes: true,
46861
+ attributeFilter: ["class"],
46862
+ childList: true,
46863
+ subtree: true
46864
+ });
46865
+ onBodyClass();
46866
+ }
46867
+ let pageWatcher = null;
46868
+ function watchRuleStyle() {
46869
+ pageWatcher?.disconnect();
46870
+ pageWatcher = null;
46871
+ const rules2 = document.getElementById(RULE_STYLE_ID);
46872
+ if (!rules2) return;
46873
+ syncPageFrom(rules2.textContent);
46874
+ pageWatcher = new MutationObserver(() => syncPageFrom(rules2.textContent));
46875
+ pageWatcher.observe(rules2, { characterData: true, childList: true, subtree: true });
46876
+ }
46877
+ function syncPageFrom(text2) {
46878
+ const found = text2?.match(PAGE_IN_RULES);
46879
+ if (!found) return;
46880
+ const page = Number(found[1]);
46881
+ if (page === currentPage) return;
46882
+ currentPage = page;
46883
+ if (active) applyCurrentPage();
46884
+ }
46885
+ function enterPresentation() {
46886
+ active = true;
46887
+ pageStyle = document.createElement("style");
46888
+ pageStyle.id = PAGE_CSS_ID;
46889
+ document.head.appendChild(pageStyle);
46890
+ watchRuleStyle();
46891
+ applyCurrentPage();
46892
+ }
46893
+ function exitPresentation() {
46894
+ active = false;
46895
+ pageWatcher?.disconnect();
46896
+ pageWatcher = null;
46897
+ pageStyle?.remove();
46898
+ pageStyle = null;
46899
+ teardownHost();
46900
+ resetApplied();
46901
+ surface()?.removeAttribute("data-slide-layout");
46902
+ }
46903
+ function applyCurrentPage() {
46904
+ const dirs = getSlideDirectives().get(currentPage);
46905
+ if (pageStyle) {
46906
+ const css2 = (dirs?.css ?? []).map((block) => scopeSlideCSS(block, `${PAGE_CLASS_PREFIX}${currentPage}`, `body.${PRESENTING_CLASS} #editor`));
46907
+ pageStyle.textContent = css2.join("\n");
46908
+ }
46909
+ syncChrome();
46910
+ const name2 = dirs?.layout ?? "";
46911
+ const surface_ = surface();
46912
+ if (surface_) {
46913
+ if (name2 && SAFE_NAME.test(name2)) surface_.dataset.slideLayout = name2;
46914
+ else surface_.removeAttribute("data-slide-layout");
46915
+ }
46916
+ teardownHost();
46917
+ resetApplied();
46918
+ const js = dirs?.js.join("\n;\n");
46919
+ if (js) mountHost(js);
46920
+ }
46921
+ let chrome = null;
46922
+ let chromeLogo = null;
46923
+ let foot = null;
46924
+ let ghost = null;
46925
+ function ensureChromeDom() {
46926
+ if (chrome && foot && ghost) return;
46927
+ chrome = document.createElement("div");
46928
+ chrome.id = "slideshow-chrome";
46929
+ chrome.className = "slide-chrome";
46930
+ chrome.setAttribute("aria-hidden", "true");
46931
+ const left = document.createElement("div");
46932
+ left.className = "slide-chrome-left";
46933
+ const right = document.createElement("div");
46934
+ right.className = "slide-chrome-right";
46935
+ chrome.append(left, right);
46936
+ foot = document.createElement("div");
46937
+ foot.id = "slideshow-foot";
46938
+ foot.className = "slide-foot";
46939
+ foot.setAttribute("aria-hidden", "true");
46940
+ ghost = document.createElement("div");
46941
+ ghost.className = "slide-ghost";
46942
+ ghost.setAttribute("aria-hidden", "true");
46943
+ document.body.append(chrome, foot, ghost);
46944
+ }
46945
+ const pad2 = (n) => String(n).padStart(2, "0");
46946
+ function resolveAsset(raw) {
46947
+ const value = raw.trim().replace(/^<|>$/g, "");
46948
+ if (/^(?:https?:|file:|data:|blob:)/i.test(value)) return value;
46949
+ const base2 = getDocumentBase();
46950
+ if (!base2) return value;
46951
+ try {
46952
+ return new URL(value.replaceAll("\\", "/"), base2).href;
46953
+ } catch {
46954
+ return value;
46955
+ }
46956
+ }
46957
+ function syncChrome() {
46958
+ ensureChromeDom();
46959
+ const deck = getDeckChrome();
46960
+ const dirs = getSlideDirectives().get(currentPage);
46961
+ const pages2 = deckPages();
46962
+ const total = Math.max(pages2.length || getDeckPageCount(), 1);
46963
+ const at = pages2.indexOf(currentPage);
46964
+ const ordinal = at >= 0 ? at + 1 : currentPage + 1;
46965
+ const label = (printing ? deck.title : dirs?.label || deck.title) ?? "";
46966
+ const chapter = (printing ? deck.meta : dirs?.chapter || deck.meta) ?? "";
46967
+ const left = chrome.firstElementChild;
46968
+ const right = chrome.lastElementChild;
46969
+ left.textContent = "";
46970
+ right.textContent = "";
46971
+ if (deck.logo) {
46972
+ if (!chromeLogo) {
46973
+ chromeLogo = document.createElement("img");
46974
+ chromeLogo.className = "slide-chrome-logo";
46975
+ chromeLogo.alt = "";
46976
+ }
46977
+ chromeLogo.src = resolveAsset(deck.logo);
46978
+ left.appendChild(chromeLogo);
46979
+ } else {
46980
+ chromeLogo = null;
46981
+ }
46982
+ if (label) {
46983
+ const t2 = document.createElement("span");
46984
+ t2.className = "slide-chrome-title";
46985
+ t2.textContent = label;
46986
+ left.appendChild(t2);
46987
+ }
46988
+ if (chapter) {
46989
+ const m = document.createElement("span");
46990
+ m.className = "slide-chrome-meta";
46991
+ m.textContent = chapter;
46992
+ right.appendChild(m);
46993
+ }
46994
+ chrome.style.display = deck.logo || label || chapter ? "" : "none";
46995
+ foot.textContent = "";
46996
+ if (deck.brand) {
46997
+ const b = document.createElement("span");
46998
+ b.className = "slide-foot-brand";
46999
+ b.textContent = deck.brand;
47000
+ foot.appendChild(b);
47001
+ }
47002
+ const num = document.createElement("span");
47003
+ num.className = "slide-foot-num";
47004
+ num.textContent = `${pad2(ordinal)} / ${pad2(total)}`;
47005
+ foot.appendChild(num);
47006
+ ghost.textContent = pad2(ordinal);
47007
+ }
47008
+ function newToken() {
47009
+ return Math.random().toString(36).slice(2) + Date.now().toString(36);
47010
+ }
47011
+ let bridgeToken = "";
47012
+ function bootHtml(token) {
47013
+ return `<!doctype html><html><body><script>
47014
+ (function () {
47015
+ var TOKEN = ${JSON.stringify(token)};
47016
+ var slide = {
47017
+ setClass: function (name, value) {
47018
+ parent.postMessage({ __colamdSlide: 1, token: TOKEN, kind: 'class', name: name, value: value }, '*');
47019
+ },
47020
+ setVar: function (name, value) {
47021
+ parent.postMessage({ __colamdSlide: 1, token: TOKEN, kind: 'var', name: name, value: value }, '*');
47022
+ },
47023
+ setTimeout: function (fn, ms) { return setTimeout(fn, ms); },
47024
+ requestAnimationFrame: function (fn) { return requestAnimationFrame(fn); }
47025
+ };
47026
+ window.addEventListener('message', function (event) {
47027
+ var data = event.data;
47028
+ if (!data || data.__colamdSlideRun !== 1 || data.token !== TOKEN) return;
47029
+ try { (new Function('slide', data.code))(slide); }
47030
+ catch (err) { console.warn('[slide-js]', err); }
47031
+ });
47032
+ parent.postMessage({ __colamdSlide: 1, token: TOKEN, ready: true }, '*');
47033
+ })();
47034
+ <\/script></body></html>`;
47035
+ }
47036
+ function mountHost(code) {
47037
+ const target = surface();
47038
+ if (!target) return;
47039
+ bridgeToken = newToken();
47040
+ const html2 = bootHtml(bridgeToken);
47041
+ const blob = new Blob([html2], { type: "text/html" });
47042
+ hostUrl = URL.createObjectURL(blob);
47043
+ host = document.createElement("iframe");
47044
+ host.setAttribute("sandbox", "allow-scripts");
47045
+ host.setAttribute("aria-hidden", "true");
47046
+ host.title = "slide script host";
47047
+ host.style.display = "none";
47048
+ host.src = hostUrl;
47049
+ pendingCode = code;
47050
+ window.addEventListener("message", onBridgeMessage);
47051
+ target.appendChild(host);
47052
+ }
47053
+ let pendingCode = "";
47054
+ function teardownHost() {
47055
+ window.removeEventListener("message", onBridgeMessage);
47056
+ if (host) {
47057
+ host.remove();
47058
+ host = null;
47059
+ }
47060
+ if (hostUrl) {
47061
+ URL.revokeObjectURL(hostUrl);
47062
+ hostUrl = null;
47063
+ }
47064
+ pendingCode = "";
47065
+ }
47066
+ function onBridgeMessage(event) {
47067
+ const data2 = event.data;
47068
+ if (!data2 || data2.__colamdSlide !== 1 || data2.token !== bridgeToken) return;
47069
+ if (event.source !== host?.contentWindow) return;
47070
+ if (data2.ready) {
47071
+ host?.contentWindow?.postMessage({ __colamdSlideRun: 1, token: bridgeToken, code: pendingCode }, "*");
47072
+ return;
47073
+ }
47074
+ if (data2.kind === "class") applyClass(String(data2.name ?? ""), Boolean(data2.value));
47075
+ if (data2.kind === "var") applyVar(String(data2.name ?? ""), data2.value);
47076
+ }
47077
+ function applyClass(name2, value) {
47078
+ if (!SAFE_NAME.test(name2)) return;
47079
+ const surface_ = surface();
47080
+ if (!surface_) return;
47081
+ const cls = `slide-${name2}`;
47082
+ surface_.classList.toggle(cls, value);
47083
+ if (value) appliedClasses.add(cls);
47084
+ else appliedClasses.delete(cls);
47085
+ }
47086
+ function applyVar(name2, value) {
47087
+ if (!SAFE_NAME.test(name2)) return;
47088
+ const surface_ = surface();
47089
+ if (!surface_) return;
47090
+ const prop = `--slide-${name2}`;
47091
+ surface_.style.setProperty(prop, String(value));
47092
+ appliedVars.add(prop);
47093
+ }
47094
+ function resetApplied() {
47095
+ const surface_ = surface();
47096
+ if (surface_) {
47097
+ for (const cls of appliedClasses) surface_.classList.remove(cls);
47098
+ for (const prop of appliedVars) surface_.style.removeProperty(prop);
47099
+ }
47100
+ appliedClasses.clear();
47101
+ appliedVars.clear();
47102
+ }
47103
+ function mountPrintCss() {
47104
+ printing = true;
47105
+ const rules2 = [];
47106
+ for (const [page, dirs] of getSlideDirectives()) {
47107
+ for (const block of dirs.css) {
47108
+ rules2.push(scopeSlideCSS(block, `${PAGE_CLASS_PREFIX}${page}`, `body.${PRINT_CLASS} #editor`));
47109
+ }
47110
+ }
47111
+ printStyle = document.createElement("style");
47112
+ printStyle.id = PRINT_CSS_ID;
47113
+ printStyle.textContent = rules2.join("\n");
47114
+ document.head.appendChild(printStyle);
47115
+ syncChrome();
47116
+ }
47117
+ function unmountPrintCss() {
47118
+ printing = false;
47119
+ printStyle?.remove();
47120
+ printStyle = null;
47121
+ }
47122
+ if (document.body) initSlidesEnhance();
47123
+ else document.addEventListener("DOMContentLoaded", initSlidesEnhance, { once: true });
45280
47124
  /*! Capacitor: https://capacitorjs.com/ - MIT License */
45281
47125
  const createCapacitorPlatforms = (win) => {
45282
47126
  const defaultPlatformMap = /* @__PURE__ */ new Map();
@@ -45878,7 +47722,15 @@ function enterPrintLayout() {
45878
47722
  overflow: "visible"
45879
47723
  });
45880
47724
  override("#editor, .cm-editor, .cm-scroller", { height: "auto", overflow: "visible" });
45881
- return () => undo2.forEach(({ el, cssText }) => el.style.cssText = cssText);
47725
+ const zoomStyle = document.createElement("style");
47726
+ zoomStyle.textContent = ".pele-zoom { display: none !important; }";
47727
+ document.head.append(zoomStyle);
47728
+ const restoreZoom = pauseDiagramZoom();
47729
+ return () => {
47730
+ restoreZoom();
47731
+ zoomStyle.remove();
47732
+ undo2.forEach(({ el, cssText }) => el.style.cssText = cssText);
47733
+ };
45882
47734
  }
45883
47735
  function exportBaseName() {
45884
47736
  const title = (document.title || "").trim();
@@ -45890,8 +47742,8 @@ function isChinese() {
45890
47742
  }
45891
47743
  function defaultBaseName() {
45892
47744
  const d = /* @__PURE__ */ new Date();
45893
- const pad2 = (n) => String(n).padStart(2, "0");
45894
- const stamp = `${d.getFullYear()}${pad2(d.getMonth() + 1)}${pad2(d.getDate())}-${pad2(d.getHours())}${pad2(d.getMinutes())}${pad2(d.getSeconds())}`;
47745
+ const pad3 = (n) => String(n).padStart(2, "0");
47746
+ const stamp = `${d.getFullYear()}${pad3(d.getMonth() + 1)}${pad3(d.getDate())}-${pad3(d.getHours())}${pad3(d.getMinutes())}${pad3(d.getSeconds())}`;
45895
47747
  return `${isChinese() ? "未命名" : "Untitled"}-${stamp}`;
45896
47748
  }
45897
47749
  function escapeHTML(value) {
@@ -45910,11 +47762,11 @@ async function capModule(name2) {
45910
47762
  try {
45911
47763
  switch (name2) {
45912
47764
  case "@capacitor/filesystem":
45913
- return await __vitePreload(() => import("./index-DsYLJ8It.js"), true ? [] : void 0, import.meta.url);
47765
+ return await __vitePreload(() => import("./index--lwcDMTj.js"), true ? [] : void 0, import.meta.url);
45914
47766
  case "@capacitor/share":
45915
- return await __vitePreload(() => import("./index-B6uVUc9e.js"), true ? [] : void 0, import.meta.url);
47767
+ return await __vitePreload(() => import("./index-D0d2vg7k.js"), true ? [] : void 0, import.meta.url);
45916
47768
  case "@capacitor/app":
45917
- return await __vitePreload(() => import("./index-DgC9JAzE.js"), true ? [] : void 0, import.meta.url);
47769
+ return await __vitePreload(() => import("./index-CFKk8_-a.js"), true ? [] : void 0, import.meta.url);
45918
47770
  default:
45919
47771
  return null;
45920
47772
  }
@@ -46043,28 +47895,28 @@ function createCapacitorAPI() {
46043
47895
  setCleanExport(false);
46044
47896
  }
46045
47897
  },
46046
- exportHTML: async (snapshot) => {
47898
+ exportHTML: async (snapshot2) => {
46047
47899
  const f = await fs();
46048
47900
  if (!f) return false;
46049
47901
  const base2 = exportBaseName().replace(/[\\/:*?"<>|]/g, "_");
46050
47902
  const fileName = `${base2}-${Date.now()}.html`;
46051
47903
  const target = `${DOCS_DIR}/exports/${fileName}`;
46052
47904
  const title = escapeHTML(base2);
46053
- const renderedContent = snapshot.document || snapshot.html || `<pre>${escapeHTML(snapshot.content)}</pre>`;
47905
+ const renderedContent = snapshot2.document || snapshot2.html || `<pre>${escapeHTML(snapshot2.content)}</pre>`;
46054
47906
  const documentHTML = `<!doctype html>
46055
47907
  <html lang="zh-CN">
46056
47908
  <head>
46057
47909
  <meta charset="UTF-8">
46058
47910
  <meta name="viewport" content="width=device-width, initial-scale=1">
46059
47911
  <title>${title}</title>
46060
- <style>${snapshot.styles || ""}
47912
+ <style>${snapshot2.styles || ""}
46061
47913
  html, body { height: auto; overflow: visible; }
46062
47914
  body { min-width: 320px; }
46063
47915
  #titlebar, #file-panel { display: none !important; }
46064
47916
  #editor { height: auto !important; min-height: 100vh; overflow: visible !important; padding: 0 !important; }
46065
47917
  </style>
46066
47918
  </head>
46067
- <body class="${escapeHTML(snapshot.bodyClass || "")}">
47919
+ <body class="${escapeHTML(snapshot2.bodyClass || "")}">
46068
47920
  <article class="colamd-document">${renderedContent}</article>
46069
47921
  </body>
46070
47922
  </html>
@@ -46732,8 +48584,8 @@ function renderTabBar() {
46732
48584
  add.addEventListener("mouseenter", () => scheduleTip(add, isChinese$1() ? "新建标签页 · ⌘T" : "New tab · ⌘T", "below", TAB_TIP_DELAY));
46733
48585
  add.addEventListener("mouseleave", hideTip);
46734
48586
  bar.after(add);
46735
- const active = bar.querySelector(".tab-entry.active");
46736
- active?.scrollIntoView({ block: "nearest", inline: "nearest" });
48587
+ const active2 = bar.querySelector(".tab-entry.active");
48588
+ active2?.scrollIntoView({ block: "nearest", inline: "nearest" });
46737
48589
  window.electronAPI.setTabFiles(tabs.map((tab) => tab.filePath).filter((path2) => !!path2));
46738
48590
  }
46739
48591
  function showBlankDocument() {
@@ -47284,8 +49136,8 @@ function applyOutlineActive() {
47284
49136
  buttons.forEach((button, index2) => {
47285
49137
  button.classList.toggle("active", index2 === outlineActiveIndex);
47286
49138
  });
47287
- const active = buttons[outlineActiveIndex];
47288
- if (active) revealOutlineEntry(active);
49139
+ const active2 = buttons[outlineActiveIndex];
49140
+ if (active2) revealOutlineEntry(active2);
47289
49141
  }
47290
49142
  function revealOutlineEntry(button) {
47291
49143
  const panel = filePanelEl();
@@ -47642,7 +49494,7 @@ async function toggleSlideshow() {
47642
49494
  requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
47643
49495
  });
47644
49496
  }
47645
- const started = startSlideshow({
49497
+ const started = await startSlideshow({
47646
49498
  onStart: () => {
47647
49499
  setEditorEditable(false);
47648
49500
  void window.electronAPI.setSlideshowFullscreen(true);