@pdfme/schemas 3.1.3 → 3.1.5
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__/text.test.js +47 -25
- package/dist/cjs/__tests__/text.test.js.map +1 -1
- package/dist/cjs/src/barcodes/constants.js +1 -2
- package/dist/cjs/src/barcodes/constants.js.map +1 -1
- package/dist/cjs/src/barcodes/propPanel.js +34 -13
- package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
- package/dist/cjs/src/constants.js +6 -0
- package/dist/cjs/src/constants.js.map +1 -0
- package/dist/cjs/src/image/propPanel.js +2 -2
- package/dist/cjs/src/image/propPanel.js.map +1 -1
- package/dist/cjs/src/text/constants.js +2 -2
- package/dist/cjs/src/text/constants.js.map +1 -1
- package/dist/cjs/src/text/helper.js +8 -7
- package/dist/cjs/src/text/helper.js.map +1 -1
- package/dist/cjs/src/text/pdfRender.js +14 -11
- package/dist/cjs/src/text/pdfRender.js.map +1 -1
- package/dist/cjs/src/text/propPanel.js +24 -3
- package/dist/cjs/src/text/propPanel.js.map +1 -1
- package/dist/cjs/src/text/uiRender.js +72 -42
- package/dist/cjs/src/text/uiRender.js.map +1 -1
- package/dist/esm/__tests__/text.test.js +47 -25
- package/dist/esm/__tests__/text.test.js.map +1 -1
- package/dist/esm/src/barcodes/constants.js +0 -1
- package/dist/esm/src/barcodes/constants.js.map +1 -1
- package/dist/esm/src/barcodes/propPanel.js +24 -3
- package/dist/esm/src/barcodes/propPanel.js.map +1 -1
- package/dist/esm/src/constants.js +3 -0
- package/dist/esm/src/constants.js.map +1 -0
- package/dist/esm/src/image/propPanel.js +1 -1
- package/dist/esm/src/image/propPanel.js.map +1 -1
- package/dist/esm/src/text/constants.js +1 -1
- package/dist/esm/src/text/constants.js.map +1 -1
- package/dist/esm/src/text/helper.js +8 -7
- package/dist/esm/src/text/helper.js.map +1 -1
- package/dist/esm/src/text/pdfRender.js +15 -12
- package/dist/esm/src/text/pdfRender.js.map +1 -1
- package/dist/esm/src/text/propPanel.js +24 -3
- package/dist/esm/src/text/propPanel.js.map +1 -1
- package/dist/esm/src/text/uiRender.js +73 -43
- package/dist/esm/src/text/uiRender.js.map +1 -1
- package/dist/types/src/barcodes/constants.d.ts +0 -1
- package/dist/types/src/constants.d.ts +2 -0
- package/dist/types/src/text/constants.d.ts +1 -1
- package/dist/types/src/text/helper.d.ts +4 -3
- package/package.json +1 -1
- package/src/barcodes/constants.ts +0 -2
- package/src/barcodes/propPanel.ts +24 -3
- package/src/constants.ts +2 -0
- package/src/image/propPanel.ts +1 -1
- package/src/text/constants.ts +1 -1
- package/src/text/helper.ts +11 -7
- package/src/text/pdfRender.ts +31 -13
- package/src/text/propPanel.ts +23 -3
- package/src/text/uiRender.ts +83 -46
- package/dist/cjs/src/image/constants.js +0 -5
- package/dist/cjs/src/image/constants.js.map +0 -1
- package/dist/cjs/src/image/helper.js +0 -3
- package/dist/cjs/src/image/helper.js.map +0 -1
- package/dist/esm/src/image/constants.js +0 -2
- package/dist/esm/src/image/constants.js.map +0 -1
- package/dist/esm/src/image/helper.js +0 -2
- package/dist/esm/src/image/helper.js.map +0 -1
- package/dist/types/src/image/constants.d.ts +0 -1
- package/dist/types/src/image/helper.d.ts +0 -1
- package/src/image/constants.ts +0 -1
- package/src/image/helper.ts +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/barcodes/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,QAAQ;IACR,WAAW;IACX,OAAO;IACP,MAAM;IACN,QAAQ;IACR,SAAS;IACT,KAAK;IACL,OAAO;IACP,MAAM;IACN,MAAM;IACN,eAAe;CACP,CAAC;AAEX,MAAM,CAAC,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAElD,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAS,CAAC
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/barcodes/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,QAAQ;IACR,WAAW;IACX,OAAO;IACP,MAAM;IACN,QAAQ;IACR,SAAS;IACT,KAAK;IACL,OAAO;IACP,MAAM;IACN,MAAM;IACN,eAAe;CACP,CAAC;AAEX,MAAM,CAAC,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAElD,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAS,CAAC"}
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import { DEFAULT_BARCODE_COLOR, DEFAULT_BARCODE_BG_COLOR
|
1
|
+
import { DEFAULT_BARCODE_COLOR, DEFAULT_BARCODE_BG_COLOR } from './constants.js';
|
2
|
+
import { DEFAULT_OPACITY, HEX_COLOR_PATTERN } from '../constants.js';
|
2
3
|
const defaultColors = {
|
3
4
|
backgroundColor: DEFAULT_BARCODE_BG_COLOR,
|
4
5
|
barColor: DEFAULT_BARCODE_COLOR,
|
@@ -151,8 +152,28 @@ export const getPropPanelByBarcodeType = (barcodeType) => {
|
|
151
152
|
return {
|
152
153
|
schema: ({ i18n }) => {
|
153
154
|
return {
|
154
|
-
barColor: {
|
155
|
-
|
155
|
+
barColor: {
|
156
|
+
title: i18n('schemas.barcodes.barColor'),
|
157
|
+
type: 'string',
|
158
|
+
widget: 'color',
|
159
|
+
rules: [
|
160
|
+
{
|
161
|
+
pattern: HEX_COLOR_PATTERN,
|
162
|
+
message: 'Please enter a valid hex color code.',
|
163
|
+
},
|
164
|
+
],
|
165
|
+
},
|
166
|
+
backgroundColor: {
|
167
|
+
title: i18n('schemas.bgColor'),
|
168
|
+
type: 'string',
|
169
|
+
widget: 'color',
|
170
|
+
rules: [
|
171
|
+
{
|
172
|
+
pattern: HEX_COLOR_PATTERN,
|
173
|
+
message: 'Please enter a valid hex color code.',
|
174
|
+
},
|
175
|
+
],
|
176
|
+
},
|
156
177
|
...(barcodeHasText
|
157
178
|
? { textColor: { title: i18n('schemas.textColor'), type: 'string', widget: 'color' } }
|
158
179
|
: {}),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"propPanel.js","sourceRoot":"","sources":["../../../../src/barcodes/propPanel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"propPanel.js","sourceRoot":"","sources":["../../../../src/barcodes/propPanel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAErE,MAAM,aAAa,GAAG;IACpB,eAAe,EAAE,wBAAwB;IACzC,QAAQ,EAAE,qBAAqB;CAChC,CAAC;AACF,MAAM,iBAAiB,GAAG,EAAE,SAAS,EAAE,qBAAqB,EAAE,CAAC;AAC/D,MAAM,QAAQ,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAChC,MAAM,YAAY,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAE/C,MAAM,eAAe,GAA6D;IAChF;QACE,YAAY,EAAE,oBAAoB;QAClC,aAAa,EAAE;YACb,IAAI,EAAE,QAAQ;YACd,QAAQ;YACR,GAAG,aAAa;YAChB,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,eAAe;SACzB;KACF;IACD;QACE,YAAY,EAAE,kBAAkB;QAChC,aAAa,EAAE;YACb,IAAI,EAAE,WAAW;YACjB,QAAQ;YACR,GAAG,aAAa;YAChB,GAAG,iBAAiB;YACpB,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,eAAe;SACzB;KACF;IACD;QACE,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BACD,eAAe,EAAE;oBACf,KAAK,EAAE,IAAI,CAAC,iBAAiB,CAAC;oBAC9B,IAAI,EAAE,QAAQ;oBACd,MAAM,EAAE,OAAO;oBACf,KAAK,EAAE;wBACL;4BACE,OAAO,EAAE,iBAAiB;4BAC1B,OAAO,EAAE,sCAAsC;yBAChD;qBACF;iBACF;gBACD,GAAG,CAAC,cAAc;oBAChB,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,mBAAmB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;oBACtF,CAAC,CAAC,EAAE,CAAC;aACR,CAAC;QACJ,CAAC;QACD,GAAG,QAAQ;KACZ,CAAC;AACJ,CAAC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,iBAAiB,GAAG,uDAAuD,CAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { DEFAULT_OPACITY } from '../
|
1
|
+
import { DEFAULT_OPACITY } from '../constants.js';
|
2
2
|
export const propPanel = {
|
3
3
|
schema: {},
|
4
4
|
defaultValue: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAu4AAALuAQMAAADL0wGJAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAGUExURbzAw+rv8fKruy0AAAPoSURBVHja7dwxbtwwEEBRCkKwRQodYftcYk+ROkcJz5NTsEuZK/AIKlIQAUEnke0VqQ0pA5zxWvFnZcD2s0CNuENxPOZBc0QDDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PD/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Hh4eHh4eHh4eHh4eHh4eHl+d/A9cKjmiL040TAAAAAElFTkSuQmCC',
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"propPanel.js","sourceRoot":"","sources":["../../../../src/image/propPanel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"propPanel.js","sourceRoot":"","sources":["../../../../src/image/propPanel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,CAAC,MAAM,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,eAAe;KACzB;CACF,CAAC"}
|
@@ -10,11 +10,11 @@ export const DEFAULT_VERTICAL_ALIGNMENT = VERTICAL_ALIGN_TOP;
|
|
10
10
|
export const DEFAULT_LINE_HEIGHT = 1;
|
11
11
|
export const DEFAULT_CHARACTER_SPACING = 0;
|
12
12
|
export const DEFAULT_FONT_COLOR = '#000000';
|
13
|
+
export const PLACEHOLDER_FONT_COLOR = '#A0A0A0';
|
13
14
|
export const DYNAMIC_FIT_VERTICAL = 'vertical';
|
14
15
|
export const DYNAMIC_FIT_HORIZONTAL = 'horizontal';
|
15
16
|
export const DEFAULT_DYNAMIC_FIT = DYNAMIC_FIT_VERTICAL;
|
16
17
|
export const DEFAULT_DYNAMIC_MIN_FONT_SIZE = 4;
|
17
18
|
export const DEFAULT_DYNAMIC_MAX_FONT_SIZE = 72;
|
18
19
|
export const FONT_SIZE_ADJUSTMENT = 0.25;
|
19
|
-
export const DEFAULT_OPACITY = 1;
|
20
20
|
//# sourceMappingURL=constants.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/text/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAEpC,MAAM,CAAC,MAAM,UAAU,GAAG,MAAmB,CAAC;AAC9C,MAAM,CAAC,MAAM,YAAY,GAAG,QAAqB,CAAC;AAClD,MAAM,CAAC,MAAM,WAAW,GAAG,OAAoB,CAAC;AAChD,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAC5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAA2B,CAAC;AAC9D,MAAM,CAAC,MAAM,qBAAqB,GAAG,QAA8B,CAAC;AACpE,MAAM,CAAC,MAAM,qBAAqB,GAAG,QAA8B,CAAC;AACpE,MAAM,CAAC,MAAM,0BAA0B,GAAG,kBAAkB,CAAC;AAC7D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAC3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAC5C,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAmC,CAAC;AACxE,MAAM,CAAC,MAAM,sBAAsB,GAAG,YAAqC,CAAC;AAC5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AACxD,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAE/C,MAAM,CAAC,MAAM,6BAA6B,GAAG,EAAE,CAAC;AAChD,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/text/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAEpC,MAAM,CAAC,MAAM,UAAU,GAAG,MAAmB,CAAC;AAC9C,MAAM,CAAC,MAAM,YAAY,GAAG,QAAqB,CAAC;AAClD,MAAM,CAAC,MAAM,WAAW,GAAG,OAAoB,CAAC;AAChD,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAC5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAA2B,CAAC;AAC9D,MAAM,CAAC,MAAM,qBAAqB,GAAG,QAA8B,CAAC;AACpE,MAAM,CAAC,MAAM,qBAAqB,GAAG,QAA8B,CAAC;AACpE,MAAM,CAAC,MAAM,0BAA0B,GAAG,kBAAkB,CAAC;AAC7D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAC3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAC5C,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAS,CAAC;AAChD,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAmC,CAAC;AACxE,MAAM,CAAC,MAAM,sBAAsB,GAAG,YAAqC,CAAC;AAC5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AACxD,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAE/C,MAAM,CAAC,MAAM,6BAA6B,GAAG,EAAE,CAAC;AAChD,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC"}
|
@@ -58,11 +58,12 @@ const getFallbackFont = (font) => {
|
|
58
58
|
const fallbackFontName = getFallbackFontName(font);
|
59
59
|
return font[fallbackFontName];
|
60
60
|
};
|
61
|
-
const
|
62
|
-
export const getFontKitFont = async (textSchema, font) => {
|
61
|
+
const getCacheKey = (fontName) => `getFontKitFont-${fontName}`;
|
62
|
+
export const getFontKitFont = async (textSchema, font, _cache) => {
|
63
63
|
const fontName = textSchema.fontName || getFallbackFontName(font);
|
64
|
-
|
65
|
-
|
64
|
+
const cacheKey = getCacheKey(fontName);
|
65
|
+
if (_cache.has(cacheKey)) {
|
66
|
+
return _cache.get(cacheKey);
|
66
67
|
}
|
67
68
|
const currentFont = font[fontName] || getFallbackFont(font) || getDefaultFont()[DEFAULT_FONT_NAME];
|
68
69
|
let fontData = currentFont.data;
|
@@ -72,7 +73,7 @@ export const getFontKitFont = async (textSchema, font) => {
|
|
72
73
|
: b64toUint8Array(fontData);
|
73
74
|
}
|
74
75
|
const fontKitFont = fontkit.create(fontData instanceof Buffer ? fontData : Buffer.from(fontData));
|
75
|
-
|
76
|
+
_cache.set(cacheKey, fontKitFont);
|
76
77
|
return fontKitFont;
|
77
78
|
};
|
78
79
|
const isTextExceedingBoxWidth = (text, calcValues) => {
|
@@ -133,7 +134,7 @@ export const getSplittedLines = (textLine, calcValues) => {
|
|
133
134
|
* Calculating space usage involves splitting lines where they exceed
|
134
135
|
* the box width based on the proposed size.
|
135
136
|
*/
|
136
|
-
export const calculateDynamicFontSize = async ({ textSchema, font, value, startingFontSize, }) => {
|
137
|
+
export const calculateDynamicFontSize = async ({ textSchema, font, value, startingFontSize, _cache, }) => {
|
137
138
|
const { fontSize: schemaFontSize, dynamicFontSize: dynamicFontSizeSetting, characterSpacing: schemaCharacterSpacing, width: boxWidth, height: boxHeight, lineHeight = DEFAULT_LINE_HEIGHT, } = textSchema;
|
138
139
|
const fontSize = startingFontSize || schemaFontSize || DEFAULT_FONT_SIZE;
|
139
140
|
if (!dynamicFontSizeSetting)
|
@@ -141,7 +142,7 @@ export const calculateDynamicFontSize = async ({ textSchema, font, value, starti
|
|
141
142
|
if (dynamicFontSizeSetting.max < dynamicFontSizeSetting.min)
|
142
143
|
return fontSize;
|
143
144
|
const characterSpacing = schemaCharacterSpacing ?? DEFAULT_CHARACTER_SPACING;
|
144
|
-
const fontKitFont = await getFontKitFont(textSchema, font);
|
145
|
+
const fontKitFont = await getFontKitFont(textSchema, font, _cache);
|
145
146
|
const paragraphs = value.split('\n');
|
146
147
|
let dynamicFontSize = fontSize;
|
147
148
|
if (dynamicFontSize < dynamicFontSizeSetting.min) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../src/text/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,EACL,eAAe,EACf,KAAK,EACL,KAAK,EACL,KAAK,EAGL,mBAAmB,EACnB,cAAc,EACd,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAExB,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAC/C,WAAwB,EACxB,QAAgB,EAChB,UAAkB,EAClB,iBAAyB,EACzB,EAAE;IACF,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC;IAEpD,8FAA8F;IAC9F,MAAM,kBAAkB,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,UAAU,CAAC;IAE3D,6BAA6B;IAC7B,6FAA6F;IAC7F,wDAAwD;IACxD,+FAA+F;IAC/F,qFAAqF;IACrF,MAAM,aAAa,GAAG,CAAC,kBAAkB,GAAG,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAErE,IAAI,iBAAiB,KAAK,kBAAkB,EAAE;QAC5C,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;KACvD;IAED,2CAA2C;IAC3C,6FAA6F;IAC7F,wFAAwF;IACxF,oCAAoC;IACpC,8FAA8F;IAC9F,gFAAgF;IAChF,2FAA2F;IAC3F,4FAA4F;IAC5F,+DAA+D;IAC/D,2FAA2F;IAC3F,IAAI,gBAAgB,G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AG,SAAS,CAAC;IAClE,CAAC,CAAC;IAEF,IAAI,EAAE,cAAc,EAAE,eAAe,EAAE,GAAG,oBAAoB,CAAC,eAAe,CAAC,CAAC;IAEhF,sDAAsD;IACtD,OAAO,mBAAmB,CAAC,cAAc,EAAE,eAAe,CAAC,EAAE;QAC3D,eAAe,IAAI,oBAAoB,CAAC;QACxC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,GAC5D,oBAAoB,CAAC,eAAe,CAAC,CAAC;QAExC,IAAI,SAAS,GAAG,SAAS,EAAE;YACzB,cAAc,GAAG,QAAQ,CAAC;YAC1B,eAAe,GAAG,SAAS,CAAC;SAC7B;aAAM;YACL,eAAe,IAAI,oBAAoB,CAAC;YACxC,MAAM;SACP;KACF;IAED,wDAAwD;IACxD,OAAO,qBAAqB,CAAC,cAAc,EAAE,eAAe,CAAC,EAAE;QAC7D,eAAe,IAAI,oBAAoB,CAAC;QACxC,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,GAAG,oBAAoB,CAAC,eAAe,CAAC,CAAC,CAAC;KAC/E;IAED,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { rgb } from '@pdfme/pdf-lib';
|
2
|
-
import { getDefaultFont, getFallbackFontName, mm2pt } from '@pdfme/common';
|
2
|
+
import { getDefaultFont, getFallbackFontName, mm2pt, isHexValid, } from '@pdfme/common';
|
3
3
|
import { VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE, VERTICAL_ALIGN_BOTTOM, DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_VERTICAL_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, } from './constants.js';
|
4
4
|
import { calculateDynamicFontSize, heightOfFontAtSize, getFontDescentInPt, getFontKitFont, getSplittedLines, widthOfTextAtSize, } from './helper.js';
|
5
5
|
import { convertForPdfLayoutProps, rotatePoint } from '../renderUtils.js';
|
@@ -18,16 +18,19 @@ const hex2rgb = (hex) => {
|
|
18
18
|
};
|
19
19
|
const hex2RgbColor = (hexString) => {
|
20
20
|
if (hexString) {
|
21
|
+
const isValid = isHexValid(hexString);
|
22
|
+
if (!isValid) {
|
23
|
+
throw new Error(`Invalid hex color value ${hexString}`);
|
24
|
+
}
|
21
25
|
const [r, g, b] = hex2rgb(hexString);
|
22
26
|
return rgb(r / 255, g / 255, b / 255);
|
23
27
|
}
|
24
28
|
return undefined;
|
25
29
|
};
|
26
|
-
const embedAndGetFontObjCache = new WeakMap();
|
27
30
|
const embedAndGetFontObj = async (arg) => {
|
28
|
-
const { pdfDoc, font } = arg;
|
29
|
-
if (
|
30
|
-
return
|
31
|
+
const { pdfDoc, font, _cache } = arg;
|
32
|
+
if (_cache.has(pdfDoc)) {
|
33
|
+
return _cache.get(pdfDoc);
|
31
34
|
}
|
32
35
|
const fontValues = await Promise.all(Object.values(font).map(async (v) => {
|
33
36
|
let fontData = v.data;
|
@@ -39,12 +42,12 @@ const embedAndGetFontObj = async (arg) => {
|
|
39
42
|
});
|
40
43
|
}));
|
41
44
|
const fontObj = Object.keys(font).reduce((acc, cur, i) => Object.assign(acc, { [cur]: fontValues[i] }), {});
|
42
|
-
|
45
|
+
_cache.set(pdfDoc, fontObj);
|
43
46
|
return fontObj;
|
44
47
|
};
|
45
|
-
const getFontProp = async ({ value, font, schema, }) => {
|
48
|
+
const getFontProp = async ({ value, font, schema, _cache, }) => {
|
46
49
|
const fontSize = schema.dynamicFontSize
|
47
|
-
? await calculateDynamicFontSize({ textSchema: schema, font, value })
|
50
|
+
? await calculateDynamicFontSize({ textSchema: schema, font, value, _cache })
|
48
51
|
: schema.fontSize ?? DEFAULT_FONT_SIZE;
|
49
52
|
const color = hex2RgbColor(schema.fontColor || DEFAULT_FONT_COLOR);
|
50
53
|
return {
|
@@ -57,12 +60,12 @@ const getFontProp = async ({ value, font, schema, }) => {
|
|
57
60
|
};
|
58
61
|
};
|
59
62
|
export const pdfRender = async (arg) => {
|
60
|
-
const { value, pdfDoc, pdfLib, page, options, schema } = arg;
|
63
|
+
const { value, pdfDoc, pdfLib, page, options, schema, _cache } = arg;
|
61
64
|
const { font = getDefaultFont() } = options;
|
62
65
|
const [pdfFontObj, fontKitFont, fontProp] = await Promise.all([
|
63
|
-
embedAndGetFontObj({ pdfDoc, font }),
|
64
|
-
getFontKitFont(schema, font),
|
65
|
-
getFontProp({ value, font, schema }),
|
66
|
+
embedAndGetFontObj({ pdfDoc, font, _cache }),
|
67
|
+
getFontKitFont(schema, font, _cache),
|
68
|
+
getFontProp({ value, font, schema, _cache }),
|
66
69
|
]);
|
67
70
|
const { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing } = fontProp;
|
68
71
|
const fontName = (schema.fontName ? schema.fontName : getFallbackFontName(font));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pdfRender.js","sourceRoot":"","sources":["../../../../src/text/pdfRender.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,
|
1
|
+
{"version":3,"file":"pdfRender.js","sourceRoot":"","sources":["../../../../src/text/pdfRender.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAGL,cAAc,EACd,mBAAmB,EACnB,KAAK,EACL,UAAU,GACX,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAA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T_NAME, getFallbackFontName, } from '@pdfme/common';
|
2
|
-
import { DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_VERTICAL_ALIGNMENT, DEFAULT_CHARACTER_SPACING, DEFAULT_LINE_HEIGHT, VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE, VERTICAL_ALIGN_BOTTOM, DEFAULT_FONT_COLOR, DYNAMIC_FIT_VERTICAL, DYNAMIC_FIT_HORIZONTAL, DEFAULT_DYNAMIC_FIT, DEFAULT_DYNAMIC_MIN_FONT_SIZE, DEFAULT_DYNAMIC_MAX_FONT_SIZE, ALIGN_RIGHT, ALIGN_CENTER,
|
2
|
+
import { DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_VERTICAL_ALIGNMENT, DEFAULT_CHARACTER_SPACING, DEFAULT_LINE_HEIGHT, VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE, VERTICAL_ALIGN_BOTTOM, DEFAULT_FONT_COLOR, DYNAMIC_FIT_VERTICAL, DYNAMIC_FIT_HORIZONTAL, DEFAULT_DYNAMIC_FIT, DEFAULT_DYNAMIC_MIN_FONT_SIZE, DEFAULT_DYNAMIC_MAX_FONT_SIZE, ALIGN_RIGHT, ALIGN_CENTER, } from './constants.js';
|
3
|
+
import { DEFAULT_OPACITY, HEX_COLOR_PATTERN } from '../constants.js';
|
3
4
|
const UseDynamicFontSize = (props) => {
|
4
5
|
const { rootElement, changeSchemas, activeSchema, i18n } = props;
|
5
6
|
const checkbox = document.createElement('input');
|
@@ -116,8 +117,28 @@ export const propPanel = {
|
|
116
117
|
},
|
117
118
|
},
|
118
119
|
},
|
119
|
-
fontColor: {
|
120
|
-
|
120
|
+
fontColor: {
|
121
|
+
title: i18n('schemas.textColor'),
|
122
|
+
type: 'string',
|
123
|
+
widget: 'color',
|
124
|
+
rules: [
|
125
|
+
{
|
126
|
+
pattern: HEX_COLOR_PATTERN,
|
127
|
+
message: 'Please enter a valid hex color code.',
|
128
|
+
},
|
129
|
+
],
|
130
|
+
},
|
131
|
+
backgroundColor: {
|
132
|
+
title: i18n('schemas.bgColor'),
|
133
|
+
type: 'string',
|
134
|
+
widget: 'color',
|
135
|
+
rules: [
|
136
|
+
{
|
137
|
+
pattern: HEX_COLOR_PATTERN,
|
138
|
+
message: 'Please enter a valid hex color code.',
|
139
|
+
},
|
140
|
+
],
|
141
|
+
},
|
121
142
|
};
|
122
143
|
return textSchema;
|
123
144
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"propPanel.js","sourceRoot":"","sources":["../../../../src/text/propPanel.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAIjB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,0BAA0B,EAC1B,yBAAyB,EACzB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,6BAA6B,EAC7B,6BAA6B,EAC7B,WAAW,EACX,YAAY,
|
1
|
+
{"version":3,"file":"propPanel.js","sourceRoot":"","sources":["../../../../src/text/propPanel.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAIjB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,0BAA0B,EAC1B,yBAAyB,EACzB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,6BAA6B,EAC7B,6BAA6B,EAC7B,WAAW,EACX,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAErE,MAAM,kBAAkB,GAAG,CAAC,KAA2B,EAAE,EAAE;IACzD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AAE,0BAA0B;QAC7C,QAAQ,EAAE,iBAAiB;QAC3B,UAAU,EAAE,mBAAmB;QAC/B,gBAAgB,EAAE,yBAAyB;QAC3C,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,kBAAkB;QAC7B,QAAQ,EAAE,SAAS;QACnB,eAAe,EAAE,EAAE;QACnB,OAAO,EAAE,eAAe;KACzB;CACF,CAAC"}
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { getDefaultFont } from '@pdfme/common';
|
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, } from './constants.js';
|
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
4
|
import { addAlphaToHex } from '../renderUtils.js';
|
5
|
+
import { DEFAULT_OPACITY } from '../constants.js';
|
5
6
|
const mapVerticalAlignToFlex = (verticalAlignmentValue) => {
|
6
7
|
switch (verticalAlignmentValue) {
|
7
8
|
case VERTICAL_ALIGN_TOP:
|
@@ -25,23 +26,25 @@ const getBackgroundColor = (mode, value, schema, defaultBackgroundColor) => {
|
|
25
26
|
}
|
26
27
|
};
|
27
28
|
export const uiRender = async (arg) => {
|
28
|
-
const { value, schema, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, options, theme, } = arg;
|
29
|
+
const { value, schema, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, options, theme, _cache, } = arg;
|
29
30
|
const font = options?.font || getDefaultFont();
|
30
31
|
let dynamicFontSize = undefined;
|
32
|
+
const getCdfArg = (v) => ({
|
33
|
+
textSchema: schema,
|
34
|
+
font,
|
35
|
+
value: v,
|
36
|
+
startingFontSize: dynamicFontSize,
|
37
|
+
_cache,
|
38
|
+
});
|
31
39
|
if (schema.dynamicFontSize && value) {
|
32
|
-
dynamicFontSize = await calculateDynamicFontSize(
|
33
|
-
textSchema: schema,
|
34
|
-
font,
|
35
|
-
value,
|
36
|
-
startingFontSize: dynamicFontSize,
|
37
|
-
});
|
40
|
+
dynamicFontSize = await calculateDynamicFontSize(getCdfArg(value));
|
38
41
|
}
|
39
|
-
const fontKitFont = await getFontKitFont(schema, font);
|
42
|
+
const fontKitFont = await getFontKitFont(schema, font, _cache);
|
40
43
|
// Depending on vertical alignment, we need to move the top or bottom of the font to keep
|
41
44
|
// it within it's defined box and align it with the generated pdf.
|
42
45
|
const { topAdj, bottomAdj } = getBrowserVerticalFontAdjustments(fontKitFont, dynamicFontSize ?? schema.fontSize ?? DEFAULT_FONT_SIZE, schema.lineHeight ?? DEFAULT_LINE_HEIGHT, schema.verticalAlignment ?? DEFAULT_VERTICAL_ALIGNMENT);
|
43
|
-
const topAdjustment = topAdj;
|
44
|
-
const bottomAdjustment = bottomAdj;
|
46
|
+
const topAdjustment = topAdj.toString();
|
47
|
+
const bottomAdjustment = bottomAdj.toString();
|
45
48
|
const container = document.createElement('div');
|
46
49
|
const containerStyle = {
|
47
50
|
padding: 0,
|
@@ -53,12 +56,13 @@ export const uiRender = async (arg) => {
|
|
53
56
|
justifyContent: mapVerticalAlignToFlex(schema.verticalAlignment),
|
54
57
|
width: '100%',
|
55
58
|
height: '100%',
|
56
|
-
opacity: schema.opacity,
|
59
|
+
opacity: schema.opacity ?? DEFAULT_OPACITY,
|
57
60
|
};
|
58
61
|
Object.assign(container.style, containerStyle);
|
59
62
|
rootElement.innerHTML = '';
|
60
63
|
rootElement.appendChild(container);
|
61
|
-
const
|
64
|
+
const textBlockStyle = {
|
65
|
+
// Font formatting styles
|
62
66
|
fontFamily: schema.fontName ? `'${schema.fontName}'` : 'inherit',
|
63
67
|
color: schema.fontColor ? schema.fontColor : DEFAULT_FONT_COLOR,
|
64
68
|
fontSize: `${dynamicFontSize ?? schema.fontSize ?? DEFAULT_FONT_SIZE}pt`,
|
@@ -67,45 +71,71 @@ export const uiRender = async (arg) => {
|
|
67
71
|
textAlign: schema.alignment ?? DEFAULT_ALIGNMENT,
|
68
72
|
whiteSpace: 'pre-wrap',
|
69
73
|
wordBreak: 'break-word',
|
74
|
+
// Block layout styles
|
75
|
+
resize: 'none',
|
76
|
+
border: 'none',
|
77
|
+
outline: 'none',
|
78
|
+
marginBottom: bottomAdjustment + 'px',
|
79
|
+
paddingTop: topAdjustment + 'px',
|
80
|
+
backgroundColor: 'transparent',
|
70
81
|
};
|
82
|
+
const textBlock = document.createElement('div');
|
83
|
+
Object.assign(textBlock.style, textBlockStyle);
|
71
84
|
if (mode === 'form' || mode === 'designer') {
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
85
|
+
textBlock.contentEditable = 'plaintext-only';
|
86
|
+
textBlock.tabIndex = tabIndex || 0;
|
87
|
+
textBlock.innerText = value;
|
88
|
+
textBlock.addEventListener('blur', (e) => {
|
89
|
+
onChange && onChange(e.target.innerText);
|
90
|
+
stopEditing && stopEditing();
|
91
|
+
});
|
92
|
+
if (schema.dynamicFontSize) {
|
93
|
+
textBlock.addEventListener('keyup', () => {
|
94
|
+
setTimeout(() => {
|
95
|
+
void (async () => {
|
96
|
+
if (!textBlock.textContent)
|
97
|
+
return;
|
98
|
+
dynamicFontSize = await calculateDynamicFontSize(getCdfArg(textBlock.textContent));
|
99
|
+
textBlock.style.fontSize = `${dynamicFontSize}pt`;
|
100
|
+
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.toString() + 'px';
|
102
|
+
textBlock.style.marginBottom = newBottomAdj.toString() + 'px';
|
103
|
+
})();
|
104
|
+
}, 0);
|
105
|
+
});
|
106
|
+
}
|
107
|
+
if (placeholder && !value) {
|
108
|
+
textBlock.innerText = placeholder;
|
109
|
+
textBlock.style.color = PLACEHOLDER_FONT_COLOR;
|
110
|
+
if (schema.dynamicFontSize) {
|
111
|
+
const fontSize = await calculateDynamicFontSize(getCdfArg(placeholder));
|
112
|
+
textBlock.style.fontSize = `${fontSize}pt`;
|
113
|
+
}
|
114
|
+
textBlock.addEventListener('focus', () => {
|
115
|
+
if (textBlock.innerText === placeholder) {
|
116
|
+
textBlock.innerText = '';
|
117
|
+
textBlock.style.color = schema.fontColor ?? DEFAULT_FONT_COLOR;
|
118
|
+
}
|
119
|
+
});
|
120
|
+
}
|
121
|
+
container.appendChild(textBlock);
|
91
122
|
if (mode === 'designer') {
|
92
|
-
|
93
|
-
textarea
|
123
|
+
textBlock.focus();
|
124
|
+
// Set the focus to the end of the editable element when you focus, as we would for a textarea
|
125
|
+
const selection = window.getSelection();
|
126
|
+
const range = document.createRange();
|
127
|
+
range.selectNodeContents(textBlock);
|
128
|
+
range.collapse(false); // Collapse range to the end
|
129
|
+
selection?.removeAllRanges();
|
130
|
+
selection?.addRange(range);
|
94
131
|
}
|
95
132
|
}
|
96
133
|
else {
|
97
|
-
|
98
|
-
const divStyle = {
|
99
|
-
...fontStyles,
|
100
|
-
marginBottom: bottomAdjustment + 'px',
|
101
|
-
paddingTop: topAdjustment + 'px',
|
102
|
-
};
|
103
|
-
Object.assign(div.style, divStyle);
|
104
|
-
div.innerHTML = value
|
134
|
+
textBlock.innerHTML = value
|
105
135
|
.split('')
|
106
136
|
.map((l, i) => `<span style="letter-spacing:${String(value).length === i + 1 ? 0 : 'inherit'};">${l}</span>`)
|
107
137
|
.join('');
|
108
|
-
container.appendChild(
|
138
|
+
container.appendChild(textBlock);
|
109
139
|
}
|
110
140
|
};
|
111
141
|
//# sourceMappingURL=uiRender.js.map
|
@@ -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,
|
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,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,sBAAsB,GAAG,CAAC,sBAA0C,EAAE,EAAE;IAC5E,QAAQ,sBAAsB,EAAE;QAC9B,KAAK,kBAAkB;YACrB,OAAO,YAAY,CAAC;QACtB,KAAK,q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AAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,SAAS,IAAI,kBAAkB,CAAC;iBAChE;YACH,CAAC,CAAC,CAAC;SACJ;QAED,SAAS,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,4 +1,3 @@
|
|
1
1
|
export declare const BARCODE_TYPES: readonly ["qrcode", "japanpost", "ean13", "ean8", "code39", "code128", "nw7", "itf14", "upca", "upce", "gs1datamatrix"];
|
2
2
|
export declare const DEFAULT_BARCODE_BG_COLOR = "#ffffff";
|
3
3
|
export declare const DEFAULT_BARCODE_COLOR = "#000000";
|
4
|
-
export declare const DEFAULT_OPACITY = 1;
|
@@ -11,10 +11,10 @@ export declare const DEFAULT_VERTICAL_ALIGNMENT: VERTICAL_ALIGNMENT;
|
|
11
11
|
export declare const DEFAULT_LINE_HEIGHT = 1;
|
12
12
|
export declare const DEFAULT_CHARACTER_SPACING = 0;
|
13
13
|
export declare const DEFAULT_FONT_COLOR = "#000000";
|
14
|
+
export declare const PLACEHOLDER_FONT_COLOR = "#A0A0A0";
|
14
15
|
export declare const DYNAMIC_FIT_VERTICAL: DYNAMIC_FONT_SIZE_FIT;
|
15
16
|
export declare const DYNAMIC_FIT_HORIZONTAL: DYNAMIC_FONT_SIZE_FIT;
|
16
17
|
export declare const DEFAULT_DYNAMIC_FIT: DYNAMIC_FONT_SIZE_FIT;
|
17
18
|
export declare const DEFAULT_DYNAMIC_MIN_FONT_SIZE = 4;
|
18
19
|
export declare const DEFAULT_DYNAMIC_MAX_FONT_SIZE = 72;
|
19
20
|
export declare const FONT_SIZE_ADJUSTMENT = 0.25;
|
20
|
-
export declare const DEFAULT_OPACITY = 1;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as fontkit from 'fontkit';
|
2
2
|
import type { Font as FontKitFont } from 'fontkit';
|
3
|
-
import {
|
3
|
+
import { Font } from '@pdfme/common';
|
4
4
|
import type { TextSchema, FontWidthCalcValues } from './types';
|
5
5
|
export declare const getBrowserVerticalFontAdjustments: (fontKitFont: FontKitFont, fontSize: number, lineHeight: number, verticalAlignment: string) => {
|
6
6
|
topAdj: number;
|
@@ -9,7 +9,7 @@ export declare const getBrowserVerticalFontAdjustments: (fontKitFont: FontKitFon
|
|
9
9
|
export declare const getFontDescentInPt: (fontKitFont: FontKitFont, fontSize: number) => number;
|
10
10
|
export declare const heightOfFontAtSize: (fontKitFont: FontKitFont, fontSize: number) => number;
|
11
11
|
export declare const widthOfTextAtSize: (text: string, fontKitFont: FontKitFont, fontSize: number, characterSpacing: number) => number;
|
12
|
-
export declare const getFontKitFont: (textSchema:
|
12
|
+
export declare const getFontKitFont: (textSchema: TextSchema, font: Font, _cache: Map<any, any>) => Promise<fontkit.Font>;
|
13
13
|
/**
|
14
14
|
* Recursively splits the line at getSplitPosition.
|
15
15
|
* If there is some leftover, split the rest again in the same manner.
|
@@ -21,9 +21,10 @@ export declare const getSplittedLines: (textLine: string, calcValues: FontWidthC
|
|
21
21
|
* Calculating space usage involves splitting lines where they exceed
|
22
22
|
* the box width based on the proposed size.
|
23
23
|
*/
|
24
|
-
export declare const calculateDynamicFontSize: ({ textSchema, font, value, startingFontSize, }: {
|
24
|
+
export declare const calculateDynamicFontSize: ({ textSchema, font, value, startingFontSize, _cache, }: {
|
25
25
|
textSchema: TextSchema;
|
26
26
|
font: Font;
|
27
27
|
value: string;
|
28
28
|
startingFontSize?: number | undefined;
|
29
|
+
_cache: Map<any, any>;
|
29
30
|
}) => Promise<number>;
|