@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 CHANGED
@@ -142,12 +142,23 @@ interface RowTheme {
142
142
  gap?: number;
143
143
  toPicture?: boolean;
144
144
  reach?: number;
145
+ lengths?: number[];
145
146
  };
146
147
  priceLabelScale?: number;
147
148
  venue?: {
148
149
  body?: boolean;
149
150
  bare?: boolean;
151
+ oneLine?: boolean;
152
+ pinSize?: number;
153
+ pinGap?: number;
154
+ pinShift?: number;
155
+ centred?: boolean;
150
156
  };
157
+ priceGap?: number;
158
+ labelScale?: number;
159
+ timeScale?: number;
160
+ timeWeight?: number;
161
+ textWidth?: number;
151
162
  }
152
163
  interface LogoSlot {
153
164
  imageId: string;
@@ -194,6 +205,11 @@ interface PosterTuning {
194
205
  scriptTitleGap?: number;
195
206
  titleScale?: number;
196
207
  titleBottomScale?: number;
208
+ headerTextWidth?: number;
209
+ bodyTop?: number;
210
+ headerHeight?: number;
211
+ titleSpacing?: number;
212
+ scriptScale?: number;
197
213
  }
198
214
  interface Rect {
199
215
  x: number;
package/dist/index.d.ts CHANGED
@@ -142,12 +142,23 @@ interface RowTheme {
142
142
  gap?: number;
143
143
  toPicture?: boolean;
144
144
  reach?: number;
145
+ lengths?: number[];
145
146
  };
146
147
  priceLabelScale?: number;
147
148
  venue?: {
148
149
  body?: boolean;
149
150
  bare?: boolean;
151
+ oneLine?: boolean;
152
+ pinSize?: number;
153
+ pinGap?: number;
154
+ pinShift?: number;
155
+ centred?: boolean;
150
156
  };
157
+ priceGap?: number;
158
+ labelScale?: number;
159
+ timeScale?: number;
160
+ timeWeight?: number;
161
+ textWidth?: number;
151
162
  }
152
163
  interface LogoSlot {
153
164
  imageId: string;
@@ -194,6 +205,11 @@ interface PosterTuning {
194
205
  scriptTitleGap?: number;
195
206
  titleScale?: number;
196
207
  titleBottomScale?: number;
208
+ headerTextWidth?: number;
209
+ bodyTop?: number;
210
+ headerHeight?: number;
211
+ titleSpacing?: number;
212
+ scriptScale?: number;
197
213
  }
198
214
  interface Rect {
199
215
  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: '"Style Script", "Dancing Script", 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
 
@@ -201,6 +201,15 @@ var MAX_LINE_GAP = 200;
201
201
  var MIN_TITLE_SCALE = 0.3;
202
202
  var MAX_TITLE_SCALE = 2.5;
203
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;
204
213
  var num = (minimum, maximum) => ({ type: "number", minimum, maximum });
205
214
  var icons = (maxItems) => ({ type: "array", items: { type: "string", enum: Object.values(RowIcon) }, minItems: 1, maxItems });
206
215
  var rowsSchema = {
@@ -217,11 +226,17 @@ var rowsSchema = {
217
226
  color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
218
227
  gap: num(0, MAX_GAP),
219
228
  toPicture: { type: "boolean" },
220
- reach: num(0, 1)
229
+ reach: num(0, 1),
230
+ lengths: { type: "array", items: num(0, MAX_LENGTH), minItems: 1, maxItems: MAX_LENGTHS }
221
231
  }
222
232
  },
223
233
  priceLabelScale: num(MIN_LABEL_SCALE, 1),
224
- venue: { type: "object", additionalProperties: false, properties: { body: { type: "boolean" }, bare: { type: "boolean" } } }
234
+ 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" } } },
235
+ priceGap: num(-MAX_GAP, MAX_GAP),
236
+ labelScale: num(MIN_LABEL_SCALE, MAX_ROW_SCALE),
237
+ timeScale: num(MIN_LABEL_SCALE, MAX_ROW_SCALE),
238
+ timeWeight: num(MIN_WEIGHT, MAX_WEIGHT),
239
+ textWidth: num(MIN_WIDTH, MAX_LENGTH)
225
240
  }
226
241
  };
227
242
  var overlapSchema = {
@@ -235,7 +250,12 @@ var headerTuningSchema = {
235
250
  titleScriptGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
236
251
  scriptTitleGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
237
252
  titleScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
238
- titleBottomScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE)
253
+ titleBottomScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
254
+ headerTextWidth: num(MIN_WIDTH, MAX_LENGTH),
255
+ bodyTop: num(0, MAX_BODY_TOP),
256
+ headerHeight: num(MIN_WIDTH, MAX_BODY_TOP),
257
+ titleSpacing: num(MIN_SPACING2, MAX_SPACING2),
258
+ scriptScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE)
239
259
  };
240
260
 
241
261
  // src/schema/flierDocSchema.ts
@@ -795,6 +815,7 @@ var BOLD = 700;
795
815
  var SEMI = 600;
796
816
  var MEDIUM = 500;
797
817
  var SCRIPT = 400;
