@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,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The checks a reader makes before evaluating a scene. `validate` throws a TychoError that gives the
|
|
3
|
+
* rule, and returns warnings for what a reader only reports: unknown top-level keys (section 2)
|
|
4
|
+
* and a panel value of a shared input (rule `input-scope`).
|
|
5
|
+
*/
|
|
6
|
+
import type { DataStore } from './container.js';
|
|
7
|
+
import { type Scene, type State } from './scene.js';
|
|
8
|
+
/** Checks a scene, and its data and a state when given. Returns the warnings. */
|
|
9
|
+
export declare function validate(scene: Scene, data?: DataStore, state?: State): string[];
|
package/package.json
CHANGED
|
@@ -1,39 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beeson-group/tycho",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"scripts": {
|
|
6
|
-
"build": "npm run build:iife && npm run build:esm && npm run build:py",
|
|
7
|
-
"build:iife": "esbuild src/index.ts --bundle --format=iife --global-name=tycho --minify --target=es2020 --outfile=dist/tycho.js",
|
|
8
|
-
"build:esm": "esbuild src/index.ts --bundle --format=esm --minify --target=es2020 --outfile=dist/tycho.esm.js",
|
|
9
|
-
"build:py": "node -e \"require('fs').mkdirSync('../src/pytycho/_static',{recursive:true});require('fs').copyFileSync('dist/tycho.js','../src/pytycho/_static/tycho.js')\"",
|
|
10
|
-
"build:dev": "esbuild src/index.ts --bundle --format=iife --global-name=tycho --sourcemap=inline --target=es2020 --outfile=dist/tycho.dev.js",
|
|
11
|
-
"typecheck": "tsc --noEmit"
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@types/three": "^0.180.0",
|
|
15
|
-
"esbuild": "^0.28.0",
|
|
16
|
-
"typescript": "^5.6.0"
|
|
17
|
-
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"three": "^0.180.0"
|
|
20
|
-
},
|
|
21
|
-
"main": "dist/tycho.esm.js",
|
|
22
|
-
"module": "dist/tycho.esm.js",
|
|
23
|
-
"exports": {
|
|
24
|
-
".": "./dist/tycho.esm.js",
|
|
25
|
-
"./iife": "./dist/tycho.js"
|
|
26
|
-
},
|
|
27
|
-
"files": [
|
|
28
|
-
"dist",
|
|
29
|
-
"src"
|
|
30
|
-
],
|
|
31
|
-
"repository": {
|
|
32
|
-
"type": "git",
|
|
33
|
-
"url": "git+https://github.com/beeson-group/tycho.git",
|
|
34
|
-
"directory": "web"
|
|
35
|
-
},
|
|
36
|
-
"homepage": "https://github.com/beeson-group/tycho",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "The browser runtime of TyCHO, with the scene format reader, its pure evaluator, and the <tycho-viewer> element",
|
|
37
5
|
"keywords": [
|
|
38
6
|
"astrodynamics",
|
|
39
7
|
"visualization",
|
|
@@ -41,5 +9,65 @@
|
|
|
41
9
|
"webgl",
|
|
42
10
|
"web-component"
|
|
43
11
|
],
|
|
44
|
-
"
|
|
12
|
+
"homepage": "https://github.com/beeson-group/tycho",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/beeson-group/tycho/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/beeson-group/tycho.git",
|
|
19
|
+
"directory": "web"
|
|
20
|
+
},
|
|
21
|
+
"author": "Claudio Vestini",
|
|
22
|
+
"contributors": ["Jannik Graebner", "Nina Karampela", "Jack Sydney Schwartz"],
|
|
23
|
+
"license": "Apache-2.0 AND MIT",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/tycho.esm.js",
|
|
26
|
+
"module": "./dist/tycho.esm.js",
|
|
27
|
+
"types": "./dist/types/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/types/index.d.ts",
|
|
31
|
+
"default": "./dist/tycho.esm.js"
|
|
32
|
+
},
|
|
33
|
+
"./iife": "./dist/tycho.js",
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist/tycho.js",
|
|
38
|
+
"dist/tycho.esm.js",
|
|
39
|
+
"dist/types",
|
|
40
|
+
"NOTICE",
|
|
41
|
+
"AUTHORS",
|
|
42
|
+
"THIRD_PARTY_NOTICES.md"
|
|
43
|
+
],
|
|
44
|
+
"sideEffects": true,
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "npm run build:iife && npm run build:esm && npm run build:py",
|
|
47
|
+
"build:iife": "esbuild src/index.ts --bundle --format=iife --global-name=tycho --minify --target=es2022 --outfile=dist/tycho.js --banner:js=\"$(node scripts/notices.mjs)\"",
|
|
48
|
+
"build:esm": "esbuild src/index.ts --bundle --format=esm --minify --target=es2022 --outfile=dist/tycho.esm.js --banner:js=\"$(node scripts/notices.mjs)\"",
|
|
49
|
+
"build:py": "node -e \"require('fs').mkdirSync('../src/pytycho/_static',{recursive:true});require('fs').copyFileSync('dist/tycho.js','../src/pytycho/_static/tycho.js')\"",
|
|
50
|
+
"build:dev": "esbuild src/index.ts --bundle --format=iife --global-name=tycho --sourcemap=inline --target=es2022 --outfile=dist/tycho.dev.js",
|
|
51
|
+
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p test/tsconfig.json",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"gen:types": "node scripts/gen-types.mjs",
|
|
54
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
55
|
+
"notices": "node scripts/notices.mjs --check",
|
|
56
|
+
"prepack": "npm run notices && npm run build && npm run build:types && node scripts/prepack.mjs",
|
|
57
|
+
"postpack": "node scripts/prepack.mjs --clean"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/node": "^26.6.3",
|
|
61
|
+
"@types/three": "^0.187.0",
|
|
62
|
+
"ajv": "^8.20.0",
|
|
63
|
+
"esbuild": "^0.28.2",
|
|
64
|
+
"json-schema-to-typescript": "^16.0.0",
|
|
65
|
+
"mp4-muxer": "^5.2.2",
|
|
66
|
+
"three": "^0.187.0",
|
|
67
|
+
"typescript": "^7.0.2",
|
|
68
|
+
"vitest": "^5.0.3"
|
|
69
|
+
},
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"access": "public"
|
|
72
|
+
}
|
|
45
73
|
}
|
package/src/colormaps.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Small colormap lookup tables, sampled from matplotlib's maps, for colouring
|
|
3
|
-
* family members by their continuation parameter. The two single-hue maps are
|
|
4
|
-
* restricted to their brighter half so the low end stays visible on black.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export type ColormapId = 'viridis' | 'plasma' | 'cividis' | 'blues' | 'reds';
|
|
8
|
-
|
|
9
|
-
const STOPS: Record<ColormapId, number[][]> = {
|
|
10
|
-
viridis: [
|
|
11
|
-
[0.267, 0.005, 0.329], [0.283, 0.141, 0.458], [0.254, 0.265, 0.53], [0.207, 0.372, 0.553],
|
|
12
|
-
[0.164, 0.471, 0.558], [0.128, 0.567, 0.551], [0.135, 0.659, 0.518], [0.267, 0.749, 0.441],
|
|
13
|
-
[0.478, 0.821, 0.318], [0.741, 0.873, 0.15], [0.993, 0.906, 0.144],
|
|
14
|
-
],
|
|
15
|
-
plasma: [
|
|
16
|
-
[0.05, 0.03, 0.528], [0.294, 0.012, 0.615], [0.492, 0.012, 0.658], [0.665, 0.139, 0.586],
|
|
17
|
-
[0.798, 0.28, 0.47], [0.902, 0.418, 0.36], [0.973, 0.585, 0.252], [0.993, 0.771, 0.155],
|
|
18
|
-
[0.94, 0.975, 0.131],
|
|
19
|
-
],
|
|
20
|
-
cividis: [
|
|
21
|
-
[0.0, 0.135, 0.304], [0.086, 0.218, 0.396], [0.243, 0.301, 0.42], [0.365, 0.383, 0.432],
|
|
22
|
-
[0.478, 0.466, 0.448], [0.588, 0.55, 0.437], [0.702, 0.638, 0.402], [0.822, 0.73, 0.343],
|
|
23
|
-
[0.945, 0.827, 0.244], [0.996, 0.91, 0.149],
|
|
24
|
-
],
|
|
25
|
-
blues: [[0.19, 0.42, 0.71], [0.33, 0.6, 0.8], [0.53, 0.76, 0.87], [0.7, 0.85, 0.92], [0.85, 0.93, 0.98]],
|
|
26
|
-
reds: [[0.72, 0.1, 0.1], [0.89, 0.27, 0.2], [0.98, 0.5, 0.36], [0.99, 0.7, 0.58], [1.0, 0.86, 0.78]],
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/** RGB in [0, 1] at parameter t in [0, 1]. */
|
|
30
|
-
export function colormap(id: ColormapId, t: number, out: number[] = [0, 0, 0]): number[] {
|
|
31
|
-
const stops = STOPS[id];
|
|
32
|
-
const x = Math.max(0, Math.min(1, t)) * (stops.length - 1);
|
|
33
|
-
const i = Math.min(stops.length - 2, Math.floor(x));
|
|
34
|
-
const u = x - i;
|
|
35
|
-
for (let c = 0; c < 3; c++) out[c] = stops[i][c] + (stops[i + 1][c] - stops[i][c]) * u;
|
|
36
|
-
return out;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function colormapCss(id: ColormapId, t: number): string {
|
|
40
|
-
const [r, g, b] = colormap(id, t);
|
|
41
|
-
return `rgb(${Math.round(r * 255)},${Math.round(g * 255)},${Math.round(b * 255)})`;
|
|
42
|
-
}
|
package/src/container.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reader for the Tycho data container, .tyd (see src/pytycho/container.py).
|
|
3
|
-
* A JSON header followed by 8-byte aligned typed buffers; no dependencies.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export interface ViewInfo {
|
|
7
|
-
offset: number;
|
|
8
|
-
length: number;
|
|
9
|
-
dtype: 'float32' | 'float64' | 'int32' | 'uint8';
|
|
10
|
-
shape: number[];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface Header {
|
|
14
|
-
format: string;
|
|
15
|
-
version: number;
|
|
16
|
-
generator: string;
|
|
17
|
-
meta: Record<string, unknown>;
|
|
18
|
-
views: Record<string, ViewInfo>;
|
|
19
|
-
datasets: DatasetRecord[];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Dataset records are plain JSON; `kind` selects the interpretation. */
|
|
23
|
-
export interface DatasetRecord {
|
|
24
|
-
id: string;
|
|
25
|
-
kind: string;
|
|
26
|
-
title: string;
|
|
27
|
-
[key: string]: unknown;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type TypedArray = Float32Array | Float64Array | Int32Array | Uint8Array;
|
|
31
|
-
|
|
32
|
-
const MAGIC = 0x44435954; // "TYCD" little endian
|
|
33
|
-
|
|
34
|
-
export class Container {
|
|
35
|
-
readonly header: Header;
|
|
36
|
-
private readonly body: ArrayBuffer;
|
|
37
|
-
private readonly bodyOffset: number;
|
|
38
|
-
|
|
39
|
-
private constructor(header: Header, body: ArrayBuffer, bodyOffset: number) {
|
|
40
|
-
this.header = header;
|
|
41
|
-
this.body = body;
|
|
42
|
-
this.bodyOffset = bodyOffset;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static parse(buffer: ArrayBuffer): Container {
|
|
46
|
-
const dv = new DataView(buffer);
|
|
47
|
-
if (dv.getUint32(0, true) !== MAGIC) throw new Error('not a Tycho data container');
|
|
48
|
-
const version = dv.getUint32(4, true);
|
|
49
|
-
if (version !== 1) throw new Error(`unsupported container version ${version}`);
|
|
50
|
-
const hlen = dv.getUint32(8, true);
|
|
51
|
-
const header = JSON.parse(new TextDecoder().decode(new Uint8Array(buffer, 12, hlen))) as Header;
|
|
52
|
-
const headEnd = 12 + hlen;
|
|
53
|
-
const bodyOffset = headEnd + ((8 - (headEnd % 8)) % 8);
|
|
54
|
-
return new Container(header, buffer, bodyOffset);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
get datasets(): DatasetRecord[] {
|
|
58
|
-
return this.header.datasets;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
viewInfo(name: string): ViewInfo {
|
|
62
|
-
const info = this.header.views[name];
|
|
63
|
-
if (!info) throw new Error(`unknown view ${name}`);
|
|
64
|
-
return info;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Returns a typed array over the view's bytes, zero-copy. */
|
|
68
|
-
view(name: string): TypedArray {
|
|
69
|
-
const info = this.viewInfo(name);
|
|
70
|
-
const start = this.bodyOffset + info.offset;
|
|
71
|
-
switch (info.dtype) {
|
|
72
|
-
case 'float32':
|
|
73
|
-
return new Float32Array(this.body, start, info.length / 4);
|
|
74
|
-
case 'float64':
|
|
75
|
-
return new Float64Array(this.body, start, info.length / 8);
|
|
76
|
-
case 'int32':
|
|
77
|
-
return new Int32Array(this.body, start, info.length / 4);
|
|
78
|
-
case 'uint8':
|
|
79
|
-
return new Uint8Array(this.body, start, info.length);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
f32(name: string): Float32Array {
|
|
84
|
-
const a = this.view(name);
|
|
85
|
-
return a instanceof Float32Array ? a : Float32Array.from(a as ArrayLike<number>);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
f64(name: string): Float64Array {
|
|
89
|
-
const a = this.view(name);
|
|
90
|
-
return a instanceof Float64Array ? a : Float64Array.from(a as ArrayLike<number>);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function base64ToBytes(text: string): Uint8Array<ArrayBuffer> {
|
|
95
|
-
const bin = atob(text.replace(/\s+/g, ''));
|
|
96
|
-
const out = new Uint8Array(new ArrayBuffer(bin.length));
|
|
97
|
-
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
98
|
-
return out;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** Decodes a container embedded in a script tag by src/pytycho/html.py. */
|
|
102
|
-
export async function decodeEmbedded(el: HTMLScriptElement): Promise<ArrayBuffer> {
|
|
103
|
-
const encoding = el.dataset.encoding ?? 'base64';
|
|
104
|
-
const bytes = base64ToBytes(el.textContent ?? '');
|
|
105
|
-
if (encoding === 'base64') return bytes.buffer;
|
|
106
|
-
if (encoding === 'gzip+base64') {
|
|
107
|
-
if (typeof DecompressionStream === 'undefined') {
|
|
108
|
-
throw new Error('this browser lacks DecompressionStream; rebuild the page with compress=False');
|
|
109
|
-
}
|
|
110
|
-
const stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream('gzip'));
|
|
111
|
-
return new Response(stream).arrayBuffer();
|
|
112
|
-
}
|
|
113
|
-
throw new Error(`unknown data encoding ${encoding}`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Loads a container from an element selector (embedded) or a URL (sidecar). */
|
|
117
|
-
export async function loadContainer(source: string): Promise<Container> {
|
|
118
|
-
if (source.startsWith('#')) {
|
|
119
|
-
const el = document.querySelector<HTMLScriptElement>(source);
|
|
120
|
-
if (!el) throw new Error(`no element matches ${source}`);
|
|
121
|
-
return Container.parse(await decodeEmbedded(el));
|
|
122
|
-
}
|
|
123
|
-
const res = await fetch(source);
|
|
124
|
-
if (!res.ok) throw new Error(`failed to fetch ${source}: ${res.status}`);
|
|
125
|
-
return Container.parse(await res.arrayBuffer());
|
|
126
|
-
}
|