@kensio/colophon 1.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -4
- package/dist/config.d.ts +18 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +39 -0
- package/dist/config.js.map +1 -1
- package/dist/content/index.d.ts.map +1 -1
- package/dist/content/index.js +4 -5
- package/dist/content/index.js.map +1 -1
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +9 -1
- package/dist/generate.js.map +1 -1
- package/dist/highlight.d.ts +75 -0
- package/dist/highlight.d.ts.map +1 -0
- package/dist/highlight.js +137 -0
- package/dist/highlight.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/render.d.ts +4 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +6 -3
- package/dist/render.js.map +1 -1
- package/dist/templates/banner.d.ts.map +1 -1
- package/dist/templates/banner.js +2 -12
- package/dist/templates/banner.js.map +1 -1
- package/dist/templates/card.d.ts.map +1 -1
- package/dist/templates/card.js +2 -12
- package/dist/templates/card.js.map +1 -1
- package/dist/templates/code.d.ts +12 -0
- package/dist/templates/code.d.ts.map +1 -0
- package/dist/templates/code.js +275 -0
- package/dist/templates/code.js.map +1 -0
- package/dist/templates/index.d.ts +2 -0
- package/dist/templates/index.d.ts.map +1 -1
- package/dist/templates/index.js +4 -0
- package/dist/templates/index.js.map +1 -1
- package/dist/templates/props.d.ts +7 -0
- package/dist/templates/props.d.ts.map +1 -0
- package/dist/templates/props.js +17 -0
- package/dist/templates/props.js.map +1 -0
- package/dist/types.d.ts +54 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -4
package/dist/types.d.ts
CHANGED
|
@@ -68,6 +68,38 @@ export interface Badge {
|
|
|
68
68
|
/** Badge background colour. Defaults to white. */
|
|
69
69
|
readonly background?: string;
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Styling for the `code` template. Every field is optional; defaults are
|
|
73
|
+
* applied by `resolveConfig`.
|
|
74
|
+
*/
|
|
75
|
+
export interface CodeStyle {
|
|
76
|
+
/** Shiki theme name, e.g. `github-dark`, `monokai`, `catppuccin-mocha`. */
|
|
77
|
+
readonly theme?: string;
|
|
78
|
+
/** Monospace font stack. Must resolve to a font available to `sharp`. */
|
|
79
|
+
readonly fontFamily?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Glyph advance width as a fraction of the font size. `0.6` matches most
|
|
82
|
+
* monospace faces (Source Code Pro, Menlo, DejaVu Sans Mono); narrower faces
|
|
83
|
+
* such as Consolas want ~`0.55`.
|
|
84
|
+
*/
|
|
85
|
+
readonly charWidthRatio?: number;
|
|
86
|
+
/** Line advance as a multiple of the font size. Default `1.55`. */
|
|
87
|
+
readonly lineHeight?: number;
|
|
88
|
+
/** Spaces a tab expands to before layout. Default `2`. */
|
|
89
|
+
readonly tabSize?: number;
|
|
90
|
+
/** Corner radius of the code panel, as a fraction of the smaller side. */
|
|
91
|
+
readonly cornerScale?: number;
|
|
92
|
+
/** Upper bound on the auto-fitted font size, as a fraction of image width. */
|
|
93
|
+
readonly maxFontScale?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Lower bound on the auto-fitted font size, as a fraction of image width —
|
|
96
|
+
* width, because that is what a feed scales a share image to. Code too long
|
|
97
|
+
* to fit at this size is truncated with an ellipsis rather than shrunk into
|
|
98
|
+
* illegibility, so raising this trades lines of code for readability and
|
|
99
|
+
* lowering it does the reverse.
|
|
100
|
+
*/
|
|
101
|
+
readonly minFontScale?: number;
|
|
102
|
+
}
|
|
71
103
|
/**
|
|
72
104
|
* Image properties, typically read from a post's frontmatter. The schema is
|
|
73
105
|
* intentionally open: templates read whatever fields they understand, so a
|
|
@@ -76,11 +108,18 @@ export interface Badge {
|
|
|
76
108
|
export interface MetaImageProps {
|
|
77
109
|
/** Name of the template to render with. */
|
|
78
110
|
readonly template: string;
|
|
79
|
-
readonly title
|
|
111
|
+
readonly title?: string;
|
|
80
112
|
readonly subtitle?: string;
|
|
81
113
|
readonly version?: string | number;
|
|
82
114
|
readonly [key: string]: unknown;
|
|
83
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Reports something a template had to compromise on — code truncated to stay
|
|
118
|
+
* legible, so far. Rendering carries on regardless: a share image is worth
|
|
119
|
+
* having even when the input did not quite fit, but the author should hear
|
|
120
|
+
* about it rather than discover it in someone else's timeline.
|
|
121
|
+
*/
|
|
122
|
+
export type WarningHandler = (message: string) => void;
|
|
84
123
|
/**
|
|
85
124
|
* Everything a template needs to produce its SVG foreground content.
|
|
86
125
|
*/
|
|
@@ -93,10 +132,14 @@ export interface TemplateContext {
|
|
|
93
132
|
* A registered template. `render` returns the SVG *foreground* content (text,
|
|
94
133
|
* badges, etc.) for the given dimensions; the background and the enclosing
|
|
95
134
|
* `<svg>` root are added by the renderer.
|
|
135
|
+
*
|
|
136
|
+
* Rendering may be asynchronous — the `code` template loads syntax grammars on
|
|
137
|
+
* demand — so `render` can return a promise. Simple templates can stay
|
|
138
|
+
* synchronous and just return a string.
|
|
96
139
|
*/
|
|
97
140
|
export interface Template {
|
|
98
141
|
readonly name: string;
|
|
99
|
-
render(context: TemplateContext): string
|
|
142
|
+
render(context: TemplateContext): string | Promise<string>;
|
|
100
143
|
}
|
|
101
144
|
/**
|
|
102
145
|
* User-supplied configuration. Every field is optional; defaults are applied
|
|
@@ -111,6 +154,13 @@ export interface ColophonConfig {
|
|
|
111
154
|
readonly footer?: string;
|
|
112
155
|
/** Corner badge for the `banner` template. Omit (the default) for none. */
|
|
113
156
|
readonly badge?: Badge;
|
|
157
|
+
/** Styling for the `code` template. */
|
|
158
|
+
readonly code?: CodeStyle;
|
|
159
|
+
/**
|
|
160
|
+
* Where non-fatal rendering complaints go. Defaults to `console.warn`; pass
|
|
161
|
+
* a no-op to silence them, or your build's logger to route them.
|
|
162
|
+
*/
|
|
163
|
+
readonly onWarning?: WarningHandler;
|
|
114
164
|
/**
|
|
115
165
|
* Output sizes, each with a unique `name` used in the filename. Defaults to
|
|
116
166
|
* a 1.91:1 Open Graph landscape plus a 1:1 square (see `DEFAULT_SIZES`).
|
|
@@ -128,6 +178,8 @@ export interface ResolvedConfig {
|
|
|
128
178
|
readonly fontFamily: string;
|
|
129
179
|
readonly footer: string | undefined;
|
|
130
180
|
readonly badge: Badge | undefined;
|
|
181
|
+
readonly code: Required<CodeStyle>;
|
|
182
|
+
readonly onWarning: WarningHandler;
|
|
131
183
|
readonly sizes: readonly OutputSize[];
|
|
132
184
|
readonly templates: Readonly<Record<string, Template>>;
|
|
133
185
|
}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,yDAAyD;IACzD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClD;IACE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IAC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,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;CACxD;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB"}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"homepage": "https://github.com/KensioSoftware/colophon#readme",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
|
-
"version": "
|
|
11
|
+
"version": "2.2.0",
|
|
12
12
|
"type": "module",
|
|
13
13
|
"main": "./dist/index.js",
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
@@ -47,7 +47,10 @@
|
|
|
47
47
|
"frontmatter",
|
|
48
48
|
"static-site",
|
|
49
49
|
"svg",
|
|
50
|
-
"sharp"
|
|
50
|
+
"sharp",
|
|
51
|
+
"syntax-highlighting",
|
|
52
|
+
"code-image",
|
|
53
|
+
"shiki"
|
|
51
54
|
],
|
|
52
55
|
"devDependencies": {
|
|
53
56
|
"@eslint/js": "^10.0.1",
|
|
@@ -62,7 +65,7 @@
|
|
|
62
65
|
"eslint-plugin-jsdoc": "^63.0.13",
|
|
63
66
|
"eslint-plugin-no-secrets": "^2.3.3",
|
|
64
67
|
"eslint-plugin-security": "^4.0.1",
|
|
65
|
-
"eslint-plugin-unicorn": "^
|
|
68
|
+
"eslint-plugin-unicorn": "^69.0.0",
|
|
66
69
|
"globals": "^17.7.0",
|
|
67
70
|
"jiti": "^2.7.0",
|
|
68
71
|
"prettier": "^3.9.5",
|
|
@@ -72,7 +75,8 @@
|
|
|
72
75
|
},
|
|
73
76
|
"dependencies": {
|
|
74
77
|
"gray-matter": "^4.0.3",
|
|
75
|
-
"sharp": "^0.35.3"
|
|
78
|
+
"sharp": "^0.35.3",
|
|
79
|
+
"shiki": "^4.3.1"
|
|
76
80
|
},
|
|
77
81
|
"scripts": {
|
|
78
82
|
"build": "tsc -p tsconfig.build.json",
|