@dloizides/poster-render 0.7.0 → 0.8.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 +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +70 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -142,12 +142,18 @@ interface RowTheme {
|
|
|
142
142
|
gap?: number;
|
|
143
143
|
toPicture?: boolean;
|
|
144
144
|
reach?: number;
|
|
145
|
+
lengths?: number[];
|
|
145
146
|
};
|
|
146
147
|
priceLabelScale?: number;
|
|
147
148
|
venue?: {
|
|
148
149
|
body?: boolean;
|
|
149
150
|
bare?: boolean;
|
|
151
|
+
oneLine?: boolean;
|
|
150
152
|
};
|
|
153
|
+
labelScale?: number;
|
|
154
|
+
timeScale?: number;
|
|
155
|
+
timeWeight?: number;
|
|
156
|
+
textWidth?: number;
|
|
151
157
|
}
|
|
152
158
|
interface LogoSlot {
|
|
153
159
|
imageId: string;
|
|
@@ -194,6 +200,11 @@ interface PosterTuning {
|
|
|
194
200
|
scriptTitleGap?: number;
|
|
195
201
|
titleScale?: number;
|
|
196
202
|
titleBottomScale?: number;
|
|
203
|
+
headerTextWidth?: number;
|
|
204
|
+
bodyTop?: number;
|
|
205
|
+
headerHeight?: number;
|
|
206
|
+
titleSpacing?: number;
|
|
207
|
+
scriptScale?: number;
|
|
197
208
|
}
|
|
198
209
|
interface Rect {
|
|
199
210
|
x: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -142,12 +142,18 @@ interface RowTheme {
|
|
|
142
142
|
gap?: number;
|
|
143
143
|
toPicture?: boolean;
|
|
144
144
|
reach?: number;
|
|
145
|
+
lengths?: number[];
|
|
145
146
|
};
|
|
146
147
|
priceLabelScale?: number;
|
|
147
148
|
venue?: {
|
|
148
149
|
body?: boolean;
|
|
149
150
|
bare?: boolean;
|
|
151
|
+
oneLine?: boolean;
|
|
150
152
|
};
|
|
153
|
+
labelScale?: number;
|
|
154
|
+
timeScale?: number;
|
|
155
|
+
timeWeight?: number;
|
|
156
|
+
textWidth?: number;
|
|
151
157
|
}
|
|
152
158
|
interface LogoSlot {
|
|
153
159
|
imageId: string;
|
|
@@ -194,6 +200,11 @@ interface PosterTuning {
|
|
|
194
200
|
scriptTitleGap?: number;
|
|
195
201
|
titleScale?: number;
|
|
196
202
|
titleBottomScale?: number;
|
|
203
|
+
headerTextWidth?: number;
|
|
204
|
+
bodyTop?: number;
|
|
205
|
+
headerHeight?: number;
|
|
206
|
+
titleSpacing?: number;
|
|
207
|
+
scriptScale?: number;
|
|
197
208
|
}
|
|
198
209
|
interface Rect {
|
|
199
210
|
x: number;
|
package/dist/index.js
CHANGED
|
@@ -182,7 +182,7 @@ var FONT_SETS = {
|
|
|
182
182
|
["classic" /* Classic */]: { display: '"Oswald", "Arial Narrow", sans-serif', script: '"Sacramento", cursive', body: '"Fredoka", sans-serif' },
|
|
183
183
|
["modern" /* Modern */]: { display: '"Bebas Neue", "Arial Narrow", sans-serif', script: '"Great Vibes", cursive', body: '"Montserrat", sans-serif' },
|
|
184
184
|
["elegant" /* Elegant */]: { display: '"Playfair Display", serif', script: '"Allura", cursive', body: '"Lato", sans-serif' },
|
|
185
|
-
["kizomba-sample" /* KizombaSample */]: { display: '"Anton", "Oswald", "Arial Narrow", sans-serif', script: '"Sacramento", cursive', body: '"Barlow Semi Condensed", "Fredoka", sans-serif' },
|
|
185
|
+
["kizomba-sample" /* KizombaSample */]: { display: '"Anton", "Oswald", "Arial Narrow", sans-serif', script: '"Dancing Script", "Sacramento", cursive', body: '"Barlow Semi Condensed", "Fredoka", sans-serif' },
|
|
186
186
|
["coastal" /* Coastal */]: { display: '"Fraunces", Georgia, serif', script: '"Allura", cursive', body: '"Jost", sans-serif' }
|
|
187
187
|
};
|
|
188
188
|
|
|
@@ -201,6 +201,15 @@ var MAX_LINE_GAP = 200;
|
|
|
201
201
|
var MIN_TITLE_SCALE = 0.3;
|
|
202
202
|
var MAX_TITLE_SCALE = 2.5;
|
|
203
203
|
var MIN_LABEL_SCALE = 0.3;
|
|
204
|
+
var MAX_ROW_SCALE = 2;
|
|
205
|
+
var MIN_WEIGHT = 100;
|
|
206
|
+
var MAX_WEIGHT = 900;
|
|
207
|
+
var MIN_WIDTH = 100;
|
|
208
|
+
var MAX_LENGTH = 1080;
|
|
209
|
+
var MAX_BODY_TOP = 1920;
|
|
210
|
+
var MAX_LENGTHS = 12;
|
|
211
|
+
var MIN_SPACING2 = -0.2;
|
|
212
|
+
var MAX_SPACING2 = 0.5;
|
|
204
213
|
var num = (minimum, maximum) => ({ type: "number", minimum, maximum });
|
|
205
214
|
var icons = (maxItems) => ({ type: "array", items: { type: "string", enum: Object.values(RowIcon) }, minItems: 1, maxItems });
|
|
206
215
|
var rowsSchema = {
|
|
@@ -217,11 +226,16 @@ var rowsSchema = {
|
|
|
217
226
|
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
|
|
218
227
|
gap: num(0, MAX_GAP),
|
|
219
228
|
toPicture: { type: "boolean" },
|
|
220
|
-
reach: num(0, 1)
|
|
229
|
+
reach: num(0, 1),
|
|
230
|
+
lengths: { type: "array", items: num(0, MAX_LENGTH), minItems: 1, maxItems: MAX_LENGTHS }
|
|
221
231
|
}
|
|
222
232
|
},
|
|
223
233
|
priceLabelScale: num(MIN_LABEL_SCALE, 1),
|
|
224
|
-
venue: { type: "object", additionalProperties: false, properties: { body: { type: "boolean" }, bare: { type: "boolean" } } }
|
|
234
|
+
venue: { type: "object", additionalProperties: false, properties: { body: { type: "boolean" }, bare: { type: "boolean" }, oneLine: { type: "boolean" } } },
|
|
235
|
+
labelScale: num(MIN_LABEL_SCALE, MAX_ROW_SCALE),
|
|
236
|
+
timeScale: num(MIN_LABEL_SCALE, MAX_ROW_SCALE),
|
|
237
|
+
timeWeight: num(MIN_WEIGHT, MAX_WEIGHT),
|
|
238
|
+
textWidth: num(MIN_WIDTH, MAX_LENGTH)
|
|
225
239
|
}
|
|
226
240
|
};
|
|
227
241
|
var overlapSchema = {
|
|
@@ -235,7 +249,12 @@ var headerTuningSchema = {
|
|
|
235
249
|
titleScriptGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
|
|
236
250
|
scriptTitleGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
|
|
237
251
|
titleScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
|
|
238
|
-
titleBottomScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE)
|
|
252
|
+
titleBottomScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
|
|
253
|
+
headerTextWidth: num(MIN_WIDTH, MAX_LENGTH),
|
|
254
|
+
bodyTop: num(0, MAX_BODY_TOP),
|
|
255
|
+
headerHeight: num(MIN_WIDTH, MAX_BODY_TOP),
|
|
256
|
+
titleSpacing: num(MIN_SPACING2, MAX_SPACING2),
|
|
257
|
+
scriptScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE)
|
|
239
258
|
};
|
|
240
259
|
|
|
241
260
|
// src/schema/flierDocSchema.ts
|
|
@@ -795,6 +814,7 @@ var BOLD = 700;
|
|
|
795
814
|
var SEMI = 600;
|
|
796
815
|
var MEDIUM = 500;
|
|
797
816
|
var SCRIPT = 400;
|
|
817
|
+
var LABEL_TIE = -1;
|
|
798
818
|
var SIZE = {
|
|
799
819
|
title: 250,
|
|
800
820
|
headerScript: 120,
|
|
@@ -819,7 +839,7 @@ var GAP = {
|
|
|
819
839
|
rule: 8,
|
|
820
840
|
divider: 24
|
|
821
841
|
};
|
|
822
|
-
var makers = (p, u, sc) => ({
|
|
842
|
+
var makers = (p, u, sc, timeWeight = SEMI) => ({
|
|
823
843
|
display: (text2, size, key) => styled({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }, key, sc),
|
|
824
844
|
venue: (text2, size, key) => styled({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }, key, sc),
|
|
825
845
|
bodyVenue: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
|
|
@@ -827,16 +847,18 @@ var makers = (p, u, sc) => ({
|
|
|
827
847
|
strong: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
|
|
828
848
|
accent: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }, key, sc),
|
|
829
849
|
item: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }, key, sc),
|
|
830
|
-
soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc)
|
|
850
|
+
soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc),
|
|
851
|
+
time: (text2, size, key) => styled({ text: text2, role: "body", weight: timeWeight, size: size * u, color: p.accent }, key, sc)
|
|
831
852
|
});
|
|
832
853
|
function headerGroups(doc, p, u) {
|
|
833
854
|
const l = makers(p, u, styleContext(doc));
|
|
834
855
|
const b = doc.blocks;
|
|
835
856
|
const t = doc.tuning;
|
|
836
857
|
const gap = (line, after) => after === void 0 ? line : { ...line, gapAfter: after * u };
|
|
837
|
-
const
|
|
838
|
-
const
|
|
839
|
-
const
|
|
858
|
+
const spaced = (line) => t?.titleSpacing === void 0 || line.spacing !== void 0 ? line : { ...line, spacing: t.titleSpacing };
|
|
859
|
+
const title = gap(spaced(l.display(b.title, SIZE.title * (t?.titleScale ?? 1), "title")), b.script ?? b.titleBottom ? t?.titleScriptGap : void 0);
|
|
860
|
+
const script = b.script ? gap(l.script(b.script, SIZE.headerScript * (t?.scriptScale ?? 1), "script"), b.titleBottom ? t?.scriptTitleGap : void 0) : void 0;
|
|
861
|
+
const lines = [title, script, b.titleBottom ? spaced(l.display(b.titleBottom, SIZE.title * (t?.titleBottomScale ?? 1), "titleBottom")) : void 0];
|
|
840
862
|
return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
|
|
841
863
|
}
|
|
842
864
|
function itemGroup(item, n, l, scale) {
|
|
@@ -875,6 +897,12 @@ function wrapped(line, wrap) {
|
|
|
875
897
|
const parts = wrap ? halves(line.text) : [line.text];
|
|
876
898
|
return parts.map((text2, i) => i === 0 ? { ...line, text: text2 } : { ...line, text: text2, bullet: void 0, hang: line.bullet !== void 0 });
|
|
877
899
|
}
|
|
900
|
+
function scheduleLines(doc, l, row, i) {
|
|
901
|
+
const r3 = doc.rows;
|
|
902
|
+
const label = l.strong(row.label, SIZE.scheduleLabel * (r3?.labelScale ?? 1), `schedule.${i}.label`);
|
|
903
|
+
const tied = r3?.labelScale === void 0 ? label : { ...label, sizeTie: label.sizeTie ?? LABEL_TIE };
|
|
904
|
+
return [tied, l.time(row.time, SIZE.scheduleTime * (r3?.timeScale ?? 1), `schedule.${i}.time`)];
|
|
905
|
+
}
|
|
878
906
|
function eventGroups(doc, l, u, options) {
|
|
879
907
|
const b = doc.blocks;
|
|
880
908
|
const groups = [];
|
|
@@ -883,7 +911,7 @@ function eventGroups(doc, l, u, options) {
|
|
|
883
911
|
const lastRow = schedule2.length + prices.length - 1;
|
|
884
912
|
const icons2 = doc.rows?.icons;
|
|
885
913
|
schedule2.forEach((row, i) => {
|
|
886
|
-
const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`)] :
|
|
914
|
+
const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`)] : scheduleLines(doc, l, row, i);
|
|
887
915
|
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1, ...options.marks(icons2?.schedule, i, i === lastRow) });
|
|
888
916
|
});
|
|
889
917
|
prices.forEach((row, i) => {
|
|
@@ -905,7 +933,7 @@ function flankPriceGroups(doc, p, u) {
|
|
|
905
933
|
return (doc.blocks.prices ?? []).map((row, i) => ({ lines: [l.strong(row.amount, SIZE.flankAmount, `prices.${i}.amount`), l.accent(row.label, SIZE.flankLabel, `prices.${i}.label`)], gapAfter: GAP.row * u }));
|
|
906
934
|
}
|
|
907
935
|
function bodyGroups(doc, p, u, options = {}) {
|
|
908
|
-
const l = makers(p, u, styleContext(doc));
|
|
936
|
+
const l = makers(p, u, styleContext(doc), doc.rows?.timeWeight);
|
|
909
937
|
const b = doc.blocks;
|
|
910
938
|
const groups = [];
|
|
911
939
|
const isList = doc.layout === "list" /* List */;
|
|
@@ -914,7 +942,8 @@ function bodyGroups(doc, p, u, options = {}) {
|
|
|
914
942
|
const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
|
|
915
943
|
const look = doc.rows?.venue;
|
|
916
944
|
const line = look?.body === true ? l.bodyVenue : l.venue;
|
|
917
|
-
|
|
945
|
+
const venue = look?.oneLine === true ? [b.venue.join(" ")] : b.venue;
|
|
946
|
+
groups.push({ lines: venue.map((v, i) => line(v, size, `venue.${i}`)), gapAfter: GAP.venue * u, rule: dividerOf(doc, p, u) ?? { color: p.accent, height: GAP.rule * u }, ruleBelow: true, icon: { color: p.icon ?? p.accent, glyph: p.background, bare: look?.bare }, keepWithNext });
|
|
918
947
|
}
|
|
919
948
|
groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, { ...options, marks: rowMarks(doc, p, u) }));
|
|
920
949
|
if (b.includes) {
|
|
@@ -1253,10 +1282,29 @@ function closeHeaderGap(geo, head, gap, u) {
|
|
|
1253
1282
|
const top = Math.round(Math.max(...head.texts.map((t) => t.box.y + t.box.h)) + gap * u);
|
|
1254
1283
|
return top < body.y ? { ...geo, body: { ...body, y: top, h: body.h + body.y - top } } : geo;
|
|
1255
1284
|
}
|
|
1256
|
-
function
|
|
1285
|
+
function tunedGeo(geo, doc, u) {
|
|
1286
|
+
const top = doc.tuning?.bodyTop;
|
|
1287
|
+
const width = doc.rows?.textWidth;
|
|
1288
|
+
let { header, body } = geo;
|
|
1289
|
+
if (top !== void 0) {
|
|
1290
|
+
const y = Math.round(top * u);
|
|
1291
|
+
header = { ...header, h: Math.max(1, y - header.y) };
|
|
1292
|
+
body = { ...body, y, h: Math.max(1, body.y + body.h - y) };
|
|
1293
|
+
}
|
|
1294
|
+
if (width !== void 0) {
|
|
1295
|
+
body = { ...body, w: Math.round(width * u) };
|
|
1296
|
+
}
|
|
1297
|
+
return { ...geo, header, body };
|
|
1298
|
+
}
|
|
1299
|
+
function widened(zones, size, u) {
|
|
1300
|
+
const { text: text2 } = zones;
|
|
1301
|
+
return { ...zones, text: { ...text2, w: size.w === void 0 ? text2.w : Math.round(size.w * u), h: size.h === void 0 ? text2.h : Math.round(size.h * u) } };
|
|
1302
|
+
}
|
|
1303
|
+
function flowAll(ctx, input, base2, reflow) {
|
|
1257
1304
|
const { doc, palette, fonts } = input;
|
|
1258
1305
|
const u = Math.min(input.width, input.height) / BASE;
|
|
1259
|
-
const
|
|
1306
|
+
const geo = tunedGeo(base2, doc, u);
|
|
1307
|
+
const zones = widened(headerAt(geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0), doc.tuning?.headerTop, u), { w: doc.tuning?.headerTextWidth, h: doc.tuning?.headerHeight }, u);
|
|
1260
1308
|
const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
|
|
1261
1309
|
const flanks = geo.flanks ?? [];
|
|
1262
1310
|
const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
|
|
@@ -1352,6 +1400,11 @@ function reachPicture(rules, picture, reach) {
|
|
|
1352
1400
|
r3.rect.w = Math.max(0, end - r3.rect.x);
|
|
1353
1401
|
});
|
|
1354
1402
|
}
|
|
1403
|
+
function stepRules(rules, lengths, u) {
|
|
1404
|
+
rules.forEach((r3, i) => {
|
|
1405
|
+
r3.rect.w = (lengths[Math.min(i, lengths.length - 1)] ?? 0) * u;
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1355
1408
|
|
|
1356
1409
|
// src/render/rowIcons.ts
|
|
1357
1410
|
var LINE2 = 0.03;
|
|
@@ -1533,6 +1586,9 @@ function placeOnPage(doc, assets, fitted, frame) {
|
|
|
1533
1586
|
if (picture && dividers?.toPicture === true) {
|
|
1534
1587
|
reachPicture(fitted.body.rules, picture, dividers.reach ?? 0);
|
|
1535
1588
|
}
|
|
1589
|
+
if (dividers?.lengths !== void 0) {
|
|
1590
|
+
stepRules(fitted.body.rules, dividers.lengths, frame.u);
|
|
1591
|
+
}
|
|
1536
1592
|
return { image, region, picture };
|
|
1537
1593
|
}
|
|
1538
1594
|
function drawLogo(ctx, doc, assets, fitted) {
|