@dloizides/poster-render 0.6.0 → 0.8.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.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: '"Sacramento", cursive', body: '"Barlow Semi Condensed", "Fredoka", sans-serif' },
183
+ ["kizomba-sample" /* KizombaSample */]: { display: '"Anton", "Oswald", "Arial Narrow", sans-serif', script: '"Dancing Script", "Sacramento", 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
 
@@ -198,6 +198,16 @@ var MAX_TOP = 600;
198
198
  var MAX_LINE_GAP = 200;
199
199
  var MIN_TITLE_SCALE = 0.3;
200
200
  var MAX_TITLE_SCALE = 2.5;
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;
201
211
  var num = (minimum, maximum) => ({ type: "number", minimum, maximum });
202
212
  var icons = (maxItems) => ({ type: "array", items: { type: "string", enum: Object.values(RowIcon) }, minItems: 1, maxItems });
203
213
  var rowsSchema = {
@@ -214,9 +224,16 @@ var rowsSchema = {
214
224
  color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
215
225
  gap: num(0, MAX_GAP),
216
226
  toPicture: { type: "boolean" },
217
- reach: num(0, 1)
227
+ reach: num(0, 1),
228
+ lengths: { type: "array", items: num(0, MAX_LENGTH), minItems: 1, maxItems: MAX_LENGTHS }
218
229
  }
219
- }
230
+ },
231
+ priceLabelScale: num(MIN_LABEL_SCALE, 1),
232
+ venue: { type: "object", additionalProperties: false, properties: { body: { type: "boolean" }, bare: { type: "boolean" }, oneLine: { type: "boolean" } } },
233
+ labelScale: num(MIN_LABEL_SCALE, MAX_ROW_SCALE),
234
+ timeScale: num(MIN_LABEL_SCALE, MAX_ROW_SCALE),
235
+ timeWeight: num(MIN_WEIGHT, MAX_WEIGHT),
236
+ textWidth: num(MIN_WIDTH, MAX_LENGTH)
220
237
  }
221
238
  };
222
239
  var overlapSchema = {
@@ -230,7 +247,12 @@ var headerTuningSchema = {
230
247
  titleScriptGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
231
248
  scriptTitleGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
232
249
  titleScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
233
- titleBottomScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE)
250
+ titleBottomScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
251
+ headerTextWidth: num(MIN_WIDTH, MAX_LENGTH),
252
+ bodyTop: num(0, MAX_BODY_TOP),
253
+ headerHeight: num(MIN_WIDTH, MAX_BODY_TOP),
254
+ titleSpacing: num(MIN_SPACING2, MAX_SPACING2),
255
+ scriptScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE)
234
256
  };
235
257
 
236
258
  // src/schema/flierDocSchema.ts
@@ -790,6 +812,7 @@ var BOLD = 700;
790
812
  var SEMI = 600;
791
813
  var MEDIUM = 500;
792
814
  var SCRIPT = 400;
815
+ var LABEL_TIE = -1;
793
816
  var SIZE = {
794
817
  title: 250,
795
818
  headerScript: 120,
@@ -814,23 +837,26 @@ var GAP = {
814
837
  rule: 8,
815
838
  divider: 24
816
839
  };
817
- var makers = (p, u, sc) => ({
840
+ var makers = (p, u, sc, timeWeight = SEMI) => ({
818
841
  display: (text2, size, key) => styled({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }, key, sc),
819
842
  venue: (text2, size, key) => styled({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }, key, sc),
843
+ bodyVenue: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
820
844
  script: (text2, size, key) => styled({ text: text2, role: "script", weight: SCRIPT, size: size * u, color: p.script ?? p.accent }, key, sc),
821
845
  strong: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
822
846
  accent: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }, key, sc),
823
847
  item: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }, key, sc),
824
- soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc)
848
+ soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc),
849
+ time: (text2, size, key) => styled({ text: text2, role: "body", weight: timeWeight, size: size * u, color: p.accent }, key, sc)
825
850
  });
826
851
  function headerGroups(doc, p, u) {
827
852
  const l = makers(p, u, styleContext(doc));
828
853
  const b = doc.blocks;
829
854
  const t = doc.tuning;
830
855
  const gap = (line, after) => after === void 0 ? line : { ...line, gapAfter: after * u };
831
- const title = gap(l.display(b.title, SIZE.title * (t?.titleScale ?? 1), "title"), b.script ?? b.titleBottom ? t?.titleScriptGap : void 0);
832
- const script = b.script ? gap(l.script(b.script, SIZE.headerScript, "script"), b.titleBottom ? t?.scriptTitleGap : void 0) : void 0;
833
- const lines = [title, script, b.titleBottom ? l.display(b.titleBottom, SIZE.title * (t?.titleBottomScale ?? 1), "titleBottom") : void 0];
856
+ const spaced = (line) => t?.titleSpacing === void 0 || line.spacing !== void 0 ? line : { ...line, spacing: t.titleSpacing };
857
+ const title = gap(spaced(l.display(b.title, SIZE.title * (t?.titleScale ?? 1), "title")), b.script ?? b.titleBottom ? t?.titleScriptGap : void 0);
858
+ const script = b.script ? gap(l.script(b.script, SIZE.headerScript * (t?.scriptScale ?? 1), "script"), b.titleBottom ? t?.scriptTitleGap : void 0) : void 0;
859
+ const lines = [title, script, b.titleBottom ? spaced(l.display(b.titleBottom, SIZE.title * (t?.titleBottomScale ?? 1), "titleBottom")) : void 0];
834
860
  return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
835
861
  }
