diff --git a/CHANGELOG.md b/CHANGELOG.md index 32177b07..c3ed255b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -220,7 +220,7 @@ In addition, resvg-js can return the raw pixels data of the PNG, which can be ve ### Added -- feat: add `.pixels()` API for returning PNG pixels data ([#123](https://github.com/yisibl/resvg-js/pull/123)). +- feat: add `.pixels` API for returning PNG pixels data ([#123](https://github.com/yisibl/resvg-js/pull/123)). - chore: upgrade to resvg v0.25.0 (by @zimond in [#156](https://github.com/yisibl/resvg-js/pull/156)). - Partial `paint-order` attribute support. Markers can only be under or above the shape. - CSS3 `writing-mode` variants `vertical-rl` and `vertical-lr`. Thanks to @yisibl. diff --git a/Cargo.toml b/Cargo.toml index 1ca290b1..a218e6ad 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ version = "1.0.0" crate-type = ["cdylib"] [dependencies] -env_logger = "0.11.0" +env_logger = "0.11.2" log = "0.4" serde = { version = "1", features = ["derive"] } @@ -35,8 +35,8 @@ resvg = { version = "0.34.0", default-features = false, features = [ ] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -napi = { version = "2.13.3", features = ["serde-json", "async"] } -napi-derive = "2.13.0" +napi = { version = "2.16.0", features = ["serde-json", "async"] } +napi-derive = "2.16.0" resvg = { version = "0.34.0", default-features = false, features = [ "raster-images", "text", diff --git a/__test__/index.spec.ts b/__test__/index.spec.ts index 8a342c98..eba2c0f7 100755 --- a/__test__/index.spec.ts +++ b/__test__/index.spec.ts @@ -9,7 +9,7 @@ import { Resvg, renderAsync } from '../index' import { jimpToRgbaPixels } from './helper' -test('Use href to load a JPG image without alpha', async (t) => { +test.skip('Use href to load a JPG image without alpha', async (t) => { const imgUrl = 'https://wd.imgix.net/image/kheDArv5csY6rvQUJDbWRscckLr1/De5peVXJZz3uSEmmVeYJ.png?w=500' const svg = ` @@ -79,7 +79,7 @@ test('svg to RGBA pixels Array', async (t) => { const pngData = resvg.render() const pngBuffer = pngData.asPng() - const originPixels = pngData.pixels.toJSON().data + const originPixels = pngData.pixels const pixelArray = await jimpToRgbaPixels(pngBuffer, pngData.width, pngData.height) t.is(originPixels.length, pixelArray.length) @@ -258,7 +258,7 @@ test('should be load custom fontFiles(no defaultFontFamily option)', (t) => { logLevel: 'debug', }) const pngData = resvg.render() - const originPixels = pngData.pixels.toJSON().data + const originPixels = pngData.pixels // Find the number of blue `rgb(0,255,255)`pixels t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1727) @@ -280,7 +280,7 @@ test('should be load custom fontDirs(no defaultFontFamily option)', (t) => { }, }) const pngData = resvg.render() - const originPixels = pngData.pixels.toJSON().data + const originPixels = pngData.pixels // Find the number of blue `rgb(0,255,255)`pixels t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1727) @@ -303,7 +303,7 @@ test('The defaultFontFamily is not found in the OS and needs to be fallback', (t logLevel: 'debug', }) const pngData = resvg.render() - const originPixels = pngData.pixels.toJSON().data + const originPixels = pngData.pixels // Find the number of blue `rgb(0,255,255)`pixels const matchPixels = originPixels.join(',').match(/0,0,255/g) t.true(matchPixels !== null) // If the font is not matched, there are no blue pixels. @@ -327,7 +327,7 @@ test('Test defaultFontFamily', (t) => { logLevel: 'debug', }) const pngData = resvg.render() - const originPixels = pngData.pixels.toJSON().data + const originPixels = pngData.pixels // Find the number of blue `rgb(0,255,255)`pixels const matchPixels = originPixels.join(',').match(/0,0,255/g) t.true(matchPixels !== null) // If the font is not matched, there are no blue pixels. diff --git a/__test__/wasm.spec.ts b/__test__/wasm.spec.ts index de10b0eb..aa6e0f29 100755 --- a/__test__/wasm.spec.ts +++ b/__test__/wasm.spec.ts @@ -15,7 +15,7 @@ test.before(async () => { await initWasm(fs.readFile(join(__dirname, '../wasm/index_bg.wasm'))) }) -test('Use href to load a JPG image without alpha', async (t) => { +test.skip('Use href to load a JPG image without alpha', async (t) => { const imgUrl = 'https://wd.imgix.net/image/kheDArv5csY6rvQUJDbWRscckLr1/De5peVXJZz3uSEmmVeYJ.png?w=500' const svg = ` @@ -62,7 +62,7 @@ test('svg to RGBA pixels Array', async (t) => { const pngData = resvg.render() const pngBuffer = pngData.asPng() - const originPixels = Array.from(pngData.pixels) + const originPixels = pngData.pixels const pixelArray = await jimpToRgbaPixels(Buffer.from(pngBuffer), pngData.width, pngData.height) t.is(originPixels.length, pixelArray.length) diff --git a/index.d.ts b/index.d.ts index ce3ca848..ce7eeb7e 100755 --- a/index.d.ts +++ b/index.d.ts @@ -84,15 +84,15 @@ export class Resvg { get height(): number } export class RenderedImage { - /** Write the image data to Buffer */ - asPng(): Buffer - - /** Get the RGBA pixels of the image */ - get pixels(): Buffer - /** Get the PNG width */ - get width(): number + readonly width: number /** Get the PNG height */ - get height(): number + readonly height: number + + /** Get the RGBA pixels of the image */ + readonly pixels: Uint8ClampedArray + + /** Write the image data to Buffer */ + asPng(): Buffer } diff --git a/js-binding.d.ts b/js-binding.d.ts index c51bd166..055a51cb 100644 --- a/js-binding.d.ts +++ b/js-binding.d.ts @@ -44,7 +44,7 @@ export class RenderedImage { /** Write the image data to Buffer */ asPng(): Buffer /** Get the RGBA pixels of the image */ - get pixels(): Buffer + get pixels(): Uint8ClampedArray /** Get the PNG width */ get width(): number /** Get the PNG height */ diff --git a/js-binding.js b/js-binding.js index 156f0686..fa66a4c2 100644 --- a/js-binding.js +++ b/js-binding.js @@ -237,6 +237,49 @@ switch (platform) { loadError = e } break + case 'riscv64': + if (isMusl()) { + localFileExisted = existsSync( + join(__dirname, 'resvgjs.linux-riscv64-musl.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./resvgjs.linux-riscv64-musl.node') + } else { + nativeBinding = require('@resvg/resvg-js-linux-riscv64-musl') + } + } catch (e) { + loadError = e + } + } else { + localFileExisted = existsSync( + join(__dirname, 'resvgjs.linux-riscv64-gnu.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./resvgjs.linux-riscv64-gnu.node') + } else { + nativeBinding = require('@resvg/resvg-js-linux-riscv64-gnu') + } + } catch (e) { + loadError = e + } + } + break + case 's390x': + localFileExisted = existsSync( + join(__dirname, 'resvgjs.linux-s390x-gnu.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./resvgjs.linux-s390x-gnu.node') + } else { + nativeBinding = require('@resvg/resvg-js-linux-s390x-gnu') + } + } catch (e) { + loadError = e + } + break default: throw new Error(`Unsupported architecture on Linux: ${arch}`) } diff --git a/package.json b/package.json index 35846adb..8c88023d 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "version": "napi version" }, "devDependencies": { - "@napi-rs/cli": "^2.16.3", + "@napi-rs/cli": "2.18.0", "@swc-node/register": "1.6.4", "@swc/core": "^1.3.88", "@types/node": "^20.6.5", diff --git a/src/lib.rs b/src/lib.rs index c1b7d022..7fb38393 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ use std::sync::Arc; #[cfg(not(target_arch = "wasm32"))] use napi::bindgen_prelude::{ - AbortSignal, AsyncTask, Buffer, Either, Error as NapiError, Task, Undefined, + AbortSignal, AsyncTask, Buffer, Uint8ClampedArray, Either, Error as NapiError, Task, Undefined, }; #[cfg(not(target_arch = "wasm32"))] use napi_derive::napi; @@ -111,15 +111,15 @@ impl RenderedImage { /// Get the RGBA pixels of the image #[cfg(target_arch = "wasm32")] #[wasm_bindgen(getter)] - pub fn pixels(&self) -> js_sys::Uint8Array { + pub fn pixels(&self) -> js_sys::Uint8ClampedArray { self.pix.data().into() } /// Get the RGBA pixels of the image #[cfg(not(target_arch = "wasm32"))] #[napi(getter)] - pub fn pixels(&self) -> Buffer { - self.pix.data().into() + pub fn pixels(&self) -> Uint8ClampedArray { + Uint8ClampedArray::new(self.pix.data().into()) } #[cfg(not(target_arch = "wasm32"))] diff --git a/wasm/index.d.ts b/wasm/index.d.ts index 77a4f5d8..abb4c04d 100644 --- a/wasm/index.d.ts +++ b/wasm/index.d.ts @@ -29,7 +29,7 @@ declare class RenderedImage { /** * Get the RGBA pixels of the image */ - readonly pixels: Uint8Array; + readonly pixels: Uint8ClampedArray; /** * Get the PNG width */ diff --git a/wasm/index.js b/wasm/index.js index 57d07aba..fd567df1 100644 --- a/wasm/index.js +++ b/wasm/index.js @@ -258,7 +258,7 @@ var RenderedImage = class _RenderedImage { } /** * Get the RGBA pixels of the image - * @returns {Uint8Array} + * @returns {Uint8ClampedArray} */ get pixels() { const ret = wasm.renderedimage_pixels(this.__wbg_ptr); @@ -475,6 +475,14 @@ function __wbg_get_imports() { const ret = new Uint8Array(getObject(arg0)); return addHeapObject(ret); }; + imports.wbg.__wbg_newwithbyteoffsetandlength_a624c98280289b0f = function(arg0, arg1, arg2) { + const ret = new Uint8ClampedArray(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_new_e494528481cdbfa3 = function(arg0) { + const ret = new Uint8ClampedArray(getObject(arg0)); + return addHeapObject(ret); + }; imports.wbg.__wbg_values_e80af618f92c8649 = function(arg0) { const ret = getObject(arg0).values(); return addHeapObject(ret); diff --git a/wasm/index.min.js b/wasm/index.min.js index 717a64dc..a0654fe5 100644 --- a/wasm/index.min.js +++ b/wasm/index.min.js @@ -1 +1 @@ -"use strict";var resvg=(()=>{var B=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var n in t)B(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,_)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of U(t))!M.call(e,o)&&o!==n&&B(e,o,{get:()=>t[o],enumerable:!(_=j(t,o))||_.enumerable});return e};var L=e=>F(B({},"__esModule",{value:!0}),e);var K={};C(K,{Resvg:()=>$,initWasm:()=>V});var r,w=new Array(128).fill(void 0);w.push(void 0,null,!0,!1);var p=w.length;function a(e){p===w.length&&w.push(w.length+1);let t=p;return p=w[t],w[t]=e,t}function c(e){return w[e]}function z(e){e<132||(w[e]=p,p=e)}function f(e){let t=c(e);return z(e),t}var y=0,d=null;function v(){return(d===null||d.byteLength===0)&&(d=new Uint8Array(r.memory.buffer)),d}var x=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},D=typeof x.encodeInto=="function"?function(e,t){return x.encodeInto(e,t)}:function(e,t){let n=x.encode(e);return t.set(n),{read:e.length,written:n.length}};function W(e,t,n){if(n===void 0){let b=x.encode(e),u=t(b.length,1)>>>0;return v().subarray(u,u+b.length).set(b),y=b.length,u}let _=e.length,o=t(_,1)>>>0,g=v(),s=0;for(;s<_;s++){let b=e.charCodeAt(s);if(b>127)break;g[o+s]=b}if(s!==_){s!==0&&(e=e.slice(s)),o=n(o,_,_=s+e.length*3,1)>>>0;let b=v().subarray(o+s,o+_),u=D(e,b);s+=u.written}return y=s,o}function k(e){return e==null}var l=null;function i(){return(l===null||l.byteLength===0)&&(l=new Int32Array(r.memory.buffer)),l}var R=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&R.decode();function O(e,t){return e=e>>>0,R.decode(v().subarray(e,e+t))}function P(e,t){if(!(e instanceof t))throw new Error(`expected instance of ${t.name}`);return e.ptr}function N(e,t){try{return e.apply(this,t)}catch(n){r.__wbindgen_exn_store(a(n))}}var h=class e{static __wrap(t){t=t>>>0;let n=Object.create(e.prototype);return n.__wbg_ptr=t,n}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,t}free(){let t=this.__destroy_into_raw();r.__wbg_bbox_free(t)}get x(){return r.__wbg_get_bbox_x(this.__wbg_ptr)}set x(t){r.__wbg_set_bbox_x(this.__wbg_ptr,t)}get y(){return r.__wbg_get_bbox_y(this.__wbg_ptr)}set y(t){r.__wbg_set_bbox_y(this.__wbg_ptr,t)}get width(){return r.__wbg_get_bbox_width(this.__wbg_ptr)}set width(t){r.__wbg_set_bbox_width(this.__wbg_ptr,t)}get height(){return r.__wbg_get_bbox_height(this.__wbg_ptr)}set height(t){r.__wbg_set_bbox_height(this.__wbg_ptr,t)}},E=class e{static __wrap(t){t=t>>>0;let n=Object.create(e.prototype);return n.__wbg_ptr=t,n}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,t}free(){let t=this.__destroy_into_raw();r.__wbg_renderedimage_free(t)}get width(){return r.renderedimage_width(this.__wbg_ptr)>>>0}get height(){return r.renderedimage_height(this.__wbg_ptr)>>>0}asPng(){try{let o=r.__wbindgen_add_to_stack_pointer(-16);r.renderedimage_asPng(o,this.__wbg_ptr);var t=i()[o/4+0],n=i()[o/4+1],_=i()[o/4+2];if(_)throw f(n);return f(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}get pixels(){let t=r.renderedimage_pixels(this.__wbg_ptr);return f(t)}},A=class e{static __wrap(t){t=t>>>0;let n=Object.create(e.prototype);return n.__wbg_ptr=t,n}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,t}free(){let t=this.__destroy_into_raw();r.__wbg_resvg_free(t)}constructor(t,n,_){try{let m=r.__wbindgen_add_to_stack_pointer(-16);var o=k(n)?0:W(n,r.__wbindgen_malloc,r.__wbindgen_realloc),g=y;r.resvg_new(m,a(t),o,g,k(_)?0:a(_));var s=i()[m/4+0],b=i()[m/4+1],u=i()[m/4+2];if(u)throw f(b);return e.__wrap(s)}finally{r.__wbindgen_add_to_stack_pointer(16)}}get width(){return r.resvg_width(this.__wbg_ptr)}get height(){return r.resvg_height(this.__wbg_ptr)}render(){try{let o=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_render(o,this.__wbg_ptr);var t=i()[o/4+0],n=i()[o/4+1],_=i()[o/4+2];if(_)throw f(n);return E.__wrap(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}toString(){let t,n;try{let g=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_toString(g,this.__wbg_ptr);var _=i()[g/4+0],o=i()[g/4+1];return t=_,n=o,O(_,o)}finally{r.__wbindgen_add_to_stack_pointer(16),r.__wbindgen_free(t,n,1)}}innerBBox(){let t=r.resvg_innerBBox(this.__wbg_ptr);return t===0?void 0:h.__wrap(t)}getBBox(){let t=r.resvg_getBBox(this.__wbg_ptr);return t===0?void 0:h.__wrap(t)}cropByBBox(t){P(t,h),r.resvg_cropByBBox(this.__wbg_ptr,t.__wbg_ptr)}imagesToResolve(){try{let o=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_imagesToResolve(o,this.__wbg_ptr);var t=i()[o/4+0],n=i()[o/4+1],_=i()[o/4+2];if(_)throw f(n);return f(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}resolveImage(t,n){try{let g=r.__wbindgen_add_to_stack_pointer(-16),s=W(t,r.__wbindgen_malloc,r.__wbindgen_realloc),b=y;r.resvg_resolveImage(g,this.__wbg_ptr,s,b,a(n));var _=i()[g/4+0],o=i()[g/4+1];if(o)throw f(_)}finally{r.__wbindgen_add_to_stack_pointer(16)}}};async function q(e,t){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,t)}catch(_){if(e.headers.get("Content-Type")!="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",_);else throw _}let n=await e.arrayBuffer();return await WebAssembly.instantiate(n,t)}else{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}}function J(){let e={};return e.wbg={},e.wbg.__wbg_new_d258248ed531ff54=function(t,n){let _=new Error(O(t,n));return a(_)},e.wbg.__wbindgen_memory=function(){let t=r.memory;return a(t)},e.wbg.__wbg_buffer_085ec1f694018c4f=function(t){let n=c(t).buffer;return a(n)},e.wbg.__wbg_newwithbyteoffsetandlength_6da8e527659b86aa=function(t,n,_){let o=new Uint8Array(c(t),n>>>0,_>>>0);return a(o)},e.wbg.__wbindgen_object_drop_ref=function(t){f(t)},e.wbg.__wbg_new_8125e318e6245eed=function(t){let n=new Uint8Array(c(t));return a(n)},e.wbg.__wbg_values_e80af618f92c8649=function(t){let n=c(t).values();return a(n)},e.wbg.__wbg_next_ddb3312ca1c4e32a=function(){return N(function(t){let n=c(t).next();return a(n)},arguments)},e.wbg.__wbg_done_5c1f01fb660d73b5=function(t){return c(t).done},e.wbg.__wbg_value_1695675138684bd5=function(t){let n=c(t).value;return a(n)},e.wbg.__wbg_instanceof_Uint8Array_d8d9cb2b8e8ac1d4=function(t){let n;try{n=c(t)instanceof Uint8Array}catch{n=!1}return n},e.wbg.__wbindgen_string_get=function(t,n){let _=c(n),o=typeof _=="string"?_:void 0;var g=k(o)?0:W(o,r.__wbindgen_malloc,r.__wbindgen_realloc),s=y;i()[t/4+1]=s,i()[t/4+0]=g},e.wbg.__wbg_new_898a68150f225f2e=function(){let t=new Array;return a(t)},e.wbg.__wbindgen_string_new=function(t,n){let _=O(t,n);return a(_)},e.wbg.__wbg_push_ca1c26067ef907ac=function(t,n){return c(t).push(c(n))},e.wbg.__wbg_length_72e2208bbc0efc61=function(t){return c(t).length},e.wbg.__wbg_set_5cf90238115182c3=function(t,n,_){c(t).set(c(n),_>>>0)},e.wbg.__wbindgen_throw=function(t,n){throw new Error(O(t,n))},e}function H(e,t){return r=e.exports,T.__wbindgen_wasm_module=t,l=null,d=null,r}async function T(e){if(r!==void 0)return r;typeof e>"u"&&(e=new URL("index_bg.wasm",void 0));let t=J();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:_}=await q(await e,t);return H(n,_)}var S=T;var I=!1,V=async e=>{if(I)throw new Error("Already initialized. The `initWasm()` function can be used only once.");await S(await e),I=!0},$=class extends A{constructor(e,t){if(!I)throw new Error("Wasm has not been initialized. Call `initWasm()` function.");let n=t?.font;if(n&&G(n)){let _={...t,font:{...n,fontBuffers:void 0}};super(e,JSON.stringify(_),n.fontBuffers)}else super(e,JSON.stringify(t))}};function G(e){return Object.prototype.hasOwnProperty.call(e,"fontBuffers")}return L(K);})(); +"use strict";var resvg=(()=>{var B=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var n in t)B(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,_)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of U(t))!C.call(e,o)&&o!==n&&B(e,o,{get:()=>t[o],enumerable:!(_=j(t,o))||_.enumerable});return e};var L=e=>F(B({},"__esModule",{value:!0}),e);var K={};M(K,{Resvg:()=>$,initWasm:()=>V});var r,g=new Array(128).fill(void 0);g.push(void 0,null,!0,!1);var p=g.length;function c(e){p===g.length&&g.push(g.length+1);let t=p;return p=g[t],g[t]=e,t}function a(e){return g[e]}function z(e){e<132||(g[e]=p,p=e)}function f(e){let t=a(e);return z(e),t}var y=0,d=null;function v(){return(d===null||d.byteLength===0)&&(d=new Uint8Array(r.memory.buffer)),d}var x=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},D=typeof x.encodeInto=="function"?function(e,t){return x.encodeInto(e,t)}:function(e,t){let n=x.encode(e);return t.set(n),{read:e.length,written:n.length}};function W(e,t,n){if(n===void 0){let b=x.encode(e),u=t(b.length,1)>>>0;return v().subarray(u,u+b.length).set(b),y=b.length,u}let _=e.length,o=t(_,1)>>>0,w=v(),s=0;for(;s<_;s++){let b=e.charCodeAt(s);if(b>127)break;w[o+s]=b}if(s!==_){s!==0&&(e=e.slice(s)),o=n(o,_,_=s+e.length*3,1)>>>0;let b=v().subarray(o+s,o+_),u=D(e,b);s+=u.written}return y=s,o}function k(e){return e==null}var l=null;function i(){return(l===null||l.byteLength===0)&&(l=new Int32Array(r.memory.buffer)),l}var R=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&R.decode();function A(e,t){return e=e>>>0,R.decode(v().subarray(e,e+t))}function P(e,t){if(!(e instanceof t))throw new Error(`expected instance of ${t.name}`);return e.ptr}function N(e,t){try{return e.apply(this,t)}catch(n){r.__wbindgen_exn_store(c(n))}}var h=class e{static __wrap(t){t=t>>>0;let n=Object.create(e.prototype);return n.__wbg_ptr=t,n}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,t}free(){let t=this.__destroy_into_raw();r.__wbg_bbox_free(t)}get x(){return r.__wbg_get_bbox_x(this.__wbg_ptr)}set x(t){r.__wbg_set_bbox_x(this.__wbg_ptr,t)}get y(){return r.__wbg_get_bbox_y(this.__wbg_ptr)}set y(t){r.__wbg_set_bbox_y(this.__wbg_ptr,t)}get width(){return r.__wbg_get_bbox_width(this.__wbg_ptr)}set width(t){r.__wbg_set_bbox_width(this.__wbg_ptr,t)}get height(){return r.__wbg_get_bbox_height(this.__wbg_ptr)}set height(t){r.__wbg_set_bbox_height(this.__wbg_ptr,t)}},E=class e{static __wrap(t){t=t>>>0;let n=Object.create(e.prototype);return n.__wbg_ptr=t,n}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,t}free(){let t=this.__destroy_into_raw();r.__wbg_renderedimage_free(t)}get width(){return r.renderedimage_width(this.__wbg_ptr)>>>0}get height(){return r.renderedimage_height(this.__wbg_ptr)>>>0}asPng(){try{let o=r.__wbindgen_add_to_stack_pointer(-16);r.renderedimage_asPng(o,this.__wbg_ptr);var t=i()[o/4+0],n=i()[o/4+1],_=i()[o/4+2];if(_)throw f(n);return f(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}get pixels(){let t=r.renderedimage_pixels(this.__wbg_ptr);return f(t)}},O=class e{static __wrap(t){t=t>>>0;let n=Object.create(e.prototype);return n.__wbg_ptr=t,n}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,t}free(){let t=this.__destroy_into_raw();r.__wbg_resvg_free(t)}constructor(t,n,_){try{let m=r.__wbindgen_add_to_stack_pointer(-16);var o=k(n)?0:W(n,r.__wbindgen_malloc,r.__wbindgen_realloc),w=y;r.resvg_new(m,c(t),o,w,k(_)?0:c(_));var s=i()[m/4+0],b=i()[m/4+1],u=i()[m/4+2];if(u)throw f(b);return e.__wrap(s)}finally{r.__wbindgen_add_to_stack_pointer(16)}}get width(){return r.resvg_width(this.__wbg_ptr)}get height(){return r.resvg_height(this.__wbg_ptr)}render(){try{let o=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_render(o,this.__wbg_ptr);var t=i()[o/4+0],n=i()[o/4+1],_=i()[o/4+2];if(_)throw f(n);return E.__wrap(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}toString(){let t,n;try{let w=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_toString(w,this.__wbg_ptr);var _=i()[w/4+0],o=i()[w/4+1];return t=_,n=o,A(_,o)}finally{r.__wbindgen_add_to_stack_pointer(16),r.__wbindgen_free(t,n,1)}}innerBBox(){let t=r.resvg_innerBBox(this.__wbg_ptr);return t===0?void 0:h.__wrap(t)}getBBox(){let t=r.resvg_getBBox(this.__wbg_ptr);return t===0?void 0:h.__wrap(t)}cropByBBox(t){P(t,h),r.resvg_cropByBBox(this.__wbg_ptr,t.__wbg_ptr)}imagesToResolve(){try{let o=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_imagesToResolve(o,this.__wbg_ptr);var t=i()[o/4+0],n=i()[o/4+1],_=i()[o/4+2];if(_)throw f(n);return f(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}resolveImage(t,n){try{let w=r.__wbindgen_add_to_stack_pointer(-16),s=W(t,r.__wbindgen_malloc,r.__wbindgen_realloc),b=y;r.resvg_resolveImage(w,this.__wbg_ptr,s,b,c(n));var _=i()[w/4+0],o=i()[w/4+1];if(o)throw f(_)}finally{r.__wbindgen_add_to_stack_pointer(16)}}};async function q(e,t){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,t)}catch(_){if(e.headers.get("Content-Type")!="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",_);else throw _}let n=await e.arrayBuffer();return await WebAssembly.instantiate(n,t)}else{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}}function J(){let e={};return e.wbg={},e.wbg.__wbg_new_d258248ed531ff54=function(t,n){let _=new Error(A(t,n));return c(_)},e.wbg.__wbindgen_memory=function(){let t=r.memory;return c(t)},e.wbg.__wbg_buffer_085ec1f694018c4f=function(t){let n=a(t).buffer;return c(n)},e.wbg.__wbg_newwithbyteoffsetandlength_6da8e527659b86aa=function(t,n,_){let o=new Uint8Array(a(t),n>>>0,_>>>0);return c(o)},e.wbg.__wbindgen_object_drop_ref=function(t){f(t)},e.wbg.__wbg_new_8125e318e6245eed=function(t){let n=new Uint8Array(a(t));return c(n)},e.wbg.__wbg_newwithbyteoffsetandlength_a624c98280289b0f=function(t,n,_){let o=new Uint8ClampedArray(a(t),n>>>0,_>>>0);return c(o)},e.wbg.__wbg_new_e494528481cdbfa3=function(t){let n=new Uint8ClampedArray(a(t));return c(n)},e.wbg.__wbg_values_e80af618f92c8649=function(t){let n=a(t).values();return c(n)},e.wbg.__wbg_next_ddb3312ca1c4e32a=function(){return N(function(t){let n=a(t).next();return c(n)},arguments)},e.wbg.__wbg_done_5c1f01fb660d73b5=function(t){return a(t).done},e.wbg.__wbg_value_1695675138684bd5=function(t){let n=a(t).value;return c(n)},e.wbg.__wbg_instanceof_Uint8Array_d8d9cb2b8e8ac1d4=function(t){let n;try{n=a(t)instanceof Uint8Array}catch{n=!1}return n},e.wbg.__wbindgen_string_get=function(t,n){let _=a(n),o=typeof _=="string"?_:void 0;var w=k(o)?0:W(o,r.__wbindgen_malloc,r.__wbindgen_realloc),s=y;i()[t/4+1]=s,i()[t/4+0]=w},e.wbg.__wbg_new_898a68150f225f2e=function(){let t=new Array;return c(t)},e.wbg.__wbindgen_string_new=function(t,n){let _=A(t,n);return c(_)},e.wbg.__wbg_push_ca1c26067ef907ac=function(t,n){return a(t).push(a(n))},e.wbg.__wbg_length_72e2208bbc0efc61=function(t){return a(t).length},e.wbg.__wbg_set_5cf90238115182c3=function(t,n,_){a(t).set(a(n),_>>>0)},e.wbg.__wbindgen_throw=function(t,n){throw new Error(A(t,n))},e}function H(e,t){return r=e.exports,T.__wbindgen_wasm_module=t,l=null,d=null,r}async function T(e){if(r!==void 0)return r;typeof e>"u"&&(e=new URL("index_bg.wasm",void 0));let t=J();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:_}=await q(await e,t);return H(n,_)}var S=T;var I=!1,V=async e=>{if(I)throw new Error("Already initialized. The `initWasm()` function can be used only once.");await S(await e),I=!0},$=class extends O{constructor(e,t){if(!I)throw new Error("Wasm has not been initialized. Call `initWasm()` function.");let n=t?.font;if(n&&G(n)){let _={...t,font:{...n,fontBuffers:void 0}};super(e,JSON.stringify(_),n.fontBuffers)}else super(e,JSON.stringify(t))}};function G(e){return Object.prototype.hasOwnProperty.call(e,"fontBuffers")}return L(K);})(); diff --git a/wasm/index.mjs b/wasm/index.mjs index e0281ba5..a6d948ae 100644 --- a/wasm/index.mjs +++ b/wasm/index.mjs @@ -231,7 +231,7 @@ var RenderedImage = class _RenderedImage { } /** * Get the RGBA pixels of the image - * @returns {Uint8Array} + * @returns {Uint8ClampedArray} */ get pixels() { const ret = wasm.renderedimage_pixels(this.__wbg_ptr); @@ -448,6 +448,14 @@ function __wbg_get_imports() { const ret = new Uint8Array(getObject(arg0)); return addHeapObject(ret); }; + imports.wbg.__wbg_newwithbyteoffsetandlength_a624c98280289b0f = function(arg0, arg1, arg2) { + const ret = new Uint8ClampedArray(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_new_e494528481cdbfa3 = function(arg0) { + const ret = new Uint8ClampedArray(getObject(arg0)); + return addHeapObject(ret); + }; imports.wbg.__wbg_values_e80af618f92c8649 = function(arg0) { const ret = getObject(arg0).values(); return addHeapObject(ret); diff --git a/wasm/index_bg.wasm b/wasm/index_bg.wasm index adbeb7cc..1eb316df 100644 Binary files a/wasm/index_bg.wasm and b/wasm/index_bg.wasm differ diff --git a/yarn.lock b/yarn.lock index dc8c5975..ad9be26f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -247,12 +247,12 @@ __metadata: languageName: node linkType: hard -"@napi-rs/cli@npm:^2.16.3": - version: 2.16.3 - resolution: "@napi-rs/cli@npm:2.16.3" +"@napi-rs/cli@npm:2.18.0": + version: 2.18.0 + resolution: "@napi-rs/cli@npm:2.18.0" bin: napi: scripts/index.js - checksum: 11f78b09548bc5c22df56e4fab4a87b68c2d3f2a18a55cf11e775e6a4cb5739ec0e21a14e614db2cdc2b9773cb42536c6bd00c3f85d3b461f956594f8a89ddcb + checksum: eadff1dda564416b66db44f5ea7088712f8cf66f6677082197e6d3ce5a57d9eabeb0d091b4d1685e8a4bd275ff1de684fca1ae84edd0f66dac82cb328acc068c languageName: node linkType: hard @@ -307,7 +307,7 @@ __metadata: version: 0.0.0-use.local resolution: "@resvg/resvg-js@workspace:." dependencies: - "@napi-rs/cli": ^2.16.3 + "@napi-rs/cli": 2.18.0 "@swc-node/register": 1.6.4 "@swc/core": ^1.3.88 "@types/node": ^20.6.5