@dloizides/poster-render 0.11.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.js CHANGED
@@ -989,10 +989,10 @@ function groupBox(group, k, colW) {
989
989
  }
990
990
  function lineSize(line, width, k, avail) {
991
991
  const indent = bulletIndent(line, k);
992
- return Math.max(0, Math.min(line.size * k, line.size * (avail * (line.widthScale ?? 1) - indent) / Math.max(width, 1)));
992
+ return Math.max(0, Math.min(line.size * k, line.size * (avail - indent) / Math.max(width, 1)));
993
993
  }
994
- function groupSizes(m, k, avail) {
995
- 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)));
996
996
  if (!m.group.uniform) {
997
997
  return own;
998
998
  }
@@ -1007,7 +1007,7 @@ function tieMembers(all, k, colW, table, pick) {
1007
1007
  m.group.lines.forEach((line, i) => {
1008
1008
  const id = pick(line);
1009
1009
  if (id !== void 0) {
1010
- const member = { line, width: Math.max(m.widths[i] ?? 1, 1), cap: Math.max(0, avail * (line.widthScale ?? 1) - 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 };
1011
1011
  byId.set(id, [...byId.get(id) ?? [], member]);
1012
1012
  }
1013
1013
  });
@@ -1027,8 +1027,8 @@ function sameWidths(list) {
1027
1027
  x.sizes[x.i] = target * x.line.size / x.width;
1028
1028
  });
1029
1029
  }
1030
- function sizeTable(all, k, colW) {
1031
- 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))]));
1032
1032
  tieMembers(all, k, colW, table, (line) => line.sizeTie).forEach(sameSizes);
1033
1033
  tieMembers(all, k, colW, table, (line) => line.widthTie).forEach(sameWidths);
1034
1034
  return table;
@@ -1053,7 +1053,7 @@ var emptyFlow = () => ({ texts: [], cards: [], rules: [], bullets: [], icons: []
1053
1053
  function lineX(line, box) {
1054
1054
  const { col, pad, indent, w } = box;
1055
1055
  const left = col.x + pad + indent;
1056
- const right = col.x + col.w - pad - w;
1056
+ const right = Math.max(left, col.x + col.w - pad - w);
1057
1057
  switch (line.align) {
1058
1058
  case "left" /* Left */:
1059
1059
  return left;
@@ -1160,11 +1160,11 @@ function splitColumns(groups, zone) {
1160
1160
  }
1161
1161
  cut = keepTogether(groups, heights, cut);
1162
1162
  return [
1163
- { col: { ...zone, w }, groups: groups.slice(0, cut) },
1164
- { 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) }
1165
1165
  ];
1166
1166
  }
1167
- 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);
1168
1168
  function largestK(columns, zoneH) {
1169
1169
  const fits = (k) => {
1170
1170
  const table = tableFor(columns, k);
@@ -1323,7 +1323,7 @@ function flowAll(ctx, input, base2, reflow) {
1323
1323
  const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
1324
1324
  const flanks = geo.flanks ?? [];
1325
1325
  const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
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, 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);
1327
1327
  const sides = flanks.length > 0 ? equalFlanks(ctx, flankPriceGroups(doc, palette, u), flanks, fonts) : [emptyFlow()];
1328
1328
  return { geo: tight, zones, head, body, sides };
1329
1329
  }