av6-pdf-engine 3.0.0 → 3.0.1

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.d.mts CHANGED
@@ -612,4 +612,78 @@ declare function watermarkUsesLast(mode?: WatermarkMode): boolean;
612
612
  */
613
613
  declare function drawWatermarkForPage(doc: PDFDoc, watermark: WatermarkDef, pageNumber: number, isLast: boolean): void;
614
614
 
615
- export { type Alignment, BARCODE_TYPES, type BarcodeBlock, type BarcodeType, type BaseBlock, type Block, type BlockRendererDeps, type BottomLimitForContentFn, type BoxSpacing, type BuiltInFont, type ColumnsBlock, type CustomDocDefinition, type EnsureSpaceForFn, type FinishPageParams, type FontName, type FontRegistration, type FooterDef, type FooterInput, type HeaderDef, type ImageBlock, type InlineTextStyle, type KeyValueGridBlock, type KeyValueItem, type LineBlock, type ListBlock, type ListItem, type ListStyle, type MeasureBlockHeightFn, type Orientation, type PDFDoc, type PageBackgroundDef, type PageBreakBlock, type PageContext, type PageMargins, PdfEngineError, PdfEngineErrorCode, type PlacedCell, type QRErrorLevel, QR_ERROR_LEVEL, type QrCodeBlock, type RenderBlockArrayFn, type RenderEnv, type ResolvedSpacing, type ShapeBlock, type ShapePoint, type ShapeType, type SignatureBlock, type SpacingInput, type StyleDef, type StyleRef, type TableBlock, type TableBodyIterable, type TableBorderSide, type TableBorderStyle, type TableCell, type TableCellBorder, type TableColumnStyle, type TableRowStyle, type TextBlock, type WatermarkDef, type WatermarkMode, type Width, computeColumnPixelWidths, contentEnv, createBlockRenderer, createBottomLimitForContent, createEnsureSpaceFor, createInitialContext, createMeasureBlockHeight, createProcessSignatureBlock, createStartNewPageLayout, drawFooter, drawHeader, drawPageBackground, drawSignatureBlock, drawStyledText, drawWatermarkForPage, finishPage, generateBarcodeBuffer, generateQrBuffer, getBottomLimitForContent, getFontNameForText, hasPadding, images, isPdfEngineError, mapBarcodeTypeToBcid, materializeImagesInBlocks, materializeQrAndBarcodesInBlocks, mergeStyleDefs, normalizeImageSrc, renderCustomPdf, renderCustomPdfToBuffer, resolveBlockPadding, resolveFooterPadding, resolveHeaderPadding, resolveSpacing, resolveTableCell, resolveTextBlock, toPdfEngineError, watermarkUsesLast };
615
+ interface PieChartOptions {
616
+ /** X coordinate of the circle center. Default: 55 */
617
+ cx?: number;
618
+ /** Y coordinate of the circle center. Default: 55 */
619
+ cy?: number;
620
+ /** Circle radius in points. Default: 50 */
621
+ radius?: number;
622
+ }
623
+ /**
624
+ * Builds an SVG arc path for a pie-slice segment.
625
+ * The slice starts at 12 o'clock and sweeps clockwise.
626
+ *
627
+ * Use the returned string as the `path` property on a shape block
628
+ * with `shape: "path"`.
629
+ *
630
+ * @param percent - Filled portion, 0–100
631
+ * @param options - Circle geometry (defaults match the 110×110 pt donut in the assessment template)
632
+ *
633
+ * @example
634
+ * buildPieSlicePath(75)
635
+ * // "M 55 55 L 55.0 5.0 A 50 50 0 1 1 105.0 55.0 Z"
636
+ *
637
+ * buildPieSlicePath(55, { cx: 55, cy: 55, radius: 50 })
638
+ * // "M 55 55 L 55.0 5.0 A 50 50 0 1 1 39.6 102.6 Z"
639
+ */
640
+ declare function buildPieSlicePath(percent: number, options?: PieChartOptions): string;
641
+ interface PieDataInput {
642
+ obtained: number;
643
+ total: number;
644
+ }
645
+ interface PieDataResult {
646
+ /** Marks / score obtained */
647
+ obtained: number;
648
+ /** Total / full score */
649
+ total: number;
650
+ /** Remaining = total − obtained */
651
+ remaining: number;
652
+ /** Rounded percentage 0–100 */
653
+ percentage: number;
654
+ /** SVG path string for the filled slice */
655
+ piePath: string;
656
+ }
657
+ /**
658
+ * Computes all values needed to render a pie/donut score chart.
659
+ * Works for any obtained-out-of-total scenario — marks, ratings, progress, etc.
660
+ *
661
+ * Pass the returned fields to your substitution service so placeholders like
662
+ * `{{marks.piePath}}`, `{{marks.percentage}}`, `{{marks.remaining}}` resolve correctly.
663
+ *
664
+ * @example
665
+ * calcPieData({ obtained: 55, total: 100 })
666
+ * // { obtained: 55, total: 100, remaining: 45, percentage: 55, piePath: "M 55 55 ..." }
667
+ */
668
+ declare function calcPieData(input: PieDataInput, options?: PieChartOptions): PieDataResult;
669
+ interface PercentagePieResult {
670
+ /** Rounded percentage 0–100 */
671
+ percentage: number;
672
+ /** Complement = 100 − percentage */
673
+ remaining: number;
674
+ /** SVG path string for the filled slice */
675
+ piePath: string;
676
+ }
677
+ /**
678
+ * Builds pie chart fields when you already have a percentage (0–100).
679
+ * Use for strengths/weaknesses scores, skill ratings, progress, etc.
680
+ *
681
+ * @example
682
+ * calcPercentagePie(72, { cx: 50, cy: 50, radius: 42 })
683
+ * // { percentage: 72, remaining: 28, piePath: "M 50 50 ..." }
684
+ */
685
+ declare function calcPercentagePie(percentage: number, options?: PieChartOptions): PercentagePieResult;
686
+ /** Default geometry for the 100×100 pt donut charts in the assessment template. */
687
+ declare const DEFAULT_PIE_OPTIONS: PieChartOptions;
688
+
689
+ export { type Alignment, BARCODE_TYPES, type BarcodeBlock, type BarcodeType, type BaseBlock, type Block, type BlockRendererDeps, type BottomLimitForContentFn, type BoxSpacing, type BuiltInFont, type ColumnsBlock, type CustomDocDefinition, DEFAULT_PIE_OPTIONS, type EnsureSpaceForFn, type FinishPageParams, type FontName, type FontRegistration, type FooterDef, type FooterInput, type HeaderDef, type ImageBlock, type InlineTextStyle, type KeyValueGridBlock, type KeyValueItem, type LineBlock, type ListBlock, type ListItem, type ListStyle, type MeasureBlockHeightFn, type Orientation, type PDFDoc, type PageBackgroundDef, type PageBreakBlock, type PageContext, type PageMargins, PdfEngineError, PdfEngineErrorCode, type PercentagePieResult, type PieChartOptions, type PieDataInput, type PieDataResult, type PlacedCell, type QRErrorLevel, QR_ERROR_LEVEL, type QrCodeBlock, type RenderBlockArrayFn, type RenderEnv, type ResolvedSpacing, type ShapeBlock, type ShapePoint, type ShapeType, type SignatureBlock, type SpacingInput, type StyleDef, type StyleRef, type TableBlock, type TableBodyIterable, type TableBorderSide, type TableBorderStyle, type TableCell, type TableCellBorder, type TableColumnStyle, type TableRowStyle, type TextBlock, type WatermarkDef, type WatermarkMode, type Width, buildPieSlicePath, calcPercentagePie, calcPieData, computeColumnPixelWidths, contentEnv, createBlockRenderer, createBottomLimitForContent, createEnsureSpaceFor, createInitialContext, createMeasureBlockHeight, createProcessSignatureBlock, createStartNewPageLayout, drawFooter, drawHeader, drawPageBackground, drawSignatureBlock, drawStyledText, drawWatermarkForPage, finishPage, generateBarcodeBuffer, generateQrBuffer, getBottomLimitForContent, getFontNameForText, hasPadding, images, isPdfEngineError, mapBarcodeTypeToBcid, materializeImagesInBlocks, materializeQrAndBarcodesInBlocks, mergeStyleDefs, normalizeImageSrc, renderCustomPdf, renderCustomPdfToBuffer, resolveBlockPadding, resolveFooterPadding, resolveHeaderPadding, resolveSpacing, resolveTableCell, resolveTextBlock, toPdfEngineError, watermarkUsesLast };
package/dist/index.d.ts CHANGED
@@ -612,4 +612,78 @@ declare function watermarkUsesLast(mode?: WatermarkMode): boolean;
612
612
  */
