@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.d.mts CHANGED
@@ -129,7 +129,7 @@ interface PictureOverlap {
129
129
  dx: number;
130
130
  dy: number;
131
131
  }
132
- /** Row icon discs and divider rules; a short icon list repeats its last icon; px at a 1080 short edge. */
132
+ /** Row icon discs, divider rules, price label scale and venue face/pin; a short icon list repeats its last icon; px at a 1080 short edge. */
133
133
  interface RowTheme {
134
134
  icons?: {
135
135
  schedule?: RowIcon[];
@@ -142,7 +142,18 @@ interface RowTheme {
142
142
  gap?: number;
143
143
  toPicture?: boolean;
144
144
  reach?: number;
145
+ lengths?: number[];
145
146
  };
147
+ priceLabelScale?: number;
148
+ venue?: {
149
+ body?: boolean;
150
+ bare?: boolean;
151
+ oneLine?: boolean;
152
+ };
153
+ labelScale?: number;
154
+ timeScale?: number;
155
+ timeWeight?: number;
156
+ textWidth?: number;
146
157
  }
147
158
  interface LogoSlot {
148
159
  imageId: string;
@@ -189,6 +200,11 @@ interface PosterTuning {
189
200
  scriptTitleGap?: number;
190
201
  titleScale?: number;
191
202
  titleBottomScale?: number;
203
+ headerTextWidth?: number;
204
+ bodyTop?: number;
205
+ headerHeight?: number;
206
+ titleSpacing?: number;
207
+ scriptScale?: number;
192
208
  }
193
209
  interface Rect {
194
210
  x: number;
package/dist/index.d.ts CHANGED
@@ -129,7 +129,7 @@ interface PictureOverlap {
129
129
  dx: number;
130
130
  dy: number;
131
131
  }
132
- /** Row icon discs and divider rules; a short icon list repeats its last icon; px at a 1080 short edge. */
132
+ /** Row icon discs, divider rules, price label scale and venue face/pin; a short icon list repeats its last icon; px at a 1080 short edge. */
133
133
  interface RowTheme {
134
134
  icons?: {
135
135
  schedule?: RowIcon[];
@@ -142,7 +142,18 @@ interface RowTheme {
142
142
  gap?: number;
143
143
  toPicture?: boolean;
144
144
  reach?: number;
145
+ lengths?: number[];
145
146
  };
147
+ priceLabelScale?: number;
148
+ venue?: {
149
+ body?: boolean;
150
+ bare?: boolean;
151
+ oneLine?: boolean;
152
+ };
153
+ labelScale?: number;
154
+ timeScale?: number;
155
+ timeWeight?: number;
156
+ textWidth?: number;
146
157
  }
147
158
  interface LogoSlot {
148
159
  imageId: string;
@@ -189,6 +200,11 @@ interface PosterTuning {
189
200
  scriptTitleGap?: number;
190
201
  titleScale?: number;
191
202
  titleBottomScale?: number;
203
+ headerTextWidth?: number;
204
+ bodyTop?: number;
205
+ headerHeight?: number;
206
+ titleSpacing?: number;
207
+ scriptScale?: number;
192
208
  }
193
209
  interface Rect {
194
210
  x: number;
package/dist/index.js CHANGED
@@ -182,7 +182,7 @@ var FONT_SETS = {
182
182
  ["classic" /* Classic */]: { display: '"Oswald", "Arial Narrow", sans-serif', script: '"Sacramento", cursive', body: '"Fredoka", sans-serif' },
183
183
  ["modern" /* Modern */]: { display: '"Bebas Neue", "Arial Narrow", sans-serif', script: '"Great Vibes", cursive', body: '"Montserrat", sans-serif' },
184
184
  ["elegant" /* Elegant */]: { display: '"Playfair Display", serif', script: '"Allura", cursive', body: '"Lato", sans-serif' },
185
- ["kizomba-sample" /* KizombaSample */]: { display: '"Anton", "Oswald", "Arial Narrow", sans-serif', script: '"Sacramento", cursive', body: '"Barlow Semi Condensed", "Fredoka", sans-serif' },
185
+ ["kizomba-sample" /* KizombaSample */]: { display: '"Anton", "Oswald", "Arial Narrow", sans-serif', script: '"Dancing Script", "Sacramento", cursive', body: '"Barlow Semi Condensed", "Fredoka", sans-serif' },
186
186
  ["coastal" /* Coastal */]: { display: '"Fraunces", Georgia, serif', script: '"Allura", cursive', body: '"Jost", sans-serif' }
187
187
  };
188
188
 
@@ -200,6 +200,16 @@ var MAX_TOP = 600;
200
200
  var MAX_LINE_GAP = 200;
201
201
  var MIN_TITLE_SCALE = 0.3;
202
202
  var MAX_TITLE_SCALE = 2.5;
203
+ var MIN_LABEL_SCALE = 0.3;
204
+ var MAX_ROW_SCALE = 2;
205
+ var MIN_WEIGHT = 100;
206
+ var MAX_WEIGHT = 900;
207
+ var MIN_WIDTH = 100;
208
+ var MAX_LENGTH = 1080;
209
+ var MAX_BODY_TOP = 1920;
210
+ var MAX_LENGTHS = 12;
211
+ var MIN_SPACING2 = -0.2;
212
+ var MAX_SPACING2 = 0.5;
203
213
  var num = (minimum, maximum) => ({ type: "number", minimum, maximum });
204
214
  var icons = (maxItems) => ({ type: "array", items: { type: "string", enum: Object.values(RowIcon) }, minItems: 1, maxItems });
205
215
  var rowsSchema = {
@@ -216,9 +226,16 @@ var rowsSchema = {
216
226
  color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
217
227
  gap: num(0, MAX_GAP),
218
228
  toPicture: { type: "boolean" },
219
- reach: num(0, 1)
229
+ reach: num(0, 1),
230
+ lengths: { type: "array", items: num(0, MAX_LENGTH), minItems: 1, maxItems: MAX_LENGTHS }
220
231
  }
221
- }
232
+ },
233
+ priceLabelScale: num(MIN_LABEL_SCALE, 1),
234
+ venue: { type: "object", additionalProperties: false, properties: { body: { type: "boolean" }, bare: { type: "boolean" }, oneLine: { type: "boolean" } } },
235
+ labelScale: num(MIN_LABEL_SCALE, MAX_ROW_SCALE),
236
+ timeScale: num(MIN_LABEL_SCALE, MAX_ROW_SCALE),
237
+ timeWeight: num(MIN_WEIGHT, MAX_WEIGHT),
238
+ textWidth: num(MIN_WIDTH, MAX_LENGTH)
222
239
  }
223
240
  };
224
241
  var overlapSchema = {
@@ -232,7 +249,12 @@ var headerTuningSchema = {
232
249
  titleScriptGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
233
250
  scriptTitleGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
234
251
  titleScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
235
- titleBottomScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE)
252
+ titleBottomScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
253
+ headerTextWidth: num(MIN_WIDTH, MAX_LENGTH),
254
+ bodyTop: num(0, MAX_BODY_TOP),
255
+ headerHeight: num(MIN_WIDTH, MAX_BODY_TOP),
256
+ titleSpacing: num(MIN_SPACING2, MAX_SPACING2),
257
+ scriptScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE)
236
258
  };
237
259
 
238
260
  // src/schema/flierDocSchema.ts
@@ -792,6 +814,7 @@ var BOLD = 700;
792
814
  var SEMI = 600;
793
815
  var MEDIUM = 500;
794
816
  var SCRIPT = 400;
817
+ var LABEL_TIE = -1;
795
818
  var SIZE = {
796
819
  title: 250,
797
820
  headerScript: 120,
@@ -816,23 +839,26 @@ var GAP = {
816
839
  rule: 8,
817
840
  divider: 24
818
841
  };
819
- var makers = (p, u, sc) => ({
842
+ var makers = (p, u, sc, timeWeight = SEMI) => ({
820
843
  display: (text2, size, key) => styled({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }, key, sc),
821
844
  venue: (text2, size, key) => styled({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }, key, sc),
845
+ bodyVenue: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
822
846
  script: (text2, size, key) => styled({ text: text2, role: "script", weight: SCRIPT, size: size * u, color: p.script ?? p.accent }, key, sc),
823
847
  strong: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
824
848
  accent: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }, key, sc),
825
849
  item: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }, key, sc),
826
- soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc)
850
+ soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc),
851
+ time: (text2, size, key) => styled({ text: text2, role: "body", weight: timeWeight, size: size * u, color: p.accent }, key, sc)
827
852
  });
