JavaScript documentationView source ↗
On this page

JavaScript / TypeScript API

cosmol_viewer.__setCkTypes(molecule: Function, protein: Function, element: Function) → void
cosmol_viewer.__setViewerTypes(selection: Function, sphere: Function, stick: Function, style: Function) → void
cosmol_viewer.bindingContractJson() → string
async cosmol_viewer.default(module_or_path?: InitInput | Promise<InitInput> | { module_or_path: InitInput | Promise<InitInput>; }) → Promise<InitOutput>

If module_or_path is {RequestInfo} or {URL}, makes a request and for everything else, calls WebAssembly.instantiate directly.

Arguments:
  • module_or_path? – Passing InitInput directly is deprecated.

cosmol_viewer.initSync(module: SyncInitInput | { module: SyncInitInput; }) → InitOutput

Instantiates the given module, which can either be bytes or a precompiled WebAssembly.Module.

Arguments:
  • module – Passing SyncInitInput directly is deprecated.

cosmol_viewer.select(source: Molecule | Protein) → Selector
class cosmol_viewer.Scene

Reusable scene state. Cloned binding handles refer to the same scene.

exported from cosmol_viewer_wasm.d

Members (30)
Scene.[Symbol․dispose]() → void
Scene.add(item: Molecule | Protein | Selection | Sphere | Stick, style?: Style | null) → void
Scene.cloneScene() → Scene

Explicitly copy scene display state into an independent scene.

Scene.free() → void
Scene.mergeShapes(other: Scene) → void
Scene.recenter(center: FloatArrayInput) → void
Scene.recenterOn(source: Molecule | Protein) → void
Scene.removeShape(id: string) → void
Scene.rotateCamera(azimuth_delta: number, elevation_delta: number, roll_delta: number) → void
Scene.set(name: string, item: Molecule | Protein | Selection | Sphere | Stick, style?: Style | null) → void
Scene.setAmbientLight(intensity: number) → void
Scene.setAutoRotate(enabled: boolean, speed: number) → void
Scene.setBackgroundColor(color: BytesInput) → void

RGB components are bytes in the range 0..255.

Scene.setCameraDistance(distance: number) → void
Scene.setCameraFov(fov: number) → void
Scene.setCameraTarget(target: FloatArrayInput) → void
Scene.setCameraView(azimuth: number, elevation: number, roll: number, distance: number, target: FloatArrayInput, fov: number) → void
Scene.setDepthCue(enabled: boolean) → void
Scene.setDepthCueColor(color: BytesInput) → void
Scene.setDepthCueRange(start: number, end: number) → void
Scene.setLightColor(color: BytesInput) → void
Scene.setLightIntensity(intensity: number) → void
Scene.setLighting(ambient: number, diffuse: number, specular: number, intensity: number, color: BytesInput) → void
Scene.setScale(scale: number) → void
Scene.setTransparentBackground(enabled: boolean) → void
Scene.setZoomDisabled(disabled: boolean) → void
Scene.shapeCount() → number
Scene.toJson() → string

Inspect display state; this serialization is not needed for render/update.

Scene.useBlackBackground() → void
static Scene.new() → Scene
class cosmol_viewer.Viewer

A browser renderer. Scene and animation arguments are typed, reusable handles.

exported from cosmol_viewer_wasm.d

Members (14)
Viewer.[Symbol․dispose]() → void
Viewer.cameraParameterLogging(enabled: boolean) → void
Viewer.close() → void

Stop rendering and release renderer resources. The caller-owned canvas remains.

Viewer.dispatch(payload: string) → void

Internal one-way notebook command ingress. Ordinary JS callers use update directly.

Viewer.free() → void
async Viewer.play(animation: Animation) → Promise<void>

Play an animation on this viewer’s canvas, replacing previous content.

async Viewer.render(scene: Scene) → Promise<void>

Render a scene on this viewer’s canvas, stopping any previous animation. First use starts the renderer; subsequent calls queue a new scene.

Viewer.showCameraParameters(enabled: boolean) → void

Show live camera parameters over the viewport, independently of logging.

Viewer.showFps(enabled: boolean) → void

Show renderer FPS. One diagnostic repaint shows zero after one second idle, without counting that repaint or renewing the idle timer.

async Viewer.takeScreenshot() → Promise<Uint8Array<ArrayBufferLike>>

Return PNG bytes to JavaScript. Notebook response transport is not supported.

Viewer.update(scene: Scene) → void

Queue a typed scene update. The renderer applies it on a subsequent frame.

static Viewer.new(canvas_id: string) → Viewer

