@pdfme/schemas 3.2.3-dev.1 → 4.0.0-alpha.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.
Files changed (138) hide show
  1. package/dist/cjs/__tests__/text.test.js +5 -4
  2. package/dist/cjs/__tests__/text.test.js.map +1 -1
  3. package/dist/cjs/__tests__/utils.test.js +3 -0
  4. package/dist/cjs/__tests__/utils.test.js.map +1 -1
  5. package/dist/cjs/src/barcodes/propPanel.js +11 -11
  6. package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
  7. package/dist/cjs/src/barcodes/uiRender.js +1 -1
  8. package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
  9. package/dist/cjs/src/graphics/image.js +5 -11
  10. package/dist/cjs/src/graphics/image.js.map +1 -1
  11. package/dist/cjs/src/graphics/svg.js +2 -3
  12. package/dist/cjs/src/graphics/svg.js.map +1 -1
  13. package/dist/cjs/src/index.js +6 -1
  14. package/dist/cjs/src/index.js.map +1 -1
  15. package/dist/cjs/src/shapes/line.js +5 -9
  16. package/dist/cjs/src/shapes/line.js.map +1 -1
  17. package/dist/cjs/src/shapes/rectAndEllipse.js +3 -2
  18. package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -1
  19. package/dist/cjs/src/tables/cell.js +125 -0
  20. package/dist/cjs/src/tables/cell.js.map +1 -0
  21. package/dist/cjs/src/tables/classes.js +467 -0
  22. package/dist/cjs/src/tables/classes.js.map +1 -0
  23. package/dist/cjs/src/tables/dynamicTemplate.js +71 -0
  24. package/dist/cjs/src/tables/dynamicTemplate.js.map +1 -0
  25. package/dist/cjs/src/tables/helper.js +171 -0
  26. package/dist/cjs/src/tables/helper.js.map +1 -0
  27. package/dist/cjs/src/tables/index.js +12 -0
  28. package/dist/cjs/src/tables/index.js.map +1 -0
  29. package/dist/cjs/src/tables/pdfRender.js +95 -0
  30. package/dist/cjs/src/tables/pdfRender.js.map +1 -0
  31. package/dist/cjs/src/tables/propPanel.js +87 -0
  32. package/dist/cjs/src/tables/propPanel.js.map +1 -0
  33. package/dist/cjs/src/tables/tableHelper.js +231 -0
  34. package/dist/cjs/src/tables/tableHelper.js.map +1 -0
  35. package/dist/cjs/src/tables/types.js +3 -0
  36. package/dist/cjs/src/tables/types.js.map +1 -0
  37. package/dist/cjs/src/tables/uiRender.js +321 -0
  38. package/dist/cjs/src/tables/uiRender.js.map +1 -0
  39. package/dist/cjs/src/text/helper.js +21 -6
  40. package/dist/cjs/src/text/helper.js.map +1 -1
  41. package/dist/cjs/src/text/index.js +0 -1
  42. package/dist/cjs/src/text/index.js.map +1 -1
  43. package/dist/cjs/src/text/pdfRender.js +5 -8
  44. package/dist/cjs/src/text/pdfRender.js.map +1 -1
  45. package/dist/cjs/src/text/propPanel.js +6 -4
  46. package/dist/cjs/src/text/propPanel.js.map +1 -1
  47. package/dist/cjs/src/text/uiRender.js +18 -17
  48. package/dist/cjs/src/text/uiRender.js.map +1 -1
  49. package/dist/cjs/src/utils.js +9 -1
  50. package/dist/cjs/src/utils.js.map +1 -1
  51. package/dist/esm/__tests__/text.test.js +5 -4
  52. package/dist/esm/__tests__/text.test.js.map +1 -1
  53. package/dist/esm/__tests__/utils.test.js +3 -0
  54. package/dist/esm/__tests__/utils.test.js.map +1 -1
  55. package/dist/esm/src/barcodes/propPanel.js +11 -11
  56. package/dist/esm/src/barcodes/propPanel.js.map +1 -1
  57. package/dist/esm/src/barcodes/uiRender.js +1 -1
  58. package/dist/esm/src/barcodes/uiRender.js.map +1 -1
  59. package/dist/esm/src/graphics/image.js +4 -10
  60. package/dist/esm/src/graphics/image.js.map +1 -1
  61. package/dist/esm/src/graphics/svg.js +2 -3
  62. package/dist/esm/src/graphics/svg.js.map +1 -1
  63. package/dist/esm/src/index.js +3 -1
  64. package/dist/esm/src/index.js.map +1 -1
  65. package/dist/esm/src/shapes/line.js +5 -9
  66. package/dist/esm/src/shapes/line.js.map +1 -1
  67. package/dist/esm/src/shapes/rectAndEllipse.js +3 -2
  68. package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -1
  69. package/dist/esm/src/tables/cell.js +120 -0
  70. package/dist/esm/src/tables/cell.js.map +1 -0
  71. package/dist/esm/src/tables/classes.js +460 -0
  72. package/dist/esm/src/tables/classes.js.map +1 -0
  73. package/dist/esm/src/tables/dynamicTemplate.js +66 -0
  74. package/dist/esm/src/tables/dynamicTemplate.js.map +1 -0
  75. package/dist/esm/src/tables/helper.js +163 -0
  76. package/dist/esm/src/tables/helper.js.map +1 -0
  77. package/dist/esm/src/tables/index.js +10 -0
  78. package/dist/esm/src/tables/index.js.map +1 -0
  79. package/dist/esm/src/tables/pdfRender.js +88 -0
  80. package/dist/esm/src/tables/pdfRender.js.map +1 -0
  81. package/dist/esm/src/tables/propPanel.js +84 -0
  82. package/dist/esm/src/tables/propPanel.js.map +1 -0
  83. package/dist/esm/src/tables/tableHelper.js +226 -0
  84. package/dist/esm/src/tables/tableHelper.js.map +1 -0
  85. package/dist/esm/src/tables/types.js +2 -0
  86. package/dist/esm/src/tables/types.js.map +1 -0
  87. package/dist/esm/src/tables/uiRender.js +314 -0
  88. package/dist/esm/src/tables/uiRender.js.map +1 -0
  89. package/dist/esm/src/text/helper.js +19 -5
  90. package/dist/esm/src/text/helper.js.map +1 -1
  91. package/dist/esm/src/text/index.js +0 -1
  92. package/dist/esm/src/text/index.js.map +1 -1
  93. package/dist/esm/src/text/pdfRender.js +6 -9
  94. package/dist/esm/src/text/pdfRender.js.map +1 -1
  95. package/dist/esm/src/text/propPanel.js +6 -4
  96. package/dist/esm/src/text/propPanel.js.map +1 -1
  97. package/dist/esm/src/text/uiRender.js +19 -18
  98. package/dist/esm/src/text/uiRender.js.map +1 -1
  99. package/dist/esm/src/utils.js +6 -0
  100. package/dist/esm/src/utils.js.map +1 -1
  101. package/dist/types/src/index.d.ts +3 -1
  102. package/dist/types/src/shapes/rectAndEllipse.d.ts +13 -27
  103. package/dist/types/src/tables/cell.d.ts +4 -0
  104. package/dist/types/src/tables/classes.d.ts +68 -0
  105. package/dist/types/src/tables/dynamicTemplate.d.ts +13 -0
  106. package/dist/types/src/tables/helper.d.ts +252 -0
  107. package/dist/types/src/tables/index.d.ts +4 -0
  108. package/dist/types/src/tables/pdfRender.d.ts +3 -0
  109. package/dist/types/src/tables/propPanel.d.ts +3 -0
  110. package/dist/types/src/tables/tableHelper.d.ts +11 -0
  111. package/dist/types/src/tables/types.d.ts +91 -0
  112. package/dist/types/src/tables/uiRender.d.ts +3 -0
  113. package/dist/types/src/text/helper.d.ts +8 -1
  114. package/dist/types/src/utils.d.ts +2 -0
  115. package/package.json +1 -1
  116. package/src/barcodes/propPanel.ts +12 -12
  117. package/src/barcodes/uiRender.ts +1 -1
  118. package/src/graphics/image.ts +6 -11
  119. package/src/graphics/svg.ts +2 -3
  120. package/src/index.ts +5 -0
  121. package/src/shapes/line.ts +4 -9
  122. package/src/shapes/rectAndEllipse.ts +4 -4
  123. package/src/tables/cell.ts +157 -0
  124. package/src/tables/classes.ts +398 -0
  125. package/src/tables/dynamicTemplate.ts +81 -0
  126. package/src/tables/helper.ts +198 -0
  127. package/src/tables/index.ts +12 -0
  128. package/src/tables/pdfRender.ts +115 -0
  129. package/src/tables/propPanel.ts +90 -0
  130. package/src/tables/tableHelper.ts +322 -0
  131. package/src/tables/types.ts +88 -0
  132. package/src/tables/uiRender.ts +362 -0
  133. package/src/text/helper.ts +30 -6
  134. package/src/text/index.ts +0 -1
  135. package/src/text/pdfRender.ts +7 -11
  136. package/src/text/propPanel.ts +6 -4
  137. package/src/text/uiRender.ts +18 -18
  138. package/src/utils.ts +8 -0
