pdf-parser.js 3.0.8 → 4.5.1

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 (240) hide show
  1. package/README.md +105 -54
  2. package/dist/{afm-widths-Dxucrg7D.js → afm-widths-BTu0IDp2.cjs} +1517 -4
  3. package/dist/{afm-widths-DyDq56Ph.d.cts → afm-widths-CneRyu5l.d.cts} +1 -1
  4. package/dist/{afm-widths-DyDq56Ph.d.ts → afm-widths-CneRyu5l.d.ts} +1 -1
  5. package/dist/{afm-widths-BoeTOK2r.cjs → afm-widths-De_QMWgC.js} +1416 -51
  6. package/dist/afm-widths.cjs +1 -1
  7. package/dist/afm-widths.d.cts +1 -1
  8. package/dist/afm-widths.d.ts +1 -1
  9. package/dist/afm-widths.js +1 -1
  10. package/dist/annotations.cjs +104 -0
  11. package/dist/annotations.d.cts +9 -0
  12. package/dist/annotations.d.ts +9 -0
  13. package/dist/annotations.js +103 -0
  14. package/dist/attachments.cjs +65 -0
  15. package/dist/attachments.d.cts +8 -0
  16. package/dist/attachments.d.ts +8 -0
  17. package/dist/attachments.js +64 -0
  18. package/dist/builtin-encoding.cjs +221 -0
  19. package/dist/builtin-encoding.d.cts +8 -0
  20. package/dist/builtin-encoding.d.ts +8 -0
  21. package/dist/builtin-encoding.js +220 -0
  22. package/dist/bytes/flate.cjs +1 -1
  23. package/dist/bytes/flate.js +1 -1
  24. package/dist/cff.cjs +14 -0
  25. package/dist/cff.d.cts +4 -1
  26. package/dist/cff.d.ts +4 -1
  27. package/dist/cff.js +12 -1
  28. package/dist/cmap-table.cjs +76 -13
  29. package/dist/cmap-table.d.cts +9 -1
  30. package/dist/cmap-table.d.ts +9 -1
  31. package/dist/cmap-table.js +77 -15
  32. package/dist/codec.cjs +1 -1
  33. package/dist/codec.d.cts +134 -0
  34. package/dist/codec.d.ts +134 -0
  35. package/dist/codec.js +1 -1
  36. package/dist/content-read.cjs +1 -1
  37. package/dist/content-read.d.cts +3 -3
  38. package/dist/content-read.d.ts +3 -3
  39. package/dist/content-read.js +1 -1
  40. package/dist/content-write.cjs +32 -10
  41. package/dist/content-write.d.cts +12 -5
  42. package/dist/content-write.d.ts +12 -5
  43. package/dist/content-write.js +32 -10
  44. package/dist/crypto/random.cjs +9 -0
  45. package/dist/crypto/random.d.cts +4 -0
  46. package/dist/crypto/random.d.ts +4 -0
  47. package/dist/crypto/random.js +8 -0
  48. package/dist/diagnostics.d.cts +1 -1
  49. package/dist/diagnostics.d.ts +1 -1
  50. package/dist/document.cjs +12 -3
  51. package/dist/document.d.cts +3 -1
  52. package/dist/document.d.ts +3 -1
  53. package/dist/document.js +12 -3
  54. package/dist/{embedded-font-fREdbxnr.d.ts → embedded-font-B4p9a3O3.d.ts} +3 -1
  55. package/dist/{embedded-font-BU6Jgcof.d.cts → embedded-font-oc65VGlr.d.cts} +3 -1
  56. package/dist/embedded-font-write.cjs +1 -1
  57. package/dist/embedded-font-write.d.cts +3 -3
  58. package/dist/embedded-font-write.d.ts +3 -3
  59. package/dist/embedded-font-write.js +1 -1
  60. package/dist/embedded-font.cjs +46 -15
  61. package/dist/embedded-font.d.cts +1 -1
  62. package/dist/embedded-font.d.ts +1 -1
  63. package/dist/embedded-font.js +46 -15
  64. package/dist/encoding.cjs +10 -1
  65. package/dist/encoding.d.cts +10 -1
  66. package/dist/encoding.d.ts +10 -1
  67. package/dist/encoding.js +2 -2
  68. package/dist/encrypt-write.cjs +234 -0
  69. package/dist/encrypt-write.d.cts +31 -0
  70. package/dist/encrypt-write.d.ts +31 -0
  71. package/dist/encrypt-write.js +231 -0
  72. package/dist/encrypt.cjs +51 -21
  73. package/dist/encrypt.d.cts +19 -3
  74. package/dist/encrypt.d.ts +19 -3
  75. package/dist/encrypt.js +36 -22
  76. package/dist/filters.cjs +18 -14
  77. package/dist/filters.d.cts +1 -1
  78. package/dist/filters.d.ts +1 -1
  79. package/dist/filters.js +18 -14
  80. package/dist/font-read.cjs +68 -13
  81. package/dist/font-read.d.cts +1 -1
  82. package/dist/font-read.d.ts +1 -1
  83. package/dist/font-read.js +69 -14
  84. package/dist/font-registry.cjs +1 -1
  85. package/dist/font-registry.d.cts +4 -4
  86. package/dist/font-registry.d.ts +4 -4
  87. package/dist/font-registry.js +1 -1
  88. package/dist/font-substitutes.d.cts +1 -1
  89. package/dist/font-substitutes.d.ts +1 -1
  90. package/dist/font-tables.cjs +31 -0
  91. package/dist/font-tables.d.cts +3 -1
  92. package/dist/font-tables.d.ts +3 -1
  93. package/dist/font-tables.js +31 -2
  94. package/dist/fonts.d.cts +2 -2
  95. package/dist/fonts.d.ts +2 -2
  96. package/dist/form.cjs +138 -0
  97. package/dist/form.d.cts +9 -0
  98. package/dist/form.d.ts +9 -0
  99. package/dist/form.js +137 -0
  100. package/dist/gsub-table-BRTQ8EUW.d.ts +10 -0
  101. package/dist/gsub-table-URczLd85.d.cts +10 -0
  102. package/dist/gsub-table.cjs +225 -0
  103. package/dist/gsub-table.d.cts +2 -0
  104. package/dist/gsub-table.d.ts +2 -0
  105. package/dist/gsub-table.js +224 -0
  106. package/dist/image/ccitt-encode.cjs +119 -0
  107. package/dist/image/ccitt-encode.d.cts +9 -0
  108. package/dist/image/ccitt-encode.d.ts +9 -0
  109. package/dist/image/ccitt-encode.js +118 -0
  110. package/dist/image/ccitt.cjs +3 -0
  111. package/dist/image/ccitt.d.cts +4 -1
  112. package/dist/image/ccitt.d.ts +4 -1
  113. package/dist/image/ccitt.js +1 -1
  114. package/dist/image/jbig2-bitmap.d.cts +1 -1
  115. package/dist/image/jbig2-bitmap.d.ts +1 -1
  116. package/dist/image/jbig2.cjs +3 -1
  117. package/dist/image/jbig2.js +3 -1
  118. package/dist/image/jp2-boxes.d.cts +1 -1
  119. package/dist/image/jp2-boxes.d.ts +1 -1
  120. package/dist/image/jpeg2000-codestream.d.cts +3 -3
  121. package/dist/image/jpeg2000-codestream.d.ts +3 -3
  122. package/dist/image/jpeg2000-t1.d.cts +1 -1
  123. package/dist/image/jpeg2000-t1.d.ts +1 -1
  124. package/dist/image/jpeg2000.cjs +1 -0
  125. package/dist/image/jpeg2000.d.cts +3 -0
  126. package/dist/image/jpeg2000.d.ts +3 -0
  127. package/dist/image/jpeg2000.js +1 -0
  128. package/dist/image/png-decode.cjs +1 -1
  129. package/dist/image/png-decode.js +1 -1
  130. package/dist/image/png-filter.d.cts +1 -1
  131. package/dist/image/png-filter.d.ts +1 -1
  132. package/dist/images-read.cjs +18 -12
  133. package/dist/images-read.d.cts +2 -2
  134. package/dist/images-read.d.ts +2 -2
  135. package/dist/images-read.js +15 -9
  136. package/dist/index.cjs +17 -4
  137. package/dist/index.d.cts +7 -6
  138. package/dist/index.d.ts +7 -6
  139. package/dist/index.js +6 -5
  140. package/dist/interpret.cjs +178 -56
  141. package/dist/interpret.d.cts +27 -12
  142. package/dist/interpret.d.ts +27 -12
  143. package/dist/interpret.js +178 -56
  144. package/dist/layout.cjs +149 -2
  145. package/dist/layout.d.cts +394 -1
  146. package/dist/layout.d.ts +394 -1
  147. package/dist/layout.js +140 -4
  148. package/dist/lexer.d.cts +9 -9
  149. package/dist/lexer.d.ts +9 -9
  150. package/dist/math-content-write.cjs +1 -1
  151. package/dist/math-content-write.js +1 -1
  152. package/dist/math-font-write.cjs +1 -1
  153. package/dist/math-font-write.d.cts +1 -1
  154. package/dist/math-font-write.d.ts +1 -1
  155. package/dist/math-font-write.js +1 -1
  156. package/dist/math-font.cjs +2 -2
  157. package/dist/math-font.d.cts +1 -1
  158. package/dist/math-font.d.ts +1 -1
  159. package/dist/math-font.js +2 -2
  160. package/dist/{math-stretch-a_rHNRvc.d.ts → math-stretch-BbC2o4Br.d.ts} +1 -1
  161. package/dist/{math-stretch-E26z6byT.d.cts → math-stretch-C2JanDAz.d.cts} +1 -1
  162. package/dist/math-stretch.d.cts +1 -1
  163. package/dist/math-stretch.d.ts +1 -1
  164. package/dist/measure.cjs +1 -1
  165. package/dist/measure.d.cts +1 -1
  166. package/dist/measure.d.ts +1 -1
  167. package/dist/measure.js +1 -1
  168. package/dist/names.cjs +41 -0
  169. package/dist/names.d.cts +11 -0
  170. package/dist/names.d.ts +11 -0
  171. package/dist/names.js +40 -0
  172. package/dist/navigation.cjs +210 -0
  173. package/dist/navigation.d.cts +18 -0
  174. package/dist/navigation.d.ts +18 -0
  175. package/dist/navigation.js +207 -0
  176. package/dist/notes-annotation-author.cjs +5 -0
  177. package/dist/notes-annotation-author.d.cts +4 -0
  178. package/dist/notes-annotation-author.d.ts +4 -0
  179. package/dist/notes-annotation-author.js +4 -0
  180. package/dist/objects-B7HdMeWS.d.cts +59 -0
  181. package/dist/objects-B7HdMeWS.d.ts +59 -0
  182. package/dist/objects.d.cts +1 -58
  183. package/dist/objects.d.ts +1 -58
  184. package/dist/optional-content.cjs +63 -0
  185. package/dist/optional-content.d.cts +12 -0
  186. package/dist/optional-content.d.ts +12 -0
  187. package/dist/optional-content.js +62 -0
  188. package/dist/parse.cjs +1 -1
  189. package/dist/parse.d.cts +2 -2
  190. package/dist/parse.d.ts +2 -2
  191. package/dist/parse.js +1 -1
  192. package/dist/pdf-text.cjs +21 -0
  193. package/dist/pdf-text.d.cts +5 -0
  194. package/dist/pdf-text.d.ts +5 -0
  195. package/dist/pdf-text.js +19 -0
  196. package/dist/predictors.d.cts +1 -1
  197. package/dist/predictors.d.ts +1 -1
  198. package/dist/read.cjs +287 -72
  199. package/dist/read.d.cts +2 -4
  200. package/dist/read.d.ts +2 -4
  201. package/dist/read.js +284 -67
  202. package/dist/serialize.cjs +5 -1
  203. package/dist/serialize.d.cts +3 -2
  204. package/dist/serialize.d.ts +3 -2
  205. package/dist/serialize.js +5 -2
  206. package/dist/sfnt-subset.cjs +10 -3
  207. package/dist/sfnt-subset.d.cts +1 -1
  208. package/dist/sfnt-subset.d.ts +1 -1
  209. package/dist/sfnt-subset.js +10 -3
  210. package/dist/structure.cjs +184 -0
  211. package/dist/structure.d.cts +12 -0
  212. package/dist/structure.d.ts +12 -0
  213. package/dist/structure.js +183 -0
  214. package/dist/tounicode.cjs +8 -3
  215. package/dist/tounicode.d.cts +2 -2
  216. package/dist/tounicode.d.ts +2 -2
  217. package/dist/tounicode.js +8 -3
  218. package/dist/util/base64.cjs +4 -4
  219. package/dist/util/base64.js +4 -4
  220. package/dist/winansi.cjs +1 -1
  221. package/dist/winansi.d.cts +1 -1
  222. package/dist/winansi.d.ts +1 -1
  223. package/dist/winansi.js +1 -1
  224. package/dist/write.cjs +464 -21
  225. package/dist/write.d.cts +4 -3
  226. package/dist/write.d.ts +4 -3
  227. package/dist/write.js +464 -20
  228. package/dist/xmp.cjs +46 -0
  229. package/dist/xmp.d.cts +14 -0
  230. package/dist/xmp.d.ts +14 -0
  231. package/dist/xmp.js +45 -0
  232. package/dist/xref.cjs +2 -2
  233. package/dist/xref.d.cts +3 -3
  234. package/dist/xref.d.ts +3 -3
  235. package/dist/xref.js +2 -2
  236. package/package.json +46 -31
  237. package/dist/image/png-encode.cjs +0 -64
  238. package/dist/image/png-encode.d.cts +0 -8
  239. package/dist/image/png-encode.d.ts +0 -8
  240. package/dist/image/png-encode.js +0 -63
