reamkit 0.1.0-alpha.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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -0
  3. package/dist/esm/bidi/algorithm.d.ts +9 -0
  4. package/dist/esm/bidi/algorithm.js +458 -0
  5. package/dist/esm/bidi/char-types.d.ts +2 -0
  6. package/dist/esm/bidi/char-types.js +439 -0
  7. package/dist/esm/bidi/index.d.ts +14 -0
  8. package/dist/esm/bidi/index.js +25 -0
  9. package/dist/esm/converter/docx-to-pdf.d.ts +15 -0
  10. package/dist/esm/converter/docx-to-pdf.js +227 -0
  11. package/dist/esm/converter/index.d.ts +4 -0
  12. package/dist/esm/converter/index.js +2 -0
  13. package/dist/esm/converter/xlsx-to-pdf.d.ts +13 -0
  14. package/dist/esm/converter/xlsx-to-pdf.js +515 -0
  15. package/dist/esm/crypto/asn1.d.ts +23 -0
  16. package/dist/esm/crypto/asn1.js +123 -0
  17. package/dist/esm/crypto/cms.d.ts +9 -0
  18. package/dist/esm/crypto/cms.js +34 -0
  19. package/dist/esm/crypto/index.d.ts +2 -0
  20. package/dist/esm/crypto/index.js +1 -0
  21. package/dist/esm/document-model/index.d.ts +1 -0
  22. package/dist/esm/document-model/index.js +0 -0
  23. package/dist/esm/document-model/types.d.ts +403 -0
  24. package/dist/esm/font/arabic-joining.d.ts +4 -0
  25. package/dist/esm/font/arabic-joining.js +97 -0
  26. package/dist/esm/font/binary-reader.d.ts +13 -0
  27. package/dist/esm/font/binary-reader.js +44 -0
  28. package/dist/esm/font/font-registry.d.ts +19 -0
  29. package/dist/esm/font/font-registry.js +39 -0
  30. package/dist/esm/font/index.d.ts +7 -0
  31. package/dist/esm/font/opentype-layout.d.ts +21 -0
  32. package/dist/esm/font/opentype-layout.js +329 -0
  33. package/dist/esm/font/ttf-parser.d.ts +29 -0
  34. package/dist/esm/font/ttf-parser.js +290 -0
  35. package/dist/esm/font/ttf-subset.d.ts +3 -0
  36. package/dist/esm/font/ttf-subset.js +201 -0
  37. package/dist/esm/fonts/index.d.ts +2 -0
  38. package/dist/esm/fonts/remote-fonts.d.ts +13 -0
  39. package/dist/esm/fonts/remote-fonts.js +94 -0
  40. package/dist/esm/hyphenation/index.d.ts +10 -0
  41. package/dist/esm/hyphenation/index.js +38 -0
  42. package/dist/esm/hyphenation/liang.d.ts +10 -0
  43. package/dist/esm/hyphenation/liang.js +79 -0
  44. package/dist/esm/hyphenation/patterns-en-us.d.ts +2 -0
  45. package/dist/esm/hyphenation/patterns-en-us.js +5 -0
  46. package/dist/esm/hyphenation/patterns-ru.d.ts +2 -0
  47. package/dist/esm/hyphenation/patterns-ru.js +5 -0
  48. package/dist/esm/index.d.ts +12 -0
  49. package/dist/esm/index.js +13 -0
  50. package/dist/esm/line-breaker/index.d.ts +2 -0
  51. package/dist/esm/line-breaker/knuth-plass.d.ts +30 -0
  52. package/dist/esm/line-breaker/knuth-plass.js +172 -0
  53. package/dist/esm/numbering/index.d.ts +1 -0
  54. package/dist/esm/numbering/state.d.ts +6 -0
  55. package/dist/esm/numbering/state.js +83 -0
  56. package/dist/esm/ooxml/drawingml/chart-parser.d.ts +3 -0
  57. package/dist/esm/ooxml/drawingml/chart-parser.js +218 -0
  58. package/dist/esm/ooxml/drawingml/colors.d.ts +17 -0
  59. package/dist/esm/ooxml/drawingml/colors.js +125 -0
  60. package/dist/esm/ooxml/drawingml/theme-parser.d.ts +1 -0
  61. package/dist/esm/ooxml/drawingml/theme-parser.js +55 -0
  62. package/dist/esm/ooxml/index.d.ts +1 -0
  63. package/dist/esm/ooxml/math/omml-parser.d.ts +4 -0
  64. package/dist/esm/ooxml/math/omml-parser.js +217 -0
  65. package/dist/esm/ooxml/spreadsheet/cell-reference.d.ts +6 -0
  66. package/dist/esm/ooxml/spreadsheet/cell-reference.js +26 -0
  67. package/dist/esm/ooxml/spreadsheet/defined-name-ref.d.ts +11 -0
  68. package/dist/esm/ooxml/spreadsheet/defined-name-ref.js +64 -0
  69. package/dist/esm/ooxml/spreadsheet/index.d.ts +12 -0
  70. package/dist/esm/ooxml/spreadsheet/index.js +7 -0
  71. package/dist/esm/ooxml/spreadsheet/number-format.d.ts +1 -0
  72. package/dist/esm/ooxml/spreadsheet/number-format.js +438 -0
  73. package/dist/esm/ooxml/spreadsheet/shared-strings-parser.d.ts +1 -0
  74. package/dist/esm/ooxml/spreadsheet/shared-strings-parser.js +47 -0
  75. package/dist/esm/ooxml/spreadsheet/styles-parser.d.ts +52 -0
  76. package/dist/esm/ooxml/spreadsheet/styles-parser.js +225 -0
  77. package/dist/esm/ooxml/spreadsheet/workbook-parser.d.ts +16 -0
  78. package/dist/esm/ooxml/spreadsheet/workbook-parser.js +90 -0
  79. package/dist/esm/ooxml/spreadsheet/worksheet-parser.d.ts +60 -0
  80. package/dist/esm/ooxml/spreadsheet/worksheet-parser.js +311 -0
  81. package/dist/esm/ooxml/wordproc/document-parser.d.ts +9 -0
  82. package/dist/esm/ooxml/wordproc/document-parser.js +274 -0
  83. package/dist/esm/ooxml/wordproc/drawing-parser.d.ts +33 -0
  84. package/dist/esm/ooxml/wordproc/drawing-parser.js +374 -0
  85. package/dist/esm/ooxml/wordproc/font-table.d.ts +15 -0
  86. package/dist/esm/ooxml/wordproc/font-table.js +82 -0
  87. package/dist/esm/ooxml/wordproc/index.d.ts +10 -0
  88. package/dist/esm/ooxml/wordproc/index.js +9 -0
  89. package/dist/esm/ooxml/wordproc/numbering-parser.d.ts +3 -0
  90. package/dist/esm/ooxml/wordproc/numbering-parser.js +89 -0
  91. package/dist/esm/ooxml/wordproc/paragraph-properties.d.ts +2 -0
  92. package/dist/esm/ooxml/wordproc/paragraph-properties.js +85 -0
  93. package/dist/esm/ooxml/wordproc/po-helpers.d.ts +14 -0
  94. package/dist/esm/ooxml/wordproc/po-helpers.js +76 -0
  95. package/dist/esm/ooxml/wordproc/po-to-flat.d.ts +2 -0
  96. package/dist/esm/ooxml/wordproc/po-to-flat.js +28 -0
  97. package/dist/esm/ooxml/wordproc/run-properties.d.ts +2 -0
  98. package/dist/esm/ooxml/wordproc/run-properties.js +82 -0
  99. package/dist/esm/ooxml/wordproc/settings-parser.d.ts +5 -0
  100. package/dist/esm/ooxml/wordproc/settings-parser.js +26 -0
  101. package/dist/esm/ooxml/wordproc/styles-parser.d.ts +3 -0
  102. package/dist/esm/ooxml/wordproc/styles-parser.js +67 -0
  103. package/dist/esm/ooxml/wordproc/table-parser.d.ts +3 -0
  104. package/dist/esm/ooxml/wordproc/table-parser.js +162 -0
  105. package/dist/esm/ooxml/wordproc/text-extractor.d.ts +1 -0
  106. package/dist/esm/ooxml/wordproc/text-extractor.js +1 -0
  107. package/dist/esm/ooxml/wordproc/xml-helpers.d.ts +9 -0
  108. package/dist/esm/ooxml/wordproc/xml-helpers.js +36 -0
  109. package/dist/esm/opc/core-properties.d.ts +11 -0
  110. package/dist/esm/opc/core-properties.js +51 -0
  111. package/dist/esm/opc/index.d.ts +5 -0
  112. package/dist/esm/opc/index.js +3 -0
  113. package/dist/esm/opc/package.d.ts +26 -0
  114. package/dist/esm/opc/package.js +113 -0
  115. package/dist/esm/opc/relationship-types.d.ts +3 -0
  116. package/dist/esm/opc/relationship-types.js +4 -0
  117. package/dist/esm/opc/relationships.d.ts +7 -0
  118. package/dist/esm/opc/relationships.js +28 -0
  119. package/dist/esm/pdf/arc-to-bezier.d.ts +5 -0
  120. package/dist/esm/pdf/arc-to-bezier.js +58 -0
  121. package/dist/esm/pdf/builtin-fonts.d.ts +2 -0
  122. package/dist/esm/pdf/chart-geometry.d.ts +64 -0
  123. package/dist/esm/pdf/chart-geometry.js +674 -0
  124. package/dist/esm/pdf/cid-font.d.ts +15 -0
  125. package/dist/esm/pdf/cid-font.js +174 -0
  126. package/dist/esm/pdf/embedded-file.d.ts +11 -0
  127. package/dist/esm/pdf/embedded-file.js +23 -0
  128. package/dist/esm/pdf/icc-profile.d.ts +1 -0
  129. package/dist/esm/pdf/icc-profile.js +166 -0
  130. package/dist/esm/pdf/image-xobject.d.ts +13 -0
  131. package/dist/esm/pdf/image-xobject.js +335 -0
  132. package/dist/esm/pdf/index.d.ts +11 -0
  133. package/dist/esm/pdf/index.js +5 -0
  134. package/dist/esm/pdf/math-layout.d.ts +45 -0
  135. package/dist/esm/pdf/math-layout.js +1138 -0
  136. package/dist/esm/pdf/objects.d.ts +32 -0
  137. package/dist/esm/pdf/objects.js +54 -0
  138. package/dist/esm/pdf/preset-geometry.d.ts +6 -0
  139. package/dist/esm/pdf/preset-geometry.js +199 -0
  140. package/dist/esm/pdf/serialize.d.ts +3 -0
  141. package/dist/esm/pdf/serialize.js +54 -0
  142. package/dist/esm/pdf/signature.d.ts +25 -0
  143. package/dist/esm/pdf/signature.js +126 -0
  144. package/dist/esm/pdf/struct-tree.d.ts +31 -0
  145. package/dist/esm/pdf/struct-tree.js +109 -0
  146. package/dist/esm/pdf/styled-page-renderer.d.ts +43 -0
  147. package/dist/esm/pdf/styled-page-renderer.js +2317 -0
  148. package/dist/esm/pdf/text-encoding.d.ts +2 -0
  149. package/dist/esm/pdf/text-page-renderer.d.ts +16 -0
  150. package/dist/esm/pdf/text-page-renderer.js +4 -0
  151. package/dist/esm/pdf/vector-graphics.d.ts +46 -0
  152. package/dist/esm/pdf/vector-graphics.js +103 -0
  153. package/dist/esm/pdf/writer.d.ts +10 -0
  154. package/dist/esm/pdf/writer.js +81 -0
  155. package/dist/esm/pdf/xmp.d.ts +13 -0
  156. package/dist/esm/pdf/xmp.js +38 -0
  157. package/dist/esm/style-cascade/index.d.ts +3 -0
  158. package/dist/esm/style-cascade/resolver.d.ts +4 -0
  159. package/dist/esm/style-cascade/resolver.js +96 -0
  160. package/dist/esm/style-cascade/types.d.ts +29 -0
  161. package/dist/esm/style-cascade/types.js +26 -0
  162. package/package.json +90 -0
