Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,18 @@ jobs:
with:
node-version: 18
cache: yarn
- name: Install
uses: dtolnay/rust-toolchain@master
- name: Rustup toolchain version
shell: bash
id: rustup-version
run: |
export RUST_TOOLCHAIN_VERSION="$(grep 'channel' rust-toolchain.toml | head -1 | awk -F '"' '{print $2}')"
echo "Rust toolchain version: $RUST_TOOLCHAIN_VERSION"
echo "RUST_TOOLCHAIN_VERSION=$RUST_TOOLCHAIN_VERSION" >> "$GITHUB_OUTPUT"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
if: ${{ !matrix.settings.docker }}
with:
toolchain: nightly-2023-12-11
toolchain: ${{ steps.rustup-version.outputs.RUST_TOOLCHAIN_VERSION }}
targets: ${{ matrix.settings.target }}
- name: Cache cargo
uses: actions/cache@v4
Expand Down Expand Up @@ -191,11 +198,20 @@ jobs:
with:
node-version: ${{ matrix.node }}

- name: Install
uses: actions-rs/toolchain@v1
- name: Rustup toolchain version
shell: bash
id: rustup-version
run: |
export RUST_TOOLCHAIN_VERSION="$(grep 'channel' rust-toolchain.toml | head -1 | awk -F '"' '{print $2}')"
echo "Rust toolchain version: $RUST_TOOLCHAIN_VERSION"
echo "RUST_TOOLCHAIN_VERSION=$RUST_TOOLCHAIN_VERSION" >> "$GITHUB_OUTPUT"

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
if: ${{ !matrix.settings.docker }}
with:
profile: minimal
override: true
toolchain: ${{ steps.rustup-version.outputs.RUST_TOOLCHAIN_VERSION }}
targets: ${{ matrix.settings.target }}

- name: Cache cargo
uses: Swatinem/rust-cache@v2
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ jobs:
with:
node-version: 16

- name: Install
uses: actions-rs/toolchain@v1
- name: Rustup toolchain version
shell: bash
id: rustup-version
run: |
export RUST_TOOLCHAIN_VERSION="$(grep 'channel' rust-toolchain.toml | head -1 | awk -F '"' '{print $2}')"
echo "Rust toolchain version: $RUST_TOOLCHAIN_VERSION"
echo "RUST_TOOLCHAIN_VERSION=$RUST_TOOLCHAIN_VERSION" >> "$GITHUB_OUTPUT"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
if: ${{ !matrix.settings.docker }}
with:
profile: minimal
override: true
toolchain: ${{ steps.rustup-version.outputs.RUST_TOOLCHAIN_VERSION }}
targets: ${{ matrix.settings.target }}
components: rustfmt, clippy

- name: Cache NPM dependencies
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ thiserror = "1.0.37"
png = "=0.17.5"
pathfinder_geometry = "0.5.1"
pathfinder_content = { version = "0.5.0", default-features = false }
pathfinder_simd = { version = "=0.5.2", features = ["pf-no-simd"] }
pathfinder_simd = { version = "=0.5.5", features = ["pf-no-simd"] }
futures = "0.3.21"
woff2 = "0.3.0"

