@ethercorps/sveltekit-og 4.2.1 → 4.3.0-next.10

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.
Files changed (47) hide show
  1. package/README.md +27 -193
  2. package/dist/fonts.d.ts +5 -13
  3. package/dist/fonts.js +26 -24
  4. package/dist/helpers/create.d.ts +2 -2
  5. package/dist/helpers/create.js +29 -27
  6. package/dist/helpers/defaults.d.ts +4 -4
  7. package/dist/helpers/defaults.js +18 -17
  8. package/dist/helpers/emoji.js +30 -15
  9. package/dist/helpers/error-handler.d.ts +37 -0
  10. package/dist/helpers/error-handler.js +75 -0
  11. package/dist/helpers/logger.d.ts +7 -0
  12. package/dist/helpers/logger.js +21 -0
  13. package/dist/helpers/response.d.ts +20 -0
  14. package/dist/helpers/response.js +39 -0
  15. package/dist/helpers/to-html.d.ts +10 -0
  16. package/dist/helpers/to-html.js +10 -0
  17. package/dist/helpers/toJSX.d.ts +2 -2
  18. package/dist/helpers/toJSX.js +10 -5
  19. package/dist/helpers/utils.d.ts +2 -0
  20. package/dist/helpers/utils.js +25 -0
  21. package/dist/image-response.d.ts +2 -2
  22. package/dist/image-response.js +14 -21
  23. package/dist/plugin.js +6 -6
  24. package/dist/providers/instances.d.ts +3 -3
  25. package/dist/providers/instances.js +37 -10
  26. package/dist/providers/resvg/edge.d.ts +1 -1
  27. package/dist/providers/resvg/edge.js +10 -6
  28. package/dist/providers/resvg/node.d.ts +1 -1
  29. package/dist/providers/resvg/node.js +18 -9
  30. package/dist/providers/satori/edge.d.ts +6 -0
  31. package/dist/providers/satori/edge.js +12 -0
  32. package/dist/providers/satori/node.d.ts +1 -1
  33. package/dist/providers/satori/node.js +4 -4
  34. package/dist/takumi/fonts.d.ts +16 -0
  35. package/dist/takumi/fonts.js +15 -0
  36. package/dist/takumi/image-response.d.ts +6 -0
  37. package/dist/takumi/image-response.js +33 -0
  38. package/dist/takumi/index.d.ts +5 -0
  39. package/dist/takumi/index.js +4 -0
  40. package/dist/takumi/render.d.ts +4 -0
  41. package/dist/takumi/render.js +30 -0
  42. package/dist/takumi/renderer.d.ts +6 -0
  43. package/dist/takumi/renderer.js +35 -0
  44. package/dist/takumi/types.d.ts +64 -0
  45. package/dist/takumi/types.js +1 -0
  46. package/dist/types.d.ts +10 -10
  47. package/package.json +130 -81
