@stll/folio-core 0.66.2 → 0.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-edits/apply.js +45 -10
- package/dist/ai-edits/batch-claims.js +5 -3
- package/dist/ai-edits/clean-text.js +4 -1
- package/dist/ai-edits/read.js +6 -4
- package/dist/ai-edits/snapshot.js +24 -14
- package/dist/ai-edits/table-cell-mutations.js +3 -2
- package/dist/ai-edits/table-row-column-mutations.js +20 -6
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +76 -18
- package/dist/controller/canonicalInput.d.ts +0 -1
- package/dist/controller/canonicalInput.js +19 -1
- package/dist/controller/canonicalSession.js +1 -2
- package/dist/controller/hiddenEditorManager.d.ts +6 -0
- package/dist/controller/hiddenEditorManager.js +3 -1
- package/dist/controller/layoutPipeline.d.ts +2 -0
- package/dist/controller/layoutPipeline.js +7 -3
- package/dist/controller/layoutSession.d.ts +1 -0
- package/dist/display-list/build/tablePrimitives.d.ts +3 -1
- package/dist/display-list/build/tablePrimitives.js +29 -13
- package/dist/docx/chartPreview.d.ts +4 -1
- package/dist/docx/chartPreview.js +26 -15
- package/dist/docx/mainDocumentPart.d.ts +6 -0
- package/dist/docx/mainDocumentPart.js +65 -0
- package/dist/docx/packageParts.d.ts +1 -1
- package/dist/docx/packageParts.js +10 -4
- package/dist/docx/previewBudget.d.ts +6 -0
- package/dist/docx/previewBudget.js +7 -1
- package/dist/docx/rezip.js +4 -4
- package/dist/docx/shapeAlternateContent.js +19 -0
- package/dist/docx/unzip.js +2 -0
- package/dist/i18n/messages/ar.gen.js +1 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
- package/dist/i18n/messages/catalogs.gen.js +17 -0
- package/dist/i18n/messages/cs.gen.js +1 -0
- package/dist/i18n/messages/de.gen.js +1 -0
- package/dist/i18n/messages/en.gen.js +1 -0
- package/dist/i18n/messages/es.gen.js +1 -0
- package/dist/i18n/messages/et.gen.js +1 -0
- package/dist/i18n/messages/fr.gen.js +1 -0
- package/dist/i18n/messages/he.gen.js +1 -0
- package/dist/i18n/messages/hi.gen.js +1 -0
- package/dist/i18n/messages/hu.gen.js +1 -0
- package/dist/i18n/messages/lt.gen.js +1 -0
- package/dist/i18n/messages/lv.gen.js +1 -0
- package/dist/i18n/messages/messages.gen.d.ts +1 -0
- package/dist/i18n/messages/pl.gen.js +1 -0
- package/dist/i18n/messages/pt-BR.gen.js +1 -0
- package/dist/i18n/messages/sk.gen.js +1 -0
- package/dist/i18n/messages/tr.gen.js +1 -0
- package/dist/i18n/messages/zh-CN.gen.js +1 -0
- package/dist/internal/wholeStoryRevisionResolution.js +57 -12
- package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
- package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
- package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
- package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
- package/dist/layout-bridge/convert/tableConversion.js +6 -2
- package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
- package/dist/layout-bridge/engine/clickToPosition.js +5 -1
- package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
- package/dist/layout-engine/measure/tableCellFloating.js +1 -0
- package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
- package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
- package/dist/layout-engine/tableLayout.js +7 -4
- package/dist/layout-engine/tableRowBreak.d.ts +10 -0
- package/dist/layout-engine/tableRowBreak.js +151 -36
- package/dist/layout-engine/types.d.ts +7 -2
- package/dist/layout-painter/previewSvg.d.ts +8 -0
- package/dist/layout-painter/previewSvg.js +47 -0
- package/dist/layout-painter/renderImage.js +2 -1
- package/dist/layout-painter/renderPage.d.ts +1 -0
- package/dist/layout-painter/renderPage.js +6 -3
- package/dist/layout-painter/renderParagraph.js +3 -2
- package/dist/layout-painter/renderTable.d.ts +5 -2
- package/dist/layout-painter/renderTable.js +33 -19
- package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
- package/dist/prosemirror/commands/comments.js +20 -7
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
- package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
- package/dist/prosemirror/commands/pastePlainText.js +13 -3
- package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
- package/dist/prosemirror/commentReferenceIntegrity.d.ts +8 -2
- package/dist/prosemirror/commentReferenceIntegrity.js +19 -4
- package/dist/prosemirror/conversion/fromProseDoc.js +39 -4
- package/dist/prosemirror/conversion/toProseDoc.js +6 -4
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
- package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
- package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
- package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
- package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +87 -7
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
- package/dist/prosemirror/plugins/suggestionMode.js +175 -21
- package/dist/prosemirror/rowGridOmissions.d.ts +11 -0
- package/dist/prosemirror/rowGridOmissions.js +21 -0
- package/dist/prosemirror/tableGridMutation.d.ts +19 -2
- package/dist/prosemirror/tableGridMutation.js +118 -15
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
- package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
- package/dist/prosemirror/validation.js +1 -1
- package/package.json +2 -2
|
@@ -467,7 +467,9 @@ const createHiddenEditorManager = (deps) => {
|
|
|
467
467
|
return true;
|
|
468
468
|
},
|
|
469
469
|
endComposition: () => {
|
|
470
|
-
if (editorSession.type
|
|
470
|
+
if (editorSession.type !== "canonical") return;
|
|
471
|
+
editorSession.session.endComposition();
|
|
472
|
+
deps.onCanonicalCompositionEnd();
|
|
471
473
|
}
|
|
472
474
|
};
|
|
473
475
|
const input = createCanonicalInputBoundary({
|
|
@@ -80,5 +80,7 @@ export type LayoutPipelineDeps<THfPMs> = {
|
|
|
80
80
|
markupView: DisplayMode;
|
|
81
81
|
/** Independent highlight visibility in All Markup; resolved views always hide comments. */
|
|
82
82
|
showCommentHighlights?: boolean;
|
|
83
|
+
/** Localised text for a `w:altChunk` that has no text of its own to show. */
|
|
84
|
+
altChunkMarkerText?: string;
|
|
83
85
|
};
|
|
84
86
|
export declare function runLayoutPipeline<THfPMs>(deps: LayoutPipelineDeps<THfPMs>, state: EditorState, options?: LayoutRunOptions): LayoutOutcome;
|
|
@@ -45,7 +45,7 @@ const formatEndnoteTexts = (numbers, formatNumber) => {
|
|
|
45
45
|
for (const [id, displayNumber] of numbers) texts.set(id, formatNumber(displayNumber));
|
|
46
46
|
return texts;
|
|
47
47
|
};
|
|
48
|
-
const sameMeasureInputs = (left, right) => left.embeddedFontFamilyMap === right.embeddedFontFamilyMap && left.documentFontFactsCacheIdentity === right.documentFontFactsCacheIdentity && left.styles === right.styles && left.theme === right.theme && left.defaultTabStop === right.defaultTabStop && left.pageContentHeight === right.pageContentHeight && left.fontSet === right.fontSet && left.fontAlternates.size === right.fontAlternates.size && [...left.fontAlternates].every(([name, alternate]) => right.fontAlternates.get(name) === alternate) && left.markupView === right.markupView && left.showCommentHighlights === right.showCommentHighlights;
|
|
48
|
+
const sameMeasureInputs = (left, right) => left.embeddedFontFamilyMap === right.embeddedFontFamilyMap && left.documentFontFactsCacheIdentity === right.documentFontFactsCacheIdentity && left.styles === right.styles && left.theme === right.theme && left.defaultTabStop === right.defaultTabStop && left.pageContentHeight === right.pageContentHeight && left.fontSet === right.fontSet && left.fontAlternates.size === right.fontAlternates.size && [...left.fontAlternates].every(([name, alternate]) => right.fontAlternates.get(name) === alternate) && left.markupView === right.markupView && left.showCommentHighlights === right.showCommentHighlights && left.altChunkMarkerText === right.altChunkMarkerText;
|
|
49
49
|
/**
|
|
50
50
|
* The range an incremental pass re-measures, or `null` for a full measure: the
|
|
51
51
|
* committed measures must come from the same measure inputs, and the range is
|
|
@@ -139,7 +139,7 @@ function runLayoutPipeline(deps, state, options = {}) {
|
|
|
139
139
|
return result;
|
|
140
140
|
}
|
|
141
141
|
function runLayoutPipelineMeasured(deps, state, options) {
|
|
142
|
-
const { contentWidth, columns, pageSize, margins, pageGap, showMarginGuides, marginGuideColor, syncCoordinator, headerContent, footerContent, firstPageHeaderContent, firstPageFooterContent, headerContentRId, footerContentRId, firstPageHeaderContentRId, firstPageFooterContentRId, sectionHeaderFooterRefs, theme: _theme, sectionProperties, document, defaultTabStop, mirrorMargins, styles, layout, hfPMs, painter, pagesContainer, session, renderHfFromContentOrPm, renderHeaderFooterContentByRId, readFontSetSignature, buildFootnoteRenderItems, describeInvalidHighlightMarks, pageRenderer = PAGE_RENDERER.legacy, emptyTemplatePreviewEntries: EMPTY_TEMPLATE_PREVIEW_ENTRIES, emptyTemplatePreviewHidden: EMPTY_TEMPLATE_PREVIEW_HIDDEN, markupView, showCommentHighlights = true } = deps;
|
|
142
|
+
const { contentWidth, columns, pageSize, margins, pageGap, showMarginGuides, marginGuideColor, syncCoordinator, headerContent, footerContent, firstPageHeaderContent, firstPageFooterContent, headerContentRId, footerContentRId, firstPageHeaderContentRId, firstPageFooterContentRId, sectionHeaderFooterRefs, theme: _theme, sectionProperties, document, defaultTabStop, mirrorMargins, styles, layout, hfPMs, painter, pagesContainer, session, renderHfFromContentOrPm, renderHeaderFooterContentByRId, readFontSetSignature, buildFootnoteRenderItems, describeInvalidHighlightMarks, pageRenderer = PAGE_RENDERER.legacy, emptyTemplatePreviewEntries: EMPTY_TEMPLATE_PREVIEW_ENTRIES, emptyTemplatePreviewHidden: EMPTY_TEMPLATE_PREVIEW_HIDDEN, markupView, showCommentHighlights = true, altChunkMarkerText } = deps;
|
|
143
143
|
let outcome = {};
|
|
144
144
|
let pendingArtifacts;
|
|
145
145
|
let pendingTemplatePreview;
|
|
@@ -170,10 +170,12 @@ function runLayoutPipelineMeasured(deps, state, options) {
|
|
|
170
170
|
fontSet,
|
|
171
171
|
fontAlternates,
|
|
172
172
|
markupView,
|
|
173
|
-
showCommentHighlights: displayCommentHighlights
|
|
173
|
+
showCommentHighlights: displayCommentHighlights,
|
|
174
|
+
...altChunkMarkerText === void 0 ? {} : { altChunkMarkerText }
|
|
174
175
|
};
|
|
175
176
|
const flowOpts = {
|
|
176
177
|
showCommentHighlights: displayCommentHighlights,
|
|
178
|
+
...altChunkMarkerText === void 0 ? {} : { altChunkMarkerText },
|
|
177
179
|
...embeddedFontFamilies,
|
|
178
180
|
...documentFontFacts === void 0 ? {} : { documentFontFacts },
|
|
179
181
|
pageContentHeight,
|
|
@@ -258,6 +260,7 @@ function runLayoutPipelineMeasured(deps, state, options) {
|
|
|
258
260
|
return {
|
|
259
261
|
markupView,
|
|
260
262
|
showCommentHighlights: displayCommentHighlights,
|
|
263
|
+
...altChunkMarkerText === void 0 ? {} : { altChunkMarkerText },
|
|
261
264
|
...flowOpts.styles ? { styles: flowOpts.styles } : {},
|
|
262
265
|
...document?.package.numbering === void 0 ? {} : { numbering: document.package.numbering },
|
|
263
266
|
...flowOpts.defaultSize === void 0 ? {} : { defaultSize: flowOpts.defaultSize },
|
|
@@ -394,6 +397,7 @@ function runLayoutPipelineMeasured(deps, state, options) {
|
|
|
394
397
|
const noteOptions = {
|
|
395
398
|
measureBlocks,
|
|
396
399
|
showCommentHighlights: displayCommentHighlights,
|
|
400
|
+
...altChunkMarkerText === void 0 ? {} : { altChunkMarkerText },
|
|
397
401
|
markupView
|
|
398
402
|
};
|
|
399
403
|
if (flowOpts.styles) noteOptions.styles = flowOpts.styles;
|
|
@@ -37,6 +37,7 @@ export type LayoutMeasureInputs = {
|
|
|
37
37
|
/** The review view: each lays out different text, so a measure is reusable only within one. */
|
|
38
38
|
markupView: DisplayMode;
|
|
39
39
|
showCommentHighlights?: boolean;
|
|
40
|
+
altChunkMarkerText?: string;
|
|
40
41
|
};
|
|
41
42
|
export type LayoutSession = {
|
|
42
43
|
embeddedFontFamilyMap?: ReadonlyMap<string, string>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TableBlock, TableFragment, TableMeasure, TextBoxBlock, TextBoxFragment, TextBoxMeasure } from "../../layout-engine/types.js";
|
|
2
|
+
import { VisibleBand } from "../../layout-engine/measure/tableVisibleBand.js";
|
|
2
3
|
import { BuildContext } from "./buildContext.js";
|
|
3
4
|
import { PageComposer } from "./regions.js";
|
|
4
5
|
type PaintTextBox = (options: {
|
|
@@ -16,9 +17,10 @@ export type TableBlockPaintOptions = {
|
|
|
16
17
|
readonly yPx: number;
|
|
17
18
|
readonly context: BuildContext;
|
|
18
19
|
readonly paintTextBox: PaintTextBox;
|
|
20
|
+
readonly visibleBand?: VisibleBand | undefined;
|
|
19
21
|
};
|
|
20
22
|
/** A whole, unpaginated table: what a nested table inside a cell or box is. */
|
|
21
|
-
export declare const paintTableBlock: ({ composer, block, measure, xPx, yPx, context, paintTextBox }: TableBlockPaintOptions) => void;
|
|
23
|
+
export declare const paintTableBlock: ({ composer, block, measure, xPx, yPx, context, paintTextBox, visibleBand }: TableBlockPaintOptions) => void;
|
|
22
24
|
export type TablePaintOptions = {
|
|
23
25
|
readonly composer: PageComposer;
|
|
24
26
|
readonly fragment: TableFragment;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createTableCellFlowState, placeTableCellBlock } from "../../layout-engine/measure/tableCellFlow.js";
|
|
2
2
|
import { buildTableCellGrid, buildTableCellPlacements, getSourceCellAt, getTableCellSpacingInsetsY } from "../../layout-engine/measure/tableCellGrid.js";
|
|
3
3
|
import { tableFragmentBottomBorders } from "../../layout-engine/measure/tableFragmentBorderGeometry.js";
|
|
4
|
+
import { isOutsideBand, tableHasFloatingCellContent, tableRowPaintBottom } from "../../layout-engine/measure/tableVisibleBand.js";
|
|
4
5
|
import { resolveTableCellPadding } from "../../layout-engine/types.js";
|
|
5
6
|
import { cellTextRotationDegrees } from "../../layout-painter/renderTable.js";
|
|
6
7
|
import { paintsCssBorder } from "../../utils/borderCss.js";
|
|
@@ -35,7 +36,7 @@ const strokeFor = (border, context, label) => {
|
|
|
35
36
|
if (unresolvedColor !== void 0) context.unsupported.report(UNSUPPORTED_CONSTRUCT.unresolvedColor, context.pageIndex, `${label} colour ${unresolvedColor}`);
|
|
36
37
|
return stroke;
|
|
37
38
|
};
|
|
38
|
-
const paintCell = ({ composer, cell, cellMeasure, box, context, paintTextBox, sides }) => {
|
|
39
|
+
const paintCell = ({ composer, cell, cellMeasure, box, context, paintTextBox, visibleBand, sides }) => {
|
|
39
40
|
const primitives = [];
|
|
40
41
|
if (cell.background) {
|
|
41
42
|
const fill = parseDisplayColor(cell.background);
|
|
@@ -119,7 +120,8 @@ const paintCell = ({ composer, cell, cellMeasure, box, context, paintTextBox, si
|
|
|
119
120
|
widthPx: contentWidthPx,
|
|
120
121
|
inlinePictureViewport: cellPictureViewport,
|
|
121
122
|
context,
|
|
122
|
-
paintTextBox
|
|
123
|
+
paintTextBox,
|
|
124
|
+
visibleBand
|
|
123
125
|
});
|
|
124
126
|
const diagonals = [{
|
|
125
127
|
border: borders?.topLeftToBottomRight,
|
|
@@ -146,7 +148,7 @@ const paintCell = ({ composer, cell, cellMeasure, box, context, paintTextBox, si
|
|
|
146
148
|
* A cell's inner blocks, stacked by the same flow state the measurer used, so
|
|
147
149
|
* paragraph spacing collapses in paint exactly where it collapsed in layout.
|
|
148
150
|
*/
|
|
149
|
-
const paintCellBlocks = ({ composer, blocks, measures, xPx, yPx, widthPx, inlinePictureViewport, context, paintTextBox }) => {
|
|
151
|
+
const paintCellBlocks = ({ composer, blocks, measures, xPx, yPx, widthPx, inlinePictureViewport, context, paintTextBox, visibleBand }) => {
|
|
150
152
|
const flowState = createTableCellFlowState();
|
|
151
153
|
for (let index = 0; index < blocks.length; index += 1) {
|
|
152
154
|
const block = blocks[index];
|
|
@@ -156,6 +158,7 @@ const paintCellBlocks = ({ composer, blocks, measures, xPx, yPx, widthPx, inline
|
|
|
156
158
|
continue;
|
|
157
159
|
}
|
|
158
160
|
const placement = placeTableCellBlock(flowState, block, measure);
|
|
161
|
+
if (block.kind === "table" && isOutsideBand(visibleBand, yPx + placement.top, yPx + placement.contentTop + placement.contentHeight)) continue;
|
|
159
162
|
if (block.kind === "paragraph" && measure.kind === "paragraph") {
|
|
160
163
|
const previous = blocks[index - 1];
|
|
161
164
|
const next = blocks[index + 1];
|
|
@@ -210,7 +213,8 @@ const paintCellBlocks = ({ composer, blocks, measures, xPx, yPx, widthPx, inline
|
|
|
210
213
|
...context,
|
|
211
214
|
inlinePictureViewport
|
|
212
215
|
},
|
|
213
|
-
paintTextBox
|
|
216
|
+
paintTextBox,
|
|
217
|
+
visibleBand
|
|
214
218
|
});
|
|
215
219
|
});
|
|
216
220
|
continue;
|
|
@@ -261,7 +265,7 @@ const paintCellBlocks = ({ composer, blocks, measures, xPx, yPx, widthPx, inline
|
|
|
261
265
|
}
|
|
262
266
|
};
|
|
263
267
|
const rowIsPainted = (row) => row !== void 0 && row.hidden !== true;
|
|
264
|
-
const paintTableBody = ({ composer, block, measure, xPx, yPx, fromRow, toRow, headerRowCount, context, paintTextBox }) => {
|
|
268
|
+
const paintTableBody = ({ composer, block, measure, xPx, yPx, fromRow, toRow, headerRowCount, context, paintTextBox, visibleBand }) => {
|
|
265
269
|
const grid = buildTableCellGrid(block.rows, measure.columnWidths.length);
|
|
266
270
|
const placements = buildTableCellPlacements({
|
|
267
271
|
grid,
|
|
@@ -272,10 +276,14 @@ const paintTableBody = ({ composer, block, measure, xPx, yPx, fromRow, toRow, he
|
|
|
272
276
|
const bordersSeparated = (block.cellSpacing ?? 0) > 0;
|
|
273
277
|
const rowTops = [0];
|
|
274
278
|
for (const rowMeasure of measure.rows) rowTops.push((rowTops.at(-1) ?? 0) + rowMeasure.height);
|
|
279
|
+
let firstShownRow;
|
|
275
280
|
const paintRow = (rowIndex, rowYPx) => {
|
|
276
281
|
const row = block.rows[rowIndex];
|
|
277
282
|
const rowMeasure = measure.rows[rowIndex];
|
|
278
283
|
if (!rowIsPainted(row) || !rowMeasure) return;
|
|
284
|
+
const rowTop = rowTops[rowIndex] ?? 0;
|
|
285
|
+
if (isOutsideBand(visibleBand, rowYPx, rowYPx + tableRowPaintBottom(row, rowIndex, rowTops) - rowTop)) return;
|
|
286
|
+
firstShownRow ??= rowIndex;
|
|
279
287
|
composer.region({
|
|
280
288
|
kind: HIT_REGION_KINDS.tableRow,
|
|
281
289
|
rect: {
|
|
@@ -290,6 +298,7 @@ const paintTableBody = ({ composer, block, measure, xPx, yPx, fromRow, toRow, he
|
|
|
290
298
|
});
|
|
291
299
|
};
|
|
292
300
|
const paintRowCells = (row, rowMeasure, rowIndex, rowYPx) => {
|
|
301
|
+
const opensContinuation = visibleBand !== void 0 && rowIndex === firstShownRow && rowYPx >= visibleBand.top;
|
|
293
302
|
for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
|
|
294
303
|
const cell = row.cells[cellIndex];
|
|
295
304
|
const cellMeasure = rowMeasure.cells[cellIndex];
|
|
@@ -328,8 +337,9 @@ const paintTableBody = ({ composer, block, measure, xPx, yPx, fromRow, toRow, he
|
|
|
328
337
|
box,
|
|
329
338
|
context,
|
|
330
339
|
paintTextBox,
|
|
340
|
+
visibleBand,
|
|
331
341
|
sides: {
|
|
332
|
-
top: bordersSeparated || rowIndex === fromRow || !hasVisibleBorder(aboveCell?.borders?.bottom),
|
|
342
|
+
top: bordersSeparated || rowIndex === fromRow || opensContinuation || !hasVisibleBorder(aboveCell?.borders?.bottom),
|
|
333
343
|
bottom: true,
|
|
334
344
|
left: bordersSeparated || isFirstColumn || !hasVisibleBorder(leftCell?.borders?.right),
|
|
335
345
|
right: true
|
|
@@ -375,7 +385,7 @@ const paintFragmentBottomBorders = ({ composer, fragment, block, measure, contex
|
|
|
375
385
|
composer.push(primitives);
|
|
376
386
|
};
|
|
377
387
|
/** A whole, unpaginated table: what a nested table inside a cell or box is. */
|
|
378
|
-
const paintTableBlock = ({ composer, block, measure, xPx, yPx, context, paintTextBox }) => paintTableBody({
|
|
388
|
+
const paintTableBlock = ({ composer, block, measure, xPx, yPx, context, paintTextBox, visibleBand }) => paintTableBody({
|
|
379
389
|
composer,
|
|
380
390
|
block,
|
|
381
391
|
measure,
|
|
@@ -385,7 +395,8 @@ const paintTableBlock = ({ composer, block, measure, xPx, yPx, context, paintTex
|
|
|
385
395
|
toRow: block.rows.length,
|
|
386
396
|
headerRowCount: 0,
|
|
387
397
|
context,
|
|
388
|
-
paintTextBox
|
|
398
|
+
paintTextBox,
|
|
399
|
+
visibleBand
|
|
389
400
|
});
|
|
390
401
|
/**
|
|
391
402
|
* A table fragment's primitives. A fragment that cuts a row mid-content wraps
|
|
@@ -408,11 +419,12 @@ const paintTableFragment = ({ composer, fragment, block, measure, context, paint
|
|
|
408
419
|
toRow: 0,
|
|
409
420
|
headerRowCount,
|
|
410
421
|
context,
|
|
411
|
-
paintTextBox
|
|
422
|
+
paintTextBox,
|
|
423
|
+
visibleBand: void 0
|
|
412
424
|
});
|
|
413
425
|
};
|
|
414
426
|
const topClipPx = fragment.topClip ?? 0;
|
|
415
|
-
const paintBody = (into) => {
|
|
427
|
+
const paintBody = (into, visibleBand) => {
|
|
416
428
|
paintTableBody({
|
|
417
429
|
composer: into,
|
|
418
430
|
block,
|
|
@@ -423,7 +435,8 @@ const paintTableFragment = ({ composer, fragment, block, measure, context, paint
|
|
|
423
435
|
toRow: fragment.toRow,
|
|
424
436
|
headerRowCount: 0,
|
|
425
437
|
context,
|
|
426
|
-
paintTextBox
|
|
438
|
+
paintTextBox,
|
|
439
|
+
visibleBand
|
|
427
440
|
});
|
|
428
441
|
};
|
|
429
442
|
if (fragment.topClip === void 0 && fragment.bottomClip === void 0) {
|
|
@@ -432,14 +445,17 @@ const paintTableFragment = ({ composer, fragment, block, measure, context, paint
|
|
|
432
445
|
return;
|
|
433
446
|
}
|
|
434
447
|
paintHeaders(composer);
|
|
435
|
-
const clipped = createPageComposer();
|
|
436
|
-
paintBody(clipped);
|
|
437
448
|
const clip = {
|
|
438
449
|
xPx: fragment.x,
|
|
439
450
|
yPx: fragment.y + headerHeightPx,
|
|
440
451
|
widthPx: fragment.width,
|
|
441
452
|
heightPx: Math.max(0, fragment.height - headerHeightPx)
|
|
442
453
|
};
|
|
454
|
+
const clipped = createPageComposer();
|
|
455
|
+
paintBody(clipped, tableHasFloatingCellContent(block) ? void 0 : {
|
|
456
|
+
top: clip.yPx,
|
|
457
|
+
bottom: clip.yPx + clip.heightPx
|
|
458
|
+
});
|
|
443
459
|
composer.push([{
|
|
444
460
|
kind: "clipGroup",
|
|
445
461
|
rect: clip,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
2
|
import { XmlElement } from "./xmlParser.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Describe a chart: the marks of a supported cached chart, or an empty frame of
|
|
5
|
+
* the same size. AlternateContent fallbacks are resolved by the run parser.
|
|
6
|
+
*/
|
|
4
7
|
export declare const parseChartPreview: (drawing: XmlElement, rels?: document_d_exports.RelationshipMap, media?: Map<string, document_d_exports.MediaFile>) => document_d_exports.Image | null;
|
|
@@ -257,12 +257,33 @@ const chartPart = (drawing, rels, media) => {
|
|
|
257
257
|
path
|
|
258
258
|
} : null;
|
|
259
259
|
};
|
|
260
|
-
/**
|
|
260
|
+
/**
|
|
261
|
+
* Describe a chart: the marks of a supported cached chart, or an empty frame of
|
|
262
|
+
* the same size. AlternateContent fallbacks are resolved by the run parser.
|
|
263
|
+
*/
|
|
261
264
|
const parseChartPreview = (drawing, rels, media) => {
|
|
265
|
+
const size = extentOf(drawing);
|
|
266
|
+
if (!isChartDrawing(drawing) || size.width <= 0 || size.height <= 0) return null;
|
|
267
|
+
return {
|
|
268
|
+
type: "image",
|
|
269
|
+
preview: {
|
|
270
|
+
kind: "chart",
|
|
271
|
+
extent: size,
|
|
272
|
+
shapes: chartMarks(drawing, size, rels, media) ?? []
|
|
273
|
+
},
|
|
274
|
+
size,
|
|
275
|
+
wrap: { type: "inline" }
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
const isChartDrawing = (drawing) => {
|
|
279
|
+
const graphicData = firstDescendant(drawing, DRAWINGML, "graphicData");
|
|
280
|
+
return graphicData !== null && CHART.has(getAttribute(graphicData, null, "uri") ?? "") && firstDescendant(graphicData, CHART, "chart") !== null;
|
|
281
|
+
};
|
|
282
|
+
/** The marks a chart's cached data draws, or null when it cannot draw them. */
|
|
283
|
+
const chartMarks = (drawing, size, rels, media) => {
|
|
262
284
|
if (!rels || !media) return null;
|
|
263
285
|
const part = chartPart(drawing, rels, media);
|
|
264
|
-
|
|
265
|
-
if (!part || size.width <= 0 || size.height <= 0) return null;
|
|
286
|
+
if (!part) return null;
|
|
266
287
|
const plotArea = firstDescendant(part.root, CHART, "plotArea");
|
|
267
288
|
if (!plotArea) return null;
|
|
268
289
|
const supported = getChildElements(plotArea).find((item) => [
|
|
@@ -281,21 +302,11 @@ const parseChartPreview = (drawing, rels, media) => {
|
|
|
281
302
|
else shapes = pieShapes(supported, series, size.width, size.height, kind === "doughnutChart");
|
|
282
303
|
if (shapes.length === 0) return null;
|
|
283
304
|
if (shapes.reduce((total, shape) => total + (shape.type === "polygon" || shape.type === "polyline" ? shape.points.length : 0), 0) > 512) return null;
|
|
284
|
-
|
|
305
|
+
return shapes.every((shape) => shape.type === "polygon" || shape.type === "polyline" ? shape.points.every(({ x, y }) => Number.isFinite(x) && Number.isFinite(y)) : [
|
|
285
306
|
shape.x,
|
|
286
307
|
shape.y,
|
|
287
308
|
shape.width,
|
|
288
309
|
shape.height
|
|
289
|
-
].every(Number.isFinite))
|
|
290
|
-
return {
|
|
291
|
-
type: "image",
|
|
292
|
-
preview: {
|
|
293
|
-
kind: "chart",
|
|
294
|
-
extent: size,
|
|
295
|
-
shapes
|
|
296
|
-
},
|
|
297
|
-
size,
|
|
298
|
-
wrap: { type: "inline" }
|
|
299
|
-
};
|
|
310
|
+
].every(Number.isFinite)) ? shapes : null;
|
|
300
311
|
};
|
|
301
312
|
export { parseChartPreview };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ZipArchive } from "@stll/docx-core/zip";
|
|
2
|
+
/**
|
|
3
|
+
* Moves the main document to the standard path. Returns whether it moved.
|
|
4
|
+
* What is not a word processing main part, a theme package say, stays put.
|
|
5
|
+
*/
|
|
6
|
+
export declare const moveMainDocumentToStandardPath: (zip: ZipArchive) => Promise<boolean>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { resolvePackageRelationshipTarget } from "./packageParts.js";
|
|
2
|
+
// src/docx/mainDocumentPart.ts
|
|
3
|
+
const STANDARD_PATH = "word/document.xml";
|
|
4
|
+
const STANDARD_RELATIONSHIPS_PATH = "word/_rels/document.xml.rels";
|
|
5
|
+
const PACKAGE_RELATIONSHIPS_PATH = "_rels/.rels";
|
|
6
|
+
const CONTENT_TYPES_PATH = "[content_types].xml";
|
|
7
|
+
const OFFICE_DOCUMENT_TYPE = /\/officeDocument["']/u;
|
|
8
|
+
const WORD_MAIN_CONTENT_TYPE = /wordprocessingml\.[a-z.]*main\+xml/iu;
|
|
9
|
+
const entryNamed = (zip, lowerPath) => zip.paths().find((path) => path.toLowerCase() === lowerPath);
|
|
10
|
+
const relationshipsPathOf = (part) => {
|
|
11
|
+
const slash = part.lastIndexOf("/");
|
|
12
|
+
return `${part.slice(0, slash + 1)}_rels/${part.slice(slash + 1)}.rels`;
|
|
13
|
+
};
|
|
14
|
+
/** A relationship's relative target as an absolute part name. */
|
|
15
|
+
const absolutePartPath = (directory, relative) => {
|
|
16
|
+
const segments = [];
|
|
17
|
+
for (const segment of `${directory}${relative}`.split("/")) if (segment === "..") segments.pop();
|
|
18
|
+
else if (segment !== "" && segment !== ".") segments.push(segment);
|
|
19
|
+
return `/${segments.join("/")}`;
|
|
20
|
+
};
|
|
21
|
+
const escapeForRegExp = (text) => text.replaceAll(/[.*+?^${}()|[\]\\]/gu, String.raw`\$&`);
|
|
22
|
+
const targetOf = (element) => /\bTarget\s*=\s*["']([^"']+)["']/u.exec(element)?.[1] ?? null;
|
|
23
|
+
/**
|
|
24
|
+
* Moves the main document to the standard path. Returns whether it moved.
|
|
25
|
+
* What is not a word processing main part, a theme package say, stays put.
|
|
26
|
+
*/
|
|
27
|
+
const moveMainDocumentToStandardPath = async (zip) => {
|
|
28
|
+
const packagePath = entryNamed(zip, PACKAGE_RELATIONSHIPS_PATH);
|
|
29
|
+
const contentTypesPath = entryNamed(zip, CONTENT_TYPES_PATH);
|
|
30
|
+
if (packagePath === void 0 || contentTypesPath === void 0) return false;
|
|
31
|
+
const packageXml = await zip.entry(packagePath)?.text();
|
|
32
|
+
const contentTypes = await zip.entry(contentTypesPath)?.text();
|
|
33
|
+
if (packageXml === void 0 || contentTypes === void 0) return false;
|
|
34
|
+
const relationship = [...packageXml.matchAll(/<(?:\w+:)?Relationship\b[^>]*>/gu)].map(([element]) => element).find((element) => OFFICE_DOCUMENT_TYPE.test(element));
|
|
35
|
+
const target = relationship && targetOf(relationship);
|
|
36
|
+
if (!relationship || !target) return false;
|
|
37
|
+
const lowerPath = resolvePackageRelationshipTarget(target, PACKAGE_RELATIONSHIPS_PATH);
|
|
38
|
+
if (lowerPath === void 0 || lowerPath === STANDARD_PATH) return false;
|
|
39
|
+
const part = entryNamed(zip, lowerPath);
|
|
40
|
+
if (part === void 0) return false;
|
|
41
|
+
const override = new RegExp(String.raw`<(?:\w+:)?Override\b[^>]*PartName\s*=\s*["']/${escapeForRegExp(part)}["'][^>]*>`, "iu");
|
|
42
|
+
const declared = override.exec(contentTypes)?.[0];
|
|
43
|
+
if (declared === void 0 || !WORD_MAIN_CONTENT_TYPE.test(declared)) return false;
|
|
44
|
+
const bytes = await zip.entry(part)?.bytes();
|
|
45
|
+
if (bytes === void 0) return false;
|
|
46
|
+
const relationshipsPath = entryNamed(zip, relationshipsPathOf(part).toLowerCase());
|
|
47
|
+
const relationships = relationshipsPath === void 0 ? void 0 : await zip.entry(relationshipsPath)?.text();
|
|
48
|
+
const directory = part.slice(0, part.lastIndexOf("/") + 1);
|
|
49
|
+
const anchored = relationships === void 0 || directory === "word/" ? relationships : relationships.replaceAll(/<(?:\w+:)?Relationship\b[^>]*>/gu, (element) => /TargetMode\s*=\s*["']External["']/iu.test(element) ? element : element.replace(/\bTarget\s*=\s*(["'])(?!\/)([^"']+)\1/u, (_match, quote, relative) => {
|
|
50
|
+
return `Target=${quote}${absolutePartPath(directory, relative)}${quote}`;
|
|
51
|
+
}));
|
|
52
|
+
zip.delete(part);
|
|
53
|
+
if (relationshipsPath !== void 0) zip.delete(relationshipsPath);
|
|
54
|
+
const replaced = entryNamed(zip, STANDARD_PATH);
|
|
55
|
+
if (replaced !== void 0) zip.delete(replaced);
|
|
56
|
+
const replacedRelationships = entryNamed(zip, STANDARD_RELATIONSHIPS_PATH);
|
|
57
|
+
if (replacedRelationships !== void 0) zip.delete(replacedRelationships);
|
|
58
|
+
zip.set(STANDARD_PATH, bytes);
|
|
59
|
+
if (anchored !== void 0) zip.set(STANDARD_RELATIONSHIPS_PATH, anchored);
|
|
60
|
+
zip.set(packagePath, packageXml.replace(relationship, relationship.replace(/\bTarget\s*=\s*(["'])[^"']+\1/u, `Target="${STANDARD_PATH}"`)));
|
|
61
|
+
const standardOverride = new RegExp(String.raw`<(?:\w+:)?Override\b[^>]*PartName\s*=\s*["']/${escapeForRegExp(STANDARD_PATH)}["'][^>]*>`, "iu");
|
|
62
|
+
zip.set(contentTypesPath, contentTypes.replace(standardOverride, "").replace(override, declared.replace(/PartName\s*=\s*(["'])[^"']+\1/u, `PartName="/${STANDARD_PATH}"`)));
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
export { moveMainDocumentToStandardPath };
|
|
@@ -41,7 +41,7 @@ export type PackageReferenceRepair = {
|
|
|
41
41
|
* already-reconciled package therefore reports nothing and changes nothing,
|
|
42
42
|
* which is what the repack tests assert about their own output.
|
|
43
43
|
*/
|
|
44
|
-
export declare const reconcilePackageReferences: (zip: ZipArchive, compressionLevel: number) => Promise<PackageReferenceRepair>;
|
|
44
|
+
export declare const reconcilePackageReferences: (zip: ZipArchive, compressionLevel: number, source?: ZipArchive) => Promise<PackageReferenceRepair>;
|
|
45
45
|
/**
|
|
46
46
|
* What {@link checkPackageIntegrity} found wrong with a package. Both fields
|
|
47
47
|
* are empty for a package where every internal relationship resolves and
|
|
@@ -102,7 +102,11 @@ const removeUnsafeEntries = (zip) => {
|
|
|
102
102
|
};
|
|
103
103
|
const presentPartPaths = (zip) => {
|
|
104
104
|
const present = /* @__PURE__ */ new Set();
|
|
105
|
-
for (const path of zip.paths())
|
|
105
|
+
for (const path of zip.paths()) {
|
|
106
|
+
present.add(normalizePartPath(path));
|
|
107
|
+
const decoded = decodePartName(path);
|
|
108
|
+
if (decoded !== void 0) present.add(normalizePartPath(decoded));
|
|
109
|
+
}
|
|
106
110
|
return present;
|
|
107
111
|
};
|
|
108
112
|
const isPresent = (present, partPath) => present.has(normalizePartPath(partPath)) || present.has(normalizePartPath(decodePartName(partPath) ?? ""));
|
|
@@ -143,8 +147,10 @@ const writePart = ({ zip, path, xml, compressionLevel }) => {
|
|
|
143
147
|
* already-reconciled package therefore reports nothing and changes nothing,
|
|
144
148
|
* which is what the repack tests assert about their own output.
|
|
145
149
|
*/
|
|
146
|
-
const reconcilePackageReferences = async (zip, compressionLevel) => {
|
|
150
|
+
const reconcilePackageReferences = async (zip, compressionLevel, source) => {
|
|
147
151
|
const present = presentPartPaths(zip);
|
|
152
|
+
const sourceParts = source ? presentPartPaths(source) : null;
|
|
153
|
+
const danglingInSource = (partPath) => sourceParts !== null && partPath !== "" && !isPresent(sourceParts, partPath);
|
|
148
154
|
const repair = {
|
|
149
155
|
danglingRelationships: [],
|
|
150
156
|
danglingOverrides: [],
|
|
@@ -155,7 +161,7 @@ const reconcilePackageReferences = async (zip, compressionLevel) => {
|
|
|
155
161
|
let dropped = false;
|
|
156
162
|
const pruned = xml.replaceAll(RELATIONSHIP_ELEMENT, (element) => {
|
|
157
163
|
const target = relationshipTarget(element, path);
|
|
158
|
-
if (target === null || present
|
|
164
|
+
if (target === null || isPresent(present, target) || danglingInSource(target)) return element;
|
|
159
165
|
repair.danglingRelationships.push(target || TARGET_ATTRIBUTE.exec(element)?.groups?.["value"] || "");
|
|
160
166
|
dropped = true;
|
|
161
167
|
const id = RELATIONSHIP_ID_ATTRIBUTE.exec(element)?.groups?.["value"];
|
|
@@ -201,7 +207,7 @@ const reconcilePackageReferences = async (zip, compressionLevel) => {
|
|
|
201
207
|
let droppedOverride = false;
|
|
202
208
|
const prunedContentTypes = (await contentTypes.bytes().then((bytes) => decodeText(bytes, { ignoreBOM: true }))).replaceAll(CONTENT_TYPE_ELEMENT, (element) => {
|
|
203
209
|
const partName = PART_NAME_ATTRIBUTE.exec(element)?.groups?.["value"];
|
|
204
|
-
if (partName === void 0 || isPresent(present, partName)) return element;
|
|
210
|
+
if (partName === void 0 || isPresent(present, partName) || danglingInSource(partName)) return element;
|
|
205
211
|
repair.danglingOverrides.push(normalizePartPath(decodePartName(partName) ?? partName));
|
|
206
212
|
droppedOverride = true;
|
|
207
213
|
return "";
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
2
|
type PreviewKindName = "vmlShape" | "wpGroup" | "smartArt";
|
|
3
|
+
/**
|
|
4
|
+
* A drawn preview as an `<img>` source. It is derived from a descriptor the
|
|
5
|
+
* ledger already charged and held only while a painter uses it, so it is not a
|
|
6
|
+
* second retained preview.
|
|
7
|
+
*/
|
|
8
|
+
export declare const svgPreviewDataUrl: (svg: string) => string;
|
|
3
9
|
declare const PREVIEW_KINDS: {
|
|
4
10
|
/** A VML shape folio renders rather than projects (`v:shape`, `v:rect`, ...). */
|
|
5
11
|
readonly vmlShape: {
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
/** Both SVG producers encode their drawing into the URL rather than base64. */
|
|
3
3
|
const SVG_PREVIEW_DATA_URL_PREFIX = "data:image/svg+xml;charset=utf-8,";
|
|
4
4
|
/**
|
|
5
|
+
* A drawn preview as an `<img>` source. It is derived from a descriptor the
|
|
6
|
+
* ledger already charged and held only while a painter uses it, so it is not a
|
|
7
|
+
* second retained preview.
|
|
8
|
+
*/
|
|
9
|
+
const svgPreviewDataUrl = (svg) => `${SVG_PREVIEW_DATA_URL_PREFIX}${encodeURIComponent(svg)}`;
|
|
10
|
+
/**
|
|
5
11
|
* Eight times what a producer may spend on one drawing, which is a package
|
|
6
12
|
* holding a handful of the largest previews folio will build.
|
|
7
13
|
*/
|
|
@@ -109,4 +115,4 @@ const createPackagePreviewBudget = () => {
|
|
|
109
115
|
* whose previews no package budget charges.
|
|
110
116
|
*/
|
|
111
117
|
const standalonePreviewLedger = () => createPackagePreviewBudget().ledger;
|
|
112
|
-
export { createPackagePreviewBudget, standalonePreviewLedger };
|
|
118
|
+
export { createPackagePreviewBudget, standalonePreviewLedger, svgPreviewDataUrl };
|
package/dist/docx/rezip.js
CHANGED
|
@@ -698,8 +698,8 @@ const normalizePackageOnSave = async (zip, compressionLevel) => {
|
|
|
698
698
|
* at each caller so no save path can emit a package whose relationships or
|
|
699
699
|
* content types name a part it does not hold.
|
|
700
700
|
*/
|
|
701
|
-
const generateDocxZip = async (zip, compressionLevel) => {
|
|
702
|
-
await reconcilePackageReferences(zip, compressionLevel);
|
|
701
|
+
const generateDocxZip = async (zip, compressionLevel, source) => {
|
|
702
|
+
await reconcilePackageReferences(zip, compressionLevel, source);
|
|
703
703
|
await normalizePackageOnSave(zip, compressionLevel);
|
|
704
704
|
return zip.generate({ level: compressionLevel }).then((bytes) => bytes.buffer);
|
|
705
705
|
};
|
|
@@ -829,7 +829,7 @@ const finishRepack = async ({ document: sourceDocument, originalZip, outputZip,
|
|
|
829
829
|
});
|
|
830
830
|
outputZip.set("docProps/core.xml", updatedCoreProperties, { level: compressionLevel });
|
|
831
831
|
}
|
|
832
|
-
return generateDocxZip(outputZip, compressionLevel);
|
|
832
|
+
return generateDocxZip(outputZip, compressionLevel, originalZip);
|
|
833
833
|
};
|
|
834
834
|
async function repackDocxWithSectionEndpointRemoval({ document: doc, options, sectionEndpointRemoval, sectionReferenceRemovals }) {
|
|
835
835
|
if (!doc.originalBuffer) panic("Cannot repack document: no original buffer for round-trip. Use createDocx() for new documents.");
|
|
@@ -937,7 +937,7 @@ async function repackDocxFromRaw(doc, rawContent, options = {}) {
|
|
|
937
937
|
});
|
|
938
938
|
newZip.set("docProps/core.xml", updatedCoreProps, { level: compressionLevel });
|
|
939
939
|
}
|
|
940
|
-
return generateDocxZip(newZip, compressionLevel);
|
|
940
|
+
return generateDocxZip(newZip, compressionLevel, rawContent.originalZip);
|
|
941
941
|
}
|
|
942
942
|
const COMMENTS_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml";
|
|
943
943
|
const COMMENTS_EXTENDED_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml";
|
|
@@ -62,6 +62,23 @@ const descendantsNamed = ({ root, namespaceUris, localName }) => {
|
|
|
62
62
|
return result;
|
|
63
63
|
};
|
|
64
64
|
const branchNamed = (root, localName) => getChildElements(root).find((child) => getNamespaceUri(child) === NAMESPACES.mc && getLocalName(child.name ?? "") === localName);
|
|
65
|
+
/**
|
|
66
|
+
* The freshly written body leans on its document's root for prefixes such as
|
|
67
|
+
* `w14`, which a captured alternate content does not declare for itself.
|
|
68
|
+
*/
|
|
69
|
+
const namespaceDeclarationsFor = (body) => {
|
|
70
|
+
const declarations = {};
|
|
71
|
+
const visit = (element) => {
|
|
72
|
+
for (const name of [element.name ?? "", ...Object.keys(element.attributes ?? {})]) {
|
|
73
|
+
const prefix = getNamespacePrefix(name);
|
|
74
|
+
const uri = prefix !== null && Object.hasOwn(NAMESPACES, prefix) ? NAMESPACES[prefix] : void 0;
|
|
75
|
+
if (prefix !== "xmlns" && uri !== void 0) declarations[`xmlns:${prefix}`] = uri;
|
|
76
|
+
}
|
|
77
|
+
for (const child of element.elements ?? []) visit(child);
|
|
78
|
+
};
|
|
79
|
+
visit(body);
|
|
80
|
+
return declarations;
|
|
81
|
+
};
|
|
65
82
|
const updateAlternateContentText = (capturedXml, drawingXml) => {
|
|
66
83
|
assertXmlResourceLimits({ xml: capturedXml });
|
|
67
84
|
assertXmlResourceLimits({ xml: drawingXml });
|
|
@@ -93,9 +110,11 @@ const updateAlternateContentText = (capturedXml, drawingXml) => {
|
|
|
93
110
|
const qualifiedName = drawingBody.name ?? "txbxContent";
|
|
94
111
|
const prefix = getNamespacePrefix(qualifiedName);
|
|
95
112
|
const declaration = prefix === null ? "xmlns" : `xmlns:${prefix}`;
|
|
113
|
+
const declarations = namespaceDeclarationsFor(drawingBody);
|
|
96
114
|
for (const body of [choiceBody, fallbackBody]) {
|
|
97
115
|
body.name = qualifiedName;
|
|
98
116
|
body.attributes = {
|
|
117
|
+
...declarations,
|
|
99
118
|
...body.attributes,
|
|
100
119
|
[declaration]: NAMESPACES.w
|
|
101
120
|
};
|
package/dist/docx/unzip.js
CHANGED
|
@@ -2,6 +2,7 @@ import { bytesToDataUrl } from "../utils/base64.js";
|
|
|
2
2
|
import { DOCX_COMPRESSION_RATIO_GRACE_BYTES, isRatioBoundedPart } from "./archiveInflation.js";
|
|
3
3
|
import { DOCX_CONTAINER_TYPES, detectDocxContainerType } from "./encryption/containerFormat.js";
|
|
4
4
|
import { openDocxBuffer } from "./encryption/openEncryptedDocx.js";
|
|
5
|
+
import { moveMainDocumentToStandardPath } from "./mainDocumentPart.js";
|
|
5
6
|
import { RASTER_MIME_TYPES, detectRasterMimeType } from "./rasterMime.js";
|
|
6
7
|
import { decodeXmlBytes } from "./xmlEncoding.js";
|
|
7
8
|
import { Result } from "better-result";
|
|
@@ -116,6 +117,7 @@ async function unzipDocx(buffer, options = {}, { verifyUnreadEntries = true } =
|
|
|
116
117
|
if (zipBuffer.byteLength > limits.maxInputBytes) throw new DocxSecurityError("DOCX file exceeds the maximum allowed size");
|
|
117
118
|
const wasEncrypted = containerType === DOCX_CONTAINER_TYPES.CFB;
|
|
118
119
|
const loaded = await loadDocxZip(zipBuffer, limits);
|
|
120
|
+
if (await moveMainDocumentToStandardPath(loaded.zip)) loaded.buffer = (await loaded.zip.generate()).slice().buffer;
|
|
119
121
|
if (loaded.buffer.byteLength > limits.maxInputBytes) throw new DocxSecurityError("DOCX file exceeds the maximum allowed size");
|
|
120
122
|
const { zip } = loaded;
|
|
121
123
|
const entries = zip.entries();
|
|
@@ -65,6 +65,7 @@ const messages = { "folio": {
|
|
|
65
65
|
"contentControlDateAriaLabel": "اختر تاريخًا",
|
|
66
66
|
"contentControlDropdownAriaLabel": "خيارات القائمة المنسدلة",
|
|
67
67
|
"contentControlDropdownNoOptions": "لا توجد خيارات",
|
|
68
|
+
"contentNotDisplayed": "المحتوى غير معروض",
|
|
68
69
|
"contextMenu": {
|
|
69
70
|
"continueNumbering": "متابعة الترقيم",
|
|
70
71
|
"copy": "نسخ",
|