@kensio/colophon 2.2.0 → 2.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 +560 -24
- package/dist/cli/args.d.ts +14 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +67 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/config.d.ts +12 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +43 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +35 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli.js +34 -6
- package/dist/cli.js.map +1 -1
- package/dist/config/defaults.d.ts +64 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +64 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/index.d.ts +22 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +52 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/resolve.d.ts +24 -0
- package/dist/config/resolve.d.ts.map +1 -0
- package/dist/config/resolve.js +66 -0
- package/dist/config/resolve.js.map +1 -0
- package/dist/config/size.d.ts +20 -0
- package/dist/config/size.d.ts.map +1 -0
- package/dist/config/size.js +46 -0
- package/dist/config/size.js.map +1 -0
- package/dist/config.d.ts +27 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +78 -2
- package/dist/config.js.map +1 -1
- package/dist/content/index.d.ts +5 -51
- package/dist/content/index.d.ts.map +1 -1
- package/dist/content/index.js +3 -115
- package/dist/content/index.js.map +1 -1
- package/dist/content/props.d.ts +15 -0
- package/dist/content/props.d.ts.map +1 -0
- package/dist/content/props.js +71 -0
- package/dist/content/props.js.map +1 -0
- package/dist/content/slug.d.ts +23 -0
- package/dist/content/slug.d.ts.map +1 -0
- package/dist/content/slug.js +52 -0
- package/dist/content/slug.js.map +1 -0
- package/dist/content/walk.d.ts +17 -0
- package/dist/content/walk.d.ts.map +1 -0
- package/dist/content/walk.js +57 -0
- package/dist/content/walk.js.map +1 -0
- package/dist/fonts/index.d.ts +10 -0
- package/dist/fonts/index.d.ts.map +1 -0
- package/dist/fonts/index.js +11 -0
- package/dist/fonts/index.js.map +1 -0
- package/dist/fonts/materialise.d.ts +7 -0
- package/dist/fonts/materialise.d.ts.map +1 -0
- package/dist/fonts/materialise.js +47 -0
- package/dist/fonts/materialise.js.map +1 -0
- package/dist/fonts/resolve.d.ts +7 -0
- package/dist/fonts/resolve.d.ts.map +1 -0
- package/dist/fonts/resolve.js +50 -0
- package/dist/fonts/resolve.js.map +1 -0
- package/dist/fonts.d.ts +18 -0
- package/dist/fonts.d.ts.map +1 -0
- package/dist/fonts.js +102 -0
- package/dist/fonts.js.map +1 -0
- package/dist/generate/extra.d.ts +16 -0
- package/dist/generate/extra.d.ts.map +1 -0
- package/dist/generate/extra.js +60 -0
- package/dist/generate/extra.js.map +1 -0
- package/dist/generate/index.d.ts +19 -0
- package/dist/generate/index.d.ts.map +1 -0
- package/dist/generate/index.js +46 -0
- package/dist/generate/index.js.map +1 -0
- package/dist/generate/job.d.ts +35 -0
- package/dist/generate/job.d.ts.map +1 -0
- package/dist/generate/job.js +2 -0
- package/dist/generate/job.js.map +1 -0
- package/dist/generate/options.d.ts +56 -0
- package/dist/generate/options.d.ts.map +1 -0
- package/dist/generate/options.js +17 -0
- package/dist/generate/options.js.map +1 -0
- package/dist/generate/output-path.d.ts +12 -0
- package/dist/generate/output-path.d.ts.map +1 -0
- package/dist/generate/output-path.js +18 -0
- package/dist/generate/output-path.js.map +1 -0
- package/dist/generate/outputs.d.ts +28 -0
- package/dist/generate/outputs.d.ts.map +1 -0
- package/dist/generate/outputs.js +71 -0
- package/dist/generate/outputs.js.map +1 -0
- package/dist/generate/plan.d.ts +21 -0
- package/dist/generate/plan.d.ts.map +1 -0
- package/dist/generate/plan.js +72 -0
- package/dist/generate/plan.js.map +1 -0
- package/dist/generate/render-image.d.ts +11 -0
- package/dist/generate/render-image.d.ts.map +1 -0
- package/dist/generate/render-image.js +27 -0
- package/dist/generate/render-image.js.map +1 -0
- package/dist/generate.d.ts +27 -6
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +69 -15
- package/dist/generate.js.map +1 -1
- package/dist/highlight/color.d.ts +9 -0
- package/dist/highlight/color.d.ts.map +1 -0
- package/dist/highlight/color.js +15 -0
- package/dist/highlight/color.js.map +1 -0
- package/dist/highlight/grid.d.ts +14 -0
- package/dist/highlight/grid.d.ts.map +1 -0
- package/dist/highlight/grid.js +36 -0
- package/dist/highlight/grid.js.map +1 -0
- package/dist/highlight/index.d.ts +12 -0
- package/dist/highlight/index.d.ts.map +1 -0
- package/dist/highlight/index.js +31 -0
- package/dist/highlight/index.js.map +1 -0
- package/dist/highlight/language.d.ts +14 -0
- package/dist/highlight/language.d.ts.map +1 -0
- package/dist/highlight/language.js +42 -0
- package/dist/highlight/language.js.map +1 -0
- package/dist/highlight/normalise.d.ts +17 -0
- package/dist/highlight/normalise.d.ts.map +1 -0
- package/dist/highlight/normalise.js +37 -0
- package/dist/highlight/normalise.js.map +1 -0
- package/dist/highlight/types.d.ts +40 -0
- package/dist/highlight/types.d.ts.map +1 -0
- package/dist/highlight/types.js +2 -0
- package/dist/highlight/types.js.map +1 -0
- package/dist/index.d.ts +15 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/manifest/build.d.ts +14 -0
- package/dist/manifest/build.d.ts.map +1 -0
- package/dist/manifest/build.js +43 -0
- package/dist/manifest/build.js.map +1 -0
- package/dist/manifest/index.d.ts +27 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +31 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/order.d.ts +12 -0
- package/dist/manifest/order.d.ts.map +1 -0
- package/dist/manifest/order.js +17 -0
- package/dist/manifest/order.js.map +1 -0
- package/dist/manifest/page.d.ts +24 -0
- package/dist/manifest/page.d.ts.map +1 -0
- package/dist/manifest/page.js +55 -0
- package/dist/manifest/page.js.map +1 -0
- package/dist/meta/html.d.ts +14 -0
- package/dist/meta/html.d.ts.map +1 -0
- package/dist/meta/html.js +24 -0
- package/dist/meta/html.js.map +1 -0
- package/dist/meta/index.d.ts +11 -0
- package/dist/meta/index.d.ts.map +1 -0
- package/dist/meta/index.js +11 -0
- package/dist/meta/index.js.map +1 -0
- package/dist/meta/tags.d.ts +21 -0
- package/dist/meta/tags.d.ts.map +1 -0
- package/dist/meta/tags.js +72 -0
- package/dist/meta/tags.js.map +1 -0
- package/dist/meta/url.d.ts +15 -0
- package/dist/meta/url.d.ts.map +1 -0
- package/dist/meta/url.js +34 -0
- package/dist/meta/url.js.map +1 -0
- package/dist/placement/check.d.ts +16 -0
- package/dist/placement/check.d.ts.map +1 -0
- package/dist/placement/check.js +40 -0
- package/dist/placement/check.js.map +1 -0
- package/dist/placement/index.d.ts +29 -0
- package/dist/placement/index.d.ts.map +1 -0
- package/dist/placement/index.js +61 -0
- package/dist/placement/index.js.map +1 -0
- package/dist/placement/relative.d.ts +31 -0
- package/dist/placement/relative.d.ts.map +1 -0
- package/dist/placement/relative.js +53 -0
- package/dist/placement/relative.js.map +1 -0
- package/dist/pool.d.ts +18 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +56 -0
- package/dist/pool.js.map +1 -0
- package/dist/render/index.d.ts +10 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/index.js +27 -0
- package/dist/render/index.js.map +1 -0
- package/dist/render/png.d.ts +10 -0
- package/dist/render/png.d.ts.map +1 -0
- package/dist/render/png.js +30 -0
- package/dist/render/png.js.map +1 -0
- package/dist/render/svg.d.ts +10 -0
- package/dist/render/svg.d.ts.map +1 -0
- package/dist/render/svg.js +20 -0
- package/dist/render/svg.js.map +1 -0
- package/dist/render/template.d.ts +9 -0
- package/dist/render/template.d.ts.map +1 -0
- package/dist/render/template.js +17 -0
- package/dist/render/template.js.map +1 -0
- package/dist/render.d.ts +6 -2
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +31 -10
- package/dist/render.js.map +1 -1
- package/dist/stamp/chunk.d.ts +16 -0
- package/dist/stamp/chunk.d.ts.map +1 -0
- package/dist/stamp/chunk.js +46 -0
- package/dist/stamp/chunk.js.map +1 -0
- package/dist/stamp/config-digest.d.ts +11 -0
- package/dist/stamp/config-digest.d.ts.map +1 -0
- package/dist/stamp/config-digest.js +43 -0
- package/dist/stamp/config-digest.js.map +1 -0
- package/dist/stamp/digest.d.ts +8 -0
- package/dist/stamp/digest.d.ts.map +1 -0
- package/dist/stamp/digest.js +20 -0
- package/dist/stamp/digest.js.map +1 -0
- package/dist/stamp/index.d.ts +20 -0
- package/dist/stamp/index.d.ts.map +1 -0
- package/dist/stamp/index.js +40 -0
- package/dist/stamp/index.js.map +1 -0
- package/dist/stamp/read.d.ts +7 -0
- package/dist/stamp/read.d.ts.map +1 -0
- package/dist/stamp/read.js +62 -0
- package/dist/stamp/read.js.map +1 -0
- package/dist/stamp.d.ts +29 -0
- package/dist/stamp.d.ts.map +1 -0
- package/dist/stamp.js +198 -0
- package/dist/stamp.js.map +1 -0
- package/dist/templates/banner/badge.d.ts +7 -0
- package/dist/templates/banner/badge.d.ts.map +1 -0
- package/dist/templates/banner/badge.js +24 -0
- package/dist/templates/banner/badge.js.map +1 -0
- package/dist/templates/banner/index.d.ts +9 -0
- package/dist/templates/banner/index.d.ts.map +1 -0
- package/dist/templates/banner/index.js +66 -0
- package/dist/templates/banner/index.js.map +1 -0
- package/dist/templates/banner/lines.d.ts +27 -0
- package/dist/templates/banner/lines.d.ts.map +1 -0
- package/dist/templates/banner/lines.js +46 -0
- package/dist/templates/banner/lines.js.map +1 -0
- package/dist/templates/card/index.d.ts +7 -0
- package/dist/templates/card/index.d.ts.map +1 -0
- package/dist/templates/card/index.js +43 -0
- package/dist/templates/card/index.js.map +1 -0
- package/dist/templates/card/lines.d.ts +17 -0
- package/dist/templates/card/lines.d.ts.map +1 -0
- package/dist/templates/card/lines.js +32 -0
- package/dist/templates/card/lines.js.map +1 -0
- package/dist/templates/code/chrome.d.ts +9 -0
- package/dist/templates/code/chrome.d.ts.map +1 -0
- package/dist/templates/code/chrome.js +32 -0
- package/dist/templates/code/chrome.js.map +1 -0
- package/dist/templates/code/clip.d.ts +18 -0
- package/dist/templates/code/clip.d.ts.map +1 -0
- package/dist/templates/code/clip.js +44 -0
- package/dist/templates/code/clip.js.map +1 -0
- package/dist/templates/code/ellipsis.d.ts +3 -0
- package/dist/templates/code/ellipsis.d.ts.map +1 -0
- package/dist/templates/code/ellipsis.js +3 -0
- package/dist/templates/code/ellipsis.js.map +1 -0
- package/dist/templates/code/fit.d.ts +27 -0
- package/dist/templates/code/fit.d.ts.map +1 -0
- package/dist/templates/code/fit.js +59 -0
- package/dist/templates/code/fit.js.map +1 -0
- package/dist/templates/code/index.d.ts +12 -0
- package/dist/templates/code/index.d.ts.map +1 -0
- package/dist/templates/code/index.js +64 -0
- package/dist/templates/code/index.js.map +1 -0
- package/dist/templates/code/layout.d.ts +21 -0
- package/dist/templates/code/layout.d.ts.map +1 -0
- package/dist/templates/code/layout.js +21 -0
- package/dist/templates/code/layout.js.map +1 -0
- package/dist/templates/code/panel.d.ts +17 -0
- package/dist/templates/code/panel.d.ts.map +1 -0
- package/dist/templates/code/panel.js +20 -0
- package/dist/templates/code/panel.js.map +1 -0
- package/dist/templates/code/plate.d.ts +15 -0
- package/dist/templates/code/plate.d.ts.map +1 -0
- package/dist/templates/code/plate.js +32 -0
- package/dist/templates/code/plate.js.map +1 -0
- package/dist/templates/code/spans.d.ts +19 -0
- package/dist/templates/code/spans.d.ts.map +1 -0
- package/dist/templates/code/spans.js +36 -0
- package/dist/templates/code/spans.js.map +1 -0
- package/dist/templates/code/warn.d.ts +11 -0
- package/dist/templates/code/warn.d.ts.map +1 -0
- package/dist/templates/code/warn.js +24 -0
- package/dist/templates/code/warn.js.map +1 -0
- package/dist/templates/footer.d.ts +21 -0
- package/dist/templates/footer.d.ts.map +1 -0
- package/dist/templates/footer.js +25 -0
- package/dist/templates/footer.js.map +1 -0
- package/dist/templates/index.d.ts +3 -3
- package/dist/templates/index.d.ts.map +1 -1
- package/dist/templates/index.js +6 -6
- package/dist/templates/index.js.map +1 -1
- package/dist/text/element.d.ts +18 -0
- package/dist/text/element.d.ts.map +1 -0
- package/dist/text/element.js +19 -0
- package/dist/text/element.js.map +1 -0
- package/dist/text/escape.d.ts +5 -0
- package/dist/text/escape.d.ts.map +1 -0
- package/dist/text/escape.js +12 -0
- package/dist/text/escape.js.map +1 -0
- package/dist/text/index.d.ts +7 -0
- package/dist/text/index.d.ts.map +1 -0
- package/dist/text/index.js +5 -0
- package/dist/text/index.js.map +1 -0
- package/dist/text/stack.d.ts +24 -0
- package/dist/text/stack.d.ts.map +1 -0
- package/dist/text/stack.js +18 -0
- package/dist/text/stack.js.map +1 -0
- package/dist/text/wrap.d.ts +12 -0
- package/dist/text/wrap.d.ts.map +1 -0
- package/dist/text/wrap.js +33 -0
- package/dist/text/wrap.js.map +1 -0
- package/dist/types.d.ts +326 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/validate/check.d.ts +13 -0
- package/dist/validate/check.d.ts.map +1 -0
- package/dist/validate/check.js +34 -0
- package/dist/validate/check.js.map +1 -0
- package/dist/validate/index.d.ts +15 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +41 -0
- package/dist/validate/index.js.map +1 -0
- package/dist/validate/keys.d.ts +58 -0
- package/dist/validate/keys.d.ts.map +1 -0
- package/dist/validate/keys.js +166 -0
- package/dist/validate/keys.js.map +1 -0
- package/dist/validate/overrides.d.ts +5 -0
- package/dist/validate/overrides.d.ts.map +1 -0
- package/dist/validate/overrides.js +43 -0
- package/dist/validate/overrides.js.map +1 -0
- package/dist/validate/placement.d.ts +10 -0
- package/dist/validate/placement.d.ts.map +1 -0
- package/dist/validate/placement.js +38 -0
- package/dist/validate/placement.js.map +1 -0
- package/dist/validate/sizes.d.ts +9 -0
- package/dist/validate/sizes.d.ts.map +1 -0
- package/dist/validate/sizes.js +27 -0
- package/dist/validate/sizes.js.map +1 -0
- package/dist/validate/suggest.d.ts +10 -0
- package/dist/validate/suggest.d.ts.map +1 -0
- package/dist/validate/suggest.js +55 -0
- package/dist/validate/suggest.js.map +1 -0
- package/dist/validate/values.d.ts +21 -0
- package/dist/validate/values.d.ts.map +1 -0
- package/dist/validate/values.js +57 -0
- package/dist/validate/values.js.map +1 -0
- package/dist/validate.d.ts +15 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +300 -0
- package/dist/validate.js.map +1 -0
- package/package.json +13 -6
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { renderAsync } from "@resvg/resvg-js";
|
|
2
|
+
import { resolveConfig } from "../config/index.js";
|
|
3
|
+
import { fallbackFamily, fontFilePaths } from "../fonts/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Font options for the rasteriser: the configured font files, and whether to
|
|
6
|
+
* fall back to the machine's own.
|
|
7
|
+
*/
|
|
8
|
+
async function fontOptions(config) {
|
|
9
|
+
const fallback = fallbackFamily(config.fonts);
|
|
10
|
+
return {
|
|
11
|
+
loadSystemFonts: config.systemFonts,
|
|
12
|
+
fontFiles: await fontFilePaths(config.fonts),
|
|
13
|
+
...(fallback !== undefined && { defaultFontFamily: fallback }),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Rasterise an SVG string to a PNG buffer, scaled to `dimensions.width`.
|
|
18
|
+
*
|
|
19
|
+
* Text is drawn with the fonts named by `config`, which is what keeps the
|
|
20
|
+
* output the same on a laptop, in CI and in a container. Height follows the
|
|
21
|
+
* SVG's own aspect ratio; `buildSvg` sizes it to match.
|
|
22
|
+
*/
|
|
23
|
+
export async function renderSvgToPng(svg, dimensions, config = resolveConfig()) {
|
|
24
|
+
const rendered = await renderAsync(svg, {
|
|
25
|
+
fitTo: { mode: "width", value: dimensions.width },
|
|
26
|
+
font: await fontOptions(config),
|
|
27
|
+
});
|
|
28
|
+
return rendered.asPng();
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=png.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"png.js","sourceRoot":"","sources":["../../src/render/png.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlE;;;GAGG;AACH,KAAK,UAAU,WAAW,CACxB,MAAsB;IAEtB,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAE9C,OAAO;QACL,eAAe,EAAE,MAAM,CAAC,WAAW;QACnC,SAAS,EAAE,MAAM,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC;QAC5C,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,iBAAiB,EAAE,QAAQ,EAAE,CAAC;KAC/D,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,GAAW,EACX,UAAsB,EACtB,MAAM,GAAmB,aAAa,EAAE;IAExC,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE;QACtC,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE;QACjD,IAAI,EAAE,MAAM,WAAW,CAAC,MAAM,CAAC;KAChC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Dimensions, MetaImageProps, ResolvedConfig } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build the complete SVG document for one image: the enclosing `<svg>` root,
|
|
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.
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildSvg(props: MetaImageProps, config: ResolvedConfig, dimensions: Dimensions): Promise<string>;
|
|
10
|
+
//# sourceMappingURL=svg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../../src/render/svg.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAK9E;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,MAAM,CAAC,CAWjB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { backgroundSvg } from "../background.js";
|
|
2
|
+
import { selectTemplate } from "./template.js";
|
|
3
|
+
const backgroundId = "colophon-bg";
|
|
4
|
+
/**
|
|
5
|
+
* Build the complete SVG document for one image: the enclosing `<svg>` root,
|
|
6
|
+
* the config-driven background, and the template's foreground content.
|
|
7
|
+
*
|
|
8
|
+
* Asynchronous because a template may need to load resources — the `code`
|
|
9
|
+
* template fetches syntax grammars and themes on demand.
|
|
10
|
+
*/
|
|
11
|
+
export async function buildSvg(props, config, dimensions) {
|
|
12
|
+
const template = selectTemplate(config, props.template);
|
|
13
|
+
const background = backgroundSvg(config.background, dimensions, backgroundId);
|
|
14
|
+
const body = await template.render({ props, config, dimensions });
|
|
15
|
+
const { width, height } = dimensions;
|
|
16
|
+
return (`<svg width="${String(width)}" height="${String(height)}"` +
|
|
17
|
+
` viewBox="0 0 ${String(width)} ${String(height)}"` +
|
|
18
|
+
` xmlns="http://www.w3.org/2000/svg">${background}${body}</svg>`);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=svg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.js","sourceRoot":"","sources":["../../src/render/svg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,YAAY,GAAG,aAAa,CAAC;AAEnC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,KAAqB,EACrB,MAAsB,EACtB,UAAsB;IAEtB,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxD,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;IAC9E,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IAClE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;IAErC,OAAO,CACL,eAAe,MAAM,CAAC,KAAK,CAAC,aAAa,MAAM,CAAC,MAAM,CAAC,GAAG;QAC1D,iBAAiB,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG;QACnD,uCAAuC,UAAU,GAAG,IAAI,QAAQ,CACjE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ResolvedConfig, Template } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Look up the template a set of props asks for, failing with the names that
|
|
4
|
+
* are actually available. A template name comes from frontmatter, so getting
|
|
5
|
+
* it wrong is routine, and "unknown template" alone leaves the author guessing
|
|
6
|
+
* at what the project registered.
|
|
7
|
+
*/
|
|
8
|
+
export declare function selectTemplate(config: ResolvedConfig, name: string): Template;
|
|
9
|
+
//# sourceMappingURL=template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/render/template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAa7E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Look up the template a set of props asks for, failing with the names that
|
|
3
|
+
* are actually available. A template name comes from frontmatter, so getting
|
|
4
|
+
* it wrong is routine, and "unknown template" alone leaves the author guessing
|
|
5
|
+
* at what the project registered.
|
|
6
|
+
*/
|
|
7
|
+
export function selectTemplate(config, name) {
|
|
8
|
+
const template = config.templates[name];
|
|
9
|
+
if (template === undefined) {
|
|
10
|
+
const available = Object.keys(config.templates)
|
|
11
|
+
.toSorted((a, b) => a.localeCompare(b))
|
|
12
|
+
.join(", ");
|
|
13
|
+
throw new Error(`Unknown template "${name}". Available templates: ${available}.`);
|
|
14
|
+
}
|
|
15
|
+
return template;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/render/template.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAAsB,EAAE,IAAY;IACjE,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,CAAC"}
|
package/dist/render.d.ts
CHANGED
|
@@ -8,9 +8,13 @@ import type { ColophonConfig, Dimensions, MetaImageProps, RenderedMetaImage, Res
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function buildSvg(props: MetaImageProps, config: ResolvedConfig, dimensions: Dimensions): Promise<string>;
|
|
10
10
|
/**
|
|
11
|
-
* Rasterise an SVG string to a PNG buffer
|
|
11
|
+
* Rasterise an SVG string to a PNG buffer, scaled to `dimensions.width`.
|
|
12
|
+
*
|
|
13
|
+
* Text is drawn with the fonts named by `config`, which is what keeps the
|
|
14
|
+
* output the same on a laptop, in CI and in a container. Height follows the
|
|
15
|
+
* SVG's own aspect ratio; {@link buildSvg} sizes it to match.
|
|
12
16
|
*/
|
|
13
|
-
export declare function renderSvgToPng(svg: string, dimensions: Dimensions): Promise<Buffer>;
|
|
17
|
+
export declare function renderSvgToPng(svg: string, dimensions: Dimensions, config?: ResolvedConfig): Promise<Buffer>;
|
|
14
18
|
/**
|
|
15
19
|
* Render an image for every configured output size from a single set of props.
|
|
16
20
|
* This is the reusable core: it takes props and config and returns rendered
|
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAMA,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;AAkBD;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,UAAU,EACtB,MAAM,GAAE,cAAgC,GACvC,OAAO,CAAC,MAAM,CAAC,CAOjB;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,cAAc,EACrB,MAAM,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAiB9B"}
|
package/dist/render.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { renderAsync } from "@resvg/resvg-js";
|
|
2
2
|
import { backgroundSvg } from "./background.js";
|
|
3
|
-
import { resolveConfig } from "./config.js";
|
|
3
|
+
import { resolveConfig, resolveConfigForSize } from "./config.js";
|
|
4
|
+
import { fallbackFamily, fontFilePaths } from "./fonts.js";
|
|
4
5
|
const backgroundId = "colophon-bg";
|
|
5
6
|
function selectTemplate(config, name) {
|
|
6
7
|
const template = config.templates[name];
|
|
@@ -29,13 +30,30 @@ export async function buildSvg(props, config, dimensions) {
|
|
|
29
30
|
` xmlns="http://www.w3.org/2000/svg">${background}${body}</svg>`);
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
|
-
*
|
|
33
|
+
* Font options for the rasteriser: the configured font files, and whether to
|
|
34
|
+
* fall back to the machine's own.
|
|
33
35
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.
|
|
38
|
-
.
|
|
36
|
+
async function fontOptions(config) {
|
|
37
|
+
const fallback = fallbackFamily(config.fonts);
|
|
38
|
+
return {
|
|
39
|
+
loadSystemFonts: config.systemFonts,
|
|
40
|
+
fontFiles: await fontFilePaths(config.fonts),
|
|
41
|
+
...(fallback !== undefined && { defaultFontFamily: fallback }),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Rasterise an SVG string to a PNG buffer, scaled to `dimensions.width`.
|
|
46
|
+
*
|
|
47
|
+
* Text is drawn with the fonts named by `config`, which is what keeps the
|
|
48
|
+
* output the same on a laptop, in CI and in a container. Height follows the
|
|
49
|
+
* SVG's own aspect ratio; {@link buildSvg} sizes it to match.
|
|
50
|
+
*/
|
|
51
|
+
export async function renderSvgToPng(svg, dimensions, config = resolveConfig()) {
|
|
52
|
+
const rendered = await renderAsync(svg, {
|
|
53
|
+
fitTo: { mode: "width", value: dimensions.width },
|
|
54
|
+
font: await fontOptions(config),
|
|
55
|
+
});
|
|
56
|
+
return rendered.asPng();
|
|
39
57
|
}
|
|
40
58
|
/**
|
|
41
59
|
* Render an image for every configured output size from a single set of props.
|
|
@@ -47,9 +65,12 @@ export async function renderMetaImages(props, config) {
|
|
|
47
65
|
// Validate the template once up front so a bad name fails fast.
|
|
48
66
|
selectTemplate(resolved, props.template);
|
|
49
67
|
return Promise.all(resolved.sizes.map(async (size) => {
|
|
68
|
+
// Each size renders with its own overrides folded in, so one size wanting
|
|
69
|
+
// a smaller minimum font does not mean a second pass over everything.
|
|
70
|
+
const sizeConfig = resolveConfigForSize(config, size);
|
|
50
71
|
const dimensions = { width: size.width, height: size.height };
|
|
51
|
-
const svg = await buildSvg(props,
|
|
52
|
-
const png = await renderSvgToPng(svg, dimensions);
|
|
72
|
+
const svg = await buildSvg(props, sizeConfig, dimensions);
|
|
73
|
+
const png = await renderSvgToPng(svg, dimensions, sizeConfig);
|
|
53
74
|
return { name: size.name, dimensions, svg, png };
|
|
54
75
|
}));
|
|
55
76
|
}
|
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM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,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACtD,MAAM,UAAU,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;QAC9D,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;QAC1D,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;QAC9D,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IACnD,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PNG `tEXt` keyword the stamp is stored under. Keeping it in the image means
|
|
3
|
+
* there is no sidecar file to fall out of sync, and deleting an image deletes
|
|
4
|
+
* its stamp with it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const stampKeyword = "colophon";
|
|
7
|
+
/** The eight bytes every PNG file starts with. */
|
|
8
|
+
export declare const pngSignature: Buffer<ArrayBuffer>;
|
|
9
|
+
/** Signature + the whole `IHDR` chunk: length, type, 13 bytes of data, CRC. */
|
|
10
|
+
export declare const afterHeader: number;
|
|
11
|
+
/**
|
|
12
|
+
* Return `png` with the stamp embedded as a `tEXt` chunk, inserted straight
|
|
13
|
+
* after the header so it can be read back without decoding the image.
|
|
14
|
+
*/
|
|
15
|
+
export declare function stampPng(png: Buffer, stamp: string): Buffer;
|
|
16
|
+
//# sourceMappingURL=chunk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../../src/stamp/chunk.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,YAAY,aAAa,CAAC;AAEvC,kDAAkD;AAClD,eAAO,MAAM,YAAY,qBAEvB,CAAC;AAEH,+EAA+E;AAC/E,eAAO,MAAM,WAAW,QAAuC,CAAC;AAwBhE;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAc3D"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { crc32 } from "node:zlib";
|
|
2
|
+
/**
|
|
3
|
+
* PNG `tEXt` keyword the stamp is stored under. Keeping it in the image means
|
|
4
|
+
* there is no sidecar file to fall out of sync, and deleting an image deletes
|
|
5
|
+
* its stamp with it.
|
|
6
|
+
*/
|
|
7
|
+
export const stampKeyword = "colophon";
|
|
8
|
+
/** The eight bytes every PNG file starts with. */
|
|
9
|
+
export const pngSignature = Buffer.from([
|
|
10
|
+
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
|
|
11
|
+
]);
|
|
12
|
+
/** Signature + the whole `IHDR` chunk: length, type, 13 bytes of data, CRC. */
|
|
13
|
+
export const afterHeader = pngSignature.length + 4 + 4 + 13 + 4;
|
|
14
|
+
/**
|
|
15
|
+
* A PNG `tEXt` chunk: length, type, `keyword\0text`, CRC over type and data.
|
|
16
|
+
*/
|
|
17
|
+
function textChunk(keyword, text) {
|
|
18
|
+
const data = Buffer.concat([
|
|
19
|
+
Buffer.from(keyword, "latin1"),
|
|
20
|
+
Buffer.from([0]),
|
|
21
|
+
Buffer.from(text, "latin1"),
|
|
22
|
+
]);
|
|
23
|
+
const chunk = Buffer.alloc(4 + 4 + data.length + 4);
|
|
24
|
+
chunk.writeUInt32BE(data.length, 0);
|
|
25
|
+
chunk.write("tEXt", 4, "latin1");
|
|
26
|
+
data.copy(chunk, 8);
|
|
27
|
+
chunk.writeUInt32BE(crc32(chunk.subarray(4, 8 + data.length)), 8 + data.length);
|
|
28
|
+
return chunk;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Return `png` with the stamp embedded as a `tEXt` chunk, inserted straight
|
|
32
|
+
* after the header so it can be read back without decoding the image.
|
|
33
|
+
*/
|
|
34
|
+
export function stampPng(png, stamp) {
|
|
35
|
+
if (png.length < afterHeader ||
|
|
36
|
+
!png.subarray(0, pngSignature.length).equals(pngSignature) ||
|
|
37
|
+
png.toString("latin1", 12, 16) !== "IHDR") {
|
|
38
|
+
throw new Error("Cannot stamp: not a PNG image.");
|
|
39
|
+
}
|
|
40
|
+
return Buffer.concat([
|
|
41
|
+
png.subarray(0, afterHeader),
|
|
42
|
+
textChunk(stampKeyword, stamp),
|
|
43
|
+
png.subarray(afterHeader),
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=chunk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.js","sourceRoot":"","sources":["../../src/stamp/chunk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;AAEvC,kDAAkD;AAClD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC;IACtC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CAC/C,CAAC,CAAC;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAEhE;;GAEG;AACH,SAAS,SAAS,CAAC,OAAe,EAAE,IAAY;IAC9C,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAChB,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC;KAC5B,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
*
|
|
5
|
+
* `onWarning` is left out because it cannot change a pixel. So are `sizes` and
|
|
6
|
+
* `templates`: the one size and the one template an image actually uses go into
|
|
7
|
+
* its own stamp, so adding a third size or an unrelated custom template does
|
|
8
|
+
* not invalidate everything already on disk.
|
|
9
|
+
*/
|
|
10
|
+
export declare function configDigest(config: ResolvedConfig): Promise<string>;
|
|
11
|
+
//# sourceMappingURL=config-digest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-digest.d.ts","sourceRoot":"","sources":["../../src/stamp/config-digest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,aAAa,CAAC;AA0B9D;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAkB1E"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { sha256, stableStringify } from "./digest.js";
|
|
3
|
+
/**
|
|
4
|
+
* The installed Colophon version. The built-in templates ship in this package,
|
|
5
|
+
* so an upgrade can change what an image looks like without anything in the
|
|
6
|
+
* project changing; folding the version into the stamp makes that upgrade
|
|
7
|
+
* re-render rather than leave the old images in place.
|
|
8
|
+
*/
|
|
9
|
+
async function packageVersion() {
|
|
10
|
+
const manifest = await readFile(new URL("../../package.json", import.meta.url), "utf8");
|
|
11
|
+
return JSON.parse(manifest).version;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Digest one configured font by its contents, not its path: replacing the file
|
|
15
|
+
* at the same path changes every image drawn with it.
|
|
16
|
+
*/
|
|
17
|
+
async function fontDigest(font) {
|
|
18
|
+
const bytes = "data" in font ? font.data : await readFile(font.path);
|
|
19
|
+
return sha256(stableStringify({ family: font.family, bytes: sha256(bytes) }));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Digest the config fields that affect what an image looks like.
|
|
23
|
+
*
|
|
24
|
+
* `onWarning` is left out because it cannot change a pixel. So are `sizes` and
|
|
25
|
+
* `templates`: the one size and the one template an image actually uses go into
|
|
26
|
+
* its own stamp, so adding a third size or an unrelated custom template does
|
|
27
|
+
* not invalidate everything already on disk.
|
|
28
|
+
*/
|
|
29
|
+
export async function configDigest(config) {
|
|
30
|
+
const fonts = await Promise.all(config.fonts.map(async (font) => fontDigest(font)));
|
|
31
|
+
return sha256(stableStringify({
|
|
32
|
+
version: await packageVersion(),
|
|
33
|
+
colors: config.colors,
|
|
34
|
+
background: config.background,
|
|
35
|
+
fonts,
|
|
36
|
+
systemFonts: config.systemFonts,
|
|
37
|
+
fontFamily: config.fontFamily,
|
|
38
|
+
footer: config.footer,
|
|
39
|
+
badge: config.badge,
|
|
40
|
+
code: config.code,
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=config-digest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-digest.js","sourceRoot":"","sources":["../../src/stamp/config-digest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;;GAKG;AACH,KAAK,UAAU,cAAc;IAC3B,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAC7B,IAAI,GAAG,CAAC,oBAAoB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAC9C,MAAM,CACP,CAAC;IACF,OAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAyB,CAAC,OAAO,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,UAAU,CAAC,IAAgB;IACxC,MAAM,KAAK,GAAG,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrE,OAAO,MAAM,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AAChF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAsB;IACvD,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAC7B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CACnD,CAAC;IAEF,OAAO,MAAM,CACX,eAAe,CAAC;QACd,OAAO,EAAE,MAAM,cAAc,EAAE;QAC/B,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,KAAK;QACL,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** SHA-256 of a string or buffer, as hex. */
|
|
2
|
+
export declare function sha256(value: string | Uint8Array): string;
|
|
3
|
+
/**
|
|
4
|
+
* `JSON.stringify` with object keys sorted, so that reordering frontmatter
|
|
5
|
+
* without changing it does not look like a change.
|
|
6
|
+
*/
|
|
7
|
+
export declare function stableStringify(value: unknown): string;
|
|
8
|
+
//# sourceMappingURL=digest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../../src/stamp/digest.ts"],"names":[],"mappings":"AAEA,6CAA6C;AAC7C,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAEzD;AAMD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAUtD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
/** SHA-256 of a string or buffer, as hex. */
|
|
3
|
+
export function sha256(value) {
|
|
4
|
+
return createHash("sha256").update(value).digest("hex");
|
|
5
|
+
}
|
|
6
|
+
function isRecord(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* `JSON.stringify` with object keys sorted, so that reordering frontmatter
|
|
11
|
+
* without changing it does not look like a change.
|
|
12
|
+
*/
|
|
13
|
+
export function stableStringify(value) {
|
|
14
|
+
return JSON.stringify(value, (_key, raw) => isRecord(raw)
|
|
15
|
+
? Object.fromEntries(Object.keys(raw)
|
|
16
|
+
.toSorted((a, b) => a.localeCompare(b))
|
|
17
|
+
.map((key) => [key, raw[key]]))
|
|
18
|
+
: raw);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=digest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digest.js","sourceRoot":"","sources":["../../src/stamp/digest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,6CAA6C;AAC7C,MAAM,UAAU,MAAM,CAAC,KAA0B;IAC/C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,GAAY,EAAE,EAAE,CAClD,QAAQ,CAAC,GAAG,CAAC;QACX,CAAC,CAAC,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;aACb,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;aACtC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CACjC;QACH,CAAC,CAAC,GAAG,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MetaImageProps, OutputSize, ResolvedConfig } from "../types.js";
|
|
2
|
+
export { stampPng } from "./chunk.js";
|
|
3
|
+
export { readPngStamp } from "./read.js";
|
|
4
|
+
/**
|
|
5
|
+
* Computes stamps for the images rendered from one resolved config.
|
|
6
|
+
*/
|
|
7
|
+
export interface Stamper {
|
|
8
|
+
/**
|
|
9
|
+
* The stamp for one image: a digest of the props, the config and the size it
|
|
10
|
+
* was rendered from. Equal stamps mean re-rendering would produce the same
|
|
11
|
+
* image.
|
|
12
|
+
*/
|
|
13
|
+
stamp(props: MetaImageProps, size: OutputSize): string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Build a {@link Stamper} for a resolved config. Asynchronous because it reads
|
|
17
|
+
* the configured font files; do it once per run rather than once per image.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createStamper(config: ResolvedConfig): Promise<Stamper>;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stamp/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI9E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;CACxD;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAqC5E"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { configDigest } from "./config-digest.js";
|
|
2
|
+
import { sha256, stableStringify } from "./digest.js";
|
|
3
|
+
export { stampPng } from "./chunk.js";
|
|
4
|
+
export { readPngStamp } from "./read.js";
|
|
5
|
+
/**
|
|
6
|
+
* Build a {@link Stamper} for a resolved config. Asynchronous because it reads
|
|
7
|
+
* the configured font files; do it once per run rather than once per image.
|
|
8
|
+
*/
|
|
9
|
+
export async function createStamper(config) {
|
|
10
|
+
const base = await configDigest(config);
|
|
11
|
+
const templateDigests = new Map();
|
|
12
|
+
// A custom template is config the project controls, so its source counts as
|
|
13
|
+
// part of the input. Built-in templates are covered by the package version.
|
|
14
|
+
// Source text is all there is to go on: a template that reads something its
|
|
15
|
+
// own code does not name — a closed-over value, a file — can change without
|
|
16
|
+
// the stamp noticing, and needs `overwrite` to pick it up.
|
|
17
|
+
const templateDigest = (name) => {
|
|
18
|
+
const cached = templateDigests.get(name);
|
|
19
|
+
if (cached !== undefined) {
|
|
20
|
+
return cached;
|
|
21
|
+
}
|
|
22
|
+
const template = config.templates[name];
|
|
23
|
+
const digest = template === undefined ? "" : sha256(template.render.toString());
|
|
24
|
+
templateDigests.set(name, digest);
|
|
25
|
+
return digest;
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
stamp(props, size) {
|
|
29
|
+
return sha256(stableStringify([
|
|
30
|
+
base,
|
|
31
|
+
templateDigest(props.template),
|
|
32
|
+
// The whole size, not just its dimensions: a size carries its own
|
|
33
|
+
// config overrides, and changing one has to re-render that image.
|
|
34
|
+
size,
|
|
35
|
+
props,
|
|
36
|
+
]));
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stamp/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAczC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAsB;IACxD,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,eAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IAElD,4EAA4E;IAC5E,4EAA4E;IAC5E,4EAA4E;IAC5E,4EAA4E;IAC5E,2DAA2D;IAC3D,MAAM,cAAc,GAAG,CAAC,IAAY,EAAU,EAAE;QAC9C,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAEzC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACxC,MAAM,MAAM,GACV,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnE,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAClC,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,OAAO;QACL,KAAK,CAAC,KAAK,EAAE,IAAI;YACf,OAAO,MAAM,CACX,eAAe,CAAC;gBACd,IAAI;gBACJ,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC;gBAC9B,kEAAkE;gBAClE,kEAAkE;gBAClE,IAAI;gBACJ,KAAK;aACN,CAAC,CACH,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the stamp out of a PNG file. Returns `undefined` when the file is
|
|
3
|
+
* missing, unreadable, not a PNG, or carries no stamp — all of which mean the
|
|
4
|
+
* image cannot be shown to be up to date, so it should be rendered again.
|
|
5
|
+
*/
|
|
6
|
+
export declare function readPngStamp(file: string): Promise<string | undefined>;
|
|
7
|
+
//# sourceMappingURL=read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/stamp/read.ts"],"names":[],"mappings":"AAqDA;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgB5E"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { open } from "node:fs/promises";
|
|
2
|
+
import { pngSignature, stampKeyword } from "./chunk.js";
|
|
3
|
+
/**
|
|
4
|
+
* How much of a PNG to read when looking for a stamp. The stamp goes in
|
|
5
|
+
* immediately after `IHDR`, so this only has to cover the header — reading
|
|
6
|
+
* whole images just to compare a hash would defeat the point of skipping them.
|
|
7
|
+
*/
|
|
8
|
+
const headBytes = 4096;
|
|
9
|
+
/**
|
|
10
|
+
* Find the stamp in the leading bytes of a PNG, or `undefined` if there is
|
|
11
|
+
* none — the image was written by something else, or by a Colophon that did
|
|
12
|
+
* not stamp yet.
|
|
13
|
+
*/
|
|
14
|
+
function findStamp(head) {
|
|
15
|
+
if (!head.subarray(0, pngSignature.length).equals(pngSignature)) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
let offset = pngSignature.length;
|
|
19
|
+
while (offset + 8 <= head.length) {
|
|
20
|
+
const length = head.readUInt32BE(offset);
|
|
21
|
+
const type = head.toString("latin1", offset + 4, offset + 8);
|
|
22
|
+
const start = offset + 8;
|
|
23
|
+
const end = start + length;
|
|
24
|
+
// Image data starts here; anything past it is not worth reading for a hash.
|
|
25
|
+
if (type === "IDAT" || type === "IEND" || end > head.length) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
if (type === "tEXt") {
|
|
29
|
+
const data = head.subarray(start, end);
|
|
30
|
+
const separator = data.indexOf(0);
|
|
31
|
+
if (separator !== -1 &&
|
|
32
|
+
data.toString("latin1", 0, separator) === stampKeyword) {
|
|
33
|
+
return data.toString("latin1", separator + 1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
offset = end + 4;
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Read the stamp out of a PNG file. Returns `undefined` when the file is
|
|
42
|
+
* missing, unreadable, not a PNG, or carries no stamp — all of which mean the
|
|
43
|
+
* image cannot be shown to be up to date, so it should be rendered again.
|
|
44
|
+
*/
|
|
45
|
+
export async function readPngStamp(file) {
|
|
46
|
+
let handle;
|
|
47
|
+
try {
|
|
48
|
+
handle = await open(file, "r");
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const buffer = Buffer.alloc(headBytes);
|
|
55
|
+
const { bytesRead } = await handle.read(buffer, 0, headBytes, 0);
|
|
56
|
+
return findStamp(buffer.subarray(0, bytesRead));
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
await handle.close();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=read.js.map
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AC;gBAChB,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,CAAC,KAAK,YAAY,EACtD,CAAC;gBACD,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;QAED,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAY;IAC7C,IAAI,MAAkB,CAAC;IAEvB,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACvC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IAClD,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;AACH,CAAC"}
|
package/dist/stamp.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { MetaImageProps, OutputSize, ResolvedConfig } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Computes stamps for the images rendered from one resolved config.
|
|
4
|
+
*/
|
|
5
|
+
export interface Stamper {
|
|
6
|
+
/**
|
|
7
|
+
* The stamp for one image: a digest of the props, the config and the size it
|
|
8
|
+
* was rendered from. Equal stamps mean re-rendering would produce the same
|
|
9
|
+
* image.
|
|
10
|
+
*/
|
|
11
|
+
stamp(props: MetaImageProps, size: OutputSize): string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build a {@link Stamper} for a resolved config. Asynchronous because it reads
|
|
15
|
+
* the configured font files; do it once per run rather than once per image.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createStamper(config: ResolvedConfig): Promise<Stamper>;
|
|
18
|
+
/**
|
|
19
|
+
* Return `png` with the stamp embedded as a `tEXt` chunk, inserted straight
|
|
20
|
+
* after the header so it can be read back without decoding the image.
|
|
21
|
+
*/
|
|
22
|
+
export declare function stampPng(png: Buffer, stamp: string): Buffer;
|
|
23
|
+
/**
|
|
24
|
+
* Read the stamp out of a PNG file. Returns `undefined` when the file is
|
|
25
|
+
* missing, unreadable, not a PNG, or carries no stamp — all of which mean the
|
|
26
|
+
* image cannot be shown to be up to date, so it should be rendered again.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readPngStamp(file: string): Promise<string | undefined>;
|
|
29
|
+
//# sourceMappingURL=stamp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stamp.d.ts","sourceRoot":"","sources":["../src/stamp.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,cAAc,EACd,UAAU,EACV,cAAc,EACf,MAAM,YAAY,CAAC;AAkGpB;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;CACxD;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAqC5E;AAwBD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAc3D;AA2CD;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgB5E"}
|