@pdfme/pdf-lib 6.2.6-dev.7 → 6.2.6-dev.9
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/api/svg.d.ts +9 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/api/svg.d.ts
CHANGED
|
@@ -15,6 +15,11 @@ interface Size {
|
|
|
15
15
|
height: number;
|
|
16
16
|
}
|
|
17
17
|
type Box = Position & Size;
|
|
18
|
+
/** A dash length as written in SVG, resolved against the viewport where it is used. */
|
|
19
|
+
type DashLength = {
|
|
20
|
+
value: number;
|
|
21
|
+
percent: boolean;
|
|
22
|
+
};
|
|
18
23
|
type InheritedAttributes = {
|
|
19
24
|
width: number;
|
|
20
25
|
height: number;
|
|
@@ -24,6 +29,8 @@ type InheritedAttributes = {
|
|
|
24
29
|
strokeWidth?: number;
|
|
25
30
|
strokeOpacity?: number;
|
|
26
31
|
strokeLineCap?: LineCapStyle;
|
|
32
|
+
dashArray?: DashLength[];
|
|
33
|
+
dashOffset?: DashLength;
|
|
27
34
|
fillRule?: FillRule;
|
|
28
35
|
strokeLineJoin?: LineJoinStyle;
|
|
29
36
|
fontFamily?: string;
|
|
@@ -56,6 +63,8 @@ type SVGAttributes = {
|
|
|
56
63
|
textAnchor?: string;
|
|
57
64
|
preserveAspectRatio?: string;
|
|
58
65
|
strokeWidth?: number;
|
|
66
|
+
strokeDashArray?: number[];
|
|
67
|
+
strokeDashOffset?: number;
|
|
59
68
|
dominantBaseline?: string;
|
|
60
69
|
points?: string;
|
|
61
70
|
};
|
package/dist/index.js
CHANGED
|
@@ -17283,6 +17283,8 @@ var runnersToPage = (page, options) => ({
|
|
|
17283
17283
|
color: element.svgAttributes.stroke,
|
|
17284
17284
|
opacity: element.svgAttributes.strokeOpacity,
|
|
17285
17285
|
lineCap: element.svgAttributes.strokeLineCap,
|
|
17286
|
+
dashArray: element.svgAttributes.strokeDashArray,
|
|
17287
|
+
dashPhase: element.svgAttributes.strokeDashOffset,
|
|
17286
17288
|
matrix: element.svgAttributes.matrix,
|
|
17287
17289
|
clipSpaces: element.svgAttributes.clipSpaces
|
|
17288
17290
|
});
|
|
@@ -17296,6 +17298,8 @@ var runnersToPage = (page, options) => ({
|
|
|
17296
17298
|
borderWidth: element.svgAttributes.strokeWidth,
|
|
17297
17299
|
borderOpacity: element.svgAttributes.strokeOpacity,
|
|
17298
17300
|
borderLineCap: element.svgAttributes.strokeLineCap,
|
|
17301
|
+
borderDashArray: element.svgAttributes.strokeDashArray,
|
|
17302
|
+
borderDashPhase: element.svgAttributes.strokeDashOffset,
|
|
17299
17303
|
color: element.svgAttributes.fill,
|
|
17300
17304
|
opacity: element.svgAttributes.fillOpacity,
|
|
17301
17305
|
fillRule: element.svgAttributes.fillRule,
|
|
@@ -17329,6 +17333,8 @@ var runnersToPage = (page, options) => ({
|
|
|
17329
17333
|
borderWidth: element.svgAttributes.strokeWidth,
|
|
17330
17334
|
borderOpacity: element.svgAttributes.strokeOpacity,
|
|
17331
17335
|
borderLineCap: element.svgAttributes.strokeLineCap,
|
|
17336
|
+
borderDashArray: element.svgAttributes.strokeDashArray,
|
|
17337
|
+
borderDashPhase: element.svgAttributes.strokeDashOffset,
|
|
17332
17338
|
color: element.svgAttributes.fill,
|
|
17333
17339
|
opacity: element.svgAttributes.fillOpacity,
|
|
17334
17340
|
matrix: element.svgAttributes.matrix,
|
|
@@ -17345,6 +17351,8 @@ var runnersToPage = (page, options) => ({
|
|
|
17345
17351
|
borderWidth: element.svgAttributes.strokeWidth,
|
|
17346
17352
|
borderOpacity: element.svgAttributes.strokeOpacity,
|
|
17347
17353
|
borderLineCap: element.svgAttributes.strokeLineCap,
|
|
17354
|
+
borderDashArray: element.svgAttributes.strokeDashArray,
|
|
17355
|
+
borderDashPhase: element.svgAttributes.strokeDashOffset,
|
|
17348
17356
|
color: element.svgAttributes.fill,
|
|
17349
17357
|
opacity: element.svgAttributes.fillOpacity,
|
|
17350
17358
|
matrix: element.svgAttributes.matrix,
|
|
@@ -17397,6 +17405,59 @@ var splitFontFamilies = (fontFamily) => {
|
|
|
17397
17405
|
var normalizeFontFamily = (fontFamily) => {
|
|
17398
17406
|
return splitFontFamilies(fontFamily)[0] || fontFamily.trim();
|
|
17399
17407
|
};
|
|
17408
|
+
var DASH_LENGTH_REGEX = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?(px|%)?$/i;
|
|
17409
|
+
/** Parses one dash length. The whole token must be a finite number, optionally in px or %. */
|
|
17410
|
+
var parseDashLength = (token) => {
|
|
17411
|
+
const match = DASH_LENGTH_REGEX.exec(token);
|
|
17412
|
+
if (!match) return void 0;
|
|
17413
|
+
const value = parseFloat(token);
|
|
17414
|
+
if (!Number.isFinite(value)) return void 0;
|
|
17415
|
+
return {
|
|
17416
|
+
value,
|
|
17417
|
+
percent: match[1] === "%"
|
|
17418
|
+
};
|
|
17419
|
+
};
|
|
17420
|
+
/**
|
|
17421
|
+
* Parses `stroke-dasharray`. Returns `undefined` when the value is missing or
|
|
17422
|
+
* invalid so that the inherited pattern applies, and an empty array for a
|
|
17423
|
+
* solid stroke.
|
|
17424
|
+
*/
|
|
17425
|
+
var parseDashArray = (value) => {
|
|
17426
|
+
if (!value) return void 0;
|
|
17427
|
+
const trimmed = value.trim();
|
|
17428
|
+
if (trimmed.toLowerCase() === "none") return [];
|
|
17429
|
+
const dashes = trimmed.split(/\s*,\s*|\s+/).filter((dash) => dash.length > 0).map(parseDashLength);
|
|
17430
|
+
if (dashes.length === 0) return void 0;
|
|
17431
|
+
if (dashes.some((dash) => dash === void 0 || dash.value < 0)) return void 0;
|
|
17432
|
+
const lengths = dashes;
|
|
17433
|
+
if (lengths.every((dash) => dash.value === 0)) return [];
|
|
17434
|
+
return lengths.length % 2 === 1 ? [...lengths, ...lengths] : lengths;
|
|
17435
|
+
};
|
|
17436
|
+
/** Parses `stroke-dashoffset`. Returns `undefined` when the value is missing or invalid. */
|
|
17437
|
+
var parseDashOffset = (value) => value ? parseDashLength(value.trim()) : void 0;
|
|
17438
|
+
/**
|
|
17439
|
+
* Resolves the dash pattern of a stroked element. Percentages refer to the
|
|
17440
|
+
* normalized diagonal of the element's nearest viewport, and the offset is
|
|
17441
|
+
* wrapped into the PDF dash phase range [0, pattern length).
|
|
17442
|
+
*/
|
|
17443
|
+
var resolveDashPattern = (dashArray, dashOffset, viewBox) => {
|
|
17444
|
+
if (!dashArray) return {
|
|
17445
|
+
strokeDashArray: void 0,
|
|
17446
|
+
strokeDashOffset: 0
|
|
17447
|
+
};
|
|
17448
|
+
const reference = Math.sqrt((viewBox.width ** 2 + viewBox.height ** 2) / 2);
|
|
17449
|
+
const resolve = (length) => length.percent ? length.value * reference / 100 : length.value;
|
|
17450
|
+
const lengths = dashArray.map(resolve);
|
|
17451
|
+
const patternLength = lengths.reduce((sum, dash) => sum + dash, 0);
|
|
17452
|
+
if (patternLength <= 0 || !Number.isFinite(patternLength)) return {
|
|
17453
|
+
strokeDashArray: [],
|
|
17454
|
+
strokeDashOffset: 0
|
|
17455
|
+
};
|
|
17456
|
+
return {
|
|
17457
|
+
strokeDashArray: lengths,
|
|
17458
|
+
strokeDashOffset: ((dashOffset ? resolve(dashOffset) : 0) % patternLength + patternLength) % patternLength
|
|
17459
|
+
};
|
|
17460
|
+
};
|
|
17400
17461
|
var parseColor = (color, kind, options, inherited) => {
|
|
17401
17462
|
if (!color || color.length === 0) return void 0;
|
|
17402
17463
|
if (["none", "transparent"].includes(color)) return void 0;
|
|
@@ -17447,6 +17508,8 @@ var parseAttributes = (element, inherited, matrix, options) => {
|
|
|
17447
17508
|
const strokeLineJoinRaw = styleOrAttribute(attributes, style, "stroke-linejoin");
|
|
17448
17509
|
const fillRuleRaw = styleOrAttribute(attributes, style, "fill-rule");
|
|
17449
17510
|
const strokeWidthRaw = styleOrAttribute(attributes, style, "stroke-width");
|
|
17511
|
+
const strokeDashArrayRaw = styleOrAttribute(attributes, style, "stroke-dasharray");
|
|
17512
|
+
const strokeDashOffsetRaw = styleOrAttribute(attributes, style, "stroke-dashoffset");
|
|
17450
17513
|
const fontFamilyRaw = styleOrAttribute(attributes, style, "font-family");
|
|
17451
17514
|
const fontStyleRaw = styleOrAttribute(attributes, style, "font-style");
|
|
17452
17515
|
const fontWeightRaw = styleOrAttribute(attributes, style, "font-weight");
|
|
@@ -17476,6 +17539,8 @@ var parseAttributes = (element, inherited, matrix, options) => {
|
|
|
17476
17539
|
strokeOpacity: parseFloatValue(strokeOpacityRaw || opacityRaw || strokeRaw?.alpha) ?? inherited.strokeOpacity,
|
|
17477
17540
|
strokeLineCap: StrokeLineCapMap[strokeLineCapRaw] || inherited.strokeLineCap,
|
|
17478
17541
|
strokeLineJoin: StrokeLineJoinMap[strokeLineJoinRaw] || inherited.strokeLineJoin,
|
|
17542
|
+
dashArray: parseDashArray(strokeDashArrayRaw) ?? inherited.dashArray,
|
|
17543
|
+
dashOffset: parseDashOffset(strokeDashOffsetRaw) ?? inherited.dashOffset,
|
|
17479
17544
|
width: width || inherited.width,
|
|
17480
17545
|
height: height || inherited.height,
|
|
17481
17546
|
rotation: inherited.rotation,
|
|
@@ -17626,6 +17691,7 @@ var parseHTMLNode = (node, inherited, matrix, clipSpaces, options) => {
|
|
|
17626
17691
|
const svgAttributes = {
|
|
17627
17692
|
...attributes.inherited,
|
|
17628
17693
|
...attributes.svgAttributes,
|
|
17694
|
+
...resolveDashPattern(attributes.inherited.dashArray, attributes.inherited.dashOffset, attributes.inherited.viewBox),
|
|
17629
17695
|
matrix: attributes.matrix,
|
|
17630
17696
|
clipSpaces
|
|
17631
17697
|
};
|