@w100n/documents 0.15.1 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/Compare-M57FG4R3.js +96 -0
  2. package/dist/Compare-M57FG4R3.js.map +1 -0
  3. package/dist/{SheetView-RPQS43XY.js → SheetView-FVLKQR7J.js} +6 -4
  4. package/dist/{SheetView-RPQS43XY.js.map → SheetView-FVLKQR7J.js.map} +1 -1
  5. package/dist/{TextEditor-D6QH2B7O.js → TextEditor-BF6HCNHL.js} +500 -369
  6. package/dist/TextEditor-BF6HCNHL.js.map +1 -0
  7. package/dist/chunk-EQLBYW42.js +458 -0
  8. package/dist/chunk-EQLBYW42.js.map +1 -0
  9. package/dist/{chunk-BGH36LAR.js → chunk-GN3ZOD36.js} +87 -411
  10. package/dist/chunk-GN3ZOD36.js.map +1 -0
  11. package/dist/chunk-LZYITB56.js +1032 -0
  12. package/dist/chunk-LZYITB56.js.map +1 -0
  13. package/dist/{chunk-XR42B3F5.js → chunk-NPVH2YDI.js} +2 -2
  14. package/dist/{chunk-CAPICJ6B.js → chunk-ZAVXCH7V.js} +51 -1032
  15. package/dist/chunk-ZAVXCH7V.js.map +1 -0
  16. package/dist/collab.cjs +367 -200
  17. package/dist/collab.cjs.map +1 -1
  18. package/dist/collab.d.cts +1 -1
  19. package/dist/collab.d.ts +1 -1
  20. package/dist/collab.js +4 -2
  21. package/dist/index.cjs +1680 -1230
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.css +187 -0
  24. package/dist/index.css.map +1 -1
  25. package/dist/index.d.cts +2 -2
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.js +70 -15
  28. package/dist/index.js.map +1 -1
  29. package/dist/kinds.d.cts +1 -1
  30. package/dist/kinds.d.ts +1 -1
  31. package/dist/memory.cjs +25 -2
  32. package/dist/memory.cjs.map +1 -1
  33. package/dist/memory.d.cts +3 -2
  34. package/dist/memory.d.ts +3 -2
  35. package/dist/memory.js +25 -2
  36. package/dist/memory.js.map +1 -1
  37. package/dist/{types-BTsVooZw.d.cts → types-DNcaU6SK.d.cts} +9 -0
  38. package/dist/{types-BTsVooZw.d.ts → types-DNcaU6SK.d.ts} +9 -0
  39. package/package.json +1 -1
  40. package/dist/TextEditor-D6QH2B7O.js.map +0 -1
  41. package/dist/chunk-BGH36LAR.js.map +0 -1
  42. package/dist/chunk-CAPICJ6B.js.map +0 -1
  43. /package/dist/{chunk-XR42B3F5.js.map → chunk-NPVH2YDI.js.map} +0 -0
@@ -1,4 +1,12 @@
1
1
  'use client';
