@ethercorps/sveltekit-og 2.0.1 → 3.0.0-alpha.1
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 +0 -189
- package/dist/api.d.ts +6 -0
- package/dist/font.d.ts +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +157 -0
- package/dist/resvg-HVRFGR4B.wasm +0 -0
- package/dist/types.d.ts +11 -0
- package/dist/yoga-ZMNYPE6Z.wasm +0 -0
- package/package.json +36 -34
- package/LICENSE +0 -21
- package/index.d.ts +0 -17
- package/index.js +0 -62
- package/toReactElement.d.ts +0 -10
- package/toReactElement.js +0 -100
package/README.md
CHANGED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
# SvelteKit Open Graph Image Generation
|
|
2
|
-
|
|
3
|
-
Dynamically generate Open Graph images from an HTML+CSS template or Svelte component using fast and efficient conversion from HTML > SVG > PNG. Based on [Satori](https://github.com/vercel/satori#documentation). No headless browser required.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pnpm install -D @ethercorps/sveltekit-og
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
> Using with Cloudflare Pages or Workers then you have to provide `url` polyfill by just installing it as `devDependency`.
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
pnpm i -D url
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Usage
|
|
18
|
-
|
|
19
|
-
Create a file at `/src/routes/og/+server.ts`. Alternatively, you can use JavaScript by removing the types from this example.
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
// src/routes/og/+server.ts
|
|
23
|
-
import { ImageResponse } from '@ethercorps/sveltekit-og';
|
|
24
|
-
import { RequestHandler } from './$types';
|
|
25
|
-
|
|
26
|
-
const template = `
|
|
27
|
-
<div tw="bg-gray-50 flex w-full h-full items-center justify-center">
|
|
28
|
-
<div tw="flex flex-col md:flex-row w-full py-12 px-4 md:items-center justify-between p-8">
|
|
29
|
-
<h2 tw="flex flex-col text-3xl sm:text-4xl font-bold tracking-tight text-gray-900 text-left">
|
|
30
|
-
<span>Ready to dive in?</span>
|
|
31
|
-
<span tw="text-indigo-600">Start your free trial today.</span>
|
|
32
|
-
</h2>
|
|
33
|
-
<div tw="mt-8 flex md:mt-0">
|
|
34
|
-
<div tw="flex rounded-md shadow">
|
|
35
|
-
<a href="#" tw="flex items-center justify-center rounded-md border border-transparent bg-indigo-600 px-5 py-3 text-base font-medium text-white">Get started</a>
|
|
36
|
-
</div>
|
|
37
|
-
<div tw="ml-3 flex rounded-md shadow">
|
|
38
|
-
<a href="#" tw="flex items-center justify-center rounded-md border border-transparent bg-white px-5 py-3 text-base font-medium text-indigo-600">Learn more</a>
|
|
39
|
-
</div>
|
|
40
|
-
</div>
|
|
41
|
-
</div>
|
|
42
|
-
</div>
|
|
43
|
-
`;
|
|
44
|
-
|
|
45
|
-
const fontFile = await fetch('https://og-playground.vercel.app/inter-latin-ext-400-normal.woff');
|
|
46
|
-
const fontData: ArrayBuffer = await fontFile.arrayBuffer();
|
|
47
|
-
|
|
48
|
-
export const GET: RequestHandler = async () => {
|
|
49
|
-
return await ImageResponse(template, {
|
|
50
|
-
height: 630,
|
|
51
|
-
width: 1200,
|
|
52
|
-
fonts: [
|
|
53
|
-
{
|
|
54
|
-
name: 'Inter Latin',
|
|
55
|
-
data: fontData,
|
|
56
|
-
weight: 400
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Then run `npm dev` and visit `localhost:5173/og` to view your generated PNG. Remember that hot module reloading does not work with server routes, so if you change your HTML or CSS, hard refresh the route to see changes.
|
|
64
|
-
|
|
65
|
-
## Example Output
|
|
66
|
-
|
|
67
|
-

|
|
68
|
-
|
|
69
|
-
## Headers
|
|
70
|
-
|
|
71
|
-
When run in development, image headers contain `cache-control: no-cache, no-store`. In production, image headers contain `'cache-control': 'public, immutable, no-transform, max-age=31536000'`, which caches the image for 1 year. In both cases, the `'content-type': 'image/png'` is used.
|
|
72
|
-
|
|
73
|
-
## Styling
|
|
74
|
-
|
|
75
|
-
Notice that our example uses TailwindCSS classes (e.g. `tw="bg-gray-50"`). Alternatively, your HTML can contain style attributes using any of [the subset of CSS supported by Satori](https://github.com/vercel/satori#css).
|
|
76
|
-
|
|
77
|
-
Satori supports only a subset of HTML and CSS. For full details, see [Satori’s documentation](https://github.com/vercel/satori#documentation). Notably, Satori only supports flex-based layouts.
|
|
78
|
-
|
|
79
|
-
## Fonts
|
|
80
|
-
|
|
81
|
-
Satori supports `ttf`, `otf`, and `woff` font formats; `woff2` is not supported. To maximize the font parsing speed, `ttf` or `otf` are recommended over `woff`.
|
|
82
|
-
|
|
83
|
-
By default, `@ethercorps/sveltekit-og` includes only 'Noto Sans' font. If you need to use other fonts, you can specify them as shown in the example. Notably, you can also import a font file that is stored locally within your project and are not required to use fetch.
|
|
84
|
-
|
|
85
|
-
## Examples
|
|
86
|
-
|
|
87
|
-
- `ImageResponse` · [_source_](/src/routes/new/+server.ts) · [_demo_](https://sveltekit-og-five.vercel.app/new)
|
|
88
|
-
- `componentToImageResponse` · [_source_](/src/routes/component-og/) · [_demo_](https://sveltekit-og-five.vercel.app/component-og)
|
|
89
|
-
|
|
90
|
-
## API Reference
|
|
91
|
-
|
|
92
|
-
The package exposes an `ImageResponse` and `componentToImageResponse` constructors, with the following options available:
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
import {ImageResponse, componentToImageResponse} from '@ethercorps/sveltekit-og'
|
|
96
|
-
import {SvelteComponent} from "svelte";
|
|
97
|
-
|
|
98
|
-
// ...
|
|
99
|
-
ImageResponse(
|
|
100
|
-
element : string,
|
|
101
|
-
options : {
|
|
102
|
-
width ? : number = 1200
|
|
103
|
-
height ? : number = 630,
|
|
104
|
-
backgroundColor ? : string = "#fff"
|
|
105
|
-
fonts ? : {
|
|
106
|
-
name: string,
|
|
107
|
-
data: ArrayBuffer,
|
|
108
|
-
weight: number,
|
|
109
|
-
style: 'normal' | 'italic'
|
|
110
|
-
}[]
|
|
111
|
-
debug ? : boolean = false
|
|
112
|
-
graphemeImages ? : Record<string, string>;
|
|
113
|
-
loadAdditionalAsset ? : (languageCode: string, segment: string) => Promise<SatoriOptions["fonts"] | string | undefined>;
|
|
114
|
-
// Options that will be passed to the HTTP response
|
|
115
|
-
status ? : number = 200
|
|
116
|
-
statusText ? : string
|
|
117
|
-
headers ? : Record<string, string>
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
componentToImageResponse(
|
|
121
|
-
component : typeof SvelteComponent,
|
|
122
|
-
props : {}, // All export let example inside prop dictionary
|
|
123
|
-
options : {
|
|
124
|
-
width ? : number = 1200
|
|
125
|
-
height ? : number = 630
|
|
126
|
-
fonts ? : {
|
|
127
|
-
name: string,
|
|
128
|
-
data: ArrayBuffer,
|
|
129
|
-
weight: number,
|
|
130
|
-
style: 'normal' | 'italic'
|
|
131
|
-
}[]
|
|
132
|
-
debug ? : boolean = false
|
|
133
|
-
graphemeImages ? : Record<string, string>;
|
|
134
|
-
loadAdditionalAsset ? : (languageCode: string, segment: string) => Promise<SatoriOptions["fonts"] | string | undefined>;
|
|
135
|
-
// Options that will be passed to the HTTP response
|
|
136
|
-
status ? : number = 200
|
|
137
|
-
statusText ? : string
|
|
138
|
-
headers ? : Record<string, string>
|
|
139
|
-
})
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## Changelog
|
|
143
|
-
|
|
144
|
-
### v1.2.3 Update (Breaking Changes)
|
|
145
|
-
|
|
146
|
-
> Now you have to install dependency by yourself which will make it easier to build for all plateforms.
|
|
147
|
-
|
|
148
|
-
```
|
|
149
|
-
npm i @resvg/resvg-js
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
```
|
|
153
|
-
npm i satori
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
> From now on their will be no issues related to build, and soon this library going to have its own documentation.
|
|
157
|
-
|
|
158
|
-
### v1.2.2 Update (Breaking Change)
|
|
159
|
-
|
|
160
|
-
- We don't provide access to satori from `@ethercorps/sveltekit-og`.
|
|
161
|
-
|
|
162
|
-
### v1.0.0 Update (Breaking Changes)
|
|
163
|
-
|
|
164
|
-
Finally, We have added html to react like element like object converter out of the box and with svelte compiler.
|
|
165
|
-
Now you can use `{ toReactElement }` with `"@ethercorps/sveltekit-og"` like:
|
|
166
|
-
|
|
167
|
-
- We have changed to function based instead of class based ImageResponse and componentToImageResponse.
|
|
168
|
-
- Removed `@resvg/resvg-wasm` with `@resvg/resvg-js` because of internal errors.
|
|
169
|
-
- Removed `satori-html` because now we have `toReactElement` out of the box with svelte compiler.
|
|
170
|
-
> If you find a problem related to undefined a please check [_vite.config.js_](/vite.config.ts) and add ` define: { _a: 'undefined' } in config.`
|
|
171
|
-
|
|
172
|
-
> If you find any issue and have suggestion for this project please open a ticket and if you want to contribute please create a new discussion.
|
|
173
|
-
|
|
174
|
-
## Acknowledgements
|
|
175
|
-
|
|
176
|
-
This project will not be possible without the following projects:
|
|
177
|
-
|
|
178
|
-
- [Satori & @vercel/og](https://github.com/vercel/satori)
|
|
179
|
-
- [Noto by Google Fonts](https://fonts.google.com/noto)
|
|
180
|
-
- [svg2png-wasm](https://github.com/ssssota/svg2png-wasm)
|
|
181
|
-
|
|
182
|
-
## Authors
|
|
183
|
-
|
|
184
|
-
- [@theetherGit](https://www.github.com/theetherGit)
|
|
185
|
-
- [@etherCorps](https://www.github.com/etherCorps)
|
|
186
|
-
|
|
187
|
-
## Contributors
|
|
188
|
-
|
|
189
|
-
- [@jasongitmail](https://github.com/jasongitmail)
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ImageResponseOptions } from './types.js';
|
|
2
|
+
import type { SvelteComponent } from "svelte";
|
|
3
|
+
export declare const og: (element: string | SvelteComponent, options: ImageResponseOptions, props?: {}) => Promise<string | Uint8Array>;
|
|
4
|
+
export declare class ImageResponse extends Response {
|
|
5
|
+
constructor(element: string | SvelteComponent, options?: ImageResponseOptions, props?: {});
|
|
6
|
+
}
|
package/dist/font.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ImageResponse } from "./api.js";
|