@pdfme/schemas 3.1.5-dev.9 → 3.2.0-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 (173) 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/constants.js +2 -1
  4. package/dist/cjs/src/barcodes/constants.js.map +1 -1
  5. package/dist/cjs/src/barcodes/helper.js +1 -2
  6. package/dist/cjs/src/barcodes/helper.js.map +1 -1
  7. package/dist/cjs/src/barcodes/index.js +2 -2
  8. package/dist/cjs/src/barcodes/index.js.map +1 -1
  9. package/dist/cjs/src/barcodes/pdfRender.js +3 -3
  10. package/dist/cjs/src/barcodes/pdfRender.js.map +1 -1
  11. package/dist/cjs/src/barcodes/propPanel.js +19 -2
  12. package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
  13. package/dist/cjs/src/barcodes/uiRender.js +9 -32
  14. package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
  15. package/dist/cjs/src/graphics/helper.js +115 -0
  16. package/dist/cjs/src/graphics/helper.js.map +1 -0
  17. package/dist/cjs/src/graphics/image.js +179 -0
  18. package/dist/cjs/src/graphics/image.js.map +1 -0
  19. package/dist/cjs/src/graphics/svg.js +96 -0
  20. package/dist/cjs/src/graphics/svg.js.map +1 -0
  21. package/dist/cjs/src/index.js +42 -11
  22. package/dist/cjs/src/index.js.map +1 -1
  23. package/dist/cjs/src/shapes/line.js +57 -0
  24. package/dist/cjs/src/shapes/line.js.map +1 -0
  25. package/dist/cjs/src/shapes/rectAndEllipse.js +100 -0
  26. package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -0
  27. package/dist/cjs/src/text/helper.js.map +1 -1
  28. package/dist/cjs/src/text/index.js +16 -2
  29. package/dist/cjs/src/text/index.js.map +1 -1
  30. package/dist/cjs/src/text/pdfRender.js +5 -5
  31. package/dist/cjs/src/text/pdfRender.js.map +1 -1
  32. package/dist/cjs/src/text/uiRender.js +3 -3
  33. package/dist/cjs/src/text/uiRender.js.map +1 -1
  34. package/dist/cjs/src/{renderUtils.js → utils.js} +55 -7
  35. package/dist/cjs/src/utils.js.map +1 -0
  36. package/dist/esm/__tests__/{renderUtils.test.js → utils.test.js} +34 -8
  37. package/dist/esm/__tests__/utils.test.js.map +1 -0
  38. package/dist/esm/src/barcodes/constants.js +1 -0
  39. package/dist/esm/src/barcodes/constants.js.map +1 -1
  40. package/dist/esm/src/barcodes/helper.js +2 -3
  41. package/dist/esm/src/barcodes/helper.js.map +1 -1
  42. package/dist/esm/src/barcodes/index.js +2 -2
  43. package/dist/esm/src/barcodes/index.js.map +1 -1
  44. package/dist/esm/src/barcodes/pdfRender.js +2 -2
  45. package/dist/esm/src/barcodes/pdfRender.js.map +1 -1
  46. package/dist/esm/src/barcodes/propPanel.js +20 -3
  47. package/dist/esm/src/barcodes/propPanel.js.map +1 -1
  48. package/dist/esm/src/barcodes/uiRender.js +9 -32
  49. package/dist/esm/src/barcodes/uiRender.js.map +1 -1
  50. package/dist/esm/src/graphics/helper.js +111 -0
  51. package/dist/esm/src/graphics/helper.js.map +1 -0
  52. package/dist/esm/src/graphics/image.js +176 -0
  53. package/dist/esm/src/graphics/image.js.map +1 -0
  54. package/dist/esm/src/graphics/svg.js +93 -0
  55. package/dist/esm/src/graphics/svg.js.map +1 -0
  56. package/dist/esm/src/index.js +7 -5
  57. package/dist/esm/src/index.js.map +1 -1
  58. package/dist/esm/src/shapes/line.js +55 -0
  59. package/dist/esm/src/shapes/line.js.map +1 -0
  60. package/dist/esm/src/shapes/rectAndEllipse.js +97 -0
  61. package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -0
  62. package/dist/esm/src/text/helper.js.map +1 -1
  63. package/dist/esm/src/text/index.js +15 -2
  64. package/dist/esm/src/text/index.js.map +1 -1
  65. package/dist/esm/src/text/pdfRender.js +1 -1
  66. package/dist/esm/src/text/pdfRender.js.map +1 -1
  67. package/dist/esm/src/text/uiRender.js +2 -2
  68. package/dist/esm/src/text/uiRender.js.map +1 -1
  69. package/dist/esm/src/{renderUtils.js → utils.js} +52 -6
  70. package/dist/esm/src/utils.js.map +1 -0
  71. package/dist/types/src/barcodes/constants.d.ts +1 -0
  72. package/dist/types/src/barcodes/helper.d.ts +1 -0
  73. package/dist/types/src/barcodes/index.d.ts +2 -2
  74. package/dist/types/src/barcodes/types.d.ts +1 -0
  75. package/dist/types/src/graphics/helper.d.ts +5 -0
  76. package/dist/types/src/graphics/image.d.ts +7 -0
  77. package/dist/types/src/graphics/svg.d.ts +6 -0
  78. package/dist/types/src/index.d.ts +7 -5
  79. package/dist/types/src/shapes/line.d.ts +6 -0
  80. package/dist/types/src/shapes/rectAndEllipse.d.ts +144 -0
  81. package/dist/types/src/text/index.d.ts +3 -2
  82. package/dist/types/src/text/pdfRender.d.ts +1 -1
  83. package/dist/types/src/{renderUtils.d.ts → utils.d.ts} +3 -1
  84. package/package.json +4 -3
  85. package/src/barcodes/constants.ts +2 -0
  86. package/src/barcodes/helper.ts +12 -3
  87. package/src/barcodes/index.ts +2 -2
  88. package/src/barcodes/pdfRender.ts +2 -2
  89. package/src/barcodes/propPanel.ts +25 -3
  90. package/src/barcodes/types.ts +1 -0
  91. package/src/barcodes/uiRender.ts +9 -36
  92. package/src/graphics/helper.ts +147 -0
  93. package/src/graphics/image.ts +207 -0
  94. package/src/graphics/svg.ts +98 -0
  95. package/src/index.ts +21 -5
  96. package/src/shapes/line.ts +67 -0
  97. package/src/shapes/rectAndEllipse.ts +110 -0
  98. package/src/text/helper.ts +0 -1
  99. package/src/text/index.ts +17 -2
  100. package/src/text/pdfRender.ts +2 -2
  101. package/src/text/uiRender.ts +2 -2
  102. package/src/{renderUtils.ts → utils.ts} +61 -5
  103. package/dist/cjs/__tests__/renderUtils.test.js.map +0 -1
  104. package/dist/cjs/src/image/index.js +0 -8
  105. package/dist/cjs/src/image/index.js.map +0 -1
  106. package/dist/cjs/src/image/pdfRender.js +0 -22
  107. package/dist/cjs/src/image/pdfRender.js.map +0 -1
  108. package/dist/cjs/src/image/propPanel.js +0 -19
  109. package/dist/cjs/src/image/propPanel.js.map +0 -1
  110. package/dist/cjs/src/image/types.js +0 -3
  111. package/dist/cjs/src/image/types.js.map +0 -1
  112. package/dist/cjs/src/image/uiRender.js +0 -111
  113. package/dist/cjs/src/image/uiRender.js.map +0 -1
  114. package/dist/cjs/src/line/constants.js +0 -5
  115. package/dist/cjs/src/line/constants.js.map +0 -1
  116. package/dist/cjs/src/line/index.js +0 -8
  117. package/dist/cjs/src/line/index.js.map +0 -1
  118. package/dist/cjs/src/line/pdfRender.js +0 -20
  119. package/dist/cjs/src/line/pdfRender.js.map +0 -1
  120. package/dist/cjs/src/line/propPanel.js +0 -35
  121. package/dist/cjs/src/line/propPanel.js.map +0 -1
  122. package/dist/cjs/src/line/types.js +0 -3
  123. package/dist/cjs/src/line/types.js.map +0 -1
  124. package/dist/cjs/src/line/uiRender.js +0 -14
  125. package/dist/cjs/src/line/uiRender.js.map +0 -1
  126. package/dist/cjs/src/renderUtils.js.map +0 -1
  127. package/dist/esm/__tests__/renderUtils.test.js.map +0 -1
  128. package/dist/esm/src/image/index.js +0 -6
  129. package/dist/esm/src/image/index.js.map +0 -1
  130. package/dist/esm/src/image/pdfRender.js +0 -18
  131. package/dist/esm/src/image/pdfRender.js.map +0 -1
  132. package/dist/esm/src/image/propPanel.js +0 -16
  133. package/dist/esm/src/image/propPanel.js.map +0 -1
  134. package/dist/esm/src/image/types.js +0 -2
  135. package/dist/esm/src/image/types.js.map +0 -1
  136. package/dist/esm/src/image/uiRender.js +0 -107
  137. package/dist/esm/src/image/uiRender.js.map +0 -1
  138. package/dist/esm/src/line/constants.js +0 -2
  139. package/dist/esm/src/line/constants.js.map +0 -1
  140. package/dist/esm/src/line/index.js +0 -6
  141. package/dist/esm/src/line/index.js.map +0 -1
  142. package/dist/esm/src/line/pdfRender.js +0 -16
  143. package/dist/esm/src/line/pdfRender.js.map +0 -1
  144. package/dist/esm/src/line/propPanel.js +0 -32
  145. package/dist/esm/src/line/propPanel.js.map +0 -1
  146. package/dist/esm/src/line/types.js +0 -2
  147. package/dist/esm/src/line/types.js.map +0 -1
  148. package/dist/esm/src/line/uiRender.js +0 -10
  149. package/dist/esm/src/line/uiRender.js.map +0 -1
  150. package/dist/esm/src/renderUtils.js.map +0 -1
  151. package/dist/types/src/image/index.d.ts +0 -4
  152. package/dist/types/src/image/pdfRender.d.ts +0 -3
  153. package/dist/types/src/image/propPanel.d.ts +0 -3
  154. package/dist/types/src/image/types.d.ts +0 -3
  155. package/dist/types/src/image/uiRender.d.ts +0 -3
  156. package/dist/types/src/line/constants.d.ts +0 -1
  157. package/dist/types/src/line/index.d.ts +0 -4
  158. package/dist/types/src/line/pdfRender.d.ts +0 -3
  159. package/dist/types/src/line/propPanel.d.ts +0 -3
  160. package/dist/types/src/line/types.d.ts +0 -4
  161. package/dist/types/src/line/uiRender.d.ts +0 -3
  162. package/src/image/index.ts +0 -8
  163. package/src/image/pdfRender.ts +0 -29
  164. package/src/image/propPanel.ts +0 -19
  165. package/src/image/types.ts +0 -3
  166. package/src/image/uiRender.ts +0 -121
  167. package/src/line/constants.ts +0 -1
  168. package/src/line/index.ts +0 -8
  169. package/src/line/pdfRender.ts +0 -24
  170. package/src/line/propPanel.ts +0 -34
  171. package/src/line/types.ts +0 -5
  172. package/src/line/uiRender.ts +0 -12
  173. /package/dist/types/__tests__/{renderUtils.test.d.ts → utils.test.d.ts} +0 -0