Expand All @@ -30,16 +30,17 @@ mimalloc = "0.1"
mimalloc = { version = "0.1", features = ["local_dynamic_tls"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2.87"
# 暂时锁定 wasm-bindgen 版本,禁用 reference-types,Node.js 16 不支持。后面的 API 有较大变动:https://github.com/wasm-bindgen/wasm-bindgen/pull/3995#issuecomment-2295178639
wasm-bindgen = "=0.2.92"
js-sys = "0.3.64"
resvg = { version = "0.34.0", default-features = false, features = [
"raster-images",
"text",
] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
napi = { version = "2.16.0", features = ["serde-json", "async"] }
napi-derive = "2.16.0"
napi = { version = "2.16.17", features = ["serde-json", "async"] }
napi-derive = "2.16.13"
resvg = { version = "0.34.0", default-features = false, features = [
"raster-images",
"text",
Expand Down
5 changes: 4 additions & 1 deletion __test__/wasm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { jimpToRgbaPixels } from './helper'

// Init Wasm
test.before(async () => {
await initWasm(fs.readFile(join(__dirname, '../wasm/index_bg.wasm')))
const file = await fs.readFile(join(__dirname, '../wasm/index_bg.wasm'))
await initWasm(file)
// 暂时锁定 wasm-bindgen 版本,后面的 API 有较大变动:https://github.com/wasm-bindgen/wasm-bindgen/pull/3995#issuecomment-2295178639
// await initWasm({ module_or_path: file })
})

test.skip('Use href to load a JPG image without alpha', async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion js-binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/* auto-generated by NAPI-RS */

export function renderAsync(svg: string | Buffer, options?: string | undefined | null, signal?: AbortSignal | undefined | null): Promise<RenderedImage>
export declare function renderAsync(svg: string | Buffer, options?: string | undefined | null, signal?: AbortSignal | undefined | null): Promise<RenderedImage>
export declare class BBox {
x: number
y: number
Expand Down
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

4 changes: 4 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Use `rustup show` to view the currently installed version.
[toolchain]
channel = "1.86.0"
profile = "default"
15 changes: 5 additions & 10 deletions wasm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ var heap = new Array(128).fill(void 0);
heap.push(void 0, null, true, false);
var heap_next = heap.length;
function addHeapObject(obj) {
if (heap_next === heap.length)
heap.push(heap.length + 1);
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
Expand All @@ -42,8 +41,7 @@ function getObject(idx) {
return heap[idx];
}
function dropObject(idx) {
if (idx < 132)
return;
if (idx < 132) return;
heap[idx] = heap_next;
heap_next = idx;
}
Expand Down Expand Up @@ -87,8 +85,7 @@ function passStringToWasm0(arg, malloc, realloc) {
let offset = 0;
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 127)
break;
if (code > 127) break;
mem[ptr + offset] = code;
}
if (offset !== len) {
Expand Down Expand Up @@ -555,8 +552,7 @@ function __wbg_finalize_init(instance, module2) {
return wasm;
}
async function __wbg_init(input) {
if (wasm !== void 0)
return wasm;
if (wasm !== void 0) return wasm;
if (typeof input === "undefined") {
input = new URL("index_bg.wasm", void 0);
}
Expand Down Expand Up @@ -585,8 +581,7 @@ var Resvg2 = class extends Resvg {
* @param {ResvgRenderOptions | undefined} options
*/
constructor(svg, options) {
if (!initialized)
throw new Error("Wasm has not been initialized. Call `initWasm()` function.");
if (!initialized) throw new Error("Wasm has not been initialized. Call `initWasm()` function.");
const font = options?.font;
if (!!font && isCustomFontsOptions(font)) {
const serializableOptions = {
Expand Down
15 changes: 5 additions & 10 deletions wasm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ var heap = new Array(128).fill(void 0);
heap.push(void 0, null, true, false);
var heap_next = heap.length;
function addHeapObject(obj) {
if (heap_next === heap.length)
heap.push(heap.length + 1);
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
Expand All @@ -15,8 +14,7 @@ function getObject(idx) {
return heap[idx];
}
function dropObject(idx) {
if (idx < 132)
return;
if (idx < 132) return;
heap[idx] = heap_next;
heap_next = idx;
}
Expand Down Expand Up @@ -60,8 +58,7 @@ function passStringToWasm0(arg, malloc, realloc) {
let offset = 0;
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 127)
break;
if (code > 127) break;
mem[ptr + offset] = code;
}
if (offset !== len) {
Expand Down Expand Up @@ -528,8 +525,7 @@ function __wbg_finalize_init(instance, module) {
return wasm;
}
async function __wbg_init(input) {
if (wasm !== void 0)
return wasm;
if (wasm !== void 0) return wasm;
if (typeof input === "undefined") {
input = new URL("index_bg.wasm", void 0);
}
Expand Down Expand Up @@ -558,8 +554,7 @@ var Resvg2 = class extends Resvg {
* @param {ResvgRenderOptions | undefined} options
*/
constructor(svg, options) {
if (!initialized)
throw new Error("Wasm has not been initialized. Call `initWasm()` function.");
if (!initialized) throw new Error("Wasm has not been initialized. Call `initWasm()` function.");
const font = options?.font;
if (!!font && isCustomFontsOptions(font)) {
const serializableOptions = {
Expand Down
Binary file modified wasm/index_bg.wasm
Binary file not shown.
Loading