@tolokoban/impress 0.1.0 → 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
@@ -27,6 +27,7 @@ At the start of a line in the `.md` file:
27
27
  | `@layout grid <C>x<R>` | Put the next C×R sections (starting at the next heading) on one slide, in a grid. |
28
28
  | `@layout columns <sizes>` | Put the next sections on one slide, in columns sized `1fr`, `2fr`… or `auto` (one size per section). |
29
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. |
30
31
 
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`.
32
33
 
@@ -148,6 +149,25 @@ Options for `@graph` diagrams.
148
149
  - `connector`: shape of the edges, `"curve"` (default), `"line"` (straight), `"standard"` (right angles) or `"lines"` (several straight segments).
149
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.
150
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
+
151
171
  ### Placeholders
152
172
 
153
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):
@@ -189,13 +209,13 @@ Since styles inherit from each other, changing a parent changes all its children
189
209
 
190
210
  #### Where each style is used
191
211
 
192
- **Content slides** (master page `Greta`):
212
+ **Content slides** (master page `Master`):
193
213
 
194
214
  | Style | Element |
195
215
  | --- | --- |
196
- | `Greta-title` | Slide title. |
216
+ | `Master-title` | Slide title. |
197
217
  | `Fil-ariane` | Breadcrumb (parent headings) above the title. |
198
- | `Greta-outline1` … `Greta-outline9` | Lists, one style per level (each level inherits from the previous one). |
218
+ | `Master-outline1` … `Master-outline9` | Lists, one style per level (each level inherits from the previous one). |
199
219
  | `Texte` | Paragraphs. |
200
220
  | `Citation` | Blockquotes. |
201
221
  | `Prompt` | ` ```prompt ` code blocks (chat bubbles). |
@@ -203,8 +223,9 @@ Since styles inherit from each other, changing a parent changes all its children
203
223
  | `Image` | Frame of images. |
204
224
  | `Tableau-cadre` | Frame around tables. |
205
225
  | `Decor` | Vertical bar on the left of the slide. |
226
+ | `Master-image` | Background image (`theme.backgrounds.Master`). |
206
227
  | `Decor-ligne` | Line under the title. |
207
- | `Greta-notes` | Speaker notes. |
228
+ | `Master-notes` | Speaker notes. |
208
229
 
209
230
  **Section slides** (master page `Section`, for `#` headings):
210
231
 
@@ -213,10 +234,11 @@ Since styles inherit from each other, changing a parent changes all its children
213
234
  | `Section-title` | Title. |
214
235
  | `Section-subtitle` | Breadcrumb under the title. |
215
236
  | `Section-fond` | Full-slide background rectangle. |
237
+ | `Section-image` | Background image (`theme.backgrounds.Section`), above `Section-fond`. |
216
238
  | `Decor` | Horizontal bar under the title. |
217
239
  | `Section-notes` | Speaker notes. |
218
240
 
219
- `Section-outline1…9`, `Greta-subtitle`, `*-background` and `*-backgroundobjects` exist for LibreOffice's master pages but are not used by the generated content.
241
+ `Section-outline1…9`, `Master-subtitle`, `*-background` and `*-backgroundobjects` exist for LibreOffice's master pages but are not used by the generated content.
220
242
 
221
243
  **Tables:**
222
244
 
@@ -289,7 +311,7 @@ Two properties are on purpose on most text styles and are best kept: `style:shri
289
311
 
290
312
  #### Bullets
291
313
 
292
- Styles that hold lists (`Greta-outline1`, `Colonne-texte`, `Grille-texte`) have a `bullets` entry:
314
+ Styles that hold lists (`Master-outline1`, `Colonne-texte`, `Grille-texte`) have a `bullets` entry:
293
315
 
294
316
  ```json