836
862
  function itemGroup(item, n, l, scale) {
@@ -869,6 +895,12 @@ function wrapped(line, wrap) {
869
895
  const parts = wrap ? halves(line.text) : [line.text];
870
896
  return parts.map((text2, i) => i === 0 ? { ...line, text: text2 } : { ...line, text: text2, bullet: void 0, hang: line.bullet !== void 0 });
871
897
  }
898
+ function scheduleLines(doc, l, row, i) {
899
+ const r3 = doc.rows;
900
+ const label = l.strong(row.label, SIZE.scheduleLabel * (r3?.labelScale ?? 1), `schedule.${i}.label`);
901
+ const tied = r3?.labelScale === void 0 ? label : { ...label, sizeTie: label.sizeTie ?? LABEL_TIE };
902
+ return [tied, l.time(row.time, SIZE.scheduleTime * (r3?.timeScale ?? 1), `schedule.${i}.time`)];
903
+ }
872
904
  function eventGroups(doc, l, u, options) {
873
905
  const b = doc.blocks;
874
906
  const groups = [];
@@ -877,11 +909,11 @@ function eventGroups(doc, l, u, options) {
877
909
  const lastRow = schedule2.length + prices.length - 1;
878
910
  const icons2 = doc.rows?.icons;
879
911
  schedule2.forEach((row, i) => {
880
- const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`)] : [l.strong(row.label, SIZE.scheduleLabel, `schedule.${i}.label`), l.accent(row.time, SIZE.scheduleTime, `schedule.${i}.time`)];
912
+ const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`)] : scheduleLines(doc, l, row, i);
881
913
  groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1, ...options.marks(icons2?.schedule, i, i === lastRow) });
882
914
  });
