@effing/satori 0.1.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/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ O'Saasy License
2
+
3
+ Copyright © 2026, Trackuity BV.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ 1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ 2. No licensee or downstream recipient may use the Software (including any modified or derivative versions) to directly compete with the original Licensor by offering it to third parties as a hosted, managed, or Software-as-a-Service (SaaS) product or cloud service where the primary value of the service is the functionality of the Software itself.
10
+
11
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,198 @@
1
+ # @effing/satori
2
+
3
+ **Render JSX to PNG using Satori, with emoji support.**
4
+
5
+ > Part of the [**Effing**](../../README.md) family — programmatic video creation with TypeScript.
6
+
7
+ A thin wrapper around [Satori](https://github.com/vercel/satori) that renders JSX to PNG buffers. Includes built-in emoji support with multiple emoji styles.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @effing/satori
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { pngFromSatori, type FontData } from "@effing/satori";
19
+
20
+ // Load fonts
21
+ const interFont: FontData = {
22
+ name: "Inter",
23
+ data: await fs.readFile("./fonts/Inter-Regular.ttf"),
24
+ weight: 400,
25
+ style: "normal"
26
+ };
27
+
28
+ // Render JSX to PNG
29
+ const png = await pngFromSatori(
30
+ <div style={{
31
+ width: 1080,
32
+ height: 1920,
33
+ display: "flex",
34
+ alignItems: "center",
35
+ justifyContent: "center",
36
+ backgroundColor: "#1a1a2e",
37
+ color: "white",
38
+ fontSize: 64,
39
+ }}>
40
+ Hello World! 🚀
41
+ </div>,
42
+ {
43
+ width: 1080,
44
+ height: 1920,
45
+ fonts: [interFont],
46
+ emoji: "twemoji"
47
+ }
48
+ );
49
+
50
+ // png is a Buffer containing the PNG image
51
+ await fs.writeFile("output.png", png);
52
+ ```
53
+
54
+ ## Concepts
55
+
56
+ ### Rendering Pipeline
57
+
58
+ ```
59
+ JSX → Satori → SVG → Resvg → PNG Buffer
60
+ ```
61
+
62
+ 1. **Satori** converts JSX with CSS-like styles to SVG
63
+ 2. **Resvg** renders the SVG to a PNG buffer
64
+
65
+ ### Font Loading
66
+
67
+ Satori requires font data to render text. You must provide fonts as ArrayBuffers:
68
+
69
+ ```typescript
70
+ const fonts: FontData[] = [
71
+ {
72
+ name: "Inter",
73
+ data: fontBuffer,
74
+ weight: 400,
75
+ style: "normal",
76
+ },
77
+ ];
78
+ ```
79
+
80
+ ### Emoji Support
81
+
82
+ The package automatically loads emoji SVGs from CDNs. Supported styles:
83
+
84
+ | Style | Source |
85
+ | ------------ | ------------------------------ |
86
+ | `twemoji` | Twitter Emoji (default) |
87
+ | `openmoji` | OpenMoji |
88
+ | `blobmoji` | Google Blob Emoji |
89
+ | `noto` | Google Noto Emoji |
90
+ | `fluent` | Microsoft Fluent Emoji (color) |
91
+ | `fluentFlat` | Microsoft Fluent Emoji (flat) |
92
+
93
+ ## API Overview
94
+
95
+ ### `pngFromSatori(template, options)`
96
+
97
+ Render a JSX template to a PNG buffer.
98
+
99
+ ```typescript
100
+ function pngFromSatori(
101
+ template: React.ReactNode,
102
+ options: PngFromSatoriOptions,
103
+ ): Promise<Buffer>;
104
+ ```
105
+
106
+ **Options:**
107
+
108
+ | Option | Type | Required | Description |
109
+ | -------- | ------------ | -------- | ---------------------------------- |
110
+ | `width` | `number` | Yes | Output width in pixels |
111
+ | `height` | `number` | Yes | Output height in pixels |
112
+ | `fonts` | `FontData[]` | Yes | Font data for text rendering |
113
+ | `emoji` | `EmojiStyle` | No | Emoji style (default: `"twemoji"`) |
114
+
115
+ ### Types
116
+
117
+ ```typescript
118
+ type FontData = {
119
+ name: string;
120
+ data: Buffer | ArrayBuffer;
121
+ weight: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
122
+ style: "normal" | "italic";
123
+ };
124
+
125
+ type EmojiStyle =
126
+ | "twemoji"
127
+ | "openmoji"
128
+ | "blobmoji"
129
+ | "noto"
130
+ | "fluent"
131
+ | "fluentFlat";
132
+ ```
133
+
134
+ ## Examples
135
+
136
+ ### Frame Generation for Animations
137
+
138
+ ```typescript
139
+ import { pngFromSatori } from "@effing/satori";
140
+ import { tween, easeOutQuad } from "@effing/tween";
141
+ import { annieStream } from "@effing/annie";
142
+
143
+ async function* generateFrames() {
144
+ yield* tween(90, async ({ lower: progress }) => {
145
+ const scale = 1 + 0.3 * easeOutQuad(progress);
146
+
147
+ return pngFromSatori(
148
+ <div style={{
149
+ width: 1080,
150
+ height: 1920,
151
+ display: "flex",
152
+ alignItems: "center",
153
+ justifyContent: "center",
154
+ transform: `scale(${scale})`,
155
+ fontSize: 72,
156
+ color: "white",
157
+ }}>
158
+ ✨ Animated! ✨
159
+ </div>,
160
+ { width: 1080, height: 1920, fonts }
161
+ );
162
+ });
163
+ }
164
+
165
+ const stream = annieStream(generateFrames());
166
+ ```
167
+
168
+ ### Multiple Font Weights
169
+
170
+ ```typescript
171
+ const fonts: FontData[] = [
172
+ {
173
+ name: "Inter",
174
+ data: await fs.readFile("./Inter-Regular.ttf"),
175
+ weight: 400,
176
+ style: "normal"
177
+ },
178
+ {
179
+ name: "Inter",
180
+ data: await fs.readFile("./Inter-Bold.ttf"),
181
+ weight: 700,
182
+ style: "normal"
183
+ }
184
+ ];
185
+
186
+ const png = await pngFromSatori(
187
+ <div style={{ display: "flex", flexDirection: "column" }}>
188
+ <span style={{ fontWeight: 400 }}>Regular text</span>
189
+ <span style={{ fontWeight: 700 }}>Bold text</span>
190
+ </div>,
191
+ { width: 800, height: 600, fonts }
192
+ );
193
+ ```
194
+
195
+ ## Related Packages
196
+
197
+ - [`@effing/tween`](../tween) — Step iteration for frame generation
198
+ - [`@effing/annie`](../annie) — Package rendered frames into animations
@@ -0,0 +1,46 @@
1
+ import satori from 'satori';
2
+
3
+ /**
4
+ * Font data for satori rendering
5
+ */
6
+ type FontData = {
7
+ name: string;
8
+ data: Buffer | ArrayBuffer;
9
+ weight: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
10
+ style: "normal" | "italic";
11
+ };
12
+ /**
13
+ * Emoji style options for rendering
14
+ */
15
+ type EmojiStyle = "twemoji" | "openmoji" | "blobmoji" | "noto" | "fluent" | "fluentFlat";
16
+ /**
17
+ * Options for pngFromSatori
18
+ */
19
+ type PngFromSatoriOptions = {
20
+ /** Frame width in pixels */
21
+ width: number;
22
+ /** Frame height in pixels */
23
+ height: number;
24
+ /** Font data for text rendering */
25
+ fonts: FontData[];
26
+ /** Emoji style to use (default: "twemoji") */
27
+ emoji?: EmojiStyle;
28
+ };
29
+ /**
30
+ * Render a React/JSX template to a PNG buffer using Satori
31
+ *
32
+ * @param template React element to render
33
+ * @param options Rendering options
34
+ * @returns PNG image as a Buffer
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * const png = await pngFromSatori(
39
+ * <div style={{ fontSize: 48, color: "white" }}>Hello World</div>,
40
+ * { width: 1080, height: 1080, fonts: [myFont] }
41
+ * );
42
+ * ```
43
+ */
44
+ declare function pngFromSatori(template: Parameters<typeof satori>[0], { width, height, fonts, emoji }: PngFromSatoriOptions): Promise<Buffer>;
45
+
46
+ export { type EmojiStyle, type FontData, type PngFromSatoriOptions, pngFromSatori };
package/dist/index.js ADDED
@@ -0,0 +1,63 @@
1
+ // src/index.ts
2
+ import { Resvg } from "@resvg/resvg-js";
3
+ import satori from "satori";
4
+ var emojiApis = {
5
+ twemoji: (code) => `https://cdnjs.cloudflare.com/ajax/libs/twemoji/16.0.1/svg/${code.toLowerCase()}.svg`,
6
+ openmoji: "https://cdn.jsdelivr.net/npm/@svgmoji/openmoji@2.0.0/svg/",
7
+ blobmoji: "https://cdn.jsdelivr.net/npm/@svgmoji/blob@2.0.0/svg/",
8
+ noto: "https://cdn.jsdelivr.net/gh/svgmoji/svgmoji/packages/svgmoji__noto/svg/",
9
+ fluent: (code) => `https://cdn.jsdelivr.net/gh/shuding/fluentui-emoji-unicode/assets/${code.toLowerCase()}_color.svg`,
10
+ fluentFlat: (code) => `https://cdn.jsdelivr.net/gh/shuding/fluentui-emoji-unicode/assets/${code.toLowerCase()}_flat.svg`
11
+ };
12
+ var U200D = String.fromCharCode(8205);
13
+ var UFE0Fg = /\uFE0F/g;
14
+ function getEmojiCode(char) {
15
+ return toCodePoint(char.indexOf(U200D) < 0 ? char.replace(UFE0Fg, "") : char);
16
+ }
17
+ function toCodePoint(unicodeSurrogates) {
18
+ const r = [];
19
+ let c = 0, p = 0, i = 0;
20
+ while (i < unicodeSurrogates.length) {
21
+ c = unicodeSurrogates.charCodeAt(i++);
22
+ if (p) {
23
+ r.push((65536 + (p - 55296 << 10) + (c - 56320)).toString(16));
24
+ p = 0;
25
+ } else if (55296 <= c && c <= 56319) {
26
+ p = c;
27
+ } else {
28
+ r.push(c.toString(16));
29
+ }
30
+ }
31
+ return r.join("-");
32
+ }
33
+ var emojiCache = {};
34
+ async function loadEmoji(type, code) {
35
+ const key = type + ":" + code;
36
+ if (key in emojiCache) return emojiCache[key];
37
+ const api = emojiApis[type];
38
+ if (typeof api === "function") {
39
+ return emojiCache[key] = fetch(api(code)).then((r) => r.text());
40
+ }
41
+ return emojiCache[key] = fetch(`${api}${code.toUpperCase()}.svg`).then(
42
+ (r) => r.text()
43
+ );
44
+ }
45
+ async function pngFromSatori(template, { width, height, fonts, emoji = "twemoji" }) {
46
+ const overlaySvg = await satori(template, {
47
+ width,
48
+ height,
49
+ fonts,
50
+ loadAdditionalAsset: async (code, segment) => {
51
+ if (code === "emoji") {
52
+ return "data:image/svg+xml;base64," + btoa(await loadEmoji(emoji, getEmojiCode(segment)));
53
+ }
54
+ return segment;
55
+ }
56
+ });
57
+ const resvg = new Resvg(overlaySvg, { font: { loadSystemFonts: false } });
58
+ return resvg.render().asPng();
59
+ }
60
+ export {
61
+ pngFromSatori
62
+ };
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Resvg } from \"@resvg/resvg-js\";\nimport satori from \"satori\";\n\n/**\n * Font data for satori rendering\n */\nexport type FontData = {\n name: string;\n data: Buffer | ArrayBuffer;\n weight: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;\n style: \"normal\" | \"italic\";\n};\n\n/**\n * Emoji style options for rendering\n */\nexport type EmojiStyle =\n | \"twemoji\"\n | \"openmoji\"\n | \"blobmoji\"\n | \"noto\"\n | \"fluent\"\n | \"fluentFlat\";\n\nconst emojiApis: Record<EmojiStyle, string | ((code: string) => string)> = {\n twemoji: (code: string) =>\n `https://cdnjs.cloudflare.com/ajax/libs/twemoji/16.0.1/svg/${code.toLowerCase()}.svg`,\n openmoji: \"https://cdn.jsdelivr.net/npm/@svgmoji/openmoji@2.0.0/svg/\",\n blobmoji: \"https://cdn.jsdelivr.net/npm/@svgmoji/blob@2.0.0/svg/\",\n noto: \"https://cdn.jsdelivr.net/gh/svgmoji/svgmoji/packages/svgmoji__noto/svg/\",\n fluent: (code: string) =>\n `https://cdn.jsdelivr.net/gh/shuding/fluentui-emoji-unicode/assets/${code.toLowerCase()}_color.svg`,\n fluentFlat: (code: string) =>\n `https://cdn.jsdelivr.net/gh/shuding/fluentui-emoji-unicode/assets/${code.toLowerCase()}_flat.svg`,\n};\n\nconst U200D = String.fromCharCode(8205);\nconst UFE0Fg = /\\uFE0F/g;\n\nfunction getEmojiCode(char: string): string {\n return toCodePoint(char.indexOf(U200D) < 0 ? char.replace(UFE0Fg, \"\") : char);\n}\n\nfunction toCodePoint(unicodeSurrogates: string): string {\n const r: string[] = [];\n let c = 0,\n p = 0,\n i = 0;\n\n while (i < unicodeSurrogates.length) {\n c = unicodeSurrogates.charCodeAt(i++);\n if (p) {\n r.push((65536 + ((p - 55296) << 10) + (c - 56320)).toString(16));\n p = 0;\n } else if (55296 <= c && c <= 56319) {\n p = c;\n } else {\n r.push(c.toString(16));\n }\n }\n return r.join(\"-\");\n}\n\nconst emojiCache: Record<string, Promise<string>> = {};\n\nasync function loadEmoji(type: EmojiStyle, code: string): Promise<string> {\n const key = type + \":\" + code;\n if (key in emojiCache) return emojiCache[key];\n\n const api = emojiApis[type];\n if (typeof api === \"function\") {\n return (emojiCache[key] = fetch(api(code)).then((r) => r.text()));\n }\n return (emojiCache[key] = fetch(`${api}${code.toUpperCase()}.svg`).then((r) =>\n r.text(),\n ));\n}\n\n/**\n * Options for pngFromSatori\n */\nexport type PngFromSatoriOptions = {\n /** Frame width in pixels */\n width: number;\n /** Frame height in pixels */\n height: number;\n /** Font data for text rendering */\n fonts: FontData[];\n /** Emoji style to use (default: \"twemoji\") */\n emoji?: EmojiStyle;\n};\n\n/**\n * Render a React/JSX template to a PNG buffer using Satori\n *\n * @param template React element to render\n * @param options Rendering options\n * @returns PNG image as a Buffer\n *\n * @example\n * ```tsx\n * const png = await pngFromSatori(\n * <div style={{ fontSize: 48, color: \"white\" }}>Hello World</div>,\n * { width: 1080, height: 1080, fonts: [myFont] }\n * );\n * ```\n */\nexport async function pngFromSatori(\n template: Parameters<typeof satori>[0],\n { width, height, fonts, emoji = \"twemoji\" }: PngFromSatoriOptions,\n): Promise<Buffer> {\n const overlaySvg = await satori(template, {\n width,\n height,\n fonts,\n loadAdditionalAsset: async (code: string, segment: string) => {\n if (code === \"emoji\") {\n return (\n \"data:image/svg+xml;base64,\" +\n btoa(await loadEmoji(emoji, getEmojiCode(segment)))\n );\n }\n return segment;\n },\n });\n const resvg = new Resvg(overlaySvg, { font: { loadSystemFonts: false } });\n return resvg.render().asPng();\n}\n"],"mappings":";AAAA,SAAS,aAAa;AACtB,OAAO,YAAY;AAuBnB,IAAM,YAAqE;AAAA,EACzE,SAAS,CAAC,SACR,6DAA6D,KAAK,YAAY,CAAC;AAAA,EACjF,UAAU;AAAA,EACV,UAAU;AAAA,EACV,MAAM;AAAA,EACN,QAAQ,CAAC,SACP,qEAAqE,KAAK,YAAY,CAAC;AAAA,EACzF,YAAY,CAAC,SACX,qEAAqE,KAAK,YAAY,CAAC;AAC3F;AAEA,IAAM,QAAQ,OAAO,aAAa,IAAI;AACtC,IAAM,SAAS;AAEf,SAAS,aAAa,MAAsB;AAC1C,SAAO,YAAY,KAAK,QAAQ,KAAK,IAAI,IAAI,KAAK,QAAQ,QAAQ,EAAE,IAAI,IAAI;AAC9E;AAEA,SAAS,YAAY,mBAAmC;AACtD,QAAM,IAAc,CAAC;AACrB,MAAI,IAAI,GACN,IAAI,GACJ,IAAI;AAEN,SAAO,IAAI,kBAAkB,QAAQ;AACnC,QAAI,kBAAkB,WAAW,GAAG;AACpC,QAAI,GAAG;AACL,QAAE,MAAM,SAAU,IAAI,SAAU,OAAO,IAAI,QAAQ,SAAS,EAAE,CAAC;AAC/D,UAAI;AAAA,IACN,WAAW,SAAS,KAAK,KAAK,OAAO;AACnC,UAAI;AAAA,IACN,OAAO;AACL,QAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAAA,IACvB;AAAA,EACF;AACA,SAAO,EAAE,KAAK,GAAG;AACnB;AAEA,IAAM,aAA8C,CAAC;AAErD,eAAe,UAAU,MAAkB,MAA+B;AACxE,QAAM,MAAM,OAAO,MAAM;AACzB,MAAI,OAAO,WAAY,QAAO,WAAW,GAAG;AAE5C,QAAM,MAAM,UAAU,IAAI;AAC1B,MAAI,OAAO,QAAQ,YAAY;AAC7B,WAAQ,WAAW,GAAG,IAAI,MAAM,IAAI,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACjE;AACA,SAAQ,WAAW,GAAG,IAAI,MAAM,GAAG,GAAG,GAAG,KAAK,YAAY,CAAC,MAAM,EAAE;AAAA,IAAK,CAAC,MACvE,EAAE,KAAK;AAAA,EACT;AACF;AA+BA,eAAsB,cACpB,UACA,EAAE,OAAO,QAAQ,OAAO,QAAQ,UAAU,GACzB;AACjB,QAAM,aAAa,MAAM,OAAO,UAAU;AAAA,IACxC;AAAA,IACA;AAAA,IACA;AAAA,IACA,qBAAqB,OAAO,MAAc,YAAoB;AAC5D,UAAI,SAAS,SAAS;AACpB,eACE,+BACA,KAAK,MAAM,UAAU,OAAO,aAAa,OAAO,CAAC,CAAC;AAAA,MAEtD;AACA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACD,QAAM,QAAQ,IAAI,MAAM,YAAY,EAAE,MAAM,EAAE,iBAAiB,MAAM,EAAE,CAAC;AACxE,SAAO,MAAM,OAAO,EAAE,MAAM;AAC9B;","names":[]}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@effing/satori",
3
+ "version": "0.1.0",
4
+ "description": "Render JSX to PNG using Satori with emoji support",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "dependencies": {
16
+ "@resvg/resvg-js": "^2.6.2",
17
+ "satori": "^0.12.2"
18
+ },
19
+ "devDependencies": {
20
+ "tsup": "^8.0.0",
21
+ "typescript": "^5.9.3"
22
+ },
23
+ "keywords": [
24
+ "satori",
25
+ "svg",
26
+ "png",
27
+ "jsx",
28
+ "emoji"
29
+ ],
30
+ "license": "O'Saasy",
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "scripts": {
35
+ "build": "tsup",
36
+ "typecheck": "tsc --noEmit"
37
+ }
38
+ }