@beeson-group/tycho 0.1.0 → 0.3.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.
- package/AUTHORS +8 -0
- package/LICENSE +202 -0
- package/NOTICE +14 -0
- package/README.md +38 -0
- package/THIRD_PARTY_NOTICES.md +68 -0
- package/dist/tycho.esm.js +1517 -760
- package/dist/tycho.js +1517 -760
- package/dist/types/container.d.ts +64 -0
- package/dist/types/errors.d.ts +9 -0
- package/dist/types/evaluate/clock.d.ts +36 -0
- package/dist/types/evaluate/frames.d.ts +63 -0
- package/dist/types/evaluate/index.d.ts +21 -0
- package/dist/types/evaluate/layers.d.ts +108 -0
- package/dist/types/evaluate/resolve.d.ts +50 -0
- package/dist/types/evaluate/sets.d.ts +50 -0
- package/dist/types/evaluate/timeline.d.ts +60 -0
- package/dist/types/evaluate/types.d.ts +87 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/runtime/colormaps.d.ts +10 -0
- package/dist/types/runtime/colors.d.ts +121 -0
- package/dist/types/runtime/element.d.ts +290 -0
- package/dist/types/runtime/export.d.ts +129 -0
- package/dist/types/runtime/geometry.d.ts +217 -0
- package/dist/types/runtime/icons.d.ts +66 -0
- package/dist/types/runtime/layout.d.ts +34 -0
- package/dist/types/runtime/outline.d.ts +29 -0
- package/dist/types/runtime/overlay.d.ts +33 -0
- package/dist/types/runtime/paint.d.ts +110 -0
- package/dist/types/runtime/raster.d.ts +33 -0
- package/dist/types/runtime/readouts.d.ts +136 -0
- package/dist/types/runtime/renderer.d.ts +551 -0
- package/dist/types/runtime/state.d.ts +104 -0
- package/dist/types/runtime/tiles.d.ts +33 -0
- package/dist/types/scene.d.ts +51 -0
- package/dist/types/scene.gen.d.ts +2033 -0
- package/dist/types/validate.d.ts +9 -0
- package/package.json +63 -35
- package/src/colormaps.ts +0 -42
- package/src/container.ts +0 -126
- package/src/element.ts +0 -1034
- package/src/frames.ts +0 -204
- package/src/index.ts +0 -14
- package/src/layout.ts +0 -82
- 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 `c-order`), its shape, and its dtype. */
|
|
4
|
+
export interface DataArray {
|
|
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. `array` throws for a name that is missing. */
|
|
11
|
+
export interface DataStore {
|
|
12
|
+
has(name: string): boolean;
|
|
13
|
+
array(name: string): DataArray;
|
|
14
|
+
}
|
|
15
|
+
/** An array stored as its little-endian bytes in C order, at `offset` in the payload. */
|
|
16
|
+
export interface RawArrayInfo {
|
|
17
|
+
dtype: Dtype;
|
|
18
|
+
shape: number[];
|
|
19
|
+
encoding: 'raw';
|
|
20
|
+
offset: number;
|
|
21
|
+
length: number;
|
|
22
|
+
}
|
|
23
|
+
/** An array stored in chunks of `chunk_rows` rows, each an `[offset, length]` in the payload (rule `shuffle-delta-deflate`). */
|
|
24
|
+
export interface EncodedArrayInfo {
|
|
25
|
+
dtype: Dtype;
|
|
26
|
+
shape: number[];
|
|
27
|
+
encoding: 'shuffle-delta-deflate';
|
|
28
|
+
chunk_rows: number;
|
|
29
|
+
chunks: [number, number][];
|
|
30
|
+
}
|
|
31
|
+
export type ArrayInfo = RawArrayInfo | EncodedArrayInfo;
|
|
32
|
+
export interface DataHeader {
|
|
33
|
+
format: 'tycho-data';
|
|
34
|
+
version: 2;
|
|
35
|
+
generator?: string;
|
|
36
|
+
meta?: Record<string, unknown>;
|
|
37
|
+
arrays: Record<string, ArrayInfo>;
|
|
38
|
+
}
|
|
39
|
+
export declare const DATA_VERSION = 2;
|
|
40
|
+
export declare function isDtype(s: unknown): s is Dtype;
|
|
41
|
+
export declare function itemSize(dtype: Dtype): number;
|
|
42
|
+
/** A parsed data.tyd. Raw arrays are built once, on first access, and encoded arrays 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 `array-dtype`, `array-keys`, `container-version`, and
|
|
51
|
+
* `shuffle-delta-deflate` for every array, and decodes every encoded array. The decoding rejects a chunk that does not inflate to the byte length of its rows (rule `shuffle-delta-deflate`).
|
|
52
|
+
*/
|
|
53
|
+
static parse(input: ArrayBufferLike | ArrayBufferView): Promise<Container>;
|
|
54
|
+
has(name: string): boolean;
|
|
55
|
+
names(): string[];
|
|
56
|
+
array(name: string): DataArray;
|
|
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,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one error type a reader throws. `rule` is the name of the rule of spec/tycho-scene.md that the
|
|
3
|
+
* input breaks, such as `array-keys`, `transform-channels`, or the section-level rule `frame`.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TychoError extends Error {
|
|
6
|
+
readonly rule: string;
|
|
7
|
+
constructor(rule: string, message: string);
|
|
8
|
+
}
|
|
9
|
+
export declare function fail(rule: string, message: string): never;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Clock, type LayerClock } from '../scene.js';
|
|
2
|
+
import type { SetData } from './sets.js';
|
|
3
|
+
/** Progress q in [0, 1) for a frame index, taken modulo the frame count (section 2.6). */
|
|
4
|
+
export declare function progress(frameCount: number, frameIndex: number): number;
|
|
5
|
+
/** The clock along one trajectory, which holds the sample readings u_i of rule `sample-fraction` and gives the reading of rule `clock-mode`. */
|
|
6
|
+
export declare class TrajectoryClock {
|
|
7
|
+
readonly m: number;
|
|
8
|
+
private readonly c0;
|
|
9
|
+
private readonly c1;
|
|
10
|
+
private readonly u;
|
|
11
|
+
constructor(set: SetData, trajectory: number, channel: string);
|
|
12
|
+
/** The reading u_i at which sample `i` sits along the trajectory (rule `sample-fraction`). */
|
|
13
|
+
at(i: number): number;
|
|
14
|
+
/** The trajectory's reading at progress q (rule `clock-mode`), possibly outside [0, 1] in epoch 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 `segment`). */
|
|
17
|
+
locate(u: number): {
|
|
18
|
+
k: number;
|
|
19
|
+
w: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** The number of revolutions of rule `revolutions`, 1 when absent. Only a clock in fraction mode has revolutions. */
|
|
23
|
+
export declare function clockRevolutions(clock: Clock): number;
|
|
24
|
+
/** The revolution of a loop reading and the within-revolution reading there (rule `revolutions`). */
|
|
25
|
+
export declare function revolutionOf(loopReading: number, revolutions: number): {
|
|
26
|
+
revolution: number;
|
|
27
|
+
u: number;
|
|
28
|
+
};
|
|
29
|
+
/** Applies `before` and `after` (rule `before-after`) to a reading. Null means the trajectory is hidden. */
|
|
30
|
+
export declare function bound(u: number, before?: 'clamp' | 'hidden', after?: 'clamp' | 'hidden'): number | null;
|
|
31
|
+
/**
|
|
32
|
+
* The clock of a layer with a clock of its own (rule `layer-clock`), as a clock in epoch mode on the layer's channel, whose loop lasts as
|
|
33
|
+
* long as the scene's, so that its keyframes read the same timeline. It does not have revolutions. The clock is checked and built once
|
|
34
|
+
* and returned again while the scene's clock keeps its frame count and its loop length, hence a caller must not change it.
|
|
35
|
+
*/
|
|
36
|
+
export declare function layerClock(scene: Clock, own: LayerClock): Clock;
|
|
@@ -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
|
+
trajectory: number;
|
|
7
|
+
sample: number;
|
|
8
|
+
/** One revolution lower than `revolution` (rule `trail-wrap`). */
|
|
9
|
+
shifted: boolean;
|
|
10
|
+
/** The revolution of rule `revolutions`, 0 when absent. */
|
|
11
|
+
revolution?: 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 `frame-path`), 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 `frame-path`). */
|
|
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 trajectory set. */
|
|
51
|
+
bodyPosition(bodyId: string, frame: string, ctx: Context): Vec3;
|
|
52
|
+
/**
|
|
53
|
+
* Applies the edge from `child`'s parent to `child` (rule `transform`), or its inverse. Only an origin at
|
|
54
|
+
* a body evaluates further edges, hence only there can an edge meet itself (rule `body-origin-cycle`).
|
|
55
|
+
*/
|
|
56
|
+
private edge;
|
|
57
|
+
/**
|
|
58
|
+
* The channels and attributes a context's trajectory set must carry to take a position from `from`
|
|
59
|
+
* to `to` (rule `transform-channels`), through body origins too. It fails with rule `body-origin-cycle` 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,21 @@
|
|
|
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 { Panel, Scene, State } from '../scene.js';
|
|
8
|
+
import { type Reference, type LayerEnv } from './layers.js';
|
|
9
|
+
import { SetCache } from './sets.js';
|
|
10
|
+
import type { CameraResult, EvaluateResult } from './types.js';
|
|
11
|
+
export type * from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Evaluates `state` at frame index `frameIndex` and returns, for every panel, the display frame and one entry per layer,
|
|
14
|
+
* the same answer as pytycho.evaluate. It throws a TychoError that gives the broken rule.
|
|
15
|
+
*/
|
|
16
|
+
export declare function evaluate(scene: Scene, data: DataStore, state: State, frameIndex: number): EvaluateResult;
|
|
17
|
+
/**
|
|
18
|
+
* The window of a 2d camera with keyframes at the environment's progress (rule `camera-keyframes`). A follow key's center is the mean of its targets'
|
|
19
|
+
* points, projected onto the plane, plus its offset, and its `center` when every target's set query fails to match.
|
|
20
|
+
*/
|
|
21
|
+
export declare function cameraAt(env: LayerEnv, panel: Panel, sets: SetCache, reference: Reference): CameraResult | null;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type ArrowLayer, type BodyLayer, type Clock, type LabelLayer, type InsetBoxLayer, type PointsLayer, type TrajectoriesLayer } from '../scene.js';
|
|
2
|
+
import { TrajectoryClock } from './clock.js';
|
|
3
|
+
import { type Context, type Frames } from './frames.js';
|
|
4
|
+
import type { PanelScope } from './resolve.js';
|
|
5
|
+
import type { SetData } from './sets.js';
|
|
6
|
+
import type { ArrowLayerResult, BodyLayerResult, LabelLayerResult, InsetBoxLayerResult, PointsLayerResult, TrajectoriesLayerResult, 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 revolution of rule `revolutions` (0 when absent). `shifted` puts it one revolution lower (rule `trail-wrap`).
|
|
10
|
+
*/
|
|
11
|
+
export type Vertex = {
|
|
12
|
+
sample: number;
|
|
13
|
+
shifted: boolean;
|
|
14
|
+
revolution?: number;
|
|
15
|
+
} | BlendVertex;
|
|
16
|
+
export type BlendVertex = {
|
|
17
|
+
k: number;
|
|
18
|
+
w: number;
|
|
19
|
+
shifted: boolean;
|
|
20
|
+
revolution?: number;
|
|
21
|
+
};
|
|
22
|
+
export declare function point(tc: TrajectoryClock, u: number, shifted: boolean, revolution?: number): BlendVertex;
|
|
23
|
+
/** The polyline of a trajectory between readings `ua` and `ub` within one revolution (rule `polyline`). */
|
|
24
|
+
export declare function polyline(tc: TrajectoryClock, ua: number, ub: number, revolution?: number): Vertex[];
|
|
25
|
+
/** The polyline between loop readings `ua <= ub` across revolutions (rule `revolutions`). Each joint keeps the first sample of the higher revolution. */
|
|
26
|
+
export declare function loopPolyline(tc: TrajectoryClock, ua: number, ub: number, revolutions: number): Vertex[];
|
|
27
|
+
/** Every sample of every revolution, joined (rule `revolutions`). A trajectory set that is not periodic has one revolution. */
|
|
28
|
+
export declare function whole(m: number, revolutions: number, periodic: boolean): Vertex[];
|
|
29
|
+
/** The trail from loop reading `loopReading - revolutions * fraction` to `loopReading`, cut at 0 unless the trajectory set is periodic (rules `trail-wrap` and `revolutions`). */
|
|
30
|
+
export declare function trail(tc: TrajectoryClock, loopReading: number, revolutions: number, fraction: number, periodic: boolean): Vertex[];
|
|
31
|
+
/** Whether a trajectories layer gives a head (rule `head`), i.e. whether its `head` is `true` or an object. */
|
|
32
|
+
export declare function hasHead(layer: TrajectoriesLayer): boolean;
|
|
33
|
+
/** Evaluates a vertex with `f`, which gives the position of a sample in a context (rule `segment`). */
|
|
34
|
+
export declare function vertexPosition(v: Vertex, set: SetData, trajectory: number, f: (ctx: Context) => Vec3): Vec3;
|
|
35
|
+
export interface LayerEnv {
|
|
36
|
+
scope: PanelScope;
|
|
37
|
+
frames: Frames;
|
|
38
|
+
clock: Clock;
|
|
39
|
+
channel: string;
|
|
40
|
+
q: number;
|
|
41
|
+
display: string;
|
|
42
|
+
/** The environment of the scene's clock, for a layer with a clock of its own (rule `layer-clock`), whose reference still reads the scene's clock. */
|
|
43
|
+
base?: LayerEnv;
|
|
44
|
+
}
|
|
45
|
+
/** The environment in which a layer takes its readings: the scene's, or one on the layer's own clock (rule `layer-clock`). */
|
|
46
|
+
export declare function layerEnv(env: LayerEnv, layer: {
|
|
47
|
+
clock?: TrajectoriesLayer['clock'];
|
|
48
|
+
}): LayerEnv;
|
|
49
|
+
/** The reference's trajectory, as a panel resolves it, or null when its set query does not match any set. */
|
|
50
|
+
export type Reference = {
|
|
51
|
+
set: SetData;
|
|
52
|
+
trajectory: number;
|
|
53
|
+
} | null;
|
|
54
|
+
/**
|
|
55
|
+
* The reference's clock and loop reading, and the point at the reading in its revolution. A body layer and a layer that reads from the reference lack `before` and `after`,
|
|
56
|
+
* thus the reading is clamped (rules `body-layer` and `read-from`). A caller that keeps the reference trajectory's clock on `env.channel` passes it as `tc`, which is otherwise built here.
|
|
57
|
+
*/
|
|
58
|
+
export declare function referencePoint(env: LayerEnv, reference: NonNullable<Reference>, tc?: TrajectoryClock): {
|
|
59
|
+
tc: TrajectoryClock;
|
|
60
|
+
loopReading: number;
|
|
61
|
+
at: BlendVertex;
|
|
62
|
+
};
|
|
63
|
+
/** The contexts of the reference trajectory's samples k and k + 1 at its point `at`, and the weight that blends them (rules `body-layer` and `read-from`). */
|
|
64
|
+
export declare function referenceContexts(reference: NonNullable<Reference>, at: BlendVertex): {
|
|
65
|
+
a: Context;
|
|
66
|
+
b: Context;
|
|
67
|
+
w: number;
|
|
68
|
+
};
|
|
69
|
+
export declare function trajectoriesLayer(env: LayerEnv, layer: TrajectoriesLayer, set: SetData | null, reference?: Reference): TrajectoriesLayerResult;
|
|
70
|
+
/** Checks the keys of an arrow layer that rule `arrow` restricts, and returns its vector channels and its scale. */
|
|
71
|
+
export declare function arrowParts(layer: ArrowLayer): {
|
|
72
|
+
vector: string[];
|
|
73
|
+
scale: ArrowLayer['scale'] & {};
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The base and the tip of each member's arrow at the reading (rule `arrow`). A caller that keeps the clocks of the set's trajectories on `env.channel` passes them as
|
|
77
|
+
* `clocks`, which are otherwise built here.
|
|
78
|
+
*/
|
|
79
|
+
export declare function arrowLayer(env: LayerEnv, layer: ArrowLayer, set: SetData | null, clocks?: (t: number) => TrajectoryClock): ArrowLayerResult;
|
|
80
|
+
/**
|
|
81
|
+
* Checks that the panel of an inset_box layer is declared, is not the declared panel `host` that holds the layer, and has a 2d camera
|
|
82
|
+
* (rule `inset-box`).
|
|
83
|
+
*/
|
|
84
|
+
export declare function checkInsetBoxPanel(scene: {
|
|
85
|
+
panels: Record<string, {
|
|
86
|
+
camera?: {
|
|
87
|
+
kind: string;
|
|
88
|
+
};
|
|
89
|
+
} | undefined>;
|
|
90
|
+
}, host: string, layer: InsetBoxLayer): void;
|
|
91
|
+
/**
|
|
92
|
+
* The target panel and frame of an inset_box layer, and the affine map from the target frame into the display frame at the reading of
|
|
93
|
+
* the reference trajectory (rule `inset-box`).
|
|
94
|
+
*/
|
|
95
|
+
export declare function insetBoxLayer(env: LayerEnv, layer: InsetBoxLayer, reference: Reference): InsetBoxLayerResult;
|
|
96
|
+
/** The position and trail of a body layer (rule `body-layer`). The reference's reading is clamped to [0, 1], since a body layer does not have `before` or `after`. */
|
|
97
|
+
export declare function bodyLayer(env: LayerEnv, layer: BodyLayer, reference: Reference): BodyLayerResult;
|
|
98
|
+
/**
|
|
99
|
+
* The point at the reading of member `k` of a set, clamped to [0, 1] as for a body (rule `body-layer`), in its revolution of rule `revolutions`, under the clock
|
|
100
|
+
* of `env`, transformed by `f`. This is the anchor of a label at a member (rule `label`) and the target of a camera keyframe (rule `camera-keyframes`).
|
|
101
|
+
*/
|
|
102
|
+
export declare function memberPoint(env: LayerEnv, set: SetData, k: number, f: (ctx: Context) => Vec3): Vec3;
|
|
103
|
+
/** The target of a camera keyframe (rule `camera-keyframes`): the point at the reading of member `k` of a trajectories layer, in the layer's context, or null when its set query does not match any set. */
|
|
104
|
+
export declare function targetPoint(env: LayerEnv, layer: TrajectoriesLayer, set: SetData | null, k: number, reference: Reference): Vec3 | null;
|
|
105
|
+
/** The position of a label's anchor (rule `label`), or null on the screen or when the anchor does not resolve. */
|
|
106
|
+
export declare function labelLayer(env: LayerEnv, layer: LabelLayer, set: SetData | null, reference: Reference): LabelLayerResult;
|
|
107
|
+
/** The drawn samples of each member of a points layer (rule `points`). */
|
|
108
|
+
export declare function pointsLayer(env: LayerEnv, layer: PointsLayer, set: SetData | null): PointsLayerResult;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Layer, Layout, MemberRef, ShownPanel, Scene, Panel, SetQuery, State, StringValue, InputRef, Input, InputValue } 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: ShownPanel;
|
|
8
|
+
}
|
|
9
|
+
/** The definition of input `id`, looked up by own property only, so that an id like "constructor" is not declared. */
|
|
10
|
+
export declare function inputDef(scene: Scene, id: string): Input | undefined;
|
|
11
|
+
/** The value of input `id` in a panel (rule `input-scope`). A per-panel input takes the panel's value, and any other input the scene's. */
|
|
12
|
+
export declare function inputValue(scope: PanelScope, id: string): InputValue;
|
|
13
|
+
/** Whether a value fits its input's kind (section 2.5). */
|
|
14
|
+
export declare function fits(v: Input, value: unknown): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Checks that a state is valid as section 2.8 defines it. Every shown panel names a declared panel, 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 input. Undeclared input 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): InputValue;
|
|
23
|
+
/** Every trajectory set a query matches, in the order of `trajectory_sets` (rule `set-query`). */
|
|
24
|
+
export declare function querySets(scope: PanelScope, q: SetQuery): string[];
|
|
25
|
+
/** The one trajectory set that the query of a layer or a reference matches (rule `set-query`), 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
|
+
/**
|
|
28
|
+
* The member that an input of kind parameter picks in the trajectory set where the member reference or highlight that refers
|
|
29
|
+
* to the input is resolved, i.e. the member whose value of the parameter is nearest, the lowest index on a tie (section 2.5).
|
|
30
|
+
*/
|
|
31
|
+
export declare function parameterMember(scope: PanelScope, ref: InputRef, set: SetData): number;
|
|
32
|
+
/** The members of `{"evenly_spaced": n}` (rule `members`), i.e. every `step`-th trajectory from 0, and the last trajectory. */
|
|
33
|
+
export declare function sparse(trajectories: number, n: number): number[];
|
|
34
|
+
/** The trajectories that a member reference selects in a trajectory set (rule `members`), i.e. all of them, one by index, an evenly spaced subset, or the member of an input of kind parameter. */
|
|
35
|
+
export declare function members(scope: PanelScope, ref: MemberRef, set: SetData): number[];
|
|
36
|
+
export declare function referenceMember(scope: PanelScope, ref: {
|
|
37
|
+
index: number;
|
|
38
|
+
} | InputRef, set: SetData): number;
|
|
39
|
+
/**
|
|
40
|
+
* The target of an inset_box layer, i.e. the first shown panel in layout order that names declared panel `panelId`, and its display
|
|
41
|
+
* frame read with its own values of the inputs (rule `inset-box`), or null when the layout does not show the declared panel.
|
|
42
|
+
*/
|
|
43
|
+
export declare function insetBoxTarget(scope: PanelScope, panelId: string): {
|
|
44
|
+
shown: string;
|
|
45
|
+
frame: string;
|
|
46
|
+
} | null;
|
|
47
|
+
/** The display frame of a declared panel where it is shown (section 2.7). */
|
|
48
|
+
export declare function displayFrame(scope: PanelScope, panel: Panel): string;
|
|
49
|
+
/** Whether a layer is drawn, i.e. false while its `visible` toggle is off (rule `visible`). */
|
|
50
|
+
export declare function layerVisible(scope: PanelScope, layer: Layer): boolean;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read access to one trajectory 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 TrajectorySet } from '../scene.js';
|
|
7
|
+
import type { Vec3 } from './types.js';
|
|
8
|
+
export declare class SetData {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly def: TrajectorySet;
|
|
11
|
+
readonly trajectories: number;
|
|
12
|
+
/** The number S of samples over all trajectories. */
|
|
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: TrajectorySet, data: DataStore);
|
|
21
|
+
get periodic(): boolean;
|
|
22
|
+
/** Index of the first sample of trajectory `t` in the concatenated arrays. */
|
|
23
|
+
start(t: number): number;
|
|
24
|
+
/** The number m of samples of trajectory `t`. */
|
|
25
|
+
count(t: number): number;
|
|
26
|
+
/** Sample `i` of trajectory `t`, in the trajectory 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 trajectory `t` (rule `index-channel` for `@index`), raised by the
|
|
33
|
+
* channel's advance over the trajectory once per revolution (rules `periodic` and `revolutions`). A shifted context is one
|
|
34
|
+
* revolution lower (rule `trail-wrap`).
|
|
35
|
+
*/
|
|
36
|
+
channelAt(name: string, t: number, i: number, shifted: boolean, revolution?: number): number;
|
|
37
|
+
hasParameter(name: string): boolean;
|
|
38
|
+
/** The values of a parameter, one per member, of shape (trajectories,). The built-in parameter `@index` has the value `t` for member `t`. */
|
|
39
|
+
parameter(name: string, rule?: string): TypedArray;
|
|
40
|
+
hasAttr(name: string): boolean;
|
|
41
|
+
attr(name: string): number;
|
|
42
|
+
}
|
|
43
|
+
/** One SetData per trajectory set, built on first use. */
|
|
44
|
+
export declare class SetCache {
|
|
45
|
+
private readonly scene;
|
|
46
|
+
private readonly data;
|
|
47
|
+
private readonly sets;
|
|
48
|
+
constructor(scene: Scene, data: DataStore);
|
|
49
|
+
get(id: string): SetData;
|
|
50
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Camera, Clock, Opacity, Size } from '../scene.js';
|
|
2
|
+
/** Seconds one revolution of the clock lasts at speed 1, whatever its frame count. */
|
|
3
|
+
export declare const REVOLUTION_SECONDS = 8;
|
|
4
|
+
export declare const EASES: readonly string[];
|
|
5
|
+
/** A keyframe as the scene gives it, `[t, v]` or `[t, v, ease]`. */
|
|
6
|
+
export type Keyframe = readonly unknown[];
|
|
7
|
+
/** The seconds that one loop of the clock lasts at speed 1: its `seconds` when given, else REVOLUTION_SECONDS for each of its revolutions (rule `revolutions`). */
|
|
8
|
+
export declare function loopSeconds(clock: Pick<Clock, 'seconds' | 'revolutions'> & Partial<Clock>): number;
|
|
9
|
+
/** The time of the timeline at progress `q`, `s = q * L` (section 2.11). */
|
|
10
|
+
export declare function timeAt(clock: Pick<Clock, 'seconds' | 'revolutions'> & Partial<Clock>, q: number): number;
|
|
11
|
+
/** The ease E(x) of rule `ease`. */
|
|
12
|
+
export declare function ease(name: unknown, x: number): number;
|
|
13
|
+
/** Checks a list of keyframes (rules `keyframes` and `ease`), with numbers for values unless `values` says otherwise, and returns it. */
|
|
14
|
+
export declare function checkKeyframes(keys: unknown, what: string, values?: (v: unknown) => boolean): Keyframe[];
|
|
15
|
+
/**
|
|
16
|
+
* The segment of a list of keyframes at time `s` (rule `keyframes`): the index `i` of the last keyframe at or before `s`, and the eased
|
|
17
|
+
* weight `e` toward keyframe `i + 1`, or `e = null` when `s` lies before the first keyframe (i = 0) or at or after the last.
|
|
18
|
+
*/
|
|
19
|
+
export declare function segmentAt(times: (i: number) => number, count: number, s: number, easeOf: (i: number) => unknown): {
|
|
20
|
+
i: number;
|
|
21
|
+
e: number | null;
|
|
22
|
+
};
|
|
23
|
+
/** The value of a list of keyframes at time `s` (rule `keyframes`). */
|
|
24
|
+
export declare function keyframesValue(keys: readonly Keyframe[], s: number): number;
|
|
25
|
+
/** A number that may be keyframed, at time `s`, or `fallback` when it is absent. */
|
|
26
|
+
export declare function numberAt(value: number | {
|
|
27
|
+
keyframes: unknown;
|
|
28
|
+
} | undefined, s: number, fallback: number): number;
|
|
29
|
+
/** An opacity that may be keyframed, at time `s`, clamped into [0, 1]. */
|
|
30
|
+
export declare function opacityAt(value: Opacity | undefined, s: number, fallback?: number): number;
|
|
31
|
+
/** A size that may be keyframed, at time `s`, never below zero. */
|
|
32
|
+
export declare function sizeAt(value: Size | undefined, s: number, fallback: number): number;
|
|
33
|
+
/** Checks a number that may be keyframed, whose values `ok` accepts, e.g. an opacity in [0, 1]. */
|
|
34
|
+
export declare function checkKeyframed(value: unknown, what: string, ok: (v: unknown) => boolean, rule?: string): void;
|
|
35
|
+
export declare const isOpacity: (v: unknown) => boolean;
|
|
36
|
+
/** A value of the keyframes of a split (section 2.11), the share of its first side, in [0, 1]. */
|
|
37
|
+
export declare const isShare: (v: unknown) => boolean;
|
|
38
|
+
export declare const isPositive: (v: unknown) => boolean;
|
|
39
|
+
/** The shared value of a clock in epoch mode at progress `q`, by its range (rule `clock-mode`) or its keyframes (rule `clock-keyframes`). */
|
|
40
|
+
export declare function clockValue(clock: Clock, q: number): number;
|
|
41
|
+
/** The two axes of a 2d camera's plane, as indices of x, y, and z. */
|
|
42
|
+
export declare function planeAxes(cam: {
|
|
43
|
+
plane?: 'xy' | 'xz' | 'yz';
|
|
44
|
+
}): [number, number];
|
|
45
|
+
export type CameraKeyframe = NonNullable<Extract<Camera, {
|
|
46
|
+
kind: '2d';
|
|
47
|
+
}>['keyframes']>[number];
|
|
48
|
+
/** The window of a camera at a time (rule `camera-keyframes`), with `height` null when the panel's aspect ratio gives it. */
|
|
49
|
+
export interface CameraWindow {
|
|
50
|
+
center: [number, number];
|
|
51
|
+
width: number;
|
|
52
|
+
height: number | null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The window of a camera with keyframes at time `s` (rule `camera-keyframes`). `center(i)` gives the center of keyframe `i` at `s`, a follow keyframe's
|
|
56
|
+
* mean of its targets plus its offset, or null when the keyframe does not have a center then.
|
|
57
|
+
*/
|
|
58
|
+
export declare function cameraWindow(keys: readonly CameraKeyframe[], s: number, center: (i: number) => [number, number] | null): CameraWindow | null;
|
|
59
|
+
/** Checks the keyframes of a 2d camera (rule `camera-keyframes`), apart from the targets of its follow keyframes, which need the layers of the panel. */
|
|
60
|
+
export declare function checkCameraKeyframes(keys: unknown, free: boolean, what: string): void;
|
|
@@ -0,0 +1,87 @@
|
|
|
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 trajectory is hidden. */
|
|
10
|
+
head?: Vec3 | null;
|
|
11
|
+
}
|
|
12
|
+
export interface TrajectoriesLayerResult {
|
|
13
|
+
kind: 'trajectories';
|
|
14
|
+
/** Null when the set query does not match any trajectory set, and `members` is then empty. */
|
|
15
|
+
set: string | null;
|
|
16
|
+
members: MemberResult[];
|
|
17
|
+
}
|
|
18
|
+
export interface ArrowMemberResult {
|
|
19
|
+
index: number;
|
|
20
|
+
/** The point at the reading. Null while the trajectory is hidden. */
|
|
21
|
+
base: Vec3 | null;
|
|
22
|
+
/** The base displaced by `scale` times the vector, blended in the same way. Null while the trajectory is hidden. */
|
|
23
|
+
tip: Vec3 | null;
|
|
24
|
+
}
|
|
25
|
+
export interface ArrowLayerResult {
|
|
26
|
+
kind: 'arrow';
|
|
27
|
+
/** Null when the set query does not match any trajectory set, and `members` is then empty. */
|
|
28
|
+
set: string | null;
|
|
29
|
+
members: ArrowMemberResult[];
|
|
30
|
+
}
|
|
31
|
+
export interface InsetBoxLayerResult {
|
|
32
|
+
kind: 'inset_box';
|
|
33
|
+
/** The declared panel whose window the box outlines. */
|
|
34
|
+
panel: string;
|
|
35
|
+
/** The first shown panel in layout order that names `panel`, or null when the layout does not show it, and the four keys below are then null. */
|
|
36
|
+
shown_panel: string | null;
|
|
37
|
+
/** The display frame of the target panel. */
|
|
38
|
+
frame: string | null;
|
|
39
|
+
/** The image of the origin of the target frame in the display frame, at the reading of the reference trajectory. Null when the reference does not resolve to a trajectory. */
|
|
40
|
+
origin: Vec3 | null;
|
|
41
|
+
/** The images of the three unit points of the target frame minus `origin`, i.e. the columns of the linear part of the map. Null as `origin` is. */
|
|
42
|
+
axes: [Vec3, Vec3, Vec3] | null;
|
|
43
|
+
}
|
|
44
|
+
export interface BodyLayerResult {
|
|
45
|
+
kind: 'body';
|
|
46
|
+
body: string;
|
|
47
|
+
/** Null when the reference does not resolve to a trajectory. */
|
|
48
|
+
position: Vec3 | null;
|
|
49
|
+
/** Present only when the layer has a `trail`. */
|
|
50
|
+
trail?: Vec3[];
|
|
51
|
+
}
|
|
52
|
+
export interface MarkLayerResult {
|
|
53
|
+
kind: 'axes' | 'grid';
|
|
54
|
+
}
|
|
55
|
+
export interface LabelLayerResult {
|
|
56
|
+
kind: 'label';
|
|
57
|
+
/** The anchor in the display frame (rule `label`), or null for an anchor on the screen or one that does not resolve. */
|
|
58
|
+
position: Vec3 | null;
|
|
59
|
+
}
|
|
60
|
+
export interface PointsMemberResult {
|
|
61
|
+
index: number;
|
|
62
|
+
/** The drawn samples in storage order (rule `points`). Empty while the member is hidden or before its first sample is reached. */
|
|
63
|
+
points: Vec3[];
|
|
64
|
+
}
|
|
65
|
+
export interface PointsLayerResult {
|
|
66
|
+
kind: 'points';
|
|
67
|
+
/** Null when the set query does not match any trajectory set, and `members` is then empty. */
|
|
68
|
+
set: string | null;
|
|
69
|
+
members: PointsMemberResult[];
|
|
70
|
+
}
|
|
71
|
+
export type LayerResult = TrajectoriesLayerResult | ArrowLayerResult | InsetBoxLayerResult | BodyLayerResult | MarkLayerResult | LabelLayerResult | PointsLayerResult;
|
|
72
|
+
/** The window of a camera with keyframes (rule `camera-keyframes`). */
|
|
73
|
+
export interface CameraResult {
|
|
74
|
+
center: [number, number];
|
|
75
|
+
width: number;
|
|
76
|
+
/** Null unless the keyframes give a height, under a camera of free aspect. */
|
|
77
|
+
height: number | null;
|
|
78
|
+
}
|
|
79
|
+
export interface PanelResult {
|
|
80
|
+
frame: string;
|
|
81
|
+
layers: LayerResult[];
|
|
82
|
+
/** Present only when the camera of the panel has keyframes, and null when the camera does not have a window at the frame (rule `camera-keyframes`). */
|
|
83
|
+
camera?: CameraResult | null;
|
|
84
|
+
}
|
|
85
|
+
export interface EvaluateResult {
|
|
86
|
+
panels: Record<string, PanelResult>;
|
|
87
|
+
}
|
|
@@ -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 { ArrayInfo, DataArray, DataHeader, DataStore, Dtype, EncodedArrayInfo, RawArrayInfo, TypedArray } 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 { ExportLimits, 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;
|