818
+ var LABEL_TIE = -1;
798
819
  var SIZE = {
799
820
  title: 250,
800
821
  headerScript: 120,
@@ -819,7 +840,7 @@ var GAP = {
819
840
  rule: 8,
820
841
  divider: 24
821
842
  };
822
- var makers = (p, u, sc) => ({
843
+ var makers = (p, u, sc, timeWeight = SEMI) => ({
823
844
  display: (text2, size, key) => styled({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }, key, sc),
824
845
  venue: (text2, size, key) => styled({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }, key, sc),
825
846
  bodyVenue: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
@@ -827,16 +848,18 @@ var makers = (p, u, sc) => ({
827
848
  strong: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
828
849
  accent: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }, key, sc),
829
850
  item: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }, key, sc),
830
- soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc)
851
+ soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc),
852
+ time: (text2, size, key) => styled({ text: text2, role: "body", weight: timeWeight, size: size * u, color: p.accent }, key, sc)
831
853
  });
832
854
  function headerGroups(doc, p, u) {
833
855
  const l = makers(p, u, styleContext(doc));
834
856
  const b = doc.blocks;
835
857
  const t = doc.tuning;
836
858
  const gap = (line, after) => after === void 0 ? line : { ...line, gapAfter: after * u };
837
- const title = gap(l.display(b.title, SIZE.title * (t?.titleScale ?? 1), "title"), b.script ?? b.titleBottom ? t?.titleScriptGap : void 0);
838
- const script = b.script ? gap(l.script(b.script, SIZE.headerScript, "script"), b.titleBottom ? t?.scriptTitleGap : void 0) : void 0;
839
- const lines = [title, script, b.titleBottom ? l.display(b.titleBottom, SIZE.title * (t?.titleBottomScale ?? 1), "titleBottom") : void 0];
859
+ const spaced = (line) => t?.titleSpacing === void 0 || line.spacing !== void 0 ? line : { ...line, spacing: t.titleSpacing };
860
+ const title = gap(spaced(l.display(b.title, SIZE.title * (t?.titleScale ?? 1), "title")), b.script ?? b.titleBottom ? t?.titleScriptGap : void 0);
861
+ const script = b.script ? gap(l.script(b.script, SIZE.headerScript * (t?.scriptScale ?? 1), "script"), b.titleBottom ? t?.scriptTitleGap : void 0) : void 0;
862
+ const lines = [title, script, b.titleBottom ? spaced(l.display(b.titleBottom, SIZE.title * (t?.titleBottomScale ?? 1), "titleBottom")) : void 0];
840
863
  return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
841
864
  }
842
865
  function itemGroup(item, n, l, scale) {
@@ -875,6 +898,13 @@ function wrapped(line, wrap) {
875
898
  const parts = wrap ? halves(line.text) : [line.text];
876
899
  return parts.map((text2, i) => i === 0 ? { ...line, text: text2 } : { ...line, text: text2, bullet: void 0, hang: line.bullet !== void 0 });
877
900
  }
901
+ function scheduleLines(doc, l, row, i) {
902
+ const r3 = doc.rows;
903
+ const label = l.strong(row.label, SIZE.scheduleLabel * (r3?.labelScale ?? 1), `schedule.${i}.label`);
904
+ const tied = r3?.labelScale === void 0 ? label : { ...label, sizeTie: label.sizeTie ?? LABEL_TIE };
905
+ return [tied, l.time(row.time, SIZE.scheduleTime * (r3?.timeScale ?? 1), `schedule.${i}.time`)];
906
+ }
907
+ var priceAmount = (doc, line) => doc.rows?.priceGap === void 0 ? line : { ...line, gapAfter: doc.rows.priceGap };
878
908
  function eventGroups(doc, l, u, options) {
879
909
  const b = doc.blocks;
880
910
  const groups = [];
@@ -883,11 +913,11 @@ function eventGroups(doc, l, u, options) {
883
913
  const lastRow = schedule2.length + prices.length - 1;
884
914
  const icons2 = doc.rows?.icons;
885
915
  schedule2.forEach((row, i) => {
886
- 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`)];
916
+ const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`)] : scheduleLines(doc, l, row, i);
887
917
  groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1, ...options.marks(icons2?.schedule, i, i === lastRow) });
888
918
  });
889
919
  prices.forEach((row, i) => {
890
- 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`)];
920
+ 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`)];
891
921
  groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1, ...options.marks(icons2?.prices, i, schedule2.length + i === lastRow) });
892
922
  });
893
923
  return groups;
@@ -904,8 +934,11 @@ function flankPriceGroups(doc, p, u) {
904
934
  const l = makers(p, u, styleContext(doc));
905
935
  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 }));
906
936
  }
