react-pdf-levelup 2.0.14 → 2.0.18
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/dist/index.d.mts +149 -0
- package/dist/index.d.ts +69 -60
- package/dist/index.js +261 -96
- package/dist/{index.cjs → index.mjs} +174 -181
- package/package.json +6 -5
- package/dist/index.d.cts +0 -140
|
@@ -1,91 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/components/core/index.tsx
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
A: () => A,
|
|
34
|
-
BR: () => BR,
|
|
35
|
-
Blockquote: () => Blockquote,
|
|
36
|
-
Center: () => Center,
|
|
37
|
-
Col1: () => Col1,
|
|
38
|
-
Col10: () => Col10,
|
|
39
|
-
Col11: () => Col11,
|
|
40
|
-
Col12: () => Col12,
|
|
41
|
-
Col2: () => Col2,
|
|
42
|
-
Col3: () => Col3,
|
|
43
|
-
Col4: () => Col4,
|
|
44
|
-
Col5: () => Col5,
|
|
45
|
-
Col6: () => Col6,
|
|
46
|
-
Col7: () => Col7,
|
|
47
|
-
Col8: () => Col8,
|
|
48
|
-
Col9: () => Col9,
|
|
49
|
-
Container: () => Container,
|
|
50
|
-
Em: () => Em,
|
|
51
|
-
Footer: () => Footer,
|
|
52
|
-
H1: () => H1,
|
|
53
|
-
H2: () => H2,
|
|
54
|
-
H3: () => H3,
|
|
55
|
-
H4: () => H4,
|
|
56
|
-
H5: () => H5,
|
|
57
|
-
H6: () => H6,
|
|
58
|
-
Header: () => Header,
|
|
59
|
-
Img: () => Img_default,
|
|
60
|
-
LI: () => LI,
|
|
61
|
-
LayoutPDF: () => LayoutPDF_default,
|
|
62
|
-
Left: () => Left,
|
|
63
|
-
Mark: () => Mark,
|
|
64
|
-
OL: () => OL,
|
|
65
|
-
P: () => P,
|
|
66
|
-
QR: () => QR_default,
|
|
67
|
-
Right: () => Right,
|
|
68
|
-
Row: () => Row,
|
|
69
|
-
Small: () => Small,
|
|
70
|
-
Span: () => Span,
|
|
71
|
-
Strong: () => Strong,
|
|
72
|
-
Table: () => Table,
|
|
73
|
-
Tbody: () => Tbody,
|
|
74
|
-
Td: () => Td,
|
|
75
|
-
Text: () => import_renderer10.Text,
|
|
76
|
-
Th: () => Th,
|
|
77
|
-
Thead: () => Thead,
|
|
78
|
-
Tr: () => Tr,
|
|
79
|
-
U: () => U,
|
|
80
|
-
UL: () => UL,
|
|
81
|
-
View: () => import_renderer10.View
|
|
82
|
-
});
|
|
83
|
-
module.exports = __toCommonJS(index_exports);
|
|
84
|
-
|
|
85
1
|
// src/components/core/LayoutPDF.tsx
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
var styles =
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Page, Document, StyleSheet, Text } from "@react-pdf/renderer";
|
|
4
|
+
var styles = StyleSheet.create({
|
|
89
5
|
page: {
|
|
90
6
|
backgroundColor: "white",
|
|
91
7
|
padding: 30,
|
|
@@ -96,7 +12,7 @@ var styles = import_renderer.StyleSheet.create({
|
|
|
96
12
|
pageNumber: {
|
|
97
13
|
position: "absolute",
|
|
98
14
|
fontSize: 10,
|
|
99
|
-
|
|
15
|
+
top: 792 - 14,
|
|
100
16
|
left: 0,
|
|
101
17
|
right: 0,
|
|
102
18
|
textAlign: "center",
|
|
@@ -109,15 +25,41 @@ var LayoutPDF = ({
|
|
|
109
25
|
orientation = "portrait",
|
|
110
26
|
backgroundColor = "white",
|
|
111
27
|
showPageNumbers = true,
|
|
28
|
+
padding = 30,
|
|
112
29
|
style = {}
|
|
113
30
|
}) => {
|
|
31
|
+
let safeSize = size;
|
|
32
|
+
let safeOrientation = orientation;
|
|
33
|
+
let safeBackgroundColor = backgroundColor;
|
|
34
|
+
let safeShowPageNumbers = showPageNumbers;
|
|
35
|
+
try {
|
|
36
|
+
const validSizes = ["A4", "A3", "A5", "LETTER", "LEGAL", "TABLOID"];
|
|
37
|
+
if (typeof size === "string" && !validSizes.includes(size.toUpperCase())) {
|
|
38
|
+
console.warn(`Tama\xF1o de p\xE1gina inv\xE1lido: ${size}. Usando A4 como valor predeterminado.`);
|
|
39
|
+
safeSize = "A4";
|
|
40
|
+
}
|
|
41
|
+
if (orientation !== "portrait" && orientation !== "landscape") {
|
|
42
|
+
console.warn(`Orientaci\xF3n inv\xE1lida: ${orientation}. Usando portrait como valor predeterminado.`);
|
|
43
|
+
safeOrientation = "portrait";
|
|
44
|
+
}
|
|
45
|
+
if (typeof backgroundColor !== "string") {
|
|
46
|
+
console.warn(`Color de fondo inv\xE1lido: ${backgroundColor}. Usando white como valor predeterminado.`);
|
|
47
|
+
safeBackgroundColor = "white";
|
|
48
|
+
}
|
|
49
|
+
if (typeof showPageNumbers !== "boolean") {
|
|
50
|
+
safeShowPageNumbers = Boolean(showPageNumbers);
|
|
51
|
+
}
|
|
52
|
+
} catch (e) {
|
|
53
|
+
console.warn("Error procesando props en LayoutPDF:", e);
|
|
54
|
+
}
|
|
114
55
|
const pageStyle = {
|
|
115
56
|
...styles.page,
|
|
116
|
-
backgroundColor,
|
|
57
|
+
backgroundColor: safeBackgroundColor,
|
|
58
|
+
padding,
|
|
117
59
|
...style
|
|
118
60
|
};
|
|
119
|
-
return /* @__PURE__ */
|
|
120
|
-
|
|
61
|
+
return /* @__PURE__ */ React.createElement(Document, null, /* @__PURE__ */ React.createElement(Page, { size: safeSize, orientation: safeOrientation, style: pageStyle }, children, safeShowPageNumbers && /* @__PURE__ */ React.createElement(
|
|
62
|
+
Text,
|
|
121
63
|
{
|
|
122
64
|
style: styles.pageNumber,
|
|
123
65
|
render: ({ pageNumber, totalPages }) => `${pageNumber} / ${totalPages}`,
|
|
@@ -128,9 +70,9 @@ var LayoutPDF = ({
|
|
|
128
70
|
var LayoutPDF_default = LayoutPDF;
|
|
129
71
|
|
|
130
72
|
// src/components/core/Img.tsx
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
var styles2 =
|
|
73
|
+
import React2 from "react";
|
|
74
|
+
import { Image as Image2, StyleSheet as StyleSheet2 } from "@react-pdf/renderer";
|
|
75
|
+
var styles2 = StyleSheet2.create({
|
|
134
76
|
image: {
|
|
135
77
|
width: "100%",
|
|
136
78
|
height: "auto",
|
|
@@ -138,14 +80,14 @@ var styles2 = import_renderer2.StyleSheet.create({
|
|
|
138
80
|
}
|
|
139
81
|
});
|
|
140
82
|
var Img = ({ src, style }) => {
|
|
141
|
-
return /* @__PURE__ */
|
|
83
|
+
return /* @__PURE__ */ React2.createElement(Image2, { src, style: [styles2.image, style] });
|
|
142
84
|
};
|
|
143
85
|
var Img_default = Img;
|
|
144
86
|
|
|
145
87
|
// src/components/core/Position.tsx
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
var styles3 =
|
|
88
|
+
import React3 from "react";
|
|
89
|
+
import { View, StyleSheet as StyleSheet3 } from "@react-pdf/renderer";
|
|
90
|
+
var styles3 = StyleSheet3.create({
|
|
149
91
|
left: {
|
|
150
92
|
textAlign: "left"
|
|
151
93
|
},
|
|
@@ -157,19 +99,19 @@ var styles3 = import_renderer3.StyleSheet.create({
|
|
|
157
99
|
}
|
|
158
100
|
});
|
|
159
101
|
var Left = ({ children, style }) => {
|
|
160
|
-
return /* @__PURE__ */
|
|
102
|
+
return /* @__PURE__ */ React3.createElement(View, { style: [styles3.left, style] }, children);
|
|
161
103
|
};
|
|
162
104
|
var Right = ({ children, style }) => {
|
|
163
|
-
return /* @__PURE__ */
|
|
105
|
+
return /* @__PURE__ */ React3.createElement(View, { style: [styles3.right, style] }, children);
|
|
164
106
|
};
|
|
165
107
|
var Center = ({ children, style }) => {
|
|
166
|
-
return /* @__PURE__ */
|
|
108
|
+
return /* @__PURE__ */ React3.createElement(View, { style: [styles3.center, style] }, children);
|
|
167
109
|
};
|
|
168
110
|
|
|
169
111
|
// src/components/core/Etiquetas.tsx
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
var styles4 =
|
|
112
|
+
import React4 from "react";
|
|
113
|
+
import { Text as Text2, StyleSheet as StyleSheet4, Link } from "@react-pdf/renderer";
|
|
114
|
+
var styles4 = StyleSheet4.create({
|
|
173
115
|
p: {
|
|
174
116
|
fontSize: 12,
|
|
175
117
|
marginBottom: 14,
|
|
@@ -239,58 +181,58 @@ var styles4 = import_renderer4.StyleSheet.create({
|
|
|
239
181
|
}
|
|
240
182
|
});
|
|
241
183
|
var P = ({ children, style }) => {
|
|
242
|
-
return /* @__PURE__ */
|
|
184
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.p, style] }, children);
|
|
243
185
|
};
|
|
244
186
|
var H1 = ({ children, style }) => {
|
|
245
|
-
return /* @__PURE__ */
|
|
187
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.h1, style] }, children);
|
|
246
188
|
};
|
|
247
189
|
var H2 = ({ children, style }) => {
|
|
248
|
-
return /* @__PURE__ */
|
|
190
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.h2, style] }, children);
|
|
249
191
|
};
|
|
250
192
|
var H3 = ({ children, style }) => {
|
|
251
|
-
return /* @__PURE__ */
|
|
193
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.h3, style] }, children);
|
|
252
194
|
};
|
|
253
195
|
var H4 = ({ children, style }) => {
|
|
254
|
-
return /* @__PURE__ */
|
|
196
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.h4, style] }, children);
|
|
255
197
|
};
|
|
256
198
|
var H5 = ({ children, style }) => {
|
|
257
|
-
return /* @__PURE__ */
|
|
199
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.h5, style] }, children);
|
|
258
200
|
};
|
|
259
201
|
var H6 = ({ children, style }) => {
|
|
260
|
-
return /* @__PURE__ */
|
|
202
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.h6, style] }, children);
|
|
261
203
|
};
|
|
262
204
|
var Strong = ({ children, style }) => {
|
|
263
|
-
return /* @__PURE__ */
|
|
205
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.strong, style] }, children);
|
|
264
206
|
};
|
|
265
207
|
var Em = ({ children, style }) => {
|
|
266
|
-
return /* @__PURE__ */
|
|
208
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.em, style] }, children);
|
|
267
209
|
};
|
|
268
210
|
var U = ({ children, style }) => {
|
|
269
|
-
return /* @__PURE__ */
|
|
211
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.u, style] }, children);
|
|
270
212
|
};
|
|
271
213
|
var Small = ({ children, style }) => {
|
|
272
|
-
return /* @__PURE__ */
|
|
214
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.small, style] }, children);
|
|
273
215
|
};
|
|
274
216
|
var Blockquote = ({ children, style }) => {
|
|
275
|
-
return /* @__PURE__ */
|
|
217
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.blockquote, style] }, children);
|
|
276
218
|
};
|
|
277
219
|
var Mark = ({ children, style }) => {
|
|
278
|
-
return /* @__PURE__ */
|
|
220
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.mark, style] }, children);
|
|
279
221
|
};
|
|
280
222
|
var A = ({ children, style, href }) => {
|
|
281
|
-
return /* @__PURE__ */
|
|
223
|
+
return /* @__PURE__ */ React4.createElement(Link, { src: href, style: [styles4.A, style] }, children);
|
|
282
224
|
};
|
|
283
225
|
var BR = ({ style }) => {
|
|
284
|
-
return /* @__PURE__ */
|
|
226
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [styles4.br, style] }, "\n");
|
|
285
227
|
};
|
|
286
228
|
var Span = ({ children, style }) => {
|
|
287
|
-
return /* @__PURE__ */
|
|
229
|
+
return /* @__PURE__ */ React4.createElement(Text2, { style: [style] }, children);
|
|
288
230
|
};
|
|
289
231
|
|
|
290
232
|
// src/components/core/Tablet.tsx
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
var styles5 =
|
|
233
|
+
import React5 from "react";
|
|
234
|
+
import { View as View2, Text as Text3, StyleSheet as StyleSheet5 } from "@react-pdf/renderer";
|
|
235
|
+
var styles5 = StyleSheet5.create({
|
|
294
236
|
table: {
|
|
295
237
|
width: "100%",
|
|
296
238
|
borderWidth: 1,
|
|
@@ -341,16 +283,16 @@ var cellSizeMapping = {
|
|
|
341
283
|
large: styles5.cellLarge
|
|
342
284
|
};
|
|
343
285
|
var Table = ({ children, style }) => {
|
|
344
|
-
return /* @__PURE__ */
|
|
286
|
+
return /* @__PURE__ */ React5.createElement(View2, { style: [styles5.table, style] }, children);
|
|
345
287
|
};
|
|
346
288
|
var Thead = ({ children, style }) => {
|
|
347
|
-
return /* @__PURE__ */
|
|
289
|
+
return /* @__PURE__ */ React5.createElement(View2, { style: [styles5.thead, style] }, children);
|
|
348
290
|
};
|
|
349
291
|
var Tbody = ({ children, style }) => {
|
|
350
|
-
return /* @__PURE__ */
|
|
292
|
+
return /* @__PURE__ */ React5.createElement(View2, { style: [styles5.tbody, style] }, children);
|
|
351
293
|
};
|
|
352
294
|
var Tr = ({ children, style }) => {
|
|
353
|
-
return /* @__PURE__ */
|
|
295
|
+
return /* @__PURE__ */ React5.createElement(View2, { style: [styles5.tr, style] }, children);
|
|
354
296
|
};
|
|
355
297
|
var Th = ({ children, style, cellSize = "medium", width, height, colSpan }) => {
|
|
356
298
|
const spanWidth = colSpan ? `${100 / 3 * colSpan}%` : void 0;
|
|
@@ -359,7 +301,7 @@ var Th = ({ children, style, cellSize = "medium", width, height, colSpan }) => {
|
|
|
359
301
|
width: width || spanWidth || sizeStyle?.width,
|
|
360
302
|
...height !== void 0 && { height }
|
|
361
303
|
};
|
|
362
|
-
return /* @__PURE__ */
|
|
304
|
+
return /* @__PURE__ */ React5.createElement(View2, { style: [styles5.th, customStyle, style] }, /* @__PURE__ */ React5.createElement(Text3, null, children));
|
|
363
305
|
};
|
|
364
306
|
var Td = ({ children, style, cellSize = "medium", width, height, colSpan }) => {
|
|
365
307
|
const spanWidth = colSpan ? `${100 / 3 * colSpan}%` : void 0;
|
|
@@ -368,13 +310,13 @@ var Td = ({ children, style, cellSize = "medium", width, height, colSpan }) => {
|
|
|
368
310
|
width: width || spanWidth || sizeStyle?.width,
|
|
369
311
|
...height !== void 0 && { height }
|
|
370
312
|
};
|
|
371
|
-
return /* @__PURE__ */
|
|
313
|
+
return /* @__PURE__ */ React5.createElement(View2, { style: [styles5.td, customStyle, style] }, /* @__PURE__ */ React5.createElement(Text3, null, children));
|
|
372
314
|
};
|
|
373
315
|
|
|
374
316
|
// src/components/core/Grid.tsx
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
var styles6 =
|
|
317
|
+
import React6 from "react";
|
|
318
|
+
import { View as View3, StyleSheet as StyleSheet6 } from "@react-pdf/renderer";
|
|
319
|
+
var styles6 = StyleSheet6.create({
|
|
378
320
|
container: {
|
|
379
321
|
width: "100%",
|
|
380
322
|
paddingHorizontal: 20
|
|
@@ -401,52 +343,52 @@ var styles6 = import_renderer6.StyleSheet.create({
|
|
|
401
343
|
col12: { width: "100%" }
|
|
402
344
|
});
|
|
403
345
|
var Container = ({ children, style }) => {
|
|
404
|
-
return /* @__PURE__ */
|
|
346
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.container, style] }, children);
|
|
405
347
|
};
|
|
406
348
|
var Row = ({ children, style }) => {
|
|
407
|
-
return /* @__PURE__ */
|
|
349
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.row, style] }, children);
|
|
408
350
|
};
|
|
409
351
|
var Col1 = ({ children, style }) => {
|
|
410
|
-
return /* @__PURE__ */
|
|
352
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.col, styles6.col1, style] }, children);
|
|
411
353
|
};
|
|
412
354
|
var Col2 = ({ children, style }) => {
|
|
413
|
-
return /* @__PURE__ */
|
|
355
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.col, styles6.col2, style] }, children);
|
|
414
356
|
};
|
|
415
357
|
var Col3 = ({ children, style }) => {
|
|
416
|
-
return /* @__PURE__ */
|
|
358
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.col, styles6.col3, style] }, children);
|
|
417
359
|
};
|
|
418
360
|
var Col4 = ({ children, style }) => {
|
|
419
|
-
return /* @__PURE__ */
|
|
361
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.col, styles6.col4, style] }, children);
|
|
420
362
|
};
|
|
421
363
|
var Col5 = ({ children, style }) => {
|
|
422
|
-
return /* @__PURE__ */
|
|
364
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.col, styles6.col5, style] }, children);
|
|
423
365
|
};
|
|
424
366
|
var Col6 = ({ children, style }) => {
|
|
425
|
-
return /* @__PURE__ */
|
|
367
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.col, styles6.col6, style] }, children);
|
|
426
368
|
};
|
|
427
369
|
var Col7 = ({ children, style }) => {
|
|
428
|
-
return /* @__PURE__ */
|
|
370
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.col, styles6.col7, style] }, children);
|
|
429
371
|
};
|
|
430
372
|
var Col8 = ({ children, style }) => {
|
|
431
|
-
return /* @__PURE__ */
|
|
373
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.col, styles6.col8, style] }, children);
|
|
432
374
|
};
|
|
433
375
|
var Col9 = ({ children, style }) => {
|
|
434
|
-
return /* @__PURE__ */
|
|
376
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.col, styles6.col9, style] }, children);
|
|
435
377
|
};
|
|
436
378
|
var Col10 = ({ children, style }) => {
|
|
437
|
-
return /* @__PURE__ */
|
|
379
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.col, styles6.col10, style] }, children);
|
|
438
380
|
};
|
|
439
381
|
var Col11 = ({ children, style }) => {
|
|
440
|
-
return /* @__PURE__ */
|
|
382
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.col, styles6.col11, style] }, children);
|
|
441
383
|
};
|
|
442
384
|
var Col12 = ({ children, style }) => {
|
|
443
|
-
return /* @__PURE__ */
|
|
385
|
+
return /* @__PURE__ */ React6.createElement(View3, { style: [styles6.col, styles6.col12, style] }, children);
|
|
444
386
|
};
|
|
445
387
|
|
|
446
388
|
// src/components/core/PageElements.tsx
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
var styles7 =
|
|
389
|
+
import React7 from "react";
|
|
390
|
+
import { Text as Text4, View as View4, StyleSheet as StyleSheet7 } from "@react-pdf/renderer";
|
|
391
|
+
var styles7 = StyleSheet7.create({
|
|
450
392
|
header: {
|
|
451
393
|
position: "absolute",
|
|
452
394
|
top: 20,
|
|
@@ -469,19 +411,19 @@ var styles7 = import_renderer7.StyleSheet.create({
|
|
|
469
411
|
}
|
|
470
412
|
});
|
|
471
413
|
var Header = ({ children, style, fixed = false }) => {
|
|
472
|
-
return /* @__PURE__ */
|
|
414
|
+
return /* @__PURE__ */ React7.createElement(View4, { style: [styles7.header, style], fixed }, typeof children === "string" ? /* @__PURE__ */ React7.createElement(Text4, null, children) : children);
|
|
473
415
|
};
|
|
474
416
|
var Footer = ({ children, style, fixed = false }) => {
|
|
475
|
-
return /* @__PURE__ */
|
|
417
|
+
return /* @__PURE__ */ React7.createElement(View4, { style: [styles7.footer, style], fixed }, typeof children === "string" ? /* @__PURE__ */ React7.createElement(Text4, null, children) : children);
|
|
476
418
|
};
|
|
477
419
|
|
|
478
420
|
// src/components/core/QR.tsx
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
421
|
+
import React8 from "react";
|
|
422
|
+
import { Image as Image3, StyleSheet as StyleSheet8, View as View5 } from "@react-pdf/renderer";
|
|
423
|
+
import { useEffect, useState } from "react";
|
|
482
424
|
|
|
483
425
|
// src/components/core/QRGenerator.tsx
|
|
484
|
-
|
|
426
|
+
import QRCode from "qrcode";
|
|
485
427
|
var generateQRAsBase64 = async ({
|
|
486
428
|
value,
|
|
487
429
|
size = 150,
|
|
@@ -502,7 +444,7 @@ var generateQRAsBase64 = async ({
|
|
|
502
444
|
},
|
|
503
445
|
width: size
|
|
504
446
|
};
|
|
505
|
-
const qrDataUrl =
|
|
447
|
+
const qrDataUrl = QRCode.toDataURL(value, options);
|
|
506
448
|
return qrDataUrl;
|
|
507
449
|
} catch (error) {
|
|
508
450
|
console.error("Error generando QR:", error);
|
|
@@ -558,7 +500,7 @@ var addLogoToQR = async (qrDataUrl, logoUrl, logoWidth, logoHeight) => {
|
|
|
558
500
|
};
|
|
559
501
|
|
|
560
502
|
// src/components/core/QR.tsx
|
|
561
|
-
var styles8 =
|
|
503
|
+
var styles8 = StyleSheet8.create({
|
|
562
504
|
qrContainer: {
|
|
563
505
|
display: "flex",
|
|
564
506
|
alignItems: "center",
|
|
@@ -584,8 +526,8 @@ var QR = ({
|
|
|
584
526
|
logoHeight = 30,
|
|
585
527
|
errorCorrectionLevel = "M"
|
|
586
528
|
}) => {
|
|
587
|
-
const [qrDataUrl, setQrDataUrl] =
|
|
588
|
-
|
|
529
|
+
const [qrDataUrl, setQrDataUrl] = useState("");
|
|
530
|
+
useEffect(() => {
|
|
589
531
|
const generateQR = async () => {
|
|
590
532
|
try {
|
|
591
533
|
const baseQrDataUrl = await generateQRAsBase64({
|
|
@@ -617,14 +559,14 @@ var QR = ({
|
|
|
617
559
|
const fallbackUrl = `https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(
|
|
618
560
|
value
|
|
619
561
|
)}&size=${size}x${size}`;
|
|
620
|
-
return /* @__PURE__ */
|
|
562
|
+
return /* @__PURE__ */ React8.createElement(View5, { style: [styles8.qrContainer, style] }, /* @__PURE__ */ React8.createElement(Image3, { src: qrDataUrl || fallbackUrl, style: { width: size, height: size } }));
|
|
621
563
|
};
|
|
622
564
|
var QR_default = QR;
|
|
623
565
|
|
|
624
566
|
// src/components/core/Lista.tsx
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
var styles9 =
|
|
567
|
+
import React9 from "react";
|
|
568
|
+
import { View as View6, Text as Text5, StyleSheet as StyleSheet9 } from "@react-pdf/renderer";
|
|
569
|
+
var styles9 = StyleSheet9.create({
|
|
628
570
|
ul: {
|
|
629
571
|
marginBottom: 10,
|
|
630
572
|
paddingLeft: 15
|
|
@@ -684,9 +626,9 @@ var toRoman = (num) => {
|
|
|
684
626
|
return romanNumerals[3][Math.floor(num / 1e3)] + romanNumerals[2][Math.floor(num % 1e3 / 100)] + romanNumerals[1][Math.floor(num % 100 / 10)] + romanNumerals[0][num % 10];
|
|
685
627
|
};
|
|
686
628
|
var UL = ({ children, style, type = "disc" }) => {
|
|
687
|
-
const childrenWithBullets =
|
|
688
|
-
if (
|
|
689
|
-
return
|
|
629
|
+
const childrenWithBullets = React9.Children.map(children, (child, index) => {
|
|
630
|
+
if (React9.isValidElement(child)) {
|
|
631
|
+
return React9.cloneElement(child, {
|
|
690
632
|
bulletType: type,
|
|
691
633
|
isOrdered: false,
|
|
692
634
|
index: index + 1
|
|
@@ -694,12 +636,12 @@ var UL = ({ children, style, type = "disc" }) => {
|
|
|
694
636
|
}
|
|
695
637
|
return child;
|
|
696
638
|
});
|
|
697
|
-
return /* @__PURE__ */
|
|
639
|
+
return /* @__PURE__ */ React9.createElement(View6, { style: [styles9.ul, style] }, childrenWithBullets);
|
|
698
640
|
};
|
|
699
641
|
var OL = ({ children, style, type = "decimal", start = 1 }) => {
|
|
700
|
-
const childrenWithNumbers =
|
|
701
|
-
if (
|
|
702
|
-
return
|
|
642
|
+
const childrenWithNumbers = React9.Children.map(children, (child, index) => {
|
|
643
|
+
if (React9.isValidElement(child)) {
|
|
644
|
+
return React9.cloneElement(child, {
|
|
703
645
|
bulletType: type,
|
|
704
646
|
isOrdered: true,
|
|
705
647
|
index: index + 1,
|
|
@@ -708,7 +650,7 @@ var OL = ({ children, style, type = "decimal", start = 1 }) => {
|
|
|
708
650
|
}
|
|
709
651
|
return child;
|
|
710
652
|
});
|
|
711
|
-
return /* @__PURE__ */
|
|
653
|
+
return /* @__PURE__ */ React9.createElement(View6, { style: [styles9.ol, style] }, childrenWithNumbers);
|
|
712
654
|
};
|
|
713
655
|
var LI = ({ children, style, bulletType = "disc", isOrdered = false, index = 1, start = 1, value }) => {
|
|
714
656
|
let marker;
|
|
@@ -718,13 +660,62 @@ var LI = ({ children, style, bulletType = "disc", isOrdered = false, index = 1,
|
|
|
718
660
|
} else {
|
|
719
661
|
marker = getBulletPoint(bulletType);
|
|
720
662
|
}
|
|
721
|
-
return /* @__PURE__ */
|
|
663
|
+
return /* @__PURE__ */ React9.createElement(View6, { style: [styles9.li, style] }, /* @__PURE__ */ React9.createElement(Text5, { style: styles9.bulletPoint }, marker), /* @__PURE__ */ React9.createElement(View6, { style: styles9.itemContent }, typeof children === "string" ? /* @__PURE__ */ React9.createElement(Text5, null, children) : children));
|
|
722
664
|
};
|
|
723
665
|
|
|
724
666
|
// src/components/core/index.tsx
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
667
|
+
import { View as View7, Text as Text6 } from "@react-pdf/renderer";
|
|
668
|
+
|
|
669
|
+
// src/functions/decodeBase64Pdf.ts
|
|
670
|
+
var decodeBase64Pdf = (base64, fileName) => {
|
|
671
|
+
const byteCharacters = atob(base64);
|
|
672
|
+
const byteNumbers = new Array(byteCharacters.length);
|
|
673
|
+
for (let i = 0; i < byteCharacters.length; i++) {
|
|
674
|
+
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
675
|
+
}
|
|
676
|
+
const byteArray = new Uint8Array(byteNumbers);
|
|
677
|
+
const blob = new Blob([byteArray], { type: "application/pdf" });
|
|
678
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
679
|
+
if (document === void 0) {
|
|
680
|
+
console.error("document is undefined, only works in browser context");
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
const link = document.createElement("a");
|
|
684
|
+
link.href = blobUrl;
|
|
685
|
+
link.download = fileName;
|
|
686
|
+
document.body.appendChild(link);
|
|
687
|
+
link.click();
|
|
688
|
+
document.body.removeChild(link);
|
|
689
|
+
window.open(blobUrl, "_blank");
|
|
690
|
+
setTimeout(() => {
|
|
691
|
+
URL.revokeObjectURL(blobUrl);
|
|
692
|
+
}, 100);
|
|
693
|
+
};
|
|
694
|
+
var decodeBase64Pdf_default = decodeBase64Pdf;
|
|
695
|
+
|
|
696
|
+
// src/functions/generatePDF.ts
|
|
697
|
+
import { renderToStream } from "@react-pdf/renderer";
|
|
698
|
+
import { createElement } from "react";
|
|
699
|
+
var generatePDF = async ({ template: Template, data }) => {
|
|
700
|
+
try {
|
|
701
|
+
if (!Template) {
|
|
702
|
+
throw new Error("Template not provided");
|
|
703
|
+
}
|
|
704
|
+
const MyDocument = createElement(Template, { data });
|
|
705
|
+
const stream = await renderToStream(MyDocument);
|
|
706
|
+
const base64String = await new Promise((resolve, reject) => {
|
|
707
|
+
const chunks = [];
|
|
708
|
+
stream.on("data", (chunk) => chunks.push(chunk));
|
|
709
|
+
stream.on("end", () => resolve(Buffer.concat(chunks).toString("base64")));
|
|
710
|
+
stream.on("error", (error) => reject(error));
|
|
711
|
+
});
|
|
712
|
+
return base64String;
|
|
713
|
+
} catch (error) {
|
|
714
|
+
throw new Error("Error generating PDF: " + (error instanceof Error ? error.message : "Unknown error"));
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
var generatePDF_default = generatePDF;
|
|
718
|
+
export {
|
|
728
719
|
A,
|
|
729
720
|
BR,
|
|
730
721
|
Blockquote,
|
|
@@ -751,14 +742,14 @@ var import_renderer10 = require("@react-pdf/renderer");
|
|
|
751
742
|
H5,
|
|
752
743
|
H6,
|
|
753
744
|
Header,
|
|
754
|
-
Img,
|
|
745
|
+
Img_default as Img,
|
|
755
746
|
LI,
|
|
756
|
-
LayoutPDF,
|
|
747
|
+
LayoutPDF_default as LayoutPDF,
|
|
757
748
|
Left,
|
|
758
749
|
Mark,
|
|
759
750
|
OL,
|
|
760
751
|
P,
|
|
761
|
-
QR,
|
|
752
|
+
QR_default as QR,
|
|
762
753
|
Right,
|
|
763
754
|
Row,
|
|
764
755
|
Small,
|
|
@@ -767,11 +758,13 @@ var import_renderer10 = require("@react-pdf/renderer");
|
|
|
767
758
|
Table,
|
|
768
759
|
Tbody,
|
|
769
760
|
Td,
|
|
770
|
-
Text,
|
|
761
|
+
Text6 as Text,
|
|
771
762
|
Th,
|
|
772
763
|
Thead,
|
|
773
764
|
Tr,
|
|
774
765
|
U,
|
|
775
766
|
UL,
|
|
776
|
-
View
|
|
777
|
-
|
|
767
|
+
View7 as View,
|
|
768
|
+
decodeBase64Pdf_default as decodeBase64Pdf,
|
|
769
|
+
generatePDF_default as generatePDF
|
|
770
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-pdf-levelup",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "2.0.18",
|
|
5
4
|
"main": "dist/index.js",
|
|
6
5
|
"types": "dist/index.d.ts",
|
|
7
6
|
"files": [
|
|
@@ -16,7 +15,8 @@
|
|
|
16
15
|
"update-jsx": "node ./fn/updateTsconfig.js",
|
|
17
16
|
"clean-dist": "rimraf dist",
|
|
18
17
|
"build-lib": "npm run clean-dist && tsup",
|
|
19
|
-
"publicar": "npm run upVersion && npm run update-jsx && npm run build-lib && npm publish"
|
|
18
|
+
"publicar": "npm run upVersion && npm run update-jsx && npm run build-lib && npm publish",
|
|
19
|
+
"demo": "ts-node ./src/useExample/index.ts"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@babel/standalone": "^7.23.10",
|
|
@@ -27,9 +27,10 @@
|
|
|
27
27
|
"qrcode": "^1.5.4",
|
|
28
28
|
"react": "^18.2.0",
|
|
29
29
|
"react-dom": "^18.2.0",
|
|
30
|
-
"react-pdf-levelup": "^2.0.
|
|
30
|
+
"react-pdf-levelup": "^2.0.17",
|
|
31
31
|
"react-router-dom": "^7.4.1",
|
|
32
|
-
"rimraf": "^6.0.1"
|
|
32
|
+
"rimraf": "^6.0.1",
|
|
33
|
+
"ts-node": "^10.9.2"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@eslint/js": "^9.21.0",
|