@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.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 },
|
|
@@ -179,6 +244,8 @@ var flierDocSchema = {
|
|
|
179
244
|
itemDateScale: { type: "number", minimum: MIN_DATE_SCALE, maximum: MAX_DATE_SCALE }
|
|
180
245
|
}
|
|
181
246
|
},
|
|
247
|
+
lineStyles: lineStylesSchema,
|
|
248
|
+
lineTies: lineTiesSchema,
|
|
182
249
|
items: {
|
|
183
250
|
type: "array",
|
|
184
251
|
minItems: 1,
|
|
@@ -202,7 +269,7 @@ var typeName = (v) => {
|
|
|
202
269
|
};
|
|
203
270
|
var join = (path, key) => path === "" ? key : `${path}.${key}`;
|
|
204
271
|
var show = (v) => JSON.stringify(v) ?? typeName(v);
|
|
205
|
-
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" };
|
|
206
273
|
function matchesType(schema, value) {
|
|
207
274
|
switch (schema.type) {
|
|
208
275
|
case void 0:
|
|
@@ -222,6 +289,9 @@ function checkString(schema, value, path, errors) {
|
|
|
222
289
|
if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
|
|
223
290
|
errors.push(`${path}: must be at most ${schema.maxLength} characters (got ${value.length})`);
|
|
224
291
|
}
|
|
292
|
+
if (schema.pattern !== void 0 && !new RegExp(schema.pattern).test(value)) {
|
|
293
|
+
errors.push(`${path}: has an invalid format`);
|
|
294
|
+
}
|
|
225
295
|
}
|
|
226
296
|
function checkNumber(schema, value, path, errors) {
|
|
227
297
|
if (schema.minimum !== void 0 && value < schema.minimum) {
|
|
@@ -244,6 +314,14 @@ function checkArray(schema, value, path, errors) {
|
|
|
244
314
|
value.forEach((item, i) => validateAgainst(itemSchema, item, `${path}[${i}]`, errors));
|
|
245
315
|
}
|
|
246
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
|
+
}
|
|
247
325
|
function checkObject(schema, value, path, errors) {
|
|
248
326
|
const props = schema.properties ?? {};
|
|
249
327
|
for (const key of schema.required ?? []) {
|
|
@@ -252,9 +330,9 @@ function checkObject(schema, value, path, errors) {
|
|
|
252
330
|
}
|
|
253
331
|
}
|
|
254
332
|
for (const [key, child] of Object.entries(value)) {
|
|
255
|
-
const childSchema = Object.hasOwn(props, key) ? props[key] :
|
|
333
|
+
const childSchema = Object.hasOwn(props, key) ? props[key] : extraSchema(schema, key);
|
|
256
334
|
if (childSchema === void 0) {
|
|
257
|
-
if (schema.additionalProperties
|
|
335
|
+
if (schema.additionalProperties !== void 0 && schema.additionalProperties !== true) {
|
|
258
336
|
errors.push(`${join(path, key)}: is not allowed`);
|
|
259
337
|
}
|
|
260
338
|
} else if (child !== void 0) {
|
|
@@ -296,6 +374,13 @@ var FlierDocError = class extends Error {
|
|
|
296
374
|
this.errors = errors;
|
|
297
375
|
}
|
|
298
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
|
+
}
|
|
299
384
|
function validateFlierDoc(input) {
|
|
300
385
|
if (typeName(input) !== "object") {
|
|
301
386
|
return { ok: false, errors: ["doc: must be an object"] };
|
|
@@ -306,6 +391,7 @@ function validateFlierDoc(input) {
|
|
|
306
391
|
if (doc.layout === "list" /* List */ && (doc.items === void 0 || doc.items.length === 0)) {
|
|
307
392
|
errors.push('items: layout "list" needs at least one item');
|
|
308
393
|
}
|
|
394
|
+
sameLineTies(doc).forEach((i) => errors.push(`lineTies[${i}].lines: must name two different lines`));
|
|
309
395
|
return errors.length === 0 ? { ok: true, doc } : { ok: false, errors };
|
|
310
396
|
}
|
|
311
397
|
function missingAssets(doc, assets) {
|
|
@@ -485,6 +571,47 @@ function placeContain(image, region, fit) {
|
|
|
485
571
|
};
|
|
486
572
|
}
|
|
487
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
|
+
|
|
488
615
|
// src/layout/blockGroups.ts
|
|
489
616
|
var BOLD = 700;
|
|
490
617
|
var SEMI = 600;
|
|
@@ -513,26 +640,27 @@ var GAP = {
|
|
|
513
640
|
includes: 24,
|
|
514
641
|
rule: 8
|
|
515
642
|
};
|
|
516
|
-
var makers = (p, u) => ({
|
|
517
|
-
display: (text2, size) => ({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }),
|
|
518
|
-
venue: (text2, size) => ({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }),
|
|
519
|
-
script: (text2, size) => ({ text: text2, role: "script", weight: SCRIPT, size: size * u, color: p.accent }),
|
|
520
|
-
strong: (text2, size) => ({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }),
|
|
521
|
-
accent: (text2, size) => ({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }),
|
|
522
|
-
item: (text2, size) => ({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }),
|
|
523
|
-
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)
|
|
524
651
|
});
|
|
525
652
|
function headerGroups(doc, p, u) {
|
|
526
|
-
const l = makers(p, u);
|
|
653
|
+
const l = makers(p, u, styleContext(doc));
|
|
527
654
|
const b = doc.blocks;
|
|
528
|
-
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];
|
|
529
656
|
return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
|
|
530
657
|
}
|
|
531
|
-
function itemGroup(item,
|
|
532
|
-
const
|
|
533
|
-
|
|
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}`)));
|
|
534
662
|
if (item.price) {
|
|
535
|
-
lines.push(l.accent(item.price, SIZE.itemRow));
|
|
663
|
+
lines.push(l.accent(item.price, SIZE.itemRow, `items.${n}.price`));
|
|
536
664
|
}
|
|
537
665
|
return { lines, gapAfter: GAP.item * u };
|
|
538
666
|
}
|
|
@@ -555,79 +683,143 @@ function eventGroups(doc, l, u, options) {
|
|
|
555
683
|
const groups = [];
|
|
556
684
|
const schedule2 = b.schedule ?? [];
|
|
557
685
|
schedule2.forEach((row, i) => {
|
|
558
|
-
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`)];
|
|
559
687
|
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1 });
|
|
560
688
|
});
|
|
561
689
|
const prices = (options.withPrices === false ? void 0 : b.prices) ?? [];
|
|
562
690
|
prices.forEach((row, i) => {
|
|
563
|
-
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`)];
|
|
564
692
|
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1 });
|
|
565
693
|
});
|
|
566
694
|
return groups;
|
|
567
695
|
}
|
|
568
696
|
function listGroups(doc, l, u, dateScale) {
|
|
569
|
-
const groups = (doc.items ?? []).map((item) => itemGroup(item, l, u, dateScale));
|
|
570
|
-
const prices = doc.blocks.prices?.map((row) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice)) ?? [];
|
|
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`)) ?? [];
|
|
571
699
|
if (prices.length > 0) {
|
|
572
700
|
groups.push({ lines: prices, gapAfter: GAP.row * u });
|
|
573
701
|
}
|
|
574
702
|
return groups;
|
|
575
703
|
}
|
|
576
704
|
function flankPriceGroups(doc, p, u) {
|
|
577
|
-
const l = makers(p, u);
|
|
578
|
-
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 }));
|
|
579
707
|
}
|
|
580
708
|
function bodyGroups(doc, p, u, options = {}) {
|
|
581
|
-
const l = makers(p, u);
|
|
709
|
+
const l = makers(p, u, styleContext(doc));
|
|
582
710
|
const b = doc.blocks;
|
|
583
711
|
const groups = [];
|
|
584
712
|
const isList = doc.layout === "list" /* List */;
|
|
585
713
|
if (b.venue) {
|
|
586
714
|
const size = isList ? SIZE.listVenue : SIZE.venue;
|
|
587
715
|
const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
|
|
588
|
-
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 });
|
|
589
717
|
}
|
|
590
718
|
groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, options));
|
|
591
719
|
if (b.includes) {
|
|
592
|
-
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));
|
|
593
721
|
groups.push({ lines, gapAfter: GAP.includes * u, uniform: true, keepWithNext: b.footer !== void 0, attachNext: b.footer !== void 0 });
|
|
594
722
|
}
|
|
595
723
|
if (b.footer) {
|
|
596
|
-
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 });
|
|
597
725
|
}
|
|
598
726
|
return groups;
|
|
599
727
|
}
|
|
600
728
|
|
|
601
|
-
// src/layout/
|
|
729
|
+
// src/layout/lineSizes.ts
|
|
602
730
|
var LINE_HEIGHT = 1.2;
|
|
603
731
|
var BULLET_INDENT = 1.1;
|
|
604
|
-
var BULLET_RADIUS = 0.2;
|
|
605
|
-
var RULE_GAP = 2.5;
|
|
606
|
-
var RULE_WIDTH = 0.9;
|
|
607
|
-
var WIDE = 1.6;
|
|
608
|
-
var COLUMN_GAP = 0.04;
|
|
609
|
-
var TWO_COLUMN_MIN = 0.75;
|
|
610
|
-
var TWO_COLUMN_GAIN = 1.15;
|
|
611
|
-
var MIN_K = 0.02;
|
|
612
|
-
var STEPS = 22;
|
|
613
732
|
var ICON_SCALE = 1.6;
|
|
614
733
|
var ICON_GAP = 0.35;
|
|
615
|
-
var fontOf = (line, size, fonts) => `${line.weight} ${size}px ${fonts[line.role]}`;
|
|
616
|
-
var emptyFlow = () => ({ texts: [], cards: [], rules: [], bullets: [], icons: [] });
|
|
617
734
|
var indented = (line) => line.bullet !== void 0 || line.hang === true;
|
|
735
|
+
var bulletIndent = (line, k) => indented(line) ? line.size * k * BULLET_INDENT : 0;
|
|
618
736
|
var iconSize = (group, k) => {
|
|
619
737
|
const first = group.lines[0];
|
|
620
738
|
return group.icon && first ? first.size * k * LINE_HEIGHT * ICON_SCALE : 0;
|
|
621
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
|
+
}
|
|
622
746
|
function lineSize(line, width, k, avail) {
|
|
623
|
-
const indent =
|
|
747
|
+
const indent = bulletIndent(line, k);
|
|
624
748
|
return Math.max(0, Math.min(line.size * k, line.size * (avail - indent) / Math.max(width, 1)));
|
|
625
749
|
}
|
|
626
|
-
function
|
|
750
|
+
function groupSizes(m, k, avail) {
|
|
751
|
+
const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail));
|
|
627
752
|
if (!m.group.uniform) {
|
|
628
|
-
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;
|
|
629
822
|
}
|
|
630
|
-
return Math.min(...m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail) / line.size));
|
|
631
823
|
}
|
|
632
824
|
function placeIcon(group, box, out) {
|
|
633
825
|
const { d, x, top, bottom: bottom2 } = box;
|
|
@@ -639,25 +831,21 @@ function placeIcon(group, box, out) {
|
|
|
639
831
|
return top + Math.max(textH, d);
|
|
640
832
|
}
|
|
641
833
|
function placeGroup(m, at, out) {
|
|
642
|
-
const { k, col, y0 } = at;
|
|
834
|
+
const { k, col, y0, sizes } = at;
|
|
643
835
|
const { group } = m;
|
|
644
836
|
let y = y0;
|
|
645
837
|
if (group.rule) {
|
|
646
838
|
out?.rules.push({ rect: { x: col.x, y, w: col.w * RULE_WIDTH, h: group.rule.height * k }, color: group.rule.color });
|
|
647
839
|
y += group.rule.height * k * RULE_GAP;
|
|
648
840
|
}
|
|
649
|
-
const pad
|
|
841
|
+
const { pad, d, iconIndent } = groupBox(group, k, col.w);
|
|
650
842
|
const top = y;
|
|
651
843
|
y += pad;
|
|
652
|
-
const d = iconSize(group, k);
|
|
653
|
-
const iconIndent = d > 0 ? d * (1 + ICON_GAP) : 0;
|
|
654
|
-
const avail = col.w - 2 * pad - iconIndent;
|
|
655
|
-
const ratio = groupRatio(m, k, avail);
|
|
656
844
|
group.lines.forEach((line, i) => {
|
|
657
|
-
const size =
|
|
845
|
+
const size = sizes[i] ?? 0;
|
|
658
846
|
const indent = (indented(line) ? line.size * k * BULLET_INDENT : 0) + iconIndent;
|
|
659
847
|
const w = (m.widths[i] ?? 0) * size / line.size;
|
|
660
|
-
const x =
|
|
848
|
+
const x = lineX(line, { col, pad, indent, w });
|
|
661
849
|
out?.texts.push({ text: line.text, font: "", color: line.color, box: { x, y, w, h: size * LINE_HEIGHT } });
|
|
662
850
|
if (line.bullet && out) {
|
|
663
851
|
out.bullets.push({ x: col.x + pad + size * BULLET_RADIUS, y: y + size * LINE_HEIGHT / 2, r: size * BULLET_RADIUS, color: line.bullet });
|
|
@@ -677,10 +865,10 @@ function placeGroup(m, at, out) {
|
|
|
677
865
|
return y + group.gapAfter * k - y0;
|
|
678
866
|
}
|
|
679
867
|
function placeColumn(groups, at, out) {
|
|
680
|
-
const { k, col, spread = 0 } = at;
|
|
868
|
+
const { k, col, table, spread = 0 } = at;
|
|
681
869
|
let h = 0;
|
|
682
870
|
groups.forEach((g, i) => {
|
|
683
|
-
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);
|
|
684
872
|
if (i < groups.length - 1 && g.group.attachNext !== true) {
|
|
685
873
|
h += spread;
|
|
686
874
|
}
|
|
@@ -713,7 +901,8 @@ function keepTogether(groups, heights, cut) {
|
|
|
713
901
|
function splitColumns(groups, zone) {
|
|
714
902
|
const gap = Math.round(zone.w * COLUMN_GAP);
|
|
715
903
|
const w = (zone.w - gap) / 2;
|
|
716
|
-
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));
|
|
717
906
|
const total = columnSum(heights, 0, heights.length);
|
|
718
907
|
let cut = 1;
|
|
719
908
|
for (let c = 2; c < groups.length; c++) {
|
|
@@ -727,8 +916,12 @@ function splitColumns(groups, zone) {
|
|
|
727
916
|
{ col: { ...zone, x: zone.x + w + gap, w }, groups: groups.slice(cut) }
|
|
728
917
|
];
|
|
729
918
|
}
|
|
919
|
+
var tableFor = (columns, k) => sizeTable(columns.flatMap((c) => c.groups), k, columns[0]?.col.w ?? 0);
|
|
730
920
|
function largestK(columns, zoneH) {
|
|
731
|
-
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
|
+
};
|
|
732
925
|
let lo = MIN_K;
|
|
733
926
|
let hi = 1;
|
|
734
927
|
if (fits(1)) {
|
|
@@ -755,26 +948,37 @@ function bestColumns(measured, zone) {
|
|
|
755
948
|
const forced = zone.w / Math.max(zone.h, 1) > WIDE;
|
|
756
949
|
return forced || k2 > k1 * TWO_COLUMN_GAIN ? { columns: split, k: k2 } : { columns: single, k: k1 };
|
|
757
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
|
+
}
|
|
758
961
|
function flow(ctx, groups, zone, fonts) {
|
|
759
962
|
const measured = groups.map((group) => ({
|
|
760
963
|
group,
|
|
761
|
-
widths: group.lines.map((line) =>
|
|
762
|
-
ctx.font = fontOf(line, line.size, fonts);
|
|
763
|
-
return ctx.measureText(line.text).width;
|
|
764
|
-
})
|
|
964
|
+
widths: group.lines.map((line) => measure(ctx, line, fonts))
|
|
765
965
|
}));
|
|
766
966
|
const { columns, k: lo } = bestColumns(measured, zone);
|
|
767
967
|
const out = emptyFlow();
|
|
768
|
-
const
|
|
968
|
+
const table = tableFor(columns, lo);
|
|
969
|
+
const heights = columns.map((c) => placeColumn(c.groups, { k: lo, col: c.col, table }, null));
|
|
769
970
|
const end = Math.max(...heights);
|
|
770
971
|
columns.forEach((c, i) => {
|
|
771
972
|
const gaps = spreadGaps(c.groups);
|
|
772
|
-
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);
|
|
773
974
|
});
|
|
774
975
|
const lines = groups.flatMap((g) => g.lines);
|
|
775
976
|
out.texts.forEach((t, i) => {
|
|
776
977
|
const line = lines[i];
|
|
777
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
|
+
}
|
|
778
982
|
});
|
|
779
983
|
return out;
|
|
780
984
|
}
|
|
@@ -917,6 +1121,7 @@ function fitToFloor(ctx, input) {
|
|
|
917
1121
|
|
|
918
1122
|
// src/render/render.ts
|
|
919
1123
|
var BASE2 = 1080;
|
|
1124
|
+
var NO_SPACING2 = "0px";
|
|
920
1125
|
var CARD_RADIUS = 0.035;
|
|
921
1126
|
var CAP_TOP = 0.15;
|
|
922
1127
|
var PIN_HEAD_Y = 0.08;
|
|
@@ -977,7 +1182,13 @@ function drawFlow(ctx, f, radius) {
|
|
|
977
1182
|
f.texts.forEach((t) => {
|
|
978
1183
|
ctx.font = t.font;
|
|
979
1184
|
ctx.fillStyle = t.color;
|
|
1185
|
+
if (t.spacing !== void 0) {
|
|
1186
|
+
ctx.letterSpacing = t.spacing;
|
|
1187
|
+
}
|
|
980
1188
|
ctx.fillText(t.text, t.box.x, t.box.y);
|
|
1189
|
+
if (t.spacing !== void 0) {
|
|
1190
|
+
ctx.letterSpacing = NO_SPACING2;
|
|
1191
|
+
}
|
|
981
1192
|
});
|
|
982
1193
|
}
|
|
983
1194
|
function checked(input, assets) {
|
|
@@ -1157,7 +1368,10 @@ exports.FlierDocError = FlierDocError;
|
|
|
1157
1368
|
exports.FontSetId = FontSetId;
|
|
1158
1369
|
exports.FormatId = FormatId;
|
|
1159
1370
|
exports.LAYOUT_CATALOGUE = LAYOUT_CATALOGUE;
|
|
1371
|
+
exports.LINE_KEY_PATTERN = LINE_KEY_PATTERN;
|
|
1160
1372
|
exports.LayoutId = LayoutId;
|
|
1373
|
+
exports.LineAlign = LineAlign;
|
|
1374
|
+
exports.LineTieKind = LineTieKind;
|
|
1161
1375
|
exports.PALETTES = PALETTES;
|
|
1162
1376
|
exports.PaletteId = PaletteId;
|
|
1163
1377
|
exports.PictureAnchor = PictureAnchor;
|
|
@@ -1167,6 +1381,8 @@ exports.flierDocSchema = flierDocSchema;
|
|
|
1167
1381
|
exports.kizombaWorkshop = kizombaWorkshop;
|
|
1168
1382
|
exports.kizombaWorkshopDocs = kizombaWorkshopDocs;
|
|
1169
1383
|
exports.render = render;
|
|
1384
|
+
exports.sameSize = sameSize;
|
|
1385
|
+
exports.sameWidth = sameWidth;
|
|
1170
1386
|
exports.validateFlierDoc = validateFlierDoc;
|
|
1171
1387
|
//# sourceMappingURL=index.js.map
|
|
1172
1388
|
//# sourceMappingURL=index.js.map
|