@tolokoban/impress 0.3.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
@@ -8,12 +8,38 @@ npx @tolokoban/impress course.md [other.md ...]
8
8
 
9
9
  Each `foo.md` produces `foo.odp` in the same folder. Run it without arguments to see the help.
10
10
 
11
+ `@graph` diagrams are laid out by the [Graphviz](https://graphviz.org/) `dot` tool. When a file uses `@graph` and `dot` is not installed, `impress` offers to install it with the package manager of the system:
12
+
13
+ | System | Command |
14
+ | --- | --- |
15
+ | Linux | `apt-get`, `dnf`, `yum`, `pacman`, `zypper`, `apk` or `brew` (with `sudo` when needed) |
16
+ | macOS | `brew install graphviz` or `sudo port install graphviz` |
17
+ | Windows | `winget install Graphviz.Graphviz`, `choco install graphviz` or `scoop install graphviz` |
18
+
19
+ Without a known package manager (or in a non-interactive shell), it prints how to install it instead, and the presentations using `@graph` fail.
20
+
21
+ Each time `dot` renders a diagram, the exact command is printed after a bold cyan `>`, so you can run it yourself to check the PNG:
22
+
23
+ ```
24
+ > /usr/bin/dot -Tpng -Gdpi=300 -Gbgcolor=transparent "-Gfontname=Liberation Sans" … diagram.dot
25
+ ```
26
+
27
+ In a terminal, the output is colored: file names in bold, the example of AI prompt (printed when the files contain `@hint` pragmas) in cyan, and the questions waiting for an answer in bright yellow. Set the `NO_COLOR` environment variable (or redirect the output) to disable the colors.
28
+
11
29
  ## Slides
12
30
 
13
31
  - `#` headings become section slides (blue background).
14
- - Deeper headings become content slides, split over several slides when they are too long.
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.
15
35
  - Paragraphs, lists, tables, blockquotes and images are laid out automatically: images go beside or below the text depending on their shape.
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)).
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.
38
+ - Every image embedded in the `.odp` (PNG, JPEG, SVG, `@graph` diagrams, background images) is converted to WebP, at quality 70 by default (see [`theme.images`](#themeimages)). The `.odp` stays light, and SVG files look in the slides as they do in a browser, since they are rasterized before LibreOffice sees them.
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)).
40
+ - Blockquotes (`> ...`) are shown in a bordered box with a soft blurred shadow.
16
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`).
17
43
 
18
44
  ## Pragmas
19
45
 
@@ -26,8 +52,12 @@ At the start of a line in the `.md` file:
26
52
  | `@hint <text>` | Instruction for an AI: stored verbatim in the `.odp` (alt-text of the slide title), never displayed. |
27
53
  | `@layout grid <C>x<R>` | Put the next C×R sections (starting at the next heading) on one slide, in a grid. |
28
54
  | `@layout columns <sizes>` | Put the next sections on one slide, in columns sized `1fr`, `2fr`… or `auto` (one size per section). |
29
- | `@graph <file.dot>` | Insert a Graphviz diagram (path relative to the `.md`) as native shapes, editable in Impress without the `.dot` file. |
55
+ | `@layout …` *(not followed by a heading)* | Put the next blocks of the section (paragraph, list, image, table…) on one slide, one block per cell, without cell headings. |
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. |
30
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. |
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. |
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. |
31
61
 
32
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`.
33
63
 
@@ -71,8 +101,9 @@ The theme gathers the values that are used in several places. Changing it is the
71
101
  | `primary` | `#1F3A5F` | Slide titles, section background, table headers, quote text and border, diagram node borders. |
72
102
  | `accent` | `#E8833A` | Left bar of content slides, line under section titles, bullets. |
73
103
  | `ink` | `#222222` | Body text, code, diagram edges. |
74
- | `muted` | `#7A8899` | Breadcrumb, prompt shadow, diagram clusters. |
75
- | `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`). |
76
107
  | `white` | `#FFFFFF` | Section titles, table header text, table cells. |
77
108
  | `quoteBackground` | `#F1F4F8` | Blockquotes. |
78
109
  | `promptBackground` | `#DCEBFF` | ` ```prompt ` chat bubbles. |
@@ -116,7 +147,7 @@ Font sizes, in points. They are not only applied to the text: they are also used
116
147
  | --- | --- | --- |
117
148
  | `title` | 34 | Title of content slides. |
118
149
  | `sectionTitle` | 44 | Title of section slides (`#` headings). |
119
- | `subtitle` | 20 | Breadcrumb under a section title. |
150
+ | `subtitle` | 20 | Hierarchy box of section slides. |
120
151
  | `breadcrumb` | 14 | Breadcrumb above the title of content slides. |
121
152
  | `text` | 24 | Paragraphs. |
122
153
  | `list` | `[24, 21, 18, …]` | List items, one size per level (9 levels). |
@@ -138,7 +169,7 @@ Text boxes shrink their text when it does not fit (`style:shrink-to-fit`), so a
138
169
  Geometry, in centimeters.
139
170
 
140
171
  - `slide`: `width` and `height` of the slides (default 28 × 15.75, i.e. 16:9). For 4:3, use for instance 28 × 21 and adapt `content`.
141
- - `content`: the area that receives the content of the slides, below the title: `x`, `y`, `width`, `height`, and the vertical `gap` between two blocks.
172
+ - `content`: the area that receives the content of the slides, below the title: `x`, `y`, `width`, `height`, and the vertical `gap` between two blocks. `align` places the content vertically in this area: `"top"` (default) or `"center"`. With `"center"`, a slide holding only a few bullets has them in the middle of the slide instead of at the top (a wide image under the text still fills the remaining height).
142
173
 
143
174
  The title, the breadcrumb and the decorations of the master pages have fixed positions (title at 0.95 cm from the top, line at 2.7 cm), section slides assume a slide about 28 cm wide, and the slide background is always white (change it in LibreOffice with _Slide › Slide Properties › Background_ on each master slide).
144
175
 
@@ -146,8 +177,17 @@ The title, the breadcrumb and the decorations of the master pages have fixed pos
146
177
 
147
178
  Options for `@graph` diagrams.
148
179
 
149
- - `connector`: shape of the edges, `"curve"` (default), `"line"` (straight), `"standard"` (right angles) or `"lines"` (several straight segments).
150
- - `maxScale`: maximum enlargement of a diagram relative to its Graphviz size (default 1.5). Small diagrams are not blown up, since the text would keep its size while the shapes grow.
180
+ - `maxScale`: maximum enlargement of a diagram relative to its Graphviz size (default 1.5). Small diagrams are not blown up, so their text does not become huge.
181
+ - `dpi`: resolution of the PNG rendered by Graphviz (default 300). Do not set `dpi` in the `.dot` file: the size of the diagram on the slide is computed from this one.
182
+
183
+ #### `theme.images`
184
+
185
+ Every embedded image is stored as WebP.
186
+
187
+ - `quality`: WebP quality, from 0 to 100 (default 70).
188
+ - `maxSize`: longest side in pixels (default 3840): larger images are shrunk. SVG images are rasterized at this size.
189
+
190
+ A WebP image already within `maxSize` is embedded as is, so it does not lose quality twice.
151
191
 
152
192
  #### `theme.backgrounds`
153
193
 
@@ -170,7 +210,7 @@ LibreOffice ignores image adjustments inherited from a named style, so they are
170
210
 
171
211
  ### Placeholders
172
212
 
173
- Any string value of `styles`, `spanStyles`, `markers`, `dashes` or `bullets` can reference the theme with `{path}`, where `path` is a dot-separated path in `theme` (array indexes are numbers):
213
+ Any string value of `styles`, `spanStyles`, `markers`, `dashes`, `bullets` or `numbers` can reference the theme with `{path}`, where `path` is a dot-separated path in `theme` (array indexes are numbers):
174
214
 
175
215
  ```json
176
216
  "fo:color": "{colors.primary}"
@@ -204,6 +244,7 @@ Each entry of `styles` is one named style:
204
244
  | `paragraph` | Properties of the paragraphs: alignment, margins, line height… |
205
245
  | `text` | Properties of the characters: font, size, weight, style, color… |
206
246
  | `bullets` | Bullets of lists (only for styles that hold lists, see below). |
247
+ | `numbers` | Numbers of numbered lists (only for styles that hold lists, see below). |
207
248
 
208
249
  Since styles inherit from each other, changing a parent changes all its children. For instance every drawing style derives from `standard`, and `Code` derives from `Prompt`.
209
250
 
@@ -221,6 +262,7 @@ Since styles inherit from each other, changing a parent changes all its children
221
262
  | `Prompt` | ` ```prompt ` code blocks (chat bubbles). |
222
263
  | `Code` | Other code blocks. |
223
264
  | `Image` | Frame of images. |
265
+ | `Separateur` | Horizontal rules (`----`). |
224
266
  | `Tableau-cadre` | Frame around tables. |
225
267
  | `Decor` | Vertical bar on the left of the slide. |
226
268
  | `Master-image` | Background image (`theme.backgrounds.Master`). |
@@ -231,8 +273,8 @@ Since styles inherit from each other, changing a parent changes all its children
231
273
 
232
274
  | Style | Element |
233
275
  | --- | --- |
234
- | `Section-title` | Title. |
235
- | `Section-subtitle` | Breadcrumb under the title. |
276
+ | `Section-title` | Title: always the `#` heading. |
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). |
236
278
  | `Section-fond` | Full-slide background rectangle. |
237
279
  | `Section-image` | Background image (`theme.backgrounds.Section`), above `Section-fond`. |
238
280
  | `Decor` | Horizontal bar under the title. |
@@ -255,19 +297,6 @@ Cell borders are a `paragraph` property (`fo:border`) and padding a `graphic` pr
255
297
 
256
298
  **`@layout grid`:** `Grille-titre` and `Grille-texte` hold the common properties; `Grille-titre-1…4` and `Grille-texte-1…4` only add the colors of each cell, taken from `theme.colors.grid`.
257
299
 
258
- **`@graph` diagrams:**
259
-
260
- | Style | Element |
261
- | --- | --- |
262
- | `Graphe-noeud` | Nodes. |
263
- | `Graphe-texte` | Nodes without border (`shape=plaintext`, `none`, `plain`, `underline` or `style=invis`). |
264
- | `Graphe-titre` | Label of the graph (`graph [label="…"]`). |
265
- | `Graphe-groupe` | Clusters (`subgraph cluster_…`). |
266
- | `Graphe-lien` | Directed edges (arrow at the end). |
267
- | `Graphe-lien-simple` | Edges without arrow (undirected graphs, `dir=none`). |
268
- | `Graphe-lien-double` | Edges with `dir=both`. |
269
-
270
- Colors and font sizes set in the `.dot` file (`color`, `fillcolor`, `fontcolor`, `fontsize`, `style=filled`, `style=dashed`…) win over the styles: they become automatic styles derived from the named ones.
271
300
 
272
301
  #### Common properties
273
302
 
@@ -329,6 +358,30 @@ Styles that hold lists (`Master-outline1`, `Colonne-texte`, `Grille-texte`) have
329
358
 
330
359
  Nested list items use the level of `chars` matching their depth: `Master-outline2…9` do not need a `bullets` entry of their own.
331
360
 
361
+ #### Numbers
362
+
363
+ The same styles have a `numbers` entry, used by numbered lists (`1. item`):
364
+
365
+ ```json
366
+ "numbers": {
367
+ "formats": ["1", "a", "i", "1", "a", "i", "1", "a", "i"],
368
+ "suffix": ".",
369
+ "color": "{colors.accent}",
370
+ "size": "100%",
371
+ "weight": "bold",
372
+ "indent": 0.9,
373
+ "width": 0.9
374
+ }
375
+ ```
376
+
377
+ - `formats`: numbering of each level, from 1 to 9: `"1"` (1, 2, 3…), `"a"` / `"A"` (letters), `"i"` / `"I"` (roman numerals).
378
+ - `suffix`: text after the number. It applies to every item, so `1)` in the markdown is shown as `1.` with the default suffix.
379
+ - `color`, `size`, `weight` (`"bold"` or `"normal"`): look of the numbers.
380
+ - `indent`: indentation added at each level, in cm.
381
+ - `width`: room left for the number before the text, in cm.
382
+
383
+ A list holding numbered items is written with two named list styles, `<style>-numbers` and `<style>-bullets` (e.g. `Master-outline1-numbers`), built from `numbers` and `bullets`, so bullets nested in a numbered list (and the reverse) keep their own look. Lists with bullets only keep using the bullets of the frame style. Styles that only inherit lists (`Grille-texte-1…4`) use the entries of their parent.
384
+
332
385
  ### Table templates
333
386
 
334
387
  `tableTemplates` tells LibreOffice which cell style each part of a table uses. There are two templates, `Tableau` and `Tableau-petit`:
@@ -349,6 +402,7 @@ Impress has no character styles, so inline formatting is defined in `spanStyles`
349
402
  | `T_i` | `*italic*` |
350
403
  | `T_bi` | `***bold italic***` |
351
404
  | `T_code` | `` `code` `` |
405
+ | `T_section` | Highlighted section in the hierarchy box of a section slide. |
352
406
 
353
407
  For instance, to show inline code in color on a light background:
354
408
 
@@ -406,4 +460,4 @@ npm run build # transpile src/*.ts into dist/
406
460
  npm run pub # build and publish to npmjs
407
461
  ```
408
462
 
409
- Requires Node.js 20.15 or later. Graphviz is bundled as WebAssembly (`@hpcc-js/wasm-graphviz`): nothing else to install.
463
+ Requires Node.js 20.15 or later. Images are converted with [sharp](https://sharp.pixelplumbing.com/), installed by npm with prebuilt binaries.