@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.mjs CHANGED
@@ -88,6 +88,8 @@ var LINE_KEY_PATTERN = "^(title|titleBottom|script|footer|includes[.]heading|inc
88
88
  var MAX_FONT = 40;
89
89
  var MIN_SIZE_SCALE = 0.25;
90
90
  var MAX_SIZE_SCALE = 3;
91
+ var MIN_WIDTH_SCALE = 0.5;
92
+ var MAX_WIDTH_SCALE = 1.5;
91
93
  var MIN_SPACING = -0.1;
92
94
  var MAX_SPACING = 0.5;
93
95
  var MAX_TIES = 12;
@@ -99,6 +101,7 @@ var lineStyle = {
99
101
  properties: {
100
102
  font: { type: "string", minLength: 1, maxLength: MAX_FONT, pattern: "^[A-Za-z0-9 ]+$" },
101
103
  sizeScale: { type: "number", minimum: MIN_SIZE_SCALE, maximum: MAX_SIZE_SCALE },
104
+ widthScale: { type: "number", minimum: MIN_WIDTH_SCALE, maximum: MAX_WIDTH_SCALE },
102
105
  color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
103
106
  weight: { type: "integer", enum: WEIGHTS },
104
107
  italic: { type: "boolean" },
@@ -803,6 +806,7 @@ function styled(line, key, sc) {
803
806
  family: style?.font,
804
807
  italic: style?.italic,
805
808
  spacing: style?.letterSpacing,
809
+ widthScale: style?.widthScale,
806
810
  align: style?.align,
807
811
  widthTie,
808
812
  sizeTie
@@ -985,8 +989,8 @@ function lineSize(line, width, k, avail) {
985
989
  const indent = bulletIndent(line, k);
986
990
  return Math.max(0, Math.min(line.size * k, line.size * (avail - indent) / Math.max(width, 1)));
987
991
  }
988
- function groupSizes(m, k, avail) {
989
- 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)));
990
994
  if (!m.group.uniform) {
991
995
  return own;
992
996
  }
@@ -1001,7 +1005,7 @@ function tieMembers(all, k, colW, table, pick) {
1001
1005
  m.group.lines.forEach((line, i) => {
1002
1006
  const id = pick(line);
1003
1007
  if (id !== void 0) {
1004
- const member = { line, width: Math.max(m.widths[i] ?? 1, 1), cap: Math.max(0, avail - 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 };
1005
1009
  byId.set(id, [...byId.get(id) ?? [], member]);
1006
1010
  }
1007
1011
  });
@@ -1021,8 +1025,8 @@ function sameWidths(list) {
1021
1025
  x.sizes[x.i] = target * x.line.size / x.width;
1022
1026
  });
1023
1027
  }
1024
- function sizeTable(all, k, colW) {
1025
- 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))]));
1026
1030
  tieMembers(all, k, colW, table, (line) => line.sizeTie).forEach(sameSizes);
1027
1031
  tieMembers(all, k, colW, table, (line) => line.widthTie).forEach(sameWidths);
1028
1032
  return table;
@@ -1047,7 +1051,7 @@ var emptyFlow = () => ({ texts: [], cards: [], rules: [], bullets: [], icons: []
1047
1051
  function lineX(line, box) {
1048
1052
  const { col, pad, indent, w } = box;
1049
1053
  const left = col.x + pad + indent;
1050
- const right = col.x + col.w - pad - w;
1054
+ const right = Math.max(left, col.x + col.w - pad - w);
1051
1055
  switch (line.align) {
1052
1056
  case "left" /* Left */:
1053
1057
  return left;
@@ -1154,11 +1158,11 @@ function splitColumns(groups, zone) {
1154
1158
  }
1155
1159
  cut = keepTogether(groups, heights, cut);
1156
1160
  return [
1157
- { col: { ...zone, w }, groups: groups.slice(0, cut) },
1158
- { 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) }
1159
1163
  ];
1160
1164
  }
1161
- 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);
1162
1166
  function largestK(columns, zoneH) {
1163
1167
  const fits = (k) => {
1164
1168
  const table = tableFor(columns, k);
@@ -1317,7 +1321,7 @@ function flowAll(ctx, input, base2, reflow) {
1317
1321
  const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
1318
1322
  const flanks = geo.flanks ?? [];
1319
1323
  const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
1320
- 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, base2.body.w) }, fonts);
1321
1325
  const sides = flanks.length > 0 ? equalFlanks(ctx, flankPriceGroups(doc, palette, u), flanks, fonts) : [emptyFlow()];
1322
1326
  return { geo: tight, zones, head, body, sides };
1323
1327
  }