Bind a viewer to an existing canvas ID without starting rendering. The caller owns canvas placement and dimensions.

static async Viewer.openNotebook(canvas_id: string, payload: string) → Promise<Viewer>

Internal notebook startup: payload is not the public JS scene API.

static async Viewer.playNotebook(canvas_id: string, payload: string) → Promise<Viewer>

Internal notebook animation startup, accepting the versioned transport envelope.

class cosmol_viewer.Animation

Reusable animation state. Added frames are scene snapshots, matching core behavior.

exported from cosmol_viewer_wasm.d

Members (10)
Animation.[Symbol․dispose]() → void
Animation.addFrame(scene: Scene) → void
Animation.frameCount() → number
Animation.free() → void
Animation.setInterpolate(interpolate: boolean) → void
Animation.setInterval(interval: number) → void
Animation.setLoops(loops: bigint) → void
Animation.setStaticScene(scene: Scene) → void
Animation.toJson() → string
static Animation.new(interval: number, loops: bigint, interpolate: boolean) → Animation
class cosmol_viewer.Selection

exported from cosmol_viewer_wasm.d

Members (7)
Selection.[Symbol․dispose]() → void
Selection.aromatic() → Selection
Selection.cloneSelection() → Selection

Copy the selection handle while sharing the same imported source.

Selection.element(element: Element) → Selection
Selection.free() → void
Selection.ids() → Uint32Array
Selection.len() → number
class cosmol_viewer.Selector

exported from cosmol_viewer_wasm.d

Members (5)
Selector.[Symbol․dispose]() → void
Selector.atoms() → Selection
Selector.bonds() → Selection
Selector.free() → void
Selector.residues() → Selection
interface cosmol_viewer.InitOutput

exported from cosmol_viewer_wasm.d

Members (108)
InitOutput.__wbindgen_externrefs

type: readonly Table

InitOutput.memory

type: readonly Memory

