pols-pdf 1.1.1 → 1.1.3

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
@@ -1,27 +1,16 @@
1
+ import pdfkit from 'pdfkit';
1
2
  export type PBoundParams = number | {
2
3
  top?: number;
3
4
  bottom?: number;
4
5
  left?: number;
5
6
  right?: number;
6
7
  };
7
- export type PBound = {
8
- top: number;
9
- bottom: number;
10
- left: number;
11
- right: number;
12
- };
13
8
  export type PRadiusParams = number | {
14
9
  leftTop?: number;
15
10
  rightTop?: number;
16
11
  rightBottom?: number;
17
12
  leftBottom?: number;
18
13
  };
19
- export type PRadius = {
20
- leftTop: number;
21
- rightTop: number;
22
- rightBottom: number;
23
- leftBottom: number;
24
- };
25
14
  export type PBorderParams = boolean | {
26
15
  leftTop?: boolean;
27
16
  top?: boolean;
@@ -32,16 +21,6 @@ export type PBorderParams = boolean | {
32
21
  leftBottom?: boolean;
33
22
  left?: boolean;
34
23
  };
35
- export type PBorder = {
36
- leftTop: boolean;
37
- top: boolean;
38
- rightTop: boolean;
39
- right: boolean;
40
- rightBottom: boolean;
41
- bottom: boolean;
42
- leftBottom: boolean;
43
- left: boolean;
44
- };
45
24
  export type PBorderColorParams = string | {
46
25
  top?: string;
47
26
  rightTop?: string;
@@ -52,16 +31,6 @@ export type PBorderColorParams = string | {
52
31
  left?: string;
53
32
  leftTop?: string;
54
33
  };
55
- export type PBorderColor = {
56
- top: string;
57
- rightTop: string;
58
- right: string;
59
- rightBottom: string;
60
- bottom: string;
61
- leftBottom: string;
62
- left: string;
63
- leftTop: string;
64
- };
65
34
  export type PPage = {
66
35
  size: 'A4' | 'LETTER';
67
36
  layout: 'portrait' | 'landscape';
@@ -119,31 +88,6 @@ export type PTextParams = {
119
88
  chars: string;
120
89
  font?: Partial<PFontParams>;
121
90
  };
122
- type PLetter = {
123
- char: string;
124
- left: number;
125
- top: number;
126
- width: number;
127
- height: number;
128
- font: PFont;
129
- };
130
- export type PCell = {
131
- letters: PLetter[];
132
- left: number;
133
- top: number;
134
- height: number;
135
- width: number;
136
- padding: PBound;
137
- border: PBorder;
138
- radius: PRadius;
139
- stroke?: {
140
- width?: number;
141
- color?: PBorderColorParams;
142
- };
143
- fillColor?: string;
144
- hAlign?: 'left' | 'center' | 'right';
145
- vAlign?: 'top' | 'center' | 'bottom';
146
- };
147
91
  export type PCellParams = {
148
92
  text: null | undefined | number | string | PTextParams | PTextParams[];
149
93
  left?: number;
@@ -167,22 +111,6 @@ export type PCellParams = {
167
111
  } | {
168
112
  autojump?: boolean;
169
113
  });
170
- export type PRow = {
171
- cells: Omit<PCell, 'autojump'>[];
172
- gap?: number;
173
- left: number;
174
- top: number;
175
- width: number;
176
- height: number;
177
- padding: PBound;
178
- border: PBorder;
179
- radius: PRadius;
180
- stroke?: {
181
- width?: number;
182
- color?: PBorderColorParams;
183
- };
184
- fillColor?: string;
185
- };
186
114
  export type PRowParams = {
187
115
  cells: (Omit<PCellParams, 'width' | 'left' | 'top' | 'height' | 'autojump'> & ({
188
116
  width: number;
@@ -222,28 +150,12 @@ export type PTableParams = {
222
150
  width?: 'full' | 'auto' | number;
223
151
  autojump?: boolean;
224
152
  };
225
- export type PTable = {
226
- rows: PRow[];
227
- gap?: number;
228
- left: number;
229
- top: number;
230
- width: number;
231
- height: number;
232
- padding: PBound;
233
- border: PBorder;
234
- radius: PRadius;
235
- stroke?: {
236
- width?: number;
237
- color?: PBorderColorParams;
238
- };
239
- fillColor?: string;
240
- };
241
153
  export declare class PPdf {
242
154
  private static readonly charWidthCache;
243
155
  private static readonly lineHeightCache;
244
156
  private cursor;
245
157
  private configPage;
246
- private engine;
158
+ engine: typeof pdfkit;
247
159
  template?: () => void;
248
160
  private currentFont;
249
161
  get title(): string;
@@ -290,5 +202,4 @@ export declare class PPdf {
290
202
  private prepareBorderValues;
291
203
  private prepareBorderColorValues;
292
204
  }
293
- export {};
294
205
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -6,6 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PPdf = void 0;
7
7
  const pdfkit_1 = __importDefault(require("pdfkit"));
8
8
  const pols_utils_1 = require("pols-utils");
9
+ const calculateWidth = ({ width, left, pdf }) => {
10
+ if (width == null || width == 'auto') {
11
+ return pdf.engine.page.width - pdf.engine.page.margins.right - (left ?? pdf.getCursorLeftPosition());
12
+ }
13
+ else if (width == 'full') {
14
+ return pdf.engine.page.width - pdf.engine.page.margins.right - pdf.engine.page.margins.left;
15
+ }
16
+ else {
17
+ return width;
18
+ }
19
+ };
9
20
  class PPdf {
10
21
  /* Cachés de métricas de fuente, compartidas por todas las instancias: widthOfString/heightOfString
11
22
  de pdfkit son funciones puras de (fuente, carácter) — el mismo par siempre da el mismo resultado —,
@@ -168,17 +179,11 @@ class PPdf {
168
179
  return this.engine;
169
180
  }
170
181
  table(params) {
171
- const width = (() => {
172
- if (params.width == null || params.width == 'auto') {
173
- return this.engine.page.width - this.engine.page.margins.right - (params.left ?? this.cursor.left);
174
- }
175
- else if (params.width == 'full') {
176
- return this.engine.page.width - this.engine.page.margins.right - this.engine.page.margins.left;
177
- }
178
- else {
179
- return params.width;
180
- }
181
- })();
182
+ const width = calculateWidth({
183
+ width: params.width,
184
+ left: params.left,
185
+ pdf: this,
186
+ });
182
187
  const left = params.left ?? this.cursor.left;
183
188
  const top = params.top ?? this.cursor.top;
184
189
  const padding = this.prepareBoundValues(params.padding);
@@ -204,7 +209,7 @@ class PPdf {
204
209
  left: left + padding.left,
205
210
  top: cursorTop,
206
211
  width: usefulWidth,
207
- font: params.font,
212
+ font: { ...params.font, ...rowToDraw.font },
208
213
  autojump: params.autojump ?? true
209
214
  });
210
215
  if (preparedRow.currentPage.cells.some(cell => cell.letters?.length)) {
@@ -304,7 +309,7 @@ class PPdf {
304
309
  left: cursorLeft,
305
310
  top: top + padding.top,
306
311
  width: cellWidth,
307
- font: cell.font ?? params.font,
312
+ font: { ...params.font, ...cell.font },
308
313
  autojump: params.autojump ?? true,
309
314
  complete: params.complete
310
315
  });
@@ -673,7 +678,12 @@ class PPdf {
673
678
  this.setCursorTopPosition(params.top + params.height);
674
679
  }
675
680
  cell(params) {
676
- let paramsToDraw = params;
681
+ const width = calculateWidth({
682
+ width: params.width,
683
+ left: params.left,
684
+ pdf: this
685
+ });
686
+ let paramsToDraw = { ...params, width };
677
687
  while (paramsToDraw) {
678
688
  const prepared = this.prepareCell(paramsToDraw);
679
689
  this.drawCell(prepared.currentPage);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pols-pdf",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {