@bytechain.cn/colamd 2.7.13 → 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 +2 -0
  2. package/README_CN.md +2 -0
  3. package/dist/lib/colamd-renderer.js +19817 -18358
  4. package/dist/lib/colamd.css +1 -1
  5. package/dist/renderer/assets/{2DXBBFLN-ALNXA0ap.js → 2DXBBFLN-BcQoTXNK.js} +4 -4
  6. package/dist/renderer/assets/{46IJ22JX-CwxSS7s2.js → 46IJ22JX-Dvln4uUB.js} +5 -5
  7. package/dist/renderer/assets/{4TTDE5I4-CCaQ-Qhr.js → 4TTDE5I4-LOG7xsNo.js} +3 -3
  8. package/dist/renderer/assets/{4UF3HTLV-DZOYgtOD.js → 4UF3HTLV-B5M4TbQl.js} +4 -4
  9. package/dist/renderer/assets/{AAXQQPKT-C-1s3Dqf.js → AAXQQPKT-S6Q6iTwj.js} +8 -8
  10. package/dist/renderer/assets/{AKE5O7KZ-BWT9NTVZ.js → AKE5O7KZ-DgRxWRXD.js} +5 -5
  11. package/dist/renderer/assets/{BNMLP6AG-ByQWPes6.js → BNMLP6AG-DSQgcgO4.js} +7 -7
  12. package/dist/renderer/assets/{DR6PKOQU-BJHswFty.js → DR6PKOQU-BSlXBi4M.js} +3 -3
  13. package/dist/renderer/assets/{E4RJ7UJB-1Eo8TOcw.js → E4RJ7UJB-AOICEUO8.js} +6 -6
  14. package/dist/renderer/assets/{ELSXBIJH-CTihDDj-.js → ELSXBIJH-6yzOt2yu.js} +1 -1
  15. package/dist/renderer/assets/{ERTIBQVS-VlP2Fl8s.js → ERTIBQVS-Bwlpwnl5.js} +4 -4
  16. package/dist/renderer/assets/{F653G4FO-BfRMrcT2.js → F653G4FO-Bv18U9we.js} +8 -8
  17. package/dist/renderer/assets/{FKCDD66M-Dx6nCace.js → FKCDD66M-BACYwspg.js} +1 -1
  18. package/dist/renderer/assets/{FP7KDXVC-JX4wVWHb.js → FP7KDXVC-CzGjSBpi.js} +6 -6
  19. package/dist/renderer/assets/{FT5I3RHX-BKmbu0Ww.js → FT5I3RHX-S570rXpT.js} +7 -7
  20. package/dist/renderer/assets/{GY35JXOZ-BVBmqsqd.js → GY35JXOZ-cSQ3vgtQ.js} +4 -4
  21. package/dist/renderer/assets/{H5EEJPP2-BiAAKO-B.js → H5EEJPP2-B5mRihtC.js} +9 -9
  22. package/dist/renderer/assets/{HWDLEDTA-gm8E-Yqq.js → HWDLEDTA-QxGhC7BD.js} +1 -1
  23. package/dist/renderer/assets/{JZWSX6AR-B3v8qMsV.js → JZWSX6AR-D5J8dvEc.js} +2 -2
  24. package/dist/renderer/assets/{KQOEJWJY-BMTjDHaU.js → KQOEJWJY-B1H_7gPD.js} +1 -1
  25. package/dist/renderer/assets/{KS3BB3KE-UNhg0tjp.js → KS3BB3KE-DLlGsWQC.js} +5 -5
  26. package/dist/renderer/assets/{KXJRRZHI-BkjpheXn.js → KXJRRZHI-rxZ-n8Go.js} +3 -3
  27. package/dist/renderer/assets/{MFVI5XKI-BKnsNeAu.js → MFVI5XKI-CQp2wV67.js} +1 -1
  28. package/dist/renderer/assets/{MWY2J62P-C2fXJt2z.js → MWY2J62P-CdKsEllR.js} +5 -5
  29. package/dist/renderer/assets/{MXGNCBL2-OdlMkSYe.js → MXGNCBL2-CpHADYfy.js} +5 -5
  30. package/dist/renderer/assets/{N6DAJLIZ-DZk90zfQ.js → N6DAJLIZ-z4bfft0m.js} +2 -2
  31. package/dist/renderer/assets/{NU5M23IW-CqrkpDmA.js → NU5M23IW-BdEspGlf.js} +5 -5
  32. package/dist/renderer/assets/{NV4XNBIS-CEOfa376.js → NV4XNBIS-DwWAiQZN.js} +7 -7
  33. package/dist/renderer/assets/{OGLU4SIR-CXCAJdcN.js → OGLU4SIR-B4O60CC1.js} +5 -5
  34. package/dist/renderer/assets/{OUNS5N76-CaxK8E0B.js → OUNS5N76-DRQSAFpx.js} +6 -6
  35. package/dist/renderer/assets/{PU4ISKXV-CkQL-IWp.js → PU4ISKXV-CH7B9Xam.js} +5 -5
  36. package/dist/renderer/assets/{PUZGS23X-B-CGNpKZ.js → PUZGS23X-Czec-t51.js} +1 -1
  37. package/dist/renderer/assets/{Q3IYVLG5-CmIlJsgG.js → Q3IYVLG5-ppP144xP.js} +5 -5
  38. package/dist/renderer/assets/{QYHQDLKZ-Br57AbVX.js → QYHQDLKZ-BqPSAS2H.js} +9 -9
  39. package/dist/renderer/assets/{RZSVICHU-DD3CK-Lf.js → RZSVICHU-_ZqNTL97.js} +1 -1
  40. package/dist/renderer/assets/{UEXXS2NB-BNdzFN7f.js → UEXXS2NB-rgOpII99.js} +1 -1
  41. package/dist/renderer/assets/{UHTQJXKL-Bsu9QNn2.js → UHTQJXKL-AI90fkq9.js} +5 -5
  42. package/dist/renderer/assets/{URA2L2QI-BeIBFAAP.js → URA2L2QI-BDDmGORh.js} +1 -1
  43. package/dist/renderer/assets/{UXCHDUKG-BIB6A9DU.js → UXCHDUKG-DcMu-Kjz.js} +5 -5
  44. package/dist/renderer/assets/{VKNV3BUX-C_MjwJ6m.js → VKNV3BUX-BoFccAWM.js} +6 -6
  45. package/dist/renderer/assets/{VMV7XPHP-D0cww3Fb.js → VMV7XPHP-B4mGwDDN.js} +1 -1
  46. package/dist/renderer/assets/{WEVWDWVA-CCDvMBKl.js → WEVWDWVA-BM5eqE-B.js} +1 -1
  47. package/dist/renderer/assets/{XRRJ35LF-CRwwhzJ0.js → XRRJ35LF-Cb6fWs_U.js} +4 -4
  48. package/dist/renderer/assets/{YFKBLVVN-CH_wsIFW.js → YFKBLVVN-DJPx2596.js} +4 -4
  49. package/dist/renderer/assets/{YHRE5QGZ-_1I4H-Cd.js → YHRE5QGZ-DA0Ne8ZS.js} +7 -7
  50. package/dist/renderer/assets/{ZF3OVT4B-BqoSMdR7.js → ZF3OVT4B-CC3b1pZi.js} +3 -3
  51. package/dist/renderer/assets/{index-gvL3lkzR.js → index--lwcDMTj.js} +3 -3
  52. package/dist/renderer/assets/{index-CtO7mpP3.js → index-5TWFI5jV.js} +1 -1
  53. package/dist/renderer/assets/{index-Du6z3bAn.js → index-B-Tvkk_D.js} +1 -1
  54. package/dist/renderer/assets/{index-C3jLCWOv.js → index-B66yNs8z.js} +1 -1
  55. package/dist/renderer/assets/{index-BgSGixdO.js → index-BUO7yV_Q.js} +1 -1
  56. package/dist/renderer/assets/{index-Dct5tTjE.js → index-BjG9rVTb.js} +1311 -386
  57. package/dist/renderer/assets/{index-BpqOaUd_.js → index-CFKk8_-a.js} +3 -3
  58. package/dist/renderer/assets/{index-alRdsw6J.js → index-CJQRWrTj.js} +1 -1
  59. package/dist/renderer/assets/{index-BXn8SSRO.js → index-CTBBXEX2.js} +1 -1
  60. package/dist/renderer/assets/{index-cLTU2RS5.js → index-CcwQz0gI.js} +1 -1
  61. package/dist/renderer/assets/{index-CGWaYts7.js → index-CipBATEm.js} +1 -1
  62. package/dist/renderer/assets/{index-CU4eUjnS.js → index-Co-0vhM1.js} +1 -1
  63. package/dist/renderer/assets/{index-Dz7ZQeU1.js → index-Cyi8NXI_.js} +1 -1
  64. package/dist/renderer/assets/{index-CwH04Tq_.js → index-D0d2vg7k.js} +3 -3
  65. package/dist/renderer/assets/{index-DtH-vuwI.js → index-D4NskBFS.js} +1 -1
  66. package/dist/renderer/assets/{index-B9mxJmxP.js → index-DEjGaOKF.js} +1 -1
  67. package/dist/renderer/assets/{index-9gnHkoK7.js → index-DI9_AaWi.js} +1 -1
  68. package/dist/renderer/assets/{index-D6SLND4G.css → index-DM3GNRiR.css} +177 -76
  69. package/dist/renderer/assets/{index-DjTtBl71.js → index-Ditiw7Uj.js} +1 -1
  70. package/dist/renderer/assets/{index-DN-WehV_.js → index-DypVmFXi.js} +1 -1
  71. package/dist/renderer/assets/{index-DDMRqKv0.js → index-pHq11714.js} +1 -1
  72. package/dist/renderer/assets/{index-QzYbuPVg.js → index-rA_KpISM.js} +1 -1
  73. package/dist/renderer/assets/{lazy-DVWnMOaz.js → lazy-C1NE8LhM.js} +3 -3
  74. package/dist/renderer/assets/{web-BBDWek-d.js → web-Bct4Qz8N.js} +1 -1
  75. package/dist/renderer/assets/{web-Cmk7I-i1.js → web-CI4szGaS.js} +2 -2
  76. package/dist/renderer/assets/{web-DkHfYGAr.js → web-Db6-iOH9.js} +1 -1
  77. package/dist/renderer/index.html +2 -2
  78. package/package.json +11 -2
  79. package/themes/contract.json +3 -1