@@ -0,0 +1,6 @@
1
+ import type { Renderer as NodeRenderer, FontDetails } from "takumi-js/node";
2
+ export type TakumiRenderer = NodeRenderer;
3
+ /** Lazily creates and caches the Takumi renderer for the current runtime. */
4
+ export declare function useTakumiRenderer(_debug?: boolean): Promise<TakumiRenderer>;
5
+ /** Register each font once, keyed by name/weight/style. */
6
+ export declare function registerTakumiFonts(renderer: TakumiRenderer, fonts: FontDetails[]): Promise<void>;
@@ -0,0 +1,35 @@
1
+ import autoModule, { init as initTakumiWasm, Renderer } from "takumi-js/wasm";
2
+ import { handleAsync, ErrorCodes } from "../helpers/error-handler.js";
3
+ // keep one renderer alive across requests, same as the satori/resvg instances.
4
+ // fonts registered on it stick around, so we dedupe by key.
5
+ let rendererPromise;
6
+ const registeredFontKeys = new Set();
7
+ async function initRenderer() {
8
+ await handleAsync(async () => {
9
+ // reuse the wasm that ships with takumi-js instead of vendoring our own.
10
+ // @takumi-rs/wasm/auto picks the right binary per runtime (workerd, edge,
11
+ // node, ?module) via export conditions. this is the same dance takumi-js
12
+ // does internally.
13
+ const resolved = typeof autoModule === "function" ? await autoModule() : await autoModule;
14
+ const input = resolved && typeof resolved === "object" && "default" in resolved
15
+ ? resolved.default
16
+ : resolved;
17
+ await initTakumiWasm(input ? { module_or_path: input } : undefined);
18
+ }, ErrorCodes.TAKUMI_INIT_FAILED, "Failed to initialize Takumi WASM");
19
+ return new Renderer();
20
+ }
21
+ /** Lazily creates and caches the Takumi renderer for the current runtime. */
22
+ export async function useTakumiRenderer(_debug = false) {
23
+ rendererPromise ??= initRenderer();
24
+ return rendererPromise;
25
+ }
26
+ /** Register each font once, keyed by name/weight/style. */
27
+ export async function registerTakumiFonts(renderer, fonts) {
28
+ for (const font of fonts) {
29
+ const key = `${font.name ?? "unnamed"}-${font.weight ?? "auto"}-${font.style ?? "normal"}`;
30
+ if (registeredFontKeys.has(key))
31
+ continue;
32
+ await handleAsync(() => renderer.registerFont(font), ErrorCodes.FONT_LOAD_FAILED, `Failed to register Takumi font: ${key}`);
33
+ registeredFontKeys.add(key);
34
+ }
35
+ }
@@ -0,0 +1,64 @@
1
+ import type { EmojiType } from "takumi-js/helpers/emoji";
2
+ import type { OutputFormat } from "takumi-js/node";
3
+ import type { TakumiFontInput } from "./fonts.js";
4
+ /** Static output formats Takumi can encode, plus vector `svg`. */
5
+ export type TakumiFormat = OutputFormat | "svg";
6
+ export type TakumiImageOptions = {
7
+ /**
8
+ * Width of the image.
9
+ * @default 1200
10
+ * */
11
+ width?: number;
12
+ /**
13
+ * Height of the image.
14
+ * @default 630
15
+ * */
16
+ height?: number;
17
+ /**
18
+ * Output format.
19
+ * @default png
20
+ * */
21
+ format?: TakumiFormat;
22
+ /**
23
+ * Quality for lossy formats (jpeg, lossy webp), 0-100.
24
+ * */
25
+ quality?: number;
26
+ /**
27
+ * Fonts to register. Accepts this library's `GoogleFont`/`CustomFont`
28
+ * helpers or raw Takumi font descriptors. If omitted, Takumi's built-in
29
+ * sans-serif is used.
30
+ * */
31
+ fonts?: TakumiFontInput[];
32
+ /**
33
+ * Extra CSS stylesheets applied before rendering.
34
+ * */
35
+ stylesheets?: string[];
36
+ /**
37
+ * Emoji provider, or `"from-font"` to source emoji glyphs from loaded fonts.
38
+ * @default twemoji
39
+ * */
40
+ emoji?: EmojiType | "from-font";
41
+ /**
42
+ * Enable debug logging.
43
+ * @default false
44
+ * */
45
+ debug?: boolean;
46
+ };
47
+ export type TakumiResponseOptions = {
48
+ /**
49
+ * Response status code.
50
+ * @default 200
51
+ * */
52
+ status?: number;
53
+ /**
54
+ * Response status text.
55
+ * @default Success
56
+ * */
57
+ statusText?: string;
58
+ /**
59
+ * Response headers.
60
+ * */
61
+ headers?: Record<string, string>;
62
+ };
63
+ /** Options for the Takumi `ImageResponse`. */
64
+ export type TakumiImageResponseOptions = TakumiImageOptions & TakumiResponseOptions;
@@ -0,0 +1 @@
1
+ export {};
package/dist/types.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { SatoriOptions } from 'satori/wasm';
2
- import type { EmojiType } from './helpers/emoji.js';
3
- export type Font = SatoriOptions['fonts'][number];
1
+ import type { SatoriOptions } from "satori";
2
+ import type { EmojiType } from "./helpers/emoji.js";
3
+ export type Font = SatoriOptions["fonts"][number];
4
4
  export type Fonts = Font[];
