@pdfme/schemas 3.1.5-dev.9 → 3.2.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 (159) hide show
  1. package/dist/cjs/__tests__/{renderUtils.test.js → utils.test.js} +38 -12
  2. package/dist/cjs/__tests__/utils.test.js.map +1 -0
  3. package/dist/cjs/src/barcodes/index.js +2 -2
  4. package/dist/cjs/src/barcodes/index.js.map +1 -1
  5. package/dist/cjs/src/barcodes/pdfRender.js +2 -2
  6. package/dist/cjs/src/barcodes/pdfRender.js.map +1 -1
  7. package/dist/cjs/src/barcodes/propPanel.js +1 -1
  8. package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
  9. package/dist/cjs/src/barcodes/uiRender.js +9 -32
  10. package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
  11. package/dist/cjs/src/graphics/helper.js +115 -0
  12. package/dist/cjs/src/graphics/helper.js.map +1 -0
  13. package/dist/cjs/src/graphics/image.js +179 -0
  14. package/dist/cjs/src/graphics/image.js.map +1 -0
  15. package/dist/cjs/src/graphics/svg.js +96 -0
  16. package/dist/cjs/src/graphics/svg.js.map +1 -0
  17. package/dist/cjs/src/index.js +42 -11
  18. package/dist/cjs/src/index.js.map +1 -1
  19. package/dist/cjs/src/shapes/line.js +57 -0
  20. package/dist/cjs/src/shapes/line.js.map +1 -0
  21. package/dist/cjs/src/shapes/rectAndEllipse.js +100 -0
  22. package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -0
  23. package/dist/cjs/src/text/helper.js.map +1 -1
  24. package/dist/cjs/src/text/index.js +16 -2
  25. package/dist/cjs/src/text/index.js.map +1 -1
  26. package/dist/cjs/src/text/pdfRender.js +5 -5
  27. package/dist/cjs/src/text/pdfRender.js.map +1 -1
  28. package/dist/cjs/src/text/uiRender.js +3 -3
  29. package/dist/cjs/src/text/uiRender.js.map +1 -1
  30. package/dist/cjs/src/{renderUtils.js → utils.js} +55 -7
  31. package/dist/cjs/src/utils.js.map +1 -0
  32. package/dist/esm/__tests__/{renderUtils.test.js → utils.test.js} +34 -8
  33. package/dist/esm/__tests__/utils.test.js.map +1 -0
  34. package/dist/esm/src/barcodes/index.js +2 -2
  35. package/dist/esm/src/barcodes/index.js.map +1 -1
  36. package/dist/esm/src/barcodes/pdfRender.js +1 -1
  37. package/dist/esm/src/barcodes/pdfRender.js.map +1 -1
  38. package/dist/esm/src/barcodes/propPanel.js +1 -1
  39. package/dist/esm/src/barcodes/propPanel.js.map +1 -1
  40. package/dist/esm/src/barcodes/uiRender.js +9 -32
  41. package/dist/esm/src/barcodes/uiRender.js.map +1 -1
  42. package/dist/esm/src/graphics/helper.js +111 -0
  43. package/dist/esm/src/graphics/helper.js.map +1 -0
  44. package/dist/esm/src/graphics/image.js +176 -0
  45. package/dist/esm/src/graphics/image.js.map +1 -0
  46. package/dist/esm/src/graphics/svg.js +93 -0
  47. package/dist/esm/src/graphics/svg.js.map +1 -0
  48. package/dist/esm/src/index.js +7 -5
  49. package/dist/esm/src/index.js.map +1 -1
  50. package/dist/esm/src/shapes/line.js +55 -0
  51. package/dist/esm/src/shapes/line.js.map +1 -0
  52. package/dist/esm/src/shapes/rectAndEllipse.js +97 -0
  53. package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -0
  54. package/dist/esm/src/text/helper.js.map +1 -1
  55. package/dist/esm/src/text/index.js +15 -2
  56. package/dist/esm/src/text/index.js.map +1 -1
  57. package/dist/esm/src/text/pdfRender.js +1 -1
  58. package/dist/esm/src/text/pdfRender.js.map +1 -1
  59. package/dist/esm/src/text/uiRender.js +2 -2
  60. package/dist/esm/src/text/uiRender.js.map +1 -1
  61. package/dist/esm/src/{renderUtils.js → utils.js} +52 -6
  62. package/dist/esm/src/utils.js.map +1 -0
  63. package/dist/types/src/barcodes/index.d.ts +2 -2
  64. package/dist/types/src/graphics/helper.d.ts +5 -0
  65. package/dist/types/src/graphics/image.d.ts +7 -0
  66. package/dist/types/src/graphics/svg.d.ts +6 -0
  67. package/dist/types/src/index.d.ts +7 -5
  68. package/dist/types/src/shapes/line.d.ts +6 -0
  69. package/dist/types/src/shapes/rectAndEllipse.d.ts +144 -0
  70. package/dist/types/src/text/index.d.ts +3 -2
  71. package/dist/types/src/text/pdfRender.d.ts +1 -1
  72. package/dist/types/src/{renderUtils.d.ts → utils.d.ts} +3 -1
  73. package/package.json +4 -3
  74. package/src/barcodes/index.ts +2 -2
  75. package/src/barcodes/pdfRender.ts +1 -1
  76. package/src/barcodes/propPanel.ts +1 -1
  77. package/src/barcodes/uiRender.ts +9 -36
  78. package/src/graphics/helper.ts +147 -0
  79. package/src/graphics/image.ts +207 -0
  80. package/src/graphics/svg.ts +98 -0
  81. package/src/index.ts +21 -5
  82. package/src/shapes/line.ts +67 -0
  83. package/src/shapes/rectAndEllipse.ts +110 -0
  84. package/src/text/helper.ts +0 -1
  85. package/src/text/index.ts +17 -2
  86. package/src/text/pdfRender.ts +2 -2
  87. package/src/text/uiRender.ts +2 -2
  88. package/src/{renderUtils.ts → utils.ts} +61 -5
  89. package/dist/cjs/__tests__/renderUtils.test.js.map +0 -1
  90. package/dist/cjs/src/image/index.js +0 -8
  91. package/dist/cjs/src/image/index.js.map +0 -1
  92. package/dist/cjs/src/image/pdfRender.js +0 -22
  93. package/dist/cjs/src/image/pdfRender.js.map +0 -1
  94. package/dist/cjs/src/image/propPanel.js +0 -19
  95. package/dist/cjs/src/image/propPanel.js.map +0 -1
  96. package/dist/cjs/src/image/types.js +0 -3
  97. package/dist/cjs/src/image/types.js.map +0 -1
  98. package/dist/cjs/src/image/uiRender.js +0 -111
  99. package/dist/cjs/src/image/uiRender.js.map +0 -1
  100. package/dist/cjs/src/line/constants.js +0 -5
  101. package/dist/cjs/src/line/constants.js.map +0 -1
  102. package/dist/cjs/src/line/index.js +0 -8
  103. package/dist/cjs/src/line/index.js.map +0 -1
  104. package/dist/cjs/src/line/pdfRender.js +0 -20
  105. package/dist/cjs/src/line/pdfRender.js.map +0 -1
  106. package/dist/cjs/src/line/propPanel.js +0 -35
  107. package/dist/cjs/src/line/propPanel.js.map +0 -1
  108. package/dist/cjs/src/line/types.js +0 -3
  109. package/dist/cjs/src/line/types.js.map +0 -1
  110. package/dist/cjs/src/line/uiRender.js +0 -14
  111. package/dist/cjs/src/line/uiRender.js.map +0 -1
  112. package/dist/cjs/src/renderUtils.js.map +0 -1
  113. package/dist/esm/__tests__/renderUtils.test.js.map +0 -1
  114. package/dist/esm/src/image/index.js +0 -6
  115. package/dist/esm/src/image/index.js.map +0 -1
  116. package/dist/esm/src/image/pdfRender.js +0 -18
  117. package/dist/esm/src/image/pdfRender.js.map +0 -1
  118. package/dist/esm/src/image/propPanel.js +0 -16
  119. package/dist/esm/src/image/propPanel.js.map +0 -1
  120. package/dist/esm/src/image/types.js +0 -2
  121. package/dist/esm/src/image/types.js.map +0 -1
  122. package/dist/esm/src/image/uiRender.js +0 -107
  123. package/dist/esm/src/image/uiRender.js.map +0 -1
  124. package/dist/esm/src/line/constants.js +0 -2
  125. package/dist/esm/src/line/constants.js.map +0 -1
  126. package/dist/esm/src/line/index.js +0 -6
  127. package/dist/esm/src/line/index.js.map +0 -1
  128. package/dist/esm/src/line/pdfRender.js +0 -16
  129. package/dist/esm/src/line/pdfRender.js.map +0 -1
  130. package/dist/esm/src/line/propPanel.js +0 -32
  131. package/dist/esm/src/line/propPanel.js.map +0 -1
  132. package/dist/esm/src/line/types.js +0 -2
  133. package/dist/esm/src/line/types.js.map +0 -1
  134. package/dist/esm/src/line/uiRender.js +0 -10
  135. package/dist/esm/src/line/uiRender.js.map +0 -1
  136. package/dist/esm/src/renderUtils.js.map +0 -1
  137. package/dist/types/src/image/index.d.ts +0 -4
  138. package/dist/types/src/image/pdfRender.d.ts +0 -3
  139. package/dist/types/src/image/propPanel.d.ts +0 -3
  140. package/dist/types/src/image/types.d.ts +0 -3
  141. package/dist/types/src/image/uiRender.d.ts +0 -3
  142. package/dist/types/src/line/constants.d.ts +0 -1
  143. package/dist/types/src/line/index.d.ts +0 -4
  144. package/dist/types/src/line/pdfRender.d.ts +0 -3
  145. package/dist/types/src/line/propPanel.d.ts +0 -3
  146. package/dist/types/src/line/types.d.ts +0 -4
  147. package/dist/types/src/line/uiRender.d.ts +0 -3
  148. package/src/image/index.ts +0 -8
  149. package/src/image/pdfRender.ts +0 -29
  150. package/src/image/propPanel.ts +0 -19
  151. package/src/image/types.ts +0 -3
  152. package/src/image/uiRender.ts +0 -121
  153. package/src/line/constants.ts +0 -1
  154. package/src/line/index.ts +0 -8
  155. package/src/line/pdfRender.ts +0 -24
  156. package/src/line/propPanel.ts +0 -34
  157. package/src/line/types.ts +0 -5
  158. package/src/line/uiRender.ts +0 -12
  159. /package/dist/types/__tests__/{renderUtils.test.d.ts → utils.test.d.ts} +0 -0
