@dloizides/poster-render 0.5.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
 
@@ -72,6 +75,14 @@ var LineTieKind = /* @__PURE__ */ ((LineTieKind2) => {
72
75
  return LineTieKind2;
73
76
  })(LineTieKind || {});
74
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
+
75
86
  // src/schema/lineStyleSchema.ts
76
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]))$";
77
88
  var MAX_FONT = 40;
@@ -147,6 +158,20 @@ var PALETTES = {
147
158
  arch: "#c7d4d6",
148
159
  sky: [[0, "#bfd3d8"], [0.55, "#d4dddd"], [1, "#eadccb"]]
149
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
+ },
150
175
  ["rose" /* Rose */]: { background: "#f8efec", tint: "#f1e2dd", title: "#9b6b63", accent: "#c9846f", ink: "#4a3934", soft: "#b39a92", card: "#ffffff", arch: "#f1e5e1" }
151
176
  };
152
177
 
@@ -155,15 +180,65 @@ var FONT_SETS = {
155
180
  ["classic" /* Classic */]: { display: '"Oswald", "Arial Narrow", sans-serif', script: '"Sacramento", cursive', body: '"Fredoka", sans-serif' },
156
181
  ["modern" /* Modern */]: { display: '"Bebas Neue", "Arial Narrow", sans-serif', script: '"Great Vibes", cursive', body: '"Montserrat", sans-serif' },
157
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' },
158
184
  ["coastal" /* Coastal */]: { display: '"Fraunces", Georgia, serif', script: '"Allura", cursive', body: '"Jost", sans-serif' }
159
185
  };
160
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
+
161
236
  // src/schema/flierDocSchema.ts
162
237
  var SHORT = 60;
163
238
  var LINE = 120;
164
- var MAX_ROWS = 6;
239
+ var MAX_ROWS2 = 6;
165
240
  var MAX_ITEMS = 8;
166
- var MAX_PRICES = 4;
241
+ var MAX_PRICES2 = 4;
167
242
  var MAX_VENUE = 3;
168
243
  var MIN_SCALE = 0.3;
169
244
  var MAX_HEADER_GAP = 200;
@@ -176,7 +251,7 @@ var scheduleRow = {
176
251
  additionalProperties: false,
177
252
  properties: { label: text(SHORT), time: text(SHORT) }
178
253
  };
179
- var scheduleList = { type: "array", items: scheduleRow, minItems: 1, maxItems: MAX_ROWS };
254
+ var scheduleList = { type: "array", items: scheduleRow, minItems: 1, maxItems: MAX_ROWS2 };
180
255
  var blocks = {
181
256
  type: "object",
182
257
  required: ["title"],
@@ -190,7 +265,7 @@ var blocks = {
190
265
  prices: {
191
266
  type: "array",
192
267
  minItems: 1,
193
- maxItems: MAX_PRICES,
268
+ maxItems: MAX_PRICES2,
194
269
  items: {
195
270
  type: "object",
196
271
  required: ["amount", "label"],
@@ -202,7 +277,7 @@ var blocks = {
202
277
  type: "object",
203
278
  required: ["heading", "items"],
204
279
  additionalProperties: false,
205
- 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 } }
206
281
  },
207
282
  footer: text(LINE)
208
283
  }
@@ -229,7 +304,8 @@ var flierDocSchema = {
229
304
  properties: {
230
305
  imageId: text(SHORT),
231
306
  anchor: { type: "string", enum: Object.values(PictureAnchor) },
232
- scale: { type: "number", minimum: MIN_SCALE, maximum: 1 }
307
+ scale: { type: "number", minimum: MIN_SCALE, maximum: 1 },
308
+ overlap: overlapSchema
233
309
  }
234
310
  },
235
311
  logo: { type: "object", required: ["imageId"], additionalProperties: false, properties: { imageId: text(SHORT) } },
@@ -239,11 +315,13 @@ var flierDocSchema = {
239
315
  additionalProperties: false,
240
316
  properties: {
241
317
  headerGap: { type: "number", minimum: 0, maximum: MAX_HEADER_GAP },
242
- 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
243
320
  }
244
321
  },
245
322
  lineStyles: lineStylesSchema,
246
323
  lineTies: lineTiesSchema,
324
+ rows: rowsSchema,
247
325
  items: {
248
326
  type: "array",
249
327
  minItems: 1,
@@ -403,6 +481,92 @@ function missingAssets(doc, assets) {
403
481
  return errors;
404
482
  }
405
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
+
406
570
  // src/render/background.ts
407
571
  function paintGround(ctx, style, palette, size) {
408
572
  ctx.fillStyle = palette.background;
@@ -414,6 +578,17 @@ function paintGround(ctx, style, palette, size) {
414
578
  }
415
579
  ctx.fillRect(0, 0, size.width, size.height);
416
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
+ }
417
592
 
418
593
  // src/layout/layoutSpecs.ts
419
594
  var flanksBeside = (pic, top, bottom2, m) => [
@@ -636,12 +811,13 @@ var GAP = {
636
811
  row: 30,
637
812
  venue: 40,
638
813
  includes: 24,
639
- rule: 8
814
+ rule: 8,
815
+ divider: 24
640
816
  };
641
817
  var makers = (p, u, sc) => ({
642
818
  display: (text2, size, key) => styled({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }, key, sc),
643
819
  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),
820
+ script: (text2, size, key) => styled({ text: text2, role: "script", weight: SCRIPT, size: size * u, color: p.script ?? p.accent }, key, sc),
645
821
  strong: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
646
822
  accent: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }, key, sc),
647
823
  item: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }, key, sc),
