@beeson-group/tycho 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/AUTHORS +7 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +14 -0
  4. package/README.md +38 -0
  5. package/THIRD_PARTY_NOTICES.md +68 -0
  6. package/dist/tycho.esm.js +515 -261
  7. package/dist/tycho.js +515 -261
  8. package/dist/types/container.d.ts +64 -0
  9. package/dist/types/errors.d.ts +10 -0
  10. package/dist/types/evaluate/clock.d.ts +30 -0
  11. package/dist/types/evaluate/frames.d.ts +63 -0
  12. package/dist/types/evaluate/index.d.ts +14 -0
  13. package/dist/types/evaluate/layers.d.ts +47 -0
  14. package/dist/types/evaluate/resolve.d.ts +39 -0
  15. package/dist/types/evaluate/sets.d.ts +49 -0
  16. package/dist/types/evaluate/types.d.ts +36 -0
  17. package/dist/types/index.d.ts +22 -0
  18. package/dist/types/runtime/colormaps.d.ts +10 -0
  19. package/dist/types/runtime/colors.d.ts +94 -0
  20. package/dist/types/runtime/element.d.ts +224 -0
  21. package/dist/types/runtime/export.d.ts +119 -0
  22. package/dist/types/runtime/geometry.d.ts +214 -0
  23. package/dist/types/runtime/icons.d.ts +56 -0
  24. package/dist/types/runtime/layout.d.ts +34 -0
  25. package/dist/types/runtime/overlay.d.ts +33 -0
  26. package/dist/types/runtime/readouts.d.ts +129 -0
  27. package/dist/types/runtime/renderer.d.ts +303 -0
  28. package/dist/types/runtime/state.d.ts +106 -0
  29. package/dist/types/runtime/tiles.d.ts +33 -0
  30. package/dist/types/scene.d.ts +37 -0
  31. package/dist/types/scene.gen.d.ts +440 -0
  32. package/dist/types/validate.d.ts +9 -0
  33. package/package.json +63 -35
  34. package/src/colormaps.ts +0 -42
  35. package/src/container.ts +0 -126
  36. package/src/element.ts +0 -1034
  37. package/src/frames.ts +0 -204
  38. package/src/index.ts +0 -14
  39. package/src/layout.ts +0 -82
  40. package/src/viewer.ts +0 -864