@@ -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-DVWnMOaz.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) {
@@ -33129,15 +33460,16 @@ function pushBlockLines(state, from, to, className, ranges) {
33129
33460
  ranges.push({ from: lineFrom, to: lineFrom, deco: BLOCK(className) });
33130
33461
  }
33131
33462
  }
33132
- const QUOTE_PREFIX_RE$2 = /^(?:[ \t]*> ?)+/;
33133
33463
  function hasListSpace(state, markTo) {
33134
33464
  const ch = markTo < state.doc.length ? state.doc.sliceString(markTo, markTo + 1) : "";
33135
- return ch === " " || ch === " ";
33465
+ return ch === " ";
33136
33466
  }
33137
33467
  function pushListItemLines(state, node, ranges) {
33138
33468
  const selfMark = node.getChild("ListMark");
33139
33469
  if (!selfMark || !hasListSpace(state, selfMark.to)) return;
33140
- 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)}`;
33141
33473
  const tree = syntaxTree(state);
33142
33474
  const path2 = [];
33143
33475
  let quoted = false;
@@ -33159,16 +33491,17 @@ function pushListItemLines(state, node, ranges) {
33159
33491
  }
33160
33492
  }
33161
33493
  const first = state.doc.lineAt(node.from).number;
33162
- const ownLast = state.doc.lineAt(node.to).number;
33494
+ const ownLast = state.doc.lineAt(Math.max(node.from, node.to - 1)).number;
33163
33495
  const last2 = node.nextSibling?.name === "ListItem" ? state.doc.lineAt(node.nextSibling.from).number - 1 : ownLast;
33164
33496
  for (let n = first; n <= last2; n++) {
33165
33497
  const line = state.doc.line(n);
33498
+ const isBlank = line.text.replace(QUOTE_PREFIX_RE, "").trim() === "";
33166
33499
  if (n > first && n <= ownLast && line.to <= ownEnd) {
33167
- const body = line.text.replace(QUOTE_PREFIX_RE$2, "");
33500
+ const body = line.text.replace(QUOTE_PREFIX_RE, "");
33168
33501
  if (body.trim() !== "" && !/^[ \t]/.test(body)) break;
33169
33502
  }
33170
33503
  if (n <= ownLast && line.to > ownEnd) {
33171
- const quoteLen = QUOTE_PREFIX_RE$2.exec(line.text)?.[0].length ?? 0;
33504
+ const quoteLen = QUOTE_PREFIX_RE.exec(line.text)?.[0].length ?? 0;
33172
33505
  const indent = /^[ \t]*/.exec(line.text.slice(quoteLen))?.[0].length ?? 0;
33173
33506
  const at = Math.min(line.from + quoteLen + indent, line.to);
33174
33507
  let owner = tree.resolveInner(at, 1);
@@ -33178,10 +33511,12 @@ function pushListItemLines(state, node, ranges) {
33178
33511
  if (body.trim() !== "" && !/^[ \t]/.test(body)) break;
33179
33512
  }
33180
33513
  const paragraph = paragraphs.find((block) => block.from <= line.to && block.to > line.from);
33181
- ranges.push({ from: line.from, to: line.from, deco: Decoration.line({ class: className, attributes: {
33514
+ const lineAttrs = {
33182
33515
  ...attributes,
33183
33516
  ...paragraph ? { "data-list-paragraph": String(paragraph.from) } : {}
33184
- } }) });
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 }) });
33185
33520
  }
33186
33521
  }
33187
33522
  const hide = (from, to) => Decoration.replace({});
@@ -33370,8 +33705,8 @@ function listDepth$1(node) {
33370
33705
  }
33371
33706
  return depth;
33372
33707
  }
33373
- function collectMath(state, text2, excluded, ranges, zones) {
33374
- for (const range of scanMath(text2, excluded)) {
33708
+ function collectMath(state, mathRanges, ranges, zones) {
33709
+ for (const range of mathRanges) {
33375
33710
  if (range.block) zones.push({ from: range.from, to: range.to, kind: "block" });
33376
33711
  if (isActiveLine(state, range.from) || range.block && isBlockActive(state, range.from, range.to)) {
33377
33712
  const delim = range.block ? 2 : 1;
@@ -33425,6 +33760,10 @@ class TaskCheckboxWidget extends WidgetType {
33425
33760
  function collectTaskItems(state, ranges, front) {
33426
33761
  iterateContent$1(state, front, (node) => {
33427
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;
33428
33767
  const raw = state.doc.sliceString(node.from, node.to);
33429
33768
  const checked = /x/i.test(raw);
33430
33769
  ranges.push({
@@ -33871,7 +34210,7 @@ function collectImages(state, ranges, front) {
33871
34210
  return false;
33872
34211
  });
33873
34212
  }
33874
- function collectBlocks(state, ranges, front) {
34213
+ function collectBlocks$1(state, ranges, front, mathRanges) {
33875
34214
  iterateContent$1(state, front, (node) => {
33876
34215
  switch (node.name) {
33877
34216
  case "Blockquote": {
@@ -33889,12 +34228,14 @@ function collectBlocks(state, ranges, front) {
33889
34228
  case "ListMark": {
33890
34229
  if (!hasListSpace(state, node.to)) break;
33891
34230
  const line = state.doc.lineAt(node.from);
33892
- 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;
33893
34234
  const hideFrom = line.from + quoteLen;
33894
34235
  if (node.from > hideFrom) ranges.push({ from: hideFrom, to: node.from, deco: hide(hideFrom, node.from) });
33895
34236
  const raw = state.doc.sliceString(node.from, node.to).trim();
33896
34237
  const after = state.doc.sliceString(node.to, node.to + 4);
33897
- if (/^\s+\[[ xX]\]/.test(after)) {
34238
+ if (/^ +\[[ xX]\]/.test(after)) {
33898
34239
  hideMarker(state, node.from, node.to, ranges, isActiveLine(state, node.from));
33899
34240
  break;
33900
34241
  }
@@ -33915,6 +34256,36 @@ function collectBlocks(state, ranges, front) {
33915
34256
  pushListItemLines(state, node.node, ranges);
33916
34257
  break;
33917
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
+ }
33918
34289
  case "FencedCode": {
33919
34290
  const code = exportingCleanly(state) ? "" : codeInsideFence(state, node);
33920
34291
  if (code !== "") {
@@ -33980,6 +34351,7 @@ function collectInline(state, ranges, front) {
33980
34351
  break;
33981
34352
  }
33982
34353
  case "HeaderMark": {
34354
+ if (!node.node.parent?.name.startsWith("ATXHeading")) break;
33983
34355
  hideMarker(state, from, to, ranges, active2);
33984
34356
  break;
33985
34357
  }
@@ -34060,7 +34432,8 @@ function buildDecorations$1(state, flash) {
34060
34432
  if (flash && flash.to <= state.doc.length) {
34061
34433
  ranges.push({ from: flash.from, to: flash.to, deco: MARK({ class: "cm-md-jump-flash" }) });
34062
34434
  }
34063
- collectBlocks(state, ranges, front);
34435
+ const mathRanges = scanMath(text2, excluded);
34436
+ collectBlocks$1(state, ranges, front, mathRanges);
34064
34437
  collectLinks(state, ranges, front);
34065
34438
  collectFootnotes(state, text2, ranges, front);
34066
34439
  collectHTML(state, ranges, front, zones);
@@ -34072,7 +34445,7 @@ function buildDecorations$1(state, flash) {
34072
34445
  collectTaskItems(state, ranges, front);
34073
34446
  collectMermaid(state, text2, ranges, front, zones);
34074
34447
  collectHighlight(state, text2, ranges, excluded);
34075
- collectMath(state, text2, excluded, ranges, zones);
34448
+ collectMath(state, mathRanges, ranges, zones);
34076
34449
  ranges.sort((a, b) => a.from - b.from || a.deco.startSide - b.deco.startSide || a.to - b.to);
34077
34450
  const builder = new RangeSetBuilder();
34078
34451
  for (const r of ranges) builder.add(r.from, r.to, r.deco);
@@ -41567,64 +41940,195 @@ const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
41567
41940
  markdownLanguage,
41568
41941
  pasteURLAsLink
41569
41942
  }, Symbol.toStringTag, { value: "Module" }));
41570
- const QUOTE_PREFIX_RE$1 = /^(?:[ \t]*> ?)+/;
41571
- const LIST_BODY_RE = /^([ \t]*)(?:([-*+])|(\d+)([.)]))([ \t]+)(\[[ xX]\][ \t]+)?/;
41572
- const INDENT = " ";
41573
- function countQuotes(prefix) {
41574
- let count2 = 0;
41575
- for (let i = 0; i < prefix.length; i++) {
41576
- if (prefix[i] === ">") count2++;
41577
- }
41578
- return count2;
41943
+ const continueMarkup = insertNewlineContinueMarkupCommand({ nonTightLists: false });
41944
+ function getTreeAndFm(state) {
41945
+ return { tree: syntaxTree(state), fmEnd: frontmatterEnd(state.doc) };
41579
41946
  }
41580
- function parseListLine(text2) {
41581
- const quotePrefix = QUOTE_PREFIX_RE$1.exec(text2)?.[0] ?? "";
41582
- const quoteLen = quotePrefix.length;
41583
- const match = LIST_BODY_RE.exec(text2.slice(quoteLen));
41584
- if (!match) return null;
41585
- const lead = match[1].length;
41586
- const box = match[6] ?? "";
41587
- const width = match[0].length - lead - box.length;
41588
- return {
41589
- quoteLen,
41590
- quoteDepth: countQuotes(quotePrefix),
41591
- lead,
41592
- width,
41593
- digits: match[3] ?? "",
41594
- box,
41595
- contentOffset: quoteLen + match[0].length
41596
- };
41947
+ function parseOrderDigits(digits) {
41948
+ const n = Number.parseInt(digits, 10);
41949
+ return Number.isFinite(n) && n >= 0 ? n : 1;
41597
41950
  }
41598
- const continueMarkup = insertNewlineContinueMarkupCommand({ nonTightLists: false });
41599
41951
  function handleEnter(view) {
41600
41952
  const { state } = view;
41953
+ if (state.selection.ranges.length > 1) return false;
41601
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
+ }
41602
41967
  if (!range.empty) return false;
41603
- const line = state.doc.lineAt(range.head);
41604
- if (/^[ \t]*(?:>[ \t]*)+$/.test(line.text)) {
41605
- const lastGt = line.text.lastIndexOf(">");
41606
- if (range.head >= line.from + lastGt + 1) {
41607
- const depth = countQuotes(line.text);
41608
- 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}`;
41609
42033
  view.dispatch({
41610
- changes: { from: delFrom, to: line.to, insert: "" },
41611
- selection: { anchor: delFrom },
42034
+ changes: { from: line.to, to: line.to, insert: insert22 },
42035
+ selection: { anchor: line.to + insert22.length },
41612
42036
  scrollIntoView: true,
41613
42037
  userEvent: "input"
41614
42038
  });
