@dloizides/poster-render 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -3,6 +3,7 @@ var BackgroundStyle = /* @__PURE__ */ ((BackgroundStyle2) => {
3
3
  BackgroundStyle2["Solid"] = "solid";
4
4
  BackgroundStyle2["Tint"] = "tint";
5
5
  BackgroundStyle2["Horizon"] = "horizon";
6
+ BackgroundStyle2["Brush"] = "brush";
6
7
  return BackgroundStyle2;
7
8
  })(BackgroundStyle || {});
8
9
 
@@ -12,6 +13,7 @@ var FontSetId = /* @__PURE__ */ ((FontSetId2) => {
12
13
  FontSetId2["Modern"] = "modern";
13
14
  FontSetId2["Elegant"] = "elegant";
14
15
  FontSetId2["Coastal"] = "coastal";
16
+ FontSetId2["KizombaSample"] = "kizomba-sample";
15
17
  return FontSetId2;
16
18
  })(FontSetId || {});
17
19
 
@@ -46,6 +48,7 @@ var PaletteId = /* @__PURE__ */ ((PaletteId2) => {
46
48
  PaletteId2["Sea"] = "sea";
47
49
  PaletteId2["Rose"] = "rose";
48
50
  PaletteId2["GoldenHorizon"] = "golden-horizon";
51
+ PaletteId2["KizombaSample"] = "kizomba-sample";
49
52
  return PaletteId2;
50
53
  })(PaletteId || {});
51
54
 
@@ -57,6 +60,79 @@ var PictureAnchor = /* @__PURE__ */ ((PictureAnchor2) => {
57
60
  return PictureAnchor2;
58
61
  })(PictureAnchor || {});
59
62
 
63
+ // src/enums/LineAlign.ts
64
+ var LineAlign = /* @__PURE__ */ ((LineAlign2) => {
65
+ LineAlign2["Left"] = "left";
66
+ LineAlign2["Center"] = "center";
67
+ LineAlign2["Right"] = "right";
68
+ return LineAlign2;
69
+ })(LineAlign || {});
70
+
71
+ // src/enums/LineTieKind.ts
72
+ var LineTieKind = /* @__PURE__ */ ((LineTieKind2) => {
73
+ LineTieKind2["Width"] = "width";
74
+ LineTieKind2["Size"] = "size";
75
+ return LineTieKind2;
76
+ })(LineTieKind || {});
77
+
78
+ // src/enums/RowIcon.ts
79
+ var RowIcon = /* @__PURE__ */ ((RowIcon2) => {
80
+ RowIcon2["Person"] = "person";
81
+ RowIcon2["People"] = "people";
82
+ RowIcon2["Ticket"] = "ticket";
83
+ return RowIcon2;
84
+ })(RowIcon || {});
85
+
86
+ // src/schema/lineStyleSchema.ts
87
+ 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]))$";
88
+ var MAX_FONT = 40;
89
+ var MIN_SIZE_SCALE = 0.25;
90
+ var MAX_SIZE_SCALE = 3;
91
+ var MIN_SPACING = -0.1;
92
+ var MAX_SPACING = 0.5;
93
+ var MAX_TIES = 12;
94
+ var WEIGHTS = [100, 200, 300, 400, 500, 600, 700, 800, 900];
95
+ var lineKey = { type: "string", pattern: LINE_KEY_PATTERN };
96
+ var lineStyle = {
97
+ type: "object",
98
+ additionalProperties: false,
99
+ properties: {
100
+ font: { type: "string", minLength: 1, maxLength: MAX_FONT, pattern: "^[A-Za-z0-9 ]+$" },
101
+ sizeScale: { type: "number", minimum: MIN_SIZE_SCALE, maximum: MAX_SIZE_SCALE },
102
+ color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
103
+ weight: { type: "integer", enum: WEIGHTS },
104
+ italic: { type: "boolean" },
105
+ letterSpacing: { type: "number", minimum: MIN_SPACING, maximum: MAX_SPACING },
106
+ align: { type: "string", enum: Object.values(LineAlign) }
107
+ }
108
+ };
109
+ var lineStylesSchema = { type: "object", propertyNames: lineKey, additionalProperties: lineStyle };
110
+ var lineTiesSchema = {
111
+ type: "array",
112
+ maxItems: MAX_TIES,
113
+ items: {
114
+ type: "object",
115
+ required: ["kind", "lines"],
116
+ additionalProperties: false,
117
+ properties: {
118
+ kind: { type: "string", enum: Object.values(LineTieKind) },
119
+ lines: { type: "array", minItems: 2, maxItems: 2, items: lineKey }
120
+ }
121
+ }
122
+ };
123
+
124
+ // src/lineTies.ts
125
+ function tie(doc, kind, a, b) {
126
+ const ties = doc.lineTies ?? [];
127
+ const exists = ties.some((t) => t.kind === kind && t.lines.includes(a) && t.lines.includes(b));
128
+ if (a === b || exists) {
129
+ return doc;
130
+ }
131
+ return { ...doc, lineTies: [...ties, { kind, lines: [a, b] }] };
132
+ }
133
+ var sameWidth = (doc, a, b) => tie(doc, "width" /* Width */, a, b);
134
+ var sameSize = (doc, a, b) => tie(doc, "size" /* Size */, a, b);
135
+
60
136
  // src/formats.ts
61
137
  var FORMAT_SIZES = {
62
138
  ["story" /* Story */]: { width: 1080, height: 1920 },
@@ -82,6 +158,20 @@ var PALETTES = {
82
158
  arch: "#c7d4d6",
83
159
  sky: [[0, "#bfd3d8"], [0.55, "#d4dddd"], [1, "#eadccb"]]
84
160
  },
161
+ ["kizomba-sample" /* KizombaSample */]: {
162
+ background: "#fefefe",
163
+ tint: "#f3eee9",
164
+ title: "#6d645d",
165
+ accent: "#ad8164",
166
+ ink: "#45372f",
167
+ soft: "#9c8f84",
168
+ card: "#ffffff",
169
+ arch: "#efe8e1",
170
+ script: "#e5bb97",
171
+ icon: "#cca383",
172
+ rule: "#d5bca8",
173
+ brush: ["#cdc3b9", "#96918b", "#daae81"]
174
+ },
85
175
  ["rose" /* Rose */]: { background: "#f8efec", tint: "#f1e2dd", title: "#9b6b63", accent: "#c9846f", ink: "#4a3934", soft: "#b39a92", card: "#ffffff", arch: "#f1e5e1" }
86
176
  };
87
177
 
@@ -90,15 +180,65 @@ var FONT_SETS = {
90
180
  ["classic" /* Classic */]: { display: '"Oswald", "Arial Narrow", sans-serif', script: '"Sacramento", cursive', body: '"Fredoka", sans-serif' },
91
181
  ["modern" /* Modern */]: { display: '"Bebas Neue", "Arial Narrow", sans-serif', script: '"Great Vibes", cursive', body: '"Montserrat", sans-serif' },
92
182
  ["elegant" /* Elegant */]: { display: '"Playfair Display", serif', script: '"Allura", cursive', body: '"Lato", sans-serif' },
183
+ ["kizomba-sample" /* KizombaSample */]: { display: '"Anton", "Oswald", "Arial Narrow", sans-serif', script: '"Sacramento", cursive', body: '"Barlow Semi Condensed", "Fredoka", sans-serif' },
93
184
  ["coastal" /* Coastal */]: { display: '"Fraunces", Georgia, serif', script: '"Allura", cursive', body: '"Jost", sans-serif' }
94
185
  };
95
186
 