613
613
  declare function drawWatermarkForPage(doc: PDFDoc, watermark: WatermarkDef, pageNumber: number, isLast: boolean): void;
614
614
 
615
- export { type Alignment, BARCODE_TYPES, type BarcodeBlock, type BarcodeType, type BaseBlock, type Block, type BlockRendererDeps, type BottomLimitForContentFn, type BoxSpacing, type BuiltInFont, type ColumnsBlock, type CustomDocDefinition, type EnsureSpaceForFn, type FinishPageParams, type FontName, type FontRegistration, type FooterDef, type FooterInput, type HeaderDef, type ImageBlock, type InlineTextStyle, type KeyValueGridBlock, type KeyValueItem, type LineBlock, type ListBlock, type ListItem, type ListStyle, type MeasureBlockHeightFn, type Orientation, type PDFDoc, type PageBackgroundDef, type PageBreakBlock, type PageContext, type PageMargins, PdfEngineError, PdfEngineErrorCode, type PlacedCell, type QRErrorLevel, QR_ERROR_LEVEL, type QrCodeBlock, type RenderBlockArrayFn, type RenderEnv, type ResolvedSpacing, type ShapeBlock, type ShapePoint, type ShapeType, type SignatureBlock, type SpacingInput, type StyleDef, type StyleRef, type TableBlock, type TableBodyIterable, type TableBorderSide, type TableBorderStyle, type TableCell, type TableCellBorder, type TableColumnStyle, type TableRowStyle, type TextBlock, type WatermarkDef, type WatermarkMode, type Width, computeColumnPixelWidths, contentEnv, createBlockRenderer, createBottomLimitForContent, createEnsureSpaceFor, createInitialContext, createMeasureBlockHeight, createProcessSignatureBlock, createStartNewPageLayout, drawFooter, drawHeader, drawPageBackground, drawSignatureBlock, drawStyledText, drawWatermarkForPage, finishPage, generateBarcodeBuffer, generateQrBuffer, getBottomLimitForContent, getFontNameForText, hasPadding, images, isPdfEngineError, mapBarcodeTypeToBcid, materializeImagesInBlocks, materializeQrAndBarcodesInBlocks, mergeStyleDefs, normalizeImageSrc, renderCustomPdf, renderCustomPdfToBuffer, resolveBlockPadding, resolveFooterPadding, resolveHeaderPadding, resolveSpacing, resolveTableCell, resolveTextBlock, toPdfEngineError, watermarkUsesLast };
615
+ interface PieChartOptions {
616
+ /** X coordinate of the circle center. Default: 55 */
617
+ cx?: number;
618
+ /** Y coordinate of the circle center. Default: 55 */
619
+ cy?: number;
620
+ /** Circle radius in points. Default: 50 */
621
+ radius?: number;
622
+ }
623
+ /**
624
+ * Builds an SVG arc path for a pie-slice segment.
625
+ * The slice starts at 12 o'clock and sweeps clockwise.
626
+ *
627
+ * Use the returned string as the `path` property on a shape block
628
+ * with `shape: "path"`.
629
+ *
630
+ * @param percent - Filled portion, 0–100
631
+ * @param options - Circle geometry (defaults match the 110×110 pt donut in the assessment template)
632
+ *
633
+ * @example
634
+ * buildPieSlicePath(75)
635
+ * // "M 55 55 L 55.0 5.0 A 50 50 0 1 1 105.0 55.0 Z"
636
+ *
637
+ * buildPieSlicePath(55, { cx: 55, cy: 55, radius: 50 })
638
+ * // "M 55 55 L 55.0 5.0 A 50 50 0 1 1 39.6 102.6 Z"
639
+ */
640
+ declare function buildPieSlicePath(percent: number, options?: PieChartOptions): string;
641
+ interface PieDataInput {
642
+ obtained: number;
643
+ total: number;
644
+ }
645
+ interface PieDataResult {
646
+ /** Marks / score obtained */
647
+ obtained: number;
648
+ /** Total / full score */
649
+ total: number;
650
+ /** Remaining = total − obtained */
651
+ remaining: number;
652
+ /** Rounded percentage 0–100 */
653
+ percentage: number;
654
+ /** SVG path string for the filled slice */
655
+ piePath: string;
656
+ }
657
+ /**
658
+ * Computes all values needed to render a pie/donut score chart.
659
+ * Works for any obtained-out-of-total scenario — marks, ratings, progress, etc.
660
+ *
661
+ * Pass the returned fields to your substitution service so placeholders like
662
+ * `{{marks.piePath}}`, `{{marks.percentage}}`, `{{marks.remaining}}` resolve correctly.
663
+ *
664
+ * @example
665
+ * calcPieData({ obtained: 55, total: 100 })
666
+ * // { obtained: 55, total: 100, remaining: 45, percentage: 55, piePath: "M 55 55 ..." }
667
+ */
668
+ declare function calcPieData(input: PieDataInput, options?: PieChartOptions): PieDataResult;
669
+ interface PercentagePieResult {
670
+ /** Rounded percentage 0–100 */
671
+ percentage: number;
672
+ /** Complement = 100 − percentage */
673
+ remaining: number;
674
+ /** SVG path string for the filled slice */
675
+ piePath: string;
676
+ }
677
+ /**
678
+ * Builds pie chart fields when you already have a percentage (0–100).
679
+ * Use for strengths/weaknesses scores, skill ratings, progress, etc.
680
+ *
681
+ * @example
682
+ * calcPercentagePie(72, { cx: 50, cy: 50, radius: 42 })
683
+ * // { percentage: 72, remaining: 28, piePath: "M 50 50 ..." }
684
+ */
685
+ declare function calcPercentagePie(percentage: number, options?: PieChartOptions): PercentagePieResult;
686
+ /** Default geometry for the 100×100 pt donut charts in the assessment template. */
687
+ declare const DEFAULT_PIE_OPTIONS: PieChartOptions;
688
+
689
+ export { type Alignment, BARCODE_TYPES, type BarcodeBlock, type BarcodeType, type BaseBlock, type Block, type BlockRendererDeps, type BottomLimitForContentFn, type BoxSpacing, type BuiltInFont, type ColumnsBlock, type CustomDocDefinition, DEFAULT_PIE_OPTIONS, type EnsureSpaceForFn, type FinishPageParams, type FontName, type FontRegistration, type FooterDef, type FooterInput, type HeaderDef, type ImageBlock, type InlineTextStyle, type KeyValueGridBlock, type KeyValueItem, type LineBlock, type ListBlock, type ListItem, type ListStyle, type MeasureBlockHeightFn, type Orientation, type PDFDoc, type PageBackgroundDef, type PageBreakBlock, type PageContext, type PageMargins, PdfEngineError, PdfEngineErrorCode, type PercentagePieResult, type PieChartOptions, type PieDataInput, type PieDataResult, type PlacedCell, type QRErrorLevel, QR_ERROR_LEVEL, type QrCodeBlock, type RenderBlockArrayFn, type RenderEnv, type ResolvedSpacing, type ShapeBlock, type ShapePoint, type ShapeType, type SignatureBlock, type SpacingInput, type StyleDef, type StyleRef, type TableBlock, type TableBodyIterable, type TableBorderSide, type TableBorderStyle, type TableCell, type TableCellBorder, type TableColumnStyle, type TableRowStyle, type TextBlock, type WatermarkDef, type WatermarkMode, type Width, buildPieSlicePath, calcPercentagePie, calcPieData, computeColumnPixelWidths, contentEnv, createBlockRenderer, createBottomLimitForContent, createEnsureSpaceFor, createInitialContext, createMeasureBlockHeight, createProcessSignatureBlock, createStartNewPageLayout, drawFooter, drawHeader, drawPageBackground, drawSignatureBlock, drawStyledText, drawWatermarkForPage, finishPage, generateBarcodeBuffer, generateQrBuffer, getBottomLimitForContent, getFontNameForText, hasPadding, images, isPdfEngineError, mapBarcodeTypeToBcid, materializeImagesInBlocks, materializeQrAndBarcodesInBlocks, mergeStyleDefs, normalizeImageSrc, renderCustomPdf, renderCustomPdfToBuffer, resolveBlockPadding, resolveFooterPadding, resolveHeaderPadding, resolveSpacing, resolveTableCell, resolveTextBlock, toPdfEngineError, watermarkUsesLast };
package/dist/index.js CHANGED
@@ -31,9 +31,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  BARCODE_TYPES: () => BARCODE_TYPES,
34
+ DEFAULT_PIE_OPTIONS: () => DEFAULT_PIE_OPTIONS,
34
35
  PdfEngineError: () => PdfEngineError,
