pols-pdf 1.2.0 → 1.2.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.ts CHANGED
@@ -164,6 +164,7 @@ export declare class PPdf {
164
164
  private configPage;
165
165
  engine: typeof pdfkit;
166
166
  template?: () => void;
167
+ private templateIsRunning;
167
168
  private currentFont;
168
169
  get title(): string;
169
170
  set title(value: string);
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ class PPdf {
31
31
  configPage;
32
32
  engine;
33
33
  template;
34
+ templateIsRunning = false;
34
35
  currentFont = {
35
36
  name: 'Helvetica',
36
37
  bold: false,
@@ -107,6 +108,8 @@ class PPdf {
107
108
  this.addPage();
108
109
  }
109
110
  addPage(config) {
111
+ if (this.templateIsRunning)
112
+ throw new Error(`Intento de inserción de página dentro de una llamada a la función 'template'`);
110
113
  const finalConfig = {
111
114
  ...this.configPage,
112
115
  ...(config ?? {}),
@@ -116,7 +119,13 @@ class PPdf {
116
119
  this.configPage = finalConfig;
117
120
  this.cursor.top = finalConfig.margins.top;
118
121
  this.drawMarginLines();
119
- this.template?.();
122
+ this.templateIsRunning = true;
123
+ try {
124
+ this.template?.();
125
+ }
126
+ finally {
127
+ this.templateIsRunning = false;
128
+ }
120
129
  }
121
130
  /* Dibuja líneas grises en los márgenes de la hoja actual, sin alterar el cursor */
122
131
  drawMarginLines() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pols-pdf",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {