@adeu/core 1.7.3 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +14 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +14 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/docx/bridge.ts +14 -12
- package/src/sanitize/sanitize.test.ts +134 -104
package/dist/index.cjs
CHANGED
|
@@ -49,7 +49,7 @@ __export(index_exports, {
|
|
|
49
49
|
module.exports = __toCommonJS(index_exports);
|
|
50
50
|
|
|
51
51
|
// src/docx/bridge.ts
|
|
52
|
-
var
|
|
52
|
+
var import_fflate = require("fflate");
|
|
53
53
|
|
|
54
54
|
// src/docx/dom.ts
|
|
55
55
|
var import_xmldom = require("@xmldom/xmldom");
|
|
@@ -158,10 +158,10 @@ var Part = class {
|
|
|
158
158
|
}
|
|
159
159
|
};
|
|
160
160
|
var DocxPackage = class {
|
|
161
|
-
constructor(
|
|
162
|
-
this.
|
|
161
|
+
constructor(unzipped) {
|
|
162
|
+
this.unzipped = unzipped;
|
|
163
163
|
}
|
|
164
|
-
|
|
164
|
+
unzipped;
|
|
165
165
|
parts = [];
|
|
166
166
|
mainDocumentPart;
|
|
167
167
|
getPartByPath(path) {
|
|
@@ -236,20 +236,21 @@ var DocumentObject = class _DocumentObject {
|
|
|
236
236
|
* Main entrypoint for loading a DOCX buffer into the DOM wrapper.
|
|
237
237
|
*/
|
|
238
238
|
static async load(buffer) {
|
|
239
|
-
const
|
|
240
|
-
const
|
|
241
|
-
const
|
|
239
|
+
const u8 = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
240
|
+
const unzipped = (0, import_fflate.unzipSync)(u8);
|
|
241
|
+
const pkg = new DocxPackage(unzipped);
|
|
242
|
+
const ctFile = unzipped["[Content_Types].xml"];
|
|
242
243
|
let contentTypes = {};
|
|
243
244
|
if (ctFile) {
|
|
244
|
-
const ctXml = parseXml(
|
|
245
|
+
const ctXml = parseXml((0, import_fflate.strFromU8)(ctFile));
|
|
245
246
|
const overrides = findAllDescendants(ctXml.documentElement, "Override");
|
|
246
247
|
for (const override of overrides) {
|
|
247
248
|
contentTypes[override.getAttribute("PartName") || ""] = override.getAttribute("ContentType") || "";
|
|
248
249
|
}
|
|
249
250
|
}
|
|
250
|
-
for (const [path,
|
|
251
|
-
if (
|
|
252
|
-
const text =
|
|
251
|
+
for (const [path, fileData] of Object.entries(unzipped)) {
|
|
252
|
+
if (path.endsWith(".xml") || path.endsWith(".rels")) {
|
|
253
|
+
const text = (0, import_fflate.strFromU8)(fileData);
|
|
253
254
|
const doc = parseXml(text);
|
|
254
255
|
const cType = contentTypes["/" + path] || "application/xml";
|
|
255
256
|
const part = new Part("/" + path, text, doc.documentElement, cType);
|
|
@@ -302,9 +303,9 @@ var DocumentObject = class _DocumentObject {
|
|
|
302
303
|
if (!xmlStr.startsWith("<?xml")) {
|
|
303
304
|
xmlStr = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' + xmlStr;
|
|
304
305
|
}
|
|
305
|
-
this.pkg.
|
|
306
|
+
this.pkg.unzipped[part.partname.substring(1)] = (0, import_fflate.strToU8)(xmlStr);
|
|
306
307
|
}
|
|
307
|
-
return this.pkg.
|
|
308
|
+
return Buffer.from((0, import_fflate.zipSync)(this.pkg.unzipped));
|
|
308
309
|
}
|
|
309
310
|
};
|
|
310
311
|
|