@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,111 @@
1
+ const decoder = new TextDecoder();
2
+ const toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end));
3
+ const toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + ('0' + i.toString(16)).slice(-2), '');
4
+ const readUInt16BE = (input, offset = 0) => input[offset] * 2 ** 8 + input[offset + 1];
5
+ const readUInt32BE = (input, offset = 0) => input[offset] * 2 ** 24 +
6
+ input[offset + 1] * 2 ** 16 +
7
+ input[offset + 2] * 2 ** 8 +
8
+ input[offset + 3];
9
+ const extractSize = (input, index) => {
10
+ return {
11
+ height: readUInt16BE(input, index),
12
+ width: readUInt16BE(input, index + 2),
13
+ };
14
+ };
15
+ const validateInput = (input, index) => {
16
+ // index should be within buffer limits
17
+ if (index > input.length) {
18
+ throw new TypeError('Corrupt JPG, exceeded buffer limits');
19
+ }
20
+ // Every JPEG block must begin with a 0xFF
21
+ if (input[index] !== 0xff) {
22
+ throw new TypeError('Invalid JPG, marker table corrupted');
23
+ }
24
+ };
25
+ const JPG = {
26
+ validate: (input) => toHexString(input, 0, 2) === 'ffd8',
27
+ calculate(input) {
28
+ // Skip 4 chars, they are for signature
29
+ input = input.slice(4);
30
+ let next;
31
+ while (input.length) {
32
+ // read length of the next block
33
+ const i = readUInt16BE(input, 0);
34
+ // ensure correct format
35
+ validateInput(input, i);
36
+ // 0xFFC0 is baseline standard(SOF)
37
+ // 0xFFC1 is baseline optimized(SOF)
38
+ // 0xFFC2 is progressive(SOF2)
39
+ next = input[i + 1];
40
+ if (next === 0xc0 || next === 0xc1 || next === 0xc2) {
41
+ const size = extractSize(input, i + 5);
42
+ return size;
43
+ }
44
+ // move to the next block
45
+ input = input.slice(i + 2);
46
+ }
47
+ throw new TypeError('Invalid JPG, no size found');
48
+ },
49
+ };
50
+ const pngSignature = 'PNG\r\n\x1a\n';
51
+ const pngImageHeaderChunkName = 'IHDR';
52
+ // Used to detect "fried" png's: http://www.jongware.com/pngdefry.html
53
+ const pngFriedChunkName = 'CgBI';
54
+ const PNG = {
55
+ validate(input) {
56
+ if (pngSignature === toUTF8String(input, 1, 8)) {
57
+ let chunkName = toUTF8String(input, 12, 16);
58
+ if (chunkName === pngFriedChunkName) {
59
+ chunkName = toUTF8String(input, 28, 32);
60
+ }
61
+ if (chunkName !== pngImageHeaderChunkName) {
62
+ throw new TypeError('Invalid PNG');
63
+ }
64
+ return true;
65
+ }
66
+ return false;
67
+ },
68
+ calculate(input) {
69
+ if (toUTF8String(input, 12, 16) === pngFriedChunkName) {
70
+ return {
71
+ height: readUInt32BE(input, 36),
72
+ width: readUInt32BE(input, 32),
73
+ };
74
+ }
75
+ return {
76
+ height: readUInt32BE(input, 20),
77
+ width: readUInt32BE(input, 16),
78
+ };
79
+ },
80
+ };
81
+ const typeHandlers = {
82
+ jpg: JPG,
83
+ png: PNG,
84
+ };
85
+ function detector(input) {
86
+ const firstBytes = {
87
+ 0x89: 'png',
88
+ 0xff: 'jpg',
89
+ };
90
+ const byte = input[0];
91
+ if (byte in firstBytes) {
92
+ const type = firstBytes[byte];
93
+ if (type && typeHandlers[type].validate(input)) {
94
+ return type;
95
+ }
96
+ }
97
+ const keys = Object.keys(typeHandlers);
98
+ return keys.find((key) => typeHandlers[key].validate(input));
99
+ }
100
+ export const imageSize = (imgBuffer) => {
101
+ const type = detector(imgBuffer);
102
+ if (typeof type !== 'undefined' && type in typeHandlers) {
103
+ const size = typeHandlers[type].calculate(imgBuffer);
104
+ if (size !== undefined) {
105
+ return size;
106
+ }
107
+ }
108
+ throw new TypeError('[@pdfme/schemas/images] Unsupported file type: ' + (type === undefined ? 'undefined' : type));
109
+ };
110
+ // ----------------------------
111
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../src/graphics/helper.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,YAAY,GAAG,CAAC,KAAiB,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CACxE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AAE1C,MAAM,WAAW,GAAG,CAAC,KAAiB,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,MAA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,MAAM,CAAC,IAAI,CAAC,YAAY,CAAgB,CAAC;IACtD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAc,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,SAAiB,EAAqC,EAAE;IAChF,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IAEjC,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,IAAI,YAAY,EAAE;QACvD,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QACrD,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO,IAAI,CAAC;SACb;KACF;IAED,MAAM,IAAI,SAAS,CACjB,iDAAiD,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAC9F,CAAC;AACJ,CAAC,CAAC;AACF,+BAA+B"}
@@ -0,0 +1,176 @@
1
+ import { Buffer } from 'buffer';
2
+ import { convertForPdfLayoutProps, addAlphaToHex, isEditable, readFile } from '../utils.js';
3
+ import { DEFAULT_OPACITY } from '../constants.js';
4
+ import { imageSize } from './helper.js';
5
+ const px2mm = (px) => {
6
+ // http://www.endmemo.com/sconvert/millimeterpixel.php
7
+ const ratio = 0.26458333333333;
8
+ return parseFloat(String(px)) * ratio;
9
+ };
10
+ const getCacheKey = (schema, input) => `${schema.type}${input}`;
11
+ const fullSize = { width: '100%', height: '100%' };
12
+ const defaultValue = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUgAAAGQBAMAAAA+V+RCAAAAAXNSR0IArs4c6QAAABtQTFRFAAAAR3BMAAAAAAAAAAAAAAAAAAAAAAAAAAAAqmQqwQAAAAh0Uk5TDQAvVYGtxusE1uR9AAAKg0l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xYitzchOjkrDLR6cZWCYMrIiXc7zoUnj3nX1s8ZUTbqc5eWhMeLpoibvkdJmemBejSPVeIn6V4ssr0nXo7QzNCxp+th4KVKEQXkmRvLQcaxcANKPXTO+eICkgWvIW0JkEDsWyB4hkgbuBRKRQexcIBFJA/cCichg5o5x7VUg6SCzTMN0YYikiSvIL1SNDGLnRg0i6ch2g2PeNUTSmQvIBwIknAtZLXgWiEgKY+sdckTfQ9J+Yte4eUOIhHJkQ4mJABGJSvvGeiT1F7aMyzH9KJL2biyN6zdUjUTlr6l54vZDj+qQWPrXmWEi5KUEJBa//26RGRMuP449+jEkprV8TLPGgenjx8uomkj0N73+g6V/XjknAAAAAElFTkSuQmCC';
13
+ const imageSchema = {
14
+ pdf: async (arg) => {
15
+ const { value, schema, pdfDoc, page, _cache } = arg;
16
+ if (!value || !value.startsWith('data:image/'))
17
+ return;
18
+ const inputImageCacheKey = getCacheKey(schema, value);
19
+ let image = _cache.get(inputImageCacheKey);
20
+ if (!image) {
21
+ const isPng = value.startsWith('data:image/png;');
22
+ image = await (isPng ? pdfDoc.embedPng(value) : pdfDoc.embedJpg(value));
23
+ _cache.set(inputImageCacheKey, image);
24
+ }
25
+ const _schema = { ...schema, position: { ...schema.position } };
26
+ const dataUriPrefix = ';base64,';
27
+ const idx = value.indexOf(dataUriPrefix);
28
+ const imgBase64 = value.substring(idx + dataUriPrefix.length, value.length);
29
+ const dimension = imageSize(Buffer.from(imgBase64, 'base64'));
30
+ const imageWidth = px2mm(dimension.width);
31
+ const imageHeight = px2mm(dimension.height);
32
+ const boxWidth = _schema.width;
33
+ const boxHeight = _schema.height;
34
+ const imageRatio = imageWidth / imageHeight;
35
+ const boxRatio = boxWidth / boxHeight;
36
+ if (imageRatio > boxRatio) {
37
+ _schema.width = boxWidth;
38
+ _schema.height = boxWidth / imageRatio;
39
+ _schema.position.y += (boxHeight - _schema.height) / 2;
40
+ }
41
+ else {
42
+ _schema.width = boxHeight * imageRatio;
43
+ _schema.height = boxHeight;
44
+ _schema.position.x += (boxWidth - _schema.width) / 2;
45
+ }
46
+ const pageHeight = page.getHeight();
47
+ const lProps = convertForPdfLayoutProps({ schema: _schema, pageHeight });
48
+ const { width, height, rotate, position, opacity } = lProps;
49
+ const { x, y } = position;
50
+ page.drawImage(image, { x, y, rotate, width, height, opacity });
51
+ },
52
+ ui: (arg) => {
53
+ const { value, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, theme, schema, } = arg;
54
+ const editable = isEditable(mode, schema);
55
+ const isDefault = value === defaultValue;
56
+ const container = document.createElement('div');
57
+ const backgroundStyle = placeholder ? `url(${placeholder})` : 'none';
58
+ const containerStyle = {
59
+ ...fullSize,
60
+ backgroundImage: value ? 'none' : backgroundStyle,
61
+ backgroundSize: `contain`,
62
+ backgroundRepeat: 'no-repeat',
63
+ backgroundPosition: 'center',
64
+ };
65
+ Object.assign(container.style, containerStyle);
66
+ container.addEventListener('click', (e) => {
67
+ if (editable) {
68
+ e.stopPropagation();
69
+ }
70
+ });
71
+ rootElement.appendChild(container);
72
+ // image tag
73
+ if (value) {
74
+ const img = document.createElement('img');
75
+ const imgStyle = {
76
+ height: '100%',
77
+ width: '100%',
78
+ borderRadius: 0,
79
+ objectFit: 'contain',
80
+ };
81
+ Object.assign(img.style, imgStyle);
82
+ img.src = value;
83
+ container.appendChild(img);
84
+ }
85
+ // remove button
86
+ if (value && !isDefault && editable) {
87
+ const button = document.createElement('button');
88
+ button.textContent = 'x';
89
+ const buttonStyle = {
90
+ position: 'absolute',
91
+ top: 0,
92
+ left: 0,
93
+ zIndex: 1,
94
+ display: 'flex',
95
+ justifyContent: 'center',
96
+ alignItems: 'center',
97
+ color: '#333',
98
+ background: '#f2f2f2',
99
+ borderRadius: '2px',
100
+ border: '1px solid #767676',
101
+ cursor: 'pointer',
102
+ height: '24px',
103
+ width: '24px',
104
+ };
105
+ Object.assign(button.style, buttonStyle);
106
+ button.addEventListener('click', () => {
107
+ onChange && onChange('');
108
+ });
109
+ container.appendChild(button);
110
+ }
111
+ // file input
112
+ if ((!value || isDefault) && editable) {
113
+ const label = document.createElement('label');
114
+ const labelStyle = {
115
+ ...fullSize,
116
+ display: editable ? 'flex' : 'none',
117
+ position: 'absolute',
118
+ top: 0,
119
+ backgroundColor: editable || value ? addAlphaToHex(theme.colorPrimaryBg, 30) : 'none',
120
+ cursor: 'pointer',
121
+ };
122
+ Object.assign(label.style, labelStyle);
123
+ container.appendChild(label);
124
+ const input = document.createElement('input');
125
+ const inputStyle = {
126
+ ...fullSize,
127
+ position: 'absolute',
128
+ top: '50%',
129
+ left: '50%',
130
+ width: '180px',
131
+ height: '30px',
132
+ marginLeft: '-90px',
133
+ marginTop: '-15px',
134
+ };
135
+ Object.assign(input.style, inputStyle);
136
+ input.tabIndex = tabIndex || 0;
137
+ input.type = 'file';
138
+ input.accept = 'image/jpeg, image/png';
139
+ input.addEventListener('change', (event) => {
140
+ const changeEvent = event;
141
+ readFile(changeEvent.target.files).then((result) => onChange && onChange(result));
142
+ });
143
+ input.addEventListener('blur', () => stopEditing && stopEditing());
144
+ label.appendChild(input);
145
+ }
146
+ },
147
+ propPanel: {
148
+ schema: {},
149
+ defaultValue,
150
+ defaultSchema: {
151
+ type: 'image',
152
+ position: { x: 0, y: 0 },
153
+ width: 40,
154
+ height: 40,
155
+ // If the value of "rotate" is set to undefined or not set at all, rotation will be disabled in the UI.
156
+ // Check this document: https://pdfme.com//docs/custom-schemas#learning-how-to-create-from-pdfmeschemas-code
157
+ rotate: 0,
158
+ opacity: DEFAULT_OPACITY,
159
+ },
160
+ },
161
+ };
162
+ export default imageSchema;
163
+ export const readOnlyImage = {
164
+ pdf: imageSchema.pdf,
165
+ ui: imageSchema.ui,
166
+ propPanel: {
167
+ ...imageSchema.propPanel,
168
+ defaultSchema: {
169
+ ...imageSchema.propPanel.defaultSchema,
170
+ type: 'readOnlyImage',
171
+ readOnly: true,
172
+ readOnlyValue: defaultValue,
173
+ },
174
+ },
175
+ };
176
+ //# sourceMappingURL=image.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C,SAAS;QACxB,aAAa,EAAE;YACb,GAAG,WAAW,CAAC,SAAS,CAAC,aAAa;YACtC,IAAI,EAAE,eAAe;YACrB,QAAQ,EAAE,IAAI;YACd,aAAa,EAAE,YAAY;SAC5B;KACF;CACF,CAAC"}
@@ -0,0 +1,93 @@
1
+ import { XMLValidator } from 'fast-xml-parser';
2
+ import { convertForPdfLayoutProps, isEditable, addAlphaToHex, createErrorElm } from '../utils.js';
3
+ const isValidSVG = (svgString) => XMLValidator.validate(svgString) === true;
4
+ const defaultValue = `<svg viewBox="0 0 488 600" version="1.1" xmlns="http://www.w3.org/2000/svg">
5
+ <g transform="matrix(1,0,0,1,-56,0)" fill="#000000" stroke="none">
6
+ <path d="M228.667,0L56,172.667L56.267,345.334L56.667,518L59.733,527.334C65.867,545.467 72.933,557.067 86,570.134C96.133,580.4 100,583.2 110.667,588.4C134.533,600.134 120,599.334 300,599.334C480,599.334 465.467,600.134 489.334,588.4C500,583.2 503.867,580.4 514,570.134C527.334,556.8 534.534,544.8 540.267,526.667L543.334,516.667L543.334,83.333L540.267,73.333C534.534,55.2 527.334,43.2 514,29.867C503.867,19.6 500,16.8 489.334,11.6C465.734,0 475.467,0.8 344.667,0.267L228.667,0ZM466.4,41.6C483.334,48.933 496.267,61.867 502.934,78.4L506,86L506,514L502.934,521.734C496,538.934 480.267,553.867 463.334,559.334C455.6,561.867 450.8,562 300,562C149.2,562 144.4,561.867 136.667,559.334C119.733,553.867 104,538.934 97.067,521.734L94,514L93.6,351.067L93.333,188.133L149.067,187.733L204.667,187.333L213.6,182.933C224.8,177.467 235.867,165.867 240.267,155.067C243.333,147.467 243.333,146.4 243.733,92.267L244.133,37.2L458,38L466.4,41.6ZM195.067,304C175.6,306.8 164,320.667 165.6,339.467C166,343.6 167.6,348.667 169.733,352.4C174.4,360.267 185.2,365.734 201.867,368.534C208.4,369.734 215.067,371.467 216.8,372.667C224,377.334 221.467,389.067 212.533,392C205.6,394.4 193.733,392.934 185.6,388.8C173.333,382.534 164,385.334 164,395.2C164,400.934 170.133,406.667 180.267,410.134C190.933,413.867 217.067,413.734 225.467,409.867C238.933,403.6 246.667,390 244.8,375.6C242.667,359.734 232.8,351.334 212.267,347.867C193.6,344.8 189.333,342.4 189.333,334.533C189.333,324.267 201.867,320.933 218.267,326.667C228.667,330.267 232.533,330.133 235.867,325.867C242.133,318 237.6,310.667 224.267,306.8C213.333,303.6 204.267,302.8 195.067,304ZM386,304.133C377.6,305.333 374,306.8 367.334,311.6C355.734,320.133 351.2,336.4 352.4,365.334C353.2,385.334 356,394.4 364.134,402.534C372.267,410.667 381.734,413.734 396.667,413.067C406.8,412.667 409.734,412 415.734,408.667C429.2,401.334 434.534,390.934 435.6,370.667C436.4,353.734 436,353.067 420.934,352.267C401.867,351.334 396,353.467 396,361.867C396,367.867 399.467,370.667 407.067,370.667C413.2,370.667 413.334,370.667 413.334,374.934C413.334,394 386.267,400.534 378.534,383.467C374.934,375.334 374.934,341.867 378.534,333.733C382,326.4 387.467,323.467 396.8,324.267C403.067,324.8 404.667,325.6 410.534,331.067C414.267,334.533 418.4,337.333 419.867,337.333C427.334,337.333 433.334,330.267 431.334,323.733C427.2,310.133 406.4,301.2 386,304.133ZM258.4,308C255.067,311.467 254.533,312.8 255.2,316.4C257.067,326.667 285.333,405.867 288.133,408.8C289.733,410.534 293.067,412.267 295.333,412.8C303.867,414.4 310.667,407.867 314.4,394.667C315.067,392.134 321.2,374.134 327.867,354.8C334.8,334.533 340,317.467 340,314.533C340,303.733 325.067,299.867 319.867,309.467C318.533,312.133 309.467,340.933 302.667,364C301.067,369.467 299.333,374.4 298.8,375.067C298.267,375.6 292.933,360.8 286.933,342C275.333,306 274.133,304 266.267,304C263.867,304 261.067,305.467 258.4,308Z" style="fill-rule:nonzero;"/>
7
+ </g>
8
+ </svg>`;
9
+ const svgSchema = {
10
+ ui: (arg) => {
11
+ const { rootElement, value, mode, onChange, theme, schema } = arg;
12
+ const container = document.createElement(isEditable(mode, schema) ? 'textarea' : 'div');
13
+ container.style.width = '100%';
14
+ container.style.height = '100%';
15
+ container.style.boxSizing = 'border-box';
16
+ if (isEditable(mode, schema)) {
17
+ const textarea = container;
18
+ textarea.value = value;
19
+ textarea.style.position = 'absolute';
20
+ textarea.style.backgroundColor = addAlphaToHex(theme.colorPrimaryBg, 30);
21
+ if (isValidSVG(value)) {
22
+ const svgElement = new DOMParser().parseFromString(value, 'text/xml').childNodes[0];
23
+ if (svgElement instanceof SVGElement) {
24
+ svgElement.setAttribute('width', '100%');
25
+ svgElement.setAttribute('height', '100%');
26
+ svgElement.style.position = 'absolute';
27
+ }
28
+ rootElement.appendChild(svgElement);
29
+ }
30
+ else if (value) {
31
+ const errorElm = createErrorElm();
32
+ errorElm.style.position = 'absolute';
33
+ rootElement.appendChild(errorElm);
34
+ }
35
+ textarea.addEventListener('change', (e) => {
36
+ const newValue = e.target.value;
37
+ onChange && onChange(newValue);
38
+ });
39
+ rootElement.appendChild(container);
40
+ textarea.setSelectionRange(value.length, value.length);
41
+ textarea.focus();
42
+ }
43
+ else {
44
+ if (!value)
45
+ return;
46
+ if (!isValidSVG(value)) {
47
+ rootElement.appendChild(createErrorElm());
48
+ return;
49
+ }
50
+ container.innerHTML = value;
51
+ const svgElement = container.childNodes[0];
52
+ if (svgElement instanceof SVGElement) {
53
+ svgElement.setAttribute('width', '100%');
54
+ svgElement.setAttribute('height', '100%');
55
+ rootElement.appendChild(container);
56
+ }
57
+ }
58
+ },
59
+ pdf: async (arg) => {
60
+ const { page, schema, value } = arg;
61
+ if (!value || !isValidSVG(value))
62
+ return;
63
+ const pageHeight = page.getHeight();
64
+ const { width, height, position } = convertForPdfLayoutProps({ schema, pageHeight });
65
+ const { x, y } = position;
66
+ await page.drawSvg(value, { x, y: y + height, width, height });
67
+ },
68
+ propPanel: {
69
+ schema: {},
70
+ defaultValue,
71
+ defaultSchema: {
72
+ type: 'svg',
73
+ position: { x: 0, y: 0 },
74
+ width: 40,
75
+ height: 40,
76
+ },
77
+ },
78
+ };
79
+ export default svgSchema;
80
+ export const readOnlySvg = {
81
+ pdf: svgSchema.pdf,
82
+ ui: svgSchema.ui,
83
+ propPanel: {
84
+ ...svgSchema.propPanel,
85
+ defaultSchema: {
86
+ ...svgSchema.propPanel.defaultSchema,
87
+ type: 'readOnlySvg',
88
+ readOnly: true,
89
+ readOnlyValue: defaultValue,
90
+ },
91
+ },
92
+ };
93
+ //# sourceMappingURL=svg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svg.js","sourceRoot":"","sources":["../../../../src/graphics/svg.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElG,MAAM,UAAU,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;AAEpF,MAAM,YAAY,GAAG;;;;OAId,CAAC;AAIR,MAAM,SAAS,GAAsB;IACnC,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;QACV,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;QAClE,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACxF,SAAS,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;QAC/B,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;QAChC,SAAS,CAAC,KAAK,CAAC,SAAS,GAAG,YAAY,CAAC;QACzC,IAAI,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;YAC5B,MAAM,QAAQ,GAAG,SAAgC,CAAC;YAClD,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KAAK,EAAE,EAAE;YACT,MAAM,EAAE,EAAE;SACX;KACF;CACF,CAAC;AAEF,eAAe,SAAS,CAAC;AAEzB,MAAM,CAAC,MAAM,WAAW,GAAsB;IAC5C,GAAG,EAAE,SAAS,CAAC,GAAG;IAClB,EAAE,EAAE,SAAS,CAAC,EAAE;IAChB,SAAS,EAAE;QACT,GAAG,SAAS,CAAC,SAAS;QACtB,aAAa,EAAE;YACb,GAAG,SAAS,CAAC,SAAS,CAAC,aAAa;YACpC,IAAI,EAAE,aAAa;YACnB,QAAQ,EAAE,IAAI;YACd,aAAa,EAAE,YAAY;SAC5B;KACF;CACF,CAAC"}
@@ -1,8 +1,10 @@
1
- import text from './text/index.js';
2
- import image from './image/index.js';
1
+ import text, { readOnlyText } from './text/index.js';
2
+ import image, { readOnlyImage } from './graphics/image.js';
3
+ import svg, { readOnlySvg } from './graphics/svg.js';
3
4
  import barcodes from './barcodes/index.js';
4
- import line from './line/index.js';
5
- import { convertForPdfLayoutProps, rotatePoint } from './renderUtils.js';
5
+ import line from './shapes/line.js';
6
+ import { rectangle, ellipse } from './shapes/rectAndEllipse.js';
7
+ import { convertForPdfLayoutProps, rotatePoint } from './utils.js';
6
8
  const builtInPlugins = { Text: text };
7
- export { text, image, barcodes, line, builtInPlugins, convertForPdfLayoutProps, rotatePoint };
9
+ export { text, readOnlyText, image, readOnlyImage, svg, readOnlySvg, barcodes, line, rectangle, ellipse, builtInPlugins, convertForPdfLayoutProps, rotatePoint, };
8
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAC3C,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEzE,MAAM,cAAc,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAEtC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,wBAAwB,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,GAAG,EAAE,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAC3C,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEnE,MAAM,cAAc,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAEtC,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,aAAa,EACb,GAAG,EACH,WAAW,EACX,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,OAAO,EACP,cAAc,EACd,wBAAwB,EACxB,WAAW,GACZ,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { rotatePoint, convertForPdfLayoutProps, hex2RgbColor } from '../utils.js';
2
+ import { HEX_COLOR_PATTERN } from '../constants.js';
3
+ const DEFAULT_LINE_COLOR = '#000000';
4
+ const lineSchema = {
5
+ pdf: (arg) => {
6
+ const { page, schema } = arg;
7
+ const pageHeight = page.getHeight();
8
+ const { width, height, rotate, position: { x, y }, opacity, } = convertForPdfLayoutProps({ schema, pageHeight, applyRotateTranslate: false });
9
+ const pivot = { x: x + width / 2, y: y + height / 2 };
10
+ page.drawLine({
11
+ start: rotatePoint({ x, y: y + height / 2 }, pivot, rotate.angle),
12
+ end: rotatePoint({ x: x + width, y: y + height / 2 }, pivot, rotate.angle),
13
+ thickness: height,
14
+ color: hex2RgbColor(schema.color ?? DEFAULT_LINE_COLOR),
15
+ opacity: opacity,
16
+ });
17
+ },
18
+ ui: (arg) => {
19
+ const { schema, rootElement } = arg;
20
+ const div = document.createElement('div');
21
+ div.style.backgroundColor = schema.color ?? DEFAULT_LINE_COLOR;
22
+ div.style.width = '100%';
23
+ div.style.height = '100%';
24
+ rootElement.appendChild(div);
25
+ },
26
+ propPanel: {
27
+ schema: ({ i18n }) => ({
28
+ color: {
29
+ title: i18n('schemas.color'),
30
+ type: 'string',
31
+ widget: 'color',
32
+ required: true,
33
+ rules: [
34
+ {
35
+ pattern: HEX_COLOR_PATTERN,
36
+ message: i18n('hexColorPrompt'),
37
+ },
38
+ ],
39
+ },
40
+ }),
41
+ defaultValue: '',
42
+ defaultSchema: {
43
+ type: 'line',
44
+ position: { x: 0, y: 0 },
45
+ width: 50,
46
+ height: 1,
47
+ rotate: 0,
48
+ opacity: 1,
49
+ readOnly: true,
50
+ color: DEFAULT_LINE_COLOR,
51
+ },
52
+ },
53
+ };
54
+ export default lineSchema;
55
+ //# sourceMappingURL=line.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"line.js","sourceRoot":"","sources":["../../../../src/shapes/line.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAMrC,MAAM,UAAU,GAAuB;IACrC,GAAG,EAAE,CAAC,GAA+B,EAAE,EAAE;QACvC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;QAC7B,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QACpC,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,SAAS,EAAE;QACT,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;YACrB,KAAK,EAAE;gBACL,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC;gBAC5B,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,OAAO;gBACf,QAAQ,EAAE,IAAI;gBACd,KAAK,EAAE;oBACL;wBACE,OAAO,EAAE,iBAAiB;wBAC1B,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC;qBAChC;iBACF;aACF;SACF,CAAC;QACF,YAAY,EAAE,EAAE;QAChB,aAAa,EAAE;YACb,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;YACxB,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,CAAC;YACT,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,IAAI;YACd,KAAK,EAAE,kBAAkB;SAC1B;KACF;CACF,CAAC;AACF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { mm2pt } from '@pdfme/common';
2
+ import { HEX_COLOR_PATTERN } from '../constants.js';
3
+ import { hex2RgbColor, convertForPdfLayoutProps } from '../utils.js';
4
+ const shape = {
5
+ ui: (arg) => {
6
+ const { schema, rootElement } = arg;
7
+ const div = document.createElement('div');
8
+ div.style.width = '100%';
9
+ div.style.height = '100%';
10
+ div.style.boxSizing = 'border-box';
11
+ if (schema.type === 'ellipse') {
12
+ div.style.borderRadius = '50%';
13
+ }
14
+ div.style.borderWidth = `${schema.borderWidth ?? 0}mm`;
15
+ div.style.borderStyle = schema.borderWidth && schema.borderColor ? 'solid' : 'none';
16
+ div.style.borderColor = schema.borderColor ?? 'transparent';
17
+ div.style.backgroundColor = schema.color ?? 'transparent';
18
+ rootElement.appendChild(div);
19
+ },
20
+ pdf: (arg) => {
21
+ const { schema, page } = arg;
22
+ const pageHeight = page.getHeight();
23
+ const cArg = { schema, pageHeight };
24
+ const { position, width, height, rotate, opacity } = convertForPdfLayoutProps(cArg);
25
+ const { position: { x: x4Ellipse, y: y4Ellipse }, } = convertForPdfLayoutProps({ ...cArg, applyRotateTranslate: false });
26
+ const borderWidth = schema.borderWidth ? mm2pt(schema.borderWidth) : 0;
27
+ const drawOptions = {
28
+ rotate,
29
+ borderWidth,
30
+ borderColor: hex2RgbColor(schema.borderColor),
31
+ color: hex2RgbColor(schema.color),
32
+ opacity,
33
+ borderOpacity: opacity,
34
+ };
35
+ if (schema.type === 'ellipse') {
36
+ page.drawEllipse({
37
+ x: x4Ellipse + width / 2,
38
+ y: y4Ellipse + height / 2,
39
+ xScale: width / 2 - borderWidth / 2,
40
+ yScale: height / 2 - borderWidth / 2,
41
+ ...drawOptions,
42
+ });
43
+ }
44
+ else if (schema.type === 'rectangle') {
45
+ page.drawRectangle({
46
+ x: position.x + borderWidth / 2,
47
+ y: position.y + borderWidth / 2,
48
+ width: width - borderWidth,
49
+ height: height - borderWidth,
50
+ ...drawOptions,
51
+ });
52
+ }
53
+ },
54
+ propPanel: {
55
+ schema: ({ i18n }) => ({
56
+ borderWidth: {
57
+ title: i18n('schemas.borderWidth'),
58
+ type: 'number',
59
+ widget: 'inputNumber',
60
+ min: 0,
61
+ step: 1,
62
+ },
63
+ borderColor: {
64
+ title: i18n('schemas.borderColor'),
65
+ type: 'string',
66
+ widget: 'color',
67
+ rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('hexColorPrompt') }],
68
+ },
69
+ color: {
70
+ title: i18n('schemas.color'),
71
+ type: 'string',
72
+ widget: 'color',
73
+ rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('hexColorPrompt') }],
74
+ },
75
+ }),
76
+ defaultValue: '',
77
+ defaultSchema: {
78
+ type: 'rectangle',
79
+ position: { x: 0, y: 0 },
80
+ width: 62.5,
81
+ height: 37.5,
82
+ rotate: 0,
83
+ opacity: 1,
84
+ borderWidth: 5,
85
+ borderColor: '#000000',
86
+ color: '#ffffff',
87
+ readOnly: true,
88
+ },
89
+ },
90
+ };
91
+ const getPropPanelSchema = (type) => ({
92
+ ...shape.propPanel,
93
+ defaultSchema: { ...shape.propPanel.defaultSchema, type },
94
+ });
95
+ export const rectangle = { ...shape, propPanel: getPropPanelSchema('rectangle') };
96
+ export const ellipse = { ...shape, propPanel: getPropPanelSchema('ellipse') };
97
+ //# sourceMappingURL=rectAndEllipse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rectAndEllipse.js","sourceRoot":"","sources":["../../../../src/shapes/rectAndEllipse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AASrE,MAAM,KAAK,GAAkB;IAC3B,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;QACV,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,GAAG,CAAC;QACpC,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1C,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;QACzB,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;QAC1B,GAAG,CAAC,KAAK,CAAC,SAAS,GAAG,YAAY,CAAC;QACnC,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE;YAC7B,GAAG,CAAC,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC;SAChC;QACD,GAAG,CAAC,KAAK,CAAC,WAAW,GAAG,GAAG,MAAM,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC;QACvD,GAAG,CAAC,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAA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