187
+ // src/schema/rowsSchema.ts
188
+ var MAX_ROWS = 6;
189
+ var MAX_PRICES = 4;
190
+ var MIN_ICON = 16;
191
+ var MAX_ICON = 300;
192
+ var MIN_THICKNESS = 0.5;
193
+ var MAX_THICKNESS = 20;
194
+ var MAX_GAP = 120;
195
+ var MAX_OVERLAP = 1.5;
196
+ var MAX_SHIFT = 0.5;
197
+ var MAX_TOP = 600;
198
+ var MAX_LINE_GAP = 200;
199
+ var MIN_TITLE_SCALE = 0.3;
200
+ var MAX_TITLE_SCALE = 2.5;
201
+ var num = (minimum, maximum) => ({ type: "number", minimum, maximum });
202
+ var icons = (maxItems) => ({ type: "array", items: { type: "string", enum: Object.values(RowIcon) }, minItems: 1, maxItems });
203
+ var rowsSchema = {
204
+ type: "object",
205
+ additionalProperties: false,
206
+ properties: {
207
+ icons: { type: "object", additionalProperties: false, properties: { schedule: icons(MAX_ROWS), prices: icons(MAX_PRICES), size: num(MIN_ICON, MAX_ICON) } },
208
+ dividers: {
209
+ type: "object",
210
+ required: ["thickness"],
211
+ additionalProperties: false,
212
+ properties: {
213
+ thickness: num(MIN_THICKNESS, MAX_THICKNESS),
214
+ color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
215
+ gap: num(0, MAX_GAP),
216
+ toPicture: { type: "boolean" },
217
+ reach: num(0, 1)
218
+ }
219
+ }
220
+ }
221
+ };
222
+ var overlapSchema = {
223
+ type: "object",
224
+ required: ["scale", "dx", "dy"],
225
+ additionalProperties: false,
226
+ properties: { scale: num(1, MAX_OVERLAP), dx: num(-MAX_SHIFT, MAX_SHIFT), dy: num(-MAX_SHIFT, MAX_SHIFT) }
227
+ };
228
+ var headerTuningSchema = {
229
+ headerTop: num(0, MAX_TOP),
230
+ titleScriptGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
231
+ scriptTitleGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
232
+ titleScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
233
+ titleBottomScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE)
234
+ };
235
+
96
236
  // src/schema/flierDocSchema.ts
97
237
  var SHORT = 60;
98
238
  var LINE = 120;
99
- var MAX_ROWS = 6;
239
+ var MAX_ROWS2 = 6;
100
240
  var MAX_ITEMS = 8;
101
- var MAX_PRICES = 4;
241
+ var MAX_PRICES2 = 4;
102
242
  var MAX_VENUE = 3;
103
243
  var MIN_SCALE = 0.3;
104
244
  var MAX_HEADER_GAP = 200;
@@ -111,7 +251,7 @@ var scheduleRow = {
111
251
  additionalProperties: false,
112
252
  properties: { label: text(SHORT), time: text(SHORT) }
113
253
  };