41615
42039
  return true;
41616
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;
41617
42049
  }
41618
- if (!QUOTE_PREFIX_RE$1.test(line.text) && !parseListLine(line.text) && !/^[ \t]/.test(line.text)) {
41619
- 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
+ }
41620
42076
  }
41621
- 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;
41622
42123
  }
41623
42124
  function deleteTaskBox(view) {
41624
42125
  const { state } = view;
42126
+ if (state.selection.ranges.length > 1) return false;
41625
42127
  const range = state.selection.main;
41626
42128
  if (!range.empty) return false;
42129
+ const { tree, fmEnd } = getTreeAndFm(state);
41627
42130
  const line = state.doc.lineAt(range.head);
42131
+ if (isExcludedLine(state.doc, tree, line.number, fmEnd)) return false;
41628
42132
  const self2 = parseListLine(line.text);
41629
42133
  if (!self2 || !self2.box) return false;
41630
42134
  const contentStart = line.from + self2.contentOffset;
@@ -41639,22 +42143,51 @@ function deleteTaskBox(view) {
41639
42143
  }
41640
42144
  function deleteAtLineStart(view) {
41641
42145
  const { state } = view;
42146
+ if (state.selection.ranges.length > 1) return false;
41642
42147
  const range = state.selection.main;
41643
42148
  if (!range.empty) return false;
42149
+ const { tree, fmEnd } = getTreeAndFm(state);
41644
42150
  const line = state.doc.lineAt(range.head);
42151
+ if (isExcludedLine(state.doc, tree, line.number, fmEnd)) return false;
41645
42152
  const self2 = parseListLine(line.text);
41646
42153
  if (self2 && range.head <= line.from + self2.contentOffset) {
41647
- 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
+ }
41648
42180
  const from = line.from + self2.quoteLen;
41649
42181
  const to = line.from + self2.contentOffset;
41650
42182
  view.dispatch({
41651
42183
  changes: { from, to, insert: "" },
41652
42184
  selection: { anchor: from },
42185
+ scrollIntoView: true,
41653
42186
  userEvent: "delete"
41654
42187
  });
41655
42188
  return true;
41656
42189
  }
41657
- const quotePrefix = QUOTE_PREFIX_RE$1.exec(line.text)?.[0] ?? "";
42190
+ const quotePrefix = QUOTE_PREFIX_RE.exec(line.text)?.[0] ?? "";
41658
42191
  const quoteLen = quotePrefix.length;
41659
42192
  const head = /^#{1,6}[ \t]?/.exec(line.text.slice(quoteLen));
41660
42193
  if (head && head[0].length > 0 && range.head >= line.from + quoteLen && range.head <= line.from + quoteLen + head[0].length) {
@@ -41668,7 +42201,7 @@ function deleteAtLineStart(view) {
41668
42201
  }
41669
42202
  if (quoteLen > 0 && range.head <= line.from + quoteLen) {
41670
42203
  if (line.text.length > quoteLen || range.head > line.from) {
41671
- const innerMatch = /[ \t]*> ?$/.exec(quotePrefix);
42204
+ const innerMatch = />[ \t]?$/.exec(quotePrefix);
41672
42205
  const delFrom = innerMatch ? line.from + quoteLen - innerMatch[0].length : line.from;
41673
42206
  view.dispatch({
41674
42207
  changes: { from: delFrom, to: line.from + quoteLen, insert: "" },
@@ -41680,21 +42213,46 @@ function deleteAtLineStart(view) {
41680
42213
  }
41681
42214
  return false;
41682
42215
  }
41683
- function indentListItem(view, direction) {
42216
+ function handleTab(view, direction) {
41684
42217
  const { state } = view;
42218
+ if (state.selection.ranges.length > 1) return false;
41685
42219
  const range = state.selection.main;
41686
- if (!range.empty) return false;
41687
- 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);
41688
42235
  const self2 = parseListLine(line.text);
41689
42236
  if (!self2) {
41690
- const quotePrefix = QUOTE_PREFIX_RE$1.exec(line.text)?.[0];
41691
- if (!quotePrefix) return false;
41692
- 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;
41693
42251
  if (direction === 1) {
41694
- const at = Math.max(range.head, bodyFrom2);
42252
+ const at = Math.max(range.head, bodyFrom);
41695
42253
  view.dispatch({
41696
- changes: { from: at, to: at, insert: INDENT },
41697
- selection: { anchor: at + INDENT.length },
42254
+ changes: { from: at, to: at, insert: " " },
42255
+ selection: { anchor: at + 1 },
41698
42256
  scrollIntoView: true,
41699
42257
  userEvent: "input"
41700
42258
  });
@@ -41702,83 +42260,235 @@ function indentListItem(view, direction) {
41702
42260
  }
41703
42261
  const spaces2 = /^[ \t]+/.exec(line.text.slice(quotePrefix.length))?.[0] ?? "";
41704
42262
  if (!spaces2) return true;
41705
- 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)));
41706
42267
  view.dispatch({
41707
- changes: { from: bodyFrom2, to: bodyFrom2 + remove2, insert: "" },
41708
- selection: { anchor: Math.max(bodyFrom2, range.head - remove2) },
42268
+ changes: changes2,
42269
+ selection: { anchor },
41709
42270
  scrollIntoView: true,
41710
42271
  userEvent: "input"
41711
42272
  });
41712
42273
  return true;
41713
42274
  }
41714
- 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;
41715
42279
  if (direction === 1) {
41716
- const parent2 = parentItem(state, line, self2.lead, self2.quoteDepth);
41717
- const target = parent2 ? parent2.lead + parent2.width : self2.lead + self2.width;
41718
- const lead2 = Math.max(target, self2.lead + INDENT.length);
41719
- 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) };
41720
- 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)));
41721
42297
  view.dispatch({
41722
- changes,
41723
- selection: { anchor: changes.mapPos(range.head, 1) },
42298
+ changes: changes2,
42299
+ selection: { anchor },
41724
42300
  scrollIntoView: true,
41725
42301
  userEvent: "input"
41726
42302
  });
