react-vector-pdf 0.3.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.
@@ -0,0 +1,901 @@
1
+ import A, { createContext as st, useContext as at } from "react";
2
+ import { jsPDF as ft } from "jspdf";
3
+ var J = { exports: {} }, $ = {};
4
+ var tt;
5
+ function ct() {
6
+ if (tt) return $;
7
+ tt = 1;
8
+ var i = /* @__PURE__ */ Symbol.for("react.transitional.element"), t = /* @__PURE__ */ Symbol.for("react.fragment");
9
+ function r(n, o, s) {
10
+ var f = null;
11
+ if (s !== void 0 && (f = "" + s), o.key !== void 0 && (f = "" + o.key), "key" in o) {
12
+ s = {};
13
+ for (var l in o)
14
+ l !== "key" && (s[l] = o[l]);
15
+ } else s = o;
16
+ return o = s.ref, {
17
+ $$typeof: i,
18
+ type: n,
19
+ key: f,
20
+ ref: o !== void 0 ? o : null,
21
+ props: s
22
+ };
23
+ }
24
+ return $.Fragment = t, $.jsx = r, $.jsxs = r, $;
25
+ }
26
+ var V = {};
27
+ var et;
28
+ function lt() {
29
+ return et || (et = 1, process.env.NODE_ENV !== "production" && (function() {
30
+ function i(e) {
31
+ if (e == null) return null;
32
+ if (typeof e == "function")
33
+ return e.$$typeof === S ? null : e.displayName || e.name || null;
34
+ if (typeof e == "string") return e;
35
+ switch (e) {
36
+ case u:
37
+ return "Fragment";
38
+ case M:
39
+ return "Profiler";
40
+ case O:
41
+ return "StrictMode";
42
+ case G:
43
+ return "Suspense";
44
+ case m:
45
+ return "SuspenseList";
46
+ case W:
47
+ return "Activity";
48
+ }
49
+ if (typeof e == "object")
50
+ switch (typeof e.tag == "number" && console.error(
51
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
52
+ ), e.$$typeof) {
53
+ case C:
54
+ return "Portal";
55
+ case B:
56
+ return e.displayName || "Context";
57
+ case N:
58
+ return (e._context.displayName || "Context") + ".Consumer";
59
+ case X:
60
+ var c = e.render;
61
+ return e = e.displayName, e || (e = c.displayName || c.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
62
+ case v:
63
+ return c = e.displayName || null, c !== null ? c : i(e.type) || "Memo";
64
+ case P:
65
+ c = e._payload, e = e._init;
66
+ try {
67
+ return i(e(c));
68
+ } catch {
69
+ }
70
+ }
71
+ return null;
72
+ }
73
+ function t(e) {
74
+ return "" + e;
75
+ }
76
+ function r(e) {
77
+ try {
78
+ t(e);
79
+ var c = !1;
80
+ } catch {
81
+ c = !0;
82
+ }
83
+ if (c) {
84
+ c = console;
85
+ var d = c.error, T = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
86
+ return d.call(
87
+ c,
88
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
89
+ T
90
+ ), t(e);
91
+ }
92
+ }
93
+ function n(e) {
94
+ if (e === u) return "<>";
95
+ if (typeof e == "object" && e !== null && e.$$typeof === P)
96
+ return "<...>";
97
+ try {
98
+ var c = i(e);
99
+ return c ? "<" + c + ">" : "<...>";
100
+ } catch {
101
+ return "<...>";
102
+ }
103
+ }
104
+ function o() {
105
+ var e = p.A;
106
+ return e === null ? null : e.getOwner();
107
+ }
108
+ function s() {
109
+ return Error("react-stack-top-frame");
110
+ }
111
+ function f(e) {
112
+ if (D.call(e, "key")) {
113
+ var c = Object.getOwnPropertyDescriptor(e, "key").get;
114
+ if (c && c.isReactWarning) return !1;
115
+ }
116
+ return e.key !== void 0;
117
+ }
118
+ function l(e, c) {
119
+ function d() {
120
+ E || (E = !0, console.error(
121
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
122
+ c
123
+ ));
124
+ }
125
+ d.isReactWarning = !0, Object.defineProperty(e, "key", {
126
+ get: d,
127
+ configurable: !0
128
+ });
129
+ }
130
+ function g() {
131
+ var e = i(this.type);
132
+ return b[e] || (b[e] = !0, console.error(
133
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
134
+ )), e = this.props.ref, e !== void 0 ? e : null;
135
+ }
136
+ function x(e, c, d, T, L, _) {
137
+ var k = d.ref;
138
+ return e = {
139
+ $$typeof: j,
140
+ type: e,
141
+ key: c,
142
+ props: d,
143
+ _owner: T
144
+ }, (k !== void 0 ? k : null) !== null ? Object.defineProperty(e, "ref", {
145
+ enumerable: !1,
146
+ get: g
147
+ }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
148
+ configurable: !1,
149
+ enumerable: !1,
150
+ writable: !0,
151
+ value: 0
152
+ }), Object.defineProperty(e, "_debugInfo", {
153
+ configurable: !1,
154
+ enumerable: !1,
155
+ writable: !0,
156
+ value: null
157
+ }), Object.defineProperty(e, "_debugStack", {
158
+ configurable: !1,
159
+ enumerable: !1,
160
+ writable: !0,
161
+ value: L
162
+ }), Object.defineProperty(e, "_debugTask", {
163
+ configurable: !1,
164
+ enumerable: !1,
165
+ writable: !0,
166
+ value: _
167
+ }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
168
+ }
169
+ function a(e, c, d, T, L, _) {
170
+ var k = c.children;
171
+ if (k !== void 0)
172
+ if (T)
173
+ if (Y(k)) {
174
+ for (T = 0; T < k.length; T++)
175
+ R(k[T]);
176
+ Object.freeze && Object.freeze(k);
177
+ } else
178
+ console.error(
179
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
180
+ );
181
+ else R(k);
182
+ if (D.call(c, "key")) {
183
+ k = i(e);
184
+ var I = Object.keys(c).filter(function(it) {
185
+ return it !== "key";
186
+ });
187
+ T = 0 < I.length ? "{key: someKey, " + I.join(": ..., ") + ": ...}" : "{key: someKey}", F[k + T] || (I = 0 < I.length ? "{" + I.join(": ..., ") + ": ...}" : "{}", console.error(
188
+ `A props object containing a "key" prop is being spread into JSX:
189
+ let props = %s;
190
+ <%s {...props} />
191
+ React keys must be passed directly to JSX without using spread:
192
+ let props = %s;
193
+ <%s key={someKey} {...props} />`,
194
+ T,
195
+ k,
196
+ I,
197
+ k
198
+ ), F[k + T] = !0);
199
+ }
200
+ if (k = null, d !== void 0 && (r(d), k = "" + d), f(c) && (r(c.key), k = "" + c.key), "key" in c) {
201
+ d = {};
202
+ for (var K in c)
203
+ K !== "key" && (d[K] = c[K]);
204
+ } else d = c;
205
+ return k && l(
206
+ d,
207
+ typeof e == "function" ? e.displayName || e.name || "Unknown" : e
208
+ ), x(
209
+ e,
210
+ k,
211
+ d,
212
+ o(),
213
+ L,
214
+ _
215
+ );
216
+ }
217
+ function R(e) {
218
+ h(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === P && (e._payload.status === "fulfilled" ? h(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
219
+ }
220
+ function h(e) {
221
+ return typeof e == "object" && e !== null && e.$$typeof === j;
222
+ }
223
+ var H = A, j = /* @__PURE__ */ Symbol.for("react.transitional.element"), C = /* @__PURE__ */ Symbol.for("react.portal"), u = /* @__PURE__ */ Symbol.for("react.fragment"), O = /* @__PURE__ */ Symbol.for("react.strict_mode"), M = /* @__PURE__ */ Symbol.for("react.profiler"), N = /* @__PURE__ */ Symbol.for("react.consumer"), B = /* @__PURE__ */ Symbol.for("react.context"), X = /* @__PURE__ */ Symbol.for("react.forward_ref"), G = /* @__PURE__ */ Symbol.for("react.suspense"), m = /* @__PURE__ */ Symbol.for("react.suspense_list"), v = /* @__PURE__ */ Symbol.for("react.memo"), P = /* @__PURE__ */ Symbol.for("react.lazy"), W = /* @__PURE__ */ Symbol.for("react.activity"), S = /* @__PURE__ */ Symbol.for("react.client.reference"), p = H.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, D = Object.prototype.hasOwnProperty, Y = Array.isArray, z = console.createTask ? console.createTask : function() {
224
+ return null;
225
+ };
226
+ H = {
227
+ react_stack_bottom_frame: function(e) {
228
+ return e();
229
+ }
230
+ };
231
+ var E, b = {}, y = H.react_stack_bottom_frame.bind(
232
+ H,
233
+ s
234
+ )(), w = z(n(s)), F = {};
235
+ V.Fragment = u, V.jsx = function(e, c, d) {
236
+ var T = 1e4 > p.recentlyCreatedOwnerStacks++;
237
+ return a(
238
+ e,
239
+ c,
240
+ d,
241
+ !1,
242
+ T ? Error("react-stack-top-frame") : y,
243
+ T ? z(n(e)) : w
244
+ );
245
+ }, V.jsxs = function(e, c, d) {
246
+ var T = 1e4 > p.recentlyCreatedOwnerStacks++;
247
+ return a(
248
+ e,
249
+ c,
250
+ d,
251
+ !0,
252
+ T ? Error("react-stack-top-frame") : y,
253
+ T ? z(n(e)) : w
254
+ );
255
+ };
256
+ })()), V;
257
+ }
258
+ var rt;
259
+ function ut() {
260
+ return rt || (rt = 1, process.env.NODE_ENV === "production" ? J.exports = ct() : J.exports = lt()), J.exports;
261
+ }
262
+ var U = ut();
263
+ function Z(i) {
264
+ return !i && i !== 0 ? { top: 0, right: 0, bottom: 0, left: 0 } : typeof i == "number" ? { top: i, right: i, bottom: i, left: i } : { top: i.top ?? 0, right: i.right ?? 0, bottom: i.bottom ?? 0, left: i.left ?? 0 };
265
+ }
266
+ function Q(i) {
267
+ const t = i.replace("#", "");
268
+ if (t.length === 3) {
269
+ const r = parseInt(t[0] + t[0], 16), n = parseInt(t[1] + t[1], 16), o = parseInt(t[2] + t[2], 16);
270
+ return [r, n, o];
271
+ }
272
+ if (t.length === 6) {
273
+ const r = parseInt(t.slice(0, 2), 16), n = parseInt(t.slice(2, 4), 16), o = parseInt(t.slice(4, 6), 16);
274
+ return [r, n, o];
275
+ }
276
+ return null;
277
+ }
278
+ function ot(i, t = !0) {
279
+ if (i <= 0) return String(i);
280
+ const r = [
281
+ [1e3, "M"],
282
+ [900, "CM"],
283
+ [500, "D"],
284
+ [400, "CD"],
285
+ [100, "C"],
286
+ [90, "XC"],
287
+ [50, "L"],
288
+ [40, "XL"],
289
+ [10, "X"],
290
+ [9, "IX"],
291
+ [5, "V"],
292
+ [4, "IV"],
293
+ [1, "I"]
294
+ ];
295
+ let n = i, o = "";
296
+ for (const [s, f] of r)
297
+ for (; n >= s; )
298
+ o += f, n -= s;
299
+ return t ? o : o.toLowerCase();
300
+ }
301
+ class ht {
302
+ constructor(t = {}) {
303
+ this.cursorX = 0, this.cursorY = 0, this.contentWidth = 0, this.margin = { top: 15, right: 15, bottom: 15, left: 15 }, this.defaultFont = {
304
+ name: void 0,
305
+ style: "normal",
306
+ size: 12
307
+ }, this.defaultColor = "#111827", this.defaultLineHeight = 1.25, this.pendingTasks = /* @__PURE__ */ new Set(), this.opQueue = Promise.resolve(), this.margin = t.margin ?? this.margin, this.defaultFont = {
308
+ name: t.font?.name,
309
+ style: t.font?.style ?? "normal",
310
+ size: t.font?.size ?? 12
311
+ }, this.defaultColor = t.color ?? this.defaultColor, this.defaultLineHeight = t.lineHeight ?? this.defaultLineHeight, this.pdf = new ft({
312
+ unit: t.unit ?? "mm",
313
+ format: t.format ?? "a4",
314
+ orientation: t.orientation ?? "p"
315
+ }), this.pageWidth = this.pdf.internal.pageSize.getWidth(), this.pageHeight = this.pdf.internal.pageSize.getHeight(), this.resetFlowCursor(), this.applyBaseFont();
316
+ }
317
+ get instance() {
318
+ return this.pdf;
319
+ }
320
+ get width() {
321
+ return this.pageWidth;
322
+ }
323
+ get height() {
324
+ return this.pageHeight;
325
+ }
326
+ get contentLeft() {
327
+ return this.margin.left;
328
+ }
329
+ get contentRight() {
330
+ return this.pageWidth - this.margin.right;
331
+ }
332
+ get contentTop() {
333
+ return this.margin.top;
334
+ }
335
+ get contentBottom() {
336
+ return this.pageHeight - this.margin.bottom;
337
+ }
338
+ get contentHeight() {
339
+ return this.contentBottom - this.contentTop;
340
+ }
341
+ get contentAreaWidth() {
342
+ return this.contentWidth;
343
+ }
344
+ get baseFont() {
345
+ return this.defaultFont;
346
+ }
347
+ get baseLineHeight() {
348
+ return this.defaultLineHeight;
349
+ }
350
+ resetFlowCursor() {
351
+ this.cursorX = this.margin.left, this.cursorY = this.margin.top, this.contentWidth = this.pageWidth - this.margin.left - this.margin.right;
352
+ }
353
+ setHeaderFooter(t, r) {
354
+ this.headerDrawer = t, this.footerDrawer = r;
355
+ }
356
+ applyBaseFont() {
357
+ const t = this.defaultFont.name ?? this.pdf.getFont().fontName;
358
+ this.pdf.setFont(t, this.defaultFont.style), this.pdf.setFontSize(this.defaultFont.size);
359
+ const r = Q(this.defaultColor);
360
+ r && this.pdf.setTextColor(...r);
361
+ }
362
+ addPage() {
363
+ this.pdf.addPage(), this.resetFlowCursor();
364
+ }
365
+ ensureSpace(t) {
366
+ this.cursorY + t > this.contentBottom && this.addPage();
367
+ }
368
+ setTextStyle(t) {
369
+ if (t) {
370
+ if (t.fontSize && this.pdf.setFontSize(t.fontSize), t.fontStyle) {
371
+ const r = this.pdf.getFont().fontName;
372
+ this.pdf.setFont(r, t.fontStyle);
373
+ }
374
+ if (t.color) {
375
+ const r = Q(t.color);
376
+ r && this.pdf.setTextColor(...r);
377
+ }
378
+ }
379
+ }
380
+ textRaw(t, r, n, o, s, f = "left") {
381
+ this.setTextStyle(o);
382
+ const l = { align: f };
383
+ typeof s == "number" && (l.maxWidth = s), this.pdf.text(t, r, n, l), this.applyBaseFont();
384
+ }
385
+ box(t, r, n, o, s) {
386
+ const f = s ?? {};
387
+ if (f.fillColor) {
388
+ const l = Q(f.fillColor);
389
+ l && this.pdf.setFillColor(...l), this.pdf.rect(t, r, n, o, "F");
390
+ }
391
+ if (f.borderWidth || f.borderColor) {
392
+ if (f.borderWidth && this.pdf.setLineWidth(f.borderWidth), f.borderColor) {
393
+ const l = Q(f.borderColor);
394
+ l && this.pdf.setDrawColor(...l);
395
+ }
396
+ this.pdf.rect(t, r, n, o), this.pdf.setLineWidth(0.2), this.pdf.setDrawColor(0, 0, 0);
397
+ }
398
+ }
399
+ line(t, r, n, o) {
400
+ this.pdf.line(t, r, n, o);
401
+ }
402
+ async imageFromUrl(t, r = {}) {
403
+ const n = (async () => {
404
+ try {
405
+ const { dataUrl: o, width: s, height: f } = await this.loadImageAsDataURL(t), l = 0.264583, g = s * l, x = f * l;
406
+ let a = r.w, R = r.h;
407
+ a === void 0 && R === void 0 ? (a = g, R = x) : a === void 0 && R !== void 0 ? a = R * (g / x) : R === void 0 && a !== void 0 && (R = a * (x / g));
408
+ const h = a ?? g, H = R ?? x;
409
+ let j = r.x, C = r.y ?? this.cursorY;
410
+ if (r.y === void 0 && C + H > this.contentBottom && (this.addPage(), C = this.cursorY), j === void 0) {
411
+ const u = r.align ?? "left";
412
+ u === "left" ? j = this.contentLeft : u === "center" ? j = (this.contentLeft + this.contentRight) / 2 - h / 2 : u === "right" && (j = this.contentRight - h);
413
+ }
414
+ return this.pdf.addImage(
415
+ o,
416
+ r.mime ?? "PNG",
417
+ j,
418
+ C,
419
+ h,
420
+ H
421
+ ), { width: h, height: H, x: j, y: C };
422
+ } catch (o) {
423
+ return console.error("Failed to load image", t, o), { width: 0, height: 0, x: 0, y: 0 };
424
+ }
425
+ })();
426
+ return this.registerTask(n), n;
427
+ }
428
+ queueOperation(t) {
429
+ const r = this.opQueue.then(async () => {
430
+ try {
431
+ await t();
432
+ } catch (n) {
433
+ console.error("Operation failed", n);
434
+ }
435
+ });
436
+ this.opQueue = r, this.registerTask(r);
437
+ }
438
+ registerTask(t) {
439
+ this.pendingTasks.add(t), t.finally(() => {
440
+ this.pendingTasks.delete(t);
441
+ });
442
+ }
443
+ async waitForTasks() {
444
+ await Promise.all(this.pendingTasks), await this.opQueue;
445
+ }
446
+ loadImageAsDataURL(t) {
447
+ return new Promise((r, n) => {
448
+ const o = new Image();
449
+ o.crossOrigin = "anonymous", o.onload = () => {
450
+ const s = document.createElement("canvas");
451
+ s.width = o.width, s.height = o.height;
452
+ const f = s.getContext("2d");
453
+ if (!f) return n(new Error("Canvas 2D context not available"));
454
+ f.drawImage(o, 0, 0), r({
455
+ dataUrl: s.toDataURL("image/png"),
456
+ width: o.width,
457
+ height: o.height
458
+ });
459
+ }, o.onerror = (s) => n(s), o.src = t;
460
+ });
461
+ }
462
+ paragraph(t, r, n) {
463
+ const o = n ?? this.contentWidth;
464
+ this.setTextStyle(r);
465
+ const s = r?.lineHeight ?? this.defaultLineHeight, f = r?.fontSize ?? this.defaultFont.size, l = f * s * 0.3528, g = this.pdf.splitTextToSize(t, o), x = r?.align ?? "left";
466
+ let a = 0;
467
+ return g.forEach((R) => {
468
+ this.cursorY + l > this.contentBottom && this.addPage();
469
+ const h = this.cursorY + f * 0.3528;
470
+ this.pdf.text(R, this.cursorX, h, { align: x, maxWidth: o }), this.cursorY += l, a += l;
471
+ }), this.cursorY += 1, this.applyBaseFont(), a;
472
+ }
473
+ moveCursor(t, r) {
474
+ this.cursorX += t, this.cursorY += r;
475
+ }
476
+ setCursor(t, r) {
477
+ this.cursorX = t, this.cursorY = r;
478
+ }
479
+ getCursor() {
480
+ return { x: this.cursorX, y: this.cursorY };
481
+ }
482
+ getPageCount() {
483
+ return this.pdf.getNumberOfPages();
484
+ }
485
+ applyHeaderFooter() {
486
+ const t = this.getPageCount();
487
+ if (!(!this.headerDrawer && !this.footerDrawer)) {
488
+ for (let r = 1; r <= t; r++)
489
+ this.pdf.setPage(r), this.headerDrawer && this.headerDrawer(this.pdf, r, t, this), this.footerDrawer && this.footerDrawer(this.pdf, r, t, this);
490
+ this.pdf.setPage(t);
491
+ }
492
+ }
493
+ measureText(t, r, n) {
494
+ this.setTextStyle(r);
495
+ const o = r?.fontSize ?? this.defaultFont.size, s = r?.lineHeight ?? this.defaultLineHeight, f = o * s * 0.3528;
496
+ if (n) {
497
+ const l = this.pdf.splitTextToSize(t, n);
498
+ return {
499
+ width: n,
500
+ height: l.length * f
501
+ };
502
+ } else {
503
+ const l = this.pdf.getTextDimensions(t);
504
+ return { width: l.w, height: l.h };
505
+ }
506
+ }
507
+ setMetadata(t) {
508
+ t.title && this.pdf.setDocumentProperties({ title: t.title }), t.author && this.pdf.setDocumentProperties({ author: t.author }), t.subject && this.pdf.setDocumentProperties({ subject: t.subject }), t.keywords && this.pdf.setDocumentProperties({
509
+ keywords: t.keywords.join(", ")
510
+ });
511
+ }
512
+ save(t) {
513
+ this.applyHeaderFooter(), this.pdf.save(t);
514
+ }
515
+ }
516
+ const nt = st(null), q = () => {
517
+ const i = at(nt);
518
+ if (!i) throw new Error("usePdf must be used within <PdfDocument>");
519
+ return i;
520
+ }, wt = ({
521
+ options: i,
522
+ header: t,
523
+ footer: r,
524
+ pageNumbers: n,
525
+ centerLabel: o,
526
+ metadata: s,
527
+ children: f,
528
+ onReady: l,
529
+ filename: g,
530
+ autoSave: x = !1
531
+ }) => {
532
+ const [a] = A.useState(() => new ht(i));
533
+ return A.useEffect(() => {
534
+ s && a.setMetadata(s);
535
+ }, [a, s]), A.useEffect(() => {
536
+ const R = (C, u) => !u || u === "all" ? !0 : u === "first-only" ? C === 1 : u === "except-first" ? C > 1 : Array.isArray(u) ? u.includes(C) : !0, h = (C, u) => u === "roman-upper" ? ot(C, !0) : u === "roman-lower" ? ot(C, !1) : String(C), H = (C, u, O) => {
537
+ if (!n?.enabled || !R(u, n.scope)) return;
538
+ const M = n.preset ?? "page-slash-total", B = (n.template ?? (M === "page-slash-total" ? "Page {page}/{total}" : M === "page-of-total" ? "Page {page} of {total}" : "{page}/{total}")).replace("{page}", h(u, n.format)).replace("{total}", h(O, n.format)), X = n.align ?? "right", G = X === "left" ? a.contentLeft + (n.offsetX ?? 0) : X === "right" ? a.contentRight - (n.offsetX ?? 0) : (a.contentLeft + a.contentRight) / 2 + (n.offsetX ?? 0), m = C === "header" ? 10 : a.height - 7, v = typeof n.y == "number" ? n.y : m;
539
+ a.textRaw(B, G, v, n.style, void 0, X);
540
+ }, j = (C, u, O) => {
541
+ if (!o?.enabled || !R(u, o.scope)) return;
542
+ const M = "center", N = (a.contentLeft + a.contentRight) / 2 + (o.offsetX ?? 0), B = C === "header" ? 10 : a.height - 7, X = typeof o.y == "number" ? o.y : B;
543
+ a.textRaw(
544
+ o.text,
545
+ N,
546
+ X,
547
+ o.style,
548
+ void 0,
549
+ M
550
+ );
551
+ };
552
+ a.setHeaderFooter(
553
+ (C, u, O) => {
554
+ t && t(a, u, O), n?.position === "header" && H("header", u, O), o?.position === "header" && j("header", u);
555
+ },
556
+ (C, u, O) => {
557
+ n?.position === "footer" && H("footer", u, O), r && r(a, u, O), o?.position === "footer" && j("footer", u);
558
+ }
559
+ ), a.waitForTasks().then(() => {
560
+ l?.(a);
561
+ });
562
+ }, []), A.useEffect(() => {
563
+ x && g && a.save(g);
564
+ }, [x, g]), /* @__PURE__ */ U.jsx(nt.Provider, { value: a, children: f });
565
+ }, vt = ({
566
+ x: i,
567
+ y: t,
568
+ w: r,
569
+ h: n,
570
+ children: o,
571
+ ...s
572
+ }) => {
573
+ const f = q(), l = Z(s.padding), g = {
574
+ top: s.paddingTop ?? l.top,
575
+ right: s.paddingRight ?? l.right,
576
+ bottom: s.paddingBottom ?? l.bottom,
577
+ left: s.paddingLeft ?? l.left
578
+ }, x = A.useRef(
579
+ {}
580
+ ).current;
581
+ return typeof i == "number" && typeof t == "number" && typeof r == "number" && typeof n == "number" ? (A.useEffect(() => {
582
+ f.queueOperation(() => {
583
+ f.box(i, t, r, n, s);
584
+ });
585
+ }, [i, t, r, n]), /* @__PURE__ */ U.jsx(A.Fragment, { children: o })) : (A.useEffect(() => {
586
+ f.queueOperation(() => {
587
+ const a = f.getCursor();
588
+ x.start = { ...a };
589
+ const R = a.x + g.left, h = a.y + g.top;
590
+ f.setCursor(R, h);
591
+ });
592
+ }, []), /* @__PURE__ */ U.jsxs(A.Fragment, { children: [
593
+ o,
594
+ /* @__PURE__ */ U.jsx(dt, { boxState: x, pad: g, style: s })
595
+ ] }));
596
+ }, dt = ({ boxState: i, style: t, pad: r }) => {
597
+ const n = q();
598
+ return A.useEffect(() => {
599
+ n.queueOperation(() => {
600
+ const o = i.start;
601
+ if (!o) return;
602
+ const s = n.getCursor(), l = Math.max(s.y - o.y - r.top, 0) + r.top + r.bottom;
603
+ n.box(o.x, o.y, n.contentAreaWidth, l, t), n.setCursor(o.x, o.y + l);
604
+ });
605
+ }, []), null;
606
+ }, xt = ({
607
+ src: i,
608
+ x: t,
609
+ y: r,
610
+ w: n,
611
+ h: o,
612
+ mime: s = "PNG",
613
+ flow: f,
614
+ align: l = "left"
615
+ }) => {
616
+ const g = q();
617
+ return A.useEffect(() => {
618
+ const x = f === !0 || t === void 0 && r === void 0, a = t, R = r;
619
+ g.queueOperation(async () => {
620
+ const h = await g.imageFromUrl(i, {
621
+ x: a,
622
+ y: R,
623
+ w: n,
624
+ h: o,
625
+ mime: s,
626
+ align: l
627
+ });
628
+ x && h && g.moveCursor(0, h.height + 2);
629
+ });
630
+ }, [i, t, r, n, o, s, f, l]), null;
631
+ }, Rt = ({
632
+ items: i,
633
+ ordered: t = !1,
634
+ style: r,
635
+ indent: n = 5,
636
+ markerWidth: o = 5,
637
+ spacing: s = 2
638
+ }) => {
639
+ const f = q();
640
+ return A.useEffect(() => {
641
+ f.queueOperation(() => {
642
+ i.forEach((l, g) => {
643
+ const x = t ? `${g + 1}.` : "•", a = f.getCursor().y, R = f.getCursor().x, h = R + n + o, H = r?.fontSize ?? f.baseFont.size, j = a + H * 0.3528;
644
+ f.textRaw(
645
+ x,
646
+ R + n,
647
+ j,
648
+ r,
649
+ o,
650
+ "right"
651
+ ), f.setCursor(h, a);
652
+ const C = f.contentRight - h;
653
+ f.paragraph(l, r, C);
654
+ const u = f.getCursor().y;
655
+ f.setCursor(R, u + s);
656
+ });
657
+ });
658
+ }, [i, t, r, n, o, s]), null;
659
+ }, Et = ({
660
+ data: i,
661
+ columns: t,
662
+ width: r = "100%",
663
+ borderWidth: n = 0.1,
664
+ borderColor: o = "#000000",
665
+ cellPadding: s = 2,
666
+ headerStyle: f,
667
+ rowStyle: l,
668
+ alternateRowStyle: g,
669
+ headerHeight: x
670
+ }) => {
671
+ const a = q();
672
+ return A.useEffect(() => {
673
+ a.queueOperation(() => {
674
+ const R = typeof r == "number" ? r : parseFloat(r) / 100 * a.contentAreaWidth, h = t.map((m) => typeof m.width == "number" ? m.width : typeof m.width == "string" && m.width.endsWith("%") ? parseFloat(m.width) / 100 * R : 0), H = h.reduce((m, v) => m + v, 0), j = Math.max(0, R - H), C = h.filter((m) => m === 0).length;
675
+ if (C > 0) {
676
+ const m = j / C;
677
+ for (let v = 0; v < h.length; v++)
678
+ h[v] === 0 && (h[v] = m);
679
+ }
680
+ const u = (m, v, P, W, S, p, D = "left", Y = !0) => {
681
+ Y && a.box(v, P, W, S, {
682
+ borderColor: p.borderColor ?? o,
683
+ borderWidth: p.borderWidth ?? n,
684
+ fillColor: p.fillColor
685
+ });
686
+ const z = Z(p.padding ?? s), E = {
687
+ top: p.paddingTop ?? z.top,
688
+ right: p.paddingRight ?? z.right,
689
+ bottom: p.paddingBottom ?? z.bottom,
690
+ left: p.paddingLeft ?? z.left
691
+ }, b = W - E.left - E.right, y = a.instance.splitTextToSize(m, b, p), w = (p.fontSize ?? a.baseFont.size) * (p.lineHeight ?? a.baseLineHeight) * 0.3528, F = (p.fontSize ?? a.baseFont.size) * 0.3528, e = y.length * w, c = S - E.top - E.bottom;
692
+ let d = 0;
693
+ p.verticalAlign === "middle" ? d = Math.max(0, (c - e) / 2) : p.verticalAlign === "bottom" && (d = Math.max(0, c - e));
694
+ let T = P + E.top + d + F;
695
+ const L = p.align ?? D, _ = a.getCursor();
696
+ y.forEach((k) => {
697
+ let I = v + E.left;
698
+ L === "center" ? I = v + W / 2 : L === "right" && (I = v + W - E.right), a.textRaw(k, I, T, p, void 0, L), T += w;
699
+ }), a.setCursor(_.x, _.y);
700
+ };
701
+ let O = a.getCursor().y;
702
+ const M = a.getCursor().x, N = x ?? 10;
703
+ O + N > a.contentBottom && (a.addPage(), O = a.getCursor().y);
704
+ let B = M;
705
+ t.forEach((m, v) => {
706
+ const P = h[v];
707
+ u(
708
+ m.header ?? "",
709
+ B,
710
+ O,
711
+ P,
712
+ N,
713
+ f ?? { fontStyle: "bold" },
714
+ m.align ?? "left"
715
+ ), B += P;
716
+ }), O += N, a.setCursor(M, O);
717
+ const X = (m, v, P) => {
718
+ const W = Z(s), S = {
719
+ top: P.paddingTop ?? W.top,
720
+ right: P.paddingRight ?? W.right,
721
+ bottom: P.paddingBottom ?? W.bottom,
722
+ left: P.paddingLeft ?? W.left
723
+ }, p = v - S.left - S.right;
724
+ return a.measureText(m, P, p).height + S.top + S.bottom;
725
+ };
726
+ new Array(t.length).fill(0), (() => {
727
+ const m = new Array(i.length).fill(0);
728
+ for (let S = 0; S < i.length; S++) {
729
+ const p = i[S];
730
+ let D = 0;
731
+ for (let Y = 0; Y < t.length; Y++) {
732
+ const z = t[Y], E = typeof z.accessor == "function" ? z.accessor(p) : p[z.accessor];
733
+ let b = "", y = l, w = 1, F = 1;
734
+ if (E && typeof E == "object" && E.content !== void 0 ? (b = String(E.content), E.style && (y = E.style), E.colSpan && (w = E.colSpan), E.rowSpan && (F = E.rowSpan)) : b = String(E ?? ""), F > 1) {
735
+ Y += w - 1;
736
+ continue;
737
+ }
738
+ let e = h[Y];
739
+ for (let d = 1; d < w; d++)
740
+ Y + d < h.length && (e += h[Y + d]);
741
+ const c = X(b, e, y ?? {});
742
+ c > D && (D = c), Y += w - 1;
743
+ }
744
+ D < 8 && (D = 8), m[S] = D;
745
+ }
746
+ let v = O;
747
+ const P = new Array(t.length).fill(0), W = a.getCursor().x;
748
+ for (let S = 0; S < i.length; S++) {
749
+ const p = i[S], D = m[S];
750
+ let Y = D;
751
+ for (let b = 0; b < t.length; b++) {
752
+ const y = t[b], w = typeof y.accessor == "function" ? y.accessor(p) : p[y.accessor];
753
+ let F = 1;
754
+ if (w && typeof w == "object" && w.rowSpan && (F = w.rowSpan), F > 1) {
755
+ let e = 0;
756
+ for (let c = 0; c < F; c++)
757
+ S + c < m.length && (e += m[S + c]);
758
+ e > Y && (Y = e);
759
+ }
760
+ }
761
+ const z = Math.abs(v - (a.contentTop + (x ?? 10))) < 1;
762
+ if (v + Y > a.contentBottom && !z && (a.addPage(), v = a.getCursor().y, x !== 0)) {
763
+ let b = W;
764
+ t.forEach((y, w) => {
765
+ const F = h[w];
766
+ u(
767
+ y.header ?? "",
768
+ b,
769
+ v,
770
+ F,
771
+ x ?? 10,
772
+ f ?? { fontStyle: "bold" },
773
+ y.align ?? "left"
774
+ ), b += F;
775
+ }), v += x ?? 10;
776
+ }
777
+ let E = W;
778
+ for (let b = 0; b < t.length; b++) {
779
+ if (P[b] > 0) {
780
+ P[b]--, E += h[b];
781
+ continue;
782
+ }
783
+ const y = t[b], w = typeof y.accessor == "function" ? y.accessor(p) : p[y.accessor];
784
+ let F = 1, e = 1, c = S % 2 === 1 && g ? g : l, d = "";
785
+ w && typeof w == "object" && w.content !== void 0 ? (d = String(w.content), w.colSpan && (F = w.colSpan), w.rowSpan && (e = w.rowSpan), w.style && (c = { ...c, ...w.style })) : d = String(w ?? "");
786
+ let T = h[b];
787
+ for (let _ = 1; _ < F; _++)
788
+ b + _ < h.length && (T += h[b + _]);
789
+ let L = D;
790
+ if (e > 1)
791
+ for (let _ = 1; _ < e; _++)
792
+ S + _ < m.length && (L += m[S + _]);
793
+ if (u(
794
+ d,
795
+ E,
796
+ v,
797
+ T,
798
+ L,
799
+ c ?? {},
800
+ y.align ?? "left",
801
+ !0
802
+ ), e > 1) {
803
+ P[b] = e - 1;
804
+ for (let _ = 1; _ < F; _++)
805
+ b + _ < P.length && (P[b + _] = e - 1);
806
+ }
807
+ E += T, b += F - 1;
808
+ }
809
+ v += D;
810
+ }
811
+ a.setCursor(W, v);
812
+ })();
813
+ });
814
+ }, [i, t, r]), null;
815
+ }, Tt = ({
816
+ children: i,
817
+ x: t,
818
+ y: r,
819
+ maxWidth: n,
820
+ spacingBelow: o = 2,
821
+ ...s
822
+ }) => {
823
+ const f = q();
824
+ return A.useEffect(() => {
825
+ f.queueOperation(() => {
826
+ if (typeof t == "number" && typeof r == "number")
827
+ f.textRaw(i, t, r, s, n, s.align);
828
+ else {
829
+ f.paragraph(i, s, n);
830
+ const l = f.getCursor();
831
+ f.setCursor(l.x, l.y + o);
832
+ }
833
+ });
834
+ }, [i, t, r, n, o, s.fontSize, s.align]), null;
835
+ };
836
+ function gt(i) {
837
+ return typeof i == "number" ? { top: i, right: i, bottom: i, left: i } : {
838
+ top: i?.top ?? 0,
839
+ right: i?.right ?? 0,
840
+ bottom: i?.bottom ?? 0,
841
+ left: i?.left ?? 0
842
+ };
843
+ }
844
+ const Ct = ({ style: i = {}, children: t }) => {
845
+ const r = q(), n = Z(i.padding), o = {
846
+ top: i.paddingTop ?? n.top,
847
+ right: i.paddingRight ?? n.right,
848
+ bottom: i.paddingBottom ?? n.bottom,
849
+ left: i.paddingLeft ?? n.left
850
+ }, s = gt(i.margin), f = {
851
+ top: i.marginTop ?? s.top,
852
+ right: i.marginRight ?? s.right,
853
+ bottom: i.marginBottom ?? s.bottom,
854
+ left: i.marginLeft ?? s.left
855
+ }, l = A.useRef(
856
+ {}
857
+ ).current;
858
+ return A.useEffect(() => {
859
+ r.queueOperation(() => {
860
+ f.top > 0 && r.moveCursor(0, f.top);
861
+ const g = r.getCursor();
862
+ l.start = { ...g }, r.setCursor(g.x + o.left, g.y + o.top);
863
+ });
864
+ }, []), /* @__PURE__ */ U.jsxs(A.Fragment, { children: [
865
+ t,
866
+ /* @__PURE__ */ U.jsx(
867
+ pt,
868
+ {
869
+ viewState: l,
870
+ style: i,
871
+ pad: o,
872
+ margin: f
873
+ }
874
+ )
875
+ ] });
876
+ }, pt = ({ viewState: i, style: t, pad: r, margin: n }) => {
877
+ const o = q();
878
+ return A.useEffect(() => {
879
+ o.queueOperation(() => {
880
+ const s = i.start;
881
+ if (!s) return;
882
+ const f = o.getCursor();
883
+ let g = Math.max(f.y - s.y - r.top, 0) + r.top + r.bottom;
884
+ t.height && (g = t.height);
885
+ let x = o.contentAreaWidth;
886
+ typeof t.width == "number" && (x = t.width), (t.borderColor || t.fillColor || t.borderWidth) && o.box(s.x, s.y, x, g, t);
887
+ const a = s.y + g + n.bottom;
888
+ o.setCursor(s.x, a);
889
+ });
890
+ }, []), null;
891
+ };
892
+ export {
893
+ vt as PdfBox,
894
+ wt as PdfDocument,
895
+ xt as PdfImage,
896
+ Rt as PdfList,
897
+ ht as PdfRenderer,
898
+ Et as PdfTable,
899
+ Tt as PdfText,
900
+ Ct as PdfView
901
+ };