wpd-codec 3.2.2 → 3.4.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.
Files changed (44) hide show
  1. package/README.md +8 -3
  2. package/dist/bytes/base64.cjs +21 -0
  3. package/dist/bytes/base64.d.cts +4 -0
  4. package/dist/bytes/base64.d.ts +4 -0
  5. package/dist/bytes/base64.js +20 -0
  6. package/dist/container/container.cjs +6 -3
  7. package/dist/container/container.d.cts +2 -2
  8. package/dist/container/container.d.ts +2 -2
  9. package/dist/container/container.js +6 -3
  10. package/dist/container/encryption.cjs +59 -0
  11. package/dist/container/encryption.d.cts +9 -0
  12. package/dist/container/encryption.d.ts +9 -0
  13. package/dist/container/encryption.js +54 -0
  14. package/dist/container/header.cjs +5 -3
  15. package/dist/container/header.d.cts +6 -2
  16. package/dist/container/header.d.ts +6 -2
  17. package/dist/container/header.js +5 -3
  18. package/dist/{diagnostics-Dtb2uPw4.d.cts → diagnostics-DhO7mgqJ.d.cts} +1 -0
  19. package/dist/{diagnostics-Dtb2uPw4.d.ts → diagnostics-DhO7mgqJ.d.ts} +1 -0
  20. package/dist/diagnostics.cjs +1 -0
  21. package/dist/diagnostics.d.cts +1 -1
  22. package/dist/diagnostics.d.ts +1 -1
  23. package/dist/diagnostics.js +1 -0
  24. package/dist/errors.cjs +11 -0
  25. package/dist/errors.d.cts +6 -1
  26. package/dist/errors.d.ts +6 -1
  27. package/dist/errors.js +11 -1
  28. package/dist/index.cjs +1 -0
  29. package/dist/index.d.cts +3 -3
  30. package/dist/index.d.ts +3 -3
  31. package/dist/index.js +2 -2
  32. package/dist/read.cjs +177 -7
  33. package/dist/read.d.cts +9 -3
  34. package/dist/read.d.ts +9 -3
  35. package/dist/read.js +177 -7
  36. package/dist/stream/furniture.cjs +33 -0
  37. package/dist/stream/furniture.d.cts +15 -0
  38. package/dist/stream/furniture.d.ts +15 -0
  39. package/dist/stream/furniture.js +25 -0
  40. package/dist/stream/image.cjs +72 -0
  41. package/dist/stream/image.d.cts +8 -0
  42. package/dist/stream/image.d.ts +8 -0
  43. package/dist/stream/image.js +71 -0
  44. package/package.json +3 -3