114
- var scheduleList = { type: "array", items: scheduleRow, minItems: 1, maxItems: MAX_ROWS };
254
+ var scheduleList = { type: "array", items: scheduleRow, minItems: 1, maxItems: MAX_ROWS2 };
115
255
  var blocks = {
116
256
  type: "object",
117
257
  required: ["title"],
@@ -125,7 +265,7 @@ var blocks = {
125
265
  prices: {
126
266
  type: "array",
127
267
  minItems: 1,
128
- maxItems: MAX_PRICES,
268
+ maxItems: MAX_PRICES2,
129
269
  items: {
130
270
  type: "object",
131
271
  required: ["amount", "label"],
@@ -137,7 +277,7 @@ var blocks = {
137
277
  type: "object",
138
278
  required: ["heading", "items"],
139
279
  additionalProperties: false,
140
- properties: { heading: text(SHORT), items: { type: "array", items: text(LINE), minItems: 1, maxItems: MAX_ROWS } }
280
+ properties: { heading: text(SHORT), items: { type: "array", items: text(LINE), minItems: 1, maxItems: MAX_ROWS2 } }
141
281
  },
142
282
  footer: text(LINE)
143
283
  }
@@ -164,7 +304,8 @@ var flierDocSchema = {
164
304
  properties: {
165
305
  imageId: text(SHORT),
166
306
  anchor: { type: "string", enum: Object.values(PictureAnchor) },
167
- scale: { type: "number", minimum: MIN_SCALE, maximum: 1 }
307
+ scale: { type: "number", minimum: MIN_SCALE, maximum: 1 },
308
+ overlap: overlapSchema
168
309
  }
169
310
  },
170
311
  logo: { type: "object", required: ["imageId"], additionalProperties: false, properties: { imageId: text(SHORT) } },
@@ -174,9 +315,13 @@ var flierDocSchema = {
174
315
  additionalProperties: false,
175
316
  properties: {
176
317
  headerGap: { type: "number", minimum: 0, maximum: MAX_HEADER_GAP },
177
- itemDateScale: { type: "number", minimum: MIN_DATE_SCALE, maximum: MAX_DATE_SCALE }
318
+ itemDateScale: { type: "number", minimum: MIN_DATE_SCALE, maximum: MAX_DATE_SCALE },
319
+ ...headerTuningSchema
178
320
  }
179
321
  },
322
+ lineStyles: lineStylesSchema,
323
+ lineTies: lineTiesSchema,
324
+ rows: rowsSchema,
180
325
  items: {
181
326
  type: "array",
182
327
  minItems: 1,
@@ -200,7 +345,7 @@ var typeName = (v) => {
200
345
  };
201
346
  var join = (path, key) => path === "" ? key : `${path}.${key}`;
202
347
  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" };
348
+ var ARTICLE = { object: "an object", array: "an array", string: "a string", number: "a number", integer: "an integer", boolean: "a boolean" };
204
349
  function matchesType(schema, value) {
205
350
  switch (schema.type) {
206
351
  case void 0:
@@ -220,6 +365,9 @@ function checkString(schema, value, path, errors) {
220
365
  if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
221
366
  errors.push(`${path}: must be at most ${schema.maxLength} characters (got ${value.length})`);
222
367
  }
368
+ if (schema.pattern !== void 0 && !new RegExp(schema.pattern).test(value)) {
369
+ errors.push(`${path}: has an invalid format`);
370
+ }
223
371
  }
224
372
  function checkNumber(schema, value, path, errors) {
225
373
  if (schema.minimum !== void 0 && value < schema.minimum) {
@@ -242,6 +390,14 @@ function checkArray(schema, value, path, errors) {
242
390
  value.forEach((item, i) => validateAgainst(itemSchema, item, `${path}[${i}]`, errors));
243
391
  }
244
392
  }
393
+ function extraSchema(schema, key) {
394
+ const extra = schema.additionalProperties;
395
+ if (typeof extra !== "object") {
396
+ return void 0;
397
+ }
398
+ const names = schema.propertyNames?.pattern;
399
+ return names === void 0 || new RegExp(names).test(key) ? extra : void 0;
400
+ }
245
401
  function checkObject(schema, value, path, errors) {
246
402
  const props = schema.properties ?? {};
247
403
  for (const key of schema.required ?? []) {
@@ -250,9 +406,9 @@ function checkObject(schema, value, path, errors) {
250
406
  }
251
407
  }
252
408
  for (const [key, child] of Object.entries(value)) {
253
- const childSchema = Object.hasOwn(props, key) ? props[key] : void 0;
409
+ const childSchema = Object.hasOwn(props, key) ? props[key] : extraSchema(schema, key);
254
410
  if (childSchema === void 0) {
255
- if (schema.additionalProperties === false) {
411
+ if (schema.additionalProperties !== void 0 && schema.additionalProperties !== true) {
256
412
  errors.push(`${join(path, key)}: is not allowed`);
257
413
  }
258
414
  } else if (child !== void 0) {
@@ -294,6 +450,13 @@ var FlierDocError = class extends Error {
294
450
  this.errors = errors;
295
451
  }
296
452
  };
453
+ function sameLineTies(doc) {
454
+ const ties = doc.lineTies;
455
+ if (!Array.isArray(ties)) {
456
+ return [];
457
+ }
458
+ return ties.flatMap((tie2, i) => Array.isArray(tie2?.lines) && tie2.lines.length === 2 && tie2.lines[0] === tie2.lines[1] ? [i] : []);
459
+ }
297
460
  function validateFlierDoc(input) {
298
461
  if (typeName(input) !== "object") {
299
462
  return { ok: false, errors: ["doc: must be an object"] };
@@ -304,6 +467,7 @@ function validateFlierDoc(input) {
304
467
  if (doc.layout === "list" /* List */ && (doc.items === void 0 || doc.items.length === 0)) {
305
468
  errors.push('items: layout "list" needs at least one item');
306
469
  }
470
+ sameLineTies(doc).forEach((i) => errors.push(`lineTies[${i}].lines: must name two different lines`));
307
471
  return errors.length === 0 ? { ok: true, doc } : { ok: false, errors };
308
472
  }
309
473
  function missingAssets(doc, assets) {
@@ -317,6 +481,92 @@ function missingAssets(doc, assets) {
317
481
  return errors;
318
482
  }
319
483
 
484
+ // src/render/shapes.ts
485
+ function polygon(ctx, pts) {
486
+ const first = pts[0];
487
+ if (!first) {
488
+ return;
489
+ }
490
+ ctx.beginPath();
491
+ ctx.moveTo(first[0], first[1]);
492
+ pts.slice(1).forEach((p, i) => {
493
+ const next = pts[i + 2] ?? first;
494
+ ctx.arcTo(p[0], p[1], next[0], next[1], 0);
495
+ });
496
+ ctx.closePath();
497
+ ctx.fill();
498
+ }
499
+ function disc(ctx, c, r3, color) {
500
+ ctx.fillStyle = color;
501
+ ctx.beginPath();
502
+ ctx.arc(c[0], c[1], Math.max(0, r3), 0, Math.PI * 2);
503
+ ctx.fill();
504
+ }
505
+ function turnedRect(c, size, angle) {
506
+ const cos = Math.cos(angle);
507
+ const sin = Math.sin(angle);
508
+ const hw = size.w / 2;
509
+ const hh = size.h / 2;
510
+ const corners = [[-hw, -hh], [hw, -hh], [hw, hh], [-hw, hh]];
511
+ return corners.map(([px, py]) => [c[0] + px * cos - py * sin, c[1] + px * sin + py * cos]);
512
+ }
513
+
514
+ // src/render/brush.ts
515
+ var CLUSTERS = [
516
+ { x: -0.14, y: 0.13, w: 0.42, h: 0.35, tone: 0 },
517
+ { x: -0.16, y: 0.78, w: 0.36, h: 0.22, tone: 1 },
518
+ { x: 0.78, y: 0.63, w: 0.3, h: 0.3, tone: 2 }
519
+ ];
520
+ var STROKES = 7;
521
+ var ALPHA = 0.55;
522
+ var SLANT = -0.3;
523
+ var TAPER = 0.3;
524
+ var SEED = 42;
525
+ var PM_A = 16807;
526
+ var PM_M = 2147483647;
527
+ var JITTER = 0.3;
528
+ var MIN_LENGTH = 0.7;
529
+ var MIN_THICK = 0.6;
530
+ var THICK_RANGE = 0.8;
531
+ var HALF = 0.5;
532
+ function random(seed) {
533
+ let s = seed;
534
+ return () => {
535
+ s = s * PM_A % PM_M;
536
+ return s / PM_M;
537
+ };
538
+ }
539
+ function stroke(ctx, c, length, thick) {
540
+ const dx = Math.cos(SLANT) * length / 2;
541
+ const dy = Math.sin(SLANT) * length / 2;
542
+ const nx = -Math.sin(SLANT);
543
+ const ny = Math.cos(SLANT);
544
+ const a = thick / 2;
545
+ const b = thick * TAPER / 2;
546
+ polygon(ctx, [
547
+ [c[0] - dx + nx * a, c[1] - dy + ny * a],
548
+ [c[0] + dx + nx * b, c[1] + dy + ny * b],
549
+ [c[0] + dx - nx * b, c[1] + dy - ny * b],
550
+ [c[0] - dx - nx * a, c[1] - dy - ny * a]
551
+ ]);
552
+ }
553
+ function paintBrush(ctx, picture, colors) {
554
+ if (colors.length === 0) {
555
+ return;
556
+ }
557
+ const next = random(SEED);
558
+ ctx.globalAlpha = ALPHA;
559
+ CLUSTERS.forEach((cl) => {
560
+ ctx.fillStyle = colors[cl.tone % colors.length] ?? colors[0] ?? "";
561
+ const box = { x: picture.x + picture.w * cl.x, y: picture.y + picture.h * cl.y, w: picture.w * cl.w, h: picture.h * cl.h };
562
+ for (let i = 0; i < STROKES; i++) {
563
+ const c = [box.x + box.w * (HALF + (next() - HALF) * JITTER), box.y + box.h * (i + HALF) / STROKES];
564
+ stroke(ctx, c, box.w * (MIN_LENGTH + (1 - MIN_LENGTH) * next()), box.h / STROKES * (MIN_THICK + THICK_RANGE * next()));
565
+ }
566
+ });
567
+ ctx.globalAlpha = 1;
568
+ }
569
+
320
570
  // src/render/background.ts
321
571
  function paintGround(ctx, style, palette, size) {
322
572
  ctx.fillStyle = palette.background;
@@ -328,6 +578,17 @@ function paintGround(ctx, style, palette, size) {
328
578
  }
329
579
  ctx.fillRect(0, 0, size.width, size.height);
330
580
  }
581
+ function paintPage(ctx, doc, palette, page) {
582
+ ctx.globalAlpha = 1;
583
+ paintGround(ctx, doc.background, palette, page);
584
+ if (doc.background === "tint" /* Tint */) {
585
+ ctx.fillStyle = palette.tint;
586
+ [page.geo.header, page.geo.body].forEach((r3) => ctx.fillRect(r3.x, r3.y, r3.w, r3.h));
587
+ }
588
+ if (doc.background === "brush" /* Brush */ && page.picture) {
589
+ paintBrush(ctx, page.picture, palette.brush ?? [palette.tint, palette.arch]);
590
+ }
591
+ }
331
592
 
332
593
  // src/layout/layoutSpecs.ts
333
594
  var flanksBeside = (pic, top, bottom2, m) => [
@@ -483,6 +744,47 @@ function placeContain(image, region, fit) {
483
744
  };
484
745
  }
485
746
 
747
+ // src/layout/lineStyle.ts
748
+ function tieIds(ties, kind) {
749
+ const ids = /* @__PURE__ */ new Map();
750
+ ties.filter((t) => t.kind === kind).forEach((t, n) => {
751
+ const [a, b] = t.lines;
752
+ const ia = ids.get(a);
753
+ const ib = ids.get(b);
754
+ const id = ia ?? ib ?? n;
755
+ ids.set(a, id);
756
+ ids.set(b, id);
757
+ if (ib !== void 0 && ib !== id) {
758
+ [...ids.entries()].filter(([, v]) => v === ib).forEach(([key]) => ids.set(key, id));
759
+ }
760
+ });
761
+ return ids;
762
+ }
763
+ function styleContext(doc) {
764
+ const ties = doc.lineTies ?? [];
765
+ return { styles: doc.lineStyles ?? {}, width: tieIds(ties, "width" /* Width */), size: tieIds(ties, "size" /* Size */) };
766
+ }
767
+ function styled(line, key, sc) {
768
+ const style = Object.hasOwn(sc.styles, key) ? sc.styles[key] : void 0;
769
+ const widthTie = sc.width.get(key);
770
+ const sizeTie = sc.size.get(key);
771
+ if (style === void 0 && widthTie === void 0 && sizeTie === void 0) {
772
+ return line;
773
+ }
774
+ return {
775
+ ...line,
776
+ size: line.size * (style?.sizeScale ?? 1),
777
+ color: style?.color ?? line.color,
778
+ weight: style?.weight ?? line.weight,
779
+ family: style?.font,
780
+ italic: style?.italic,
781
+ spacing: style?.letterSpacing,
782
+ align: style?.align,
783
+ widthTie,
784
+ sizeTie
785
+ };
786
+ }
787
+
486
788
  // src/layout/blockGroups.ts
487
789
  var BOLD = 700;
488
790
  var SEMI = 600;
@@ -509,32 +811,51 @@ var GAP = {
509
811
  row: 30,
510
812
  venue: 40,
511
813
  includes: 24,
512
- rule: 8
814
+ rule: 8,
815
+ divider: 24
513
816
  };
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 })
817
+ var makers = (p, u, sc) => ({
818
+ display: (text2, size, key) => styled({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }, key, sc),
819
+ venue: (text2, size, key) => styled({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }, key, sc),
820
+ script: (text2, size, key) => styled({ text: text2, role: "script", weight: SCRIPT, size: size * u, color: p.script ?? p.accent }, key, sc),
821
+ strong: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
822
+ accent: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }, key, sc),
823
+ item: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }, key, sc),
824
+ soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc)
522
825
  });
523
826
  function headerGroups(doc, p, u) {
524
- const l = makers(p, u);
827
+ const l = makers(p, u, styleContext(doc));
525
828
  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];
829
+ const t = doc.tuning;
830
+ const gap = (line, after) => after === void 0 ? line : { ...line, gapAfter: after * u };
831
+ const title = gap(l.display(b.title, SIZE.title * (t?.titleScale ?? 1), "title"), b.script ?? b.titleBottom ? t?.titleScriptGap : void 0);
832
+ const script = b.script ? gap(l.script(b.script, SIZE.headerScript, "script"), b.titleBottom ? t?.scriptTitleGap : void 0) : void 0;
833
+ const lines = [title, script, b.titleBottom ? l.display(b.titleBottom, SIZE.title * (t?.titleBottomScale ?? 1), "titleBottom") : void 0];
527
834
  return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
528
835
  }
529
- function itemGroup(item, l, u, dateScale) {
530
- const lines = [l.script(item.date, SIZE.itemDate * dateScale)];
531
- item.schedule.forEach((row) => lines.push(l.strong(`${row.label} ${row.time}`, SIZE.itemRow)));
836
+ function itemGroup(item, n, l, scale) {
837
+ const { u, dateScale } = scale;
838
+ const lines = [l.script(item.date, SIZE.itemDate * dateScale, `items.${n}.date`)];
839
+ item.schedule.forEach((row, m) => lines.push(l.strong(`${row.label} ${row.time}`, SIZE.itemRow, `items.${n}.schedule.${m}`)));
532
840
  if (item.price) {
533
- lines.push(l.accent(item.price, SIZE.itemRow));
841
+ lines.push(l.accent(item.price, SIZE.itemRow, `items.${n}.price`));
534
842
  }
535
843
  return { lines, gapAfter: GAP.item * u };
536
844
  }
537
845
  var WRAP_FROM = 14;
846
+ function dividerOf(doc, p, u) {
847
+ const d = doc.rows?.dividers;
848
+ return d === void 0 ? void 0 : { color: d.color ?? p.rule ?? p.accent, height: d.thickness * u, gap: (d.gap ?? GAP.divider) * u };
849
+ }
850
+ function rowMarks(doc, p, u) {
851
+ const divider = dividerOf(doc, p, u);
852
+ const size = doc.rows?.icons?.size;
853
+ return (icons2, i, last) => {
854
+ const kind = icons2 === void 0 || icons2.length === 0 ? void 0 : icons2[Math.min(i, icons2.length - 1)];
855
+ const icon = kind === void 0 ? {} : { icon: { color: p.icon ?? p.accent, glyph: p.background, kind, size: size === void 0 ? void 0 : size * u } };
856
+ return { ...icon, ...divider === void 0 || last ? {} : { rule: divider, ruleBelow: true, ruleAbove: false } };
857
+ };
858
+ }
538
859
  function halves(text2) {
539
860
  const mid = text2.length / 2;
540
861
  const spaces = [...text2].flatMap((c, i) => c === " " ? [i] : []);
@@ -552,80 +873,149 @@ function eventGroups(doc, l, u, options) {
552
873
  const b = doc.blocks;
553
874
  const groups = [];
554
875
  const schedule2 = b.schedule ?? [];
876
+ const prices = (options.withPrices === false ? void 0 : b.prices) ?? [];
877
+ const lastRow = schedule2.length + prices.length - 1;
878
+ const icons2 = doc.rows?.icons;
555
879
  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)];
557
- groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1 });
880
+ 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`)];
881
+ groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1, ...options.marks(icons2?.schedule, i, i === lastRow) });
558
882
  });
559
- const prices = (options.withPrices === false ? void 0 : b.prices) ?? [];
560
883
  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)];
562
- groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1 });
884
+ 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`)];
885
+ groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1, ...options.marks(icons2?.prices, i, schedule2.length + i === lastRow) });
563
886
  });