2
+ import {
3
+ fromMarkdown,
4
+ toMarkdown,
5
+ track
6
+ } from "./chunk-EQLBYW42.js";
7
+ import {
8
+ texts
9
+ } from "./chunk-LZYITB56.js";
2
10
  import {
3
11
  attr,
4
12
  attrs,
@@ -8,12 +16,11 @@ import {
8
16
  mathml,
9
17
  parse,
10
18
  readDocx,
11
- texts,
12
19
  unescape,
13
20
  unzip,
14
21
  writeDocx,
15
22
  zip
16
- } from "./chunk-CAPICJ6B.js";
23
+ } from "./chunk-ZAVXCH7V.js";
17
24
  import {
18
25
  a1,
19
26
  box,
@@ -36,7 +43,7 @@ import { prosemirrorJSONToYXmlFragment, updateYFragment, yXmlFragmentToProseMirr
36
43
  import * as Y2 from "yjs";
37
44
 
38
45
  // package.json
39
- var version = "0.15.1";
46
+ var version = "0.16.1";
40
47
 
41
48
  // src/editor/extensions.ts
42
49
  import { Extension as Extension2, Mark, Node } from "@tiptap/core";
@@ -110,10 +117,10 @@ var Pager = Extension.create({
110
117
  addProseMirrorPlugins: () => [new Plugin({
111
118
  key: paging,
112
119
  state: {
113
- init: () => ({ set: DecorationSet.empty, page: a4, marks: { header: "", footer: "" } }),
120
+ init: () => ({ set: DecorationSet.empty, page: a4, marks: { header: "", footer: "" }, flow: false }),
114
121
  apply(tr, value2) {
115
122
  const next = tr.getMeta(paging);
116
- return { set: next?.set ?? value2.set.map(tr.mapping, tr.doc), page: next?.page ?? value2.page, marks: next?.marks ?? value2.marks };
123
+ return { set: next?.set ?? value2.set.map(tr.mapping, tr.doc), page: next?.page ?? value2.page, marks: next?.marks ?? value2.marks, flow: next?.flow ?? value2.flow };
117
124
  }
118
125
  },
119
126
  props: { decorations: (state) => paging.getState(state).set },
@@ -122,8 +129,13 @@ var Pager = Extension.create({
122
129
  let sig = "";
123
130
  const run = () => {
124
131
  if (!view.dom.isConnected) return;
132
+ const { marks, flow } = paging.getState(view.state);
133
+ if (flow) {
134
+ if (sig !== "flow") view.dispatch(view.state.tr.setMeta(paging, { set: DecorationSet.empty }).setMeta("addToHistory", false));
135
+ sig = "flow";
136
+ return;
137
+ }
125
138
  const gaps = measure(view);
126
- const { marks } = paging.getState(view.state);
127
139
  const next = gaps.map((g) => `${g.pos}:${g.height}:${g.notes.join("\n")}`).join() + `|${marks.header}|${marks.footer}`;
128
140
  if (next === sig) return;
129
141
  sig = next;
@@ -174,7 +186,8 @@ var Pager = Extension.create({
174
186
  later(0);
175
187
  return {
176
188
  update: (next, prev) => {
177
- if (paging.getState(next.state).page !== paging.getState(prev).page || paging.getState(next.state).marks !== paging.getState(prev).marks) later(0);
189
+ const now = paging.getState(next.state), was = paging.getState(prev);
190
+ if (now.page !== was.page || now.marks !== was.marks || now.flow !== was.flow) later(0);
178
191
  else if (next.state.doc !== prev.doc) later(400);
179
192
  },
180
193
  destroy: () => {
@@ -365,6 +378,31 @@ var Footnote = Node.create({
365
378
  parseHTML: () => [{ tag: "sup[data-footnote]" }],
366
379
  renderHTML: ({ node }) => ["sup", { "data-footnote": "", "data-note-id": node.attrs.id ?? void 0, title: node.attrs.text, class: "w100n-fn", contenteditable: "false" }]
367
380
  });
381
+ var EndNotes = Extension2.create({
382
+ name: "endNotes",
383
+ addProseMirrorPlugins: () => [new Plugin2({
384
+ props: {
385
+ decorations(state) {
386
+ const notes2 = [];
387
+ state.doc.descendants((n) => {
388
+ if (n.type.name === "footnote") notes2.push(n.attrs.text);
389
+ });
390
+ if (!notes2.length) return null;
391
+ return DecorationSet2.create(state.doc, [Decoration2.widget(state.doc.content.size, () => {
392
+ const list = document.createElement("div");
393
+ list.className = "w100n-text-endnotes";
394
+ list.contentEditable = "false";
395
+ notes2.forEach((text, i) => {
396
+ const p = list.appendChild(document.createElement("p"));
397
+ p.appendChild(document.createElement("sup")).textContent = String(i + 1);
398
+ p.append(text);
399
+ });
400
+ return list;
401
+ }, { key: notes2.join("\n"), side: 1, ignoreSelection: true })]);
402
+ }
403
+ }
404
+ })]
405
+ });
368
406
  var headings = (doc, after) => {
369
407
  const found = [];
370
408
  doc.descendants((node, pos) => {
@@ -687,7 +725,10 @@ function kit(kind, t, live) {
687
725
  Toc.configure({ relative: kind === "markdown", label: t.toc, empty: t.tocEmpty }),
688
726
  Note,
689
727
  Notes,
690
- ...kind === "docx" ? [Formula, Footnote, Pager, Locks.configure({ label: t.locked }), revision("insertion", "ins"), revision("deletion", "del"), Suggest] : [],
728
+ Formula,
729
+ Footnote,
730
+ EndNotes,
731
+ ...kind === "docx" ? [Pager, Locks.configure({ label: t.locked }), revision("insertion", "ins"), revision("deletion", "del"), Suggest] : [],
691
732
  ...live ? [Collaboration.configure({ document: live.doc }), CollaborationCaret.configure({ provider: live.link, user: live.user })] : []
692
733
  ];
693
734
  }
@@ -714,14 +755,14 @@ var clear = (editor) => {
714
755
  };
715
756
  function locate(doc, list) {
716
757
  if (!list.length) return [];
717
- const marked2 = /* @__PURE__ */ new Map();
758
+ const marked = /* @__PURE__ */ new Map();
718
759
  doc.descendants((node, pos) => {
719
760
  if (!node.isText) return;
720
761
  for (const mark of node.marks) {
721
762
  if (mark.type.name !== "comment") continue;
722
- const found = marked2.get(mark.attrs.id);
763
+ const found = marked.get(mark.attrs.id);
723
764
  if (found) Object.assign(found, { to: pos + node.nodeSize, text: found.text + node.text });
724
- else marked2.set(mark.attrs.id, { from: pos, to: pos + node.nodeSize, text: node.text });
765
+ else marked.set(mark.attrs.id, { from: pos, to: pos + node.nodeSize, text: node.text });
725
766
  }
726
767
  });
727
768
  const claimed = /* @__PURE__ */ new Set();
@@ -738,10 +779,10 @@ function locate(doc, list) {
738
779
  return hit;
739
780
  };
740
781
  return list.flatMap((c) => {
741
- const own = [c.anchor, c.id].find((id) => id && marked2.has(id));
742
- let range = own ? marked2.get(own) : void 0;
782
+ const own = [c.anchor, c.id].find((id) => id && marked.has(id));
783
+ let range = own ? marked.get(own) : void 0;
743
784
  if (!range) {
744
- const twin = [...marked2].find(([id, m]) => !claimed.has(id) && m.text === c.quote);
785
+ const twin = [...marked].find(([id, m]) => !claimed.has(id) && m.text === c.quote);
745
786
  if (twin) {
746
787
  claimed.add(twin[0]);
747
788
  range = twin[1];
@@ -752,368 +793,6 @@ function locate(doc, list) {
752
793
  });
753
794
  }
754
795
 
755
- // src/editor/markdown.ts
756
- import { marked } from "marked";
757
- import { MarkdownSerializer } from "prosemirror-markdown";
758
- var tags = { u: "underline", ins: "underline", mark: "highlight", s: "strike", del: "strike", b: "bold", strong: "bold", i: "italic", em: "italic" };
759
- var decode = (text) => text.includes("&") ? new DOMParser().parseFromString(`<p>${text.replace(/</g, "&lt;")}</p>`, "text/html").body.textContent ?? text : text;
760
- var unique = (marks) => [...new Map(marks.map((m) => [m.type, m])).values()];
761
- function inline(tokens = [], outer = []) {
762
- const out = [];
763
- let open = [];
764
- const marks = () => unique([...outer, ...open]);
765
- const text = (value2, extra = []) => {
766
- const set = unique([...marks(), ...extra]);
767
- const clean = out[out.length - 1]?.type === "hardBreak" ? value2.replace(/^\n/, "") : value2;
768
- if (clean) out.push({ type: "text", text: clean, ...set.length ? { marks: set } : {} });
769
- };
770
- const wrap = (children, mark) => out.push(...inline(children, [...marks(), mark]));
771
- for (const token of tokens) {
772
- if (token.type === "text") {
773
- if (token.tokens) out.push(...inline(token.tokens, marks()));
774
- else text(decode(token.text));
775
- } else if (token.type === "escape") text(decode(token.text));
776
- else if (token.type === "strong") wrap(token.tokens, { type: "bold" });
777
- else if (token.type === "em") wrap(token.tokens, { type: "italic" });
778
- else if (token.type === "del") wrap(token.tokens, { type: "strike" });
779
- else if (token.type === "codespan") text(token.text, [{ type: "code" }]);
780
- else if (token.type === "br") out.push({ type: "hardBreak" });
781
- else if (token.type === "link") wrap(token.tokens, { type: "link", attrs: { href: token.href } });
782
- else if (token.type === "image") out.push({ type: "image", attrs: { src: token.href, alt: token.text || null, title: token.title || null }, ...marks().length ? { marks: marks() } : {} });
783
- else if (token.type === "html") {
784
- const tag = /^<(\/?)([a-z]+)\s*\/?>$/i.exec(token.raw.trim());
785
- const name = tag?.[2].toLowerCase() ?? "";
786
- if (name === "br") out.push({ type: "hardBreak" });
787
- else if (!tags[name]) text(token.raw);
788
- else open = tag[1] ? open.filter((m) => m.type !== tags[name]) : [...open, { type: tags[name] }];
789
- } else if (token.type !== "checkbox") text(token.raw);
790
- }
791
- return out;
792
- }
793
- var fill = (content) => content.length ? content : [{ type: "paragraph" }];
794
- function block(token, hints) {
795
- const ref = (hint) => {
796
- const id = `md${Object.keys(hints).length + 1}`;
797
- hints[id] = hint;
798
- return id;
799
- };
800
- switch (token.type) {
801
- case "space":
802
- case "def":
803
- case "checkbox":
804
- return [];
805
- case "heading":
806
- return [{ type: "heading", attrs: { level: token.depth }, content: inline(token.tokens) }];
807
- case "paragraph":
808
- case "text":
809
- return [{ type: "paragraph", content: token.tokens ? inline(token.tokens) : inline([{ type: "text", raw: token.text, text: token.text }]) }];
810
- case "blockquote":
811
- return [{ type: "blockquote", content: fill(token.tokens.flatMap((t) => block(t, hints))) }];
812
- case "code": {
813
- const fence = /^ {0,3}(`{3,}|~{3,})/.exec(token.raw)?.[1][0];
814
- return [{ type: "codeBlock", attrs: { language: token.lang || null, ref: fence ? ref({ fence: fence.repeat(3) }) : null }, content: token.text ? [{ type: "text", text: token.text }] : [] }];
815
- }
816
- case "html":
817
- return [{ type: "codeBlock", attrs: { language: "html" }, content: [{ type: "text", text: token.raw.replace(/\n+$/, "") }] }];
818
- case "hr":
819
- return [{ type: "horizontalRule" }];
820
- case "list": {
821
- const list = token;
822
- const tasks = list.items.every((entry2) => entry2.task);
823
- const marker = /^\s*(?:([-*+])|\d+([.)]))/.exec(list.raw);
824
- const id = ref({ bullet: marker?.[1], delim: marker?.[2], loose: list.loose });
825
- return [{
826
- type: tasks ? "taskList" : list.ordered ? "orderedList" : "bulletList",
827
- attrs: list.ordered && !tasks ? { start: list.start === "" ? 1 : Number(list.start), ref: id } : { ref: id },
828
- content: list.items.map((entry2) => {
829
- const content = fill(entry2.tokens.flatMap((t) => block(t, hints)));
830
- if (!tasks && entry2.task) content[0].content = [{ type: "text", text: entry2.checked ? "[x] " : "[ ] " }, ...content[0].content ?? []];
831
- return tasks ? { type: "taskItem", attrs: { checked: !!entry2.checked }, content } : { type: "listItem", content };
832
- })
833
- }];
834
- }
835
- case "table": {
836
- const table = token;
837
- const cell2 = (type) => (c, i) => ({ type, attrs: { align: table.align[i] }, content: [{ type: "paragraph", content: inline(c.tokens) }] });
838
- return [{ type: "table", content: [
839
- { type: "tableRow", content: table.header.map(cell2("tableHeader")) },
840
- ...table.rows.map((row2) => ({ type: "tableRow", content: row2.map(cell2("tableCell")) }))
841
- ] }];
842
- }
843
- default:
844
- return [{ type: "paragraph", content: inline([{ type: "text", raw: token.raw, text: token.raw }]) }];
845
- }
846
- }
847
- var opens = /^\s*<!--\s*toc\s*-->\s*$/i;
848
- var shuts = /^\s*<!--\s*\/toc\s*-->\s*$/i;
849
- var row = /^(\s*)[-*+]\s+\[((?:\\.|[^\]\\])*)\]\(#[^)\s]*\)\s*$/;
850
- function contents(tokens, i) {
851
- if (tokens[i].type !== "html" || !opens.test(tokens[i].raw)) return null;
852
- let j = i + 1;
853
- const skip2 = () => {
854
- while (tokens[j]?.type === "space") j++;
855
- };
856
- skip2();
857
- const list = tokens[j]?.type === "list" ? tokens[j++] : null;
858
- skip2();
859
- if (tokens[j]?.type !== "html" || !shuts.test(tokens[j].raw)) return null;
860
- const rows = list ? list.raw.split("\n").filter((line) => line.trim()).map((line) => row.exec(line)) : [];
861
- if (rows.some((r) => !r)) return null;
862
- const steps = [...new Set(rows.map((r) => r[1].length))].sort((a, b) => a - b);
863
- return { end: j, entries: rows.map((r) => [steps.indexOf(r[1].length) + 1, r[2].replace(/\\(.)/g, "$1")]) };
864
- }
865
- var slug = (text, seen2) => {
866
- const base = text.toLowerCase().replace(/[^\p{L}\p{N}\s_-]/gu, "").trim().replace(/\s/g, "-");
867
- const n = seen2.get(base) ?? 0;
868
- seen2.set(base, n + 1);
869
- return n ? `${base}-${n}` : base;
870
- };
871
- function sniff(tokens) {
872
- const style = { bullet: "-", delim: ".", em: "*", strong: "**", fence: "```", br: "\\\n", loose: false };
873
- const seen2 = /* @__PURE__ */ new Set();
874
- const note = (key2, value2) => {
875
- if (seen2.has(key2)) return;
876
- seen2.add(key2);
877
- style[key2] = value2;
878
- };
879
- let loose = 0;
880
- marked.walkTokens(tokens, (token) => {
881
- if (token.type === "list") {
882
- const marker = /^\s*(?:([-*+])|\d+([.)]))/.exec(token.raw);
883
- if (token.ordered) note("delim", marker?.[2] ?? ".");
884
- else note("bullet", marker?.[1] ?? "-");
885
- loose += token.loose ? 1 : -1;
886
- } else if (token.type === "em") note("em", token.raw[0]);
887
- else if (token.type === "strong") note("strong", token.raw.slice(0, 2));
888
- else if (token.type === "code" && /^ {0,3}(```|~~~)/.test(token.raw)) note("fence", token.raw.trimStart().slice(0, 3));
889
- else if (token.type === "br" && token.raw !== "<br>") note("br", token.raw.startsWith("\\") ? "\\\n" : " \n");
890
- });
891
- style.loose = loose > 0;
892
- return style;
893
- }
894
- function fromMarkdown(source) {
895
- const bom = source.startsWith("\uFEFF");
896
- const crlf = source.includes("\r\n");
897
- const tokens = marked.lexer(source.slice(bom ? 1 : 0).replace(/\r\n?/g, "\n"));
898
- const hints = {};
899
- const content = [];
900
- const raws = [];
901
- let head = "";
902
- let gap = "";
903
- for (let i = 0; i < tokens.length; i++) {
904
- const token = tokens[i];
905
- const toc = contents(tokens, i);
906
- const made2 = toc ? [{ type: "toc", attrs: { entries: JSON.stringify(toc.entries) } }] : block(token, hints);
907
- if (!made2.length) {
908
- gap += token.raw;
909
- continue;
910
- }
911
- if (raws.length) raws[raws.length - 1] += gap;
912
- else head = gap;
913
- gap = "";
914
- content.push(...made2);
915
- raws.push(toc ? tokens.slice(i, toc.end + 1).map((t) => t.raw).join("") : token.raw);
916
- if (toc) i = toc.end;
917
- }
918
- if (!content.length) {
919
- content.push({ type: "paragraph" });
920
- raws.push("");
921
- head = "";
922
- }
923
- return { doc: { type: "doc", content }, raws, head, tail: gap, style: sniff(tokens), hints, crlf, bom };
924
- }
925
- var track = ({ doc: _json, ...parsed }, doc) => {
926
- const nodes = [];
927
- doc.forEach((node) => nodes.push(node));
928
- return nodes.length === parsed.raws.length ? { ...parsed, nodes } : { ...parsed, nodes: [], raws: [], head: "", tail: "\n" };
929
- };
930
- var ticks = (node, side) => {
931
- const len = Math.max(0, ...(node.isText ? node.text.match(/`+/g) ?? [] : []).map((run) => run.length));
932
- return len ? side > 0 ? ` ${"`".repeat(len + 1)}` : `${"`".repeat(len + 1)} ` : "`";
933
- };
934
- var plain2 = (mark, parent, index) => {
935
- const node = parent.child(index);
936
- const href = mark.attrs.href;
937
- if (!node.isText || node.marks.length !== 1 || index + 1 < parent.childCount && mark.isInSet(parent.child(index + 1).marks)) return null;
938
- const text = node.text;
939
- if (text !== href && `mailto:${text}` !== href && !(text.startsWith("www.") && `http://${text}` === href)) return null;
940
- const before = index ? parent.child(index - 1) : null;
941
- const after = index + 1 < parent.childCount ? parent.child(index + 1) : null;
942
- const left = before ? before.isText ? before.text.slice(-1) : "x" : "";
943
- const right = after ? after.isText ? after.text : "x" : "";
944
- return /^[\s(*_~]?$/.test(left) && /^([\s)]|[.,:;!?]+(\s|$)|$)/.test(right) ? "bare" : text === href || href.startsWith("mailto:") ? "angle" : null;
945
- };
946
- function serializer(style, hints, before, cell2 = false) {
947
- let form = null;
948
- const hint = (node) => hints[node.attrs.ref] ?? {};
949
- const run = (parent, index, types) => {
950
- let n = 0;
951
- for (let i = index - 1; i >= 0 && types.includes(parent.child(i).type.name); i--) n++;
952
- if (!index && before && types.includes(before.type.name)) n++;
953
- return n % 2;
954
- };
955
- const tight = (state, node, render) => {
956
- const deep = node.content.content.some((entry2) => entry2.content.content.filter((child) => !child.type.name.endsWith("List")).length > 1);
957
- const was = state.options.tightLists;
958
- state.options.tightLists = !deep && !(hint(node).loose ?? style.loose);
959
- render();
960
- state.options.tightLists = was;
961
- };
962
- const list = (state, node, parent, index) => {
963
- const bullet = hint(node).bullet ?? (run(parent, index, ["bulletList", "taskList"]) ? style.bullet === "-" ? "*" : "-" : style.bullet);
964
- tight(state, node, () => state.renderList(node, " ", () => `${bullet} `));
965
- };
966
- const blank2 = { open: "", close: "", mixable: true };
967
- const wrap = (open, close = open) => ({ open, close, mixable: true, expelEnclosingWhitespace: true });
968
- return new MarkdownSerializer({
969
- paragraph(state, node) {
970
- state.renderInline(node);
971
- state.closeBlock(node);
972
- },
973
- heading(state, node) {
974
- state.write(`${"#".repeat(node.attrs.level)} `);
975
- state.renderInline(node, false);
976
- state.closeBlock(node);
977
- },
978
- blockquote(state, node) {
979
- state.wrapBlock("> ", null, node, () => state.renderContent(node));
980
- },
981
- codeBlock(state, node) {
982
- const mark = (hint(node).fence ?? style.fence)[0];
983
- const longest = Math.max(2, ...(node.textContent.match(new RegExp(`${mark}{3,}`, "g")) ?? []).map((r) => r.length));
984
- const fence = mark.repeat(longest + 1);
985
- state.write(`${fence}${node.attrs.language ?? ""}
986
- `);
987
- state.text(node.textContent, false);
988
- state.ensureNewLine();
989
- state.write(fence);
990
- state.closeBlock(node);
991
- },
992
- horizontalRule(state, node) {
993
- state.write("---");
994
- state.closeBlock(node);
995
- },
996
- pageBreak(state, node) {
997
- state.closeBlock(node);
998
- },
999
- toc(state, node) {
1000
- const seen2 = /* @__PURE__ */ new Map();
1001
- const lines2 = JSON.parse(node.attrs.entries).map(([level, text]) => `${" ".repeat(level - 1)}${style.bullet} [${text.replace(/[[\]\\]/g, "\\$&")}](#${slug(text, seen2)})
1002
- `);
1003
- state.write(`<!-- toc -->
1004
- ${lines2.join("")}<!-- /toc -->`);
1005
- state.closeBlock(node);
1006
- },
1007
- bulletList: list,
1008
- taskList: list,
1009
- orderedList(state, node, parent, index) {
1010
- const start = node.attrs.start ?? 1;
1011
- const delim = hint(node).delim ?? (run(parent, index, ["orderedList"]) ? style.delim === "." ? ")" : "." : style.delim);
1012
- const width = String(start + node.childCount - 1).length;
1013
- tight(state, node, () => state.renderList(node, " ".repeat(width + 2), (i) => `${start + i}${delim} `));
1014
- },
1015
- listItem(state, node) {
1016
- state.renderContent(node);
1017
- },
1018
- taskItem(state, node) {
1019
- state.write(node.attrs.checked ? "[x] " : "[ ] ");
1020
- state.renderContent(node);
1021
- },
1022
- table(state, node) {
1023
- const rows = [];
1024
- const aligns = [];
1025
- node.forEach((row2, _, r) => {
1026
- const cells = [];
1027
- row2.forEach((c) => {
1028
- const span2 = c.attrs.colspan || 1;
1029
- const text = [];
1030
- c.forEach((child) => text.push(serializer(style, hints, null, true).serialize(c.type.schema.topNodeType.create(null, child)).replace(/\n+/g, " ")));
1031
- if (!r) aligns.push(c.attrs.align, ...Array(span2 - 1).fill(null));
1032
- cells.push(text.join("<br>").replace(/\|/g, "\\|"), ...Array(span2 - 1).fill(""));
1033
- });
1034
- rows.push(cells);
1035
- });
1036
- const width = Math.max(...rows.map((r) => r.length));
1037
- const line = (cells) => `| ${[...cells, ...Array(width - cells.length).fill("")].join(" | ")} |`;
1038
- const rule = Array.from({ length: width }, (_, i) => ({ left: ":---", center: ":---:", right: "---:" })[aligns[i] ?? ""] ?? "---");
1039
- [line(rows[0]), `| ${rule.join(" | ")} |`, ...rows.slice(1).map(line)].forEach((text, i) => {
1040
- if (i) state.ensureNewLine();
1041
- state.write(text);
1042
- });
1043
- state.closeBlock(node);
1044
- },
1045
- image(state, node) {
1046
- const src = String(node.attrs.src ?? "");
1047
- const title = node.attrs.title ? ` "${String(node.attrs.title).replace(/"/g, '\\"')}"` : "";
1048
- state.write(`![${state.esc(String(node.attrs.alt ?? ""))}](${/\s/.test(src) ? `<${src}>` : src.replace(/[()]/g, "\\$&")}${title})`);
1049
- },
1050
- hardBreak(state, node, parent, index) {
1051
- for (let i = index + 1; i < parent.childCount; i++) {
1052
- if (parent.child(i).type === node.type) continue;
1053
- state.write(cell2 ? "<br>" : style.br);
1054
- return;
1055
- }
1056
- },
1057
- text(state, node) {
1058
- state.text(node.text, !state.inAutolink);
1059
- }
1060
- }, {
1061
- italic: wrap(style.em),
1062
- bold: wrap(style.strong),
1063
- strike: wrap("~~"),
1064
- underline: wrap("<u>", "</u>"),
1065
- highlight: wrap("<mark>", "</mark>"),
1066
- textStyle: blank2,
1067
- comment: blank2,
1068
- link: {
1069
- open(state, mark, parent, index) {
1070
- form = plain2(mark, parent, index);
1071
- state.inAutolink = !!form;
1072
- return form === "bare" ? "" : form === "angle" ? "<" : "[";
1073
- },
1074
- close(state, mark) {
1075
- state.inAutolink = void 0;
1076
- const was = form;
1077
- form = null;
1078
- return was === "bare" ? "" : was === "angle" ? ">" : `](${String(mark.attrs.href).replace(/[()"]/g, "\\$&")})`;
1079
- },
1080
- mixable: true
1081
- },
1082
- code: { open: (_s, _m, parent, index) => ticks(parent.child(index), -1), close: (_s, _m, parent, index) => ticks(parent.child(index - 1), 1), escape: false }
1083
- }, { hardBreakNodeName: "hardBreak", strict: false, escapeExtraCharacters: /<(?=[A-Za-z/!?])/g });
1084
- }
1085
- var one = (node, before, base) => serializer(base.style, base.hints, before).serialize(node.type.schema.topNodeType.create(null, node)).replace(/\n+$/, "");
1086
- function toMarkdown(doc, base) {
1087
- const nodes = [];
1088
- const found = [];
1089
- let j = 0;
1090
- doc.forEach((node) => {
1091
- let k = -1;
1092
- for (let m = j; m < Math.min(base.nodes.length, j + 64) && k < 0; m++) if (base.nodes[m] === node || base.nodes[m].eq(node)) k = m;
1093
- if (k >= 0) j = k + 1;
1094
- nodes.push(node);
1095
- found.push(k);
1096
- });
1097
- let out = base.head;
1098
- const starts = [];
1099
- nodes.forEach((node, i) => {
1100
- const k = found[i];
1101
- if (i && !(k >= 0 && found[i - 1] === k - 1)) out = out.replace(/\n*$/, "\n\n");
1102
- starts.push(out.length);
1103
- out += k >= 0 ? base.raws[k] : one(node, i ? nodes[i - 1] : null, base);
1104
- });
1105
- const last = found[found.length - 1];
1106
- const end = last >= 0 && last === base.nodes.length - 1;
1107
- if (!end) out = out.replace(/\n*$/, "\n");
1108
- const cut = out.length;
1109
- out += end ? base.tail : base.tail.trim() ? `
1110
- ${base.tail.replace(/^\n+/, "")}` : "";
1111
- const at = starts.map((s) => Math.min(s, cut));
1112
- const raws = at.map((s, i) => out.slice(s, i + 1 < at.length ? at[i + 1] : cut));
1113
- const text = base.crlf ? out.replace(/\n/g, "\r\n") : out;
1114
- return { text: base.bom ? `\uFEFF${text}` : text, base: { ...base, nodes, raws, tail: out.slice(cut) } };
1115
- }
1116
-
1117
796
  // src/sheets/model.ts
1118
797
  var SheetRefusal = class extends Error {
1119
798
  constructor(code, sheet = "") {
@@ -1141,7 +820,7 @@ function rebase(model, lines2, sheets) {
1141
820
  }
1142
821
 
1143
822
  // src/sheets/csv.ts
1144
- function decode2(bytes) {
823
+ function decode(bytes) {
1145
824
  if (bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) return { text: new TextDecoder("utf-8").decode(bytes.subarray(3)), encoding: "utf-8", bom: true };
1146
825
  if (bytes[0] === 255 && bytes[1] === 254) return { text: new TextDecoder("utf-16le").decode(bytes.subarray(2)), encoding: "utf-16le", bom: true };
1147
826
  if (bytes[0] === 254 && bytes[1] === 255) return { text: new TextDecoder("utf-16be").decode(bytes.subarray(2)), encoding: "utf-16be", bom: true };
@@ -1193,7 +872,7 @@ function encode(text, encoding, bom) {
1193
872
  }
1194
873
  function split(text, delimiter, limit = Infinity) {
1195
874
  const rows = [];
1196
- let row2 = [];
875
+ let row = [];
1197
876
  let i = 0;
1198
877
  const n = text.length;
1199
878
  while (i <= n && rows.length < limit) {
@@ -1218,9 +897,9 @@ function split(text, delimiter, limit = Infinity) {
1218
897
  while (i < n && text[i] !== delimiter && text[i] !== "\n" && text[i] !== "\r") i++;
1219
898
  value2 = text.slice(start, i);
1220
899
  }
1221
- row2.push({ text: value2, raw: text.slice(start, i) });
900
+ row.push({ text: value2, raw: text.slice(start, i) });
1222
901
  if (i >= n) {
1223
- rows.push(row2);
902
+ rows.push(row);
1224
903
  break;
1225
904
  }
1226
905
  if (text[i] === delimiter) {
@@ -1228,13 +907,13 @@ function split(text, delimiter, limit = Infinity) {
1228
907
  continue;
1229
908
  }
1230
909
  i += text[i] === "\r" && text[i + 1] === "\n" ? 2 : 1;
1231
- rows.push(row2);
1232
- row2 = [];
910
+ rows.push(row);
911
+ row = [];
1233
912
  if (i >= n) break;
1234
913
  }
1235
914
  return rows;
1236
915
  }
1237
- function sniff2(text) {
916
+ function sniff(text) {
1238
917
  let best = ",", score = -1;
1239
918
  for (const d of [",", ";", " ", "|"]) {
1240
919
  const rows = split(text, d, 30).filter((r) => r.length > 1 || r[0]?.text);
@@ -1252,8 +931,8 @@ function sniff2(text) {
1252
931
  }
1253
932
  var numeric = (s, decimal) => decimal === "," ? /^-?(0|[1-9]\d*)(,\d+)?$/.test(s) : /^-?(0|[1-9]\d*)(\.\d+)?([eE][-+]?\d+)?$/.test(s);
1254
933
  function readCsv(bytes) {
1255
- const { text, encoding, bom } = decode2(new Uint8Array(bytes));
1256
- const delimiter = sniff2(text);
934
+ const { text, encoding, bom } = decode(new Uint8Array(bytes));
935
+ const delimiter = sniff(text);
1257
936
  const eol = /\r\n/.test(text) ? "\r\n" : /\r(?!\n)/.test(text) && !text.includes("\n") ? "\r" : "\n";
1258
937
  const rows = split(text, delimiter);
1259
938
  const end = /[\r\n]$/.test(text);
@@ -1295,7 +974,7 @@ function value(x) {
1295
974
  return x.v ?? null;
1296
975
  }
1297
976
  function writeCsv(original, model) {
1298
- const { text } = decode2(new Uint8Array(original));
977
+ const { text } = decode(new Uint8Array(original));
1299
978
  const format = model.csv ?? readCsv(original).csv;
1300
979
  const old = split(text, format.delimiter);
1301
980
  if (format.end && old.length && old[old.length - 1].length === 1 && old[old.length - 1][0].raw === "") old.pop();
@@ -1661,10 +1340,10 @@ var Styles = class {
1661
1340
  if (font.has("name")) s.ff = val(font.get("name"));
1662
1341
  const cl = this.color(font.get("color"));
1663
1342
  if (cl) s.cl = { rgb: cl };
1664
- const fill3 = this.fills[Number(a.fillId ?? 0)];
1665
- const pattern = fill3 && /patternType="(\w+)"/.exec(fill3)?.[1];
1666
- if (fill3 && pattern && pattern !== "none" && pattern !== "gray125") {
1667
- const fg = this.color(/<(?:\w+:)?fgColor\b[^>]*>/.exec(fill3)?.[0]);
1343
+ const fill2 = this.fills[Number(a.fillId ?? 0)];
1344
+ const pattern = fill2 && /patternType="(\w+)"/.exec(fill2)?.[1];
1345
+ if (fill2 && pattern && pattern !== "none" && pattern !== "gray125") {
1346
+ const fg = this.color(/<(?:\w+:)?fgColor\b[^>]*>/.exec(fill2)?.[0]);
1668
1347
  if (fg) s.bg = { rgb: fg };
1669
1348
  }
1670
1349
  const border = this.parts(this.borders[Number(a.borderId ?? 0)] ?? "<border/>");
@@ -1977,7 +1656,7 @@ function load(bytes) {
1977
1656
  let maxRow = -1, maxCol = -1;
1978
1657
  if (open && open.close > open.open) {
1979
1658
  const end = open.close;
1980
- let at = open.open, row2 = -1, col = -1;
1659
+ let at = open.open, row = -1, col = -1;
1981
1660
  while (at < end) {
1982
1661
  const lt = sxml.indexOf("<", at);
1983
1662
  if (lt < 0 || lt >= end) break;
@@ -1996,9 +1675,9 @@ function load(bytes) {
1996
1675
  const tag = sxml.slice(lt, gt + 1);
1997
1676
  if (name === "row") {
1998
1677
  const r = attr2(tag, "r");
1999
- row2 = r ? Number(r) - 1 : row2 + 1;
1678
+ row = r ? Number(r) - 1 : row + 1;
2000
1679
  col = -1;
2001
- rows.set(row2, { open: tag });
1680
+ rows.set(row, { open: tag });
2002
1681
  const rd = {};
2003
1682
  const ht = attr2(tag, "ht");
2004
1683
  if (ht !== null) rd.h = px.row(Number(ht));
@@ -2006,11 +1685,11 @@ function load(bytes) {
2006
1685
  if (/^(1|true)$/.test(attr2(tag, "hidden") ?? "")) rd.hd = 1;
2007
1686
  const rs = attr2(tag, "s");
2008
1687
  if (rs !== null && /^(1|true)$/.test(attr2(tag, "customFormat") ?? "")) {
2009
- rowStyles.set(row2, Number(rs));
1688
+ rowStyles.set(row, Number(rs));
2010
1689
  rd.s = useStyle(Number(rs));
2011
1690
  }
2012
- if (Object.keys(rd).length) rowData[row2] = rd;
2013
- if (rd.h !== void 0 || rd.hd || rd.s) maxRow = Math.max(maxRow, row2);
1691
+ if (Object.keys(rd).length) rowData[row] = rd;
1692
+ if (rd.h !== void 0 || rd.hd || rd.s) maxRow = Math.max(maxRow, row);
2014
1693
  at = gt + 1;
2015
1694
  continue;
2016
1695
  }
@@ -2037,8 +1716,8 @@ function load(bytes) {
2037
1716
  if (kind === "shared") {
2038
1717
  shared = true;
2039
1718
  const si = attr2(f[0], "si") ?? "";
2040
- if (formula) masters.set(si, { f: formula, r: row2, c: col });
2041
- else children.push([row2, col, si]);
1719
+ if (formula) masters.set(si, { f: formula, r: row, c: col });
1720
+ else children.push([row, col, si]);
2042
1721
  if (formula) out.f = "=" + plain(formula);
2043
1722
  } else if (kind !== "dataTable" && formula) out.f = "=" + plain(formula);
2044
1723
  }
@@ -2069,16 +1748,16 @@ function load(bytes) {
2069
1748
  }
2070
1749
  }
2071
1750
  }
2072
- const styled = s || rowStyles.has(row2) || cols.some((spec) => spec.style !== void 0 && col + 1 >= spec.min && col + 1 <= spec.max);
1751
+ const styled = s || rowStyles.has(row) || cols.some((spec) => spec.style !== void 0 && col + 1 >= spec.min && col + 1 <= spec.max);
2073
1752
  if (styled) out.s = useStyle(s);
2074
1753
  if (out.v !== void 0 || out.f || out.s || shared) {
2075
- (cellData[row2] ?? (cellData[row2] = {}))[col] = out;
1754
+ (cellData[row] ?? (cellData[row] = {}))[col] = out;
2076
1755
  if (out.v !== void 0 || out.f || s) {
2077
- maxRow = Math.max(maxRow, row2);
1756
+ maxRow = Math.max(maxRow, row);
2078
1757
  maxCol = Math.max(maxCol, col);
2079
1758
  }
2080
1759
  }
2081
- cells.set(key(row2, col), { start: lt, end: stop, shared });
1760
+ cells.set(key(row, col), { start: lt, end: stop, shared });
2082
1761
  at = stop;
2083
1762
  }
2084
1763
  }
@@ -2999,7 +2678,7 @@ function writeSheet(original, model, kind) {
2999
2678
  // src/sheets/shared.ts
3000
2679
  import * as Y from "yjs";
3001
2680
  var props = ["name", "hidden", "tabColor", "freeze", "showGridlines", "rightToLeft"];
3002
- var spot = (row2, col) => `${row2}:${col}`;
2681
+ var spot = (row, col) => `${row}:${col}`;
3003
2682
  var canon = (x) => x === null || typeof x !== "object" ? JSON.stringify(x ?? null) : Array.isArray(x) ? `[${x.map(canon).join(",")}]` : `{${Object.keys(x).filter((k) => x[k] !== void 0).sort().map((k) => `${JSON.stringify(k)}:${canon(x[k])}`).join(",")}}`;
3004
2683
  var strip = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0 && v !== null));
3005
2684
  var fnv = (bytes, h = 2166136261) => {
@@ -3035,7 +2714,7 @@ function made(config, lines2) {
3035
2714
  for (const name of ["cells", "rowData", "colData", "merges", "notes"]) m.set(name, new Y.Map());
3036
2715
  return m;
3037
2716
  }
3038
- function fill2(doc, model) {
2717
+ function fill(doc, model) {
3039
2718
  const { book: wb, lines: lines2 } = model;
3040
2719
  const book = doc.getMap("book");
3041
2720
  const notes2 = JSON.parse(wb.resources?.find((r) => r.name === "SHEET_NOTE_PLUGIN")?.data ?? "{}");
@@ -3083,8 +2762,8 @@ function sheetOf(doc, sid, l) {
3083
2762
  const rows = new Map(l.rows.map((id, i) => [id, i])), cols = new Map(l.cols.map((id, i) => [id, i]));
3084
2763
  const cellData = {};
3085
2764
  for (const [at, x] of cells) {
3086
- const [row2, col] = at.split(":");
3087
- const r = rows.get(row2), c = cols.get(col);
2765
+ const [row, col] = at.split(":");
2766
+ const r = rows.get(row), c = cols.get(col);
3088
2767
  if (r === void 0 || c === void 0) continue;
3089
2768
  const kept = x.f ? values.get(`${sid}:${at}`) : void 0;
3090
2769
  (cellData[r] ?? (cellData[r] = {}))[c] = kept ? { ...x, v: kept.v, t: kept.t } : { ...x };
@@ -3433,7 +3112,7 @@ function seed(doc, kind, bytes, json) {
3433
3112
  if (filled(doc)) return false;
3434
3113
  const fixed = new Y2.Doc();
3435
3114
  fixed.clientID = fnv(new Uint8Array(bytes), fnv(new TextEncoder().encode(`${version}:${kind}`)));
3436
- if (kind === "xlsx" || kind === "csv") fill2(fixed, readSheet(bytes, kind));
3115
+ if (kind === "xlsx" || kind === "csv") fill(fixed, readSheet(bytes, kind));
3437
3116
  else prosemirrorJSONToYXmlFragment(schemaOf(kind), json, fixed.getXmlFragment("default"));
3438
3117
  Y2.applyUpdate(doc, Y2.encodeStateAsUpdate(fixed), ours);
3439
3118
  return true;
@@ -3576,9 +3255,6 @@ export {
3576
3255
  indent,
3577
3256
  clear,
3578
3257
  locate,
3579
- fromMarkdown,
3580
- track,
3581
- toMarkdown,
3582
3258
  SheetRefusal,
3583
3259
  fresh,
3584
3260
  insert,
@@ -3613,4 +3289,4 @@ export {
3613
3289
  applyText,
3614
3290
  save
3615
3291
  };
3616
- //# sourceMappingURL=chunk-BGH36LAR.js.map
3292
+ //# sourceMappingURL=chunk-GN3ZOD36.js.map