Redesign the VTK.wasm JavaScript API + docs overhaul#45
Open
jspanchu wants to merge 6 commits into
Open
Conversation
Replace the scattered VtkWASMLoader/createNamespace entry points with a single loadVtkWasm() that returns a cached VtkWasmRuntime, the factory for StandaloneSession and RemoteSession. Both sessions wrap their C++ handle as a private #native and expose dispose()/[Symbol.dispose] for clean teardown. - runtime.js: loadVtkWasm + VtkWasmRuntime (module cache, session factories) - standaloneSession.js / remoteSession.js: session wrappers with lifecycle - remoteSession: rely on user-provided canvas ids (bindCanvas) instead of a hard-coded internal selector; never create/remove canvas elements - index.js: public exports + <script id="vtk-wasm"> bootstrap - drop legacy (<9.5) support: sessionFactory, stateDecorators, dual-path branches in proxy/scriptLoader, and the old remote.js shims - vite: build from src/index.js (esm "index" + umd "vtk") BREAKING CHANGE: VtkWASMLoader, createNamespace, and the standalone/remote entry modules are removed in favor of loadVtkWasm() and runtime.create*Session().
Update the simple-app example and the plain-javascript demos to use
loadVtkWasm({ url }).createStandaloneSession().vtk instead of the removed
VtkWASMLoader/createNamespace API.
- package.json: collapse exports to the new "." (index) + "./viewer" entry points; add docs:api script (run before docs:dev/docs:build) - add TypeDoc (+ markdown/vitepress theme) and mermaid dev deps - typedoc.json + tsconfig.json: generate the API reference from source JSDoc into docs/api (allowJs, no TS migration) - gitignore the generated docs/api output
- new conceptual guides: Loading VTK.wasm (with a mermaid path diagram), Standalone Session, and Remote Session, each linking into the generated API reference rather than restating signatures - merge HTML Script Tag + Bundler Integration into "Adding VTK.wasm to a Project"; remove the JS Getting started page - reorder the "For JavaScript developers" sidebar and repoint inbound links - wire the TypeDoc-generated API reference into the nav/sidebar (expanded by default) and enable mermaid via vitepress-plugin-mermaid
The C++ vtkRemoteSession has no create/destroy, so creating or deleting objects through a remote session's vtk proxy would throw. Gate both on typeof checks: warn and return undefined/false instead. Document that a remote session can only control server-owned objects via getVtkObject.
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.
Summary
Replaces the scattered, confusingly-named loader/session API with a single, lean entry point and adds clean teardown. Also drops legacy (<9.5) support, regenerates the docs around the new API, and wires up an auto-generated API reference.
Motivation
The previous API had three pain points:
createNamespace()(free function),VtkWASMLoader.createNamespace(), andVtkWASMLoader.createStandaloneSession()— no canonical path.RemoteSessionclass shadowed the C++vtkRemoteSessionit wrapped (exposed as.sceneManager), andload()meant three different things.What changed
Core API
loadVtkWasm(options)→ cachedVtkWasmRuntime, the single factory for sessions.runtime.createStandaloneSession()/runtime.createRemoteSession(); the C++ handle is private (#native), andsession.vtkis the one way to the namespace.dispose()/[Symbol.dispose]on runtime and both sessions for real teardown (usingworks).RemoteSessionnow binds to user-provided canvas ids (bindCanvas) instead of a hard-coded internal selector, and never creates/removes canvas elements.sessionFactory,stateDecorators, and the dual-path branches inproxy/scriptLoader/remoteare gone.flowchart TD ST["HTML script tag (global vtkWASM)"] BD["Bundler import"] AN["Annotation script tag"] ST --> LF["loadVtkWasm(options)"] BD --> LF LF --> RT["VtkWasmRuntime — cached per url + config"] RT -->|createStandaloneSession| SS["StandaloneSession"] RT -->|createRemoteSession| RS["RemoteSession"] SS --> NS["session.vtk: create & render objects"] RS --> RW["bindNetwork + bindCanvas + update"] AN -.->|auto: loads + standalone session| NS NS --> DS["session.dispose()"] RW --> DS RT --> DR["runtime.dispose()"]Packaging — exports collapse to
.(index) +./viewer; vite builds fromsrc/index.js.Docs
Migration
new VtkWASMLoader(); await l.load(url, cfg, name)await loadVtkWasm({ url, ...cfg, wasmBaseName: name })createNamespace(url, cfg)(await loadVtkWasm({ url, ...cfg })).createStandaloneSession().vtknew RemoteSession(); await r.load(url, cfg)(await loadVtkWasm({ url, ...cfg })).createRemoteSession()remote.sceneManager.xxx()remote.vtk/remotemethods (#nativeis private)import … from "@kitware/vtk-wasm/vtk"//remoteimport { loadVtkWasm } from "@kitware/vtk-wasm"session.dispose(),runtime.dispose(),usingTesting
npm run build— ESM + both UMD bundles build clean.npm run lint— passes.npm run docs:build— builds with no dead links (only the pre-existing mermaid chunk-size advisory).