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