@dloizides/poster-render 0.9.1 → 0.11.0
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.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +27 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -88,6 +88,8 @@ var LINE_KEY_PATTERN = "^(title|titleBottom|script|footer|includes[.]heading|inc
|
|
|
88
88
|
var MAX_FONT = 40;
|
|
89
89
|
var MIN_SIZE_SCALE = 0.25;
|
|
90
90
|
var MAX_SIZE_SCALE = 3;
|
|
91
|
+
var MIN_WIDTH_SCALE = 0.5;
|
|
92
|
+
var MAX_WIDTH_SCALE = 1.5;
|
|
91
93
|
var MIN_SPACING = -0.1;
|
|
92
94
|
var MAX_SPACING = 0.5;
|
|
93
95
|
var MAX_TIES = 12;
|
|
@@ -99,6 +101,7 @@ var lineStyle = {
|
|
|
99
101
|
properties: {
|
|
100
102
|
font: { type: "string", minLength: 1, maxLength: MAX_FONT, pattern: "^[A-Za-z0-9 ]+$" },
|
|
101
103
|
sizeScale: { type: "number", minimum: MIN_SIZE_SCALE, maximum: MAX_SIZE_SCALE },
|
|
104
|
+
widthScale: { type: "number", minimum: MIN_WIDTH_SCALE, maximum: MAX_WIDTH_SCALE },
|
|
102
105
|
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
|
|
103
106
|
weight: { type: "integer", enum: WEIGHTS },
|
|
104
107
|
italic: { type: "boolean" },
|
|
@@ -792,16 +795,18 @@ function styled(line, key, sc) {
|
|
|
792
795
|
const widthTie = sc.width.get(key);
|
|
793
796
|
const sizeTie = sc.size.get(key);
|
|
794
797
|
if (style === void 0 && widthTie === void 0 && sizeTie === void 0) {
|
|
795
|
-
return line;
|
|
798
|
+
return { ...line, key };
|
|
796
799
|
}
|
|
797
800
|
return {
|
|
798
801
|
...line,
|
|
802
|
+
key,
|
|
799
803
|
size: line.size * (style?.sizeScale ?? 1),
|
|
800
804
|
color: style?.color ?? line.color,
|
|
801
805
|
weight: style?.weight ?? line.weight,
|
|
802
806
|
family: style?.font,
|
|
803
807
|
italic: style?.italic,
|
|
804
808
|
spacing: style?.letterSpacing,
|
|
809
|
+
widthScale: style?.widthScale,
|
|
805
810
|
align: style?.align,
|
|
806
811
|
widthTie,
|
|
807
812
|
sizeTie
|
|
@@ -982,7 +987,7 @@ function groupBox(group, k, colW) {
|
|
|
982
987
|
}
|
|
983
988
|
function lineSize(line, width, k, avail) {
|
|
984
989
|
const indent = bulletIndent(line, k);
|
|
985
|
-
return Math.max(0, Math.min(line.size * k, line.size * (avail - indent) / Math.max(width, 1)));
|
|
990
|
+
return Math.max(0, Math.min(line.size * k, line.size * (avail * (line.widthScale ?? 1) - indent) / Math.max(width, 1)));
|
|
986
991
|
}
|
|
987
992
|
function groupSizes(m, k, avail) {
|
|
988
993
|
const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail));
|
|
@@ -1000,7 +1005,7 @@ function tieMembers(all, k, colW, table, pick) {
|
|
|
1000
1005
|
m.group.lines.forEach((line, i) => {
|
|
1001
1006
|
const id = pick(line);
|
|
1002
1007
|
if (id !== void 0) {
|
|
1003
|
-
const member = { line, width: Math.max(m.widths[i] ?? 1, 1), cap: Math.max(0, avail - bulletIndent(line, k)), sizes, i };
|
|
1008
|
+
const member = { line, width: Math.max(m.widths[i] ?? 1, 1), cap: Math.max(0, avail * (line.widthScale ?? 1) - bulletIndent(line, k)), sizes, i };
|
|
1004
1009
|
byId.set(id, [...byId.get(id) ?? [], member]);
|
|
1005
1010
|
}
|
|
1006
1011
|
});
|
|
@@ -1087,7 +1092,7 @@ function placeGroup(m, at, out) {
|
|
|
1087
1092
|
const indent = (indented(line) ? line.size * k * BULLET_INDENT : 0) + iconIndent;
|
|
1088
1093
|
const w = (m.widths[i] ?? 0) * size / line.size;
|
|
1089
1094
|
const x = lineX(line, { col, pad, indent, w });
|
|
1090
|
-
out?.texts.push({ text: line.text, font: "", color: line.color, box: { x, y, w, h: size * LINE_HEIGHT } });
|
|
1095
|
+
out?.texts.push({ text: line.text, font: "", color: line.color, box: { x, y, w, h: size * LINE_HEIGHT }, key: line.key });
|
|
1091
1096
|
if (line.bullet && out) {
|
|
1092
1097
|
out.bullets.push({ x: col.x + pad + size * BULLET_RADIUS, y: y + size * LINE_HEIGHT / 2, r: size * BULLET_RADIUS, color: line.bullet });
|
|
1093
1098
|
}
|
|
@@ -1608,6 +1613,23 @@ function drawLogo(ctx, doc, assets, fitted) {
|
|
|
1608
1613
|
}
|
|
1609
1614
|
return logo;
|
|
1610
1615
|
}
|
|
1616
|
+
function lineBoxesOf(texts) {
|
|
1617
|
+
const boxes = {};
|
|
1618
|
+
texts.forEach(({ key, box }) => {
|
|
1619
|
+
if (key !== void 0) {
|
|
1620
|
+
boxes[key] = union(boxes[key], box);
|
|
1621
|
+
}
|
|
1622
|
+
});
|
|
1623
|
+
return boxes;
|
|
1624
|
+
}
|
|
1625
|
+
function union(a, b) {
|
|
1626
|
+
if (a === void 0) {
|
|
1627
|
+
return { ...b };
|
|
1628
|
+
}
|
|
1629
|
+
const x = Math.min(a.x, b.x);
|
|
1630
|
+
const y = Math.min(a.y, b.y);
|
|
1631
|
+
return { x, y, w: Math.max(a.x + a.w, b.x + b.w) - x, h: Math.max(a.y + a.h, b.y + b.h) - y };
|
|
1632
|
+
}
|
|
1611
1633
|
function render(input, assets, canvas) {
|
|
1612
1634
|
const doc = checked(input, assets);
|
|
1613
1635
|
const { width, height } = FORMAT_SIZES[doc.format];
|
|
@@ -1643,6 +1665,7 @@ function render(input, assets, canvas) {
|
|
|
1643
1665
|
picture,
|
|
1644
1666
|
pictureRegion: region,
|
|
1645
1667
|
textBoxes: flows.flatMap((f) => f.texts.map((t) => t.box)),
|
|
1668
|
+
lineBoxes: lineBoxesOf(flows.flatMap((f) => f.texts)),
|
|
1646
1669
|
cardBoxes: body.cards.map((c) => c.rect),
|
|
1647
1670
|
iconBoxes: flows.flatMap((f) => f.icons.map((i) => i.rect)),
|
|
1648
1671
|
ruleBoxes: flows.flatMap((f) => f.rules.map((r3) => r3.rect)),
|