Add type definitions - #62
Open
jspanchu wants to merge 8 commits into
Open
Conversation
Adding "type": "module" flips Vite's default output extensions (.js for ES, .umd.cjs for UMD) and its default CSS asset names. Pin fileName and cssFileName in all three configs so the published artifact names (index.mjs, vtk.umd.js, viewer.umd.js, viewer.css) stay exactly as the exports map and script-tag consumers expect.
Every unprefixed plumbing member (id, obj, set, observe, unObserve, unObserveAll, userData, state, delete) shadowed the C++ member of the same name, making those VTK methods unreachable through the proxy. $ is not a legal character in C++ identifiers, so the prefix guarantees no future collision. toJSON/toString stay unprefixed because JSON.stringify and string coercion look them up by exactly those names. BREAKING CHANGE: proxy plumbing members are now $-prefixed, e.g. actor.delete() becomes actor.$delete() and camera.state becomes camera.$state.
The proxy used to accept any property name as a method and forward it blindly, so a typo surfaced as an opaque C++ error at invocation time. Build a method table from the per-class serdes manifests (types/*.json) shipped inside the .tar.gz bundle, or from a merged vtk-methods.json hosted next to loose .mjs/.wasm files, and reject unknown names with a TypeError naming the class. The table also carries the [[vtk::maysuspend]] flag: only those methods route through invokeAsync and return a Promise. Everything else now dispatches through invoke and returns its value synchronously, so callers no longer need await for ordinary calls. Bundles that ship no manifests keep the old forward-anything behaviour.
Zero-copy exchange of bulk data required reaching into Module.HEAPU8 and _malloc by hand. Expose the pointer primitives (alloc, free, copyToHeap, copyFromHeap, viewAt) as runtime.heapInterface, and layer the VTK-aware conversions (toVTKAoSArray, toJSTypedArray) on top as session.typedArrayInterface, since creating a vtkTypeXxxArray needs a session's vtk namespace. Widths come from the runtime's vtkType enum rather than from class names, so vtkIdTypeArray and friends read correctly on both wasm32 and wasm64.
Declares the runtime, both session classes and the proxy plumbing, plus the open interfaces (vtkObject, VtkNamespace, ...) that generated per-class declarations merge into via module augmentation. The loose index signature on VtkNamespace keeps untyped use compiling when no generated file is present. Ignore the generated output (types/generated.d.ts, **/vtk-wasm.gen.d.ts) in git and Prettier: it is derived from a specific VTK.wasm bundle and regenerated per project.
Emits a module-augmentation .d.ts from the per-class serdes manifests of a specific VTK.wasm bundle, so session.vtk is typed against the exact VTK version and architecture the app loads. Takes either a .tar.gz URL or a directory of vtk*.json manifests. Overload collapse in the manifests means a child class often redeclares an inherited member with an incompatible signature, so interfaces are emitted as extends Omit<Parent, redeclared...> and nominal brands are omitted to keep subclasses structurally assignable to their bases.
Covers generating per-bundle declarations with vtk-wasm gen-types and wiring them into a project. The vitepress config is reformatted by Prettier in the same pass; the only behavioural change is the new sidebar entry.
A minimal Vite + TypeScript app that regenerates its declarations from the bundle it loads (gen:types runs before dev and build) and typechecks in CI-style with tsc --noEmit, so the generated types stay honest against the VTK.wasm binary in public/.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.