diff --git a/Cargo.toml b/Cargo.toml index 48cfc4b9..673b7db1 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ crate-type = ["cdylib"] env_logger = "0.10.0" log = "0.4" +kurbo = "0.9.5" serde = { version = "1", features = ["derive"] } serde_json = "1" svgtypes = "0.13.0" @@ -29,7 +30,7 @@ mimalloc-rust = { version = "0.2" } [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen = "0.2.87" js-sys = "0.3.64" -resvg = { version = "0.34.0", default-features = false, features = [ +resvg = { version = "0.38.0", default-features = false, features = [ "raster-images", "text", ] } @@ -37,7 +38,7 @@ 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" -resvg = { version = "0.34.0", default-features = false, features = [ +resvg = { version = "0.38.0", default-features = false, features = [ "raster-images", "text", "system-fonts", @@ -54,5 +55,5 @@ opt-level = 3 codegen-units = 1 [patch.crates-io] -resvg = { git = "https://github.com/zimond/resvg", rev = "3495d870" } +resvg = { git="https://github.com/yisibl/resvg", branch="patch-0.38" } woff2 = { git="https://github.com/yisibl/woff2-rs", branch="fix-total-compressed-size" } diff --git a/src/lib.rs b/src/lib.rs index c1b7d022..92405247 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,15 +11,15 @@ use napi::bindgen_prelude::{ #[cfg(not(target_arch = "wasm32"))] use napi_derive::napi; use options::JsOptions; -use pathfinder_content::{ - outline::{Contour, Outline}, - stroke::{LineCap, LineJoin, OutlineStrokeToFill, StrokeStyle}, -}; +use pathfinder_content::outline::{Contour, Outline}; +use pathfinder_content::stroke::{LineCap, LineJoin, OutlineStrokeToFill, StrokeStyle}; use pathfinder_geometry::rect::RectF; use pathfinder_geometry::vector::Vector2F; +use resvg::tiny_skia::{NonZeroRect, PathSegment, Rect, Transform}; +use resvg::usvg::TreePostProc; use resvg::{ - tiny_skia::{PathSegment, Pixmap, Point}, - usvg::{self, ImageKind, NodeKind, TreeParsing, TreeTextToPath}, + tiny_skia::{Pixmap, Point}, + usvg::{self, ImageKind, Node, TreeParsing}, }; #[cfg(target_arch = "wasm32")] use wasm_bindgen::{ @@ -32,7 +32,6 @@ mod fonts; mod options; use error::Error; -use usvg::NodeExt; #[cfg(all( not(target_arch = "wasm32"), @@ -164,7 +163,10 @@ impl Resvg { Either::B(b) => usvg::Tree::from_data(b.as_ref(), &opts), } .map_err(|e| napi::Error::from_reason(format!("{e}")))?; - tree.convert_text(&fontdb); + tree.postprocess(Default::default(), &fontdb); + tree.calculate_abs_transforms(); + tree.calculate_bounding_boxes(); + Ok(Resvg { tree, js_options }) } @@ -188,15 +190,15 @@ impl Resvg { // Either depends on napi 2.4.3 // https://github.com/napi-rs/napi-rs/releases/tag/napi@2.4.3 - pub fn inner_bbox(&self) -> Either { + pub fn inner_bbox(&mut self) -> Either { let rect = self.tree.view_box.rect; let rect = points_to_rect( Vector2F::new(rect.x(), rect.y()), Vector2F::new(rect.right(), rect.bottom()), ); let mut v = None; - for child in self.tree.root.children() { - let child_viewbox = match self.node_bbox(child).and_then(|v| v.intersection(rect)) { + for child in &self.tree.root.children { + let child_viewbox = match self.node_bbox(&child).and_then(|v| v.intersection(rect)) { Some(v) => v, None => continue, }; @@ -225,12 +227,12 @@ impl Resvg { // Either depends on napi 2.4.3 // https://github.com/napi-rs/napi-rs/releases/tag/napi@2.4.3 pub fn get_bbox(&self) -> Either { - match self.tree.root.calculate_bbox() { + match self.calculate_bbox(self.tree.root.clone()) { Some(bbox) => Either::A(BBox { - x: bbox.x() as f64, - y: bbox.y() as f64, - width: bbox.width() as f64, - height: bbox.height() as f64, + x: bbox.x, + y: bbox.y as f64, + width: bbox.width, + height: bbox.height, }), None => Either::B(()), } @@ -256,9 +258,9 @@ impl Resvg { } #[napi] - pub fn resolve_image(&self, href: String, buffer: Buffer) -> Result<(), NapiError> { + pub fn resolve_image(&mut self, _href: String, buffer: Buffer) -> Result<(), NapiError> { let buffer = buffer.to_vec(); - Ok(self.resolve_image_inner(href, buffer)?) + Ok(self.resolve_image_inner(buffer)?) } /// Get the SVG width @@ -301,7 +303,9 @@ impl Resvg { } else { Err(Error::InvalidInput) }?; - tree.convert_text(&fontdb); + tree.postprocess(Default::default(), &fontdb); + tree.calculate_abs_transforms(); + tree.calculate_bounding_boxes(); Ok(Resvg { tree, js_options }) } @@ -340,7 +344,7 @@ impl Resvg { Vector2F::new(rect.right(), rect.bottom()), ); let mut v = None; - for child in self.tree.root.children() { + for child in &self.tree.root.children { let child_viewbox = match self.node_bbox(child).and_then(|v| v.intersection(rect)) { Some(v) => v, None => continue, @@ -365,12 +369,12 @@ impl Resvg { /// This will first apply transform. /// Similar to `SVGGraphicsElement.getBBox()` DOM API. pub fn get_bbox(&self) -> Option { - let bbox = self.tree.root.calculate_bbox()?; + let bbox = self.calculate_bbox(self.tree.root.clone())?; Some(BBox { - x: bbox.x() as f64, - y: bbox.y() as f64, - width: bbox.width() as f64, - height: bbox.height() as f64, + x: bbox.x, + y: bbox.y, + width: bbox.width, + height: bbox.height, }) } @@ -397,20 +401,20 @@ impl Resvg { #[wasm_bindgen(js_name = resolveImage)] pub fn resolve_image( - &self, - href: String, + &mut self, + _href: String, buffer: js_sys::Uint8Array, ) -> Result<(), js_sys::Error> { let buffer = buffer.to_vec(); - Ok(self.resolve_image_inner(href, buffer)?) + Ok(self.resolve_image_inner(buffer)?) } } impl Resvg { - fn node_bbox(&self, node: usvg::Node) -> Option { - let transform = node.borrow().transform(); - let bbox = match &*node.borrow() { - usvg::NodeKind::Path(p) => { + fn node_bbox(&self, node: &usvg::Node) -> Option { + let mut transform = Transform::identity(); + let bbox = match node { + usvg::Node::Path(p) => { let no_fill = p.fill.is_none() || p.fill .as_ref() @@ -483,18 +487,25 @@ impl Resvg { } Some(outline.bounds()) } - usvg::NodeKind::Group(g) => { - let clippath = if let Some(clippath) = - g.clip_path.as_ref().and_then(|n| n.root.first_child()) + usvg::Node::Group(g) => { + transform = g.transform; + let clippath = if let Some(ref clippath) = g + .clip_path + .as_ref() + .and_then(|n| n.borrow().root.children.first().cloned()) { self.node_bbox(clippath) - } else if let Some(mask) = g.mask.as_ref().and_then(|n| n.root.first_child()) { + } else if let Some(ref mask) = g + .mask + .as_ref() + .and_then(|n| n.borrow().root.children.first().cloned()) + { self.node_bbox(mask) } else { Some(self.viewbox()) }?; let mut v = None; - for child in node.children() { + for child in &g.children { let child_viewbox = match self.node_bbox(child).and_then(|v| v.intersection(clippath)) { Some(v) => v, @@ -508,14 +519,14 @@ impl Resvg { } v.and_then(|v| v.intersection(self.viewbox())) } - usvg::NodeKind::Image(image) => { + usvg::Node::Image(image) => { let rect = image.view_box.rect; Some(points_to_rect( Vector2F::new(rect.x(), rect.y()), Vector2F::new(rect.right(), rect.bottom()), )) } - usvg::NodeKind::Text(_) => None, + usvg::Node::Text(_) => None, }?; let mut pts = vec![ Point::from_xy(bbox.min_x(), bbox.min_y()), @@ -532,6 +543,62 @@ impl Resvg { Some(r) } + // https://github.com/RazrFalcon/resvg/blob/1dfe9e506c2f90b55e662b1803d27f0b4e4ace77/crates/usvg-tree/src/lib.rs#L1289-L1291 + #[inline] + fn calculate_bbox(&self, group: usvg::Group) -> Option { + let node = Node::Group(Box::new(group)); + let transform = node.abs_transform(); + self.calc_node_bbox(&node, transform) + } + + /// https://github.com/RazrFalcon/resvg/blob/v0.37.0/crates/usvg-tree/src/lib.rs#L1298-L1335 + fn calc_node_bbox(&self, node: &Node, ts: Transform) -> Option { + match node { + Node::Path(ref path) => bbox_with_transform(&path.data, ts, path.stroke.as_ref()), + Node::Image(ref img) => img.view_box.rect.transform(ts).map(bbox_from_nonzrect), + Node::Group(g) => { + // https://github.com/RazrFalcon/resvg/blob/v0.37.0/crates/usvg-tree/src/geom.rs#L89-L98 + // Self { + // left: f32::MAX, + // top: f32::MAX, + // right: f32::MIN, + // bottom: f32::MIN, + // } + let mut bbox = BBox { + x: f64::MAX, + y: f64::MAX, + width: f64::MIN, + height: f64::MIN, + }; + + for child in &g.children { + let child_transform = if let Node::Group(ref group) = child { + ts.pre_concat(group.transform) + } else { + ts + }; + if let Some(c_bbox) = self.calc_node_bbox(&child, child_transform) { + bbox = bbox_expanded(&bbox, &c_bbox); + } + } + + // Make sure bbox was changed. + if bbox_is_default(&bbox) { + return None; + } + + Some(bbox) + } + Node::Text(ref text) => { + if let Some(bbox) = text.bounding_box { + bbox.transform(ts).map(bbox_from_nonzrect) + } else { + None + } + } + } + } + fn viewbox(&self) -> RectF { RectF::new( Vector2F::new(0.0, 0.0), @@ -543,7 +610,7 @@ impl Resvg { let (width, height, transform) = self.js_options.fit_to.fit_to(self.tree.size)?; let mut pixmap = self.js_options.create_pixmap(width, height)?; // Render the tree - let _image = resvg::Tree::from_usvg(&self.tree).render(transform, &mut pixmap.as_mut()); + let _image = resvg::render(&self.tree, transform, &mut pixmap.as_mut()); // Crop the SVG let crop_rect = resvg::tiny_skia::IntRect::from_ltrb( @@ -562,42 +629,255 @@ impl Resvg { fn images_to_resolve_inner(&self) -> Result, Error> { let mut data = vec![]; - for node in self.tree.root.descendants() { - if let NodeKind::Image(i) = &mut *node.borrow_mut() { - if let ImageKind::RAW(_, _, buffer) = &mut i.kind { - let s = String::from_utf8(buffer.as_slice().to_vec())?; - data.push(s); - } + let mut err: Option = None; + for node in &self.tree.root.children { + if err.is_some() { + break; } + let err = &mut err; + let data = &mut data; + traverse_tree(node, &mut |node| { + if let Node::Image(img) = node { + if err.is_some() { + return; + } + + match &img.kind { + ImageKind::HOLE(url) => { + if is_not_data_url(&url) { + data.push(url.clone()); + } + } + _ => {} + } + } + }); } Ok(data) } - fn resolve_image_inner(&self, href: String, buffer: Vec) -> Result<(), Error> { + fn resolve_image_inner(&mut self, buffer: Vec) -> Result<(), Error> { let resolver = usvg::ImageHrefResolver::default_data_resolver(); let (options, _) = self.js_options.to_usvg_options(); let mime = MimeType::parse(&buffer)?.mime_type().to_string(); - for node in self.tree.root.descendants() { - if let NodeKind::Image(i) = &mut *node.borrow_mut() { - let matched = if let ImageKind::RAW(_, _, data) = &mut i.kind { - let s = String::from_utf8(data.as_slice().to_vec()).map_err(Error::from)?; - s == href - } else { - false - }; - if matched { - let data = (resolver)(&mime, Arc::new(buffer.clone()), &options); - if let Some(kind) = data { - i.kind = kind; + for node in &mut self.tree.root.children { + traverse_tree_mut(node, &|node| { + if let Node::Image(ref mut i) = node { + let need_fallback = match &i.kind { + ImageKind::HOLE(_) => true, + _ => false, + }; + + if need_fallback { + let data = (resolver)(&mime, Arc::new(buffer.clone()), &options); + if let Some(ref kind) = data { + i.as_mut().kind = kind.clone(); + } } } - } + }); } + Ok(()) } } +// https://github.com/RazrFalcon/resvg/blob/1dfe9e506c2f90b55e662b1803d27f0b4e4ace77/crates/usvg-tree/src/geom.rs#L78-L87 +fn bbox_from_nonzrect(rect: NonZeroRect) -> BBox { + BBox { + x: rect.x() as f64, + y: rect.y() as f64, + width: rect.width() as f64, + height: rect.height() as f64, + } +} + +// https://github.com/RazrFalcon/resvg/blob/1dfe9e506c2f90b55e662b1803d27f0b4e4ace77/crates/usvg-tree/src/geom.rs#L102-L107 +fn bbox_is_default(bbox: &BBox) -> bool { + bbox.x == f64::MAX && bbox.y == f64::MAX && bbox.width == f64::MIN && bbox.height == f64::MIN +} + +// https://github.com/RazrFalcon/resvg/blob/1dfe9e506c2f90b55e662b1803d27f0b4e4ace77/crates/usvg-tree/src/geom.rs#L111-L122 +fn bbox_expanded(this_bbox: &BBox, other: &BBox) -> BBox { + // left: self.left.min(r.left), + // top: self.top.min(r.top), + // right: self.right.max(r.right), + // bottom: self.bottom.max(r.bottom), + BBox { + x: this_bbox.x.min(other.x), + y: this_bbox.y.min(other.y), + width: this_bbox.width.max(other.width), + height: this_bbox.height.max(other.height), + } +} + +// https://github.com/zimond/resvg/commit/3495d8705b302d6d266748516973606ca9657906 +fn bbox_with_transform( + path: &usvg::tiny_skia_path::Path, + ts: Transform, + stroke: Option<&usvg::Stroke>, +) -> Option { + use kurbo::{CubicBez, Point}; + + if path.segments().count() == 0 { + return None; + } + + let mut prev_x = 0.0; + let mut prev_y = 0.0; + let mut minx = 0.0; + let mut miny = 0.0; + let mut maxx = 0.0; + let mut maxy = 0.0; + + if let Some(PathSegment::MoveTo(p)) = + path.clone().transform(ts).and_then(|p| p.segments().next()) + { + prev_x = p.x; + prev_y = p.y; + minx = p.x; + miny = p.y; + maxx = p.x; + maxy = p.y; + } + + for seg in path + .clone() + .transform(ts) + .as_ref() + .map(|p| p.segments()) + .into_iter() + .flatten() + { + match seg { + PathSegment::MoveTo(p) | PathSegment::LineTo(p) => { + let x = p.x; + let y = p.y; + prev_x = x; + prev_y = y; + + if x > maxx { + maxx = x; + } else if x < minx { + minx = x; + } + + if y > maxy { + maxy = y; + } else if y < miny { + miny = y; + } + } + PathSegment::CubicTo(p1, p2, p) => { + let curve = CubicBez::new( + Point::new(prev_x as f64, prev_y as f64), + Point::new(p1.x as f64, p1.y as f64), + Point::new(p2.x as f64, p2.y as f64), + Point::new(p.x as f64, p.y as f64), + ); + let r = kurbo::ParamCurveExtrema::bounding_box(&curve); + + if (r.x0 as f32) < minx { + minx = r.x0 as f32; + } + if (r.x1 as f32) > maxx { + maxx = r.x1 as f32; + } + if (r.y0 as f32) < miny { + miny = r.y0 as f32; + } + if (r.y1 as f32) > maxy { + maxy = r.y1 as f32; + } + + prev_x = p.x; + prev_y = p.y; + } + PathSegment::QuadTo(p1, p) => { + let curve = CubicBez::new( + Point::new(prev_x as f64, prev_y as f64), + Point::new(p1.x as f64, p1.y as f64), + Point::new(p1.x as f64, p1.y as f64), + Point::new(p.x as f64, p.y as f64), + ); + let r = kurbo::ParamCurveExtrema::bounding_box(&curve); + + if (r.x0 as f32) < minx { + minx = r.x0 as f32; + } + if (r.x1 as f32) > maxx { + maxx = r.x1 as f32; + } + if (r.y0 as f32) < miny { + miny = r.y0 as f32; + } + if (r.y1 as f32) > maxy { + maxy = r.y1 as f32; + } + + prev_x = p.x; + prev_y = p.y; + } + _ => {} + } + } + + // TODO: find a better way + // It's an approximation, but it's better than nothing. + if let Some(stroke) = stroke { + let w = stroke.width.get() + / if ts.is_identity() { + 2.0 + } else { + 2.0 / (ts.sx * ts.sy - ts.kx * ts.ky).abs().sqrt() + }; + minx -= w; + miny -= w; + maxx += w; + maxy += w; + } + + let width = maxx - minx; + let height = maxy - miny; + + // Some(BBox::from(Rect::from_xywh(minx, miny, width, height)?)) + Some(BBox { + x: minx as f64, + y: miny as f64, + width: width as f64, + height: height as f64, + }) +} + +fn is_not_data_url(data: &str) -> bool { + return !data.starts_with("data:"); +} + +fn traverse_tree_mut(node: &mut usvg::Node, f: &F) +where + F: Fn(&mut usvg::Node), +{ + f(node); + if let usvg::Node::Group(g) = node { + for child in &mut g.children { + traverse_tree_mut(child, f); + } + } +} + +fn traverse_tree(node: &usvg::Node, f: &mut F) +where + F: FnMut(&usvg::Node), +{ + f(node); + if let usvg::Node::Group(g) = node { + for child in &g.children { + traverse_tree(child, f); + } + } +} + #[cfg(not(target_arch = "wasm32"))] pub struct AsyncRenderer { options: Option, diff --git a/src/options.rs b/src/options.rs index 4a8d2c57..3f02e844 100644 --- a/src/options.rs +++ b/src/options.rs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use std::sync::Arc; - use crate::error::Error; +use crate::is_not_data_url; #[cfg(not(target_arch = "wasm32"))] use napi::{bindgen_prelude::Buffer, Either}; use resvg::tiny_skia::{Pixmap, Transform}; @@ -366,9 +365,9 @@ where pub(crate) fn tweak_usvg_options(opts: &mut usvg::Options) { opts.image_href_resolver = ImageHrefResolver::default(); - opts.image_href_resolver.resolve_string = Arc::new(move |data: &str, opts: &Options| { - if data.starts_with("https://") || data.starts_with("http://") { - Some(ImageKind::RAW(1, 1, Arc::new(data.as_bytes().to_vec()))) + opts.image_href_resolver.resolve_string = Box::new(move |data: &str, opts: &Options| { + if is_not_data_url(data) { + Some(ImageKind::HOLE(data.to_string())) } else { let resolver = ImageHrefResolver::default().resolve_string; (resolver)(data, opts) diff --git a/wasm/index.d.ts b/wasm/index.d.ts index 77a4f5d8..31684140 100644 --- a/wasm/index.d.ts +++ b/wasm/index.d.ts @@ -100,7 +100,7 @@ export declare const Resvg: { getBBox(): BBox | undefined; cropByBBox(bbox: BBox): void; imagesToResolve(): any[]; - resolveImage(href: string, buffer: Uint8Array): void; + resolveImage(_href: string, buffer: Uint8Array): void; readonly height: number; readonly width: number; }; diff --git a/wasm/index.js b/wasm/index.js index 57d07aba..ccfc8582 100644 --- a/wasm/index.js +++ b/wasm/index.js @@ -265,13 +265,7 @@ var RenderedImage = class _RenderedImage { return takeObject(ret); } }; -var Resvg = class _Resvg { - static __wrap(ptr) { - ptr = ptr >>> 0; - const obj = Object.create(_Resvg.prototype); - obj.__wbg_ptr = ptr; - return obj; - } +var Resvg = class { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; @@ -283,8 +277,8 @@ var Resvg = class _Resvg { } /** * @param {Uint8Array | string} svg - * @param {string | undefined} options - * @param {Array | undefined} custom_font_buffers + * @param {string | undefined} [options] + * @param {Array | undefined} [custom_font_buffers] */ constructor(svg, options, custom_font_buffers) { try { @@ -298,7 +292,8 @@ var Resvg = class _Resvg { if (r2) { throw takeObject(r1); } - return _Resvg.__wrap(r0); + this.__wbg_ptr = r0 >>> 0; + return this; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } @@ -406,13 +401,13 @@ var Resvg = class _Resvg { } } /** - * @param {string} href + * @param {string} _href * @param {Uint8Array} buffer */ - resolveImage(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 ptr0 = passStringToWasm0(_href, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; wasm.resvg_resolveImage(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(buffer)); var r0 = getInt32Memory0()[retptr / 4 + 0]; @@ -452,52 +447,52 @@ async function __wbg_load(module2, imports) { function __wbg_get_imports() { const imports = {}; imports.wbg = {}; - imports.wbg.__wbg_new_d258248ed531ff54 = function(arg0, arg1) { - const ret = new Error(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }; imports.wbg.__wbindgen_memory = function() { const ret = wasm.memory; return addHeapObject(ret); }; - imports.wbg.__wbg_buffer_085ec1f694018c4f = function(arg0) { + imports.wbg.__wbg_buffer_5d1b598a01b41a42 = function(arg0) { const ret = getObject(arg0).buffer; return addHeapObject(ret); }; - imports.wbg.__wbg_newwithbyteoffsetandlength_6da8e527659b86aa = function(arg0, arg1, arg2) { + imports.wbg.__wbg_newwithbyteoffsetandlength_d695c7957788f922 = function(arg0, arg1, arg2) { const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); return addHeapObject(ret); }; imports.wbg.__wbindgen_object_drop_ref = function(arg0) { takeObject(arg0); }; - imports.wbg.__wbg_new_8125e318e6245eed = function(arg0) { + imports.wbg.__wbg_new_ace717933ad7117f = function(arg0) { const ret = new Uint8Array(getObject(arg0)); return addHeapObject(ret); }; - imports.wbg.__wbg_values_e80af618f92c8649 = function(arg0) { + imports.wbg.__wbg_new_3a66822ed076951c = function(arg0, arg1) { + const ret = new Error(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_values_705f0abfa0ca41f6 = function(arg0) { const ret = getObject(arg0).values(); return addHeapObject(ret); }; - imports.wbg.__wbg_next_ddb3312ca1c4e32a = function() { + imports.wbg.__wbg_next_267398d0e0761bf9 = function() { return handleError(function(arg0) { const ret = getObject(arg0).next(); return addHeapObject(ret); }, arguments); }; - imports.wbg.__wbg_done_5c1f01fb660d73b5 = function(arg0) { + imports.wbg.__wbg_done_506b44765ba84b9c = function(arg0) { const ret = getObject(arg0).done; return ret; }; - imports.wbg.__wbg_value_1695675138684bd5 = function(arg0) { + imports.wbg.__wbg_value_31485d8770eb06ab = function(arg0) { const ret = getObject(arg0).value; return addHeapObject(ret); }; - imports.wbg.__wbg_instanceof_Uint8Array_d8d9cb2b8e8ac1d4 = function(arg0) { + imports.wbg.__wbg_instanceof_Uint8Array_4f5cffed7df34b2f = function(arg0) { let result; try { result = getObject(arg0) instanceof Uint8Array; - } catch { + } catch (_) { result = false; } const ret = result; @@ -511,7 +506,7 @@ function __wbg_get_imports() { getInt32Memory0()[arg0 / 4 + 1] = len1; getInt32Memory0()[arg0 / 4 + 0] = ptr1; }; - imports.wbg.__wbg_new_898a68150f225f2e = function() { + imports.wbg.__wbg_new_34c624469fb1d4fd = function() { const ret = new Array(); return addHeapObject(ret); }; @@ -519,15 +514,15 @@ function __wbg_get_imports() { const ret = getStringFromWasm0(arg0, arg1); return addHeapObject(ret); }; - imports.wbg.__wbg_push_ca1c26067ef907ac = function(arg0, arg1) { + imports.wbg.__wbg_push_906164999551d793 = function(arg0, arg1) { const ret = getObject(arg0).push(getObject(arg1)); return ret; }; - imports.wbg.__wbg_length_72e2208bbc0efc61 = function(arg0) { + imports.wbg.__wbg_length_f0764416ba5bb237 = function(arg0) { const ret = getObject(arg0).length; return ret; }; - imports.wbg.__wbg_set_5cf90238115182c3 = function(arg0, arg1, arg2) { + imports.wbg.__wbg_set_74906aa30864df5a = function(arg0, arg1, arg2) { getObject(arg0).set(getObject(arg1), arg2 >>> 0); }; imports.wbg.__wbindgen_throw = function(arg0, arg1) { diff --git a/wasm/index.min.js b/wasm/index.min.js index 717a64dc..151c8707 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 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 c(e){p===w.length&&w.push(w.length+1);let t=p;return p=w[t],w[t]=e,t}function a(e){return w[e]}function z(e){e<132||(w[e]=p,p=e)}function f(e){let t=a(e);return z(e),t}var y=0,u=null;function v(){return(u===null||u.byteLength===0)&&(u=new Uint8Array(r.memory.buffer)),u}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 g=x.encode(e),d=t(g.length,1)>>>0;return v().subarray(d,d+g.length).set(g),y=g.length,d}let _=e.length,o=t(_,1)>>>0,b=v(),s=0;for(;s<_;s++){let g=e.charCodeAt(s);if(g>127)break;b[o+s]=g}if(s!==_){s!==0&&(e=e.slice(s)),o=n(o,_,_=s+e.length*3,1)>>>0;let g=v().subarray(o+s,o+_),d=D(e,g);s+=d.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{__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),b=y;r.resvg_new(m,c(t),o,b,k(_)?0:c(_));var s=i()[m/4+0],g=i()[m/4+1],d=i()[m/4+2];if(d)throw f(g);return this.__wbg_ptr=s>>>0,this}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 b=r.__wbindgen_add_to_stack_pointer(-16);r.resvg_toString(b,this.__wbg_ptr);var _=i()[b/4+0],o=i()[b/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 b=r.__wbindgen_add_to_stack_pointer(-16),s=W(t,r.__wbindgen_malloc,r.__wbindgen_realloc),g=y;r.resvg_resolveImage(b,this.__wbg_ptr,s,g,c(n));var _=i()[b/4+0],o=i()[b/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.__wbindgen_memory=function(){let t=r.memory;return c(t)},e.wbg.__wbg_buffer_5d1b598a01b41a42=function(t){let n=a(t).buffer;return c(n)},e.wbg.__wbg_newwithbyteoffsetandlength_d695c7957788f922=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_ace717933ad7117f=function(t){let n=new Uint8Array(a(t));return c(n)},e.wbg.__wbg_new_3a66822ed076951c=function(t,n){let _=new Error(A(t,n));return c(_)},e.wbg.__wbg_values_705f0abfa0ca41f6=function(t){let n=a(t).values();return c(n)},e.wbg.__wbg_next_267398d0e0761bf9=function(){return N(function(t){let n=a(t).next();return c(n)},arguments)},e.wbg.__wbg_done_506b44765ba84b9c=function(t){return a(t).done},e.wbg.__wbg_value_31485d8770eb06ab=function(t){let n=a(t).value;return c(n)},e.wbg.__wbg_instanceof_Uint8Array_4f5cffed7df34b2f=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 b=k(o)?0:W(o,r.__wbindgen_malloc,r.__wbindgen_realloc),s=y;i()[t/4+1]=s,i()[t/4+0]=b},e.wbg.__wbg_new_34c624469fb1d4fd=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_906164999551d793=function(t,n){return a(t).push(a(n))},e.wbg.__wbg_length_f0764416ba5bb237=function(t){return a(t).length},e.wbg.__wbg_set_74906aa30864df5a=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,u=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..d93786fc 100644 --- a/wasm/index.mjs +++ b/wasm/index.mjs @@ -238,13 +238,7 @@ var RenderedImage = class _RenderedImage { return takeObject(ret); } }; -var Resvg = class _Resvg { - static __wrap(ptr) { - ptr = ptr >>> 0; - const obj = Object.create(_Resvg.prototype); - obj.__wbg_ptr = ptr; - return obj; - } +var Resvg = class { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; @@ -256,8 +250,8 @@ var Resvg = class _Resvg { } /** * @param {Uint8Array | string} svg - * @param {string | undefined} options - * @param {Array | undefined} custom_font_buffers + * @param {string | undefined} [options] + * @param {Array | undefined} [custom_font_buffers] */ constructor(svg, options, custom_font_buffers) { try { @@ -271,7 +265,8 @@ var Resvg = class _Resvg { if (r2) { throw takeObject(r1); } - return _Resvg.__wrap(r0); + this.__wbg_ptr = r0 >>> 0; + return this; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } @@ -379,13 +374,13 @@ var Resvg = class _Resvg { } } /** - * @param {string} href + * @param {string} _href * @param {Uint8Array} buffer */ - resolveImage(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 ptr0 = passStringToWasm0(_href, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; wasm.resvg_resolveImage(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(buffer)); var r0 = getInt32Memory0()[retptr / 4 + 0]; @@ -425,52 +420,52 @@ async function __wbg_load(module, imports) { function __wbg_get_imports() { const imports = {}; imports.wbg = {}; - imports.wbg.__wbg_new_d258248ed531ff54 = function(arg0, arg1) { - const ret = new Error(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }; imports.wbg.__wbindgen_memory = function() { const ret = wasm.memory; return addHeapObject(ret); }; - imports.wbg.__wbg_buffer_085ec1f694018c4f = function(arg0) { + imports.wbg.__wbg_buffer_5d1b598a01b41a42 = function(arg0) { const ret = getObject(arg0).buffer; return addHeapObject(ret); }; - imports.wbg.__wbg_newwithbyteoffsetandlength_6da8e527659b86aa = function(arg0, arg1, arg2) { + imports.wbg.__wbg_newwithbyteoffsetandlength_d695c7957788f922 = function(arg0, arg1, arg2) { const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); return addHeapObject(ret); }; imports.wbg.__wbindgen_object_drop_ref = function(arg0) { takeObject(arg0); }; - imports.wbg.__wbg_new_8125e318e6245eed = function(arg0) { + imports.wbg.__wbg_new_ace717933ad7117f = function(arg0) { const ret = new Uint8Array(getObject(arg0)); return addHeapObject(ret); }; - imports.wbg.__wbg_values_e80af618f92c8649 = function(arg0) { + imports.wbg.__wbg_new_3a66822ed076951c = function(arg0, arg1) { + const ret = new Error(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_values_705f0abfa0ca41f6 = function(arg0) { const ret = getObject(arg0).values(); return addHeapObject(ret); }; - imports.wbg.__wbg_next_ddb3312ca1c4e32a = function() { + imports.wbg.__wbg_next_267398d0e0761bf9 = function() { return handleError(function(arg0) { const ret = getObject(arg0).next(); return addHeapObject(ret); }, arguments); }; - imports.wbg.__wbg_done_5c1f01fb660d73b5 = function(arg0) { + imports.wbg.__wbg_done_506b44765ba84b9c = function(arg0) { const ret = getObject(arg0).done; return ret; }; - imports.wbg.__wbg_value_1695675138684bd5 = function(arg0) { + imports.wbg.__wbg_value_31485d8770eb06ab = function(arg0) { const ret = getObject(arg0).value; return addHeapObject(ret); }; - imports.wbg.__wbg_instanceof_Uint8Array_d8d9cb2b8e8ac1d4 = function(arg0) { + imports.wbg.__wbg_instanceof_Uint8Array_4f5cffed7df34b2f = function(arg0) { let result; try { result = getObject(arg0) instanceof Uint8Array; - } catch { + } catch (_) { result = false; } const ret = result; @@ -484,7 +479,7 @@ function __wbg_get_imports() { getInt32Memory0()[arg0 / 4 + 1] = len1; getInt32Memory0()[arg0 / 4 + 0] = ptr1; }; - imports.wbg.__wbg_new_898a68150f225f2e = function() { + imports.wbg.__wbg_new_34c624469fb1d4fd = function() { const ret = new Array(); return addHeapObject(ret); }; @@ -492,15 +487,15 @@ function __wbg_get_imports() { const ret = getStringFromWasm0(arg0, arg1); return addHeapObject(ret); }; - imports.wbg.__wbg_push_ca1c26067ef907ac = function(arg0, arg1) { + imports.wbg.__wbg_push_906164999551d793 = function(arg0, arg1) { const ret = getObject(arg0).push(getObject(arg1)); return ret; }; - imports.wbg.__wbg_length_72e2208bbc0efc61 = function(arg0) { + imports.wbg.__wbg_length_f0764416ba5bb237 = function(arg0) { const ret = getObject(arg0).length; return ret; }; - imports.wbg.__wbg_set_5cf90238115182c3 = function(arg0, arg1, arg2) { + imports.wbg.__wbg_set_74906aa30864df5a = function(arg0, arg1, arg2) { getObject(arg0).set(getObject(arg1), arg2 >>> 0); }; imports.wbg.__wbindgen_throw = function(arg0, arg1) { diff --git a/wasm/index_bg.wasm b/wasm/index_bg.wasm index adbeb7cc..b315f8a5 100644 Binary files a/wasm/index_bg.wasm and b/wasm/index_bg.wasm differ