@dloizides/poster-render 0.3.0 → 0.5.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,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ - FLIER-2 "Flier Studio follow-ups" AC-38/39/40 (D25, D26, D29): optional `FlierDoc.lineStyles`, a per-line override keyed by line path (`title`, `venue.1`, `schedule.0.time`, `items.2.date`, see `LINE_KEY_PATTERN`) with `font`, `sizeScale`, `color`, `weight`, `italic`, `letterSpacing` (em) and `align` (`LineAlign`).
6
+ - Optional `FlierDoc.lineTies` plus helpers `sameWidth(doc, a, b)` (drawn widths equal within 1px, grown to the wider, inside the margins) and `sameSize(doc, a, b)` (one font size). Ties are resolved at layout time, so a theme or font switch keeps them.
7
+ - `validateFlierDoc` checks both (own keys only, so `__proto__` is rejected); the validator now supports `pattern`, `propertyNames`, schema-valued `additionalProperties` and `boolean`.
8
+ - `PosterContext.letterSpacing` is optional; it is only set when a line has letter spacing.
9
+ - Docs without `lineStyles`/`lineTies` render pixel-identical to 0.4.0 (sha256 of every layout x format pinned in a snapshot).
10
+
11
+ ## 0.4.0
12
+
13
+ - 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.
14
+
15
+ ## 0.3.0
16
+
17
+ - FLIER-2 "Flier Studio follow-ups" theme 2 Golden hour: `GoldenHorizon` palette, Coastal font set, Horizon sky-only background.
18
+ - Breaking for custom contexts: `PosterContext.createLinearGradient` is now required (the Horizon sky is a linear gradient). A custom `PosterContext` must implement it.
19
+
3
20
  ## 0.2.7
4
21
 
5
22
  - 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
 
