@dloizides/poster-render 0.7.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
 
@@ -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,16 @@ 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" } } },
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)
223
237
  }
224
238
  };
225
239
  var overlapSchema = {
@@ -233,7 +247,12 @@ var headerTuningSchema = {
233
247
  titleScriptGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
234
248
  scriptTitleGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
235
249
  titleScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
236
- 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)
237
256
  };
238
257
 
239
258
  // src/schema/flierDocSchema.ts
@@ -793,6 +812,7 @@ var BOLD = 700;
793
812
  var SEMI = 600;
794
813
  var MEDIUM = 500;
795
814
  var SCRIPT = 400;
815
+ var LABEL_TIE = -1;
796
816
  var SIZE = {
797
817
  title: 250,
798
818
  headerScript: 120,
@@ -817,7 +837,7 @@ var GAP = {
817
837
  rule: 8,
818
838
  divider: 24
819
839
  };
820
- var makers = (p, u, sc) => ({
840
+ var makers = (p, u, sc, timeWeight = SEMI) => ({
821
841
  display: (text2, size, key) => styled({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }, key, sc),
822
842
  venue: (text2, size, key) => styled({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }, key, sc),
823
843
  bodyVenue: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
@@ -825,16 +845,18 @@ var makers = (p, u, sc) => ({
825
845
  strong: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
826
846
  accent: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }, key, sc),
827
847
  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)
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)
829
850
  });
830
851
  function headerGroups(doc, p, u) {
831
852
  const l = makers(p, u, styleContext(doc));
832
853
  const b = doc.blocks;
833
854
  const t = doc.tuning;
834
855
  const gap = (line, after) => after === void 0 ? line : { ...line, gapAfter: after * u };
835
- const title = gap(l.display(b.title, SIZE.title * (t?.titleScale ?? 1), "title"), b.script ?? b.titleBottom ? t?.titleScriptGap : void 0);
836
- const script = b.script ? gap(l.script(b.script, SIZE.headerScript, "script"), b.titleBottom ? t?.scriptTitleGap : void 0) : void 0;
837
- 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];
838
860
  return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
839
861
  }
840
862
  function itemGroup(item, n, l, scale) {
@@ -873,6 +895,12 @@ function wrapped(line, wrap) {
873
895
  const parts = wrap ? halves(line.text) : [line.text];
874
896
  return parts.map((text2, i) => i === 0 ? { ...line, text: text2 } : { ...line, text: text2, bullet: void 0, hang: line.bullet !== void 0 });
875
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
+ }
876
904
  function eventGroups(doc, l, u, options) {
877
905
  const b = doc.blocks;
878
906
  const groups = [];
@@ -881,7 +909,7 @@ function eventGroups(doc, l, u, options) {
881
909
  const lastRow = schedule2.length + prices.length - 1;
882
910
  const icons2 = doc.rows?.icons;
883
911
  schedule2.forEach((row, i) => {
884
- 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);
885
913
  groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1, ...options.marks(icons2?.schedule, i, i === lastRow) });
886
914
  });
887
915
  prices.forEach((row, i) => {
@@ -903,7 +931,7 @@ function flankPriceGroups(doc, p, u) {
903
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 }));
904
932
  }
905
933
  function bodyGroups(doc, p, u, options = {}) {
906
- const l = makers(p, u, styleContext(doc));
934
+ const l = makers(p, u, styleContext(doc), doc.rows?.timeWeight);
907
935
  const b = doc.blocks;
908
936
  const groups = [];
909
937
  const isList = doc.layout === "list" /* List */;
@@ -912,7 +940,8 @@ function bodyGroups(doc, p, u, options = {}) {
912
940
  const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
913
941
  const look = doc.rows?.venue;
914
942
  const line = look?.body === true ? l.bodyVenue : l.venue;
915
- 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 });
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 });
916
945
  }
917
946
  groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, { ...options, marks: rowMarks(doc, p, u) }));
918
947
  if (b.includes) {
@@ -1251,10 +1280,29 @@ function closeHeaderGap(geo, head, gap, u) {
1251
1280
  const top = Math.round(Math.max(...head.texts.map((t) => t.box.y + t.box.h)) + gap * u);
1252
1281
  return top < body.y ? { ...geo, body: { ...body, y: top, h: body.h + body.y - top } } : geo;
1253
1282
  }
1254
- 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) {
1255
1302
  const { doc, palette, fonts } = input;
1256
1303
  const u = Math.min(input.width, input.height) / BASE;
1257
- 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);
1258
1306
  const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
1259
1307
  const flanks = geo.flanks ?? [];
1260
1308
  const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
@@ -1350,6 +1398,11 @@ function reachPicture(rules, picture, reach) {
1350
1398
  r3.rect.w = Math.max(0, end - r3.rect.x);
1351
1399
  });
1352
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
+ }
1353
1406
 
1354
1407
  // src/render/rowIcons.ts
1355
1408
  var LINE2 = 0.03;
@@ -1531,6 +1584,9 @@ function placeOnPage(doc, assets, fitted, frame) {
1531
1584
  if (picture && dividers?.toPicture === true) {
1532
1585
  reachPicture(fitted.body.rules, picture, dividers.reach ?? 0);
1533
1586
  }
1587
+ if (dividers?.lengths !== void 0) {
1588
+ stepRules(fitted.body.rules, dividers.lengths, frame.u);
1589
+ }
1534
1590
  return { image, region, picture };
1535
1591
  }
1536
1592
  function drawLogo(ctx, doc, assets, fitted) {