From 093b8393f87601acbd549654317eb63c74851c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=9D?= Date: Tue, 5 Sep 2023 18:58:00 +0800 Subject: [PATCH] refactor(wasm): change the `fontsBuffers` option to `fontBuffers` --- __test__/wasm.spec.ts | 16 ++++++++-------- js-binding.js | 2 +- src/fonts.rs | 14 +++++++------- wasm-binding.ts | 6 +++--- wasm/index.d.ts | 2 +- wasm/index.js | 24 ++++++++++++------------ wasm/index.min.js | 2 +- wasm/index.mjs | 24 ++++++++++++------------ 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/__test__/wasm.spec.ts b/__test__/wasm.spec.ts index 7bf08ee4..362b586f 100755 --- a/__test__/wasm.spec.ts +++ b/__test__/wasm.spec.ts @@ -206,13 +206,13 @@ test('Set the background without alpha by hsla()', async (t) => { t.is(result.hasAlpha(), false) }) -test('Load custom font(use fontsBuffers option)', async (t) => { +test('Load custom font(use fontBuffers option)', async (t) => { const filePath = '../example/text.svg' const svg = await fs.readFile(join(__dirname, filePath)) const fontBuffer = await fs.readFile(join(__dirname, '../example/SourceHanSerifCN-Light-subset.ttf')) const resvg = new Resvg(svg.toString('utf-8'), { font: { - fontsBuffers: [fontBuffer], // Load custom fonts. + fontBuffers: [fontBuffer], // Load custom fonts. }, }) const pngBuffer = resvg.render().asPng() @@ -233,7 +233,7 @@ test('should be load custom font(no defaultFontFamily option)', async (t) => { const fontBuffer = await fs.readFile(join(__dirname, '../example/SourceHanSerifCN-Light-subset.ttf')) const resvg = new Resvg(svg, { font: { - fontsBuffers: [fontBuffer], + fontBuffers: [fontBuffer], // defaultFontFamily: 'Source Han Serif CN Light', }, }) @@ -244,7 +244,7 @@ test('should be load custom font(no defaultFontFamily option)', async (t) => { t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1726) }) -test('should be load custom fontsBuffers(no defaultFontFamily option)', async (t) => { +test('should be load custom fontBuffers(no defaultFontFamily option)', async (t) => { const svg = ` @@ -255,7 +255,7 @@ test('should be load custom fontsBuffers(no defaultFontFamily option)', async (t const fontBuffer = await fs.readFile(join(__dirname, '../example/SourceHanSerifCN-Light-subset.ttf')) const resvg = new Resvg(svg, { font: { - fontsBuffers: [fontBuffer], + fontBuffers: [fontBuffer], }, }) const pngData = resvg.render() @@ -265,7 +265,7 @@ test('should be load custom fontsBuffers(no defaultFontFamily option)', async (t t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1726) }) -test('should be load custom multiple fontsBuffers', async (t) => { +test('should be load custom multiple fontBuffers', async (t) => { const svg = ` @@ -278,7 +278,7 @@ test('should be load custom multiple fontsBuffers', async (t) => { const pacificoBuffer = await fs.readFile(join(__dirname, './Pacifico-Regular.ttf')) const resvg = new Resvg(svg, { font: { - fontsBuffers: [pacificoBuffer, fontBuffer], + fontBuffers: [pacificoBuffer, fontBuffer], defaultFontFamily: ' Pacifico ', // Multiple spaces }, }) @@ -421,7 +421,7 @@ test('should render using font buffer provided by options', async (t) => { const options = { font: { - fontsBuffers: [pacificoBuffer], + fontBuffers: [pacificoBuffer], defaultFontFamily: 'non-existent-font-family', }, } diff --git a/js-binding.js b/js-binding.js index 221d088b..156f0686 100644 --- a/js-binding.js +++ b/js-binding.js @@ -17,7 +17,7 @@ function isMusl() { // For Node 10 if (!process.report || typeof process.report.getReport !== 'function') { try { - const lddPath = require('child_process').execSync('which ldd').toString().trim(); + const lddPath = require('child_process').execSync('which ldd').toString().trim() return readFileSync(lddPath, 'utf8').includes('musl') } catch (e) { return true diff --git a/src/fonts.rs b/src/fonts.rs index ecfe140d..90c71c36 100644 --- a/src/fonts.rs +++ b/src/fonts.rs @@ -55,18 +55,18 @@ pub fn load_fonts(font_options: &JsFontOptions) -> Database { #[cfg(target_arch = "wasm32")] pub fn load_wasm_fonts( font_options: &JsFontOptions, - fonts_buffers: Option, + font_buffers: Option, fontdb: &mut Database, ) -> Result<(), js_sys::Error> { - if let Some(ref fonts_buffers) = fonts_buffers { - for font in fonts_buffers.values().into_iter() { + if let Some(ref font_buffers) = font_buffers { + for font in font_buffers.values().into_iter() { let raw_font = font?; let font_data = raw_font.dyn_into::()?.to_vec(); fontdb.load_font_data(font_data); } } - set_wasm_font_families(font_options, fontdb, fonts_buffers); + set_wasm_font_families(font_options, fontdb, font_buffers); Ok(()) } @@ -120,7 +120,7 @@ fn set_font_families(font_options: &JsFontOptions, fontdb: &mut Database) { fn set_wasm_font_families( font_options: &JsFontOptions, fontdb: &mut Database, - fonts_buffers: Option, + font_buffers: Option, ) { let mut default_font_family = font_options.default_font_family.clone().trim().to_string(); @@ -138,8 +138,8 @@ fn set_wasm_font_families( // 当 default_font_family 为空或系统无该字体时,尝试把 fontdb // 中字体列表的第一个字体设置为默认的字体。 if default_font_family.is_empty() || fontdb_found_default_font_family.is_empty() { - // fonts_buffers 选项不为空时, 从已加载的字体列表中获取第一个字体的 font family。 - if let Some(_fonts_buffers) = fonts_buffers { + // font_buffers 选项不为空时, 从已加载的字体列表中获取第一个字体的 font family。 + if let Some(_font_buffers) = font_buffers { default_font_family = get_first_font_family_or_fallback(fontdb); } } diff --git a/wasm-binding.ts b/wasm-binding.ts index 1df6e26f..c9f08967 100644 --- a/wasm-binding.ts +++ b/wasm-binding.ts @@ -31,11 +31,11 @@ export const Resvg = class extends _Resvg { ...options, font: { ...font, - fontsBuffers: undefined, + fontBuffers: undefined, }, } - super(svg, JSON.stringify(serializableOptions), font.fontsBuffers) + super(svg, JSON.stringify(serializableOptions), font.fontBuffers) } else { super(svg, JSON.stringify(options)) } @@ -43,5 +43,5 @@ export const Resvg = class extends _Resvg { } function isCustomFontsOptions(value: SystemFontsOptions | CustomFontsOptions): value is CustomFontsOptions { - return Object.prototype.hasOwnProperty.call(value, 'fontsBuffers') + return Object.prototype.hasOwnProperty.call(value, 'fontBuffers') } diff --git a/wasm/index.d.ts b/wasm/index.d.ts index 746da4ce..77a4f5d8 100644 --- a/wasm/index.d.ts +++ b/wasm/index.d.ts @@ -78,7 +78,7 @@ export type FontOptions = { monospaceFamily?: string; }; export type CustomFontsOptions = { - fontsBuffers: Uint8Array[]; // A list of raw font files to load. + fontBuffers: Uint8Array[]; // A list of raw font buffers to load. } & FontOptions; export type SystemFontsOptions = { loadSystemFonts?: boolean; // Default: true. if set to false, it will be faster. diff --git a/wasm/index.js b/wasm/index.js index 8f7c5ff8..ada728e3 100644 --- a/wasm/index.js +++ b/wasm/index.js @@ -129,9 +129,9 @@ function handleError(f, args) { wasm.__wbindgen_exn_store(addHeapObject(e)); } } -var BBox = class { +var BBox = class _BBox { static __wrap(ptr) { - const obj = Object.create(BBox.prototype); + const obj = Object.create(_BBox.prototype); obj.ptr = ptr; return obj; } @@ -197,9 +197,9 @@ var BBox = class { wasm.__wbg_set_bbox_height(this.ptr, arg0); } }; -var RenderedImage = class { +var RenderedImage = class _RenderedImage { static __wrap(ptr) { - const obj = Object.create(RenderedImage.prototype); + const obj = Object.create(_RenderedImage.prototype); obj.ptr = ptr; return obj; } @@ -256,9 +256,9 @@ var RenderedImage = class { return takeObject(ret); } }; -var Resvg = class { +var Resvg = class _Resvg { static __wrap(ptr) { - const obj = Object.create(Resvg.prototype); + const obj = Object.create(_Resvg.prototype); obj.ptr = ptr; return obj; } @@ -288,7 +288,7 @@ var Resvg = class { if (r2) { throw takeObject(r1); } - return Resvg.__wrap(r0); + return _Resvg.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } @@ -483,7 +483,7 @@ function getImports() { let result; try { result = getObject(arg0) instanceof Uint8Array; - } catch (e) { + } catch { result = false; } const ret = result; @@ -561,21 +561,21 @@ var Resvg2 = class extends Resvg { constructor(svg, options) { if (!initialized) throw new Error("Wasm has not been initialized. Call `initWasm()` function."); - const font = options == null ? void 0 : options.font; + const font = options?.font; if (!!font && isCustomFontsOptions(font)) { const serializableOptions = { ...options, font: { ...font, - fontsBuffers: void 0 + fontBuffers: void 0 } }; - super(svg, JSON.stringify(serializableOptions), font.fontsBuffers); + super(svg, JSON.stringify(serializableOptions), font.fontBuffers); } else { super(svg, JSON.stringify(options)); } } }; function isCustomFontsOptions(value) { - return Object.prototype.hasOwnProperty.call(value, "fontsBuffers"); + return Object.prototype.hasOwnProperty.call(value, "fontBuffers"); } diff --git a/wasm/index.min.js b/wasm/index.min.js index 71036f11..44f277d0 100644 --- a/wasm/index.min.js +++ b/wasm/index.min.js @@ -1 +1 @@ -"use strict";var resvg=(()=>{var I=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var n in t)I(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of U(t))!T.call(e,i)&&i!==n&&I(e,i,{get:()=>t[i],enumerable:!(o=M(t,i))||o.enumerable});return e};var L=e=>F(I({},"__esModule",{value:!0}),e);var K={};C(K,{Resvg:()=>$,initWasm:()=>V});var r,b=new Array(128).fill(void 0);b.push(void 0,null,!0,!1);var y=b.length;function c(e){y===b.length&&b.push(b.length+1);let t=y;return y=b[t],b[t]=e,t}function a(e){return b[e]}function z(e){e<132||(b[e]=y,y=e)}function g(e){let t=a(e);return z(e),t}var m=0,l=null;function O(){return(l===null||l.byteLength===0)&&(l=new Uint8Array(r.memory.buffer)),l}var A=new TextEncoder("utf-8"),P=typeof A.encodeInto=="function"?function(e,t){return A.encodeInto(e,t)}:function(e,t){let n=A.encode(e);return t.set(n),{read:e.length,written:n.length}};function k(e,t,n){if(n===void 0){let f=A.encode(e),w=t(f.length);return O().subarray(w,w+f.length).set(f),m=f.length,w}let o=e.length,i=t(o),u=O(),_=0;for(;_127)break;u[i+_]=f}if(_!==o){_!==0&&(e=e.slice(_)),i=n(i,o,o=_+e.length*3);let f=O().subarray(i+_,i+o),w=P(e,f);_+=w.written}return m=_,i}function B(e){return e==null}var h=null;function s(){return(h===null||h.byteLength===0)&&(h=new Int32Array(r.memory.buffer)),h}var j=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});j.decode();function W(e,t){return j.decode(O().subarray(e,e+t))}function N(e,t){if(!(e instanceof t))throw new Error(`expected instance of ${t.name}`);return e.ptr}function q(e,t){try{return e.apply(this,t)}catch(n){r.__wbindgen_exn_store(c(n))}}var d=class{static __wrap(t){let n=Object.create(d.prototype);return n.ptr=t,n}__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)}},v=class{static __wrap(t){let n=Object.create(v.prototype);return n.ptr=t,n}__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 i=r.__wbindgen_add_to_stack_pointer(-16);r.renderedimage_asPng(i,this.ptr);var t=s()[i/4+0],n=s()[i/4+1],o=s()[i/4+2];if(o)throw g(n);return g(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}get pixels(){let t=r.renderedimage_pixels(this.ptr);return g(t)}},p=class{static __wrap(t){let n=Object.create(p.prototype);return n.ptr=t,n}__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,n,o){try{let x=r.__wbindgen_add_to_stack_pointer(-16);var i=B(n)?0:k(n,r.__wbindgen_malloc,r.__wbindgen_realloc),u=m;r.resvg_new(x,c(t),i,u,B(o)?0:c(o));var _=s()[x/4+0],f=s()[x/4+1],w=s()[x/4+2];if(w)throw g(f);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 i=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_render(i,this.ptr);var t=s()[i/4+0],n=s()[i/4+1],o=s()[i/4+2];if(o)throw g(n);return v.__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=s()[o/4+0],n=s()[o/4+1];return W(t,n)}finally{r.__wbindgen_add_to_stack_pointer(16),r.__wbindgen_free(t,n)}}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)}imagesToResolve(){try{let i=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_imagesToResolve(i,this.ptr);var t=s()[i/4+0],n=s()[i/4+1],o=s()[i/4+2];if(o)throw g(n);return g(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}resolveImage(t,n){try{let u=r.__wbindgen_add_to_stack_pointer(-16),_=k(t,r.__wbindgen_malloc,r.__wbindgen_realloc),f=m;r.resvg_resolveImage(u,this.ptr,_,f,c(n));var o=s()[u/4+0],i=s()[u/4+1];if(i)throw g(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 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_15d3966e9981a196=function(t,n){let o=new Error(W(t,n));return c(o)},e.wbg.__wbindgen_memory=function(){let t=r.memory;return c(t)},e.wbg.__wbg_buffer_cf65c07de34b9a08=function(t){let n=a(t).buffer;return c(n)},e.wbg.__wbg_newwithbyteoffsetandlength_9fb2f11355ecadf5=function(t,n,o){let i=new Uint8Array(a(t),n>>>0,o>>>0);return c(i)},e.wbg.__wbindgen_object_drop_ref=function(t){g(t)},e.wbg.__wbg_new_537b7341ce90bb31=function(t){let n=new Uint8Array(a(t));return c(n)},e.wbg.__wbg_values_97683218f24ed826=function(t){let n=a(t).values();return c(n)},e.wbg.__wbg_next_88560ec06a094dea=function(){return q(function(t){let n=a(t).next();return c(n)},arguments)},e.wbg.__wbg_done_1ebec03bbd919843=function(t){return a(t).done},e.wbg.__wbg_value_6ac8da5cc5b3efda=function(t){let n=a(t).value;return c(n)},e.wbg.__wbg_instanceof_Uint8Array_01cebe79ca606cca=function(t){let n;try{n=a(t)instanceof Uint8Array}catch(i){n=!1}return n},e.wbg.__wbindgen_string_get=function(t,n){let o=a(n),i=typeof o=="string"?o:void 0;var u=B(i)?0:k(i,r.__wbindgen_malloc,r.__wbindgen_realloc),_=m;s()[t/4+1]=_,s()[t/4+0]=u},e.wbg.__wbg_new_b525de17f44a8943=function(){let t=new Array;return c(t)},e.wbg.__wbindgen_string_new=function(t,n){let o=W(t,n);return c(o)},e.wbg.__wbg_push_49c286f04dd3bf59=function(t,n){return a(t).push(a(n))},e.wbg.__wbg_length_27a2afe8ab42b09f=function(t){return a(t).length},e.wbg.__wbg_set_17499e8aa4003ebd=function(t,n,o){a(t).set(a(n),o>>>0)},e.wbg.__wbindgen_throw=function(t,n){throw new Error(W(t,n))},e}function H(e,t){return r=e.exports,R.__wbindgen_wasm_module=t,h=null,l=null,r}async function R(e){typeof e=="undefined"&&(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:o}=await D(await e,t);return H(n,o)}var E=R;var S=!1,V=async e=>{if(S)throw new Error("Already initialized. The `initWasm()` function can be used only once.");await E(await e),S=!0},$=class extends p{constructor(e,t){if(!S)throw new Error("Wasm has not been initialized. Call `initWasm()` function.");let n=t==null?void 0:t.font;if(n&&G(n)){let o={...t,font:{...n,fontsBuffers:void 0}};super(e,JSON.stringify(o),n.fontsBuffers)}else super(e,JSON.stringify(t))}};function G(e){return Object.prototype.hasOwnProperty.call(e,"fontsBuffers")}return L(K);})(); +"use strict";var resvg=(()=>{var B=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var n in t)B(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of U(t))!T.call(e,i)&&i!==n&&B(e,i,{get:()=>t[i],enumerable:!(o=M(t,i))||o.enumerable});return e};var L=e=>F(B({},"__esModule",{value:!0}),e);var K={};C(K,{Resvg:()=>$,initWasm:()=>V});var r,b=new Array(128).fill(void 0);b.push(void 0,null,!0,!1);var l=b.length;function c(e){l===b.length&&b.push(b.length+1);let t=l;return l=b[t],b[t]=e,t}function a(e){return b[e]}function z(e){e<132||(b[e]=l,l=e)}function g(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=new TextEncoder("utf-8"),P=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 I(e,t,n){if(n===void 0){let f=x.encode(e),w=t(f.length);return v().subarray(w,w+f.length).set(f),y=f.length,w}let o=e.length,i=t(o),u=v(),_=0;for(;_127)break;u[i+_]=f}if(_!==o){_!==0&&(e=e.slice(_)),i=n(i,o,o=_+e.length*3);let f=v().subarray(i+_,i+o),w=P(e,f);_+=w.written}return y=_,i}function W(e){return e==null}var p=null;function s(){return(p===null||p.byteLength===0)&&(p=new Int32Array(r.memory.buffer)),p}var S=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});S.decode();function O(e,t){return S.decode(v().subarray(e,e+t))}function N(e,t){if(!(e instanceof t))throw new Error(`expected instance of ${t.name}`);return e.ptr}function q(e,t){try{return e.apply(this,t)}catch(n){r.__wbindgen_exn_store(c(n))}}var h=class e{static __wrap(t){let n=Object.create(e.prototype);return n.ptr=t,n}__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 e{static __wrap(t){let n=Object.create(e.prototype);return n.ptr=t,n}__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 i=r.__wbindgen_add_to_stack_pointer(-16);r.renderedimage_asPng(i,this.ptr);var t=s()[i/4+0],n=s()[i/4+1],o=s()[i/4+2];if(o)throw g(n);return g(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}get pixels(){let t=r.renderedimage_pixels(this.ptr);return g(t)}},A=class e{static __wrap(t){let n=Object.create(e.prototype);return n.ptr=t,n}__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,n,o){try{let m=r.__wbindgen_add_to_stack_pointer(-16);var i=W(n)?0:I(n,r.__wbindgen_malloc,r.__wbindgen_realloc),u=y;r.resvg_new(m,c(t),i,u,W(o)?0:c(o));var _=s()[m/4+0],f=s()[m/4+1],w=s()[m/4+2];if(w)throw g(f);return e.__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 i=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_render(i,this.ptr);var t=s()[i/4+0],n=s()[i/4+1],o=s()[i/4+2];if(o)throw g(n);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=s()[o/4+0],n=s()[o/4+1];return O(t,n)}finally{r.__wbindgen_add_to_stack_pointer(16),r.__wbindgen_free(t,n)}}innerBBox(){let t=r.resvg_innerBBox(this.ptr);return t===0?void 0:h.__wrap(t)}getBBox(){let t=r.resvg_getBBox(this.ptr);return t===0?void 0:h.__wrap(t)}cropByBBox(t){N(t,h),r.resvg_cropByBBox(this.ptr,t.ptr)}imagesToResolve(){try{let i=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_imagesToResolve(i,this.ptr);var t=s()[i/4+0],n=s()[i/4+1],o=s()[i/4+2];if(o)throw g(n);return g(t)}finally{r.__wbindgen_add_to_stack_pointer(16)}}resolveImage(t,n){try{let u=r.__wbindgen_add_to_stack_pointer(-16),_=I(t,r.__wbindgen_malloc,r.__wbindgen_realloc),f=y;r.resvg_resolveImage(u,this.ptr,_,f,c(n));var o=s()[u/4+0],i=s()[u/4+1];if(i)throw g(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 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_15d3966e9981a196=function(t,n){let o=new Error(O(t,n));return c(o)},e.wbg.__wbindgen_memory=function(){let t=r.memory;return c(t)},e.wbg.__wbg_buffer_cf65c07de34b9a08=function(t){let n=a(t).buffer;return c(n)},e.wbg.__wbg_newwithbyteoffsetandlength_9fb2f11355ecadf5=function(t,n,o){let i=new Uint8Array(a(t),n>>>0,o>>>0);return c(i)},e.wbg.__wbindgen_object_drop_ref=function(t){g(t)},e.wbg.__wbg_new_537b7341ce90bb31=function(t){let n=new Uint8Array(a(t));return c(n)},e.wbg.__wbg_values_97683218f24ed826=function(t){let n=a(t).values();return c(n)},e.wbg.__wbg_next_88560ec06a094dea=function(){return q(function(t){let n=a(t).next();return c(n)},arguments)},e.wbg.__wbg_done_1ebec03bbd919843=function(t){return a(t).done},e.wbg.__wbg_value_6ac8da5cc5b3efda=function(t){let n=a(t).value;return c(n)},e.wbg.__wbg_instanceof_Uint8Array_01cebe79ca606cca=function(t){let n;try{n=a(t)instanceof Uint8Array}catch{n=!1}return n},e.wbg.__wbindgen_string_get=function(t,n){let o=a(n),i=typeof o=="string"?o:void 0;var u=W(i)?0:I(i,r.__wbindgen_malloc,r.__wbindgen_realloc),_=y;s()[t/4+1]=_,s()[t/4+0]=u},e.wbg.__wbg_new_b525de17f44a8943=function(){let t=new Array;return c(t)},e.wbg.__wbindgen_string_new=function(t,n){let o=O(t,n);return c(o)},e.wbg.__wbg_push_49c286f04dd3bf59=function(t,n){return a(t).push(a(n))},e.wbg.__wbg_length_27a2afe8ab42b09f=function(t){return a(t).length},e.wbg.__wbg_set_17499e8aa4003ebd=function(t,n,o){a(t).set(a(n),o>>>0)},e.wbg.__wbindgen_throw=function(t,n){throw new Error(O(t,n))},e}function H(e,t){return r=e.exports,j.__wbindgen_wasm_module=t,p=null,d=null,r}async function j(e){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:o}=await D(await e,t);return H(n,o)}var E=j;var R=!1,V=async e=>{if(R)throw new Error("Already initialized. The `initWasm()` function can be used only once.");await E(await e),R=!0},$=class extends A{constructor(e,t){if(!R)throw new Error("Wasm has not been initialized. Call `initWasm()` function.");let n=t?.font;if(n&&G(n)){let o={...t,font:{...n,fontBuffers:void 0}};super(e,JSON.stringify(o),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 8e88e953..4c353df5 100644 --- a/wasm/index.mjs +++ b/wasm/index.mjs @@ -102,9 +102,9 @@ function handleError(f, args) { wasm.__wbindgen_exn_store(addHeapObject(e)); } } -var BBox = class { +var BBox = class _BBox { static __wrap(ptr) { - const obj = Object.create(BBox.prototype); + const obj = Object.create(_BBox.prototype); obj.ptr = ptr; return obj; } @@ -170,9 +170,9 @@ var BBox = class { wasm.__wbg_set_bbox_height(this.ptr, arg0); } }; -var RenderedImage = class { +var RenderedImage = class _RenderedImage { static __wrap(ptr) { - const obj = Object.create(RenderedImage.prototype); + const obj = Object.create(_RenderedImage.prototype); obj.ptr = ptr; return obj; } @@ -229,9 +229,9 @@ var RenderedImage = class { return takeObject(ret); } }; -var Resvg = class { +var Resvg = class _Resvg { static __wrap(ptr) { - const obj = Object.create(Resvg.prototype); + const obj = Object.create(_Resvg.prototype); obj.ptr = ptr; return obj; } @@ -261,7 +261,7 @@ var Resvg = class { if (r2) { throw takeObject(r1); } - return Resvg.__wrap(r0); + return _Resvg.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } @@ -456,7 +456,7 @@ function getImports() { let result; try { result = getObject(arg0) instanceof Uint8Array; - } catch (e) { + } catch { result = false; } const ret = result; @@ -534,23 +534,23 @@ var Resvg2 = class extends Resvg { constructor(svg, options) { if (!initialized) throw new Error("Wasm has not been initialized. Call `initWasm()` function."); - const font = options == null ? void 0 : options.font; + const font = options?.font; if (!!font && isCustomFontsOptions(font)) { const serializableOptions = { ...options, font: { ...font, - fontsBuffers: void 0 + fontBuffers: void 0 } }; - super(svg, JSON.stringify(serializableOptions), font.fontsBuffers); + super(svg, JSON.stringify(serializableOptions), font.fontBuffers); } else { super(svg, JSON.stringify(options)); } } }; function isCustomFontsOptions(value) { - return Object.prototype.hasOwnProperty.call(value, "fontsBuffers"); + return Object.prototype.hasOwnProperty.call(value, "fontBuffers"); } export { Resvg2 as Resvg,