@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.
- package/dist/cjs/__tests__/{renderUtils.test.js → utils.test.js} +38 -12
- package/dist/cjs/__tests__/utils.test.js.map +1 -0
- package/dist/cjs/src/barcodes/index.js +2 -2
- package/dist/cjs/src/barcodes/index.js.map +1 -1
- package/dist/cjs/src/barcodes/pdfRender.js +2 -2
- package/dist/cjs/src/barcodes/pdfRender.js.map +1 -1
- package/dist/cjs/src/barcodes/propPanel.js +1 -1
- package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
- package/dist/cjs/src/barcodes/uiRender.js +9 -32
- package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
- package/dist/cjs/src/graphics/helper.js +115 -0
- package/dist/cjs/src/graphics/helper.js.map +1 -0
- package/dist/cjs/src/graphics/image.js +179 -0
- package/dist/cjs/src/graphics/image.js.map +1 -0
- package/dist/cjs/src/graphics/svg.js +96 -0
- package/dist/cjs/src/graphics/svg.js.map +1 -0
- package/dist/cjs/src/index.js +42 -11
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/shapes/line.js +57 -0
- package/dist/cjs/src/shapes/line.js.map +1 -0
- package/dist/cjs/src/shapes/rectAndEllipse.js +100 -0
- package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -0
- package/dist/cjs/src/text/helper.js.map +1 -1
- package/dist/cjs/src/text/index.js +16 -2
- package/dist/cjs/src/text/index.js.map +1 -1
- package/dist/cjs/src/text/pdfRender.js +5 -5
- package/dist/cjs/src/text/pdfRender.js.map +1 -1
- package/dist/cjs/src/text/uiRender.js +3 -3
- package/dist/cjs/src/text/uiRender.js.map +1 -1
- package/dist/cjs/src/{renderUtils.js → utils.js} +55 -7
- package/dist/cjs/src/utils.js.map +1 -0
- package/dist/esm/__tests__/{renderUtils.test.js → utils.test.js} +34 -8
- package/dist/esm/__tests__/utils.test.js.map +1 -0
- package/dist/esm/src/barcodes/index.js +2 -2
- package/dist/esm/src/barcodes/index.js.map +1 -1
- package/dist/esm/src/barcodes/pdfRender.js +1 -1
- package/dist/esm/src/barcodes/pdfRender.js.map +1 -1
- package/dist/esm/src/barcodes/propPanel.js +1 -1
- package/dist/esm/src/barcodes/propPanel.js.map +1 -1
- package/dist/esm/src/barcodes/uiRender.js +9 -32
- package/dist/esm/src/barcodes/uiRender.js.map +1 -1
- package/dist/esm/src/graphics/helper.js +111 -0
- package/dist/esm/src/graphics/helper.js.map +1 -0
- package/dist/esm/src/graphics/image.js +176 -0
- package/dist/esm/src/graphics/image.js.map +1 -0
- package/dist/esm/src/graphics/svg.js +93 -0
- package/dist/esm/src/graphics/svg.js.map +1 -0
- package/dist/esm/src/index.js +7 -5
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/shapes/line.js +55 -0
- package/dist/esm/src/shapes/line.js.map +1 -0
- package/dist/esm/src/shapes/rectAndEllipse.js +97 -0
- package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -0
- package/dist/esm/src/text/helper.js.map +1 -1
- package/dist/esm/src/text/index.js +15 -2
- package/dist/esm/src/text/index.js.map +1 -1
- package/dist/esm/src/text/pdfRender.js +1 -1
- package/dist/esm/src/text/pdfRender.js.map +1 -1
- package/dist/esm/src/text/uiRender.js +2 -2
- package/dist/esm/src/text/uiRender.js.map +1 -1
- package/dist/esm/src/{renderUtils.js → utils.js} +52 -6
- package/dist/esm/src/utils.js.map +1 -0
- package/dist/types/src/barcodes/index.d.ts +2 -2
- package/dist/types/src/graphics/helper.d.ts +5 -0
- package/dist/types/src/graphics/image.d.ts +7 -0
- package/dist/types/src/graphics/svg.d.ts +6 -0
- package/dist/types/src/index.d.ts +7 -5
- package/dist/types/src/shapes/line.d.ts +6 -0
- package/dist/types/src/shapes/rectAndEllipse.d.ts +144 -0
- package/dist/types/src/text/index.d.ts +3 -2
- package/dist/types/src/text/pdfRender.d.ts +1 -1
- package/dist/types/src/{renderUtils.d.ts → utils.d.ts} +3 -1
- package/package.json +4 -3
- package/src/barcodes/index.ts +2 -2
- package/src/barcodes/pdfRender.ts +1 -1
- package/src/barcodes/propPanel.ts +1 -1
- package/src/barcodes/uiRender.ts +9 -36
- package/src/graphics/helper.ts +147 -0
- package/src/graphics/image.ts +207 -0
- package/src/graphics/svg.ts +98 -0
- package/src/index.ts +21 -5
- package/src/shapes/line.ts +67 -0
- package/src/shapes/rectAndEllipse.ts +110 -0
- package/src/text/helper.ts +0 -1
- package/src/text/index.ts +17 -2
- package/src/text/pdfRender.ts +2 -2
- package/src/text/uiRender.ts +2 -2
- package/src/{renderUtils.ts → utils.ts} +61 -5
- package/dist/cjs/__tests__/renderUtils.test.js.map +0 -1
- package/dist/cjs/src/image/index.js +0 -8
- package/dist/cjs/src/image/index.js.map +0 -1
- package/dist/cjs/src/image/pdfRender.js +0 -22
- package/dist/cjs/src/image/pdfRender.js.map +0 -1
- package/dist/cjs/src/image/propPanel.js +0 -19
- package/dist/cjs/src/image/propPanel.js.map +0 -1
- package/dist/cjs/src/image/types.js +0 -3
- package/dist/cjs/src/image/types.js.map +0 -1
- package/dist/cjs/src/image/uiRender.js +0 -111
- package/dist/cjs/src/image/uiRender.js.map +0 -1
- package/dist/cjs/src/line/constants.js +0 -5
- package/dist/cjs/src/line/constants.js.map +0 -1
- package/dist/cjs/src/line/index.js +0 -8
- package/dist/cjs/src/line/index.js.map +0 -1
- package/dist/cjs/src/line/pdfRender.js +0 -20
- package/dist/cjs/src/line/pdfRender.js.map +0 -1
- package/dist/cjs/src/line/propPanel.js +0 -35
- package/dist/cjs/src/line/propPanel.js.map +0 -1
- package/dist/cjs/src/line/types.js +0 -3
- package/dist/cjs/src/line/types.js.map +0 -1
- package/dist/cjs/src/line/uiRender.js +0 -14
- package/dist/cjs/src/line/uiRender.js.map +0 -1
- package/dist/cjs/src/renderUtils.js.map +0 -1
- package/dist/esm/__tests__/renderUtils.test.js.map +0 -1
- package/dist/esm/src/image/index.js +0 -6
- package/dist/esm/src/image/index.js.map +0 -1
- package/dist/esm/src/image/pdfRender.js +0 -18
- package/dist/esm/src/image/pdfRender.js.map +0 -1
- package/dist/esm/src/image/propPanel.js +0 -16
- package/dist/esm/src/image/propPanel.js.map +0 -1
- package/dist/esm/src/image/types.js +0 -2
- package/dist/esm/src/image/types.js.map +0 -1
- package/dist/esm/src/image/uiRender.js +0 -107
- package/dist/esm/src/image/uiRender.js.map +0 -1
- package/dist/esm/src/line/constants.js +0 -2
- package/dist/esm/src/line/constants.js.map +0 -1
- package/dist/esm/src/line/index.js +0 -6
- package/dist/esm/src/line/index.js.map +0 -1
- package/dist/esm/src/line/pdfRender.js +0 -16
- package/dist/esm/src/line/pdfRender.js.map +0 -1
- package/dist/esm/src/line/propPanel.js +0 -32
- package/dist/esm/src/line/propPanel.js.map +0 -1
- package/dist/esm/src/line/types.js +0 -2
- package/dist/esm/src/line/types.js.map +0 -1
- package/dist/esm/src/line/uiRender.js +0 -10
- package/dist/esm/src/line/uiRender.js.map +0 -1
- package/dist/esm/src/renderUtils.js.map +0 -1
- package/dist/types/src/image/index.d.ts +0 -4
- package/dist/types/src/image/pdfRender.d.ts +0 -3
- package/dist/types/src/image/propPanel.d.ts +0 -3
- package/dist/types/src/image/types.d.ts +0 -3
- package/dist/types/src/image/uiRender.d.ts +0 -3
- package/dist/types/src/line/constants.d.ts +0 -1
- package/dist/types/src/line/index.d.ts +0 -4
- package/dist/types/src/line/pdfRender.d.ts +0 -3
- package/dist/types/src/line/propPanel.d.ts +0 -3
- package/dist/types/src/line/types.d.ts +0 -4
- package/dist/types/src/line/uiRender.d.ts +0 -3
- package/src/image/index.ts +0 -8
- package/src/image/pdfRender.ts +0 -29
- package/src/image/propPanel.ts +0 -19
- package/src/image/types.ts +0 -3
- package/src/image/uiRender.ts +0 -121
- package/src/line/constants.ts +0 -1
- package/src/line/index.ts +0 -8
- package/src/line/pdfRender.ts +0 -24
- package/src/line/propPanel.ts +0 -34
- package/src/line/types.ts +0 -5
- package/src/line/uiRender.ts +0 -12
- /package/dist/types/__tests__/{renderUtils.test.d.ts → utils.test.d.ts} +0 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
import { Plugin, Schema } from '@pdfme/common';
|
2
|
+
import { XMLValidator } from 'fast-xml-parser';
|
3
|
+
import { convertForPdfLayoutProps, isEditable, addAlphaToHex, createErrorElm } from '../utils.js';
|
4
|
+
|
5
|
+
const isValidSVG = (svgString: string) => XMLValidator.validate(svgString) === true;
|
6
|
+
|
7
|
+
const defaultValue = `<svg viewBox="0 0 488 600" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
8
|
+
<g transform="matrix(1,0,0,1,-56,0)" fill="#000000" stroke="none">
|
9
|
+
<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;"/>
|
10
|
+
</g>
|
11
|
+
</svg>`;
|
12
|
+
|
13
|
+
interface SVGSchema extends Schema {}
|
14
|
+
|
15
|
+
const svgSchema: Plugin<SVGSchema> = {
|
16
|
+
ui: (arg) => {
|
17
|
+
const { rootElement, value, mode, onChange, theme, schema } = arg;
|
18
|
+
const container = document.createElement(isEditable(mode, schema) ? 'textarea' : 'div');
|
19
|
+
container.style.width = '100%';
|
20
|
+
container.style.height = '100%';
|
21
|
+
container.style.boxSizing = 'border-box';
|
22
|
+
if (isEditable(mode, schema)) {
|
23
|
+
const textarea = container as HTMLTextAreaElement;
|
24
|
+
textarea.value = value;
|
25
|
+
textarea.style.position = 'absolute';
|
26
|
+
textarea.style.backgroundColor = addAlphaToHex(theme.colorPrimaryBg, 30);
|
27
|
+
|
28
|
+
if (isValidSVG(value)) {
|
29
|
+
const svgElement = new DOMParser().parseFromString(value, 'text/xml').childNodes[0];
|
30
|
+
if (svgElement instanceof SVGElement) {
|
31
|
+
svgElement.setAttribute('width', '100%');
|
32
|
+
svgElement.setAttribute('height', '100%');
|
33
|
+
svgElement.style.position = 'absolute';
|
34
|
+
}
|
35
|
+
rootElement.appendChild(svgElement);
|
36
|
+
} else if (value) {
|
37
|
+
const errorElm = createErrorElm();
|
38
|
+
errorElm.style.position = 'absolute';
|
39
|
+
rootElement.appendChild(errorElm);
|
40
|
+
}
|
41
|
+
|
42
|
+
textarea.addEventListener('change', (e: Event) => {
|
43
|
+
const newValue = (e.target as HTMLTextAreaElement).value;
|
44
|
+
onChange && onChange(newValue);
|
45
|
+
});
|
46
|
+
rootElement.appendChild(container);
|
47
|
+
textarea.setSelectionRange(value.length, value.length);
|
48
|
+
textarea.focus();
|
49
|
+
} else {
|
50
|
+
if (!value) return;
|
51
|
+
if (!isValidSVG(value)) {
|
52
|
+
rootElement.appendChild(createErrorElm());
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
container.innerHTML = value;
|
56
|
+
const svgElement = container.childNodes[0];
|
57
|
+
if (svgElement instanceof SVGElement) {
|
58
|
+
svgElement.setAttribute('width', '100%');
|
59
|
+
svgElement.setAttribute('height', '100%');
|
60
|
+
rootElement.appendChild(container);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
},
|
64
|
+
pdf: async (arg) => {
|
65
|
+
const { page, schema, value } = arg;
|
66
|
+
if (!value || !isValidSVG(value)) return;
|
67
|
+
const pageHeight = page.getHeight();
|
68
|
+
const { width, height, position } = convertForPdfLayoutProps({ schema, pageHeight });
|
69
|
+
const { x, y } = position;
|
70
|
+
await page.drawSvg(value, { x, y: y + height, width, height });
|
71
|
+
},
|
72
|
+
propPanel: {
|
73
|
+
schema: {},
|
74
|
+
defaultValue,
|
75
|
+
defaultSchema: {
|
76
|
+
type: 'svg',
|
77
|
+
position: { x: 0, y: 0 },
|
78
|
+
width: 40,
|
79
|
+
height: 40,
|
80
|
+
},
|
81
|
+
},
|
82
|
+
};
|
83
|
+
|
84
|
+
export default svgSchema;
|
85
|
+
|
86
|
+
export const readOnlySvg: Plugin<SVGSchema> = {
|
87
|
+
pdf: svgSchema.pdf,
|
88
|
+
ui: svgSchema.ui,
|
89
|
+
propPanel: {
|
90
|
+
...svgSchema.propPanel,
|
91
|
+
defaultSchema: {
|
92
|
+
...svgSchema.propPanel.defaultSchema,
|
93
|
+
type: 'readOnlySvg',
|
94
|
+
readOnly: true,
|
95
|
+
readOnlyValue: defaultValue,
|
96
|
+
},
|
97
|
+
},
|
98
|
+
};
|
package/src/index.ts
CHANGED
@@ -1,9 +1,25 @@
|
|
1
|
-
import text from './text/index.js';
|
2
|
-
import image from './image
|
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
|
5
|
-
import {
|
5
|
+
import line from './shapes/line.js';
|
6
|
+
import { rectangle, ellipse } from './shapes/rectAndEllipse.js';
|
7
|
+
import { convertForPdfLayoutProps, rotatePoint } from './utils.js';
|
6
8
|
|
7
9
|
const builtInPlugins = { Text: text };
|
8
10
|
|
9
|
-
export {
|
11
|
+
export {
|
12
|
+
text,
|
13
|
+
readOnlyText,
|
14
|
+
image,
|
15
|
+
readOnlyImage,
|
16
|
+
svg,
|
17
|
+
readOnlySvg,
|
18
|
+
barcodes,
|
19
|
+
line,
|
20
|
+
rectangle,
|
21
|
+
ellipse,
|
22
|
+
builtInPlugins,
|
23
|
+
convertForPdfLayoutProps,
|
24
|
+
rotatePoint,
|
25
|
+
};
|
@@ -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') };
|
package/src/text/helper.ts
CHANGED
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
|
8
|
-
|
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
|
+
};
|
package/src/text/pdfRender.ts
CHANGED
@@ -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 '../
|
23
|
+
import { convertForPdfLayoutProps, rotatePoint, hex2RgbColor } from '../utils.js';
|
24
24
|
|
25
25
|
const embedAndGetFontObj = async (arg: {
|
26
26
|
pdfDoc: PDFDocument;
|
package/src/text/uiRender.ts
CHANGED
@@ -18,7 +18,7 @@ import {
|
|
18
18
|
getFontKitFont,
|
19
19
|
getBrowserVerticalFontAdjustments,
|
20
20
|
} from './helper.js';
|
21
|
-
import { addAlphaToHex, isEditable } from '../
|
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) =>
|
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,E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EAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACrC,MAAM,CAAC,IAAA,cAAK,EAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAA,cAAK,EAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAA,cAAK,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAA,cAAK,EAAC,IAAI,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC;QAC1E,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,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/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,sDAA6D;AAE7D,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;AAEzE,MAAM,SAAS,GAAG,KAAK,EAAE,GAAgC,EAAE,EAAE;IAClE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IACpD,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC;QAAE,OAAO;IAEvD,MAAM,kBAAkB,GAAG,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACtD,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;QAClD,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QACxE,MAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;KACvC;IAED,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,CAAC,CAAC;IAErD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAClE,CAAC,CAAC;AAtBW,QAAA,SAAS,aAsBpB"}
|
@@ -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+RO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DavSwGXf7YjT76uqCEQ/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 +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
|