@dloizides/poster-render 0.12.0 → 0.13.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.13.1
4
+
5
+ - D-SPACE-1 "Space above/below applies per item": a wrapped line keeps `spaceAbove` on its first part and `spaceBelow` on its last, so a wrapped includes item's own lines stay tight.
6
+
7
+ ## 0.13.0
8
+
9
+ - FLIER-2 "Bullets on/off and line spacing": `FlierDoc.bullets` (default true; false drops the includes bullet dot and its indent), `LineStyle.spaceAbove` / `spaceBelow` (em of the line size, 0-2) added above / below a line, and a footer holding line breaks sets one footer line per text line. Docs without the new fields render pixel-identical (45 snapshots unchanged).
10
+
3
11
  ## 0.6.0
4
12
 
5
13
  - FLIER-2 "Flier Studio follow-ups" D30 (sample parity, gap table `apps/flier-studio/docs/design/FLIER-2-sample-parity/gap.md`), all optional:
package/dist/index.d.mts CHANGED
@@ -188,10 +188,11 @@ interface FlierDoc {
188
188
  lineTies?: LineTie[];
189
189
  rows?: RowTheme;
190
190
  sectionOrder?: BodySection[];
191
+ bullets?: boolean;
191
192
  }
192
193
  /** A text line path such as "title", "venue.1", "schedule.0.time" or "items.2.date" (see LINE_KEY_PATTERN). */
193
194
  type LineKey = string;
