Skip to content

Commit

Permalink
build: update the wasm file
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Jul 3, 2022
1 parent 8dcb6ea commit a57b2d0
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 67 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- `v2`: Support for outputting simplified SVG strings, such as converting shapes(rect, circle, etc) to `<path>`.
- `v2`: Support WebAssembly.
- No need for node-gyp and postinstall, the `.node` file has been compiled for you.
- Cross-platform support, including [Apple M1](https://www.apple.com/newsroom/2020/11/apple-unleashes-m1/).
- Cross-platform support, including [Apple M Chips](https://www.apple.com/newsroom/2020/11/apple-unleashes-m1/).

## Installation

Expand Down Expand Up @@ -169,6 +169,19 @@ Running "resize width" suite...
```bash
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
```
Normally `wasm-pack` will install `wasm-bindgen` automatically, but if the installation [fails due to network reasons](https://github.com/rustwasm/wasm-pack-template/issues/44#issuecomment-521657516), please try to install it manually.
```bash
cargo install wasm-bindgen-cli
```

On computers with Apple M chips, the following error message may appear:
> Error: failed to download from https://github.com/WebAssembly/binaryen/releases/download/version_90/binaryen-version_90-x86_64-apple-darwin.tar.gz
Please install binaryen manually:
```bash
brew install binaryen
```


### Build Node.js bindings

Expand All @@ -195,7 +208,7 @@ please feel free to discuss with me or submit a PR.
- [x] Upgrade to napi-rs v2
- [x] Support WebAssembly
- [x] Output usvg-simplified SVG string
- [ ] Support for getting SVG Bounding box
- [x] Support for getting SVG Bounding box
- [ ] Support for generating more lossless bitmap formats, e.g. avif, webp, JPEG XL

## Release package
Expand Down
4 changes: 1 addition & 3 deletions wasm/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by dts-bundle-generator v6.9.0
// Generated by dts-bundle-generator v6.12.0

declare class BBox {
free(): void;
Expand All @@ -24,12 +24,10 @@ declare class RenderedImage {
asPng(): Uint8Array;
/**
* Get the PNG height
* @returns {number}
*/
readonly height: number;
/**
* Get the PNG width
* @returns {number}
*/
readonly width: number;
}
Expand Down
82 changes: 45 additions & 37 deletions wasm/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
"use strict";
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 __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 });
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 });
}
return target;
return to;
};
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);
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// wasm-binding.ts
var wasm_binding_exports = {};
__export(wasm_binding_exports, {
Resvg: () => Resvg2,
initWasm: () => initWasm
});
module.exports = __toCommonJS(wasm_binding_exports);

// wasm/dist/index.js
var wasm;
Expand Down Expand Up @@ -56,12 +53,12 @@ function takeObject(idx) {
return ret;
}
var WASM_VECTOR_LEN = 0;
var cachegetUint8Memory0 = null;
var cachedUint8Memory0;
function getUint8Memory0() {
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
if (cachedUint8Memory0.byteLength === 0) {
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8Memory0;
return cachedUint8Memory0;
}
var cachedTextEncoder = new TextEncoder("utf-8");
var encodeString = typeof cachedTextEncoder.encodeInto === "function" ? function(arg, view) {
Expand Down Expand Up @@ -107,12 +104,12 @@ function passStringToWasm0(arg, malloc, realloc) {
function isLikeNone(x) {
return x === void 0 || x === null;
}
var cachegetInt32Memory0 = null;
var cachedInt32Memory0;
function getInt32Memory0() {
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
if (cachedInt32Memory0.byteLength === 0) {
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32Memory0;
return cachedInt32Memory0;
}
var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
cachedTextDecoder.decode();
Expand Down Expand Up @@ -342,36 +339,33 @@ async function load(module2, imports) {
}
}
}
async function init(input) {
if (typeof input === "undefined") {
input = new URL("index_bg.wasm", void 0);
}
function getImports() {
const imports = {};
imports.wbg = {};
imports.wbg.__wbg_new_3047bf4b4f02b802 = function(arg0, arg1) {
imports.wbg.__wbg_new_651776e932b7e9c7 = 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_7af23f65f6c64548 = function(arg0) {
imports.wbg.__wbg_buffer_de1150f91b23aa89 = function(arg0) {
const ret = getObject(arg0).buffer;
return addHeapObject(ret);
};
imports.wbg.__wbg_newwithbyteoffsetandlength_ce1e75f0ce5f7974 = function(arg0, arg1, arg2) {
imports.wbg.__wbg_newwithbyteoffsetandlength_9ca61320599a2c84 = 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_cc9018bd6f283b6f = function(arg0) {
imports.wbg.__wbg_new_97cf52648830a70d = function(arg0) {
const ret = new Uint8Array(getObject(arg0));
return addHeapObject(ret);
};
imports.wbg.__wbg_instanceof_Uint8Array_edb92795fc0c63b4 = function(arg0) {
imports.wbg.__wbg_instanceof_Uint8Array_fd17ec67c77de602 = function(arg0) {
const ret = getObject(arg0) instanceof Uint8Array;
return ret;
};
Expand All @@ -383,35 +377,50 @@ async function init(input) {
getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
};
imports.wbg.__wbg_new_94fb1279cf6afea5 = function() {
imports.wbg.__wbg_new_2ab697f1555e0dbc = function() {
const ret = new Array();
return addHeapObject(ret);
};
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};
imports.wbg.__wbg_push_40c6a90f1805aa90 = function(arg0, arg1) {
imports.wbg.__wbg_push_811c8b08bf4ff9d5 = function(arg0, arg1) {
const ret = getObject(arg0).push(getObject(arg1));
return ret;
};
imports.wbg.__wbg_length_0acb1cf9bbaf8519 = function(arg0) {
imports.wbg.__wbg_length_e09c0b925ab8de5d = function(arg0) {
const ret = getObject(arg0).length;
return ret;
};
imports.wbg.__wbg_set_f25e869e4565d2a2 = function(arg0, arg1, arg2) {
imports.wbg.__wbg_set_a0172b213e2469e9 = function(arg0, arg1, arg2) {
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
};
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};
return imports;
}
function initMemory(imports, maybe_memory) {
}
function finalizeInit(instance, module2) {
wasm = instance.exports;
init.__wbindgen_wasm_module = module2;
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
return wasm;
}
async function init(input) {
if (typeof input === "undefined") {
input = new URL("index_bg.wasm", void 0);
}
const imports = getImports();
if (typeof input === "string" || typeof Request === "function" && input instanceof Request || typeof URL === "function" && input instanceof URL) {
input = fetch(input);
}
initMemory(imports);
const { instance, module: module2 } = await load(await input, imports);
wasm = instance.exports;
init.__wbindgen_wasm_module = module2;
return wasm;
return finalizeInit(instance, module2);
}
var dist_default = init;

Expand All @@ -431,4 +440,3 @@ var Resvg2 = class extends Resvg {
super(svg, JSON.stringify(options));
}
};
module.exports = __toCommonJS(wasm_binding_exports);
Loading

0 comments on commit a57b2d0

Please sign in to comment.