@dloizides/poster-render 0.2.7 → 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/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,6 +308,18 @@ 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],
@@ -977,8 +1004,7 @@ function render(input, assets, canvas) {
977
1004
  const u = Math.min(width, height) / BASE2;
978
1005
  const { geo, zones, head, body, sides } = fitToFloor(ctx, { doc, palette, fonts, width, height });
979
1006
  ctx.globalAlpha = 1;
980
- ctx.fillStyle = palette.background;
981
- ctx.fillRect(0, 0, width, height);
1007
+ paintGround(ctx, doc.background, palette, { width, height });
982
1008
  if (doc.background === "tint" /* Tint */) {
983
1009
  ctx.fillStyle = palette.tint;
984
1010
  [geo.header, geo.body].forEach((r3) => ctx.fillRect(r3.x, r3.y, r3.w, r3.h));