satori-cf 0.0.1
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/README.md +37 -0
- package/dist/assets/emoji.d.ts +15 -0
- package/dist/assets/emoji.d.ts.map +1 -0
- package/dist/assets/font.d.ts +10 -0
- package/dist/assets/font.d.ts.map +1 -0
- package/dist/core/yoga.d.ts +12 -0
- package/dist/core/yoga.d.ts.map +1 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/generators/batch.d.ts +26 -0
- package/dist/generators/batch.d.ts.map +1 -0
- package/dist/generators/single.d.ts +23 -0
- package/dist/generators/single.d.ts.map +1 -0
- package/dist/generators/stream.d.ts +21 -0
- package/dist/generators/stream.d.ts.map +1 -0
- package/dist/html/parser.d.ts +13 -0
- package/dist/html/parser.d.ts.map +1 -0
- package/dist/html/utils.d.ts +13 -0
- package/dist/html/utils.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +80 -0
- package/dist/types.d.ts +169 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/response.d.ts +18 -0
- package/dist/utils/response.d.ts.map +1 -0
- package/dist/yoga-ZMNYPE6Z.wasm +0 -0
- package/package.json +51 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { Font } from "satori";
|
|
2
|
+
/**
|
|
3
|
+
* Emoji provider types
|
|
4
|
+
*/
|
|
5
|
+
export type EmojiType = "twemoji" | "openmoji" | "blobmoji" | "noto" | "fluent" | "fluentFlat";
|
|
6
|
+
/**
|
|
7
|
+
* Options for generating OG images
|
|
8
|
+
*/
|
|
9
|
+
export interface OGOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The width of the image.
|
|
12
|
+
* @default 1200
|
|
13
|
+
*/
|
|
14
|
+
width?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The height of the image.
|
|
17
|
+
* @default 630
|
|
18
|
+
*/
|
|
19
|
+
height?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Array of fonts to use for rendering.
|
|
22
|
+
* If not provided, a default font will be loaded.
|
|
23
|
+
*/
|
|
24
|
+
fonts?: Font[];
|
|
25
|
+
/**
|
|
26
|
+
* Emoji provider to use for rendering emojis.
|
|
27
|
+
*/
|
|
28
|
+
emoji?: EmojiType;
|
|
29
|
+
/**
|
|
30
|
+
* Enable debug mode (disables caching).
|
|
31
|
+
*/
|
|
32
|
+
debug?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Success result type
|
|
36
|
+
*/
|
|
37
|
+
export interface OGSuccess<T> {
|
|
38
|
+
ok: true;
|
|
39
|
+
value: T;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Error result type
|
|
43
|
+
*/
|
|
44
|
+
export interface OGError {
|
|
45
|
+
ok: false;
|
|
46
|
+
error: Error;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Discriminated union for results
|
|
50
|
+
*/
|
|
51
|
+
export type OGResult<T> = OGSuccess<T> | OGError;
|
|
52
|
+
/**
|
|
53
|
+
* Item for batch processing
|
|
54
|
+
*/
|
|
55
|
+
export interface BatchItem {
|
|
56
|
+
/**
|
|
57
|
+
* The React element or HTML string to render
|
|
58
|
+
*/
|
|
59
|
+
element: React.ReactNode | string;
|
|
60
|
+
/**
|
|
61
|
+
* Optional per-item options (merged with batch defaults)
|
|
62
|
+
*/
|
|
63
|
+
options?: Partial<OGOptions>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Result for a single batch item
|
|
67
|
+
*/
|
|
68
|
+
export interface BatchResult {
|
|
69
|
+
/**
|
|
70
|
+
* Index of the item in the original batch
|
|
71
|
+
*/
|
|
72
|
+
index: number;
|
|
73
|
+
/**
|
|
74
|
+
* The result of the generation
|
|
75
|
+
*/
|
|
76
|
+
result: OGResult<string>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Options for batch processing
|
|
80
|
+
*/
|
|
81
|
+
export interface BatchOptions extends OGOptions {
|
|
82
|
+
/**
|
|
83
|
+
* Maximum number of concurrent generations.
|
|
84
|
+
* @default 5
|
|
85
|
+
*/
|
|
86
|
+
concurrency?: number;
|
|
87
|
+
/**
|
|
88
|
+
* Stop processing on first error.
|
|
89
|
+
* @default false
|
|
90
|
+
*/
|
|
91
|
+
failFast?: boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Item for stream processing
|
|
95
|
+
*/
|
|
96
|
+
export interface StreamItem {
|
|
97
|
+
/**
|
|
98
|
+
* The React element or HTML string to render
|
|
99
|
+
*/
|
|
100
|
+
element: React.ReactNode | string;
|
|
101
|
+
/**
|
|
102
|
+
* Optional per-item options
|
|
103
|
+
*/
|
|
104
|
+
options?: Partial<OGOptions>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Result yielded by the stream
|
|
108
|
+
*/
|
|
109
|
+
export interface StreamResult {
|
|
110
|
+
/**
|
|
111
|
+
* Index of the item
|
|
112
|
+
*/
|
|
113
|
+
index: number;
|
|
114
|
+
/**
|
|
115
|
+
* The result of the generation
|
|
116
|
+
*/
|
|
117
|
+
result: OGResult<string>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Options for stream processing
|
|
121
|
+
*/
|
|
122
|
+
export interface StreamOptions extends OGOptions {
|
|
123
|
+
/**
|
|
124
|
+
* Number of items to prefetch ahead.
|
|
125
|
+
* @default 3
|
|
126
|
+
*/
|
|
127
|
+
prefetch?: number;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Options for Google Font loading
|
|
131
|
+
*/
|
|
132
|
+
export interface GoogleFontOptions {
|
|
133
|
+
/**
|
|
134
|
+
* Font family name
|
|
135
|
+
*/
|
|
136
|
+
family: string;
|
|
137
|
+
/**
|
|
138
|
+
* Font weight
|
|
139
|
+
*/
|
|
140
|
+
weight?: number;
|
|
141
|
+
/**
|
|
142
|
+
* Specific text to subset the font for
|
|
143
|
+
*/
|
|
144
|
+
text?: string;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Options for creating SVG response
|
|
148
|
+
*/
|
|
149
|
+
export interface SVGResponseOptions {
|
|
150
|
+
/**
|
|
151
|
+
* Custom headers to add to the response
|
|
152
|
+
*/
|
|
153
|
+
headers?: HeadersInit;
|
|
154
|
+
/**
|
|
155
|
+
* HTTP status code
|
|
156
|
+
* @default 200
|
|
157
|
+
*/
|
|
158
|
+
status?: number;
|
|
159
|
+
/**
|
|
160
|
+
* HTTP status text
|
|
161
|
+
*/
|
|
162
|
+
statusText?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Disable caching (sets no-cache headers)
|
|
165
|
+
* @default false
|
|
166
|
+
*/
|
|
167
|
+
debug?: boolean;
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,SAAS,GACT,UAAU,GACV,UAAU,GACV,MAAM,GACN,QAAQ,GACR,YAAY,CAAC;AAEjB;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IAEf;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,C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MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;IAEtB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SVGResponseOptions } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Response object with appropriate headers for SVG content.
|
|
4
|
+
*
|
|
5
|
+
* @param svg - The SVG string to return
|
|
6
|
+
* @param options - Response options
|
|
7
|
+
* @returns A Response object with the SVG content
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const result = await generateOG(element);
|
|
12
|
+
* if (result.ok) {
|
|
13
|
+
* return createSVGResponse(result.value);
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSVGResponse(svg: string, options?: SVGResponseOptions): Response;
|
|
18
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/utils/response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,kBAAuB,GAC/B,QAAQ,CAcV"}
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "satori-cf",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "SVG-only, batch-optimized Open Graph image generation for Cloudflare Workers",
|
|
6
|
+
"author": "Pavle Dzuverovic",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/PavleDz/satori-cf"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"satori",
|
|
14
|
+
"cloudflare",
|
|
15
|
+
"workers",
|
|
16
|
+
"og",
|
|
17
|
+
"open-graph",
|
|
18
|
+
"svg",
|
|
19
|
+
"image-generation",
|
|
20
|
+
"social-cards"
|
|
21
|
+
],
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"require": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "node bin/build.js",
|
|
36
|
+
"ts": "tsc --noEmit"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"just-camel-case": "^6.2.0",
|
|
40
|
+
"satori": "^0.15.2",
|
|
41
|
+
"yoga-wasm-web": "0.3.3"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@cloudflare/workers-types": "^4.20250610.0",
|
|
45
|
+
"@types/node": "^20.19.0",
|
|
46
|
+
"@types/react": "^19.0.0",
|
|
47
|
+
"esbuild": "^0.19.12",
|
|
48
|
+
"esbuild-plugin-d.ts": "^1.3.1",
|
|
49
|
+
"typescript": "^5.8.3"
|
|
50
|
+
}
|
|
51
|
+
}
|