@dloizides/poster-render 0.2.7 → 0.4.0

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,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0
4
+
5
+ - FLIER-2 "Flier Studio follow-ups" D6 polish: optional `FlierDoc.tuning` with `headerGap` (closes the empty band between a stacked header and the body) and `itemDateScale` (list date script size). Docs without `tuning` render pixel-identical to 0.3.0.
6
+
7
+ ## 0.3.0
8
+
9
+ - FLIER-2 "Flier Studio follow-ups" theme 2 Golden hour: `GoldenHorizon` palette, Coastal font set, Horizon sky-only background.
10
+ - Breaking for custom contexts: `PosterContext.createLinearGradient` is now required (the Horizon sky is a linear gradient). A custom `PosterContext` must implement it.
11
+
3
12
  ## 0.2.7
4
13
 
5
14
  - P-B "Phone arch": the title block starts at the top margin (0.05h) instead of under a clock zone; the arch picture starts at 0.47h and grows.
package/README.md CHANGED
@@ -9,6 +9,7 @@ One JSON document (`FlierDoc`) in, one poster out. Used by Flier Studio (FLIER-1
9
9
  - Formats: story 1080x1920, post 1080x1350, square 1080x1080, phone 1170x2532, desktop 2560x1440.
10
10
  - Layouts: `picture-right` (E-A "Picture right"), `picture-left` (E-B "Picture left"), `arch` (E-C "Arch"), `picture-bottom`, `list`, `phone-clock-safe` (P-A "Phone, clock clear": top kept clear for the lock-screen clock), `phone-arch` (P-B "Phone arch"), `desktop-safe` (D-A "Desktop, icons clear": text clear of desktop icons and the taskbar), `desktop-arch` (D-B "Desktop arch"). `LAYOUT_CATALOGUE` lists id, design id, label, description and designed formats (for the app picker and the LLM prompt); `defaultLayoutFor(format)` gives E-A "Picture right" / P-A "Phone, clock clear" / D-A "Desktop, icons clear" (D4 "Layouts: keep all").
11
11
  - Arch layouts paint a soft arch (palette `arch`, about 4% off the ground) behind the picture only, inside the picture region; prices sit large on either side. The includes block is set at one size for every line. Palettes: `sand`, `night`, `sea`, `rose`. Font sets: `classic`, `modern`, `elegant` (the app loads the web fonts).
12
+ - Optional `tuning` (per-theme overrides, absent = layout default): `headerGap` (0-200 px at a 1080 short edge) starts the body that far under the last header line when the header sits above it; `itemDateScale` (0.5-2) scales the list date script.
12
13
  - The picture is placed contain + anchor in its own region: never cropped, never faded, drawn last, and no text or card is laid out in its region. Text shrinks to fit, never overflows.
13
14
  - Example: `kizombaWorkshopDocs` (3 workshops + list flier), `kizombaWorkshop` (the list flier).
14
15
 
package/dist/index.d.mts CHANGED
@@ -1,12 +1,14 @@
1
1
  declare enum BackgroundStyle {
2
2
  Solid = "solid",
3
- Tint = "tint"
3
+ Tint = "tint",
4
+ Horizon = "horizon"
4
5
  }
5
6
 
6
7
  declare enum FontSetId {
7
8
  Classic = "classic",
8
9
  Modern = "modern",
9
- Elegant = "elegant"
10
+ Elegant = "elegant",
11
+ Coastal = "coastal"
10
12
  }
11
13
 
12
14
  declare enum FormatId {
@@ -33,7 +35,8 @@ declare enum PaletteId {
33
35
  Sand = "sand",
34
36
  Night = "night",
35
37
  Sea = "sea",
36
- Rose = "rose"
38
+ Rose = "rose",
39
+ GoldenHorizon = "golden-horizon"
37
40
  }
38
41
 
39
42
  declare enum PictureAnchor {
@@ -94,6 +97,12 @@ interface FlierDoc {
94
97
  logo?: LogoSlot;
95
98
  blocks: FlierBlocks;
96
99
  items?: ListItem[];
100
+ tuning?: PosterTuning;
101
+ }
102
+ /** Optional per-theme spacing and size overrides; an absent field keeps the layout default. */
103
+ interface PosterTuning {
104
+ headerGap?: number;
105
+ itemDateScale?: number;
97
106
  }
98
107
  interface Rect {
99
108
  x: number;
@@ -109,9 +118,12 @@ type PosterAssets = Record<string, PosterImage | undefined>;
109
118
  interface TextMetricsLike {
110
119
  width: number;
111
120
  }
121
+ interface PosterGradient {
122
+ addColorStop(offset: number, color: string): void;
123
+ }
112
124
  interface PosterContext {
113
125
  font: string;
114
- fillStyle: string;
126
+ fillStyle: string | PosterGradient;
115
127
  textAlign: string;
116
128
  textBaseline: string;
117
129
  globalAlpha: number;
@@ -127,6 +139,7 @@ interface PosterContext {
127
139
  arc(x: number, y: number, r: number, start: number, end: number): void;
128
140
  closePath(): void;
129
141
  fill(): void;
142
+ createLinearGradient(x0: number, y0: number, x1: number, y1: number): PosterGradient;
130
143
  }
131
144
  interface PosterCanvas {
132
145
  width: number;
@@ -153,7 +166,10 @@ interface Palette {
153
166
  soft: string;
154
167
  card: string;
155
168
  arch: string;
169
+ sky?: readonly SkyStop[];
156
170
  }
171
+ /** One gradient stop of a horizon sky: offset 0 (top) to 1 (bottom) and its colour. */
172
+ type SkyStop = readonly [number, string];
157
173
  interface FontSet {
158
174
  display: string;
159
175
  script: string;
@@ -223,4 +239,4 @@ declare function defaultLayoutFor(format: FormatId): LayoutId;
223
239
  declare const kizombaWorkshop: FlierDoc;
224
240
  declare const kizombaWorkshopDocs: FlierDoc[];
225
241
 
226
- export { BackgroundStyle, type DataUrlCanvas, FONT_SETS, FORMAT_SIZES, type FlierBlocks, type FlierDoc, FlierDocError, type FlierDocResult, type FontSet, FontSetId, FormatId, type FormatSize, type IncludesBlock, type JsonSchema, LAYOUT_CATALOGUE, type LayoutCatalogueEntry, LayoutId, type ListItem, type LogoSlot, PALETTES, type Palette, PaletteId, PictureAnchor, type PictureSlot, type PosterAssets, type PosterCanvas, type PosterContext, type PosterImage, type PriceRow, type Rect, type RenderReport, type ScheduleRow, type TextMetricsLike, defaultLayoutFor, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, validateFlierDoc };
242
+ export { BackgroundStyle, type DataUrlCanvas, FONT_SETS, FORMAT_SIZES, type FlierBlocks, type FlierDoc, FlierDocError, type FlierDocResult, type FontSet, FontSetId, FormatId, type FormatSize, type IncludesBlock, type JsonSchema, LAYOUT_CATALOGUE, type LayoutCatalogueEntry, LayoutId, type ListItem, type LogoSlot, PALETTES, type Palette, PaletteId, PictureAnchor, type PictureSlot, type PosterAssets, type PosterCanvas, type PosterContext, type PosterGradient, type PosterImage, type PosterTuning, type PriceRow, type Rect, type RenderReport, type ScheduleRow, type SkyStop, type TextMetricsLike, defaultLayoutFor, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, validateFlierDoc };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  declare enum BackgroundStyle {
2
2
  Solid = "solid",
3
- Tint = "tint"
3
+ Tint = "tint",
4
+ Horizon = "horizon"
4
5
  }
5
6
 
6
7
  declare enum FontSetId {
7
8
  Classic = "classic",
8
9
  Modern = "modern",
9
- Elegant = "elegant"
10
+ Elegant = "elegant",
11
+ Coastal = "coastal"
10
12
  }
11
13
 
12
14
  declare enum FormatId {
@@ -33,7 +35,8 @@ declare enum PaletteId {
33
35
  Sand = "sand",
34
36
  Night = "night",
35
37
  Sea = "sea",
36
- Rose = "rose"
38
+ Rose = "rose",
39
+ GoldenHorizon = "golden-horizon"
37
40
  }
38
41
 
39
42
  declare enum PictureAnchor {
@@ -94,6 +97,12 @@ interface FlierDoc {
94
97
  logo?: LogoSlot;
95
98
  blocks: FlierBlocks;
96
99
  items?: ListItem[];
100
+ tuning?: PosterTuning;
101
+ }
102
+ /** Optional per-theme spacing and size overrides; an absent field keeps the layout default. */
103
+ interface PosterTuning {
104
+ headerGap?: number;
105
+ itemDateScale?: number;
97
106
  }
98
107
  interface Rect {
99
108
  x: number;
@@ -109,9 +118,12 @@ type PosterAssets = Record<string, PosterImage | undefined>;
109
118
  interface TextMetricsLike {
110
119
  width: number;
111
120
  }
121
+ interface PosterGradient {
122
+ addColorStop(offset: number, color: string): void;
123
+ }
112
124
  interface PosterContext {
113
125
  font: string;
114
- fillStyle: string;
126
+ fillStyle: string | PosterGradient;
115
127
  textAlign: string;
116
128
  textBaseline: string;
117
129
  globalAlpha: number;
@@ -127,6 +139,7 @@ interface PosterContext {
127
139
  arc(x: number, y: number, r: number, start: number, end: number): void;
128
140
  closePath(): void;
129
141
  fill(): void;
142
+ createLinearGradient(x0: number, y0: number, x1: number, y1: number): PosterGradient;
130
143
  }
131
144
  interface PosterCanvas {
132
145
  width: number;
@@ -153,7 +166,10 @@ interface Palette {
153
166
  soft: string;
154
167
  card: string;
155
168
  arch: string;
169
+ sky?: readonly SkyStop[];
156
170
  }
171
+ /** One gradient stop of a horizon sky: offset 0 (top) to 1 (bottom) and its colour. */
172
+ type SkyStop = readonly [number, string];
157
173
  interface FontSet {
158
174
  display: string;
159
175
  script: string;
@@ -223,4 +239,4 @@ declare function defaultLayoutFor(format: FormatId): LayoutId;
223
239
  declare const kizombaWorkshop: FlierDoc;
224
240
  declare const kizombaWorkshopDocs: FlierDoc[];
225
241
 
226
- export { BackgroundStyle, type DataUrlCanvas, FONT_SETS, FORMAT_SIZES, type FlierBlocks, type FlierDoc, FlierDocError, type FlierDocResult, type FontSet, FontSetId, FormatId, type FormatSize, type IncludesBlock, type JsonSchema, LAYOUT_CATALOGUE, type LayoutCatalogueEntry, LayoutId, type ListItem, type LogoSlot, PALETTES, type Palette, PaletteId, PictureAnchor, type PictureSlot, type PosterAssets, type PosterCanvas, type PosterContext, type PosterImage, type PriceRow, type Rect, type RenderReport, type ScheduleRow, type TextMetricsLike, defaultLayoutFor, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, validateFlierDoc };
242
+ export { BackgroundStyle, type DataUrlCanvas, FONT_SETS, FORMAT_SIZES, type FlierBlocks, type FlierDoc, FlierDocError, type FlierDocResult, type FontSet, FontSetId, FormatId, type FormatSize, type IncludesBlock, type JsonSchema, LAYOUT_CATALOGUE, type LayoutCatalogueEntry, LayoutId, type ListItem, type LogoSlot, PALETTES, type Palette, PaletteId, PictureAnchor, type PictureSlot, type PosterAssets, type PosterCanvas, type PosterContext, type PosterGradient, type PosterImage, type PosterTuning, type PriceRow, type Rect, type RenderReport, type ScheduleRow, type SkyStop, type TextMetricsLike, defaultLayoutFor, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, validateFlierDoc };
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@
4
4
  var BackgroundStyle = /* @__PURE__ */ ((BackgroundStyle2) => {
5
5
  BackgroundStyle2["Solid"] = "solid";
6
6
  BackgroundStyle2["Tint"] = "tint";
7
+ BackgroundStyle2["Horizon"] = "horizon";
7
8
  return BackgroundStyle2;
8
9
  })(BackgroundStyle || {});
9
10
 
@@ -12,6 +13,7 @@ var FontSetId = /* @__PURE__ */ ((FontSetId2) => {
12
13
  FontSetId2["Classic"] = "classic";
13
14
  FontSetId2["Modern"] = "modern";
14
15
  FontSetId2["Elegant"] = "elegant";
16
+ FontSetId2["Coastal"] = "coastal";
15
17
  return FontSetId2;
16
18
  })(FontSetId || {});
17
19
 
@@ -45,6 +47,7 @@ var PaletteId = /* @__PURE__ */ ((PaletteId2) => {
45
47
  PaletteId2["Night"] = "night";
46
48
  PaletteId2["Sea"] = "sea";
47
49
  PaletteId2["Rose"] = "rose";
50
+ PaletteId2["GoldenHorizon"] = "golden-horizon";
48
51
  return PaletteId2;
49
52
  })(PaletteId || {});
50
53
 
@@ -70,6 +73,17 @@ var PALETTES = {
70
73
  ["sand" /* Sand */]: { background: "#f5f4f2", tint: "#ece8e3", title: "#958a80", accent: "#e9b47f", ink: "#5f564f", soft: "#b3a89e", card: "#ffffff", arch: "#ede8e2" },
71
74
  ["night" /* Night */]: { background: "#1c1a17", tint: "#25221e", title: "#e8dccb", accent: "#e9b47f", ink: "#f4efe8", soft: "#9c9284", card: "#2c2824", arch: "#25221f" },
72
75
  ["sea" /* Sea */]: { background: "#eef4f3", tint: "#e1ecea", title: "#4f7d7a", accent: "#e07a5f", ink: "#2f3e46", soft: "#8aa3a1", card: "#ffffff", arch: "#e4ecea" },
76
+ ["golden-horizon" /* GoldenHorizon */]: {
77
+ background: "#dce5e7",
78
+ tint: "#d3dee1",
79
+ title: "#2f566f",
80
+ accent: "#8a4325",
81
+ ink: "#1f2d36",
82
+ soft: "#46606f",
83
+ card: "#f4f1ec",
84
+ arch: "#c7d4d6",
85
+ sky: [[0, "#bfd3d8"], [0.55, "#d4dddd"], [1, "#eadccb"]]
86
+ },
73
87
  ["rose" /* Rose */]: { background: "#f8efec", tint: "#f1e2dd", title: "#9b6b63", accent: "#c9846f", ink: "#4a3934", soft: "#b39a92", card: "#ffffff", arch: "#f1e5e1" }
74
88
  };
75
89
 
@@ -77,7 +91,8 @@ var PALETTES = {
77
91
  var FONT_SETS = {
78
92
  ["classic" /* Classic */]: { display: '"Oswald", "Arial Narrow", sans-serif', script: '"Sacramento", cursive', body: '"Fredoka", sans-serif' },
79
93
  ["modern" /* Modern */]: { display: '"Bebas Neue", "Arial Narrow", sans-serif', script: '"Great Vibes", cursive', body: '"Montserrat", sans-serif' },
80
- ["elegant" /* Elegant */]: { display: '"Playfair Display", serif', script: '"Allura", cursive', body: '"Lato", sans-serif' }
94
+ ["elegant" /* Elegant */]: { display: '"Playfair Display", serif', script: '"Allura", cursive', body: '"Lato", sans-serif' },
95
+ ["coastal" /* Coastal */]: { display: '"Fraunces", Georgia, serif', script: '"Allura", cursive', body: '"Jost", sans-serif' }
81
96
  };
82
97
 
83
98
  // src/schema/flierDocSchema.ts
@@ -88,6 +103,9 @@ var MAX_ITEMS = 8;
88
103
  var MAX_PRICES = 4;
89
104
  var MAX_VENUE = 3;
90
105
  var MIN_SCALE = 0.3;
106
+ var MAX_HEADER_GAP = 200;
107
+ var MIN_DATE_SCALE = 0.5;
108
+ var MAX_DATE_SCALE = 2;
91
109
  var text = (maxLength) => ({ type: "string", minLength: 1, maxLength });
92
110
  var scheduleRow = {
93
111
  type: "object",
@@ -153,6 +171,14 @@ var flierDocSchema = {
153
171
  },
154
172
  logo: { type: "object", required: ["imageId"], additionalProperties: false, properties: { imageId: text(SHORT) } },
155
173
  blocks,
174
+ tuning: {
175
+ type: "object",
176
+ additionalProperties: false,
177
+ properties: {
178
+ headerGap: { type: "number", minimum: 0, maximum: MAX_HEADER_GAP },
179
+ itemDateScale: { type: "number", minimum: MIN_DATE_SCALE, maximum: MAX_DATE_SCALE }
180
+ }
181
+ },
156
182
  items: {
157
183
  type: "array",
158
184
  minItems: 1,
@@ -293,6 +319,18 @@ function missingAssets(doc, assets) {
293
319
  return errors;
294
320
  }
295
321
 
322
+ // src/render/background.ts
323
+ function paintGround(ctx, style, palette, size) {
324
+ ctx.fillStyle = palette.background;
325
+ if (style === "horizon" /* Horizon */) {
326
+ const stops = palette.sky ?? [[0, palette.background], [1, palette.tint]];
327
+ const sky = ctx.createLinearGradient(0, 0, 0, size.height);
328
+ stops.forEach(([offset, color]) => sky.addColorStop(offset, color));
329
+ ctx.fillStyle = sky;
330
+ }
331
+ ctx.fillRect(0, 0, size.width, size.height);
332
+ }
333
+
296
334
  // src/layout/layoutSpecs.ts
297
335
  var flanksBeside = (pic, top, bottom2, m) => [
298
336
  [m, top, pic[0] - 2 * m, bottom2 - top],
@@ -490,8 +528,8 @@ function headerGroups(doc, p, u) {
490
528
  const lines = [l.display(b.title, SIZE.title), b.script ? l.script(b.script, SIZE.headerScript) : void 0, b.titleBottom ? l.display(b.titleBottom, SIZE.title) : void 0];
491
529
  return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
492
530
  }
493
- function itemGroup(item, l, u) {
494
- const lines = [l.script(item.date, SIZE.itemDate)];
531
+ function itemGroup(item, l, u, dateScale) {
532
+ const lines = [l.script(item.date, SIZE.itemDate * dateScale)];
495
533
  item.schedule.forEach((row) => lines.push(l.strong(`${row.label} ${row.time}`, SIZE.itemRow)));
496
534
  if (item.price) {
497
535
  lines.push(l.accent(item.price, SIZE.itemRow));
@@ -527,8 +565,8 @@ function eventGroups(doc, l, u, options) {
527
565
  });
528
566
  return groups;
529
567
  }
530
- function listGroups(doc, l, u) {
531
- const groups = (doc.items ?? []).map((item) => itemGroup(item, l, u));
568
+ function listGroups(doc, l, u, dateScale) {
569
+ const groups = (doc.items ?? []).map((item) => itemGroup(item, l, u, dateScale));
532
570
  const prices = doc.blocks.prices?.map((row) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice)) ?? [];
533
571
  if (prices.length > 0) {
534
572
  groups.push({ lines: prices, gapAfter: GAP.row * u });
@@ -549,7 +587,7 @@ function bodyGroups(doc, p, u, options = {}) {
549
587
  const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
550
588
  groups.push({ lines: b.venue.map((v) => l.venue(v, size)), gapAfter: GAP.venue * u, rule: { color: p.accent, height: GAP.rule * u }, ruleBelow: true, icon: { color: p.accent, glyph: p.background }, keepWithNext });
551
589
  }
552
- groups.push(...isList ? listGroups(doc, l, u) : eventGroups(doc, l, u, options));
590
+ groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, options));
553
591
  if (b.includes) {
554
592
  const lines = [l.accent(b.includes.heading, SIZE.small), ...b.includes.items.map((i) => l.item(i, SIZE.small))].flatMap((line) => wrapped(line, options.wrap));
555
593
  groups.push({ lines, gapAfter: GAP.includes * u, uniform: true, keepWithNext: b.footer !== void 0, attachNext: b.footer !== void 0 });
@@ -791,15 +829,25 @@ function splitHeader(header, hasLogo) {
791
829
  const logoW = hasLogo ? Math.round(header.w * LOGO_SHARE) : 0;
792
830
  return { text: { ...header, w: header.w - logoW * 1.1 }, logo: { ...header, x: header.x + header.w - logoW, w: logoW } };
793
831
  }
832
+ function closeHeaderGap(geo, head, gap, u) {
833
+ const { header, body } = geo;
834
+ const stacked = header.y + header.h <= body.y && header.x < body.x + body.w && body.x < header.x + header.w;
835
+ if (gap === void 0 || !stacked || head.texts.length === 0) {
836
+ return geo;
837
+ }
838
+ const top = Math.round(Math.max(...head.texts.map((t) => t.box.y + t.box.h)) + gap * u);
839
+ return top < body.y ? { ...geo, body: { ...body, y: top, h: body.h + body.y - top } } : geo;
840
+ }
794
841
  function flowAll(ctx, input, geo, reflow) {
795
842
  const { doc, palette, fonts } = input;
796
843
  const u = Math.min(input.width, input.height) / BASE;
797
844
  const zones = geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0);
798
845
  const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
799
846
  const flanks = geo.flanks ?? [];
800
- const body = flow(ctx, bodyGroups(doc, palette, u, { withPrices: flanks.length === 0, compact: reflow.compact, wrap: reflow.wrap }), geo.body, fonts);
847
+ const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
848
+ 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);
801
849
  const sides = flanks.length > 0 ? equalFlanks(ctx, flankPriceGroups(doc, palette, u), flanks, fonts) : [emptyFlow()];
802
- return { geo, zones, head, body, sides };
850
+ return { geo: tight, zones, head, body, sides };
803
851
  }
804
852
  var smallest = (t) => Math.min(Infinity, ...[t.head, t.body, ...t.sides].flatMap((f) => f.texts.map((x) => x.box.h / LINE_HEIGHT3)));
805
853
  function shiftHeader(geo, shift) {
@@ -977,8 +1025,7 @@ function render(input, assets, canvas) {
977
1025
  const u = Math.min(width, height) / BASE2;
978
1026
  const { geo, zones, head, body, sides } = fitToFloor(ctx, { doc, palette, fonts, width, height });
979
1027
  ctx.globalAlpha = 1;
980
- ctx.fillStyle = palette.background;
981
- ctx.fillRect(0, 0, width, height);
1028
+ paintGround(ctx, doc.background, palette, { width, height });
982
1029
  if (doc.background === "tint" /* Tint */) {
983
1030
  ctx.fillStyle = palette.tint;
984
1031
  [geo.header, geo.body].forEach((r3) => ctx.fillRect(r3.x, r3.y, r3.w, r3.h));