h17-sspdf 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -407,3 +407,5 @@ npx sspdf -s source.json -t theme.js -o output.pdf
407
407
  ---
408
408
 
409
409
  Hugo Palma, 2026
410
+
411
+ Built on [jsPDF](https://github.com/parallax/jsPDF).
package/core/pdf-core.js CHANGED
@@ -130,7 +130,7 @@ class PDFCore {
130
130
  subject: meta.subject || "",
131
131
  author: meta.author || "Hugo Palma",
132
132
  keywords: meta.keywords || "",
133
- creator: "SuperSimplePDF (github.com/hugopalma17/sspdf)",
133
+ creator: "SuperSimplePDF (github.com/hugopalma17/sspdf) — built on jsPDF",
134
134
  });
135
135
 
136
136
  this.paintBackground();
@@ -64,34 +64,51 @@ function getCanvas() {
64
64
  return _ChartJSNodeCanvas;
65
65
  }
66
66
 
67
+ /**
68
+ * Pre-render the chart to a PNG buffer and cache it on the operation.
69
+ * Call this before renderDocument() for any source containing chart operations.
70
+ * @param {object} operation - the chart operation object (mutated in place)
71
+ * @returns {Promise<void>}
72
+ */
73
+ async function preRender(operation) {
74
+ const ChartJSNodeCanvas = getCanvas();
75
+ const canvasW = operation.canvasWidth || 1600;
76
+ const canvasH = operation.canvasHeight || 800;
77
+
78
+ const canvas = new ChartJSNodeCanvas({
79
+ width: canvasW,
80
+ height: canvasH,
81
+ backgroundColour: 'transparent',
82
+ });
83
+
84
+ operation._buf = await canvas.renderToBuffer({
85
+ type: operation.chartType || 'bar',
86
+ data: operation.data || { labels: [], datasets: [] },
87
+ options: {
88
+ ...(operation.options || {}),
89
+ responsive: false,
90
+ animation: false,
91
+ },
92
+ });
93
+ }
94
+
67
95
  module.exports = {
68
- async render(ctx) {
69
- const { core, operation, bounds } = ctx;
70
- const ChartJSNodeCanvas = getCanvas();
96
+ preRender,
71
97
 
72
- const widthMm = operation.widthMm || (bounds.right - bounds.left);
73
- const heightMm = operation.heightMm || 80;
74
- const canvasW = operation.canvasWidth || 1600;
75
- const canvasH = operation.canvasHeight || 800;
76
- const x = operation.xMm !== undefined ? operation.xMm : bounds.left;
98
+ render(ctx) {
99
+ const { core, operation, bounds } = ctx;
77
100
 
78
- const canvas = new ChartJSNodeCanvas({
79
- width: canvasW,
80
- height: canvasH,
81
- backgroundColour: 'transparent',
82
- });
101
+ if (!operation._buf) {
102
+ throw new Error(
103
+ 'chart plugin: operation._buf is missing — call plugin.preRender(operation) before renderDocument()'
104
+ );
105
+ }
83
106
 
84
- const buf = await canvas.renderToBuffer({
85
- type: operation.chartType || 'bar',
86
- data: operation.data || { labels: [], datasets: [] },
87
- options: {
88
- ...(operation.options || {}),
89
- responsive: false,
90
- animation: false,
91
- },
92
- });
107
+ const widthMm = operation.widthMm || (bounds.right - bounds.left);
108
+ const heightMm = operation.heightMm || 80;
109
+ const x = operation.xMm !== undefined ? operation.xMm : bounds.left;
93
110
 
94
- core.drawImage({ data: buf, format: 'PNG', x, widthMm, heightMm });
111
+ core.drawImage({ data: operation._buf, format: 'PNG', x, widthMm, heightMm });
95
112
  },
96
113
 
97
114
  estimateHeight(ctx) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h17-sspdf",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Declarative PDF engine — define layout once, feed it JSON, get consistent PDFs",
5
5
  "main": "index.js",
6
6
  "author": "Hugo Palma",