@dloizides/poster-render 0.11.0 → 0.11.2

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