@vitavision/stage2d 0.7.2 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CSSProperties, ComponentPropsWithRef, PointerEvent, ReactNode } from "react";
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
4
  /**
@@ -256,6 +256,19 @@ interface StageContext {
256
256
  */
257
257
  panMode: boolean;
258
258
  }
259
+ /**
260
+ * The stage's controls for code outside it — an inspector's "frame this contour", a
261
+ * "fit on open" — through `ImageStage`'s `ref`. Each is a no-op until the viewport has been
262
+ * measured. Layers inside the stage use `useStage` instead.
263
+ */
264
+ interface StageHandle {
265
+ /** Put a rect (image coordinates) on screen with a margin (CSS pixels, default 24). */
266
+ frame: (rect: Rect, pad?: number) => void;
267
+ /** Fit the whole image. */
268
+ fit: () => void;
269
+ /** Set a scale about the viewport centre, or about `anchor` in client coordinates. */
270
+ zoomTo: (scale: number, anchor?: Point) => void;
271
+ }
259
272
  /**
260
273
  * The stage a layer is drawn into: its view, the coordinate conversions, and the zoom
261
274
  * controls.
@@ -292,7 +305,7 @@ interface ImageStageProps {
292
305
  /** Where the pointer is over the image, in image pixels, or `null` when it is outside. */
293
306
  onHover?: (point: Point | null) => void;
294
307
  /** A press on the background that was not a pan — how a layer hears "deselect". */
295
- onBackgroundClick?: (event: PointerEvent<HTMLDivElement>) => void;
308
+ onBackgroundClick?: (event: PointerEvent$1<HTMLDivElement>) => void;
296
309
  /** The legal scale range; see `clampView`. */
297
310
  clamp?: ClampOptions;
298
311
  /** Keyboard zoom/pan shortcuts. On by default; the stage takes focus to receive them. */
@@ -305,6 +318,14 @@ interface ImageStageProps {
305
318
  panKeys?: boolean;
306
319
  /** The viewport's accessible name. Defaults to "Image canvas". */
307
320
  label?: string;
321
+ /**
322
+ * How a `null` view opens: `"auto"` (the default) at 1:1 when the image fits the viewport
323
+ * and fit otherwise; `"fit"` always fit, for a viewer that should show the whole frame
324
+ * whatever its size.
325
+ */
326
+ initialView?: "auto" | "fit" | undefined;
327
+ /** The stage's controls for code outside it; see `StageHandle`. */
328
+ ref?: Ref<StageHandle> | undefined;
308
329
  }
