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