@dloizides/poster-render 0.3.0 → 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
@@ -97,6 +97,12 @@ interface FlierDoc {
97
97
  logo?: LogoSlot;
98
98
  blocks: FlierBlocks;
99
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;
100
106
  }
101
107
  interface Rect {
102
108
  x: number;
@@ -233,4 +239,4 @@ declare function defaultLayoutFor(format: FormatId): LayoutId;
233
239
  declare const kizombaWorkshop: FlierDoc;
234
240
  declare const kizombaWorkshopDocs: FlierDoc[];
235
241
 
236
- 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 PriceRow, type Rect, type RenderReport, type ScheduleRow, type SkyStop, 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
@@ -97,6 +97,12 @@ interface FlierDoc {
97
97
  logo?: LogoSlot;
98
98
  blocks: FlierBlocks;
99
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;
100
106
  }
101
107
  interface Rect {
102
108
  x: number;
@@ -233,4 +239,4 @@ declare function defaultLayoutFor(format: FormatId): LayoutId;
233
239
  declare const kizombaWorkshop: FlierDoc;
234
240
  declare const kizombaWorkshopDocs: FlierDoc[];
235
241
 
236
- 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 PriceRow, type Rect, type RenderReport, type ScheduleRow, type SkyStop, 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
@@ -103,6 +103,9 @@ var MAX_ITEMS = 8;
103
103
  var MAX_PRICES = 4;
104
104
  var MAX_VENUE = 3;
105
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;
106
109
  var text = (maxLength) => ({ type: "string", minLength: 1, maxLength });
107
110
  var scheduleRow = {
108
111
  type: "object",
@@ -168,6 +171,14 @@ var flierDocSchema = {
168
171
  },
169
172
  logo: { type: "object", required: ["imageId"], additionalProperties: false, properties: { imageId: text(SHORT) } },
170
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
+ },
171
182
  items: {
172
183
  type: "array",
173
184
  minItems: 1,
@@ -517,8 +528,8 @@ function headerGroups(doc, p, u) {
517
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];
518
529
  return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
519
530
  }
520
- function itemGroup(item, l, u) {
521
- 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)];
522
533
  item.schedule.forEach((row) => lines.push(l.strong(`${row.label} ${row.time}`, SIZE.itemRow)));
523
534
  if (item.price) {
524
535
  lines.push(l.accent(item.price, SIZE.itemRow));
@@ -554,8 +565,8 @@ function eventGroups(doc, l, u, options) {
554
565
  });
555
566
  return groups;
556
567
  }
557
- function listGroups(doc, l, u) {
558
- 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));
559
570
  const prices = doc.blocks.prices?.map((row) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice)) ?? [];
560
571
  if (prices.length > 0) {
561
572
  groups.push({ lines: prices, gapAfter: GAP.row * u });
@@ -576,7 +587,7 @@ function bodyGroups(doc, p, u, options = {}) {
576
587
  const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
577
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 });
578
589
  }
579
- 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));
580
591
  if (b.includes) {
581
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));
582
593
  groups.push({ lines, gapAfter: GAP.includes * u, uniform: true, keepWithNext: b.footer !== void 0, attachNext: b.footer !== void 0 });
@@ -818,15 +829,25 @@ function splitHeader(header, hasLogo) {
818
829
  const logoW = hasLogo ? Math.round(header.w * LOGO_SHARE) : 0;
819
830
  return { text: { ...header, w: header.w - logoW * 1.1 }, logo: { ...header, x: header.x + header.w - logoW, w: logoW } };
820
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
+ }
821
841
  function flowAll(ctx, input, geo, reflow) {
822
842
  const { doc, palette, fonts } = input;
823
843
  const u = Math.min(input.width, input.height) / BASE;
824
844
  const zones = geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0);
825
845
  const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
826
846
  const flanks = geo.flanks ?? [];
827
- 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);
828
849
  const sides = flanks.length > 0 ? equalFlanks(ctx, flankPriceGroups(doc, palette, u), flanks, fonts) : [emptyFlow()];
829
- return { geo, zones, head, body, sides };
850
+ return { geo: tight, zones, head, body, sides };
830
851
  }
831
852
  var smallest = (t) => Math.min(Infinity, ...[t.head, t.body, ...t.sides].flatMap((f) => f.texts.map((x) => x.box.h / LINE_HEIGHT3)));
832
853
  function shiftHeader(geo, shift) {