@kensio/colophon 1.0.0 → 2.2.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 +132 -4
- package/dist/config.d.ts +18 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +39 -0
- package/dist/config.js.map +1 -1
- package/dist/content/index.d.ts.map +1 -1
- package/dist/content/index.js +4 -5
- package/dist/content/index.js.map +1 -1
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +9 -1
- package/dist/generate.js.map +1 -1
- package/dist/highlight.d.ts +75 -0
- package/dist/highlight.d.ts.map +1 -0
- package/dist/highlight.js +137 -0
- package/dist/highlight.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/render.d.ts +4 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +6 -3
- package/dist/render.js.map +1 -1
- package/dist/templates/banner.d.ts.map +1 -1
- package/dist/templates/banner.js +2 -12
- package/dist/templates/banner.js.map +1 -1
- package/dist/templates/card.d.ts.map +1 -1
- package/dist/templates/card.js +2 -12
- package/dist/templates/card.js.map +1 -1
- package/dist/templates/code.d.ts +12 -0
- package/dist/templates/code.d.ts.map +1 -0
- package/dist/templates/code.js +275 -0
- package/dist/templates/code.js.map +1 -0
- package/dist/templates/index.d.ts +2 -0
- package/dist/templates/index.d.ts.map +1 -1
- package/dist/templates/index.js +4 -0
- package/dist/templates/index.js.map +1 -1
- package/dist/templates/props.d.ts +7 -0
- package/dist/templates/props.d.ts.map +1 -0
- package/dist/templates/props.js +17 -0
- package/dist/templates/props.js.map +1 -0
- package/dist/types.d.ts +54 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -4
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,YAAY,GACb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,MAAM,EACN,UAAU,EACV,aAAa,EACb,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG5D,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/render.d.ts
CHANGED
|
@@ -2,8 +2,11 @@ import type { ColophonConfig, Dimensions, MetaImageProps, RenderedMetaImage, Res
|
|
|
2
2
|
/**
|
|
3
3
|
* Build the complete SVG document for one image: the enclosing `<svg>` root,
|
|
4
4
|
* the config-driven background, and the template's foreground content.
|
|
5
|
+
*
|
|
6
|
+
* Asynchronous because a template may need to load resources — the `code`
|
|
7
|
+
* template fetches syntax grammars and themes on demand.
|
|
5
8
|
*/
|
|
6
|
-
export declare function buildSvg(props: MetaImageProps, config: ResolvedConfig, dimensions: Dimensions): string
|
|
9
|
+
export declare function buildSvg(props: MetaImageProps, config: ResolvedConfig, dimensions: Dimensions): Promise<string>;
|
|
7
10
|
/**
|
|
8
11
|
* Rasterise an SVG string to a PNG buffer at the given dimensions.
|
|
9
12
|
*/
|
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,cAAc,EAEf,MAAM,YAAY,CAAC;AAmBpB
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,cAAc,EAEf,MAAM,YAAY,CAAC;AAmBpB;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,MAAM,CAAC,CAKjB;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,cAAc,EACrB,MAAM,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAc9B"}
|
package/dist/render.js
CHANGED
|
@@ -15,11 +15,14 @@ function selectTemplate(config, name) {
|
|
|
15
15
|
/**
|
|
16
16
|
* Build the complete SVG document for one image: the enclosing `<svg>` root,
|
|
17
17
|
* the config-driven background, and the template's foreground content.
|
|
18
|
+
*
|
|
19
|
+
* Asynchronous because a template may need to load resources — the `code`
|
|
20
|
+
* template fetches syntax grammars and themes on demand.
|
|
18
21
|
*/
|
|
19
|
-
export function buildSvg(props, config, dimensions) {
|
|
22
|
+
export async function buildSvg(props, config, dimensions) {
|
|
20
23
|
const template = selectTemplate(config, props.template);
|
|
21
24
|
const background = backgroundSvg(config.background, dimensions, backgroundId);
|
|
22
|
-
const body = template.render({ props, config, dimensions });
|
|
25
|
+
const body = await template.render({ props, config, dimensions });
|
|
23
26
|
const { width, height } = dimensions;
|
|
24
27
|
return (`<svg width="${String(width)}" height="${String(height)}"` +
|
|
25
28
|
` viewBox="0 0 ${String(width)} ${String(height)}"` +
|
|
@@ -45,7 +48,7 @@ export async function renderMetaImages(props, config) {
|
|
|
45
48
|
selectTemplate(resolved, props.template);
|
|
46
49
|
return Promise.all(resolved.sizes.map(async (size) => {
|
|
47
50
|
const dimensions = { width: size.width, height: size.height };
|
|
48
|
-
const svg = buildSvg(props, resolved, dimensions);
|
|
51
|
+
const svg = await buildSvg(props, resolved, dimensions);
|
|
49
52
|
const png = await renderSvgToPng(svg, dimensions);
|
|
50
53
|
return { name: size.name, dimensions, svg, png };
|
|
51
54
|
}));
|
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAU5C,MAAM,YAAY,GAAG,aAAa,CAAC;AAEnC,SAAS,cAAc,CAAC,MAAsB,EAAE,IAAY;IAC1D,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAExC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;aAC5C,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;aACtC,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,IAAI,KAAK,CACb,qBAAqB,IAAI,2BAA2B,SAAS,GAAG,CACjE,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CA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3,"file":"banner.d.ts","sourceRoot":"","sources":["../../src/templates/banner.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAS,QAAQ,EAAmB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"banner.d.ts","sourceRoot":"","sources":["../../src/templates/banner.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAS,QAAQ,EAAmB,MAAM,aAAa,CAAC;AA2CpE;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,QAwH5B,CAAC"}
|
package/dist/templates/banner.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import { estimateCharsPerLine, layoutStack, textElement, wrapText, } from "../text.js";
|
|
2
|
+
import { optionalString } from "./props.js";
|
|
2
3
|
const maxTitleLines = 3;
|
|
3
4
|
const maxSubtitleLines = 4;
|
|
4
|
-
function optionalString(value) {
|
|
5
|
-
if (typeof value === "string") {
|
|
6
|
-
return value;
|
|
7
|
-
}
|
|
8
|
-
if (typeof value === "number" ||
|
|
9
|
-
typeof value === "boolean" ||
|
|
10
|
-
typeof value === "bigint") {
|
|
11
|
-
return String(value);
|
|
12
|
-
}
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
5
|
function renderBadge(badge, fontFamily, brand, pad, height) {
|
|
16
6
|
const fontSize = Math.round(height * 0.6);
|
|
17
7
|
const padX = Math.round(height * 0.36);
|
|
@@ -44,7 +34,7 @@ export const bannerTemplate = {
|
|
|
44
34
|
const fg = config.colors.foreground;
|
|
45
35
|
const pad = Math.round(width * 0.075);
|
|
46
36
|
const contentWidth = width - pad * 2;
|
|
47
|
-
const title = props.title;
|
|
37
|
+
const title = optionalString(props.title) ?? "";
|
|
48
38
|
const subtitle = optionalString(props.subtitle);
|
|
49
39
|
const version = optionalString(props.version);
|
|
50
40
|
const hasSubtitle = subtitle !== undefined && subtitle !== "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"banner.js","sourceRoot":"","sources":["../../src/templates/banner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AAC,EAAE,CAAC,IAAI,GAAG;YAC1B,UAAU;YACV,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,IAAI,EAAE,EAAE;YACR,WAAW,EAAE,IAAI,CAAC,OAAO;SAC1B,CAAC,CACH;aACA,IAAI,CAAC,EAAE,CAAC,CAAC;QAEZ,MAAM,KAAK,GACT,MAAM,CAAC,KAAK,KAAK,SAAS;YACxB,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,WAAW,CACT,MAAM,CAAC,KAAK,EACZ,UAAU,EACV,MAAM,CAAC,MAAM,CAAC,KAAK,EACnB,GAAG,EACH,WAAW,CACZ,CAAC;QAER,MAAM,MAAM,GACV,MAAM,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,EAAE;YACjD,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE;gBACzB,CAAC,EAAE,GAAG;gBACN,CAAC,EAAE,MAAM,GAAG,GAAG;gBACf,UAAU;gBACV,QAAQ,EAAE,QAAQ;gBAClB,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,EAAE;gBACR,WAAW,EAAE,IAAI;aAClB,CAAC;YACJ,CAAC,CAAC,EAAE,CAAC;QAET,OAAO,KAAK,GAAG,IAAI,GAAG,MAAM,CAAC;IAC/B,CAAC;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../src/templates/card.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../src/templates/card.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,aAAa,CAAC;AAa7D;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,QAsF1B,CAAC"}
|
package/dist/templates/card.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import { estimateCharsPerLine, layoutStack, textElement, wrapText, } from "../text.js";
|
|
2
|
+
import { optionalString } from "./props.js";
|
|
2
3
|
const maxTitleLines = 3;
|
|
3
4
|
const maxSubtitleLines = 3;
|
|
4
|
-
function optionalString(value) {
|
|
5
|
-
if (typeof value === "string") {
|
|
6
|
-
return value;
|
|
7
|
-
}
|
|
8
|
-
if (typeof value === "number" ||
|
|
9
|
-
typeof value === "boolean" ||
|
|
10
|
-
typeof value === "bigint") {
|
|
11
|
-
return String(value);
|
|
12
|
-
}
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
5
|
/**
|
|
16
6
|
* Minimal "card" template: a centred title with an optional subtitle. No
|
|
17
7
|
* badge or version — a clean, quieter alternative to `banner`.
|
|
@@ -25,7 +15,7 @@ export const cardTemplate = {
|
|
|
25
15
|
const pad = Math.round(width * 0.09);
|
|
26
16
|
const contentWidth = width - pad * 2;
|
|
27
17
|
const centreX = Math.round(width / 2);
|
|
28
|
-
const title = props.title;
|
|
18
|
+
const title = optionalString(props.title) ?? "";
|
|
29
19
|
const subtitle = optionalString(props.subtitle);
|
|
30
20
|
const hasSubtitle = subtitle !== undefined && subtitle !== "";
|
|
31
21
|
const titleFs = Math.round(height * 0.1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"card.js","sourceRoot":"","sources":["../../src/templates/card.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,WAAW,EACX,QAAQ,GACT,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"card.js","sourceRoot":"","sources":["../../src/templates/card.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,WAAW,EACX,QAAQ,GACT,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,aAAa,GAAG,CAAC,CAA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,GAAG;YAC1B,UAAU;YACV,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,IAAI,EAAE,EAAE;YACR,WAAW,EAAE,IAAI,CAAC,OAAO;YACzB,MAAM,EAAE,QAAQ;SACjB,CAAC,CACH;aACA,IAAI,CAAC,EAAE,CAAC,CAAC;QAEZ,MAAM,MAAM,GACV,MAAM,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,EAAE;YACjD,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE;gBACzB,CAAC,EAAE,OAAO;gBACV,CAAC,EAAE,MAAM,GAAG,GAAG;gBACf,UAAU;gBACV,QAAQ,EAAE,QAAQ;gBAClB,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,EAAE;gBACR,WAAW,EAAE,IAAI;gBACjB,MAAM,EAAE,QAAQ;aACjB,CAAC;YACJ,CAAC,CAAC,EAAE,CAAC;QAET,OAAO,IAAI,GAAG,MAAM,CAAC;IACvB,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Template } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Syntax-highlighted code snippet on a rounded panel over the configured
|
|
4
|
+
* background. Reads `code` and `language` from the props (as the original
|
|
5
|
+
* `image_text` / `image_lexer` frontmatter did), with an optional `title`
|
|
6
|
+
* above the panel and the configured footer below it.
|
|
7
|
+
*
|
|
8
|
+
* Highlighting uses Shiki, so token colours come from a real VS Code theme
|
|
9
|
+
* rather than being approximated.
|
|
10
|
+
*/
|
|
11
|
+
export declare const codeTemplate: Template;
|
|
12
|
+
//# sourceMappingURL=code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/templates/code.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA8B,QAAQ,EAAE,MAAM,aAAa,CAAC;AA2PxE;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,QA6J1B,CAAC"}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { highlightCode } from "../highlight.js";
|
|
2
|
+
import { escapeXml, textElement } from "../text.js";
|
|
3
|
+
import { optionalString } from "./props.js";
|
|
4
|
+
/** Fraction of the font size the baseline sits below the glyph box top. */
|
|
5
|
+
const ascentRatio = 0.78;
|
|
6
|
+
const ellipsis = "…";
|
|
7
|
+
/**
|
|
8
|
+
* Place the code panel within the image, leaving room above for a title and
|
|
9
|
+
* below for a footer when either is present.
|
|
10
|
+
*/
|
|
11
|
+
function layoutPanel(dimensions, config, titleFontSize, footerFontSize, hasTitle, hasFooter) {
|
|
12
|
+
const { width, height } = dimensions;
|
|
13
|
+
const shorter = Math.min(width, height);
|
|
14
|
+
const pad = Math.round(shorter * 0.05);
|
|
15
|
+
const gap = Math.round(shorter * 0.028);
|
|
16
|
+
const top = pad + (hasTitle ? titleFontSize + gap : 0);
|
|
17
|
+
const bottom = height - pad - (hasFooter ? footerFontSize + gap : 0);
|
|
18
|
+
return {
|
|
19
|
+
x: pad,
|
|
20
|
+
y: top,
|
|
21
|
+
width: width - pad * 2,
|
|
22
|
+
height: Math.max(1, bottom - top),
|
|
23
|
+
radius: Math.round(shorter * config.code.cornerScale),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Shrink a panel onto its content, keeping it centred in the space it was
|
|
28
|
+
* allotted. Both axes are floored so a small snippet still gets a panel with
|
|
29
|
+
* presence rather than a letterbox slot or a narrow strip.
|
|
30
|
+
*/
|
|
31
|
+
function hugPanel(available, wanted) {
|
|
32
|
+
const width = Math.min(available.width, Math.max(Math.round(wanted.width), Math.round(available.width * 0.55)));
|
|
33
|
+
// Floor relative to the panel's own width, so shrinking never leaves a
|
|
34
|
+
// sliver, and never taller than the space the font was fitted against.
|
|
35
|
+
const height = Math.min(available.height, Math.max(Math.round(wanted.height), Math.round(width * 0.25)));
|
|
36
|
+
return {
|
|
37
|
+
...available,
|
|
38
|
+
x: available.x + Math.round((available.width - width) / 2),
|
|
39
|
+
y: available.y + Math.round((available.height - height) / 2),
|
|
40
|
+
width,
|
|
41
|
+
height,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Pick the largest font size that fits the snippet in the panel on both axes,
|
|
46
|
+
* clamped to the configured bounds.
|
|
47
|
+
*
|
|
48
|
+
* The bounds are fractions of the image *width*, not its height: a share image
|
|
49
|
+
* is scaled to fit the width of whatever feed shows it, so width is what
|
|
50
|
+
* decides whether the code ends up legible. Keying the floor to height would
|
|
51
|
+
* let a landscape image render the same snippet at half the size of its square
|
|
52
|
+
* counterpart.
|
|
53
|
+
*/
|
|
54
|
+
function fitFontSize(highlighted, codeWidth, codeHeight, imageWidth, config) {
|
|
55
|
+
const { charWidthRatio, lineHeight, maxFontScale, minFontScale } = config.code;
|
|
56
|
+
const byWidth = codeWidth / (Math.max(1, highlighted.longestLine) * charWidthRatio);
|
|
57
|
+
const byHeight = codeHeight / (Math.max(1, highlighted.lines.length) * lineHeight);
|
|
58
|
+
const fitted = Math.min(byWidth, byHeight, imageWidth * maxFontScale);
|
|
59
|
+
return Math.max(1, Math.floor(Math.max(fitted, imageWidth * minFontScale)));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Width of the laid-out block in characters, measured from the lines actually
|
|
63
|
+
* being drawn. Narrower than the snippet's longest line whenever that line was
|
|
64
|
+
* dropped or clipped, which keeps the panel hugged tight to what is visible.
|
|
65
|
+
*/
|
|
66
|
+
function blockColumns(lines) {
|
|
67
|
+
let columns = 0;
|
|
68
|
+
for (const tokens of lines) {
|
|
69
|
+
const last = tokens.at(-1);
|
|
70
|
+
if (last !== undefined) {
|
|
71
|
+
columns = Math.max(columns, last.column + last.text.length);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return columns;
|
|
75
|
+
}
|
|
76
|
+
function ellipsisToken(column) {
|
|
77
|
+
return {
|
|
78
|
+
text: ellipsis,
|
|
79
|
+
column,
|
|
80
|
+
color: undefined,
|
|
81
|
+
opacity: 0.6,
|
|
82
|
+
bold: false,
|
|
83
|
+
italic: false,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Drop lines that cannot fit at the chosen font size, marking the truncation
|
|
88
|
+
* with an ellipsis line so the image never silently misrepresents the snippet.
|
|
89
|
+
* The marker takes the indentation of the first dropped line, so it reads as
|
|
90
|
+
* part of the block rather than as a stray mark in the left margin.
|
|
91
|
+
*/
|
|
92
|
+
function fitLines(lines, codeHeight, step) {
|
|
93
|
+
const maxLines = Math.max(1, Math.floor(codeHeight / step));
|
|
94
|
+
if (lines.length <= maxLines) {
|
|
95
|
+
return lines;
|
|
96
|
+
}
|
|
97
|
+
const kept = lines.slice(0, maxLines - 1);
|
|
98
|
+
const dropped = lines.slice(maxLines - 1).find((line) => line.length > 0);
|
|
99
|
+
return [...kept, [ellipsisToken(dropped?.[0]?.column ?? 0)]];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Clip a line to the columns that fit, ending it with an ellipsis. The font
|
|
103
|
+
* size is floored for legibility, so a wide enough snippet can still overrun
|
|
104
|
+
* the panel — clipping keeps it inside instead of bleeding off the image.
|
|
105
|
+
*
|
|
106
|
+
* Returns the line unchanged when it already fits, so the caller can count the
|
|
107
|
+
* clipped lines by identity.
|
|
108
|
+
*/
|
|
109
|
+
function clipLine(tokens, maxColumns) {
|
|
110
|
+
const last = tokens.at(-1);
|
|
111
|
+
if (last === undefined || last.column + last.text.length <= maxColumns) {
|
|
112
|
+
return tokens;
|
|
113
|
+
}
|
|
114
|
+
const clipped = [];
|
|
115
|
+
for (const token of tokens) {
|
|
116
|
+
if (token.column >= maxColumns) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
const room = maxColumns - token.column;
|
|
120
|
+
if (token.text.length <= room) {
|
|
121
|
+
clipped.push(token);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
clipped.push({ ...token, text: token.text.slice(0, room - 1) + ellipsis });
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
return clipped;
|
|
128
|
+
}
|
|
129
|
+
function plural(count, noun) {
|
|
130
|
+
return `${String(count)} ${noun}${count === 1 ? "" : "s"}`;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Tell the author when the snippet did not fit. Nothing in a finished image
|
|
134
|
+
* says the sample continued, so silent truncation is how a half-a-function
|
|
135
|
+
* share card ends up on someone else's timeline.
|
|
136
|
+
*/
|
|
137
|
+
function warnIfTruncated(config, dimensions, counts, total) {
|
|
138
|
+
const parts = [];
|
|
139
|
+
if (counts.dropped > 0) {
|
|
140
|
+
parts.push(`${String(counts.dropped)} of ${plural(total, "line")} dropped`);
|
|
141
|
+
}
|
|
142
|
+
if (counts.clipped > 0) {
|
|
143
|
+
parts.push(`${plural(counts.clipped, "line")} clipped to the panel width`);
|
|
144
|
+
}
|
|
145
|
+
if (parts.length === 0) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
config.onWarning(`code snippet does not fit the ${String(dimensions.width)}x${String(dimensions.height)}` +
|
|
149
|
+
` image at a legible size: ${parts.join(", ")}.` +
|
|
150
|
+
` Shorten the sample, or lower code.minFontScale to fit it in smaller.`);
|
|
151
|
+
}
|
|
152
|
+
function tokenSpan(token, x, charWidth, foreground) {
|
|
153
|
+
const fill = token.color ?? foreground;
|
|
154
|
+
const opacity = token.opacity === undefined
|
|
155
|
+
? ""
|
|
156
|
+
: ` fill-opacity="${String(token.opacity)}"`;
|
|
157
|
+
const weight = token.bold ? ` font-weight="700"` : "";
|
|
158
|
+
const style = token.italic ? ` font-style="italic"` : "";
|
|
159
|
+
return (`<tspan x="${String(Math.round(x + token.column * charWidth))}"` +
|
|
160
|
+
` fill="${fill}"${opacity}${weight}${style}>` +
|
|
161
|
+
`${escapeXml(token.text)}</tspan>`);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Syntax-highlighted code snippet on a rounded panel over the configured
|
|
165
|
+
* background. Reads `code` and `language` from the props (as the original
|
|
166
|
+
* `image_text` / `image_lexer` frontmatter did), with an optional `title`
|
|
167
|
+
* above the panel and the configured footer below it.
|
|
168
|
+
*
|
|
169
|
+
* Highlighting uses Shiki, so token colours come from a real VS Code theme
|
|
170
|
+
* rather than being approximated.
|
|
171
|
+
*/
|
|
172
|
+
export const codeTemplate = {
|
|
173
|
+
name: "code",
|
|
174
|
+
async render({ props, config, dimensions }) {
|
|
175
|
+
const { width, height } = dimensions;
|
|
176
|
+
const code = optionalString(props["code"]) ?? "";
|
|
177
|
+
const language = optionalString(props["language"]) ?? "text";
|
|
178
|
+
const theme = optionalString(props["theme"]) ?? config.code.theme;
|
|
179
|
+
const highlighted = await highlightCode(code, {
|
|
180
|
+
language,
|
|
181
|
+
theme,
|
|
182
|
+
tabSize: config.code.tabSize,
|
|
183
|
+
});
|
|
184
|
+
const title = optionalString(props.title);
|
|
185
|
+
const hasTitle = title !== undefined && title !== "";
|
|
186
|
+
const hasFooter = config.footer !== undefined && config.footer !== "";
|
|
187
|
+
const titleFs = Math.round(height * 0.045);
|
|
188
|
+
const footerFs = Math.round(height * 0.032);
|
|
189
|
+
const available = layoutPanel(dimensions, config, titleFs, footerFs, hasTitle, hasFooter);
|
|
190
|
+
const inner = Math.round(Math.min(available.width, available.height) * 0.07);
|
|
191
|
+
const codeWidth = Math.max(1, available.width - inner * 2);
|
|
192
|
+
const codeHeight = Math.max(1, available.height - inner * 2);
|
|
193
|
+
const fontSize = fitFontSize(highlighted, codeWidth, codeHeight, width, config);
|
|
194
|
+
const charWidth = fontSize * config.code.charWidthRatio;
|
|
195
|
+
const step = fontSize * config.code.lineHeight;
|
|
196
|
+
const maxColumns = Math.max(1, Math.floor(codeWidth / charWidth));
|
|
197
|
+
const fitted = fitLines(highlighted.lines, codeHeight, step);
|
|
198
|
+
let clipped = 0;
|
|
199
|
+
const lines = fitted.map((tokens) => {
|
|
200
|
+
const line = clipLine(tokens, maxColumns);
|
|
201
|
+
if (line !== tokens) {
|
|
202
|
+
clipped += 1;
|
|
203
|
+
}
|
|
204
|
+
return line;
|
|
205
|
+
});
|
|
206
|
+
warnIfTruncated(config, dimensions, { dropped: highlighted.lines.length - lines.length, clipped }, highlighted.lines.length);
|
|
207
|
+
// Padding reads best proportional to the text, not the panel — a snippet
|
|
208
|
+
// fitted down to a small size wants tighter margins. Only ever shrink, so
|
|
209
|
+
// the code area the font was fitted against stays valid.
|
|
210
|
+
const padding = Math.max(Math.min(inner, Math.round(fontSize * 1.6)), Math.round(inner * 0.35));
|
|
211
|
+
// Shrink the panel down onto the snippet so it isn't left floating in dead
|
|
212
|
+
// space — on a landscape image especially, a wide panel holding a narrow
|
|
213
|
+
// block leaves the code marooned off to one side.
|
|
214
|
+
const blockWidth = blockColumns(lines) * charWidth;
|
|
215
|
+
const panel = hugPanel(available, {
|
|
216
|
+
width: blockWidth + padding * 2,
|
|
217
|
+
height: lines.length * step + padding * 2,
|
|
218
|
+
});
|
|
219
|
+
// Code reads from the left edge, as it does in an editor. Indentation is
|
|
220
|
+
// carried by each token's column, so the snippet keeps its shape.
|
|
221
|
+
const originX = panel.x + padding;
|
|
222
|
+
const originY = panel.y + (panel.height - lines.length * step) / 2;
|
|
223
|
+
const shadowOffset = Math.max(1, Math.round(Math.min(width, height) * 0.01));
|
|
224
|
+
const shadow = `<rect x="${String(panel.x)}" y="${String(panel.y + shadowOffset)}"` +
|
|
225
|
+
` width="${String(panel.width)}" height="${String(panel.height)}"` +
|
|
226
|
+
` rx="${String(panel.radius)}" fill="#000000" fill-opacity="0.22"/>`;
|
|
227
|
+
const surface = `<rect x="${String(panel.x)}" y="${String(panel.y)}"` +
|
|
228
|
+
` width="${String(panel.width)}" height="${String(panel.height)}"` +
|
|
229
|
+
` rx="${String(panel.radius)}" fill="${highlighted.background}"` +
|
|
230
|
+
` stroke="#ffffff" stroke-opacity="0.12"/>`;
|
|
231
|
+
const body = lines
|
|
232
|
+
.map((tokens, index) => {
|
|
233
|
+
if (tokens.length === 0) {
|
|
234
|
+
return "";
|
|
235
|
+
}
|
|
236
|
+
const baseline = Math.round(originY +
|
|
237
|
+
index * step +
|
|
238
|
+
(step - fontSize) / 2 +
|
|
239
|
+
fontSize * ascentRatio);
|
|
240
|
+
const spans = tokens
|
|
241
|
+
.map((token) => tokenSpan(token, originX, charWidth, highlighted.foreground))
|
|
242
|
+
.join("");
|
|
243
|
+
return (`<text y="${String(baseline)}" xml:space="preserve"` +
|
|
244
|
+
` font-family="${escapeXml(config.code.fontFamily)}"` +
|
|
245
|
+
` font-size="${String(fontSize)}">${spans}</text>`);
|
|
246
|
+
})
|
|
247
|
+
.join("");
|
|
248
|
+
const heading = title !== undefined && title !== ""
|
|
249
|
+
? textElement(title, {
|
|
250
|
+
x: Math.round(width / 2),
|
|
251
|
+
y: panel.y - Math.round(titleFs * 0.42),
|
|
252
|
+
fontFamily: config.fontFamily,
|
|
253
|
+
fontSize: titleFs,
|
|
254
|
+
fontWeight: 700,
|
|
255
|
+
fill: config.colors.foreground,
|
|
256
|
+
fillOpacity: 0.95,
|
|
257
|
+
anchor: "middle",
|
|
258
|
+
})
|
|
259
|
+
: "";
|
|
260
|
+
const footer = hasFooter
|
|
261
|
+
? textElement(config.footer, {
|
|
262
|
+
x: Math.round(width / 2),
|
|
263
|
+
y: height - Math.round(Math.min(width, height) * 0.05),
|
|
264
|
+
fontFamily: config.fontFamily,
|
|
265
|
+
fontSize: footerFs,
|
|
266
|
+
fontWeight: 500,
|
|
267
|
+
fill: config.colors.foreground,
|
|
268
|
+
fillOpacity: 0.78,
|
|
269
|
+
anchor: "middle",
|
|
270
|
+
})
|
|
271
|
+
: "";
|
|
272
|
+
return heading + shadow + surface + body + footer;
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
//# sourceMappingURL=code.js.map
|
|
@@ -0,0 +1 @@
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IAAI,CAAC;gBACtD,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,QAAQ,EAAE,QAAQ;gBAClB,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU;gBAC9B,WAAW,EAAE,IAAI;gBACjB,MAAM,EAAE,QAAQ;aACjB,CAAC;YACJ,CAAC,CAAC,EAAE,CAAC;QAEP,OAAO,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC;IACpD,CAAC;CACF,CAAC"}
|
|
@@ -6,4 +6,6 @@ import type { Template } from "../types.js";
|
|
|
6
6
|
export declare const builtinTemplates: Readonly<Record<string, Template>>;
|
|
7
7
|
export { bannerTemplate } from "./banner.js";
|
|
8
8
|
export { cardTemplate } from "./card.js";
|
|
9
|
+
export { codeTemplate } from "./code.js";
|
|
10
|
+
export { optionalString } from "./props.js";
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAK5C;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAI/D,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/templates/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { bannerTemplate } from "./banner.js";
|
|
2
2
|
import { cardTemplate } from "./card.js";
|
|
3
|
+
import { codeTemplate } from "./code.js";
|
|
3
4
|
/**
|
|
4
5
|
* Templates registered out of the box. Projects can add to or override these
|
|
5
6
|
* via `config.templates`.
|
|
@@ -7,7 +8,10 @@ import { cardTemplate } from "./card.js";
|
|
|
7
8
|
export const builtinTemplates = {
|
|
8
9
|
[bannerTemplate.name]: bannerTemplate,
|
|
9
10
|
[cardTemplate.name]: cardTemplate,
|
|
11
|
+
[codeTemplate.name]: codeTemplate,
|
|
10
12
|
};
|
|
11
13
|
export { bannerTemplate } from "./banner.js";
|
|
12
14
|
export { cardTemplate } from "./card.js";
|
|
15
|
+
export { codeTemplate } from "./code.js";
|
|
16
|
+
export { optionalString } from "./props.js";
|
|
13
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAuC;IAClE,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,cAAc;IACrC,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,YAAY;CAClC,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAuC;IAClE,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,cAAc;IACrC,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,YAAY;IACjC,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,YAAY;CAClC,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a prop as a string, coercing the scalar types YAML frontmatter yields
|
|
3
|
+
* (numbers, booleans) and returning `undefined` for anything else — templates
|
|
4
|
+
* treat "not a usable string" and "absent" the same way.
|
|
5
|
+
*/
|
|
6
|
+
export declare function optionalString(value: unknown): string | undefined;
|
|
7
|
+
//# sourceMappingURL=props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/templates/props.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAcjE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a prop as a string, coercing the scalar types YAML frontmatter yields
|
|
3
|
+
* (numbers, booleans) and returning `undefined` for anything else — templates
|
|
4
|
+
* treat "not a usable string" and "absent" the same way.
|
|
5
|
+
*/
|
|
6
|
+
export function optionalString(value) {
|
|
7
|
+
if (typeof value === "string") {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
if (typeof value === "number" ||
|
|
11
|
+
typeof value === "boolean" ||
|
|
12
|
+
typeof value === "bigint") {
|
|
13
|
+
return String(value);
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.js","sourceRoot":"","sources":["../../src/templates/props.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,SAAS;QAC1B,OAAO,KAAK,KAAK,QAAQ,EACzB,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|