pdf-catalog-generator 3.1.2 → 3.1.4
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/README.md +11 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +229 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +230 -137
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,31 +1,8 @@
|
|
|
1
|
-
import { StyleSheet, Font, View, Text, Link, Image, Document, Page, pdf } from '@react-pdf/renderer';
|
|
1
|
+
import { StyleSheet, Font, View, Text, Link, Image, Document, Page, renderToBuffer, pdf } from '@react-pdf/renderer';
|
|
2
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import * as XLSX from 'xlsx';
|
|
4
4
|
|
|
5
5
|
// src/generator.tsx
|
|
6
|
-
var styles = StyleSheet.create({
|
|
7
|
-
wrapper: {
|
|
8
|
-
position: "absolute",
|
|
9
|
-
bottom: 6,
|
|
10
|
-
right: 10,
|
|
11
|
-
flexDirection: "row",
|
|
12
|
-
alignItems: "center",
|
|
13
|
-
opacity: 0.5
|
|
14
|
-
},
|
|
15
|
-
label: {
|
|
16
|
-
fontSize: 6.5,
|
|
17
|
-
color: "#666666",
|
|
18
|
-
letterSpacing: 0.2
|
|
19
|
-
},
|
|
20
|
-
link: {
|
|
21
|
-
fontSize: 6.5,
|
|
22
|
-
color: "#666666",
|
|
23
|
-
textDecoration: "none",
|
|
24
|
-
letterSpacing: 0.2
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
var PoweredByTeziApp = () => /* @__PURE__ */ jsx(View, { style: styles.wrapper, fixed: true, children: /* @__PURE__ */ jsx(Link, { style: styles.link, src: "https://teziapp.com", children: "Powered by Tezi App" }) });
|
|
28
|
-
var PoweredByTeziApp_default = PoweredByTeziApp;
|
|
29
6
|
|
|
30
7
|
// src/utils/fieldHelpers.ts
|
|
31
8
|
function formatFieldName(fieldName) {
|
|
@@ -207,12 +184,12 @@ var dynamicFieldStyles = StyleSheet.create({
|
|
|
207
184
|
flexShrink: 1
|
|
208
185
|
}
|
|
209
186
|
});
|
|
210
|
-
function renderDynamicFields(fields,
|
|
187
|
+
function renderDynamicFields(fields, styles8) {
|
|
211
188
|
if (fields.length === 0) return null;
|
|
212
|
-
const containerStyle =
|
|
213
|
-
const rowStyle =
|
|
214
|
-
const labelStyle =
|
|
215
|
-
const valueStyle =
|
|
189
|
+
const containerStyle = styles8?.container || { marginBottom: 8 };
|
|
190
|
+
const rowStyle = styles8?.row || dynamicFieldStyles.detailRow;
|
|
191
|
+
const labelStyle = styles8?.label || dynamicFieldStyles.detailLabel;
|
|
192
|
+
const valueStyle = styles8?.value || dynamicFieldStyles.detailValue;
|
|
216
193
|
return /* @__PURE__ */ jsx(View, { style: containerStyle, children: fields.map(([key, value]) => /* @__PURE__ */ jsxs(View, { style: rowStyle, children: [
|
|
217
194
|
/* @__PURE__ */ jsxs(Text, { style: labelStyle, children: [
|
|
218
195
|
formatFieldName(key),
|
|
@@ -256,7 +233,7 @@ function mergeTemplateConfig(config = {}) {
|
|
|
256
233
|
...config
|
|
257
234
|
};
|
|
258
235
|
}
|
|
259
|
-
var
|
|
236
|
+
var styles = StyleSheet.create({
|
|
260
237
|
productContainer: {
|
|
261
238
|
flexDirection: "row",
|
|
262
239
|
flexWrap: "wrap",
|
|
@@ -320,27 +297,27 @@ var styles2 = StyleSheet.create({
|
|
|
320
297
|
}
|
|
321
298
|
});
|
|
322
299
|
var Template1 = ({ products }) => {
|
|
323
|
-
return /* @__PURE__ */ jsx(View, { style:
|
|
300
|
+
return /* @__PURE__ */ jsx(View, { style: styles.productContainer, children: products.map((product, index) => {
|
|
324
301
|
const fields = extractProductFields(product);
|
|
325
|
-
return /* @__PURE__ */ jsxs(View, { style:
|
|
326
|
-
/* @__PURE__ */ jsx(Image, { style:
|
|
327
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
328
|
-
/* @__PURE__ */ jsx(Text, { style:
|
|
329
|
-
renderRating(fields.rating,
|
|
302
|
+
return /* @__PURE__ */ jsxs(View, { style: styles.productSection, children: [
|
|
303
|
+
/* @__PURE__ */ jsx(Image, { style: styles.image, src: fields.imageUrl }),
|
|
304
|
+
/* @__PURE__ */ jsxs(View, { style: styles.productTitleBox, children: [
|
|
305
|
+
/* @__PURE__ */ jsx(Text, { style: styles.productTitle, children: fields.title }),
|
|
306
|
+
renderRating(fields.rating, styles.productRate)
|
|
330
307
|
] }),
|
|
331
|
-
fields.description && /* @__PURE__ */ jsx(Text, { style:
|
|
308
|
+
fields.description && /* @__PURE__ */ jsx(Text, { style: styles.productDescription, children: fields.description }),
|
|
332
309
|
renderDynamicFields(fields.dynamicFields),
|
|
333
310
|
renderBuyButton(
|
|
334
311
|
fields.link,
|
|
335
|
-
|
|
312
|
+
styles.buyButton,
|
|
336
313
|
"Buy Now",
|
|
337
|
-
renderPrice(fields.price,
|
|
314
|
+
renderPrice(fields.price, styles.productPrice)
|
|
338
315
|
)
|
|
339
316
|
] }, index);
|
|
340
317
|
}) });
|
|
341
318
|
};
|
|
342
319
|
var Template1_default = Template1;
|
|
343
|
-
var
|
|
320
|
+
var styles2 = StyleSheet.create({
|
|
344
321
|
productContainer: {
|
|
345
322
|
flexDirection: "row",
|
|
346
323
|
flexWrap: "wrap",
|
|
@@ -417,14 +394,14 @@ var styles3 = StyleSheet.create({
|
|
|
417
394
|
}
|
|
418
395
|
});
|
|
419
396
|
var Template2 = ({ products }) => {
|
|
420
|
-
return /* @__PURE__ */ jsx(View, { style:
|
|
397
|
+
return /* @__PURE__ */ jsx(View, { style: styles2.productContainer, children: products.map((product, index) => {
|
|
421
398
|
const fields = extractProductFields(product);
|
|
422
|
-
return /* @__PURE__ */ jsxs(View, { style:
|
|
423
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
424
|
-
/* @__PURE__ */ jsx(Image, { style:
|
|
425
|
-
renderRating(fields.rating,
|
|
399
|
+
return /* @__PURE__ */ jsxs(View, { style: styles2.productSection, children: [
|
|
400
|
+
/* @__PURE__ */ jsxs(View, { style: styles2.productSectionImage, children: [
|
|
401
|
+
/* @__PURE__ */ jsx(Image, { style: styles2.image, src: fields.imageUrl }),
|
|
402
|
+
renderRating(fields.rating, styles2.productRate)
|
|
426
403
|
] }),
|
|
427
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
404
|
+
/* @__PURE__ */ jsxs(View, { style: styles2.productSectionText, children: [
|
|
428
405
|
/* @__PURE__ */ jsxs(
|
|
429
406
|
View,
|
|
430
407
|
{
|
|
@@ -434,20 +411,20 @@ var Template2 = ({ products }) => {
|
|
|
434
411
|
justifyContent: "space-between"
|
|
435
412
|
},
|
|
436
413
|
children: [
|
|
437
|
-
/* @__PURE__ */ jsx(Text, { style:
|
|
438
|
-
renderPrice(fields.price,
|
|
414
|
+
/* @__PURE__ */ jsx(Text, { style: styles2.productTitle, children: fields.title }),
|
|
415
|
+
renderPrice(fields.price, styles2.productPrice)
|
|
439
416
|
]
|
|
440
417
|
}
|
|
441
418
|
),
|
|
442
|
-
fields.description && /* @__PURE__ */ jsx(Text, { style:
|
|
419
|
+
fields.description && /* @__PURE__ */ jsx(Text, { style: styles2.productDescription, children: fields.description }),
|
|
443
420
|
renderDynamicFields(fields.dynamicFields),
|
|
444
|
-
renderBuyButton(fields.link,
|
|
421
|
+
renderBuyButton(fields.link, styles2.buyButton)
|
|
445
422
|
] })
|
|
446
423
|
] }, index);
|
|
447
424
|
}) });
|
|
448
425
|
};
|
|
449
426
|
var Template2_default = Template2;
|
|
450
|
-
var
|
|
427
|
+
var styles3 = StyleSheet.create({
|
|
451
428
|
productSection: {
|
|
452
429
|
width: "100%",
|
|
453
430
|
height: "100vh",
|
|
@@ -527,10 +504,10 @@ var compactDynamicFieldStyles = StyleSheet.create({
|
|
|
527
504
|
var Template3 = ({ products }) => {
|
|
528
505
|
return /* @__PURE__ */ jsx(Fragment, { children: products.map((product, index) => {
|
|
529
506
|
const fields = extractProductFields(product, { maxDynamicFields: 5 });
|
|
530
|
-
return /* @__PURE__ */ jsxs(View, { style:
|
|
531
|
-
/* @__PURE__ */ jsx(Image, { style:
|
|
532
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
533
|
-
/* @__PURE__ */ jsx(Text, { style:
|
|
507
|
+
return /* @__PURE__ */ jsxs(View, { style: styles3.productSection, children: [
|
|
508
|
+
/* @__PURE__ */ jsx(Image, { style: styles3.image, src: fields.imageUrl }),
|
|
509
|
+
/* @__PURE__ */ jsxs(View, { style: styles3.productDetailsBox, children: [
|
|
510
|
+
/* @__PURE__ */ jsx(Text, { style: styles3.productTitle, children: fields.title }),
|
|
534
511
|
/* @__PURE__ */ jsxs(
|
|
535
512
|
View,
|
|
536
513
|
{
|
|
@@ -540,25 +517,25 @@ var Template3 = ({ products }) => {
|
|
|
540
517
|
justifyContent: "space-between"
|
|
541
518
|
},
|
|
542
519
|
children: [
|
|
543
|
-
renderPrice(fields.price,
|
|
544
|
-
renderRating(fields.rating,
|
|
520
|
+
renderPrice(fields.price, styles3.productPrice),
|
|
521
|
+
renderRating(fields.rating, styles3.productRate)
|
|
545
522
|
]
|
|
546
523
|
}
|
|
547
524
|
),
|
|
548
|
-
fields.description && /* @__PURE__ */ jsx(Text, { style:
|
|
525
|
+
fields.description && /* @__PURE__ */ jsx(Text, { style: styles3.productDescription, children: fields.description }),
|
|
549
526
|
renderDynamicFields(fields.dynamicFields, {
|
|
550
527
|
row: compactDynamicFieldStyles.detailRow,
|
|
551
528
|
label: compactDynamicFieldStyles.detailLabel,
|
|
552
529
|
value: compactDynamicFieldStyles.detailValue
|
|
553
530
|
}),
|
|
554
|
-
renderBuyButton(fields.link,
|
|
531
|
+
renderBuyButton(fields.link, styles3.buyButton)
|
|
555
532
|
] }),
|
|
556
533
|
/* @__PURE__ */ jsx(View, { break: true })
|
|
557
534
|
] }, index);
|
|
558
535
|
}) });
|
|
559
536
|
};
|
|
560
537
|
var Template3_default = Template3;
|
|
561
|
-
var
|
|
538
|
+
var styles4 = StyleSheet.create({
|
|
562
539
|
page: {
|
|
563
540
|
width: "100%",
|
|
564
541
|
height: "100%",
|
|
@@ -655,21 +632,21 @@ var Template4 = ({
|
|
|
655
632
|
)
|
|
656
633
|
);
|
|
657
634
|
const fields = extractProductFields(product);
|
|
658
|
-
return /* @__PURE__ */ jsxs(View, { style:
|
|
659
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
660
|
-
/* @__PURE__ */ jsx(Text, { style:
|
|
661
|
-
companyLogo && /* @__PURE__ */ jsx(Image, { style:
|
|
635
|
+
return /* @__PURE__ */ jsxs(View, { style: styles4.page, children: [
|
|
636
|
+
/* @__PURE__ */ jsxs(View, { style: styles4.header, children: [
|
|
637
|
+
/* @__PURE__ */ jsx(Text, { style: styles4.companyName, children: companyName || "" }),
|
|
638
|
+
companyLogo && /* @__PURE__ */ jsx(Image, { style: styles4.brandLogo, src: companyLogo })
|
|
662
639
|
] }),
|
|
663
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
664
|
-
/* @__PURE__ */ jsx(Image, { style:
|
|
665
|
-
allFields.length > 0 && /* @__PURE__ */ jsx(View, { style:
|
|
640
|
+
/* @__PURE__ */ jsxs(View, { style: styles4.productContainer, children: [
|
|
641
|
+
/* @__PURE__ */ jsx(Image, { style: styles4.productImage, src: fields.imageUrl }),
|
|
642
|
+
allFields.length > 0 && /* @__PURE__ */ jsx(View, { style: styles4.detailsBox, children: renderFieldsInColumns(allFields) })
|
|
666
643
|
] }),
|
|
667
644
|
/* @__PURE__ */ jsx(View, { break: true })
|
|
668
645
|
] }, index);
|
|
669
646
|
}) });
|
|
670
647
|
};
|
|
671
648
|
var Template4_default = Template4;
|
|
672
|
-
var
|
|
649
|
+
var styles5 = StyleSheet.create({
|
|
673
650
|
page: {
|
|
674
651
|
width: "100%",
|
|
675
652
|
height: "100%",
|
|
@@ -782,22 +759,22 @@ var Template5 = ({
|
|
|
782
759
|
const { imageUrl, title, dynamicFields } = extractProductFields(product);
|
|
783
760
|
const image2Url = getImage2Url(product);
|
|
784
761
|
const secondImage = image2Url || imageUrl;
|
|
785
|
-
return /* @__PURE__ */ jsxs(View, { style:
|
|
786
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
787
|
-
companyLogo && /* @__PURE__ */ jsx(Image, { style:
|
|
788
|
-
/* @__PURE__ */ jsx(Text, { style:
|
|
762
|
+
return /* @__PURE__ */ jsxs(View, { style: styles5.page, children: [
|
|
763
|
+
/* @__PURE__ */ jsxs(View, { style: styles5.header, children: [
|
|
764
|
+
companyLogo && /* @__PURE__ */ jsx(Image, { style: styles5.logo, src: companyLogo }),
|
|
765
|
+
/* @__PURE__ */ jsx(Text, { style: styles5.companyName, children: companyName })
|
|
789
766
|
] }),
|
|
790
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
791
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
792
|
-
/* @__PURE__ */ jsx(View, { style:
|
|
793
|
-
/* @__PURE__ */ jsx(View, { style:
|
|
767
|
+
/* @__PURE__ */ jsxs(View, { style: styles5.contentContainer, children: [
|
|
768
|
+
/* @__PURE__ */ jsxs(View, { style: styles5.imageSection, children: [
|
|
769
|
+
/* @__PURE__ */ jsx(View, { style: styles5.imageWrapper, children: /* @__PURE__ */ jsx(Image, { style: styles5.productImage, src: imageUrl }) }),
|
|
770
|
+
/* @__PURE__ */ jsx(View, { style: styles5.imageWrapper, children: /* @__PURE__ */ jsx(Image, { style: styles5.productImage, src: secondImage }) })
|
|
794
771
|
] }),
|
|
795
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
796
|
-
title && /* @__PURE__ */ jsx(Text, { style:
|
|
797
|
-
/* @__PURE__ */ jsx(View, { style:
|
|
798
|
-
row:
|
|
799
|
-
label:
|
|
800
|
-
value:
|
|
772
|
+
/* @__PURE__ */ jsxs(View, { style: styles5.detailsSection, children: [
|
|
773
|
+
title && /* @__PURE__ */ jsx(Text, { style: styles5.productTitle, children: title }),
|
|
774
|
+
/* @__PURE__ */ jsx(View, { style: styles5.dynamicFieldsContainer, children: renderDynamicFields(dynamicFields, {
|
|
775
|
+
row: styles5.detailRow,
|
|
776
|
+
label: styles5.detailLabel,
|
|
777
|
+
value: styles5.detailValue
|
|
801
778
|
}) })
|
|
802
779
|
] })
|
|
803
780
|
] }),
|
|
@@ -806,7 +783,7 @@ var Template5 = ({
|
|
|
806
783
|
}) });
|
|
807
784
|
};
|
|
808
785
|
var Template5_default = Template5;
|
|
809
|
-
var
|
|
786
|
+
var styles6 = StyleSheet.create({
|
|
810
787
|
page: {
|
|
811
788
|
width: "100%",
|
|
812
789
|
height: "100%",
|
|
@@ -947,26 +924,26 @@ var Template6 = ({
|
|
|
947
924
|
const { imageUrl, title, dynamicFields } = extractProductFields(product);
|
|
948
925
|
const image2Url = getImage2Url2(product);
|
|
949
926
|
const secondImage = image2Url || imageUrl;
|
|
950
|
-
return /* @__PURE__ */ jsxs(View, { style:
|
|
951
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
952
|
-
/* @__PURE__ */ jsx(Image, { style:
|
|
953
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
954
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
955
|
-
companyLogo && /* @__PURE__ */ jsx(Image, { style:
|
|
956
|
-
/* @__PURE__ */ jsx(Text, { style:
|
|
927
|
+
return /* @__PURE__ */ jsxs(View, { style: styles6.page, children: [
|
|
928
|
+
/* @__PURE__ */ jsxs(View, { style: styles6.leftColumn, children: [
|
|
929
|
+
/* @__PURE__ */ jsx(Image, { style: styles6.imageFull, src: imageUrl }),
|
|
930
|
+
/* @__PURE__ */ jsxs(View, { style: styles6.specsOverlay, children: [
|
|
931
|
+
/* @__PURE__ */ jsxs(View, { style: styles6.specsHeader, children: [
|
|
932
|
+
companyLogo && /* @__PURE__ */ jsx(Image, { style: styles6.miniLogo, src: companyLogo }),
|
|
933
|
+
/* @__PURE__ */ jsx(Text, { style: styles6.designNumber, children: title || "Specifications" })
|
|
957
934
|
] }),
|
|
958
935
|
renderDynamicFields(dynamicFields, {
|
|
959
|
-
row:
|
|
960
|
-
label:
|
|
961
|
-
value:
|
|
936
|
+
row: styles6.fieldRow,
|
|
937
|
+
label: styles6.fieldLabel,
|
|
938
|
+
value: styles6.fieldValue
|
|
962
939
|
})
|
|
963
940
|
] })
|
|
964
941
|
] }),
|
|
965
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
966
|
-
/* @__PURE__ */ jsx(View, { style:
|
|
967
|
-
/* @__PURE__ */ jsx(View, { style:
|
|
968
|
-
companyLogo && /* @__PURE__ */ jsx(Image, { style:
|
|
969
|
-
/* @__PURE__ */ jsx(Text, { style:
|
|
942
|
+
/* @__PURE__ */ jsxs(View, { style: styles6.rightColumn, children: [
|
|
943
|
+
/* @__PURE__ */ jsx(View, { style: styles6.rightImageContainer, children: /* @__PURE__ */ jsx(Image, { style: styles6.rightImage, src: secondImage }) }),
|
|
944
|
+
/* @__PURE__ */ jsx(View, { style: styles6.footer, children: /* @__PURE__ */ jsxs(View, { style: styles6.footerContent, children: [
|
|
945
|
+
companyLogo && /* @__PURE__ */ jsx(Image, { style: styles6.footerLogo, src: companyLogo }),
|
|
946
|
+
/* @__PURE__ */ jsx(Text, { style: styles6.footerText, children: companyName })
|
|
970
947
|
] }) })
|
|
971
948
|
] }),
|
|
972
949
|
/* @__PURE__ */ jsx(View, { break: true })
|
|
@@ -974,7 +951,7 @@ var Template6 = ({
|
|
|
974
951
|
}) });
|
|
975
952
|
};
|
|
976
953
|
var Template6_default = Template6;
|
|
977
|
-
var
|
|
954
|
+
var styles7 = StyleSheet.create({
|
|
978
955
|
page: {
|
|
979
956
|
flexDirection: "column",
|
|
980
957
|
backgroundColor: "#FFFFFF"
|
|
@@ -1006,8 +983,137 @@ Font.registerEmojiSource({
|
|
|
1006
983
|
format: "png",
|
|
1007
984
|
url: "https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/72x72/"
|
|
1008
985
|
});
|
|
986
|
+
function normalizeImageSource(imageSource) {
|
|
987
|
+
const trimmedImageSource = imageSource.trim();
|
|
988
|
+
if (trimmedImageSource.startsWith("data:")) {
|
|
989
|
+
return trimmedImageSource;
|
|
990
|
+
}
|
|
991
|
+
if (trimmedImageSource.startsWith("http://") || trimmedImageSource.startsWith("https://")) {
|
|
992
|
+
return trimmedImageSource;
|
|
993
|
+
}
|
|
994
|
+
let mimeType = "image/png";
|
|
995
|
+
const base64Start = trimmedImageSource.substring(0, 20).toLowerCase();
|
|
996
|
+
if (base64Start.includes("ivborw0kggo") || trimmedImageSource.startsWith("iVBORw0KGgo")) {
|
|
997
|
+
mimeType = "image/png";
|
|
998
|
+
} else if (base64Start.includes("/9j/4aaq") || trimmedImageSource.startsWith("/9j/4AAQ")) {
|
|
999
|
+
mimeType = "image/jpeg";
|
|
1000
|
+
} else if (base64Start.includes("r0lgodlh") || trimmedImageSource.startsWith("R0lGODlh")) {
|
|
1001
|
+
mimeType = "image/gif";
|
|
1002
|
+
} else if (base64Start.includes("uklgr") || trimmedImageSource.startsWith("UklGR")) {
|
|
1003
|
+
mimeType = "image/webp";
|
|
1004
|
+
}
|
|
1005
|
+
return `data:${mimeType};base64,${trimmedImageSource}`;
|
|
1006
|
+
}
|
|
1007
|
+
var IMAGE_FIELD_NAMES_LOWER = /* @__PURE__ */ new Set([
|
|
1008
|
+
"image",
|
|
1009
|
+
"imageurl",
|
|
1010
|
+
"img",
|
|
1011
|
+
"photo",
|
|
1012
|
+
"picture",
|
|
1013
|
+
"image2",
|
|
1014
|
+
"imageurl2",
|
|
1015
|
+
"img2",
|
|
1016
|
+
"photo2",
|
|
1017
|
+
"picture2"
|
|
1018
|
+
]);
|
|
1019
|
+
var DEFAULT_IMAGE_OPTIMIZATION = {
|
|
1020
|
+
enabled: true,
|
|
1021
|
+
maxWidth: 900,
|
|
1022
|
+
maxHeight: 900,
|
|
1023
|
+
quality: 70,
|
|
1024
|
+
logoMaxWidth: 400,
|
|
1025
|
+
logoMaxHeight: 400,
|
|
1026
|
+
logoQuality: 70
|
|
1027
|
+
};
|
|
1028
|
+
function getImageOptimizationOptions(options) {
|
|
1029
|
+
return {
|
|
1030
|
+
...DEFAULT_IMAGE_OPTIMIZATION,
|
|
1031
|
+
...options
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
function getNumericSearchParam(url, key) {
|
|
1035
|
+
const rawValue = url.searchParams.get(key);
|
|
1036
|
+
if (rawValue === null || rawValue.trim() === "") {
|
|
1037
|
+
return null;
|
|
1038
|
+
}
|
|
1039
|
+
const numericValue = Number(rawValue);
|
|
1040
|
+
return Number.isFinite(numericValue) ? numericValue : null;
|
|
1041
|
+
}
|
|
1042
|
+
function optimizeImageUrl(imageSource, options, imageKind) {
|
|
1043
|
+
if (!options.enabled) {
|
|
1044
|
+
return normalizeImageSource(imageSource);
|
|
1045
|
+
}
|
|
1046
|
+
const normalizedSource = normalizeImageSource(imageSource);
|
|
1047
|
+
if (!normalizedSource.startsWith("http://") && !normalizedSource.startsWith("https://")) {
|
|
1048
|
+
return normalizedSource;
|
|
1049
|
+
}
|
|
1050
|
+
let url;
|
|
1051
|
+
try {
|
|
1052
|
+
url = new URL(normalizedSource);
|
|
1053
|
+
} catch {
|
|
1054
|
+
return normalizedSource;
|
|
1055
|
+
}
|
|
1056
|
+
const hostname = url.hostname.toLowerCase();
|
|
1057
|
+
const isImgixStyleHost = hostname.includes("unsplash.com") || hostname.includes("imgix.net") || hostname.includes("builder.io") || hostname.includes("sanity.io");
|
|
1058
|
+
if (!isImgixStyleHost) {
|
|
1059
|
+
return normalizedSource;
|
|
1060
|
+
}
|
|
1061
|
+
const maxWidth = imageKind === "logo" ? options.logoMaxWidth : options.maxWidth;
|
|
1062
|
+
const maxHeight = imageKind === "logo" ? options.logoMaxHeight : options.maxHeight;
|
|
1063
|
+
const quality = imageKind === "logo" ? options.logoQuality : options.quality;
|
|
1064
|
+
url.searchParams.set("auto", "format,compress");
|
|
1065
|
+
url.searchParams.set("fit", "max");
|
|
1066
|
+
const currentWidth = getNumericSearchParam(url, "w");
|
|
1067
|
+
if (currentWidth === null || currentWidth > maxWidth) {
|
|
1068
|
+
url.searchParams.set("w", String(maxWidth));
|
|
1069
|
+
}
|
|
1070
|
+
const currentHeight = getNumericSearchParam(url, "h");
|
|
1071
|
+
if (currentHeight === null || currentHeight > maxHeight) {
|
|
1072
|
+
url.searchParams.set("h", String(maxHeight));
|
|
1073
|
+
}
|
|
1074
|
+
const currentQuality = getNumericSearchParam(url, "q");
|
|
1075
|
+
if (currentQuality === null || currentQuality > quality) {
|
|
1076
|
+
url.searchParams.set("q", String(quality));
|
|
1077
|
+
}
|
|
1078
|
+
return url.toString();
|
|
1079
|
+
}
|
|
1080
|
+
function normalizeProductImages(products, options) {
|
|
1081
|
+
const imageCache = /* @__PURE__ */ new Map();
|
|
1082
|
+
const normalizeCachedImage = (value, imageKind) => {
|
|
1083
|
+
const cacheKey = `${imageKind}:${value}`;
|
|
1084
|
+
const cachedValue = imageCache.get(cacheKey);
|
|
1085
|
+
if (cachedValue) {
|
|
1086
|
+
return cachedValue;
|
|
1087
|
+
}
|
|
1088
|
+
const normalizedValue = optimizeImageUrl(value, options, imageKind);
|
|
1089
|
+
imageCache.set(cacheKey, normalizedValue);
|
|
1090
|
+
return normalizedValue;
|
|
1091
|
+
};
|
|
1092
|
+
return products.map((product) => {
|
|
1093
|
+
const normalizedProduct = { ...product };
|
|
1094
|
+
for (const [key, value] of Object.entries(product)) {
|
|
1095
|
+
if (typeof value === "string" && value.trim() !== "" && IMAGE_FIELD_NAMES_LOWER.has(key.toLowerCase())) {
|
|
1096
|
+
normalizedProduct[key] = normalizeCachedImage(value, "product");
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
return normalizedProduct;
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
async function renderPdfToUint8Array(doc) {
|
|
1103
|
+
const isNodeRuntime = typeof process !== "undefined" && typeof process.versions?.node === "string";
|
|
1104
|
+
if (isNodeRuntime && typeof renderToBuffer === "function") {
|
|
1105
|
+
const buffer = await renderToBuffer(doc);
|
|
1106
|
+
return buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
1107
|
+
}
|
|
1108
|
+
const blob = await pdf(doc).toBlob();
|
|
1109
|
+
const arrayBuffer = await blob.arrayBuffer();
|
|
1110
|
+
return new Uint8Array(arrayBuffer);
|
|
1111
|
+
}
|
|
1009
1112
|
async function generateProductCatalog(config) {
|
|
1010
|
-
const { products, companyLogo, companyName, template = "template1" } = config;
|
|
1113
|
+
const { products, companyLogo, companyName, template = "template1", imageOptimization } = config;
|
|
1114
|
+
const optimizationOptions = getImageOptimizationOptions(imageOptimization);
|
|
1115
|
+
const normalizedProducts = normalizeProductImages(products, optimizationOptions);
|
|
1116
|
+
const normalizedCompanyLogo = companyLogo ? optimizeImageUrl(companyLogo, optimizationOptions, "logo") : companyLogo;
|
|
1011
1117
|
let TemplateComponent;
|
|
1012
1118
|
switch (template) {
|
|
1013
1119
|
case "template1":
|
|
@@ -1032,49 +1138,36 @@ async function generateProductCatalog(config) {
|
|
|
1032
1138
|
TemplateComponent = Template1_default;
|
|
1033
1139
|
}
|
|
1034
1140
|
if (template === "template4") {
|
|
1035
|
-
const doc2 = /* @__PURE__ */ jsx(Document, { children: /* @__PURE__ */
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
/* @__PURE__ */ jsx(PoweredByTeziApp_default, {})
|
|
1045
|
-
] }) });
|
|
1046
|
-
const blob2 = await pdf(doc2).toBlob();
|
|
1047
|
-
const arrayBuffer2 = await blob2.arrayBuffer();
|
|
1048
|
-
return new Uint8Array(arrayBuffer2);
|
|
1141
|
+
const doc2 = /* @__PURE__ */ jsx(Document, { children: /* @__PURE__ */ jsx(Page, { size: "A4", style: styles7.page, children: /* @__PURE__ */ jsx(
|
|
1142
|
+
Template4_default,
|
|
1143
|
+
{
|
|
1144
|
+
products: normalizedProducts,
|
|
1145
|
+
companyLogo: normalizedCompanyLogo,
|
|
1146
|
+
companyName
|
|
1147
|
+
}
|
|
1148
|
+
) }) });
|
|
1149
|
+
return renderPdfToUint8Array(doc2);
|
|
1049
1150
|
}
|
|
1050
1151
|
if (template === "template5" || template === "template6") {
|
|
1051
1152
|
const Template = template === "template5" ? Template5_default : Template6_default;
|
|
1052
|
-
const doc2 = /* @__PURE__ */ jsx(Document, { children: /* @__PURE__ */
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
/* @__PURE__ */ jsx(PoweredByTeziApp_default, {})
|
|
1062
|
-
] }) });
|
|
1063
|
-
const blob2 = await pdf(doc2).toBlob();
|
|
1064
|
-
const arrayBuffer2 = await blob2.arrayBuffer();
|
|
1065
|
-
return new Uint8Array(arrayBuffer2);
|
|
1153
|
+
const doc2 = /* @__PURE__ */ jsx(Document, { children: /* @__PURE__ */ jsx(Page, { size: "A4", orientation: "landscape", style: styles7.page, children: /* @__PURE__ */ jsx(
|
|
1154
|
+
Template,
|
|
1155
|
+
{
|
|
1156
|
+
products: normalizedProducts,
|
|
1157
|
+
companyLogo: normalizedCompanyLogo,
|
|
1158
|
+
companyName
|
|
1159
|
+
}
|
|
1160
|
+
) }) });
|
|
1161
|
+
return renderPdfToUint8Array(doc2);
|
|
1066
1162
|
}
|
|
1067
|
-
const doc = /* @__PURE__ */ jsx(Document, { children: /* @__PURE__ */ jsxs(Page, { size: "A4", style:
|
|
1068
|
-
/* @__PURE__ */ jsxs(View, { style:
|
|
1069
|
-
|
|
1070
|
-
/* @__PURE__ */ jsx(View, { style:
|
|
1163
|
+
const doc = /* @__PURE__ */ jsx(Document, { children: /* @__PURE__ */ jsxs(Page, { size: "A4", style: styles7.page, children: [
|
|
1164
|
+
/* @__PURE__ */ jsxs(View, { style: styles7.header, children: [
|
|
1165
|
+
normalizedCompanyLogo && /* @__PURE__ */ jsx(View, { style: styles7.logoSection, children: /* @__PURE__ */ jsx(Image, { style: styles7.logo, src: normalizedCompanyLogo }) }),
|
|
1166
|
+
/* @__PURE__ */ jsx(View, { style: styles7.storeNameSection, children: /* @__PURE__ */ jsx(Text, { style: styles7.storeName, children: companyName }) })
|
|
1071
1167
|
] }),
|
|
1072
|
-
/* @__PURE__ */ jsx(TemplateComponent, { products })
|
|
1073
|
-
/* @__PURE__ */ jsx(PoweredByTeziApp_default, {})
|
|
1168
|
+
/* @__PURE__ */ jsx(TemplateComponent, { products: normalizedProducts })
|
|
1074
1169
|
] }) });
|
|
1075
|
-
|
|
1076
|
-
const arrayBuffer = await blob.arrayBuffer();
|
|
1077
|
-
return new Uint8Array(arrayBuffer);
|
|
1170
|
+
return renderPdfToUint8Array(doc);
|
|
1078
1171
|
}
|
|
1079
1172
|
function parseExcelFile(buffer) {
|
|
1080
1173
|
const workbook = XLSX.read(buffer, {
|