564
887
  return groups;
565
888
  }
566
889
  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)) ?? [];
890
+ const groups = (doc.items ?? []).map((item, n) => itemGroup(item, n, l, { u, dateScale }));
891
+ const prices = doc.blocks.prices?.map((row, i) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice, `prices.${i}.amount`)) ?? [];
569
892
  if (prices.length > 0) {
570
893
  groups.push({ lines: prices, gapAfter: GAP.row * u });
571
894
  }
572
895
  return groups;
573
896
  }
574
897
  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 }));
898
+ const l = makers(p, u, styleContext(doc));
899
+ 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
900
  }
578
901
  function bodyGroups(doc, p, u, options = {}) {
579
- const l = makers(p, u);
902
+ const l = makers(p, u, styleContext(doc));
580
903
  const b = doc.blocks;
581
904
  const groups = [];
582
905
  const isList = doc.layout === "list" /* List */;
583
906
  if (b.venue) {
584
907
  const size = isList ? SIZE.listVenue : SIZE.venue;
585
908
  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 });
909
+ groups.push({ lines: b.venue.map((v, i) => l.venue(v, size, `venue.${i}`)), gapAfter: GAP.venue * u, rule: dividerOf(doc, p, u) ?? { color: p.accent, height: GAP.rule * u }, ruleBelow: true, icon: { color: p.icon ?? p.accent, glyph: p.background }, keepWithNext });
587
910
  }
