molstar
Version:
A comprehensive macromolecular library.
39 lines (38 loc) • 1.34 kB
JavaScript
/**
* Copyright (c) 2025 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.queryMVSRef = queryMVSRef;
exports.createMVSRefMap = createMVSRefMap;
const mol_state_1 = require("../../mol-state");
/**
* Queries all MolViewSpec references in the current state of the plugin.
*/
function queryMVSRef(plugin, ref) {
return plugin.state.data.selectQ(q => q.root.subtree().withTag(`mvs-ref:${ref}`));
}
/**
* Creates a mapping of all MolViewSpec references in the current state of the plugin.
*/
function createMVSRefMap(plugin) {
const tree = plugin.state.data.tree;
const mapping = new Map();
mol_state_1.StateTree.doPreOrder(tree, tree.root, { mapping, plugin }, (n, _, s) => {
if (!n.tags)
return;
for (const tag of n.tags) {
if (!tag.startsWith('mvs-ref:'))
continue;
const mvsRef = tag.substring(8);
const selector = new mol_state_1.StateObjectSelector(n.ref, s.plugin.state.data);
if (s.mapping.has(mvsRef))
s.mapping.get(mvsRef).push(selector);
else
s.mapping.set(mvsRef, [selector]);
}
});
return mapping;
}
;