modern-pdf-lib 0.12.1 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -75,7 +75,7 @@ async function initDeflateWasm(wasmBytes) {
75
75
  let bytes;
76
76
  if (wasmBytes) bytes = wasmBytes;
77
77
  else {
78
- const { loadWasmModule } = await import("./loader-CZMj0gBy.mjs");
78
+ const { loadWasmModule } = await import("./loader-CQfoGFp9.mjs");
79
79
  bytes = await loadWasmModule("libdeflate");
80
80
  }
81
81
  const compiled = await WebAssembly.compile(new Uint8Array(bytes));
@@ -217,4 +217,4 @@ var LibdeflateWasm = class {
217
217
 
218
218
  //#endregion
219
219
  export { isAvailable as n, libdeflateWasm_exports as r, deflateSync as t };
220
- //# sourceMappingURL=libdeflateWasm-CRFwmrSl.mjs.map
220
+ //# sourceMappingURL=libdeflateWasm-DlHgU5oy.mjs.map
@@ -75,7 +75,7 @@ async function initDeflateWasm(wasmBytes) {
75
75
  let bytes;
76
76
  if (wasmBytes) bytes = wasmBytes;
77
77
  else {
78
- const { loadWasmModule } = await Promise.resolve().then(() => require("./loader-DWwMj8jZ.cjs"));
78
+ const { loadWasmModule } = await Promise.resolve().then(() => require("./loader-_fqS-TmT.cjs"));
79
79
  bytes = await loadWasmModule("libdeflate");
80
80
  }
81
81
  const compiled = await WebAssembly.compile(new Uint8Array(bytes));
@@ -234,4 +234,4 @@ Object.defineProperty(exports, 'libdeflateWasm_exports', {
234
234
  return libdeflateWasm_exports;
235
235
  }
236
236
  });
237
- //# sourceMappingURL=libdeflateWasm-DeU6cupL.cjs.map
237
+ //# sourceMappingURL=libdeflateWasm-OkNoqBnO.cjs.map
@@ -4,7 +4,8 @@ const DEFAULT_FILENAMES = {
4
4
  libdeflate: "modern_pdf_deflate_bg.wasm",
5
5
  png: "modern_pdf_png_bg.wasm",
6
6
  ttf: "modern_pdf_ttf_bg.wasm",
7
- shaping: "modern_pdf_shaping_bg.wasm"
7
+ shaping: "modern_pdf_shaping_bg.wasm",
8
+ jbig2: "modern_pdf_jbig2_bg.wasm"
8
9
  };
9
10
  /** Cached loaded WASM modules. */
10
11
  const moduleCache = /* @__PURE__ */ new Map();
@@ -113,7 +114,7 @@ function resolveModulePath(name, config, runtime) {
113
114
  * Results are cached -- subsequent calls for the same module name
114
115
  * return the cached bytes without re-fetching.
115
116
  *
116
- * @param name - Module name. One of: `'libdeflate'`, `'png'`, `'ttf'`, `'shaping'`.
117
+ * @param name - Module name. One of: `'libdeflate'`, `'png'`, `'ttf'`, `'shaping'`, `'jbig2'`.
117
118
  * @returns The raw WASM bytes.
118
119
  * @throws If the module cannot be loaded in the current runtime.
119
120
  *
@@ -159,4 +160,4 @@ async function loadWasmModule(name) {
159
160
 
160
161
  //#endregion
161
162
  export { getWasmLoaderConfig, loadWasmModule };
162
- //# sourceMappingURL=loader-CZMj0gBy.mjs.map
163
+ //# sourceMappingURL=loader-CQfoGFp9.mjs.map
@@ -5,7 +5,8 @@ const DEFAULT_FILENAMES = {
5
5
  libdeflate: "modern_pdf_deflate_bg.wasm",
6
6
  png: "modern_pdf_png_bg.wasm",
7
7
  ttf: "modern_pdf_ttf_bg.wasm",
8
- shaping: "modern_pdf_shaping_bg.wasm"
8
+ shaping: "modern_pdf_shaping_bg.wasm",
9
+ jbig2: "modern_pdf_jbig2_bg.wasm"
9
10
  };
10
11
  /** Cached loaded WASM modules. */
11
12
  const moduleCache = /* @__PURE__ */ new Map();
@@ -114,7 +115,7 @@ function resolveModulePath(name, config, runtime) {
114
115
  * Results are cached -- subsequent calls for the same module name
115
116
  * return the cached bytes without re-fetching.
116
117
  *
117
- * @param name - Module name. One of: `'libdeflate'`, `'png'`, `'ttf'`, `'shaping'`.
118
+ * @param name - Module name. One of: `'libdeflate'`, `'png'`, `'ttf'`, `'shaping'`, `'jbig2'`.
118
119
  * @returns The raw WASM bytes.
119
120
  * @throws If the module cannot be loaded in the current runtime.
120
121
  *
@@ -161,4 +162,4 @@ async function loadWasmModule(name) {
161
162
  //#endregion
162
163
  exports.getWasmLoaderConfig = getWasmLoaderConfig;
163
164
  exports.loadWasmModule = loadWasmModule;
164
- //# sourceMappingURL=loader-DWwMj8jZ.cjs.map
165
+ //# sourceMappingURL=loader-_fqS-TmT.cjs.map
@@ -5,12 +5,26 @@ const encoder = new TextEncoder();
5
5
  /** Format a number for PDF output (no trailing zeros). */
6
6
  function formatNumber(value) {
7
7
  if (Number.isInteger(value)) return value.toString();
8
- const s = value.toFixed(10).replace(/\.?0+$/, "");
9
- return s === "-0" ? "0" : s;
8
+ const s = value.toFixed(10);
9
+ let end = s.length;
10
+ while (end > 0 && s.charCodeAt(end - 1) === 48) end--;
11
+ if (end > 0 && s.charCodeAt(end - 1) === 46) end--;
12
+ const trimmed = end === s.length ? s : s.slice(0, end);
13
+ return trimmed === "-0" ? "0" : trimmed;
10
14
  }
11
15
  /** Escape bytes for a PDF literal string `(…)`. */
12
16
  function escapeLiteralString(str) {
13
- return str.replace(/\\/g, "\\\\").replace(/\(/g, "\\(").replace(/\)/g, "\\)").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
17
+ const parts = [];
18
+ for (let i = 0; i < str.length; i++) {
19
+ const c = str.charCodeAt(i);
20
+ if (c === 92) parts.push("\\\\");
21
+ else if (c === 40) parts.push("\\(");
22
+ else if (c === 41) parts.push("\\)");
23
+ else if (c === 13) parts.push("\\r");
24
+ else if (c === 10) parts.push("\\n");
25
+ else parts.push(str[i]);
26
+ }
27
+ return parts.join("");
14
28
  }
15
29
  /** Convert bytes to hex pairs (delegates to Uint8Array.prototype.toHex). */
16
30
  function bytesToHex(data) {
@@ -116,13 +130,13 @@ var PdfName = class PdfName {
116
130
  return cached;
117
131
  }
118
132
  serialize(writer) {
119
- let encoded = "/";
133
+ const parts = ["/"];
120
134
  for (let i = 1; i < this.value.length; i++) {
121
135
  const code = this.value.charCodeAt(i);
122
- if (code !== void 0 && code >= 33 && code <= 126 && code !== 35) encoded += this.value.at(i);
123
- else encoded += "#" + (code ?? 0).toString(16).padStart(2, "0");
136
+ if (code >= 33 && code <= 126 && code !== 35) parts.push(this.value[i]);
137
+ else parts.push("#" + code.toString(16).padStart(2, "0"));
124
138
  }
125
- writer.writeString(encoded);
139
+ writer.writeString(parts.join(""));
126
140
  }
127
141
  };
128
142
  /** A PDF array `[…]`. */
@@ -133,7 +147,7 @@ var PdfArray = class PdfArray {
133
147
  this.items = items;
134
148
  }
135
149
  static of(items) {
136
- return new PdfArray([...items]);
150
+ return new PdfArray(items.slice());
137
151
  }
138
152
  /** Convenience: create an array of PdfNumbers. */
139
153
  static fromNumbers(values) {
@@ -529,4 +543,4 @@ function buildDocumentStructure(pages, meta, registry, options) {
529
543
 
530
544
  //#endregion
531
545
  export { formatPdfDate as a, PdfBool as c, PdfNull as d, PdfNumber as f, PdfString as g, PdfStream as h, buildPageTree as i, PdfDict as l, PdfRef as m, buildDocumentStructure as n, pdfCatalog_exports as o, PdfObjectRegistry as p, buildInfoDict as r, PdfArray as s, buildCatalog as t, PdfName as u };
532
- //# sourceMappingURL=pdfCatalog-CTfeeqtF.mjs.map
546
+ //# sourceMappingURL=pdfCatalog-BB2Wnmud.mjs.map
@@ -5,12 +5,26 @@ const encoder = new TextEncoder();
5
5
  /** Format a number for PDF output (no trailing zeros). */
6
6
  function formatNumber(value) {
7
7
  if (Number.isInteger(value)) return value.toString();
8
- const s = value.toFixed(10).replace(/\.?0+$/, "");
9
- return s === "-0" ? "0" : s;
8
+ const s = value.toFixed(10);
9
+ let end = s.length;
10
+ while (end > 0 && s.charCodeAt(end - 1) === 48) end--;
11
+ if (end > 0 && s.charCodeAt(end - 1) === 46) end--;
12
+ const trimmed = end === s.length ? s : s.slice(0, end);
13
+ return trimmed === "-0" ? "0" : trimmed;
10
14
  }
11
15
  /** Escape bytes for a PDF literal string `(…)`. */
12
16
  function escapeLiteralString(str) {
13
- return str.replace(/\\/g, "\\\\").replace(/\(/g, "\\(").replace(/\)/g, "\\)").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
17
+ const parts = [];
18
+ for (let i = 0; i < str.length; i++) {
19
+ const c = str.charCodeAt(i);
20
+ if (c === 92) parts.push("\\\\");
21
+ else if (c === 40) parts.push("\\(");
22
+ else if (c === 41) parts.push("\\)");
23
+ else if (c === 13) parts.push("\\r");
24
+ else if (c === 10) parts.push("\\n");
25
+ else parts.push(str[i]);
26
+ }
27
+ return parts.join("");
14
28
  }
15
29
  /** Convert bytes to hex pairs (delegates to Uint8Array.prototype.toHex). */
16
30
  function bytesToHex(data) {
@@ -116,13 +130,13 @@ var PdfName = class PdfName {
116
130
  return cached;
117
131
  }
118
132
  serialize(writer) {
119
- let encoded = "/";
133
+ const parts = ["/"];
120
134
  for (let i = 1; i < this.value.length; i++) {
121
135
  const code = this.value.charCodeAt(i);
122
- if (code !== void 0 && code >= 33 && code <= 126 && code !== 35) encoded += this.value.at(i);
123
- else encoded += "#" + (code ?? 0).toString(16).padStart(2, "0");
136
+ if (code >= 33 && code <= 126 && code !== 35) parts.push(this.value[i]);
137
+ else parts.push("#" + code.toString(16).padStart(2, "0"));
124
138
  }
125
- writer.writeString(encoded);
139
+ writer.writeString(parts.join(""));
126
140
  }
127
141
  };
128
142
  /** A PDF array `[…]`. */
@@ -133,7 +147,7 @@ var PdfArray = class PdfArray {
133
147
  this.items = items;
134
148
  }
135
149
  static of(items) {
136
- return new PdfArray([...items]);
150
+ return new PdfArray(items.slice());
137
151
  }
138
152
  /** Convenience: create an array of PdfNumbers. */
139
153
  static fromNumbers(values) {
@@ -624,4 +638,4 @@ Object.defineProperty(exports, 'pdfCatalog_exports', {
624
638
  return pdfCatalog_exports;
625
639
  }
626
640
  });
627
- //# sourceMappingURL=pdfCatalog-y_XG8Hq1.cjs.map
641
+ //# sourceMappingURL=pdfCatalog-COKoYQ8C.cjs.map