309
330
  /**
310
331
  * A pannable, zoomable viewport over a stack of layers laid out at the image's own pixel
@@ -315,7 +336,115 @@ interface ImageStageProps {
315
336
  * is in progress) and `data-pan-mode` (the hand tool is on or space is held), each present
316
337
  * or absent.
317
338
  */
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;
339
+ export declare function ImageStage({ image, view, onView, children, toolbar, readout, banner, panTool, className, style, onHover, onBackgroundClick, clamp, shortcuts, panKeys, label, initialView: opening, ref }: ImageStageProps): import("react").JSX.Element;
340
+ //#endregion
341
+ //#region src/components/stage/ImageLayer.d.ts
342
+ /**
343
+ * The photograph, as a stage layer.
344
+ *
345
+ * The stage is laid out at the image's own pixel size, so the photograph is drawn at its
346
+ * natural size, with no `object-fit` letterbox for an overlay to disagree with.
347
+ *
348
+ * Two things every viewer of a large frame ends up doing by hand, done once here:
349
+ *
350
+ * - **A preview tier, then the full image.** A downscaled preview loads fast and is enough
351
+ * until it would be magnified — until the screen shows more pixels than it has. Past that
352
+ * point the full image is requested, and it stays once loaded, so zooming back out does
353
+ * not swap back. The preview stays underneath while the full image loads, so the frame
354
+ * never goes blank.
355
+ * - **Pixelated past a zoom.** Above about 4× the browser's smoothing paints detail the
356
+ * sensor never recorded; on a metrology bench the sensor's own samples are what is worth
357
+ * looking at.
358
+ */
359
+ /** A downscaled tier of the image, shown until the stage would magnify it. */
360
+ interface ImageTier {
361
+ /** Its URL. */
362
+ src: string;
363
+ /** Its width in pixels. The full image's width is the stage's own. */
364
+ width: number;
365
+ }
366
+ /** Props of `ImageLayer`. */
367
+ interface ImageLayerProps {
368
+ /** The full-resolution image's URL. */
369
+ src: string;
370
+ /** A smaller tier to show first; without one, `src` is shown from the start. */
371
+ preview?: ImageTier | undefined;
372
+ /** The image's description, for assistive technology. `""` marks it decorative. */
373
+ alt: string;
374
+ /** The zoom (CSS pixels per image pixel) from which pixels are drawn as blocks. Defaults to 4. */
375
+ pixelatedAbove?: number | undefined;
376
+ /** Called when the full image has loaded. */
377
+ onLoad?: (() => void) | undefined;
378
+ /** Called when the full image fails to load. */
379
+ onError?: (() => void) | undefined;
380
+ /** Merged onto both images with `cn`. */
381
+ className?: string | undefined;
382
+ }
383
+ /**
384
+ * The photograph at its natural size inside an `ImageStage`, with an optional preview tier
385
+ * and pixelated rendering past `pixelatedAbove`. It takes no pointer events, so presses reach
386
+ * the stage and the layers above.
387
+ *
388
+ * Each image carries `data-tier` (`preview` or `full`); the full image carries `data-loaded`
389
+ * once it has loaded, and both carry `data-pixelated` while pixelated.
390
+ */
391
+ export declare function ImageLayer({ src, preview, alt, pixelatedAbove, onLoad, onError, className }: ImageLayerProps): import("react").JSX.Element;
392
+ //#endregion
393
+ //#region src/components/stage/StageSurface.d.ts
394
+ /** What a drag does as the pointer moves and when it is released, in image coordinates. */
395
+ interface StageDrag {
396
+ /** Each move of the pointer while the button is held. */
397
+ onMove?: ((point: Point, event: PointerEvent) => void) | undefined;
398
+ /**
399
+ * Release. `moved` is whether the pointer travelled more than a few screen pixels, which
400
+ * tells a click from a drag.
401
+ */
402
+ onEnd?: ((point: Point, event: PointerEvent, moved: boolean) => void) | undefined;
403
+ /** The drag was interrupted (`pointercancel`) or the component unmounted mid-drag. */
404
+ onCancel?: (() => void) | undefined;
405
+ }
406
+ /**
407
+ * Start a drag from a press on any element inside an `ImageStage`.
408
+ *
409
+ * The press is claimed: propagation stops, so the stage does not pan. Later moves and the
410
+ * release are read from `window` and converted to image coordinates. Call it from a
411
+ * `pointerdown` handler.
412
+ *
413
+ * @returns `start(event, drag)`.
414
+ */
415
+ export declare function useStageDrag(): (event: PointerEvent$1<Element>, drag: StageDrag) => void;
416
+ /** A press on the surface, as the app's `onPress` sees it. */
417
+ interface StagePress {
418
+ /** Where, in image coordinates. */
419
+ point: Point;
420
+ /** Shift was held. */
421
+ shiftKey: boolean;
422
+ /** Alt / Option was held. */
423
+ altKey: boolean;
424
+ /** ⌘ (macOS) or Ctrl was held: the usual "add to / toggle in the selection" modifier. */
425
+ metaKey: boolean;
426
+ }
427
+ /** Props of `StageSurface`. */
428
+ interface StageSurfaceProps {
429
+ /**
430
+ * What a press means. Return a `StageDrag` to claim it (a click is a drag that never
431
+ * moved), or nothing to decline it: a declined press reaches the stage, which pans.
432
+ */
433
+ onPress: (press: StagePress) => StageDrag | null | undefined | void;
434
+ /** The cursor over the image while no drag is in flight, e.g. `crosshair` for a draw tool. */
435
+ cursor?: string | undefined;
436
+ /** Where the pointer is over the image while no drag is in flight, for hover feedback. */
437
+ onHover?: ((point: Point) => void) | undefined;
438
+ }
439
+ /**
440
+ * The stage's one full-frame press target. Put it inside an `ImageStage`, below the layers
441
+ * that have their own small targets (handles, strokes). Each press is offered to `onPress`
442
+ * unless the hand tool or a held space bar make it a pan; a declined press pans.
443
+ *
444
+ * The surface draws nothing. It carries `data-dragging` while a drag it started is in
445
+ * flight.
446
+ */
447
+ export declare function StageSurface({ onPress, cursor, onHover }: StageSurfaceProps): import("react").JSX.Element;
319
448
  //#endregion
320
449
  //#region src/components/stage/StageToolbar.d.ts
321
450
  /** Props of `StageToolbar`. */
@@ -332,6 +461,9 @@ interface StageToolbarProps {
332
461
  *
333
462
  * The bar carries `data-fit` while the view is fit; the percentage button carries
334
463
  * `data-state="open"` or `"closed"` for its menu.
464
+ *
465
+ * On a canvas narrower than 30rem, zoom out, zoom in and 100% collapse: the percentage menu
466
+ * and the `+` / `-` / `1` keys still reach them, so the app's own groups keep their room.
335
467
  */
336
468
  export declare function StageToolbar({ children, className }: StageToolbarProps): import("react").JSX.Element;
337
469
  /** Props of `StageButton`: a `<button>`'s, less the ones it sets itself. */
@@ -340,6 +472,14 @@ interface StageButtonProps extends Omit<ComponentPropsWithRef<"button">, "type"
340
472
  label: string;
341
473
  /** A toggle's state; omit for a plain action button. */
342
474
  pressed?: boolean;
475
+ /**
476
+ * A longer explanation for the tooltip, after the label. Giving `hint` or `shortcut`
477
+ * switches the native `title` for the ui `Tooltip`, which needs a `TooltipProvider` above
478
+ * the stage.
479
+ */
480
+ hint?: ReactNode;
481
+ /** The key that does the same, shown in the tooltip as a `Kbd`. Display only. */
482
+ shortcut?: string | undefined;
343
483
  /** The icon (mark it `aria-hidden`). */
344
484
  children: ReactNode;
345
485
  }
