@extend-ai/react-docx 0.9.2 → 0.11.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/README.md CHANGED
@@ -4,8 +4,8 @@ React-first DOCX viewing and editing components for rendering `.docx` files in a
4
4
 
5
5
  `@extend-ai/react-docx` gives you:
6
6
 
7
- - A simple read-only viewer for rendering `.docx` files or prebuilt document models
8
- - A richer editor/controller API for building custom DOCX editing UIs
7
+ - A shared viewer for read-only previews and editable documents
8
+ - A controller API for import/export and custom DOCX editing UIs
9
9
  - Pagination, page layout, theme, tracked-change, form-field, and thumbnail hooks
10
10
  - Configurable page surface and inter-page background colors
11
11
  - A dark read-only night-reader mode that inverts document content while preserving image hues
@@ -51,13 +51,10 @@ You can also call `initWasm()` (optionally with a source) ahead of time to warm
51
51
 
52
52
  ## Main Entry Points
53
53
 
54
- The package exports two useful levels of API:
55
-
56
- 1. `ReactDocxViewer`
57
- A lightweight read-only viewer when you just want to render a document.
58
-
59
- 2. `useDocxEditor` + `DocxEditorViewer`
60
- The full controller/view split for editable or highly customized experiences.
54
+ Use `useDocxEditor` + `DocxEditorViewer` for both read-only and editable
55
+ experiences. The hook manages document state, import/export, and editing
56
+ commands; the component renders the document. Set `mode="read-only"` for
57
+ view-only use or `mode="edit"` for editing.
61
58
 
62
59
  It also re-exports lower-level document/model/layout/serializer APIs, so you can work below the UI layer when needed.
63
60
 
@@ -65,36 +62,41 @@ It also re-exports lower-level document/model/layout/serializer APIs, so you can
65
62
 
66
63
  ### Read-only viewer
67
64
 
68
- Use `ReactDocxViewer` when you want the smallest integration surface.
65
+ Starting in v0.10.0, the intended pattern for read-only viewing is
66
+ `useDocxEditor` with `DocxEditorViewer mode="read-only"`. Use the same component
67
+ with `mode="edit"` when editing is needed.
69
68
 
70
69
  ```tsx
71
- import * as React from "react";
72
- import { ReactDocxViewer } from "@extend-ai/react-docx";
70
+ import { DocxEditorViewer, useDocxEditor } from "@extend-ai/react-docx";
73
71
 
74
72
  export function ReadOnlyDocxExample() {
75
- const [file, setFile] = React.useState<ArrayBuffer | undefined>();
73
+ const editor = useDocxEditor();
76
74
 
77
75
  return (
78
76
  <div style={{ display: "grid", gap: 12 }}>
79
77
  <input
80
78
  type="file"
81
79
  accept=".docx"
82
- onChange={async (event) => {
83
- const nextFile = event.target.files?.[0];
84
- setFile(nextFile ? await nextFile.arrayBuffer() : undefined);
80
+ onChange={(event) => {
81
+ const file = event.target.files?.[0];
82
+ if (file) {
83
+ void editor.importDocxFile(file);
84
+ }
85
85
  }}
86
86
  />
87
87
 
88
- <ReactDocxViewer
89
- file={file}
90
- emptyState="Choose a DOCX file to preview."
91
- />
88
+ <DocxEditorViewer editor={editor} mode="read-only" />
92
89
  </div>
93
90
  );
94
91
  }
95
92
  ```
96
93
 
97
- You can also pass a `model` instead of a raw `.docx` file if you already have a normalized document model.
94
+ For an already parsed document, initialize the controller with
95
+ `useDocxEditor({ document })`. For a prebuilt document model, use
96
+ `useDocxEditor({ starterModel: model })`. To start from a raw buffer, call
97
+ `parseDocxForViewer(buffer)` and pass the resulting `document` to the hook.
98
+ These options set the initial document; use `editor.importDocxFile(file)` to
99
+ load a different document into an existing controller.
98
100
 
99
101
  ### Full editor/viewer
100
102
 
@@ -192,14 +194,16 @@ function FullEditor() {
192
194
 
193
195
  ## Responsive zoom
194
196
 
195
- Both viewer components accept numeric percentages and responsive zoom modes.
197
+ `DocxEditorViewer` accepts numeric percentages and responsive zoom modes.
196
198
  Responsive modes remain selected while the viewer recalculates their resolved
197
199
  percentage as its viewport or page layout changes.
198
200
 
199
201
  ```tsx
200
- const Viewer = ReactDocxViewer;
201
-
202
- <Viewer defaultZoom="fit-width" />
202
+ <DocxEditorViewer
203
+ editor={editor}
204
+ mode="read-only"
205
+ defaultZoom="fit-width"
206
+ />
203
207
  ```
204
208
 
205
209
  Use `zoom` with `onZoomChange` for a controlled viewer, or `defaultZoom` for an
@@ -217,6 +221,39 @@ and embedded-font loading. Use `loadEmbeddedFonts: "defer"` to load fonts later
217
221
  through `document.loadEmbeddedFonts()`. The renderer also accepts an existing
218
222
  `DocModel` directly when the OOXML package is not needed.
219
223
 
224
+ ## Caller fonts
225
+
226
+ Fonts embedded in a DOCX load automatically by default. Caller-provided fonts
227
+ must be available in `document.fonts` before layout uses them. When adding or
228
+ removing fonts after parsing or mounting, call `refreshDocxFontMetrics()` after
229
+ the change to refresh cached text measurements and mounted viewers.
230
+
231
+ ```tsx
232
+ import { refreshDocxFontMetrics } from "@extend-ai/react-docx";
233
+
234
+ async function attachViewerFont(face: FontFace) {
235
+ await face.load();
236
+ document.fonts.add(face);
237
+ refreshDocxFontMetrics();
238
+
239
+ return () => {
240
+ document.fonts.delete(face);
241
+ refreshDocxFontMetrics();
242
+ };
243
+ }
244
+ ```
245
+
246
+ Provide matching font data and descriptors for each required weight and style.
247
+ If a reference renderer uses different vertical metrics for the same font,
248
+ the caller can supply verified `ascentOverride`, `descentOverride`, and
249
+ `lineGapOverride` descriptors on the `FontFace`. These affect browser layout
250
+ as well as viewer measurements. Bind such a profile to the actual font bytes
251
+ and reference environment; a family name or document charset alone does not
252
+ establish the correct metrics.
253
+ The caller owns loading and cleanup. Load fonts before creating a standalone
254
+ `createDocxThumbnailRenderer`; after changing fonts, dispose and recreate that
255
+ renderer to refresh its captured pagination.
256
+
220
257
  ## Thumbnail Hook
221
258
 
222
259
  The library can expose page thumbnails so you can build your own page strip, mini-map, or navigation UI. Thumbnail painting can render from the live page surface when it is mounted, or from an offscreen one-page surface when viewer virtualization has unmounted that page.
@@ -2,8 +2,10 @@ import {
2
2
  mapsToWasmPackage,
3
3
  wasmBuildDocModelFromBytes,
4
4
  wasmBuildDocModelFromPackage,
5
+ wasmExtractDocumentBlocks,
6
+ wasmInspectDocumentSource,
5
7
  wasmPackageToMaps
6
- } from "./chunk-AKDFE4ZH.js";
8
+ } from "./chunk-TPYS6CSH.js";
7
9
 
8
10
  // ../doc-model/src/normalize.ts
9
11
  function normalizeUint8Array(value) {
@@ -21,12 +23,13 @@ function normalizeParagraphChild(child) {
21
23
  }
22
24
  const image = child;
23
25
  const data = normalizeUint8Array(image.data);
24
- if (data === image.data) {
26
+ if (data === image.data && !image.contentNodes) {
25
27
  return child;
26
28
  }
27
29
  return {
28
30
  ...image,
29
- data
31
+ data,
32
+ contentNodes: image.contentNodes?.map(normalizeDocNode)
30
33
  };
31
34
  }
32
35
  function normalizeTableCellContent(node) {
@@ -85,6 +88,10 @@ function normalizeDocModel(model) {
85
88
  ...note,
86
89
  nodes: note.nodes?.map(normalizeDocNode)
87
90
  })),
91
+ comments: model.metadata.comments?.map((comment) => ({
92
+ ...comment,
93
+ nodes: comment.nodes?.map(normalizeDocNode)
94
+ })),
88
95
  endnotes: model.metadata.endnotes?.map((note) => ({
89
96
  ...note,
90
97
  nodes: note.nodes?.map(normalizeDocNode)
@@ -93,6 +100,56 @@ function normalizeDocModel(model) {
93
100
  };
94
101
  }
95
102
 
103
+ // ../doc-model/src/blocks.ts
104
+ var DOCUMENT_BLOCK_TYPES = [
105
+ "text",
106
+ "heading",
107
+ "section_heading",
108
+ "figure",
109
+ "table",
110
+ "table_head",
111
+ "table_cell",
112
+ "key_value",
113
+ "page_number",
114
+ "barcode",
115
+ "formula",
116
+ "header",
117
+ "footer",
118
+ "watermark",
119
+ "legend"
120
+ ];
121
+ async function extractDocumentBlocks(model, options = {}) {
122
+ return await wasmExtractDocumentBlocks(model, options);
123
+ }
124
+ function flattenDocumentBlocks(blocks) {
125
+ return blocks.flatMap((block) => [
126
+ block,
127
+ ...flattenDocumentBlocks(block.children)
128
+ ]);
129
+ }
130
+ async function inspectDocumentSource(bytes) {
131
+ return await wasmInspectDocumentSource(bytes);
132
+ }
133
+
134
+ // ../doc-model/src/table-grid.ts
135
+ function tableGridColumnBound(table) {
136
+ if (table.style?.columnWidthsTwips !== void 0) return table.style.columnWidthsTwips.length;
137
+ return Math.max(0, ...table.rows.map((row) => row.cells.reduce((total, cell) => {
138
+ const span = cell.style?.gridSpan;
139
+ return total + (Number.isFinite(span) && span > 0 ? Math.max(1, Math.floor(span)) : 1);
140
+ }, 0)));
141
+ }
142
+ function resolveTableGridSkipCount(count, gridColumnCount) {
143
+ const value = Number.isFinite(count) && count >= 0 ? Math.floor(count) : 0;
144
+ return Number.isFinite(gridColumnCount) && gridColumnCount >= value ? value : 0;
145
+ }
146
+ function tableRowGridSkipCount(table, row, edge) {
147
+ return resolveTableGridSkipCount(
148
+ edge === "before" ? row.style?.gridBefore : row.style?.gridAfter,
149
+ tableGridColumnBound(table)
150
+ );
151
+ }
152
+
96
153
  // ../doc-model/src/block-id.ts
97
154
  var nextBlockIdValue = 1;
98
155
  function allocateBlockId() {
@@ -105,6 +162,11 @@ function ensureNodeBlockIds(node) {
105
162
  node.blockId = allocateBlockId();
106
163
  }
107
164
  if (node.type !== "table") {
165
+ node.children.forEach((child, index) => {
166
+ if (child.type !== "image") return;
167
+ child.blockId ??= `${node.blockId}/child/${index}`;
168
+ child.contentNodes?.forEach(ensureNodeBlockIds);
169
+ });
108
170
  return;
109
171
  }
110
172
  for (const row of node.rows) {
@@ -137,6 +199,9 @@ function ensureDocModelBlockIds(model) {
137
199
  for (const note of model.metadata.endnotes ?? []) {
138
200
  note.nodes?.forEach(ensureNodeBlockIds);
139
201
  }
202
+ for (const comment of model.metadata.comments ?? []) {
203
+ comment.nodes?.forEach(ensureNodeBlockIds);
204
+ }
140
205
  return model;
141
206
  }
142
207
  function collectNodeBlockIds(node, seen, duplicates) {
@@ -235,6 +300,7 @@ function cloneParagraphStyle(style) {
235
300
  spacing: cloneParagraphSpacing(style.spacing),
236
301
  indent: cloneParagraphIndent(style.indent),
237
302
  borders: cloneParagraphBorderSet(style.borders),
303
+ tabStops: style.tabStops?.map((stop) => ({ ...stop })),
238
304
  dropCap: style.dropCap ? {
239
305
  ...style.dropCap
240
306
  } : void 0
@@ -246,6 +312,13 @@ function cloneTextStyle(style) {
246
312
  runBorder: style.runBorder ? { ...style.runBorder } : void 0
247
313
  } : void 0;
248
314
  }
315
+ function cloneParagraphMarkFormatting(formatting) {
316
+ return formatting ? {
317
+ defaultStyle: cloneTextStyle(formatting.defaultStyle),
318
+ characterStyle: cloneTextStyle(formatting.characterStyle),
319
+ directStyle: cloneTextStyle(formatting.directStyle)
320
+ } : void 0;
321
+ }
249
322
  function cloneParagraphNode(paragraph) {
250
323
  return cloneParagraph(paragraph);
251
324
  }
@@ -257,6 +330,12 @@ function cloneParagraph(paragraph) {
257
330
  type: "paragraph",
258
331
  blockId: paragraph.blockId,
259
332
  style: cloneParagraphStyle(paragraph.style),
333
+ paragraphMarkStyle: cloneTextStyle(paragraph.paragraphMarkStyle),
334
+ sourceParagraphMarkStyle: cloneTextStyle(paragraph.sourceParagraphMarkStyle),
335
+ sourceParagraphMarkFormatting: cloneParagraphMarkFormatting(
336
+ paragraph.sourceParagraphMarkFormatting
337
+ ),
338
+ sourceParagraphMarkPropertiesXml: paragraph.sourceParagraphMarkPropertiesXml,
260
339
  paragraphMarkDeleted: paragraph.paragraphMarkDeleted,
261
340
  sourceXml: paragraph.sourceXml,
262
341
  sourceTextPatch: paragraph.sourceTextPatch ? {
@@ -326,6 +405,10 @@ function cloneParagraph(paragraph) {
326
405
  }
327
406
  return {
328
407
  type: "image",
408
+ blockId: child.blockId,
409
+ semanticKind: child.semanticKind,
410
+ mathMl: child.mathMl,
411
+ contentNodes: child.contentNodes?.map(cloneDocNode),
329
412
  src: child.src,
330
413
  alt: child.alt,
331
414
  widthPx: child.widthPx,
@@ -397,6 +480,28 @@ function cloneTableFloatingStyle(floating) {
397
480
  verticalAlign: floating.verticalAlign
398
481
  };
399
482
  }
483
+ function cloneTablePreferredWidth(width) {
484
+ return width ? { ...width } : void 0;
485
+ }
486
+ function cloneTableWidthSource(source) {
487
+ return source ? {
488
+ ...source,
489
+ preferredWidth: cloneTablePreferredWidth(source.preferredWidth),
490
+ inheritedPreferredWidth: cloneTablePreferredWidth(source.inheritedPreferredWidth)
491
+ } : void 0;
492
+ }
493
+ function cloneTableRowStyle(style) {
494
+ return style ? {
495
+ ...style,
496
+ widthBefore: cloneTablePreferredWidth(style.widthBefore),
497
+ widthAfter: cloneTablePreferredWidth(style.widthAfter),
498
+ sourceRowGeometry: style.sourceRowGeometry ? {
499
+ ...style.sourceRowGeometry,
500
+ widthBefore: cloneTablePreferredWidth(style.sourceRowGeometry.widthBefore),
501
+ widthAfter: cloneTablePreferredWidth(style.sourceRowGeometry.widthAfter)
502
+ } : void 0
503
+ } : void 0;
504
+ }
400
505
  function cloneTable(table) {
401
506
  return {
402
507
  type: "table",
@@ -407,7 +512,17 @@ function cloneTable(table) {
407
512
  paragraph: cloneParagraph(patch.paragraph)
408
513
  })),
409
514
  style: table.style ? {
515
+ styleId: table.style.styleId,
516
+ sourceStyleId: table.style.sourceStyleId,
410
517
  widthTwips: table.style.widthTwips,
518
+ preferredWidth: cloneTablePreferredWidth(table.style.preferredWidth),
519
+ sourceWidth: cloneTableWidthSource(table.style.sourceWidth),
520
+ alignment: table.style.alignment,
521
+ sourceAlignment: table.style.sourceAlignment,
522
+ sourceInheritedAlignment: table.style.sourceInheritedAlignment,
523
+ bidiVisual: table.style.bidiVisual,
524
+ sourceBidiVisual: table.style.sourceBidiVisual,
525
+ sourceInheritedBidiVisual: table.style.sourceInheritedBidiVisual,
411
526
  indentTwips: table.style.indentTwips,
412
527
  layout: table.style.layout,
413
528
  cellSpacingTwips: table.style.cellSpacingTwips,
@@ -418,11 +533,13 @@ function cloneTable(table) {
418
533
  } : void 0,
419
534
  rows: table.rows.map((row) => ({
420
535
  type: "table-row",
421
- style: row.style ? { ...row.style } : void 0,
536
+ style: cloneTableRowStyle(row.style),
422
537
  cells: row.cells.map((cell) => ({
423
538
  type: "table-cell",
424
539
  style: cell.style ? {
425
540
  ...cell.style,
541
+ preferredWidth: cloneTablePreferredWidth(cell.style.preferredWidth),
542
+ sourceWidth: cloneTableWidthSource(cell.style.sourceWidth),
426
543
  marginTwips: cloneTableBoxSpacing(cell.style.marginTwips),
427
544
  borders: cloneTableBorderSet(cell.style.borders)
428
545
  } : void 0,
@@ -463,6 +580,8 @@ function cloneDocModel(model) {
463
580
  return {
464
581
  nodes: model.nodes.map(cloneDocNode),
465
582
  metadata: {
583
+ documentId: model.metadata.documentId,
584
+ sourcePartNames: model.metadata.sourcePartNames ? { ...model.metadata.sourcePartNames } : void 0,
466
585
  sourceParts: model.metadata.sourceParts,
467
586
  warnings: [...model.metadata.warnings],
468
587
  documentPageCount: model.metadata.documentPageCount,
@@ -502,6 +621,9 @@ function cloneDocModel(model) {
502
621
  borders: cloneParagraphBorderSet(style.borders)
503
622
  })),
504
623
  defaultParagraphStyleId: model.metadata.defaultParagraphStyleId,
624
+ defaultTabStopTwips: model.metadata.defaultTabStopTwips,
625
+ documentSettingsImported: model.metadata.documentSettingsImported,
626
+ lineSpacingCompatibilityImported: model.metadata.lineSpacingCompatibilityImported,
505
627
  numberingDefinitions: cloneNumberingDefinitions(
506
628
  model.metadata.numberingDefinitions
507
629
  ),
@@ -514,7 +636,7 @@ function cloneDocModel(model) {
514
636
  ...note,
515
637
  nodes: note.nodes?.map(cloneDocNode)
516
638
  })),
517
- comments: model.metadata.comments?.map((comment) => ({ ...comment }))
639
+ comments: model.metadata.comments?.map((comment) => ({ ...comment, nodes: comment.nodes?.map(cloneDocNode) }))
518
640
  }
519
641
  };
520
642
  }
@@ -578,9 +700,17 @@ async function buildDocModelFromBytes(bytes) {
578
700
 
579
701
  export {
580
702
  normalizeDocModel,
703
+ DOCUMENT_BLOCK_TYPES,
704
+ extractDocumentBlocks,
705
+ flattenDocumentBlocks,
706
+ inspectDocumentSource,
707
+ tableGridColumnBound,
708
+ resolveTableGridSkipCount,
709
+ tableRowGridSkipCount,
581
710
  allocateBlockId,
582
711
  ensureDocModelBlockIds,
583
712
  collectDuplicateDocModelBlockIds,
713
+ cloneParagraphMarkFormatting,
584
714
  cloneParagraphNode,
585
715
  cloneTableNode,
586
716
  cloneDocModel,
@@ -588,4 +718,4 @@ export {
588
718
  buildDocModel,
589
719
  buildDocModelFromBytes
590
720
  };
591
- //# sourceMappingURL=chunk-GRQPIBJJ.js.map
721
+ //# sourceMappingURL=chunk-PCMLHNDX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../doc-model/src/normalize.ts","../../doc-model/src/blocks.ts","../../doc-model/src/table-grid.ts","../../doc-model/src/block-id.ts","../../doc-model/src/clone.ts","../../doc-model/src/freeze.ts","../../doc-model/src/index.ts"],"sourcesContent":["import type {\n DocModel,\n DocNode,\n ImageRunNode,\n ParagraphChildNode,\n TableCellContentNode\n} from \"./types\";\n\nfunction normalizeUint8Array(value: unknown): Uint8Array | undefined {\n if (value instanceof Uint8Array) {\n return value;\n }\n if (Array.isArray(value)) {\n return Uint8Array.from(value as number[]);\n }\n return undefined;\n}\n\nfunction normalizeParagraphChild(child: ParagraphChildNode): ParagraphChildNode {\n if (child.type !== \"image\") {\n return child;\n }\n\n const image = child as ImageRunNode;\n const data = normalizeUint8Array(image.data);\n if (data === image.data && !image.contentNodes) {\n return child;\n }\n\n return {\n ...image,\n data,\n contentNodes: image.contentNodes?.map(normalizeDocNode)\n };\n}\n\nfunction normalizeTableCellContent(node: TableCellContentNode): TableCellContentNode {\n if (node.type === \"table\") {\n return normalizeDocNode(node) as TableCellContentNode;\n }\n\n return {\n ...node,\n children: node.children.map(normalizeParagraphChild)\n };\n}\n\nfunction normalizeDocNode(node: DocNode): DocNode {\n if (node.type === \"paragraph\") {\n return {\n ...node,\n children: node.children.map(normalizeParagraphChild)\n };\n }\n\n return {\n ...node,\n rows: node.rows.map((row) => ({\n ...row,\n cells: row.cells.map((cell) => ({\n ...cell,\n nodes: cell.nodes.map(normalizeTableCellContent)\n }))\n }))\n };\n}\n\nexport function normalizeDocModel(model: DocModel): DocModel {\n return {\n ...model,\n nodes: model.nodes.map(normalizeDocNode),\n metadata: {\n ...model.metadata,\n headerSections: model.metadata.headerSections.map((section) => ({\n ...section,\n nodes: section.nodes.map(normalizeDocNode)\n })),\n footerSections: model.metadata.footerSections.map((section) => ({\n ...section,\n nodes: section.nodes.map(normalizeDocNode)\n })),\n sections: model.metadata.sections?.map((section) => ({\n ...section,\n headerSections: section.headerSections.map((header) => ({\n ...header,\n nodes: header.nodes.map(normalizeDocNode)\n })),\n footerSections: section.footerSections.map((footer) => ({\n ...footer,\n nodes: footer.nodes.map(normalizeDocNode)\n }))\n })),\n footnotes: model.metadata.footnotes?.map((note) => ({\n ...note,\n nodes: note.nodes?.map(normalizeDocNode)\n })),\n comments: model.metadata.comments?.map((comment) => ({\n ...comment,\n nodes: comment.nodes?.map(normalizeDocNode)\n })),\n endnotes: model.metadata.endnotes?.map((note) => ({\n ...note,\n nodes: note.nodes?.map(normalizeDocNode)\n }))\n }\n };\n}\n","import {\n wasmExtractDocumentBlocks,\n wasmInspectDocumentSource,\n} from \"@extend-ai/react-docx-wasm\";\nimport type { DocModel } from \"./types\";\n\nexport const DOCUMENT_BLOCK_TYPES = [\n \"text\",\n \"heading\",\n \"section_heading\",\n \"figure\",\n \"table\",\n \"table_head\",\n \"table_cell\",\n \"key_value\",\n \"page_number\",\n \"barcode\",\n \"formula\",\n \"header\",\n \"footer\",\n \"watermark\",\n \"legend\",\n] as const;\n\nexport type DocumentBlockType = (typeof DOCUMENT_BLOCK_TYPES)[number];\n\nexport interface DocxSourceRef {\n documentId: string;\n nodeId: string;\n partName: string;\n story: string;\n start?: number;\n end?: number;\n offsetEncoding: \"utf-16\";\n}\n\nexport interface ExtractDocumentBlocksOptions {\n includeWords?: boolean;\n}\n\nexport interface DocumentWord {\n object: \"word\";\n id: string;\n blockId: string;\n content: string;\n sourceRefs: DocxSourceRef[];\n}\n\nexport interface DocumentBlock {\n object: \"block\";\n id: string;\n type: DocumentBlockType;\n content: string;\n details: Record<string, unknown>;\n sourceRefs: DocxSourceRef[];\n parentBlockId?: string;\n children: DocumentBlock[];\n words?: DocumentWord[];\n}\n\nexport interface StructuredDocument {\n schemaVersion: 1;\n parserVersion: string;\n documentId: string;\n blocks: DocumentBlock[];\n warnings: string[];\n geometryStatus: \"requires_layout\";\n}\n\nexport async function extractDocumentBlocks(\n model: DocModel,\n options: ExtractDocumentBlocksOptions = {}\n): Promise<StructuredDocument> {\n return (await wasmExtractDocumentBlocks(model, options)) as StructuredDocument;\n}\n\nexport function flattenDocumentBlocks(\n blocks: readonly DocumentBlock[]\n): DocumentBlock[] {\n return blocks.flatMap((block) => [\n block,\n ...flattenDocumentBlocks(block.children),\n ]);\n}\n\nexport interface SourceElement {\n id: string;\n kind: \"document\" | \"element\" | \"text\" | \"comment\" | \"processing_instruction\";\n namespace?: string;\n name?: string;\n text?: string;\n byteStart: number;\n byteEnd: number;\n attributes: Array<{ namespace: string | null; name: string; value: string }>;\n children: SourceElement[];\n}\n\nexport interface DocumentSourceGraph {\n schemaVersion: 1;\n documentId: string;\n parts: Array<{\n name: string;\n byteLength: number;\n root: SourceElement | null;\n error: string | null;\n }>;\n assets: Array<{ name: string; byteLength: number; root: null; error: null }>;\n warnings: string[];\n preservedFeatures: Array<{\n partName: string;\n feature: string;\n occurrences: number;\n support: \"preserved_only\" | \"approximate_rendering\";\n }>;\n}\n\nexport async function inspectDocumentSource(\n bytes: ArrayBuffer | Uint8Array\n): Promise<DocumentSourceGraph> {\n return (await wasmInspectDocumentSource(bytes)) as DocumentSourceGraph;\n}\n","import type { TableNode, TableRowNode } from \"./types\";\n\n/** The parent grid bounds skipped-column counts without changing their source values. */\nexport function tableGridColumnBound(table: Pick<TableNode, \"style\" | \"rows\">): number {\n if (table.style?.columnWidthsTwips !== undefined) return table.style.columnWidthsTwips.length;\n return Math.max(0, ...table.rows.map((row) => row.cells.reduce((total, cell) => {\n const span = cell.style?.gridSpan;\n return total + (Number.isFinite(span) && (span as number) > 0 ? Math.max(1, Math.floor(span as number)) : 1);\n }, 0)));\n}\n\n/** Ignore skipped-grid counts that exceed the parent grid. */\nexport function resolveTableGridSkipCount(count: number | undefined, gridColumnCount: number): number {\n const value = Number.isFinite(count) && (count as number) >= 0 ? Math.floor(count as number) : 0;\n return Number.isFinite(gridColumnCount) && gridColumnCount >= value ? value : 0;\n}\n\nexport function tableRowGridSkipCount(\n table: Pick<TableNode, \"style\" | \"rows\">,\n row: TableRowNode,\n edge: \"before\" | \"after\"\n): number {\n return resolveTableGridSkipCount(\n edge === \"before\" ? row.style?.gridBefore : row.style?.gridAfter,\n tableGridColumnBound(table)\n );\n}\n","import type { DocModel, DocNode, TableCellContentNode } from \"./types\";\n\nlet nextBlockIdValue = 1;\n\n/** Returns a fresh block id, unique for the lifetime of this module instance. */\nexport function allocateBlockId(): string {\n const value = nextBlockIdValue;\n nextBlockIdValue += 1;\n return `b${value}`;\n}\n\nfunction ensureNodeBlockIds(node: DocNode | TableCellContentNode): void {\n if (!node.blockId) {\n node.blockId = allocateBlockId();\n }\n\n if (node.type !== \"table\") {\n node.children.forEach((child, index) => {\n if (child.type !== \"image\") return;\n child.blockId ??= `${node.blockId}/child/${index}`;\n child.contentNodes?.forEach(ensureNodeBlockIds);\n });\n return;\n }\n\n for (const row of node.rows) {\n for (const cell of row.cells) {\n for (const child of cell.nodes) {\n ensureNodeBlockIds(child);\n }\n }\n }\n}\n\n/**\n * Assigns a fresh block id to every paragraph/table node (body, headers,\n * footers, footnotes, endnotes, nested table content) that does not already\n * have one. Mutates the model in place and returns it.\n */\nexport function ensureDocModelBlockIds(model: DocModel): DocModel {\n model.nodes.forEach(ensureNodeBlockIds);\n\n for (const section of model.metadata.headerSections ?? []) {\n section.nodes.forEach(ensureNodeBlockIds);\n }\n for (const section of model.metadata.footerSections ?? []) {\n section.nodes.forEach(ensureNodeBlockIds);\n }\n for (const section of model.metadata.sections ?? []) {\n for (const headerSection of section.headerSections ?? []) {\n headerSection.nodes.forEach(ensureNodeBlockIds);\n }\n for (const footerSection of section.footerSections ?? []) {\n footerSection.nodes.forEach(ensureNodeBlockIds);\n }\n }\n for (const note of model.metadata.footnotes ?? []) {\n note.nodes?.forEach(ensureNodeBlockIds);\n }\n for (const note of model.metadata.endnotes ?? []) {\n note.nodes?.forEach(ensureNodeBlockIds);\n }\n for (const comment of model.metadata.comments ?? []) {\n comment.nodes?.forEach(ensureNodeBlockIds);\n }\n\n return model;\n}\n\nfunction collectNodeBlockIds(\n node: DocNode | TableCellContentNode,\n seen: Set<string>,\n duplicates: Set<string>\n): void {\n if (node.blockId) {\n if (seen.has(node.blockId)) {\n duplicates.add(node.blockId);\n }\n seen.add(node.blockId);\n }\n\n if (node.type !== \"table\") {\n return;\n }\n\n for (const row of node.rows) {\n for (const cell of row.cells) {\n for (const child of cell.nodes) {\n collectNodeBlockIds(child, seen, duplicates);\n }\n }\n }\n}\n\n/**\n * Returns block ids that appear on more than one node within the same\n * container (body, a header/footer part, a note). Nodes without ids are\n * ignored, and the same id may legitimately recur across containers (section\n * views reference the same header/footer parts as the flat metadata lists).\n */\nexport function collectDuplicateDocModelBlockIds(model: DocModel): string[] {\n const duplicates = new Set<string>();\n\n const visitContainer = (nodes: DocNode[] | undefined): void => {\n if (!nodes) {\n return;\n }\n const seen = new Set<string>();\n nodes.forEach((node) => collectNodeBlockIds(node, seen, duplicates));\n };\n\n visitContainer(model.nodes);\n for (const section of model.metadata.headerSections ?? []) {\n visitContainer(section.nodes);\n }\n for (const section of model.metadata.footerSections ?? []) {\n visitContainer(section.nodes);\n }\n for (const note of model.metadata.footnotes ?? []) {\n visitContainer(note.nodes);\n }\n for (const note of model.metadata.endnotes ?? []) {\n visitContainer(note.nodes);\n }\n\n return Array.from(duplicates);\n}\n","import type {\n DocModel,\n DocNode,\n FooterSection,\n HeaderSection,\n NumberingDefinitionSet,\n ParagraphBorderSet,\n ParagraphBorderStyle,\n ParagraphIndent,\n ParagraphMarkFormattingSource,\n ParagraphNode,\n ParagraphNumbering,\n ParagraphSpacing,\n ParagraphStyle,\n ParagraphStyleDefinition,\n TableBorderSet,\n TableBorderStyle,\n TableBoxSpacing,\n TableCellContentNode,\n TableNode,\n TablePreferredWidth,\n TableWidthSource,\n TableRowStyle,\n TableStyle,\n TextStyle,\n} from \"./types\";\n\nfunction isParagraphCellContent(\n node: TableCellContentNode\n): node is ParagraphNode {\n return node.type === \"paragraph\";\n}\n\nfunction isTableCellContentTable(\n node: TableCellContentNode\n): node is TableNode {\n return node.type === \"table\";\n}\n\nfunction cloneTableCellContent(\n nodes: TableCellContentNode[]\n): TableCellContentNode[] {\n return nodes.map((node) => {\n if (isParagraphCellContent(node)) {\n return cloneParagraph(node);\n }\n\n if (isTableCellContentTable(node)) {\n return cloneTable(node);\n }\n\n return node;\n });\n}\n\nfunction cloneParagraphNumbering(\n numbering?: ParagraphNumbering\n): ParagraphNumbering | undefined {\n return numbering ? { ...numbering } : undefined;\n}\n\nfunction cloneParagraphSpacing(\n spacing?: ParagraphSpacing\n): ParagraphSpacing | undefined {\n return spacing ? { ...spacing } : undefined;\n}\n\nfunction cloneParagraphIndent(\n indent?: ParagraphIndent\n): ParagraphIndent | undefined {\n return indent ? { ...indent } : undefined;\n}\n\nfunction cloneParagraphBorderStyle(\n border?: ParagraphBorderStyle\n): ParagraphBorderStyle | undefined {\n return border ? { ...border } : undefined;\n}\n\nfunction cloneParagraphBorderSet(\n borders?: ParagraphBorderSet\n): ParagraphBorderSet | undefined {\n if (!borders) {\n return undefined;\n }\n\n return {\n top: cloneParagraphBorderStyle(borders.top),\n right: cloneParagraphBorderStyle(borders.right),\n bottom: cloneParagraphBorderStyle(borders.bottom),\n left: cloneParagraphBorderStyle(borders.left),\n between: cloneParagraphBorderStyle(borders.between),\n bar: cloneParagraphBorderStyle(borders.bar),\n };\n}\n\nfunction cloneParagraphStyle(\n style?: ParagraphStyle\n): ParagraphStyle | undefined {\n if (!style) {\n return undefined;\n }\n\n return {\n ...style,\n numbering: cloneParagraphNumbering(style.numbering),\n spacing: cloneParagraphSpacing(style.spacing),\n indent: cloneParagraphIndent(style.indent),\n borders: cloneParagraphBorderSet(style.borders),\n tabStops: style.tabStops?.map((stop) => ({ ...stop })),\n dropCap: style.dropCap\n ? {\n ...style.dropCap,\n }\n : undefined,\n };\n}\n\nfunction cloneTextStyle(style?: TextStyle): TextStyle | undefined {\n return style\n ? {\n ...style,\n runBorder: style.runBorder ? { ...style.runBorder } : undefined,\n }\n : undefined;\n}\n\nexport function cloneParagraphMarkFormatting(\n formatting?: ParagraphMarkFormattingSource\n): ParagraphMarkFormattingSource | undefined {\n return formatting\n ? {\n defaultStyle: cloneTextStyle(formatting.defaultStyle),\n characterStyle: cloneTextStyle(formatting.characterStyle),\n directStyle: cloneTextStyle(formatting.directStyle),\n }\n : undefined;\n}\n\nexport function cloneParagraphNode(paragraph: ParagraphNode): ParagraphNode {\n return cloneParagraph(paragraph);\n}\n\nexport function cloneTableNode(table: TableNode): TableNode {\n return cloneTable(table);\n}\n\nfunction cloneParagraph(paragraph: ParagraphNode): ParagraphNode {\n return {\n type: \"paragraph\",\n blockId: paragraph.blockId,\n style: cloneParagraphStyle(paragraph.style),\n paragraphMarkStyle: cloneTextStyle(paragraph.paragraphMarkStyle),\n sourceParagraphMarkStyle: cloneTextStyle(paragraph.sourceParagraphMarkStyle),\n sourceParagraphMarkFormatting: cloneParagraphMarkFormatting(\n paragraph.sourceParagraphMarkFormatting\n ),\n sourceParagraphMarkPropertiesXml: paragraph.sourceParagraphMarkPropertiesXml,\n paragraphMarkDeleted: paragraph.paragraphMarkDeleted,\n sourceXml: paragraph.sourceXml,\n sourceTextPatch: paragraph.sourceTextPatch\n ? {\n runs: paragraph.sourceTextPatch.runs.map((run) => ({\n style: cloneTextStyle(run.style),\n link: run.link,\n noteReference: run.noteReference\n ? { ...run.noteReference }\n : undefined,\n })),\n }\n : undefined,\n sourceRunProvenance: paragraph.sourceRunProvenance\n ? {\n runs: paragraph.sourceRunProvenance.runs.map((run) => ({\n style: cloneTextStyle(run.style),\n link: run.link,\n noteReference: run.noteReference\n ? { ...run.noteReference }\n : undefined,\n })),\n }\n : undefined,\n children: paragraph.children.map((child) => {\n if (child.type === \"text\") {\n return {\n type: \"text\" as const,\n text: child.text,\n style: cloneTextStyle(child.style),\n link: child.link,\n noteReference: child.noteReference\n ? { ...child.noteReference }\n : undefined,\n };\n }\n\n if (child.type === \"form-field\") {\n return {\n type: \"form-field\" as const,\n fieldType: child.fieldType,\n sourceKind: child.sourceKind,\n id: child.id,\n tag: child.tag,\n title: child.title,\n placeholder: child.placeholder,\n checked: child.checked,\n value: child.value,\n options: child.options?.map((option) => ({\n displayText: option.displayText,\n value: option.value,\n })),\n widget: child.widget\n ? {\n name: child.widget.name,\n enabled: child.widget.enabled,\n calcOnExit: child.widget.calcOnExit,\n text: child.widget.text\n ? {\n inputType: child.widget.text.inputType,\n defaultText: child.widget.text.defaultText,\n maxLength: child.widget.text.maxLength,\n textFormat: child.widget.text.textFormat,\n }\n : undefined,\n checkbox: child.widget.checkbox\n ? {\n defaultChecked: child.widget.checkbox.defaultChecked,\n sizeMode: child.widget.checkbox.sizeMode,\n sizePt: child.widget.checkbox.sizePt,\n }\n : undefined,\n dropdown: child.widget.dropdown\n ? {\n defaultValue: child.widget.dropdown.defaultValue,\n }\n : undefined,\n }\n : undefined,\n checkedSymbol: child.checkedSymbol,\n uncheckedSymbol: child.uncheckedSymbol,\n style: child.style ? { ...child.style } : undefined,\n link: child.link,\n sourceXml: child.sourceXml,\n };\n }\n\n return {\n type: \"image\" as const,\n blockId: child.blockId,\n semanticKind: child.semanticKind,\n mathMl: child.mathMl,\n contentNodes: child.contentNodes?.map(cloneDocNode),\n src: child.src,\n alt: child.alt,\n widthPx: child.widthPx,\n heightPx: child.heightPx,\n partName: child.partName,\n contentType: child.contentType,\n data: child.data ? new Uint8Array(child.data) : undefined,\n sourceXml: child.sourceXml,\n crop: child.crop ? { ...child.crop } : undefined,\n cssFilter: child.cssFilter,\n cssOpacity: child.cssOpacity,\n floating: child.floating ? { ...child.floating } : undefined,\n syntheticTextBox: child.syntheticTextBox,\n textBoxText: child.textBoxText,\n };\n }),\n };\n}\n\nfunction cloneTableBoxSpacing(\n spacing?: TableBoxSpacing\n): TableBoxSpacing | undefined {\n if (!spacing) {\n return undefined;\n }\n\n return {\n topTwips: spacing.topTwips,\n rightTwips: spacing.rightTwips,\n bottomTwips: spacing.bottomTwips,\n leftTwips: spacing.leftTwips,\n };\n}\n\nfunction cloneTableBorderStyle(\n border?: TableBorderStyle\n): TableBorderStyle | undefined {\n if (!border) {\n return undefined;\n }\n\n return {\n type: border.type,\n color: border.color,\n sizeEighthPt: border.sizeEighthPt,\n };\n}\n\nfunction cloneTableBorderSet(\n borders?: TableBorderSet\n): TableBorderSet | undefined {\n if (!borders) {\n return undefined;\n }\n\n return {\n top: cloneTableBorderStyle(borders.top),\n right: cloneTableBorderStyle(borders.right),\n bottom: cloneTableBorderStyle(borders.bottom),\n left: cloneTableBorderStyle(borders.left),\n insideH: cloneTableBorderStyle(borders.insideH),\n insideV: cloneTableBorderStyle(borders.insideV),\n tl2br: cloneTableBorderStyle(borders.tl2br),\n tr2bl: cloneTableBorderStyle(borders.tr2bl),\n };\n}\n\nfunction cloneTableFloatingStyle(\n floating?: NonNullable<TableStyle[\"floating\"]>\n): NonNullable<TableStyle[\"floating\"]> | undefined {\n if (!floating) {\n return undefined;\n }\n\n return {\n xTwips: floating.xTwips,\n yTwips: floating.yTwips,\n leftFromTextTwips: floating.leftFromTextTwips,\n rightFromTextTwips: floating.rightFromTextTwips,\n topFromTextTwips: floating.topFromTextTwips,\n bottomFromTextTwips: floating.bottomFromTextTwips,\n horizontalAnchor: floating.horizontalAnchor,\n verticalAnchor: floating.verticalAnchor,\n horizontalAlign: floating.horizontalAlign,\n verticalAlign: floating.verticalAlign,\n };\n}\n\nfunction cloneTablePreferredWidth(\n width?: TablePreferredWidth\n): TablePreferredWidth | undefined {\n return width ? { ...width } : undefined;\n}\n\nfunction cloneTableWidthSource(\n source?: TableWidthSource\n): TableWidthSource | undefined {\n return source ? {\n ...source,\n preferredWidth: cloneTablePreferredWidth(source.preferredWidth),\n inheritedPreferredWidth: cloneTablePreferredWidth(source.inheritedPreferredWidth),\n } : undefined;\n}\n\nfunction cloneTableRowStyle(style?: TableRowStyle): TableRowStyle | undefined {\n return style ? {\n ...style,\n widthBefore: cloneTablePreferredWidth(style.widthBefore),\n widthAfter: cloneTablePreferredWidth(style.widthAfter),\n sourceRowGeometry: style.sourceRowGeometry ? {\n ...style.sourceRowGeometry,\n widthBefore: cloneTablePreferredWidth(style.sourceRowGeometry.widthBefore),\n widthAfter: cloneTablePreferredWidth(style.sourceRowGeometry.widthAfter),\n } : undefined,\n } : undefined;\n}\n\nfunction cloneTable(table: TableNode): TableNode {\n return {\n type: \"table\",\n blockId: table.blockId,\n sourceXml: table.sourceXml,\n sourceTextPatches: table.sourceTextPatches?.map((patch) => ({\n sourceParagraphXml: patch.sourceParagraphXml,\n paragraph: cloneParagraph(patch.paragraph),\n })),\n style: table.style\n ? {\n styleId: table.style.styleId,\n sourceStyleId: table.style.sourceStyleId,\n widthTwips: table.style.widthTwips,\n preferredWidth: cloneTablePreferredWidth(table.style.preferredWidth),\n sourceWidth: cloneTableWidthSource(table.style.sourceWidth),\n alignment: table.style.alignment,\n sourceAlignment: table.style.sourceAlignment,\n sourceInheritedAlignment: table.style.sourceInheritedAlignment,\n bidiVisual: table.style.bidiVisual,\n sourceBidiVisual: table.style.sourceBidiVisual,\n sourceInheritedBidiVisual: table.style.sourceInheritedBidiVisual,\n indentTwips: table.style.indentTwips,\n layout: table.style.layout,\n cellSpacingTwips: table.style.cellSpacingTwips,\n floating: cloneTableFloatingStyle(table.style.floating),\n cellMarginTwips: cloneTableBoxSpacing(table.style.cellMarginTwips),\n columnWidthsTwips: table.style.columnWidthsTwips\n ? [...table.style.columnWidthsTwips]\n : undefined,\n borders: cloneTableBorderSet(table.style.borders),\n }\n : undefined,\n rows: table.rows.map((row) => ({\n type: \"table-row\",\n style: cloneTableRowStyle(row.style),\n cells: row.cells.map((cell) => ({\n type: \"table-cell\",\n style: cell.style\n ? {\n ...cell.style,\n preferredWidth: cloneTablePreferredWidth(cell.style.preferredWidth),\n sourceWidth: cloneTableWidthSource(cell.style.sourceWidth),\n marginTwips: cloneTableBoxSpacing(cell.style.marginTwips),\n borders: cloneTableBorderSet(cell.style.borders),\n }\n : undefined,\n nodes: cloneTableCellContent(cell.nodes),\n })),\n })),\n };\n}\n\nfunction cloneDocNode(node: DocNode): DocNode {\n return node.type === \"paragraph\" ? cloneParagraph(node) : cloneTable(node);\n}\n\nfunction cloneNumberingDefinitions(\n numberingDefinitions?: NumberingDefinitionSet\n): NumberingDefinitionSet | undefined {\n if (!numberingDefinitions) {\n return undefined;\n }\n\n return {\n abstracts: numberingDefinitions.abstracts.map((abstractDefinition) => ({\n abstractNumId: abstractDefinition.abstractNumId,\n levels: abstractDefinition.levels.map((level) => ({\n ...level,\n runStyle: level.runStyle ? { ...level.runStyle } : undefined,\n pictureBullet: level.pictureBullet\n ? { ...level.pictureBullet }\n : undefined,\n })),\n })),\n instances: numberingDefinitions.instances.map((instanceDefinition) => ({\n numId: instanceDefinition.numId,\n abstractNumId: instanceDefinition.abstractNumId,\n levelStartOverrides: instanceDefinition.levelStartOverrides\n ? { ...instanceDefinition.levelStartOverrides }\n : undefined,\n levelOverrides: instanceDefinition.levelOverrides\n ? instanceDefinition.levelOverrides.map((level) => ({\n ...level,\n runStyle: level.runStyle ? { ...level.runStyle } : undefined,\n pictureBullet: level.pictureBullet\n ? { ...level.pictureBullet }\n : undefined,\n }))\n : undefined,\n })),\n };\n}\n\nexport function cloneDocModel(model: DocModel): DocModel {\n return {\n nodes: model.nodes.map(cloneDocNode),\n metadata: {\n documentId: model.metadata.documentId,\n sourcePartNames: model.metadata.sourcePartNames ? { ...model.metadata.sourcePartNames } : undefined,\n sourceParts: model.metadata.sourceParts,\n warnings: [...model.metadata.warnings],\n documentPageCount: model.metadata.documentPageCount,\n documentOpenTag: model.metadata.documentOpenTag,\n documentBackgroundColor: model.metadata.documentBackgroundColor,\n sectionPropertiesXml: model.metadata.sectionPropertiesXml,\n sections: model.metadata.sections?.map((section) => ({\n startNodeIndex: section.startNodeIndex,\n sectionPropertiesXml: section.sectionPropertiesXml,\n headerSections: (section.headerSections ?? []).map((headerSection) => ({\n partName: headerSection.partName,\n referenceType: headerSection.referenceType,\n nodes: headerSection.nodes.map(cloneDocNode),\n })),\n footerSections: (section.footerSections ?? []).map((footerSection) => ({\n partName: footerSection.partName,\n referenceType: footerSection.referenceType,\n nodes: footerSection.nodes.map(cloneDocNode),\n })),\n })),\n headerSections: (model.metadata.headerSections ?? []).map((section) => ({\n partName: section.partName,\n referenceType: section.referenceType,\n nodes: section.nodes.map(cloneDocNode),\n })),\n footerSections: (model.metadata.footerSections ?? []).map((section) => ({\n partName: section.partName,\n referenceType: section.referenceType,\n nodes: section.nodes.map(cloneDocNode),\n })),\n paragraphStyles: (model.metadata.paragraphStyles ?? []).map((style) => ({\n ...style,\n runStyle: style.runStyle ? { ...style.runStyle } : undefined,\n numbering: cloneParagraphNumbering(style.numbering),\n spacing: cloneParagraphSpacing(style.spacing),\n indent: cloneParagraphIndent(style.indent),\n borders: cloneParagraphBorderSet(style.borders),\n })),\n defaultParagraphStyleId: model.metadata.defaultParagraphStyleId,\n defaultTabStopTwips: model.metadata.defaultTabStopTwips,\n documentSettingsImported: model.metadata.documentSettingsImported,\n lineSpacingCompatibilityImported: model.metadata.lineSpacingCompatibilityImported,\n numberingDefinitions: cloneNumberingDefinitions(\n model.metadata.numberingDefinitions\n ),\n compatibility: model.metadata.compatibility\n ? { ...model.metadata.compatibility }\n : undefined,\n footnotes: model.metadata.footnotes?.map((note) => ({\n ...note,\n nodes: note.nodes?.map(cloneDocNode),\n })),\n endnotes: model.metadata.endnotes?.map((note) => ({\n ...note,\n nodes: note.nodes?.map(cloneDocNode),\n })),\n comments: model.metadata.comments?.map((comment) => ({ ...comment, nodes: comment.nodes?.map(cloneDocNode) })),\n },\n };\n}\n","import type { DocModel } from \"./types\";\n\nfunction deepFreezeValue(value: unknown): void {\n if (typeof value !== \"object\" || value === null) {\n return;\n }\n // Freezing a typed array throws; image byte payloads stay unfrozen.\n if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {\n return;\n }\n if (Object.isFrozen(value)) {\n return;\n }\n\n Object.freeze(value);\n if (Array.isArray(value)) {\n for (const entry of value) {\n deepFreezeValue(entry);\n }\n return;\n }\n\n for (const key of Object.keys(value)) {\n deepFreezeValue((value as Record<string, unknown>)[key]);\n }\n}\n\n/**\n * Dev-only commit guard: freezes a committed model so in-place mutation of\n * structure shared with history snapshots throws instead of corrupting them.\n * Already-frozen subtrees are skipped, so once a model is frozen, freezing a\n * structurally shared successor only pays for the changed nodes.\n */\nexport function deepFreezeDocModel(model: DocModel): DocModel {\n deepFreezeValue(model);\n return model;\n}\n","import type { OoxmlPackage } from \"@extend-ai/react-docx-ooxml-core\";\nimport {\n mapsToWasmPackage,\n wasmBuildDocModelFromBytes,\n wasmBuildDocModelFromPackage,\n wasmPackageToMaps\n} from \"@extend-ai/react-docx-wasm\";\n\nimport { normalizeDocModel } from \"./normalize\";\nimport type { DocModel } from \"./types\";\n\nexport * from \"./types\";\nexport * from \"./blocks\";\nexport { resolveTableGridSkipCount, tableGridColumnBound, tableRowGridSkipCount } from \"./table-grid\";\nexport {\n allocateBlockId,\n collectDuplicateDocModelBlockIds,\n ensureDocModelBlockIds\n} from \"./block-id\";\nexport { cloneDocModel, cloneParagraphMarkFormatting, cloneParagraphNode, cloneTableNode } from \"./clone\";\nexport { deepFreezeDocModel } from \"./freeze\";\nexport { normalizeDocModel } from \"./normalize\";\n\nexport async function buildDocModel(pkg: OoxmlPackage): Promise<DocModel> {\n const wasmPackage = mapsToWasmPackage({\n parts: pkg.parts,\n binaryAssets: pkg.binaryAssets,\n warnings: pkg.warnings\n });\n const model = (await wasmBuildDocModelFromPackage(wasmPackage)) as DocModel;\n return normalizeDocModel(model);\n}\n\nexport async function buildDocModelFromBytes(bytes: ArrayBuffer | Uint8Array): Promise<{\n package: OoxmlPackage;\n model: DocModel;\n timings: { parseMs: number; buildModelMs: number; totalMs: number };\n}> {\n const startedAt = performance.now();\n const result = await wasmBuildDocModelFromBytes(bytes);\n const builtAt = performance.now();\n const { parts, binaryAssets, warnings } = wasmPackageToMaps(result.package);\n const pkg = { parts, binaryAssets, ...(warnings.length > 0 ? { warnings } : {}) };\n const model = normalizeDocModel(result.model as DocModel);\n const finishedAt = performance.now();\n const buildModelMs = result.timings.buildModelMs + finishedAt - builtAt;\n return {\n package: pkg,\n model,\n timings: {\n parseMs: Math.max(0, builtAt - startedAt - result.timings.buildModelMs),\n buildModelMs,\n totalMs: finishedAt - startedAt,\n },\n };\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAS,oBAAoB,OAAwC;AACnE,MAAI,iBAAiB,YAAY;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,WAAW,KAAK,KAAiB;AAAA,EAC1C;AACA,SAAO;AACT;AAEA,SAAS,wBAAwB,OAA+C;AAC9E,MAAI,MAAM,SAAS,SAAS;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ;AACd,QAAM,OAAO,oBAAoB,MAAM,IAAI;AAC3C,MAAI,SAAS,MAAM,QAAQ,CAAC,MAAM,cAAc;AAC9C,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,cAAc,MAAM,cAAc,IAAI,gBAAgB;AAAA,EACxD;AACF;AAEA,SAAS,0BAA0B,MAAkD;AACnF,MAAI,KAAK,SAAS,SAAS;AACzB,WAAO,iBAAiB,IAAI;AAAA,EAC9B;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,KAAK,SAAS,IAAI,uBAAuB;AAAA,EACrD;AACF;AAEA,SAAS,iBAAiB,MAAwB;AAChD,MAAI,KAAK,SAAS,aAAa;AAC7B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,UAAU,KAAK,SAAS,IAAI,uBAAuB;AAAA,IACrD;AAAA,EACF;AAEA,SA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OAAO,QAAQ,eAAe,aAAa;AAChE,SAAO;AAAA,IACL,SAAS;AAAA,IACT;AAAA,IACA,SAAS;AAAA,MACP,SAAS,KAAK,IAAI,GAAG,UAAU,YAAY,OAAO,QAAQ,YAAY;AAAA,MACtE;AAAA,MACA,SAAS,aAAa;AAAA,IACxB;AAAA,EACF;AACF;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  wasmPackageToArrayBuffer,
4
4
  wasmPackageToMaps,
5
5
  wasmParseDocx
6
- } from "./chunk-AKDFE4ZH.js";
6
+ } from "./chunk-TPYS6CSH.js";
7
7
 
8
8
  // ../ooxml-core/src/index.ts
9
9
  async function parseDocx(input) {
@@ -71,4 +71,4 @@ export {
71
71
  getPart,
72
72
  withPart
73
73
  };
74
- //# sourceMappingURL=chunk-6NVXVLTW.js.map
74
+ //# sourceMappingURL=chunk-PTOOIOQG.js.map
@@ -42,6 +42,89 @@ function build_doc_model_from_package(_package) {
42
42
  wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
43
43
  }
44
44
  }
45
+ function extract_document_blocks_wasm(model_json) {
46
+ let deferred3_0;
47
+ let deferred3_1;
48
+ try {
49
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
50
+ const ptr0 = passStringToWasm0(model_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
51
+ const len0 = WASM_VECTOR_LEN;
52
+ wasm.extract_document_blocks_wasm(retptr, ptr0, len0);
53
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
54
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
55
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
56
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
57
+ var ptr2 = r0;
58
+ var len2 = r1;
59
+ if (r3) {
60
+ ptr2 = 0;
61
+ len2 = 0;
62
+ throw takeObject(r2);
63
+ }
64
+ deferred3_0 = ptr2;
65
+ deferred3_1 = len2;
66
+ return getStringFromWasm0(ptr2, len2);
67
+ } finally {
68
+ wasm.__wbindgen_add_to_stack_pointer(16);
69
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
70
+ }
71
+ }
72
+ function extract_document_blocks_with_options_wasm(model_json, options_json) {
73
+ let deferred4_0;
74
+ let deferred4_1;
75
+ try {
76
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
77
+ const ptr0 = passStringToWasm0(model_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
78
+ const len0 = WASM_VECTOR_LEN;
79
+ const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
80
+ const len1 = WASM_VECTOR_LEN;
81
+ wasm.extract_document_blocks_with_options_wasm(retptr, ptr0, len0, ptr1, len1);
82
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
83
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
84
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
85
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
86
+ var ptr3 = r0;
87
+ var len3 = r1;
88
+ if (r3) {
89
+ ptr3 = 0;
90
+ len3 = 0;
91
+ throw takeObject(r2);
92
+ }
93
+ deferred4_0 = ptr3;
94
+ deferred4_1 = len3;
95
+ return getStringFromWasm0(ptr3, len3);
96
+ } finally {
97
+ wasm.__wbindgen_add_to_stack_pointer(16);
98
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
99
+ }
100
+ }
101
+ function inspect_document_source_wasm(bytes) {
102
+ let deferred3_0;
103
+ let deferred3_1;
104
+ try {
105
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
106
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
107
+ const len0 = WASM_VECTOR_LEN;
108
+ wasm.inspect_document_source_wasm(retptr, ptr0, len0);
109
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
110
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
111
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
112
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
113
+ var ptr2 = r0;
114
+ var len2 = r1;
115
+ if (r3) {
116
+ ptr2 = 0;
117
+ len2 = 0;
118
+ throw takeObject(r2);
119
+ }
120
+ deferred3_0 = ptr2;
121
+ deferred3_1 = len2;
122
+ return getStringFromWasm0(ptr2, len2);
123
+ } finally {
124
+ wasm.__wbindgen_add_to_stack_pointer(16);
125
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
126
+ }
127
+ }
45
128
  function model_to_document_xml_from_json_wasm(model_json, base_package) {
46
129
  let deferred3_0;
47
130
  let deferred3_1;
@@ -622,6 +705,15 @@ async function wasmBuildDocModelFromPackage(pkg) {
622
705
  const json = build_doc_model_from_package(pkg);
623
706
  return JSON.parse(json);
624
707
  }
708
+ async function wasmInspectDocumentSource(bytes) {
709
+ await initWasm();
710
+ return JSON.parse(inspect_document_source_wasm(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes)));
711
+ }
712
+ async function wasmExtractDocumentBlocks(model, options = {}) {
713
+ await initWasm();
714
+ const json = JSON.stringify(model, (key, value) => key === "data" || key === "src" ? void 0 : value);
715
+ return JSON.parse(options.includeWords ? extract_document_blocks_with_options_wasm(json, JSON.stringify(options)) : extract_document_blocks_wasm(json));
716
+ }
625
717
  async function wasmBuildDocModelFromBytes(bytes) {
626
718
  await initWasm();
627
719
  const payload = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
@@ -650,9 +742,11 @@ export {
650
742
  mapsToWasmPackage,
651
743
  wasmParseDocx,
652
744
  wasmBuildDocModelFromPackage,
745
+ wasmInspectDocumentSource,
746
+ wasmExtractDocumentBlocks,
653
747
  wasmBuildDocModelFromBytes,
654
748
  wasmSerializeDocx,
655
749
  wasmModelToDocumentXml,
656
750
  wasmPackageToArrayBuffer
657
751
  };
658
- //# sourceMappingURL=chunk-AKDFE4ZH.js.map
752
+ //# sourceMappingURL=chunk-TPYS6CSH.js.map