@pdfme/common 6.1.1-dev.7 → 6.1.1-dev.8
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 +209 -194
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +87 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -168,6 +168,9 @@ z.object({
|
|
|
168
168
|
"schemas.text.max": z.string(),
|
|
169
169
|
"schemas.text.fit": z.string(),
|
|
170
170
|
"schemas.text.dynamicFontSize": z.string(),
|
|
171
|
+
"schemas.text.overflow": z.string(),
|
|
172
|
+
"schemas.text.overflowVisible": z.string(),
|
|
173
|
+
"schemas.text.overflowExpand": z.string(),
|
|
171
174
|
"schemas.text.format": z.string(),
|
|
172
175
|
"schemas.text.plain": z.string(),
|
|
173
176
|
"schemas.text.inlineMarkdown": z.string(),
|
|
@@ -242,6 +245,10 @@ var Schema = z.object({
|
|
|
242
245
|
start: z.number(),
|
|
243
246
|
end: z.number().optional()
|
|
244
247
|
}).optional(),
|
|
248
|
+
__textLineRange: z.object({
|
|
249
|
+
start: z.number(),
|
|
250
|
+
end: z.number().optional()
|
|
251
|
+
}).optional(),
|
|
245
252
|
__isSplit: z.boolean().optional()
|
|
246
253
|
}).passthrough();
|
|
247
254
|
var SchemaForUIAdditionalInfo = z.object({ id: z.string() });
|
|
@@ -634,200 +641,6 @@ var checkGenerateProps = (data) => {
|
|
|
634
641
|
checkProps(data, GenerateProps);
|
|
635
642
|
};
|
|
636
643
|
//#endregion
|
|
637
|
-
//#region src/dynamicTemplate.ts
|
|
638
|
-
/** Floating point tolerance for comparisons */
|
|
639
|
-
var EPSILON = .01;
|
|
640
|
-
/** Calculate the content height of a page (drawable area excluding padding) */
|
|
641
|
-
var getContentHeight = (basePdf) => basePdf.height - basePdf.padding[0] - basePdf.padding[2];
|
|
642
|
-
/** Get the input value for a schema */
|
|
643
|
-
var getSchemaValue = (schema, input) => (schema.readOnly ? schema.content : input?.[schema.name]) || "";
|
|
644
|
-
/**
|
|
645
|
-
* Normalize schemas within a single page into layout items.
|
|
646
|
-
* Returns items sorted by Y coordinate with their order preserved.
|
|
647
|
-
*/
|
|
648
|
-
function normalizePageSchemas(pageSchemas, paddingTop) {
|
|
649
|
-
const items = [];
|
|
650
|
-
const orderMap = /* @__PURE__ */ new Map();
|
|
651
|
-
pageSchemas.forEach((schema, index) => {
|
|
652
|
-
const localY = Math.max(0, schema.position.y - paddingTop);
|
|
653
|
-
items.push({
|
|
654
|
-
schema: cloneDeep(schema),
|
|
655
|
-
baseY: localY,
|
|
656
|
-
height: schema.height,
|
|
657
|
-
dynamicLayout: { heights: [schema.height] }
|
|
658
|
-
});
|
|
659
|
-
orderMap.set(schema.name, index);
|
|
660
|
-
});
|
|
661
|
-
items.sort((a, b) => {
|
|
662
|
-
if (Math.abs(a.baseY - b.baseY) > EPSILON) return a.baseY - b.baseY;
|
|
663
|
-
return (orderMap.get(a.schema.name) ?? 0) - (orderMap.get(b.schema.name) ?? 0);
|
|
664
|
-
});
|
|
665
|
-
return {
|
|
666
|
-
items,
|
|
667
|
-
orderMap
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Place height units on pages, splitting across pages as needed.
|
|
672
|
-
* @returns The final global Y coordinate after placement
|
|
673
|
-
*/
|
|
674
|
-
function placeUnitsOnPages(schema, dynamicLayout, startGlobalY, contentHeight, paddingTop, pages) {
|
|
675
|
-
const dynamicHeights = dynamicLayout.heights;
|
|
676
|
-
let currentUnitIndex = 0;
|
|
677
|
-
let currentPageIndex = Math.floor(startGlobalY / contentHeight);
|
|
678
|
-
let currentYInPage = startGlobalY % contentHeight;
|
|
679
|
-
if (currentYInPage < 0) currentYInPage = 0;
|
|
680
|
-
let actualGlobalEndY = 0;
|
|
681
|
-
const isSplittable = dynamicHeights.length > 1;
|
|
682
|
-
while (currentUnitIndex < dynamicHeights.length) {
|
|
683
|
-
while (pages.length <= currentPageIndex) pages.push([]);
|
|
684
|
-
const spaceLeft = contentHeight - currentYInPage;
|
|
685
|
-
if (dynamicHeights[currentUnitIndex] > spaceLeft + EPSILON) {
|
|
686
|
-
if (!(Math.abs(spaceLeft - contentHeight) <= EPSILON)) {
|
|
687
|
-
currentPageIndex++;
|
|
688
|
-
currentYInPage = 0;
|
|
689
|
-
continue;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
let chunkHeight = 0;
|
|
693
|
-
const startUnitIndex = currentUnitIndex;
|
|
694
|
-
while (currentUnitIndex < dynamicHeights.length) {
|
|
695
|
-
const h = dynamicHeights[currentUnitIndex];
|
|
696
|
-
if (currentYInPage + chunkHeight + h <= contentHeight + EPSILON) {
|
|
697
|
-
chunkHeight += h;
|
|
698
|
-
currentUnitIndex++;
|
|
699
|
-
} else break;
|
|
700
|
-
}
|
|
701
|
-
const isAtPageTop = currentYInPage <= EPSILON;
|
|
702
|
-
if (dynamicLayout.avoidFirstUnitOnly && isSplittable && startUnitIndex === 0 && currentUnitIndex === 1 && dynamicHeights.length > 1 && !isAtPageTop) {
|
|
703
|
-
currentUnitIndex = 0;
|
|
704
|
-
currentPageIndex++;
|
|
705
|
-
currentYInPage = 0;
|
|
706
|
-
continue;
|
|
707
|
-
}
|
|
708
|
-
if (currentUnitIndex === startUnitIndex) {
|
|
709
|
-
chunkHeight += dynamicHeights[currentUnitIndex];
|
|
710
|
-
currentUnitIndex++;
|
|
711
|
-
}
|
|
712
|
-
const patch = dynamicLayout.patchSplitSchema?.({
|
|
713
|
-
schema,
|
|
714
|
-
start: startUnitIndex,
|
|
715
|
-
end: currentUnitIndex,
|
|
716
|
-
isSplit: startUnitIndex > 0,
|
|
717
|
-
chunkHeight
|
|
718
|
-
}) ?? {};
|
|
719
|
-
const newSchema = {
|
|
720
|
-
...schema,
|
|
721
|
-
...patch,
|
|
722
|
-
height: chunkHeight,
|
|
723
|
-
position: {
|
|
724
|
-
...schema.position,
|
|
725
|
-
y: currentYInPage + paddingTop
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
pages[currentPageIndex].push(newSchema);
|
|
729
|
-
currentYInPage += chunkHeight;
|
|
730
|
-
if (currentYInPage >= contentHeight - EPSILON) {
|
|
731
|
-
currentPageIndex++;
|
|
732
|
-
currentYInPage = 0;
|
|
733
|
-
}
|
|
734
|
-
actualGlobalEndY = currentPageIndex * contentHeight + currentYInPage;
|
|
735
|
-
}
|
|
736
|
-
return actualGlobalEndY;
|
|
737
|
-
}
|
|
738
|
-
/** Sort elements within each page by their original order */
|
|
739
|
-
function sortPagesByOrder(pages, orderMap) {
|
|
740
|
-
pages.forEach((page) => {
|
|
741
|
-
page.sort((a, b) => (orderMap.get(a.name) ?? 0) - (orderMap.get(b.name) ?? 0));
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
/** Remove trailing empty pages */
|
|
745
|
-
function removeTrailingEmptyPages(pages) {
|
|
746
|
-
while (pages.length > 1 && pages[pages.length - 1].length === 0) pages.pop();
|
|
747
|
-
}
|
|
748
|
-
/**
|
|
749
|
-
* Process a single template page that has dynamic content.
|
|
750
|
-
* Uses the same layout algorithm as the original implementation,
|
|
751
|
-
* but scoped to a single page's schemas.
|
|
752
|
-
*/
|
|
753
|
-
function processDynamicPage(items, orderMap, contentHeight, paddingTop) {
|
|
754
|
-
const pages = [];
|
|
755
|
-
let totalYOffset = 0;
|
|
756
|
-
for (const item of items) {
|
|
757
|
-
const currentGlobalStartY = item.baseY + totalYOffset;
|
|
758
|
-
totalYOffset = placeUnitsOnPages(item.schema, item.dynamicLayout, currentGlobalStartY, contentHeight, paddingTop, pages) - (item.baseY + item.height);
|
|
759
|
-
}
|
|
760
|
-
sortPagesByOrder(pages, orderMap);
|
|
761
|
-
removeTrailingEmptyPages(pages);
|
|
762
|
-
return pages;
|
|
763
|
-
}
|
|
764
|
-
var normalizeDynamicLayoutResult = (result) => {
|
|
765
|
-
const dynamicLayout = Array.isArray(result) ? { heights: result } : result;
|
|
766
|
-
return {
|
|
767
|
-
...dynamicLayout,
|
|
768
|
-
heights: dynamicLayout.heights.length === 0 ? [0] : dynamicLayout.heights
|
|
769
|
-
};
|
|
770
|
-
};
|
|
771
|
-
/**
|
|
772
|
-
* Process a template containing tables with dynamic heights
|
|
773
|
-
* and generate a new template with proper page breaks.
|
|
774
|
-
*
|
|
775
|
-
* Processing is done page-by-page:
|
|
776
|
-
* - Pages with height changes are processed with full layout calculations
|
|
777
|
-
* - Pages without height changes are copied as-is (no offset propagation between pages)
|
|
778
|
-
*
|
|
779
|
-
* This reduces computation cost by:
|
|
780
|
-
* 1. Limiting layout calculations to pages that need them
|
|
781
|
-
* 2. Avoiding cross-page offset propagation for static pages
|
|
782
|
-
*/
|
|
783
|
-
var getDynamicTemplate = async (arg) => {
|
|
784
|
-
const { template, input, options, _cache, getDynamicHeights } = arg;
|
|
785
|
-
const basePdf = template.basePdf;
|
|
786
|
-
if (!isBlankPdf(basePdf)) return template;
|
|
787
|
-
const contentHeight = getContentHeight(basePdf);
|
|
788
|
-
const paddingTop = basePdf.padding[0];
|
|
789
|
-
const resultPages = [];
|
|
790
|
-
const PARALLEL_LIMIT = 10;
|
|
791
|
-
for (let pageIndex = 0; pageIndex < template.schemas.length; pageIndex++) {
|
|
792
|
-
const pageSchemas = template.schemas[pageIndex];
|
|
793
|
-
const { items, orderMap } = normalizePageSchemas(pageSchemas, paddingTop);
|
|
794
|
-
for (let i = 0; i < items.length; i += PARALLEL_LIMIT) {
|
|
795
|
-
const chunk = items.slice(i, i + PARALLEL_LIMIT);
|
|
796
|
-
const chunkResults = await Promise.all(chunk.map((item) => {
|
|
797
|
-
return getDynamicHeights(getSchemaValue(item.schema, input), {
|
|
798
|
-
schema: item.schema,
|
|
799
|
-
basePdf,
|
|
800
|
-
options,
|
|
801
|
-
_cache
|
|
802
|
-
}).then(normalizeDynamicLayoutResult);
|
|
803
|
-
}));
|
|
804
|
-
for (let j = 0; j < chunkResults.length; j++) items[i + j].dynamicLayout = chunkResults[j];
|
|
805
|
-
}
|
|
806
|
-
const processedPages = processDynamicPage(items, orderMap, contentHeight, paddingTop);
|
|
807
|
-
resultPages.push(...processedPages);
|
|
808
|
-
}
|
|
809
|
-
removeTrailingEmptyPages(resultPages);
|
|
810
|
-
if (resultPages.length === template.schemas.length) {
|
|
811
|
-
let unchanged = true;
|
|
812
|
-
for (let i = 0; i < resultPages.length && unchanged; i++) {
|
|
813
|
-
if (resultPages[i].length !== template.schemas[i].length) {
|
|
814
|
-
unchanged = false;
|
|
815
|
-
break;
|
|
816
|
-
}
|
|
817
|
-
for (let j = 0; j < resultPages[i].length && unchanged; j++) {
|
|
818
|
-
const orig = template.schemas[i][j];
|
|
819
|
-
const result = resultPages[i][j];
|
|
820
|
-
if (Math.abs(orig.height - result.height) > EPSILON || Math.abs(orig.position.y - result.position.y) > EPSILON) unchanged = false;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
if (unchanged) return template;
|
|
824
|
-
}
|
|
825
|
-
return {
|
|
826
|
-
basePdf,
|
|
827
|
-
schemas: resultPages
|
|
828
|
-
};
|
|
829
|
-
};
|
|
830
|
-
//#endregion
|
|
831
644
|
//#region src/expression.ts
|
|
832
645
|
var expressionCache = /* @__PURE__ */ new Map();
|
|
833
646
|
/**
|
|
@@ -1147,6 +960,208 @@ var replacePlaceholders = (arg) => {
|
|
|
1147
960
|
});
|
|
1148
961
|
};
|
|
1149
962
|
//#endregion
|
|
963
|
+
//#region src/dynamicTemplate.ts
|
|
964
|
+
/** Floating point tolerance for comparisons */
|
|
965
|
+
var EPSILON = .01;
|
|
966
|
+
/** Calculate the content height of a page (drawable area excluding padding) */
|
|
967
|
+
var getContentHeight = (basePdf) => basePdf.height - basePdf.padding[0] - basePdf.padding[2];
|
|
968
|
+
/** Get the input value for a schema */
|
|
969
|
+
var getSchemaValue = (schema, input, schemas) => {
|
|
970
|
+
if (!schema.readOnly) return input?.[schema.name] || "";
|
|
971
|
+
if (schema.type !== "text" && schema.type !== "multiVariableText") return schema.content || "";
|
|
972
|
+
return replacePlaceholders({
|
|
973
|
+
content: schema.content || "",
|
|
974
|
+
variables: input,
|
|
975
|
+
schemas
|
|
976
|
+
});
|
|
977
|
+
};
|
|
978
|
+
/**
|
|
979
|
+
* Normalize schemas within a single page into layout items.
|
|
980
|
+
* Returns items sorted by Y coordinate with their order preserved.
|
|
981
|
+
*/
|
|
982
|
+
function normalizePageSchemas(pageSchemas, paddingTop) {
|
|
983
|
+
const items = [];
|
|
984
|
+
const orderMap = /* @__PURE__ */ new Map();
|
|
985
|
+
pageSchemas.forEach((schema, index) => {
|
|
986
|
+
const localY = Math.max(0, schema.position.y - paddingTop);
|
|
987
|
+
items.push({
|
|
988
|
+
schema: cloneDeep(schema),
|
|
989
|
+
baseY: localY,
|
|
990
|
+
height: schema.height,
|
|
991
|
+
dynamicLayout: { heights: [schema.height] }
|
|
992
|
+
});
|
|
993
|
+
orderMap.set(schema.name, index);
|
|
994
|
+
});
|
|
995
|
+
items.sort((a, b) => {
|
|
996
|
+
if (Math.abs(a.baseY - b.baseY) > EPSILON) return a.baseY - b.baseY;
|
|
997
|
+
return (orderMap.get(a.schema.name) ?? 0) - (orderMap.get(b.schema.name) ?? 0);
|
|
998
|
+
});
|
|
999
|
+
return {
|
|
1000
|
+
items,
|
|
1001
|
+
orderMap
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Place height units on pages, splitting across pages as needed.
|
|
1006
|
+
* @returns The final global Y coordinate after placement
|
|
1007
|
+
*/
|
|
1008
|
+
function placeUnitsOnPages(schema, dynamicLayout, startGlobalY, contentHeight, paddingTop, pages) {
|
|
1009
|
+
const dynamicHeights = dynamicLayout.heights;
|
|
1010
|
+
let currentUnitIndex = 0;
|
|
1011
|
+
let currentPageIndex = Math.floor(startGlobalY / contentHeight);
|
|
1012
|
+
let currentYInPage = startGlobalY % contentHeight;
|
|
1013
|
+
if (currentYInPage < 0) currentYInPage = 0;
|
|
1014
|
+
let actualGlobalEndY = 0;
|
|
1015
|
+
const isSplittable = dynamicHeights.length > 1;
|
|
1016
|
+
while (currentUnitIndex < dynamicHeights.length) {
|
|
1017
|
+
while (pages.length <= currentPageIndex) pages.push([]);
|
|
1018
|
+
const spaceLeft = contentHeight - currentYInPage;
|
|
1019
|
+
if (dynamicHeights[currentUnitIndex] > spaceLeft + EPSILON) {
|
|
1020
|
+
if (!(Math.abs(spaceLeft - contentHeight) <= EPSILON)) {
|
|
1021
|
+
currentPageIndex++;
|
|
1022
|
+
currentYInPage = 0;
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
let chunkHeight = 0;
|
|
1027
|
+
const startUnitIndex = currentUnitIndex;
|
|
1028
|
+
while (currentUnitIndex < dynamicHeights.length) {
|
|
1029
|
+
const h = dynamicHeights[currentUnitIndex];
|
|
1030
|
+
if (currentYInPage + chunkHeight + h <= contentHeight + EPSILON) {
|
|
1031
|
+
chunkHeight += h;
|
|
1032
|
+
currentUnitIndex++;
|
|
1033
|
+
} else break;
|
|
1034
|
+
}
|
|
1035
|
+
const isAtPageTop = currentYInPage <= EPSILON;
|
|
1036
|
+
if (dynamicLayout.avoidFirstUnitOnly && isSplittable && startUnitIndex === 0 && currentUnitIndex === 1 && dynamicHeights.length > 1 && !isAtPageTop) {
|
|
1037
|
+
currentUnitIndex = 0;
|
|
1038
|
+
currentPageIndex++;
|
|
1039
|
+
currentYInPage = 0;
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
if (currentUnitIndex === startUnitIndex) {
|
|
1043
|
+
chunkHeight += dynamicHeights[currentUnitIndex];
|
|
1044
|
+
currentUnitIndex++;
|
|
1045
|
+
}
|
|
1046
|
+
const patch = dynamicLayout.patchSplitSchema?.({
|
|
1047
|
+
schema,
|
|
1048
|
+
start: startUnitIndex,
|
|
1049
|
+
end: currentUnitIndex,
|
|
1050
|
+
isSplit: startUnitIndex > 0,
|
|
1051
|
+
chunkHeight
|
|
1052
|
+
}) ?? {};
|
|
1053
|
+
const newSchema = {
|
|
1054
|
+
...schema,
|
|
1055
|
+
...patch,
|
|
1056
|
+
height: chunkHeight,
|
|
1057
|
+
position: {
|
|
1058
|
+
...schema.position,
|
|
1059
|
+
y: currentYInPage + paddingTop
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
pages[currentPageIndex].push(newSchema);
|
|
1063
|
+
currentYInPage += chunkHeight;
|
|
1064
|
+
if (currentYInPage >= contentHeight - EPSILON) {
|
|
1065
|
+
currentPageIndex++;
|
|
1066
|
+
currentYInPage = 0;
|
|
1067
|
+
}
|
|
1068
|
+
actualGlobalEndY = currentPageIndex * contentHeight + currentYInPage;
|
|
1069
|
+
}
|
|
1070
|
+
return actualGlobalEndY;
|
|
1071
|
+
}
|
|
1072
|
+
/** Sort elements within each page by their original order */
|
|
1073
|
+
function sortPagesByOrder(pages, orderMap) {
|
|
1074
|
+
pages.forEach((page) => {
|
|
1075
|
+
page.sort((a, b) => (orderMap.get(a.name) ?? 0) - (orderMap.get(b.name) ?? 0));
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
/** Remove trailing empty pages */
|
|
1079
|
+
function removeTrailingEmptyPages(pages) {
|
|
1080
|
+
while (pages.length > 1 && pages[pages.length - 1].length === 0) pages.pop();
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Process a single template page that has dynamic content.
|
|
1084
|
+
* Uses the same layout algorithm as the original implementation,
|
|
1085
|
+
* but scoped to a single page's schemas.
|
|
1086
|
+
*/
|
|
1087
|
+
function processDynamicPage(items, orderMap, contentHeight, paddingTop) {
|
|
1088
|
+
const pages = [];
|
|
1089
|
+
let totalYOffset = 0;
|
|
1090
|
+
for (const item of items) {
|
|
1091
|
+
const currentGlobalStartY = item.baseY + totalYOffset;
|
|
1092
|
+
totalYOffset = placeUnitsOnPages(item.schema, item.dynamicLayout, currentGlobalStartY, contentHeight, paddingTop, pages) - (item.baseY + item.height);
|
|
1093
|
+
}
|
|
1094
|
+
sortPagesByOrder(pages, orderMap);
|
|
1095
|
+
removeTrailingEmptyPages(pages);
|
|
1096
|
+
return pages;
|
|
1097
|
+
}
|
|
1098
|
+
var normalizeDynamicLayoutResult = (result) => {
|
|
1099
|
+
const dynamicLayout = Array.isArray(result) ? { heights: result } : result;
|
|
1100
|
+
return {
|
|
1101
|
+
...dynamicLayout,
|
|
1102
|
+
heights: dynamicLayout.heights.length === 0 ? [0] : dynamicLayout.heights
|
|
1103
|
+
};
|
|
1104
|
+
};
|
|
1105
|
+
/**
|
|
1106
|
+
* Process a template containing tables with dynamic heights
|
|
1107
|
+
* and generate a new template with proper page breaks.
|
|
1108
|
+
*
|
|
1109
|
+
* Processing is done page-by-page:
|
|
1110
|
+
* - Pages with height changes are processed with full layout calculations
|
|
1111
|
+
* - Pages without height changes are copied as-is (no offset propagation between pages)
|
|
1112
|
+
*
|
|
1113
|
+
* This reduces computation cost by:
|
|
1114
|
+
* 1. Limiting layout calculations to pages that need them
|
|
1115
|
+
* 2. Avoiding cross-page offset propagation for static pages
|
|
1116
|
+
*/
|
|
1117
|
+
var getDynamicTemplate = async (arg) => {
|
|
1118
|
+
const { template, input, options, _cache, getDynamicHeights } = arg;
|
|
1119
|
+
const basePdf = template.basePdf;
|
|
1120
|
+
if (!isBlankPdf(basePdf)) return template;
|
|
1121
|
+
const contentHeight = getContentHeight(basePdf);
|
|
1122
|
+
const paddingTop = basePdf.padding[0];
|
|
1123
|
+
const resultPages = [];
|
|
1124
|
+
const PARALLEL_LIMIT = 10;
|
|
1125
|
+
for (let pageIndex = 0; pageIndex < template.schemas.length; pageIndex++) {
|
|
1126
|
+
const pageSchemas = template.schemas[pageIndex];
|
|
1127
|
+
const { items, orderMap } = normalizePageSchemas(pageSchemas, paddingTop);
|
|
1128
|
+
for (let i = 0; i < items.length; i += PARALLEL_LIMIT) {
|
|
1129
|
+
const chunk = items.slice(i, i + PARALLEL_LIMIT);
|
|
1130
|
+
const chunkResults = await Promise.all(chunk.map((item) => {
|
|
1131
|
+
return getDynamicHeights(getSchemaValue(item.schema, input, template.schemas), {
|
|
1132
|
+
schema: item.schema,
|
|
1133
|
+
basePdf,
|
|
1134
|
+
options,
|
|
1135
|
+
_cache
|
|
1136
|
+
}).then(normalizeDynamicLayoutResult);
|
|
1137
|
+
}));
|
|
1138
|
+
for (let j = 0; j < chunkResults.length; j++) items[i + j].dynamicLayout = chunkResults[j];
|
|
1139
|
+
}
|
|
1140
|
+
const processedPages = processDynamicPage(items, orderMap, contentHeight, paddingTop);
|
|
1141
|
+
resultPages.push(...processedPages);
|
|
1142
|
+
}
|
|
1143
|
+
removeTrailingEmptyPages(resultPages);
|
|
1144
|
+
if (resultPages.length === template.schemas.length) {
|
|
1145
|
+
let unchanged = true;
|
|
1146
|
+
for (let i = 0; i < resultPages.length && unchanged; i++) {
|
|
1147
|
+
if (resultPages[i].length !== template.schemas[i].length) {
|
|
1148
|
+
unchanged = false;
|
|
1149
|
+
break;
|
|
1150
|
+
}
|
|
1151
|
+
for (let j = 0; j < resultPages[i].length && unchanged; j++) {
|
|
1152
|
+
const orig = template.schemas[i][j];
|
|
1153
|
+
const result = resultPages[i][j];
|
|
1154
|
+
if (Math.abs(orig.height - result.height) > EPSILON || Math.abs(orig.position.y - result.position.y) > EPSILON) unchanged = false;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
if (unchanged) return template;
|
|
1158
|
+
}
|
|
1159
|
+
return {
|
|
1160
|
+
basePdf,
|
|
1161
|
+
schemas: resultPages
|
|
1162
|
+
};
|
|
1163
|
+
};
|
|
1164
|
+
//#endregion
|
|
1150
1165
|
//#region src/pluginRegistry.ts
|
|
1151
1166
|
/**
|
|
1152
1167
|
* Wraps plugins collection with utility methods
|