@takumi-rs/image-response 0.49.0 → 0.50.0
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 +7 -9
- package/dist/wasm.cjs +1 -1
- package/dist/wasm.d.cts +36 -7
- package/dist/wasm.d.ts +36 -7
- package/dist/wasm.js +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -92,20 +92,18 @@ If you want to use this package in browser environment/cloudflare, you can impor
|
|
|
92
92
|
|
|
93
93
|
Make sure you have the `@takumi-rs/wasm` package installed as well.
|
|
94
94
|
|
|
95
|
+
Check the additional [bundler setup section](https://takumi.kane.tw/docs#additional-bundler-setup) for more setup details.
|
|
96
|
+
|
|
95
97
|
```tsx
|
|
96
98
|
import { describe, expect, test } from "bun:test";
|
|
97
|
-
import { ImageResponse
|
|
98
|
-
|
|
99
|
-
// Or with bundler specific WASM resolution process,
|
|
100
|
-
// like cloudflare workers can be configured with wrangler.toml.
|
|
101
|
-
await initWasm(fetch(import.meta.resolve("@takumi-rs/wasm/takumi_wasm_bg.wasm")));
|
|
102
|
-
|
|
103
|
-
// For Next.js Runtime, you can use the bundled WASM file.
|
|
104
|
-
await initWasm(import("@takumi-rs/wasm/next"));
|
|
99
|
+
import { ImageResponse } from "@takumi-rs/image-response/wasm";
|
|
100
|
+
import module from "@takumi-rs/wasm/next";
|
|
105
101
|
|
|
106
102
|
export default {
|
|
107
103
|
fetch() {
|
|
108
|
-
return new ImageResponse(<div>Hello</div
|
|
104
|
+
return new ImageResponse(<div>Hello</div>, {
|
|
105
|
+
module,
|
|
106
|
+
});
|
|
109
107
|
}
|
|
110
108
|
}
|
|
111
109
|
```
|
package/dist/wasm.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var I=Object.create;var o=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var O=(e,t)=>{for(var n in t)o(e,n,{get:t[n],enumerable:!0})},f=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of y(t))!h.call(e,s)&&s!==n&&o(e,s,{get:()=>t[s],enumerable:!(r=l(t,s))||r.enumerable});return e};var M=(e,t,n)=>(n=e!=null?I(w(e)):{},f(t||!e||!e.__esModule?o(n,"default",{value:e,enumerable:!0}):n,e)),P=e=>f(o({},"__esModule",{value:!0}),e);var S={};O(S,{ImageResponse:()=>p,default:()=>N});module.exports=P(S);var m=require("@takumi-rs/helpers/jsx"),a=M(require("@takumi-rs/wasm"),1),i,b=new WeakSet,x=new WeakSet;function F(e){if(e&&"renderer"in e)return e.renderer;if(i??=new a.Renderer,e?.fonts)for(let t of e.fonts)W(t,i);if(e?.persistentImages)for(let t of e.persistentImages)k(t,i);return i}function W(e,t){b.has(e)||t.loadFont(e)}function k(e,t){x.has(e)||t.putPersistentImage(e.src,new Uint8Array(e.data))}function B(e,t){return t.format??="webp",new ReadableStream({async start(n){try{let r=await t.module;typeof r=="object"&&"default"in r&&(r=r.default),await(0,a.default)({module_or_path:r});let s=F(t),d=await(0,m.fromJsx)(e);if(!t.fetchedResources){let c=(0,a.collectNodeFetchTasks)(d);c.length>0&&(t.fetchedResources=new Map(await Promise.all(c.map(async u=>[u,await fetch(u).then(R=>R.arrayBuffer())]))))}let g=s.render(d,t);n.enqueue(g),n.close()}catch(r){n.error(r)}}})}var T={png:"image/png",jpeg:"image/jpeg",webp:"image/webp"},p=class extends Response{constructor(t,n){let r=B(t,n),s=new Headers(n?.headers);s.get("content-type")||s.set("content-type",T[n?.format??"webp"]),super(r,{status:n?.status,statusText:n?.statusText,headers:s})}},N=p;0&&(module.exports={ImageResponse});
|
package/dist/wasm.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RenderOptions, Renderer, Font, ByteBuf
|
|
1
|
+
import { RenderOptions, InitInput, Renderer, Font, ByteBuf } from '@takumi-rs/wasm';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
type PersistentImage = {
|
|
@@ -10,18 +10,47 @@ declare module "react" {
|
|
|
10
10
|
tw?: string;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
type
|
|
13
|
+
type ModuleOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* @description The WebAssembly module to use for the renderer.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* For Cloudflare Workers, you can use the bundled WASM file.
|
|
19
|
+
* ```ts
|
|
20
|
+
* {
|
|
21
|
+
* module: import("@takumi-rs/wasm/takumi_wasm_bg.wasm"),
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* For Next.js Turbopack, you can use the nextjs helper.
|
|
26
|
+
* ```ts
|
|
27
|
+
* {
|
|
28
|
+
* module: import("@takumi-rs/wasm/next"),
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* For Vite, use `?url` suffix to get the URL of the WASM file.
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* {
|
|
36
|
+
* module: import("@takumi-rs/wasm/takumi_wasm_bg.wasm?url"),
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
module: InitInput | Promise<InitInput> | {
|
|
41
|
+
default: InitInput;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
type ImageResponseOptionsWithRenderer = ResponseInit & RenderOptions & ModuleOptions & {
|
|
14
45
|
renderer: Renderer;
|
|
15
46
|
};
|
|
16
|
-
type ImageResponseOptionsWithoutRenderer = ResponseInit & RenderOptions & {
|
|
47
|
+
type ImageResponseOptionsWithoutRenderer = ResponseInit & RenderOptions & ModuleOptions & {
|
|
17
48
|
fonts?: Font[];
|
|
18
49
|
persistentImages?: PersistentImage[];
|
|
19
50
|
};
|
|
20
51
|
type ImageResponseOptions = ImageResponseOptionsWithRenderer | ImageResponseOptionsWithoutRenderer;
|
|
21
52
|
declare class ImageResponse extends Response {
|
|
22
|
-
constructor(component: ReactNode, options
|
|
53
|
+
constructor(component: ReactNode, options: ImageResponseOptions);
|
|
23
54
|
}
|
|
24
|
-
declare function initWasm(source: Promise<InitInput> | InitInput): Promise<void>;
|
|
25
|
-
declare function initWasmSync(source: SyncInitInput): void;
|
|
26
55
|
|
|
27
|
-
export { ImageResponse, type ImageResponseOptions, ImageResponse as default
|
|
56
|
+
export { ImageResponse, type ImageResponseOptions, ImageResponse as default };
|
package/dist/wasm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RenderOptions, Renderer, Font, ByteBuf
|
|
1
|
+
import { RenderOptions, InitInput, Renderer, Font, ByteBuf } from '@takumi-rs/wasm';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
type PersistentImage = {
|
|
@@ -10,18 +10,47 @@ declare module "react" {
|
|
|
10
10
|
tw?: string;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
type
|
|
13
|
+
type ModuleOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* @description The WebAssembly module to use for the renderer.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* For Cloudflare Workers, you can use the bundled WASM file.
|
|
19
|
+
* ```ts
|
|
20
|
+
* {
|
|
21
|
+
* module: import("@takumi-rs/wasm/takumi_wasm_bg.wasm"),
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* For Next.js Turbopack, you can use the nextjs helper.
|
|
26
|
+
* ```ts
|
|
27
|
+
* {
|
|
28
|
+
* module: import("@takumi-rs/wasm/next"),
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* For Vite, use `?url` suffix to get the URL of the WASM file.
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* {
|
|
36
|
+
* module: import("@takumi-rs/wasm/takumi_wasm_bg.wasm?url"),
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
module: InitInput | Promise<InitInput> | {
|
|
41
|
+
default: InitInput;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
type ImageResponseOptionsWithRenderer = ResponseInit & RenderOptions & ModuleOptions & {
|
|
14
45
|
renderer: Renderer;
|
|
15
46
|
};
|
|
16
|
-
type ImageResponseOptionsWithoutRenderer = ResponseInit & RenderOptions & {
|
|
47
|
+
type ImageResponseOptionsWithoutRenderer = ResponseInit & RenderOptions & ModuleOptions & {
|
|
17
48
|
fonts?: Font[];
|
|
18
49
|
persistentImages?: PersistentImage[];
|
|
19
50
|
};
|
|
20
51
|
type ImageResponseOptions = ImageResponseOptionsWithRenderer | ImageResponseOptionsWithoutRenderer;
|
|
21
52
|
declare class ImageResponse extends Response {
|
|
22
|
-
constructor(component: ReactNode, options
|
|
53
|
+
constructor(component: ReactNode, options: ImageResponseOptions);
|
|
23
54
|
}
|
|
24
|
-
declare function initWasm(source: Promise<InitInput> | InitInput): Promise<void>;
|
|
25
|
-
declare function initWasmSync(source: SyncInitInput): void;
|
|
26
55
|
|
|
27
|
-
export { ImageResponse, type ImageResponseOptions, ImageResponse as default
|
|
56
|
+
export { ImageResponse, type ImageResponseOptions, ImageResponse as default };
|
package/dist/wasm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fromJsx as f}from"@takumi-rs/helpers/jsx";import
|
|
1
|
+
import{fromJsx as f}from"@takumi-rs/helpers/jsx";import m,{collectNodeFetchTasks as g,Renderer as R}from"@takumi-rs/wasm";var a,I=new WeakSet,l=new WeakSet;function y(e){if(e&&"renderer"in e)return e.renderer;if(a??=new R,e?.fonts)for(let t of e.fonts)w(t,a);if(e?.persistentImages)for(let t of e.persistentImages)h(t,a);return a}function w(e,t){I.has(e)||t.loadFont(e)}function h(e,t){l.has(e)||t.putPersistentImage(e.src,new Uint8Array(e.data))}function O(e,t){return t.format??="webp",new ReadableStream({async start(n){try{let r=await t.module;typeof r=="object"&&"default"in r&&(r=r.default),await m({module_or_path:r});let s=y(t),i=await f(e);if(!t.fetchedResources){let p=g(i);p.length>0&&(t.fetchedResources=new Map(await Promise.all(p.map(async d=>[d,await fetch(d).then(u=>u.arrayBuffer())]))))}let c=s.render(i,t);n.enqueue(c),n.close()}catch(r){n.error(r)}}})}var M={png:"image/png",jpeg:"image/jpeg",webp:"image/webp"},o=class extends Response{constructor(t,n){let r=O(t,n),s=new Headers(n?.headers);s.get("content-type")||s.set("content-type",M[n?.format??"webp"]),super(r,{status:n?.status,statusText:n?.statusText,headers:s})}},x=o;export{o as ImageResponse,x as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takumi-rs/image-response",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.50.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "me@kane.tw",
|
|
7
7
|
"name": "Kane Wang",
|
|
@@ -11,17 +11,17 @@
|
|
|
11
11
|
"url": "git+https://github.com/kane50613/takumi.git"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@takumi-rs/core": "0.
|
|
15
|
-
"@takumi-rs/helpers": "0.
|
|
16
|
-
"@takumi-rs/wasm": "0.
|
|
14
|
+
"@takumi-rs/core": "0.50.0",
|
|
15
|
+
"@takumi-rs/helpers": "0.50.0",
|
|
16
|
+
"@takumi-rs/wasm": "0.50.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/bun": "catalog:",
|
|
20
|
-
"@types/react": "
|
|
21
|
-
"@types/react-dom": "^19.2.
|
|
20
|
+
"@types/react": "catalog:",
|
|
21
|
+
"@types/react-dom": "^19.2.3",
|
|
22
22
|
"react": "^19.2.0",
|
|
23
23
|
"react-dom": "^19.2.0",
|
|
24
|
-
"tsup": "^8.5.
|
|
24
|
+
"tsup": "^8.5.1",
|
|
25
25
|
"type-fest": "^5.2.0",
|
|
26
26
|
"typescript": "catalog:"
|
|
27
27
|
},
|