package/dist/xmp.js ADDED
@@ -0,0 +1,45 @@
1
+ //#region src/xmp.ts
2
+ function readXmpMetadata(packet) {
3
+ return {
4
+ ...field(xmpValue(packet, "dc:title"), "title"),
5
+ ...field(xmpValue(packet, "dc:creator"), "author"),
6
+ ...field(xmpValue(packet, "dc:description"), "subject"),
7
+ ...field(xmpValue(packet, "xmp:CreatorTool"), "creator"),
8
+ ...field(xmpValue(packet, "pdf:Producer"), "producer"),
9
+ ...field(xmpValue(packet, "xmp:CreateDate"), "createdIso"),
10
+ ...field(xmpValue(packet, "xmp:ModifyDate"), "modifiedIso"),
11
+ ...keywordsOf(packet)
12
+ };
13
+ }
14
+ function xmpValue(packet, element) {
15
+ const match = new RegExp(`<${element}(?:\\s[^>]*)?>([\\s\\S]*?)</${element}>`).exec(packet);
16
+ if (match === null) return;
17
+ const inner = match[1] ?? "";
18
+ const items = listItems(inner);
19
+ if (items.length > 0) return items;
20
+ const text = inner.trim();
21
+ return text.length > 0 ? text : void 0;
22
+ }
23
+ function listItems(inner) {
24
+ const items = [];
25
+ const pattern = /<rdf:li(?:\s[^>]*)?>([\s\S]*?)<\/rdf:li>/g;
26
+ let match;
27
+ while ((match = pattern.exec(inner)) !== null) {
28
+ const text = (match[1] ?? "").trim();
29
+ if (text.length > 0) items.push(text);
30
+ }
31
+ return items;
32
+ }
33
+ function field(value, key) {
34
+ if (typeof value === "string") return { [key]: value };
35
+ if (Array.isArray(value) && value.length > 0) return { [key]: value.join(", ") };
36
+ return {};
37
+ }
38
+ function keywordsOf(packet) {
39
+ const match = (/* @__PURE__ */ new RegExp("<dc:subject(?:\\s[^>]*)?>([\\s\\S]*?)</dc:subject>")).exec(packet);
40
+ if (match === null) return {};
41
+ const items = listItems(match[1] ?? "");
42
+ return items.length > 0 ? { keywords: items } : {};
43
+ }
44
+ //#endregion
45
+ export { readXmpMetadata };
package/dist/xref.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_bytes_reader = require("./bytes/reader.cjs");
3
- const require_lexer = require("./lexer.cjs");
4
2
  const require_objects = require("./objects.cjs");
