@ethercorps/sveltekit-og 4.3.0-next.10 → 4.3.0-next.12
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 +9 -1
- package/dist/takumi/render.js +6 -5
- package/package.json +129 -130
- package/dist/providers/resvg/resvg.wasm +0 -0
package/README.md
CHANGED
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
# SvelteKit Open Graph Image Generation
|
|
6
6
|
|
|
7
|
-
Dynamically generate Open Graph images from an HTML+CSS template or Svelte component
|
|
7
|
+
Dynamically generate Open Graph images from an HTML+CSS template or Svelte component. No headless browser required.
|
|
8
|
+
|
|
9
|
+
Pick the rendering engine that fits your needs:
|
|
10
|
+
|
|
11
|
+
- **Satori** (default) — HTML → SVG → PNG, based on [Satori](https://github.com/vercel/satori#documentation).
|
|
12
|
+
- **[Takumi](https://takumi.kane.tw)** — a Rust/WASM engine with more output formats (`webp`, `jpeg`, `ico`, `svg`, …) and a built-in font, available from `@ethercorps/sveltekit-og/takumi` (v4.3.0+).
|
|
8
13
|
|
|
9
14
|
## Table of Contents
|
|
10
15
|
|
|
@@ -35,6 +40,8 @@ pnpm install @ethercorps/sveltekit-og
|
|
|
35
40
|
|
|
36
41
|
For detailed usage instructions, please see the [Getting Started](https://sveltekit-og.dev/docs/getting-started) section of our documentation.
|
|
37
42
|
|
|
43
|
+
Prefer the Takumi engine — more output formats and a built-in font? See the [Takumi Engine](https://sveltekit-og.dev/docs/usage/takumi) guide.
|
|
44
|
+
|
|
38
45
|
## Examples
|
|
39
46
|
|
|
40
47
|
- **ImageResponse**: [_source_](/src/routes/+server.ts) · [_demo_](https://vercel.sveltekit-og.dev)
|
|
@@ -57,6 +64,7 @@ This project is licensed under the [MIT License](LICENSE).
|
|
|
57
64
|
This project would not be possible without the following projects:
|
|
58
65
|
|
|
59
66
|
- [Satori & @vercel/og](https://github.com/vercel/satori)
|
|
67
|
+
- [Takumi](https://takumi.kane.tw)
|
|
60
68
|
- [Noto by Google Fonts](https://fonts.google.com/noto)
|
|
61
69
|
- [fineshopdesign](https://github.com/fineshopdesign/cf-wasm)
|
|
62
70
|
|
package/dist/takumi/render.js
CHANGED
|
@@ -4,17 +4,18 @@ import { useTakumiRenderer, registerTakumiFonts } from "./renderer.js";
|
|
|
4
4
|
import { resolveTakumiFonts } from "./fonts.js";
|
|
5
5
|
import { createLogger } from "../helpers/logger.js";
|
|
6
6
|
import { handleAsync, handleSync, ErrorCodes } from "../helpers/error-handler.js";
|
|
7
|
+
import { html } from "satori-html";
|
|
7
8
|
function elementToHtml(element, props) {
|
|
8
9
|
if (typeof element === "string")
|
|
9
|
-
return element.replaceAll("\n", "").trim();
|
|
10
|
+
return html(element.replaceAll("\n", "").trim());
|
|
10
11
|
// head carries css injected via <svelte:options css="injected" />, so it goes first
|
|
11
12
|
const { head, body } = renderComponentToHtml(element, props);
|
|
12
|
-
return head + body;
|
|
13
|
+
return html(head + body);
|
|
13
14
|
}
|
|
14
15
|
/** Render an HTML string or Svelte component to image bytes (or an svg string). */
|
|
15
16
|
export async function createTakumiImage(element, options, props) {
|
|
16
17
|
const log = createLogger(options.debug ?? false);
|
|
17
|
-
const
|
|
18
|
+
const vNode = handleSync(() => elementToHtml(element, props), ErrorCodes.VNODE_CREATION_FAILED, "Failed to create HTML for Takumi");
|
|
18
19
|
const renderer = await useTakumiRenderer(options.debug);
|
|
19
20
|
if (options.fonts?.length) {
|
|
20
21
|
const fonts = await resolveTakumiFonts(options.fonts);
|
|
@@ -24,7 +25,7 @@ export async function createTakumiImage(element, options, props) {
|
|
|
24
25
|
const shared = { renderer: renderer, width, height, stylesheets, emoji };
|
|
25
26
|
log.debug(`Rendering ${format.toUpperCase()} with Takumi`);
|
|
26
27
|
if (format === "svg") {
|
|
27
|
-
return handleAsync(() => renderSvg(
|
|
28
|
+
return handleAsync(() => renderSvg(vNode, shared), ErrorCodes.TAKUMI_RENDER_FAILED, "Failed to render SVG with Takumi");
|
|
28
29
|
}
|
|
29
|
-
return handleAsync(() => takumiRender(
|
|
30
|
+
return handleAsync(() => takumiRender(vNode, { ...shared, format, quality }), ErrorCodes.TAKUMI_RENDER_FAILED, "Failed to render image with Takumi");
|
|
30
31
|
}
|
package/package.json
CHANGED
|
@@ -1,131 +1,130 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
2
|
+
"name": "@ethercorps/sveltekit-og",
|
|
3
|
+
"version": "4.3.0-next.12",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"homepage": "https://sveltekit-og.dev",
|
|
6
|
+
"repository": "github:ethercorps/sveltekit-og",
|
|
7
|
+
"funding": "https://github.com/sponsors/ethercorps",
|
|
8
|
+
"author": "Shivam Meena <https://github.com/theetherGit>",
|
|
9
|
+
"description": "Dynamically generate Open Graph images from an HTML, CSS template or Svelte component using fast and efficient conversion from HTML > SVG > PNG",
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "Shivam Meena",
|
|
13
|
+
"github": "https://github.com/theetherGit"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "Jason",
|
|
17
|
+
"github": "https://github.com/jasongitmail"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "Mihkel Martin Kasterpalu",
|
|
21
|
+
"github": "https://github.com/MihkelMK"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "Luke Parke",
|
|
25
|
+
"github": "https://github.com/LukasParke"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "Willow (GHOST)",
|
|
29
|
+
"github": "https://github.com/ghostdevv"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "Minseo Lee",
|
|
33
|
+
"github": "https://github.com/quiple"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"svelte": "./dist/index.js",
|
|
40
|
+
"import": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./fonts": {
|
|
43
|
+
"types": "./dist/fonts.d.ts",
|
|
44
|
+
"import": "./dist/fonts.js"
|
|
45
|
+
},
|
|
46
|
+
"./takumi": {
|
|
47
|
+
"types": "./dist/takumi/index.d.ts",
|
|
48
|
+
"svelte": "./dist/takumi/index.js",
|
|
49
|
+
"import": "./dist/takumi/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./plugin": {
|
|
52
|
+
"types": "./dist/plugin.d.ts",
|
|
53
|
+
"import": "./dist/plugin.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist",
|
|
58
|
+
"!dist/**/*.test.*",
|
|
59
|
+
"!dist/**/*.spec.*"
|
|
60
|
+
],
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@eslint/compat": "^2.0.3",
|
|
63
|
+
"@eslint/js": "^9.39.3",
|
|
64
|
+
"@sveltejs/adapter-vercel": "^5.10.3",
|
|
65
|
+
"@sveltejs/kit": "^2.53.4",
|
|
66
|
+
"@sveltejs/package": "^2.5.7",
|
|
67
|
+
"@sveltejs/vite-plugin-svelte": "^4.0.4",
|
|
68
|
+
"@types/node": "^24.11.0",
|
|
69
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
70
|
+
"@typescript-eslint/parser": "^5.62.0",
|
|
71
|
+
"css-tree": "^2.3.1",
|
|
72
|
+
"eslint": "^8.57.1",
|
|
73
|
+
"eslint-config-prettier": "^8.10.2",
|
|
74
|
+
"eslint-plugin-oxlint": "^1.55.0",
|
|
75
|
+
"eslint-plugin-svelte": "^2.46.1",
|
|
76
|
+
"globals": "^16.5.0",
|
|
77
|
+
"oxlint": "^1.55.0",
|
|
78
|
+
"prettier": "^3.8.1",
|
|
79
|
+
"prettier-plugin-svelte": "^3.5.1",
|
|
80
|
+
"prettier-plugin-tailwindcss": "^0.6.14",
|
|
81
|
+
"publint": "^0.1.16",
|
|
82
|
+
"rollup-plugin-visualizer": "^5.14.0",
|
|
83
|
+
"svelte": "^5.53.10",
|
|
84
|
+
"svelte-check": "^4.4.5",
|
|
85
|
+
"tslib": "^2.8.1",
|
|
86
|
+
"typescript": "^5.9.3",
|
|
87
|
+
"typescript-eslint": "^8.57.0",
|
|
88
|
+
"vite": "^5.4.21",
|
|
89
|
+
"takumi-js": "2.0.0-beta.14",
|
|
90
|
+
"vitest": "^1.6.1"
|
|
91
|
+
},
|
|
92
|
+
"main": "./dist/index.js",
|
|
93
|
+
"svelte": "./dist/index.js",
|
|
94
|
+
"types": "./dist/index.d.ts",
|
|
95
|
+
"type": "module",
|
|
96
|
+
"dependencies": {
|
|
97
|
+
"@resvg/resvg-wasm": "^2.6.2",
|
|
98
|
+
"satori": "^0.25.0",
|
|
99
|
+
"satori-html": "0.3.2",
|
|
100
|
+
"std-env": "^4.1.0",
|
|
101
|
+
"unwasm": "^0.5.3"
|
|
102
|
+
},
|
|
103
|
+
"peerDependencies": {
|
|
104
|
+
"@sveltejs/kit": ">=2.0.0",
|
|
105
|
+
"takumi-js": "^2.0.0-beta.14"
|
|
106
|
+
},
|
|
107
|
+
"peerDependenciesMeta": {
|
|
108
|
+
"takumi-js": {
|
|
109
|
+
"optional": true
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
"scripts": {
|
|
113
|
+
"dev": "vite dev",
|
|
114
|
+
"build": "vite build && npm run package",
|
|
115
|
+
"build:examples": "pnpm -F \"./examples/**\" --parallel --color build",
|
|
116
|
+
"check:examples": "pnpm install -r",
|
|
117
|
+
"preview": "vite preview",
|
|
118
|
+
"package": "svelte-kit sync && svelte-package && publint",
|
|
119
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
120
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
121
|
+
"test": "vitest",
|
|
122
|
+
"bench": "vitest bench --run",
|
|
123
|
+
"bench:save": "vitest bench --run --outputJson benchmarks/baseline.json",
|
|
124
|
+
"bench:compare": "vitest bench --run --compare benchmarks/baseline.json",
|
|
125
|
+
"bench:snapshot": "node scripts/bench-snapshot.mjs",
|
|
126
|
+
"lint": "oxlint . && eslint .",
|
|
127
|
+
"format": "prettier --plugin-search-dir . --write .",
|
|
128
|
+
"publishBeta": "npm publish --tag beta"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
Binary file
|