@softwear/latestcollectioncore 1.0.179 → 1.0.181
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/reports.js +60 -22
- package/package.json +1 -1
- package/src/reports.ts +67 -23
package/dist/reports.js
CHANGED
|
@@ -381,6 +381,8 @@ function drawSimpleObject(x, y, doc, object, printBuffer, width, height, options
|
|
|
381
381
|
}
|
|
382
382
|
function addPage(originX, originY, doc, layout, rootPrintBuffer, paperSize, options, containerChain, context) {
|
|
383
383
|
context.pendingRootStartBumpTenths = 0;
|
|
384
|
+
context.applyRootStartBumpToThisCall = false;
|
|
385
|
+
context.remainingRootStartBumpTenths = 0;
|
|
384
386
|
if (context.mode === 'measurement') {
|
|
385
387
|
// Track page count in measurement mode
|
|
386
388
|
if (context.currentPageCount === undefined) {
|
|
@@ -454,28 +456,48 @@ function drawBottomDwellers(object, originX, originY, absoluteLowerRightHandSide
|
|
|
454
456
|
* Use originX,originY as origin to displace the object's own x,y coordinates
|
|
455
457
|
*/
|
|
456
458
|
addObjectToPDF = function (originX, originY, doc, object, printBuffer, paperSize, layout, options, rootPrintBuffer, containerChain, context) {
|
|
457
|
-
var _a, _b;
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
459
|
+
var _a, _b, _c, _d, _f;
|
|
460
|
+
if (context.applyRootStartBumpToThisCall) {
|
|
461
|
+
context.remainingRootStartBumpTenths = (_a = context.pendingRootStartBumpTenths) !== null && _a !== void 0 ? _a : 0;
|
|
462
|
+
context.applyRootStartBumpToThisCall = false;
|
|
463
|
+
context.pendingRootStartBumpTenths = 0;
|
|
464
|
+
}
|
|
465
|
+
const layoutXtenths = originX + object.x;
|
|
466
|
+
const layoutYtenths = originY + object.y;
|
|
467
|
+
/** printOnlyAtStart offset only for outermost recursion and only until first positioning or addPage clears it */
|
|
468
|
+
const bumpForDrawNonContainer = containerChain.length === 0 ? (_b = context.remainingRootStartBumpTenths) !== null && _b !== void 0 ? _b : 0 : 0;
|
|
469
|
+
const x = layoutXtenths / 10;
|
|
470
|
+
const y = (layoutYtenths + bumpForDrawNonContainer) / 10;
|
|
461
471
|
const width = object.width / 10;
|
|
462
472
|
const height = object.height / 10;
|
|
463
473
|
// Keep track of the lower righthandside of all objects in this container
|
|
464
474
|
// We need to return this object so whatever calls addObjectToPDF knows how big our drawing was
|
|
465
475
|
let absoluteLowerRightHandSide = { x: x + width, y: y + height };
|
|
466
|
-
if (!object.active)
|
|
476
|
+
if (!object.active) {
|
|
477
|
+
if (bumpForDrawNonContainer !== 0)
|
|
478
|
+
context.remainingRootStartBumpTenths = 0;
|
|
467
479
|
return absoluteLowerRightHandSide;
|
|
468
|
-
|
|
480
|
+
}
|
|
481
|
+
if (object.type != 'container') {
|
|
482
|
+
if (bumpForDrawNonContainer !== 0)
|
|
483
|
+
context.remainingRootStartBumpTenths = 0;
|
|
469
484
|
drawSimpleObject(x, y, doc, object, printBuffer, width, height, options, context);
|
|
485
|
+
}
|
|
470
486
|
// Recursively draw all child objects from a container object
|
|
471
487
|
if (object.type == 'container') {
|
|
472
|
-
let originX = x * 10, originY = y * 10;
|
|
473
488
|
const source = containerLoopSource(object, printBuffer);
|
|
474
489
|
if (source === undefined) {
|
|
475
|
-
(
|
|
490
|
+
(_c = options.onAlert) === null || _c === void 0 ? void 0 : _c.call(options, { header: 'containernotfound', body: object.source, type: 'warning', timeout: 10000 });
|
|
491
|
+
if (containerChain.length === 0)
|
|
492
|
+
context.remainingRootStartBumpTenths = 0;
|
|
476
493
|
return absoluteLowerRightHandSide;
|
|
477
494
|
}
|
|
478
495
|
const nrContainers = source.length;
|
|
496
|
+
let bumpOnce = containerChain.length === 0 ? (_d = context.remainingRootStartBumpTenths) !== null && _d !== void 0 ? _d : 0 : 0;
|
|
497
|
+
if (bumpOnce !== 0 && containerChain.length === 0)
|
|
498
|
+
context.remainingRootStartBumpTenths = 0;
|
|
499
|
+
let originX = layoutXtenths;
|
|
500
|
+
let originY = layoutYtenths + bumpOnce;
|
|
479
501
|
for (let containerIndex = 0; containerIndex < nrContainers; containerIndex++) {
|
|
480
502
|
const newContainerChain = containerChain.filter(function () {
|
|
481
503
|
return true;
|
|
@@ -486,8 +508,8 @@ addObjectToPDF = function (originX, originY, doc, object, printBuffer, paperSize
|
|
|
486
508
|
const useOrphanCheck = minHeightMm != null && minHeightMm > 0;
|
|
487
509
|
if (useOrphanCheck && (object.pageBreak || originY + minHeightMm > paperSize.height - paperSize.footerHeight)) {
|
|
488
510
|
// We ran out of paper
|
|
489
|
-
originX =
|
|
490
|
-
originY =
|
|
511
|
+
originX = layoutXtenths;
|
|
512
|
+
originY = layoutYtenths + (containerChain.length === 0 ? (_f = context.remainingRootStartBumpTenths) !== null && _f !== void 0 ? _f : 0 : 0);
|
|
491
513
|
const newOrigin = addPage(originX, originY, doc, layout, rootPrintBuffer, paperSize, options, newContainerChain, context);
|
|
492
514
|
originX = newOrigin.originX;
|
|
493
515
|
originY = newOrigin.originY;
|
|
@@ -679,23 +701,31 @@ function genPDF(layout, printBuffer, options = {}) {
|
|
|
679
701
|
// Draw containers in measurement mode (same order as render)
|
|
680
702
|
let measurementTopPrintedStartBottomTenths = 0;
|
|
681
703
|
layout.objects
|
|
682
|
-
.filter((object) => object.type == 'container' && object.printOnlyAtStart)
|
|
704
|
+
.filter((object) => object.type == 'container' && object.printOnlyAtStart === true)
|
|
683
705
|
.forEach((object) => {
|
|
684
706
|
const lh = addObjectToPDF(0, 0, measurementDoc, object, printBuffer, paperSize, layout, options, printBuffer, [], measurementContext);
|
|
685
707
|
measurementTopPrintedStartBottomTenths = Math.max(measurementTopPrintedStartBottomTenths, lh.y * 10);
|
|
686
708
|
});
|
|
687
709
|
layout.objects
|
|
688
710
|
.filter((object) => object.type == 'container' &&
|
|
689
|
-
|
|
690
|
-
|
|
711
|
+
object.printOnlyAtEnd !== true &&
|
|
712
|
+
object.printOnlyAtStart !== true)
|
|
691
713
|
.forEach((object) => {
|
|
692
|
-
|
|
714
|
+
const bumpTenths = Math.max(0, measurementTopPrintedStartBottomTenths - object.y);
|
|
715
|
+
if (bumpTenths > 0) {
|
|
716
|
+
measurementContext.applyRootStartBumpToThisCall = true;
|
|
717
|
+
measurementContext.pendingRootStartBumpTenths = bumpTenths;
|
|
718
|
+
}
|
|
693
719
|
addObjectToPDF(0, 0, measurementDoc, object, printBuffer, paperSize, layout, options, printBuffer, [], measurementContext);
|
|
694
720
|
});
|
|
695
721
|
layout.objects
|
|
696
|
-
.filter((object) => object.type == 'container' && object.printOnlyAtEnd)
|
|
722
|
+
.filter((object) => object.type == 'container' && object.printOnlyAtEnd === true)
|
|
697
723
|
.forEach((object) => {
|
|
698
|
-
|
|
724
|
+
const bumpTenths = Math.max(0, measurementTopPrintedStartBottomTenths - object.y);
|
|
725
|
+
if (bumpTenths > 0) {
|
|
726
|
+
measurementContext.applyRootStartBumpToThisCall = true;
|
|
727
|
+
measurementContext.pendingRootStartBumpTenths = bumpTenths;
|
|
728
|
+
}
|
|
699
729
|
addObjectToPDF(0, 0, measurementDoc, object, printBuffer, paperSize, layout, options, printBuffer, [], measurementContext);
|
|
700
730
|
});
|
|
701
731
|
// Get total page count from measurement pass
|
|
@@ -717,7 +747,7 @@ function genPDF(layout, printBuffer, options = {}) {
|
|
|
717
747
|
drawStaticPartOfPage(doc, layout, printBuffer, paperSize, options, renderContext);
|
|
718
748
|
let renderTopPrintedStartBottomTenths = 0;
|
|
719
749
|
layout.objects
|
|
720
|
-
.filter((object) => object.type == 'container' && object.printOnlyAtStart)
|
|
750
|
+
.filter((object) => object.type == 'container' && object.printOnlyAtStart === true)
|
|
721
751
|
.forEach((object) => {
|
|
722
752
|
const lh = addObjectToPDF(0, 0, doc, object, printBuffer, paperSize, layout, options, printBuffer, [], renderContext);
|
|
723
753
|
renderTopPrintedStartBottomTenths = Math.max(renderTopPrintedStartBottomTenths, lh.y * 10);
|
|
@@ -725,16 +755,24 @@ function genPDF(layout, printBuffer, options = {}) {
|
|
|
725
755
|
// Draw containers in rendering mode (body containers after printOnlyAtStart)
|
|
726
756
|
layout.objects
|
|
727
757
|
.filter((object) => object.type == 'container' &&
|
|
728
|
-
|
|
729
|
-
|
|
758
|
+
object.printOnlyAtEnd !== true &&
|
|
759
|
+
object.printOnlyAtStart !== true)
|
|
730
760
|
.forEach((object) => {
|
|
731
|
-
|
|
761
|
+
const bumpTenths = Math.max(0, renderTopPrintedStartBottomTenths - object.y);
|
|
762
|
+
if (bumpTenths > 0) {
|
|
763
|
+
renderContext.applyRootStartBumpToThisCall = true;
|
|
764
|
+
renderContext.pendingRootStartBumpTenths = bumpTenths;
|
|
765
|
+
}
|
|
732
766
|
addObjectToPDF(0, 0, doc, object, printBuffer, paperSize, layout, options, printBuffer, [], renderContext);
|
|
733
767
|
});
|
|
734
768
|
// Draw printOnlyAtEnd containers once at the end (at their layout coordinates on current page)
|
|
735
|
-
const printOnlyAtEndContainers = layout.objects.filter((object) => object.type == 'container' && object.printOnlyAtEnd);
|
|
769
|
+
const printOnlyAtEndContainers = layout.objects.filter((object) => object.type == 'container' && object.printOnlyAtEnd === true);
|
|
736
770
|
printOnlyAtEndContainers.forEach((object) => {
|
|
737
|
-
|
|
771
|
+
const bumpTenths = Math.max(0, renderTopPrintedStartBottomTenths - object.y);
|
|
772
|
+
if (bumpTenths > 0) {
|
|
773
|
+
renderContext.applyRootStartBumpToThisCall = true;
|
|
774
|
+
renderContext.pendingRootStartBumpTenths = bumpTenths;
|
|
775
|
+
}
|
|
738
776
|
addObjectToPDF(0, 0, doc, object, printBuffer, paperSize, layout, options, printBuffer, [], renderContext);
|
|
739
777
|
});
|
|
740
778
|
return doc;
|
package/package.json
CHANGED
package/src/reports.ts
CHANGED
|
@@ -46,8 +46,14 @@ interface RenderContext {
|
|
|
46
46
|
imageAssets?: Map<string, PdfImageAsset>
|
|
47
47
|
/** Layout default font used when object.fontFamily is undefined */
|
|
48
48
|
defaultFontFamily?: string
|
|
49
|
-
/**
|
|
49
|
+
/** Set with {@link pendingRootStartBumpTenths} only for top-level genPDF container draws; moved to remaining on entry. */
|
|
50
|
+
applyRootStartBumpToThisCall?: boolean
|
|
51
|
+
/** Vertical pad (tenths-mm) so body roots sit below rendered printOnlyAtStart siblings; use with applyRootStartBumpToThisCall only. */
|
|
50
52
|
pendingRootStartBumpTenths?: number
|
|
53
|
+
/**
|
|
54
|
+
* First-fragment bump for top-level draws from genPDF — applied with layout coords, then cleared after first positioning or addPage().
|
|
55
|
+
*/
|
|
56
|
+
remainingRootStartBumpTenths?: number
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
// We have to declare some functions that will be called by other functions but also have to call those other functions
|
|
@@ -448,6 +454,8 @@ function addPage(
|
|
|
448
454
|
context: RenderContext
|
|
449
455
|
): { originX: number; originY: number; x: number; y: number } {
|
|
450
456
|
context.pendingRootStartBumpTenths = 0
|
|
457
|
+
context.applyRootStartBumpToThisCall = false
|
|
458
|
+
context.remainingRootStartBumpTenths = 0
|
|
451
459
|
if (context.mode === 'measurement') {
|
|
452
460
|
// Track page count in measurement mode
|
|
453
461
|
if (context.currentPageCount === undefined) {
|
|
@@ -544,29 +552,49 @@ addObjectToPDF = function (
|
|
|
544
552
|
containerChain: { object: ContainerLayoutObject; printBuffer: any }[],
|
|
545
553
|
context: RenderContext
|
|
546
554
|
): { x: number; y: number } {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
555
|
+
if (context.applyRootStartBumpToThisCall) {
|
|
556
|
+
context.remainingRootStartBumpTenths = context.pendingRootStartBumpTenths ?? 0
|
|
557
|
+
context.applyRootStartBumpToThisCall = false
|
|
558
|
+
context.pendingRootStartBumpTenths = 0
|
|
559
|
+
}
|
|
560
|
+
const layoutXtenths = originX + object.x
|
|
561
|
+
const layoutYtenths = originY + object.y
|
|
562
|
+
/** printOnlyAtStart offset only for outermost recursion and only until first positioning or addPage clears it */
|
|
563
|
+
const bumpForDrawNonContainer =
|
|
564
|
+
containerChain.length === 0 ? context.remainingRootStartBumpTenths ?? 0 : 0
|
|
565
|
+
|
|
566
|
+
const x = layoutXtenths / 10
|
|
567
|
+
const y = (layoutYtenths + bumpForDrawNonContainer) / 10
|
|
550
568
|
const width = object.width / 10
|
|
551
569
|
const height = object.height / 10
|
|
552
570
|
// Keep track of the lower righthandside of all objects in this container
|
|
553
571
|
// We need to return this object so whatever calls addObjectToPDF knows how big our drawing was
|
|
554
572
|
let absoluteLowerRightHandSide = { x: x + width, y: y + height }
|
|
555
573
|
|
|
556
|
-
if (!object.active)
|
|
557
|
-
|
|
574
|
+
if (!object.active) {
|
|
575
|
+
if (bumpForDrawNonContainer !== 0) context.remainingRootStartBumpTenths = 0
|
|
576
|
+
return absoluteLowerRightHandSide
|
|
577
|
+
}
|
|
578
|
+
if (object.type != 'container') {
|
|
579
|
+
if (bumpForDrawNonContainer !== 0) context.remainingRootStartBumpTenths = 0
|
|
580
|
+
drawSimpleObject(x, y, doc, object, printBuffer, width, height, options, context)
|
|
581
|
+
}
|
|
558
582
|
|
|
559
583
|
// Recursively draw all child objects from a container object
|
|
560
584
|
if (object.type == 'container') {
|
|
561
|
-
let originX = x * 10,
|
|
562
|
-
originY = y * 10
|
|
563
|
-
|
|
564
585
|
const source = containerLoopSource(object as ContainerLayoutObject, printBuffer)
|
|
565
586
|
if (source === undefined) {
|
|
566
587
|
options.onAlert?.({ header: 'containernotfound', body: object.source, type: 'warning', timeout: 10000 })
|
|
588
|
+
if (containerChain.length === 0) context.remainingRootStartBumpTenths = 0
|
|
567
589
|
return absoluteLowerRightHandSide
|
|
568
590
|
}
|
|
569
591
|
const nrContainers = source.length
|
|
592
|
+
|
|
593
|
+
let bumpOnce = containerChain.length === 0 ? context.remainingRootStartBumpTenths ?? 0 : 0
|
|
594
|
+
if (bumpOnce !== 0 && containerChain.length === 0) context.remainingRootStartBumpTenths = 0
|
|
595
|
+
let originX = layoutXtenths
|
|
596
|
+
let originY = layoutYtenths + bumpOnce
|
|
597
|
+
|
|
570
598
|
for (let containerIndex = 0; containerIndex < nrContainers; containerIndex++) {
|
|
571
599
|
const newContainerChain = containerChain.filter(function () {
|
|
572
600
|
return true
|
|
@@ -577,8 +605,8 @@ addObjectToPDF = function (
|
|
|
577
605
|
const useOrphanCheck = minHeightMm != null && minHeightMm > 0
|
|
578
606
|
if (useOrphanCheck && (object.pageBreak || originY + minHeightMm > paperSize.height - paperSize.footerHeight)) {
|
|
579
607
|
// We ran out of paper
|
|
580
|
-
originX =
|
|
581
|
-
originY =
|
|
608
|
+
originX = layoutXtenths
|
|
609
|
+
originY = layoutYtenths + (containerChain.length === 0 ? context.remainingRootStartBumpTenths ?? 0 : 0)
|
|
582
610
|
const newOrigin = addPage(originX, originY, doc, layout, rootPrintBuffer, paperSize, options, newContainerChain, context)
|
|
583
611
|
originX = newOrigin.originX
|
|
584
612
|
originY = newOrigin.originY
|
|
@@ -804,7 +832,7 @@ export async function genPDF(layout: Layout, printBuffer: any, options: GenPdfOp
|
|
|
804
832
|
// Draw containers in measurement mode (same order as render)
|
|
805
833
|
let measurementTopPrintedStartBottomTenths = 0
|
|
806
834
|
layout.objects
|
|
807
|
-
.filter((object) => object.type == 'container' && (object as ContainerLayoutObject).printOnlyAtStart)
|
|
835
|
+
.filter((object) => object.type == 'container' && (object as ContainerLayoutObject).printOnlyAtStart === true)
|
|
808
836
|
.forEach((object) => {
|
|
809
837
|
const lh = addObjectToPDF(0, 0, measurementDoc, object, printBuffer, paperSize, layout, options, printBuffer, [], measurementContext)
|
|
810
838
|
measurementTopPrintedStartBottomTenths = Math.max(measurementTopPrintedStartBottomTenths, lh.y * 10)
|
|
@@ -813,17 +841,25 @@ export async function genPDF(layout: Layout, printBuffer: any, options: GenPdfOp
|
|
|
813
841
|
.filter(
|
|
814
842
|
(object) =>
|
|
815
843
|
object.type == 'container' &&
|
|
816
|
-
|
|
817
|
-
|
|
844
|
+
(object as ContainerLayoutObject).printOnlyAtEnd !== true &&
|
|
845
|
+
(object as ContainerLayoutObject).printOnlyAtStart !== true
|
|
818
846
|
)
|
|
819
847
|
.forEach((object) => {
|
|
820
|
-
|
|
848
|
+
const bumpTenths = Math.max(0, measurementTopPrintedStartBottomTenths - object.y)
|
|
849
|
+
if (bumpTenths > 0) {
|
|
850
|
+
measurementContext.applyRootStartBumpToThisCall = true
|
|
851
|
+
measurementContext.pendingRootStartBumpTenths = bumpTenths
|
|
852
|
+
}
|
|
821
853
|
addObjectToPDF(0, 0, measurementDoc, object, printBuffer, paperSize, layout, options, printBuffer, [], measurementContext)
|
|
822
854
|
})
|
|
823
855
|
layout.objects
|
|
824
|
-
.filter((object) => object.type == 'container' && (object as ContainerLayoutObject).printOnlyAtEnd)
|
|
856
|
+
.filter((object) => object.type == 'container' && (object as ContainerLayoutObject).printOnlyAtEnd === true)
|
|
825
857
|
.forEach((object) => {
|
|
826
|
-
|
|
858
|
+
const bumpTenths = Math.max(0, measurementTopPrintedStartBottomTenths - object.y)
|
|
859
|
+
if (bumpTenths > 0) {
|
|
860
|
+
measurementContext.applyRootStartBumpToThisCall = true
|
|
861
|
+
measurementContext.pendingRootStartBumpTenths = bumpTenths
|
|
862
|
+
}
|
|
827
863
|
addObjectToPDF(0, 0, measurementDoc, object, printBuffer, paperSize, layout, options, printBuffer, [], measurementContext)
|
|
828
864
|
})
|
|
829
865
|
|
|
@@ -848,7 +884,7 @@ export async function genPDF(layout: Layout, printBuffer: any, options: GenPdfOp
|
|
|
848
884
|
|
|
849
885
|
let renderTopPrintedStartBottomTenths = 0
|
|
850
886
|
layout.objects
|
|
851
|
-
.filter((object) => object.type == 'container' && (object as ContainerLayoutObject).printOnlyAtStart)
|
|
887
|
+
.filter((object) => object.type == 'container' && (object as ContainerLayoutObject).printOnlyAtStart === true)
|
|
852
888
|
.forEach((object) => {
|
|
853
889
|
const lh = addObjectToPDF(0, 0, doc, object, printBuffer, paperSize, layout, options, printBuffer, [], renderContext)
|
|
854
890
|
renderTopPrintedStartBottomTenths = Math.max(renderTopPrintedStartBottomTenths, lh.y * 10)
|
|
@@ -859,20 +895,28 @@ export async function genPDF(layout: Layout, printBuffer: any, options: GenPdfOp
|
|
|
859
895
|
.filter(
|
|
860
896
|
(object) =>
|
|
861
897
|
object.type == 'container' &&
|
|
862
|
-
|
|
863
|
-
|
|
898
|
+
(object as ContainerLayoutObject).printOnlyAtEnd !== true &&
|
|
899
|
+
(object as ContainerLayoutObject).printOnlyAtStart !== true
|
|
864
900
|
)
|
|
865
901
|
.forEach((object) => {
|
|
866
|
-
|
|
902
|
+
const bumpTenths = Math.max(0, renderTopPrintedStartBottomTenths - object.y)
|
|
903
|
+
if (bumpTenths > 0) {
|
|
904
|
+
renderContext.applyRootStartBumpToThisCall = true
|
|
905
|
+
renderContext.pendingRootStartBumpTenths = bumpTenths
|
|
906
|
+
}
|
|
867
907
|
addObjectToPDF(0, 0, doc, object, printBuffer, paperSize, layout, options, printBuffer, [], renderContext)
|
|
868
908
|
})
|
|
869
909
|
|
|
870
910
|
// Draw printOnlyAtEnd containers once at the end (at their layout coordinates on current page)
|
|
871
911
|
const printOnlyAtEndContainers = layout.objects.filter(
|
|
872
|
-
(object) => object.type == 'container' && (object as ContainerLayoutObject).printOnlyAtEnd
|
|
912
|
+
(object) => object.type == 'container' && (object as ContainerLayoutObject).printOnlyAtEnd === true
|
|
873
913
|
)
|
|
874
914
|
printOnlyAtEndContainers.forEach((object) => {
|
|
875
|
-
|
|
915
|
+
const bumpTenths = Math.max(0, renderTopPrintedStartBottomTenths - object.y)
|
|
916
|
+
if (bumpTenths > 0) {
|
|
917
|
+
renderContext.applyRootStartBumpToThisCall = true
|
|
918
|
+
renderContext.pendingRootStartBumpTenths = bumpTenths
|
|
919
|
+
}
|
|
876
920
|
addObjectToPDF(0, 0, doc, object, printBuffer, paperSize, layout, options, printBuffer, [], renderContext)
|
|
877
921
|
})
|
|
878
922
|
return doc
|