828
853
  function headerGroups(doc, p, u) {
829
854
  const l = makers(p, u, styleContext(doc));
830
855
  const b = doc.blocks;
831
856
  const t = doc.tuning;
832
857
  const gap = (line, after) => after === void 0 ? line : { ...line, gapAfter: after * u };
833
- const title = gap(l.display(b.title, SIZE.title * (t?.titleScale ?? 1), "title"), b.script ?? b.titleBottom ? t?.titleScriptGap : void 0);
834
- const script = b.script ? gap(l.script(b.script, SIZE.headerScript, "script"), b.titleBottom ? t?.scriptTitleGap : void 0) : void 0;
835
- const lines = [title, script, b.titleBottom ? l.display(b.titleBottom, SIZE.title * (t?.titleBottomScale ?? 1), "titleBottom") : void 0];
858
+ const spaced = (line) => t?.titleSpacing === void 0 || line.spacing !== void 0 ? line : { ...line, spacing: t.titleSpacing };
859
+ const title = gap(spaced(l.display(b.title, SIZE.title * (t?.titleScale ?? 1), "title")), b.script ?? b.titleBottom ? t?.titleScriptGap : void 0);
860
+ const script = b.script ? gap(l.script(b.script, SIZE.headerScript * (t?.scriptScale ?? 1), "script"), b.titleBottom ? t?.scriptTitleGap : void 0) : void 0;
861
+ const lines = [title, script, b.titleBottom ? spaced(l.display(b.titleBottom, SIZE.title * (t?.titleBottomScale ?? 1), "titleBottom")) : void 0];
836
862
  return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
837
863
  }
