Skip to content

Deprecated Molstar wrapper functions

marek edited this page Feb 8, 2026 · 1 revision
/**
 * Exports views together with local assets in the form of MVS.
 * Opens a file explorer for user to choose file location.
 * @param views views
 * @param assets assets
 */
export async function exportViewsAsMVSStory(
    views: ViewMetadata[],
    assets: FileData[],
) {
    if (!molstar) throw new Error("Molstar is not initialized!");

    const storyTitle: string | undefined = undefined; // TODO: enable user to enter a story title

    // Create a story.
    const story: Story = {
        assets: assets.map((fd) => ({
            path: fd.name,
            content: fd.content as Uint8Array<ArrayBuffer>,
        })),
        views: views,
        title: storyTitle,
    };

    // Builds MVSStory.
    const data = await buildMVSStory(story, true);

    // Create data blob out of MVSStory.
    const blob = createMVSBlob(data);

    // Let user download the story.
    const filename = `${storyTitle ? storyTitle : "export"}.${data instanceof Uint8Array ? "mvsx" : "mvsj"}`;
    download(blob, filename);
}

Clone this wiki locally