@pdfme/schemas 6.2.0 → 6.2.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/barcodes/helper.d.ts +5 -0
- package/dist/index.js +38 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -9,6 +9,11 @@ export declare const barCodeType2Bcid: (type: BarcodeTypes) => "code128" | "code
|
|
|
9
9
|
* Strip hash from the beginning of HTML hex color codes for the bwip.js lib
|
|
10
10
|
*/
|
|
11
11
|
export declare const mapHexColorForBwipJsLib: (color: string | undefined, fallback?: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Barcode colors historically accept bwip-js style hex without a leading '#';
|
|
14
|
+
* CSS and pdfme's color utils require the '#', so add it when missing.
|
|
15
|
+
*/
|
|
16
|
+
export declare const ensureHexColorHash: (color: string | undefined) => string | undefined;
|
|
12
17
|
export type BarcodeRenderRuntime = 'document-canvas' | 'offscreencanvas' | 'node-buffer';
|
|
13
18
|
/**
|
|
14
19
|
* Pick a barcode renderer from capabilities, not `typeof window`.
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { a as normalizeListItems, c as LIST_STYLE_BULLET, i as normalizeListItem
|
|
|
7
7
|
import { i as validateVariables, n as substituteVariables, r as substituteVariablesAsInlineMarkdownLiterals, t as resolveReadOnlyMultiVariableText } from "./helper-BR4_UZA5.js";
|
|
8
8
|
import "./tables.js";
|
|
9
9
|
import "./lists.js";
|
|
10
|
-
import { DEFAULT_FONT_NAME, ZOOM, b64toUint8Array, getDefaultFont, getFallbackFontName, getInternalLinkTarget, mm2pt, normalizeLinkHref, px2mm } from "@pdfme/common";
|
|
10
|
+
import { DEFAULT_FONT_NAME, ZOOM, b64toUint8Array, getDefaultFont, getFallbackFontName, getInternalLinkTarget, isHexValid, mm2pt, normalizeLinkHref, px2mm } from "@pdfme/common";
|
|
11
11
|
import { Buffer as Buffer$1 } from "buffer";
|
|
12
12
|
import { popGraphicsState, pushGraphicsState, rotateDegrees, translate } 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";
|
|
@@ -2458,6 +2458,11 @@ var barCodeType2Bcid = (type) => type === "nw7" ? "rationalizedCodabar" : type;
|
|
|
2458
2458
|
* Strip hash from the beginning of HTML hex color codes for the bwip.js lib
|
|
2459
2459
|
*/
|
|
2460
2460
|
var mapHexColorForBwipJsLib = (color, fallback) => color ? color.replace("#", "") : fallback ? fallback.replace("#", "") : "000000";
|
|
2461
|
+
/**
|
|
2462
|
+
* Barcode colors historically accept bwip-js style hex without a leading '#';
|
|
2463
|
+
* CSS and pdfme's color utils require the '#', so add it when missing.
|
|
2464
|
+
*/
|
|
2465
|
+
var ensureHexColorHash = (color) => color && !color.startsWith("#") && isHexValid(`#${color}`) ? `#${color}` : color;
|
|
2461
2466
|
var getBwipJsRenderer = () => bwipjs;
|
|
2462
2467
|
var getDocument = () => globalThis.document;
|
|
2463
2468
|
var getOffscreenCanvasCtor = () => globalThis.OffscreenCanvas;
|
|
@@ -2532,11 +2537,24 @@ var createBarCode = async (arg) => {
|
|
|
2532
2537
|
//#endregion
|
|
2533
2538
|
//#region src/barcodes/pdfRender.ts
|
|
2534
2539
|
var getBarcodeCacheKey = (schema, value) => {
|
|
2535
|
-
return `svg:${schema.type}:${schema.width}:${schema.height}:${schema.
|
|
2540
|
+
return `svg:${schema.type}:${schema.width}:${schema.height}:${schema.barColor}:${schema.textColor}:${schema.includetext}:${value}`;
|
|
2536
2541
|
};
|
|
2537
2542
|
var addSvgOpacity = (svg, opacity) => {
|
|
2538
2543
|
return opacity === void 0 ? svg : svg.replace(/<svg\b/, `<svg opacity="${opacity}"`);
|
|
2539
2544
|
};
|
|
2545
|
+
var splitHexAlpha = (hexColor) => {
|
|
2546
|
+
const hex = hexColor.slice(1);
|
|
2547
|
+
if (hex.length !== 4 && hex.length !== 8) return {
|
|
2548
|
+
color: hexColor,
|
|
2549
|
+
alpha: 1
|
|
2550
|
+
};
|
|
2551
|
+
const rgbLength = hex.length === 4 ? 3 : 6;
|
|
2552
|
+
const alphaHex = hex.slice(rgbLength);
|
|
2553
|
+
return {
|
|
2554
|
+
color: `#${hex.slice(0, rgbLength)}`,
|
|
2555
|
+
alpha: parseInt(alphaHex.length === 1 ? alphaHex.repeat(2) : alphaHex, 16) / 255
|
|
2556
|
+
};
|
|
2557
|
+
};
|
|
2540
2558
|
var getSvgColorMapper = (colorType = "") => {
|
|
2541
2559
|
return colorType.toLowerCase() === "cmyk" ? ({ parsed }) => ({
|
|
2542
2560
|
color: rgbColorToCmykColor(parsed.rgb),
|
|
@@ -2551,9 +2569,11 @@ var pdfRender$1 = async (arg) => {
|
|
|
2551
2569
|
if (!svg) {
|
|
2552
2570
|
svg = createBarCodeSvg({
|
|
2553
2571
|
...schema,
|
|
2572
|
+
backgroundColor: void 0,
|
|
2554
2573
|
type: schema.type,
|
|
2555
2574
|
input: value
|
|
2556
2575
|
});
|
|
2576
|
+
svg = svg.replace(/<svg\b/, "<svg preserveAspectRatio=\"none\"");
|
|
2557
2577
|
_cache.set(inputBarcodeCacheKey, svg);
|
|
2558
2578
|
}
|
|
2559
2579
|
const pageHeight = page.getHeight();
|
|
@@ -2569,6 +2589,19 @@ var pdfRender$1 = async (arg) => {
|
|
|
2569
2589
|
const rotate = schema.rotate ? -schema.rotate : 0;
|
|
2570
2590
|
if (rotate) page.pushOperators(pushGraphicsState(), translate(pivot.x, pivot.y), rotateDegrees(rotate), translate(-pivot.x, -pivot.y));
|
|
2571
2591
|
try {
|
|
2592
|
+
const backgroundHex = ensureHexColorHash(schema.backgroundColor);
|
|
2593
|
+
if (backgroundHex) {
|
|
2594
|
+
const { color: backgroundColorHex, alpha } = splitHexAlpha(backgroundHex);
|
|
2595
|
+
const backgroundColor = alpha > 0 ? hex2PrintingColor(backgroundColorHex, options.colorType) : void 0;
|
|
2596
|
+
if (backgroundColor) page.drawRectangle({
|
|
2597
|
+
x,
|
|
2598
|
+
y,
|
|
2599
|
+
width,
|
|
2600
|
+
height,
|
|
2601
|
+
color: backgroundColor,
|
|
2602
|
+
opacity: (opacity ?? 1) * alpha
|
|
2603
|
+
});
|
|
2604
|
+
}
|
|
2572
2605
|
await page.drawSvg(addSvgOpacity(svg, opacity), {
|
|
2573
2606
|
x,
|
|
2574
2607
|
y: y + height,
|
|
@@ -2800,6 +2833,7 @@ var blobToDataURL = (blob) => new Promise((resolve, reject) => {
|
|
|
2800
2833
|
var createBarcodeImage = async (schema, value) => {
|
|
2801
2834
|
const imageBuf = await createBarCode({
|
|
2802
2835
|
...schema,
|
|
2836
|
+
backgroundColor: void 0,
|
|
2803
2837
|
input: value
|
|
2804
2838
|
});
|
|
2805
2839
|
return await blobToDataURL(new Blob([new Uint8Array(imageBuf)], { type: "image/png" }));
|
|
@@ -2823,7 +2857,8 @@ var uiRender$1 = async (arg) => {
|
|
|
2823
2857
|
display: "flex",
|
|
2824
2858
|
alignItems: "center",
|
|
2825
2859
|
justifyContent: "center",
|
|
2826
|
-
fontFamily: "'Open Sans', sans-serif"
|
|
2860
|
+
fontFamily: "'Open Sans', sans-serif",
|
|
2861
|
+
backgroundColor: ensureHexColorHash(schema.backgroundColor) || "transparent"
|
|
2827
2862
|
};
|
|
2828
2863
|
Object.assign(container.style, containerStyle);
|
|
2829
2864
|
rootElement.appendChild(container);
|