937
+ function pinOf(look, u) {
938
+ 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 };
939
+ }
907
940
  function bodyGroups(doc, p, u, options = {}) {
908
- const l = makers(p, u, styleContext(doc));
941
+ const l = makers(p, u, styleContext(doc), doc.rows?.timeWeight);
909
942
  const b = doc.blocks;
910
943
  const groups = [];
911
944
  const isList = doc.layout === "list" /* List */;
@@ -914,7 +947,8 @@ function bodyGroups(doc, p, u, options = {}) {
914
947
  const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
915
948
  const look = doc.rows?.venue;
916
949
  const line = look?.body === true ? l.bodyVenue : l.venue;
917
- groups.push({ lines: b.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 });
950
+ const venue = look?.oneLine === true ? [b.venue.join(" ")] : b.venue;
951
+ 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 });
918
952
  }
919
953
  groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, { ...options, marks: rowMarks(doc, p, u) }));
920
954
  if (b.includes) {
@@ -944,7 +978,8 @@ var iconSize = (group, k) => {
944
978
  function groupBox(group, k, colW) {
945
979
  const pad = group.card ? group.card.pad * k : 0;
946
980
  const d = iconSize(group, k);
947
- const iconIndent = d > 0 ? d * (1 + ICON_GAP) : 0;
981
+ const gap = group.icon?.gap === void 0 ? d * ICON_GAP : group.icon.gap * k;
982
+ const iconIndent = d > 0 ? d + gap : 0;
948
983
  return { pad, d, iconIndent, avail: colW - 2 * pad - iconIndent };
949
984
  }
950
985
  function lineSize(line, width, k, avail) {
@@ -1031,7 +1066,7 @@ function placeIcon(group, box, out) {
1031
1066
  return bottom2;
1032
1067
  }
1033
1068
  const textH = bottom2 - top;
1034
- 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 });
1069
+ 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 });
1035
1070
  return top + Math.max(textH, d);
1036
1071
  }
1037
1072
  function placeGroup(m, at, out) {
@@ -1045,6 +1080,10 @@ function placeGroup(m, at, out) {
1045
1080
  const { pad, d, iconIndent } = groupBox(group, k, col.w);
1046
1081
  const top = y;
1047
1082
  y += pad;
1083
+ if (group.icon?.centre === true) {
1084
+ 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);
1085
+ y += Math.max(0, (d - textH) / 2);
1086
+ }
1048
1087
  group.lines.forEach((line, i) => {
1049
1088
  const size = sizes[i] ?? 0;
1050
1089
  const indent = (indented(line) ? line.size * k * BULLET_INDENT : 0) + iconIndent;
@@ -1253,10 +1292,29 @@ function closeHeaderGap(geo, head, gap, u) {
1253
1292
  const top = Math.round(Math.max(...head.texts.map((t) => t.box.y + t.box.h)) + gap * u);
1254
1293
  return top < body.y ? { ...geo, body: { ...body, y: top, h: body.h + body.y - top } } : geo;
1255
1294
  }
1256
- function flowAll(ctx, input, geo, reflow) {
1295
+ function tunedGeo(geo, doc, u) {
1296
+ const top = doc.tuning?.bodyTop;
1297
+ const width = doc.rows?.textWidth;
1298
+ let { header, body } = geo;
1299
+ if (top !== void 0) {
1300
+ const y = Math.round(top * u);
1301
+ header = { ...header, h: Math.max(1, y - header.y) };
1302
+ body = { ...body, y, h: Math.max(1, body.y + body.h - y) };
1303
+ }
1304
+ if (width !== void 0) {
1305
+ body = { ...body, w: Math.round(width * u) };
1306
+ }
1307
+ return { ...geo, header, body };
1308
+ }
1309
+ function widened(zones, size, u) {
1310
+ const { text: text2 } = zones;
1311
+ 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) } };
1312
+ }
1313
+ function flowAll(ctx, input, base2, reflow) {
1257
1314
  const { doc, palette, fonts } = input;
1258
1315
  const u = Math.min(input.width, input.height) / BASE;
1259
- const zones = headerAt(geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0), doc.tuning?.headerTop, u);
1316
+ const geo = tunedGeo(base2, doc, u);
1317
+ 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);
1260
1318
  const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
1261
1319
  const flanks = geo.flanks ?? [];
1262
1320
  const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
@@ -1352,6 +1410,11 @@ function reachPicture(rules, picture, reach) {
1352
1410
  r3.rect.w = Math.max(0, end - r3.rect.x);
1353
1411
  });
1354
1412
  }
1413
+ function stepRules(rules, lengths, u) {
1414
+ rules.forEach((r3, i) => {
1415
+ r3.rect.w = (lengths[Math.min(i, lengths.length - 1)] ?? 0) * u;
1416
+ });
1417
+ }
1355
1418
 
1356
1419
  // src/render/rowIcons.ts
1357
1420
  var LINE2 = 0.03;
@@ -1533,6 +1596,9 @@ function placeOnPage(doc, assets, fitted, frame) {
1533
1596
  if (picture && dividers?.toPicture === true) {
1534
1597
  reachPicture(fitted.body.rules, picture, dividers.reach ?? 0);
1535
1598
  }
1599
+ if (dividers?.lengths !== void 0) {
1600
+ stepRules(fitted.body.rules, dividers.lengths, frame.u);
1601
+ }
1536
1602
  return { image, region, picture };
1537
1603
  }
1538
1604
  function drawLogo(ctx, doc, assets, fitted) {