@tolokoban/impress 0.20.0 → 0.21.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
@@ -98,6 +98,7 @@ When the slide appears, the list and the image have an opacity of 0.1. The first
98
98
  - `@anim (scale=0.5:1) {` has its own list of properties: the other properties of `@animation` are not animated.
99
99
  - For each of the duration, the delay and the easing, the first one given wins: on the property in `@anim`, on the `@anim`, on the property in `@animation`, on the `@animation`. Without any, animations last 500ms, with no delay and a linear easing. An `@anim` without properties, or a property without values, that `@animation` does not complete is an error.
100
100
  - Each block in a region (paragraph, list, table, image, code…) is a shape of its own, and all of them animate together. A table carries the images of its cells along.
101
+ - **Table cells**: a cell written `@anim [<index>] [(…)] [<timing>] { … @}` is animated on its own, with the same syntax and the same defaults as a region: `| C.R.A.F.T | @anim 1 {**C**ontexte@} | @anim 2 {**R**ôle@} |`. Impress cannot animate a single cell of a table, so the cell stays empty and its text (and its images) are drawn over it in a frame of their own, styled by `<cell style>-anim` (e.g. `Tableau-cellule-anim`: the text, alignment and padding of the cell style, without background nor borders). A cell can be animated in a table of an `@anim {` region too: it keeps its own animation.
101
102
  - A region can be inside a `@compact {` region (a list cut over several columns animates as one), but a `@compact {` region cannot be inside an `@anim {` region. Regions cannot be nested. A heading, `@next` or `@layout` inside a region, a region not closed by `@}`, an unknown property and a value out of range are errors.
102
103
  - In an `@layout`, the paragraphs and lists of a cell share a text frame, except across the border of a region.
103
104
  - With `@reveal`, the animations play on the last slide of the sequence, once every row is revealed; the slides before it show the `from` values.
@@ -121,7 +122,7 @@ The first conversion of `foo.md` writes `foo.style.json` with the complete defau
121
122
  { "theme": { "colors": { "primary": "#800020" } } }
