@w100n/documents 0.15.0 → 0.16.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.
package/dist/collab.cjs CHANGED
@@ -50,7 +50,7 @@ var import_y_tiptap2 = require("@tiptap/y-tiptap");
50
50
  var Y2 = __toESM(require("yjs"), 1);
51
51
 
52
52
  // package.json
53
- var version = "0.15.0";
53
+ var version = "0.16.0";
54
54
 
55
55
  // src/docx/xml.ts
56
56
  function parse(s) {
@@ -187,35 +187,35 @@ function unzip(buf) {
187
187
  while (eocd >= 0 && view.getUint32(eocd, true) !== 101010256) eocd--;
188
188
  if (eocd < 0) throw new Error("Not a DOCX file");
189
189
  const count = view.getUint16(eocd + 10, true);
190
- let at = view.getUint32(eocd + 16, true);
191
- if (count === 65535 || at === 4294967295) throw new Error("ZIP64 DOCX files are not supported");
190
+ let at2 = view.getUint32(eocd + 16, true);
191
+ if (count === 65535 || at2 === 4294967295) throw new Error("ZIP64 DOCX files are not supported");
192
192
  const names = new TextDecoder();
193
193
  const out = [];
194
194
  for (let n = 0; n < count; n++) {
195
- if (view.getUint32(at, true) !== 33639248) throw new Error("Broken DOCX file");
196
- const length = view.getUint16(at + 28, true);
197
- const extra = view.getUint16(at + 30, true);
198
- const note = view.getUint16(at + 32, true);
199
- const local = view.getUint32(at + 42, true);
200
- const csize = view.getUint32(at + 20, true);
201
- const path = buf.subarray(at + 46, at + 46 + length);
195
+ if (view.getUint32(at2, true) !== 33639248) throw new Error("Broken DOCX file");
196
+ const length = view.getUint16(at2 + 28, true);
197
+ const extra = view.getUint16(at2 + 30, true);
198
+ const note = view.getUint16(at2 + 32, true);
199
+ const local = view.getUint32(at2 + 42, true);
200
+ const csize = view.getUint32(at2 + 20, true);
201
+ const path = buf.subarray(at2 + 46, at2 + 46 + length);
202
202
  const begin = local + 30 + view.getUint16(local + 26, true) + view.getUint16(local + 28, true);
203
203
  out.push({
204
204
  name: names.decode(path),
205
205
  path,
206
- made: view.getUint16(at + 4, true),
207
- version: view.getUint16(at + 6, true),
208
- flags: view.getUint16(at + 8, true),
209
- method: view.getUint16(at + 10, true),
210
- time: view.getUint16(at + 12, true),
211
- date: view.getUint16(at + 14, true),
212
- crc: view.getUint32(at + 16, true),
213
- size: view.getUint32(at + 24, true),
214
- inner: view.getUint16(at + 36, true),
215
- outer: view.getUint32(at + 38, true),
206
+ made: view.getUint16(at2 + 4, true),
207
+ version: view.getUint16(at2 + 6, true),
208
+ flags: view.getUint16(at2 + 8, true),
209
+ method: view.getUint16(at2 + 10, true),
210
+ time: view.getUint16(at2 + 12, true),
211
+ date: view.getUint16(at2 + 14, true),
212
+ crc: view.getUint32(at2 + 16, true),
213
+ size: view.getUint32(at2 + 24, true),
214
+ inner: view.getUint16(at2 + 36, true),
215
+ outer: view.getUint32(at2 + 38, true),
216
216
  raw: buf.subarray(begin, begin + csize)
217
217
  });
218
- at += 46 + length + extra + note;
218
+ at2 += 46 + length + extra + note;
219
219
  }
220
220
  return out;
221
221
  }
@@ -248,49 +248,49 @@ function zip(entries2) {
248
248
  const buf = new Uint8Array(total);
249
249
  const view = new DataView(buf.buffer);
250
250
  const offsets = [];
251
- let at = 0;
251
+ let at2 = 0;
252
252
  for (const e of entries2) {
253
- offsets.push(at);
254
- view.setUint32(at, 67324752, true);
255
- view.setUint16(at + 4, e.version, true);
256
- view.setUint16(at + 6, e.flags & ~8, true);
257
- view.setUint16(at + 8, e.method, true);
258
- view.setUint16(at + 10, e.time, true);
259
- view.setUint16(at + 12, e.date, true);
260
- view.setUint32(at + 14, e.crc, true);
261
- view.setUint32(at + 18, e.raw.length, true);
262
- view.setUint32(at + 22, e.size, true);
263
- view.setUint16(at + 26, e.path.length, true);
264
- view.setUint16(at + 28, 0, true);
265
- buf.set(e.path, at + 30);
266
- buf.set(e.raw, at + 30 + e.path.length);
267
- at += 30 + e.path.length + e.raw.length;
268
- }
269
- const start = at;
253
+ offsets.push(at2);
254
+ view.setUint32(at2, 67324752, true);
255
+ view.setUint16(at2 + 4, e.version, true);
256
+ view.setUint16(at2 + 6, e.flags & ~8, true);
257
+ view.setUint16(at2 + 8, e.method, true);
258
+ view.setUint16(at2 + 10, e.time, true);
259
+ view.setUint16(at2 + 12, e.date, true);
260
+ view.setUint32(at2 + 14, e.crc, true);
261
+ view.setUint32(at2 + 18, e.raw.length, true);
262
+ view.setUint32(at2 + 22, e.size, true);
263
+ view.setUint16(at2 + 26, e.path.length, true);
264
+ view.setUint16(at2 + 28, 0, true);
265
+ buf.set(e.path, at2 + 30);
266
+ buf.set(e.raw, at2 + 30 + e.path.length);
267
+ at2 += 30 + e.path.length + e.raw.length;
268
+ }
269
+ const start = at2;
270
270
  entries2.forEach((e, n) => {
271
- view.setUint32(at, 33639248, true);
272
- view.setUint16(at + 4, e.made, true);
273
- view.setUint16(at + 6, e.version, true);
274
- view.setUint16(at + 8, e.flags & ~8, true);
275
- view.setUint16(at + 10, e.method, true);
276
- view.setUint16(at + 12, e.time, true);
277
- view.setUint16(at + 14, e.date, true);
278
- view.setUint32(at + 16, e.crc, true);
279
- view.setUint32(at + 20, e.raw.length, true);
280
- view.setUint32(at + 24, e.size, true);
281
- view.setUint16(at + 28, e.path.length, true);
282
- view.setUint16(at + 36, e.inner, true);
283
- view.setUint32(at + 38, e.outer, true);
284
- view.setUint32(at + 42, offsets[n], true);
285
- buf.set(e.path, at + 46);
286
- at += 46 + e.path.length;
271
+ view.setUint32(at2, 33639248, true);
272
+ view.setUint16(at2 + 4, e.made, true);
273
+ view.setUint16(at2 + 6, e.version, true);
274
+ view.setUint16(at2 + 8, e.flags & ~8, true);
275
+ view.setUint16(at2 + 10, e.method, true);
276
+ view.setUint16(at2 + 12, e.time, true);
277
+ view.setUint16(at2 + 14, e.date, true);
278
+ view.setUint32(at2 + 16, e.crc, true);
279
+ view.setUint32(at2 + 20, e.raw.length, true);
280
+ view.setUint32(at2 + 24, e.size, true);
281
+ view.setUint16(at2 + 28, e.path.length, true);
282
+ view.setUint16(at2 + 36, e.inner, true);
283
+ view.setUint32(at2 + 38, e.outer, true);
284
+ view.setUint32(at2 + 42, offsets[n], true);
285
+ buf.set(e.path, at2 + 46);
286
+ at2 += 46 + e.path.length;
287
287
  });
288
- view.setUint32(at, 101010256, true);
289
- view.setUint16(at + 8, entries2.length, true);
290
- view.setUint16(at + 10, entries2.length, true);
291
- view.setUint32(at + 12, at - start, true);
292
- view.setUint32(at + 16, start, true);
293
- return buf.subarray(0, at + 22);
288
+ view.setUint32(at2, 101010256, true);
289
+ view.setUint16(at2 + 8, entries2.length, true);
290
+ view.setUint16(at2 + 10, entries2.length, true);
291
+ view.setUint32(at2 + 12, at2 - start, true);
292
+ view.setUint32(at2 + 16, start, true);
293
+ return buf.subarray(0, at2 + 22);
294
294
  }
295
295
 
296
296
  // src/docx/pkg.ts
