diff --git a/example/image-url.js b/example/image-url.js index e25ee43b..e3a78179 100644 --- a/example/image-url.js +++ b/example/image-url.js @@ -1,6 +1,5 @@ const { promises } = require('fs') const { join } = require('path') -// const { performance } = require('perf_hooks') const fetch = require('node-fetch') @@ -14,8 +13,8 @@ async function main() { }, logLevel: 'off', } - const resvg = new Resvg(svg, opts) + const resolved = await Promise.all( resvg.imagesToResolve().map(async (url) => { console.info('image url', url) @@ -23,15 +22,15 @@ async function main() { const buffer = await img.arrayBuffer() return { url, - mime: 'image/png', buffer: Buffer.from(buffer), } }), ) - - for (const result of resolved) { - const { url, mime, buffer } = result - resvg.resolveImage(url, mime, buffer) + if (resolved.length > 0) { + for (const result of resolved) { + const { url, buffer } = result + resvg.resolveImage(url, buffer) + } } const pngData = resvg.render() diff --git a/example/url-out.png b/example/url-out.png index 09833941..4559d204 100644 Binary files a/example/url-out.png and b/example/url-out.png differ diff --git a/example/url.svg b/example/url.svg index bb47da15..9a900dc2 100644 --- a/example/url.svg +++ b/example/url.svg @@ -1,3 +1,4 @@ - - + + + diff --git a/index.d.ts b/index.d.ts index ad7c819e..1b5292cf 100755 --- a/index.d.ts +++ b/index.d.ts @@ -74,6 +74,9 @@ export class Resvg { */ cropByBBox(bbox: BBox): void + imagesToResolve(): Array + resolveImage(href: string, buffer: Buffer): void + /** Get the SVG width */ get width(): number diff --git a/js-binding.d.ts b/js-binding.d.ts index 992a5dad..1e21cb98 100644 --- a/js-binding.d.ts +++ b/js-binding.d.ts @@ -33,6 +33,8 @@ export class Resvg { * the viewbox/size of the svg and do not move the elements for simplicity */ cropByBBox(bbox: BBox): void + imagesToResolve(): Array + resolveImage(href: string, buffer: Buffer): void /** Get the SVG width */ get width(): number /** Get the SVG height */ diff --git a/src/lib.rs b/src/lib.rs index 3e471978..0b9a1b15 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -369,12 +369,14 @@ impl Resvg { } } + #[wasm_bindgen(js_name = imagesToResolve)] pub fn images_to_resolve(&self) -> Result { let images = self.images_to_resolve_inner()?; let result = js_sys::Array::from_iter(images.into_iter().map(|s| JsValue::from(s))); Ok(result) } + #[wasm_bindgen(js_name = resolveImage)] pub fn resolve_image( &self, href: String, @@ -624,6 +626,7 @@ pub struct AsyncRenderer { } #[cfg(not(target_arch = "wasm32"))] +#[napi] impl Task for AsyncRenderer { type Output = RenderedImage; type JsValue = RenderedImage; diff --git a/wasm/index.d.ts b/wasm/index.d.ts index 6835d8f6..37bb23fc 100644 --- a/wasm/index.d.ts +++ b/wasm/index.d.ts @@ -35,18 +35,6 @@ declare class RenderedImage { } export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; export type ResvgRenderOptions = { - font?: { - loadSystemFonts?: boolean; - fontFiles?: string[]; - fontDirs?: string[]; - defaultFontFamily?: string; - defaultFontSize?: number; - serifFamily?: string; - sansSerifFamily?: string; - cursiveFamily?: string; - fantasyFamily?: string; - monospaceFamily?: string; - }; dpi?: number; languages?: string[]; shapeRendering?: 0 // optimizeSpeed @@ -76,7 +64,6 @@ export type ResvgRenderOptions = { right?: number; bottom?: number; }; - logLevel?: "off" | "error" | "warn" | "info" | "debug" | "trace"; }; /** * Initialize Wasm module @@ -92,11 +79,9 @@ export declare const Resvg: { innerBBox(): BBox | undefined; getBBox(): BBox | undefined; cropByBBox(bbox: BBox): void; - images_to_resolve(): string[]; - resolve_image(href: string, buffer: Uint8Array): void; + imagesToResolve(): Array; + resolveImage(href: string, buffer: Uint8Array): void; readonly height: number; readonly width: number; }; }; - -export {}; diff --git a/wasm/index.html b/wasm/index.html index a16dd458..9de34c52 100644 --- a/wasm/index.html +++ b/wasm/index.html @@ -162,16 +162,10 @@ const output = document.getElementById('output') const svgElement = document.querySelector('#input-svg') const inputSVG = svgElement.value.trim() - let resvgOpts = { - // fitTo: { - // mode: 'width', - // value: 500, - // } - } - - svg2png(inputSVG, resvgOpts) + let resvgOpts = {} + await svg2png(inputSVG, resvgOpts) - function svg2png(svgString, opts, hasCrop) { + async function svg2png(svgString, opts, hasCrop) { const svg = svgString ? svgString : svgElement.value.trim() if (!svg) { @@ -181,6 +175,25 @@ const resvgJS = new resvg.Resvg(svg, opts) document.querySelector('#svg-info').textContent = 'Original SVG size: ' + resvgJS.width + ' x ' + resvgJS.height + ' px' + const resolved = await Promise.all( + resvgJS.imagesToResolve().map(async (url) => { + console.log('image url', url) + const img = await fetch(url) + const buffer = await img.arrayBuffer() + // const MIME = img.headers.get('Content-Type') + return { + url, + buffer: new Uint8Array(buffer), + } + }), + ) + if (resolved.length > 0) { + for (const result of resolved) { + const { url, buffer } = result + resvgJS.resolveImage(url, buffer) + } + } + const innerBBox = resvgJS.innerBBox() const bbox = resvgJS.getBBox() console.log('SVG innerBBox', innerBBox) diff --git a/wasm/index.js b/wasm/index.js index 31cede45..e3314785 100644 --- a/wasm/index.js +++ b/wasm/index.js @@ -2,19 +2,24 @@ var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; +var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); +var __reExport = (target, module2, copyDefault, desc) => { + if (module2 && typeof module2 === "object" || typeof module2 === "function") { + for (let key of __getOwnPropNames(module2)) + if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default")) + __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); } - return to; + return target; }; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); +var __toCommonJS = /* @__PURE__ */ ((cache) => { + return (module2, temp) => { + return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp); + }; +})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0); // wasm-binding.ts var wasm_binding_exports = {}; @@ -22,7 +27,6 @@ __export(wasm_binding_exports, { Resvg: () => Resvg2, initWasm: () => initWasm }); -module.exports = __toCommonJS(wasm_binding_exports); // wasm/dist/index.js var wasm; @@ -283,10 +287,10 @@ var Resvg = class { _assertClass(bbox, BBox); wasm.resvg_cropByBBox(this.ptr, bbox.ptr); } - images_to_resolve() { + imagesToResolve() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.resvg_images_to_resolve(retptr, this.ptr); + wasm.resvg_imagesToResolve(retptr, this.ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -298,12 +302,12 @@ var Resvg = class { wasm.__wbindgen_add_to_stack_pointer(16); } } - resolve_image(href, buffer) { + resolveImage(href, buffer) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passStringToWasm0(href, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; - wasm.resvg_resolve_image(retptr, this.ptr, ptr0, len0, addHeapObject(buffer)); + wasm.resvg_resolveImage(retptr, this.ptr, ptr0, len0, addHeapObject(buffer)); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; if (r1) { @@ -427,3 +431,4 @@ var Resvg2 = class extends Resvg { super(svg, JSON.stringify(options)); } }; +module.exports = __toCommonJS(wasm_binding_exports); diff --git a/wasm/index.min.js b/wasm/index.min.js index 5b709a9c..a8d40ddc 100644 --- a/wasm/index.min.js +++ b/wasm/index.min.js @@ -1 +1 @@ -var resvg=(()=>{var W=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var i in t)W(e,i,{get:t[i],enumerable:!0})},L=(e,t,i,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of M(t))!T.call(e,n)&&n!==i&&W(e,n,{get:()=>t[n],enumerable:!(o=S(t,n))||o.enumerable});return e};var P=e=>L(W({},"__esModule",{value:!0}),e);var J={};C(J,{Resvg:()=>H,initWasm:()=>D});var r,w=new Array(32).fill(void 0);w.push(void 0,null,!0,!1);var h=w.length;function g(e){h===w.length&&w.push(w.length+1);let t=h;return h=w[t],w[t]=e,t}function b(e){return w[e]}function z(e){e<36||(w[e]=h,h=e)}function u(e){let t=b(e);return z(e),t}var l=0,m=null;function x(){return(m===null||m.buffer!==r.memory.buffer)&&(m=new Uint8Array(r.memory.buffer)),m}var A=new TextEncoder("utf-8"),F=typeof A.encodeInto=="function"?function(e,t){return A.encodeInto(e,t)}:function(e,t){let i=A.encode(e);return t.set(i),{read:e.length,written:i.length}};function O(e,t,i){if(i===void 0){let a=A.encode(e),f=t(a.length);return x().subarray(f,f+a.length).set(a),l=a.length,f}let o=e.length,n=t(o),_=x(),s=0;for(;s127)break;_[n+s]=a}if(s!==o){s!==0&&(e=e.slice(s)),n=i(n,o,o=s+e.length*3);let a=x().subarray(n+s,n+o);s+=F(e,a).written}return l=s,n}function B(e){return e==null}var v=null;function c(){return(v===null||v.buffer!==r.memory.buffer)&&(v=new Int32Array(r.memory.buffer)),v}var I=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});I.decode();function k(e,t){return I.decode(x().subarray(e,e+t))}function N(e,t){if(!(e instanceof t))throw new Error(`expected instance of ${t.name}`);return e.ptr}var d=class{static __wrap(t){let i=Object.create(d.prototype);return i.ptr=t,i}__destroy_into_raw(){let t=this.ptr;return this.ptr=0,t}free(){let t=this.__destroy_into_raw();r.__wbg_bbox_free(t)}get x(){return r.__wbg_get_bbox_x(this.ptr)}set x(t){r.__wbg_set_bbox_x(this.ptr,t)}get y(){return r.__wbg_get_bbox_y(this.ptr)}set y(t){r.__wbg_set_bbox_y(this.ptr,t)}get width(){return r.__wbg_get_bbox_width(this.ptr)}set width(t){r.__wbg_set_bbox_width(this.ptr,t)}get height(){return r.__wbg_get_bbox_height(this.ptr)}set height(t){r.__wbg_set_bbox_height(this.ptr,t)}},y=class{static __wrap(t){let i=Object.create(y.prototype);return i.ptr=t,i}__destroy_into_raw(){let t=this.ptr;return this.ptr=0,t}free(){let t=this.__destroy_into_raw();r.__wbg_renderedimage_free(t)}get width(){return r.renderedimage_width(this.ptr)>>>0}get height(){return r.renderedimage_height(this.ptr)>>>0}asPng(){try{let n=r.__wbindgen_add_to_stack_pointer(-16);r.renderedimage_asPng(n,this.ptr);var t=c()[n/4+0],i=c()[n/4+1],o=c()[n/4+2];if(o)throw u(i);return u(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}},p=class{static __wrap(t){let i=Object.create(p.prototype);return i.ptr=t,i}__destroy_into_raw(){let t=this.ptr;return this.ptr=0,t}free(){let t=this.__destroy_into_raw();r.__wbg_resvg_free(t)}constructor(t,i){try{let f=r.__wbindgen_add_to_stack_pointer(-16);var o=B(i)?0:O(i,r.__wbindgen_malloc,r.__wbindgen_realloc),n=l;r.resvg_new(f,g(t),o,n);var _=c()[f/4+0],s=c()[f/4+1],a=c()[f/4+2];if(a)throw u(s);return p.__wrap(_)}finally{r.__wbindgen_add_to_stack_pointer(16)}}get width(){return r.resvg_width(this.ptr)}get height(){return r.resvg_height(this.ptr)}render(){try{let n=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_render(n,this.ptr);var t=c()[n/4+0],i=c()[n/4+1],o=c()[n/4+2];if(o)throw u(i);return y.__wrap(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}toString(){try{let o=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_toString(o,this.ptr);var t=c()[o/4+0],i=c()[o/4+1];return k(t,i)}finally{r.__wbindgen_add_to_stack_pointer(16),r.__wbindgen_free(t,i)}}innerBBox(){let t=r.resvg_innerBBox(this.ptr);return t===0?void 0:d.__wrap(t)}getBBox(){let t=r.resvg_getBBox(this.ptr);return t===0?void 0:d.__wrap(t)}cropByBBox(t){N(t,d),r.resvg_cropByBBox(this.ptr,t.ptr)}images_to_resolve(){try{let n=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_images_to_resolve(n,this.ptr);var t=c()[n/4+0],i=c()[n/4+1],o=c()[n/4+2];if(o)throw u(i);return u(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}resolve_image(t,i){try{let _=r.__wbindgen_add_to_stack_pointer(-16),s=O(t,r.__wbindgen_malloc,r.__wbindgen_realloc),a=l;r.resvg_resolve_image(_,this.ptr,s,a,g(i));var o=c()[_/4+0],n=c()[_/4+1];if(n)throw u(o)}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(o){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",o);else throw o}let i=await e.arrayBuffer();return await WebAssembly.instantiate(i,t)}else{let i=await WebAssembly.instantiate(e,t);return i instanceof WebAssembly.Instance?{instance:i,module:e}:i}}async function U(e){typeof e=="undefined"&&(e=new URL("index_bg.wasm",void 0));let t={};t.wbg={},t.wbg.__wbg_new_3047bf4b4f02b802=function(n,_){let s=new Error(k(n,_));return g(s)},t.wbg.__wbindgen_memory=function(){let n=r.memory;return g(n)},t.wbg.__wbg_buffer_7af23f65f6c64548=function(n){let _=b(n).buffer;return g(_)},t.wbg.__wbg_newwithbyteoffsetandlength_ce1e75f0ce5f7974=function(n,_,s){let a=new Uint8Array(b(n),_>>>0,s>>>0);return g(a)},t.wbg.__wbindgen_object_drop_ref=function(n){u(n)},t.wbg.__wbg_new_cc9018bd6f283b6f=function(n){let _=new Uint8Array(b(n));return g(_)},t.wbg.__wbg_instanceof_Uint8Array_edb92795fc0c63b4=function(n){return b(n)instanceof Uint8Array},t.wbg.__wbindgen_string_get=function(n,_){let s=b(_),a=typeof s=="string"?s:void 0;var f=B(a)?0:O(a,r.__wbindgen_malloc,r.__wbindgen_realloc),R=l;c()[n/4+1]=R,c()[n/4+0]=f},t.wbg.__wbg_new_94fb1279cf6afea5=function(){let n=new Array;return g(n)},t.wbg.__wbindgen_string_new=function(n,_){let s=k(n,_);return g(s)},t.wbg.__wbg_push_40c6a90f1805aa90=function(n,_){return b(n).push(b(_))},t.wbg.__wbg_length_0acb1cf9bbaf8519=function(n){return b(n).length},t.wbg.__wbg_set_f25e869e4565d2a2=function(n,_,s){b(n).set(b(_),s>>>0)},t.wbg.__wbindgen_throw=function(n,_){throw new Error(k(n,_))},(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:i,module:o}=await q(await e,t);return r=i.exports,U.__wbindgen_wasm_module=o,r}var E=U;var j=!1,D=async e=>{if(j)throw new Error("Already initialized. The `initWasm()` function can be used only once.");await E(await e),j=!0},H=class extends p{constructor(e,t){if(!j)throw new Error("Wasm has not been initialized. Call `initWasm()` function.");super(e,JSON.stringify(t))}};return P(J);})(); +var resvg=(()=>{var B=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var C=e=>B(e,"__esModule",{value:!0});var L=(e,t)=>{for(var i in t)B(e,i,{get:t[i],enumerable:!0})},P=(e,t,i,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of T(t))!M.call(e,n)&&(i||n!=="default")&&B(e,n,{get:()=>t[n],enumerable:!(o=S(t,n))||o.enumerable});return e};var z=(e=>(t,i)=>e&&e.get(t)||(i=P(C({}),t,1),e&&e.set(t,i),i))(typeof WeakMap!="undefined"?new WeakMap:0);var V={};L(V,{Resvg:()=>J,initWasm:()=>H});var r,w=new Array(32).fill(void 0);w.push(void 0,null,!0,!1);var h=w.length;function b(e){h===w.length&&w.push(w.length+1);let t=h;return h=w[t],w[t]=e,t}function g(e){return w[e]}function F(e){e<36||(w[e]=h,h=e)}function u(e){let t=g(e);return F(e),t}var l=0,y=null;function v(){return(y===null||y.buffer!==r.memory.buffer)&&(y=new Uint8Array(r.memory.buffer)),y}var x=new TextEncoder("utf-8"),N=typeof x.encodeInto=="function"?function(e,t){return x.encodeInto(e,t)}:function(e,t){let i=x.encode(e);return t.set(i),{read:e.length,written:i.length}};function I(e,t,i){if(i===void 0){let a=x.encode(e),f=t(a.length);return v().subarray(f,f+a.length).set(a),l=a.length,f}let o=e.length,n=t(o),_=v(),s=0;for(;s127)break;_[n+s]=a}if(s!==o){s!==0&&(e=e.slice(s)),n=i(n,o,o=s+e.length*3);let a=v().subarray(n+s,n+o);s+=N(e,a).written}return l=s,n}function W(e){return e==null}var m=null;function c(){return(m===null||m.buffer!==r.memory.buffer)&&(m=new Int32Array(r.memory.buffer)),m}var O=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});O.decode();function A(e,t){return O.decode(v().subarray(e,e+t))}function q(e,t){if(!(e instanceof t))throw new Error(`expected instance of ${t.name}`);return e.ptr}var d=class{static __wrap(t){let i=Object.create(d.prototype);return i.ptr=t,i}__destroy_into_raw(){let t=this.ptr;return this.ptr=0,t}free(){let t=this.__destroy_into_raw();r.__wbg_bbox_free(t)}get x(){return r.__wbg_get_bbox_x(this.ptr)}set x(t){r.__wbg_set_bbox_x(this.ptr,t)}get y(){return r.__wbg_get_bbox_y(this.ptr)}set y(t){r.__wbg_set_bbox_y(this.ptr,t)}get width(){return r.__wbg_get_bbox_width(this.ptr)}set width(t){r.__wbg_set_bbox_width(this.ptr,t)}get height(){return r.__wbg_get_bbox_height(this.ptr)}set height(t){r.__wbg_set_bbox_height(this.ptr,t)}},k=class{static __wrap(t){let i=Object.create(k.prototype);return i.ptr=t,i}__destroy_into_raw(){let t=this.ptr;return this.ptr=0,t}free(){let t=this.__destroy_into_raw();r.__wbg_renderedimage_free(t)}get width(){return r.renderedimage_width(this.ptr)>>>0}get height(){return r.renderedimage_height(this.ptr)>>>0}asPng(){try{let n=r.__wbindgen_add_to_stack_pointer(-16);r.renderedimage_asPng(n,this.ptr);var t=c()[n/4+0],i=c()[n/4+1],o=c()[n/4+2];if(o)throw u(i);return u(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}},p=class{static __wrap(t){let i=Object.create(p.prototype);return i.ptr=t,i}__destroy_into_raw(){let t=this.ptr;return this.ptr=0,t}free(){let t=this.__destroy_into_raw();r.__wbg_resvg_free(t)}constructor(t,i){try{let f=r.__wbindgen_add_to_stack_pointer(-16);var o=W(i)?0:I(i,r.__wbindgen_malloc,r.__wbindgen_realloc),n=l;r.resvg_new(f,b(t),o,n);var _=c()[f/4+0],s=c()[f/4+1],a=c()[f/4+2];if(a)throw u(s);return p.__wrap(_)}finally{r.__wbindgen_add_to_stack_pointer(16)}}get width(){return r.resvg_width(this.ptr)}get height(){return r.resvg_height(this.ptr)}render(){try{let n=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_render(n,this.ptr);var t=c()[n/4+0],i=c()[n/4+1],o=c()[n/4+2];if(o)throw u(i);return k.__wrap(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}toString(){try{let o=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_toString(o,this.ptr);var t=c()[o/4+0],i=c()[o/4+1];return A(t,i)}finally{r.__wbindgen_add_to_stack_pointer(16),r.__wbindgen_free(t,i)}}innerBBox(){let t=r.resvg_innerBBox(this.ptr);return t===0?void 0:d.__wrap(t)}getBBox(){let t=r.resvg_getBBox(this.ptr);return t===0?void 0:d.__wrap(t)}cropByBBox(t){q(t,d),r.resvg_cropByBBox(this.ptr,t.ptr)}imagesToResolve(){try{let n=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_imagesToResolve(n,this.ptr);var t=c()[n/4+0],i=c()[n/4+1],o=c()[n/4+2];if(o)throw u(i);return u(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}resolveImage(t,i){try{let _=r.__wbindgen_add_to_stack_pointer(-16),s=I(t,r.__wbindgen_malloc,r.__wbindgen_realloc),a=l;r.resvg_resolveImage(_,this.ptr,s,a,b(i));var o=c()[_/4+0],n=c()[_/4+1];if(n)throw u(o)}finally{r.__wbindgen_add_to_stack_pointer(16)}}};async function D(e,t){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,t)}catch(o){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",o);else throw o}let i=await e.arrayBuffer();return await WebAssembly.instantiate(i,t)}else{let i=await WebAssembly.instantiate(e,t);return i instanceof WebAssembly.Instance?{instance:i,module:e}:i}}async function j(e){typeof e=="undefined"&&(e=new URL("index_bg.wasm",void 0));let t={};t.wbg={},t.wbg.__wbg_new_3047bf4b4f02b802=function(n,_){let s=new Error(A(n,_));return b(s)},t.wbg.__wbindgen_memory=function(){let n=r.memory;return b(n)},t.wbg.__wbg_buffer_7af23f65f6c64548=function(n){let _=g(n).buffer;return b(_)},t.wbg.__wbg_newwithbyteoffsetandlength_ce1e75f0ce5f7974=function(n,_,s){let a=new Uint8Array(g(n),_>>>0,s>>>0);return b(a)},t.wbg.__wbindgen_object_drop_ref=function(n){u(n)},t.wbg.__wbg_new_cc9018bd6f283b6f=function(n){let _=new Uint8Array(g(n));return b(_)},t.wbg.__wbg_instanceof_Uint8Array_edb92795fc0c63b4=function(n){return g(n)instanceof Uint8Array},t.wbg.__wbindgen_string_get=function(n,_){let s=g(_),a=typeof s=="string"?s:void 0;var f=W(a)?0:I(a,r.__wbindgen_malloc,r.__wbindgen_realloc),E=l;c()[n/4+1]=E,c()[n/4+0]=f},t.wbg.__wbg_new_94fb1279cf6afea5=function(){let n=new Array;return b(n)},t.wbg.__wbindgen_string_new=function(n,_){let s=A(n,_);return b(s)},t.wbg.__wbg_push_40c6a90f1805aa90=function(n,_){return g(n).push(g(_))},t.wbg.__wbg_length_0acb1cf9bbaf8519=function(n){return g(n).length},t.wbg.__wbg_set_f25e869e4565d2a2=function(n,_,s){g(n).set(g(_),s>>>0)},t.wbg.__wbindgen_throw=function(n,_){throw new Error(A(n,_))},(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:i,module:o}=await D(await e,t);return r=i.exports,j.__wbindgen_wasm_module=o,r}var U=j;var R=!1,H=async e=>{if(R)throw new Error("Already initialized. The `initWasm()` function can be used only once.");await U(await e),R=!0},J=class extends p{constructor(e,t){if(!R)throw new Error("Wasm has not been initialized. Call `initWasm()` function.");super(e,JSON.stringify(t))}};return z(V);})(); diff --git a/wasm/index.mjs b/wasm/index.mjs index 4b10fbd3..0c568f3c 100644 --- a/wasm/index.mjs +++ b/wasm/index.mjs @@ -257,10 +257,10 @@ var Resvg = class { _assertClass(bbox, BBox); wasm.resvg_cropByBBox(this.ptr, bbox.ptr); } - images_to_resolve() { + imagesToResolve() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.resvg_images_to_resolve(retptr, this.ptr); + wasm.resvg_imagesToResolve(retptr, this.ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -272,12 +272,12 @@ var Resvg = class { wasm.__wbindgen_add_to_stack_pointer(16); } } - resolve_image(href, buffer) { + resolveImage(href, buffer) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passStringToWasm0(href, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; - wasm.resvg_resolve_image(retptr, this.ptr, ptr0, len0, addHeapObject(buffer)); + wasm.resvg_resolveImage(retptr, this.ptr, ptr0, len0, addHeapObject(buffer)); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; if (r1) { diff --git a/wasm/index_bg.wasm b/wasm/index_bg.wasm index 6485c55c..1a7b9925 100644 Binary files a/wasm/index_bg.wasm and b/wasm/index_bg.wasm differ