@beyondwork/docx-react-component 1.0.1 → 1.0.3
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 +44 -104
- package/package.json +50 -30
- package/src/README.md +85 -0
- package/src/api/README.md +22 -0
- package/src/api/public-types.ts +525 -0
- package/src/compare/diff-engine.ts +530 -0
- package/src/compare/export-redlines.ts +162 -0
- package/src/compare/snapshot.ts +37 -0
- package/src/component-inventory.md +99 -0
- package/src/core/README.md +10 -0
- package/src/core/commands/README.md +3 -0
- package/src/core/commands/formatting-commands.ts +161 -0
- package/src/core/commands/image-commands.ts +144 -0
- package/src/core/commands/index.ts +1013 -0
- package/src/core/commands/list-commands.ts +370 -0
- package/src/core/commands/review-commands.ts +108 -0
- package/src/core/commands/text-commands.ts +119 -0
- package/src/core/schema/README.md +3 -0
- package/src/core/schema/text-schema.ts +512 -0
- package/src/core/selection/README.md +3 -0
- package/src/core/selection/mapping.ts +238 -0
- package/src/core/selection/review-anchors.ts +94 -0
- package/src/core/state/README.md +3 -0
- package/src/core/state/editor-state.ts +580 -0
- package/src/core/state/text-transaction.ts +276 -0
- package/src/formats/xlsx/io/parse-shared-strings.ts +41 -0
- package/src/formats/xlsx/io/parse-sheet.ts +289 -0
- package/src/formats/xlsx/io/parse-styles.ts +57 -0
- package/src/formats/xlsx/io/parse-workbook.ts +75 -0
- package/src/formats/xlsx/io/xlsx-session.ts +306 -0
- package/src/formats/xlsx/model/cell.ts +189 -0
- package/src/formats/xlsx/model/sheet.ts +244 -0
- package/src/formats/xlsx/model/styles.ts +118 -0
- package/src/formats/xlsx/model/workbook.ts +449 -0
- package/src/index.ts +45 -0
- package/src/io/README.md +10 -0
- package/src/io/docx-session.ts +1763 -0
- package/src/io/export/README.md +3 -0
- package/src/io/export/export-session.ts +165 -0
- package/src/io/export/minimal-docx.ts +115 -0
- package/src/io/export/reattach-preserved-parts.ts +54 -0
- package/src/io/export/serialize-comments.ts +876 -0
- package/src/io/export/serialize-footnotes.ts +217 -0
- package/src/io/export/serialize-headers-footers.ts +200 -0
- package/src/io/export/serialize-main-document.ts +982 -0
- package/src/io/export/serialize-numbering.ts +97 -0
- package/src/io/export/serialize-revisions.ts +389 -0
- package/src/io/export/serialize-runtime-revisions.ts +265 -0
- package/src/io/export/serialize-tables.ts +147 -0
- package/src/io/export/split-review-boundaries.ts +194 -0
- package/src/io/normalize/README.md +3 -0
- package/src/io/normalize/normalize-text.ts +437 -0
- package/src/io/ooxml/README.md +3 -0
- package/src/io/ooxml/parse-comments.ts +779 -0
- package/src/io/ooxml/parse-complex-content.ts +287 -0
- package/src/io/ooxml/parse-fields.ts +438 -0
- package/src/io/ooxml/parse-footnotes.ts +403 -0
- package/src/io/ooxml/parse-headers-footers.ts +483 -0
- package/src/io/ooxml/parse-inline-media.ts +431 -0
- package/src/io/ooxml/parse-main-document.ts +1846 -0
- package/src/io/ooxml/parse-numbering.ts +425 -0
- package/src/io/ooxml/parse-revisions.ts +658 -0
- package/src/io/ooxml/parse-shapes.ts +271 -0
- package/src/io/ooxml/parse-tables.ts +568 -0
- package/src/io/ooxml/parse-theme.ts +314 -0
- package/src/io/ooxml/part-manifest.ts +136 -0
- package/src/io/ooxml/revision-boundaries.ts +351 -0
- package/src/io/opc/README.md +3 -0
- package/src/io/opc/corrupt-package.ts +166 -0
- package/src/io/opc/docx-package.ts +74 -0
- package/src/io/opc/package-reader.ts +325 -0
- package/src/io/opc/package-writer.ts +273 -0
- package/src/legal/bookmarks.ts +196 -0
- package/src/legal/cross-references.ts +356 -0
- package/src/legal/defined-terms.ts +203 -0
- package/src/model/README.md +3 -0
- package/src/model/canonical-document.ts +1911 -0
- package/src/model/cds-1.0.0.ts +196 -0
- package/src/model/snapshot.ts +393 -0
- package/src/preservation/README.md +3 -0
- package/src/preservation/markup-compatibility.ts +48 -0
- package/src/preservation/opaque-fragment-store.ts +89 -0
- package/src/preservation/opaque-region.ts +233 -0
- package/src/preservation/package-preservation.ts +120 -0
- package/src/preservation/preserved-part-manifest.ts +56 -0
- package/src/preservation/relationship-retention.ts +57 -0
- package/src/preservation/store.ts +185 -0
- package/src/review/README.md +16 -0
- package/src/review/store/README.md +3 -0
- package/src/review/store/comment-anchors.ts +70 -0
- package/src/review/store/comment-remapping.ts +154 -0
- package/src/review/store/comment-store.ts +331 -0
- package/src/review/store/comment-thread.ts +109 -0
- package/src/review/store/revision-actions.ts +394 -0
- package/src/review/store/revision-store.ts +303 -0
- package/src/review/store/revision-types.ts +168 -0
- package/src/review/store/runtime-comment-store.ts +43 -0
- package/src/runtime/README.md +3 -0
- package/src/runtime/ai-action-policy.ts +764 -0
- package/src/runtime/document-runtime.ts +967 -0
- package/src/runtime/read-only-diagnostics-runtime.ts +232 -0
- package/src/runtime/review-runtime.ts +44 -0
- package/src/runtime/revision-runtime.ts +107 -0
- package/src/runtime/session-capabilities.ts +138 -0
- package/src/runtime/surface-projection.ts +570 -0
- package/src/runtime/table-commands.ts +87 -0
- package/src/runtime/table-schema.ts +140 -0
- package/src/runtime/virtualized-rendering.ts +258 -0
- package/src/ui/README.md +30 -0
- package/src/ui/WordReviewEditor.tsx +1506 -0
- package/src/ui/comments/README.md +3 -0
- package/src/ui/compatibility/README.md +3 -0
- package/src/ui/editor-surface/README.md +3 -0
- package/src/ui/headless/comment-decoration-model.ts +124 -0
- package/src/ui/headless/revision-decoration-model.ts +128 -0
- package/src/ui/headless/selection-helpers.ts +34 -0
- package/src/ui/headless/use-editor-keyboard.ts +98 -0
- package/src/ui/review/README.md +3 -0
- package/src/ui/shared/revision-filters.ts +31 -0
- package/src/ui/status/README.md +3 -0
- package/src/ui/theme/README.md +3 -0
- package/src/ui/toolbar/README.md +3 -0
- package/src/ui-tailwind/chrome/tw-alert-banner.tsx +48 -0
- package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +44 -0
- package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +58 -0
- package/src/ui-tailwind/chrome/use-before-unload.ts +20 -0
- package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +139 -0
- package/src/ui-tailwind/editor-surface/pm-decorations.ts +98 -0
- package/src/ui-tailwind/editor-surface/pm-position-map.ts +123 -0
- package/src/ui-tailwind/editor-surface/pm-schema.ts +452 -0
- package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +327 -0
- package/src/ui-tailwind/editor-surface/search-plugin.ts +157 -0
- package/src/ui-tailwind/editor-surface/tw-caret.tsx +12 -0
- package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +150 -0
- package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +118 -0
- package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +52 -0
- package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +151 -0
- package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +215 -0
- package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +111 -0
- package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +122 -0
- package/src/ui-tailwind/index.ts +61 -0
- package/src/ui-tailwind/review/tw-comment-sidebar.tsx +276 -0
- package/src/ui-tailwind/review/tw-health-panel.tsx +120 -0
- package/src/ui-tailwind/review/tw-review-rail.tsx +120 -0
- package/src/ui-tailwind/review/tw-revision-sidebar.tsx +164 -0
- package/src/ui-tailwind/status/tw-status-bar.tsx +58 -0
- package/src/ui-tailwind/theme/editor-theme.css +190 -0
- package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +48 -0
- package/src/ui-tailwind/toolbar/tw-toolbar.tsx +231 -0
- package/src/ui-tailwind/tw-review-workspace.tsx +140 -0
- package/src/validation/README.md +3 -0
- package/src/validation/compatibility-engine.ts +317 -0
- package/src/validation/compatibility-report.ts +160 -0
- package/src/validation/diagnostics.ts +203 -0
- package/src/validation/import-diagnostics.ts +128 -0
- package/src/validation/low-priority-word-surfaces.ts +373 -0
- package/dist/chunk-32W6IVQE.js +0 -7725
- package/dist/chunk-32W6IVQE.js.map +0 -1
- package/dist/index.cjs +0 -23722
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -7
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -16011
- package/dist/index.js.map +0 -1
- package/dist/public-types-DqCURAz8.d.cts +0 -1152
- package/dist/public-types-DqCURAz8.d.ts +0 -1152
- package/dist/tailwind.cjs +0 -8295
- package/dist/tailwind.cjs.map +0 -1
- package/dist/tailwind.d.cts +0 -323
- package/dist/tailwind.d.ts +0 -323
- package/dist/tailwind.js +0 -553
- package/dist/tailwind.js.map +0 -1
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AltChunkNode,
|
|
3
|
+
BlockNode,
|
|
4
|
+
CustomXmlNode,
|
|
5
|
+
DiagnosticStore,
|
|
6
|
+
DocumentRootNode,
|
|
7
|
+
InlineNode,
|
|
8
|
+
MediaCatalog,
|
|
9
|
+
OpaqueBlockNode,
|
|
10
|
+
OpaqueFragmentRecord,
|
|
11
|
+
OpaqueInlineNode,
|
|
12
|
+
ParagraphNode,
|
|
13
|
+
PreservationStore,
|
|
14
|
+
TableCellNode,
|
|
15
|
+
TableNode,
|
|
16
|
+
TableRowNode,
|
|
17
|
+
TextMark,
|
|
18
|
+
TextNode,
|
|
19
|
+
SdtNode,
|
|
20
|
+
} from "../../model/canonical-document.ts";
|
|
21
|
+
import type {
|
|
22
|
+
ParsedAltChunkNode,
|
|
23
|
+
ParsedBlockNode,
|
|
24
|
+
ParsedCustomXmlNode,
|
|
25
|
+
ParsedHyperlinkNode,
|
|
26
|
+
ParsedInlineNode,
|
|
27
|
+
ParsedImageNode,
|
|
28
|
+
ParsedMainDocument,
|
|
29
|
+
ParsedParagraphNode,
|
|
30
|
+
ParsedSdtNode,
|
|
31
|
+
ParsedTableBlockNode,
|
|
32
|
+
ParsedTableCellNode,
|
|
33
|
+
ParsedTableRowNode,
|
|
34
|
+
} from "../ooxml/parse-main-document.ts";
|
|
35
|
+
|
|
36
|
+
export interface NormalizedTextDocument {
|
|
37
|
+
content: DocumentRootNode;
|
|
38
|
+
media: MediaCatalog;
|
|
39
|
+
preservation: PreservationStore;
|
|
40
|
+
diagnostics: DiagnosticStore;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface NormalizationState {
|
|
44
|
+
nextFragmentIndex: number;
|
|
45
|
+
nextWarningIndex: number;
|
|
46
|
+
nextDiagnosticIndex: number;
|
|
47
|
+
cursor: number;
|
|
48
|
+
media: MediaCatalog;
|
|
49
|
+
preservation: PreservationStore;
|
|
50
|
+
diagnostics: DiagnosticStore;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function normalizeParsedTextDocument(
|
|
54
|
+
document: ParsedMainDocument,
|
|
55
|
+
packagePartName = "/word/document.xml",
|
|
56
|
+
): NormalizedTextDocument {
|
|
57
|
+
const state: NormalizationState = {
|
|
58
|
+
nextFragmentIndex: 1,
|
|
59
|
+
nextWarningIndex: 1,
|
|
60
|
+
nextDiagnosticIndex: 1,
|
|
61
|
+
cursor: 0,
|
|
62
|
+
media: {
|
|
63
|
+
items: {},
|
|
64
|
+
},
|
|
65
|
+
preservation: {
|
|
66
|
+
opaqueFragments: {},
|
|
67
|
+
packageParts: {},
|
|
68
|
+
},
|
|
69
|
+
diagnostics: {
|
|
70
|
+
warnings: [],
|
|
71
|
+
errors: [],
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const children = document.blocks.map((block, index) => {
|
|
76
|
+
if (
|
|
77
|
+
index > 0 &&
|
|
78
|
+
document.blocks[index - 1]?.type === "paragraph" &&
|
|
79
|
+
block.type === "paragraph"
|
|
80
|
+
) {
|
|
81
|
+
state.cursor += 1;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return normalizeBlock(block, state, packagePartName);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
content: {
|
|
89
|
+
type: "doc",
|
|
90
|
+
children,
|
|
91
|
+
},
|
|
92
|
+
media: state.media,
|
|
93
|
+
preservation: state.preservation,
|
|
94
|
+
diagnostics: state.diagnostics,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function normalizeBlock(
|
|
99
|
+
block: ParsedBlockNode,
|
|
100
|
+
state: NormalizationState,
|
|
101
|
+
packagePartName: string,
|
|
102
|
+
): BlockNode {
|
|
103
|
+
if (block.type === "opaque_block") {
|
|
104
|
+
const opaque = recordOpaqueFragment("opaque_block", block.rawXml, state, packagePartName);
|
|
105
|
+
state.cursor += 1;
|
|
106
|
+
return {
|
|
107
|
+
type: "opaque_block",
|
|
108
|
+
fragmentId: opaque.fragmentId,
|
|
109
|
+
warningId: opaque.warningId,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (block.type === "table") {
|
|
114
|
+
return normalizeTable(block, state, packagePartName);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (block.type === "sdt") {
|
|
118
|
+
return normalizeSdt(block, state, packagePartName);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (block.type === "custom_xml") {
|
|
122
|
+
return normalizeCustomXml(block, state, packagePartName);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (block.type === "alt_chunk") {
|
|
126
|
+
return normalizeAltChunk(block, state);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return normalizeParagraph(block, state, packagePartName);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function normalizeParagraph(
|
|
133
|
+
paragraph: ParsedParagraphNode,
|
|
134
|
+
state: NormalizationState,
|
|
135
|
+
packagePartName: string,
|
|
136
|
+
): ParagraphNode {
|
|
137
|
+
const children = normalizeInlineChildren(paragraph.children, state, packagePartName);
|
|
138
|
+
return {
|
|
139
|
+
type: "paragraph",
|
|
140
|
+
...(paragraph.styleId ? { styleId: paragraph.styleId } : {}),
|
|
141
|
+
...(paragraph.numbering ? { numbering: paragraph.numbering } : {}),
|
|
142
|
+
...(paragraph.alignment ? { alignment: paragraph.alignment } : {}),
|
|
143
|
+
...(paragraph.spacing ? { spacing: paragraph.spacing } : {}),
|
|
144
|
+
...(paragraph.indentation ? { indentation: paragraph.indentation } : {}),
|
|
145
|
+
...(paragraph.tabStops && paragraph.tabStops.length > 0 ? { tabStops: paragraph.tabStops } : {}),
|
|
146
|
+
...(paragraph.keepNext ? { keepNext: paragraph.keepNext } : {}),
|
|
147
|
+
...(paragraph.keepLines ? { keepLines: paragraph.keepLines } : {}),
|
|
148
|
+
...(paragraph.outlineLevel !== undefined ? { outlineLevel: paragraph.outlineLevel } : {}),
|
|
149
|
+
...(paragraph.pageBreakBefore ? { pageBreakBefore: paragraph.pageBreakBefore } : {}),
|
|
150
|
+
children,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function normalizeTable(
|
|
155
|
+
table: ParsedTableBlockNode,
|
|
156
|
+
state: NormalizationState,
|
|
157
|
+
packagePartName: string,
|
|
158
|
+
): TableNode {
|
|
159
|
+
const rows = table.rows.map((row) => normalizeTableRow(row, state, packagePartName));
|
|
160
|
+
state.cursor += 1;
|
|
161
|
+
return {
|
|
162
|
+
type: "table",
|
|
163
|
+
...(table.styleId ? { styleId: table.styleId } : {}),
|
|
164
|
+
...(table.propertiesXml ? { propertiesXml: table.propertiesXml } : {}),
|
|
165
|
+
gridColumns: table.gridColumns,
|
|
166
|
+
rows,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function normalizeTableRow(
|
|
171
|
+
row: ParsedTableRowNode,
|
|
172
|
+
state: NormalizationState,
|
|
173
|
+
packagePartName: string,
|
|
174
|
+
): TableRowNode {
|
|
175
|
+
const cells = row.cells.map((cell) => normalizeTableCell(cell, state, packagePartName));
|
|
176
|
+
return {
|
|
177
|
+
type: "table_row",
|
|
178
|
+
...(row.propertiesXml ? { propertiesXml: row.propertiesXml } : {}),
|
|
179
|
+
cells,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function normalizeTableCell(
|
|
184
|
+
cell: ParsedTableCellNode,
|
|
185
|
+
state: NormalizationState,
|
|
186
|
+
packagePartName: string,
|
|
187
|
+
): TableCellNode {
|
|
188
|
+
const children: BlockNode[] = [];
|
|
189
|
+
for (const block of cell.children) {
|
|
190
|
+
children.push(normalizeBlock(block, state, packagePartName));
|
|
191
|
+
}
|
|
192
|
+
// Ensure at least one child (OOXML requires at least one <w:p> per cell)
|
|
193
|
+
if (children.length === 0) {
|
|
194
|
+
children.push({ type: "paragraph", children: [] });
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
type: "table_cell",
|
|
198
|
+
...(cell.propertiesXml ? { propertiesXml: cell.propertiesXml } : {}),
|
|
199
|
+
...(cell.gridSpan ? { gridSpan: cell.gridSpan } : {}),
|
|
200
|
+
...(cell.verticalMerge ? { verticalMerge: cell.verticalMerge } : {}),
|
|
201
|
+
children,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function normalizeSdt(
|
|
206
|
+
block: ParsedSdtNode,
|
|
207
|
+
state: NormalizationState,
|
|
208
|
+
packagePartName: string,
|
|
209
|
+
): SdtNode {
|
|
210
|
+
return {
|
|
211
|
+
type: "sdt",
|
|
212
|
+
properties: { ...block.properties },
|
|
213
|
+
children: block.children.map((child) => normalizeBlock(child, state, packagePartName)),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function normalizeCustomXml(
|
|
218
|
+
block: ParsedCustomXmlNode,
|
|
219
|
+
state: NormalizationState,
|
|
220
|
+
packagePartName: string,
|
|
221
|
+
): CustomXmlNode {
|
|
222
|
+
return {
|
|
223
|
+
type: "custom_xml",
|
|
224
|
+
...(block.uri ? { uri: block.uri } : {}),
|
|
225
|
+
...(block.element ? { element: block.element } : {}),
|
|
226
|
+
children: block.children.map((child) => normalizeBlock(child, state, packagePartName)),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function normalizeAltChunk(
|
|
231
|
+
block: ParsedAltChunkNode,
|
|
232
|
+
state: NormalizationState,
|
|
233
|
+
): AltChunkNode {
|
|
234
|
+
state.cursor += 1;
|
|
235
|
+
return {
|
|
236
|
+
type: "alt_chunk",
|
|
237
|
+
relationshipId: block.relationshipId,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function normalizeInlineChildren(
|
|
242
|
+
nodes: ParsedInlineNode[],
|
|
243
|
+
state: NormalizationState,
|
|
244
|
+
packagePartName: string,
|
|
245
|
+
): InlineNode[] {
|
|
246
|
+
const normalized: InlineNode[] = [];
|
|
247
|
+
|
|
248
|
+
for (const node of nodes) {
|
|
249
|
+
switch (node.type) {
|
|
250
|
+
case "text": {
|
|
251
|
+
if (node.text.length === 0) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const previous = normalized[normalized.length - 1];
|
|
256
|
+
if (previous?.type === "text" && sameMarks(previous.marks, node.marks)) {
|
|
257
|
+
previous.text += node.text;
|
|
258
|
+
} else {
|
|
259
|
+
normalized.push({
|
|
260
|
+
type: "text",
|
|
261
|
+
text: node.text,
|
|
262
|
+
...(node.marks && node.marks.length > 0 ? { marks: node.marks } : {}),
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
state.cursor += node.text.length;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
case "tab":
|
|
269
|
+
normalized.push({ type: "tab" });
|
|
270
|
+
state.cursor += 1;
|
|
271
|
+
break;
|
|
272
|
+
case "hard_break":
|
|
273
|
+
normalized.push({ type: "hard_break" });
|
|
274
|
+
state.cursor += 1;
|
|
275
|
+
break;
|
|
276
|
+
case "image":
|
|
277
|
+
normalized.push(normalizeImageNode(node, state));
|
|
278
|
+
state.cursor += 1;
|
|
279
|
+
break;
|
|
280
|
+
case "hyperlink":
|
|
281
|
+
normalized.push(normalizeHyperlink(node));
|
|
282
|
+
state.cursor += measureHyperlink(node);
|
|
283
|
+
break;
|
|
284
|
+
case "opaque_inline": {
|
|
285
|
+
const opaque = recordOpaqueFragment("opaque_inline", node.rawXml, state, packagePartName);
|
|
286
|
+
normalized.push(opaque as OpaqueInlineNode);
|
|
287
|
+
state.cursor += 1;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return normalized;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function normalizeImageNode(
|
|
297
|
+
node: ParsedImageNode,
|
|
298
|
+
state: NormalizationState,
|
|
299
|
+
): InlineNode {
|
|
300
|
+
if (!state.media.items[node.mediaId]) {
|
|
301
|
+
const packagePartName =
|
|
302
|
+
typeof node.packagePartName === "string" && node.packagePartName.length > 0
|
|
303
|
+
? node.packagePartName
|
|
304
|
+
: `/${node.mediaId.slice("media:".length)}`;
|
|
305
|
+
const filename =
|
|
306
|
+
typeof node.filename === "string" && node.filename.length > 0
|
|
307
|
+
? node.filename
|
|
308
|
+
: packagePartName.slice(packagePartName.lastIndexOf("/") + 1) || "image.bin";
|
|
309
|
+
state.media.items[node.mediaId] = {
|
|
310
|
+
mediaId: node.mediaId,
|
|
311
|
+
contentType: node.contentType ?? "application/octet-stream",
|
|
312
|
+
filename,
|
|
313
|
+
packagePartName,
|
|
314
|
+
...(node.relationshipId ? { relationshipId: node.relationshipId } : {}),
|
|
315
|
+
...(node.altText ? { altText: node.altText } : {}),
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return {
|
|
320
|
+
type: "image",
|
|
321
|
+
mediaId: node.mediaId,
|
|
322
|
+
...(node.altText ? { altText: node.altText } : {}),
|
|
323
|
+
...(node.placementXml ? { placementXml: node.placementXml } : {}),
|
|
324
|
+
...(node.display ? { display: node.display } : {}),
|
|
325
|
+
...(node.floating ? { floating: node.floating } : {}),
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function normalizeHyperlink(node: ParsedHyperlinkNode): {
|
|
330
|
+
type: "hyperlink";
|
|
331
|
+
href: string;
|
|
332
|
+
children: Array<TextNode | { type: "hard_break" } | { type: "tab" }>;
|
|
333
|
+
} {
|
|
334
|
+
const children: Array<TextNode | { type: "hard_break" } | { type: "tab" }> = [];
|
|
335
|
+
|
|
336
|
+
for (const child of node.children) {
|
|
337
|
+
switch (child.type) {
|
|
338
|
+
case "text": {
|
|
339
|
+
if (child.text.length === 0) {
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
const previous = children[children.length - 1];
|
|
343
|
+
if (previous?.type === "text" && sameMarks(previous.marks, child.marks)) {
|
|
344
|
+
previous.text += child.text;
|
|
345
|
+
} else {
|
|
346
|
+
children.push({
|
|
347
|
+
type: "text",
|
|
348
|
+
text: child.text,
|
|
349
|
+
...(child.marks && child.marks.length > 0 ? { marks: child.marks } : {}),
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
case "tab":
|
|
355
|
+
children.push({ type: "tab" });
|
|
356
|
+
break;
|
|
357
|
+
case "hard_break":
|
|
358
|
+
children.push({ type: "hard_break" });
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return {
|
|
364
|
+
type: "hyperlink",
|
|
365
|
+
href: node.href,
|
|
366
|
+
children,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function measureHyperlink(node: ParsedHyperlinkNode): number {
|
|
371
|
+
return node.children.reduce((size, child) => {
|
|
372
|
+
switch (child.type) {
|
|
373
|
+
case "text":
|
|
374
|
+
return size + child.text.length;
|
|
375
|
+
case "tab":
|
|
376
|
+
case "hard_break":
|
|
377
|
+
return size + 1;
|
|
378
|
+
}
|
|
379
|
+
}, 0);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function sameMarks(left: TextMark[] | undefined, right: TextMark[] | undefined): boolean {
|
|
383
|
+
const leftMarks = normalizeMarks(left);
|
|
384
|
+
const rightMarks = normalizeMarks(right);
|
|
385
|
+
return leftMarks.length === rightMarks.length && leftMarks.every((mark, index) => mark === rightMarks[index]);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function normalizeMarks(marks: TextMark[] | undefined): string[] {
|
|
389
|
+
return [...(marks ?? []).map((mark) => mark.type)].sort();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function recordOpaqueFragment(
|
|
393
|
+
nodeType: "opaque_inline" | "opaque_block",
|
|
394
|
+
rawXml: string,
|
|
395
|
+
state: NormalizationState,
|
|
396
|
+
packagePartName: string,
|
|
397
|
+
): { type: "opaque_inline" | "opaque_block"; fragmentId: string; warningId: string } {
|
|
398
|
+
const fragmentId = `fragment:import-${state.nextFragmentIndex}`;
|
|
399
|
+
state.nextFragmentIndex += 1;
|
|
400
|
+
const warningId = `warning:import-${state.nextWarningIndex}`;
|
|
401
|
+
state.nextWarningIndex += 1;
|
|
402
|
+
const diagnosticId = `diagnostic:import-${state.nextDiagnosticIndex}`;
|
|
403
|
+
state.nextDiagnosticIndex += 1;
|
|
404
|
+
|
|
405
|
+
const rangeStart = state.cursor;
|
|
406
|
+
const rangeEnd = state.cursor + 1;
|
|
407
|
+
|
|
408
|
+
const record: OpaqueFragmentRecord = {
|
|
409
|
+
fragmentId,
|
|
410
|
+
payloadKind: "xml-subtree",
|
|
411
|
+
payloadReference: rawXml,
|
|
412
|
+
featureClass: "preserve-only",
|
|
413
|
+
lastKnownRange: {
|
|
414
|
+
from: rangeStart,
|
|
415
|
+
to: rangeEnd,
|
|
416
|
+
},
|
|
417
|
+
warningId,
|
|
418
|
+
packagePartName,
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
state.preservation.opaqueFragments[fragmentId] = record;
|
|
422
|
+
state.diagnostics.warnings.push({
|
|
423
|
+
diagnosticId,
|
|
424
|
+
warningId,
|
|
425
|
+
source: "import",
|
|
426
|
+
message:
|
|
427
|
+
nodeType === "opaque_inline"
|
|
428
|
+
? "Unsupported inline OOXML was preserved as an opaque placeholder."
|
|
429
|
+
: "Unsupported block OOXML was preserved as an opaque placeholder.",
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
return {
|
|
433
|
+
type: nodeType,
|
|
434
|
+
fragmentId,
|
|
435
|
+
warningId,
|
|
436
|
+
};
|
|
437
|
+
}
|