@superdoc-dev/cli 0.5.0-next.1 → 0.5.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/index.js +1504 -750
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -62964,7 +62964,7 @@ var init_remark_gfm_z_sDF4ss_es = __esm(() => {
|
|
|
62964
62964
|
emptyOptions2 = {};
|
|
62965
62965
|
});
|
|
62966
62966
|
|
|
62967
|
-
// ../../packages/superdoc/dist/chunks/SuperConverter-
|
|
62967
|
+
// ../../packages/superdoc/dist/chunks/SuperConverter-CXcZg9Os.es.js
|
|
62968
62968
|
function getExtensionConfigField(extension$1, field, context = { name: "" }) {
|
|
62969
62969
|
const fieldValue = extension$1.config[field];
|
|
62970
62970
|
if (typeof fieldValue === "function")
|
|
@@ -113235,7 +113235,7 @@ var isRegExp = (value) => {
|
|
|
113235
113235
|
state.kern = kernNode.attributes["w:val"];
|
|
113236
113236
|
}
|
|
113237
113237
|
}, SuperConverter;
|
|
113238
|
-
var
|
|
113238
|
+
var init_SuperConverter_CXcZg9Os_es = __esm(() => {
|
|
113239
113239
|
init_rolldown_runtime_B2q5OVn9_es();
|
|
113240
113240
|
init_jszip_ChlR43oI_es();
|
|
113241
113241
|
init_xml_js_40FWvL78_es();
|
|
@@ -149810,8 +149810,11 @@ var init_SuperConverter_DPILugtg_es = __esm(() => {
|
|
|
149810
149810
|
numberingXml = baseNumbering;
|
|
149811
149811
|
const currentNumberingXml = numberingXml.elements[0];
|
|
149812
149812
|
const referencedNumIds = collectReferencedNumIds(this.convertedXml);
|
|
149813
|
-
|
|
149814
|
-
|
|
149813
|
+
if (this.numbering?.definitions && this.numbering?.abstracts) {
|
|
149814
|
+
const { liveAbstracts, liveDefinitions } = filterOrphanedNumberingDefinitions(this.numbering, referencedNumIds);
|
|
149815
|
+
currentNumberingXml.elements = [...liveAbstracts, ...liveDefinitions];
|
|
149816
|
+
} else
|
|
149817
|
+
currentNumberingXml.elements = [];
|
|
149815
149818
|
this.convertedXml[numberingPath] = numberingXml;
|
|
149816
149819
|
}
|
|
149817
149820
|
#prepareCommentsXmlFilesForExport({ defs, exportType, commentsWithParaIds }) {
|
|
@@ -150610,7 +150613,7 @@ var init_remark_stringify_D8vxv_XI_es = __esm(() => {
|
|
|
150610
150613
|
eol = /\r?\n|\r/g;
|
|
150611
150614
|
});
|
|
150612
150615
|
|
|
150613
|
-
// ../../packages/superdoc/dist/chunks/
|
|
150616
|
+
// ../../packages/superdoc/dist/chunks/dist-Cwvmda4Q.es.js
|
|
150614
150617
|
function getLens2(b64) {
|
|
150615
150618
|
var len$1 = b64.length;
|
|
150616
150619
|
if (len$1 % 4 > 0)
|
|
@@ -150685,631 +150688,8 @@ function fromByteArray2(uint8) {
|
|
|
150685
150688
|
}
|
|
150686
150689
|
return parts.join("");
|
|
150687
150690
|
}
|
|
150688
|
-
|
|
150689
|
-
|
|
150690
|
-
const b0 = u8[0], b1 = u8[1];
|
|
150691
|
-
if (b0 === 255 && b1 === 254)
|
|
150692
|
-
return "utf-16le";
|
|
150693
|
-
if (b0 === 254 && b1 === 255)
|
|
150694
|
-
return "utf-16be";
|
|
150695
|
-
}
|
|
150696
|
-
let nul = 0;
|
|
150697
|
-
for (let i$1 = 0;i$1 < Math.min(64, u8.length); i$1++)
|
|
150698
|
-
if (u8[i$1] === 0)
|
|
150699
|
-
nul++;
|
|
150700
|
-
if (nul > 16)
|
|
150701
|
-
return "utf-16le";
|
|
150702
|
-
return "utf-8";
|
|
150703
|
-
}
|
|
150704
|
-
function stripBOM(str) {
|
|
150705
|
-
return str && str.charCodeAt(0) === 65279 ? str.slice(1) : str;
|
|
150706
|
-
}
|
|
150707
|
-
function ensureXmlString(content2) {
|
|
150708
|
-
if (typeof content2 === "string")
|
|
150709
|
-
return stripBOM(content2);
|
|
150710
|
-
let u8 = null;
|
|
150711
|
-
if (content2 && typeof content2 === "object") {
|
|
150712
|
-
if (content2 instanceof Uint8Array)
|
|
150713
|
-
u8 = content2;
|
|
150714
|
-
else if (typeof Buffer3 !== "undefined" && Buffer3.isBuffer && Buffer3.isBuffer(content2))
|
|
150715
|
-
u8 = new Uint8Array(content2.buffer, content2.byteOffset, content2.byteLength);
|
|
150716
|
-
else if (ArrayBuffer.isView && ArrayBuffer.isView(content2))
|
|
150717
|
-
u8 = new Uint8Array(content2.buffer, content2.byteOffset, content2.byteLength);
|
|
150718
|
-
else if (content2.constructor && (content2 instanceof ArrayBuffer || content2.constructor.name === "ArrayBuffer"))
|
|
150719
|
-
u8 = new Uint8Array(content2);
|
|
150720
|
-
}
|
|
150721
|
-
if (!u8)
|
|
150722
|
-
throw new Error("Unsupported content type for XML");
|
|
150723
|
-
const enc = sniffEncoding(u8);
|
|
150724
|
-
let xml = new TextDecoder(enc).decode(u8);
|
|
150725
|
-
xml = stripBOM(xml);
|
|
150726
|
-
if (enc !== "utf-8")
|
|
150727
|
-
xml = xml.replace(/(<\?xml\b[^?]*?)\bencoding\s*=\s*["'][^"']*["']/i, '$1encoding="UTF-8"');
|
|
150728
|
-
return xml;
|
|
150729
|
-
}
|
|
150730
|
-
function readEntry(path2, baseFiles, updatedDocs) {
|
|
150731
|
-
if (updatedDocs && Object.prototype.hasOwnProperty.call(updatedDocs, path2))
|
|
150732
|
-
return updatedDocs[path2];
|
|
150733
|
-
if (!baseFiles)
|
|
150734
|
-
return;
|
|
150735
|
-
if (Array.isArray(baseFiles))
|
|
150736
|
-
return baseFiles.find((f2) => f2.name === path2)?.content;
|
|
150737
|
-
return baseFiles[path2];
|
|
150738
|
-
}
|
|
150739
|
-
function partExistsInPackage(zipPath, baseFiles, updatedDocs) {
|
|
150740
|
-
return readEntry(zipPath, baseFiles, updatedDocs) != null;
|
|
150741
|
-
}
|
|
150742
|
-
function parseXml(xmlString) {
|
|
150743
|
-
try {
|
|
150744
|
-
return import_lib$2.xml2js(xmlString, { compact: false });
|
|
150745
|
-
} catch {
|
|
150746
|
-
return null;
|
|
150747
|
-
}
|
|
150748
|
-
}
|
|
150749
|
-
function serializeXml(jsObject) {
|
|
150750
|
-
return import_lib$2.js2xml(jsObject, { spaces: 0 });
|
|
150751
|
-
}
|
|
150752
|
-
function findRootElement(parsed, tagName) {
|
|
150753
|
-
return parsed?.elements?.find((el) => {
|
|
150754
|
-
if (!el.name)
|
|
150755
|
-
return false;
|
|
150756
|
-
return (el.name.includes(":") ? el.name.split(":").pop() : el.name) === tagName;
|
|
150757
|
-
});
|
|
150758
|
-
}
|
|
150759
|
-
function createEmptyRels() {
|
|
150760
|
-
return {
|
|
150761
|
-
declaration: { attributes: {
|
|
150762
|
-
version: "1.0",
|
|
150763
|
-
encoding: "UTF-8",
|
|
150764
|
-
standalone: "yes"
|
|
150765
|
-
} },
|
|
150766
|
-
elements: [{
|
|
150767
|
-
type: "element",
|
|
150768
|
-
name: "Relationships",
|
|
150769
|
-
attributes: { xmlns: RELATIONSHIPS_NS },
|
|
150770
|
-
elements: []
|
|
150771
|
-
}]
|
|
150772
|
-
};
|
|
150773
|
-
}
|
|
150774
|
-
function findMaxRId$1(relsRoot) {
|
|
150775
|
-
let max4 = 0;
|
|
150776
|
-
for (const el of relsRoot.elements || []) {
|
|
150777
|
-
const id2 = el.attributes?.Id;
|
|
150778
|
-
if (!id2)
|
|
150779
|
-
continue;
|
|
150780
|
-
const match = id2.match(/^rId(\d+)$/);
|
|
150781
|
-
if (match)
|
|
150782
|
-
max4 = Math.max(max4, parseInt(match[1], 10));
|
|
150783
|
-
}
|
|
150784
|
-
return max4;
|
|
150785
|
-
}
|
|
150786
|
-
function reconcileContentTypes(typesRoot, presentParts) {
|
|
150787
|
-
if (!typesRoot.elements)
|
|
150788
|
-
typesRoot.elements = [];
|
|
150789
|
-
const managedByPartName = /* @__PURE__ */ new Map;
|
|
150790
|
-
for (const entry of MANAGED_PACKAGE_PARTS)
|
|
150791
|
-
managedByPartName.set(`/${entry.zipPath}`, entry);
|
|
150792
|
-
const existingOverrides = /* @__PURE__ */ new Map;
|
|
150793
|
-
for (let i$1 = 0;i$1 < typesRoot.elements.length; i$1++) {
|
|
150794
|
-
const el = typesRoot.elements[i$1];
|
|
150795
|
-
if (el.name !== "Override")
|
|
150796
|
-
continue;
|
|
150797
|
-
const partName = el.attributes?.PartName;
|
|
150798
|
-
if (!partName || !managedByPartName.has(partName))
|
|
150799
|
-
continue;
|
|
150800
|
-
if (!existingOverrides.has(partName))
|
|
150801
|
-
existingOverrides.set(partName, []);
|
|
150802
|
-
existingOverrides.get(partName).push(i$1);
|
|
150803
|
-
}
|
|
150804
|
-
const indicesToRemove = /* @__PURE__ */ new Set;
|
|
150805
|
-
for (const [partName, entry] of managedByPartName) {
|
|
150806
|
-
const isPresent = presentParts.has(entry.zipPath);
|
|
150807
|
-
const indices = existingOverrides.get(partName) || [];
|
|
150808
|
-
if (!isPresent) {
|
|
150809
|
-
for (const idx of indices)
|
|
150810
|
-
indicesToRemove.add(idx);
|
|
150811
|
-
continue;
|
|
150812
|
-
}
|
|
150813
|
-
if (indices.length === 0)
|
|
150814
|
-
typesRoot.elements.push({
|
|
150815
|
-
type: "element",
|
|
150816
|
-
name: "Override",
|
|
150817
|
-
attributes: {
|
|
150818
|
-
PartName: partName,
|
|
150819
|
-
ContentType: entry.contentType
|
|
150820
|
-
}
|
|
150821
|
-
});
|
|
150822
|
-
else {
|
|
150823
|
-
typesRoot.elements[indices[0]].attributes.ContentType = entry.contentType;
|
|
150824
|
-
for (let i$1 = 1;i$1 < indices.length; i$1++)
|
|
150825
|
-
indicesToRemove.add(indices[i$1]);
|
|
150826
|
-
}
|
|
150827
|
-
}
|
|
150828
|
-
if (indicesToRemove.size > 0) {
|
|
150829
|
-
const sorted = [...indicesToRemove].sort((a, b) => b - a);
|
|
150830
|
-
for (const idx of sorted)
|
|
150831
|
-
typesRoot.elements.splice(idx, 1);
|
|
150832
|
-
}
|
|
150833
|
-
}
|
|
150834
|
-
function reconcileRootRels(relsRoot, presentParts) {
|
|
150835
|
-
if (!relsRoot.elements)
|
|
150836
|
-
relsRoot.elements = [];
|
|
150837
|
-
const managedByType = /* @__PURE__ */ new Map;
|
|
150838
|
-
for (const entry of MANAGED_PACKAGE_PARTS)
|
|
150839
|
-
managedByType.set(entry.relationshipType, entry);
|
|
150840
|
-
const existingRels = /* @__PURE__ */ new Map;
|
|
150841
|
-
for (let i$1 = 0;i$1 < relsRoot.elements.length; i$1++) {
|
|
150842
|
-
const el = relsRoot.elements[i$1];
|
|
150843
|
-
if (el.name !== "Relationship")
|
|
150844
|
-
continue;
|
|
150845
|
-
const type = el.attributes?.Type;
|
|
150846
|
-
if (!type || !managedByType.has(type))
|
|
150847
|
-
continue;
|
|
150848
|
-
if (!existingRels.has(type))
|
|
150849
|
-
existingRels.set(type, []);
|
|
150850
|
-
existingRels.get(type).push({
|
|
150851
|
-
index: i$1,
|
|
150852
|
-
element: el
|
|
150853
|
-
});
|
|
150854
|
-
}
|
|
150855
|
-
const indicesToRemove = /* @__PURE__ */ new Set;
|
|
150856
|
-
let maxRId = findMaxRId$1(relsRoot);
|
|
150857
|
-
for (const [relType, entry] of managedByType) {
|
|
150858
|
-
const isPresent = presentParts.has(entry.zipPath);
|
|
150859
|
-
const existing = existingRels.get(relType) || [];
|
|
150860
|
-
if (!isPresent) {
|
|
150861
|
-
for (const { index: index2 } of existing)
|
|
150862
|
-
indicesToRemove.add(index2);
|
|
150863
|
-
continue;
|
|
150864
|
-
}
|
|
150865
|
-
if (existing.length === 0) {
|
|
150866
|
-
maxRId++;
|
|
150867
|
-
relsRoot.elements.push({
|
|
150868
|
-
type: "element",
|
|
150869
|
-
name: "Relationship",
|
|
150870
|
-
attributes: {
|
|
150871
|
-
Id: `rId${maxRId}`,
|
|
150872
|
-
Type: relType,
|
|
150873
|
-
Target: entry.zipPath
|
|
150874
|
-
}
|
|
150875
|
-
});
|
|
150876
|
-
} else {
|
|
150877
|
-
existing[0].element.attributes.Target = entry.zipPath;
|
|
150878
|
-
for (let i$1 = 1;i$1 < existing.length; i$1++)
|
|
150879
|
-
indicesToRemove.add(existing[i$1].index);
|
|
150880
|
-
}
|
|
150881
|
-
}
|
|
150882
|
-
if (indicesToRemove.size > 0) {
|
|
150883
|
-
const sorted = [...indicesToRemove].sort((a, b) => b - a);
|
|
150884
|
-
for (const idx of sorted)
|
|
150885
|
-
relsRoot.elements.splice(idx, 1);
|
|
150886
|
-
}
|
|
150887
|
-
}
|
|
150888
|
-
function syncPackageMetadata({ baseFiles, updatedDocs }) {
|
|
150889
|
-
const presentParts = /* @__PURE__ */ new Set;
|
|
150890
|
-
for (const entry of MANAGED_PACKAGE_PARTS)
|
|
150891
|
-
if (partExistsInPackage(entry.zipPath, baseFiles, updatedDocs))
|
|
150892
|
-
presentParts.add(entry.zipPath);
|
|
150893
|
-
const rawContentTypes = readEntry("[Content_Types].xml", baseFiles, updatedDocs);
|
|
150894
|
-
if (rawContentTypes == null)
|
|
150895
|
-
throw new Error("syncPackageMetadata: [Content_Types].xml is missing from the package. Cannot safely reconcile package metadata without an existing content types file.");
|
|
150896
|
-
const contentTypesParsed = parseXml(rawContentTypes);
|
|
150897
|
-
if (!contentTypesParsed)
|
|
150898
|
-
throw new Error("syncPackageMetadata: [Content_Types].xml could not be parsed as valid XML. Cannot safely reconcile package metadata from a malformed content types file.");
|
|
150899
|
-
const typesRoot = findRootElement(contentTypesParsed, "Types");
|
|
150900
|
-
if (!typesRoot)
|
|
150901
|
-
throw new Error("syncPackageMetadata: [Content_Types].xml does not contain a <Types> root element.");
|
|
150902
|
-
reconcileContentTypes(typesRoot, presentParts);
|
|
150903
|
-
const rawRels = readEntry("_rels/.rels", baseFiles, updatedDocs);
|
|
150904
|
-
let relsParsed;
|
|
150905
|
-
if (rawRels == null)
|
|
150906
|
-
relsParsed = createEmptyRels();
|
|
150907
|
-
else {
|
|
150908
|
-
relsParsed = parseXml(rawRels);
|
|
150909
|
-
if (!relsParsed)
|
|
150910
|
-
throw new Error("syncPackageMetadata: _rels/.rels could not be parsed as valid XML. Cannot safely reconcile root relationships from a malformed rels file.");
|
|
150911
|
-
}
|
|
150912
|
-
let relsRoot = findRootElement(relsParsed, "Relationships");
|
|
150913
|
-
if (!relsRoot) {
|
|
150914
|
-
relsParsed = createEmptyRels();
|
|
150915
|
-
relsRoot = relsParsed.elements[0];
|
|
150916
|
-
}
|
|
150917
|
-
reconcileRootRels(relsRoot, presentParts);
|
|
150918
|
-
return {
|
|
150919
|
-
contentTypesXml: serializeXml(contentTypesParsed),
|
|
150920
|
-
relsXml: serializeXml(relsParsed)
|
|
150921
|
-
};
|
|
150922
|
-
}
|
|
150923
|
-
function findMaxRId(elements) {
|
|
150924
|
-
let max4 = 0;
|
|
150925
|
-
for (const el of elements) {
|
|
150926
|
-
const match = el.attributes?.Id?.match(/^rId(\d+)$/);
|
|
150927
|
-
if (match)
|
|
150928
|
-
max4 = Math.max(max4, Number(match[1]));
|
|
150929
|
-
}
|
|
150930
|
-
return max4;
|
|
150931
|
-
}
|
|
150932
|
-
function reconcileDocumentRelationships(relsXml, fileExists) {
|
|
150933
|
-
if (!relsXml)
|
|
150934
|
-
return relsXml;
|
|
150935
|
-
let parsed;
|
|
150936
|
-
try {
|
|
150937
|
-
parsed = import_lib$12.xml2js(relsXml, { compact: false });
|
|
150938
|
-
} catch {
|
|
150939
|
-
return relsXml;
|
|
150940
|
-
}
|
|
150941
|
-
const relsTag = parsed?.elements?.find((el) => el.name === "Relationships");
|
|
150942
|
-
if (!relsTag)
|
|
150943
|
-
return relsXml;
|
|
150944
|
-
if (!relsTag.elements)
|
|
150945
|
-
relsTag.elements = [];
|
|
150946
|
-
let changed = false;
|
|
150947
|
-
let maxId = findMaxRId(relsTag.elements);
|
|
150948
|
-
for (const entry of MANAGED_DOCUMENT_PARTS) {
|
|
150949
|
-
if (!fileExists(entry.zipPath))
|
|
150950
|
-
continue;
|
|
150951
|
-
if (relsTag.elements.some((el) => el.attributes?.Type === entry.relationshipType))
|
|
150952
|
-
continue;
|
|
150953
|
-
maxId++;
|
|
150954
|
-
relsTag.elements.push({
|
|
150955
|
-
type: "element",
|
|
150956
|
-
name: "Relationship",
|
|
150957
|
-
attributes: {
|
|
150958
|
-
Id: `rId${maxId}`,
|
|
150959
|
-
Type: entry.relationshipType,
|
|
150960
|
-
Target: entry.relTarget
|
|
150961
|
-
}
|
|
150962
|
-
});
|
|
150963
|
-
changed = true;
|
|
150964
|
-
}
|
|
150965
|
-
if (!changed)
|
|
150966
|
-
return relsXml;
|
|
150967
|
-
return import_lib$12.js2xml(parsed, { spaces: 0 });
|
|
150968
|
-
}
|
|
150969
|
-
var DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", buffer2, base64Js2, lookup2, revLookup2, Arr2, code5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i3, len2, ieee7542, Buffer3, isXmlLike = (name) => /\.xml$|\.rels$/i.test(name), MANAGED_PACKAGE_PARTS, import_lib$2, RELATIONSHIPS_NS = "http://schemas.openxmlformats.org/package/2006/relationships", import_lib$12, MANAGED_DOCUMENT_PARTS, import_lib3, import_jszip_min, IMAGE_EXTS, MIME_TYPE_FOR_EXT, CUSTOM_XML_ITEM_PROPS_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.customXmlProperties+xml", FONT_CONTENT_TYPES, DocxZipper = class {
|
|
150970
|
-
constructor(params3 = {}) {
|
|
150971
|
-
this.debug = params3.debug || false;
|
|
150972
|
-
this.zip = new import_jszip_min.default;
|
|
150973
|
-
this.files = [];
|
|
150974
|
-
this.media = {};
|
|
150975
|
-
this.mediaFiles = {};
|
|
150976
|
-
this.fonts = {};
|
|
150977
|
-
}
|
|
150978
|
-
async getDocxData(file, isNode3 = false) {
|
|
150979
|
-
const extractedFiles = await this.unzip(file);
|
|
150980
|
-
const files = Object.entries(extractedFiles.files);
|
|
150981
|
-
for (const [, zipEntry] of files) {
|
|
150982
|
-
const name = zipEntry.name;
|
|
150983
|
-
if (isXmlLike(name)) {
|
|
150984
|
-
const content2 = ensureXmlString(await zipEntry.async("uint8array"));
|
|
150985
|
-
this.files.push({
|
|
150986
|
-
name,
|
|
150987
|
-
content: content2
|
|
150988
|
-
});
|
|
150989
|
-
} else if (name.startsWith("word/media") && name !== "word/media/" || zipEntry.name.startsWith("media") && zipEntry.name !== "media/" || name.startsWith("media") && name !== "media/" || name.startsWith("word/embeddings") && name !== "word/embeddings/")
|
|
150990
|
-
if (isNode3) {
|
|
150991
|
-
const fileBase64 = (await zipEntry.async("nodebuffer")).toString("base64");
|
|
150992
|
-
this.mediaFiles[name] = fileBase64;
|
|
150993
|
-
} else {
|
|
150994
|
-
const fileBase64 = await zipEntry.async("base64");
|
|
150995
|
-
let extension2 = this.getFileExtension(name)?.toLowerCase();
|
|
150996
|
-
let detectedType = null;
|
|
150997
|
-
if (!IMAGE_EXTS.has(extension2) || extension2 === "tmp") {
|
|
150998
|
-
detectedType = detectImageType(fileBase64);
|
|
150999
|
-
if (detectedType)
|
|
151000
|
-
extension2 = detectedType;
|
|
151001
|
-
}
|
|
151002
|
-
if (IMAGE_EXTS.has(extension2)) {
|
|
151003
|
-
const mimeSubtype = MIME_TYPE_FOR_EXT[extension2] || extension2;
|
|
151004
|
-
this.mediaFiles[name] = `data:image/${mimeSubtype};base64,${fileBase64}`;
|
|
151005
|
-
const blob = await zipEntry.async("blob");
|
|
151006
|
-
const fileObj = new File([blob], name, { type: blob.type });
|
|
151007
|
-
const imageUrl = URL.createObjectURL(fileObj);
|
|
151008
|
-
this.media[name] = imageUrl;
|
|
151009
|
-
} else
|
|
151010
|
-
this.mediaFiles[name] = fileBase64;
|
|
151011
|
-
}
|
|
151012
|
-
else if (name.startsWith("word/fonts") && name !== "word/fonts/") {
|
|
151013
|
-
const uint8array = await zipEntry.async("uint8array");
|
|
151014
|
-
this.fonts[name] = uint8array;
|
|
151015
|
-
}
|
|
151016
|
-
}
|
|
151017
|
-
return this.files;
|
|
151018
|
-
}
|
|
151019
|
-
getFileExtension(fileName) {
|
|
151020
|
-
const fileSplit = fileName.split(".");
|
|
151021
|
-
if (fileSplit.length < 2)
|
|
151022
|
-
return null;
|
|
151023
|
-
return fileSplit[fileSplit.length - 1];
|
|
151024
|
-
}
|
|
151025
|
-
async updateContentTypes(docx, media, fromJson, updatedDocs = {}, fonts = {}) {
|
|
151026
|
-
const additionalPartNames = Object.keys(updatedDocs || {});
|
|
151027
|
-
const newMediaTypes = Object.keys(media).map((name) => this.getFileExtension(name)).filter((ext) => ext && IMAGE_EXTS.has(ext));
|
|
151028
|
-
const extensionlessMediaOverrides = Object.entries(media).filter(([name]) => !this.getFileExtension(name)).map(([name, value]) => ({
|
|
151029
|
-
name,
|
|
151030
|
-
contentType: this.#detectImageContentType(value)
|
|
151031
|
-
})).filter((entry) => entry.contentType);
|
|
151032
|
-
const contentTypesPath = "[Content_Types].xml";
|
|
151033
|
-
let contentTypesXml;
|
|
151034
|
-
if (fromJson)
|
|
151035
|
-
if (Array.isArray(docx.files))
|
|
151036
|
-
contentTypesXml = docx.files.find((file) => file.name === contentTypesPath)?.content || "";
|
|
151037
|
-
else
|
|
151038
|
-
contentTypesXml = docx.files?.[contentTypesPath] || "";
|
|
151039
|
-
else
|
|
151040
|
-
contentTypesXml = await docx.file(contentTypesPath).async("string");
|
|
151041
|
-
let typesString = "";
|
|
151042
|
-
const defaultMediaTypes = getContentTypesFromXml(contentTypesXml);
|
|
151043
|
-
const seenTypes = /* @__PURE__ */ new Set;
|
|
151044
|
-
for (let type of newMediaTypes) {
|
|
151045
|
-
if (defaultMediaTypes.includes(type))
|
|
151046
|
-
continue;
|
|
151047
|
-
if (seenTypes.has(type))
|
|
151048
|
-
continue;
|
|
151049
|
-
const newContentType = `<Default Extension="${type}" ContentType="image/${MIME_TYPE_FOR_EXT[type] || type}"/>`;
|
|
151050
|
-
typesString += newContentType;
|
|
151051
|
-
seenTypes.add(type);
|
|
151052
|
-
}
|
|
151053
|
-
if (fonts) {
|
|
151054
|
-
const fontExts = new Set(Object.keys(fonts).map((name) => this.getFileExtension(name)).filter((ext) => ext && FONT_CONTENT_TYPES[ext]));
|
|
151055
|
-
for (const ext of fontExts) {
|
|
151056
|
-
if (defaultMediaTypes.includes(ext))
|
|
151057
|
-
continue;
|
|
151058
|
-
if (seenTypes.has(ext))
|
|
151059
|
-
continue;
|
|
151060
|
-
typesString += `<Default Extension="${ext}" ContentType="${FONT_CONTENT_TYPES[ext]}"/>`;
|
|
151061
|
-
seenTypes.add(ext);
|
|
151062
|
-
}
|
|
151063
|
-
}
|
|
151064
|
-
const types3 = JSON.parse(import_lib3.xml2json(contentTypesXml, null, 2)).elements?.find((el) => el.name === "Types") || {};
|
|
151065
|
-
const hasPartOverride = (partName) => types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === partName);
|
|
151066
|
-
for (const { name, contentType } of extensionlessMediaOverrides) {
|
|
151067
|
-
const partName = `/${name}`;
|
|
151068
|
-
if (hasPartOverride(partName))
|
|
151069
|
-
continue;
|
|
151070
|
-
typesString += `<Override PartName="${partName}" ContentType="${contentType}" />`;
|
|
151071
|
-
}
|
|
151072
|
-
const hasComments = types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === "/word/comments.xml");
|
|
151073
|
-
const hasCommentsExtended = types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === "/word/commentsExtended.xml");
|
|
151074
|
-
const hasCommentsIds = types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === "/word/commentsIds.xml");
|
|
151075
|
-
const hasCommentsExtensible = types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === "/word/commentsExtensible.xml");
|
|
151076
|
-
const hasFile = (filename) => {
|
|
151077
|
-
if (updatedDocs && Object.prototype.hasOwnProperty.call(updatedDocs, filename))
|
|
151078
|
-
return updatedDocs[filename] !== null;
|
|
151079
|
-
if (!docx?.files)
|
|
151080
|
-
return false;
|
|
151081
|
-
if (!fromJson)
|
|
151082
|
-
return Boolean(docx.files[filename]);
|
|
151083
|
-
if (Array.isArray(docx.files))
|
|
151084
|
-
return docx.files.some((file) => file.name === filename);
|
|
151085
|
-
return Boolean(docx.files[filename]);
|
|
151086
|
-
};
|
|
151087
|
-
if (hasFile("word/comments.xml")) {
|
|
151088
|
-
const commentsDef = `<Override PartName="/word/comments.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml" />`;
|
|
151089
|
-
if (!hasComments)
|
|
151090
|
-
typesString += commentsDef;
|
|
151091
|
-
}
|
|
151092
|
-
if (hasFile("word/commentsExtended.xml")) {
|
|
151093
|
-
const commentsExtendedDef = `<Override PartName="/word/commentsExtended.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml" />`;
|
|
151094
|
-
if (!hasCommentsExtended)
|
|
151095
|
-
typesString += commentsExtendedDef;
|
|
151096
|
-
}
|
|
151097
|
-
if (hasFile("word/commentsIds.xml")) {
|
|
151098
|
-
const commentsIdsDef = `<Override PartName="/word/commentsIds.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsIds+xml" />`;
|
|
151099
|
-
if (!hasCommentsIds)
|
|
151100
|
-
typesString += commentsIdsDef;
|
|
151101
|
-
}
|
|
151102
|
-
if (hasFile("word/commentsExtensible.xml")) {
|
|
151103
|
-
const commentsExtendedDef = `<Override PartName="/word/commentsExtensible.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml" />`;
|
|
151104
|
-
if (!hasCommentsExtensible)
|
|
151105
|
-
typesString += commentsExtendedDef;
|
|
151106
|
-
}
|
|
151107
|
-
const hasFootnotes = types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === "/word/footnotes.xml");
|
|
151108
|
-
if (hasFile("word/footnotes.xml")) {
|
|
151109
|
-
const footnotesDef = `<Override PartName="/word/footnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml" />`;
|
|
151110
|
-
if (!hasFootnotes)
|
|
151111
|
-
typesString += footnotesDef;
|
|
151112
|
-
}
|
|
151113
|
-
for (const entry of MANAGED_DOCUMENT_PARTS)
|
|
151114
|
-
if (hasFile(entry.zipPath) && !hasPartOverride(`/${entry.zipPath}`))
|
|
151115
|
-
typesString += `<Override PartName="/${entry.zipPath}" ContentType="${entry.contentType}" />`;
|
|
151116
|
-
const partNames = new Set(additionalPartNames);
|
|
151117
|
-
if (docx?.files)
|
|
151118
|
-
if (fromJson && Array.isArray(docx.files))
|
|
151119
|
-
docx.files.forEach((file) => partNames.add(file.name));
|
|
151120
|
-
else
|
|
151121
|
-
Object.keys(docx.files).forEach((key) => partNames.add(key));
|
|
151122
|
-
partNames.forEach((name) => {
|
|
151123
|
-
if (!/^customXml\/itemProps\d+\.xml$/i.test(name))
|
|
151124
|
-
return;
|
|
151125
|
-
if (!hasFile(name))
|
|
151126
|
-
return;
|
|
151127
|
-
const partName = `/${name}`;
|
|
151128
|
-
if (hasPartOverride(partName))
|
|
151129
|
-
return;
|
|
151130
|
-
typesString += `<Override PartName="${partName}" ContentType="${CUSTOM_XML_ITEM_PROPS_CONTENT_TYPE}" />`;
|
|
151131
|
-
});
|
|
151132
|
-
partNames.forEach((name) => {
|
|
151133
|
-
if (name.includes(".rels"))
|
|
151134
|
-
return;
|
|
151135
|
-
if (!name.includes("header") && !name.includes("footer"))
|
|
151136
|
-
return;
|
|
151137
|
-
const hasExtensible = types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === `/${name}`);
|
|
151138
|
-
const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${name.includes("header") ? "header" : "footer"}+xml"/>`;
|
|
151139
|
-
if (!hasExtensible)
|
|
151140
|
-
typesString += extendedDef;
|
|
151141
|
-
});
|
|
151142
|
-
const staleOverridePartNames = COMMENT_FILE_BASENAMES.map((name) => `/word/${name}`).filter((partName) => {
|
|
151143
|
-
return !hasFile(partName.slice(1));
|
|
151144
|
-
});
|
|
151145
|
-
const beginningString = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
|
|
151146
|
-
let updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
|
|
151147
|
-
for (const partName of staleOverridePartNames) {
|
|
151148
|
-
const escapedPartName = partName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
151149
|
-
const overrideRegex = new RegExp(`\\s*<Override[^>]*PartName="${escapedPartName}"[^>]*/>`, "g");
|
|
151150
|
-
updatedContentTypesXml = updatedContentTypesXml.replace(overrideRegex, "");
|
|
151151
|
-
}
|
|
151152
|
-
let relationshipsXml = updatedDocs["word/_rels/document.xml.rels"];
|
|
151153
|
-
if (!relationshipsXml)
|
|
151154
|
-
if (fromJson)
|
|
151155
|
-
if (Array.isArray(docx.files))
|
|
151156
|
-
relationshipsXml = docx.files.find((file) => file.name === "word/_rels/document.xml.rels")?.content;
|
|
151157
|
-
else
|
|
151158
|
-
relationshipsXml = docx.files?.["word/_rels/document.xml.rels"];
|
|
151159
|
-
else
|
|
151160
|
-
relationshipsXml = await docx.file("word/_rels/document.xml.rels")?.async("string");
|
|
151161
|
-
if (relationshipsXml)
|
|
151162
|
-
try {
|
|
151163
|
-
import_lib3.xml2js(relationshipsXml, { compact: false }).elements?.find((el) => el.name === "Relationships")?.elements?.forEach((rel) => {
|
|
151164
|
-
const type = rel.attributes?.Type;
|
|
151165
|
-
const target = rel.attributes?.Target;
|
|
151166
|
-
if (!type || !target)
|
|
151167
|
-
return;
|
|
151168
|
-
const isHeader = type.includes("/header");
|
|
151169
|
-
const isFooter = type.includes("/footer");
|
|
151170
|
-
if (!isHeader && !isFooter)
|
|
151171
|
-
return;
|
|
151172
|
-
let sanitizedTarget = target.replace(/^\.\//, "");
|
|
151173
|
-
if (sanitizedTarget.startsWith("../"))
|
|
151174
|
-
sanitizedTarget = sanitizedTarget.slice(3);
|
|
151175
|
-
if (sanitizedTarget.startsWith("/"))
|
|
151176
|
-
sanitizedTarget = sanitizedTarget.slice(1);
|
|
151177
|
-
const partName = sanitizedTarget.startsWith("word/") ? sanitizedTarget : `word/${sanitizedTarget}`;
|
|
151178
|
-
partNames.add(partName);
|
|
151179
|
-
});
|
|
151180
|
-
} catch (error3) {
|
|
151181
|
-
console.warn("Failed to parse document relationships while updating content types", error3);
|
|
151182
|
-
}
|
|
151183
|
-
partNames.forEach((name) => {
|
|
151184
|
-
if (name.includes(".rels"))
|
|
151185
|
-
return;
|
|
151186
|
-
if (!name.includes("header") && !name.includes("footer"))
|
|
151187
|
-
return;
|
|
151188
|
-
if (updatedContentTypesXml.includes(`PartName="/${name}"`))
|
|
151189
|
-
return;
|
|
151190
|
-
const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${name.includes("header") ? "header" : "footer"}+xml"/>`;
|
|
151191
|
-
updatedContentTypesXml = updatedContentTypesXml.replace("</Types>", `${extendedDef}</Types>`);
|
|
151192
|
-
});
|
|
151193
|
-
if (relationshipsXml) {
|
|
151194
|
-
const reconciledRels = reconcileDocumentRelationships(relationshipsXml, hasFile);
|
|
151195
|
-
if (reconciledRels !== relationshipsXml)
|
|
151196
|
-
if (fromJson)
|
|
151197
|
-
updatedDocs["word/_rels/document.xml.rels"] = reconciledRels;
|
|
151198
|
-
else
|
|
151199
|
-
docx.file("word/_rels/document.xml.rels", reconciledRels);
|
|
151200
|
-
}
|
|
151201
|
-
if (fromJson)
|
|
151202
|
-
return updatedContentTypesXml;
|
|
151203
|
-
docx.file(contentTypesPath, updatedContentTypesXml);
|
|
151204
|
-
}
|
|
151205
|
-
async#syncPackageMetadataInZip(zip) {
|
|
151206
|
-
const baseForSync = {};
|
|
151207
|
-
zip.forEach((path2) => {
|
|
151208
|
-
baseForSync[path2] = "";
|
|
151209
|
-
});
|
|
151210
|
-
const ctEntry = zip.file("[Content_Types].xml");
|
|
151211
|
-
if (ctEntry)
|
|
151212
|
-
baseForSync["[Content_Types].xml"] = await ctEntry.async("string");
|
|
151213
|
-
const rlEntry = zip.file("_rels/.rels");
|
|
151214
|
-
if (rlEntry)
|
|
151215
|
-
baseForSync["_rels/.rels"] = await rlEntry.async("string");
|
|
151216
|
-
const { contentTypesXml, relsXml } = syncPackageMetadata({
|
|
151217
|
-
baseFiles: baseForSync,
|
|
151218
|
-
updatedDocs: {}
|
|
151219
|
-
});
|
|
151220
|
-
zip.file("[Content_Types].xml", contentTypesXml);
|
|
151221
|
-
zip.file("_rels/.rels", relsXml);
|
|
151222
|
-
}
|
|
151223
|
-
async unzip(file) {
|
|
151224
|
-
return await this.zip.loadAsync(file);
|
|
151225
|
-
}
|
|
151226
|
-
async updateZip({ docx, updatedDocs, originalDocxFile, media, fonts, isHeadless, compression = "DEFLATE" }) {
|
|
151227
|
-
let zip;
|
|
151228
|
-
if (originalDocxFile)
|
|
151229
|
-
zip = await this.exportFromOriginalFile(originalDocxFile, updatedDocs, media, fonts);
|
|
151230
|
-
else
|
|
151231
|
-
zip = await this.exportFromCollaborativeDocx(docx, updatedDocs, media, fonts);
|
|
151232
|
-
const exportType = isHeadless ? "nodebuffer" : "blob";
|
|
151233
|
-
return await zip.generateAsync({
|
|
151234
|
-
type: exportType,
|
|
151235
|
-
mimeType: DOCX,
|
|
151236
|
-
compression,
|
|
151237
|
-
compressionOptions: compression === "DEFLATE" ? { level: 6 } : undefined
|
|
151238
|
-
});
|
|
151239
|
-
}
|
|
151240
|
-
async exportFromCollaborativeDocx(docx, updatedDocs, media, fonts) {
|
|
151241
|
-
if (!Array.isArray(docx))
|
|
151242
|
-
throw new Error("Collaborative DOCX export requires base package entries");
|
|
151243
|
-
const zip = new import_jszip_min.default;
|
|
151244
|
-
for (const file of docx) {
|
|
151245
|
-
const content2 = file.content;
|
|
151246
|
-
zip.file(file.name, content2);
|
|
151247
|
-
}
|
|
151248
|
-
Object.keys(updatedDocs).forEach((key) => {
|
|
151249
|
-
if (updatedDocs[key] === null)
|
|
151250
|
-
zip.remove(key);
|
|
151251
|
-
else
|
|
151252
|
-
zip.file(key, updatedDocs[key]);
|
|
151253
|
-
});
|
|
151254
|
-
Object.keys(media).forEach((path2) => {
|
|
151255
|
-
const value = media[path2];
|
|
151256
|
-
const binaryData = typeof value === "string" ? base64ToUint8Array(value) : value;
|
|
151257
|
-
zip.file(path2, binaryData);
|
|
151258
|
-
});
|
|
151259
|
-
for (const [fontName, fontUintArray] of Object.entries(fonts))
|
|
151260
|
-
zip.file(fontName, fontUintArray);
|
|
151261
|
-
await this.updateContentTypes(zip, media, false, updatedDocs, fonts);
|
|
151262
|
-
await this.#syncPackageMetadataInZip(zip);
|
|
151263
|
-
return zip;
|
|
151264
|
-
}
|
|
151265
|
-
async exportFromOriginalFile(originalDocxFile, updatedDocs, media, fonts) {
|
|
151266
|
-
const unzippedOriginalDocx = await this.unzip(originalDocxFile);
|
|
151267
|
-
const filePromises = [];
|
|
151268
|
-
unzippedOriginalDocx.forEach((relativePath, zipEntry) => {
|
|
151269
|
-
const promise = zipEntry.async("uint8array").then((u8) => {
|
|
151270
|
-
unzippedOriginalDocx.file(zipEntry.name, isXmlLike(zipEntry.name) ? ensureXmlString(u8) : u8);
|
|
151271
|
-
});
|
|
151272
|
-
filePromises.push(promise);
|
|
151273
|
-
});
|
|
151274
|
-
await Promise.all(filePromises);
|
|
151275
|
-
Object.keys(updatedDocs).forEach((key) => {
|
|
151276
|
-
if (updatedDocs[key] === null)
|
|
151277
|
-
unzippedOriginalDocx.remove(key);
|
|
151278
|
-
else
|
|
151279
|
-
unzippedOriginalDocx.file(key, updatedDocs[key]);
|
|
151280
|
-
});
|
|
151281
|
-
Object.keys(media).forEach((path2) => {
|
|
151282
|
-
unzippedOriginalDocx.file(path2, media[path2]);
|
|
151283
|
-
});
|
|
151284
|
-
if (fonts)
|
|
151285
|
-
for (const [fontName, fontUintArray] of Object.entries(fonts))
|
|
151286
|
-
unzippedOriginalDocx.file(fontName, fontUintArray);
|
|
151287
|
-
await this.updateContentTypes(unzippedOriginalDocx, media, false, updatedDocs, fonts);
|
|
151288
|
-
await this.#syncPackageMetadataInZip(unzippedOriginalDocx);
|
|
151289
|
-
return unzippedOriginalDocx;
|
|
151290
|
-
}
|
|
151291
|
-
#detectImageContentType(value) {
|
|
151292
|
-
if (value == null)
|
|
151293
|
-
return null;
|
|
151294
|
-
if (typeof value === "string" && value.startsWith("data:image/"))
|
|
151295
|
-
return value.match(/^data:(image\/[a-zA-Z0-9.+-]+);/i)?.[1]?.toLowerCase() || null;
|
|
151296
|
-
let detectedType = null;
|
|
151297
|
-
if (value instanceof ArrayBuffer)
|
|
151298
|
-
detectedType = detectImageType(new Uint8Array(value));
|
|
151299
|
-
else if (ArrayBuffer.isView(value))
|
|
151300
|
-
detectedType = detectImageType(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
151301
|
-
else if (typeof value === "string")
|
|
151302
|
-
detectedType = detectImageType(value.startsWith("data:") ? value.split(",", 2)[1] : value);
|
|
151303
|
-
if (!detectedType)
|
|
151304
|
-
return null;
|
|
151305
|
-
return `image/${MIME_TYPE_FOR_EXT[detectedType] || detectedType}`;
|
|
151306
|
-
}
|
|
151307
|
-
}, DocxZipper_default;
|
|
151308
|
-
var init_DocxZipper_gWkmvJfR_es = __esm(() => {
|
|
151309
|
-
init_rolldown_runtime_B2q5OVn9_es();
|
|
151310
|
-
init_jszip_ChlR43oI_es();
|
|
151311
|
-
init_xml_js_40FWvL78_es();
|
|
151312
|
-
init_constants_Qqwopz80_es();
|
|
150691
|
+
var buffer2, base64Js2, lookup2, revLookup2, Arr2, code5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i3, len2, ieee7542, Buffer3;
|
|
150692
|
+
var init_dist_Cwvmda4Q_es = __esm(() => {
|
|
151313
150693
|
buffer2 = {};
|
|
151314
150694
|
base64Js2 = {};
|
|
151315
150695
|
base64Js2.byteLength = byteLength2;
|
|
@@ -152924,6 +152304,1370 @@ var init_DocxZipper_gWkmvJfR_es = __esm(() => {
|
|
|
152924
152304
|
buffer2.kStringMaxLength;
|
|
152925
152305
|
buffer2.resolveObjectURL;
|
|
152926
152306
|
buffer2.transcode;
|
|
152307
|
+
});
|
|
152308
|
+
|
|
152309
|
+
// ../../packages/superdoc/dist/chunks/detect-container-CstXTt5n.es.js
|
|
152310
|
+
function matchesMagic(bytes, magic) {
|
|
152311
|
+
if (bytes.length < magic.length)
|
|
152312
|
+
return false;
|
|
152313
|
+
for (let i4 = 0;i4 < magic.length; i4++)
|
|
152314
|
+
if (bytes[i4] !== magic[i4])
|
|
152315
|
+
return false;
|
|
152316
|
+
return true;
|
|
152317
|
+
}
|
|
152318
|
+
function detectContainerType(data) {
|
|
152319
|
+
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
152320
|
+
if (matchesMagic(bytes, ZIP_MAGIC))
|
|
152321
|
+
return "zip";
|
|
152322
|
+
if (matchesMagic(bytes, CFB_MAGIC))
|
|
152323
|
+
return "cfb";
|
|
152324
|
+
return "unknown";
|
|
152325
|
+
}
|
|
152326
|
+
var ZIP_MAGIC, CFB_MAGIC;
|
|
152327
|
+
var init_detect_container_CstXTt5n_es = __esm(() => {
|
|
152328
|
+
ZIP_MAGIC = [
|
|
152329
|
+
80,
|
|
152330
|
+
75,
|
|
152331
|
+
3,
|
|
152332
|
+
4
|
|
152333
|
+
];
|
|
152334
|
+
CFB_MAGIC = [
|
|
152335
|
+
208,
|
|
152336
|
+
207,
|
|
152337
|
+
17,
|
|
152338
|
+
224,
|
|
152339
|
+
161,
|
|
152340
|
+
177,
|
|
152341
|
+
26,
|
|
152342
|
+
225
|
|
152343
|
+
];
|
|
152344
|
+
});
|
|
152345
|
+
|
|
152346
|
+
// ../../packages/superdoc/dist/chunks/detect-container-Mk-wjDRB.es.js
|
|
152347
|
+
var exports_detect_container_Mk_wjDRB_es = {};
|
|
152348
|
+
__export(exports_detect_container_Mk_wjDRB_es, {
|
|
152349
|
+
detectContainerType: () => detectContainerType
|
|
152350
|
+
});
|
|
152351
|
+
var init_detect_container_Mk_wjDRB_es = __esm(() => {
|
|
152352
|
+
init_detect_container_CstXTt5n_es();
|
|
152353
|
+
});
|
|
152354
|
+
|
|
152355
|
+
// ../../packages/superdoc/dist/chunks/errors-CtyzHiH4.es.js
|
|
152356
|
+
var EditorError, InvalidStateError, NoSourcePathError, FileSystemNotAvailableError, DocumentLoadError, DocxEncryptionErrorCode, DocxEncryptionError;
|
|
152357
|
+
var init_errors_CtyzHiH4_es = __esm(() => {
|
|
152358
|
+
EditorError = class extends Error {
|
|
152359
|
+
constructor(message) {
|
|
152360
|
+
super(message);
|
|
152361
|
+
this.name = "EditorError";
|
|
152362
|
+
}
|
|
152363
|
+
};
|
|
152364
|
+
InvalidStateError = class extends EditorError {
|
|
152365
|
+
constructor(message) {
|
|
152366
|
+
super(message);
|
|
152367
|
+
this.name = "InvalidStateError";
|
|
152368
|
+
}
|
|
152369
|
+
};
|
|
152370
|
+
NoSourcePathError = class extends EditorError {
|
|
152371
|
+
constructor(message) {
|
|
152372
|
+
super(message);
|
|
152373
|
+
this.name = "NoSourcePathError";
|
|
152374
|
+
}
|
|
152375
|
+
};
|
|
152376
|
+
FileSystemNotAvailableError = class extends EditorError {
|
|
152377
|
+
constructor(message) {
|
|
152378
|
+
super(message);
|
|
152379
|
+
this.name = "FileSystemNotAvailableError";
|
|
152380
|
+
}
|
|
152381
|
+
};
|
|
152382
|
+
DocumentLoadError = class extends EditorError {
|
|
152383
|
+
constructor(message, cause) {
|
|
152384
|
+
super(message);
|
|
152385
|
+
this.name = "DocumentLoadError";
|
|
152386
|
+
this.cause = cause;
|
|
152387
|
+
}
|
|
152388
|
+
};
|
|
152389
|
+
DocxEncryptionErrorCode = {
|
|
152390
|
+
PASSWORD_REQUIRED: "DOCX_PASSWORD_REQUIRED",
|
|
152391
|
+
PASSWORD_INVALID: "DOCX_PASSWORD_INVALID",
|
|
152392
|
+
ENCRYPTION_UNSUPPORTED: "DOCX_ENCRYPTION_UNSUPPORTED",
|
|
152393
|
+
DECRYPTION_FAILED: "DOCX_DECRYPTION_FAILED"
|
|
152394
|
+
};
|
|
152395
|
+
DocxEncryptionError = class extends EditorError {
|
|
152396
|
+
constructor(code6, message, cause) {
|
|
152397
|
+
super(message);
|
|
152398
|
+
this.name = "DocxEncryptionError";
|
|
152399
|
+
this.code = code6;
|
|
152400
|
+
this.cause = cause;
|
|
152401
|
+
}
|
|
152402
|
+
};
|
|
152403
|
+
});
|
|
152404
|
+
|
|
152405
|
+
// ../../packages/superdoc/dist/chunks/decrypt-docx-CNtHeQDp.es.js
|
|
152406
|
+
var exports_decrypt_docx_CNtHeQDp_es = {};
|
|
152407
|
+
__export(exports_decrypt_docx_CNtHeQDp_es, {
|
|
152408
|
+
decryptDocxIfNeeded: () => decryptDocxIfNeeded
|
|
152409
|
+
});
|
|
152410
|
+
function concatUint8Arrays(chunks) {
|
|
152411
|
+
const totalLength = chunks.reduce((sum, chunk2) => sum + chunk2.length, 0);
|
|
152412
|
+
const result = new Uint8Array(totalLength);
|
|
152413
|
+
let offset = 0;
|
|
152414
|
+
for (const chunk2 of chunks) {
|
|
152415
|
+
result.set(chunk2, offset);
|
|
152416
|
+
offset += chunk2.length;
|
|
152417
|
+
}
|
|
152418
|
+
return result;
|
|
152419
|
+
}
|
|
152420
|
+
function getSectorOffset(sectorId, sectorSize) {
|
|
152421
|
+
return (sectorId + 1) * sectorSize;
|
|
152422
|
+
}
|
|
152423
|
+
function readUint16LE$1(view, offset) {
|
|
152424
|
+
return view.getUint16(offset, true);
|
|
152425
|
+
}
|
|
152426
|
+
function readUint32LE(view, offset) {
|
|
152427
|
+
return view.getUint32(offset, true);
|
|
152428
|
+
}
|
|
152429
|
+
function readUint64LE(view, offset) {
|
|
152430
|
+
const low = BigInt(view.getUint32(offset, true));
|
|
152431
|
+
return BigInt(view.getUint32(offset + 4, true)) << 32n | low;
|
|
152432
|
+
}
|
|
152433
|
+
function decodeUtf16Le(bytes) {
|
|
152434
|
+
return utf16LeDecoder.decode(bytes).replace(/\u0000+$/g, "");
|
|
152435
|
+
}
|
|
152436
|
+
function createDataView(bytes) {
|
|
152437
|
+
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
152438
|
+
}
|
|
152439
|
+
function ensureAvailable(bytes, offset, length3, label) {
|
|
152440
|
+
if (offset < 0 || length3 < 0 || offset + length3 > bytes.length)
|
|
152441
|
+
throw new Error(`CFB ${label} exceeds available data`);
|
|
152442
|
+
}
|
|
152443
|
+
function parseHeader(bytes) {
|
|
152444
|
+
if (bytes.length < 512)
|
|
152445
|
+
throw new Error(`CFB header is truncated (${bytes.length} bytes)`);
|
|
152446
|
+
for (let i4 = 0;i4 < CFB_SIGNATURE.length; i4++)
|
|
152447
|
+
if (bytes[i4] !== CFB_SIGNATURE[i4])
|
|
152448
|
+
throw new Error("Invalid CFB signature");
|
|
152449
|
+
const view = createDataView(bytes);
|
|
152450
|
+
const majorVersion = readUint16LE$1(view, 26);
|
|
152451
|
+
const byteOrder = readUint16LE$1(view, 28);
|
|
152452
|
+
const sectorShift = readUint16LE$1(view, 30);
|
|
152453
|
+
const miniSectorShift = readUint16LE$1(view, 32);
|
|
152454
|
+
const sectorSize = 1 << sectorShift;
|
|
152455
|
+
const miniSectorSize = 1 << miniSectorShift;
|
|
152456
|
+
if (byteOrder !== 65534)
|
|
152457
|
+
throw new Error(`Unsupported CFB byte order: 0x${byteOrder.toString(16)}`);
|
|
152458
|
+
if (!(majorVersion === 3 && sectorSize === 512 || majorVersion === 4 && sectorSize === 4096))
|
|
152459
|
+
throw new Error(`Unsupported CFB major version ${majorVersion} with sector size ${sectorSize}`);
|
|
152460
|
+
const difatEntries = [];
|
|
152461
|
+
for (let i4 = 0;i4 < 109; i4++) {
|
|
152462
|
+
const sectorId = readUint32LE(view, 76 + i4 * 4);
|
|
152463
|
+
if (sectorId !== 4294967295)
|
|
152464
|
+
difatEntries.push(sectorId);
|
|
152465
|
+
}
|
|
152466
|
+
return {
|
|
152467
|
+
sectorSize,
|
|
152468
|
+
miniSectorSize,
|
|
152469
|
+
numberOfFatSectors: readUint32LE(view, 44),
|
|
152470
|
+
firstDirectorySector: readUint32LE(view, 48),
|
|
152471
|
+
miniStreamCutoffSize: readUint32LE(view, 56),
|
|
152472
|
+
firstMiniFatSector: readUint32LE(view, 60),
|
|
152473
|
+
numberOfMiniFatSectors: readUint32LE(view, 64),
|
|
152474
|
+
firstDifatSector: readUint32LE(view, 68),
|
|
152475
|
+
numberOfDifatSectors: readUint32LE(view, 72),
|
|
152476
|
+
difatEntries
|
|
152477
|
+
};
|
|
152478
|
+
}
|
|
152479
|
+
function readSector(bytes, header, sectorId) {
|
|
152480
|
+
if (sectorId >= 4294967292)
|
|
152481
|
+
throw new Error(`Invalid sector id 0x${sectorId.toString(16)}`);
|
|
152482
|
+
const offset = getSectorOffset(sectorId, header.sectorSize);
|
|
152483
|
+
ensureAvailable(bytes, offset, header.sectorSize, `sector ${sectorId}`);
|
|
152484
|
+
return bytes.subarray(offset, offset + header.sectorSize);
|
|
152485
|
+
}
|
|
152486
|
+
function readDifatEntries(bytes, header) {
|
|
152487
|
+
const difatEntries = [...header.difatEntries];
|
|
152488
|
+
let nextDifatSector = header.firstDifatSector;
|
|
152489
|
+
for (let i4 = 0;i4 < header.numberOfDifatSectors; i4++) {
|
|
152490
|
+
if (nextDifatSector === 4294967294 || nextDifatSector === 4294967295)
|
|
152491
|
+
break;
|
|
152492
|
+
const view = createDataView(readSector(bytes, header, nextDifatSector));
|
|
152493
|
+
const entriesPerDifatSector = header.sectorSize / 4 - 1;
|
|
152494
|
+
for (let entryIndex = 0;entryIndex < entriesPerDifatSector; entryIndex++) {
|
|
152495
|
+
const fatSectorId = readUint32LE(view, entryIndex * 4);
|
|
152496
|
+
if (fatSectorId !== 4294967295)
|
|
152497
|
+
difatEntries.push(fatSectorId);
|
|
152498
|
+
}
|
|
152499
|
+
nextDifatSector = readUint32LE(view, header.sectorSize - 4);
|
|
152500
|
+
}
|
|
152501
|
+
if (difatEntries.length < header.numberOfFatSectors)
|
|
152502
|
+
throw new Error(`CFB DIFAT only exposed ${difatEntries.length} FAT sectors, expected ${header.numberOfFatSectors}`);
|
|
152503
|
+
return difatEntries.slice(0, header.numberOfFatSectors);
|
|
152504
|
+
}
|
|
152505
|
+
function readFat(bytes, header) {
|
|
152506
|
+
const fatSectorIds = readDifatEntries(bytes, header);
|
|
152507
|
+
const fatEntries = [];
|
|
152508
|
+
for (const fatSectorId of fatSectorIds) {
|
|
152509
|
+
const view = createDataView(readSector(bytes, header, fatSectorId));
|
|
152510
|
+
const entriesPerSector = header.sectorSize / 4;
|
|
152511
|
+
for (let i4 = 0;i4 < entriesPerSector; i4++)
|
|
152512
|
+
fatEntries.push(readUint32LE(view, i4 * 4));
|
|
152513
|
+
}
|
|
152514
|
+
return fatEntries;
|
|
152515
|
+
}
|
|
152516
|
+
function readSectorChain(bytes, header, fat, startSector) {
|
|
152517
|
+
if (startSector === 4294967294 || startSector === 4294967295)
|
|
152518
|
+
return new Uint8Array(0);
|
|
152519
|
+
const chunks = [];
|
|
152520
|
+
const visited = /* @__PURE__ */ new Set;
|
|
152521
|
+
let sectorId = startSector;
|
|
152522
|
+
while (sectorId !== CFB_END_OF_CHAIN) {
|
|
152523
|
+
if (visited.has(sectorId))
|
|
152524
|
+
throw new Error(`CFB sector chain loop detected at sector ${sectorId}`);
|
|
152525
|
+
if (sectorId >= fat.length)
|
|
152526
|
+
throw new Error(`CFB sector ${sectorId} is out of FAT bounds`);
|
|
152527
|
+
visited.add(sectorId);
|
|
152528
|
+
chunks.push(readSector(bytes, header, sectorId));
|
|
152529
|
+
const nextSector = fat[sectorId];
|
|
152530
|
+
if (nextSector == null)
|
|
152531
|
+
throw new Error(`CFB FAT missing next sector for sector ${sectorId}`);
|
|
152532
|
+
sectorId = nextSector;
|
|
152533
|
+
}
|
|
152534
|
+
return concatUint8Arrays(chunks);
|
|
152535
|
+
}
|
|
152536
|
+
function parseStreamSize(view, offset) {
|
|
152537
|
+
const streamSize = readUint64LE(view, offset);
|
|
152538
|
+
if (streamSize > BigInt(Number.MAX_SAFE_INTEGER))
|
|
152539
|
+
throw new Error(`CFB stream is too large to fit in a JavaScript number: ${streamSize.toString()}`);
|
|
152540
|
+
return Number(streamSize);
|
|
152541
|
+
}
|
|
152542
|
+
function parseDirectoryEntries(directoryBytes) {
|
|
152543
|
+
const entries2 = [];
|
|
152544
|
+
for (let offset = 0;offset + 128 <= directoryBytes.length; offset += 128) {
|
|
152545
|
+
const slice2 = directoryBytes.subarray(offset, offset + 128);
|
|
152546
|
+
const view = createDataView(slice2);
|
|
152547
|
+
const nameLength = readUint16LE$1(view, 64);
|
|
152548
|
+
const rawNameBytes = slice2.subarray(0, Math.max(0, Math.min(nameLength, 64) - 2));
|
|
152549
|
+
entries2.push({
|
|
152550
|
+
name: decodeUtf16Le(rawNameBytes),
|
|
152551
|
+
objectType: slice2[66],
|
|
152552
|
+
leftSiblingId: readUint32LE(view, 68),
|
|
152553
|
+
rightSiblingId: readUint32LE(view, 72),
|
|
152554
|
+
childId: readUint32LE(view, 76),
|
|
152555
|
+
startSector: readUint32LE(view, 116),
|
|
152556
|
+
streamSize: parseStreamSize(view, 120)
|
|
152557
|
+
});
|
|
152558
|
+
}
|
|
152559
|
+
return entries2;
|
|
152560
|
+
}
|
|
152561
|
+
function forEachSiblingTree(entries2, entryId, visitor, visited = /* @__PURE__ */ new Set) {
|
|
152562
|
+
if (entryId === 4294967295)
|
|
152563
|
+
return false;
|
|
152564
|
+
if (entryId >= entries2.length)
|
|
152565
|
+
throw new Error(`CFB directory entry id ${entryId} is out of bounds`);
|
|
152566
|
+
if (visited.has(entryId))
|
|
152567
|
+
throw new Error(`CFB directory tree loop detected at entry id ${entryId}`);
|
|
152568
|
+
visited.add(entryId);
|
|
152569
|
+
const entry = entries2[entryId];
|
|
152570
|
+
if (forEachSiblingTree(entries2, entry.leftSiblingId, visitor, visited))
|
|
152571
|
+
return true;
|
|
152572
|
+
if (visitor(entry) === true)
|
|
152573
|
+
return true;
|
|
152574
|
+
if (forEachSiblingTree(entries2, entry.rightSiblingId, visitor, visited))
|
|
152575
|
+
return true;
|
|
152576
|
+
return false;
|
|
152577
|
+
}
|
|
152578
|
+
function findEntryByPath(entries2, path2) {
|
|
152579
|
+
const components = path2.split("/").map((component) => component.trim()).filter(Boolean);
|
|
152580
|
+
let currentEntry = entries2[0];
|
|
152581
|
+
for (const component of components) {
|
|
152582
|
+
if (currentEntry.objectType !== CFB_OBJECT_TYPE.ROOT && currentEntry.objectType !== CFB_OBJECT_TYPE.STORAGE)
|
|
152583
|
+
return null;
|
|
152584
|
+
let nextEntry = null;
|
|
152585
|
+
forEachSiblingTree(entries2, currentEntry.childId, (candidate) => {
|
|
152586
|
+
if (candidate.name.toLowerCase() === component.toLowerCase()) {
|
|
152587
|
+
nextEntry = candidate;
|
|
152588
|
+
return true;
|
|
152589
|
+
}
|
|
152590
|
+
return false;
|
|
152591
|
+
});
|
|
152592
|
+
if (!nextEntry)
|
|
152593
|
+
return null;
|
|
152594
|
+
currentEntry = nextEntry;
|
|
152595
|
+
}
|
|
152596
|
+
return currentEntry;
|
|
152597
|
+
}
|
|
152598
|
+
function readMiniStream(rootEntry, bytes, header, fat) {
|
|
152599
|
+
if (rootEntry.streamSize === 0 || rootEntry.startSector === 4294967294)
|
|
152600
|
+
return new Uint8Array(0);
|
|
152601
|
+
return readSectorChain(bytes, header, fat, rootEntry.startSector).subarray(0, rootEntry.streamSize);
|
|
152602
|
+
}
|
|
152603
|
+
function readMiniFat(bytes, header, fat) {
|
|
152604
|
+
if (header.numberOfMiniFatSectors === 0 || header.firstMiniFatSector === 4294967294)
|
|
152605
|
+
return [];
|
|
152606
|
+
const miniFatBytes = readSectorChain(bytes, header, fat, header.firstMiniFatSector);
|
|
152607
|
+
const view = createDataView(miniFatBytes);
|
|
152608
|
+
const entryCount = Math.floor(miniFatBytes.length / 4);
|
|
152609
|
+
const entries2 = [];
|
|
152610
|
+
for (let i4 = 0;i4 < entryCount; i4++)
|
|
152611
|
+
entries2.push(readUint32LE(view, i4 * 4));
|
|
152612
|
+
return entries2;
|
|
152613
|
+
}
|
|
152614
|
+
function readMiniSectorChain(miniStream, miniFat, miniSectorSize, startSector) {
|
|
152615
|
+
if (startSector === 4294967294 || startSector === 4294967295)
|
|
152616
|
+
return new Uint8Array(0);
|
|
152617
|
+
const chunks = [];
|
|
152618
|
+
const visited = /* @__PURE__ */ new Set;
|
|
152619
|
+
let sectorId = startSector;
|
|
152620
|
+
while (sectorId !== CFB_END_OF_CHAIN) {
|
|
152621
|
+
if (visited.has(sectorId))
|
|
152622
|
+
throw new Error(`CFB mini sector chain loop detected at mini sector ${sectorId}`);
|
|
152623
|
+
if (sectorId >= miniFat.length)
|
|
152624
|
+
throw new Error(`CFB mini sector ${sectorId} is out of MiniFAT bounds`);
|
|
152625
|
+
visited.add(sectorId);
|
|
152626
|
+
const offset = sectorId * miniSectorSize;
|
|
152627
|
+
ensureAvailable(miniStream, offset, miniSectorSize, `mini sector ${sectorId}`);
|
|
152628
|
+
chunks.push(miniStream.subarray(offset, offset + miniSectorSize));
|
|
152629
|
+
const nextSector = miniFat[sectorId];
|
|
152630
|
+
if (nextSector == null)
|
|
152631
|
+
throw new Error(`CFB MiniFAT missing next sector for mini sector ${sectorId}`);
|
|
152632
|
+
sectorId = nextSector;
|
|
152633
|
+
}
|
|
152634
|
+
return concatUint8Arrays(chunks);
|
|
152635
|
+
}
|
|
152636
|
+
function createCfbReader(data) {
|
|
152637
|
+
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
152638
|
+
const header = parseHeader(bytes);
|
|
152639
|
+
const fat = readFat(bytes, header);
|
|
152640
|
+
const directoryEntries = parseDirectoryEntries(readSectorChain(bytes, header, fat, header.firstDirectorySector));
|
|
152641
|
+
if (directoryEntries.length === 0 || directoryEntries[0].objectType !== CFB_OBJECT_TYPE.ROOT)
|
|
152642
|
+
throw new Error("CFB root directory entry is missing");
|
|
152643
|
+
const rootEntry = directoryEntries[0];
|
|
152644
|
+
const miniFat = readMiniFat(bytes, header, fat);
|
|
152645
|
+
const miniStream = readMiniStream(rootEntry, bytes, header, fat);
|
|
152646
|
+
return { getStream(path2) {
|
|
152647
|
+
const entry = findEntryByPath(directoryEntries, path2);
|
|
152648
|
+
if (!entry || entry.objectType !== CFB_OBJECT_TYPE.STREAM)
|
|
152649
|
+
return null;
|
|
152650
|
+
if (entry.streamSize < header.miniStreamCutoffSize)
|
|
152651
|
+
return readMiniSectorChain(miniStream, miniFat, header.miniSectorSize, entry.startSector).subarray(0, entry.streamSize);
|
|
152652
|
+
return readSectorChain(bytes, header, fat, entry.startSector).subarray(0, entry.streamSize);
|
|
152653
|
+
} };
|
|
152654
|
+
}
|
|
152655
|
+
function extractEncryptionStreams(data) {
|
|
152656
|
+
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
152657
|
+
let reader;
|
|
152658
|
+
try {
|
|
152659
|
+
reader = createCfbReader(bytes);
|
|
152660
|
+
} catch (err) {
|
|
152661
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, "Failed to parse OLE/CFB container", err instanceof Error ? err : undefined);
|
|
152662
|
+
}
|
|
152663
|
+
const encryptionInfo = reader.getStream("/EncryptionInfo");
|
|
152664
|
+
if (!encryptionInfo)
|
|
152665
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, "CFB container missing EncryptionInfo stream");
|
|
152666
|
+
const encryptedPackage = reader.getStream("/EncryptedPackage");
|
|
152667
|
+
if (!encryptedPackage)
|
|
152668
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, "CFB container missing EncryptedPackage stream");
|
|
152669
|
+
return {
|
|
152670
|
+
encryptionInfo,
|
|
152671
|
+
encryptedPackage
|
|
152672
|
+
};
|
|
152673
|
+
}
|
|
152674
|
+
function readUint16LE(data, offset) {
|
|
152675
|
+
return data[offset] | data[offset + 1] << 8;
|
|
152676
|
+
}
|
|
152677
|
+
function extractElementAttrs(xml, localName) {
|
|
152678
|
+
const tagPattern = /* @__PURE__ */ new RegExp(`<(?:\\w+:)?${localName}\\b([^>]*)/?>`);
|
|
152679
|
+
const match = xml.match(tagPattern);
|
|
152680
|
+
if (!match)
|
|
152681
|
+
return null;
|
|
152682
|
+
const attrs = {};
|
|
152683
|
+
const attrPattern = /(\w+)="([^"]*)"/g;
|
|
152684
|
+
let attrMatch;
|
|
152685
|
+
while ((attrMatch = attrPattern.exec(match[1])) !== null)
|
|
152686
|
+
attrs[attrMatch[1]] = attrMatch[2];
|
|
152687
|
+
return attrs;
|
|
152688
|
+
}
|
|
152689
|
+
function base64ToBytes(b64) {
|
|
152690
|
+
if (typeof atob === "function") {
|
|
152691
|
+
const raw = atob(b64);
|
|
152692
|
+
const bytes = new Uint8Array(raw.length);
|
|
152693
|
+
for (let i4 = 0;i4 < raw.length; i4++)
|
|
152694
|
+
bytes[i4] = raw.charCodeAt(i4);
|
|
152695
|
+
return bytes;
|
|
152696
|
+
}
|
|
152697
|
+
return new Uint8Array(Buffer3.from(b64, "base64"));
|
|
152698
|
+
}
|
|
152699
|
+
function requireAttr(attrs, name, label) {
|
|
152700
|
+
const value = attrs?.[name];
|
|
152701
|
+
if (value == null)
|
|
152702
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, `Missing required attribute "${name}" on <${label}>`);
|
|
152703
|
+
return value;
|
|
152704
|
+
}
|
|
152705
|
+
function requireBase64Attr(attrs, name, label) {
|
|
152706
|
+
return base64ToBytes(requireAttr(attrs, name, label));
|
|
152707
|
+
}
|
|
152708
|
+
function requireIntAttr(attrs, name, label) {
|
|
152709
|
+
const value = parseInt(requireAttr(attrs, name, label), 10);
|
|
152710
|
+
if (Number.isNaN(value))
|
|
152711
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, `Invalid integer for attribute "${name}" on <${label}>`);
|
|
152712
|
+
return value;
|
|
152713
|
+
}
|
|
152714
|
+
function parseAgileXml(xmlBytes) {
|
|
152715
|
+
const xml = new TextDecoder("utf-8").decode(xmlBytes);
|
|
152716
|
+
const keyData = extractElementAttrs(xml, "keyData");
|
|
152717
|
+
const dataIntegrity = extractElementAttrs(xml, "dataIntegrity");
|
|
152718
|
+
const encryptedKey = extractElementAttrs(xml, "encryptedKey");
|
|
152719
|
+
return {
|
|
152720
|
+
keySalt: requireBase64Attr(keyData, "saltValue", "keyData"),
|
|
152721
|
+
keyBits: requireIntAttr(keyData, "keyBits", "keyData"),
|
|
152722
|
+
hashAlgorithm: requireAttr(keyData, "hashAlgorithm", "keyData"),
|
|
152723
|
+
hashSize: requireIntAttr(keyData, "hashSize", "keyData"),
|
|
152724
|
+
blockSize: requireIntAttr(keyData, "blockSize", "keyData"),
|
|
152725
|
+
cipherAlgorithm: requireAttr(keyData, "cipherAlgorithm", "keyData"),
|
|
152726
|
+
cipherChaining: requireAttr(keyData, "cipherChaining", "keyData"),
|
|
152727
|
+
spinCount: requireIntAttr(encryptedKey, "spinCount", "encryptedKey"),
|
|
152728
|
+
passwordSalt: requireBase64Attr(encryptedKey, "saltValue", "encryptedKey"),
|
|
152729
|
+
passwordHashAlgorithm: requireAttr(encryptedKey, "hashAlgorithm", "encryptedKey"),
|
|
152730
|
+
passwordKeyBits: requireIntAttr(encryptedKey, "keyBits", "encryptedKey"),
|
|
152731
|
+
passwordBlockSize: requireIntAttr(encryptedKey, "blockSize", "encryptedKey"),
|
|
152732
|
+
encryptedVerifierHashInput: requireBase64Attr(encryptedKey, "encryptedVerifierHashInput", "encryptedKey"),
|
|
152733
|
+
encryptedVerifierHashValue: requireBase64Attr(encryptedKey, "encryptedVerifierHashValue", "encryptedKey"),
|
|
152734
|
+
encryptedKeyValue: requireBase64Attr(encryptedKey, "encryptedKeyValue", "encryptedKey"),
|
|
152735
|
+
encryptedHmacKey: requireBase64Attr(dataIntegrity, "encryptedHmacKey", "dataIntegrity"),
|
|
152736
|
+
encryptedHmacValue: requireBase64Attr(dataIntegrity, "encryptedHmacValue", "dataIntegrity")
|
|
152737
|
+
};
|
|
152738
|
+
}
|
|
152739
|
+
function parseEncryptionInfo(data) {
|
|
152740
|
+
if (data.length < MIN_HEADER_SIZE)
|
|
152741
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, `EncryptionInfo too short: ${data.length} bytes (minimum ${MIN_HEADER_SIZE})`);
|
|
152742
|
+
const version3 = readUint16LE(data, 0);
|
|
152743
|
+
const reserved = readUint16LE(data, 2);
|
|
152744
|
+
if (version3 === AGILE_VERSION && reserved === AGILE_RESERVED)
|
|
152745
|
+
return {
|
|
152746
|
+
type: "agile",
|
|
152747
|
+
params: parseAgileXml(data.subarray(MIN_HEADER_SIZE))
|
|
152748
|
+
};
|
|
152749
|
+
if ((version3 === STANDARD_VERSION_3 || version3 === STANDARD_VERSION_4) && reserved === STANDARD_RESERVED)
|
|
152750
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.ENCRYPTION_UNSUPPORTED, "Standard Encryption (Office 2007) is not yet supported. Only Agile Encryption (Office 2010+) is supported.");
|
|
152751
|
+
if (version3 <= 2)
|
|
152752
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.ENCRYPTION_UNSUPPORTED, "Legacy RC4 encryption is not supported. Only Agile Encryption (Office 2010+) is supported.");
|
|
152753
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.ENCRYPTION_UNSUPPORTED, `Unrecognized EncryptionInfo version=${version3} reserved=${reserved}`);
|
|
152754
|
+
}
|
|
152755
|
+
function getSubtleCrypto() {
|
|
152756
|
+
const subtle2 = globalThis.crypto?.subtle;
|
|
152757
|
+
if (!subtle2)
|
|
152758
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, "Web Crypto API (SubtleCrypto) is not available in this environment");
|
|
152759
|
+
return subtle2;
|
|
152760
|
+
}
|
|
152761
|
+
function toWebCryptoHash(ooxmlName) {
|
|
152762
|
+
const mapped = {
|
|
152763
|
+
SHA1: "SHA-1",
|
|
152764
|
+
"SHA-1": "SHA-1",
|
|
152765
|
+
SHA256: "SHA-256",
|
|
152766
|
+
"SHA-256": "SHA-256",
|
|
152767
|
+
SHA384: "SHA-384",
|
|
152768
|
+
"SHA-384": "SHA-384",
|
|
152769
|
+
SHA512: "SHA-512",
|
|
152770
|
+
"SHA-512": "SHA-512"
|
|
152771
|
+
}[ooxmlName];
|
|
152772
|
+
if (!mapped)
|
|
152773
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, `Unsupported hash algorithm: ${ooxmlName}`);
|
|
152774
|
+
return mapped;
|
|
152775
|
+
}
|
|
152776
|
+
function encodeUtf16le(str) {
|
|
152777
|
+
const buf = new Uint8Array(str.length * 2);
|
|
152778
|
+
for (let i4 = 0;i4 < str.length; i4++) {
|
|
152779
|
+
const code6 = str.charCodeAt(i4);
|
|
152780
|
+
buf[i4 * 2] = code6 & 255;
|
|
152781
|
+
buf[i4 * 2 + 1] = code6 >> 8 & 255;
|
|
152782
|
+
}
|
|
152783
|
+
return buf;
|
|
152784
|
+
}
|
|
152785
|
+
function concat(...arrays) {
|
|
152786
|
+
const totalLength = arrays.reduce((sum, a) => sum + a.length, 0);
|
|
152787
|
+
const result = new Uint8Array(totalLength);
|
|
152788
|
+
let offset = 0;
|
|
152789
|
+
for (const arr of arrays) {
|
|
152790
|
+
result.set(arr, offset);
|
|
152791
|
+
offset += arr.length;
|
|
152792
|
+
}
|
|
152793
|
+
return result;
|
|
152794
|
+
}
|
|
152795
|
+
function uint32LE(value) {
|
|
152796
|
+
const buf = new Uint8Array(4);
|
|
152797
|
+
buf[0] = value & 255;
|
|
152798
|
+
buf[1] = value >>> 8 & 255;
|
|
152799
|
+
buf[2] = value >>> 16 & 255;
|
|
152800
|
+
buf[3] = value >>> 24 & 255;
|
|
152801
|
+
return buf;
|
|
152802
|
+
}
|
|
152803
|
+
function toBuffer(arr) {
|
|
152804
|
+
return arr.buffer.slice(arr.byteOffset, arr.byteOffset + arr.byteLength);
|
|
152805
|
+
}
|
|
152806
|
+
async function hash(algorithm, data) {
|
|
152807
|
+
const digest = await getSubtleCrypto().digest(algorithm, toBuffer(data));
|
|
152808
|
+
return new Uint8Array(digest);
|
|
152809
|
+
}
|
|
152810
|
+
async function decryptAesCbc(keyBytes, iv, ciphertext) {
|
|
152811
|
+
const subtle2 = getSubtleCrypto();
|
|
152812
|
+
const blockSize = 16;
|
|
152813
|
+
const key = await subtle2.importKey("raw", toBuffer(keyBytes), { name: "AES-CBC" }, false, ["encrypt", "decrypt"]);
|
|
152814
|
+
const lastBlock = ciphertext.subarray(ciphertext.length - blockSize);
|
|
152815
|
+
const pkcs7Plaintext = new Uint8Array(blockSize);
|
|
152816
|
+
pkcs7Plaintext.fill(blockSize);
|
|
152817
|
+
const paddingBlock = new Uint8Array(await subtle2.encrypt({
|
|
152818
|
+
name: "AES-CBC",
|
|
152819
|
+
iv: toBuffer(lastBlock)
|
|
152820
|
+
}, key, pkcs7Plaintext)).subarray(0, blockSize);
|
|
152821
|
+
const withPadding = new Uint8Array(ciphertext.length + blockSize);
|
|
152822
|
+
withPadding.set(ciphertext);
|
|
152823
|
+
withPadding.set(paddingBlock, ciphertext.length);
|
|
152824
|
+
const decrypted = await subtle2.decrypt({
|
|
152825
|
+
name: "AES-CBC",
|
|
152826
|
+
iv: toBuffer(iv)
|
|
152827
|
+
}, key, withPadding);
|
|
152828
|
+
return new Uint8Array(decrypted).subarray(0, ciphertext.length);
|
|
152829
|
+
}
|
|
152830
|
+
async function deriveKey(password, salt, spinCount, keyBits, hashAlgorithm, blockKey) {
|
|
152831
|
+
const algo = toWebCryptoHash(hashAlgorithm);
|
|
152832
|
+
let h = await hash(algo, concat(salt, encodeUtf16le(password)));
|
|
152833
|
+
for (let i4 = 0;i4 < spinCount; i4++)
|
|
152834
|
+
h = await hash(algo, concat(uint32LE(i4), h));
|
|
152835
|
+
const hDerived = await hash(algo, concat(h, blockKey));
|
|
152836
|
+
const requiredBytes = keyBits / 8;
|
|
152837
|
+
if (hDerived.length >= requiredBytes)
|
|
152838
|
+
return hDerived.subarray(0, requiredBytes);
|
|
152839
|
+
const padded = new Uint8Array(requiredBytes);
|
|
152840
|
+
padded.set(hDerived);
|
|
152841
|
+
padded.fill(54, hDerived.length);
|
|
152842
|
+
return padded;
|
|
152843
|
+
}
|
|
152844
|
+
async function generateIV(hashAlgorithm, salt, blockKey, blockSize) {
|
|
152845
|
+
let ivSource;
|
|
152846
|
+
if (blockKey)
|
|
152847
|
+
ivSource = await hash(toWebCryptoHash(hashAlgorithm), concat(salt, blockKey));
|
|
152848
|
+
else
|
|
152849
|
+
ivSource = salt;
|
|
152850
|
+
if (ivSource.length >= blockSize)
|
|
152851
|
+
return ivSource.subarray(0, blockSize);
|
|
152852
|
+
const padded = new Uint8Array(blockSize);
|
|
152853
|
+
padded.set(ivSource);
|
|
152854
|
+
padded.fill(54, ivSource.length);
|
|
152855
|
+
return padded;
|
|
152856
|
+
}
|
|
152857
|
+
async function verifyPasswordAndGetKey(password, params3) {
|
|
152858
|
+
const { passwordSalt, spinCount, passwordHashAlgorithm, passwordKeyBits, passwordBlockSize } = params3;
|
|
152859
|
+
const keyVerifierInput = await deriveKey(password, passwordSalt, spinCount, passwordKeyBits, passwordHashAlgorithm, BLOCK_KEY_VERIFIER_INPUT);
|
|
152860
|
+
const keyVerifierValue = await deriveKey(password, passwordSalt, spinCount, passwordKeyBits, passwordHashAlgorithm, BLOCK_KEY_VERIFIER_VALUE);
|
|
152861
|
+
const keyEncryptedKey = await deriveKey(password, passwordSalt, spinCount, passwordKeyBits, passwordHashAlgorithm, BLOCK_KEY_ENCRYPTED_KEY);
|
|
152862
|
+
const passwordVerifierIv = await generateIV(passwordHashAlgorithm, passwordSalt, undefined, passwordBlockSize);
|
|
152863
|
+
const verifierHashInput = await decryptAesCbc(keyVerifierInput, passwordVerifierIv, params3.encryptedVerifierHashInput);
|
|
152864
|
+
const verifierHashValue = await decryptAesCbc(keyVerifierValue, passwordVerifierIv, params3.encryptedVerifierHashValue);
|
|
152865
|
+
const computedHash = await hash(toWebCryptoHash(passwordHashAlgorithm), verifierHashInput);
|
|
152866
|
+
if (!constantTimeEqual(computedHash, verifierHashValue.subarray(0, computedHash.length)))
|
|
152867
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.PASSWORD_INVALID, "The password is incorrect");
|
|
152868
|
+
return decryptAesCbc(keyEncryptedKey, passwordVerifierIv, params3.encryptedKeyValue);
|
|
152869
|
+
}
|
|
152870
|
+
function constantTimeEqual(a, b) {
|
|
152871
|
+
if (a.length !== b.length)
|
|
152872
|
+
return false;
|
|
152873
|
+
let diff = 0;
|
|
152874
|
+
for (let i4 = 0;i4 < a.length; i4++)
|
|
152875
|
+
diff |= a[i4] ^ b[i4];
|
|
152876
|
+
return diff === 0;
|
|
152877
|
+
}
|
|
152878
|
+
async function decryptPackageSegments(encryptionKey, params3, encryptedPackage) {
|
|
152879
|
+
const { keySalt, hashAlgorithm, blockSize } = params3;
|
|
152880
|
+
const algo = toWebCryptoHash(hashAlgorithm);
|
|
152881
|
+
if (encryptedPackage.length < PACKAGE_HEADER_SIZE)
|
|
152882
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, "EncryptedPackage too short to contain size header");
|
|
152883
|
+
const plaintextSize = encryptedPackage[0] | encryptedPackage[1] << 8 | encryptedPackage[2] << 16 | encryptedPackage[3] << 24 >>> 0;
|
|
152884
|
+
const encryptedData = encryptedPackage.subarray(PACKAGE_HEADER_SIZE);
|
|
152885
|
+
const segmentCount = Math.ceil(encryptedData.length / SEGMENT_SIZE);
|
|
152886
|
+
const decryptedChunks = [];
|
|
152887
|
+
for (let i4 = 0;i4 < segmentCount; i4++) {
|
|
152888
|
+
const segmentStart = i4 * SEGMENT_SIZE;
|
|
152889
|
+
const segmentEnd = Math.min(segmentStart + SEGMENT_SIZE, encryptedData.length);
|
|
152890
|
+
const segment = encryptedData.subarray(segmentStart, segmentEnd);
|
|
152891
|
+
const ivHash = await hash(algo, concat(keySalt, uint32LE(i4)));
|
|
152892
|
+
const decrypted = await decryptAesCbc(encryptionKey, ivHash.length >= blockSize ? ivHash.subarray(0, blockSize) : ivHash, segment);
|
|
152893
|
+
decryptedChunks.push(decrypted);
|
|
152894
|
+
}
|
|
152895
|
+
return concat(...decryptedChunks).subarray(0, plaintextSize);
|
|
152896
|
+
}
|
|
152897
|
+
async function verifyDataIntegrity(encryptionKey, params3, encryptedPackage) {
|
|
152898
|
+
const { keySalt, hashAlgorithm, blockSize, hashSize } = params3;
|
|
152899
|
+
const algo = toWebCryptoHash(hashAlgorithm);
|
|
152900
|
+
const subtle2 = getSubtleCrypto();
|
|
152901
|
+
const hmacKey = (await decryptAesCbc(encryptionKey, await generateIV(hashAlgorithm, keySalt, BLOCK_KEY_HMAC_KEY, blockSize), params3.encryptedHmacKey)).subarray(0, hashSize);
|
|
152902
|
+
const expectedHmac = await decryptAesCbc(encryptionKey, await generateIV(hashAlgorithm, keySalt, BLOCK_KEY_HMAC_VALUE, blockSize), params3.encryptedHmacValue);
|
|
152903
|
+
const cryptoKey = await subtle2.importKey("raw", toBuffer(hmacKey), {
|
|
152904
|
+
name: "HMAC",
|
|
152905
|
+
hash: algo
|
|
152906
|
+
}, false, ["sign"]);
|
|
152907
|
+
const computedHmac = new Uint8Array(await subtle2.sign("HMAC", cryptoKey, toBuffer(encryptedPackage)));
|
|
152908
|
+
if (!constantTimeEqual(computedHmac, expectedHmac.subarray(0, computedHmac.length)))
|
|
152909
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, "Data integrity check failed — the encrypted package may be corrupt or tampered with");
|
|
152910
|
+
}
|
|
152911
|
+
async function decryptAgilePackage(password, params3, encryptedPackage) {
|
|
152912
|
+
try {
|
|
152913
|
+
const encryptionKey = await verifyPasswordAndGetKey(password, params3);
|
|
152914
|
+
await verifyDataIntegrity(encryptionKey, params3, encryptedPackage);
|
|
152915
|
+
return await decryptPackageSegments(encryptionKey, params3, encryptedPackage);
|
|
152916
|
+
} catch (err) {
|
|
152917
|
+
if (err instanceof DocxEncryptionError)
|
|
152918
|
+
throw err;
|
|
152919
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, "Decryption failed unexpectedly", err instanceof Error ? err : undefined);
|
|
152920
|
+
}
|
|
152921
|
+
}
|
|
152922
|
+
function validateDecryptedOutput(data) {
|
|
152923
|
+
if (detectContainerType(data) !== "zip")
|
|
152924
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, "Decrypted output is not a valid ZIP archive — the file may be corrupt");
|
|
152925
|
+
}
|
|
152926
|
+
async function decryptDocxIfNeeded(data, options) {
|
|
152927
|
+
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
152928
|
+
const containerType = detectContainerType(bytes);
|
|
152929
|
+
if (containerType === "zip")
|
|
152930
|
+
return {
|
|
152931
|
+
data: bytes,
|
|
152932
|
+
wasEncrypted: false
|
|
152933
|
+
};
|
|
152934
|
+
if (containerType === "unknown")
|
|
152935
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.DECRYPTION_FAILED, "Unrecognized file format — expected a .docx (ZIP) or encrypted .docx (OLE/CFB)");
|
|
152936
|
+
if (!options?.password)
|
|
152937
|
+
throw new DocxEncryptionError(DocxEncryptionErrorCode.PASSWORD_REQUIRED, "This document is password-protected. A password is required to open it.");
|
|
152938
|
+
const streams = extractEncryptionStreams(bytes);
|
|
152939
|
+
const { params: params3 } = parseEncryptionInfo(streams.encryptionInfo);
|
|
152940
|
+
const decryptedZip = await decryptAgilePackage(options.password, params3, streams.encryptedPackage);
|
|
152941
|
+
validateDecryptedOutput(decryptedZip);
|
|
152942
|
+
return {
|
|
152943
|
+
data: decryptedZip,
|
|
152944
|
+
wasEncrypted: true
|
|
152945
|
+
};
|
|
152946
|
+
}
|
|
152947
|
+
var CFB_SIGNATURE, CFB_END_OF_CHAIN = 4294967294, CFB_OBJECT_TYPE, utf16LeDecoder, AGILE_VERSION = 4, AGILE_RESERVED = 4, STANDARD_VERSION_3 = 3, STANDARD_VERSION_4 = 4, STANDARD_RESERVED = 3, MIN_HEADER_SIZE = 8, BLOCK_KEY_VERIFIER_INPUT, BLOCK_KEY_VERIFIER_VALUE, BLOCK_KEY_ENCRYPTED_KEY, BLOCK_KEY_HMAC_KEY, BLOCK_KEY_HMAC_VALUE, SEGMENT_SIZE = 4096, PACKAGE_HEADER_SIZE = 8;
|
|
152948
|
+
var init_decrypt_docx_CNtHeQDp_es = __esm(() => {
|
|
152949
|
+
init_dist_Cwvmda4Q_es();
|
|
152950
|
+
init_errors_CtyzHiH4_es();
|
|
152951
|
+
init_detect_container_CstXTt5n_es();
|
|
152952
|
+
CFB_SIGNATURE = new Uint8Array([
|
|
152953
|
+
208,
|
|
152954
|
+
207,
|
|
152955
|
+
17,
|
|
152956
|
+
224,
|
|
152957
|
+
161,
|
|
152958
|
+
177,
|
|
152959
|
+
26,
|
|
152960
|
+
225
|
|
152961
|
+
]);
|
|
152962
|
+
CFB_OBJECT_TYPE = {
|
|
152963
|
+
STORAGE: 1,
|
|
152964
|
+
STREAM: 2,
|
|
152965
|
+
ROOT: 5
|
|
152966
|
+
};
|
|
152967
|
+
utf16LeDecoder = new TextDecoder("utf-16le");
|
|
152968
|
+
BLOCK_KEY_VERIFIER_INPUT = new Uint8Array([
|
|
152969
|
+
254,
|
|
152970
|
+
167,
|
|
152971
|
+
210,
|
|
152972
|
+
118,
|
|
152973
|
+
59,
|
|
152974
|
+
75,
|
|
152975
|
+
158,
|
|
152976
|
+
121
|
|
152977
|
+
]);
|
|
152978
|
+
BLOCK_KEY_VERIFIER_VALUE = new Uint8Array([
|
|
152979
|
+
215,
|
|
152980
|
+
170,
|
|
152981
|
+
15,
|
|
152982
|
+
109,
|
|
152983
|
+
48,
|
|
152984
|
+
97,
|
|
152985
|
+
52,
|
|
152986
|
+
78
|
|
152987
|
+
]);
|
|
152988
|
+
BLOCK_KEY_ENCRYPTED_KEY = new Uint8Array([
|
|
152989
|
+
20,
|
|
152990
|
+
110,
|
|
152991
|
+
11,
|
|
152992
|
+
231,
|
|
152993
|
+
171,
|
|
152994
|
+
172,
|
|
152995
|
+
208,
|
|
152996
|
+
214
|
|
152997
|
+
]);
|
|
152998
|
+
BLOCK_KEY_HMAC_KEY = new Uint8Array([
|
|
152999
|
+
95,
|
|
153000
|
+
178,
|
|
153001
|
+
173,
|
|
153002
|
+
1,
|
|
153003
|
+
12,
|
|
153004
|
+
185,
|
|
153005
|
+
225,
|
|
153006
|
+
246
|
|
153007
|
+
]);
|
|
153008
|
+
BLOCK_KEY_HMAC_VALUE = new Uint8Array([
|
|
153009
|
+
160,
|
|
153010
|
+
103,
|
|
153011
|
+
127,
|
|
153012
|
+
2,
|
|
153013
|
+
178,
|
|
153014
|
+
44,
|
|
153015
|
+
132,
|
|
153016
|
+
51
|
|
153017
|
+
]);
|
|
153018
|
+
});
|
|
153019
|
+
|
|
153020
|
+
// ../../packages/superdoc/dist/chunks/DocxZipper-DvDGw347.es.js
|
|
153021
|
+
function sniffEncoding(u8) {
|
|
153022
|
+
if (u8.length >= 2) {
|
|
153023
|
+
const b0 = u8[0], b1 = u8[1];
|
|
153024
|
+
if (b0 === 255 && b1 === 254)
|
|
153025
|
+
return "utf-16le";
|
|
153026
|
+
if (b0 === 254 && b1 === 255)
|
|
153027
|
+
return "utf-16be";
|
|
153028
|
+
}
|
|
153029
|
+
let nul = 0;
|
|
153030
|
+
for (let i4 = 0;i4 < Math.min(64, u8.length); i4++)
|
|
153031
|
+
if (u8[i4] === 0)
|
|
153032
|
+
nul++;
|
|
153033
|
+
if (nul > 16)
|
|
153034
|
+
return "utf-16le";
|
|
153035
|
+
return "utf-8";
|
|
153036
|
+
}
|
|
153037
|
+
function stripBOM(str) {
|
|
153038
|
+
return str && str.charCodeAt(0) === 65279 ? str.slice(1) : str;
|
|
153039
|
+
}
|
|
153040
|
+
function ensureXmlString(content2) {
|
|
153041
|
+
if (typeof content2 === "string")
|
|
153042
|
+
return stripBOM(content2);
|
|
153043
|
+
let u8 = null;
|
|
153044
|
+
if (content2 && typeof content2 === "object") {
|
|
153045
|
+
if (content2 instanceof Uint8Array)
|
|
153046
|
+
u8 = content2;
|
|
153047
|
+
else if (typeof Buffer3 !== "undefined" && Buffer3.isBuffer && Buffer3.isBuffer(content2))
|
|
153048
|
+
u8 = new Uint8Array(content2.buffer, content2.byteOffset, content2.byteLength);
|
|
153049
|
+
else if (ArrayBuffer.isView && ArrayBuffer.isView(content2))
|
|
153050
|
+
u8 = new Uint8Array(content2.buffer, content2.byteOffset, content2.byteLength);
|
|
153051
|
+
else if (content2.constructor && (content2 instanceof ArrayBuffer || content2.constructor.name === "ArrayBuffer"))
|
|
153052
|
+
u8 = new Uint8Array(content2);
|
|
153053
|
+
}
|
|
153054
|
+
if (!u8)
|
|
153055
|
+
throw new Error("Unsupported content type for XML");
|
|
153056
|
+
const enc = sniffEncoding(u8);
|
|
153057
|
+
let xml = new TextDecoder(enc).decode(u8);
|
|
153058
|
+
xml = stripBOM(xml);
|
|
153059
|
+
if (enc !== "utf-8")
|
|
153060
|
+
xml = xml.replace(/(<\?xml\b[^?]*?)\bencoding\s*=\s*["'][^"']*["']/i, '$1encoding="UTF-8"');
|
|
153061
|
+
return xml;
|
|
153062
|
+
}
|
|
153063
|
+
function readEntry(path2, baseFiles, updatedDocs) {
|
|
153064
|
+
if (updatedDocs && Object.prototype.hasOwnProperty.call(updatedDocs, path2))
|
|
153065
|
+
return updatedDocs[path2];
|
|
153066
|
+
if (!baseFiles)
|
|
153067
|
+
return;
|
|
153068
|
+
if (Array.isArray(baseFiles))
|
|
153069
|
+
return baseFiles.find((f2) => f2.name === path2)?.content;
|
|
153070
|
+
return baseFiles[path2];
|
|
153071
|
+
}
|
|
153072
|
+
function partExistsInPackage(zipPath, baseFiles, updatedDocs) {
|
|
153073
|
+
return readEntry(zipPath, baseFiles, updatedDocs) != null;
|
|
153074
|
+
}
|
|
153075
|
+
function parseXml(xmlString) {
|
|
153076
|
+
try {
|
|
153077
|
+
return import_lib$2.xml2js(xmlString, { compact: false });
|
|
153078
|
+
} catch {
|
|
153079
|
+
return null;
|
|
153080
|
+
}
|
|
153081
|
+
}
|
|
153082
|
+
function serializeXml(jsObject) {
|
|
153083
|
+
return import_lib$2.js2xml(jsObject, { spaces: 0 });
|
|
153084
|
+
}
|
|
153085
|
+
function findRootElement(parsed, tagName) {
|
|
153086
|
+
return parsed?.elements?.find((el) => {
|
|
153087
|
+
if (!el.name)
|
|
153088
|
+
return false;
|
|
153089
|
+
return (el.name.includes(":") ? el.name.split(":").pop() : el.name) === tagName;
|
|
153090
|
+
});
|
|
153091
|
+
}
|
|
153092
|
+
function createEmptyRels() {
|
|
153093
|
+
return {
|
|
153094
|
+
declaration: { attributes: {
|
|
153095
|
+
version: "1.0",
|
|
153096
|
+
encoding: "UTF-8",
|
|
153097
|
+
standalone: "yes"
|
|
153098
|
+
} },
|
|
153099
|
+
elements: [{
|
|
153100
|
+
type: "element",
|
|
153101
|
+
name: "Relationships",
|
|
153102
|
+
attributes: { xmlns: RELATIONSHIPS_NS },
|
|
153103
|
+
elements: []
|
|
153104
|
+
}]
|
|
153105
|
+
};
|
|
153106
|
+
}
|
|
153107
|
+
function findMaxRId$1(relsRoot) {
|
|
153108
|
+
let max4 = 0;
|
|
153109
|
+
for (const el of relsRoot.elements || []) {
|
|
153110
|
+
const id2 = el.attributes?.Id;
|
|
153111
|
+
if (!id2)
|
|
153112
|
+
continue;
|
|
153113
|
+
const match = id2.match(/^rId(\d+)$/);
|
|
153114
|
+
if (match)
|
|
153115
|
+
max4 = Math.max(max4, parseInt(match[1], 10));
|
|
153116
|
+
}
|
|
153117
|
+
return max4;
|
|
153118
|
+
}
|
|
153119
|
+
function reconcileContentTypes(typesRoot, presentParts) {
|
|
153120
|
+
if (!typesRoot.elements)
|
|
153121
|
+
typesRoot.elements = [];
|
|
153122
|
+
const managedByPartName = /* @__PURE__ */ new Map;
|
|
153123
|
+
for (const entry of MANAGED_PACKAGE_PARTS)
|
|
153124
|
+
managedByPartName.set(`/${entry.zipPath}`, entry);
|
|
153125
|
+
const existingOverrides = /* @__PURE__ */ new Map;
|
|
153126
|
+
for (let i4 = 0;i4 < typesRoot.elements.length; i4++) {
|
|
153127
|
+
const el = typesRoot.elements[i4];
|
|
153128
|
+
if (el.name !== "Override")
|
|
153129
|
+
continue;
|
|
153130
|
+
const partName = el.attributes?.PartName;
|
|
153131
|
+
if (!partName || !managedByPartName.has(partName))
|
|
153132
|
+
continue;
|
|
153133
|
+
if (!existingOverrides.has(partName))
|
|
153134
|
+
existingOverrides.set(partName, []);
|
|
153135
|
+
existingOverrides.get(partName).push(i4);
|
|
153136
|
+
}
|
|
153137
|
+
const indicesToRemove = /* @__PURE__ */ new Set;
|
|
153138
|
+
for (const [partName, entry] of managedByPartName) {
|
|
153139
|
+
const isPresent = presentParts.has(entry.zipPath);
|
|
153140
|
+
const indices = existingOverrides.get(partName) || [];
|
|
153141
|
+
if (!isPresent) {
|
|
153142
|
+
for (const idx of indices)
|
|
153143
|
+
indicesToRemove.add(idx);
|
|
153144
|
+
continue;
|
|
153145
|
+
}
|
|
153146
|
+
if (indices.length === 0)
|
|
153147
|
+
typesRoot.elements.push({
|
|
153148
|
+
type: "element",
|
|
153149
|
+
name: "Override",
|
|
153150
|
+
attributes: {
|
|
153151
|
+
PartName: partName,
|
|
153152
|
+
ContentType: entry.contentType
|
|
153153
|
+
}
|
|
153154
|
+
});
|
|
153155
|
+
else {
|
|
153156
|
+
typesRoot.elements[indices[0]].attributes.ContentType = entry.contentType;
|
|
153157
|
+
for (let i4 = 1;i4 < indices.length; i4++)
|
|
153158
|
+
indicesToRemove.add(indices[i4]);
|
|
153159
|
+
}
|
|
153160
|
+
}
|
|
153161
|
+
if (indicesToRemove.size > 0) {
|
|
153162
|
+
const sorted = [...indicesToRemove].sort((a, b) => b - a);
|
|
153163
|
+
for (const idx of sorted)
|
|
153164
|
+
typesRoot.elements.splice(idx, 1);
|
|
153165
|
+
}
|
|
153166
|
+
}
|
|
153167
|
+
function reconcileRootRels(relsRoot, presentParts) {
|
|
153168
|
+
if (!relsRoot.elements)
|
|
153169
|
+
relsRoot.elements = [];
|
|
153170
|
+
const managedByType = /* @__PURE__ */ new Map;
|
|
153171
|
+
for (const entry of MANAGED_PACKAGE_PARTS)
|
|
153172
|
+
managedByType.set(entry.relationshipType, entry);
|
|
153173
|
+
const existingRels = /* @__PURE__ */ new Map;
|
|
153174
|
+
for (let i4 = 0;i4 < relsRoot.elements.length; i4++) {
|
|
153175
|
+
const el = relsRoot.elements[i4];
|
|
153176
|
+
if (el.name !== "Relationship")
|
|
153177
|
+
continue;
|
|
153178
|
+
const type = el.attributes?.Type;
|
|
153179
|
+
if (!type || !managedByType.has(type))
|
|
153180
|
+
continue;
|
|
153181
|
+
if (!existingRels.has(type))
|
|
153182
|
+
existingRels.set(type, []);
|
|
153183
|
+
existingRels.get(type).push({
|
|
153184
|
+
index: i4,
|
|
153185
|
+
element: el
|
|
153186
|
+
});
|
|
153187
|
+
}
|
|
153188
|
+
const indicesToRemove = /* @__PURE__ */ new Set;
|
|
153189
|
+
let maxRId = findMaxRId$1(relsRoot);
|
|
153190
|
+
for (const [relType, entry] of managedByType) {
|
|
153191
|
+
const isPresent = presentParts.has(entry.zipPath);
|
|
153192
|
+
const existing = existingRels.get(relType) || [];
|
|
153193
|
+
if (!isPresent) {
|
|
153194
|
+
for (const { index: index2 } of existing)
|
|
153195
|
+
indicesToRemove.add(index2);
|
|
153196
|
+
continue;
|
|
153197
|
+
}
|
|
153198
|
+
if (existing.length === 0) {
|
|
153199
|
+
maxRId++;
|
|
153200
|
+
relsRoot.elements.push({
|
|
153201
|
+
type: "element",
|
|
153202
|
+
name: "Relationship",
|
|
153203
|
+
attributes: {
|
|
153204
|
+
Id: `rId${maxRId}`,
|
|
153205
|
+
Type: relType,
|
|
153206
|
+
Target: entry.zipPath
|
|
153207
|
+
}
|
|
153208
|
+
});
|
|
153209
|
+
} else {
|
|
153210
|
+
existing[0].element.attributes.Target = entry.zipPath;
|
|
153211
|
+
for (let i4 = 1;i4 < existing.length; i4++)
|
|
153212
|
+
indicesToRemove.add(existing[i4].index);
|
|
153213
|
+
}
|
|
153214
|
+
}
|
|
153215
|
+
if (indicesToRemove.size > 0) {
|
|
153216
|
+
const sorted = [...indicesToRemove].sort((a, b) => b - a);
|
|
153217
|
+
for (const idx of sorted)
|
|
153218
|
+
relsRoot.elements.splice(idx, 1);
|
|
153219
|
+
}
|
|
153220
|
+
}
|
|
153221
|
+
function syncPackageMetadata({ baseFiles, updatedDocs }) {
|
|
153222
|
+
const presentParts = /* @__PURE__ */ new Set;
|
|
153223
|
+
for (const entry of MANAGED_PACKAGE_PARTS)
|
|
153224
|
+
if (partExistsInPackage(entry.zipPath, baseFiles, updatedDocs))
|
|
153225
|
+
presentParts.add(entry.zipPath);
|
|
153226
|
+
const rawContentTypes = readEntry("[Content_Types].xml", baseFiles, updatedDocs);
|
|
153227
|
+
if (rawContentTypes == null)
|
|
153228
|
+
throw new Error("syncPackageMetadata: [Content_Types].xml is missing from the package. Cannot safely reconcile package metadata without an existing content types file.");
|
|
153229
|
+
const contentTypesParsed = parseXml(rawContentTypes);
|
|
153230
|
+
if (!contentTypesParsed)
|
|
153231
|
+
throw new Error("syncPackageMetadata: [Content_Types].xml could not be parsed as valid XML. Cannot safely reconcile package metadata from a malformed content types file.");
|
|
153232
|
+
const typesRoot = findRootElement(contentTypesParsed, "Types");
|
|
153233
|
+
if (!typesRoot)
|
|
153234
|
+
throw new Error("syncPackageMetadata: [Content_Types].xml does not contain a <Types> root element.");
|
|
153235
|
+
reconcileContentTypes(typesRoot, presentParts);
|
|
153236
|
+
const rawRels = readEntry("_rels/.rels", baseFiles, updatedDocs);
|
|
153237
|
+
let relsParsed;
|
|
153238
|
+
if (rawRels == null)
|
|
153239
|
+
relsParsed = createEmptyRels();
|
|
153240
|
+
else {
|
|
153241
|
+
relsParsed = parseXml(rawRels);
|
|
153242
|
+
if (!relsParsed)
|
|
153243
|
+
throw new Error("syncPackageMetadata: _rels/.rels could not be parsed as valid XML. Cannot safely reconcile root relationships from a malformed rels file.");
|
|
153244
|
+
}
|
|
153245
|
+
let relsRoot = findRootElement(relsParsed, "Relationships");
|
|
153246
|
+
if (!relsRoot) {
|
|
153247
|
+
relsParsed = createEmptyRels();
|
|
153248
|
+
relsRoot = relsParsed.elements[0];
|
|
153249
|
+
}
|
|
153250
|
+
reconcileRootRels(relsRoot, presentParts);
|
|
153251
|
+
return {
|
|
153252
|
+
contentTypesXml: serializeXml(contentTypesParsed),
|
|
153253
|
+
relsXml: serializeXml(relsParsed)
|
|
153254
|
+
};
|
|
153255
|
+
}
|
|
153256
|
+
function findMaxRId(elements) {
|
|
153257
|
+
let max4 = 0;
|
|
153258
|
+
for (const el of elements) {
|
|
153259
|
+
const match = el.attributes?.Id?.match(/^rId(\d+)$/);
|
|
153260
|
+
if (match)
|
|
153261
|
+
max4 = Math.max(max4, Number(match[1]));
|
|
153262
|
+
}
|
|
153263
|
+
return max4;
|
|
153264
|
+
}
|
|
153265
|
+
function reconcileDocumentRelationships(relsXml, fileExists) {
|
|
153266
|
+
if (!relsXml)
|
|
153267
|
+
return relsXml;
|
|
153268
|
+
let parsed;
|
|
153269
|
+
try {
|
|
153270
|
+
parsed = import_lib$12.xml2js(relsXml, { compact: false });
|
|
153271
|
+
} catch {
|
|
153272
|
+
return relsXml;
|
|
153273
|
+
}
|
|
153274
|
+
const relsTag = parsed?.elements?.find((el) => el.name === "Relationships");
|
|
153275
|
+
if (!relsTag)
|
|
153276
|
+
return relsXml;
|
|
153277
|
+
if (!relsTag.elements)
|
|
153278
|
+
relsTag.elements = [];
|
|
153279
|
+
let changed = false;
|
|
153280
|
+
let maxId = findMaxRId(relsTag.elements);
|
|
153281
|
+
for (const entry of MANAGED_DOCUMENT_PARTS) {
|
|
153282
|
+
if (!fileExists(entry.zipPath))
|
|
153283
|
+
continue;
|
|
153284
|
+
if (relsTag.elements.some((el) => el.attributes?.Type === entry.relationshipType))
|
|
153285
|
+
continue;
|
|
153286
|
+
maxId++;
|
|
153287
|
+
relsTag.elements.push({
|
|
153288
|
+
type: "element",
|
|
153289
|
+
name: "Relationship",
|
|
153290
|
+
attributes: {
|
|
153291
|
+
Id: `rId${maxId}`,
|
|
153292
|
+
Type: entry.relationshipType,
|
|
153293
|
+
Target: entry.relTarget
|
|
153294
|
+
}
|
|
153295
|
+
});
|
|
153296
|
+
changed = true;
|
|
153297
|
+
}
|
|
153298
|
+
if (!changed)
|
|
153299
|
+
return relsXml;
|
|
153300
|
+
return import_lib$12.js2xml(parsed, { spaces: 0 });
|
|
153301
|
+
}
|
|
153302
|
+
var DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", isXmlLike = (name) => /\.xml$|\.rels$/i.test(name), MANAGED_PACKAGE_PARTS, import_lib$2, RELATIONSHIPS_NS = "http://schemas.openxmlformats.org/package/2006/relationships", import_lib$12, MANAGED_DOCUMENT_PARTS, import_lib3, import_jszip_min, IMAGE_EXTS, MIME_TYPE_FOR_EXT, CUSTOM_XML_ITEM_PROPS_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.customXmlProperties+xml", FONT_CONTENT_TYPES, DocxZipper = class {
|
|
153303
|
+
constructor(params3 = {}) {
|
|
153304
|
+
this.debug = params3.debug || false;
|
|
153305
|
+
this.zip = new import_jszip_min.default;
|
|
153306
|
+
this.files = [];
|
|
153307
|
+
this.media = {};
|
|
153308
|
+
this.mediaFiles = {};
|
|
153309
|
+
this.fonts = {};
|
|
153310
|
+
this.decryptedFileData = null;
|
|
153311
|
+
}
|
|
153312
|
+
async#peekBytes(file, n) {
|
|
153313
|
+
if (file instanceof Uint8Array || typeof Buffer3 !== "undefined" && Buffer3.isBuffer(file))
|
|
153314
|
+
return new Uint8Array(file.buffer, file.byteOffset, Math.min(n, file.byteLength));
|
|
153315
|
+
if (file instanceof ArrayBuffer)
|
|
153316
|
+
return new Uint8Array(file, 0, Math.min(n, file.byteLength));
|
|
153317
|
+
if (typeof Blob !== "undefined" && file instanceof Blob)
|
|
153318
|
+
try {
|
|
153319
|
+
if (typeof file.arrayBuffer === "function") {
|
|
153320
|
+
const buf = await file.arrayBuffer();
|
|
153321
|
+
return new Uint8Array(buf, 0, Math.min(n, buf.byteLength));
|
|
153322
|
+
}
|
|
153323
|
+
} catch {}
|
|
153324
|
+
return new Uint8Array(0);
|
|
153325
|
+
}
|
|
153326
|
+
async getDocxData(file, isNode3 = false, options = {}) {
|
|
153327
|
+
const { detectContainerType: detectContainerType2 } = await Promise.resolve().then(() => (init_detect_container_Mk_wjDRB_es(), exports_detect_container_Mk_wjDRB_es));
|
|
153328
|
+
const containerType = detectContainerType2(await this.#peekBytes(file, 8));
|
|
153329
|
+
let fileData = file;
|
|
153330
|
+
if (containerType === "cfb") {
|
|
153331
|
+
const { decryptDocxIfNeeded: decryptDocxIfNeeded2 } = await Promise.resolve().then(() => (init_decrypt_docx_CNtHeQDp_es(), exports_decrypt_docx_CNtHeQDp_es));
|
|
153332
|
+
const result = await decryptDocxIfNeeded2(file instanceof Uint8Array ? file : file instanceof ArrayBuffer ? new Uint8Array(file) : new Uint8Array(await file.arrayBuffer()), { password: options.password });
|
|
153333
|
+
fileData = result.data;
|
|
153334
|
+
this.decryptedFileData = result.data;
|
|
153335
|
+
}
|
|
153336
|
+
const extractedFiles = await this.unzip(fileData);
|
|
153337
|
+
const files = Object.entries(extractedFiles.files);
|
|
153338
|
+
for (const [, zipEntry] of files) {
|
|
153339
|
+
const name = zipEntry.name;
|
|
153340
|
+
if (isXmlLike(name)) {
|
|
153341
|
+
const content2 = ensureXmlString(await zipEntry.async("uint8array"));
|
|
153342
|
+
this.files.push({
|
|
153343
|
+
name,
|
|
153344
|
+
content: content2
|
|
153345
|
+
});
|
|
153346
|
+
} else if (name.startsWith("word/media") && name !== "word/media/" || zipEntry.name.startsWith("media") && zipEntry.name !== "media/" || name.startsWith("media") && name !== "media/" || name.startsWith("word/embeddings") && name !== "word/embeddings/")
|
|
153347
|
+
if (isNode3) {
|
|
153348
|
+
const fileBase64 = (await zipEntry.async("nodebuffer")).toString("base64");
|
|
153349
|
+
this.mediaFiles[name] = fileBase64;
|
|
153350
|
+
} else {
|
|
153351
|
+
const fileBase64 = await zipEntry.async("base64");
|
|
153352
|
+
let extension2 = this.getFileExtension(name)?.toLowerCase();
|
|
153353
|
+
let detectedType = null;
|
|
153354
|
+
if (!IMAGE_EXTS.has(extension2) || extension2 === "tmp") {
|
|
153355
|
+
detectedType = detectImageType(fileBase64);
|
|
153356
|
+
if (detectedType)
|
|
153357
|
+
extension2 = detectedType;
|
|
153358
|
+
}
|
|
153359
|
+
if (IMAGE_EXTS.has(extension2)) {
|
|
153360
|
+
const mimeSubtype = MIME_TYPE_FOR_EXT[extension2] || extension2;
|
|
153361
|
+
this.mediaFiles[name] = `data:image/${mimeSubtype};base64,${fileBase64}`;
|
|
153362
|
+
const blob = await zipEntry.async("blob");
|
|
153363
|
+
const fileObj = new File([blob], name, { type: blob.type });
|
|
153364
|
+
const imageUrl = URL.createObjectURL(fileObj);
|
|
153365
|
+
this.media[name] = imageUrl;
|
|
153366
|
+
} else
|
|
153367
|
+
this.mediaFiles[name] = fileBase64;
|
|
153368
|
+
}
|
|
153369
|
+
else if (name.startsWith("word/fonts") && name !== "word/fonts/") {
|
|
153370
|
+
const uint8array = await zipEntry.async("uint8array");
|
|
153371
|
+
this.fonts[name] = uint8array;
|
|
153372
|
+
}
|
|
153373
|
+
}
|
|
153374
|
+
return this.files;
|
|
153375
|
+
}
|
|
153376
|
+
getFileExtension(fileName) {
|
|
153377
|
+
const fileSplit = fileName.split(".");
|
|
153378
|
+
if (fileSplit.length < 2)
|
|
153379
|
+
return null;
|
|
153380
|
+
return fileSplit[fileSplit.length - 1];
|
|
153381
|
+
}
|
|
153382
|
+
async updateContentTypes(docx, media, fromJson, updatedDocs = {}, fonts = {}) {
|
|
153383
|
+
const additionalPartNames = Object.keys(updatedDocs || {});
|
|
153384
|
+
const newMediaTypes = Object.keys(media).map((name) => this.getFileExtension(name)).filter((ext) => ext && IMAGE_EXTS.has(ext));
|
|
153385
|
+
const extensionlessMediaOverrides = Object.entries(media).filter(([name]) => !this.getFileExtension(name)).map(([name, value]) => ({
|
|
153386
|
+
name,
|
|
153387
|
+
contentType: this.#detectImageContentType(value)
|
|
153388
|
+
})).filter((entry) => entry.contentType);
|
|
153389
|
+
const contentTypesPath = "[Content_Types].xml";
|
|
153390
|
+
let contentTypesXml;
|
|
153391
|
+
if (fromJson)
|
|
153392
|
+
if (Array.isArray(docx.files))
|
|
153393
|
+
contentTypesXml = docx.files.find((file) => file.name === contentTypesPath)?.content || "";
|
|
153394
|
+
else
|
|
153395
|
+
contentTypesXml = docx.files?.[contentTypesPath] || "";
|
|
153396
|
+
else
|
|
153397
|
+
contentTypesXml = await docx.file(contentTypesPath).async("string");
|
|
153398
|
+
let typesString = "";
|
|
153399
|
+
const defaultMediaTypes = getContentTypesFromXml(contentTypesXml);
|
|
153400
|
+
const seenTypes = /* @__PURE__ */ new Set;
|
|
153401
|
+
for (let type of newMediaTypes) {
|
|
153402
|
+
if (defaultMediaTypes.includes(type))
|
|
153403
|
+
continue;
|
|
153404
|
+
if (seenTypes.has(type))
|
|
153405
|
+
continue;
|
|
153406
|
+
const newContentType = `<Default Extension="${type}" ContentType="image/${MIME_TYPE_FOR_EXT[type] || type}"/>`;
|
|
153407
|
+
typesString += newContentType;
|
|
153408
|
+
seenTypes.add(type);
|
|
153409
|
+
}
|
|
153410
|
+
if (fonts) {
|
|
153411
|
+
const fontExts = new Set(Object.keys(fonts).map((name) => this.getFileExtension(name)).filter((ext) => ext && FONT_CONTENT_TYPES[ext]));
|
|
153412
|
+
for (const ext of fontExts) {
|
|
153413
|
+
if (defaultMediaTypes.includes(ext))
|
|
153414
|
+
continue;
|
|
153415
|
+
if (seenTypes.has(ext))
|
|
153416
|
+
continue;
|
|
153417
|
+
typesString += `<Default Extension="${ext}" ContentType="${FONT_CONTENT_TYPES[ext]}"/>`;
|
|
153418
|
+
seenTypes.add(ext);
|
|
153419
|
+
}
|
|
153420
|
+
}
|
|
153421
|
+
const types3 = JSON.parse(import_lib3.xml2json(contentTypesXml, null, 2)).elements?.find((el) => el.name === "Types") || {};
|
|
153422
|
+
const hasPartOverride = (partName) => types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === partName);
|
|
153423
|
+
for (const { name, contentType } of extensionlessMediaOverrides) {
|
|
153424
|
+
const partName = `/${name}`;
|
|
153425
|
+
if (hasPartOverride(partName))
|
|
153426
|
+
continue;
|
|
153427
|
+
typesString += `<Override PartName="${partName}" ContentType="${contentType}" />`;
|
|
153428
|
+
}
|
|
153429
|
+
const hasComments = types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === "/word/comments.xml");
|
|
153430
|
+
const hasCommentsExtended = types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === "/word/commentsExtended.xml");
|
|
153431
|
+
const hasCommentsIds = types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === "/word/commentsIds.xml");
|
|
153432
|
+
const hasCommentsExtensible = types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === "/word/commentsExtensible.xml");
|
|
153433
|
+
const hasFile = (filename) => {
|
|
153434
|
+
if (updatedDocs && Object.prototype.hasOwnProperty.call(updatedDocs, filename))
|
|
153435
|
+
return updatedDocs[filename] !== null;
|
|
153436
|
+
if (!docx?.files)
|
|
153437
|
+
return false;
|
|
153438
|
+
if (!fromJson)
|
|
153439
|
+
return Boolean(docx.files[filename]);
|
|
153440
|
+
if (Array.isArray(docx.files))
|
|
153441
|
+
return docx.files.some((file) => file.name === filename);
|
|
153442
|
+
return Boolean(docx.files[filename]);
|
|
153443
|
+
};
|
|
153444
|
+
if (hasFile("word/comments.xml")) {
|
|
153445
|
+
const commentsDef = `<Override PartName="/word/comments.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml" />`;
|
|
153446
|
+
if (!hasComments)
|
|
153447
|
+
typesString += commentsDef;
|
|
153448
|
+
}
|
|
153449
|
+
if (hasFile("word/commentsExtended.xml")) {
|
|
153450
|
+
const commentsExtendedDef = `<Override PartName="/word/commentsExtended.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml" />`;
|
|
153451
|
+
if (!hasCommentsExtended)
|
|
153452
|
+
typesString += commentsExtendedDef;
|
|
153453
|
+
}
|
|
153454
|
+
if (hasFile("word/commentsIds.xml")) {
|
|
153455
|
+
const commentsIdsDef = `<Override PartName="/word/commentsIds.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsIds+xml" />`;
|
|
153456
|
+
if (!hasCommentsIds)
|
|
153457
|
+
typesString += commentsIdsDef;
|
|
153458
|
+
}
|
|
153459
|
+
if (hasFile("word/commentsExtensible.xml")) {
|
|
153460
|
+
const commentsExtendedDef = `<Override PartName="/word/commentsExtensible.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml" />`;
|
|
153461
|
+
if (!hasCommentsExtensible)
|
|
153462
|
+
typesString += commentsExtendedDef;
|
|
153463
|
+
}
|
|
153464
|
+
const hasFootnotes = types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === "/word/footnotes.xml");
|
|
153465
|
+
if (hasFile("word/footnotes.xml")) {
|
|
153466
|
+
const footnotesDef = `<Override PartName="/word/footnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml" />`;
|
|
153467
|
+
if (!hasFootnotes)
|
|
153468
|
+
typesString += footnotesDef;
|
|
153469
|
+
}
|
|
153470
|
+
for (const entry of MANAGED_DOCUMENT_PARTS)
|
|
153471
|
+
if (hasFile(entry.zipPath) && !hasPartOverride(`/${entry.zipPath}`))
|
|
153472
|
+
typesString += `<Override PartName="/${entry.zipPath}" ContentType="${entry.contentType}" />`;
|
|
153473
|
+
const partNames = new Set(additionalPartNames);
|
|
153474
|
+
if (docx?.files)
|
|
153475
|
+
if (fromJson && Array.isArray(docx.files))
|
|
153476
|
+
docx.files.forEach((file) => partNames.add(file.name));
|
|
153477
|
+
else
|
|
153478
|
+
Object.keys(docx.files).forEach((key) => partNames.add(key));
|
|
153479
|
+
partNames.forEach((name) => {
|
|
153480
|
+
if (!/^customXml\/itemProps\d+\.xml$/i.test(name))
|
|
153481
|
+
return;
|
|
153482
|
+
if (!hasFile(name))
|
|
153483
|
+
return;
|
|
153484
|
+
const partName = `/${name}`;
|
|
153485
|
+
if (hasPartOverride(partName))
|
|
153486
|
+
return;
|
|
153487
|
+
typesString += `<Override PartName="${partName}" ContentType="${CUSTOM_XML_ITEM_PROPS_CONTENT_TYPE}" />`;
|
|
153488
|
+
});
|
|
153489
|
+
partNames.forEach((name) => {
|
|
153490
|
+
if (name.includes(".rels"))
|
|
153491
|
+
return;
|
|
153492
|
+
if (!name.includes("header") && !name.includes("footer"))
|
|
153493
|
+
return;
|
|
153494
|
+
const hasExtensible = types3.elements?.some((el) => el.name === "Override" && el.attributes.PartName === `/${name}`);
|
|
153495
|
+
const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${name.includes("header") ? "header" : "footer"}+xml"/>`;
|
|
153496
|
+
if (!hasExtensible)
|
|
153497
|
+
typesString += extendedDef;
|
|
153498
|
+
});
|
|
153499
|
+
const staleOverridePartNames = COMMENT_FILE_BASENAMES.map((name) => `/word/${name}`).filter((partName) => {
|
|
153500
|
+
return !hasFile(partName.slice(1));
|
|
153501
|
+
});
|
|
153502
|
+
const beginningString = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
|
|
153503
|
+
let updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
|
|
153504
|
+
for (const partName of staleOverridePartNames) {
|
|
153505
|
+
const escapedPartName = partName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
153506
|
+
const overrideRegex = new RegExp(`\\s*<Override[^>]*PartName="${escapedPartName}"[^>]*/>`, "g");
|
|
153507
|
+
updatedContentTypesXml = updatedContentTypesXml.replace(overrideRegex, "");
|
|
153508
|
+
}
|
|
153509
|
+
let relationshipsXml = updatedDocs["word/_rels/document.xml.rels"];
|
|
153510
|
+
if (!relationshipsXml)
|
|
153511
|
+
if (fromJson)
|
|
153512
|
+
if (Array.isArray(docx.files))
|
|
153513
|
+
relationshipsXml = docx.files.find((file) => file.name === "word/_rels/document.xml.rels")?.content;
|
|
153514
|
+
else
|
|
153515
|
+
relationshipsXml = docx.files?.["word/_rels/document.xml.rels"];
|
|
153516
|
+
else
|
|
153517
|
+
relationshipsXml = await docx.file("word/_rels/document.xml.rels")?.async("string");
|
|
153518
|
+
if (relationshipsXml)
|
|
153519
|
+
try {
|
|
153520
|
+
import_lib3.xml2js(relationshipsXml, { compact: false }).elements?.find((el) => el.name === "Relationships")?.elements?.forEach((rel) => {
|
|
153521
|
+
const type = rel.attributes?.Type;
|
|
153522
|
+
const target = rel.attributes?.Target;
|
|
153523
|
+
if (!type || !target)
|
|
153524
|
+
return;
|
|
153525
|
+
const isHeader = type.includes("/header");
|
|
153526
|
+
const isFooter = type.includes("/footer");
|
|
153527
|
+
if (!isHeader && !isFooter)
|
|
153528
|
+
return;
|
|
153529
|
+
let sanitizedTarget = target.replace(/^\.\//, "");
|
|
153530
|
+
if (sanitizedTarget.startsWith("../"))
|
|
153531
|
+
sanitizedTarget = sanitizedTarget.slice(3);
|
|
153532
|
+
if (sanitizedTarget.startsWith("/"))
|
|
153533
|
+
sanitizedTarget = sanitizedTarget.slice(1);
|
|
153534
|
+
const partName = sanitizedTarget.startsWith("word/") ? sanitizedTarget : `word/${sanitizedTarget}`;
|
|
153535
|
+
partNames.add(partName);
|
|
153536
|
+
});
|
|
153537
|
+
} catch (error3) {
|
|
153538
|
+
console.warn("Failed to parse document relationships while updating content types", error3);
|
|
153539
|
+
}
|
|
153540
|
+
partNames.forEach((name) => {
|
|
153541
|
+
if (name.includes(".rels"))
|
|
153542
|
+
return;
|
|
153543
|
+
if (!name.includes("header") && !name.includes("footer"))
|
|
153544
|
+
return;
|
|
153545
|
+
if (updatedContentTypesXml.includes(`PartName="/${name}"`))
|
|
153546
|
+
return;
|
|
153547
|
+
const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${name.includes("header") ? "header" : "footer"}+xml"/>`;
|
|
153548
|
+
updatedContentTypesXml = updatedContentTypesXml.replace("</Types>", `${extendedDef}</Types>`);
|
|
153549
|
+
});
|
|
153550
|
+
if (relationshipsXml) {
|
|
153551
|
+
const reconciledRels = reconcileDocumentRelationships(relationshipsXml, hasFile);
|
|
153552
|
+
if (reconciledRels !== relationshipsXml)
|
|
153553
|
+
if (fromJson)
|
|
153554
|
+
updatedDocs["word/_rels/document.xml.rels"] = reconciledRels;
|
|
153555
|
+
else
|
|
153556
|
+
docx.file("word/_rels/document.xml.rels", reconciledRels);
|
|
153557
|
+
}
|
|
153558
|
+
if (fromJson)
|
|
153559
|
+
return updatedContentTypesXml;
|
|
153560
|
+
docx.file(contentTypesPath, updatedContentTypesXml);
|
|
153561
|
+
}
|
|
153562
|
+
async#syncPackageMetadataInZip(zip) {
|
|
153563
|
+
const baseForSync = {};
|
|
153564
|
+
zip.forEach((path2) => {
|
|
153565
|
+
baseForSync[path2] = "";
|
|
153566
|
+
});
|
|
153567
|
+
const ctEntry = zip.file("[Content_Types].xml");
|
|
153568
|
+
if (ctEntry)
|
|
153569
|
+
baseForSync["[Content_Types].xml"] = await ctEntry.async("string");
|
|
153570
|
+
const rlEntry = zip.file("_rels/.rels");
|
|
153571
|
+
if (rlEntry)
|
|
153572
|
+
baseForSync["_rels/.rels"] = await rlEntry.async("string");
|
|
153573
|
+
const { contentTypesXml, relsXml } = syncPackageMetadata({
|
|
153574
|
+
baseFiles: baseForSync,
|
|
153575
|
+
updatedDocs: {}
|
|
153576
|
+
});
|
|
153577
|
+
zip.file("[Content_Types].xml", contentTypesXml);
|
|
153578
|
+
zip.file("_rels/.rels", relsXml);
|
|
153579
|
+
}
|
|
153580
|
+
async unzip(file) {
|
|
153581
|
+
return await this.zip.loadAsync(file);
|
|
153582
|
+
}
|
|
153583
|
+
async updateZip({ docx, updatedDocs, originalDocxFile, media, fonts, isHeadless, compression = "DEFLATE" }) {
|
|
153584
|
+
let zip;
|
|
153585
|
+
if (originalDocxFile)
|
|
153586
|
+
zip = await this.exportFromOriginalFile(originalDocxFile, updatedDocs, media, fonts);
|
|
153587
|
+
else
|
|
153588
|
+
zip = await this.exportFromCollaborativeDocx(docx, updatedDocs, media, fonts);
|
|
153589
|
+
const exportType = isHeadless ? "nodebuffer" : "blob";
|
|
153590
|
+
return await zip.generateAsync({
|
|
153591
|
+
type: exportType,
|
|
153592
|
+
mimeType: DOCX,
|
|
153593
|
+
compression,
|
|
153594
|
+
compressionOptions: compression === "DEFLATE" ? { level: 6 } : undefined
|
|
153595
|
+
});
|
|
153596
|
+
}
|
|
153597
|
+
async exportFromCollaborativeDocx(docx, updatedDocs, media, fonts) {
|
|
153598
|
+
if (!Array.isArray(docx))
|
|
153599
|
+
throw new Error("Collaborative DOCX export requires base package entries");
|
|
153600
|
+
const zip = new import_jszip_min.default;
|
|
153601
|
+
for (const file of docx) {
|
|
153602
|
+
const content2 = file.content;
|
|
153603
|
+
zip.file(file.name, content2);
|
|
153604
|
+
}
|
|
153605
|
+
Object.keys(updatedDocs).forEach((key) => {
|
|
153606
|
+
if (updatedDocs[key] === null)
|
|
153607
|
+
zip.remove(key);
|
|
153608
|
+
else
|
|
153609
|
+
zip.file(key, updatedDocs[key]);
|
|
153610
|
+
});
|
|
153611
|
+
Object.keys(media).forEach((path2) => {
|
|
153612
|
+
const value = media[path2];
|
|
153613
|
+
const binaryData = typeof value === "string" ? base64ToUint8Array(value) : value;
|
|
153614
|
+
zip.file(path2, binaryData);
|
|
153615
|
+
});
|
|
153616
|
+
for (const [fontName, fontUintArray] of Object.entries(fonts))
|
|
153617
|
+
zip.file(fontName, fontUintArray);
|
|
153618
|
+
await this.updateContentTypes(zip, media, false, updatedDocs, fonts);
|
|
153619
|
+
await this.#syncPackageMetadataInZip(zip);
|
|
153620
|
+
return zip;
|
|
153621
|
+
}
|
|
153622
|
+
async exportFromOriginalFile(originalDocxFile, updatedDocs, media, fonts) {
|
|
153623
|
+
const unzippedOriginalDocx = await this.unzip(originalDocxFile);
|
|
153624
|
+
const filePromises = [];
|
|
153625
|
+
unzippedOriginalDocx.forEach((relativePath, zipEntry) => {
|
|
153626
|
+
const promise = zipEntry.async("uint8array").then((u8) => {
|
|
153627
|
+
unzippedOriginalDocx.file(zipEntry.name, isXmlLike(zipEntry.name) ? ensureXmlString(u8) : u8);
|
|
153628
|
+
});
|
|
153629
|
+
filePromises.push(promise);
|
|
153630
|
+
});
|
|
153631
|
+
await Promise.all(filePromises);
|
|
153632
|
+
Object.keys(updatedDocs).forEach((key) => {
|
|
153633
|
+
if (updatedDocs[key] === null)
|
|
153634
|
+
unzippedOriginalDocx.remove(key);
|
|
153635
|
+
else
|
|
153636
|
+
unzippedOriginalDocx.file(key, updatedDocs[key]);
|
|
153637
|
+
});
|
|
153638
|
+
Object.keys(media).forEach((path2) => {
|
|
153639
|
+
unzippedOriginalDocx.file(path2, media[path2]);
|
|
153640
|
+
});
|
|
153641
|
+
if (fonts)
|
|
153642
|
+
for (const [fontName, fontUintArray] of Object.entries(fonts))
|
|
153643
|
+
unzippedOriginalDocx.file(fontName, fontUintArray);
|
|
153644
|
+
await this.updateContentTypes(unzippedOriginalDocx, media, false, updatedDocs, fonts);
|
|
153645
|
+
await this.#syncPackageMetadataInZip(unzippedOriginalDocx);
|
|
153646
|
+
return unzippedOriginalDocx;
|
|
153647
|
+
}
|
|
153648
|
+
#detectImageContentType(value) {
|
|
153649
|
+
if (value == null)
|
|
153650
|
+
return null;
|
|
153651
|
+
if (typeof value === "string" && value.startsWith("data:image/"))
|
|
153652
|
+
return value.match(/^data:(image\/[a-zA-Z0-9.+-]+);/i)?.[1]?.toLowerCase() || null;
|
|
153653
|
+
let detectedType = null;
|
|
153654
|
+
if (value instanceof ArrayBuffer)
|
|
153655
|
+
detectedType = detectImageType(new Uint8Array(value));
|
|
153656
|
+
else if (ArrayBuffer.isView(value))
|
|
153657
|
+
detectedType = detectImageType(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
153658
|
+
else if (typeof value === "string")
|
|
153659
|
+
detectedType = detectImageType(value.startsWith("data:") ? value.split(",", 2)[1] : value);
|
|
153660
|
+
if (!detectedType)
|
|
153661
|
+
return null;
|
|
153662
|
+
return `image/${MIME_TYPE_FOR_EXT[detectedType] || detectedType}`;
|
|
153663
|
+
}
|
|
153664
|
+
}, DocxZipper_default;
|
|
153665
|
+
var init_DocxZipper_DvDGw347_es = __esm(() => {
|
|
153666
|
+
init_rolldown_runtime_B2q5OVn9_es();
|
|
153667
|
+
init_jszip_ChlR43oI_es();
|
|
153668
|
+
init_xml_js_40FWvL78_es();
|
|
153669
|
+
init_constants_Qqwopz80_es();
|
|
153670
|
+
init_dist_Cwvmda4Q_es();
|
|
152927
153671
|
MANAGED_PACKAGE_PARTS = [
|
|
152928
153672
|
{
|
|
152929
153673
|
zipPath: "word/document.xml",
|
|
@@ -152981,7 +153725,7 @@ var init_DocxZipper_gWkmvJfR_es = __esm(() => {
|
|
|
152981
153725
|
DocxZipper_default = DocxZipper;
|
|
152982
153726
|
});
|
|
152983
153727
|
|
|
152984
|
-
// ../../packages/superdoc/dist/chunks/vue-
|
|
153728
|
+
// ../../packages/superdoc/dist/chunks/vue-DMgTaOx9.es.js
|
|
152985
153729
|
function makeMap(str) {
|
|
152986
153730
|
const map$12 = /* @__PURE__ */ Object.create(null);
|
|
152987
153731
|
for (const key of str.split(","))
|
|
@@ -159032,7 +159776,7 @@ var EMPTY_OBJ, EMPTY_ARR, NOOP = () => {}, NO = () => false, isOn = (key) => key
|
|
|
159032
159776
|
};
|
|
159033
159777
|
return app;
|
|
159034
159778
|
};
|
|
159035
|
-
var
|
|
159779
|
+
var init_vue_DMgTaOx9_es = __esm(() => {
|
|
159036
159780
|
init_jszip_ChlR43oI_es();
|
|
159037
159781
|
init_dist$1();
|
|
159038
159782
|
init_dist4();
|
|
@@ -159887,18 +160631,18 @@ var init_vue_LcaAh_pz_es = __esm(() => {
|
|
|
159887
160631
|
initDev();
|
|
159888
160632
|
});
|
|
159889
160633
|
|
|
159890
|
-
// ../../packages/superdoc/dist/chunks/_plugin-vue_export-helper-
|
|
160634
|
+
// ../../packages/superdoc/dist/chunks/_plugin-vue_export-helper-HmhZBO0u.es.js
|
|
159891
160635
|
var __plugin_vue_export_helper_default = (sfc, props) => {
|
|
159892
160636
|
const target = sfc.__vccOpts || sfc;
|
|
159893
160637
|
for (const [key, val] of props)
|
|
159894
160638
|
target[key] = val;
|
|
159895
160639
|
return target;
|
|
159896
160640
|
};
|
|
159897
|
-
var
|
|
160641
|
+
var init__plugin_vue_export_helper_HmhZBO0u_es = () => {};
|
|
159898
160642
|
|
|
159899
|
-
// ../../packages/superdoc/dist/chunks/eventemitter3-
|
|
160643
|
+
// ../../packages/superdoc/dist/chunks/eventemitter3-DGBTyUUP.es.js
|
|
159900
160644
|
var import_eventemitter3, eventemitter3_default;
|
|
159901
|
-
var
|
|
160645
|
+
var init_eventemitter3_DGBTyUUP_es = __esm(() => {
|
|
159902
160646
|
init_rolldown_runtime_B2q5OVn9_es();
|
|
159903
160647
|
import_eventemitter3 = /* @__PURE__ */ __toESM2((/* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
159904
160648
|
var has = Object.prototype.hasOwnProperty, prefix = "~";
|
|
@@ -160068,8 +160812,8 @@ var init_eventemitter3_C8I7im8Y_es = __esm(() => {
|
|
|
160068
160812
|
eventemitter3_default = import_eventemitter3.default;
|
|
160069
160813
|
});
|
|
160070
160814
|
|
|
160071
|
-
// ../../packages/superdoc/dist/chunks/blank-docx-
|
|
160072
|
-
var
|
|
160815
|
+
// ../../packages/superdoc/dist/chunks/blank-docx-sI869qur.es.js
|
|
160816
|
+
var init_blank_docx_sI869qur_es = () => {};
|
|
160073
160817
|
|
|
160074
160818
|
// ../../packages/superdoc/dist/chunks/unified-Df6iltvW.es.js
|
|
160075
160819
|
var exports_unified_Df6iltvW_es = {};
|
|
@@ -160080,9 +160824,9 @@ var init_unified_Df6iltvW_es = __esm(() => {
|
|
|
160080
160824
|
init_unified_BRHLwnjP_es();
|
|
160081
160825
|
});
|
|
160082
160826
|
|
|
160083
|
-
// ../../packages/superdoc/dist/chunks/rehype-parse-
|
|
160084
|
-
var
|
|
160085
|
-
__export(
|
|
160827
|
+
// ../../packages/superdoc/dist/chunks/rehype-parse-BLZiqvrL.es.js
|
|
160828
|
+
var exports_rehype_parse_BLZiqvrL_es = {};
|
|
160829
|
+
__export(exports_rehype_parse_BLZiqvrL_es, {
|
|
160086
160830
|
default: () => rehypeParse
|
|
160087
160831
|
});
|
|
160088
160832
|
function merge2(definitions, space) {
|
|
@@ -166031,7 +166775,7 @@ var Schema2 = class {
|
|
|
166031
166775
|
}
|
|
166032
166776
|
}
|
|
166033
166777
|
}, TABLE_VOID_ELEMENTS, errors, base3 = "https://html.spec.whatwg.org/multipage/parsing.html#parse-error-", dashToCamelRe, formatCRe, formatXRe, fatalities, emptyOptions3;
|
|
166034
|
-
var
|
|
166778
|
+
var init_rehype_parse_BLZiqvrL_es = __esm(() => {
|
|
166035
166779
|
init_rolldown_runtime_B2q5OVn9_es();
|
|
166036
166780
|
init_default_Cj_AMFZ9_es();
|
|
166037
166781
|
init_lib_HnbxUP96_es();
|
|
@@ -168776,9 +169520,9 @@ var init_rehype_parse_DBGL9UkS_es = __esm(() => {
|
|
|
168776
169520
|
emptyOptions3 = {};
|
|
168777
169521
|
});
|
|
168778
169522
|
|
|
168779
|
-
// ../../packages/superdoc/dist/chunks/rehype-remark-
|
|
168780
|
-
var
|
|
168781
|
-
__export(
|
|
169523
|
+
// ../../packages/superdoc/dist/chunks/rehype-remark-pZi116RJ.es.js
|
|
169524
|
+
var exports_rehype_remark_pZi116RJ_es = {};
|
|
169525
|
+
__export(exports_rehype_remark_pZi116RJ_es, {
|
|
168782
169526
|
default: () => rehypeRemark
|
|
168783
169527
|
});
|
|
168784
169528
|
function anyFactory2(tests) {
|
|
@@ -170398,7 +171142,7 @@ var env, deserializer = ($2, _) => {
|
|
|
170398
171142
|
if (is(parent.children[index2], index2, parent))
|
|
170399
171143
|
return parent.children[index2];
|
|
170400
171144
|
}, searchLineFeeds, searchTabOrSpaces, br$1, cell, p$1, row, notRendered, blockOrCaption, prefix = "language-", defaultChecked = "[x]", defaultUnchecked = "[ ]", own$12, list$1, basic, meta, defaultQuotes, nodeHandlers, handlers2, own6, emptyOptions4, defaults;
|
|
170401
|
-
var
|
|
171145
|
+
var init_rehype_remark_pZi116RJ_es = __esm(() => {
|
|
170402
171146
|
init_lib_DAB30bX1_es();
|
|
170403
171147
|
env = typeof self === "object" ? self : globalThis;
|
|
170404
171148
|
({ toString: toString$1 } = {});
|
|
@@ -170774,12 +171518,12 @@ var init_rehype_remark_CBHTrfcB_es = __esm(() => {
|
|
|
170774
171518
|
defaults = { document: true };
|
|
170775
171519
|
});
|
|
170776
171520
|
|
|
170777
|
-
// ../../packages/superdoc/dist/chunks/remark-stringify-
|
|
170778
|
-
var
|
|
170779
|
-
__export(
|
|
171521
|
+
// ../../packages/superdoc/dist/chunks/remark-stringify-WeOdhmLF.es.js
|
|
171522
|
+
var exports_remark_stringify_WeOdhmLF_es = {};
|
|
171523
|
+
__export(exports_remark_stringify_WeOdhmLF_es, {
|
|
170780
171524
|
default: () => remarkStringify
|
|
170781
171525
|
});
|
|
170782
|
-
var
|
|
171526
|
+
var init_remark_stringify_WeOdhmLF_es = __esm(() => {
|
|
170783
171527
|
init_remark_stringify_D8vxv_XI_es();
|
|
170784
171528
|
});
|
|
170785
171529
|
|
|
@@ -170792,7 +171536,7 @@ var init_remark_gfm_CjV8kaUy_es = __esm(() => {
|
|
|
170792
171536
|
init_remark_gfm_z_sDF4ss_es();
|
|
170793
171537
|
});
|
|
170794
171538
|
|
|
170795
|
-
// ../../packages/superdoc/dist/chunks/src-
|
|
171539
|
+
// ../../packages/superdoc/dist/chunks/src-DWC5tAy5.es.js
|
|
170796
171540
|
function deleteProps(obj, propOrProps) {
|
|
170797
171541
|
const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
|
|
170798
171542
|
const removeNested = (target, pathParts, index2 = 0) => {
|
|
@@ -177121,7 +177865,7 @@ function getOppositePlacement(placement2) {
|
|
|
177121
177865
|
}
|
|
177122
177866
|
function getOppositeVariationPlacement(placement2) {
|
|
177123
177867
|
return placement2.replace(/start|end/g, function(matched) {
|
|
177124
|
-
return
|
|
177868
|
+
return hash2[matched];
|
|
177125
177869
|
});
|
|
177126
177870
|
}
|
|
177127
177871
|
function getWindowScroll(node3) {
|
|
@@ -234324,7 +235068,7 @@ var Node$13 = class Node$14 {
|
|
|
234324
235068
|
}, TextTransform, Placeholder, bottom = "bottom", right = "right", left = "left", auto = "auto", basePlacements, start = "start", clippingParents = "clippingParents", viewport = "viewport", popper = "popper", reference = "reference", variationPlacements, placements, modifierPhases, applyStyles_default, max4, min4, round, toPaddingObject = function toPaddingObject$1(padding, state) {
|
|
234325
235069
|
padding = typeof padding === "function" ? padding(Object.assign({}, state.rects, { placement: state.placement })) : padding;
|
|
234326
235070
|
return mergePaddingObject(typeof padding !== "number" ? padding : expandToHashMap(padding, basePlacements));
|
|
234327
|
-
}, arrow_default, unsetSides, computeStyles_default, passive, eventListeners_default, hash$1,
|
|
235071
|
+
}, arrow_default, unsetSides, computeStyles_default, passive, eventListeners_default, hash$1, hash2, flip_default, hide_default, offset_default, popperOffsets_default, preventOverflow_default, DEFAULT_OPTIONS, createPopper, BOX_CLASS = "tippy-box", CONTENT_CLASS = "tippy-content", BACKDROP_CLASS = "tippy-backdrop", ARROW_CLASS = "tippy-arrow", SVG_ARROW_CLASS = "tippy-svg-arrow", TOUCH_OPTIONS, TIPPY_DEFAULT_APPEND_TO = function TIPPY_DEFAULT_APPEND_TO$1() {
|
|
234328
235072
|
return document.body;
|
|
234329
235073
|
}, currentInput, lastMouseMoveTime = 0, isIE11, visitedMessages, pluginProps, defaultProps, defaultKeys, setDefaultProps = function setDefaultProps$1(partialProps) {
|
|
234330
235074
|
if (process$1.env.NODE_ENV !== "production")
|
|
@@ -240549,7 +241293,7 @@ var Node$13 = class Node$14 {
|
|
|
240549
241293
|
});
|
|
240550
241294
|
return Object.fromEntries(markEntries);
|
|
240551
241295
|
}
|
|
240552
|
-
},
|
|
241296
|
+
}, Commands, handleEnter = (editor) => {
|
|
240553
241297
|
const { view } = editor;
|
|
240554
241298
|
view?.dispatch?.(closeHistory(view?.state?.tr));
|
|
240555
241299
|
return editor.commands.first(({ commands: commands$1 }) => [
|
|
@@ -250552,20 +251296,22 @@ var Node$13 = class Node$14 {
|
|
|
250552
251296
|
return;
|
|
250553
251297
|
console.log(...args$1);
|
|
250554
251298
|
}, HEADER_FOOTER_INIT_BUDGET_MS = 200, MAX_ZOOM_WARNING_THRESHOLD = 10, MAX_SELECTION_RECTS_PER_USER = 100, SEMANTIC_RESIZE_DEBOUNCE_MS = 120, MIN_SEMANTIC_CONTENT_WIDTH_PX = 1, GLOBAL_PERFORMANCE, PresentationEditor, ICONS, TEXTS, tableActionsOptions;
|
|
250555
|
-
var
|
|
251299
|
+
var init_src_DWC5tAy5_es = __esm(() => {
|
|
250556
251300
|
init_rolldown_runtime_B2q5OVn9_es();
|
|
250557
|
-
|
|
251301
|
+
init_SuperConverter_CXcZg9Os_es();
|
|
250558
251302
|
init_jszip_ChlR43oI_es();
|
|
250559
251303
|
init_uuid_qzgm05fK_es();
|
|
250560
251304
|
init_constants_Qqwopz80_es();
|
|
250561
251305
|
init_unified_BRHLwnjP_es();
|
|
250562
251306
|
init_remark_gfm_z_sDF4ss_es();
|
|
250563
251307
|
init_remark_stringify_D8vxv_XI_es();
|
|
250564
|
-
|
|
250565
|
-
|
|
250566
|
-
|
|
250567
|
-
|
|
250568
|
-
|
|
251308
|
+
init_DocxZipper_DvDGw347_es();
|
|
251309
|
+
init_dist_Cwvmda4Q_es();
|
|
251310
|
+
init_vue_DMgTaOx9_es();
|
|
251311
|
+
init__plugin_vue_export_helper_HmhZBO0u_es();
|
|
251312
|
+
init_eventemitter3_DGBTyUUP_es();
|
|
251313
|
+
init_errors_CtyzHiH4_es();
|
|
251314
|
+
init_blank_docx_sI869qur_es();
|
|
250569
251315
|
init_yjs();
|
|
250570
251316
|
init_yjs();
|
|
250571
251317
|
CSS_DIMENSION_REGEX = /[\d-.]+(\w+)$/;
|
|
@@ -264722,7 +265468,7 @@ ${err.toString()}`);
|
|
|
264722
265468
|
}
|
|
264723
265469
|
return result$1;
|
|
264724
265470
|
}
|
|
264725
|
-
function
|
|
265471
|
+
function concat2() {
|
|
264726
265472
|
var length$12 = arguments.length;
|
|
264727
265473
|
if (!length$12)
|
|
264728
265474
|
return [];
|
|
@@ -266443,7 +267189,7 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
266443
267189
|
lodash.chain = chain;
|
|
266444
267190
|
lodash.chunk = chunk2;
|
|
266445
267191
|
lodash.compact = compact2;
|
|
266446
|
-
lodash.concat =
|
|
267192
|
+
lodash.concat = concat2;
|
|
266447
267193
|
lodash.cond = cond;
|
|
266448
267194
|
lodash.conforms = conforms;
|
|
266449
267195
|
lodash.constant = constant;
|
|
@@ -267521,7 +268267,7 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
267521
268267
|
bottom: "top",
|
|
267522
268268
|
top: "bottom"
|
|
267523
268269
|
};
|
|
267524
|
-
|
|
268270
|
+
hash2 = {
|
|
267525
268271
|
start: "end",
|
|
267526
268272
|
end: "start"
|
|
267527
268273
|
};
|
|
@@ -275600,37 +276346,6 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
275600
276346
|
}
|
|
275601
276347
|
}
|
|
275602
276348
|
};
|
|
275603
|
-
EditorError = class extends Error {
|
|
275604
|
-
constructor(message) {
|
|
275605
|
-
super(message);
|
|
275606
|
-
this.name = "EditorError";
|
|
275607
|
-
}
|
|
275608
|
-
};
|
|
275609
|
-
InvalidStateError = class extends EditorError {
|
|
275610
|
-
constructor(message) {
|
|
275611
|
-
super(message);
|
|
275612
|
-
this.name = "InvalidStateError";
|
|
275613
|
-
}
|
|
275614
|
-
};
|
|
275615
|
-
NoSourcePathError = class extends EditorError {
|
|
275616
|
-
constructor(message) {
|
|
275617
|
-
super(message);
|
|
275618
|
-
this.name = "NoSourcePathError";
|
|
275619
|
-
}
|
|
275620
|
-
};
|
|
275621
|
-
FileSystemNotAvailableError = class extends EditorError {
|
|
275622
|
-
constructor(message) {
|
|
275623
|
-
super(message);
|
|
275624
|
-
this.name = "FileSystemNotAvailableError";
|
|
275625
|
-
}
|
|
275626
|
-
};
|
|
275627
|
-
DocumentLoadError = class extends EditorError {
|
|
275628
|
-
constructor(message, cause) {
|
|
275629
|
-
super(message);
|
|
275630
|
-
this.name = "DocumentLoadError";
|
|
275631
|
-
this.cause = cause;
|
|
275632
|
-
}
|
|
275633
|
-
};
|
|
275634
276349
|
Commands = Extension.create({
|
|
275635
276350
|
name: "commands",
|
|
275636
276351
|
addCommands() {
|
|
@@ -277502,16 +278217,17 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
277502
278217
|
markdown: options?.markdown,
|
|
277503
278218
|
jsonOverride: options?.json ?? null
|
|
277504
278219
|
};
|
|
278220
|
+
const loadOptions = options?.password ? { password: options.password } : undefined;
|
|
277505
278221
|
if (typeof source === "string")
|
|
277506
278222
|
if (typeof process$12 !== "undefined" && process$12.versions?.node) {
|
|
277507
278223
|
const buffer4 = (init_empty(), __toCommonJS(empty_exports)).readFileSync(source);
|
|
277508
|
-
const [docx, _media, mediaFiles, fonts] = await Editor2.loadXmlData(buffer4, true);
|
|
278224
|
+
const [docx, _media, mediaFiles, fonts, decryptedData] = await Editor2.loadXmlData(buffer4, true, loadOptions);
|
|
277509
278225
|
resolvedOptions.content = docx;
|
|
277510
278226
|
resolvedOptions.mediaFiles = mediaFiles;
|
|
277511
278227
|
resolvedOptions.fonts = fonts;
|
|
277512
|
-
resolvedOptions.fileSource = buffer4;
|
|
278228
|
+
resolvedOptions.fileSource = decryptedData ?? buffer4;
|
|
277513
278229
|
resolvedOptions.isNewFile = explicitIsNewFile ?? false;
|
|
277514
|
-
this.#sourcePath = source;
|
|
278230
|
+
this.#sourcePath = decryptedData ? null : source;
|
|
277515
278231
|
} else {
|
|
277516
278232
|
const response = await fetch(source);
|
|
277517
278233
|
if (!response.ok) {
|
|
@@ -277519,11 +278235,11 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
277519
278235
|
throw new Error(`Fetch failed: ${response.status} ${response.statusText}`);
|
|
277520
278236
|
}
|
|
277521
278237
|
const blob = await response.blob();
|
|
277522
|
-
const [docx, _media, mediaFiles, fonts] = await Editor2.loadXmlData(blob);
|
|
278238
|
+
const [docx, _media, mediaFiles, fonts, decryptedData] = await Editor2.loadXmlData(blob, false, loadOptions);
|
|
277523
278239
|
resolvedOptions.content = docx;
|
|
277524
278240
|
resolvedOptions.mediaFiles = mediaFiles;
|
|
277525
278241
|
resolvedOptions.fonts = fonts;
|
|
277526
|
-
resolvedOptions.fileSource = blob;
|
|
278242
|
+
resolvedOptions.fileSource = decryptedData ?? blob;
|
|
277527
278243
|
resolvedOptions.isNewFile = explicitIsNewFile ?? false;
|
|
277528
278244
|
this.#sourcePath = source.split("/").pop() || null;
|
|
277529
278245
|
}
|
|
@@ -277533,19 +278249,19 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
277533
278249
|
const isArrayBuffer = source instanceof ArrayBuffer;
|
|
277534
278250
|
const hasArrayBuffer = typeof source === "object" && "buffer" in source && source.buffer instanceof ArrayBuffer;
|
|
277535
278251
|
if (isNodeBuffer || isBlob || isArrayBuffer || hasArrayBuffer) {
|
|
277536
|
-
const [docx, _media, mediaFiles, fonts] = await Editor2.loadXmlData(source, isNodeBuffer);
|
|
278252
|
+
const [docx, _media, mediaFiles, fonts, decryptedData] = await Editor2.loadXmlData(source, isNodeBuffer, loadOptions);
|
|
277537
278253
|
resolvedOptions.content = docx;
|
|
277538
278254
|
resolvedOptions.mediaFiles = mediaFiles;
|
|
277539
278255
|
resolvedOptions.fonts = fonts;
|
|
277540
|
-
resolvedOptions.fileSource = source;
|
|
278256
|
+
resolvedOptions.fileSource = decryptedData ?? source;
|
|
277541
278257
|
resolvedOptions.isNewFile = explicitIsNewFile ?? false;
|
|
277542
278258
|
this.#sourcePath = null;
|
|
277543
278259
|
} else {
|
|
277544
|
-
const [docx, _media, mediaFiles, fonts] = await Editor2.loadXmlData(source, false);
|
|
278260
|
+
const [docx, _media, mediaFiles, fonts, decryptedData] = await Editor2.loadXmlData(source, false, loadOptions);
|
|
277545
278261
|
resolvedOptions.content = docx;
|
|
277546
278262
|
resolvedOptions.mediaFiles = mediaFiles;
|
|
277547
278263
|
resolvedOptions.fonts = fonts;
|
|
277548
|
-
resolvedOptions.fileSource = source;
|
|
278264
|
+
resolvedOptions.fileSource = decryptedData ?? source;
|
|
277549
278265
|
resolvedOptions.isNewFile = explicitIsNewFile ?? false;
|
|
277550
278266
|
this.#sourcePath = null;
|
|
277551
278267
|
}
|
|
@@ -277606,6 +278322,10 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
277606
278322
|
this.#registerCopyHandler();
|
|
277607
278323
|
}
|
|
277608
278324
|
} catch (error3) {
|
|
278325
|
+
if (error3 instanceof DocxEncryptionError) {
|
|
278326
|
+
console.debug("[SuperDoc] Document load error:", error3.message);
|
|
278327
|
+
throw error3;
|
|
278328
|
+
}
|
|
277609
278329
|
const err = error3 instanceof Error ? error3 : new Error(String(error3));
|
|
277610
278330
|
console.debug("[SuperDoc] Document load error:", err.message);
|
|
277611
278331
|
throw new DocumentLoadError(`Failed to load document: ${err.message}`, err);
|
|
@@ -278150,15 +278870,16 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
278150
278870
|
return !canRender && !isFontImported;
|
|
278151
278871
|
});
|
|
278152
278872
|
}
|
|
278153
|
-
static async loadXmlData(fileSource, isNode$1 = false) {
|
|
278873
|
+
static async loadXmlData(fileSource, isNode$1 = false, options) {
|
|
278154
278874
|
if (!fileSource)
|
|
278155
278875
|
return;
|
|
278156
278876
|
const zipper = new DocxZipper_default;
|
|
278157
278877
|
return [
|
|
278158
|
-
await zipper.getDocxData(fileSource, isNode$1),
|
|
278878
|
+
await zipper.getDocxData(fileSource, isNode$1, { password: options?.password }),
|
|
278159
278879
|
zipper.media,
|
|
278160
278880
|
zipper.mediaFiles,
|
|
278161
|
-
zipper.fonts
|
|
278881
|
+
zipper.fonts,
|
|
278882
|
+
zipper.decryptedFileData
|
|
278162
278883
|
];
|
|
278163
278884
|
}
|
|
278164
278885
|
static getDocumentVersion(doc$12) {
|
|
@@ -278546,9 +279267,9 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
278546
279267
|
try {
|
|
278547
279268
|
const [{ unified: unified$1 }, { default: rehypeParse2 }, { default: rehypeRemark2 }, { default: remarkStringify$1 }, { default: remarkGfm$1 }] = await Promise.all([
|
|
278548
279269
|
Promise.resolve().then(() => (init_unified_Df6iltvW_es(), exports_unified_Df6iltvW_es)),
|
|
278549
|
-
Promise.resolve().then(() => (
|
|
278550
|
-
Promise.resolve().then(() => (
|
|
278551
|
-
Promise.resolve().then(() => (
|
|
279270
|
+
Promise.resolve().then(() => (init_rehype_parse_BLZiqvrL_es(), exports_rehype_parse_BLZiqvrL_es)),
|
|
279271
|
+
Promise.resolve().then(() => (init_rehype_remark_pZi116RJ_es(), exports_rehype_remark_pZi116RJ_es)),
|
|
279272
|
+
Promise.resolve().then(() => (init_remark_stringify_WeOdhmLF_es(), exports_remark_stringify_WeOdhmLF_es)),
|
|
278552
279273
|
Promise.resolve().then(() => (init_remark_gfm_CjV8kaUy_es(), exports_remark_gfm_CjV8kaUy_es))
|
|
278553
279274
|
]);
|
|
278554
279275
|
const html3 = this.getHTML();
|
|
@@ -278762,7 +279483,7 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
278762
279483
|
isHeadless: !(config2?.element != null || config2?.selector != null),
|
|
278763
279484
|
...config2
|
|
278764
279485
|
};
|
|
278765
|
-
const { html: html3, markdown, json, isCommentsEnabled, suppressDefaultDocxStyles, documentMode, content: content3, mediaFiles, fonts, isNewFile, ...editorConfig } = resolvedConfig;
|
|
279486
|
+
const { html: html3, markdown, json, isCommentsEnabled, suppressDefaultDocxStyles, documentMode, content: content3, mediaFiles, fonts, isNewFile, password, ...editorConfig } = resolvedConfig;
|
|
278766
279487
|
const openOptions = {
|
|
278767
279488
|
mode: resolvedConfig.mode,
|
|
278768
279489
|
html: html3,
|
|
@@ -278774,7 +279495,8 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
278774
279495
|
content: content3,
|
|
278775
279496
|
mediaFiles,
|
|
278776
279497
|
fonts,
|
|
278777
|
-
isNewFile
|
|
279498
|
+
isNewFile,
|
|
279499
|
+
password
|
|
278778
279500
|
};
|
|
278779
279501
|
const editor = new Editor2({
|
|
278780
279502
|
...editorConfig,
|
|
@@ -278914,11 +279636,11 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
278914
279636
|
return;
|
|
278915
279637
|
return (syncPlugin?.getState(this.state)).doc;
|
|
278916
279638
|
}
|
|
278917
|
-
async replaceFile(newFile) {
|
|
279639
|
+
async replaceFile(newFile, options) {
|
|
278918
279640
|
this.setOptions({ annotations: true });
|
|
278919
|
-
const [docx, media2, mediaFiles, fonts] = await Editor2.loadXmlData(newFile);
|
|
279641
|
+
const [docx, media2, mediaFiles, fonts, decryptedData] = await Editor2.loadXmlData(newFile, false, options);
|
|
278920
279642
|
this.setOptions({
|
|
278921
|
-
fileSource: newFile,
|
|
279643
|
+
fileSource: decryptedData ?? newFile,
|
|
278922
279644
|
content: docx,
|
|
278923
279645
|
media: media2,
|
|
278924
279646
|
mediaFiles,
|
|
@@ -283864,9 +284586,9 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
283864
284586
|
];
|
|
283865
284587
|
});
|
|
283866
284588
|
|
|
283867
|
-
// ../../packages/superdoc/dist/chunks/zipper-
|
|
284589
|
+
// ../../packages/superdoc/dist/chunks/zipper-YmNpPIyc.es.js
|
|
283868
284590
|
var import_jszip_min2;
|
|
283869
|
-
var
|
|
284591
|
+
var init_zipper_YmNpPIyc_es = __esm(() => {
|
|
283870
284592
|
init_rolldown_runtime_B2q5OVn9_es();
|
|
283871
284593
|
init_jszip_ChlR43oI_es();
|
|
283872
284594
|
import_jszip_min2 = /* @__PURE__ */ __toESM2(require_jszip_min(), 1);
|
|
@@ -283874,16 +284596,18 @@ var init_zipper_DqXT7uTa_es = __esm(() => {
|
|
|
283874
284596
|
|
|
283875
284597
|
// ../../packages/superdoc/dist/super-editor.es.js
|
|
283876
284598
|
var init_super_editor_es = __esm(() => {
|
|
283877
|
-
|
|
283878
|
-
|
|
284599
|
+
init_src_DWC5tAy5_es();
|
|
284600
|
+
init_SuperConverter_CXcZg9Os_es();
|
|
283879
284601
|
init_jszip_ChlR43oI_es();
|
|
283880
284602
|
init_xml_js_40FWvL78_es();
|
|
283881
284603
|
init_constants_Qqwopz80_es();
|
|
283882
284604
|
init_unified_BRHLwnjP_es();
|
|
283883
|
-
|
|
283884
|
-
|
|
283885
|
-
|
|
283886
|
-
|
|
284605
|
+
init_DocxZipper_DvDGw347_es();
|
|
284606
|
+
init_dist_Cwvmda4Q_es();
|
|
284607
|
+
init_vue_DMgTaOx9_es();
|
|
284608
|
+
init_eventemitter3_DGBTyUUP_es();
|
|
284609
|
+
init_errors_CtyzHiH4_es();
|
|
284610
|
+
init_zipper_YmNpPIyc_es();
|
|
283887
284611
|
});
|
|
283888
284612
|
|
|
283889
284613
|
// ../../node_modules/.pnpm/happy-dom@20.4.0/node_modules/happy-dom/lib/PropertySymbol.js
|
|
@@ -284625,12 +285349,12 @@ class ResponseCacheFileSystem {
|
|
|
284625
285349
|
}
|
|
284626
285350
|
};
|
|
284627
285351
|
const json = JSON.stringify(cacheableEntry, null, 3);
|
|
284628
|
-
const
|
|
284629
|
-
if (!this.#hashes.has(
|
|
284630
|
-
this.#hashes.add(
|
|
284631
|
-
promises.push(FS.promises.writeFile(Path3.join(absoluteDirectory, `${
|
|
285352
|
+
const hash3 = Crypto.createHash("md5").update(json).digest("hex");
|
|
285353
|
+
if (!this.#hashes.has(hash3)) {
|
|
285354
|
+
this.#hashes.add(hash3);
|
|
285355
|
+
promises.push(FS.promises.writeFile(Path3.join(absoluteDirectory, `${hash3}.json`), json));
|
|
284632
285356
|
if (cachedResponse2.response.body) {
|
|
284633
|
-
promises.push(FS.promises.writeFile(Path3.join(absoluteDirectory, `${
|
|
285357
|
+
promises.push(FS.promises.writeFile(Path3.join(absoluteDirectory, `${hash3}.data`), cachedResponse2.response.body));
|
|
284634
285358
|
}
|
|
284635
285359
|
}
|
|
284636
285360
|
}
|
|
@@ -289397,11 +290121,11 @@ class SelectorItem {
|
|
|
289397
290121
|
}
|
|
289398
290122
|
return null;
|
|
289399
290123
|
case "target":
|
|
289400
|
-
const
|
|
289401
|
-
if (!
|
|
290124
|
+
const hash3 = element3[ownerDocument].location.hash;
|
|
290125
|
+
if (!hash3) {
|
|
289402
290126
|
return null;
|
|
289403
290127
|
}
|
|
289404
|
-
return element3.isConnected && element3.id ===
|
|
290128
|
+
return element3.isConnected && element3.id === hash3.slice(1) ? { priorityWeight: 10 } : null;
|
|
289405
290129
|
case "is":
|
|
289406
290130
|
let priorityWeightForIs = 0;
|
|
289407
290131
|
if (!pseudo.selectorItems) {
|
|
@@ -298704,14 +299428,14 @@ var init_Location = __esm(() => {
|
|
|
298704
299428
|
get hash() {
|
|
298705
299429
|
return this.#url.hash;
|
|
298706
299430
|
}
|
|
298707
|
-
set hash(
|
|
299431
|
+
set hash(hash3) {
|
|
298708
299432
|
const history3 = this.#browserFrame?.[history2];
|
|
298709
299433
|
if (!history3 || !this.#browserFrame) {
|
|
298710
299434
|
return;
|
|
298711
299435
|
}
|
|
298712
299436
|
const url3 = new URL(this.#url.href);
|
|
298713
299437
|
const oldHash = this.#url.hash;
|
|
298714
|
-
url3.hash =
|
|
299438
|
+
url3.hash = hash3;
|
|
298715
299439
|
if (url3.hash !== oldHash) {
|
|
298716
299440
|
history3.currentItem.popState = true;
|
|
298717
299441
|
history3.push({
|
|
@@ -306558,14 +307282,14 @@ class HTMLHyperlinkElementUtility {
|
|
|
306558
307282
|
}
|
|
306559
307283
|
return url3.hash;
|
|
306560
307284
|
}
|
|
306561
|
-
setHash(
|
|
307285
|
+
setHash(hash3) {
|
|
306562
307286
|
let url3;
|
|
306563
307287
|
try {
|
|
306564
307288
|
url3 = new URL(this.getHref());
|
|
306565
307289
|
} catch (e) {
|
|
306566
307290
|
return;
|
|
306567
307291
|
}
|
|
306568
|
-
url3.hash =
|
|
307292
|
+
url3.hash = hash3;
|
|
306569
307293
|
this.element.setAttribute("href", url3.href);
|
|
306570
307294
|
}
|
|
306571
307295
|
}
|
|
@@ -306594,8 +307318,8 @@ var init_HTMLAnchorElement = __esm(() => {
|
|
|
306594
307318
|
get hash() {
|
|
306595
307319
|
return this.#htmlHyperlinkElementUtility.getHash();
|
|
306596
307320
|
}
|
|
306597
|
-
set hash(
|
|
306598
|
-
this.#htmlHyperlinkElementUtility.setHash(
|
|
307321
|
+
set hash(hash3) {
|
|
307322
|
+
this.#htmlHyperlinkElementUtility.setHash(hash3);
|
|
306599
307323
|
}
|
|
306600
307324
|
get href() {
|
|
306601
307325
|
return this.#htmlHyperlinkElementUtility.getHref();
|
|
@@ -306871,8 +307595,8 @@ var init_HTMLAreaElement = __esm(() => {
|
|
|
306871
307595
|
get hash() {
|
|
306872
307596
|
return this.#htmlHyperlinkElementUtility.getHash();
|
|
306873
307597
|
}
|
|
306874
|
-
set hash(
|
|
306875
|
-
this.#htmlHyperlinkElementUtility.setHash(
|
|
307598
|
+
set hash(hash3) {
|
|
307599
|
+
this.#htmlHyperlinkElementUtility.setHash(hash3);
|
|
306876
307600
|
}
|
|
306877
307601
|
get tabIndex() {
|
|
306878
307602
|
const tabIndex = this.getAttribute("tabindex");
|
|
@@ -332137,6 +332861,9 @@ async function openDocument(doc4, io, options2 = {}) {
|
|
|
332137
332861
|
} catch (error4) {
|
|
332138
332862
|
commentBridge?.dispose();
|
|
332139
332863
|
domEnv.dispose();
|
|
332864
|
+
if (error4 instanceof DocxEncryptionError) {
|
|
332865
|
+
throw new CliError(error4.code, error4.message, { source: meta2 });
|
|
332866
|
+
}
|
|
332140
332867
|
const message = error4 instanceof Error ? error4.message : String(error4);
|
|
332141
332868
|
throw new CliError("DOCUMENT_OPEN_FAILED", "Failed to open document.", {
|
|
332142
332869
|
message,
|
|
@@ -332224,6 +332951,7 @@ async function openCollaborativeDocument(doc4, io, profile, options2 = {}) {
|
|
|
332224
332951
|
ydoc: runtime.ydoc,
|
|
332225
332952
|
collaborationProvider: runtime.provider,
|
|
332226
332953
|
isNewFile: shouldSeed,
|
|
332954
|
+
editorOpenOptions: options2.editorOpenOptions,
|
|
332227
332955
|
user: options2.user
|
|
332228
332956
|
});
|
|
332229
332957
|
let raceDetection;
|
|
@@ -333491,10 +334219,10 @@ function buildStableIdMappings(rawListResult) {
|
|
|
333491
334219
|
if (!rawId)
|
|
333492
334220
|
return entry;
|
|
333493
334221
|
const signature = stableTrackChangeSignature(entry);
|
|
333494
|
-
const
|
|
333495
|
-
const nextCount = (signatureCounts.get(
|
|
333496
|
-
signatureCounts.set(
|
|
333497
|
-
const stableId = nextCount === 1 ?
|
|
334222
|
+
const hash3 = createHash3("sha1").update(signature).digest("hex").slice(0, 24);
|
|
334223
|
+
const nextCount = (signatureCounts.get(hash3) ?? 0) + 1;
|
|
334224
|
+
signatureCounts.set(hash3, nextCount);
|
|
334225
|
+
const stableId = nextCount === 1 ? hash3 : `${hash3}-${nextCount}`;
|
|
333498
334226
|
stableToRawId.set(stableId, rawId);
|
|
333499
334227
|
rawToStableId.set(rawId, stableId);
|
|
333500
334228
|
const normalizedAddress = asTrackChangeAddress(entry.address);
|
|
@@ -335008,7 +335736,7 @@ function deriveOptionSpecs(operationId, params4) {
|
|
|
335008
335736
|
}
|
|
335009
335737
|
return specs;
|
|
335010
335738
|
}
|
|
335011
|
-
var DOC_PARAM, SESSION_PARAM, OUT_PARAM, FORCE_PARAM, DRY_RUN_PARAM, CHANGE_MODE_PARAM, EXPECTED_REVISION_PARAM, USER_NAME_PARAM, USER_EMAIL_PARAM, AGENT_HIDDEN_PARAM_NAMES, OPERATION_CONSTRAINTS, PARAM_FLAG_OVERRIDES, DOC_FIND_SELECT_SCHEMA, PARAM_SCHEMA_OVERRIDES, PARAM_EXCLUSIONS, TEXT_TARGET_FLAT_PARAMS, TEXT_TARGET_FLAT_PARAMS_AGENT_HIDDEN, LIST_TARGET_FLAT_PARAMS, FORMAT_OPERATION_IDS, EXTRA_CLI_PARAMS, CLI_ONLY_METADATA, CLI_OPERATION_METADATA, OPTION_FLAG_ALIASES, CLI_OPERATION_OPTION_SPECS;
|
|
335739
|
+
var DOC_PARAM, SESSION_PARAM, OUT_PARAM, FORCE_PARAM, DRY_RUN_PARAM, CHANGE_MODE_PARAM, EXPECTED_REVISION_PARAM, USER_NAME_PARAM, USER_EMAIL_PARAM, PASSWORD_PARAM, AGENT_HIDDEN_PARAM_NAMES, OPERATION_CONSTRAINTS, PARAM_FLAG_OVERRIDES, DOC_FIND_SELECT_SCHEMA, PARAM_SCHEMA_OVERRIDES, PARAM_EXCLUSIONS, TEXT_TARGET_FLAT_PARAMS, TEXT_TARGET_FLAT_PARAMS_AGENT_HIDDEN, LIST_TARGET_FLAT_PARAMS, FORMAT_OPERATION_IDS, EXTRA_CLI_PARAMS, CLI_ONLY_METADATA, CLI_OPERATION_METADATA, OPTION_FLAG_ALIASES, CLI_OPERATION_OPTION_SPECS;
|
|
335012
335740
|
var init_operation_params = __esm(() => {
|
|
335013
335741
|
init_src();
|
|
335014
335742
|
init_commands();
|
|
@@ -335067,6 +335795,13 @@ var init_operation_params = __esm(() => {
|
|
|
335067
335795
|
flag: "user-email",
|
|
335068
335796
|
type: "string"
|
|
335069
335797
|
};
|
|
335798
|
+
PASSWORD_PARAM = {
|
|
335799
|
+
name: "password",
|
|
335800
|
+
kind: "flag",
|
|
335801
|
+
type: "string",
|
|
335802
|
+
description: "Password for opening encrypted DOCX files.",
|
|
335803
|
+
agentVisible: false
|
|
335804
|
+
};
|
|
335070
335805
|
AGENT_HIDDEN_PARAM_NAMES = new Set(["out", "in"]);
|
|
335071
335806
|
OPERATION_CONSTRAINTS = {
|
|
335072
335807
|
"doc.find": {
|
|
@@ -335626,7 +336361,8 @@ var init_operation_params = __esm(() => {
|
|
|
335626
336361
|
{ name: "onMissing", kind: "flag", flag: "on-missing", type: "string" },
|
|
335627
336362
|
{ name: "bootstrapSettlingMs", kind: "flag", flag: "bootstrap-settling-ms", type: "number" },
|
|
335628
336363
|
USER_NAME_PARAM,
|
|
335629
|
-
USER_EMAIL_PARAM
|
|
336364
|
+
USER_EMAIL_PARAM,
|
|
336365
|
+
PASSWORD_PARAM
|
|
335630
336366
|
],
|
|
335631
336367
|
constraints: null
|
|
335632
336368
|
},
|
|
@@ -336955,6 +337691,15 @@ var init_close = __esm(() => {
|
|
|
336955
337691
|
init_context();
|
|
336956
337692
|
});
|
|
336957
337693
|
|
|
337694
|
+
// src/lib/open-password.ts
|
|
337695
|
+
function resolvePassword(explicit, allowEnvFallback = true) {
|
|
337696
|
+
if (explicit != null)
|
|
337697
|
+
return explicit;
|
|
337698
|
+
if (allowEnvFallback)
|
|
337699
|
+
return process.env.SUPERDOC_DOC_PASSWORD ?? undefined;
|
|
337700
|
+
return;
|
|
337701
|
+
}
|
|
337702
|
+
|
|
336958
337703
|
// src/commands/open.ts
|
|
336959
337704
|
async function runOpen(tokens, context) {
|
|
336960
337705
|
const { parsed, help } = parseOperationArgs("doc.open", tokens, {
|
|
@@ -336966,16 +337711,20 @@ async function runOpen(tokens, context) {
|
|
|
336966
337711
|
command: "open",
|
|
336967
337712
|
data: {
|
|
336968
337713
|
usage: [
|
|
336969
|
-
"superdoc open [doc] [--session <id>]",
|
|
337714
|
+
"superdoc open [doc] [--session <id>] [--password <password>]",
|
|
336970
337715
|
"superdoc open [doc] --content-override <content> --override-type <markdown|html|text>",
|
|
336971
|
-
'superdoc open [doc] --collaboration-json "{...}" [--session <id>]'
|
|
337716
|
+
'superdoc open [doc] --collaboration-json "{...}" [--session <id>]',
|
|
337717
|
+
"",
|
|
337718
|
+
"Encrypted documents: use --password or set SUPERDOC_DOC_PASSWORD env var."
|
|
336972
337719
|
]
|
|
336973
337720
|
},
|
|
336974
337721
|
pretty: [
|
|
336975
337722
|
"Usage:",
|
|
336976
|
-
" superdoc open [doc] [--session <id>]",
|
|
337723
|
+
" superdoc open [doc] [--session <id>] [--password <password>]",
|
|
336977
337724
|
" superdoc open [doc] --content-override <content> --override-type <markdown|html|text>",
|
|
336978
|
-
' superdoc open [doc] --collaboration-json "{...}" [--session <id>]'
|
|
337725
|
+
' superdoc open [doc] --collaboration-json "{...}" [--session <id>]',
|
|
337726
|
+
"",
|
|
337727
|
+
"Encrypted documents: use --password or set SUPERDOC_DOC_PASSWORD env var."
|
|
336979
337728
|
].join(`
|
|
336980
337729
|
`)
|
|
336981
337730
|
};
|
|
@@ -336991,6 +337740,8 @@ async function runOpen(tokens, context) {
|
|
|
336991
337740
|
const bootstrapSettlingMs = getNumberOption(parsed, "bootstrap-settling-ms");
|
|
336992
337741
|
const userName = getStringOption(parsed, "user-name");
|
|
336993
337742
|
const userEmail = getStringOption(parsed, "user-email");
|
|
337743
|
+
const allowEnvFallback = context.executionMode !== "host";
|
|
337744
|
+
const password = resolvePassword(getStringOption(parsed, "password"), allowEnvFallback);
|
|
336994
337745
|
if (contentOverride != null && !overrideType) {
|
|
336995
337746
|
throw new CliError("INVALID_ARGUMENT", "open: --content-override requires --override-type.");
|
|
336996
337747
|
}
|
|
@@ -337046,6 +337797,9 @@ async function runOpen(tokens, context) {
|
|
|
337046
337797
|
editorOpenOptions.plainText = contentOverride;
|
|
337047
337798
|
}
|
|
337048
337799
|
}
|
|
337800
|
+
if (password != null) {
|
|
337801
|
+
editorOpenOptions.password = password;
|
|
337802
|
+
}
|
|
337049
337803
|
return withContextLock(context.io, "open", async (paths) => {
|
|
337050
337804
|
const existing = await readContextMetadata(paths);
|
|
337051
337805
|
if (existing && existing.projectRoot !== getProjectRoot()) {
|
|
@@ -337061,7 +337815,7 @@ async function runOpen(tokens, context) {
|
|
|
337061
337815
|
revision: existing.revision
|
|
337062
337816
|
});
|
|
337063
337817
|
}
|
|
337064
|
-
const opened = collaboration ? await openCollaborativeDocument(doc4, context.io, collaboration, { user }) : await openDocument(doc4, context.io, { editorOpenOptions, user });
|
|
337818
|
+
const opened = collaboration ? await openCollaborativeDocument(doc4, context.io, collaboration, { editorOpenOptions, user }) : await openDocument(doc4, context.io, { editorOpenOptions, user });
|
|
337065
337819
|
const bootstrap = "bootstrap" in opened ? opened.bootstrap : undefined;
|
|
337066
337820
|
let adoptedToHostPool = false;
|
|
337067
337821
|
try {
|