@kensio/colophon 2.3.0 → 2.5.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 +107 -798
- package/dist/background/gradient.d.ts +12 -0
- package/dist/background/gradient.d.ts.map +1 -0
- package/dist/background/gradient.js +21 -0
- package/dist/background/gradient.js.map +1 -0
- package/dist/background/image.d.ts +14 -0
- package/dist/background/image.d.ts.map +1 -0
- package/dist/background/image.js +36 -0
- package/dist/background/image.js.map +1 -0
- package/dist/background/index.d.ts +13 -0
- package/dist/background/index.d.ts.map +1 -0
- package/dist/background/index.js +27 -0
- package/dist/background/index.js.map +1 -0
- package/dist/background/mesh.d.ts +12 -0
- package/dist/background/mesh.d.ts.map +1 -0
- package/dist/background/mesh.js +43 -0
- package/dist/background/mesh.js.map +1 -0
- package/dist/background.d.ts +7 -2
- package/dist/background.d.ts.map +1 -1
- package/dist/background.js +44 -1
- package/dist/background.js.map +1 -1
- package/dist/cli/args.d.ts +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +1 -1
- package/dist/cli/config.d.ts +1 -1
- package/dist/cli/config.js +1 -1
- package/dist/config/defaults.d.ts +8 -7
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +8 -8
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +14 -5
- package/dist/config/index.js.map +1 -1
- package/dist/config/resolve.d.ts +7 -0
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config/resolve.js +16 -0
- package/dist/config/resolve.js.map +1 -1
- package/dist/config/size.d.ts +7 -1
- package/dist/config/size.d.ts.map +1 -1
- package/dist/config/size.js +22 -9
- package/dist/config/size.js.map +1 -1
- package/dist/content/props.d.ts +2 -2
- package/dist/content/props.js +2 -2
- package/dist/content/slug.d.ts +5 -5
- package/dist/content/slug.js +6 -6
- package/dist/content/slug.js.map +1 -1
- package/dist/content/walk.d.ts +1 -1
- package/dist/content/walk.js +1 -1
- package/dist/fonts/index.d.ts +3 -2
- package/dist/fonts/index.d.ts.map +1 -1
- package/dist/fonts/index.js +3 -2
- package/dist/fonts/index.js.map +1 -1
- package/dist/fonts/resolve.js +1 -1
- package/dist/generate/extra.js +4 -4
- package/dist/generate/extra.js.map +1 -1
- package/dist/generate/options.d.ts +1 -1
- package/dist/generate/outputs.d.ts +4 -4
- package/dist/generate/outputs.js +4 -4
- package/dist/highlight/language.d.ts +2 -3
- package/dist/highlight/language.d.ts.map +1 -1
- package/dist/highlight/language.js +3 -4
- package/dist/highlight/language.js.map +1 -1
- package/dist/highlight/normalise.d.ts +2 -2
- package/dist/highlight/normalise.js +2 -2
- package/dist/image/index.d.ts +18 -0
- package/dist/image/index.d.ts.map +1 -0
- package/dist/image/index.js +42 -0
- package/dist/image/index.js.map +1 -0
- package/dist/image/jpeg.d.ts +10 -0
- package/dist/image/jpeg.d.ts.map +1 -0
- package/dist/image/jpeg.js +57 -0
- package/dist/image/jpeg.js.map +1 -0
- package/dist/image/load.d.ts +4 -0
- package/dist/image/load.d.ts.map +1 -0
- package/dist/image/load.js +60 -0
- package/dist/image/load.js.map +1 -0
- package/dist/image/media.d.ts +10 -0
- package/dist/image/media.d.ts.map +1 -0
- package/dist/image/media.js +37 -0
- package/dist/image/media.js.map +1 -0
- package/dist/image/resolve.d.ts +13 -0
- package/dist/image/resolve.d.ts.map +1 -0
- package/dist/image/resolve.js +38 -0
- package/dist/image/resolve.js.map +1 -0
- package/dist/image/size.d.ts +22 -0
- package/dist/image/size.d.ts.map +1 -0
- package/dist/image/size.js +60 -0
- package/dist/image/size.js.map +1 -0
- package/dist/image/svg.d.ts +12 -0
- package/dist/image/svg.d.ts.map +1 -0
- package/dist/image/svg.js +61 -0
- package/dist/image/svg.js.map +1 -0
- package/dist/image/uri.d.ts +9 -0
- package/dist/image/uri.d.ts.map +1 -0
- package/dist/image/uri.js +22 -0
- package/dist/image/uri.js.map +1 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/layout/block.d.ts +37 -0
- package/dist/layout/block.d.ts.map +1 -0
- package/dist/layout/block.js +26 -0
- package/dist/layout/block.js.map +1 -0
- package/dist/layout/box.d.ts +20 -0
- package/dist/layout/box.d.ts.map +1 -0
- package/dist/layout/box.js +61 -0
- package/dist/layout/box.js.map +1 -0
- package/dist/layout/distribute.d.ts +15 -0
- package/dist/layout/distribute.d.ts.map +1 -0
- package/dist/layout/distribute.js +30 -0
- package/dist/layout/distribute.js.map +1 -0
- package/dist/layout/image.d.ts +42 -0
- package/dist/layout/image.d.ts.map +1 -0
- package/dist/layout/image.js +34 -0
- package/dist/layout/image.js.map +1 -0
- package/dist/layout/index.d.ts +40 -0
- package/dist/layout/index.d.ts.map +1 -0
- package/dist/layout/index.js +30 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/layout/lines.d.ts +45 -0
- package/dist/layout/lines.d.ts.map +1 -0
- package/dist/layout/lines.js +71 -0
- package/dist/layout/lines.js.map +1 -0
- package/dist/layout/measure.d.ts +11 -0
- package/dist/layout/measure.d.ts.map +1 -0
- package/dist/layout/measure.js +11 -0
- package/dist/layout/measure.js.map +1 -0
- package/dist/layout/panel.d.ts +20 -0
- package/dist/layout/panel.d.ts.map +1 -0
- package/dist/layout/panel.js +22 -0
- package/dist/layout/panel.js.map +1 -0
- package/dist/layout/row.d.ts +15 -0
- package/dist/layout/row.d.ts.map +1 -0
- package/dist/layout/row.js +20 -0
- package/dist/layout/row.js.map +1 -0
- package/dist/layout/scrim.d.ts +23 -0
- package/dist/layout/scrim.d.ts.map +1 -0
- package/dist/layout/scrim.js +38 -0
- package/dist/layout/scrim.js.map +1 -0
- package/dist/layout/stack.d.ts +14 -0
- package/dist/layout/stack.d.ts.map +1 -0
- package/dist/layout/stack.js +19 -0
- package/dist/layout/stack.js.map +1 -0
- package/dist/layout/types.d.ts +49 -0
- package/dist/layout/types.d.ts.map +1 -0
- package/dist/layout/types.js +2 -0
- package/dist/layout/types.js.map +1 -0
- package/dist/manifest/build.d.ts +1 -1
- package/dist/manifest/build.js +1 -1
- package/dist/manifest/index.d.ts +1 -1
- package/dist/manifest/index.js +1 -1
- package/dist/manifest/order.d.ts +1 -1
- package/dist/manifest/order.js +1 -1
- package/dist/manifest/page.d.ts +2 -2
- package/dist/manifest/page.js +3 -3
- package/dist/measure/estimate.d.ts +10 -0
- package/dist/measure/estimate.d.ts.map +1 -0
- package/dist/measure/estimate.js +58 -0
- package/dist/measure/estimate.js.map +1 -0
- package/dist/measure/faces.d.ts +15 -0
- package/dist/measure/faces.d.ts.map +1 -0
- package/dist/measure/faces.js +70 -0
- package/dist/measure/faces.js.map +1 -0
- package/dist/measure/index.d.ts +16 -0
- package/dist/measure/index.d.ts.map +1 -0
- package/dist/measure/index.js +0 -0
- package/dist/measure/index.js.map +1 -0
- package/dist/measure/runs.d.ts +17 -0
- package/dist/measure/runs.d.ts.map +1 -0
- package/dist/measure/runs.js +39 -0
- package/dist/measure/runs.js.map +1 -0
- package/dist/measure/select.d.ts +13 -0
- package/dist/measure/select.d.ts.map +1 -0
- package/dist/measure/select.js +47 -0
- package/dist/measure/select.js.map +1 -0
- package/dist/meta/tags.d.ts +6 -6
- package/dist/meta/tags.js +6 -6
- package/dist/meta/url.d.ts +4 -4
- package/dist/meta/url.js +4 -4
- package/dist/placement/check.d.ts +1 -1
- package/dist/placement/check.js +1 -1
- package/dist/placement/index.js +1 -1
- package/dist/placement/relative.d.ts +3 -3
- package/dist/placement/relative.js +3 -3
- package/dist/pool.d.ts +2 -2
- package/dist/pool.js +3 -3
- package/dist/pool.js.map +1 -1
- package/dist/props.d.ts +7 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/props.js +17 -0
- package/dist/props.js.map +1 -0
- package/dist/render/svg.d.ts +4 -2
- package/dist/render/svg.d.ts.map +1 -1
- package/dist/render/svg.js +28 -6
- package/dist/render/svg.js.map +1 -1
- package/dist/stamp/config-digest.d.ts.map +1 -1
- package/dist/stamp/config-digest.js +21 -1
- package/dist/stamp/config-digest.js.map +1 -1
- package/dist/stamp/index.js +2 -2
- package/dist/stamp/index.js.map +1 -1
- package/dist/stamp/read.d.ts +1 -1
- package/dist/stamp/read.js +4 -4
- package/dist/templates/attribution.d.ts +17 -0
- package/dist/templates/attribution.d.ts.map +1 -0
- package/dist/templates/attribution.js +39 -0
- package/dist/templates/attribution.js.map +1 -0
- package/dist/templates/banner/badge-props.d.ts +16 -0
- package/dist/templates/banner/badge-props.d.ts.map +1 -0
- package/dist/templates/banner/badge-props.js +58 -0
- package/dist/templates/banner/badge-props.js.map +1 -0
- package/dist/templates/banner/badge.d.ts.map +1 -1
- package/dist/templates/banner/badge.js +3 -6
- package/dist/templates/banner/badge.js.map +1 -1
- package/dist/templates/banner/index.d.ts +3 -0
- package/dist/templates/banner/index.d.ts.map +1 -1
- package/dist/templates/banner/index.js +41 -37
- package/dist/templates/banner/index.js.map +1 -1
- package/dist/templates/banner/lines.d.ts +7 -12
- package/dist/templates/banner/lines.d.ts.map +1 -1
- package/dist/templates/banner/lines.js +23 -34
- package/dist/templates/banner/lines.js.map +1 -1
- package/dist/templates/banner/version.d.ts +9 -0
- package/dist/templates/banner/version.d.ts.map +1 -0
- package/dist/templates/banner/version.js +21 -0
- package/dist/templates/banner/version.js.map +1 -0
- package/dist/templates/card/index.d.ts +4 -1
- package/dist/templates/card/index.d.ts.map +1 -1
- package/dist/templates/card/index.js +37 -25
- package/dist/templates/card/index.js.map +1 -1
- package/dist/templates/card/lines.d.ts +17 -13
- package/dist/templates/card/lines.d.ts.map +1 -1
- package/dist/templates/card/lines.js +24 -20
- package/dist/templates/card/lines.js.map +1 -1
- package/dist/templates/code/chrome.d.ts +7 -3
- package/dist/templates/code/chrome.d.ts.map +1 -1
- package/dist/templates/code/chrome.js +12 -11
- package/dist/templates/code/chrome.js.map +1 -1
- package/dist/templates/code/clip.d.ts +1 -1
- package/dist/templates/code/clip.js +1 -1
- package/dist/templates/code/fit.d.ts +2 -2
- package/dist/templates/code/fit.d.ts.map +1 -1
- package/dist/templates/code/fit.js +4 -4
- package/dist/templates/code/fit.js.map +1 -1
- package/dist/templates/code/index.d.ts.map +1 -1
- package/dist/templates/code/index.js +7 -6
- package/dist/templates/code/index.js.map +1 -1
- package/dist/templates/code/layout.d.ts +1 -1
- package/dist/templates/code/layout.d.ts.map +1 -1
- package/dist/templates/code/layout.js +6 -6
- package/dist/templates/code/layout.js.map +1 -1
- package/dist/templates/code/panel.d.ts +13 -0
- package/dist/templates/code/panel.d.ts.map +1 -1
- package/dist/templates/code/panel.js +34 -2
- package/dist/templates/code/panel.js.map +1 -1
- package/dist/templates/code/plate.d.ts +3 -1
- package/dist/templates/code/plate.d.ts.map +1 -1
- package/dist/templates/code/plate.js +11 -9
- package/dist/templates/code/plate.js.map +1 -1
- package/dist/templates/code/spans.js +1 -1
- package/dist/templates/code/spans.js.map +1 -1
- package/dist/templates/code/width.d.ts +10 -0
- package/dist/templates/code/width.d.ts.map +1 -0
- package/dist/templates/code/width.js +26 -0
- package/dist/templates/code/width.js.map +1 -0
- package/dist/templates/footer.d.ts +8 -0
- package/dist/templates/footer.d.ts.map +1 -1
- package/dist/templates/footer.js +11 -1
- package/dist/templates/footer.js.map +1 -1
- package/dist/templates/index.d.ts +1 -1
- package/dist/templates/index.d.ts.map +1 -1
- package/dist/templates/index.js +1 -1
- package/dist/templates/index.js.map +1 -1
- package/dist/templates/logo.d.ts +15 -0
- package/dist/templates/logo.d.ts.map +1 -0
- package/dist/templates/logo.js +30 -0
- package/dist/templates/logo.js.map +1 -0
- package/dist/templates/measure.d.ts +11 -0
- package/dist/templates/measure.d.ts.map +1 -0
- package/dist/templates/measure.js +11 -0
- package/dist/templates/measure.js.map +1 -0
- package/dist/templates/props.d.ts +2 -2
- package/dist/templates/props.js +2 -2
- package/dist/templates/text.d.ts +37 -0
- package/dist/templates/text.d.ts.map +1 -0
- package/dist/templates/text.js +26 -0
- package/dist/templates/text.js.map +1 -0
- package/dist/text/break.d.ts +11 -0
- package/dist/text/break.d.ts.map +1 -0
- package/dist/text/break.js +30 -0
- package/dist/text/break.js.map +1 -0
- package/dist/text/fit.d.ts +30 -0
- package/dist/text/fit.d.ts.map +1 -0
- package/dist/text/fit.js +29 -0
- package/dist/text/fit.js.map +1 -0
- package/dist/text/index.d.ts +5 -3
- package/dist/text/index.d.ts.map +1 -1
- package/dist/text/index.js +3 -2
- package/dist/text/index.js.map +1 -1
- package/dist/text/wrap.d.ts +17 -7
- package/dist/text/wrap.d.ts.map +1 -1
- package/dist/text/wrap.js +25 -17
- package/dist/text/wrap.js.map +1 -1
- package/dist/texture/grain.d.ts +17 -0
- package/dist/texture/grain.d.ts.map +1 -0
- package/dist/texture/grain.js +29 -0
- package/dist/texture/grain.js.map +1 -0
- package/dist/texture/index.d.ts +11 -0
- package/dist/texture/index.d.ts.map +1 -0
- package/dist/texture/index.js +20 -0
- package/dist/texture/index.js.map +1 -0
- package/dist/texture/pattern.d.ts +17 -0
- package/dist/texture/pattern.d.ts.map +1 -0
- package/dist/texture/pattern.js +45 -0
- package/dist/texture/pattern.js.map +1 -0
- package/dist/texture/resolve.d.ts +16 -0
- package/dist/texture/resolve.d.ts.map +1 -0
- package/dist/texture/resolve.js +20 -0
- package/dist/texture/resolve.js.map +1 -0
- package/dist/theme/index.d.ts +27 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +41 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/presets.d.ts +38 -0
- package/dist/theme/presets.d.ts.map +1 -0
- package/dist/theme/presets.js +150 -0
- package/dist/theme/presets.js.map +1 -0
- package/dist/types.d.ts +281 -46
- package/dist/types.d.ts.map +1 -1
- package/dist/validate/background.d.ts +12 -0
- package/dist/validate/background.d.ts.map +1 -0
- package/dist/validate/background.js +53 -0
- package/dist/validate/background.js.map +1 -0
- package/dist/validate/collect.d.ts +9 -0
- package/dist/validate/collect.d.ts.map +1 -0
- package/dist/validate/collect.js +34 -0
- package/dist/validate/collect.js.map +1 -0
- package/dist/validate/index.d.ts +1 -1
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +3 -20
- package/dist/validate/index.js.map +1 -1
- package/dist/validate/keys.d.ts +35 -2
- package/dist/validate/keys.d.ts.map +1 -1
- package/dist/validate/keys.js +92 -3
- package/dist/validate/keys.js.map +1 -1
- package/dist/validate/overrides.d.ts.map +1 -1
- package/dist/validate/overrides.js +5 -1
- package/dist/validate/overrides.js.map +1 -1
- package/dist/validate/suggest.d.ts.map +1 -1
- package/dist/validate/suggest.js +21 -3
- package/dist/validate/suggest.js.map +1 -1
- package/dist/validate/texture.d.ts +11 -0
- package/dist/validate/texture.d.ts.map +1 -0
- package/dist/validate/texture.js +34 -0
- package/dist/validate/texture.js.map +1 -0
- package/dist/validate/values.d.ts +10 -10
- package/dist/validate/values.d.ts.map +1 -1
- package/dist/validate/values.js +21 -31
- package/dist/validate/values.js.map +1 -1
- package/package.json +7 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { sniffMediaType } from "./media.js";
|
|
3
|
+
import { aspectOf } from "./size.js";
|
|
4
|
+
/**
|
|
5
|
+
* Loaded images, keyed by the path they were read from. A build draws the same
|
|
6
|
+
* logo onto every image it generates, and the bytes are the largest thing in
|
|
7
|
+
* the SVG, so reading and encoding it once matters more here than it does for
|
|
8
|
+
* a font.
|
|
9
|
+
*/
|
|
10
|
+
const byPath = new Map();
|
|
11
|
+
/** The same for images given as bytes, keyed by the array itself. */
|
|
12
|
+
const byData = new WeakMap();
|
|
13
|
+
/**
|
|
14
|
+
* `Uint8Array.toBase64` reads better and is not on the oldest Node this
|
|
15
|
+
* package supports, so the encoding goes through a Buffer.
|
|
16
|
+
*/
|
|
17
|
+
function base64(bytes) {
|
|
18
|
+
// eslint-disable-next-line unicorn/prefer-uint8array-base64
|
|
19
|
+
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Turn bytes into something drawable: a `data:` URI and the proportions of the
|
|
23
|
+
* picture inside it.
|
|
24
|
+
*
|
|
25
|
+
* Inlining rather than referencing the file is what makes a generated image
|
|
26
|
+
* self-contained. The rasteriser would have to resolve a relative href against
|
|
27
|
+
* something, and there is nothing sensible to resolve it against when the SVG
|
|
28
|
+
* only ever exists in memory.
|
|
29
|
+
*/
|
|
30
|
+
function toAsset(bytes, label) {
|
|
31
|
+
const mediaType = sniffMediaType(bytes);
|
|
32
|
+
if (mediaType === undefined) {
|
|
33
|
+
throw new Error(`${label} is not an image this can read. PNG, JPEG, GIF, WebP and SVG` +
|
|
34
|
+
` are understood, and the bytes given match none of them.`);
|
|
35
|
+
}
|
|
36
|
+
// `Uint8Array.toBase64` would read better and does not exist on the oldest
|
|
37
|
+
// Node this package supports.
|
|
38
|
+
return {
|
|
39
|
+
href: `data:${mediaType};base64,${base64(bytes)}`,
|
|
40
|
+
aspect: aspectOf(bytes, mediaType) ?? 1,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function read(source, label) {
|
|
44
|
+
const bytes = "data" in source
|
|
45
|
+
? source.data
|
|
46
|
+
: new Uint8Array(await readFile(source.path));
|
|
47
|
+
return toAsset(bytes, label);
|
|
48
|
+
}
|
|
49
|
+
/** Load one image source, reusing the bytes across the images of a build. */
|
|
50
|
+
export function loadImage(source, label) {
|
|
51
|
+
if ("data" in source) {
|
|
52
|
+
const pending = byData.get(source.data) ?? read(source, label);
|
|
53
|
+
byData.set(source.data, pending);
|
|
54
|
+
return pending;
|
|
55
|
+
}
|
|
56
|
+
const pending = byPath.get(source.path) ?? read(source, label);
|
|
57
|
+
byPath.set(source.path, pending);
|
|
58
|
+
return pending;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=load.js.map
|
|
@@ -0,0 +1 @@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AC,CAAC;IAElD,OAAO,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,SAAS,CACvB,MAAmB,EACnB,KAAa;IAEb,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;QACrB,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC/D,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACjC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC/D,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The image formats a build can draw with. */
|
|
2
|
+
export type MediaType = "image/png" | "image/jpeg" | "image/gif" | "image/webp" | "image/svg+xml";
|
|
3
|
+
/**
|
|
4
|
+
* The format of some bytes, read from the bytes themselves rather than from
|
|
5
|
+
* the file extension. A file named `.png` that is really a JPEG renders either
|
|
6
|
+
* way once the `data:` URI says what it is, and a rename is not the sort of
|
|
7
|
+
* thing a build should fail over.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sniffMediaType(bytes: Uint8Array): MediaType | undefined;
|
|
10
|
+
//# sourceMappingURL=media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../src/image/media.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,MAAM,SAAS,GACnB,WAAW,GAAG,YAAY,GAAG,WAAW,GAAG,YAAY,GAAG,eAAe,CAAC;AAmB5E;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,SAAS,CAkBvE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function hasSignature(bytes, signature) {
|
|
2
|
+
return signature.every((byte, index) => bytes[index] === byte);
|
|
3
|
+
}
|
|
4
|
+
/** Whether the bytes at `offset` spell `text` in ASCII. */
|
|
5
|
+
function hasAscii(bytes, offset, text) {
|
|
6
|
+
return Array.from(text, (character, index) => [character, index]).every(([character, index]) => bytes[offset + index] === character.codePointAt(0));
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The format of some bytes, read from the bytes themselves rather than from
|
|
10
|
+
* the file extension. A file named `.png` that is really a JPEG renders either
|
|
11
|
+
* way once the `data:` URI says what it is, and a rename is not the sort of
|
|
12
|
+
* thing a build should fail over.
|
|
13
|
+
*/
|
|
14
|
+
export function sniffMediaType(bytes) {
|
|
15
|
+
if (hasSignature(bytes, [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])) {
|
|
16
|
+
return "image/png";
|
|
17
|
+
}
|
|
18
|
+
if (hasSignature(bytes, [0xff, 0xd8, 0xff])) {
|
|
19
|
+
return "image/jpeg";
|
|
20
|
+
}
|
|
21
|
+
if (hasAscii(bytes, 0, "GIF8")) {
|
|
22
|
+
return "image/gif";
|
|
23
|
+
}
|
|
24
|
+
if (hasAscii(bytes, 0, "RIFF") && hasAscii(bytes, 8, "WEBP")) {
|
|
25
|
+
return "image/webp";
|
|
26
|
+
}
|
|
27
|
+
return isSvg(bytes) ? "image/svg+xml" : undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* SVG is text, so it has no signature to match. Look for the opening tag in
|
|
31
|
+
* the first stretch of the file, past any declaration, doctype or comment.
|
|
32
|
+
*/
|
|
33
|
+
function isSvg(bytes) {
|
|
34
|
+
const head = new TextDecoder().decode(bytes.slice(0, 1024));
|
|
35
|
+
return /<svg[\s>]/i.test(head);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/image/media.ts"],"names":[],"mappings":"AAIA,SAAS,YAAY,CACnB,KAAiB,EACjB,SAA4B;IAE5B,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;AACjE,CAAC;AAED,2DAA2D;AAC3D,SAAS,QAAQ,CAAC,KAAiB,EAAE,MAAc,EAAE,IAAY;IAC/D,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,EACJ,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,SAAS,EAAE,KAAK,CAAU,CAClD,CAAC,KAAK,CACL,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAC3E,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAiB;IAC9C,IAAI,YAAY,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;QAC1E,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,IAAI,YAAY,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;QAC5C,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC;QAC/B,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,CAAC,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC;QAC7D,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC;AACpD,CAAC;AAED;;;GAGG;AACH,SAAS,KAAK,CAAC,KAAiB;IAC9B,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;IAC5D,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ImageSource } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Validate one image source and make its path absolute.
|
|
4
|
+
*
|
|
5
|
+
* Checked when the config is resolved rather than when the image is drawn, for
|
|
6
|
+
* the reason `fonts/resolve.ts` gives: an image that cannot be read is a blank
|
|
7
|
+
* corner on every generated file, and a blank corner does not say which path
|
|
8
|
+
* was wrong.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveImageSource(source: ImageSource, label: string): ImageSource;
|
|
11
|
+
/** The same for a source that may not be there at all. */
|
|
12
|
+
export declare function resolveOptionalImage(source: ImageSource | undefined, label: string): ImageSource | undefined;
|
|
13
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/image/resolve.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,MAAM,GACZ,WAAW,CAsCb;AAED,0DAA0D;AAC1D,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,KAAK,EAAE,MAAM,GACZ,WAAW,GAAG,SAAS,CAEzB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { existsSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Validate one image source and make its path absolute.
|
|
5
|
+
*
|
|
6
|
+
* Checked when the config is resolved rather than when the image is drawn, for
|
|
7
|
+
* the reason `fonts/resolve.ts` gives: an image that cannot be read is a blank
|
|
8
|
+
* corner on every generated file, and a blank corner does not say which path
|
|
9
|
+
* was wrong.
|
|
10
|
+
*/
|
|
11
|
+
export function resolveImageSource(source, label) {
|
|
12
|
+
const raw = source;
|
|
13
|
+
const hasPath = raw.path !== undefined;
|
|
14
|
+
const hasData = raw.data !== undefined;
|
|
15
|
+
if (hasPath && hasData) {
|
|
16
|
+
throw new Error(`${label} has both "path" and "data"; give one or the other.`);
|
|
17
|
+
}
|
|
18
|
+
if (raw.data !== undefined) {
|
|
19
|
+
if (raw.data.byteLength === 0) {
|
|
20
|
+
throw new Error(`${label} has empty image data.`);
|
|
21
|
+
}
|
|
22
|
+
return source;
|
|
23
|
+
}
|
|
24
|
+
if (raw.path === undefined || raw.path === "") {
|
|
25
|
+
throw new Error(`${label} needs a "path" to an image file, or its bytes as "data".`);
|
|
26
|
+
}
|
|
27
|
+
const absolute = path.resolve(raw.path);
|
|
28
|
+
if (!existsSync(absolute) || !statSync(absolute).isFile()) {
|
|
29
|
+
throw new Error(`${label}: image file not found at ${absolute} (from "${raw.path}").` +
|
|
30
|
+
` Relative paths resolve from the working directory.`);
|
|
31
|
+
}
|
|
32
|
+
return { path: absolute };
|
|
33
|
+
}
|
|
34
|
+
/** The same for a source that may not be there at all. */
|
|
35
|
+
export function resolveOptionalImage(source, label) {
|
|
36
|
+
return source === undefined ? undefined : resolveImageSource(source, label);
|
|
37
|
+
}
|
|
38
|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AAI,KAAK;YACnE,qDAAqD,CACxD,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC5B,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,oBAAoB,CAClC,MAA+B,EAC/B,KAAa;IAEb,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MediaType } from "./media.js";
|
|
2
|
+
/** How big an image is, in whatever units it states for itself. */
|
|
3
|
+
export interface Extent {
|
|
4
|
+
readonly width: number;
|
|
5
|
+
readonly height: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* How wide an image is against how tall, or `undefined` where the format does
|
|
9
|
+
* not say in any way this reads.
|
|
10
|
+
*
|
|
11
|
+
* Only the ratio is wanted. A template sizes a logo from the image it is
|
|
12
|
+
* drawing into rather than from the logo's own pixels, since the same logo has
|
|
13
|
+
* to work on a 1200x630 and a 1200x1200, and the ratio is what stops it being
|
|
14
|
+
* stretched or given a square of space it does not fill.
|
|
15
|
+
*
|
|
16
|
+
* WebP is deliberately absent. Its dimensions live in one of three different
|
|
17
|
+
* chunk layouts depending on how it was encoded, and a logo is a PNG or an SVG
|
|
18
|
+
* often enough that guessing at bit-packed headers is not worth the risk of
|
|
19
|
+
* getting one of them subtly wrong.
|
|
20
|
+
*/
|
|
21
|
+
export declare function aspectOf(bytes: Uint8Array, mediaType: MediaType): number | undefined;
|
|
22
|
+
//# sourceMappingURL=size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.d.ts","sourceRoot":"","sources":["../../src/image/size.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,mEAAmE;AACnE,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAuBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,SAAS,GACnB,MAAM,GAAG,SAAS,CAMpB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jpegExtent } from "./jpeg.js";
|
|
2
|
+
import { svgExtent } from "./svg.js";
|
|
3
|
+
function view(bytes) {
|
|
4
|
+
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
5
|
+
}
|
|
6
|
+
/** PNG states its size in the IHDR chunk, which is always the first one. */
|
|
7
|
+
function pngExtent(bytes) {
|
|
8
|
+
return bytes.length < 24
|
|
9
|
+
? undefined
|
|
10
|
+
: { width: view(bytes).getUint32(16), height: view(bytes).getUint32(20) };
|
|
11
|
+
}
|
|
12
|
+
/** GIF states its screen size in the header, little-endian. */
|
|
13
|
+
function gifExtent(bytes) {
|
|
14
|
+
return bytes.length < 10
|
|
15
|
+
? undefined
|
|
16
|
+
: {
|
|
17
|
+
width: view(bytes).getUint16(6, true),
|
|
18
|
+
height: view(bytes).getUint16(8, true),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* How wide an image is against how tall, or `undefined` where the format does
|
|
23
|
+
* not say in any way this reads.
|
|
24
|
+
*
|
|
25
|
+
* Only the ratio is wanted. A template sizes a logo from the image it is
|
|
26
|
+
* drawing into rather than from the logo's own pixels, since the same logo has
|
|
27
|
+
* to work on a 1200x630 and a 1200x1200, and the ratio is what stops it being
|
|
28
|
+
* stretched or given a square of space it does not fill.
|
|
29
|
+
*
|
|
30
|
+
* WebP is deliberately absent. Its dimensions live in one of three different
|
|
31
|
+
* chunk layouts depending on how it was encoded, and a logo is a PNG or an SVG
|
|
32
|
+
* often enough that guessing at bit-packed headers is not worth the risk of
|
|
33
|
+
* getting one of them subtly wrong.
|
|
34
|
+
*/
|
|
35
|
+
export function aspectOf(bytes, mediaType) {
|
|
36
|
+
const extent = extentOf(bytes, mediaType);
|
|
37
|
+
return extent === undefined || extent.height <= 0
|
|
38
|
+
? undefined
|
|
39
|
+
: extent.width / extent.height;
|
|
40
|
+
}
|
|
41
|
+
function extentOf(bytes, mediaType) {
|
|
42
|
+
switch (mediaType) {
|
|
43
|
+
case "image/png": {
|
|
44
|
+
return pngExtent(bytes);
|
|
45
|
+
}
|
|
46
|
+
case "image/gif": {
|
|
47
|
+
return gifExtent(bytes);
|
|
48
|
+
}
|
|
49
|
+
case "image/jpeg": {
|
|
50
|
+
return jpegExtent(bytes);
|
|
51
|
+
}
|
|
52
|
+
case "image/svg+xml": {
|
|
53
|
+
return svgExtent(bytes);
|
|
54
|
+
}
|
|
55
|
+
case "image/webp": {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.js","sourceRoot":"","sources":["../../src/image/size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAQrC,SAAS,IAAI,CAAC,KAAiB;IAC7B,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;AACxE,CAAC;AAED,4EAA4E;AAC5E,SAAS,SAAS,CAAC,KAAiB;IAClC,OAAO,KAAK,CAAC,MAAM,GAAG,EAAE;QACtB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,C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";
|
|
2
|
+
/**
|
|
3
|
+
* The proportions of an SVG, which are what a template needs: an SVG has no
|
|
4
|
+
* pixels of its own, so only the ratio between its width and height means
|
|
5
|
+
* anything here.
|
|
6
|
+
*
|
|
7
|
+
* `width` and `height` are read first and `viewBox` second, which is the order
|
|
8
|
+
* a renderer resolves them in. A document with neither is left unmeasured
|
|
9
|
+
* rather than assumed to be square, since a wordmark usually has neither.
|
|
10
|
+
*/
|
|
11
|
+
export declare function svgExtent(bytes: Uint8Array): Extent | undefined;
|
|
12
|
+
//# sourceMappingURL=svg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../../src/image/svg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAwCxC;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAyB/D"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The attributes of the root `<svg>` element that say how big it is. Written
|
|
3
|
+
* out rather than built from a name, since there are three of them and a
|
|
4
|
+
* pattern assembled from a string is harder to read than the three patterns.
|
|
5
|
+
*/
|
|
6
|
+
const attributes = {
|
|
7
|
+
width: /\swidth\s*=\s*"([^"]*)"/i,
|
|
8
|
+
height: /\sheight\s*=\s*"([^"]*)"/i,
|
|
9
|
+
viewBox: /\sviewBox\s*=\s*"([^"]*)"/i,
|
|
10
|
+
};
|
|
11
|
+
/** The value of one of them, where the root element carries it. */
|
|
12
|
+
function attribute(head, name) {
|
|
13
|
+
return attributes[name].exec(head)?.[1];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A length such as `120`, `120px` or `7.5em`, as far as its number goes.
|
|
17
|
+
*
|
|
18
|
+
* A percentage is not one of them. `width="100%"` is the commonest way an
|
|
19
|
+
* export states that it scales to its container, and reading it as 100 units
|
|
20
|
+
* would make every such file square whatever its `viewBox` says.
|
|
21
|
+
*/
|
|
22
|
+
function length(value) {
|
|
23
|
+
if (value?.trim().endsWith("%") === true) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
// Deliberately parseFloat rather than Number: a length may carry a unit,
|
|
27
|
+
// and `6em` is six of something rather than not a number.
|
|
28
|
+
// eslint-disable-next-line unicorn/prefer-number-coercion
|
|
29
|
+
const number = Number.parseFloat(value ?? "");
|
|
30
|
+
return Number.isFinite(number) && number > 0 ? number : undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The proportions of an SVG, which are what a template needs: an SVG has no
|
|
34
|
+
* pixels of its own, so only the ratio between its width and height means
|
|
35
|
+
* anything here.
|
|
36
|
+
*
|
|
37
|
+
* `width` and `height` are read first and `viewBox` second, which is the order
|
|
38
|
+
* a renderer resolves them in. A document with neither is left unmeasured
|
|
39
|
+
* rather than assumed to be square, since a wordmark usually has neither.
|
|
40
|
+
*/
|
|
41
|
+
export function svgExtent(bytes) {
|
|
42
|
+
const head = new TextDecoder().decode(bytes.slice(0, 4096));
|
|
43
|
+
const root = /<svg[\s>][^>]*/i.exec(head)?.[0] ?? "";
|
|
44
|
+
const width = length(attribute(root, "width"));
|
|
45
|
+
const height = length(attribute(root, "height"));
|
|
46
|
+
if (width !== undefined && height !== undefined) {
|
|
47
|
+
return { width, height };
|
|
48
|
+
}
|
|
49
|
+
const box = attribute(root, "viewBox")
|
|
50
|
+
?.trim()
|
|
51
|
+
.split(/[\s,]+/);
|
|
52
|
+
if (box?.length !== 4) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
const boxWidth = length(box[2]);
|
|
56
|
+
const boxHeight = length(box[3]);
|
|
57
|
+
return boxWidth === undefined || boxHeight === undefined
|
|
58
|
+
? undefined
|
|
59
|
+
: { width: boxWidth, height: boxHeight };
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=svg.js.map
|
|
@@ -0,0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CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEjD,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAChD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAC3B,CAAC;IAED,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC;QACpC,EAAE,IAAI,EAAE;SACP,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEnB,IAAI,GAAG,EAAE,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAEjC,OAAO,QAAQ,KAAK,SAAS,IAAI,SAAS,KAAK,SAAS;QACtD,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bytes behind a `data:` URI, so that an image already inline is measured
|
|
3
|
+
* and checked on the same terms as one read from disk.
|
|
4
|
+
*
|
|
5
|
+
* A prop can carry either, since frontmatter written by hand names a file and
|
|
6
|
+
* frontmatter written by a props mapper may have the image already.
|
|
7
|
+
*/
|
|
8
|
+
export declare function bytesFromDataUri(uri: string, label: string): Uint8Array;
|
|
9
|
+
//# sourceMappingURL=uri.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uri.d.ts","sourceRoot":"","sources":["../../src/image/uri.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAgBvE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bytes behind a `data:` URI, so that an image already inline is measured
|
|
3
|
+
* and checked on the same terms as one read from disk.
|
|
4
|
+
*
|
|
5
|
+
* A prop can carry either, since frontmatter written by hand names a file and
|
|
6
|
+
* frontmatter written by a props mapper may have the image already.
|
|
7
|
+
*/
|
|
8
|
+
export function bytesFromDataUri(uri, label) {
|
|
9
|
+
const comma = uri.indexOf(",");
|
|
10
|
+
const head = comma === -1 ? "" : uri.slice(0, comma);
|
|
11
|
+
const body = comma === -1 ? "" : uri.slice(comma + 1);
|
|
12
|
+
if (comma === -1) {
|
|
13
|
+
throw new Error(`${label} is a "data:" URI with no comma in it.`);
|
|
14
|
+
}
|
|
15
|
+
if (head.endsWith(";base64")) {
|
|
16
|
+
// `Uint8Array.fromBase64` is not on the oldest Node this package supports.
|
|
17
|
+
// eslint-disable-next-line unicorn/prefer-uint8array-base64
|
|
18
|
+
return Buffer.from(body, "base64");
|
|
19
|
+
}
|
|
20
|
+
return new TextEncoder().encode(decodeURIComponent(body));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=uri.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uri.js","sourceRoot":"","sources":["../../src/image/uri.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,KAAa;IACzD,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACrD,MAAM,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAEtD,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,wCAAwC,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,2EAA2E;QAC3E,4DAA4D;QAC5D,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;AAC5D,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export type { Background, Badge, BrandColors, CodeStyle, ColophonConfig, ColophonConfigFactory, ColophonConfigInput, ContentFile, ContentOptions, Dimensions, ExtraImage, FontSource, GradientStop, Manifest, ManifestImage, ManifestPage, MetaImageProps, MetaTag, MetaTagOptions, OutputSize, Placement, PropsFromFrontmatter, RenderedMetaImage, SlugStrategy, SizeOverrides, ResolvedConfig, Template, TemplateContext, WarningHandler, } from "./types.js";
|
|
1
|
+
export type { Background, Badge, BrandColors, CodeStyle, ColophonConfig, ColophonConfigFactory, ColophonConfigInput, ContentFile, ContentOptions, Dimensions, ExtraImage, FontSource, GradientStop, Manifest, ManifestImage, ManifestPage, MeshBlob, MetaImageProps, MeasureText, MetaTag, MetaTagOptions, OutputSize, Placement, PropsFromFrontmatter, RenderedMetaImage, SlugStrategy, SizeOverrides, ResolvedConfig, Template, TemplateContext, Texture, TextStyle, ThemeName, WarningHandler, } from "./types.js";
|
|
2
2
|
export { DEFAULT_CODE_FONT_FAMILY, DEFAULT_CODE_STYLE, DEFAULT_COLORS, DEFAULT_FONT_FAMILY, DEFAULT_SIZES, defineConfig, resolveConfig, SIZE_PRESETS, } from "./config/index.js";
|
|
3
3
|
export { resolveConfigForSize } from "./config/size.js";
|
|
4
|
-
export { backgroundSvg } from "./background.js";
|
|
4
|
+
export { backgroundSvg } from "./background/index.js";
|
|
5
|
+
export { textureSvg } from "./texture/index.js";
|
|
5
6
|
export { buildSvg, renderMetaImages, renderSvgToPng } from "./render/index.js";
|
|
6
7
|
export { bannerTemplate, builtinTemplates, cardTemplate, codeTemplate, } from "./templates/index.js";
|
|
7
8
|
export { dedent, expandTabs, highlightCode, resolveLanguage, } from "./highlight/index.js";
|
|
@@ -10,7 +11,11 @@ export { defaultOutputPath, generate } from "./generate/index.js";
|
|
|
10
11
|
export type { GeneratedImage, GenerateOptions } from "./generate/index.js";
|
|
11
12
|
export { createStamper, readPngStamp, stampPng } from "./stamp/index.js";
|
|
12
13
|
export type { Stamper } from "./stamp/index.js";
|
|
13
|
-
export {
|
|
14
|
+
export { createMeasurer } from "./measure/index.js";
|
|
15
|
+
export { escapeXml, fitText, textElement, wrapText } from "./text/index.js";
|
|
16
|
+
export type { FitOptions, FittedText, MeasureAt, MeasureLine, TextAttributes, } from "./text/index.js";
|
|
17
|
+
export { blockLines, box, distribute, drawLines, image, inset, measureIn, optionalString, panel, placeLines, row, scrim, stack, } from "./layout/index.js";
|
|
18
|
+
export type { Align, BoxStyle, Extent, ImageOptions, LinesStyle, Placed, PlacedLine, PanelStyle, Rect, RowRect, ScrimOptions, Span, StackedRect, StyledBlock, TextBlock, TextLine, } from "./layout/index.js";
|
|
14
19
|
export { extractProps, slugFromPath, walkContent } from "./content/index.js";
|
|
15
20
|
export type { WalkOptions } from "./content/index.js";
|
|
16
21
|
export { metaTags, metaTagsHtml } from "./meta/index.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,KAAK,EACL,WAAW,EACX,SAAS,EACT,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,UAAU,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,cAAc,EACd,OAAO,EACP,cAAc,EACd,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,QAAQ,EACR,eAAe,EACf,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,KAAK,EACL,WAAW,EACX,SAAS,EACT,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,UAAU,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,WAAW,EACX,OAAO,EACP,cAAc,EACd,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,QAAQ,EACR,eAAe,EACf,OAAO,EACP,SAAS,EACT,SAAS,EACT,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM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B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC7E,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
export { DEFAULT_CODE_FONT_FAMILY, DEFAULT_CODE_STYLE, DEFAULT_COLORS, DEFAULT_FONT_FAMILY, DEFAULT_SIZES, defineConfig, resolveConfig, SIZE_PRESETS, } from "./config/index.js";
|
|
2
2
|
export { resolveConfigForSize } from "./config/size.js";
|
|
3
|
-
export { backgroundSvg } from "./background.js";
|
|
3
|
+
export { backgroundSvg } from "./background/index.js";
|
|
4
|
+
export { textureSvg } from "./texture/index.js";
|
|
4
5
|
export { buildSvg, renderMetaImages, renderSvgToPng } from "./render/index.js";
|
|
5
6
|
export { bannerTemplate, builtinTemplates, cardTemplate, codeTemplate, } from "./templates/index.js";
|
|
6
7
|
export { dedent, expandTabs, highlightCode, resolveLanguage, } from "./highlight/index.js";
|
|
7
8
|
export { defaultOutputPath, generate } from "./generate/index.js";
|
|
8
9
|
export { createStamper, readPngStamp, stampPng } from "./stamp/index.js";
|
|
9
|
-
export {
|
|
10
|
+
export { createMeasurer } from "./measure/index.js";
|
|
11
|
+
export { escapeXml, fitText, textElement, wrapText } from "./text/index.js";
|
|
12
|
+
// The layout toolkit, which also has its own `@kensio/colophon/layout` subpath
|
|
13
|
+
// for a template that would rather not pull the rasteriser in with it.
|
|
14
|
+
export { blockLines, box, distribute, drawLines, image, inset, measureIn, optionalString, panel, placeLines, row, scrim, stack, } from "./layout/index.js";
|
|
10
15
|
export { extractProps, slugFromPath, walkContent } from "./content/index.js";
|
|
11
16
|
export { metaTags, metaTagsHtml } from "./meta/index.js";
|
|
12
17
|
export { createPlacer } from "./placement/index.js";
|
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":"AAqCA,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC/E,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,sBAAsB,CAAC;AAO9B,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGlE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGzE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAS5E,+EAA+E;AAC/E,uEAAuE;AACvE,OAAO,EACL,UAAU,EACV,GAAG,EACH,UAAU,EACV,SAAS,EACT,KAAK,EACL,KAAK,EACL,SAAS,EACT,cAAc,EACd,KAAK,EACL,UAAU,EACV,GAAG,EACH,KAAK,EACL,KAAK,GACN,MAAM,mBAAmB,CAAC;AAoB3B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAG7E,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { MeasureText } from "../types.js";
|
|
2
|
+
/** One group of a template's text: the space it has and how it is drawn. */
|
|
3
|
+
export interface TextBlock {
|
|
4
|
+
readonly maxWidth: number;
|
|
5
|
+
readonly maxLines: number;
|
|
6
|
+
readonly fontSize: number;
|
|
7
|
+
/**
|
|
8
|
+
* Fraction of `fontSize` this group may shrink to before it is cut instead.
|
|
9
|
+
* The title of a layout has the furthest to fall, because it is the line
|
|
10
|
+
* worth keeping whole; a subtitle that has shrunk much has stopped being
|
|
11
|
+
* readable in a feed, so it may as well lose its tail.
|
|
12
|
+
*/
|
|
13
|
+
readonly floor: number;
|
|
14
|
+
readonly fontWeight: number;
|
|
15
|
+
}
|
|
16
|
+
/** A block along with how the lines it produces are drawn. */
|
|
17
|
+
export interface StyledBlock extends TextBlock {
|
|
18
|
+
readonly opacity: number;
|
|
19
|
+
/** Space inserted before the group's first line, to separate it from the last. */
|
|
20
|
+
readonly gapBefore?: number;
|
|
21
|
+
}
|
|
22
|
+
/** One line of a template's text block, ready to be stacked and drawn. */
|
|
23
|
+
export interface TextLine {
|
|
24
|
+
readonly text: string;
|
|
25
|
+
readonly fontSize: number;
|
|
26
|
+
readonly fontWeight: number;
|
|
27
|
+
readonly opacity: number;
|
|
28
|
+
readonly gapBefore?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Fit one group of a template's text, from a prop that may not be there, and
|
|
32
|
+
* return its lines. Each group is fitted on its own, so a long title shrinking
|
|
33
|
+
* does not drag the subtitle down with it. A group whose prop is absent or
|
|
34
|
+
* empty produces no lines at all.
|
|
35
|
+
*/
|
|
36
|
+
export declare function blockLines(value: unknown, measure: MeasureText, fontFamily: string, block: StyledBlock): TextLine[];
|
|
37
|
+
//# sourceMappingURL=block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../src/layout/block.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,4EAA4E;AAC5E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,8DAA8D;AAC9D,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,kFAAkF;IAClF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,0EAA0E;AAC1E,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,WAAW,GACjB,QAAQ,EAAE,CAoBZ"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { fitText } from "../text/index.js";
|
|
2
|
+
import { optionalString } from "../props.js";
|
|
3
|
+
import { measureIn } from "./measure.js";
|
|
4
|
+
/**
|
|
5
|
+
* Fit one group of a template's text, from a prop that may not be there, and
|
|
6
|
+
* return its lines. Each group is fitted on its own, so a long title shrinking
|
|
7
|
+
* does not drag the subtitle down with it. A group whose prop is absent or
|
|
8
|
+
* empty produces no lines at all.
|
|
9
|
+
*/
|
|
10
|
+
export function blockLines(value, measure, fontFamily, block) {
|
|
11
|
+
const fitted = fitText(optionalString(value) ?? "", measureIn(measure, fontFamily, block.fontWeight), {
|
|
12
|
+
maxWidth: block.maxWidth,
|
|
13
|
+
maxLines: block.maxLines,
|
|
14
|
+
fontSize: block.fontSize,
|
|
15
|
+
minFontSize: Math.round(block.fontSize * block.floor),
|
|
16
|
+
});
|
|
17
|
+
return fitted.lines.map((text, index) => ({
|
|
18
|
+
text,
|
|
19
|
+
fontSize: fitted.fontSize,
|
|
20
|
+
fontWeight: block.fontWeight,
|
|
21
|
+
opacity: block.opacity,
|
|
22
|
+
...(index === 0 &&
|
|
23
|
+
block.gapBefore !== undefined && { gapBefore: block.gapBefore }),
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../../src/layout/block.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAiCzC;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CACxB,KAAc,EACd,OAAoB,EACpB,UAAkB,EAClB,KAAkB;IAElB,MAAM,MAAM,GAAe,OAAO,CAChC,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,EAC3B,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,EAChD;QACE,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC;KACtD,CACF,CAAC;IAEF,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACxC,IAAI;QACJ,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,GAAG,CAAC,KAAK,KAAK,CAAC;YACb,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;KACnE,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BoxStyle, Rect } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* A rectangle: the plate a badge sits on, the surface of a panel, a rule along
|
|
4
|
+
* an edge. Everything in a template that is not text or an image is one of
|
|
5
|
+
* these.
|
|
6
|
+
*
|
|
7
|
+
* Attributes a style does not name are left out rather than written as their
|
|
8
|
+
* defaults, so the output says only what the template decided.
|
|
9
|
+
*/
|
|
10
|
+
export declare function box(rect: Rect, style?: BoxStyle): string;
|
|
11
|
+
/**
|
|
12
|
+
* Shrink a rectangle inwards, which is how a template gets its margins. One
|
|
13
|
+
* number insets every edge; a partial one insets the edges it names.
|
|
14
|
+
*
|
|
15
|
+
* An inset larger than the rectangle collapses it to nothing rather than
|
|
16
|
+
* turning it inside out, since a negative width draws nothing anyway and an
|
|
17
|
+
* empty rectangle is easier to reason about than one with its corners crossed.
|
|
18
|
+
*/
|
|
19
|
+
export declare function inset(rect: Rect, amount: number | Partial<Record<"top" | "right" | "bottom" | "left", number>>): Rect;
|
|
20
|
+
//# sourceMappingURL=box.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../../src/layout/box.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAejD;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,GAAE,QAAa,GAAG,MAAM,CAe5D;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CACnB,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,EAAE,MAAM,CAAC,CAAC,GAC5E,IAAI,CAgBN"}
|