@dloizides/poster-render 0.4.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 +8 -0
- package/README.md +15 -0
- package/dist/index.d.mts +66 -25
- package/dist/index.d.ts +66 -25
- package/dist/index.js +277 -61
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +273 -62
- 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 },
|
|
@@ -177,6 +242,8 @@ var flierDocSchema = {
|
|
|
177
242
|
itemDateScale: { type: "number", minimum: MIN_DATE_SCALE, maximum: MAX_DATE_SCALE }
|
|
178
243
|
}
|
|
179
244
|
},
|
|
245
|
+
lineStyles: lineStylesSchema,
|
|
246
|
+
lineTies: lineTiesSchema,
|
|
180
247
|
items: {
|
|
181
248
|
type: "array",
|
|
182
249
|
minItems: 1,
|
|
@@ -200,7 +267,7 @@ var typeName = (v) => {
|
|
|
200
267
|
};
|
|
201
268
|
var join = (path, key) => path === "" ? key : `${path}.${key}`;
|
|
202
269
|
var show = (v) => JSON.stringify(v) ?? typeName(v);
|
|
203
|
-
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" };
|
|
204
271
|
function matchesType(schema, value) {
|
|
205
272
|
switch (schema.type) {
|
|
206
273
|
case void 0:
|
|
@@ -220,6 +287,9 @@ function checkString(schema, value, path, errors) {
|
|
|
220
287
|
if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
|
|
221
288
|
errors.push(`${path}: must be at most ${schema.maxLength} characters (got ${value.length})`);
|
|
222
289
|
}
|
|
290
|
+
if (schema.pattern !== void 0 && !new RegExp(schema.pattern).test(value)) {
|
|
291
|
+
errors.push(`${path}: has an invalid format`);
|
|
292
|
+
}
|
|
223
293
|
}
|
|
224
294
|
function checkNumber(schema, value, path, errors) {
|
|
225
295
|
if (schema.minimum !== void 0 && value < schema.minimum) {
|
|
@@ -242,6 +312,14 @@ function checkArray(schema, value, path, errors) {
|
|
|
242
312
|
value.forEach((item, i) => validateAgainst(itemSchema, item, `${path}[${i}]`, errors));
|
|
243
313
|
}
|
|
244
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
|
+
}
|
|
245
323
|
function checkObject(schema, value, path, errors) {
|
|
246
324
|
const props = schema.properties ?? {};
|
|
247
325
|
for (const key of schema.required ?? []) {
|
|
@@ -250,9 +328,9 @@ function checkObject(schema, value, path, errors) {
|
|
|
250
328
|
}
|
|
251
329
|
}
|
|
252
330
|
for (const [key, child] of Object.entries(value)) {
|
|
253
|
-
const childSchema = Object.hasOwn(props, key) ? props[key] :
|
|
331
|
+
const childSchema = Object.hasOwn(props, key) ? props[key] : extraSchema(schema, key);
|
|
254
332
|
if (childSchema === void 0) {
|
|
255
|
-
if (schema.additionalProperties
|
|
333
|
+
if (schema.additionalProperties !== void 0 && schema.additionalProperties !== true) {
|
|
256
334
|
errors.push(`${join(path, key)}: is not allowed`);
|
|
257
335
|
}
|
|
258
336
|
} else if (child !== void 0) {
|
|
@@ -294,6 +372,13 @@ var FlierDocError = class extends Error {
|
|
|
294
372
|
this.errors = errors;
|
|
295
373
|
}
|
|
296
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
|
+
}
|
|
297
382
|
function validateFlierDoc(input) {
|
|
298
383
|
if (typeName(input) !== "object") {
|
|
299
384
|
return { ok: false, errors: ["doc: must be an object"] };
|
|
@@ -304,6 +389,7 @@ function validateFlierDoc(input) {
|
|
|
304
389
|
if (doc.layout === "list" /* List */ && (doc.items === void 0 || doc.items.length === 0)) {
|
|
305
390
|
errors.push('items: layout "list" needs at least one item');
|
|
306
391
|
}
|
|
392
|
+
sameLineTies(doc).forEach((i) => errors.push(`lineTies[${i}].lines: must name two different lines`));
|
|
307
393
|
return errors.length === 0 ? { ok: true, doc } : { ok: false, errors };
|
|
308
394
|
}
|
|
309
395
|
function missingAssets(doc, assets) {
|
|
@@ -483,6 +569,47 @@ function placeContain(image, region, fit) {
|
|
|
483
569
|
};
|
|
484
570
|
}
|
|
485
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
|
+
|
|
486
613
|
// src/layout/blockGroups.ts
|
|
487
614
|
var BOLD = 700;
|
|
488
615
|
var SEMI = 600;
|
|
@@ -511,26 +638,27 @@ var GAP = {
|
|
|
511
638
|
includes: 24,
|
|
512
639
|
rule: 8
|
|
513
640
|
};
|
|
514
|
-
var makers = (p, u) => ({
|
|
515
|
-
display: (text2, size) => ({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }),
|
|
516
|
-
venue: (text2, size) => ({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }),
|
|
517
|
-
script: (text2, size) => ({ text: text2, role: "script", weight: SCRIPT, size: size * u, color: p.accent }),
|
|
518
|
-
strong: (text2, size) => ({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }),
|
|
519
|
-
accent: (text2, size) => ({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }),
|
|
520
|
-
item: (text2, size) => ({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }),
|
|
521
|
-
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)
|
|
522
649
|
});
|
|
523
650
|
function headerGroups(doc, p, u) {
|
|
524
|
-
const l = makers(p, u);
|
|
651
|
+
const l = makers(p, u, styleContext(doc));
|
|
525
652
|
const b = doc.blocks;
|
|
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];
|
|
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];
|
|
527
654
|
return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
|
|
528
655
|
}
|
|
529
|
-
function itemGroup(item,
|
|
530
|
-
const
|
|
531
|
-
|
|
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}`)));
|
|
532
660
|
if (item.price) {
|
|
533
|
-
lines.push(l.accent(item.price, SIZE.itemRow));
|
|
661
|
+
lines.push(l.accent(item.price, SIZE.itemRow, `items.${n}.price`));
|
|
534
662
|
}
|
|
535
663
|
return { lines, gapAfter: GAP.item * u };
|
|
536
664
|
}
|
|
@@ -553,79 +681,143 @@ function eventGroups(doc, l, u, options) {
|
|
|
553
681
|
const groups = [];
|
|
554
682
|
const schedule2 = b.schedule ?? [];
|
|
555
683
|
schedule2.forEach((row, i) => {
|
|
556
|
-
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`)];
|
|
557
685
|
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1 });
|
|
558
686
|
});
|
|
559
687
|
const prices = (options.withPrices === false ? void 0 : b.prices) ?? [];
|
|
560
688
|
prices.forEach((row, i) => {
|
|
561
|
-
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`)];
|
|
562
690
|
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1 });
|
|
563
691
|
});
|
|
564
692
|
return groups;
|
|
565
693
|
}
|
|
566
694
|
function listGroups(doc, l, u, dateScale) {
|
|
567
|
-
const groups = (doc.items ?? []).map((item) => itemGroup(item, l, u, dateScale));
|
|
568
|
-
const prices = doc.blocks.prices?.map((row) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice)) ?? [];
|
|
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`)) ?? [];
|
|
569
697
|
if (prices.length > 0) {
|
|
570
698
|
groups.push({ lines: prices, gapAfter: GAP.row * u });
|
|
571
699
|
}
|
|
572
700
|
return groups;
|
|
573
701
|
}
|
|
574
702
|
function flankPriceGroups(doc, p, u) {
|
|
575
|
-
const l = makers(p, u);
|
|
576
|
-
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 }));
|
|
577
705
|
}
|
|
578
706
|
function bodyGroups(doc, p, u, options = {}) {
|
|
579
|
-
const l = makers(p, u);
|
|
707
|
+
const l = makers(p, u, styleContext(doc));
|
|
580
708
|
const b = doc.blocks;
|
|
581
709
|
const groups = [];
|
|
582
710
|
const isList = doc.layout === "list" /* List */;
|
|
583
711
|
if (b.venue) {
|
|
584
712
|
const size = isList ? SIZE.listVenue : SIZE.venue;
|
|
585
713
|
const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
|
|
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 });
|
|
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 });
|
|
587
715
|
}
|
|
588
716
|
groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, options));
|
|
589
717
|
if (b.includes) {
|
|
590
|
-
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));
|
|
591
719
|
groups.push({ lines, gapAfter: GAP.includes * u, uniform: true, keepWithNext: b.footer !== void 0, attachNext: b.footer !== void 0 });
|
|
592
720
|
}
|
|
593
721
|
if (b.footer) {
|
|
594
|
-
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 });
|
|
595
723
|
}
|
|
596
724
|
return groups;
|
|
597
725
|
}
|
|
598
726
|
|
|
599
|
-
// src/layout/
|
|
727
|
+
// src/layout/lineSizes.ts
|
|
600
728
|
var LINE_HEIGHT = 1.2;
|
|
601
729
|
var BULLET_INDENT = 1.1;
|
|
602
|
-
var BULLET_RADIUS = 0.2;
|
|
603
|
-
var RULE_GAP = 2.5;
|
|
604
|
-
var RULE_WIDTH = 0.9;
|
|
605
|
-
var WIDE = 1.6;
|
|
606
|
-
var COLUMN_GAP = 0.04;
|
|
607
|
-
var TWO_COLUMN_MIN = 0.75;
|
|
608
|
-
var TWO_COLUMN_GAIN = 1.15;
|
|
609
|
-
var MIN_K = 0.02;
|
|
610
|
-
var STEPS = 22;
|
|
611
730
|
var ICON_SCALE = 1.6;
|
|
612
731
|
var ICON_GAP = 0.35;
|
|
613
|
-
var fontOf = (line, size, fonts) => `${line.weight} ${size}px ${fonts[line.role]}`;
|
|
614
|
-
var emptyFlow = () => ({ texts: [], cards: [], rules: [], bullets: [], icons: [] });
|
|
615
732
|
var indented = (line) => line.bullet !== void 0 || line.hang === true;
|
|
733
|
+
var bulletIndent = (line, k) => indented(line) ? line.size * k * BULLET_INDENT : 0;
|
|
616
734
|
var iconSize = (group, k) => {
|
|
617
735
|
const first = group.lines[0];
|
|
618
736
|
return group.icon && first ? first.size * k * LINE_HEIGHT * ICON_SCALE : 0;
|
|
619
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
|
+
}
|
|
620
744
|
function lineSize(line, width, k, avail) {
|
|
621
|
-
const indent =
|
|
745
|
+
const indent = bulletIndent(line, k);
|
|
622
746
|
return Math.max(0, Math.min(line.size * k, line.size * (avail - indent) / Math.max(width, 1)));
|
|
623
747
|
}
|
|
624
|
-
function
|
|
748
|
+
function groupSizes(m, k, avail) {
|
|
749
|
+
const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail));
|
|
625
750
|
if (!m.group.uniform) {
|
|
626
|
-
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;
|
|
627
820
|
}
|
|
628
|
-
return Math.min(...m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail) / line.size));
|
|
629
821
|
}
|
|
630
822
|
function placeIcon(group, box, out) {
|
|
631
823
|
const { d, x, top, bottom: bottom2 } = box;
|
|
@@ -637,25 +829,21 @@ function placeIcon(group, box, out) {
|
|
|
637
829
|
return top + Math.max(textH, d);
|
|
638
830
|
}
|
|
639
831
|
function placeGroup(m, at, out) {
|
|
640
|
-
const { k, col, y0 } = at;
|
|
832
|
+
const { k, col, y0, sizes } = at;
|
|
641
833
|
const { group } = m;
|
|
642
834
|
let y = y0;
|
|
643
835
|
if (group.rule) {
|
|
644
836
|
out?.rules.push({ rect: { x: col.x, y, w: col.w * RULE_WIDTH, h: group.rule.height * k }, color: group.rule.color });
|
|
645
837
|
y += group.rule.height * k * RULE_GAP;
|
|
646
838
|
}
|
|
647
|
-
const pad
|
|
839
|
+
const { pad, d, iconIndent } = groupBox(group, k, col.w);
|
|
648
840
|
const top = y;
|
|
649
841
|
y += pad;
|
|
650
|
-
const d = iconSize(group, k);
|
|
651
|
-
const iconIndent = d > 0 ? d * (1 + ICON_GAP) : 0;
|
|
652
|
-
const avail = col.w - 2 * pad - iconIndent;
|
|
653
|
-
const ratio = groupRatio(m, k, avail);
|
|
654
842
|
group.lines.forEach((line, i) => {
|
|
655
|
-
const size =
|
|
843
|
+
const size = sizes[i] ?? 0;
|
|
656
844
|
const indent = (indented(line) ? line.size * k * BULLET_INDENT : 0) + iconIndent;
|
|
657
845
|
const w = (m.widths[i] ?? 0) * size / line.size;
|
|
658
|
-
const x =
|
|
846
|
+
const x = lineX(line, { col, pad, indent, w });
|
|
659
847
|
out?.texts.push({ text: line.text, font: "", color: line.color, box: { x, y, w, h: size * LINE_HEIGHT } });
|
|
660
848
|
if (line.bullet && out) {
|
|
661
849
|
out.bullets.push({ x: col.x + pad + size * BULLET_RADIUS, y: y + size * LINE_HEIGHT / 2, r: size * BULLET_RADIUS, color: line.bullet });
|
|
@@ -675,10 +863,10 @@ function placeGroup(m, at, out) {
|
|
|
675
863
|
return y + group.gapAfter * k - y0;
|
|
676
864
|
}
|
|
677
865
|
function placeColumn(groups, at, out) {
|
|
678
|
-
const { k, col, spread = 0 } = at;
|
|
866
|
+
const { k, col, table, spread = 0 } = at;
|
|
679
867
|
let h = 0;
|
|
680
868
|
groups.forEach((g, i) => {
|
|
681
|
-
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);
|
|
682
870
|
if (i < groups.length - 1 && g.group.attachNext !== true) {
|
|
683
871
|
h += spread;
|
|
684
872
|
}
|
|
@@ -711,7 +899,8 @@ function keepTogether(groups, heights, cut) {
|
|
|
711
899
|
function splitColumns(groups, zone) {
|
|
712
900
|
const gap = Math.round(zone.w * COLUMN_GAP);
|
|
713
901
|
const w = (zone.w - gap) / 2;
|
|
714
|
-
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));
|
|
715
904
|
const total = columnSum(heights, 0, heights.length);
|
|
716
905
|
let cut = 1;
|
|
717
906
|
for (let c = 2; c < groups.length; c++) {
|
|
@@ -725,8 +914,12 @@ function splitColumns(groups, zone) {
|
|
|
725
914
|
{ col: { ...zone, x: zone.x + w + gap, w }, groups: groups.slice(cut) }
|
|
726
915
|
];
|
|
727
916
|
}
|
|
917
|
+
var tableFor = (columns, k) => sizeTable(columns.flatMap((c) => c.groups), k, columns[0]?.col.w ?? 0);
|
|
728
918
|
function largestK(columns, zoneH) {
|
|
729
|
-
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
|
+
};
|
|
730
923
|
let lo = MIN_K;
|
|
731
924
|
let hi = 1;
|
|
732
925
|
if (fits(1)) {
|
|
@@ -753,26 +946,37 @@ function bestColumns(measured, zone) {
|
|
|
753
946
|
const forced = zone.w / Math.max(zone.h, 1) > WIDE;
|
|
754
947
|
return forced || k2 > k1 * TWO_COLUMN_GAIN ? { columns: split, k: k2 } : { columns: single, k: k1 };
|
|
755
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
|
+
}
|
|
756
959
|
function flow(ctx, groups, zone, fonts) {
|
|
757
960
|
const measured = groups.map((group) => ({
|
|
758
961
|
group,
|
|
759
|
-
widths: group.lines.map((line) =>
|
|
760
|
-
ctx.font = fontOf(line, line.size, fonts);
|
|
761
|
-
return ctx.measureText(line.text).width;
|
|
762
|
-
})
|
|
962
|
+
widths: group.lines.map((line) => measure(ctx, line, fonts))
|
|
763
963
|
}));
|
|
764
964
|
const { columns, k: lo } = bestColumns(measured, zone);
|
|
765
965
|
const out = emptyFlow();
|
|
766
|
-
const
|
|
966
|
+
const table = tableFor(columns, lo);
|
|
967
|
+
const heights = columns.map((c) => placeColumn(c.groups, { k: lo, col: c.col, table }, null));
|
|
767
968
|
const end = Math.max(...heights);
|
|
768
969
|
columns.forEach((c, i) => {
|
|
769
970
|
const gaps = spreadGaps(c.groups);
|
|
770
|
-
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);
|
|
771
972
|
});
|
|
772
973
|
const lines = groups.flatMap((g) => g.lines);
|
|
773
974
|
out.texts.forEach((t, i) => {
|
|
774
975
|
const line = lines[i];
|
|
775
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
|
+
}
|
|
776
980
|
});
|
|
777
981
|
return out;
|
|
778
982
|
}
|
|
@@ -915,6 +1119,7 @@ function fitToFloor(ctx, input) {
|
|
|
915
1119
|
|
|
916
1120
|
// src/render/render.ts
|
|
917
1121
|
var BASE2 = 1080;
|
|
1122
|
+
var NO_SPACING2 = "0px";
|
|
918
1123
|
var CARD_RADIUS = 0.035;
|
|
919
1124
|
var CAP_TOP = 0.15;
|
|
920
1125
|
var PIN_HEAD_Y = 0.08;
|
|
@@ -975,7 +1180,13 @@ function drawFlow(ctx, f, radius) {
|
|
|
975
1180
|
f.texts.forEach((t) => {
|
|
976
1181
|
ctx.font = t.font;
|
|
977
1182
|
ctx.fillStyle = t.color;
|
|
1183
|
+
if (t.spacing !== void 0) {
|
|
1184
|
+
ctx.letterSpacing = t.spacing;
|
|
1185
|
+
}
|
|
978
1186
|
ctx.fillText(t.text, t.box.x, t.box.y);
|
|
1187
|
+
if (t.spacing !== void 0) {
|
|
1188
|
+
ctx.letterSpacing = NO_SPACING2;
|
|
1189
|
+
}
|
|
979
1190
|
});
|
|
980
1191
|
}
|
|
981
1192
|
function checked(input, assets) {
|
|
@@ -1148,6 +1359,6 @@ var kizombaWorkshop = {
|
|
|
1148
1359
|
};
|
|
1149
1360
|
var kizombaWorkshopDocs = [...WORKSHOPS.map(workshopDoc), kizombaWorkshop];
|
|
1150
1361
|
|
|
1151
|
-
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 };
|
|
1152
1363
|
//# sourceMappingURL=index.mjs.map
|
|
1153
1364
|
//# sourceMappingURL=index.mjs.map
|