@ethercorps/sveltekit-og 3.0.0-alpha.1 → 3.0.0-next.10

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.
@@ -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 isEdge = isEdgeLight || isWorkerd;
9
+ try {
10
+ resvgInstance.instance = resvgInstance.instance || await import(`./resvg/${isEdge ? 'wasm' : 'node'}.js`).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,6 @@
1
+ declare namespace _default {
2
+ export let initWasmPromise: Promise<void>;
3
+ export { _Resvg as Resvg };
4
+ }
5
+ export default _default;
6
+ import { Resvg as _Resvg } from '@resvg/resvg-js';
@@ -0,0 +1,6 @@
1
+ import { Resvg as _Resvg } from '@resvg/resvg-js'
2
+
3
+ export default {
4
+ initWasmPromise: Promise.resolve(),
5
+ Resvg: _Resvg,
6
+ }
@@ -0,0 +1,6 @@
1
+ declare namespace _default {
2
+ export let initWasmPromise: Promise<void>;
3
+ export { _Resvg as Resvg };
4
+ }
5
+ export default _default;
6
+ import { Resvg as _Resvg } from '@resvg/resvg-wasm';
@@ -0,0 +1,6 @@
1
+ import { Resvg as _Resvg, initWasm } from '@resvg/resvg-wasm'
2
+
3
+ export default {
4
+ initWasmPromise: initWasm(import('@resvg/resvg-wasm/index_bg.wasm?module').then(r => r.default || r)),
5
+ Resvg: _Resvg,
6
+ }
@@ -0,0 +1,6 @@
1
+ declare namespace _default {
2
+ export let initWasmPromise: Promise<void>;
3
+ export { _satori as satori };
4
+ }
5
+ export default _default;
6
+ import _satori from 'satori';
@@ -0,0 +1,6 @@
1
+ import _satori from 'satori'
2
+
3
+ export default {
4
+ initWasmPromise: Promise.resolve(),
5
+ satori: _satori,
6
+ }
@@ -0,0 +1,6 @@
1
+ declare namespace _default {
2
+ export function initWasmPromise(resolve: any): void;
3
+ export { _satori as satori };
4
+ }
5
+ export default _default;
6
+ import _satori from 'satori/wasm';
@@ -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,2 @@
1
+ import type { RuntimeCompatibility, SupportedRuntimes } from '../types.js';
2
+ export declare const runtimeCompatibility: Record<SupportedRuntimes, RuntimeCompatibility>;
@@ -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,3 @@
1
+ import type { RuntimeCompatibility, SupportedRuntimes } from '../types.js';
2
+ export declare function getRuntime(): SupportedRuntimes;
3
+ export declare function getRuntimeCompatibility(runtime?: SupportedRuntimes): RuntimeCompatibility;
@@ -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 interface ImageResponseOptions {
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
- format?: 'svg' | 'png';
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
@@ -0,0 +1,3 @@
1
+ ;
2
+ ;
3
+ export {};
package/package.json CHANGED
@@ -1,57 +1,69 @@
1
1
  {
2
- "name": "@ethercorps/sveltekit-og",
3
- "version": "3.0.0-alpha.1",
4
- "private": false,
5
- "description": "Generate Open Graph Images dynamically from HTML/CSS without a browser in SvelteKit",
6
- "type": "module",
7
- "files": [
8
- "dist"
9
- ],
10
- "devDependencies": {
11
- "svelte": "^4.2.2",
12
- "@types/node": "^20.5.1",
13
- "esbuild": "^0.18.20",
14
- "esbuild-plugin-d.ts": "^1.1.0",
15
- "typescript": "^5.1.6"
16
- },
17
- "dependencies": {
18
- "@ethercorps/svelte-h2j": "link:../svelte-h2j",
19
- "@resvg/resvg-wasm": "^2.4.1",
20
- "just-camel-case": "^6.2.0",
21
- "satori": "^0.10.3",
22
- "yoga-wasm-web": "^0.3.3"
23
- },
24
- "main": "./dist/index.js",
25
- "module": "./dist/index.js",
26
- "exports": {
27
- ".": {
28
- "import": "./dist/index.js",
29
- "require": "./dist/index.js"
30
- }
31
- },
32
- "repository": {
33
- "type": "git",
34
- "url": "git+https://github.com/etherCorps/sveltekit-og.git"
35
- },
36
- "homepage": "https://github.com/etherCorps/sveltekit-og#readme",
37
- "keywords": [
38
- "open graph image",
39
- "open graph",
40
- "og image",
41
- "og:image",
42
- "social",
43
- "card",
44
- "sveltekit og",
45
- "sveltekit-og",
46
- "@ethercorps/sveltekit-og"
47
- ],
48
- "author": "theetherGit",
49
- "license": "MIT",
50
- "bugs": {
51
- "url": "https://github.com/etherCorps/sveltekit-og/issues"
52
- },
53
- "scripts": {
54
- "build": "node bin/esbuild.js",
55
- "ts": "tsc --noEmit"
56
- }
2
+ "name": "@ethercorps/sveltekit-og",
3
+ "version": "3.0.0-next.10",
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
@@ -1,5 +0,0 @@
1
- export declare function loadGoogleFont({ family, weight, text }: {
2
- family: string;
3
- weight?: number;
4
- text?: string;
5
- }): Promise<ArrayBuffer>;
Binary file
Binary file