@dloizides/poster-render 0.3.0 → 0.4.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
@@ -101,6 +101,9 @@ var MAX_ITEMS = 8;
101
101
  var MAX_PRICES = 4;
102
102
  var MAX_VENUE = 3;
103
103
  var MIN_SCALE = 0.3;
104
+ var MAX_HEADER_GAP = 200;
105
+ var MIN_DATE_SCALE = 0.5;
106
+ var MAX_DATE_SCALE = 2;
104
107
  var text = (maxLength) => ({ type: "string", minLength: 1, maxLength });
105
108
  var scheduleRow = {
106
109
  type: "object",
@@ -166,6 +169,14 @@ var flierDocSchema = {
166
169
  },
167
170
  logo: { type: "object", required: ["imageId"], additionalProperties: false, properties: { imageId: text(SHORT) } },
168
171
  blocks,
172
+ tuning: {
173
+ type: "object",
174
+ additionalProperties: false,
175
+ properties: {
176
+ headerGap: { type: "number", minimum: 0, maximum: MAX_HEADER_GAP },
177
+ itemDateScale: { type: "number", minimum: MIN_DATE_SCALE, maximum: MAX_DATE_SCALE }
178
+ }
179
+ },
169
180
  items: {
170
181
  type: "array",
171
182
  minItems: 1,
@@ -515,8 +526,8 @@ function headerGroups(doc, p, u) {
515
526
  const lines = [l.display(b.title, SIZE.title), b.script ? l.script(b.script, SIZE.headerScript) : void 0, b.titleBottom ? l.display(b.titleBottom, SIZE.title) : void 0];
516
527
  return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
517
528
  }
518
- function itemGroup(item, l, u) {
519
- const lines = [l.script(item.date, SIZE.itemDate)];
529
+ function itemGroup(item, l, u, dateScale) {
530
+ const lines = [l.script(item.date, SIZE.itemDate * dateScale)];
520
531
  item.schedule.forEach((row) => lines.push(l.strong(`${row.label} ${row.time}`, SIZE.itemRow)));
521
532
  if (item.price) {
522
533
  lines.push(l.accent(item.price, SIZE.itemRow));
@@ -552,8 +563,8 @@ function eventGroups(doc, l, u, options) {
552
563
  });
553
564
  return groups;
554
565
  }
555
- function listGroups(doc, l, u) {
556
- const groups = (doc.items ?? []).map((item) => itemGroup(item, l, u));
566
+ function listGroups(doc, l, u, dateScale) {
567
+ const groups = (doc.items ?? []).map((item) => itemGroup(item, l, u, dateScale));
557
568
  const prices = doc.blocks.prices?.map((row) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice)) ?? [];
558
569
  if (prices.length > 0) {
559
570
  groups.push({ lines: prices, gapAfter: GAP.row * u });
@@ -574,7 +585,7 @@ function bodyGroups(doc, p, u, options = {}) {
574
585
  const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
575
586
  groups.push({ lines: b.venue.map((v) => l.venue(v, size)), gapAfter: GAP.venue * u, rule: { color: p.accent, height: GAP.rule * u }, ruleBelow: true, icon: { color: p.accent, glyph: p.background }, keepWithNext });
576
587
  }
577
- groups.push(...isList ? listGroups(doc, l, u) : eventGroups(doc, l, u, options));
588
+ groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, options));
578
589
  if (b.includes) {
579
590
  const lines = [l.accent(b.includes.heading, SIZE.small), ...b.includes.items.map((i) => l.item(i, SIZE.small))].flatMap((line) => wrapped(line, options.wrap));
580
591
  groups.push({ lines, gapAfter: GAP.includes * u, uniform: true, keepWithNext: b.footer !== void 0, attachNext: b.footer !== void 0 });
@@ -816,15 +827,25 @@ function splitHeader(header, hasLogo) {
816
827
  const logoW = hasLogo ? Math.round(header.w * LOGO_SHARE) : 0;
817
828
  return { text: { ...header, w: header.w - logoW * 1.1 }, logo: { ...header, x: header.x + header.w - logoW, w: logoW } };
818
829
  }
830
+ function closeHeaderGap(geo, head, gap, u) {
831
+ const { header, body } = geo;
832
+ const stacked = header.y + header.h <= body.y && header.x < body.x + body.w && body.x < header.x + header.w;
833
+ if (gap === void 0 || !stacked || head.texts.length === 0) {
834
+ return geo;
835
+ }
836
+ const top = Math.round(Math.max(...head.texts.map((t) => t.box.y + t.box.h)) + gap * u);
837
+ return top < body.y ? { ...geo, body: { ...body, y: top, h: body.h + body.y - top } } : geo;
838
+ }
819
839
  function flowAll(ctx, input, geo, reflow) {
820
840
  const { doc, palette, fonts } = input;
821
841
  const u = Math.min(input.width, input.height) / BASE;
822
842
  const zones = geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0);
823
843
  const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
824
844
  const flanks = geo.flanks ?? [];
825
- const body = flow(ctx, bodyGroups(doc, palette, u, { withPrices: flanks.length === 0, compact: reflow.compact, wrap: reflow.wrap }), geo.body, fonts);
845
+ const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
846
+ const body = flow(ctx, bodyGroups(doc, palette, u, { withPrices: flanks.length === 0, compact: reflow.compact, wrap: reflow.wrap, dateScale: doc.tuning?.itemDateScale }), tight.body, fonts);
826
847
  const sides = flanks.length > 0 ? equalFlanks(ctx, flankPriceGroups(doc, palette, u), flanks, fonts) : [emptyFlow()];
827
- return { geo, zones, head, body, sides };
848
+ return { geo: tight, zones, head, body, sides };
828
849
  }
829
850
  var smallest = (t) => Math.min(Infinity, ...[t.head, t.body, ...t.sides].flatMap((f) => f.texts.map((x) => x.box.h / LINE_HEIGHT3)));
830
851
  function shiftHeader(geo, shift) {