@@ -347,8 +487,40 @@ interface StageButtonProps extends Omit<ComponentPropsWithRef<"button">, "type"
347
487
  * The bar's own button shape, exported so app groups match it exactly. An icon button
348
488
  * named by `label`; a toggle when `pressed` is given, exposed as `aria-pressed` and
349
489
  * `data-state="on"` or `"off"`. Other button props (and `ref`) are passed through.
490
+ *
491
+ * Its tooltip is the native `title` (the label), or with `hint` / `shortcut` the ui
492
+ * `Tooltip`: the label, the hint, and the shortcut as a key cap.
350
493
  */
351
- export declare function StageButton({ label, pressed, className, children, ...props }: StageButtonProps): import("react").JSX.Element;
494
+ export declare function StageButton({ label, pressed, hint, shortcut, className, children, ...props }: StageButtonProps): import("react").JSX.Element;
495
+ /** One layer in a `StageLayersMenu`. */
496
+ interface StageLayer {
497
+ /** Its identity, passed back to `onVisibleChange`. */
498
+ id: string;
499
+ /** Its name in the menu. */
500
+ label: string;
501
+ /** Whether it is shown. */
502
+ visible: boolean;
503
+ /** Shown but not switchable, e.g. a layer that has nothing to draw yet. */
504
+ disabled?: boolean | undefined;
505
+ /** A key that toggles it, shown as a `Kbd`. Display only: binding it is the app's. */
506
+ shortcut?: string | undefined;
507
+ }
508
+ /** Props of `StageLayersMenu`. */
509
+ interface StageLayersMenuProps {
510
+ /** The layers, in menu order. */
511
+ layers: readonly StageLayer[];
512
+ /** Called with a layer's id and its new visibility. */
513
+ onVisibleChange: (id: string, visible: boolean) => void;
514
+ /** The trigger's accessible name and the menu's heading. Defaults to "Layers". */
515
+ label?: string | undefined;
516
+ }
517
+ /**
518
+ * A `StageButton`-shaped trigger opening a menu of layer toggles, for `StageToolbar`'s
519
+ * children. Each layer is a `menuitemcheckbox`; toggling one keeps the menu open for the
520
+ * next. The trigger shows as pressed while any layer is hidden, so a canvas missing a layer
521
+ * says so before the menu is opened.
522
+ */
523
+ export declare function StageLayersMenu({ layers, onVisibleChange, label }: StageLayersMenuProps): import("react").JSX.Element;
352
524
  /** Props of `StageToolbarDivider`. */
