neco-view2d-wasm
WebAssembly bindings for neco-view2d. Exposes the View2d pan/zoom transform to JavaScript via wasm-bindgen.
JavaScript binding surface
WasmView2d mirrors the core pan, zoom, fit, and coordinate-conversion operations of neco-view2d and returns small fixed-shape arrays for JavaScript interop.
Usage
Build with wasm-pack build --target web, then import the generated package from JavaScript.
import init from "./pkg/neco_view2d_wasm.js";
await ;
const view = ;
// pan (dx, dy in canvas pixels, canvas_height)
view.;
// zoom at canvas point (delta, cx, cy, canvas_width, canvas_height)
view.;
// coordinate conversion (returns [x, y])
const = view.;
const = view.;
// fit world region into canvas
view.;
// get/set state: [center_x, center_y, view_size]
const = view.;
view.;
// zoom factor relative to a reference view_size
const factor = view.;
API
| Item | Description |
|---|---|
new WasmView2d() |
Create a default view -- center (0, 0), view_size 1.0 |
pan(dx, dy, canvas_height) |
Translate the view by (dx, dy) in canvas pixels |
zoom_at(delta, cx, cy, cw, ch) |
Zoom at canvas point (cx, cy); delta > 0 zooms in |
canvas_to_world(cx, cy, cw, ch) |
Canvas coordinates to world coordinates; returns [wx, wy] |
world_to_canvas(wx, wy, cw, ch) |
World coordinates to canvas coordinates; returns [cx, cy] |
fit(ww, wh, cw, ch) |
Fit a world region into the canvas with margin |
get_state() |
Returns [center_x, center_y, view_size] |
set_state(cx, cy, vs) |
Set view state directly |
zoom_factor(ref_view_size) |
Current zoom relative to a reference view_size |
License
MIT