@tolokoban/impress 0.21.0 → 0.22.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 +16 -4
- package/dist/impress.js +98 -47
- package/dist/styles.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -133,7 +133,7 @@ The file has eight top-level sections:
|
|
|
133
133
|
| `markers` | Line ends (arrows) used by diagram edges. |
|
|
134
134
|
| `dashes` | Dash patterns used by diagram edges and shapes. |
|
|
135
135
|
| `boxes` | The boxes of `@box <name> {`. |
|
|
136
|
-
| `logo` |
|
|
136
|
+
| `logo` | One or several logos shown on every slide (see [Logo](#logo)). |
|
|
137
137
|
|
|
138
138
|
### Theme
|
|
139
139
|
|
|
@@ -520,18 +520,30 @@ Lengths are in `cm`, `mm`, `pt` or `in`, and every value can use [placeholders](
|
|
|
520
520
|
|
|
521
521
|
### Logo
|
|
522
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
|
|
523
|
+
`logo` puts an image on every slide (content and section slides), above the background image (`theme.backgrounds`) and the vertical bar of the content slides, below everything else. The image sits in a rectangle stuck to the edges of the slide; it always keeps its aspect ratio and is as big as possible in this rectangle (like CSS `object-fit: contain`), pushed toward the anchor: with `BR`, a wide logo touches the bottom of the rectangle and a tall one touches its right side; with `B` or `T`, it is centered horizontally.
|
|
524
|
+
|
|
525
|
+
`logo` is one logo, or an array of logos. Each logo of an array is completed with the default values (`size` 12, `margin` 0, `anchor` `BR`). Logos with the same `anchor` are stacked vertically, in the order of the array, starting from the edge of the anchor (the first one of `BR` is at the bottom, the first one of `TR` at the top). They are stacked by the actual height of each logo, not the height of its rectangle, so wide logos in square rectangles do not leave gaps; between two stacked logos, the room is the largest of their facing margins (as with CSS margin collapsing: the `top` margin of the lower logo and the `bottom` margin of the upper one).
|
|
524
526
|
|
|
525
527
|
```json
|
|
526
528
|
{ "logo": { "path": "images/logo.svg", "backgroundColor": "#FFFFFF", "size": { "width": 15, "height": 10 }, "margin": 2, "anchor": "BR" } }
|
|
527
529
|
```
|
|
528
530
|
|
|
531
|
+
```json
|
|
532
|
+
{
|
|
533
|
+
"logo": [
|
|
534
|
+
{ "path": "images/school.png", "anchor": "TR", "margin": 1 },
|
|
535
|
+
{ "path": "images/partner.svg", "anchor": "TR", "margin": 1, "size": 8 },
|
|
536
|
+
{ "path": "images/license.svg", "anchor": "BL", "size": { "width": 10, "height": 5 } }
|
|
537
|
+
]
|
|
538
|
+
}
|
|
539
|
+
```
|
|
540
|
+
|
|
529
541
|
| Key | Value |
|
|
530
542
|
| --- | --- |
|
|
531
543
|
| `path` | Path relative to the markdown file, to a SVG, PNG, JPEG or WebP image. `""` (default): no logo. |
|
|
532
|
-
| `backgroundColor` | Optional color
|
|
544
|
+
| `backgroundColor` | Optional color behind the logo, with the width of the rectangle and the height of the logo, e.g. for a transparent logo on a dark section slide. Can use [placeholders](#placeholders), e.g. `{colors.white}`. |
|
|
533
545
|
| `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
|
|
546
|
+
| `margin` | Room around the logo, in percent (0 to 100) of the smallest side of the slide (default `0`). As in CSS: `2` for every side, `[1, 3]` for `[vertical, horizontal]`, or `[1, 3, 0, 2]` for `[top, right, bottom, left]`. A logo anchored `B` or `T` is centered between its `left` and `right` margins. |
|
|
535
547
|
| `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
548
|
|
|
537
549
|
### Recipes
|
package/dist/impress.js
CHANGED
|
@@ -45,7 +45,7 @@ import { crc32, deflateRawSync } from "node:zlib";
|
|
|
45
45
|
import { spawnSync } from "node:child_process";
|
|
46
46
|
import { createInterface } from "node:readline/promises";
|
|
47
47
|
import sharp from "sharp";
|
|
48
|
-
import { defaultStyle } from "./styles.js";
|
|
48
|
+
import { defaultLogo, defaultStyle } from "./styles.js";
|
|
49
49
|
const PT = 0.03528; // cm per point
|
|
50
50
|
// ---------------------------------------------------------------- terminal colors
|
|
51
51
|
/** ANSI styles, only when writing to a terminal and NO_COLOR is not set. */
|
|
@@ -2814,63 +2814,113 @@ function backgroundXml(b, master) {
|
|
|
2814
2814
|
`<draw:image xlink:href="${esc(href)}" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>` +
|
|
2815
2815
|
`</draw:frame>`);
|
|
2816
2816
|
}
|
|
2817
|
-
/**
|
|
2817
|
+
/**
|
|
2818
|
+
* The logos of `style.logo` (one object or an array), each one completed with the defaults.
|
|
2819
|
+
* Those whose `path` is empty are not drawn.
|
|
2820
|
+
*/
|
|
2821
|
+
function logos() {
|
|
2822
|
+
const list = Array.isArray(style.logo) ? style.logo : [style.logo];
|
|
2823
|
+
return list.map(logo => ({ ...defaultLogo, ...logo }));
|
|
2824
|
+
}
|
|
2825
|
+
/** Automatic styles of the logos (see `logoXml()`): one for the images, one per background color. */
|
|
2818
2826
|
function logoStylesXml() {
|
|
2819
|
-
const
|
|
2820
|
-
if (!logo
|
|
2827
|
+
const all = logos();
|
|
2828
|
+
if (!all.some(logo => logo.path))
|
|
2821
2829
|
return "";
|
|
2822
|
-
const
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2830
|
+
const fills = all.map((logo, i) => {
|
|
2831
|
+
if (!logo.path || !logo.backgroundColor)
|
|
2832
|
+
return "";
|
|
2833
|
+
const where = `"logo[${i}].backgroundColor"`;
|
|
2834
|
+
const color = resolveValue(logo.backgroundColor, where);
|
|
2835
|
+
if (!rgb(color))
|
|
2836
|
+
throw new Error(`${where} must be a color like #FFFFFF, got "${logo.backgroundColor}"`);
|
|
2837
|
+
return (`<style:style style:name="MLogo-fond-${i}" style:family="graphic" style:parent-style-name="standard">` +
|
|
2838
|
+
`<style:graphic-properties draw:stroke="none" draw:fill="solid" draw:fill-color="${esc(color)}"/></style:style>`);
|
|
2839
|
+
});
|
|
2826
2840
|
return (`<style:style style:name="MLogo" style:family="graphic" style:parent-style-name="standard">` +
|
|
2827
2841
|
`<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
|
-
(
|
|
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
|
-
: ""));
|
|
2842
|
+
fills.join(""));
|
|
2832
2843
|
}
|
|
2833
2844
|
/** Percentage (0 to 100) of a logo value, as a fraction. Only `allowZero` accepts 0. */
|
|
2834
2845
|
function logoPercent(value, what, allowZero = false) {
|
|
2835
2846
|
if (typeof value !== "number" || value > 100 || value < 0 || (value === 0 && !allowZero))
|
|
2836
|
-
throw new Error(`"
|
|
2847
|
+
throw new Error(`"${what}" must be a number between 0 and 100, got ${JSON.stringify(value)}`);
|
|
2837
2848
|
return value / 100;
|
|
2838
2849
|
}
|
|
2839
|
-
/**
|
|
2850
|
+
/**
|
|
2851
|
+
* Margins of a logo as fractions of the smallest side of the slide: [top, right, bottom, left].
|
|
2852
|
+
* As in CSS: `m` for every side, `[vertical, horizontal]` or `[top, right, bottom, left]`.
|
|
2853
|
+
*/
|
|
2854
|
+
function logoMargins(margin, where) {
|
|
2855
|
+
if (typeof margin === "number") {
|
|
2856
|
+
const m = logoPercent(margin, where, true);
|
|
2857
|
+
return [m, m, m, m];
|
|
2858
|
+
}
|
|
2859
|
+
if (Array.isArray(margin) && (margin.length === 2 || margin.length === 4)) {
|
|
2860
|
+
const [top, right, bottom = top, left = right] = margin.map((m, k) => logoPercent(m, `${where}[${k}]`, true));
|
|
2861
|
+
return [top, right, bottom, left];
|
|
2862
|
+
}
|
|
2863
|
+
throw new Error(`"${where}" must be a number, [vertical, horizontal] or [top, right, bottom, left], got ${JSON.stringify(margin)}`);
|
|
2864
|
+
}
|
|
2865
|
+
/**
|
|
2866
|
+
* Frames of the logos of every slide (see `StyleConfig.logo`), or "" if there is none.
|
|
2867
|
+
* Logos with the same anchor are stacked vertically, in their order, starting from the edge
|
|
2868
|
+
* of the anchor, by their actual height (not the height of their rectangle). Between two stacked
|
|
2869
|
+
* logos, the room is the largest of their facing margins (like CSS margin collapsing).
|
|
2870
|
+
*/
|
|
2840
2871
|
function logoXml(b) {
|
|
2841
|
-
const logo = style.logo;
|
|
2842
|
-
if (!logo?.path)
|
|
2843
|
-
return "";
|
|
2844
|
-
const { href, size } = b.picture(logo.path);
|
|
2845
2872
|
const side = Math.min(SLIDE_W, SLIDE_H);
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2873
|
+
/**
|
|
2874
|
+
* For each anchor, distance from its top or bottom edge already taken by the logos (`edge`),
|
|
2875
|
+
* and the margin of the last logo on the side away from that edge (`far`).
|
|
2876
|
+
*/
|
|
2877
|
+
const stacks = new Map();
|
|
2878
|
+
return logos()
|
|
2879
|
+
.map((logo, i) => {
|
|
2880
|
+
if (!logo.path)
|
|
2881
|
+
return "";
|
|
2882
|
+
const where = `logo[${i}]`;
|
|
2883
|
+
const { href, size } = b.picture(logo.path);
|
|
2884
|
+
// Rectangle holding the logo.
|
|
2885
|
+
let boxW;
|
|
2886
|
+
let boxH;
|
|
2887
|
+
if (typeof logo.size === "number") {
|
|
2888
|
+
boxW = boxH = logoPercent(logo.size, `${where}.size`) * side;
|
|
2889
|
+
}
|
|
2890
|
+
else if (isObject(logo.size)) {
|
|
2891
|
+
boxW = logoPercent(logo.size.width, `${where}.size.width`) * SLIDE_W;
|
|
2892
|
+
boxH = logoPercent(logo.size.height, `${where}.size.height`) * SLIDE_H;
|
|
2893
|
+
}
|
|
2894
|
+
else {
|
|
2895
|
+
throw new Error(`"${where}.size" must be a number or { "width": number, "height": number }`);
|
|
2896
|
+
}
|
|
2897
|
+
const [top, right, bottom, left] = logoMargins(logo.margin ?? 0, `${where}.margin`).map(m => m * side);
|
|
2898
|
+
const anchor = logo.anchor;
|
|
2899
|
+
if (!["B", "BL", "BR", "T", "TR", "TL"].includes(anchor))
|
|
2900
|
+
throw new Error(`"${where}.anchor" must be one of B, BL, BR, T, TR, TL, got "${anchor}"`);
|
|
2901
|
+
// The logo keeps its aspect ratio (CSS "contain") and is pushed toward its anchor in the rectangle.
|
|
2902
|
+
const [w, h] = fit(size[0], size[1], boxW, boxH);
|
|
2903
|
+
// Stacked by the actual height of the logo, not by the height of its rectangle.
|
|
2904
|
+
const fromTop = anchor.startsWith("T");
|
|
2905
|
+
const [near, far] = fromTop ? [top, bottom] : [bottom, top];
|
|
2906
|
+
const stack = stacks.get(anchor) ?? { edge: 0, far: 0 };
|
|
2907
|
+
const offset = stack.edge + Math.max(stack.far, near);
|
|
2908
|
+
stacks.set(anchor, { edge: offset + h, far });
|
|
2909
|
+
const y = fromTop ? offset : SLIDE_H - offset - h;
|
|
2910
|
+
const boxX = anchor.endsWith("L")
|
|
2911
|
+
? left
|
|
2912
|
+
: anchor.endsWith("R")
|
|
2913
|
+
? SLIDE_W - right - boxW
|
|
2914
|
+
: left + (SLIDE_W - left - right - boxW) / 2;
|
|
2915
|
+
const x = anchor.endsWith("L") ? boxX : anchor.endsWith("R") ? boxX + boxW - w : boxX + (boxW - w) / 2;
|
|
2916
|
+
// The background has the width of the rectangle and the height of the logo, so stacked backgrounds do not overlap.
|
|
2917
|
+
const fond = logo.backgroundColor ? `<draw:rect draw:style-name="MLogo-fond-${i}" ${Builder.geom(boxX, y, boxW, h)}/>` : "";
|
|
2918
|
+
return (fond +
|
|
2919
|
+
`<draw:frame draw:style-name="MLogo" ${Builder.geom(x, y, w, h)}>` +
|
|
2920
|
+
`<draw:image xlink:href="${esc(href)}" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>` +
|
|
2921
|
+
`</draw:frame>`);
|
|
2922
|
+
})
|
|
2923
|
+
.join("");
|
|
2874
2924
|
}
|
|
2875
2925
|
function stylesXml(b) {
|
|
2876
2926
|
const templates = style.tableTemplates.map(t => `<table:table-template table:name="${esc(t.name)}">` +
|
|
@@ -2915,8 +2965,9 @@ function stylesXml(b) {
|
|
|
2915
2965
|
const masters = [
|
|
2916
2966
|
`<style:master-page style:name="Master" style:page-layout-name="PM1" draw:style-name="Mdp1">` +
|
|
2917
2967
|
backgroundXml(b, "Master") +
|
|
2918
|
-
logoXml(b) +
|
|
2919
2968
|
`<draw:rect draw:style-name="Decor" ${Builder.geom(0, 0, 0.4, SLIDE_H)}/>` +
|
|
2969
|
+
// Above the vertical bar, so that a logo anchored on the left is not hidden by it.
|
|
2970
|
+
logoXml(b) +
|
|
2920
2971
|
`<draw:line draw:style-name="Decor-ligne" svg:x1="${X0}cm" svg:y1="2.7cm" svg:x2="${X0 + W}cm" svg:y2="2.7cm"/>` +
|
|
2921
2972
|
placeholder("Master-title", "title", X0, 0.95, W, 1.6) +
|
|
2922
2973
|
placeholder("Master-outline1", "outline", X0, Y0, W, H) +
|
package/dist/styles.js
CHANGED
|
@@ -380,6 +380,11 @@ const defaultStyles = {
|
|
|
380
380
|
...tableStyles("Tableau", "{sizes.table}pt"),
|
|
381
381
|
...tableStyles("Tableau-petit", "{sizes.tableSmall}pt"),
|
|
382
382
|
};
|
|
383
|
+
/**
|
|
384
|
+
* No logo by default: set `path` to show one. Each logo of an array of logos
|
|
385
|
+
* is completed with these values.
|
|
386
|
+
*/
|
|
387
|
+
export const defaultLogo = { path: "", size: 12, margin: 0, anchor: "BR" };
|
|
383
388
|
export const defaultStyle = {
|
|
384
389
|
theme: defaultTheme,
|
|
385
390
|
styles: defaultStyles,
|
|
@@ -395,8 +400,7 @@ export const defaultStyle = {
|
|
|
395
400
|
dashes: {
|
|
396
401
|
Tirets: { "draw:style": "rect", "draw:dots1": "1", "draw:dots1-length": "0.2cm", "draw:distance": "0.15cm" },
|
|
397
402
|
},
|
|
398
|
-
|
|
399
|
-
logo: { path: "", size: 12, margin: 0, anchor: "BR" },
|
|
403
|
+
logo: defaultLogo,
|
|
400
404
|
boxes: {
|
|
401
405
|
/** No `color`: black or white, whichever is more readable on the background. */
|
|
402
406
|
info: {
|