@stll/folio-core 0.60.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 +13 -0
- 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 +3 -1
- 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/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 +13 -4
- package/dist/controller/layoutSession.d.ts +2 -1
- package/dist/display-list/build/imagePrimitives.js +3 -6
- 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/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/packageParts.js +6 -5
- package/dist/docx/paragraphParser.js +6 -4
- package/dist/docx/parser.js +5 -4
- package/dist/docx/preservedRunContent.js +11 -2
- package/dist/docx/removeHeaderFooterParts.js +8 -7
- package/dist/docx/replyToComment.js +3 -13
- package/dist/docx/rezip.js +88 -89
- 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/selectiveSave.js +15 -14
- package/dist/docx/serializer/runSerializer.js +3 -2
- package/dist/docx/serializer/tableSerializer.js +2 -1
- 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/fontsourceFaces.js +2 -1
- 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/index.d.ts +3 -1
- 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 +2 -0
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +4 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +13 -3
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +5 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +12 -15
- package/dist/layout-bridge/convert/paragraphRuns.js +2 -1
- package/dist/layout-engine/measure/crossRunWords.js +12 -2
- 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/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/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/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/plugins/transactionInvariants.js +6 -1
- 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/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 +51 -25
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";
|
|
@@ -200,7 +201,7 @@ 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;
|
|
204
205
|
if (sourceCommentsXml !== void 0 && canReplayCommentsPart(doc, sourceCommentsXml)) return;
|
|
205
206
|
if (comments.length === 0) {
|
|
206
207
|
const ownsCommentsPart = hasOwnedCommentsPart(doc);
|
|
@@ -211,7 +212,7 @@ async function serializeCommentsToZip(doc, zip, compressionLevel) {
|
|
|
211
212
|
writeZipPart({
|
|
212
213
|
zip,
|
|
213
214
|
path: sourceCommentsFile?.name ?? "word/comments.xml",
|
|
214
|
-
data: commentsXml,
|
|
215
|
+
data: encodeUtf8(commentsXml),
|
|
215
216
|
options: {
|
|
216
217
|
compression: "DEFLATE",
|
|
217
218
|
compressionOptions: { level: compressionLevel }
|
|
@@ -247,7 +248,7 @@ async function syncCommentsExtendedPart(plan, zip, compressionLevel) {
|
|
|
247
248
|
writeZipPart({
|
|
248
249
|
zip,
|
|
249
250
|
path: existing?.name ?? "word/commentsExtended.xml",
|
|
250
|
-
data: xml,
|
|
251
|
+
data: encodeUtf8(xml),
|
|
251
252
|
options: {
|
|
252
253
|
compression: "DEFLATE",
|
|
253
254
|
compressionOptions: { level: compressionLevel }
|
|
@@ -260,12 +261,12 @@ async function syncCommentsExtendedPart(plan, zip, compressionLevel) {
|
|
|
260
261
|
async function transformPackagingFile(zip, path, transform, compressionLevel) {
|
|
261
262
|
const file = zip.file(path);
|
|
262
263
|
if (!file) return;
|
|
263
|
-
const xml = await file.async("
|
|
264
|
+
const xml = await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
264
265
|
const next = transform(xml);
|
|
265
266
|
if (next !== xml) writeZipPart({
|
|
266
267
|
zip,
|
|
267
268
|
path,
|
|
268
|
-
data: next,
|
|
269
|
+
data: encodeUtf8(next),
|
|
269
270
|
options: {
|
|
270
271
|
compression: "DEFLATE",
|
|
271
272
|
compressionOptions: { level: compressionLevel }
|
|
@@ -351,7 +352,7 @@ function collectDocxParts(doc, zip) {
|
|
|
351
352
|
}
|
|
352
353
|
async function readRelsOrStub(zip, relsPath) {
|
|
353
354
|
const file = zip.file(relsPath);
|
|
354
|
-
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>");
|
|
355
356
|
}
|
|
356
357
|
function findMaxImageNum(zip) {
|
|
357
358
|
let maxImageNum = 0;
|
|
@@ -368,7 +369,7 @@ async function registerImageExtensions(zip, extensions, compressionLevel) {
|
|
|
368
369
|
if (extensions.size === 0) return;
|
|
369
370
|
const ctFile = zip.file("[Content_Types].xml");
|
|
370
371
|
if (!ctFile) return;
|
|
371
|
-
let ctXml = await ctFile.async("
|
|
372
|
+
let ctXml = await ctFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
372
373
|
let changed = false;
|
|
373
374
|
for (const ext of extensions) {
|
|
374
375
|
if (ctXml.includes(`Extension="${ext}"`)) continue;
|
|
@@ -380,7 +381,7 @@ async function registerImageExtensions(zip, extensions, compressionLevel) {
|
|
|
380
381
|
writeZipPart({
|
|
381
382
|
zip,
|
|
382
383
|
path: "[Content_Types].xml",
|
|
383
|
-
data: ctXml,
|
|
384
|
+
data: encodeUtf8(ctXml),
|
|
384
385
|
options: {
|
|
385
386
|
compression: "DEFLATE",
|
|
386
387
|
compressionOptions: { level: compressionLevel }
|
|
@@ -420,11 +421,8 @@ function decodeDataUrl(dataUrl) {
|
|
|
420
421
|
const payload = match.groups["data"];
|
|
421
422
|
const parameters = match.groups["parameters"];
|
|
422
423
|
let bytes;
|
|
423
|
-
if (parameters.split(";").some((parameter) => parameter.toLowerCase() === "base64"))
|
|
424
|
-
|
|
425
|
-
bytes = new Uint8Array(binary.length);
|
|
426
|
-
for (let i = 0; i < binary.length; i++) bytes[i] = binary.codePointAt(i) ?? 0;
|
|
427
|
-
} 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));
|
|
428
426
|
return {
|
|
429
427
|
data: bytes.slice().buffer,
|
|
430
428
|
extension: MIME_TO_EXT[match.groups["mime"]] ?? "png"
|
|
@@ -458,7 +456,7 @@ async function processNewImages(parts, zip, compressionLevel) {
|
|
|
458
456
|
writeZipPart({
|
|
459
457
|
zip,
|
|
460
458
|
path: mediaPath,
|
|
461
|
-
data,
|
|
459
|
+
data: new Uint8Array(data),
|
|
462
460
|
options: {
|
|
463
461
|
compression: "DEFLATE",
|
|
464
462
|
compressionOptions: { level: compressionLevel }
|
|
@@ -476,7 +474,7 @@ async function processNewImages(parts, zip, compressionLevel) {
|
|
|
476
474
|
if (relEntries.length > 0) writeZipPart({
|
|
477
475
|
zip,
|
|
478
476
|
path: relsPath,
|
|
479
|
-
data: relsXml.replace("</Relationships>", `${relEntries.join("")}</Relationships>`),
|
|
477
|
+
data: encodeUtf8(relsXml.replace("</Relationships>", `${relEntries.join("")}</Relationships>`)),
|
|
480
478
|
options: {
|
|
481
479
|
compression: "DEFLATE",
|
|
482
480
|
compressionOptions: { level: compressionLevel }
|
|
@@ -496,7 +494,7 @@ const materializeEmbeddedMedia = async ({ document, zip, compressionLevel }) =>
|
|
|
496
494
|
writeZipPart({
|
|
497
495
|
zip,
|
|
498
496
|
path: media.path,
|
|
499
|
-
data: media.data,
|
|
497
|
+
data: new Uint8Array(media.data),
|
|
500
498
|
options: {
|
|
501
499
|
compression: "DEFLATE",
|
|
502
500
|
compressionOptions: { level: compressionLevel }
|
|
@@ -558,7 +556,7 @@ const publishCanonicalImageResources = async ({ document, zip, compressionLevel
|
|
|
558
556
|
writeZipPart({
|
|
559
557
|
zip,
|
|
560
558
|
path: absolute,
|
|
561
|
-
data: media.data,
|
|
559
|
+
data: new Uint8Array(media.data),
|
|
562
560
|
options: {
|
|
563
561
|
compression: "DEFLATE",
|
|
564
562
|
compressionOptions: { level: compressionLevel }
|
|
@@ -588,7 +586,7 @@ const publishCanonicalImageResources = async ({ document, zip, compressionLevel
|
|
|
588
586
|
if (changed) writeZipPart({
|
|
589
587
|
zip,
|
|
590
588
|
path: relsPath,
|
|
591
|
-
data: xml,
|
|
589
|
+
data: encodeUtf8(xml),
|
|
592
590
|
options: {
|
|
593
591
|
compression: "DEFLATE",
|
|
594
592
|
compressionOptions: { level: compressionLevel }
|
|
@@ -739,7 +737,7 @@ async function processNewHyperlinks(parts, zip, compressionLevel) {
|
|
|
739
737
|
writeZipPart({
|
|
740
738
|
zip,
|
|
741
739
|
path: relsPath,
|
|
742
|
-
data: captureVerbatimXml(root),
|
|
740
|
+
data: encodeUtf8(captureVerbatimXml(root)),
|
|
743
741
|
options: {
|
|
744
742
|
compression: "DEFLATE",
|
|
745
743
|
compressionOptions: { level: compressionLevel }
|
|
@@ -763,7 +761,7 @@ async function processNewHyperlinks(parts, zip, compressionLevel) {
|
|
|
763
761
|
const normalizePackageIdsInZip = async (zip, compressionLevel) => {
|
|
764
762
|
const xmlParts = /* @__PURE__ */ new Map();
|
|
765
763
|
for (const [path, file] of Object.entries(zip.files)) if (!file.dir && path.startsWith("word/") && path.endsWith(".xml")) {
|
|
766
|
-
const xml = await file.async("
|
|
764
|
+
const xml = await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
767
765
|
assertValidOoxmlNumericIds(xml, path);
|
|
768
766
|
xmlParts.set(path, xml);
|
|
769
767
|
}
|
|
@@ -773,7 +771,7 @@ const normalizePackageIdsInZip = async (zip, compressionLevel) => {
|
|
|
773
771
|
writeZipPart({
|
|
774
772
|
zip,
|
|
775
773
|
path,
|
|
776
|
-
data: xml,
|
|
774
|
+
data: encodeUtf8(xml),
|
|
777
775
|
options: {
|
|
778
776
|
compression: "DEFLATE",
|
|
779
777
|
compressionOptions: { level: compressionLevel }
|
|
@@ -790,12 +788,12 @@ const EXTENDED_PROPERTIES_PATH = "docProps/app.xml";
|
|
|
790
788
|
const normalizeAppVersionInZip = async (zip, compressionLevel) => {
|
|
791
789
|
const extendedProperties = zip.file(EXTENDED_PROPERTIES_PATH);
|
|
792
790
|
if (!extendedProperties) return;
|
|
793
|
-
const xml = await extendedProperties.async("
|
|
791
|
+
const xml = await extendedProperties.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
794
792
|
const normalized = normalizeAppVersionInExtendedProperties(xml);
|
|
795
793
|
if (normalized !== xml) writeZipPart({
|
|
796
794
|
zip,
|
|
797
795
|
path: EXTENDED_PROPERTIES_PATH,
|
|
798
|
-
data: normalized,
|
|
796
|
+
data: encodeUtf8(normalized),
|
|
799
797
|
options: {
|
|
800
798
|
compression: "DEFLATE",
|
|
801
799
|
compressionOptions: { level: compressionLevel }
|
|
@@ -854,7 +852,7 @@ const loadParsedZipSource = async (document, buffer) => {
|
|
|
854
852
|
if (cached?.buffer === buffer) return cached;
|
|
855
853
|
const zip = await JSZip.loadAsync(buffer);
|
|
856
854
|
removeUnsafeEntries(zip);
|
|
857
|
-
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 }))]);
|
|
858
856
|
const source = {
|
|
859
857
|
buffer,
|
|
860
858
|
zip,
|
|
@@ -925,7 +923,7 @@ const finishRepack = async ({ document: sourceDocument, originalZip, outputZip,
|
|
|
925
923
|
writeZipPart({
|
|
926
924
|
zip: outputZip,
|
|
927
925
|
path: "word/document.xml",
|
|
928
|
-
data: documentXml,
|
|
926
|
+
data: encodeUtf8(documentXml),
|
|
929
927
|
options: {
|
|
930
928
|
compression: "DEFLATE",
|
|
931
929
|
compressionOptions: { level: compressionLevel }
|
|
@@ -958,10 +956,10 @@ const finishRepack = async ({ document: sourceDocument, originalZip, outputZip,
|
|
|
958
956
|
if (updateModifiedDate && originalCorePropertiesXml) writeZipPart({
|
|
959
957
|
zip: outputZip,
|
|
960
958
|
path: "docProps/core.xml",
|
|
961
|
-
data: updateCoreProperties(originalCorePropertiesXml, {
|
|
959
|
+
data: encodeUtf8(updateCoreProperties(originalCorePropertiesXml, {
|
|
962
960
|
updateModifiedDate,
|
|
963
961
|
...modifiedBy !== void 0 ? { modifiedBy } : {}
|
|
964
|
-
}),
|
|
962
|
+
})),
|
|
965
963
|
options: {
|
|
966
964
|
compression: "DEFLATE",
|
|
967
965
|
compressionOptions: { level: compressionLevel }
|
|
@@ -974,7 +972,7 @@ async function repackDocxWithSectionEndpointRemoval({ document: doc, options, se
|
|
|
974
972
|
const { compressionLevel = 6, updateModifiedDate = true, modifiedBy, changedNoteParaIds } = options;
|
|
975
973
|
const exportDocument = withoutOrphanCommentRanges(doc);
|
|
976
974
|
const originalZip = await JSZip.loadAsync(doc.originalBuffer);
|
|
977
|
-
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 }))]);
|
|
978
976
|
removeUnsafeEntries(originalZip);
|
|
979
977
|
const newZip = cloneDocxZip(originalZip);
|
|
980
978
|
return finishRepack({
|
|
@@ -1020,7 +1018,7 @@ async function repackDocxFromRaw(doc, rawContent, options = {}) {
|
|
|
1020
1018
|
writeZipPart({
|
|
1021
1019
|
zip: newZip,
|
|
1022
1020
|
path,
|
|
1023
|
-
data:
|
|
1021
|
+
data: /* @__PURE__ */ new Uint8Array(),
|
|
1024
1022
|
options: {
|
|
1025
1023
|
dir: true,
|
|
1026
1024
|
date: file.date
|
|
@@ -1029,10 +1027,11 @@ async function repackDocxFromRaw(doc, rawContent, options = {}) {
|
|
|
1029
1027
|
continue;
|
|
1030
1028
|
}
|
|
1031
1029
|
if (isUnsafePackagePath(path)) continue;
|
|
1030
|
+
const content = await file.async("arraybuffer");
|
|
1032
1031
|
writeZipPart({
|
|
1033
1032
|
zip: newZip,
|
|
1034
1033
|
path,
|
|
1035
|
-
data:
|
|
1034
|
+
data: new Uint8Array(content),
|
|
1036
1035
|
options: {
|
|
1037
1036
|
compression: "DEFLATE",
|
|
1038
1037
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1069,7 +1068,7 @@ async function repackDocxFromRaw(doc, rawContent, options = {}) {
|
|
|
1069
1068
|
writeZipPart({
|
|
1070
1069
|
zip: newZip,
|
|
1071
1070
|
path: "word/document.xml",
|
|
1072
|
-
data: documentXml,
|
|
1071
|
+
data: encodeUtf8(documentXml),
|
|
1073
1072
|
options: {
|
|
1074
1073
|
compression: "DEFLATE",
|
|
1075
1074
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1102,10 +1101,10 @@ async function repackDocxFromRaw(doc, rawContent, options = {}) {
|
|
|
1102
1101
|
if (updateModifiedDate && rawContent.corePropsXml) writeZipPart({
|
|
1103
1102
|
zip: newZip,
|
|
1104
1103
|
path: "docProps/core.xml",
|
|
1105
|
-
data: updateCoreProperties(rawContent.corePropsXml, {
|
|
1104
|
+
data: encodeUtf8(updateCoreProperties(rawContent.corePropsXml, {
|
|
1106
1105
|
updateModifiedDate,
|
|
1107
1106
|
...modifiedBy !== void 0 ? { modifiedBy } : {}
|
|
1108
|
-
}),
|
|
1107
|
+
})),
|
|
1109
1108
|
options: {
|
|
1110
1109
|
compression: "DEFLATE",
|
|
1111
1110
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1198,11 +1197,11 @@ async function dropAttachedTemplateReference(zip, compressionLevel) {
|
|
|
1198
1197
|
const settingsFile = zip.file(SETTINGS_PART);
|
|
1199
1198
|
if (!settingsFile) return;
|
|
1200
1199
|
const relsFile = zip.file(SETTINGS_RELS_PART);
|
|
1201
|
-
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 })));
|
|
1202
1201
|
if (filtered.settingsXml !== void 0) writeZipPart({
|
|
1203
1202
|
zip,
|
|
1204
1203
|
path: SETTINGS_PART,
|
|
1205
|
-
data: filtered.settingsXml,
|
|
1204
|
+
data: encodeUtf8(filtered.settingsXml),
|
|
1206
1205
|
options: {
|
|
1207
1206
|
compression: "DEFLATE",
|
|
1208
1207
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1211,7 +1210,7 @@ async function dropAttachedTemplateReference(zip, compressionLevel) {
|
|
|
1211
1210
|
if (filtered.relsXml !== void 0) writeZipPart({
|
|
1212
1211
|
zip,
|
|
1213
1212
|
path: SETTINGS_RELS_PART,
|
|
1214
|
-
data: filtered.relsXml,
|
|
1213
|
+
data: encodeUtf8(filtered.relsXml),
|
|
1215
1214
|
options: {
|
|
1216
1215
|
compression: "DEFLATE",
|
|
1217
1216
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1225,14 +1224,14 @@ async function dropAttachedTemplateReference(zip, compressionLevel) {
|
|
|
1225
1224
|
async function ensureCommentsContentType(zip, compressionLevel) {
|
|
1226
1225
|
const ctFile = zip.file("[Content_Types].xml");
|
|
1227
1226
|
if (!ctFile) return;
|
|
1228
|
-
let ctXml = await ctFile.async("
|
|
1227
|
+
let ctXml = await ctFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1229
1228
|
if (ctXml.toLowerCase().includes("/word/comments.xml")) return;
|
|
1230
1229
|
const commentsPartPath = findZipEntryCaseInsensitive(zip, "word/comments.xml")?.name ?? "word/comments.xml";
|
|
1231
1230
|
ctXml = ctXml.replace("</Types>", `<Override PartName="/${commentsPartPath}" ContentType="${COMMENTS_CONTENT_TYPE}"/></Types>`);
|
|
1232
1231
|
writeZipPart({
|
|
1233
1232
|
zip,
|
|
1234
1233
|
path: "[Content_Types].xml",
|
|
1235
|
-
data: ctXml,
|
|
1234
|
+
data: encodeUtf8(ctXml),
|
|
1236
1235
|
options: {
|
|
1237
1236
|
compression: "DEFLATE",
|
|
1238
1237
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1247,7 +1246,7 @@ async function ensureCommentsRelationship(zip, compressionLevel) {
|
|
|
1247
1246
|
const relsPath = "word/_rels/document.xml.rels";
|
|
1248
1247
|
const relsFile = zip.file(relsPath);
|
|
1249
1248
|
if (!relsFile) return;
|
|
1250
|
-
let relsXml = await relsFile.async("
|
|
1249
|
+
let relsXml = await relsFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1251
1250
|
if (relsXml.toLowerCase().includes("comments.xml")) return;
|
|
1252
1251
|
const commentsPartPath = findZipEntryCaseInsensitive(zip, "word/comments.xml")?.name ?? "word/comments.xml";
|
|
1253
1252
|
const newRId = `rId${findMaxRId(relsXml) + 1}`;
|
|
@@ -1255,7 +1254,7 @@ async function ensureCommentsRelationship(zip, compressionLevel) {
|
|
|
1255
1254
|
writeZipPart({
|
|
1256
1255
|
zip,
|
|
1257
1256
|
path: relsPath,
|
|
1258
|
-
data: relsXml,
|
|
1257
|
+
data: encodeUtf8(relsXml),
|
|
1259
1258
|
options: {
|
|
1260
1259
|
compression: "DEFLATE",
|
|
1261
1260
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1276,7 +1275,7 @@ async function updateDocumentXml(originalBuffer, newDocumentXml, options = {}) {
|
|
|
1276
1275
|
writeZipPart({
|
|
1277
1276
|
zip,
|
|
1278
1277
|
path: "word/document.xml",
|
|
1279
|
-
data: newDocumentXml,
|
|
1278
|
+
data: encodeUtf8(newDocumentXml),
|
|
1280
1279
|
options: {
|
|
1281
1280
|
compression: "DEFLATE",
|
|
1282
1281
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1303,7 +1302,7 @@ async function updateXmlFile(originalBuffer, path, content, options = {}) {
|
|
|
1303
1302
|
writeZipPart({
|
|
1304
1303
|
zip,
|
|
1305
1304
|
path,
|
|
1306
|
-
data: content,
|
|
1305
|
+
data: encodeUtf8(content),
|
|
1307
1306
|
options: {
|
|
1308
1307
|
compression: "DEFLATE",
|
|
1309
1308
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1341,7 +1340,7 @@ async function applyUpdatesToZip(zip, updates, options = {}) {
|
|
|
1341
1340
|
for (const [path, content] of updates) writeZipPart({
|
|
1342
1341
|
zip,
|
|
1343
1342
|
path,
|
|
1344
|
-
data: content,
|
|
1343
|
+
data: typeof content === "string" ? encodeUtf8(content) : new Uint8Array(content),
|
|
1345
1344
|
options: {
|
|
1346
1345
|
compression: "DEFLATE",
|
|
1347
1346
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1366,14 +1365,14 @@ async function addRelationship(originalBuffer, relationship) {
|
|
|
1366
1365
|
const relsPath = "word/_rels/document.xml.rels";
|
|
1367
1366
|
const relsFile = zip.file(relsPath);
|
|
1368
1367
|
if (!relsFile) panic("document.xml.rels not found in DOCX");
|
|
1369
|
-
const relsXml = await relsFile.async("
|
|
1368
|
+
const relsXml = await relsFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1370
1369
|
const newRId = `rId${findMaxRId(relsXml) + 1}`;
|
|
1371
1370
|
const targetModeAttr = relationship.targetMode === "External" ? " TargetMode=\"External\"" : "";
|
|
1372
1371
|
const newRelElement = `<Relationship Id="${newRId}" Type="${relationship.type}" Target="${escapeXmlAttribute(relationship.target)}"${targetModeAttr}/>`;
|
|
1373
1372
|
writeZipPart({
|
|
1374
1373
|
zip,
|
|
1375
1374
|
path: relsPath,
|
|
1376
|
-
data: relsXml.replace("</Relationships>", `${newRelElement}</Relationships>`)
|
|
1375
|
+
data: encodeUtf8(relsXml.replace("</Relationships>", `${newRelElement}</Relationships>`))
|
|
1377
1376
|
});
|
|
1378
1377
|
return {
|
|
1379
1378
|
buffer: await zip.generateAsync({
|
|
@@ -1399,7 +1398,7 @@ async function addMedia(originalBuffer, filename, data, mimeType) {
|
|
|
1399
1398
|
writeZipPart({
|
|
1400
1399
|
zip,
|
|
1401
1400
|
path: mediaPath,
|
|
1402
|
-
data
|
|
1401
|
+
data: new Uint8Array(data)
|
|
1403
1402
|
});
|
|
1404
1403
|
const relResult = await addRelationship(await zip.generateAsync({ type: "arraybuffer" }), {
|
|
1405
1404
|
type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
|
@@ -1407,7 +1406,7 @@ async function addMedia(originalBuffer, filename, data, mimeType) {
|
|
|
1407
1406
|
});
|
|
1408
1407
|
const contentTypesFile = zip.file("[Content_Types].xml");
|
|
1409
1408
|
if (contentTypesFile) {
|
|
1410
|
-
const contentTypesXml = await contentTypesFile.async("
|
|
1409
|
+
const contentTypesXml = await contentTypesFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1411
1410
|
const extension = filename.split(".").pop()?.toLowerCase() || "";
|
|
1412
1411
|
if (!contentTypesXml.includes(`Extension="${extension}"`) && extension) {
|
|
1413
1412
|
const extensionElement = `<Default Extension="${extension}" ContentType="${getContentTypeForExtension(extension, mimeType)}"/>`;
|
|
@@ -1416,7 +1415,7 @@ async function addMedia(originalBuffer, filename, data, mimeType) {
|
|
|
1416
1415
|
writeZipPart({
|
|
1417
1416
|
zip: finalZip,
|
|
1418
1417
|
path: "[Content_Types].xml",
|
|
1419
|
-
data: updatedContentTypes
|
|
1418
|
+
data: encodeUtf8(updatedContentTypes)
|
|
1420
1419
|
});
|
|
1421
1420
|
return {
|
|
1422
1421
|
buffer: await finalZip.generateAsync({
|
|
@@ -1566,7 +1565,7 @@ async function materializeNewHeaderFooterParts(doc, zip, compressionLevel) {
|
|
|
1566
1565
|
if (relEntries.length > 0) writeZipPart({
|
|
1567
1566
|
zip,
|
|
1568
1567
|
path: relsPath,
|
|
1569
|
-
data: relsXml.replace("</Relationships>", `${relEntries.join("")}</Relationships>`),
|
|
1568
|
+
data: encodeUtf8(relsXml.replace("</Relationships>", `${relEntries.join("")}</Relationships>`)),
|
|
1570
1569
|
options: {
|
|
1571
1570
|
compression: "DEFLATE",
|
|
1572
1571
|
compressionOptions
|
|
@@ -1574,12 +1573,12 @@ async function materializeNewHeaderFooterParts(doc, zip, compressionLevel) {
|
|
|
1574
1573
|
});
|
|
1575
1574
|
const ctFile = zip.file("[Content_Types].xml");
|
|
1576
1575
|
if (ctFile) {
|
|
1577
|
-
const original = await ctFile.async("
|
|
1576
|
+
const original = await ctFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1578
1577
|
const updated = registerContentTypeParts(original, contentTypeParts);
|
|
1579
1578
|
if (updated !== original) writeZipPart({
|
|
1580
1579
|
zip,
|
|
1581
1580
|
path: "[Content_Types].xml",
|
|
1582
|
-
data: updated,
|
|
1581
|
+
data: encodeUtf8(updated),
|
|
1583
1582
|
options: {
|
|
1584
1583
|
compression: "DEFLATE",
|
|
1585
1584
|
compressionOptions
|
|
@@ -1732,7 +1731,7 @@ async function rebindWatermarkRelIds({ document: doc, zip, compressionLevel, bod
|
|
|
1732
1731
|
if (xml) writeZipPart({
|
|
1733
1732
|
zip,
|
|
1734
1733
|
path,
|
|
1735
|
-
data: xml,
|
|
1734
|
+
data: encodeUtf8(xml),
|
|
1736
1735
|
options: {
|
|
1737
1736
|
compression: "DEFLATE",
|
|
1738
1737
|
compressionOptions
|
|
@@ -1759,7 +1758,7 @@ async function collectHeaderFooterUpdates(doc, { sourceZip, onDiagnostic }) {
|
|
|
1759
1758
|
if (rel && rel.type === type && rel.target) {
|
|
1760
1759
|
const path = resolveRelativePath(documentRelsPath, rel.target);
|
|
1761
1760
|
const sourceFile = findZipEntryCaseInsensitive(sourceZip, path.toLowerCase());
|
|
1762
|
-
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();
|
|
1763
1762
|
updates.set(path, serializeHeaderFooter(headerFooter, {
|
|
1764
1763
|
path,
|
|
1765
1764
|
bindings,
|
|
@@ -1779,7 +1778,7 @@ async function serializeHeadersFootersToZip({ doc, zip, compressionLevel, onDiag
|
|
|
1779
1778
|
})) writeZipPart({
|
|
1780
1779
|
zip,
|
|
1781
1780
|
path: filename,
|
|
1782
|
-
data: xml,
|
|
1781
|
+
data: encodeUtf8(xml),
|
|
1783
1782
|
options: {
|
|
1784
1783
|
compression: "DEFLATE",
|
|
1785
1784
|
compressionOptions
|
|
@@ -1835,25 +1834,25 @@ async function materializeNewNotePart({ contentType, newZip, partPath, relations
|
|
|
1835
1834
|
const relationshipsFile = findNotePartEntry(newZip, "word/_rels/document.xml.rels");
|
|
1836
1835
|
if (!contentTypesFile || !relationshipsFile) throw new DocxPackageFidelityError(`Cannot create ${partPath}: the DOCX package is missing content types or document relationships`);
|
|
1837
1836
|
const compressionOptions = { level: compressionLevel };
|
|
1838
|
-
const contentTypesXml = await contentTypesFile.async("
|
|
1837
|
+
const contentTypesXml = await contentTypesFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1839
1838
|
const partName = `/${partPath}`;
|
|
1840
1839
|
if (!contentTypesXml.toLowerCase().includes(partName.toLowerCase())) writeZipPart({
|
|
1841
1840
|
zip: newZip,
|
|
1842
1841
|
path: contentTypesFile.name,
|
|
1843
|
-
data: contentTypesXml.replace("</Types>", () => `<Override PartName="${partName}" ContentType="${contentType}"/></Types>`),
|
|
1842
|
+
data: encodeUtf8(contentTypesXml.replace("</Types>", () => `<Override PartName="${partName}" ContentType="${contentType}"/></Types>`)),
|
|
1844
1843
|
options: {
|
|
1845
1844
|
compression: "DEFLATE",
|
|
1846
1845
|
compressionOptions
|
|
1847
1846
|
}
|
|
1848
1847
|
});
|
|
1849
|
-
const relationshipsXml = await relationshipsFile.async("
|
|
1848
|
+
const relationshipsXml = await relationshipsFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1850
1849
|
if (!relationshipsXml.includes(relationshipType)) {
|
|
1851
1850
|
const relationshipId = `rId${findMaxRId(relationshipsXml) + 1}`;
|
|
1852
1851
|
const target = partPath.slice(5);
|
|
1853
1852
|
writeZipPart({
|
|
1854
1853
|
zip: newZip,
|
|
1855
1854
|
path: relationshipsFile.name,
|
|
1856
|
-
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>`)),
|
|
1857
1856
|
options: {
|
|
1858
1857
|
compression: "DEFLATE",
|
|
1859
1858
|
compressionOptions
|
|
@@ -1863,7 +1862,7 @@ async function materializeNewNotePart({ contentType, newZip, partPath, relations
|
|
|
1863
1862
|
writeZipPart({
|
|
1864
1863
|
zip: newZip,
|
|
1865
1864
|
path: partPath,
|
|
1866
|
-
data: serializedPart,
|
|
1865
|
+
data: encodeUtf8(serializedPart),
|
|
1867
1866
|
options: {
|
|
1868
1867
|
compression: "DEFLATE",
|
|
1869
1868
|
compressionOptions
|
|
@@ -1887,14 +1886,14 @@ async function serializeHeaderFooterSettingsIntoZip(doc, zip, compressionLevel)
|
|
|
1887
1886
|
});
|
|
1888
1887
|
return;
|
|
1889
1888
|
}
|
|
1890
|
-
const xml = await file.async("
|
|
1889
|
+
const xml = await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1891
1890
|
if (parseSettings(xml).evenAndOddHeaders === enabled) return;
|
|
1892
1891
|
const patched = updateEvenAndOddHeaders(xml, enabled);
|
|
1893
1892
|
if (patched === null) throw new DocxPackageFidelityError("Cannot update malformed header/footer settings");
|
|
1894
1893
|
writeZipPart({
|
|
1895
1894
|
zip,
|
|
1896
1895
|
path: file.name,
|
|
1897
|
-
data: patched,
|
|
1896
|
+
data: encodeUtf8(patched),
|
|
1898
1897
|
options: {
|
|
1899
1898
|
compression: "DEFLATE",
|
|
1900
1899
|
compressionOptions: { level: compressionLevel }
|
|
@@ -1919,7 +1918,7 @@ async function serializeNumberingIntoZip(doc, originalZip, newZip, compressionLe
|
|
|
1919
1918
|
}
|
|
1920
1919
|
let baseline = doc.originalBuffer ? numberingBaselines.get(doc) : void 0;
|
|
1921
1920
|
if (!baseline || baseline.originalBuffer !== doc.originalBuffer) {
|
|
1922
|
-
const originalXml = await file.async("
|
|
1921
|
+
const originalXml = await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
1923
1922
|
baseline = {
|
|
1924
1923
|
originalBuffer: doc.originalBuffer,
|
|
1925
1924
|
originalXml,
|
|
@@ -1937,7 +1936,7 @@ async function serializeNumberingIntoZip(doc, originalZip, newZip, compressionLe
|
|
|
1937
1936
|
writeZipPart({
|
|
1938
1937
|
zip: newZip,
|
|
1939
1938
|
path: file.name,
|
|
1940
|
-
data: patched,
|
|
1939
|
+
data: encodeUtf8(patched),
|
|
1941
1940
|
options: {
|
|
1942
1941
|
compression: "DEFLATE",
|
|
1943
1942
|
compressionOptions: { level: compressionLevel }
|
|
@@ -2054,7 +2053,7 @@ async function planAddedStyles(doc, originalZip) {
|
|
|
2054
2053
|
const styles = doc.package.styles;
|
|
2055
2054
|
if (!styles || styles.styles.length === 0) return { type: "unchanged" };
|
|
2056
2055
|
const file = findNotePartEntry(originalZip, STYLES_PART_PATH);
|
|
2057
|
-
const originalXml = file ? await file.async("
|
|
2056
|
+
const originalXml = file ? await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true })) : null;
|
|
2058
2057
|
const rootName = originalXml === null ? void 0 : /<(?![?!])(?<name>[^\s/>]+)/u.exec(originalXml)?.groups?.["name"];
|
|
2059
2058
|
const rootClose = originalXml !== null && rootName !== void 0 && getLocalName(rootName) === "styles" ? originalXml.lastIndexOf(`</${rootName}>`) : -1;
|
|
2060
2059
|
if (file === null || originalXml === null || rootClose < 0) return {
|
|
@@ -2095,7 +2094,7 @@ async function serializeAddedStylesIntoZip(doc, originalZip, newZip, compression
|
|
|
2095
2094
|
writeZipPart({
|
|
2096
2095
|
zip: newZip,
|
|
2097
2096
|
path: plan.path,
|
|
2098
|
-
data: plan.xml,
|
|
2097
|
+
data: encodeUtf8(plan.xml),
|
|
2099
2098
|
options: {
|
|
2100
2099
|
compression: "DEFLATE",
|
|
2101
2100
|
compressionOptions: { level: compressionLevel }
|
|
@@ -2138,7 +2137,7 @@ const notePartXmlFor = ({ patch, originalXml, replacementXml, hasDirtyParagraph,
|
|
|
2138
2137
|
async function patchNotePartIntoZip({ conventionalLowerPath, currentXml, replacementXml, baselineFrom, elementName, changedNoteParaIds, originalZip, newZip, compressionLevel }) {
|
|
2139
2138
|
const file = findNotePartEntry(originalZip, conventionalLowerPath);
|
|
2140
2139
|
if (!file) return;
|
|
2141
|
-
const originalXml = await file.async("
|
|
2140
|
+
const originalXml = await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
2142
2141
|
const baselineXml = baselineFrom(originalXml);
|
|
2143
2142
|
const effectiveChangedNoteParaIds = changedNoteParaIds ?? collectChangedNoteParaIds(baselineXml, currentXml);
|
|
2144
2143
|
const currentParaIds = collectParaIds(currentXml);
|
|
@@ -2161,7 +2160,7 @@ async function patchNotePartIntoZip({ conventionalLowerPath, currentXml, replace
|
|
|
2161
2160
|
writeZipPart({
|
|
2162
2161
|
zip: newZip,
|
|
2163
2162
|
path: file.name,
|
|
2164
|
-
data: patchedXml,
|
|
2163
|
+
data: encodeUtf8(patchedXml),
|
|
2165
2164
|
options: {
|
|
2166
2165
|
compression: "DEFLATE",
|
|
2167
2166
|
compressionOptions: { level: compressionLevel }
|
|
@@ -2266,7 +2265,7 @@ const createEmptyDocxZip = ({ creator, application }) => {
|
|
|
2266
2265
|
writeZipPart({
|
|
2267
2266
|
zip,
|
|
2268
2267
|
path: "[Content_Types].xml",
|
|
2269
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2268
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2270
2269
|
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
|
2271
2270
|
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
|
|
2272
2271
|
<Default Extension="xml" ContentType="application/xml"/>
|
|
@@ -2274,30 +2273,30 @@ const createEmptyDocxZip = ({ creator, application }) => {
|
|
|
2274
2273
|
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
|
|
2275
2274
|
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
|
|
2276
2275
|
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
|
|
2277
|
-
</Types>`
|
|
2276
|
+
</Types>`)
|
|
2278
2277
|
});
|
|
2279
2278
|
writeZipPart({
|
|
2280
2279
|
zip,
|
|
2281
2280
|
path: "_rels/.rels",
|
|
2282
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2281
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2283
2282
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
2284
2283
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
|
|
2285
2284
|
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
|
|
2286
2285
|
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
|
|
2287
|
-
</Relationships>`
|
|
2286
|
+
</Relationships>`)
|
|
2288
2287
|
});
|
|
2289
2288
|
writeZipPart({
|
|
2290
2289
|
zip,
|
|
2291
2290
|
path: "word/_rels/document.xml.rels",
|
|
2292
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2291
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2293
2292
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
2294
2293
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
|
|
2295
|
-
</Relationships>`
|
|
2294
|
+
</Relationships>`)
|
|
2296
2295
|
});
|
|
2297
2296
|
writeZipPart({
|
|
2298
2297
|
zip,
|
|
2299
2298
|
path: "word/document.xml",
|
|
2300
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2299
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2301
2300
|
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
|
2302
2301
|
<w:body>
|
|
2303
2302
|
<w:p>
|
|
@@ -2310,29 +2309,29 @@ const createEmptyDocxZip = ({ creator, application }) => {
|
|
|
2310
2309
|
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
|
|
2311
2310
|
</w:sectPr>
|
|
2312
2311
|
</w:body>
|
|
2313
|
-
</w:document>`
|
|
2312
|
+
</w:document>`)
|
|
2314
2313
|
});
|
|
2315
2314
|
writeZipPart({
|
|
2316
2315
|
zip,
|
|
2317
2316
|
path: STYLES_PART_PATH,
|
|
2318
|
-
data: SEED_STYLES_XML
|
|
2317
|
+
data: encodeUtf8(SEED_STYLES_XML)
|
|
2319
2318
|
});
|
|
2320
2319
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2321
2320
|
writeZipPart({
|
|
2322
2321
|
zip,
|
|
2323
2322
|
path: "docProps/core.xml",
|
|
2324
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2323
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2325
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>`}
|
|
2326
2325
|
<dcterms:created xsi:type="dcterms:W3CDTF">${now}</dcterms:created>
|
|
2327
2326
|
<dcterms:modified xsi:type="dcterms:W3CDTF">${now}</dcterms:modified>
|
|
2328
|
-
</cp:coreProperties>`
|
|
2327
|
+
</cp:coreProperties>`)
|
|
2329
2328
|
});
|
|
2330
2329
|
writeZipPart({
|
|
2331
2330
|
zip,
|
|
2332
2331
|
path: "docProps/app.xml",
|
|
2333
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2332
|
+
data: encodeUtf8(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2334
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>`}
|
|
2335
|
-
</Properties>`
|
|
2334
|
+
</Properties>`)
|
|
2336
2335
|
});
|
|
2337
2336
|
return zip;
|
|
2338
2337
|
};
|
|
@@ -2365,7 +2364,7 @@ async function createDocx(doc, properties = {}) {
|
|
|
2365
2364
|
originalZip: zip,
|
|
2366
2365
|
outputZip: zip,
|
|
2367
2366
|
originalDocument: void 0,
|
|
2368
|
-
originalCorePropertiesXml: await zip.file("docProps/core.xml")?.async("
|
|
2367
|
+
originalCorePropertiesXml: await zip.file("docProps/core.xml")?.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true })),
|
|
2369
2368
|
compressionLevel: 6,
|
|
2370
2369
|
updateModifiedDate: true,
|
|
2371
2370
|
onDiagnostic: properties.onDiagnostic,
|
|
@@ -2383,19 +2382,19 @@ const createDocumentSeedZip = async (doc, properties) => {
|
|
|
2383
2382
|
writeZipPart({
|
|
2384
2383
|
zip,
|
|
2385
2384
|
path: STYLES_PART_PATH,
|
|
2386
|
-
data: serializeStylesXml(styleDefinitions)
|
|
2385
|
+
data: encodeUtf8(serializeStylesXml(styleDefinitions))
|
|
2387
2386
|
});
|
|
2388
2387
|
} else writeZipPart({
|
|
2389
2388
|
zip,
|
|
2390
2389
|
path: STYLES_PART_PATH,
|
|
2391
|
-
data: seedStylesXmlWith(missingNoteReferenceStyles(void 0, noteReferenceNeeds(doc.package)))
|
|
2390
|
+
data: encodeUtf8(seedStylesXmlWith(missingNoteReferenceStyles(void 0, noteReferenceNeeds(doc.package))))
|
|
2392
2391
|
});
|
|
2393
2392
|
const numbering = doc.package.numbering;
|
|
2394
2393
|
if (numbering && (numbering.abstractNums.length > 0 || numbering.nums.length > 0)) {
|
|
2395
2394
|
writeZipPart({
|
|
2396
2395
|
zip,
|
|
2397
2396
|
path: "word/numbering.xml",
|
|
2398
|
-
data: serializeNumberingXml(numbering)
|
|
2397
|
+
data: encodeUtf8(serializeNumberingXml(numbering))
|
|
2399
2398
|
});
|
|
2400
2399
|
relationships.push(relationshipXml(nextRelationshipId, "numbering", "numbering.xml"));
|
|
2401
2400
|
overrides.push(overrideXml("/word/numbering.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"));
|
|
@@ -2405,7 +2404,7 @@ const createDocumentSeedZip = async (doc, properties) => {
|
|
|
2405
2404
|
writeZipPart({
|
|
2406
2405
|
zip,
|
|
2407
2406
|
path: "word/theme/theme1.xml",
|
|
2408
|
-
data: serializeThemeXml(doc.package.theme)
|
|
2407
|
+
data: encodeUtf8(serializeThemeXml(doc.package.theme))
|
|
2409
2408
|
});
|
|
2410
2409
|
relationships.push(relationshipXml(nextRelationshipId, "theme", "theme/theme1.xml"));
|
|
2411
2410
|
overrides.push(overrideXml("/word/theme/theme1.xml", "application/vnd.openxmlformats-officedocument.theme+xml"));
|
|
@@ -2415,7 +2414,7 @@ const createDocumentSeedZip = async (doc, properties) => {
|
|
|
2415
2414
|
writeZipPart({
|
|
2416
2415
|
zip,
|
|
2417
2416
|
path: "word/fontTable.xml",
|
|
2418
|
-
data: serializeFontTableXml(doc.package.fontTable)
|
|
2417
|
+
data: encodeUtf8(serializeFontTableXml(doc.package.fontTable))
|
|
2419
2418
|
});
|
|
2420
2419
|
relationships.push(relationshipXml(nextRelationshipId, "fontTable", "fontTable.xml"));
|
|
2421
2420
|
overrides.push(overrideXml("/word/fontTable.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"));
|
|
@@ -2425,7 +2424,7 @@ const createDocumentSeedZip = async (doc, properties) => {
|
|
|
2425
2424
|
writeZipPart({
|
|
2426
2425
|
zip,
|
|
2427
2426
|
path: "word/settings.xml",
|
|
2428
|
-
data: serializeSettingsXml(doc.package.settings)
|
|
2427
|
+
data: encodeUtf8(serializeSettingsXml(doc.package.settings))
|
|
2429
2428
|
});
|
|
2430
2429
|
relationships.push(relationshipXml(nextRelationshipId, "settings", "settings.xml"));
|
|
2431
2430
|
overrides.push(overrideXml("/word/settings.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"));
|
|
@@ -2433,7 +2432,7 @@ const createDocumentSeedZip = async (doc, properties) => {
|
|
|
2433
2432
|
writeZipPart({
|
|
2434
2433
|
zip,
|
|
2435
2434
|
path: "word/_rels/document.xml.rels",
|
|
2436
|
-
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>`)
|
|
2437
2436
|
});
|
|
2438
2437
|
if (overrides.length > 0) {
|
|
2439
2438
|
const contentTypesFile = zip.file("[Content_Types].xml");
|
|
@@ -2441,7 +2440,7 @@ const createDocumentSeedZip = async (doc, properties) => {
|
|
|
2441
2440
|
writeZipPart({
|
|
2442
2441
|
zip,
|
|
2443
2442
|
path: "[Content_Types].xml",
|
|
2444
|
-
data: (await contentTypesFile.async("
|
|
2443
|
+
data: encodeUtf8((await contentTypesFile.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }))).replace("</Types>", `${overrides.join("")}\n</Types>`))
|
|
2445
2444
|
});
|
|
2446
2445
|
}
|
|
2447
2446
|
return zip;
|