@tolokoban/impress 0.13.0 → 0.16.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/README.md CHANGED
@@ -29,7 +29,9 @@ In a terminal, the output is colored: file names in bold, the example of AI prom
29
29
  ## Slides
30
30
 
31
31
  - `#` headings become section slides (blue background).
32
- - Deeper headings become content slides, split over several slides when they are too long. A deeper heading with no content of its own, only sub-headings, gets a section slide too: its big title is still the `#` heading above it, and the deeper heading goes in the subtitle (e.g. `Possibilités`).
32
+ - Deeper headings become content slides, split over several slides when they are too long. A deeper heading with no content of its own, only sub-headings, gets a section slide too.
33
+ - A section slide shows the `#` heading as its title, at the top, and below it a box with the hierarchy of the sections under that `#` heading, as nested bullet points. A section is expanded (its sub-sections are listed) only if the slide after the section slide is inside it. The section the slide introduces is highlighted (bold, color `sectionHighlight`); on the slide of a `#` heading, it is the sub-section holding the next slide.
34
+ - When the slides go back up more than one heading level, a section slide recalls where we are before the next slides. From `1 > 1 > 1`, going to `1 > 2` or to `1 > 2 > 1` shows the section slide of `1 > 2`; going to `1 > 1 > 2` does not.
33
35
  - Paragraphs, lists, tables, blockquotes and images are laid out automatically: images go beside or below the text depending on their shape.
34
36
  - A table too long for one slide is first spread over two side-by-side tables on the same slide. If that is still too long, it is split over several slides. In both cases the header row is repeated on each part, and every part keeps the same column widths. Put `@compact` before the table to shrink it onto one slide instead (see [Pragmas](#pragmas)).
35
37
  - Table cells can hold images, as HTML (`<img src="logos/claude.webp" alt="Claude" width="48" height="48">`) or markdown (`![Claude](logos/claude.webp)`). Their pixel sizes assume a 16px font: a 48px image is 3 times as tall as the text of the table, and it shrinks with the text of a `@compact` table. With only `width` or `height`, the other one follows the shape of the image; with neither, the image is 2 lines tall. An image alone in its cell is centered, otherwise it comes before the text. Images too wide for their column are shrunk to fit.
@@ -37,6 +39,7 @@ In a terminal, the output is colored: file names in bold, the example of AI prom
37
39
  - Lists can be bulleted (`- item`, `* item`) or numbered (`1. item`, `1) item`), and the two can be nested in each other. A numbered list starts at the number of its first item (`4.` starts at 4); the number of each following item is computed, not read. Numbered items get numbers `1.`, then letters `a.` and roman numerals `i.` when nested (see [Numbers](#numbers)).
38
40
  - Blockquotes (`> ...`) are shown in a bordered box with a soft blurred shadow.
39
41
  - A code block whose language is `prompt` is shown as a chat bubble.
42
+ - A line of dashes (`----`, at least three) draws a horizontal rule across the content of the slide (style `Separateur`).
40
43
 
41
44
  ## Pragmas
42
45
 
@@ -53,6 +56,7 @@ At the start of a line in the `.md` file:
53
56
  | `@graph <file.dot>` | Insert a Graphviz diagram (path relative to the `.md`), rendered by `dot -Tpng` (the same Cairo renderer as DOT viewers, so the diagram looks the same in the slides) and embedded in the `.odp` as a WebP image. The fonts, sizes and colors of the theme are inserted as `graph [...]`, `node [...]` and `edge [...]` defaults at the start of the graph, so every attribute set in the `.dot` file wins, including its own `node [...]` / `edge [...]` defaults. |
54
57
  | `@next` | Start a new slide with the same title as the current one. If the next line is a heading (`#`, `##`…), that heading gives the new slide its title instead. |
55
58
  | `@compact` | The next table of the section, if it is too long for one slide, has its text shrunk (down to 4pt) until it fits on one slide with the paragraph introducing it, instead of being split into two columns or over several slides. The words of the header are never cut: if one of them is too long for its column, the text is shrunk further, even when the table would fit at full size (a header cell of several words may still wrap between words). |
59
+ | `@compact [N\|*] {` … `@}` | Compact everything in between on one slide, flowing through `N` columns (`@compact {`: one column). The content flows in reading order and the columns are balanced, so the tallest one is as short as possible. A list can be cut between its top-level items (a sub-item stays with its parent, numbering continues), and a table between its rows (its header is repeated at the top of each column). Paragraphs, quotes, code blocks and images are never cut. If there are fewer of these pieces than columns, fewer columns are used. The columns are separated by 1em, and an image takes the width of its column. If the region does not fit on the slide with the paragraph introducing it, everything in it (text, spacing, tables, images) is shrunk by the same factor, half a point of body text at a time, down to 10pt for a 24pt body text. Like a `@compact` table, the region stays on the current slide if it fits there, otherwise it starts a new one with its introduction. `@compact * {` tries 1, 2, 3… columns and keeps the number giving the biggest text, the fewest columns on a tie, avoiding those where a word would be too long for its column. `@note` and `@reveal` work inside a region. A heading, `@next` or `@layout` inside a region, a region inside another one, a region in a cell of an `@layout`, a region not closed by `@}` and an `@}` without a region are errors. |
56
60
  | `@reveal [C<columns>] [R<rows>]` | The rows of the next table appear one slide after the other: the first slide shows only the header, each following slide reveals one more row. The table keeps its final size and place from the first slide. `C` and `R` list the columns and the body rows (counted from 1, header excluded) that are always visible, as numbers and ranges: `@reveal C1,3 R1-4` always shows columns 1 and 3 and rows 1 to 4. Both are optional. The speaker notes are repeated on every slide of the sequence. A revealed table always stays on one slide, and its header words are never cut, as with `@compact`: if it is too long, its rows are first spread over two side-by-side tables, and if that is still too long, its text is shrunk, on one table or two side by side, whichever keeps the text bigger. A table inside an `@layout` is shown entirely. |
57
61
 
58
62
  When some files contain `@hint`, the end of the output gives a ready-to-paste prompt asking an AI agent to apply them to the `.odp`.
@@ -97,8 +101,9 @@ The theme gathers the values that are used in several places. Changing it is the
97
101
  | `primary` | `#1F3A5F` | Slide titles, section background, table headers, quote text and border, diagram node borders. |
98
102
  | `accent` | `#E8833A` | Left bar of content slides, line under section titles, bullets. |
99
103
  | `ink` | `#222222` | Body text, code, diagram edges. |
100
- | `muted` | `#7A8899` | Breadcrumb, prompt shadow, diagram clusters. |
101
- | `subtitle` | `#FFD8B0` | Breadcrumb shown under the title of a section slide. |
104
+ | `muted` | `#7A8899` | Breadcrumb, prompt shadow, diagram clusters, horizontal rules. |
105
+ | `subtitle` | `#FFD8B0` | Sections in the hierarchy box of a section slide. |
106
+ | `sectionHighlight` | `#FF9F43` | Highlighted section in the hierarchy box of a section slide (`T_section`). |
102
107
  | `white` | `#FFFFFF` | Section titles, table header text, table cells. |
103
108
  | `quoteBackground` | `#F1F4F8` | Blockquotes. |
104
109
  | `promptBackground` | `#DCEBFF` | ` ```prompt ` chat bubbles. |
@@ -142,7 +147,7 @@ Font sizes, in points. They are not only applied to the text: they are also used
142
147
  | --- | --- | --- |
143
148
  | `title` | 34 | Title of content slides. |
144
149
  | `sectionTitle` | 44 | Title of section slides (`#` headings). |
145
- | `subtitle` | 20 | Breadcrumb under a section title. |
150
+ | `subtitle` | 20 | Hierarchy box of section slides. |
146
151
  | `breadcrumb` | 14 | Breadcrumb above the title of content slides. |
147
152
  | `text` | 24 | Paragraphs. |
148
153
  | `list` | `[24, 21, 18, …]` | List items, one size per level (9 levels). |
@@ -257,6 +262,7 @@ Since styles inherit from each other, changing a parent changes all its children
257
262
  | `Prompt` | ` ```prompt ` code blocks (chat bubbles). |
258
263
  | `Code` | Other code blocks. |
259
264
  | `Image` | Frame of images. |
265
+ | `Separateur` | Horizontal rules (`----`). |
260
266
  | `Tableau-cadre` | Frame around tables. |
261
267
  | `Decor` | Vertical bar on the left of the slide. |
262
268
  | `Master-image` | Background image (`theme.backgrounds.Master`). |
@@ -268,7 +274,7 @@ Since styles inherit from each other, changing a parent changes all its children
268
274
  | Style | Element |
269
275
  | --- | --- |
270
276
  | `Section-title` | Title: always the `#` heading. |
271
- | `Section-subtitle` | Breadcrumb of the deeper headings, under the title. |
277
+ | `Section-subtitle` | Box of the hierarchy of the sections, under the title (semi-transparent background). The sections are a bulleted list, always left aligned, nested by depth; its `bullets` define the bullets (color `sectionHighlight` by default). |
272
278
  | `Section-fond` | Full-slide background rectangle. |
273
279
  | `Section-image` | Background image (`theme.backgrounds.Section`), above `Section-fond`. |
274
280
  | `Decor` | Horizontal bar under the title. |
@@ -396,6 +402,7 @@ Impress has no character styles, so inline formatting is defined in `spanStyles`
396
402
  | `T_i` | `*italic*` |
397
403
  | `T_bi` | `***bold italic***` |
398
404
  | `T_code` | `` `code` `` |
405
+ | `T_section` | Highlighted section in the hierarchy box of a section slide. |
399
406
 
400
407
  For instance, to show inline code in color on a light background:
401
408
 
package/dist/impress.js CHANGED
@@ -25,6 +25,8 @@
25
25
  * Every embedded image (graphs included) is stored as WebP (see `theme.images`).
26
26
  * @next start a new slide with the same title as the current one
27
27
  * @compact the next table is shrunk to fit on one slide instead of being split
28
+ * @compact N { ... @} the blocks in between are compacted on one slide, in N columns (1 by
29
+ * default, "*" for the number giving the biggest text), shrunk if needed
28
30
  * @reveal C1,3 R1-4 the rows of the next table appear one slide after the other; the
29
31
  * columns (C) and rows (R) listed, both optional, are always visible
30
32
  * ```prompt ... ``` chat prompt bubble
@@ -192,12 +194,18 @@ function stripMd(s) {
192
194
  const LIST_RE = /^(\s*)(?:[*-]|(\d+)[.)])\s+(.*)$/;
193
195
  const IMG_RE = /^\s*!\[([^\]]*)\]\(([^)]+)\)\s*$/;
194
196
  const HEAD_RE = /^(#{1,6})\s+(.*)$/;
197
+ /** Horizontal rule: a line of at least three dashes. */
198
+ const HR_RE = /^-{3,}$/;
199
+ /** `@compact {`, `@compact 3 {` or `@compact * {`. */
200
+ const COMPACT_RE = /^@compact\s*(\d+|\*)?\s*\{$/;
195
201
  function parse(md, file) {
196
202
  const root = new Section(0, "", null, dirname(file));
197
203
  let cur = root;
198
204
  const lines = md.split("\n");
199
205
  let para = [];
200
206
  let list = null;
207
+ // Open `@compact {` region: its blocks go into it until `@}`.
208
+ let region = null;
201
209
  let layout = null;
202
210
  // `@layout` followed by content instead of a heading: the next blocks fill its cells.
203
211
  let grouped = null;
@@ -216,6 +224,8 @@ function parse(md, file) {
216
224
  reveal = null;
217
225
  };
218
226
  const push = (b) => {
227
+ if (region)
228
+ return void region.blocks.push(b);
219
229
  if (!grouped)
220
230
  return void cur.blocks.push(b);
221
231
  const cells = grouped.cells;
@@ -254,6 +264,10 @@ function parse(md, file) {
254
264
  const line = lines[i];
255
265
  const s = line.trim();
256
266
  let m;
267
+ if (region && (HEAD_RE.test(line) || s === "@next" || s.startsWith("@layout"))) {
268
+ const what = HEAD_RE.test(line) ? "a heading" : s === "@next" ? '"@next"' : '"@layout"';
269
+ throw new Error(`${file}:${i + 1}: ${what} cannot be inside a "@compact {" region (opened at line ${region.where.split(":").pop()}, closed by "@}")`);
270
+ }
257
271
  if ((m = line.match(HEAD_RE))) {
258
272
  flush();
259
273
  dropCompact();
@@ -297,6 +311,30 @@ function parse(md, file) {
297
311
  cur.parent.children.push(sec);
298
312
  cur = sec;
299
313
  }
314
+ else if ((m = s.match(COMPACT_RE))) {
315
+ const where = `${file}:${i + 1}`;
316
+ if (region)
317
+ throw new Error(`${where}: "@compact {" regions cannot be nested (one is already open since line ${region.where.split(":").pop()})`);
318
+ flush();
319
+ dropCompact();
320
+ dropReveal();
321
+ const columns = m[1] === "*" ? "auto" : Number(m[1] ?? 1);
322
+ if (columns === 0)
323
+ throw new Error(`${where}: a "@compact {" region needs at least one column`);
324
+ const b = { t: "compact", columns, blocks: [], where };
325
+ push(b);
326
+ region = b;
327
+ }
328
+ else if (s === "@}") {
329
+ if (!region)
330
+ throw new Error(`${file}:${i + 1}: "@}" without an open "@compact {" region`);
331
+ flush();
332
+ dropCompact();
333
+ dropReveal();
334
+ if (!region.blocks.some(b => b.t !== "note"))
335
+ console.warn(` ! ${bold(region.where)}: empty "@compact {" region`);
336
+ region = null;
337
+ }
300
338
  else if (s === "@compact") {
301
339
  flush();
302
340
  dropCompact();
@@ -378,6 +416,10 @@ function parse(md, file) {
378
416
  i--;
379
417
  push({ t: "quote", text: buf.join(" ") });
380
418
  }
419
+ else if (HR_RE.test(s)) {
420
+ flush();
421
+ push({ t: "hr" });
422
+ }
381
423
  else if ((m = line.match(IMG_RE))) {
382
424
  flush();
383
425
  push({ t: "image", alt: m[1], src: m[2] });
@@ -411,6 +453,8 @@ function parse(md, file) {
411
453
  flush();
412
454
  dropCompact();
413
455
  dropReveal();
456
+ if (region)
457
+ throw new Error(`${region.where}: "@compact {" region not closed by "@}"`);
414
458
  if (layout)
415
459
  console.warn(` ! ${bold(file)}: "${layout.source}" is not followed by any section`);
416
460
  return root;
@@ -503,17 +547,17 @@ function textH(nChars, width, pt, lh = 1.25) {
503
547
  const cpl = Math.max(1, width / (pt * PT * 0.5));
504
548
  return Math.max(1, Math.ceil(nChars / cpl)) * pt * PT * lh;
505
549
  }
506
- function paraH(text, width, pt = sizes.text) {
507
- return text.split("\n").reduce((h, p) => h + textH(plainLen(p), width, pt), 0) + 0.25;
550
+ function paraH(text, width, pt = sizes.text, k = 1) {
551
+ return text.split("\n").reduce((h, p) => h + textH(plainLen(p), width, pt), 0) + 0.25 * k;
508
552
  }
509
- function listH(items, width) {
553
+ function listH(items, width, k = 1) {
510
554
  let h = 0;
511
555
  for (const [lvl, txt] of items)
512
- h += textH(plainLen(txt), width - 0.9 * (lvl + 1), sizes.list[Math.min(lvl, 8)]) + 0.3;
556
+ h += textH(plainLen(txt), width - 0.9 * (lvl + 1), sizes.list[Math.min(lvl, 8)] * k) + 0.3 * k;
513
557
  return h + 0.1;
514
558
  }
515
- function promptSize(lines, width) {
516
- const pt = sizes.prompt;
559
+ function promptSize(lines, width, k = 1) {
560
+ const pt = sizes.prompt * k;
517
561
  const longest = Math.max(10, ...lines.map(l => l.length));
518
562
  const w = Math.min(width, Math.max(8, longest * pt * PT * 0.5 + 1.4));
519
563
  const h = lines.reduce((acc, l) => acc + textH(l.length, w - 1, pt), 0) + 0.9;
@@ -616,11 +660,11 @@ function boldWordW(word, pt) {
616
660
  * Do the words of the header of a `@compact` or `@reveal` table fit in their columns, at the
617
661
  * size of the table, on a slide of full width? Several words may wrap, but no word is cut.
618
662
  */
619
- function headerFits(b) {
663
+ function headerFits(b, width = W) {
620
664
  if (!b.header)
621
665
  return true;
622
666
  const pt = b.pt ?? sizes.table;
623
- const cols = tableBlockCols(b, W);
667
+ const cols = tableBlockCols(b, width);
624
668
  return b.header.every((s, i) => {
625
669
  const c = cell(s);
626
670
  const room = cols[i] - CELL_PAD_X - cellTextIndent(c, cols[i], pt);
@@ -682,19 +726,25 @@ function tableBlockH(b, width) {
682
726
  const pw = tablePartW(b, width);
683
727
  return Math.max(...tableParts(b).map(rows => tableH(b.header, rows, pw, b.pt ?? sizes.table, cols)));
684
728
  }
729
+ /** Height taken by a horizontal rule (the line is drawn in its middle). */
730
+ const HR_H = 0.5;
685
731
  function blockH(b, width) {
686
732
  switch (b.t) {
687
733
  case "para":
688
- return paraH(b.text, width);
734
+ return paraH(b.text, width, sizes.text * (b.k ?? 1), b.k);
689
735
  case "list":
690
- return listH(b.items, width);
736
+ return listH(b.items, width, b.k);
691
737
  case "quote":
692
- return paraH(b.text, width - 1.2, sizes.quote) + 0.8;
738
+ return paraH(b.text, width - 1.2, sizes.quote * (b.k ?? 1), b.k) + 0.8;
693
739
  case "prompt":
694
740
  case "code":
695
- return promptSize(b.lines, width)[1];
741
+ return promptSize(b.lines, width, b.k)[1];
696
742
  case "table":
697
743
  return tableBlockH(b, width);
744
+ case "hr":
745
+ return HR_H;
746
+ case "compact":
747
+ return arrange(b, width).h;
698
748
  default:
699
749
  return 0;
700
750
  }
@@ -740,6 +790,168 @@ function fit(iw, ih, bw, bh) {
740
790
  const r = Math.min(bw / iw, bh / ih);
741
791
  return [iw * r, ih * r];
742
792
  }
793
+ // ---------------------------------------------------------------- compact regions
794
+ /** Lowest font scale of a `@compact {` region: 10pt for a body text of 24pt. */
795
+ const MIN_COMPACT_SCALE = 10 / 24;
796
+ /** Highest number of columns tried by `@compact * {`. */
797
+ const MAX_AUTO_COLUMNS = 8;
798
+ /** Font scales tried for a `@compact {` region, biggest first: the body text loses half a point at each step. */
799
+ function compactScales() {
800
+ const out = [];
801
+ for (let pt = sizes.text; pt >= sizes.text * MIN_COMPACT_SCALE - 1e-6; pt -= 0.5)
802
+ out.push(pt / sizes.text);
803
+ return out;
804
+ }
805
+ const piecesCache = new WeakMap();
806
+ function compactPieces(blocks) {
807
+ let out = piecesCache.get(blocks);
808
+ if (out)
809
+ return out;
810
+ const pieces = [];
811
+ for (const b of blocks) {
812
+ if (b.t === "note")
813
+ continue;
814
+ if (b.t === "list") {
815
+ let start = 0;
816
+ b.items.forEach((it, i) => {
817
+ if (i > start && it[0] === 0) {
818
+ pieces.push({ src: b, block: { ...b, items: b.items.slice(start, i) } });
819
+ start = i;
820
+ }
821
+ });
822
+ pieces.push({ src: b, block: { ...b, items: b.items.slice(start) } });
823
+ }
824
+ else if (b.t === "table" && b.rows.length > 1) {
825
+ for (const r of b.rows)
826
+ pieces.push({ src: b, block: { ...b, rows: [r] } });
827
+ }
828
+ else
829
+ pieces.push({ src: b, block: b });
830
+ }
831
+ piecesCache.set(blocks, (out = pieces));
832
+ return out;
833
+ }
834
+ /** A block of a region at the font scale `k`. Tables keep the column widths of all their rows. */
835
+ function scaleBlock(b, src, k) {
836
+ if (b.t === "table")
837
+ return { ...b, pt: sizes.table * k, ref: src.rows, compact: undefined, columns: undefined };
838
+ if (b.t === "hr" || b.t === "note" || b.t === "layout" || b.t === "compact")
839
+ return b;
840
+ return { ...b, k };
841
+ }
842
+ /** The blocks of a column: consecutive pieces of the same list or table are merged back together. */
843
+ function mergePieces(pieces, k) {
844
+ const out = [];
845
+ pieces.forEach((p, i) => {
846
+ const last = out[out.length - 1];
847
+ const same = i > 0 && pieces[i - 1].src === p.src;
848
+ if (same && last.t === "list" && p.block.t === "list")
849
+ out[out.length - 1] = { ...last, items: [...last.items, ...p.block.items] };
850
+ else if (same && last.t === "table" && p.block.t === "table")
851
+ out[out.length - 1] = { ...last, rows: [...last.rows, ...p.block.rows] };
852
+ else
853
+ out.push(scaleBlock(p.block, p.src, k));
854
+ });
855
+ return out;
856
+ }
857
+ /** Height of a block in a column of a region. An image takes the width of the column, up to the (scaled) height of the slide. */
858
+ function regionBlockH(b, width) {
859
+ if (b.t !== "image")
860
+ return blockH(b, width);
861
+ return regionImageSize(b, width)[1];
862
+ }
863
+ function regionImageSize(b, width) {
864
+ const [iw, ih] = imageSize(resolve(mdDir, b.src));
865
+ return fit(iw, ih, width, H * (b.k ?? 1));
866
+ }
867
+ const arrangeCache = new WeakMap();
868
+ /**
869
+ * Lay out a region at its scale and number of columns (fewer if it has fewer pieces) in `width`.
870
+ * The pieces flow in reading order through the columns, cut so that the tallest column is as
871
+ * short as possible.
872
+ */
873
+ function arrange(b, width) {
874
+ const k = b.k ?? 1;
875
+ const pieces = compactPieces(b.blocks);
876
+ const P = pieces.length;
877
+ const n = Math.max(1, Math.min(b.n ?? (b.columns === "auto" ? 1 : b.columns), P));
878
+ const key = `${f2(width)}|${n}|${k}`;
879
+ let cache = arrangeCache.get(b.blocks);
880
+ if (!cache)
881
+ arrangeCache.set(b.blocks, (cache = new Map()));
882
+ const hit = cache.get(key);
883
+ if (hit)
884
+ return hit;
885
+ // 1em of the (scaled) body text between the columns.
886
+ const gap = sizes.text * k * PT;
887
+ const colW = (width - gap * (n - 1)) / n;
888
+ const memo = new Map();
889
+ /** Height of the column holding the pieces `i` to `j - 1`. */
890
+ const colH = (i, j) => {
891
+ let h = memo.get(i * (P + 1) + j);
892
+ if (h === undefined) {
893
+ const bs = mergePieces(pieces.slice(i, j), k);
894
+ h = bs.reduce((a, x) => a + regionBlockH(x, colW), 0) + GAP * k * (bs.length - 1);
895
+ memo.set(i * (P + 1) + j, h);
896
+ }
897
+ return h;
898
+ };
899
+ // best[c][j]: lowest height of the tallest of `c` columns holding the first `j` pieces;
900
+ // cut[c][j]: first piece of the last of these columns.
901
+ const best = [Array.from({ length: P + 1 }, (_, j) => (j ? Infinity : 0))];
902
+ const cut = [[]];
903
+ for (let c = 1; c <= n; c++) {
904
+ best.push(new Array(P + 1).fill(Infinity));
905
+ cut.push(new Array(P + 1).fill(0));
906
+ for (let j = c; j <= P; j++)
907
+ for (let i = c - 1; i < j; i++) {
908
+ const h = Math.max(best[c - 1][i], colH(i, j));
909
+ if (h < best[c][j]) {
910
+ best[c][j] = h;
911
+ cut[c][j] = i;
912
+ }
913
+ }
914
+ }
915
+ const cols = [];
916
+ if (P)
917
+ for (let c = n, j = P; c > 0; c--) {
918
+ const i = cut[c][j];
919
+ cols.unshift(mergePieces(pieces.slice(i, j), k));
920
+ j = i;
921
+ }
922
+ const out = { n, k, colW, gap, cols, h: P ? best[n][P] : 0 };
923
+ cache.set(key, out);
924
+ return out;
925
+ }
926
+ /**
927
+ * Do the words of a laid out region fit in its columns? The words of the table headers are always
928
+ * checked (as for `@compact` tables); those of the paragraphs, quotes and lists only when `all`.
929
+ */
930
+ function regionWordsFit(arr, all) {
931
+ const fits = (text, room, pt) => inline(text)
932
+ .map(r => r.text)
933
+ .join("")
934
+ .split(/\s+/)
935
+ .filter(Boolean)
936
+ .every(w => boldWordW(w, pt) <= room);
937
+ return arr.cols.every(col => col.every(b => {
938
+ if (b.t === "table")
939
+ return headerFits(b, arr.colW);
940
+ if (!all)
941
+ return true;
942
+ if (b.t === "para")
943
+ return fits(b.text, arr.colW - 0.5, sizes.text * arr.k);
944
+ if (b.t === "quote")
945
+ return fits(b.text, arr.colW - 1.7, sizes.quote * arr.k);
946
+ if (b.t === "list")
947
+ return b.items.every(([lvl, txt]) => fits(txt, arr.colW - 0.9 * (lvl + 1), sizes.list[Math.min(lvl, 8)] * arr.k));
948
+ return true;
949
+ }));
950
+ }
951
+ /** The tables of some blocks, including those of their `@compact {` regions. */
952
+ function tablesOf(blocks) {
953
+ return blocks.flatMap(b => (b.t === "table" ? [b] : b.t === "compact" ? tablesOf(b.blocks) : []));
954
+ }
743
955
  /** Rendered diagrams, keyed by the arguments of `dot` (which include the theme). */
744
956
  const graphCache = new Map();
745
957
  const IS_WINDOWS = process.platform === "win32";
@@ -998,6 +1210,8 @@ async function encodePictures(pics) {
998
1210
  .toBuffer();
999
1211
  }));
1000
1212
  }
1213
+ /** Geometry of section slides: title at the top, bar under it, then the box of the hierarchy. */
1214
+ const SEC = { x: 2, w: 24, titleY: 0.5, titleH: 2.6, barY: 3.1, boxY: 3.7, boxBottom: 15 };
1001
1215
  const f2 = (n) => n.toFixed(2);
1002
1216
  /**
1003
1217
  * The content of one slide, once per step of its `@reveal` tables: the first step shows their
@@ -1005,12 +1219,13 @@ const f2 = (n) => n.toFixed(2);
1005
1219
  * the order of the slide, rows in reading order). Rows with nothing to reveal are skipped.
1006
1220
  */
1007
1221
  function revealSteps(content) {
1008
- const order = content.flatMap(b => b.t === "table" && b.reveal ? b.rows.filter(r => !b.reveal.rows.has(r) && r.some((c, i) => c !== "" && !b.reveal.cols.has(i))) : []);
1009
- if (!content.some(b => b.t === "table" && b.reveal))
1222
+ const revealed = tablesOf(content).filter(b => b.reveal);
1223
+ if (!revealed.length)
1010
1224
  return [content];
1225
+ const order = revealed.flatMap(b => b.rows.filter(r => !b.reveal.rows.has(r) && r.some((c, i) => c !== "" && !b.reveal.cols.has(i))));
1011
1226
  return Array.from({ length: order.length + 1 }, (_, k) => {
1012
1227
  const shown = new Set(order.slice(0, k));
1013
- return content.map(b => (b.t === "table" && b.reveal ? { ...b, shown } : b));
1228
+ return content.map(b => (b.t === "table" && b.reveal) || (b.t === "compact" && tablesOf(b.blocks).some(t => t.reveal)) ? { ...b, shown } : b);
1014
1229
  });
1015
1230
  }
1016
1231
  class Builder {
@@ -1022,6 +1237,10 @@ class Builder {
1022
1237
  paraStyles = new Map();
1023
1238
  /** Hints waiting to be attached to the next slide title. */
1024
1239
  pendingHints = [];
1240
+ /** Heading path of the section of the last slide. */
1241
+ lastPath = [];
1242
+ /** Section of the slides being built. */
1243
+ current = null;
1025
1244
  constructor(base) {
1026
1245
  this.base = base;
1027
1246
  mdDir = base;
@@ -1052,12 +1271,22 @@ class Builder {
1052
1271
  * Automatic paragraph style setting the font size (in points) of a `@compact` table,
1053
1272
  * and the left margin (in cm) leaving room for the images of a cell.
1054
1273
  */
1055
- paraStyle(pt, indent = 0) {
1056
- const key = indent ? `${f2(pt)}/${f2(indent)}` : f2(pt);
1274
+ paraStyle(pt, indent = 0, margins) {
1275
+ const key = [f2(pt), indent ? f2(indent) : "", margins ? margins.map(f2).join(",") : ""].join("/");
1057
1276
  if (!this.paraStyles.has(key))
1058
1277
  this.paraStyles.set(key, `Pt${this.paraStyles.size + 1}`);
1059
1278
  return this.paraStyles.get(key);
1060
1279
  }
1280
+ /**
1281
+ * Style attribute of a paragraph of `pt` points shrunk by a `@compact {` region (nothing when
1282
+ * `k` is 1). The spacing above and below the paragraphs of the style `name` shrinks too.
1283
+ */
1284
+ scaledPara(pt, k = 1, name) {
1285
+ if (k === 1)
1286
+ return "";
1287
+ const margins = name ? [styleCm(name, "fo:margin-top") * k, styleCm(name, "fo:margin-bottom") * k] : undefined;
1288
+ return ` text:style-name="${this.paraStyle(pt * k, 0, margins)}"`;
1289
+ }
1061
1290
  rowStyle(h) {
1062
1291
  const key = f2(h);
1063
1292
  if (!this.rowStyles.has(key))
@@ -1087,7 +1316,7 @@ class Builder {
1087
1316
  * style. Lists with numbered items name the list styles `<frameStyle>-numbers` and
1088
1317
  * `<frameStyle>-bullets` (see `listStylesXml()`) on every nested list.
1089
1318
  */
1090
- listXml(items, frameStyle) {
1319
+ listXml(items, frameStyle, k = 1) {
1091
1320
  const holder = listStyleHolder(frameStyle);
1092
1321
  const styled = holder !== null && items.some(it => it[2] !== undefined);
1093
1322
  const out = [];
@@ -1113,7 +1342,7 @@ class Builder {
1113
1342
  out.push(`<text:list${name}><text:list-item${start}>`);
1114
1343
  open.push(ordered);
1115
1344
  }
1116
- out.push(`<text:p>${runsXml(txt)}</text:p>`);
1345
+ out.push(`<text:p${this.scaledPara(sizes.list[Math.min(lvl, 8)], k, outlineStyle(frameStyle, lvl))}>${runsXml(txt)}</text:p>`);
1117
1346
  }
1118
1347
  while (open.length)
1119
1348
  close();
@@ -1181,8 +1410,14 @@ class Builder {
1181
1410
  (alt ? `<svg:title>${esc(alt)}</svg:title>` : "") +
1182
1411
  `</draw:frame>`);
1183
1412
  }
1184
- promptXml(lines, x, y, w, h, style = "Prompt") {
1185
- const paras = lines.map(l => `<text:p>${xmlText(l)}</text:p>`).join("");
1413
+ /** Horizontal line across the box, in its middle. */
1414
+ hrXml(x, y, w, h) {
1415
+ const ly = f2(y + h / 2);
1416
+ return `<draw:line draw:style-name="Separateur" svg:x1="${f2(x)}cm" svg:y1="${ly}cm" svg:x2="${f2(x + w)}cm" svg:y2="${ly}cm"/>`;
1417
+ }
1418
+ promptXml(lines, x, y, w, h, style = "Prompt", k = 1) {
1419
+ const ps = this.scaledPara(style === "Code" ? sizes.code : sizes.prompt, k);
1420
+ const paras = lines.map(l => `<text:p${ps}>${xmlText(l)}</text:p>`).join("");
1186
1421
  return (`<draw:custom-shape draw:style-name="${style}" ${Builder.geom(x, y, w, h)}>${paras}` +
1187
1422
  `<draw:enhanced-geometry svg:viewBox="0 0 21600 21600" draw:type="round-rectangle" draw:modifiers="1800"/>` +
1188
1423
  `</draw:custom-shape>`);
@@ -1190,16 +1425,18 @@ class Builder {
1190
1425
  blockXml(b, x, y, w, h) {
1191
1426
  switch (b.t) {
1192
1427
  case "para":
1193
- return this.frame("Texte", x, y, w, h, `<text:p>${runsXml(b.text)}</text:p>`);
1428
+ return this.frame("Texte", x, y, w, h, `<text:p${this.scaledPara(sizes.text, b.k, "Texte")}>${runsXml(b.text)}</text:p>`);
1194
1429
  case "list":
1195
- return this.frame("Master-outline1", x, y, w, h, this.listXml(b.items, "Master-outline1"), "outline");
1430
+ return this.frame("Master-outline1", x, y, w, h, this.listXml(b.items, "Master-outline1", b.k), "outline");
1196
1431
  case "quote":
1197
- return this.frame("Citation", x, y, w, h, `<text:p>${runsXml(b.text)}</text:p>`);
1432
+ return this.frame("Citation", x, y, w, h, `<text:p${this.scaledPara(sizes.quote, b.k, "Citation")}>${runsXml(b.text)}</text:p>`);
1198
1433
  case "prompt":
1199
1434
  case "code": {
1200
- const [pw] = promptSize(b.lines, w);
1201
- return this.promptXml(b.lines, x + w - pw, y, pw, h, b.t === "prompt" ? "Prompt" : "Code");
1435
+ const [pw] = promptSize(b.lines, w, b.k);
1436
+ return this.promptXml(b.lines, x + w - pw, y, pw, h, b.t === "prompt" ? "Prompt" : "Code", b.k);
1202
1437
  }
1438
+ case "compact":
1439
+ return this.regionXml(b, x, y, w);
1203
1440
  case "table": {
1204
1441
  const pw = tablePartW(b, w);
1205
1442
  const cols = tableBlockCols(b, w);
@@ -1207,10 +1444,32 @@ class Builder {
1207
1444
  .map((rows, i) => this.tableXml(b.header, rows, x + i * (pw + TABLE_GAP), y, pw, b.pt ?? sizes.table, false, cols, (r, c) => isHidden(b, r, c)))
1208
1445
  .join("");
1209
1446
  }
1447
+ case "hr":
1448
+ return this.hrXml(x, y, w, h);
1210
1449
  default:
1211
1450
  throw new Error(`Unexpected block ${b.t}`);
1212
1451
  }
1213
1452
  }
1453
+ /** The columns of a `@compact {` region, top-aligned. */
1454
+ regionXml(b, x, y, w) {
1455
+ const arr = arrange(b, w);
1456
+ const out = [];
1457
+ arr.cols.forEach((col, c) => {
1458
+ const cx = x + c * (arr.colW + arr.gap);
1459
+ let cy = y;
1460
+ for (const blk of col) {
1461
+ const bh = regionBlockH(blk, arr.colW);
1462
+ if (blk.t === "image") {
1463
+ const [iw] = regionImageSize(blk, arr.colW);
1464
+ out.push(this.imageXml(blk.src, cx + (arr.colW - iw) / 2, cy, iw, bh, blk.alt));
1465
+ }
1466
+ else
1467
+ out.push(this.blockXml(blk.t === "table" && b.shown ? { ...blk, shown: b.shown } : blk, cx, cy, arr.colW, bh));
1468
+ cy += bh + GAP * arr.k;
1469
+ }
1470
+ });
1471
+ return out.join("");
1472
+ }
1214
1473
  // -- slide-level layout
1215
1474
  /** Return the required height and the shapes for the content blocks of one slide. */
1216
1475
  layout(blocks) {
@@ -1261,6 +1520,10 @@ class Builder {
1261
1520
  slides[slides.length - 1][1].push(b.text);
1262
1521
  continue;
1263
1522
  }
1523
+ if (b.t === "compact") {
1524
+ this.compactRegion(b, slides);
1525
+ continue;
1526
+ }
1264
1527
  if (b.t === "table" && (!this.fits([b]) || ((b.compact || b.reveal) && !headerFits(b)))) {
1265
1528
  // A revealed table must stay on one slide: on two side-by-side tables, or else shrunk.
1266
1529
  if (b.reveal)
@@ -1335,6 +1598,56 @@ class Builder {
1335
1598
  const carry = cur.length > 1 && intro.length && this.fits([...intro, small]) ? [cur.pop()] : [];
1336
1599
  slides.push([[...carry, small], []]);
1337
1600
  }
1601
+ /**
1602
+ * A `@compact {` region: at full size if it fits on a slide with the paragraph introducing it,
1603
+ * otherwise shrunk (by steps of half a point of body text) until its balanced columns fit.
1604
+ * `@compact * {` takes the number of columns giving the biggest text (the fewest on a tie),
1605
+ * among those where no word is too long for its column. Like a `@compact` table, it stays on
1606
+ * the current slide if it fits there, otherwise it starts a new one with its introduction.
1607
+ */
1608
+ compactRegion(b, slides) {
1609
+ const cur = slides[slides.length - 1][0];
1610
+ const last = cur[cur.length - 1];
1611
+ const intro = last?.t === "para" ? [last] : [];
1612
+ const pieces = compactPieces(b.blocks).length;
1613
+ const auto = b.columns === "auto";
1614
+ const counts = auto
1615
+ ? Array.from({ length: Math.max(1, Math.min(pieces, MAX_AUTO_COLUMNS)) }, (_, i) => i + 1)
1616
+ : [Math.max(1, Math.min(b.columns, pieces))];
1617
+ const scales = compactScales();
1618
+ const at = (n, k) => ({ ...b, n, k });
1619
+ const fitsAlone = (r) => this.fits([...intro, r]);
1620
+ // Biggest scale (fewest columns on a tie) passing `ok`.
1621
+ const search = (ok) => {
1622
+ let found = null;
1623
+ for (const n of counts) {
1624
+ const k = scales.find(k => (!found || k > found.k) && ok(at(n, k)));
1625
+ if (k !== undefined)
1626
+ found = at(n, k);
1627
+ if (found?.k === 1)
1628
+ break;
1629
+ }
1630
+ return found;
1631
+ };
1632
+ let region = search(r => fitsAlone(r) && regionWordsFit(arrange(r, W), auto)) ?? search(fitsAlone);
1633
+ const minPt = Math.round(sizes.text * MIN_COMPACT_SCALE * 2) / 2;
1634
+ if (!region) {
1635
+ // Too long even at the smallest size: the number of columns giving the shortest region.
1636
+ const k = scales[scales.length - 1];
1637
+ region = counts.map(n => at(n, k)).reduce((a, r) => (arrange(r, W).h < arrange(a, W).h ? r : a));
1638
+ console.warn(` ! ${bold(b.where)}: the "@compact {" region is still too long with a body text of ${minPt}pt: it overflows its slide`);
1639
+ }
1640
+ else if (!regionWordsFit(arrange(region, W), false)) {
1641
+ console.warn(` ! ${bold(b.where)}: a table of the "@compact {" region has header words too long for their column`);
1642
+ }
1643
+ if (!cur.length || this.fits([...cur, region]))
1644
+ cur.push(region);
1645
+ else {
1646
+ const carry = cur.length > 1 && intro.length && this.fits([...intro, region]) ? [cur.pop()] : [];
1647
+ slides.push([[...carry, region], []]);
1648
+ }
1649
+ slides[slides.length - 1][1].push(...b.blocks.flatMap(x => (x.t === "note" ? [x.text] : [])));
1650
+ }
1338
1651
  /**
1339
1652
  * Spread the rows of a table over two side-by-side tables, if they fit on one slide: on the
1340
1653
  * current slide if there is room, otherwise on a new one. Return false if they do not fit.
@@ -1389,7 +1702,9 @@ class Builder {
1389
1702
  }
1390
1703
  // -- pages
1391
1704
  page(master, shapes, notes = []) {
1392
- this.pages.push({ master, shapes, notes });
1705
+ const page = { master, shapes, notes, sec: this.current };
1706
+ this.pages.push(page);
1707
+ return page;
1393
1708
  }
1394
1709
  titleShapes(title, crumbs) {
1395
1710
  const out = [];
@@ -1399,13 +1714,74 @@ class Builder {
1399
1714
  return out;
1400
1715
  }
1401
1716
  sectionPage(sec) {
1402
- // The big title is always the top-level (`#`) heading; deeper headings go in the subtitle.
1403
- const [title, ...rest] = sec.path();
1404
- const shapes = [this.frame("Section-title", 2, 5, 24, 3.5, `<text:p>${xmlText(title)}</text:p>`, "title", this.takeHints())];
1405
- if (rest.length)
1406
- shapes.push(this.frame("Section-subtitle", 2, 8.8, 24, 1.5, `<text:p>${xmlText(rest.join(" › "))}</text:p>`, "subtitle"));
1717
+ // The big title is always the top-level (`#`) heading; the hierarchy box comes in `finish()`.
1718
+ const [title] = sec.path();
1719
+ const shapes = [this.frame("Section-title", SEC.x, SEC.titleY, SEC.w, SEC.titleH, `<text:p>${xmlText(title)}</text:p>`, "title", this.takeHints())];
1407
1720
  const notes = sec.blocks.flatMap(b => (b.t === "note" ? [b.text] : []));
1408
- this.page("Section", shapes, notes);
1721
+ this.page("Section", shapes, notes).toc = sec;
1722
+ this.lastPath = sec.path();
1723
+ }
1724
+ /** Adds the hierarchy boxes to the section slides, now that the slide after each one is known. */
1725
+ finish() {
1726
+ this.pages.forEach((page, i) => {
1727
+ if (page.toc)
1728
+ page.shapes.push(...this.tocShapes(page.toc, this.pages[i + 1]?.sec ?? null));
1729
+ });
1730
+ }
1731
+ /**
1732
+ * Box listing the sub-sections of the `#` heading of `sec`, indented by depth. A section is
1733
+ * expanded only if the next slide (in section `next`) is inside it. The highlighted section is
1734
+ * `sec`, or for a `#` slide, the sub-section holding the next slide.
1735
+ */
1736
+ tocShapes(sec, next) {
1737
+ let top = sec;
1738
+ while (top.parent && top.parent.level > 0)
1739
+ top = top.parent;
1740
+ const ancestors = new Set();
1741
+ for (let s = next?.parent ?? null; s; s = s.parent)
1742
+ ancestors.add(s);
1743
+ let current = sec.level > 1 ? sec : null;
1744
+ if (!current && next && next !== top) {
1745
+ current = next;
1746
+ while (current.parent && current.parent !== top)
1747
+ current = current.parent;
1748
+ }
1749
+ const pt = style.theme.sizes.subtitle;
1750
+ const lines = [];
1751
+ // Nested bulleted lists: the bullets come from the `bullets` of `Section-subtitle` (list style `Toc-list`).
1752
+ const listXml = (parent) => {
1753
+ const items = [];
1754
+ for (const child of parent.children) {
1755
+ if (child.continued || !child.title)
1756
+ continue;
1757
+ let text = xmlText(child.title);
1758
+ if (child === current)
1759
+ text = `<text:span text:style-name="T_section">${text}</text:span>`;
1760
+ lines.push(text);
1761
+ const sub = ancestors.has(child) ? listXml(child) : "";
1762
+ items.push(`<text:list-item><text:p text:style-name="Toc">${text}</text:p>${sub}</text:list-item>`);
1763
+ }
1764
+ const name = style.styles["Section-subtitle"]?.bullets ? ` text:style-name="Toc-list"` : "";
1765
+ return items.length ? `<text:list${name}>${items.join("")}</text:list>` : "";
1766
+ };
1767
+ const xml = listXml(top);
1768
+ if (!lines.length)
1769
+ return [];
1770
+ const lineH = pt * PT * 1.25;
1771
+ const h = Math.min(SEC.boxBottom - SEC.boxY, lines.length * lineH + 1.2);
1772
+ return [this.frame("Section-subtitle", SEC.x, SEC.boxY, SEC.w, h, xml, "subtitle")];
1773
+ }
1774
+ /**
1775
+ * When going back up more than one level (from `1 > 1 > 1` to `1 > 2`, or to `1 > 2 > 1`),
1776
+ * a section slide recalls where we are before the slides of `sec`.
1777
+ */
1778
+ recallSection(sec) {
1779
+ const path = sec.path();
1780
+ let common = 0;
1781
+ while (common < path.length && common < this.lastPath.length && path[common] === this.lastPath[common])
1782
+ common++;
1783
+ if (this.lastPath.length - common >= 2)
1784
+ this.sectionPage(sec);
1409
1785
  }
1410
1786
  contentPages(title, crumbs, blocks) {
1411
1787
  // Notes not attached to a slide yet: they go to the next one.
@@ -1480,6 +1856,8 @@ class Builder {
1480
1856
  cellXml(sec, x, y, w, h, textStyle, textPt) {
1481
1857
  const items = [];
1482
1858
  for (const b of sec.blocks) {
1859
+ if (b.t === "compact")
1860
+ throw new Error(`${b.where}: a "@compact {" region cannot be in a cell of an "@layout"`);
1483
1861
  if (b.t === "note" || b.t === "layout")
1484
1862
  continue;
1485
1863
  const last = items[items.length - 1];
@@ -1501,6 +1879,8 @@ class Builder {
1501
1879
  return tableH(b.header, b.rows, w, sizes.tableSmall);
1502
1880
  if (b.t === "prompt" || b.t === "code")
1503
1881
  return promptSize(b.lines, w)[1];
1882
+ if (b.t === "hr")
1883
+ return HR_H;
1504
1884
  return 0;
1505
1885
  });
1506
1886
  const flexible = items.map(it => it.kind === "text" || (it.kind === "block" && it.block.t === "image"));
@@ -1553,6 +1933,9 @@ class Builder {
1553
1933
  const [pw] = promptSize(b.lines, w);
1554
1934
  shapes.push(this.promptXml(b.lines, x + w - pw, cy, pw, ih, b.t === "prompt" ? "Prompt" : "Code"));
1555
1935
  }
1936
+ else if (b.t === "hr") {
1937
+ shapes.push(this.hrXml(x, cy, w, ih));
1938
+ }
1556
1939
  }
1557
1940
  cy += heights[i] + gap;
1558
1941
  });
@@ -1615,6 +1998,7 @@ class Builder {
1615
1998
  this.page("Master", shapes, notes);
1616
1999
  }
1617
2000
  walk(sec) {
2001
+ this.current = sec;
1618
2002
  this.pendingHints.push(...sec.hints);
1619
2003
  const crumbs = sec.path().slice(0, -1);
1620
2004
  const content = sec.blocks.filter(b => b.t !== "note");
@@ -1624,9 +2008,12 @@ class Builder {
1624
2008
  this.sectionPage(sec);
1625
2009
  if (content.length)
1626
2010
  this.contentPages(sec.title, [...crumbs, sec.title], sec.blocks);
2011
+ this.lastPath = sec.path();
1627
2012
  }
1628
2013
  else if (content.length) {
2014
+ this.recallSection(sec);
1629
2015
  this.contentPages(sec.title, crumbs, sec.blocks);
2016
+ this.lastPath = sec.path();
1630
2017
  }
1631
2018
  else if (sec.children.length && !groupedOnly) {
1632
2019
  this.sectionPage(sec);
@@ -1643,13 +2030,19 @@ class Builder {
1643
2030
  continue;
1644
2031
  }
1645
2032
  const group = children.slice(i, i + cellCount(layout));
2033
+ if (sec.level > 0)
2034
+ this.recallSection(sec);
2035
+ this.current = group[0];
1646
2036
  for (const g of group)
1647
2037
  this.pendingHints.push(...g.hints);
1648
2038
  const title = sec.level > 0 ? sec.title : group[0].title;
1649
2039
  this.layoutPage(title, sec.path().slice(0, -1), group, layout, i === 0 ? notes : []);
2040
+ this.lastPath = sec.level > 0 ? sec.path() : group[0].path();
1650
2041
  // Sub-sections of grouped sections still get their own slides.
1651
- for (const g of group)
2042
+ for (const g of group) {
2043
+ this.current = g;
1652
2044
  this.walkChildren(g);
2045
+ }
1653
2046
  i += group.length - 1;
1654
2047
  }
1655
2048
  }
@@ -1684,6 +2077,23 @@ function bulletsXml(def, name) {
1684
2077
  `</text:list-level-style-bullet>`);
1685
2078
  return `<text:list-style style:name="${esc(name)}-list">${levels.join("")}</text:list-style>`;
1686
2079
  }
2080
+ /** Length in cm of a paragraph property (`"0.2cm"`) of a style or of its parents, 0 if none. */
2081
+ function styleCm(name, prop) {
2082
+ for (let n = name, depth = 0; n && depth < 20; depth++) {
2083
+ const s = style.styles[n];
2084
+ const v = s?.paragraph?.[prop];
2085
+ if (v !== undefined) {
2086
+ const m = resolveValue(String(v), `style "${n}"`).match(/^(-?[\d.]+)(cm|mm|pt)$/);
2087
+ return m ? Number(m[1]) * (m[2] === "mm" ? 0.1 : m[2] === "pt" ? PT : 1) : 0;
2088
+ }
2089
+ n = s?.parent;
2090
+ }
2091
+ return 0;
2092
+ }
2093
+ /** Style of the paragraphs of level `lvl` (0-based) in a frame of style `Master-outline1`. */
2094
+ function outlineStyle(frameStyle, lvl) {
2095
+ return frameStyle.replace(/1$/, String(Math.min(lvl, 8) + 1));
2096
+ }
1687
2097
  /** `name` or its nearest parent style defining both `bullets` and `numbers`, if any. */
1688
2098
  function listStyleHolder(name) {
1689
2099
  for (let n = name, depth = 0; n && depth < 20; depth++) {
@@ -1783,9 +2193,9 @@ function stylesXml(b) {
1783
2193
  `<style:master-page style:name="Section" style:page-layout-name="PM1" draw:style-name="Mdp1">` +
1784
2194
  `<draw:rect draw:style-name="Section-fond" ${Builder.geom(0, 0, SLIDE_W, SLIDE_H)}/>` +
1785
2195
  backgroundXml(b, "Section") +
1786
- `<draw:rect draw:style-name="Decor" ${Builder.geom(0, 8.55, SLIDE_W, 0.12)}/>` +
1787
- placeholder("Section-title", "title", 2, 5, 24, 3.5) +
1788
- placeholder("Section-subtitle", "subtitle", 2, 8.8, 24, 1.5) +
2196
+ `<draw:rect draw:style-name="Decor" ${Builder.geom(0, SEC.barY, SLIDE_W, 0.12)}/>` +
2197
+ placeholder("Section-title", "title", SEC.x, SEC.titleY, SEC.w, SEC.titleH) +
2198
+ placeholder("Section-subtitle", "subtitle", SEC.x, SEC.boxY, SEC.w, SEC.boxBottom - SEC.boxY) +
1789
2199
  `${notes("Section")}</style:master-page>`,
1790
2200
  ];
1791
2201
  return (`<?xml version="1.0" encoding="UTF-8"?><office:document-styles ${NS}>` +
@@ -1801,10 +2211,17 @@ function contentXml(b) {
1801
2211
  for (const [key, name] of b.colStyles)
1802
2212
  auto.push(`<style:style style:name="${name}" style:family="table-column"><style:table-column-properties style:column-width="${key}cm"/></style:style>`);
1803
2213
  for (const [key, name] of b.paraStyles) {
1804
- const [pt, indent] = key.split("/");
1805
- const para = indent ? `<style:paragraph-properties fo:margin-left="${indent}cm"/>` : "";
2214
+ const [pt, indent, margins] = key.split("/");
2215
+ const [top, bottom] = margins ? margins.split(",") : [];
2216
+ const props = [indent ? `fo:margin-left="${indent}cm"` : "", margins ? `fo:margin-top="${top}cm" fo:margin-bottom="${bottom}cm"` : ""].filter(Boolean);
2217
+ const para = props.length ? `<style:paragraph-properties ${props.join(" ")}/>` : "";
1806
2218
  auto.push(`<style:style style:name="${name}" style:family="paragraph">${para}<style:text-properties fo:font-size="${pt}pt"/></style:style>`);
1807
2219
  }
2220
+ // Lines of the hierarchy boxes of section slides: left aligned (the bullets indent them).
2221
+ auto.push(`<style:style style:name="Toc" style:family="paragraph"><style:paragraph-properties fo:text-align="start" fo:margin-top="0.1cm" fo:margin-bottom="0.1cm"/></style:style>`);
2222
+ const tocBullets = style.styles["Section-subtitle"]?.bullets;
2223
+ if (tocBullets)
2224
+ auto.push(bulletsXml(tocBullets, "Toc"));
1808
2225
  for (const [key, name] of b.rowStyles)
1809
2226
  auto.push(`<style:style style:name="${name}" style:family="table-row"><style:table-row-properties style:row-height="${key}cm"/></style:style>`);
1810
2227
  const pages = b.pages.map(({ master, shapes, notes }, i) => {
@@ -1912,6 +2329,7 @@ async function convert(src, config) {
1912
2329
  const root = parse(readFileSync(src, "utf8"), src);
1913
2330
  const b = new Builder(dirname(src));
1914
2331
  b.walkChildren(root);
2332
+ b.finish();
1915
2333
  const out = src.replace(/\.md$/i, ".odp");
1916
2334
  await writeOdp(b, out, basename(src, extname(src)));
1917
2335
  return { out, hints: countHints(root) };
@@ -1954,6 +2372,7 @@ const PRAGMAS = [
1954
2372
  ["@graph <file.dot>", "Insert a Graphviz diagram (path relative to the .md), rendered as a PNG image by dot."],
1955
2373
  ["@next", "Start a new slide with the same title as the current one (unless a heading follows)."],
1956
2374
  ["@compact", "Shrink the next table so that it fits on one slide, instead of splitting it."],
2375
+ ["@compact [N|*] { ... @}", 'Compact the blocks in between on one slide, flowing through N columns (1 by default, "*": the number giving the biggest text), shrunk if needed.'],
1957
2376
  ["@reveal [C<cols>] [R<rows>]", 'Reveal the rows of the next table one slide after the other; "C1,3 R1-4" keeps columns 1 and 3 and rows 1 to 4 always visible.'],
1958
2377
  ["```prompt ... ```", "Not a pragma: a code block shown as a chat prompt bubble."],
1959
2378
  ];
package/dist/styles.js CHANGED
@@ -19,6 +19,7 @@ export const defaultTheme = {
19
19
  ink: "#222222",
20
20
  muted: "#7A8899",
21
21
  subtitle: "#FFD8B0",
22
+ sectionHighlight: "#FF9F43",
22
23
  white: "#FFFFFF",
23
24
  quoteBackground: "#F1F4F8",
24
25
  promptBackground: "#DCEBFF",
@@ -125,7 +126,18 @@ function masterStyles(master) {
125
126
  },
126
127
  [`${master}-subtitle`]: {
127
128
  family: "presentation",
128
- graphic: { "draw:stroke": "none", "draw:fill": "none", "draw:textarea-vertical-align": "top", ...shrink },
129
+ graphic: {
130
+ "draw:stroke": "none",
131
+ "draw:fill": "solid",
132
+ "draw:fill-color": "#000000",
133
+ "draw:opacity": "55%",
134
+ "draw:textarea-vertical-align": "middle",
135
+ "fo:padding-left": "0.8cm",
136
+ "fo:padding-right": "0.8cm",
137
+ ...shrink,
138
+ },
139
+ // Bullets of the hierarchy box of section slides.
140
+ bullets: { ...bullets, color: "{colors.sectionHighlight}", indent: 1.2 },
129
141
  paragraph: { "fo:text-align": "center" },
130
142
  text: { ...sans, "fo:font-size": "{sizes.subtitle}pt", "fo:color": "{colors.subtitle}" },
131
143
  },
@@ -297,6 +309,12 @@ const defaultStyles = {
297
309
  text: { ...mono, "fo:font-size": "{sizes.code}pt", "fo:color": "{colors.ink}" },
298
310
  },
299
311
  Image: { family: "graphic", parent: "standard", graphic: { "draw:stroke": "none", "draw:fill": "none" } },
312
+ /** `----`: horizontal rule. */
313
+ Separateur: {
314
+ family: "graphic",
315
+ parent: "standard",
316
+ graphic: { "draw:stroke": "solid", "svg:stroke-color": "{colors.muted}", "svg:stroke-width": "0.03cm" },
317
+ },
300
318
  "Tableau-cadre": { family: "graphic", parent: "standard", graphic: { "draw:stroke": "none", "draw:fill": "none" } },
301
319
  /** `@layout columns ...`: column headings and column text. */
302
320
  "Colonne-titre": {
@@ -382,5 +400,7 @@ export const defaultStyle = {
382
400
  T_i: { "fo:font-style": "italic" },
383
401
  T_bi: { "fo:font-weight": "bold", "fo:font-style": "italic" },
384
402
  T_code: mono,
403
+ /** Highlighted section in the hierarchy box of a section slide. */
404
+ T_section: { "fo:font-weight": "bold", "fo:color": "{colors.sectionHighlight}" },
385
405
  },
386
406
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolokoban/impress",
3
- "version": "0.13.0",
3
+ "version": "0.16.0",
4
4
  "description": "Convert teaching markdown files into LibreOffice Impress presentations (.odp)",
5
5
  "type": "module",
6
6
  "bin": {