@ethercorps/sveltekit-og 0.1.3 → 0.1.5
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 +2 -2
- package/index.d.ts +7 -7
- package/index.js +5 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,8 +9,8 @@ Install `@ethercorps/sveltekit-og`, then use it inside a server endpoint route (
|
|
|
9
9
|
|
|
10
10
|
```typescript
|
|
11
11
|
// /routes/og/+server.ts
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
12
|
+
import {ImageResponse} from '@ethercorps/sveltekit-og';
|
|
13
|
+
import {RequestHandler} from "./$types";
|
|
14
14
|
|
|
15
15
|
const template = `
|
|
16
16
|
<div tw="bg-gray-50 flex w-full h-full items-center justify-center">
|
package/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { SatoriOptions } from 'satori';
|
|
2
2
|
import type { SvelteComponent } from "svelte";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
3
|
+
declare class ImageResponse {
|
|
4
|
+
constructor(htmlTemplate: string, optionsByUser: ImageResponseOptions);
|
|
5
|
+
}
|
|
6
|
+
declare class componentToImageResponse {
|
|
7
|
+
constructor(component: typeof SvelteComponent, props: {} | undefined, optionsByUser: ImageResponseOptions);
|
|
8
|
+
}
|
|
9
9
|
declare type ImageResponseOptions = ConstructorParameters<typeof Response>[1] & ImageOptions;
|
|
10
10
|
declare type ImageOptions = {
|
|
11
11
|
width?: number;
|
|
@@ -15,4 +15,4 @@ declare type ImageOptions = {
|
|
|
15
15
|
graphemeImages?: Record<string, string>;
|
|
16
16
|
loadAdditionalAsset?: (languageCode: string, segment: string) => Promise<SatoriOptions["fonts"] | string | undefined>;
|
|
17
17
|
};
|
|
18
|
-
export {};
|
|
18
|
+
export { componentToImageResponse, ImageResponse };
|
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Resvg, initWasm } from '@resvg/resvg-wasm';
|
|
|
4
4
|
const resSvgWasm = initWasm(fetch('https://sveltekit-og.ethercorps.io/resvg.wasm'));
|
|
5
5
|
const fontFile = await fetch('https://sveltekit-og.ethercorps.io/noto-sans.ttf');
|
|
6
6
|
const fontData = await fontFile.arrayBuffer();
|
|
7
|
-
|
|
7
|
+
class ImageResponse {
|
|
8
8
|
constructor(htmlTemplate, optionsByUser) {
|
|
9
9
|
const options = Object.assign({ width: 1200, height: 630, debug: !1 }, optionsByUser);
|
|
10
10
|
const png = new ReadableStream({
|
|
@@ -40,13 +40,13 @@ export const ImageResponse = class {
|
|
|
40
40
|
statusText: options.statusText
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
}
|
|
44
|
-
|
|
43
|
+
}
|
|
44
|
+
class componentToImageResponse {
|
|
45
45
|
constructor(component, props = {}, optionsByUser) {
|
|
46
46
|
const htmlTemplate = componentToMarkup(component, props);
|
|
47
47
|
return new ImageResponse(htmlTemplate, optionsByUser);
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
|
50
50
|
const componentToMarkup = (component, props = {}) => {
|
|
51
51
|
const SvelteRenderedMarkup = component.render(props);
|
|
52
52
|
let htmlTemplate = `${SvelteRenderedMarkup.html}`;
|
|
@@ -55,3 +55,4 @@ const componentToMarkup = (component, props = {}) => {
|
|
|
55
55
|
}
|
|
56
56
|
return htmlTemplate;
|
|
57
57
|
};
|
|
58
|
+
export { componentToImageResponse, ImageResponse };
|