/** * Copyright (c) 2023-2026 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Adam Midlik * @author David Sehnal */ import { StateObject } from '../../../mol-state/index.js'; import { Color } from '../../../mol-util/color/index.js'; import { ColorT } from '../tree/mvs/param-types.js'; /** Represents either the result or the reason of failure of an operation that might have failed */ export type Maybe = { ok: true; value: T; } | { ok: false; error: any; }; /** Try to await a promise and return an object with its result (if resolved) or with the error (if rejected) */ export declare function safePromise(promise: T): Promise>>; /** A map where values are arrays. Handles missing keys when adding values. */ export declare class MultiMap implements Mapping { private _map; /** Return the array of values assidned to a key (or `undefined` if no such values) */ get(key: K): V[] | undefined; /** Append value to a key (handles missing keys) */ add(key: K, value: V): void; } /** Basic subset of `Map`, only needs to have `get` method */ export type Mapping = Pick, 'get'>; /** Implementation of `Map` where keys are integers * and most keys are expected to be from interval `[0, limit)`. * For the keys within this interval, performance is better than `Map` (implemented by array). * For the keys out of this interval, performance is slightly worse than `Map`. */ export declare class NumberMap implements Mapping { readonly limit: K; private array; private map; constructor(limit: K); get(key: K): V | undefined; set(key: K, value: V): void; } /** Return `true` if `value` is not `undefined` or `null`. * Prefer this over `value !== undefined` * (for maybe if we want to allow `null` in `AnnotationRow` in the future) */ export declare function isDefined(value: T | undefined | null): value is T; /** Return `true` if at least one of `values` is not `undefined` or `null`. */ export declare function isAnyDefined(...values: any[]): boolean; /** Return filtered array containing all original elements except `undefined` or `null`. */ export declare function filterDefined(elements: (T | undefined | null)[]): T[]; /** Create an 16-hex-character hash for a given input string, e.g. 'spanish inquisition' -> '7f9ac4be544330be'*/ export declare function stringHash(input: string): string; /** Return type of elements in a set */ export type ElementOfSet = S extends Set ? T : never; /** Convert `colorString` (either X11 color name like 'magenta' or hex code like '#ff00ff') to Color. * If `colorString` contains a "split color" (e.g. 'red/white'), process only the first part. * Return `undefined` if `colorString` cannot be converted. */ export declare function decodeColor(colorString: string | number | undefined | null): Color | undefined; /** Utility functions for handling "split color" strings with primary and secondary color, e.g. 'red/white', '#ff0000/#ffffff'. * Regular color strings are treated as the same color repeated (e.g. 'red' == 'red/red'). */ export declare const SplitColor: { /** Return number-encoded colors before and after slash, or the same value twice if there is no slash. * e.g. 'red/white' -> [0xff0000, 0xffffff], 'red' -> [0xff0000, 0xff0000], * Throw error on invalid input. */ decodeStrict(colorString: string): [Color, Color]; /** Return number-encoded colors before and after slash, or the same value twice if there is no slash. * e.g. 'red/white' -> [0xff0000, 0xffffff], 'red' -> [0xff0000, 0xff0000], * Return `undefined` on invalid input. */ decode(colorString: string): [Color, Color] | undefined; /** Parse `colorString` into number-encoded colors before and after slash, or the same value twice if there is no slash. * Write result into `out`. * e.g. 'red/white' -> [0xff0000, 0xffffff], 'red' -> [0xff0000, 0xff0000], * Write [`undefined`, `undefined` on invalid input. */ decodeTo(colorString: string, out: [Color | undefined, Color | undefined]): void; /** Convert to hex code string, '#ff0000/#ffffff', '#ff0000' */ toHexStyle(primaryColor: Color, secondaryColor?: Color): ColorT; }; export declare function collectMVSReferences(type: T[], dependencies: Record): Record['data']>; export declare function getMVSReferenceObject(type: T[], dependencies: Record | undefined, ref: string): StateObject | undefined; /** Data structure for an array divided into contiguous groups */ export interface GroupedArray { /** Number of groups */ count: number; /** Get size of i-th group as `offsets[i+1]-offsets[i]`. * Get j-th element in i-th group as `grouped[offsets[i]+j]` */ offsets: number[]; /** Get j-th element in i-th group as `grouped[offsets[i]+j]` */ grouped: T[]; } export declare const GroupedArray: { getGroup(groupedArray: GroupedArray, iGroup: number): T[]; /** Return element indices grouped by `group_by(element, index)`. Elements with `group_by(element, index)===undefined` are treated as separate groups. */ groupIndices(elements: readonly T[], group_by: (element: T, index: number) => string | undefined): GroupedArray; };