@dloizides/poster-render 0.2.6 → 0.3.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 +5 -0
- package/dist/index.d.mts +15 -5
- package/dist/index.d.ts +15 -5
- package/dist/index.js +45 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.7
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
- The footer stays attached under the includes list: columns never spread space between them, and both stay in one column.
|
|
7
|
+
|
|
3
8
|
## 0.2.5
|
|
4
9
|
|
|
5
10
|
- Own-key checks: the schema validator and the asset lookup use `Object.hasOwn`, so a `__proto__` key is rejected and an imageId such as `constructor` is reported missing.
|
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 {
|
|
@@ -109,9 +112,12 @@ type PosterAssets = Record<string, PosterImage | undefined>;
|
|
|
109
112
|
interface TextMetricsLike {
|
|
110
113
|
width: number;
|
|
111
114
|
}
|
|
115
|
+
interface PosterGradient {
|
|
116
|
+
addColorStop(offset: number, color: string): void;
|
|
117
|
+
}
|
|
112
118
|
interface PosterContext {
|
|
113
119
|
font: string;
|
|
114
|
-
fillStyle: string;
|
|
120
|
+
fillStyle: string | PosterGradient;
|
|
115
121
|
textAlign: string;
|
|
116
122
|
textBaseline: string;
|
|
117
123
|
globalAlpha: number;
|
|
@@ -127,6 +133,7 @@ interface PosterContext {
|
|
|
127
133
|
arc(x: number, y: number, r: number, start: number, end: number): void;
|
|
128
134
|
closePath(): void;
|
|
129
135
|
fill(): void;
|
|
136
|
+
createLinearGradient(x0: number, y0: number, x1: number, y1: number): PosterGradient;
|
|
130
137
|
}
|
|
131
138
|
interface PosterCanvas {
|
|
132
139
|
width: number;
|
|
@@ -153,7 +160,10 @@ interface Palette {
|
|
|
153
160
|
soft: string;
|
|
154
161
|
card: string;
|
|
155
162
|
arch: string;
|
|
163
|
+
sky?: readonly SkyStop[];
|
|
156
164
|
}
|
|
165
|
+
/** One gradient stop of a horizon sky: offset 0 (top) to 1 (bottom) and its colour. */
|
|
166
|
+
type SkyStop = readonly [number, string];
|
|
157
167
|
interface FontSet {
|
|
158
168
|
display: string;
|
|
159
169
|
script: string;
|
|
@@ -223,4 +233,4 @@ declare function defaultLayoutFor(format: FormatId): LayoutId;
|
|
|
223
233
|
declare const kizombaWorkshop: FlierDoc;
|
|
224
234
|
declare const kizombaWorkshopDocs: FlierDoc[];
|
|
225
235
|
|
|
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 };
|
|
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 };
|
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 {
|
|
@@ -109,9 +112,12 @@ type PosterAssets = Record<string, PosterImage | undefined>;
|
|
|
109
112
|
interface TextMetricsLike {
|
|
110
113
|
width: number;
|
|
111
114
|
}
|
|
115
|
+
interface PosterGradient {
|
|
116
|
+
addColorStop(offset: number, color: string): void;
|
|
117
|
+
}
|
|
112
118
|
interface PosterContext {
|
|
113
119
|
font: string;
|
|
114
|
-
fillStyle: string;
|
|
120
|
+
fillStyle: string | PosterGradient;
|
|
115
121
|
textAlign: string;
|
|
116
122
|
textBaseline: string;
|
|
117
123
|
globalAlpha: number;
|
|
@@ -127,6 +133,7 @@ interface PosterContext {
|
|
|
127
133
|
arc(x: number, y: number, r: number, start: number, end: number): void;
|
|
128
134
|
closePath(): void;
|
|
129
135
|
fill(): void;
|
|
136
|
+
createLinearGradient(x0: number, y0: number, x1: number, y1: number): PosterGradient;
|
|
130
137
|
}
|
|
131
138
|
interface PosterCanvas {
|
|
132
139
|
width: number;
|
|
@@ -153,7 +160,10 @@ interface Palette {
|
|
|
153
160
|
soft: string;
|
|
154
161
|
card: string;
|
|
155
162
|
arch: string;
|
|
163
|
+
sky?: readonly SkyStop[];
|
|
156
164
|
}
|
|
165
|
+
/** One gradient stop of a horizon sky: offset 0 (top) to 1 (bottom) and its colour. */
|
|
166
|
+
type SkyStop = readonly [number, string];
|
|
157
167
|
interface FontSet {
|
|
158
168
|
display: string;
|
|
159
169
|
script: string;
|
|
@@ -223,4 +233,4 @@ declare function defaultLayoutFor(format: FormatId): LayoutId;
|
|
|
223
233
|
declare const kizombaWorkshop: FlierDoc;
|
|
224
234
|
declare const kizombaWorkshopDocs: FlierDoc[];
|
|
225
235
|
|
|
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 };
|
|
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 };
|
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
|
|
@@ -293,13 +308,25 @@ function missingAssets(doc, assets) {
|
|
|
293
308
|
return errors;
|
|
294
309
|
}
|
|
295
310
|
|
|
311
|
+
// src/render/background.ts
|
|
312
|
+
function paintGround(ctx, style, palette, size) {
|
|
313
|
+
ctx.fillStyle = palette.background;
|
|
314
|
+
if (style === "horizon" /* Horizon */) {
|
|
315
|
+
const stops = palette.sky ?? [[0, palette.background], [1, palette.tint]];
|
|
316
|
+
const sky = ctx.createLinearGradient(0, 0, 0, size.height);
|
|
317
|
+
stops.forEach(([offset, color]) => sky.addColorStop(offset, color));
|
|
318
|
+
ctx.fillStyle = sky;
|
|
319
|
+
}
|
|
320
|
+
ctx.fillRect(0, 0, size.width, size.height);
|
|
321
|
+
}
|
|
322
|
+
|
|
296
323
|
// src/layout/layoutSpecs.ts
|
|
297
324
|
var flanksBeside = (pic, top, bottom2, m) => [
|
|
298
325
|
[m, top, pic[0] - 2 * m, bottom2 - top],
|
|
299
326
|
[pic[0] + pic[2] + m, top, 1 - pic[0] - pic[2] - 2 * m, bottom2 - top]
|
|
300
327
|
];
|
|
301
328
|
var ARCH_PIC = [0.22, 0.42, 0.56, 0.58];
|
|
302
|
-
var PHONE_ARCH_PIC = [0.2, 0.
|
|
329
|
+
var PHONE_ARCH_PIC = [0.2, 0.47, 0.6, 0.53];
|
|
303
330
|
var DESK_ARCH_PIC = [0.355, 0.07, 0.32, 0.93];
|
|
304
331
|
var ARCH_LANDSCAPE = {
|
|
305
332
|
header: [0.04, 0.06, 0.3, 0.5],
|
|
@@ -319,7 +346,7 @@ var LAYOUT_SPECS = {
|
|
|
319
346
|
landscape: { header: [0.04, 0.2, 0.52, 0.3], body: [0.04, 0.52, 0.52, 0.42], picture: [0.6, 0.12, 0.4, 0.88], alignX: 1 }
|
|
320
347
|
},
|
|
321
348
|
["phone-arch" /* PhoneArch */]: {
|
|
322
|
-
portrait: { header: [0.045, 0.
|
|
349
|
+
portrait: { header: [0.045, 0.05, 0.91, 0.16], body: [0.045, 0.22, 0.91, 0.21], picture: PHONE_ARCH_PIC, alignX: 0.5, flanks: flanksBeside(PHONE_ARCH_PIC, 0.5, 0.94, 0.03), arch: 0.08 },
|
|
323
350
|
landscape: { ...ARCH_LANDSCAPE, header: [0.04, 0.16, 0.3, 0.42], picture: [0.36, 0.16, 0.3, 0.84] }
|
|
324
351
|
},
|
|
325
352
|
["desktop-safe" /* DesktopSafe */]: {
|
|
@@ -552,7 +579,7 @@ function bodyGroups(doc, p, u, options = {}) {
|
|
|
552
579
|
groups.push(...isList ? listGroups(doc, l, u) : eventGroups(doc, l, u, options));
|
|
553
580
|
if (b.includes) {
|
|
554
581
|
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
|
-
groups.push({ lines, gapAfter: GAP.includes * u, uniform: true });
|
|
582
|
+
groups.push({ lines, gapAfter: GAP.includes * u, uniform: true, keepWithNext: b.footer !== void 0, attachNext: b.footer !== void 0 });
|
|
556
583
|
}
|
|
557
584
|
if (b.footer) {
|
|
558
585
|
groups.push({ lines: wrapped(l.soft(b.footer, SIZE.small), options.wrap), gapAfter: 0 });
|
|
@@ -641,11 +668,15 @@ function placeGroup(m, at, out) {
|
|
|
641
668
|
function placeColumn(groups, at, out) {
|
|
642
669
|
const { k, col, spread = 0 } = at;
|
|
643
670
|
let h = 0;
|
|
644
|
-
|
|
645
|
-
h += placeGroup(g, { k, col, y0: col.y + h }, out)
|
|
646
|
-
|
|
647
|
-
|
|
671
|
+
groups.forEach((g, i) => {
|
|
672
|
+
h += placeGroup(g, { k, col, y0: col.y + h }, out);
|
|
673
|
+
if (i < groups.length - 1 && g.group.attachNext !== true) {
|
|
674
|
+
h += spread;
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
return h;
|
|
648
678
|
}
|
|
679
|
+
var spreadGaps = (groups) => groups.slice(0, -1).filter((g) => g.group.attachNext !== true).length;
|
|
649
680
|
var columnSum = (heights, from, to) => heights.slice(from, to).reduce((a, b) => a + b, 0);
|
|
650
681
|
var tallest = (heights, cut) => {
|
|
651
682
|
const left = heights.slice(0, cut).reduce((a, b) => a + b, 0);
|
|
@@ -725,7 +756,10 @@ function flow(ctx, groups, zone, fonts) {
|
|
|
725
756
|
const out = emptyFlow();
|
|
726
757
|
const heights = columns.map((c) => placeColumn(c.groups, { k: lo, col: c.col }, null));
|
|
727
758
|
const end = Math.max(...heights);
|
|
728
|
-
columns.forEach((c, i) =>
|
|
759
|
+
columns.forEach((c, i) => {
|
|
760
|
+
const gaps = spreadGaps(c.groups);
|
|
761
|
+
placeColumn(c.groups, { k: lo, col: c.col, spread: gaps > 0 && columns.length > 1 ? (end - (heights[i] ?? end)) / gaps : 0 }, out);
|
|
762
|
+
});
|
|
729
763
|
const lines = groups.flatMap((g) => g.lines);
|
|
730
764
|
out.texts.forEach((t, i) => {
|
|
731
765
|
const line = lines[i];
|
|
@@ -970,8 +1004,7 @@ function render(input, assets, canvas) {
|
|
|
970
1004
|
const u = Math.min(width, height) / BASE2;
|
|
971
1005
|
const { geo, zones, head, body, sides } = fitToFloor(ctx, { doc, palette, fonts, width, height });
|
|
972
1006
|
ctx.globalAlpha = 1;
|
|
973
|
-
ctx.
|
|
974
|
-
ctx.fillRect(0, 0, width, height);
|
|
1007
|
+
paintGround(ctx, doc.background, palette, { width, height });
|
|
975
1008
|
if (doc.background === "tint" /* Tint */) {
|
|
976
1009
|
ctx.fillStyle = palette.tint;
|
|
977
1010
|
[geo.header, geo.body].forEach((r3) => ctx.fillRect(r3.x, r3.y, r3.w, r3.h));
|
|
@@ -1030,7 +1063,7 @@ var LAYOUT_CATALOGUE = [
|
|
|
1030
1063
|
{ id: "picture-bottom" /* PictureBottom */, designId: "picture-bottom", label: "Picture bottom", description: "Titles and details on top, the picture across the bottom half.", formats: POSTERS },
|
|
1031
1064
|
{ id: "list" /* List */, designId: "list", label: "Upcoming list", description: "Several dated events as a list beside the picture.", formats: POSTERS },
|
|
1032
1065
|
{ id: "phone-clock-safe" /* PhoneClockSafe */, designId: "P-A", label: "Phone, clock clear", description: "Lock-screen wallpaper: top kept clear for the clock, details on the left, picture on the right.", formats: ["phone" /* Phone */] },
|
|
1033
|
-
{ id: "phone-arch" /* PhoneArch */, designId: "P-B", label: "Phone arch", description: "Lock-screen wallpaper:
|
|
1066
|
+
{ id: "phone-arch" /* PhoneArch */, designId: "P-B", label: "Phone arch", description: "Lock-screen wallpaper: titles at the top, details under them, the picture in an arch at the bottom.", formats: ["phone" /* Phone */] },
|
|
1034
1067
|
{ id: "desktop-safe" /* DesktopSafe */, designId: "D-A", label: "Desktop, icons clear", description: "Desktop wallpaper: text on the left clear of desktop icons and the taskbar, the picture on the right.", formats: ["desktop" /* Desktop */] },
|
|
1035
1068
|
{ id: "desktop-arch" /* DesktopArch */, designId: "D-B", label: "Desktop arch", description: "Desktop wallpaper: titles left, the picture in a centred arch, details right.", formats: ["desktop" /* Desktop */] }
|
|
1036
1069
|
];
|