@ethercorps/sveltekit-og 3.0.0-alpha.1 → 3.0.0-next.11
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 +171 -0
- package/dist/helpers/create.d.ts +5 -0
- package/dist/helpers/create.js +45 -0
- package/dist/helpers/defaults.d.ts +10 -0
- package/dist/helpers/defaults.js +37 -0
- package/dist/helpers/emoji.d.ts +3 -0
- package/dist/helpers/emoji.js +53 -0
- package/dist/image-response.d.ts +5 -0
- package/dist/image-response.js +27 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -157
- package/dist/providers/instances.d.ts +38 -0
- package/dist/providers/instances.js +22 -0
- package/dist/providers/resvg/node.d.ts +6 -0
- package/dist/providers/resvg/node.js +6 -0
- package/dist/providers/resvg/wasm.d.ts +6 -0
- package/dist/providers/resvg/wasm.js +6 -0
- package/dist/providers/satori/node.d.ts +6 -0
- package/dist/providers/satori/node.js +6 -0
- package/dist/providers/satori/wasm.d.ts +6 -0
- package/dist/providers/satori/wasm.js +16 -0
- package/dist/runtime/compatability.d.ts +2 -0
- package/dist/runtime/compatability.js +25 -0
- package/dist/runtime/detector.d.ts +3 -0
- package/dist/runtime/detector.js +29 -0
- package/dist/types.d.ts +90 -2
- package/dist/types.js +3 -0
- package/package.json +67 -55
- package/dist/api.d.ts +0 -6
- package/dist/font.d.ts +0 -5
- package/dist/resvg-HVRFGR4B.wasm +0 -0
- package/dist/yoga-ZMNYPE6Z.wasm +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type _satori from 'satori';
|
|
2
|
+
export declare function useResvg(): Promise<new (svg: Uint8Array | string, options?: import("@resvg/resvg-wasm").ResvgRenderOptions) => {
|
|
3
|
+
free(): void;
|
|
4
|
+
render(): {
|
|
5
|
+
free(): void;
|
|
6
|
+
asPng(): Uint8Array;
|
|
7
|
+
readonly height: number;
|
|
8
|
+
readonly pixels: Uint8Array;
|
|
9
|
+
readonly width: number;
|
|
10
|
+
};
|
|
11
|
+
toString(): string;
|
|
12
|
+
innerBBox(): {
|
|
13
|
+
free(): void;
|
|
14
|
+
height: number;
|
|
15
|
+
width: number;
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
} | undefined;
|
|
19
|
+
getBBox(): {
|
|
20
|
+
free(): void;
|
|
21
|
+
height: number;
|
|
22
|
+
width: number;
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
} | undefined;
|
|
26
|
+
cropByBBox(bbox: {
|
|
27
|
+
free(): void;
|
|
28
|
+
height: number;
|
|
29
|
+
width: number;
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
}): void;
|
|
33
|
+
imagesToResolve(): any[];
|
|
34
|
+
resolveImage(href: string, buffer: Uint8Array): void;
|
|
35
|
+
readonly height: number;
|
|
36
|
+
readonly width: number;
|
|
37
|
+
}>;
|
|
38
|
+
export declare function useSatori(): Promise<typeof _satori>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isEdgeLight, isWorkerd } from 'std-env';
|
|
2
|
+
// we keep instances alive to avoid re-importing them on every request, maybe not needed but
|
|
3
|
+
// also helps with type inference
|
|
4
|
+
// Code from vue-og-images
|
|
5
|
+
const resvgInstance = { instance: undefined };
|
|
6
|
+
const satoriInstance = { instance: undefined };
|
|
7
|
+
export async function useResvg() {
|
|
8
|
+
const moduleImport = isEdgeLight || isWorkerd ? import(`./resvg/wasm.js`) : import('./resvg/node.js');
|
|
9
|
+
try {
|
|
10
|
+
resvgInstance.instance = resvgInstance.instance || await moduleImport.then(m => m.default);
|
|
11
|
+
await resvgInstance.instance.initWasmPromise;
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
console.log(e);
|
|
15
|
+
}
|
|
16
|
+
return resvgInstance.instance.Resvg;
|
|
17
|
+
}
|
|
18
|
+
export async function useSatori() {
|
|
19
|
+
satoriInstance.instance = satoriInstance.instance || await import(`./satori/node.js`).then(m => m.default);
|
|
20
|
+
await satoriInstance.instance.initWasmPromise;
|
|
21
|
+
return satoriInstance.instance.satori;
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import _satori from 'satori/wasm'
|
|
2
|
+
import initYoga from 'yoga-wasm-web'
|
|
3
|
+
import { init } from 'satori'
|
|
4
|
+
|
|
5
|
+
const wasm = import('yoga-wasm-web/dist/yoga.wasm?module')
|
|
6
|
+
.then(async yoga => await initYoga(yoga.default || yoga))
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
initWasmPromise: ((resolve) => {
|
|
10
|
+
wasm.then((yoga) => {
|
|
11
|
+
init(yoga)
|
|
12
|
+
resolve()
|
|
13
|
+
})
|
|
14
|
+
}),
|
|
15
|
+
satori: _satori,
|
|
16
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const NodeRuntime = {
|
|
2
|
+
'resvg': 'wasm',
|
|
3
|
+
'satori': 'wasm',
|
|
4
|
+
};
|
|
5
|
+
const WorkersRuntime = {
|
|
6
|
+
'resvg': 'wasm',
|
|
7
|
+
'satori': 'node',
|
|
8
|
+
};
|
|
9
|
+
const WebContainerRuntime = {
|
|
10
|
+
'resvg': 'wasm-fs',
|
|
11
|
+
'satori': 'wasm-fs',
|
|
12
|
+
};
|
|
13
|
+
export const runtimeCompatibility = {
|
|
14
|
+
'dev': NodeRuntime,
|
|
15
|
+
'node': NodeRuntime,
|
|
16
|
+
'stackblitz': WebContainerRuntime,
|
|
17
|
+
'codesandbox': WebContainerRuntime,
|
|
18
|
+
'aws-lambda': NodeRuntime,
|
|
19
|
+
'netlify': NodeRuntime,
|
|
20
|
+
'netlify-edge': WorkersRuntime,
|
|
21
|
+
'vercel': NodeRuntime,
|
|
22
|
+
'vercel-edge': WorkersRuntime,
|
|
23
|
+
'cloudflare-pages': WorkersRuntime,
|
|
24
|
+
'cloudflare-workers': WorkersRuntime
|
|
25
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { provider, env, runtime, isDevelopment } from 'std-env';
|
|
2
|
+
import { runtimeCompatibility } from '../runtime/compatability.js';
|
|
3
|
+
export function getRuntime() {
|
|
4
|
+
if (provider === 'stackblitz' || provider === 'codesandbox')
|
|
5
|
+
return provider;
|
|
6
|
+
if (isDevelopment) {
|
|
7
|
+
return 'node';
|
|
8
|
+
}
|
|
9
|
+
const parsedProvider = provider.replace('_', '-');
|
|
10
|
+
const compatibility = runtimeCompatibility[env['OG_RUNTIME'] || parsedProvider];
|
|
11
|
+
if (compatibility)
|
|
12
|
+
return parsedProvider;
|
|
13
|
+
switch (runtime) {
|
|
14
|
+
case 'node':
|
|
15
|
+
case 'deno':
|
|
16
|
+
case 'bun':
|
|
17
|
+
case 'netlify':
|
|
18
|
+
default:
|
|
19
|
+
return 'node';
|
|
20
|
+
case 'edge-light':
|
|
21
|
+
return 'vercel-edge';
|
|
22
|
+
case 'workerd':
|
|
23
|
+
return 'cloudflare-workers';
|
|
24
|
+
}
|
|
25
|
+
;
|
|
26
|
+
}
|
|
27
|
+
export function getRuntimeCompatibility(runtime = getRuntime()) {
|
|
28
|
+
return runtimeCompatibility[runtime];
|
|
29
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,99 @@
|
|
|
1
1
|
import type { SatoriOptions } from 'satori/wasm';
|
|
2
|
-
export
|
|
2
|
+
export type ImageOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Width of the image
|
|
5
|
+
* @default 1200
|
|
6
|
+
* */
|
|
3
7
|
width?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Height of the image
|
|
10
|
+
* @default 630
|
|
11
|
+
* */
|
|
4
12
|
height?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Emoji provider
|
|
15
|
+
* @default twemoji
|
|
16
|
+
* */
|
|
17
|
+
emoji?: 'twemoji' | 'blobmoji' | 'noto' | 'openmoji' | 'fluent' | 'fluentFlat';
|
|
18
|
+
/**
|
|
19
|
+
* Fonts used for your text
|
|
20
|
+
* @default `helpers/defaults.js`
|
|
21
|
+
* */
|
|
5
22
|
fonts?: SatoriOptions['fonts'];
|
|
23
|
+
/**
|
|
24
|
+
* Tailwind config
|
|
25
|
+
* @default provided by satori
|
|
26
|
+
* */
|
|
27
|
+
tailwindConfig?: SatoriOptions['tailwindConfig'];
|
|
28
|
+
/**
|
|
29
|
+
* Debug operations
|
|
30
|
+
* @default false
|
|
31
|
+
* */
|
|
6
32
|
debug?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Image format
|
|
35
|
+
* @default png
|
|
36
|
+
* */
|
|
37
|
+
format?: 'svg' | 'png';
|
|
38
|
+
};
|
|
39
|
+
export type ResponseImageOptions = {
|
|
40
|
+
/**
|
|
41
|
+
* Status code for response
|
|
42
|
+
* @default 200
|
|
43
|
+
* */
|
|
7
44
|
status?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Status text for response
|
|
47
|
+
* @default Success
|
|
48
|
+
* */
|
|
8
49
|
statusText?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Response Headers
|
|
52
|
+
* @default {
|
|
53
|
+
* 'Content-Type': 'image/png',
|
|
54
|
+
* 'Cache-Control': options.debug ? 'no-cache, no-store' : 'public, immutable, no-transform, max-age=31536000'
|
|
55
|
+
* }
|
|
56
|
+
* */
|
|
9
57
|
headers?: Record<string, string>;
|
|
10
|
-
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Image response options type exposed to devs for ImageResponse Instance
|
|
61
|
+
* */
|
|
62
|
+
export type ImageResponseOptions = ImageOptions & ResponseImageOptions;
|
|
63
|
+
/**
|
|
64
|
+
* Svelte Component props to render the component which dynamic content
|
|
65
|
+
* */
|
|
66
|
+
export type ComponentOptions = {
|
|
67
|
+
props: Record<string, any>;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* React virtual node, supported by satori as input (alternative to JSX input).
|
|
71
|
+
* */
|
|
72
|
+
export interface VNode {
|
|
73
|
+
type: string;
|
|
74
|
+
props: {
|
|
75
|
+
style?: Record<string, any>;
|
|
76
|
+
children?: string | VNode | VNode[];
|
|
77
|
+
[prop: string]: any;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Supported runtimes by sveltekit-og
|
|
82
|
+
* TODO: Test all the runtimes.
|
|
83
|
+
* */
|
|
84
|
+
export type SupportedRuntimes = 'node' | 'stackblitz' | 'codesandbox' | 'aws-lambda' | 'netlify' | 'netlify-edge' | 'vercel' | 'vercel-edge' | 'cloudflare-pages' | 'cloudflare-workers';
|
|
85
|
+
/**
|
|
86
|
+
* Files support on the basis of runtime
|
|
87
|
+
* node: Use nodejs based implementation of the provider
|
|
88
|
+
* wasm: Use wasm based implementation of the provider
|
|
89
|
+
* wasm-fs: Mainly provided for web containers which supports `fs`.
|
|
90
|
+
* */
|
|
91
|
+
type SupportedImplementations = 'node' | 'wasm' | 'wasm-fs';
|
|
92
|
+
/**
|
|
93
|
+
* Provider and There supported Implementations
|
|
94
|
+
* */
|
|
95
|
+
export interface RuntimeCompatibility {
|
|
96
|
+
resvg: SupportedImplementations;
|
|
97
|
+
satori: SupportedImplementations;
|
|
11
98
|
}
|
|
99
|
+
export {};
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,57 +1,69 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
2
|
+
"name": "@ethercorps/sveltekit-og",
|
|
3
|
+
"version": "3.0.0-next.11",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"dev": "vite dev",
|
|
6
|
+
"build": "vite build && npm run package",
|
|
7
|
+
"preview": "vite preview",
|
|
8
|
+
"package": "svelte-kit sync && svelte-package && publint",
|
|
9
|
+
"prepublishOnly": "npm run package",
|
|
10
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
11
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
12
|
+
"test": "vitest",
|
|
13
|
+
"lint": "prettier --plugin-search-dir . --check . && eslint .",
|
|
14
|
+
"format": "prettier --plugin-search-dir . --write .",
|
|
15
|
+
"publishBeta": "npm publish --tag beta"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"svelte": "./dist/index.js",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"!dist/**/*.test.*",
|
|
27
|
+
"!dist/**/*.spec.*"
|
|
28
|
+
],
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"svelte": "^4.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@sveltejs/adapter-auto": "^3.2.2",
|
|
34
|
+
"@sveltejs/adapter-vercel": "^5.3.2",
|
|
35
|
+
"@sveltejs/kit": "^2.5.17",
|
|
36
|
+
"@sveltejs/package": "^2.3.2",
|
|
37
|
+
"@sveltejs/vite-plugin-svelte": "^3.1.1",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
39
|
+
"@typescript-eslint/parser": "^5.62.0",
|
|
40
|
+
"css-tree": "^2.3.1",
|
|
41
|
+
"eslint": "^8.57.0",
|
|
42
|
+
"eslint-config-prettier": "^8.10.0",
|
|
43
|
+
"eslint-plugin-svelte": "^2.40.0",
|
|
44
|
+
"prettier": "^2.8.8",
|
|
45
|
+
"prettier-plugin-svelte": "^2.10.1",
|
|
46
|
+
"publint": "^0.1.16",
|
|
47
|
+
"svelte": "^4.2.18",
|
|
48
|
+
"svelte-check": "^3.8.1",
|
|
49
|
+
"tslib": "^2.6.3",
|
|
50
|
+
"typescript": "^5.5.2",
|
|
51
|
+
"vite": "^5.3.1",
|
|
52
|
+
"vite-plugin-wasm": "^3.3.0",
|
|
53
|
+
"vitest": "^1.6.0"
|
|
54
|
+
},
|
|
55
|
+
"svelte": "./dist/index.js",
|
|
56
|
+
"types": "./dist/index.d.ts",
|
|
57
|
+
"type": "module",
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@ethercorps/svelte-h2j": "^4.0.0",
|
|
60
|
+
"satori": "^0.10.13",
|
|
61
|
+
"std-env": "^3.7.0",
|
|
62
|
+
"unwasm": "^0.3.9",
|
|
63
|
+
"yoga-wasm-web": "^0.3.3"
|
|
64
|
+
},
|
|
65
|
+
"optionalDependencies": {
|
|
66
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
67
|
+
"@resvg/resvg-wasm": "^2.6.2"
|
|
68
|
+
}
|
|
57
69
|
}
|
package/dist/api.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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
DELETED
package/dist/resvg-HVRFGR4B.wasm
DELETED
|
Binary file
|
package/dist/yoga-ZMNYPE6Z.wasm
DELETED
|
Binary file
|