@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,224 @@
1
+ import type { Readout, State } from '../scene.js';
2
+ import { type ExportOptions } from './export.js';
3
+ import { type DropZone } from './layout.js';
4
+ import { type ReadoutTile } from './readouts.js';
5
+ /** A readout's elements, which are stat tiles when its text splits, or else one line that also shows an error. */
6
+ export interface ReadoutDom {
7
+ parts: Readout['parts'];
8
+ tiles: ReadoutTile[] | null;
9
+ root: HTMLDivElement;
10
+ list: HTMLElement | null;
11
+ values: HTMLElement[];
12
+ line: HTMLDivElement;
13
+ }
14
+ /**
15
+ * A chip holds a grip and a label in a body that drags, then a caret. The caret is a menu button for `menu`. For `select` it
16
+ * is a chevron under a native select at opacity 0, which opens the platform's picker, and for `none` it is left out. The caret
17
+ * never starts a drag.
18
+ */
19
+ export declare function buildChip(text: string, caret: 'menu' | 'select' | 'none'): {
20
+ root: HTMLDivElement;
21
+ body: HTMLSpanElement;
22
+ label: HTMLSpanElement;
23
+ button: HTMLButtonElement | null;
24
+ select: HTMLSelectElement | null;
25
+ };
26
+ /** A readout's elements, as stat tiles when `readoutTiles` splits its parts, in a row under the stage or stacked in a panel. */
27
+ export declare function buildReadout(parts: Readout['parts'], cls: 'wide' | 'stack'): ReadoutDom;
28
+ /** Writes a readout: its value parts into the tiles, or the whole text, or an error, as a line. */
29
+ export declare function fillReadout(r: ReadoutDom, pieces: string[] | {
30
+ error: string;
31
+ }): void;
32
+ /** The words inside a drop overlay. */
33
+ export declare function dropText(payload: {
34
+ kind: string;
35
+ }, zone: DropZone): string;
36
+ /** HTMLElement where there is one, so that importing this module under Node does not throw. */
37
+ declare const Base: typeof HTMLElement;
38
+ /**
39
+ * The class of the `<tycho-viewer>` element. It reads its attributes once, when it connects, apart from `theme`, and shows the
40
+ * error of a scene that cannot be read in place of the panels.
41
+ */
42
+ export declare class TychoViewerElement extends Base {
43
+ static readonly observedAttributes: string[];
44
+ private scene;
45
+ private sceneText;
46
+ private geometry;
47
+ private store;
48
+ private renderer;
49
+ /** The colors in use, or null before a scene loads. */
50
+ private theme;
51
+ private kiosk;
52
+ private loading;
53
+ /** Counts the loads begun, so that a load that a later one overtook drops its result. */
54
+ private loads;
55
+ /** The panel-scoped choice that a panel's header chip shows. */
56
+ private choice;
57
+ private root;
58
+ private header;
59
+ private titleEl;
60
+ private varsEl;
61
+ private addEl;
62
+ private stage;
63
+ private panelsEl;
64
+ private statusEl;
65
+ private statsEl;
66
+ private footer;
67
+ private canvas;
68
+ private readonly panelDom;
69
+ private readonly gutterDom;
70
+ private gutters;
71
+ private sceneWidgets;
72
+ private captions;
73
+ private addChips;
74
+ private addButton;
75
+ private addGroup;
76
+ private transport;
77
+ private menu;
78
+ /** Closes the export row when it is open, and returns whether it was open. */
79
+ private closeExport;
80
+ private raf;
81
+ /** Whether the element intersects the viewport. It stays true where IntersectionObserver does not exist. */
82
+ private intersecting;
83
+ /** Whether the animation loop may run, i.e. the element intersects the viewport and the page is visible. */
84
+ private shown;
85
+ private viewObserver;
86
+ private readonly onVisibility;
87
+ private dirty;
88
+ private anchor;
89
+ /** The progress that playback last reached, between two frame indices, or null while paused. */
90
+ private playProgress;
91
+ private speed;
92
+ private readonly meter;
93
+ /** The stage's size in CSS pixels, kept by the resize observer so that a draw never forces a layout. */
94
+ private stageSize;
95
+ private saveTimer;
96
+ private resizeObserver;
97
+ private readonly onPageHide;
98
+ private unsubscribe;
99
+ private lastPanels;
100
+ private lastLayout;
101
+ /** Restates the export's length when the speed changes. */
102
+ private refreshExport;
103
+ connectedCallback(): void;
104
+ disconnectedCallback(): void;
105
+ attributeChangedCallback(): void;
106
+ private buildShell;
107
+ private fail;
108
+ /** The element that `selector` matches, or null when it does not match any or is not a valid selector, as most URLs are not. */
109
+ private select;
110
+ /** The block or the URL of the scene or the data, by the order given at the top of this file, or null when the page gives neither. */
111
+ private source;
112
+ private read;
113
+ /** Loads the scene that the page gives this viewer. A viewer without any source stays empty until a caller invokes `load`. */
114
+ private loadFromSources;
115
+ /**
116
+ * Loads a scene from the text of scene.tys and the bytes of data.tyd, and resolves once the scene or
117
+ * its error shows. A load begun later takes precedence over this one.
118
+ */
119
+ load(sceneText: string, dataBytes: Uint8Array): Promise<void>;
120
+ private start;
121
+ private stop;
122
+ /** The computed value of a custom property on the host, or an empty string when it is not set. */
123
+ private hostProperty;
124
+ /** Recolors the chrome and a live renderer from the scene's theme, the `theme` attribute, and the custom properties of the host. */
125
+ private applyTheme;
126
+ private recall;
127
+ private save;
128
+ private flushSave;
129
+ /** Returns to the scene's initial state and discards the stored state. */
130
+ reset(): void;
131
+ /** The current state snapshot of section 2.8, or null before a scene loads. */
132
+ get state(): State | null;
133
+ private onChange;
134
+ private invalidate;
135
+ private schedule;
136
+ /** Stops the animation loop when the element stops being shown, and restarts it when the element comes back, with the clock where it paused. */
137
+ private syncShown;
138
+ /** The loop position that playback last reached, between two frame indices, so that a new anchor does not move the picture back to a frame index. */
139
+ private playPosition;
140
+ /**
141
+ * One animation frame. In live playback it maps wall time to a loop position, whose integer part is the
142
+ * frame index the controls show, and draws at the fractional progress every frame. Otherwise it draws
143
+ * if anything changed.
144
+ */
145
+ private tick;
146
+ /** Feeds the frame rate shown in the Playback group with a draw presented at `now`. */
147
+ private countDraw;
148
+ private showRate;
149
+ /** Reads the stage's size once per resize, so that the draw loop never forces a layout. */
150
+ private measureStage;
151
+ private draw;
152
+ private pieces;
153
+ private firstPanel;
154
+ private hasTransport;
155
+ /** Whether the clock is set to run. It stays true while the clock waits for the element to be shown. */
156
+ get playing(): boolean;
157
+ /** Starts the clock, at once or when the element is next shown. It does not do anything before a scene loads. */
158
+ play(): void;
159
+ /** Stops the clock. It does not do anything before a scene loads. */
160
+ pause(): void;
161
+ private step;
162
+ /** Goes to a frame, playing on from there when playing. */
163
+ private seek;
164
+ private onKey;
165
+ /**
166
+ * Acts on a key that reached the element, and returns whether the viewer used it. A key used by a focused control counts as
167
+ * used, since a listener on the document, such as reveal.js's, sees the event retargeted to the element and cannot tell.
168
+ */
169
+ private useKey;
170
+ /** Fits every panel's camera to what it draws. */
171
+ fitAll(): void;
172
+ private fitPanel;
173
+ /** Moves the first scene-scoped slider by `by` stops, and returns false when there is not a slider with stops to move. */
174
+ private stepSlider;
175
+ private buildFooter;
176
+ /**
177
+ * Exports a video of the current state, at the viewer's playback speed unless `options.speed` is set,
178
+ * and resolves to an MP4 blob. It rejects for the reasons that exportVideo in export.ts lists, and when
179
+ * the viewer has not loaded a scene.
180
+ */
181
+ exportVideo(options?: ExportOptions): Promise<Blob>;
182
+ private buildExport;
183
+ private makeWidget;
184
+ /** The panel-scoped choice that a header chip shows and, with one view, the Add panel group offers, i.e. the one a view's frame reads, or else the first. */
185
+ private templateChoice;
186
+ /** What the Add panel group offers. It offers the views when there are several, and the values of the panel-scoped choice otherwise. */
187
+ private templates;
188
+ private buildTopBar;
189
+ private buildAddGroup;
190
+ /** Shows the Add panel chips on one line, or the single Add panel menu button when they would wrap. */
191
+ private fitAddGroup;
192
+ /** The menu of a chip in the top bar, with Add panel, then Split right, Split below, and Replace for every panel. */
193
+ private chipEntries;
194
+ private addPanel;
195
+ private isTall;
196
+ /** A panel's name in the menus, which is its view when the scene has several, then what its header chip shows. */
197
+ private panelName;
198
+ /** Opens a menu under `anchor`, or closes it when it is the one open. */
199
+ private openMenu;
200
+ private closeMenu;
201
+ private syncWidgets;
202
+ private panelValue;
203
+ private syncPanels;
204
+ private createPanelDom;
205
+ private removePanelDom;
206
+ /** Places panels and gutters where the layout tiles the stage. */
207
+ private layoutDom;
208
+ private startResize;
209
+ /** Writes a panel's colorbars from the renderer's data, in place, so that a drag on one survives the redraw it causes. */
210
+ private syncBars;
211
+ private makeBar;
212
+ private barStops;
213
+ /** Sets the bar's selector to the stop nearest the value at `t` along the bar, as the top bar's slider does. */
214
+ private setFromBar;
215
+ private stepBar;
216
+ private startDrag;
217
+ private dropOn;
218
+ }
219
+ /**
220
+ * Registers TychoViewerElement as the custom element `tag`, which a page passes when the default name is taken. It does
221
+ * not do anything when an element named `tag` is already defined or where the environment lacks custom elements (e.g. Node).
222
+ */
223
+ export declare function define(tag?: string): void;
224
+ export {};
@@ -0,0 +1,119 @@
1
+ import type { Scene, State } from '../scene.js';
2
+ import { type Theme } from './colors.js';
3
+ import type { GeometryCache } from './geometry.js';
4
+ import type { Colorbar, PanelLabel } from './overlay.js';
5
+ /** The longest export allowed, in frames and in seconds. A longer export is refused. */
6
+ export declare const EXPORT_LIMITS: {
7
+ readonly frames: 2000;
8
+ readonly seconds: 90;
9
+ };
10
+ export declare const EXPORT_FPS: readonly [24, 30, 60];
11
+ export declare const EXPORT_LOOPS: readonly [1, 2, 3, 4];
12
+ export interface Schedule {
13
+ /** The number of output frames. */
14
+ count: number;
15
+ /** The length of the video in seconds. */
16
+ duration: number;
17
+ /** The frame index shown at output frame `k`, which its readouts' clock parts show. */
18
+ index(k: number): number;
19
+ /** The progress drawn at output frame `k`, between two frame indices as live playback draws it. */
20
+ progress(k: number): number;
21
+ }
22
+ /**
23
+ * Every output frame, as live playback would draw it at the time of the frame. A loop of `steps` lasts
24
+ * `seconds / speed`, where `seconds` is LAP_SECONDS for each lap. Output frame `k` is drawn at time
25
+ * `k / fps`, at the progress reached then, with the integer part of the loop position as its index.
26
+ */
27
+ export declare function frameSchedule(steps: number, fps: number, loops: number, speed?: number, start?: number, seconds?: number): Schedule;
28
+ /** Why an export of `count` frames at `fps` is refused, or null when it is not. */
29
+ export declare function checkExport(count: number, fps: number): string | null;
30
+ /**
31
+ * The frame rate an export row starts at, i.e. the highest of EXPORT_FPS at which one loop at
32
+ * `speed` stays within EXPORT_LIMITS, or null when every rate in EXPORT_FPS exceeds them.
33
+ */
34
+ export declare function defaultExportFps(steps: number, speed: number, seconds?: number): number | null;
35
+ export type SizePreset = '720p' | '1080p' | 'stage';
36
+ export interface ExportSize {
37
+ /** The size of the video in pixels, as `width` and `height`. */
38
+ width: number;
39
+ height: number;
40
+ /** Video pixels per CSS pixel. The layout, the fit, the line widths, and the text are laid out at a width of width / pixelRatio CSS pixels. */
41
+ pixelRatio: number;
42
+ }
43
+ /**
44
+ * A preset's size at `fps`. The presets 720p and 1080p share one layout of 1280 by 720 CSS pixels,
45
+ * at pixel ratios of 1 and 1.5. The preset `stage` is the stage's size rounded down to even pixels,
46
+ * at the whole pixel ratio nearest the screen's, at most 2. Where H.264 cannot hold the size and the
47
+ * rate there, the ratio is lowered in eighths to the largest at which it can. Both sides are kept even, as required by H.264.
48
+ */
49
+ export declare function sizePreset(preset: SizePreset, stage?: {
50
+ w: number;
51
+ h: number;
52
+ }, devicePixelRatio?: number, fps?: number): ExportSize;
53
+ /**
54
+ * The widest side an export takes. The H.264 hardware encoder of macOS does not accept a wider side (VideoToolbox
55
+ * does not open a session at 4352 by 2160), and Chrome there falls back to software beyond it.
56
+ */
57
+ export declare const AVC_MAX_SIDE = 4096;
58
+ /** Whether H.264 holds a size and rate, i.e. whether both sides are even, a level up to 5.2 holds them, and neither side exceeds AVC_MAX_SIDE. */
59
+ export declare function avcFits(width: number, height: number, fps: number): boolean;
60
+ /** The H.264 codec string for a size and rate, at the lowest level that holds them, or null past level 5.2. */
61
+ export declare function avcCodec(width: number, height: number, fps: number, profile?: 'high' | 'main' | 'baseline'): string | null;
62
+ /** A target bitrate of 0.08 bits per pixel per frame, ample for lines on a plain background, within 1 to 40 Mbit/s. */
63
+ export declare function exportBitrate(width: number, height: number, fps: number): number;
64
+ /**
65
+ * MP4 muxing of encoded H.264 chunks, through mp4-muxer's raw path, so that it runs without
66
+ * WebCodecs. The moov box goes before the media data.
67
+ */
68
+ export declare class Mp4Writer {
69
+ private readonly muxer;
70
+ constructor(width: number, height: number, fps: number);
71
+ /** Adds one encoded frame. Times are in microseconds. */
72
+ add(data: Uint8Array, key: boolean, timestamp: number, duration: number, meta?: EncodedVideoChunkMetadata): void;
73
+ finish(): Uint8Array;
74
+ }
75
+ export interface ExportOptions {
76
+ /** A preset, or an explicit size. Defaults to 720p. */
77
+ size?: SizePreset | ExportSize;
78
+ fps?: number;
79
+ loops?: number;
80
+ /** The playback speed, at which a lap of the clock lasts 8 s divided by the speed. Defaults to 1. */
81
+ speed?: number;
82
+ /** The frame index of the first frame. Defaults to 0. */
83
+ start?: number;
84
+ bitrate?: number;
85
+ /** Called with the encoder configuration the browser accepted, before the first frame. */
86
+ onConfig?: (config: VideoEncoderConfig) => void;
87
+ onProgress?: (done: number, total: number) => void;
88
+ signal?: AbortSignal;
89
+ }
90
+ /** What an export draws: a scene, its data, and the snapshot to freeze. */
91
+ export interface ExportSource {
92
+ scene: Scene;
93
+ geometry: GeometryCache;
94
+ state: State;
95
+ /** The stage's size in CSS pixels, for the `stage` preset. */
96
+ stage?: {
97
+ w: number;
98
+ h: number;
99
+ };
100
+ /** The theme to draw with, by default the scene's. */
101
+ theme?: Theme;
102
+ /** The font family of the text on the canvas, by default FONT. */
103
+ font?: string;
104
+ }
105
+ export declare function webCodecsMissing(): string | null;
106
+ /**
107
+ * The first H.264 configuration this browser's encoder accepts, at the lowest level that holds the
108
+ * size and rate. The profiles high, main, and baseline are tried in turn, in the avc format used in an MP4.
109
+ */
110
+ export declare function chooseConfig(width: number, height: number, fps: number, bitrate: number): Promise<VideoEncoderConfig>;
111
+ /** Draws a panel label as the page places it, centered vertically on (x, y) and turned to read upward when rotated. Exported for the tests. */
112
+ export declare function drawLabel(g: CanvasRenderingContext2D, l: PanelLabel, x: number, y: number, fg: string, bg: string, font?: string): void;
113
+ export declare function drawColorbars(g: CanvasRenderingContext2D, bars: Colorbar[], right: number, top: number, fg: string, dim: string, line: string, bg: string, font?: string): void;
114
+ /**
115
+ * Exports a video of `source` and resolves to an MP4 blob of H.264. Rejects with an AbortError
116
+ * when `options.signal` aborts, and with an Error that gives the reason when WebCodecs is missing, when
117
+ * the browser does not have an H.264 encoder for the size, or when the export would exceed EXPORT_LIMITS.
118
+ */
119
+ export declare function exportVideo(source: ExportSource, options?: ExportOptions): Promise<Blob>;
@@ -0,0 +1,214 @@
1
+ /**
2
+ * Static geometry of a track set in a display frame, and the revealed part of one track at a
3
+ * reading. A set's samples are transformed once per display frame and lap, each in its context
4
+ * (rules F4 and C6). Their readings u_i are computed once per clock channel (rule C1), so that
5
+ * drawing a frame only compares readings and blends two transformed samples (rule C4). Every
6
+ * panel showing the same frame shares the same buffers, and a lap is transformed the first time
7
+ * something draws it.
8
+ *
9
+ * The GPU draws the stored segments of one lap per pass. Within a lap below the top one, the
10
+ * closing sample of a track is replaced by the first sample of the next lap, which is the joint
11
+ * of rule C6, so that the passes of consecutive laps draw one polyline. A segment is drawn when
12
+ * both its ends lie strictly inside the revealed range of loop readings U = n u, where n is the
13
+ * number of laps and u the reading. The range is stored as the lap and the within-lap reading of
14
+ * each end, and compared lap by lap, so that the GPU compares the float32 readings as stored and
15
+ * does not add a lap to any of them. The CPU draws the pieces at the two ends of the range, thus
16
+ * the GPU and the CPU together draw the polyline of rules L1, L2 and C6.
17
+ */
18
+ import type { DataStore } from '../container.js';
19
+ import { TrackClock } from '../evaluate/clock.js';
20
+ import { Frames } from '../evaluate/frames.js';
21
+ import { type Vertex } from '../evaluate/layers.js';
22
+ import { SetCache, type SetData } from '../evaluate/sets.js';
23
+ import type { Clock, Scene, TrackLayer } from '../scene.js';
24
+ type Box6 = [number, number, number, number, number, number];
25
+ /** The lap a vertex is evaluated in, which is its lap of rule C6, or one lower when it is shifted (rule L2). */
26
+ export declare function vertexLap(v: Vertex): number;
27
+ /**
28
+ * Every sample of a set in one display frame, per lap, as x, y, z per sample in storage order.
29
+ * A track is transformed in a lap the first time it is needed, so that drawing one member of a
30
+ * large set costs one track, and the laps of rule C6 do not cost anything until something draws them.
31
+ */
32
+ export declare class TrackGeometry {
33
+ readonly set: SetData;
34
+ readonly frame: string;
35
+ /** The number of laps of rule C6 on the set. It is taken from the clock for a periodic set, and is one otherwise. */
36
+ readonly laps: number;
37
+ /** The highest lap, the only one that keeps its closing sample when the laps are joined. */
38
+ readonly top: number;
39
+ /** True when the edges into the display frame do not read any channel, meaning that every lap has the positions of lap 0. */
40
+ readonly invariant: boolean;
41
+ private readonly frames;
42
+ private readonly stores;
43
+ private box;
44
+ constructor(set: SetData, frame: string, frames: Frames, laps?: number);
45
+ /** The lap whose positions lap `j` has. */
46
+ private storeLap;
47
+ /** A name for the GPU's segments of lap `j`, the same for every lap whose segments are the same. */
48
+ lapKey(j: number): string;
49
+ private store;
50
+ /** Transforms track `t` in lap `lap` (true stands for lap -1 and false for lap 0), unless it is already transformed. */
51
+ ensure(t: number, lap: number | boolean): Float64Array;
52
+ /** Every sample of lap `j`, each in its context. */
53
+ lapPositions(j: number): Float64Array;
54
+ /** Every sample of lap 0, each in its context (rule F4). */
55
+ get positions(): Float64Array;
56
+ /** Every sample of lap -1, the shifted contexts of rule L2, for a periodic set only. */
57
+ get shifted(): Float64Array | null;
58
+ /** The samples of track `t` alone in a lap, as x, y, z per sample. */
59
+ track(t: number, lap: number | boolean): Float64Array;
60
+ /**
61
+ * Sample `i` of track `t` as the GPU draws lap `lap`, written at `out[o..o+2]`. It is the sample
62
+ * of lap `lap` itself, except for the closing sample of a lap below the top, which is the first
63
+ * sample of the next lap (rule C6).
64
+ */
65
+ gpuSample(t: number, lap: number, i: number, out: {
66
+ [i: number]: number;
67
+ }, o?: number): void;
68
+ /**
69
+ * The bounding box of track `t`, or of the whole set, over every lap from 0 to the top, as
70
+ * minimum then maximum x, y, z.
71
+ */
72
+ bounds(t?: number): Box6;
73
+ /** The position of a vertex of track `t` (rule C4) in its lap, written at `out[o..o+2]`. */
74
+ vertex(t: number, v: Vertex, out: {
75
+ [i: number]: number;
76
+ }, o?: number): void;
77
+ }
78
+ /** The clock along every track of a set for one channel, with the reading u_i of every sample and one TrackClock per track. */
79
+ export declare class TrackReadings {
80
+ readonly channel: string;
81
+ readonly clocks: TrackClock[];
82
+ readonly u: Float64Array;
83
+ constructor(set: SetData, channel: string);
84
+ }
85
+ /** Geometry and readings, built on first use and kept for the life of the page. */
86
+ export declare class GeometryCache {
87
+ readonly scene: Scene;
88
+ readonly sets: SetCache;
89
+ readonly frames: Frames;
90
+ private readonly geometries;
91
+ private readonly readingsBy;
92
+ private readonly bodyTrails;
93
+ constructor(scene: Scene, data: DataStore);
94
+ /** Throws an error of rule C6 when the clock is in value mode but has laps. */
95
+ geometry(setId: string, frame: string): TrackGeometry;
96
+ hasChannel(setId: string, channel: string): boolean;
97
+ /** Throws an error of rule C5 when the set lacks the channel. */
98
+ readings(setId: string, channel: string): TrackReadings;
99
+ /** The positions of a body along one driver track in one display frame, kept per lap. */
100
+ bodyTrail(bodyId: string, display: string, setId: string, track: number): BodyTrailTable;
101
+ }
102
+ /**
103
+ * A channel of the driver's track at progress `q`, as a readout shows it (section 2.9). The
104
+ * reading is clamped to [0, 1], and the channel is blended between the samples of rule C4 in the
105
+ * context of the driver's lap of rule C6.
106
+ */
107
+ export declare function channelAtReading(set: SetData, tc: TrackClock, track: number, channel: string, clock: Clock, q: number): number;
108
+ /** A range that does not contain any vertex, as [lap, reading, lap, reading] of its two ends. */
109
+ export declare const EMPTY_RANGE: readonly [number, number, number, number];
110
+ /** The range every sample of every lap from 0 to `top` lies inside, closing samples included. */
111
+ export declare const fullRange: (top: number) => [number, number, number, number];
112
+ /** The part of a polyline the GPU draws and the pieces the CPU draws at its two ends. */
113
+ export interface LoopSpan {
114
+ /** The lap and the within-lap reading of each end for the GPU, [jA, uA, jB, uB], rounded as the GPU stores readings. */
115
+ range: [number, number, number, number];
116
+ /** The lowest and the highest lap whose pass draws a segment, or null when the GPU does not draw any segment. */
117
+ laps: [number, number] | null;
118
+ /** Segments the CPU draws, at the ends of the range. */
119
+ pieces: [Vertex, Vertex][];
120
+ }
121
+ /**
122
+ * Whether the GPU draws, in lap `lap`, a segment whose samples read `ui` and `uj` (as stored),
123
+ * against a range of `LoopSpan.range`. Both ends must lie strictly inside the range in loop
124
+ * readings, compared lap first and reading second.
125
+ */
126
+ export declare function segmentShown(range: readonly [number, number, number, number], lap: number, ui: number, uj: number): boolean;
127
+ /**
128
+ * The polyline of rules L1 and C6 between loop readings `ua <= ub`, on a set of `laps` laps. A
129
+ * vertex is inside when its rounded reading in its lap lies strictly inside the rounded range, as
130
+ * segmentShown tests it. With `round` the identity, the test selects the vertices of the
131
+ * evaluator's polyline. With Math.fround, it is the comparison a float32 GPU makes, so that the
132
+ * CPU's end pieces meet the GPU's segments at the same samples.
133
+ */
134
+ export declare function loopSpan(tc: TrackClock, ua: number, ub: number, laps: number, round?: (x: number) => number): LoopSpan;
135
+ export interface Reveal extends LoopSpan {
136
+ /** The track is not drawn at this reading (rule C3). */
137
+ hidden: boolean;
138
+ /** The track's reading u, bounded by rule C3, or null when the layer does not take a reading or the track is hidden. */
139
+ reading: number | null;
140
+ /** The loop reading U = n u of rule C6, null when `reading` is null. */
141
+ loop: number | null;
142
+ /** The point at the reading, i.e. the head of rule L3, when the layer draws a head and the track is shown. */
143
+ head: Vertex | null;
144
+ }
145
+ export interface RevealSpec {
146
+ reveal: 'none' | 'grow' | 'trail';
147
+ fraction: number;
148
+ before?: 'clamp' | 'hidden';
149
+ after?: 'clamp' | 'hidden';
150
+ head: boolean;
151
+ periodic: boolean;
152
+ /** The number of laps n of rule C6 on this set, taken from the clock for a periodic set and one otherwise. */
153
+ laps: number;
154
+ }
155
+ /** Whether a layer takes a reading on its tracks (rule C5), by the same test as the evaluator. */
156
+ export declare function needsReading(layer: TrackLayer, clock: Clock): boolean;
157
+ export declare function revealSpec(layer: TrackLayer, periodic: boolean, laps?: number): RevealSpec;
158
+ /**
159
+ * The revealed part of one track at progress `q` (rules C2, C3, C6, L1, L2 and L3). The track clock
160
+ * `tc` is null only for a layer that does not take a reading, which shows every sample of every lap.
161
+ */
162
+ export declare function revealTrack(tc: TrackClock | null, clock: Clock, q: number, spec: RevealSpec, round?: (x: number) => number): Reveal;
163
+ /** The number of stored segments of a set, i.e. its number of samples minus its number of tracks. */
164
+ export declare function segmentCount(set: SetData): number;
165
+ /** The index of the first segment of track `t`. */
166
+ export declare function firstSegment(set: SetData, t: number): number;
167
+ /** Per-sample values of width `k`, as two vertices per segment. */
168
+ export declare function pairs(set: SetData, values: ArrayLike<number>, k: number): Float32Array;
169
+ /** Per-sample values of width `k` of the `m` samples from `s` on, as two vertices per segment. */
170
+ export declare function slicePairs(values: ArrayLike<number>, k: number, s: number, m: number): Float32Array;
171
+ /** The positions of every segment of a set in lap `lap`, as two vertices per segment, joined to the next lap below the top. */
172
+ export declare function lapPairs(g: TrackGeometry, lap: number): Float32Array;
173
+ /** The positions of the segments of track `t` in lap `lap`, as lapPairs lays them out. */
174
+ export declare function trackLapPairs(g: TrackGeometry, t: number, lap: number): Float32Array;
175
+ /** The loop reading of a vertex, which is the reading u_i at a sample or the blended reading at a point, plus its lap. */
176
+ export declare function vertexReading(tc: TrackClock, v: Vertex): number;
177
+ /** The readings of a segment's two samples, (u_i, u_(i+1)), on both its vertices. */
178
+ export declare function pairReadings(set: SetData, u: Float64Array): Float32Array;
179
+ /** The readings of the `m` samples from `s` on, as pairReadings lays them out. */
180
+ export declare function readingPairs(u: ArrayLike<number>, s: number, m: number): Float32Array;
181
+ /** The track index of every vertex. */
182
+ export declare function pairTracks(set: SetData): Float32Array;
183
+ /**
184
+ * A body's position in one display frame in the context of each sample of one driver track,
185
+ * per lap of rule C6, as x, y, z per sample. A lap is filled the first time it is drawn and kept,
186
+ * so that a frame copies a trail instead of evaluating it. When neither the body's position nor an
187
+ * edge into the display frame reads a channel, every lap has the positions of lap 0.
188
+ */
189
+ export declare class BodyTrailTable {
190
+ private readonly frames;
191
+ private readonly body;
192
+ private readonly display;
193
+ private readonly set;
194
+ private readonly track;
195
+ readonly m: number;
196
+ readonly invariant: boolean;
197
+ private readonly laps;
198
+ constructor(frames: Frames, body: string, display: string, set: SetData, track: number);
199
+ /** The body's positions at every sample of lap `j`, each in the context of its sample. */
200
+ lap(j: number): Float64Array;
201
+ /** The position of a vertex (rule C4) in its lap, written at `out[o..o+2]`. */
202
+ vertex(v: Vertex, out: {
203
+ [i: number]: number;
204
+ }, o?: number): void;
205
+ /**
206
+ * The polyline of rules L1 and C6 between loop readings `ua <= ub`, with the same vertices as the
207
+ * evaluator's `loopPolyline`, written as x, y, z per vertex from `out[0]`. Returns the vertex
208
+ * count. The samples of a lap are copied as runs, and only the two ends are blended.
209
+ */
210
+ polyline(tc: TrackClock, ua: number, ub: number, laps: number, out: Float32Array): number;
211
+ }
212
+ /** The most vertices a trail of `fraction` of a loop of `laps` laps over `m` samples can have. */
213
+ export declare function trailCapacity(m: number, laps: number, fraction: number): number;
214
+ export {};
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The icons of the viewer's controls, as inline SVG built with createElementNS from path strings, so that
3
+ * the browser neither parses markup nor fetches a file. The icons house, chevron-down, grip-vertical, x,
4
+ * rotate-ccw, plus, and download are taken from Lucide, on its 24 px grid with a 2 px stroke (the dots of grip-vertical
5
+ * are written as paths). The icons play and pause are drawn here on a 16 px grid and filled.
6
+ */
7
+ export declare const GLYPHS: {
8
+ readonly house: {
9
+ readonly grid: 24;
10
+ readonly fill: false;
11
+ readonly d: readonly ["M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8", "M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"];
12
+ };
13
+ readonly chevronDown: {
14
+ readonly grid: 24;
15
+ readonly fill: false;
16
+ readonly d: readonly ["m6 9 6 6 6-6"];
17
+ };
18
+ readonly grip: {
19
+ readonly grid: 24;
20
+ readonly fill: false;
21
+ readonly d: readonly [string, string];
22
+ };
23
+ readonly x: {
24
+ readonly grid: 24;
25
+ readonly fill: false;
26
+ readonly d: readonly ["M18 6 6 18", "m6 6 12 12"];
27
+ };
28
+ readonly rotateCcw: {
29
+ readonly grid: 24;
30
+ readonly fill: false;
31
+ readonly d: readonly ["M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8", "M3 3v5h5"];
32
+ };
33
+ readonly plus: {
34
+ readonly grid: 24;
35
+ readonly fill: false;
36
+ readonly d: readonly ["M5 12h14", "M12 5v14"];
37
+ };
38
+ readonly download: {
39
+ readonly grid: 24;
40
+ readonly fill: false;
41
+ readonly d: readonly ["M12 15V3", "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4", "m7 10 5 5 5-5"];
42
+ };
43
+ readonly play: {
44
+ readonly grid: 16;
45
+ readonly fill: true;
46
+ readonly d: readonly ["M5 3.5v9l7.5-4.5z"];
47
+ };
48
+ readonly pause: {
49
+ readonly grid: 16;
50
+ readonly fill: true;
51
+ readonly d: readonly ["M4.5 3H7v10H4.5zM9 3h2.5v10H9z"];
52
+ };
53
+ };
54
+ export type IconName = keyof typeof GLYPHS;
55
+ /** An icon as an `<svg>` that takes the text color. It is hidden from assistive technology, since its button carries the label. */
56
+ export declare function icon(name: IconName, cls?: string): SVGSVGElement;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Tiling layout: a binary tree of splits whose leaves are panels.
3
+ *
4
+ * A new panel dropped on an edge of an existing panel splits the existing panel along the same
5
+ * edge, and one dropped on its center replaces it. Removing a panel collapses its parent split.
6
+ * The tree is plain JSON, thus it can be stored and put into an export.
7
+ */
8
+ export type SplitDir = 'row' | 'col';
9
+ export type DropZone = 'left' | 'right' | 'top' | 'bottom' | 'centre';
10
+ export type LayoutNode = {
11
+ kind: 'panel';
12
+ id: string;
13
+ } | {
14
+ kind: 'split';
15
+ dir: SplitDir;
16
+ ratio: number;
17
+ a: LayoutNode;
18
+ b: LayoutNode;
19
+ };
20
+ export declare function panelIds(node: LayoutNode | null): string[];
21
+ export declare function hasPanel(node: LayoutNode | null, id: string): boolean;
22
+ /** Returns a new tree with `newId` placed relative to `targetId` in `zone`. */
23
+ export declare function splitAt(node: LayoutNode, targetId: string, newId: string, zone: DropZone): LayoutNode;
24
+ /** Returns the tree without `id`, or null if it was the only panel. */
25
+ export declare function removePanel(node: LayoutNode, id: string): LayoutNode | null;
26
+ export declare function setRatio(node: LayoutNode, split: LayoutNode, ratio: number): LayoutNode;
27
+ /** Panel ids with the area fraction each one occupies, for picking a split target. */
28
+ export declare function panelAreas(node: LayoutNode, area?: number): {
29
+ id: string;
30
+ area: number;
31
+ }[];
32
+ /** The drop zone for a pointer at (x, y) inside a rectangle of size (w, h), i.e. the nearest edge within 28% of the side, or else the center. */
33
+ export declare function zoneFor(x: number, y: number, w: number, h: number): DropZone;
34
+ export declare function isLayoutNode(v: unknown): v is LayoutNode;