@@ -0,0 +1,335 @@
1
+ import { name, stream } from "./objects.js";
2
+ import { unzlibSync, zlibSync } from "fflate";
3
+ //#region src/pdf/image-xobject.ts
4
+ function detectImageFormat(bytes) {
5
+ if (bytes.length >= 3 && bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) return "jpeg";
6
+ if (bytes.length >= 8 && bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71 && bytes[4] === 13 && bytes[5] === 10 && bytes[6] === 26 && bytes[7] === 10) return "png";
7
+ if (bytes.length >= 12 && bytes[0] === 0 && bytes[1] === 0 && bytes[2] === 0 && bytes[3] === 12 && bytes[4] === 106 && bytes[5] === 80 && bytes[6] === 32 && bytes[7] === 32 && bytes[8] === 13 && bytes[9] === 10 && bytes[10] === 135 && bytes[11] === 10) return "jpeg2000";
8
+ if (bytes.length >= 4 && bytes[0] === 255 && bytes[1] === 79 && bytes[2] === 255 && bytes[3] === 81) return "jpeg2000";
9
+ return null;
10
+ }
11
+ function embedImage(doc, bytes, options = {}) {
12
+ const format = detectImageFormat(bytes);
13
+ if (format === "jpeg") return embedJpeg(doc, bytes);
14
+ if (format === "png") return embedPng(doc, bytes, options);
15
+ if (format === "jpeg2000") return embedJpeg2000(doc, bytes);
16
+ throw new Error("Unsupported image format");
17
+ }
18
+ function embedJpeg2000(doc, bytes) {
19
+ const { width, height } = readJpeg2000Info(bytes);
20
+ return {
21
+ ref: doc.add(stream({
22
+ Type: name("XObject"),
23
+ Subtype: name("Image"),
24
+ Width: width,
25
+ Height: height,
26
+ Filter: name("JPXDecode")
27
+ }, bytes)),
28
+ widthPx: width,
29
+ heightPx: height
30
+ };
31
+ }
32
+ function readU32(b, o) {
33
+ return b[o] * 16777216 + (b[o + 1] << 16) + (b[o + 2] << 8) + b[o + 3];
34
+ }
35
+ var boxType = (b, o) => String.fromCharCode(b[o], b[o + 1], b[o + 2], b[o + 3]);
36
+ function readJpeg2000Info(bytes) {
37
+ if (bytes[0] === 255 && bytes[1] === 79) return readSiz(bytes, 2);
38
+ let p = 0;
39
+ while (p + 8 <= bytes.length) {
40
+ let len = readU32(bytes, p);
41
+ const type = boxType(bytes, p + 4);
42
+ let contentStart = p + 8;
43
+ if (len === 1) {
44
+ len = readU32(bytes, p + 12);
45
+ contentStart = p + 16;
46
+ }
47
+ const end = len === 0 ? bytes.length : p + len;
48
+ if (type === "jp2h") {
49
+ let q = contentStart;
50
+ while (q + 8 <= end) {
51
+ const clen = readU32(bytes, q);
52
+ if (boxType(bytes, q + 4) === "ihdr") return {
53
+ height: readU32(bytes, q + 8),
54
+ width: readU32(bytes, q + 12)
55
+ };
56
+ if (clen === 0) break;
57
+ q += clen;
58
+ }
59
+ }
60
+ if (len === 0) break;
61
+ p = end;
62
+ }
63
+ for (let i = 0; i + 22 < bytes.length; i++) if (bytes[i] === 255 && bytes[i + 1] === 81) return readSiz(bytes, i);
64
+ throw new Error("JPEG 2000: no ihdr/SIZ found");
65
+ }
66
+ function readSiz(bytes, sizOffset) {
67
+ const xsiz = readU32(bytes, sizOffset + 6);
68
+ const ysiz = readU32(bytes, sizOffset + 10);
69
+ const xo = readU32(bytes, sizOffset + 14);
70
+ const yo = readU32(bytes, sizOffset + 18);
71
+ const width = xsiz - xo;
72
+ const height = ysiz - yo;
73
+ if (width <= 0 || height <= 0) throw new Error("JPEG 2000: invalid SIZ dimensions");
74
+ return {
75
+ width,
76
+ height
77
+ };
78
+ }
79
+ function embedJpeg(doc, bytes) {
80
+ const info = readJpegInfo(bytes);
81
+ const colorSpace = info.numComponents === 1 ? "DeviceGray" : "DeviceRGB";
82
+ return {
83
+ ref: doc.add(stream({
84
+ Type: name("XObject"),
85
+ Subtype: name("Image"),
86
+ Width: info.width,
87
+ Height: info.height,
88
+ ColorSpace: name(colorSpace),
89
+ BitsPerComponent: info.precision,
90
+ Filter: name("DCTDecode")
91
+ }, bytes)),
92
+ widthPx: info.width,
93
+ heightPx: info.height
94
+ };
95
+ }
96
+ function readJpegInfo(bytes) {
97
+ if (bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216) throw new Error("Not a JPEG (missing SOI)");
98
+ let i = 2;
99
+ while (i + 9 < bytes.length) {
100
+ if (bytes[i] !== 255) {
101
+ i++;
102
+ continue;
103
+ }
104
+ let marker = bytes[i + 1];
105
+ while (marker === 255) {
106
+ i++;
107
+ marker = bytes[i + 1];
108
+ }
109
+ if (marker === 1 || marker >= 208 && marker <= 217) {
110
+ i += 2;
111
+ continue;
112
+ }
113
+ if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) return {
114
+ precision: bytes[i + 4],
115
+ height: bytes[i + 5] << 8 | bytes[i + 6],
116
+ width: bytes[i + 7] << 8 | bytes[i + 8],
117
+ numComponents: bytes[i + 9]
118
+ };
119
+ const length = bytes[i + 2] << 8 | bytes[i + 3];
120
+ i += 2 + length;
121
+ }
122
+ throw new Error("JPEG SOFn marker not found");
123
+ }
124
+ function embedPng(doc, bytes, options = {}) {
125
+ let decoded = decodePng(bytes);
126
+ if (options.flattenAlpha && decoded.smaskRaw) decoded = flattenAlphaOnWhite(decoded);
127
+ const compressedColor = zlibSync(decoded.raw);
128
+ const baseDict = {
129
+ Type: name("XObject"),
130
+ Subtype: name("Image"),
131
+ Width: decoded.width,
132
+ Height: decoded.height,
133
+ ColorSpace: name(decoded.colorSpace),
134
+ BitsPerComponent: decoded.bitsPerComponent,
135
+ Filter: name("FlateDecode")
136
+ };
137
+ let smaskRef;
138
+ if (decoded.smaskRaw) {
139
+ const compressedAlpha = zlibSync(decoded.smaskRaw);
140
+ smaskRef = doc.add(stream({
141
+ Type: name("XObject"),
142
+ Subtype: name("Image"),
143
+ Width: decoded.width,
144
+ Height: decoded.height,
145
+ ColorSpace: name("DeviceGray"),
146
+ BitsPerComponent: 8,
147
+ Filter: name("FlateDecode")
148
+ }, compressedAlpha));
149
+ }
150
+ const entries = { ...baseDict };
151
+ if (smaskRef) entries["SMask"] = smaskRef;
152
+ return {
153
+ ref: doc.add(stream(entries, compressedColor)),
154
+ widthPx: decoded.width,
155
+ heightPx: decoded.height
156
+ };
157
+ }
158
+ function decodePng(bytes) {
159
+ let width = 0;
160
+ let height = 0;
161
+ let bitDepth = 0;
162
+ let colorType = 0;
163
+ let interlaceMethod = 0;
164
+ const idatChunks = [];
165
+ let pos = 8;
166
+ while (pos + 12 <= bytes.length) {
167
+ const len = readU32BE(bytes, pos);
168
+ const type = chunkType(bytes, pos + 4);
169
+ const dataOff = pos + 8;
170
+ if (type === "IHDR") {
171
+ width = readU32BE(bytes, dataOff);
172
+ height = readU32BE(bytes, dataOff + 4);
173
+ bitDepth = bytes[dataOff + 8];
174
+ colorType = bytes[dataOff + 9];
175
+ interlaceMethod = bytes[dataOff + 12];
176
+ } else if (type === "IDAT") idatChunks.push(bytes.subarray(dataOff, dataOff + len));
177
+ else if (type === "IEND") break;
178
+ pos = dataOff + len + 4;
179
+ }
180
+ if (width === 0 || height === 0) throw new Error("PNG: missing IHDR");
181
+ if (idatChunks.length === 0) throw new Error("PNG: no IDAT");
182
+ if (interlaceMethod !== 0) throw new Error("PNG: interlaced not supported");
183
+ if (bitDepth !== 8) throw new Error(`PNG: bit depth ${bitDepth} not supported`);
184
+ const inflated = unzlibSync(concatBytes(idatChunks));
185
+ const channels = pngChannels(colorType);
186
+ if (channels === 0) throw new Error(`PNG color type ${colorType} not supported`);
187
+ const bpp = channels;
188
+ const scanlineBytes = width * bpp;
189
+ const expected = height * (1 + scanlineBytes);
190
+ if (inflated.length !== expected) throw new Error(`PNG: inflated size ${inflated.length} != expected ${expected} (interlaced or malformed)`);
191
+ const raw = new Uint8Array(height * scanlineBytes);
192
+ let prev = null;
193
+ for (let y = 0; y < height; y++) {
194
+ const inOff = y * (1 + scanlineBytes);
195
+ const filterType = inflated[inOff];
196
+ const decoded = new Uint8Array(scanlineBytes);
197
+ for (let x = 0; x < scanlineBytes; x++) {
198
+ const filt = inflated[inOff + 1 + x];
199
+ const a = x < bpp ? 0 : decoded[x - bpp];
200
+ const b = prev ? prev[x] : 0;
201
+ const c = !prev || x < bpp ? 0 : prev[x - bpp];
202
+ let v;
203
+ switch (filterType) {
204
+ case 0:
205
+ v = filt;
206
+ break;
207
+ case 1:
208
+ v = filt + a;
209
+ break;
210
+ case 2:
211
+ v = filt + b;
212
+ break;
213
+ case 3:
214
+ v = filt + Math.floor((a + b) / 2);
215
+ break;
216
+ case 4:
217
+ v = filt + paethPredictor(a, b, c);
218
+ break;
219
+ default: throw new Error(`PNG: unknown filter type ${filterType}`);
220
+ }
221
+ decoded[x] = v & 255;
222
+ }
223
+ raw.set(decoded, y * scanlineBytes);
224
+ prev = decoded;
225
+ }
226
+ return splitChannels(width, height, colorType, raw);
227
+ }
228
+ function flattenAlphaOnWhite(decoded) {
229
+ const alpha = decoded.smaskRaw;
230
+ if (!alpha) return decoded;
231
+ const channels = decoded.colorSpace === "DeviceRGB" ? 3 : 1;
232
+ const pixelCount = decoded.width * decoded.height;
233
+ const out = new Uint8Array(pixelCount * channels);
234
+ for (let i = 0; i < pixelCount; i++) {
235
+ const a = alpha[i] / 255;
236
+ for (let c = 0; c < channels; c++) {
237
+ const src = decoded.raw[i * channels + c];
238
+ out[i * channels + c] = Math.round(src * a + 255 * (1 - a));
239
+ }
240
+ }
241
+ return {
242
+ width: decoded.width,
243
+ height: decoded.height,
244
+ raw: out,
245
+ colorSpace: decoded.colorSpace,
246
+ bitsPerComponent: decoded.bitsPerComponent
247
+ };
248
+ }
249
+ function splitChannels(width, height, colorType, raw) {
250
+ const pixelCount = width * height;
251
+ if (colorType === 0) return {
252
+ width,
253
+ height,
254
+ raw,
255
+ colorSpace: "DeviceGray",
256
+ bitsPerComponent: 8
257
+ };
258
+ if (colorType === 2) return {
259
+ width,
260
+ height,
261
+ raw,
262
+ colorSpace: "DeviceRGB",
263
+ bitsPerComponent: 8
264
+ };
265
+ if (colorType === 4) {
266
+ const gray = new Uint8Array(pixelCount);
267
+ const alpha = new Uint8Array(pixelCount);
268
+ for (let i = 0; i < pixelCount; i++) {
269
+ gray[i] = raw[i * 2];
270
+ alpha[i] = raw[i * 2 + 1];
271
+ }
272
+ return {
273
+ width,
274
+ height,
275
+ raw: gray,
276
+ colorSpace: "DeviceGray",
277
+ bitsPerComponent: 8,
278
+ smaskRaw: alpha
279
+ };
280
+ }
281
+ if (colorType === 6) {
282
+ const rgb = new Uint8Array(pixelCount * 3);
283
+ const alpha = new Uint8Array(pixelCount);
284
+ for (let i = 0; i < pixelCount; i++) {
285
+ rgb[i * 3] = raw[i * 4];
286
+ rgb[i * 3 + 1] = raw[i * 4 + 1];
287
+ rgb[i * 3 + 2] = raw[i * 4 + 2];
288
+ alpha[i] = raw[i * 4 + 3];
289
+ }
290
+ return {
291
+ width,
292
+ height,
293
+ raw: rgb,
294
+ colorSpace: "DeviceRGB",
295
+ bitsPerComponent: 8,
296
+ smaskRaw: alpha
297
+ };
298
+ }
299
+ throw new Error(`PNG color type ${colorType} not supported (palette/indexed?)`);
300
+ }
301
+ function pngChannels(colorType) {
302
+ if (colorType === 0) return 1;
303
+ if (colorType === 2) return 3;
304
+ if (colorType === 4) return 2;
305
+ if (colorType === 6) return 4;
306
+ return 0;
307
+ }
308
+ function paethPredictor(a, b, c) {
309
+ const p = a + b - c;
310
+ const pa = Math.abs(p - a);
311
+ const pb = Math.abs(p - b);
312
+ const pc = Math.abs(p - c);
313
+ if (pa <= pb && pa <= pc) return a;
314
+ if (pb <= pc) return b;
315
+ return c;
316
+ }
317
+ function readU32BE(bytes, offset) {
318
+ return bytes[offset] * 16777216 + (bytes[offset + 1] << 16 | bytes[offset + 2] << 8 | bytes[offset + 3]);
319
+ }
320
+ function chunkType(bytes, offset) {
321
+ return String.fromCharCode(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]);
322
+ }
323
+ function concatBytes(parts) {
324
+ let total = 0;
325
+ for (const p of parts) total += p.length;
326
+ const out = new Uint8Array(total);
327
+ let off = 0;
328
+ for (const p of parts) {
329
+ out.set(p, off);
330
+ off += p.length;
331
+ }
332
+ return out;
333
+ }
334
+ //#endregion
335
+ export { detectImageFormat, embedImage };
@@ -0,0 +1,11 @@
1
+ export { renderPlainTextPdf } from './text-page-renderer.js';
2
+ export type { TextRenderOptions, FontInput } from './text-page-renderer.js';
3
+ export { renderStyledPdf } from './styled-page-renderer.js';
4
+ export type { DocumentInfo, StyledRenderOptions, PdfALevel } from './styled-page-renderer.js';
5
+ export { signPdf } from './signature.js';
6
+ export type { SignaturePlaceholder, SignerCredentials, SignatureOptions } from './signature.js';
7
+ export type { AttachedFile, AFRelationship } from './embedded-file.js';
8
+ export { embedTtfFont } from './cid-font.js';
9
+ export type { EmbeddedFont } from './cid-font.js';
10
+ export { embedImage, detectImageFormat } from './image-xobject.js';
11
+ export type { EmbeddedImage, ImageFormat } from './image-xobject.js';
@@ -0,0 +1,5 @@
1
+ import "./cid-font.js";
2
+ import "./text-page-renderer.js";
3
+ import "./image-xobject.js";
4
+ import "./signature.js";
5
+ import "./styled-page-renderer.js";
@@ -0,0 +1,45 @@
1
+ import { MathNode } from '../document-model/index.js';
2
+ import { PathSegment } from './vector-graphics.js';
3
+ export type MathVariant = 'regular' | 'italic' | 'bold' | 'boldItalic';
4
+ export interface MathGlyphItem {
5
+ readonly kind: 'glyph';
6
+ readonly x: number;
7
+ readonly y: number;
8
+ readonly text: string;
9
+ readonly variant: MathVariant;
10
+ readonly sizePt: number;
11
+ }
12
+ export interface MathRuleItem {
13
+ readonly kind: 'rule';
14
+ readonly x: number;
15
+ readonly y: number;
16
+ readonly w: number;
17
+ readonly h: number;
18
+ }
19
+ export interface MathPathItem {
20
+ readonly kind: 'path';
21
+ readonly segments: ReadonlyArray<PathSegment>;
22
+ readonly strokeWidthPt?: number;
23
+ readonly fill?: boolean;
24
+ }
25
+ export type MathDrawItem = MathGlyphItem | MathRuleItem | MathPathItem;
26
+ export interface MathBox {
27
+ readonly width: number;
28
+ readonly ascent: number;
29
+ readonly descent: number;
30
+ readonly items: ReadonlyArray<MathDrawItem>;
31
+ }
32
+ export type MeasureMath = (text: string, sizePt: number, variant: MathVariant) => number;
33
+ export interface MathCtx {
34
+ readonly sizePt: number;
35
+ }
36
+ export declare function variantStyle(v: MathVariant): {
37
+ bold: boolean;
38
+ italic: boolean;
39
+ };
40
+ export declare function layoutMath(node: MathNode, ctx: MathCtx, measure: MeasureMath): MathBox;
41
+ export declare function shiftItems(items: ReadonlyArray<MathDrawItem>, dx: number, dy: number): Array<MathDrawItem>;
42
+ export declare function mathGlyphSegments(node: MathNode): Array<{
43
+ variant: MathVariant;
44
+ text: string;
45
+ }>;