5
- export type FontStyle = Font['style'];
6
- export type FontWeight = Font['weight'];
5
+ export type FontStyle = Font["style"];
6
+ export type FontWeight = Font["weight"];
7
7
  export type FinalFontOptions = NonNullable<Fonts>;
8
8
  export type ImageOptions = {
9
9
  /**
@@ -30,7 +30,7 @@ export type ImageOptions = {
30
30
  * Tailwind config
31
31
  * @default provided by satori
32
32
  * */
33
- tailwindConfig?: SatoriOptions['tailwindConfig'];
33
+ tailwindConfig?: SatoriOptions["tailwindConfig"];
34
34
  /**
35
35
  * Debug operations
36
36
  * @default false
@@ -40,7 +40,7 @@ export type ImageOptions = {
40
40
  * Image format
41
41
  * @default png
42
42
  * */
43
- format?: 'svg' | 'png';
43
+ format?: "svg" | "png";
44
44
  };
45
45
  export type ResponseImageOptions = {
46
46
  /**
@@ -70,7 +70,7 @@ export type ImageResponseOptions = ImageOptions & ResponseImageOptions;
70
70
  * Svelte Component props to render the component which dynamic content
71
71
  * */
72
72
  export type ComponentOptions = {
73
- props?: Record<string, any>;
73
+ props?: Record<string, unknown>;
74
74
  };
75
75
  /**
76
76
  * React virtual node, supported by satori as input (alternative to JSX input).
@@ -78,9 +78,9 @@ export type ComponentOptions = {
78
78
  export interface VNode {
79
79
  type: string;
80
80
  props: {
81
- style?: Record<string, any>;
81
+ style?: Record<string, unknown>;
82
82
  children?: string | VNode | VNode[];
83
- [prop: string]: any;
83
+ [prop: string]: unknown;
84
84
  };
85
85
  }
86
86
  /** utils types */
package/package.json CHANGED
@@ -1,82 +1,131 @@
1
1
  {
2
- "name": "@ethercorps/sveltekit-og",
3
- "version": "4.2.1",
4
- "license": "MIT",
5
- "homepage": "https://sveltekit-og.dev",
6
- "repository": "github:ethercorps/sveltekit-og",
7
- "funding": "https://github.com/sponsors/ethercorps",
8
- "author": "Shivam Meena <https://github.com/theetherGit>",
9
- "description": "Dynamically generate Open Graph images from an HTML, CSS template or Svelte component using fast and efficient conversion from HTML > SVG > PNG",
10
- "exports": {
11
- ".": {
12
- "types": "./dist/index.d.ts",
13
- "svelte": "./dist/index.js",
14
- "import": "./dist/index.js"
15
- },
16
- "./fonts": {
17
- "types": "./dist/fonts.d.ts",
18
- "import": "./dist/fonts.js"
19
- },
20
- "./plugin": {
21
- "types": "./dist/plugin.d.ts",
22
- "import": "./dist/plugin.js"
23
- }
24
- },
25
- "files": [
26
- "dist",
27
- "!dist/**/*.test.*",
28
- "!dist/**/*.spec.*"
29
- ],
30
- "devDependencies": {
31
- "@sveltejs/adapter-vercel": "^5.10.2",
32
- "@sveltejs/kit": "^2.48.5",
33
- "@sveltejs/package": "^2.5.4",
34
- "@sveltejs/vite-plugin-svelte": "^4.0.4",
35
- "@types/node": "^24.7.1",
36
- "@typescript-eslint/eslint-plugin": "^5.62.0",
37
- "@typescript-eslint/parser": "^5.62.0",
38
- "css-tree": "^2.3.1",
39
- "eslint": "^8.57.1",
40
- "eslint-config-prettier": "^8.10.0",
41
- "eslint-plugin-svelte": "^2.46.1",
42
- "prettier": "^3.6.2",
43
- "prettier-plugin-svelte": "^3.4.0",
44
- "publint": "^0.1.16",
45
- "rollup-plugin-visualizer": "^5.14.0",
46
- "svelte": "^5.43.12",
47
- "svelte-check": "^4.3.2",
48
- "tslib": "^2.8.1",
49
- "typescript": "^5.9.3",
50
- "vite": "^5.4.19",
51
- "vitest": "^1.6.1"
52
- },
53
- "main": "./dist/index.js",
54
- "svelte": "./dist/index.js",
55
- "types": "./dist/index.d.ts",
56
- "type": "module",
57
- "dependencies": {
58
- "@resvg/resvg-wasm": "^2.6.2",
59
- "@takumi-rs/helpers": "^0.55.0",
60
- "@takumi-rs/image-response": "^0.55.0",
61
- "@takumi-rs/wasm": "^0.55.0",
62
- "satori": "^0.10.14",
63
- "satori-html": "0.3.2",
64
- "std-env": "^3.9.0",
65
- "unwasm": "^0.5.0"
66
- },
67
- "peerDependencies": {
68
- "@sveltejs/kit": ">=2.0.0"
69
- },
70
- "scripts": {
71
- "dev": "vite dev",
72
- "build": "vite build && npm run package",
73
- "preview": "vite preview",
74
- "package": "svelte-kit sync && svelte-package && publint",
75
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
76
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
77
- "test": "vitest",
78
- "lint": "prettier --plugin-search-dir . --check . && eslint .",
79
- "format": "prettier --plugin-search-dir . --write .",
80
- "publishBeta": "npm publish --tag beta"
81
- }
82
- }
2
+ "name": "@ethercorps/sveltekit-og",
3
+ "version": "4.3.0-next.10",
4
+ "license": "MIT",
5
+ "homepage": "https://sveltekit-og.dev",
6
+ "repository": "github:ethercorps/sveltekit-og",
7
+ "funding": "https://github.com/sponsors/ethercorps",
8
+ "author": "Shivam Meena <https://github.com/theetherGit>",
9
+ "description": "Dynamically generate Open Graph images from an HTML, CSS template or Svelte component using fast and efficient conversion from HTML > SVG > PNG",
10
+ "contributors": [
11
+ {
12
+ "name": "Shivam Meena",
13
+ "github": "https://github.com/theetherGit"
14
+ },
15
+ {
16
+ "name": "Jason",
17
+ "github": "https://github.com/jasongitmail"
18
+ },
19
+ {
20
+ "name": "Mihkel Martin Kasterpalu",
21
+ "github": "https://github.com/MihkelMK"
22
+ },
23
+ {
24
+ "name": "Luke Parke",
25
+ "github": "https://github.com/LukasParke"
26
+ },
27
+ {
28
+ "name": "Willow (GHOST)",
29
+ "github": "https://github.com/ghostdevv"
30
+ },
31
+ {
32
+ "name": "Minseo Lee",
33
+ "github": "https://github.com/quiple"
34
+ }
35
+ ],
36
+ "scripts": {
37
+ "dev": "vite dev",
38
+ "build": "vite build && npm run package",
39
+ "build:examples": "pnpm -F \"./examples/**\" --parallel --color build",
40
+ "check:examples": "pnpm install -r",
41
+ "preview": "vite preview",
42
+ "package": "svelte-kit sync && svelte-package && publint",
43
+ "prepublishOnly": "pnpm run package",
44
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
45
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
46
+ "test": "vitest",
47
+ "bench": "vitest bench --run",
48
+ "bench:save": "vitest bench --run --outputJson benchmarks/baseline.json",
49
+ "bench:compare": "vitest bench --run --compare benchmarks/baseline.json",
50
+ "bench:snapshot": "node scripts/bench-snapshot.mjs",
51
+ "lint": "oxlint . && eslint .",
52
+ "format": "prettier --plugin-search-dir . --write .",
53
+ "publishBeta": "npm publish --tag beta"
54
+ },
55
+ "exports": {
56
+ ".": {
57
+ "types": "./dist/index.d.ts",
58
+ "svelte": "./dist/index.js",
59
+ "import": "./dist/index.js"
60
+ },
61
+ "./fonts": {
62
+ "types": "./dist/fonts.d.ts",
63
+ "import": "./dist/fonts.js"
64
+ },
65
+ "./takumi": {
66
+ "types": "./dist/takumi/index.d.ts",
67
+ "svelte": "./dist/takumi/index.js",
68
+ "import": "./dist/takumi/index.js"
69
+ },
70
+ "./plugin": {
71
+ "types": "./dist/plugin.d.ts",
72
+ "import": "./dist/plugin.js"
73
+ }
74
+ },
75
+ "files": [
76
+ "dist",
77
+ "!dist/**/*.test.*",
78
+ "!dist/**/*.spec.*"
79
+ ],
80
+ "devDependencies": {
81
+ "@eslint/compat": "^2.0.3",
82
+ "@eslint/js": "^9.39.3",
83
+ "@sveltejs/adapter-vercel": "^5.10.3",
84
+ "@sveltejs/kit": "^2.53.4",
85
+ "@sveltejs/package": "^2.5.7",
86
+ "@sveltejs/vite-plugin-svelte": "^4.0.4",
87
+ "@types/node": "^24.11.0",
88
+ "@typescript-eslint/eslint-plugin": "^5.62.0",
89
+ "@typescript-eslint/parser": "^5.62.0",
90
+ "css-tree": "^2.3.1",
91
+ "eslint": "^8.57.1",
92
+ "eslint-config-prettier": "^8.10.2",
93
+ "eslint-plugin-oxlint": "^1.55.0",
94
+ "eslint-plugin-svelte": "^2.46.1",
95
+ "globals": "^16.5.0",
96
+ "oxlint": "^1.55.0",
97
+ "prettier": "^3.8.1",
98
+ "prettier-plugin-svelte": "^3.5.1",
99
+ "prettier-plugin-tailwindcss": "^0.6.14",
100
+ "publint": "^0.1.16",
101
+ "rollup-plugin-visualizer": "^5.14.0",
102
+ "svelte": "^5.53.10",
103
+ "svelte-check": "^4.4.5",
104
+ "tslib": "^2.8.1",
105
+ "typescript": "^5.9.3",
106
+ "typescript-eslint": "^8.57.0",
107
+ "vite": "^5.4.21",
108
+ "takumi-js": "2.0.0-beta.14",
109
+ "vitest": "^1.6.1"
110
+ },
111
+ "main": "./dist/index.js",
112
+ "svelte": "./dist/index.js",
113
+ "types": "./dist/index.d.ts",
114
+ "type": "module",
115
+ "dependencies": {
116
+ "@resvg/resvg-wasm": "^2.6.2",
117
+ "satori": "^0.25.0",
118
+ "satori-html": "0.3.2",
119
+ "std-env": "^4.1.0",
120
+ "unwasm": "^0.5.3"
121
+ },
122
+ "peerDependencies": {
123
+ "@sveltejs/kit": ">=2.0.0",
124
+ "takumi-js": "^2.0.0-beta.14"
125
+ },
126
+ "peerDependenciesMeta": {
127
+ "takumi-js": {
128
+ "optional": true
129
+ }
130
+ }
131
+ }