UNPKG

molstar

Version:

A comprehensive macromolecular library.

76 lines (75 loc) 3.3 kB
/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ import { ParamDefinition as PD } from '../../mol-util/param-definition'; export function paramsToMd(params) { return getParams(params, 0); } function paramInfo(param, offset) { switch (param.type) { case 'value': return 'Value'; case 'boolean': return 'true/false'; case 'number': return 'Numeric value'; case 'converted': return paramInfo(param.converted, offset); case 'conditioned': return getParams(param.conditionParams, offset); case 'multi-select': return "Array of ".concat(oToS(param.options)); case 'color': return 'Color as 0xrrggbb'; case 'color-list': return "A list of colors as 0xrrggbb"; case 'vec3': return "3D vector [x, y, z]"; case 'mat4': return "4x4 transformation matrix"; case 'url': return "URL couple with unique identifier"; case 'file': return "JavaScript File Handle"; case 'file-list': return "JavaScript FileList Handle"; case 'select': return "One of ".concat(oToS(param.options)); case 'value-ref': return "Reference to a runtime defined value."; case 'data-ref': return "Reference to a computed data value."; case 'text': return 'String'; case 'interval': return "Interval [min, max]"; case 'group': return "Object with:\n".concat(getParams(param.params, offset + 2)); case 'mapped': return "Object { name: string, params: object } where name+params are:\n".concat(getMapped(param, offset + 2)); case 'line-graph': return "A list of 2d vectors [xi, yi][]"; case 'object-list': return "Array of\n".concat(paramInfo(PD.Group(param.element), offset + 2)); // TODO: support more languages case 'script': return "An expression in the specified language { language: 'mol-script', expressiong: string }"; default: var _ = param; console.warn("".concat(_, " has no associated UI component")); return ''; } } function oToS(options) { return options.map(function (o) { return "'".concat(o[0], "'"); }).join(', '); } function offsetS(n) { return new Array(n + 1).join(' ') + '- '; } function getMapped(param, offset) { var ret = ''; for (var _i = 0, _a = param.select.options; _i < _a.length; _i++) { var n = _a[_i][0]; ret += offsetS(offset); ret += "**".concat(n, "**:\n"); ret += paramInfo(param.map(n), offset + 2); ret += '\n'; } return ret; } function getParams(params, offset) { var ret = ''; for (var _i = 0, _a = Object.keys(params); _i < _a.length; _i++) { var k = _a[_i]; var param = params[k]; ret += offsetS(offset); ret += "**".concat(k, "**").concat(param.isOptional ? '?:' : ':', " ").concat(paramInfo(param, offset)); // if (param.defaultValue) { // ret += ` = ${JSON.stringify(param.defaultValue)}`; // } if (param.description) { ret += " *(".concat(param.description, ")*"); } ret += '\n'; } return ret; }