@dloizides/poster-render 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - FlierDoc schema + validator, render, exportPng, 4 layouts, 5 formats, palettes, font sets, Kizomba example.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 dloizides
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,12 @@
1
- # Temporary Holding Version
1
+ # @dloizides/poster-render
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ One JSON document (`FlierDoc`) in, one poster out. Used by Flier Studio (FLIER-1 "Flier Studio").
4
+
5
+ - `flierDocSchema`: JSON Schema of `FlierDoc` (give it to an LLM as `response_format`).
6
+ - `validateFlierDoc(input)`: `{ ok, doc }` or `{ ok: false, errors }`; errors read `blocks.title: is required`.
7
+ - `render(doc, assets, canvas)`: validates first (throws `FlierDocError` before touching the canvas), resizes the canvas to the format, draws, returns a `RenderReport` (picture rect, text and card boxes).
8
+ - `exportPng(canvas)`: PNG `Blob` of the canvas size.
9
+ - Formats: story 1080x1920, post 1080x1350, square 1080x1080, phone 1170x2532, desktop 2560x1440.
10
+ - Layouts: `picture-right`, `picture-left`, `picture-bottom`, `list`. Palettes: `sand`, `night`, `sea`, `rose`. Font sets: `classic`, `modern`, `elegant` (the app loads the web fonts).
11
+ - 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.
12
+ - Example: `kizombaWorkshopDocs` (3 workshops + list flier), `kizombaWorkshop` (the list flier).
@@ -0,0 +1,206 @@
1
+ declare enum BackgroundStyle {
2
+ Solid = "solid",
3
+ Tint = "tint"
4
+ }
5
+
6
+ declare enum FontSetId {
7
+ Classic = "classic",
8
+ Modern = "modern",
9
+ Elegant = "elegant"
10
+ }
11
+
12
+ declare enum FormatId {
13
+ Story = "story",
14
+ Post = "post",
15
+ Square = "square",
16
+ Phone = "phone",
17
+ Desktop = "desktop"
18
+ }
19
+
20
+ declare enum LayoutId {
21
+ PictureRight = "picture-right",
22
+ PictureLeft = "picture-left",
23
+ PictureBottom = "picture-bottom",
24
+ List = "list"
25
+ }
26
+
27
+ declare enum PaletteId {
28
+ Sand = "sand",
29
+ Night = "night",
30
+ Sea = "sea",
31
+ Rose = "rose"
32
+ }
33
+
34
+ declare enum PictureAnchor {
35
+ Top = "top",
36
+ Center = "center",
37
+ Bottom = "bottom"
38
+ }
39
+
40
+ interface FormatSize {
41
+ width: number;
42
+ height: number;
43
+ }
44
+ declare const FORMAT_SIZES: Readonly<Record<FormatId, FormatSize>>;
45
+
46
+ interface ScheduleRow {
47
+ label: string;
48
+ time: string;
49
+ }
50
+ interface PriceRow {
51
+ amount: string;
52
+ label: string;
53
+ }
54
+ interface IncludesBlock {
55
+ heading: string;
56
+ items: string[];
57
+ }
58
+ interface FlierBlocks {
59
+ title: string;
60
+ titleBottom?: string;
61
+ script?: string;
62
+ venue?: string[];
63
+ schedule?: ScheduleRow[];
64
+ prices?: PriceRow[];
65
+ includes?: IncludesBlock;
66
+ footer?: string;
67
+ }
68
+ interface ListItem {
69
+ date: string;
70
+ schedule: ScheduleRow[];
71
+ price?: string;
72
+ }
73
+ interface PictureSlot {
74
+ imageId: string;
75
+ anchor: PictureAnchor;
76
+ scale: number;
77
+ }
78
+ interface LogoSlot {
79
+ imageId: string;
80
+ }
81
+ interface FlierDoc {
82
+ version: 1;
83
+ format: FormatId;
84
+ layout: LayoutId;
85
+ palette: PaletteId;
86
+ fonts: FontSetId;
87
+ background: BackgroundStyle;
88
+ picture?: PictureSlot;
89
+ logo?: LogoSlot;
90
+ blocks: FlierBlocks;
91
+ items?: ListItem[];
92
+ }
93
+ interface Rect {
94
+ x: number;
95
+ y: number;
96
+ w: number;
97
+ h: number;
98
+ }
99
+ interface PosterImage {
100
+ readonly width: number;
101
+ readonly height: number;
102
+ }
103
+ type PosterAssets = Record<string, PosterImage | undefined>;
104
+ interface TextMetricsLike {
105
+ width: number;
106
+ }
107
+ interface PosterContext {
108
+ font: string;
109
+ fillStyle: string;
110
+ textAlign: string;
111
+ textBaseline: string;
112
+ globalAlpha: number;
113
+ save(): void;
114
+ restore(): void;
115
+ fillRect(x: number, y: number, w: number, h: number): void;
116
+ fillText(text: string, x: number, y: number): void;
117
+ measureText(text: string): TextMetricsLike;
118
+ drawImage(image: PosterImage, dx: number, dy: number, dw: number, dh: number): void;
119
+ beginPath(): void;
120
+ moveTo(x: number, y: number): void;
121
+ arcTo(x1: number, y1: number, x2: number, y2: number, r: number): void;
122
+ arc(x: number, y: number, r: number, start: number, end: number): void;
123
+ closePath(): void;
124
+ fill(): void;
125
+ }
126
+ interface PosterCanvas {
127
+ width: number;
128
+ height: number;
129
+ getContext(kind: '2d'): PosterContext | null;
130
+ }
131
+ interface RenderReport {
132
+ width: number;
133
+ height: number;
134
+ picture: Rect | null;
135
+ pictureRegion: Rect;
136
+ textBoxes: Rect[];
137
+ cardBoxes: Rect[];
138
+ }
139
+ interface Palette {
140
+ background: string;
141
+ tint: string;
142
+ title: string;
143
+ accent: string;
144
+ ink: string;
145
+ soft: string;
146
+ card: string;
147
+ }
148
+ interface FontSet {
149
+ display: string;
150
+ script: string;
151
+ body: string;
152
+ }
153
+
154
+ declare const PALETTES: Readonly<Record<PaletteId, Palette>>;
155
+
156
+ declare const FONT_SETS: Readonly<Record<FontSetId, FontSet>>;
157
+
158
+ interface JsonSchema {
159
+ $schema?: string;
160
+ $id?: string;
161
+ title?: string;
162
+ description?: string;
163
+ type?: 'object' | 'array' | 'string' | 'number' | 'integer';
164
+ properties?: Record<string, JsonSchema>;
165
+ required?: string[];
166
+ additionalProperties?: boolean;
167
+ enum?: readonly (string | number)[];
168
+ const?: string | number;
169
+ minLength?: number;
170
+ maxLength?: number;
171
+ minimum?: number;
172
+ maximum?: number;
173
+ items?: JsonSchema;
174
+ minItems?: number;
175
+ maxItems?: number;
176
+ }
177
+
178
+ declare const flierDocSchema: JsonSchema;
179
+
180
+ type FlierDocResult = {
181
+ ok: true;
182
+ doc: FlierDoc;
183
+ } | {
184
+ ok: false;
185
+ errors: string[];
186
+ };
187
+ declare class FlierDocError extends Error {
188
+ readonly errors: string[];
189
+ constructor(errors: string[]);
190
+ }
191
+ /** Checks any input (form, preset file, LLM output) against the FlierDoc schema; errors read "path: problem". */
192
+ declare function validateFlierDoc(input: unknown): FlierDocResult;
193
+
194
+ /** Validates the doc, then draws it on the canvas (resized to the format); throws FlierDocError before touching the canvas. */
195
+ declare function render(input: unknown, assets: PosterAssets, canvas: PosterCanvas): RenderReport;
196
+
197
+ interface DataUrlCanvas {
198
+ toDataURL(type: string): string;
199
+ }
200
+ /** Encodes the canvas as a PNG Blob of the canvas's exact pixel size. */
201
+ declare function exportPng(canvas: DataUrlCanvas): Blob;
202
+
203
+ declare const kizombaWorkshop: FlierDoc;
204
+ declare const kizombaWorkshopDocs: FlierDoc[];
205
+
206
+ 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, 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, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, validateFlierDoc };
@@ -0,0 +1,206 @@
1
+ declare enum BackgroundStyle {
2
+ Solid = "solid",
3
+ Tint = "tint"
4
+ }
5
+
6
+ declare enum FontSetId {
7
+ Classic = "classic",
8
+ Modern = "modern",
9
+ Elegant = "elegant"
10
+ }
11
+
12
+ declare enum FormatId {
13
+ Story = "story",
14
+ Post = "post",
15
+ Square = "square",
16
+ Phone = "phone",
17
+ Desktop = "desktop"
18
+ }
19
+
20
+ declare enum LayoutId {
21
+ PictureRight = "picture-right",
22
+ PictureLeft = "picture-left",
23
+ PictureBottom = "picture-bottom",
24
+ List = "list"
25
+ }
26
+
27
+ declare enum PaletteId {
28
+ Sand = "sand",
29
+ Night = "night",
30
+ Sea = "sea",
31
+ Rose = "rose"
32
+ }
33
+
34
+ declare enum PictureAnchor {
35
+ Top = "top",
36
+ Center = "center",
37
+ Bottom = "bottom"
38
+ }
39
+
40
+ interface FormatSize {
41
+ width: number;
42
+ height: number;
43
+ }
44
+ declare const FORMAT_SIZES: Readonly<Record<FormatId, FormatSize>>;
45
+
46
+ interface ScheduleRow {
47
+ label: string;
48
+ time: string;
49
+ }
50
+ interface PriceRow {
51
+ amount: string;
52
+ label: string;
53
+ }
54
+ interface IncludesBlock {
55
+ heading: string;
56
+ items: string[];
57
+ }
58
+ interface FlierBlocks {
59
+ title: string;
60
+ titleBottom?: string;
61
+ script?: string;
62
+ venue?: string[];
63
+ schedule?: ScheduleRow[];
64
+ prices?: PriceRow[];
65
+ includes?: IncludesBlock;
66
+ footer?: string;
67
+ }
68
+ interface ListItem {
69
+ date: string;
70
+ schedule: ScheduleRow[];
71
+ price?: string;
72
+ }
73
+ interface PictureSlot {
74
+ imageId: string;
75
+ anchor: PictureAnchor;
76
+ scale: number;
77
+ }
78
+ interface LogoSlot {
79
+ imageId: string;
80
+ }
81
+ interface FlierDoc {
82
+ version: 1;
83
+ format: FormatId;
84
+ layout: LayoutId;
85
+ palette: PaletteId;
86
+ fonts: FontSetId;
87
+ background: BackgroundStyle;
88
+ picture?: PictureSlot;
89
+ logo?: LogoSlot;
90
+ blocks: FlierBlocks;
91
+ items?: ListItem[];
92
+ }
93
+ interface Rect {
94
+ x: number;
95
+ y: number;
96
+ w: number;
97
+ h: number;
98
+ }
99
+ interface PosterImage {
100
+ readonly width: number;
101
+ readonly height: number;
102
+ }
103
+ type PosterAssets = Record<string, PosterImage | undefined>;
104
+ interface TextMetricsLike {
105
+ width: number;
106
+ }
107
+ interface PosterContext {
108
+ font: string;
109
+ fillStyle: string;
110
+ textAlign: string;
111
+ textBaseline: string;
112
+ globalAlpha: number;
113
+ save(): void;
114
+ restore(): void;
115
+ fillRect(x: number, y: number, w: number, h: number): void;
116
+ fillText(text: string, x: number, y: number): void;
117
+ measureText(text: string): TextMetricsLike;
118
+ drawImage(image: PosterImage, dx: number, dy: number, dw: number, dh: number): void;
119
+ beginPath(): void;
120
+ moveTo(x: number, y: number): void;
121
+ arcTo(x1: number, y1: number, x2: number, y2: number, r: number): void;
122
+ arc(x: number, y: number, r: number, start: number, end: number): void;
123
+ closePath(): void;
124
+ fill(): void;
125
+ }
126
+ interface PosterCanvas {
127
+ width: number;
128
+ height: number;
129
+ getContext(kind: '2d'): PosterContext | null;
130
+ }
131
+ interface RenderReport {
132
+ width: number;
133
+ height: number;
134
+ picture: Rect | null;
135
+ pictureRegion: Rect;
136
+ textBoxes: Rect[];
137
+ cardBoxes: Rect[];
138
+ }
139
+ interface Palette {
140
+ background: string;
141
+ tint: string;
142
+ title: string;
143
+ accent: string;
144
+ ink: string;
145
+ soft: string;
146
+ card: string;
147
+ }
148
+ interface FontSet {
149
+ display: string;
150
+ script: string;
151
+ body: string;
152
+ }
153
+
154
+ declare const PALETTES: Readonly<Record<PaletteId, Palette>>;
155
+
156
+ declare const FONT_SETS: Readonly<Record<FontSetId, FontSet>>;
157
+
158
+ interface JsonSchema {
159
+ $schema?: string;
160
+ $id?: string;
161
+ title?: string;
162
+ description?: string;
163
+ type?: 'object' | 'array' | 'string' | 'number' | 'integer';
164
+ properties?: Record<string, JsonSchema>;
165
+ required?: string[];
166
+ additionalProperties?: boolean;
167
+ enum?: readonly (string | number)[];
168
+ const?: string | number;
169
+ minLength?: number;
170
+ maxLength?: number;
171
+ minimum?: number;
172
+ maximum?: number;
173
+ items?: JsonSchema;
174
+ minItems?: number;
175
+ maxItems?: number;
176
+ }
177
+
178
+ declare const flierDocSchema: JsonSchema;
179
+
180
+ type FlierDocResult = {
181
+ ok: true;
182
+ doc: FlierDoc;
183
+ } | {
184
+ ok: false;
185
+ errors: string[];
186
+ };
187
+ declare class FlierDocError extends Error {
188
+ readonly errors: string[];
189
+ constructor(errors: string[]);
190
+ }
191
+ /** Checks any input (form, preset file, LLM output) against the FlierDoc schema; errors read "path: problem". */
192
+ declare function validateFlierDoc(input: unknown): FlierDocResult;
193
+
194
+ /** Validates the doc, then draws it on the canvas (resized to the format); throws FlierDocError before touching the canvas. */
195
+ declare function render(input: unknown, assets: PosterAssets, canvas: PosterCanvas): RenderReport;
196
+
197
+ interface DataUrlCanvas {
198
+ toDataURL(type: string): string;
199
+ }
200
+ /** Encodes the canvas as a PNG Blob of the canvas's exact pixel size. */
201
+ declare function exportPng(canvas: DataUrlCanvas): Blob;
202
+
203
+ declare const kizombaWorkshop: FlierDoc;
204
+ declare const kizombaWorkshopDocs: FlierDoc[];
205
+
206
+ 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, 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, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, validateFlierDoc };