@@ -1,121 +0,0 @@
1
- import type { ChangeEvent } from 'react';
2
- import type * as CSS from 'csstype';
3
- import type { ImageSchema } from './types';
4
- import { UIRenderProps, ZOOM } from '@pdfme/common';
5
- import { addAlphaToHex, isEditable } from '../renderUtils.js';
6
-
7
- const fullSize = { width: '100%', height: '100%' };
8
-
9
- const readFile = (input: File | FileList | null): Promise<string | ArrayBuffer> =>
10
- new Promise((resolve, reject) => {
11
- const fileReader = new FileReader();
12
-
13
- fileReader.onload = (e) => {
14
- if (e.target?.result) {
15
- resolve(e.target.result);
16
- }
17
- };
18
-
19
- fileReader.onerror = (e) => {
20
- reject(new Error('[@pdfme/schemas] File reading failed'));
21
- };
22
-
23
- let file: File | null = null;
24
- if (input instanceof FileList && input.length > 0) {
25
- file = input[0];
26
- } else if (input instanceof File) {
27
- file = input;
28
- }
29
-
30
- if (file) {
31
- fileReader.readAsDataURL(file);
32
- } else {
33
- reject(new Error('[@pdfme/schemas] No files provided'));
34
- }
35
- });
36
-
37
- export const uiRender = async (arg: UIRenderProps<ImageSchema>) => {
38
- const { value, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, schema, theme } =
39
- arg;
40
- const editable = isEditable(mode);
41
-
42
- const size = { width: schema.width * ZOOM, height: schema.height * ZOOM };
43
-
44
- const container = document.createElement('div');
45
- const backgroundStyle = placeholder ? `url(${placeholder})` : 'none';
46
- const containerStyle: CSS.Properties = {
47
- ...fullSize,
48
- backgroundImage: value ? 'none' : backgroundStyle,
49
- backgroundSize: `${size.width}px ${size.height}px`,
50
- };
51
- Object.assign(container.style, containerStyle);
52
- container.addEventListener('click', (e) => {
53
- if (editable) {
54
- e.stopPropagation();
55
- }
56
- });
57
- rootElement.appendChild(container);
58
-
59
- // image tag
60
- if (value) {
61
- const img = document.createElement('img');
62
- const imgStyle: CSS.Properties = { height: '100%', width: '100%', borderRadius: 0 };
63
- Object.assign(img.style, imgStyle);
64
- img.src = value;
65
- container.appendChild(img);
66
- }
67
-
68
- // remove button
69
- if (value && editable) {
70
- const button = document.createElement('button');
71
- button.textContent = 'x';
72
- const buttonStyle: CSS.Properties = {
73
- position: 'absolute',
74
- top: 0,
75
- left: 0,
76
- zIndex: 1,
77
- display: 'flex',
78
- justifyContent: 'center',
79
- alignItems: 'center',
80
- color: '#333',
81
- background: '#f2f2f2',
82
- borderRadius: '2px',
83
- border: '1px solid #767676',
84
- cursor: 'pointer',
85
- height: '24px',
86
- width: '24px',
87
- };
88
- Object.assign(button.style, buttonStyle);
89
- button.addEventListener('click', () => {
90
- onChange && onChange('');
91
- });
92
- container.appendChild(button);
93
- }
94
-
95
- // file input
96
- if (!value && editable) {
97
- const label = document.createElement('label');
98
- const labelStyle: CSS.Properties = {
99
- ...fullSize,
100
- display: editable ? 'flex' : 'none',
101
- position: 'absolute',
102
- top: 0,
103
- backgroundColor: editable || value ? addAlphaToHex(theme.colorPrimaryBg, 30) : 'none',
104
- cursor: 'pointer',
105
- };
106
- Object.assign(label.style, labelStyle);
107
- container.appendChild(label);
108
- const input = document.createElement('input');
109
- const inputStyle: CSS.Properties = { ...fullSize, position: 'absolute', top: '50%' };
110
- Object.assign(input.style, inputStyle);
111
- input.tabIndex = tabIndex || 0;
112
- input.type = 'file';
113
- input.accept = 'image/jpeg, image/png';
114
- input.addEventListener('change', (event: Event) => {
115
- const changeEvent = event as unknown as ChangeEvent<HTMLInputElement>;
116
- readFile(changeEvent.target.files).then((result) => onChange && onChange(result as string));
117
- });
118
- input.addEventListener('blur', () => stopEditing && stopEditing());
119
- label.appendChild(input);
120
- }
121
- };
@@ -1 +0,0 @@
1
- export const DEFAULT_LINE_COLOR = '#000000';
package/src/line/index.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { Plugin } from '@pdfme/common';
2
- import { pdfRender } from './pdfRender.js';
3
- import { propPanel } from './propPanel.js';
4
- import { uiRender } from './uiRender.js';
5
- import type { LineSchema } from './types.js';
6
-
7
- const schema: Plugin<LineSchema> = { pdf: pdfRender, ui: uiRender, propPanel };
8
- export default schema;
@@ -1,24 +0,0 @@
1
- import type { PDFRenderProps } from '@pdfme/common';
2
- import type { LineSchema } from './types';
3
- import { rotatePoint, convertForPdfLayoutProps, hex2RgbColor } from '../renderUtils.js';
4
- import { DEFAULT_LINE_COLOR } from './constants.js';
5
-
6
- export const pdfRender = (arg: PDFRenderProps<LineSchema>) => {
7
- const { page, schema } = arg;
8
- const pageHeight = page.getHeight();
9
- const {
10
- width,
11
- height,
12
- rotate,
13
- position: { x, y },
14
- opacity,
15
- } = convertForPdfLayoutProps({ schema, pageHeight, applyRotateTranslate: false });
16
- const pivot = { x: x + width / 2, y: y + height / 2 };
17
- page.drawLine({
18
- start: rotatePoint({ x, y: y + height / 2 }, pivot, rotate.angle),
19
- end: rotatePoint({ x: x + width, y: y + height / 2 }, pivot, rotate.angle),
20
- thickness: height,
21
- color: hex2RgbColor(schema.color ?? DEFAULT_LINE_COLOR),
22
- opacity: opacity,
23
- });
24
- };
@@ -1,34 +0,0 @@
1
- import { PropPanel } from '@pdfme/common';
2
- import type { LineSchema } from './types';
3
- import { HEX_COLOR_PATTERN } from '../constants.js';
4
- import { DEFAULT_LINE_COLOR } from './constants.js';
5
-
6
- export const propPanel: PropPanel<LineSchema> = {
7
- schema: ({ i18n }) => {
8
- return {
9
- color: {
10
- title: i18n('schemas.line.color'),
11
- type: 'string',
12
- widget: 'color',
13
- required: true,
14
- rules: [
15
- {
16
- pattern: HEX_COLOR_PATTERN,
17
- message: i18n('hexColorPrompt'),
18
- },
19
- ],
20
- },
21
- };
22
- },
23
- defaultValue: '',
24
- defaultSchema: {
25
- type: 'line',
26
- position: { x: 0, y: 0 },
27
- width: 50,
28
- height: 1,
29
- rotate: 0,
30
- opacity: 1,
31
- readOnly: true,
32
- color: DEFAULT_LINE_COLOR,
33
- },
34
- };
package/src/line/types.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Schema } from '@pdfme/common';
2
-
3
- export interface LineSchema extends Schema {
4
- color: string;
5
- }
@@ -1,12 +0,0 @@
1
- import type { LineSchema } from './types';
2
- import { UIRenderProps } from '@pdfme/common';
3
- import { DEFAULT_LINE_COLOR } from './constants.js';
4
-
5
- export const uiRender = (arg: UIRenderProps<LineSchema>) => {
6
- const { schema, rootElement } = arg;
7
- const div = document.createElement('div');
8
- div.style.backgroundColor = schema.color ?? DEFAULT_LINE_COLOR;
9
- div.style.width = '100%';
10
- div.style.height = '100%';
11
- rootElement.appendChild(div);
12
- };