194
- /** 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. */
195
+ /** Optional per-line overrides of the theme; an absent field keeps the theme value. letterSpacing, spaceAbove and spaceBelow are in em; widthScale widens or narrows the room the line may fill. */
195
196
  interface LineStyle {
196
197
  font?: string;
197
198
  sizeScale?: number;
@@ -201,6 +202,8 @@ interface LineStyle {
201
202
  italic?: boolean;
202
203
  letterSpacing?: number;
203
204
  align?: LineAlign;
205
+ spaceAbove?: number;
206
+ spaceBelow?: number;
204
207
  }
205
208
  /** Two lines drawn at one width (width) or one font size (size). */
206
209
  interface LineTie {
package/dist/index.d.ts CHANGED
@@ -188,10 +188,11 @@ interface FlierDoc {
188
188
  lineTies?: LineTie[];
189
189
  rows?: RowTheme;
190
190
  sectionOrder?: BodySection[];
191
+ bullets?: boolean;
191
192
  }
192
193
  /** A text line path such as "title", "venue.1", "schedule.0.time" or "items.2.date" (see LINE_KEY_PATTERN). */
193
194
  type LineKey = string;
194
- /** 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. */
195
+ /** Optional per-line overrides of the theme; an absent field keeps the theme value. letterSpacing, spaceAbove and spaceBelow are in em; widthScale widens or narrows the room the line may fill. */
195
196
  interface LineStyle {
196
197
  font?: string;
197
198
  sizeScale?: number;
@@ -201,6 +202,8 @@ interface LineStyle {
201
202
  italic?: boolean;
202
203
  letterSpacing?: number;
203
204
  align?: LineAlign;
205
+ spaceAbove?: number;
206
+ spaceBelow?: number;
204
207
  }
205
208
  /** Two lines drawn at one width (width) or one font size (size). */
206
209
  interface LineTie {
package/dist/index.js CHANGED
@@ -102,6 +102,7 @@ var MAX_FONT = 40;
102
102
  var MIN_SPACING = -0.1;
103
103
  var MAX_SPACING = 0.5;
104
104
  var MAX_TIES = 12;
105
+ var MAX_SPACE = 2;
105
106
  var WEIGHTS = [100, 200, 300, 400, 500, 600, 700, 800, 900];
106
107
  var lineKey = { type: "string", pattern: LINE_KEY_PATTERN };
107
108
  var lineStyle = {
@@ -115,7 +116,9 @@ var lineStyle = {
115
116
  weight: { type: "integer", enum: WEIGHTS },
116
117
  italic: { type: "boolean" },
117
118
  letterSpacing: { type: "number", minimum: MIN_SPACING, maximum: MAX_SPACING },
118
- align: { type: "string", enum: Object.values(LineAlign) }
119
+ align: { type: "string", enum: Object.values(LineAlign) },
120
+ spaceAbove: { type: "number", minimum: 0, maximum: MAX_SPACE },
121
+ spaceBelow: { type: "number", minimum: 0, maximum: MAX_SPACE }
119
122
  }
120
123
  };
121
124
  var lineStylesSchema = { type: "object", propertyNames: lineKey, additionalProperties: lineStyle };
@@ -358,6 +361,7 @@ var flierDocSchema = {
358
361
  lineStyles: lineStylesSchema,
359
362
  lineTies: lineTiesSchema,
360
363
  rows: rowsSchema,
364
+ bullets: { type: "boolean" },
361
365
  sectionOrder: { type: "array", maxItems: MAX_SECTIONS, items: { type: "string", enum: Object.values(BodySection) } },
362
366
  items: {
363
367
  type: "array",
@@ -808,10 +812,11 @@ function styled(line, key, sc) {
808
812
  if (style === void 0 && widthTie === void 0 && sizeTie === void 0) {
809
813
  return { ...line, key };
810
814
  }
815
+ const size = line.size * (style?.sizeScale ?? 1);
811
816
  return {
812
817
  ...line,
813
818
  key,
814
- size: line.size * (style?.sizeScale ?? 1),
819
+ size,
815
820
  color: style?.color ?? line.color,
816
821
  weight: style?.weight ?? line.weight,
817
822
  family: style?.font,
@@ -820,6 +825,8 @@ function styled(line, key, sc) {
820
825
  widthScale: style?.widthScale,
821
826
  fixedSize: style?.sizeScale === void 0 ? void 0 : true,
822
827
  align: style?.align,
828
+ spaceAbove: style?.spaceAbove === void 0 ? void 0 : style.spaceAbove * size,
829
+ spaceBelow: style?.spaceBelow === void 0 ? void 0 : style.spaceBelow * size,
823
830
  widthTie,
824
831
  sizeTie
825
832
  };
@@ -867,14 +874,14 @@ var GAP = {
867
874
  rule: 8,
868
875
  divider: 24
869
876
  };
870
- var makers = (p, u, sc, timeWeight = SEMI) => ({
877
+ var makers = (p, u, sc, timeWeight = SEMI, bullets = true) => ({
871
878
  display: (text2, size, key) => styled({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }, key, sc),
872
879
  venue: (text2, size, key) => styled({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }, key, sc),
873
880
  bodyVenue: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
874
881
  script: (text2, size, key) => styled({ text: text2, role: "script", weight: SCRIPT, size: size * u, color: p.script ?? p.accent }, key, sc),
875
882
  strong: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
876
883
  accent: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }, key, sc),
877
- item: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }, key, sc),
884
+ item: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: bullets ? p.accent : void 0 }, key, sc),
878
885
  soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc),
879
886
  time: (text2, size, key) => styled({ text: text2, role: "body", weight: timeWeight, size: size * u, color: p.accent }, key, sc)
880
887
  });
@@ -923,7 +930,9 @@ function halves(text2) {
923
930
  }
924
931
  function wrapped(line, wrap) {
925
932
  const parts = wrap ? halves(line.text) : [line.text];
926
- return parts.length === 1 ? [line] : parts.map((text2, i) => i === 0 ? { ...line, text: text2, tail: void 0 } : { ...line, text: text2, tail: void 0, bullet: void 0, hang: line.bullet !== void 0 });
933
+ const last = parts.length - 1;
934
+ const edges = (i) => ({ spaceAbove: i === 0 ? line.spaceAbove : void 0, spaceBelow: i === last ? line.spaceBelow : void 0 });
935
+ return parts.length === 1 ? [line] : parts.map((text2, i) => i === 0 ? { ...line, ...edges(i), text: text2, tail: void 0 } : { ...line, ...edges(i), text: text2, tail: void 0, bullet: void 0, hang: line.bullet !== void 0 });
927
936
  }
928
937
  function scheduleLines(doc, l, row, i) {
929
938
  const r3 = doc.rows;
@@ -987,13 +996,14 @@ function joined(order, parts) {
987
996
  });
988
997
  }
989
998
  function bodyGroups(doc, p, u, options = {}) {
990
- const l = makers(p, u, styleContext(doc), doc.rows?.timeWeight);
999
+ const l = makers(p, u, styleContext(doc), doc.rows?.timeWeight, doc.bullets !== false);
991
1000
  const b = doc.blocks;
992
1001
  const isList = doc.layout === "list" /* List */;
993
1002
  const [rows, prices] = isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, { ...options, marks: rowMarks(doc, p, u) });
994
1003
  const includeLines = b.includes ? [l.accent(b.includes.heading, SIZE.small, "includes.heading"), ...b.includes.items.map((item, i) => l.item(item, SIZE.small, `includes.items.${i}`))] : [];
995
1004
  const includes = includeLines.length > 0 ? [{ lines: includeLines.flatMap((line) => wrapped(line, options.wrap)), gapAfter: GAP.includes * u, uniform: true }] : [];
996
- const footer = b.footer ? [{ lines: wrapped(l.soft(b.footer, SIZE.small, "footer"), options.wrap), gapAfter: 0 }] : [];
1005
+ const footerLines = (b.footer ?? "").split("\n").filter((text2) => text2.trim() !== "");
1006
+ const footer = footerLines.length > 0 ? [{ lines: footerLines.flatMap((text2) => wrapped(l.soft(text2, SIZE.small, "footer"), options.wrap)), gapAfter: 0 }] : [];
997
1007
  const parts = {
998
1008
  ["venue" /* Venue */]: venueGroups(doc, p, u, l),
999
1009
  ["schedule" /* Schedule */]: isList ? [] : rows,
@@ -1155,11 +1165,12 @@ function placeGroup(m, at, out) {
1155
1165
  const top = y;
1156
1166
  y += pad;
1157
1167
  if (group.icon?.centre === true) {
1158
- const textH = group.lines.reduce((h, line, i) => h + (sizes[i] ?? 0) * LINE_HEIGHT + (i < group.lines.length - 1 ? (line.gapAfter ?? 0) * k : 0), 0);
1168
+ const textH = group.lines.reduce((h, line, i) => h + (sizes[i] ?? 0) * LINE_HEIGHT + ((line.spaceAbove ?? 0) + (line.spaceBelow ?? 0)) * k + (i < group.lines.length - 1 ? (line.gapAfter ?? 0) * k : 0), 0);
1159
1169
  y += Math.max(0, (d - textH) / 2);
1160
1170
  }
1161
1171
  group.lines.forEach((line, i) => {
1162
1172
  const size = sizes[i] ?? 0;
1173
+ y += (line.spaceAbove ?? 0) * k;
1163
1174
  const indent = (indented(line) ? line.size * k * BULLET_INDENT : 0) + iconIndent;
1164
1175
  const w = (m.widths[i] ?? 0) * size / line.size;
1165
1176
  const x = lineX(line, { col, pad, indent, w });
@@ -1168,7 +1179,7 @@ function placeGroup(m, at, out) {
1168
1179
  if (line.bullet && out) {
1169
1180
  out.bullets.push({ x: col.x + pad + size * BULLET_RADIUS, y: y + size * LINE_HEIGHT / 2, r: size * BULLET_RADIUS, color: line.bullet });
1170
1181
  }
1171
- y += size * LINE_HEIGHT + (line.gapAfter ?? 0) * k;
1182
+ y += size * LINE_HEIGHT + ((line.gapAfter ?? 0) + (line.spaceBelow ?? 0)) * k;
1172
1183
  });
1173
1184
  y = placeIcon(group, { d, x: col.x + pad, top: top + pad, bottom: y }, out);
1174
1185
  y += pad;