@dloizides/poster-render 0.4.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,13 @@
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
+
3
11
  ## 0.4.0
4
12
 
5
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.
package/README.md CHANGED
@@ -48,6 +48,21 @@ The font sets name CSS families (`FONT_SETS`). The host loads them before `rende
48
48
 
49
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.
50
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
+
51
66
  ## Schema version policy
52
67
 
53
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;
@@ -98,6 +128,25 @@ interface FlierDoc {
98
128
  blocks: FlierBlocks;
99
129
  items?: ListItem[];
100
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];
101
150
  }
102
151
  /** Optional per-theme spacing and size overrides; an absent field keeps the layout default. */
103
152
  interface PosterTuning {
@@ -127,6 +176,7 @@ interface PosterContext {
127
176
  textAlign: string;
128
177
  textBaseline: string;
129
178
  globalAlpha: number;
179
+ letterSpacing?: string;
130
180
  save(): void;
131
181
  restore(): void;
132
182
  fillRect(x: number, y: number, w: number, h: number): void;
@@ -176,30 +226,21 @@ interface FontSet {
176
226
  body: string;
177
227
  }
178
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
+
179
240
  declare const PALETTES: Readonly<Record<PaletteId, Palette>>;
180
241
 
181
242
  declare const FONT_SETS: Readonly<Record<FontSetId, FontSet>>;
182
243
 
183
- interface JsonSchema {
184
- $schema?: string;
185
- $id?: string;
186
- title?: string;
187
- description?: string;
188
- type?: 'object' | 'array' | 'string' | 'number' | 'integer';
189
- properties?: Record<string, JsonSchema>;
190
- required?: string[];
191
- additionalProperties?: boolean;
192
- enum?: readonly (string | number)[];
193
- const?: string | number;
194
- minLength?: number;
195
- maxLength?: number;
196
- minimum?: number;
197
- maximum?: number;
198
- items?: JsonSchema;
199
- minItems?: number;
200
- maxItems?: number;
201
- }
202
-
203
244
  declare const flierDocSchema: JsonSchema;
204
245
 
205
246
  type FlierDocResult = {
@@ -239,4 +280,4 @@ declare function defaultLayoutFor(format: FormatId): LayoutId;
239
280
  declare const kizombaWorkshop: FlierDoc;
240
281
  declare const kizombaWorkshopDocs: FlierDoc[];
241
282
 
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 };
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;
@@ -98,6 +128,25 @@ interface FlierDoc {
98
128
  blocks: FlierBlocks;
99
129
  items?: ListItem[];
100
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];
101
150
  }
102
151
  /** Optional per-theme spacing and size overrides; an absent field keeps the layout default. */
103
152
  interface PosterTuning {
@@ -127,6 +176,7 @@ interface PosterContext {
127
176
  textAlign: string;
128
177
  textBaseline: string;
129
178
  globalAlpha: number;
179
+ letterSpacing?: string;
130
180
  save(): void;
131
181
  restore(): void;
132
182
  fillRect(x: number, y: number, w: number, h: number): void;
@@ -176,30 +226,21 @@ interface FontSet {
176
226
  body: string;
177
227
  }
178
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
+
179
240
  declare const PALETTES: Readonly<Record<PaletteId, Palette>>;
180
241
 
181
242
  declare const FONT_SETS: Readonly<Record<FontSetId, FontSet>>;
182
243
 
183
- interface JsonSchema {
184
- $schema?: string;
185
- $id?: string;
186
- title?: string;
187
- description?: string;
188
- type?: 'object' | 'array' | 'string' | 'number' | 'integer';
189
- properties?: Record<string, JsonSchema>;
190
- required?: string[];
191
- additionalProperties?: boolean;
192
- enum?: readonly (string | number)[];
193
- const?: string | number;
194
- minLength?: number;
195
- maxLength?: number;
196
- minimum?: number;
197
- maximum?: number;
198
- items?: JsonSchema;
199
- minItems?: number;
200
- maxItems?: number;
201
- }
202
-
203
244
  declare const flierDocSchema: JsonSchema;
204
245
 
205
246
  type FlierDocResult = {
@@ -239,4 +280,4 @@ declare function defaultLayoutFor(format: FormatId): LayoutId;
239
280
  declare const kizombaWorkshop: FlierDoc;
240
281
  declare const kizombaWorkshopDocs: FlierDoc[];
241
282
 
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 };
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 };