41727
42303
  return true;
41728
42304
  }
41729
- const parent = parentItem(state, line, self2.lead - 1, self2.quoteDepth);
41730
- const lead = parent ? parent.lead : 0;
41731
- 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
+ );
41732
42327
  view.dispatch({
41733
- changes: { from: bodyFrom, to: bodyFrom + self2.lead, insert: " ".repeat(lead) },
41734
- selection: { anchor: Math.max(bodyFrom + lead, range.head - (self2.lead - lead)) },
42328
+ changes,
42329
+ selection: { anchor: nextAnchor },
41735
42330
  scrollIntoView: true,
41736
42331
  userEvent: "input"
41737
42332
  });
41738
42333
  return true;
41739
42334
  }
41740
- function freshSublist(state, line, depth, self2) {
41741
- if (!self2.digits) return false;
41742
- for (let number2 = line.number - 1; number2 >= 1; number2--) {
41743
- const prev = state.doc.line(number2);
41744
- const prevQuote = QUOTE_PREFIX_RE$1.exec(prev.text)?.[0] ?? "";
41745
- if (countQuotes(prevQuote) !== self2.quoteDepth) break;
41746
- const rest = prev.text.slice(prevQuote.length);
41747
- if (rest.trim() === "") break;
41748
- const prevLine = parseListLine(prev.text);
41749
- if (!prevLine) {
41750
- 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;
41751
42346
  break;
41752
42347
  }
41753
- if (prevLine.lead === depth) return false;
41754
- if (prevLine.lead < depth) break;
41755
42348
  }
41756
- return true;
41757
- }
41758
- function parentItem(state, line, lead, quoteDepth) {
41759
- for (let number2 = line.number - 1; number2 >= 1; number2--) {
41760
- const prev = state.doc.line(number2);
41761
- const prevQuote = QUOTE_PREFIX_RE$1.exec(prev.text)?.[0] ?? "";
41762
- if (countQuotes(prevQuote) !== quoteDepth) return null;
41763
- const rest = prev.text.slice(prevQuote.length);
41764
- if (rest.trim() === "") return null;
41765
- const prevLine = parseListLine(prev.text);
41766
- if (prevLine) {
41767
- if (prevLine.lead <= lead) return prevLine;
41768
- 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
+ }
41769
42378
  }
41770
- if (/^[ \t]*/.exec(rest)[0].length <= lead) return null;
41771
42379
  }
41772
- 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;
42390
+ }
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;
41773
42446
  }
41774
- const listInput = Prec.high(keymap.of([
41775
- { key: "Enter", run: handleEnter },
41776
- { key: "Backspace", run: deleteTaskBox },
41777
- { key: "Backspace", run: deleteAtLineStart },
41778
- { key: "Backspace", run: deleteMarkupBackward },
41779
- { key: "Tab", run: (view) => indentListItem(view, 1) },
41780
- { key: "Shift-Tab", run: (view) => indentListItem(view, -1) }
41781
- ]));
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
+ ];
41782
42492
  const setSearchHighlight = StateEffect.define();
