@pdfme/schemas 6.1.1-dev.4 → 6.1.1-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{builtins-CFqn6U5J.js → builtins-pN5NVCSV.js} +245 -457
- package/dist/builtins-pN5NVCSV.js.map +1 -0
- package/dist/builtins.d.ts +1 -1
- package/dist/builtins.js +1 -1
- package/dist/checkbox/index.d.ts +2 -2
- package/dist/dynamicLayout.d.ts +3 -0
- package/dist/dynamicLayout.js +20 -0
- package/dist/dynamicLayout.js.map +1 -0
- package/dist/dynamicTemplate-ByBNu75x.js +71 -0
- package/dist/dynamicTemplate-ByBNu75x.js.map +1 -0
- package/dist/{dynamicTemplate-DslOH4FZ.js → dynamicTemplate-CkrZKlg-.js} +2 -2
- package/dist/{dynamicTemplate-DslOH4FZ.js.map → dynamicTemplate-CkrZKlg-.js.map} +1 -1
- package/dist/{lists-BmAAx0lx.js → dynamicTemplate-Cy07Imb5.js} +2 -2
- package/dist/dynamicTemplate-Cy07Imb5.js.map +1 -0
- package/dist/graphics/image.d.ts +1 -1
- package/dist/graphics/signature.d.ts +1 -1
- package/dist/helper-BaUAusvL.js +40 -0
- package/dist/helper-BaUAusvL.js.map +1 -0
- package/dist/{helper-6FilIoVM.js → helper-CBd9plP_.js} +5 -2
- package/dist/helper-CBd9plP_.js.map +1 -0
- package/dist/index.js +31 -43
- package/dist/index.js.map +1 -1
- package/dist/lists.js +1 -1
- package/dist/measure-h-7PUE2B.js +584 -0
- package/dist/measure-h-7PUE2B.js.map +1 -0
- package/dist/multiVariableText/dynamicTemplate.d.ts +2 -0
- package/dist/radioGroup/index.d.ts +2 -2
- package/dist/select/index.d.ts +2 -2
- package/dist/shapes/line.d.ts +1 -1
- package/dist/shapes/rectAndEllipse.d.ts +1 -2
- package/dist/tables/helper.d.ts +4 -4
- package/dist/tables.js +1 -1
- package/dist/text/constants.d.ts +3 -0
- package/dist/text/dynamicTemplate.d.ts +2 -0
- package/dist/text/linkAnnotation.d.ts +14 -0
- package/dist/text/measure.d.ts +26 -0
- package/dist/text/overflow.d.ts +3 -0
- package/dist/text/richTextPdfRender.d.ts +1 -0
- package/dist/text/types.d.ts +8 -0
- package/dist/texts.d.ts +4 -0
- package/dist/texts.js +4 -0
- package/dist/types.d.ts +14 -0
- package/dist/types.js +0 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +3 -2
- package/dist/utils.js.map +1 -1
- package/package.json +16 -1
- package/dist/builtins-CFqn6U5J.js.map +0 -1
- package/dist/helper-6FilIoVM.js.map +0 -1
- package/dist/lists-BmAAx0lx.js.map +0 -1
|
@@ -1,426 +1,36 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { c as
|
|
1
|
+
import { A as SYNTHETIC_BOLD_OFFSET_RATIO, C as DYNAMIC_FIT_VERTICAL, D as FONT_VARIANT_FALLBACK_SYNTHETIC, E as FONT_VARIANT_FALLBACK_PLAIN, F as VERTICAL_ALIGN_BOTTOM, I as VERTICAL_ALIGN_MIDDLE, M as TEXT_FORMAT_PLAIN, N as TEXT_OVERFLOW_EXPAND, O as PLACEHOLDER_FONT_COLOR, P as TEXT_OVERFLOW_VISIBLE, S as DYNAMIC_FIT_HORIZONTAL, T as FONT_VARIANT_FALLBACK_ERROR, _ as DEFAULT_DYNAMIC_FIT, a as getFontKitFont, b as DEFAULT_TEXT_FORMAT, c as splitTextToSize, d as ALIGN_JUSTIFY, g as DEFAULT_ALIGNMENT, h as CODE_HORIZONTAL_PADDING, i as getFontDescentInPt, j as TEXT_FORMAT_INLINE_MARKDOWN, k as SYNTHETIC_BOLD_CSS_TEXT_SHADOW, l as widthOfTextAtSize, m as CODE_BACKGROUND_COLOR, n as fetchRemoteFontData, o as heightOfFontAtSize, p as ALIGN_RIGHT, r as getBrowserVerticalFontAdjustments, s as isFirefox, t as calculateDynamicFontSize, u as ALIGN_CENTER, v as DEFAULT_FONT_COLOR, x as DEFAULT_TEXT_OVERFLOW, y as DEFAULT_FONT_VARIANT_FALLBACK } from "./helper-CBd9plP_.js";
|
|
2
|
+
import { a as plainTextLinesToValue, c as countRichTextLineGraphemes, f as resolveRichTextRuns, h as stripInlineMarkdown, l as isInlineMarkdownTextSchema, m as parseInlineMarkdown, s as calculateDynamicRichTextFontSize, t as applyTextLineRange, u as layoutRichTextLines } from "./measure-h-7PUE2B.js";
|
|
3
|
+
import { c as HEX_COLOR_PATTERN } from "./dynamicTemplate-CkrZKlg-.js";
|
|
3
4
|
import { convertForPdfLayoutProps, createSvgStr, hex2PrintingColor, isEditable, rotatePoint } from "./utils.js";
|
|
4
|
-
import { DEFAULT_FONT_NAME, getDefaultFont, getFallbackFontName, mm2pt,
|
|
5
|
+
import { DEFAULT_FONT_NAME, getDefaultFont, getFallbackFontName, getInternalLinkTarget, mm2pt, normalizeLinkHref, normalizeSafeLinkUri, registerInternalLinkAnnotation } from "@pdfme/common";
|
|
6
|
+
import { PDFName, PDFString } from "@pdfme/pdf-lib";
|
|
5
7
|
import { AlignCenter, AlignJustify, AlignLeft, AlignRight, ArrowDownToLine, ArrowUpToLine, Strikethrough, TextCursorInput, Underline } from "lucide";
|
|
6
|
-
//#region src/text/
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
var findClosingDelimiter = (value, delimiter, from) => {
|
|
32
|
-
for (let i = from; i < value.length; i++) {
|
|
33
|
-
if (value[i] === "\\") {
|
|
34
|
-
i += 1;
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (delimiter !== "`" && value[i] === "`") {
|
|
38
|
-
const codeEnd = findClosingDelimiter(value, "`", i + 1);
|
|
39
|
-
if (codeEnd === -1) continue;
|
|
40
|
-
i = codeEnd;
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (value.startsWith(delimiter, i)) return i;
|
|
44
|
-
}
|
|
45
|
-
return -1;
|
|
46
|
-
};
|
|
47
|
-
var getDelimiter = (value, index) => {
|
|
48
|
-
if (value[index] === "`") return "`";
|
|
49
|
-
if (value.startsWith("***", index)) return "***";
|
|
50
|
-
if (value.startsWith("**", index)) return "**";
|
|
51
|
-
if (value.startsWith("~~", index)) return "~~";
|
|
52
|
-
if (value[index] === "*") return "*";
|
|
53
|
-
return "";
|
|
54
|
-
};
|
|
55
|
-
var mergeStyle = (style, delimiter) => {
|
|
56
|
-
if (delimiter === "***") return {
|
|
57
|
-
...style,
|
|
58
|
-
bold: true,
|
|
59
|
-
italic: true
|
|
60
|
-
};
|
|
61
|
-
if (delimiter === "**") return {
|
|
62
|
-
...style,
|
|
63
|
-
bold: true
|
|
64
|
-
};
|
|
65
|
-
if (delimiter === "*") return {
|
|
66
|
-
...style,
|
|
67
|
-
italic: true
|
|
68
|
-
};
|
|
69
|
-
if (delimiter === "~~") return {
|
|
70
|
-
...style,
|
|
71
|
-
strikethrough: true
|
|
72
|
-
};
|
|
73
|
-
return style;
|
|
74
|
-
};
|
|
75
|
-
var parseRange = (value, from, to, style) => {
|
|
76
|
-
const runs = [];
|
|
77
|
-
let buffer = "";
|
|
78
|
-
const flush = () => {
|
|
79
|
-
appendRun(runs, buffer, style);
|
|
80
|
-
buffer = "";
|
|
81
|
-
};
|
|
82
|
-
for (let index = from; index < to; index++) {
|
|
83
|
-
const char = value[index];
|
|
84
|
-
if (char === "\\" && index + 1 < to && MARKDOWN_ESCAPABLE_CHARS.has(value[index + 1])) {
|
|
85
|
-
buffer += value[index + 1];
|
|
86
|
-
index += 1;
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
const delimiter = getDelimiter(value, index);
|
|
90
|
-
if (!delimiter) {
|
|
91
|
-
buffer += char;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
const closingIndex = findClosingDelimiter(value, delimiter, index + delimiter.length);
|
|
95
|
-
if (closingIndex === -1 || closingIndex + delimiter.length > to) {
|
|
96
|
-
buffer += char;
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
flush();
|
|
100
|
-
if (delimiter === "`") appendRun(runs, value.slice(index + 1, closingIndex).replace(MARKDOWN_UNESCAPE_PATTERN, "$1"), {
|
|
101
|
-
...style,
|
|
102
|
-
code: true
|
|
103
|
-
});
|
|
104
|
-
else parseRange(value, index + delimiter.length, closingIndex, mergeStyle(style, delimiter)).forEach((run) => appendRun(runs, run.text, run));
|
|
105
|
-
index = closingIndex + delimiter.length - 1;
|
|
106
|
-
}
|
|
107
|
-
flush();
|
|
108
|
-
return runs;
|
|
109
|
-
};
|
|
110
|
-
var parseInlineMarkdown = (value) => {
|
|
111
|
-
if (!value) return [];
|
|
112
|
-
return parseRange(value, 0, value.length, {});
|
|
113
|
-
};
|
|
114
|
-
var escapeInlineMarkdown = (value) => value.replace(MARKDOWN_ESCAPE_PATTERN, (char) => `\\${char}`);
|
|
115
|
-
var stripInlineMarkdown = (value) => parseInlineMarkdown(value).map((run) => run.text).join("");
|
|
116
|
-
//#endregion
|
|
117
|
-
//#region src/text/richText.ts
|
|
118
|
-
var richTextWordSegmenter = new Intl.Segmenter(void 0, { granularity: "word" });
|
|
119
|
-
var richTextGraphemeSegmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
120
|
-
var getBaseFontName = (schema, font) => schema.fontName && font[schema.fontName] ? schema.fontName : getFallbackFontName(font);
|
|
121
|
-
var getLoadedFontName = (font, fontName) => fontName && font[fontName] ? fontName : void 0;
|
|
122
|
-
var isInlineMarkdownTextSchema = (schema) => schema.textFormat === "inline-markdown" && !(schema.type === "text" && schema.readOnly !== true);
|
|
123
|
-
var resolveFontVariant = (run, schema, font) => {
|
|
124
|
-
const baseFontName = getBaseFontName(schema, font);
|
|
125
|
-
const variants = schema.fontVariants ?? {};
|
|
126
|
-
const fallback = schema.fontVariantFallback ?? "synthetic";
|
|
127
|
-
let fontName = baseFontName;
|
|
128
|
-
let needsBold = Boolean(run.bold);
|
|
129
|
-
let needsItalic = Boolean(run.italic);
|
|
130
|
-
if (run.code) fontName = getLoadedFontName(font, variants.code) ?? baseFontName;
|
|
131
|
-
else if (run.bold && run.italic) {
|
|
132
|
-
const boldItalic = getLoadedFontName(font, variants.boldItalic);
|
|
133
|
-
const italic = getLoadedFontName(font, variants.italic);
|
|
134
|
-
const bold = getLoadedFontName(font, variants.bold);
|
|
135
|
-
if (boldItalic) {
|
|
136
|
-
fontName = boldItalic;
|
|
137
|
-
needsBold = false;
|
|
138
|
-
needsItalic = false;
|
|
139
|
-
} else if (italic) {
|
|
140
|
-
fontName = italic;
|
|
141
|
-
needsItalic = false;
|
|
142
|
-
} else if (bold) {
|
|
143
|
-
fontName = bold;
|
|
144
|
-
needsBold = false;
|
|
145
|
-
}
|
|
146
|
-
} else if (run.bold) {
|
|
147
|
-
const bold = getLoadedFontName(font, variants.bold);
|
|
148
|
-
if (bold) {
|
|
149
|
-
fontName = bold;
|
|
150
|
-
needsBold = false;
|
|
151
|
-
}
|
|
152
|
-
} else if (run.italic) {
|
|
153
|
-
const italic = getLoadedFontName(font, variants.italic);
|
|
154
|
-
if (italic) {
|
|
155
|
-
fontName = italic;
|
|
156
|
-
needsItalic = false;
|
|
8
|
+
//#region src/text/linkAnnotation.ts
|
|
9
|
+
var addUriLinkAnnotation = (arg) => {
|
|
10
|
+
const { pdfDoc, page, uri, rect, borderWidth = 0 } = arg;
|
|
11
|
+
const safeUri = normalizeSafeLinkUri(uri);
|
|
12
|
+
if (!safeUri || rect.width <= 0 || rect.height <= 0) return;
|
|
13
|
+
const annotationRef = pdfDoc.context.register(pdfDoc.context.obj({
|
|
14
|
+
Type: PDFName.of("Annot"),
|
|
15
|
+
Subtype: PDFName.of("Link"),
|
|
16
|
+
Rect: [
|
|
17
|
+
rect.x,
|
|
18
|
+
rect.y,
|
|
19
|
+
rect.x + rect.width,
|
|
20
|
+
rect.y + rect.height
|
|
21
|
+
],
|
|
22
|
+
Border: [
|
|
23
|
+
0,
|
|
24
|
+
0,
|
|
25
|
+
borderWidth
|
|
26
|
+
],
|
|
27
|
+
A: {
|
|
28
|
+
Type: PDFName.of("Action"),
|
|
29
|
+
S: PDFName.of("URI"),
|
|
30
|
+
URI: PDFString.of(safeUri)
|
|
157
31
|
}
|
|
158
|
-
}
|
|
159
|
-
if ((needsBold || needsItalic || run.code && !getLoadedFontName(font, variants.code)) && fallback === "error") throw new Error(`[@pdfme/schemas] Missing font variant for markdown text in field "${schema.name}".`);
|
|
160
|
-
return {
|
|
161
|
-
fontName,
|
|
162
|
-
syntheticBold: fallback !== "plain" && needsBold,
|
|
163
|
-
syntheticItalic: fallback !== "plain" && needsItalic
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
var resolveRichTextRuns = async (arg) => {
|
|
167
|
-
const { runs, schema, font, _cache } = arg;
|
|
168
|
-
const fontKitCache = /* @__PURE__ */ new Map();
|
|
169
|
-
const getResolvedFontKitFont = async (fontName) => {
|
|
170
|
-
const cached = fontKitCache.get(fontName);
|
|
171
|
-
if (cached) return cached;
|
|
172
|
-
const fontKitFont = await getFontKitFont(fontName, font, _cache);
|
|
173
|
-
fontKitCache.set(fontName, fontKitFont);
|
|
174
|
-
return fontKitFont;
|
|
175
|
-
};
|
|
176
|
-
return Promise.all(runs.map(async (run) => {
|
|
177
|
-
const resolution = resolveFontVariant(run, schema, font);
|
|
178
|
-
return {
|
|
179
|
-
...run,
|
|
180
|
-
...resolution,
|
|
181
|
-
fontKitFont: await getResolvedFontKitFont(resolution.fontName)
|
|
182
|
-
};
|
|
183
32
|
}));
|
|
184
|
-
|
|
185
|
-
var measureRunText = (run, text, fontSize, characterSpacing) => {
|
|
186
|
-
const syntheticBoldWidth = run.syntheticBold ? fontSize * SYNTHETIC_BOLD_OFFSET_RATIO * 2 : 0;
|
|
187
|
-
const syntheticItalicWidth = run.syntheticItalic ? heightOfFontAtSize(run.fontKitFont, fontSize) * Math.tan(12 * Math.PI / 180) : 0;
|
|
188
|
-
return widthOfTextAtSize(text, run.fontKitFont, fontSize, characterSpacing) + syntheticBoldWidth + syntheticItalicWidth;
|
|
189
|
-
};
|
|
190
|
-
var createLine = () => ({
|
|
191
|
-
runs: [],
|
|
192
|
-
width: 0,
|
|
193
|
-
hardBreak: false
|
|
194
|
-
});
|
|
195
|
-
var pushRunToLine = (line, run, text, fontSize, characterSpacing) => {
|
|
196
|
-
if (!text) return;
|
|
197
|
-
const width = measureRunText(run, text, fontSize, characterSpacing);
|
|
198
|
-
if (line.runs.length > 0) line.width += characterSpacing;
|
|
199
|
-
line.runs.push({
|
|
200
|
-
...run,
|
|
201
|
-
text,
|
|
202
|
-
width
|
|
203
|
-
});
|
|
204
|
-
line.width += width;
|
|
205
|
-
};
|
|
206
|
-
var measurePiecesWidth = (pieces, fontSize, characterSpacing) => {
|
|
207
|
-
let width = 0;
|
|
208
|
-
let hasText = false;
|
|
209
|
-
pieces.forEach((piece) => {
|
|
210
|
-
if (!piece.text) return;
|
|
211
|
-
if (hasText) width += characterSpacing;
|
|
212
|
-
width += measureRunText(piece.run, piece.text, fontSize, characterSpacing);
|
|
213
|
-
hasText = true;
|
|
214
|
-
});
|
|
215
|
-
return width;
|
|
216
|
-
};
|
|
217
|
-
var sliceRunPieces = (pieces, startIndex, endIndex) => {
|
|
218
|
-
const result = [];
|
|
219
|
-
let offset = 0;
|
|
220
|
-
pieces.forEach((piece) => {
|
|
221
|
-
const pieceStart = offset;
|
|
222
|
-
const pieceEnd = pieceStart + piece.text.length;
|
|
223
|
-
const sliceStart = Math.max(startIndex, pieceStart);
|
|
224
|
-
const sliceEnd = Math.min(endIndex, pieceEnd);
|
|
225
|
-
if (sliceStart < sliceEnd) result.push({
|
|
226
|
-
run: piece.run,
|
|
227
|
-
text: piece.text.slice(sliceStart - pieceStart, sliceEnd - pieceStart)
|
|
228
|
-
});
|
|
229
|
-
offset = pieceEnd;
|
|
230
|
-
});
|
|
231
|
-
return result;
|
|
232
|
-
};
|
|
233
|
-
var segmentRunPiecesByWord = (runs, onSegment, onHardBreak) => {
|
|
234
|
-
let paragraphPieces = [];
|
|
235
|
-
const flushParagraph = () => {
|
|
236
|
-
if (paragraphPieces.length === 0) return;
|
|
237
|
-
const paragraphText = paragraphPieces.map((piece) => piece.text).join("");
|
|
238
|
-
Array.from(richTextWordSegmenter.segment(paragraphText), ({ segment, index }) => {
|
|
239
|
-
const pieces = sliceRunPieces(paragraphPieces, index, index + segment.length);
|
|
240
|
-
if (pieces.length > 0) onSegment(pieces);
|
|
241
|
-
});
|
|
242
|
-
paragraphPieces = [];
|
|
243
|
-
};
|
|
244
|
-
runs.forEach((run) => {
|
|
245
|
-
run.text.split(/(\r\n|\r|\n)/).forEach((part) => {
|
|
246
|
-
if (part === "\r\n" || part === "\r" || part === "\n") {
|
|
247
|
-
flushParagraph();
|
|
248
|
-
onHardBreak();
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
if (part) paragraphPieces.push({
|
|
252
|
-
run,
|
|
253
|
-
text: part
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
flushParagraph();
|
|
258
|
-
};
|
|
259
|
-
var splitIntoGraphemes = (value) => Array.from(richTextGraphemeSegmenter.segment(value), ({ segment }) => segment);
|
|
260
|
-
var countRichTextLineGraphemes = (line) => splitIntoGraphemes(line.runs.map((run) => run.text).join("")).length;
|
|
261
|
-
var layoutRichTextLines = (arg) => {
|
|
262
|
-
const { runs, fontSize, characterSpacing, boxWidthInPt } = arg;
|
|
263
|
-
const lines = [];
|
|
264
|
-
let currentLine = createLine();
|
|
265
|
-
const pushCurrentLine = (hardBreak) => {
|
|
266
|
-
currentLine.hardBreak = hardBreak;
|
|
267
|
-
lines.push(currentLine);
|
|
268
|
-
currentLine = createLine();
|
|
269
|
-
};
|
|
270
|
-
const pushPiecesToLine = (pieces) => {
|
|
271
|
-
pieces.forEach((piece) => {
|
|
272
|
-
pushRunToLine(currentLine, piece.run, piece.text, fontSize, characterSpacing);
|
|
273
|
-
});
|
|
274
|
-
};
|
|
275
|
-
const pushOversizedText = (run, text) => {
|
|
276
|
-
let remainingText = text;
|
|
277
|
-
while (remainingText.length > 0) {
|
|
278
|
-
const pendingSpacing = currentLine.runs.length > 0 ? characterSpacing : 0;
|
|
279
|
-
const remainingWidth = Math.max(boxWidthInPt - currentLine.width - pendingSpacing, 0);
|
|
280
|
-
const remainingTextWidth = measureRunText(run, remainingText, fontSize, characterSpacing);
|
|
281
|
-
if (remainingTextWidth <= remainingWidth || currentLine.runs.length === 0 && remainingTextWidth <= boxWidthInPt) {
|
|
282
|
-
pushRunToLine(currentLine, run, remainingText, fontSize, characterSpacing);
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
if (currentLine.runs.length > 0 && remainingTextWidth <= boxWidthInPt) {
|
|
286
|
-
pushCurrentLine(false);
|
|
287
|
-
continue;
|
|
288
|
-
}
|
|
289
|
-
const graphemes = splitIntoGraphemes(remainingText);
|
|
290
|
-
let fittingText = "";
|
|
291
|
-
let fittingLength = 0;
|
|
292
|
-
for (const grapheme of graphemes) {
|
|
293
|
-
const candidate = fittingText + grapheme;
|
|
294
|
-
const candidateWidth = measureRunText(run, candidate, fontSize, characterSpacing);
|
|
295
|
-
const maxWidth = currentLine.runs.length === 0 ? boxWidthInPt : remainingWidth;
|
|
296
|
-
if (candidateWidth > maxWidth) {
|
|
297
|
-
if (fittingText) break;
|
|
298
|
-
if (currentLine.runs.length > 0) break;
|
|
299
|
-
}
|
|
300
|
-
fittingText = candidate;
|
|
301
|
-
fittingLength += grapheme.length;
|
|
302
|
-
if (candidateWidth > maxWidth) break;
|
|
303
|
-
}
|
|
304
|
-
if (!fittingText) {
|
|
305
|
-
pushCurrentLine(false);
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
pushRunToLine(currentLine, run, fittingText, fontSize, characterSpacing);
|
|
309
|
-
remainingText = remainingText.slice(fittingLength);
|
|
310
|
-
if (remainingText.length > 0) pushCurrentLine(false);
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
const pushSegment = (pieces) => {
|
|
314
|
-
const segmentWidth = measurePiecesWidth(pieces, fontSize, characterSpacing);
|
|
315
|
-
const pendingSpacing = currentLine.runs.length > 0 ? characterSpacing : 0;
|
|
316
|
-
if (segmentWidth <= Math.max(boxWidthInPt - currentLine.width - pendingSpacing, 0) || currentLine.runs.length === 0 && segmentWidth <= boxWidthInPt) {
|
|
317
|
-
pushPiecesToLine(pieces);
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
if (currentLine.runs.length > 0) {
|
|
321
|
-
pushCurrentLine(false);
|
|
322
|
-
if (segmentWidth <= boxWidthInPt) {
|
|
323
|
-
pushPiecesToLine(pieces);
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
pieces.forEach((piece) => pushOversizedText(piece.run, piece.text));
|
|
328
|
-
};
|
|
329
|
-
segmentRunPiecesByWord(runs, pushSegment, () => pushCurrentLine(true));
|
|
330
|
-
if (currentLine.runs.length > 0 || lines.length === 0) pushCurrentLine(false);
|
|
331
|
-
return lines;
|
|
332
|
-
};
|
|
333
|
-
var measureParagraphWidths = (runs, fontSize, characterSpacing) => {
|
|
334
|
-
const widths = [];
|
|
335
|
-
let paragraphPieces = [];
|
|
336
|
-
const pushWidth = () => {
|
|
337
|
-
widths.push(measurePiecesWidth(paragraphPieces, fontSize, characterSpacing));
|
|
338
|
-
paragraphPieces = [];
|
|
339
|
-
};
|
|
340
|
-
runs.forEach((run) => {
|
|
341
|
-
run.text.split(/(\r\n|\r|\n)/).forEach((part) => {
|
|
342
|
-
if (part === "\r\n" || part === "\r" || part === "\n") {
|
|
343
|
-
pushWidth();
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
if (part) paragraphPieces.push({
|
|
347
|
-
run,
|
|
348
|
-
text: part
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
pushWidth();
|
|
353
|
-
return widths;
|
|
354
|
-
};
|
|
355
|
-
var getLineHeightAtSize = (line, fontSize) => {
|
|
356
|
-
if (line.runs.length === 0) return fontSize;
|
|
357
|
-
return Math.max(...line.runs.map((run) => heightOfFontAtSize(run.fontKitFont, fontSize)));
|
|
358
|
-
};
|
|
359
|
-
var calculateDynamicRichTextFontSize = async (arg) => {
|
|
360
|
-
const { value, schema, font, _cache, startingFontSize } = arg;
|
|
361
|
-
const { fontSize: schemaFontSize, dynamicFontSize: dynamicFontSizeSetting, characterSpacing: schemaCharacterSpacing, width: boxWidth, height: boxHeight, lineHeight = 1 } = schema;
|
|
362
|
-
const fontSize = startingFontSize || schemaFontSize || 13;
|
|
363
|
-
if (!dynamicFontSizeSetting) return fontSize;
|
|
364
|
-
if (dynamicFontSizeSetting.max < dynamicFontSizeSetting.min) return fontSize;
|
|
365
|
-
const resolvedRuns = await resolveRichTextRuns({
|
|
366
|
-
runs: parseInlineMarkdown(value),
|
|
367
|
-
schema,
|
|
368
|
-
font,
|
|
369
|
-
_cache
|
|
370
|
-
});
|
|
371
|
-
const characterSpacing = schemaCharacterSpacing ?? 0;
|
|
372
|
-
const dynamicFontFit = dynamicFontSizeSetting.fit ?? "vertical";
|
|
373
|
-
const boxWidthInPt = mm2pt(boxWidth);
|
|
374
|
-
let dynamicFontSize = fontSize;
|
|
375
|
-
if (dynamicFontSize < dynamicFontSizeSetting.min) dynamicFontSize = dynamicFontSizeSetting.min;
|
|
376
|
-
else if (dynamicFontSize > dynamicFontSizeSetting.max) dynamicFontSize = dynamicFontSizeSetting.max;
|
|
377
|
-
const calculateConstraints = (size) => {
|
|
378
|
-
let totalWidthInMm = 0;
|
|
379
|
-
let totalHeightInMm = 0;
|
|
380
|
-
layoutRichTextLines({
|
|
381
|
-
runs: resolvedRuns,
|
|
382
|
-
fontSize: size,
|
|
383
|
-
characterSpacing,
|
|
384
|
-
boxWidthInPt
|
|
385
|
-
}).forEach((line, lineIndex) => {
|
|
386
|
-
if (dynamicFontFit === "vertical") totalWidthInMm = Math.max(totalWidthInMm, pt2mm(line.width));
|
|
387
|
-
if (lineIndex === 0) totalHeightInMm += pt2mm(getLineHeightAtSize(line, size) * lineHeight);
|
|
388
|
-
else totalHeightInMm += pt2mm(size * lineHeight);
|
|
389
|
-
});
|
|
390
|
-
if (dynamicFontFit === "horizontal") measureParagraphWidths(resolvedRuns, size, characterSpacing).forEach((paragraphWidth) => {
|
|
391
|
-
totalWidthInMm = Math.max(totalWidthInMm, pt2mm(paragraphWidth));
|
|
392
|
-
});
|
|
393
|
-
return {
|
|
394
|
-
totalWidthInMm,
|
|
395
|
-
totalHeightInMm
|
|
396
|
-
};
|
|
397
|
-
};
|
|
398
|
-
const shouldFontGrowToFit = (totalWidthInMm, totalHeightInMm) => {
|
|
399
|
-
if (dynamicFontSize >= dynamicFontSizeSetting.max) return false;
|
|
400
|
-
if (dynamicFontFit === "horizontal") return totalWidthInMm < boxWidth;
|
|
401
|
-
return totalHeightInMm < boxHeight;
|
|
402
|
-
};
|
|
403
|
-
const shouldFontShrinkToFit = (totalWidthInMm, totalHeightInMm) => {
|
|
404
|
-
if (dynamicFontSize <= dynamicFontSizeSetting.min || dynamicFontSize <= 0) return false;
|
|
405
|
-
return totalWidthInMm > boxWidth || totalHeightInMm > boxHeight;
|
|
406
|
-
};
|
|
407
|
-
let { totalWidthInMm, totalHeightInMm } = calculateConstraints(dynamicFontSize);
|
|
408
|
-
while (shouldFontGrowToFit(totalWidthInMm, totalHeightInMm)) {
|
|
409
|
-
dynamicFontSize += FONT_SIZE_ADJUSTMENT;
|
|
410
|
-
const { totalWidthInMm: newWidth, totalHeightInMm: newHeight } = calculateConstraints(dynamicFontSize);
|
|
411
|
-
if (newHeight < boxHeight) {
|
|
412
|
-
totalWidthInMm = newWidth;
|
|
413
|
-
totalHeightInMm = newHeight;
|
|
414
|
-
} else {
|
|
415
|
-
dynamicFontSize -= FONT_SIZE_ADJUSTMENT;
|
|
416
|
-
break;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
while (shouldFontShrinkToFit(totalWidthInMm, totalHeightInMm)) {
|
|
420
|
-
dynamicFontSize -= FONT_SIZE_ADJUSTMENT;
|
|
421
|
-
({totalWidthInMm, totalHeightInMm} = calculateConstraints(dynamicFontSize));
|
|
422
|
-
}
|
|
423
|
-
return dynamicFontSize;
|
|
33
|
+
page.node.addAnnot(annotationRef);
|
|
424
34
|
};
|
|
425
35
|
//#endregion
|
|
426
36
|
//#region src/text/richTextPdfRender.ts
|
|
@@ -454,8 +64,58 @@ var drawDecorationLine = (arg) => {
|
|
|
454
64
|
opacity
|
|
455
65
|
});
|
|
456
66
|
};
|
|
67
|
+
var getAxisAlignedRect = (arg) => {
|
|
68
|
+
const { x, y, width, height, rotate, pivotPoint } = arg;
|
|
69
|
+
if (rotate.angle === 0) return {
|
|
70
|
+
x,
|
|
71
|
+
y,
|
|
72
|
+
width,
|
|
73
|
+
height
|
|
74
|
+
};
|
|
75
|
+
const points = [
|
|
76
|
+
{
|
|
77
|
+
x,
|
|
78
|
+
y
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
x: x + width,
|
|
82
|
+
y
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
x: x + width,
|
|
86
|
+
y: y + height
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
x,
|
|
90
|
+
y: y + height
|
|
91
|
+
}
|
|
92
|
+
].map((point) => rotatePoint(point, pivotPoint, rotate.angle));
|
|
93
|
+
const xs = points.map((point) => point.x);
|
|
94
|
+
const ys = points.map((point) => point.y);
|
|
95
|
+
const minX = Math.min(...xs);
|
|
96
|
+
const minY = Math.min(...ys);
|
|
97
|
+
return {
|
|
98
|
+
x: minX,
|
|
99
|
+
y: minY,
|
|
100
|
+
width: Math.max(...xs) - minX,
|
|
101
|
+
height: Math.max(...ys) - minY
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
var getLinkAnnotationRect = (arg) => {
|
|
105
|
+
const { run, x, y, width, rotate, pivotPoint, fontSize } = arg;
|
|
106
|
+
const textHeight = heightOfFontAtSize(run.fontKitFont, fontSize);
|
|
107
|
+
const descent = getFontDescentInPt(run.fontKitFont, fontSize);
|
|
108
|
+
return getAxisAlignedRect({
|
|
109
|
+
x,
|
|
110
|
+
y: y + descent,
|
|
111
|
+
width,
|
|
112
|
+
height: textHeight - descent,
|
|
113
|
+
rotate,
|
|
114
|
+
pivotPoint
|
|
115
|
+
});
|
|
116
|
+
};
|
|
457
117
|
var drawRun = (arg) => {
|
|
458
|
-
const { page, pdfLib, run, pdfFont, x, y, rotate, pivotPoint, fontSize, lineHeight, color, opacity, colorType, characterSpacing, strikethrough } = arg;
|
|
118
|
+
const { page, pdfLib, run, pdfFont, x, y, rotate, pivotPoint, fontSize, lineHeight, color, opacity, colorType, characterSpacing, strikethrough, underline } = arg;
|
|
459
119
|
const runWidth = getRunWidth(run, fontSize, characterSpacing);
|
|
460
120
|
const textHeight = heightOfFontAtSize(run.fontKitFont, fontSize);
|
|
461
121
|
if (run.code) {
|
|
@@ -490,6 +150,17 @@ var drawRun = (arg) => {
|
|
|
490
150
|
color,
|
|
491
151
|
opacity
|
|
492
152
|
});
|
|
153
|
+
if (underline && runWidth > 0) drawDecorationLine({
|
|
154
|
+
page,
|
|
155
|
+
x,
|
|
156
|
+
y: y - textHeight / 12,
|
|
157
|
+
width: runWidth,
|
|
158
|
+
rotate,
|
|
159
|
+
pivotPoint,
|
|
160
|
+
fontSize,
|
|
161
|
+
color,
|
|
162
|
+
opacity
|
|
163
|
+
});
|
|
493
164
|
const drawAt = (drawX) => {
|
|
494
165
|
const point = rotate.angle === 0 ? {
|
|
495
166
|
x: drawX,
|
|
@@ -517,8 +188,8 @@ var drawRun = (arg) => {
|
|
|
517
188
|
}
|
|
518
189
|
};
|
|
519
190
|
var renderInlineMarkdownText = async (arg) => {
|
|
520
|
-
const { value, schema, font, embedPdfFont, fontKitFont, page, pdfLib, _cache, colorType, fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing, x, width, height, pageHeight, pivotPoint, rotate, opacity } = arg;
|
|
521
|
-
const
|
|
191
|
+
const { value, schema, font, embedPdfFont, fontKitFont, pdfDoc, page, pdfLib, _cache, colorType, fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing, x, width, height, pageHeight, pivotPoint, rotate, opacity } = arg;
|
|
192
|
+
const allLines = layoutRichTextLines({
|
|
522
193
|
runs: await resolveRichTextRuns({
|
|
523
194
|
runs: parseInlineMarkdown(value),
|
|
524
195
|
schema,
|
|
@@ -529,6 +200,8 @@ var renderInlineMarkdownText = async (arg) => {
|
|
|
529
200
|
characterSpacing,
|
|
530
201
|
boxWidthInPt: width
|
|
531
202
|
});
|
|
203
|
+
const lines = applyTextLineRange(allLines, schema.__textLineRange);
|
|
204
|
+
const lineRangeStart = schema.__textLineRange?.start ?? 0;
|
|
532
205
|
const pdfFontObj = await embedFontsForRuns(lines.flatMap((line) => line.runs), embedPdfFont);
|
|
533
206
|
const firstLineTextHeight = heightOfFontAtSize(fontKitFont, fontSize);
|
|
534
207
|
const descent = getFontDescentInPt(fontKitFont, fontSize);
|
|
@@ -544,7 +217,7 @@ var renderInlineMarkdownText = async (arg) => {
|
|
|
544
217
|
if (line.runs.length === 0) return;
|
|
545
218
|
let textWidth = line.width;
|
|
546
219
|
let spacing = characterSpacing;
|
|
547
|
-
if (alignment === "justify" && !line.hardBreak && rowIndex <
|
|
220
|
+
if (alignment === "justify" && !line.hardBreak && lineRangeStart + rowIndex < allLines.length - 1) {
|
|
548
221
|
const graphemeCount = countRichTextLineGraphemes(line);
|
|
549
222
|
if (graphemeCount > 0) {
|
|
550
223
|
spacing += (width - textWidth) / graphemeCount;
|
|
@@ -598,13 +271,42 @@ var renderInlineMarkdownText = async (arg) => {
|
|
|
598
271
|
opacity,
|
|
599
272
|
colorType,
|
|
600
273
|
characterSpacing: spacing,
|
|
601
|
-
strikethrough: Boolean(run.strikethrough)
|
|
274
|
+
strikethrough: Boolean(run.strikethrough),
|
|
275
|
+
underline: Boolean(run.href) && !schema.underline
|
|
602
276
|
});
|
|
277
|
+
if (run.href) {
|
|
278
|
+
const rect = getLinkAnnotationRect({
|
|
279
|
+
run,
|
|
280
|
+
x: currentX,
|
|
281
|
+
y: yLine,
|
|
282
|
+
width: runWidth,
|
|
283
|
+
rotate,
|
|
284
|
+
pivotPoint,
|
|
285
|
+
fontSize
|
|
286
|
+
});
|
|
287
|
+
const targetName = getInternalLinkTarget(run.href);
|
|
288
|
+
if (targetName) registerInternalLinkAnnotation({
|
|
289
|
+
_cache,
|
|
290
|
+
page,
|
|
291
|
+
targetName,
|
|
292
|
+
rect
|
|
293
|
+
});
|
|
294
|
+
else addUriLinkAnnotation({
|
|
295
|
+
pdfDoc,
|
|
296
|
+
page,
|
|
297
|
+
uri: run.href,
|
|
298
|
+
rect
|
|
299
|
+
});
|
|
300
|
+
}
|
|
603
301
|
return currentX + runWidth + (runIndex === line.runs.length - 1 ? 0 : spacing);
|
|
604
302
|
}, xLine);
|
|
605
303
|
});
|
|
606
304
|
};
|
|
607
305
|
//#endregion
|
|
306
|
+
//#region src/text/overflow.ts
|
|
307
|
+
var isTextOverflowExpand = (schema) => schema.overflow === TEXT_OVERFLOW_EXPAND;
|
|
308
|
+
var shouldUseDynamicFontSize = (schema) => Boolean(schema.dynamicFontSize) && !isTextOverflowExpand(schema);
|
|
309
|
+
//#endregion
|
|
608
310
|
//#region src/text/pdfRender.ts
|
|
609
311
|
var PDF_FONT_CACHE_KEY = "text-pdf-font-cache";
|
|
610
312
|
var getPdfFontCache = (_cache) => {
|
|
@@ -631,7 +333,7 @@ var embedAndGetFont = (arg) => {
|
|
|
631
333
|
return pdfFontPromise;
|
|
632
334
|
};
|
|
633
335
|
var getFontProp = ({ value, fontKitFont, schema, colorType, fontSize: resolvedFontSize }) => {
|
|
634
|
-
const fontSize = resolvedFontSize ?? (schema
|
|
336
|
+
const fontSize = resolvedFontSize ?? (shouldUseDynamicFontSize(schema) ? calculateDynamicFontSize({
|
|
635
337
|
textSchema: schema,
|
|
636
338
|
fontKitFont,
|
|
637
339
|
value
|
|
@@ -669,7 +371,7 @@ var pdfRender = async (arg) => {
|
|
|
669
371
|
fontKitFont,
|
|
670
372
|
schema,
|
|
671
373
|
colorType,
|
|
672
|
-
fontSize: enableInlineMarkdown && schema
|
|
374
|
+
fontSize: enableInlineMarkdown && shouldUseDynamicFontSize(schema) ? await calculateDynamicRichTextFontSize({
|
|
673
375
|
value,
|
|
674
376
|
schema,
|
|
675
377
|
font,
|
|
@@ -722,6 +424,7 @@ var pdfRender = async (arg) => {
|
|
|
722
424
|
_cache
|
|
723
425
|
}),
|
|
724
426
|
fontKitFont,
|
|
427
|
+
pdfDoc,
|
|
725
428
|
page,
|
|
726
429
|
pdfLib,
|
|
727
430
|
_cache,
|
|
@@ -747,13 +450,13 @@ var pdfRender = async (arg) => {
|
|
|
747
450
|
const firstLineTextHeight = heightOfFontAtSize(fontKitFont, fontSize);
|
|
748
451
|
const descent = getFontDescentInPt(fontKitFont, fontSize);
|
|
749
452
|
const halfLineHeightAdjustment = lineHeight === 0 ? 0 : (lineHeight - 1) * fontSize / 2;
|
|
750
|
-
const lines = splitTextToSize({
|
|
453
|
+
const lines = applyTextLineRange(splitTextToSize({
|
|
751
454
|
value,
|
|
752
455
|
characterSpacing,
|
|
753
456
|
fontSize,
|
|
754
457
|
fontKitFont,
|
|
755
458
|
boxWidthInPt: width
|
|
756
|
-
});
|
|
459
|
+
}), schema.__textLineRange);
|
|
757
460
|
const needsTextWidth = alignment !== "left" || Boolean(schema.strikethrough || schema.underline);
|
|
758
461
|
const needsTextHeight = Boolean(schema.strikethrough || schema.underline);
|
|
759
462
|
let yOffset = 0;
|
|
@@ -920,9 +623,11 @@ function getExtraFormatterSchema(i18n) {
|
|
|
920
623
|
//#region src/text/propPanel.ts
|
|
921
624
|
var UseDynamicFontSize = (props) => {
|
|
922
625
|
const { rootElement, changeSchemas, activeSchema, i18n } = props;
|
|
626
|
+
const isExpand = isTextOverflowExpand(activeSchema);
|
|
923
627
|
const checkbox = document.createElement("input");
|
|
924
628
|
checkbox.type = "checkbox";
|
|
925
|
-
checkbox.checked = Boolean(activeSchema?.dynamicFontSize);
|
|
629
|
+
checkbox.checked = !isExpand && Boolean(activeSchema?.dynamicFontSize);
|
|
630
|
+
checkbox.disabled = isExpand;
|
|
926
631
|
checkbox.onchange = (e) => {
|
|
927
632
|
changeSchemas([{
|
|
928
633
|
key: "dynamicFontSize",
|
|
@@ -939,6 +644,7 @@ var UseDynamicFontSize = (props) => {
|
|
|
939
644
|
span.innerText = i18n("schemas.text.dynamicFontSize") || "";
|
|
940
645
|
span.style.cssText = "margin-left: 0.5rem";
|
|
941
646
|
label.style.cssText = "display: flex; width: 100%;";
|
|
647
|
+
label.style.opacity = isExpand ? "0.5" : "1";
|
|
942
648
|
label.appendChild(checkbox);
|
|
943
649
|
label.appendChild(span);
|
|
944
650
|
rootElement.appendChild(label);
|
|
@@ -972,8 +678,8 @@ var propPanel = {
|
|
|
972
678
|
} };
|
|
973
679
|
const fontNames = Object.keys(font);
|
|
974
680
|
const fallbackFontName = getFallbackFontName(font);
|
|
975
|
-
const enableDynamicFont = Boolean(activeSchema?.dynamicFontSize);
|
|
976
681
|
const activeTextSchema = activeSchema;
|
|
682
|
+
const enableDynamicFont = !isTextOverflowExpand(activeTextSchema) && Boolean(activeSchema?.dynamicFontSize);
|
|
977
683
|
const hideTextFormat = activeTextSchema.type === "text" && activeTextSchema.readOnly !== true;
|
|
978
684
|
const enableInlineMarkdown = activeTextSchema.textFormat === "inline-markdown" && !hideTextFormat;
|
|
979
685
|
const baseFontName = activeTextSchema.fontName && font[activeTextSchema.fontName] ? activeTextSchema.fontName : fallbackFontName;
|
|
@@ -1023,6 +729,20 @@ var propPanel = {
|
|
|
1023
729
|
},
|
|
1024
730
|
span: 8
|
|
1025
731
|
},
|
|
732
|
+
overflow: {
|
|
733
|
+
title: i18n("schemas.text.overflow"),
|
|
734
|
+
type: "string",
|
|
735
|
+
widget: "select",
|
|
736
|
+
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
|
+
}] },
|
|
744
|
+
span: 8
|
|
745
|
+
},
|
|
1026
746
|
useDynamicFontSize: {
|
|
1027
747
|
type: "boolean",
|
|
1028
748
|
widget: "UseDynamicFontSize",
|
|
@@ -1166,6 +886,7 @@ var propPanel = {
|
|
|
1166
886
|
verticalAlignment: "top",
|
|
1167
887
|
fontSize: 13,
|
|
1168
888
|
textFormat: DEFAULT_TEXT_FORMAT,
|
|
889
|
+
overflow: DEFAULT_TEXT_OVERFLOW,
|
|
1169
890
|
fontVariantFallback: DEFAULT_FONT_VARIANT_FALLBACK,
|
|
1170
891
|
lineHeight: 1,
|
|
1171
892
|
characterSpacing: 0,
|
|
@@ -1198,7 +919,12 @@ var replaceUnsupportedChars = (text, fontKitFont) => {
|
|
|
1198
919
|
};
|
|
1199
920
|
var uiRender = async (arg) => {
|
|
1200
921
|
const { value, schema, mode, onChange, stopEditing, tabIndex, placeholder, options, _cache } = arg;
|
|
1201
|
-
const
|
|
922
|
+
const hasInlineMarkdownFormat = schema.textFormat === TEXT_FORMAT_INLINE_MARKDOWN;
|
|
923
|
+
const enableInlineMarkdown = isInlineMarkdownTextSchema(schema);
|
|
924
|
+
const isReadOnlySplitInlineMarkdownFormChunk = mode === "form" && Boolean(schema.__textLineRange) && hasInlineMarkdownFormat;
|
|
925
|
+
const renderInlineMarkdownReadOnlyChunk = enableInlineMarkdown || isReadOnlySplitInlineMarkdownFormChunk;
|
|
926
|
+
const editable = isEditable(mode, schema) && !isReadOnlySplitInlineMarkdownFormChunk;
|
|
927
|
+
const usePlaceholder = editable && placeholder && !value;
|
|
1202
928
|
const getText = (element) => {
|
|
1203
929
|
let text = element.innerText;
|
|
1204
930
|
if (text.endsWith("\n")) text = text.slice(0, -1);
|
|
@@ -1206,18 +932,26 @@ var uiRender = async (arg) => {
|
|
|
1206
932
|
};
|
|
1207
933
|
const font = options?.font || getDefaultFont();
|
|
1208
934
|
const fontKitFont = await getFontKitFont(schema.fontName, font, _cache);
|
|
1209
|
-
const
|
|
935
|
+
const enableDynamicFontSize = shouldUseDynamicFontSize(schema);
|
|
1210
936
|
const displayValue = enableInlineMarkdown ? stripInlineMarkdown(value) : value;
|
|
1211
|
-
const dynamicRichTextFontSize = enableInlineMarkdown &&
|
|
937
|
+
const dynamicRichTextFontSize = enableInlineMarkdown && enableDynamicFontSize ? await calculateDynamicRichTextFontSize({
|
|
1212
938
|
value: usePlaceholder ? placeholder : value,
|
|
1213
939
|
schema,
|
|
1214
940
|
font,
|
|
1215
941
|
_cache
|
|
1216
942
|
}) : void 0;
|
|
1217
|
-
const textBlock = buildStyledTextContainer(
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
943
|
+
const textBlock = buildStyledTextContainer(isReadOnlySplitInlineMarkdownFormChunk ? {
|
|
944
|
+
...arg,
|
|
945
|
+
mode: "viewer"
|
|
946
|
+
} : arg, fontKitFont, usePlaceholder ? placeholder : displayValue, dynamicRichTextFontSize);
|
|
947
|
+
const processedText = replaceUnsupportedChars(getRangedPlainTextValue({
|
|
948
|
+
value,
|
|
949
|
+
schema,
|
|
950
|
+
fontKitFont,
|
|
951
|
+
fontSize: schema.fontSize ?? 13
|
|
952
|
+
}), fontKitFont);
|
|
953
|
+
if (!editable) {
|
|
954
|
+
if (renderInlineMarkdownReadOnlyChunk) {
|
|
1221
955
|
await renderInlineMarkdownReadOnly({
|
|
1222
956
|
textBlock,
|
|
1223
957
|
value,
|
|
@@ -1243,7 +977,7 @@ var uiRender = async (arg) => {
|
|
|
1243
977
|
});
|
|
1244
978
|
if (stopEditing) stopEditing();
|
|
1245
979
|
});
|
|
1246
|
-
if (
|
|
980
|
+
if (enableDynamicFontSize) {
|
|
1247
981
|
let dynamicFontSize = void 0;
|
|
1248
982
|
textBlock.addEventListener("keyup", () => {
|
|
1249
983
|
setTimeout(() => {
|
|
@@ -1292,30 +1026,84 @@ var renderInlineMarkdownReadOnly = async (arg) => {
|
|
|
1292
1026
|
font,
|
|
1293
1027
|
_cache
|
|
1294
1028
|
});
|
|
1029
|
+
if (schema.__textLineRange) {
|
|
1030
|
+
const lines = applyTextLineRange(layoutRichTextLines({
|
|
1031
|
+
runs,
|
|
1032
|
+
fontSize: schema.fontSize ?? 13,
|
|
1033
|
+
characterSpacing: schema.characterSpacing ?? 0,
|
|
1034
|
+
boxWidthInPt: mm2pt(schema.width)
|
|
1035
|
+
}), schema.__textLineRange);
|
|
1036
|
+
textBlock.innerHTML = "";
|
|
1037
|
+
lines.forEach((line, lineIndex) => {
|
|
1038
|
+
line.runs.forEach((run) => {
|
|
1039
|
+
appendInlineMarkdownRun({
|
|
1040
|
+
textBlock,
|
|
1041
|
+
run,
|
|
1042
|
+
schema,
|
|
1043
|
+
font
|
|
1044
|
+
});
|
|
1045
|
+
});
|
|
1046
|
+
if (lineIndex < lines.length - 1) textBlock.appendChild(document.createElement("br"));
|
|
1047
|
+
});
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1295
1050
|
textBlock.innerHTML = "";
|
|
1296
1051
|
runs.forEach((run) => {
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
}
|
|
1304
|
-
if (run.syntheticItalic) span.style.fontStyle = "italic";
|
|
1305
|
-
if (run.strikethrough) span.style.textDecoration = "line-through";
|
|
1306
|
-
if (run.code) {
|
|
1307
|
-
span.style.backgroundColor = CODE_BACKGROUND_COLOR;
|
|
1308
|
-
span.style.borderRadius = "2px";
|
|
1309
|
-
span.style.padding = "0 0.15em";
|
|
1310
|
-
if (!schema.fontVariants?.code || !font[schema.fontVariants.code]) span.style.fontFamily = run.fontName ? `'${run.fontName}', monospace` : "monospace";
|
|
1311
|
-
}
|
|
1312
|
-
textBlock.appendChild(span);
|
|
1052
|
+
appendInlineMarkdownRun({
|
|
1053
|
+
textBlock,
|
|
1054
|
+
run,
|
|
1055
|
+
schema,
|
|
1056
|
+
font
|
|
1057
|
+
});
|
|
1313
1058
|
});
|
|
1314
1059
|
};
|
|
1060
|
+
var appendInlineMarkdownRun = (arg) => {
|
|
1061
|
+
const { textBlock, run, schema, font } = arg;
|
|
1062
|
+
const href = run.href ? normalizeLinkHref(run.href) : void 0;
|
|
1063
|
+
const span = href ? document.createElement("a") : document.createElement("span");
|
|
1064
|
+
const processedText = replaceUnsupportedChars(run.text, run.fontKitFont);
|
|
1065
|
+
const textDecorations = [];
|
|
1066
|
+
span.textContent = processedText;
|
|
1067
|
+
if (href) {
|
|
1068
|
+
const anchor = span;
|
|
1069
|
+
anchor.href = href;
|
|
1070
|
+
if (!getInternalLinkTarget(href)) {
|
|
1071
|
+
anchor.target = "_blank";
|
|
1072
|
+
anchor.rel = "noopener noreferrer";
|
|
1073
|
+
}
|
|
1074
|
+
textDecorations.push("underline");
|
|
1075
|
+
}
|
|
1076
|
+
if (run.fontName) span.style.fontFamily = `'${run.fontName}'`;
|
|
1077
|
+
if (run.syntheticBold) {
|
|
1078
|
+
span.style.fontWeight = "800";
|
|
1079
|
+
span.style.textShadow = SYNTHETIC_BOLD_CSS_TEXT_SHADOW;
|
|
1080
|
+
}
|
|
1081
|
+
if (run.syntheticItalic) span.style.fontStyle = "italic";
|
|
1082
|
+
if (run.strikethrough) textDecorations.push("line-through");
|
|
1083
|
+
if (textDecorations.length > 0) span.style.textDecoration = textDecorations.join(" ");
|
|
1084
|
+
if (run.code) {
|
|
1085
|
+
span.style.backgroundColor = CODE_BACKGROUND_COLOR;
|
|
1086
|
+
span.style.borderRadius = "2px";
|
|
1087
|
+
span.style.padding = "0 0.15em";
|
|
1088
|
+
if (!schema.fontVariants?.code || !font[schema.fontVariants.code]) span.style.fontFamily = run.fontName ? `'${run.fontName}', monospace` : "monospace";
|
|
1089
|
+
}
|
|
1090
|
+
textBlock.appendChild(span);
|
|
1091
|
+
};
|
|
1092
|
+
var getRangedPlainTextValue = (arg) => {
|
|
1093
|
+
const { value, schema, fontKitFont, fontSize } = arg;
|
|
1094
|
+
if (!schema.__textLineRange) return value;
|
|
1095
|
+
return plainTextLinesToValue(applyTextLineRange(splitTextToSize({
|
|
1096
|
+
value,
|
|
1097
|
+
characterSpacing: schema.characterSpacing ?? 0,
|
|
1098
|
+
fontSize,
|
|
1099
|
+
fontKitFont,
|
|
1100
|
+
boxWidthInPt: mm2pt(schema.width)
|
|
1101
|
+
}), schema.__textLineRange));
|
|
1102
|
+
};
|
|
1315
1103
|
var buildStyledTextContainer = (arg, fontKitFont, value, resolvedDynamicFontSize) => {
|
|
1316
1104
|
const { schema, rootElement, mode } = arg;
|
|
1317
1105
|
let dynamicFontSize = resolvedDynamicFontSize;
|
|
1318
|
-
if (dynamicFontSize === void 0 && schema
|
|
1106
|
+
if (dynamicFontSize === void 0 && shouldUseDynamicFontSize(schema) && value) dynamicFontSize = calculateDynamicFontSize({
|
|
1319
1107
|
textSchema: schema,
|
|
1320
1108
|
fontKitFont,
|
|
1321
1109
|
value,
|
|
@@ -1416,6 +1204,6 @@ var textSchema = {
|
|
|
1416
1204
|
//#region src/builtins.ts
|
|
1417
1205
|
var builtInPlugins = { Text: textSchema };
|
|
1418
1206
|
//#endregion
|
|
1419
|
-
export { mapVerticalAlignToFlex as a, Formatter as c,
|
|
1207
|
+
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 };
|
|
1420
1208
|
|
|
1421
|
-
//# sourceMappingURL=builtins-
|
|
1209
|
+
//# sourceMappingURL=builtins-pN5NVCSV.js.map
|