/** * Copyright (c) 2018-2024 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose * @author David Sehnal */ import { Color as ColorData } from './color/index.js'; import { Vec2 as Vec2Data, Vec3 as Vec3Data, Mat4 as Mat4Data } from '../mol-math/linear-algebra.js'; import { Script as ScriptData } from '../mol-script/script.js'; import { Legend } from './legend.js'; import { ColorListName } from './color/lists.js'; import { Asset } from './assets.js'; import { ColorListEntry } from './color/color.js'; export declare namespace ParamDefinition { export interface Info { label?: string; description?: string; legend?: Legend; fieldLabels?: { [name: string]: string; }; isHidden?: boolean; shortLabel?: boolean; twoColumns?: boolean; isEssential?: boolean; category?: string; hideIf?: (currentGroup: any) => boolean; help?: (value: any) => { description?: string; legend?: Legend; }; } export const Essential: { isEssential: boolean; }; export interface Base extends Info { isOptional?: boolean; defaultValue: T; } export interface Optional extends Base { type: T['type']; } export function Optional(p: Base): Base; export interface Value extends Base { type: 'value'; } export function Value(defaultValue: T, info?: Info): Value; export type SelectOption = readonly [ /** Value of the option */ value: T, /** Human-readable label for UI */ label: string, /** Category, to group options in UI */ category?: string, /** More detailed description, tooltip in UI */ description?: string ]; export interface Select extends Base { type: 'select'; /** array of (value, label, category?, description?) tuples */ options: readonly SelectOption[]; cycle?: boolean; } export function Select(defaultValue: T, options: readonly SelectOption[], info?: Info & { cycle?: boolean; }): Select; export interface MultiSelect extends Base { type: 'multi-select'; /** array of (value, label) tuples */ options: readonly (readonly [E, string])[]; emptyValue?: string; } export function MultiSelect(defaultValue: E[], options: readonly (readonly [E, string])[], info?: Info & { emptyValue?: string; }): MultiSelect; export interface BooleanParam extends Base { type: 'boolean'; } export function Boolean(defaultValue: boolean, info?: Info): BooleanParam; export interface Text extends Base { type: 'text'; multiline?: boolean; placeholder?: string; disableInteractiveUpdates?: boolean; } export function Text(defaultValue?: string, info?: Info & { multiline?: boolean; placeholder?: string; disableInteractiveUpdates?: boolean; }): Text; export interface Color extends Base { type: 'color'; isExpanded?: boolean; } export function Color(defaultValue: ColorData, info?: Info & { isExpanded?: boolean; }): Color; export interface ColorList extends Base<{ kind: 'interpolate' | 'set'; colors: ColorListEntry[]; }> { type: 'color-list'; offsets: boolean; presetKind: 'all' | 'scale' | 'set'; } export function ColorList(defaultValue: { kind: 'interpolate' | 'set'; colors: ColorListEntry[]; } | ColorListName, info?: Info & { presetKind?: ColorList['presetKind']; offsets?: boolean; }): ColorList; export interface Vec3 extends Base, Range { type: 'vec3'; } export function Vec3(defaultValue: Vec3Data, range?: { min?: number; max?: number; step?: number; }, info?: Info): Vec3; export interface Mat4 extends Base { type: 'mat4'; } export function Mat4(defaultValue: Mat4Data, info?: Info): Mat4; export interface UrlParam extends Base { type: 'url'; } export function Url(url: string | { url: string; body?: string; }, info?: Info): UrlParam; export interface FileParam extends Base { type: 'file'; accept?: string; } export function File(info?: Info & { accept?: string; multiple?: boolean; }): FileParam; export interface FileListParam extends Base { type: 'file-list'; accept?: string; } export function FileList(info?: Info & { accept?: string; multiple?: boolean; }): FileListParam; export interface Range { /** If given treat as a range. */ min?: number; /** If given treat as a range. */ max?: number; /** * If given treat as a range. * If an `integer` parse value with parseInt, otherwise use parseFloat. */ step?: number; } export interface Numeric extends Base, Range { type: 'number'; immediateUpdate?: boolean; } export function Numeric(defaultValue: number, range?: { min?: number; max?: number; step?: number; }, info?: Info & { immediateUpdate?: boolean; }): Numeric; export interface Interval extends Base<[number, number]>, Range { type: 'interval'; } export function Interval(defaultValue: [number, number], range?: { min?: number; max?: number; step?: number; }, info?: Info): Interval; export interface LineGraph extends Base { type: 'line-graph'; getVolume?: () => unknown; } export function LineGraph(defaultValue: Vec2Data[], info?: Info & { getVolume?: (binCount?: number) => unknown; }): LineGraph; export interface Group extends Base { type: 'group'; params: Params; presets?: Select['options']; isExpanded?: boolean; isFlat?: boolean; pivot?: keyof T; } export function Group(params: For, info?: Info & { isExpanded?: boolean; isFlat?: boolean; customDefault?: any; pivot?: keyof T; presets?: Select['options']; }): Group>; export function EmptyGroup(info?: Info): Group>; export interface NamedParams { name: K; params: T; } export type NamedParamUnion

= K extends any ? NamedParams : never; export interface Mapped> extends Base { type: 'mapped'; select: Select; map(name: string): Any; } export function Mapped(defaultKey: string, names: ([string, string] | [string, string, string])[], map: (name: string) => Any, info?: Info & { cycle?: boolean; }): Mapped>; export function MappedStatic(defaultKey: keyof C, map: C, info?: Info & { options?: [keyof C, string][]; cycle?: boolean; }): Mapped>; export interface ObjectList extends Base { type: 'object-list'; element: Params; ctor(): T; getLabel(t: T): string; } export function ObjectList(element: For, getLabel: (e: T) => string, info?: Info & { defaultValue?: T[]; ctor?: () => T; }): ObjectList>; export interface ValueRef extends Base<{ ref: string; getValue: () => T; }> { type: 'value-ref'; resolveRef: (ref: string, getData: (ref: string) => any) => T; getOptions: (ctx: any) => Select['options']; } export function ValueRef(getOptions: ValueRef['getOptions'], resolveRef: ValueRef['resolveRef'], info?: Info & { defaultRef?: string; }): ValueRef; export interface DataRef extends Base<{ ref: string; getValue: () => T; }> { type: 'data-ref'; } export function DataRef(info?: Info & { defaultRef?: string; }): DataRef; export interface Converted extends Base { type: 'converted'; converted: Any; /** converts from prop value to display value */ fromValue(v: T): C; /** converts from display value to prop value */ toValue(v: C): T; } export function Converted(fromValue: (v: T) => C['defaultValue'], toValue: (v: C['defaultValue']) => T, converted: C): Converted; export interface Conditioned, C = { [k: string]: P; }> extends Base { type: 'conditioned'; select: Select; conditionParams: C; conditionForValue(v: T): keyof C; conditionedValue(v: T, condition: keyof C): T; } export function Conditioned, C extends {} = { [k: string]: P; }>(defaultValue: T, conditionParams: C, conditionForValue: (v: T) => keyof C, conditionedValue: (v: T, condition: keyof C) => T, info?: Info): Conditioned; export interface Script extends Base { type: 'script'; } export function Script(defaultValue: Script['defaultValue'], info?: Info): Script; export type Any = Value | Select | MultiSelect | BooleanParam | Text | Color | Vec3 | Mat4 | Numeric | FileParam | UrlParam | FileListParam | Interval | LineGraph | ColorList | Group | Mapped | Converted | Conditioned | Script | ObjectList | ValueRef | DataRef; export type Params = { [k: string]: Any; }; export type Values = { [k in keyof T]: T[k]['defaultValue']; }; /** This is required for params with optional values */ export type ValuesFor> = Normalize<{ [k in keyof T]: T[k]['defaultValue']; }>; type Optionals

= { [K in keyof P]-?: undefined extends P[K] ? K : never; }[keyof P]; type NonOptionals

= { [K in keyof P]-?: undefined extends P[K] ? never : K; }[keyof P]; export type Normalize

= Pick> & Partial>>; export type For

= { [K in keyof P]-?: Base; }; export type Def

= { [K in keyof P]: Any; }; export function For

(params: For

): For

; export function getDefaultValues(params: T): Values; export function resolveRefs(params: Params, values: any, getData: (ref: string) => any): void; export function setDefaultValues(params: T, defaultValues: Values): void; export function clone

(params: P): P; /** * List of [error text, pathToValue] * i.e. ['Missing Nested Id', ['group1', 'id']] */ export type ParamErrors = [string, string | string[]][]; export function validate(params: Params, values: any): ParamErrors | undefined; export function areEqual(params: Params, a: any, b: any): boolean; export function isParamEqual(p: Any, a: any, b: any): boolean; export function merge

(params: P, a: any, b: any): Values

; export function mergeParam(p: Any, a: any, b: any): any; export function normalizeParams(p: Params, value: any, defaultIfUndefined: 'all' | 'children' | 'skip'): any; /** * Map an object to a list of [K, string][] to be used as options, stringToWords for key used by default (or identity of null). * * if options is { [string]: string } and mapping is not provided, use the Value. */ export function objectToOptions(options: { [k in K]: V; }, f?: null | ((k: K, v: V) => string | [string, string])): [K, string][]; /** * Map array of options using stringToWords by default (or identity of null). */ export function arrayToOptions(xs: readonly V[], f?: null | ((v: V) => string)): [V, string][]; export function optionLabel(param: Select, value: T): string; export function withDefaults(schema: T, updates: Partial>): T; export {}; }