@takumi-rs/image-response 0.48.0 → 0.49.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 +5 -7
- package/dist/wasm.cjs +1 -1
- package/dist/wasm.d.cts +4 -2
- package/dist/wasm.d.ts +4 -2
- package/dist/wasm.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -94,16 +94,14 @@ Make sure you have the `@takumi-rs/wasm` package installed as well.
|
|
|
94
94
|
|
|
95
95
|
```tsx
|
|
96
96
|
import { describe, expect, test } from "bun:test";
|
|
97
|
-
import
|
|
98
|
-
import ImageResponse from "@takumi-rs/image-response/wasm";
|
|
97
|
+
import { ImageResponse, initWasm } from "@takumi-rs/image-response/wasm";
|
|
99
98
|
|
|
100
99
|
// Or with bundler specific WASM resolution process,
|
|
101
100
|
// like cloudflare workers can be configured with wrangler.toml.
|
|
102
|
-
await
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
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"));
|
|
107
105
|
|
|
108
106
|
export default {
|
|
109
107
|
fetch() {
|
package/dist/wasm.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var R=Object.create;var o=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var l=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,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of l(t))!h.call(e,r)&&r!==n&&o(e,r,{get:()=>t[r],enumerable:!(s=y(t,r))||s.enumerable});return e};var W=(e,t,n)=>(n=e!=null?R(w(e)):{},f(t||!e||!e.__esModule?o(n,"default",{value:e,enumerable:!0}):n,e)),S=e=>f(o({},"__esModule",{value:!0}),e);var z={};O(z,{ImageResponse:()=>c,default:()=>j,initWasm:()=>N,initWasmSync:()=>A});module.exports=S(z);var u=require("@takumi-rs/helpers/jsx"),a=W(require("@takumi-rs/wasm"),1),p,x=new WeakSet,P=new WeakSet;function F(e){if(e&&"renderer"in e)return e.renderer;if(p??=new a.Renderer,e?.fonts)for(let t of e.fonts)b(t,p);if(e?.persistentImages)for(let t of e.persistentImages)M(t,p);return p}function b(e,t){x.has(e)||t.loadFont(e)}function M(e,t){P.has(e)||t.putPersistentImage(e.src,new Uint8Array(e.data))}var k={format:"webp"};function B(e,t={...k}){return new ReadableStream({async start(n){try{let s=F(t),r=await(0,u.fromJsx)(e);if(!t.fetchedResources){let d=(0,a.collectNodeFetchTasks)(r);d.length>0&&(t.fetchedResources=new Map(await Promise.all(d.map(async m=>[m,await fetch(m).then(I=>I.arrayBuffer())]))))}let g=s.render(r,t);n.enqueue(g),n.close()}catch(s){n.error(s)}}})}var T={png:"image/png",jpeg:"image/jpeg",webp:"image/webp"},i=!1,c=class extends Response{constructor(t,n){if(!i)throw new Error("WASM is not initialized, please call `initWasm` or `initWasmSync` first.");let s=B(t,n),r=new Headers(n?.headers);r.get("content-type")||r.set("content-type",T[n?.format??"webp"]),super(s,{status:n?.status,statusText:n?.statusText,headers:r})}};async function N(e){i||(i=!0,await(0,a.default)({module_or_path:e}))}function A(e){i||((0,a.initSync)({module:e}),i=!0)}var j=c;0&&(module.exports={ImageResponse,initWasm,initWasmSync});
|
package/dist/wasm.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RenderOptions, Renderer, Font, ByteBuf } from '@takumi-rs/wasm';
|
|
1
|
+
import { RenderOptions, Renderer, Font, ByteBuf, InitInput, SyncInitInput } from '@takumi-rs/wasm';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
type PersistentImage = {
|
|
@@ -21,5 +21,7 @@ type ImageResponseOptions = ImageResponseOptionsWithRenderer | ImageResponseOpti
|
|
|
21
21
|
declare class ImageResponse extends Response {
|
|
22
22
|
constructor(component: ReactNode, options?: ImageResponseOptions);
|
|
23
23
|
}
|
|
24
|
+
declare function initWasm(source: Promise<InitInput> | InitInput): Promise<void>;
|
|
25
|
+
declare function initWasmSync(source: SyncInitInput): void;
|
|
24
26
|
|
|
25
|
-
export { ImageResponse, type ImageResponseOptions, ImageResponse as default };
|
|
27
|
+
export { ImageResponse, type ImageResponseOptions, ImageResponse as default, initWasm, initWasmSync };
|
package/dist/wasm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RenderOptions, Renderer, Font, ByteBuf } from '@takumi-rs/wasm';
|
|
1
|
+
import { RenderOptions, Renderer, Font, ByteBuf, InitInput, SyncInitInput } from '@takumi-rs/wasm';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
type PersistentImage = {
|
|
@@ -21,5 +21,7 @@ type ImageResponseOptions = ImageResponseOptionsWithRenderer | ImageResponseOpti
|
|
|
21
21
|
declare class ImageResponse extends Response {
|
|
22
22
|
constructor(component: ReactNode, options?: ImageResponseOptions);
|
|
23
23
|
}
|
|
24
|
+
declare function initWasm(source: Promise<InitInput> | InitInput): Promise<void>;
|
|
25
|
+
declare function initWasmSync(source: SyncInitInput): void;
|
|
24
26
|
|
|
25
|
-
export { ImageResponse, type ImageResponseOptions, ImageResponse as default };
|
|
27
|
+
export { ImageResponse, type ImageResponseOptions, ImageResponse as default, initWasm, initWasmSync };
|
package/dist/wasm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fromJsx as f}from"@takumi-rs/helpers/jsx";import{collectNodeFetchTasks as
|
|
1
|
+
import{fromJsx as f}from"@takumi-rs/helpers/jsx";import u,{collectNodeFetchTasks as g,initSync as I,Renderer as R}from"@takumi-rs/wasm";var i,y=new WeakSet,l=new WeakSet;function w(e){if(e&&"renderer"in e)return e.renderer;if(i??=new R,e?.fonts)for(let t of e.fonts)h(t,i);if(e?.persistentImages)for(let t of e.persistentImages)O(t,i);return i}function h(e,t){y.has(e)||t.loadFont(e)}function O(e,t){l.has(e)||t.putPersistentImage(e.src,new Uint8Array(e.data))}var W={format:"webp"};function S(e,t={...W}){return new ReadableStream({async start(n){try{let s=w(t),r=await f(e);if(!t.fetchedResources){let p=g(r);p.length>0&&(t.fetchedResources=new Map(await Promise.all(p.map(async c=>[c,await fetch(c).then(m=>m.arrayBuffer())]))))}let d=s.render(r,t);n.enqueue(d),n.close()}catch(s){n.error(s)}}})}var x={png:"image/png",jpeg:"image/jpeg",webp:"image/webp"},a=!1,o=class extends Response{constructor(t,n){if(!a)throw new Error("WASM is not initialized, please call `initWasm` or `initWasmSync` first.");let s=S(t,n),r=new Headers(n?.headers);r.get("content-type")||r.set("content-type",x[n?.format??"webp"]),super(s,{status:n?.status,statusText:n?.statusText,headers:r})}};async function b(e){a||(a=!0,await u({module_or_path:e}))}function M(e){a||(I({module:e}),a=!0)}var k=o;export{o as ImageResponse,k as default,b as initWasm,M as initWasmSync};
|
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.49.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "me@kane.tw",
|
|
7
7
|
"name": "Kane Wang",
|
|
@@ -11,9 +11,9 @@
|
|
|
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.49.0",
|
|
15
|
+
"@takumi-rs/helpers": "0.49.0",
|
|
16
|
+
"@takumi-rs/wasm": "0.49.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/bun": "catalog:",
|