pols-pdf 1.1.2 → 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,3 +1,4 @@
1
+ import pdfkit from 'pdfkit';
1
2
  export type PBoundParams = number | {
2
3
  top?: number;
3
4
  bottom?: number;
@@ -154,7 +155,7 @@ export declare class PPdf {
154
155
  private static readonly lineHeightCache;
155
156
  private cursor;
156
157
  private configPage;
157
- private engine;
158
+ engine: typeof pdfkit;
158
159
  template?: () => void;
159
160
  private currentFont;
160
161
  get title(): string;
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);
@@ -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.2",
3
+ "version": "1.1.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {