@vitavision/stage2d 0.11.0 → 0.13.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 (41) hide show
  1. package/README.md +3 -6
  2. package/dist/index.d.ts +806 -74
  3. package/dist/index.js +6669 -4568
  4. package/dist/index.js.map +1 -1
  5. package/package.json +2 -2
  6. package/src/components/AreaSet.tsx +87 -56
  7. package/src/components/ContourEditor.tsx +297 -39
  8. package/src/components/DatumEditor.tsx +261 -0
  9. package/src/components/DraftShape.tsx +56 -11
  10. package/src/components/EllipseSet.tsx +3 -3
  11. package/src/components/GridLayer.tsx +1 -2
  12. package/src/components/HeatmapLayer.tsx +1 -1
  13. package/src/components/MaskEditor.tsx +22 -9
  14. package/src/components/MeasureOverlay.tsx +320 -89
  15. package/src/components/PointSet.tsx +18 -10
  16. package/src/components/PolylineSet.tsx +81 -17
  17. package/src/components/RectRoiEditor.tsx +193 -88
  18. package/src/components/ShapeEditor.tsx +14 -4
  19. package/src/components/areaBatching.ts +111 -0
  20. package/src/components/contourArc.ts +268 -0
  21. package/src/components/datumEdit.ts +149 -0
  22. package/src/components/labelLod.ts +2 -3
  23. package/src/components/markerShapes.ts +1 -2
  24. package/src/components/measureGeometry.ts +34 -1
  25. package/src/components/measureHit.ts +371 -0
  26. package/src/components/overlayRole.ts +1 -1
  27. package/src/components/pointIndex.ts +2 -3
  28. package/src/components/polylineIndex.ts +3 -3
  29. package/src/components/shapeEdit.ts +38 -5
  30. package/src/components/stage/CompareLayer.tsx +228 -0
  31. package/src/components/stage/ImageLayer.tsx +56 -15
  32. package/src/components/stage/ImageStage.tsx +231 -128
  33. package/src/components/stage/StageSurface.tsx +44 -18
  34. package/src/components/stage/StageToolbar.tsx +26 -8
  35. package/src/components/stage/compareStyle.ts +155 -0
  36. package/src/components/stage/gesture.ts +5 -0
  37. package/src/components/stage/hitTest.ts +19 -0
  38. package/src/components/stage/useStageHitTest.ts +11 -0
  39. package/src/components/stage/view.ts +33 -6
  40. package/src/components/useShapeDrag.ts +2 -4
  41. package/src/index.ts +34 -2
package/dist/index.d.ts CHANGED
@@ -1,17 +1,6 @@
1
1
  import { CSSProperties, ComponentPropsWithRef, PointerEvent as PointerEvent$1, ReactNode, Ref } from "react";
2
2
  import { MeasureTone } from "@vitavision/ui";
3
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
4
  /** A 2D point — in image pixels unless a signature says otherwise. */