3
+ const require_bytes_reader = require("./bytes/reader.cjs");
5
4
  const require_filters = require("./filters.cjs");
5
+ const require_lexer = require("./lexer.cjs");
6
6
  const require_parse = require("./parse.cjs");
7
7
  //#region src/xref.ts
8
8
  const STARTXREF_BYTES = new TextEncoder().encode("startxref");
package/dist/xref.d.cts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
- import { PdfDict } from "./objects.cjs";
2
+ import { n as PdfDict } from "./objects-B7HdMeWS.cjs";
3
3
  //#region src/xref.d.ts
4
4
  interface XrefOffsetEntry {
5
- readonly type: 'offset';
5
+ readonly type: "offset";
6
6
  readonly offset: number;
7
7
  readonly gen: number;
8
8
  }
9
9
  interface XrefCompressedEntry {
10
- readonly type: 'compressed';
10
+ readonly type: "compressed";
11
11
  readonly streamObjNum: number;
12
12
  readonly indexInStream: number;
13
13
  }
package/dist/xref.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { PdfDict } from "./objects.js";
2
+ import { n as PdfDict } from "./objects-B7HdMeWS.js";
3
3
  //#region src/xref.d.ts
4
4
  interface XrefOffsetEntry {
5
- readonly type: 'offset';
5
+ readonly type: "offset";
6
6
  readonly offset: number;
7
7
  readonly gen: number;
8
8
  }
