@dloizides/poster-render 0.2.7 → 0.4.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 +9 -0
- package/README.md +1 -0
- package/dist/index.d.mts +21 -5
- package/dist/index.d.ts +21 -5
- package/dist/index.js +57 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
var BackgroundStyle = /* @__PURE__ */ ((BackgroundStyle2) => {
|
|
3
3
|
BackgroundStyle2["Solid"] = "solid";
|
|
4
4
|
BackgroundStyle2["Tint"] = "tint";
|
|
5
|
+
BackgroundStyle2["Horizon"] = "horizon";
|
|
5
6
|
return BackgroundStyle2;
|
|
6
7
|
})(BackgroundStyle || {});
|
|
7
8
|
|
|
@@ -10,6 +11,7 @@ var FontSetId = /* @__PURE__ */ ((FontSetId2) => {
|
|
|
10
11
|
FontSetId2["Classic"] = "classic";
|
|
11
12
|
FontSetId2["Modern"] = "modern";
|
|
12
13
|
FontSetId2["Elegant"] = "elegant";
|
|
14
|
+
FontSetId2["Coastal"] = "coastal";
|
|
13
15
|
return FontSetId2;
|
|
14
16
|
})(FontSetId || {});
|
|
15
17
|
|
|
@@ -43,6 +45,7 @@ var PaletteId = /* @__PURE__ */ ((PaletteId2) => {
|
|
|
43
45
|
PaletteId2["Night"] = "night";
|
|
44
46
|
PaletteId2["Sea"] = "sea";
|
|
45
47
|
PaletteId2["Rose"] = "rose";
|
|
48
|
+
PaletteId2["GoldenHorizon"] = "golden-horizon";
|
|
46
49
|
return PaletteId2;
|
|
47
50
|
})(PaletteId || {});
|
|
48
51
|
|
|
@@ -68,6 +71,17 @@ var PALETTES = {
|
|
|
68
71
|
["sand" /* Sand */]: { background: "#f5f4f2", tint: "#ece8e3", title: "#958a80", accent: "#e9b47f", ink: "#5f564f", soft: "#b3a89e", card: "#ffffff", arch: "#ede8e2" },
|
|
69
72
|
["night" /* Night */]: { background: "#1c1a17", tint: "#25221e", title: "#e8dccb", accent: "#e9b47f", ink: "#f4efe8", soft: "#9c9284", card: "#2c2824", arch: "#25221f" },
|
|
70
73
|
["sea" /* Sea */]: { background: "#eef4f3", tint: "#e1ecea", title: "#4f7d7a", accent: "#e07a5f", ink: "#2f3e46", soft: "#8aa3a1", card: "#ffffff", arch: "#e4ecea" },
|
|
74
|
+
["golden-horizon" /* GoldenHorizon */]: {
|
|
75
|
+
background: "#dce5e7",
|
|
76
|
+
tint: "#d3dee1",
|
|
77
|
+
title: "#2f566f",
|
|
78
|
+
accent: "#8a4325",
|
|
79
|
+
ink: "#1f2d36",
|
|
80
|
+
soft: "#46606f",
|
|
81
|
+
card: "#f4f1ec",
|
|
82
|
+
arch: "#c7d4d6",
|
|
83
|
+
sky: [[0, "#bfd3d8"], [0.55, "#d4dddd"], [1, "#eadccb"]]
|
|
84
|
+
},
|
|
71
85
|
["rose" /* Rose */]: { background: "#f8efec", tint: "#f1e2dd", title: "#9b6b63", accent: "#c9846f", ink: "#4a3934", soft: "#b39a92", card: "#ffffff", arch: "#f1e5e1" }
|
|
72
86
|
};
|
|
73
87
|
|
|
@@ -75,7 +89,8 @@ var PALETTES = {
|
|
|
75
89
|
var FONT_SETS = {
|
|
76
90
|
["classic" /* Classic */]: { display: '"Oswald", "Arial Narrow", sans-serif', script: '"Sacramento", cursive', body: '"Fredoka", sans-serif' },
|
|
77
91
|
["modern" /* Modern */]: { display: '"Bebas Neue", "Arial Narrow", sans-serif', script: '"Great Vibes", cursive', body: '"Montserrat", sans-serif' },
|
|
78
|
-
["elegant" /* Elegant */]: { display: '"Playfair Display", serif', script: '"Allura", cursive', body: '"Lato", sans-serif' }
|
|
92
|
+
["elegant" /* Elegant */]: { display: '"Playfair Display", serif', script: '"Allura", cursive', body: '"Lato", sans-serif' },
|
|
93
|
+
["coastal" /* Coastal */]: { display: '"Fraunces", Georgia, serif', script: '"Allura", cursive', body: '"Jost", sans-serif' }
|
|
79
94
|
};
|
|
80
95
|
|
|
81
96
|
// src/schema/flierDocSchema.ts
|
|
@@ -86,6 +101,9 @@ var MAX_ITEMS = 8;
|
|
|
86
101
|
var MAX_PRICES = 4;
|
|
87
102
|
var MAX_VENUE = 3;
|
|
88
103
|
var MIN_SCALE = 0.3;
|
|
104
|
+
var MAX_HEADER_GAP = 200;
|
|
105
|
+
var MIN_DATE_SCALE = 0.5;
|
|
106
|
+
var MAX_DATE_SCALE = 2;
|
|
89
107
|
var text = (maxLength) => ({ type: "string", minLength: 1, maxLength });
|
|
90
108
|
var scheduleRow = {
|
|
91
109
|
type: "object",
|
|
@@ -151,6 +169,14 @@ var flierDocSchema = {
|
|
|
151
169
|
},
|
|
152
170
|
logo: { type: "object", required: ["imageId"], additionalProperties: false, properties: { imageId: text(SHORT) } },
|
|
153
171
|
blocks,
|
|
172
|
+
tuning: {
|
|
173
|
+
type: "object",
|
|
174
|
+
additionalProperties: false,
|
|
175
|
+
properties: {
|
|
176
|
+
headerGap: { type: "number", minimum: 0, maximum: MAX_HEADER_GAP },
|
|
177
|
+
itemDateScale: { type: "number", minimum: MIN_DATE_SCALE, maximum: MAX_DATE_SCALE }
|
|
178
|
+
}
|
|
179
|
+
},
|
|
154
180
|
items: {
|
|
155
181
|
type: "array",
|
|
156
182
|
minItems: 1,
|
|
@@ -291,6 +317,18 @@ function missingAssets(doc, assets) {
|
|
|
291
317
|
return errors;
|
|
292
318
|
}
|
|
293
319
|
|
|
320
|
+
// src/render/background.ts
|
|
321
|
+
function paintGround(ctx, style, palette, size) {
|
|
322
|
+
ctx.fillStyle = palette.background;
|
|
323
|
+
if (style === "horizon" /* Horizon */) {
|
|
324
|
+
const stops = palette.sky ?? [[0, palette.background], [1, palette.tint]];
|
|
325
|
+
const sky = ctx.createLinearGradient(0, 0, 0, size.height);
|
|
326
|
+
stops.forEach(([offset, color]) => sky.addColorStop(offset, color));
|
|
327
|
+
ctx.fillStyle = sky;
|
|
328
|
+
}
|
|
329
|
+
ctx.fillRect(0, 0, size.width, size.height);
|
|
330
|
+
}
|
|
331
|
+
|
|
294
332
|
// src/layout/layoutSpecs.ts
|
|
295
333
|
var flanksBeside = (pic, top, bottom2, m) => [
|
|
296
334
|
[m, top, pic[0] - 2 * m, bottom2 - top],
|
|
@@ -488,8 +526,8 @@ function headerGroups(doc, p, u) {
|
|
|
488
526
|
const lines = [l.display(b.title, SIZE.title), b.script ? l.script(b.script, SIZE.headerScript) : void 0, b.titleBottom ? l.display(b.titleBottom, SIZE.title) : void 0];
|
|
489
527
|
return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
|
|
490
528
|
}
|
|
491
|
-
function itemGroup(item, l, u) {
|
|
492
|
-
const lines = [l.script(item.date, SIZE.itemDate)];
|
|
529
|
+
function itemGroup(item, l, u, dateScale) {
|
|
530
|
+
const lines = [l.script(item.date, SIZE.itemDate * dateScale)];
|
|
493
531
|
item.schedule.forEach((row) => lines.push(l.strong(`${row.label} ${row.time}`, SIZE.itemRow)));
|
|
494
532
|
if (item.price) {
|
|
495
533
|
lines.push(l.accent(item.price, SIZE.itemRow));
|
|
@@ -525,8 +563,8 @@ function eventGroups(doc, l, u, options) {
|
|
|
525
563
|
});
|
|
526
564
|
return groups;
|
|
527
565
|
}
|
|
528
|
-
function listGroups(doc, l, u) {
|
|
529
|
-
const groups = (doc.items ?? []).map((item) => itemGroup(item, l, u));
|
|
566
|
+
function listGroups(doc, l, u, dateScale) {
|
|
567
|
+
const groups = (doc.items ?? []).map((item) => itemGroup(item, l, u, dateScale));
|
|
530
568
|
const prices = doc.blocks.prices?.map((row) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice)) ?? [];
|
|
531
569
|
if (prices.length > 0) {
|
|
532
570
|
groups.push({ lines: prices, gapAfter: GAP.row * u });
|
|
@@ -547,7 +585,7 @@ function bodyGroups(doc, p, u, options = {}) {
|
|
|
547
585
|
const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
|
|
548
586
|
groups.push({ lines: b.venue.map((v) => l.venue(v, size)), gapAfter: GAP.venue * u, rule: { color: p.accent, height: GAP.rule * u }, ruleBelow: true, icon: { color: p.accent, glyph: p.background }, keepWithNext });
|
|
549
587
|
}
|
|
550
|
-
groups.push(...isList ? listGroups(doc, l, u) : eventGroups(doc, l, u, options));
|
|
588
|
+
groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, options));
|
|
551
589
|
if (b.includes) {
|
|
552
590
|
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));
|
|
553
591
|
groups.push({ lines, gapAfter: GAP.includes * u, uniform: true, keepWithNext: b.footer !== void 0, attachNext: b.footer !== void 0 });
|
|
@@ -789,15 +827,25 @@ function splitHeader(header, hasLogo) {
|
|
|
789
827
|
const logoW = hasLogo ? Math.round(header.w * LOGO_SHARE) : 0;
|
|
790
828
|
return { text: { ...header, w: header.w - logoW * 1.1 }, logo: { ...header, x: header.x + header.w - logoW, w: logoW } };
|
|
791
829
|
}
|
|
830
|
+
function closeHeaderGap(geo, head, gap, u) {
|
|
831
|
+
const { header, body } = geo;
|
|
832
|
+
const stacked = header.y + header.h <= body.y && header.x < body.x + body.w && body.x < header.x + header.w;
|
|
833
|
+
if (gap === void 0 || !stacked || head.texts.length === 0) {
|
|
834
|
+
return geo;
|
|
835
|
+
}
|
|
836
|
+
const top = Math.round(Math.max(...head.texts.map((t) => t.box.y + t.box.h)) + gap * u);
|
|
837
|
+
return top < body.y ? { ...geo, body: { ...body, y: top, h: body.h + body.y - top } } : geo;
|
|
838
|
+
}
|
|
792
839
|
function flowAll(ctx, input, geo, reflow) {
|
|
793
840
|
const { doc, palette, fonts } = input;
|
|
794
841
|
const u = Math.min(input.width, input.height) / BASE;
|
|
795
842
|
const zones = geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0);
|
|
796
843
|
const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
|
|
797
844
|
const flanks = geo.flanks ?? [];
|
|
798
|
-
const
|
|
845
|
+
const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
|
|
846
|
+
const body = flow(ctx, bodyGroups(doc, palette, u, { withPrices: flanks.length === 0, compact: reflow.compact, wrap: reflow.wrap, dateScale: doc.tuning?.itemDateScale }), tight.body, fonts);
|
|
799
847
|
const sides = flanks.length > 0 ? equalFlanks(ctx, flankPriceGroups(doc, palette, u), flanks, fonts) : [emptyFlow()];
|
|
800
|
-
return { geo, zones, head, body, sides };
|
|
848
|
+
return { geo: tight, zones, head, body, sides };
|
|
801
849
|
}
|
|
802
850
|
var smallest = (t) => Math.min(Infinity, ...[t.head, t.body, ...t.sides].flatMap((f) => f.texts.map((x) => x.box.h / LINE_HEIGHT3)));
|
|
803
851
|
function shiftHeader(geo, shift) {
|
|
@@ -975,8 +1023,7 @@ function render(input, assets, canvas) {
|
|
|
975
1023
|
const u = Math.min(width, height) / BASE2;
|
|
976
1024
|
const { geo, zones, head, body, sides } = fitToFloor(ctx, { doc, palette, fonts, width, height });
|
|
977
1025
|
ctx.globalAlpha = 1;
|
|
978
|
-
ctx.
|
|
979
|
-
ctx.fillRect(0, 0, width, height);
|
|
1026
|
+
paintGround(ctx, doc.background, palette, { width, height });
|
|
980
1027
|
if (doc.background === "tint" /* Tint */) {
|
|
981
1028
|
ctx.fillStyle = palette.tint;
|
|
982
1029
|
[geo.header, geo.body].forEach((r3) => ctx.fillRect(r3.x, r3.y, r3.w, r3.h));
|