@vitavision/stage2d 0.6.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.
@@ -0,0 +1,712 @@
1
+ import { CSSProperties, ComponentPropsWithRef, PointerEvent, ReactNode } from "react";
2
+ import { MeasureTone } from "@vitavision/ui";
3
+ //#region src/components/measureGeometry.d.ts
4
+ /**
5
+ * The arithmetic behind `MeasureOverlay`: everything that can be silently wrong, factored
6
+ * out so it can be tested without a DOM.
7
+ *
8
+ * Every primitive `MeasureOverlay` draws is given in **source-image pixel coordinates** —
9
+ * the same frame `ZoomPanCanvas`'s `nativeWidth`/`nativeHeight` describe, and the same one
10
+ * `api/mapValues.ts`'s `u`/`v` fractions index into. Nothing here measures the DOM or knows
11
+ * about zoom directly; `strokeWidthFor` is the one function that turns a *scale factor* a
12
+ * caller already knows (or computes once from a `ZoomPanCanvas` `View`) into a stroke width
13
+ * that reads as constant on screen.
14
+ */
15
+ /** A 2D point — in image pixels unless a signature says otherwise. */
16
+ interface Point {
17
+ /** Horizontal coordinate, increasing rightward. */
18
+ x: number;
19
+ /** Vertical coordinate, increasing downward. */
20
+ y: number;
21
+ }
22
+ /**
23
+ * The on-screen-constant stroke width for a shape drawn in native-pixel units.
24
+ *
25
+ * `MeasureOverlay` is rendered as an SVG whose `viewBox` is the native image size, sitting
26
+ * inside `ZoomPanCanvas`'s own `scale(zoom)` transform. A stroke declared as `1` in that
27
+ * SVG's user units is `1` *native pixel*, which is `strokeScale` screen pixels once both
28
+ * transforms are applied (`strokeScale` = the SVG's own fit ratio × the canvas zoom, or
29
+ * just the zoom when the overlay is already at native resolution). Dividing by it is what
30
+ * keeps a 1px caliper edge looking like 1px at any zoom, rather than growing with it the
31
+ * way a shape's own geometry does.
32
+ *
33
+ * `vector-effect="non-scaling-stroke"` addresses only the SVG's *internal* transforms and
34
+ * is inconsistently applied across browsers once a CSS transform sits above the `<svg>`
35
+ * itself (exactly the situation inside `ZoomPanCanvas`), so this is computed explicitly
36
+ * rather than left to the renderer.
37
+ */
38
+ export declare function strokeWidthFor(strokeScale: number, screenPixels?: number): number;
39
+ /** Rotate `(x, y)` about the origin by `angle` radians. */
40
+ export declare function rotatePoint(x: number, y: number, angle: number): Point;
41
+ /** `M x,y L x,y … Z` through `points`, or `""` for fewer than two of them. */
42
+ export declare function polygonPath(points: readonly Point[]): string;
43
+ /** The two line segments of a cross mark centred on `(x, y)`, each `2·size` long. */
44
+ export declare function crossSegments(x: number, y: number, size: number): [[Point, Point], [Point, Point]];
45
+ /**
46
+ * An SVG arc path centred at `(cx, cy)` with radius `r`, sweeping forward from `startAngle`
47
+ * to `endAngle` (radians, standard `x = cx + r·cos(a)`, `y = cy + r·sin(a)` convention —
48
+ * clockwise on screen, since image-pixel `y` increases downward).
49
+ *
50
+ * A single SVG `A` command cannot express a full circle (its start and end point coincide,
51
+ * which most renderers treat as a zero-length arc), so a sweep that reaches all the way
52
+ * around is split into two half-circle arcs instead.
53
+ */
54
+ export declare function arcPath(cx: number, cy: number, r: number, startAngle: number, endAngle: number): string;
55
+ /**
56
+ * The four corners of a caliper box: a rectangle `width` (along its own measurement axis)
57
+ * by `height`, centred at `(cx, cy)` and rotated by `angle` radians. Corner order is
58
+ * suitable for `polygonPath` — around the box, not crossed.
59
+ */
60
+ export declare function caliperCorners(cx: number, cy: number, width: number, height: number, angle: number): [Point, Point, Point, Point];
61
+ /**
62
+ * The direction arrow for a caliper box: from its centre to just past its `+local-x` edge,
63
+ * along the box's own measurement axis. What the arrow points at is the scan direction the
64
+ * caliper was evaluated in, not merely a decoration on the box.
65
+ */
66
+ export declare function caliperArrow(cx: number, cy: number, width: number, angle: number): {
67
+ from: Point;
68
+ to: Point;
69
+ };
70
+ /**
71
+ * A small open chevron at `tip`, pointing along `angle` (radians), for a caliper's
72
+ * direction arrow. Three points — left-back, tip, right-back — meant for an unfilled
73
+ * `<polyline>`, which keeps the arrowhead's colour exactly the stroke colour of the line it
74
+ * caps without the fill-vs-stroke bookkeeping a filled triangle would need per tone.
75
+ */
76
+ export declare function arrowHeadPoints(tip: Point, angle: number, size: number): [Point, Point, Point];
77
+ /** What `dimensionGeometry` computes: the lines and label placement of a dimension annotation. */
78
+ interface DimensionGeometry {
79
+ /** From the first measured point out to the dimension line. */
80
+ extensionLine1: [Point, Point];
81
+ /** From the second measured point out to the dimension line. */
82
+ extensionLine2: [Point, Point];
83
+ /** The offset line spanning the measured distance, parallel to the measured segment. */
84
+ dimensionLine: [Point, Point];
85
+ /** Midpoint of the dimension line — where the label sits. */
86
+ labelAnchor: Point;
87
+ /** The dimension line's own direction, in degrees, for an upright label rotation. */
88
+ angleDegrees: number;
89
+ }
90
+ /**
91
+ * The leader geometry for a dimension annotation between two measured points, offset by
92
+ * `offset` native pixels to the line's left (so a positive offset with a left-to-right
93
+ * measurement draws the dimension line above it, consistent with `y` increasing downward).
94
+ *
95
+ * Degenerate input (`x1 === x2 && y1 === y2`) falls back to an arbitrary rightward normal
96
+ * rather than dividing by zero, so a caller need not special-case a zero-length dimension.
97
+ */
98
+ export declare function dimensionGeometry(x1: number, y1: number, x2: number, y2: number, offset: number): DimensionGeometry;
99
+ //#endregion
100
+ //#region src/components/stage/view.d.ts
101
+ /** A `translate(tx, ty) scale(scale)` about the stage's top-left corner. */
102
+ interface StageView {
103
+ /** CSS pixels per image pixel. `1` is 100%. */
104
+ scale: number;
105
+ /** Horizontal offset of the image's top-left corner from the viewport's, in CSS pixels. */
106
+ tx: number;
107
+ /** Vertical offset of the image's top-left corner from the viewport's, in CSS pixels. */
108
+ ty: number;
109
+ }
110
+ /** A size: the viewport's in CSS pixels, or the image's in image pixels. */
111
+ interface Box {
112
+ /** Horizontal extent. */
113
+ width: number;
114
+ /** Vertical extent. */
115
+ height: number;
116
+ }
117
+ /** An axis-aligned rectangle in image coordinates, from its top-left corner. */
118
+ interface Rect {
119
+ /** Left edge. */
120
+ x: number;
121
+ /** Top edge. */
122
+ y: number;
123
+ /** Horizontal extent. */
124
+ width: number;
125
+ /** Vertical extent. */
126
+ height: number;
127
+ }
128
+ /**
129
+ * The offset between the two pixel conventions: an image coordinate `i` sits at CSS
130
+ * `i + 0.5` inside a stage laid out at the image's natural size.
131
+ */
132
+ export declare const PIXEL_CENTRE = 0.5;
133
+ /**
134
+ * The `viewBox` for an SVG layer drawn in image coordinates, over a stage of that image.
135
+ *
136
+ * Shifted by half a pixel so a primitive at image coordinate `i` lands on the *centre* of
137
+ * pixel `i` rather than on its left edge. Its extent is unchanged — the box still covers
138
+ * exactly the image — so nothing about sizing or `preserveAspectRatio` changes with it.
139
+ */
140
+ export declare function imageViewBox(image: Box): string;
141
+ /** The most a viewer may magnify: past this the resampler is the subject, not the sensor. */
142
+ export declare const MAX_SCALE = 32;
143
+ /**
144
+ * How far below fit zooming out may go.
145
+ *
146
+ * `ZoomPanCanvas` bottomed out *at* fit, on the reasoning that there is nothing further to
147
+ * see. There is: room around the part, which is what you want when dragging an ROI out to
148
+ * the frame edge or checking that a model's points do not run off the image.
149
+ */
150
+ export declare const MIN_SCALE_VS_FIT = 0.25;
151
+ /** The scale at which the whole image is just visible inside `box`. */
152
+ export declare function fitScale(box: Box, image: Box): number;
153
+ /** Fit, centred — the view a viewer opens at and the one `0` returns to. */
154
+ export declare function fitView(box: Box, image: Box): StageView;
155
+ /** The whole image visible at 1:1 if it fits, otherwise fit — a sane opening view. */
156
+ export declare function initialView(box: Box, image: Box): StageView;
157
+ /** Whether `view` is (indistinguishably) the fit view for this box and image. */
158
+ export declare function isFit(view: StageView, box: Box, image: Box): boolean;
159
+ /** Where the **centre of** image pixel `p` lands in the viewport. */
160
+ export declare function toScreen(view: StageView, p: Point): Point;
161
+ /**
162
+ * Which image coordinate a viewport position is over, in the same pixel-centre convention:
163
+ * the exact centre of the top-left pixel reads `0, 0`, and its top-left corner `-0.5, -0.5`.
164
+ *
165
+ * Unbounded — callers clamp if they care.
166
+ */
167
+ export declare function toImage(view: StageView, p: Point): Point;
168
+ /** Whether an image coordinate is inside the image, in the pixel-centre convention. */
169
+ export declare function insideImage(p: Point, image: Box): boolean;
170
+ /** A length in image pixels that covers `css` screen pixels at this view. */
171
+ export declare function imageLengthFor(view: StageView, css: number): number;
172
+ /**
173
+ * Change the scale while holding whatever is under `anchor` where it is.
174
+ *
175
+ * The one piece of arithmetic here that is silently wrong when centre-anchored instead:
176
+ * magnifying a defect in a corner then costs a drag to undo every wheel notch.
177
+ */
178
+ export declare function zoomAbout(view: StageView, scale: number, anchor: Point): StageView;
179
+ /** The scale range `clampView` and `scaleRange` allow. */
180
+ interface ClampOptions {
181
+ /** Lowest scale, as a multiple of fit. Defaults to `MIN_SCALE_VS_FIT`. */
182
+ minScaleVsFit?: number;
183
+ /** Highest scale, in CSS pixels per image pixel. Defaults to `MAX_SCALE`. */
184
+ maxScale?: number;
185
+ }
186
+ /** The scale range a viewport allows for an image, as `[min, max]`. */
187
+ export declare function scaleRange(box: Box, image: Box, options?: ClampOptions): [number, number];
188
+ /**
189
+ * Keep the view legal: scale inside its range, and the image never dragged off screen.
190
+ *
191
+ * An axis where the scaled image is smaller than the viewport is centred rather than left
192
+ * where a drag put it — free-floating pixels in a grey field is a way to be lost with no
193
+ * visible handle to get back. An axis where it is larger is held so the viewport stays
194
+ * covered.
195
+ */
196
+ export declare function clampView(view: StageView, box: Box, image: Box, options?: ClampOptions): StageView;
197
+ /**
198
+ * The view that puts `rect` (image coordinates) on screen with a margin around it.
199
+ *
200
+ * `pad` is a fraction of the rect's own size, so framing a long thin contour and framing a
201
+ * blob both leave a proportionate border rather than a fixed one that swallows the small
202
+ * one.
203
+ */
204
+ export declare function frameRect(box: Box, image: Box, rect: Rect, pad?: number): StageView;
205
+ /**
206
+ * The same view, after the viewport changed size.
207
+ *
208
+ * The image point at the old centre stays at the new centre, at the same scale — so a
209
+ * window resize moves the frame around the picture instead of moving the picture. A view
210
+ * that was *fit* re-fits instead, because fit is a relationship to the viewport rather than
211
+ * a particular pair of numbers.
212
+ */
213
+ export declare function preserveCenter(view: StageView, from: Box, to: Box, image: Box, options?: ClampOptions): StageView;
214
+ /**
215
+ * The next scale up or down the ladder from `scale`, so the readout lands on a round
216
+ * percentage rather than wherever a multiplier happened to leave it.
217
+ */
218
+ export declare function steppedScale(scale: number, direction: 1 | -1, min: number, max: number): number;
219
+ /** `0.5` → `"50%"`, `1` → `"100%"`, `0.0833` → `"8%"`. */
220
+ export declare function formatScale(scale: number): string;
221
+ //#endregion
222
+ //#region src/components/stage/ImageStage.d.ts
223
+ /** What `useStage` returns: the transform of the enclosing `ImageStage`, and its controls. */
224
+ interface StageContext {
225
+ /** The view in effect — the controlled `view`, or the opening view while that is `null`. */
226
+ view: StageView;
227
+ /** Set a view, clamped to the legal range for the current viewport. */
228
+ setView: (view: StageView) => void;
229
+ /** The source image's pixel dimensions. */
230
+ image: Box;
231
+ /** The viewport's CSS size — `{0, 0}` until first measured. */
232
+ box: Box;
233
+ /** Client coordinates → image pixels. */
234
+ toImage: (client: Point) => Point;
235
+ /** Image pixels → client coordinates. */
236
+ toClient: (image: Point) => Point;
237
+ /** Image pixels → viewport-local CSS pixels. */
238
+ toViewport: (image: Point) => Point;
239
+ /** The image-pixel length that covers `css` screen pixels — for screen-constant geometry. */
240
+ imageLength: (css: number) => number;
241
+ /** Put a rect (image coordinates) on screen with a margin. */
242
+ frame: (rect: Rect, pad?: number) => void;
243
+ /** Fit the whole image. */
244
+ fit: () => void;
245
+ /** Set a scale about the viewport centre, or about `anchor` in client coordinates. */
246
+ zoomTo: (scale: number, anchor?: Point) => void;
247
+ /** Whether the view is (indistinguishably) fit. */
248
+ isFit: boolean;
249
+ /** True while a pan is in progress, so layers can suppress hover work. */
250
+ panning: boolean;
251
+ /**
252
+ * True when panning must win over anything a layer would otherwise do with a press —
253
+ * the hand tool, or space held. Layers check this before claiming a `pointerdown`; it is
254
+ * the only way a modifier can outrank a child, since a child that stops propagation is
255
+ * heard before this component is.
256
+ */
257
+ panMode: boolean;
258
+ }
259
+ /**
260
+ * The stage a layer is drawn into: its view, the coordinate conversions, and the zoom
261
+ * controls.
262
+ *
263
+ * @throws `Error` outside an `ImageStage`, which is always a wiring bug.
264
+ */
265
+ export declare function useStage(): StageContext;
266
+ /** Props of `ImageStage`. */
267
+ interface ImageStageProps {
268
+ /** The source image's pixel dimensions — the stage's own layout size. */
269
+ image: Box;
270
+ /**
271
+ * The view (controlled). `null` opens at a sensible view — 1:1 if the image fits,
272
+ * otherwise fit — reported through `onView` once the viewport is measured. A non-null
273
+ * view is kept on first measure, only clamped to the legal range.
274
+ */
275
+ view: StageView | null;
276
+ /** Called with every view change: gestures, keys, toolbar, and viewport resizes. */
277
+ onView: (view: StageView) => void;
278
+ /** Layers, each `absolute inset-0` and sized by the stage. */
279
+ children: ReactNode;
280
+ /** Rendered floating over the bottom-left, outside the transform. */
281
+ toolbar?: ReactNode;
282
+ /** Rendered floating over the bottom-right, outside the transform. */
283
+ readout?: ReactNode;
284
+ /** Rendered over the top-left — a mode banner, a staleness warning. */
285
+ banner?: ReactNode;
286
+ /** Force panning regardless of where the press lands (a "hand tool"). */
287
+ panTool?: boolean;
288
+ /** Merged onto the viewport with `cn`. */
289
+ className?: string;
290
+ /** Inline style for the viewport. */
291
+ style?: CSSProperties;
292
+ /** Where the pointer is over the image, in image pixels, or `null` when it is outside. */
293
+ onHover?: (point: Point | null) => void;
294
+ /** A press on the background that was not a pan — how a layer hears "deselect". */
295
+ onBackgroundClick?: (event: PointerEvent<HTMLDivElement>) => void;
296
+ /** The legal scale range; see `clampView`. */
297
+ clamp?: ClampOptions;
298
+ /** Keyboard zoom/pan shortcuts. On by default; the stage takes focus to receive them. */
299
+ shortcuts?: boolean;
300
+ /**
301
+ * Whether the arrow keys pan. On by default, and worth turning off in an app where the
302
+ * arrows have a better job — stepping through a list of findings, say. The zoom keys
303
+ * (`+`, `-`, `0`, `1`) are unaffected, and dragging still pans either way.
304
+ */
305
+ panKeys?: boolean;
306
+ /** The viewport's accessible name. Defaults to "Image canvas". */
307
+ label?: string;
308
+ }
309
+ /**
310
+ * A pannable, zoomable viewport over a stack of layers laid out at the image's own pixel
311
+ * size, so an overlay drawn in image coordinates stays registered with the photograph at
312
+ * any zoom and window size. Layers read the transform through `useStage`.
313
+ *
314
+ * State is exposed on the viewport as `data-fit` (the view is fit), `data-panning` (a drag
315
+ * is in progress) and `data-pan-mode` (the hand tool is on or space is held), each present
316
+ * or absent.
317
+ */
318
+ export declare function ImageStage({ image, view, onView, children, toolbar, readout, banner, panTool, className, style, onHover, onBackgroundClick, clamp, shortcuts, panKeys, label }: ImageStageProps): import("react").JSX.Element;
319
+ //#endregion
320
+ //#region src/components/stage/StageToolbar.d.ts
321
+ /** Props of `StageToolbar`. */
322
+ interface StageToolbarProps {
323
+ /** App-specific groups — a tool selector, a layers popover — after a divider. */
324
+ children?: ReactNode;
325
+ /** Merged onto the bar with `cn`. */
326
+ className?: string;
327
+ }
328
+ /**
329
+ * The stage's zoom controls — zoom out, a percentage menu (fit and presets), zoom in, fit,
330
+ * and 100% — plus any app groups passed as children. Pass it as `ImageStage`'s `toolbar`;
331
+ * it reads the stage through `useStage`.
332
+ *
333
+ * The bar carries `data-fit` while the view is fit; the percentage button carries
334
+ * `data-state="open"` or `"closed"` for its menu.
335
+ */
336
+ export declare function StageToolbar({ children, className }: StageToolbarProps): import("react").JSX.Element;
337
+ /** Props of `StageButton`: a `<button>`'s, less the ones it sets itself. */
338
+ interface StageButtonProps extends Omit<ComponentPropsWithRef<"button">, "type" | "title" | "aria-label" | "aria-pressed" | "children"> {
339
+ /** The accessible name, also shown as the tooltip. */
340
+ label: string;
341
+ /** A toggle's state; omit for a plain action button. */
342
+ pressed?: boolean;
343
+ /** The icon (mark it `aria-hidden`). */
344
+ children: ReactNode;
345
+ }
346
+ /**
347
+ * The bar's own button shape, exported so app groups match it exactly. An icon button
348
+ * named by `label`; a toggle when `pressed` is given, exposed as `aria-pressed` and
349
+ * `data-state="on"` or `"off"`. Other button props (and `ref`) are passed through.
350
+ */
351
+ export declare function StageButton({ label, pressed, className, children, ...props }: StageButtonProps): import("react").JSX.Element;
352
+ /** Props of `StageToolbarDivider`. */
353
+ interface StageToolbarDividerProps {
354
+ /** Merged onto the divider with `cn`. */
355
+ className?: string;
356
+ }
357
+ /** A thin vertical rule between groups of `StageButton`s. Decorative (`aria-hidden`). */
358
+ export declare function StageToolbarDivider({ className }: StageToolbarDividerProps): import("react").JSX.Element;
359
+ /** Props of `StageReadout`. */
360
+ interface StageReadoutProps {
361
+ /** The pointer in image pixels (from `ImageStage`'s `onHover`); the image size shows without it. */
362
+ cursor?: {
363
+ x: number;
364
+ y: number;
365
+ } | null;
366
+ /** Appended after a separator — a pixel value, a channel. */
367
+ extra?: ReactNode;
368
+ /** Merged onto the readout with `cn`. */
369
+ className?: string;
370
+ }
371
+ /**
372
+ * The instrument's display line for the canvas: where the cursor is, and how magnified.
373
+ * Pass it as `ImageStage`'s `readout`; it reads the stage through `useStage`.
374
+ *
375
+ * In image pixels, because that is the coordinate every number the backend returns is in —
376
+ * a readout in screen pixels would be a second coordinate system to reconcile by hand.
377
+ */
378
+ export declare function StageReadout({ cursor, extra, className }: StageReadoutProps): import("react").JSX.Element;
379
+ //#endregion
380
+ //#region src/components/ZoomPanCanvas.d.ts
381
+ /**
382
+ * `ZoomPanCanvas`'s view: `translate(x, y) scale(zoom)` about the frame's centre.
383
+ * `ImageStage` uses `StageView` instead.
384
+ */
385
+ interface View {
386
+ /** Magnification relative to fit; `1` is fit-to-window. */
387
+ zoom: number;
388
+ /** Horizontal pan, in CSS pixels, from the centred position. */
389
+ x: number;
390
+ /** Vertical pan, in CSS pixels, from the centred position. */
391
+ y: number;
392
+ }
393
+ /** Zoom 1, centred — which is fit-to-window, given how the canvas is laid out. */
394
+ export declare const RESET_VIEW: View;
395
+ /** The lowest zoom `zoomAt` allows: fit. */
396
+ export declare const MIN_ZOOM = 1;
397
+ /** The highest zoom `zoomAt` allows. */
398
+ export declare const MAX_ZOOM = 12;
399
+ /** The zoom past which a preview tier stops being enough and real pixels are wanted. */
400
+ export declare const FULL_TIER_ZOOM = 2;
401
+ /**
402
+ * Zoom by `factor` about a point, keeping whatever is under that point where it is.
403
+ *
404
+ * Pure, and exported, because it is the one piece of arithmetic here that can be silently
405
+ * wrong: a centre-anchored zoom looks correct until someone tries to magnify a defect in a
406
+ * corner, at which point every wheel notch has to be undone with a drag.
407
+ *
408
+ * The transform is `translate(t) scale(z)` about the box's centre, so a content point `c`
409
+ * lands at `p = c·z + t`. Holding `c` fixed while `z` becomes `z'` gives
410
+ * `t' = p − (p − t)·z'/z`, with `p` measured from the centre.
411
+ */
412
+ export declare function zoomAt(view: View, pointer: {
413
+ x: number;
414
+ y: number;
415
+ }, rect: {
416
+ left: number;
417
+ top: number;
418
+ width: number;
419
+ height: number;
420
+ }, factor: number): View;
421
+ /**
422
+ * Where a pointer is over the *content*, as fractions of the frame, or `null` outside it.
423
+ *
424
+ * The inverse of the transform `zoomAt` maintains, and pure for the same reason: this is
425
+ * what turns a cursor position into an index into a value plane or a source-pixel
426
+ * coordinate, and it is wrong in a way nothing on screen would reveal — a readout that is
427
+ * confidently off by a pan offset looks exactly like a readout that works.
428
+ *
429
+ * The content fills the frame at zoom 1 by construction (the canvas is laid out with the
430
+ * source aspect ratio), so `[0, 1)` over the frame *is* `[0, 1)` over the image, with no
431
+ * letterbox correction to reconstruct.
432
+ */
433
+ export declare function contentUnder(view: View, pointer: {
434
+ clientX: number;
435
+ clientY: number;
436
+ }, rect: {
437
+ left: number;
438
+ top: number;
439
+ width: number;
440
+ height: number;
441
+ }): {
442
+ u: number;
443
+ v: number;
444
+ } | null;
445
+ /**
446
+ * The zoom at which one source pixel covers one CSS pixel.
447
+ *
448
+ * Clamped, so an image smaller than its frame reports 1: there are no further pixels to
449
+ * reveal, and pretending otherwise would magnify the resampler rather than the sensor.
450
+ */
451
+ export declare function nativeZoomFor(sourceWidth: number, boxWidth: number): number;
452
+ /**
453
+ * Props of `ZoomPanCanvas`.
454
+ *
455
+ * @deprecated Use `ImageStage` and `ImageStageProps`.
456
+ */
457
+ interface ZoomPanCanvasProps {
458
+ /** The current view (controlled). */
459
+ view: View;
460
+ /** Called with every view change — wheel, drag, double-click, the "Fit" button. */
461
+ onView: (view: View) => void;
462
+ /** The stacked layers, each filling the frame. */
463
+ children: ReactNode;
464
+ /** Height and any other framing, merged with `cn`; the transform and overflow are handled here. */
465
+ className?: string;
466
+ /** For `aspect-ratio`, which has to be a computed value rather than a utility class. */
467
+ style?: CSSProperties;
468
+ /** Drawn bottom-left over the image, where it cannot push the canvas down. */
469
+ label?: ReactNode;
470
+ /**
471
+ * The source image's pixel width, so double-click can reach true 1:1. Without it the
472
+ * gesture falls back to `FULL_TIER_ZOOM`, which is at least the tier boundary.
473
+ */
474
+ nativeWidth?: number;
475
+ /** Hidden by passing `null` — a caller with its own fit button beside the canvas. */
476
+ fitLabel?: ReactNode;
477
+ /**
478
+ * Where the pointer is over the *content*, as fractions in `[0, 1)`, or `null` when it
479
+ * is outside. Reported through the same transform the layers use, so the coordinate is
480
+ * the one a value plane or a measurement overlay is indexed by however the frame is
481
+ * zoomed or panned. Suppressed while dragging: during a pan the pointer is holding the
482
+ * image, not pointing at a pixel.
483
+ */
484
+ onHover?: (position: {
485
+ u: number;
486
+ v: number;
487
+ } | null) => void;
488
+ }
489
+ /**
490
+ * A pannable, zoomable frame that transforms its stacked children together; zoom 1 is fit.
491
+ *
492
+ * State is exposed as `data-panning` (present during a drag) and `data-fit` (present at
493
+ * zoom 1) on the frame.
494
+ *
495
+ * @deprecated Use `ImageStage`. This component scales its layers by the frame's size (so
496
+ * the frame must be laid out at the image's aspect ratio) and captures every press to pan
497
+ * (so no interactive layer can live inside it). It stays exported, unchanged in behaviour,
498
+ * for consumers that have not migrated.
499
+ */
500
+ export declare function ZoomPanCanvas({ view, onView, children, className, style, label, nativeWidth, fitLabel, onHover }: ZoomPanCanvasProps): import("react").JSX.Element;
501
+ //#endregion
502
+ //#region src/api/mapValues.d.ts
503
+ /**
504
+ * The numbers behind a picture.
505
+ *
506
+ * A rendered anomaly map or false-colour measurement overlay answers "is this region
507
+ * hotter than that one" or "roughly where does the edge fall". The next question — *how
508
+ * hot, in the units a metric is computed in* or *at what subpixel coordinate* — cannot be
509
+ * answered from the picture: a colormap clips at both ends and quantizes to 256 entries,
510
+ * and alpha is a gamma of the normalized value, so the inverse is multi-valued.
511
+ *
512
+ * So the values arrive as values, in a fixed 24-byte-header format that is deliberately
513
+ * **not** `.npy` — there is no dtype string to parse and no shape tuple. This module
514
+ * decodes them and indexes them. **It never draws.** Colour range and colormap stay wherever
515
+ * the values were produced.
516
+ */
517
+ /** A decoded value plane: the numbers behind a rendered map, one `Float32` per pixel and channel. */
518
+ interface ValuePlane {
519
+ /** Columns in the plane (after `stride` decimation). */
520
+ width: number;
521
+ /** Rows in the plane (after `stride` decimation). */
522
+ height: number;
523
+ /**
524
+ * The integer decimation applied upstream. `1` means every source pixel is here;
525
+ * anything more means the readout is sampled, and a caller should say so rather than
526
+ * presenting an approximate number as exact.
527
+ */
528
+ stride: number;
529
+ /**
530
+ * How many planes are in `values`, stored one after another.
531
+ *
532
+ * Read from the header rather than assumed: a mono anomaly map is one plane, an RGB
533
+ * source is three, and nothing here may encode which — channel count is data.
534
+ */
535
+ channels: number;
536
+ /** The samples, plane-major: channel, then row, then column. */
537
+ values: Float32Array;
538
+ }
539
+ /** Thrown by `decodePlane` when a buffer is not a well-formed value plane. */
540
+ export declare class PlaneFormatError extends Error {}
541
+ /**
542
+ * Decode a value plane from its binary form: a 24-byte header (big-endian magic `VAM1`,
543
+ * then little-endian `u32` width, height, stride and channels, and 4 reserved bytes)
544
+ * followed by `width · height · channels` little-endian `f32` values.
545
+ *
546
+ * The returned `values` is a view onto `buffer`, not a copy.
547
+ *
548
+ * @throws `PlaneFormatError` when the header is short, the magic is wrong, or the buffer
549
+ * holds fewer values than the header promises.
550
+ */
551
+ export declare function decodePlane(buffer: ArrayBuffer): ValuePlane;
552
+ /**
553
+ * The value at a normalized position, or `null` outside the plane.
554
+ *
555
+ * `u` and `v` are fractions of the source frame. A stored anomaly map or model-input plane
556
+ * is expected to already be projected into that frame, so crop and letterbox geometry is
557
+ * resolved once upstream rather than reconstructed here. NaN marks an uncovered pixel.
558
+ */
559
+ export declare function valueAt(plane: ValuePlane, u: number, v: number, channel?: number): number | null;
560
+ /** Every channel at one position, in order — one number for mono, three for RGB. */
561
+ export declare function valuesAt(plane: ValuePlane, u: number, v: number): number[];
562
+ /** Where a value sits in a range, as a fraction — `null` for a degenerate range. */
563
+ export declare function fractionOf(value: number, range: {
564
+ low: number;
565
+ high: number;
566
+ } | null | undefined): number | null;
567
+ /**
568
+ * Fetch a value plane from `url` and decode it.
569
+ *
570
+ * @throws `Error` on a non-2xx response, or `PlaneFormatError` for a malformed body.
571
+ */
572
+ export declare function fetchPlane(url: string): Promise<ValuePlane>;
573
+ //#endregion
574
+ //#region src/components/MeasureOverlay.d.ts
575
+ /** A marked location: a dot, or a cross for a subpixel edge. */
576
+ interface PointPrimitive {
577
+ /** Discriminant. */
578
+ kind: "point";
579
+ /** Image x of the point. */
580
+ x: number;
581
+ /** Image y of the point. */
582
+ y: number;
583
+ /** Verdict colour. Defaults to the neutral tone. */
584
+ tone?: MeasureTone;
585
+ /** Native-pixel radius of the dot. Ignored when `cross` is set. */
586
+ radius?: number;
587
+ /** Drawn as a cross instead of a dot — the usual mark for a subpixel edge location. */
588
+ cross?: boolean;
589
+ /** Text drawn just above the mark. */
590
+ label?: string;
591
+ }
592
+ /** A straight line between two image points. */
593
+ interface SegmentPrimitive {
594
+ /** Discriminant. */
595
+ kind: "segment";
596
+ /** Image x of the first end. */
597
+ x1: number;
598
+ /** Image y of the first end. */
599
+ y1: number;
600
+ /** Image x of the second end. */
601
+ x2: number;
602
+ /** Image y of the second end. */
603
+ y2: number;
604
+ /** Verdict colour. Defaults to the neutral tone. */
605
+ tone?: MeasureTone;
606
+ /** A short dash pattern, e.g. for a fitted line shown against its inlier points. */
607
+ dashed?: boolean;
608
+ }
609
+ /** A circle — a fitted bore, a tolerance ring. */
610
+ interface CirclePrimitive {
611
+ /** Discriminant. */
612
+ kind: "circle";
613
+ /** Image x of the centre. */
614
+ cx: number;
615
+ /** Image y of the centre. */
616
+ cy: number;
617
+ /** Radius, in image pixels. */
618
+ r: number;
619
+ /** Verdict colour. Defaults to the neutral tone. */
620
+ tone?: MeasureTone;
621
+ /** Filled rather than stroked — rare, but a small confidence disc wants it. */
622
+ filled?: boolean;
623
+ }
624
+ /** A circular arc, swept forward (clockwise on screen) from `startAngle` to `endAngle`. */
625
+ interface ArcPrimitive {
626
+ /** Discriminant. */
627
+ kind: "arc";
628
+ /** Image x of the centre. */
629
+ cx: number;
630
+ /** Image y of the centre. */
631
+ cy: number;
632
+ /** Radius, in image pixels. */
633
+ r: number;
634
+ /** Radians. `x = cx + r·cos(a)`, `y = cy + r·sin(a)` — clockwise on screen. */
635
+ startAngle: number;
636
+ /** Radians, same convention as `startAngle`. A full turn past it draws a whole circle. */
637
+ endAngle: number;
638
+ /** Verdict colour. Defaults to the neutral tone. */
639
+ tone?: MeasureTone;
640
+ }
641
+ /** A caliper search box: a rotated rectangle with an arrow along its scan direction. */
642
+ interface CaliperPrimitive {
643
+ /** Discriminant. */
644
+ kind: "caliper";
645
+ /** Image x of the box centre. */
646
+ cx: number;
647
+ /** Image y of the box centre. */
648
+ cy: number;
649
+ /** Along the box's own measurement axis. */
650
+ width: number;
651
+ /** Perpendicular to the measurement axis — the search span. */
652
+ height: number;
653
+ /** Radians, the box's own rotation (and its measurement direction). */
654
+ angle: number;
655
+ /** Verdict colour. Defaults to the neutral tone. */
656
+ tone?: MeasureTone;
657
+ /** Draws the direction arrow along the box's +x axis. Defaults to on. */
658
+ showDirection?: boolean;
659
+ /** Text drawn at the box centre. */
660
+ label?: string;
661
+ }
662
+ /** A dimension annotation: extension lines, an offset dimension line, and its value as text. */
663
+ interface DimensionPrimitive {
664
+ /** Discriminant. */
665
+ kind: "dimension";
666
+ /** Image x of the first measured point. */
667
+ x1: number;
668
+ /** Image y of the first measured point. */
669
+ y1: number;
670
+ /** Image x of the second measured point. */
671
+ x2: number;
672
+ /** Image y of the second measured point. */
673
+ y2: number;
674
+ /** The measured value as text, drawn along the dimension line. */
675
+ label: string;
676
+ /** Verdict colour. Defaults to the neutral tone. */
677
+ tone?: MeasureTone;
678
+ /** Native pixels the dimension line sits off the measured span. Defaults to 16. */
679
+ offset?: number;
680
+ }
681
+ /** Anything `MeasureOverlay` can draw, discriminated by `kind`. */
682
+ type MeasurePrimitive = PointPrimitive | SegmentPrimitive | CirclePrimitive | ArcPrimitive | CaliperPrimitive | DimensionPrimitive;
683
+ /** Props of `MeasureOverlay`. */
684
+ interface MeasureOverlayProps {
685
+ /** The source image's pixel width — the overlay's `viewBox`, and every primitive's frame. */
686
+ nativeWidth: number;
687
+ /** The source image's pixel height. */
688
+ nativeHeight: number;
689
+ /** What to draw, in image pixel coordinates, bottom to top. */
690
+ primitives: MeasurePrimitive[];
691
+ /**
692
+ * The combined image-pixel → screen-pixel scale currently in effect, so a stroke or a
693
+ * label declared at "1 screen pixel" stays that size regardless of zoom. Inside an
694
+ * `ImageStage` (which lays the overlay out at exactly `nativeWidth` × `nativeHeight` CSS
695
+ * pixels) this is simply `useStage().view.scale`. See `strokeWidthFor`.
696
+ */
697
+ strokeScale: number;
698
+ /** Merged onto the `<svg>` with `cn`. */
699
+ className?: string;
700
+ }
701
+ /**
702
+ * A vector overlay of measurement primitives — points, segments, circles, arcs, caliper
703
+ * boxes, dimensions — drawn in source-image pixel coordinates.
704
+ *
705
+ * Place it as a layer inside `ImageStage` so it moves with the image. It is a pure function
706
+ * of its props and decorative to assistive technology (`aria-hidden`), so a result drawn
707
+ * only here must also be stated in text.
708
+ */
709
+ export declare function MeasureOverlay({ nativeWidth, nativeHeight, primitives, strokeScale, className }: MeasureOverlayProps): import("react").JSX.Element;
710
+ //#endregion
711
+ export type { ArcPrimitive, Box, CaliperPrimitive, CirclePrimitive, ClampOptions, DimensionGeometry, DimensionPrimitive, ImageStageProps, MeasureOverlayProps, MeasurePrimitive, Point, PointPrimitive, Rect, SegmentPrimitive, StageButtonProps, StageContext, StageReadoutProps, StageToolbarDividerProps, StageToolbarProps, StageView, ValuePlane, View, ZoomPanCanvasProps };
712
+ //# sourceMappingURL=index.d.ts.map