InitOutput.__externref_table_alloc() → number
InitOutput.__externref_table_dealloc(a: number) → void
InitOutput.__setCkTypes(a: any, b: any, c: any) → void
InitOutput.__setViewerTypes(a: any, b: any, c: any, d: any) → void
InitOutput.__wbg_animation_free(a: number, b: number) → void
InitOutput.__wbg_scene_free(a: number, b: number) → void
InitOutput.__wbg_selection_free(a: number, b: number) → void
InitOutput.__wbg_selector_free(a: number, b: number) → void
InitOutput.__wbg_sphere_free(a: number, b: number) → void
InitOutput.__wbg_stick_free(a: number, b: number) → void
InitOutput.__wbg_style_free(a: number, b: number) → void
InitOutput.__wbg_viewer_free(a: number, b: number) → void
InitOutput.__wbindgen_destroy_closure(a: number, b: number) → void
InitOutput.__wbindgen_exn_store(a: number) → void
InitOutput.__wbindgen_free(a: number, b: number, c: number) → void
InitOutput.__wbindgen_malloc(a: number, b: number) → number
InitOutput.__wbindgen_realloc(a: number, b: number, c: number, d: number) → number
InitOutput.__wbindgen_start() → void
InitOutput.animation_addFrame(a: number, b: number) → [number, number]
InitOutput.animation_frameCount(a: number) → [number, number, number]
InitOutput.animation_new(a: any, b: any, c: any) → [number, number, number]
InitOutput.animation_setInterpolate(a: number, b: any) → [number, number]
InitOutput.animation_setInterval(a: number, b: any) → [number, number]
InitOutput.animation_setLoops(a: number, b: any) → [number, number]
InitOutput.animation_setStaticScene(a: number, b: number) → [number, number]
InitOutput.animation_toJson(a: number) → [number, number, number, number]
InitOutput.bindingContractJson() → [number, number]
InitOutput.scene_add(a: number, b: any, c: number) → [number, number]
InitOutput.scene_cloneScene(a: number) → [number, number, number]
InitOutput.scene_mergeShapes(a: number, b: number) → [number, number]
InitOutput.scene_new() → [number, number, number]
InitOutput.scene_recenter(a: number, b: any) → [number, number]
InitOutput.scene_recenterOn(a: number, b: any) → [number, number]
InitOutput.scene_removeShape(a: number, b: any) → [number, number]
InitOutput.scene_rotateCamera(a: number, b: any, c: any, d: any) → [number, number]
InitOutput.scene_set(a: number, b: any, c: any, d: number) → [number, number]
InitOutput.scene_setAmbientLight(a: number, b: any) → [number, number]
InitOutput.scene_setAutoRotate(a: number, b: any, c: any) → [number, number]
InitOutput.scene_setBackgroundColor(a: number, b: any) → [number, number]
InitOutput.scene_setCameraDistance(a: number, b: any) → [number, number]
InitOutput.scene_setCameraFov(a: number, b: any) → [number, number]
InitOutput.scene_setCameraTarget(a: number, b: any) → [number, number]
InitOutput.scene_setCameraView(a: number, b: any, c: any, d: any, e: any, f: any, g: any) → [number, number]
InitOutput.scene_setDepthCue(a: number, b: any) → [number, number]
InitOutput.scene_setDepthCueColor(a: number, b: any) → [number, number]
InitOutput.scene_setDepthCueRange(a: number, b: any, c: any) → [number, number]
InitOutput.scene_setLightColor(a: number, b: any) → [number, number]
InitOutput.scene_setLightIntensity(a: number, b: any) → [number, number]
InitOutput.scene_setLighting(a: number, b: any, c: any, d: any, e: any, f: any) → [number, number]
InitOutput.scene_setScale(a: number, b: any) → [number, number]
InitOutput.scene_setTransparentBackground(a: number, b: any) → [number, number]
InitOutput.scene_setZoomDisabled(a: number, b: any) → [number, number]
InitOutput.scene_shapeCount(a: number) → [number, number, number]
InitOutput.scene_toJson(a: number) → [number, number, number, number]
InitOutput.scene_useBlackBackground(a: number) → [number, number]
InitOutput.select(a: any) → [number, number, number]
InitOutput.selection_aromatic(a: number) → [number, number, number]
InitOutput.selection_cloneSelection(a: number) → [number, number, number]
InitOutput.selection_element(a: number, b: any) → [number, number, number]
InitOutput.selection_ids(a: number) → [number, number, number, number]
InitOutput.selection_len(a: number) → [number, number, number]
InitOutput.selector_atoms(a: number) → [number, number, number]
InitOutput.selector_bonds(a: number) → [number, number, number]
InitOutput.selector_residues(a: number) → [number, number, number]
InitOutput.sphere_cloneShape(a: number) → [number, number, number]
InitOutput.sphere_color(a: number, b: any) → [number, number, number]
InitOutput.sphere_new(a: any, b: any) → [number, number, number]
InitOutput.sphere_opacity(a: number, b: any) → [number, number, number]
InitOutput.stick_cloneShape(a: number) → [number, number, number]
InitOutput.stick_color(a: number, b: any) → [number, number, number]
InitOutput.stick_new(a: any, b: any, c: any) → [number, number, number]
InitOutput.stick_opacity(a: number, b: any) → [number, number, number]
InitOutput.style_ballAndStick() → [number, number, number]
InitOutput.style_cartoon() → [number, number, number]
InitOutput.style_cloneStyle(a: number) → [number, number, number]
InitOutput.style_color(a: number, b: any) → [number, number, number]
InitOutput.style_configureSurface(a: number, b: any, c: any, d: any, e: any) → [number, number, number]
InitOutput.style_conformer(a: number, b: any) → [number, number, number]
InitOutput.style_coordinates2d(a: number) → [number, number, number]
InitOutput.style_metallic(a: number, b: any) → [number, number, number]
InitOutput.style_opacity(a: number, b: any) → [number, number, number]
InitOutput.style_outline(a: number, b: any, c: any) → [number, number, number]
InitOutput.style_rainbowResidues(a: number) → [number, number, number]
InitOutput.style_roughness(a: number, b: any) → [number, number, number]
InitOutput.style_scale(a: number, b: any) → [number, number, number]
InitOutput.style_sphere() → [number, number, number]
InitOutput.style_stick() → [number, number, number]
InitOutput.style_surface() → [number, number, number]
InitOutput.viewer_cameraParameterLogging(a: number, b: any) → [number, number]
InitOutput.viewer_close(a: number) → [number, number]
InitOutput.viewer_dispatch(a: number, b: any) → [number, number]
InitOutput.viewer_new(a: any) → [number, number, number]
InitOutput.viewer_openNotebook(a: any, b: any) → any
InitOutput.viewer_play(a: number, b: number) → any
InitOutput.viewer_playNotebook(a: any, b: any) → any
InitOutput.viewer_render(a: number, b: number) → any
InitOutput.viewer_showCameraParameters(a: number, b: any) → [number, number]
InitOutput.viewer_showFps(a: number, b: any) → [number, number]
InitOutput.viewer_takeScreenshot(a: number) → any
InitOutput.viewer_update(a: number, b: number) → [number, number]
InitOutput.wasm_bindgen_55eb0316a1aba24b___convert__closures_____invoke___bool__true_(a: number, b: number) → number
InitOutput.wasm_bindgen_55eb0316a1aba24b___convert__closures_____invoke___core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_55eb0316a1aba24b___JsValue___true_(a: number, b: number) → [number, number]
InitOutput.wasm_bindgen_55eb0316a1aba24b___convert__closures_____invoke___js_sys_bf3af387560c3d2e___Array______true_(a: number, b: number, c: any) → void
InitOutput.wasm_bindgen_55eb0316a1aba24b___convert__closures_____invoke___js_sys_bf3af387560c3d2e___Function_fn_wasm_bindgen_55eb0316a1aba24b___JsValue_____wasm_bindgen_55eb0316a1aba24b___sys__Undefined___js_sys_bf3af387560c3d2e___Function_fn_wasm_bindgen_55eb0316a1aba24b___JsValue_____wasm_bindgen_55eb0316a1aba24b___sys__Undefined_______true_(a: number, b: number, c: any, d: any) → void
InitOutput.wasm_bindgen_55eb0316a1aba24b___convert__closures_____invoke___wasm_bindgen_55eb0316a1aba24b___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_55eb0316a1aba24b___JsError___true_(a: number, b: number, c: any) → [number, number]
InitOutput.wasm_bindgen_55eb0316a1aba24b___convert__closures_____invoke___web_sys_10a5a83e01189a22___features__gen_Event__Event______true_(a: number, b: number, c: any) → void
class cosmol_viewer.Sphere