@@ -0,0 +1,91 @@
1
+ import type { ALIGNMENT, VERTICAL_ALIGNMENT } from '../text/types';
2
+ import type { Schema } from '@pdfme/common';
3
+ export type Spacing = {
4
+ top: number;
5
+ right: number;
6
+ bottom: number;
7
+ left: number;
8
+ };
9
+ type BorderInsets = Spacing;
10
+ type BoxDimensions = Spacing;
11
+ export interface CellStyle {
12
+ fontName?: string;
13
+ alignment: ALIGNMENT;
14
+ verticalAlignment: VERTICAL_ALIGNMENT;
15
+ fontSize: number;
16
+ lineHeight: number;
17
+ characterSpacing: number;
18
+ fontColor: string;
19
+ backgroundColor: string;
20
+ borderColor: string;
21
+ borderWidth: BoxDimensions;
22
+ padding: BoxDimensions;
23
+ }
24
+ export type CellSchema = Schema & CellStyle;
25
+ export interface TableSchema extends Schema {
26
+ showHead: boolean;
27
+ head: string[];
28
+ headWidthPercentages: number[];
29
+ __bodyRange?: {
30
+ start: number;
31
+ end?: number;
32
+ };
33
+ tableStyles: {
34
+ borderColor: string;
35
+ borderWidth: number;
36
+ };
37
+ headStyles: CellStyle;
38
+ bodyStyles: CellStyle & {
39
+ alternateBackgroundColor: string;
40
+ };
41
+ columnStyles: {
42
+ alignment?: {
43
+ [colIndex: number]: ALIGNMENT;
44
+ };
45
+ };
46
+ }
47
+ export interface Styles {
48
+ fontName: string | undefined;
49
+ backgroundColor: string;
50
+ textColor: string;
51
+ lineHeight: number;
52
+ characterSpacing: number;
53
+ alignment: 'left' | 'center' | 'right';
54
+ verticalAlignment: 'top' | 'middle' | 'bottom';
55
+ fontSize: number;
56
+ cellPadding: Spacing;
57
+ lineColor: string;
58
+ lineWidth: BorderInsets;
59
+ cellWidth: number;
60
+ minCellHeight: number;
61
+ minCellWidth: number;
62
+ }
63
+ export interface TableInput {
64
+ settings: Settings;
65
+ styles: StylesProps;
66
+ content: ContentInput;
67
+ }
68
+ interface ContentInput {
69
+ body: string[][];
70
+ head: string[][];
71
+ columns: number[];
72
+ }
73
+ export interface Settings {
74
+ startY: number;
75
+ margin: Spacing;
76
+ tableWidth: number;
77
+ showHead: boolean;
78
+ tableLineWidth: number;
79
+ tableLineColor: string;
80
+ }
81
+ export interface StylesProps {
82
+ styles: Partial<Styles>;
83
+ headStyles: Partial<Styles>;
84
+ bodyStyles: Partial<Styles>;
85
+ alternateRowStyles: Partial<Styles>;
86
+ columnStyles: {
87
+ [key: string]: Partial<Styles>;
88
+ };
89
+ }
90
+ export type Section = 'head' | 'body';
91
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { UIRenderProps } from '@pdfme/common';
2
+ import type { TableSchema } from './types.js';
3
+ export declare const uiRender: (arg: UIRenderProps<TableSchema>) => Promise<void>;
@@ -9,7 +9,7 @@ export declare const getBrowserVerticalFontAdjustments: (fontKitFont: FontKitFon
9
9
  export declare const getFontDescentInPt: (fontKitFont: FontKitFont, fontSize: number) => number;
10
10
  export declare const heightOfFontAtSize: (fontKitFont: FontKitFont, fontSize: number) => number;
11
11
  export declare const widthOfTextAtSize: (text: string, fontKitFont: FontKitFont, fontSize: number, characterSpacing: number) => number;
12
- export declare const getFontKitFont: (textSchema: TextSchema, font: Font, _cache: Map<any, any>) => Promise<fontkit.Font>;
12
+ export declare const getFontKitFont: (fontName: string | undefined, font: Font, _cache: Map<any, any>) => Promise<fontkit.Font>;
13
13
  /**
14
14
  * Recursively splits the line at getSplitPosition.
15
15
  * If there is some leftover, split the rest again in the same manner.
@@ -28,3 +28,10 @@ export declare const calculateDynamicFontSize: ({ textSchema, font, value, start
28
28
  startingFontSize?: number | undefined;
29
29
  _cache: Map<any, any>;
30
30
  }) => Promise<number>;
31
+ export declare const splitTextToSize: (arg: {
32
+ value: string;
33
+ characterSpacing: number;
34
+ boxWidthInPt: number;
35
+ fontSize: number;
36
+ fontKitFont: fontkit.Font;
37
+ }) => string[];
@@ -28,3 +28,5 @@ export declare const isEditable: (mode: Mode, schema: Schema) => boolean;
28
28
  export declare const hex2RgbColor: (hexString: string | undefined) => import("@pdfme/pdf-lib").RGB | undefined;
29
29
  export declare const readFile: (input: File | FileList | null) => Promise<string | ArrayBuffer>;
30
30
  export declare const createErrorElm: () => HTMLDivElement;
31
+ export declare const px2mm: (px: number) => number;
32
+ export declare const cloneDeep: <T>(value: T) => T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/schemas",
3
- "version": "3.2.3-dev.1",
3
+ "version": "4.0.0-alpha.0",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
@@ -16,11 +16,11 @@ const defaultIncludetext = { includetext: DEFAULT_BARCODE_INCLUDETEXT };
16
16
  const position = { x: 0, y: 0 };
17
17
  const default40x20 = { width: 40, height: 20 };
18
18
 
19
- const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[] = [
19
+ const barcodeDefaults: { defaultSchema: BarcodeSchema }[] = [
20
20
  {
21
- defaultValue: 'https://pdfme.com/',
22
21
  defaultSchema: {
23
22
  type: 'qrcode',
23
+ content: 'https://pdfme.com/',
24
24
  position,
25
25
  ...defaultColors,
26
26
  width: 30,
@@ -30,9 +30,9 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
30
30
  },
31
31
  },
32
32
  {
33
- defaultValue: '6540123789-A-K-Z',
34
33
  defaultSchema: {
35
34
  type: 'japanpost',
35
+ content: '6540123789-A-K-Z',
36
36
  position,
37
37
  ...defaultColors,
38
38
  ...defaultTextColors,
@@ -44,9 +44,9 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
44
44
  },
45
45
  },
46
46
  {
47
- defaultValue: '2112345678900',
48
47
  defaultSchema: {
49
48
  type: 'ean13',
49
+ content: '2112345678900',
50
50
  position,
51
51
  ...defaultColors,
52
52
  ...defaultTextColors,
@@ -58,9 +58,9 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
58
58
  },
59
59
  },
60
60
  {
61
- defaultValue: '02345673',
62
61
  defaultSchema: {
63
62
  type: 'ean8',
63
+ content: '02345673',
64
64
  position,
65
65
  ...defaultColors,
66
66
  ...defaultTextColors,
@@ -71,9 +71,9 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
71
71
  },
72
72
  },
73
73
  {
74
- defaultValue: 'THIS IS CODE 39',
75
74
  defaultSchema: {
76
75
  type: 'code39',
76
+ content: 'THIS IS CODE 39',
77
77
  position,
78
78
  ...defaultColors,
79
79
  ...defaultTextColors,
@@ -83,9 +83,9 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
83
83
  },
84
84
  },
85
85
  {
86
- defaultValue: 'This is Code 128!',
87
86
  defaultSchema: {
88
87
  type: 'code128',
88
+ content: 'This is Code 128!',
89
89
  position,
90
90
  ...defaultColors,
91
91
  ...defaultTextColors,
@@ -96,9 +96,9 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
96
96
  },
97
97
  },
98
98
  {
99
- defaultValue: 'A0123456789B',
100
99
  defaultSchema: {
101
100
  type: 'nw7',
101
+ content: 'A0123456789B',
102
102
  position,
103
103
  ...defaultColors,
104
104
  ...defaultTextColors,
@@ -109,9 +109,9 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
109
109
  },
110
110
  },
111
111
  {
112
- defaultValue: '04601234567893',
113
112
  defaultSchema: {
114
113
  type: 'itf14',
114
+ content: '04601234567893',
115
115
  position,
116
116
  ...defaultColors,
117
117
  ...defaultTextColors,
@@ -123,9 +123,9 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
123
123
  },
124
124
  },
125
125
  {
126
- defaultValue: '416000336108',
127
126
  defaultSchema: {
128
127
  type: 'upca',
128
+ content: '416000336108',
129
129
  position,
130
130
  ...defaultColors,
131
131
  ...defaultTextColors,
@@ -137,9 +137,9 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
137
137
  },
138
138
  },
139
139
  {
140
- defaultValue: '00123457',
141
140
  defaultSchema: {
142
141
  type: 'upce',
142
+ content: '00123457',
143
143
  position,
144
144
  ...defaultColors,
145
145
  ...defaultTextColors,
@@ -150,9 +150,9 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
150
150
  },
151
151
  },
152
152
  {
153
- defaultValue: '(01)03453120000011(17)191125(10)ABCD1234',
154
153
  defaultSchema: {
155
154
  type: 'gs1datamatrix',
155
+ content: '(01)03453120000011(17)191125(10)ABCD1234',
156
156
  position,
157
157
  ...defaultColors,
158
158
  width: 30,
@@ -69,7 +69,7 @@ export const uiRender = async (arg: UIRenderProps<BarcodeSchema>) => {
69
69
  input.placeholder = placeholder || '';
70
70
  input.tabIndex = tabIndex || 0;
71
71
  input.addEventListener('change', (e: Event) => {
72
- onChange && onChange((e.target as HTMLInputElement).value);
72
+ onChange && onChange({ key: 'content', value: (e.target as HTMLInputElement).value });
73
73
  });
74
74
  input.addEventListener('blur', () => {
75
75
  stopEditing && stopEditing();
@@ -5,16 +5,10 @@ import type { PDFRenderProps, Schema } from '@pdfme/common';
5
5
  import type * as CSS from 'csstype';
6
6
  import { Buffer } from 'buffer';
7
7
  import { UIRenderProps } from '@pdfme/common';
8
- import { convertForPdfLayoutProps, addAlphaToHex, isEditable, readFile } from '../utils.js';
8
+ import { convertForPdfLayoutProps, addAlphaToHex, isEditable, readFile, px2mm } from '../utils.js';
9
9
  import { DEFAULT_OPACITY } from '../constants.js';
10
10
  import { imageSize } from './helper.js';
11
11
 
12
- const px2mm = (px: number): number => {
13
- // http://www.endmemo.com/sconvert/millimeterpixel.php
14
- const ratio = 0.26458333333333;
15
- return parseFloat(String(px)) * ratio;
16
- };
17
-
18
12
  const getCacheKey = (schema: Schema, input: string) => `${schema.type}${input}`;
19
13
  const fullSize = { width: '100%', height: '100%' };
20
14
  const defaultValue =
@@ -133,7 +127,7 @@ const imageSchema: Plugin<ImageSchema> = {
133
127
  };
134
128
  Object.assign(button.style, buttonStyle);
135
129
  button.addEventListener('click', () => {
136
- onChange && onChange('');
130
+ onChange && onChange({ key: 'content', value: '' });
137
131
  });
138
132
  container.appendChild(button);
139
133
  }
@@ -168,7 +162,9 @@ const imageSchema: Plugin<ImageSchema> = {
168
162
  input.accept = 'image/jpeg, image/png';
169
163
  input.addEventListener('change', (event: Event) => {
170
164
  const changeEvent = event as unknown as ChangeEvent<HTMLInputElement>;
171
- readFile(changeEvent.target.files).then((result) => onChange && onChange(result as string));
165
+ readFile(changeEvent.target.files).then(
166
+ (result) => onChange && onChange({ key: 'content', value: result as string })
167
+ );
172
168
  });
173
169
  input.addEventListener('blur', () => stopEditing && stopEditing());
174
170
  label.appendChild(input);
@@ -176,9 +172,9 @@ const imageSchema: Plugin<ImageSchema> = {
176
172
  },
177
173
  propPanel: {
178
174
  schema: {},
179
- defaultValue,
180
175
  defaultSchema: {
181
176
  type: 'image',
177
+ content: defaultValue,
182
178
  position: { x: 0, y: 0 },
183
179
  width: 40,
184
180
  height: 40,
@@ -201,7 +197,6 @@ export const readOnlyImage: Plugin<ImageSchema> = {
201
197
  ...imageSchema.propPanel.defaultSchema,
202
198
  type: 'readOnlyImage',
203
199
  readOnly: true,
204
- readOnlyValue: defaultValue,
205
200
  },
206
201
  },
207
202
  };
@@ -41,7 +41,7 @@ const svgSchema: Plugin<SVGSchema> = {
41
41
 
42
42
  textarea.addEventListener('change', (e: Event) => {
43
43
  const newValue = (e.target as HTMLTextAreaElement).value;
44
- onChange && onChange(newValue);
44
+ onChange && onChange({ key: 'content', value: newValue });
45
45
  });
46
46
  rootElement.appendChild(container);
47
47
  textarea.setSelectionRange(value.length, value.length);
@@ -71,9 +71,9 @@ const svgSchema: Plugin<SVGSchema> = {
71
71
  },
72
72
  propPanel: {
73
73
  schema: {},
74
- defaultValue,
75
74
  defaultSchema: {
76
75
  type: 'svg',
76
+ content: defaultValue,
77
77
  position: { x: 0, y: 0 },
78
78
  width: 40,
79
79
  height: 40,
@@ -92,7 +92,6 @@ export const readOnlySvg: Plugin<SVGSchema> = {
92
92
  ...svgSchema.propPanel.defaultSchema,
93
93
  type: 'readOnlySvg',
94
94
  readOnly: true,
95
- readOnlyValue: defaultValue,
96
95
  },
97
96
  },
98
97
  };
package/src/index.ts CHANGED
@@ -3,6 +3,8 @@ import image, { readOnlyImage } from './graphics/image.js';
3
3
  import svg, { readOnlySvg } from './graphics/svg.js';
4
4
  import barcodes from './barcodes/index.js';
5
5
  import line from './shapes/line.js';
6
+ import table from './tables/index.js';
7
+ import { modifyTemplateForTable, getDynamicHeightForTable } from './tables/dynamicTemplate.js';
6
8
  import { rectangle, ellipse } from './shapes/rectAndEllipse.js';
7
9
  import { convertForPdfLayoutProps, rotatePoint } from './utils.js';
8
10
 
@@ -17,6 +19,9 @@ export {
17
19
  readOnlySvg,
18
20
  barcodes,
19
21
  line,
22
+ table,
23
+ modifyTemplateForTable,
24
+ getDynamicHeightForTable,
20
25
  rectangle,
21
26
  ellipse,
22
27
  builtInPlugins,
@@ -11,6 +11,7 @@ interface LineSchema extends Schema {
11
11
  const lineSchema: Plugin<LineSchema> = {
12
12
  pdf: (arg: PDFRenderProps<LineSchema>) => {
13
13
  const { page, schema } = arg;
14
+ if (schema.width === 0 || schema.height === 0 || !schema.color) return;
14
15
  const pageHeight = page.getHeight();
15
16
  const {
16
17
  width,
@@ -24,14 +25,14 @@ const lineSchema: Plugin<LineSchema> = {
24
25
  start: rotatePoint({ x, y: y + height / 2 }, pivot, rotate.angle),
25
26
  end: rotatePoint({ x: x + width, y: y + height / 2 }, pivot, rotate.angle),
26
27
  thickness: height,
27
- color: hex2RgbColor(schema.color ?? DEFAULT_LINE_COLOR),
28
+ color: hex2RgbColor(schema.color),
28
29
  opacity: opacity,
29
30
  });
30
31
  },
31
32
  ui: (arg: UIRenderProps<LineSchema>) => {
32
33
  const { schema, rootElement } = arg;
33
34
  const div = document.createElement('div');
34
- div.style.backgroundColor = schema.color ?? DEFAULT_LINE_COLOR;
35
+ div.style.backgroundColor = schema.color ?? 'transparent';
35
36
  div.style.width = '100%';
36
37
  div.style.height = '100%';
37
38
  rootElement.appendChild(div);
@@ -43,15 +44,9 @@ const lineSchema: Plugin<LineSchema> = {
43
44
  type: 'string',
44
45
  widget: 'color',
45
46
  required: true,
46
- rules: [
47
- {
48
- pattern: HEX_COLOR_PATTERN,
49
- message: i18n('hexColorPrompt'),
50
- },
51
- ],
47
+ rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('hexColorPrompt') }],
52
48
  },
53
49
  }),
54
- defaultValue: '',
55
50
  defaultSchema: {
56
51
  type: 'line',
57
52
  position: { x: 0, y: 0 },
@@ -2,14 +2,14 @@ import { Plugin, Schema, mm2pt } from '@pdfme/common';
2
2
  import { HEX_COLOR_PATTERN } from '../constants.js';
3
3
  import { hex2RgbColor, convertForPdfLayoutProps } from '../utils.js';
4
4
 
5
- interface Shape extends Schema {
5
+ interface ShapeSchema extends Schema {
6
6
  type: 'ellipse' | 'rectangle';
7
7
  borderWidth: number;
8
8
  borderColor: string;
9
9
  color: string;
10
10
  }
11
11
 
12
- const shape: Plugin<Shape> = {
12
+ const shape: Plugin<ShapeSchema> = {
13
13
  ui: (arg) => {
14
14
  const { schema, rootElement } = arg;
15
15
  const div = document.createElement('div');
@@ -28,6 +28,7 @@ const shape: Plugin<Shape> = {
28
28
  },
29
29
  pdf: (arg) => {
30
30
  const { schema, page } = arg;
31
+ if (!schema.color && !schema.borderColor) return;
31
32
  const pageHeight = page.getHeight();
32
33
  const cArg = { schema, pageHeight };
33
34
  const { position, width, height, rotate, opacity } = convertForPdfLayoutProps(cArg);
@@ -68,7 +69,7 @@ const shape: Plugin<Shape> = {
68
69
  title: i18n('schemas.borderWidth'),
69
70
  type: 'number',
70
71
  widget: 'inputNumber',
71
- min: 0,
72
+ props: { min: 0 },
72
73
  step: 1,
73
74
  },
74
75
  borderColor: {
@@ -84,7 +85,6 @@ const shape: Plugin<Shape> = {
84
85
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('hexColorPrompt') }],
85
86
  },
86
87
  }),
87
- defaultValue: '',
88
88
  defaultSchema: {
89
89
  type: 'rectangle',
90
90
  position: { x: 0, y: 0 },
@@ -0,0 +1,157 @@
1
+ import {
2
+ DEFAULT_FONT_NAME,
3
+ Plugin,
4
+ PDFRenderProps,
5
+ UIRenderProps,
6
+ getFallbackFontName,
7
+ } from '@pdfme/common';
8
+ import { uiRender as textUiRender } from '../text/uiRender.js';
9
+ import { pdfRender as textPdfRender } from '../text/pdfRender.js';
10
+ import line from '../shapes/line.js';
11
+ import { rectangle } from '../shapes/rectAndEllipse.js';
12
+ import type { CellSchema } from './types';
13
+ import { getCellPropPanelSchema, getDefaultCellStyles } from './helper.js';
14
+ const linePdfRender = line.pdf;
15
+ const rectanglePdfRender = rectangle.pdf;
16
+
17
+ const renderLine = async (
18
+ arg: PDFRenderProps<CellSchema>,
19
+ schema: CellSchema,
20
+ position: { x: number; y: number },
21
+ width: number,
22
+ height: number
23
+ ) =>
24
+ linePdfRender({
25
+ ...arg,
26
+ schema: { ...schema, type: 'line', position, width, height, color: schema.borderColor },
27
+ });
28
+
29
+ const createTextDiv = (schema: CellSchema) => {
30
+ const { borderWidth: bw, width, height, padding: pd } = schema;
31
+ const textDiv = document.createElement('div');
32
+ textDiv.style.position = 'absolute';
33
+ textDiv.style.zIndex = '1';
34
+ textDiv.style.width = `${width - bw.left - bw.right - pd.left - pd.right}mm`;
35
+ textDiv.style.height = `${height - bw.top - bw.bottom - pd.top - pd.bottom}mm`;
36
+ textDiv.style.top = `${bw.top + pd.top}mm`;
37
+ textDiv.style.left = `${bw.left + pd.left}mm`;
38
+ return textDiv;
39
+ };
40
+
41
+ const createLineDiv = (
42
+ width: string,
43
+ height: string,
44
+ top: string | null,
45
+ right: string | null,
46
+ bottom: string | null,
47
+ left: string | null,
48
+ borderColor: string
49
+ ) => {
50
+ const div = document.createElement('div');
51
+ div.style.width = width;
52
+ div.style.height = height;
53
+ div.style.position = 'absolute';
54
+ if (top !== null) div.style.top = top;
55
+ if (right !== null) div.style.right = right;
56
+ if (bottom !== null) div.style.bottom = bottom;
57
+ if (left !== null) div.style.left = left;
58
+ div.style.backgroundColor = borderColor;
59
+ return div;
60
+ };
61
+
62
+ const cellSchema: Plugin<CellSchema> = {
63
+ pdf: async (arg: PDFRenderProps<CellSchema>) => {
64
+ const { schema } = arg;
65
+ const { position, width, height, borderWidth, padding } = schema;
66
+
67
+ await Promise.all([
68
+ // BACKGROUND
69
+ rectanglePdfRender({
70
+ ...arg,
71
+ schema: {
72
+ ...schema,
73
+ type: 'rectangle',
74
+ width: schema.width,
75
+ height: schema.height,
76
+ borderWidth: 0,
77
+ borderColor: '',
78
+ color: schema.backgroundColor,
79
+ },
80
+ }),
81
+ // TOP
82
+ renderLine(arg, schema, { x: position.x, y: position.y }, width, borderWidth.top),
83
+ // RIGHT
84
+ renderLine(
85
+ arg,
86
+ schema,
87
+ { x: position.x + width - borderWidth.right, y: position.y },
88
+ borderWidth.right,
89
+ height
90
+ ),
91
+ // BOTTOM
92
+ renderLine(
93
+ arg,
94
+ schema,
95
+ { x: position.x, y: position.y + height - borderWidth.bottom },
96
+ width,
97
+ borderWidth.bottom
98
+ ),
99
+ // LEFT
100
+ renderLine(arg, schema, { x: position.x, y: position.y }, borderWidth.left, height),
101
+ ]);
102
+ // TEXT
103
+ await textPdfRender({
104
+ ...arg,
105
+ schema: {
106
+ ...schema,
107
+ type: 'text',
108
+ backgroundColor: '',
109
+ position: {
110
+ x: position.x + borderWidth.left + padding.left,
111
+ y: position.y + borderWidth.top + padding.top,
112
+ },
113
+ width: width - borderWidth.left - borderWidth.right - padding.left - padding.right,
114
+ height: height - borderWidth.top - borderWidth.bottom - padding.top - padding.bottom,
115
+ },
116
+ });
117
+ },
118
+ ui: async (arg: UIRenderProps<CellSchema>) => {
119
+ const { schema, rootElement } = arg;
120
+ const { borderWidth, width, height, borderColor, backgroundColor } = schema;
121
+ rootElement.style.backgroundColor = backgroundColor;
122
+
123
+ const textDiv = createTextDiv(schema);
124
+ await textUiRender({
125
+ ...arg,
126
+ schema: { ...schema, backgroundColor: '' },
127
+ rootElement: textDiv,
128
+ });
129
+ rootElement.appendChild(textDiv);
130
+
131
+ const lines = [
132
+ createLineDiv(`${width}mm`, `${borderWidth.top}mm`, '0mm', null, null, '0mm', borderColor),
133
+ createLineDiv(`${width}mm`, `${borderWidth.bottom}mm`, null, null, '0mm', '0mm', borderColor),
134
+ createLineDiv(`${borderWidth.left}mm`, `${height}mm`, '0mm', null, null, '0mm', borderColor),
135
+ createLineDiv(`${borderWidth.right}mm`, `${height}mm`, '0mm', '0mm', null, null, borderColor),
136
+ ];
137
+
138
+ lines.forEach((line) => rootElement.appendChild(line));
139
+ },
140
+ propPanel: {
141
+ schema: ({ options, i18n }) => {
142
+ const font = options.font || { [DEFAULT_FONT_NAME]: { data: '', fallback: true } };
143
+ const fontNames = Object.keys(font);
144
+ const fallbackFontName = getFallbackFontName(font);
145
+ return getCellPropPanelSchema({ i18n, fontNames, fallbackFontName });
146
+ },
147
+ defaultSchema: {
148
+ type: 'cell',
149
+ content: 'Type Something...',
150
+ position: { x: 0, y: 0 },
151
+ width: 50,
152
+ height: 15,
153
+ ...getDefaultCellStyles(),
154
+ },
155
+ },
156
+ };
157
+ export default cellSchema;