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