exported from cosmol_viewer_wasm.d

Members (6)
Sphere.[Symbol․dispose]() → void
Sphere.cloneShape() → Sphere
Sphere.color(rgb: BytesInput) → Sphere
Sphere.free() → void
Sphere.opacity(opacity: number) → Sphere
static Sphere.new(center: FloatArrayInput, radius: number) → Sphere
class cosmol_viewer.Stick

exported from cosmol_viewer_wasm.d

Members (6)
Stick.[Symbol․dispose]() → void
Stick.cloneShape() → Stick
Stick.color(rgb: BytesInput) → Stick
Stick.free() → void
Stick.opacity(opacity: number) → Stick
static Stick.new(start: FloatArrayInput, end: FloatArrayInput, radius: number) → Stick
class cosmol_viewer.Style

exported from cosmol_viewer_wasm.d

Members (18)
Style.[Symbol․dispose]() → void
Style.cloneStyle() → Style
Style.color(rgb: BytesInput) → Style
Style.configureSurface(probe_radius: number, grid_spacing: number, solvent_accessible: boolean, sharp_boundaries: boolean) → Style
Style.conformer(id: number) → Style
Style.coordinates2d() → Style
Style.free() → void
Style.metallic(value: number) → Style
Style.opacity(value: number) → Style
Style.outline(rgb: BytesInput, width: number) → Style
Style.rainbowResidues() → Style
Style.roughness(value: number) → Style
Style.scale(value: number) → Style
static Style.ballAndStick() → Style
static Style.cartoon() → Style
static Style.sphere() → Style
static Style.stick() → Style
static Style.surface() → Style
cosmol_viewer.BoolInput

type: boolean

cosmol_viewer.ByteInput

type: number

cosmol_viewer.BytesInput

type: Uint8Array

cosmol_viewer.DoubleInput

type: number

cosmol_viewer.FloatArrayInput

type: Float32Array

cosmol_viewer.FloatInput

type: number

cosmol_viewer.I16Input

type: number

cosmol_viewer.I32Input

type: number

cosmol_viewer.I8Input

type: number

cosmol_viewer.IndexInput

type: number

cosmol_viewer.InitInput

type: RequestInfo | URL | Response | BufferSource | WebAssembly.Module

cosmol_viewer.IntegerInput

type: bigint

cosmol_viewer.SignedIndexInput

type: number

cosmol_viewer.SyncInitInput

type: BufferSource | WebAssembly.Module

cosmol_viewer.TextInput

type: string

cosmol_viewer.U16Input

type: number

cosmol_viewer.U32Input

type: number

cosmol_viewer.UnsignedIntegerInput

type: bigint

Enumerations

cosmol_viewer.ChromaSampling

TypeScript enum.

ChromaSampling.Cs400

Value: 3.

ChromaSampling.Cs420

Value: 0.

ChromaSampling.Cs422

Value: 1.

ChromaSampling.Cs444

Value: 2.