@dloizides/poster-render 0.7.0 → 0.9.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 +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +83 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -180,7 +180,7 @@ var FONT_SETS = {
|
|
|
180
180
|
["classic" /* Classic */]: { display: '"Oswald", "Arial Narrow", sans-serif', script: '"Sacramento", cursive', body: '"Fredoka", sans-serif' },
|
|
181
181
|
["modern" /* Modern */]: { display: '"Bebas Neue", "Arial Narrow", sans-serif', script: '"Great Vibes", cursive', body: '"Montserrat", sans-serif' },
|
|
182
182
|
["elegant" /* Elegant */]: { display: '"Playfair Display", serif', script: '"Allura", cursive', body: '"Lato", sans-serif' },
|
|
183
|
-
["kizomba-sample" /* KizombaSample */]: { display: '"Anton", "Oswald", "Arial Narrow", sans-serif', script: '"
|
|
183
|
+
["kizomba-sample" /* KizombaSample */]: { display: '"Anton", "Oswald", "Arial Narrow", sans-serif', script: '"Style Script", "Dancing Script", cursive', body: '"Barlow Semi Condensed", "Fredoka", sans-serif' },
|
|
184
184
|
["coastal" /* Coastal */]: { display: '"Fraunces", Georgia, serif', script: '"Allura", cursive', body: '"Jost", sans-serif' }
|
|
185
185
|
};
|
|
186
186
|
|
|
@@ -199,6 +199,15 @@ var MAX_LINE_GAP = 200;
|
|
|
199
199
|
var MIN_TITLE_SCALE = 0.3;
|
|
200
200
|
var MAX_TITLE_SCALE = 2.5;
|
|
201
201
|
var MIN_LABEL_SCALE = 0.3;
|
|
202
|
+
var MAX_ROW_SCALE = 2;
|
|
203
|
+
var MIN_WEIGHT = 100;
|
|
204
|
+
var MAX_WEIGHT = 900;
|
|
205
|
+
var MIN_WIDTH = 100;
|
|
206
|
+
var MAX_LENGTH = 1080;
|
|
207
|
+
var MAX_BODY_TOP = 1920;
|
|
208
|
+
var MAX_LENGTHS = 12;
|
|
209
|
+
var MIN_SPACING2 = -0.2;
|
|
210
|
+
var MAX_SPACING2 = 0.5;
|
|
202
211
|
var num = (minimum, maximum) => ({ type: "number", minimum, maximum });
|
|
203
212
|
var icons = (maxItems) => ({ type: "array", items: { type: "string", enum: Object.values(RowIcon) }, minItems: 1, maxItems });
|
|
204
213
|
var rowsSchema = {
|
|
@@ -215,11 +224,17 @@ var rowsSchema = {
|
|
|
215
224
|
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
|
|
216
225
|
gap: num(0, MAX_GAP),
|
|
217
226
|
toPicture: { type: "boolean" },
|
|
218
|
-
reach: num(0, 1)
|
|
227
|
+
reach: num(0, 1),
|
|
228
|
+
lengths: { type: "array", items: num(0, MAX_LENGTH), minItems: 1, maxItems: MAX_LENGTHS }
|
|
219
229
|
}
|
|
220
230
|
},
|
|
221
231
|
priceLabelScale: num(MIN_LABEL_SCALE, 1),
|
|
222
|
-
venue: { type: "object", additionalProperties: false, properties: { body: { type: "boolean" }, bare: { type: "boolean" } } }
|
|
232
|
+
venue: { type: "object", additionalProperties: false, properties: { body: { type: "boolean" }, bare: { type: "boolean" }, oneLine: { type: "boolean" }, pinSize: num(0, MAX_LENGTH), pinGap: num(0, MAX_GAP), pinShift: num(-MAX_GAP, MAX_GAP), centred: { type: "boolean" } } },
|
|
233
|
+
priceGap: num(-MAX_GAP, MAX_GAP),
|
|
234
|
+
labelScale: num(MIN_LABEL_SCALE, MAX_ROW_SCALE),
|
|
235
|
+
timeScale: num(MIN_LABEL_SCALE, MAX_ROW_SCALE),
|
|
236
|
+
timeWeight: num(MIN_WEIGHT, MAX_WEIGHT),
|
|
237
|
+
textWidth: num(MIN_WIDTH, MAX_LENGTH)
|
|
223
238
|
}
|
|
224
239
|
};
|
|
225
240
|
var overlapSchema = {
|
|
@@ -233,7 +248,12 @@ var headerTuningSchema = {
|
|
|
233
248
|
titleScriptGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
|
|
234
249
|
scriptTitleGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
|
|
235
250
|
titleScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
|
|
236
|
-
titleBottomScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE)
|
|
251
|
+
titleBottomScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
|
|
252
|
+
headerTextWidth: num(MIN_WIDTH, MAX_LENGTH),
|
|
253
|
+
bodyTop: num(0, MAX_BODY_TOP),
|
|
254
|
+
headerHeight: num(MIN_WIDTH, MAX_BODY_TOP),
|
|
255
|
+
titleSpacing: num(MIN_SPACING2, MAX_SPACING2),
|
|
256
|
+
scriptScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE)
|
|
237
257
|
};
|
|
238
258
|
|
|
239
259
|
// src/schema/flierDocSchema.ts
|
|
@@ -793,6 +813,7 @@ var BOLD = 700;
|
|
|
793
813
|
var SEMI = 600;
|
|
794
814
|
var MEDIUM = 500;
|
|
795
815
|
var SCRIPT = 400;
|
|
816
|
+
var LABEL_TIE = -1;
|
|
796
817
|
var SIZE = {
|
|
797
818
|
title: 250,
|
|
798
819
|
headerScript: 120,
|
|
@@ -817,7 +838,7 @@ var GAP = {
|
|
|
817
838
|
rule: 8,
|
|
818
839
|
divider: 24
|
|
819
840
|
};
|
|
820
|
-
var makers = (p, u, sc) => ({
|
|
841
|
+
var makers = (p, u, sc, timeWeight = SEMI) => ({
|
|
821
842
|
display: (text2, size, key) => styled({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }, key, sc),
|
|
822
843
|
venue: (text2, size, key) => styled({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }, key, sc),
|
|
823
844
|
bodyVenue: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
|
|
@@ -825,16 +846,18 @@ var makers = (p, u, sc) => ({
|
|
|
825
846
|
strong: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
|
|
826
847
|
accent: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }, key, sc),
|
|
827
848
|
item: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }, key, sc),
|
|
828
|
-
soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc)
|
|
849
|
+
soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc),
|
|
850
|
+
time: (text2, size, key) => styled({ text: text2, role: "body", weight: timeWeight, size: size * u, color: p.accent }, key, sc)
|
|
829
851
|
});
|
|
830
852
|
function headerGroups(doc, p, u) {
|
|
831
853
|
const l = makers(p, u, styleContext(doc));
|
|
832
854
|
const b = doc.blocks;
|
|
833
855
|
const t = doc.tuning;
|
|
834
856
|
const gap = (line, after) => after === void 0 ? line : { ...line, gapAfter: after * u };
|
|
835
|
-
const
|
|
836
|
-
const
|
|
837
|
-
const
|
|
857
|
+
const spaced = (line) => t?.titleSpacing === void 0 || line.spacing !== void 0 ? line : { ...line, spacing: t.titleSpacing };
|
|
858
|
+
const title = gap(spaced(l.display(b.title, SIZE.title * (t?.titleScale ?? 1), "title")), b.script ?? b.titleBottom ? t?.titleScriptGap : void 0);
|
|
859
|
+
const script = b.script ? gap(l.script(b.script, SIZE.headerScript * (t?.scriptScale ?? 1), "script"), b.titleBottom ? t?.scriptTitleGap : void 0) : void 0;
|
|
860
|
+
const lines = [title, script, b.titleBottom ? spaced(l.display(b.titleBottom, SIZE.title * (t?.titleBottomScale ?? 1), "titleBottom")) : void 0];
|
|
838
861
|
return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
|
|
839
862
|
}
|
|
840
863
|
function itemGroup(item, n, l, scale) {
|
|
@@ -873,6 +896,13 @@ function wrapped(line, wrap) {
|
|
|
873
896
|
const parts = wrap ? halves(line.text) : [line.text];
|
|
874
897
|
return parts.map((text2, i) => i === 0 ? { ...line, text: text2 } : { ...line, text: text2, bullet: void 0, hang: line.bullet !== void 0 });
|
|
875
898
|
}
|
|
899
|
+
function scheduleLines(doc, l, row, i) {
|
|
900
|
+
const r3 = doc.rows;
|
|
901
|
+
const label = l.strong(row.label, SIZE.scheduleLabel * (r3?.labelScale ?? 1), `schedule.${i}.label`);
|
|
902
|
+
const tied = r3?.labelScale === void 0 ? label : { ...label, sizeTie: label.sizeTie ?? LABEL_TIE };
|
|
903
|
+
return [tied, l.time(row.time, SIZE.scheduleTime * (r3?.timeScale ?? 1), `schedule.${i}.time`)];
|
|
904
|
+
}
|
|
905
|
+
var priceAmount = (doc, line) => doc.rows?.priceGap === void 0 ? line : { ...line, gapAfter: doc.rows.priceGap };
|
|
876
906
|
function eventGroups(doc, l, u, options) {
|
|
877
907
|
const b = doc.blocks;
|
|
878
908
|
const groups = [];
|
|
@@ -881,11 +911,11 @@ function eventGroups(doc, l, u, options) {
|
|
|
881
911
|
const lastRow = schedule2.length + prices.length - 1;
|
|
882
912
|
const icons2 = doc.rows?.icons;
|
|
883
913
|
schedule2.forEach((row, i) => {
|
|
884
|
-
const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`)] :
|
|
914
|
+
const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`)] : scheduleLines(doc, l, row, i);
|
|
885
915
|
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1, ...options.marks(icons2?.schedule, i, i === lastRow) });
|
|
886
916
|
});
|
|
887
917
|
prices.forEach((row, i) => {
|
|
888
|
-
const lines = options.compact ? [l.strong(`${row.amount} ${row.label}`, SIZE.priceAmount, `prices.${i}.amount`)] : [l.strong(row.amount, SIZE.priceAmount, `prices.${i}.amount`), l.accent(row.label, SIZE.priceLabel * (doc.rows?.priceLabelScale ?? 1), `prices.${i}.label`)];
|
|
918
|
+
const lines = options.compact ? [l.strong(`${row.amount} ${row.label}`, SIZE.priceAmount, `prices.${i}.amount`)] : [priceAmount(doc, l.strong(row.amount, SIZE.priceAmount, `prices.${i}.amount`)), l.accent(row.label, SIZE.priceLabel * (doc.rows?.priceLabelScale ?? 1), `prices.${i}.label`)];
|
|
889
919
|
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1, ...options.marks(icons2?.prices, i, schedule2.length + i === lastRow) });
|
|
890
920
|
});
|
|
891
921
|
return groups;
|
|
@@ -902,8 +932,11 @@ function flankPriceGroups(doc, p, u) {
|
|
|
902
932
|
const l = makers(p, u, styleContext(doc));
|
|
903
933
|
return (doc.blocks.prices ?? []).map((row, i) => ({ lines: [l.strong(row.amount, SIZE.flankAmount, `prices.${i}.amount`), l.accent(row.label, SIZE.flankLabel, `prices.${i}.label`)], gapAfter: GAP.row * u }));
|
|
904
934
|
}
|
|
935
|
+
function pinOf(look, u) {
|
|
936
|
+
return { size: look?.pinSize === void 0 ? void 0 : look.pinSize * u, gap: look?.pinGap === void 0 ? void 0 : look.pinGap * u, shift: look?.pinShift === void 0 ? void 0 : look.pinShift * u, centre: look?.centred };
|
|
937
|
+
}
|
|
905
938
|
function bodyGroups(doc, p, u, options = {}) {
|
|
906
|
-
const l = makers(p, u, styleContext(doc));
|
|
939
|
+
const l = makers(p, u, styleContext(doc), doc.rows?.timeWeight);
|
|
907
940
|
const b = doc.blocks;
|
|
908
941
|
const groups = [];
|
|
909
942
|
const isList = doc.layout === "list" /* List */;
|
|
@@ -912,7 +945,8 @@ function bodyGroups(doc, p, u, options = {}) {
|
|
|
912
945
|
const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
|
|
913
946
|
const look = doc.rows?.venue;
|
|
914
947
|
const line = look?.body === true ? l.bodyVenue : l.venue;
|
|
915
|
-
|
|
948
|
+
const venue = look?.oneLine === true ? [b.venue.join(" ")] : b.venue;
|
|
949
|
+
groups.push({ lines: venue.map((v, i) => line(v, size, `venue.${i}`)), gapAfter: GAP.venue * u, rule: dividerOf(doc, p, u) ?? { color: p.accent, height: GAP.rule * u }, ruleBelow: true, icon: { color: p.icon ?? p.accent, glyph: p.background, bare: look?.bare, ...pinOf(look, u) }, keepWithNext });
|
|
916
950
|
}
|
|
917
951
|
groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, { ...options, marks: rowMarks(doc, p, u) }));
|
|
918
952
|
if (b.includes) {
|
|
@@ -942,7 +976,8 @@ var iconSize = (group, k) => {
|
|
|
942
976
|
function groupBox(group, k, colW) {
|
|
943
977
|
const pad = group.card ? group.card.pad * k : 0;
|
|
944
978
|
const d = iconSize(group, k);
|
|
945
|
-
const
|
|
979
|
+
const gap = group.icon?.gap === void 0 ? d * ICON_GAP : group.icon.gap * k;
|
|
980
|
+
const iconIndent = d > 0 ? d + gap : 0;
|
|
946
981
|
return { pad, d, iconIndent, avail: colW - 2 * pad - iconIndent };
|
|
947
982
|
}
|
|
948
983
|
function lineSize(line, width, k, avail) {
|
|
@@ -1029,7 +1064,7 @@ function placeIcon(group, box, out) {
|
|
|
1029
1064
|
return bottom2;
|
|
1030
1065
|
}
|
|
1031
1066
|
const textH = bottom2 - top;
|
|
1032
|
-
out?.icons.push({ rect: { x, y: top + Math.max(0, (textH - d) / 2), w: d, h: d }, color: group.icon.color, glyph: group.icon.glyph, kind: group.icon.kind, bare: group.icon.bare });
|
|
1067
|
+
out?.icons.push({ rect: { x, y: top + Math.max(0, (textH - d) / 2) + (group.icon.shift ?? 0), w: d, h: d }, color: group.icon.color, glyph: group.icon.glyph, kind: group.icon.kind, bare: group.icon.bare });
|
|
1033
1068
|
return top + Math.max(textH, d);
|
|
1034
1069
|
}
|
|
1035
1070
|
function placeGroup(m, at, out) {
|
|
@@ -1043,6 +1078,10 @@ function placeGroup(m, at, out) {
|
|
|
1043
1078
|
const { pad, d, iconIndent } = groupBox(group, k, col.w);
|
|
1044
1079
|
const top = y;
|
|
1045
1080
|
y += pad;
|
|
1081
|
+
if (group.icon?.centre === true) {
|
|
1082
|
+
const textH = group.lines.reduce((h, line, i) => h + (sizes[i] ?? 0) * LINE_HEIGHT + (i < group.lines.length - 1 ? (line.gapAfter ?? 0) * k : 0), 0);
|
|
1083
|
+
y += Math.max(0, (d - textH) / 2);
|
|
1084
|
+
}
|
|
1046
1085
|
group.lines.forEach((line, i) => {
|
|
1047
1086
|
const size = sizes[i] ?? 0;
|
|
1048
1087
|
const indent = (indented(line) ? line.size * k * BULLET_INDENT : 0) + iconIndent;
|
|
@@ -1251,10 +1290,29 @@ function closeHeaderGap(geo, head, gap, u) {
|
|
|
1251
1290
|
const top = Math.round(Math.max(...head.texts.map((t) => t.box.y + t.box.h)) + gap * u);
|
|
1252
1291
|
return top < body.y ? { ...geo, body: { ...body, y: top, h: body.h + body.y - top } } : geo;
|
|
1253
1292
|
}
|
|
1254
|
-
function
|
|
1293
|
+
function tunedGeo(geo, doc, u) {
|
|
1294
|
+
const top = doc.tuning?.bodyTop;
|
|
1295
|
+
const width = doc.rows?.textWidth;
|
|
1296
|
+
let { header, body } = geo;
|
|
1297
|
+
if (top !== void 0) {
|
|
1298
|
+
const y = Math.round(top * u);
|
|
1299
|
+
header = { ...header, h: Math.max(1, y - header.y) };
|
|
1300
|
+
body = { ...body, y, h: Math.max(1, body.y + body.h - y) };
|
|
1301
|
+
}
|
|
1302
|
+
if (width !== void 0) {
|
|
1303
|
+
body = { ...body, w: Math.round(width * u) };
|
|
1304
|
+
}
|
|
1305
|
+
return { ...geo, header, body };
|
|
1306
|
+
}
|
|
1307
|
+
function widened(zones, size, u) {
|
|
1308
|
+
const { text: text2 } = zones;
|
|
1309
|
+
return { ...zones, text: { ...text2, w: size.w === void 0 ? text2.w : Math.round(size.w * u), h: size.h === void 0 ? text2.h : Math.round(size.h * u) } };
|
|
1310
|
+
}
|
|
1311
|
+
function flowAll(ctx, input, base2, reflow) {
|
|
1255
1312
|
const { doc, palette, fonts } = input;
|
|
1256
1313
|
const u = Math.min(input.width, input.height) / BASE;
|
|
1257
|
-
const
|
|
1314
|
+
const geo = tunedGeo(base2, doc, u);
|
|
1315
|
+
const zones = widened(headerAt(geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0), doc.tuning?.headerTop, u), { w: doc.tuning?.headerTextWidth, h: doc.tuning?.headerHeight }, u);
|
|
1258
1316
|
const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
|
|
1259
1317
|
const flanks = geo.flanks ?? [];
|
|
1260
1318
|
const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
|
|
@@ -1350,6 +1408,11 @@ function reachPicture(rules, picture, reach) {
|
|
|
1350
1408
|
r3.rect.w = Math.max(0, end - r3.rect.x);
|
|
1351
1409
|
});
|
|
1352
1410
|
}
|
|
1411
|
+
function stepRules(rules, lengths, u) {
|
|
1412
|
+
rules.forEach((r3, i) => {
|
|
1413
|
+
r3.rect.w = (lengths[Math.min(i, lengths.length - 1)] ?? 0) * u;
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1353
1416
|
|
|
1354
1417
|
// src/render/rowIcons.ts
|
|
1355
1418
|
var LINE2 = 0.03;
|
|
@@ -1531,6 +1594,9 @@ function placeOnPage(doc, assets, fitted, frame) {
|
|
|
1531
1594
|
if (picture && dividers?.toPicture === true) {
|
|
1532
1595
|
reachPicture(fitted.body.rules, picture, dividers.reach ?? 0);
|
|
1533
1596
|
}
|
|
1597
|
+
if (dividers?.lengths !== void 0) {
|
|
1598
|
+
stepRules(fitted.body.rules, dividers.lengths, frame.u);
|
|
1599
|
+
}
|
|
1534
1600
|
return { image, region, picture };
|
|
1535
1601
|
}
|
|
1536
1602
|
function drawLogo(ctx, doc, assets, fitted) {
|