@pdfme/schemas 6.1.1-dev.8 → 6.1.2
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/box.d.ts +45 -0
- package/dist/{builtins-pN5NVCSV.js → builtins-BB2DHceW.js} +216 -102
- package/dist/builtins-BB2DHceW.js.map +1 -0
- package/dist/builtins.js +1 -1
- package/dist/dynamicLayout.d.ts +1 -0
- package/dist/dynamicLayout.js +5 -5
- package/dist/dynamicLayout.js.map +1 -1
- package/dist/{dynamicTemplate-CkrZKlg-.js → dynamicTemplate-B4GCNLF9.js} +19 -53
- package/dist/dynamicTemplate-B4GCNLF9.js.map +1 -0
- package/dist/{dynamicTemplate-Cy07Imb5.js → dynamicTemplate-BwzF9C1L.js} +3 -6
- package/dist/{dynamicTemplate-Cy07Imb5.js.map → dynamicTemplate-BwzF9C1L.js.map} +1 -1
- package/dist/{dynamicTemplate-ByBNu75x.js → dynamicTemplate-C7MdZxPm.js} +18 -14
- package/dist/dynamicTemplate-C7MdZxPm.js.map +1 -0
- package/dist/{helper-BaUAusvL.js → helper-CEme39Uo.js} +2 -2
- package/dist/{helper-BaUAusvL.js.map → helper-CEme39Uo.js.map} +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +253 -75
- package/dist/index.js.map +1 -1
- package/dist/list/types.d.ts +0 -5
- package/dist/lists.d.ts +2 -1
- package/dist/lists.js +3 -2
- package/dist/{measure-h-7PUE2B.js → measure-L5diay3k.js} +37 -9
- package/dist/measure-L5diay3k.js.map +1 -0
- package/dist/{helper-CBd9plP_.js → splitRange-DmVDtmzO.js} +105 -4
- package/dist/splitRange-DmVDtmzO.js.map +1 -0
- package/dist/splitRange.d.ts +16 -0
- package/dist/tables/helper.d.ts +8 -100
- package/dist/tables/types.d.ts +2 -6
- package/dist/tables.d.ts +1 -0
- package/dist/tables.js +3 -2
- package/dist/text/measure.d.ts +9 -3
- package/dist/text/overflow.d.ts +6 -2
- package/dist/text/richTextPdfRender.d.ts +1 -1
- package/dist/text/types.d.ts +4 -5
- package/dist/texts.d.ts +2 -1
- package/dist/texts.js +4 -4
- package/dist/types.d.ts +3 -1
- package/dist/utils-zDZkqBnX.js +250 -0
- package/dist/utils-zDZkqBnX.js.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +3 -216
- package/package.json +1 -1
- package/dist/builtins-pN5NVCSV.js.map +0 -1
- package/dist/dynamicTemplate-ByBNu75x.js.map +0 -1
- package/dist/dynamicTemplate-CkrZKlg-.js.map +0 -1
- package/dist/helper-CBd9plP_.js.map +0 -1
- package/dist/measure-h-7PUE2B.js.map +0 -1
- package/dist/utils.js.map +0 -1
package/dist/box.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PropPanelSchema } from '@pdfme/common';
|
|
2
|
+
export type BoxDimension = {
|
|
3
|
+
top: number;
|
|
4
|
+
right: number;
|
|
5
|
+
bottom: number;
|
|
6
|
+
left: number;
|
|
7
|
+
};
|
|
8
|
+
export type BoxStyleSchema = {
|
|
9
|
+
borderWidth?: Partial<BoxDimension>;
|
|
10
|
+
padding?: Partial<BoxDimension>;
|
|
11
|
+
};
|
|
12
|
+
export type BoxLikeSchema = BoxStyleSchema & {
|
|
13
|
+
position: {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
};
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
export declare const createBoxDimension: (value?: number) => BoxDimension;
|
|
21
|
+
export declare const normalizeBoxDimension: (value?: Partial<BoxDimension>) => BoxDimension;
|
|
22
|
+
export declare const getBoxInsets: (schema: BoxStyleSchema) => {
|
|
23
|
+
borderWidth: BoxDimension;
|
|
24
|
+
padding: BoxDimension;
|
|
25
|
+
};
|
|
26
|
+
export declare const getBoxHorizontalInset: (schema: BoxStyleSchema) => number;
|
|
27
|
+
export declare const getBoxVerticalInset: (schema: BoxStyleSchema) => number;
|
|
28
|
+
export declare const getBoxContentArea: <T extends BoxLikeSchema>(schema: T) => {
|
|
29
|
+
position: {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
};
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
leftInset: number;
|
|
36
|
+
topInset: number;
|
|
37
|
+
rightInset: number;
|
|
38
|
+
bottomInset: number;
|
|
39
|
+
};
|
|
40
|
+
export declare const hasBoxDimension: (dimension?: Partial<BoxDimension>) => boolean;
|
|
41
|
+
export declare const getSplitBoxDimension: (dimension: Partial<BoxDimension> | undefined, range: {
|
|
42
|
+
start: number;
|
|
43
|
+
end?: number;
|
|
44
|
+
}, totalUnits: number) => BoxDimension;
|
|
45
|
+
export declare const getBoxDimensionPropPanelSchema: (step?: number) => Record<string, PropPanelSchema>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import {
|
|
3
|
-
import { c as HEX_COLOR_PATTERN } from "./dynamicTemplate-
|
|
4
|
-
import {
|
|
5
|
-
import { DEFAULT_FONT_NAME, getDefaultFont, getFallbackFontName, getInternalLinkTarget, mm2pt, normalizeLinkHref, normalizeSafeLinkUri, registerInternalLinkAnnotation } from "@pdfme/common";
|
|
1
|
+
import { $ as VERTICAL_ALIGN_MIDDLE, A as ALIGN_RIGHT, B as DYNAMIC_FIT_VERTICAL, C as getBoxInsets, D as ALIGN_CENTER, E as hasBoxDimension, F as DEFAULT_FONT_COLOR, G as PLACEHOLDER_FONT_COLOR, H as FONT_VARIANT_FALLBACK_ERROR, I as DEFAULT_FONT_VARIANT_FALLBACK, J as TEXT_FORMAT_INLINE_MARKDOWN, K as SYNTHETIC_BOLD_CSS_TEXT_SHADOW, L as DEFAULT_TEXT_FORMAT, M as CODE_HORIZONTAL_PADDING, N as DEFAULT_ALIGNMENT, O as ALIGN_JUSTIFY, P as DEFAULT_DYNAMIC_FIT, Q as VERTICAL_ALIGN_BOTTOM, R as DEFAULT_TEXT_OVERFLOW, S as getBoxDimensionPropPanelSchema, U as FONT_VARIANT_FALLBACK_PLAIN, W as FONT_VARIANT_FALLBACK_SYNTHETIC, X as TEXT_OVERFLOW_EXPAND, Y as TEXT_FORMAT_PLAIN, Z as TEXT_OVERFLOW_VISIBLE, _ as isFirefox, b as createBoxDimension, d as calculateDynamicFontSize, f as fetchRemoteFontData, g as heightOfFontAtSize, h as getFontKitFont, j as CODE_BACKGROUND_COLOR, m as getFontDescentInPt, p as getBrowserVerticalFontAdjustments, q as SYNTHETIC_BOLD_OFFSET_RATIO, u as getTextLineRange, v as splitTextToSize, x as getBoxContentArea, y as widthOfTextAtSize, z as DYNAMIC_FIT_HORIZONTAL } from "./splitRange-DmVDtmzO.js";
|
|
2
|
+
import { _ as stripInlineMarkdown, d as isInlineMarkdownTextSchema, f as layoutRichTextLines, g as parseInlineMarkdown, l as calculateDynamicRichTextFontSize, m as resolveRichTextRuns, s as plainTextLinesToValue, t as applyTextLineRange, u as countRichTextLineGraphemes } from "./measure-L5diay3k.js";
|
|
3
|
+
import { c as HEX_COLOR_PATTERN } from "./dynamicTemplate-B4GCNLF9.js";
|
|
4
|
+
import { c as isEditable, i as createSvgStr, n as convertForPdfLayoutProps, o as hex2PrintingColor, u as rotatePoint } from "./utils-zDZkqBnX.js";
|
|
5
|
+
import { DEFAULT_FONT_NAME, getDefaultFont, getFallbackFontName, getInternalLinkTarget, isBlankPdf, mm2pt, normalizeLinkHref, normalizeSafeLinkUri, registerInternalLinkAnnotation } from "@pdfme/common";
|
|
6
6
|
import { PDFName, PDFString } from "@pdfme/pdf-lib";
|
|
7
7
|
import { AlignCenter, AlignJustify, AlignLeft, AlignRight, ArrowDownToLine, ArrowUpToLine, Strikethrough, TextCursorInput, Underline } from "lucide";
|
|
8
8
|
//#region src/text/linkAnnotation.ts
|
|
@@ -36,7 +36,7 @@ var addUriLinkAnnotation = (arg) => {
|
|
|
36
36
|
//#region src/text/richTextPdfRender.ts
|
|
37
37
|
var getSyntheticBoldWidth = (run, fontSize) => run.syntheticBold ? fontSize * SYNTHETIC_BOLD_OFFSET_RATIO * 2 : 0;
|
|
38
38
|
var getSyntheticItalicWidth = (run, fontSize) => run.syntheticItalic ? heightOfFontAtSize(run.fontKitFont, fontSize) * Math.tan(12 * Math.PI / 180) : 0;
|
|
39
|
-
var getRunWidth = (run, fontSize, characterSpacing) => widthOfTextAtSize(run.text, run.fontKitFont, fontSize, characterSpacing) + getSyntheticBoldWidth(run, fontSize) + getSyntheticItalicWidth(run, fontSize);
|
|
39
|
+
var getRunWidth = (run, fontSize, characterSpacing) => widthOfTextAtSize(run.text, run.fontKitFont, fontSize, characterSpacing) + getSyntheticBoldWidth(run, fontSize) + getSyntheticItalicWidth(run, fontSize) + (run.code ? CODE_HORIZONTAL_PADDING * 2 : 0);
|
|
40
40
|
var getPdfFontFromObj = (run, pdfFontObj) => {
|
|
41
41
|
const pdfFont = pdfFontObj[run.fontName];
|
|
42
42
|
if (!pdfFont) throw new Error(`[@pdfme/schemas] Missing embedded font "${run.fontName}".`);
|
|
@@ -117,10 +117,12 @@ var getLinkAnnotationRect = (arg) => {
|
|
|
117
117
|
var drawRun = (arg) => {
|
|
118
118
|
const { page, pdfLib, run, pdfFont, x, y, rotate, pivotPoint, fontSize, lineHeight, color, opacity, colorType, characterSpacing, strikethrough, underline } = arg;
|
|
119
119
|
const runWidth = getRunWidth(run, fontSize, characterSpacing);
|
|
120
|
+
const codePadding = run.code ? CODE_HORIZONTAL_PADDING : 0;
|
|
121
|
+
const textX = x + codePadding;
|
|
122
|
+
const textWidth = runWidth - codePadding * 2;
|
|
120
123
|
const textHeight = heightOfFontAtSize(run.fontKitFont, fontSize);
|
|
121
124
|
if (run.code) {
|
|
122
|
-
const
|
|
123
|
-
const bgX = x - padding;
|
|
125
|
+
const bgX = x;
|
|
124
126
|
const bgY = y - textHeight * .2;
|
|
125
127
|
const bgPoint = rotate.angle === 0 ? {
|
|
126
128
|
x: bgX,
|
|
@@ -132,7 +134,7 @@ var drawRun = (arg) => {
|
|
|
132
134
|
page.drawRectangle({
|
|
133
135
|
x: bgPoint.x,
|
|
134
136
|
y: bgPoint.y,
|
|
135
|
-
width: runWidth
|
|
137
|
+
width: runWidth,
|
|
136
138
|
height: textHeight * 1.2,
|
|
137
139
|
rotate,
|
|
138
140
|
color: hex2PrintingColor(CODE_BACKGROUND_COLOR, colorType),
|
|
@@ -141,9 +143,9 @@ var drawRun = (arg) => {
|
|
|
141
143
|
}
|
|
142
144
|
if (strikethrough && runWidth > 0) drawDecorationLine({
|
|
143
145
|
page,
|
|
144
|
-
x,
|
|
146
|
+
x: textX,
|
|
145
147
|
y: y + textHeight / 3,
|
|
146
|
-
width:
|
|
148
|
+
width: textWidth,
|
|
147
149
|
rotate,
|
|
148
150
|
pivotPoint,
|
|
149
151
|
fontSize,
|
|
@@ -152,9 +154,9 @@ var drawRun = (arg) => {
|
|
|
152
154
|
});
|
|
153
155
|
if (underline && runWidth > 0) drawDecorationLine({
|
|
154
156
|
page,
|
|
155
|
-
x,
|
|
157
|
+
x: textX,
|
|
156
158
|
y: y - textHeight / 12,
|
|
157
|
-
width:
|
|
159
|
+
width: textWidth,
|
|
158
160
|
rotate,
|
|
159
161
|
pivotPoint,
|
|
160
162
|
fontSize,
|
|
@@ -181,14 +183,14 @@ var drawRun = (arg) => {
|
|
|
181
183
|
...run.syntheticItalic ? { ySkew: pdfLib.degrees(12) } : {}
|
|
182
184
|
});
|
|
183
185
|
};
|
|
184
|
-
drawAt(
|
|
186
|
+
drawAt(textX);
|
|
185
187
|
if (run.syntheticBold) {
|
|
186
188
|
const offset = fontSize * SYNTHETIC_BOLD_OFFSET_RATIO;
|
|
187
|
-
for (let i = 1; i <= 2; i++) drawAt(
|
|
189
|
+
for (let i = 1; i <= 2; i++) drawAt(textX + offset * i);
|
|
188
190
|
}
|
|
189
191
|
};
|
|
190
192
|
var renderInlineMarkdownText = async (arg) => {
|
|
191
|
-
const { value, schema, font, embedPdfFont, fontKitFont, pdfDoc, page, pdfLib, _cache, colorType, fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing, x, width, height,
|
|
193
|
+
const { value, schema, font, embedPdfFont, fontKitFont, pdfDoc, page, pdfLib, _cache, colorType, fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing, x, y, width, height, pivotPoint, rotate, opacity } = arg;
|
|
192
194
|
const allLines = layoutRichTextLines({
|
|
193
195
|
runs: await resolveRichTextRuns({
|
|
194
196
|
runs: parseInlineMarkdown(value),
|
|
@@ -200,8 +202,9 @@ var renderInlineMarkdownText = async (arg) => {
|
|
|
200
202
|
characterSpacing,
|
|
201
203
|
boxWidthInPt: width
|
|
202
204
|
});
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
+
const lineRange = getTextLineRange(schema);
|
|
206
|
+
const lines = applyTextLineRange(allLines, lineRange);
|
|
207
|
+
const lineRangeStart = lineRange?.start ?? 0;
|
|
205
208
|
const pdfFontObj = await embedFontsForRuns(lines.flatMap((line) => line.runs), embedPdfFont);
|
|
206
209
|
const firstLineTextHeight = heightOfFontAtSize(fontKitFont, fontSize);
|
|
207
210
|
const descent = getFontDescentInPt(fontKitFont, fontSize);
|
|
@@ -227,7 +230,7 @@ var renderInlineMarkdownText = async (arg) => {
|
|
|
227
230
|
let xLine = x;
|
|
228
231
|
if (alignment === "center") xLine += (width - textWidth) / 2;
|
|
229
232
|
else if (alignment === "right") xLine += width - textWidth;
|
|
230
|
-
const yLine =
|
|
233
|
+
const yLine = y + height - yOffset - lineHeight * fontSize * rowIndex;
|
|
231
234
|
page.pushOperators(pdfLib.setCharacterSpacing(spacing));
|
|
232
235
|
if (schema.strikethrough || schema.underline) {
|
|
233
236
|
const textHeight = Math.max(...line.runs.map((run) => heightOfFontAtSize(run.fontKitFont, fontSize)));
|
|
@@ -304,8 +307,11 @@ var renderInlineMarkdownText = async (arg) => {
|
|
|
304
307
|
};
|
|
305
308
|
//#endregion
|
|
306
309
|
//#region src/text/overflow.ts
|
|
307
|
-
var
|
|
308
|
-
var
|
|
310
|
+
var TEXT_OVERFLOW_EXPAND_SCHEMA_TYPES = new Set(["text", "multiVariableText"]);
|
|
311
|
+
var isTextOverflowExpandSchema = (schema) => schema.type === void 0 || TEXT_OVERFLOW_EXPAND_SCHEMA_TYPES.has(schema.type);
|
|
312
|
+
var canUseTextOverflowExpand = (schema, basePdf) => !isTextOverflowExpandSchema(schema) || basePdf === void 0 || isBlankPdf(basePdf);
|
|
313
|
+
var isTextOverflowExpand = (schema, basePdf) => canUseTextOverflowExpand(schema, basePdf) && schema.overflow === "expand";
|
|
314
|
+
var shouldUseDynamicFontSize = (schema, basePdf) => Boolean(schema.dynamicFontSize) && !isTextOverflowExpand(schema, basePdf);
|
|
309
315
|
//#endregion
|
|
310
316
|
//#region src/text/pdfRender.ts
|
|
311
317
|
var PDF_FONT_CACHE_KEY = "text-pdf-font-cache";
|
|
@@ -332,8 +338,8 @@ var embedAndGetFont = (arg) => {
|
|
|
332
338
|
pdfFontCache[fontName] = pdfFontPromise;
|
|
333
339
|
return pdfFontPromise;
|
|
334
340
|
};
|
|
335
|
-
var getFontProp = ({ value, fontKitFont, schema, colorType, fontSize: resolvedFontSize }) => {
|
|
336
|
-
const fontSize = resolvedFontSize ?? (shouldUseDynamicFontSize(schema) ? calculateDynamicFontSize({
|
|
341
|
+
var getFontProp = ({ value, fontKitFont, schema, basePdf, colorType, fontSize: resolvedFontSize }) => {
|
|
342
|
+
const fontSize = resolvedFontSize ?? (shouldUseDynamicFontSize(schema, basePdf) ? calculateDynamicFontSize({
|
|
337
343
|
textSchema: schema,
|
|
338
344
|
fontKitFont,
|
|
339
345
|
value
|
|
@@ -354,11 +360,37 @@ var getGraphemeSegmenter = () => {
|
|
|
354
360
|
return graphemeSegmenter;
|
|
355
361
|
};
|
|
356
362
|
var pdfRender = async (arg) => {
|
|
357
|
-
const { value, pdfDoc, pdfLib, page, options, schema, _cache } = arg;
|
|
358
|
-
if (!value) return;
|
|
363
|
+
const { value, pdfDoc, pdfLib, page, options, schema, basePdf, _cache } = arg;
|
|
359
364
|
const { font = getDefaultFont(), colorType } = options;
|
|
365
|
+
const pageHeight = page.getHeight();
|
|
366
|
+
const { width, height, rotate, position: { x, y }, opacity } = convertForPdfLayoutProps({
|
|
367
|
+
schema,
|
|
368
|
+
pageHeight,
|
|
369
|
+
applyRotateTranslate: false
|
|
370
|
+
});
|
|
371
|
+
const pivotPoint = {
|
|
372
|
+
x: x + width / 2,
|
|
373
|
+
y: pageHeight - mm2pt(schema.position.y) - height / 2
|
|
374
|
+
};
|
|
375
|
+
drawTextBoxDecoration({
|
|
376
|
+
page,
|
|
377
|
+
schema,
|
|
378
|
+
colorType,
|
|
379
|
+
x,
|
|
380
|
+
y,
|
|
381
|
+
width,
|
|
382
|
+
height,
|
|
383
|
+
rotate,
|
|
384
|
+
pivotPoint
|
|
385
|
+
});
|
|
386
|
+
if (!value) return;
|
|
360
387
|
const fontName = schema.fontName ? schema.fontName : getFallbackFontName(font);
|
|
361
388
|
const enableInlineMarkdown = isInlineMarkdownTextSchema(schema);
|
|
389
|
+
const contentArea = getBoxContentArea(schema);
|
|
390
|
+
const contentX = x + mm2pt(contentArea.leftInset);
|
|
391
|
+
const contentY = y + mm2pt(contentArea.bottomInset);
|
|
392
|
+
const contentWidth = mm2pt(contentArea.width);
|
|
393
|
+
const contentHeight = mm2pt(contentArea.height);
|
|
362
394
|
const pdfFontValuePromise = enableInlineMarkdown ? void 0 : embedAndGetFont({
|
|
363
395
|
pdfDoc,
|
|
364
396
|
font,
|
|
@@ -370,48 +402,15 @@ var pdfRender = async (arg) => {
|
|
|
370
402
|
value: enableInlineMarkdown ? stripInlineMarkdown(value) : value,
|
|
371
403
|
fontKitFont,
|
|
372
404
|
schema,
|
|
405
|
+
basePdf,
|
|
373
406
|
colorType,
|
|
374
|
-
fontSize: enableInlineMarkdown && shouldUseDynamicFontSize(schema) ? await calculateDynamicRichTextFontSize({
|
|
407
|
+
fontSize: enableInlineMarkdown && shouldUseDynamicFontSize(schema, basePdf) ? await calculateDynamicRichTextFontSize({
|
|
375
408
|
value,
|
|
376
409
|
schema,
|
|
377
410
|
font,
|
|
378
411
|
_cache
|
|
379
412
|
}) : void 0
|
|
380
413
|
});
|
|
381
|
-
const pageHeight = page.getHeight();
|
|
382
|
-
const { width, height, rotate, position: { x, y }, opacity } = convertForPdfLayoutProps({
|
|
383
|
-
schema,
|
|
384
|
-
pageHeight,
|
|
385
|
-
applyRotateTranslate: false
|
|
386
|
-
});
|
|
387
|
-
const pivotPoint = {
|
|
388
|
-
x: x + width / 2,
|
|
389
|
-
y: pageHeight - mm2pt(schema.position.y) - height / 2
|
|
390
|
-
};
|
|
391
|
-
if (schema.backgroundColor) {
|
|
392
|
-
const color = hex2PrintingColor(schema.backgroundColor, colorType);
|
|
393
|
-
if (rotate.angle !== 0) {
|
|
394
|
-
const rotatedPoint = rotatePoint({
|
|
395
|
-
x,
|
|
396
|
-
y
|
|
397
|
-
}, pivotPoint, rotate.angle);
|
|
398
|
-
page.drawRectangle({
|
|
399
|
-
x: rotatedPoint.x,
|
|
400
|
-
y: rotatedPoint.y,
|
|
401
|
-
width,
|
|
402
|
-
height,
|
|
403
|
-
rotate,
|
|
404
|
-
color
|
|
405
|
-
});
|
|
406
|
-
} else page.drawRectangle({
|
|
407
|
-
x,
|
|
408
|
-
y,
|
|
409
|
-
width,
|
|
410
|
-
height,
|
|
411
|
-
rotate,
|
|
412
|
-
color
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
414
|
if (enableInlineMarkdown) {
|
|
416
415
|
await renderInlineMarkdownText({
|
|
417
416
|
value,
|
|
@@ -435,10 +434,10 @@ var pdfRender = async (arg) => {
|
|
|
435
434
|
verticalAlignment,
|
|
436
435
|
lineHeight,
|
|
437
436
|
characterSpacing,
|
|
438
|
-
x,
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
437
|
+
x: contentX,
|
|
438
|
+
y: contentY,
|
|
439
|
+
width: contentWidth,
|
|
440
|
+
height: contentHeight,
|
|
442
441
|
pivotPoint,
|
|
443
442
|
rotate,
|
|
444
443
|
opacity
|
|
@@ -455,16 +454,16 @@ var pdfRender = async (arg) => {
|
|
|
455
454
|
characterSpacing,
|
|
456
455
|
fontSize,
|
|
457
456
|
fontKitFont,
|
|
458
|
-
boxWidthInPt:
|
|
459
|
-
}), schema
|
|
457
|
+
boxWidthInPt: contentWidth
|
|
458
|
+
}), getTextLineRange(schema));
|
|
460
459
|
const needsTextWidth = alignment !== "left" || Boolean(schema.strikethrough || schema.underline);
|
|
461
460
|
const needsTextHeight = Boolean(schema.strikethrough || schema.underline);
|
|
462
461
|
let yOffset = 0;
|
|
463
462
|
if (verticalAlignment === "top") yOffset = firstLineTextHeight + halfLineHeightAdjustment;
|
|
464
463
|
else {
|
|
465
464
|
const otherLinesHeight = lineHeight * fontSize * (lines.length - 1);
|
|
466
|
-
if (verticalAlignment === "bottom") yOffset =
|
|
467
|
-
else if (verticalAlignment === "middle") yOffset = (
|
|
465
|
+
if (verticalAlignment === "bottom") yOffset = contentHeight - otherLinesHeight + descent - halfLineHeightAdjustment;
|
|
466
|
+
else if (verticalAlignment === "middle") yOffset = (contentHeight - otherLinesHeight - firstLineTextHeight + descent) / 2 + firstLineTextHeight;
|
|
468
467
|
}
|
|
469
468
|
lines.forEach((line, rowIndex) => {
|
|
470
469
|
const trimmed = line.replace("\n", "");
|
|
@@ -472,10 +471,10 @@ var pdfRender = async (arg) => {
|
|
|
472
471
|
const textHeight = needsTextHeight ? heightOfFontAtSize(fontKitFont, fontSize) : 0;
|
|
473
472
|
const rowYOffset = lineHeight * fontSize * rowIndex;
|
|
474
473
|
if (line === "") line = "\r\n";
|
|
475
|
-
let xLine =
|
|
476
|
-
if (alignment === "center") xLine += (
|
|
477
|
-
else if (alignment === "right") xLine +=
|
|
478
|
-
let yLine =
|
|
474
|
+
let xLine = contentX;
|
|
475
|
+
if (alignment === "center") xLine += (contentWidth - textWidth) / 2;
|
|
476
|
+
else if (alignment === "right") xLine += contentWidth - textWidth;
|
|
477
|
+
let yLine = contentY + contentHeight - yOffset - rowYOffset;
|
|
479
478
|
if (schema.strikethrough && textWidth > 0) {
|
|
480
479
|
const _x = xLine + textWidth + 1;
|
|
481
480
|
const _y = yLine + textHeight / 3;
|
|
@@ -522,7 +521,7 @@ var pdfRender = async (arg) => {
|
|
|
522
521
|
if (alignment === "justify" && line.slice(-1) !== "\n") {
|
|
523
522
|
const iterator = getGraphemeSegmenter().segment(trimmed)[Symbol.iterator]();
|
|
524
523
|
const len = Array.from(iterator).length;
|
|
525
|
-
spacing += (
|
|
524
|
+
spacing += (contentWidth - textWidth) / len;
|
|
526
525
|
}
|
|
527
526
|
page.pushOperators(pdfLib.setCharacterSpacing(spacing));
|
|
528
527
|
page.drawText(trimmed, {
|
|
@@ -537,6 +536,75 @@ var pdfRender = async (arg) => {
|
|
|
537
536
|
});
|
|
538
537
|
});
|
|
539
538
|
};
|
|
539
|
+
var drawTextBoxDecoration = (arg) => {
|
|
540
|
+
const { page, schema, colorType, x, y, width, height, rotate, pivotPoint } = arg;
|
|
541
|
+
const { borderWidth } = getBoxInsets(schema);
|
|
542
|
+
const opacity = schema.opacity ?? 1;
|
|
543
|
+
const drawRectangle = (rect) => {
|
|
544
|
+
if (rect.width <= 0 || rect.height <= 0) return;
|
|
545
|
+
const point = rotate.angle === 0 ? {
|
|
546
|
+
x: rect.x,
|
|
547
|
+
y: rect.y
|
|
548
|
+
} : rotatePoint({
|
|
549
|
+
x: rect.x,
|
|
550
|
+
y: rect.y
|
|
551
|
+
}, pivotPoint, rotate.angle);
|
|
552
|
+
page.drawRectangle({
|
|
553
|
+
x: point.x,
|
|
554
|
+
y: point.y,
|
|
555
|
+
width: rect.width,
|
|
556
|
+
height: rect.height,
|
|
557
|
+
rotate,
|
|
558
|
+
color: rect.color,
|
|
559
|
+
opacity
|
|
560
|
+
});
|
|
561
|
+
};
|
|
562
|
+
if (schema.backgroundColor) {
|
|
563
|
+
const color = hex2PrintingColor(schema.backgroundColor, colorType);
|
|
564
|
+
if (color) drawRectangle({
|
|
565
|
+
x,
|
|
566
|
+
y,
|
|
567
|
+
width,
|
|
568
|
+
height,
|
|
569
|
+
color
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
if (!schema.borderColor || !hasBoxDimension(schema.borderWidth)) return;
|
|
573
|
+
const color = hex2PrintingColor(schema.borderColor, colorType);
|
|
574
|
+
if (!color) return;
|
|
575
|
+
const top = mm2pt(borderWidth.top);
|
|
576
|
+
const right = mm2pt(borderWidth.right);
|
|
577
|
+
const bottom = mm2pt(borderWidth.bottom);
|
|
578
|
+
const left = mm2pt(borderWidth.left);
|
|
579
|
+
drawRectangle({
|
|
580
|
+
x,
|
|
581
|
+
y: y + height - top,
|
|
582
|
+
width,
|
|
583
|
+
height: top,
|
|
584
|
+
color
|
|
585
|
+
});
|
|
586
|
+
drawRectangle({
|
|
587
|
+
x: x + width - right,
|
|
588
|
+
y,
|
|
589
|
+
width: right,
|
|
590
|
+
height,
|
|
591
|
+
color
|
|
592
|
+
});
|
|
593
|
+
drawRectangle({
|
|
594
|
+
x,
|
|
595
|
+
y,
|
|
596
|
+
width,
|
|
597
|
+
height: bottom,
|
|
598
|
+
color
|
|
599
|
+
});
|
|
600
|
+
drawRectangle({
|
|
601
|
+
x,
|
|
602
|
+
y,
|
|
603
|
+
width: left,
|
|
604
|
+
height,
|
|
605
|
+
color
|
|
606
|
+
});
|
|
607
|
+
};
|
|
540
608
|
//#endregion
|
|
541
609
|
//#region src/text/icons/index.ts
|
|
542
610
|
var TextStrikethroughIcon = createSvgStr(Strikethrough);
|
|
@@ -622,8 +690,8 @@ function getExtraFormatterSchema(i18n) {
|
|
|
622
690
|
//#endregion
|
|
623
691
|
//#region src/text/propPanel.ts
|
|
624
692
|
var UseDynamicFontSize = (props) => {
|
|
625
|
-
const { rootElement, changeSchemas, activeSchema, i18n } = props;
|
|
626
|
-
const isExpand = isTextOverflowExpand(activeSchema);
|
|
693
|
+
const { rootElement, changeSchemas, activeSchema, i18n, basePdf } = props;
|
|
694
|
+
const isExpand = isTextOverflowExpand(activeSchema, basePdf);
|
|
627
695
|
const checkbox = document.createElement("input");
|
|
628
696
|
checkbox.type = "checkbox";
|
|
629
697
|
checkbox.checked = !isExpand && Boolean(activeSchema?.dynamicFontSize);
|
|
@@ -671,7 +739,7 @@ var UseInlineMarkdown = (props) => {
|
|
|
671
739
|
rootElement.appendChild(label);
|
|
672
740
|
};
|
|
673
741
|
var propPanel = {
|
|
674
|
-
schema: ({ options, activeSchema, i18n }) => {
|
|
742
|
+
schema: ({ options, activeSchema, i18n, basePdf }) => {
|
|
675
743
|
const font = options.font || { [DEFAULT_FONT_NAME]: {
|
|
676
744
|
data: "",
|
|
677
745
|
fallback: true
|
|
@@ -679,7 +747,8 @@ var propPanel = {
|
|
|
679
747
|
const fontNames = Object.keys(font);
|
|
680
748
|
const fallbackFontName = getFallbackFontName(font);
|
|
681
749
|
const activeTextSchema = activeSchema;
|
|
682
|
-
const
|
|
750
|
+
const canExpandOverflow = canUseTextOverflowExpand(activeTextSchema, basePdf);
|
|
751
|
+
const enableDynamicFont = !isTextOverflowExpand(activeTextSchema, basePdf) && Boolean(activeSchema?.dynamicFontSize);
|
|
683
752
|
const hideTextFormat = activeTextSchema.type === "text" && activeTextSchema.readOnly !== true;
|
|
684
753
|
const enableInlineMarkdown = activeTextSchema.textFormat === "inline-markdown" && !hideTextFormat;
|
|
685
754
|
const baseFontName = activeTextSchema.fontName && font[activeTextSchema.fontName] ? activeTextSchema.fontName : fallbackFontName;
|
|
@@ -690,6 +759,13 @@ var propPanel = {
|
|
|
690
759
|
label: name,
|
|
691
760
|
value: name
|
|
692
761
|
}))];
|
|
762
|
+
const overflowOptions = [{
|
|
763
|
+
label: i18n("schemas.text.overflowVisible"),
|
|
764
|
+
value: TEXT_OVERFLOW_VISIBLE
|
|
765
|
+
}, ...canExpandOverflow ? [{
|
|
766
|
+
label: i18n("schemas.text.overflowExpand"),
|
|
767
|
+
value: TEXT_OVERFLOW_EXPAND
|
|
768
|
+
}] : []];
|
|
693
769
|
return {
|
|
694
770
|
fontName: {
|
|
695
771
|
title: i18n("schemas.text.fontName"),
|
|
@@ -734,13 +810,7 @@ var propPanel = {
|
|
|
734
810
|
type: "string",
|
|
735
811
|
widget: "select",
|
|
736
812
|
default: DEFAULT_TEXT_OVERFLOW,
|
|
737
|
-
props: { options:
|
|
738
|
-
label: i18n("schemas.text.overflowVisible"),
|
|
739
|
-
value: TEXT_OVERFLOW_VISIBLE
|
|
740
|
-
}, {
|
|
741
|
-
label: i18n("schemas.text.overflowExpand"),
|
|
742
|
-
value: TEXT_OVERFLOW_EXPAND
|
|
743
|
-
}] },
|
|
813
|
+
props: { options: overflowOptions },
|
|
744
814
|
span: 8
|
|
745
815
|
},
|
|
746
816
|
useDynamicFontSize: {
|
|
@@ -803,6 +873,30 @@ var propPanel = {
|
|
|
803
873
|
message: i18n("validation.hexColor")
|
|
804
874
|
}]
|
|
805
875
|
},
|
|
876
|
+
borderColor: {
|
|
877
|
+
title: i18n("schemas.borderColor"),
|
|
878
|
+
type: "string",
|
|
879
|
+
widget: "color",
|
|
880
|
+
props: { disabledAlpha: true },
|
|
881
|
+
rules: [{
|
|
882
|
+
pattern: HEX_COLOR_PATTERN,
|
|
883
|
+
message: i18n("validation.hexColor")
|
|
884
|
+
}]
|
|
885
|
+
},
|
|
886
|
+
borderWidth: {
|
|
887
|
+
title: i18n("schemas.borderWidth"),
|
|
888
|
+
type: "object",
|
|
889
|
+
widget: "lineTitle",
|
|
890
|
+
span: 24,
|
|
891
|
+
properties: getBoxDimensionPropPanelSchema(.1)
|
|
892
|
+
},
|
|
893
|
+
padding: {
|
|
894
|
+
title: i18n("schemas.padding"),
|
|
895
|
+
type: "object",
|
|
896
|
+
widget: "lineTitle",
|
|
897
|
+
span: 24,
|
|
898
|
+
properties: getBoxDimensionPropPanelSchema()
|
|
899
|
+
},
|
|
806
900
|
useInlineMarkdown: {
|
|
807
901
|
type: "boolean",
|
|
808
902
|
widget: "UseInlineMarkdown",
|
|
@@ -894,6 +988,9 @@ var propPanel = {
|
|
|
894
988
|
fontColor: DEFAULT_FONT_COLOR,
|
|
895
989
|
fontName: void 0,
|
|
896
990
|
backgroundColor: "",
|
|
991
|
+
borderColor: "#000000",
|
|
992
|
+
borderWidth: createBoxDimension(0),
|
|
993
|
+
padding: createBoxDimension(0),
|
|
897
994
|
opacity: 1,
|
|
898
995
|
strikethrough: false,
|
|
899
996
|
underline: false
|
|
@@ -918,10 +1015,10 @@ var replaceUnsupportedChars = (text, fontKitFont) => {
|
|
|
918
1015
|
}).join("");
|
|
919
1016
|
};
|
|
920
1017
|
var uiRender = async (arg) => {
|
|
921
|
-
const { value, schema, mode, onChange, stopEditing, tabIndex, placeholder, options, _cache } = arg;
|
|
1018
|
+
const { value, schema, basePdf, mode, onChange, stopEditing, tabIndex, placeholder, options, _cache } = arg;
|
|
922
1019
|
const hasInlineMarkdownFormat = schema.textFormat === TEXT_FORMAT_INLINE_MARKDOWN;
|
|
923
1020
|
const enableInlineMarkdown = isInlineMarkdownTextSchema(schema);
|
|
924
|
-
const isReadOnlySplitInlineMarkdownFormChunk = mode === "form" && Boolean(schema
|
|
1021
|
+
const isReadOnlySplitInlineMarkdownFormChunk = mode === "form" && Boolean(getTextLineRange(schema)) && hasInlineMarkdownFormat;
|
|
925
1022
|
const renderInlineMarkdownReadOnlyChunk = enableInlineMarkdown || isReadOnlySplitInlineMarkdownFormChunk;
|
|
926
1023
|
const editable = isEditable(mode, schema) && !isReadOnlySplitInlineMarkdownFormChunk;
|
|
927
1024
|
const usePlaceholder = editable && placeholder && !value;
|
|
@@ -932,7 +1029,7 @@ var uiRender = async (arg) => {
|
|
|
932
1029
|
};
|
|
933
1030
|
const font = options?.font || getDefaultFont();
|
|
934
1031
|
const fontKitFont = await getFontKitFont(schema.fontName, font, _cache);
|
|
935
|
-
const enableDynamicFontSize = shouldUseDynamicFontSize(schema);
|
|
1032
|
+
const enableDynamicFontSize = shouldUseDynamicFontSize(schema, basePdf);
|
|
936
1033
|
const displayValue = enableInlineMarkdown ? stripInlineMarkdown(value) : value;
|
|
937
1034
|
const dynamicRichTextFontSize = enableInlineMarkdown && enableDynamicFontSize ? await calculateDynamicRichTextFontSize({
|
|
938
1035
|
value: usePlaceholder ? placeholder : value,
|
|
@@ -1026,13 +1123,14 @@ var renderInlineMarkdownReadOnly = async (arg) => {
|
|
|
1026
1123
|
font,
|
|
1027
1124
|
_cache
|
|
1028
1125
|
});
|
|
1029
|
-
|
|
1126
|
+
const lineRange = getTextLineRange(schema);
|
|
1127
|
+
if (lineRange) {
|
|
1030
1128
|
const lines = applyTextLineRange(layoutRichTextLines({
|
|
1031
1129
|
runs,
|
|
1032
1130
|
fontSize: schema.fontSize ?? 13,
|
|
1033
1131
|
characterSpacing: schema.characterSpacing ?? 0,
|
|
1034
|
-
boxWidthInPt: mm2pt(schema.width)
|
|
1035
|
-
}),
|
|
1132
|
+
boxWidthInPt: mm2pt(getBoxContentArea(schema).width)
|
|
1133
|
+
}), lineRange);
|
|
1036
1134
|
textBlock.innerHTML = "";
|
|
1037
1135
|
lines.forEach((line, lineIndex) => {
|
|
1038
1136
|
line.runs.forEach((run) => {
|
|
@@ -1091,19 +1189,20 @@ var appendInlineMarkdownRun = (arg) => {
|
|
|
1091
1189
|
};
|
|
1092
1190
|
var getRangedPlainTextValue = (arg) => {
|
|
1093
1191
|
const { value, schema, fontKitFont, fontSize } = arg;
|
|
1094
|
-
|
|
1192
|
+
const lineRange = getTextLineRange(schema);
|
|
1193
|
+
if (!lineRange) return value;
|
|
1095
1194
|
return plainTextLinesToValue(applyTextLineRange(splitTextToSize({
|
|
1096
1195
|
value,
|
|
1097
1196
|
characterSpacing: schema.characterSpacing ?? 0,
|
|
1098
1197
|
fontSize,
|
|
1099
1198
|
fontKitFont,
|
|
1100
|
-
boxWidthInPt: mm2pt(schema.width)
|
|
1101
|
-
}),
|
|
1199
|
+
boxWidthInPt: mm2pt(getBoxContentArea(schema).width)
|
|
1200
|
+
}), lineRange));
|
|
1102
1201
|
};
|
|
1103
1202
|
var buildStyledTextContainer = (arg, fontKitFont, value, resolvedDynamicFontSize) => {
|
|
1104
1203
|
const { schema, rootElement, mode } = arg;
|
|
1105
1204
|
let dynamicFontSize = resolvedDynamicFontSize;
|
|
1106
|
-
if (dynamicFontSize === void 0 && shouldUseDynamicFontSize(schema) && value) dynamicFontSize = calculateDynamicFontSize({
|
|
1205
|
+
if (dynamicFontSize === void 0 && shouldUseDynamicFontSize(schema, arg.basePdf) && value) dynamicFontSize = calculateDynamicFontSize({
|
|
1107
1206
|
textSchema: schema,
|
|
1108
1207
|
fontKitFont,
|
|
1109
1208
|
value,
|
|
@@ -1112,15 +1211,29 @@ var buildStyledTextContainer = (arg, fontKitFont, value, resolvedDynamicFontSize
|
|
|
1112
1211
|
const { topAdj, bottomAdj } = getBrowserVerticalFontAdjustments(fontKitFont, dynamicFontSize ?? schema.fontSize ?? 13, schema.lineHeight ?? 1, schema.verticalAlignment ?? "top");
|
|
1113
1212
|
const topAdjustment = topAdj.toString();
|
|
1114
1213
|
const bottomAdjustment = bottomAdj.toString();
|
|
1214
|
+
const verticalAlignment = schema.verticalAlignment ?? "top";
|
|
1215
|
+
const isTopAligned = verticalAlignment === "top";
|
|
1115
1216
|
const container = document.createElement("div");
|
|
1217
|
+
const { borderWidth, padding } = getBoxInsets(schema);
|
|
1218
|
+
const hasPadding = hasBoxDimension(schema.padding);
|
|
1219
|
+
const hasBorder = Boolean(schema.borderColor && hasBoxDimension(schema.borderWidth));
|
|
1116
1220
|
const containerStyle = {
|
|
1117
|
-
padding: 0,
|
|
1221
|
+
padding: hasPadding ? `${padding.top}mm ${padding.right}mm ${padding.bottom}mm ${padding.left}mm` : 0,
|
|
1118
1222
|
resize: "none",
|
|
1119
|
-
backgroundColor: getBackgroundColor(
|
|
1120
|
-
border: "none",
|
|
1223
|
+
backgroundColor: getBackgroundColor(schema),
|
|
1224
|
+
border: hasBorder ? void 0 : "none",
|
|
1225
|
+
...hasBorder ? {
|
|
1226
|
+
borderTopWidth: `${borderWidth.top}mm`,
|
|
1227
|
+
borderRightWidth: `${borderWidth.right}mm`,
|
|
1228
|
+
borderBottomWidth: `${borderWidth.bottom}mm`,
|
|
1229
|
+
borderLeftWidth: `${borderWidth.left}mm`,
|
|
1230
|
+
borderStyle: "solid",
|
|
1231
|
+
borderColor: schema.borderColor
|
|
1232
|
+
} : {},
|
|
1233
|
+
...hasPadding || hasBorder ? { boxSizing: "border-box" } : {},
|
|
1121
1234
|
display: "flex",
|
|
1122
1235
|
flexDirection: "column",
|
|
1123
|
-
justifyContent: mapVerticalAlignToFlex(
|
|
1236
|
+
justifyContent: mapVerticalAlignToFlex(verticalAlignment),
|
|
1124
1237
|
width: "100%",
|
|
1125
1238
|
height: "100%",
|
|
1126
1239
|
cursor: isEditable(mode, schema) ? "text" : "default"
|
|
@@ -1146,7 +1259,8 @@ var buildStyledTextContainer = (arg, fontKitFont, value, resolvedDynamicFontSize
|
|
|
1146
1259
|
marginBottom: `${bottomAdjustment}px`,
|
|
1147
1260
|
paddingTop: `${topAdjustment}px`,
|
|
1148
1261
|
backgroundColor: "transparent",
|
|
1149
|
-
textDecoration: textDecorations.join(" ")
|
|
1262
|
+
textDecoration: textDecorations.join(" "),
|
|
1263
|
+
...isTopAligned ? { height: "100%" } : {}
|
|
1150
1264
|
};
|
|
1151
1265
|
const textBlock = document.createElement("div");
|
|
1152
1266
|
textBlock.id = "text-" + String(schema.id);
|
|
@@ -1188,8 +1302,8 @@ var mapVerticalAlignToFlex = (verticalAlignmentValue) => {
|
|
|
1188
1302
|
}
|
|
1189
1303
|
return "flex-start";
|
|
1190
1304
|
};
|
|
1191
|
-
var getBackgroundColor = (
|
|
1192
|
-
if (!
|
|
1305
|
+
var getBackgroundColor = (schema) => {
|
|
1306
|
+
if (!schema.backgroundColor) return "transparent";
|
|
1193
1307
|
return schema.backgroundColor;
|
|
1194
1308
|
};
|
|
1195
1309
|
//#endregion
|
|
@@ -1206,4 +1320,4 @@ var builtInPlugins = { Text: textSchema };
|
|
|
1206
1320
|
//#endregion
|
|
1207
1321
|
export { mapVerticalAlignToFlex as a, Formatter as c, makeElementPlainTextContentEditable as i, getExtraFormatterSchema as l, textSchema as n, uiRender as o, buildStyledTextContainer as r, propPanel as s, builtInPlugins as t, pdfRender as u };
|
|
1208
1322
|
|
|
1209
|
-
//# sourceMappingURL=builtins-
|
|
1323
|
+
//# sourceMappingURL=builtins-BB2DHceW.js.map
|