pdfv8 0.0.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 (76) hide show
  1. package/.cursor/settings.json +7 -0
  2. package/CHANGELOG.md +148 -0
  3. package/LICENSE +8 -0
  4. package/README.md +195 -0
  5. package/bun.lock +1549 -0
  6. package/js/pdfkit.es.js +498 -0
  7. package/js/pdfkit.es.js.map +1 -0
  8. package/js/pdfkit.js +500 -0
  9. package/js/pdfkit.js.map +1 -0
  10. package/js/pdfkit.standalone.js +49525 -0
  11. package/js/virtual-fs.js +95 -0
  12. package/jsconfig.json +13 -0
  13. package/package.json +102 -0
  14. package/scripts/gen-afm-data.mjs +41 -0
  15. package/tsconfig.build.json +23 -0
  16. package/types/abstract_reference.d.ts +4 -0
  17. package/types/crypto/aes.d.ts +2 -0
  18. package/types/crypto/md5.d.ts +2 -0
  19. package/types/crypto/random.d.ts +1 -0
  20. package/types/crypto/rc4.d.ts +1 -0
  21. package/types/crypto/sha256.d.ts +1 -0
  22. package/types/data.d.ts +29 -0
  23. package/types/document.d.ts +25 -0
  24. package/types/font/afm.d.ts +21 -0
  25. package/types/font/afm_data.generated.d.ts +1 -0
  26. package/types/font/embedded.d.ts +12 -0
  27. package/types/font/standard.d.ts +12 -0
  28. package/types/font.d.ts +10 -0
  29. package/types/font_factory.d.ts +6 -0
  30. package/types/gradient.d.ts +23 -0
  31. package/types/image/jpeg.d.ts +5 -0
  32. package/types/image/png.d.ts +9 -0
  33. package/types/image.d.ts +6 -0
  34. package/types/jest.custom-matchers.d.ts +28 -0
  35. package/types/line_wrapper.d.ts +10 -0
  36. package/types/metadata.d.ts +9 -0
  37. package/types/mixins/acroform.d.ts +48 -0
  38. package/types/mixins/annotations.d.ts +17 -0
  39. package/types/mixins/attachments.d.ts +17 -0
  40. package/types/mixins/color.d.ts +39 -0
  41. package/types/mixins/fonts.d.ts +19 -0
  42. package/types/mixins/images.d.ts +6 -0
  43. package/types/mixins/markings.d.ts +19 -0
  44. package/types/mixins/metadata.d.ts +7 -0
  45. package/types/mixins/outline.d.ts +5 -0
  46. package/types/mixins/pdfa.d.ts +9 -0
  47. package/types/mixins/pdfua.d.ts +7 -0
  48. package/types/mixins/subsets.d.ts +5 -0
  49. package/types/mixins/table.d.ts +11 -0
  50. package/types/mixins/text.d.ts +31 -0
  51. package/types/mixins/vector.d.ts +43 -0
  52. package/types/name_tree.d.ts +7 -0
  53. package/types/number_tree.d.ts +7 -0
  54. package/types/object.d.ts +5 -0
  55. package/types/outline.d.ts +20 -0
  56. package/types/page.d.ts +27 -0
  57. package/types/path.d.ts +4 -0
  58. package/types/pattern.d.ts +12 -0
  59. package/types/reference.d.ts +9 -0
  60. package/types/saslprep/index.d.ts +9 -0
  61. package/types/security.d.ts +12 -0
  62. package/types/spotcolor.d.ts +4 -0
  63. package/types/structure_annotation.d.ts +4 -0
  64. package/types/structure_content.d.ts +5 -0
  65. package/types/structure_element.d.ts +15 -0
  66. package/types/table/accessibility.d.ts +38 -0
  67. package/types/table/index.d.ts +23 -0
  68. package/types/table/normalize.d.ts +41 -0
  69. package/types/table/render.d.ts +10 -0
  70. package/types/table/size.d.ts +23 -0
  71. package/types/table/style.d.ts +48 -0
  72. package/types/table/utils.d.ts +303 -0
  73. package/types/tree.d.ts +10 -0
  74. package/types/utils.d.ts +64 -0
  75. package/types/virtual-fs.d.ts +8 -0
  76. package/types.d.ts +1128 -0
