@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.d.cts CHANGED
@@ -1,5 +1,3 @@
1
- import JSZip from 'jszip';
2
-
3
1
  declare class Relationship {
4
2
  id: string;
5
3
  type: string;
@@ -18,10 +16,10 @@ declare class Part {
18
16
  addRelationship(id: string, type: string, target: string, isExternal?: boolean): void;
19
17
  }
20
18
  declare class DocxPackage {
21
- zip: JSZip;
19
+ unzipped: Record<string, Uint8Array>;
22
20
  parts: Part[];
23
21
  mainDocumentPart: Part;
24
- constructor(zip: JSZip);
22
+ constructor(unzipped: Record<string, Uint8Array>);
25
23
  getPartByPath(path: string): Part | undefined;
26
24
  nextPartname(pattern: string): string;
27
25
  addPart(partname: string, contentType: string, xmlString: string): Part;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import JSZip from 'jszip';
2
-
3
1
  declare class Relationship {
4
2
  id: string;
5
3
  type: string;
@@ -18,10 +16,10 @@ declare class Part {
18
16
  addRelationship(id: string, type: string, target: string, isExternal?: boolean): void;
19
17
  }
20
18
  declare class DocxPackage {
21
- zip: JSZip;
19
+ unzipped: Record<string, Uint8Array>;
22
20
  parts: Part[];
23
21
  mainDocumentPart: Part;
24
- constructor(zip: JSZip);
22
+ constructor(unzipped: Record<string, Uint8Array>);
25
23
  getPartByPath(path: string): Part | undefined;
26
24
  nextPartname(pattern: string): string;
27
25
  addPart(partname: string, contentType: string, xmlString: string): Part;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/docx/bridge.ts
2
- import JSZip from "jszip";
2
+ import { unzipSync, zipSync, strFromU8, strToU8 } from "fflate";
3
3
 
4
4
  // src/docx/dom.ts
5
5
  import { DOMParser, XMLSerializer } from "@xmldom/xmldom";
@@ -108,10 +108,10 @@ var Part = class {
108
108
  }
109
109
  };
110
110
  var DocxPackage = class {
111
- constructor(zip) {
112
- this.zip = zip;
111
+ constructor(unzipped) {
112
+ this.unzipped = unzipped;
113
113
  }
114
- zip;
114
+ unzipped;
115
115
  parts = [];
116
116
  mainDocumentPart;
117
117
  getPartByPath(path) {
@@ -186,20 +186,21 @@ var DocumentObject = class _DocumentObject {
186
186
  * Main entrypoint for loading a DOCX buffer into the DOM wrapper.
187
187
  */
188
188
  static async load(buffer) {
189
- const zip = await JSZip.loadAsync(buffer);
190
- const pkg = new DocxPackage(zip);
191
- const ctFile = zip.file("[Content_Types].xml");
189
+ const u8 = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
190
+ const unzipped = unzipSync(u8);
191
+ const pkg = new DocxPackage(unzipped);
192
+ const ctFile = unzipped["[Content_Types].xml"];
192
193
  let contentTypes = {};
193
194
  if (ctFile) {
194
- const ctXml = parseXml(await ctFile.async("text"));
195
+ const ctXml = parseXml(strFromU8(ctFile));
195
196
  const overrides = findAllDescendants(ctXml.documentElement, "Override");
196
197
  for (const override of overrides) {
197
198
  contentTypes[override.getAttribute("PartName") || ""] = override.getAttribute("ContentType") || "";
198
199
  }
199
200
  }
200
- for (const [path, file] of Object.entries(zip.files)) {
201
- if (!file.dir && (path.endsWith(".xml") || path.endsWith(".rels"))) {
202
- const text = await file.async("text");
201
+ for (const [path, fileData] of Object.entries(unzipped)) {
202
+ if (path.endsWith(".xml") || path.endsWith(".rels")) {
203
+ const text = strFromU8(fileData);
203
204
  const doc = parseXml(text);
204
205
  const cType = contentTypes["/" + path] || "application/xml";
205
206
  const part = new Part("/" + path, text, doc.documentElement, cType);
@@ -252,9 +253,9 @@ var DocumentObject = class _DocumentObject {
252
253
  if (!xmlStr.startsWith("<?xml")) {
253
254
  xmlStr = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' + xmlStr;
254
255
  }
255
- this.pkg.zip.file(part.partname.substring(1), xmlStr);
256
+ this.pkg.unzipped[part.partname.substring(1)] = strToU8(xmlStr);
256
257
  }
257
- return this.pkg.zip.generateAsync({ type: "nodebuffer" });
258
+ return Buffer.from(zipSync(this.pkg.unzipped));
258
259
  }
259
260
  };
260
261