@@ -0,0 +1,64 @@
1
+ export type Dtype = 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'float32' | 'float64';
2
+ export type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
3
+ /** One named array, with its elements flat in C order (rule D4), its shape, and its dtype. */
4
+ export interface ArrayView {
5
+ readonly name: string;
6
+ readonly dtype: Dtype;
7
+ readonly shape: readonly number[];
8
+ readonly data: TypedArray;
9
+ }
10
+ /** The interface through which the evaluator reads arrays. `view` throws for a name that is missing. */
11
+ export interface DataStore {
12
+ has(name: string): boolean;
13
+ view(name: string): ArrayView;
14
+ }
15
+ /** A view stored as its little-endian bytes in C order, at `offset` in the payload. */
16
+ export interface RawViewInfo {
17
+ dtype: Dtype;
18
+ shape: number[];
19
+ encoding: 'raw';
20
+ offset: number;
21
+ length: number;
22
+ }
23
+ /** A view stored in chunks of `chunk_rows` rows, each an `[offset, length]` in the payload (rule D5). */
24
+ export interface EncodedViewInfo {
25
+ dtype: Dtype;
26
+ shape: number[];
27
+ encoding: 'shuffle-delta-deflate';
28
+ chunk_rows: number;
29
+ chunks: [number, number][];
30
+ }
31
+ export type ViewInfo = RawViewInfo | EncodedViewInfo;
32
+ export interface DataHeader {
33
+ format: 'tycho-data';
34
+ version: 1;
35
+ generator?: string;
36
+ meta?: Record<string, unknown>;
37
+ views: Record<string, ViewInfo>;
38
+ }
39
+ export declare const DATA_VERSION = 1;
40
+ export declare function isDtype(s: unknown): s is Dtype;
41
+ export declare function itemSize(dtype: Dtype): number;
42
+ /** A parsed data.tyd. Raw views are built once, on first access, and encoded views by `parse`. */
43
+ export declare class Container implements DataStore {
44
+ readonly header: DataHeader;
45
+ private readonly bytes;
46
+ private readonly payloadStart;
47
+ private readonly cache;
48
+ private constructor();
49
+ /**
50
+ * Parses a data container, checks rules D1 to D3 and D5 for every view, and decodes every encoded
51
+ * view. The decoding rejects a chunk that does not inflate to the byte length of its rows (rule D5).
52
+ */
53
+ static parse(input: ArrayBufferLike | ArrayBufferView): Promise<Container>;
54
+ has(name: string): boolean;
55
+ names(): string[];
56
+ view(name: string): ArrayView;
57
+ }
58
+ /** Decodes base64 text, ignoring whitespace. */
59
+ export declare function base64ToBytes(text: string): Uint8Array<ArrayBuffer>;
60
+ /**
61
+ * Decodes a file embedded in a page as text. The only encoding is `base64`, which the caller
62
+ * passes from the `data-encoding` attribute of the element. The function runs without a DOM.
63
+ */
64
+ export declare function decodeEmbedded(text: string, encoding?: string): Uint8Array<ArrayBuffer>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The one error type a reader throws. `rule` is the rule of spec/tycho-scene.md that the
3
+ * input breaks (`D2`, `F5`, ...), or the section number for a requirement stated without a
4
+ * rule number (`2.3`).
5
+ */
6
+ export declare class TychoError extends Error {
7
+ readonly rule: string;
8
+ constructor(rule: string, message: string);
9
+ }
10
+ export declare function fail(rule: string, message: string): never;
@@ -0,0 +1,30 @@
1
+ import { type Clock } from '../scene.js';
2
+ import type { SetData } from './sets.js';
3
+ /** Progress q in [0, 1) for a frame index, taken modulo `steps` (section 2.6). */
4
+ export declare function progress(steps: number, frameIndex: number): number;
5
+ /** The clock along one track, which holds the sample readings u_i of rule C1 and gives the reading of rule C2. */
6
+ export declare class TrackClock {
7
+ readonly m: number;
8
+ private readonly c0;
9
+ private readonly c1;
10
+ private readonly u;
11
+ constructor(set: SetData, track: number, channel: string);
12
+ /** The reading u_i at which sample `i` sits along the track (rule C1). */
13
+ at(i: number): number;
14
+ /** The track's reading at progress q (rule C2), possibly outside [0, 1] in value mode. */
15
+ reading(clock: Clock, q: number): number;
16
+ /** The segment k and weight w of the point at reading u in [0, 1] (rule C4). */
17
+ locate(u: number): {
18
+ k: number;
19
+ w: number;
20
+ };
21
+ }
22
+ /** The number of laps of rule C6, 1 when absent. Only a clock in fraction mode has laps. */
23
+ export declare function clockLaps(clock: Clock): number;
24
+ /** The lap of a loop reading and the within-lap reading there (rule C6). */
25
+ export declare function lapOf(loopReading: number, laps: number): {
26
+ lap: number;
27
+ u: number;
28
+ };
29
+ /** Applies `before` and `after` (rule C3) to a reading. Null means the track is hidden. */
30
+ export declare function bound(u: number, before?: 'clamp' | 'hidden', after?: 'clamp' | 'hidden'): number | null;
@@ -0,0 +1,63 @@
1
+ import { type ConstantScalar, type Frame, type Scalar, type Scene } from '../scene.js';
2
+ import type { SetData } from './sets.js';
3
+ import type { Vec3 } from './types.js';
4
+ export interface Context {
5
+ set: SetData;
6
+ track: number;
7
+ sample: number;
8
+ /** One lap lower than `lap` (rule L2). */
9
+ shifted: boolean;
10
+ /** The lap of rule C6, 0 when absent. */
11
+ lap?: number;
12
+ }
13
+ /** The value of a number, an attribute, or a channel in a context (section 2.2). */
14
+ export declare function scalarValue(s: Scalar | ConstantScalar, ctx: Context): number;
15
+ export declare class FrameTree {
16
+ private readonly frames;
17
+ private readonly depth;
18
+ /** Paths already found, by their two ends, since a transform takes the same path at every sample. */
19
+ private readonly paths;
20
+ readonly root: string;
21
+ constructor(frames: Record<string, Frame | undefined>);
22
+ has(id: string): boolean;
23
+ frame(id: string): Frame;
24
+ /** True when `id` is `ancestor` or below it. */
25
+ inSubtree(id: string, ancestor: string): boolean;
26
+ /**
27
+ * The edges from `a` to `b` (rule F3), each identified by its child frame. The edges in `up` are in the
28
+ * order taken inversely from `a`, and those in `down` in the order taken forward toward `b`.
29
+ */
30
+ path(a: string, b: string): {
31
+ up: readonly string[];
32
+ down: readonly string[];
33
+ };
34
+ }
35
+ export interface Requirements {
36
+ channels: Set<string>;
37
+ attrs: Set<string>;
38
+ }
39
+ export declare class Frames {
40
+ readonly tree: FrameTree;
41
+ private readonly scene;
42
+ private readonly active;
43
+ private readonly edges;
44
+ private readonly bodies;
45
+ constructor(scene: Scene);
46
+ private body;
47
+ private edgeOf;
48
+ /** Takes `p` from frame `from` to frame `to` in one context (rule F3). */
49
+ transform(p: Vec3, from: string, to: string, ctx: Context): Vec3;
50
+ /** A body's position in `frame` (section 2.4), with its attributes read from the context's track set. */
51
+ bodyPosition(bodyId: string, frame: string, ctx: Context): Vec3;
52
+ /**
53
+ * Applies the edge from `child`'s parent to `child` (rule F1), or its inverse. Only an origin at
54
+ * a body evaluates further edges, hence only there can an edge meet itself (rule F6).
55
+ */
56
+ private edge;
57
+ /**
58
+ * The channels and attributes a context's track set must carry to take a position from `from`
59
+ * to `to` (rule F5), through body origins too. It fails with rule F6 on an origin that depends on itself.
60
+ */
61
+ requirements(from: string, to: string, req?: Requirements): Requirements;
62
+ bodyRequirements(bodyId: string, frame: string, req?: Requirements): Requirements;
63
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The pure evaluator of section 3 of spec/tycho-scene.md. For every panel of a state, it returns
3
+ * the display frame and one entry per layer, computed in float64 throughout. It throws a TychoError
4
+ * for a scene it cannot evaluate. It does not run every check of validate().
5
+ */
6
+ import type { DataStore } from '../container.js';
7
+ import type { Scene, State } from '../scene.js';
8
+ import type { EvaluateResult } from './types.js';
9
+ export type * from './types.js';
10
+ /**
11
+ * Evaluates `state` at frame index `frameIndex` and returns, for every panel, the display frame and one entry per layer,
12
+ * the same answer as pytycho.evaluate. It throws a TychoError that gives the broken rule.
13
+ */
14
+ export declare function evaluate(scene: Scene, data: DataStore, state: State, frameIndex: number): EvaluateResult;
@@ -0,0 +1,47 @@
1
+ import type { BodyLayer, Clock, TrackLayer } from '../scene.js';
2
+ import { TrackClock } from './clock.js';
3
+ import type { Context, Frames } from './frames.js';
4
+ import type { PanelScope } from './resolve.js';
5
+ import type { SetData } from './sets.js';
6
+ import type { BodyLayerResult, TrackLayerResult, Vec3 } from './types.js';
7
+ /**
8
+ * A vertex is a stored sample or a point blended between samples k and k + 1, in the context of
9
+ * its lap of rule C6 (0 when absent). `shifted` puts it one lap lower (rule L2).
10
+ */
11
+ export type Vertex = {
12
+ sample: number;
13
+ shifted: boolean;
14
+ lap?: number;
15
+ } | {
16
+ k: number;
17
+ w: number;
18
+ shifted: boolean;
19
+ lap?: number;
20
+ };
21
+ export declare function point(tc: TrackClock, u: number, shifted: boolean, lap?: number): Vertex;
22
+ /** The polyline of a track between readings `ua` and `ub` within one lap (rule L1). */
23
+ export declare function polyline(tc: TrackClock, ua: number, ub: number, lap?: number): Vertex[];
24
+ /** The polyline between loop readings `ua <= ub` across laps (rule C6). Each joint keeps the first sample of the higher lap. */
25
+ export declare function loopPolyline(tc: TrackClock, ua: number, ub: number, laps: number): Vertex[];
26
+ /** Every sample of every lap, joined (rule C6). A track set that is not periodic has one lap. */
27
+ export declare function whole(m: number, laps: number, periodic: boolean): Vertex[];
28
+ /** The trail from loop reading `loopReading - laps * fraction` to `loopReading`, cut at 0 unless the track set is periodic (rules L2 and C6). */
29
+ export declare function trail(tc: TrackClock, loopReading: number, laps: number, fraction: number, periodic: boolean): Vertex[];
30
+ /** Whether a track layer gives a head (rule L3), i.e. whether its `head` is `true` or an object. */
31
+ export declare function hasHead(layer: TrackLayer): boolean;
32
+ /** Evaluates a vertex with `f`, which gives the position of a sample in a context (rule C4). */
33
+ export declare function vertexPosition(v: Vertex, set: SetData, track: number, f: (ctx: Context) => Vec3): Vec3;
34
+ export interface LayerEnv {
35
+ scope: PanelScope;
36
+ frames: Frames;
37
+ clock: Clock;
38
+ channel: string;
39
+ q: number;
40
+ display: string;
41
+ }
42
+ export declare function trackLayer(env: LayerEnv, layer: TrackLayer, set: SetData | null): TrackLayerResult;
43
+ /** The position and trail of a body layer (rule L4). The driver's reading is clamped to [0, 1], since a body layer does not have `before` or `after`. */
44
+ export declare function bodyLayer(env: LayerEnv, layer: BodyLayer, driver: {
45
+ set: SetData;
46
+ track: number;
47
+ } | null): BodyLayerResult;
@@ -0,0 +1,39 @@
1
+ import type { Layer, Layout, MemberRef, PanelState, Scene, SetQuery, State, StringValue, VarRef, Variable, VariableValue, View } from '../scene.js';
2
+ import type { SetData } from './sets.js';
3
+ /** One panel of one state, where a value is read. */
4
+ export interface PanelScope {
5
+ scene: Scene;
6
+ state: State;
7
+ panel: PanelState;
8
+ }
9
+ /** The definition of variable `id`, looked up by own property only, so that an id like "constructor" is not declared. */
10
+ export declare function variableDef(scene: Scene, id: string): Variable | undefined;
11
+ /** The value of variable `id` in a panel (rule V1). A panel-scoped variable takes the panel's value, and any other variable the scene's. */
12
+ export declare function variableValue(scope: PanelScope, id: string): VariableValue;
13
+ /** Whether a value fits its variable's kind (section 2.5). */
14
+ export declare function fits(v: Variable, value: unknown): boolean;
15
+ /**
16
+ * Checks that a state is valid as section 2.8 defines it. Every panel shows a declared view, the layout
17
+ * shows every panel once and does not repeat any, the clock channel is one of the scene's, and every
18
+ * value fits its variable. Undeclared variable ids are ignored.
19
+ */
20
+ export declare function checkState(scene: Scene, state: State): void;
21
+ export declare function layoutIds(node: Layout, out?: string[]): string[];
22
+ export declare function stringValue(scope: PanelScope, s: StringValue): VariableValue;
23
+ /** Every track set a query matches, in the order of `track_sets` (rule V2). */
24
+ export declare function querySets(scope: PanelScope, q: SetQuery): string[];
25
+ /** The one track set that the query of a layer or a driver matches (rule V2), null when the query does not match any and an error when it matches several. */
26
+ export declare function oneSet(scope: PanelScope, q: SetQuery): string | null;
27
+ /** The track a selector picks in the track set where the member reference or highlight that refers to the selector is resolved (section 2.5). */
28
+ export declare function selectorTrack(scope: PanelScope, ref: VarRef, set: SetData): number;
29
+ /** The tracks of `{"count": n}` (rule V3), i.e. every `step`-th track from 0, and the last track. */
30
+ export declare function sparse(tracks: number, n: number): number[];
31
+ /** The tracks that a member reference selects in a track set (rule V3), i.e. all of them, one by index, an evenly spaced subset, or a selector's track. */
32
+ export declare function members(scope: PanelScope, ref: MemberRef, set: SetData): number[];
33
+ export declare function driverMember(scope: PanelScope, ref: {
34
+ index: number;
35
+ } | VarRef, set: SetData): number;
36
+ /** The display frame of a view in a panel (section 2.7). */
37
+ export declare function displayFrame(scope: PanelScope, view: View): string;
38
+ /** Whether a layer is drawn, i.e. false while its `visible` toggle is off (rule L5). */
39
+ export declare function layerVisible(scope: PanelScope, layer: Layer): boolean;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Read access to one track set's arrays (spec section 2.1), checked against the shapes given in
3
+ * the same section. Every value is returned as a float64 number, whatever the stored dtype.
4
+ */
5
+ import type { DataStore, TypedArray } from '../container.js';
6
+ import { type Scene, type TrackSet } from '../scene.js';
7
+ import type { Vec3 } from './types.js';
8
+ export declare class SetData {
9
+ readonly id: string;
10
+ readonly def: TrackSet;
11
+ readonly tracks: number;
12
+ /** The number S of samples over all tracks. */
13
+ readonly samples: number;
14
+ readonly dim: 2 | 3;
15
+ private readonly data;
16
+ private readonly offsets;
17
+ private readonly positions;
18
+ private readonly channels;
19
+ private readonly parameters;
20
+ constructor(id: string, def: TrackSet, data: DataStore);
21
+ get periodic(): boolean;
22
+ /** Index of the first sample of track `t` in the concatenated arrays. */
23
+ start(t: number): number;
24
+ /** The number m of samples of track `t`. */
25
+ count(t: number): number;
26
+ /** Sample `i` of track `t`, in the track set's frame. A two-component position has z = 0. */
27
+ position(t: number, i: number): Vec3;
28
+ hasChannel(name: string): boolean;
29
+ /** The stored values of a channel, of shape (S,). `@index` does not have stored values. */
30
+ channel(name: string, rule?: string): TypedArray;
31
+ /**
32
+ * The value of a channel at sample `i` of track `t` (rule T4 for `@index`), raised by the
33
+ * channel's advance over the track once per lap (rules T2 and C6). A shifted context is one
34
+ * lap lower (rule L2).
35
+ */
36
+ channelAt(name: string, t: number, i: number, shifted: boolean, lap?: number): number;
37
+ /** The per-track values of a parameter, of shape (tracks,). */
38
+ parameter(name: string, rule?: string): TypedArray;
39
+ hasAttr(name: string): boolean;
40
+ attr(name: string): number;
41
+ }
42
+ /** One SetData per track set, built on first use. */
43
+ export declare class SetCache {
44
+ private readonly scene;
45
+ private readonly data;
46
+ private readonly sets;
47
+ constructor(scene: Scene, data: DataStore);
48
+ get(id: string): SetData;
49
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The value that `evaluate` returns, as section 3 of spec/tycho-scene.md defines it. Positions are
3
+ * plain arrays of three float64 numbers, thus JSON.stringify writes the result as it is.
4
+ */
5
+ export type Vec3 = [number, number, number];
6
+ export interface MemberResult {
7
+ index: number;
8
+ line: Vec3[];
9
+ /** Present only when the layer has `head: true`. Null while the track is hidden. */
10
+ head?: Vec3 | null;
11
+ }
12
+ export interface TrackLayerResult {
13
+ kind: 'track';
14
+ /** Null when the set query does not match any track set, and `members` is then empty. */
15
+ set: string | null;
16
+ members: MemberResult[];
17
+ }
18
+ export interface BodyLayerResult {
19
+ kind: 'body';
20
+ body: string;
21
+ /** Null when the view's driver does not resolve to a track. */
22
+ position: Vec3 | null;
23
+ /** Present only when the layer has a `trail`. */
24
+ trail?: Vec3[];
25
+ }
26
+ export interface MarkLayerResult {
27
+ kind: 'axes' | 'grid';
28
+ }
29
+ export type LayerResult = TrackLayerResult | BodyLayerResult | MarkLayerResult;
30
+ export interface PanelResult {
31
+ frame: string;
32
+ layers: LayerResult[];
33
+ }
34
+ export interface EvaluateResult {
35
+ panels: Record<string, PanelResult>;
36
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The TyCHO browser runtime: the scene format reader, its pure evaluator, and the
3
+ * `<tycho-viewer>` element, which is registered on load wherever custom elements exist.
4
+ * It is bundled as an immediately invoked function expression (IIFE) that exposes `tycho`, and as an ES module.
5
+ */
6
+ export { Container, DATA_VERSION, decodeEmbedded } from './container.js';
7
+ export type { ArrayView, DataHeader, DataStore, Dtype, EncodedViewInfo, RawViewInfo, TypedArray, ViewInfo } from './container.js';
8
+ export { TychoError } from './errors.js';
9
+ export { SCENE_MAJOR, SCENE_MINOR } from './scene.js';
10
+ export type * from './scene.js';
11
+ export { validate } from './validate.js';
12
+ export { evaluate } from './evaluate/index.js';
13
+ export type * from './evaluate/types.js';
14
+ export { TychoViewerElement, define } from './runtime/element.js';
15
+ export { EXPORT_LIMITS, sizePreset } from './runtime/export.js';
16
+ export type { ExportOptions, ExportSize, SizePreset } from './runtime/export.js';
17
+ export { formatNumber } from './runtime/readouts.js';
18
+ export { colormap, colormapCss } from './runtime/colormaps.js';
19
+ import { type TychoViewerElement } from './runtime/element.js';
20
+ import type { ExportOptions } from './runtime/export.js';
21
+ /** Exports a video of a viewer's current state and resolves to an MP4 blob. */
22
+ export declare function exportVideo(element: TychoViewerElement, options?: ExportOptions): Promise<Blob>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Small colormap lookup tables, sampled from matplotlib's maps, for coloring
3
+ * family members by their continuation parameter. The two single-hue maps are
4
+ * restricted to their brighter half so that the low end stays visible on black.
5
+ */
6
+ export type ColormapId = 'viridis' | 'plasma' | 'cividis' | 'blues' | 'reds';
7
+ /** The color of the colormap `id` at the position `t`, clamped to [0, 1], as RGB components in [0, 1] written into `out`. */
8
+ export declare function colormap(id: ColormapId, t: number, out?: number[]): number[];
9
+ /** The color of the colormap `id` at the position `t`, clamped to [0, 1], as a CSS `rgb()` string with components from 0 to 255. */
10
+ export declare function colormapCss(id: ColormapId, t: number): string;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Colors for drawing (section 2.7): the theme, a layer's color as a constant or a colormap over
3
+ * a parameter or a channel of its set, and the body colors. Colors are sRGB in [0, 1] and are
4
+ * written to the canvas as they are, without color management.
5
+ */
6
+ import type { SetData } from '../evaluate/sets.js';
7
+ import type { ColormapByChoice, ColormapName, ColorSpec, Scene } from '../scene.js';
8
+ import { type ColormapId } from './colormaps.js';
9
+ export type Rgb = [number, number, number];
10
+ export interface Theme {
11
+ background: string;
12
+ foreground: string;
13
+ grid: string;
14
+ }
15
+ export declare const DEFAULT_THEME: Theme;
16
+ export declare function sceneTheme(scene: Scene): Theme;
17
+ /** The palettes of the `theme` attribute of `<tycho-viewer>`, which match the dark and light modes of the Beeson group's slide theme. */
18
+ export declare const PALETTES: {
19
+ readonly dark: {
20
+ readonly background: '#050505';
21
+ readonly foreground: '#f2f2ef';
22
+ readonly grid: '#232320';
23
+ };
24
+ readonly light: {
25
+ readonly background: '#faf8f3';
26
+ readonly foreground: '#141413';
27
+ readonly grid: '#e3e0d8';
28
+ };
29
+ };
30
+ /**
31
+ * The value of a CSS color as `#rrggbb`, or null when `value` is empty or is not a color. A form other than `#rgb` and
32
+ * `#rrggbb` is read only in a browser, by painting it on a canvas. A canvas keeps its previous fill for a color that it rejects,
33
+ * hence such a color is detected by two different previous fills.
34
+ */
35
+ export declare function cssColorHex(value: string): string | null;
36
+ /**
37
+ * The theme that a viewer draws with. `base` is the scene's theme, a `name` of a palette replaces it, and a color read from one of
38
+ * the custom properties `--tycho-background`, `--tycho-foreground`, and `--tycho-grid` takes precedence over both.
39
+ */
40
+ export declare function hostTheme(base: Theme, name: string | null, read: (property: string) => string): Theme;
41
+ /** The brand colors of the viewer's controls (its chrome). Orange marks what is current, and violet what the pointer or the keyboard touches. */
42
+ export declare const ACCENT: {
43
+ readonly accent: '#f0a050';
44
+ readonly hover: '#ffb366';
45
+ readonly press: '#d98a3a';
46
+ readonly violet: '#c050f0';
47
+ readonly violetText: '#d98cff';
48
+ readonly error: '#ff7a7a';
49
+ };
50
+ /**
51
+ * The colors of the chrome as CSS custom properties. The neutrals are
52
+ * the theme's foreground mixed toward its background, and the orange and violet accents are
53
+ * fixed. Every value is a color, hence the result can be put into a style sheet as it is.
54
+ */
55
+ export declare function chromeTokens(theme: Theme): Record<string, string>;
56
+ /** Parses `hex`, written as `#rrggbb`, into three numbers in [0, 1], and returns white, [1, 1, 1], for any other string. */
57
+ export declare function hexRgb(hex: string): Rgb;
58
+ /** The color `a` blended toward `b` by the fraction `t`, as `#rrggbb`. */
59
+ export declare function mixHex(a: string, b: string, t: number): string;
60
+ /**
61
+ * A value's position on a colormap. The interval `range` maps to [0, 1], a value outside it is
62
+ * clamped, and the result maps onto the part of the colormap that `clip` specifies.
63
+ */
64
+ export declare function colormapPosition(value: number, range: readonly [number, number], clip?: readonly [number, number]): number;
65
+ /** A colormapped color's values over a set, one per track or one per sample, with its range and clip. */
66
+ export interface ColorScale {
67
+ id: ColormapId;
68
+ name: string;
69
+ perTrack: boolean;
70
+ values: ArrayLike<number>;
71
+ range: [number, number];
72
+ clip: [number, number];
73
+ }
74
+ /** A function from which a color reads a choice. It returns the current value of `variable`, or undefined when `variable` does not have one. */
75
+ export type ChoiceValue = (variable: string) => string | undefined;
76
+ /**
77
+ * The colormap given by `colormap`, or for a map keyed by a choice, its entry for the choice's
78
+ * current value. The map's first entry is used without a value or for a value that the map lacks.
79
+ */
80
+ export declare function colormapName(colormap: ColormapName | ColormapByChoice, value?: ChoiceValue): ColormapId;
81
+ export declare function colorScale(spec: Exclude<ColorSpec, string>, set: SetData, value?: ChoiceValue): ColorScale;
82
+ /** A layer's color on its set, either one constant or one color per sample (a track's color repeated over its samples). */
83
+ export type Coloring = {
84
+ kind: 'constant';
85
+ rgb: Rgb;
86
+ } | {
87
+ kind: 'sample';
88
+ rgb: Float32Array;
89
+ };
90
+ export declare function coloring(spec: ColorSpec | undefined, set: SetData, fallback: Rgb, value?: ChoiceValue): Coloring;
91
+ /** Colors along the part of a colormap that a scale uses, from 0 at the low end to 1 at the high end. */
92
+ export declare function gradientStops(scale: ColorScale, stops?: number): [number, string][];
93
+ /** A CSS gradient from the bottom up over the part of a colormap that a scale uses. */
94
+ export declare function gradientCss(scale: ColorScale, stops?: number): string;