@pylonsync/react 0.3.316 → 0.3.318
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/image-response.d.ts +62 -0
- package/dist/index.d.ts +2 -0
- package/package.json +3 -3
- package/src/image-response.ts +76 -0
- package/src/index.ts +9 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/** A font for `ImageResponse`. Satori requires static TTF/OTF (not woff2,
|
|
3
|
+
* not variable fonts) — a variable font crashes the parser. */
|
|
4
|
+
export interface ImageResponseFont {
|
|
5
|
+
name: string;
|
|
6
|
+
data: ArrayBuffer | Buffer | Uint8Array;
|
|
7
|
+
weight?: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
8
|
+
style?: "normal" | "italic";
|
|
9
|
+
}
|
|
10
|
+
export interface ImageResponseOptions {
|
|
11
|
+
/** Output width in px. Default 1200 (the standard OG card width). */
|
|
12
|
+
width?: number;
|
|
13
|
+
/** Output height in px. Default 630 (1.91:1). */
|
|
14
|
+
height?: number;
|
|
15
|
+
/** Override/extra fonts. When omitted the framework's bundled Inter
|
|
16
|
+
* (weights 400 + 600) is used. */
|
|
17
|
+
fonts?: ImageResponseFont[];
|
|
18
|
+
/** Response content type. Only "image/png" is produced today. */
|
|
19
|
+
contentType?: string;
|
|
20
|
+
/** Extra headers merged onto the image response (e.g. a custom
|
|
21
|
+
* `Cache-Control`). The framework sets a sensible default otherwise. */
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
/** Satori emoji/asset loader passthrough (`graphemeImages` /
|
|
24
|
+
* `loadAdditionalAsset`) for rendering emoji or remote images. */
|
|
25
|
+
loadAdditionalAsset?: (code: string, text: string) => Promise<string> | string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A response that renders a React element to an image (PNG), for the
|
|
29
|
+
* `opengraph-image.tsx` / `twitter-image.tsx` file convention — the Pylon
|
|
30
|
+
* equivalent of Next.js's `next/og` `ImageResponse`.
|
|
31
|
+
*
|
|
32
|
+
* Return one from an `opengraph-image` module's default export:
|
|
33
|
+
*
|
|
34
|
+
* ```tsx
|
|
35
|
+
* import { ImageResponse } from "@pylonsync/react";
|
|
36
|
+
* export const size = { width: 1200, height: 630 };
|
|
37
|
+
* export default function OG() {
|
|
38
|
+
* return new ImageResponse(
|
|
39
|
+
* <div style={{ width: "100%", height: "100%", display: "flex" }}>
|
|
40
|
+
* Hello
|
|
41
|
+
* </div>,
|
|
42
|
+
* { ...size },
|
|
43
|
+
* );
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* This is a thin holder: it captures the element + options and the SSR
|
|
48
|
+
* runtime does the Satori→resvg render server-side (so this package pulls
|
|
49
|
+
* in no image-rendering deps). Satori is flexbox-only — an element with
|
|
50
|
+
* more than one child must set `display: flex` (same rule as next/og).
|
|
51
|
+
*/
|
|
52
|
+
export declare class ImageResponse {
|
|
53
|
+
/** Brand for structural detection in the runtime (survives bundling and
|
|
54
|
+
* cross-realm boundaries where `instanceof` would not). */
|
|
55
|
+
readonly __pylonImageResponse: true;
|
|
56
|
+
readonly element: ReactNode;
|
|
57
|
+
readonly options: ImageResponseOptions;
|
|
58
|
+
constructor(element: ReactNode, options?: ImageResponseOptions);
|
|
59
|
+
}
|
|
60
|
+
/** Structural check the runtime uses instead of `instanceof` (the user's
|
|
61
|
+
* module and the runtime may load different copies of this class). */
|
|
62
|
+
export declare function isImageResponse(v: unknown): v is ImageResponse;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export { Image } from "./Image";
|
|
|
6
6
|
export type { ImageProps } from "./Image";
|
|
7
7
|
export { Form } from "./Form";
|
|
8
8
|
export type { FormProps } from "./Form";
|
|
9
|
+
export { ImageResponse, isImageResponse } from "./image-response";
|
|
10
|
+
export type { ImageResponseOptions, ImageResponseFont, } from "./image-response";
|
|
9
11
|
export type { PageProps, PageAuth, ServerData, SsrResponse, SsrCookieOptions, Metadata, GenerateMetadata, Sitemap, SitemapEntry, Robots, RobotsRule, RouteSegmentConfig, ErrorBoundaryProps, NotFoundProps, FormFields, FormDb, FormRequest, RouteHandler, RawRouteHandler, RawResponse, } from "./ssr";
|
|
10
12
|
export { useRouter, useSearchParams, usePathname, useParams, useRouteSeed, useRouteData, redirect, notFound, NotFoundError, } from "./useRouter";
|
|
11
13
|
export type { PylonRouter } from "./useRouter";
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.3.
|
|
6
|
+
"version": "0.3.318",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.ts",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"prepack": "bun run build"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@pylonsync/sdk": "0.3.
|
|
17
|
-
"@pylonsync/sync": "0.3.
|
|
16
|
+
"@pylonsync/sdk": "0.3.318",
|
|
17
|
+
"@pylonsync/sync": "0.3.318"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"react": ">=19.0.0"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
/** A font for `ImageResponse`. Satori requires static TTF/OTF (not woff2,
|
|
4
|
+
* not variable fonts) — a variable font crashes the parser. */
|
|
5
|
+
export interface ImageResponseFont {
|
|
6
|
+
name: string;
|
|
7
|
+
data: ArrayBuffer | Buffer | Uint8Array;
|
|
8
|
+
weight?: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
9
|
+
style?: "normal" | "italic";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ImageResponseOptions {
|
|
13
|
+
/** Output width in px. Default 1200 (the standard OG card width). */
|
|
14
|
+
width?: number;
|
|
15
|
+
/** Output height in px. Default 630 (1.91:1). */
|
|
16
|
+
height?: number;
|
|
17
|
+
/** Override/extra fonts. When omitted the framework's bundled Inter
|
|
18
|
+
* (weights 400 + 600) is used. */
|
|
19
|
+
fonts?: ImageResponseFont[];
|
|
20
|
+
/** Response content type. Only "image/png" is produced today. */
|
|
21
|
+
contentType?: string;
|
|
22
|
+
/** Extra headers merged onto the image response (e.g. a custom
|
|
23
|
+
* `Cache-Control`). The framework sets a sensible default otherwise. */
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
/** Satori emoji/asset loader passthrough (`graphemeImages` /
|
|
26
|
+
* `loadAdditionalAsset`) for rendering emoji or remote images. */
|
|
27
|
+
loadAdditionalAsset?: (code: string, text: string) => Promise<string> | string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A response that renders a React element to an image (PNG), for the
|
|
32
|
+
* `opengraph-image.tsx` / `twitter-image.tsx` file convention — the Pylon
|
|
33
|
+
* equivalent of Next.js's `next/og` `ImageResponse`.
|
|
34
|
+
*
|
|
35
|
+
* Return one from an `opengraph-image` module's default export:
|
|
36
|
+
*
|
|
37
|
+
* ```tsx
|
|
38
|
+
* import { ImageResponse } from "@pylonsync/react";
|
|
39
|
+
* export const size = { width: 1200, height: 630 };
|
|
40
|
+
* export default function OG() {
|
|
41
|
+
* return new ImageResponse(
|
|
42
|
+
* <div style={{ width: "100%", height: "100%", display: "flex" }}>
|
|
43
|
+
* Hello
|
|
44
|
+
* </div>,
|
|
45
|
+
* { ...size },
|
|
46
|
+
* );
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* This is a thin holder: it captures the element + options and the SSR
|
|
51
|
+
* runtime does the Satori→resvg render server-side (so this package pulls
|
|
52
|
+
* in no image-rendering deps). Satori is flexbox-only — an element with
|
|
53
|
+
* more than one child must set `display: flex` (same rule as next/og).
|
|
54
|
+
*/
|
|
55
|
+
export class ImageResponse {
|
|
56
|
+
/** Brand for structural detection in the runtime (survives bundling and
|
|
57
|
+
* cross-realm boundaries where `instanceof` would not). */
|
|
58
|
+
readonly __pylonImageResponse = true as const;
|
|
59
|
+
readonly element: ReactNode;
|
|
60
|
+
readonly options: ImageResponseOptions;
|
|
61
|
+
|
|
62
|
+
constructor(element: ReactNode, options: ImageResponseOptions = {}) {
|
|
63
|
+
this.element = element;
|
|
64
|
+
this.options = options;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Structural check the runtime uses instead of `instanceof` (the user's
|
|
69
|
+
* module and the runtime may load different copies of this class). */
|
|
70
|
+
export function isImageResponse(v: unknown): v is ImageResponse {
|
|
71
|
+
return (
|
|
72
|
+
typeof v === "object" &&
|
|
73
|
+
v !== null &&
|
|
74
|
+
(v as { __pylonImageResponse?: unknown }).__pylonImageResponse === true
|
|
75
|
+
);
|
|
76
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,15 @@ export type { ImageProps } from "./Image";
|
|
|
10
10
|
export { Form } from "./Form";
|
|
11
11
|
export type { FormProps } from "./Form";
|
|
12
12
|
|
|
13
|
+
// Dynamic image generation for the `opengraph-image.tsx` / `twitter-image.tsx`
|
|
14
|
+
// file convention (Next.js `next/og` parity). `ImageResponse` is a thin
|
|
15
|
+
// holder — the SSR runtime does the Satori→resvg render server-side.
|
|
16
|
+
export { ImageResponse, isImageResponse } from "./image-response";
|
|
17
|
+
export type {
|
|
18
|
+
ImageResponseOptions,
|
|
19
|
+
ImageResponseFont,
|
|
20
|
+
} from "./image-response";
|
|
21
|
+
|
|
13
22
|
// SSR page-author types — the contract every `app/**/page.tsx` is handed
|
|
14
23
|
// in props, plus `metadata` / `generateMetadata`. Type-only.
|
|
15
24
|
export type {
|