@stll/folio-core 0.59.0 → 0.61.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 +23 -1
- package/dist/ai-edits/apply.js +139 -32
- package/dist/ai-edits/headless.d.ts +3 -0
- package/dist/ai-edits/headless.js +57 -63
- package/dist/ai-edits/note-story-inventory.d.ts +7 -0
- package/dist/ai-edits/note-story-inventory.js +11 -0
- package/dist/ai-edits/read.js +16 -9
- package/dist/ai-edits/revisionStretches.js +52 -1
- package/dist/ai-edits/table-row-column-mutations.js +6 -1
- package/dist/compare/reproducible-package.js +2 -1
- package/dist/compare/verification.js +1 -0
- package/dist/compat/eigenpal.d.ts +4 -2
- package/dist/compat/eigenpal.js +2 -2
- package/dist/controller/canonicalClipboard.js +2 -1
- package/dist/controller/canonicalListRendering.d.ts +4 -6
- package/dist/controller/canonicalListRendering.js +3 -157
- package/dist/controller/canonicalSession.js +3 -2
- package/dist/controller/canonicalStructure.js +10 -7
- package/dist/controller/fontReadiness.js +1 -1
- package/dist/controller/headerFooterEditorManager.d.ts +1 -0
- package/dist/controller/headerFooterEditorManager.js +11 -0
- package/dist/controller/hiddenEditorManager.d.ts +1 -1
- package/dist/controller/hiddenEditorManager.js +3 -1
- package/dist/controller/layoutPipeline.d.ts +3 -1
- package/dist/controller/layoutPipeline.js +19 -4
- package/dist/controller/layoutSession.d.ts +4 -1
- package/dist/display-list/build/fontTable.js +7 -5
- package/dist/display-list/build/furniture.d.ts +1 -0
- package/dist/display-list/build/furniture.js +1 -0
- package/dist/display-list/build/imagePrimitives.js +3 -6
- package/dist/display-list/build/watermarkPrimitives.d.ts +2 -1
- package/dist/display-list/build/watermarkPrimitives.js +9 -3
- package/dist/display-list/editor/pageRenderer.js +1 -0
- package/dist/docx/bookmarkIdNormalization.d.ts +10 -0
- package/dist/docx/bookmarkIdNormalization.js +100 -0
- package/dist/docx/bookmarkParser.js +4 -2
- package/dist/docx/canonicalStoryRepack.js +3 -2
- package/dist/docx/commentTextParagraph.d.ts +6 -0
- package/dist/docx/commentTextParagraph.js +15 -0
- package/dist/docx/conformance.js +6 -1
- package/dist/docx/diagramPreview.js +2 -1
- package/dist/docx/documentParser.d.ts +13 -1
- package/dist/docx/documentParser.js +1 -1
- package/dist/docx/encryption/compoundFile.d.ts +0 -8
- package/dist/docx/encryption/compoundFile.js +2 -1
- package/dist/docx/encryption/cryptoBytes.d.ts +2 -2
- package/dist/docx/encryption/cryptoBytes.js +3 -18
- package/dist/docx/encryption/encryptionInfo.d.ts +0 -5
- package/dist/docx/encryption/encryptionInfo.js +2 -1
- package/dist/docx/ensureParaIds.js +2 -1
- package/dist/docx/groupDrawingParser.js +6 -1
- package/dist/docx/importedIdCollisions.d.ts +136 -0
- package/dist/docx/importedIdCollisions.js +215 -0
- package/dist/docx/listModelNormalization.d.ts +10 -0
- package/dist/docx/listModelNormalization.js +166 -0
- package/dist/docx/metadataPrivacy.js +3 -2
- package/dist/docx/metafileRaster.js +2 -1
- package/dist/docx/numberingParser.js +2 -2
- package/dist/docx/packageParts.js +6 -5
- package/dist/docx/paragraphParser.js +6 -4
- package/dist/docx/paragraphPropertySource.js +1 -2
- package/dist/docx/parseContext.d.ts +2 -1
- package/dist/docx/parseContext.js +1 -0
- package/dist/docx/parseWarningMessage.js +1 -0
- package/dist/docx/parser.js +10 -5
- package/dist/docx/preservedRunContent.js +11 -2
- package/dist/docx/relsParser.js +1 -1
- package/dist/docx/removeHeaderFooterParts.js +8 -7
- package/dist/docx/replyToComment.js +3 -13
- package/dist/docx/rezip.js +90 -90
- package/dist/docx/runParser.js +12 -6
- package/dist/docx/runPropertyPresence.d.ts +11 -0
- package/dist/docx/runPropertyPresence.js +14 -0
- package/dist/docx/selectedXmlIdentityScan.d.ts +10 -0
- package/dist/docx/selectedXmlIdentityScan.js +36 -0
- package/dist/docx/selectiveSave.js +19 -17
- package/dist/docx/selectiveXmlPatch.js +44 -52
- package/dist/docx/serializer/commentSerializer.d.ts +3 -1
- package/dist/docx/serializer/commentSerializer.js +11 -2
- package/dist/docx/serializer/runSerializer.js +5 -4
- package/dist/docx/serializer/tableSerializer.js +2 -1
- package/dist/docx/serializer/trackedChangeAttributes.d.ts +1 -3
- package/dist/docx/serializer/trackedChangeAttributes.js +1 -11
- package/dist/docx/server/applyDocxXmlPatchProposal.js +2 -2
- package/dist/docx/server/boundedArchive.js +2 -1
- package/dist/docx/server/evaluateDocxXmlPatchProposal.js +2 -1
- package/dist/docx/server/inspectDocxPackage.js +5 -1
- package/dist/docx/server/validateDocxConformance.js +2 -1
- package/dist/docx/tableParser.js +7 -4
- package/dist/docx/tableRowPropertyPresence.d.ts +9 -0
- package/dist/docx/tableRowPropertyPresence.js +15 -0
- package/dist/docx/unzip.js +2 -1
- package/dist/docx/xmlEncoding.js +6 -5
- package/dist/fonts/embeddedFontFingerprint.d.ts +5 -0
- package/dist/fonts/embeddedFontFingerprint.js +18 -0
- package/dist/fonts/embeddedFonts.d.ts +1 -1
- package/dist/fonts/embeddedFonts.js +1 -1
- package/dist/fonts/fontsourceFaces.js +2 -1
- package/dist/fonts/headlessMeasure.js +0 -0
- package/dist/fonts/sfnt/parse.js +6 -9
- package/dist/fonts/sfnt/subset.js +2 -1
- package/dist/fonts/sfnt/tables.js +2 -3
- package/dist/fonts/sfnt/woff.js +2 -1
- package/dist/headless-layout.js +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -2
- package/dist/internal/revisionResolutionInline.d.ts +2 -1
- package/dist/internal/revisionResolutionInline.js +22 -1
- package/dist/internal/wholeStoryRevisionResolution.js +24 -7
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +4 -0
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +5 -1
- package/dist/layout-bridge/convert/footnoteLayout.js +16 -3
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +6 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +13 -14
- package/dist/layout-bridge/convert/paragraphConversion.js +8 -1
- package/dist/layout-bridge/convert/paragraphRuns.js +2 -1
- package/dist/layout-bridge/convert/toFlowBlocks.js +25 -1
- package/dist/layout-engine/measure/cache.js +39 -7
- package/dist/layout-engine/measure/crossRunWords.js +12 -2
- package/dist/layout-engine/measure/lineTypography.js +1 -0
- package/dist/layout-engine/measure/listMarkerWidth.d.ts +1 -0
- package/dist/layout-engine/measure/listMarkerWidth.js +1 -0
- package/dist/layout-engine/measure/measureContainer.js +3 -4
- package/dist/layout-engine/measure/measureHelpers.d.ts +6 -9
- package/dist/layout-engine/measure/measureHelpers.js +21 -18
- package/dist/layout-engine/measure/measureParagraph.js +2 -0
- package/dist/layout-engine/measure/measureTypes.d.ts +2 -0
- package/dist/layout-engine/types.d.ts +4 -1
- package/dist/layout-painter/renderPage.d.ts +1 -0
- package/dist/layout-painter/renderPage.js +11 -3
- package/dist/layout-painter/renderParagraph.js +13 -3
- package/dist/layout-painter/renderWatermark.d.ts +1 -0
- package/dist/layout-painter/renderWatermark.js +7 -3
- package/dist/managers/AutoSaveManager.js +2 -1
- package/dist/managers/EditorModeManager.d.ts +10 -1
- package/dist/managers/EditorModeManager.js +15 -1
- package/dist/managers/TableSelectionManager.d.ts +1 -1
- package/dist/managers/autoSaveCodec.js +2 -6
- package/dist/managers/editorShortcuts.d.ts +2 -1
- package/dist/managers/editorShortcuts.js +2 -1
- package/dist/managers/reviewDisplayMode.d.ts +8 -0
- package/dist/managers/reviewDisplayMode.js +15 -0
- package/dist/paged-layout/pageText.d.ts +11 -2
- package/dist/paged-layout/pageText.js +8 -3
- package/dist/pdf/fonts.js +5 -14
- package/dist/pdf/images.js +3 -2
- package/dist/pdf/objects.d.ts +0 -11
- package/dist/pdf/objects.js +7 -9
- package/dist/pdf/writePdf.js +2 -1
- package/dist/prosemirror/canonicalSelectionRange.d.ts +4 -1
- package/dist/prosemirror/canonicalSelectionRange.js +9 -3
- package/dist/prosemirror/commands/comments.js +51 -13
- package/dist/prosemirror/containerFinalParagraph.d.ts +8 -8
- package/dist/prosemirror/containerFinalParagraph.js +8 -8
- package/dist/prosemirror/conversion/fromProseDoc.js +9 -4
- package/dist/prosemirror/conversion/toProseDoc.js +4 -4
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +8 -2
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +39 -3
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.d.ts +8 -2
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +4 -3
- package/dist/prosemirror/extensions/features/ImageDragExtension.js +4 -3
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.js +4 -3
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +9 -3
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +6 -5
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +8 -2
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +11 -3
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +4 -3
- package/dist/prosemirror/extensions/marks/markUtils.js +1 -1
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +16 -2
- package/dist/prosemirror/findReplaceSelection.d.ts +11 -1
- package/dist/prosemirror/findReplaceSelection.js +15 -1
- package/dist/prosemirror/markupViewProjection.d.ts +10 -1
- package/dist/prosemirror/markupViewProjection.js +21 -3
- package/dist/prosemirror/pluginKeyOwner.d.ts +13 -0
- package/dist/prosemirror/pluginKeyOwner.js +35 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.d.ts +11 -4
- package/dist/prosemirror/plugins/aiCitationDecorations.js +16 -3
- package/dist/prosemirror/plugins/aiSuggestionDecorations.d.ts +11 -4
- package/dist/prosemirror/plugins/aiSuggestionDecorations.js +18 -3
- package/dist/prosemirror/plugins/anonymizationDecorations.d.ts +11 -11
- package/dist/prosemirror/plugins/anonymizationDecorations.js +23 -13
- package/dist/prosemirror/plugins/autocompleteSuggestion.d.ts +8 -2
- package/dist/prosemirror/plugins/autocompleteSuggestion.js +27 -5
- package/dist/prosemirror/plugins/contentControlWidgets.d.ts +8 -2
- package/dist/prosemirror/plugins/contentControlWidgets.js +4 -3
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +6 -5
- package/dist/prosemirror/plugins/createDocScanPlugin.js +1 -1
- package/dist/prosemirror/plugins/documentNumbering.js +5 -3
- package/dist/prosemirror/plugins/documentStyleState.d.ts +8 -2
- package/dist/prosemirror/plugins/documentStyleState.js +2 -2
- package/dist/prosemirror/plugins/documentStyles.js +1 -1
- package/dist/prosemirror/plugins/selectionTracker.d.ts +8 -2
- package/dist/prosemirror/plugins/selectionTracker.js +4 -3
- package/dist/prosemirror/plugins/suggestionMode.d.ts +8 -2
- package/dist/prosemirror/plugins/suggestionMode.js +4 -3
- package/dist/prosemirror/plugins/templateDirectives.d.ts +8 -2
- package/dist/prosemirror/plugins/templateDirectives.js +19 -4
- package/dist/prosemirror/plugins/templatePreviewValues.d.ts +8 -2
- package/dist/prosemirror/plugins/templatePreviewValues.js +27 -5
- package/dist/prosemirror/plugins/templateSlashMenu.d.ts +8 -2
- package/dist/prosemirror/plugins/templateSlashMenu.js +23 -5
- package/dist/prosemirror/plugins/transactionInvariants.js +29 -4
- package/dist/prosemirror/replacedAnnotations.d.ts +15 -1
- package/dist/prosemirror/replacedAnnotations.js +71 -12
- package/dist/prosemirror/runFormattingReconciliation.d.ts +3 -1
- package/dist/prosemirror/runFormattingReconciliation.js +10 -2
- package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +5 -7
- package/dist/prosemirror/runIdentityAcrossRevisions.js +66 -38
- package/dist/prosemirror/runPropertyChangeResolution.js +13 -1
- package/dist/utils/base64.d.ts +1 -31
- package/dist/utils/base64.js +19 -33
- package/dist/utils/clipboard.js +5 -4
- package/dist/utils/colorResolver.js +11 -2
- package/dist/utils/findReplace.d.ts +5 -0
- package/dist/utils/fontLoader.d.ts +2 -2
- package/dist/utils/fontLoader.js +2 -7
- package/dist/utils/fontResolver.d.ts +7 -3
- package/dist/utils/fontResolver.js +6 -8
- package/dist/utils/replaceText.js +21 -4
- package/dist/utils/sliceText.d.ts +2 -0
- package/dist/utils/sliceText.js +2 -0
- package/dist/utils/textEncoding.d.ts +2 -0
- package/dist/utils/textEncoding.js +2 -0
- package/dist/utils/tiffConverter.d.ts +0 -9
- package/dist/utils/tiffConverter.js +2 -4
- package/package.json +73 -31
package/dist/docx/rezip.js
CHANGED
|
@@ -2,6 +2,7 @@ import { consumeTrackedSectionEndpointRemoval } from "../internal/sectionEndpoin
|
|
|
2
2
|
import { consumeSectionReferenceResolution } from "../internal/sectionReferenceResolution.js";
|
|
3
3
|
import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
|
|
4
4
|
import { canonicalJson } from "../utils/canonicalJson.js";
|
|
5
|
+
import { base64ToBytes, decodeText, encodeUtf8 } from "../utils/textEncoding.js";
|
|
5
6
|
import { isAllowedExternalWatermarkImageUrl } from "../watermark/index.js";
|
|
6
7
|
import { appVersionInSchemaForm, normalizeAppVersionInExtendedProperties } from "./appVersionNormalization.js";
|
|
7
8
|
import { withoutOrphanCommentRanges } from "./commentRangeIntegrity.js";
|
|
@@ -25,7 +26,7 @@ import { RELATIONSHIP_TYPES, parseRelationships, resolveRelativePath } from "./r
|
|
|
25
26
|
import { removeResolvedHeaderFooterParts } from "./removeHeaderFooterParts.js";
|
|
26
27
|
import { normalizeRevisionIdsInXmlParts } from "./revisionIdNormalization.js";
|
|
27
28
|
import { buildPatchedNotePartXml, collectChangedNoteParaIds, collectParaIds, patchNumberingDefinitions, spliceXml } from "./selectiveXmlPatch.js";
|
|
28
|
-
import { hasOwnedCommentsPart, planCommentParts, serializeComments, serializeCommentsExtended } from "./serializer/commentSerializer.js";
|
|
29
|
+
import { canReplayCommentsPart, hasOwnedCommentsPart, planCommentParts, serializeComments, serializeCommentsExtended } from "./serializer/commentSerializer.js";
|
|
29
30
|
import { serializeDocument } from "./serializer/documentSerializer.js";
|
|
30
31
|
import { serializeFontTableXml } from "./serializer/fontTableSerializer.js";
|
|
31
32
|
import { serializeHeaderFooter } from "./serializer/headerFooterSerializer.js";
|
|
@@ -200,7 +201,8 @@ function assertDocumentPackageFidelity({ originalDocumentFacts, serializedDocume
|
|
|
200
201
|
async function serializeCommentsToZip(doc, zip, compressionLevel) {
|
|
201
202
|
const comments = doc.package.document.comments ?? [];
|
|
202
203
|
const sourceCommentsFile = findZipEntryCaseInsensitive(zip, "word/comments.xml");
|
|
203
|
-
const sourceCommentsXml = sourceCommentsFile ? await sourceCommentsFile.async("
|
|
204
|
+
const sourceCommentsXml = sourceCommentsFile ? await sourceCommentsFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true })) : void 0;
|
|
205
|
+
if (sourceCommentsXml !== void 0 && canReplayCommentsPart(doc, sourceCommentsXml)) return;
|
|
204
206
|
if (comments.length === 0) {
|
|
205
207
|
const ownsCommentsPart = hasOwnedCommentsPart(doc);
|
|
206
208
|
if (sourceCommentsXml === void 0 ? !ownsCommentsPart : !hasCommentEntries(sourceCommentsXml)) return;
|
|
@@ -210,7 +212,7 @@ async function serializeCommentsToZip(doc, zip, compressionLevel) {
|
|
|
210
212
|
writeZipPart({
|
|
211
213
|
zip,
|
|
212
214
|
path: sourceCommentsFile?.name ?? "word/comments.xml",
|
|
213
|
-
data: commentsXml,
|
|
215
|
+
data: encodeUtf8(commentsXml),
|
|
214
216
|
options: {
|
|
215
217
|
compression: "DEFLATE",
|
|
216
218
|
compressionOptions: { level: compressionLevel }
|
|
@@ -246,7 +248,7 @@ async function syncCommentsExtendedPart(plan, zip, compressionLevel) {
|
|
|
246
248
|
writeZipPart({
|
|
247
249
|
zip,
|
|
248
250
|
path: existing?.name ?? "word/commentsExtended.xml",
|
|
249
|
-
data: xml,
|
|
251
|
+
data: encodeUtf8(xml),
|
|
250
252
|
options: {
|
|
251
253
|
compression: "DEFLATE",
|
|
252
254
|
compressionOptions: { level: compressionLevel }
|
|
@@ -259,12 +261,12 @@ async function syncCommentsExtendedPart(plan, zip, compressionLevel) {
|
|
|
259
261
|
async function transformPackagingFile(zip, path, transform, compressionLevel) {
|
|
260
262
|
const file = zip.file(path);
|
|
261
263
|
if (!file) return;
|
|
262
|
-
const xml = await file.async("
|
|
264
|
+
const xml = await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
263
265
|
const next = transform(xml);
|
|
264
266
|
if (next !== xml) writeZipPart({
|
|
265
267
|
zip,
|
|
266
268
|
path,
|
|
267
|
-
data: next,
|
|
269
|
+
data: encodeUtf8(next),
|
|
268
270
|
options: {
|
|
269
271
|
compression: "DEFLATE",
|
|
270
272
|
compressionOptions: { level: compressionLevel }
|
|
@@ -350,7 +352,7 @@ function collectDocxParts(doc, zip) {
|
|
|
350
352
|
}
|
|
351
353
|
async function readRelsOrStub(zip, relsPath) {
|
|
352
354
|
const file = zip.file(relsPath);
|
|
353
|
-
return (file ? await file.async("
|
|
355
|
+
return (file ? await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true })) : EMPTY_RELS_XML).replace(/<Relationships(?<attrs>[^>]*)\/>/u, "<Relationships$<attrs>></Relationships>");
|
|
354
356
|
}
|
|
355
357
|
function findMaxImageNum(zip) {
|
|
356
358
|
let maxImageNum = 0;
|
|
@@ -367,7 +369,7 @@ async function registerImageExtensions(zip, extensions, compressionLevel) {
|
|
|
367
369
|
if (extensions.size === 0) return;
|
|
368
370
|
const ctFile = zip.file("[Content_Types].xml");
|
|
369
371
|
if (!ctFile) return;
|
|
370
|
-
let ctXml = await ctFile.async("
|
|
372
|
+
let ctXml = await ctFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
371
373
|
let changed = false;
|
|
372
374
|
for (const ext of extensions) {
|
|
373
375
|
if (ctXml.includes(`Extension="${ext}"`)) continue;
|
|
@@ -379,7 +381,7 @@ async function registerImageExtensions(zip, extensions, compressionLevel) {
|
|
|
379
381
|
writeZipPart({
|
|
380
382
|
zip,
|
|
381
383
|
path: "[Content_Types].xml",
|
|
382
|
-
data: ctXml,
|
|
384
|
+
data: encodeUtf8(ctXml),
|
|
383
385
|
options: {
|
|
384
386
|
compression: "DEFLATE",
|
|
385
387
|
compressionOptions: { level: compressionLevel }
|
|
@@ -419,11 +421,8 @@ function decodeDataUrl(dataUrl) {
|
|
|
419
421
|
const payload = match.groups["data"];
|
|
420
422
|
const parameters = match.groups["parameters"];
|
|
421
423
|
let bytes;
|
|
422
|
-
if (parameters.split(";").some((parameter) => parameter.toLowerCase() === "base64"))
|
|
423
|
-
|
|
424
|
-
bytes = new Uint8Array(binary.length);
|
|
425
|
-
for (let i = 0; i < binary.length; i++) bytes[i] = binary.codePointAt(i) ?? 0;
|
|
426
|
-
} else bytes = new TextEncoder().encode(decodeURIComponent(payload));
|
|
424
|
+
if (parameters.split(";").some((parameter) => parameter.toLowerCase() === "base64")) bytes = base64ToBytes(payload);
|
|
425
|
+
else bytes = encodeUtf8(decodeURIComponent(payload));
|
|
427
426
|
return {
|
|
428
427
|
data: bytes.slice().buffer,
|
|
429
428
|
extension: MIME_TO_EXT[match.groups["mime"]] ?? "png"
|
|
@@ -457,7 +456,7 @@ async function processNewImages(parts, zip, compressionLevel) {
|
|
|
457
456
|
writeZipPart({
|
|
458
457
|
zip,
|
|
459
458
|
path: mediaPath,
|
|
460
|
-
data,
|
|
459
|
+
data: new Uint8Array(data),
|
|
461
460
|
options: {
|
|
462
461
|
compression: "DEFLATE",
|
|
463
462
|
compressionOptions: { level: compressionLevel }
|
|
@@ -475,7 +474,7 @@ async function processNewImages(parts, zip, compressionLevel) {
|
|
|
475
474
|
if (relEntries.length > 0) writeZipPart({
|
|
476
475
|
zip,
|
|
477
476
|
path: relsPath,
|
|
478
|
-
data: relsXml.replace("</Relationships>", `${relEntries.join("")}</Relationships>`),
|
|
477
|
+
data: encodeUtf8(relsXml.replace("</Relationships>", `${relEntries.join("")}</Relationships>`)),
|
|
479
478
|
options: {
|
|
480
479
|
compression: "DEFLATE",
|
|
481
480
|
compressionOptions: { level: compressionLevel }
|
|
@@ -495,7 +494,7 @@ const materializeEmbeddedMedia = async ({ document, zip, compressionLevel }) =>
|
|
|
495
494
|
writeZipPart({
|
|
496
495
|
zip,
|
|
497
496
|
path: media.path,
|
|
498
|
-
data: media.data,
|
|
497
|
+
data: new Uint8Array(media.data),
|
|
499
498
|
options: {
|
|
500
499
|
compression: "DEFLATE",
|
|
501
500
|
compressionOptions: { level: compressionLevel }
|
|
@@ -557,7 +556,7 @@ const publishCanonicalImageResources = async ({ document, zip, compressionLevel
|
|
|
557
556
|
writeZipPart({
|
|
558
557
|
zip,
|
|
559
558
|
path: absolute,
|
|
560
|
-
data: media.data,
|
|
559
|
+
data: new Uint8Array(media.data),
|
|
561
560
|
options: {
|
|
562
561
|
compression: "DEFLATE",
|
|
563
562
|
compressionOptions: { level: compressionLevel }
|
|
@@ -587,7 +586,7 @@ const publishCanonicalImageResources = async ({ document, zip, compressionLevel
|
|
|
587
586
|
if (changed) writeZipPart({
|
|
588
587
|
zip,
|
|
589
588
|
path: relsPath,
|
|
590
|
-
data: xml,
|
|
589
|
+
data: encodeUtf8(xml),
|
|
591
590
|
options: {
|
|
592
591
|
compression: "DEFLATE",
|
|
593
592
|
compressionOptions: { level: compressionLevel }
|
|
@@ -738,7 +737,7 @@ async function processNewHyperlinks(parts, zip, compressionLevel) {
|
|
|
738
737
|
writeZipPart({
|
|
739
738
|
zip,
|
|
740
739
|
path: relsPath,
|
|
741
|
-
data: captureVerbatimXml(root),
|
|
740
|
+
data: encodeUtf8(captureVerbatimXml(root)),
|
|
742
741
|
options: {
|
|
743
742
|
compression: "DEFLATE",
|
|
744
743
|
compressionOptions: { level: compressionLevel }
|
|
@@ -762,7 +761,7 @@ async function processNewHyperlinks(parts, zip, compressionLevel) {
|
|
|
762
761
|
const normalizePackageIdsInZip = async (zip, compressionLevel) => {
|
|
763
762
|
const xmlParts = /* @__PURE__ */ new Map();
|
|
764
763
|
for (const [path, file] of Object.entries(zip.files)) if (!file.dir && path.startsWith("word/") && path.endsWith(".xml")) {
|
|
765
|
-
const xml = await file.async("
|
|
764
|
+
const xml = await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
766
765
|
assertValidOoxmlNumericIds(xml, path);
|
|
767
766
|
xmlParts.set(path, xml);
|
|
768
767
|
}
|
|
@@ -772,7 +771,7 @@ const normalizePackageIdsInZip = async (zip, compressionLevel) => {
|
|
|
772
771
|
writeZipPart({
|
|
773
772
|
zip,
|
|
774
773
|
path,
|
|
775
|
-
data: xml,
|
|
774
|
+
data: encodeUtf8(xml),
|
|
776
775
|
options: {
|
|
777
776
|
compression: "DEFLATE",
|
|
778
777
|
compressionOptions: { level: compressionLevel }
|
|
@@ -789,12 +788,12 @@ const EXTENDED_PROPERTIES_PATH = "docProps/app.xml";
|
|
|
789
788
|
const normalizeAppVersionInZip = async (zip, compressionLevel) => {
|
|
790
789
|
const extendedProperties = zip.file(EXTENDED_PROPERTIES_PATH);
|
|
791
790
|
if (!extendedProperties) return;
|
|
792
|
-
const xml = await extendedProperties.async("
|
|
791
|
+
const xml = await extendedProperties.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
793
792
|
const normalized = normalizeAppVersionInExtendedProperties(xml);
|
|
794
793
|
if (normalized !== xml) writeZipPart({
|
|
795
794
|
zip,
|
|
796
795
|
path: EXTENDED_PROPERTIES_PATH,
|
|
797
|
-
data: normalized,
|
|
796
|
+
data: encodeUtf8(normalized),
|
|
798
797
|
options: {
|
|
799
798
|
compression: "DEFLATE",
|
|
800
799
|
compressionOptions: { level: compressionLevel }
|
|
@@ -853,7 +852,7 @@ const loadParsedZipSource = async (document, buffer) => {
|
|
|
853
852
|
if (cached?.buffer === buffer) return cached;
|
|
854
853
|
const zip = await JSZip.loadAsync(buffer);
|
|
855
854
|
removeUnsafeEntries(zip);
|
|
856
|
-
const [documentXml, corePropertiesXml] = await Promise.all([zip.file("word/document.xml")?.async("
|
|
855
|
+
const [documentXml, corePropertiesXml] = await Promise.all([zip.file("word/document.xml")?.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true })), zip.file("docProps/core.xml")?.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }))]);
|
|
857
856
|
const source = {
|
|
858
857
|
buffer,
|
|
859
858
|
zip,
|
|
@@ -924,7 +923,7 @@ const finishRepack = async ({ document: sourceDocument, originalZip, outputZip,
|
|
|
924
923
|
writeZipPart({
|
|
925
924
|
zip: outputZip,
|
|
926
925
|
path: "word/document.xml",
|
|
927
|
-
data: documentXml,
|
|
926
|
+
data: encodeUtf8(documentXml),
|
|
928
927
|
options: {
|
|
929
928
|
compression: "DEFLATE",
|
|
930
929
|
compressionOptions: { level: compressionLevel }
|
|
@@ -957,10 +956,10 @@ const finishRepack = async ({ document: sourceDocument, originalZip, outputZip,
|
|
|
957
956
|
if (updateModifiedDate && originalCorePropertiesXml) writeZipPart({
|
|
958
957
|
zip: outputZip,
|
|
959
958
|
path: "docProps/core.xml",
|
|
960
|
-
data: updateCoreProperties(originalCorePropertiesXml, {
|
|
959
|
+
data: encodeUtf8(updateCoreProperties(originalCorePropertiesXml, {
|
|
961
960
|
updateModifiedDate,
|
|
962
961
|
...modifiedBy !== void 0 ? { modifiedBy } : {}
|
|
963
|
-
}),
|
|
962
|
+
})),
|
|
964
963
|
options: {
|
|
965
964
|
compression: "DEFLATE",
|
|
966
965
|
compressionOptions: { level: compressionLevel }
|
|
@@ -973,7 +972,7 @@ async function repackDocxWithSectionEndpointRemoval({ document: doc, options, se
|
|
|
973
972
|
const { compressionLevel = 6, updateModifiedDate = true, modifiedBy, changedNoteParaIds } = options;
|
|
974
973
|
const exportDocument = withoutOrphanCommentRanges(doc);
|
|
975
974
|
const originalZip = await JSZip.loadAsync(doc.originalBuffer);
|
|
976
|
-
const [originalDocumentXml, originalCorePropertiesXml] = await Promise.all([originalZip.file("word/document.xml")?.async("
|
|
975
|
+
const [originalDocumentXml, originalCorePropertiesXml] = await Promise.all([originalZip.file("word/document.xml")?.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true })), originalZip.file("docProps/core.xml")?.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }))]);
|
|
977
976
|
removeUnsafeEntries(originalZip);
|
|
978
977
|
const newZip = cloneDocxZip(originalZip);
|
|
979
978
|
return finishRepack({
|
|
@@ -1019,7 +1018,7 @@ async function repackDocxFromRaw(doc, rawContent, options = {}) {
|
|
|
1019
1018
|
writeZipPart({
|
|
1020
1019
|
zip: newZip,
|
|
1021
1020
|
path,
|
|
1022
|
-
data:
|
|
1021
|
+
data: /* @__PURE__ */ new Uint8Array(),
|
|
1023
1022
|
options: {
|
|
1024
1023
|
dir: true,
|
|
1025
1024
|
date: file.date
|
|
@@ -1028,10 +1027,11 @@ async function repackDocxFromRaw(doc, rawContent, options = {}) {
|
|
|
1028
1027
|
continue;
|
|
1029
1028
|
}
|
|
1030
1029
|
if (isUnsafePackagePath(path)) continue;
|
|
1030
|
+
const content = await file.async("arraybuffer");
|
|
1031
1031
|
writeZipPart({
|
|
1032
1032
|
zip: newZip,
|
|
1033
1033
|
path,
|
|
1034
|
-
data:
|
|
1034
|
+
data: new Uint8Array(content),
|
|
1035
1035
|
options: {
|
|
1036
1036
|
compression: "DEFLATE",
|
|
1037
1037
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1068,7 +1068,7 @@ async function repackDocxFromRaw(doc, rawContent, options = {}) {
|
|
|
1068
1068
|
writeZipPart({
|
|
1069
1069
|
zip: newZip,
|
|
1070
1070
|
path: "word/document.xml",
|
|
1071
|
-
data: documentXml,
|
|
1071
|
+
data: encodeUtf8(documentXml),
|
|
1072
1072
|
options: {
|
|
1073
1073
|
compression: "DEFLATE",
|
|
1074
1074
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1101,10 +1101,10 @@ async function repackDocxFromRaw(doc, rawContent, options = {}) {
|
|
|
1101
1101
|
if (updateModifiedDate && rawContent.corePropsXml) writeZipPart({
|
|
1102
1102
|
zip: newZip,
|
|
1103
1103
|
path: "docProps/core.xml",
|
|
1104
|
-
data: updateCoreProperties(rawContent.corePropsXml, {
|
|
1104
|
+
data: encodeUtf8(updateCoreProperties(rawContent.corePropsXml, {
|
|
1105
1105
|
updateModifiedDate,
|
|
1106
1106
|
...modifiedBy !== void 0 ? { modifiedBy } : {}
|
|
1107
|
-
}),
|
|
1107
|
+
})),
|
|
1108
1108
|
options: {
|
|
1109
1109
|
compression: "DEFLATE",
|
|
1110
1110
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1197,11 +1197,11 @@ async function dropAttachedTemplateReference(zip, compressionLevel) {
|
|
|
1197
1197
|
const settingsFile = zip.file(SETTINGS_PART);
|
|
1198
1198
|
if (!settingsFile) return;
|
|
1199
1199
|
const relsFile = zip.file(SETTINGS_RELS_PART);
|
|
1200
|
-
const filtered = withoutAttachedTemplate(await settingsFile.async("
|
|
1200
|
+
const filtered = withoutAttachedTemplate(await settingsFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true })), await relsFile?.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true })));
|
|
1201
1201
|
if (filtered.settingsXml !== void 0) writeZipPart({
|
|
1202
1202
|
zip,
|
|
1203
1203
|
path: SETTINGS_PART,
|
|
1204
|
-
data: filtered.settingsXml,
|
|
1204
|
+
data: encodeUtf8(filtered.settingsXml),
|
|
1205
1205
|
options: {
|
|
1206
1206
|
compression: "DEFLATE",
|
|
1207
1207
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1210,7 +1210,7 @@ async function dropAttachedTemplateReference(zip, compressionLevel) {
|
|
|
1210
1210
|
if (filtered.relsXml !== void 0) writeZipPart({
|
|
1211
1211
|
zip,
|
|
1212
1212
|
path: SETTINGS_RELS_PART,
|
|
1213
|
-
data: filtered.relsXml,
|
|
1213
|
+
data: encodeUtf8(filtered.relsXml),
|
|
1214
1214
|
options: {
|
|
1215
1215
|
compression: "DEFLATE",
|
|
1216
1216
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1224,14 +1224,14 @@ async function dropAttachedTemplateReference(zip, compressionLevel) {
|
|
|
1224
1224
|
async function ensureCommentsContentType(zip, compressionLevel) {
|
|
1225
1225
|
const ctFile = zip.file("[Content_Types].xml");
|
|
1226
1226
|
if (!ctFile) return;
|
|
1227
|
-
let ctXml = await ctFile.async("
|
|
1227
|
+
let ctXml = await ctFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1228
1228
|
if (ctXml.toLowerCase().includes("/word/comments.xml")) return;
|
|
1229
1229
|
const commentsPartPath = findZipEntryCaseInsensitive(zip, "word/comments.xml")?.name ?? "word/comments.xml";
|
|
1230
1230
|
ctXml = ctXml.replace("</Types>", `<Override PartName="/${commentsPartPath}" ContentType="${COMMENTS_CONTENT_TYPE}"/></Types>`);
|
|
1231
1231
|
writeZipPart({
|
|
1232
1232
|
zip,
|
|
1233
1233
|
path: "[Content_Types].xml",
|
|
1234
|
-
data: ctXml,
|
|
1234
|
+
data: encodeUtf8(ctXml),
|
|
1235
1235
|
options: {
|
|
1236
1236
|
compression: "DEFLATE",
|
|
1237
1237
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1246,7 +1246,7 @@ async function ensureCommentsRelationship(zip, compressionLevel) {
|
|
|
1246
1246
|
const relsPath = "word/_rels/document.xml.rels";
|
|
1247
1247
|
const relsFile = zip.file(relsPath);
|
|
1248
1248
|
if (!relsFile) return;
|
|
1249
|
-
let relsXml = await relsFile.async("
|
|
1249
|
+
let relsXml = await relsFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1250
1250
|
if (relsXml.toLowerCase().includes("comments.xml")) return;
|
|
1251
1251
|
const commentsPartPath = findZipEntryCaseInsensitive(zip, "word/comments.xml")?.name ?? "word/comments.xml";
|
|
1252
1252
|
const newRId = `rId${findMaxRId(relsXml) + 1}`;
|
|
@@ -1254,7 +1254,7 @@ async function ensureCommentsRelationship(zip, compressionLevel) {
|
|
|
1254
1254
|
writeZipPart({
|
|
1255
1255
|
zip,
|
|
1256
1256
|
path: relsPath,
|
|
1257
|
-
data: relsXml,
|
|
1257
|
+
data: encodeUtf8(relsXml),
|
|
1258
1258
|
options: {
|
|
1259
1259
|
compression: "DEFLATE",
|
|
1260
1260
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1275,7 +1275,7 @@ async function updateDocumentXml(originalBuffer, newDocumentXml, options = {}) {
|
|
|
1275
1275
|
writeZipPart({
|
|
1276
1276
|
zip,
|
|
1277
1277
|
path: "word/document.xml",
|
|
1278
|
-
data: newDocumentXml,
|
|
1278
|
+
data: encodeUtf8(newDocumentXml),
|
|
1279
1279
|
options: {
|
|
1280
1280
|
compression: "DEFLATE",
|
|
1281
1281
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1302,7 +1302,7 @@ async function updateXmlFile(originalBuffer, path, content, options = {}) {
|
|
|
1302
1302
|
writeZipPart({
|
|
1303
1303
|
zip,
|
|
1304
1304
|
path,
|
|
1305
|
-
data: content,
|
|
1305
|
+
data: encodeUtf8(content),
|
|
1306
1306
|
options: {
|
|
1307
1307
|
compression: "DEFLATE",
|
|
1308
1308
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1340,7 +1340,7 @@ async function applyUpdatesToZip(zip, updates, options = {}) {
|
|
|
1340
1340
|
for (const [path, content] of updates) writeZipPart({
|
|
1341
1341
|
zip,
|
|
1342
1342
|
path,
|
|
1343
|
-
data: content,
|
|
1343
|
+
data: typeof content === "string" ? encodeUtf8(content) : new Uint8Array(content),
|
|
1344
1344
|
options: {
|
|
1345
1345
|
compression: "DEFLATE",
|
|
1346
1346
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1365,14 +1365,14 @@ async function addRelationship(originalBuffer, relationship) {
|
|
|
1365
1365
|
const relsPath = "word/_rels/document.xml.rels";
|
|
1366
1366
|
const relsFile = zip.file(relsPath);
|
|
1367
1367
|
if (!relsFile) panic("document.xml.rels not found in DOCX");
|
|
1368
|
-
const relsXml = await relsFile.async("
|
|
1368
|
+
const relsXml = await relsFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1369
1369
|
const newRId = `rId${findMaxRId(relsXml) + 1}`;
|
|
1370
1370
|
const targetModeAttr = relationship.targetMode === "External" ? " TargetMode=\"External\"" : "";
|
|
1371
1371
|
const newRelElement = `<Relationship Id="${newRId}" Type="${relationship.type}" Target="${escapeXmlAttribute(relationship.target)}"${targetModeAttr}/>`;
|
|
1372
1372
|
writeZipPart({
|
|
1373
1373
|
zip,
|
|
1374
1374
|
path: relsPath,
|
|
1375
|
-
data: relsXml.replace("</Relationships>", `${newRelElement}</Relationships>`)
|
|
1375
|
+
data: encodeUtf8(relsXml.replace("</Relationships>", `${newRelElement}</Relationships>`))
|
|
1376
1376
|
});
|
|
1377
1377
|
return {
|
|
1378
1378
|
buffer: await zip.generateAsync({
|
|
@@ -1398,7 +1398,7 @@ async function addMedia(originalBuffer, filename, data, mimeType) {
|
|
|
1398
1398
|
writeZipPart({
|
|
1399
1399
|
zip,
|
|
1400
1400
|
path: mediaPath,
|
|
1401
|
-
data
|
|
1401
|
+
data: new Uint8Array(data)
|
|
1402
1402
|
});
|
|
1403
1403
|
const relResult = await addRelationship(await zip.generateAsync({ type: "arraybuffer" }), {
|
|
1404
1404
|
type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
|
@@ -1406,7 +1406,7 @@ async function addMedia(originalBuffer, filename, data, mimeType) {
|
|
|
1406
1406
|
});
|
|
1407
1407
|
const contentTypesFile = zip.file("[Content_Types].xml");
|
|
1408
1408
|
if (contentTypesFile) {
|
|
1409
|
-
const contentTypesXml = await contentTypesFile.async("
|
|
1409
|
+
const contentTypesXml = await contentTypesFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1410
1410
|
const extension = filename.split(".").pop()?.toLowerCase() || "";
|
|
1411
1411
|
if (!contentTypesXml.includes(`Extension="${extension}"`) && extension) {
|
|
1412
1412
|
const extensionElement = `<Default Extension="${extension}" ContentType="${getContentTypeForExtension(extension, mimeType)}"/>`;
|
|
@@ -1415,7 +1415,7 @@ async function addMedia(originalBuffer, filename, data, mimeType) {
|
|
|
1415
1415
|
writeZipPart({
|
|
1416
1416
|
zip: finalZip,
|
|
1417
1417
|
path: "[Content_Types].xml",
|
|
1418
|
-
data: updatedContentTypes
|
|
1418
|
+
data: encodeUtf8(updatedContentTypes)
|
|
1419
1419
|
});
|
|
1420
1420
|
return {
|
|
1421
1421
|
buffer: await finalZip.generateAsync({
|
|
@@ -1565,7 +1565,7 @@ async function materializeNewHeaderFooterParts(doc, zip, compressionLevel) {
|
|
|
1565
1565
|
if (relEntries.length > 0) writeZipPart({
|
|
1566
1566
|
zip,
|
|
1567
1567
|
path: relsPath,
|
|
1568
|
-
data: relsXml.replace("</Relationships>", `${relEntries.join("")}</Relationships>`),
|
|
1568
|
+
data: encodeUtf8(relsXml.replace("</Relationships>", `${relEntries.join("")}</Relationships>`)),
|
|
1569
1569
|
options: {
|
|
1570
1570
|
compression: "DEFLATE",
|
|
1571
1571
|
compressionOptions
|
|
@@ -1573,12 +1573,12 @@ async function materializeNewHeaderFooterParts(doc, zip, compressionLevel) {
|
|
|
1573
1573
|
});
|
|
1574
1574
|
const ctFile = zip.file("[Content_Types].xml");
|
|
1575
1575
|
if (ctFile) {
|
|
1576
|
-
const original = await ctFile.async("
|
|
1576
|
+
const original = await ctFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1577
1577
|
const updated = registerContentTypeParts(original, contentTypeParts);
|
|
1578
1578
|
if (updated !== original) writeZipPart({
|
|
1579
1579
|
zip,
|
|
1580
1580
|
path: "[Content_Types].xml",
|
|
1581
|
-
data: updated,
|
|
1581
|
+
data: encodeUtf8(updated),
|
|
1582
1582
|
options: {
|
|
1583
1583
|
compression: "DEFLATE",
|
|
1584
1584
|
compressionOptions
|
|
@@ -1731,7 +1731,7 @@ async function rebindWatermarkRelIds({ document: doc, zip, compressionLevel, bod
|
|
|
1731
1731
|
if (xml) writeZipPart({
|
|
1732
1732
|
zip,
|
|
1733
1733
|
path,
|
|
1734
|
-
data: xml,
|
|
1734
|
+
data: encodeUtf8(xml),
|
|
1735
1735
|
options: {
|
|
1736
1736
|
compression: "DEFLATE",
|
|
1737
1737
|
compressionOptions
|
|
@@ -1758,7 +1758,7 @@ async function collectHeaderFooterUpdates(doc, { sourceZip, onDiagnostic }) {
|
|
|
1758
1758
|
if (rel && rel.type === type && rel.target) {
|
|
1759
1759
|
const path = resolveRelativePath(documentRelsPath, rel.target);
|
|
1760
1760
|
const sourceFile = findZipEntryCaseInsensitive(sourceZip, path.toLowerCase());
|
|
1761
|
-
const bindings = sourceFile ? readRootNamespaceBindings(await sourceFile.async("
|
|
1761
|
+
const bindings = sourceFile ? readRootNamespaceBindings(await sourceFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }))) : /* @__PURE__ */ new Map();
|
|
1762
1762
|
updates.set(path, serializeHeaderFooter(headerFooter, {
|
|
1763
1763
|
path,
|
|
1764
1764
|
bindings,
|
|
@@ -1778,7 +1778,7 @@ async function serializeHeadersFootersToZip({ doc, zip, compressionLevel, onDiag
|
|
|
1778
1778
|
})) writeZipPart({
|
|
1779
1779
|
zip,
|
|
1780
1780
|
path: filename,
|
|
1781
|
-
data: xml,
|
|
1781
|
+
data: encodeUtf8(xml),
|
|
1782
1782
|
options: {
|
|
1783
1783
|
compression: "DEFLATE",
|
|
1784
1784
|
compressionOptions
|
|
@@ -1834,25 +1834,25 @@ async function materializeNewNotePart({ contentType, newZip, partPath, relations
|
|
|
1834
1834
|
const relationshipsFile = findNotePartEntry(newZip, "word/_rels/document.xml.rels");
|
|
1835
1835
|
if (!contentTypesFile || !relationshipsFile) throw new DocxPackageFidelityError(`Cannot create ${partPath}: the DOCX package is missing content types or document relationships`);
|
|
1836
1836
|
const compressionOptions = { level: compressionLevel };
|
|
1837
|
-
const contentTypesXml = await contentTypesFile.async("
|
|
1837
|
+
const contentTypesXml = await contentTypesFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1838
1838
|
const partName = `/${partPath}`;
|
|
1839
1839
|
if (!contentTypesXml.toLowerCase().includes(partName.toLowerCase())) writeZipPart({
|
|
1840
1840
|
zip: newZip,
|
|
1841
1841
|
path: contentTypesFile.name,
|
|
1842
|
-
data: contentTypesXml.replace("</Types>", () => `<Override PartName="${partName}" ContentType="${contentType}"/></Types>`),
|
|
1842
|
+
data: encodeUtf8(contentTypesXml.replace("</Types>", () => `<Override PartName="${partName}" ContentType="${contentType}"/></Types>`)),
|
|
1843
1843
|
options: {
|
|
1844
1844
|
compression: "DEFLATE",
|
|
1845
1845
|
compressionOptions
|
|
1846
1846
|
}
|
|
1847
1847
|
});
|
|
1848
|
-
const relationshipsXml = await relationshipsFile.async("
|
|
1848
|
+
const relationshipsXml = await relationshipsFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1849
1849
|
if (!relationshipsXml.includes(relationshipType)) {
|
|
1850
1850
|
const relationshipId = `rId${findMaxRId(relationshipsXml) + 1}`;
|
|
1851
1851
|
const target = partPath.slice(5);
|
|
1852
1852
|
writeZipPart({
|
|
1853
1853
|
zip: newZip,
|
|
1854
1854
|
path: relationshipsFile.name,
|
|
1855
|
-
data: relationshipsXml.replace("</Relationships>", () => `<Relationship Id="${relationshipId}" Type="${relationshipType}" Target="${target}"/></Relationships>`),
|
|
1855
|
+
data: encodeUtf8(relationshipsXml.replace("</Relationships>", () => `<Relationship Id="${relationshipId}" Type="${relationshipType}" Target="${target}"/></Relationships>`)),
|
|
1856
1856
|
options: {
|
|
1857
1857
|
compression: "DEFLATE",
|
|
1858
1858
|
compressionOptions
|
|
@@ -1862,7 +1862,7 @@ async function materializeNewNotePart({ contentType, newZip, partPath, relations
|
|
|
1862
1862
|
writeZipPart({
|
|
1863
1863
|
zip: newZip,
|
|
1864
1864
|
path: partPath,
|
|
1865
|
-
data: serializedPart,
|
|
1865
|
+
data: encodeUtf8(serializedPart),
|
|
1866
1866
|
options: {
|
|
1867
1867
|
compression: "DEFLATE",
|
|
1868
1868
|
compressionOptions
|
|
@@ -1886,14 +1886,14 @@ async function serializeHeaderFooterSettingsIntoZip(doc, zip, compressionLevel)
|
|
|
1886
1886
|
});
|
|
1887
1887
|
return;
|
|
1888
1888
|
}
|
|
1889
|
-
const xml = await file.async("
|
|
1889
|
+
const xml = await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1890
1890
|
if (parseSettings(xml).evenAndOddHeaders === enabled) return;
|
|
1891
1891
|
const patched = updateEvenAndOddHeaders(xml, enabled);
|
|
1892
1892
|
if (patched === null) throw new DocxPackageFidelityError("Cannot update malformed header/footer settings");
|
|
1893
1893
|
writeZipPart({
|
|
1894
1894
|
zip,
|
|
1895
1895
|
path: file.name,
|
|
1896
|
-
data: patched,
|
|
1896
|
+
data: encodeUtf8(patched),
|
|
1897
1897
|
options: {
|
|
1898
1898
|
compression: "DEFLATE",
|
|
1899
1899
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1918,7 +1918,7 @@ async function serializeNumberingIntoZip(doc, originalZip, newZip, compressionLe
|
|
|
1918
1918
|
}
|
|
1919
1919
|
let baseline = doc.originalBuffer ? numberingBaselines.get(doc) : void 0;
|
|
1920
1920
|
if (!baseline || baseline.originalBuffer !== doc.originalBuffer) {
|
|
1921
|
-
const originalXml = await file.async("
|
|
1921
|
+
const originalXml = await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1922
1922
|
baseline = {
|
|
1923
1923
|
originalBuffer: doc.originalBuffer,
|
|
1924
1924
|
originalXml,
|
|
@@ -1936,7 +1936,7 @@ async function serializeNumberingIntoZip(doc, originalZip, newZip, compressionLe
|
|
|
1936
1936
|
writeZipPart({
|
|
1937
1937
|
zip: newZip,
|
|
1938
1938
|
path: file.name,
|
|
1939
|
-
data: patched,
|
|
1939
|
+
data: encodeUtf8(patched),
|
|
1940
1940
|
options: {
|
|
1941
1941
|
compression: "DEFLATE",
|
|
1942
1942
|
compressionOptions: { level: compressionLevel }
|
|
@@ -2053,7 +2053,7 @@ async function planAddedStyles(doc, originalZip) {
|
|
|
2053
2053
|
const styles = doc.package.styles;
|
|
2054
2054
|
if (!styles || styles.styles.length === 0) return { type: "unchanged" };
|
|
2055
2055
|
const file = findNotePartEntry(originalZip, STYLES_PART_PATH);
|
|
2056
|
-
const originalXml = file ? await file.async("
|
|
2056
|
+
const originalXml = file ? await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true })) : null;
|
|
2057
2057
|
const rootName = originalXml === null ? void 0 : /<(?![?!])(?<name>[^\s/>]+)/u.exec(originalXml)?.groups?.["name"];
|
|
2058
2058
|
const rootClose = originalXml !== null && rootName !== void 0 && getLocalName(rootName) === "styles" ? originalXml.lastIndexOf(`</${rootName}>`) : -1;
|
|
2059
2059
|
if (file === null || originalXml === null || rootClose < 0) return {
|
|
@@ -2094,7 +2094,7 @@ async function serializeAddedStylesIntoZip(doc, originalZip, newZip, compression
|
|
|
2094
2094
|
writeZipPart({
|
|
2095
2095
|
zip: newZip,
|
|
2096
2096
|
path: plan.path,
|
|
2097
|
-
data: plan.xml,
|
|
2097
|
+
data: encodeUtf8(plan.xml),
|
|
2098
2098
|
options: {
|
|
2099
2099
|
compression: "DEFLATE",
|
|
2100
2100
|
compressionOptions: { level: compressionLevel }
|
|
@@ -2137,7 +2137,7 @@ const notePartXmlFor = ({ patch, originalXml, replacementXml, hasDirtyParagraph,
|
|
|
2137
2137
|
async function patchNotePartIntoZip({ conventionalLowerPath, currentXml, replacementXml, baselineFrom, elementName, changedNoteParaIds, originalZip, newZip, compressionLevel }) {
|
|
2138
2138
|
const file = findNotePartEntry(originalZip, conventionalLowerPath);
|
|
2139
2139
|
if (!file) return;
|
|
2140
|
-
const originalXml = await file.async("
|
|
2140
|
+
const originalXml = await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
2141
2141
|
const baselineXml = baselineFrom(originalXml);
|
|
2142
2142
|
const effectiveChangedNoteParaIds = changedNoteParaIds ?? collectChangedNoteParaIds(baselineXml, currentXml);
|
|
2143
2143
|
const currentParaIds = collectParaIds(currentXml);
|
|
@@ -2160,7 +2160,7 @@ async function patchNotePartIntoZip({ conventionalLowerPath, currentXml, replace
|
|
|
2160
2160
|
writeZipPart({
|
|
2161
2161
|
zip: newZip,
|
|
2162
2162
|
path: file.name,
|
|
2163
|
-
data: patchedXml,
|
|
2163
|
+
data: encodeUtf8(patchedXml),
|
|
2164
2164
|
options: {
|
|
2165
2165
|
compression: "DEFLATE",
|
|
2166
2166
|
compressionOptions: { level: compressionLevel }
|
|
@@ -2265,7 +2265,7 @@ const createEmptyDocxZip = ({ creator, application }) => {
|
|
|
2265
2265
|
writeZipPart({
|
|
2266
2266
|
zip,
|
|
2267
2267
|
path: "[Content_Types].xml",
|
|
2268
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2268
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2269
2269
|
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
|
2270
2270
|
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
|
|
2271
2271
|
<Default Extension="xml" ContentType="application/xml"/>
|
|
@@ -2273,30 +2273,30 @@ const createEmptyDocxZip = ({ creator, application }) => {
|
|
|
2273
2273
|
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
|
|
2274
2274
|
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
|
|
2275
2275
|
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
|
|
2276
|
-
</Types>`
|
|
2276
|
+
</Types>`)
|
|
2277
2277
|
});
|
|
2278
2278
|
writeZipPart({
|
|
2279
2279
|
zip,
|
|
2280
2280
|
path: "_rels/.rels",
|
|
2281
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2281
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2282
2282
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
2283
2283
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
|
|
2284
2284
|
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
|
|
2285
2285
|
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
|
|
2286
|
-
</Relationships>`
|
|
2286
|
+
</Relationships>`)
|
|
2287
2287
|
});
|
|
2288
2288
|
writeZipPart({
|
|
2289
2289
|
zip,
|
|
2290
2290
|
path: "word/_rels/document.xml.rels",
|
|
2291
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2291
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2292
2292
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
2293
2293
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
|
|
2294
|
-
</Relationships>`
|
|
2294
|
+
</Relationships>`)
|
|
2295
2295
|
});
|
|
2296
2296
|
writeZipPart({
|
|
2297
2297
|
zip,
|
|
2298
2298
|
path: "word/document.xml",
|
|
2299
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2299
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2300
2300
|
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
|
2301
2301
|
<w:body>
|
|
2302
2302
|
<w:p>
|
|
@@ -2309,29 +2309,29 @@ const createEmptyDocxZip = ({ creator, application }) => {
|
|
|
2309
2309
|
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
|
|
2310
2310
|
</w:sectPr>
|
|
2311
2311
|
</w:body>
|
|
2312
|
-
</w:document>`
|
|
2312
|
+
</w:document>`)
|
|
2313
2313
|
});
|
|
2314
2314
|
writeZipPart({
|
|
2315
2315
|
zip,
|
|
2316
2316
|
path: STYLES_PART_PATH,
|
|
2317
|
-
data: SEED_STYLES_XML
|
|
2317
|
+
data: encodeUtf8(SEED_STYLES_XML)
|
|
2318
2318
|
});
|
|
2319
2319
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2320
2320
|
writeZipPart({
|
|
2321
2321
|
zip,
|
|
2322
2322
|
path: "docProps/core.xml",
|
|
2323
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2323
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2324
2324
|
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">${creator === void 0 ? "" : `\n <dc:creator>${escapeXmlText(creator)}</dc:creator>`}
|
|
2325
2325
|
<dcterms:created xsi:type="dcterms:W3CDTF">${now}</dcterms:created>
|
|
2326
2326
|
<dcterms:modified xsi:type="dcterms:W3CDTF">${now}</dcterms:modified>
|
|
2327
|
-
</cp:coreProperties>`
|
|
2327
|
+
</cp:coreProperties>`)
|
|
2328
2328
|
});
|
|
2329
2329
|
writeZipPart({
|
|
2330
2330
|
zip,
|
|
2331
2331
|
path: "docProps/app.xml",
|
|
2332
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2332
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2333
2333
|
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">${application === void 0 ? "" : `\n <Application>${escapeXmlText(application)}</Application>\n <AppVersion>${CREATED_APP_VERSION}</AppVersion>`}
|
|
2334
|
-
</Properties>`
|
|
2334
|
+
</Properties>`)
|
|
2335
2335
|
});
|
|
2336
2336
|
return zip;
|
|
2337
2337
|
};
|
|
@@ -2364,7 +2364,7 @@ async function createDocx(doc, properties = {}) {
|
|
|
2364
2364
|
originalZip: zip,
|
|
2365
2365
|
outputZip: zip,
|
|
2366
2366
|
originalDocument: void 0,
|
|
2367
|
-
originalCorePropertiesXml: await zip.file("docProps/core.xml")?.async("
|
|
2367
|
+
originalCorePropertiesXml: await zip.file("docProps/core.xml")?.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true })),
|
|
2368
2368
|
compressionLevel: 6,
|
|
2369
2369
|
updateModifiedDate: true,
|
|
2370
2370
|
onDiagnostic: properties.onDiagnostic,
|
|
@@ -2382,19 +2382,19 @@ const createDocumentSeedZip = async (doc, properties) => {
|
|
|
2382
2382
|
writeZipPart({
|
|
2383
2383
|
zip,
|
|
2384
2384
|
path: STYLES_PART_PATH,
|
|
2385
|
-
data: serializeStylesXml(styleDefinitions)
|
|
2385
|
+
data: encodeUtf8(serializeStylesXml(styleDefinitions))
|
|
2386
2386
|
});
|
|
2387
2387
|
} else writeZipPart({
|
|
2388
2388
|
zip,
|
|
2389
2389
|
path: STYLES_PART_PATH,
|
|
2390
|
-
data: seedStylesXmlWith(missingNoteReferenceStyles(void 0, noteReferenceNeeds(doc.package)))
|
|
2390
|
+
data: encodeUtf8(seedStylesXmlWith(missingNoteReferenceStyles(void 0, noteReferenceNeeds(doc.package))))
|
|
2391
2391
|
});
|
|
2392
2392
|
const numbering = doc.package.numbering;
|
|
2393
2393
|
if (numbering && (numbering.abstractNums.length > 0 || numbering.nums.length > 0)) {
|
|
2394
2394
|
writeZipPart({
|
|
2395
2395
|
zip,
|
|
2396
2396
|
path: "word/numbering.xml",
|
|
2397
|
-
data: serializeNumberingXml(numbering)
|
|
2397
|
+
data: encodeUtf8(serializeNumberingXml(numbering))
|
|
2398
2398
|
});
|
|
2399
2399
|
relationships.push(relationshipXml(nextRelationshipId, "numbering", "numbering.xml"));
|
|
2400
2400
|
overrides.push(overrideXml("/word/numbering.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"));
|
|
@@ -2404,7 +2404,7 @@ const createDocumentSeedZip = async (doc, properties) => {
|
|
|
2404
2404
|
writeZipPart({
|
|
2405
2405
|
zip,
|
|
2406
2406
|
path: "word/theme/theme1.xml",
|
|
2407
|
-
data: serializeThemeXml(doc.package.theme)
|
|
2407
|
+
data: encodeUtf8(serializeThemeXml(doc.package.theme))
|
|
2408
2408
|
});
|
|
2409
2409
|
relationships.push(relationshipXml(nextRelationshipId, "theme", "theme/theme1.xml"));
|
|
2410
2410
|
overrides.push(overrideXml("/word/theme/theme1.xml", "application/vnd.openxmlformats-officedocument.theme+xml"));
|
|
@@ -2414,7 +2414,7 @@ const createDocumentSeedZip = async (doc, properties) => {
|
|
|
2414
2414
|
writeZipPart({
|
|
2415
2415
|
zip,
|
|
2416
2416
|
path: "word/fontTable.xml",
|
|
2417
|
-
data: serializeFontTableXml(doc.package.fontTable)
|
|
2417
|
+
data: encodeUtf8(serializeFontTableXml(doc.package.fontTable))
|
|
2418
2418
|
});
|
|
2419
2419
|
relationships.push(relationshipXml(nextRelationshipId, "fontTable", "fontTable.xml"));
|
|
2420
2420
|
overrides.push(overrideXml("/word/fontTable.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"));
|
|
@@ -2424,7 +2424,7 @@ const createDocumentSeedZip = async (doc, properties) => {
|
|
|
2424
2424
|
writeZipPart({
|
|
2425
2425
|
zip,
|
|
2426
2426
|
path: "word/settings.xml",
|
|
2427
|
-
data: serializeSettingsXml(doc.package.settings)
|
|
2427
|
+
data: encodeUtf8(serializeSettingsXml(doc.package.settings))
|
|
2428
2428
|
});
|
|
2429
2429
|
relationships.push(relationshipXml(nextRelationshipId, "settings", "settings.xml"));
|
|
2430
2430
|
overrides.push(overrideXml("/word/settings.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"));
|
|
@@ -2432,7 +2432,7 @@ const createDocumentSeedZip = async (doc, properties) => {
|
|
|
2432
2432
|
writeZipPart({
|
|
2433
2433
|
zip,
|
|
2434
2434
|
path: "word/_rels/document.xml.rels",
|
|
2435
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${relationships.join("")}</Relationships>`
|
|
2435
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${relationships.join("")}</Relationships>`)
|
|
2436
2436
|
});
|
|
2437
2437
|
if (overrides.length > 0) {
|
|
2438
2438
|
const contentTypesFile = zip.file("[Content_Types].xml");
|
|
@@ -2440,7 +2440,7 @@ const createDocumentSeedZip = async (doc, properties) => {
|
|
|
2440
2440
|
writeZipPart({
|
|
2441
2441
|
zip,
|
|
2442
2442
|
path: "[Content_Types].xml",
|
|
2443
|
-
data: (await contentTypesFile.async("
|
|
2443
|
+
data: encodeUtf8((await contentTypesFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }))).replace("</Types>", `${overrides.join("")}\n</Types>`))
|
|
2444
2444
|
});
|
|
2445
2445
|
}
|
|
2446
2446
|
return zip;
|