@ethercorps/sveltekit-og 0.1.1 → 0.1.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.
Files changed (4) hide show
  1. package/README.md +48 -20
  2. package/index.d.ts +3 -2
  3. package/index.js +12 -10
  4. package/package.json +3 -3
package/README.md CHANGED
@@ -49,7 +49,7 @@ export const GET: RequestHandler = async () => {
49
49
 
50
50
  ```
51
51
 
52
- Then run `pnpm dev` and access localhost:5173/og, the React element will be rendered and responded as a PNG from that endpoint:
52
+ Then run `pnpm dev` and access localhost:5173/og, the api/route endpoint be rendered and responded as a PNG from that api/endpoint:
53
53
 
54
54
  ![Rendered OG image](static/demo.png)
55
55
 
@@ -62,32 +62,53 @@ Read more about the API, supported features and check out the examples on Satori
62
62
 
63
63
  ## API Reference
64
64
 
65
- The package exposes an `ImageResponse` constructor, with the following options available:
65
+ The package exposes an `ImageResponse` and `componentToImageResponse` constructors, with the following options available:
66
66
 
67
67
  ```typescript
68
- import { ImageResponse } from '@ethercorps/sveltekit-og'
68
+ import {ImageResponse, componentToImageResponse} from '@ethercorps/sveltekit-og'
69
+ import {SvelteComponent} from "svelte";
69
70
 
70
71
  // ...
71
72
  new ImageResponse(
72
- element: string,
73
- options: {
74
- width?: number = 1200
75
- height?: number = 630
76
- fonts?: {
77
- name: string,
78
- data: ArrayBuffer,
79
- weight: number,
80
- style: 'normal' | 'italic'
73
+ element : string,
74
+ options : {
75
+ width ? : number = 1200
76
+ height ? : number = 630
77
+ fonts ? : {
78
+ name: string,
79
+ data: ArrayBuffer,
80
+ weight: number,
81
+ style: 'normal' | 'italic'
81
82
  }[]
82
- debug?: boolean = false
83
- graphemeImages?: Record<string, string>;
84
- loadAdditionalAsset?: (languageCode: string, segment: string) => Promise<SatoriOptions["fonts"] | string | undefined>;
83
+ debug ? : boolean = false
84
+ graphemeImages ? : Record<string, string>;
85
+ loadAdditionalAsset ? : (languageCode: string, segment: string) => Promise<SatoriOptions["fonts"] | string | undefined>;
85
86
  // Options that will be passed to the HTTP response
86
- status?: number = 200
87
- statusText?: string
88
- headers?: Record<string, string>
89
- },
90
- )
87
+ status ? : number = 200
88
+ statusText ? : string
89
+ headers ? : Record<string, string>
90
+ })
91
+
92
+ new componentToImageResponse(
93
+ component : typeof SvelteComponent,
94
+ props : {}, // All export let example inside prop dictionary
95
+ options : {
96
+ width ? : number = 1200
97
+ height ? : number = 630
98
+ fonts ? : {
99
+ name: string,
100
+ data: ArrayBuffer,
101
+ weight: number,
102
+ style: 'normal' | 'italic'
103
+ }[]
104
+ debug ? : boolean = false
105
+ graphemeImages ? : Record<string, string>;
106
+ loadAdditionalAsset ? : (languageCode: string, segment: string) => Promise<SatoriOptions["fonts"] | string | undefined>;
107
+ // Options that will be passed to the HTTP response
108
+ status ? : number = 200
109
+ statusText ? : string
110
+ headers ? : Record<string, string>
111
+ })
91
112
  ```
92
113
 
93
114
  When running in production, these headers will be included by `@ethercorps/sveltekit-og`:
@@ -111,5 +132,12 @@ By default, `@ethercorps/sveltekit-og` only has the 'Noto Sans' font included. I
111
132
  This project will not be possible without the following projects:
112
133
 
113
134
  - [Satori & @vercel/og](https://github.com/vercel/satori)
135
+ - [Satori-Html](https://github.com/natemoo-re/satori-html)
114
136
  - [Noto by Google Fonts](https://fonts.google.com/noto)
115
137
  - [Resvg.js](https://github.com/yisibl/resvg-js)
138
+
139
+
140
+ ## Authors
141
+
142
+ - [@theetherGit](https://www.github.com/theetherGit)
143
+ - [@etherCorps](https://www.github.com/etherCorps)
package/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import type { SatoriOptions } from 'satori';
2
+ import type { SvelteComponent } from "svelte";
2
3
  export declare const ImageResponse: {
3
4
  new (htmlTemplate: string, optionsByUser: ImageResponseOptions): {};
4
5
  };
5
6
  export declare const componentToImageResponse: {
6
- new (component: any, props: {} | undefined, optionsByUser: ImageResponseOptions): {};
7
+ new (component: typeof SvelteComponent, props: {} | undefined, optionsByUser: ImageResponseOptions): {};
7
8
  };
8
- export declare type ImageResponseOptions = ConstructorParameters<typeof Response>[1] & ImageOptions;
9
+ declare type ImageResponseOptions = ConstructorParameters<typeof Response>[1] & ImageOptions;
9
10
  declare type ImageOptions = {
10
11
  width?: number;
11
12
  height?: number;
package/index.js CHANGED
@@ -1,10 +1,8 @@
1
1
  import { html as toReactNode } from 'satori-html';
2
2
  import satori from 'satori';
3
3
  import { Resvg, initWasm } from '@resvg/resvg-wasm';
4
- import { fileURLToPath } from 'url';
5
- const __filename = fileURLToPath(import.meta.url);
6
- const resSvgWasm = initWasm(fetch('https://unpkg.com/@resvg/resvg-wasm/index_bg.wasm'));
7
- const fontFile = await fetch('https://sveltekit-og-five.vercel.app/noto-sans.ttf');
4
+ const resSvgWasm = initWasm(fetch('https://sveltekit-og.ethercorps.io/resvg.wasm'));
5
+ const fontFile = await fetch('https://sveltekit-og.ethercorps.io/noto-sans.ttf');
8
6
  const fontData = await fontFile.arrayBuffer();
9
7
  export const ImageResponse = class {
10
8
  constructor(htmlTemplate, optionsByUser) {
@@ -26,7 +24,7 @@ export const ImageResponse = class {
26
24
  ]
27
25
  });
28
26
  const pngData = new Resvg(svg, { fitTo: { mode: 'width', value: options.width } });
29
- a.enqueue(await pngData.render().asPng());
27
+ a.enqueue(pngData.render().asPng());
30
28
  a.close();
31
29
  }
32
30
  });
@@ -45,11 +43,15 @@ export const ImageResponse = class {
45
43
  };
46
44
  export const componentToImageResponse = class {
47
45
  constructor(component, props = {}, optionsByUser) {
48
- const SvelteRenderedMarkup = component.render(props);
49
- let htmlTemplate = `${SvelteRenderedMarkup.html}`;
50
- if (SvelteRenderedMarkup && SvelteRenderedMarkup.css && SvelteRenderedMarkup.css.code) {
51
- htmlTemplate = `${SvelteRenderedMarkup.html}<style>${SvelteRenderedMarkup.css.code}</style>`;
52
- }
46
+ const htmlTemplate = componentToMarkup(component, props);
53
47
  return new ImageResponse(htmlTemplate, optionsByUser);
54
48
  }
55
49
  };
50
+ const componentToMarkup = (component, props = {}) => {
51
+ const SvelteRenderedMarkup = component.render(props);
52
+ let htmlTemplate = `${SvelteRenderedMarkup.html}`;
53
+ if (SvelteRenderedMarkup && SvelteRenderedMarkup.css && SvelteRenderedMarkup.css.code) {
54
+ htmlTemplate = `${SvelteRenderedMarkup.html}<style>${SvelteRenderedMarkup.css.code}</style>`;
55
+ }
56
+ return htmlTemplate;
57
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethercorps/sveltekit-og",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "private": false,
5
5
  "devDependencies": {
6
6
  "@playwright/test": "^1.27.1",
@@ -24,8 +24,8 @@
24
24
  "type": "module",
25
25
  "dependencies": {
26
26
  "@resvg/resvg-wasm": "^2.1.0",
27
- "satori": "^0.0.42",
28
- "satori-html": "^0.2.0"
27
+ "satori": "^0.0.43",
28
+ "satori-html": "^0.3.0"
29
29
  },
30
30
  "keywords": [
31
31
  "open graph image",