@ethercorps/sveltekit-og 3.0.0-next.12 → 3.0.0-next.14
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/dist/helpers/create.d.ts +1 -1
- package/dist/helpers/create.js +5 -5
- package/dist/helpers/defaults.d.ts +1 -1
- package/dist/helpers/defaults.js +2 -2
- package/dist/image-response.js +4 -5
- package/dist/providers/instances.js +3 -8
- package/dist/providers/resvg/node.d.ts +1 -1
- package/dist/providers/resvg/node.js +10 -3
- package/dist/types.d.ts +1 -21
- package/dist/types.js +0 -2
- package/package.json +3 -13
- package/dist/providers/satori/wasm.d.ts +0 -6
- package/dist/providers/satori/wasm.js +0 -16
- package/dist/runtime/compatability.d.ts +0 -2
- package/dist/runtime/compatability.js +0 -25
- package/dist/runtime/detector.d.ts +0 -3
- package/dist/runtime/detector.js +0 -29
- /package/dist/providers/resvg/{wasm.d.ts → edge.d.ts} +0 -0
- /package/dist/providers/resvg/{wasm.js → edge.js} +0 -0
package/dist/helpers/create.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SvelteComponent } from "svelte";
|
|
2
2
|
import type { ComponentOptions, ImageOptions, VNode } from '../types.js';
|
|
3
|
-
export declare function createVNode(element: string | SvelteComponent, componentOptions?: ComponentOptions): VNode
|
|
3
|
+
export declare function createVNode(element: string | SvelteComponent, componentOptions?: ComponentOptions): Promise<VNode>;
|
|
4
4
|
export declare function createSvg(element: string | SvelteComponent, imageOptions: ImageOptions, componentOptions?: ComponentOptions): Promise<string>;
|
|
5
5
|
export declare function createPng(element: string | SvelteComponent, imageOptions: ImageOptions, componentOptions?: ComponentOptions): Promise<Uint8Array>;
|
package/dist/helpers/create.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { svelteComponentToJsx, toReactElement } from '@ethercorps/svelte-h2j';
|
|
2
2
|
import { loadDynamicAsset } from './emoji.js';
|
|
3
|
-
import { default_fonts } from '../helpers/defaults.js';
|
|
3
|
+
import { default_fonts, DEFAULT_WIDTH } from '../helpers/defaults.js';
|
|
4
4
|
import { useResvg, useSatori } from '../providers/instances.js';
|
|
5
5
|
// TODO: Export VNode Type from svelte-h2j
|
|
6
6
|
// TODO: Make svelte-h2j functions async in new v5 support
|
|
@@ -13,6 +13,8 @@ export async function createSvg(element, imageOptions, componentOptions) {
|
|
|
13
13
|
imageOptions['fonts'] = await default_fonts();
|
|
14
14
|
}
|
|
15
15
|
// Add dynamic emoji loading handler
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
17
|
+
// @ts-ignore
|
|
16
18
|
imageOptions['loadAdditionalAsset'] = loadDynamicAsset({
|
|
17
19
|
emoji: imageOptions.emoji
|
|
18
20
|
});
|
|
@@ -28,13 +30,11 @@ export async function createPng(element, imageOptions, componentOptions) {
|
|
|
28
30
|
console.info('SVG generated by satori:', svg, '\n');
|
|
29
31
|
}
|
|
30
32
|
const resvg_instance = await useResvg();
|
|
31
|
-
console.log(resvg_instance, 'f');
|
|
32
33
|
const resvg_options = {
|
|
33
34
|
fitTo: {
|
|
34
35
|
mode: 'width',
|
|
35
|
-
value: imageOptions.width
|
|
36
|
-
}
|
|
37
|
-
logLevel: imageOptions.debug ? 'info' : 'error'
|
|
36
|
+
value: imageOptions.width || DEFAULT_WIDTH,
|
|
37
|
+
}
|
|
38
38
|
};
|
|
39
39
|
if (imageOptions.debug) {
|
|
40
40
|
console.info('Options provided to ReSVG:', resvg_options, '\n');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SatoriOptions } from 'satori';
|
|
2
2
|
import type { ImageOptions } from '../types.js';
|
|
3
|
-
export declare function default_fonts(): SatoriOptions['fonts']
|
|
3
|
+
export declare function default_fonts(): Promise<SatoriOptions['fonts']>;
|
|
4
4
|
export declare const DEFAULT_FORMAT = "png";
|
|
5
5
|
export declare const DEFAULT_WIDTH = 1200;
|
|
6
6
|
export declare const DEFAULT_HEIGHT = 630;
|
package/dist/helpers/defaults.js
CHANGED
|
@@ -9,13 +9,13 @@ export async function default_fonts() {
|
|
|
9
9
|
const [noto_sans_regular_font, noto_sans_bold_font] = await Promise.all([noto_sans_regular_font_resp.arrayBuffer(), noto_sans_bold_font_reps.arrayBuffer()]);
|
|
10
10
|
return [
|
|
11
11
|
{
|
|
12
|
-
data: noto_sans_regular_font,
|
|
12
|
+
data: new Uint8Array(noto_sans_regular_font),
|
|
13
13
|
name: 'Inter',
|
|
14
14
|
weight: 400,
|
|
15
15
|
style: 'normal'
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
|
-
data: noto_sans_bold_font,
|
|
18
|
+
data: new Uint8Array(noto_sans_bold_font),
|
|
19
19
|
name: 'Inter',
|
|
20
20
|
weight: 700,
|
|
21
21
|
style: 'normal'
|
package/dist/image-response.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { DEFAULT_OPTIONS, DEFAULT_STATUS_CODE, DEFAULT_STATUS_TEXT } from './helpers/defaults.js';
|
|
2
2
|
import { createPng, createSvg } from './helpers/create.js';
|
|
3
|
-
import { isDevelopment } from 'std-env';
|
|
4
3
|
export class ImageResponse extends Response {
|
|
5
4
|
constructor(element, options, props) {
|
|
6
5
|
const extended_options = Object.assign({ ...DEFAULT_OPTIONS }, options);
|
|
7
|
-
const
|
|
6
|
+
const create_image_function = extended_options.format === 'png' ? createPng : createSvg;
|
|
8
7
|
const body = new ReadableStream({
|
|
9
8
|
async start(controller) {
|
|
10
|
-
const buffer = await
|
|
9
|
+
const buffer = await create_image_function(element, extended_options, { props });
|
|
11
10
|
controller.enqueue(buffer);
|
|
12
11
|
controller.close();
|
|
13
12
|
}
|
|
14
13
|
});
|
|
15
14
|
super(body, {
|
|
16
15
|
headers: {
|
|
17
|
-
'Content-Type': `image/${extended_options.format}`,
|
|
18
|
-
'Cache-Control':
|
|
16
|
+
'Content-Type': `image/${extended_options.format}${extended_options.format === 'svg' ? '+xml' : ''}`,
|
|
17
|
+
'Cache-Control': extended_options.debug
|
|
19
18
|
? 'no-cache, no-store'
|
|
20
19
|
: 'public, immutable, no-transform, max-age=31536000',
|
|
21
20
|
...extended_options.headers
|
|
@@ -5,14 +5,9 @@ import { isEdgeLight, isWorkerd } from 'std-env';
|
|
|
5
5
|
const resvgInstance = { instance: undefined };
|
|
6
6
|
const satoriInstance = { instance: undefined };
|
|
7
7
|
export async function useResvg() {
|
|
8
|
-
const moduleImport = isEdgeLight || isWorkerd ? import(`./resvg/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
await resvgInstance.instance.initWasmPromise;
|
|
12
|
-
}
|
|
13
|
-
catch (e) {
|
|
14
|
-
console.log(e);
|
|
15
|
-
}
|
|
8
|
+
const moduleImport = isEdgeLight || isWorkerd ? import(`./resvg/edge.js`) : import('./resvg/node.js');
|
|
9
|
+
resvgInstance.instance = resvgInstance.instance || await moduleImport.then(m => m.default);
|
|
10
|
+
await resvgInstance.instance.initWasmPromise;
|
|
16
11
|
return resvgInstance.instance.Resvg;
|
|
17
12
|
}
|
|
18
13
|
export async function useSatori() {
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import { Resvg as _Resvg } from '@resvg/resvg-
|
|
1
|
+
import { Resvg as _Resvg, initWasm } from '@resvg/resvg-wasm';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fetch will be called only once whenever you load this file.
|
|
5
|
+
* In vercel serverless functions, fetch will run on cold start.
|
|
6
|
+
* In Node.js (Stateful e.g. Linux servers), Fetch will run once when you start your server.
|
|
7
|
+
* */
|
|
8
|
+
const resvgWasm = fetch('https://unpkg.com/@resvg/resvg-wasm/index_bg.wasm')
|
|
2
9
|
|
|
3
10
|
export default {
|
|
4
|
-
initWasmPromise:
|
|
11
|
+
initWasmPromise: initWasm(resvgWasm),
|
|
5
12
|
Resvg: _Resvg,
|
|
6
|
-
}
|
|
13
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ export type ImageResponseOptions = ImageOptions & ResponseImageOptions;
|
|
|
64
64
|
* Svelte Component props to render the component which dynamic content
|
|
65
65
|
* */
|
|
66
66
|
export type ComponentOptions = {
|
|
67
|
-
props
|
|
67
|
+
props?: Record<string, any>;
|
|
68
68
|
};
|
|
69
69
|
/**
|
|
70
70
|
* React virtual node, supported by satori as input (alternative to JSX input).
|
|
@@ -77,23 +77,3 @@ export interface VNode {
|
|
|
77
77
|
[prop: string]: any;
|
|
78
78
|
};
|
|
79
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;
|
|
98
|
-
}
|
|
99
|
-
export {};
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ethercorps/sveltekit-og",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.14",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite dev",
|
|
6
6
|
"build": "vite build && npm run package",
|
|
@@ -57,21 +57,11 @@
|
|
|
57
57
|
"satori": "^0.10.13",
|
|
58
58
|
"std-env": "^3.7.0",
|
|
59
59
|
"unwasm": "^0.3.9",
|
|
60
|
-
"
|
|
60
|
+
"@resvg/resvg-wasm": "^2.6.2"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"svelte": "^4.0.0",
|
|
64
64
|
"unwasm": "^0.3.9",
|
|
65
|
-
"vite-plugin-wasm": "^3.3.0"
|
|
66
|
-
"@resvg/resvg-js": "^2.6.2",
|
|
67
|
-
"@resvg/resvg-wasm": "^2.6.2"
|
|
68
|
-
},
|
|
69
|
-
"peerDependenciesMeta": {
|
|
70
|
-
"@resvg/resvg-js": {
|
|
71
|
-
"optional": true
|
|
72
|
-
},
|
|
73
|
-
"@resvg/resvg-wasm": {
|
|
74
|
-
"optional": true
|
|
75
|
-
}
|
|
65
|
+
"vite-plugin-wasm": "^3.3.0"
|
|
76
66
|
}
|
|
77
67
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/runtime/detector.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
}
|
|
File without changes
|
|
File without changes
|