588
- groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, options));
911
+ groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, { ...options, marks: rowMarks(doc, p, u) }));
589
912
  if (b.includes) {
590
- const lines = [l.accent(b.includes.heading, SIZE.small), ...b.includes.items.map((i) => l.item(i, SIZE.small))].flatMap((line) => wrapped(line, options.wrap));
913
+ 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
914
  groups.push({ lines, gapAfter: GAP.includes * u, uniform: true, keepWithNext: b.footer !== void 0, attachNext: b.footer !== void 0 });
592
915
  }
593
916
  if (b.footer) {
594
- groups.push({ lines: wrapped(l.soft(b.footer, SIZE.small), options.wrap), gapAfter: 0 });
917
+ groups.push({ lines: wrapped(l.soft(b.footer, SIZE.small, "footer"), options.wrap), gapAfter: 0 });
595
918
  }
596
919
  return groups;
597
920
  }
598
921
 
599
- // src/layout/textFlow.ts
922
+ // src/layout/lineSizes.ts
600
923
  var LINE_HEIGHT = 1.2;
601
924
  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
925
  var ICON_SCALE = 1.6;
612
926
  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
927
  var indented = (line) => line.bullet !== void 0 || line.hang === true;
928
+ var bulletIndent = (line, k) => indented(line) ? line.size * k * BULLET_INDENT : 0;
616
929
  var iconSize = (group, k) => {
617
930
  const first = group.lines[0];
931
+ if (group.icon?.size !== void 0) {
932
+ return group.icon.size * k;
933
+ }
618
934
  return group.icon && first ? first.size * k * LINE_HEIGHT * ICON_SCALE : 0;
619
935
  };
936
+ function groupBox(group, k, colW) {
937
+ const pad = group.card ? group.card.pad * k : 0;
938
+ const d = iconSize(group, k);
939
+ const iconIndent = d > 0 ? d * (1 + ICON_GAP) : 0;
940
+ return { pad, d, iconIndent, avail: colW - 2 * pad - iconIndent };
941
+ }
620
942
  function lineSize(line, width, k, avail) {
621
- const indent = indented(line) ? line.size * k * BULLET_INDENT : 0;
943
+ const indent = bulletIndent(line, k);
622
944
  return Math.max(0, Math.min(line.size * k, line.size * (avail - indent) / Math.max(width, 1)));
623
945
  }
624
- function groupRatio(m, k, avail) {
946
+ function groupSizes(m, k, avail) {
947
+ const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail));
625
948
  if (!m.group.uniform) {
626
- return null;
949
+ return own;
950
+ }
951
+ const ratio = Math.min(...m.group.lines.map((line, i) => (own[i] ?? 0) / line.size));
952
+ return m.group.lines.map((line) => line.size * ratio);
953
+ }
954
+ function tieMembers(all, k, colW, table, pick) {
955
+ const byId = /* @__PURE__ */ new Map();
956
+ all.forEach((m) => {
957
+ const { avail } = groupBox(m.group, k, colW);
958
+ const sizes = table.get(m) ?? [];
959
+ m.group.lines.forEach((line, i) => {
960
+ const id = pick(line);
961
+ if (id !== void 0) {
962
+ const member = { line, width: Math.max(m.widths[i] ?? 1, 1), cap: Math.max(0, avail - bulletIndent(line, k)), sizes, i };
963
+ byId.set(id, [...byId.get(id) ?? [], member]);
964
+ }
965
+ });
966
+ });
967
+ return [...byId.values()].filter((list) => list.length > 1);
968
+ }
969
+ function sameSizes(list) {
970
+ const target = Math.min(Math.max(...list.map((x) => x.sizes[x.i] ?? 0)), ...list.map((x) => x.line.size * x.cap / x.width));
971
+ list.forEach((x) => {
972
+ x.sizes[x.i] = target;
973
+ });
974
+ }
975
+ function sameWidths(list) {
976
+ const drawn = list.map((x) => x.width * (x.sizes[x.i] ?? 0) / x.line.size);
977
+ const target = Math.min(Math.max(...drawn), ...list.map((x) => x.cap));
978
+ list.forEach((x) => {
979
+ x.sizes[x.i] = target * x.line.size / x.width;
980
+ });
981
+ }
982
+ function sizeTable(all, k, colW) {
983
+ const table = new Map(all.map((m) => [m, groupSizes(m, k, groupBox(m.group, k, colW).avail)]));
984
+ tieMembers(all, k, colW, table, (line) => line.sizeTie).forEach(sameSizes);
985
+ tieMembers(all, k, colW, table, (line) => line.widthTie).forEach(sameWidths);
986
+ return table;
987
+ }
988
+
989
+ // src/layout/textFlow.ts
990
+ var BULLET_RADIUS = 0.2;
991
+ var RULE_GAP = 2.5;
992
+ var RULE_WIDTH = 0.9;
993
+ var WIDE = 1.6;
994
+ var COLUMN_GAP = 0.04;
995
+ var TWO_COLUMN_MIN = 0.75;
996
+ var TWO_COLUMN_GAIN = 1.15;
997
+ var MIN_K = 0.02;
998
+ var STEPS = 22;
999
+ var NO_SPACING = "0px";
1000
+ var fontOf = (line, size, fonts) => {
1001
+ const family = line.family === void 0 ? fonts[line.role] : `"${line.family}", ${fonts[line.role]}`;
1002
+ return `${line.italic === true ? "italic " : ""}${line.weight} ${size}px ${family}`;
1003
+ };
1004
+ var emptyFlow = () => ({ texts: [], cards: [], rules: [], bullets: [], icons: [] });
1005
+ function lineX(line, box) {
1006
+ const { col, pad, indent, w } = box;
1007
+ const left = col.x + pad + indent;
1008
+ const right = col.x + col.w - pad - w;
1009
+ switch (line.align) {
1010
+ case "left" /* Left */:
1011
+ return left;
1012
+ case "right" /* Right */:
1013
+ return right;
1014
+ case "center" /* Center */:
1015
+ return left + (right - left) / 2;
1016
+ default:
1017
+ return col.right ? right : left;
627
1018
  }
628
- return Math.min(...m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail) / line.size));
629
1019
  }
630
1020
  function placeIcon(group, box, out) {
631
1021
  const { d, x, top, bottom: bottom2 } = box;
@@ -633,39 +1023,35 @@ function placeIcon(group, box, out) {
633
1023
  return bottom2;
634
1024
  }
635
1025
  const textH = bottom2 - top;
636
- out?.icons.push({ rect: { x, y: top + Math.max(0, (textH - d) / 2), w: d, h: d }, color: group.icon.color, glyph: group.icon.glyph });
1026
+ out?.icons.push({ rect: { x, y: top + Math.max(0, (textH - d) / 2), w: d, h: d }, color: group.icon.color, glyph: group.icon.glyph, kind: group.icon.kind });
637
1027
  return top + Math.max(textH, d);
638
1028
  }
