@ethercorps/sveltekit-og 0.1.4 → 0.1.6

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 CHANGED
@@ -10,6 +10,7 @@ Install `@ethercorps/sveltekit-og`, then use it inside a server endpoint route (
10
10
  ```typescript
11
11
  // /routes/og/+server.ts
12
12
  import { ImageResponse } from '@ethercorps/sveltekit-og';
13
+ import { RequestHandler } from './$types';
13
14
 
14
15
  const template = `
15
16
  <div tw="bg-gray-50 flex w-full h-full items-center justify-center">
@@ -32,20 +33,19 @@ const template = `
32
33
  const fontFile = await fetch('https://og-playground.vercel.app/inter-latin-ext-400-normal.woff');
33
34
  const fontData: ArrayBuffer = await fontFile.arrayBuffer();
34
35
 
35
- export const GET: () => Promise<ImageResponse> = async () => {
36
- return new ImageResponse(template, {
37
- height: 250,
38
- width: 500,
39
- fonts: [
40
- {
41
- name: 'Inter Latin',
42
- data: fontData,
43
- weight: 400
44
- }
45
- ]
46
- });
36
+ export const GET: RequestHandler = async () => {
37
+ return new ImageResponse(template, {
38
+ height: 250,
39
+ width: 500,
40
+ fonts: [
41
+ {
42
+ name: 'Inter Latin',
43
+ data: fontData,
44
+ weight: 400
45
+ }
46
+ ]
47
+ });
47
48
  };
48
-
49
49
  ```
50
50
 
51
51
  Then run `pnpm dev` and access localhost:5173/og, the api/route endpoint be rendered and responded as a PNG from that api/endpoint:
@@ -55,10 +55,10 @@ Then run `pnpm dev` and access localhost:5173/og, the api/route endpoint be rend
55
55
  Read more about the API, supported features and check out the examples on Satori Playground.
56
56
 
57
57
  ## Examples:
58
+
58
59
  - `ImageResponse` · [_source_](/src/routes/+server.ts) · [_demo_](https://sveltekit-og-five.vercel.app)
59
60
  - `componentToImageResponse` · [_source_](/src/routes/component-og/) · [_demo_](https://sveltekit-og-five.vercel.app/component-og)
60
61
 
61
-
62
62
  ## API Reference
63
63
 
64
64
  The package exposes an `ImageResponse` and `componentToImageResponse` constructors, with the following options available:
@@ -125,7 +125,6 @@ Please refer to [Satori’s documentation](https://github.com/vercel/satori#docu
125
125
 
126
126
  By default, `@ethercorps/sveltekit-og` only has the 'Noto Sans' font included. If you need to use other fonts, you can pass them in the `fonts` option.
127
127
 
128
-
129
128
  ## Acknowledgements
130
129
 
131
130
  This project will not be possible without the following projects:
@@ -135,7 +134,6 @@ This project will not be possible without the following projects:
135
134
  - [Noto by Google Fonts](https://fonts.google.com/noto)
136
135
  - [Resvg.js](https://github.com/yisibl/resvg-js)
137
136
 
138
-
139
137
  ## Authors
140
138
 
141
139
  - [@theetherGit](https://www.github.com/theetherGit)
package/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { SatoriOptions } from 'satori';
2
- import type { SvelteComponent } from "svelte";
3
- export declare class ImageResponse {
2
+ import type { SvelteComponent } from 'svelte';
3
+ declare class ImageResponse {
4
4
  constructor(htmlTemplate: string, optionsByUser: ImageResponseOptions);
5
5
  }
6
- export declare class componentToImageResponse {
6
+ declare class componentToImageResponse {
7
7
  constructor(component: typeof SvelteComponent, props: {} | undefined, optionsByUser: ImageResponseOptions);
8
8
  }
9
9
  declare type ImageResponseOptions = ConstructorParameters<typeof Response>[1] & ImageOptions;
@@ -13,6 +13,6 @@ declare type ImageOptions = {
13
13
  debug?: boolean;
14
14
  fonts?: SatoriOptions['fonts'];
15
15
  graphemeImages?: Record<string, string>;
16
- loadAdditionalAsset?: (languageCode: string, segment: string) => Promise<SatoriOptions["fonts"] | string | undefined>;
16
+ loadAdditionalAsset?: (languageCode: string, segment: string) => Promise<SatoriOptions['fonts'] | string | undefined>;
17
17
  };
18
- export {};
18
+ export { componentToImageResponse, ImageResponse };
package/index.js CHANGED
@@ -1,10 +1,11 @@
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 { dev } from '$app/environment';
4
5
  const resSvgWasm = initWasm(fetch('https://sveltekit-og.ethercorps.io/resvg.wasm'));
5
6
  const fontFile = await fetch('https://sveltekit-og.ethercorps.io/noto-sans.ttf');
6
7
  const fontData = await fontFile.arrayBuffer();
7
- export class ImageResponse {
8
+ class ImageResponse {
8
9
  constructor(htmlTemplate, optionsByUser) {
9
10
  const options = Object.assign({ width: 1200, height: 630, debug: !1 }, optionsByUser);
10
11
  const png = new ReadableStream({
@@ -31,7 +32,7 @@ export class ImageResponse {
31
32
  return new Response(png, {
32
33
  headers: {
33
34
  'Content-Type': 'image/png',
34
- 'cache-control': import.meta.env.DEV
35
+ 'cache-control': dev
35
36
  ? 'no-cache, no-store'
36
37
  : 'public, immutable, no-transform, max-age=31536000',
37
38
  ...options.headers
@@ -41,7 +42,7 @@ export class ImageResponse {
41
42
  });
42
43
  }
43
44
  }
44
- export class componentToImageResponse {
45
+ class componentToImageResponse {
45
46
  constructor(component, props = {}, optionsByUser) {
46
47
  const htmlTemplate = componentToMarkup(component, props);
47
48
  return new ImageResponse(htmlTemplate, optionsByUser);
@@ -55,3 +56,4 @@ const componentToMarkup = (component, props = {}) => {
55
56
  }
56
57
  return htmlTemplate;
57
58
  };
59
+ export { componentToImageResponse, ImageResponse };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethercorps/sveltekit-og",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "private": false,
5
5
  "devDependencies": {
6
6
  "@playwright/test": "^1.27.1",