@@ -0,0 +1,15 @@
1
+ //#region src/stream/furniture.d.ts
2
+ declare const HEADER_FOOTER_GROUP = 214;
3
+ declare const HEADER_A = 0;
4
+ declare const HEADER_B = 1;
5
+ declare const FOOTER_A = 2;
6
+ declare const FOOTER_B = 3;
7
+ declare const WATERMARK_A = 4;
8
+ declare const WATERMARK_B = 5;
9
+ interface WpdFurnitureClaim {
10
+ readonly kind: "header" | "footer";
11
+ readonly slot: "default" | "even";
12
+ }
13
+ declare function readFurnitureClaim(subgroup: number, nonDeletable: Uint8Array): WpdFurnitureClaim | "watermark" | "none";
14
+ //#endregion
15
+ export { FOOTER_A, FOOTER_B, HEADER_A, HEADER_B, HEADER_FOOTER_GROUP, WATERMARK_A, WATERMARK_B, WpdFurnitureClaim, readFurnitureClaim };
@@ -0,0 +1,25 @@
1
+ //#region src/stream/furniture.ts
2
+ const HEADER_FOOTER_GROUP = 214;
3
+ const HEADER_A = 0;
4
+ const HEADER_B = 1;
5
+ const FOOTER_A = 2;
6
+ const FOOTER_B = 3;
7
+ const WATERMARK_A = 4;
8
+ const WATERMARK_B = 5;
9
+ const OCCURS_ON_ODD = 1;
10
+ const OCCURS_ON_EVEN = 2;
11
+ function readFurnitureClaim(subgroup, nonDeletable) {
12
+ if (subgroup === 4 || subgroup === 5) return "watermark";
13
+ const kind = subgroup === 0 || subgroup === 1 ? "header" : subgroup === 2 || subgroup === 3 ? "footer" : void 0;
14
+ if (kind === void 0) return "none";
15
+ const occurrence = nonDeletable[0] ?? 0;
16
+ const odd = (occurrence & OCCURS_ON_ODD) !== 0;
17
+ const even = (occurrence & OCCURS_ON_EVEN) !== 0;
18
+ if (!odd && !even) return "none";
19
+ return {
20
+ kind,
21
+ slot: even && !odd ? "even" : "default"
22
+ };
23
+ }
24
+ //#endregion
25
+ export { FOOTER_A, FOOTER_B, HEADER_A, HEADER_B, HEADER_FOOTER_GROUP, WATERMARK_A, WATERMARK_B, readFurnitureClaim };
@@ -0,0 +1,72 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_bytes_view = require("../bytes/view.cjs");
3
+ //#region src/stream/image.ts
4
+ const PNG_SIGNATURE = [
5
+ 137,
6
+ 80,
7
+ 78,
8
+ 71,
9
+ 13,
10
+ 10,
11
+ 26,
12
+ 10
13
+ ];
14
+ const JPEG_SOI = [255, 216];
15
+ function indexOf(bytes, needle, from) {
16
+ outer: for (let i = from; i + needle.length <= bytes.length; i += 1) {
17
+ for (let j = 0; j < needle.length; j += 1) if (bytes[i + j] !== needle[j]) continue outer;
18
+ return i;
19
+ }
20
+ }
21
+ function scanPng(bytes, signatureAt) {
22
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
23
+ let cursor = signatureAt + PNG_SIGNATURE.length;
24
+ for (;;) {
25
+ if (cursor + 8 > bytes.length) return;
26
+ const length = view.getUint32(cursor);
27
+ const type = String.fromCharCode(require_bytes_view.byteAt(bytes, cursor + 4), require_bytes_view.byteAt(bytes, cursor + 5), require_bytes_view.byteAt(bytes, cursor + 6), require_bytes_view.byteAt(bytes, cursor + 7));
28
+ cursor += 8 + length + 4;
29
+ if (cursor > bytes.length) return;
30
+ if (type === "IEND") return {
31
+ format: "png",
32
+ bytes: bytes.subarray(signatureAt, cursor)
33
+ };
34
+ }
35
+ }
36
+ function scanJpeg(bytes, soiAt) {
37
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
38
+ let cursor = soiAt + JPEG_SOI.length;
39
+ for (;;) {
40
+ if (cursor >= bytes.length) return;
41
+ if (require_bytes_view.byteAt(bytes, cursor) !== 255) return;
42
+ while (cursor < bytes.length && require_bytes_view.byteAt(bytes, cursor) === 255) cursor += 1;
43
+ if (cursor >= bytes.length) return;
44
+ const marker = require_bytes_view.byteAt(bytes, cursor);
45
+ cursor += 1;
46
+ if (marker === 216 || marker === 1 || marker >= 208 && marker <= 215) continue;
47
+ if (marker === 217) return {
48
+ format: "jpeg",
49
+ bytes: bytes.subarray(soiAt, cursor)
50
+ };
51
+ if (cursor + 2 > bytes.length) return;
52
+ const length = view.getUint16(cursor);
53
+ if (length < 2 || cursor + length > bytes.length) return;
54
+ cursor += length;
55
+ if (marker === 218) {
56
+ const eoi = indexOf(bytes, [255, 217], cursor);
57
+ if (eoi === void 0) return;
58
+ return {
59
+ format: "jpeg",
60
+ bytes: bytes.subarray(soiAt, eoi + 2)
61
+ };
62
+ }
63
+ }
64
+ }
65
+ function scanImagePayload(bytes) {
66
+ const pngAt = indexOf(bytes, PNG_SIGNATURE, 0);
67
+ const jpegAt = indexOf(bytes, JPEG_SOI, 0);
68
+ if (pngAt !== void 0 && (jpegAt === void 0 || pngAt < jpegAt)) return scanPng(bytes, pngAt);
69
+ if (jpegAt !== void 0) return scanJpeg(bytes, jpegAt);
70
+ }
71
+ //#endregion
72
+ exports.scanImagePayload = scanImagePayload;
@@ -0,0 +1,8 @@
1
+ //#region src/stream/image.d.ts
2
+ interface WpdImagePayload {
3
+ readonly format: "png" | "jpeg";
4
+ readonly bytes: Uint8Array;
5
+ }
6
+ declare function scanImagePayload(bytes: Uint8Array): WpdImagePayload | undefined;
7
+ //#endregion
8
+ export { WpdImagePayload, scanImagePayload };
@@ -0,0 +1,8 @@
1
+ //#region src/stream/image.d.ts
2
+ interface WpdImagePayload {
3
+ readonly format: "png" | "jpeg";
4
+ readonly bytes: Uint8Array;
5
+ }
6
+ declare function scanImagePayload(bytes: Uint8Array): WpdImagePayload | undefined;
7
+ //#endregion
8
+ export { WpdImagePayload, scanImagePayload };
@@ -0,0 +1,71 @@
1
+ import { byteAt } from "../bytes/view.js";
2
+ //#region src/stream/image.ts
3
+ const PNG_SIGNATURE = [
4
+ 137,
5
+ 80,
6
+ 78,
7
+ 71,
8
+ 13,
9
+ 10,
10
+ 26,
11
+ 10
12
+ ];
13
+ const JPEG_SOI = [255, 216];
14
+ function indexOf(bytes, needle, from) {
15
+ outer: for (let i = from; i + needle.length <= bytes.length; i += 1) {
16
+ for (let j = 0; j < needle.length; j += 1) if (bytes[i + j] !== needle[j]) continue outer;
17
+ return i;
18
+ }
19
+ }
20
+ function scanPng(bytes, signatureAt) {
21
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
22
+ let cursor = signatureAt + PNG_SIGNATURE.length;
23
+ for (;;) {
24
+ if (cursor + 8 > bytes.length) return;
25
+ const length = view.getUint32(cursor);
26
+ const type = String.fromCharCode(byteAt(bytes, cursor + 4), byteAt(bytes, cursor + 5), byteAt(bytes, cursor + 6), byteAt(bytes, cursor + 7));
27
+ cursor += 8 + length + 4;
28
+ if (cursor > bytes.length) return;
29
+ if (type === "IEND") return {
30
+ format: "png",
31
+ bytes: bytes.subarray(signatureAt, cursor)
32
+ };
33
+ }
34
+ }
35
+ function scanJpeg(bytes, soiAt) {
36
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
37
+ let cursor = soiAt + JPEG_SOI.length;
38
+ for (;;) {
39
+ if (cursor >= bytes.length) return;
40
+ if (byteAt(bytes, cursor) !== 255) return;
41
+ while (cursor < bytes.length && byteAt(bytes, cursor) === 255) cursor += 1;
42
+ if (cursor >= bytes.length) return;
43
+ const marker = byteAt(bytes, cursor);
44
+ cursor += 1;
45
+ if (marker === 216 || marker === 1 || marker >= 208 && marker <= 215) continue;
46
+ if (marker === 217) return {
47
+ format: "jpeg",
48
+ bytes: bytes.subarray(soiAt, cursor)
49
+ };
50
+ if (cursor + 2 > bytes.length) return;
51
+ const length = view.getUint16(cursor);
52
+ if (length < 2 || cursor + length > bytes.length) return;
53
+ cursor += length;
54
+ if (marker === 218) {
55
+ const eoi = indexOf(bytes, [255, 217], cursor);
56
+ if (eoi === void 0) return;
57
+ return {
58
+ format: "jpeg",
59
+ bytes: bytes.subarray(soiAt, eoi + 2)
60
+ };
61
+ }
62
+ }
63
+ }
64
+ function scanImagePayload(bytes) {
65
+ const pngAt = indexOf(bytes, PNG_SIGNATURE, 0);
66
+ const jpegAt = indexOf(bytes, JPEG_SOI, 0);
67
+ if (pngAt !== void 0 && (jpegAt === void 0 || pngAt < jpegAt)) return scanPng(bytes, pngAt);
68
+ if (jpegAt !== void 0) return scanJpeg(bytes, jpegAt);
69
+ }
70
+ //#endregion
71
+ export { scanImagePayload };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wpd-codec",
3
- "version": "3.2.2",
3
+ "version": "3.4.0",
4
4
  "description": "Hand-written read-only WordPerfect 6.x-X6 (.wpd) reader over document-schema.js's ContentDocument",
5
5
  "type": "module",
6
6
  "repository": {
@@ -80,8 +80,8 @@
80
80
  "license": "MIT",
81
81
  "packageManager": "pnpm@11.6.0",
82
82
  "dependencies": {
83
- "archive-codec": "1.10.1",
84
- "document-schema.js": "7.5.1",
83
+ "archive-codec": "1.10.2",
84
+ "document-schema.js": "7.6.0",
85
85
  "zod": "4.4.3"
86
86
  },
87
87
  "devDependencies": {