@ethercorps/sveltekit-og 0.0.3
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 +21 -0
- package/README.md +38 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +38 -0
- package/svelte-satori.d.ts +16 -0
- package/svelte-satori.js +54 -0
- package/vendors/resvg.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Ether Corps
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# create-svelte
|
|
2
|
+
|
|
3
|
+
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
|
|
4
|
+
|
|
5
|
+
## Creating a project
|
|
6
|
+
|
|
7
|
+
If you're seeing this, you've probably already done this step. Congrats!
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# create a new project in the current directory
|
|
11
|
+
npm create svelte@latest
|
|
12
|
+
|
|
13
|
+
# create a new project in my-app
|
|
14
|
+
npm create svelte@latest my-app
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Developing
|
|
18
|
+
|
|
19
|
+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm run dev
|
|
23
|
+
|
|
24
|
+
# or start the server and open the app in a new browser tab
|
|
25
|
+
npm run dev -- --open
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Building
|
|
29
|
+
|
|
30
|
+
To create a production version of your app:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm run build
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
You can preview the production build with `npm run preview`.
|
|
37
|
+
|
|
38
|
+
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ImageResponse, componentToImageResponse, ImageResponseOptions } from "./svelte-satori";
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ImageResponse, componentToImageResponse, ImageResponseOptions } from './svelte-satori';
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ethercorps/sveltekit-og",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"devDependencies": {
|
|
5
|
+
"@playwright/test": "^1.25.0",
|
|
6
|
+
"@sveltejs/adapter-auto": "next",
|
|
7
|
+
"@sveltejs/package": "next",
|
|
8
|
+
"@typescript-eslint/eslint-plugin": "^5.27.0",
|
|
9
|
+
"@typescript-eslint/parser": "^5.27.0",
|
|
10
|
+
"eslint": "^8.16.0",
|
|
11
|
+
"eslint-config-prettier": "^8.3.0",
|
|
12
|
+
"eslint-plugin-svelte3": "^4.0.0",
|
|
13
|
+
"prettier": "^2.6.2",
|
|
14
|
+
"prettier-plugin-svelte": "^2.7.0",
|
|
15
|
+
"svelte": "^3.44.0",
|
|
16
|
+
"svelte-check": "^2.7.1",
|
|
17
|
+
"svelte-preprocess": "^4.10.6",
|
|
18
|
+
"tslib": "^2.3.1",
|
|
19
|
+
"typescript": "^4.7.4",
|
|
20
|
+
"vite": "^3.1.0",
|
|
21
|
+
"sveltekit-og": "link:./package"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@resvg/resvg-wasm": "^2.1.0",
|
|
26
|
+
"satori": "^0.0.42",
|
|
27
|
+
"satori-html": "^0.2.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@sveltejs/kit": "next"
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
"./package.json": "./package.json",
|
|
34
|
+
".": "./index.js",
|
|
35
|
+
"./svelte-satori": "./svelte-satori.js",
|
|
36
|
+
"./vendors/resvg.wasm": "./vendors/resvg.wasm"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SvelteComponent } from 'svelte';
|
|
2
|
+
import type { SatoriOptions } from 'satori';
|
|
3
|
+
export declare const ImageResponse: {
|
|
4
|
+
new (htmlTemplate: string, optionsByUser: ImageResponseOptions): {};
|
|
5
|
+
};
|
|
6
|
+
export declare const componentToImageResponse: {
|
|
7
|
+
new (component: SvelteComponent, props: {} | undefined, optionsByUser: ImageResponseOptions): {};
|
|
8
|
+
};
|
|
9
|
+
export declare type ImageResponseOptions = ConstructorParameters<typeof Response>[1] & ImageOptions;
|
|
10
|
+
declare type ImageOptions = {
|
|
11
|
+
width?: number;
|
|
12
|
+
height?: number;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
fonts?: SatoriOptions['fonts'];
|
|
15
|
+
};
|
|
16
|
+
export {};
|
package/svelte-satori.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { html as toReactNode } from 'satori-html';
|
|
2
|
+
import satori from 'satori';
|
|
3
|
+
import { Resvg, initWasm } from '@resvg/resvg-wasm';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { readFileSync } from 'fs';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const resSvgWasm = initWasm(readFileSync(join(__filename, '../vendors/resvg.wasm')));
|
|
9
|
+
const fontFile = await fetch('https://og-playground.vercel.app/inter-latin-ext-400-normal.woff');
|
|
10
|
+
const fontData = await fontFile.arrayBuffer();
|
|
11
|
+
export const ImageResponse = class {
|
|
12
|
+
constructor(htmlTemplate, optionsByUser) {
|
|
13
|
+
const options = Object.assign({ width: 1200, height: 630, debug: !1 }, optionsByUser);
|
|
14
|
+
const png = new ReadableStream({
|
|
15
|
+
async start(a) {
|
|
16
|
+
await resSvgWasm;
|
|
17
|
+
const svg = await satori(toReactNode(htmlTemplate), {
|
|
18
|
+
width: options.width,
|
|
19
|
+
height: options.height,
|
|
20
|
+
fonts: options.fonts || [
|
|
21
|
+
{
|
|
22
|
+
name: 'Inter Latin',
|
|
23
|
+
data: fontData,
|
|
24
|
+
weight: 400,
|
|
25
|
+
style: 'normal'
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
});
|
|
29
|
+
const pngData = new Resvg(svg, { fitTo: { mode: 'width', value: options.width } });
|
|
30
|
+
a.enqueue(pngData.render().asPng());
|
|
31
|
+
a.close();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return new Response(png, {
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'image/png',
|
|
37
|
+
'cache-control': 'public, immutable, no-transform, max-age=31536000',
|
|
38
|
+
...options.headers
|
|
39
|
+
},
|
|
40
|
+
status: options.status,
|
|
41
|
+
statusText: options.statusText
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export const componentToImageResponse = class {
|
|
46
|
+
constructor(component, props = {}, optionsByUser) {
|
|
47
|
+
const SvelteRenderedMarkup = component.render(props);
|
|
48
|
+
let htmlTemplate = `${SvelteRenderedMarkup.html}`;
|
|
49
|
+
if (SvelteRenderedMarkup && SvelteRenderedMarkup.css && SvelteRenderedMarkup.css.code) {
|
|
50
|
+
htmlTemplate = `${SvelteRenderedMarkup.html}<style>${SvelteRenderedMarkup.css.code}</style>`;
|
|
51
|
+
}
|
|
52
|
+
return new ImageResponse(htmlTemplate, optionsByUser);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
Binary file
|