122
123
  ```
123
124
 
124
- The file has seven top-level sections:
125
+ The file has eight top-level sections:
125
126
 
126
127
  | Key | Content |
127
128
  | --- | --- |
@@ -132,6 +133,7 @@ The file has seven top-level sections:
132
133
  | `markers` | Line ends (arrows) used by diagram edges. |
133
134
  | `dashes` | Dash patterns used by diagram edges and shapes. |
134
135
  | `boxes` | The boxes of `@box <name> {`. |
136
+ | `logo` | A logo shown on every slide (see [Logo](#logo)). |
135
137
 
136
138
  ### Theme
137
139
 
@@ -516,6 +518,22 @@ Et sa réponse : il y a bien une jurisprudence du … qui dit …
516
518
 
517
519
  Lengths are in `cm`, `mm`, `pt` or `in`, and every value can use [placeholders](#placeholders). Each box `<name>` becomes the named drawing style `Box-<name>` (content vertically centered, text shrunk if it does not fit), so it can also be changed in LibreOffice afterwards; a style `Box-<name>` in `styles` is merged over it. A box without nested boxes is one shape holding its text. A box holding other boxes is an empty shape, with its nested boxes and its text frames (style `Box-<name>-texte`: the text of `Box-<name>` without fill, border, shadow or padding) drawn over it. Three boxes come by default: `info` (light, with an automatic text color), `warning` (orange with white text) and `terminal` (dark, monospace text of `{sizes.code}pt`, to put in another box).
518
520
 
521
+ ### Logo
522
+
523
+ `logo` puts an image on every slide (content and section slides), above the background image (`theme.backgrounds`) and below everything else. The image sits in a rectangle stuck to the edges of the slide; it always keeps its aspect ratio and is centered in this rectangle, as big as possible (like CSS `object-fit: contain`).
524
+
525
+ ```json
526
+ { "logo": { "path": "images/logo.svg", "backgroundColor": "#FFFFFF", "size": { "width": 15, "height": 10 }, "margin": 2, "anchor": "BR" } }
527
+ ```
528
+
529
+ | Key | Value |
530
+ | --- | --- |
531
+ | `path` | Path relative to the markdown file, to a SVG, PNG, JPEG or WebP image. `""` (default): no logo. |
532
+ | `backgroundColor` | Optional color filling the whole rectangle, behind the logo, e.g. for a transparent logo on a dark section slide. Can use [placeholders](#placeholders), e.g. `{colors.white}`. |
533
+ | `size` | Size of the rectangle, in percent (0 to 100) of the slide. A number (default `12`) is a square whose side is a percentage of the smallest side of the slide (its height). `{ "width": 15, "height": 10 }` is 15% of the slide width by 10% of its height. |
534
+ | `margin` | Room between the rectangle and the edges of the slide, in percent (0 to 100) of the smallest side of the slide (default `0`). |
535
+ | `anchor` | Where the rectangle is stuck to the edges of the slide: `TL`, `T`, `TR`, `BL`, `B` or `BR` (default), with T = top, B = bottom, L = left, R = right. `T` and `B` center it horizontally. |
536
+
519
537
  ### Recipes
520
538
 
521
539
  Bigger text everywhere:
package/dist/impress.js CHANGED
@@ -71,7 +71,7 @@ let CENTER = false;
71
71
  function useStyle(config) {
72
72
  style = config;
73
73
  // The boxes of `@box` become named styles (their values can use the theme, hence `style` first).
74
- style = { ...config, styles: { ...config.styles, ...boxStyles(config) } };
74
+ style = { ...config, styles: { ...config.styles, ...boxStyles(config), ...cellAnimStyles(config) } };
75
75
  sizes = config.theme.sizes;
76
76
  SLIDE_W = config.theme.slide.width;
77
77
  SLIDE_H = config.theme.slide.height;
@@ -229,6 +229,26 @@ function boxShadow(spec, where) {
229
229
  * Named styles `Box-<name>` of the boxes of the style file. A style `Box-<name>` of `styles`, if
230
230
  * any, is merged over the one built from the box.
231
231
  */
232
+ /**
233
+ * `<cell style>-anim`: the text of an animated table cell (`@anim 1 {text@}`), in a frame drawn
234
+ * over its empty cell, because Impress cannot animate a single cell of a table. It takes the text,
235
+ * the alignment and the padding of the cell style, without its background and borders.
236
+ */
237
+ function cellAnimStyles(config) {
238
+ const out = {};
239
+ const keep = ["draw:textarea-vertical-align", "fo:padding-left", "fo:padding-right", "fo:padding-top", "fo:padding-bottom"];
240
+ for (const [name, s] of Object.entries(config.styles)) {
241
+ if (s.family !== "table-cell" || config.styles[`${name}-anim`])
242
+ continue;
243
+ const graphic = { "draw:fill": "none", "draw:stroke": "none", "fo:wrap-option": "wrap" };
244
+ for (const k of keep)
245
+ if (s.graphic?.[k] !== undefined)
246
+ graphic[k] = s.graphic[k];
247
+ const { "fo:border": _, ...paragraph } = s.paragraph ?? {};
248
+ out[`${name}-anim`] = { family: "graphic", parent: "standard", graphic, paragraph, text: { ...s.text } };
249
+ }
250
+ return out;
251
+ }
232
252
  function boxStyles(config) {
233
253
  const out = {};
234
254
  for (const [name, box] of Object.entries(config.boxes ?? {})) {
@@ -612,7 +632,7 @@ function parse(md, file) {
612
632
  const level = m[1].length;
613
633
  while (cur.level >= level)
614
634
  cur = cur.parent;
615
- const sec = new Section(level, stripMd(m[2]), cur, root.source);
635
+ const sec = new Section(level, m[2].trim(), cur, root.source);
616
636
  sec.layout = layout;
617
637
  layout = null;
618
638
  cur.children.push(sec);
@@ -789,7 +809,10 @@ function parse(md, file) {
789
809
  const rows = [];
790
810
  for (; i < lines.length && lines[i].trim().startsWith("|"); i++) {
791
811
  const row = lines[i].trim().replace(/^\|/, "").replace(/\|$/, "");
792
- rows.push(row.split("|").map(c => c.trim()));
812
+ const cells = row.split("|").map(c => c.trim());
813
+ for (const c of cells)
814
+ cellAnim(c, `${file}:${i + 1}`);
815
+ rows.push(cells);
793
816
  }
794
817
  i--;
795
818
  let header = rows[0];
@@ -983,6 +1006,19 @@ const IMG_GAP_EM = 0.3;
983
1006
  /** Horizontal padding of the table cells (both sides), in cm. */
984
1007
  const CELL_PAD_X = 0.4;
985
1008
  const cellCache = new Map();
1009
+ /** `@anim 1 (opacity=0.1:1) 300ms { **C**ontexte @}`: a table cell animated on its own. */
1010
+ const CELL_ANIM_RE = /^@anim(?:\s+(\d+(?:\.\d+)?|\.\d+)(?![\w.]))?\s*(?:\((.*)\))?\s*(.*?)\s*\{(.*)@\}$/;
1011
+ /** The animation of a table cell, if any, and its content without the `@anim { ... @}`. */
1012
+ function cellAnim(s, where) {
1013
+ if (!s.startsWith("@anim"))
1014
+ return { content: s };
1015
+ const m = s.match(CELL_ANIM_RE);
1016
+ if (!m)
1017
+ throw new Error(`${where}: expected a table cell like "@anim [<index>] [(<property>=<from>:<to>, ...)] [<duration> [<delay>]] [<easing>] { ... @}" (e.g. "@anim 1 { **C**ontexte @}"), got "${s}"`);
1018
+ const timing = parseTiming(m[3].split(/\s+/).filter(Boolean), where, '"@anim"');
1019
+ const props = m[2]?.trim() ? parseAnimProps(m[2], where, false) : undefined;
1020
+ return { anim: { index: Number(m[1] ?? 0), ...(props && { props }), where, ...timing }, content: m[4].trim() };
1021
+ }
986
1022
  function htmlAttr(tag, name) {
987
1023
  const m = tag.match(new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i"));
988
1024
  return m ? (m[1] ?? m[2] ?? m[3]) : undefined;
@@ -992,8 +1028,9 @@ function cell(s) {
992
1028
  let c = cellCache.get(s);
993
1029
  if (c)
994
1030
  return c;
1031
+ const { anim, content } = cellAnim(s, `table cell "${s}"`);
995
1032
  const imgs = [];
996
- const text = s
1033
+ const text = content
997
1034
  .replace(CELL_IMG_RE, (tag, mdAlt, mdSrc) => {
998
1035
  const src = mdSrc ?? htmlAttr(tag, "src");
999
1036
  if (!src)
@@ -1019,7 +1056,7 @@ function cell(s) {
1019
1056
  })
1020
1057
  .replace(/\s+/g, " ")
1021
1058
  .trim();
1022
- c = { text, imgs };
1059
+ c = { text, imgs, ...(anim && { anim }) };
1023
1060
  cellCache.set(s, c);
1024
1061
  return c;
1025
1062
  }
@@ -1746,6 +1783,8 @@ class Builder {
1746
1783
  colStyles = new Map();
1747
1784
  rowStyles = new Map();
1748
1785
  paraStyles = new Map();
1786
+ /** Table templates at a size other than the one of their cell styles: "<template>/<pt>" -> name. */
1787
+ cellStyles = new Map();
1749
1788
  /** Hints waiting to be attached to the next slide title. */
1750
1789
  pendingHints = [];
1751
1790
  /** Heading path of the section of the last slide. */
@@ -1778,6 +1817,17 @@ class Builder {
1778
1817
  this.colStyles.set(key, `co${this.colStyles.size + 1}`);
1779
1818
  return this.colStyles.get(key);
1780
1819
  }
1820
+ /**
1821
+ * Table template `<template>-<pt>pt`: the template `template` with its cell styles at `pt`
1822
+ * points. A shrunk table needs it, because LibreOffice sizes the rows with the font of the cell
1823
+ * styles of the template, not with the one of the paragraphs (see `stylesXml()`).
1824
+ */
1825
+ sizedTemplate(template, pt) {
1826
+ const key = `${template}/${f2(pt)}`;
1827
+ if (!this.cellStyles.has(key))
1828
+ this.cellStyles.set(key, `${template}-${f2(pt).replace(".", "_")}pt`);
1829
+ return this.cellStyles.get(key);
1830
+ }
1781
1831
  /**
1782
1832
  * Automatic paragraph style setting the font size (in points) of a `@compact` table,
1783
1833
  * and the left margin (in cm) leaving room for the images of a cell.
@@ -1817,7 +1867,8 @@ class Builder {
1817
1867
  return xml.replace(/<(\/?)([\w:-]+)([^>]*?)(\/?)>/g, (tag, close, name, rest, empty) => {
1818
1868
  if (close)
1819
1869
  depth--;
1820
- else if (depth++ === 0) {
1870
+ // A shape animated on its own (a cell of a table) keeps its id.
1871
+ else if (depth++ === 0 && !/\sdraw:id="/.test(rest)) {
1821
1872
  const id = `anim${++this.animCount}`;
1822
1873
  this.animShapes.push({ id, anim });
1823
1874
  tag = `<${name} draw:id="${id}" xml:id="${id}"${rest}${empty}>`;
@@ -1886,12 +1937,13 @@ class Builder {
1886
1937
  const prefix = small ? "Tableau-petit" : "Tableau";
1887
1938
  // A size other than the one of the cell styles (`@compact`) needs a paragraph style.
1888
1939
  const defaultPt = pt === (small ? sizes.tableSmall : sizes.table);
1940
+ const template = defaultPt ? prefix : this.sizedTemplate(prefix, pt);
1889
1941
  const para = (indent) => (defaultPt && !indent ? "" : ` text:style-name="${this.paraStyle(pt, indent)}"`);
1890
1942
  // Images of the cells, drawn over the table: a table cell of Impress only holds text.
1891
1943
  const overlays = [];
1892
1944
  const parts = [
1893
1945
  `<draw:frame draw:style-name="Tableau-cadre" ${Builder.geom(x, y, width, tableH(header, rows, width, pt, cols))}>`,
1894
- `<table:table table:template-name="${prefix}" table:use-first-row-styles="${header ? "true" : "false"}" table:use-banding-rows-styles="true">`,
1946
+ `<table:table table:template-name="${template}" table:use-first-row-styles="${header ? "true" : "false"}" table:use-banding-rows-styles="true">`,
1895
1947
  ...cols.map(cw => `<table:table-column table:style-name="${this.colStyle(cw)}"/>`),
1896
1948
  ];
1897
1949
  const all = [
@@ -1907,7 +1959,12 @@ class Builder {
1907
1959
  // A hidden cell keeps the size of its content, so the table does not move when it shows up.
1908
1960
  const c = kind !== "entete" && hidden(r, i) ? { text: "", imgs: [] } : cell(r[i] ?? "");
1909
1961
  const indent = cellTextIndent(c, cw, pt);
1910
- parts.push(`<table:table-cell table:style-name="${prefix}-${kind}"><text:p${para(indent)}>${runsXml(c.text)}</text:p></table:table-cell>`);
1962
+ // An animated cell is empty: its text is in a frame of its own, drawn over it.
1963
+ const text = c.anim ? "" : runsXml(c.text);
1964
+ parts.push(`<table:table-cell table:style-name="${template}-${kind}"><text:p${para(indent)}>${text}</text:p></table:table-cell>`);
1965
+ const cellOverlays = [];
1966
+ if (c.anim && c.text)
1967
+ cellOverlays.push(this.frame(`${prefix}-${kind}-anim`, cx, cy, cw, rh, `<text:p${para(indent)}>${runsXml(c.text)}</text:p>`));
1911
1968
  if (c.imgs.length) {
1912
1969
  const [scale, iw] = cellImgBox(c, cw, pt);
1913
1970
  const em = pt * PT * scale;
@@ -1915,10 +1972,11 @@ class Builder {
1915
1972
  let ix = c.text ? cx + CELL_PAD_X / 2 : cx + (cw - iw) / 2;
1916
1973
  for (const img of c.imgs) {
1917
1974
  const [w, h] = [img.w * em, img.h * em];
1918
- overlays.push(this.imageXml(img.src, ix, cy + (rh - h) / 2, w, h, img.alt));
1975
+ cellOverlays.push(this.imageXml(img.src, ix, cy + (rh - h) / 2, w, h, img.alt));
1919
1976
  ix += w + IMG_GAP_EM * em;
1920
1977
  }
1921
1978
  }
1979
+ overlays.push(this.animated(cellOverlays.join(""), c.anim));
1922
1980
  cx += cw;
1923
1981
  });
1924
1982
  parts.push("</table:table-row>");
@@ -2123,10 +2181,10 @@ class Builder {
2123
2181
  /** Do these blocks fit on one slide? */
2124
2182
  fits(blocks) {
2125
2183
  // `layout()` registers the automatic styles and the animated shapes it builds: forget those of this trial.
2126
- const saved = [new Map(this.colStyles), new Map(this.rowStyles), new Map(this.paraStyles)];
2184
+ const saved = [new Map(this.colStyles), new Map(this.rowStyles), new Map(this.paraStyles), new Map(this.cellStyles)];
2127
2185
  const [animCount, animShapes] = [this.animCount, this.animShapes.length];
2128
2186
  const ok = this.layout(blocks)[0] <= H;
2129
- [this.colStyles, this.rowStyles, this.paraStyles] = saved;
2187
+ [this.colStyles, this.rowStyles, this.paraStyles, this.cellStyles] = saved;
2130
2188
  this.animCount = animCount;
2131
2189
  this.animShapes.length = animShapes;
2132
2190
  return ok;
@@ -2292,14 +2350,14 @@ class Builder {
2292
2350
  titleShapes(title, crumbs) {
2293
2351
  const out = [];
2294
2352
  if (crumbs.length)
2295
- out.push(this.frame("Fil-ariane", X0, 0.35, W, 0.6, `<text:p>${xmlText(crumbs.join(" › "))}</text:p>`));
2296
- out.push(this.frame("Master-title", X0, 0.95, W, 1.6, `<text:p>${xmlText(title)}</text:p>`, "title", this.takeHints()));
2353
+ out.push(this.frame("Fil-ariane", X0, 0.35, W, 0.6, `<text:p>${crumbs.map(runsXml).join(" › ")}</text:p>`));
2354
+ out.push(this.frame("Master-title", X0, 0.95, W, 1.6, `<text:p>${runsXml(title)}</text:p>`, "title", this.takeHints()));
2297
2355
  return out;
2298
2356
  }
2299
2357
  sectionPage(sec) {
2300
2358
  // The big title is always the top-level (`#`) heading; the hierarchy box comes in `finish()`.
2301
2359
  const [title] = sec.path();
2302
- const shapes = [this.frame("Section-title", SEC.x, SEC.titleY, SEC.w, SEC.titleH, `<text:p>${xmlText(title)}</text:p>`, "title", this.takeHints())];
2360
+ const shapes = [this.frame("Section-title", SEC.x, SEC.titleY, SEC.w, SEC.titleH, `<text:p>${runsXml(title)}</text:p>`, "title", this.takeHints())];
2303
2361
  const notes = sec.blocks.flatMap(b => (b.t === "note" ? [b.text] : []));
2304
2362
  this.page("Section", shapes, notes).toc = sec;
2305
2363
  this.lastPath = sec.path();
@@ -2337,7 +2395,7 @@ class Builder {
2337
2395
  for (const child of parent.children) {
2338
2396
  if (child.continued || !child.title)
2339
2397
  continue;
2340
- let text = xmlText(child.title);
2398
+ let text = runsXml(child.title);
2341
2399
  if (child === current)
2342
2400
  text = `<text:span text:style-name="T_section">${text}</text:span>`;
2343
2401
  lines.push(text);
@@ -2414,7 +2472,7 @@ class Builder {
2414
2472
  /** Preferred width of a cell content, used by `auto` columns. */
2415
2473
  static preferredWidth(sec, height, textPt) {
2416
2474
  const cw = (pt) => pt * PT * 0.5;
2417
- let w = sec.title.length * cw(sizes.gridTitle) + 0.8;
2475
+ let w = plainLen(sec.title) * cw(sizes.gridTitle) + 0.8;
2418
2476
  for (const b of sec.blocks) {
2419
2477
  if (b.t === "para" || b.t === "quote")
2420
2478
  w = Math.max(w, plainLen(b.text) * cw(textPt) + 0.8);
@@ -2583,7 +2641,7 @@ class Builder {
2583
2641
  // Cells of an `@layout` of blocks have no heading.
2584
2642
  const hh = sec.title ? headH : 0;
2585
2643
  if (sec.title)
2586
- shapes.push(this.frame(headStyle, x, y, w, hh, `<text:p>${xmlText(sec.title)}</text:p>`));
2644
+ shapes.push(this.frame(headStyle, x, y, w, hh, `<text:p>${runsXml(sec.title)}</text:p>`));
2587
2645
  shapes.push(...this.cellXml(sec, x, y + hh, w, h - hh, textStyle, textPt));
2588
2646
  notes.push(...sec.blocks.flatMap(b => (b.t === "note" ? [b.text] : [])));
2589
2647
  });
@@ -2756,12 +2814,87 @@ function backgroundXml(b, master) {
2756
2814
  `<draw:image xlink:href="${esc(href)}" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>` +
2757
2815
  `</draw:frame>`);
2758
2816
  }
2817
+ /** Automatic styles of the logo (see `logoXml()`). */
2818
+ function logoStylesXml() {
2819
+ const logo = style.logo;
2820
+ if (!logo?.path)
2821
+ return "";
2822
+ const where = `"logo.backgroundColor"`;
2823
+ const color = logo.backgroundColor ? resolveValue(logo.backgroundColor, where) : "";
2824
+ if (color && !rgb(color))
2825
+ throw new Error(`${where} must be a color like #FFFFFF, got "${logo.backgroundColor}"`);
2826
+ return (`<style:style style:name="MLogo" style:family="graphic" style:parent-style-name="standard">` +
2827
+ `<style:graphic-properties draw:stroke="none" draw:fill="none" draw:image-opacity="100%" draw:color-mode="standard" draw:luminance="0%" draw:contrast="0%"/></style:style>` +
2828
+ (color
2829
+ ? `<style:style style:name="MLogo-fond" style:family="graphic" style:parent-style-name="standard">` +
2830
+ `<style:graphic-properties draw:stroke="none" draw:fill="solid" draw:fill-color="${esc(color)}"/></style:style>`
2831
+ : ""));
2832
+ }
2833
+ /** Percentage (0 to 100) of a logo value, as a fraction. Only `allowZero` accepts 0. */
2834
+ function logoPercent(value, what, allowZero = false) {
2835
+ if (typeof value !== "number" || value > 100 || value < 0 || (value === 0 && !allowZero))
2836
+ throw new Error(`"logo.${what}" must be a number between 0 and 100, got ${JSON.stringify(value)}`);
2837
+ return value / 100;
2838
+ }
2839
+ /** Frame of the logo of every slide (see `StyleConfig.logo`), or "" if there is none. */
2840
+ function logoXml(b) {
2841
+ const logo = style.logo;
2842
+ if (!logo?.path)
2843
+ return "";
2844
+ const { href, size } = b.picture(logo.path);
2845
+ const side = Math.min(SLIDE_W, SLIDE_H);
2846
+ // Rectangle holding the logo.
2847
+ let boxW;
2848
+ let boxH;
2849
+ if (typeof logo.size === "number") {
2850
+ boxW = boxH = logoPercent(logo.size, "size") * side;
2851
+ }
2852
+ else if (isObject(logo.size)) {
2853
+ boxW = logoPercent(logo.size.width, "size.width") * SLIDE_W;
2854
+ boxH = logoPercent(logo.size.height, "size.height") * SLIDE_H;
2855
+ }
2856
+ else {
2857
+ throw new Error(`"logo.size" must be a number or { "width": number, "height": number }`);
2858
+ }
2859
+ const margin = logoPercent(logo.margin ?? 0, "margin", true) * side;
2860
+ const anchor = logo.anchor;
2861
+ if (!["B", "BL", "BR", "T", "TR", "TL"].includes(anchor))
2862
+ throw new Error(`"logo.anchor" must be one of B, BL, BR, T, TR, TL, got "${anchor}"`);
2863
+ const boxY = anchor.startsWith("T") ? margin : SLIDE_H - margin - boxH;
2864
+ const boxX = anchor.endsWith("L") ? margin : anchor.endsWith("R") ? SLIDE_W - margin - boxW : (SLIDE_W - boxW) / 2;
2865
+ // The logo keeps its aspect ratio, centered in the rectangle (CSS "contain").
2866
+ const [w, h] = fit(size[0], size[1], boxW, boxH);
2867
+ const x = boxX + (boxW - w) / 2;
2868
+ const y = boxY + (boxH - h) / 2;
2869
+ const fond = logo.backgroundColor ? `<draw:rect draw:style-name="MLogo-fond" ${Builder.geom(boxX, boxY, boxW, boxH)}/>` : "";
2870
+ return (fond +
2871
+ `<draw:frame draw:style-name="MLogo" ${Builder.geom(x, y, w, h)}>` +
2872
+ `<draw:image xlink:href="${esc(href)}" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>` +
2873
+ `</draw:frame>`);
2874
+ }
2759
2875
  function stylesXml(b) {
2760
2876
  const templates = style.tableTemplates.map(t => `<table:table-template table:name="${esc(t.name)}">` +
2761
2877
  `<table:first-row table:style-name="${esc(t.header)}"/>` +
2762
2878
  `<table:body table:style-name="${esc(t.body)}"/>` +
2763
2879
  `<table:odd-rows table:style-name="${esc(t.bandedRows)}"/>` +
2764
2880
  `</table:table-template>`);
2881
+ // Templates of the shrunk tables: each one with its cell styles, at the size of the table.
2882
+ const cellStyles = [];
2883
+ for (const [key, name] of b.cellStyles) {
2884
+ const [base, pt] = key.split("/");
2885
+ const t = style.tableTemplates.find(t => t.name === base);
2886
+ if (!t)
2887
+ continue;
2888
+ const sized = (cellStyle) => {
2889
+ cellStyles.push(`<style:style style:name="${esc(`${name}-${cellStyle.slice(base.length + 1)}`)}" style:family="table-cell" style:parent-style-name="${esc(cellStyle)}"><style:text-properties fo:font-size="${pt}pt"/></style:style>`);
2890
+ return `${name}-${cellStyle.slice(base.length + 1)}`;
2891
+ };
2892
+ templates.push(`<table:table-template table:name="${esc(name)}">` +
2893
+ `<table:first-row table:style-name="${esc(sized(t.header))}"/>` +
2894
+ `<table:body table:style-name="${esc(sized(t.body))}"/>` +
2895
+ `<table:odd-rows table:style-name="${esc(sized(t.bandedRows))}"/>` +
2896
+ `</table:table-template>`);
2897
+ }
2765
2898
  const markers = [
2766
2899
  ...Object.entries(style.markers).map(([name, m]) => `<draw:marker draw:name="${esc(name)}" svg:viewBox="${esc(m.viewBox)}" svg:d="${esc(m.d)}"/>`),
2767
2900
  ...Object.entries(style.dashes).map(([name, props]) => `<draw:stroke-dash draw:name="${esc(name)}" ${attrs(props)}/>`),
@@ -2772,6 +2905,7 @@ function stylesXml(b) {
2772
2905
  `<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>`,
2773
2906
  backgroundStyleXml("Master"),
2774
2907
  backgroundStyleXml("Section"),
2908
+ logoStylesXml(),
2775
2909
  ];
2776
2910
  const notes = (m) => `<presentation:notes style:page-layout-name="PM2">` +
2777
2911
  `<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"/>` +
@@ -2781,6 +2915,7 @@ function stylesXml(b) {
2781
2915
  const masters = [
2782
2916
  `<style:master-page style:name="Master" style:page-layout-name="PM1" draw:style-name="Mdp1">` +
2783
2917
  backgroundXml(b, "Master") +
2918
+ logoXml(b) +
2784
2919
  `<draw:rect draw:style-name="Decor" ${Builder.geom(0, 0, 0.4, SLIDE_H)}/>` +
2785
2920
  `<draw:line draw:style-name="Decor-ligne" svg:x1="${X0}cm" svg:y1="2.7cm" svg:x2="${X0 + W}cm" svg:y2="2.7cm"/>` +
2786
2921
  placeholder("Master-title", "title", X0, 0.95, W, 1.6) +
@@ -2789,13 +2924,14 @@ function stylesXml(b) {
2789
2924
  `<style:master-page style:name="Section" style:page-layout-name="PM1" draw:style-name="Mdp1">` +
2790
2925
  `<draw:rect draw:style-name="Section-fond" ${Builder.geom(0, 0, SLIDE_W, SLIDE_H)}/>` +
2791
2926
  backgroundXml(b, "Section") +
2927
+ logoXml(b) +
2792
2928
  `<draw:rect draw:style-name="Decor" ${Builder.geom(0, SEC.barY, SLIDE_W, 0.12)}/>` +
2793
2929
  placeholder("Section-title", "title", SEC.x, SEC.titleY, SEC.w, SEC.titleH) +
2794
2930
  placeholder("Section-subtitle", "subtitle", SEC.x, SEC.boxY, SEC.w, SEC.boxBottom - SEC.boxY) +
2795
2931
  `${notes("Section")}</style:master-page>`,
2796
2932
  ];
2797
2933
  return (`<?xml version="1.0" encoding="UTF-8"?><office:document-styles ${NS}>` +
2798
- `<office:styles>${Object.entries(style.styles).map(([name, s]) => styleXml(name, s)).join("")}${templates.join("")}${markers.join("")}</office:styles>` +
2934
+ `<office:styles>${Object.entries(style.styles).map(([name, s]) => styleXml(name, s)).join("")}${cellStyles.join("")}${templates.join("")}${markers.join("")}</office:styles>` +
2799
2935
  `<office:automatic-styles>${auto.join("")}</office:automatic-styles>` +
2800
2936
  `<office:master-styles>${masters.join("")}</office:master-styles></office:document-styles>`);
2801
2937
  }
package/dist/styles.js CHANGED
@@ -395,6 +395,8 @@ export const defaultStyle = {
395
395
  dashes: {
396
396
  Tirets: { "draw:style": "rect", "draw:dots1": "1", "draw:dots1-length": "0.2cm", "draw:distance": "0.15cm" },
397
397
  },
398
+ /** No logo by default: set `path` to show one. */
399
+ logo: { path: "", size: 12, margin: 0, anchor: "BR" },
398
400
  boxes: {
399
401
  /** No `color`: black or white, whichever is more readable on the background. */
400
402
  info: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolokoban/impress",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "Convert teaching markdown files into LibreOffice Impress presentations (.odp)",
5
5
  "type": "module",
6
6
  "bin": {