@pdfme/schemas 6.0.3 → 6.0.5-dev.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.
Files changed (116) hide show
  1. package/dist/barcodes/constants.d.ts +4 -0
  2. package/dist/barcodes/helper.d.ts +21 -0
  3. package/dist/barcodes/index.d.ts +4 -0
  4. package/dist/barcodes/pdfRender.d.ts +3 -0
  5. package/dist/barcodes/propPanel.d.ts +3 -0
  6. package/{src/barcodes/types.ts → dist/barcodes/types.d.ts} +5 -7
  7. package/dist/barcodes/uiRender.d.ts +3 -0
  8. package/dist/builtins-CgaZ0UX3.js +613 -0
  9. package/dist/builtins-CgaZ0UX3.js.map +1 -0
  10. package/dist/builtins.d.ts +4 -0
  11. package/dist/builtins.js +2 -0
  12. package/dist/checkbox/index.d.ts +6 -0
  13. package/dist/constants.d.ts +2 -0
  14. package/dist/date/date.d.ts +2 -0
  15. package/dist/date/dateTime.d.ts +2 -0
  16. package/dist/date/helper.d.ts +20 -0
  17. package/dist/date/time.d.ts +2 -0
  18. package/dist/date/types.d.ts +17 -0
  19. package/dist/dynamicTemplate-D_DHR3-X.js +1128 -0
  20. package/dist/dynamicTemplate-D_DHR3-X.js.map +1 -0
  21. package/dist/graphics/image.d.ts +5 -0
  22. package/dist/graphics/imagehelper.d.ts +4 -0
  23. package/dist/graphics/signature.d.ts +4 -0
  24. package/dist/graphics/svg.d.ts +4 -0
  25. package/{src/index.ts → dist/index.d.ts} +1 -22
  26. package/dist/index.js +5383 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/multiVariableText/helper.d.ts +3 -0
  29. package/dist/multiVariableText/index.d.ts +4 -0
  30. package/dist/multiVariableText/pdfRender.d.ts +3 -0
  31. package/dist/multiVariableText/propPanel.d.ts +3 -0
  32. package/{src/multiVariableText/types.ts → dist/multiVariableText/types.d.ts} +2 -3
  33. package/dist/multiVariableText/uiRender.d.ts +3 -0
  34. package/dist/multiVariableText/variables.d.ts +10 -0
  35. package/dist/radioGroup/index.d.ts +7 -0
  36. package/dist/sanitize.d.ts +1 -0
  37. package/dist/select/index.d.ts +7 -0
  38. package/dist/shapes/line.d.ts +6 -0
  39. package/dist/shapes/rectAndEllipse.d.ts +11 -0
  40. package/dist/tables/cell.d.ts +4 -0
  41. package/dist/tables/classes.d.ts +69 -0
  42. package/dist/tables/dynamicTemplate.d.ts +7 -0
  43. package/dist/tables/helper.d.ts +265 -0
  44. package/dist/tables/index.d.ts +4 -0
  45. package/dist/tables/pdfRender.d.ts +3 -0
  46. package/dist/tables/propPanel.d.ts +3 -0
  47. package/dist/tables/tableHelper.d.ts +10 -0
  48. package/dist/tables/types.d.ts +88 -0
  49. package/dist/tables/uiRender.d.ts +3 -0
  50. package/dist/tables.js +2 -0
  51. package/dist/text/constants.d.ts +23 -0
  52. package/dist/text/extraFormatter.d.ts +25 -0
  53. package/dist/text/helper.d.ts +40 -0
  54. package/dist/text/icons/index.d.ts +9 -0
  55. package/dist/text/index.d.ts +4 -0
  56. package/dist/text/pdfRender.d.ts +3 -0
  57. package/dist/text/propPanel.d.ts +3 -0
  58. package/dist/text/types.d.ts +28 -0
  59. package/dist/text/uiRender.d.ts +11 -0
  60. package/dist/utils.d.ts +40 -0
  61. package/dist/utils.js +215 -0
  62. package/dist/utils.js.map +1 -0
  63. package/package.json +5 -1
  64. package/src/barcodes/constants.ts +0 -20
  65. package/src/barcodes/helper.ts +0 -187
  66. package/src/barcodes/index.ts +0 -23
  67. package/src/barcodes/pdfRender.ts +0 -37
  68. package/src/barcodes/propPanel.ts +0 -249
  69. package/src/barcodes/uiRender.ts +0 -94
  70. package/src/builtins.ts +0 -8
  71. package/src/checkbox/index.ts +0 -70
  72. package/src/constants.ts +0 -2
  73. package/src/date/date.ts +0 -9
  74. package/src/date/dateTime.ts +0 -9
  75. package/src/date/helper.ts +0 -544
  76. package/src/date/time.ts +0 -9
  77. package/src/date/types.ts +0 -19
  78. package/src/graphics/image.ts +0 -201
  79. package/src/graphics/imagehelper.ts +0 -156
  80. package/src/graphics/signature.ts +0 -136
  81. package/src/graphics/svg.ts +0 -121
  82. package/src/multiVariableText/helper.ts +0 -65
  83. package/src/multiVariableText/index.ts +0 -16
  84. package/src/multiVariableText/pdfRender.ts +0 -21
  85. package/src/multiVariableText/propPanel.ts +0 -169
  86. package/src/multiVariableText/uiRender.ts +0 -157
  87. package/src/multiVariableText/variables.ts +0 -63
  88. package/src/radioGroup/index.ts +0 -115
  89. package/src/sanitize.ts +0 -50
  90. package/src/select/index.ts +0 -205
  91. package/src/shapes/line.ts +0 -94
  92. package/src/shapes/rectAndEllipse.ts +0 -152
  93. package/src/tables/cell.ts +0 -152
  94. package/src/tables/classes.ts +0 -402
  95. package/src/tables/dynamicTemplate.ts +0 -88
  96. package/src/tables/helper.ts +0 -216
  97. package/src/tables/index.ts +0 -15
  98. package/src/tables/pdfRender.ts +0 -144
  99. package/src/tables/propPanel.ts +0 -111
  100. package/src/tables/tableHelper.ts +0 -289
  101. package/src/tables/types.ts +0 -87
  102. package/src/tables/uiRender.ts +0 -436
  103. package/src/text/constants.ts +0 -104
  104. package/src/text/extraFormatter.ts +0 -83
  105. package/src/text/helper.ts +0 -573
  106. package/src/text/icons/index.ts +0 -30
  107. package/src/text/index.ts +0 -16
  108. package/src/text/pdfRender.ts +0 -240
  109. package/src/text/propPanel.ts +0 -184
  110. package/src/text/types.ts +0 -30
  111. package/src/text/uiRender.ts +0 -292
  112. package/src/utils.ts +0 -354
  113. package/tsconfig.build.json +0 -14
  114. package/tsconfig.json +0 -16
  115. package/vite.config.mts +0 -51
  116. /package/{src/tables.ts → dist/tables.d.ts} +0 -0