16
5
  interface Point {
17
6
  /** Horizontal coordinate, increasing rightward. */
@@ -40,6 +29,18 @@ export declare function strokeWidthFor(strokeScale: number, screenPixels?: numbe
40
29
  export declare function rotatePoint(x: number, y: number, angle: number): Point;
41
30
  /** `M x,y L x,y … Z` through `points`, or `""` for fewer than two of them. */
42
31
  export declare function polygonPath(points: readonly Point[]): string;
32
+ /**
33
+ * Many unconnected segments as one SVG path: `M x1 y1 L x2 y2` per segment.
34
+ *
35
+ * One path draws thousands of ticks for the cost of one element. A segment with a
36
+ * non-finite coordinate is skipped rather than written, since a single `NaN` in path data
37
+ * stops the browser drawing every segment after it.
38
+ *
39
+ * @param points - `[x1, y1, x2, y2, …]`, four numbers per segment. A trailing partial
40
+ * segment is ignored.
41
+ * @returns The path data; `""` without a whole segment.
42
+ */
43
+ export declare function segmentsPath(points: ArrayLike<number>): string;
43
44
  /** The two line segments of a cross mark centred on `(x, y)`, each `2·size` long. */
44
45
  export declare function crossSegments(x: number, y: number, size: number): [[Point, Point], [Point, Point]];
45
46
  /**
@@ -203,6 +204,11 @@ export declare function toScreen(view: StageView, p: Point): Point;
203
204
  export declare function toImage(view: StageView, p: Point): Point;
204
205
  /** Whether an image coordinate is inside the image, in the pixel-centre convention. */
205
206
  export declare function insideImage(p: Point, image: Box): boolean;
207
+ /**
208
+ * An image coordinate held to the image's extent, `[-0.5, w - 0.5] x [-0.5, h - 0.5]` in the
209
+ * pixel-centre convention: the point on the frame's edge nearest to `p`.
210
+ */
211
+ export declare function clampToImage(p: Point, image: Box): Point;
206
212
  /** A length in image pixels that covers `css` screen pixels at this view. */
207
213
  export declare function imageLengthFor(view: StageView, css: number): number;
208
214
  /**
@@ -214,6 +220,15 @@ export declare function imageLengthFor(view: StageView, css: number): number;
214
220
  export declare function zoomAbout(view: StageView, scale: number, anchor: Point): StageView;
215
221
  /** The scale range `clampView` and `scaleRange` allow. */
216
222
  interface ClampOptions {
223
+ /**
224
+ * How far the image may be panned. `"cover"` (the default): an axis the image overflows
225
+ * keeps the viewport covered, and an axis it does not fill is centred. `"center"`: any
226
+ * image point may be brought to the viewport's centre and no further, on both axes and at
227
+ * every scale — so a zoom about the pointer keeps the pointer's pixel under it while the
228
+ * image is still smaller than the viewport, and an edge or corner can be worked on in the
229
+ * middle of the screen.
230
+ */
231
+ panBounds?: "cover" | "center" | undefined;
217
232
  /** Lowest scale, as a multiple of fit. Defaults to `MIN_SCALE_VS_FIT`. */
218
233
  minScaleVsFit?: number;
219
234
  /** Highest scale, in CSS pixels per image pixel. Defaults to `MAX_SCALE`. */
@@ -224,10 +239,11 @@ export declare function scaleRange(box: Box, image: Box, options?: ClampOptions)
224
239
  /**
225
240
  * Keep the view legal: scale inside its range, and the image never dragged off screen.
226
241
  *
227
- * An axis where the scaled image is smaller than the viewport is centred rather than left
228
- * where a drag put it — free-floating pixels in a grey field is a way to be lost with no
229
- * visible handle to get back. An axis where it is larger is held so the viewport stays
230
- * covered.
242
+ * With the default `panBounds: "cover"`, an axis where the scaled image is smaller than the
243
+ * viewport is centred rather than left where a drag put it — free-floating pixels in a grey
244
+ * field is a way to be lost with no visible handle to get back — and an axis where it is
245
+ * larger is held so the viewport stays covered. With `"center"`, each axis only keeps some
246
+ * image point at or past the viewport's centre.
231
247
  */
232
248
  export declare function clampView(view: StageView, box: Box, image: Box, options?: ClampOptions): StageView;
233
249
  /**
@@ -260,6 +276,20 @@ export declare function formatScale(scale: number): string;
260
276
  type StageMouseButton = "left" | "middle" | "right";
261
277
  //#endregion
262
278
  //#region src/components/stage/ImageStage.d.ts
279
+ /** Why a view was reported through `ImageStage`'s `onView`. */
280
+ interface StageViewChange {
281
+ /**
282
+ * What moved the view:
283
+ * - `"gesture"`: a wheel zoom, a drag or touch pan, a pinch, a double-click.
284
+ * - `"key"`: a keyboard shortcut or pan key.
285
+ * - `"command"`: a call to the handle or the context (`fit`, `zoomTo`, `frame`, `setView`),
286
+ * which includes the toolbar's buttons.
287
+ * - `"measure"`: the opening view, and a resize re-anchoring the view.
288
+ */
289
+ cause: "gesture" | "key" | "command" | "measure";
290
+ /** The measured viewport, in CSS pixels, at the moment of the change. */
291
+ box: Box;
292
+ }
263
293
  /** What `useStage` returns: the transform of the enclosing `ImageStage`, and its controls. */
264
294
  interface StageContext {
265
295
  /** The view in effect — the controlled `view`, or the opening view while that is `null`. */
@@ -278,7 +308,10 @@ interface StageContext {
278
308
  toViewport: (image: Point) => Point;
279
309
  /** The image-pixel length that covers `css` screen pixels — for screen-constant geometry. */
280
310
  imageLength: (css: number) => number;
281
- /** Put a rect (image coordinates) on screen with a margin. */
311
+ /**
312
+ * Put a rect (image coordinates) on screen with a margin: `pad` is a fraction of the rect's
313
+ * own width and height added on each side (default 0.15).
314
+ */
282
315
  frame: (rect: Rect, pad?: number) => void;
283
316
  /** Fit the whole image. */
284
317
  fit: () => void;
@@ -302,7 +335,10 @@ interface StageContext {
302
335
  * measured. Layers inside the stage use `useStage` instead.
303
336
  */
304
337
  interface StageHandle {
305
- /** Put a rect (image coordinates) on screen with a margin (CSS pixels, default 24). */
338
+ /**
339
+ * Put a rect (image coordinates) on screen with a margin: `pad` is a fraction of the rect's
340
+ * own width and height added on each side (default 0.15).
341
+ */
306
342
  frame: (rect: Rect, pad?: number) => void;
307
343
  /** Fit the whole image. */
308
344
  fit: () => void;
@@ -326,8 +362,13 @@ interface ImageStageProps {
326
362
  * view is kept on first measure, only clamped to the legal range.
327
363
  */
328
364
  view: StageView | null;
329
- /** Called with every view change: gestures, keys, toolbar, and viewport resizes. */
330
- onView: (view: StageView) => void;
365
+ /**
366
+ * Called with every view change: gestures, keys, toolbar, and viewport resizes. The second
367
+ * argument says why and carries the measured viewport; a one-argument callback ignores it.
368
+ * A `null` `view` that the stage has already measured is re-opened and reported again, with
369
+ * cause `"measure"`.
370
+ */
371
+ onView: (view: StageView, change: StageViewChange) => void;
331
372
  /** Layers, each `absolute inset-0` and sized by the stage. */
332
373
  children: ReactNode;
333
374
  /** Rendered floating over the bottom-left, outside the transform. */
@@ -347,7 +388,8 @@ interface ImageStageProps {
347
388
  panButton?: StageMouseButton | readonly StageMouseButton[] | undefined;
348
389
  /**
349
390
  * Whether a double-click toggles fit and the previous view. On by default; turn it off in
350
- * an app whose tools use double-click, such as closing a polygon.
391
+ * an app whose tools use double-click, such as closing a polygon. A double-click a layer
392
+ * takes through the hit-test (an editable `ContourEditor` inserting a vertex) never toggles.
351
393
  */
352
394
  doubleClickFit?: boolean | undefined;
353
395
  /**
@@ -364,12 +406,23 @@ interface ImageStageProps {
364
406
  style?: CSSProperties;
365
407
  /** Where the pointer is over the image, in image pixels, or `null` when it is outside. */
366
408
  onHover?: (point: Point | null) => void;
367
- /** A press on the background that was not a pan — how a layer hears "deselect". */
368
- onBackgroundClick?: (event: PointerEvent$1<HTMLDivElement>) => void;
409
+ /**
410
+ * A press on the background that was not a pan — how a layer hears "deselect". `point` is
411
+ * where it landed, in image coordinates (the pixel-centre convention, unclamped).
412
+ */
413
+ onBackgroundClick?: (event: PointerEvent$1<HTMLDivElement>, point: Point) => void;
369
414
  /** The legal scale range; see `clampView`. */
370
415
  clamp?: ClampOptions;
371
416
  /** Keyboard zoom/pan shortcuts. On by default; the stage takes focus to receive them. */
372
417
  shortcuts?: boolean;
418
+ /**
419
+ * Whether the viewport is a tab stop (`tabIndex={0}`, `role="application"`). Defaults to
420
+ * `shortcuts`. Off, the viewport is a plain `role="group"` that takes no focus, for an app that
421
+ * owns the keyboard on an element around the stage and would otherwise have two nested tab
422
+ * stops. With `shortcuts` on and `focusable` off the keys still work while focus is on an
423
+ * element inside the stage, such as an editor's handle.
424
+ */
425
+ focusable?: boolean | undefined;
373
426
  /**
374
427
  * Whether the arrow keys pan. On by default, and worth turning off in an app where the
375
428
  * arrows have a better job — stepping through a list of findings, say. The zoom keys
@@ -406,8 +459,11 @@ interface ImageStageProps {
406
459
  * State is exposed on the viewport as `data-fit` (the view is fit), `data-panning` (a drag
407
460
  * is in progress) and `data-pan-mode` (the hand tool is on or space is held), each present
408
461
  * or absent.
462
+ *
463
+ * The viewport is a `role="application"` tab stop named by `label`. With `focusable` off (the
464
+ * default when `shortcuts` is off) it is a `role="group"` and takes no focus.
409
465
  */
410
- export declare function ImageStage({ image, view, onView, children, toolbar, readout, banner, panTool, panButton, doubleClickFit, touchPan, className, style, onHover, onBackgroundClick, clamp, shortcuts, panKeys, label, initialView: opening, fit: fitOptions, ref }: ImageStageProps): import("react").JSX.Element;
466
+ export declare function ImageStage({ image, view, onView, children, toolbar, readout, banner, panTool, panButton, doubleClickFit, touchPan, className, style, onHover, onBackgroundClick, clamp, shortcuts, focusable, panKeys, label, initialView: opening, fit: fitOptions, ref }: ImageStageProps): import("react").JSX.Element;
411
467
  //#endregion
412
468
  //#region src/components/stage/hitTest.d.ts
413
469
  /** What a layer is picked as, and so how it ranks against the layers around it. */
@@ -498,6 +554,12 @@ interface StageHitLayerOptions {
498
554
  * decline one. For a touch tap this is the `pointerup`.
499
555
  */
500
556
  onPress?: ((id: HitId, event: StagePointerEvent) => boolean | void) | undefined;
557
+ /**
558
+ * A double-click landed on an item, at `point` in image coordinates, and nothing above it
559
+ * claimed it. The stage offers a double-click to its layers before its own double-click to
560
+ * fit, so a layer that handles one keeps the view where it is. Return `false` to decline it.
561
+ */
562
+ onDoubleClick?: ((id: HitId, point: Point) => boolean | void) | undefined;
501
563
  }
502
564
  /**
503
565
  * Register a layer with the stage's hit-test. The callbacks may change every render; the
@@ -509,6 +571,67 @@ interface StageHitLayerOptions {
509
571
  */
510
572
  export declare function useStageHitLayer(options: StageHitLayerOptions): string;
511
573
  //#endregion
574
+ //#region src/components/stage/compareStyle.d.ts
575
+ /** How two images are compared. */
576
+ type CompareMode = "checker" | "wipe" | "difference";
577
+ /** Which way the wipe's divider runs: `vertical` splits left from right, `horizontal` top from bottom. */
578
+ type CompareOrientation = "vertical" | "horizontal";
579
+ //#endregion
580
+ //#region src/components/stage/CompareLayer.d.ts
581
+ /** Props of `CompareLayer`. */
582
+ interface CompareLayerProps {
583
+ /** Image A's URL: the reference. It is the stage's size. */
584
+ a: string;
585
+ /** Image B's URL: compared with A. The same size as A. */
586
+ b: string;
587
+ /**
588
+ * How they are compared.
589
+ * - `checker`: alternate squares of A and B, `cell` image pixels across, A at the top-left.
590
+ * - `wipe`: A before the divider and B after it; drag the divider, or focus it and use the keys.
591
+ * - `difference`: the per-channel difference of the two, brightened by `gain`. Identical pixels
592
+ * are black. It is computed on the sRGB-encoded values the browser composites, not on linear
593
+ * light, so treat it as a picture of where the images differ, not as a measurement.
594
+ */
595
+ mode: CompareMode;
596
+ /** The wipe's divider, as the fraction of the image before it (0 to 1), when the app controls it. */
597
+ split?: number | undefined;
598
+ /** The divider's starting place when the layer controls it. Defaults to 0.5. */
599
+ defaultSplit?: number | undefined;
600
+ /** Called as the divider is dragged or moved by a key, with the new fraction. */
601
+ onSplitChange?: ((split: number) => void) | undefined;
602
+ /** `vertical` (the default) puts A left of the divider; `horizontal` puts A above it. */
603
+ orientation?: CompareOrientation | undefined;
604
+ /** The checkerboard's square, in image pixels. Defaults to 32. */
605
+ cell?: number | undefined;
606
+ /** How much the difference is brightened: 1 shows it as it is, 4 makes a small one visible. Defaults to 1. */
607
+ gain?: number | undefined;
608
+ /** What the comparison shows, for assistive technology. */
609
+ alt: string;
610
+ /** The two images' names, for the divider's value and its tags. Defaults to `["A", "B"]`. */
611
+ labels?: readonly [string, string] | undefined;
612
+ /** The zoom (CSS pixels per image pixel) from which pixels are drawn as blocks. Defaults to 4. */
613
+ pixelatedAbove?: number | undefined;
614
+ /** Merged onto the layer's wrapper with `cn`. */
615
+ className?: string | undefined;
616
+ }
617
+ /**
618
+ * Two same-size images compared inside an `ImageStage`: as a checkerboard, a wipe or their
619
+ * difference (`mode`).
620
+ *
621
+ * - **Wipe.** The divider is a line one and a half screen pixels wide with a knob kept in the
622
+ * middle of the part of it on screen. Drag the line or the knob; the press is claimed, so the
623
+ * stage does not pan from it.
624
+ * - **Keyboard.** The knob is a slider (0 to 100, the share of A): arrow keys move it 1 % (10 %
625
+ * with Shift), Page Up and Page Down 10 %, Home and End to either edge. The keys do not reach
626
+ * the stage, so they do not pan it.
627
+ * - **Pixels.** Past `pixelatedAbove` both images are drawn as blocks, as `ImageLayer` does.
628
+ *
629
+ * The images are one picture to assistive technology (`role="img"`, named by `alt`); the knob is
630
+ * outside it, so it stays reachable. The wrapper carries `data-mode`, and `data-pixelated` while
631
+ * pixelated; the knob carries `data-dragging` during a drag.
632
+ */
633
+ export declare function CompareLayer({ a, b, mode, split, defaultSplit, onSplitChange, orientation, cell, gain, alt, labels, pixelatedAbove, className }: CompareLayerProps): import("react").JSX.Element;
634
+ //#endregion
512
635
  //#region src/components/stage/ImageLayer.d.ts
513
636
  /**
514
637
  * The photograph, as a stage layer.
@@ -522,7 +645,8 @@ export declare function useStageHitLayer(options: StageHitLayerOptions): string;
522
645
  * until it would be magnified — until the screen shows more pixels than it has. Past that
523
646
  * point the full image is requested, and it stays once loaded, so zooming back out does
524
647
  * not swap back. The preview stays underneath while the full image loads, so the frame
525
- * never goes blank.
648
+ * never goes blank. When the full image is costly to produce, the app can leave its URL
649
+ * out and supply it when `onFullNeeded` says the same rule has tripped.
526
650
  * - **Pixelated past a zoom.** Above about 4× the browser's smoothing paints detail the
527
651
  * sensor never recorded; on a metrology bench the sensor's own samples are what is worth
528
652
  * looking at.
@@ -534,16 +658,19 @@ interface ImageTier {
534
658
  /** Its width in pixels. The full image's width is the stage's own. */
535
659
  width: number;
536
660
  }
537
- /** Props of `ImageLayer`. */
538
- interface ImageLayerProps {
539
- /** The full-resolution image's URL. */
540
- src: string;
541
- /** A smaller tier to show first; without one, `src` is shown from the start. */
542
- preview?: ImageTier | undefined;
661
+ /** What every `ImageLayer` takes, whichever tiers it is given. */
662
+ interface ImageLayerBaseProps {
543
663
  /** The image's description, for assistive technology. `""` marks it decorative. */
544
664
  alt: string;
545
665
  /** The zoom (CSS pixels per image pixel) from which pixels are drawn as blocks. Defaults to 4. */
546
666
  pixelatedAbove?: number | undefined;
667
+ /**
668
+ * Called once per `preview.src` when the full image is first wanted: the stage would magnify
669
+ * the preview. An app whose full image is costly to make or fetch leaves `src` out and
670
+ * passes it from here; the full image is shown as soon as `src` arrives. Not called without
671
+ * a `preview`.
672
+ */
673
+ onFullNeeded?: (() => void) | undefined;
547
674
  /** Called when the full image has loaded. */
548
675
  onLoad?: (() => void) | undefined;
549
676
  /** Called when the full image fails to load. */
@@ -551,15 +678,34 @@ interface ImageLayerProps {
551
678
  /** Merged onto both images with `cn`. */
552
679
  className?: string | undefined;
553
680
  }
681
+ /**
682
+ * Props of `ImageLayer`: the full image's `src`, a `preview` tier, or both. With a `preview`,
683
+ * `src` may be left out until `onFullNeeded` asks for it.
684
+ */
685
+ type ImageLayerProps = ImageLayerBaseProps & ({
686
+ /** The full-resolution image's URL. */
687
+ src: string;
688
+ /** A smaller tier to show first; without one, `src` is shown from the start. */
689
+ preview?: ImageTier | undefined;
690
+ } | {
691
+ /** The full-resolution image's URL, once known. Until then the preview stands in. */
692
+ src?: string | undefined;
693
+ /** A smaller tier to show first. */
694
+ preview: ImageTier;
695
+ });
554
696
  /**
555
697
  * The photograph at its natural size inside an `ImageStage`, with an optional preview tier
556
698
  * and pixelated rendering past `pixelatedAbove`. It takes no pointer events, so presses reach
557
699
  * the stage and the layers above.
558
700
  *
701
+ * With a `preview`, the full image is wanted once the stage would magnify the preview, and
702
+ * `onFullNeeded` says so; `src` can be supplied then rather than up front.
703
+ *
559
704
  * Each image carries `data-tier` (`preview` or `full`); the full image carries `data-loaded`
560
- * once it has loaded, and both carry `data-pixelated` while pixelated.
705
+ * once it has loaded, the preview carries `data-wants-full` from the moment the full image is
706
+ * wanted until it has loaded, and both carry `data-pixelated` while pixelated.
561
707
  */
562
- export declare function ImageLayer({ src, preview, alt, pixelatedAbove, onLoad, onError, className }: ImageLayerProps): import("react").JSX.Element;
708
+ export declare function ImageLayer({ src, preview, alt, pixelatedAbove, onFullNeeded, onLoad, onError, className }: ImageLayerProps): import("react").JSX.Element;
563
709
  //#endregion
564
710
  //#region src/components/stage/StageSurface.d.ts
565
711
  /** What a drag does as the pointer moves and when it is released, in image coordinates. */
@@ -628,6 +774,15 @@ interface StageSurfaceProps {
628
774
  * stage's double-click-to-fit does not run; leave it out to keep the fit.
629
775
  */
630
776
  onDoubleClick?: ((point: Point) => void) | undefined;
777
+ /**
778
+ * How far the surface reaches. `"image"` (the default) is the image rectangle: a press in
779
+ * the margin around the image goes to the stage, which pans. `"viewport"` covers everything
780
+ * visible, margin included, so a drawing tool can place a point on the image's border by
781
+ * pressing just outside it; every point the surface then reports (the press, a drag's moves
782
+ * and release, hover, double-click) is clamped to the image's extent, `[-0.5, w - 0.5]` by
783
+ * `[-0.5, h - 0.5]`. `StagePress.client` stays the raw pointer position.
784
+ */
785
+ extent?: "image" | "viewport" | undefined;
631
786
  }
632
787
  /**
633
788
  * The stage's one full-frame press target. Put it inside an `ImageStage`, below the layers
@@ -646,9 +801,12 @@ interface StageSurfaceProps {
646
801
  *
647
802
  * A touch gesture that sets `claimsTouch: true` is claimed like a mouse press.
648
803
  *
804
+ * With `extent="viewport"` the surface also takes presses in the margin around the image, and
805
+ * clamps every reported point to the image.
806
+ *
649
807
  * The surface draws nothing. It carries `data-dragging` while a gesture it started is in flight.
650
808
  */
651
- export declare function StageSurface({ onPress, cursor, onHover, onDoubleClick }: StageSurfaceProps): import("react").JSX.Element;
809
+ export declare function StageSurface({ onPress, cursor, onHover, onDoubleClick, extent }: StageSurfaceProps): import("react").JSX.Element;
652
810
  //#endregion
653
811
  //#region src/components/stage/StageToolbar.d.ts
654
812
  /** Props of `StageToolbar`. */
@@ -700,8 +858,16 @@ export declare function StageButton({ label, pressed, hint, shortcut, className,
700
858
  interface StageLayer {
701
859
  /** Its identity, passed back to `onVisibleChange`. */
702
860
  id: string;
703
- /** Its name in the menu. */
704
- label: string;
861
+ /**
862
+ * Its name in the menu: text, or richer content such as a name and a count. It names the
863
+ * menu item for assistive technology, so keep its text meaningful.
864
+ */
865
+ label: ReactNode;
866
+ /**
867
+ * A CSS colour shown as a small dot before the label, matching the layer's colour on the
868
+ * canvas. Decorative (`aria-hidden`), so the label must name the layer on its own.
869
+ */
870
+ swatch?: string | undefined;
705
871
  /** Whether it is shown. */
706
872
  visible: boolean;
707
873
  /** Shown but not switchable, e.g. a layer that has nothing to draw yet. */
@@ -715,16 +881,18 @@ interface StageLayersMenuProps {
715
881
  layers: readonly StageLayer[];
716
882
  /** Called with a layer's id and its new visibility. */
717
883
  onVisibleChange: (id: string, visible: boolean) => void;
718
- /** The trigger's accessible name and the menu's heading. Defaults to "Layers". */
884
+ /** The trigger's accessible name and tooltip. Defaults to "Layers". */
719
885
  label?: string | undefined;
886
+ /** The heading over the menu's items. Defaults to `label`. */
887
+ heading?: ReactNode;
720
888
  }
721
889
  /**
722
890
  * A `StageButton`-shaped trigger opening a menu of layer toggles, for `StageToolbar`'s
723
- * children. Each layer is a `menuitemcheckbox`; toggling one keeps the menu open for the
724
- * next. The trigger shows as pressed while any layer is hidden, so a canvas missing a layer
725
- * says so before the menu is opened.
891
+ * children. Each layer is a `menuitemcheckbox`, with its `swatch` as a dot before its label;
892
+ * toggling one keeps the menu open for the next. The trigger shows as pressed while any layer
893
+ * is hidden, so a canvas missing a layer says so before the menu is opened.
726
894
  */
727
- export declare function StageLayersMenu({ layers, onVisibleChange, label }: StageLayersMenuProps): import("react").JSX.Element;
895
+ export declare function StageLayersMenu({ layers, onVisibleChange, label, heading }: StageLayersMenuProps): import("react").JSX.Element;
728
896
  /** Props of `StageToolbarDivider`. */
729
897
  interface StageToolbarDividerProps {
730
898
  /** Merged onto the divider with `cn`. */
@@ -949,7 +1117,7 @@ export declare function fetchPlane(url: string): Promise<ValuePlane>;
949
1117
  //#endregion
950
1118
  //#region src/components/overlayRole.d.ts
951
1119
  /**
952
- * The overlay grammar's roles and states (docs/visual-language.md §5), for layers that paint
1120
+ * The overlay grammar's roles and states for layers that paint
953
1121
  * through SVG attributes rather than class names.
954
1122
  */
955
1123
  /**
@@ -1121,8 +1289,31 @@ interface PolylinePrimitive extends PrimitiveCommon {
1121
1289
  /** Text drawn just above the first point. */
1122
1290
  label?: string;
1123
1291
  }
1124
- /** Anything `MeasureOverlay` can draw, discriminated by `kind`. */
1125
- type MeasurePrimitive = PointPrimitive | SegmentPrimitive | CirclePrimitive | ArcPrimitive | CaliperPrimitive | DimensionPrimitive | PolylinePrimitive;
1292
+ /**
1293
+ * Many unconnected segments drawn as one element, e.g. the tick marks of a shape model whose
1294
+ * points are stored in no particular order, so that a `polyline` cannot join them. Thousands
1295
+ * of segments cost one path, not one element each.
1296
+ */
1297
+ interface SegmentsPrimitive extends PrimitiveCommon {
1298
+ /** Discriminant. */
1299
+ kind: "segments";
1300
+ /**
1301
+ * `[x1, y1, x2, y2, …]` in image coordinates: four numbers per segment. A trailing partial
1302
+ * segment is ignored, and a segment with a non-finite coordinate is skipped.
1303
+ */
1304
+ points: number[];
1305
+ /** Verdict colour. Defaults to the neutral tone. */
1306
+ tone?: MeasureTone;
1307
+ /** A short dash pattern. */
1308
+ dashed?: boolean;
1309
+ /** Text drawn just above the first segment's start. */
1310
+ label?: string;
1311
+ }
1312
+ /**
1313
+ * Anything `MeasureOverlay` can draw, discriminated by `kind`. Kinds are added in minor
1314
+ * releases, so code that switches over `kind` should keep a default case.
1315
+ */
1316
+ type MeasurePrimitive = PointPrimitive | SegmentPrimitive | SegmentsPrimitive | CirclePrimitive | ArcPrimitive | CaliperPrimitive | DimensionPrimitive | PolylinePrimitive;
1126
1317
  /** Props of `MeasureOverlay`. */
1127
1318
  interface MeasureOverlayProps {
1128
1319
  /** The source image's pixel width — the overlay's `viewBox`, and every primitive's frame. */
@@ -1138,6 +1329,40 @@ interface MeasureOverlayProps {
1138
1329
  * pixels) this is simply `useStage().view.scale`. See `strokeWidthFor`.
1139
1330
  */
1140
1331
  strokeScale: number;
1332
+ /**
1333
+ * Which primitives get a halo: a dark band under the mark (2 screen px wider, at 60 %
1334
+ * opacity) and behind its label's glyphs (3 screen px), so it holds on a bright part of the
1335
+ * image as well as a dark one.
1336
+ * - `"role"` (the default): primitives that carry a `role`.
1337
+ * - `"all"`: every primitive, verdict tones included.
1338
+ * - `"none"`: none.
1339
+ */
1340
+ halo?: "role" | "all" | "none" | undefined;
1341
+ /**
1342
+ * The hovered primitive's `id`, when the app controls hover (a table beside the stage hovers
1343
+ * rows too). That primitive is drawn in the hover state unless it is selected. Without it, a
1344
+ * pickable overlay tracks the pointer's hover itself.
1345
+ */
1346
+ hoveredId?: string | null | undefined;
1347
+ /**
1348
+ * Called when the primitive under the pointer changes: its `id`, or `null` when the pointer
1349
+ * leaves every primitive. Only primitives with an `id` are picked.
1350
+ *
1351
+ * Setting this or `onItemPress` makes the overlay pickable: it answers the stage's hit-test,
1352
+ * so it must then sit inside an `ImageStage`. Its SVG still takes no pointer events.
1353
+ */
1354
+ onHoverChange?: ((id: string | null) => void) | undefined;
1355
+ /**
1356
+ * A press landed on a primitive with an `id`: the nearest within the pointer's tolerance, the
1357
+ * later one on a tie. The press is claimed, so the stage does not pan from it. Return `false`
1358
+ * to decline it: the press then goes to the next layer under the pointer, or to the stage.
1359
+ * The event is the `pointerdown` (the `pointerup` for a touch tap).
1360
+ */
1361
+ onItemPress?: ((id: string, event: StagePointerEvent) => boolean | void) | undefined;
1362
+ /** The id hit-tests report for this layer. Defaults to a generated one. */
1363
+ layerId?: string | undefined;
1364
+ /** Rank against other layers in hit-tests. Defaults to `STAGE_HIT_PRIORITY.line`. */
1365
+ priority?: number | undefined;
1141
1366
  /** Merged onto the `<svg>` with `cn`. */
1142
1367
  className?: string;
1143
1368
  }
@@ -1151,10 +1376,57 @@ interface MeasureOverlayProps {
1151
1376
  *
1152
1377
  * A primitive's colour is its `role` (overlay grammar) if given, else its verdict `tone`.
1153
1378
  * Its `state` follows the overlay grammar: `hover` thickens it, `selected` thickens it and
1154
- * rings it in the selection colour, and `dimmed` fades it. Each primitive is a `<g>` carrying
1155
- * `data-kind`, plus `data-id` and `data-state` when given.
1379
+ * rings it in the selection colour, and `dimmed` fades it. A primitive with a `role` is drawn
1380
+ * over a halo, and so is its label; `halo` widens or drops that.
1381
+ *
1382
+ * **Picking.** With `onHoverChange` or `onItemPress` the overlay answers the stage's hit-test
1383
+ * (`useStageHitTest` finds its primitives too): the pointer picks the nearest primitive with
1384
+ * an `id`, a dot, a filled circle and a caliper box by their inside, every other kind by its
1385
+ * strokes. The hovered one is drawn in the hover state.
1386
+ *
1387
+ * Each primitive is a `<g>` carrying `data-kind`, plus `data-id` and `data-state` (`hover`
1388
+ * while hovered) when given; its halo is the `<g data-halo>` inside it. The SVG carries
1389
+ * `data-hovered` (the hovered id).
1156
1390
  */
1157
- export declare function MeasureOverlay({ nativeWidth, nativeHeight, primitives, strokeScale, className }: MeasureOverlayProps): import("react").JSX.Element;
1391
+ export declare function MeasureOverlay({ nativeWidth, nativeHeight, primitives, strokeScale, halo, hoveredId, onHoverChange, onItemPress, layerId, priority, className }: MeasureOverlayProps): import("react").JSX.Element;
1392
+ //#endregion
1393
+ //#region src/components/measureHit.d.ts
1394
+ /**
1395
+ * How far a point is from a primitive as drawn, in image pixels.
1396
+ *
1397
+ * - A dot, a filled circle and a caliper box are areas: the distance is 0 anywhere inside.
1398
+ * - Every other kind is a line: the distance to its nearest stroke (a cross's arms, a
1399
+ * circle's or an arc's rim, a dimension's three lines, a caliper's direction arrow).
1400
+ * - Labels are not part of a primitive's shape.
1401
+ *
1402
+ * @param primitive - The primitive.
1403
+ * @param point - The point, in image coordinates.
1404
+ * @param strokeScale - The image-to-screen scale the overlay is drawn at, which sizes a dot,
1405
+ * a cross and an arrow head.
1406
+ * @returns The distance; `Infinity` for a primitive that draws nothing (a zero sweep, an empty
1407
+ * polyline, a kind this version does not know).
1408
+ */
1409
+ export declare function measurePrimitiveDistance(primitive: MeasurePrimitive, point: Point, strokeScale: number): number;
1410
+ /**
1411
+ * The primitive nearest to `point` within `radius`, among those with an `id`.
1412
+ *
1413
+ * The primitives are gridded by bounding box once per `primitives` array, and the grid is
1414
+ * kept while that array lives, so a hover over thousands of primitives measures only those
1415
+ * near the pointer. Pass a new array when the primitives change (as React state does): one
1416
+ * edited in place keeps its old grid.
1417
+ *
1418
+ * @param primitives - The primitives, bottom to top, as `MeasureOverlay` draws them.
1419
+ * @param point - The point, in image coordinates.
1420
+ * @param radius - The search radius, in image pixels.
1421
+ * @param strokeScale - The image-to-screen scale the overlay is drawn at.
1422
+ * @returns The nearest primitive's id and distance, or `null`. A tie goes to the later
1423
+ * primitive, which is drawn on top. A primitive with a NaN coordinate is never picked,
1424
+ * except a `segments` one, whose bad segments are skipped as they are when drawn.
1425
+ */
1426
+ export declare function nearestMeasurePrimitive(primitives: readonly MeasurePrimitive[], point: Point, radius: number, strokeScale: number): {
1427
+ id: string;
1428
+ distance: number;
1429
+ } | null;
1158
1430
  //#endregion
1159
1431
  //#region src/components/stage/useScreenPx.d.ts
1160
1432
  /**
@@ -1170,10 +1442,16 @@ export declare function MeasureOverlay({ nativeWidth, nativeHeight, primitives,
1170
1442
  export declare function useScreenPx(): (css: number) => number;
1171
1443
  //#endregion
1172
1444
  //#region src/components/ContourEditor.d.ts
1173
- /** An ordered, closed contour drawn in source-image pixel-center coordinates. */
1445
+ /** An ordered contour, closed or open, drawn in source-image pixel-center coordinates. */
1174
1446
  interface ContourEditorProps {
1175
- /** Ordered vertices; the final vertex connects back to the first. */
1447
+ /** Ordered vertices; on a closed contour the final vertex connects back to the first. */
1176
1448
  points: Point[];
1449
+ /**
1450
+ * Whether the last vertex joins the first. Defaults to `true`, a closed polygon; `false`
1451
+ * draws an open polyline (a centreline, an edge piece), which keeps at least two vertices
1452
+ * where a closed contour keeps three.
1453
+ */
1454
+ closed?: boolean | undefined;
1177
1455
  /** Receives a complete replacement point list after each edit. */
1178
1456
  onChange: (points: Point[]) => void;
1179
1457
  /** Called at the end of a pointer or keyboard edit; useful for history snapshots. */
@@ -1184,13 +1462,197 @@ interface ContourEditorProps {
1184
1462
  label?: string;
1185
1463
  /** CSS stroke color. */
1186
1464
  stroke?: string;
1187
- }
1188
- /** Return the index of the closest segment, with the last vertex joined to the first. */
1189
- export declare function nearestContourSegment(points: Point[], point: Point): number;
1190
- /** Edit contour vertices over an ImageStage using its shared source-image transform. */
1191
- export declare function ContourEditor({ points, onChange, onCommit, editable, label, stroke }: ContourEditorProps): import("react").JSX.Element;
1465
+ /**
1466
+ * The area, in image coordinates, every vertex is kept inside: a drag, a keyboard nudge and
1467
+ * an inserted vertex are clamped to it. Defaults to the pixel centres,
1468
+ * `{ x: 0, y: 0, width: w - 1, height: h - 1 }`. Pass `{ x: -0.5, y: -0.5, width: w, height: h }`
1469
+ * for polygons in the area convention, which may lie exactly on the image border.
1470
+ */
1471
+ bounds?: Rect | undefined;
1472
+ /** The id hit-tests report for this contour, whose items are segment indices. Defaults to a generated one. */
1473
+ layerId?: string | undefined;
1474
+ /** Rank against other layers in hit-tests. Defaults to `STAGE_HIT_PRIORITY.line`. */
1475
+ priority?: number | undefined;
1476
+ /**
1477
+ * What a press does while `editable`:
1478
+ * - `"vertex"` (the default): vertices are dragged, nudged, inserted and deleted.
1479
+ * - `"brush"`: a drag pushes the contour with a soft round brush of `brushRadius`, centred
1480
+ * where the press landed; `onChange` follows the drag and `onCommit` ends it.
1481
+ * - `"erase"`: a drag along the contour marks a stretch of it, and the release reports what
1482
+ * is left through `onErase`.
1483
+ *
1484
+ * In `"brush"` and `"erase"` the editor covers the image with its own press target
1485
+ * (`data-tool-surface`) and shows the brush's footprint under the pointer; a press whose
1486
+ * brush does not reach the contour is declined, so the stage pans.
1487
+ */
1488
+ mode?: "vertex" | "brush" | "erase" | undefined;
1489
+ /** The brush's radius in `"brush"` and `"erase"` mode, in image pixels. Defaults to 20. */
1490
+ brushRadius?: number | undefined;
1491
+ /**
1492
+ * Called when an erase drag is released, with the pieces of the contour that are left (each
1493
+ * an open polyline, see `eraseArc`) and the erased stretch as arc lengths: from `start`
1494
+ * forward to `end`, past the first vertex of a closed contour when `start > end`. The editor
1495
+ * does not change `points` itself. Erasing a stretch of a closed contour leaves **one open
1496
+ * piece**: to keep editing it, pass it back as `points` with `closed={false}`.
1497
+ */
1498
+ onErase?: ((pieces: Point[][], range: {
1499
+ start: number;
1500
+ end: number;
1501
+ }) => void) | undefined;
1502
+ }
1503
+ /**
1504
+ * The index of the segment closest to `point`: segment `i` runs from vertex `i` to the next.
1505
+ *
1506
+ * @param points - The contour's vertices.
1507
+ * @param point - The point, in image coordinates.
1508
+ * @param closed - Whether the last vertex joins the first, which adds the closing segment
1509
+ * (index `points.length - 1`). Defaults to `true`.
1510
+ * @returns The segment's index; 0 for a contour with no segment.
1511
+ */
1512
+ export declare function nearestContourSegment(points: Point[], point: Point, closed?: boolean): number;
1513
+ /**
1514
+ * Edit contour vertices over an ImageStage using its shared source-image transform.
1515
+ *
1516
+ * - **Vertices.** Each vertex is a focusable button: drag it (once the pointer has moved
1517
+ * 3 screen pixels, so a jittery click edits nothing), nudge it with the arrow keys (Shift for
1518
+ * a tenth of a pixel), delete it with Delete or Backspace (a closed contour keeps three
1519
+ * vertices, an open one two), or insert one after it with Insert.
1520
+ * - **Open or closed.** `closed` (the default) draws a polygon; `closed={false}` an open
1521
+ * polyline with no segment from the last vertex back to the first.
1522
+ * - **Outline.** The outline takes no presses, so a press on it reaches the layers below, or
1523
+ * pans. While `editable` in `"vertex"` mode, the contour answers the stage's hit-test
1524
+ * (`STAGE_HIT_PRIORITY.line` by default, segment indices as ids), and a double-click near the
1525
+ * outline inserts a vertex on the nearest segment; the stage's double-click to fit does not
1526
+ * run then.
1527
+ * - **Brush and erase.** In `"brush"` mode a drag pushes the contour with a soft round brush
1528
+ * (`deformContour`, from the contour as it was at the press, held inside `bounds`); in
1529
+ * `"erase"` mode a drag along the contour previews the stretch it removes, dashed, and the
1530
+ * release calls `onErase`. Both start only past the click slop. The vertex handles are
1531
+ * hidden in these modes.
1532
+ *
1533
+ * The SVG carries `data-mode` while editable; the tool surface is `data-tool-surface`, and the
1534
+ * stretch an erase would remove is `data-erase-preview`.
1535
+ */
1536
+ export declare function ContourEditor({ points, closed, onChange, onCommit, editable, label, stroke, bounds, layerId, priority, mode, brushRadius, onErase }: ContourEditorProps): import("react").JSX.Element;
1537
+ //#endregion
1538
+ //#region src/components/contourArc.d.ts
1539
+ /**
1540
+ * The cumulative arc length at each vertex.
1541
+ *
1542
+ * @param points - The path's vertices.
1543
+ * @param closed - Whether the last vertex joins the first. Defaults to `false`.
1544
+ * @returns `s[i]`, the length of the path from the first vertex to vertex `i`, so `s[0]` is 0.
1545
+ * A closed path has one more entry: its whole length, back at the first vertex. The last
1546
+ * entry is always the path's length. An empty path gives `[]`.
1547
+ */
1548
+ export declare function arcLengths(points: readonly Point[], closed?: boolean): number[];
1549
+ /**
1550
+ * The point at arc length `s`.
1551
+ *
1552
+ * @param points - The path's vertices.
1553
+ * @param s - The distance along the path, in image pixels. On an open path it is clamped to
1554
+ * `[0, length]`; on a closed path it wraps around.
1555
+ * @param closed - Whether the last vertex joins the first. Defaults to `false`.
1556
+ * @returns The point. An empty path gives `NaN` coordinates.
1557
+ */
1558
+ export declare function pointAtArc(points: readonly Point[], s: number, closed?: boolean): Point;
1559
+ /**
1560
+ * The nearest place on the path to a point.
1561
+ *
1562
+ * @param points - The path's vertices.
1563
+ * @param p - The point, in image coordinates.
1564
+ * @param closed - Whether the last vertex joins the first. Defaults to `false`.
1565
+ * @returns `s`, the arc length of the nearest place (the first one, on a tie); `point`, the
1566
+ * place itself; and `distance`, how far `p` is from it. An empty path gives `s` 0, a `NaN`
1567
+ * point and an infinite distance.
1568
+ */
1569
+ export declare function projectToArc(points: readonly Point[], p: Point, closed?: boolean): {
1570
+ s: number;
1571
+ point: Point;
1572
+ distance: number;
1573
+ };
1574
+ /**
1575
+ * The stretch of the path between two arc lengths, as a polyline: the place at `s0`, every
1576
+ * vertex strictly between, and the place at `s1`.
1577
+ *
1578
+ * @param points - The path's vertices.
1579
+ * @param s0 - Where the stretch starts.
1580
+ * @param s1 - Where it ends.
1581
+ * @param closed - Whether the last vertex joins the first. Defaults to `false`. On an open
1582
+ * path both ends are clamped to it and the stretch always runs forward (`s0` and `s1` are
1583
+ * swapped when `s0 > s1`). On a closed path an end outside `[0, length]` wraps, and with
1584
+ * `s0 > s1` the stretch runs forward past the first vertex and on to `s1`.
1585
+ * @returns The stretch, at least its two ends (the same point twice for an empty stretch).
1586
+ * An empty path gives `[]`.
1587
+ */
1588
+ export declare function subPath(points: readonly Point[], s0: number, s1: number, closed?: boolean): Point[];
1589
+ /**
1590
+ * The unit normal at arc length `s`: the tangent of the segment there, turned a quarter turn
1591
+ * by `(tx, ty) → (-ty, tx)`. With image `y` pointing down that turn is **clockwise on
1592
+ * screen**: on a path running left to right the normal points down, and on a closed contour
1593
+ * whose vertices run clockwise on screen it points inward.
1594
+ *
1595
+ * @param points - The path's vertices.
1596
+ * @param s - The distance along the path, clamped or wrapped as in `pointAtArc`. At a vertex
1597
+ * the segment that starts there is used (at the end of an open path, the last one).
1598
+ * @param closed - Whether the last vertex joins the first. Defaults to `false`.
1599
+ * @returns A unit vector, or `{ x: 0, y: 0 }` for a path with no length.
1600
+ */
1601
+ export declare function normalAtArc(points: readonly Point[], s: number, closed?: boolean): Point;
1602
+ /**
1603
+ * Push part of a path with a soft round brush: every vertex within `radius` of `centre`
1604
+ * moves by `delta` scaled by a falloff of `0.5 · (1 + cos(π · d / radius))`, `d` being its
1605
+ * distance from `centre` — the whole `delta` at the centre, nothing at the rim, smooth in
1606
+ * between. Each segment that passes within `radius` of `centre` is first divided so its
1607
+ * vertices are at most `radius / 4` apart, so the brush bends the path rather than dragging
1608
+ * a long segment's two ends.
1609
+ *
1610
+ * @param points - The path's vertices.
1611
+ * @param centre - The brush's centre, in image coordinates.
1612
+ * @param delta - How far its centre pushes, in image pixels.
1613
+ * @param radius - The brush's radius, in image pixels. Zero or less leaves the path as it is.
1614
+ * @param closed - Whether the last vertex joins the first. Defaults to `false`; a closed
1615
+ * path's closing segment is divided like the others, its new vertices appended at the end.
1616
+ * @returns A new list of vertices.
1617
+ */
1618
+ export declare function deformContour(points: readonly Point[], centre: Point, delta: Point, radius: number, closed?: boolean): Point[];
1619
+ /**
1620
+ * The pieces of a path left after erasing the stretch between two arc lengths.
1621
+ *
1622
+ * @param points - The path's vertices.
1623
+ * @param s0 - Where the erased stretch starts.
1624
+ * @param s1 - Where it ends.
1625
+ * @param closed - Whether the last vertex joins the first. Defaults to `false`. On an open
1626
+ * path the ends are clamped and ordered as in `subPath`, and up to two pieces remain: before
1627
+ * the stretch and after it. On a closed path the stretch runs forward from `s0` to `s1`
1628
+ * (past the first vertex when `s0 > s1`), and what remains is **one open piece**, from `s1`
1629
+ * on around to `s0`; erasing an empty stretch (`s0` equal to `s1`) cuts the contour open there.
1630
+ * @returns The pieces, each an open polyline of at least two points. A piece with no length
1631
+ * (the erased stretch reached an open path's end) is left out.
1632
+ */
1633
+ export declare function eraseArc(points: readonly Point[], s0: number, s1: number, closed?: boolean): Point[][];
1192
1634
  //#endregion
1193
1635
  //#region src/components/RectRoiEditor.d.ts
1636
+ /**
1637
+ * What `RectRoiEditor`'s `ref` exposes: a new region drawn from a press the app's own target
1638
+ * received, for an app whose one `StageSurface` decides what a press means.
1639
+ */
1640
+ interface RectRoiEditorHandle {
1641
+ /**
1642
+ * Draw a new region from a press: call it from a `pointerdown` handler, such as a layer's
1643
+ * `onItemPress`. The press is claimed (the stage does not pan) and followed on `window`; a
1644
+ * drag shorter than the click slop, or a box smaller than `minSize`, draws nothing. Another
1645
+ * event type (a touch tap reported on release) does nothing. Works whether or not `draw` is
1646
+ * set, and does nothing while `editable` is off or the stage is in pan mode.
1647
+ */
1648
+ startDraw(event: StagePointerEvent): void;
1649
+ /**
1650
+ * The same draw as a `StageDrag`, to return from `StageSurface`'s `onPress`. It claims a
1651
+ * touch, so a finger draws instead of panning. While `editable` is off it is an empty drag:
1652
+ * the press is claimed and nothing is drawn.
1653
+ */
1654
+ drawDrag(press: StagePress): StageDrag;
1655
+ }
1194
1656
  /** Props of `RectRoiEditor`. */
1195
1657
  interface RectRoiEditorProps {
1196
1658
  /** The region in image coordinates, or `null` for none. */
@@ -1207,8 +1669,23 @@ interface RectRoiEditorProps {
1207
1669
  */
1208
1670
  draw?: boolean | undefined;
1209
1671
  /**
1210
- * The area the region must stay in. Defaults to `{ x: 0, y: 0, width, height }` of the
1211
- * image: a region given as a start pixel and a size.
1672
+ * Whether `draw` puts a full-frame draw target (`data-draw-surface`) in this layer. Defaults
1673
+ * to `true`. Turn it off when the app's own `StageSurface` decides what a press means, so
1674
+ * other layers can sit between the target and the region's handles, and start the draw from
1675
+ * there with the `ref`'s `drawDrag` or `startDraw`.
1676
+ */
1677
+ drawSurface?: boolean | undefined;
1678
+ /**
1679
+ * What a press inside the region does. `"move"` (the default) moves it. `"none"` leaves the
1680
+ * inside to the layers below (a press there selects what lies under the region, say): only
1681
+ * the handles and the band along the outline grab the region. The region stays focusable and
1682
+ * the arrow keys still move it.
1683
+ */
1684
+ interior?: "move" | "none" | undefined;
1685
+ /**
1686
+ * The area the region must stay in, in the stage's centre convention. Defaults to
1687
+ * `{ x: -0.5, y: -0.5, width, height }` of the image: its full extent, so a region that
1688
+ * fills it outlines the image edges.
1212
1689
  */
1213
1690
  bounds?: Rect | undefined;
1214
1691
  /** The smallest side, in image pixels; a smaller drawn box is a click, not a region. Defaults to 4. */
@@ -1217,22 +1694,40 @@ interface RectRoiEditorProps {
1217
1694
  label?: string | undefined;
1218
1695
  /** CSS colour of the outline and handles. Defaults to the overlay `selection` role. */
1219
1696
  stroke?: string | undefined;
1697
+ /** CSS colour of the tint inside the region. Defaults to `stroke`. */
1698
+ fill?: string | undefined;
1699
+ /** Opacity of the tint inside the region, 0 to 1. Defaults to 0.06; `0` draws no tint. */
1700
+ fillOpacity?: number | undefined;
1701
+ /** Draw from the app's own press target; see `RectRoiEditorHandle`. */
1702
+ ref?: Ref<RectRoiEditorHandle> | undefined;
1220
1703
  }
1221
1704
  /**
1222
1705
  * An editable axis-aligned region inside an `ImageStage`.
1223
1706
  *
1224
- * - **Handles.** The eight handles resize the region, and the interior moves it. A handle
1225
- * dragged through the opposite edge flips the box.
1226
- * - **Drawing.** With `draw`, a drag elsewhere on the image draws a new region.
1707
+ * - **Handles.** The eight handles resize the region, and the interior moves it, as does the
1708
+ * band along the outline (the pointer's tolerance: 6 px for a mouse, 12 px for a finger). A
1709
+ * handle dragged through the opposite edge flips the box.
1710
+ * - **Press order.** One decision serves every part of the editor: the nearest handle first,
1711
+ * then the outline band, then the interior (unless `interior` is `"none"`). A small region's
1712
+ * interior does not steal a press meant for a handle, and a press that grabs nothing is not
1713
+ * claimed.
1714
+ * - **Click slop.** A press becomes an edit only once the pointer has moved 3 screen pixels, so
1715
+ * a jittery click calls neither `onValueChange` nor `onCommit`. An interrupted drag
1716
+ * (`pointercancel`) puts the region back and commits nothing.
1717
+ * - **Drawing.** With `draw`, a drag elsewhere on the image draws a new region; with
1718
+ * `drawSurface={false}` the app starts it through the `ref`.
1227
1719
  * - **Keyboard.** The region is focusable: arrow keys move it by one image pixel (ten with
1228
1720
  * Shift), and with Alt they grow or shrink it from the bottom-right corner.
1229
1721
  * - **Limits.** The region stays inside `bounds` and never gets smaller than `minSize`.
1230
1722
  * - **Rendering.** Handles and the outline are a constant size on screen at every zoom.
1231
1723
  * - **Panning.** A press with the hand tool, or with space held, still pans.
1232
1724
  *
1233
- * The SVG carries `data-editable` and `data-drawing` (while a draw is in progress).
1725
+ * Data attributes, for styling and tests: the SVG carries `data-editable`, and `data-drawing`
1726
+ * while a draw is in progress; the full-frame draw target is `data-draw-surface`; the region's
1727
+ * focusable inside is `data-roi-interior`; the band along its outline is `data-roi-band`; and
1728
+ * each handle is `data-handle`, one of `nw`, `n`, `ne`, `e`, `se`, `s`, `sw`, `w`.
1234
1729
  */
1235
- export declare function RectRoiEditor({ value, onValueChange, onCommit, editable, draw, bounds, minSize, label, stroke }: RectRoiEditorProps): import("react").JSX.Element;
1730
+ export declare function RectRoiEditor({ value, onValueChange, onCommit, editable, draw, drawSurface, interior, bounds, minSize, label, stroke, fill, fillOpacity, ref }: RectRoiEditorProps): import("react").JSX.Element;
1236
1731
  //#endregion
1237
1732
  //#region src/components/polylineIndex.d.ts
1238
1733
  /** A polyline's identity. */
@@ -1333,6 +1828,25 @@ interface PolylineSetItem extends Polyline {
1333
1828
  }
1334
1829
  /** How a gesture combines with the current selection. */
1335
1830
  type PolylineSelectMode = "replace" | "toggle" | "add";
1831
+ /**
1832
+ * What `PolylineSet`'s `ref` exposes: a rubber band started from a press somewhere else, such
1833
+ * as the app's `StageSurface` or a region editor's inside. It works whether or not the layer
1834
+ * is `interactive`, and ends in `onSelect` like a band started on the set itself.
1835
+ */
1836
+ interface PolylineSetHandle {
1837
+ /**
1838
+ * Start a band from a `pointerdown`: the press is claimed (the stage does not pan) and
1839
+ * followed on `window`. `mode` defaults to `"add"` with ⌘/Ctrl held and `"replace"` without.
1840
+ * Another event type (a touch tap reported on release) does nothing, and so does a press
1841
+ * while the stage is in pan mode.
1842
+ */
1843
+ startSweep(event: StagePointerEvent, mode?: "replace" | "add"): void;
1844
+ /**
1845
+ * The same band as a `StageDrag`, to return from `StageSurface`'s `onPress`. `mode` defaults
1846
+ * from the press's ⌘/Ctrl. It claims a touch, so a finger sweeps instead of panning.
1847
+ */
1848
+ sweepDrag(press: StagePress, mode?: "replace" | "add"): StageDrag;
1849
+ }
1336
1850
  /** Props of `PolylineSet`. */
1337
1851
  interface PolylineSetProps {
1338
1852
  /** The polylines, in image coordinates. */
@@ -1370,6 +1884,13 @@ interface PolylineSetProps {
1370
1884
  * and to the layers below.
1371
1885
  */
1372
1886
  marquee?: boolean | undefined;
1887
+ /**
1888
+ * Whether `marquee` puts a full-frame sweep target (`data-marquee-surface`) in this layer.
1889
+ * Defaults to `true`. Off, a press on a line still starts a band, and a press on bare image
1890
+ * reaches the layers below: the app starts a band from there with the `ref`'s `sweepDrag`
1891
+ * or `startSweep`, so a band can begin anywhere without this layer covering the others.
1892
+ */
1893
+ marqueeSurface?: boolean | undefined;
1373
1894
  /**
1374
1895
  * Whether the layer takes presses and hover. Defaults to `true` when any of `onItemPress`,
1375
1896
  * `onSelect`, `onHover`, `onHoverChange` or `marquee` is given. When `false` the layer
@@ -1389,30 +1910,45 @@ interface PolylineSetProps {
1389
1910
  hitWidth?: number | undefined;
1390
1911
  /** The zoom from which a hovered or selected line's points are drawn. Defaults to 3. */
1391
1912
  vertexScale?: number | undefined;
1913
+ /**
1914
+ * CSS colour of the point dots. Defaults to the overlay `label` role, a near-white that stands
1915
+ * apart from both the line colours and the selection colour, so the points of a selected line
1916
+ * show on it. Each dot sits on a dark halo.
1917
+ */
1918
+ vertexColor?: string | undefined;
1919
+ /** Diameter of a point dot, in screen pixels, without its 1 px halo. Defaults to 4. */
1920
+ vertexSize?: number | undefined;
1392
1921
  /** The layer's accessible name. Defaults to "Lines". */
1393
1922
  label?: string | undefined;
1394
1923
  /** The id hit-tests report for this layer. Defaults to a generated one. */
1395
1924
  layerId?: string | undefined;
1396
1925
  /** Rank against other layers in hit-tests. Defaults to `STAGE_HIT_PRIORITY.line`. */
1397
1926
  priority?: number | undefined;
1927
+ /** Start a rubber band from a press elsewhere; see `PolylineSetHandle`. */
1928
+ ref?: Ref<PolylineSetHandle> | undefined;
1398
1929
  }
1399
1930
  /**
1400
1931
  * A selectable set of polylines inside an `ImageStage`.
1401
1932
  *
1402
- * - **States**, from visual-language §5:
1933
+ * - **States**:
1403
1934
  * - default 1.5 screen px;
1404
1935
  * - hover 2 px;
1405
1936
  * - selected 2.5 px in `selectionStroke`;
1406
1937
  * - dimmed at 35 % opacity.
1407
1938
  * - **Halo.** Every line has a halo, so it holds on any image.
1408
- * - **Points.** Above `vertexScale`, the points of the hovered and selected lines are drawn.
1939
+ * - **Points.** Above `vertexScale`, the points of the hovered and selected lines are drawn as
1940
+ * `vertexColor` dots on a dark halo, so they show on a selected line too.
1409
1941
  * - **Panning.** The hand tool and a held space bar still pan.
1410
1942
  * - **Tools.** Without a handler (or with `interactive={false}`) the layer takes no presses
1411
1943
  * and only answers `useStageHitTest`, so a draw tool's surface below receives them.
1944
+ * - **Sweeps from elsewhere.** The `ref`'s `startSweep` and `sweepDrag` start a band from a
1945
+ * press another target received; with `marqueeSurface={false}` the layer keeps no
1946
+ * full-frame target of its own.
1412
1947
  *
1413
- * The SVG carries `data-hovered` (the hovered id) and `data-sweeping` while a band is drawn.
1948
+ * The SVG carries `data-hovered` (the hovered id) and `data-sweeping` while a band is drawn;
1949
+ * the point dots are `data-points`.
1414
1950
  */
1415
- export declare function PolylineSet({ items, selected, dimmed, hovered, onHover, onHoverChange, onItemPress, onSelect, marquee, interactive, stroke, selectionStroke, hitWidth, vertexScale, label, layerId, priority }: PolylineSetProps): import("react").JSX.Element;
1951
+ export declare function PolylineSet({ items, selected, dimmed, hovered, onHover, onHoverChange, onItemPress, onSelect, marquee, marqueeSurface, interactive, stroke, selectionStroke, hitWidth, vertexScale, vertexColor, vertexSize, label, layerId, priority, ref }: PolylineSetProps): import("react").JSX.Element;
1416
1952
  //#endregion
1417
1953
  //#region src/components/markerShapes.d.ts
1418
1954
  /** One kind of marker. */
@@ -1590,6 +2126,11 @@ interface PointSetItem extends PointItem {
1590
2126
  kind?: string | undefined;
1591
2127
  /** The overlay role it is painted in. Defaults to the marker kind's role, usually `feature`. */
1592
2128
  role?: OverlayRole | undefined;
2129
+ /**
2130
+ * CSS colour of its mark (`#hex`, `var(--x)`, `color-mix(…)`; used as given). Overrides the
2131
+ * role; selection still paints in `selectionStroke`. Points sharing a colour share a batch.
2132
+ */
2133
+ color?: string | undefined;
1593
2134
  /** Its orientation in radians, clockwise from +x; read by `directed`. */
1594
2135
  angle?: number | undefined;
1595
2136
  /** A second angle in radians, for a glyph with two axes. `MarkerShape.path` gets `undefined` without it. */
@@ -1643,7 +2184,7 @@ interface PointSetProps {
1643
2184
  *
1644
2185
  * - **Markers** by kind, from the overlay grammar: `dot`, `plus` (corner), `cross`, `square`,
1645
2186
  * `hollow` (predicted), `directed`. Add your own through `markers`.
1646
- * - **States**, from visual-language §5: default 1.5 screen px, hover 2, selected 2.5 in the
2187
+ * - **States**: default 1.5 screen px, hover 2, selected 2.5 in the
1647
2188
  * selection colour with a ring, dimmed at 35 % opacity. Every mark has a halo.
1648
2189
  * - **Labels** only where points are at least 24 screen px apart, at most 200 at a time.
1649
2190
  * - **Picking** goes through the stage's hit registry: `onHoverChange` and `onItemPress` here,
@@ -1773,6 +2314,13 @@ interface AreaSetItem extends Area {
1773
2314
  role?: OverlayRole | undefined;
1774
2315
  /** Text drawn at its centre (the mean of its vertices), when the zoom leaves room. */
1775
2316
  label?: string | undefined;
2317
+ /**
2318
+ * CSS colour of its outline (`#hex`, `var(--x)`, `color-mix(…)`; used as given). Overrides
2319
+ * the role and the layer's `stroke`. Items sharing a colour share a batch.
2320
+ */
2321
+ stroke?: string | undefined;
2322
+ /** CSS colour of its fill. Defaults to its outline colour. */
2323
+ fill?: string | undefined;
1776
2324
  }
1777
2325
  /** Props of `AreaSet`. */
1778
2326
  interface AreaSetProps {
@@ -1807,6 +2355,30 @@ interface AreaSetProps {
1807
2355
  * of a marker quad reads (the overlay grammar's "corner 0 ticked"). Off by default.
1808
2356
  */
1809
2357
  firstVertexTick?: boolean | undefined;
2358
+ /** CSS colour of every outline that names none of its own, in place of its role's. */
2359
+ stroke?: string | undefined;
2360
+ /** The fill's alpha, 0 to 1. Defaults to 0.12. */
2361
+ fillOpacity?: number | undefined;
2362
+ /**
2363
+ * How a self-overlapping ring is filled. `"nonzero"` (the default) fills everything a ring
2364
+ * encloses; `"evenodd"` leaves the doubly-wound part of a self-intersecting ring open, as
2365
+ * a rasteriser would. With `"evenodd"` every region's fill is its own path (even-odd across
2366
+ * a batched path would cut a hole where two regions overlap); outlines stay batched.
2367
+ */
2368
+ fillRule?: "nonzero" | "evenodd" | undefined;
2369
+ /**
2370
+ * The paint order. `"appearance"` (the default) draws one batch per appearance, in order of
2371
+ * first appearance. `"items"` draws consecutive runs in item order, so a later region
2372
+ * covers an earlier one of another appearance (a subtract region over an add region); more
2373
+ * runs mean more paths, so use it when the order matters.
2374
+ */
2375
+ paintOrder?: "appearance" | "items" | undefined;
2376
+ /**
2377
+ * What a selected region looks like. `"selection"` (the default) paints it in the
2378
+ * selection colour, fill and outline. `"item"` keeps its own fill (and its place in the
2379
+ * paint order) and restyles only the outline.
2380
+ */
2381
+ selectionFill?: "selection" | "item" | undefined;
1810
2382
  /** Draw the dark band under every outline. On by default; off for a fast, flat layer. */
1811
2383
  halo?: boolean | undefined;
1812
2384
  /** CSS colour of selected regions. Defaults to the overlay `selection` role. */
@@ -1821,10 +2393,11 @@ interface AreaSetProps {
1821
2393
  /**
1822
2394
  * A selectable set of closed regions inside an `ImageStage`.
1823
2395
  *
1824
- * - **Rendering**: an outline and its 12 % fill, in the item's role (`feature` by default).
2396
+ * - **Rendering**: an outline and its 12 % fill, in the item's role (`feature` by default) or its own
2397
+ * `stroke` / `fill` colours (`fillOpacity`, `fillRule`, `paintOrder` and `selectionFill` tune the fill).
1825
2398
  * Rings are wound alike before they are batched, so overlapping regions never cut a hole in
1826
2399
  * each other.
1827
- * - **States**, from visual-language §5: default 1.5 screen px (1 for `model` and
2400
+ * - **States**: default 1.5 screen px (1 for `model` and
1828
2401
  * `structure`), hover 2, selected 2.5 in the selection colour, dimmed at 35 % opacity. Every
1829
2402
  * outline has a halo. A region has no ring: its outline at 2.5 px is the mark.
1830
2403
  * - **Labels** at the centre of a region, only where regions are at least 24 screen px apart,
@@ -1835,7 +2408,7 @@ interface AreaSetProps {
1835
2408
  *
1836
2409
  * The SVG carries `data-hovered` (the hovered id).
1837
2410
  */
1838
- export declare function AreaSet({ items, role, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, labels, firstVertexTick, halo, selectionStroke, layerId, priority, label }: AreaSetProps): import("react").JSX.Element;
2411
+ export declare function AreaSet({ items, role, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, labels, firstVertexTick, stroke, fillOpacity, fillRule, paintOrder, selectionFill, halo, selectionStroke, layerId, priority, label }: AreaSetProps): import("react").JSX.Element;
1839
2412
  //#endregion
1840
2413
  //#region src/components/ellipseIndex.d.ts
1841
2414
  /** An ellipse's identity. */
@@ -1999,7 +2572,7 @@ interface EllipseSetProps {
1999
2572
  *
2000
2573
  * - **Geometry** is data: `rx`, `ry` and the centre are image pixels and scale with the image;
2001
2574
  * the stroke is a screen constant.
2002
- * - **States** follow visual-language §5: 1.5 screen px (1 for `model` and `structure`), hover
2575
+ * - **States**: 1.5 screen px (1 for `model` and `structure`), hover
2003
2576
  * 2, selected 2.5 in the selection colour, dimmed at 35 % opacity. Every stroke has a halo.
2004
2577
  * - **Batching** is by (role, dash, opacity, dimming): a thousand rings are a dozen elements.
2005
2578
  * - **Picking** goes through the stage's hit registry: a press within the pointer's tolerance of
@@ -2387,6 +2960,14 @@ export declare function resizeShape(shape: RotatedShape, handle: RoiHandle, to:
2387
2960
  * @returns The rotated shape: the same centre and size, `rotation` in `(-π, π]`.
2388
2961
  */
2389
2962
  export declare function rotateShape(shape: RotatedShape, to: Point, snap?: number): RotatedShape;
2963
+ /**
2964
+ * An angle rounded to the nearest multiple of a step: what Shift does to a rotation.
2965
+ *
2966
+ * @param angle - Radians.
2967
+ * @param step - The step, in radians (`Math.PI / 12` for 15°). 0 or less leaves the angle as it is.
2968
+ * @returns The rounded angle. It is not brought into `(-π, π]`; pass it through `normalizeAngle` for that.
2969
+ */
2970
+ export declare function snapAngle(angle: number, step: number): number;
2390
2971
  /**
2391
2972
  * Move the shape.
2392
2973
  *
@@ -2481,6 +3062,8 @@ interface ShapeEditorProps {
2481
3062
  * then the interior or outline band (move), then nothing. A small shape's interior does not
2482
3063
  * steal a press meant for a handle, and a press that hits none of them is not claimed, so
2483
3064
  * it reaches whatever is below, or the stage.
3065
+ * - **Click slop.** A press becomes an edit only once the pointer has moved 3 screen pixels
3066
+ * from where it landed, so a jittery click changes nothing and commits nothing.
2484
3067
  * - **Touch.** A press that grabs the shape is claimed; a second finger landing during an edit
2485
3068
  * cancels it (the shape reverts, nothing is committed) and is left to the stage.
2486
3069
  * - **Rotation.** The handle past the top side turns the shape about its centre; hold Shift to
@@ -2499,13 +3082,141 @@ interface ShapeEditorProps {
2499
3082
  */
2500
3083
  export declare function ShapeEditor({ kind, value, onValueChange, onCommit, editable, rotatable, minSize, label, stroke }: ShapeEditorProps): import("react").JSX.Element;
2501
3084
  //#endregion
3085
+ //#region src/components/datumEdit.d.ts
3086
+ /** A frame on the image: where it starts, and which way its i axis points. */
3087
+ interface Datum {
3088
+ /** The origin, in image coordinates. */
3089
+ origin: Point;
3090
+ /** The i axis's direction: radians, clockwise on screen from the image's `+x`. */
3091
+ angle: number;
3092
+ }
3093
+ /** The origin ring's radius, in screen pixels. */
3094
+ export declare const DATUM_RING_PX = 7;
3095
+ /** The i axis's length when nothing else is given, in screen pixels; the j axis is half of it. */
3096
+ export declare const DATUM_ARM_PX = 40;
3097
+ /** The rotation handle's radius at the end of the i axis, in screen pixels. */
3098
+ export declare const DATUM_HANDLE_PX = 5;
3099
+ /**
3100
+ * The ends of a datum's axes.
3101
+ *
3102
+ * @param d - The datum.
3103
+ * @param armLength - The i axis's length, in image pixels; the j axis is half of it. For a
3104
+ * screen-constant glyph pass `useScreenPx()(40)`.
3105
+ * @returns The end of the i axis and of the j axis, in image coordinates.
3106
+ */
3107
+ export declare function datumAxes(d: Datum, armLength: number): {
3108
+ i: Point;
3109
+ j: Point;
3110
+ };
3111
+ /** How `moveDatum` places the origin. */
3112
+ interface MoveDatumOptions {
3113
+ /** Round the origin to a grid of this many image pixels; 0 or omitted for none. */
3114
+ grid?: number | undefined;
3115
+ /** Keep the origin inside this rectangle (edges included), on the last grid line inside it when there is a grid. */
3116
+ bounds?: Rect | undefined;
3117
+ }
3118
+ /**
3119
+ * Move a datum's origin to `to`, keeping its angle.
3120
+ *
3121
+ * @param d - The datum.
3122
+ * @param to - The new origin, in image coordinates.
3123
+ * @param options - A grid to round to, then bounds to stay inside.
3124
+ * @returns The moved datum.
3125
+ */
3126
+ export declare function moveDatum(d: Datum, to: Point, options?: MoveDatumOptions): Datum;
3127
+ /**
3128
+ * Turn a datum about its origin so that its i axis points at `to`.
3129
+ *
3130
+ * @param d - The datum.
3131
+ * @param to - The pointer, in image coordinates. At the origin itself the angle is kept.
3132
+ * @param snap - Round the angle to a multiple of this many radians; 0 for none.
3133
+ * @returns The turned datum, its angle in `(-π, π]`.
3134
+ */
3135
+ export declare function rotateDatum(d: Datum, to: Point, snap?: number): Datum;
3136
+ /** What `datumPress` reads besides the press. */
3137
+ interface DatumPressOptions {
3138
+ /** The i axis's length, in screen pixels. Defaults to 40. */
3139
+ armLength?: number | undefined;
3140
+ /** Whether the arm can be grabbed to turn the datum. Defaults to `true`. */
3141
+ rotatable?: boolean | undefined;
3142
+ }
3143
+ /**
3144
+ * What a press on a datum grabs, decided once for the whole glyph.
3145
+ *
3146
+ * The origin is its ring (7 screen px); the arm is the i axis from the ring out to its handle.
3147
+ * Each is within reach when the press is within `radius` screen pixels of it, and the nearer
3148
+ * one wins; a tie goes to the origin.
3149
+ *
3150
+ * @param d - The datum.
3151
+ * @param point - The press, in image coordinates.
3152
+ * @param scale - The view scale: screen pixels per image pixel.
3153
+ * @param radius - The pointer's tolerance in screen pixels: 12 for a touch, 6 for a mouse.
3154
+ * @param options - The arm's length, and whether it can be grabbed.
3155
+ * @returns `"origin"` (move), `"arm"` (turn), or `null`: the press belongs to whatever is below.
3156
+ */
3157
+ export declare function datumPress(d: Datum, point: Point, scale: number, radius: number, options?: DatumPressOptions): "origin" | "arm" | null;
3158
+ //#endregion
3159
+ //#region src/components/DatumEditor.d.ts
3160
+ /** Props of `DatumEditor`. */
3161
+ interface DatumEditorProps {
3162
+ /** The datum, when the app controls it. `angle` is in radians, clockwise on screen from `+x`. */
3163
+ value?: Datum | undefined;
3164
+ /** The starting datum when the editor controls it. Defaults to the image's centre, pointing along `+x`. */
3165
+ defaultValue?: Datum | undefined;
3166
+ /** Called with the datum as it changes: on every move of a drag, and on each key press. */
3167
+ onValueChange?: ((value: Datum) => void) | undefined;
3168
+ /** Called once a gesture ends (a drag released, a key pressed): the moment to save or re-run. */
3169
+ onCommit?: ((value: Datum) => void) | undefined;
3170
+ /** Accept moves and turns, by pointer and keyboard. Defaults to `true`. */
3171
+ editable?: boolean | undefined;
3172
+ /** Show the rotation handle and accept `[` / `]`. Defaults to `true`; off for a datum that must keep its angle. */
3173
+ rotatable?: boolean | undefined;
3174
+ /** The step a turn rounds to, in radians: while Shift is held, or always with `snapAlways`. Defaults to π/12 (15°); 0 never rounds. */
3175
+ angleSnap?: number | undefined;
3176
+ /** Round every turn to `angleSnap`, not only while Shift is held. Defaults to `false`. */
3177
+ snapAlways?: boolean | undefined;
3178
+ /** Round the origin to a grid of this many image pixels as it moves. Defaults to 0: no grid. */
3179
+ originSnap?: number | undefined;
3180
+ /** The rectangle the origin stays inside, in image coordinates. Defaults to the image. */
3181
+ bounds?: Rect | undefined;
3182
+ /** The i axis's length in screen pixels; the j axis is half of it. Defaults to 40. */
3183
+ armLength?: number | undefined;
3184
+ /** The datum's accessible name. Defaults to "Datum". */
3185
+ label?: string | undefined;
3186
+ /** CSS colour of the glyph. Defaults to the overlay `model` role. */
3187
+ stroke?: string | undefined;
3188
+ /** Merged onto the `<svg>` with `cn`. */
3189
+ className?: string | undefined;
3190
+ }
3191
+ /**
3192
+ * An editable datum inside an `ImageStage`: a ring at the origin with its i axis (an arm ending
3193
+ * in a rotation handle) and its j axis (half as long, a quarter turn clockwise from i).
3194
+ *
3195
+ * - **Pointer.** Drag the ring to move the origin; drag the arm or its handle to turn the datum
3196
+ * about the origin. A press grabs whichever is nearer, and nothing happens until the pointer
3197
+ * has moved 3 px, so a click does not nudge it. Hold Shift to round the angle to `angleSnap`
3198
+ * (15°), or set `snapAlways`. `originSnap` rounds the origin to a grid; `bounds` keeps it in.
3199
+ * - **Keyboard.** The origin is a focusable button: arrow keys move it one image pixel (ten with
3200
+ * Shift; one grid step with `originSnap`), and `[` / `]` turn it by 1° (15° with Shift).
3201
+ * - **Rendering.** Every part is a constant size on screen at every zoom, over a halo.
3202
+ * - **Panning.** A press away from the glyph, or with the hand tool or space held, still pans.
3203
+ *
3204
+ * The SVG carries `data-editable`, and `data-dragging` (`origin` or `arm`) during a drag.
3205
+ */
3206
+ export declare function DatumEditor({ value, defaultValue, onValueChange, onCommit, editable, rotatable, angleSnap, snapAlways, originSnap, bounds, armLength, label, stroke, className }: DatumEditorProps): import("react").JSX.Element;
3207
+ //#endregion
2502
3208
  //#region src/components/DraftShape.d.ts
2503
3209
  /**
2504
3210
  * The shape being drawn.
2505
3211
  * - `point`: a position.
2506
3212
  * - `line`: a segment from `from` to `to`.
2507
3213
  * - `polyline` and `polygon`: the vertices placed so far, flat `[x0, y0, x1, y1, …]`, and
2508
- * the pointer as `cursor`, which the next vertex would land on.
3214
+ * the pointer as `cursor`, which the next vertex would land on. A polygon with `closing`
3215
+ * set has the pointer on its first vertex: a click there closes it, so the first vertex is
3216
+ * highlighted and the closing edge drawn solid.
3217
+ * - `stroke`: a brush trail, the flat `points` swept by a round brush of `width` image pixels
3218
+ * (never thinner than 1 screen pixel), as a translucent filled band without dashes.
3219
+ * - `brush`: a brush footprint cursor, a circle of `diameter` image pixels centred on `x`, `y`.
2509
3220
  * - `rect` and `ellipse`: two opposite corners of the axis-aligned box (the drag's start and
2510
3221
  * the pointer).
2511
3222
  */
@@ -2525,6 +3236,16 @@ type DraftShapeSpec = {
2525
3236
  kind: "polygon";
2526
3237
  points: ArrayLike<number>;
2527
3238
  cursor?: Point | undefined;
3239
+ closing?: boolean | undefined;
3240
+ } | {
3241
+ kind: "stroke";
3242
+ points: ArrayLike<number>;
3243
+ width: number;
3244
+ } | {
3245
+ kind: "brush";
3246
+ x: number;
3247
+ y: number;
3248
+ diameter: number;
2528
3249
  } | {
2529
3250
  kind: "rect";
2530
3251
  from: Point;
@@ -2540,6 +3261,8 @@ interface DraftShapeProps {
2540
3261
  shape: DraftShapeSpec | null;
2541
3262
  /** The overlay role it is drawn in. Defaults to `"selection"`, the accent. */
2542
3263
  role?: OverlayRole | undefined;
3264
+ /** A CSS colour that overrides `role`, for example `"var(--defect)"` for an eraser. */
3265
+ stroke?: string | undefined;
2543
3266
  /** Draw the dark band under the outline. On by default. */
2544
3267
  halo?: boolean | undefined;
2545
3268
  }
@@ -2549,12 +3272,17 @@ interface DraftShapeProps {
2549
3272
  * The outline is 1.5 screen px, dashed 6 4 screen px, in the accent (`selection`) role by
2550
3273
  * default, with a halo; regions (`polygon`, `rect`, `ellipse`) carry the 12 % fill. A polyline
2551
3274
  * or polygon shows its placed vertices as dots and a segment on to the pointer; a polygon also
2552
- * shows, fainter, the segment that would close it. It takes no pointer events and is hidden
3275
+ * shows, fainter, the segment that would close it; with `closing` the first vertex gets a
3276
+ * ring and that segment turns solid and full strength: "click here to close". A `stroke`
3277
+ * (brush trail) is a translucent band of its own width with round caps and joins and no
3278
+ * dashes, and a `brush` is a footprint ring: a dark ring under a light one, so it reads on
3279
+ * any image. `points` may be a typed-array view that changes identity every move: the draft
3280
+ * is rebuilt in one O(n) pass per render, with no per-vertex elements. It takes no pointer events and is hidden
2553
3281
  * from assistive technology: it is transient feedback for a gesture.
2554
3282
  *
2555
3283
  * The SVG carries `data-draft` (the shape's kind).
2556
3284
  */
2557
- export declare function DraftShape({ shape, role, halo }: DraftShapeProps): import("react").JSX.Element;
3285
+ export declare function DraftShape({ shape, role, stroke, halo }: DraftShapeProps): import("react").JSX.Element;
2558
3286
  /** Props of `MarqueeRect`. */
2559
3287
  interface MarqueeRectProps {
2560
3288
  /** The band in image coordinates, or `null` when no band is being dragged. */
@@ -2636,8 +3364,12 @@ interface MaskEditorProps {
2636
3364
  /** RGBA overlay color. */
2637
3365
  color?: readonly [number, number, number, number];
2638
3366
  }
2639
- /** Render and edit a binary raster mask within the enclosing ImageStage. */
3367
+ /**
3368
+ * Render and edit a binary raster mask within the enclosing ImageStage. While editing, a
3369
+ * `DraftShape` brush footprint (a circle of the brush's diameter) follows the mouse or pen
3370
+ * pointer, and the keyboard brush while the layer has keyboard focus.
3371
+ */
2640
3372
  export declare function MaskEditor({ mask, onChange, onCommit, editable, brushRadius, mode, label, color }: MaskEditorProps): import("react").JSX.Element;
2641
3373
  //#endregion
2642
- export type { ArcPrimitive, Area, AreaHit, AreaId, AreaIndex, AreaSetItem, AreaSetProps, Box, BuiltinMarkerKind, CaliperPrimitive, CirclePrimitive, ClampOptions, Colormap, ContourEditorProps, DimensionGeometry, DimensionPrimitive, DraftShapeProps, DraftShapeSpec, Ellipse, EllipseHit, EllipseId, EllipseIndex, EllipseSetItem, EllipseSetProps, FitOptions, GridEdgeStyle, GridLayerProps, GridNode, HeatmapLayerBaseProps, HeatmapLayerProps, HeatmapPlaneProps, HeatmapRgbaProps, HitCandidate, HitId, ImageLayerProps, ImageStageProps, ImageTier, LatticeAxis, LatticeEdge, LatticeNode, MarkerShape, MarqueeRectProps, MaskEditorProps, MeasureOverlayProps, MeasurePrimitive, OverlayRole, OverlayState, Point, PointHit, PointId, PointIndex, PointIndexOptions, PointItem, PointPrimitive, PointSetItem, PointSetProps, Polyline, PolylineHit, PolylineId, PolylineIndex, PolylinePrimitive, PolylineSelectMode, PolylineSetItem, PolylineSetProps, PrimitiveCommon, Rect, RectRoiEditorProps, RoiHandle, RotatedShape, SegmentPrimitive, ShapeDragHandlers, ShapeDragOptions, ShapeEditorProps, StageButtonProps, StageContext, StageDrag, StageHandle, StageHit, StageHitLayerOptions, StageHitOptions, StageHitTestApi, StageLayer, StageLayersMenuProps, StageMouseButton, StagePointerEvent, StagePress, StageReadoutProps, StageSurfaceProps, StageToolbarDividerProps, StageToolbarProps, StageView, ValuePlane, ValueRange, View, ZoomPanCanvasProps };
3374
+ export type { ArcPrimitive, Area, AreaHit, AreaId, AreaIndex, AreaSetItem, AreaSetProps, Box, BuiltinMarkerKind, CaliperPrimitive, CirclePrimitive, ClampOptions, Colormap, CompareLayerProps, CompareMode, CompareOrientation, ContourEditorProps, Datum, DatumEditorProps, DatumPressOptions, DimensionGeometry, DimensionPrimitive, DraftShapeProps, DraftShapeSpec, Ellipse, EllipseHit, EllipseId, EllipseIndex, EllipseSetItem, EllipseSetProps, FitOptions, GridEdgeStyle, GridLayerProps, GridNode, HeatmapLayerBaseProps, HeatmapLayerProps, HeatmapPlaneProps, HeatmapRgbaProps, HitCandidate, HitId, ImageLayerBaseProps, ImageLayerProps, ImageStageProps, ImageTier, LatticeAxis, LatticeEdge, LatticeNode, MarkerShape, MarqueeRectProps, MaskEditorProps, MeasureOverlayProps, MeasurePrimitive, MoveDatumOptions, OverlayRole, OverlayState, Point, PointHit, PointId, PointIndex, PointIndexOptions, PointItem, PointPrimitive, PointSetItem, PointSetProps, Polyline, PolylineHit, PolylineId, PolylineIndex, PolylinePrimitive, PolylineSelectMode, PolylineSetHandle, PolylineSetItem, PolylineSetProps, PrimitiveCommon, Rect, RectRoiEditorHandle, RectRoiEditorProps, RoiHandle, RotatedShape, SegmentPrimitive, SegmentsPrimitive, ShapeDragHandlers, ShapeDragOptions, ShapeEditorProps, StageButtonProps, StageContext, StageDrag, StageHandle, StageHit, StageHitLayerOptions, StageHitOptions, StageHitTestApi, StageLayer, StageLayersMenuProps, StageMouseButton, StagePointerEvent, StagePress, StageReadoutProps, StageSurfaceProps, StageToolbarDividerProps, StageToolbarProps, StageView, StageViewChange, ValuePlane, ValueRange, View, ZoomPanCanvasProps };
2643
3375
  //# sourceMappingURL=index.d.ts.map