@@ -1542,10 +1542,10 @@ function diff(a, b) {
1542
1542
  if (x >= n && y >= m) {
1543
1543
  for (let e = d; e > 0; e--) {
1544
1544
  const t = trace[e];
1545
- const at = (j) => t[j + e + 1];
1546
- const down2 = k === -e || k !== e && at(k - 1) < at(k + 1);
1545
+ const at2 = (j) => t[j + e + 1];
1546
+ const down2 = k === -e || k !== e && at2(k - 1) < at2(k + 1);
1547
1547
  const pk = down2 ? k + 1 : k - 1;
1548
- const px2 = at(pk);
1548
+ const px2 = at2(pk);
1549
1549
  const py = px2 - pk;
1550
1550
  while (x > px2 && y > py) map[p + --y] = p + --x;
1551
1551
  x = px2;
@@ -1712,10 +1712,10 @@ function checked(xml, on2) {
1712
1712
  const no = /w14:uncheckedState\b[^>]*w14:val="([0-9A-Fa-f]+)"/.exec(xml)?.[1] ?? "2610";
1713
1713
  const [from, to] = on2 ? [no, yes] : [yes, no];
1714
1714
  let out = /<w14:checked\b/.test(xml) ? xml.replace(/(<w14:checked\b[^>]*w14:val=")[^"]*"/, `$1${on2 ? 1 : 0}"`) : xml.replace(/(<w14:checkbox\b[^>]*>)/, `$1<w14:checked w14:val="${on2 ? 1 : 0}"/>`);
1715
- const at = out.indexOf("<w:sdtContent");
1716
- if (at === -1) return out;
1717
- const tail = out.slice(at).replace(new RegExp(`w:char="${from}"`, "i"), `w:char="${to}"`).replace(`>${String.fromCharCode(parseInt(from, 16))}<`, `>${String.fromCharCode(parseInt(to, 16))}<`);
1718
- out = out.slice(0, at) + tail;
1715
+ const at2 = out.indexOf("<w:sdtContent");
1716
+ if (at2 === -1) return out;
1717
+ const tail = out.slice(at2).replace(new RegExp(`w:char="${from}"`, "i"), `w:char="${to}"`).replace(`>${String.fromCharCode(parseInt(from, 16))}<`, `>${String.fromCharCode(parseInt(to, 16))}<`);
1718
+ out = out.slice(0, at2) + tail;
1719
1719
  return out;
1720
1720
  }
1721
1721
  var Writer = class {
@@ -1781,9 +1781,9 @@ var Writer = class {
1781
1781
  <w:numbering xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"></w:numbering>`;
1782
1782
  this.types.add(`<Override PartName="/${path}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/>`);
1783
1783
  }
1784
- const at = n.search(/<w:num\b[\s>]/);
1784
+ const at2 = n.search(/<w:num\b[\s>]/);
1785
1785
  const abs = this.numbering.abs.join("");
1786
- n = at === -1 ? n.replace(/(<w:numIdMacAtCleanup\b|<\/w:numbering>)/, abs + "$1") : n.slice(0, at) + abs + n.slice(at);
1786
+ n = at2 === -1 ? n.replace(/(<w:numIdMacAtCleanup\b|<\/w:numbering>)/, abs + "$1") : n.slice(0, at2) + abs + n.slice(at2);
1787
1787
  n = n.replace(/(<w:numIdMacAtCleanup\b|<\/w:numbering>)/, this.numbering.nums.join("") + "$1");
1788
1788
  changed2.set(path, n);
1789
1789
  if (!rel) {
@@ -1796,8 +1796,8 @@ var Writer = class {
1796
1796
  const settings = this.tocs && this.pkg.byType("/settings");
1797
1797
  const listed2 = settings && this.pkg.text(settings.target);
1798
1798
  if (settings && listed2 && !/<w:updateFields\b/.test(listed2)) {
1799
- const at = listed2.search(/<(?:w:hdrShapeDefaults|w:footnotePr|w:endnotePr|w:compat|w:docVars|w:rsids|m:mathPr|w:attachedSchema|w:themeFontLang|w:clrSchemeMapping|w:doNotIncludeSubdocsInStats|w:doNotAutoCompressPictures|w:forceUpgrade|w:captions|w:readModeInkLockDown|w:smartTagType|sl:schemaLibrary|w:shapeDefaults|w:doNotEmbedSmartTags|w:decimalSymbol|w:listSeparator)\b|<\/w:settings>/);
1800
- changed2.set(settings.target, listed2.slice(0, at) + '<w:updateFields w:val="true"/>' + listed2.slice(at));
1799
+ const at2 = listed2.search(/<(?:w:hdrShapeDefaults|w:footnotePr|w:endnotePr|w:compat|w:docVars|w:rsids|m:mathPr|w:attachedSchema|w:themeFontLang|w:clrSchemeMapping|w:doNotIncludeSubdocsInStats|w:doNotAutoCompressPictures|w:forceUpgrade|w:captions|w:readModeInkLockDown|w:smartTagType|sl:schemaLibrary|w:shapeDefaults|w:doNotEmbedSmartTags|w:decimalSymbol|w:listSeparator)\b|<\/w:settings>/);
1800
+ changed2.set(settings.target, listed2.slice(0, at2) + '<w:updateFields w:val="true"/>' + listed2.slice(at2));
1801
1801
  }
1802
1802
  if (this.styleXml.length) {
1803
1803
  const rel = this.pkg.byType("/styles");
@@ -1897,20 +1897,20 @@ var Writer = class {
1897
1897
  return ++this.lastNote;
1898
1898
  }
1899
1899
  footnotes(doc, changed2) {
1900
- const notes2 = [];
1900
+ const notes3 = [];
1901
1901
  const walk = (n) => {
1902
- if (n.type === "footnote" && n.attrs?.id) notes2.push({ id: String(n.attrs.id), text: String(n.attrs.text ?? "") });
1902
+ if (n.type === "footnote" && n.attrs?.id) notes3.push({ id: String(n.attrs.id), text: String(n.attrs.text ?? "") });
1903
1903
  n.content?.forEach(walk);
1904
1904
  };
1905
1905
  walk(doc);
1906
1906
  const rel = this.pkg.byType("/footnotes");
1907
1907
  const old = rel ? this.pkg.text(rel.target) : null;
1908
- if (!notes2.length) return;
1908
+ if (!notes3.length) return;
1909
1909
  const path = rel ? rel.target : "word/footnotes.xml";
1910
1910
  let xml = old ?? `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1911
1911
  <w:footnotes xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="${REL}"><w:footnote w:type="separator" w:id="-1"><w:p><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:r><w:separator/></w:r></w:p></w:footnote><w:footnote w:type="continuationSeparator" w:id="0"><w:p><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:r><w:continuationSeparator/></w:r></w:p></w:footnote></w:footnotes>`;
1912
1912
  const fresh = (id, words2) => `<w:footnote w:id="${id}"><w:p><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:r><w:rPr><w:vertAlign w:val="superscript"/></w:rPr><w:footnoteRef/></w:r><w:r><w:rPr><w:sz w:val="20"/></w:rPr><w:t xml:space="preserve"> ${escape(words2)}</w:t></w:r></w:p></w:footnote>`;
1913
- for (const n of notes2) {
1913
+ for (const n of notes3) {
1914
1914
  const found = new RegExp(`<w:footnote\\b[^>]*\\bw:id="${n.id}"[^>]*>([\\s\\S]*?)</w:footnote>`).exec(xml);
1915
1915
  if (found && noteText(found[1]) === n.text) continue;
1916
1916
  xml = found ? xml.replace(found[0], fresh(n.id, n.text)) : xml.replace(/<\/w:footnotes>\s*$/, fresh(n.id, n.text) + "</w:footnotes>");
@@ -1957,8 +1957,8 @@ var Writer = class {
1957
1957
  sec = sec.replace(re, xml);
1958
1958
  return;
1959
1959
  }
1960
- const at = before.map((b) => sec.search(new RegExp(`<${b}[\\s>/]`))).filter((i2) => i2 >= 0);
1961
- const i = at.length ? Math.min(...at) : sec.lastIndexOf("</w:sectPr>");
1960
+ const at2 = before.map((b) => sec.search(new RegExp(`<${b}[\\s>/]`))).filter((i2) => i2 >= 0);
1961
+ const i = at2.length ? Math.min(...at2) : sec.lastIndexOf("</w:sectPr>");
1962
1962
  sec = sec.slice(0, i) + xml + sec.slice(i);
1963
1963
  };
1964
1964
  const tw = (px2) => Math.round(px2 * 15);
@@ -2223,11 +2223,11 @@ var Writer = class {
2223
2223
  }
2224
2224
  const slot = new Int32Array(A.length + 1);
2225
2225
  for (let k = 1; k <= A.length; k++) slot[k] = back[k - 1] >= 0 ? back[k - 1] + 1 : slot[k - 1];
2226
- const at = Array.from({ length: B.length + 1 }, () => []);
2226
+ const at2 = Array.from({ length: B.length + 1 }, () => []);
2227
2227
  let chars = 0;
2228
2228
  for (const u of units) {
2229
2229
  if (u.ch !== null) chars++;
2230
- else if (!u.box || o.task !== null) at[slot[chars]].push(u);
2230
+ else if (!u.box || o.task !== null) at2[slot[chars]].push(u);
2231
2231
  }
2232
2232
  const paraBase = b ? this.markRun(b) : this.firstRun(src);
2233
2233
  const out = [];
@@ -2241,7 +2241,7 @@ var Writer = class {
2241
2241
  const next = new Int32Array(B.length + 1).fill(-1);
2242
2242
  for (let k = B.length - 1; k >= 0; k--) next[k] = map[k] >= 0 ? map[k] : next[k + 1];
2243
2243
  for (let j = 0; j <= B.length; j++) {
2244
- for (const u of at[j]) out.push({ ch: null, raw: u.box && !u.run && b && b.task !== o.task ? checked(u.raw, !!o.task) : u.raw, run: u.run, ctx: u.ctx, u, fmt: u.fmt });
2244
+ for (const u of at2[j]) out.push({ ch: null, raw: u.box && !u.run && b && b.task !== o.task ? checked(u.raw, !!o.task) : u.raw, run: u.run, ctx: u.ctx, u, fmt: u.fmt });
2245
2245
  if (j === B.length) break;
2246
2246
  const i = map[j];
2247
2247
  const want = B[j];
@@ -2260,8 +2260,10 @@ var Writer = class {
2260
2260
  }
2261
2261
  if (want.note) {
2262
2262
  const u = i >= 0 ? A[i] : null;
2263
- if (u?.note && u.note.id === want.note.id) out.push({ ch: u.ch, raw: u.raw, run: u.run, ctx: u.ctx, u, fmt: u.fmt });
2264
- else {
2263
+ if (u?.note && (u.note.id === want.note.id || !want.note.id)) {
2264
+ want.note.id = u.note.id;
2265
+ out.push({ ch: u.ch, raw: u.raw, run: u.run, ctx: u.ctx, u, fmt: u.fmt });
2266
+ } else {
2265
2267
  want.note.id = typeof want.note.id === "string" && want.note.id ? want.note.id : String(this.noteId());
2266
2268
  out.push({ ch: want.ch, raw: `<w:footnoteReference w:id="${want.note.id}"/>`, run: { open: "<w:r>", rPr: '<w:rPr><w:vertAlign w:val="superscript"/></w:rPr>', fmt: plain, el: null, parent: null }, ctx: [], u: null, fmt: plain });
2267
2269
  }
@@ -2340,8 +2342,8 @@ var Writer = class {
2340
2342
  wrap = { open: tag, close: "</w:hyperlink>", link, ins: false };
2341
2343
  this.wraps.set(link, wrap);
2342
2344
  }
2343
- const at = out.findIndex((w) => w.ins);
2344
- return at === -1 ? [...out, wrap] : [...out.slice(0, at), wrap, ...out.slice(at)];
2345
+ const at2 = out.findIndex((w) => w.ins);
2346
+ return at2 === -1 ? [...out, wrap] : [...out.slice(0, at2), wrap, ...out.slice(at2)];
2345
2347
  }
2346
2348
  revised(ctx, rev) {
2347
2349
  const out = ctx.filter((w) => !w.rev || w.rev === rev);
@@ -2728,7 +2730,7 @@ function measure(view) {
2728
2730
  const gaps = [];
2729
2731
  const line = page.width - page.margins[1] - page.margins[3];
2730
2732
  const area = (list) => list.length ? 14 + list.reduce((h, text) => h + 15 * Math.max(1, Math.ceil(text.length * 5.6 / line)), 0) : 0;
2731
- let notes2 = [];
2733
+ let notes3 = [];
2732
2734
  let count = 0;
2733
2735
  let i = 0;
2734
2736
  let shift = 0;
@@ -2748,20 +2750,20 @@ function measure(view) {
2748
2750
  if (d.type.name === "footnote") mine.push(`${count + mine.length + 1} ${d.attrs.text}`);
2749
2751
  });
2750
2752
  if (node.type.name === "pageBreak") {
2751
- gaps.push({ pos: offset + node.nodeSize, height: start + room - end + bottom + 24 + top, page: gaps.length + 1, notes: notes2 });
2752
- notes2 = [];
2753
+ gaps.push({ pos: offset + node.nodeSize, height: start + room - end + bottom + 24 + top, page: gaps.length + 1, notes: notes3 });
2754
+ notes3 = [];
2753
2755
  start = end;
2754
- } else if (end > start + room - area([...notes2, ...mine]) && y > start) {
2755
- gaps.push({ pos: offset, height: start + room - y + bottom + 24 + top, page: gaps.length + 1, notes: notes2 });
2756
- notes2 = [];
2756
+ } else if (end > start + room - area([...notes3, ...mine]) && y > start) {
2757
+ gaps.push({ pos: offset, height: start + room - y + bottom + 24 + top, page: gaps.length + 1, notes: notes3 });
2758
+ notes3 = [];
2757
2759
  start = y;
2758
2760
  }
2759
- notes2.push(...mine);
2761
+ notes3.push(...mine);
2760
2762
  count += mine.length;
2761
2763
  while (end > start + room) start += room;
2762
2764
  last = end;
2763
2765
  });
2764
- gaps.push({ pos: view.state.doc.content.size, height: Math.max(0, start + room - last), page: gaps.length + 1, end: true, notes: notes2 });
2766
+ gaps.push({ pos: view.state.doc.content.size, height: Math.max(0, start + room - last), page: gaps.length + 1, end: true, notes: notes3 });
2765
2767
  return gaps.map((g) => ({ ...g, height: Math.max(0, Math.round(g.height)) }));
2766
2768
  }
2767
2769
  var Pager = import_core.Extension.create({
@@ -2769,10 +2771,10 @@ var Pager = import_core.Extension.create({
2769
2771
  addProseMirrorPlugins: () => [new import_state.Plugin({
2770
2772
  key: paging,
2771
2773
  state: {
2772
- init: () => ({ set: import_view.DecorationSet.empty, page: a4, marks: { header: "", footer: "" } }),
2774
+ init: () => ({ set: import_view.DecorationSet.empty, page: a4, marks: { header: "", footer: "" }, flow: false }),
2773
2775
  apply(tr, value3) {
2774
2776
  const next = tr.getMeta(paging);
2775
- return { set: next?.set ?? value3.set.map(tr.mapping, tr.doc), page: next?.page ?? value3.page, marks: next?.marks ?? value3.marks };
2777
+ return { set: next?.set ?? value3.set.map(tr.mapping, tr.doc), page: next?.page ?? value3.page, marks: next?.marks ?? value3.marks, flow: next?.flow ?? value3.flow };
2776
2778
  }
2777
2779
  },
2778
2780
  props: { decorations: (state) => paging.getState(state).set },
@@ -2781,8 +2783,13 @@ var Pager = import_core.Extension.create({
2781
2783
  let sig2 = "";
2782
2784
  const run2 = () => {
2783
2785
  if (!view.dom.isConnected) return;
2786
+ const { marks, flow } = paging.getState(view.state);
2787
+ if (flow) {
2788
+ if (sig2 !== "flow") view.dispatch(view.state.tr.setMeta(paging, { set: import_view.DecorationSet.empty }).setMeta("addToHistory", false));
2789
+ sig2 = "flow";
2790
+ return;
2791
+ }
2784
2792
  const gaps = measure(view);
2785
- const { marks } = paging.getState(view.state);
2786
2793
  const next = gaps.map((g) => `${g.pos}:${g.height}:${g.notes.join("\n")}`).join() + `|${marks.header}|${marks.footer}`;
2787
2794
  if (next === sig2) return;
2788
2795
  sig2 = next;
@@ -2833,7 +2840,8 @@ var Pager = import_core.Extension.create({
2833
2840
  later(0);
2834
2841
  return {
2835
2842
  update: (next, prev) => {
2836
- if (paging.getState(next.state).page !== paging.getState(prev).page || paging.getState(next.state).marks !== paging.getState(prev).marks) later(0);
2843
+ const now = paging.getState(next.state), was = paging.getState(prev);
2844
+ if (now.page !== was.page || now.marks !== was.marks || now.flow !== was.flow) later(0);
2837
2845
  else if (next.state.doc !== prev.doc) later(400);
2838
2846
  },
2839
2847
  destroy: () => {
@@ -2891,14 +2899,14 @@ var lookup = (doc, query, matchCase) => {
2891
2899
  doc.descendants((node, pos) => {
2892
2900
  if (!node.isTextblock) return true;
2893
2901
  let text = "";
2894
- const at = [];
2902
+ const at2 = [];
2895
2903
  node.forEach((child, offset) => {
2896
2904
  const part = child.isText ? child.text : "\uFFFC";
2897
- for (let i = 0; i < part.length; i++) at.push(pos + 1 + offset + i);
2905
+ for (let i = 0; i < part.length; i++) at2.push(pos + 1 + offset + i);
2898
2906
  text += part;
2899
2907
  });
2900
2908
  const hay = matchCase ? text : text.toLowerCase();
2901
- for (let i = hay.indexOf(needle); i >= 0; i = hay.indexOf(needle, i + needle.length)) hits.push({ from: at[i], to: at[i + needle.length - 1] + 1 });
2909
+ for (let i = hay.indexOf(needle); i >= 0; i = hay.indexOf(needle, i + needle.length)) hits.push({ from: at2[i], to: at2[i + needle.length - 1] + 1 });
2902
2910
  return false;
2903
2911
  });
2904
2912
  return hits;
@@ -2914,8 +2922,8 @@ var Search = import_core2.Extension.create({
2914
2922
  if (!meta2 && !tr.docChanged) return value3;
2915
2923
  const next = { ...value3, ...meta2 };
2916
2924
  const hits = lookup(tr.doc, next.query, next.matchCase);
2917
- const at = hits.length ? (next.at % hits.length + hits.length) % hits.length : 0;
2918
- return { ...next, hits, at, set: import_view2.DecorationSet.create(tr.doc, hits.map((h, i) => import_view2.Decoration.inline(h.from, h.to, { class: i === at ? "w100n-found is-current" : "w100n-found" }))) };
2925
+ const at2 = hits.length ? (next.at % hits.length + hits.length) % hits.length : 0;
2926
+ return { ...next, hits, at: at2, set: import_view2.DecorationSet.create(tr.doc, hits.map((h, i) => import_view2.Decoration.inline(h.from, h.to, { class: i === at2 ? "w100n-found is-current" : "w100n-found" }))) };
2919
2927
  }
2920
2928
  },
2921
2929
  props: { decorations: (state) => searching.getState(state).set }
@@ -2960,12 +2968,12 @@ var Blocks = import_core2.Extension.create({
2960
2968
  for (let i = start; i < end; i++) {
2961
2969
  const top = state.doc.child(i);
2962
2970
  visit(top, pos);
2963
- top.descendants((node, at) => visit(node, pos + 1 + at));
2971
+ top.descendants((node, at2) => visit(node, pos + 1 + at2));
2964
2972
  pos += top.nodeSize;
2965
2973
  }
2966
2974
  if (!drop.length) return null;
2967
2975
  const tr = state.tr;
2968
- for (const at of drop) tr.setNodeAttribute(at, "ref", null);
2976
+ for (const at2 of drop) tr.setNodeAttribute(at2, "ref", null);
2969
2977
  return tr;
2970
2978
  }
2971
2979
  })]
@@ -3012,6 +3020,31 @@ var Footnote = import_core2.Node.create({
3012
3020
  parseHTML: () => [{ tag: "sup[data-footnote]" }],
3013
3021
  renderHTML: ({ node }) => ["sup", { "data-footnote": "", "data-note-id": node.attrs.id ?? void 0, title: node.attrs.text, class: "w100n-fn", contenteditable: "false" }]
3014
3022
  });
3023
+ var EndNotes = import_core2.Extension.create({
3024
+ name: "endNotes",
3025
+ addProseMirrorPlugins: () => [new import_state2.Plugin({
3026
+ props: {
3027
+ decorations(state) {
3028
+ const notes3 = [];
3029
+ state.doc.descendants((n) => {
3030
+ if (n.type.name === "footnote") notes3.push(n.attrs.text);
3031
+ });
3032
+ if (!notes3.length) return null;
3033
+ return import_view2.DecorationSet.create(state.doc, [import_view2.Decoration.widget(state.doc.content.size, () => {
3034
+ const list = document.createElement("div");
3035
+ list.className = "w100n-text-endnotes";
3036
+ list.contentEditable = "false";
3037
+ notes3.forEach((text, i) => {
3038
+ const p = list.appendChild(document.createElement("p"));
3039
+ p.appendChild(document.createElement("sup")).textContent = String(i + 1);
3040
+ p.append(text);
3041
+ });
3042
+ return list;
3043
+ }, { key: notes3.join("\n"), side: 1, ignoreSelection: true })]);
3044
+ }
3045
+ }
3046
+ })]
3047
+ });
3015
3048
  var headings = (doc, after) => {
3016
3049
  const found = [];
3017
3050
  doc.descendants((node, pos) => {
@@ -3042,8 +3075,8 @@ var Toc = import_core2.Node.create({
3042
3075
  dom.className = "w100n-text-toc";
3043
3076
  dom.contentEditable = "false";
3044
3077
  const paint2 = () => {
3045
- const at = getPos() ?? 0;
3046
- const list = entries(editor.state.doc, this.options.relative, at);
3078
+ const at2 = getPos() ?? 0;
3079
+ const list = entries(editor.state.doc, this.options.relative, at2);
3047
3080
  const head = document.createElement("b");
3048
3081
  head.textContent = this.options.label;
3049
3082
  const items = list.map(([level, text], i) => {
@@ -3078,13 +3111,13 @@ var Toc = import_core2.Node.create({
3078
3111
  return [new import_state2.Plugin({
3079
3112
  appendTransaction(trs, _old, state) {
3080
3113
  if (!trs.some((tr2) => tr2.docChanged && !tr2.getMeta(import_y_tiptap.ySyncPluginKey))) return null;
3081
- const at = [];
3114
+ const at2 = [];
3082
3115
  state.doc.forEach((node, pos) => {
3083
- if (node.type.name === "toc") at.push(pos);
3116
+ if (node.type.name === "toc") at2.push(pos);
3084
3117
  });
3085
- if (!at.length) return null;
3118
+ if (!at2.length) return null;
3086
3119
  const tr = state.tr;
3087
- for (const pos of at) {
3120
+ for (const pos of at2) {
3088
3121
  const fresh = JSON.stringify(entries(state.doc, relative2, pos));
3089
3122
  if (state.doc.nodeAt(pos).attrs.entries !== fresh) tr.setNodeAttribute(pos, "entries", fresh);
3090
3123
  }
@@ -3127,10 +3160,10 @@ var Suggest = import_core2.Extension.create({
3127
3160
  const { state } = view;
3128
3161
  const tr = state.tr;
3129
3162
  if (to > from) strike(tr, state, from, to);
3130
- const at = tr.mapping.map(to);
3163
+ const at2 = tr.mapping.map(to);
3131
3164
  const kept = (state.storedMarks ?? state.doc.resolve(from).marks()).filter((m) => m.type.name !== "insertion" && m.type.name !== "deletion");
3132
- tr.insert(at, state.schema.text(text, [...kept, stamp(state, "insertion", from, to)]));
3133
- tr.setSelection(import_state2.TextSelection.create(tr.doc, at + text.length));
3165
+ tr.insert(at2, state.schema.text(text, [...kept, stamp(state, "insertion", from, to)]));
3166
+ tr.setSelection(import_state2.TextSelection.create(tr.doc, at2 + text.length));
3134
3167
  view.dispatch(tr.scrollIntoView());
3135
3168
  return true;
3136
3169
  };
@@ -3154,16 +3187,16 @@ var Suggest = import_core2.Extension.create({
3154
3187
  if (!suggesting.getState(state).on || event.key !== "Backspace" && event.key !== "Delete" || event.metaKey || event.ctrlKey || event.altKey) return false;
3155
3188
  const { from, to, empty, $from } = state.selection;
3156
3189
  const back = event.key === "Backspace";
3157
- let at = from;
3190
+ let at2 = from;
3158
3191
  if (empty) {
3159
3192
  const skip2 = (pos) => state.doc.resolve(pos)[back ? "nodeBefore" : "nodeAfter"]?.marks.some((m) => m.type.name === "deletion");
3160
- while (skip2(at)) at += back ? -1 : 1;
3161
- if (back ? at <= $from.start() : at >= $from.end()) return false;
3193
+ while (skip2(at2)) at2 += back ? -1 : 1;
3194
+ if (back ? at2 <= $from.start() : at2 >= $from.end()) return false;
3162
3195
  }
3163
3196
  const tr = state.tr;
3164
- if (empty) strike(tr, state, back ? at - 1 : at, back ? at : at + 1);
3197
+ if (empty) strike(tr, state, back ? at2 - 1 : at2, back ? at2 : at2 + 1);
3165
3198
  else strike(tr, state, from, to);
3166
- const caret = empty ? tr.mapping.map(back ? at - 1 : at + 1, back ? -1 : 1) : tr.mapping.map(back ? from : to);
3199
+ const caret = empty ? tr.mapping.map(back ? at2 - 1 : at2 + 1, back ? -1 : 1) : tr.mapping.map(back ? from : to);
3167
3200
  tr.setSelection(import_state2.TextSelection.create(tr.doc, caret));
3168
3201
  view.dispatch(tr.scrollIntoView());
3169
3202
  return true;
@@ -3235,10 +3268,10 @@ var Locks = import_core2.Extension.create({
3235
3268
  const { $from, empty } = view.state.selection;
3236
3269
  if (!back && event.key !== "Delete" || !empty || $from.depth < 1) return false;
3237
3270
  if (back ? $from.parentOffset !== 0 : $from.parentOffset !== $from.parent.content.size) return false;
3238
- const at = back ? $from.before() : $from.after();
3239
- const node = back ? view.state.doc.resolve(at).nodeBefore : view.state.doc.resolve(at).nodeAfter;
3271
+ const at2 = back ? $from.before() : $from.after();
3272
+ const node = back ? view.state.doc.resolve(at2).nodeBefore : view.state.doc.resolve(at2).nodeAfter;
3240
3273
  if (!node || !locked(node)) return false;
3241
- view.dispatch(view.state.tr.delete(back ? at - node.nodeSize : at, back ? at : at + node.nodeSize));
3274
+ view.dispatch(view.state.tr.delete(back ? at2 - node.nodeSize : at2, back ? at2 : at2 + node.nodeSize));
3242
3275
  return true;
3243
3276
  }
3244
3277
  }
@@ -3309,7 +3342,10 @@ function kit(kind, t, live) {
3309
3342
  Toc.configure({ relative: kind === "markdown", label: t.toc, empty: t.tocEmpty }),
3310
3343
  Note,
3311
3344
  Notes,
3312
- ...kind === "docx" ? [Formula, Footnote, Pager, Locks.configure({ label: t.locked }), revision("insertion", "ins"), revision("deletion", "del"), Suggest] : [],
3345
+ Formula,
3346
+ Footnote,
3347
+ EndNotes,
3348
+ ...kind === "docx" ? [Pager, Locks.configure({ label: t.locked }), revision("insertion", "ins"), revision("deletion", "del"), Suggest] : [],
3313
3349
  ...live ? [import_extension_collaboration.default.configure({ document: live.doc }), import_extension_collaboration_caret.default.configure({ provider: live.link, user: live.user })] : []
3314
3350
  ];
3315
3351
  }
@@ -3317,6 +3353,28 @@ function kit(kind, t, live) {
3317
3353
  // src/editor/markdown.ts
3318
3354
  var import_marked = require("marked");
3319
3355
  var import_prosemirror_markdown = require("prosemirror-markdown");
3356
+ var def = /^\[\^([^\]\s]+)\]:[ \t]*([^\n]*(?:\n {4}[^\n]*)*)(?:\n|$)/;
3357
+ var defs = new RegExp(def.source.slice(1), "gm");
3358
+ var noteOf = (text) => text.replace(/\n {4}/g, "\n").trim();
3359
+ var at = (src, find3) => {
3360
+ const i = src.search(find3);
3361
+ return i < 0 ? void 0 : i;
3362
+ };
3363
+ var marked = new import_marked.Marked({ extensions: [
3364
+ { name: "footnoteDef", level: "block", start: (src) => at(src, /^\[\^/m), tokenizer(src) {
3365
+ const m = def.exec(src);
3366
+ return m ? { type: "footnoteDef", raw: m[0], id: m[1], text: noteOf(m[2]) } : void 0;
3367
+ } },
3368
+ { name: "footnoteRef", level: "inline", start: (src) => at(src, /\[\^/), tokenizer(src) {
3369
+ const m = /^\[\^([^\]\s]+)\]/.exec(src);
3370
+ return m ? { type: "footnoteRef", raw: m[0], id: m[1] } : void 0;
3371
+ } },
3372
+ { name: "math", level: "inline", start: (src) => at(src, /\$/), tokenizer(src) {
3373
+ const m = /^\$\$([^$]+?)\$\$|^\$(?![\s$])((?:\\.|[^$\\\n])*?[^\s\\])\$(?!\d)/.exec(src);
3374
+ return m ? { type: "math", raw: m[0], text: (m[1] ?? m[2]).trim() } : void 0;
3375
+ } }
3376
+ ] });
3377
+ var notes2 = /* @__PURE__ */ new Map();
3320
3378
  var tags = { u: "underline", ins: "underline", mark: "highlight", s: "strike", del: "strike", b: "bold", strong: "bold", i: "italic", em: "italic" };
3321
3379
  var decode = (text) => text.includes("&") ? new DOMParser().parseFromString(`<p>${text.replace(/</g, "&lt;")}</p>`, "text/html").body.textContent ?? text : text;
3322
3380
  var unique = (marks) => [...new Map(marks.map((m) => [m.type, m])).values()];
@@ -3340,6 +3398,8 @@ function inline2(tokens = [], outer = []) {
3340
3398
  else if (token2.type === "del") wrap(token2.tokens, { type: "strike" });
3341
3399
  else if (token2.type === "codespan") text(token2.text, [{ type: "code" }]);
3342
3400
  else if (token2.type === "br") out.push({ type: "hardBreak" });
3401
+ else if (token2.type === "math") out.push({ type: "math", attrs: { latex: token2.text } });
3402
+ else if (token2.type === "footnoteRef") out.push({ type: "footnote", attrs: { id: token2.id, text: notes2.get(token2.id) ?? "" } });
3343
3403
  else if (token2.type === "link") wrap(token2.tokens, { type: "link", attrs: { href: token2.href } });
3344
3404
  else if (token2.type === "image") out.push({ type: "image", attrs: { src: token2.href, alt: token2.text || null, title: token2.title || null }, ...marks().length ? { marks: marks() } : {} });
3345
3405
  else if (token2.type === "html") {
@@ -3363,7 +3423,15 @@ function block(token2, hints) {
3363
3423
  case "space":
3364
3424
  case "def":
3365
3425
  case "checkbox":
3426
+ case "footnoteDef":
3366
3427
  return [];
3428
+ case "html": {
3429
+ const m = /^\s*<(p|h[1-6])\s+align="(center|right|justify)"\s*>([\s\S]*?)<\/\1>\s*$/i.exec(token2.raw);
3430
+ if (!m) return [{ type: "codeBlock", attrs: { language: "html" }, content: [{ type: "text", text: token2.raw.replace(/\n+$/, "") }] }];
3431
+ const content = inline2(marked.Lexer.lexInline(m[3].trim(), marked.defaults));
3432
+ const level = Number(m[1][1]);
3433
+ return [level ? { type: "heading", attrs: { level, align: m[2] }, content } : { type: "paragraph", attrs: { align: m[2] }, content }];
3434
+ }
3367
3435
  case "heading":
3368
3436
  return [{ type: "heading", attrs: { level: token2.depth }, content: inline2(token2.tokens) }];
3369
3437
  case "paragraph":
@@ -3375,8 +3443,6 @@ function block(token2, hints) {
3375
3443
  const fence = /^ {0,3}(`{3,}|~{3,})/.exec(token2.raw)?.[1][0];
3376
3444
  return [{ type: "codeBlock", attrs: { language: token2.lang || null, ref: fence ? ref({ fence: fence.repeat(3) }) : null }, content: token2.text ? [{ type: "text", text: token2.text }] : [] }];
3377
3445
  }
3378
- case "html":
3379
- return [{ type: "codeBlock", attrs: { language: "html" }, content: [{ type: "text", text: token2.raw.replace(/\n+$/, "") }] }];
3380
3446
  case "hr":
3381
3447
  return [{ type: "horizontalRule" }];
3382
3448
  case "list": {
@@ -3409,6 +3475,21 @@ function block(token2, hints) {
3409
3475
  var opens = /^\s*<!--\s*toc\s*-->\s*$/i;
3410
3476
  var shuts = /^\s*<!--\s*\/toc\s*-->\s*$/i;
3411
3477
  var row = /^(\s*)[-*+]\s+\[((?:\\.|[^\]\\])*)\]\(#[^)\s]*\)\s*$/;
3478
+ function aligned(tokens, i, hints) {
3479
+ const m = tokens[i].type === "html" ? /^\s*<div\s+align="(center|right|justify)"\s*>\s*$/i.exec(tokens[i].raw) : null;
3480
+ if (!m) return null;
3481
+ let j = i + 1;
3482
+ const skip2 = () => {
3483
+ while (tokens[j]?.type === "space") j++;
3484
+ };
3485
+ skip2();
3486
+ const inner2 = tokens[j]?.type === "paragraph" || tokens[j]?.type === "heading" ? tokens[j++] : null;
3487
+ skip2();
3488
+ if (!inner2 || tokens[j]?.type !== "html" || !/^\s*<\/div>\s*$/i.test(tokens[j].raw)) return null;
3489
+ const made2 = block(inner2, hints);
3490
+ made2[0].attrs = { ...made2[0].attrs, align: m[1] };
3491
+ return { end: j, made: made2 };
3492
+ }
3412
3493
  function contents2(tokens, i) {
3413
3494
  if (tokens[i].type !== "html" || !opens.test(tokens[i].raw)) return null;
3414
3495
  let j = i + 1;
@@ -3439,7 +3520,7 @@ function sniff(tokens) {
3439
3520
  style[key2] = value3;
3440
3521
  };
3441
3522
  let loose = 0;
3442
- import_marked.marked.walkTokens(tokens, (token2) => {
3523
+ marked.walkTokens(tokens, (token2) => {
3443
3524
  if (token2.type === "list") {
3444
3525
  const marker = /^\s*(?:([-*+])|\d+([.)]))/.exec(token2.raw);
3445
3526
  if (token2.ordered) note("delim", marker?.[2] ?? ".");
@@ -3456,7 +3537,11 @@ function sniff(tokens) {
3456
3537
  function fromMarkdown(source) {
3457
3538
  const bom = source.startsWith("\uFEFF");
3458
3539
  const crlf = source.includes("\r\n");
3459
- const tokens = import_marked.marked.lexer(source.slice(bom ? 1 : 0).replace(/\r\n?/g, "\n"));
3540
+ const tokens = marked.lexer(source.slice(bom ? 1 : 0).replace(/\r\n?/g, "\n"));
3541
+ notes2 = /* @__PURE__ */ new Map();
3542
+ marked.walkTokens(tokens, (token2) => {
3543
+ if (token2.type === "footnoteDef") notes2.set(token2.id, token2.text);
3544
+ });
3460
3545
  const hints = {};
3461
3546
  const content = [];
3462
3547
  const raws = [];
@@ -3464,8 +3549,8 @@ function fromMarkdown(source) {
3464
3549
  let gap = "";
3465
3550
  for (let i = 0; i < tokens.length; i++) {
3466
3551
  const token2 = tokens[i];
3467
- const toc = contents2(tokens, i);
3468
- const made2 = toc ? [{ type: "toc", attrs: { entries: JSON.stringify(toc.entries) } }] : block(token2, hints);
3552
+ const toc = contents2(tokens, i) ?? aligned(tokens, i, hints);
3553
+ const made2 = toc ? "made" in toc ? toc.made : [{ type: "toc", attrs: { entries: JSON.stringify(toc.entries) } }] : block(token2, hints);
3469
3554
  if (!made2.length) {
3470
3555
  gap += token2.raw;
3471
3556
  continue;
@@ -3525,17 +3610,36 @@ function serializer(style, hints, before, cell2 = false) {
3525
3610
  const bullet = hint(node).bullet ?? (run2(parent, index, ["bulletList", "taskList"]) ? style.bullet === "-" ? "*" : "-" : style.bullet);
3526
3611
  tight(state, node, () => state.renderList(node, " ", () => `${bullet} `));
3527
3612
  };
3613
+ const aligned2 = (state, node, render) => {
3614
+ const side2 = cell2 ? null : node.attrs.align;
3615
+ if (side2 && side2 !== "left") {
3616
+ state.write(`<div align="${side2}">`);
3617
+ state.closeBlock(node);
3618
+ }
3619
+ render();
3620
+ state.closeBlock(node);
3621
+ if (side2 && side2 !== "left") {
3622
+ state.write("</div>");
3623
+ state.closeBlock(node);
3624
+ }
3625
+ };
3528
3626
  const blank3 = { open: "", close: "", mixable: true };
3529
3627
  const wrap = (open, close = open) => ({ open, close, mixable: true, expelEnclosingWhitespace: true });
3530
3628
  return new import_prosemirror_markdown.MarkdownSerializer({
3531
3629
  paragraph(state, node) {
3532
- state.renderInline(node);
3533
- state.closeBlock(node);
3630
+ aligned2(state, node, () => state.renderInline(node));
3534
3631
  },
3535
3632
  heading(state, node) {
3536
- state.write(`${"#".repeat(node.attrs.level)} `);
3537
- state.renderInline(node, false);
3538
- state.closeBlock(node);
3633
+ aligned2(state, node, () => {
3634
+ state.write(`${"#".repeat(node.attrs.level)} `);
3635
+ state.renderInline(node, false);
3636
+ });
3637
+ },
3638
+ math(state, node, parent) {
3639
+ state.write(parent.childCount === 1 ? `$$${node.attrs.latex}$$` : `$${node.attrs.latex}$`);
3640
+ },
3641
+ footnote(state, node) {
3642
+ state.write(`[^${node.attrs.id}]`);
3539
3643
  },
3540
3644
  blockquote(state, node) {
3541
3645
  state.wrapBlock("> ", null, node, () => state.renderContent(node));
@@ -3645,6 +3749,13 @@ ${lines2.join("")}<!-- /toc -->`);
3645
3749
  }, { hardBreakNodeName: "hardBreak", strict: false, escapeExtraCharacters: /<(?=[A-Za-z/!?])/g });
3646
3750
  }
3647
3751
  var one = (node, before, base) => serializer(base.style, base.hints, before).serialize(node.type.schema.topNodeType.create(null, node)).replace(/\n+$/, "");
3752
+ var refs = (nodes) => {
3753
+ const found = /* @__PURE__ */ new Map();
3754
+ nodes.forEach((n) => n.descendants((d) => {
3755
+ if (d.type.name === "footnote" && d.attrs.id) found.set(d.attrs.id, d.attrs.text);
3756
+ }));
3757
+ return found;
3758
+ };
3648
3759
  function toMarkdown(doc, base) {
3649
3760
  const nodes = [];
3650
3761
  const found = [];
@@ -3656,22 +3767,35 @@ function toMarkdown(doc, base) {
3656
3767
  nodes.push(node);
3657
3768
  found.push(k);
3658
3769
  });
3659
- let out = base.head;
3770
+ const now = refs(nodes), was = refs(base.nodes);
3771
+ const seen = /* @__PURE__ */ new Set();
3772
+ const fix = (text2) => now.size || was.size ? text2.replace(defs, (all, id, note) => {
3773
+ if (!now.has(id)) return was.has(id) ? "" : all;
3774
+ seen.add(id);
3775
+ return noteOf(note) === now.get(id) ? all : `[^${id}]: ${now.get(id).replace(/\n/g, "\n ")}
3776
+ `;
3777
+ }) : text2;
3778
+ const kept = new Set(found);
3779
+ const lost = base.raws.filter((_, m) => !kept.has(m)).flatMap((raw) => marked.lexer(raw).filter((t) => t.type === "def" || t.type === "footnoteDef").map((t) => t.raw.replace(/\n*$/, "\n"))).join("");
3780
+ let out = fix(base.head);
3660
3781
  const starts = [];
3661
3782
  nodes.forEach((node, i) => {
3662
3783
  const k = found[i];
3663
3784
  if (i && !(k >= 0 && found[i - 1] === k - 1)) out = out.replace(/\n*$/, "\n\n");
3664
3785
  starts.push(out.length);
3665
- out += k >= 0 ? base.raws[k] : one(node, i ? nodes[i - 1] : null, base);
3786
+ out += k >= 0 ? fix(base.raws[k]) : one(node, i ? nodes[i - 1] : null, base);
3666
3787
  });
3667
3788
  const last = found[found.length - 1];
3668
3789
  const end = last >= 0 && last === base.nodes.length - 1;
3669
3790
  if (!end) out = out.replace(/\n*$/, "\n");
3670
3791
  const cut = out.length;
3671
- out += end ? base.tail : base.tail.trim() ? `
3672
- ${base.tail.replace(/^\n+/, "")}` : "";
3673
- const at = starts.map((s) => Math.min(s, cut));
3674
- const raws = at.map((s, i) => out.slice(s, i + 1 < at.length ? at[i + 1] : cut));
3792
+ out += fix(end ? base.tail : base.tail.trim() ? `
3793
+ ${base.tail.replace(/^\n+/, "")}` : "");
3794
+ const extra = fix(lost) + [...now].filter(([id]) => !seen.has(id)).map(([id, note]) => `[^${id}]: ${note.replace(/\n/g, "\n ")}
3795
+ `).join("");
3796
+ if (extra) out = `${out.replace(/\n*$/, "\n\n")}${extra}`;
3797
+ const at2 = starts.map((s) => Math.min(s, cut));
3798
+ const raws = at2.map((s, i) => out.slice(s, i + 1 < at2.length ? at2[i + 1] : cut));
3675
3799
  const text = base.crlf ? out.replace(/\n/g, "\r\n") : out;
3676
3800
  return { text: base.bom ? `\uFEFF${text}` : text, base: { ...base, nodes, raws, tail: out.slice(cut) } };
3677
3801
  }
@@ -3722,12 +3846,12 @@ function encode(text, encoding, bom) {
3722
3846
  if (encoding === "utf-16le" || encoding === "utf-16be") {
3723
3847
  const out2 = new Uint8Array(text.length * 2 + (bom ? 2 : 0));
3724
3848
  const view = new DataView(out2.buffer);
3725
- let at = 0;
3849
+ let at2 = 0;
3726
3850
  if (bom) {
3727
3851
  view.setUint16(0, 65279, encoding === "utf-16le");
3728
- at = 2;
3852
+ at2 = 2;
3729
3853
  }
3730
- for (let i = 0; i < text.length; i++) view.setUint16(at + i * 2, text.charCodeAt(i), encoding === "utf-16le");
3854
+ for (let i = 0; i < text.length; i++) view.setUint16(at2 + i * 2, text.charCodeAt(i), encoding === "utf-16le");
3731
3855
  return out2;
3732
3856
  }
3733
3857
  const table2 = /* @__PURE__ */ new Map();
@@ -4004,7 +4128,7 @@ function squeeze(b, rows, cols) {
4004
4128
  return r && c ? { startRow: r[0], endRow: r[1], startColumn: c[0], endColumn: c[1] } : null;
4005
4129
  }
4006
4130
  var token = /("(?:[^"]|"")*")|('(?:[^']|'')+'|[A-Za-z_À-￿][\w.À-￿]*)!|(\[(?:[^[\]]|\[[^\]]*\])*\])|(\$?[A-Za-z]{1,3}\$?\d+(?::\$?[A-Za-z]{1,3}\$?\d+)?|\$?[A-Za-z]{1,3}:\$?[A-Za-z]{1,3}|\$?\d+:\$?\d+)(?![\w(.!À-￿])/g;
4007
- function refs(formula, visit) {
4131
+ function refs2(formula, visit) {
4008
4132
  let sheet = null;
4009
4133
  let outside = false;
4010
4134
  let last = 0;
@@ -4036,7 +4160,7 @@ function refs(formula, visit) {
4036
4160
  return out + formula.slice(last);
4037
4161
  }
4038
4162
  function shifted(formula, dr, dc) {
4039
- return refs(formula, (p) => {
4163
+ return refs2(formula, (p) => {
4040
4164
  const ends = p.text.split(":").map(side);
4041
4165
  if (ends.some((e) => !e)) return p.text;
4042
4166
  for (const e of ends) {
@@ -4048,7 +4172,7 @@ function shifted(formula, dr, dc) {
4048
4172
  });
4049
4173
  }
4050
4174
  function remapped(formula, mine, rows, cols) {
4051
- return refs(formula, (p) => {
4175
+ return refs2(formula, (p) => {
4052
4176
  if (!mine(p.sheet)) return p.text;
4053
4177
  const b = box(p.text);
4054
4178
  const ends = p.text.split(":").map(side);
@@ -4433,8 +4557,8 @@ var Styles2 = class {
4433
4557
  return index;
4434
4558
  }
4435
4559
  add(list, xml) {
4436
- const at = this[list].indexOf(xml);
4437
- if (at >= 0) return at;
4560
+ const at2 = this[list].indexOf(xml);
4561
+ if (at2 >= 0) return at2;
4438
4562
  this[list].push(xml);
4439
4563
  this.added = true;
4440
4564
  return this[list].length - 1;
@@ -4513,8 +4637,8 @@ var Styles2 = class {
4513
4637
  edits2.push([el.start, el.end, `${open} count="${lists[name].length}">${lists[name].join("")}</${el.name}>`]);
4514
4638
  } else {
4515
4639
  const after = root.kids.find((k) => order2.indexOf(this.bare(k.name)) > order2.indexOf(name));
4516
- const at = after ? after.start : root.close;
4517
- edits2.push([at, at, `<${p}${name} count="${lists[name].length}">${lists[name].join("")}</${p}${name}>`]);
4640
+ const at2 = after ? after.start : root.close;
4641
+ edits2.push([at2, at2, `<${p}${name} count="${lists[name].length}">${lists[name].join("")}</${p}${name}>`]);
4518
4642
  }
4519
4643
  }
4520
4644
  edits2.sort((x, y) => y[0] - x[0]);
@@ -4592,7 +4716,7 @@ function load(bytes) {
4592
4716
  defaultStyle: styles.looks[0]
4593
4717
  };
4594
4718
  if (date1904) book.dateSystem = "date1904";
4595
- const notes2 = {};
4719
+ const notes3 = {};
4596
4720
  const validations = {};
4597
4721
  const filters = {};
4598
4722
  const model = { book, lines: {}, origin: { sheets: {}, lines: {} } };
@@ -4656,13 +4780,13 @@ function load(bytes) {
4656
4780
  let maxRow = -1, maxCol = -1;
4657
4781
  if (open && open.close > open.open) {
4658
4782
  const end = open.close;
4659
- let at = open.open, row2 = -1, col = -1;
4660
- while (at < end) {
4661
- const lt = sxml.indexOf("<", at);
4783
+ let at2 = open.open, row2 = -1, col = -1;
4784
+ while (at2 < end) {
4785
+ const lt = sxml.indexOf("<", at2);
4662
4786
  if (lt < 0 || lt >= end) break;
4663
4787
  const gt = sxml.indexOf(">", lt);
4664
4788
  if (sxml.charCodeAt(lt + 1) === 47) {
4665
- at = gt + 1;
4789
+ at2 = gt + 1;
4666
4790
  continue;
4667
4791
  }
4668
4792
  let j = lt + 1;
@@ -4690,11 +4814,11 @@ function load(bytes) {
4690
4814
  }
4691
4815
  if (Object.keys(rd).length) rowData[row2] = rd;
4692
4816
  if (rd.h !== void 0 || rd.hd || rd.s) maxRow = Math.max(maxRow, row2);
4693
- at = gt + 1;
4817
+ at2 = gt + 1;
4694
4818
  continue;
4695
4819
  }
4696
4820
  if (name !== "c") {
4697
- at = gt + 1;
4821
+ at2 = gt + 1;
4698
4822
  continue;
4699
4823
  }
4700
4824
  const ref = attr2(tag, "r");
@@ -4758,7 +4882,7 @@ function load(bytes) {
4758
4882
  }
4759
4883
  }
4760
4884
  cells.set(key(row2, col), { start: lt, end: stop, shared });
4761
- at = stop;
4885
+ at2 = stop;
4762
4886
  }
4763
4887
  }
4764
4888
  for (const [r, c, si] of children) {
@@ -4806,7 +4930,7 @@ function load(bytes) {
4806
4930
  sheetNotes.push(note);
4807
4931
  const [r, c] = cell(ref);
4808
4932
  if (r < 0) continue;
4809
- ((_b = notes2[sid] ?? (notes2[sid] = {}))[r] ?? (_b[r] = {}))[c] = { note: note.text, width: 160, height: 72, show: false, id: `n${sheetNotes.length - 1}`, row: r, col: c };
4933
+ ((_b = notes3[sid] ?? (notes3[sid] = {}))[r] ?? (_b[r] = {}))[c] = { note: note.text, width: 160, height: 72, show: false, id: `n${sheetNotes.length - 1}`, row: r, col: c };
4810
4934
  maxRow = Math.max(maxRow, r);
4811
4935
  maxCol = Math.max(maxCol, c);
4812
4936
  }
@@ -4863,7 +4987,7 @@ function load(bytes) {
4863
4987
  }
4864
4988
  const resources = book.resources;
4865
4989
  if (Object.keys(names).length) resources.push({ name: "SHEET_DEFINED_NAME_PLUGIN", data: JSON.stringify(names) });
4866
- if (Object.keys(notes2).length) resources.push({ name: "SHEET_NOTE_PLUGIN", data: JSON.stringify(notes2) });
4990
+ if (Object.keys(notes3).length) resources.push({ name: "SHEET_NOTE_PLUGIN", data: JSON.stringify(notes3) });
4867
4991
  if (Object.keys(validations).length) resources.push({ name: "SHEET_DATA_VALIDATION_PLUGIN", data: JSON.stringify(validations) });
4868
4992
  if (Object.keys(filters).length) resources.push({ name: "SHEET_FILTER_PLUGIN", data: JSON.stringify(filters) });
4869
4993
  const shown = entries2[active];
@@ -5035,14 +5159,14 @@ function place(xml, name, value3) {
5035
5159
  if (found) return xml.slice(0, found.start) + (value3 ?? "") + xml.slice(found.end);
5036
5160
  if (value3 === null) return xml;
5037
5161
  const rank = order.indexOf(name);
5038
- let at = -1;
5162
+ let at2 = -1;
5039
5163
  for (const later of order.slice(rank + 1)) {
5040
5164
  const f = find2(xml, later);
5041
- if (f && (at < 0 || f.start < at)) at = f.start;
5165
+ if (f && (at2 < 0 || f.start < at2)) at2 = f.start;
5042
5166
  }
5043
- if (at < 0) at = xml.search(/<\/(?:\w+:)?worksheet>\s*$/);
5044
- if (at < 0) at = xml.length;
5045
- return xml.slice(0, at) + value3 + xml.slice(at);
5167
+ if (at2 < 0) at2 = xml.search(/<\/(?:\w+:)?worksheet>\s*$/);
5168
+ if (at2 < 0) at2 = xml.length;
5169
+ return xml.slice(0, at2) + value3 + xml.slice(at2);
5046
5170
  }
5047
5171
  function remapZone(xml, mine, rows, cols) {
5048
5172
  const ranges = (sqref) => boxes(sqref).map((b) => squeeze(b, rows.map, cols.map)).filter((b) => b !== null).map(span).join(" ");
@@ -5293,12 +5417,12 @@ function writeXlsx(original, model) {
5293
5417
  tail = place(tail, "autoFilter", filter?.ref ? filterXml(p, filter.ref, filter.filterColumns ?? []) : null);
5294
5418
  filterNames.set(entry2.sheetId, filter?.ref ? `${quoted(sheet.name)}!${span(filter.ref).split(":").map((s) => s.replace(/([A-Z]+)(\d+)/, "$$$1$$$2")).join(":")}` : null);
5295
5419
  }
5296
- const notes2 = Object.values(curNotes?.[sid] ?? {}).flatMap((line) => Object.values(line ?? {})).filter((n) => n && !blank2(n.note));
5420
+ const notes3 = Object.values(curNotes?.[sid] ?? {}).flatMap((line) => Object.values(line ?? {})).filter((n) => n && !blank2(n.note));
5297
5421
  const oldNotes = (rec?.notes ?? []).map((n) => ({ ref: n.ref, text: n.text }));
5298
- const nowNotes = notes2.map((n) => ({ ref: a1(n.row, n.col), text: n.note })).sort((a, b) => a.ref.localeCompare(b.ref));
5422
+ const nowNotes = notes3.map((n) => ({ ref: a1(n.row, n.col), text: n.note })).sort((a, b) => a.ref.localeCompare(b.ref));
5299
5423
  if (curNotes && !same(nowNotes, [...oldNotes].sort((a, b) => a.ref.localeCompare(b.ref)))) {
5300
5424
  changed2 = true;
5301
- tail = writeNotes(book, entry2, tail, p, notes2, rows, cols, types, defaultsNeeded, fresh);
5425
+ tail = writeNotes(book, entry2, tail, p, notes3, rows, cols, types, defaultsNeeded, fresh);
5302
5426
  }
5303
5427
  const rename = (s) => names.size ? s.replace(/<(xm:f|(?:\w+:)?formula\d?)>([\s\S]*?)<\/\1>/g, (_, n, f) => `<${n}>${escape([...names].reduce((g, [from, to]) => renamed(g, from, to), unescape(f)))}</${n}>`) : s;
5304
5428
  if (!changed2) {
@@ -5388,9 +5512,9 @@ function writeXlsx(original, model) {
5388
5512
  listed2.push({ xml: tag, sheetId: s.sheetId, oldIndex: s.rec ? indexOf.get(s.sheetId) : -1 });
5389
5513
  }
5390
5514
  for (const { e, i } of nonSheets) {
5391
- let at = listed2.findIndex((x) => x.oldIndex > i);
5392
- if (at < 0) at = listed2.length;
5393
- listed2.splice(at, 0, { xml: e.xml, sheetId: e.sheetId, oldIndex: i });
5515
+ let at2 = listed2.findIndex((x) => x.oldIndex > i);
5516
+ if (at2 < 0) at2 = listed2.length;
5517
+ listed2.splice(at2, 0, { xml: e.xml, sheetId: e.sheetId, oldIndex: i });
5394
5518
  }
5395
5519
  wb = wb.replace(/(<(?:\w+:)?sheets\b[^>]*>)[\s\S]*?(<\/(?:\w+:)?sheets>)/, (_, a, b) => a + listed2.map((x) => x.xml).join("") + b);
5396
5520
  const newIndex = new Map(listed2.map((x, i) => [x.oldIndex, i]));
@@ -5418,8 +5542,8 @@ function writeXlsx(original, model) {
5418
5542
  });
5419
5543
  for (const [sheetId, f] of filterNames) {
5420
5544
  if (!f) continue;
5421
- const def = `<${wp}definedName name="_xlnm._FilterDatabase" localSheetId="${sheetIndex.get(sheetId)}" hidden="1">${escape(f)}</${wp}definedName>`;
5422
- wb = /<(?:\w+:)?definedNames\b/.test(wb) ? wb.replace(/<\/(?:\w+:)?definedNames>/, (end) => def + end) : wb.replace(/<\/(?:\w+:)?sheets>/, (end) => `${end}<${wp}definedNames>${def}</${wp}definedNames>`);
5545
+ const def2 = `<${wp}definedName name="_xlnm._FilterDatabase" localSheetId="${sheetIndex.get(sheetId)}" hidden="1">${escape(f)}</${wp}definedName>`;
5546
+ wb = /<(?:\w+:)?definedNames\b/.test(wb) ? wb.replace(/<\/(?:\w+:)?definedNames>/, (end) => def2 + end) : wb.replace(/<\/(?:\w+:)?sheets>/, (end) => `${end}<${wp}definedNames>${def2}</${wp}definedNames>`);
5423
5547
  }
5424
5548
  wb = wb.replace(/<((?:\w+:)?)definedNames>\s*<\/\1definedNames>/, "");
5425
5549
  wb = wb.replace(/<(?:\w+:)?workbookView\b[^>]*>/g, (tag) => {
@@ -5608,7 +5732,7 @@ function filterXml(p, ref, columns2) {
5608
5732
  }).join("");
5609
5733
  return body ? `<${p}autoFilter ref="${span(ref)}">${body}</${p}autoFilter>` : `<${p}autoFilter ref="${span(ref)}"/>`;
5610
5734
  }
5611
- function writeNotes(book, entry2, tail, p, notes2, rows, cols, types, defaults, fresh) {
5735
+ function writeNotes(book, entry2, tail, p, notes3, rows, cols, types, defaults, fresh) {
5612
5736
  const { pack } = book;
5613
5737
  const rec = entry2.rec;
5614
5738
  const relsPart = relsOf(entry2.part);
@@ -5635,7 +5759,7 @@ function writeNotes(book, entry2, tail, p, notes2, rows, cols, types, defaults,
5635
5759
  const [r, c] = cell(n.ref);
5636
5760
  return [a1(rows.map(r), cols.map(c)), n];
5637
5761
  }));
5638
- const list = [...notes2].sort((a, b) => a.row - b.row || a.col - b.col).map((n) => {
5762
+ const list = [...notes3].sort((a, b) => a.row - b.row || a.col - b.col).map((n) => {
5639
5763
  const ref = a1(n.row, n.col);
5640
5764
  const was = byOld.get(ref);
5641
5765
  if (was && was.text === n.note) return setAttr(was.xml.slice(0, was.xml.indexOf(">") + 1), "ref", ref) + was.xml.slice(was.xml.indexOf(">") + 1);
@@ -5656,7 +5780,7 @@ function writeNotes(book, entry2, tail, p, notes2, rows, cols, types, defaults,
5656
5780
  return "";
5657
5781
  });
5658
5782
  let id = Math.max(1024, ...[...vml2.matchAll(/_x0000_s(\d+)/g)].map((m) => Number(m[1])));
5659
- const out = notes2.map((n) => {
5783
+ const out = notes3.map((n) => {
5660
5784
  const ref = a1(n.row, n.col);
5661
5785
  const was = shapes.get(ref);
5662
5786
  if (was) return was.replace(/<x:Row>\d+<\/x:Row>/, `<x:Row>${n.row}</x:Row>`).replace(/<x:Column>\d+<\/x:Column>/, `<x:Column>${n.col}</x:Column>`).replace(/<x:Anchor>([^<]*)<\/x:Anchor>/, `<x:Anchor>${n.col + 1}, 15, ${n.row}, 2, ${n.col + 3}, 15, ${n.row + 4}, 16</x:Anchor>`);
@@ -5716,7 +5840,7 @@ function made(config, lines2) {
5716
5840
  function fill2(doc, model) {
5717
5841
  const { book: wb, lines: lines2 } = model;
5718
5842
  const book = doc.getMap("book");
5719
- const notes2 = JSON.parse(wb.resources?.find((r) => r.name === "SHEET_NOTE_PLUGIN")?.data ?? "{}");
5843
+ const notes3 = JSON.parse(wb.resources?.find((r) => r.name === "SHEET_NOTE_PLUGIN")?.data ?? "{}");
5720
5844
  doc.transact(() => {
5721
5845
  book.set("head", strip({ id: wb.id, name: wb.name, appVersion: wb.appVersion, locale: wb.locale, defaultStyle: wb.defaultStyle, dateSystem: wb.dateSystem }));
5722
5846
  book.set("extras", (wb.resources ?? []).filter((r) => r.name !== "SHEET_NOTE_PLUGIN"));
@@ -5734,23 +5858,23 @@ function fill2(doc, model) {
5734
5858
  const { cells, rowData, colData, merges, notes: kept } = pieces(sheets.get(sid));
5735
5859
  for (const [r, line] of Object.entries(sheet.cellData ?? {})) for (const [c, x] of Object.entries(line ?? {})) {
5736
5860
  if (!x) continue;
5737
- const at = spot(l.rows[+r], l.cols[+c]);
5861
+ const at2 = spot(l.rows[+r], l.cols[+c]);
5738
5862
  const out = {};
5739
5863
  if (x.f) {
5740
5864
  out.f = x.f;
5741
- values.set(`${sid}:${at}`, { v: x.v ?? null, t: x.t ?? null });
5865
+ values.set(`${sid}:${at2}`, { v: x.v ?? null, t: x.t ?? null });
5742
5866
  } else {
5743
5867
  if (x.v !== void 0 && x.v !== null) out.v = x.v;
5744
5868
  if (x.t) out.t = x.t;
5745
5869
  }
5746
5870
  if (x.p) out.p = x.p;
5747
5871
  if (typeof x.s === "string") out.s = x.s;
5748
- cells.set(at, out);
5872
+ cells.set(at2, out);
5749
5873
  }
5750
5874
  for (const [r, rd] of Object.entries(sheet.rowData ?? {})) if (rd) rowData.set(l.rows[+r], strip({ h: rd.h, hd: rd.hd, ia: rd.ia, s: typeof rd.s === "string" ? rd.s : void 0 }));
5751
5875
  for (const [c, cd] of Object.entries(sheet.columnData ?? {})) if (cd) colData.set(l.cols[+c], strip({ w: cd.w, hd: cd.hd, s: typeof cd.s === "string" ? cd.s : void 0 }));
5752
5876
  for (const b of sheet.mergeData ?? []) merges.set([l.rows[b.startRow], l.cols[b.startColumn], l.rows[b.endRow], l.cols[b.endColumn]].join(":"), 1);
5753
- for (const [r, line] of Object.entries(notes2[sid] ?? {})) for (const [c, n] of Object.entries(line)) kept.set(spot(l.rows[+r], l.cols[+c]), { note: n.note, width: n.width, height: n.height });
5877
+ for (const [r, line] of Object.entries(notes3[sid] ?? {})) for (const [c, n] of Object.entries(line)) kept.set(spot(l.rows[+r], l.cols[+c]), { note: n.note, width: n.width, height: n.height });
5754
5878
  }
5755
5879
  });
5756
5880
  }
@@ -5760,11 +5884,11 @@ function sheetOf(doc, sid, l) {
5760
5884
  const { cells, rowData, colData, merges } = pieces(m);
5761
5885
  const rows = new Map(l.rows.map((id, i) => [id, i])), cols = new Map(l.cols.map((id, i) => [id, i]));
5762
5886
  const cellData = {};
5763
- for (const [at, x] of cells) {
5764
- const [row2, col] = at.split(":");
5887
+ for (const [at2, x] of cells) {
5888
+ const [row2, col] = at2.split(":");
5765
5889
  const r = rows.get(row2), c = cols.get(col);
5766
5890
  if (r === void 0 || c === void 0) continue;
5767
- const kept = x.f ? values.get(`${sid}:${at}`) : void 0;
5891
+ const kept = x.f ? values.get(`${sid}:${at2}`) : void 0;
5768
5892
  (cellData[r] ?? (cellData[r] = {}))[c] = kept ? { ...x, v: kept.v, t: kept.t } : { ...x };
5769
5893
  }
5770
5894
  const rowsOut = {}, colsOut = {};
@@ -5777,14 +5901,14 @@ function sheetOf(doc, sid, l) {
5777
5901
  }
5778
5902
  var notesOf = (m, l) => {
5779
5903
  const rows = new Map(l.rows.map((id, i) => [id, i])), cols = new Map(l.cols.map((id, i) => [id, i]));
5780
- return [...pieces(m).notes].map(([at, n]) => ({ ...n, row: rows.get(at.split(":")[0]), col: cols.get(at.split(":")[1]) })).filter((n) => n.row !== void 0 && n.col !== void 0);
5904
+ return [...pieces(m).notes].map(([at2, n]) => ({ ...n, row: rows.get(at2.split(":")[0]), col: cols.get(at2.split(":")[1]) })).filter((n) => n.row !== void 0 && n.col !== void 0);
5781
5905
  };
5782
5906
  function build(doc) {
5783
5907
  const { book, order: order2, sheets, styles, origin } = parts(doc);
5784
5908
  const sheetOrder = [...new Set(order2.toArray())].filter((sid) => sheets.has(sid));
5785
5909
  const wb = { ...book.get("head"), styles: styles.toJSON(), sheetOrder, sheets: {}, resources: [] };
5786
5910
  const model = { book: wb, lines: {}, origin: { sheets: {}, lines: {} } };
5787
- const notes2 = {};
5911
+ const notes3 = {};
5788
5912
  for (const sid of sheetOrder) {
5789
5913
  const { rows, cols } = pieces(sheets.get(sid));
5790
5914
  const l = { rows: rows.toArray(), cols: cols.toArray() };
@@ -5792,14 +5916,14 @@ function build(doc) {
5792
5916
  wb.sheets[sid] = sheetOf(doc, sid, l);
5793
5917
  notesOf(sheets.get(sid), l).forEach((n, i) => {
5794
5918
  var _a, _b;
5795
- ((_a = notes2[sid] ?? (notes2[sid] = {}))[_b = n.row] ?? (_a[_b] = {}))[n.col] = { ...n, show: false, id: `n${i}` };
5919
+ ((_a = notes3[sid] ?? (notes3[sid] = {}))[_b = n.row] ?? (_a[_b] = {}))[n.col] = { ...n, show: false, id: `n${i}` };
5796
5920
  });
5797
5921
  const o = origin.get(sid);
5798
5922
  if (!o) continue;
5799
5923
  model.origin.sheets[sid] = o.id;
5800
5924
  model.origin.lines[sid] = { rows: typeof o.rows === "number" ? numbered("r", o.rows) : o.rows, cols: typeof o.cols === "number" ? numbered("c", o.cols) : o.cols };
5801
5925
  }
5802
- wb.resources.push({ name: "SHEET_NOTE_PLUGIN", data: JSON.stringify(notes2) });
5926
+ wb.resources.push({ name: "SHEET_NOTE_PLUGIN", data: JSON.stringify(notes3) });
5803
5927
  const active = book.get("active");
5804
5928
  if (active && sheetOrder.includes(active)) model.active = active;
5805
5929
  return model;
@@ -5827,16 +5951,16 @@ function applyCells(doc, list, origin) {
5827
5951
  if (!sid || r < 0) continue;
5828
5952
  const { rows, cols, cells } = pieces(sheets.get(sid));
5829
5953
  if (r >= rows.length || c >= cols.length) continue;
5830
- const at = spot(rows.get(r), cols.get(c));
5954
+ const at2 = spot(rows.get(r), cols.get(c));
5831
5955
  const next = {};
5832
5956
  if (x.formula !== void 0) next.f = x.formula.startsWith("=") ? x.formula : `=${x.formula}`;
5833
5957
  else if (typeof x.value === "boolean") Object.assign(next, { v: x.value ? 1 : 0, t: 3 });
5834
5958
  else if (x.value !== void 0 && x.value !== null && x.value !== "") Object.assign(next, { v: x.value, t: typeof x.value === "number" ? 2 : 1 });
5835
- const s = cells.get(at)?.s;
5959
+ const s = cells.get(at2)?.s;
5836
5960
  if (s) next.s = s;
5837
- values.delete(`${sid}:${at}`);
5838
- if (Object.keys(next).length) cells.set(at, next);
5839
- else cells.delete(at);
5961
+ values.delete(`${sid}:${at2}`);
5962
+ if (Object.keys(next).length) cells.set(at2, next);
5963
+ else cells.delete(at2);
5840
5964
  done++;
5841
5965
  }
5842
5966
  }, origin);
@@ -6098,8 +6222,17 @@ var en2 = {
6098
6222
  retry: "Try again",
6099
6223
  loading: "Loading",
6100
6224
  unsupported: "This file cannot be shown yet",
6225
+ printLayout: "Print layout",
6226
+ cut: "Cut",
6227
+ paste: "Paste",
6228
+ spellCheck: "Spell check",
6229
+ spellHint: "Spelling: right-click again",
6101
6230
  restore: "Restore this version",
6102
6231
  restoreFailed: "Could not restore",
6232
+ showChanges: "What changed",
6233
+ hideChanges: "Back to the version",
6234
+ noChanges: "Same text as now",
6235
+ changeCount: "Since this version, paragraphs: {added} added, {edited} changed, {removed} removed",
6103
6236
  allProjects: "All projects",
6104
6237
  closePanel: "Hide the panel",
6105
6238
  openPanel: "Show the panel",
@@ -6204,7 +6337,6 @@ var en2 = {
6204
6337
  footnote: "Footnote",
6205
6338
  footnoteText: "Footnote text",
6206
6339
  formula: "Formula",
6207
- formulaHint: "Saved as a Word equation",
6208
6340
  symbols: "Special characters",
6209
6341
  symbolSearch: "Search, for example arrow",
6210
6342
  update: "Update",
@@ -6424,8 +6556,17 @@ var pl2 = {
6424
6556
  retry: "Spr\xF3buj ponownie",
6425
6557
  loading: "Wczytywanie",
6426
6558
  unsupported: "Tego pliku nie da si\u0119 jeszcze pokaza\u0107",
6559
+ printLayout: "Uk\u0142ad wydruku",
6560
+ cut: "Wytnij",
6561
+ paste: "Wklej",
6562
+ spellCheck: "Sprawdzanie pisowni",
6563
+ spellHint: "Pisownia: kliknij prawym jeszcze raz",
6427
6564
  restore: "Przywr\xF3\u0107 t\u0119 wersj\u0119",
6428
6565
  restoreFailed: "Nie uda\u0142o si\u0119 przywr\xF3ci\u0107",
6566
+ showChanges: "Co si\u0119 zmieni\u0142o",
6567
+ hideChanges: "Wr\xF3\u0107 do wersji",
6568
+ noChanges: "Tekst taki sam jak teraz",
6569
+ changeCount: "Od tej wersji, akapity: {added} dodane, {edited} zmienione, {removed} usuni\u0119te",
6429
6570
  allProjects: "Wszystkie projekty",
6430
6571
  closePanel: "Ukryj panel",
6431
6572
  openPanel: "Poka\u017C panel",
@@ -6530,7 +6671,6 @@ var pl2 = {
6530
6671
  footnote: "Przypis",
6531
6672
  footnoteText: "Tekst przypisu",
6532
6673
  formula: "Wz\xF3r",
6533
- formulaHint: "Zapisany jako r\xF3wnanie Word",
6534
6674
  symbols: "Znaki specjalne",
6535
6675
  symbolSearch: "Szukaj, na przyk\u0142ad strza\u0142ka",
6536
6676
  update: "Zmie\u0144",
@@ -6750,8 +6890,17 @@ var uk2 = {
6750
6890
  retry: "\u0421\u043F\u0440\u043E\u0431\u0443\u0432\u0430\u0442\u0438 \u0449\u0435",
6751
6891
  loading: "\u0417\u0430\u0432\u0430\u043D\u0442\u0430\u0436\u0435\u043D\u043D\u044F",
6752
6892
  unsupported: "\u0426\u0435\u0439 \u0444\u0430\u0439\u043B \u043F\u043E\u043A\u0438 \u043D\u0435 \u043C\u043E\u0436\u043D\u0430 \u043F\u043E\u043A\u0430\u0437\u0430\u0442\u0438",
6893
+ printLayout: "\u0420\u043E\u0437\u043C\u0456\u0442\u043A\u0430 \u0441\u0442\u043E\u0440\u0456\u043D\u043A\u0438",
6894
+ cut: "\u0412\u0438\u0440\u0456\u0437\u0430\u0442\u0438",
6895
+ paste: "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u0438",
6896
+ spellCheck: "\u041F\u0435\u0440\u0435\u0432\u0456\u0440\u043A\u0430 \u043F\u0440\u0430\u0432\u043E\u043F\u0438\u0441\u0443",
6897
+ spellHint: "\u041F\u0440\u0430\u0432\u043E\u043F\u0438\u0441: \u043A\u043B\u0430\u0446\u043D\u0456\u0442\u044C \u043F\u0440\u0430\u0432\u043E\u044E \u0449\u0435 \u0440\u0430\u0437",
6753
6898
  restore: "\u0412\u0456\u0434\u043D\u043E\u0432\u0438\u0442\u0438 \u0446\u044E \u0432\u0435\u0440\u0441\u0456\u044E",
6754
6899
  restoreFailed: "\u041D\u0435 \u0432\u0434\u0430\u043B\u043E\u0441\u044F \u0432\u0456\u0434\u043D\u043E\u0432\u0438\u0442\u0438",
6900
+ showChanges: "\u0429\u043E \u0437\u043C\u0456\u043D\u0438\u043B\u043E\u0441\u044C",
6901
+ hideChanges: "\u041D\u0430\u0437\u0430\u0434 \u0434\u043E \u0432\u0435\u0440\u0441\u0456\u0457",
6902
+ noChanges: "\u0422\u0435\u043A\u0441\u0442 \u0442\u0430\u043A\u0438\u0439 \u0441\u0430\u043C\u0438\u0439, \u044F\u043A \u0437\u0430\u0440\u0430\u0437",
6903
+ changeCount: "\u0412\u0456\u0434\u0442\u043E\u0434\u0456 \u0430\u0431\u0437\u0430\u0446\u0456\u0432: {added} \u0434\u043E\u0434\u0430\u043D\u043E, {edited} \u0437\u043C\u0456\u043D\u0435\u043D\u043E, {removed} \u0432\u0438\u0434\u0430\u043B\u0435\u043D\u043E",
6755
6904
  allProjects: "\u0423\u0441\u0456 \u043F\u0440\u043E\u0454\u043A\u0442\u0438",
6756
6905
  closePanel: "\u0421\u0445\u043E\u0432\u0430\u0442\u0438 \u043F\u0430\u043D\u0435\u043B\u044C",
6757
6906
  openPanel: "\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u0438 \u043F\u0430\u043D\u0435\u043B\u044C",
@@ -6855,7 +7004,6 @@ var uk2 = {
6855
7004
  footnote: "\u0412\u0438\u043D\u043E\u0441\u043A\u0430",
6856
7005
  footnoteText: "\u0422\u0435\u043A\u0441\u0442 \u0432\u0438\u043D\u043E\u0441\u043A\u0438",
6857
7006
  formula: "\u0424\u043E\u0440\u043C\u0443\u043B\u0430",
6858
- formulaHint: "\u0417\u0431\u0435\u0440\u0456\u0433\u0430\u0454\u0442\u044C\u0441\u044F \u044F\u043A \u0440\u0456\u0432\u043D\u044F\u043D\u043D\u044F Word",
6859
7007
  symbols: "\u0421\u043F\u0435\u0446\u0441\u0438\u043C\u0432\u043E\u043B\u0438",
6860
7008
  symbolSearch: "\u041F\u043E\u0448\u0443\u043A, \u043D\u0430\u043F\u0440\u0438\u043A\u043B\u0430\u0434 \u0441\u0442\u0440\u0456\u043B\u043A\u0430",
6861
7009
  update: "\u0417\u043C\u0456\u043D\u0438\u0442\u0438",
@@ -7092,9 +7240,9 @@ function applyText(doc, kind, changes, origin) {
7092
7240
  return false;
7093
7241
  });
7094
7242
  if (hits.length !== 1) throw new Refusal(`${hits.length ? "more than once" : "not"} in the document: ${c.find.slice(0, 80)}`);
7095
- const [at] = hits;
7096
- if (c.replace) step.replaceWith(at, at + c.find.length, schema.text(c.replace, step.doc.resolve(at + 1).marks()));
7097
- else step.delete(at, at + c.find.length);
7243
+ const [at2] = hits;
7244
+ if (c.replace) step.replaceWith(at2, at2 + c.find.length, schema.text(c.replace, step.doc.resolve(at2 + 1).marks()));
7245
+ else step.delete(at2, at2 + c.find.length);
7098
7246
  }
7099
7247
  (0, import_y_tiptap2.updateYFragment)({ transact: (run2) => doc.transact(run2, origin) }, fragment, step.doc, { mapping: /* @__PURE__ */ new Map(), isOMark: /* @__PURE__ */ new Map() });
7100
7248
  return changes.length;
@@ -7140,13 +7288,13 @@ async function save(doc, kind, base, put, load2, note) {
7140
7288
  const bytes = await write2(kind, base, node, load2, doc.getMap("setup").size ? doc.getMap("setup").toJSON() : void 0);
7141
7289
  const changed2 = !same2(bytes, base);
7142
7290
  const id = changed2 ? await put(bytes, note ?? named2((texts[who[0].language] ?? texts.en).editedNote, who)) : null;
7143
- const refs2 = [];
7291
+ const refs3 = [];
7144
7292
  if (changed2) schema.nodeFromJSON(await parse3(kind, bytes)).descendants((n) => {
7145
- if (n.isBlock) refs2.push([n.type.name, n.attrs.ref ?? null]);
7293
+ if (n.isBlock) refs3.push([n.type.name, n.attrs.ref ?? null]);
7146
7294
  });
7147
7295
  doc.transact(() => {
7148
- if (refs2.length === list.length && list.every((el, i) => el.nodeName === refs2[i][0])) list.forEach((el, i) => {
7149
- const ref = refs2[i][1];
7296
+ if (refs3.length === list.length && list.every((el, i) => el.nodeName === refs3[i][0])) list.forEach((el, i) => {
7297
+ const ref = refs3[i][1];
7150
7298
  if ((el.getAttribute("ref") ?? null) === ref) return;
7151
7299
  if (ref === null) el.removeAttribute("ref");
7152
7300
  else el.setAttribute("ref", ref);