framesheet 0.0.0-stage → 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 (85) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +247 -2
  3. package/dist/analysis.d.ts +84 -0
  4. package/dist/analysis.d.ts.map +1 -0
  5. package/dist/analysis.js +335 -0
  6. package/dist/analysis.js.map +1 -0
  7. package/dist/checks.d.ts +44 -0
  8. package/dist/checks.d.ts.map +1 -0
  9. package/dist/checks.js +200 -0
  10. package/dist/checks.js.map +1 -0
  11. package/dist/compose.d.ts +130 -0
  12. package/dist/compose.d.ts.map +1 -0
  13. package/dist/compose.js +266 -0
  14. package/dist/compose.js.map +1 -0
  15. package/dist/driver.d.ts +56 -0
  16. package/dist/driver.d.ts.map +1 -0
  17. package/dist/driver.js +94 -0
  18. package/dist/driver.js.map +1 -0
  19. package/dist/generated/assets.d.ts +13 -0
  20. package/dist/generated/assets.d.ts.map +1 -0
  21. package/dist/generated/assets.js +15 -0
  22. package/dist/generated/assets.js.map +1 -0
  23. package/dist/index.d.ts +18 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +17 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/inspect.d.ts +163 -0
  28. package/dist/inspect.d.ts.map +1 -0
  29. package/dist/inspect.js +593 -0
  30. package/dist/inspect.js.map +1 -0
  31. package/dist/marks.d.ts +49 -0
  32. package/dist/marks.d.ts.map +1 -0
  33. package/dist/marks.js +460 -0
  34. package/dist/marks.js.map +1 -0
  35. package/dist/marks.schema.json +307 -0
  36. package/dist/media.d.ts +22 -0
  37. package/dist/media.d.ts.map +1 -0
  38. package/dist/media.js +306 -0
  39. package/dist/media.js.map +1 -0
  40. package/dist/models.d.ts +208 -0
  41. package/dist/models.d.ts.map +1 -0
  42. package/dist/models.js +9 -0
  43. package/dist/models.js.map +1 -0
  44. package/dist/pixels.d.ts +52 -0
  45. package/dist/pixels.d.ts.map +1 -0
  46. package/dist/pixels.js +275 -0
  47. package/dist/pixels.js.map +1 -0
  48. package/dist/pyfmt.d.ts +16 -0
  49. package/dist/pyfmt.d.ts.map +1 -0
  50. package/dist/pyfmt.js +54 -0
  51. package/dist/pyfmt.js.map +1 -0
  52. package/dist/report.schema.json +1326 -0
  53. package/dist/sources.d.ts +43 -0
  54. package/dist/sources.d.ts.map +1 -0
  55. package/dist/sources.js +164 -0
  56. package/dist/sources.js.map +1 -0
  57. package/dist/test.d.ts +46 -0
  58. package/dist/test.d.ts.map +1 -0
  59. package/dist/test.js +58 -0
  60. package/dist/test.js.map +1 -0
  61. package/dist/timing.d.ts +30 -0
  62. package/dist/timing.d.ts.map +1 -0
  63. package/dist/timing.js +128 -0
  64. package/dist/timing.js.map +1 -0
  65. package/dist/video.d.ts +65 -0
  66. package/dist/video.d.ts.map +1 -0
  67. package/dist/video.js +440 -0
  68. package/dist/video.js.map +1 -0
  69. package/package.json +79 -4
  70. package/src/analysis.ts +416 -0
  71. package/src/checks.ts +261 -0
  72. package/src/compose.ts +337 -0
  73. package/src/driver.ts +115 -0
  74. package/src/generated/assets.ts +20 -0
  75. package/src/index.ts +54 -0
  76. package/src/inspect.ts +722 -0
  77. package/src/marks.ts +481 -0
  78. package/src/media.ts +296 -0
  79. package/src/models.ts +225 -0
  80. package/src/pixels.ts +284 -0
  81. package/src/pyfmt.ts +55 -0
  82. package/src/sources.ts +175 -0
  83. package/src/test.ts +100 -0
  84. package/src/timing.ts +133 -0
  85. package/src/video.ts +513 -0