838
864
  function itemGroup(item, n, l, scale) {
@@ -871,6 +897,12 @@ function wrapped(line, wrap) {
871
897
  const parts = wrap ? halves(line.text) : [line.text];
872
898
  return parts.map((text2, i) => i === 0 ? { ...line, text: text2 } : { ...line, text: text2, bullet: void 0, hang: line.bullet !== void 0 });
873
899
  }
900
+ function scheduleLines(doc, l, row, i) {
901
+ const r3 = doc.rows;
902
+ const label = l.strong(row.label, SIZE.scheduleLabel * (r3?.labelScale ?? 1), `schedule.${i}.label`);
903
+ const tied = r3?.labelScale === void 0 ? label : { ...label, sizeTie: label.sizeTie ?? LABEL_TIE };
904
+ return [tied, l.time(row.time, SIZE.scheduleTime * (r3?.timeScale ?? 1), `schedule.${i}.time`)];
905
+ }
874
906
  function eventGroups(doc, l, u, options) {
875
907
  const b = doc.blocks;
876
908
  const groups = [];
@@ -879,11 +911,11 @@ function eventGroups(doc, l, u, options) {
879
911
  const lastRow = schedule2.length + prices.length - 1;
880
912
  const icons2 = doc.rows?.icons;
881
913
  schedule2.forEach((row, i) => {
882
- 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`)];
914
+ const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`)] : scheduleLines(doc, l, row, i);
883
915
  groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1, ...options.marks(icons2?.schedule, i, i === lastRow) });
884
916
  });
885
917
  prices.forEach((row, i) => {
886
- 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`)];
918
+ 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`)];
887
919
  groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1, ...options.marks(icons2?.prices, i, schedule2.length + i === lastRow) });
888
920
  });
889
921
  return groups;
@@ -901,14 +933,17 @@ function flankPriceGroups(doc, p, u) {
901
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 }));
902
934
  }
903
935
  function bodyGroups(doc, p, u, options = {}) {
904
- const l = makers(p, u, styleContext(doc));
936
+ const l = makers(p, u, styleContext(doc), doc.rows?.timeWeight);
905
937
  const b = doc.blocks;
906
938
  const groups = [];
907
939
  const isList = doc.layout === "list" /* List */;
908
940
  if (b.venue) {
909
941
  const size = isList ? SIZE.listVenue : SIZE.venue;
910
942
  const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
911
- 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 });
943
+ const look = doc.rows?.venue;
944
+ const line = look?.body === true ? l.bodyVenue : l.venue;
945
+ const venue = look?.oneLine === true ? [b.venue.join(" ")] : b.venue;
946
+ 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 });
912
947
  }
913
948
  groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, { ...options, marks: rowMarks(doc, p, u) }));
914
949
  if (b.includes) {
@@ -1025,7 +1060,7 @@ function placeIcon(group, box, out) {
1025
1060
  return bottom2;
1026
1061
  }
1027
1062
  const textH = bottom2 - top;
1028
- 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 });
1063
+ 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 });
1029
1064
  return top + Math.max(textH, d);
1030
1065
  }
