react-pdf-levelup 2.0.25 → 2.0.26
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 +7 -21
- package/dist/index.d.ts +7 -21
- package/dist/index.js +141 -183
- package/dist/index.mjs +139 -181
- package/package.json +3 -5
package/dist/index.d.mts
CHANGED
|
@@ -109,33 +109,19 @@ interface PageElementProps {
|
|
|
109
109
|
declare const Header: React$1.FC<PageElementProps>;
|
|
110
110
|
declare const Footer: React$1.FC<PageElementProps>;
|
|
111
111
|
|
|
112
|
-
interface
|
|
113
|
-
|
|
112
|
+
interface QRProps {
|
|
113
|
+
value: string;
|
|
114
114
|
size?: number;
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
style?: any;
|
|
116
|
+
colorDark?: string;
|
|
117
|
+
colorLight?: string;
|
|
118
|
+
margin?: number;
|
|
117
119
|
logo?: string;
|
|
118
120
|
logoWidth?: number;
|
|
119
121
|
logoHeight?: number;
|
|
120
|
-
margin?: number;
|
|
121
122
|
errorCorrectionLevel?: "L" | "M" | "Q" | "H";
|
|
122
|
-
style?: any;
|
|
123
|
-
dotType?: "rounded" | "dots" | "classy" | "classy-rounded" | "square" | "extra-rounded";
|
|
124
|
-
cornerSquareType?: "square" | "dot" | "extra-rounded";
|
|
125
|
-
cornerDotType?: "square" | "dot";
|
|
126
|
-
cornerSquareColor?: string;
|
|
127
|
-
cornerDotColor?: string;
|
|
128
|
-
logoBG?: string;
|
|
129
|
-
logoText?: string;
|
|
130
|
-
moveText?: number;
|
|
131
|
-
textColor?: string;
|
|
132
|
-
fontSize?: number;
|
|
133
|
-
fontFamily?: string;
|
|
134
|
-
textBackgroundColor?: string;
|
|
135
|
-
textPadding?: number;
|
|
136
|
-
textBold?: boolean;
|
|
137
123
|
}
|
|
138
|
-
declare const QR: React$1.FC<
|
|
124
|
+
declare const QR: React$1.FC<QRProps>;
|
|
139
125
|
|
|
140
126
|
interface ListProps {
|
|
141
127
|
children: React$1.ReactNode;
|
package/dist/index.d.ts
CHANGED
|
@@ -109,33 +109,19 @@ interface PageElementProps {
|
|
|
109
109
|
declare const Header: React$1.FC<PageElementProps>;
|
|
110
110
|
declare const Footer: React$1.FC<PageElementProps>;
|
|
111
111
|
|
|
112
|
-
interface
|
|
113
|
-
|
|
112
|
+
interface QRProps {
|
|
113
|
+
value: string;
|
|
114
114
|
size?: number;
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
style?: any;
|
|
116
|
+
colorDark?: string;
|
|
117
|
+
colorLight?: string;
|
|
118
|
+
margin?: number;
|
|
117
119
|
logo?: string;
|
|
118
120
|
logoWidth?: number;
|
|
119
121
|
logoHeight?: number;
|
|
120
|
-
margin?: number;
|
|
121
122
|
errorCorrectionLevel?: "L" | "M" | "Q" | "H";
|
|
122
|
-
style?: any;
|
|
123
|
-
dotType?: "rounded" | "dots" | "classy" | "classy-rounded" | "square" | "extra-rounded";
|
|
124
|
-
cornerSquareType?: "square" | "dot" | "extra-rounded";
|
|
125
|
-
cornerDotType?: "square" | "dot";
|
|
126
|
-
cornerSquareColor?: string;
|
|
127
|
-
cornerDotColor?: string;
|
|
128
|
-
logoBG?: string;
|
|
129
|
-
logoText?: string;
|
|
130
|
-
moveText?: number;
|
|
131
|
-
textColor?: string;
|
|
132
|
-
fontSize?: number;
|
|
133
|
-
fontFamily?: string;
|
|
134
|
-
textBackgroundColor?: string;
|
|
135
|
-
textPadding?: number;
|
|
136
|
-
textBold?: boolean;
|
|
137
123
|
}
|
|
138
|
-
declare const QR: React$1.FC<
|
|
124
|
+
declare const QR: React$1.FC<QRProps>;
|
|
139
125
|
|
|
140
126
|
interface ListProps {
|
|
141
127
|
children: React$1.ReactNode;
|
package/dist/index.js
CHANGED
|
@@ -528,195 +528,153 @@ var Footer = ({ children, style, fixed = false }) => {
|
|
|
528
528
|
// src/components/core/QR.tsx
|
|
529
529
|
var import_react8 = __toESM(require("react"));
|
|
530
530
|
var import_renderer8 = require("@react-pdf/renderer");
|
|
531
|
-
var
|
|
532
|
-
|
|
531
|
+
var import_react9 = require("react");
|
|
532
|
+
|
|
533
|
+
// src/components/core/QRGenerator.tsx
|
|
534
|
+
var import_qrcode = __toESM(require("qrcode"));
|
|
535
|
+
var generateQRAsBase64 = async ({
|
|
536
|
+
value,
|
|
537
|
+
size = 150,
|
|
538
|
+
colorDark = "#000000",
|
|
539
|
+
colorLight = "#ffffff",
|
|
540
|
+
margin = 0,
|
|
541
|
+
errorCorrectionLevel = "M"
|
|
542
|
+
}) => {
|
|
533
543
|
try {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
});
|
|
548
|
-
}).catch((err) => {
|
|
549
|
-
console.error("Error loading jsdom:", err);
|
|
550
|
-
});
|
|
544
|
+
const options = {
|
|
545
|
+
errorCorrectionLevel,
|
|
546
|
+
type: "image/png",
|
|
547
|
+
quality: 0.92,
|
|
548
|
+
margin,
|
|
549
|
+
color: {
|
|
550
|
+
dark: colorDark,
|
|
551
|
+
light: colorLight
|
|
552
|
+
},
|
|
553
|
+
width: size
|
|
554
|
+
};
|
|
555
|
+
const qrDataUrl = import_qrcode.default.toDataURL(value, options);
|
|
556
|
+
return qrDataUrl;
|
|
551
557
|
} catch (error) {
|
|
552
|
-
console.error("Error
|
|
558
|
+
console.error("Error generando QR:", error);
|
|
559
|
+
return "";
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
var addLogoToQR = async (qrDataUrl, logoUrl, logoWidth, logoHeight) => {
|
|
563
|
+
return new Promise((resolve) => {
|
|
564
|
+
if (!qrDataUrl || !logoUrl) {
|
|
565
|
+
resolve(qrDataUrl);
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
try {
|
|
569
|
+
const canvas = document.createElement("canvas");
|
|
570
|
+
const ctx = canvas.getContext("2d");
|
|
571
|
+
if (!ctx) {
|
|
572
|
+
resolve(qrDataUrl);
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
const qrImage = new Image();
|
|
576
|
+
qrImage.crossOrigin = "anonymous";
|
|
577
|
+
qrImage.onload = () => {
|
|
578
|
+
canvas.width = qrImage.width;
|
|
579
|
+
canvas.height = qrImage.height;
|
|
580
|
+
ctx.drawImage(qrImage, 0, 0, canvas.width, canvas.height);
|
|
581
|
+
const logoImage = new Image();
|
|
582
|
+
logoImage.crossOrigin = "anonymous";
|
|
583
|
+
logoImage.onload = () => {
|
|
584
|
+
const x = (canvas.width - logoWidth) / 2;
|
|
585
|
+
const y = (canvas.height - logoHeight) / 2;
|
|
586
|
+
ctx.fillStyle = "#FFFFFF";
|
|
587
|
+
ctx.fillRect(x - 5, y - 5, logoWidth + 10, logoHeight + 10);
|
|
588
|
+
ctx.drawImage(logoImage, x, y, logoWidth, logoHeight);
|
|
589
|
+
const finalQrDataUrl = canvas.toDataURL("image/png");
|
|
590
|
+
resolve(finalQrDataUrl);
|
|
591
|
+
};
|
|
592
|
+
logoImage.onerror = () => {
|
|
593
|
+
console.error("Error cargando el logo");
|
|
594
|
+
resolve(qrDataUrl);
|
|
595
|
+
};
|
|
596
|
+
logoImage.src = logoUrl;
|
|
597
|
+
};
|
|
598
|
+
qrImage.onerror = () => {
|
|
599
|
+
console.error("Error cargando el QR");
|
|
600
|
+
resolve("");
|
|
601
|
+
};
|
|
602
|
+
qrImage.src = qrDataUrl;
|
|
603
|
+
} catch (error) {
|
|
604
|
+
console.error("Error procesando el QR con logo:", error);
|
|
605
|
+
resolve(qrDataUrl);
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
// src/components/core/QR.tsx
|
|
611
|
+
var styles8 = import_renderer8.StyleSheet.create({
|
|
612
|
+
qrContainer: {
|
|
613
|
+
display: "flex",
|
|
614
|
+
alignItems: "center",
|
|
615
|
+
justifyContent: "center",
|
|
616
|
+
margin: 10
|
|
553
617
|
}
|
|
554
|
-
}
|
|
618
|
+
});
|
|
619
|
+
var errorLevelMap = {
|
|
620
|
+
0: "L",
|
|
621
|
+
1: "M",
|
|
622
|
+
2: "Q",
|
|
623
|
+
3: "H"
|
|
624
|
+
};
|
|
555
625
|
var QR = ({
|
|
556
|
-
|
|
557
|
-
size =
|
|
558
|
-
colorData = "#000000",
|
|
559
|
-
colorDataBG = "#ffffff",
|
|
560
|
-
logo,
|
|
561
|
-
logoWidth = 30,
|
|
562
|
-
logoHeight,
|
|
563
|
-
margin = 0,
|
|
564
|
-
errorCorrectionLevel = "H",
|
|
626
|
+
value,
|
|
627
|
+
size = 150,
|
|
565
628
|
style,
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
moveText = 0,
|
|
574
|
-
textColor = colorData,
|
|
575
|
-
fontSize = 12,
|
|
576
|
-
fontFamily = "Helvetica",
|
|
577
|
-
textBackgroundColor = colorDataBG,
|
|
578
|
-
textPadding = 1,
|
|
579
|
-
textBold = true
|
|
629
|
+
colorDark = "#000000",
|
|
630
|
+
colorLight = "#ffffff",
|
|
631
|
+
margin = 0,
|
|
632
|
+
logo = "",
|
|
633
|
+
logoWidth = 30,
|
|
634
|
+
logoHeight = 30,
|
|
635
|
+
errorCorrectionLevel = "M"
|
|
580
636
|
}) => {
|
|
581
|
-
const [
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
(0, import_react8.useEffect)(() => {
|
|
585
|
-
if (typeof window === "undefined") {
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
const generateQRCode = async () => {
|
|
637
|
+
const [qrDataUrl, setQrDataUrl] = (0, import_react9.useState)("");
|
|
638
|
+
(0, import_react9.useEffect)(() => {
|
|
639
|
+
const generateQR = async () => {
|
|
589
640
|
try {
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
type: dotType
|
|
598
|
-
},
|
|
599
|
-
cornersSquareOptions: {
|
|
600
|
-
color: cornerSquareColor || colorData,
|
|
601
|
-
type: cornerSquareType
|
|
602
|
-
},
|
|
603
|
-
cornersDotOptions: {
|
|
604
|
-
color: cornerDotColor || colorData,
|
|
605
|
-
type: cornerDotType
|
|
606
|
-
},
|
|
607
|
-
backgroundOptions: {
|
|
608
|
-
color: colorDataBG
|
|
609
|
-
},
|
|
610
|
-
qrOptions: {
|
|
611
|
-
errorCorrectionLevel
|
|
612
|
-
},
|
|
613
|
-
margin
|
|
641
|
+
const baseQrDataUrl = await generateQRAsBase64({
|
|
642
|
+
value,
|
|
643
|
+
size,
|
|
644
|
+
colorDark,
|
|
645
|
+
colorLight,
|
|
646
|
+
margin,
|
|
647
|
+
errorCorrectionLevel: typeof errorCorrectionLevel === "number" ? errorLevelMap[errorCorrectionLevel] || "M" : errorCorrectionLevel
|
|
614
648
|
});
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
setTimeout(() => {
|
|
622
|
-
try {
|
|
623
|
-
const qrCanvas = container.querySelector("canvas");
|
|
624
|
-
if (qrCanvas) {
|
|
625
|
-
const canvas = document.createElement("canvas");
|
|
626
|
-
canvas.width = size;
|
|
627
|
-
canvas.height = size;
|
|
628
|
-
const ctx = canvas.getContext("2d");
|
|
629
|
-
if (ctx) {
|
|
630
|
-
ctx.drawImage(qrCanvas, 0, 0);
|
|
631
|
-
const dataURL = canvas.toDataURL("image/png");
|
|
632
|
-
setQrDataURL(dataURL);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
document.body.removeChild(container);
|
|
636
|
-
} catch (error) {
|
|
637
|
-
console.error("Error capturando QR:", error);
|
|
638
|
-
}
|
|
639
|
-
}, 100);
|
|
649
|
+
if (logo && logoWidth && logoHeight) {
|
|
650
|
+
const qrWithLogo = await addLogoToQR(baseQrDataUrl, logo, logoWidth, logoHeight);
|
|
651
|
+
setQrDataUrl(qrWithLogo);
|
|
652
|
+
} else {
|
|
653
|
+
setQrDataUrl(baseQrDataUrl);
|
|
654
|
+
}
|
|
640
655
|
} catch (error) {
|
|
641
656
|
console.error("Error generando QR:", error);
|
|
657
|
+
const fallbackUrl2 = `https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(
|
|
658
|
+
value
|
|
659
|
+
)}&size=${size}x${size}&color=${encodeURIComponent(colorDark.replace("#", ""))}&bgcolor=${encodeURIComponent(
|
|
660
|
+
colorLight.replace("#", "")
|
|
661
|
+
)}`;
|
|
662
|
+
setQrDataUrl(fallbackUrl2);
|
|
642
663
|
}
|
|
643
664
|
};
|
|
644
|
-
|
|
645
|
-
}, [
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
margin,
|
|
651
|
-
errorCorrectionLevel,
|
|
652
|
-
dotType,
|
|
653
|
-
cornerSquareType,
|
|
654
|
-
cornerDotType,
|
|
655
|
-
cornerSquareColor,
|
|
656
|
-
cornerDotColor,
|
|
657
|
-
logoBG
|
|
658
|
-
]);
|
|
659
|
-
if (!qrDataURL) return null;
|
|
660
|
-
const centerPosition = size / 2;
|
|
661
|
-
const logoContainerSize = Math.max(actualLogoWidth, actualLogoHeight) + 10;
|
|
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(
|
|
663
|
-
import_renderer8.View,
|
|
664
|
-
{
|
|
665
|
-
style: {
|
|
666
|
-
position: "absolute",
|
|
667
|
-
width: logoContainerSize,
|
|
668
|
-
height: logoContainerSize,
|
|
669
|
-
backgroundColor: logoBG,
|
|
670
|
-
left: centerPosition - logoContainerSize / 2,
|
|
671
|
-
top: centerPosition - logoContainerSize / 2,
|
|
672
|
-
borderRadius: 100,
|
|
673
|
-
border: `5px solid ${colorData}`,
|
|
674
|
-
padding: 0
|
|
675
|
-
}
|
|
676
|
-
},
|
|
677
|
-
/* @__PURE__ */ import_react8.default.createElement(
|
|
678
|
-
import_renderer8.Image,
|
|
679
|
-
{
|
|
680
|
-
src: logo,
|
|
681
|
-
style: {
|
|
682
|
-
objectFit: "contain",
|
|
683
|
-
width: actualLogoWidth,
|
|
684
|
-
height: actualLogoHeight
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
)
|
|
688
|
-
), !logo && logoText && /* @__PURE__ */ import_react8.default.createElement(
|
|
689
|
-
import_renderer8.View,
|
|
690
|
-
{
|
|
691
|
-
style: {
|
|
692
|
-
position: "absolute",
|
|
693
|
-
backgroundColor: textBackgroundColor,
|
|
694
|
-
padding: textPadding,
|
|
695
|
-
borderRadius: 4,
|
|
696
|
-
left: moveText + centerPosition - 20,
|
|
697
|
-
top: centerPosition - 10
|
|
698
|
-
}
|
|
699
|
-
},
|
|
700
|
-
/* @__PURE__ */ import_react8.default.createElement(
|
|
701
|
-
import_renderer8.Text,
|
|
702
|
-
{
|
|
703
|
-
style: {
|
|
704
|
-
color: textColor,
|
|
705
|
-
fontSize,
|
|
706
|
-
fontFamily,
|
|
707
|
-
fontWeight: textBold ? "bold" : "normal"
|
|
708
|
-
}
|
|
709
|
-
},
|
|
710
|
-
logoText
|
|
711
|
-
)
|
|
712
|
-
));
|
|
665
|
+
generateQR();
|
|
666
|
+
}, [value, size, colorDark, colorLight, margin, logo, logoWidth, logoHeight, errorCorrectionLevel]);
|
|
667
|
+
const fallbackUrl = `https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(
|
|
668
|
+
value
|
|
669
|
+
)}&size=${size}x${size}`;
|
|
670
|
+
return /* @__PURE__ */ import_react8.default.createElement(import_renderer8.View, { style: [styles8.qrContainer, style] }, /* @__PURE__ */ import_react8.default.createElement(import_renderer8.Image, { src: qrDataUrl || fallbackUrl, style: { width: size, height: size } }));
|
|
713
671
|
};
|
|
714
672
|
var QR_default = QR;
|
|
715
673
|
|
|
716
674
|
// src/components/core/Lista.tsx
|
|
717
|
-
var
|
|
675
|
+
var import_react10 = __toESM(require("react"));
|
|
718
676
|
var import_renderer9 = require("@react-pdf/renderer");
|
|
719
|
-
var
|
|
677
|
+
var styles9 = import_renderer9.StyleSheet.create({
|
|
720
678
|
ul: {
|
|
721
679
|
marginBottom: 10,
|
|
722
680
|
paddingLeft: 15
|
|
@@ -776,9 +734,9 @@ var toRoman = (num) => {
|
|
|
776
734
|
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];
|
|
777
735
|
};
|
|
778
736
|
var UL = ({ children, style, type = "disc" }) => {
|
|
779
|
-
const childrenWithBullets =
|
|
780
|
-
if (
|
|
781
|
-
return
|
|
737
|
+
const childrenWithBullets = import_react10.default.Children.map(children, (child, index) => {
|
|
738
|
+
if (import_react10.default.isValidElement(child)) {
|
|
739
|
+
return import_react10.default.cloneElement(child, {
|
|
782
740
|
bulletType: type,
|
|
783
741
|
isOrdered: false,
|
|
784
742
|
index: index + 1
|
|
@@ -786,12 +744,12 @@ var UL = ({ children, style, type = "disc" }) => {
|
|
|
786
744
|
}
|
|
787
745
|
return child;
|
|
788
746
|
});
|
|
789
|
-
return /* @__PURE__ */
|
|
747
|
+
return /* @__PURE__ */ import_react10.default.createElement(import_renderer9.View, { style: [styles9.ul, style] }, childrenWithBullets);
|
|
790
748
|
};
|
|
791
749
|
var OL = ({ children, style, type = "decimal", start = 1 }) => {
|
|
792
|
-
const childrenWithNumbers =
|
|
793
|
-
if (
|
|
794
|
-
return
|
|
750
|
+
const childrenWithNumbers = import_react10.default.Children.map(children, (child, index) => {
|
|
751
|
+
if (import_react10.default.isValidElement(child)) {
|
|
752
|
+
return import_react10.default.cloneElement(child, {
|
|
795
753
|
bulletType: type,
|
|
796
754
|
isOrdered: true,
|
|
797
755
|
index: index + 1,
|
|
@@ -800,7 +758,7 @@ var OL = ({ children, style, type = "decimal", start = 1 }) => {
|
|
|
800
758
|
}
|
|
801
759
|
return child;
|
|
802
760
|
});
|
|
803
|
-
return /* @__PURE__ */
|
|
761
|
+
return /* @__PURE__ */ import_react10.default.createElement(import_renderer9.View, { style: [styles9.ol, style] }, childrenWithNumbers);
|
|
804
762
|
};
|
|
805
763
|
var LI = ({ children, style, bulletType = "disc", isOrdered = false, index = 1, start = 1, value }) => {
|
|
806
764
|
let marker;
|
|
@@ -810,7 +768,7 @@ var LI = ({ children, style, bulletType = "disc", isOrdered = false, index = 1,
|
|
|
810
768
|
} else {
|
|
811
769
|
marker = getBulletPoint(bulletType);
|
|
812
770
|
}
|
|
813
|
-
return /* @__PURE__ */
|
|
771
|
+
return /* @__PURE__ */ import_react10.default.createElement(import_renderer9.View, { style: [styles9.li, style] }, /* @__PURE__ */ import_react10.default.createElement(import_renderer9.Text, { style: styles9.bulletPoint }, marker), /* @__PURE__ */ import_react10.default.createElement(import_renderer9.View, { style: styles9.itemContent }, typeof children === "string" ? /* @__PURE__ */ import_react10.default.createElement(import_renderer9.Text, null, children) : children));
|
|
814
772
|
};
|
|
815
773
|
|
|
816
774
|
// src/components/core/index.tsx
|
|
@@ -845,13 +803,13 @@ var decodeBase64Pdf_default = decodeBase64Pdf;
|
|
|
845
803
|
|
|
846
804
|
// src/functions/generatePDF.ts
|
|
847
805
|
var import_renderer10 = require("@react-pdf/renderer");
|
|
848
|
-
var
|
|
806
|
+
var import_react11 = require("react");
|
|
849
807
|
var generatePDF = async ({ template: Template, data }) => {
|
|
850
808
|
try {
|
|
851
809
|
if (!Template) {
|
|
852
810
|
throw new Error("Template not provided");
|
|
853
811
|
}
|
|
854
|
-
const MyDocument = (0,
|
|
812
|
+
const MyDocument = (0, import_react11.createElement)(Template, { data });
|
|
855
813
|
const stream = await (0, import_renderer10.renderToStream)(MyDocument);
|
|
856
814
|
const base64String = await new Promise((resolve, reject) => {
|
|
857
815
|
const chunks = [];
|
package/dist/index.mjs
CHANGED
|
@@ -71,7 +71,7 @@ var LayoutPDF_default = LayoutPDF;
|
|
|
71
71
|
|
|
72
72
|
// src/components/core/Img.tsx
|
|
73
73
|
import React2 from "react";
|
|
74
|
-
import { Image, StyleSheet as StyleSheet2 } from "@react-pdf/renderer";
|
|
74
|
+
import { Image as Image2, StyleSheet as StyleSheet2 } from "@react-pdf/renderer";
|
|
75
75
|
var styles2 = StyleSheet2.create({
|
|
76
76
|
image: {
|
|
77
77
|
width: "100%",
|
|
@@ -80,7 +80,7 @@ var styles2 = StyleSheet2.create({
|
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
var Img = ({ src, style }) => {
|
|
83
|
-
return /* @__PURE__ */ React2.createElement(
|
|
83
|
+
return /* @__PURE__ */ React2.createElement(Image2, { src, style: [styles2.image, style] });
|
|
84
84
|
};
|
|
85
85
|
var Img_default = Img;
|
|
86
86
|
|
|
@@ -438,197 +438,155 @@ var Footer = ({ children, style, fixed = false }) => {
|
|
|
438
438
|
};
|
|
439
439
|
|
|
440
440
|
// src/components/core/QR.tsx
|
|
441
|
-
import React8
|
|
442
|
-
import { Image as
|
|
443
|
-
import
|
|
444
|
-
|
|
441
|
+
import React8 from "react";
|
|
442
|
+
import { Image as Image3, StyleSheet as StyleSheet8, View as View5 } from "@react-pdf/renderer";
|
|
443
|
+
import { useEffect, useState } from "react";
|
|
444
|
+
|
|
445
|
+
// src/components/core/QRGenerator.tsx
|
|
446
|
+
import QRCode from "qrcode";
|
|
447
|
+
var generateQRAsBase64 = async ({
|
|
448
|
+
value,
|
|
449
|
+
size = 150,
|
|
450
|
+
colorDark = "#000000",
|
|
451
|
+
colorLight = "#ffffff",
|
|
452
|
+
margin = 0,
|
|
453
|
+
errorCorrectionLevel = "M"
|
|
454
|
+
}) => {
|
|
445
455
|
try {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
});
|
|
460
|
-
}).catch((err) => {
|
|
461
|
-
console.error("Error loading jsdom:", err);
|
|
462
|
-
});
|
|
456
|
+
const options = {
|
|
457
|
+
errorCorrectionLevel,
|
|
458
|
+
type: "image/png",
|
|
459
|
+
quality: 0.92,
|
|
460
|
+
margin,
|
|
461
|
+
color: {
|
|
462
|
+
dark: colorDark,
|
|
463
|
+
light: colorLight
|
|
464
|
+
},
|
|
465
|
+
width: size
|
|
466
|
+
};
|
|
467
|
+
const qrDataUrl = QRCode.toDataURL(value, options);
|
|
468
|
+
return qrDataUrl;
|
|
463
469
|
} catch (error) {
|
|
464
|
-
console.error("Error
|
|
470
|
+
console.error("Error generando QR:", error);
|
|
471
|
+
return "";
|
|
465
472
|
}
|
|
466
|
-
}
|
|
473
|
+
};
|
|
474
|
+
var addLogoToQR = async (qrDataUrl, logoUrl, logoWidth, logoHeight) => {
|
|
475
|
+
return new Promise((resolve) => {
|
|
476
|
+
if (!qrDataUrl || !logoUrl) {
|
|
477
|
+
resolve(qrDataUrl);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
try {
|
|
481
|
+
const canvas = document.createElement("canvas");
|
|
482
|
+
const ctx = canvas.getContext("2d");
|
|
483
|
+
if (!ctx) {
|
|
484
|
+
resolve(qrDataUrl);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
const qrImage = new Image();
|
|
488
|
+
qrImage.crossOrigin = "anonymous";
|
|
489
|
+
qrImage.onload = () => {
|
|
490
|
+
canvas.width = qrImage.width;
|
|
491
|
+
canvas.height = qrImage.height;
|
|
492
|
+
ctx.drawImage(qrImage, 0, 0, canvas.width, canvas.height);
|
|
493
|
+
const logoImage = new Image();
|
|
494
|
+
logoImage.crossOrigin = "anonymous";
|
|
495
|
+
logoImage.onload = () => {
|
|
496
|
+
const x = (canvas.width - logoWidth) / 2;
|
|
497
|
+
const y = (canvas.height - logoHeight) / 2;
|
|
498
|
+
ctx.fillStyle = "#FFFFFF";
|
|
499
|
+
ctx.fillRect(x - 5, y - 5, logoWidth + 10, logoHeight + 10);
|
|
500
|
+
ctx.drawImage(logoImage, x, y, logoWidth, logoHeight);
|
|
501
|
+
const finalQrDataUrl = canvas.toDataURL("image/png");
|
|
502
|
+
resolve(finalQrDataUrl);
|
|
503
|
+
};
|
|
504
|
+
logoImage.onerror = () => {
|
|
505
|
+
console.error("Error cargando el logo");
|
|
506
|
+
resolve(qrDataUrl);
|
|
507
|
+
};
|
|
508
|
+
logoImage.src = logoUrl;
|
|
509
|
+
};
|
|
510
|
+
qrImage.onerror = () => {
|
|
511
|
+
console.error("Error cargando el QR");
|
|
512
|
+
resolve("");
|
|
513
|
+
};
|
|
514
|
+
qrImage.src = qrDataUrl;
|
|
515
|
+
} catch (error) {
|
|
516
|
+
console.error("Error procesando el QR con logo:", error);
|
|
517
|
+
resolve(qrDataUrl);
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
// src/components/core/QR.tsx
|
|
523
|
+
var styles8 = StyleSheet8.create({
|
|
524
|
+
qrContainer: {
|
|
525
|
+
display: "flex",
|
|
526
|
+
alignItems: "center",
|
|
527
|
+
justifyContent: "center",
|
|
528
|
+
margin: 10
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
var errorLevelMap = {
|
|
532
|
+
0: "L",
|
|
533
|
+
1: "M",
|
|
534
|
+
2: "Q",
|
|
535
|
+
3: "H"
|
|
536
|
+
};
|
|
467
537
|
var QR = ({
|
|
468
|
-
|
|
469
|
-
size =
|
|
470
|
-
colorData = "#000000",
|
|
471
|
-
colorDataBG = "#ffffff",
|
|
472
|
-
logo,
|
|
473
|
-
logoWidth = 30,
|
|
474
|
-
logoHeight,
|
|
475
|
-
margin = 0,
|
|
476
|
-
errorCorrectionLevel = "H",
|
|
538
|
+
value,
|
|
539
|
+
size = 150,
|
|
477
540
|
style,
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
moveText = 0,
|
|
486
|
-
textColor = colorData,
|
|
487
|
-
fontSize = 12,
|
|
488
|
-
fontFamily = "Helvetica",
|
|
489
|
-
textBackgroundColor = colorDataBG,
|
|
490
|
-
textPadding = 1,
|
|
491
|
-
textBold = true
|
|
541
|
+
colorDark = "#000000",
|
|
542
|
+
colorLight = "#ffffff",
|
|
543
|
+
margin = 0,
|
|
544
|
+
logo = "",
|
|
545
|
+
logoWidth = 30,
|
|
546
|
+
logoHeight = 30,
|
|
547
|
+
errorCorrectionLevel = "M"
|
|
492
548
|
}) => {
|
|
493
|
-
const [
|
|
494
|
-
const actualLogoWidth = logoWidth || Math.floor(size * 0.2);
|
|
495
|
-
const actualLogoHeight = logoHeight || actualLogoWidth;
|
|
549
|
+
const [qrDataUrl, setQrDataUrl] = useState("");
|
|
496
550
|
useEffect(() => {
|
|
497
|
-
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
const generateQRCode = async () => {
|
|
551
|
+
const generateQR = async () => {
|
|
501
552
|
try {
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
type: dotType
|
|
510
|
-
},
|
|
511
|
-
cornersSquareOptions: {
|
|
512
|
-
color: cornerSquareColor || colorData,
|
|
513
|
-
type: cornerSquareType
|
|
514
|
-
},
|
|
515
|
-
cornersDotOptions: {
|
|
516
|
-
color: cornerDotColor || colorData,
|
|
517
|
-
type: cornerDotType
|
|
518
|
-
},
|
|
519
|
-
backgroundOptions: {
|
|
520
|
-
color: colorDataBG
|
|
521
|
-
},
|
|
522
|
-
qrOptions: {
|
|
523
|
-
errorCorrectionLevel
|
|
524
|
-
},
|
|
525
|
-
margin
|
|
553
|
+
const baseQrDataUrl = await generateQRAsBase64({
|
|
554
|
+
value,
|
|
555
|
+
size,
|
|
556
|
+
colorDark,
|
|
557
|
+
colorLight,
|
|
558
|
+
margin,
|
|
559
|
+
errorCorrectionLevel: typeof errorCorrectionLevel === "number" ? errorLevelMap[errorCorrectionLevel] || "M" : errorCorrectionLevel
|
|
526
560
|
});
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
setTimeout(() => {
|
|
534
|
-
try {
|
|
535
|
-
const qrCanvas = container.querySelector("canvas");
|
|
536
|
-
if (qrCanvas) {
|
|
537
|
-
const canvas = document.createElement("canvas");
|
|
538
|
-
canvas.width = size;
|
|
539
|
-
canvas.height = size;
|
|
540
|
-
const ctx = canvas.getContext("2d");
|
|
541
|
-
if (ctx) {
|
|
542
|
-
ctx.drawImage(qrCanvas, 0, 0);
|
|
543
|
-
const dataURL = canvas.toDataURL("image/png");
|
|
544
|
-
setQrDataURL(dataURL);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
document.body.removeChild(container);
|
|
548
|
-
} catch (error) {
|
|
549
|
-
console.error("Error capturando QR:", error);
|
|
550
|
-
}
|
|
551
|
-
}, 100);
|
|
561
|
+
if (logo && logoWidth && logoHeight) {
|
|
562
|
+
const qrWithLogo = await addLogoToQR(baseQrDataUrl, logo, logoWidth, logoHeight);
|
|
563
|
+
setQrDataUrl(qrWithLogo);
|
|
564
|
+
} else {
|
|
565
|
+
setQrDataUrl(baseQrDataUrl);
|
|
566
|
+
}
|
|
552
567
|
} catch (error) {
|
|
553
568
|
console.error("Error generando QR:", error);
|
|
569
|
+
const fallbackUrl2 = `https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(
|
|
570
|
+
value
|
|
571
|
+
)}&size=${size}x${size}&color=${encodeURIComponent(colorDark.replace("#", ""))}&bgcolor=${encodeURIComponent(
|
|
572
|
+
colorLight.replace("#", "")
|
|
573
|
+
)}`;
|
|
574
|
+
setQrDataUrl(fallbackUrl2);
|
|
554
575
|
}
|
|
555
576
|
};
|
|
556
|
-
|
|
557
|
-
}, [
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
margin,
|
|
563
|
-
errorCorrectionLevel,
|
|
564
|
-
dotType,
|
|
565
|
-
cornerSquareType,
|
|
566
|
-
cornerDotType,
|
|
567
|
-
cornerSquareColor,
|
|
568
|
-
cornerDotColor,
|
|
569
|
-
logoBG
|
|
570
|
-
]);
|
|
571
|
-
if (!qrDataURL) return null;
|
|
572
|
-
const centerPosition = size / 2;
|
|
573
|
-
const logoContainerSize = Math.max(actualLogoWidth, actualLogoHeight) + 10;
|
|
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(
|
|
575
|
-
View5,
|
|
576
|
-
{
|
|
577
|
-
style: {
|
|
578
|
-
position: "absolute",
|
|
579
|
-
width: logoContainerSize,
|
|
580
|
-
height: logoContainerSize,
|
|
581
|
-
backgroundColor: logoBG,
|
|
582
|
-
left: centerPosition - logoContainerSize / 2,
|
|
583
|
-
top: centerPosition - logoContainerSize / 2,
|
|
584
|
-
borderRadius: 100,
|
|
585
|
-
border: `5px solid ${colorData}`,
|
|
586
|
-
padding: 0
|
|
587
|
-
}
|
|
588
|
-
},
|
|
589
|
-
/* @__PURE__ */ React8.createElement(
|
|
590
|
-
Image2,
|
|
591
|
-
{
|
|
592
|
-
src: logo,
|
|
593
|
-
style: {
|
|
594
|
-
objectFit: "contain",
|
|
595
|
-
width: actualLogoWidth,
|
|
596
|
-
height: actualLogoHeight
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
)
|
|
600
|
-
), !logo && logoText && /* @__PURE__ */ React8.createElement(
|
|
601
|
-
View5,
|
|
602
|
-
{
|
|
603
|
-
style: {
|
|
604
|
-
position: "absolute",
|
|
605
|
-
backgroundColor: textBackgroundColor,
|
|
606
|
-
padding: textPadding,
|
|
607
|
-
borderRadius: 4,
|
|
608
|
-
left: moveText + centerPosition - 20,
|
|
609
|
-
top: centerPosition - 10
|
|
610
|
-
}
|
|
611
|
-
},
|
|
612
|
-
/* @__PURE__ */ React8.createElement(
|
|
613
|
-
Text5,
|
|
614
|
-
{
|
|
615
|
-
style: {
|
|
616
|
-
color: textColor,
|
|
617
|
-
fontSize,
|
|
618
|
-
fontFamily,
|
|
619
|
-
fontWeight: textBold ? "bold" : "normal"
|
|
620
|
-
}
|
|
621
|
-
},
|
|
622
|
-
logoText
|
|
623
|
-
)
|
|
624
|
-
));
|
|
577
|
+
generateQR();
|
|
578
|
+
}, [value, size, colorDark, colorLight, margin, logo, logoWidth, logoHeight, errorCorrectionLevel]);
|
|
579
|
+
const fallbackUrl = `https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(
|
|
580
|
+
value
|
|
581
|
+
)}&size=${size}x${size}`;
|
|
582
|
+
return /* @__PURE__ */ React8.createElement(View5, { style: [styles8.qrContainer, style] }, /* @__PURE__ */ React8.createElement(Image3, { src: qrDataUrl || fallbackUrl, style: { width: size, height: size } }));
|
|
625
583
|
};
|
|
626
584
|
var QR_default = QR;
|
|
627
585
|
|
|
628
586
|
// src/components/core/Lista.tsx
|
|
629
587
|
import React9 from "react";
|
|
630
|
-
import { View as View6, Text as
|
|
631
|
-
var
|
|
588
|
+
import { View as View6, Text as Text5, StyleSheet as StyleSheet9 } from "@react-pdf/renderer";
|
|
589
|
+
var styles9 = StyleSheet9.create({
|
|
632
590
|
ul: {
|
|
633
591
|
marginBottom: 10,
|
|
634
592
|
paddingLeft: 15
|
|
@@ -698,7 +656,7 @@ var UL = ({ children, style, type = "disc" }) => {
|
|
|
698
656
|
}
|
|
699
657
|
return child;
|
|
700
658
|
});
|
|
701
|
-
return /* @__PURE__ */ React9.createElement(View6, { style: [
|
|
659
|
+
return /* @__PURE__ */ React9.createElement(View6, { style: [styles9.ul, style] }, childrenWithBullets);
|
|
702
660
|
};
|
|
703
661
|
var OL = ({ children, style, type = "decimal", start = 1 }) => {
|
|
704
662
|
const childrenWithNumbers = React9.Children.map(children, (child, index) => {
|
|
@@ -712,7 +670,7 @@ var OL = ({ children, style, type = "decimal", start = 1 }) => {
|
|
|
712
670
|
}
|
|
713
671
|
return child;
|
|
714
672
|
});
|
|
715
|
-
return /* @__PURE__ */ React9.createElement(View6, { style: [
|
|
673
|
+
return /* @__PURE__ */ React9.createElement(View6, { style: [styles9.ol, style] }, childrenWithNumbers);
|
|
716
674
|
};
|
|
717
675
|
var LI = ({ children, style, bulletType = "disc", isOrdered = false, index = 1, start = 1, value }) => {
|
|
718
676
|
let marker;
|
|
@@ -722,11 +680,11 @@ var LI = ({ children, style, bulletType = "disc", isOrdered = false, index = 1,
|
|
|
722
680
|
} else {
|
|
723
681
|
marker = getBulletPoint(bulletType);
|
|
724
682
|
}
|
|
725
|
-
return /* @__PURE__ */ React9.createElement(View6, { style: [
|
|
683
|
+
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));
|
|
726
684
|
};
|
|
727
685
|
|
|
728
686
|
// src/components/core/index.tsx
|
|
729
|
-
import { View as View7, Text as
|
|
687
|
+
import { View as View7, Text as Text6, StyleSheet as StyleSheet10, Font } from "@react-pdf/renderer";
|
|
730
688
|
|
|
731
689
|
// src/functions/decodeBase64Pdf.ts
|
|
732
690
|
var decodeBase64Pdf = (base64, fileName) => {
|
|
@@ -818,11 +776,11 @@ export {
|
|
|
818
776
|
Small,
|
|
819
777
|
Span,
|
|
820
778
|
Strong,
|
|
821
|
-
|
|
779
|
+
StyleSheet10 as StyleSheet,
|
|
822
780
|
Table,
|
|
823
781
|
Tbody,
|
|
824
782
|
Td,
|
|
825
|
-
|
|
783
|
+
Text6 as Text,
|
|
826
784
|
Th,
|
|
827
785
|
Thead,
|
|
828
786
|
Tr,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-pdf-levelup",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.26",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -20,16 +20,14 @@
|
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@react-pdf/renderer": "^4.3.0",
|
|
23
|
-
"
|
|
23
|
+
"qrcode": "^1.5.4",
|
|
24
24
|
"react": "^18",
|
|
25
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",
|
|
31
30
|
"i": "^0.3.7",
|
|
32
|
-
"jsdom": "^26.1.0",
|
|
33
31
|
"lucide-react": "^0.485.0",
|
|
34
32
|
"npm": "^11.3.0",
|
|
35
33
|
"react-router-dom": "^7.4.1",
|
|
@@ -39,7 +37,7 @@
|
|
|
39
37
|
"devDependencies": {
|
|
40
38
|
"@eslint/js": "^9.21.0",
|
|
41
39
|
"@react-pdf/types": "^2.9.0",
|
|
42
|
-
"@types/
|
|
40
|
+
"@types/qrcode": "^1.5.5",
|
|
43
41
|
"@types/react": "^18.2.56",
|
|
44
42
|
"@types/react-dom": "^18.2.19",
|
|
45
43
|
"@vitejs/plugin-react": "^4.3.4",
|