package/src/media.ts ADDED
@@ -0,0 +1,296 @@
1
+ /**
2
+ * Container probing for video inputs (no ffmpeg): format, codec, size, frame rate
3
+ * (port of media.py). Best effort: unknown fields are `null`.
4
+ */
5
+
6
+ import { pyRound } from "./pyfmt.js";
7
+
8
+ export const VIDEO_EXTENSIONS: Record<string, string> = {
9
+ ".mp4": "mp4",
10
+ ".m4v": "mp4",
11
+ ".mov": "mov",
12
+ ".webm": "webm",
13
+ ".mkv": "mkv",
14
+ ".gif": "gif",
15
+ ".webp": "webp",
16
+ };
17
+ export const MIME_TYPES: Record<string, string> = {
18
+ mp4: "video/mp4",
19
+ mov: "video/mp4",
20
+ webm: "video/webm",
21
+ mkv: "video/webm",
22
+ gif: "image/gif",
23
+ webp: "image/webp",
24
+ };
25
+ const MP4_CODECS: Record<string, string> = {
26
+ avc1: "h264",
27
+ avc3: "h264",
28
+ hvc1: "hevc",
29
+ hev1: "hevc",
30
+ av01: "av1",
31
+ vp09: "vp9",
32
+ vp08: "vp8",
33
+ mp4v: "mpeg4",
34
+ };
35
+ const MKV_CODECS: Record<string, string> = {
36
+ V_VP8: "vp8",
37
+ V_VP9: "vp9",
38
+ V_AV1: "av1",
39
+ "V_MPEG4/ISO/AVC": "h264",
40
+ "V_MPEGH/ISO/HEVC": "hevc",
41
+ };
42
+
43
+ /** What the container says about the (first) video track. */
44
+ export interface Probe {
45
+ container: string;
46
+ codec: string | null;
47
+ width: number | null;
48
+ height: number | null;
49
+ fps: number | null;
50
+ frameCount: number | null;
51
+ duration: number | null;
52
+ }
53
+
54
+ export const isAnimatedImage = (p: Probe) => p.container === "gif" || p.container === "webp";
55
+
56
+ const ascii = (data: Uint8Array, s: number, e: number) => String.fromCharCode(...data.subarray(s, e));
57
+
58
+ /** Container from magic bytes (`null` if not a supported video/animated image). */
59
+ export function sniff(data: Uint8Array): string | null {
60
+ if (ascii(data, 4, 8) === "ftyp") return ascii(data, 8, 12) === "qt " ? "mov" : "mp4";
61
+ if (data[0] === 0x1a && data[1] === 0x45 && data[2] === 0xdf && data[3] === 0xa3) {
62
+ return ascii(data, 0, 64).includes("webm") ? "webm" : "mkv";
63
+ }
64
+ const head = ascii(data, 0, 6);
65
+ if (head === "GIF87a" || head === "GIF89a") return "gif";
66
+ if (ascii(data, 0, 4) === "RIFF" && ascii(data, 8, 12) === "WEBP") return "webp";
67
+ return null;
68
+ }
69
+
70
+ /** Parse the container header (`container` is used if the magic bytes are unknown). */
71
+ export function probe(data: Uint8Array, container: string | null = null): Probe {
72
+ const kind = sniff(data) ?? container;
73
+ if (kind === null) throw new Error("Not a supported video or animated image (mp4, mov, webm, mkv, gif, webp)");
74
+ const out: Probe = { container: kind, codec: null, width: null, height: null, fps: null, frameCount: null, duration: null };
75
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
76
+ try {
77
+ if (kind === "mp4" || kind === "mov") mp4(data, view, out);
78
+ else if (kind === "webm" || kind === "mkv") matroska(data, view, out);
79
+ else if (kind === "gif") {
80
+ out.codec = "gif";
81
+ out.width = view.getUint16(6, true);
82
+ out.height = view.getUint16(8, true);
83
+ } else if (kind === "webp") {
84
+ out.codec = "webp";
85
+ webp(data, view, out);
86
+ }
87
+ } catch {
88
+ // Truncated or unusual header: keep what was found.
89
+ }
90
+ if (out.fps !== null) out.fps = pyRound(out.fps, 3);
91
+ if (out.duration !== null) out.duration = pyRound(out.duration, 4);
92
+ return out;
93
+ }
94
+
95
+ // ISO BMFF -------------------------------------------------------------------------------
96
+
97
+ const MP4_CONTAINERS = new Set(["moov", "trak", "mdia", "minf", "stbl"]);
98
+
99
+ function* boxes(data: Uint8Array, view: DataView, start: number, end: number): Generator<[string, number, number]> {
100
+ let pos = start;
101
+ while (pos + 8 <= end) {
102
+ let size = view.getUint32(pos);
103
+ const kind = ascii(data, pos + 4, pos + 8);
104
+ let header = 8;
105
+ if (size === 1) {
106
+ size = Number(view.getBigUint64(pos + 8));
107
+ header = 16;
108
+ } else if (size === 0) {
109
+ size = end - pos;
110
+ }
111
+ if (size < header) return;
112
+ yield [kind, pos + header, Math.min(pos + size, end)];
113
+ pos += size;
114
+ }
115
+ }
116
+
117
+ function mp4(data: Uint8Array, view: DataView, out: Probe): void {
118
+ for (const [kind, start, end] of boxes(data, view, 0, data.length)) {
119
+ if (kind !== "moov") continue;
120
+ for (const [tkind, ts, te] of boxes(data, view, start, end)) {
121
+ if (tkind === "trak" && mp4Track(data, view, ts, te, out)) return;
122
+ }
123
+ }
124
+ }
125
+
126
+ function mp4Track(data: Uint8Array, view: DataView, start: number, end: number, out: Probe): boolean {
127
+ const found = new Map<string, [number, number]>();
128
+ const walk = (s: number, e: number) => {
129
+ for (const [kind, cs, ce] of boxes(data, view, s, e)) {
130
+ if (MP4_CONTAINERS.has(kind)) walk(cs, ce);
131
+ else if (!found.has(kind)) found.set(kind, [cs, ce]);
132
+ }
133
+ };
134
+ walk(start, end);
135
+ const hdlr = found.get("hdlr");
136
+ if (!hdlr || ascii(data, hdlr[0] + 8, hdlr[0] + 12) !== "vide") return false;
137
+ let timescale = 0;
138
+ const mdhd = found.get("mdhd");
139
+ if (mdhd) {
140
+ const s = mdhd[0];
141
+ let duration: number;
142
+ if (data[s] === 1) {
143
+ timescale = view.getUint32(s + 20);
144
+ duration = Number(view.getBigUint64(s + 24));
145
+ } else {
146
+ timescale = view.getUint32(s + 12);
147
+ duration = view.getUint32(s + 16);
148
+ }
149
+ if (timescale) out.duration = duration / timescale;
150
+ }
151
+ const stsd = found.get("stsd");
152
+ if (stsd) {
153
+ const entry = stsd[0] + 8;
154
+ const fourcc = ascii(data, entry + 4, entry + 8);
155
+ out.codec = MP4_CODECS[fourcc] ?? (fourcc.trim() || null);
156
+ out.width = view.getUint16(entry + 32);
157
+ out.height = view.getUint16(entry + 34);
158
+ }
159
+ const stts = found.get("stts");
160
+ if (stts && timescale) {
161
+ const count = view.getUint32(stts[0] + 4);
162
+ let frames = 0;
163
+ let total = 0;
164
+ for (let i = 0; i < count; i++) {
165
+ const n = view.getUint32(stts[0] + 8 + 8 * i);
166
+ const delta = view.getUint32(stts[0] + 12 + 8 * i);
167
+ frames += n;
168
+ total += n * delta;
169
+ }
170
+ if (frames) out.frameCount = frames;
171
+ if (total) out.fps = (frames * timescale) / total;
172
+ }
173
+ return true;
174
+ }
175
+
176
+ // Matroska / WebM ------------------------------------------------------------------------
177
+
178
+ const MKV_ENTER = new Set([0x18538067, 0x1549a966, 0x1654ae6b, 0xe0, 0x1f43b675, 0xa0]);
179
+ const TRACK_ENTRY = 0xae;
180
+ const TIMECODE_SCALE = 0x2ad7b1;
181
+ const DURATION = 0x4489;
182
+ const CODEC_ID = 0x86;
183
+ const TRACK_UINTS: Record<number, string> = {
184
+ 0xd7: "number",
185
+ 0x83: "type",
186
+ 0x23e383: "default_duration",
187
+ 0xb0: "width",
188
+ 0xba: "height",
189
+ };
190
+ const BLOCKS = new Set([0xa3, 0xa1]);
191
+
192
+ /** EBML variable-length integer -> [value, length, all-ones = unknown size]. */
193
+ function vint(data: Uint8Array, pos: number, strip: boolean): [number, number, boolean] {
194
+ const first = data[pos];
195
+ if (first === undefined) throw new Error("truncated");
196
+ let length = 1;
197
+ let mask = 0x80;
198
+ while (length <= 8 && !(first & mask)) {
199
+ mask >>= 1;
200
+ length++;
201
+ }
202
+ if (length > 8) throw new Error("bad EBML vint");
203
+ let value = strip ? first & (mask - 1) : first;
204
+ for (let i = 1; i < length; i++) {
205
+ const b = data[pos + i];
206
+ if (b === undefined) throw new Error("truncated");
207
+ value = value * 256 + b;
208
+ }
209
+ const unknown = strip && value === 2 ** (7 * length) - 1;
210
+ return [value, length, unknown];
211
+ }
212
+
213
+ function uint(data: Uint8Array, s: number, e: number): number {
214
+ let v = 0;
215
+ for (let i = s; i < e; i++) v = v * 256 + data[i];
216
+ return v;
217
+ }
218
+
219
+ function matroska(data: Uint8Array, view: DataView, out: Probe): void {
220
+ const tracks: Record<string, number | string>[] = [];
221
+ const blocks = new Map<number, number>();
222
+ let timescale = 1_000_000;
223
+ let duration: number | null = null;
224
+ const [headerSize, headerLen] = vint(data, 4, true);
225
+ let pos = 4 + headerLen + headerSize;
226
+ const end = data.length;
227
+ while (pos < end) {
228
+ const [eid, ilen] = vint(data, pos, false);
229
+ const [size, slen, unknown] = vint(data, pos + ilen, true);
230
+ const body = pos + ilen + slen;
231
+ if (MKV_ENTER.has(eid)) {
232
+ pos = body;
233
+ continue;
234
+ }
235
+ if (eid === TRACK_ENTRY) {
236
+ tracks.push({});
237
+ pos = body;
238
+ continue;
239
+ }
240
+ if (unknown) break;
241
+ const stop = Math.min(body + size, end);
242
+ const track = tracks.length ? tracks[tracks.length - 1] : {};
243
+ if (eid === TIMECODE_SCALE) timescale = uint(data, body, stop);
244
+ else if (eid === DURATION) duration = size === 4 ? view.getFloat32(body) : view.getFloat64(body);
245
+ else if (eid === CODEC_ID) track.codec = ascii(data, body, stop).replace(/\0+$/, "");
246
+ else if (eid in TRACK_UINTS) track[TRACK_UINTS[eid]] = uint(data, body, stop);
247
+ else if (BLOCKS.has(eid)) {
248
+ const number = vint(data, body, true)[0];
249
+ blocks.set(number, (blocks.get(number) ?? 0) + 1);
250
+ }
251
+ pos = stop;
252
+ }
253
+ if (duration !== null) out.duration = (duration * timescale) / 1e9;
254
+ const video = tracks.find((t) => t.type === 1);
255
+ if (!video) return;
256
+ const codec = String(video.codec ?? "");
257
+ out.codec = MKV_CODECS[codec] ?? (codec.replace(/^V_/, "").toLowerCase() || null);
258
+ out.width = typeof video.width === "number" ? video.width : null;
259
+ out.height = typeof video.height === "number" ? video.height : null;
260
+ const count = typeof video.number === "number" ? blocks.get(video.number) : undefined;
261
+ out.frameCount = count || null;
262
+ const dd = video.default_duration;
263
+ if (typeof dd === "number" && dd > 0) out.fps = 1e9 / dd;
264
+ else if (count && out.duration) out.fps = count / out.duration;
265
+ }
266
+
267
+ // WebP -----------------------------------------------------------------------------------
268
+
269
+ function webp(data: Uint8Array, view: DataView, out: Probe): void {
270
+ let pos = 12;
271
+ let frames = 0;
272
+ let totalMs = 0;
273
+ const u24 = (p: number) => data[p] | (data[p + 1] << 8) | (data[p + 2] << 16);
274
+ while (pos + 8 <= data.length) {
275
+ const kind = ascii(data, pos, pos + 4);
276
+ const size = view.getUint32(pos + 4, true);
277
+ const body = pos + 8;
278
+ if (kind === "VP8X") {
279
+ out.width = 1 + u24(body + 4);
280
+ out.height = 1 + u24(body + 7);
281
+ } else if (kind === "ANMF") {
282
+ frames++;
283
+ totalMs += u24(body + 12);
284
+ } else if (kind === "VP8 " && out.width === null) {
285
+ out.width = view.getUint16(body + 6, true) & 0x3fff;
286
+ out.height = view.getUint16(body + 8, true) & 0x3fff;
287
+ } else if (kind === "VP8L" && out.width === null) {
288
+ const bits = view.getUint32(body + 1, true);
289
+ out.width = (bits & 0x3fff) + 1;
290
+ out.height = ((bits >>> 14) & 0x3fff) + 1;
291
+ }
292
+ pos = body + size + (size & 1);
293
+ }
294
+ out.frameCount = frames || 1;
295
+ if (totalMs) out.duration = totalMs / 1000;
296
+ }
package/src/models.ts ADDED
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Report types: the same shape as the Python package's `report.json`
3
+ * (`framesheet.models.InspectionResult`), checked against ../schema/report.schema.json.
4
+ * Field names are snake_case on purpose: one schema for both implementations.
5
+ */
6
+
7
+ export type Severity = "error" | "warning" | "info";
8
+ export type SourceKind = "svg" | "html" | "video";
9
+ export type ColorScheme = "light" | "dark";
10
+ /** An axis-aligned box as `[x, y, width, height]`. */
11
+ export type Rect = [number, number, number, number];
12
+
13
+ /** A single problem (or noteworthy fact) found by a static or render check. */
14
+ export interface Finding {
15
+ severity: Severity;
16
+ /** Stable, kebab-case identifier, e.g. `parked-at-origin` (see schema/finding-codes.json). */
17
+ code: string;
18
+ message: string;
19
+ check: "static" | "render";
20
+ /** Human-readable element label such as `circle#dot` or `text[2] "Hello"`. */
21
+ element: string | null;
22
+ /** Sample times (seconds) at which the problem was observed. */
23
+ times: number[] | null;
24
+ }
25
+
26
+ export type AnimationKind = "smil" | "css-animation" | "css-transition" | "web-animation";
27
+
28
+ /** Timing of one declarative animation, as reported by the browser. */
29
+ export interface AnimationTiming {
30
+ kind: AnimationKind;
31
+ target: string | null;
32
+ name: string | null;
33
+ /** Begin / delay in seconds (may be negative). */
34
+ start: number;
35
+ /** Duration of one iteration in seconds. */
36
+ duration: number;
37
+ /** Iteration count; `null` means infinite. */
38
+ iterations: number | null;
39
+ direction: string;
40
+ /** Seconds until the animation looks the same again (2x duration for alternate). */
41
+ period: number;
42
+ /** End of the active interval in seconds; `null` if infinite. */
43
+ end: number | null;
44
+ /** Computed `transform-box` of an SVG target whose transform is animated by CSS. */
45
+ transform_box: string | null;
46
+ }
47
+
48
+ export interface DurationInfo {
49
+ seconds: number;
50
+ method: "override" | "detected" | "fallback" | "media";
51
+ /** True if at least one animation repeats forever (or motion is JS-driven). */
52
+ looping: boolean;
53
+ detail: string;
54
+ animations: AnimationTiming[];
55
+ }
56
+
57
+ export interface FrameMetrics {
58
+ index: number;
59
+ t: number;
60
+ /** Share of pixels that differ from the previous frame (0 for the first frame). */
61
+ changed_ratio: number;
62
+ /** Bounding box (CSS px) of the pixels that changed vs. the previous frame. */
63
+ changed_box: Rect | null;
64
+ /** Path of the individual frame PNG, if frames were written. */
65
+ path: string | null;
66
+ }
67
+
68
+ export interface ElementTrack {
69
+ element: string;
70
+ /** `smil`, `css-animation`, `web-animation` and/or `moved` (geometry changed). */
71
+ animated_by: string[];
72
+ units: "viewBox" | "px";
73
+ /** One box per frame (`null` if not rendered at that frame). */
74
+ boxes: (Rect | null)[];
75
+ }
76
+
77
+ export interface LoopInfo {
78
+ checked: boolean;
79
+ seamless: boolean | null;
80
+ /** Changed-pixel share between `t=end-epsilon` and `t=0`. */
81
+ seam_ratio: number | null;
82
+ /** Changed-pixel share between `t=0` and `t=epsilon` (normal motion per step). */
83
+ step_ratio: number | null;
84
+ seam_box: Rect | null;
85
+ detail: string;
86
+ }
87
+
88
+ /** Image paths. Absolute when written to disk (`out`), else bare file names. */
89
+ export interface ImagePaths {
90
+ full: string;
91
+ sheet: string;
92
+ heatmap: string;
93
+ report: string;
94
+ }
95
+
96
+ /** Everything framesheet found out about one input: the content of `report.json`. */
97
+ export interface Report {
98
+ source: string;
99
+ kind: SourceKind;
100
+ viewport: [number, number];
101
+ device_scale_factor: number;
102
+ /** Drawing area in CSS px (viewBox for SVG documents/components, viewport for HTML). */
103
+ canvas: Rect;
104
+ duration: DurationInfo;
105
+ /** Sample times of the contact-sheet tiles in seconds. */
106
+ times: number[];
107
+ full_at: number;
108
+ images: ImagePaths;
109
+ findings: Finding[];
110
+ frames: FrameMetrics[];
111
+ elements: ElementTrack[];
112
+ loop: LoopInfo;
113
+ console_errors: string[];
114
+ /** Media facts and per-tile metrics (video inputs only). */
115
+ video: VideoInfo | null;
116
+ /** The marks drawn onto the sheet, as validated. */
117
+ marks: Marks | null;
118
+ }
119
+
120
+ /** An instant at a position, e.g. a click: drawn on the tile nearest to `t`. */
121
+ export interface MarkPoint {
122
+ t: number;
123
+ x: number;
124
+ y: number;
125
+ label: string | null;
126
+ /** Free-form, e.g. `click`. */
127
+ kind: string | null;
128
+ /** Seconds the point stays relevant (drawn on every tile it overlaps). Default 0. */
129
+ duration: number;
130
+ }
131
+
132
+ /** A time range, optionally with a box: a target element, a zoom, a highlight. */
133
+ export interface MarkRegion {
134
+ x: number | null;
135
+ y: number | null;
136
+ w: number | null;
137
+ h: number | null;
138
+ start: number;
139
+ end: number;
140
+ label: string | null;
141
+ /** Free-form, e.g. `zoom`. `target` boxes are checked against span boxes. */
142
+ kind: string | null;
143
+ }
144
+
145
+ /** A labelled time range, e.g. a caption; the optional box is its screen area. */
146
+ export interface MarkSpan {
147
+ x: number | null;
148
+ y: number | null;
149
+ w: number | null;
150
+ h: number | null;
151
+ start: number;
152
+ end: number;
153
+ label: string;
154
+ kind: string | null;
155
+ }
156
+
157
+ /**
158
+ * Annotations drawn onto video tiles and the timeline (schema: framesheet/schema/marks.schema.json).
159
+ * Times are seconds of the media; coordinates are fractions (0-1) of the video frame, or
160
+ * pixels of `frame` if given.
161
+ */
162
+ export interface Marks {
163
+ frame: { width: number; height: number } | null;
164
+ points: MarkPoint[];
165
+ regions: MarkRegion[];
166
+ spans: MarkSpan[];
167
+ }
168
+
169
+ /** One dense video sample: share of pixels changed since the previous sample. */
170
+ export interface ActivitySample {
171
+ t: number;
172
+ changed_ratio: number;
173
+ }
174
+
175
+ /** Per-tile numbers for videos, so an agent can score without looking. */
176
+ export interface VideoTile {
177
+ index: number;
178
+ t: number;
179
+ /** Presentation time of the decoded frame (`null` if the browser did not say). */
180
+ media_time: number | null;
181
+ black: boolean;
182
+ /** One flat colour that is not black (e.g. a white page before load). */
183
+ blank: boolean;
184
+ /** Near-identical to the previous tile (changes < 0.05% of pixels). */
185
+ duplicate: boolean;
186
+ /** Mean luma gradient (0-510); compare tiles of one video: drops = blur/upscaling. */
187
+ sharpness: number;
188
+ /** Labels of the marks active on this tile. */
189
+ marks: string[];
190
+ }
191
+
192
+ /** Media facts and dense-sample metrics of a video or animated image. */
193
+ export interface VideoInfo {
194
+ container: string;
195
+ codec: string | null;
196
+ decoder: "video" | "image-decoder";
197
+ width: number;
198
+ height: number;
199
+ media_duration: number | null;
200
+ fps: number | null;
201
+ frame_count: number | null;
202
+ start: number;
203
+ end: number;
204
+ /** Seconds without visible change that count as a static stretch. */
205
+ static_threshold: number;
206
+ /** Every sampled time in `[start, end]` (tiles + dense grid), in order. */
207
+ samples: ActivitySample[];
208
+ tiles: VideoTile[];
209
+ }
210
+
211
+ /** PNG bytes of the three images (plus every sampled frame if requested). */
212
+ export interface ImageBuffers {
213
+ /** One full-resolution frame at `fullAt` (default t=0): layout, text, margins. */
214
+ full: Buffer;
215
+ /** Contact sheet: N labelled frames over one cycle. */
216
+ sheet: Buffer;
217
+ /** Motion heatmap: what moves at all, over a dimmed first frame. */
218
+ heatmap: Buffer;
219
+ /** Every contact-sheet frame (only with `keepFrames`). */
220
+ frames?: Buffer[];
221
+ }
222
+
223
+ export function asRect(values: ArrayLike<number>): Rect {
224
+ return [Number(values[0]), Number(values[1]), Number(values[2]), Number(values[3])];
225
+ }