35
36
  PdfEngineErrorCode: () => PdfEngineErrorCode,
36
37
  QR_ERROR_LEVEL: () => QR_ERROR_LEVEL,
38
+ buildPieSlicePath: () => buildPieSlicePath,
39
+ calcPercentagePie: () => calcPercentagePie,
40
+ calcPieData: () => calcPieData,
37
41
  computeColumnPixelWidths: () => computeColumnPixelWidths,
38
42
  contentEnv: () => contentEnv,
39
43
  createBlockRenderer: () => createBlockRenderer,
@@ -2906,12 +2910,58 @@ async function renderCustomPdfToBuffer(def) {
2906
2910
  runRender(doc, def, fallbackImage);
2907
2911
  });
2908
2912
  }
2913
+
2914
+ // src/utils/pie-chart.ts
2915
+ function buildPieSlicePath(percent, options = {}) {
2916
+ const { cx = 55, cy = 55, radius: r = 50 } = options;
2917
+ const p = Math.max(0, Math.min(100, Number(percent) || 0));
2918
+ if (p <= 0) return "";
2919
+ if (p >= 100) {
2920
+ return `M ${cx} ${cy} L ${cx} ${cy - r} A ${r} ${r} 0 1 1 ${(cx - 0.01).toFixed(2)} ${cy - r} Z`;
2921
+ }
2922
+ const startAngle = -Math.PI / 2;
2923
+ const endAngle = startAngle + p / 100 * 2 * Math.PI;
2924
+ const x1 = cx;
2925
+ const y1 = cy - r;
2926
+ const x2 = cx + r * Math.cos(endAngle);
2927
+ const y2 = cy + r * Math.sin(endAngle);
2928
+ const largeArc = p > 50 ? 1 : 0;
2929
+ return `M ${cx} ${cy} L ${x1.toFixed(1)} ${y1.toFixed(1)} A ${r} ${r} 0 ${largeArc} 1 ${x2.toFixed(1)} ${y2.toFixed(1)} Z`;
2930
+ }
2931
+ function calcPieData(input, options = {}) {
2932
+ const { obtained, total } = input;
2933
+ if (!Number.isFinite(total) || !Number.isFinite(obtained) || total <= 0) {
2934
+ throw new Error(`calcPieData: "total" must be a positive finite number, got ${total}`);
2935
+ }
2936
+ const percentage = Math.round(obtained / total * 100);
2937
+ const remaining = Math.max(0, total - obtained);
2938
+ return {
2939
+ obtained,
2940
+ total,
2941
+ remaining,
2942
+ percentage,
2943
+ piePath: buildPieSlicePath(percentage, options)
2944
+ };
2945
+ }
2946
+ function calcPercentagePie(percentage, options = {}) {
2947
+ const p = Math.max(0, Math.min(100, Math.round(Number(percentage) || 0)));
2948
+ return {
2949
+ percentage: p,
2950
+ remaining: 100 - p,
2951
+ piePath: buildPieSlicePath(p, options)
2952
+ };
2953
+ }
2954
+ var DEFAULT_PIE_OPTIONS = { cx: 50, cy: 50, radius: 42 };
2909
2955
  // Annotate the CommonJS export names for ESM import in node:
