react-pdf-levelup 2.0.21 → 2.0.25
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.js +46 -24
- package/dist/index.mjs +33 -11
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -527,9 +527,31 @@ var Footer = ({ children, style, fixed = false }) => {
|
|
|
527
527
|
|
|
528
528
|
// src/components/core/QR.tsx
|
|
529
529
|
var import_react8 = __toESM(require("react"));
|
|
530
|
-
var import_react9 = require("react");
|
|
531
530
|
var import_renderer8 = require("@react-pdf/renderer");
|
|
532
531
|
var import_qr_code_styling = __toESM(require("qr-code-styling"));
|
|
532
|
+
if (typeof window === "undefined" && typeof process !== "undefined") {
|
|
533
|
+
try {
|
|
534
|
+
import("jsdom").then((jsdom) => {
|
|
535
|
+
const { JSDOM } = jsdom;
|
|
536
|
+
import("canvas").then((canvas) => {
|
|
537
|
+
const { Canvas, Image: CanvasImage } = canvas;
|
|
538
|
+
const { window: domWindow } = new JSDOM("<!DOCTYPE html><html><body></body></html>");
|
|
539
|
+
global.window = domWindow;
|
|
540
|
+
global.document = domWindow.document;
|
|
541
|
+
global.HTMLElement = domWindow.HTMLElement;
|
|
542
|
+
global.HTMLCanvasElement = Canvas;
|
|
543
|
+
global.CanvasRenderingContext2D = Canvas;
|
|
544
|
+
global.Image = CanvasImage;
|
|
545
|
+
}).catch((err) => {
|
|
546
|
+
console.error("Error loading canvas:", err);
|
|
547
|
+
});
|
|
548
|
+
}).catch((err) => {
|
|
549
|
+
console.error("Error loading jsdom:", err);
|
|
550
|
+
});
|
|
551
|
+
} catch (error) {
|
|
552
|
+
console.error("Error setting up Node.js environment:", error);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
533
555
|
var QR = ({
|
|
534
556
|
url,
|
|
535
557
|
size = 200,
|
|
@@ -556,11 +578,13 @@ var QR = ({
|
|
|
556
578
|
textPadding = 1,
|
|
557
579
|
textBold = true
|
|
558
580
|
}) => {
|
|
559
|
-
const [qrDataURL, setQrDataURL] = (0,
|
|
581
|
+
const [qrDataURL, setQrDataURL] = (0, import_react8.useState)(null);
|
|
560
582
|
const actualLogoWidth = logoWidth || Math.floor(size * 0.2);
|
|
561
583
|
const actualLogoHeight = logoHeight || actualLogoWidth;
|
|
562
|
-
(0,
|
|
563
|
-
if (typeof window === "undefined")
|
|
584
|
+
(0, import_react8.useEffect)(() => {
|
|
585
|
+
if (typeof window === "undefined") {
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
564
588
|
const generateQRCode = async () => {
|
|
565
589
|
try {
|
|
566
590
|
const qrCode = new import_qr_code_styling.default({
|
|
@@ -610,11 +634,11 @@ var QR = ({
|
|
|
610
634
|
}
|
|
611
635
|
document.body.removeChild(container);
|
|
612
636
|
} catch (error) {
|
|
613
|
-
console.error("Error
|
|
637
|
+
console.error("Error capturando QR:", error);
|
|
614
638
|
}
|
|
615
639
|
}, 100);
|
|
616
640
|
} catch (error) {
|
|
617
|
-
console.error("Error
|
|
641
|
+
console.error("Error generando QR:", error);
|
|
618
642
|
}
|
|
619
643
|
};
|
|
620
644
|
generateQRCode();
|
|
@@ -635,14 +659,14 @@ var QR = ({
|
|
|
635
659
|
if (!qrDataURL) return null;
|
|
636
660
|
const centerPosition = size / 2;
|
|
637
661
|
const logoContainerSize = Math.max(actualLogoWidth, actualLogoHeight) + 10;
|
|
638
|
-
return /* @__PURE__ */ import_react8.default.createElement(import_renderer8.View, { style: { width: size, height: size, position: "relative", ...style } }, /* @__PURE__ */ import_react8.default.createElement(import_renderer8.Image, { src: qrDataURL
|
|
662
|
+
return /* @__PURE__ */ import_react8.default.createElement(import_renderer8.View, { style: { width: size, height: size, position: "relative", ...style } }, /* @__PURE__ */ import_react8.default.createElement(import_renderer8.Image, { src: qrDataURL, style: { width: size, height: size } }), logo && /* @__PURE__ */ import_react8.default.createElement(
|
|
639
663
|
import_renderer8.View,
|
|
640
664
|
{
|
|
641
665
|
style: {
|
|
642
666
|
position: "absolute",
|
|
643
667
|
width: logoContainerSize,
|
|
644
668
|
height: logoContainerSize,
|
|
645
|
-
backgroundColor: logoBG
|
|
669
|
+
backgroundColor: logoBG,
|
|
646
670
|
left: centerPosition - logoContainerSize / 2,
|
|
647
671
|
top: centerPosition - logoContainerSize / 2,
|
|
648
672
|
borderRadius: 100,
|
|
@@ -653,11 +677,11 @@ var QR = ({
|
|
|
653
677
|
/* @__PURE__ */ import_react8.default.createElement(
|
|
654
678
|
import_renderer8.Image,
|
|
655
679
|
{
|
|
656
|
-
src: logo
|
|
680
|
+
src: logo,
|
|
657
681
|
style: {
|
|
658
682
|
objectFit: "contain",
|
|
659
683
|
width: actualLogoWidth,
|
|
660
|
-
height: actualLogoHeight
|
|
684
|
+
height: actualLogoHeight
|
|
661
685
|
}
|
|
662
686
|
}
|
|
663
687
|
)
|
|
@@ -670,9 +694,7 @@ var QR = ({
|
|
|
670
694
|
padding: textPadding,
|
|
671
695
|
borderRadius: 4,
|
|
672
696
|
left: moveText + centerPosition - 20,
|
|
673
|
-
// Approximate center
|
|
674
697
|
top: centerPosition - 10
|
|
675
|
-
// Approximate center
|
|
676
698
|
}
|
|
677
699
|
},
|
|
678
700
|
/* @__PURE__ */ import_react8.default.createElement(
|
|
@@ -692,7 +714,7 @@ var QR = ({
|
|
|
692
714
|
var QR_default = QR;
|
|
693
715
|
|
|
694
716
|
// src/components/core/Lista.tsx
|
|
695
|
-
var
|
|
717
|
+
var import_react9 = __toESM(require("react"));
|
|
696
718
|
var import_renderer9 = require("@react-pdf/renderer");
|
|
697
719
|
var styles8 = import_renderer9.StyleSheet.create({
|
|
698
720
|
ul: {
|
|
@@ -754,9 +776,9 @@ var toRoman = (num) => {
|
|
|
754
776
|
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];
|
|
755
777
|
};
|
|
756
778
|
var UL = ({ children, style, type = "disc" }) => {
|
|
757
|
-
const childrenWithBullets =
|
|
758
|
-
if (
|
|
759
|
-
return
|
|
779
|
+
const childrenWithBullets = import_react9.default.Children.map(children, (child, index) => {
|
|
780
|
+
if (import_react9.default.isValidElement(child)) {
|
|
781
|
+
return import_react9.default.cloneElement(child, {
|
|
760
782
|
bulletType: type,
|
|
761
783
|
isOrdered: false,
|
|
762
784
|
index: index + 1
|
|
@@ -764,12 +786,12 @@ var UL = ({ children, style, type = "disc" }) => {
|
|
|
764
786
|
}
|
|
765
787
|
return child;
|
|
766
788
|
});
|
|
767
|
-
return /* @__PURE__ */
|
|
789
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_renderer9.View, { style: [styles8.ul, style] }, childrenWithBullets);
|
|
768
790
|
};
|
|
769
791
|
var OL = ({ children, style, type = "decimal", start = 1 }) => {
|
|
770
|
-
const childrenWithNumbers =
|
|
771
|
-
if (
|
|
772
|
-
return
|
|
792
|
+
const childrenWithNumbers = import_react9.default.Children.map(children, (child, index) => {
|
|
793
|
+
if (import_react9.default.isValidElement(child)) {
|
|
794
|
+
return import_react9.default.cloneElement(child, {
|
|
773
795
|
bulletType: type,
|
|
774
796
|
isOrdered: true,
|
|
775
797
|
index: index + 1,
|
|
@@ -778,7 +800,7 @@ var OL = ({ children, style, type = "decimal", start = 1 }) => {
|
|
|
778
800
|
}
|
|
779
801
|
return child;
|
|
780
802
|
});
|
|
781
|
-
return /* @__PURE__ */
|
|
803
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_renderer9.View, { style: [styles8.ol, style] }, childrenWithNumbers);
|
|
782
804
|
};
|
|
783
805
|
var LI = ({ children, style, bulletType = "disc", isOrdered = false, index = 1, start = 1, value }) => {
|
|
784
806
|
let marker;
|
|
@@ -788,7 +810,7 @@ var LI = ({ children, style, bulletType = "disc", isOrdered = false, index = 1,
|
|
|
788
810
|
} else {
|
|
789
811
|
marker = getBulletPoint(bulletType);
|
|
790
812
|
}
|
|
791
|
-
return /* @__PURE__ */
|
|
813
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_renderer9.View, { style: [styles8.li, style] }, /* @__PURE__ */ import_react9.default.createElement(import_renderer9.Text, { style: styles8.bulletPoint }, marker), /* @__PURE__ */ import_react9.default.createElement(import_renderer9.View, { style: styles8.itemContent }, typeof children === "string" ? /* @__PURE__ */ import_react9.default.createElement(import_renderer9.Text, null, children) : children));
|
|
792
814
|
};
|
|
793
815
|
|
|
794
816
|
// src/components/core/index.tsx
|
|
@@ -823,13 +845,13 @@ var decodeBase64Pdf_default = decodeBase64Pdf;
|
|
|
823
845
|
|
|
824
846
|
// src/functions/generatePDF.ts
|
|
825
847
|
var import_renderer10 = require("@react-pdf/renderer");
|
|
826
|
-
var
|
|
848
|
+
var import_react10 = require("react");
|
|
827
849
|
var generatePDF = async ({ template: Template, data }) => {
|
|
828
850
|
try {
|
|
829
851
|
if (!Template) {
|
|
830
852
|
throw new Error("Template not provided");
|
|
831
853
|
}
|
|
832
|
-
const MyDocument = (0,
|
|
854
|
+
const MyDocument = (0, import_react10.createElement)(Template, { data });
|
|
833
855
|
const stream = await (0, import_renderer10.renderToStream)(MyDocument);
|
|
834
856
|
const base64String = await new Promise((resolve, reject) => {
|
|
835
857
|
const chunks = [];
|
package/dist/index.mjs
CHANGED
|
@@ -438,10 +438,32 @@ var Footer = ({ children, style, fixed = false }) => {
|
|
|
438
438
|
};
|
|
439
439
|
|
|
440
440
|
// src/components/core/QR.tsx
|
|
441
|
-
import React8 from "react";
|
|
442
|
-
import { useEffect, useState } from "react";
|
|
441
|
+
import React8, { useEffect, useState } from "react";
|
|
443
442
|
import { Image as Image2, View as View5, Text as Text5 } from "@react-pdf/renderer";
|
|
444
443
|
import QRCodeStyling from "qr-code-styling";
|
|
444
|
+
if (typeof window === "undefined" && typeof process !== "undefined") {
|
|
445
|
+
try {
|
|
446
|
+
import("jsdom").then((jsdom) => {
|
|
447
|
+
const { JSDOM } = jsdom;
|
|
448
|
+
import("canvas").then((canvas) => {
|
|
449
|
+
const { Canvas, Image: CanvasImage } = canvas;
|
|
450
|
+
const { window: domWindow } = new JSDOM("<!DOCTYPE html><html><body></body></html>");
|
|
451
|
+
global.window = domWindow;
|
|
452
|
+
global.document = domWindow.document;
|
|
453
|
+
global.HTMLElement = domWindow.HTMLElement;
|
|
454
|
+
global.HTMLCanvasElement = Canvas;
|
|
455
|
+
global.CanvasRenderingContext2D = Canvas;
|
|
456
|
+
global.Image = CanvasImage;
|
|
457
|
+
}).catch((err) => {
|
|
458
|
+
console.error("Error loading canvas:", err);
|
|
459
|
+
});
|
|
460
|
+
}).catch((err) => {
|
|
461
|
+
console.error("Error loading jsdom:", err);
|
|
462
|
+
});
|
|
463
|
+
} catch (error) {
|
|
464
|
+
console.error("Error setting up Node.js environment:", error);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
445
467
|
var QR = ({
|
|
446
468
|
url,
|
|
447
469
|
size = 200,
|
|
@@ -472,7 +494,9 @@ var QR = ({
|
|
|
472
494
|
const actualLogoWidth = logoWidth || Math.floor(size * 0.2);
|
|
473
495
|
const actualLogoHeight = logoHeight || actualLogoWidth;
|
|
474
496
|
useEffect(() => {
|
|
475
|
-
if (typeof window === "undefined")
|
|
497
|
+
if (typeof window === "undefined") {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
476
500
|
const generateQRCode = async () => {
|
|
477
501
|
try {
|
|
478
502
|
const qrCode = new QRCodeStyling({
|
|
@@ -522,11 +546,11 @@ var QR = ({
|
|
|
522
546
|
}
|
|
523
547
|
document.body.removeChild(container);
|
|
524
548
|
} catch (error) {
|
|
525
|
-
console.error("Error
|
|
549
|
+
console.error("Error capturando QR:", error);
|
|
526
550
|
}
|
|
527
551
|
}, 100);
|
|
528
552
|
} catch (error) {
|
|
529
|
-
console.error("Error
|
|
553
|
+
console.error("Error generando QR:", error);
|
|
530
554
|
}
|
|
531
555
|
};
|
|
532
556
|
generateQRCode();
|
|
@@ -547,14 +571,14 @@ var QR = ({
|
|
|
547
571
|
if (!qrDataURL) return null;
|
|
548
572
|
const centerPosition = size / 2;
|
|
549
573
|
const logoContainerSize = Math.max(actualLogoWidth, actualLogoHeight) + 10;
|
|
550
|
-
return /* @__PURE__ */ React8.createElement(View5, { style: { width: size, height: size, position: "relative", ...style } }, /* @__PURE__ */ React8.createElement(Image2, { src: qrDataURL
|
|
574
|
+
return /* @__PURE__ */ React8.createElement(View5, { style: { width: size, height: size, position: "relative", ...style } }, /* @__PURE__ */ React8.createElement(Image2, { src: qrDataURL, style: { width: size, height: size } }), logo && /* @__PURE__ */ React8.createElement(
|
|
551
575
|
View5,
|
|
552
576
|
{
|
|
553
577
|
style: {
|
|
554
578
|
position: "absolute",
|
|
555
579
|
width: logoContainerSize,
|
|
556
580
|
height: logoContainerSize,
|
|
557
|
-
backgroundColor: logoBG
|
|
581
|
+
backgroundColor: logoBG,
|
|
558
582
|
left: centerPosition - logoContainerSize / 2,
|
|
559
583
|
top: centerPosition - logoContainerSize / 2,
|
|
560
584
|
borderRadius: 100,
|
|
@@ -565,11 +589,11 @@ var QR = ({
|
|
|
565
589
|
/* @__PURE__ */ React8.createElement(
|
|
566
590
|
Image2,
|
|
567
591
|
{
|
|
568
|
-
src: logo
|
|
592
|
+
src: logo,
|
|
569
593
|
style: {
|
|
570
594
|
objectFit: "contain",
|
|
571
595
|
width: actualLogoWidth,
|
|
572
|
-
height: actualLogoHeight
|
|
596
|
+
height: actualLogoHeight
|
|
573
597
|
}
|
|
574
598
|
}
|
|
575
599
|
)
|
|
@@ -582,9 +606,7 @@ var QR = ({
|
|
|
582
606
|
padding: textPadding,
|
|
583
607
|
borderRadius: 4,
|
|
584
608
|
left: moveText + centerPosition - 20,
|
|
585
|
-
// Approximate center
|
|
586
609
|
top: centerPosition - 10
|
|
587
|
-
// Approximate center
|
|
588
610
|
}
|
|
589
611
|
},
|
|
590
612
|
/* @__PURE__ */ React8.createElement(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-pdf-levelup",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.25",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -20,14 +20,16 @@
|
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@react-pdf/renderer": "^4.3.0",
|
|
23
|
+
"qr-code-styling": "^1.9.2",
|
|
23
24
|
"react": "^18",
|
|
24
|
-
"react-dom": "^18"
|
|
25
|
-
"qr-code-styling": "^1.9.2"
|
|
25
|
+
"react-dom": "^18"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@babel/standalone": "^7.23.10",
|
|
29
29
|
"@monaco-editor/react": "^4.7.0",
|
|
30
|
+
"canvas": "^3.1.0",
|
|
30
31
|
"i": "^0.3.7",
|
|
32
|
+
"jsdom": "^26.1.0",
|
|
31
33
|
"lucide-react": "^0.485.0",
|
|
32
34
|
"npm": "^11.3.0",
|
|
33
35
|
"react-router-dom": "^7.4.1",
|
|
@@ -37,6 +39,7 @@
|
|
|
37
39
|
"devDependencies": {
|
|
38
40
|
"@eslint/js": "^9.21.0",
|
|
39
41
|
"@react-pdf/types": "^2.9.0",
|
|
42
|
+
"@types/jsdom": "^21.1.7",
|
|
40
43
|
"@types/react": "^18.2.56",
|
|
41
44
|
"@types/react-dom": "^18.2.19",
|
|
42
45
|
"@vitejs/plugin-react": "^4.3.4",
|