@pdfme/schemas 6.1.1-dev.5 → 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-BpOyUs31.js → builtins-pN5NVCSV.js} +130 -530
- 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 +28 -42
- 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/measure.d.ts +26 -0
- package/dist/text/overflow.d.ts +3 -0
- package/dist/text/types.d.ts +7 -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-BpOyUs31.js.map +0 -1
- package/dist/helper-6FilIoVM.js.map +0 -1
- package/dist/lists-BmAAx0lx.js.map +0 -1
|
@@ -1,488 +1,10 @@
|
|
|
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, getInternalLinkTarget, mm2pt, normalizeLinkHref, normalizeSafeLinkUri,
|
|
5
|
+
import { DEFAULT_FONT_NAME, getDefaultFont, getFallbackFontName, getInternalLinkTarget, mm2pt, normalizeLinkHref, normalizeSafeLinkUri, registerInternalLinkAnnotation } from "@pdfme/common";
|
|
5
6
|
import { PDFName, PDFString } from "@pdfme/pdf-lib";
|
|
6
7
|
import { AlignCenter, AlignJustify, AlignLeft, AlignRight, ArrowDownToLine, ArrowUpToLine, Strikethrough, TextCursorInput, Underline } from "lucide";
|
|
7
|
-
//#region src/text/inlineMarkdown.ts
|
|
8
|
-
var MARKDOWN_ESCAPABLE_CHARS = new Set([
|
|
9
|
-
"\\",
|
|
10
|
-
"*",
|
|
11
|
-
"~",
|
|
12
|
-
"`",
|
|
13
|
-
"[",
|
|
14
|
-
"]",
|
|
15
|
-
"(",
|
|
16
|
-
")"
|
|
17
|
-
]);
|
|
18
|
-
var MARKDOWN_ESCAPE_PATTERN = /[\\*~`[\]()]/g;
|
|
19
|
-
var MARKDOWN_UNESCAPE_PATTERN = /\\([\\*~`[\]()])/g;
|
|
20
|
-
var sameStyle = (a, b) => Boolean(a.bold) === Boolean(b.bold) && Boolean(a.italic) === Boolean(b.italic) && Boolean(a.strikethrough) === Boolean(b.strikethrough) && Boolean(a.code) === Boolean(b.code) && a.href === b.href;
|
|
21
|
-
var appendRun = (runs, text, style) => {
|
|
22
|
-
if (!text) return;
|
|
23
|
-
const lastRun = runs.at(-1);
|
|
24
|
-
if (lastRun && sameStyle(lastRun, style)) {
|
|
25
|
-
lastRun.text += text;
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
runs.push({
|
|
29
|
-
text,
|
|
30
|
-
...style.bold ? { bold: true } : {},
|
|
31
|
-
...style.italic ? { italic: true } : {},
|
|
32
|
-
...style.strikethrough ? { strikethrough: true } : {},
|
|
33
|
-
...style.code ? { code: true } : {},
|
|
34
|
-
...style.href ? { href: style.href } : {}
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
var findClosingDelimiter = (value, delimiter, from) => {
|
|
38
|
-
for (let i = from; i < value.length; i++) {
|
|
39
|
-
if (value[i] === "\\") {
|
|
40
|
-
i += 1;
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (delimiter !== "`" && value[i] === "`") {
|
|
44
|
-
const codeEnd = findClosingDelimiter(value, "`", i + 1);
|
|
45
|
-
if (codeEnd === -1) continue;
|
|
46
|
-
i = codeEnd;
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (value.startsWith(delimiter, i)) return i;
|
|
50
|
-
}
|
|
51
|
-
return -1;
|
|
52
|
-
};
|
|
53
|
-
var getDelimiter = (value, index) => {
|
|
54
|
-
if (value[index] === "`") return "`";
|
|
55
|
-
if (value.startsWith("***", index)) return "***";
|
|
56
|
-
if (value.startsWith("**", index)) return "**";
|
|
57
|
-
if (value.startsWith("~~", index)) return "~~";
|
|
58
|
-
if (value[index] === "*") return "*";
|
|
59
|
-
return "";
|
|
60
|
-
};
|
|
61
|
-
var findLinkLabelEnd = (value, from, to) => {
|
|
62
|
-
for (let index = from; index < to; index += 1) {
|
|
63
|
-
if (value[index] === "\\") {
|
|
64
|
-
index += 1;
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (value[index] === "]") return index;
|
|
68
|
-
}
|
|
69
|
-
return -1;
|
|
70
|
-
};
|
|
71
|
-
var findLinkDestinationEnd = (value, from, to) => {
|
|
72
|
-
let depth = 0;
|
|
73
|
-
for (let index = from; index < to; index += 1) {
|
|
74
|
-
if (value[index] === "\\") {
|
|
75
|
-
index += 1;
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (value[index] === "(") {
|
|
79
|
-
depth += 1;
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (value[index] === ")") {
|
|
83
|
-
if (depth === 0) return index;
|
|
84
|
-
depth -= 1;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return -1;
|
|
88
|
-
};
|
|
89
|
-
var parseLinkAt = (value, index, to) => {
|
|
90
|
-
if (value[index] !== "[") return void 0;
|
|
91
|
-
const labelEnd = findLinkLabelEnd(value, index + 1, to);
|
|
92
|
-
if (labelEnd === -1 || value[labelEnd + 1] !== "(") return void 0;
|
|
93
|
-
const destinationStart = labelEnd + 2;
|
|
94
|
-
const destinationEnd = findLinkDestinationEnd(value, destinationStart, to);
|
|
95
|
-
if (destinationEnd === -1) return void 0;
|
|
96
|
-
const safeHref = normalizeLinkHref(value.slice(destinationStart, destinationEnd).replace(MARKDOWN_UNESCAPE_PATTERN, "$1"));
|
|
97
|
-
if (!safeHref) return void 0;
|
|
98
|
-
return {
|
|
99
|
-
labelStart: index + 1,
|
|
100
|
-
labelEnd,
|
|
101
|
-
href: safeHref,
|
|
102
|
-
end: destinationEnd + 1
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
var mergeStyle = (style, delimiter) => {
|
|
106
|
-
if (delimiter === "***") return {
|
|
107
|
-
...style,
|
|
108
|
-
bold: true,
|
|
109
|
-
italic: true
|
|
110
|
-
};
|
|
111
|
-
if (delimiter === "**") return {
|
|
112
|
-
...style,
|
|
113
|
-
bold: true
|
|
114
|
-
};
|
|
115
|
-
if (delimiter === "*") return {
|
|
116
|
-
...style,
|
|
117
|
-
italic: true
|
|
118
|
-
};
|
|
119
|
-
if (delimiter === "~~") return {
|
|
120
|
-
...style,
|
|
121
|
-
strikethrough: true
|
|
122
|
-
};
|
|
123
|
-
return style;
|
|
124
|
-
};
|
|
125
|
-
var parseRange = (value, from, to, style) => {
|
|
126
|
-
const runs = [];
|
|
127
|
-
let buffer = "";
|
|
128
|
-
const flush = () => {
|
|
129
|
-
appendRun(runs, buffer, style);
|
|
130
|
-
buffer = "";
|
|
131
|
-
};
|
|
132
|
-
for (let index = from; index < to; index++) {
|
|
133
|
-
const char = value[index];
|
|
134
|
-
if (char === "\\" && index + 1 < to && MARKDOWN_ESCAPABLE_CHARS.has(value[index + 1])) {
|
|
135
|
-
buffer += value[index + 1];
|
|
136
|
-
index += 1;
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
const link = style.href ? void 0 : parseLinkAt(value, index, to);
|
|
140
|
-
if (link) {
|
|
141
|
-
flush();
|
|
142
|
-
parseRange(value, link.labelStart, link.labelEnd, {
|
|
143
|
-
...style,
|
|
144
|
-
href: link.href
|
|
145
|
-
}).forEach((run) => appendRun(runs, run.text, run));
|
|
146
|
-
index = link.end - 1;
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
const delimiter = getDelimiter(value, index);
|
|
150
|
-
if (!delimiter) {
|
|
151
|
-
buffer += char;
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
const closingIndex = findClosingDelimiter(value, delimiter, index + delimiter.length);
|
|
155
|
-
if (closingIndex === -1 || closingIndex + delimiter.length > to) {
|
|
156
|
-
buffer += char;
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
flush();
|
|
160
|
-
if (delimiter === "`") appendRun(runs, value.slice(index + 1, closingIndex).replace(MARKDOWN_UNESCAPE_PATTERN, "$1"), {
|
|
161
|
-
...style,
|
|
162
|
-
code: true
|
|
163
|
-
});
|
|
164
|
-
else parseRange(value, index + delimiter.length, closingIndex, mergeStyle(style, delimiter)).forEach((run) => appendRun(runs, run.text, run));
|
|
165
|
-
index = closingIndex + delimiter.length - 1;
|
|
166
|
-
}
|
|
167
|
-
flush();
|
|
168
|
-
return runs;
|
|
169
|
-
};
|
|
170
|
-
var parseInlineMarkdown = (value) => {
|
|
171
|
-
if (!value) return [];
|
|
172
|
-
return parseRange(value, 0, value.length, {});
|
|
173
|
-
};
|
|
174
|
-
var escapeInlineMarkdown = (value) => value.replace(MARKDOWN_ESCAPE_PATTERN, (char) => `\\${char}`);
|
|
175
|
-
var stripInlineMarkdown = (value) => parseInlineMarkdown(value).map((run) => run.text).join("");
|
|
176
|
-
//#endregion
|
|
177
|
-
//#region src/text/richText.ts
|
|
178
|
-
var richTextWordSegmenter = new Intl.Segmenter(void 0, { granularity: "word" });
|
|
179
|
-
var richTextGraphemeSegmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
180
|
-
var getBaseFontName = (schema, font) => schema.fontName && font[schema.fontName] ? schema.fontName : getFallbackFontName(font);
|
|
181
|
-
var getLoadedFontName = (font, fontName) => fontName && font[fontName] ? fontName : void 0;
|
|
182
|
-
var isInlineMarkdownTextSchema = (schema) => schema.textFormat === "inline-markdown" && !(schema.type === "text" && schema.readOnly !== true);
|
|
183
|
-
var resolveFontVariant = (run, schema, font) => {
|
|
184
|
-
const baseFontName = getBaseFontName(schema, font);
|
|
185
|
-
const variants = schema.fontVariants ?? {};
|
|
186
|
-
const fallback = schema.fontVariantFallback ?? "synthetic";
|
|
187
|
-
let fontName = baseFontName;
|
|
188
|
-
let needsBold = Boolean(run.bold);
|
|
189
|
-
let needsItalic = Boolean(run.italic);
|
|
190
|
-
if (run.code) fontName = getLoadedFontName(font, variants.code) ?? baseFontName;
|
|
191
|
-
else if (run.bold && run.italic) {
|
|
192
|
-
const boldItalic = getLoadedFontName(font, variants.boldItalic);
|
|
193
|
-
const italic = getLoadedFontName(font, variants.italic);
|
|
194
|
-
const bold = getLoadedFontName(font, variants.bold);
|
|
195
|
-
if (boldItalic) {
|
|
196
|
-
fontName = boldItalic;
|
|
197
|
-
needsBold = false;
|
|
198
|
-
needsItalic = false;
|
|
199
|
-
} else if (italic) {
|
|
200
|
-
fontName = italic;
|
|
201
|
-
needsItalic = false;
|
|
202
|
-
} else if (bold) {
|
|
203
|
-
fontName = bold;
|
|
204
|
-
needsBold = false;
|
|
205
|
-
}
|
|
206
|
-
} else if (run.bold) {
|
|
207
|
-
const bold = getLoadedFontName(font, variants.bold);
|
|
208
|
-
if (bold) {
|
|
209
|
-
fontName = bold;
|
|
210
|
-
needsBold = false;
|
|
211
|
-
}
|
|
212
|
-
} else if (run.italic) {
|
|
213
|
-
const italic = getLoadedFontName(font, variants.italic);
|
|
214
|
-
if (italic) {
|
|
215
|
-
fontName = italic;
|
|
216
|
-
needsItalic = false;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
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}".`);
|
|
220
|
-
return {
|
|
221
|
-
fontName,
|
|
222
|
-
syntheticBold: fallback !== "plain" && needsBold,
|
|
223
|
-
syntheticItalic: fallback !== "plain" && needsItalic
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
var resolveRichTextRuns = async (arg) => {
|
|
227
|
-
const { runs, schema, font, _cache } = arg;
|
|
228
|
-
const fontKitCache = /* @__PURE__ */ new Map();
|
|
229
|
-
const getResolvedFontKitFont = async (fontName) => {
|
|
230
|
-
const cached = fontKitCache.get(fontName);
|
|
231
|
-
if (cached) return cached;
|
|
232
|
-
const fontKitFont = await getFontKitFont(fontName, font, _cache);
|
|
233
|
-
fontKitCache.set(fontName, fontKitFont);
|
|
234
|
-
return fontKitFont;
|
|
235
|
-
};
|
|
236
|
-
return Promise.all(runs.map(async (run) => {
|
|
237
|
-
const resolution = resolveFontVariant(run, schema, font);
|
|
238
|
-
return {
|
|
239
|
-
...run,
|
|
240
|
-
...resolution,
|
|
241
|
-
fontKitFont: await getResolvedFontKitFont(resolution.fontName)
|
|
242
|
-
};
|
|
243
|
-
}));
|
|
244
|
-
};
|
|
245
|
-
var measureRunText = (run, text, fontSize, characterSpacing) => {
|
|
246
|
-
const syntheticBoldWidth = run.syntheticBold ? fontSize * SYNTHETIC_BOLD_OFFSET_RATIO * 2 : 0;
|
|
247
|
-
const syntheticItalicWidth = run.syntheticItalic ? heightOfFontAtSize(run.fontKitFont, fontSize) * Math.tan(12 * Math.PI / 180) : 0;
|
|
248
|
-
return widthOfTextAtSize(text, run.fontKitFont, fontSize, characterSpacing) + syntheticBoldWidth + syntheticItalicWidth;
|
|
249
|
-
};
|
|
250
|
-
var createLine = () => ({
|
|
251
|
-
runs: [],
|
|
252
|
-
width: 0,
|
|
253
|
-
hardBreak: false
|
|
254
|
-
});
|
|
255
|
-
var pushRunToLine = (line, run, text, fontSize, characterSpacing) => {
|
|
256
|
-
if (!text) return;
|
|
257
|
-
const width = measureRunText(run, text, fontSize, characterSpacing);
|
|
258
|
-
if (line.runs.length > 0) line.width += characterSpacing;
|
|
259
|
-
line.runs.push({
|
|
260
|
-
...run,
|
|
261
|
-
text,
|
|
262
|
-
width
|
|
263
|
-
});
|
|
264
|
-
line.width += width;
|
|
265
|
-
};
|
|
266
|
-
var measurePiecesWidth = (pieces, fontSize, characterSpacing) => {
|
|
267
|
-
let width = 0;
|
|
268
|
-
let hasText = false;
|
|
269
|
-
pieces.forEach((piece) => {
|
|
270
|
-
if (!piece.text) return;
|
|
271
|
-
if (hasText) width += characterSpacing;
|
|
272
|
-
width += measureRunText(piece.run, piece.text, fontSize, characterSpacing);
|
|
273
|
-
hasText = true;
|
|
274
|
-
});
|
|
275
|
-
return width;
|
|
276
|
-
};
|
|
277
|
-
var sliceRunPieces = (pieces, startIndex, endIndex) => {
|
|
278
|
-
const result = [];
|
|
279
|
-
let offset = 0;
|
|
280
|
-
pieces.forEach((piece) => {
|
|
281
|
-
const pieceStart = offset;
|
|
282
|
-
const pieceEnd = pieceStart + piece.text.length;
|
|
283
|
-
const sliceStart = Math.max(startIndex, pieceStart);
|
|
284
|
-
const sliceEnd = Math.min(endIndex, pieceEnd);
|
|
285
|
-
if (sliceStart < sliceEnd) result.push({
|
|
286
|
-
run: piece.run,
|
|
287
|
-
text: piece.text.slice(sliceStart - pieceStart, sliceEnd - pieceStart)
|
|
288
|
-
});
|
|
289
|
-
offset = pieceEnd;
|
|
290
|
-
});
|
|
291
|
-
return result;
|
|
292
|
-
};
|
|
293
|
-
var segmentRunPiecesByWord = (runs, onSegment, onHardBreak) => {
|
|
294
|
-
let paragraphPieces = [];
|
|
295
|
-
const flushParagraph = () => {
|
|
296
|
-
if (paragraphPieces.length === 0) return;
|
|
297
|
-
const paragraphText = paragraphPieces.map((piece) => piece.text).join("");
|
|
298
|
-
Array.from(richTextWordSegmenter.segment(paragraphText), ({ segment, index }) => {
|
|
299
|
-
const pieces = sliceRunPieces(paragraphPieces, index, index + segment.length);
|
|
300
|
-
if (pieces.length > 0) onSegment(pieces);
|
|
301
|
-
});
|
|
302
|
-
paragraphPieces = [];
|
|
303
|
-
};
|
|
304
|
-
runs.forEach((run) => {
|
|
305
|
-
run.text.split(/(\r\n|\r|\n)/).forEach((part) => {
|
|
306
|
-
if (part === "\r\n" || part === "\r" || part === "\n") {
|
|
307
|
-
flushParagraph();
|
|
308
|
-
onHardBreak();
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
if (part) paragraphPieces.push({
|
|
312
|
-
run,
|
|
313
|
-
text: part
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
flushParagraph();
|
|
318
|
-
};
|
|
319
|
-
var splitIntoGraphemes = (value) => Array.from(richTextGraphemeSegmenter.segment(value), ({ segment }) => segment);
|
|
320
|
-
var countRichTextLineGraphemes = (line) => splitIntoGraphemes(line.runs.map((run) => run.text).join("")).length;
|
|
321
|
-
var layoutRichTextLines = (arg) => {
|
|
322
|
-
const { runs, fontSize, characterSpacing, boxWidthInPt } = arg;
|
|
323
|
-
const lines = [];
|
|
324
|
-
let currentLine = createLine();
|
|
325
|
-
const pushCurrentLine = (hardBreak) => {
|
|
326
|
-
currentLine.hardBreak = hardBreak;
|
|
327
|
-
lines.push(currentLine);
|
|
328
|
-
currentLine = createLine();
|
|
329
|
-
};
|
|
330
|
-
const pushPiecesToLine = (pieces) => {
|
|
331
|
-
pieces.forEach((piece) => {
|
|
332
|
-
pushRunToLine(currentLine, piece.run, piece.text, fontSize, characterSpacing);
|
|
333
|
-
});
|
|
334
|
-
};
|
|
335
|
-
const pushOversizedText = (run, text) => {
|
|
336
|
-
let remainingText = text;
|
|
337
|
-
while (remainingText.length > 0) {
|
|
338
|
-
const pendingSpacing = currentLine.runs.length > 0 ? characterSpacing : 0;
|
|
339
|
-
const remainingWidth = Math.max(boxWidthInPt - currentLine.width - pendingSpacing, 0);
|
|
340
|
-
const remainingTextWidth = measureRunText(run, remainingText, fontSize, characterSpacing);
|
|
341
|
-
if (remainingTextWidth <= remainingWidth || currentLine.runs.length === 0 && remainingTextWidth <= boxWidthInPt) {
|
|
342
|
-
pushRunToLine(currentLine, run, remainingText, fontSize, characterSpacing);
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
if (currentLine.runs.length > 0 && remainingTextWidth <= boxWidthInPt) {
|
|
346
|
-
pushCurrentLine(false);
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
const graphemes = splitIntoGraphemes(remainingText);
|
|
350
|
-
let fittingText = "";
|
|
351
|
-
let fittingLength = 0;
|
|
352
|
-
for (const grapheme of graphemes) {
|
|
353
|
-
const candidate = fittingText + grapheme;
|
|
354
|
-
const candidateWidth = measureRunText(run, candidate, fontSize, characterSpacing);
|
|
355
|
-
const maxWidth = currentLine.runs.length === 0 ? boxWidthInPt : remainingWidth;
|
|
356
|
-
if (candidateWidth > maxWidth) {
|
|
357
|
-
if (fittingText) break;
|
|
358
|
-
if (currentLine.runs.length > 0) break;
|
|
359
|
-
}
|
|
360
|
-
fittingText = candidate;
|
|
361
|
-
fittingLength += grapheme.length;
|
|
362
|
-
if (candidateWidth > maxWidth) break;
|
|
363
|
-
}
|
|
364
|
-
if (!fittingText) {
|
|
365
|
-
pushCurrentLine(false);
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
pushRunToLine(currentLine, run, fittingText, fontSize, characterSpacing);
|
|
369
|
-
remainingText = remainingText.slice(fittingLength);
|
|
370
|
-
if (remainingText.length > 0) pushCurrentLine(false);
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
const pushSegment = (pieces) => {
|
|
374
|
-
const segmentWidth = measurePiecesWidth(pieces, fontSize, characterSpacing);
|
|
375
|
-
const pendingSpacing = currentLine.runs.length > 0 ? characterSpacing : 0;
|
|
376
|
-
if (segmentWidth <= Math.max(boxWidthInPt - currentLine.width - pendingSpacing, 0) || currentLine.runs.length === 0 && segmentWidth <= boxWidthInPt) {
|
|
377
|
-
pushPiecesToLine(pieces);
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
if (currentLine.runs.length > 0) {
|
|
381
|
-
pushCurrentLine(false);
|
|
382
|
-
if (segmentWidth <= boxWidthInPt) {
|
|
383
|
-
pushPiecesToLine(pieces);
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
pieces.forEach((piece) => pushOversizedText(piece.run, piece.text));
|
|
388
|
-
};
|
|
389
|
-
segmentRunPiecesByWord(runs, pushSegment, () => pushCurrentLine(true));
|
|
390
|
-
if (currentLine.runs.length > 0 || lines.length === 0) pushCurrentLine(false);
|
|
391
|
-
return lines;
|
|
392
|
-
};
|
|
393
|
-
var measureParagraphWidths = (runs, fontSize, characterSpacing) => {
|
|
394
|
-
const widths = [];
|
|
395
|
-
let paragraphPieces = [];
|
|
396
|
-
const pushWidth = () => {
|
|
397
|
-
widths.push(measurePiecesWidth(paragraphPieces, fontSize, characterSpacing));
|
|
398
|
-
paragraphPieces = [];
|
|
399
|
-
};
|
|
400
|
-
runs.forEach((run) => {
|
|
401
|
-
run.text.split(/(\r\n|\r|\n)/).forEach((part) => {
|
|
402
|
-
if (part === "\r\n" || part === "\r" || part === "\n") {
|
|
403
|
-
pushWidth();
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
if (part) paragraphPieces.push({
|
|
407
|
-
run,
|
|
408
|
-
text: part
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
pushWidth();
|
|
413
|
-
return widths;
|
|
414
|
-
};
|
|
415
|
-
var getLineHeightAtSize = (line, fontSize) => {
|
|
416
|
-
if (line.runs.length === 0) return fontSize;
|
|
417
|
-
return Math.max(...line.runs.map((run) => heightOfFontAtSize(run.fontKitFont, fontSize)));
|
|
418
|
-
};
|
|
419
|
-
var calculateDynamicRichTextFontSize = async (arg) => {
|
|
420
|
-
const { value, schema, font, _cache, startingFontSize } = arg;
|
|
421
|
-
const { fontSize: schemaFontSize, dynamicFontSize: dynamicFontSizeSetting, characterSpacing: schemaCharacterSpacing, width: boxWidth, height: boxHeight, lineHeight = 1 } = schema;
|
|
422
|
-
const fontSize = startingFontSize || schemaFontSize || 13;
|
|
423
|
-
if (!dynamicFontSizeSetting) return fontSize;
|
|
424
|
-
if (dynamicFontSizeSetting.max < dynamicFontSizeSetting.min) return fontSize;
|
|
425
|
-
const resolvedRuns = await resolveRichTextRuns({
|
|
426
|
-
runs: parseInlineMarkdown(value),
|
|
427
|
-
schema,
|
|
428
|
-
font,
|
|
429
|
-
_cache
|
|
430
|
-
});
|
|
431
|
-
const characterSpacing = schemaCharacterSpacing ?? 0;
|
|
432
|
-
const dynamicFontFit = dynamicFontSizeSetting.fit ?? "vertical";
|
|
433
|
-
const boxWidthInPt = mm2pt(boxWidth);
|
|
434
|
-
let dynamicFontSize = fontSize;
|
|
435
|
-
if (dynamicFontSize < dynamicFontSizeSetting.min) dynamicFontSize = dynamicFontSizeSetting.min;
|
|
436
|
-
else if (dynamicFontSize > dynamicFontSizeSetting.max) dynamicFontSize = dynamicFontSizeSetting.max;
|
|
437
|
-
const calculateConstraints = (size) => {
|
|
438
|
-
let totalWidthInMm = 0;
|
|
439
|
-
let totalHeightInMm = 0;
|
|
440
|
-
layoutRichTextLines({
|
|
441
|
-
runs: resolvedRuns,
|
|
442
|
-
fontSize: size,
|
|
443
|
-
characterSpacing,
|
|
444
|
-
boxWidthInPt
|
|
445
|
-
}).forEach((line, lineIndex) => {
|
|
446
|
-
if (dynamicFontFit === "vertical") totalWidthInMm = Math.max(totalWidthInMm, pt2mm(line.width));
|
|
447
|
-
if (lineIndex === 0) totalHeightInMm += pt2mm(getLineHeightAtSize(line, size) * lineHeight);
|
|
448
|
-
else totalHeightInMm += pt2mm(size * lineHeight);
|
|
449
|
-
});
|
|
450
|
-
if (dynamicFontFit === "horizontal") measureParagraphWidths(resolvedRuns, size, characterSpacing).forEach((paragraphWidth) => {
|
|
451
|
-
totalWidthInMm = Math.max(totalWidthInMm, pt2mm(paragraphWidth));
|
|
452
|
-
});
|
|
453
|
-
return {
|
|
454
|
-
totalWidthInMm,
|
|
455
|
-
totalHeightInMm
|
|
456
|
-
};
|
|
457
|
-
};
|
|
458
|
-
const shouldFontGrowToFit = (totalWidthInMm, totalHeightInMm) => {
|
|
459
|
-
if (dynamicFontSize >= dynamicFontSizeSetting.max) return false;
|
|
460
|
-
if (dynamicFontFit === "horizontal") return totalWidthInMm < boxWidth;
|
|
461
|
-
return totalHeightInMm < boxHeight;
|
|
462
|
-
};
|
|
463
|
-
const shouldFontShrinkToFit = (totalWidthInMm, totalHeightInMm) => {
|
|
464
|
-
if (dynamicFontSize <= dynamicFontSizeSetting.min || dynamicFontSize <= 0) return false;
|
|
465
|
-
return totalWidthInMm > boxWidth || totalHeightInMm > boxHeight;
|
|
466
|
-
};
|
|
467
|
-
let { totalWidthInMm, totalHeightInMm } = calculateConstraints(dynamicFontSize);
|
|
468
|
-
while (shouldFontGrowToFit(totalWidthInMm, totalHeightInMm)) {
|
|
469
|
-
dynamicFontSize += FONT_SIZE_ADJUSTMENT;
|
|
470
|
-
const { totalWidthInMm: newWidth, totalHeightInMm: newHeight } = calculateConstraints(dynamicFontSize);
|
|
471
|
-
if (newHeight < boxHeight) {
|
|
472
|
-
totalWidthInMm = newWidth;
|
|
473
|
-
totalHeightInMm = newHeight;
|
|
474
|
-
} else {
|
|
475
|
-
dynamicFontSize -= FONT_SIZE_ADJUSTMENT;
|
|
476
|
-
break;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
while (shouldFontShrinkToFit(totalWidthInMm, totalHeightInMm)) {
|
|
480
|
-
dynamicFontSize -= FONT_SIZE_ADJUSTMENT;
|
|
481
|
-
({totalWidthInMm, totalHeightInMm} = calculateConstraints(dynamicFontSize));
|
|
482
|
-
}
|
|
483
|
-
return dynamicFontSize;
|
|
484
|
-
};
|
|
485
|
-
//#endregion
|
|
486
8
|
//#region src/text/linkAnnotation.ts
|
|
487
9
|
var addUriLinkAnnotation = (arg) => {
|
|
488
10
|
const { pdfDoc, page, uri, rect, borderWidth = 0 } = arg;
|
|
@@ -667,7 +189,7 @@ var drawRun = (arg) => {
|
|
|
667
189
|
};
|
|
668
190
|
var renderInlineMarkdownText = async (arg) => {
|
|
669
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;
|
|
670
|
-
const
|
|
192
|
+
const allLines = layoutRichTextLines({
|
|
671
193
|
runs: await resolveRichTextRuns({
|
|
672
194
|
runs: parseInlineMarkdown(value),
|
|
673
195
|
schema,
|
|
@@ -678,6 +200,8 @@ var renderInlineMarkdownText = async (arg) => {
|
|
|
678
200
|
characterSpacing,
|
|
679
201
|
boxWidthInPt: width
|
|
680
202
|
});
|
|
203
|
+
const lines = applyTextLineRange(allLines, schema.__textLineRange);
|
|
204
|
+
const lineRangeStart = schema.__textLineRange?.start ?? 0;
|
|
681
205
|
const pdfFontObj = await embedFontsForRuns(lines.flatMap((line) => line.runs), embedPdfFont);
|
|
682
206
|
const firstLineTextHeight = heightOfFontAtSize(fontKitFont, fontSize);
|
|
683
207
|
const descent = getFontDescentInPt(fontKitFont, fontSize);
|
|
@@ -693,7 +217,7 @@ var renderInlineMarkdownText = async (arg) => {
|
|
|
693
217
|
if (line.runs.length === 0) return;
|
|
694
218
|
let textWidth = line.width;
|
|
695
219
|
let spacing = characterSpacing;
|
|
696
|
-
if (alignment === "justify" && !line.hardBreak && rowIndex <
|
|
220
|
+
if (alignment === "justify" && !line.hardBreak && lineRangeStart + rowIndex < allLines.length - 1) {
|
|
697
221
|
const graphemeCount = countRichTextLineGraphemes(line);
|
|
698
222
|
if (graphemeCount > 0) {
|
|
699
223
|
spacing += (width - textWidth) / graphemeCount;
|
|
@@ -779,6 +303,10 @@ var renderInlineMarkdownText = async (arg) => {
|
|
|
779
303
|
});
|
|
780
304
|
};
|
|
781
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
|
|
782
310
|
//#region src/text/pdfRender.ts
|
|
783
311
|
var PDF_FONT_CACHE_KEY = "text-pdf-font-cache";
|
|
784
312
|
var getPdfFontCache = (_cache) => {
|
|
@@ -805,7 +333,7 @@ var embedAndGetFont = (arg) => {
|
|
|
805
333
|
return pdfFontPromise;
|
|
806
334
|
};
|
|
807
335
|
var getFontProp = ({ value, fontKitFont, schema, colorType, fontSize: resolvedFontSize }) => {
|
|
808
|
-
const fontSize = resolvedFontSize ?? (schema
|
|
336
|
+
const fontSize = resolvedFontSize ?? (shouldUseDynamicFontSize(schema) ? calculateDynamicFontSize({
|
|
809
337
|
textSchema: schema,
|
|
810
338
|
fontKitFont,
|
|
811
339
|
value
|
|
@@ -843,7 +371,7 @@ var pdfRender = async (arg) => {
|
|
|
843
371
|
fontKitFont,
|
|
844
372
|
schema,
|
|
845
373
|
colorType,
|
|
846
|
-
fontSize: enableInlineMarkdown && schema
|
|
374
|
+
fontSize: enableInlineMarkdown && shouldUseDynamicFontSize(schema) ? await calculateDynamicRichTextFontSize({
|
|
847
375
|
value,
|
|
848
376
|
schema,
|
|
849
377
|
font,
|
|
@@ -922,13 +450,13 @@ var pdfRender = async (arg) => {
|
|
|
922
450
|
const firstLineTextHeight = heightOfFontAtSize(fontKitFont, fontSize);
|
|
923
451
|
const descent = getFontDescentInPt(fontKitFont, fontSize);
|
|
924
452
|
const halfLineHeightAdjustment = lineHeight === 0 ? 0 : (lineHeight - 1) * fontSize / 2;
|
|
925
|
-
const lines = splitTextToSize({
|
|
453
|
+
const lines = applyTextLineRange(splitTextToSize({
|
|
926
454
|
value,
|
|
927
455
|
characterSpacing,
|
|
928
456
|
fontSize,
|
|
929
457
|
fontKitFont,
|
|
930
458
|
boxWidthInPt: width
|
|
931
|
-
});
|
|
459
|
+
}), schema.__textLineRange);
|
|
932
460
|
const needsTextWidth = alignment !== "left" || Boolean(schema.strikethrough || schema.underline);
|
|
933
461
|
const needsTextHeight = Boolean(schema.strikethrough || schema.underline);
|
|
934
462
|
let yOffset = 0;
|
|
@@ -1095,9 +623,11 @@ function getExtraFormatterSchema(i18n) {
|
|
|
1095
623
|
//#region src/text/propPanel.ts
|
|
1096
624
|
var UseDynamicFontSize = (props) => {
|
|
1097
625
|
const { rootElement, changeSchemas, activeSchema, i18n } = props;
|
|
626
|
+
const isExpand = isTextOverflowExpand(activeSchema);
|
|
1098
627
|
const checkbox = document.createElement("input");
|
|
1099
628
|
checkbox.type = "checkbox";
|
|
1100
|
-
checkbox.checked = Boolean(activeSchema?.dynamicFontSize);
|
|
629
|
+
checkbox.checked = !isExpand && Boolean(activeSchema?.dynamicFontSize);
|
|
630
|
+
checkbox.disabled = isExpand;
|
|
1101
631
|
checkbox.onchange = (e) => {
|
|
1102
632
|
changeSchemas([{
|
|
1103
633
|
key: "dynamicFontSize",
|
|
@@ -1114,6 +644,7 @@ var UseDynamicFontSize = (props) => {
|
|
|
1114
644
|
span.innerText = i18n("schemas.text.dynamicFontSize") || "";
|
|
1115
645
|
span.style.cssText = "margin-left: 0.5rem";
|
|
1116
646
|
label.style.cssText = "display: flex; width: 100%;";
|
|
647
|
+
label.style.opacity = isExpand ? "0.5" : "1";
|
|
1117
648
|
label.appendChild(checkbox);
|
|
1118
649
|
label.appendChild(span);
|
|
1119
650
|
rootElement.appendChild(label);
|
|
@@ -1147,8 +678,8 @@ var propPanel = {
|
|
|
1147
678
|
} };
|
|
1148
679
|
const fontNames = Object.keys(font);
|
|
1149
680
|
const fallbackFontName = getFallbackFontName(font);
|
|
1150
|
-
const enableDynamicFont = Boolean(activeSchema?.dynamicFontSize);
|
|
1151
681
|
const activeTextSchema = activeSchema;
|
|
682
|
+
const enableDynamicFont = !isTextOverflowExpand(activeTextSchema) && Boolean(activeSchema?.dynamicFontSize);
|
|
1152
683
|
const hideTextFormat = activeTextSchema.type === "text" && activeTextSchema.readOnly !== true;
|
|
1153
684
|
const enableInlineMarkdown = activeTextSchema.textFormat === "inline-markdown" && !hideTextFormat;
|
|
1154
685
|
const baseFontName = activeTextSchema.fontName && font[activeTextSchema.fontName] ? activeTextSchema.fontName : fallbackFontName;
|
|
@@ -1198,6 +729,20 @@ var propPanel = {
|
|
|
1198
729
|
},
|
|
1199
730
|
span: 8
|
|
1200
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
|
+
},
|
|
1201
746
|
useDynamicFontSize: {
|
|
1202
747
|
type: "boolean",
|
|
1203
748
|
widget: "UseDynamicFontSize",
|
|
@@ -1341,6 +886,7 @@ var propPanel = {
|
|
|
1341
886
|
verticalAlignment: "top",
|
|
1342
887
|
fontSize: 13,
|
|
1343
888
|
textFormat: DEFAULT_TEXT_FORMAT,
|
|
889
|
+
overflow: DEFAULT_TEXT_OVERFLOW,
|
|
1344
890
|
fontVariantFallback: DEFAULT_FONT_VARIANT_FALLBACK,
|
|
1345
891
|
lineHeight: 1,
|
|
1346
892
|
characterSpacing: 0,
|
|
@@ -1373,7 +919,12 @@ var replaceUnsupportedChars = (text, fontKitFont) => {
|
|
|
1373
919
|
};
|
|
1374
920
|
var uiRender = async (arg) => {
|
|
1375
921
|
const { value, schema, mode, onChange, stopEditing, tabIndex, placeholder, options, _cache } = arg;
|
|
1376
|
-
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;
|
|
1377
928
|
const getText = (element) => {
|
|
1378
929
|
let text = element.innerText;
|
|
1379
930
|
if (text.endsWith("\n")) text = text.slice(0, -1);
|
|
@@ -1381,18 +932,26 @@ var uiRender = async (arg) => {
|
|
|
1381
932
|
};
|
|
1382
933
|
const font = options?.font || getDefaultFont();
|
|
1383
934
|
const fontKitFont = await getFontKitFont(schema.fontName, font, _cache);
|
|
1384
|
-
const
|
|
935
|
+
const enableDynamicFontSize = shouldUseDynamicFontSize(schema);
|
|
1385
936
|
const displayValue = enableInlineMarkdown ? stripInlineMarkdown(value) : value;
|
|
1386
|
-
const dynamicRichTextFontSize = enableInlineMarkdown &&
|
|
937
|
+
const dynamicRichTextFontSize = enableInlineMarkdown && enableDynamicFontSize ? await calculateDynamicRichTextFontSize({
|
|
1387
938
|
value: usePlaceholder ? placeholder : value,
|
|
1388
939
|
schema,
|
|
1389
940
|
font,
|
|
1390
941
|
_cache
|
|
1391
942
|
}) : void 0;
|
|
1392
|
-
const textBlock = buildStyledTextContainer(
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
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) {
|
|
1396
955
|
await renderInlineMarkdownReadOnly({
|
|
1397
956
|
textBlock,
|
|
1398
957
|
value,
|
|
@@ -1418,7 +977,7 @@ var uiRender = async (arg) => {
|
|
|
1418
977
|
});
|
|
1419
978
|
if (stopEditing) stopEditing();
|
|
1420
979
|
});
|
|
1421
|
-
if (
|
|
980
|
+
if (enableDynamicFontSize) {
|
|
1422
981
|
let dynamicFontSize = void 0;
|
|
1423
982
|
textBlock.addEventListener("keyup", () => {
|
|
1424
983
|
setTimeout(() => {
|
|
@@ -1467,43 +1026,84 @@ var renderInlineMarkdownReadOnly = async (arg) => {
|
|
|
1467
1026
|
font,
|
|
1468
1027
|
_cache
|
|
1469
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
|
+
}
|
|
1470
1050
|
textBlock.innerHTML = "";
|
|
1471
1051
|
runs.forEach((run) => {
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
const anchor = span;
|
|
1479
|
-
anchor.href = href;
|
|
1480
|
-
if (!getInternalLinkTarget(href)) {
|
|
1481
|
-
anchor.target = "_blank";
|
|
1482
|
-
anchor.rel = "noopener noreferrer";
|
|
1483
|
-
}
|
|
1484
|
-
textDecorations.push("underline");
|
|
1485
|
-
}
|
|
1486
|
-
if (run.fontName) span.style.fontFamily = `'${run.fontName}'`;
|
|
1487
|
-
if (run.syntheticBold) {
|
|
1488
|
-
span.style.fontWeight = "800";
|
|
1489
|
-
span.style.textShadow = SYNTHETIC_BOLD_CSS_TEXT_SHADOW;
|
|
1490
|
-
}
|
|
1491
|
-
if (run.syntheticItalic) span.style.fontStyle = "italic";
|
|
1492
|
-
if (run.strikethrough) textDecorations.push("line-through");
|
|
1493
|
-
if (textDecorations.length > 0) span.style.textDecoration = textDecorations.join(" ");
|
|
1494
|
-
if (run.code) {
|
|
1495
|
-
span.style.backgroundColor = CODE_BACKGROUND_COLOR;
|
|
1496
|
-
span.style.borderRadius = "2px";
|
|
1497
|
-
span.style.padding = "0 0.15em";
|
|
1498
|
-
if (!schema.fontVariants?.code || !font[schema.fontVariants.code]) span.style.fontFamily = run.fontName ? `'${run.fontName}', monospace` : "monospace";
|
|
1499
|
-
}
|
|
1500
|
-
textBlock.appendChild(span);
|
|
1052
|
+
appendInlineMarkdownRun({
|
|
1053
|
+
textBlock,
|
|
1054
|
+
run,
|
|
1055
|
+
schema,
|
|
1056
|
+
font
|
|
1057
|
+
});
|
|
1501
1058
|
});
|
|
1502
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
|
+
};
|
|
1503
1103
|
var buildStyledTextContainer = (arg, fontKitFont, value, resolvedDynamicFontSize) => {
|
|
1504
1104
|
const { schema, rootElement, mode } = arg;
|
|
1505
1105
|
let dynamicFontSize = resolvedDynamicFontSize;
|
|
1506
|
-
if (dynamicFontSize === void 0 && schema
|
|
1106
|
+
if (dynamicFontSize === void 0 && shouldUseDynamicFontSize(schema) && value) dynamicFontSize = calculateDynamicFontSize({
|
|
1507
1107
|
textSchema: schema,
|
|
1508
1108
|
fontKitFont,
|
|
1509
1109
|
value,
|
|
@@ -1604,6 +1204,6 @@ var textSchema = {
|
|
|
1604
1204
|
//#region src/builtins.ts
|
|
1605
1205
|
var builtInPlugins = { Text: textSchema };
|
|
1606
1206
|
//#endregion
|
|
1607
|
-
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 };
|
|
1608
1208
|
|
|
1609
|
-
//# sourceMappingURL=builtins-
|
|
1209
|
+
//# sourceMappingURL=builtins-pN5NVCSV.js.map
|