@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.d.mts
CHANGED
|
@@ -181,10 +181,11 @@ interface FlierDoc {
|
|
|
181
181
|
}
|
|
182
182
|
/** A text line path such as "title", "venue.1", "schedule.0.time" or "items.2.date" (see LINE_KEY_PATTERN). */
|
|
183
183
|
type LineKey = string;
|
|
184
|
-
/** Optional per-line overrides of the theme; an absent field keeps the theme value. letterSpacing is in em. */
|
|
184
|
+
/** Optional per-line overrides of the theme; an absent field keeps the theme value. letterSpacing is in em; widthScale widens or narrows the room the line may fill. */
|
|
185
185
|
interface LineStyle {
|
|
186
186
|
font?: string;
|
|
187
187
|
sizeScale?: number;
|
|
188
|
+
widthScale?: number;
|
|
188
189
|
color?: string;
|
|
189
190
|
weight?: number;
|
|
190
191
|
italic?: boolean;
|
|
@@ -260,6 +261,7 @@ interface RenderReport {
|
|
|
260
261
|
picture: Rect | null;
|
|
261
262
|
pictureRegion: Rect;
|
|
262
263
|
textBoxes: Rect[];
|
|
264
|
+
lineBoxes: Record<LineKey, Rect | undefined>;
|
|
263
265
|
cardBoxes: Rect[];
|
|
264
266
|
iconBoxes: Rect[];
|
|
265
267
|
ruleBoxes: Rect[];
|
package/dist/index.d.ts
CHANGED
|
@@ -181,10 +181,11 @@ interface FlierDoc {
|
|
|
181
181
|
}
|
|
182
182
|
/** A text line path such as "title", "venue.1", "schedule.0.time" or "items.2.date" (see LINE_KEY_PATTERN). */
|
|
183
183
|
type LineKey = string;
|
|
184
|
-
/** Optional per-line overrides of the theme; an absent field keeps the theme value. letterSpacing is in em. */
|
|
184
|
+
/** Optional per-line overrides of the theme; an absent field keeps the theme value. letterSpacing is in em; widthScale widens or narrows the room the line may fill. */
|
|
185
185
|
interface LineStyle {
|
|
186
186
|
font?: string;
|
|
187
187
|
sizeScale?: number;
|
|
188
|
+
widthScale?: number;
|
|
188
189
|
color?: string;
|
|
189
190
|
weight?: number;
|
|
190
191
|
italic?: boolean;
|
|
@@ -260,6 +261,7 @@ interface RenderReport {
|
|
|
260
261
|
picture: Rect | null;
|
|
261
262
|
pictureRegion: Rect;
|
|
262
263
|
textBoxes: Rect[];
|
|
264
|
+
lineBoxes: Record<LineKey, Rect | undefined>;
|
|
263
265
|
cardBoxes: Rect[];
|
|
264
266
|
iconBoxes: Rect[];
|
|
265
267
|
ruleBoxes: Rect[];
|
package/dist/index.js
CHANGED
|
@@ -90,6 +90,8 @@ var LINE_KEY_PATTERN = "^(title|titleBottom|script|footer|includes[.]heading|inc
|
|
|
90
90
|
var MAX_FONT = 40;
|
|
91
91
|
var MIN_SIZE_SCALE = 0.25;
|
|
92
92
|
var MAX_SIZE_SCALE = 3;
|
|
93
|
+
var MIN_WIDTH_SCALE = 0.5;
|
|
94
|
+
var MAX_WIDTH_SCALE = 1.5;
|
|
93
95
|
var MIN_SPACING = -0.1;
|
|
94
96
|
var MAX_SPACING = 0.5;
|
|
95
97
|
var MAX_TIES = 12;
|
|
@@ -101,6 +103,7 @@ var lineStyle = {
|
|
|
101
103
|
properties: {
|
|
102
104
|
font: { type: "string", minLength: 1, maxLength: MAX_FONT, pattern: "^[A-Za-z0-9 ]+$" },
|
|
103
105
|
sizeScale: { type: "number", minimum: MIN_SIZE_SCALE, maximum: MAX_SIZE_SCALE },
|
|
106
|
+
widthScale: { type: "number", minimum: MIN_WIDTH_SCALE, maximum: MAX_WIDTH_SCALE },
|
|
104
107
|
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
|
|
105
108
|
weight: { type: "integer", enum: WEIGHTS },
|
|
106
109
|
italic: { type: "boolean" },
|
|
@@ -794,16 +797,18 @@ function styled(line, key, sc) {
|
|
|
794
797
|
const widthTie = sc.width.get(key);
|
|
795
798
|
const sizeTie = sc.size.get(key);
|
|
796
799
|
if (style === void 0 && widthTie === void 0 && sizeTie === void 0) {
|
|
797
|
-
return line;
|
|
800
|
+
return { ...line, key };
|
|
798
801
|
}
|
|
799
802
|
return {
|
|
800
803
|
...line,
|
|
804
|
+
key,
|
|
801
805
|
size: line.size * (style?.sizeScale ?? 1),
|
|
802
806
|
color: style?.color ?? line.color,
|
|
803
807
|
weight: style?.weight ?? line.weight,
|
|
804
808
|
family: style?.font,
|
|
805
809
|
italic: style?.italic,
|
|
806
810
|
spacing: style?.letterSpacing,
|
|
811
|
+
widthScale: style?.widthScale,
|
|
807
812
|
align: style?.align,
|
|
808
813
|
widthTie,
|
|
809
814
|
sizeTie
|
|
@@ -984,7 +989,7 @@ function groupBox(group, k, colW) {
|
|
|
984
989
|
}
|
|
985
990
|
function lineSize(line, width, k, avail) {
|
|
986
991
|
const indent = bulletIndent(line, k);
|
|
987
|
-
return Math.max(0, Math.min(line.size * k, line.size * (avail - indent) / Math.max(width, 1)));
|
|
992
|
+
return Math.max(0, Math.min(line.size * k, line.size * (avail * (line.widthScale ?? 1) - indent) / Math.max(width, 1)));
|
|
988
993
|
}
|
|
989
994
|
function groupSizes(m, k, avail) {
|
|
990
995
|
const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail));
|
|
@@ -1002,7 +1007,7 @@ function tieMembers(all, k, colW, table, pick) {
|
|
|
1002
1007
|
m.group.lines.forEach((line, i) => {
|
|
1003
1008
|
const id = pick(line);
|
|
1004
1009
|
if (id !== void 0) {
|
|
1005
|
-
const member = { line, width: Math.max(m.widths[i] ?? 1, 1), cap: Math.max(0, avail - bulletIndent(line, k)), sizes, i };
|
|
1010
|
+
const member = { line, width: Math.max(m.widths[i] ?? 1, 1), cap: Math.max(0, avail * (line.widthScale ?? 1) - bulletIndent(line, k)), sizes, i };
|
|
1006
1011
|
byId.set(id, [...byId.get(id) ?? [], member]);
|
|
1007
1012
|
}
|
|
1008
1013
|
});
|
|
@@ -1089,7 +1094,7 @@ function placeGroup(m, at, out) {
|
|
|
1089
1094
|
const indent = (indented(line) ? line.size * k * BULLET_INDENT : 0) + iconIndent;
|
|
1090
1095
|
const w = (m.widths[i] ?? 0) * size / line.size;
|
|
1091
1096
|
const x = lineX(line, { col, pad, indent, w });
|
|
1092
|
-
out?.texts.push({ text: line.text, font: "", color: line.color, box: { x, y, w, h: size * LINE_HEIGHT } });
|
|
1097
|
+
out?.texts.push({ text: line.text, font: "", color: line.color, box: { x, y, w, h: size * LINE_HEIGHT }, key: line.key });
|
|
1093
1098
|
if (line.bullet && out) {
|
|
1094
1099
|
out.bullets.push({ x: col.x + pad + size * BULLET_RADIUS, y: y + size * LINE_HEIGHT / 2, r: size * BULLET_RADIUS, color: line.bullet });
|
|
1095
1100
|
}
|
|
@@ -1610,6 +1615,23 @@ function drawLogo(ctx, doc, assets, fitted) {
|
|
|
1610
1615
|
}
|
|
1611
1616
|
return logo;
|
|
1612
1617
|
}
|
|
1618
|
+
function lineBoxesOf(texts) {
|
|
1619
|
+
const boxes = {};
|
|
1620
|
+
texts.forEach(({ key, box }) => {
|
|
1621
|
+
if (key !== void 0) {
|
|
1622
|
+
boxes[key] = union(boxes[key], box);
|
|
1623
|
+
}
|
|
1624
|
+
});
|
|
1625
|
+
return boxes;
|
|
1626
|
+
}
|
|
1627
|
+
function union(a, b) {
|
|
1628
|
+
if (a === void 0) {
|
|
1629
|
+
return { ...b };
|
|
1630
|
+
}
|
|
1631
|
+
const x = Math.min(a.x, b.x);
|
|
1632
|
+
const y = Math.min(a.y, b.y);
|
|
1633
|
+
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 };
|
|
1634
|
+
}
|
|
1613
1635
|
function render(input, assets, canvas) {
|
|
1614
1636
|
const doc = checked(input, assets);
|
|
1615
1637
|
const { width, height } = FORMAT_SIZES[doc.format];
|
|
@@ -1645,6 +1667,7 @@ function render(input, assets, canvas) {
|
|
|
1645
1667
|
picture,
|
|
1646
1668
|
pictureRegion: region,
|
|
1647
1669
|
textBoxes: flows.flatMap((f) => f.texts.map((t) => t.box)),
|
|
1670
|
+
lineBoxes: lineBoxesOf(flows.flatMap((f) => f.texts)),
|
|
1648
1671
|
cardBoxes: body.cards.map((c) => c.rect),
|
|
1649
1672
|
iconBoxes: flows.flatMap((f) => f.icons.map((i) => i.rect)),
|
|
1650
1673
|
ruleBoxes: flows.flatMap((f) => f.rules.map((r3) => r3.rect)),
|