@ethercorps/sveltekit-og 4.2.0 → 4.3.1-next.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Ethercorps
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,9 +1,13 @@
1
+ [![npm version](https://flat.badgen.net/npm/v/@ethercorps/sveltekit-og?color=orange)](https://npmjs.com/package/bits-ui)
2
+ [![npm downloads](https://flat.badgen.net/npm/dm/@ethercorps/sveltekit-og?color=orange)](https://npmjs.com/package/@ethercorps/sveltekit-og)
3
+ [![license](https://flat.badgen.net/github/license/ethercorps/sveltekit-og?color=orange)](https://github.com/ethercorps/sveltekit-og/blob/main/LICENSE)
4
+
1
5
  # SvelteKit Open Graph Image Generation
2
6
 
3
7
  Dynamically generate Open Graph images from an HTML+CSS template or Svelte component using fast and efficient conversion from HTML > SVG > PNG. Based on [Satori](https://github.com/vercel/satori#documentation). No headless browser required.
4
8
 
5
9
  ## Docs
6
- - With sveltekit-og@4, we have [official documentation](https://sveltekit-og.dev).
10
+ - With `sveltekit-og@4`, we have [official documentation](https://sveltekit-og.dev).
7
11
 
8
12
  ## Installation
9
13
 
@@ -114,7 +118,7 @@ Then run `npm dev` and visit `localhost:5173/og` to view your generated PNG. Rem
114
118
 
115
119
  ## Example Output
116
120
 
117
- ![Rendered OG image](https://vercel.sveltekit-og.dev)
121
+ ![Rendered OG image](https://github.com/etherCorps/sveltekit-og/blob/main/static/og.png)
118
122
 
119
123
  ## Headers
120
124
 
package/dist/fonts.d.ts CHANGED
@@ -17,18 +17,10 @@ export declare class BaseFont {
17
17
  */
18
18
  get data(): MayBePromise<Buffer | ArrayBuffer>;
19
19
  }
20
- /** * A helper class to load Custom fonts, typically from local files.
21
- * The input must be a function provided by the user (e.g., using $app/server/read).
22
- */
23
20
  export declare class CustomFont extends BaseFont {
24
21
  private promise?;
25
- /**
26
- * Creates an instance of CustomFont.
27
- * @param name The name of the font (for CSS font-family).
28
- * @param input Font data as ArrayBuffer or a function that resolves to ArrayBuffer (user must provide the loading logic).
29
- */
30
22
  constructor(name: string, input: MayBePromise<Buffer | ArrayBuffer> | (() => MayBePromise<Buffer | ArrayBuffer>), options?: BaseFontOptions);
31
- /** A promise which resolves to font data as `ArrayBuffer` (Lazy load) */
23
+ /** A promise which resolves to font data as `ArrayBuffer` (Lazy load and CACHED) */
32
24
  get data(): Promise<Buffer | ArrayBuffer>;
33
25
  }
34
26
  /** Loads Google font ArrayBuffer with caching. */
package/dist/fonts.js CHANGED
@@ -20,24 +20,24 @@ export class BaseFont {
20
20
  return this.input;
21
21
  }
22
22
  }
23
- /** * A helper class to load Custom fonts, typically from local files.
24
- * The input must be a function provided by the user (e.g., using $app/server/read).
25
- */
26
23
  export class CustomFont extends BaseFont {
27
24
  promise;
28
- /**
29
- * Creates an instance of CustomFont.
30
- * @param name The name of the font (for CSS font-family).
31
- * @param input Font data as ArrayBuffer or a function that resolves to ArrayBuffer (user must provide the loading logic).
32
- */
33
25
  constructor(name, input, options) {
34
26
  super(name, input, options);
35
27
  }
36
- /** A promise which resolves to font data as `ArrayBuffer` (Lazy load) */
28
+ /** A promise which resolves to font data as `ArrayBuffer` (Lazy load and CACHED) */
37
29
  get data() {
38
- // Defines the loading mechanism: execute the input function or resolve the promise/buffer.
39
- const fallback = async () => (typeof this.input === 'function' ? this.input() : this.input);
40
- // Memoization: ensures the input function is executed only once.
30
+ const cacheKey = `${this.name}-${this.weight}-${this.style}`;
31
+ const cachedData = FONT_CACHE_MAP.get(cacheKey);
32
+ if (cachedData) {
33
+ return Promise.resolve(cachedData);
34
+ }
35
+ const fallback = async () => {
36
+ const buffer = typeof this.input === 'function' ? this.input() : this.input;
37
+ const resolvedBuffer = await buffer;
38
+ FONT_CACHE_MAP.set(cacheKey, resolvedBuffer);
39
+ return resolvedBuffer;
40
+ };
41
41
  this.promise = this.promise?.then(null, fallback) ?? fallback();
42
42
  return this.promise;
43
43
  }
@@ -1,5 +1,4 @@
1
1
  import type { Component } from 'svelte';
2
- import type { ComponentOptions, ImageOptions, VNode } from '../types.js';
3
- export declare function createVNode(element: string | Component, componentOptions?: ComponentOptions): Promise<VNode>;
2
+ import type { ComponentOptions, ImageOptions } from '../types.js';
4
3
  export declare function createSvg(element: string | Component, imageOptions: ImageOptions, componentOptions?: ComponentOptions): Promise<string>;
5
4
  export declare function createPng(element: string | Component, imageOptions: ImageOptions, componentOptions?: ComponentOptions): Promise<Uint8Array<ArrayBufferLike>>;
@@ -1,15 +1,7 @@
1
- import { html } from 'satori-html';
2
1
  import { loadDynamicAsset } from './emoji.js';
3
2
  import { default_fonts, DEFAULT_WIDTH } from '../helpers/defaults.js';
4
3
  import { useResvg, useSatori } from '../providers/instances.js';
5
- import { render } from 'svelte/server';
6
- function svelteComponentToJsx(component, props = {}) {
7
- const { body, head } = render(component, { props });
8
- return html(body + head);
9
- }
10
- export async function createVNode(element, componentOptions) {
11
- return typeof element === 'string' ? html(element.replaceAll('\n', '').trim()) : svelteComponentToJsx(element, componentOptions?.props);
12
- }
4
+ import { createVNode } from './toJSX.js';
13
5
  export async function createSvg(element, imageOptions, componentOptions) {
14
6
  const [satori, vnodes] = await Promise.all([useSatori(), createVNode(element, componentOptions)]);
15
7
  const satoriOptions = structuredClone(imageOptions);
@@ -0,0 +1,3 @@
1
+ import type { Component } from 'svelte';
2
+ import type { ComponentOptions, VNode } from '../types.js';
3
+ export declare function createVNode(element: string | Component, componentOptions?: ComponentOptions): VNode;
@@ -0,0 +1,9 @@
1
+ import { render } from 'svelte/server';
2
+ import { html } from 'satori-html';
3
+ function svelteComponentToHTML(component, props = {}) {
4
+ const { body, head } = render(component, { props });
5
+ return html(body + head);
6
+ }
7
+ export function createVNode(element, componentOptions) {
8
+ return typeof element === 'string' ? html(element.replaceAll('\n', '').trim()) : svelteComponentToHTML(element, componentOptions?.props);
9
+ }
package/dist/plugin.js CHANGED
@@ -13,8 +13,8 @@ export function sveltekitOG(options) {
13
13
  return {
14
14
  build: {
15
15
  rollupOptions: {
16
- plugins: [rollupWasm(options)]
17
- }
16
+ plugins: [rollupWasm(options)],
17
+ },
18
18
  }
19
19
  };
20
20
  }
@@ -3,6 +3,6 @@ import { Resvg as _Resvg, initWasm } from '@resvg/resvg-wasm'
3
3
  export default {
4
4
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
5
  // @ts-ignore
6
- initWasmPromise: initWasm(import('./resvg.wasm?module').then(r => r.default || r)),
6
+ initWasmPromise: initWasm(import('@resvg/resvg-wasm/index_bg.wasm').then(r => r.default || r)),
7
7
  Resvg: _Resvg,
8
8
  }
package/package.json CHANGED
@@ -1,73 +1,81 @@
1
1
  {
2
- "name": "@ethercorps/sveltekit-og",
3
- "version": "4.2.0",
4
- "exports": {
5
- ".": {
6
- "types": "./dist/index.d.ts",
7
- "svelte": "./dist/index.js",
8
- "import": "./dist/index.js"
9
- },
10
- "./fonts": {
11
- "types": "./dist/fonts.d.ts",
12
- "import": "./dist/fonts.js"
13
- },
14
- "./plugin": {
15
- "types": "./dist/plugin.d.ts",
16
- "import": "./dist/plugin.js"
17
- }
18
- },
19
- "files": [
20
- "dist",
21
- "!dist/**/*.test.*",
22
- "!dist/**/*.spec.*"
23
- ],
24
- "devDependencies": {
25
- "@sveltejs/adapter-vercel": "^5.10.2",
26
- "@sveltejs/kit": "^2.48.5",
27
- "@sveltejs/package": "^2.5.4",
28
- "@sveltejs/vite-plugin-svelte": "^4.0.4",
29
- "@types/node": "^24.7.1",
30
- "@typescript-eslint/eslint-plugin": "^5.62.0",
31
- "@typescript-eslint/parser": "^5.62.0",
32
- "css-tree": "^2.3.1",
33
- "eslint": "^8.57.1",
34
- "eslint-config-prettier": "^8.10.0",
35
- "eslint-plugin-svelte": "^2.46.1",
36
- "prettier": "^3.6.2",
37
- "prettier-plugin-svelte": "^3.4.0",
38
- "publint": "^0.1.16",
39
- "rollup-plugin-visualizer": "^5.14.0",
40
- "svelte": "^5.43.12",
41
- "svelte-check": "^4.3.2",
42
- "tslib": "^2.8.1",
43
- "typescript": "^5.9.3",
44
- "vite": "^5.4.19",
45
- "vitest": "^1.6.1"
46
- },
47
- "main": "./dist/index.js",
48
- "svelte": "./dist/index.js",
49
- "types": "./dist/index.d.ts",
50
- "type": "module",
51
- "dependencies": {
52
- "@resvg/resvg-wasm": "^2.6.2",
53
- "satori": "^0.10.14",
54
- "satori-html": "0.3.2",
55
- "std-env": "^3.9.0",
56
- "unwasm": "^0.5.0"
57
- },
58
- "peerDependencies": {
59
- "@sveltejs/kit": ">=2.0.0"
60
- },
61
- "scripts": {
62
- "dev": "vite dev",
63
- "build": "vite build && npm run package",
64
- "preview": "vite preview",
65
- "package": "svelte-kit sync && svelte-package && publint",
66
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
67
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
68
- "test": "vitest",
69
- "lint": "prettier --plugin-search-dir . --check . && eslint .",
70
- "format": "prettier --plugin-search-dir . --write .",
71
- "publishBeta": "npm publish --tag beta"
72
- }
2
+ "name": "@ethercorps/sveltekit-og",
3
+ "version": "4.3.1-next.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
+ "scripts": {
11
+ "dev": "vite dev",
12
+ "build": "vite build && npm run package",
13
+ "preview": "vite preview",
14
+ "package": "svelte-kit sync && svelte-package && publint",
15
+ "prepublishOnly": "npm run package",
16
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
17
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
18
+ "test": "vitest",
19
+ "lint": "prettier --plugin-search-dir . --check . && eslint .",
20
+ "format": "prettier --plugin-search-dir . --write .",
21
+ "publishBeta": "npm publish --tag beta"
22
+ },
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "svelte": "./dist/index.js",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./fonts": {
30
+ "types": "./dist/fonts.d.ts",
31
+ "import": "./dist/fonts.js"
32
+ },
33
+ "./plugin": {
34
+ "types": "./dist/plugin.d.ts",
35
+ "import": "./dist/plugin.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "!dist/**/*.test.*",
41
+ "!dist/**/*.spec.*"
42
+ ],
43
+ "devDependencies": {
44
+ "@sveltejs/adapter-vercel": "^5.10.2",
45
+ "@sveltejs/kit": "^2.48.5",
46
+ "@sveltejs/package": "^2.5.4",
47
+ "@sveltejs/vite-plugin-svelte": "^4.0.4",
48
+ "@types/node": "^24.7.1",
49
+ "@typescript-eslint/eslint-plugin": "^5.62.0",
50
+ "@typescript-eslint/parser": "^5.62.0",
51
+ "css-tree": "^2.3.1",
52
+ "eslint": "^8.57.1",
53
+ "eslint-config-prettier": "^8.10.0",
54
+ "eslint-plugin-svelte": "^2.46.1",
55
+ "prettier": "^3.6.2",
56
+ "prettier-plugin-svelte": "^3.4.0",
57
+ "publint": "^0.1.16",
58
+ "rollup-plugin-visualizer": "^5.14.0",
59
+ "svelte": "^5.43.12",
60
+ "svelte-check": "^4.3.2",
61
+ "tslib": "^2.8.1",
62
+ "typescript": "^5.9.3",
63
+ "vite": "^5.4.19",
64
+ "vitest": "^1.6.1"
65
+ },
66
+ "main": "./dist/index.js",
67
+ "svelte": "./dist/index.js",
68
+ "types": "./dist/index.d.ts",
69
+ "type": "module",
70
+ "dependencies": {
71
+ "@resvg/resvg-wasm": "^2.6.2",
72
+ "satori": "^0.10.14",
73
+ "satori-html": "0.3.2",
74
+ "std-env": "^3.9.0",
75
+ "unwasm": "^0.5.0"
76
+ },
77
+ "peerDependencies": {
78
+ "@sveltejs/kit": ">=2.0.0"
79
+ },
80
+ "packageManager": "pnpm@10.12.1"
73
81
  }