@@ -650,7 +826,11 @@ var makers = (p, u, sc) => ({
650
826
  function headerGroups(doc, p, u) {
651
827
  const l = makers(p, u, styleContext(doc));
652
828
  const b = doc.blocks;
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];
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];
654
834
  return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
655
835
  }
656
836
  function itemGroup(item, n, l, scale) {
@@ -663,6 +843,19 @@ function itemGroup(item, n, l, scale) {
663
843
  return { lines, gapAfter: GAP.item * u };
664
844
  }
665
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
+ }
666
859
  function halves(text2) {
667
860
  const mid = text2.length / 2;
668
861
  const spaces = [...text2].flatMap((c, i) => c === " " ? [i] : []);
@@ -680,14 +873,16 @@ function eventGroups(doc, l, u, options) {
680
873
  const b = doc.blocks;
681
874
  const groups = [];
682
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;
683
879
  schedule2.forEach((row, i) => {
684
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`)];
685
- groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1 });
881
+ groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1, ...options.marks(icons2?.schedule, i, i === lastRow) });
686
882
  });
687
- const prices = (options.withPrices === false ? void 0 : b.prices) ?? [];
688
883
  prices.forEach((row, i) => {
689
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`)];
690
- groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1 });
885
+ groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1, ...options.marks(icons2?.prices, i, schedule2.length + i === lastRow) });
691
886
  });
692
887
  return groups;
693
888
  }
@@ -711,9 +906,9 @@ function bodyGroups(doc, p, u, options = {}) {
711
906
  if (b.venue) {
712
907
  const size = isList ? SIZE.listVenue : SIZE.venue;
713
908
  const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
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 });
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 });
715
910
  }
716
- 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) }));
717
912
  if (b.includes) {
718
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));
719
914
  groups.push({ lines, gapAfter: GAP.includes * u, uniform: true, keepWithNext: b.footer !== void 0, attachNext: b.footer !== void 0 });
@@ -733,6 +928,9 @@ var indented = (line) => line.bullet !== void 0 || line.hang === true;
733
928
  var bulletIndent = (line, k) => indented(line) ? line.size * k * BULLET_INDENT : 0;
734
929
  var iconSize = (group, k) => {
735
930
  const first = group.lines[0];
931
+ if (group.icon?.size !== void 0) {
932
+ return group.icon.size * k;
933
+ }
736
934
  return group.icon && first ? first.size * k * LINE_HEIGHT * ICON_SCALE : 0;
737
935
  };
738
936
  function groupBox(group, k, colW) {
@@ -825,16 +1023,16 @@ function placeIcon(group, box, out) {
825
1023
  return bottom2;
826
1024
  }
827
1025
  const textH = bottom2 - top;
828
- 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 });
829
1027
  return top + Math.max(textH, d);
830
1028
  }
831
1029
  function placeGroup(m, at, out) {
832
1030
  const { k, col, y0, sizes } = at;
833
1031
  const { group } = m;
834
1032
  let y = y0;
835
- if (group.rule) {
1033
+ if (group.rule && group.ruleAbove !== false) {
836
1034
  out?.rules.push({ rect: { x: col.x, y, w: col.w * RULE_WIDTH, h: group.rule.height * k }, color: group.rule.color });
837
- 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;
838
1036
  }
839
1037
  const { pad, d, iconIndent } = groupBox(group, k, col.w);
840
1038
  const top = y;
@@ -848,12 +1046,12 @@ function placeGroup(m, at, out) {
848
1046
  if (line.bullet && out) {
849
1047
  out.bullets.push({ x: col.x + pad + size * BULLET_RADIUS, y: y + size * LINE_HEIGHT / 2, r: size * BULLET_RADIUS, color: line.bullet });
850
1048
  }
851
- y += size * LINE_HEIGHT;
1049
+ y += size * LINE_HEIGHT + (line.gapAfter ?? 0) * k;
852
1050
  });
853
1051
  y = placeIcon(group, { d, x: col.x + pad, top: top + pad, bottom: y }, out);
854
1052
  y += pad;
855
1053
  if (group.rule && group.ruleBelow) {
856
- 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;
857
1055
  out?.rules.push({ rect: { x: col.x, y, w: col.w * RULE_WIDTH, h: group.rule.height * k }, color: group.rule.color });
858
1056
  y += group.rule.height * k;
859
1057
  }
@@ -1031,6 +1229,13 @@ function splitHeader(header, hasLogo) {
1031
1229
  const logoW = hasLogo ? Math.round(header.w * LOGO_SHARE) : 0;
1032
1230
  return { text: { ...header, w: header.w - logoW * 1.1 }, logo: { ...header, x: header.x + header.w - logoW, w: logoW } };
1033
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
+ }
1034
1239
  function closeHeaderGap(geo, head, gap, u) {
1035
1240
  const { header, body } = geo;
1036
1241
  const stacked = header.y + header.h <= body.y && header.x < body.x + body.w && body.x < header.x + header.w;
@@ -1043,7 +1248,7 @@ function closeHeaderGap(geo, head, gap, u) {
1043
1248
  function flowAll(ctx, input, geo, reflow) {
1044
1249
  const { doc, palette, fonts } = input;
1045
1250
  const u = Math.min(input.width, input.height) / BASE;
1046
- 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);
1047
1252
  const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
1048
1253
  const flanks = geo.flanks ?? [];
1049
1254
  const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
@@ -1117,6 +1322,87 @@ function fitToFloor(ctx, input) {
1117
1322
  return best ?? flowAll(ctx, input, base2, { compact: false, wrap: false});
1118
1323
  }
1119
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
+
1120
1406
  // src/render/render.ts
1121
1407
  var BASE2 = 1080;
1122
1408
  var NO_SPACING2 = "0px";
@@ -1159,11 +1445,13 @@ function roundRect(ctx, r3, radius) {
1159
1445
  ctx.closePath();
1160
1446
  ctx.fill();
1161
1447
  }
1162
- function drawFlow(ctx, f, radius) {
1448
+ function drawRules(ctx, f) {
1163
1449
  f.rules.forEach((r3) => {
1164
1450
  ctx.fillStyle = r3.color;
1165
1451
  ctx.fillRect(r3.rect.x, r3.rect.y, r3.rect.w, r3.rect.h);
1166
1452
  });
1453
+ }
1454
+ function drawMarks(ctx, f, radius) {
1167
1455
  f.cards.forEach((c) => {
1168
1456
  ctx.fillStyle = c.color;
1169
1457
  roundRect(ctx, c.rect, radius);
@@ -1174,7 +1462,7 @@ function drawFlow(ctx, f, radius) {
1174
1462
  ctx.arc(b.x, b.y, b.r, 0, Math.PI * 2);
1175
1463
  ctx.fill();
1176
1464
  });
1177
- 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 }));
1178
1466
  ctx.textAlign = "left";
1179
1467
  ctx.textBaseline = "top";
1180
1468
  f.texts.forEach((t) => {
@@ -1189,6 +1477,10 @@ function drawFlow(ctx, f, radius) {
1189
1477
  }
1190
1478
  });
1191
1479
  }
1480
+ function drawFlow(ctx, f, radius) {
1481
+ drawRules(ctx, f);
1482
+ drawMarks(ctx, f, radius);
1483
+ }
1192
1484
  function checked(input, assets) {
1193
1485
  const result = validateFlierDoc(input);
1194
1486
  if (!result.ok) {
@@ -1220,6 +1512,25 @@ function capAligned(zone, head) {
1220
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;
1221
1513
  return { ...zone, y: zone.y + shift, h: zone.h - shift };
1222
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
+ }
1223
1534
  function render(input, assets, canvas) {
1224
1535
  const doc = checked(input, assets);
1225
1536
  const { width, height } = FORMAT_SIZES[doc.format];
@@ -1230,40 +1541,34 @@ function render(input, assets, canvas) {
1230
1541
  throw new Error("poster-render: the canvas has no 2d context");
1231
1542
  }
1232
1543
  const palette = PALETTES[doc.palette];
1233
- const fonts = FONT_SETS[doc.fonts];
1234
- const u = Math.min(width, height) / BASE2;
1235
- const { geo, zones, head, body, sides } = fitToFloor(ctx, { doc, palette, fonts, width, height });
1236
- ctx.globalAlpha = 1;
1237
- paintGround(ctx, doc.background, palette, { width, height });
1238
- if (doc.background === "tint" /* Tint */) {
1239
- ctx.fillStyle = palette.tint;
1240
- [geo.header, geo.body].forEach((r3) => ctx.fillRect(r3.x, r3.y, r3.w, r3.h));
1241
- }
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 });
1242
1548
  const radius = Math.min(width, height) * CARD_RADIUS;
1243
- [head, body, ...sides].forEach((f) => drawFlow(ctx, f, radius));
1244
- const logoImage = doc.logo ? assets[doc.logo.imageId] : void 0;
1245
- const logo = logoImage ? placeContain(logoImage, geo.logo ? zones.logo : capAligned(zones.logo, head), { anchor: "top" /* Top */, alignX: 1, scale: 1 }) : null;
1246
- if (logoImage && logo) {
1247
- ctx.drawImage(logoImage, logo.x, logo.y, logo.w, logo.h);
1248
- }
1249
- 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);
1250
1553
  const backdrop = image ? archRect(geo) : null;
1251
1554
  if (backdrop) {
1252
1555
  drawArch(ctx, backdrop, palette.arch);
1253
1556
  }
1254
- const region = pictureRegion(doc.layout, geo, body, { height, u });
1255
- const picture = image && doc.picture ? placeContain(image, region, { anchor: doc.picture.anchor, alignX: geo.alignX, scale: doc.picture.scale }) : null;
1256
1557
  if (image && picture) {
1257
1558
  ctx.drawImage(image, picture.x, picture.y, picture.w, picture.h);
1258
1559
  }
1560
+ if (layered) {
1561
+ flows.forEach((f) => drawMarks(ctx, f, radius));
1562
+ }
1259
1563
  return {
1260
1564
  width,
1261
1565
  height,
1262
1566
  picture,
1263
1567
  pictureRegion: region,
1264
- textBoxes: [head, body, ...sides].flatMap((f) => f.texts.map((t) => t.box)),
1568
+ textBoxes: flows.flatMap((f) => f.texts.map((t) => t.box)),
1265
1569
  cardBoxes: body.cards.map((c) => c.rect),
1266
- 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)),
1267
1572
  logo,
1268
1573
  backdrop
1269
1574
  };
@@ -1359,6 +1664,6 @@ var kizombaWorkshop = {
1359
1664
  };
1360
1665
  var kizombaWorkshopDocs = [...WORKSHOPS.map(workshopDoc), kizombaWorkshop];
1361
1666
 
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 };
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 };
1363
1668
  //# sourceMappingURL=index.mjs.map
1364
1669
  //# sourceMappingURL=index.mjs.map