@pdfme/schemas 3.1.5-dev.6 → 3.1.5-dev.8
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/src/barcodes/propPanel.js +27 -29
- package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
- package/dist/cjs/src/barcodes/uiRender.js +3 -6
- package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
- package/dist/cjs/src/image/pdfRender.js +2 -0
- package/dist/cjs/src/image/pdfRender.js.map +1 -1
- package/dist/cjs/src/image/uiRender.js +3 -3
- package/dist/cjs/src/image/uiRender.js.map +1 -1
- package/dist/cjs/src/index.js +3 -1
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/line/constants.js +5 -0
- package/dist/cjs/src/line/constants.js.map +1 -0
- package/dist/cjs/src/line/index.js +8 -0
- package/dist/cjs/src/line/index.js.map +1 -0
- package/dist/cjs/src/line/pdfRender.js +20 -0
- package/dist/cjs/src/line/pdfRender.js.map +1 -0
- package/dist/cjs/src/line/propPanel.js +35 -0
- package/dist/cjs/src/line/propPanel.js.map +1 -0
- package/dist/cjs/src/line/types.js +3 -0
- package/dist/cjs/src/line/types.js.map +1 -0
- package/dist/cjs/src/line/uiRender.js +14 -0
- package/dist/cjs/src/line/uiRender.js.map +1 -0
- package/dist/cjs/src/renderUtils.js +28 -1
- package/dist/cjs/src/renderUtils.js.map +1 -1
- package/dist/cjs/src/text/index.js.map +1 -1
- package/dist/cjs/src/text/pdfRender.js +5 -28
- package/dist/cjs/src/text/pdfRender.js.map +1 -1
- package/dist/cjs/src/text/propPanel.js +2 -2
- package/dist/cjs/src/text/propPanel.js.map +1 -1
- package/dist/cjs/src/text/uiRender.js +11 -17
- package/dist/cjs/src/text/uiRender.js.map +1 -1
- package/dist/esm/src/barcodes/propPanel.js +27 -29
- package/dist/esm/src/barcodes/propPanel.js.map +1 -1
- package/dist/esm/src/barcodes/uiRender.js +4 -7
- package/dist/esm/src/barcodes/uiRender.js.map +1 -1
- package/dist/esm/src/image/pdfRender.js +2 -0
- package/dist/esm/src/image/pdfRender.js.map +1 -1
- package/dist/esm/src/image/uiRender.js +4 -4
- package/dist/esm/src/image/uiRender.js.map +1 -1
- package/dist/esm/src/index.js +2 -1
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/line/constants.js +2 -0
- package/dist/esm/src/line/constants.js.map +1 -0
- package/dist/esm/src/line/index.js +6 -0
- package/dist/esm/src/line/index.js.map +1 -0
- package/dist/esm/src/line/pdfRender.js +16 -0
- package/dist/esm/src/line/pdfRender.js.map +1 -0
- package/dist/esm/src/line/propPanel.js +32 -0
- package/dist/esm/src/line/propPanel.js.map +1 -0
- package/dist/esm/src/line/types.js +2 -0
- package/dist/esm/src/line/types.js.map +1 -0
- package/dist/esm/src/line/uiRender.js +10 -0
- package/dist/esm/src/line/uiRender.js.map +1 -0
- package/dist/esm/src/renderUtils.js +27 -2
- package/dist/esm/src/renderUtils.js.map +1 -1
- package/dist/esm/src/text/index.js.map +1 -1
- package/dist/esm/src/text/pdfRender.js +5 -28
- package/dist/esm/src/text/pdfRender.js.map +1 -1
- package/dist/esm/src/text/propPanel.js +2 -2
- package/dist/esm/src/text/propPanel.js.map +1 -1
- package/dist/esm/src/text/uiRender.js +12 -18
- package/dist/esm/src/text/uiRender.js.map +1 -1
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/line/constants.d.ts +1 -0
- package/dist/types/src/line/index.d.ts +4 -0
- package/dist/types/src/line/pdfRender.d.ts +3 -0
- package/dist/types/src/line/propPanel.d.ts +3 -0
- package/dist/types/src/line/types.d.ts +4 -0
- package/dist/types/src/line/uiRender.d.ts +3 -0
- package/dist/types/src/renderUtils.d.ts +3 -1
- package/package.json +1 -1
- package/src/barcodes/propPanel.ts +27 -29
- package/src/barcodes/uiRender.ts +4 -7
- package/src/image/pdfRender.ts +1 -0
- package/src/image/uiRender.ts +4 -4
- package/src/index.ts +2 -1
- package/src/line/constants.ts +1 -0
- package/src/line/index.ts +8 -0
- package/src/line/pdfRender.ts +24 -0
- package/src/line/propPanel.ts +34 -0
- package/src/line/types.ts +5 -0
- package/src/line/uiRender.ts +12 -0
- package/src/renderUtils.ts +34 -2
- package/src/text/index.ts +0 -1
- package/src/text/pdfRender.ts +5 -41
- package/src/text/propPanel.ts +2 -2
- package/src/text/uiRender.ts +11 -27
@@ -1,8 +1,7 @@
|
|
1
1
|
import { getDefaultFont } from '@pdfme/common';
|
2
2
|
import { DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE, VERTICAL_ALIGN_BOTTOM, DEFAULT_VERTICAL_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, PLACEHOLDER_FONT_COLOR, } from './constants.js';
|
3
3
|
import { calculateDynamicFontSize, getFontKitFont, getBrowserVerticalFontAdjustments, } from './helper.js';
|
4
|
-
import { addAlphaToHex } from '../renderUtils.js';
|
5
|
-
import { DEFAULT_OPACITY } from '../constants.js';
|
4
|
+
import { addAlphaToHex, isEditable } from '../renderUtils.js';
|
6
5
|
const mapVerticalAlignToFlex = (verticalAlignmentValue) => {
|
7
6
|
switch (verticalAlignmentValue) {
|
8
7
|
case VERTICAL_ALIGN_TOP:
|
@@ -14,16 +13,12 @@ const mapVerticalAlignToFlex = (verticalAlignmentValue) => {
|
|
14
13
|
}
|
15
14
|
return 'flex-start';
|
16
15
|
};
|
17
|
-
const getBackgroundColor = (
|
18
|
-
if (
|
16
|
+
const getBackgroundColor = (value, schema, defaultBackgroundColor) => {
|
17
|
+
if (!value)
|
18
|
+
return 'transparent';
|
19
|
+
if (schema.backgroundColor)
|
19
20
|
return schema.backgroundColor;
|
20
|
-
|
21
|
-
else if (mode === 'viewer') {
|
22
|
-
return schema.backgroundColor ?? 'transparent';
|
23
|
-
}
|
24
|
-
else {
|
25
|
-
return defaultBackgroundColor;
|
26
|
-
}
|
21
|
+
return defaultBackgroundColor;
|
27
22
|
};
|
28
23
|
export const uiRender = async (arg) => {
|
29
24
|
const { value, schema, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, options, theme, _cache, } = arg;
|
@@ -49,14 +44,13 @@ export const uiRender = async (arg) => {
|
|
49
44
|
const containerStyle = {
|
50
45
|
padding: 0,
|
51
46
|
resize: 'none',
|
52
|
-
backgroundColor: getBackgroundColor(
|
47
|
+
backgroundColor: getBackgroundColor(value, schema, addAlphaToHex(theme.colorPrimaryBg, 30)),
|
53
48
|
border: 'none',
|
54
49
|
display: 'flex',
|
55
50
|
flexDirection: 'column',
|
56
51
|
justifyContent: mapVerticalAlignToFlex(schema.verticalAlignment),
|
57
52
|
width: '100%',
|
58
53
|
height: '100%',
|
59
|
-
opacity: schema.opacity ?? DEFAULT_OPACITY,
|
60
54
|
};
|
61
55
|
Object.assign(container.style, containerStyle);
|
62
56
|
rootElement.innerHTML = '';
|
@@ -75,13 +69,13 @@ export const uiRender = async (arg) => {
|
|
75
69
|
resize: 'none',
|
76
70
|
border: 'none',
|
77
71
|
outline: 'none',
|
78
|
-
marginBottom: bottomAdjustment
|
79
|
-
paddingTop: topAdjustment
|
72
|
+
marginBottom: `${bottomAdjustment}px`,
|
73
|
+
paddingTop: `${topAdjustment}px`,
|
80
74
|
backgroundColor: 'transparent',
|
81
75
|
};
|
82
76
|
const textBlock = document.createElement('div');
|
83
77
|
Object.assign(textBlock.style, textBlockStyle);
|
84
|
-
if (mode
|
78
|
+
if (isEditable(mode)) {
|
85
79
|
textBlock.contentEditable = 'plaintext-only';
|
86
80
|
textBlock.tabIndex = tabIndex || 0;
|
87
81
|
textBlock.innerText = value;
|
@@ -98,8 +92,8 @@ export const uiRender = async (arg) => {
|
|
98
92
|
dynamicFontSize = await calculateDynamicFontSize(getCdfArg(textBlock.textContent));
|
99
93
|
textBlock.style.fontSize = `${dynamicFontSize}pt`;
|
100
94
|
const { topAdj: newTopAdj, bottomAdj: newBottomAdj } = getBrowserVerticalFontAdjustments(fontKitFont, dynamicFontSize ?? schema.fontSize ?? DEFAULT_FONT_SIZE, schema.lineHeight ?? DEFAULT_LINE_HEIGHT, schema.verticalAlignment ?? DEFAULT_VERTICAL_ALIGNMENT);
|
101
|
-
textBlock.style.paddingTop = newTopAdj
|
102
|
-
textBlock.style.marginBottom = newBottomAdj
|
95
|
+
textBlock.style.paddingTop = `${newTopAdj}px`;
|
96
|
+
textBlock.style.marginBottom = `${newBottomAdj}px`;
|
103
97
|
})();
|
104
98
|
}, 0);
|
105
99
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"uiRender.js","sourceRoot":"","sources":["../../../../src/text/uiRender.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,cAAc,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,cAAc,EACd,iCAAiC,GAClC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,
|
1
|
+
{"version":3,"file":"uiRender.js","sourceRoot":"","sources":["../../../../src/text/uiRender.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,cAAc,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,cAAc,EACd,iCAAiC,GAClC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAA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,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAEjC,IAAI,IAAI,KAAK,UAAU,EAAE;YACvB,SAAS,CAAC,KAAK,EAAE,CAAC;YAElB,8FAA8F;YAC9F,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;YACxC,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;YACrC,KAAK,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;YACpC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,4BAA4B;YACnD,SAAS,EAAE,eAAe,EAAE,CAAC;YAC7B,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;SAC5B;KACF;SAAM;QACL,SAAS,CAAC,SAAS,GAAG,KAAK;aACxB,KAAK,CAAC,EAAE,CAAC;aACT,GAAG,CACF,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CACvB,+BACE,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SACvC,MAAM,CAAC,SAAS,CACnB;aACA,IAAI,CAAC,EAAE,CAAC,CAAC;QAEZ,SAAS,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;KAClC;AACH,CAAC,CAAC"}
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import text from './text/index.js';
|
2
2
|
import image from './image/index.js';
|
3
3
|
import barcodes from './barcodes/index.js';
|
4
|
+
import line from './line/index.js';
|
4
5
|
import { convertForPdfLayoutProps, rotatePoint } from './renderUtils.js';
|
5
6
|
declare const builtInPlugins: {
|
6
7
|
Text: import("@pdfme/common").Plugin<import("./text/types.js").TextSchema>;
|
7
8
|
};
|
8
|
-
export { text, image, barcodes, builtInPlugins, convertForPdfLayoutProps, rotatePoint };
|
9
|
+
export { text, image, barcodes, line, builtInPlugins, convertForPdfLayoutProps, rotatePoint };
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const DEFAULT_LINE_COLOR = "#000000";
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Schema } from '@pdfme/common';
|
1
|
+
import { Schema, Mode } from '@pdfme/common';
|
2
2
|
export declare const convertForPdfLayoutProps: ({ schema, pageHeight, applyRotateTranslate, }: {
|
3
3
|
schema: Schema;
|
4
4
|
pageHeight: number;
|
@@ -24,3 +24,5 @@ export declare const rotatePoint: (point: {
|
|
24
24
|
y: number;
|
25
25
|
};
|
26
26
|
export declare const addAlphaToHex: (hex: string, alphaPercentage: number) => string;
|
27
|
+
export declare const isEditable: (mode: Mode) => boolean;
|
28
|
+
export declare const hex2RgbColor: (hexString: string | undefined) => import("@pdfme/pdf-lib").RGB | undefined;
|
package/package.json
CHANGED
@@ -157,35 +157,33 @@ export const getPropPanelByBarcodeType = (barcodeType: string): PropPanel<Barcod
|
|
157
157
|
if (!defaults) throw new Error(`[@pdfme/schemas] No default for barcode type ${barcodeType}`);
|
158
158
|
|
159
159
|
return {
|
160
|
-
schema: ({ i18n }) => {
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
};
|
188
|
-
},
|
160
|
+
schema: ({ i18n }) => ({
|
161
|
+
barColor: {
|
162
|
+
title: i18n('schemas.barcodes.barColor'),
|
163
|
+
type: 'string',
|
164
|
+
widget: 'color',
|
165
|
+
rules: [
|
166
|
+
{
|
167
|
+
pattern: HEX_COLOR_PATTERN,
|
168
|
+
message: i18n('hexColorPrompt'),
|
169
|
+
},
|
170
|
+
],
|
171
|
+
},
|
172
|
+
backgroundColor: {
|
173
|
+
title: i18n('schemas.bgColor'),
|
174
|
+
type: 'string',
|
175
|
+
widget: 'color',
|
176
|
+
rules: [
|
177
|
+
{
|
178
|
+
pattern: HEX_COLOR_PATTERN,
|
179
|
+
message: i18n('hexColorPrompt'),
|
180
|
+
},
|
181
|
+
],
|
182
|
+
},
|
183
|
+
...(barcodeHasText
|
184
|
+
? { textColor: { title: i18n('schemas.textColor'), type: 'string', widget: 'color' } }
|
185
|
+
: {}),
|
186
|
+
}),
|
189
187
|
...defaults,
|
190
188
|
};
|
191
189
|
};
|
package/src/barcodes/uiRender.ts
CHANGED
@@ -2,7 +2,7 @@ import type * as CSS from 'csstype';
|
|
2
2
|
import { UIRenderProps } from '@pdfme/common';
|
3
3
|
import type { BarcodeSchema } from './types';
|
4
4
|
import { validateBarcodeInput, createBarCode } from './helper.js';
|
5
|
-
import { addAlphaToHex } from '../renderUtils.js';
|
5
|
+
import { addAlphaToHex, isEditable } from '../renderUtils.js';
|
6
6
|
|
7
7
|
const fullSize = { width: '100%', height: '100%' };
|
8
8
|
|
@@ -71,11 +71,10 @@ export const uiRender = async (arg: UIRenderProps<BarcodeSchema>) => {
|
|
71
71
|
alignItems: 'center',
|
72
72
|
justifyContent: 'center',
|
73
73
|
fontFamily: "'Open Sans', sans-serif",
|
74
|
-
opacity: schema.opacity,
|
75
74
|
};
|
76
75
|
Object.assign(container.style, containerStyle);
|
77
76
|
rootElement.appendChild(container);
|
78
|
-
const editable = mode
|
77
|
+
const editable = isEditable(mode);
|
79
78
|
if (editable) {
|
80
79
|
const input = document.createElement('input');
|
81
80
|
const inputStyle: CSS.Properties = {
|
@@ -102,10 +101,8 @@ export const uiRender = async (arg: UIRenderProps<BarcodeSchema>) => {
|
|
102
101
|
stopEditing && stopEditing();
|
103
102
|
});
|
104
103
|
container.appendChild(input);
|
105
|
-
|
106
|
-
|
107
|
-
input.focus();
|
108
|
-
}
|
104
|
+
input.setSelectionRange(value.length, value.length);
|
105
|
+
input.focus();
|
109
106
|
}
|
110
107
|
|
111
108
|
if (!value) return;
|
package/src/image/pdfRender.ts
CHANGED
@@ -6,6 +6,7 @@ const getCacheKey = (schema: Schema, input: string) => `${schema.type}${input}`;
|
|
6
6
|
|
7
7
|
export const pdfRender = async (arg: PDFRenderProps<ImageSchema>) => {
|
8
8
|
const { value, schema, pdfDoc, page, _cache } = arg;
|
9
|
+
if (!value || !value.startsWith('data:image/')) return;
|
9
10
|
|
10
11
|
const inputImageCacheKey = getCacheKey(schema, value);
|
11
12
|
let image = _cache.get(inputImageCacheKey);
|
package/src/image/uiRender.ts
CHANGED
@@ -2,7 +2,7 @@ import type { ChangeEvent } from 'react';
|
|
2
2
|
import type * as CSS from 'csstype';
|
3
3
|
import type { ImageSchema } from './types';
|
4
4
|
import { UIRenderProps, ZOOM } from '@pdfme/common';
|
5
|
-
import { addAlphaToHex } from '../renderUtils.js';
|
5
|
+
import { addAlphaToHex, isEditable } from '../renderUtils.js';
|
6
6
|
|
7
7
|
const fullSize = { width: '100%', height: '100%' };
|
8
8
|
|
@@ -37,16 +37,16 @@ const readFile = (input: File | FileList | null): Promise<string | ArrayBuffer>
|
|
37
37
|
export const uiRender = async (arg: UIRenderProps<ImageSchema>) => {
|
38
38
|
const { value, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, schema, theme } =
|
39
39
|
arg;
|
40
|
-
const editable = mode
|
40
|
+
const editable = isEditable(mode);
|
41
41
|
|
42
42
|
const size = { width: schema.width * ZOOM, height: schema.height * ZOOM };
|
43
43
|
|
44
44
|
const container = document.createElement('div');
|
45
|
+
const backgroundStyle = placeholder ? `url(${placeholder})` : 'none';
|
45
46
|
const containerStyle: CSS.Properties = {
|
46
47
|
...fullSize,
|
47
|
-
backgroundImage: value ? 'none' :
|
48
|
+
backgroundImage: value ? 'none' : backgroundStyle,
|
48
49
|
backgroundSize: `${size.width}px ${size.height}px`,
|
49
|
-
opacity: schema.opacity,
|
50
50
|
};
|
51
51
|
Object.assign(container.style, containerStyle);
|
52
52
|
container.addEventListener('click', (e) => {
|
package/src/index.ts
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
import text from './text/index.js';
|
2
2
|
import image from './image/index.js';
|
3
3
|
import barcodes from './barcodes/index.js';
|
4
|
+
import line from './line/index.js';
|
4
5
|
import { convertForPdfLayoutProps, rotatePoint } from './renderUtils.js';
|
5
6
|
|
6
7
|
const builtInPlugins = { Text: text };
|
7
8
|
|
8
|
-
export { text, image, barcodes, builtInPlugins, convertForPdfLayoutProps, rotatePoint };
|
9
|
+
export { text, image, barcodes, line, builtInPlugins, convertForPdfLayoutProps, rotatePoint };
|
@@ -0,0 +1 @@
|
|
1
|
+
export const DEFAULT_LINE_COLOR = '#000000';
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { Plugin } from '@pdfme/common';
|
2
|
+
import { pdfRender } from './pdfRender.js';
|
3
|
+
import { propPanel } from './propPanel.js';
|
4
|
+
import { uiRender } from './uiRender.js';
|
5
|
+
import type { LineSchema } from './types.js';
|
6
|
+
|
7
|
+
const schema: Plugin<LineSchema> = { pdf: pdfRender, ui: uiRender, propPanel };
|
8
|
+
export default schema;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import type { PDFRenderProps } from '@pdfme/common';
|
2
|
+
import type { LineSchema } from './types';
|
3
|
+
import { rotatePoint, convertForPdfLayoutProps, hex2RgbColor } from '../renderUtils.js';
|
4
|
+
import { DEFAULT_LINE_COLOR } from './constants.js';
|
5
|
+
|
6
|
+
export const pdfRender = (arg: PDFRenderProps<LineSchema>) => {
|
7
|
+
const { page, schema } = arg;
|
8
|
+
const pageHeight = page.getHeight();
|
9
|
+
const {
|
10
|
+
width,
|
11
|
+
height,
|
12
|
+
rotate,
|
13
|
+
position: { x, y },
|
14
|
+
opacity,
|
15
|
+
} = convertForPdfLayoutProps({ schema, pageHeight, applyRotateTranslate: false });
|
16
|
+
const pivot = { x: x + width / 2, y: y + height / 2 };
|
17
|
+
page.drawLine({
|
18
|
+
start: rotatePoint({ x, y: y + height / 2 }, pivot, rotate.angle),
|
19
|
+
end: rotatePoint({ x: x + width, y: y + height / 2 }, pivot, rotate.angle),
|
20
|
+
thickness: height,
|
21
|
+
color: hex2RgbColor(schema.color ?? DEFAULT_LINE_COLOR),
|
22
|
+
opacity: opacity,
|
23
|
+
});
|
24
|
+
};
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { PropPanel } from '@pdfme/common';
|
2
|
+
import type { LineSchema } from './types';
|
3
|
+
import { HEX_COLOR_PATTERN } from '../constants.js';
|
4
|
+
import { DEFAULT_LINE_COLOR } from './constants.js';
|
5
|
+
|
6
|
+
export const propPanel: PropPanel<LineSchema> = {
|
7
|
+
schema: ({ i18n }) => {
|
8
|
+
return {
|
9
|
+
color: {
|
10
|
+
title: i18n('schemas.line.color'),
|
11
|
+
type: 'string',
|
12
|
+
widget: 'color',
|
13
|
+
required: true,
|
14
|
+
rules: [
|
15
|
+
{
|
16
|
+
pattern: HEX_COLOR_PATTERN,
|
17
|
+
message: i18n('hexColorPrompt'),
|
18
|
+
},
|
19
|
+
],
|
20
|
+
},
|
21
|
+
};
|
22
|
+
},
|
23
|
+
defaultValue: '',
|
24
|
+
defaultSchema: {
|
25
|
+
type: 'line',
|
26
|
+
position: { x: 0, y: 0 },
|
27
|
+
width: 50,
|
28
|
+
height: 1,
|
29
|
+
rotate: 0,
|
30
|
+
opacity: 1,
|
31
|
+
readOnly: true,
|
32
|
+
color: DEFAULT_LINE_COLOR,
|
33
|
+
},
|
34
|
+
};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { LineSchema } from './types';
|
2
|
+
import { UIRenderProps } from '@pdfme/common';
|
3
|
+
import { DEFAULT_LINE_COLOR } from './constants.js';
|
4
|
+
|
5
|
+
export const uiRender = (arg: UIRenderProps<LineSchema>) => {
|
6
|
+
const { schema, rootElement } = arg;
|
7
|
+
const div = document.createElement('div');
|
8
|
+
div.style.backgroundColor = schema.color ?? DEFAULT_LINE_COLOR;
|
9
|
+
div.style.width = '100%';
|
10
|
+
div.style.height = '100%';
|
11
|
+
rootElement.appendChild(div);
|
12
|
+
};
|
package/src/renderUtils.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { degrees, degreesToRadians } from '@pdfme/pdf-lib';
|
2
|
-
import { Schema, mm2pt } from '@pdfme/common';
|
1
|
+
import { degrees, degreesToRadians, rgb } from '@pdfme/pdf-lib';
|
2
|
+
import { Schema, mm2pt, Mode, isHexValid } from '@pdfme/common';
|
3
3
|
|
4
4
|
export const convertForPdfLayoutProps = ({
|
5
5
|
schema,
|
@@ -71,3 +71,35 @@ export const addAlphaToHex = (hex: string, alphaPercentage: number) => {
|
|
71
71
|
if (alphaHex.length === 1) alphaHex = '0' + alphaHex;
|
72
72
|
return hex + alphaHex;
|
73
73
|
};
|
74
|
+
|
75
|
+
export const isEditable = (mode: Mode) => mode === 'form' || mode === 'designer';
|
76
|
+
|
77
|
+
const hex2rgb = (hex: string) => {
|
78
|
+
if (hex.slice(0, 1) === '#') hex = hex.slice(1);
|
79
|
+
if (hex.length === 3)
|
80
|
+
hex =
|
81
|
+
hex.slice(0, 1) +
|
82
|
+
hex.slice(0, 1) +
|
83
|
+
hex.slice(1, 2) +
|
84
|
+
hex.slice(1, 2) +
|
85
|
+
hex.slice(2, 3) +
|
86
|
+
hex.slice(2, 3);
|
87
|
+
|
88
|
+
return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map((str) => parseInt(str, 16));
|
89
|
+
};
|
90
|
+
|
91
|
+
export const hex2RgbColor = (hexString: string | undefined) => {
|
92
|
+
if (hexString) {
|
93
|
+
const isValid = isHexValid(hexString);
|
94
|
+
|
95
|
+
if (!isValid) {
|
96
|
+
throw new Error(`Invalid hex color value ${hexString}`);
|
97
|
+
}
|
98
|
+
|
99
|
+
const [r, g, b] = hex2rgb(hexString);
|
100
|
+
|
101
|
+
return rgb(r / 255, g / 255, b / 255);
|
102
|
+
}
|
103
|
+
|
104
|
+
return undefined;
|
105
|
+
};
|
package/src/text/index.ts
CHANGED
package/src/text/pdfRender.ts
CHANGED
@@ -1,12 +1,5 @@
|
|
1
|
-
import { PDFFont, PDFDocument
|
2
|
-
import {
|
3
|
-
PDFRenderProps,
|
4
|
-
Font,
|
5
|
-
getDefaultFont,
|
6
|
-
getFallbackFontName,
|
7
|
-
mm2pt,
|
8
|
-
isHexValid,
|
9
|
-
} from '@pdfme/common';
|
1
|
+
import { PDFFont, PDFDocument } from '@pdfme/pdf-lib';
|
2
|
+
import { PDFRenderProps, Font, getDefaultFont, getFallbackFontName, mm2pt } from '@pdfme/common';
|
10
3
|
import type { TextSchema, FontWidthCalcValues } from './types';
|
11
4
|
import {
|
12
5
|
VERTICAL_ALIGN_TOP,
|
@@ -27,37 +20,7 @@ import {
|
|
27
20
|
getSplittedLines,
|
28
21
|
widthOfTextAtSize,
|
29
22
|
} from './helper.js';
|
30
|
-
import { convertForPdfLayoutProps, rotatePoint } from '../renderUtils.js';
|
31
|
-
|
32
|
-
const hex2rgb = (hex: string) => {
|
33
|
-
if (hex.slice(0, 1) === '#') hex = hex.slice(1);
|
34
|
-
if (hex.length === 3)
|
35
|
-
hex =
|
36
|
-
hex.slice(0, 1) +
|
37
|
-
hex.slice(0, 1) +
|
38
|
-
hex.slice(1, 2) +
|
39
|
-
hex.slice(1, 2) +
|
40
|
-
hex.slice(2, 3) +
|
41
|
-
hex.slice(2, 3);
|
42
|
-
|
43
|
-
return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map((str) => parseInt(str, 16));
|
44
|
-
};
|
45
|
-
|
46
|
-
const hex2RgbColor = (hexString: string | undefined) => {
|
47
|
-
if (hexString) {
|
48
|
-
const isValid = isHexValid(hexString);
|
49
|
-
|
50
|
-
if (!isValid) {
|
51
|
-
throw new Error(`Invalid hex color value ${hexString}`);
|
52
|
-
}
|
53
|
-
|
54
|
-
const [r, g, b] = hex2rgb(hexString);
|
55
|
-
|
56
|
-
return rgb(r / 255, g / 255, b / 255);
|
57
|
-
}
|
58
|
-
|
59
|
-
return undefined;
|
60
|
-
};
|
23
|
+
import { convertForPdfLayoutProps, rotatePoint, hex2RgbColor } from '../renderUtils.js';
|
61
24
|
|
62
25
|
const embedAndGetFontObj = async (arg: {
|
63
26
|
pdfDoc: PDFDocument;
|
@@ -118,6 +81,7 @@ const getFontProp = async ({
|
|
118
81
|
|
119
82
|
export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
120
83
|
const { value, pdfDoc, pdfLib, page, options, schema, _cache } = arg;
|
84
|
+
if (!value) return;
|
121
85
|
|
122
86
|
const { font = getDefaultFont() } = options;
|
123
87
|
|
@@ -132,7 +96,7 @@ export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
|
132
96
|
const fontName = (
|
133
97
|
schema.fontName ? schema.fontName : getFallbackFontName(font)
|
134
98
|
) as keyof typeof pdfFontObj;
|
135
|
-
const pdfFontValue = pdfFontObj[fontName];
|
99
|
+
const pdfFontValue = pdfFontObj && pdfFontObj[fontName];
|
136
100
|
|
137
101
|
const pageHeight = page.getHeight();
|
138
102
|
const {
|
package/src/text/propPanel.ts
CHANGED
@@ -153,7 +153,7 @@ export const propPanel: PropPanel<TextSchema> = {
|
|
153
153
|
rules: [
|
154
154
|
{
|
155
155
|
pattern: HEX_COLOR_PATTERN,
|
156
|
-
message: '
|
156
|
+
message: i18n('hexColorPrompt'),
|
157
157
|
},
|
158
158
|
],
|
159
159
|
},
|
@@ -164,7 +164,7 @@ export const propPanel: PropPanel<TextSchema> = {
|
|
164
164
|
rules: [
|
165
165
|
{
|
166
166
|
pattern: HEX_COLOR_PATTERN,
|
167
|
-
message: '
|
167
|
+
message: i18n('hexColorPrompt'),
|
168
168
|
},
|
169
169
|
],
|
170
170
|
},
|
package/src/text/uiRender.ts
CHANGED
@@ -18,8 +18,7 @@ import {
|
|
18
18
|
getFontKitFont,
|
19
19
|
getBrowserVerticalFontAdjustments,
|
20
20
|
} from './helper.js';
|
21
|
-
import { addAlphaToHex } from '../renderUtils.js';
|
22
|
-
import { DEFAULT_OPACITY } from '../constants.js';
|
21
|
+
import { addAlphaToHex, isEditable } from '../renderUtils.js';
|
23
22
|
|
24
23
|
const mapVerticalAlignToFlex = (verticalAlignmentValue: string | undefined) => {
|
25
24
|
switch (verticalAlignmentValue) {
|
@@ -33,19 +32,10 @@ const mapVerticalAlignToFlex = (verticalAlignmentValue: string | undefined) => {
|
|
33
32
|
return 'flex-start';
|
34
33
|
};
|
35
34
|
|
36
|
-
const getBackgroundColor = (
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
defaultBackgroundColor: string
|
41
|
-
) => {
|
42
|
-
if ((mode === 'form' || mode === 'designer') && value && schema.backgroundColor) {
|
43
|
-
return schema.backgroundColor as string;
|
44
|
-
} else if (mode === 'viewer') {
|
45
|
-
return (schema.backgroundColor as string) ?? 'transparent';
|
46
|
-
} else {
|
47
|
-
return defaultBackgroundColor;
|
48
|
-
}
|
35
|
+
const getBackgroundColor = (value: string, schema: Schema, defaultBackgroundColor: string) => {
|
36
|
+
if (!value) return 'transparent';
|
37
|
+
if (schema.backgroundColor) return schema.backgroundColor as string;
|
38
|
+
return defaultBackgroundColor;
|
49
39
|
};
|
50
40
|
|
51
41
|
export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
@@ -94,19 +84,13 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
94
84
|
const containerStyle: CSS.Properties = {
|
95
85
|
padding: 0,
|
96
86
|
resize: 'none',
|
97
|
-
backgroundColor: getBackgroundColor(
|
98
|
-
mode,
|
99
|
-
value,
|
100
|
-
schema,
|
101
|
-
addAlphaToHex(theme.colorPrimaryBg, 30)
|
102
|
-
),
|
87
|
+
backgroundColor: getBackgroundColor(value, schema, addAlphaToHex(theme.colorPrimaryBg, 30)),
|
103
88
|
border: 'none',
|
104
89
|
display: 'flex',
|
105
90
|
flexDirection: 'column',
|
106
91
|
justifyContent: mapVerticalAlignToFlex(schema.verticalAlignment),
|
107
92
|
width: '100%',
|
108
93
|
height: '100%',
|
109
|
-
opacity: schema.opacity ?? DEFAULT_OPACITY,
|
110
94
|
};
|
111
95
|
Object.assign(container.style, containerStyle);
|
112
96
|
rootElement.innerHTML = '';
|
@@ -126,14 +110,14 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
126
110
|
resize: 'none',
|
127
111
|
border: 'none',
|
128
112
|
outline: 'none',
|
129
|
-
marginBottom: bottomAdjustment
|
130
|
-
paddingTop: topAdjustment
|
113
|
+
marginBottom: `${bottomAdjustment}px`,
|
114
|
+
paddingTop: `${topAdjustment}px`,
|
131
115
|
backgroundColor: 'transparent',
|
132
116
|
};
|
133
117
|
const textBlock = document.createElement('div');
|
134
118
|
Object.assign(textBlock.style, textBlockStyle);
|
135
119
|
|
136
|
-
if (mode
|
120
|
+
if (isEditable(mode)) {
|
137
121
|
textBlock.contentEditable = 'plaintext-only';
|
138
122
|
textBlock.tabIndex = tabIndex || 0;
|
139
123
|
textBlock.innerText = value;
|
@@ -157,8 +141,8 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
157
141
|
schema.lineHeight ?? DEFAULT_LINE_HEIGHT,
|
158
142
|
schema.verticalAlignment ?? DEFAULT_VERTICAL_ALIGNMENT
|
159
143
|
);
|
160
|
-
textBlock.style.paddingTop = newTopAdj
|
161
|
-
textBlock.style.marginBottom = newBottomAdj
|
144
|
+
textBlock.style.paddingTop = `${newTopAdj}px`;
|
145
|
+
textBlock.style.marginBottom = `${newBottomAdj}px`;
|
162
146
|
})();
|
163
147
|
}, 0);
|
164
148
|
});
|