353
525
  interface StageToolbarDividerProps {
354
526
  /** Merged onto the divider with `cn`. */
@@ -571,9 +743,58 @@ export declare function fractionOf(value: number, range: {
571
743
  */
572
744
  export declare function fetchPlane(url: string): Promise<ValuePlane>;
573
745
  //#endregion
746
+ //#region src/components/overlayRole.d.ts
747
+ /**
748
+ * The overlay grammar's roles and states (docs/visual-language.md §5), for layers that paint
749
+ * through SVG attributes rather than class names.
750
+ */
751
+ /**
752
+ * What an overlay mark is.
753
+ * - `feature`: detected or observed (corners, edges, contours).
754
+ * - `model`: predicted (reprojections, fitted geometry).
755
+ * - `structure`: context (a board outline, grid lines).
756
+ * - `selection`: the selected item.
757
+ * - `label`: ids and text.
758
+ * - `halo`: the dark band under every stroke and label, so a mark holds on any image.
759
+ */
760
+ type OverlayRole = "feature" | "model" | "structure" | "selection" | "label" | "halo";
761
+ /**
762
+ * A mark's interaction state.
763
+ * - `default` is drawn 1.5 screen px wide.
764
+ * - `hover` is 2 px, and nothing else changes.
765
+ * - `selected` is 2.5 px with a ring in the selection colour.
766
+ * - `dimmed` is 35 % opacity.
767
+ */
768
+ type OverlayState = "default" | "hover" | "selected" | "dimmed";
769
+ /** The roles, in the order the spec lists them. */
770
+ export declare const OVERLAY_ROLES: readonly OverlayRole[];
771
+ /**
772
+ * The CSS paint for a role: a `var(--stage-…)` reference defined by `@vitavision/stage2d/styles.css`.
773
+ *
774
+ * @param role - The role.
775
+ * @returns A CSS value usable as an SVG `stroke` or `fill`.
776
+ */
777
+ export declare function overlayRole(role: OverlayRole): string;
778
+ /** Screen-pixel stroke widths for each state, before the stage's scale is applied. */
779
+ export declare const OVERLAY_STATE_WIDTH: Readonly<Record<OverlayState, number>>;
780
+ /** Opacity for each state. */
781
+ export declare const OVERLAY_STATE_OPACITY: Readonly<Record<OverlayState, number>>;
782
+ //#endregion
574
783
  //#region src/components/MeasureOverlay.d.ts
784
+ /**
785
+ * Optional fields every primitive takes. All are additive: a primitive without them draws
786
+ * exactly as before.
787
+ */
788
+ interface PrimitiveCommon {
789
+ /** An identity, written to the primitive's `data-id`, for linking a mark to a row in a list. */
790
+ id?: string | undefined;
791
+ /** Interaction state: hover thickens, selected adds a ring, dimmed fades (overlay grammar). */
792
+ state?: OverlayState | undefined;
793
+ /** An overlay role colour, instead of `tone`: `feature`, `model`, `structure`. */
794
+ role?: OverlayRole | undefined;
795
+ }
575
796
  /** A marked location: a dot, or a cross for a subpixel edge. */
576
- interface PointPrimitive {
797
+ interface PointPrimitive extends PrimitiveCommon {
577
798
  /** Discriminant. */
578
799
  kind: "point";
579
800
  /** Image x of the point. */
@@ -590,7 +811,7 @@ interface PointPrimitive {
590
811
  label?: string;
591
812
  }
592
813
  /** A straight line between two image points. */
593
- interface SegmentPrimitive {
814
+ interface SegmentPrimitive extends PrimitiveCommon {
594
815
  /** Discriminant. */
595
816
  kind: "segment";
596
817
  /** Image x of the first end. */
@@ -607,7 +828,7 @@ interface SegmentPrimitive {
607
828
  dashed?: boolean;
608
829
  }
609
830
  /** A circle — a fitted bore, a tolerance ring. */
610
- interface CirclePrimitive {
831
+ interface CirclePrimitive extends PrimitiveCommon {
611
832
  /** Discriminant. */
612
833
  kind: "circle";
613
834
  /** Image x of the centre. */
@@ -622,7 +843,7 @@ interface CirclePrimitive {
622
843
  filled?: boolean;
623
844
  }
624
845
  /** A circular arc, swept forward (clockwise on screen) from `startAngle` to `endAngle`. */
625
- interface ArcPrimitive {
846
+ interface ArcPrimitive extends PrimitiveCommon {
626
847
  /** Discriminant. */
627
848
  kind: "arc";
628
849
  /** Image x of the centre. */
@@ -639,7 +860,7 @@ interface ArcPrimitive {
639
860
  tone?: MeasureTone;
640
861
  }
641
862
  /** A caliper search box: a rotated rectangle with an arrow along its scan direction. */
642
- interface CaliperPrimitive {
863
+ interface CaliperPrimitive extends PrimitiveCommon {
643
864
  /** Discriminant. */
644
865
  kind: "caliper";
645
866
  /** Image x of the box centre. */
@@ -660,7 +881,7 @@ interface CaliperPrimitive {
660
881
  label?: string;
661
882
  }
662
883
  /** A dimension annotation: extension lines, an offset dimension line, and its value as text. */
663
- interface DimensionPrimitive {
884
+ interface DimensionPrimitive extends PrimitiveCommon {
664
885
  /** Discriminant. */
665
886
  kind: "dimension";
666
887
  /** Image x of the first measured point. */
@@ -678,8 +899,26 @@ interface DimensionPrimitive {
678
899
  /** Native pixels the dimension line sits off the measured span. Defaults to 16. */
679
900
  offset?: number;
680
901
  }
902
+ /**
903
+ * A polyline through image points, e.g. a model's contour. It replaces one `segment` per
904
+ * edge, which runs to thousands of elements for a model outline.
905
+ */
906
+ interface PolylinePrimitive extends PrimitiveCommon {
907
+ /** Discriminant. */
908
+ kind: "polyline";
909
+ /** `[x0, y0, x1, y1, …]` in image coordinates. */
910
+ points: number[];
911
+ /** Join the last point to the first. */
912
+ closed?: boolean;
913
+ /** Verdict colour. Defaults to the neutral tone. */
914
+ tone?: MeasureTone;
915
+ /** A short dash pattern. */
916
+ dashed?: boolean;
917
+ /** Text drawn just above the first point. */
918
+ label?: string;
919
+ }
681
920
  /** Anything `MeasureOverlay` can draw, discriminated by `kind`. */
682
- type MeasurePrimitive = PointPrimitive | SegmentPrimitive | CirclePrimitive | ArcPrimitive | CaliperPrimitive | DimensionPrimitive;
921
+ type MeasurePrimitive = PointPrimitive | SegmentPrimitive | CirclePrimitive | ArcPrimitive | CaliperPrimitive | DimensionPrimitive | PolylinePrimitive;
683
922
  /** Props of `MeasureOverlay`. */
684
923
  interface MeasureOverlayProps {
685
924
  /** The source image's pixel width — the overlay's `viewBox`, and every primitive's frame. */
@@ -699,15 +938,33 @@ interface MeasureOverlayProps {
699
938
  className?: string;
700
939
  }
701
940
  /**
702
- * A vector overlay of measurement primitives — points, segments, circles, arcs, caliper
703
- * boxes, dimensions — drawn in source-image pixel coordinates.
941
+ * A vector overlay of measurement primitives — points, segments, polylines, circles, arcs,
942
+ * caliper boxes, dimensions — drawn in source-image pixel coordinates.
704
943
  *
705
944
  * Place it as a layer inside `ImageStage` so it moves with the image. It is a pure function
706
945
  * of its props and decorative to assistive technology (`aria-hidden`), so a result drawn
707
946
  * only here must also be stated in text.
947
+ *
948
+ * A primitive's colour is its `role` (overlay grammar) if given, else its verdict `tone`.
949
+ * Its `state` follows the overlay grammar: `hover` thickens it, `selected` thickens it and
950
+ * rings it in the selection colour, and `dimmed` fades it. Each primitive is a `<g>` carrying
951
+ * `data-kind`, plus `data-id` and `data-state` when given.
708
952
  */
709
953
  export declare function MeasureOverlay({ nativeWidth, nativeHeight, primitives, strokeScale, className }: MeasureOverlayProps): import("react").JSX.Element;
710
954
  //#endregion
955
+ //#region src/components/stage/useScreenPx.d.ts
956
+ /**
957
+ * Screen-constant geometry for a layer inside an `ImageStage`.
958
+ */
959
+ /**
960
+ * A function from screen pixels to image pixels at the current zoom. A stroke, handle or
961
+ * label drawn `px(1.5)` wide stays 1.5 screen pixels at every zoom (the overlay grammar's
962
+ * rule).
963
+ *
964
+ * @returns `px(css)`.
965
+ */
966
+ export declare function useScreenPx(): (css: number) => number;
967
+ //#endregion
711
968
  //#region src/components/ContourEditor.d.ts
712
969
  /** An ordered, closed contour drawn in source-image pixel-center coordinates. */
713
970
  interface ContourEditorProps {
@@ -729,6 +986,273 @@ export declare function nearestContourSegment(points: Point[], point: Point): nu
729
986
  /** Edit contour vertices over an ImageStage using its shared source-image transform. */
730
987
  export declare function ContourEditor({ points, onChange, onCommit, editable, label, stroke }: ContourEditorProps): import("react").JSX.Element;
731
988
  //#endregion
989
+ //#region src/components/RectRoiEditor.d.ts
990
+ /** Props of `RectRoiEditor`. */
991
+ interface RectRoiEditorProps {
992
+ /** The region in image coordinates, or `null` for none. */
993
+ value: Rect | null;
994
+ /** Called with the region as it changes: on every move of a drag, and on each key nudge. */
995
+ onValueChange: (value: Rect) => void;
996
+ /** Called once a gesture ends (a drag released, a nudge made): the moment to save or re-run. */
997
+ onCommit?: ((value: Rect) => void) | undefined;
998
+ /** Show handles and accept moves and resizes. Defaults to `true`. */
999
+ editable?: boolean | undefined;
1000
+ /**
1001
+ * Draw a new region with a drag on the image, outside the current one. Only while the app's
1002
+ * region tool is active: in draw mode the layer claims presses that would otherwise pan.
1003
+ */
1004
+ draw?: boolean | undefined;
1005
+ /**
1006
+ * The area the region must stay in. Defaults to `{ x: 0, y: 0, width, height }` of the
1007
+ * image: a region given as a start pixel and a size.
1008
+ */
1009
+ bounds?: Rect | undefined;
1010
+ /** The smallest side, in image pixels; a smaller drawn box is a click, not a region. Defaults to 4. */
1011
+ minSize?: number | undefined;
1012
+ /** The region's accessible name. Defaults to "Region". */
1013
+ label?: string | undefined;
1014
+ /** CSS colour of the outline and handles. Defaults to the overlay `selection` role. */
1015
+ stroke?: string | undefined;
1016
+ }
1017
+ /**
1018
+ * An editable axis-aligned region inside an `ImageStage`.
1019
+ *
1020
+ * - **Handles.** The eight handles resize the region, and the interior moves it. A handle
1021
+ * dragged through the opposite edge flips the box.
1022
+ * - **Drawing.** With `draw`, a drag elsewhere on the image draws a new region.
1023
+ * - **Keyboard.** The region is focusable: arrow keys move it by one image pixel (ten with
1024
+ * Shift), and with Alt they grow or shrink it from the bottom-right corner.
1025
+ * - **Limits.** The region stays inside `bounds` and never gets smaller than `minSize`.
1026
+ * - **Rendering.** Handles and the outline are a constant size on screen at every zoom.
1027
+ * - **Panning.** A press with the hand tool, or with space held, still pans.
1028
+ *
1029
+ * The SVG carries `data-editable` and `data-drawing` (while a draw is in progress).
1030
+ */
1031
+ export declare function RectRoiEditor({ value, onValueChange, onCommit, editable, draw, bounds, minSize, label, stroke }: RectRoiEditorProps): import("react").JSX.Element;
1032
+ //#endregion
1033
+ //#region src/components/polylineIndex.d.ts
1034
+ /** A polyline's identity. */
1035
+ type PolylineId = string | number;
1036
+ /** One polyline: an id, flat image-coordinate points, and whether its last point joins its first. */
1037
+ interface Polyline {
1038
+ /** Its identity, unique in the set. */
1039
+ id: PolylineId;
1040
+ /** `[x0, y0, x1, y1, …]` in image coordinates. */
1041
+ points: ArrayLike<number>;
1042
+ /** Join the last point to the first. */
1043
+ closed?: boolean | undefined;
1044
+ }
1045
+ /**
1046
+ * An index built by `buildPolylineIndex`. Treat it as opaque and query it with
1047
+ * `nearestPolyline` and `polylinesInRect`; its layout may change.
1048
+ */
1049
+ interface PolylineIndex {
1050
+ /** The polylines, in the order given. */
1051
+ readonly items: readonly Polyline[];
1052
+ /** Grid cell side, in image pixels. */
1053
+ readonly cell: number;
1054
+ /** The grid's origin x. */
1055
+ readonly x0: number;
1056
+ /** The grid's origin y. */
1057
+ readonly y0: number;
1058
+ /** Grid columns. */
1059
+ readonly cols: number;
1060
+ /** Grid rows. */
1061
+ readonly rows: number;
1062
+ /** CSR layout: cell `c`'s entries are `starts[c] .. starts[c + 1]`. */
1063
+ readonly starts: Uint32Array;
1064
+ /** Per entry, two numbers: the polyline's index and the segment's start point index. */
1065
+ readonly segs: Uint32Array;
1066
+ }
1067
+ /** The nearest polyline to a point. */
1068
+ interface PolylineHit {
1069
+ /** Its id. */
1070
+ id: PolylineId;
1071
+ /** The closest point on it. */
1072
+ point: Point;
1073
+ /** The distance to that point. */
1074
+ distance: number;
1075
+ }
1076
+ /**
1077
+ * Index a set of polylines.
1078
+ *
1079
+ * @param items - The polylines.
1080
+ * @param cell - The grid cell side in image pixels. Defaults to 32: a few segments per cell
1081
+ * at contour densities, and a pointer's search radius spans one or two cells.
1082
+ * @returns The index.
1083
+ */
1084
+ export declare function buildPolylineIndex(items: readonly Polyline[], cell?: number): PolylineIndex;
1085
+ /**
1086
+ * The polyline nearest to `p` within `radius`, or `null`.
1087
+ *
1088
+ * @param index - The index.
1089
+ * @param p - The point, in image coordinates.
1090
+ * @param radius - The search radius, in image pixels.
1091
+ * @returns The nearest polyline, the closest point on it and the distance; ties go to the
1092
+ * earlier polyline, so the result does not depend on cell order.
1093
+ */
1094
+ export declare function nearestPolyline(index: PolylineIndex, p: Point, radius: number): PolylineHit | null;
1095
+ /**
1096
+ * The polylines with any part inside `rect`, in the order they were given.
1097
+ *
1098
+ * Any part, not any vertex: a long straight contour crossing a rubber band has no vertex
1099
+ * inside it and is still what the band was aimed at.
1100
+ *
1101
+ * @param index - The index.
1102
+ * @param rect - The band, in image coordinates.
1103
+ * @returns Their ids.
1104
+ */
1105
+ export declare function polylinesInRect(index: PolylineIndex, rect: Rect): PolylineId[];
1106
+ /**
1107
+ * A polyline as an SVG path (`M … L … Z`).
1108
+ *
1109
+ * @param points - Flat points.
1110
+ * @param closed - Whether to close it.
1111
+ * @returns The path data; `""` with no points.
1112
+ */
1113
+ export declare function polylinePath(points: ArrayLike<number>, closed?: boolean): string;
1114
+ /**
1115
+ * The bounding box of flat points.
1116
+ *
1117
+ * @param points - Flat points.
1118
+ * @returns The box, or `null` without points.
1119
+ */
1120
+ export declare function polylineBounds(points: ArrayLike<number>): Rect | null;
1121
+ //#endregion
1122
+ //#region src/components/PolylineSet.d.ts
1123
+ /** One polyline of a `PolylineSet`, with optional styling. */
1124
+ interface PolylineSetItem extends Polyline {
1125
+ /** CSS colour for this line, instead of the set's `stroke`. */
1126
+ stroke?: string | undefined;
1127
+ /** Draw dashed: a line that is present but not in play (a dropped contour). */
1128
+ dashed?: boolean | undefined;
1129
+ }
1130
+ /** How a gesture combines with the current selection. */
1131
+ type PolylineSelectMode = "replace" | "toggle" | "add";
1132
+ /** Props of `PolylineSet`. */
1133
+ interface PolylineSetProps {
1134
+ /** The polylines, in image coordinates. */
1135
+ items: readonly PolylineSetItem[];
1136
+ /** The selected ids. */
1137
+ selected?: Iterable<PolylineId> | undefined;
1138
+ /** Ids drawn at 35 % opacity, e.g. outside the current filter. They still take hover and clicks. */
1139
+ dimmed?: Iterable<PolylineId> | undefined;
1140
+ /** The hovered id, when the app controls hover (e.g. a list beside the stage hovers lines too). */
1141
+ hovered?: PolylineId | null | undefined;
1142
+ /** Called when the line under the pointer changes. */
1143
+ onHover?: ((id: PolylineId | null) => void) | undefined;
1144
+ /**
1145
+ * Called on a selection gesture.
1146
+ * - A click on a line → `[id]`, "replace".
1147
+ * - ⌘/Ctrl-click → `[id]`, "toggle".
1148
+ * - A rubber band → every line it touches, "replace", or "add" with ⌘/Ctrl held. An empty
1149
+ * band clears.
1150
+ */
1151
+ onSelect?: ((ids: PolylineId[], mode: PolylineSelectMode) => void) | undefined;
1152
+ /**
1153
+ * The sweep tool is active: a drag anywhere on the image draws a rubber band. Without it a
1154
+ * band starts only with Shift held on a line, and a press on bare image is left to the stage
1155
+ * and to the layers below.
1156
+ */
1157
+ marquee?: boolean | undefined;
1158
+ /** CSS colour of the lines. Defaults to the overlay `feature` role: they are detected lines. */
1159
+ stroke?: string | undefined;
1160
+ /** CSS colour of a selected line. Defaults to the overlay `selection` role. */
1161
+ selectionStroke?: string | undefined;
1162
+ /** How close the pointer must be to pick a line, in screen pixels (the hit band's full width). Defaults to 14. */
1163
+ hitWidth?: number | undefined;
1164
+ /** The zoom from which a hovered or selected line's points are drawn. Defaults to 3. */
1165
+ vertexScale?: number | undefined;
1166
+ /** The layer's accessible name. Defaults to "Lines". */
1167
+ label?: string | undefined;
1168
+ }
1169
+ /**
1170
+ * A selectable set of polylines inside an `ImageStage`.
1171
+ *
1172
+ * - **States**, from visual-language §5:
1173
+ * - default 1.5 screen px;
1174
+ * - hover 2 px;
1175
+ * - selected 2.5 px in `selectionStroke`;
1176
+ * - dimmed at 35 % opacity.
1177
+ * - **Halo.** Every line has a halo, so it holds on any image.
1178
+ * - **Points.** Above `vertexScale`, the points of the hovered and selected lines are drawn.
1179
+ * - **Panning.** The hand tool and a held space bar still pan.
1180
+ *
1181
+ * The SVG carries `data-hovered` (the hovered id) and `data-sweeping` while a band is drawn.
1182
+ */
1183
+ export declare function PolylineSet({ items, selected, dimmed, hovered, onHover, onSelect, marquee, stroke, selectionStroke, hitWidth, vertexScale, label }: PolylineSetProps): import("react").JSX.Element;
1184
+ //#endregion
1185
+ //#region src/components/roiEdit.d.ts
1186
+ /** A region's handle, by compass direction. */
1187
+ type RoiHandle = "nw" | "n" | "ne" | "e" | "se" | "s" | "sw" | "w";
1188
+ /** The eight handles, clockwise from the top-left corner. */
1189
+ export declare const ROI_HANDLES: readonly RoiHandle[];
1190
+ /** The CSS resize cursor for each handle, so the affordance is legible before the press. */
1191
+ export declare const ROI_HANDLE_CURSOR: Readonly<Record<RoiHandle, string>>;
1192
+ /**
1193
+ * Where a handle sits.
1194
+ *
1195
+ * @param rect - The region.
1196
+ * @param handle - The handle.
1197
+ * @returns The handle's centre.
1198
+ */
1199
+ export declare function roiHandlePoint(rect: Rect, handle: RoiHandle): Point;
1200
+ /**
1201
+ * The box spanned by two corners, with positive width and height whichever way it was
1202
+ * dragged.
1203
+ *
1204
+ * @param a - One corner.
1205
+ * @param b - The opposite corner.
1206
+ * @returns The normalised box.
1207
+ */
1208
+ export declare function rectFromCorners(a: Point, b: Point): Rect;
1209
+ /**
1210
+ * A box held inside `bounds`, and no smaller than `minSize` on either side, unless `bounds`
1211
+ * itself is smaller.
1212
+ *
1213
+ * @param rect - The box.
1214
+ * @param bounds - The area it must stay in.
1215
+ * @param minSize - The smallest side.
1216
+ * @returns The clamped box.
1217
+ */
1218
+ export declare function clampRect(rect: Rect, bounds: Rect, minSize: number): Rect;
1219
+ /**
1220
+ * Drag a handle to `to`.
1221
+ *
1222
+ * The dragged edge follows the pointer and the opposite edge stays put, which is what makes
1223
+ * a handle feel attached to the corner it is drawn on. Dragging an edge through its opposite
1224
+ * flips the box instead of clamping it to zero: a clamp leaves the pointer moving and the box
1225
+ * not, which reads as the drag having died.
1226
+ *
1227
+ * @param rect - The box before the drag.
1228
+ * @param handle - The handle being dragged.
1229
+ * @param to - The pointer, in image coordinates.
1230
+ * @param bounds - The area the box must stay in.
1231
+ * @param minSize - The smallest side.
1232
+ * @returns The resized box.
1233
+ */
1234
+ export declare function resizeRect(rect: Rect, handle: RoiHandle, to: Point, bounds: Rect, minSize: number): Rect;
1235
+ /**
1236
+ * Move the whole box, held inside `bounds` without changing its size.
1237
+ *
1238
+ * @param rect - The box.
1239
+ * @param dx - Horizontal shift.
1240
+ * @param dy - Vertical shift.
1241
+ * @param bounds - The area it must stay in.
1242
+ * @returns The moved box.
1243
+ */
1244
+ export declare function moveRect(rect: Rect, dx: number, dy: number, bounds: Rect): Rect;
1245
+ /**
1246
+ * Whether two boxes are the same, to within `epsilon`. Useful for telling whether a region
1247
+ * still matches the one a result was computed for.
1248
+ *
1249
+ * @param a - A box, or `null`.
1250
+ * @param b - A box, or `null`.
1251
+ * @param epsilon - The tolerance. Defaults to 1e-6.
1252
+ * @returns `true` for two equal boxes, or two `null`s.
1253
+ */
1254
+ export declare function sameRect(a: Rect | null, b: Rect | null, epsilon?: number): boolean;
1255
+ //#endregion
732
1256
  //#region src/components/MaskEditor.d.ts
733
1257
  /** Paint a continuous round stroke into a copied binary mask. Pixel centers are integers. */
734
1258
  export declare function paintMask(mask: Uint8Array, width: number, height: number, from: Point, to: Point, radius: number, value: 0 | 1): Uint8Array;
@@ -754,5 +1278,5 @@ interface MaskEditorProps {
754
1278
  /** Render and edit a binary raster mask within the enclosing ImageStage. */
755
1279
  export declare function MaskEditor({ mask, onChange, onCommit, editable, brushRadius, mode, label, color }: MaskEditorProps): import("react").JSX.Element;
756
1280
  //#endregion
757
- export type { ArcPrimitive, Box, CaliperPrimitive, CirclePrimitive, ClampOptions, ContourEditorProps, DimensionGeometry, DimensionPrimitive, ImageStageProps, MaskEditorProps, MeasureOverlayProps, MeasurePrimitive, Point, PointPrimitive, Rect, SegmentPrimitive, StageButtonProps, StageContext, StageReadoutProps, StageToolbarDividerProps, StageToolbarProps, StageView, ValuePlane, View, ZoomPanCanvasProps };
1281
+ export type { ArcPrimitive, Box, CaliperPrimitive, CirclePrimitive, ClampOptions, ContourEditorProps, DimensionGeometry, DimensionPrimitive, ImageLayerProps, ImageStageProps, ImageTier, MaskEditorProps, MeasureOverlayProps, MeasurePrimitive, OverlayRole, OverlayState, Point, PointPrimitive, Polyline, PolylineHit, PolylineId, PolylineIndex, PolylinePrimitive, PolylineSelectMode, PolylineSetItem, PolylineSetProps, PrimitiveCommon, Rect, RectRoiEditorProps, RoiHandle, SegmentPrimitive, StageButtonProps, StageContext, StageDrag, StageHandle, StageLayer, StageLayersMenuProps, StagePress, StageReadoutProps, StageSurfaceProps, StageToolbarDividerProps, StageToolbarProps, StageView, ValuePlane, View, ZoomPanCanvasProps };
758
1282
  //# sourceMappingURL=index.d.ts.map