9
9
  interface XrefCompressedEntry {
10
- readonly type: 'compressed';
10
+ readonly type: "compressed";
11
11
  readonly streamObjNum: number;
12
12
  readonly indexInStream: number;
13
13
  }
package/dist/xref.js CHANGED
@@ -1,7 +1,7 @@
1
- import { ByteReader, isAsciiWhitespace } from "./bytes/reader.js";
2
- import { nextToken } from "./lexer.js";
3
1
  import { asArray, asDict, asNumber, dictGet, isName, pdfDict, pdfRef } from "./objects.js";
2
+ import { ByteReader, isAsciiWhitespace } from "./bytes/reader.js";
4
3
  import { decodeStream } from "./filters.js";
4
+ import { nextToken } from "./lexer.js";
5
5
  import { parseIndirectObject, parseValue } from "./parse.js";
6
6
  //#region src/xref.ts
7
7
  const STARTXREF_BYTES = new TextEncoder().encode("startxref");
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "pdf-parser.js",
3
- "version": "3.0.8",
3
+ "version": "4.5.1",
4
4
  "description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on its own codec-owned LayoutDocument item model and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/ExaDev/pdf-codec.git"
8
+ "url": "git+https://github.com/ExaDev/documents.js.git",
9
+ "directory": "packages/pdf-codec"
9
10
  },
