@pdfme/schemas 3.0.1 → 3.1.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.
- package/dist/cjs/__tests__/barcode.test.js +6 -15
- package/dist/cjs/__tests__/barcode.test.js.map +1 -1
- package/dist/cjs/__tests__/renderUtils.test.js +0 -7
- package/dist/cjs/__tests__/renderUtils.test.js.map +1 -1
- package/dist/cjs/__tests__/text.test.js +49 -58
- package/dist/cjs/__tests__/text.test.js.map +1 -1
- package/dist/cjs/src/barcodes/helper.js +5 -14
- package/dist/cjs/src/barcodes/helper.js.map +1 -1
- package/dist/cjs/src/barcodes/index.js +6 -6
- package/dist/cjs/src/barcodes/index.js.map +1 -1
- package/dist/cjs/src/barcodes/pdfRender.js +12 -18
- package/dist/cjs/src/barcodes/pdfRender.js.map +1 -1
- package/dist/cjs/src/barcodes/propPanel.js +107 -19
- package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
- package/dist/cjs/src/barcodes/uiRender.js +44 -26
- package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
- package/dist/cjs/src/image/index.js +4 -4
- package/dist/cjs/src/image/index.js.map +1 -1
- package/dist/cjs/src/image/pdfRender.js +7 -15
- package/dist/cjs/src/image/pdfRender.js.map +1 -1
- package/dist/cjs/src/image/uiRender.js +19 -17
- package/dist/cjs/src/image/uiRender.js.map +1 -1
- package/dist/cjs/src/index.js +10 -10
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/renderUtils.js +12 -3
- package/dist/cjs/src/renderUtils.js.map +1 -1
- package/dist/cjs/src/text/helper.js +18 -28
- package/dist/cjs/src/text/helper.js.map +1 -1
- package/dist/cjs/src/text/index.js +4 -4
- package/dist/cjs/src/text/index.js.map +1 -1
- package/dist/cjs/src/text/pdfRender.js +31 -41
- package/dist/cjs/src/text/pdfRender.js.map +1 -1
- package/dist/cjs/src/text/propPanel.js +55 -35
- package/dist/cjs/src/text/propPanel.js.map +1 -1
- package/dist/cjs/src/text/uiRender.js +27 -33
- package/dist/cjs/src/text/uiRender.js.map +1 -1
- package/dist/esm/__tests__/barcode.test.js +6 -15
- package/dist/esm/__tests__/barcode.test.js.map +1 -1
- package/dist/esm/__tests__/renderUtils.test.js +1 -8
- package/dist/esm/__tests__/renderUtils.test.js.map +1 -1
- package/dist/esm/__tests__/text.test.js +49 -58
- package/dist/esm/__tests__/text.test.js.map +1 -1
- package/dist/esm/src/barcodes/helper.js +4 -13
- package/dist/esm/src/barcodes/helper.js.map +1 -1
- package/dist/esm/src/barcodes/index.js +4 -4
- package/dist/esm/src/barcodes/index.js.map +1 -1
- package/dist/esm/src/barcodes/pdfRender.js +9 -15
- package/dist/esm/src/barcodes/pdfRender.js.map +1 -1
- package/dist/esm/src/barcodes/propPanel.js +104 -16
- package/dist/esm/src/barcodes/propPanel.js.map +1 -1
- package/dist/esm/src/barcodes/uiRender.js +43 -25
- package/dist/esm/src/barcodes/uiRender.js.map +1 -1
- package/dist/esm/src/image/index.js +3 -3
- package/dist/esm/src/image/index.js.map +1 -1
- package/dist/esm/src/image/pdfRender.js +5 -13
- package/dist/esm/src/image/pdfRender.js.map +1 -1
- package/dist/esm/src/image/uiRender.js +19 -17
- package/dist/esm/src/image/uiRender.js.map +1 -1
- package/dist/esm/src/index.js +4 -4
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/renderUtils.js +10 -1
- package/dist/esm/src/renderUtils.js.map +1 -1
- package/dist/esm/src/text/helper.js +9 -19
- package/dist/esm/src/text/helper.js.map +1 -1
- package/dist/esm/src/text/index.js +3 -3
- package/dist/esm/src/text/index.js.map +1 -1
- package/dist/esm/src/text/pdfRender.js +20 -30
- package/dist/esm/src/text/pdfRender.js.map +1 -1
- package/dist/esm/src/text/propPanel.js +46 -26
- package/dist/esm/src/text/propPanel.js.map +1 -1
- package/dist/esm/src/text/uiRender.js +23 -29
- package/dist/esm/src/text/uiRender.js.map +1 -1
- package/dist/types/src/barcodes/types.d.ts +1 -1
- package/dist/types/src/index.d.ts +5 -5
- package/dist/types/src/renderUtils.d.ts +1 -1
- package/package.json +5 -3
- package/src/barcodes/helper.ts +1 -1
- package/src/barcodes/index.ts +4 -4
- package/src/barcodes/pdfRender.ts +7 -3
- package/src/barcodes/propPanel.ts +13 -9
- package/src/barcodes/types.ts +1 -1
- package/src/barcodes/uiRender.ts +5 -3
- package/src/image/index.ts +3 -3
- package/src/image/pdfRender.ts +4 -2
- package/src/image/uiRender.ts +4 -2
- package/src/index.ts +4 -4
- package/src/renderUtils.ts +9 -1
- package/src/text/helper.ts +1 -1
- package/src/text/index.ts +3 -3
- package/src/text/pdfRender.ts +3 -3
- package/src/text/propPanel.ts +44 -24
- package/src/text/uiRender.ts +13 -5
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/schemas",
|
3
|
-
"version": "3.0.1",
|
3
|
+
"version": "3.1.0-dev.1",
|
4
4
|
"sideEffects": false,
|
5
5
|
"author": "hand-dot",
|
6
6
|
"license": "MIT",
|
@@ -21,13 +21,15 @@
|
|
21
21
|
"bugs": {
|
22
22
|
"url": "https://github.com/pdfme/pdfme/issues"
|
23
23
|
},
|
24
|
+
"type": "module",
|
24
25
|
"main": "dist/cjs/src/index.js",
|
25
26
|
"module": "dist/esm/src/index.js",
|
26
27
|
"types": "dist/types/src/index.d.ts",
|
27
28
|
"exports": {
|
28
29
|
".": {
|
29
30
|
"import": "./dist/esm/src/index.js",
|
30
|
-
"require": "./dist/cjs/src/index.js"
|
31
|
+
"require": "./dist/cjs/src/index.js",
|
32
|
+
"types": "./dist/types/src/index.d.ts"
|
31
33
|
}
|
32
34
|
},
|
33
35
|
"engines": {
|
@@ -35,7 +37,7 @@
|
|
35
37
|
},
|
36
38
|
"scripts": {
|
37
39
|
"develop": "tsc -p tsconfig.esm.json -w",
|
38
|
-
"build": "npm
|
40
|
+
"build": "npm-run-all --parallel build:cjs build:esm",
|
39
41
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
40
42
|
"build:esm": "tsc -p tsconfig.esm.json",
|
41
43
|
"clean": "rimraf dist",
|
package/src/barcodes/helper.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { b64toUint8Array } from '@pdfme/common';
|
2
2
|
import bwipjs, { RenderOptions } from 'bwip-js';
|
3
3
|
import { Buffer } from 'buffer';
|
4
|
-
import { BARCODE_TYPES } from './constants';
|
4
|
+
import { BARCODE_TYPES } from './constants.js';
|
5
5
|
import { BarcodeTypes } from './types';
|
6
6
|
|
7
7
|
// GTIN-13, GTIN-8, GTIN-12, GTIN-14
|
package/src/barcodes/index.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { pdfRender } from './pdfRender';
|
2
|
-
import { getPropPanelByBarcodeType } from './propPanel';
|
3
|
-
import { uiRender } from './uiRender';
|
1
|
+
import { pdfRender } from './pdfRender.js';
|
2
|
+
import { getPropPanelByBarcodeType } from './propPanel.js';
|
3
|
+
import { uiRender } from './uiRender.js';
|
4
4
|
import type { BarcodeSchema, BarcodeTypes } from './types';
|
5
|
-
import { BARCODE_TYPES } from './constants';
|
5
|
+
import { BARCODE_TYPES } from './constants.js';
|
6
6
|
import { Plugin } from '@pdfme/common';
|
7
7
|
|
8
8
|
const schemas = BARCODE_TYPES.reduce(
|
@@ -1,13 +1,17 @@
|
|
1
1
|
import { PDFRenderProps } from '@pdfme/common';
|
2
|
-
import {
|
2
|
+
import { convertForPdfLayoutProps } from '../renderUtils.js';
|
3
3
|
import type { BarcodeSchema } from './types';
|
4
|
-
import { createBarCode, validateBarcodeInput } from './helper';
|
4
|
+
import { createBarCode, validateBarcodeInput } from './helper.js';
|
5
|
+
|
6
|
+
const getBarcodeCacheKey = (schema: BarcodeSchema, value: string) => {
|
7
|
+
return `${schema.type}${schema.backgroundColor}${schema.barColor}${schema.textColor}${value}`;
|
8
|
+
};
|
5
9
|
|
6
10
|
export const pdfRender = async (arg: PDFRenderProps<BarcodeSchema>) => {
|
7
11
|
const { value, schema, pdfDoc, page, _cache } = arg;
|
8
12
|
if (!validateBarcodeInput(schema.type, value)) return;
|
9
13
|
|
10
|
-
const inputBarcodeCacheKey =
|
14
|
+
const inputBarcodeCacheKey = getBarcodeCacheKey(schema, value);
|
11
15
|
let image = _cache.get(inputBarcodeCacheKey);
|
12
16
|
if (!image) {
|
13
17
|
const imageBuf = await createBarCode(
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { PropPanel } from '@pdfme/common';
|
2
2
|
import type { BarcodeSchema } from './types';
|
3
|
-
import { DEFAULT_BARCODE_COLOR, DEFAULT_BARCODE_BG_COLOR } from './constants';
|
3
|
+
import { DEFAULT_BARCODE_COLOR, DEFAULT_BARCODE_BG_COLOR } from './constants.js';
|
4
4
|
|
5
5
|
const defaultColors = {
|
6
6
|
backgroundColor: DEFAULT_BARCODE_BG_COLOR,
|
@@ -140,16 +140,20 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
140
140
|
export const getPropPanelByBarcodeType = (barcodeType: string): PropPanel<BarcodeSchema> => {
|
141
141
|
const barcodeHasText = barcodeType !== 'qrcode' && barcodeType !== 'gs1datamatrix';
|
142
142
|
|
143
|
-
const schema = {
|
144
|
-
barColor: { title: 'Bar Color', type: 'string', widget: 'color' },
|
145
|
-
backgroundColor: { title: 'Background', type: 'string', widget: 'color' },
|
146
|
-
...(barcodeHasText
|
147
|
-
? { textColor: { title: 'Text Color', type: 'string', widget: 'color' } }
|
148
|
-
: {}),
|
149
|
-
};
|
150
143
|
const defaults = barcodeDefaults.find(({ defaultSchema }) => defaultSchema.type === barcodeType);
|
151
144
|
|
152
145
|
if (!defaults) throw new Error(`[@pdfme/schemas] No default for barcode type ${barcodeType}`);
|
153
146
|
|
154
|
-
return {
|
147
|
+
return {
|
148
|
+
schema: ({ i18n }) => {
|
149
|
+
return {
|
150
|
+
barColor: { title: i18n('schemas.barcodes.barColor'), type: 'string', widget: 'color' },
|
151
|
+
backgroundColor: { title: i18n('schemas.bgColor'), type: 'string', widget: 'color' },
|
152
|
+
...(barcodeHasText
|
153
|
+
? { textColor: { title: i18n('schemas.textColor'), type: 'string', widget: 'color' } }
|
154
|
+
: {}),
|
155
|
+
};
|
156
|
+
},
|
157
|
+
...defaults,
|
158
|
+
};
|
155
159
|
};
|
package/src/barcodes/types.ts
CHANGED
package/src/barcodes/uiRender.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import type * as CSS from 'csstype';
|
2
2
|
import { UIRenderProps } from '@pdfme/common';
|
3
3
|
import type { BarcodeSchema } from './types';
|
4
|
-
import { validateBarcodeInput, createBarCode } from './helper';
|
4
|
+
import { validateBarcodeInput, createBarCode } from './helper.js';
|
5
|
+
import { addAlphaToHex } from '../renderUtils.js';
|
5
6
|
|
6
7
|
const fullSize = { width: '100%', height: '100%' };
|
7
8
|
|
@@ -60,7 +61,8 @@ const createBarcodeImageElm = async (schema: BarcodeSchema, value: string) => {
|
|
60
61
|
};
|
61
62
|
|
62
63
|
export const uiRender = async (arg: UIRenderProps<BarcodeSchema>) => {
|
63
|
-
const { value, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, schema } =
|
64
|
+
const { value, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, schema, theme } =
|
65
|
+
arg;
|
64
66
|
|
65
67
|
const container = document.createElement('div');
|
66
68
|
const containerStyle: CSS.Properties = {
|
@@ -81,7 +83,7 @@ export const uiRender = async (arg: UIRenderProps<BarcodeSchema>) => {
|
|
81
83
|
textAlign: 'center',
|
82
84
|
fontSize: '1rem',
|
83
85
|
color: '#000',
|
84
|
-
backgroundColor: editable || value ?
|
86
|
+
backgroundColor: editable || value ? addAlphaToHex(theme.colorPrimaryBg, 30) : 'none',
|
85
87
|
border: 'none',
|
86
88
|
display: 'flex',
|
87
89
|
alignItems: 'center',
|
package/src/image/index.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { Plugin } from '@pdfme/common';
|
2
|
-
import { pdfRender } from './pdfRender';
|
3
|
-
import { propPanel } from './propPanel';
|
4
|
-
import { uiRender } from './uiRender';
|
2
|
+
import { pdfRender } from './pdfRender.js';
|
3
|
+
import { propPanel } from './propPanel.js';
|
4
|
+
import { uiRender } from './uiRender.js';
|
5
5
|
import type { ImageSchema } from './types';
|
6
6
|
|
7
7
|
const schema: Plugin<ImageSchema> = { pdf: pdfRender, ui: uiRender, propPanel };
|
package/src/image/pdfRender.ts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
import type { PDFRenderProps } from '@pdfme/common';
|
1
|
+
import type { PDFRenderProps, Schema } from '@pdfme/common';
|
2
2
|
import type { ImageSchema } from './types';
|
3
|
-
import {
|
3
|
+
import { convertForPdfLayoutProps } from '../renderUtils.js';
|
4
|
+
|
5
|
+
const getCacheKey = (schema: Schema, input: string) => `${schema.type}${input}`;
|
4
6
|
|
5
7
|
export const pdfRender = async (arg: PDFRenderProps<ImageSchema>) => {
|
6
8
|
const { value, schema, pdfDoc, page, _cache } = arg;
|
package/src/image/uiRender.ts
CHANGED
@@ -2,6 +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
6
|
|
6
7
|
const fullSize = { width: '100%', height: '100%' };
|
7
8
|
|
@@ -34,7 +35,8 @@ const readFile = (input: File | FileList | null): Promise<string | ArrayBuffer>
|
|
34
35
|
});
|
35
36
|
|
36
37
|
export const uiRender = async (arg: UIRenderProps<ImageSchema>) => {
|
37
|
-
const { value, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, schema } =
|
38
|
+
const { value, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, schema, theme } =
|
39
|
+
arg;
|
38
40
|
const editable = mode === 'form' || mode === 'designer';
|
39
41
|
|
40
42
|
const size = { width: schema.width * ZOOM, height: schema.height * ZOOM };
|
@@ -97,7 +99,7 @@ export const uiRender = async (arg: UIRenderProps<ImageSchema>) => {
|
|
97
99
|
display: editable ? 'flex' : 'none',
|
98
100
|
position: 'absolute',
|
99
101
|
top: 0,
|
100
|
-
backgroundColor: editable || value ?
|
102
|
+
backgroundColor: editable || value ? addAlphaToHex(theme.colorPrimaryBg, 30) : 'none',
|
101
103
|
cursor: 'pointer',
|
102
104
|
};
|
103
105
|
Object.assign(label.style, labelStyle);
|
package/src/index.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import text from './text';
|
2
|
-
import image from './image';
|
3
|
-
import barcodes from './barcodes';
|
4
|
-
import { convertForPdfLayoutProps, rotatePoint } from './renderUtils';
|
1
|
+
import text from './text/index.js';
|
2
|
+
import image from './image/index.js';
|
3
|
+
import barcodes from './barcodes/index.js';
|
4
|
+
import { convertForPdfLayoutProps, rotatePoint } from './renderUtils.js';
|
5
5
|
|
6
6
|
const builtInPlugins = { Text: text };
|
7
7
|
|
package/src/renderUtils.ts
CHANGED
@@ -61,4 +61,12 @@ export const rotatePoint = (
|
|
61
61
|
return { x, y };
|
62
62
|
};
|
63
63
|
|
64
|
-
export const
|
64
|
+
export const addAlphaToHex = (hex: string, alphaPercentage: number) => {
|
65
|
+
if (!/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/i.test(hex)) {
|
66
|
+
throw new Error('Invalid HEX color code');
|
67
|
+
}
|
68
|
+
const alphaValue = Math.round((alphaPercentage / 100) * 255);
|
69
|
+
let alphaHex = alphaValue.toString(16);
|
70
|
+
if (alphaHex.length === 1) alphaHex = '0' + alphaHex;
|
71
|
+
return hex + alphaHex;
|
72
|
+
};
|
package/src/text/helper.ts
CHANGED
package/src/text/index.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { Plugin } from '@pdfme/common';
|
2
|
-
import { pdfRender } from './pdfRender';
|
3
|
-
import { propPanel } from './propPanel';
|
4
|
-
import { uiRender } from './uiRender';
|
2
|
+
import { pdfRender } from './pdfRender.js';
|
3
|
+
import { propPanel } from './propPanel.js';
|
4
|
+
import { uiRender } from './uiRender.js';
|
5
5
|
import type { TextSchema } from './types';
|
6
6
|
|
7
7
|
const schema: Plugin<TextSchema> = { pdf: pdfRender, ui: uiRender, propPanel };
|
package/src/text/pdfRender.ts
CHANGED
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
DEFAULT_LINE_HEIGHT,
|
12
12
|
DEFAULT_CHARACTER_SPACING,
|
13
13
|
DEFAULT_FONT_COLOR,
|
14
|
-
} from './constants';
|
14
|
+
} from './constants.js';
|
15
15
|
import {
|
16
16
|
calculateDynamicFontSize,
|
17
17
|
heightOfFontAtSize,
|
@@ -19,8 +19,8 @@ import {
|
|
19
19
|
getFontKitFont,
|
20
20
|
getSplittedLines,
|
21
21
|
widthOfTextAtSize,
|
22
|
-
} from './helper';
|
23
|
-
import { convertForPdfLayoutProps, rotatePoint } from '../renderUtils';
|
22
|
+
} from './helper.js';
|
23
|
+
import { convertForPdfLayoutProps, rotatePoint } from '../renderUtils.js';
|
24
24
|
|
25
25
|
const hex2rgb = (hex: string) => {
|
26
26
|
if (hex.slice(0, 1) === '#') hex = hex.slice(1);
|
package/src/text/propPanel.ts
CHANGED
@@ -23,10 +23,10 @@ import {
|
|
23
23
|
DEFAULT_DYNAMIC_MAX_FONT_SIZE,
|
24
24
|
ALIGN_RIGHT,
|
25
25
|
ALIGN_CENTER,
|
26
|
-
} from './constants';
|
26
|
+
} from './constants.js';
|
27
27
|
|
28
28
|
const UseDynamicFontSize = (props: PropPanelWidgetProps) => {
|
29
|
-
const { rootElement, changeSchemas, activeSchema } = props;
|
29
|
+
const { rootElement, changeSchemas, activeSchema, i18n } = props;
|
30
30
|
|
31
31
|
const checkbox = document.createElement('input');
|
32
32
|
checkbox.type = 'checkbox';
|
@@ -42,14 +42,14 @@ const UseDynamicFontSize = (props: PropPanelWidgetProps) => {
|
|
42
42
|
changeSchemas([{ key: 'dynamicFontSize', value: val, schemaId: activeSchema.id }]);
|
43
43
|
};
|
44
44
|
const label = document.createElement('label');
|
45
|
-
label.innerText = '
|
45
|
+
label.innerText = i18n('schemas.text.dynamicFontSize') || '';
|
46
46
|
label.style.cssText = 'display: flex; width: 100%;';
|
47
47
|
label.appendChild(checkbox);
|
48
48
|
rootElement.appendChild(label);
|
49
49
|
};
|
50
50
|
|
51
51
|
export const propPanel: PropPanel<TextSchema> = {
|
52
|
-
schema: ({ options, activeSchema }) => {
|
52
|
+
schema: ({ options, activeSchema, i18n }) => {
|
53
53
|
const font = options.font || { [DEFAULT_FONT_NAME]: { data: '', fallback: true } };
|
54
54
|
const fontNames = Object.keys(font);
|
55
55
|
const fallbackFontName = getFallbackFontName(font);
|
@@ -58,7 +58,7 @@ export const propPanel: PropPanel<TextSchema> = {
|
|
58
58
|
|
59
59
|
const textSchema: Record<string, PropPanelSchema> = {
|
60
60
|
fontName: {
|
61
|
-
title: '
|
61
|
+
title: i18n('schemas.text.fontName'),
|
62
62
|
type: 'string',
|
63
63
|
widget: 'select',
|
64
64
|
default: fallbackFontName,
|
@@ -66,64 +66,84 @@ export const propPanel: PropPanel<TextSchema> = {
|
|
66
66
|
span: 12,
|
67
67
|
},
|
68
68
|
fontSize: {
|
69
|
-
title: '
|
69
|
+
title: i18n('schemas.text.size'),
|
70
70
|
type: 'number',
|
71
71
|
widget: 'inputNumber',
|
72
72
|
span: 6,
|
73
73
|
disabled: enableDynamicFont,
|
74
74
|
},
|
75
|
-
characterSpacing: {
|
75
|
+
characterSpacing: {
|
76
|
+
title: i18n('schemas.text.spacing'),
|
77
|
+
type: 'number',
|
78
|
+
widget: 'inputNumber',
|
79
|
+
span: 6,
|
80
|
+
},
|
76
81
|
alignment: {
|
77
|
-
title: '
|
82
|
+
title: i18n('schemas.text.textAlign'),
|
78
83
|
type: 'string',
|
79
84
|
widget: 'select',
|
80
85
|
props: {
|
81
86
|
options: [
|
82
|
-
{ label: '
|
83
|
-
{ label: '
|
84
|
-
{ label: '
|
87
|
+
{ label: i18n('schemas.left'), value: DEFAULT_ALIGNMENT },
|
88
|
+
{ label: i18n('schemas.center'), value: ALIGN_CENTER },
|
89
|
+
{ label: i18n('schemas.right'), value: ALIGN_RIGHT },
|
85
90
|
],
|
86
91
|
},
|
87
92
|
span: 8,
|
88
93
|
},
|
89
94
|
verticalAlignment: {
|
90
|
-
title: '
|
95
|
+
title: i18n('schemas.text.verticalAlign'),
|
91
96
|
type: 'string',
|
92
97
|
widget: 'select',
|
93
98
|
props: {
|
94
99
|
options: [
|
95
|
-
{ label: '
|
96
|
-
{ label: '
|
97
|
-
{ label: '
|
100
|
+
{ label: i18n('schemas.top'), value: VERTICAL_ALIGN_TOP },
|
101
|
+
{ label: i18n('schemas.middle'), value: VERTICAL_ALIGN_MIDDLE },
|
102
|
+
{ label: i18n('schemas.bottom'), value: VERTICAL_ALIGN_BOTTOM },
|
98
103
|
],
|
99
104
|
},
|
100
105
|
span: 8,
|
101
106
|
},
|
102
|
-
lineHeight: {
|
103
|
-
|
107
|
+
lineHeight: {
|
108
|
+
title: i18n('schemas.text.lineHeight'),
|
109
|
+
type: 'number',
|
110
|
+
widget: 'inputNumber',
|
111
|
+
span: 8,
|
112
|
+
},
|
113
|
+
useDynamicFontSize: { type: 'boolean', widget: 'UseDynamicFontSize', bind: false, span: 16 },
|
104
114
|
dynamicFontSize: {
|
105
115
|
type: 'object',
|
106
116
|
widget: 'card',
|
107
117
|
column: 3,
|
108
118
|
properties: {
|
109
|
-
min: {
|
110
|
-
|
119
|
+
min: {
|
120
|
+
title: i18n('schemas.text.min'),
|
121
|
+
type: 'number',
|
122
|
+
widget: 'inputNumber',
|
123
|
+
hidden: !enableDynamicFont,
|
124
|
+
},
|
125
|
+
max: {
|
126
|
+
title: i18n('schemas.text.max'),
|
127
|
+
type: 'number',
|
128
|
+
widget: 'inputNumber',
|
129
|
+
hidden: !enableDynamicFont,
|
130
|
+
},
|
111
131
|
fit: {
|
112
|
-
title: '
|
132
|
+
title: i18n('schemas.text.fit'),
|
113
133
|
type: 'string',
|
114
134
|
widget: 'select',
|
115
135
|
hidden: !enableDynamicFont,
|
116
136
|
props: {
|
117
137
|
options: [
|
118
|
-
{ label: '
|
119
|
-
{ label: '
|
138
|
+
{ label: i18n('schemas.horizontal'), value: DYNAMIC_FIT_HORIZONTAL },
|
139
|
+
{ label: i18n('schemas.vertical'), value: DYNAMIC_FIT_VERTICAL },
|
120
140
|
],
|
121
141
|
},
|
122
142
|
},
|
123
143
|
},
|
124
144
|
},
|
125
|
-
fontColor: { title: '
|
126
|
-
backgroundColor: { title: '
|
145
|
+
fontColor: { title: i18n('schemas.textColor'), type: 'string', widget: 'color' },
|
146
|
+
backgroundColor: { title: i18n('schemas.bgColor'), type: 'string', widget: 'color' },
|
127
147
|
};
|
128
148
|
|
129
149
|
return textSchema;
|
package/src/text/uiRender.ts
CHANGED
@@ -11,12 +11,13 @@ import {
|
|
11
11
|
DEFAULT_LINE_HEIGHT,
|
12
12
|
DEFAULT_CHARACTER_SPACING,
|
13
13
|
DEFAULT_FONT_COLOR,
|
14
|
-
} from './constants';
|
14
|
+
} from './constants.js';
|
15
15
|
import {
|
16
16
|
calculateDynamicFontSize,
|
17
17
|
getFontKitFont,
|
18
18
|
getBrowserVerticalFontAdjustments,
|
19
|
-
} from './helper';
|
19
|
+
} from './helper.js';
|
20
|
+
import { addAlphaToHex } from '../renderUtils.js';
|
20
21
|
|
21
22
|
const mapVerticalAlignToFlex = (verticalAlignmentValue: string | undefined) => {
|
22
23
|
switch (verticalAlignmentValue) {
|
@@ -33,14 +34,15 @@ const mapVerticalAlignToFlex = (verticalAlignmentValue: string | undefined) => {
|
|
33
34
|
const getBackgroundColor = (
|
34
35
|
mode: 'form' | 'viewer' | 'designer',
|
35
36
|
value: string,
|
36
|
-
schema: Schema
|
37
|
+
schema: Schema,
|
38
|
+
defaultBackgroundColor: string
|
37
39
|
) => {
|
38
40
|
if ((mode === 'form' || mode === 'designer') && value && schema.backgroundColor) {
|
39
41
|
return schema.backgroundColor as string;
|
40
42
|
} else if (mode === 'viewer') {
|
41
43
|
return (schema.backgroundColor as string) ?? 'transparent';
|
42
44
|
} else {
|
43
|
-
return
|
45
|
+
return defaultBackgroundColor;
|
44
46
|
}
|
45
47
|
};
|
46
48
|
|
@@ -55,6 +57,7 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
55
57
|
tabIndex,
|
56
58
|
placeholder,
|
57
59
|
options,
|
60
|
+
theme,
|
58
61
|
} = arg;
|
59
62
|
const font = options?.font || getDefaultFont();
|
60
63
|
|
@@ -86,7 +89,12 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
86
89
|
const containerStyle: CSS.Properties = {
|
87
90
|
padding: 0,
|
88
91
|
resize: 'none',
|
89
|
-
backgroundColor: getBackgroundColor(
|
92
|
+
backgroundColor: getBackgroundColor(
|
93
|
+
mode,
|
94
|
+
value,
|
95
|
+
schema,
|
96
|
+
addAlphaToHex(theme.colorPrimaryBg, 30)
|
97
|
+
),
|
90
98
|
border: 'none',
|
91
99
|
display: 'flex',
|
92
100
|
flexDirection: 'column',
|