@softwear/latestcollectioncore 1.0.186 → 1.0.187
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 +12 -6
- package/package.json +1 -1
- package/src/reports.ts +13 -7
package/dist/reports.js
CHANGED
|
@@ -16,13 +16,13 @@ exports.genPDF = void 0;
|
|
|
16
16
|
const jspdf_1 = require("jspdf");
|
|
17
17
|
const date_fns_1 = require("date-fns");
|
|
18
18
|
const deepCopy_1 = __importDefault(require("./deepCopy"));
|
|
19
|
-
/** Measurement uses context `currentPageNumber` (1-based). Rendering
|
|
19
|
+
/** Measurement uses context `currentPageNumber` (1-based). Rendering uses jsPDF’s `getCurrentPageInfo().pageNumber`, which is already 1-based (first page is 1). */
|
|
20
20
|
function getCurrentPageNumber(doc, context) {
|
|
21
21
|
var _a;
|
|
22
22
|
if (context.mode === 'measurement') {
|
|
23
23
|
return (_a = context.currentPageNumber) !== null && _a !== void 0 ? _a : 1;
|
|
24
24
|
}
|
|
25
|
-
return doc.getCurrentPageInfo().pageNumber
|
|
25
|
+
return doc.getCurrentPageInfo().pageNumber;
|
|
26
26
|
}
|
|
27
27
|
// We have to declare some functions that will be called by other functions but also have to call those other functions
|
|
28
28
|
// We overwrite the function definition as soon as those other functions have been declared
|
|
@@ -507,9 +507,14 @@ addObjectToPDF = function (originX, originY, doc, object, printBuffer, paperSize
|
|
|
507
507
|
const layoutXtenths = originX + object.x;
|
|
508
508
|
const layoutYtenths = originY + object.y;
|
|
509
509
|
const rawPrintOnlyAtStartOffset = printOnlyAtStartContainersOffset !== null && printOnlyAtStartContainersOffset !== void 0 ? printOnlyAtStartContainersOffset : 0;
|
|
510
|
-
|
|
510
|
+
/** Must consult current page on every read: `addPage` can move to page 2+ mid-invocation while this call stays open. */
|
|
511
|
+
const effectivePrintOnlyAtStartContainersOffsetNow = () => containerChain.length === 0 &&
|
|
512
|
+
rawPrintOnlyAtStartOffset > 0 &&
|
|
513
|
+
getCurrentPageNumber(doc, context) === 1
|
|
514
|
+
? rawPrintOnlyAtStartOffset
|
|
515
|
+
: 0;
|
|
511
516
|
const x = layoutXtenths / 10;
|
|
512
|
-
const y = (layoutYtenths +
|
|
517
|
+
const y = (layoutYtenths + effectivePrintOnlyAtStartContainersOffsetNow()) / 10;
|
|
513
518
|
const width = object.width / 10;
|
|
514
519
|
const height = object.height / 10;
|
|
515
520
|
// Keep track of the lower righthandside of all objects in this container
|
|
@@ -530,7 +535,7 @@ addObjectToPDF = function (originX, originY, doc, object, printBuffer, paperSize
|
|
|
530
535
|
}
|
|
531
536
|
const nrContainers = source.length;
|
|
532
537
|
let originX = layoutXtenths;
|
|
533
|
-
let originY = layoutYtenths +
|
|
538
|
+
let originY = layoutYtenths + effectivePrintOnlyAtStartContainersOffsetNow();
|
|
534
539
|
for (let containerIndex = 0; containerIndex < nrContainers; containerIndex++) {
|
|
535
540
|
const newContainerChain = containerChain.filter(function () {
|
|
536
541
|
return true;
|
|
@@ -542,7 +547,8 @@ addObjectToPDF = function (originX, originY, doc, object, printBuffer, paperSize
|
|
|
542
547
|
if (useOrphanCheck && (object.pageBreak || originY + minHeightMm > paperSize.height - paperSize.footerHeight)) {
|
|
543
548
|
// We ran out of paper
|
|
544
549
|
originX = layoutXtenths;
|
|
545
|
-
|
|
550
|
+
// Continuation sheets must not reuse the page-1-only overlap bump: addPage hasn't run yet so getCurrentPageNumber is still 1.
|
|
551
|
+
originY = layoutYtenths;
|
|
546
552
|
const newOrigin = addPage(originX, originY, doc, layout, rootPrintBuffer, paperSize, options, newContainerChain, context);
|
|
547
553
|
originX = newOrigin.originX;
|
|
548
554
|
originY = newOrigin.originY;
|
package/package.json
CHANGED
package/src/reports.ts
CHANGED
|
@@ -50,12 +50,12 @@ interface RenderContext {
|
|
|
50
50
|
defaultFontFamily?: string
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
/** Measurement uses context `currentPageNumber` (1-based). Rendering
|
|
53
|
+
/** Measurement uses context `currentPageNumber` (1-based). Rendering uses jsPDF’s `getCurrentPageInfo().pageNumber`, which is already 1-based (first page is 1). */
|
|
54
54
|
function getCurrentPageNumber(doc: jsPDF, context: RenderContext): number {
|
|
55
55
|
if (context.mode === 'measurement') {
|
|
56
56
|
return context.currentPageNumber ?? 1
|
|
57
57
|
}
|
|
58
|
-
return doc.getCurrentPageInfo().pageNumber
|
|
58
|
+
return doc.getCurrentPageInfo().pageNumber
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// We have to declare some functions that will be called by other functions but also have to call those other functions
|
|
@@ -585,11 +585,16 @@ addObjectToPDF = function (
|
|
|
585
585
|
const layoutXtenths = originX + object.x
|
|
586
586
|
const layoutYtenths = originY + object.y
|
|
587
587
|
const rawPrintOnlyAtStartOffset = printOnlyAtStartContainersOffset ?? 0
|
|
588
|
-
|
|
589
|
-
|
|
588
|
+
/** Must consult current page on every read: `addPage` can move to page 2+ mid-invocation while this call stays open. */
|
|
589
|
+
const effectivePrintOnlyAtStartContainersOffsetNow = (): number =>
|
|
590
|
+
containerChain.length === 0 &&
|
|
591
|
+
rawPrintOnlyAtStartOffset > 0 &&
|
|
592
|
+
getCurrentPageNumber(doc, context) === 1
|
|
593
|
+
? rawPrintOnlyAtStartOffset
|
|
594
|
+
: 0
|
|
590
595
|
|
|
591
596
|
const x = layoutXtenths / 10
|
|
592
|
-
const y = (layoutYtenths +
|
|
597
|
+
const y = (layoutYtenths + effectivePrintOnlyAtStartContainersOffsetNow()) / 10
|
|
593
598
|
const width = object.width / 10
|
|
594
599
|
const height = object.height / 10
|
|
595
600
|
// Keep track of the lower righthandside of all objects in this container
|
|
@@ -613,7 +618,7 @@ addObjectToPDF = function (
|
|
|
613
618
|
const nrContainers = source.length
|
|
614
619
|
|
|
615
620
|
let originX = layoutXtenths
|
|
616
|
-
let originY = layoutYtenths +
|
|
621
|
+
let originY = layoutYtenths + effectivePrintOnlyAtStartContainersOffsetNow()
|
|
617
622
|
|
|
618
623
|
for (let containerIndex = 0; containerIndex < nrContainers; containerIndex++) {
|
|
619
624
|
const newContainerChain = containerChain.filter(function () {
|
|
@@ -626,7 +631,8 @@ addObjectToPDF = function (
|
|
|
626
631
|
if (useOrphanCheck && (object.pageBreak || originY + minHeightMm > paperSize.height - paperSize.footerHeight)) {
|
|
627
632
|
// We ran out of paper
|
|
628
633
|
originX = layoutXtenths
|
|
629
|
-
|
|
634
|
+
// Continuation sheets must not reuse the page-1-only overlap bump: addPage hasn't run yet so getCurrentPageNumber is still 1.
|
|
635
|
+
originY = layoutYtenths
|
|
630
636
|
const newOrigin = addPage(originX, originY, doc, layout, rootPrintBuffer, paperSize, options, newContainerChain, context)
|
|
631
637
|
originX = newOrigin.originX
|
|
632
638
|
originY = newOrigin.originY
|