@dloizides/poster-render 0.3.0 → 0.5.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 +17 -0
- package/README.md +16 -0
- package/dist/index.d.mts +72 -25
- package/dist/index.d.ts +72 -25
- package/dist/index.js +302 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +298 -66
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -59,6 +59,71 @@ var PictureAnchor = /* @__PURE__ */ ((PictureAnchor2) => {
|
|
|
59
59
|
return PictureAnchor2;
|
|
60
60
|
})(PictureAnchor || {});
|
|
61
61
|
|
|
62
|
+
// src/enums/LineAlign.ts
|
|
63
|
+
var LineAlign = /* @__PURE__ */ ((LineAlign2) => {
|
|
64
|
+
LineAlign2["Left"] = "left";
|
|
65
|
+
LineAlign2["Center"] = "center";
|
|
66
|
+
LineAlign2["Right"] = "right";
|
|
67
|
+
return LineAlign2;
|
|
68
|
+
})(LineAlign || {});
|
|
69
|
+
|
|
70
|
+
// src/enums/LineTieKind.ts
|
|
71
|
+
var LineTieKind = /* @__PURE__ */ ((LineTieKind2) => {
|
|
72
|
+
LineTieKind2["Width"] = "width";
|
|
73
|
+
LineTieKind2["Size"] = "size";
|
|
74
|
+
return LineTieKind2;
|
|
75
|
+
})(LineTieKind || {});
|
|
76
|
+
|
|
77
|
+
// src/schema/lineStyleSchema.ts
|
|
78
|
+
var LINE_KEY_PATTERN = "^(title|titleBottom|script|footer|includes[.]heading|includes[.]items[.][0-5]|venue[.][0-2]|schedule[.][0-5][.](label|time)|prices[.][0-3][.](amount|label)|items[.][0-7][.](date|price|schedule[.][0-5]))$";
|
|
79
|
+
var MAX_FONT = 40;
|
|
80
|
+
var MIN_SIZE_SCALE = 0.25;
|
|
81
|
+
var MAX_SIZE_SCALE = 3;
|
|
82
|
+
var MIN_SPACING = -0.1;
|
|
83
|
+
var MAX_SPACING = 0.5;
|
|
84
|
+
var MAX_TIES = 12;
|
|
85
|
+
var WEIGHTS = [100, 200, 300, 400, 500, 600, 700, 800, 900];
|
|
86
|
+
var lineKey = { type: "string", pattern: LINE_KEY_PATTERN };
|
|
87
|
+
var lineStyle = {
|
|
88
|
+
type: "object",
|
|
89
|
+
additionalProperties: false,
|
|
90
|
+
properties: {
|
|
91
|
+
font: { type: "string", minLength: 1, maxLength: MAX_FONT, pattern: "^[A-Za-z0-9 ]+$" },
|
|
92
|
+
sizeScale: { type: "number", minimum: MIN_SIZE_SCALE, maximum: MAX_SIZE_SCALE },
|
|
93
|
+
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
|
|
94
|
+
weight: { type: "integer", enum: WEIGHTS },
|
|
95
|
+
italic: { type: "boolean" },
|
|
96
|
+
letterSpacing: { type: "number", minimum: MIN_SPACING, maximum: MAX_SPACING },
|
|
97
|
+
align: { type: "string", enum: Object.values(LineAlign) }
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var lineStylesSchema = { type: "object", propertyNames: lineKey, additionalProperties: lineStyle };
|
|
101
|
+
var lineTiesSchema = {
|
|
102
|
+
type: "array",
|
|
103
|
+
maxItems: MAX_TIES,
|
|
104
|
+
items: {
|
|
105
|
+
type: "object",
|
|
106
|
+
required: ["kind", "lines"],
|
|
107
|
+
additionalProperties: false,
|
|
108
|
+
properties: {
|
|
109
|
+
kind: { type: "string", enum: Object.values(LineTieKind) },
|
|
110
|
+
lines: { type: "array", minItems: 2, maxItems: 2, items: lineKey }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/lineTies.ts
|
|
116
|
+
function tie(doc, kind, a, b) {
|
|
117
|
+
const ties = doc.lineTies ?? [];
|
|
118
|
+
const exists = ties.some((t) => t.kind === kind && t.lines.includes(a) && t.lines.includes(b));
|
|
119
|
+
if (a === b || exists) {
|
|
120
|
+
return doc;
|
|
121
|
+
}
|
|
122
|
+
return { ...doc, lineTies: [...ties, { kind, lines: [a, b] }] };
|
|
123
|
+
}
|
|
124
|
+
var sameWidth = (doc, a, b) => tie(doc, "width" /* Width */, a, b);
|
|
125
|
+
var sameSize = (doc, a, b) => tie(doc, "size" /* Size */, a, b);
|
|
126
|
+
|
|
62
127
|
// src/formats.ts
|
|
63
128
|
var FORMAT_SIZES = {
|
|
64
129
|
["story" /* Story */]: { width: 1080, height: 1920 },
|
|
@@ -103,6 +168,9 @@ var MAX_ITEMS = 8;
|
|
|
103
168
|
var MAX_PRICES = 4;
|
|
104
169
|
var MAX_VENUE = 3;
|
|
105
170
|
var MIN_SCALE = 0.3;
|
|
171
|
+
var MAX_HEADER_GAP = 200;
|
|
172
|
+
var MIN_DATE_SCALE = 0.5;
|
|
173
|
+
var MAX_DATE_SCALE = 2;
|
|
106
174
|
var text = (maxLength) => ({ type: "string", minLength: 1, maxLength });
|
|
107
175
|
var scheduleRow = {
|
|
108
176
|
type: "object",
|
|
@@ -168,6 +236,16 @@ var flierDocSchema = {
|
|
|
168
236
|
},
|
|
169
237
|
logo: { type: "object", required: ["imageId"], additionalProperties: false, properties: { imageId: text(SHORT) } },
|
|
170
238
|
blocks,
|
|
239
|
+
tuning: {
|
|
240
|
+
type: "object",
|
|
241
|
+
additionalProperties: false,
|
|
242
|
+
properties: {
|
|
243
|
+
headerGap: { type: "number", minimum: 0, maximum: MAX_HEADER_GAP },
|
|
244
|
+
itemDateScale: { type: "number", minimum: MIN_DATE_SCALE, maximum: MAX_DATE_SCALE }
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
lineStyles: lineStylesSchema,
|
|
248
|
+
lineTies: lineTiesSchema,
|
|
171
249
|
items: {
|
|
172
250
|
type: "array",
|
|
173
251
|
minItems: 1,
|
|
@@ -191,7 +269,7 @@ var typeName = (v) => {
|
|
|
191
269
|
};
|
|
192
270
|
var join = (path, key) => path === "" ? key : `${path}.${key}`;
|
|
193
271
|
var show = (v) => JSON.stringify(v) ?? typeName(v);
|
|
194
|
-
var ARTICLE = { object: "an object", array: "an array", string: "a string", number: "a number", integer: "an integer" };
|
|
272
|
+
var ARTICLE = { object: "an object", array: "an array", string: "a string", number: "a number", integer: "an integer", boolean: "a boolean" };
|
|
195
273
|
function matchesType(schema, value) {
|
|
196
274
|
switch (schema.type) {
|
|
197
275
|
case void 0:
|
|
@@ -211,6 +289,9 @@ function checkString(schema, value, path, errors) {
|
|
|
211
289
|
if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
|
|
212
290
|
errors.push(`${path}: must be at most ${schema.maxLength} characters (got ${value.length})`);
|
|
213
291
|
}
|
|
292
|
+
if (schema.pattern !== void 0 && !new RegExp(schema.pattern).test(value)) {
|
|
293
|
+
errors.push(`${path}: has an invalid format`);
|
|
294
|
+
}
|
|
214
295
|
}
|
|
215
296
|
function checkNumber(schema, value, path, errors) {
|
|
216
297
|
if (schema.minimum !== void 0 && value < schema.minimum) {
|
|
@@ -233,6 +314,14 @@ function checkArray(schema, value, path, errors) {
|
|
|
233
314
|
value.forEach((item, i) => validateAgainst(itemSchema, item, `${path}[${i}]`, errors));
|
|
234
315
|
}
|
|
235
316
|
}
|
|
317
|
+
function extraSchema(schema, key) {
|
|
318
|
+
const extra = schema.additionalProperties;
|
|
319
|
+
if (typeof extra !== "object") {
|
|
320
|
+
return void 0;
|
|
321
|
+
}
|
|
322
|
+
const names = schema.propertyNames?.pattern;
|
|
323
|
+
return names === void 0 || new RegExp(names).test(key) ? extra : void 0;
|
|
324
|
+
}
|
|
236
325
|
function checkObject(schema, value, path, errors) {
|
|
237
326
|
const props = schema.properties ?? {};
|
|
238
327
|
for (const key of schema.required ?? []) {
|
|
@@ -241,9 +330,9 @@ function checkObject(schema, value, path, errors) {
|
|
|
241
330
|
}
|
|
242
331
|
}
|
|
243
332
|
for (const [key, child] of Object.entries(value)) {
|
|
244
|
-
const childSchema = Object.hasOwn(props, key) ? props[key] :
|
|
333
|
+
const childSchema = Object.hasOwn(props, key) ? props[key] : extraSchema(schema, key);
|
|
245
334
|
if (childSchema === void 0) {
|
|
246
|
-
if (schema.additionalProperties
|
|
335
|
+
if (schema.additionalProperties !== void 0 && schema.additionalProperties !== true) {
|
|
247
336
|
errors.push(`${join(path, key)}: is not allowed`);
|
|
248
337
|
}
|
|
249
338
|
} else if (child !== void 0) {
|
|
@@ -285,6 +374,13 @@ var FlierDocError = class extends Error {
|
|
|
285
374
|
this.errors = errors;
|
|
286
375
|
}
|
|
287
376
|
};
|
|
377
|
+
function sameLineTies(doc) {
|
|
378
|
+
const ties = doc.lineTies;
|
|
379
|
+
if (!Array.isArray(ties)) {
|
|
380
|
+
return [];
|
|
381
|
+
}
|
|
382
|
+
return ties.flatMap((tie2, i) => Array.isArray(tie2?.lines) && tie2.lines.length === 2 && tie2.lines[0] === tie2.lines[1] ? [i] : []);
|
|
383
|
+
}
|
|
288
384
|
function validateFlierDoc(input) {
|
|
289
385
|
if (typeName(input) !== "object") {
|
|
290
386
|
return { ok: false, errors: ["doc: must be an object"] };
|
|
@@ -295,6 +391,7 @@ function validateFlierDoc(input) {
|
|
|
295
391
|
if (doc.layout === "list" /* List */ && (doc.items === void 0 || doc.items.length === 0)) {
|
|
296
392
|
errors.push('items: layout "list" needs at least one item');
|
|
297
393
|
}
|
|
394
|
+
sameLineTies(doc).forEach((i) => errors.push(`lineTies[${i}].lines: must name two different lines`));
|
|
298
395
|
return errors.length === 0 ? { ok: true, doc } : { ok: false, errors };
|
|
299
396
|
}
|
|
300
397
|
function missingAssets(doc, assets) {
|
|
@@ -474,6 +571,47 @@ function placeContain(image, region, fit) {
|
|
|
474
571
|
};
|
|
475
572
|
}
|
|
476
573
|
|
|
574
|
+
// src/layout/lineStyle.ts
|
|
575
|
+
function tieIds(ties, kind) {
|
|
576
|
+
const ids = /* @__PURE__ */ new Map();
|
|
577
|
+
ties.filter((t) => t.kind === kind).forEach((t, n) => {
|
|
578
|
+
const [a, b] = t.lines;
|
|
579
|
+
const ia = ids.get(a);
|
|
580
|
+
const ib = ids.get(b);
|
|
581
|
+
const id = ia ?? ib ?? n;
|
|
582
|
+
ids.set(a, id);
|
|
583
|
+
ids.set(b, id);
|
|
584
|
+
if (ib !== void 0 && ib !== id) {
|
|
585
|
+
[...ids.entries()].filter(([, v]) => v === ib).forEach(([key]) => ids.set(key, id));
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
return ids;
|
|
589
|
+
}
|
|
590
|
+
function styleContext(doc) {
|
|
591
|
+
const ties = doc.lineTies ?? [];
|
|
592
|
+
return { styles: doc.lineStyles ?? {}, width: tieIds(ties, "width" /* Width */), size: tieIds(ties, "size" /* Size */) };
|
|
593
|
+
}
|
|
594
|
+
function styled(line, key, sc) {
|
|
595
|
+
const style = Object.hasOwn(sc.styles, key) ? sc.styles[key] : void 0;
|
|
596
|
+
const widthTie = sc.width.get(key);
|
|
597
|
+
const sizeTie = sc.size.get(key);
|
|
598
|
+
if (style === void 0 && widthTie === void 0 && sizeTie === void 0) {
|
|
599
|
+
return line;
|
|
600
|
+
}
|
|
601
|
+
return {
|
|
602
|
+
...line,
|
|
603
|
+
size: line.size * (style?.sizeScale ?? 1),
|
|
604
|
+
color: style?.color ?? line.color,
|
|
605
|
+
weight: style?.weight ?? line.weight,
|
|
606
|
+
family: style?.font,
|
|
607
|
+
italic: style?.italic,
|
|
608
|
+
spacing: style?.letterSpacing,
|
|
609
|
+
align: style?.align,
|
|
610
|
+
widthTie,
|
|
611
|
+
sizeTie
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
|
|
477
615
|
// src/layout/blockGroups.ts
|
|
478
616
|
var BOLD = 700;
|
|
479
617
|
var SEMI = 600;
|
|
@@ -502,26 +640,27 @@ var GAP = {
|
|
|
502
640
|
includes: 24,
|
|
503
641
|
rule: 8
|
|
504
642
|
};
|
|
505
|
-
var makers = (p, u) => ({
|
|
506
|
-
display: (text2, size) => ({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }),
|
|
507
|
-
venue: (text2, size) => ({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }),
|
|
508
|
-
script: (text2, size) => ({ text: text2, role: "script", weight: SCRIPT, size: size * u, color: p.accent }),
|
|
509
|
-
strong: (text2, size) => ({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }),
|
|
510
|
-
accent: (text2, size) => ({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }),
|
|
511
|
-
item: (text2, size) => ({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }),
|
|
512
|
-
soft: (text2, size) => ({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft })
|
|
643
|
+
var makers = (p, u, sc) => ({
|
|
644
|
+
display: (text2, size, key) => styled({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }, key, sc),
|
|
645
|
+
venue: (text2, size, key) => styled({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }, key, sc),
|
|
646
|
+
script: (text2, size, key) => styled({ text: text2, role: "script", weight: SCRIPT, size: size * u, color: p.accent }, key, sc),
|
|
647
|
+
strong: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
|
|
648
|
+
accent: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }, key, sc),
|
|
649
|
+
item: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }, key, sc),
|
|
650
|
+
soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc)
|
|
513
651
|
});
|
|
514
652
|
function headerGroups(doc, p, u) {
|
|
515
|
-
const l = makers(p, u);
|
|
653
|
+
const l = makers(p, u, styleContext(doc));
|
|
516
654
|
const b = doc.blocks;
|
|
517
|
-
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];
|
|
655
|
+
const lines = [l.display(b.title, SIZE.title, "title"), b.script ? l.script(b.script, SIZE.headerScript, "script") : void 0, b.titleBottom ? l.display(b.titleBottom, SIZE.title, "titleBottom") : void 0];
|
|
518
656
|
return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
|
|
519
657
|
}
|
|
520
|
-
function itemGroup(item, l,
|
|
521
|
-
const
|
|
522
|
-
|
|
658
|
+
function itemGroup(item, n, l, scale) {
|
|
659
|
+
const { u, dateScale } = scale;
|
|
660
|
+
const lines = [l.script(item.date, SIZE.itemDate * dateScale, `items.${n}.date`)];
|
|
661
|
+
item.schedule.forEach((row, m) => lines.push(l.strong(`${row.label} ${row.time}`, SIZE.itemRow, `items.${n}.schedule.${m}`)));
|
|
523
662
|
if (item.price) {
|
|
524
|
-
lines.push(l.accent(item.price, SIZE.itemRow));
|
|
663
|
+
lines.push(l.accent(item.price, SIZE.itemRow, `items.${n}.price`));
|
|
525
664
|
}
|
|
526
665
|
return { lines, gapAfter: GAP.item * u };
|
|
527
666
|
}
|
|
@@ -544,79 +683,143 @@ function eventGroups(doc, l, u, options) {
|
|
|
544
683
|
const groups = [];
|
|
545
684
|
const schedule2 = b.schedule ?? [];
|
|
546
685
|
schedule2.forEach((row, i) => {
|
|
547
|
-
const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel)] : [l.strong(row.label, SIZE.scheduleLabel), l.accent(row.time, SIZE.scheduleTime)];
|
|
686
|
+
const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`)] : [l.strong(row.label, SIZE.scheduleLabel, `schedule.${i}.label`), l.accent(row.time, SIZE.scheduleTime, `schedule.${i}.time`)];
|
|
548
687
|
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1 });
|
|
549
688
|
});
|
|
550
689
|
const prices = (options.withPrices === false ? void 0 : b.prices) ?? [];
|
|
551
690
|
prices.forEach((row, i) => {
|
|
552
|
-
const lines = options.compact ? [l.strong(`${row.amount} ${row.label}`, SIZE.priceAmount)] : [l.strong(row.amount, SIZE.priceAmount), l.accent(row.label, SIZE.priceLabel)];
|
|
691
|
+
const lines = options.compact ? [l.strong(`${row.amount} ${row.label}`, SIZE.priceAmount, `prices.${i}.amount`)] : [l.strong(row.amount, SIZE.priceAmount, `prices.${i}.amount`), l.accent(row.label, SIZE.priceLabel, `prices.${i}.label`)];
|
|
553
692
|
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1 });
|
|
554
693
|
});
|
|
555
694
|
return groups;
|
|
556
695
|
}
|
|
557
|
-
function listGroups(doc, l, u) {
|
|
558
|
-
const groups = (doc.items ?? []).map((item) => itemGroup(item, l, u));
|
|
559
|
-
const prices = doc.blocks.prices?.map((row) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice)) ?? [];
|
|
696
|
+
function listGroups(doc, l, u, dateScale) {
|
|
697
|
+
const groups = (doc.items ?? []).map((item, n) => itemGroup(item, n, l, { u, dateScale }));
|
|
698
|
+
const prices = doc.blocks.prices?.map((row, i) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice, `prices.${i}.amount`)) ?? [];
|
|
560
699
|
if (prices.length > 0) {
|
|
561
700
|
groups.push({ lines: prices, gapAfter: GAP.row * u });
|
|
562
701
|
}
|
|
563
702
|
return groups;
|
|
564
703
|
}
|
|
565
704
|
function flankPriceGroups(doc, p, u) {
|
|
566
|
-
const l = makers(p, u);
|
|
567
|
-
return (doc.blocks.prices ?? []).map((row) => ({ lines: [l.strong(row.amount, SIZE.flankAmount), l.accent(row.label, SIZE.flankLabel)], gapAfter: GAP.row * u }));
|
|
705
|
+
const l = makers(p, u, styleContext(doc));
|
|
706
|
+
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 }));
|
|
568
707
|
}
|
|
569
708
|
function bodyGroups(doc, p, u, options = {}) {
|
|
570
|
-
const l = makers(p, u);
|
|
709
|
+
const l = makers(p, u, styleContext(doc));
|
|
571
710
|
const b = doc.blocks;
|
|
572
711
|
const groups = [];
|
|
573
712
|
const isList = doc.layout === "list" /* List */;
|
|
574
713
|
if (b.venue) {
|
|
575
714
|
const size = isList ? SIZE.listVenue : SIZE.venue;
|
|
576
715
|
const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
|
|
577
|
-
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 });
|
|
716
|
+
groups.push({ lines: b.venue.map((v, i) => l.venue(v, size, `venue.${i}`)), gapAfter: GAP.venue * u, rule: { color: p.accent, height: GAP.rule * u }, ruleBelow: true, icon: { color: p.accent, glyph: p.background }, keepWithNext });
|
|
578
717
|
}
|
|
579
|
-
groups.push(...isList ? listGroups(doc, l, u) : eventGroups(doc, l, u, options));
|
|
718
|
+
groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, options));
|
|
580
719
|
if (b.includes) {
|
|
581
|
-
const lines = [l.accent(b.includes.heading, SIZE.small), ...b.includes.items.map((i) => l.item(
|
|
720
|
+
const lines = [l.accent(b.includes.heading, SIZE.small, "includes.heading"), ...b.includes.items.map((item, i) => l.item(item, SIZE.small, `includes.items.${i}`))].flatMap((line) => wrapped(line, options.wrap));
|
|
582
721
|
groups.push({ lines, gapAfter: GAP.includes * u, uniform: true, keepWithNext: b.footer !== void 0, attachNext: b.footer !== void 0 });
|
|
583
722
|
}
|
|
584
723
|
if (b.footer) {
|
|
585
|
-
groups.push({ lines: wrapped(l.soft(b.footer, SIZE.small), options.wrap), gapAfter: 0 });
|
|
724
|
+
groups.push({ lines: wrapped(l.soft(b.footer, SIZE.small, "footer"), options.wrap), gapAfter: 0 });
|
|
586
725
|
}
|
|
587
726
|
return groups;
|
|
588
727
|
}
|
|
589
728
|
|
|
590
|
-
// src/layout/
|
|
729
|
+
// src/layout/lineSizes.ts
|
|
591
730
|
var LINE_HEIGHT = 1.2;
|
|
592
731
|
var BULLET_INDENT = 1.1;
|
|
593
|
-
var BULLET_RADIUS = 0.2;
|
|
594
|
-
var RULE_GAP = 2.5;
|
|
595
|
-
var RULE_WIDTH = 0.9;
|
|
596
|
-
var WIDE = 1.6;
|
|
597
|
-
var COLUMN_GAP = 0.04;
|
|
598
|
-
var TWO_COLUMN_MIN = 0.75;
|
|
599
|
-
var TWO_COLUMN_GAIN = 1.15;
|
|
600
|
-
var MIN_K = 0.02;
|
|
601
|
-
var STEPS = 22;
|
|
602
732
|
var ICON_SCALE = 1.6;
|
|
603
733
|
var ICON_GAP = 0.35;
|
|
604
|
-
var fontOf = (line, size, fonts) => `${line.weight} ${size}px ${fonts[line.role]}`;
|
|
605
|
-
var emptyFlow = () => ({ texts: [], cards: [], rules: [], bullets: [], icons: [] });
|
|
606
734
|
var indented = (line) => line.bullet !== void 0 || line.hang === true;
|
|
735
|
+
var bulletIndent = (line, k) => indented(line) ? line.size * k * BULLET_INDENT : 0;
|
|
607
736
|
var iconSize = (group, k) => {
|
|
608
737
|
const first = group.lines[0];
|
|
609
738
|
return group.icon && first ? first.size * k * LINE_HEIGHT * ICON_SCALE : 0;
|
|
610
739
|
};
|
|
740
|
+
function groupBox(group, k, colW) {
|
|
741
|
+
const pad = group.card ? group.card.pad * k : 0;
|
|
742
|
+
const d = iconSize(group, k);
|
|
743
|
+
const iconIndent = d > 0 ? d * (1 + ICON_GAP) : 0;
|
|
744
|
+
return { pad, d, iconIndent, avail: colW - 2 * pad - iconIndent };
|
|
745
|
+
}
|
|
611
746
|
function lineSize(line, width, k, avail) {
|
|
612
|
-
const indent =
|
|
747
|
+
const indent = bulletIndent(line, k);
|
|
613
748
|
return Math.max(0, Math.min(line.size * k, line.size * (avail - indent) / Math.max(width, 1)));
|
|
614
749
|
}
|
|
615
|
-
function
|
|
750
|
+
function groupSizes(m, k, avail) {
|
|
751
|
+
const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail));
|
|
616
752
|
if (!m.group.uniform) {
|
|
617
|
-
return
|
|
753
|
+
return own;
|
|
754
|
+
}
|
|
755
|
+
const ratio = Math.min(...m.group.lines.map((line, i) => (own[i] ?? 0) / line.size));
|
|
756
|
+
return m.group.lines.map((line) => line.size * ratio);
|
|
757
|
+
}
|
|
758
|
+
function tieMembers(all, k, colW, table, pick) {
|
|
759
|
+
const byId = /* @__PURE__ */ new Map();
|
|
760
|
+
all.forEach((m) => {
|
|
761
|
+
const { avail } = groupBox(m.group, k, colW);
|
|
762
|
+
const sizes = table.get(m) ?? [];
|
|
763
|
+
m.group.lines.forEach((line, i) => {
|
|
764
|
+
const id = pick(line);
|
|
765
|
+
if (id !== void 0) {
|
|
766
|
+
const member = { line, width: Math.max(m.widths[i] ?? 1, 1), cap: Math.max(0, avail - bulletIndent(line, k)), sizes, i };
|
|
767
|
+
byId.set(id, [...byId.get(id) ?? [], member]);
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
});
|
|
771
|
+
return [...byId.values()].filter((list) => list.length > 1);
|
|
772
|
+
}
|
|
773
|
+
function sameSizes(list) {
|
|
774
|
+
const target = Math.min(Math.max(...list.map((x) => x.sizes[x.i] ?? 0)), ...list.map((x) => x.line.size * x.cap / x.width));
|
|
775
|
+
list.forEach((x) => {
|
|
776
|
+
x.sizes[x.i] = target;
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
function sameWidths(list) {
|
|
780
|
+
const drawn = list.map((x) => x.width * (x.sizes[x.i] ?? 0) / x.line.size);
|
|
781
|
+
const target = Math.min(Math.max(...drawn), ...list.map((x) => x.cap));
|
|
782
|
+
list.forEach((x) => {
|
|
783
|
+
x.sizes[x.i] = target * x.line.size / x.width;
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
function sizeTable(all, k, colW) {
|
|
787
|
+
const table = new Map(all.map((m) => [m, groupSizes(m, k, groupBox(m.group, k, colW).avail)]));
|
|
788
|
+
tieMembers(all, k, colW, table, (line) => line.sizeTie).forEach(sameSizes);
|
|
789
|
+
tieMembers(all, k, colW, table, (line) => line.widthTie).forEach(sameWidths);
|
|
790
|
+
return table;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
// src/layout/textFlow.ts
|
|
794
|
+
var BULLET_RADIUS = 0.2;
|
|
795
|
+
var RULE_GAP = 2.5;
|
|
796
|
+
var RULE_WIDTH = 0.9;
|
|
797
|
+
var WIDE = 1.6;
|
|
798
|
+
var COLUMN_GAP = 0.04;
|
|
799
|
+
var TWO_COLUMN_MIN = 0.75;
|
|
800
|
+
var TWO_COLUMN_GAIN = 1.15;
|
|
801
|
+
var MIN_K = 0.02;
|
|
802
|
+
var STEPS = 22;
|
|
803
|
+
var NO_SPACING = "0px";
|
|
804
|
+
var fontOf = (line, size, fonts) => {
|
|
805
|
+
const family = line.family === void 0 ? fonts[line.role] : `"${line.family}", ${fonts[line.role]}`;
|
|
806
|
+
return `${line.italic === true ? "italic " : ""}${line.weight} ${size}px ${family}`;
|
|
807
|
+
};
|
|
808
|
+
var emptyFlow = () => ({ texts: [], cards: [], rules: [], bullets: [], icons: [] });
|
|
809
|
+
function lineX(line, box) {
|
|
810
|
+
const { col, pad, indent, w } = box;
|
|
811
|
+
const left = col.x + pad + indent;
|
|
812
|
+
const right = col.x + col.w - pad - w;
|
|
813
|
+
switch (line.align) {
|
|
814
|
+
case "left" /* Left */:
|
|
815
|
+
return left;
|
|
816
|
+
case "right" /* Right */:
|
|
817
|
+
return right;
|
|
818
|
+
case "center" /* Center */:
|
|
819
|
+
return left + (right - left) / 2;
|
|
820
|
+
default:
|
|
821
|
+
return col.right ? right : left;
|
|
618
822
|
}
|
|
619
|
-
return Math.min(...m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail) / line.size));
|
|
620
823
|
}
|
|
621
824
|
function placeIcon(group, box, out) {
|
|
622
825
|
const { d, x, top, bottom: bottom2 } = box;
|
|
@@ -628,25 +831,21 @@ function placeIcon(group, box, out) {
|
|
|
628
831
|
return top + Math.max(textH, d);
|
|
629
832
|
}
|
|
630
833
|
function placeGroup(m, at, out) {
|
|
631
|
-
const { k, col, y0 } = at;
|
|
834
|
+
const { k, col, y0, sizes } = at;
|
|
632
835
|
const { group } = m;
|
|
633
836
|
let y = y0;
|
|
634
837
|
if (group.rule) {
|
|
635
838
|
out?.rules.push({ rect: { x: col.x, y, w: col.w * RULE_WIDTH, h: group.rule.height * k }, color: group.rule.color });
|
|
636
839
|
y += group.rule.height * k * RULE_GAP;
|
|
637
840
|
}
|
|
638
|
-
const pad
|
|
841
|
+
const { pad, d, iconIndent } = groupBox(group, k, col.w);
|
|
639
842
|
const top = y;
|
|
640
843
|
y += pad;
|
|
641
|
-
const d = iconSize(group, k);
|
|
642
|
-
const iconIndent = d > 0 ? d * (1 + ICON_GAP) : 0;
|
|
643
|
-
const avail = col.w - 2 * pad - iconIndent;
|
|
644
|
-
const ratio = groupRatio(m, k, avail);
|
|
645
844
|
group.lines.forEach((line, i) => {
|
|
646
|
-
const size =
|
|
845
|
+
const size = sizes[i] ?? 0;
|
|
647
846
|
const indent = (indented(line) ? line.size * k * BULLET_INDENT : 0) + iconIndent;
|
|
648
847
|
const w = (m.widths[i] ?? 0) * size / line.size;
|
|
649
|
-
const x =
|
|
848
|
+
const x = lineX(line, { col, pad, indent, w });
|
|
650
849
|
out?.texts.push({ text: line.text, font: "", color: line.color, box: { x, y, w, h: size * LINE_HEIGHT } });
|
|
651
850
|
if (line.bullet && out) {
|
|
652
851
|
out.bullets.push({ x: col.x + pad + size * BULLET_RADIUS, y: y + size * LINE_HEIGHT / 2, r: size * BULLET_RADIUS, color: line.bullet });
|
|
@@ -666,10 +865,10 @@ function placeGroup(m, at, out) {
|
|
|
666
865
|
return y + group.gapAfter * k - y0;
|
|
667
866
|
}
|
|
668
867
|
function placeColumn(groups, at, out) {
|
|
669
|
-
const { k, col, spread = 0 } = at;
|
|
868
|
+
const { k, col, table, spread = 0 } = at;
|
|
670
869
|
let h = 0;
|
|
671
870
|
groups.forEach((g, i) => {
|
|
672
|
-
h += placeGroup(g, { k, col, y0: col.y + h }, out);
|
|
871
|
+
h += placeGroup(g, { k, col, y0: col.y + h, sizes: table.get(g) ?? [] }, out);
|
|
673
872
|
if (i < groups.length - 1 && g.group.attachNext !== true) {
|
|
674
873
|
h += spread;
|
|
675
874
|
}
|
|
@@ -702,7 +901,8 @@ function keepTogether(groups, heights, cut) {
|
|
|
702
901
|
function splitColumns(groups, zone) {
|
|
703
902
|
const gap = Math.round(zone.w * COLUMN_GAP);
|
|
704
903
|
const w = (zone.w - gap) / 2;
|
|
705
|
-
const
|
|
904
|
+
const table = sizeTable(groups, 1, w);
|
|
905
|
+
const heights = groups.map((g) => placeGroup(g, { k: 1, col: { ...zone, w }, y0: 0, sizes: table.get(g) ?? [] }, null));
|
|
706
906
|
const total = columnSum(heights, 0, heights.length);
|
|
707
907
|
let cut = 1;
|
|
708
908
|
for (let c = 2; c < groups.length; c++) {
|
|
@@ -716,8 +916,12 @@ function splitColumns(groups, zone) {
|
|
|
716
916
|
{ col: { ...zone, x: zone.x + w + gap, w }, groups: groups.slice(cut) }
|
|
717
917
|
];
|
|
718
918
|
}
|
|
919
|
+
var tableFor = (columns, k) => sizeTable(columns.flatMap((c) => c.groups), k, columns[0]?.col.w ?? 0);
|
|
719
920
|
function largestK(columns, zoneH) {
|
|
720
|
-
const fits = (k) =>
|
|
921
|
+
const fits = (k) => {
|
|
922
|
+
const table = tableFor(columns, k);
|
|
923
|
+
return columns.every((c) => placeColumn(c.groups, { k, col: c.col, table }, null) <= zoneH);
|
|
924
|
+
};
|
|
721
925
|
let lo = MIN_K;
|
|
722
926
|
let hi = 1;
|
|
723
927
|
if (fits(1)) {
|
|
@@ -744,26 +948,37 @@ function bestColumns(measured, zone) {
|
|
|
744
948
|
const forced = zone.w / Math.max(zone.h, 1) > WIDE;
|
|
745
949
|
return forced || k2 > k1 * TWO_COLUMN_GAIN ? { columns: split, k: k2 } : { columns: single, k: k1 };
|
|
746
950
|
}
|
|
951
|
+
function measure(ctx, line, fonts) {
|
|
952
|
+
ctx.font = fontOf(line, line.size, fonts);
|
|
953
|
+
if (line.spacing === void 0) {
|
|
954
|
+
return ctx.measureText(line.text).width;
|
|
955
|
+
}
|
|
956
|
+
ctx.letterSpacing = `${line.spacing * line.size}px`;
|
|
957
|
+
const width = ctx.measureText(line.text).width;
|
|
958
|
+
ctx.letterSpacing = NO_SPACING;
|
|
959
|
+
return width;
|
|
960
|
+
}
|
|
747
961
|
function flow(ctx, groups, zone, fonts) {
|
|
748
962
|
const measured = groups.map((group) => ({
|
|
749
963
|
group,
|
|
750
|
-
widths: group.lines.map((line) =>
|
|
751
|
-
ctx.font = fontOf(line, line.size, fonts);
|
|
752
|
-
return ctx.measureText(line.text).width;
|
|
753
|
-
})
|
|
964
|
+
widths: group.lines.map((line) => measure(ctx, line, fonts))
|
|
754
965
|
}));
|
|
755
966
|
const { columns, k: lo } = bestColumns(measured, zone);
|
|
756
967
|
const out = emptyFlow();
|
|
757
|
-
const
|
|
968
|
+
const table = tableFor(columns, lo);
|
|
969
|
+
const heights = columns.map((c) => placeColumn(c.groups, { k: lo, col: c.col, table }, null));
|
|
758
970
|
const end = Math.max(...heights);
|
|
759
971
|
columns.forEach((c, i) => {
|
|
760
972
|
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);
|
|
973
|
+
placeColumn(c.groups, { k: lo, col: c.col, table, spread: gaps > 0 && columns.length > 1 ? (end - (heights[i] ?? end)) / gaps : 0 }, out);
|
|
762
974
|
});
|
|
763
975
|
const lines = groups.flatMap((g) => g.lines);
|
|
764
976
|
out.texts.forEach((t, i) => {
|
|
765
977
|
const line = lines[i];
|
|
766
978
|
t.font = line ? fontOf(line, t.box.h / LINE_HEIGHT, fonts) : t.font;
|
|
979
|
+
if (line?.spacing !== void 0) {
|
|
980
|
+
t.spacing = `${line.spacing * (t.box.h / LINE_HEIGHT)}px`;
|
|
981
|
+
}
|
|
767
982
|
});
|
|
768
983
|
return out;
|
|
769
984
|
}
|
|
@@ -818,15 +1033,25 @@ function splitHeader(header, hasLogo) {
|
|
|
818
1033
|
const logoW = hasLogo ? Math.round(header.w * LOGO_SHARE) : 0;
|
|
819
1034
|
return { text: { ...header, w: header.w - logoW * 1.1 }, logo: { ...header, x: header.x + header.w - logoW, w: logoW } };
|
|
820
1035
|
}
|
|
1036
|
+
function closeHeaderGap(geo, head, gap, u) {
|
|
1037
|
+
const { header, body } = geo;
|
|
1038
|
+
const stacked = header.y + header.h <= body.y && header.x < body.x + body.w && body.x < header.x + header.w;
|
|
1039
|
+
if (gap === void 0 || !stacked || head.texts.length === 0) {
|
|
1040
|
+
return geo;
|
|
1041
|
+
}
|
|
1042
|
+
const top = Math.round(Math.max(...head.texts.map((t) => t.box.y + t.box.h)) + gap * u);
|
|
1043
|
+
return top < body.y ? { ...geo, body: { ...body, y: top, h: body.h + body.y - top } } : geo;
|
|
1044
|
+
}
|
|
821
1045
|
function flowAll(ctx, input, geo, reflow) {
|
|
822
1046
|
const { doc, palette, fonts } = input;
|
|
823
1047
|
const u = Math.min(input.width, input.height) / BASE;
|
|
824
1048
|
const zones = geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0);
|
|
825
1049
|
const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
|
|
826
1050
|
const flanks = geo.flanks ?? [];
|
|
827
|
-
const
|
|
1051
|
+
const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
|
|
1052
|
+
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);
|
|
828
1053
|
const sides = flanks.length > 0 ? equalFlanks(ctx, flankPriceGroups(doc, palette, u), flanks, fonts) : [emptyFlow()];
|
|
829
|
-
return { geo, zones, head, body, sides };
|
|
1054
|
+
return { geo: tight, zones, head, body, sides };
|
|
830
1055
|
}
|
|
831
1056
|
var smallest = (t) => Math.min(Infinity, ...[t.head, t.body, ...t.sides].flatMap((f) => f.texts.map((x) => x.box.h / LINE_HEIGHT3)));
|
|
832
1057
|
function shiftHeader(geo, shift) {
|
|
@@ -896,6 +1121,7 @@ function fitToFloor(ctx, input) {
|
|
|
896
1121
|
|
|
897
1122
|
// src/render/render.ts
|
|
898
1123
|
var BASE2 = 1080;
|
|
1124
|
+
var NO_SPACING2 = "0px";
|
|
899
1125
|
var CARD_RADIUS = 0.035;
|
|
900
1126
|
var CAP_TOP = 0.15;
|
|
901
1127
|
var PIN_HEAD_Y = 0.08;
|
|
@@ -956,7 +1182,13 @@ function drawFlow(ctx, f, radius) {
|
|
|
956
1182
|
f.texts.forEach((t) => {
|
|
957
1183
|
ctx.font = t.font;
|
|
958
1184
|
ctx.fillStyle = t.color;
|
|
1185
|
+
if (t.spacing !== void 0) {
|
|
1186
|
+
ctx.letterSpacing = t.spacing;
|
|
1187
|
+
}
|
|
959
1188
|
ctx.fillText(t.text, t.box.x, t.box.y);
|
|
1189
|
+
if (t.spacing !== void 0) {
|
|
1190
|
+
ctx.letterSpacing = NO_SPACING2;
|
|
1191
|
+
}
|
|
960
1192
|
});
|
|
961
1193
|
}
|
|
962
1194
|
function checked(input, assets) {
|
|
@@ -1136,7 +1368,10 @@ exports.FlierDocError = FlierDocError;
|
|
|
1136
1368
|
exports.FontSetId = FontSetId;
|
|
1137
1369
|
exports.FormatId = FormatId;
|
|
1138
1370
|
exports.LAYOUT_CATALOGUE = LAYOUT_CATALOGUE;
|
|
1371
|
+
exports.LINE_KEY_PATTERN = LINE_KEY_PATTERN;
|
|
1139
1372
|
exports.LayoutId = LayoutId;
|
|
1373
|
+
exports.LineAlign = LineAlign;
|
|
1374
|
+
exports.LineTieKind = LineTieKind;
|
|
1140
1375
|
exports.PALETTES = PALETTES;
|
|
1141
1376
|
exports.PaletteId = PaletteId;
|
|
1142
1377
|
exports.PictureAnchor = PictureAnchor;
|
|
@@ -1146,6 +1381,8 @@ exports.flierDocSchema = flierDocSchema;
|
|
|
1146
1381
|
exports.kizombaWorkshop = kizombaWorkshop;
|
|
1147
1382
|
exports.kizombaWorkshopDocs = kizombaWorkshopDocs;
|
|
1148
1383
|
exports.render = render;
|
|
1384
|
+
exports.sameSize = sameSize;
|
|
1385
|
+
exports.sameWidth = sameWidth;
|
|
1149
1386
|
exports.validateFlierDoc = validateFlierDoc;
|
|
1150
1387
|
//# sourceMappingURL=index.js.map
|
|
1151
1388
|
//# sourceMappingURL=index.js.map
|