html-satori based

This commit is contained in:
Shivam Meena
2023-10-05 07:35:26 +05:30
parent f3fc389e91
commit 501efa9413
58 changed files with 1099 additions and 7864 deletions

78
src/lib/api.ts Normal file
View File

@@ -0,0 +1,78 @@
import { html } from "satori-html";
import {ImageResponse as IR} from "@vercel/og"
import type {SvelteComponent} from "svelte";
export const ImageResponse = async (htmlTemplate: string, options?: ImageResponseOptions) => {
const reactVNode = html(`${htmlTemplate}`);
console.log(reactVNode)
return new IR(reactVNode, options)
};
export const componentToImageResponse = async (component: SvelteComponent, props: Record<string, any>, options?: ImageResponseOptions) => {
const ssrSvelte = component.render(props);
console.log(ssrSvelte);
return ImageResponse(`${ssrSvelte.html}<style>${ssrSvelte.css.code}</style>`, options)
};
declare const apis: {
twemoji: (code: any) => string;
openmoji: string;
blobmoji: string;
noto: string;
fluent: (code: any) => string;
fluentFlat: (code: any) => string;
};
declare type EmojiType = keyof typeof apis;
type Weight = 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
type Style$1 = 'normal' | 'italic';
interface FontOptions {
data: Buffer | ArrayBuffer;
name: string;
weight?: Weight;
style?: Style$1;
lang?: string;
}
export declare type ImageResponseOptions = ImageOptions & ConstructorParameters<typeof Response>[1];
declare type ImageOptions = {
/**
* The width of the image.
*
* @type {number}
* @default 1200
*/
width?: number;
/**
* The height of the image.
*
* @type {number}
* @default 630
*/
height?: number;
/**
* Display debug information on the image.
*
* @type {boolean}
* @default false
*/
debug?: boolean;
/**
* A list of fonts to use.
*
* @type {{ data: ArrayBuffer; name: string; weight?: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900; style?: 'normal' | 'italic' }[]}
* @default Noto Sans Latin Regular.
*/
fonts?: FontOptions[];
/**
* Using a specific Emoji style. Defaults to `twemoji`.
*
* @link https://github.com/vercel/og#emoji
* @type {EmojiType}
* @default 'twemoji'
*/
emoji?: EmojiType;
};