oasis-editor 0.0.83 → 0.0.85

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 (28) hide show
  1. package/dist/{OasisEditorApp-BI74x5qK.js → OasisEditorApp-D_hjBUA1.js} +82 -48
  2. package/dist/app/controllers/documentIO/ImageInsertionService.d.ts +2 -1
  3. package/dist/app/controllers/tableOpsSelectionAwareCommands.d.ts +2 -1
  4. package/dist/app/controllers/useEditorDocumentIO.d.ts +2 -1
  5. package/dist/app/controllers/useEditorFindReplace.d.ts +2 -1
  6. package/dist/app/controllers/useEditorHistoryActions.d.ts +2 -1
  7. package/dist/app/controllers/useEditorImageOperations.d.ts +2 -1
  8. package/dist/app/controllers/useEditorTableOperations.d.ts +2 -1
  9. package/dist/app/controllers/useEditorTextDrag.d.ts +2 -1
  10. package/dist/app/controllers/useEditorTextInput.d.ts +2 -1
  11. package/dist/assets/{importDocxWorker-8fivvDCX.js → importDocxWorker-C94l6-O5.js} +1 -1
  12. package/dist/core/endnotes.d.ts +0 -5
  13. package/dist/core/footnotes.d.ts +0 -5
  14. package/dist/core/noteTraversal.d.ts +77 -0
  15. package/dist/core/transactionMergeKeys.d.ts +35 -0
  16. package/dist/{index-CF99ClZS.js → index-CHcJlpsx.js} +160 -245
  17. package/dist/oasis-editor.js +1 -1
  18. package/dist/oasis-editor.umd.cjs +4 -4
  19. package/dist/ui/app/createEditorChrome.d.ts +2 -1
  20. package/dist/ui/app/createEditorEssentialsPlugin.d.ts +2 -1
  21. package/dist/ui/app/createEditorLayoutOptionsController.d.ts +2 -1
  22. package/dist/ui/app/createEditorTableContextMenuActions.d.ts +2 -1
  23. package/dist/ui/app/useEditorContextMenuClipboard.d.ts +2 -1
  24. package/dist/ui/app/useFontDialogBridge.d.ts +2 -1
  25. package/dist/ui/app/useParagraphDialogBridge.d.ts +2 -1
  26. package/dist/ui/app/useTablePropertiesDialogBridge.d.ts +2 -1
  27. package/dist/ui/editorHistory.d.ts +3 -2
  28. package/package.json +1 -1
@@ -1,10 +1,5 @@
1
1
  import { EditorBlockNode, EditorDocument, EditorEndnote, EditorEndnotes, EditorParagraphNode, EditorTextRun } from './model.js';
2
2
 