295
317
  "bullets": {
@@ -305,7 +327,7 @@ Styles that hold lists (`Greta-outline1`, `Colonne-texte`, `Grille-texte`) have
305
327
  - `indent`: indentation added at each level, in cm (a number, not a string).
306
328
  - `size`: size of the bullet relative to the text.
307
329
 
308
- Nested list items use the level of `chars` matching their depth: `Greta-outline2…9` do not need a `bullets` entry of their own.
330
+ Nested list items use the level of `chars` matching their depth: `Master-outline2…9` do not need a `bullets` entry of their own.
309
331
 
310
332
  ### Table templates
311
333
 
@@ -364,7 +386,7 @@ Centered slide titles without the line:
364
386
  ```json
365
387
  {
366
388
  "styles": {
367
- "Greta-title": { "paragraph": { "fo:text-align": "center" } },
389
+ "Master-title": { "paragraph": { "fo:text-align": "center" } },
368
390
  "Decor-ligne": { "graphic": { "draw:stroke": "none" } }
369
391
  }
370
392
  }
package/dist/impress.js CHANGED
@@ -19,6 +19,7 @@
19
19
  * the next 3 sections on one slide, in columns sized by
20
20
  * fractions of the free width or by their content (auto)
21
21
  * @graph diagram.dot Graphviz diagram converted into native, editable shapes
22
+ * @next start a new slide with the same title as the current one
22
23
  * ```prompt ... ``` chat prompt bubble
23
24
  */
24
25
  import { existsSync, readFileSync, writeFileSync, statSync } from "node:fs";
@@ -123,6 +124,8 @@ class Section {
123
124
  children = [];
124
125
  /** Set on the first section of a group laid out on a single slide. */
125
126
  layout = null;
127
+ /** Created by `@next`: continues the previous section on a new slide. */
128
+ continued = false;
126
129
  /** Folder of the markdown file, for relative image paths. */
127
130
  source;
128
131
  constructor(level, title, parent = null, source = "") {
@@ -196,6 +199,21 @@ function parse(md, file) {
196
199
  flush();
197
200
  layout = parseLayout(s.slice(7).trim(), `${file}:${i + 1}`);
198
201
  }
202
+ else if (s === "@next") {
203
+ flush();
204
+ // A heading right after `@next` starts the new slide by itself.
205
+ let j = i + 1;
206
+ while (j < lines.length && lines[j].trim() === "")
207
+ j++;
208
+ if (j < lines.length && HEAD_RE.test(lines[j]))
209
+ continue;
210
+ if (!cur.parent)
211
+ throw new Error(`${file}:${i + 1}: "@next" needs a previous heading`);
212
+ const sec = new Section(cur.level, cur.title, cur.parent, root.source);
213
+ sec.continued = true;
214
+ cur.parent.children.push(sec);
215
+ cur = sec;
216
+ }
199
217
  else if (s.startsWith("@graph")) {
200
218
  flush();
201
219
  const src = s.slice(6).trim();
@@ -860,7 +878,7 @@ class Builder {
860
878
  case "para":
861
879
  return this.frame("Texte", x, y, w, h, `<text:p>${runsXml(b.text)}</text:p>`);
862
880
  case "list":
863
- return this.frame("Greta-outline1", x, y, w, h, this.listXml(b.items), "outline");
881
+ return this.frame("Master-outline1", x, y, w, h, this.listXml(b.items), "outline");
864
882
  case "quote":
865
883
  return this.frame("Citation", x, y, w, h, `<text:p>${runsXml(b.text)}</text:p>`);
866
884
  case "prompt":
@@ -945,7 +963,7 @@ class Builder {
945
963
  const out = [];
946
964
  if (crumbs.length)
947
965
  out.push(this.frame("Fil-ariane", X0, 0.35, W, 0.6, `<text:p>${xmlText(crumbs.join(" › "))}</text:p>`));
948
- out.push(this.frame("Greta-title", X0, 0.95, W, 1.6, `<text:p>${xmlText(title)}</text:p>`, "title", this.takeHints()));
966
+ out.push(this.frame("Master-title", X0, 0.95, W, 1.6, `<text:p>${xmlText(title)}</text:p>`, "title", this.takeHints()));
949
967
  return out;
950
968
  }
951
969
  sectionPage(sec) {
@@ -959,7 +977,7 @@ class Builder {
959
977
  contentPages(title, crumbs, blocks) {
960
978
  for (const [content, notes] of this.paginate(blocks)) {
961
979
  const [, shapes] = this.layout(content);
962
- this.page("Greta", [...this.titleShapes(title, crumbs), ...shapes], notes);
980
+ this.page("Master", [...this.titleShapes(title, crumbs), ...shapes], notes);
963
981
  }
964
982
  }
965
983
  /** A table whose rows appear one slide after the other. */
@@ -1004,7 +1022,7 @@ class Builder {
1004
1022
  }
1005
1023
  }
1006
1024
  const notes = k === 0 ? sec.blocks.flatMap(b => (b.t === "note" ? [b.text] : [])) : [];
1007
- this.page("Greta", [...this.titleShapes(sec.title, crumbs), ...shapes], notes);
1025
+ this.page("Master", [...this.titleShapes(sec.title, crumbs), ...shapes], notes);
1008
1026
  }
1009
1027
  }
1010
1028
  /** Height of a group of paragraphs/lists rendered at `pt` points. */
@@ -1179,7 +1197,7 @@ class Builder {
1179
1197
  shapes.push(...this.cellXml(sec, x, y + headH, w, h - headH, textStyle, textPt));
1180
1198
  notes.push(...sec.blocks.flatMap(b => (b.t === "note" ? [b.text] : [])));
1181
1199
  });
1182
- this.page("Greta", shapes, notes);
1200
+ this.page("Master", shapes, notes);
1183
1201
  }
1184
1202
  walk(sec) {
1185
1203
  this.pendingHints.push(...sec.hints);
@@ -1187,7 +1205,7 @@ class Builder {
1187
1205
  const content = sec.blocks.filter(b => b.t !== "note");
1188
1206
  // A section whose only content is a grouped slide does not get its own divider slide.
1189
1207
  const groupedOnly = !content.length && sec.children[0]?.layout != null;
1190
- if (sec.level === 1) {
1208
+ if (sec.level === 1 && !sec.continued) {
1191
1209
  this.sectionPage(sec);
1192
1210
  if (content.length)
1193
1211
  this.contentPages(sec.title, [...crumbs, sec.title], sec.blocks);
@@ -1262,7 +1280,36 @@ function styleXml(name, s) {
1262
1280
  `<style:paragraph-properties ${attrs(s.paragraph, where)}/>` +
1263
1281
  `<style:text-properties ${attrs(s.text, where)}/></style:style>`);
1264
1282
  }
1265
- function stylesXml() {
1283
+ const backgroundStyle = (master) => `M${master}-image`;
1284
+ /**
1285
+ * LibreOffice ignores image adjustments (`draw:image-opacity`, `draw:color-mode`...) inherited
1286
+ * from a named style, so the master images get an automatic style repeating them.
1287
+ */
1288
+ function backgroundStyleXml(master) {
1289
+ const name = `${master}-image`;
1290
+ return (`<style:style style:name="${backgroundStyle(master)}" style:family="graphic" style:parent-style-name="${name}">` +
1291
+ `<style:graphic-properties ${attrs(style.styles[name]?.graphic, `style "${name}"`)}/></style:style>`);
1292
+ }
1293
+ /** Frame of the image of a master page (see `theme.backgrounds`), or "" if it has none. */
1294
+ function backgroundXml(b, master) {
1295
+ const bg = style.theme.backgrounds[master];
1296
+ if (!bg.image)
1297
+ return "";
1298
+ const { href, size } = b.picture(bg.image);
1299
+ let { x = 0, y = 0, width: w = SLIDE_W, height: h = SLIDE_H } = bg;
1300
+ if (bg.fit === "contain") {
1301
+ const scale = Math.min(w / size[0], h / size[1]);
1302
+ x += (w - size[0] * scale) / 2;
1303
+ y += (h - size[1] * scale) / 2;
1304
+ w = size[0] * scale;
1305
+ h = size[1] * scale;
1306
+ }
1307
+ const mime = href.endsWith(".svg") ? ' draw:mime-type="image/svg+xml"' : "";
1308
+ return (`<draw:frame draw:style-name="${backgroundStyle(master)}" ${Builder.geom(x, y, w, h)}>` +
1309
+ `<draw:image xlink:href="${esc(href)}" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"${mime}/>` +
1310
+ `</draw:frame>`);
1311
+ }
1312
+ function stylesXml(b) {
1266
1313
  const templates = style.tableTemplates.map(t => `<table:table-template table:name="${esc(t.name)}">` +
1267
1314
  `<table:first-row table:style-name="${esc(t.header)}"/>` +
1268
1315
  `<table:body table:style-name="${esc(t.body)}"/>` +
@@ -1276,6 +1323,8 @@ function stylesXml() {
1276
1323
  `<style:page-layout style:name="PM1"><style:page-layout-properties fo:margin-top="0cm" fo:margin-bottom="0cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:page-width="${SLIDE_W}cm" fo:page-height="${SLIDE_H}cm" style:print-orientation="landscape"/></style:page-layout>`,
1277
1324
  `<style:page-layout style:name="PM2"><style:page-layout-properties fo:margin-top="0cm" fo:margin-bottom="0cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:page-width="21cm" fo:page-height="29.7cm" style:print-orientation="portrait"/></style:page-layout>`,
1278
1325
  `<style:style style:name="Mdp1" style:family="drawing-page"><style:drawing-page-properties draw:background-size="full" draw:fill="solid" draw:fill-color="#FFFFFF"/></style:style>`,
1326
+ backgroundStyleXml("Master"),
1327
+ backgroundStyleXml("Section"),
1279
1328
  ];
1280
1329
  const notes = (m) => `<presentation:notes style:page-layout-name="PM2">` +
1281
1330
  `<draw:page-thumbnail presentation:style-name="${m}-title" presentation:class="page" svg:x="1.5cm" svg:y="1.5cm" svg:width="18cm" svg:height="10.13cm"/>` +
@@ -1283,14 +1332,16 @@ function stylesXml() {
1283
1332
  `</presentation:notes>`;
1284
1333
  const placeholder = (styleName, cls, x, y, w, h) => `<draw:frame presentation:style-name="${styleName}" presentation:class="${cls}" presentation:placeholder="true" ${Builder.geom(x, y, w, h)}><draw:text-box/></draw:frame>`;
1285
1334
  const masters = [
1286
- `<style:master-page style:name="Greta" style:page-layout-name="PM1" draw:style-name="Mdp1">` +
1335
+ `<style:master-page style:name="Master" style:page-layout-name="PM1" draw:style-name="Mdp1">` +
1336
+ backgroundXml(b, "Master") +
1287
1337
  `<draw:rect draw:style-name="Decor" ${Builder.geom(0, 0, 0.4, SLIDE_H)}/>` +
1288
1338
  `<draw:line draw:style-name="Decor-ligne" svg:x1="${X0}cm" svg:y1="2.7cm" svg:x2="${X0 + W}cm" svg:y2="2.7cm"/>` +
1289
- placeholder("Greta-title", "title", X0, 0.95, W, 1.6) +
1290
- placeholder("Greta-outline1", "outline", X0, Y0, W, H) +
1291
- `${notes("Greta")}</style:master-page>`,
1339
+ placeholder("Master-title", "title", X0, 0.95, W, 1.6) +
1340
+ placeholder("Master-outline1", "outline", X0, Y0, W, H) +
1341
+ `${notes("Master")}</style:master-page>`,
1292
1342
  `<style:master-page style:name="Section" style:page-layout-name="PM1" draw:style-name="Mdp1">` +
1293
1343
  `<draw:rect draw:style-name="Section-fond" ${Builder.geom(0, 0, SLIDE_W, SLIDE_H)}/>` +
1344
+ backgroundXml(b, "Section") +
1294
1345
  `<draw:rect draw:style-name="Decor" ${Builder.geom(0, 8.55, SLIDE_W, 0.12)}/>` +
1295
1346
  placeholder("Section-title", "title", 2, 5, 24, 3.5) +
1296
1347
  placeholder("Section-subtitle", "subtitle", 2, 8.8, 24, 1.5) +
@@ -1374,6 +1425,8 @@ function zip(entries) {
1374
1425
  return Buffer.concat([...locals, cd, end]);
1375
1426
  }
1376
1427
  function writeOdp(b, out, title) {
1428
+ // Before listing the pictures: the master pages can add some.
1429
+ const styles = stylesXml(b);
1377
1430
  const pics = [...b.pictures.values()];
1378
1431
  const manifest = '<?xml version="1.0" encoding="UTF-8"?><manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.3">' +
1379
1432
  '<manifest:file-entry manifest:full-path="/" manifest:media-type="application/vnd.oasis.opendocument.presentation"/>' +
@@ -1389,7 +1442,7 @@ function writeOdp(b, out, title) {
1389
1442
  { name: "mimetype", data: text("application/vnd.oasis.opendocument.presentation"), store: true },
1390
1443
  { name: "META-INF/manifest.xml", data: text(manifest) },
1391
1444
  { name: "meta.xml", data: text(meta) },
1392
- { name: "styles.xml", data: text(stylesXml()) },
1445
+ { name: "styles.xml", data: text(styles) },
1393
1446
  { name: "content.xml", data: text(contentXml(b)) },
1394
1447
  ...pics.map(p => ({ name: p.href, data: p.data, store: true })),
1395
1448
  ]));
@@ -1452,6 +1505,7 @@ const PRAGMAS = [
1452
1505
  ["@layout grid <C>x<R>", "Put the next C×R sections (starting at the next heading) on one slide, in a grid."],
1453
1506
  ["@layout columns <sizes>", 'Put the next sections on one slide, in columns sized "1fr", "2fr"... or "auto" (one size per section).'],
1454
1507
  ["@graph <file.dot>", "Insert a Graphviz diagram (path relative to the .md) as native shapes editable in Impress."],
1508
+ ["@next", "Start a new slide with the same title as the current one (unless a heading follows)."],
1455
1509
  ["```prompt ... ```", "Not a pragma: a code block shown as a chat prompt bubble."],
1456
1510
  ];
1457
1511
  function printHelp() {
package/dist/styles.js CHANGED
@@ -72,6 +72,11 @@ export const defaultTheme = {
72
72
  /** Maximum enlargement of a diagram relative to its Graphviz size. */
73
73
  maxScale: 1.5,
74
74
  },
75
+ /** Images of the master pages, styled by `Master-image` and `Section-image`. */
76
+ backgrounds: {
77
+ Master: { image: "", fit: "stretch" },
78
+ Section: { image: "", fit: "stretch" },
79
+ },
75
80
  };
76
81
  const sans = { "fo:font-family": "{fonts.sans}", "style:font-family-generic": "swiss" };
77
82
  const mono = { "fo:font-family": "{fonts.mono}", "style:font-family-generic": "modern" };
@@ -130,6 +135,18 @@ function masterStyles(master) {
130
135
  paragraph: { "fo:margin-bottom": "0.2cm" },
131
136
  text: { ...sans, "fo:font-size": "{sizes.notes}pt", "fo:color": "{colors.ink}" },
132
137
  };
138
+ styles[`${master}-image`] = {
139
+ family: "graphic",
140
+ parent: "standard",
141
+ graphic: {
142
+ "draw:stroke": "none",
143
+ "draw:fill": "none",
144
+ "draw:image-opacity": "100%",
145
+ "draw:color-mode": "standard",
146
+ "draw:luminance": "0%",
147
+ "draw:contrast": "0%",
148
+ },
149
+ };
133
150
  styles[`${master}-background`] = { family: "presentation", graphic: { "draw:stroke": "none", "draw:fill": "none" } };
134
151
  styles[`${master}-backgroundobjects`] = { family: "presentation", graphic: { "draw:shadow": "hidden" } };
135
152
  return styles;
@@ -382,7 +399,7 @@ const defaultStyles = {
382
399
  parent: "standard",
383
400
  graphic: { "draw:stroke": "solid", "svg:stroke-color": "{colors.primary}", "svg:stroke-width": "0.04cm" },
384
401
  },
385
- ...masterStyles("Greta"),
402
+ ...masterStyles("Master"),
386
403
  ...masterStyles("Section"),
387
404
  ...tableStyles("Tableau", "{sizes.table}pt"),
388
405
  ...tableStyles("Tableau-petit", "{sizes.tableSmall}pt"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolokoban/impress",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Convert teaching markdown files into LibreOffice Impress presentations (.odp)",
5
5
  "type": "module",
6
6
  "bin": {