@pdfme/schemas 6.1.1-dev.12 → 6.1.1-dev.14

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 CHANGED
@@ -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
- renderSplitPlainVariableSpans({
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 renderSplitPlainVariableSpans = (arg) => {
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 = getSplitPlainLineSegments({
369
+ const lineSegments = getSplitLineSegments({
378
370
  lines,
371
+ runs,
379
372
  rawText,
380
373
  variables,
381
374
  start: lineRange?.start ?? 0,
@@ -389,6 +382,8 @@ 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
@@ -398,14 +393,20 @@ var renderSplitPlainVariableSpans = (arg) => {
398
393
  const span = 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 getSplitPlainLineSegments = (arg) => {
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 appendTextChars = (chars, text) => {
427
- for (let i = 0; i < text.length; i += 1) chars.push({ char: text[i] });
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 appendSegment(segments, { char: target });
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) => {