3
- /**
4
- * Iterate every paragraph in document order (endnote bodies excluded), yielding
5
- * each endnote reference run with its owning paragraph. Order matches reading
6
- * order, which is what numbering depends on.
7
- */
8
3
  export declare function iterateEndnoteReferenceRuns(document: EditorDocument): Generator<{
9
4
  paragraph: EditorParagraphNode;
10
5
  run: EditorTextRun;
@@ -1,10 +1,5 @@
1
1
  import { EditorBlockNode, EditorDocument, EditorFootnote, EditorFootnoteNumberFormat, EditorFootnotes, EditorParagraphNode, EditorTextRun } from './model.js';
2
2
 
3
- /**
4
- * Iterate every paragraph in document order (sections + footnotes excluded),
5
- * yielding each footnote reference run along with the owning paragraph. Order
6
- * matches reading order, which is what numbering depends on.
7
- */
8
3
  export declare function iterateFootnoteReferenceRuns(document: EditorDocument): Generator<{
9
4
  paragraph: EditorParagraphNode;
10
5
  run: EditorTextRun;
@@ -0,0 +1,77 @@
1
+ import { EditorBlockNode, EditorDocument, EditorFootnoteNumberFormat, EditorParagraphNode, EditorSection, EditorTextRun } from './model.js';
2
+
3
+ /** Discriminant of a note reference run. */
4
+ export type NoteReferenceRunKind = "footnoteReference" | "endnoteReference";
5
+ /** Neutral view of a note reference run's data (id + optional custom mark). */
6
+ export interface NoteRef {
7
+ id: string;
8
+ customMark?: string;
9
+ }
10
+ /** Minimal shape of a note body shared by footnotes and endnotes. */
11
+ interface NoteBody {
12
+ blocks: EditorBlockNode[];
13
+ }
14
+ /** Minimal shape of a note collection (footnotes/endnotes registry). */
15
+ interface NoteCollection<TNote extends NoteBody> {
16
+ items: Record<string, TNote>;
17
+ settings?: {
18
+ numberFormat?: EditorFootnoteNumberFormat;
19
+ startAt?: number;
20
+ };
21
+ }
22
+ /**
23
+ * Describes one note family so the shared algorithm can operate on either.
24
+ */
25
+ export interface NoteTraversal {
26
+ /** Reference run discriminant for this family. */
27
+ runKind: NoteReferenceRunKind;
28
+ /** Read neutral reference data from a run, or undefined if not this kind. */
29
+ getRef(run: EditorTextRun): NoteRef | undefined;
30
+ /** Map a one-based index + format to display marker text. */
31
+ formatMarker(oneBasedIndex: number, format: EditorFootnoteNumberFormat): string;
32
+ }
33
+ /**
34
+ * Iterate every paragraph in document order (note bodies excluded), yielding
35
+ * each reference run of `runKind` with its owning paragraph. Order matches
36
+ * reading order, which is what numbering depends on.
37
+ */
38
+ export declare function iterateNoteReferenceRuns(document: EditorDocument, runKind: NoteReferenceRunKind): Generator<{
39
+ paragraph: EditorParagraphNode;
40
+ run: EditorTextRun;
41
+ }, void, void>;
42
+ export declare function collectNoteReferences(document: EditorDocument, runKind: NoteReferenceRunKind): Array<{
43
+ paragraph: EditorParagraphNode;
44
+ run: EditorTextRun;
45
+ }>;
46
+ /** Find the note body that contains the given paragraph id (neutral id). */
47
+ export declare function findNoteBodyByParagraphId<TNote extends NoteBody>(items: Record<string, TNote> | undefined, paragraphId: string): {
48
+ id: string;
49
+ body: TNote;
50
+ } | null;
51
+ /** Find the first reference run for a given note id. */
52
+ export declare function findNoteReference(document: EditorDocument, traversal: NoteTraversal, noteId: string): {
53
+ paragraph: EditorParagraphNode;
54
+ run: EditorTextRun;
55
+ } | null;
56
+ /** Neutral per-reference info (id + custom mark + computed reading-order index). */
57
+ export interface NoteReferenceInfo {
58
+ id: string;
59
+ customMark?: string;
60
+ index: number;
61
+ }
62
+ export declare function listReferencedNotes(document: EditorDocument, traversal: NoteTraversal): NoteReferenceInfo[];
63
+ /** Result of {@link computeNoteRenumber}: rewritten sections + pruned items. */
64
+ export interface NoteRenumberResult<TNote extends NoteBody> {
65
+ sections: EditorSection[];
66
+ sectionsChanged: boolean;
67
+ nextItems: Record<string, TNote>;
68
+ itemsChanged: boolean;
69
+ }
70
+ /**
71
+ * Compute the renumbering of a note family: assign a marker per referenced note
72
+ * in reading order, rewrite reference run text where it differs, and prune note
73
+ * bodies that are no longer referenced. Pure — the caller assembles the new
74
+ * document with the correct collection field.
75
+ */
76
+ export declare function computeNoteRenumber<TNote extends NoteBody>(document: EditorDocument, collection: NoteCollection<TNote>, traversal: NoteTraversal): NoteRenumberResult<TNote>;
77
+ export {};
@@ -0,0 +1,35 @@
1
+ export declare const MERGE_KEYS: {
2
+ readonly insertText: "insertText";
3
+ readonly insertImage: "insertImage";
4
+ readonly insertTable: "insertTable";
5
+ readonly moveImage: "moveImage";
6
+ readonly splitListItem: "splitListItem";
7
+ readonly link: "link";
8
+ readonly imageAlt: "imageAlt";
9
+ readonly imageCaption: "imageCaption";
10
+ readonly layoutWrapPolygon: "layoutWrapPolygon";
11
+ readonly specialIndent: "specialIndent";
12
+ readonly paraBorders: "paraBorders";
13
+ readonly findReplace: "findReplace";
14
+ readonly findReplaceAll: "findReplaceAll";
15
+ readonly tableProperties: "tableProperties";
16
+ readonly paragraphDialog: "paragraph-dialog";
17
+ readonly fontDialog: "font-dialog";
18
+ readonly copyTextByDrag: "copyTextByDrag";
19
+ readonly moveTextByDrag: "moveTextByDrag";
20
+ readonly collapseSelectionByClick: "collapseSelectionByClick";
21
+ readonly mergeTable: "mergeTable";
22
+ readonly splitTable: "splitTable";
23
+ readonly insertTableColumn: "insertTableColumn";
24
+ readonly deleteTableColumn: "deleteTableColumn";
25
+ readonly insertTableRow: "insertTableRow";
26
+ readonly deleteTableRow: "deleteTableRow";
27
+ readonly tableShading: "tableShading";
28
+ readonly tableBorders: "tableBorders";
29
+ readonly tableWidth: "tableWidth";
30
+ readonly tableAlign: "tableAlign";
31
+ readonly tableCellWidth: "tableCellWidth";
32
+ readonly layoutWrapPreset: "layoutWrapPreset";
33
+ readonly layoutFixedPosition: "layoutFixedPosition";
34
+ };
35
+ export type MergeKey = (typeof MERGE_KEYS)[keyof typeof MERGE_KEYS];
@@ -2483,7 +2483,7 @@ function OasisEditorAppLazy(props = {}) {
2483
2483
  onCleanup(() => {
2484
2484
  cancelled = true;
2485
2485
  });
2486
- import("./OasisEditorApp-BI74x5qK.js").then((m) => {
2486
+ import("./OasisEditorApp-D_hjBUA1.js").then((m) => {
2487
2487
  cancelled = true;
2488
2488
  setProgress(1);
2489
2489
  setTimeout(() => setApp(() => m.OasisEditorApp), 180);
@@ -14000,7 +14000,7 @@ function projectDocumentSections(context2, reservedHeightByPageIndex) {
14000
14000
  )
14001
14001
  };
14002
14002
  }
14003
- function* iterateFootnoteReferenceRuns(document2) {
14003
+ function* iterateNoteReferenceRuns(document2, runKind) {
14004
14004
  const sections = getDocumentSectionsCanonical(document2);
14005
14005
  for (const section of sections) {
14006
14006
  const zones = [
@@ -14016,7 +14016,7 @@ function* iterateFootnoteReferenceRuns(document2) {
14016
14016
  for (const block of blocks) {
14017
14017
  for (const paragraph of getBlockParagraphs(block)) {
14018
14018
  for (const run of paragraph.runs) {
14019
- if (run.kind === "footnoteReference") {
14019
+ if (run.kind === runKind) {
14020
14020
  yield { paragraph, run };
14021
14021
  }
14022
14022
  }
@@ -14025,103 +14025,56 @@ function* iterateFootnoteReferenceRuns(document2) {
14025
14025
  }
14026
14026
  }
14027
14027
  }
14028
- const LOWER_LETTERS = "abcdefghijklmnopqrstuvwxyz";
14029
- const ROMAN_NUMERALS = [
14030
- [1e3, "m"],
14031
- [900, "cm"],
14032
- [500, "d"],
14033
- [400, "cd"],
14034
- [100, "c"],
14035
- [90, "xc"],
14036
- [50, "l"],
14037
- [40, "xl"],
14038
- [10, "x"],
14039
- [9, "ix"],
14040
- [5, "v"],
14041
- [4, "iv"],
14042
- [1, "i"]
14043
- ];
14044
- function toRoman(value) {
14045
- if (value <= 0) return String(value);
14046
- let remaining = value;
14047
- let result = "";
14048
- for (const [size, glyph] of ROMAN_NUMERALS) {
14049
- while (remaining >= size) {
14050
- result += glyph;
14051
- remaining -= size;
14052
- }
14053
- }
14054
- return result;
14055
- }
14056
- function toLetters(value) {
14057
- if (value <= 0) return String(value);
14058
- let remaining = value;
14059
- let result = "";
14060
- while (remaining > 0) {
14061
- const digit = (remaining - 1) % 26;
14062
- result = LOWER_LETTERS[digit] + result;
14063
- remaining = Math.floor((remaining - 1) / 26);
14064
- }
14065
- return result;
14066
- }
14067
- const SYMBOL_MARKS = ["*", "†", "‡", "§", "¶", "#"];
14068
- function getFootnoteDisplayMarker(oneBasedIndex, format = "decimal") {
14069
- switch (format) {
14070
- case "lowerRoman":
14071
- return toRoman(oneBasedIndex);
14072
- case "upperRoman":
14073
- return toRoman(oneBasedIndex).toUpperCase();
14074
- case "lowerLetter":
14075
- return toLetters(oneBasedIndex);
14076
- case "upperLetter":
14077
- return toLetters(oneBasedIndex).toUpperCase();
14078
- case "symbol": {
14079
- const slot = (oneBasedIndex - 1) % SYMBOL_MARKS.length;
14080
- const cycles = Math.floor((oneBasedIndex - 1) / SYMBOL_MARKS.length) + 1;
14081
- return SYMBOL_MARKS[slot].repeat(cycles);
14082
- }
14083
- case "decimal":
14084
- default:
14085
- return String(oneBasedIndex);
14086
- }
14087
- }
14088
- function findFootnoteReference(document2, footnoteId) {
14028
+ function findNoteReference(document2, traversal, noteId) {
14089
14029
  var _a;
14090
- for (const entry of iterateFootnoteReferenceRuns(document2)) {
14091
- if (((_a = getRunFootnoteReference(entry.run)) == null ? void 0 : _a.footnoteId) === footnoteId) {
14030
+ for (const entry of iterateNoteReferenceRuns(document2, traversal.runKind)) {
14031
+ if (((_a = traversal.getRef(entry.run)) == null ? void 0 : _a.id) === noteId) {
14092
14032
  return entry;
14093
14033
  }
14094
14034
  }
14095
14035
  return null;
14096
14036
  }
14097
- function renumberFootnotes(document2) {
14098
- var _a, _b;
14099
- const footnotes = document2.footnotes;
14100
- if (!footnotes || Object.keys(footnotes.items).length === 0) {
14101
- return document2;
14037
+ function listReferencedNotes(document2, traversal) {
14038
+ const seen = /* @__PURE__ */ new Set();
14039
+ const result = [];
14040
+ let counter2 = 0;
14041
+ for (const { run } of iterateNoteReferenceRuns(document2, traversal.runKind)) {
14042
+ const ref = traversal.getRef(run);
14043
+ if (!ref) continue;
14044
+ if (seen.has(ref.id)) continue;
14045
+ seen.add(ref.id);
14046
+ if (!ref.customMark) {
14047
+ counter2 += 1;
14048
+ }
14049
+ result.push({
14050
+ id: ref.id,
14051
+ customMark: ref.customMark,
14052
+ index: ref.customMark ? 0 : counter2
14053
+ });
14102
14054
  }
14103
- const format = ((_a = footnotes.settings) == null ? void 0 : _a.numberFormat) ?? "decimal";
14104
- const startAt = ((_b = footnotes.settings) == null ? void 0 : _b.startAt) ?? 1;
14055
+ return result;
14056
+ }
14057
+ function computeNoteRenumber(document2, collection, traversal) {
14058
+ var _a, _b;
14059
+ const format = ((_a = collection.settings) == null ? void 0 : _a.numberFormat) ?? "decimal";
14060
+ const startAt = ((_b = collection.settings) == null ? void 0 : _b.startAt) ?? 1;
14105
14061
  const referenced = /* @__PURE__ */ new Set();
14106
- const markerByFootnoteId = /* @__PURE__ */ new Map();
14062
+ const markerById = /* @__PURE__ */ new Map();
14107
14063
  let autoCounter = startAt - 1;
14108
- for (const { run } of iterateFootnoteReferenceRuns(document2)) {
14109
- const ref = getRunFootnoteReference(run);
14064
+ for (const { run } of iterateNoteReferenceRuns(document2, traversal.runKind)) {
14065
+ const ref = traversal.getRef(run);
14110
14066
  if (!ref) continue;
14111
- referenced.add(ref.footnoteId);
14067
+ referenced.add(ref.id);
14112
14068
  if (ref.customMark) {
14113
- markerByFootnoteId.set(ref.footnoteId, ref.customMark);
14069
+ markerById.set(ref.id, ref.customMark);
14114
14070
  continue;
14115
14071
  }
14116
- if (!markerByFootnoteId.has(ref.footnoteId)) {
14072
+ if (!markerById.has(ref.id)) {
14117
14073
  autoCounter += 1;
14118
- markerByFootnoteId.set(
14119
- ref.footnoteId,
14120
- getFootnoteDisplayMarker(autoCounter, format)
14121
- );
14074
+ markerById.set(ref.id, traversal.formatMarker(autoCounter, format));
14122
14075
  }
14123
14076
  }
14124
- let mutatedSections = false;
14077
+ let sectionsChanged = false;
14125
14078
  const sections = getDocumentSectionsCanonical(document2).map((section) => {
14126
14079
  const rewriteBlocks = (blocks) => {
14127
14080
  if (!blocks) return blocks;
@@ -14129,7 +14082,11 @@ function renumberFootnotes(document2) {
14129
14082
  const nextBlocks = blocks.map((block) => {
14130
14083
  switch (block.type) {
14131
14084
  case "paragraph": {
14132
- const updated = rewriteParagraphMarkers$1(block, markerByFootnoteId);
14085
+ const updated = rewriteParagraphMarkers(
14086
+ block,
14087
+ traversal,
14088
+ markerById
14089
+ );
14133
14090
  if (updated !== block) blockChanged = true;
14134
14091
  return updated;
14135
14092
  }
@@ -14140,9 +14097,10 @@ function renumberFootnotes(document2) {
14140
14097
  const nextCells = row.cells.map((cell) => {
14141
14098
  let cellChanged = false;
14142
14099
  const nextCellBlocks = cell.blocks.map((p) => {
14143
- const updated = rewriteParagraphMarkers$1(
14100
+ const updated = rewriteParagraphMarkers(
14144
14101
  p,
14145
- markerByFootnoteId
14102
+ traversal,
14103
+ markerById
14146
14104
  );
14147
14105
  if (updated !== p) cellChanged = true;
14148
14106
  return updated;
@@ -14164,7 +14122,7 @@ function renumberFootnotes(document2) {
14164
14122
  }
14165
14123
  });
14166
14124
  if (!blockChanged) return blocks;
14167
- mutatedSections = true;
14125
+ sectionsChanged = true;
14168
14126
  return nextBlocks;
14169
14127
  };
14170
14128
  return {
@@ -14180,31 +14138,21 @@ function renumberFootnotes(document2) {
14180
14138
  });
14181
14139
  const nextItems = {};
14182
14140
  let itemsChanged = false;
14183
- for (const [id, footnote] of Object.entries(footnotes.items)) {
14141
+ for (const [id, body] of Object.entries(collection.items)) {
14184
14142
  if (referenced.has(id)) {
14185
- nextItems[id] = footnote;
14143
+ nextItems[id] = body;
14186
14144
  } else {
14187
14145
  itemsChanged = true;
14188
14146
  }
14189
14147
  }
14190
- if (!mutatedSections && !itemsChanged) {
14191
- return document2;
14192
- }
14193
- return {
14194
- ...document2,
14195
- sections: mutatedSections ? sections : document2.sections,
14196
- footnotes: {
14197
- ...footnotes,
14198
- items: itemsChanged ? nextItems : footnotes.items
14199
- }
14200
- };
14148
+ return { sections, sectionsChanged, nextItems, itemsChanged };
14201
14149
  }
14202
- function rewriteParagraphMarkers$1(paragraph, markerByFootnoteId) {
14150
+ function rewriteParagraphMarkers(paragraph, traversal, markerById) {
14203
14151
  let runChanged = false;
14204
14152
  const nextRuns = paragraph.runs.map((run) => {
14205
- const ref = getRunFootnoteReference(run);
14153
+ const ref = traversal.getRef(run);
14206
14154
  if (!ref) return run;
14207
- const desired = markerByFootnoteId.get(ref.footnoteId);
14155
+ const desired = markerById.get(ref.id);
14208
14156
  if (desired === void 0) return run;
14209
14157
  if (run.text === desired) return run;
14210
14158
  runChanged = true;
@@ -14213,167 +14161,134 @@ function rewriteParagraphMarkers$1(paragraph, markerByFootnoteId) {
14213
14161
  if (!runChanged) return paragraph;
14214
14162
  return { ...paragraph, runs: nextRuns };
14215
14163
  }
14216
- function* iterateEndnoteReferenceRuns(document2) {
14217
- const sections = getDocumentSectionsCanonical(document2);
14218
- for (const section of sections) {
14219
- const zones = [
14220
- section.header ?? [],
14221
- section.firstPageHeader ?? [],
14222
- section.evenPageHeader ?? [],
14223
- section.blocks,
14224
- section.footer ?? [],
14225
- section.firstPageFooter ?? [],
14226
- section.evenPageFooter ?? []
14227
- ];
14228
- for (const blocks of zones) {
14229
- for (const block of blocks) {
14230
- for (const paragraph of getBlockParagraphs(block)) {
14231
- for (const run of paragraph.runs) {
14232
- if (run.kind === "endnoteReference") {
14233
- yield { paragraph, run };
14234
- }
14235
- }
14236
- }
14237
- }
14164
+ function iterateFootnoteReferenceRuns(document2) {
14165
+ return iterateNoteReferenceRuns(document2, "footnoteReference");
14166
+ }
14167
+ const LOWER_LETTERS = "abcdefghijklmnopqrstuvwxyz";
14168
+ const ROMAN_NUMERALS = [
14169
+ [1e3, "m"],
14170
+ [900, "cm"],
14171
+ [500, "d"],
14172
+ [400, "cd"],
14173
+ [100, "c"],
14174
+ [90, "xc"],
14175
+ [50, "l"],
14176
+ [40, "xl"],
14177
+ [10, "x"],
14178
+ [9, "ix"],
14179
+ [5, "v"],
14180
+ [4, "iv"],
14181
+ [1, "i"]
14182
+ ];
14183
+ function toRoman(value) {
14184
+ if (value <= 0) return String(value);
14185
+ let remaining = value;
14186
+ let result = "";
14187
+ for (const [size, glyph] of ROMAN_NUMERALS) {
14188
+ while (remaining >= size) {
14189
+ result += glyph;
14190
+ remaining -= size;
14238
14191
  }
14239
14192
  }
14193
+ return result;
14240
14194
  }
14241
- function listReferencedEndnotes(document2) {
14242
- const seen = /* @__PURE__ */ new Set();
14243
- const result = [];
14244
- let counter2 = 0;
14245
- for (const { run } of iterateEndnoteReferenceRuns(document2)) {
14246
- const ref = getRunEndnoteReference(run);
14247
- if (!ref) continue;
14248
- if (seen.has(ref.endnoteId)) continue;
14249
- seen.add(ref.endnoteId);
14250
- if (!ref.customMark) {
14251
- counter2 += 1;
14252
- }
14253
- result.push({
14254
- endnoteId: ref.endnoteId,
14255
- customMark: ref.customMark,
14256
- index: ref.customMark ? 0 : counter2
14257
- });
14195
+ function toLetters(value) {
14196
+ if (value <= 0) return String(value);
14197
+ let remaining = value;
14198
+ let result = "";
14199
+ while (remaining > 0) {
14200
+ const digit = (remaining - 1) % 26;
14201
+ result = LOWER_LETTERS[digit] + result;
14202
+ remaining = Math.floor((remaining - 1) / 26);
14258
14203
  }
14259
14204
  return result;
14260
14205
  }
14261
- function renumberEndnotes(document2) {
14262
- var _a, _b;
14263
- const endnotes = document2.endnotes;
14264
- if (!endnotes || Object.keys(endnotes.items).length === 0) {
14206
+ const SYMBOL_MARKS = ["*", "†", "‡", "§", "¶", "#"];
14207
+ function getFootnoteDisplayMarker(oneBasedIndex, format = "decimal") {
14208
+ switch (format) {
14209
+ case "lowerRoman":
14210
+ return toRoman(oneBasedIndex);
14211
+ case "upperRoman":
14212
+ return toRoman(oneBasedIndex).toUpperCase();
14213
+ case "lowerLetter":
14214
+ return toLetters(oneBasedIndex);
14215
+ case "upperLetter":
14216
+ return toLetters(oneBasedIndex).toUpperCase();
14217
+ case "symbol": {
14218
+ const slot = (oneBasedIndex - 1) % SYMBOL_MARKS.length;
14219
+ const cycles = Math.floor((oneBasedIndex - 1) / SYMBOL_MARKS.length) + 1;
14220
+ return SYMBOL_MARKS[slot].repeat(cycles);
14221
+ }
14222
+ case "decimal":
14223
+ default:
14224
+ return String(oneBasedIndex);
14225
+ }
14226
+ }
14227
+ const footnoteTraversal = {
14228
+ runKind: "footnoteReference",
14229
+ getRef: (run) => {
14230
+ const ref = getRunFootnoteReference(run);
14231
+ return ref ? { id: ref.footnoteId, customMark: ref.customMark } : void 0;
14232
+ },
14233
+ formatMarker: getFootnoteDisplayMarker
14234
+ };
14235
+ function findFootnoteReference(document2, footnoteId) {
14236
+ return findNoteReference(document2, footnoteTraversal, footnoteId);
14237
+ }
14238
+ function renumberFootnotes(document2) {
14239
+ const footnotes = document2.footnotes;
14240
+ if (!footnotes || Object.keys(footnotes.items).length === 0) {
14265
14241
  return document2;
14266
14242
  }
14267
- const format = ((_a = endnotes.settings) == null ? void 0 : _a.numberFormat) ?? "decimal";
14268
- const startAt = ((_b = endnotes.settings) == null ? void 0 : _b.startAt) ?? 1;
14269
- const referenced = /* @__PURE__ */ new Set();
14270
- const markerByEndnoteId = /* @__PURE__ */ new Map();
14271
- let autoCounter = startAt - 1;
14272
- for (const { run } of iterateEndnoteReferenceRuns(document2)) {
14273
- const ref = getRunEndnoteReference(run);
14274
- if (!ref) continue;
14275
- referenced.add(ref.endnoteId);
14276
- if (ref.customMark) {
14277
- markerByEndnoteId.set(ref.endnoteId, ref.customMark);
14278
- continue;
14279
- }
14280
- if (!markerByEndnoteId.has(ref.endnoteId)) {
14281
- autoCounter += 1;
14282
- markerByEndnoteId.set(
14283
- ref.endnoteId,
14284
- getFootnoteDisplayMarker(autoCounter, format)
14285
- );
14286
- }
14243
+ const { sections, sectionsChanged, nextItems, itemsChanged } = computeNoteRenumber(document2, footnotes, footnoteTraversal);
14244
+ if (!sectionsChanged && !itemsChanged) {
14245
+ return document2;
14287
14246
  }
14288
- let mutatedSections = false;
14289
- const sections = getDocumentSectionsCanonical(document2).map((section) => {
14290
- const rewriteBlocks = (blocks) => {
14291
- if (!blocks) return blocks;
14292
- let blockChanged = false;
14293
- const nextBlocks = blocks.map((block) => {
14294
- switch (block.type) {
14295
- case "paragraph": {
14296
- const updated = rewriteParagraphMarkers(block, markerByEndnoteId);
14297
- if (updated !== block) blockChanged = true;
14298
- return updated;
14299
- }
14300
- case "table": {
14301
- let tableChanged = false;
14302
- const nextRows = block.rows.map((row) => {
14303
- let rowChanged = false;
14304
- const nextCells = row.cells.map((cell) => {
14305
- let cellChanged = false;
14306
- const nextCellBlocks = cell.blocks.map((p) => {
14307
- const updated = rewriteParagraphMarkers(p, markerByEndnoteId);
14308
- if (updated !== p) cellChanged = true;
14309
- return updated;
14310
- });
14311
- if (!cellChanged) return cell;
14312
- rowChanged = true;
14313
- return { ...cell, blocks: nextCellBlocks };
14314
- });
14315
- if (!rowChanged) return row;
14316
- tableChanged = true;
14317
- return { ...row, cells: nextCells };
14318
- });
14319
- if (!tableChanged) return block;
14320
- blockChanged = true;
14321
- return { ...block, rows: nextRows };
14322
- }
14323
- default:
14324
- return assertNever(block, "block");
14325
- }
14326
- });
14327
- if (!blockChanged) return blocks;
14328
- mutatedSections = true;
14329
- return nextBlocks;
14330
- };
14331
- return {
14332
- ...section,
14333
- blocks: rewriteBlocks(section.blocks) ?? section.blocks,
14334
- header: rewriteBlocks(section.header),
14335
- firstPageHeader: rewriteBlocks(section.firstPageHeader),
14336
- evenPageHeader: rewriteBlocks(section.evenPageHeader),
14337
- footer: rewriteBlocks(section.footer),
14338
- firstPageFooter: rewriteBlocks(section.firstPageFooter),
14339
- evenPageFooter: rewriteBlocks(section.evenPageFooter)
14340
- };
14341
- });
14342
- const nextItems = {};
14343
- let itemsChanged = false;
14344
- for (const [id, endnote] of Object.entries(endnotes.items)) {
14345
- if (referenced.has(id)) {
14346
- nextItems[id] = endnote;
14347
- } else {
14348
- itemsChanged = true;
14247
+ return {
14248
+ ...document2,
14249
+ sections: sectionsChanged ? sections : document2.sections,
14250
+ footnotes: {
14251
+ ...footnotes,
14252
+ items: itemsChanged ? nextItems : footnotes.items
14349
14253
  }
14254
+ };
14255
+ }
14256
+ const endnoteTraversal = {
14257
+ runKind: "endnoteReference",
14258
+ getRef: (run) => {
14259
+ const ref = getRunEndnoteReference(run);
14260
+ return ref ? { id: ref.endnoteId, customMark: ref.customMark } : void 0;
14261
+ },
14262
+ formatMarker: getFootnoteDisplayMarker
14263
+ };
14264
+ function iterateEndnoteReferenceRuns(document2) {
14265
+ return iterateNoteReferenceRuns(document2, "endnoteReference");
14266
+ }
14267
+ function listReferencedEndnotes(document2) {
14268
+ return listReferencedNotes(document2, endnoteTraversal).map((info) => ({
14269
+ endnoteId: info.id,
14270
+ customMark: info.customMark,
14271
+ index: info.index
14272
+ }));
14273
+ }
14274
+ function renumberEndnotes(document2) {
14275
+ const endnotes = document2.endnotes;
14276
+ if (!endnotes || Object.keys(endnotes.items).length === 0) {
14277
+ return document2;
14350
14278
  }
14351
- if (!mutatedSections && !itemsChanged) {
14279
+ const { sections, sectionsChanged, nextItems, itemsChanged } = computeNoteRenumber(document2, endnotes, endnoteTraversal);
14280
+ if (!sectionsChanged && !itemsChanged) {
14352
14281
  return document2;
14353
14282
  }
14354
14283
  return {
14355
14284
  ...document2,
14356
- sections: mutatedSections ? sections : document2.sections,
14285
+ sections: sectionsChanged ? sections : document2.sections,
14357
14286
  endnotes: {
14358
14287
  ...endnotes,
14359
14288
  items: itemsChanged ? nextItems : endnotes.items
14360
14289
  }
14361
14290
  };
14362
14291
  }
14363
- function rewriteParagraphMarkers(paragraph, markerByEndnoteId) {
14364
- let runChanged = false;
14365
- const nextRuns = paragraph.runs.map((run) => {
14366
- const ref = getRunEndnoteReference(run);
14367
- if (!ref) return run;
14368
- const desired = markerByEndnoteId.get(ref.endnoteId);
14369
- if (desired === void 0) return run;
14370
- if (run.text === desired) return run;
14371
- runChanged = true;
14372
- return { ...run, text: desired };
14373
- });
14374
- if (!runChanged) return paragraph;
14375
- return { ...paragraph, runs: nextRuns };
14376
- }
14377
14292
  const FLOW_ID_PREFIX = "endnote-flow";
14378
14293
  function makeMarkerRun(endnoteId, marker) {
14379
14294
  return {
@@ -35709,7 +35624,7 @@ function importDocxInWorker(buffer, options = {}) {
35709
35624
  const worker = new Worker(
35710
35625
  new URL(
35711
35626
  /* @vite-ignore */
35712
- "" + new URL("assets/importDocxWorker-8fivvDCX.js", import.meta.url).href,
35627
+ "" + new URL("assets/importDocxWorker-C94l6-O5.js", import.meta.url).href,
35713
35628
  import.meta.url
35714
35629
  ),
35715
35630
  {
@@ -1,4 +1,4 @@
1
- import { O, c2, c3, c4, c5, c6, a8, c7, Q, bN, c8, c9, ca, N, cb, bL, cc, cd, ce, cf, cg, bZ, ch, ci, cj, ck, cl, cm, cn, co, cp, cq, cr, ad, cs, bY, ct, c4 as c42, c9 as c92, cb as cb2, ck as ck2, cm as cm2, cr as cr2, cu, bP, bK, cv, cw, cx, bM, cy, cz, bO } from "./index-CF99ClZS.js";
1
+ import { O, c2, c3, c4, c5, c6, a8, c7, Q, bN, c8, c9, ca, N, cb, bL, cc, cd, ce, cf, cg, bZ, ch, ci, cj, ck, cl, cm, cn, co, cp, cq, cr, ad, cs, bY, ct, c4 as c42, c9 as c92, cb as cb2, ck as ck2, cm as cm2, cr as cr2, cu, bP, bK, cv, cw, cx, bM, cy, cz, bO } from "./index-CHcJlpsx.js";
2
2
  export {
3
3
  O as BalloonShell,
4
4
  c2 as Button,