1031
1066
  function placeGroup(m, at, out) {
@@ -1247,10 +1282,29 @@ function closeHeaderGap(geo, head, gap, u) {
1247
1282
  const top = Math.round(Math.max(...head.texts.map((t) => t.box.y + t.box.h)) + gap * u);
1248
1283
  return top < body.y ? { ...geo, body: { ...body, y: top, h: body.h + body.y - top } } : geo;
1249
1284
  }
1250
- function flowAll(ctx, input, geo, reflow) {
1285
+ function tunedGeo(geo, doc, u) {
1286
+ const top = doc.tuning?.bodyTop;
1287
+ const width = doc.rows?.textWidth;
1288
+ let { header, body } = geo;
1289
+ if (top !== void 0) {
1290
+ const y = Math.round(top * u);
1291
+ header = { ...header, h: Math.max(1, y - header.y) };
1292
+ body = { ...body, y, h: Math.max(1, body.y + body.h - y) };
1293
+ }
1294
+ if (width !== void 0) {
1295
+ body = { ...body, w: Math.round(width * u) };
1296
+ }
1297
+ return { ...geo, header, body };
1298
+ }
1299
+ function widened(zones, size, u) {
1300
+ const { text: text2 } = zones;
1301
+ 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) } };
1302
+ }
1303
+ function flowAll(ctx, input, base2, reflow) {
1251
1304
  const { doc, palette, fonts } = input;
1252
1305
  const u = Math.min(input.width, input.height) / BASE;
1253
- const zones = headerAt(geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0), doc.tuning?.headerTop, u);
1306
+ const geo = tunedGeo(base2, doc, u);
1307
+ 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);
1254
1308
  const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
1255
1309
  const flanks = geo.flanks ?? [];
1256
1310
  const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
@@ -1346,6 +1400,11 @@ function reachPicture(rules, picture, reach) {
1346
1400
  r3.rect.w = Math.max(0, end - r3.rect.x);
1347
1401
  });
1348
1402
  }
1403
+ function stepRules(rules, lengths, u) {
1404
+ rules.forEach((r3, i) => {
1405
+ r3.rect.w = (lengths[Math.min(i, lengths.length - 1)] ?? 0) * u;
1406
+ });
1407
+ }
1349
1408
 
1350
1409
  // src/render/rowIcons.ts
1351
1410
  var LINE2 = 0.03;
@@ -1416,18 +1475,23 @@ var PIN_TIP_Y = 0.28;
1416
1475
  var PIN_HOLE = 0.42;
1417
1476
  var ARC_START = 0.75;
1418
1477
  var ARC_END = 2.25;
1419
- function drawPin(ctx, r3, color, glyph) {
1478
+ var BARE_SCALE = 1.6;
1479
+ function drawPin(ctx, r3, colors, bare = false) {
1480
+ const { color, glyph } = bare ? { color: colors.glyph, glyph: colors.color } : colors;
1481
+ const w = bare ? r3.w * BARE_SCALE : r3.w;
1420
1482
  const cx = r3.x + r3.w / 2;
1421
1483
  const cy = r3.y + r3.h / 2;
1422
- const hy = cy - r3.w * PIN_HEAD_Y;
1423
- const rad = r3.w * PIN_HEAD_R;
1424
- ctx.fillStyle = color;
1425
- ctx.beginPath();
1426
- ctx.arc(cx, cy, r3.w / 2, 0, Math.PI * 2);
1427
- ctx.fill();
1484
+ const hy = cy - w * PIN_HEAD_Y;
1485
+ const rad = w * PIN_HEAD_R;
1486
+ if (!bare) {
1487
+ ctx.fillStyle = color;
1488
+ ctx.beginPath();
1489
+ ctx.arc(cx, cy, r3.w / 2, 0, Math.PI * 2);
1490
+ ctx.fill();
1491
+ }
1428
1492
  ctx.fillStyle = glyph;
1429
1493
  ctx.beginPath();
1430
- ctx.moveTo(cx, cy + r3.w * PIN_TIP_Y);
1494
+ ctx.moveTo(cx, cy + w * PIN_TIP_Y);
1431
1495
  ctx.arc(cx, hy, rad, Math.PI * ARC_START, Math.PI * ARC_END);
1432
1496
  ctx.closePath();
1433
1497
  ctx.fill();
@@ -1464,7 +1528,7 @@ function drawMarks(ctx, f, radius) {
1464
1528
  ctx.arc(b.x, b.y, b.r, 0, Math.PI * 2);
1465
1529
  ctx.fill();
1466
1530
  });
1467
- 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 }));
1531
+ 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 }));
1468
1532
  ctx.textAlign = "left";
1469
1533
  ctx.textBaseline = "top";
1470
1534
  f.texts.forEach((t) => {
@@ -1522,6 +1586,9 @@ function placeOnPage(doc, assets, fitted, frame) {
1522
1586
  if (picture && dividers?.toPicture === true) {
1523
1587
  reachPicture(fitted.body.rules, picture, dividers.reach ?? 0);
1524
1588
  }
1589
+ if (dividers?.lengths !== void 0) {
1590
+ stepRules(fitted.body.rules, dividers.lengths, frame.u);
1591
+ }
1525
1592
  return { image, region, picture };
1526
1593
  }
1527
1594
  function drawLogo(ctx, doc, assets, fitted) {