@pdfme/ui 6.1.1-dev.4 → 6.1.1
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 +29 -83
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -98478,7 +98478,7 @@ $d636bc798e7178db$export$36b2f24e97d43be($21ee218f84ac7f32$export$2e2bcd8739ae03
|
|
|
98478
98478
|
$d636bc798e7178db$export$36b2f24e97d43be($cd5853a56c68fec7$export$2e2bcd8739ae039);
|
|
98479
98479
|
$d636bc798e7178db$export$36b2f24e97d43be($05f49f930186144e$export$2e2bcd8739ae039);
|
|
98480
98480
|
//#endregion
|
|
98481
|
-
//#region ../schemas/dist/helper-
|
|
98481
|
+
//#region ../schemas/dist/helper-M_MmV_d5.js
|
|
98482
98482
|
var ALIGN_LEFT = "left";
|
|
98483
98483
|
var ALIGN_CENTER = "center";
|
|
98484
98484
|
var ALIGN_RIGHT = "right";
|
|
@@ -98598,27 +98598,10 @@ var heightOfFontAtSize = (fontKitFont, fontSize) => {
|
|
|
98598
98598
|
var calculateCharacterSpacing = (textContent, textCharacterSpacing) => {
|
|
98599
98599
|
return (textContent.length - 1) * textCharacterSpacing;
|
|
98600
98600
|
};
|
|
98601
|
-
var TEXT_WIDTH_CACHE_LIMIT = 5e3;
|
|
98602
|
-
var textWidthCache = /* @__PURE__ */ new WeakMap();
|
|
98603
|
-
var getTextWidthCache = (fontKitFont) => {
|
|
98604
|
-
let cache = textWidthCache.get(fontKitFont);
|
|
98605
|
-
if (!cache) {
|
|
98606
|
-
cache = /* @__PURE__ */ new Map();
|
|
98607
|
-
textWidthCache.set(fontKitFont, cache);
|
|
98608
|
-
}
|
|
98609
|
-
return cache;
|
|
98610
|
-
};
|
|
98611
98601
|
var widthOfTextAtSize = (text, fontKitFont, fontSize, characterSpacing) => {
|
|
98612
|
-
const cache = getTextWidthCache(fontKitFont);
|
|
98613
|
-
const cacheKey = `${fontSize}\0${characterSpacing}\0${text}`;
|
|
98614
|
-
const cachedWidth = cache.get(cacheKey);
|
|
98615
|
-
if (cachedWidth !== void 0) return cachedWidth;
|
|
98616
98602
|
const { glyphs } = fontKitFont.layout(text);
|
|
98617
98603
|
const scale = 1e3 / fontKitFont.unitsPerEm;
|
|
98618
|
-
|
|
98619
|
-
if (cache.size >= TEXT_WIDTH_CACHE_LIMIT) cache.clear();
|
|
98620
|
-
cache.set(cacheKey, width);
|
|
98621
|
-
return width;
|
|
98604
|
+
return glyphs.reduce((totalWidth, glyph) => totalWidth + glyph.advanceWidth * scale, 0) * (fontSize / 1e3) + calculateCharacterSpacing(text, characterSpacing);
|
|
98622
98605
|
};
|
|
98623
98606
|
var getFallbackFont = (font) => {
|
|
98624
98607
|
return font[getFallbackFontName(font)];
|
|
@@ -98738,15 +98721,10 @@ var splitTextToSize = (arg) => {
|
|
|
98738
98721
|
return lines;
|
|
98739
98722
|
};
|
|
98740
98723
|
var isFirefox = () => navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
|
|
98741
|
-
var wordSegmenter;
|
|
98742
|
-
var getWordSegmenter = () => {
|
|
98743
|
-
wordSegmenter ?? (wordSegmenter = new Intl.Segmenter(void 0, { granularity: "word" }));
|
|
98744
|
-
return wordSegmenter;
|
|
98745
|
-
};
|
|
98746
98724
|
var getSplittedLinesBySegmenter = (line, calcValues) => {
|
|
98747
98725
|
if (line.trim() === "") return [""];
|
|
98748
98726
|
const { font, fontSize, characterSpacing, boxWidthInPt } = calcValues;
|
|
98749
|
-
const iterator =
|
|
98727
|
+
const iterator = new Intl.Segmenter(void 0, { granularity: "word" }).segment(line.trimEnd())[Symbol.iterator]();
|
|
98750
98728
|
let lines = [];
|
|
98751
98729
|
let lineCounter = 0;
|
|
98752
98730
|
let currentTextSize = 0;
|
|
@@ -98849,7 +98827,7 @@ var filterEndJP = (lines) => {
|
|
|
98849
98827
|
} else return filtered;
|
|
98850
98828
|
};
|
|
98851
98829
|
//#endregion
|
|
98852
|
-
//#region ../schemas/dist/dynamicTemplate-
|
|
98830
|
+
//#region ../schemas/dist/dynamicTemplate-DmuRoTw4.js
|
|
98853
98831
|
function _typeof$18(o) {
|
|
98854
98832
|
"@babel/helpers - typeof";
|
|
98855
98833
|
return _typeof$18 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -99699,7 +99677,7 @@ var Underline = [["path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }], ["line", {
|
|
|
99699
99677
|
y2: "20"
|
|
99700
99678
|
}]];
|
|
99701
99679
|
//#endregion
|
|
99702
|
-
//#region ../schemas/dist/builtins-
|
|
99680
|
+
//#region ../schemas/dist/builtins-CWHhKSVA.js
|
|
99703
99681
|
var MARKDOWN_ESCAPABLE_CHARS = new Set([
|
|
99704
99682
|
"\\",
|
|
99705
99683
|
"*",
|
|
@@ -100117,16 +100095,11 @@ var calculateDynamicRichTextFontSize = async (arg) => {
|
|
|
100117
100095
|
var getSyntheticBoldWidth = (run, fontSize) => run.syntheticBold ? fontSize * SYNTHETIC_BOLD_OFFSET_RATIO * 2 : 0;
|
|
100118
100096
|
var getSyntheticItalicWidth = (run, fontSize) => run.syntheticItalic ? heightOfFontAtSize(run.fontKitFont, fontSize) * Math.tan(12 * Math.PI / 180) : 0;
|
|
100119
100097
|
var getRunWidth = (run, fontSize, characterSpacing) => widthOfTextAtSize(run.text, run.fontKitFont, fontSize, characterSpacing) + getSyntheticBoldWidth(run, fontSize) + getSyntheticItalicWidth(run, fontSize);
|
|
100120
|
-
var
|
|
100098
|
+
var getPdfFont = (run, pdfFontObj) => {
|
|
100121
100099
|
const pdfFont = pdfFontObj[run.fontName];
|
|
100122
100100
|
if (!pdfFont) throw new Error(`[@pdfme/schemas] Missing embedded font "${run.fontName}".`);
|
|
100123
100101
|
return pdfFont;
|
|
100124
100102
|
};
|
|
100125
|
-
var embedFontsForRuns = async (runs, embedPdfFont) => {
|
|
100126
|
-
const fontNames = Array.from(new Set(runs.map((run) => run.fontName)));
|
|
100127
|
-
const pdfFonts = await Promise.all(fontNames.map(async (fontName) => [fontName, await embedPdfFont(fontName)]));
|
|
100128
|
-
return Object.fromEntries(pdfFonts);
|
|
100129
|
-
};
|
|
100130
100103
|
var drawDecorationLine = (arg) => {
|
|
100131
100104
|
const { page, x, y, width, rotate, pivotPoint, fontSize, color, opacity } = arg;
|
|
100132
100105
|
if (width <= 0) return;
|
|
@@ -100207,7 +100180,7 @@ var drawRun = (arg) => {
|
|
|
100207
100180
|
}
|
|
100208
100181
|
};
|
|
100209
100182
|
var renderInlineMarkdownText = async (arg) => {
|
|
100210
|
-
const { value, schema, font,
|
|
100183
|
+
const { value, schema, font, pdfFontObj, fontKitFont, page, pdfLib, _cache, colorType, fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing, x, width, height, pageHeight, pivotPoint, rotate, opacity } = arg;
|
|
100211
100184
|
const lines = layoutRichTextLines({
|
|
100212
100185
|
runs: await resolveRichTextRuns({
|
|
100213
100186
|
runs: parseInlineMarkdown(value),
|
|
@@ -100219,7 +100192,6 @@ var renderInlineMarkdownText = async (arg) => {
|
|
|
100219
100192
|
characterSpacing,
|
|
100220
100193
|
boxWidthInPt: width
|
|
100221
100194
|
});
|
|
100222
|
-
const pdfFontObj = await embedFontsForRuns(lines.flatMap((line) => line.runs), embedPdfFont);
|
|
100223
100195
|
const firstLineTextHeight = heightOfFontAtSize(fontKitFont, fontSize);
|
|
100224
100196
|
const descent = getFontDescentInPt(fontKitFont, fontSize);
|
|
100225
100197
|
const halfLineHeightAdjustment = lineHeight === 0 ? 0 : (lineHeight - 1) * fontSize / 2;
|
|
@@ -100277,7 +100249,7 @@ var renderInlineMarkdownText = async (arg) => {
|
|
|
100277
100249
|
page,
|
|
100278
100250
|
pdfLib,
|
|
100279
100251
|
run,
|
|
100280
|
-
pdfFont:
|
|
100252
|
+
pdfFont: getPdfFont(run, pdfFontObj),
|
|
100281
100253
|
x: currentX,
|
|
100282
100254
|
y: yLine,
|
|
100283
100255
|
rotate,
|
|
@@ -100294,29 +100266,17 @@ var renderInlineMarkdownText = async (arg) => {
|
|
|
100294
100266
|
}, xLine);
|
|
100295
100267
|
});
|
|
100296
100268
|
};
|
|
100297
|
-
var
|
|
100298
|
-
|
|
100299
|
-
|
|
100300
|
-
|
|
100301
|
-
|
|
100302
|
-
_cache.set(PDF_FONT_CACHE_KEY, pdfFontCache);
|
|
100303
|
-
}
|
|
100304
|
-
return pdfFontCache;
|
|
100305
|
-
};
|
|
100306
|
-
var embedAndGetFont = (arg) => {
|
|
100307
|
-
const { pdfDoc, font, fontName, _cache } = arg;
|
|
100308
|
-
const pdfFontCache = getPdfFontCache(_cache);
|
|
100309
|
-
const cachedFont = pdfFontCache[fontName];
|
|
100310
|
-
if (cachedFont) return cachedFont;
|
|
100311
|
-
const fontValue = font[fontName];
|
|
100312
|
-
if (!fontValue) return Promise.reject(/* @__PURE__ */ new Error(`[@pdfme/schemas] Font "${fontName}" is not found.`));
|
|
100313
|
-
const pdfFontPromise = (async () => {
|
|
100314
|
-
let fontData = fontValue.data;
|
|
100269
|
+
var embedAndGetFontObj = async (arg) => {
|
|
100270
|
+
const { pdfDoc, font, _cache } = arg;
|
|
100271
|
+
if (_cache.has(pdfDoc)) return _cache.get(pdfDoc);
|
|
100272
|
+
const fontValues = await Promise.all(Object.values(font).map(async (v) => {
|
|
100273
|
+
let fontData = v.data;
|
|
100315
100274
|
if (typeof fontData === "string" && fontData.startsWith("http")) fontData = await fetchRemoteFontData(fontData);
|
|
100316
|
-
return pdfDoc.embedFont(fontData, { subset: typeof
|
|
100317
|
-
})
|
|
100318
|
-
|
|
100319
|
-
|
|
100275
|
+
return pdfDoc.embedFont(fontData, { subset: typeof v.subset === "undefined" ? true : v.subset });
|
|
100276
|
+
}));
|
|
100277
|
+
const fontObj = Object.keys(font).reduce((acc, cur, i) => Object.assign(acc, { [cur]: fontValues[i] }), {});
|
|
100278
|
+
_cache.set(pdfDoc, fontObj);
|
|
100279
|
+
return fontObj;
|
|
100320
100280
|
};
|
|
100321
100281
|
var getFontProp = ({ value, fontKitFont, schema, colorType, fontSize: resolvedFontSize }) => {
|
|
100322
100282
|
const fontSize = resolvedFontSize ?? (schema.dynamicFontSize ? calculateDynamicFontSize({
|
|
@@ -100334,24 +100294,16 @@ var getFontProp = ({ value, fontKitFont, schema, colorType, fontSize: resolvedFo
|
|
|
100334
100294
|
color
|
|
100335
100295
|
};
|
|
100336
100296
|
};
|
|
100337
|
-
var graphemeSegmenter;
|
|
100338
|
-
var getGraphemeSegmenter = () => {
|
|
100339
|
-
graphemeSegmenter ?? (graphemeSegmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" }));
|
|
100340
|
-
return graphemeSegmenter;
|
|
100341
|
-
};
|
|
100342
100297
|
var pdfRender = async (arg) => {
|
|
100343
100298
|
const { value, pdfDoc, pdfLib, page, options, schema, _cache } = arg;
|
|
100344
100299
|
if (!value) return;
|
|
100345
100300
|
const { font = getDefaultFont(), colorType } = options;
|
|
100346
|
-
const
|
|
100347
|
-
const enableInlineMarkdown = isInlineMarkdownTextSchema(schema);
|
|
100348
|
-
const pdfFontValuePromise = enableInlineMarkdown ? void 0 : embedAndGetFont({
|
|
100301
|
+
const [pdfFontObj, fontKitFont] = await Promise.all([embedAndGetFontObj({
|
|
100349
100302
|
pdfDoc,
|
|
100350
100303
|
font,
|
|
100351
|
-
fontName,
|
|
100352
100304
|
_cache
|
|
100353
|
-
});
|
|
100354
|
-
const
|
|
100305
|
+
}), getFontKitFont(schema.fontName, font, _cache)]);
|
|
100306
|
+
const enableInlineMarkdown = isInlineMarkdownTextSchema(schema);
|
|
100355
100307
|
const { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing } = getFontProp({
|
|
100356
100308
|
value: enableInlineMarkdown ? stripInlineMarkdown(value) : value,
|
|
100357
100309
|
fontKitFont,
|
|
@@ -100364,6 +100316,8 @@ var pdfRender = async (arg) => {
|
|
|
100364
100316
|
_cache
|
|
100365
100317
|
}) : void 0
|
|
100366
100318
|
});
|
|
100319
|
+
const fontName = schema.fontName ? schema.fontName : getFallbackFontName(font);
|
|
100320
|
+
const pdfFontValue = pdfFontObj && pdfFontObj[fontName];
|
|
100367
100321
|
const pageHeight = page.getHeight();
|
|
100368
100322
|
const { width, height, rotate, position: { x, y }, opacity } = convertForPdfLayoutProps({
|
|
100369
100323
|
schema,
|
|
@@ -100403,12 +100357,7 @@ var pdfRender = async (arg) => {
|
|
|
100403
100357
|
value,
|
|
100404
100358
|
schema,
|
|
100405
100359
|
font,
|
|
100406
|
-
|
|
100407
|
-
pdfDoc,
|
|
100408
|
-
font,
|
|
100409
|
-
fontName,
|
|
100410
|
-
_cache
|
|
100411
|
-
}),
|
|
100360
|
+
pdfFontObj,
|
|
100412
100361
|
fontKitFont,
|
|
100413
100362
|
page,
|
|
100414
100363
|
pdfLib,
|
|
@@ -100430,8 +100379,6 @@ var pdfRender = async (arg) => {
|
|
|
100430
100379
|
});
|
|
100431
100380
|
return;
|
|
100432
100381
|
}
|
|
100433
|
-
if (!pdfFontValuePromise) throw new Error("[@pdfme/schemas] Failed to prepare PDF font for text rendering.");
|
|
100434
|
-
const pdfFontValue = await pdfFontValuePromise;
|
|
100435
100382
|
const firstLineTextHeight = heightOfFontAtSize(fontKitFont, fontSize);
|
|
100436
100383
|
const descent = getFontDescentInPt(fontKitFont, fontSize);
|
|
100437
100384
|
const halfLineHeightAdjustment = lineHeight === 0 ? 0 : (lineHeight - 1) * fontSize / 2;
|
|
@@ -100442,8 +100389,6 @@ var pdfRender = async (arg) => {
|
|
|
100442
100389
|
fontKitFont,
|
|
100443
100390
|
boxWidthInPt: width
|
|
100444
100391
|
});
|
|
100445
|
-
const needsTextWidth = alignment !== "left" || Boolean(schema.strikethrough || schema.underline);
|
|
100446
|
-
const needsTextHeight = Boolean(schema.strikethrough || schema.underline);
|
|
100447
100392
|
let yOffset = 0;
|
|
100448
100393
|
if (verticalAlignment === "top") yOffset = firstLineTextHeight + halfLineHeightAdjustment;
|
|
100449
100394
|
else {
|
|
@@ -100451,10 +100396,11 @@ var pdfRender = async (arg) => {
|
|
|
100451
100396
|
if (verticalAlignment === "bottom") yOffset = height - otherLinesHeight + descent - halfLineHeightAdjustment;
|
|
100452
100397
|
else if (verticalAlignment === "middle") yOffset = (height - otherLinesHeight - firstLineTextHeight + descent) / 2 + firstLineTextHeight;
|
|
100453
100398
|
}
|
|
100399
|
+
const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
100454
100400
|
lines.forEach((line, rowIndex) => {
|
|
100455
100401
|
const trimmed = line.replace("\n", "");
|
|
100456
|
-
const textWidth =
|
|
100457
|
-
const textHeight =
|
|
100402
|
+
const textWidth = widthOfTextAtSize(trimmed, fontKitFont, fontSize, characterSpacing);
|
|
100403
|
+
const textHeight = heightOfFontAtSize(fontKitFont, fontSize);
|
|
100458
100404
|
const rowYOffset = lineHeight * fontSize * rowIndex;
|
|
100459
100405
|
if (line === "") line = "\r\n";
|
|
100460
100406
|
let xLine = x;
|
|
@@ -100505,7 +100451,7 @@ var pdfRender = async (arg) => {
|
|
|
100505
100451
|
}
|
|
100506
100452
|
let spacing = characterSpacing;
|
|
100507
100453
|
if (alignment === "justify" && line.slice(-1) !== "\n") {
|
|
100508
|
-
const iterator =
|
|
100454
|
+
const iterator = segmenter.segment(trimmed)[Symbol.iterator]();
|
|
100509
100455
|
const len = Array.from(iterator).length;
|
|
100510
100456
|
spacing += (width - textWidth) / len;
|
|
100511
100457
|
}
|
|
@@ -235094,7 +235040,7 @@ var Designer = class extends BaseUIClass {
|
|
|
235094
235040
|
}
|
|
235095
235041
|
};
|
|
235096
235042
|
//#endregion
|
|
235097
|
-
//#region ../schemas/dist/lists-
|
|
235043
|
+
//#region ../schemas/dist/lists-B6dmgpkS.js
|
|
235098
235044
|
var normalizeListItems = (value) => {
|
|
235099
235045
|
if (Array.isArray(value)) return value.map((item) => String(item));
|
|
235100
235046
|
if (typeof value !== "string") return value == null ? [] : [String(value)];
|