41783
42493
  const searchHighlightField = StateField.define({
41784
42494
  create: () => Decoration.none,
@@ -41794,7 +42504,7 @@ function legacy(parser2) {
41794
42504
  return new LanguageSupport(StreamLanguage.define(parser2));
41795
42505
  }
41796
42506
  function sql(dialectName) {
41797
- return __vitePreload(() => import("./index-DN-WehV_.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] }));
41798
42508
  }
41799
42509
  const languages = [
41800
42510
  // New-style language modes
@@ -41802,7 +42512,7 @@ const languages = [
41802
42512
  name: "C",
41803
42513
  extensions: ["c", "h", "ino"],
41804
42514
  load() {
41805
- return __vitePreload(() => import("./index-C3jLCWOv.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());
41806
42516
  }
41807
42517
  }),
41808
42518
  /* @__PURE__ */ LanguageDescription.of({
@@ -41810,7 +42520,7 @@ const languages = [
41810
42520
  alias: ["cpp"],
41811
42521
  extensions: ["cpp", "c++", "cc", "cxx", "hpp", "h++", "hh", "hxx"],
41812
42522
  load() {
41813
- return __vitePreload(() => import("./index-C3jLCWOv.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());
41814
42524
  }
41815
42525
  }),
41816
42526
  /* @__PURE__ */ LanguageDescription.of({
@@ -41832,7 +42542,7 @@ const languages = [
41832
42542
  name: "Go",
41833
42543
  extensions: ["go"],
41834
42544
  load() {
41835
- return __vitePreload(() => import("./index-cLTU2RS5.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());
41836
42546
  }
41837
42547
  }),
41838
42548
  /* @__PURE__ */ LanguageDescription.of({
@@ -41847,7 +42557,7 @@ const languages = [
41847
42557
  name: "Java",
41848
42558
  extensions: ["java"],
41849
42559
  load() {
41850
- return __vitePreload(() => import("./index-BXn8SSRO.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());
41851
42561
  }
41852
42562
  }),
41853
42563
  /* @__PURE__ */ LanguageDescription.of({
@@ -41862,7 +42572,7 @@ const languages = [
41862
42572
  name: "Jinja",
41863
42573
  extensions: ["j2", "jinja", "jinja2"],
41864
42574
  load() {
41865
- return __vitePreload(() => import("./index-Du6z3bAn.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());
41866
42576
  }
41867
42577
  }),
41868
42578
  /* @__PURE__ */ LanguageDescription.of({
@@ -41870,7 +42580,7 @@ const languages = [
41870
42580
  alias: ["json5"],
41871
42581
  extensions: ["json", "map"],
41872
42582
  load() {
41873
- return __vitePreload(() => import("./index-DtH-vuwI.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());
41874
42584
  }
41875
42585
  }),
41876
42586
  /* @__PURE__ */ LanguageDescription.of({
@@ -41884,14 +42594,14 @@ const languages = [
41884
42594
  name: "LESS",
41885
42595
  extensions: ["less"],
41886
42596
  load() {
41887
- return __vitePreload(() => import("./index-alRdsw6J.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());
41888
42598
  }
41889
42599
  }),
41890
42600
  /* @__PURE__ */ LanguageDescription.of({
41891
42601
  name: "Liquid",
41892
42602
  extensions: ["liquid"],
41893
42603
  load() {
41894
- return __vitePreload(() => import("./index-CU4eUjnS.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());
41895
42605
  }
41896
42606
  }),
41897
42607
  /* @__PURE__ */ LanguageDescription.of({
@@ -41923,7 +42633,7 @@ const languages = [
41923
42633
  name: "PHP",
41924
42634
  extensions: ["php", "php3", "php4", "php5", "php7", "phtml"],
41925
42635
  load() {
41926
- return __vitePreload(() => import("./index-DjTtBl71.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());
41927
42637
  }
41928
42638
  }),
41929
42639
  /* @__PURE__ */ LanguageDescription.of({
@@ -41944,28 +42654,28 @@ const languages = [
41944
42654
  extensions: ["BUILD", "bzl", "py", "pyw"],
41945
42655
  filename: /^(BUCK|BUILD)$/,
41946
42656
  load() {
41947
- return __vitePreload(() => import("./index-QzYbuPVg.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());
41948
42658
  }
41949
42659
  }),
41950
42660
  /* @__PURE__ */ LanguageDescription.of({
41951
42661
  name: "Rust",
41952
42662
  extensions: ["rs"],
41953
42663
  load() {
41954
- return __vitePreload(() => import("./index-9gnHkoK7.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());
41955
42665
  }
41956
42666
  }),
41957
42667
  /* @__PURE__ */ LanguageDescription.of({
41958
42668
  name: "Sass",
41959
42669
  extensions: ["sass"],
41960
42670
  load() {
41961
- return __vitePreload(() => import("./index-BgSGixdO.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 }));
41962
42672
  }
41963
42673
  }),
41964
42674
  /* @__PURE__ */ LanguageDescription.of({
41965
42675
  name: "SCSS",
41966
42676
  extensions: ["scss"],
41967
42677
  load() {
41968
- return __vitePreload(() => import("./index-BgSGixdO.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());
41969
42679
  }
41970
42680
  }),
41971
42681
  /* @__PURE__ */ LanguageDescription.of({
@@ -42000,7 +42710,7 @@ const languages = [
42000
42710
  name: "WebAssembly",
42001
42711
  extensions: ["wat", "wast"],
42002
42712
  load() {
42003
- return __vitePreload(() => import("./index-B9mxJmxP.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());
42004
42714
  }
42005
42715
  }),
42006
42716
  /* @__PURE__ */ LanguageDescription.of({
@@ -42008,7 +42718,7 @@ const languages = [
42008
42718
  alias: ["rss", "wsdl", "xsd"],
42009
42719
  extensions: ["xml", "xsl", "xsd", "svg"],
42010
42720
  load() {
42011
- return __vitePreload(() => import("./index-Dz7ZQeU1.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());
42012
42722
  }
42013
42723
  }),
42014
42724
  /* @__PURE__ */ LanguageDescription.of({
@@ -42016,7 +42726,7 @@ const languages = [
42016
42726
  alias: ["yml"],
42017
42727
  extensions: ["yaml", "yml"],
42018
42728
  load() {
42019
- return __vitePreload(() => import("./index-CGWaYts7.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());
42020
42730
  }
42021
42731
  }),
42022
42732
  // Legacy modes ported from CodeMirror 5
@@ -42805,13 +43515,13 @@ const languages = [
42805
43515
  name: "Vue",
42806
43516
  extensions: ["vue"],
42807
43517
  load() {
42808
- return __vitePreload(() => import("./index-CtO7mpP3.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());
42809
43519
  }
42810
43520
  }),
42811
43521
  /* @__PURE__ */ LanguageDescription.of({
42812
43522
  name: "Angular Template",
42813
43523
  load() {
42814
- return __vitePreload(() => import("./index-DDMRqKv0.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());
42815
43525
  }
42816
43526
  })
42817
43527
  ];
@@ -42870,205 +43580,271 @@ const editorTheme = EditorView.theme({
42870
43580
  ".cm-searchMatch": { backgroundColor: "var(--search-match-bg, color-mix(in srgb, var(--text-color) 16%, transparent))" },
42871
43581
  ".cm-searchMatch-selected": { backgroundColor: "var(--search-current-bg, color-mix(in srgb, var(--text-color) 26%, transparent))" }
42872
43582
  });
42873
- const QUOTE_PREFIX_RE = /^(?:[ \t]*> ?)+/;
42874
- const LIST_LINE = /^(?:[ \t]*> ?)*[ \t]*(?:[-*+]|\d+[.)])[ \t]/;
42875
- const INDENTED = /^(?:[ \t]*> ?)*[ \t]/;
42876
- 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;
42877
43586
  let patching = false;
42878
- const renumberLists = EditorState.transactionFilter.of((tr) => {
42879
- if (!tr.docChanged) return tr;
42880
- const event = tr.annotation(Transaction.userEvent);
42881
- if (!event || event.startsWith("undo") || event.startsWith("redo")) return tr;
42882
- const before = syntaxTree(tr.startState);
42883
- if (!touchesOrderedList(before, tr.changes)) return tr;
42884
- const { oldRange, newRange } = affectedRanges(tr, before);
42885
- const beforeSlice = tr.startState.doc.sliceString(oldRange.from, oldRange.to);
42886
- const oldLists = orderedLists(markdownParser.parse(beforeSlice), beforeSlice);
42887
- const slice = tr.newDoc.sliceString(newRange.from, newRange.to);
42888
- const changes = [];
42889
- for (const list of orderedLists(markdownParser.parse(slice), slice)) {
42890
- const plan = renumberPlan(list, oldLists, tr.changes, newRange.from, oldRange.from);
42891
- if (!plan.run) continue;
42892
- const start = plan.resetToOne ? 1 : Number.parseInt(slice.slice(list.marks[0].from, list.marks[0].to), 10);
42893
- if (!Number.isFinite(start)) continue;
42894
- list.marks.forEach((mark, index2) => {
42895
- const now = slice.slice(mark.from, mark.to);
42896
- const want = `${start + index2}${now.endsWith(")") ? ")" : "."}`;
42897
- if (now !== want) changes.push({ from: newRange.from + mark.from, to: newRange.from + mark.to, insert: want });
42898
- });
42899
- }
42900
- if (changes.length === 0) return tr;
42901
- if (patching) return tr;
42902
- const patch = ChangeSet.of(changes, tr.newDoc.length);
42903
- patching = true;
42904
- try {
42905
- return tr.startState.update({
42906
- changes: tr.changes.compose(patch),
42907
- selection: tr.selection ? tr.selection.map(patch) : void 0,
42908
- effects: tr.effects,
42909
- // `Transaction.annotations` 不是公开字段,这里只把 userEvent 传下去:
42910
- // 撤销分组和「这是一次编辑」的语义都靠它
42911
- userEvent: event,
42912
- scrollIntoView: tr.scrollIntoView
42913
- });
42914
- } finally {
42915
- patching = false;
42916
- }
42917
- });
42918
- function itemHasLazyBreak(item, slice) {
42919
- let ownEnd = item.to;
42920
- for (let child = item.firstChild; child; child = child.nextSibling) {
42921
- if (child.name === "BulletList" || child.name === "OrderedList") {
42922
- ownEnd = child.from;
42923
- 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
+ }
42924
43660
  }
42925
- }
42926
- const lines = slice.slice(item.from, ownEnd).split("\n");
42927
- for (let i = 1; i < lines.length; i++) {
42928
- const body = lines[i].replace(QUOTE_PREFIX_RE, "");
42929
- if (body.trim() !== "" && !/^[ \t]/.test(body)) return true;
42930
- }
42931
- return false;
42932
- }
42933
- function orderedLists(tree, slice) {
42934
- const lists = [];
42935
- tree.iterate({
42936
- enter(node) {
42937
- if (node.name !== "OrderedList") return;
42938
- let marks = [];
42939
- let segFrom = node.from;
42940
- let segTo = node.from;
42941
- let splitFromAbove = false;
42942
- const flush = (nextSplit) => {
42943
- if (marks.length > 0) lists.push({ from: segFrom, to: segTo, splitFromAbove, marks });
42944
- marks = [];
42945
- if (nextSplit) splitFromAbove = true;
42946
- };
42947
- for (let item = node.node.firstChild; item; item = item.nextSibling) {
42948
- if (item.name !== "ListItem") continue;
42949
- const mark = item.getChild("ListMark");
42950
- if (!mark) continue;
42951
- const after = slice[mark.to];
42952
- if (after !== " " && after !== " ") continue;
42953
- if (marks.length === 0) segFrom = item.from;
42954
- marks.push({ from: mark.from, to: mark.to });
42955
- segTo = item.to;
42956
- if (itemHasLazyBreak(item, slice)) flush(true);
42957
- }
42958
- 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;
42959
43692
  }
42960
43693
  });
42961
- return lists;
42962
- }
42963
- function touchesOrderedList(tree, changes) {
42964
- let hit = false;
42965
- changes.iterChangedRanges((fromA, toA) => {
42966
- if (hit) return;
42967
- const last2 = Math.max(fromA, toA - 1);
42968
- for (const [pos, side] of [[fromA, -1], [fromA, 1], [last2, -1], [last2, 1]]) {
42969
- if (enclosingOrderedList(tree, pos, side)) {
42970
- hit = true;
42971
- 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;
42972
43734
  }
42973
43735
  }
42974
- });
42975
- return hit;
43736
+ cache2.set(lineNumber, excluded);
43737
+ return excluded;
43738
+ };
42976
43739
  }
42977
- function enclosingOrderedList(tree, pos, side) {
42978
- let node = tree.resolveInner(Math.min(Math.max(pos, 0), tree.length), side);
42979
- while (node) {
42980
- if (node.name === "OrderedList") return node;
42981
- 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;
42982
43749
  }
42983
- return null;
43750
+ return blocks;
42984
43751
  }
42985
- function affectedRanges(tr, before) {
42986
- let first = -1;
42987
- tr.changes.iterChangedRanges((fromA) => {
42988
- if (first < 0) first = fromA;
42989
- });
42990
- if (first < 0) {
42991
- return {
42992
- oldRange: { from: 0, to: tr.startState.doc.length },
42993
- newRange: { from: 0, to: tr.newDoc.length }
42994
- };
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;
42995
43761
  }
42996
- let block = before.resolveInner(first, 1);
42997
- while (block && block.parent && block.parent.name !== "Document") block = block.parent;
42998
- const oldBase = block ? block.from : first;
42999
- const oldFrom = tr.startState.doc.lineAt(Math.min(Math.max(oldBase, 0), tr.startState.doc.length)).from;
43000
- const oldTo = listClusterEnd(tr.startState.doc, oldFrom);
43001
- const mapped = tr.changes.mapPos(oldBase, -1);
43002
- const newFrom = tr.newDoc.lineAt(Math.min(Math.max(mapped, 0), tr.newDoc.length)).from;
43003
- const newTo = listClusterEnd(tr.newDoc, newFrom);
43004
- return {
43005
- oldRange: { from: oldFrom, to: oldTo },
43006
- newRange: { from: newFrom, to: newTo }
43007
- };
43762
+ return blocks;
43008
43763
  }
43009
- function listClusterEnd(doc2, from) {
43010
- const first = doc2.lineAt(from);
43011
- let end = first.to;
43012
- let blank = false;
43013
- const stop = Math.min(doc2.lines, first.number + MAX_SCAN_LINES);
43014
- for (let number2 = first.number + 1; number2 <= stop; number2++) {
43015
- const line = doc2.line(number2);
43016
- const stripped = line.text.replace(QUOTE_PREFIX_RE, "");
43017
- if (stripped.trim() === "") {
43018
- blank = true;
43019
- end = line.to;
43020
- 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
+ });
43021
43784
  }
43022
- if (blank && !LIST_LINE.test(line.text) && !INDENTED.test(line.text)) break;
43023
- blank = false;
43024
- end = line.to;
43025
43785
  }
43026
- return end;
43786
+ return map;
43027
43787
  }
43028
- function renumberPlan(list, oldLists, changes, newOffset, oldOffset) {
43029
- const listNewFrom = newOffset + list.from;
43030
- const listNewTo = newOffset + list.to;
43031
- const old = oldLists.find((item) => {
43032
- const mappedFrom = changes.mapPos(oldOffset + item.from, 1);
43033
- const mappedTo = changes.mapPos(oldOffset + item.to, -1);
43034
- 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
+ }
43035
43797
  });
43036
- if (list.splitFromAbove && old) {
43037
- const oldFirstMapped = changes.mapPos(oldOffset + old.marks[0].from, 1);
43038
- if (oldFirstMapped < newOffset + list.marks[0].from) {
43039
- 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;
43040
43818
  }
43041
43819
  }
43042
- let touchedThisSegment = false;
43043
- changes.iterChangedRanges((_fromA, _toA, fromB, toB) => {
43044
- if (toB >= listNewFrom - 1 && fromB <= listNewTo + 1) touchedThisSegment = true;
43045
- });
43046
- if (!touchedThisSegment) return { run: false, resetToOne: false };
43047
- if (!old) return { run: true, resetToOne: false };
43048
- if (old.marks.length !== list.marks.length) return { run: true, resetToOne: false };
43049
- return { run: touchedMark(changes, old, oldOffset), resetToOne: false };
43050
- }
43051
- function touchedMark(changes, list, oldOffset) {
43052
- let hit = false;
43053
- changes.iterChangedRanges((fromA, toA) => {
43054
- if (hit) return;
43055
- for (const raw of list.marks) {
43056
- const markFrom = oldOffset + raw.from;
43057
- const markTo = oldOffset + raw.to;
43058
- if (fromA <= markFrom && toA >= markFrom) {
43059
- hit = true;
43060
- return;
43061
- }
43062
- if (fromA < markTo && toA > markFrom) {
43063
- hit = true;
43064
- 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;
43065
43827
  }
43066
43828
  }
43067
- });
43068
- 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 };
43069
43842
  }
43070
43843
  const editableCompartment = new Compartment();
43071
- const markdownParser = commonmarkLanguage.parser.configure([GFM]);
43844
+ const markdownParser = commonmarkLanguage.parser.configure([
43845
+ GFM,
43846
+ { remove: ["SetextHeading"] }
43847
+ ]);
43072
43848
  const markdownBase = new Language(
43073
43849
  commonmarkLanguage.data,
43074
43850
  // `Language` 只把 parser 当 CodeMirror 自己的 Parser 接口看,不带 configure;
@@ -43086,7 +43862,7 @@ function stateExtensions() {
43086
43862
  // 看着像渲染故障。查找替换的高亮是 search 扩展自己的,不在这里。
43087
43863
  // 增删有序列表项时把序号排一遍(见 list-renumber.ts)。它是**写文件**的一层,
43088
43864
  // 所以只认用户自己的编辑,打开文件、外部写入、导出都不碰。
43089
- renumberLists,
43865
+ createRenumberLists(markdownParser),
43090
43866
  // markdown 语言支持 + 语法高亮(颜色走 CSS 变量,深浅主题自动跟随)
43091
43867
  markdown({ base: markdownBase, codeLanguages: languages, addKeymap: false }),
43092
43868
  syntaxHighlighting(markdownHighlightStyle),
@@ -43719,22 +44495,55 @@ function getEditorHandle() {
43719
44495
  return handle$1;
43720
44496
  }
43721
44497
  const livePreviewCompartment = new Compartment();
43722
- const taskMarkerAtomicRanges = EditorView.atomicRanges.of((view) => {
44498
+ const listPrefixAtomicRanges = EditorView.atomicRanges.of((view) => {
43723
44499
  const doc2 = view.state.doc;
44500
+ const tree = syntaxTree(view.state);
44501
+ const fmEnd = frontmatterEnd(doc2);
43724
44502
  const ranges = [];
43725
- syntaxTree(view.state).iterate({
43726
- enter: (node) => {
43727
- if (node.name !== "TaskMarker") return;
43728
- const line = doc2.lineAt(node.from);
43729
- const prefix = doc2.sliceString(line.from, node.from);
43730
- const quoteLen = /^(?:[ \t]*> ?)+/.exec(prefix)?.[0].length ?? 0;
43731
- const listPart = prefix.slice(quoteLen);
43732
- const from = /^[ \t]*(?:[-*+]|\d+[.)])[ \t]+$/.test(listPart) ? line.from + quoteLen : node.from;
43733
- const trailing = doc2.sliceString(node.to, Math.min(node.to + 1, line.to)) === " " ? node.to + 1 : node.to;
43734
- 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 });
43735
44544
  }
43736
- });
43737
- 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);
43738
44547
  });
43739
44548
  const ATOMIC_MARK = Decoration.replace({});
43740
44549
  function isSourceMode(state) {
@@ -43779,10 +44588,8 @@ function editorExtensions(sourceMode, editable2, onChange) {
43779
44588
  // 检索高亮。面板靠 effect 改它,而 effect 得有 StateField 接住;
43780
44589
  // 不装这一条,检索面板会以为高亮画上了,实际什么也没发生。
43781
44590
  searchHighlightField,
43782
- // 任务项的复选框是一个 replace widget,但没声明成原子区间时,光标能停在
43783
- // `[ ]` 两个方框之间那一格里:左右键要一格一格挪过去,停在里面打字又把
43784
- // `- [ ]` 敲成 `- [x]` 之类的残骸(#164)。声明成原子区间后,光标一次跨过它。
43785
- taskMarkerAtomicRanges,
44591
+ // 列表前缀与任务复选框原子区间:一次跨过 `[ ] ` 与有序列表的 `1. ` 前缀。
44592
+ listPrefixAtomicRanges,
43786
44593
  editableCompartment.of(EditorView.editable.of(editable2)),
43787
44594
  // 文档变化的唯一出口:把新文本交给外壳
43788
44595
  EditorView.updateListener.of((update) => {
@@ -43886,6 +44693,17 @@ function lineKind(line, includeList = true) {
43886
44693
  if ((line.textContent ?? "").trim() === "" && line.querySelector("img") === null) return "empty";
43887
44694
  return "p";
43888
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
+ }
43889
44707
  function listDepth(line) {
43890
44708
  for (let depth = 6; depth >= 0; depth--) {
43891
44709
  if (line.classList.contains(`cm-md-li-${depth}`)) return depth;
@@ -44010,11 +44828,11 @@ function renderCode(lines) {
44010
44828
  function renderGroup(kind, lines, ownerDepth = -1) {
44011
44829
  if (kind === "code") return renderCode(lines);
44012
44830
  if (kind === "mermaid") {
44013
- const widget = lines[0].querySelector(".cm-md-mermaid");
44831
+ const widget = widgetIn(lines[0], ".cm-md-mermaid");
44014
44832
  return widget ? `<div class="${widget.className}">${widget.innerHTML}</div>` : "";
44015
44833
  }
44016
44834
  if (kind === "math") {
44017
- const widget = lines[0].querySelector(".cm-md-math-block");
44835
+ const widget = widgetIn(lines[0], ".cm-md-math-block");
44018
44836
  return widget ? `<div>${widget.innerHTML}</div>` : "";
44019
44837
  }
44020
44838
  if (kind === "li") return renderList(lines);
@@ -44022,7 +44840,7 @@ function renderGroup(kind, lines, ownerDepth = -1) {
44022
44840
  return `<blockquote>${lines.map((line) => `<p>${lineHTML(line)}</p>`).join("")}</blockquote>`;
44023
44841
  }
44024
44842
  if (kind === "table") {
44025
- const table = lines[0].querySelector(".cm-md-table-widget");
44843
+ const table = widgetIn(lines[0], ".cm-md-table-widget");
44026
44844
  if (!table) return "";
44027
44845
  const clone = table.cloneNode(true);
44028
44846
  for (const shell of Array.from(clone.querySelectorAll(".cm-md-math, .cm-md-mermaid-ready"))) {
@@ -44030,6 +44848,7 @@ function renderGroup(kind, lines, ownerDepth = -1) {
44030
44848
  }
44031
44849
  for (const element of [clone, ...Array.from(clone.querySelectorAll("*"))]) {
44032
44850
  element.classList.remove(...Array.from(element.classList).filter((name2) => name2.startsWith("cm-md-")));
44851
+ if (element.classList.length === 0) element.removeAttribute("class");
44033
44852
  element.removeAttribute("contenteditable");
44034
44853
  for (const attribute of ["data-source-from", "data-source-to", "data-list-path", "data-line"]) {
44035
44854
  element.removeAttribute(attribute);
@@ -44091,6 +44910,12 @@ function blocksHTML(nodes, ownerDepth = -1) {
44091
44910
  continue;
44092
44911
  }
44093
44912
  if (!isLineElement(node)) {
44913
+ const widgetKind = blockWidgetKind(node);
44914
+ if (widgetKind) {
44915
+ html2 += renderGroup(widgetKind, [node], ownerDepth);
44916
+ index2 += 1;
44917
+ continue;
44918
+ }
44094
44919
  const inline = [];
44095
44920
  while (index2 < nodes.length && !isLineElement(nodes[index2])) {
44096
44921
  inline.push(inlineHTML(nodes[index2]));
@@ -44143,7 +44968,7 @@ body.${PAPER_CLASS} #editor .cm-scroller { display: block !important; height: au
44143
44968
  天生没有控件)。内联样式是 pele 自己写的,!important 才压得过。 */
44144
44969
  body.${PAPER_CLASS} .pele-zoom { display: none !important; }
44145
44970
  `;
44146
- function nextFrame() {
44971
+ function nextFrame$1() {
44147
44972
  return new Promise((resolve) => {
44148
44973
  requestAnimationFrame(() => resolve());
44149
44974
  });
@@ -44166,10 +44991,10 @@ function setFullRender(on) {
44166
44991
  }
44167
44992
  async function renderWholeDocument() {
44168
44993
  const ok = setFullRender(true);
44169
- await nextFrame();
44994
+ await nextFrame$1();
44170
44995
  const deadline = Date.now() + RENDER_TIMEOUT_MS;
44171
- while (!fullyRendered() && Date.now() < deadline) await nextFrame();
44172
- await nextFrame();
44996
+ while (!fullyRendered() && Date.now() < deadline) await nextFrame$1();
44997
+ await nextFrame$1();
44173
44998
  return ok;
44174
44999
  }
44175
45000
  function restoreViewport() {
@@ -44675,7 +45500,7 @@ function setupFootnotePreview(root) {
44675
45500
  }, { passive: true });
44676
45501
  window.addEventListener("resize", hide2);
44677
45502
  }
44678
- const TASK_RE = /^((?:[ \t]*> ?)*[ \t]*(?:[-*+]|\d+[.)])[ \t]+\[)([ xX])(\])/;
45503
+ const TASK_RE = /^((?:[ \t]*> ?)*[ \t]*(?:[-*+]|\d+[.)]) +\[)([ xX])(\])/;
44679
45504
  function sourceFromTaskClick(view, e) {
44680
45505
  if (!(e.target instanceof HTMLElement)) return null;
44681
45506
  if (!e.target.closest(".cm-md-task")) return null;
@@ -45097,17 +45922,22 @@ function tagBlockWidgets(root) {
45097
45922
  for (const child of Array.from(root.children)) {
45098
45923
  if (child.classList.contains("cm-line")) continue;
45099
45924
  for (const cls of Array.from(child.classList)) {
45100
- if (cls.startsWith(PAGE_CLASS_PREFIX)) child.classList.remove(cls);
45925
+ if (cls.startsWith(PAGE_CLASS_PREFIX) || cls.startsWith(SLIDE_CLASS_PREFIX)) child.classList.remove(cls);
45101
45926
  }
45102
45927
  }
45103
45928
  let page = null;
45929
+ let layout2 = [];
45930
+ const pageNumber = new RegExp(`^${PAGE_CLASS_PREFIX}\\d+$`);
45104
45931
  for (const child of Array.from(root.children)) {
45105
- const own = Array.from(child.classList).find((cls) => cls.startsWith(PAGE_CLASS_PREFIX));
45106
- if (own) {
45107
- page = own;
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);
45108
45937
  continue;
45109
45938
  }
45110
45939
  if (page) child.classList.add(page);
45940
+ for (const cls of layout2) child.classList.add(cls);
45111
45941
  }
45112
45942
  }
45113
45943
  function firstLineOf(page) {
@@ -45277,13 +46107,32 @@ function stopSlideshow() {
45277
46107
  if (line) claimPage(line);
45278
46108
  }
45279
46109
  }
45280
- const PAGE_WIDTH_INCHES = 13.3333;
45281
- const PAGE_HEIGHT_INCHES = 7.5;
46110
+ const PAGE_WIDTH_INCHES = 20;
46111
+ const PAGE_HEIGHT_INCHES = 11.25;
45282
46112
  const PX_PER_INCH = 96;
46113
+ const PAGE_WIDTH_PX = Math.round(PAGE_WIDTH_INCHES * PX_PER_INCH);
45283
46114
  const PAGE_HEIGHT_PX = Math.round(PAGE_HEIGHT_INCHES * PX_PER_INCH);
45284
- const FONT_SIZE_PX = 24;
45285
- const PAGE_MARGIN_PX = 77;
45286
46115
  const SAFETY_PX = 4;
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
+ };
45287
46136
  const PRINT_CLASS$1 = "slides-printing";
45288
46137
  const STYLE_ID = "slides-print-style";
45289
46138
  let sheetStyle = null;
@@ -45298,50 +46147,115 @@ function pageOfLine(line) {
45298
46147
  const match = new RegExp(`(?:^|\\s)${PAGE_CLASS_PREFIX}(\\d+)(?:\\s|$)`).exec(line.className ?? "");
45299
46148
  return match ? Number(match[1]) : null;
45300
46149
  }
45301
- function layoutRules(background) {
45302
- const softened = `color-mix(in srgb, ${background} 95%, var(--pele-accent))`;
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})`;
45303
46171
  return `/* The sheet is the page: what margins exist in here are the document's own. */
45304
- @page { size: ${PAGE_WIDTH_INCHES}in ${PAGE_HEIGHT_INCHES}in; margin: 0; background: ${background}; background: ${softened}; }
45305
- html, body { display: block !important; height: auto !important; overflow: visible !important; background: ${background} !important; background: ${softened} !important; }
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
+ }
45306
46186
  body.${PRINT_CLASS$1} #editor {
45307
46187
  position: static !important;
45308
46188
  inset: auto !important;
45309
46189
  height: auto !important;
45310
46190
  overflow: visible !important;
45311
46191
  padding: 0 !important;
45312
- background: ${background} !important;
45313
46192
  background: ${softened} !important;
45314
46193
  }
45315
46194
  /* 纸是普通的块流:CM6 的编辑器/滚动容器都是 flex 或 auto 高度,强制断开的分页在
45316
46195
  它们里面不会生效,所以这里把它们摊平成块。 */
45317
46196
  body.${PRINT_CLASS$1} #editor .cm-editor { height: auto !important; }
45318
46197
  body.${PRINT_CLASS$1} #editor .cm-scroller { display: block !important; height: auto !important; overflow: visible !important; }
46198
+ /* 版心就是纸面那么宽:屏幕上的窗口常常不到 1920,版心若跟着窗口走,量出来的
46199
+ 换行位置和纸上落下来的就不是一回事。 */
45319
46200
  body.${PRINT_CLASS$1} #editor .cm-content {
45320
46201
  display: block !important;
45321
- width: auto !important;
46202
+ width: ${PAGE_WIDTH_PX}px !important;
45322
46203
  max-width: none !important;
45323
46204
  margin: 0 !important;
45324
- padding: 0 ${PAGE_MARGIN_PX}px !important;
45325
- font-size: ${FONT_SIZE_PX}px !important;
45326
- line-height: 1.7;
46205
+ padding: 0 ${PAPER.padX}px !important;
45327
46206
  }
45328
46207
  /* 分隔线是分页边界,不是正文里的一行。 */
45329
46208
  body.${PRINT_CLASS$1} #editor .cm-line.cm-md-hr { display: none !important; }
45330
- /* Nothing may be cut off at the sheet's edge: code and cells wrap, a diagram or
45331
- a photo shrinks to fit the page it landed on. */
46209
+ /* Nothing may be cut off at the sheet's edge: code and cells wrap. */
45332
46210
  body.${PRINT_CLASS$1} #editor .cm-md-codeblock { white-space: pre-wrap !important; overflow-wrap: anywhere !important; }
45333
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; }
45334
- body.${PRINT_CLASS$1} #editor img, body.${PRINT_CLASS$1} #editor svg { max-height: ${Math.round(PAGE_HEIGHT_PX * 0.72)}px; }
45335
46212
  `;
45336
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
+ }
45337
46250
  async function enterPrintLayout$1() {
45338
46251
  if (sheetStyle) return { width: PAGE_WIDTH_INCHES, height: PAGE_HEIGHT_INCHES };
45339
46252
  const root = documentRoot();
45340
46253
  if (!root) return false;
45341
- const background = getComputedStyle(document.body).backgroundColor;
46254
+ const background = themeColor("--bg-color", "#ffffff");
46255
+ const accent2 = themeColor("--pele-accent", themeColor("--link-color", "#0969da"));
45342
46256
  const sheet = document.createElement("style");
45343
46257
  sheet.id = STYLE_ID;
45344
- sheet.textContent = layoutRules(background);
46258
+ sheet.textContent = layoutRules(background, accent2);
45345
46259
  document.head.appendChild(sheet);
45346
46260
  document.body.classList.add(PRINT_CLASS$1);
45347
46261
  sheetStyle = sheet;
@@ -45349,32 +46263,43 @@ async function enterPrintLayout$1() {
45349
46263
  root.getBoundingClientRect();
45350
46264
  await renderWholeDocument();
45351
46265
  tagBlockWidgets(root);
46266
+ await waitForDiagrams(root);
45352
46267
  const deck = deckPages();
45353
46268
  if (deck.length === 0) {
45354
46269
  exitPrintLayout();
45355
46270
  return false;
45356
46271
  }
45357
- const rules2 = [];
45358
- deck.forEach((page, order) => {
45359
- const first = root.querySelector(`.${PAGE_CLASS_PREFIX}${page}.${PAGE_START_CLASS}`);
45360
- const lines = Array.from(root.children).filter(
45361
- (line) => pageOfLine(line) === page && !line.classList.contains("cm-md-hr")
45362
- );
45363
- const last2 = lines[lines.length - 1];
45364
- if (!first || !last2) return;
45365
- const ownMargin = parseFloat(getComputedStyle(first).marginTop);
45366
- const owned = last2.getBoundingClientRect().bottom - first.getBoundingClientRect().top;
45367
- const used = owned + (Number.isFinite(ownMargin) ? ownMargin : 0);
45368
- const layout2 = getSlideDirectives().get(page)?.layout;
45369
- const hero = layout2 === "cover" || layout2 === "section" || layout2 === "closing" || layout2 === "quote";
45370
- const above = hero ? Math.max(0, Math.floor((PAGE_HEIGHT_PX - SAFETY_PX - used) / 2)) : 0;
45371
- const target = `.cm-content > .${PAGE_CLASS_PREFIX}${page}.${PAGE_START_CLASS}`;
45372
- if (order > 0) rules2.push(`body.${PRINT_CLASS$1} #editor ${target} { break-before: page; }`);
45373
- if (above > 0) {
45374
- rules2.push(`body.${PRINT_CLASS$1} #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
+ }
45375
46288
  }
45376
- });
45377
- 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);
45378
46303
  return { width: PAGE_WIDTH_INCHES, height: PAGE_HEIGHT_INCHES };
45379
46304
  }
45380
46305
  function exitPrintLayout() {
@@ -46837,11 +47762,11 @@ async function capModule(name2) {
46837
47762
  try {
46838
47763
  switch (name2) {
46839
47764
  case "@capacitor/filesystem":
46840
- return await __vitePreload(() => import("./index-gvL3lkzR.js"), true ? [] : void 0, import.meta.url);
47765
+ return await __vitePreload(() => import("./index--lwcDMTj.js"), true ? [] : void 0, import.meta.url);
46841
47766
  case "@capacitor/share":
46842
- return await __vitePreload(() => import("./index-CwH04Tq_.js"), true ? [] : void 0, import.meta.url);
47767
+ return await __vitePreload(() => import("./index-D0d2vg7k.js"), true ? [] : void 0, import.meta.url);
46843
47768
  case "@capacitor/app":
46844
- return await __vitePreload(() => import("./index-BpqOaUd_.js"), true ? [] : void 0, import.meta.url);
47769
+ return await __vitePreload(() => import("./index-CFKk8_-a.js"), true ? [] : void 0, import.meta.url);
46845
47770
  default:
46846
47771
  return null;
46847
47772
  }