@@ -1,15 +0,0 @@
1
- import type { Plugin } from '@pdfme/common';
2
- import type { TableSchema } from './types.js';
3
- import { pdfRender } from './pdfRender.js';
4
- import { uiRender } from './uiRender.js';
5
- import { propPanel } from './propPanel.js';
6
- import { Table } from 'lucide';
7
- import { createSvgStr } from '../utils.js';
8
-
9
- const tableSchema: Plugin<TableSchema> = {
10
- pdf: pdfRender,
11
- ui: uiRender,
12
- propPanel,
13
- icon: createSvgStr(Table),
14
- };
15
- export default tableSchema;
@@ -1,144 +0,0 @@
1
- import type { TableSchema } from './types.js';
2
- import type { PDFRenderProps, Schema, BasePdf, CommonOptions } from '@pdfme/common';
3
- import { Cell, Table, Row, Column } from './classes.js';
4
- import { rectangle } from '../shapes/rectAndEllipse.js';
5
- import cell from './cell.js';
6
- import { getBodyWithRange } from './helper.js';
7
- import { createSingleTable } from './tableHelper.js';
8
-
9
- // Define the CreateTableArgs interface locally since it's not exported from tableHelper.js
10
- interface CreateTableArgs {
11
- schema: Schema;
12
- basePdf: BasePdf;
13
- options: CommonOptions;
14
- _cache: Map<string | number, unknown>;
15
- }
16
-
17
- type Pos = { x: number; y: number };
18
-
19
- const rectanglePdfRender = rectangle.pdf;
20
- const cellPdfRender = cell.pdf;
21
-
22
- async function drawCell(arg: PDFRenderProps<TableSchema>, cell: Cell) {
23
- await cellPdfRender({
24
- ...arg,
25
- value: cell.raw,
26
- schema: {
27
- name: '',
28
- type: 'cell',
29
- position: { x: cell.x, y: cell.y },
30
- width: cell.width,
31
- height: cell.height,
32
- fontName: cell.styles.fontName,
33
- alignment: cell.styles.alignment,
34
- verticalAlignment: cell.styles.verticalAlignment,
35
- fontSize: cell.styles.fontSize,
36
- lineHeight: cell.styles.lineHeight,
37
- characterSpacing: cell.styles.characterSpacing,
38
- backgroundColor: cell.styles.backgroundColor,
39
- fontColor: cell.styles.textColor,
40
- borderColor: cell.styles.lineColor,
41
- borderWidth: cell.styles.lineWidth,
42
- padding: cell.styles.cellPadding,
43
- },
44
- });
45
- }
46
-
47
- async function drawRow(
48
- arg: PDFRenderProps<TableSchema>,
49
- table: Table,
50
- row: Row,
51
- cursor: Pos,
52
- columns: Column[],
53
- ) {
54
- cursor.x = table.settings.margin.left;
55
- for (const column of columns) {
56
- const cell = row.cells[column.index];
57
- if (!cell) {
58
- cursor.x += column.width;
59
- continue;
60
- }
61
-
62
- cell.x = cursor.x;
63
- cell.y = cursor.y;
64
-
65
- await drawCell(arg, cell);
66
-
67
- cursor.x += column.width;
68
- }
69
- cursor.y += row.height;
70
- }
71
-
72
- async function drawTableBorder(
73
- arg: PDFRenderProps<TableSchema>,
74
- table: Table,
75
- startPos: Pos,
76
- cursor: Pos,
77
- ) {
78
- const lineWidth = table.settings.tableLineWidth;
79
- const lineColor = table.settings.tableLineColor;
80
- if (!lineWidth || !lineColor) return;
81
- await rectanglePdfRender({
82
- ...arg,
83
- schema: {
84
- name: '',
85
- type: 'rectangle',
86
- borderWidth: lineWidth,
87
- borderColor: lineColor,
88
- color: '',
89
- position: { x: startPos.x, y: startPos.y },
90
- width: table.getWidth(),
91
- height: cursor.y - startPos.y,
92
- readOnly: true,
93
- },
94
- });
95
- }
96
-
97
- async function drawTable(arg: PDFRenderProps<TableSchema>, table: Table): Promise<void> {
98
- const settings = table.settings;
99
- const startY = settings.startY;
100
- const margin = settings.margin;
101
- const cursor = { x: margin.left, y: startY };
102
-
103
- const startPos = Object.assign({}, cursor);
104
-
105
- if (settings.showHead) {
106
- for (const row of table.head) {
107
- await drawRow(arg, table, row, cursor, table.columns);
108
- }
109
- }
110
-
111
- for (const row of table.body) {
112
- await drawRow(arg, table, row, cursor, table.columns);
113
- }
114
-
115
- await drawTableBorder(arg, table, startPos, cursor);
116
- }
117
-
118
- export const pdfRender = async (arg: PDFRenderProps<TableSchema>) => {
119
- const { value, schema, basePdf, options, _cache } = arg;
120
-
121
- const body = getBodyWithRange(
122
- typeof value !== 'string' ? JSON.stringify(value || '[]') : value,
123
- schema.__bodyRange,
124
- );
125
-
126
- // Create a properly typed CreateTableArgs object
127
- const createTableArgs: CreateTableArgs = {
128
- schema,
129
- basePdf,
130
- options,
131
- _cache,
132
- };
133
-
134
- // Ensure body is properly typed before passing to createSingleTable
135
- // Ensure body is properly typed as string[][] before passing to createSingleTable
136
- const typedBody: string[][] = Array.isArray(body)
137
- ? body.map((row) => (Array.isArray(row) ? row.map((cell) => String(cell)) : []))
138
- : [];
139
- const table = await createSingleTable(typedBody, createTableArgs);
140
-
141
- // Use the original arg directly since drawTable expects PDFRenderProps<TableSchema>
142
- // which is the same type as our arg parameter
143
- await drawTable(arg, table);
144
- };
@@ -1,111 +0,0 @@
1
- import type { PropPanel } from '@pdfme/common';
2
- import type { TableSchema } from './types.js';
3
- import { getFallbackFontName, DEFAULT_FONT_NAME } from '@pdfme/common';
4
- import {
5
- getDefaultCellStyles,
6
- getCellPropPanelSchema,
7
- getColumnStylesPropPanelSchema,
8
- } from './helper.js';
9
- import { HEX_COLOR_PATTERN } from '../constants.js';
10
-
11
- export const propPanel: PropPanel<TableSchema> = {
12
- schema: ({ activeSchema, options, i18n }) => {
13
- // @ts-expect-error Type casting is necessary here as the activeSchema type is generic
14
- const tableSchema = activeSchema as TableSchema;
15
- const head = tableSchema.head || [];
16
- const showHead = tableSchema.showHead || false;
17
- const font = options.font || { [DEFAULT_FONT_NAME]: { data: '', fallback: true } };
18
- const fontNames = Object.keys(font);
19
- const fallbackFontName = getFallbackFontName(font);
20
- return {
21
- showHead: {
22
- title: i18n('schemas.table.showHead'),
23
- type: 'boolean',
24
- widget: 'checkbox',
25
- span: 12,
26
- },
27
- repeatHead: {
28
- title: i18n('schemas.table.repeatHead'),
29
- type: 'boolean',
30
- widget: 'checkbox',
31
- span: 12,
32
- },
33
- '-------': { type: 'void', widget: 'Divider' },
34
- tableStyles: {
35
- title: i18n('schemas.table.tableStyle'),
36
- type: 'object',
37
- widget: 'Card',
38
- span: 24,
39
- properties: {
40
- borderWidth: {
41
- title: i18n('schemas.borderWidth'),
42
- type: 'number',
43
- widget: 'inputNumber',
44
- props: { min: 0, step: 0.1 },
45
- step: 1,
46
- },
47
- borderColor: {
48
- title: i18n('schemas.borderColor'),
49
- type: 'string',
50
- widget: 'color',
51
- props: {
52
- disabledAlpha: true,
53
- },
54
- rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
55
- },
56
- },
57
- },
58
- headStyles: {
59
- hidden: !showHead,
60
- title: i18n('schemas.table.headStyle'),
61
- type: 'object',
62
- widget: 'Card',
63
- span: 24,
64
- properties: getCellPropPanelSchema({ i18n, fallbackFontName, fontNames }),
65
- },
66
- bodyStyles: {
67
- title: i18n('schemas.table.bodyStyle'),
68
- type: 'object',
69
- widget: 'Card',
70
- span: 24,
71
- properties: getCellPropPanelSchema({ i18n, fallbackFontName, fontNames, isBody: true }),
72
- },
73
- columnStyles: {
74
- title: i18n('schemas.table.columnStyle'),
75
- type: 'object',
76
- widget: 'Card',
77
- span: 24,
78
- properties: getColumnStylesPropPanelSchema({ head, i18n }),
79
- },
80
- };
81
- },
82
- defaultSchema: {
83
- name: '',
84
- type: 'table',
85
- position: { x: 0, y: 0 },
86
- width: 150,
87
- height: 20,
88
- content: JSON.stringify([
89
- ['Alice', 'New York', 'Alice is a freelance web designer and developer'],
90
- ['Bob', 'Paris', 'Bob is a freelance illustrator and graphic designer'],
91
- ]),
92
- showHead: true,
93
- repeatHead: false,
94
- head: ['Name', 'City', 'Description'],
95
- headWidthPercentages: [30, 30, 40],
96
- tableStyles: {
97
- borderColor: '#000000',
98
- borderWidth: 0.3,
99
- },
100
- headStyles: Object.assign(getDefaultCellStyles(), {
101
- fontColor: '#ffffff',
102
- backgroundColor: '#2980ba',
103
- borderColor: '',
104
- borderWidth: { top: 0, right: 0, bottom: 0, left: 0 },
105
- }),
106
- bodyStyles: Object.assign(getDefaultCellStyles(), {
107
- alternateBackgroundColor: '#f5f5f5',
108
- }),
109
- columnStyles: {},
110
- },
111
- };
@@ -1,289 +0,0 @@
1
- import {
2
- Schema,
3
- isBlankPdf,
4
- BasePdf,
5
- CommonOptions,
6
- getDefaultFont,
7
- getFallbackFontName,
8
- cloneDeep,
9
- } from '@pdfme/common';
10
- import type { Font as FontKitFont } from 'fontkit';
11
- import type {
12
- TableSchema,
13
- CellStyle,
14
- Styles,
15
- Spacing,
16
- TableInput,
17
- StylesProps,
18
- Section,
19
- } from './types.js';
20
- import { Cell, Column, Row, Table } from './classes.js';
21
-
22
- type StyleProp = 'styles' | 'headStyles' | 'bodyStyles' | 'alternateRowStyles' | 'columnStyles';
23
-
24
- interface CreateTableArgs {
25
- schema: Schema;
26
- basePdf: BasePdf;
27
- options: CommonOptions;
28
- _cache: Map<string | number, unknown>;
29
- }
30
-
31
- interface UserOptions {
32
- startY: number;
33
- tableWidth: number;
34
- margin: Spacing;
35
- showHead: boolean;
36
- tableLineWidth?: number;
37
- tableLineColor?: string;
38
- head?: string[][];
39
- body?: string[][];
40
-
41
- styles?: Partial<Styles>;
42
- bodyStyles?: Partial<Styles>;
43
- headStyles?: Partial<Styles>;
44
- alternateRowStyles?: Partial<Styles>;
45
- columnStyles?: {
46
- [key: string]: Partial<Styles>;
47
- };
48
- }
49
-
50
- function parseSection(
51
- sectionName: Section,
52
- sectionRows: string[][],
53
- columns: Column[],
54
- styleProps: StylesProps,
55
- fallbackFontName: string,
56
- ): Row[] {
57
- const rowSpansLeftForColumn: { [key: string]: { left: number; times: number } } = {};
58
- const result = sectionRows.map((rawRow, rowIndex) => {
59
- let skippedRowForRowSpans = 0;
60
- const cells: { [key: string]: Cell } = {};
61
-
62
- let colSpansAdded = 0;
63
- let columnSpansLeft = 0;
64
- for (const column of columns) {
65
- if (
66
- rowSpansLeftForColumn[column.index] == null ||
67
- rowSpansLeftForColumn[column.index].left === 0
68
- ) {
69
- if (columnSpansLeft === 0) {
70
- let rawCell;
71
- if (Array.isArray(rawRow)) {
72
- rawCell = rawRow[column.index - colSpansAdded - skippedRowForRowSpans];
73
- } else {
74
- rawCell = rawRow[column.index];
75
- }
76
- const styles = cellStyles(sectionName, column, rowIndex, styleProps, fallbackFontName);
77
- const cell = new Cell(rawCell, styles, sectionName);
78
- cells[column.index] = cell;
79
-
80
- columnSpansLeft = 0;
81
- rowSpansLeftForColumn[column.index] = {
82
- left: 0,
83
- times: columnSpansLeft,
84
- };
85
- } else {
86
- columnSpansLeft--;
87
- colSpansAdded++;
88
- }
89
- } else {
90
- rowSpansLeftForColumn[column.index].left--;
91
- columnSpansLeft = rowSpansLeftForColumn[column.index].times;
92
- skippedRowForRowSpans++;
93
- }
94
- }
95
- return new Row(rawRow, rowIndex, sectionName, cells);
96
- });
97
- return result;
98
- }
99
-
100
- function parseContent4Table(input: TableInput, fallbackFontName: string) {
101
- const content = input.content;
102
- const columns = content.columns.map((index) => new Column(index));
103
- const styles = input.styles;
104
- return {
105
- columns,
106
- head: parseSection('head', content.head, columns, styles, fallbackFontName),
107
- body: parseSection('body', content.body, columns, styles, fallbackFontName),
108
- };
109
- }
110
-
111
- function cellStyles(
112
- sectionName: Section,
113
- column: Column,
114
- rowIndex: number,
115
- styles: StylesProps,
116
- fallbackFontName: string,
117
- ) {
118
- let sectionStyles;
119
- if (sectionName === 'head') {
120
- sectionStyles = styles.headStyles;
121
- } else if (sectionName === 'body') {
122
- sectionStyles = styles.bodyStyles;
123
- }
124
- const otherStyles = Object.assign({}, styles.styles, sectionStyles);
125
-
126
- const colStyles = styles.columnStyles[column.index] || {};
127
-
128
- const rowStyles =
129
- sectionName === 'body' && rowIndex % 2 === 0
130
- ? Object.assign({}, styles.alternateRowStyles)
131
- : {};
132
-
133
- const defaultStyle = {
134
- fontName: fallbackFontName,
135
- backgroundColor: '',
136
- textColor: '#000000',
137
- lineHeight: 1,
138
- characterSpacing: 0,
139
- alignment: 'left',
140
- verticalAlignment: 'middle',
141
- fontSize: 10,
142
- cellPadding: 5,
143
- lineColor: '#000000',
144
- lineWidth: 0,
145
- minCellHeight: 0,
146
- minCellWidth: 0,
147
- };
148
- return Object.assign(defaultStyle, otherStyles, rowStyles, colStyles) as Styles;
149
- }
150
-
151
- function mapCellStyle(style: CellStyle): Partial<Styles> {
152
- return {
153
- fontName: style.fontName,
154
- alignment: style.alignment,
155
- verticalAlignment: style.verticalAlignment,
156
- fontSize: style.fontSize,
157
- lineHeight: style.lineHeight,
158
- characterSpacing: style.characterSpacing,
159
- backgroundColor: style.backgroundColor,
160
- // ---
161
- textColor: style.fontColor,
162
- lineColor: style.borderColor,
163
- lineWidth: style.borderWidth,
164
- cellPadding: style.padding,
165
- };
166
- }
167
-
168
- function getTableOptions(schema: TableSchema, body: string[][]): UserOptions {
169
- const columnStylesWidth = schema.headWidthPercentages.reduce(
170
- (acc, cur, i) => ({ ...acc, [i]: { cellWidth: schema.width * (cur / 100) } }),
171
- {} as Record<number, Partial<Styles>>,
172
- );
173
-
174
- const columnStylesAlignment = Object.entries(schema.columnStyles.alignment || {}).reduce(
175
- (acc, [key, value]) => ({ ...acc, [key]: { alignment: value } }),
176
- {} as Record<number, Partial<Styles>>,
177
- );
178
-
179
- const allKeys = new Set([
180
- ...Object.keys(columnStylesWidth).map(Number),
181
- ...Object.keys(columnStylesAlignment).map(Number),
182
- ]);
183
- const columnStyles = Array.from(allKeys).reduce(
184
- (acc, key) => {
185
- const widthStyle = columnStylesWidth[key] || {};
186
- const alignmentStyle = columnStylesAlignment[key] || {};
187
- return { ...acc, [key]: { ...widthStyle, ...alignmentStyle } };
188
- },
189
- {} as Record<number, Partial<Styles>>,
190
- );
191
-
192
- return {
193
- head: [schema.head],
194
- body,
195
- showHead: schema.showHead,
196
- startY: schema.position.y,
197
- tableWidth: schema.width,
198
- tableLineColor: schema.tableStyles.borderColor,
199
- tableLineWidth: schema.tableStyles.borderWidth,
200
- headStyles: mapCellStyle(schema.headStyles),
201
- bodyStyles: mapCellStyle(schema.bodyStyles),
202
- alternateRowStyles: { backgroundColor: schema.bodyStyles.alternateBackgroundColor },
203
- columnStyles,
204
- margin: { top: 0, right: 0, left: schema.position.x, bottom: 0 },
205
- };
206
- }
207
-
208
- function parseStyles(cInput: UserOptions) {
209
- const styleOptions: StylesProps = {
210
- styles: {},
211
- headStyles: {},
212
- bodyStyles: {},
213
- alternateRowStyles: {},
214
- columnStyles: {},
215
- };
216
- for (const prop of Object.keys(styleOptions) as StyleProp[]) {
217
- if (prop === 'columnStyles') {
218
- const current = cInput[prop];
219
- styleOptions.columnStyles = Object.assign({}, current);
220
- } else {
221
- const allOptions = [cInput];
222
- const styles = allOptions.map((opts) => opts[prop] || {});
223
- styleOptions[prop] = Object.assign({}, styles[0], styles[1], styles[2]);
224
- }
225
- }
226
- return styleOptions;
227
- }
228
-
229
- function parseContent4Input(options: UserOptions) {
230
- const head = options.head || [];
231
- const body = options.body || [];
232
- const columns = (head[0] || body[0] || []).map((_, index) => index);
233
- return { columns, head, body };
234
- }
235
-
236
- function parseInput(schema: TableSchema, body: string[][]): TableInput {
237
- const options = getTableOptions(schema, body);
238
- const styles = parseStyles(options);
239
- const settings = {
240
- startY: options.startY,
241
- margin: options.margin,
242
- tableWidth: options.tableWidth,
243
- showHead: options.showHead,
244
- tableLineWidth: options.tableLineWidth ?? 0,
245
- tableLineColor: options.tableLineColor ?? '',
246
- };
247
-
248
- const content = parseContent4Input(options);
249
-
250
- return { content, styles, settings };
251
- }
252
-
253
- export function createSingleTable(body: string[][], args: CreateTableArgs) {
254
- const { options, _cache, basePdf } = args;
255
- if (!isBlankPdf(basePdf)) {
256
- console.warn(
257
- '[@pdfme/schema/table]' +
258
- 'When specifying a custom PDF for basePdf, ' +
259
- 'you cannot use features such as page breaks or re-layout of other elements.' +
260
- 'To utilize these features, please define basePdf as follows:\n' +
261
- '{ width: number; height: number; padding: [number, number, number, number]; }',
262
- );
263
- }
264
-
265
- const schema = cloneDeep(args.schema) as TableSchema;
266
- const { start } = schema.__bodyRange || { start: 0 };
267
- if (start % 2 === 1) {
268
- const alternateBackgroundColor = schema.bodyStyles.alternateBackgroundColor;
269
- schema.bodyStyles.alternateBackgroundColor = schema.bodyStyles.backgroundColor;
270
- schema.bodyStyles.backgroundColor = alternateBackgroundColor;
271
- }
272
- schema.showHead =
273
- schema.showHead === false ? false : !schema.__isSplit || schema.repeatHead === true;
274
-
275
- const input = parseInput(schema, body);
276
-
277
- const font = options.font || getDefaultFont();
278
-
279
- const fallbackFontName = getFallbackFontName(font);
280
-
281
- const content = parseContent4Table(input, fallbackFontName);
282
-
283
- return Table.create({
284
- input,
285
- content,
286
- font,
287
- _cache: _cache as unknown as Map<string | number, FontKitFont>,
288
- });
289
- }
@@ -1,87 +0,0 @@
1
- import type { ALIGNMENT, VERTICAL_ALIGNMENT } from '../text/types.js';
2
- import type { Schema } from '@pdfme/common';
3
-
4
- export type Spacing = { top: number; right: number; bottom: number; left: number };
5
- type BorderInsets = Spacing;
6
- type BoxDimensions = Spacing;
7
-
8
- export interface CellStyle {
9
- fontName?: string;
10
- alignment: ALIGNMENT;
11
- verticalAlignment: VERTICAL_ALIGNMENT;
12
- fontSize: number;
13
- lineHeight: number;
14
- characterSpacing: number;
15
- fontColor: string;
16
- backgroundColor: string;
17
- borderColor: string;
18
- borderWidth: BoxDimensions;
19
- padding: BoxDimensions;
20
- }
21
-
22
- export type CellSchema = Schema & CellStyle;
23
-
24
- export type TableSchema = Schema & {
25
- showHead: boolean;
26
- head: string[];
27
- headWidthPercentages: number[];
28
- repeatHead?: boolean;
29
-
30
- tableStyles: {
31
- borderColor: string;
32
- borderWidth: number;
33
- };
34
- headStyles: CellStyle;
35
- bodyStyles: CellStyle & { alternateBackgroundColor: string };
36
- columnStyles: {
37
- alignment?: { [colIndex: number]: ALIGNMENT };
38
- };
39
- };
40
-
41
- export interface Styles {
42
- fontName: string | undefined;
43
- backgroundColor: string;
44
- textColor: string;
45
- lineHeight: number;
46
- characterSpacing: number;
47
- alignment: 'left' | 'center' | 'right' | 'justify';
48
- verticalAlignment: 'top' | 'middle' | 'bottom';
49
- fontSize: number;
50
- cellPadding: Spacing;
51
- lineColor: string;
52
- lineWidth: BorderInsets;
53
- cellWidth: number;
54
- minCellHeight: number;
55
- minCellWidth: number;
56
- }
57
-
58
- export interface TableInput {
59
- settings: Settings;
60
- styles: StylesProps;
61
- content: ContentInput;
62
- }
63
-
64
- interface ContentInput {
65
- body: string[][];
66
- head: string[][];
67
- columns: number[];
68
- }
69
-
70
- export interface Settings {
71
- startY: number;
72
- margin: Spacing;
73
- tableWidth: number;
74
- showHead: boolean;
75
- tableLineWidth: number;
76
- tableLineColor: string;
77
- }
78
-
79
- export interface StylesProps {
80
- styles: Partial<Styles>;
81
- headStyles: Partial<Styles>;
82
- bodyStyles: Partial<Styles>;
83
- alternateRowStyles: Partial<Styles>;
84
- columnStyles: { [key: string]: Partial<Styles> };
85
- }
86
-
87
- export type Section = 'head' | 'body';