@@ -0,0 +1,303 @@
1
+ /**
2
+ * @template T
3
+ * @typedef {function(number): T} Dynamic<T | undefined>
4
+ */
5
+ /**
6
+ * @typedef {Object} Font
7
+ * @property {PDFFontSource} [src]
8
+ * The name of the font
9
+ *
10
+ * Defaults to the current document font source `doc._fontSrc`
11
+ * @property {string} [family]
12
+ * The font family of the font
13
+ *
14
+ * Defaults to the current document font family `doc._fontFamily`
15
+ * @property {Size} [size]
16
+ * The size of the font
17
+ *
18
+ * Defaults to the current document font size `doc._fontSize`
19
+ */
20
+ /**
21
+ * Measurement of how wide something is, false means 0 and true means 1
22
+ *
23
+ * @typedef {Size | boolean} Wideness
24
+ */
25
+ /**
26
+ * The value of the text of a cell
27
+ * @typedef {string | null | undefined} TableCellText
28
+ */
29
+ /** @typedef {Object} TableCellStyle
30
+ *
31
+ * @property {TableCellText} [text]
32
+ * The text of the table cell
33
+ * @property {number} [rowSpan]
34
+ * Number of rows the cell spans.
35
+ *
36
+ * Defaults to `1`.
37
+ * @property {number} [colSpan]
38
+ * Number of columns the cell spans.
39
+ *
40
+ * Defaults to `1`.
41
+ * @property {SideDefinition<Wideness>} [padding]
42
+ * Controls the padding of the cell text
43
+ *
44
+ * Defaults to `0.25em`
45
+ * @property {SideDefinition<Wideness>} [border]
46
+ * Controls the thickness of the cells borders.
47
+ *
48
+ * Defaults to `[1, 1, 1, 1]`.
49
+ * @property {SideDefinition<PDFColor>} [borderColor]
50
+ * Color of the border on each side of the cell.
51
+ *
52
+ * Defaults to the border color defined by the given table layout, or `black` on all sides.
53
+ * @property {Font} [font]
54
+ * Font options for the cell
55
+ *
56
+ * Defaults to the documents current font
57
+ * @property {PDFColor} [backgroundColor]
58
+ * Set the background color of the cell
59
+ *
60
+ * Defaults to transparent
61
+ * @property {'center' | ExpandedAlign} [align]
62
+ * Sets the text alignment of the cells text
63
+ *
64
+ * Defaults to `{x: 'left', y: 'top'}`
65
+ * @property {Size} [textStroke]
66
+ * Sets the text stroke width of the cells text
67
+ *
68
+ * Defaults to `0`
69
+ * @property {PDFColor} [textStrokeColor]
70
+ * Sets the text stroke color of the cells text
71
+ *
72
+ * Defaults to `black`
73
+ * @property {PDFColor} [textColor]
74
+ * Sets the text color of the cells text
75
+ *
76
+ * Defaults to `black`
77
+ * @property {'TH' | 'TD'} [type]
78
+ * Sets the cell type (for accessibility)
79
+ *
80
+ * Defaults to `TD`
81
+ * @property {Object} [textOptions]
82
+ * Sets any advanced text options passed into the cell renderer
83
+ *
84
+ * Same as the options you pass to `doc.text()`
85
+ *
86
+ * Will override any defaults set by the cell if set
87
+ * @property {string} [title]
88
+ * Sets the accessible title for the cell
89
+ * @property {'Column' | 'Row' | 'Both'} [scope]
90
+ * Sets the accessible scope for the cell
91
+ * @property {string} [id]
92
+ * Sets the accessible id for the cell
93
+ *
94
+ * Defaults to `<tableId>-<rowIndex>-<colIndex>`
95
+ * @property {boolean} [debug]
96
+ * Whether to show the debug lines for the cell
97
+ *
98
+ * Defaults to `false`
99
+ */
100
+ /** @typedef {TableCellText | TableCellStyle} TableCell **/
101
+ /**
102
+ * The width of the column
103
+ *
104
+ * - `*` distributes equally, filling the whole available space
105
+ * - `%` computes the proportion of the max size
106
+ *
107
+ * Defaults to `*`
108
+ * @typedef {Size | '*'} ColumnWidth
109
+ */
110
+ /**
111
+ * @typedef {Object} ColumnStyle
112
+ * @extends TableCellStyle
113
+ *
114
+ * @property {ColumnWidth} [width]
115
+ * @property {Size} [minWidth]
116
+ * The minimum width of the column
117
+ *
118
+ * Defaults to `0`
119
+ * @property {Size} [maxWidth]
120
+ * The maximum width of the column
121
+ *
122
+ * Defaults to `undefined` meaning no max
123
+ */
124
+ /** @typedef {ColumnStyle | ColumnWidth} Column **/
125
+ /**
126
+ * @typedef {Object} NormalizedColumnStyle
127
+ * @extends ColumnStyle
128
+ *
129
+ * @property {number | '*'} width
130
+ * @property {number} minWidth
131
+ * @property {number} maxWidth
132
+ */
133
+ /**
134
+ * The height of the row
135
+ *
136
+ * - A fixed value sets an absolute height for every row.
137
+ * - `auto` sets the height based on the text.
138
+ *
139
+ * `%` values are based on page content height
140
+ *
141
+ * Defaults to `auto`
142
+ * @typedef {Size | 'auto'} RowHeight
143
+ */
144
+ /**
145
+ * @typedef {Object} RowStyle
146
+ * @extends TableCellStyle
147
+ *
148
+ * @property {RowHeight} [height]
149
+ * @property {Size} [minHeight]
150
+ * The minimum height of the row
151
+ *
152
+ * `%` values are based on page content height
153
+ *
154
+ * Defaults to `0`
155
+ * @property {Size} [maxHeight]
156
+ * The maximum height of the row
157
+ *
158
+ * `%` values are based on page content height
159
+ *
160
+ * Defaults to `undefined` meaning no max
161
+ */
162
+ /** @typedef {RowStyle | RowHeight} Row **/
163
+ /**
164
+ * @typedef {Object} NormalizedRowStyle
165
+ * @extends RowStyle
166
+ *
167
+ * @property {number | 'auto'} height
168
+ * @property {number} minHeight
169
+ * @property {number} maxHeight
170
+ */
171
+ /** @typedef {'left' | 'center' | 'right' | 'justify'} AlignX **/
172
+ /** @typedef {'top' | 'center' | 'bottom'} AlignY **/
173
+ /**
174
+ * @typedef {Object} ExpandedAlign
175
+ * @property {AlignX} [x]
176
+ * @property {AlignY} [y]
177
+ */
178
+ /**
179
+ * @typedef {Object} DefaultTableCellStyle
180
+ *
181
+ * @extends ColumnStyle
182
+ * @extends RowStyle
183
+ * @extends TableCellStyle
184
+ */
185
+ /** @typedef {TableCellText | DefaultTableCellStyle} DefaultTableCell **/
186
+ /**
187
+ * @typedef {Object} NormalizedDefaultTableCellStyle
188
+ *
189
+ * @extends NormalizedColumnStyle
190
+ * @extends NormalizedRowStyle
191
+ * @extends TableCellStyle
192
+ */
193
+ /**
194
+ * @typedef {Object} NormalizedTableCellStyle
195
+ *
196
+ * @extends NormalizedColumnStyle
197
+ * @extends NormalizedRowStyle
198
+ * @extends TableCellStyle
199
+ *
200
+ * @property {number} rowIndex
201
+ * @property {number} rowSpan
202
+ * @property {number} colIndex
203
+ * @property {number} colSpan
204
+ *
205
+ * @property {string} text
206
+ * @property {Font} font
207
+ * @property {boolean} customFont
208
+ * @property {ExpandedSideDefinition<number>} padding
209
+ * @property {ExpandedSideDefinition<number>} border
210
+ * @property {ExpandedSideDefinition<PDFColor>} borderColor
211
+ * @property {ExpandedAlign} align
212
+ * @property {number} textStroke
213
+ * @property {PDFColor} textStrokeColor
214
+ * @property {PDFColor} textColor
215
+ * @property {number} minWidth
216
+ * @property {number} maxWidth
217
+ * @property {number} minHeight
218
+ * @property {number} maxHeight
219
+ * @property {Object} textOptions
220
+ */
221
+ /**
222
+ * @typedef {Object} SizedNormalizedTableCellStyle
223
+ *
224
+ * @extends {NormalizedTableCellStyle}
225
+ *
226
+ * @property {number} x
227
+ * @property {number} y
228
+ * @property {number} textX
229
+ * @property {number} textY
230
+ * @property {number} width
231
+ * @property {number} height
232
+ * @property {number} textAllocatedWidth
233
+ * @property {number} textAllocatedHeight
234
+ * @property {{x: number, y: number, width: number, height: number}} textBounds
235
+ */
236
+ /**
237
+ * @typedef {Object} Table
238
+ *
239
+ * @property {Position} [position]
240
+ * The position of the table
241
+ *
242
+ * Defaults to the current document position `{x: doc.x, y: doc.y}`
243
+ * @property {Size} [maxWidth]
244
+ * The maximum width the table can expand to
245
+ *
246
+ * Defaults to the remaining content width (offset from the tables position)
247
+ * @property {Column | Column[] | Dynamic<Column>} [columnStyles]
248
+ * Column definitions of the table.
249
+ * - A fixed value sets the config for every column
250
+ * - Use an array or a callback function to control the column config for each column individually.
251
+ *
252
+ * Defaults to `auto`
253
+ * @property {Row | Row[] | Dynamic<Row>} [rowStyles]
254
+ * Row definitions of the table.
255
+ * - A fixed value sets the config for every column
256
+ * - Use an array or a callback function to control the row config of each row individually.
257
+ *
258
+ * The given values are ignored for rows whose text is higher.
259
+ *
260
+ * Defaults to `*`.
261
+ * @property {DefaultTableCell} [defaultStyle]
262
+ * Defaults to apply to every cell
263
+ * @property {Iterable<Iterable<TableCell>>} [data]
264
+ * Two-dimensional iterable that defines the table's data.
265
+ *
266
+ * With the first dimension being the row, and the second being the column
267
+ *
268
+ * If provided the table will be automatically ended after the last row has been written,
269
+ * Otherwise it is up to the user to call `table.end()` or `table.row([], true)`
270
+ * @property {PDFStructureElement} [structParent]
271
+ * The parent structure to mount to
272
+ *
273
+ * This will cause the entire table to be enclosed in a Table structure
274
+ * with TR and TD/TH for cells
275
+ * @property {string} [id]
276
+ * Sets the accessible id for the table
277
+ *
278
+ * Defaults to `table-<number>`
279
+ * @property {boolean} [debug]
280
+ * Whether to show the debug lines for all the cells
281
+ *
282
+ * Defaults to `false`
283
+ */
284
+ /**
285
+ * Fields exclusive to row styles
286
+ * @type {string[]}
287
+ */
288
+ export declare const ROW_FIELDS: string[];
289
+ /**
290
+ * Fields exclusive to column styles
291
+ * @type {string[]}
292
+ */
293
+ export declare const COLUMN_FIELDS: string[];
294
+ export declare function memoize(fn: any, maxSize: any): (...args: any[]) => any;
295
+ /**
296
+ * Deep merge two objects.
297
+ *
298
+ * @template T
299
+ * @param {T} target
300
+ * @param sources
301
+ * @returns {T}
302
+ */
303
+ export declare function deepMerge(target: any, ...sources: any[]): any;
@@ -0,0 +1,10 @@
1
+ declare class PDFTree {
2
+ constructor(options?: {});
3
+ add(key: any, val: any): any;
4
+ get(key: any): any;
5
+ toString(): string;
6
+ _compareKeys(): void;
7
+ _keysName(): void;
8
+ _dataForKey(): void;
9
+ }
10
+ export default PDFTree;
@@ -0,0 +1,64 @@
1
+ export declare function PDFNumber(n: any): number;
2
+ /**
3
+ * Measurement of size
4
+ *
5
+ * @typedef {number | `${number}` | `${number}${'em' | 'in' | 'px' | 'cm' | 'mm' | 'pc' | 'ex' | 'ch' | 'rem' | 'vw' | 'vmin' | 'vmax' | '%' | 'pt'}`} Size
6
+ */
7
+ /**
8
+ * @typedef {Array<PDFTilingPattern | PDFColor> | string | Array<number>} PDFColor
9
+ */
10
+ /** @typedef {string | Buffer | Uint8Array | ArrayBuffer} PDFFontSource */
11
+ /**
12
+ * Side definitions
13
+ * - To define all sides, use a single value
14
+ * - To define up-down left-right, use a `[Y, X]` array
15
+ * - To define each side, use `[top, right, bottom, left]` array
16
+ * - Or `{vertical: SideValue, horizontal: SideValue}`
17
+ * - Or `{top: SideValue, right: SideValue, bottom: SideValue, left: SideValue}`
18
+ *
19
+ * @template T
20
+ * @typedef {T | [T, T] | [T, T, T, T] | { vertical: T; horizontal: T } | ExpandedSideDefinition<T>} SideDefinition<T>
21
+ **/
22
+ /**
23
+ * @template T
24
+ * @typedef {{ top: T; right: T; bottom: T; left: T }} ExpandedSideDefinition<T>
25
+ */
26
+ /**
27
+ * Convert any side definition into a static structure
28
+ *
29
+ * @template S
30
+ * @template D
31
+ * @template O
32
+ * @template {S | D} T
33
+ * @param {SideDefinition<S>} sides - The sides to convert
34
+ * @param {SideDefinition<D>} defaultDefinition - The value to use when no definition is provided
35
+ * @param {function(T): O} transformer - The transformation to apply to the sides once normalized
36
+ * @returns {ExpandedSideDefinition<O>}
37
+ */
38
+ export declare function normalizeSides(sides: any, defaultDefinition?: any, transformer?: (v: any) => any): {
39
+ top: any;
40
+ right: any;
41
+ bottom: any;
42
+ left: any;
43
+ };
44
+ export declare const MM_TO_CM: number;
45
+ export declare const CM_TO_IN: number;
46
+ export declare const PX_TO_IN: number;
47
+ export declare const IN_TO_PT = 72;
48
+ export declare const PC_TO_PT = 12;
49
+ /**
50
+ * Get cosine in degrees of a
51
+ *
52
+ * Rounding errors are handled
53
+ * @param a
54
+ * @returns {number}
55
+ */
56
+ export declare function cosine(a: any): number;
57
+ /**
58
+ * Get sine in degrees of a
59
+ *
60
+ * Rounding errors are handled
61
+ * @param a
62
+ * @returns {number}
63
+ */
64
+ export declare function sine(a: any): number;
@@ -0,0 +1,8 @@
1
+ declare class VirtualFileSystem {
2
+ constructor();
3
+ readFileSync(fileName: any, options?: {}): any;
4
+ writeFileSync(fileName: any, content: any): void;
5
+ bindFileData(data?: {}, options?: {}): void;
6
+ }
7
+ declare const _default: VirtualFileSystem;
8
+ export default _default;