@junejs/og 0.0.3 → 0.0.4
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/package.json +1 -1
- package/src/node.ts +9 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junejs/og",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "June — cross-platform OG image generation. Cloudflare Workers, Vercel Edge, and Node.js dev all share one import; the right backend is selected at build time via export conditions.",
|
|
6
6
|
"exports": {
|
package/src/node.ts
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// Uses satori (JSX → SVG) + @resvg/resvg-js (SVG → PNG, native binding).
|
|
3
3
|
// Native bindings are fine for Vercel Node.js functions too; only Edge functions need WASM.
|
|
4
4
|
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
5
|
+
// Modules are loaded via `new Function("return import(m)")` so TypeScript does not
|
|
6
|
+
// attempt to resolve them at compile time — satori and @resvg/resvg-js are optional
|
|
7
|
+
// devDependencies of @junejs/og and are never installed by downstream consumers.
|
|
7
8
|
import type { ReactElement } from "react";
|
|
8
9
|
export { loadGoogleFont, loadDefaultFonts, hasCJK, OG_HEADERS } from "./fonts";
|
|
9
10
|
export type { OgFont } from "./fonts";
|
|
@@ -12,6 +13,9 @@ export type { ImageResponseOptions } from "./types";
|
|
|
12
13
|
type Satori = (element: unknown, opts: unknown) => Promise<string>;
|
|
13
14
|
type ResvgClass = new (svg: string) => { render(): { asPng(): Uint8Array } };
|
|
14
15
|
|
|
16
|
+
// TypeScript cannot see through Function() — no static module resolution is attempted.
|
|
17
|
+
const _import = new Function("m", "return import(m)") as (m: string) => Promise<unknown>;
|
|
18
|
+
|
|
15
19
|
export class ImageResponse extends Response {
|
|
16
20
|
constructor(element: ReactElement, options: import("./types").ImageResponseOptions = {}) {
|
|
17
21
|
const { readable, writable } = new TransformStream<Uint8Array, Uint8Array>();
|
|
@@ -25,15 +29,15 @@ export class ImageResponse extends Response {
|
|
|
25
29
|
});
|
|
26
30
|
const writer = writable.getWriter();
|
|
27
31
|
Promise.all([
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
_import("satori") as Promise<{ default: Satori }>,
|
|
33
|
+
_import("@resvg/resvg-js") as Promise<{ Resvg: ResvgClass }>,
|
|
30
34
|
])
|
|
31
35
|
.then(([{ default: satori }, { Resvg }]) =>
|
|
32
36
|
satori(element, {
|
|
33
37
|
width: options.width ?? 1200,
|
|
34
38
|
height: options.height ?? 630,
|
|
35
39
|
fonts: options.fonts ?? [],
|
|
36
|
-
}).then((svg) => {
|
|
40
|
+
}).then((svg: string) => {
|
|
37
41
|
const png = new Resvg(svg).render().asPng();
|
|
38
42
|
writer.write(new Uint8Array(png));
|
|
39
43
|
writer.close();
|