10
- "homepage": "https://github.com/ExaDev/pdf-codec#readme",
11
+ "homepage": "https://github.com/ExaDev/documents.js/tree/main/packages/pdf-codec",
11
12
  "bugs": {
12
- "url": "https://github.com/ExaDev/pdf-codec/issues"
13
+ "url": "https://github.com/ExaDev/documents.js/issues"
13
14
  },
14
15
  "exports": {
15
16
  ".": {
@@ -20,6 +21,14 @@
20
21
  "import": "./dist/index.js",
21
22
  "require": "./dist/index.cjs"
22
23
  },
24
+ "./read": {
25
+ "types": {
26
+ "import": "./dist/read.d.ts",
27
+ "require": "./dist/read.d.cts"
28
+ },
29
+ "import": "./dist/read.js",
30
+ "require": "./dist/read.cjs"
31
+ },
23
32
  "./*": {
24
33
  "types": {
25
34
  "import": "./dist/*.d.ts",
@@ -32,6 +41,13 @@
32
41
  "main": "./dist/index.cjs",
33
42
  "module": "./dist/index.js",
34
43
  "types": "./dist/index.d.ts",
44
+ "typesVersions": {
45
+ "*": {
46
+ "read": [
47
+ "./dist/read.d.ts"
48
+ ]
49
+ }
50
+ },
35
51
  "files": [
36
52
  "dist"
37
53
  ],
@@ -56,42 +72,39 @@
56
72
  ],
57
73
  "license": "MIT",
58
74
  "dependencies": {
59
- "byte-codec": "^1.1.8",
60
- "document-schema.js": "^4.3.3",
61
- "fflate": "^0.8.3",
62
- "zod": "^4.4.3"
75
+ "byte-codec": "1.4.1",
76
+ "document-schema.js": "7.6.0",
77
+ "fflate": "0.8.3",
78
+ "zod": "4.4.3"
63
79
  },
64
80
  "devDependencies": {
65
- "@arethetypeswrong/cli": "^0.18.5",
66
- "@cloudflare/vitest-pool-workers": "^0.21.2",
67
- "@commitlint/cli": "^21.2.1",
68
- "@commitlint/config-conventional": "^21.2.0",
69
- "@eslint/js": "^10.0.1",
70
- "@exadev/eslint-config": "^2.1.0",
71
- "@semantic-release/changelog": "^7.0.0",
72
- "@semantic-release/git": "^11.0.1",
73
- "@types/node": "^26.1.1",
74
- "@vitest/coverage-v8": "^4.1.10",
75
- "eslint": "^10.8.0",
76
- "globals": "^17.8.0",
77
- "husky": "^9.1.7",
78
- "lint-staged": "^17.2.0",
79
- "publint": "^0.3.21",
80
- "semantic-release": "^25.0.8",
81
- "tsdown": "^0.22.13",
82
- "turbo": "^2.10.8",
83
- "typescript": "^6.0.3",
84
- "typescript-eslint": "^8.65.0",
85
- "vitest": "^4.1.10"
81
+ "@arethetypeswrong/cli": "0.18.5",
82
+ "@cloudflare/vitest-pool-workers": "0.21.2",
83
+ "@stryker-mutator/core": "10.0.0",
84
+ "@stryker-mutator/typescript-checker": "10.0.0",
85
+ "@stryker-mutator/vitest-runner": "10.0.0",
86
+ "@types/node": "26.2.0",
87
+ "@vitest/coverage-v8": "4.1.11",
88
+ "eslint": "10.8.1",
89
+ "husky": "9.1.7",
90
+ "jiti": "2.7.0",
91
+ "publint": "0.3.22",
92
+ "semantic-release": "25.0.9",
93
+ "tsdown": "0.22.14",
94
+ "turbo": "2.10.8",
95
+ "typescript": "6.0.3",
96
+ "typescript-eslint": "8.66.0",
97
+ "vitest": "4.1.11"
86
98
  },
87
99
  "scripts": {
88
100
  "build": "turbo run _build",
89
101
  "_build": "tsdown",
90
102
  "lint": "turbo run _lint",
91
103
  "_lint": "eslint . --fix --cache --max-warnings 0",
92
- "typecheck": "turbo run _typecheck _typecheck:node",
104
+ "typecheck": "turbo run _typecheck _typecheck:node _typecheck:attw",
93
105
  "_typecheck": "tsc -p tsconfig.json",
94
106
  "_typecheck:node": "tsc -p tsconfig.node.json",
107
+ "_typecheck:attw": "attw --pack",
95
108
  "test": "turbo run _test",
96
109
  "_test": "vitest run --project unit",
97
110
  "test:workers": "turbo run _test:workers",
@@ -99,10 +112,12 @@
99
112
  "test:watch": "vitest --project unit",
100
113
  "test:coverage": "turbo run _test:coverage",
101
114
  "_test:coverage": "vitest run --project unit --coverage",
115
+ "test:mutation": "turbo run _test:mutation",
116
+ "_test:mutation": "stryker run stryker.config.mjs",
102
117
  "test:corpus": "turbo run _test:corpus",
103
118
  "_test:corpus": "vitest run --project corpus",
104
119
  "test:smoke": "turbo run _test:smoke",
105
- "_test:smoke": "tsdown && vitest run --project smoke",
120
+ "_test:smoke": "vitest run --project smoke",
106
121
  "release": "semantic-release"
107
122
  }
108
123
  }
@@ -1,64 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_bytes_crc32 = require("../bytes/crc32.cjs");
3
- const require_bytes_writer = require("../bytes/writer.cjs");
4
- const require_bytes_flate = require("../bytes/flate.cjs");
5
- const require_image_png_filter = require("./png-filter.cjs");
6
- //#region src/image/png-encode.ts
7
- const PNG_SIGNATURE = new Uint8Array([
8
- 137,
9
- 80,
10
- 78,
11
- 71,
12
- 13,
13
- 10,
14
- 26,
15
- 10
16
- ]);
17
- function u32be(value) {
18
- const bytes = /* @__PURE__ */ new Uint8Array(4);
19
- new DataView(bytes.buffer).setUint32(0, value);
20
- return bytes;
21
- }
22
- function writeChunk(writer, type, data) {
23
- const typeBytes = new TextEncoder().encode(type);
24
- writer.writeBytes(u32be(data.length));
25
- writer.writeBytes(typeBytes);
26
- writer.writeBytes(data);
27
- writer.writeBytes(u32be(require_bytes_crc32.crc32(require_bytes_writer.concatBytes([typeBytes, data]))));
28
- }
29
- function colorTypeFor(image) {
30
- if (image.channels === 1) return image.alpha === void 0 ? 0 : 4;
31
- return image.alpha === void 0 ? 2 : 6;
32
- }
33
- function encodePng(image, options = {}) {
34
- const { width, height, channels, data, alpha } = image;
35
- const outChannels = alpha === void 0 ? channels : channels + 1;
36
- const bytesPerRow = width * outChannels;
37
- const pixelCount = width * height;
38
- const interleaved = new Uint8Array(pixelCount * outChannels);
39
- for (let i = 0; i < pixelCount; i++) {
40
- const srcBase = i * channels;
41
- const dstBase = i * outChannels;
42
- for (let c = 0; c < channels; c++) interleaved[dstBase + c] = data[srcBase + c];
43
- if (alpha !== void 0) interleaved[dstBase + channels] = alpha[i];
44
- }
45
- const filtered = require_image_png_filter.filterScanlines(interleaved, height, bytesPerRow, outChannels, options.filter ?? "adaptive");
46
- const compressed = require_bytes_flate.deflate(filtered);
47
- const ihdr = /* @__PURE__ */ new Uint8Array(13);
48
- const ihdrView = new DataView(ihdr.buffer);
49
- ihdrView.setUint32(0, width);
50
- ihdrView.setUint32(4, height);
51
- ihdr[8] = 8;
52
- ihdr[9] = colorTypeFor(image);
53
- ihdr[10] = 0;
54
- ihdr[11] = 0;
55
- ihdr[12] = 0;
56
- const writer = new require_bytes_writer.ByteWriter();
57
- writer.writeBytes(PNG_SIGNATURE);
58
- writeChunk(writer, "IHDR", ihdr);
59
- writeChunk(writer, "IDAT", compressed);
60
- writeChunk(writer, "IEND", /* @__PURE__ */ new Uint8Array(0));
61
- return writer.toBytes();
62
- }
63
- //#endregion
64
- exports.encodePng = encodePng;
@@ -1,8 +0,0 @@
1
- import { RawImage } from "./png-decode.cjs";
2
- //#region src/image/png-encode.d.ts
3
- interface PngEncodeOptions {
4
- readonly filter?: 'none' | 'adaptive';
5
- }
6
- declare function encodePng(image: RawImage, options?: PngEncodeOptions): Uint8Array<ArrayBuffer>;
7
- //#endregion
8
- export { PngEncodeOptions, encodePng };
@@ -1,8 +0,0 @@
1
- import { RawImage } from "./png-decode.js";
2
- //#region src/image/png-encode.d.ts
3
- interface PngEncodeOptions {
4
- readonly filter?: 'none' | 'adaptive';
5
- }
6
- declare function encodePng(image: RawImage, options?: PngEncodeOptions): Uint8Array<ArrayBuffer>;
7
- //#endregion
8
- export { PngEncodeOptions, encodePng };
@@ -1,63 +0,0 @@
1
- import { crc32 } from "../bytes/crc32.js";
2
- import { ByteWriter, concatBytes } from "../bytes/writer.js";
3
- import { deflate } from "../bytes/flate.js";
4
- import { filterScanlines } from "./png-filter.js";
5
- //#region src/image/png-encode.ts
6
- const PNG_SIGNATURE = new Uint8Array([
7
- 137,
8
- 80,
9
- 78,
10
- 71,
11
- 13,
12
- 10,
13
- 26,
14
- 10
15
- ]);
16
- function u32be(value) {
17
- const bytes = /* @__PURE__ */ new Uint8Array(4);
18
- new DataView(bytes.buffer).setUint32(0, value);
19
- return bytes;
20
- }
21
- function writeChunk(writer, type, data) {
22
- const typeBytes = new TextEncoder().encode(type);
23
- writer.writeBytes(u32be(data.length));
24
- writer.writeBytes(typeBytes);
25
- writer.writeBytes(data);
26
- writer.writeBytes(u32be(crc32(concatBytes([typeBytes, data]))));
27
- }
28
- function colorTypeFor(image) {
29
- if (image.channels === 1) return image.alpha === void 0 ? 0 : 4;
30
- return image.alpha === void 0 ? 2 : 6;
31
- }
32
- function encodePng(image, options = {}) {
33
- const { width, height, channels, data, alpha } = image;
34
- const outChannels = alpha === void 0 ? channels : channels + 1;
35
- const bytesPerRow = width * outChannels;
36
- const pixelCount = width * height;
37
- const interleaved = new Uint8Array(pixelCount * outChannels);
38
- for (let i = 0; i < pixelCount; i++) {
39
- const srcBase = i * channels;
40
- const dstBase = i * outChannels;
41
- for (let c = 0; c < channels; c++) interleaved[dstBase + c] = data[srcBase + c];
42
- if (alpha !== void 0) interleaved[dstBase + channels] = alpha[i];
43
- }
44
- const filtered = filterScanlines(interleaved, height, bytesPerRow, outChannels, options.filter ?? "adaptive");
45
- const compressed = deflate(filtered);
46
- const ihdr = /* @__PURE__ */ new Uint8Array(13);
47
- const ihdrView = new DataView(ihdr.buffer);
48
- ihdrView.setUint32(0, width);
49
- ihdrView.setUint32(4, height);
50
- ihdr[8] = 8;
51
- ihdr[9] = colorTypeFor(image);
52
- ihdr[10] = 0;
53
- ihdr[11] = 0;
54
- ihdr[12] = 0;
55
- const writer = new ByteWriter();
56
- writer.writeBytes(PNG_SIGNATURE);
57
- writeChunk(writer, "IHDR", ihdr);
58
- writeChunk(writer, "IDAT", compressed);
59
- writeChunk(writer, "IEND", /* @__PURE__ */ new Uint8Array(0));
60
- return writer.toBytes();
61
- }
62
- //#endregion
63
- export { encodePng };