@pdfme/schemas 6.1.1-dev.13 → 6.1.1-dev.16
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/index.js +75 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { a as normalizeListItems, c as LIST_STYLE_BULLET, i as normalizeListItem
|
|
|
7
7
|
import { n as substituteVariablesAsInlineMarkdownLiterals, r as validateVariables, t as substituteVariables } from "./helper-BJzBqIT4.js";
|
|
8
8
|
import "./tables.js";
|
|
9
9
|
import "./lists.js";
|
|
10
|
-
import { DEFAULT_FONT_NAME, ZOOM, b64toUint8Array, getDefaultFont, getFallbackFontName, mm2pt, px2mm } from "@pdfme/common";
|
|
10
|
+
import { DEFAULT_FONT_NAME, ZOOM, b64toUint8Array, getDefaultFont, getFallbackFontName, getInternalLinkTarget, mm2pt, normalizeLinkHref, px2mm } from "@pdfme/common";
|
|
11
11
|
import { Buffer as Buffer$1 } from "buffer";
|
|
12
12
|
import { toRadians } from "@pdfme/pdf-lib";
|
|
13
13
|
import { Barcode, Calendar, CalendarClock, ChevronDown, Circle, CircleDot, Clock, Image, List, Minus, QrCode, Route, Square, SquareCheck, Table, Type } from "lucide";
|
|
@@ -246,16 +246,6 @@ var uiRender$3 = async (arg) => {
|
|
|
246
246
|
const renderResolvedValue = schema.readOnly === true && mode !== "designer";
|
|
247
247
|
const renderValue = renderResolvedValue ? value : isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(text, value) : substituteVariables(text, value);
|
|
248
248
|
if (mode === "form" && numVariables > 0 && !renderResolvedValue) {
|
|
249
|
-
if (getTextLineRange(schema) && isInlineMarkdownTextSchema(schema)) {
|
|
250
|
-
await uiRender$4({
|
|
251
|
-
value: renderValue,
|
|
252
|
-
schema,
|
|
253
|
-
mode: "viewer",
|
|
254
|
-
rootElement,
|
|
255
|
-
...rest
|
|
256
|
-
});
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
249
|
await formUiRender(arg);
|
|
260
250
|
return;
|
|
261
251
|
}
|
|
@@ -305,18 +295,20 @@ var formUiRender = async (arg) => {
|
|
|
305
295
|
const textBlock = buildStyledTextContainer(arg, await getFontKitFont(schema.fontName, font, _cache), inlineMarkdownRuns ? getInlineMarkdownFormDisplayText(inlineMarkdownRuns, variables) : substitutedText);
|
|
306
296
|
if (getTextLineRange(schema)) {
|
|
307
297
|
const { lines } = await measureTextLines({
|
|
308
|
-
value: substitutedText,
|
|
298
|
+
value: inlineMarkdownRuns ? substituteVariablesAsInlineMarkdownLiterals(rawText, variables) : substitutedText,
|
|
309
299
|
schema,
|
|
310
300
|
font,
|
|
311
301
|
_cache,
|
|
312
302
|
ignoreDynamicFontSize: true
|
|
313
303
|
});
|
|
314
|
-
|
|
304
|
+
renderSplitVariableSpans({
|
|
315
305
|
textBlock,
|
|
316
306
|
lines,
|
|
307
|
+
runs: inlineMarkdownRuns,
|
|
317
308
|
rawText,
|
|
318
309
|
variables,
|
|
319
310
|
schema,
|
|
311
|
+
font,
|
|
320
312
|
theme,
|
|
321
313
|
onChange,
|
|
322
314
|
stopEditing
|
|
@@ -371,11 +363,12 @@ var formUiRender = async (arg) => {
|
|
|
371
363
|
}
|
|
372
364
|
}
|
|
373
365
|
};
|
|
374
|
-
var
|
|
375
|
-
const { textBlock, lines, rawText, variables, schema, theme, onChange, stopEditing } = arg;
|
|
366
|
+
var renderSplitVariableSpans = (arg) => {
|
|
367
|
+
const { textBlock, lines, runs, rawText, variables, schema, font, theme, onChange, stopEditing } = arg;
|
|
376
368
|
const lineRange = getTextLineRange(schema);
|
|
377
|
-
const lineSegments =
|
|
369
|
+
const lineSegments = getSplitLineSegments({
|
|
378
370
|
lines,
|
|
371
|
+
runs,
|
|
379
372
|
rawText,
|
|
380
373
|
variables,
|
|
381
374
|
start: lineRange?.start ?? 0,
|
|
@@ -389,23 +382,31 @@ var renderSplitPlainVariableSpans = (arg) => {
|
|
|
389
382
|
textBlock,
|
|
390
383
|
segment,
|
|
391
384
|
variables,
|
|
385
|
+
schema,
|
|
386
|
+
font,
|
|
392
387
|
theme,
|
|
393
388
|
onChange,
|
|
394
389
|
stopEditing
|
|
395
390
|
});
|
|
396
391
|
return;
|
|
397
392
|
}
|
|
398
|
-
const span = document.createElement("span");
|
|
393
|
+
const span = segment.run ? createStaticInlineMarkdownElement(segment.run) : document.createElement("span");
|
|
399
394
|
span.style.letterSpacing = lineIndex === lineSegments.length - 1 ? "0" : "inherit";
|
|
400
395
|
span.textContent = segment.text;
|
|
396
|
+
if (segment.run) applyInlineMarkdownStyle({
|
|
397
|
+
element: span,
|
|
398
|
+
run: segment.run,
|
|
399
|
+
schema,
|
|
400
|
+
font
|
|
401
|
+
});
|
|
401
402
|
textBlock.appendChild(span);
|
|
402
403
|
});
|
|
403
404
|
if (lineIndex < lineSegments.length - 1) textBlock.appendChild(document.createElement("br"));
|
|
404
405
|
});
|
|
405
406
|
};
|
|
406
|
-
var
|
|
407
|
-
const { lines, rawText, variables, start, end } = arg;
|
|
408
|
-
return consumeMeasuredLineSegments(lines, buildResolvedPlainChars(rawText, variables)).slice(start, end);
|
|
407
|
+
var getSplitLineSegments = (arg) => {
|
|
408
|
+
const { lines, runs, rawText, variables, start, end } = arg;
|
|
409
|
+
return consumeMeasuredLineSegments(lines, runs ? buildResolvedInlineMarkdownChars(runs, variables) : buildResolvedPlainChars(rawText, variables), { dropUnmappedTargets: Boolean(runs) }).slice(start, end);
|
|
409
410
|
};
|
|
410
411
|
var buildResolvedPlainChars = (rawText, variables) => {
|
|
411
412
|
const chars = [];
|
|
@@ -423,10 +424,32 @@ var buildResolvedPlainChars = (rawText, variables) => {
|
|
|
423
424
|
appendTextChars(chars, rawText.slice(lastIndex));
|
|
424
425
|
return chars;
|
|
425
426
|
};
|
|
426
|
-
var
|
|
427
|
-
|
|
427
|
+
var buildResolvedInlineMarkdownChars = (runs, variables) => {
|
|
428
|
+
const chars = [];
|
|
429
|
+
runs.forEach((run) => {
|
|
430
|
+
let lastIndex = 0;
|
|
431
|
+
visitVariables(run.text, ({ name, startIndex, endIndex }) => {
|
|
432
|
+
appendTextChars(chars, run.text.slice(lastIndex, startIndex), run);
|
|
433
|
+
const value = variables[name] ?? "";
|
|
434
|
+
for (let i = 0; i < value.length; i += 1) chars.push({
|
|
435
|
+
char: value[i],
|
|
436
|
+
variableName: name,
|
|
437
|
+
variableOffset: i,
|
|
438
|
+
run
|
|
439
|
+
});
|
|
440
|
+
lastIndex = endIndex + 1;
|
|
441
|
+
});
|
|
442
|
+
appendTextChars(chars, run.text.slice(lastIndex), run);
|
|
443
|
+
});
|
|
444
|
+
return chars;
|
|
445
|
+
};
|
|
446
|
+
var appendTextChars = (chars, text, run) => {
|
|
447
|
+
for (let i = 0; i < text.length; i += 1) chars.push({
|
|
448
|
+
char: text[i],
|
|
449
|
+
run
|
|
450
|
+
});
|
|
428
451
|
};
|
|
429
|
-
var consumeMeasuredLineSegments = (lines, resolvedChars) => {
|
|
452
|
+
var consumeMeasuredLineSegments = (lines, resolvedChars, options = {}) => {
|
|
430
453
|
const lineSegments = [];
|
|
431
454
|
let cursor = 0;
|
|
432
455
|
lines.forEach((line) => {
|
|
@@ -436,6 +459,7 @@ var consumeMeasuredLineSegments = (lines, resolvedChars) => {
|
|
|
436
459
|
const target = lineText[i];
|
|
437
460
|
while (cursor < resolvedChars.length && resolvedChars[cursor].char !== target && isWhitespaceChar(resolvedChars[cursor].char) && !isWhitespaceChar(target)) cursor += 1;
|
|
438
461
|
if (cursor >= resolvedChars.length) {
|
|
462
|
+
if (options.dropUnmappedTargets) continue;
|
|
439
463
|
appendSegment(segments, { char: target });
|
|
440
464
|
continue;
|
|
441
465
|
}
|
|
@@ -443,7 +467,10 @@ var consumeMeasuredLineSegments = (lines, resolvedChars) => {
|
|
|
443
467
|
if (sourceChar.char === target) {
|
|
444
468
|
appendSegment(segments, sourceChar);
|
|
445
469
|
cursor += 1;
|
|
446
|
-
} else
|
|
470
|
+
} else {
|
|
471
|
+
if (options.dropUnmappedTargets) continue;
|
|
472
|
+
appendSegment(segments, { char: target });
|
|
473
|
+
}
|
|
447
474
|
}
|
|
448
475
|
cursor = absorbHiddenTrailingWhitespace(segments, resolvedChars, cursor);
|
|
449
476
|
if (line.endsWith("\r\n") || line.endsWith("\n") || line.endsWith("\r")) {
|
|
@@ -459,7 +486,7 @@ var absorbHiddenTrailingWhitespace = (segments, resolvedChars, cursor) => {
|
|
|
459
486
|
while (nextCursor < resolvedChars.length && isHorizontalWhitespaceChar(resolvedChars[nextCursor].char)) {
|
|
460
487
|
const sourceChar = resolvedChars[nextCursor];
|
|
461
488
|
const lastSegment = segments.at(-1);
|
|
462
|
-
if (lastSegment && lastSegment.variableName === sourceChar.variableName && lastSegment.variableEnd === sourceChar.variableOffset && sourceChar.variableOffset !== void 0) lastSegment.variableEnd = sourceChar.variableOffset + 1;
|
|
489
|
+
if (lastSegment && lastSegment.variableName === sourceChar.variableName && lastSegment.variableEnd === sourceChar.variableOffset && lastSegment.run === sourceChar.run && sourceChar.variableOffset !== void 0) lastSegment.variableEnd = sourceChar.variableOffset + 1;
|
|
463
490
|
nextCursor += 1;
|
|
464
491
|
}
|
|
465
492
|
return nextCursor;
|
|
@@ -477,7 +504,7 @@ var isWhitespaceChar = (value) => value === " " || value === " " || value === "\
|
|
|
477
504
|
var isHorizontalWhitespaceChar = (value) => value === " " || value === " " || value === "\f" || value === "\v";
|
|
478
505
|
var appendSegment = (segments, sourceChar) => {
|
|
479
506
|
const lastSegment = segments.at(-1);
|
|
480
|
-
if (lastSegment && lastSegment.variableName === sourceChar.variableName && lastSegment.variableEnd === sourceChar.variableOffset) {
|
|
507
|
+
if (lastSegment && lastSegment.variableName === sourceChar.variableName && lastSegment.variableEnd === sourceChar.variableOffset && lastSegment.run === sourceChar.run) {
|
|
481
508
|
lastSegment.text += sourceChar.char;
|
|
482
509
|
if (sourceChar.variableOffset !== void 0) lastSegment.variableEnd = sourceChar.variableOffset + 1;
|
|
483
510
|
return;
|
|
@@ -486,14 +513,21 @@ var appendSegment = (segments, sourceChar) => {
|
|
|
486
513
|
text: sourceChar.char,
|
|
487
514
|
variableName: sourceChar.variableName,
|
|
488
515
|
variableStart: sourceChar.variableOffset,
|
|
489
|
-
variableEnd: sourceChar.variableOffset === void 0 ? void 0 : sourceChar.variableOffset + 1
|
|
516
|
+
variableEnd: sourceChar.variableOffset === void 0 ? void 0 : sourceChar.variableOffset + 1,
|
|
517
|
+
run: sourceChar.run
|
|
490
518
|
});
|
|
491
519
|
};
|
|
492
520
|
var appendRangedVariableSpan = (arg) => {
|
|
493
|
-
const { textBlock, segment, variables, theme, onChange, stopEditing } = arg;
|
|
521
|
+
const { textBlock, segment, variables, schema, font, theme, onChange, stopEditing } = arg;
|
|
494
522
|
if (!segment.variableName) return;
|
|
495
523
|
const span = document.createElement("span");
|
|
496
524
|
span.style.outline = `${theme.colorPrimary} dashed 1px`;
|
|
525
|
+
if (segment.run) applyInlineMarkdownStyle({
|
|
526
|
+
element: span,
|
|
527
|
+
run: segment.run,
|
|
528
|
+
schema,
|
|
529
|
+
font
|
|
530
|
+
});
|
|
497
531
|
makeElementPlainTextContentEditable(span);
|
|
498
532
|
span.textContent = segment.text;
|
|
499
533
|
span.addEventListener("blur", (e) => {
|
|
@@ -524,6 +558,7 @@ var applyInlineMarkdownStyle = (arg) => {
|
|
|
524
558
|
}
|
|
525
559
|
if (resolvedFont.syntheticItalic) element.style.fontStyle = "italic";
|
|
526
560
|
const textDecorations = [];
|
|
561
|
+
if (run.href) textDecorations.push("underline");
|
|
527
562
|
if (run.strikethrough) textDecorations.push("line-through");
|
|
528
563
|
if (textDecorations.length > 0) element.style.textDecoration = textDecorations.join(" ");
|
|
529
564
|
if (run.code) {
|
|
@@ -533,10 +568,21 @@ var applyInlineMarkdownStyle = (arg) => {
|
|
|
533
568
|
if (!schema.fontVariants?.code || !font[schema.fontVariants.code]) element.style.fontFamily = resolvedFont.fontName ? `'${resolvedFont.fontName}', monospace` : "monospace";
|
|
534
569
|
}
|
|
535
570
|
};
|
|
571
|
+
var createStaticInlineMarkdownElement = (run) => {
|
|
572
|
+
const href = run.href ? normalizeLinkHref(run.href) : void 0;
|
|
573
|
+
if (!href) return document.createElement("span");
|
|
574
|
+
const anchor = document.createElement("a");
|
|
575
|
+
anchor.href = href;
|
|
576
|
+
if (!getInternalLinkTarget(href)) {
|
|
577
|
+
anchor.target = "_blank";
|
|
578
|
+
anchor.rel = "noopener noreferrer";
|
|
579
|
+
}
|
|
580
|
+
return anchor;
|
|
581
|
+
};
|
|
536
582
|
var appendTextSpan = (arg) => {
|
|
537
583
|
const { textBlock, text, run, schema, font } = arg;
|
|
538
584
|
if (!text) return;
|
|
539
|
-
const span =
|
|
585
|
+
const span = createStaticInlineMarkdownElement(run);
|
|
540
586
|
span.textContent = text;
|
|
541
587
|
applyInlineMarkdownStyle({
|
|
542
588
|
element: span,
|