@pdfme/ui 6.2.0 → 6.2.1-dev.13

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
@@ -45448,7 +45448,7 @@ function parseExpressionAt(input, pos, options) {
45448
45448
  }
45449
45449
  //#endregion
45450
45450
  //#region ../common/dist/index.js
45451
- var PDFME_VERSION = "6.2.0";
45451
+ var PDFME_VERSION = "6.2.1";
45452
45452
  var PAGE_SIZE_PRESETS = {
45453
45453
  A3: {
45454
45454
  width: 297,
@@ -86113,7 +86113,7 @@ var getDynamicLayoutForTable = async (value, args) => {
86113
86113
  };
86114
86114
  };
86115
86115
  //#endregion
86116
- //#region ../schemas/dist/utils-CPYF2FY_.js
86116
+ //#region ../schemas/dist/utils-BhkbT1F9.js
86117
86117
  var convertForPdfLayoutProps = ({ schema, pageHeight, applyRotateTranslate = true }) => {
86118
86118
  const { width: mmWidth, height: mmHeight, position, rotate, opacity } = schema;
86119
86119
  const { x: mmX, y: mmY } = position;
@@ -86153,7 +86153,26 @@ var rotatePoint = (point, pivot, angleDegrees) => {
86153
86153
  };
86154
86154
  };
86155
86155
  var isEditable = (mode, schema) => mode === "designer" || mode === "form" && schema.readOnly !== true;
86156
+ var splitHexAlpha = (hexColor) => {
86157
+ if (!hexColor.startsWith("#")) return {
86158
+ color: hexColor,
86159
+ alpha: 1
86160
+ };
86161
+ const hex = hexColor.slice(1);
86162
+ if (!/^(?:[0-9a-f]{4}|[0-9a-f]{8})$/i.test(hex)) return {
86163
+ color: hexColor,
86164
+ alpha: 1
86165
+ };
86166
+ const rgbLength = hex.length === 4 ? 3 : 6;
86167
+ const alphaHex = hex.slice(rgbLength);
86168
+ return {
86169
+ color: `#${hex.slice(0, rgbLength)}`,
86170
+ alpha: parseInt(alphaHex.length === 1 ? alphaHex.repeat(2) : alphaHex, 16) / 255
86171
+ };
86172
+ };
86173
+ var applyAlphaToOpacity = (opacity, alpha) => alpha === 1 ? opacity : (opacity ?? 1) * alpha;
86156
86174
  var hex2rgb = (hex) => {
86175
+ hex = splitHexAlpha(hex).color;
86157
86176
  if (hex.slice(0, 1) === "#") hex = hex.slice(1);
86158
86177
  if (hex.length === 3) hex = hex.slice(0, 1) + hex.slice(0, 1) + hex.slice(1, 2) + hex.slice(1, 2) + hex.slice(2, 3) + hex.slice(2, 3);
86159
86178
  return [
@@ -86162,11 +86181,6 @@ var hex2rgb = (hex) => {
86162
86181
  hex.slice(4, 6)
86163
86182
  ].map((str) => parseInt(str, 16));
86164
86183
  };
86165
- var getHexOpacity = (hex) => {
86166
- const normalized = hex.startsWith("#") ? hex.slice(1) : hex;
86167
- const opacityHex = normalized.length === 4 ? normalized.slice(3, 4).repeat(2) : normalized.length === 8 ? normalized.slice(6, 8) : "";
86168
- return opacityHex ? parseInt(opacityHex, 16) / 255 : 1;
86169
- };
86170
86184
  var rgbColorToCmykColor = ({ red, green, blue }) => {
86171
86185
  const key = 1 - Math.max(red, green, blue);
86172
86186
  return cmyk(key === 1 ? 0 : (1 - red - key) / (1 - key), key === 1 ? 0 : (1 - green - key) / (1 - key), key === 1 ? 0 : (1 - blue - key) / (1 - key), key);
@@ -86181,11 +86195,7 @@ var hex2RgbColor = (hexString) => {
86181
86195
  var hex2CmykColor = (hexString) => {
86182
86196
  if (hexString) {
86183
86197
  if (!isHexValid(hexString)) throw new Error(`Invalid hex color value ${hexString}`);
86184
- let [r, g, b] = hex2rgb(hexString).map((value) => value / 255);
86185
- const opacity = getHexOpacity(hexString);
86186
- r = r * opacity + (1 - opacity);
86187
- g = g * opacity + (1 - opacity);
86188
- b = b * opacity + (1 - opacity);
86198
+ const [r, g, b] = hex2rgb(hexString).map((value) => value / 255);
86189
86199
  return rgbColorToCmykColor(rgb(r, g, b));
86190
86200
  }
86191
86201
  };
@@ -86406,7 +86416,7 @@ var Underline = [["path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }], ["line", {
86406
86416
  y2: "20"
86407
86417
  }]];
86408
86418
  //#endregion
86409
- //#region ../schemas/dist/builtins-C-2wyB_3.js
86419
+ //#region ../schemas/dist/builtins-BEweDprE.js
86410
86420
  var addUriLinkAnnotation = (arg) => {
86411
86421
  const { pdfDoc, page, uri, rect, borderWidth = 0 } = arg;
86412
86422
  const safeUri = normalizeSafeLinkUri(uri);
@@ -86514,7 +86524,7 @@ var getLinkAnnotationRect = (arg) => {
86514
86524
  });
86515
86525
  };
86516
86526
  var drawRun = (arg) => {
86517
- const { page, pdfLib, run, pdfFont, x, y, rotate, pivotPoint, fontSize, lineHeight, color, opacity, colorType, characterSpacing, strikethrough, underline } = arg;
86527
+ const { page, pdfLib, run, pdfFont, x, y, rotate, pivotPoint, fontSize, lineHeight, color, opacity, textOpacity, colorType, characterSpacing, strikethrough, underline } = arg;
86518
86528
  const runWidth = getRunWidth(run, fontSize, characterSpacing);
86519
86529
  const codePadding = run.code ? CODE_HORIZONTAL_PADDING : 0;
86520
86530
  const textX = x + codePadding;
@@ -86549,7 +86559,7 @@ var drawRun = (arg) => {
86549
86559
  pivotPoint,
86550
86560
  fontSize,
86551
86561
  color,
86552
- opacity
86562
+ opacity: textOpacity
86553
86563
  });
86554
86564
  if (underline && runWidth > 0) drawDecorationLine({
86555
86565
  page,
@@ -86560,7 +86570,7 @@ var drawRun = (arg) => {
86560
86570
  pivotPoint,
86561
86571
  fontSize,
86562
86572
  color,
86563
- opacity
86573
+ opacity: textOpacity
86564
86574
  });
86565
86575
  const drawAt = (drawX) => {
86566
86576
  const point = rotate.angle === 0 ? {
@@ -86578,7 +86588,7 @@ var drawRun = (arg) => {
86578
86588
  color,
86579
86589
  lineHeight: lineHeight * fontSize,
86580
86590
  font: pdfFont,
86581
- opacity,
86591
+ opacity: textOpacity,
86582
86592
  ...run.syntheticItalic ? { ySkew: pdfLib.degrees(12) } : {}
86583
86593
  });
86584
86594
  };
@@ -86589,7 +86599,8 @@ var drawRun = (arg) => {
86589
86599
  }
86590
86600
  };
86591
86601
  var renderInlineMarkdownText = async (arg) => {
86592
- const { value, schema, font, embedPdfFont, fontKitFont, pdfDoc, page, pdfLib, _cache, colorType, fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing, x, y, width, height, pivotPoint, rotate, opacity } = arg;
86602
+ const { value, schema, font, embedPdfFont, fontKitFont, pdfDoc, page, pdfLib, _cache, colorType, fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing, x, y, width, height, pivotPoint, rotate, opacity, colorAlpha } = arg;
86603
+ const textOpacity = applyAlphaToOpacity(opacity, colorAlpha);
86593
86604
  const lines = applyTextLineRange(layoutRichTextLines({
86594
86605
  runs: await resolveRichTextRuns({
86595
86606
  runs: parseInlineMarkdown(value),
@@ -86635,7 +86646,7 @@ var renderInlineMarkdownText = async (arg) => {
86635
86646
  pivotPoint,
86636
86647
  fontSize,
86637
86648
  color,
86638
- opacity
86649
+ opacity: textOpacity
86639
86650
  });
86640
86651
  if (schema.underline) drawDecorationLine({
86641
86652
  page,
@@ -86646,7 +86657,7 @@ var renderInlineMarkdownText = async (arg) => {
86646
86657
  pivotPoint,
86647
86658
  fontSize,
86648
86659
  color,
86649
- opacity
86660
+ opacity: textOpacity
86650
86661
  });
86651
86662
  }
86652
86663
  line.runs.reduce((currentX, run, runIndex) => {
@@ -86665,6 +86676,7 @@ var renderInlineMarkdownText = async (arg) => {
86665
86676
  lineHeight,
86666
86677
  color,
86667
86678
  opacity,
86679
+ textOpacity,
86668
86680
  colorType,
86669
86681
  characterSpacing: spacing,
86670
86682
  strikethrough: Boolean(run.strikethrough),
@@ -86717,13 +86729,14 @@ var embedAndGetFont = (arg) => {
86717
86729
  const pdfFontCache = getPdfFontCache(_cache);
86718
86730
  const cachedFont = pdfFontCache[fontName];
86719
86731
  if (cachedFont) return cachedFont;
86720
- const fontValue = font[fontName];
86721
- if (!fontValue) return Promise.reject(/* @__PURE__ */ new Error(`[@pdfme/schemas] Font "${fontName}" is not found.`));
86722
86732
  const pdfFontPromise = (async () => {
86733
+ const fontValue = font[fontName];
86734
+ if (!fontValue) throw new Error(`[@pdfme/schemas] Font "${fontName}" is not found.`);
86723
86735
  let fontData = fontValue.data;
86724
86736
  if (typeof fontData === "string" && fontData.startsWith("http")) fontData = await fetchRemoteFontData(fontData);
86725
86737
  return pdfDoc.embedFont(fontData, { subset: typeof fontValue.subset === "undefined" ? true : fontValue.subset });
86726
86738
  })();
86739
+ pdfFontPromise.catch(() => {});
86727
86740
  pdfFontCache[fontName] = pdfFontPromise;
86728
86741
  return pdfFontPromise;
86729
86742
  };
@@ -86733,14 +86746,16 @@ var getFontProp = ({ value, fontKitFont, schema, basePdf, colorType, fontSize: r
86733
86746
  fontKitFont,
86734
86747
  value
86735
86748
  }) : schema.fontSize ?? 13);
86736
- const color = hex2PrintingColor(schema.fontColor || "#000000", colorType);
86749
+ const { color: fontColorHex, alpha: colorAlpha } = splitHexAlpha(schema.fontColor || "#000000");
86750
+ const color = hex2PrintingColor(fontColorHex, colorType);
86737
86751
  return {
86738
86752
  alignment: schema.alignment ?? "left",
86739
86753
  verticalAlignment: schema.verticalAlignment ?? "top",
86740
86754
  lineHeight: schema.lineHeight ?? 1,
86741
86755
  characterSpacing: schema.characterSpacing ?? 0,
86742
86756
  fontSize,
86743
- color
86757
+ color,
86758
+ colorAlpha
86744
86759
  };
86745
86760
  };
86746
86761
  var pdfRender = async (arg) => {
@@ -86782,7 +86797,7 @@ var pdfRender = async (arg) => {
86782
86797
  _cache
86783
86798
  });
86784
86799
  const fontKitFont = await getFontKitFont(schema.fontName, font, _cache);
86785
- const { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing } = getFontProp({
86800
+ const { fontSize, color, colorAlpha, alignment, verticalAlignment, lineHeight, characterSpacing } = getFontProp({
86786
86801
  value: enableInlineMarkdown ? stripInlineMarkdown(value) : value,
86787
86802
  fontKitFont,
86788
86803
  schema,
@@ -86795,6 +86810,7 @@ var pdfRender = async (arg) => {
86795
86810
  _cache
86796
86811
  }) : void 0
86797
86812
  });
86813
+ const textOpacity = applyAlphaToOpacity(opacity, colorAlpha);
86798
86814
  if (enableInlineMarkdown) {
86799
86815
  await renderInlineMarkdownText({
86800
86816
  value,
@@ -86824,7 +86840,8 @@ var pdfRender = async (arg) => {
86824
86840
  height: contentHeight,
86825
86841
  pivotPoint,
86826
86842
  rotate,
86827
- opacity
86843
+ opacity,
86844
+ colorAlpha
86828
86845
  });
86829
86846
  return;
86830
86847
  }
@@ -86876,7 +86893,7 @@ var pdfRender = async (arg) => {
86876
86893
  }, pivotPoint, rotate.angle),
86877
86894
  thickness: 1 / 12 * fontSize,
86878
86895
  color,
86879
- opacity
86896
+ opacity: textOpacity
86880
86897
  });
86881
86898
  }
86882
86899
  if (schema.underline && textWidth > 0) {
@@ -86893,7 +86910,7 @@ var pdfRender = async (arg) => {
86893
86910
  }, pivotPoint, rotate.angle),
86894
86911
  thickness: 1 / 12 * fontSize,
86895
86912
  color,
86896
- opacity
86913
+ opacity: textOpacity
86897
86914
  });
86898
86915
  }
86899
86916
  if (rotate.angle !== 0) {
@@ -86913,7 +86930,7 @@ var pdfRender = async (arg) => {
86913
86930
  color,
86914
86931
  lineHeight: lineHeight * fontSize,
86915
86932
  font: pdfFontValue,
86916
- opacity
86933
+ opacity: textOpacity
86917
86934
  });
86918
86935
  });
86919
86936
  };
