@kymoscope/sdk 0.9.0 → 0.11.1
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/dist/assets/{importer.worker-CLBGjz4d.js → importer.worker-Cgz__4KO.js} +1 -1
- package/dist/assets/liveIngestWorker-BLPTEEc7.js +1 -0
- package/dist/assets/offscreenLineWorker-C-_uNa_H.js +80 -0
- package/dist/importers-D_M42sqZ.js +5 -0
- package/dist/{keys-Iv24Wam2.js → keys-CkI2qrI-.js} +1 -1
- package/dist/kymoscope-embed.js +66 -66
- package/dist/kymoscope-sdk.js +89 -85
- package/dist/types/analysis/ai.d.ts +50 -0
- package/dist/types/analysis/aiCheck.d.ts +54 -0
- package/dist/types/analysis/alertsBefore.d.ts +7 -0
- package/dist/types/analysis/better.d.ts +6 -0
- package/dist/types/analysis/capability.d.ts +10 -0
- package/dist/types/analysis/changes.d.ts +10 -0
- package/dist/types/analysis/containment.d.ts +10 -0
- package/dist/types/analysis/context.d.ts +131 -0
- package/dist/types/analysis/control.d.ts +13 -0
- package/dist/types/analysis/energy.d.ts +4 -0
- package/dist/types/analysis/gap.d.ts +8 -0
- package/dist/types/analysis/golden.d.ts +20 -0
- package/dist/types/analysis/health.d.ts +73 -0
- package/dist/types/analysis/index.d.ts +12 -0
- package/dist/types/analysis/infer.d.ts +68 -0
- package/dist/types/analysis/lines.d.ts +6 -0
- package/dist/types/analysis/losses.d.ts +41 -0
- package/dist/types/analysis/maintenance.d.ts +8 -0
- package/dist/types/analysis/oee.d.ts +30 -0
- package/dist/types/analysis/parts.d.ts +13 -0
- package/dist/types/analysis/presets.d.ts +35 -0
- package/dist/types/analysis/reliability.d.ts +103 -0
- package/dist/types/analysis/report.d.ts +15 -0
- package/dist/types/analysis/shifts.d.ts +7 -0
- package/dist/types/analysis/sinceLast.d.ts +8 -0
- package/dist/types/analysis/stats.d.ts +110 -0
- package/dist/types/analysis/stops.d.ts +34 -0
- package/dist/types/analysis/strip.d.ts +14 -0
- package/dist/types/analysis/text.d.ts +56 -0
- package/dist/types/analysis/types.d.ts +407 -0
- package/dist/types/components/liveWindow.d.ts +6 -2
- package/dist/types/engine/createEngine.d.ts +1 -0
- package/dist/types/engine/liveController.d.ts +7 -0
- package/dist/types/index.d.ts +6 -1
- package/dist/types/lib/live/cameraSender.d.ts +9 -1
- package/dist/types/lib/live/liveIngest.d.ts +47 -0
- package/dist/types/lib/live/liveIngestClient.d.ts +9 -0
- package/dist/types/lib/live/liveIngestWorker.d.ts +1 -0
- package/dist/types/lib/live/publisher.d.ts +23 -5
- package/dist/types/lib/live/stream.d.ts +8 -0
- package/dist/types/lib/live/types.d.ts +12 -0
- package/dist/types/lib/recordings/split.d.ts +10 -0
- package/dist/types/lib/recordings/writer.d.ts +187 -0
- package/dist/types/lib/render/frames.d.ts +10 -0
- package/dist/types/lib/render/glPoints.d.ts +18 -0
- package/dist/types/lib/render/offscreenLineRenderer.d.ts +15 -1
- package/dist/types/lib/render/sharedGl.d.ts +12 -3
- package/package.json +4 -1
- package/dist/assets/offscreenLineWorker-BQwts3O3.js +0 -80
- package/dist/importers-BVYsv8Vy.js +0 -5
|
@@ -54,6 +54,15 @@ export interface LiveStreamOptions {
|
|
|
54
54
|
* time included). Default an eighth of the device's memory (2048 on a 16 GB
|
|
55
55
|
* computer, and when the browser doesn't say), at least 512. */
|
|
56
56
|
maxMemoryMB?: number;
|
|
57
|
+
/**
|
|
58
|
+
* A password stream's salt and key_check as they are now (and its key, for a CryptoKey secret) (re-read from wherever the descriptor came from). A
|
|
59
|
+
* revoked browser makes the sender take a new salt, its messages then name a new key id: without this, the view
|
|
60
|
+
* stops until it is connected again with the new descriptor.
|
|
61
|
+
*/
|
|
62
|
+
reload?: () => Promise<(Pick<LiveStreamDescriptor, 'salt' | 'key_check'> & {
|
|
63
|
+
/** The key itself, when it doesn't come from a password (a browser's device key): checked against key_check. */
|
|
64
|
+
key?: CryptoKey;
|
|
65
|
+
}) | null>;
|
|
57
66
|
}
|
|
58
67
|
/** A host-fed stream: frames pushed from the page itself — no network, no crypto. */
|
|
59
68
|
export interface LocalLiveStream {
|
|
@@ -93,6 +102,9 @@ export interface LiveConnection {
|
|
|
93
102
|
error: string | null;
|
|
94
103
|
/** When a recording is running: its start time (ms since epoch). */
|
|
95
104
|
recordingSince: number | null;
|
|
105
|
+
/** Samples dropped before the ring because this page couldn't keep up with the stream (its traces have a gap
|
|
106
|
+
* there); 0 or absent: none. */
|
|
107
|
+
droppedSamples?: number;
|
|
96
108
|
/** The plan-limit banner it was opened with (LiveStreamDescriptor.limit_notice); a Camera panel shows it. */
|
|
97
109
|
limitNotice?: string | null;
|
|
98
110
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const SPLIT_STEPS: readonly [60, 300, 900, 1800, 3600, 7200, 14400, 28800, 43200, 86400];
|
|
2
|
+
/** Only a guide for the default period: files are never cut by size (time rules, the user decided 2026-11-09). */
|
|
3
|
+
export declare const FILE_TARGET_BYTES: number;
|
|
4
|
+
/** '1h' / '15m' / 3600 → seconds, or null when it isn't a step. */
|
|
5
|
+
export declare function parseSplit(v: unknown): number | null;
|
|
6
|
+
export declare const formatSplit: (s: number) => string;
|
|
7
|
+
/** The longest step whose file stays under the target at `bytesPerSec`; 1 min when none does. */
|
|
8
|
+
export declare function defaultSplit(bytesPerSec: number): number;
|
|
9
|
+
/** The next cut after `tMs` (strictly later), aligned to the sender's local clock (`utcOffsetS`, e.g. +3600). */
|
|
10
|
+
export declare function nextCut(tMs: number, periodS: number, utcOffsetS: number): number;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
export declare const CHUNK_MS = 60000;
|
|
2
|
+
export declare const CHUNK_MAX_BYTES: number;
|
|
3
|
+
export declare const PARENT_POLL_MS = 10000;
|
|
4
|
+
export declare const FAST_POLL_MS = 2000;
|
|
5
|
+
export declare const PARENT_GONE_MS = 30000;
|
|
6
|
+
/** The wait after a failed upload pass: 2 s, doubling, at most 60 s. */
|
|
7
|
+
export declare const backoff: (ms: number) => number;
|
|
8
|
+
export declare const bufferLabel: (mb: number) => string;
|
|
9
|
+
/** The parts of the File System Access handles the recorder uses (OPFS, a picked folder, or a fake in tests). */
|
|
10
|
+
export interface RecFile {
|
|
11
|
+
kind: 'file';
|
|
12
|
+
getFile(): Promise<Blob>;
|
|
13
|
+
createWritable(): Promise<{
|
|
14
|
+
write(b: BufferSource | Blob | string): Promise<void>;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
export interface RecDir {
|
|
19
|
+
kind: 'directory';
|
|
20
|
+
getDirectoryHandle(name: string, o?: {
|
|
21
|
+
create?: boolean;
|
|
22
|
+
}): Promise<RecDir>;
|
|
23
|
+
getFileHandle(name: string, o?: {
|
|
24
|
+
create?: boolean;
|
|
25
|
+
}): Promise<RecFile>;
|
|
26
|
+
removeEntry(name: string, o?: {
|
|
27
|
+
recursive?: boolean;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
entries(): AsyncIterable<[string, RecDir | RecFile]>;
|
|
30
|
+
}
|
|
31
|
+
/** The project's own storage, reached from this browser (the server only says which one: the keys stay here). */
|
|
32
|
+
export interface OwnStorage {
|
|
33
|
+
/** A folder the user picked (File System Access: Chrome and Edge). */
|
|
34
|
+
folder?: RecDir | FileSystemDirectoryHandle;
|
|
35
|
+
/** S3 or compatible (MinIO, R2…): the bucket must allow PUT from this page's origin (CORS). */
|
|
36
|
+
s3?: {
|
|
37
|
+
endpoint: string;
|
|
38
|
+
region?: string;
|
|
39
|
+
bucket: string;
|
|
40
|
+
prefix?: string;
|
|
41
|
+
accessKeyId: string;
|
|
42
|
+
secretAccessKey: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export interface Destination {
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
kind: 's3' | 'folder';
|
|
49
|
+
}
|
|
50
|
+
export type RecorderStatus = {
|
|
51
|
+
type: 'destination';
|
|
52
|
+
name: string;
|
|
53
|
+
splitEvery: number | null;
|
|
54
|
+
message: string;
|
|
55
|
+
} | {
|
|
56
|
+
type: 'storage_needed';
|
|
57
|
+
destination: Destination;
|
|
58
|
+
message: string;
|
|
59
|
+
} | {
|
|
60
|
+
type: 'refused' | 'buffer_full' | 'chunk_dropped' | 'storage_error' | 'disk_error';
|
|
61
|
+
message: string;
|
|
62
|
+
reason?: string;
|
|
63
|
+
};
|
|
64
|
+
export interface BrowserRecorderOptions {
|
|
65
|
+
/** The camera's stream id. */
|
|
66
|
+
streamId: string;
|
|
67
|
+
/** The data stream the camera belongs to: its files are cut with that stream's recordings. */
|
|
68
|
+
parentStreamId: string;
|
|
69
|
+
/** recording-upload (LivePublisher.recordingUpload); rejects with {status, code} (RegistryError). */
|
|
70
|
+
call: (body: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
71
|
+
/** Local space for chunks not stored yet (default 2048). */
|
|
72
|
+
bufferMaxMB?: number;
|
|
73
|
+
storage?: OwnStorage | null;
|
|
74
|
+
/** Own storage only: how long it keeps the files. */
|
|
75
|
+
retentionDays?: number;
|
|
76
|
+
onStatus?: (s: RecorderStatus) => void;
|
|
77
|
+
/** Test seams. */
|
|
78
|
+
root?: () => Promise<RecDir>;
|
|
79
|
+
fetch?: typeof fetch;
|
|
80
|
+
now?: () => number;
|
|
81
|
+
/** Web Locks (navigator.locks); null: this page is the only uploader. */
|
|
82
|
+
locks?: LockManager | null;
|
|
83
|
+
/** Start the upload loop (default true; tests drive uploadPending/pollParent themselves). */
|
|
84
|
+
autostart?: boolean;
|
|
85
|
+
}
|
|
86
|
+
/** A message without any URL's query string (a presigned S3 URL's signature never reaches a log). */
|
|
87
|
+
export declare const redactUrls: (s: string) => string;
|
|
88
|
+
export declare class BrowserRecorder {
|
|
89
|
+
readonly streamId: string;
|
|
90
|
+
readonly parentStreamId: string;
|
|
91
|
+
readonly bufferMaxMB: number;
|
|
92
|
+
/** Chunks a full buffer dropped before they were stored. */
|
|
93
|
+
dropped: number;
|
|
94
|
+
/** Bytes in the buffer at the last count. */
|
|
95
|
+
usedBytes: number;
|
|
96
|
+
private storage;
|
|
97
|
+
private readonly opts;
|
|
98
|
+
private readonly now;
|
|
99
|
+
private readonly fetch;
|
|
100
|
+
private readonly locks;
|
|
101
|
+
private rootDir;
|
|
102
|
+
/** The data stream's open recording (null: none; undefined: not asked yet), and when it was last asked. */
|
|
103
|
+
private parent;
|
|
104
|
+
private polledAt;
|
|
105
|
+
private polling;
|
|
106
|
+
/** When the data stream's recording is expected to be cut (its period's next clock cut), and since when the server
|
|
107
|
+
* has said it has none open. */
|
|
108
|
+
private cutAt;
|
|
109
|
+
private noneSince;
|
|
110
|
+
private file;
|
|
111
|
+
private chunk;
|
|
112
|
+
private continues;
|
|
113
|
+
/** The last ended file, and the files refused, gone or whose last chunk a full buffer dropped (in memory). */
|
|
114
|
+
private prev;
|
|
115
|
+
private readonly lost;
|
|
116
|
+
/** Disk writes in order (opening a file, its chunks, its end). */
|
|
117
|
+
private io;
|
|
118
|
+
/** Files this recorder still writes: never closed on the server until their end is on disk. */
|
|
119
|
+
private readonly writing;
|
|
120
|
+
private readonly held;
|
|
121
|
+
private readonly opened;
|
|
122
|
+
private readonly blocked;
|
|
123
|
+
private readonly wait;
|
|
124
|
+
private readonly said;
|
|
125
|
+
private fullSaid;
|
|
126
|
+
private refusedUntil;
|
|
127
|
+
private closing;
|
|
128
|
+
private stopped;
|
|
129
|
+
private wake;
|
|
130
|
+
private loop;
|
|
131
|
+
constructor(opts: BrowserRecorderOptions);
|
|
132
|
+
/** Whether frames are wanted now: a file is open or the data stream records (the camera encodes for it). */
|
|
133
|
+
wants(): boolean;
|
|
134
|
+
/** The data stream's file period in seconds (from `current`), null until known. */
|
|
135
|
+
splitEvery: number | null;
|
|
136
|
+
/** The open file's recording id, or null. */
|
|
137
|
+
get currentId(): string | null;
|
|
138
|
+
/** The project's own storage became reachable (the page picked its folder): the files waiting for it go. */
|
|
139
|
+
setStorage(storage: OwnStorage | null): void;
|
|
140
|
+
/** One sealed message at `tMs` (the frame's capture time, ms since epoch). `keyframe`: it starts a keyframe; files
|
|
141
|
+
* open and end only there. */
|
|
142
|
+
add(sealed: Uint8Array, tMs: number, keyframe: boolean): void;
|
|
143
|
+
/** Close a chunk open for CHUNK_MS (the loop calls it every second). */
|
|
144
|
+
tick(): void;
|
|
145
|
+
/** End the current file now (the camera stops); the next file doesn't continue it. */
|
|
146
|
+
stop(): void;
|
|
147
|
+
/** Ask the server for the data stream's open recording (a failure keeps what was known). */
|
|
148
|
+
pollParent(): Promise<void>;
|
|
149
|
+
/** Ask again: every PARENT_POLL_MS; right after the expected cut and every FAST_POLL_MS for a minute past it; and
|
|
150
|
+
* every FAST_POLL_MS while a file is open but the server says none (a cut's gap, or a stop). */
|
|
151
|
+
private pollDue;
|
|
152
|
+
private root;
|
|
153
|
+
/** Run a disk write after the ones before it; a failure is said once and never stops live. */
|
|
154
|
+
private queue;
|
|
155
|
+
private openFile;
|
|
156
|
+
private endFile;
|
|
157
|
+
private flush;
|
|
158
|
+
/** Every file under rec/ counts (one budget for every stream); past it the oldest chunks go. */
|
|
159
|
+
private enforceMax;
|
|
160
|
+
private status;
|
|
161
|
+
private say;
|
|
162
|
+
/** Whether this recorder uploads folder `id`: its own, or a leftover no running recorder holds (a leftover without
|
|
163
|
+
* meta is removed). */
|
|
164
|
+
private claim;
|
|
165
|
+
private release;
|
|
166
|
+
/** [id, meta, dir] of the folders this recorder uploads, oldest first. */
|
|
167
|
+
private files;
|
|
168
|
+
/** Drop a file's chunks here (refused or gone on the server: lost, so the next file continues nothing; or stored
|
|
169
|
+
* and closed); the current one ends. */
|
|
170
|
+
private forget;
|
|
171
|
+
/** The file's destination once opened; null when it was refused (dropped) or can't go yet (kept). */
|
|
172
|
+
private open;
|
|
173
|
+
private put;
|
|
174
|
+
private writeOwn;
|
|
175
|
+
private dropChunk;
|
|
176
|
+
private uploadChunk;
|
|
177
|
+
/** The server lost a file it had opened (404): the chunks still here go under a new recording id, continuing
|
|
178
|
+
* nothing (the current file ends first). False when none are left (the file is forgotten as before). */
|
|
179
|
+
private reopen;
|
|
180
|
+
/** One pass over the files this recorder uploads, oldest first. True when nothing is left to upload (files waiting
|
|
181
|
+
* for their storage aside). Rejects on a failure worth retrying (the caller backs off). */
|
|
182
|
+
uploadPending(): Promise<boolean>;
|
|
183
|
+
private run;
|
|
184
|
+
/** End the current file and give the uploader up to `timeoutMs` to store what is left; the rest stays in the buffer
|
|
185
|
+
* and goes out the next time a camera records on this browser. */
|
|
186
|
+
close(timeoutMs?: number): Promise<void>;
|
|
187
|
+
}
|
|
@@ -39,8 +39,18 @@ export declare class AnyWindowResizeObserver {
|
|
|
39
39
|
* frame's time until the next frame, so several changes in one frame still
|
|
40
40
|
* make one draw.
|
|
41
41
|
*/
|
|
42
|
+
/** Hidden with its worksheet (in the document, no layout: display none), as opposed to scrolled out of view. */
|
|
43
|
+
export declare function isHidden(el: Element | null | undefined): boolean;
|
|
42
44
|
export declare function createDrawScheduler(draw: () => void, element: () => Element | null | undefined): {
|
|
43
45
|
schedule(): void;
|
|
44
46
|
now(): void;
|
|
45
47
|
cancel(): void;
|
|
46
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Whether a live chart that last drew at `lastDrew` may draw in the frame at `ts`. Every chart of a frame gets the
|
|
51
|
+
* same answer from the duty above; within the frame, past LIVE_FRAME_CAP_MS the rest wait, and the next frames serve
|
|
52
|
+
* the charts that waited before those that drew since (stalest first, as near as callbacks in a fixed order allow).
|
|
53
|
+
*/
|
|
54
|
+
export declare function liveDrawAllowed(ts: number, lastDrew?: number): boolean;
|
|
55
|
+
/** A live chart drew for `ms` in the frame at `ts`. */
|
|
56
|
+
export declare function noteLiveDraw(ts: number, ms: number): void;
|
|
@@ -34,4 +34,22 @@ export interface GpuPointsRenderer {
|
|
|
34
34
|
render(): void;
|
|
35
35
|
dispose(): void;
|
|
36
36
|
}
|
|
37
|
+
/** A stretch of points with one dataset index (all of them when the colour isn't per dataset). */
|
|
38
|
+
export interface PointRun {
|
|
39
|
+
v: number;
|
|
40
|
+
a: number;
|
|
41
|
+
b: number;
|
|
42
|
+
}
|
|
43
|
+
/** The runs of equal `k` in the first `n` points (one run without `k`). */
|
|
44
|
+
export declare function pointRuns(k: ArrayLike<number> | undefined, n: number): PointRun[];
|
|
45
|
+
/**
|
|
46
|
+
* How much of the previous upload a new one holds, run by run: a live refresh drops its oldest points and adds
|
|
47
|
+
* new ones, so each run of the new data starts with a stretch of the old run of the same index. Per new run, the
|
|
48
|
+
* points kept (`len`, from old position `src`); the rest of the run is new. Null when the old points aren't found
|
|
49
|
+
* exactly (other data): everything is sent again.
|
|
50
|
+
*/
|
|
51
|
+
export declare function planReuse(oldX: Float64Array, oldY: Float64Array, oldRuns: PointRun[], x: Float64Array, y: Float64Array, runs: PointRun[]): {
|
|
52
|
+
src: number;
|
|
53
|
+
len: number;
|
|
54
|
+
}[] | null;
|
|
37
55
|
export declare function createGpuPointsRenderer(canvas: HTMLCanvasElement | OffscreenCanvas): GpuPointsRenderer | null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type GpuSeriesStyle } from './glSeries';
|
|
2
|
+
import { type GlHolder } from './sharedGl';
|
|
2
3
|
/**
|
|
3
4
|
* Main-thread handle to the OffscreenCanvas line worker. The worker owns the GL
|
|
4
5
|
* context and keeps the data on the GPU (projected in the shader); the main
|
|
@@ -36,6 +37,8 @@ export interface OffscreenLayerData extends OffscreenLayerFrame {
|
|
|
36
37
|
columns: Float32Array[];
|
|
37
38
|
}
|
|
38
39
|
export interface OffscreenChartRenderer {
|
|
40
|
+
/** Draws in a worker with a context of its own (one of the few a page gets); absent: through the shared one. */
|
|
41
|
+
own?: boolean;
|
|
39
42
|
resize(w: number, h: number, dpr: number): void;
|
|
40
43
|
/** New points for a layer (uploaded to the GPU). The worker draws every layer it holds. */
|
|
41
44
|
setData(layer: number, data: OffscreenLayerData): void;
|
|
@@ -45,9 +48,20 @@ export interface OffscreenChartRenderer {
|
|
|
45
48
|
setView(xmin: number, xmax: number, cut?: number): void;
|
|
46
49
|
dispose(): void;
|
|
47
50
|
}
|
|
51
|
+
/** Whether charts can draw in a worker here (false once starting one failed). */
|
|
52
|
+
export declare function glWorkersAvailable(): boolean;
|
|
53
|
+
/** Name of the performance mark made when a worker has drawn a canvas's first picture. */
|
|
54
|
+
export declare const GL_FIRST_FRAME_MARK = "kymoscope-gl-first-frame";
|
|
48
55
|
export declare function createOffscreenChartRenderer(canvas: HTMLCanvasElement, lineWidth?: number,
|
|
49
56
|
/** Its context was lost (Chrome dropped it): the caller makes a new canvas and renderer. */
|
|
50
|
-
onLost?: () => void
|
|
57
|
+
onLost?: () => void,
|
|
58
|
+
/** Lets a chart in view take this one's context while it is hidden (see sharedGl canOwnGl). */
|
|
59
|
+
holder?: GlHolder,
|
|
60
|
+
/**
|
|
61
|
+
* A second canvas over the same plot: until the worker has drawn its first picture (a new context: 60-130 ms),
|
|
62
|
+
* the lines are drawn here through the shared context, so a chart shown again never shows axes without lines.
|
|
63
|
+
*/
|
|
64
|
+
bridge?: HTMLCanvasElement): OffscreenChartRenderer | null;
|
|
51
65
|
/**
|
|
52
66
|
* The same renderer on the main thread through the page's shared WebGL
|
|
53
67
|
* context (see sharedGl): for charts past the contexts a page may own. Each
|
|
@@ -18,10 +18,19 @@ export interface GlLease {
|
|
|
18
18
|
lost(): boolean;
|
|
19
19
|
release(): void;
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
21
|
+
/** A chart that can give its own context up while it is hidden (`evict` releases it before returning). */
|
|
22
|
+
export interface GlHolder {
|
|
23
|
+
hidden(): boolean;
|
|
24
|
+
evict(): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Whether a chart may still own a context (a worker of its own, say). With none left, a chart that is hidden (a
|
|
28
|
+
* worksheet kept mounted) gives its own up: the charts of the first worksheets visited held all of them for good,
|
|
29
|
+
* and every chart shown after drew on the main thread through the shared context.
|
|
30
|
+
*/
|
|
22
31
|
export declare function canOwnGl(): boolean;
|
|
23
|
-
/** Count a context a chart owns outside `leaseGl` (a worker's); returns its release. */
|
|
24
|
-
export declare function ownGl(): () => void;
|
|
32
|
+
/** Count a context a chart owns outside `leaseGl` (a worker's); returns its release. `holder`: see GlHolder. */
|
|
33
|
+
export declare function ownGl(holder?: GlHolder): () => void;
|
|
25
34
|
/**
|
|
26
35
|
* A context for the chart canvas `visible`: the shared one (the chart's canvas shows copies through 2D), which comes
|
|
27
36
|
* back when Chrome drops it; with `own`, its own while the budget lasts (lost for good if Chrome drops it: the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kymoscope/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "The Kymoscope data engine and charts for the browser: import large measurement files, plot them, stream live data end-to-end encrypted.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"homepage": "https://kymoscope.com/docs/introduction",
|
|
@@ -64,6 +64,9 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"aws4fetch": "1.0.20"
|
|
69
|
+
},
|
|
67
70
|
"main": "./dist/kymoscope-sdk.js",
|
|
68
71
|
"module": "./dist/kymoscope-sdk.js",
|
|
69
72
|
"types": "./dist/types/index.d.ts"
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
function e(e,t,n){let r=e.createShader(t);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.error(`glLines shader compile failed:`,e.getShaderInfoLog(r)),e.deleteShader(r),null)):null}const t=1024,n=`#version 300 es
|
|
2
|
-
in vec2 a_corner; // static quad corner: (±1, ±1)
|
|
3
|
-
in float a_ax; // per instance: segment start/end X (relative to the layer origin)
|
|
4
|
-
in float a_bx;
|
|
5
|
-
in float a_ay; // per instance: segment start/end value
|
|
6
|
-
in float a_by;
|
|
7
|
-
in float a_bstart; // 1 where the END point starts a new trace (or a new series)
|
|
8
|
-
in float a_sid; // series of the START point
|
|
9
|
-
uniform highp sampler2D u_styles;
|
|
10
|
-
uniform vec2 u_resolution;
|
|
11
|
-
uniform float u_left; // plot left edge (CSS px)
|
|
12
|
-
uniform float u_plotW;
|
|
13
|
-
uniform float u_xoff; // view xmin - origin
|
|
14
|
-
uniform float u_xscale; // plot width px / view X range
|
|
15
|
-
uniform float u_xR; // view X range
|
|
16
|
-
uniform float u_minGap; // floor of the gap threshold (resampled: buckets apart)
|
|
17
|
-
uniform float u_cutPx; // nothing right of this (CSS px): a live trace's display edge
|
|
18
|
-
flat out vec2 v_a;
|
|
19
|
-
flat out vec2 v_b;
|
|
20
|
-
flat out vec4 v_color;
|
|
21
|
-
flat out float v_halfWidth;
|
|
22
|
-
flat out vec4 v_clip; // left, top, right, bottom (CSS px)
|
|
23
|
-
out vec2 v_pos;
|
|
24
|
-
vec4 style(int sid, int k) {
|
|
25
|
-
return texelFetch(u_styles, ivec2((sid % ${t}) * 3 + k, sid / ${t}), 0);
|
|
26
|
-
}
|
|
27
|
-
void main() {
|
|
28
|
-
int sid = int(a_sid + 0.5);
|
|
29
|
-
vec4 s0 = style(sid, 0); // scale lo, scale hi, band top, band bottom
|
|
30
|
-
vec4 s1 = style(sid, 1); // colour
|
|
31
|
-
vec4 s2 = style(sid, 2); // mean step, half width, quad extension, visible
|
|
32
|
-
// Same threshold as the on-main path (joinGapThreshold over the mean step).
|
|
33
|
-
float gap = max(u_minGap, s2.x > 0.0 ? max(s2.x * 4.0, u_xR * 1e-9) : max(u_xR * 1e-6, 1e-12));
|
|
34
|
-
if (s2.w < 0.5 || a_bstart > 0.5 || abs(a_bx - a_ax) > gap) {
|
|
35
|
-
// Not a segment (a gap, a trace or series start, a hidden series): collapse off-screen.
|
|
36
|
-
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
37
|
-
v_a = vec2(0.0); v_b = vec2(0.0); v_pos = vec2(0.0);
|
|
38
|
-
v_color = vec4(0.0); v_halfWidth = 0.0; v_clip = vec4(0.0);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
float lo = s0.x, hi = s0.y, top = s0.z, bottom = s0.w;
|
|
42
|
-
float ta = hi == lo ? 0.5 : clamp((a_ay - lo) / (hi - lo), 0.0, 1.0);
|
|
43
|
-
float tb = hi == lo ? 0.5 : clamp((a_by - lo) / (hi - lo), 0.0, 1.0);
|
|
44
|
-
vec2 a = vec2(u_left + (a_ax - u_xoff) * u_xscale, top + (1.0 - ta) * (bottom - top));
|
|
45
|
-
vec2 b = vec2(u_left + (a_bx - u_xoff) * u_xscale, top + (1.0 - tb) * (bottom - top));
|
|
46
|
-
vec2 ab = b - a;
|
|
47
|
-
float len = length(ab);
|
|
48
|
-
vec2 dir = len > 1e-6 ? ab / len : vec2(1.0, 0.0);
|
|
49
|
-
vec2 n = vec2(-dir.y, dir.x);
|
|
50
|
-
vec2 base = mix(a, b, step(0.0, a_corner.x));
|
|
51
|
-
vec2 pos = base + dir * (a_corner.x * s2.z) + n * (a_corner.y * s2.z);
|
|
52
|
-
v_a = a;
|
|
53
|
-
v_b = b;
|
|
54
|
-
v_pos = pos;
|
|
55
|
-
v_color = s1;
|
|
56
|
-
v_halfWidth = s2.y;
|
|
57
|
-
v_clip = vec4(u_left, top, min(u_left + u_plotW, u_cutPx), bottom);
|
|
58
|
-
vec2 clip = pos / u_resolution * 2.0 - 1.0;
|
|
59
|
-
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
60
|
-
}`;function r(e,t,n,r){let i=e.length,a=0;for(let t=0;t<i;t++)Number.isFinite(r[t])&&Number.isFinite(e[t])&&a++;if(a===i)return null;let o=new Float32Array(a),s=new Float32Array(a),c=new Uint8Array(a),l=0,u=!1;for(let a=0;a<i;a++)n[a]&&(u=!0),Number.isFinite(r[a])&&Number.isFinite(e[a])&&(o[l]=t[a],s[l]=r[a],u&&=(c[l]=255,!1),l++);return{x:o,y:s,starts:c}}function i(e,t,n){let i=e.length,a=0;for(let t=0;t<i;t++)if(Number.isFinite(e[t])){a=e[t];break}let o=new Float32Array(i);for(let t=0;t<i;t++)o[t]=e[t]-a;let s=new Uint8Array(i);if(t)for(let e=0;e<i;e++)t[e]&&(s[e]=255);let c=n.map(t=>r(e,o,s,t)??{x:o,y:t,starts:s}),l=c.map(e=>e.y.length),u=l.reduce((e,t)=>e+t,0),d=new Float32Array(u),f=new Float32Array(u),p=new Uint8Array(u),m=new Float32Array(u),h=0;return c.forEach((e,t)=>{d.set(e.x,h),f.set(e.y,h),p.set(e.starts,h),e.y.length>0&&(p[h]=255),m.fill(t,h,h+e.y.length),h+=e.y.length}),{origin:a,x:d,y:f,starts:p,sid:m,counts:l}}function a(e,t,n,r,i,a){let o=(i-r)/a,s=(t,n)=>{let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r},c=s(r,!1),l=s(i,!0),u=t.length*(2*a+2),d=new Float32Array(u),f=new Float32Array(u),p=new Uint8Array(u),m=new Float32Array(u),h=0,g=(e,t,r)=>{d[h]=e-n,f[h]=t,m[h]=r,h++};return t.forEach((t,n)=>{let i=h;for(let r=c-1;r>=Math.max(0,c-64);r--)if(t[r]===t[r]){g(e[r],t[r],n);break}let s=c;for(let i=0;i<a&&s<l;i++){let c=i===a-1?1/0:r+(i+1)*o,u=1/0,d=-1/0,f=-1,p=-1;for(;s<l&&e[s]<c;s++){let e=t[s];e<u&&(u=e,f=s),e>d&&(d=e,p=s)}f<0||(f===p?g(e[f],u,n):f<p?(g(e[f],u,n),g(e[p],d,n)):(g(e[p],d,n),g(e[f],u,n)))}for(let r=l;r<Math.min(e.length,l+64);r++)if(t[r]===t[r]){g(e[r],t[r],n);break}h>i&&(p[i]=255)}),{x:d.subarray(0,h),y:f.subarray(0,h),starts:p.subarray(0,h),sid:m.subarray(0,h),bucket:o}}function o(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return e.length===0||e[0]===e[0]}function s(r,s=1){let c=r.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0}),l=typeof HTMLCanvasElement<`u`&&r instanceof HTMLCanvasElement||typeof OffscreenCanvas<`u`&&r instanceof OffscreenCanvas;if(!c)return null;let u=e(c,c.VERTEX_SHADER,n),d=e(c,c.FRAGMENT_SHADER,`#version 300 es
|
|
61
|
-
precision highp float;
|
|
62
|
-
flat in vec2 v_a;
|
|
63
|
-
flat in vec2 v_b;
|
|
64
|
-
flat in vec4 v_color;
|
|
65
|
-
flat in float v_halfWidth;
|
|
66
|
-
flat in vec4 v_clip;
|
|
67
|
-
in vec2 v_pos;
|
|
68
|
-
out vec4 outColor;
|
|
69
|
-
void main() {
|
|
70
|
-
if (v_pos.x < v_clip.x || v_pos.x > v_clip.z || v_pos.y < v_clip.y || v_pos.y > v_clip.w) discard;
|
|
71
|
-
vec2 ab = v_b - v_a;
|
|
72
|
-
float t = clamp(dot(v_pos - v_a, ab) / max(dot(ab, ab), 1e-12), 0.0, 1.0);
|
|
73
|
-
float d = distance(v_pos, v_a + ab * t);
|
|
74
|
-
float aa = max(fwidth(d), 1e-4);
|
|
75
|
-
float e = clamp((v_halfWidth - d) / aa + 0.5, 0.0, 1.0);
|
|
76
|
-
float cov = e * e * (3.0 - 2.0 * e);
|
|
77
|
-
if (cov <= 0.0) discard;
|
|
78
|
-
float alpha = v_color.a * cov;
|
|
79
|
-
outColor = vec4(v_color.rgb * alpha, alpha);
|
|
80
|
-
}`);if(!u||!d)return null;let f=c.createProgram();if(!f)return null;if(c.attachShader(f,u),c.attachShader(f,d),c.linkProgram(f),!c.getProgramParameter(f,c.LINK_STATUS))return console.error(`glSeries program link failed:`,c.getProgramInfoLog(f)),null;let p=e=>c.getAttribLocation(f,e),m=p(`a_corner`),h=p(`a_ax`),g=p(`a_bx`),_=p(`a_ay`),v=p(`a_by`),y=p(`a_bstart`),b=p(`a_sid`),x=[h,g,_,v,y,b],S=e=>c.getUniformLocation(f,e),C={res:S(`u_resolution`),styles:S(`u_styles`),left:S(`u_left`),plotW:S(`u_plotW`),xoff:S(`u_xoff`),xscale:S(`u_xscale`),xR:S(`u_xR`),minGap:S(`u_minGap`),cutPx:S(`u_cutPx`)},w=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,w),c.bufferData(c.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),c.STATIC_DRAW);let T=c.createFramebuffer(),E=c.createRenderbuffer(),D=1,O=1,k=(`clientWidth`in r?r.clientWidth:0)||1,A=(`clientHeight`in r?r.clientHeight:0)||1,j=[],M=0,N=1,P=1/0,F=e=>{let t=c.createBuffer();return c.bindBuffer(c.ARRAY_BUFFER,t),c.bufferData(c.ARRAY_BUFFER,e,c.STATIC_DRAW),t},I=e=>{if(e)for(let t of[e.x,e.y,e.starts,e.sid])c.deleteBuffer(t)},L=e=>{e&&(I(e.full),I(e.res),c.deleteTexture(e.styles))},R=e=>({x:F(e.x),y:F(e.y),starts:F(e.starts),sid:F(e.sid),total:e.x.length}),z=e=>{let t=e.full;if(t&&t.version===e.version)return t;if(t&&e.valuesOnly&&t.whole&&e.counts.every(t=>t===e.xs.length)){let n=e.xs.length,r=e.columns.length===1?e.columns[0]:new Float32Array(n*e.columns.length);return e.columns.length>1&&e.columns.forEach((e,t)=>r.set(e,t*n)),c.bindBuffer(c.ARRAY_BUFFER,t.y),c.bufferSubData(c.ARRAY_BUFFER,0,r),t.version=e.version,t}I(t);let n=i(e.xs,e.breaks,e.columns);return e.full={...R(n),version:e.version,whole:n.counts.every(t=>t===e.xs.length)},e.full},B=e=>{let t=Math.max(1,Math.round(e.plotW*(r.width/k)));if(e.resamplable&&N>M){let n=e.xs,r=0,i=n.length;for(;r<i;){let e=r+i>>>1;n[e]<M?r=e+1:i=e}let o=r;for(i=n.length;r<i;){let e=r+i>>>1;n[e]<=N?r=e+1:i=e}if(r-o>t*4){let r=`${e.version}|${M}|${N}|${t}`;if(e.res?.key!==r){I(e.res);let i=a(n,e.columns,e.origin,M,N,t);e.res={...R(i),key:r,bucket:i.bucket}}return{d:e.res,minGap:e.res.bucket*2.5}}}return{d:z(e),minGap:0}},V=(e,n)=>{let r=e.counts.length,i=Math.max(1,Math.ceil(r/t)),a=3*Math.min(Math.max(r,1),t),o=new Float32Array(a*i*4);for(let i=0;i<r;i++){let r=n[i],c=(Math.floor(i/t)*a+i%t*3)*4;if(!r)continue;let l=r.width??s;o.set([Math.min(r.scaleMin,r.scaleMax),Math.max(r.scaleMin,r.scaleMax),r.bandTop,r.bandBottom],c),o.set(r.color,c+4),o.set([r.gapMedian,l/2,l/2+2.5,+(e.counts[i]>=2)],c+8)}c.bindTexture(c.TEXTURE_2D,e.styles),c.texImage2D(c.TEXTURE_2D,0,c.RGBA32F,a,i,0,c.RGBA,c.FLOAT,o),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.NEAREST),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.NEAREST)};return{resize(e,t,n){k=Math.max(1,e),A=Math.max(1,t),r.width=Math.round(k*n),r.height=Math.round(A*n),D=r.width*2,O=r.height*2,T&&E&&(c.bindRenderbuffer(c.RENDERBUFFER,E),c.renderbufferStorage(c.RENDERBUFFER,c.RGBA8,D,O),c.bindFramebuffer(c.FRAMEBUFFER,T),c.framebufferRenderbuffer(c.FRAMEBUFFER,c.COLOR_ATTACHMENT0,c.RENDERBUFFER,E),c.bindFramebuffer(c.FRAMEBUFFER,null))},setData(e,t,n,r){let i=j[e],a=!t&&!!i&&r.length===i.columns.length;if(!t){if(!i)return;t=i.xs,n=i.breaks}let s=0;for(let e=0;e<t.length;e++)if(Number.isFinite(t[e])){s=t[e];break}let l=r.map(e=>{let t=0;for(let n=0;n<e.length;n++)e[n]===e[n]&&t++;return t});if(i&&(a||i.xs===t)){i.columns=r,i.counts=l,i.valuesOnly=a,i.version++,a||(I(i.full),i.full=null);return}let u={xs:t,breaks:n,columns:r,origin:s,counts:l,resamplable:!n?.some(e=>e)&&o(t),version:0,valuesOnly:!1,full:null,res:null,styles:c.createTexture(),left:i?.left??0,plotW:i?.plotW??0};V(u,[]),j[e]=u,L(i)},setStyles(e,t,n,r){let i=j[e];i&&(V(i,t),i.left=n,i.plotW=r)},clearLayer(e){L(j[e]),j[e]=null},setView(e,t,n=1/0){M=e,N=t,P=n},render(){c.bindFramebuffer(c.FRAMEBUFFER,T),c.viewport(0,0,T?D:r.width,T?O:r.height),c.disable(c.SCISSOR_TEST),c.clearColor(0,0,0,0),c.clear(c.COLOR_BUFFER_BIT),c.useProgram(f),c.uniform2f(C.res,k,A),c.uniform1i(C.styles,0),c.activeTexture(c.TEXTURE0),c.enable(c.BLEND),c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA),c.bindBuffer(c.ARRAY_BUFFER,w),c.enableVertexAttribArray(m),c.vertexAttribPointer(m,2,c.FLOAT,!1,0,0),c.vertexAttribDivisor(m,0);for(let e of x)c.enableVertexAttribArray(e),c.vertexAttribDivisor(e,1);let e=N-M||1;for(let t of j){if(!t)continue;c.uniform1f(C.left,t.left),c.uniform1f(C.plotW,t.plotW),c.uniform1f(C.xoff,M-t.origin),c.uniform1f(C.xscale,t.plotW/e),c.uniform1f(C.xR,e),c.uniform1f(C.cutPx,Number.isFinite(P)?t.left+(P-M)*(t.plotW/e):1e9);let{d:n,minGap:r}=B(t);n.total<2||(c.uniform1f(C.minGap,r),c.bindTexture(c.TEXTURE_2D,t.styles),c.bindBuffer(c.ARRAY_BUFFER,n.x),c.vertexAttribPointer(h,1,c.FLOAT,!1,4,0),c.vertexAttribPointer(g,1,c.FLOAT,!1,4,4),c.bindBuffer(c.ARRAY_BUFFER,n.y),c.vertexAttribPointer(_,1,c.FLOAT,!1,4,0),c.vertexAttribPointer(v,1,c.FLOAT,!1,4,4),c.bindBuffer(c.ARRAY_BUFFER,n.starts),c.vertexAttribPointer(y,1,c.UNSIGNED_BYTE,!0,1,1),c.bindBuffer(c.ARRAY_BUFFER,n.sid),c.vertexAttribPointer(b,1,c.FLOAT,!1,4,0),c.drawArraysInstanced(c.TRIANGLE_STRIP,0,4,n.total-1))}for(let e of x)c.vertexAttribDivisor(e,0);T&&(c.bindFramebuffer(c.READ_FRAMEBUFFER,T),c.bindFramebuffer(c.DRAW_FRAMEBUFFER,null),c.blitFramebuffer(0,0,D,O,0,0,r.width,r.height,c.COLOR_BUFFER_BIT,c.LINEAR),c.bindFramebuffer(c.FRAMEBUFFER,null))},dispose(){for(let e of j)L(e);j.length=0,c.deleteBuffer(w),c.deleteFramebuffer(T),c.deleteRenderbuffer(E),c.deleteProgram(f),c.deleteShader(u),c.deleteShader(d),l&&c.getExtension(`WEBGL_lose_context`)?.loseContext()}}}let c=null,l=0,u=1,d;function f(e){c?.setStyles(e.layer,e.styles,e.left,e.plotW),l=e.xmin,u=e.xmax,d=e.cut,c?.setView(l,u,d),c?.render()}self.onmessage=e=>{let t=e.data;switch(t.type){case`init`:c=s(t.canvas,t.lineWidth),t.canvas.addEventListener?.(`webglcontextlost`,e=>{e.preventDefault(),self.postMessage({type:`lost`})});break;case`resize`:c?.resize(t.w,t.h,t.dpr),c?.render();break;case`data`:c?.setData(t.layer,t.xs,t.breaks,t.columns),f(t);break;case`style`:f(t);break;case`clear`:c?.clearLayer(t.layer),c?.render();break;case`view`:if(t.xmin===l&&t.xmax===u&&t.cut===d)break;l=t.xmin,u=t.xmax,d=t.cut,c?.setView(l,u,d),c?.render();break;case`dispose`:c?.dispose(),c=null,self.close();break}};
|