@vitavision/stage2d 0.11.0 → 0.12.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.
package/dist/index.d.ts CHANGED
@@ -203,6 +203,11 @@ export declare function toScreen(view: StageView, p: Point): Point;
203
203
  export declare function toImage(view: StageView, p: Point): Point;
204
204
  /** Whether an image coordinate is inside the image, in the pixel-centre convention. */
205
205
  export declare function insideImage(p: Point, image: Box): boolean;
206
+ /**
207
+ * An image coordinate held to the image's extent, `[-0.5, w - 0.5] x [-0.5, h - 0.5]` in the
208
+ * pixel-centre convention: the point on the frame's edge nearest to `p`.
209
+ */
210
+ export declare function clampToImage(p: Point, image: Box): Point;
206
211
  /** A length in image pixels that covers `css` screen pixels at this view. */
207
212
  export declare function imageLengthFor(view: StageView, css: number): number;
208
213
  /**
@@ -214,6 +219,15 @@ export declare function imageLengthFor(view: StageView, css: number): number;
214
219
  export declare function zoomAbout(view: StageView, scale: number, anchor: Point): StageView;
215
220
  /** The scale range `clampView` and `scaleRange` allow. */
216
221
  interface ClampOptions {
222
+ /**
223
+ * How far the image may be panned. `"cover"` (the default): an axis the image overflows
224
+ * keeps the viewport covered, and an axis it does not fill is centred. `"center"`: any
225
+ * image point may be brought to the viewport's centre and no further, on both axes and at
226
+ * every scale — so a zoom about the pointer keeps the pointer's pixel under it while the
227
+ * image is still smaller than the viewport, and an edge or corner can be worked on in the
228
+ * middle of the screen.
229
+ */
230
+ panBounds?: "cover" | "center" | undefined;
217
231
  /** Lowest scale, as a multiple of fit. Defaults to `MIN_SCALE_VS_FIT`. */
218
232
  minScaleVsFit?: number;
219
233
  /** Highest scale, in CSS pixels per image pixel. Defaults to `MAX_SCALE`. */
@@ -224,10 +238,11 @@ export declare function scaleRange(box: Box, image: Box, options?: ClampOptions)
224
238
  /**
225
239
  * Keep the view legal: scale inside its range, and the image never dragged off screen.
226
240
  *
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.
241
+ * With the default `panBounds: "cover"`, an axis where the scaled image is smaller than the
242
+ * viewport is centred rather than left where a drag put it — free-floating pixels in a grey
243
+ * field is a way to be lost with no visible handle to get back — and an axis where it is
244
+ * larger is held so the viewport stays covered. With `"center"`, each axis only keeps some
245
+ * image point at or past the viewport's centre.
231
246
  */
232
247
  export declare function clampView(view: StageView, box: Box, image: Box, options?: ClampOptions): StageView;
233
248
  /**
@@ -260,6 +275,20 @@ export declare function formatScale(scale: number): string;
260
275
  type StageMouseButton = "left" | "middle" | "right";
261
276
  //#endregion
262
277
  //#region src/components/stage/ImageStage.d.ts
278
+ /** Why a view was reported through `ImageStage`'s `onView`. */
279
+ interface StageViewChange {
280
+ /**
281
+ * What moved the view:
282
+ * - `"gesture"`: a wheel zoom, a drag or touch pan, a pinch, a double-click.
283
+ * - `"key"`: a keyboard shortcut or pan key.
284
+ * - `"command"`: a call to the handle or the context (`fit`, `zoomTo`, `frame`, `setView`),
285
+ * which includes the toolbar's buttons.
286
+ * - `"measure"`: the opening view, and a resize re-anchoring the view.
287
+ */
288
+ cause: "gesture" | "key" | "command" | "measure";
289
+ /** The measured viewport, in CSS pixels, at the moment of the change. */
290
+ box: Box;
291
+ }
263
292
  /** What `useStage` returns: the transform of the enclosing `ImageStage`, and its controls. */
264
293
  interface StageContext {
265
294
  /** The view in effect — the controlled `view`, or the opening view while that is `null`. */
@@ -326,8 +355,13 @@ interface ImageStageProps {
326
355
  * view is kept on first measure, only clamped to the legal range.
327
356
  */
328
357
  view: StageView | null;
329
- /** Called with every view change: gestures, keys, toolbar, and viewport resizes. */
330
- onView: (view: StageView) => void;
358
+ /**
359
+ * Called with every view change: gestures, keys, toolbar, and viewport resizes. The second
360
+ * argument says why and carries the measured viewport; a one-argument callback ignores it.
361
+ * A `null` `view` that the stage has already measured is re-opened and reported again, with
362
+ * cause `"measure"`.
363
+ */
364
+ onView: (view: StageView, change: StageViewChange) => void;
331
365
  /** Layers, each `absolute inset-0` and sized by the stage. */
332
366
  children: ReactNode;
333
367
  /** Rendered floating over the bottom-left, outside the transform. */
@@ -364,8 +398,11 @@ interface ImageStageProps {
364
398
  style?: CSSProperties;
365
399
  /** Where the pointer is over the image, in image pixels, or `null` when it is outside. */
366
400
  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;
401
+ /**
402
+ * A press on the background that was not a pan — how a layer hears "deselect". `point` is
403
+ * where it landed, in image coordinates (the pixel-centre convention, unclamped).
404
+ */
405
+ onBackgroundClick?: (event: PointerEvent$1<HTMLDivElement>, point: Point) => void;
369
406
  /** The legal scale range; see `clampView`. */
370
407
  clamp?: ClampOptions;
371
408
  /** Keyboard zoom/pan shortcuts. On by default; the stage takes focus to receive them. */
@@ -628,6 +665,15 @@ interface StageSurfaceProps {
628
665
  * stage's double-click-to-fit does not run; leave it out to keep the fit.
629
666
  */
630
667
  onDoubleClick?: ((point: Point) => void) | undefined;
668
+ /**
669
+ * How far the surface reaches. `"image"` (the default) is the image rectangle: a press in
670
+ * the margin around the image goes to the stage, which pans. `"viewport"` covers everything
671
+ * visible, margin included, so a drawing tool can place a point on the image's border by
672
+ * pressing just outside it; every point the surface then reports (the press, a drag's moves
673
+ * and release, hover, double-click) is clamped to the image's extent, `[-0.5, w - 0.5]` by
674
+ * `[-0.5, h - 0.5]`. `StagePress.client` stays the raw pointer position.
675
+ */
676
+ extent?: "image" | "viewport" | undefined;
631
677
  }
632
678
  /**
633
679
  * The stage's one full-frame press target. Put it inside an `ImageStage`, below the layers
@@ -646,9 +692,12 @@ interface StageSurfaceProps {
646
692
  *
647
693
  * A touch gesture that sets `claimsTouch: true` is claimed like a mouse press.
648
694
  *
695
+ * With `extent="viewport"` the surface also takes presses in the margin around the image, and
696
+ * clamps every reported point to the image.
697
+ *
649
698
  * The surface draws nothing. It carries `data-dragging` while a gesture it started is in flight.
650
699
  */
651
- export declare function StageSurface({ onPress, cursor, onHover, onDoubleClick }: StageSurfaceProps): import("react").JSX.Element;
700
+ export declare function StageSurface({ onPress, cursor, onHover, onDoubleClick, extent }: StageSurfaceProps): import("react").JSX.Element;
652
701
  //#endregion
653
702
  //#region src/components/stage/StageToolbar.d.ts
654
703
  /** Props of `StageToolbar`. */
@@ -1184,11 +1233,18 @@ interface ContourEditorProps {
1184
1233
  label?: string;
1185
1234
  /** CSS stroke color. */
1186
1235
  stroke?: string;
1236
+ /**
1237
+ * The area, in image coordinates, every vertex is kept inside: a drag, a keyboard nudge and
1238
+ * an inserted vertex are clamped to it. Defaults to the pixel centres,
1239
+ * `{ x: 0, y: 0, width: w - 1, height: h - 1 }`. Pass `{ x: -0.5, y: -0.5, width: w, height: h }`
1240
+ * for polygons in the area convention, which may lie exactly on the image border.
1241
+ */
1242
+ bounds?: Rect | undefined;
1187
1243
  }
1188
1244
  /** Return the index of the closest segment, with the last vertex joined to the first. */
1189
1245
  export declare function nearestContourSegment(points: Point[], point: Point): number;
1190
1246
  /** 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;
1247
+ export declare function ContourEditor({ points, onChange, onCommit, editable, label, stroke, bounds }: ContourEditorProps): import("react").JSX.Element;
1192
1248
  //#endregion
1193
1249
  //#region src/components/RectRoiEditor.d.ts
1194
1250
  /** Props of `RectRoiEditor`. */
@@ -1207,8 +1263,9 @@ interface RectRoiEditorProps {
1207
1263
  */
1208
1264
  draw?: boolean | undefined;
1209
1265
  /**
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.
1266
+ * The area the region must stay in, in the stage's centre convention. Defaults to
1267
+ * `{ x: -0.5, y: -0.5, width, height }` of the image: its full extent, so a region that
1268
+ * fills it outlines the image edges.
1212
1269
  */
1213
1270
  bounds?: Rect | undefined;
1214
1271
  /** The smallest side, in image pixels; a smaller drawn box is a click, not a region. Defaults to 4. */
@@ -1590,6 +1647,11 @@ interface PointSetItem extends PointItem {
1590
1647
  kind?: string | undefined;
1591
1648
  /** The overlay role it is painted in. Defaults to the marker kind's role, usually `feature`. */
1592
1649
  role?: OverlayRole | undefined;
1650
+ /**
1651
+ * CSS colour of its mark (`#hex`, `var(--x)`, `color-mix(…)`; used as given). Overrides the
1652
+ * role; selection still paints in `selectionStroke`. Points sharing a colour share a batch.
1653
+ */
1654
+ color?: string | undefined;
1593
1655
  /** Its orientation in radians, clockwise from +x; read by `directed`. */
1594
1656
  angle?: number | undefined;
1595
1657
  /** A second angle in radians, for a glyph with two axes. `MarkerShape.path` gets `undefined` without it. */
@@ -1773,6 +1835,13 @@ interface AreaSetItem extends Area {
1773
1835
  role?: OverlayRole | undefined;
1774
1836
  /** Text drawn at its centre (the mean of its vertices), when the zoom leaves room. */
1775
1837
  label?: string | undefined;
1838
+ /**
1839
+ * CSS colour of its outline (`#hex`, `var(--x)`, `color-mix(…)`; used as given). Overrides
1840
+ * the role and the layer's `stroke`. Items sharing a colour share a batch.
1841
+ */
1842
+ stroke?: string | undefined;
1843
+ /** CSS colour of its fill. Defaults to its outline colour. */
1844
+ fill?: string | undefined;
1776
1845
  }
1777
1846
  /** Props of `AreaSet`. */
1778
1847
  interface AreaSetProps {
@@ -1807,6 +1876,30 @@ interface AreaSetProps {
1807
1876
  * of a marker quad reads (the overlay grammar's "corner 0 ticked"). Off by default.
1808
1877
  */
1809
1878
  firstVertexTick?: boolean | undefined;
1879
+ /** CSS colour of every outline that names none of its own, in place of its role's. */
1880
+ stroke?: string | undefined;
1881
+ /** The fill's alpha, 0 to 1. Defaults to 0.12. */
1882
+ fillOpacity?: number | undefined;
1883
+ /**
1884
+ * How a self-overlapping ring is filled. `"nonzero"` (the default) fills everything a ring
1885
+ * encloses; `"evenodd"` leaves the doubly-wound part of a self-intersecting ring open, as
1886
+ * a rasteriser would. With `"evenodd"` every region's fill is its own path (even-odd across
1887
+ * a batched path would cut a hole where two regions overlap); outlines stay batched.
1888
+ */
1889
+ fillRule?: "nonzero" | "evenodd" | undefined;
1890
+ /**
1891
+ * The paint order. `"appearance"` (the default) draws one batch per appearance, in order of
1892
+ * first appearance. `"items"` draws consecutive runs in item order, so a later region
1893
+ * covers an earlier one of another appearance (a subtract region over an add region); more
1894
+ * runs mean more paths, so use it when the order matters.
1895
+ */
1896
+ paintOrder?: "appearance" | "items" | undefined;
1897
+ /**
1898
+ * What a selected region looks like. `"selection"` (the default) paints it in the
1899
+ * selection colour, fill and outline. `"item"` keeps its own fill (and its place in the
1900
+ * paint order) and restyles only the outline.
1901
+ */
1902
+ selectionFill?: "selection" | "item" | undefined;
1810
1903
  /** Draw the dark band under every outline. On by default; off for a fast, flat layer. */
1811
1904
  halo?: boolean | undefined;
1812
1905
  /** CSS colour of selected regions. Defaults to the overlay `selection` role. */
@@ -1821,7 +1914,8 @@ interface AreaSetProps {
1821
1914
  /**
1822
1915
  * A selectable set of closed regions inside an `ImageStage`.
1823
1916
  *
1824
- * - **Rendering**: an outline and its 12 % fill, in the item's role (`feature` by default).
1917
+ * - **Rendering**: an outline and its 12 % fill, in the item's role (`feature` by default) or its own
1918
+ * `stroke` / `fill` colours (`fillOpacity`, `fillRule`, `paintOrder` and `selectionFill` tune the fill).
1825
1919
  * Rings are wound alike before they are batched, so overlapping regions never cut a hole in
1826
1920
  * each other.
1827
1921
  * - **States**, from visual-language §5: default 1.5 screen px (1 for `model` and
@@ -1835,7 +1929,7 @@ interface AreaSetProps {
1835
1929
  *
1836
1930
  * The SVG carries `data-hovered` (the hovered id).
1837
1931
  */
1838
- export declare function AreaSet({ items, role, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, labels, firstVertexTick, halo, selectionStroke, layerId, priority, label }: AreaSetProps): import("react").JSX.Element;
1932
+ 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
1933
  //#endregion
1840
1934
  //#region src/components/ellipseIndex.d.ts
1841
1935
  /** An ellipse's identity. */
@@ -2505,7 +2599,12 @@ export declare function ShapeEditor({ kind, value, onValueChange, onCommit, edit
2505
2599
  * - `point`: a position.
2506
2600
  * - `line`: a segment from `from` to `to`.
2507
2601
  * - `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.
2602
+ * the pointer as `cursor`, which the next vertex would land on. A polygon with `closing`
2603
+ * set has the pointer on its first vertex: a click there closes it, so the first vertex is
2604
+ * highlighted and the closing edge drawn solid.
2605
+ * - `stroke`: a brush trail, the flat `points` swept by a round brush of `width` image pixels
2606
+ * (never thinner than 1 screen pixel), as a translucent filled band without dashes.
2607
+ * - `brush`: a brush footprint cursor, a circle of `diameter` image pixels centred on `x`, `y`.
2509
2608
  * - `rect` and `ellipse`: two opposite corners of the axis-aligned box (the drag's start and
2510
2609
  * the pointer).
2511
2610
  */
@@ -2525,6 +2624,16 @@ type DraftShapeSpec = {
2525
2624
  kind: "polygon";
2526
2625
  points: ArrayLike<number>;
2527
2626
  cursor?: Point | undefined;
2627
+ closing?: boolean | undefined;
2628
+ } | {
2629
+ kind: "stroke";
2630
+ points: ArrayLike<number>;
2631
+ width: number;
2632
+ } | {
2633
+ kind: "brush";
2634
+ x: number;
2635
+ y: number;
2636
+ diameter: number;
2528
2637
  } | {
2529
2638
  kind: "rect";
2530
2639
  from: Point;
@@ -2540,6 +2649,8 @@ interface DraftShapeProps {
2540
2649
  shape: DraftShapeSpec | null;
2541
2650
  /** The overlay role it is drawn in. Defaults to `"selection"`, the accent. */
2542
2651
  role?: OverlayRole | undefined;
2652
+ /** A CSS colour that overrides `role`, for example `"var(--defect)"` for an eraser. */
2653
+ stroke?: string | undefined;
2543
2654
  /** Draw the dark band under the outline. On by default. */
2544
2655
  halo?: boolean | undefined;
2545
2656
  }
@@ -2549,12 +2660,17 @@ interface DraftShapeProps {
2549
2660
  * The outline is 1.5 screen px, dashed 6 4 screen px, in the accent (`selection`) role by
2550
2661
  * default, with a halo; regions (`polygon`, `rect`, `ellipse`) carry the 12 % fill. A polyline
2551
2662
  * 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
2663
+ * shows, fainter, the segment that would close it; with `closing` the first vertex gets a
2664
+ * ring and that segment turns solid and full strength: "click here to close". A `stroke`
2665
+ * (brush trail) is a translucent band of its own width with round caps and joins and no
2666
+ * dashes, and a `brush` is a footprint ring: a dark ring under a light one, so it reads on
2667
+ * any image. `points` may be a typed-array view that changes identity every move: the draft
2668
+ * is rebuilt in one O(n) pass per render, with no per-vertex elements. It takes no pointer events and is hidden
2553
2669
  * from assistive technology: it is transient feedback for a gesture.
2554
2670
  *
2555
2671
  * The SVG carries `data-draft` (the shape's kind).
2556
2672
  */
2557
- export declare function DraftShape({ shape, role, halo }: DraftShapeProps): import("react").JSX.Element;
2673
+ export declare function DraftShape({ shape, role, stroke, halo }: DraftShapeProps): import("react").JSX.Element;
2558
2674
  /** Props of `MarqueeRect`. */
2559
2675
  interface MarqueeRectProps {
2560
2676
  /** The band in image coordinates, or `null` when no band is being dragged. */
@@ -2636,8 +2752,12 @@ interface MaskEditorProps {
2636
2752
  /** RGBA overlay color. */
2637
2753
  color?: readonly [number, number, number, number];
2638
2754
  }
2639
- /** Render and edit a binary raster mask within the enclosing ImageStage. */
2755
+ /**
2756
+ * Render and edit a binary raster mask within the enclosing ImageStage. While editing, a
2757
+ * `DraftShape` brush footprint (a circle of the brush's diameter) follows the mouse or pen
2758
+ * pointer, and the keyboard brush while the layer has keyboard focus.
2759
+ */
2640
2760
  export declare function MaskEditor({ mask, onChange, onCommit, editable, brushRadius, mode, label, color }: MaskEditorProps): import("react").JSX.Element;
2641
2761
  //#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 };
2762
+ 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, StageViewChange, ValuePlane, ValueRange, View, ZoomPanCanvasProps };
2643
2763
  //# sourceMappingURL=index.d.ts.map