883
915
  prices.forEach((row, i) => {
884
- 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, `prices.${i}.label`)];
916
+ 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`)];
885
917
  groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1, ...options.marks(icons2?.prices, i, schedule2.length + i === lastRow) });
886
918
  });
887
919
  return groups;
@@ -899,14 +931,17 @@ function flankPriceGroups(doc, p, u) {
899
931
  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 }));
900
932
  }
901
933
  function bodyGroups(doc, p, u, options = {}) {
902
- const l = makers(p, u, styleContext(doc));
934
+ const l = makers(p, u, styleContext(doc), doc.rows?.timeWeight);
903
935
  const b = doc.blocks;
904
936
  const groups = [];
905
937
  const isList = doc.layout === "list" /* List */;
906
938
  if (b.venue) {
907
939
  const size = isList ? SIZE.listVenue : SIZE.venue;
908
940
  const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
909
- groups.push({ lines: b.venue.map((v, i) => l.venue(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 }, keepWithNext });
941
+ const look = doc.rows?.venue;
942
+ const line = look?.body === true ? l.bodyVenue : l.venue;
943
+ const venue = look?.oneLine === true ? [b.venue.join(" ")] : b.venue;
944
+ 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 }, keepWithNext });
910
945
  }
911
946
  groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, { ...options, marks: rowMarks(doc, p, u) }));
912
947
  if (b.includes) {
@@ -1023,7 +1058,7 @@ function placeIcon(group, box, out) {
1023
1058
  return bottom2;
1024
1059
  }
1025
1060
  const textH = bottom2 - top;
1026
- 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 });
1061
+ 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 });
1027
1062
  return top + Math.max(textH, d);
1028
1063
  }
1029
1064
  function placeGroup(m, at, out) {
@@ -1245,10 +1280,29 @@ function closeHeaderGap(geo, head, gap, u) {
1245
1280
  const top = Math.round(Math.max(...head.texts.map((t) => t.box.y + t.box.h)) + gap * u);
1246
1281
  return top < body.y ? { ...geo, body: { ...body, y: top, h: body.h + body.y - top } } : geo;
1247
1282
  }
1248
- function flowAll(ctx, input, geo, reflow) {
1283
+ function tunedGeo(geo, doc, u) {
1284
+ const top = doc.tuning?.bodyTop;
1285
+ const width = doc.rows?.textWidth;
1286
+ let { header, body } = geo;
1287
+ if (top !== void 0) {
1288
+ const y = Math.round(top * u);
1289
+ header = { ...header, h: Math.max(1, y - header.y) };
1290
+ body = { ...body, y, h: Math.max(1, body.y + body.h - y) };
1291
+ }
1292
+ if (width !== void 0) {
1293
+ body = { ...body, w: Math.round(width * u) };
1294
+ }
1295
+ return { ...geo, header, body };
1296
+ }
1297
+ function widened(zones, size, u) {
1298
+ const { text: text2 } = zones;
1299
+ 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) } };
1300
+ }
1301
+ function flowAll(ctx, input, base2, reflow) {
1249
1302
  const { doc, palette, fonts } = input;
1250
1303
  const u = Math.min(input.width, input.height) / BASE;
1251
- const zones = headerAt(geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0), doc.tuning?.headerTop, u);
1304
+ const geo = tunedGeo(base2, doc, u);
1305
+ 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);
1252
1306
  const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
1253
1307
  const flanks = geo.flanks ?? [];
1254
1308
  const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
@@ -1344,6 +1398,11 @@ function reachPicture(rules, picture, reach) {
1344
1398
  r3.rect.w = Math.max(0, end - r3.rect.x);
1345
1399
  });
1346
1400
  }
1401
+ function stepRules(rules, lengths, u) {
1402
+ rules.forEach((r3, i) => {
1403
+ r3.rect.w = (lengths[Math.min(i, lengths.length - 1)] ?? 0) * u;
1404
+ });
1405
+ }
1347
1406
 
1348
1407
  // src/render/rowIcons.ts
1349
1408
  var LINE2 = 0.03;
@@ -1414,18 +1473,23 @@ var PIN_TIP_Y = 0.28;
1414
1473
  var PIN_HOLE = 0.42;
1415
1474
  var ARC_START = 0.75;
1416
1475
  var ARC_END = 2.25;
1417
- function drawPin(ctx, r3, color, glyph) {
1476
+ var BARE_SCALE = 1.6;
1477
+ function drawPin(ctx, r3, colors, bare = false) {
1478
+ const { color, glyph } = bare ? { color: colors.glyph, glyph: colors.color } : colors;
1479
+ const w = bare ? r3.w * BARE_SCALE : r3.w;
1418
1480
  const cx = r3.x + r3.w / 2;
1419
1481
  const cy = r3.y + r3.h / 2;
1420
- const hy = cy - r3.w * PIN_HEAD_Y;
1421
- const rad = r3.w * PIN_HEAD_R;
1422
- ctx.fillStyle = color;
1423
- ctx.beginPath();
1424
- ctx.arc(cx, cy, r3.w / 2, 0, Math.PI * 2);
1425
- ctx.fill();
1482
+ const hy = cy - w * PIN_HEAD_Y;
1483
+ const rad = w * PIN_HEAD_R;
1484
+ if (!bare) {
1485
+ ctx.fillStyle = color;
1486
+ ctx.beginPath();
1487
+ ctx.arc(cx, cy, r3.w / 2, 0, Math.PI * 2);
1488
+ ctx.fill();
1489
+ }
1426
1490
  ctx.fillStyle = glyph;
1427
1491
  ctx.beginPath();
1428
- ctx.moveTo(cx, cy + r3.w * PIN_TIP_Y);
1492
+ ctx.moveTo(cx, cy + w * PIN_TIP_Y);
1429
1493
  ctx.arc(cx, hy, rad, Math.PI * ARC_START, Math.PI * ARC_END);
1430
1494
  ctx.closePath();
1431
1495
  ctx.fill();
@@ -1462,7 +1526,7 @@ function drawMarks(ctx, f, radius) {
1462
1526
  ctx.arc(b.x, b.y, b.r, 0, Math.PI * 2);
1463
1527
  ctx.fill();
1464
1528
  });
1465
- f.icons.forEach((i) => i.kind === void 0 ? drawPin(ctx, i.rect, i.color, i.glyph) : drawRowIcon(ctx, i.rect, i.kind, { fill: i.color, glyph: i.glyph }));
1529
+ f.icons.forEach((i) => i.kind === void 0 ? drawPin(ctx, i.rect, { color: i.color, glyph: i.glyph }, i.bare) : drawRowIcon(ctx, i.rect, i.kind, { fill: i.color, glyph: i.glyph }));
1466
1530
  ctx.textAlign = "left";
1467
1531
  ctx.textBaseline = "top";
1468
1532
  f.texts.forEach((t) => {
@@ -1520,6 +1584,9 @@ function placeOnPage(doc, assets, fitted, frame) {
1520
1584
  if (picture && dividers?.toPicture === true) {
1521
1585
  reachPicture(fitted.body.rules, picture, dividers.reach ?? 0);
1522
1586
  }
1587
+ if (dividers?.lengths !== void 0) {
1588
+ stepRules(fitted.body.rules, dividers.lengths, frame.u);
1589
+ }
1523
1590
  return { image, region, picture };
1524
1591
  }
1525
1592
  function drawLogo(ctx, doc, assets, fitted) {