@@ -47,6 +48,21 @@ The font sets name CSS families (`FONT_SETS`). The host loads them before `rende
47
48
 
48
49
  Every text run is at least 30px at a 1080 short edge (40px on desktop 2560x1440). When a layout cannot fit its text at the floor, the picture gives space to the text.
49
50
 
51
+ ## Per-line style and ties
52
+
53
+ ```ts
54
+ import { LineAlign, sameSize, sameWidth } from '@dloizides/poster-render';
55
+
56
+ let doc = { ...base, lineStyles: { footer: { font: 'Georgia', sizeScale: 1.2, color: '#1f2a44', weight: 600, italic: true, letterSpacing: 0.05, align: LineAlign.Center } } };
57
+ doc = sameWidth(doc, 'title', 'titleBottom');
58
+ doc = sameSize(doc, 'venue.1', 'footer');
59
+ ```
60
+
61
+ - Keys: `title`, `titleBottom`, `script`, `footer`, `includes.heading`, `includes.items.N`, `venue.N`, `schedule.N.label|time`, `prices.N.amount|label`, `items.N.date|price|schedule.M` (`LINE_KEY_PATTERN`).
62
+ - When rows are set on one line (compact), the merged row takes the style of `schedule.N.label` / `prices.N.amount`.
63
+ - A width tie grows the narrower line to the wider one, capped at the column; a size tie takes the larger size where both still fit. Ties act inside one text zone (header, body or a flank).
64
+ - A doc without `lineStyles` and `lineTies` renders exactly as before.
65
+
50
66
  ## Schema version policy
51
67
 
52
68
  `FlierDoc.version` is `1`. A field added as optional keeps version 1; a removed, renamed or retyped field raises the version and `validateFlierDoc` rejects the other version with `version: must be 1 (got N)`. A package major release goes with a new doc version.
package/dist/index.d.mts CHANGED
@@ -45,11 +45,41 @@ declare enum PictureAnchor {
45
45
  Bottom = "bottom"
46
46
  }
47
47
 
48
- interface FormatSize {
49
- width: number;
50
- height: number;
48
+ declare enum LineAlign {
49
+ Left = "left",
50
+ Center = "center",
51
+ Right = "right"
52
+ }
53
+
54
+ declare enum LineTieKind {
55
+ Width = "width",
56
+ Size = "size"
51
57
  }
52
- declare const FORMAT_SIZES: Readonly<Record<FormatId, FormatSize>>;
58
+
59
+ interface JsonSchema {
60
+ $schema?: string;
61
+ $id?: string;
62
+ title?: string;
63
+ description?: string;
64
+ type?: 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean';
65
+ properties?: Record<string, JsonSchema>;
66
+ required?: string[];
67
+ additionalProperties?: boolean | JsonSchema;
68
+ propertyNames?: JsonSchema;
69
+ enum?: readonly (string | number)[];
70
+ const?: string | number;
71
+ minLength?: number;
72
+ maxLength?: number;
73
+ pattern?: string;
74
+ minimum?: number;
75
+ maximum?: number;
76
+ items?: JsonSchema;
77
+ minItems?: number;
78
+ maxItems?: number;
79
+ }
80
+
81
+ /** Every text line a style or tie can name: block fields by path, list items by index. */
82
+ declare const LINE_KEY_PATTERN = "^(title|titleBottom|script|footer|includes[.]heading|includes[.]items[.][0-5]|venue[.][0-2]|schedule[.][0-5][.](label|time)|prices[.][0-3][.](amount|label)|items[.][0-7][.](date|price|schedule[.][0-5]))$";
53
83
 
54
84
  interface ScheduleRow {
55
85
  label: string;
@@ -97,6 +127,31 @@ interface FlierDoc {
97
127
  logo?: LogoSlot;
98
128
  blocks: FlierBlocks;
99
129
  items?: ListItem[];
130
+ tuning?: PosterTuning;
131
+ lineStyles?: Record<LineKey, LineStyle | undefined>;
132
+ lineTies?: LineTie[];
133
+ }
134
+ /** A text line path such as "title", "venue.1", "schedule.0.time" or "items.2.date" (see LINE_KEY_PATTERN). */
135
+ type LineKey = string;
136
+ /** Optional per-line overrides of the theme; an absent field keeps the theme value. letterSpacing is in em. */
137
+ interface LineStyle {
138
+ font?: string;
139
+ sizeScale?: number;
140
+ color?: string;
141
+ weight?: number;
142
+ italic?: boolean;
143
+ letterSpacing?: number;
144
+ align?: LineAlign;
145
+ }
146
+ /** Two lines drawn at one width (width) or one font size (size). */
147
+ interface LineTie {
148
+ kind: LineTieKind;
149
+ lines: [LineKey, LineKey];
150
+ }
151
+ /** Optional per-theme spacing and size overrides; an absent field keeps the layout default. */
152
+ interface PosterTuning {
153
+ headerGap?: number;
154
+ itemDateScale?: number;
100
155
  }
101
156
  interface Rect {
102
157
  x: number;
@@ -121,6 +176,7 @@ interface PosterContext {
121
176
  textAlign: string;
122
177
  textBaseline: string;
123
178
  globalAlpha: number;
179
+ letterSpacing?: string;
124
180
  save(): void;
125
181
  restore(): void;
126
182
  fillRect(x: number, y: number, w: number, h: number): void;
@@ -170,30 +226,21 @@ interface FontSet {
170
226
  body: string;
171
227
  }
172
228
 
229
+ /** Returns a copy of the doc whose lines a and b draw at one width (within 1px), grown to the wider inside the margins. */
230
+ declare const sameWidth: (doc: FlierDoc, a: LineKey, b: LineKey) => FlierDoc;
231
+ /** Returns a copy of the doc whose lines a and b take one font size, the larger one where it fits. */
232
+ declare const sameSize: (doc: FlierDoc, a: LineKey, b: LineKey) => FlierDoc;
233
+
234
+ interface FormatSize {
235
+ width: number;
236
+ height: number;
237
+ }
238
+ declare const FORMAT_SIZES: Readonly<Record<FormatId, FormatSize>>;
239
+
173
240
  declare const PALETTES: Readonly<Record<PaletteId, Palette>>;
174
241
 
175
242
  declare const FONT_SETS: Readonly<Record<FontSetId, FontSet>>;
176
243
 
177
- interface JsonSchema {
178
- $schema?: string;
179
- $id?: string;
180
- title?: string;
181
- description?: string;
182
- type?: 'object' | 'array' | 'string' | 'number' | 'integer';
183
- properties?: Record<string, JsonSchema>;
184
- required?: string[];
185
- additionalProperties?: boolean;
186
- enum?: readonly (string | number)[];
187
- const?: string | number;
188
- minLength?: number;
189
- maxLength?: number;
190
- minimum?: number;
191
- maximum?: number;
192
- items?: JsonSchema;
193
- minItems?: number;
194
- maxItems?: number;
195
- }
196
-
197
244
  declare const flierDocSchema: JsonSchema;
198
245
 
199
246
  type FlierDocResult = {
@@ -233,4 +280,4 @@ declare function defaultLayoutFor(format: FormatId): LayoutId;
233
280
  declare const kizombaWorkshop: FlierDoc;
234
281
  declare const kizombaWorkshopDocs: FlierDoc[];
235
282
 
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 };
283
+ 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, LINE_KEY_PATTERN, type LayoutCatalogueEntry, LayoutId, LineAlign, type LineKey, type LineStyle, type LineTie, LineTieKind, 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, sameSize, sameWidth, validateFlierDoc };
package/dist/index.d.ts CHANGED
@@ -45,11 +45,41 @@ declare enum PictureAnchor {
45
45
  Bottom = "bottom"
46
46
  }
47
47
 
48
- interface FormatSize {
49
- width: number;
50
- height: number;
48
+ declare enum LineAlign {
49
+ Left = "left",
50
+ Center = "center",
51
+ Right = "right"
52
+ }
53
+
54
+ declare enum LineTieKind {
55
+ Width = "width",
56
+ Size = "size"
51
57
  }
52
- declare const FORMAT_SIZES: Readonly<Record<FormatId, FormatSize>>;
58
+
59
+ interface JsonSchema {
60
+ $schema?: string;
61
+ $id?: string;
62
+ title?: string;
63
+ description?: string;
64
+ type?: 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean';
65
+ properties?: Record<string, JsonSchema>;
66
+ required?: string[];
67
+ additionalProperties?: boolean | JsonSchema;
68
+ propertyNames?: JsonSchema;
69
+ enum?: readonly (string | number)[];
70
+ const?: string | number;
71
+ minLength?: number;
72
+ maxLength?: number;
73
+ pattern?: string;
74
+ minimum?: number;
75
+ maximum?: number;
76
+ items?: JsonSchema;
77
+ minItems?: number;
78
+ maxItems?: number;
79
+ }
80
+
81
+ /** Every text line a style or tie can name: block fields by path, list items by index. */
82
+ declare const LINE_KEY_PATTERN = "^(title|titleBottom|script|footer|includes[.]heading|includes[.]items[.][0-5]|venue[.][0-2]|schedule[.][0-5][.](label|time)|prices[.][0-3][.](amount|label)|items[.][0-7][.](date|price|schedule[.][0-5]))$";
53
83
 
54
84
  interface ScheduleRow {
55
85
  label: string;
@@ -97,6 +127,31 @@ interface FlierDoc {
97
127
  logo?: LogoSlot;
98
128
  blocks: FlierBlocks;
99
129
  items?: ListItem[];
130
+ tuning?: PosterTuning;
131
+ lineStyles?: Record<LineKey, LineStyle | undefined>;
132
+ lineTies?: LineTie[];
133
+ }
134
+ /** A text line path such as "title", "venue.1", "schedule.0.time" or "items.2.date" (see LINE_KEY_PATTERN). */
135
+ type LineKey = string;
136
+ /** Optional per-line overrides of the theme; an absent field keeps the theme value. letterSpacing is in em. */
137
+ interface LineStyle {
138
+ font?: string;
139
+ sizeScale?: number;
140
+ color?: string;
141
+ weight?: number;
142
+ italic?: boolean;
143
+ letterSpacing?: number;
144
+ align?: LineAlign;
145
+ }
146
+ /** Two lines drawn at one width (width) or one font size (size). */
147
+ interface LineTie {
148
+ kind: LineTieKind;
149
+ lines: [LineKey, LineKey];
150
+ }
151
+ /** Optional per-theme spacing and size overrides; an absent field keeps the layout default. */
152
+ interface PosterTuning {
153
+ headerGap?: number;
154
+ itemDateScale?: number;
100
155
  }
101
156
  interface Rect {
102
157
  x: number;
@@ -121,6 +176,7 @@ interface PosterContext {
121
176
  textAlign: string;
122
177
  textBaseline: string;
123
178
  globalAlpha: number;
179
+ letterSpacing?: string;
124
180
  save(): void;
125
181
  restore(): void;
126
182
  fillRect(x: number, y: number, w: number, h: number): void;
@@ -170,30 +226,21 @@ interface FontSet {
170
226
  body: string;
171
227
  }
172
228
 
229
+ /** Returns a copy of the doc whose lines a and b draw at one width (within 1px), grown to the wider inside the margins. */
230
+ declare const sameWidth: (doc: FlierDoc, a: LineKey, b: LineKey) => FlierDoc;
231
+ /** Returns a copy of the doc whose lines a and b take one font size, the larger one where it fits. */
232
+ declare const sameSize: (doc: FlierDoc, a: LineKey, b: LineKey) => FlierDoc;
233
+
234
+ interface FormatSize {
235
+ width: number;
236
+ height: number;
237
+ }
238
+ declare const FORMAT_SIZES: Readonly<Record<FormatId, FormatSize>>;
239
+
173
240
  declare const PALETTES: Readonly<Record<PaletteId, Palette>>;
174
241
 
175
242
  declare const FONT_SETS: Readonly<Record<FontSetId, FontSet>>;
176
243
 
177
- interface JsonSchema {
178
- $schema?: string;
179
- $id?: string;
180
- title?: string;
181
- description?: string;
182
- type?: 'object' | 'array' | 'string' | 'number' | 'integer';
183
- properties?: Record<string, JsonSchema>;
184
- required?: string[];
185
- additionalProperties?: boolean;
186
- enum?: readonly (string | number)[];
187
- const?: string | number;
188
- minLength?: number;
189
- maxLength?: number;
190
- minimum?: number;
191
- maximum?: number;
192
- items?: JsonSchema;
193
- minItems?: number;
194
- maxItems?: number;
195
- }
196
-
197
244
  declare const flierDocSchema: JsonSchema;
198
245
 
199
246
  type FlierDocResult = {
@@ -233,4 +280,4 @@ declare function defaultLayoutFor(format: FormatId): LayoutId;
233
280
  declare const kizombaWorkshop: FlierDoc;
234
281
  declare const kizombaWorkshopDocs: FlierDoc[];
235
282
 
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 };
283
+ 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, LINE_KEY_PATTERN, type LayoutCatalogueEntry, LayoutId, LineAlign, type LineKey, type LineStyle, type LineTie, LineTieKind, 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, sameSize, sameWidth, validateFlierDoc };