639
1029
  function placeGroup(m, at, out) {
640
- const { k, col, y0 } = at;
1030
+ const { k, col, y0, sizes } = at;
641
1031
  const { group } = m;
642
1032
  let y = y0;
643
- if (group.rule) {
1033
+ if (group.rule && group.ruleAbove !== false) {
644
1034
  out?.rules.push({ rect: { x: col.x, y, w: col.w * RULE_WIDTH, h: group.rule.height * k }, color: group.rule.color });
645
- y += group.rule.height * k * RULE_GAP;
1035
+ y += group.rule.gap === void 0 ? group.rule.height * k * RULE_GAP : (group.rule.height + group.rule.gap) * k;
646
1036
  }
647
- const pad = group.card ? group.card.pad * k : 0;
1037
+ const { pad, d, iconIndent } = groupBox(group, k, col.w);
648
1038
  const top = y;
649
1039
  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
1040
  group.lines.forEach((line, i) => {
655
- const size = ratio === null ? lineSize(line, m.widths[i] ?? 1, k, avail) : line.size * ratio;
1041
+ const size = sizes[i] ?? 0;
656
1042
  const indent = (indented(line) ? line.size * k * BULLET_INDENT : 0) + iconIndent;
657
1043
  const w = (m.widths[i] ?? 0) * size / line.size;
658
- const x = col.right ? col.x + col.w - pad - w : col.x + pad + indent;
1044
+ const x = lineX(line, { col, pad, indent, w });
659
1045
  out?.texts.push({ text: line.text, font: "", color: line.color, box: { x, y, w, h: size * LINE_HEIGHT } });
660
1046
  if (line.bullet && out) {
661
1047
  out.bullets.push({ x: col.x + pad + size * BULLET_RADIUS, y: y + size * LINE_HEIGHT / 2, r: size * BULLET_RADIUS, color: line.bullet });
662
1048
  }
663
- y += size * LINE_HEIGHT;
1049
+ y += size * LINE_HEIGHT + (line.gapAfter ?? 0) * k;
664
1050
  });
665
1051
  y = placeIcon(group, { d, x: col.x + pad, top: top + pad, bottom: y }, out);
666
1052
  y += pad;
667
1053
  if (group.rule && group.ruleBelow) {
668
- y += group.rule.height * k * (RULE_GAP - 1);
1054
+ y += group.rule.gap === void 0 ? group.rule.height * k * (RULE_GAP - 1) : group.rule.gap * k;
669
1055
  out?.rules.push({ rect: { x: col.x, y, w: col.w * RULE_WIDTH, h: group.rule.height * k }, color: group.rule.color });
670
1056
  y += group.rule.height * k;
671
1057
  }
@@ -675,10 +1061,10 @@ function placeGroup(m, at, out) {
675
1061
  return y + group.gapAfter * k - y0;
676
1062
  }
677
1063
  function placeColumn(groups, at, out) {
678
- const { k, col, spread = 0 } = at;
1064
+ const { k, col, table, spread = 0 } = at;
679
1065
  let h = 0;
680
1066
  groups.forEach((g, i) => {
681
- h += placeGroup(g, { k, col, y0: col.y + h }, out);
1067
+ h += placeGroup(g, { k, col, y0: col.y + h, sizes: table.get(g) ?? [] }, out);
682
1068
  if (i < groups.length - 1 && g.group.attachNext !== true) {
683
1069
  h += spread;
684
1070
  }
@@ -711,7 +1097,8 @@ function keepTogether(groups, heights, cut) {
711
1097
  function splitColumns(groups, zone) {
712
1098
  const gap = Math.round(zone.w * COLUMN_GAP);
713
1099
  const w = (zone.w - gap) / 2;
714
- const heights = groups.map((g) => placeGroup(g, { k: 1, col: { ...zone, w }, y0: 0 }, null));
1100
+ const table = sizeTable(groups, 1, w);
1101
+ const heights = groups.map((g) => placeGroup(g, { k: 1, col: { ...zone, w }, y0: 0, sizes: table.get(g) ?? [] }, null));
715
1102
  const total = columnSum(heights, 0, heights.length);
716
1103
  let cut = 1;
717
1104
  for (let c = 2; c < groups.length; c++) {
@@ -725,8 +1112,12 @@ function splitColumns(groups, zone) {
725
1112
  { col: { ...zone, x: zone.x + w + gap, w }, groups: groups.slice(cut) }
726
1113
  ];
727
1114
  }
1115
+ var tableFor = (columns, k) => sizeTable(columns.flatMap((c) => c.groups), k, columns[0]?.col.w ?? 0);
728
1116
  function largestK(columns, zoneH) {
729
- const fits = (k) => columns.every((c) => placeColumn(c.groups, { k, col: c.col }, null) <= zoneH);
1117
+ const fits = (k) => {
1118
+ const table = tableFor(columns, k);
1119
+ return columns.every((c) => placeColumn(c.groups, { k, col: c.col, table }, null) <= zoneH);
1120
+ };
730
1121
  let lo = MIN_K;
731
1122
  let hi = 1;
732
1123
  if (fits(1)) {
@@ -753,26 +1144,37 @@ function bestColumns(measured, zone) {
753
1144
  const forced = zone.w / Math.max(zone.h, 1) > WIDE;
754
1145
  return forced || k2 > k1 * TWO_COLUMN_GAIN ? { columns: split, k: k2 } : { columns: single, k: k1 };
755
1146
  }
1147
+ function measure(ctx, line, fonts) {
1148
+ ctx.font = fontOf(line, line.size, fonts);
1149
+ if (line.spacing === void 0) {
1150
+ return ctx.measureText(line.text).width;
1151
+ }
1152
+ ctx.letterSpacing = `${line.spacing * line.size}px`;
1153
+ const width = ctx.measureText(line.text).width;
1154
+ ctx.letterSpacing = NO_SPACING;
1155
+ return width;
1156
+ }
756
1157
  function flow(ctx, groups, zone, fonts) {
757
1158
  const measured = groups.map((group) => ({
758
1159
  group,
759
- widths: group.lines.map((line) => {
760
- ctx.font = fontOf(line, line.size, fonts);
761
- return ctx.measureText(line.text).width;
762
- })
1160
+ widths: group.lines.map((line) => measure(ctx, line, fonts))
763
1161
  }));
764
1162
  const { columns, k: lo } = bestColumns(measured, zone);
765
1163
  const out = emptyFlow();
766
- const heights = columns.map((c) => placeColumn(c.groups, { k: lo, col: c.col }, null));
1164
+ const table = tableFor(columns, lo);
1165
+ const heights = columns.map((c) => placeColumn(c.groups, { k: lo, col: c.col, table }, null));
767
1166
  const end = Math.max(...heights);
768
1167
  columns.forEach((c, i) => {
769
1168
  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);
1169
+ placeColumn(c.groups, { k: lo, col: c.col, table, spread: gaps > 0 && columns.length > 1 ? (end - (heights[i] ?? end)) / gaps : 0 }, out);
771
1170
  });
772
1171
  const lines = groups.flatMap((g) => g.lines);
773
1172
  out.texts.forEach((t, i) => {
774
1173
  const line = lines[i];
775
1174
  t.font = line ? fontOf(line, t.box.h / LINE_HEIGHT, fonts) : t.font;
1175
+ if (line?.spacing !== void 0) {
1176
+ t.spacing = `${line.spacing * (t.box.h / LINE_HEIGHT)}px`;
1177
+ }
776
1178
  });
777
1179
  return out;
778
1180
  }
@@ -827,6 +1229,13 @@ function splitHeader(header, hasLogo) {
827
1229
  const logoW = hasLogo ? Math.round(header.w * LOGO_SHARE) : 0;
828
1230
  return { text: { ...header, w: header.w - logoW * 1.1 }, logo: { ...header, x: header.x + header.w - logoW, w: logoW } };
829
1231
  }
1232
+ function headerAt(zones, top, u) {
1233
+ if (top === void 0) {
1234
+ return zones;
1235
+ }
1236
+ const y = Math.round(top * u);
1237
+ return { ...zones, text: { ...zones.text, y, h: Math.max(1, zones.text.y + zones.text.h - y) } };
1238
+ }
830
1239
  function closeHeaderGap(geo, head, gap, u) {
831
1240
  const { header, body } = geo;
832
1241
  const stacked = header.y + header.h <= body.y && header.x < body.x + body.w && body.x < header.x + header.w;
@@ -839,7 +1248,7 @@ function closeHeaderGap(geo, head, gap, u) {
839
1248
  function flowAll(ctx, input, geo, reflow) {
840
1249
  const { doc, palette, fonts } = input;
841
1250
  const u = Math.min(input.width, input.height) / BASE;
842
- const zones = geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0);
1251
+ const zones = headerAt(geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0), doc.tuning?.headerTop, u);
843
1252
  const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
844
1253
  const flanks = geo.flanks ?? [];
845
1254
  const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
@@ -913,8 +1322,90 @@ function fitToFloor(ctx, input) {
913
1322
  return best ?? flowAll(ctx, input, base2, { compact: false, wrap: false});
914
1323
  }
915
1324
 
1325
+ // src/render/overlap.ts
1326
+ var clamp = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
1327
+ function placePicture(image, region, slot, fit) {
1328
+ const base2 = placeContain(image, region, { anchor: slot.anchor, alignX: fit.alignX, scale: slot.scale });
1329
+ const o = slot.overlap;
1330
+ if (o === void 0) {
1331
+ return base2;
1332
+ }
1333
+ const { width, height } = fit.frame;
1334
+ const s = Math.min(o.scale, width / Math.max(base2.w, 1), height / Math.max(base2.h, 1));
1335
+ const w = Math.floor(base2.w * s);
1336
+ const h = Math.floor(base2.h * s);
1337
+ const x = base2.x + (base2.w - w) * fit.alignX + o.dx * width;
1338
+ const y = base2.y + (base2.h - h) * ANCHOR_Y[slot.anchor] + o.dy * height;
1339
+ return { x: Math.round(clamp(x, 0, width - w)), y: Math.round(clamp(y, 0, height - h)), w, h };
1340
+ }
1341
+ function reachPicture(rules, picture, reach) {
1342
+ const end = picture.x + picture.w * reach;
1343
+ rules.filter((r3) => r3.rect.y >= picture.y && r3.rect.y <= picture.y + picture.h).forEach((r3) => {
1344
+ r3.rect.w = Math.max(0, end - r3.rect.x);
1345
+ });
1346
+ }
1347
+
1348
+ // src/render/rowIcons.ts
1349
+ var LINE2 = 0.03;
1350
+ var HEAD_Y = -0.15;
1351
+ var HEAD_R = 0.1;
1352
+ var BODY_Y = 0.25;
1353
+ var BODY_R = 0.2;
1354
+ var BACK_DX = 0.12;
1355
+ var BACK_DY = -0.04;
1356
+ var FRONT_DX = -0.08;
1357
+ var PAIR_SCALE = 0.85;
1358
+ var TICKET_W = 0.52;
1359
+ var TICKET_H = 0.3;
1360
+ var TICKET_TURN = -Math.PI / 4;
1361
+ var PERFORATION = 0.14;
1362
+ var DOTS = [-0.3, 0, 0.3];
1363
+ var DOT = 0.035;
1364
+ function halfDisc(ctx, c, r3, color) {
1365
+ ctx.fillStyle = color;
1366
+ ctx.beginPath();
1367
+ ctx.arc(c[0], c[1], Math.max(0, r3), Math.PI, Math.PI * 2);
1368
+ ctx.closePath();
1369
+ ctx.fill();
1370
+ }
1371
+ function person(ctx, c, d, colors) {
1372
+ const w = d * LINE2;
1373
+ const head = [c[0], c[1] + d * HEAD_Y];
1374
+ disc(ctx, head, d * HEAD_R, colors.glyph);
1375
+ disc(ctx, head, d * HEAD_R - w, colors.fill);
1376
+ halfDisc(ctx, [c[0], c[1] + d * BODY_Y], d * BODY_R, colors.glyph);
1377
+ halfDisc(ctx, [c[0], c[1] + d * BODY_Y - w], d * BODY_R - 2 * w, colors.fill);
1378
+ }
1379
+ function people(ctx, c, d, colors) {
1380
+ const s = d * PAIR_SCALE;
1381
+ person(ctx, [c[0] + d * BACK_DX, c[1] + d * BACK_DY], s, colors);
1382
+ person(ctx, [c[0] + d * FRONT_DX, c[1]], s, colors);
1383
+ }
1384
+ function ticket(ctx, c, d, colors) {
1385
+ const w = d * LINE2;
1386
+ ctx.fillStyle = colors.glyph;
1387
+ polygon(ctx, turnedRect(c, { w: d * TICKET_W, h: d * TICKET_H }, TICKET_TURN));
1388
+ ctx.fillStyle = colors.fill;
1389
+ polygon(ctx, turnedRect(c, { w: d * TICKET_W - 2 * w, h: d * TICKET_H - 2 * w }, TICKET_TURN));
1390
+ const along = [Math.cos(TICKET_TURN), Math.sin(TICKET_TURN)];
1391
+ const across = [-along[1], along[0]];
1392
+ const x = d * PERFORATION;
1393
+ DOTS.forEach((t) => disc(ctx, [c[0] + along[0] * x + across[0] * t * d * TICKET_H, c[1] + along[1] * x + across[1] * t * d * TICKET_H], d * DOT, colors.glyph));
1394
+ }
1395
+ var GLYPHS = {
1396
+ ["person" /* Person */]: person,
1397
+ ["people" /* People */]: people,
1398
+ ["ticket" /* Ticket */]: ticket
1399
+ };
1400
+ function drawRowIcon(ctx, r3, kind, colors) {
1401
+ const c = [r3.x + r3.w / 2, r3.y + r3.h / 2];
1402
+ disc(ctx, c, r3.w / 2, colors.fill);
1403
+ GLYPHS[kind](ctx, c, r3.w, colors);
1404
+ }
1405
+
916
1406
  // src/render/render.ts
917
1407
  var BASE2 = 1080;
1408
+ var NO_SPACING2 = "0px";
918
1409
  var CARD_RADIUS = 0.035;
919
1410
  var CAP_TOP = 0.15;
920
1411
  var PIN_HEAD_Y = 0.08;
@@ -954,11 +1445,13 @@ function roundRect(ctx, r3, radius) {
954
1445
  ctx.closePath();
955
1446
  ctx.fill();
956
1447
  }
957
- function drawFlow(ctx, f, radius) {
1448
+ function drawRules(ctx, f) {
958
1449
  f.rules.forEach((r3) => {
959
1450
  ctx.fillStyle = r3.color;
960
1451
  ctx.fillRect(r3.rect.x, r3.rect.y, r3.rect.w, r3.rect.h);
961
1452
  });
1453
+ }
1454
+ function drawMarks(ctx, f, radius) {
962
1455
  f.cards.forEach((c) => {
963
1456
  ctx.fillStyle = c.color;
964
1457
  roundRect(ctx, c.rect, radius);
@@ -969,15 +1462,25 @@ function drawFlow(ctx, f, radius) {
969
1462
  ctx.arc(b.x, b.y, b.r, 0, Math.PI * 2);
970
1463
  ctx.fill();
971
1464
  });
972
- f.icons.forEach((i) => drawPin(ctx, i.rect, i.color, i.glyph));
1465
+ f.icons.forEach((i) => i.kind === void 0 ? drawPin(ctx, i.rect, i.color, i.glyph) : drawRowIcon(ctx, i.rect, i.kind, { fill: i.color, glyph: i.glyph }));
973
1466
  ctx.textAlign = "left";
974
1467
  ctx.textBaseline = "top";
975
1468
  f.texts.forEach((t) => {
976
1469
  ctx.font = t.font;
977
1470
  ctx.fillStyle = t.color;
1471
+ if (t.spacing !== void 0) {
1472
+ ctx.letterSpacing = t.spacing;
1473
+ }
978
1474
  ctx.fillText(t.text, t.box.x, t.box.y);
1475
+ if (t.spacing !== void 0) {
1476
+ ctx.letterSpacing = NO_SPACING2;
1477
+ }
979
1478
  });
980
1479
  }
1480
+ function drawFlow(ctx, f, radius) {
1481
+ drawRules(ctx, f);
1482
+ drawMarks(ctx, f, radius);
1483
+ }
981
1484
  function checked(input, assets) {
982
1485
  const result = validateFlierDoc(input);
983
1486
  if (!result.ok) {
@@ -1009,6 +1512,25 @@ function capAligned(zone, head) {
1009
1512
  const shift = first ? Math.min(Math.max(0, Math.round(first.y + first.h * CAP_TOP) - zone.y), Math.round(zone.h / 2)) : 0;
1010
1513
  return { ...zone, y: zone.y + shift, h: zone.h - shift };
1011
1514
  }
1515
+ function placeOnPage(doc, assets, fitted, frame) {
1516
+ const image = doc.picture ? assets[doc.picture.imageId] : void 0;
1517
+ const region = pictureRegion(doc.layout, fitted.geo, fitted.body, frame);
1518
+ const picture = image && doc.picture ? placePicture(image, region, doc.picture, { alignX: fitted.geo.alignX, frame }) : null;
1519
+ const dividers = doc.rows?.dividers;
1520
+ if (picture && dividers?.toPicture === true) {
1521
+ reachPicture(fitted.body.rules, picture, dividers.reach ?? 0);
1522
+ }
1523
+ return { image, region, picture };
1524
+ }
1525
+ function drawLogo(ctx, doc, assets, fitted) {
1526
+ const logoImage = doc.logo ? assets[doc.logo.imageId] : void 0;
1527
+ const zone = fitted.geo.logo ? fitted.zones.logo : capAligned(fitted.zones.logo, fitted.head);
1528
+ const logo = logoImage ? placeContain(logoImage, zone, { anchor: "top" /* Top */, alignX: 1, scale: 1 }) : null;
1529
+ if (logoImage && logo) {
1530
+ ctx.drawImage(logoImage, logo.x, logo.y, logo.w, logo.h);
1531
+ }
1532
+ return logo;
1533
+ }
1012
1534
  function render(input, assets, canvas) {
1013
1535
  const doc = checked(input, assets);
1014
1536
  const { width, height } = FORMAT_SIZES[doc.format];
@@ -1019,40 +1541,34 @@ function render(input, assets, canvas) {
1019
1541
  throw new Error("poster-render: the canvas has no 2d context");
1020
1542
  }
1021
1543
  const palette = PALETTES[doc.palette];
1022
- const fonts = FONT_SETS[doc.fonts];
1023
- const u = Math.min(width, height) / BASE2;
1024
- const { geo, zones, head, body, sides } = fitToFloor(ctx, { doc, palette, fonts, width, height });
1025
- ctx.globalAlpha = 1;
1026
- paintGround(ctx, doc.background, palette, { width, height });
1027
- if (doc.background === "tint" /* Tint */) {
1028
- ctx.fillStyle = palette.tint;
1029
- [geo.header, geo.body].forEach((r3) => ctx.fillRect(r3.x, r3.y, r3.w, r3.h));
1030
- }
1544
+ const fitted = fitToFloor(ctx, { doc, palette, fonts: FONT_SETS[doc.fonts], width, height });
1545
+ const { geo, head, body, sides } = fitted;
1546
+ const { image, region, picture } = placeOnPage(doc, assets, fitted, { width, height, u: Math.min(width, height) / BASE2 });
1547
+ paintPage(ctx, doc, palette, { geo, width, height, picture });
1031
1548
  const radius = Math.min(width, height) * CARD_RADIUS;
1032
- [head, body, ...sides].forEach((f) => drawFlow(ctx, f, radius));
1033
- const logoImage = doc.logo ? assets[doc.logo.imageId] : void 0;
1034
- const logo = logoImage ? placeContain(logoImage, geo.logo ? zones.logo : capAligned(zones.logo, head), { anchor: "top" /* Top */, alignX: 1, scale: 1 }) : null;
1035
- if (logoImage && logo) {
1036
- ctx.drawImage(logoImage, logo.x, logo.y, logo.w, logo.h);
1037
- }
1038
- const image = doc.picture ? assets[doc.picture.imageId] : void 0;
1549
+ const flows = [head, body, ...sides];
1550
+ const layered = doc.picture?.overlap !== void 0;
1551
+ flows.forEach((f) => layered ? drawRules(ctx, f) : drawFlow(ctx, f, radius));
1552
+ const logo = drawLogo(ctx, doc, assets, fitted);
1039
1553
  const backdrop = image ? archRect(geo) : null;
1040
1554
  if (backdrop) {
1041
1555
  drawArch(ctx, backdrop, palette.arch);
1042
1556
  }
1043
- const region = pictureRegion(doc.layout, geo, body, { height, u });
1044
- const picture = image && doc.picture ? placeContain(image, region, { anchor: doc.picture.anchor, alignX: geo.alignX, scale: doc.picture.scale }) : null;
1045
1557
  if (image && picture) {
1046
1558
  ctx.drawImage(image, picture.x, picture.y, picture.w, picture.h);
1047
1559
  }
1560
+ if (layered) {
1561
+ flows.forEach((f) => drawMarks(ctx, f, radius));
1562
+ }
1048
1563
  return {
1049
1564
  width,
1050
1565
  height,
1051
1566
  picture,
1052
1567
  pictureRegion: region,
1053
- textBoxes: [head, body, ...sides].flatMap((f) => f.texts.map((t) => t.box)),
1568
+ textBoxes: flows.flatMap((f) => f.texts.map((t) => t.box)),
1054
1569
  cardBoxes: body.cards.map((c) => c.rect),
1055
- iconBoxes: [head, body, ...sides].flatMap((f) => f.icons.map((i) => i.rect)),
1570
+ iconBoxes: flows.flatMap((f) => f.icons.map((i) => i.rect)),
1571
+ ruleBoxes: flows.flatMap((f) => f.rules.map((r3) => r3.rect)),
1056
1572
  logo,
1057
1573
  backdrop
1058
1574
  };
@@ -1148,6 +1664,6 @@ var kizombaWorkshop = {
1148
1664
  };
1149
1665
  var kizombaWorkshopDocs = [...WORKSHOPS.map(workshopDoc), kizombaWorkshop];
1150
1666
 
1151
- export { BackgroundStyle, FONT_SETS, FORMAT_SIZES, FlierDocError, FontSetId, FormatId, LAYOUT_CATALOGUE, LayoutId, PALETTES, PaletteId, PictureAnchor, defaultLayoutFor, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, validateFlierDoc };
1667
+ export { BackgroundStyle, FONT_SETS, FORMAT_SIZES, FlierDocError, FontSetId, FormatId, LAYOUT_CATALOGUE, LINE_KEY_PATTERN, LayoutId, LineAlign, LineTieKind, PALETTES, PaletteId, PictureAnchor, RowIcon, defaultLayoutFor, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, sameSize, sameWidth, validateFlierDoc };
1152
1668
  //# sourceMappingURL=index.mjs.map
1153
1669
  //# sourceMappingURL=index.mjs.map