pols-pdf 1.1.3 → 1.2.0

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
@@ -110,7 +110,7 @@ pdf.rectangle({
110
110
  pdf.cell({
111
111
  text: 'Texto de la celda',
112
112
  width: 200,
113
- height: 40, // o autojump: true si no se conoce el alto de antemano
113
+ height: 40, // opcional: si se omite, el alto se calcula según el contenido
114
114
  padding: 6,
115
115
  hAlign: 'center',
116
116
  vAlign: 'center',
@@ -122,11 +122,12 @@ pdf.cell({
122
122
 
123
123
  - `text` acepta `string`, `number`, `null`/`undefined`, un objeto `{ chars, font? }`, o un arreglo
124
124
  de estos últimos para mezclar fuentes/estilos dentro de una misma celda.
125
- - Una celda necesita **o bien** `height` (alto fijo) **o bien** `autojump: true` (el alto se
126
- calcula según el contenido y, si no entra en la página actual, el texto restante continúa
127
- automáticamente en una página nueva).
128
- - Si el contenido no entra en la página, `cell()` agrega una página nueva y continúa dibujando el
129
- resto automáticamente.
125
+ - Una celda admite `height` (alto fijo) **o** `autojump` (opcional, `boolean`, por defecto `true`):
126
+ con `autojump` el alto se calcula según el contenido y, si no entra en la página actual, el
127
+ texto restante continúa automáticamente en una página nueva. Pasar `autojump: false` desactiva
128
+ ese salto automático (el contenido que no entre se recorta al borde de la página).
129
+ - Si el contenido no entra en la página (con `autojump` activo, que es el default), `cell()`
130
+ agrega una página nueva y continúa dibujando el resto automáticamente.
130
131
 
131
132
  ---
132
133
 
@@ -193,6 +194,25 @@ Cambia la fuente activa del documento; los métodos de texto (`cell`, `row`, `ta
193
194
  aceptan `font` por llamada (y por fragmento de texto individual dentro de `text`), sin necesidad
194
195
  de llamar a `setFont` explícitamente.
195
196
 
197
+ `font` se hereda en cascada — tabla → fila → celda → fragmento de texto — y cada nivel solo
198
+ sobrescribe las propiedades que declara explícitamente, heredando el resto del nivel anterior. Por
199
+ ejemplo, en:
200
+
201
+ ```typescript
202
+ pdf.table({
203
+ font: { size: '80%' },
204
+ rows: [{
205
+ cells: [
206
+ { text: 'Solped:', font: { bold: true }, weight: 1 },
207
+ { text: '12345', weight: 3 },
208
+ ]
209
+ }]
210
+ })
211
+ ```
212
+
213
+ la celda `'Solped:'` se dibuja en **negrita y al 80% del tamaño de fuente activo**: `bold: true`
214
+ la define la celda, pero `size: '80%'` lo hereda de la tabla porque la celda no lo redefine.
215
+
196
216
  ---
197
217
 
198
218
  ## Tipos con forma abreviada (`*Params`)
@@ -211,6 +231,8 @@ completo:
211
231
 
212
232
  ## Convención de nombres
213
233
 
214
- Todas las clases y tipos exportados llevan el prefijo `P` (`PPdf`, `PCell`, `PRowParams`, etc.),
215
- siguiendo la convención usada en los paquetes hermanos de este ecosistema: `pols-date` (`PDate`)
216
- y `pols-utils` (`PRecord`, `PUtilsNumber`).
234
+ Todas las clases y tipos exportados llevan el prefijo `P` (`PPdf`, `PCellParams`, `PRowParams`,
235
+ etc.), siguiendo la convención usada en los paquetes hermanos de este ecosistema: `pols-date`
236
+ (`PDate`) y `pols-utils` (`PRecord`, `PUtilsNumber`). Los tipos ya resueltos que usa el motor de
237
+ layout internamente (`PCellCompiled`, `PRowCompiled`, `PTableCompiled`, etc.) llevan el sufijo
238
+ `Compiled` y no se exportan — no forman parte de la API pública.
package/dist/index.d.ts CHANGED
@@ -31,10 +31,17 @@ export type PBorderColorParams = string | {
31
31
  left?: string;
32
32
  leftTop?: string;
33
33
  };
34
+ export type PPageMarginsParams = number | {
35
+ top?: number;
36
+ bottom?: number;
37
+ left?: number;
38
+ right?: number;
39
+ show?: boolean;
40
+ };
34
41
  export type PPage = {
35
42
  size: 'A4' | 'LETTER';
36
43
  layout: 'portrait' | 'landscape';
37
- margins: PBoundParams;
44
+ margins: PPageMarginsParams;
38
45
  };
39
46
  export type PFont = {
40
47
  name: string;
@@ -176,6 +183,7 @@ export declare class PPdf {
176
183
  addFirstPage?: boolean;
177
184
  });
178
185
  addPage(config?: Partial<PPage>): void;
186
+ private drawMarginLines;
179
187
  rectangleTo(params: Omit<PRectangle, 'width' | 'height'>): void;
180
188
  rectangle(params: PRectangle): void;
181
189
  build(): PDFKit.PDFDocument;
@@ -198,6 +206,7 @@ export declare class PPdf {
198
206
  cell(params: PCellParams): void;
199
207
  image(params: PImage): void;
200
208
  private prepareBoundValues;
209
+ private prepareMarginsValues;
201
210
  private prepareRadiusValues;
202
211
  private prepareBorderValues;
203
212
  private prepareBorderColorValues;
package/dist/index.js CHANGED
@@ -95,11 +95,12 @@ class PPdf {
95
95
  size: 'A4',
96
96
  layout: 'portrait',
97
97
  ...(params?.page ?? {}),
98
- margins: this.prepareBoundValues(params?.page?.margins, {
98
+ margins: this.prepareMarginsValues(params?.page?.margins, {
99
99
  left: 20,
100
100
  top: 20,
101
101
  right: 20,
102
- bottom: 20
102
+ bottom: 20,
103
+ show: false
103
104
  })
104
105
  };
105
106
  if (params?.addFirstPage == null || params.addFirstPage)
@@ -109,18 +110,25 @@ class PPdf {
109
110
  const finalConfig = {
110
111
  ...this.configPage,
111
112
  ...(config ?? {}),
112
- margins: this.prepareBoundValues(config?.margins ?? this.configPage.margins, {
113
- left: 20,
114
- top: 20,
115
- right: 20,
116
- bottom: 20
117
- })
113
+ margins: this.prepareMarginsValues(config?.margins ?? this.configPage.margins, this.configPage.margins)
118
114
  };
119
115
  this.engine.addPage(finalConfig);
120
116
  this.configPage = finalConfig;
121
117
  this.cursor.top = finalConfig.margins.top;
118
+ this.drawMarginLines();
122
119
  this.template?.();
123
120
  }
121
+ /* Dibuja líneas grises en los márgenes de la hoja actual, sin alterar el cursor */
122
+ drawMarginLines() {
123
+ if (!this.configPage.margins.show)
124
+ return;
125
+ const left = this.configPage.margins.left;
126
+ const top = this.configPage.margins.top;
127
+ const right = this.engine.page.width - this.configPage.margins.right;
128
+ const bottom = this.engine.page.height - this.configPage.margins.bottom;
129
+ this.engine.lineWidth(0.5);
130
+ this.engine.path(`M${left},${top} L${right},${top} L${right},${bottom} L${left},${bottom} Z`).stroke('#999999');
131
+ }
124
132
  rectangleTo(params) {
125
133
  this.rectangle({
126
134
  ...params,
@@ -374,6 +382,9 @@ class PPdf {
374
382
  if (value == 'left') {
375
383
  n = this.engine.page.margins.left;
376
384
  }
385
+ else if (value < 0) {
386
+ n = this.engine.page.width + value;
387
+ }
377
388
  else {
378
389
  n = value;
379
390
  }
@@ -389,6 +400,9 @@ class PPdf {
389
400
  if (value == 'top') {
390
401
  n = this.engine.page.margins.top;
391
402
  }
403
+ else if (value < 0) {
404
+ n = this.engine.page.height + value;
405
+ }
392
406
  else {
393
407
  n = value;
394
408
  }
@@ -683,7 +697,12 @@ class PPdf {
683
697
  left: params.left,
684
698
  pdf: this
685
699
  });
686
- let paramsToDraw = { ...params, width };
700
+ const left = params.left ?? this.cursor.left;
701
+ let paramsToDraw = {
702
+ ...params,
703
+ width,
704
+ left
705
+ };
687
706
  while (paramsToDraw) {
688
707
  const prepared = this.prepareCell(paramsToDraw);
689
708
  this.drawCell(prepared.currentPage);
@@ -698,6 +717,7 @@ class PPdf {
698
717
  paramsToDraw = null;
699
718
  }
700
719
  }
720
+ this.setCursorLeftPosition(left);
701
721
  }
702
722
  image(params) {
703
723
  const options = {};
@@ -751,6 +771,12 @@ class PPdf {
751
771
  return defa;
752
772
  }
753
773
  }
774
+ prepareMarginsValues(value, defa) {
775
+ return {
776
+ ...this.prepareBoundValues(value, defa),
777
+ show: (typeof value == 'object' ? value.show : undefined) ?? defa.show,
778
+ };
779
+ }
754
780
  prepareRadiusValues(value, defa = {
755
781
  leftTop: 0,
756
782
  leftBottom: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pols-pdf",
3
- "version": "1.1.3",
3
+ "version": "1.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {