@tolokoban/impress 0.0.0-stage → 0.3.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
@@ -1,3 +1,409 @@
1
- # Temporary Holding Version
1
+ # @tolokoban/impress
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Convert markdown files into LibreOffice Impress presentations (`.odp`).
4
+
5
+ ```sh
6
+ npx @tolokoban/impress course.md [other.md ...]
7
+ ```
8
+
9
+ Each `foo.md` produces `foo.odp` in the same folder. Run it without arguments to see the help.
10
+
11
+ ## Slides
12
+
13
+ - `#` headings become section slides (blue background).
14
+ - Deeper headings become content slides, split over several slides when they are too long.
15
+ - Paragraphs, lists, tables, blockquotes and images are laid out automatically: images go beside or below the text depending on their shape.
16
+ - A code block whose language is `prompt` is shown as a chat bubble.
17
+
18
+ ## Pragmas
19
+
20
+ At the start of a line in the `.md` file:
21
+
22
+ | Pragma | Effect |
23
+ | --- | --- |
24
+ | `@note <text>` | Speaker note of the current slide (seen by the teacher only). |
25
+ | `@note begin` … `@note end` | Multi-line speaker note. |
26
+ | `@hint <text>` | Instruction for an AI: stored verbatim in the `.odp` (alt-text of the slide title), never displayed. |
27
+ | `@layout grid <C>x<R>` | Put the next C×R sections (starting at the next heading) on one slide, in a grid. |
28
+ | `@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. |
30
+ | `@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. |
31
+
32
+ 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
+
34
+ ## Styles
35
+
36
+ Every element of the slides uses a named style, so it can also be changed afterwards in LibreOffice (Styles sidebar: _Drawing Styles_ and _Presentation Styles_).
37
+
38
+ The first conversion of `foo.md` writes `foo.style.json` with the complete default style. Edit it and run again to restyle the presentation. The file is never overwritten: delete it to get the defaults back (for instance after upgrading `@tolokoban/impress`).
39
+
40
+ ### Merging with the defaults
41
+
42
+ `foo.style.json` is merged over the built-in defaults:
43
+
44
+ - objects are merged key by key, so the file can contain only the values you want to change;
45
+ - arrays and plain values replace the default ones entirely (e.g. `theme.colors.grid`, `bullets.chars`);
46
+ - default styles cannot be removed, only overridden. Unknown keys are kept, which is how you add new styles, markers or dashes.
47
+
48
+ ```json
49
+ { "theme": { "colors": { "primary": "#800020" } } }
50
+ ```
51
+
52
+ The file has six top-level sections:
53
+
54
+ | Key | Content |
55
+ | --- | --- |
56
+ | `theme` | Colors, fonts, font sizes, slide geometry and diagram options. |
57
+ | `styles` | Every named style, with ODF properties. |
58
+ | `tableTemplates` | Which cell styles a table uses for its header, body and banded rows. |
59
+ | `spanStyles` | Inline formatting: bold, italic, code. |
60
+ | `markers` | Line ends (arrows) used by diagram edges. |
61
+ | `dashes` | Dash patterns used by diagram edges and shapes. |
62
+
63
+ ### Theme
64
+
65
+ The theme gathers the values that are used in several places. Changing it is the easiest way to restyle a whole presentation.
66
+
67
+ #### `theme.colors`
68
+
69
+ | Key | Default | Used by |
70
+ | --- | --- | --- |
71
+ | `primary` | `#1F3A5F` | Slide titles, section background, table headers, quote text and border, diagram node borders. |
72
+ | `accent` | `#E8833A` | Left bar of content slides, line under section titles, bullets. |
73
+ | `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. |
76
+ | `white` | `#FFFFFF` | Section titles, table header text, table cells. |
77
+ | `quoteBackground` | `#F1F4F8` | Blockquotes. |
78
+ | `promptBackground` | `#DCEBFF` | ` ```prompt ` chat bubbles. |
79
+ | `promptInk` | `#0B2545` | Text of chat bubbles. |
80
+ | `codeBackground` | `#F3F3F3` | Other code blocks. |
81
+ | `tableBorder` | `#C9D3DF` | Table cell borders. |
82
+ | `tableBand` | `#EEF2F7` | Every other table row. |
83
+ | `gridBackground` | `#F7F7F7` | Body of the cells of `@layout grid`. |
84
+ | `graphNode` | `#EAF1FB` | `@graph` node background. |
85
+ | `graphCluster` | `#F5F7FA` | `@graph` cluster (subgraph) background. |
86
+ | `grid` | 4 pairs | `[background, text]` of each `@layout grid` cell heading, used in turn (cell 5 reuses the colors of cell 1). |
87
+
88
+ You can add your own colors to the theme and reference them in styles, e.g. `"draw:fill-color": "{colors.myGreen}"`.
89
+
90
+ To change the number of colors in `grid`, also add (or keep) the matching styles: the cell `n` of a grid uses `Grille-titre-n` and `Grille-texte-n`, and the defaults only define 1 to 4. For a fifth color:
91
+
92
+ ```json
93
+ {
94
+ "theme": { "colors": { "grid": [["#C0392B", "#FFFFFF"], ["#E67E22", "#FFFFFF"], ["#F1C40F", "#222222"], ["#27AE60", "#FFFFFF"], ["#8E44AD", "#FFFFFF"]] } },
95
+ "styles": {
96
+ "Grille-titre-5": { "family": "graphic", "parent": "Grille-titre", "graphic": { "draw:fill-color": "{colors.grid.4.0}" }, "text": { "fo:color": "{colors.grid.4.1}" } },
97
+ "Grille-texte-5": { "family": "graphic", "parent": "Grille-texte", "graphic": { "svg:stroke-color": "{colors.grid.4.0}" } }
98
+ }
99
+ }
100
+ ```
101
+
102
+ #### `theme.fonts`
103
+
104
+ | Key | Default | Used by |
105
+ | --- | --- | --- |
106
+ | `sans` | `'Liberation Sans'` | All the text, and the Graphviz layout of `@graph` diagrams. |
107
+ | `mono` | `'DejaVu Sans Mono'` | Code blocks and inline `` `code` ``. |
108
+
109
+ Use the font name as LibreOffice knows it, with quotes when it contains spaces. The font must be installed on the computer that opens the `.odp`.
110
+
111
+ #### `theme.sizes`
112
+
113
+ Font sizes, in points. They are not only applied to the text: they are also used to **estimate the height of the text** when laying out slides and deciding where to split a section over several slides. So prefer changing a size here rather than `fo:font-size` in a style, otherwise the layout will not match the text.
114
+
115
+ | Key | Default | Used by |
116
+ | --- | --- | --- |
117
+ | `title` | 34 | Title of content slides. |
118
+ | `sectionTitle` | 44 | Title of section slides (`#` headings). |
119
+ | `subtitle` | 20 | Breadcrumb under a section title. |
120
+ | `breadcrumb` | 14 | Breadcrumb above the title of content slides. |
121
+ | `text` | 24 | Paragraphs. |
122
+ | `list` | `[24, 21, 18, …]` | List items, one size per level (9 levels). |
123
+ | `quote` | 24 | Blockquotes. |
124
+ | `prompt` | 20 | Chat bubbles. |
125
+ | `code` | 14 | Code blocks. |
126
+ | `table` | 18 | Tables on a content slide. |
127
+ | `tableSmall` | 11 | Tables inside a `@layout` cell or column. |
128
+ | `columnTitle`, `columnText` | 16, 16 | Headings and content of `@layout columns`. |
129
+ | `gridTitle`, `gridText` | 16, 12 | Headings and content of `@layout grid`. |
130
+ | `notes` | 14 | Speaker notes. |
131
+ | `graphText` | 14 | `@graph` node labels (unless the `.dot` sets `fontsize`). |
132
+ | `graphEdgeText` | 12 | `@graph` edge, cluster and graph labels. |
133
+
134
+ Text boxes shrink their text when it does not fit (`style:shrink-to-fit`), so a too optimistic estimate only makes the text smaller.
135
+
136
+ #### `theme.slide` and `theme.content`
137
+
138
+ Geometry, in centimeters.
139
+
140
+ - `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.
142
+
143
+ 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
+
145
+ #### `theme.graph`
146
+
147
+ Options for `@graph` diagrams.
148
+
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.
151
+
152
+ #### `theme.backgrounds`
153
+
154
+ An image for each master page (`Master` for content slides, `Section` for section slides), drawn above the background color and below the decorations and the text.
155
+
156
+ - `image`: path relative to the markdown file, `""` (default) for no image.
157
+ - `fit`: `"stretch"` (default) fills the area, `"contain"` keeps the aspect ratio and centers the image in the area.
158
+ - `x`, `y`, `width`, `height`: the area in centimeters (default: the whole slide).
159
+
160
+ The look of the image comes from the `Master-image` and `Section-image` styles: `draw:image-opacity`, `draw:color-mode` (`standard`, `greyscale`, `mono` or `watermark`), `draw:luminance`, `draw:contrast`, `draw:gamma`, `draw:red`, `draw:green`, `draw:blue`...
161
+
162
+ ```json
163
+ {
164
+ "theme": { "backgrounds": { "Section": { "image": "images/city.jpg" } } },
165
+ "styles": { "Section-image": { "graphic": { "draw:image-opacity": "25%", "draw:color-mode": "greyscale" } } }
166
+ }
167
+ ```
168
+
169
+ LibreOffice ignores image adjustments inherited from a named style, so they are also written to an automatic style on each image: change them in `foo.style.json` rather than in LibreOffice's Styles sidebar.
170
+
171
+ ### Placeholders
172
+
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):
174
+
175
+ ```json
176
+ "fo:color": "{colors.primary}"
177
+ "fo:font-size": "{sizes.title}pt"
178
+ "fo:font-size": "{sizes.list.2}pt"
179
+ "draw:fill-color": "{colors.grid.0.0}"
180
+ "fo:border": "0.03cm solid {colors.tableBorder}"
181
+ ```
182
+
183
+ A placeholder can be part of a longer value. An unknown path stops the conversion with an error naming the faulty style.
184
+
185
+ ### Named styles
186
+
187
+ Each entry of `styles` is one named style:
188
+
189
+ ```json
190
+ "Citation": {
191
+ "family": "graphic",
192
+ "parent": "standard",
193
+ "graphic": { "draw:fill-color": "{colors.quoteBackground}" },
194
+ "paragraph": { "fo:line-height": "115%" },
195
+ "text": { "fo:font-style": "italic", "fo:color": "{colors.primary}" }
196
+ }
197
+ ```
198
+
199
+ | Key | Meaning |
200
+ | --- | --- |
201
+ | `family` | `graphic` (drawing style), `presentation` (master page placeholders) or `table-cell`. Do not change it for an existing style. |
202
+ | `parent` | Style to inherit from: only the differences need to be given. |
203
+ | `graphic` | Properties of the shape: fill, border, shadow, padding, text alignment in the box… |
204
+ | `paragraph` | Properties of the paragraphs: alignment, margins, line height… |
205
+ | `text` | Properties of the characters: font, size, weight, style, color… |
206
+ | `bullets` | Bullets of lists (only for styles that hold lists, see below). |
207
+
208
+ 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
+
210
+ #### Where each style is used
211
+
212
+ **Content slides** (master page `Master`):
213
+
214
+ | Style | Element |
215
+ | --- | --- |
216
+ | `Master-title` | Slide title. |
217
+ | `Fil-ariane` | Breadcrumb (parent headings) above the title. |
218
+ | `Master-outline1` … `Master-outline9` | Lists, one style per level (each level inherits from the previous one). |
219
+ | `Texte` | Paragraphs. |
220
+ | `Citation` | Blockquotes. |
221
+ | `Prompt` | ` ```prompt ` code blocks (chat bubbles). |
222
+ | `Code` | Other code blocks. |
223
+ | `Image` | Frame of images. |
224
+ | `Tableau-cadre` | Frame around tables. |
225
+ | `Decor` | Vertical bar on the left of the slide. |
226
+ | `Master-image` | Background image (`theme.backgrounds.Master`). |
227
+ | `Decor-ligne` | Line under the title. |
228
+ | `Master-notes` | Speaker notes. |
229
+
230
+ **Section slides** (master page `Section`, for `#` headings):
231
+
232
+ | Style | Element |
233
+ | --- | --- |
234
+ | `Section-title` | Title. |
235
+ | `Section-subtitle` | Breadcrumb under the title. |
236
+ | `Section-fond` | Full-slide background rectangle. |
237
+ | `Section-image` | Background image (`theme.backgrounds.Section`), above `Section-fond`. |
238
+ | `Decor` | Horizontal bar under the title. |
239
+ | `Section-notes` | Speaker notes. |
240
+
241
+ `Section-outline1…9`, `Master-subtitle`, `*-background` and `*-backgroundobjects` exist for LibreOffice's master pages but are not used by the generated content.
242
+
243
+ **Tables:**
244
+
245
+ | Style | Element |
246
+ | --- | --- |
247
+ | `Tableau-entete` | Header row. |
248
+ | `Tableau-cellule` | Body cells. |
249
+ | `Tableau-cellule-alt` | Every other body row. |
250
+ | `Tableau-petit-entete`, `Tableau-petit-cellule`, `Tableau-petit-cellule-alt` | Same, for tables inside a `@layout` cell or column. |
251
+
252
+ Cell borders are a `paragraph` property (`fo:border`) and padding a `graphic` property (`fo:padding-*`).
253
+
254
+ **`@layout columns`:** `Colonne-titre` (heading of each column) and `Colonne-texte` (its content, with bullets).
255
+
256
+ **`@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
+
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
+
272
+ #### Common properties
273
+
274
+ Property names are the ODF attribute names, as LibreOffice writes them in its own files. Lengths need a unit (`cm`, `mm`, `in`, `pt`), colors are `#RRGGBB`. The most useful ones:
275
+
276
+ | Group | Property | Example values |
277
+ | --- | --- | --- |
278
+ | `text` | `fo:font-family` | `"{fonts.sans}"`, `"'Open Sans'"` |
279
+ | `text` | `fo:font-size` | `"{sizes.text}pt"`, `"18pt"` |
280
+ | `text` | `fo:font-weight` | `bold`, `normal` |
281
+ | `text` | `fo:font-style` | `italic`, `normal` |
282
+ | `text` | `fo:color` | `"#222222"` |
283
+ | `text` | `style:text-underline-style` | `solid`, `none` |
284
+ | `text` | `fo:text-transform` | `uppercase`, `none` |
285
+ | `text` | `fo:letter-spacing` | `0.05cm`, `normal` |
286
+ | `text` | `fo:text-shadow` | `1pt 1pt`, `none` |
287
+ | `paragraph` | `fo:text-align` | `start`, `center`, `end`, `justify` |
288
+ | `paragraph` | `fo:line-height` | `110%`, `0.8cm` |
289
+ | `paragraph` | `fo:margin-top`, `fo:margin-bottom` | `0.2cm` |
290
+ | `paragraph` | `fo:margin-left`, `fo:text-indent` | `0.5cm`, `-0.5cm` |
291
+ | `paragraph` | `fo:border` | `0.03cm solid #C9D3DF` (table cells) |
292
+ | `graphic` | `draw:fill` | `none`, `solid`, `gradient`, `hatch` |
293
+ | `graphic` | `draw:fill-color` | `"{colors.primary}"` |
294
+ | `graphic` | `draw:opacity` | `80%` |
295
+ | `graphic` | `draw:stroke` | `none`, `solid`, `dash` |
296
+ | `graphic` | `svg:stroke-color`, `svg:stroke-width` | `"#1F3A5F"`, `0.03cm` |
297
+ | `graphic` | `draw:stroke-dash` | name of an entry of `dashes`, e.g. `Tirets` (with `draw:stroke` = `dash`) |
298
+ | `graphic` | `draw:marker-start`, `draw:marker-end` | name of an entry of `markers`, e.g. `Fleche` |
299
+ | `graphic` | `draw:marker-start-width`, `draw:marker-end-width` | `0.3cm` |
300
+ | `graphic` | `draw:shadow` | `visible`, `hidden` |
301
+ | `graphic` | `draw:shadow-offset-x`, `draw:shadow-offset-y` | `0.08cm` |
302
+ | `graphic` | `draw:shadow-color`, `draw:shadow-opacity` | `"{colors.muted}"`, `35%` |
303
+ | `graphic` | `fo:padding-left`, `-right`, `-top`, `-bottom` | `0.3cm` |
304
+ | `graphic` | `draw:textarea-vertical-align` | `top`, `middle`, `bottom` |
305
+ | `graphic` | `draw:textarea-horizontal-align` | `left`, `center`, `right`, `justify` |
306
+ | `graphic` | `style:shrink-to-fit` | `true`: shrink the text that does not fit in its box |
307
+
308
+ Any other ODF property is written as is. If LibreOffice does not know it, it is ignored silently: when in doubt, set the property in LibreOffice, save as `.fodp` (flat XML) and look at the attribute it writes.
309
+
310
+ Two properties are on purpose on most text styles and are best kept: `style:shrink-to-fit` (`true`) and `draw:auto-grow-height` (`false`). Without them, a text that is longer than estimated overflows its box instead of being shrunk.
311
+
312
+ #### Bullets
313
+
314
+ Styles that hold lists (`Master-outline1`, `Colonne-texte`, `Grille-texte`) have a `bullets` entry:
315
+
316
+ ```json
317
+ "bullets": {
318
+ "chars": ["●", "–", "●", "–", "●", "–", "●", "–", "●"],
319
+ "color": "{colors.accent}",
320
+ "indent": 0.9,
321
+ "size": "80%"
322
+ }
323
+ ```
324
+
325
+ - `chars`: bullet character of each level, from 1 to 9 (drawn with the _OpenSymbol_ font, so `■`, `▸`, `✓`, `→`… work too).
326
+ - `color`: color of the bullets.
327
+ - `indent`: indentation added at each level, in cm (a number, not a string).
328
+ - `size`: size of the bullet relative to the text.
329
+
330
+ Nested list items use the level of `chars` matching their depth: `Master-outline2…9` do not need a `bullets` entry of their own.
331
+
332
+ ### Table templates
333
+
334
+ `tableTemplates` tells LibreOffice which cell style each part of a table uses. There are two templates, `Tableau` and `Tableau-petit`:
335
+
336
+ ```json
337
+ { "name": "Tableau", "header": "Tableau-entete", "body": "Tableau-cellule", "bandedRows": "Tableau-cellule-alt" }
338
+ ```
339
+
340
+ To remove the banding, point `bandedRows` to the same style as `body` (or give both styles the same fill color).
341
+
342
+ ### Inline formatting
343
+
344
+ Impress has no character styles, so inline formatting is defined in `spanStyles`, with `text` properties only:
345
+
346
+ | Style | Markdown |
347
+ | --- | --- |
348
+ | `T_b` | `**bold**` |
349
+ | `T_i` | `*italic*` |
350
+ | `T_bi` | `***bold italic***` |
351
+ | `T_code` | `` `code` `` |
352
+
353
+ For instance, to show inline code in color on a light background:
354
+
355
+ ```json
356
+ { "spanStyles": { "T_code": { "fo:font-family": "{fonts.mono}", "fo:color": "{colors.accent}", "fo:background-color": "#F3F3F3" } } }
357
+ ```
358
+
359
+ Like everything else, span styles are merged with the defaults: here `T_code` keeps its font family even if it is omitted.
360
+
361
+ ### Markers and dashes
362
+
363
+ `markers` defines line ends, referenced by name in `draw:marker-start` / `draw:marker-end`. Each one is an SVG path with its `viewBox`; the tip of the arrow points to the top of the view box:
364
+
365
+ ```json
366
+ "markers": {
367
+ "Fleche": { "viewBox": "0 0 20 30", "d": "M10 0l-10 30h20z" },
368
+ "Rond": { "viewBox": "0 0 20 20", "d": "M10 0a10 10 0 1 0 0.01 0z" }
369
+ }
370
+ ```
371
+
372
+ `dashes` defines dash patterns, referenced by name in `draw:stroke-dash`, with the ODF attributes of `<draw:stroke-dash>`: `draw:style` (`rect` or `round`), `draw:dots1`, `draw:dots1-length`, `draw:dots2`, `draw:dots2-length` and `draw:distance`.
373
+
374
+ The **first** entry of `dashes` (`Tirets` by default) is used for `@graph` nodes and edges with `style=dashed` or `style=dotted`.
375
+
376
+ ### Recipes
377
+
378
+ Bigger text everywhere:
379
+
380
+ ```json
381
+ { "theme": { "sizes": { "text": 28, "list": [28, 24, 20, 20, 20, 20, 20, 20, 20], "title": 38 } } }
382
+ ```
383
+
384
+ Centered slide titles without the line:
385
+
386
+ ```json
387
+ {
388
+ "styles": {
389
+ "Master-title": { "paragraph": { "fo:text-align": "center" } },
390
+ "Decor-ligne": { "graphic": { "draw:stroke": "none" } }
391
+ }
392
+ }
393
+ ```
394
+
395
+ Chat bubbles without shadow:
396
+
397
+ ```json
398
+ { "styles": { "Prompt": { "graphic": { "draw:shadow": "hidden" } } } }
399
+ ```
400
+
401
+ ## Development
402
+
403
+ ```sh
404
+ npm install
405
+ npm run build # transpile src/*.ts into dist/
406
+ npm run pub # build and publish to npmjs
407
+ ```
408
+
409
+ Requires Node.js 20.15 or later. Graphviz is bundled as WebAssembly (`@hpcc-js/wasm-graphviz`): nothing else to install.