@@ -86937,21 +86954,24 @@ var drawTextBoxDecoration = (arg) => {
86937
86954
  height: rect.height,
86938
86955
  rotate,
86939
86956
  color: rect.color,
86940
- opacity
86957
+ opacity: opacity * rect.alpha
86941
86958
  });
86942
86959
  };
86943
86960
  if (schema.backgroundColor) {
86944
- const color = hex2PrintingColor(schema.backgroundColor, colorType);
86961
+ const { color: bgHex, alpha } = splitHexAlpha(schema.backgroundColor);
86962
+ const color = hex2PrintingColor(bgHex, colorType);
86945
86963
  if (color) drawRectangle({
86946
86964
  x,
86947
86965
  y,
86948
86966
  width,
86949
86967
  height,
86950
- color
86968
+ color,
86969
+ alpha
86951
86970
  });
86952
86971
  }
86953
86972
  if (!schema.borderColor || !hasBoxDimension(schema.borderWidth)) return;
86954
- const color = hex2PrintingColor(schema.borderColor, colorType);
86973
+ const { color: borderHex, alpha } = splitHexAlpha(schema.borderColor);
86974
+ const color = hex2PrintingColor(borderHex, colorType);
86955
86975
  if (!color) return;
86956
86976
  const top = mm2pt(borderWidth.top);
86957
86977
  const right = mm2pt(borderWidth.right);
@@ -86962,28 +86982,32 @@ var drawTextBoxDecoration = (arg) => {
86962
86982
  y: y + height - top,
86963
86983
  width,
86964
86984
  height: top,
86965
- color
86985
+ color,
86986
+ alpha
86966
86987
  });
86967
86988
  drawRectangle({
86968
86989
  x: x + width - right,
86969
86990
  y,
86970
86991
  width: right,
86971
86992
  height,
86972
- color
86993
+ color,
86994
+ alpha
86973
86995
  });
86974
86996
  drawRectangle({
86975
86997
  x,
86976
86998
  y,
86977
86999
  width,
86978
87000
  height: bottom,
86979
- color
87001
+ color,
87002
+ alpha
86980
87003
  });
86981
87004
  drawRectangle({
86982
87005
  x,
86983
87006
  y,
86984
87007
  width: left,
86985
87008
  height,
86986
- color
87009
+ color,
87010
+ alpha
86987
87011
  });
86988
87012
  };
86989
87013
  var TextStrikethroughIcon = createSvgStr(Strikethrough);