2910
2956
  0 && (module.exports = {
2911
2957
  BARCODE_TYPES,
2958
+ DEFAULT_PIE_OPTIONS,
2912
2959
  PdfEngineError,
2913
2960
  PdfEngineErrorCode,
2914
2961
  QR_ERROR_LEVEL,
2962
+ buildPieSlicePath,
2963
+ calcPercentagePie,
2964
+ calcPieData,
2915
2965
  computeColumnPixelWidths,
2916
2966
  contentEnv,
2917
2967
  createBlockRenderer,
package/dist/index.mjs CHANGED
@@ -2829,11 +2829,57 @@ async function renderCustomPdfToBuffer(def) {
2829
2829
  runRender(doc, def, fallbackImage);
2830
2830
  });
2831
2831
  }
2832
+
2833
+ // src/utils/pie-chart.ts
2834
+ function buildPieSlicePath(percent, options = {}) {
2835
+ const { cx = 55, cy = 55, radius: r = 50 } = options;
2836
+ const p = Math.max(0, Math.min(100, Number(percent) || 0));
2837
+ if (p <= 0) return "";
2838
+ if (p >= 100) {
2839
+ return `M ${cx} ${cy} L ${cx} ${cy - r} A ${r} ${r} 0 1 1 ${(cx - 0.01).toFixed(2)} ${cy - r} Z`;
2840
+ }
2841
+ const startAngle = -Math.PI / 2;
2842
+ const endAngle = startAngle + p / 100 * 2 * Math.PI;
2843
+ const x1 = cx;
2844
+ const y1 = cy - r;
2845
+ const x2 = cx + r * Math.cos(endAngle);
2846
+ const y2 = cy + r * Math.sin(endAngle);
2847
+ const largeArc = p > 50 ? 1 : 0;
2848
+ return `M ${cx} ${cy} L ${x1.toFixed(1)} ${y1.toFixed(1)} A ${r} ${r} 0 ${largeArc} 1 ${x2.toFixed(1)} ${y2.toFixed(1)} Z`;
2849
+ }
2850
+ function calcPieData(input, options = {}) {
2851
+ const { obtained, total } = input;
2852
+ if (!Number.isFinite(total) || !Number.isFinite(obtained) || total <= 0) {
2853
+ throw new Error(`calcPieData: "total" must be a positive finite number, got ${total}`);
2854
+ }
2855
+ const percentage = Math.round(obtained / total * 100);
2856
+ const remaining = Math.max(0, total - obtained);
2857
+ return {
2858
+ obtained,
2859
+ total,
2860
+ remaining,
2861
+ percentage,
2862
+ piePath: buildPieSlicePath(percentage, options)
2863
+ };
2864
+ }
2865
+ function calcPercentagePie(percentage, options = {}) {
2866
+ const p = Math.max(0, Math.min(100, Math.round(Number(percentage) || 0)));
2867
+ return {
2868
+ percentage: p,
2869
+ remaining: 100 - p,
2870
+ piePath: buildPieSlicePath(p, options)
2871
+ };
2872
+ }
2873
+ var DEFAULT_PIE_OPTIONS = { cx: 50, cy: 50, radius: 42 };
2832
2874
  export {
2833
2875
  BARCODE_TYPES,
2876
+ DEFAULT_PIE_OPTIONS,
2834
2877
  PdfEngineError,
2835
2878
  PdfEngineErrorCode,
2836
2879
  QR_ERROR_LEVEL,
2880
+ buildPieSlicePath,
2881
+ calcPercentagePie,
2882
+ calcPieData,
2837
2883
  computeColumnPixelWidths,
2838
2884
  contentEnv,
2839
2885
  createBlockRenderer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-pdf-engine",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.mjs",