@dloizides/poster-render 0.10.0 → 0.11.1

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
@@ -181,10 +181,11 @@ interface FlierDoc {
181
181
  }
182
182
  /** A text line path such as "title", "venue.1", "schedule.0.time" or "items.2.date" (see LINE_KEY_PATTERN). */
183
183
  type LineKey = string;
184
- /** Optional per-line overrides of the theme; an absent field keeps the theme value. letterSpacing is in em. */
184
+ /** Optional per-line overrides of the theme; an absent field keeps the theme value. letterSpacing is in em; widthScale widens or narrows the room the line may fill. */
185
185
  interface LineStyle {
186
186
  font?: string;
187
187
  sizeScale?: number;
188
+ widthScale?: number;
188
189
  color?: string;
189
190
  weight?: number;
190
191
  italic?: boolean;
package/dist/index.d.ts CHANGED
@@ -181,10 +181,11 @@ interface FlierDoc {
181
181
  }
182
182
  /** A text line path such as "title", "venue.1", "schedule.0.time" or "items.2.date" (see LINE_KEY_PATTERN). */
183
183
  type LineKey = string;
184
- /** Optional per-line overrides of the theme; an absent field keeps the theme value. letterSpacing is in em. */
184
+ /** Optional per-line overrides of the theme; an absent field keeps the theme value. letterSpacing is in em; widthScale widens or narrows the room the line may fill. */
185
185
  interface LineStyle {
186
186
  font?: string;
187
187
  sizeScale?: number;
188
+ widthScale?: number;
188
189
  color?: string;
189
190
  weight?: number;
190
191
  italic?: boolean;
package/dist/index.js CHANGED
@@ -90,6 +90,8 @@ var LINE_KEY_PATTERN = "^(title|titleBottom|script|footer|includes[.]heading|inc
90
90
  var MAX_FONT = 40;
91
91
  var MIN_SIZE_SCALE = 0.25;
92
92
  var MAX_SIZE_SCALE = 3;
93
+ var MIN_WIDTH_SCALE = 0.5;
94
+ var MAX_WIDTH_SCALE = 1.5;
93
95
  var MIN_SPACING = -0.1;
94
96
  var MAX_SPACING = 0.5;
95
97
  var MAX_TIES = 12;
@@ -101,6 +103,7 @@ var lineStyle = {
101
103
  properties: {
102
104
  font: { type: "string", minLength: 1, maxLength: MAX_FONT, pattern: "^[A-Za-z0-9 ]+$" },
103
105
  sizeScale: { type: "number", minimum: MIN_SIZE_SCALE, maximum: MAX_SIZE_SCALE },
106
+ widthScale: { type: "number", minimum: MIN_WIDTH_SCALE, maximum: MAX_WIDTH_SCALE },
104
107
  color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
105
108
  weight: { type: "integer", enum: WEIGHTS },
106
109
  italic: { type: "boolean" },
@@ -805,6 +808,7 @@ function styled(line, key, sc) {
805
808
  family: style?.font,
806
809
  italic: style?.italic,
807
810
  spacing: style?.letterSpacing,
811
+ widthScale: style?.widthScale,
808
812
  align: style?.align,
809
813
  widthTie,
810
814
  sizeTie
@@ -987,8 +991,8 @@ function lineSize(line, width, k, avail) {
987
991
  const indent = bulletIndent(line, k);
988
992
  return Math.max(0, Math.min(line.size * k, line.size * (avail - indent) / Math.max(width, 1)));
989
993
  }
990
- function groupSizes(m, k, avail) {
991
- const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail));
994
+ function groupSizes(m, k, avail, spare) {
995
+ const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, Math.min(avail * (line.widthScale ?? 1), avail + spare)));
992
996
  if (!m.group.uniform) {
993
997
  return own;
994
998
  }
@@ -1003,7 +1007,7 @@ function tieMembers(all, k, colW, table, pick) {
1003
1007
  m.group.lines.forEach((line, i) => {
1004
1008
  const id = pick(line);
1005
1009
  if (id !== void 0) {
1006
- const member = { line, width: Math.max(m.widths[i] ?? 1, 1), cap: Math.max(0, avail - bulletIndent(line, k)), sizes, i };
1010
+ const member = { line, width: Math.max(m.widths[i] ?? 1, 1), cap: Math.max(0, Math.min(1, line.widthScale ?? 1) * avail - bulletIndent(line, k)), sizes, i };
1007
1011
  byId.set(id, [...byId.get(id) ?? [], member]);
1008
1012
  }
1009
1013
  });
@@ -1023,8 +1027,8 @@ function sameWidths(list) {
1023
1027
  x.sizes[x.i] = target * x.line.size / x.width;
1024
1028
  });
1025
1029
  }
1026
- function sizeTable(all, k, colW) {
1027
- const table = new Map(all.map((m) => [m, groupSizes(m, k, groupBox(m.group, k, colW).avail)]));
1030
+ function sizeTable(all, k, colW, room = colW) {
1031
+ const table = new Map(all.map((m) => [m, groupSizes(m, k, groupBox(m.group, k, colW).avail, Math.max(0, room - colW))]));
1028
1032
  tieMembers(all, k, colW, table, (line) => line.sizeTie).forEach(sameSizes);
1029
1033
  tieMembers(all, k, colW, table, (line) => line.widthTie).forEach(sameWidths);
1030
1034
  return table;
@@ -1049,7 +1053,7 @@ var emptyFlow = () => ({ texts: [], cards: [], rules: [], bullets: [], icons: []
1049
1053
  function lineX(line, box) {
1050
1054
  const { col, pad, indent, w } = box;
1051
1055
  const left = col.x + pad + indent;
1052
- const right = col.x + col.w - pad - w;
1056
+ const right = Math.max(left, col.x + col.w - pad - w);
1053
1057
  switch (line.align) {
1054
1058
  case "left" /* Left */:
1055
1059
  return left;
@@ -1156,11 +1160,11 @@ function splitColumns(groups, zone) {
1156
1160
  }
1157
1161
  cut = keepTogether(groups, heights, cut);
1158
1162
  return [
1159
- { col: { ...zone, w }, groups: groups.slice(0, cut) },
1160
- { col: { ...zone, x: zone.x + w + gap, w }, groups: groups.slice(cut) }
1163
+ { col: { ...zone, w, room: w }, groups: groups.slice(0, cut) },
1164
+ { col: { ...zone, x: zone.x + w + gap, w, room: w }, groups: groups.slice(cut) }
1161
1165
  ];
1162
1166
  }
1163
- var tableFor = (columns, k) => sizeTable(columns.flatMap((c) => c.groups), k, columns[0]?.col.w ?? 0);
1167
+ var tableFor = (columns, k) => sizeTable(columns.flatMap((c) => c.groups), k, columns[0]?.col.w ?? 0, columns[0]?.col.room);
1164
1168
  function largestK(columns, zoneH) {
1165
1169
  const fits = (k) => {
1166
1170
  const table = tableFor(columns, k);
@@ -1319,7 +1323,7 @@ function flowAll(ctx, input, base2, reflow) {
1319
1323
  const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
1320
1324
  const flanks = geo.flanks ?? [];
1321
1325
  const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
1322
- 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);
1326
+ const body = flow(ctx, bodyGroups(doc, palette, u, { withPrices: flanks.length === 0, compact: reflow.compact, wrap: reflow.wrap, dateScale: doc.tuning?.itemDateScale }), { ...tight.body, room: Math.max(tight.body.w, base2.body.w) }, fonts);
1323
1327
  const sides = flanks.length > 0 ? equalFlanks(ctx, flankPriceGroups(doc, palette, u), flanks, fonts) : [emptyFlow()];
1324
1328
  return { geo: tight, zones, head, body, sides };
1325
1329
  }