modern-pdf-lib 0.15.1 → 0.22.9
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.
- package/README.md +119 -9
- package/dist/batchOptimize-Ba_pWw71.cjs +427 -0
- package/dist/batchOptimize-CxyY4fZe.mjs +392 -0
- package/dist/{bridge-DpzMOnHd.mjs → bridge-DTH5LMAK.mjs} +3 -3
- package/dist/{bridge-DN7BOHRW.cjs → bridge-DYCQzxF7.cjs} +2 -2
- package/dist/browser.cjs +621 -0
- package/dist/browser.d.cts +190 -0
- package/dist/browser.d.cts.map +1 -0
- package/dist/browser.d.mts +190 -0
- package/dist/browser.d.mts.map +1 -0
- package/dist/browser.mjs +212 -0
- package/dist/cli/index.cjs +40 -18
- package/dist/cli/index.mjs +40 -18
- package/dist/compressionAnalysis-B84FPXaQ.cjs +1525 -0
- package/dist/compressionAnalysis-BBv4BkQP.d.mts +261 -0
- package/dist/compressionAnalysis-BBv4BkQP.d.mts.map +1 -0
- package/dist/compressionAnalysis-ChkscEa1.mjs +1490 -0
- package/dist/compressionAnalysis-CtJ2X9l2.d.cts +261 -0
- package/dist/compressionAnalysis-CtJ2X9l2.d.cts.map +1 -0
- package/dist/create.cjs +35 -0
- package/dist/create.d.cts +3 -0
- package/dist/create.d.mts +3 -0
- package/dist/create.mjs +5 -0
- package/dist/{deduplicateImages-BfpjHY9b.mjs → deduplicateImages-CmTeo6Tx.mjs} +3 -3
- package/dist/{deduplicateImages-BtJ5tlrr.cjs → deduplicateImages-cKsnD6Ep.cjs} +2 -2
- package/dist/{fflateAdapter-D2mv_ttM.mjs → fflateAdapter-CBQpGTlx.mjs} +2 -2
- package/dist/{fflateAdapter-cT4YeY_h.cjs → fflateAdapter-LTAeAhaD.cjs} +1 -1
- package/dist/fieldAppearance-C8PoLFSc.d.mts +136 -0
- package/dist/fieldAppearance-C8PoLFSc.d.mts.map +1 -0
- package/dist/fieldAppearance-CdiGFG5e.d.cts +136 -0
- package/dist/fieldAppearance-CdiGFG5e.d.cts.map +1 -0
- package/dist/fontEmbed-Dsu9fo4U.d.mts +636 -0
- package/dist/fontEmbed-Dsu9fo4U.d.mts.map +1 -0
- package/dist/fontEmbed-LID6yG6g.d.cts +636 -0
- package/dist/fontEmbed-LID6yG6g.d.cts.map +1 -0
- package/dist/{fontSubset-BxsF9Tu5.cjs → fontSubset-5SLWMmEw.cjs} +1 -1
- package/dist/{fontSubset-ClyTXlhY.mjs → fontSubset-DWpduoY2.mjs} +2 -2
- package/dist/forms.cjs +13 -0
- package/dist/forms.d.cts +3 -0
- package/dist/forms.d.mts +3 -0
- package/dist/forms.mjs +3 -0
- package/dist/grayscaleDetect-C2m-eEXR.cjs +96 -0
- package/dist/grayscaleDetect-C6kFF3dk.mjs +84 -0
- package/dist/imageExtract-Dnk_Ssv7.mjs +155 -0
- package/dist/imageExtract-zEb1gnkb.cjs +166 -0
- package/dist/index-BtYOx5wh.d.mts +4904 -0
- package/dist/index-BtYOx5wh.d.mts.map +1 -0
- package/dist/index-bpktKzCA.d.cts +4904 -0
- package/dist/index-bpktKzCA.d.cts.map +1 -0
- package/dist/index.cjs +274 -20704
- package/dist/index.d.cts +7 -9151
- package/dist/index.d.mts +7 -9151
- package/dist/index.mjs +17 -20532
- package/dist/layout-CuAVk_Or.cjs +563 -0
- package/dist/layout-DgX_0jfK.mjs +438 -0
- package/dist/{libdeflateWasm-Cg7cWHOq.cjs → libdeflateWasm-BdiDEJOj.cjs} +2 -2
- package/dist/{libdeflateWasm-Cmxa-yiS.mjs → libdeflateWasm-rLppXytE.mjs} +3 -3
- package/dist/loader-3u6Tw5T-.mjs +328 -0
- package/dist/loader-I4zdkoWc.cjs +393 -0
- package/dist/parse.cjs +24 -0
- package/dist/parse.d.cts +4 -0
- package/dist/parse.d.mts +4 -0
- package/dist/parse.mjs +7 -0
- package/dist/{pdfCatalog-BcOL6QF-.cjs → pdfCatalog-CYy4NXEY.cjs} +2 -2
- package/dist/{pdfCatalog-CnJRovvm.mjs → pdfCatalog-IImGcMbR.mjs} +3 -3
- package/dist/pdfDocument-BFxHD_2u.mjs +13755 -0
- package/dist/pdfDocument-BSiQdNZq.d.cts +4640 -0
- package/dist/pdfDocument-BSiQdNZq.d.cts.map +1 -0
- package/dist/pdfDocument-i6U5fQ91.d.mts +4640 -0
- package/dist/pdfDocument-i6U5fQ91.d.mts.map +1 -0
- package/dist/pdfDocument-pmRXryVI.cjs +14180 -0
- package/dist/pdfForm-9gd40uz9.cjs +1796 -0
- package/dist/pdfForm-BiyNtYem.d.mts +905 -0
- package/dist/pdfForm-BiyNtYem.d.mts.map +1 -0
- package/dist/pdfForm-Cn-cVicP.mjs +1695 -0
- package/dist/pdfForm-SOXJ72LW.d.cts +905 -0
- package/dist/pdfForm-SOXJ72LW.d.cts.map +1 -0
- package/dist/{pdfObjects-BrU4Xd0V.cjs → pdfObjects-1veop1_d.cjs} +2 -2
- package/dist/{pdfObjects-DZZ2GPRW.mjs → pdfObjects-uEsWlfzU.mjs} +2 -2
- package/dist/{pdfPage-Dm5XC_g_.mjs → pdfPage-Cd8e7flb.mjs} +3024 -5
- package/dist/{pdfPage-Dz_SVKUS.cjs → pdfPage-Cd8jOJp6.cjs} +3046 -3
- package/dist/{pngEmbed-I1hU3Y6m.mjs → pngEmbed-BLj2zi-5.mjs} +3 -3
- package/dist/{pngEmbed-C6M1eX6b.cjs → pngEmbed-D4X4ZN-3.cjs} +2 -2
- package/dist/src-6L07EQsi.cjs +11852 -0
- package/dist/src-Dm4aaZ8q.mjs +11103 -0
- package/dist/{imageExtract-vjyQyFcT.mjs → streamDecode-Bj568Nc9.mjs} +1646 -188
- package/dist/{imageExtract-BC7TMY98.cjs → streamDecode-CvgErkFu.cjs} +1645 -199
- package/package.json +33 -1
- package/dist/batchOptimize-ClXizv19.mjs +0 -306
- package/dist/batchOptimize-DYQOX1-7.cjs +0 -329
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/loader-B6VIrZOJ.mjs +0 -164
- package/dist/loader-DdB5Xo5D.cjs +0 -166
- package/dist/rolldown-runtime-95iHPtFO.mjs +0 -18
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { i as wrapText, n as PdfPage, t as PageSizes } from "./pdfPage-Cd8e7flb.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/enums.ts
|
|
4
|
+
/**
|
|
5
|
+
* PDF blend modes (PDF 1.4+, Table 136).
|
|
6
|
+
* Applied via ExtGState /BM key.
|
|
7
|
+
*/
|
|
8
|
+
const BlendMode = {
|
|
9
|
+
Normal: "Normal",
|
|
10
|
+
Multiply: "Multiply",
|
|
11
|
+
Screen: "Screen",
|
|
12
|
+
Overlay: "Overlay",
|
|
13
|
+
Darken: "Darken",
|
|
14
|
+
Lighten: "Lighten",
|
|
15
|
+
ColorDodge: "ColorDodge",
|
|
16
|
+
ColorBurn: "ColorBurn",
|
|
17
|
+
HardLight: "HardLight",
|
|
18
|
+
SoftLight: "SoftLight",
|
|
19
|
+
Difference: "Difference",
|
|
20
|
+
Exclusion: "Exclusion"
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* PDF text rendering modes (Table 106).
|
|
24
|
+
* Applied via the Tr operator inside a text object.
|
|
25
|
+
*/
|
|
26
|
+
const TextRenderingMode = {
|
|
27
|
+
Fill: 0,
|
|
28
|
+
Outline: 1,
|
|
29
|
+
FillAndOutline: 2,
|
|
30
|
+
Invisible: 3,
|
|
31
|
+
FillAndClip: 4,
|
|
32
|
+
OutlineAndClip: 5,
|
|
33
|
+
FillAndOutlineAndClip: 6,
|
|
34
|
+
Clip: 7
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* PDF line cap styles (Table 54).
|
|
38
|
+
* Applied via the J operator.
|
|
39
|
+
*/
|
|
40
|
+
const LineCapStyle = {
|
|
41
|
+
Butt: 0,
|
|
42
|
+
Round: 1,
|
|
43
|
+
Projecting: 2
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* PDF line join styles (Table 55).
|
|
47
|
+
* Applied via the j operator.
|
|
48
|
+
*/
|
|
49
|
+
const LineJoinStyle = {
|
|
50
|
+
Miter: 0,
|
|
51
|
+
Round: 1,
|
|
52
|
+
Bevel: 2
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Text alignment for form fields and layout operations.
|
|
56
|
+
*/
|
|
57
|
+
const TextAlignment = {
|
|
58
|
+
Left: 0,
|
|
59
|
+
Center: 1,
|
|
60
|
+
Right: 2
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Image alignment for layout operations.
|
|
64
|
+
*/
|
|
65
|
+
const ImageAlignment = {
|
|
66
|
+
Left: 0,
|
|
67
|
+
Center: 1,
|
|
68
|
+
Right: 2
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Preset parsing speeds — maps to objectsPerTick values in LoadPdfOptions.
|
|
72
|
+
*
|
|
73
|
+
* Lower values keep the main thread more responsive but parse more slowly.
|
|
74
|
+
*/
|
|
75
|
+
const ParseSpeeds = {
|
|
76
|
+
Fastest: Infinity,
|
|
77
|
+
Fast: 500,
|
|
78
|
+
Medium: 100,
|
|
79
|
+
Slow: 10
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/core/pageManipulation.ts
|
|
84
|
+
/**
|
|
85
|
+
* Resolve a PageSize input to a `[width, height]` tuple.
|
|
86
|
+
*
|
|
87
|
+
* @param size Page size as a tuple, object, or undefined (defaults to A4).
|
|
88
|
+
* @returns A `[width, height]` tuple in PDF points.
|
|
89
|
+
*/
|
|
90
|
+
function resolveSize(size) {
|
|
91
|
+
const resolved = size ?? PageSizes.A4;
|
|
92
|
+
if (Array.isArray(resolved)) return [resolved[0], resolved[1]];
|
|
93
|
+
return [resolved.width, resolved.height];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Validate that a page index is within bounds.
|
|
97
|
+
*
|
|
98
|
+
* @param index The index to validate.
|
|
99
|
+
* @param pageCount The total number of pages.
|
|
100
|
+
* @param operation A description of the operation for error messages.
|
|
101
|
+
* @throws RangeError if the index is out of bounds.
|
|
102
|
+
*/
|
|
103
|
+
function validateIndex(index, pageCount, operation) {
|
|
104
|
+
if (!Number.isInteger(index) || index < 0 || index >= pageCount) throw new RangeError(`${operation}: index ${index} out of range [0, ${pageCount - 1}]`);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Validate that a page index is valid for insertion (0 to pageCount inclusive).
|
|
108
|
+
*
|
|
109
|
+
* @param index The index to validate.
|
|
110
|
+
* @param pageCount The total number of pages.
|
|
111
|
+
* @param operation A description of the operation for error messages.
|
|
112
|
+
* @throws RangeError if the index is out of bounds.
|
|
113
|
+
*/
|
|
114
|
+
function validateInsertIndex(index, pageCount, operation) {
|
|
115
|
+
if (!Number.isInteger(index) || index < 0 || index > pageCount) throw new RangeError(`${operation}: index ${index} out of range [0, ${pageCount}]`);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Validate that a rotation angle is a multiple of 90.
|
|
119
|
+
*
|
|
120
|
+
* @param angle The rotation angle in degrees.
|
|
121
|
+
* @throws Error if the angle is not a valid rotation.
|
|
122
|
+
*/
|
|
123
|
+
function validateRotation(angle) {
|
|
124
|
+
if (angle % 90 !== 0) throw new Error(`rotatePage: angle must be a multiple of 90, got ${angle}`);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Insert a new blank page into the document at the specified position.
|
|
128
|
+
*
|
|
129
|
+
* All existing pages at `index` and beyond are shifted to make room.
|
|
130
|
+
*
|
|
131
|
+
* @param doc The PdfDocument to modify.
|
|
132
|
+
* @param index Zero-based position at which to insert the page.
|
|
133
|
+
* Must be in the range `[0, pageCount]`.
|
|
134
|
+
* @param size Optional page size. Defaults to A4.
|
|
135
|
+
* @returns The newly created PdfPage.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { createPdf, insertPage, PageSizes } from 'modern-pdf-lib';
|
|
140
|
+
*
|
|
141
|
+
* const doc = createPdf();
|
|
142
|
+
* doc.addPage();
|
|
143
|
+
* const newPage = insertPage(doc, 0, PageSizes.Letter); // insert at front
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
function insertPage(doc, index, size) {
|
|
147
|
+
const pages = doc.getInternalPages();
|
|
148
|
+
const registry = doc.getRegistry();
|
|
149
|
+
validateInsertIndex(index, pages.length, "insertPage");
|
|
150
|
+
const [w, h] = resolveSize(size);
|
|
151
|
+
const page = new PdfPage(w, h, registry);
|
|
152
|
+
doc.registerFontsOnPage(page);
|
|
153
|
+
pages.splice(index, 0, page);
|
|
154
|
+
return page;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Remove a page from the document by its zero-based index.
|
|
158
|
+
*
|
|
159
|
+
* @param doc The PdfDocument to modify.
|
|
160
|
+
* @param index Zero-based index of the page to remove.
|
|
161
|
+
* @throws RangeError if the index is out of bounds.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* removePage(doc, 0); // Remove the first page
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
function removePage(doc, index) {
|
|
169
|
+
const pages = doc.getInternalPages();
|
|
170
|
+
validateIndex(index, pages.length, "removePage");
|
|
171
|
+
pages.splice(index, 1);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Move a page from one position to another within the document.
|
|
175
|
+
*
|
|
176
|
+
* The page at `fromIndex` is removed and then inserted at `toIndex`
|
|
177
|
+
* (computed after the removal).
|
|
178
|
+
*
|
|
179
|
+
* @param doc The PdfDocument to modify.
|
|
180
|
+
* @param fromIndex Current zero-based index of the page to move.
|
|
181
|
+
* @param toIndex Target zero-based index. Must be in range
|
|
182
|
+
* `[0, pageCount - 1]` after removal.
|
|
183
|
+
* @throws RangeError if either index is out of bounds.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* movePage(doc, 2, 0); // Move page 2 to the front
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
function movePage(doc, fromIndex, toIndex) {
|
|
191
|
+
const pages = doc.getInternalPages();
|
|
192
|
+
validateIndex(fromIndex, pages.length, "movePage (fromIndex)");
|
|
193
|
+
const [page] = pages.splice(fromIndex, 1);
|
|
194
|
+
if (toIndex < 0 || toIndex > pages.length) {
|
|
195
|
+
pages.splice(fromIndex, 0, page);
|
|
196
|
+
throw new RangeError(`movePage (toIndex): index ${toIndex} out of range [0, ${pages.length}]`);
|
|
197
|
+
}
|
|
198
|
+
pages.splice(toIndex, 0, page);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Rotate a page by the specified angle.
|
|
202
|
+
*
|
|
203
|
+
* The angle is cumulative with any existing rotation set on the page.
|
|
204
|
+
* The page's `/Rotate` entry in the page dictionary will be set when
|
|
205
|
+
* the document is saved.
|
|
206
|
+
*
|
|
207
|
+
* @param doc The PdfDocument to modify.
|
|
208
|
+
* @param index Zero-based index of the page to rotate.
|
|
209
|
+
* @param angle Rotation angle in degrees. Must be a multiple of 90.
|
|
210
|
+
* Common values: 90, 180, 270, -90.
|
|
211
|
+
* @throws RangeError if the index is out of bounds.
|
|
212
|
+
* @throws Error if the angle is not a multiple of 90.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* rotatePage(doc, 0, 90); // Rotate first page 90 degrees clockwise
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
function rotatePage(doc, index, angle) {
|
|
220
|
+
const pages = doc.getInternalPages();
|
|
221
|
+
validateIndex(index, pages.length, "rotatePage");
|
|
222
|
+
validateRotation(angle);
|
|
223
|
+
const page = pages[index];
|
|
224
|
+
const newRotation = (((page.getRotation?.() ?? 0) + angle) % 360 + 360) % 360;
|
|
225
|
+
page.setRotation(newRotation);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Set a crop box on a page.
|
|
229
|
+
*
|
|
230
|
+
* The crop box defines the visible region of the page when displayed
|
|
231
|
+
* or printed. It defaults to the media box if not set.
|
|
232
|
+
*
|
|
233
|
+
* @param doc The PdfDocument to modify.
|
|
234
|
+
* @param index Zero-based index of the page.
|
|
235
|
+
* @param cropBox The crop box rectangle.
|
|
236
|
+
* @throws RangeError if the index is out of bounds.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* cropPage(doc, 0, { x: 50, y: 50, width: 495, height: 742 });
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
function cropPage(doc, index, cropBox) {
|
|
244
|
+
const pages = doc.getInternalPages();
|
|
245
|
+
validateIndex(index, pages.length, "cropPage");
|
|
246
|
+
pages[index].setCropBox(cropBox.x, cropBox.y, cropBox.width, cropBox.height);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Get the size of a page.
|
|
250
|
+
*
|
|
251
|
+
* @param doc The PdfDocument.
|
|
252
|
+
* @param index Zero-based page index.
|
|
253
|
+
* @returns A `{ width, height }` object in PDF points.
|
|
254
|
+
*/
|
|
255
|
+
function getPageSize(doc, index) {
|
|
256
|
+
const pages = doc.getInternalPages();
|
|
257
|
+
validateIndex(index, pages.length, "getPageSize");
|
|
258
|
+
const page = pages[index];
|
|
259
|
+
return {
|
|
260
|
+
width: page.width,
|
|
261
|
+
height: page.height
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Resize a page by setting its media box.
|
|
266
|
+
*
|
|
267
|
+
* Note: This changes the page dimensions but does not scale existing
|
|
268
|
+
* content. Content that was drawn at coordinates beyond the new
|
|
269
|
+
* dimensions may be clipped.
|
|
270
|
+
*
|
|
271
|
+
* @param doc The PdfDocument to modify.
|
|
272
|
+
* @param index Zero-based page index.
|
|
273
|
+
* @param size New page size.
|
|
274
|
+
*/
|
|
275
|
+
function resizePage(doc, index, size) {
|
|
276
|
+
const pages = doc.getInternalPages();
|
|
277
|
+
validateIndex(index, pages.length, "resizePage");
|
|
278
|
+
const [w, h] = resolveSize(size);
|
|
279
|
+
pages[index].setMediaBox(0, 0, w, h);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Reverse the page order of the entire document.
|
|
283
|
+
*
|
|
284
|
+
* @param doc The PdfDocument to modify.
|
|
285
|
+
*/
|
|
286
|
+
function reversePages(doc) {
|
|
287
|
+
doc.getInternalPages().reverse();
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Remove multiple pages at once, given their zero-based indices.
|
|
291
|
+
*
|
|
292
|
+
* Indices are processed in descending order to avoid shifting issues.
|
|
293
|
+
*
|
|
294
|
+
* @param doc The PdfDocument to modify.
|
|
295
|
+
* @param indices Array of zero-based page indices to remove.
|
|
296
|
+
* @throws RangeError if any index is out of bounds.
|
|
297
|
+
*/
|
|
298
|
+
function removePages(doc, indices) {
|
|
299
|
+
const pages = doc.getInternalPages();
|
|
300
|
+
for (const index of indices) validateIndex(index, pages.length, "removePages");
|
|
301
|
+
const sorted = new Set(indices).values().toArray().sort((a, b) => b - a);
|
|
302
|
+
for (const index of sorted) pages.splice(index, 1);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Rotate all pages in the document by the specified angle.
|
|
306
|
+
*
|
|
307
|
+
* @param doc The PdfDocument to modify.
|
|
308
|
+
* @param angle Rotation angle in degrees (must be a multiple of 90).
|
|
309
|
+
*/
|
|
310
|
+
function rotateAllPages(doc, angle) {
|
|
311
|
+
validateRotation(angle);
|
|
312
|
+
const pages = doc.getInternalPages();
|
|
313
|
+
for (const page of pages) {
|
|
314
|
+
const newRotation = (((page.getRotation?.() ?? 0) + angle) % 360 + 360) % 360;
|
|
315
|
+
page.setRotation(newRotation);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/core/layout.ts
|
|
321
|
+
/**
|
|
322
|
+
* Break text into lines that fit within `maxWidth`, measuring each line's
|
|
323
|
+
* width. Explicit newlines (`\n`) are always honoured.
|
|
324
|
+
*
|
|
325
|
+
* The returned `height` is the total vertical extent: one line's ascent
|
|
326
|
+
* plus `(n-1) * lineHeight`.
|
|
327
|
+
*/
|
|
328
|
+
function layoutMultilineText(text, options) {
|
|
329
|
+
const { font, fontSize, maxWidth, wordBreaks } = options;
|
|
330
|
+
const lineHeight = options.lineHeight ?? fontSize * 1.2;
|
|
331
|
+
const rawLines = text.split("\n");
|
|
332
|
+
const allLines = [];
|
|
333
|
+
for (const rawLine of rawLines) if (maxWidth > 0) {
|
|
334
|
+
const wrapped = wrapText(rawLine, maxWidth, font, fontSize, wordBreaks);
|
|
335
|
+
for (const line of wrapped) allLines.push({
|
|
336
|
+
text: line,
|
|
337
|
+
width: font.widthOfTextAtSize(line, fontSize)
|
|
338
|
+
});
|
|
339
|
+
} else allLines.push({
|
|
340
|
+
text: rawLine,
|
|
341
|
+
width: font.widthOfTextAtSize(rawLine, fontSize)
|
|
342
|
+
});
|
|
343
|
+
return {
|
|
344
|
+
lines: allLines,
|
|
345
|
+
height: allLines.length > 0 ? font.heightAtSize(fontSize) + (allLines.length - 1) * lineHeight : 0
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Layout text into evenly-spaced cells for combed text fields.
|
|
350
|
+
*
|
|
351
|
+
* Each character is centred within its cell. Characters beyond
|
|
352
|
+
* `cellCount` are silently truncated.
|
|
353
|
+
*/
|
|
354
|
+
function layoutCombedText(text, options) {
|
|
355
|
+
const { font, fontSize, cellCount, cellWidth } = options;
|
|
356
|
+
return text.slice(0, cellCount).split("").map((char, i) => {
|
|
357
|
+
const charWidth = font.widthOfTextAtSize(char, fontSize);
|
|
358
|
+
return {
|
|
359
|
+
char,
|
|
360
|
+
x: i * cellWidth + cellWidth / 2 - charWidth / 2,
|
|
361
|
+
width: charWidth
|
|
362
|
+
};
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Compute the largest font size (in points) at which `text` fits within
|
|
367
|
+
* the given width (and optionally height) constraints.
|
|
368
|
+
*
|
|
369
|
+
* Uses binary search between `minSize` (default 4) and `maxSize`
|
|
370
|
+
* (default 500), converging to within 0.1 pt.
|
|
371
|
+
*/
|
|
372
|
+
function computeFontSize(text, options) {
|
|
373
|
+
const { font, maxWidth, wordBreaks } = options;
|
|
374
|
+
const maxHeight = options.maxHeight ?? Infinity;
|
|
375
|
+
const minSize = options.minSize ?? 4;
|
|
376
|
+
const maxSize = options.maxSize ?? 500;
|
|
377
|
+
let lo = minSize;
|
|
378
|
+
let hi = maxSize;
|
|
379
|
+
for (let i = 0; i < 40; i++) {
|
|
380
|
+
const mid = (lo + hi) / 2;
|
|
381
|
+
const layout = layoutMultilineText(text, {
|
|
382
|
+
font,
|
|
383
|
+
fontSize: mid,
|
|
384
|
+
maxWidth,
|
|
385
|
+
lineHeight: options.lineHeight,
|
|
386
|
+
wordBreaks
|
|
387
|
+
});
|
|
388
|
+
if (layout.height <= maxHeight && layout.lines.every((line) => line.width <= maxWidth)) lo = mid;
|
|
389
|
+
else hi = mid;
|
|
390
|
+
if (hi - lo < .1) break;
|
|
391
|
+
}
|
|
392
|
+
return Math.floor(lo * 10) / 10;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Layout a single line of text with optional alignment within bounds.
|
|
396
|
+
*
|
|
397
|
+
* Unlike {@link layoutMultilineText}, this does not perform any wrapping.
|
|
398
|
+
* It simply measures the text, computes alignment offsets, and returns
|
|
399
|
+
* the positioned line.
|
|
400
|
+
*
|
|
401
|
+
* @param text The text to lay out (single line, no newlines).
|
|
402
|
+
* @param options Font, size, bounds, alignment.
|
|
403
|
+
* @returns The measured line and its position offsets.
|
|
404
|
+
*/
|
|
405
|
+
function layoutSinglelineText(text, options) {
|
|
406
|
+
const { font, fontSize, bounds, alignment } = options;
|
|
407
|
+
const width = font.widthOfTextAtSize(text, fontSize);
|
|
408
|
+
const height = font.heightAtSize(fontSize);
|
|
409
|
+
let x = 0;
|
|
410
|
+
let y = 0;
|
|
411
|
+
if (bounds) {
|
|
412
|
+
y = (bounds.height - height) / 2;
|
|
413
|
+
switch (alignment) {
|
|
414
|
+
case 1:
|
|
415
|
+
x = (bounds.width - width) / 2;
|
|
416
|
+
break;
|
|
417
|
+
case 2:
|
|
418
|
+
x = bounds.width - width;
|
|
419
|
+
break;
|
|
420
|
+
default:
|
|
421
|
+
x = 0;
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
line: {
|
|
427
|
+
text,
|
|
428
|
+
width,
|
|
429
|
+
height
|
|
430
|
+
},
|
|
431
|
+
x,
|
|
432
|
+
y
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
//#endregion
|
|
437
|
+
export { LineCapStyle as _, cropPage as a, TextAlignment as b, movePage as c, resizePage as d, reversePages as f, ImageAlignment as g, BlendMode as h, layoutSinglelineText as i, removePage as l, rotatePage as m, layoutCombedText as n, getPageSize as o, rotateAllPages as p, layoutMultilineText as r, insertPage as s, computeFontSize as t, removePages as u, LineJoinStyle as v, TextRenderingMode as x, ParseSpeeds as y };
|
|
438
|
+
//# sourceMappingURL=layout-DgX_0jfK.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-
|
|
78
|
+
const { loadWasmModule } = await Promise.resolve().then(() => require("./loader-I4zdkoWc.cjs")).then((n) => n.loader_exports);
|
|
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-
|
|
237
|
+
//# sourceMappingURL=libdeflateWasm-BdiDEJOj.cjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ka as __exportAll } from "./index-BtYOx5wh.d.mts";
|
|
2
2
|
|
|
3
3
|
//#region src/compression/libdeflateWasm.ts
|
|
4
4
|
var libdeflateWasm_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -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-
|
|
78
|
+
const { loadWasmModule } = await import("./loader-3u6Tw5T-.mjs").then((n) => n.l);
|
|
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-
|
|
220
|
+
//# sourceMappingURL=libdeflateWasm-rLppXytE.mjs.map
|