@@ -0,0 +1,67 @@
1
+ import type { Schema, Plugin, PDFRenderProps, UIRenderProps } from '@pdfme/common';
2
+ import { rotatePoint, convertForPdfLayoutProps, hex2RgbColor } from '../utils.js';
3
+ import { HEX_COLOR_PATTERN } from '../constants.js';
4
+
5
+ const DEFAULT_LINE_COLOR = '#000000';
6
+
7
+ interface LineSchema extends Schema {
8
+ color: string;
9
+ }
10
+
11
+ const lineSchema: Plugin<LineSchema> = {
12
+ pdf: (arg: PDFRenderProps<LineSchema>) => {
13
+ const { page, schema } = arg;
14
+ const pageHeight = page.getHeight();
15
+ const {
16
+ width,
17
+ height,
18
+ rotate,
19
+ position: { x, y },
20
+ opacity,
21
+ } = convertForPdfLayoutProps({ schema, pageHeight, applyRotateTranslate: false });
22
+ const pivot = { x: x + width / 2, y: y + height / 2 };
23
+ page.drawLine({
24
+ start: rotatePoint({ x, y: y + height / 2 }, pivot, rotate.angle),
25
+ end: rotatePoint({ x: x + width, y: y + height / 2 }, pivot, rotate.angle),
26
+ thickness: height,
27
+ color: hex2RgbColor(schema.color ?? DEFAULT_LINE_COLOR),
28
+ opacity: opacity,
29
+ });
30
+ },
31
+ ui: (arg: UIRenderProps<LineSchema>) => {
32
+ const { schema, rootElement } = arg;
33
+ const div = document.createElement('div');
34
+ div.style.backgroundColor = schema.color ?? DEFAULT_LINE_COLOR;
35
+ div.style.width = '100%';
36
+ div.style.height = '100%';
37
+ rootElement.appendChild(div);
38
+ },
39
+ propPanel: {
40
+ schema: ({ i18n }) => ({
41
+ color: {
42
+ title: i18n('schemas.color'),
43
+ type: 'string',
44
+ widget: 'color',
45
+ required: true,
46
+ rules: [
47
+ {
48
+ pattern: HEX_COLOR_PATTERN,
49
+ message: i18n('hexColorPrompt'),
50
+ },
51
+ ],
52
+ },
53
+ }),
54
+ defaultValue: '',
55
+ defaultSchema: {
56
+ type: 'line',
57
+ position: { x: 0, y: 0 },
58
+ width: 50,
59
+ height: 1,
60
+ rotate: 0,
61
+ opacity: 1,
62
+ readOnly: true,
63
+ color: DEFAULT_LINE_COLOR,
64
+ },
65
+ },
66
+ };
67
+ export default lineSchema;
@@ -0,0 +1,110 @@
1
+ import { Plugin, Schema, mm2pt } from '@pdfme/common';
2
+ import { HEX_COLOR_PATTERN } from '../constants.js';
3
+ import { hex2RgbColor, convertForPdfLayoutProps } from '../utils.js';
4
+
5
+ interface Shape extends Schema {
6
+ type: 'ellipse' | 'rectangle';
7
+ borderWidth: number;
8
+ borderColor: string;
9
+ color: string;
10
+ }
11
+
12
+ const shape: Plugin<Shape> = {
13
+ ui: (arg) => {
14
+ const { schema, rootElement } = arg;
15
+ const div = document.createElement('div');
16
+ div.style.width = '100%';
17
+ div.style.height = '100%';
18
+ div.style.boxSizing = 'border-box';
19
+ if (schema.type === 'ellipse') {
20
+ div.style.borderRadius = '50%';
21
+ }
22
+ div.style.borderWidth = `${schema.borderWidth ?? 0}mm`;
23
+ div.style.borderStyle = schema.borderWidth && schema.borderColor ? 'solid' : 'none';
24
+ div.style.borderColor = schema.borderColor ?? 'transparent';
25
+ div.style.backgroundColor = schema.color ?? 'transparent';
26
+
27
+ rootElement.appendChild(div);
28
+ },
29
+ pdf: (arg) => {
30
+ const { schema, page } = arg;
31
+ const pageHeight = page.getHeight();
32
+ const cArg = { schema, pageHeight };
33
+ const { position, width, height, rotate, opacity } = convertForPdfLayoutProps(cArg);
34
+ const {
35
+ position: { x: x4Ellipse, y: y4Ellipse },
36
+ } = convertForPdfLayoutProps({ ...cArg, applyRotateTranslate: false });
37
+ const borderWidth = schema.borderWidth ? mm2pt(schema.borderWidth) : 0;
38
+
39
+ const drawOptions = {
40
+ rotate,
41
+ borderWidth,
42
+ borderColor: hex2RgbColor(schema.borderColor),
43
+ color: hex2RgbColor(schema.color),
44
+ opacity,
45
+ borderOpacity: opacity,
46
+ };
47
+ if (schema.type === 'ellipse') {
48
+ page.drawEllipse({
49
+ x: x4Ellipse + width / 2,
50
+ y: y4Ellipse + height / 2,
51
+ xScale: width / 2 - borderWidth / 2,
52
+ yScale: height / 2 - borderWidth / 2,
53
+ ...drawOptions,
54
+ });
55
+ } else if (schema.type === 'rectangle') {
56
+ page.drawRectangle({
57
+ x: position.x + borderWidth / 2,
58
+ y: position.y + borderWidth / 2,
59
+ width: width - borderWidth,
60
+ height: height - borderWidth,
61
+ ...drawOptions,
62
+ });
63
+ }
64
+ },
65
+ propPanel: {
66
+ schema: ({ i18n }) => ({
67
+ borderWidth: {
68
+ title: i18n('schemas.borderWidth'),
69
+ type: 'number',
70
+ widget: 'inputNumber',
71
+ min: 0,
72
+ step: 1,
73
+ },
74
+ borderColor: {
75
+ title: i18n('schemas.borderColor'),
76
+ type: 'string',
77
+ widget: 'color',
78
+ rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('hexColorPrompt') }],
79
+ },
80
+ color: {
81
+ title: i18n('schemas.color'),
82
+ type: 'string',
83
+ widget: 'color',
84
+ rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('hexColorPrompt') }],
85
+ },
86
+ }),
87
+ defaultValue: '',
88
+ defaultSchema: {
89
+ type: 'rectangle',
90
+ position: { x: 0, y: 0 },
91
+ width: 62.5,
92
+ height: 37.5,
93
+ rotate: 0,
94
+ opacity: 1,
95
+ borderWidth: 5,
96
+ borderColor: '#000000',
97
+ color: '#ffffff',
98
+ readOnly: true,
99
+ },
100
+ },
101
+ };
102
+
103
+ const getPropPanelSchema = (type: 'rectangle' | 'ellipse') => ({
104
+ ...shape.propPanel,
105
+ defaultSchema: { ...shape.propPanel.defaultSchema, type },
106
+ });
107
+
108
+ export const rectangle = { ...shape, propPanel: getPropPanelSchema('rectangle') };
109
+
110
+ export const ellipse = { ...shape, propPanel: getPropPanelSchema('ellipse') };
@@ -5,7 +5,6 @@ import {
5
5
  mm2pt,
6
6
  pt2mm,
7
7
  pt2px,
8
- Schema,
9
8
  Font,
10
9
  getFallbackFontName,
11
10
  getDefaultFont,
package/src/text/index.ts CHANGED
@@ -4,5 +4,20 @@ import { propPanel } from './propPanel.js';
4
4
  import { uiRender } from './uiRender.js';
5
5
  import type { TextSchema } from './types';
6
6
 
7
- const schema: Plugin<TextSchema> = { pdf: pdfRender, ui: uiRender, propPanel };
8
- export default schema;
7
+ const textSchema: Plugin<TextSchema> = { pdf: pdfRender, ui: uiRender, propPanel };
8
+
9
+ export default textSchema;
10
+
11
+ export const readOnlyText: Plugin<TextSchema> = {
12
+ pdf: textSchema.pdf,
13
+ ui: textSchema.ui,
14
+ propPanel: {
15
+ ...textSchema.propPanel,
16
+ defaultSchema: {
17
+ ...textSchema.propPanel.defaultSchema,
18
+ type: 'readOnlyText',
19
+ readOnly: true,
20
+ readOnlyValue: textSchema.propPanel.defaultValue,
21
+ },
22
+ },
23
+ };
@@ -1,6 +1,6 @@
1
1
  import { PDFFont, PDFDocument } from '@pdfme/pdf-lib';
2
- import { PDFRenderProps, Font, getDefaultFont, getFallbackFontName, mm2pt } from '@pdfme/common';
3
2
  import type { TextSchema, FontWidthCalcValues } from './types';
3
+ import { PDFRenderProps, Font, getDefaultFont, getFallbackFontName, mm2pt } from '@pdfme/common';
4
4
  import {
5
5
  VERTICAL_ALIGN_TOP,
6
6
  VERTICAL_ALIGN_MIDDLE,
@@ -20,7 +20,7 @@ import {
20
20
  getSplittedLines,
21
21
  widthOfTextAtSize,
22
22
  } from './helper.js';
23
- import { convertForPdfLayoutProps, rotatePoint, hex2RgbColor } from '../renderUtils.js';
23
+ import { convertForPdfLayoutProps, rotatePoint, hex2RgbColor } from '../utils.js';
24
24
 
25
25
  const embedAndGetFontObj = async (arg: {
26
26
  pdfDoc: PDFDocument;
@@ -18,7 +18,7 @@ import {
18
18
  getFontKitFont,
19
19
  getBrowserVerticalFontAdjustments,
20
20
  } from './helper.js';
21
- import { addAlphaToHex, isEditable } from '../renderUtils.js';
21
+ import { addAlphaToHex, isEditable } from '../utils.js';
22
22
 
23
23
  const mapVerticalAlignToFlex = (verticalAlignmentValue: string | undefined) => {
24
24
  switch (verticalAlignmentValue) {
@@ -117,7 +117,7 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
117
117
  const textBlock = document.createElement('div');
118
118
  Object.assign(textBlock.style, textBlockStyle);
119
119
 
120
- if (isEditable(mode)) {
120
+ if (isEditable(mode, schema)) {
121
121
  textBlock.contentEditable = 'plaintext-only';
122
122
  textBlock.tabIndex = tabIndex || 0;
123
123
  textBlock.innerText = value;
@@ -1,3 +1,4 @@
1
+ import type * as CSS from 'csstype';
1
2
  import { degrees, degreesToRadians, rgb } from '@pdfme/pdf-lib';
2
3
  import { Schema, mm2pt, Mode, isHexValid } from '@pdfme/common';
3
4
 
@@ -32,10 +33,7 @@ export const convertForPdfLayoutProps = ({
32
33
  }
33
34
 
34
35
  return {
35
- position: {
36
- x: x,
37
- y: y,
38
- },
36
+ position: { x, y },
39
37
  height: height,
40
38
  width: width,
41
39
  rotate: degrees(rotateDegrees),
@@ -72,7 +70,8 @@ export const addAlphaToHex = (hex: string, alphaPercentage: number) => {
72
70
  return hex + alphaHex;
73
71
  };
74
72
 
75
- export const isEditable = (mode: Mode) => mode === 'form' || mode === 'designer';
73
+ export const isEditable = (mode: Mode, schema: Schema) =>
74
+ mode === 'designer' || (mode === 'form' && schema.readOnly !== true);
76
75
 
77
76
  const hex2rgb = (hex: string) => {
78
77
  if (hex.slice(0, 1) === '#') hex = hex.slice(1);
@@ -103,3 +102,60 @@ export const hex2RgbColor = (hexString: string | undefined) => {
103
102
 
104
103
  return undefined;
105
104
  };
105
+
106
+ export const readFile = (input: File | FileList | null): Promise<string | ArrayBuffer> =>
107
+ new Promise((resolve, reject) => {
108
+ const fileReader = new FileReader();
109
+
110
+ fileReader.onload = (e) => {
111
+ if (e.target?.result) {
112
+ resolve(e.target.result);
113
+ }
114
+ };
115
+
116
+ fileReader.onerror = (e) => {
117
+ reject(new Error('[@pdfme/schemas] File reading failed'));
118
+ };
119
+
120
+ let file: File | null = null;
121
+ if (input instanceof FileList && input.length > 0) {
122
+ file = input[0];
123
+ } else if (input instanceof File) {
124
+ file = input;
125
+ }
126
+
127
+ if (file) {
128
+ fileReader.readAsDataURL(file);
129
+ } else {
130
+ reject(new Error('[@pdfme/schemas] No files provided'));
131
+ }
132
+ });
133
+
134
+ export const createErrorElm = () => {
135
+ const container = document.createElement('div');
136
+ const containerStyle: CSS.Properties = {
137
+ display: 'flex',
138
+ alignItems: 'center',
139
+ justifyContent: 'center',
140
+ width: '100%',
141
+ height: '100%',
142
+ };
143
+ Object.assign(container.style, containerStyle);
144
+
145
+ const span = document.createElement('span');
146
+ const spanStyle: CSS.Properties = {
147
+ color: 'white',
148
+ background: 'red',
149
+ padding: '0.25rem',
150
+ fontSize: '12pt',
151
+ fontWeight: 'bold',
152
+ borderRadius: '2px',
153
+ fontFamily: "'Open Sans', sans-serif",
154
+ };
155
+ Object.assign(span.style, spanStyle);
156
+
157
+ span.textContent = 'ERROR';
158
+ container.appendChild(span);
159
+
160
+ return container;
161
+ };
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderUtils.test.js","sourceRoot":"","sources":["../../../__tests__/renderUtils.test.ts"],"names":[],"mappings":";;AAAA,0CAAqD;AACrD,oDAA2E;AAE3E,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,MAAM,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,EAAE,CAAC;QAEjB,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,IAAA,yBAAW,EAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAClD,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QAC7B,MAAM,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object.defineProperty(exports, "__esModule", { value: true });
3
- const pdfRender_js_1 = require("./pdfRender.js");
4
- const propPanel_js_1 = require("./propPanel.js");
5
- const uiRender_js_1 = require("./uiRender.js");
6
- const schema = { pdf: pdfRender_js_1.pdfRender, ui: uiRender_js_1.uiRender, propPanel: propPanel_js_1.propPanel };
7
- exports.default = schema;
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/image/index.ts"],"names":[],"mappings":";;AACA,iDAA2C;AAC3C,iDAA2C;AAC3C,+CAAyC;AAGzC,MAAM,MAAM,GAAwB,EAAE,GAAG,EAAE,wBAAS,EAAE,EAAE,EAAE,sBAAQ,EAAE,SAAS,EAAT,wBAAS,EAAE,CAAC;AAChF,kBAAe,MAAM,CAAC"}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pdfRender = void 0;
4
- const renderUtils_js_1 = require("../renderUtils.js");
5
- const getCacheKey = (schema, input) => `${schema.type}${input}`;
6
- const pdfRender = async (arg) => {
7
- const { value, schema, pdfDoc, page, _cache } = arg;
8
- if (!value || !value.startsWith('data:image/'))
9
- return;
10
- const inputImageCacheKey = getCacheKey(schema, value);
11
- let image = _cache.get(inputImageCacheKey);
12
- if (!image) {
13
- const isPng = value.startsWith('data:image/png;');
14
- image = await (isPng ? pdfDoc.embedPng(value) : pdfDoc.embedJpg(value));
15
- _cache.set(inputImageCacheKey, image);
16
- }
17
- const pageHeight = page.getHeight();
18
- const { width, height, rotate, position: { x, y }, opacity, } = (0, renderUtils_js_1.convertForPdfLayoutProps)({ schema, pageHeight });
19
- page.drawImage(image, { x, y, rotate, width, height, opacity });
20
- };
21
- exports.pdfRender = pdfRender;
22
- //# sourceMappingURL=pdfRender.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pdfRender.js","sourceRoot":"","sources":["../../../../src/image/pdfRender.ts"],"names":[],"mappings":";;;AAEA,s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B"}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propPanel = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- exports.propPanel = {
6
- schema: {},
7
- defaultValue: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAu4AAALuAQMAAADL0wGJAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAGUExURbzAw+rv8fKruy0AAAPoSURBVHja7dwxbtwwEEBRCkKwRQodYftcYk+ROkcJz5NTsEuZK/AIKlIQAUEnke0VqQ0pA5zxWvFnZcD2s0CNuENxPOZBc0QDDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PD/+P8bkxvnTzzjTG0M2b5rh08rHNT518aPOnTt63+aGTd23edPJ2h//ax+/oO6Gzx6c78+cuPu7x01vmwx5/6uLnO/PjO+b/rGifvtWH3VnT9vmh/e3eqx/bc9d79af2YwEPDw8P/6r8r1GVt5VcUoZPtXxGhp9rGYEM72vbEBne1hJ5Gb6ayIvwqZppi/CxmgqL8KGaTIrwc3WDfATeV/ffIryr7r+PwNvq/vsIfH17D5/qbw/gb/mLKp/OqnycFPj14yqcJPm4vfp5VJ0cP6jyzqjy9rr2q/Dr4qzBp3V5E1wxp/V3rl8LXn32qF6fAY31Psv2NXi/5lQaH+Vuzak0eLsmPRppVPa3FPiU3QiFFDZmD4FCAh6yxV+Bn7O9isLmx2d/TGHr5rI7obDxtFkcKWyb89M2+U1/sX7Kv7Io8gaxFy5l2D/faRk++3x6PgsalV52+fwUW4j/+eGhDPuneyH/otHmp9jyfHHMLM6n4phZnI/FObA4H4qDWnF+Lo46xXlflG+I864o3xDnbVG+Ic6X9RXSfCrrK6T5WBZASPOhrFCQ5ufyjF+a92XdkjTvyrolad6WdUvS/KawSI7/sQn7JfDl+O+bsF8CX44fN2FvHnNnIT4Nm7BfAl+ON5uwXwJfjA/LCuk2BXvCvN0U7InxflmAtxV1gvx0U2N3luPtdZOlwj/FoR5vbuq85Pi48F6LD0scOk3+sq1cleP9ohlNfkpq/N9pGaMuH7T4ZVqGWYt/nBavyxstftblfaVIWJU/y72yODCfzJH5oMvPh+adLm+PzCdzZD5U/61ClT9Lnvyo8e7QvFHlE3ydj0zOu5ucickhcpgcJofJedUVk8j5b/nGgIeHh4d/I3x/RwLlhgfNH3DavSwGXf7YjT76uqCEQ/P37p9z7uKVmwspd17S7hul3PXK6fbsmnvWhO6GZlMnn3ri8gXN5GzHnX0B35ydj91814CHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHl+d/A9cKjmiL040TAAAAAElFTkSuQmCC',
8
- defaultSchema: {
9
- type: 'image',
10
- position: { x: 0, y: 0 },
11
- width: 40,
12
- height: 40,
13
- // If the value of "rotate" is set to undefined or not set at all, rotation will be disabled in the UI.
14
- // Check this document: https://pdfme.com//docs/custom-schemas#learning-how-to-create-from-pdfmeschemas-code
15
- rotate: 0,
16
- opacity: constants_js_1.DEFAULT_OPACITY,
17
- },
18
- };
19
- //# sourceMappingURL=propPanel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"propPanel.js","sourceRoot":"","sources":["../../../../src/image/propPanel.ts"],"names":[],"mappings":";;;AAEA,kDAAkD;AAErC,QAAA,SAAS,GAA2B;IAC/C,MAAM,EAAE,EAAE;IACV,YAAY,EACV,w9CAAw9C;IAC19C,aAAa,EAAE;QACb,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;QACxB,KAAK,EAAE,EAAE;QACT,MAAM,EAAE,EAAE;QACV,uGAAuG;QACvG,4GAA4G;QAC5G,MAAM,EAAE,CAAC;QACT,OAAO,EAAE,8BAAe;KACzB;CACF,CAAC"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/image/types.ts"],"names":[],"mappings":""}
@@ -1,111 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uiRender = void 0;
4
- const common_1 = require("@pdfme/common");
5
- const renderUtils_js_1 = require("../renderUtils.js");
6
- const fullSize = { width: '100%', height: '100%' };
7
- const readFile = (input) => new Promise((resolve, reject) => {
8
- const fileReader = new FileReader();
9
- fileReader.onload = (e) => {
10
- if (e.target?.result) {
11
- resolve(e.target.result);
12
- }
13
- };
14
- fileReader.onerror = (e) => {
15
- reject(new Error('[@pdfme/schemas] File reading failed'));
16
- };
17
- let file = null;
18
- if (input instanceof FileList && input.length > 0) {
19
- file = input[0];
20
- }
21
- else if (input instanceof File) {
22
- file = input;
23
- }
24
- if (file) {
25
- fileReader.readAsDataURL(file);
26
- }
27
- else {
28
- reject(new Error('[@pdfme/schemas] No files provided'));
29
- }
30
- });
31
- const uiRender = async (arg) => {
32
- const { value, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, schema, theme } = arg;
33
- const editable = (0, renderUtils_js_1.isEditable)(mode);
34
- const size = { width: schema.width * common_1.ZOOM, height: schema.height * common_1.ZOOM };
35
- const container = document.createElement('div');
36
- const backgroundStyle = placeholder ? `url(${placeholder})` : 'none';
37
- const containerStyle = {
38
- ...fullSize,
39
- backgroundImage: value ? 'none' : backgroundStyle,
40
- backgroundSize: `${size.width}px ${size.height}px`,
41
- };
42
- Object.assign(container.style, containerStyle);
43
- container.addEventListener('click', (e) => {
44
- if (editable) {
45
- e.stopPropagation();
46
- }
47
- });
48
- rootElement.appendChild(container);
49
- // image tag
50
- if (value) {
51
- const img = document.createElement('img');
52
- const imgStyle = { height: '100%', width: '100%', borderRadius: 0 };
53
- Object.assign(img.style, imgStyle);
54
- img.src = value;
55
- container.appendChild(img);
56
- }
57
- // remove button
58
- if (value && editable) {
59
- const button = document.createElement('button');
60
- button.textContent = 'x';
61
- const buttonStyle = {
62
- position: 'absolute',
63
- top: 0,
64
- left: 0,
65
- zIndex: 1,
66
- display: 'flex',
67
- justifyContent: 'center',
68
- alignItems: 'center',
69
- color: '#333',
70
- background: '#f2f2f2',
71
- borderRadius: '2px',
72
- border: '1px solid #767676',
73
- cursor: 'pointer',
74
- height: '24px',
75
- width: '24px',
76
- };
77
- Object.assign(button.style, buttonStyle);
78
- button.addEventListener('click', () => {
79
- onChange && onChange('');
80
- });
81
- container.appendChild(button);
82
- }
83
- // file input
84
- if (!value && editable) {
85
- const label = document.createElement('label');
86
- const labelStyle = {
87
- ...fullSize,
88
- display: editable ? 'flex' : 'none',
89
- position: 'absolute',
90
- top: 0,
91
- backgroundColor: editable || value ? (0, renderUtils_js_1.addAlphaToHex)(theme.colorPrimaryBg, 30) : 'none',
92
- cursor: 'pointer',
93
- };
94
- Object.assign(label.style, labelStyle);
95
- container.appendChild(label);
96
- const input = document.createElement('input');
97
- const inputStyle = { ...fullSize, position: 'absolute', top: '50%' };
98
- Object.assign(input.style, inputStyle);
99
- input.tabIndex = tabIndex || 0;
100
- input.type = 'file';
101
- input.accept = 'image/jpeg, image/png';
102
- input.addEventListener('change', (event) => {
103
- const changeEvent = event;
104
- readFile(changeEvent.target.files).then((result) => onChange && onChange(result));
105
- });
106
- input.addEventListener('blur', () => stopEditing && stopEditing());
107
- label.appendChild(input);
108
- }
109
- };
110
- exports.uiRender = uiRender;
111
- //# sourceMappingURL=uiRender.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uiRender.js","sourceRoot":"","sources":["../../../../src/image/uiRender.ts"],"names":[],"mappings":";;;AAGA,0CAAoD;AACpD,sDAA8D;AAE9D,MAAM,QAA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AU,CAAC,CAAC;QACvC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC7B,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,UAAU,GAAmB,EAAE,GAAG,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;QACrF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QACvC,KAAK,CAAC,QAAQ,GAAG,QAAQ,IAAI,CAAC,CAAC;QAC/B,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC;QACpB,KAAK,CAAC,MAAM,GAAG,uBAAuB,CAAC;QACvC,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,KAAY,EAAE,EAAE;YAChD,MAAM,WAAW,GAAG,KAAiD,CAAC;YACtE,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAgB,CAAC,CAAC,CAAC;QAC9F,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,WAAW,IAAI,WAAW,EAAE,CAAC,CAAC;QACnE,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;KAC1B;AACH,CAAC,CAAC;AApFW,QAAA,QAAQ,YAoFnB"}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_LINE_COLOR = void 0;
4
- exports.DEFAULT_LINE_COLOR = '#000000';
5
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/line/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,kBAAkB,GAAG,SAAS,CAAC"}
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const pdfRender_js_1 = require("./pdfRender.js");
4
- const propPanel_js_1 = require("./propPanel.js");
5
- const uiRender_js_1 = require("./uiRender.js");
6
- const schema = { pdf: pdfRender_js_1.pdfRender, ui: uiRender_js_1.uiRender, propPanel: propPanel_js_1.propPanel };
7
- exports.default = schema;
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/line/index.ts"],"names":[],"mappings":";;AACA,iDAA2C;AAC3C,iDAA2C;AAC3C,+CAAyC;AAGzC,MAAM,MAAM,GAAuB,EAAE,GAAG,EAAE,wBAAS,EAAE,EAAE,EAAE,sBAAQ,EAAE,SAAS,EAAT,wBAAS,EAAE,CAAC;AAC/E,kBAAe,MAAM,CAAC"}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pdfRender = void 0;
4
- const renderUtils_js_1 = require("../renderUtils.js");
5
- const constants_js_1 = require("./constants.js");
6
- const pdfRender = (arg) => {
7
- const { page, schema } = arg;
8
- const pageHeight = page.getHeight();
9
- const { width, height, rotate, position: { x, y }, opacity, } = (0, renderUtils_js_1.convertForPdfLayoutProps)({ schema, pageHeight, applyRotateTranslate: false });
10
- const pivot = { x: x + width / 2, y: y + height / 2 };
11
- page.drawLine({
12
- start: (0, renderUtils_js_1.rotatePoint)({ x, y: y + height / 2 }, pivot, rotate.angle),
13
- end: (0, renderUtils_js_1.rotatePoint)({ x: x + width, y: y + height / 2 }, pivot, rotate.angle),
14
- thickness: height,
15
- color: (0, renderUtils_js_1.hex2RgbColor)(schema.color ?? constants_js_1.DEFAULT_LINE_COLOR),
16
- opacity: opacity,
17
- });
18
- };
19
- exports.pdfRender = pdfRender;
20
- //# sourceMappingURL=pdfRender.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pdfRender.js","sourceRoot":"","sources":["../../../../src/line/pdfRender.ts"],"names":[],"mappings":";;;AAEA,sDAAwF;AACxF,iDAAoD;AAE7C,MAAM,SAAS,GAAG,CAAC,GAA+B,EAAE,EAAE;IAC3D,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAC7B,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IACpC,MAAM,EACJ,KAAK,EACL,MAAM,EACN,MAAM,EACN,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAClB,OAAO,GACR,GAAG,IAAA,yCAAwB,EAAC,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC;IAClF,MAAM,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC;IACtD,IAAI,CAAC,QAAQ,CAAC;QACZ,KAAK,EAAE,IAAA,4BAAW,EAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;QACjE,GAAG,EAAE,IAAA,4BAAW,EAAC,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;QAC1E,SAAS,EAAE,MAAM;QACjB,KAAK,EAAE,IAAA,6BAAY,EAAC,MAAM,CAAC,KAAK,IAAI,iCAAkB,CAAC;QACvD,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;AACL,CAAC,CAAC;AAlBW,QAAA,SAAS,aAkBpB"}
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propPanel = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- const constants_js_2 = require("./constants.js");
6
- exports.propPanel = {
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: constants_js_1.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: constants_js_2.DEFAULT_LINE_COLOR,
33
- },
34
- };
35
- //# sourceMappingURL=propPanel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"propPanel.js","sourceRoot":"","sources":["../../../../src/line/propPanel.ts"],"names":[],"mappings":";;;AAEA,kDAAoD;AACpD,iDAAoD;AAEvC,QAAA,SAAS,GAA0B;IAC9C,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;QACnB,OAAO;YACL,KAAK,EAAE;gBACL,KAAK,EAAE,IAAI,CAAC,oBAAoB,CAAC;gBACjC,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,OAAO;gBACf,QAAQ,EAAE,IAAI;gBACd,KAAK,EAAE;oBACL;wBACE,OAAO,EAAE,gCAAiB;wBAC1B,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC;qBAChC;iBACF;aACF;SACF,CAAC;IACJ,CAAC;IACD,YAAY,EAAE,EAAE;IAChB,aAAa,EAAE;QACb,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;QACxB,KAAK,EAAE,EAAE;QACT,MAAM,EAAE,CAAC;QACT,MAAM,EAAE,CAAC;QACT,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,iCAAkB;KAC1B;CACF,CAAC"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/line/types.ts"],"names":[],"mappings":""}