From 99b1c954e0c8c68f7ff76c442c57d1348601d184 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?=
<42278642+schoero@users.noreply.github.com>
Date: Thu, 16 Nov 2023 21:03:21 +0100
Subject: [PATCH] fix(table): converting of tuple shorthand syntax
---
docs/bundle/index.md | 175 ++++++++++++++----------------
docs/pdf/index.md | 179 +++++++++++++++---------------
src/pdf/table.test.snap | 234 +++++++++++++++++++++++++++++++++++++++-
src/pdf/table.test.ts | 14 ++-
src/pdf/table.ts | 42 +++++---
tests/data/table.ts | 57 +++++++++-
6 files changed, 497 insertions(+), 204 deletions(-)
diff --git a/docs/bundle/index.md b/docs/bundle/index.md
index 47d5c26..5f7c9b3 100644
--- a/docs/bundle/index.md
+++ b/docs/bundle/index.md
@@ -28,6 +28,9 @@
- [PDFTable](#interface-pdfpdftable)
- [PDFRow](#interface-pdfpdfrow)
- [PDFColumn](#interface-pdfpdfcolumn)
+ - [PDFBorderColor](#type-alias-pdfpdfbordercolor)
+ - [PDFBorderWidth](#type-alias-pdfpdfborderwidth)
+ - [PDFPadding](#type-alias-pdfpdfpadding)
- [Table](#class-pdftable)
- Constructor
@@ -327,38 +330,11 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L1C0)
- **pdf.align** `"center"` | `"left"` | `"right"` Horizontal alignment of texts inside the table `optional`
- **pdf.backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the table. `optional`
-- **pdf.borderColor** `union` The colors of the border `optional`
-
- - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - `tuple`
-
- - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
-
-- **pdf.borderWidth** `union` Width of the borders of the row. `optional`
-
- - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - `tuple`
-
- - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
-
+- **pdf.borderColor** [`PDFBorderColor`](#type-alias-pdfpdfbordercolor) The colors of the border `optional`
+- **pdf.borderWidth** [`PDFBorderWidth`](#type-alias-pdfpdfborderwidth) Width of the borders of the row. `optional`
- **pdf.fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the table. `optional`
- **pdf.fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the table. `optional`
-- **pdf.padding** `union` Cell padding of the table cells. `optional`
-
- - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - `tuple`
-
- - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
-
+- **pdf.padding** [`PDFPadding`](#type-alias-pdfpdfpadding) Cell padding of the table cells. `optional`
- **pdf.textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside table. `optional`
- **pdf.textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional`
- **pdf.verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of texts inside the table `optional`
@@ -368,7 +344,7 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L1C0)
#### Interface: pdf.PDFRow
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L29C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L30C0)
- **pdf.columns** [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) Table columns.
@@ -376,42 +352,15 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L29C0)
- **pdf.align** `"center"` | `"left"` | `"right"` Horizontal alignment of texts inside the row `optional`
- **pdf.backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the row. `optional`
-- **pdf.borderColor** `union` The colors of the border `optional`
-
- - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - `tuple`
-
- - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
-
-- **pdf.borderWidth** `union` Width of the borders of the row. `optional`
-
- - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - `tuple`
-
- - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
-
+- **pdf.borderColor** [`PDFBorderColor`](#type-alias-pdfpdfbordercolor) The colors of the border `optional`
+- **pdf.borderWidth** [`PDFBorderWidth`](#type-alias-pdfpdfborderwidth) Width of the borders of the row. `optional`
- **pdf.fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the row. `optional`
- **pdf.fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the row. `optional`
- **pdf.header** [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) A header row gets inserted automatically on new pages. Only one header row is allowed. `optional`
- **pdf.height** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Height of the row. Overrides minHeight and maxHeight `optional`
- **pdf.maxHeight** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Maximum height of the row `optional`
- **pdf.minHeight** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Minimum height of the row `optional`
-- **pdf.padding** `union` Cell padding of the table cells inside the row. `optional`
-
- - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - `tuple`
-
- - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
-
+- **pdf.padding** [`PDFPadding`](#type-alias-pdfpdfpadding) Cell padding of the table cells inside the row. `optional`
- **pdf.textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside the row. `optional`
- **pdf.textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional`
- **pdf.verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of texts inside the row `optional`
@@ -420,53 +369,95 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L29C0)
#### Interface: pdf.PDFColumn
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L62C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L63C0)
- **pdf.text** [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) | [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) | [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Cell text.
- **pdf.align** `"center"` | `"left"` | `"right"` Horizontal alignment of the text inside the cell `optional`
- **pdf.backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the cell. `optional`
-- **pdf.borderColor** `union` The colors of the border `optional`
+- **pdf.borderColor** [`PDFBorderColor`](#type-alias-pdfpdfbordercolor) The colors of the border `optional`
+- **pdf.borderWidth** [`PDFBorderWidth`](#type-alias-pdfpdfborderwidth) Width of the borders of the row. `optional`
+- **pdf.fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the cell. `optional`
+- **pdf.fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the cell. `optional`
+- **pdf.padding** [`PDFPadding`](#type-alias-pdfpdfpadding) Cell padding of the table cell. `optional`
+- **pdf.textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside the cell. `optional`
+- **pdf.textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional`
+- **pdf.verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of the text inside the cell `optional`
+- **pdf.width** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Width of the cell. `optional`
- - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - `tuple`
+
- - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+#### Type alias: pdf.PDFBorderColor
-- **pdf.borderWidth** `union` Width of the borders of the row. `optional`
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L90C0)
- - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - `tuple`
+##### Type
- - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+`union`
-- **pdf.fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the cell. `optional`
-- **pdf.fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the cell. `optional`
-- **pdf.padding** `union` Cell padding of the table cell. `optional`
+- [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+- `tuple`
- - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - `tuple`
+ - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+ - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+ - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+ - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+- `tuple`
-- **pdf.textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside the cell. `optional`
-- **pdf.textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional`
-- **pdf.verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of the text inside the cell `optional`
-- **pdf.width** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Width of the cell. `optional`
+ - vertical [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+ - horizontal [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+
+
+
+#### Type alias: pdf.PDFBorderWidth
+
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L95C0)
+
+##### Type
+
+`union`
+
+- [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+- `tuple`
+
+ - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+
+- `tuple`
+
+ - vertical [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - horizontal [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+
+
+
+#### Type alias: pdf.PDFPadding
+
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L100C0)
+
+##### Type
+
+`union`
+
+- [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+- `tuple`
+
+ - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+
+- `tuple`
+
+ - vertical [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - horizontal [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
#### Class: pdf.Table
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L138C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L154C0)
##### Description
@@ -516,7 +507,7 @@ pdf.end();
##### Constructor: new pdf.Table(data)
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L145C2)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L161C2)
###### Parameter
@@ -536,7 +527,7 @@ Creates a new Table instance.
`public`
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L169C2)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L185C2)
###### Parameters
diff --git a/docs/pdf/index.md b/docs/pdf/index.md
index 4281078..9bd09f3 100644
--- a/docs/pdf/index.md
+++ b/docs/pdf/index.md
@@ -28,6 +28,9 @@
- Method
- [attachTo(doc\[, x\]\[, y\])](#method-tableattachtodoc-x-y)
+ - [PDFBorderColor](#type-alias-pdfbordercolor)
+ - [PDFBorderWidth](#type-alias-pdfborderwidth)
+ - [PDFPadding](#type-alias-pdfpadding)
- [PDFTable](#interface-pdftable)
- [PDFRow](#interface-pdfrow)
- [PDFColumn](#interface-pdfcolumn)
@@ -236,7 +239,7 @@ Attaches the Swiss QR Code to a PDF document.
### Class: Table
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L138C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L154C0)
#### Description
@@ -286,7 +289,7 @@ pdf.end();
#### Constructor: new Table(data)
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L145C2)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L161C2)
##### Parameter
@@ -306,7 +309,7 @@ Creates a new Table instance.
`public`
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L169C2)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L185C2)
##### Parameters
@@ -329,48 +332,90 @@ every row that no longer fits on a page.
-### Interface: PDFTable
+### Type alias: PDFBorderColor
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L1C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L90C0)
-- **rows** [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) Table rows.
+#### Type
- - [`PDFRow`](#interface-pdfrow)
+`union`
-- **align** `"center"` | `"left"` | `"right"` Horizontal alignment of texts inside the table `optional`
-- **backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the table. `optional`
-- **borderColor** `union` The colors of the border `optional`
+- [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+- `tuple`
+
+ - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+ - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+ - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+ - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - `tuple`
+- `tuple`
- - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+ - vertical [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
+ - horizontal [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
-- **borderWidth** `union` Width of the borders of the row. `optional`
+
- - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - `tuple`
+### Type alias: PDFBorderWidth
- - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L95C0)
-- **fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the table. `optional`
-- **fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the table. `optional`
-- **padding** `union` Cell padding of the table cells. `optional`
+#### Type
+
+`union`
+
+- [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+- `tuple`
+
+ - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+
+- `tuple`
- - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - `tuple`
+ - vertical [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - horizontal [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+
+
+### Type alias: PDFPadding
+
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L100C0)
+
+#### Type
+
+`union`
+
+- [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+- `tuple`
+
+ - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+- `tuple`
+
+ - vertical [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+ - horizontal [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
+
+
+
+### Interface: PDFTable
+
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L1C0)
+
+- **rows** [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) Table rows.
+
+ - [`PDFRow`](#interface-pdfrow)
+
+- **align** `"center"` | `"left"` | `"right"` Horizontal alignment of texts inside the table `optional`
+- **backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the table. `optional`
+- **borderColor** [`PDFBorderColor`](#type-alias-pdfbordercolor) The colors of the border `optional`
+- **borderWidth** [`PDFBorderWidth`](#type-alias-pdfborderwidth) Width of the borders of the row. `optional`
+- **fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the table. `optional`
+- **fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the table. `optional`
+- **padding** [`PDFPadding`](#type-alias-pdfpadding) Cell padding of the table cells. `optional`
- **textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside table. `optional`
- **textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional`
- **verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of texts inside the table `optional`
@@ -380,7 +425,7 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L1C0)
### Interface: PDFRow
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L29C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L30C0)
- **columns** [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) Table columns.
@@ -388,42 +433,15 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L29C0)
- **align** `"center"` | `"left"` | `"right"` Horizontal alignment of texts inside the row `optional`
- **backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the row. `optional`
-- **borderColor** `union` The colors of the border `optional`
-
- - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - `tuple`
-
- - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
-
-- **borderWidth** `union` Width of the borders of the row. `optional`
-
- - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - `tuple`
-
- - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
-
+- **borderColor** [`PDFBorderColor`](#type-alias-pdfbordercolor) The colors of the border `optional`
+- **borderWidth** [`PDFBorderWidth`](#type-alias-pdfborderwidth) Width of the borders of the row. `optional`
- **fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the row. `optional`
- **fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the row. `optional`
- **header** [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) A header row gets inserted automatically on new pages. Only one header row is allowed. `optional`
- **height** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Height of the row. Overrides minHeight and maxHeight `optional`
- **maxHeight** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Maximum height of the row `optional`
- **minHeight** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Minimum height of the row `optional`
-- **padding** `union` Cell padding of the table cells inside the row. `optional`
-
- - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - `tuple`
-
- - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
-
+- **padding** [`PDFPadding`](#type-alias-pdfpadding) Cell padding of the table cells inside the row. `optional`
- **textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside the row. `optional`
- **textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional`
- **verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of texts inside the row `optional`
@@ -432,43 +450,16 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L29C0)
### Interface: PDFColumn
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L62C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L63C0)
- **text** [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) | [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) | [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Cell text.
- **align** `"center"` | `"left"` | `"right"` Horizontal alignment of the text inside the cell `optional`
- **backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the cell. `optional`
-- **borderColor** `union` The colors of the border `optional`
-
- - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - `tuple`
-
- - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
-
-- **borderWidth** `union` Width of the borders of the row. `optional`
-
- - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - `tuple`
-
- - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
-
+- **borderColor** [`PDFBorderColor`](#type-alias-pdfbordercolor) The colors of the border `optional`
+- **borderWidth** [`PDFBorderWidth`](#type-alias-pdfborderwidth) Width of the borders of the row. `optional`
- **fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the cell. `optional`
- **fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the cell. `optional`
-- **padding** `union` Cell padding of the table cell. `optional`
-
- - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - `tuple`
-
- - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
-
+- **padding** [`PDFPadding`](#type-alias-pdfpadding) Cell padding of the table cell. `optional`
- **textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside the cell. `optional`
- **textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional`
- **verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of the text inside the cell `optional`
diff --git a/src/pdf/table.test.snap b/src/pdf/table.test.snap
index 458aa6c..1de534f 100644
--- a/src/pdf/table.test.snap
+++ b/src/pdf/table.test.snap
@@ -829,6 +829,236 @@ Q
]
`;
+exports[`table > should convert the values of tuples shorthand syntax correctly 1`] = `
+[
+ "1 0 0 -1 0 595.28 cm
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 124.716 m
+72 72 m
+769.89 164.716 m
+72 72 m
+769.89 217.432 m
+72 72 m
+769.89 257.432 m
+72 72 m
+769.89 310.148 m
+72 72 m
+769.89 350.148 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 124.716 m
+72 72 m
+769.89 164.716 m
+72 72 m
+769.89 217.432 m
+72 72 m
+769.89 257.432 m
+72 72 m
+769.89 310.148 m
+72 72 m
+769.89 350.148 m
+72 72 m
+769.89 72 m
+[] 0 d
+0 j
+0 J
+/Gs1 gs
+72 126.716 m
+72 70 l
+/DeviceRGB CS
+1 0 0 SCN
+4 w
+S
+769.89 70 m
+769.89 126.716 l
+/DeviceRGB CS
+1 0 0 SCN
+4 w
+S
+70 72 m
+771.89 72 l
+/DeviceRGB CS
+1 0 0 SCN
+4 w
+S
+771.89 124.716 m
+70 124.716 l
+/DeviceRGB CS
+1 0 0 SCN
+4 w
+S
+72 72 m
+769.89 124.716 m
+72 72 m
+769.89 164.716 m
+[] 0 d
+0 j
+0 J
+/Gs1 gs
+70 164.716 m
+771.89 164.716 l
+/DeviceRGB CS
+1 0 0 SCN
+4 w
+S
+771.89 217.432 m
+70 217.432 l
+/DeviceRGB CS
+1 0 0 SCN
+4 w
+S
+72 72 m
+769.89 217.432 m
+72 72 m
+769.89 257.432 m
+[] 0 d
+0 j
+0 J
+/Gs1 gs
+72 312.148 m
+72 255.432 l
+/DeviceRGB CS
+0 1 0 SCN
+4 w
+S
+769.89 255.432 m
+769.89 312.148 l
+/DeviceRGB CS
+0 1 0 SCN
+4 w
+S
+70 257.432 m
+771.89 257.432 l
+/DeviceRGB CS
+1 0 0 SCN
+4 w
+S
+771.89 310.148 m
+70 310.148 l
+/DeviceRGB CS
+1 0 0 SCN
+4 w
+S
+72 72 m
+769.89 310.148 m
+72 72 m
+769.89 350.148 m
+[] 0 d
+0 j
+0 J
+/Gs1 gs
+72 404.864 m
+72 348.148 l
+/DeviceRGB CS
+1 1 0 SCN
+4 w
+S
+769.89 348.148 m
+769.89 404.864 l
+/DeviceRGB CS
+0 1 0 SCN
+4 w
+S
+70 350.148 m
+771.89 350.148 l
+/DeviceRGB CS
+1 0 0 SCN
+4 w
+S
+771.89 402.864 m
+70 402.864 l
+/DeviceRGB CS
+0 0 1 SCN
+4 w
+S
+72 72 m
+769.89 72 m
+/DeviceRGB cs
+0 0 0 scn
+/Gs2 gs
+q
+1 0 0 -1 0 595.28 cm
+BT
+1 0 0 1 366.7095 494.1115 Tm
+/F1 11 Tf
+[<626f72646572436f6c6f72> -30 <3a> 50 <20222366663030303022> 0] TJ
+ET
+Q
+72 72 m
+769.89 124.716 m
+/DeviceRGB cs
+0 0 0 scn
+/Gs2 gs
+72 72 m
+769.89 164.716 m
+/DeviceRGB cs
+0 0 0 scn
+/Gs2 gs
+q
+1 0 0 -1 0 595.28 cm
+BT
+1 0 0 1 363.6515 401.3955 Tm
+/F1 11 Tf
+[<626f72646572436f6c6f72> -30 <3a> 50 <205b2223666630303030225d> 0] TJ
+ET
+Q
+72 72 m
+769.89 217.432 m
+/DeviceRGB cs
+0 0 0 scn
+/Gs2 gs
+72 72 m
+769.89 257.432 m
+/DeviceRGB cs
+0 0 0 scn
+/Gs2 gs
+q
+1 0 0 -1 0 595.28 cm
+BT
+1 0 0 1 338.3405 308.6795 Tm
+/F1 11 Tf
+[<626f72646572436f6c6f72> -30 <3a> 50 <205b2223666630303030222c202223303066663030225d> 0] TJ
+ET
+Q
+72 72 m
+769.89 310.148 m
+/DeviceRGB cs
+0 0 0 scn
+/Gs2 gs
+72 72 m
+769.89 350.148 m
+/DeviceRGB cs
+0 0 0 scn
+/Gs2 gs
+q
+1 0 0 -1 0 595.28 cm
+BT
+1 0 0 1 290.7765 215.9635 Tm
+/F1 11 Tf
+[<626f72646572436f6c6f72> -30 <3a> 50 <205b2223666630303030222c202223303066663030222c202223303030306666222c202223666666663030225d> 0] TJ
+ET
+Q
+",
+]
+`;
+
exports[`table > should render and override background colors correctly 1`] = `
[
"1 0 0 -1 0 595.28 cm
@@ -1308,9 +1538,9 @@ Q
q
1 0 0 -1 0 595.28 cm
BT
-1 0 0 1 330.65075 445.4695 Tm
+1 0 0 1 324.53475 445.4695 Tm
/F1 11 Tf
-[<31> 0] TJ
+[<312c2031> 0] TJ
ET
Q
595.4175 122 m
diff --git a/src/pdf/table.test.ts b/src/pdf/table.test.ts
index 40036be..f08d856 100644
--- a/src/pdf/table.test.ts
+++ b/src/pdf/table.test.ts
@@ -14,13 +14,25 @@ import {
paddingOverrides,
paddingVariants,
singleCell,
- textColorOverrides
+ textColorOverrides,
+ tupleShorthand
} from "swissqrbill:tests:data/table";
import { TestDocument } from "swissqrbill:tests:utils/pdf";
describe("table", async () => {
+ it("should convert the values of tuples shorthand syntax correctly", async () => {
+ const pdf = new TestDocument("table/tuple-shorthand.pdf", { layout: "landscape", size: "A4" });
+ const table = new Table(tupleShorthand);
+
+ table.attachTo(pdf);
+
+ await pdf.writeFile();
+
+ expect(pdf.snapshots).toMatchSnapshot();
+ });
+
it("should render and override background colors correctly", async () => {
const pdf = new TestDocument("table/background-color.pdf", { layout: "landscape", size: "A4" });
const table = new Table(backgroundColorOverrides);
diff --git a/src/pdf/table.ts b/src/pdf/table.ts
index bf07b52..6be5dce 100644
--- a/src/pdf/table.ts
+++ b/src/pdf/table.ts
@@ -6,15 +6,15 @@ export interface PDFTable {
/** Background color of the table. */
backgroundColor?: string;
/** The colors of the border */
- borderColor?: string | [top: string, right?: string, bottom?: string, left?: string];
+ borderColor?: PDFBorderColor;
/** Width of the borders of the row. */
- borderWidth?: number | [top: number, right?: number, bottom?: number, left?: number];
+ borderWidth?: PDFBorderWidth;
/** Font of the text inside the table. */
fontName?: string;
/** Font size of the text inside the table. */
fontSize?: number;
/** Cell padding of the table cells. */
- padding?: number | [top: number, right?: number, bottom?: number, left?: number];
+ padding?: PDFPadding;
/** Text color of texts inside table. */
textColor?: string;
/** Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). */
@@ -26,6 +26,7 @@ export interface PDFTable {
/** Horizontal start position of the table. */
}
+
export interface PDFRow {
/** Table columns. */
columns: PDFColumn[];
@@ -34,9 +35,9 @@ export interface PDFRow {
/** Background color of the row. */
backgroundColor?: string;
/** The colors of the border */
- borderColor?: string | [top: string, right?: string, bottom?: string, left?: string];
+ borderColor?: PDFBorderColor;
/** Width of the borders of the row. */
- borderWidth?: number | [top: number, right?: number, bottom?: number, left?: number];
+ borderWidth?: PDFBorderWidth;
/** Font of the text inside the row. */
fontName?: string;
/** Font size of the text inside the row. */
@@ -50,7 +51,7 @@ export interface PDFRow {
/** Minimum height of the row */
minHeight?: number;
/** Cell padding of the table cells inside the row. */
- padding?: number | [top: number, right?: number, bottom?: number, left?: number];
+ padding?: PDFPadding;
/** Text color of texts inside the row. */
textColor?: string;
/** Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). */
@@ -67,15 +68,15 @@ export interface PDFColumn {
/** Background color of the cell. */
backgroundColor?: string;
/** The colors of the border */
- borderColor?: string | [top: string, right?: string, bottom?: string, left?: string];
+ borderColor?: PDFBorderColor;
/** Width of the borders of the row. */
- borderWidth?: number | [top: number, right?: number, bottom?: number, left?: number];
+ borderWidth?: PDFBorderWidth;
/** Font of the text inside the cell. */
fontName?: string;
/** Font size of the text inside the cell. */
fontSize?: number;
/** Cell padding of the table cell. */
- padding?: number | [top: number, right?: number, bottom?: number, left?: number];
+ padding?: PDFPadding;
/** Text color of texts inside the cell. */
textColor?: string;
/** Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). */
@@ -86,6 +87,21 @@ export interface PDFColumn {
width?: number;
}
+export type PDFBorderColor =
+ | string
+ | [top?: string, right?: string, bottom?: string, left?: string]
+ | [vertical?: string, horizontal?: string];
+
+export type PDFBorderWidth =
+ | number
+ | [top?: number, right?: number, bottom?: number, left?: number]
+ | [vertical?: number, horizontal?: number];
+
+export type PDFPadding =
+ | number
+ | [top?: number, right?: number, bottom?: number, left?: number]
+ | [vertical?: number, horizontal?: number];
+
enum TableLayer {
HeightCalculation,
PageInjection,
@@ -459,7 +475,7 @@ export class Table {
}
- private _positionsToObject(numberOrPositions: T | [top: T, right?: T, bottom?: T, left?: T]): { bottom?: T; left?: T; right?: T; top?: T; } {
+ private _positionsToObject(numberOrPositions: T | [top?: T, right?: T, bottom?: T, left?: T]): { bottom?: T; left?: T; right?: T; top?: T; } {
if(typeof numberOrPositions === "number" || typeof numberOrPositions === "string"){
return {
@@ -470,9 +486,9 @@ export class Table {
};
} else {
return {
- bottom: numberOrPositions[2] !== undefined ? numberOrPositions[2] : numberOrPositions[0] ?? numberOrPositions[0],
- left: numberOrPositions[3] !== undefined ? numberOrPositions[3] : numberOrPositions[1] ?? numberOrPositions[0],
- right: numberOrPositions[1] !== undefined ? numberOrPositions[1] : numberOrPositions[0] ?? numberOrPositions[0],
+ bottom: numberOrPositions[2] !== undefined ? numberOrPositions[2] : numberOrPositions[0],
+ left: numberOrPositions[3] !== undefined ? numberOrPositions[3] : numberOrPositions[1],
+ right: numberOrPositions[1] !== undefined ? numberOrPositions[1] : undefined,
top: numberOrPositions[0]
};
}
diff --git a/tests/data/table.ts b/tests/data/table.ts
index b443ccc..b5de0cd 100644
--- a/tests/data/table.ts
+++ b/tests/data/table.ts
@@ -1,6 +1,59 @@
import type { PDFTable } from "swissqrbill:pdf:table";
+export const tupleShorthand: PDFTable = {
+ align: "center",
+ padding: 20,
+ rows: [
+ {
+ columns: [
+ {
+ borderColor: "#ff0000",
+ borderWidth: 4,
+ text: "borderColor: \"#ff0000\""
+ }
+ ]
+ },
+ {
+ columns: [{ text: "" }]
+ },
+ {
+ columns: [
+ {
+ borderColor: ["#ff0000"],
+ borderWidth: 4,
+ text: "borderColor: [\"#ff0000\"]"
+ }
+ ]
+ },
+ {
+ columns: [{ text: "" }]
+ },
+ {
+ columns: [
+ {
+ borderColor: ["#ff0000", "#00ff00"],
+ borderWidth: 4,
+ text: "borderColor: [\"#ff0000\", \"#00ff00\"]"
+ }
+ ]
+ },
+ {
+ columns: [{ text: "" }]
+ },
+ {
+ columns: [
+ {
+ borderColor: ["#ff0000", "#00ff00", "#0000ff", "#ffff00"],
+ borderWidth: 4,
+ text: "borderColor: [\"#ff0000\", \"#00ff00\", \"#0000ff\", \"#ffff00\"]"
+ }
+ ]
+ }
+ ],
+ verticalAlign: "center"
+};
+
export const backgroundColorOverrides: PDFTable = {
align: "center",
backgroundColor: "#ff0000",
@@ -214,8 +267,8 @@ export const borderThickness: PDFTable = {
},
{
align: "center",
- borderWidth: [1],
- text: "1",
+ borderWidth: [1, 1],
+ text: "1, 1",
verticalAlign: "center"
},
{