@mkbabb/morph
v0.2.0
Published
WebAssembly bindings for the morph-core alignment pipeline.
Readme
@mkbabb/morph (morph-wasm)
WebAssembly bindings for morph-core, exposing the pairwise form alignment
pipeline to JavaScript and TypeScript. Published to npm as @mkbabb/morph.
Single export: alignForms(request) -> response.
The Cargo package is named morph (directory morph-wasm/); wasm-pack derives
the npm name @mkbabb/morph from the package name plus --scope mkbabb, not
from the directory.
Build
make wasm # from this directoryThis runs wasm-pack build --target web --release --scope mkbabb --out-dir pkg,
producing in pkg/:
package.json— npm manifest, name@mkbabb/morphmorph.js— ES-module loader (default asyncinit+ named exports)morph_bg.wasm— the compiled WebAssembly binarymorph.d.ts— TypeScript declarations
--target web is load-bearing: consumers import init, { alignForms } from the
single morph.js. A bundler-target rebuild would emit a different JS surface.
Consume
import init, { alignForms } from "@mkbabb/morph/morph.js";
await init();
const result = alignForms({
source: {
id: "b-stem",
subpaths: [{ role: "outer", segments: [...], signedArea: 42.0 }],
viewBox: [0, 0, 100, 100],
},
target: {
id: "b-bowl",
subpaths: [{ role: "outer", segments: [...], signedArea: 38.0 }],
viewBox: [0, 0, 100, 100],
},
hints: { // optional
subpathPairs: [{ source: 0, target: 1 }],
pointPairs: [{ sourceSubpath: 0, targetSubpath: 1, sourceIndex: 3, targetIndex: 3 }],
procrustes: false,
},
});
// result: { sourceFormId, targetFormId, pairs, unmatchedSource, unmatchedTarget }Test
wasm-pack test --node morph-wasm # from the workspace rootRuns the #[wasm_bindgen_test]s in tests/web.rs: an alignForms() round-trip
smoke test and a pointPairs-forwarding regression.
Layout
morph-wasm/
├── Cargo.toml # cdylib + rlib; [package] name = "morph"; path-deps morph-core
├── Makefile # `make wasm` / `make clean`
├── README.md # this file
├── src/
│ ├── lib.rs # panic-hook init + module re-exports
│ └── wire.rs # serde wire types + the JS-facing alignForms export
├── tests/
│ └── web.rs # #[wasm_bindgen_test] coverage
└── pkg/ # wasm-pack output, gitignored