@vitavision/stage2d 0.9.0 → 0.10.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
@@ -1560,6 +1560,419 @@ interface PointSetProps {
1560
1560
  */
1561
1561
  export declare function PointSet({ items, kind, markers, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, labels, halo, selectionStroke, layerId, priority, label }: PointSetProps): import("react").JSX.Element;
1562
1562
  //#endregion
1563
+ //#region src/components/areaIndex.d.ts
1564
+ /** An area's identity. */
1565
+ type AreaId = string | number;
1566
+ /** One closed polygon. */
1567
+ interface Area {
1568
+ /** Its identity, unique in the set. */
1569
+ id: AreaId;
1570
+ /** `[x0, y0, x1, y1, …]` in image coordinates; the last vertex joins the first. */
1571
+ points: ArrayLike<number>;
1572
+ }
1573
+ /**
1574
+ * An index built by `buildAreaIndex`. Treat it as opaque and query it with `nearestArea` and
1575
+ * `areasInRect`; its layout may change.
1576
+ */
1577
+ interface AreaIndex {
1578
+ /** The areas, in the order given. */
1579
+ readonly items: readonly Area[];
1580
+ /** Per area, `[minX, minY, maxX, maxY]`; `NaN`s for an area with no finite vertex. */
1581
+ readonly bounds: Float64Array;
1582
+ /** Per area, its unsigned area (shoelace), used to prefer the smaller of nested areas. */
1583
+ readonly size: Float64Array;
1584
+ /** Grid cell side, in image pixels. */
1585
+ readonly cell: number;
1586
+ /** The grid's origin x. */
1587
+ readonly x0: number;
1588
+ /** The grid's origin y. */
1589
+ readonly y0: number;
1590
+ /** Grid columns. */
1591
+ readonly cols: number;
1592
+ /** Grid rows. */
1593
+ readonly rows: number;
1594
+ /** CSR layout: cell `c`'s entries are `entries[starts[c] .. starts[c + 1]]`. */
1595
+ readonly starts: Uint32Array;
1596
+ /** Area indices by cell. */
1597
+ readonly entries: Uint32Array;
1598
+ }
1599
+ /** The area `nearestArea` picked. */
1600
+ interface AreaHit {
1601
+ /** Its id. */
1602
+ id: AreaId;
1603
+ /** Its position in the array the index was built from. */
1604
+ index: number;
1605
+ /** Whether the query is inside the polygon (even-odd rule). */
1606
+ inside: boolean;
1607
+ /** The distance from the query to the polygon's outline, in image pixels. */
1608
+ distance: number;
1609
+ }
1610
+ /**
1611
+ * Whether `(x, y)` is inside the polygon, by the even-odd rule.
1612
+ *
1613
+ * @param points - Flat ring, implicitly closed.
1614
+ * @param x - The query's x.
1615
+ * @param y - The query's y.
1616
+ * @returns `false` for a ring with fewer than three vertices. A point exactly on the outline
1617
+ * may be either; `nearestArea` treats the outline separately.
1618
+ */
1619
+ export declare function pointInPolygon(points: ArrayLike<number>, x: number, y: number): boolean;
1620
+ /**
1621
+ * A polygon as an SVG path (`M … L … Z`) from its first vertex, wound the same way whatever the
1622
+ * input's winding.
1623
+ * A batched path of overlapping polygons filled with the nonzero rule would otherwise cut a
1624
+ * hole where a clockwise ring overlaps an anticlockwise one.
1625
+ *
1626
+ * @param points - Flat ring.
1627
+ * @returns Path data; `""` with no vertices.
1628
+ */
1629
+ export declare function areaPath(points: ArrayLike<number>): string;
1630
+ /**
1631
+ * The centre a label is drawn at: the mean of the vertices.
1632
+ *
1633
+ * @param points - Flat ring.
1634
+ * @returns The mean, or `null` for an empty ring.
1635
+ */
1636
+ export declare function areaCentre(points: ArrayLike<number>): Point | null;
1637
+ /**
1638
+ * Index a set of polygons.
1639
+ *
1640
+ * @param items - The polygons.
1641
+ * @param cell - The grid cell side in image pixels. Defaults to the median of the polygons'
1642
+ * larger bounding-box sides, within `[8, 256]`, doubled if the grid would be huge.
1643
+ * @returns The index.
1644
+ */
1645
+ export declare function buildAreaIndex(items: readonly Area[], cell?: number): AreaIndex;
1646
+ /**
1647
+ * The area under a point: one whose outline passes within `radius`, or else one that contains it.
1648
+ *
1649
+ * An outline is the more precise gesture, so it wins: among areas whose outline is within
1650
+ * `radius` the nearest is picked, and only without one the containing area. Ties (equal
1651
+ * distance, or several containing areas) go to the smaller area, so a quad drawn inside a
1652
+ * region is picked rather than the region, then to the earlier one. The result does not depend
1653
+ * on cell order.
1654
+ *
1655
+ * @param index - The index.
1656
+ * @param p - The query, in image coordinates.
1657
+ * @param radius - How far from an outline the query still picks it, in image pixels.
1658
+ * @returns The area, or `null`.
1659
+ */
1660
+ export declare function nearestArea(index: AreaIndex, p: Point, radius: number): AreaHit | null;
1661
+ /**
1662
+ * The areas any part of which is inside `rect`: a vertex, an edge crossing it, or the whole
1663
+ * rectangle lying inside the polygon.
1664
+ *
1665
+ * @param index - The index.
1666
+ * @param rect - The band, in image coordinates. A negative extent is read as the box between
1667
+ * its corners.
1668
+ * @returns Their ids, in the order the areas were given.
1669
+ */
1670
+ export declare function areasInRect(index: AreaIndex, rect: Rect): AreaId[];
1671
+ //#endregion
1672
+ //#region src/components/AreaSet.d.ts
1673
+ /** One region of an `AreaSet`. */
1674
+ interface AreaSetItem extends Area {
1675
+ /** The overlay role it is painted in. Defaults to the layer's `role`. */
1676
+ role?: OverlayRole | undefined;
1677
+ /** Text drawn at its centre (the mean of its vertices), when the zoom leaves room. */
1678
+ label?: string | undefined;
1679
+ }
1680
+ /** Props of `AreaSet`. */
1681
+ interface AreaSetProps {
1682
+ /** The regions, as closed rings in image coordinates. */
1683
+ items: readonly AreaSetItem[];
1684
+ /** The role of an item that names none. Defaults to `"feature"`: they are detected regions. */
1685
+ role?: OverlayRole | undefined;
1686
+ /** The hovered id, when the app controls hover (a list beside the stage hovers regions too). */
1687
+ hoveredId?: AreaId | null | undefined;
1688
+ /** Called when the region under the pointer changes. `null` when it leaves every region. */
1689
+ onHoverChange?: ((id: AreaId | null) => void) | undefined;
1690
+ /** The selected ids, drawn at 2.5 px in the selection colour. */
1691
+ selectedIds?: Iterable<AreaId> | undefined;
1692
+ /**
1693
+ * Ids drawn at 35 % opacity, as a set or a predicate (outside the current filter, say).
1694
+ * They still take hover and presses. Pass a stable value: a new one re-batches the layer.
1695
+ */
1696
+ dimmed?: Iterable<AreaId> | ((id: AreaId) => boolean) | undefined;
1697
+ /**
1698
+ * A press landed on a region. Setting it makes the layer claim presses inside its regions,
1699
+ * so the stage does not pan from them. The event is the `pointerdown` (the `pointerup` for
1700
+ * a touch tap), so `useShapeDrag` can start a drag from it.
1701
+ *
1702
+ * A mounted `StageSurface` hears a press first; there, ask `useStageHitTest` what is
1703
+ * under it instead.
1704
+ */
1705
+ onItemPress?: ((id: AreaId, event: StagePointerEvent) => void) | undefined;
1706
+ /** Show the items' `label`s where the zoom leaves room for them. On by default. */
1707
+ labels?: boolean | undefined;
1708
+ /**
1709
+ * Tick the first vertex: a short line from vertex 0 towards the centre, so the orientation
1710
+ * of a marker quad reads (the overlay grammar's "corner 0 ticked"). Off by default.
1711
+ */
1712
+ firstVertexTick?: boolean | undefined;
1713
+ /** Draw the dark band under every outline. On by default; off for a fast, flat layer. */
1714
+ halo?: boolean | undefined;
1715
+ /** CSS colour of selected regions. Defaults to the overlay `selection` role. */
1716
+ selectionStroke?: string | undefined;
1717
+ /** The id hit-tests report for this layer. Defaults to a generated one. */
1718
+ layerId?: string | undefined;
1719
+ /** Rank against other layers in hit-tests. Defaults to `STAGE_HIT_PRIORITY.area`. */
1720
+ priority?: number | undefined;
1721
+ /** The layer's accessible name. Defaults to "Areas". */
1722
+ label?: string | undefined;
1723
+ }
1724
+ /**
1725
+ * A selectable set of closed regions inside an `ImageStage`.
1726
+ *
1727
+ * - **Rendering**: an outline and its 12 % fill, in the item's role (`feature` by default).
1728
+ * Rings are wound alike before they are batched, so overlapping regions never cut a hole in
1729
+ * each other.
1730
+ * - **States**, from visual-language §5: default 1.5 screen px (1 for `model` and
1731
+ * `structure`), hover 2, selected 2.5 in the selection colour, dimmed at 35 % opacity. Every
1732
+ * outline has a halo. A region has no ring: its outline at 2.5 px is the mark.
1733
+ * - **Labels** at the centre of a region, only where regions are at least 24 screen px apart,
1734
+ * at most 200 at a time. The hovered and selected regions always carry theirs.
1735
+ * - **Picking** goes through the stage's hit registry: a press within the pointer's tolerance of
1736
+ * an outline picks that region, else the smallest region containing the point. `onHoverChange`
1737
+ * and `onItemPress` here, and `useStageHitTest` for an app that arbitrates between layers.
1738
+ *
1739
+ * The SVG carries `data-hovered` (the hovered id).
1740
+ */
1741
+ export declare function AreaSet({ items, role, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, labels, firstVertexTick, halo, selectionStroke, layerId, priority, label }: AreaSetProps): import("react").JSX.Element;
1742
+ //#endregion
1743
+ //#region src/components/GridLayer.d.ts
1744
+ /** One node of a `GridLayer`: a point with its lattice index. */
1745
+ interface GridNode extends PointSetItem {
1746
+ /** The lattice index along the first axis. */
1747
+ i: number;
1748
+ /** The lattice index along the second axis. */
1749
+ j: number;
1750
+ }
1751
+ /** How the edges along one lattice axis are drawn. */
1752
+ interface GridEdgeStyle {
1753
+ /** The overlay role of the edges. Defaults to `"structure"`: they are context. */
1754
+ role?: OverlayRole | undefined;
1755
+ /** Draw them dashed (4 3 screen px), so the two axes differ by more than colour. */
1756
+ dashed?: boolean | undefined;
1757
+ /** Draw them at all. Defaults to `true`. */
1758
+ visible?: boolean | undefined;
1759
+ }
1760
+ /** Props of `GridLayer`. */
1761
+ interface GridLayerProps {
1762
+ /** The nodes, in image coordinates, with their lattice indices. Gaps are allowed. */
1763
+ nodes: readonly GridNode[];
1764
+ /**
1765
+ * How edges are drawn, by axis: `i` joins `(i, j)` to `(i + 1, j)` (the rows, when `i`
1766
+ * counts columns), `j` joins `(i, j)` to `(i, j + 1)`. Both are solid `structure` by default.
1767
+ */
1768
+ edges?: {
1769
+ i?: GridEdgeStyle | undefined;
1770
+ j?: GridEdgeStyle | undefined;
1771
+ } | undefined;
1772
+ /** The marker kind of a node that names none. Defaults to `"plus"`: a corner. */
1773
+ kind?: string | undefined;
1774
+ /** More marker kinds, or replacements for built-in ones, by name; see `PointSet`. */
1775
+ markers?: Readonly<Record<string, MarkerShape>> | undefined;
1776
+ /**
1777
+ * Label every node without a `label` of its own with its lattice index, `i,j`, where the
1778
+ * zoom leaves room (nodes at least 24 screen px apart). Off by default.
1779
+ */
1780
+ indexLabels?: boolean | undefined;
1781
+ /** Show the nodes' labels where the zoom leaves room for them. On by default. */
1782
+ labels?: boolean | undefined;
1783
+ /** The hovered node id, when the app controls hover. */
1784
+ hoveredId?: PointId | null | undefined;
1785
+ /** Called when the node under the pointer changes. `null` when it leaves every node. */
1786
+ onHoverChange?: ((id: PointId | null) => void) | undefined;
1787
+ /** The selected node ids, drawn at 2.5 px in the selection colour with a ring. */
1788
+ selectedIds?: Iterable<PointId> | undefined;
1789
+ /**
1790
+ * Node ids drawn at 35 % opacity, as a set or a predicate. An edge is dimmed when both its
1791
+ * nodes are. Pass a stable value: a new one re-batches the layer.
1792
+ */
1793
+ dimmed?: Iterable<PointId> | ((id: PointId) => boolean) | undefined;
1794
+ /** A press landed on a node; see `PointSet`. Setting it makes the layer claim presses on its nodes. */
1795
+ onItemPress?: ((id: PointId, event: StagePointerEvent) => void) | undefined;
1796
+ /** Draw the dark band under every mark. On by default; off for a fast, flat layer. */
1797
+ halo?: boolean | undefined;
1798
+ /** CSS colour of selected nodes and rings. Defaults to the overlay `selection` role. */
1799
+ selectionStroke?: string | undefined;
1800
+ /** The id hit-tests report for the nodes. Defaults to a generated one. */
1801
+ layerId?: string | undefined;
1802
+ /** Rank against other layers in hit-tests. Defaults to `STAGE_HIT_PRIORITY.point`. */
1803
+ priority?: number | undefined;
1804
+ /** The layer's accessible name. Defaults to "Grid". */
1805
+ label?: string | undefined;
1806
+ }
1807
+ /**
1808
+ * A detected lattice inside an `ImageStage`.
1809
+ *
1810
+ * - **Nodes** are a `PointSet`: `plus` markers by default, picked through the point index at
1811
+ * point priority, with `onHoverChange`, `onItemPress`, selection (with ring) and dimming.
1812
+ * - **Edges** join `(i, j)` to `(i + 1, j)` and to `(i, j + 1)` where both nodes exist
1813
+ * (`latticeEdges`), in one path per axis and dimming, below the nodes. They are `structure`
1814
+ * role by default, 1 screen px with a halo; `edges` restyles each axis.
1815
+ * - **Labels** are the nodes' own `label`s, or with `indexLabels` their `i,j`, only where nodes
1816
+ * are at least 24 screen px apart.
1817
+ *
1818
+ * The edges' SVG carries `data-edges`; the nodes' is the `PointSet`'s.
1819
+ */
1820
+ export declare function GridLayer({ nodes, edges, kind, markers, indexLabels, labels, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, halo, selectionStroke, layerId, priority, label }: GridLayerProps): import("react").JSX.Element;
1821
+ //#endregion
1822
+ //#region src/components/gridEdges.d.ts
1823
+ /**
1824
+ * The edges of a detected lattice: which nodes are neighbours.
1825
+ *
1826
+ * A calibration detector returns its corners with integer lattice indices `(i, j)` and gaps
1827
+ * where a corner was not found. The edges are not data: node `(i, j)` is joined to
1828
+ * `(i + 1, j)` and to `(i, j + 1)` when both exist. This module computes them in O(n) with a
1829
+ * hash of the indices. It imports neither React nor the DOM.
1830
+ */
1831
+ /** What `latticeEdges` reads from each node. */
1832
+ interface LatticeNode {
1833
+ /** The lattice index along the first axis. A non-integer index is not part of the lattice. */
1834
+ i: number;
1835
+ /** The lattice index along the second axis. A non-integer index is not part of the lattice. */
1836
+ j: number;
1837
+ }
1838
+ /** The lattice axis an edge runs along: `"i"` joins `(i, j)` to `(i + 1, j)`, `"j"` joins `(i, j)` to `(i, j + 1)`. */
1839
+ type LatticeAxis = "i" | "j";
1840
+ /** An edge between two neighbouring nodes. */
1841
+ interface LatticeEdge {
1842
+ /** Position in the node array of the end with the lower index along `axis`. */
1843
+ a: number;
1844
+ /** Position in the node array of the end with the higher index along `axis`. */
1845
+ b: number;
1846
+ /** The axis it runs along. */
1847
+ axis: LatticeAxis;
1848
+ }
1849
+ /**
1850
+ * The edges of a lattice: every pair of nodes whose indices differ by one along exactly one
1851
+ * axis.
1852
+ *
1853
+ * @param nodes - The nodes, in any order, with gaps allowed. A node whose index is not an
1854
+ * integer of magnitude below 2²⁵ takes no edges, and when two nodes share an index the
1855
+ * first one is the lattice's node there.
1856
+ * @returns The edges, ordered by the position of `a`, then `"i"` before `"j"`.
1857
+ */
1858
+ export declare function latticeEdges(nodes: ArrayLike<LatticeNode>): LatticeEdge[];
1859
+ //#endregion
1860
+ //#region src/components/heatmapRaster.d.ts
1861
+ /**
1862
+ * A sequential colour map: a position in `[0, 1]` to an `[r, g, b]` colour, each channel
1863
+ * 0 to 255. `@vitavision/charts`' `colormapRgb(name, t)` is one: `(t) => colormapRgb("viridis", t)`.
1864
+ */
1865
+ type Colormap = (t: number) => readonly [number, number, number];
1866
+ /** A range of values mapped onto the colour map: `low` to its start, `high` to its end. */
1867
+ interface ValueRange {
1868
+ /** The value drawn in the map's first colour. */
1869
+ low: number;
1870
+ /** The value drawn in the map's last colour. */
1871
+ high: number;
1872
+ }
1873
+ /**
1874
+ * The extent of a plane's finite values.
1875
+ *
1876
+ * @param plane - The plane.
1877
+ * @param channel - Which of its channels. Defaults to the first.
1878
+ * @returns `{ low, high }`, or `null` when the channel is missing or has no finite value.
1879
+ */
1880
+ export declare function planeRange(plane: ValuePlane, channel?: number): ValueRange | null;
1881
+ /**
1882
+ * Colour a plane through a colour map.
1883
+ *
1884
+ * Opaque where the value is finite; transparent where it is `NaN` or infinite (an uncovered
1885
+ * pixel, as in `valueAt`). Values outside `range` take the map's end colours. A flat range
1886
+ * (`high <= low`) draws every pixel in the map's first colour.
1887
+ *
1888
+ * @param plane - The plane.
1889
+ * @param colormap - The colour map; sampled at 256 positions.
1890
+ * @param range - What the map spans. Defaults to the extent of the channel's finite values.
1891
+ * @param channel - Which channel to draw. Defaults to the first.
1892
+ * @returns `width · height` RGBA pixels, row-major; all transparent for a missing channel.
1893
+ */
1894
+ export declare function rasterizePlane(plane: ValuePlane, colormap: Colormap, range?: ValueRange, channel?: number): Uint8ClampedArray;
1895
+ //#endregion
1896
+ //#region src/components/HeatmapLayer.d.ts
1897
+ /** What every `HeatmapLayer` takes. */
1898
+ interface HeatmapLayerBaseProps {
1899
+ /** How opaque the heatmap is, 0 to 1. Defaults to `1`. */
1900
+ opacity?: number | undefined;
1901
+ /** Draw it. Defaults to `true`. While `false` nothing is rasterised. */
1902
+ visible?: boolean | undefined;
1903
+ /**
1904
+ * Where the raster is placed, in image coordinates: `x` and `y` the top-left edge of its
1905
+ * first pixel's footprint (`-0.5, -0.5` is the image's own top-left corner), `width` and `height`
1906
+ * the extent it is stretched over. Defaults to the whole image, so a raster of any
1907
+ * resolution covers it 1:1 in position.
1908
+ */
1909
+ rect?: Rect | undefined;
1910
+ /** The zoom (CSS pixels per heatmap pixel) from which heatmap pixels are drawn as blocks. Defaults to 4. */
1911
+ pixelatedAbove?: number | undefined;
1912
+ /** A description for assistive technology. Defaults to `""`: decorative, as the legend carries the meaning. */
1913
+ alt?: string | undefined;
1914
+ /** Called once the raster is on screen (and again for each new one). */
1915
+ onReady?: (() => void) | undefined;
1916
+ /** Called when the raster could not be made: a canvas that could not be allocated, or an `rgba` buffer too short for its size. */
1917
+ onError?: (() => void) | undefined;
1918
+ /** Merged onto the image with `cn`. */
1919
+ className?: string | undefined;
1920
+ }
1921
+ /** A heatmap from pixels that are already coloured. */
1922
+ interface HeatmapRgbaProps extends HeatmapLayerBaseProps {
1923
+ /** Row-major RGBA, `width · height · 4` bytes. A `Uint8Array` is read in place, not copied. */
1924
+ rgba: Uint8ClampedArray | Uint8Array;
1925
+ /** The raster's width in pixels. */
1926
+ width: number;
1927
+ /** The raster's height in pixels. */
1928
+ height: number;
1929
+ /** Not used with `rgba`. */
1930
+ plane?: undefined;
1931
+ /** Not used with `rgba`. */
1932
+ colormap?: undefined;
1933
+ /** Not used with `rgba`. */
1934
+ range?: undefined;
1935
+ /** Not used with `rgba`. */
1936
+ channel?: undefined;
1937
+ }
1938
+ /** A heatmap from a scalar field and a colour map. */
1939
+ interface HeatmapPlaneProps extends HeatmapLayerBaseProps {
1940
+ /** The field, as decoded by `decodePlane`. */
1941
+ plane: ValuePlane;
1942
+ /**
1943
+ * The colour map. `NaN` pixels stay transparent. Pass a stable function: a new one
1944
+ * re-rasterises the heatmap. `@vitavision/charts`' `(t) => colormapRgb("viridis", t)` is one.
1945
+ */
1946
+ colormap: Colormap;
1947
+ /** What the map spans. Defaults to the extent of the channel's finite values. */
1948
+ range?: ValueRange | undefined;
1949
+ /** Which channel of the plane to draw. Defaults to the first. */
1950
+ channel?: number | undefined;
1951
+ /** Not used with `plane`. */
1952
+ rgba?: undefined;
1953
+ /** Not used with `plane`. */
1954
+ width?: undefined;
1955
+ /** Not used with `plane`. */
1956
+ height?: undefined;
1957
+ }
1958
+ /** Props of `HeatmapLayer`: pre-coloured `rgba` pixels, or a `plane` with a `colormap`. */
1959
+ type HeatmapLayerProps = HeatmapRgbaProps | HeatmapPlaneProps;
1960
+ /**
1961
+ * A heatmap inside an `ImageStage`: a scalar field coloured through a colour map, or an RGBA
1962
+ * buffer, placed over the image (default) or any rectangle of it.
1963
+ *
1964
+ * - **Rasterised in an effect**, once per change of its data, into an offscreen canvas and an
1965
+ * object URL that is revoked when replaced and on unmount. Server rendering draws nothing.
1966
+ * - **Pixelated** from 4 CSS pixels per heatmap pixel, like `ImageLayer`, so the cells of a
1967
+ * coarse map are not smoothed into a blur.
1968
+ * - **Stacking:** it is drawn where it is placed among the stage's children. Before the
1969
+ * overlays it sits under them; the image layer goes before it.
1970
+ * - **Input:** none. It takes no pointer events, so presses reach the layers above and the stage.
1971
+ *
1972
+ * The image carries `data-heatmap`, `data-pixelated` while pixelated, and `data-ready`.
1973
+ */
1974
+ export declare function HeatmapLayer(props: HeatmapLayerProps): import("react").JSX.Element | null;
1975
+ //#endregion
1563
1976
  //#region src/components/roiEdit.d.ts
1564
1977
  /** A region's handle, by compass direction. */
1565
1978
  type RoiHandle = "nw" | "n" | "ne" | "e" | "se" | "s" | "sw" | "w";
@@ -1631,6 +2044,295 @@ export declare function moveRect(rect: Rect, dx: number, dy: number, bounds: Rec
1631
2044
  */
1632
2045
  export declare function sameRect(a: Rect | null, b: Rect | null, epsilon?: number): boolean;
1633
2046
  //#endregion
2047
+ //#region src/components/shapeEdit.d.ts
2048
+ /** A rotated rectangle, or the ellipse inscribed in one. */
2049
+ interface RotatedShape {
2050
+ /** Centre x, in image coordinates. */
2051
+ cx: number;
2052
+ /** Centre y, in image coordinates. */
2053
+ cy: number;
2054
+ /** Extent along the shape's own x axis: a rectangle's width, an ellipse's full axis `2·rx`. */
2055
+ width: number;
2056
+ /** Extent along the shape's own y axis: a rectangle's height, an ellipse's full axis `2·ry`. */
2057
+ height: number;
2058
+ /** Radians, clockwise on screen: the turn from the image's x axis to the shape's own. */
2059
+ rotation: number;
2060
+ }
2061
+ /**
2062
+ * A point of image space in the shape's own frame: origin at its centre, axes along its sides.
2063
+ *
2064
+ * @param shape - The shape.
2065
+ * @param p - A point in image coordinates.
2066
+ * @returns The point relative to the shape.
2067
+ */
2068
+ export declare function toShapeFrame(shape: RotatedShape, p: Point): Point;
2069
+ /**
2070
+ * A point of the shape's own frame in image space; the inverse of `toShapeFrame`.
2071
+ *
2072
+ * @param shape - The shape.
2073
+ * @param p - A point relative to the shape.
2074
+ * @returns The point in image coordinates.
2075
+ */
2076
+ export declare function fromShapeFrame(shape: RotatedShape, p: Point): Point;
2077
+ /**
2078
+ * Where a handle sits: a corner or the middle of a side, turned with the shape.
2079
+ *
2080
+ * @param shape - The shape.
2081
+ * @param handle - The handle, by compass direction in the shape's own frame.
2082
+ * @returns The handle's centre, in image coordinates.
2083
+ */
2084
+ export declare function shapeHandlePoint(shape: RotatedShape, handle: RoiHandle): Point;
2085
+ /**
2086
+ * Where the rotation handle sits: beyond the middle of the top side, along the shape's own
2087
+ * up direction.
2088
+ *
2089
+ * @param shape - The shape.
2090
+ * @param distance - How far past the top side, in image pixels. For a screen-constant handle,
2091
+ * pass `useScreenPx()(css)`.
2092
+ * @returns The handle's centre, in image coordinates.
2093
+ */
2094
+ export declare function rotationHandlePoint(shape: RotatedShape, distance: number): Point;
2095
+ /**
2096
+ * Drag a handle to `to`.
2097
+ *
2098
+ * The dragged side or corner follows the pointer in the shape's own frame and the opposite
2099
+ * side or corner stays where it is in the image, which is what makes a handle feel attached.
2100
+ * The shape does not flip when dragged through the opposite side: it stops at `minSize`.
2101
+ *
2102
+ * @param shape - The shape before the drag.
2103
+ * @param handle - The handle being dragged.
2104
+ * @param to - The pointer, in image coordinates.
2105
+ * @param minSize - The smallest extent on either axis, in image pixels.
2106
+ * @returns The resized shape: the same rotation, and the opposite side or corner unmoved.
2107
+ */
2108
+ export declare function resizeShape(shape: RotatedShape, handle: RoiHandle, to: Point, minSize: number): RotatedShape;
2109
+ /**
2110
+ * Turn the shape about its centre so that its rotation handle points at `to`.
2111
+ *
2112
+ * @param shape - The shape before the drag.
2113
+ * @param to - The pointer, in image coordinates.
2114
+ * @param snap - Round the rotation to a multiple of this many radians (Shift while dragging
2115
+ * rounds to 15°). Defaults to no rounding.
2116
+ * @returns The rotated shape: the same centre and size, `rotation` in `(-π, π]`.
2117
+ */
2118
+ export declare function rotateShape(shape: RotatedShape, to: Point, snap?: number): RotatedShape;
2119
+ /**
2120
+ * Move the shape.
2121
+ *
2122
+ * @param shape - The shape.
2123
+ * @param dx - Horizontal shift, in image pixels.
2124
+ * @param dy - Vertical shift, in image pixels.
2125
+ * @returns The moved shape.
2126
+ */
2127
+ export declare function moveShape(shape: RotatedShape, dx: number, dy: number): RotatedShape;
2128
+ /**
2129
+ * An angle as the equivalent one in `(-π, π]`.
2130
+ *
2131
+ * @param angle - Radians.
2132
+ * @returns The angle in `(-π, π]`.
2133
+ */
2134
+ export declare function normalizeAngle(angle: number): number;
2135
+ /**
2136
+ * The resize cursor for a handle of a rotated shape: the nearest of the four CSS resize
2137
+ * cursors to the handle's direction on screen.
2138
+ *
2139
+ * @param handle - The handle.
2140
+ * @param rotation - The shape's rotation, in radians.
2141
+ * @returns A CSS `cursor` value.
2142
+ */
2143
+ export declare function shapeHandleCursor(handle: RoiHandle, rotation: number): string;
2144
+ /**
2145
+ * The shape for a rectangle given as an origin corner, a size and a rotation about that
2146
+ * corner: Konva's `Rect` (`x`, `y`, `width`, `height`, `rotation` in degrees), for one.
2147
+ *
2148
+ * @param corner - The corner the rotation is about, in image coordinates.
2149
+ * @param width - Extent along the rotated x axis.
2150
+ * @param height - Extent along the rotated y axis.
2151
+ * @param rotation - Radians, clockwise on screen.
2152
+ * @returns The same rectangle as a `RotatedShape`.
2153
+ */
2154
+ export declare function shapeFromCorner(corner: Point, width: number, height: number, rotation: number): RotatedShape;
2155
+ /**
2156
+ * The top-left corner of a shape in its own frame, the origin Konva rotates a `Rect` about;
2157
+ * the inverse of `shapeFromCorner`.
2158
+ *
2159
+ * @param shape - The shape.
2160
+ * @returns The corner, in image coordinates.
2161
+ */
2162
+ export declare function shapeCorner(shape: RotatedShape): Point;
2163
+ /**
2164
+ * Whether two shapes are the same, to within `epsilon` on every field (rotations compared modulo a turn).
2165
+ *
2166
+ * @param a - A shape, or `null`.
2167
+ * @param b - A shape, or `null`.
2168
+ * @param epsilon - The tolerance. Defaults to 1e-6.
2169
+ * @returns `true` for two equal shapes, or two `null`s.
2170
+ */
2171
+ export declare function sameShape(a: RotatedShape | null, b: RotatedShape | null, epsilon?: number): boolean;
2172
+ //#endregion
2173
+ //#region src/components/ShapeEditor.d.ts
2174
+ /** Props of `ShapeEditor`. */
2175
+ interface ShapeEditorProps {
2176
+ /** `"rect"` draws a rotated rectangle, `"ellipse"` the ellipse inscribed in it. */
2177
+ kind: "rect" | "ellipse";
2178
+ /**
2179
+ * The shape in image coordinates, or `null` for none. `rotation` is in **radians, clockwise
2180
+ * on screen**, so a value in degrees (Konva's, say) is `degrees * Math.PI / 180`. An
2181
+ * ellipse's `width` and `height` are its full axes, `2 · radiusX` and `2 · radiusY`.
2182
+ */
2183
+ value: RotatedShape | null;
2184
+ /** Called with the shape as it changes: on every move of a drag, and on each key nudge. */
2185
+ onValueChange: (value: RotatedShape) => void;
2186
+ /** Called once a gesture ends (a drag released, a nudge made): the moment to save or re-run. */
2187
+ onCommit?: ((value: RotatedShape) => void) | undefined;
2188
+ /** Show handles and accept moves, resizes and rotations. Defaults to `true`. */
2189
+ editable?: boolean | undefined;
2190
+ /** Show the rotation handle and accept `[` / `]`. Defaults to `true`; off for a shape that must stay level. */
2191
+ rotatable?: boolean | undefined;
2192
+ /** The smallest extent on either axis, in image pixels. Defaults to 5. */
2193
+ minSize?: number | undefined;
2194
+ /** The shape's accessible name. Defaults to "Shape". */
2195
+ label?: string | undefined;
2196
+ /** CSS colour of the outline and handles. Defaults to the overlay `selection` role. */
2197
+ stroke?: string | undefined;
2198
+ }
2199
+ /**
2200
+ * An editable rotated rectangle or ellipse inside an `ImageStage`.
2201
+ *
2202
+ * - **Handles.** Eight handles resize the shape in its own frame: the dragged side follows the
2203
+ * pointer and the opposite side stays where it is, whatever the rotation. A shape stops at
2204
+ * `minSize` rather than flipping. The interior moves it.
2205
+ * - **Rotation.** The handle past the top side turns the shape about its centre; hold Shift to
2206
+ * round to 15°.
2207
+ * - **Keyboard.** The shape is focusable: arrow keys move it by one image pixel (ten with Shift),
2208
+ * with Alt they grow or shrink it along its own axes from its top-left corner, and `[` / `]`
2209
+ * turn it by 1° (15° with Shift).
2210
+ * - **Rendering.** Handles and the outline are a constant size on screen at every zoom; an
2211
+ * ellipse also shows its bounding box, where the handles are.
2212
+ * - **Panning.** A press with the hand tool, or with space held, still pans.
2213
+ *
2214
+ * It does not draw a new shape (`DraftShape` previews one while the app's tool does), and does
2215
+ * not keep the shape inside the image.
2216
+ *
2217
+ * The SVG carries `data-editable`; the outline carries `data-shape`.
2218
+ */
2219
+ export declare function ShapeEditor({ kind, value, onValueChange, onCommit, editable, rotatable, minSize, label, stroke }: ShapeEditorProps): import("react").JSX.Element;
2220
+ //#endregion
2221
+ //#region src/components/DraftShape.d.ts
2222
+ /**
2223
+ * The shape being drawn.
2224
+ * - `point`: a position.
2225
+ * - `line`: a segment from `from` to `to`.
2226
+ * - `polyline` and `polygon`: the vertices placed so far, flat `[x0, y0, x1, y1, …]`, and
2227
+ * the pointer as `cursor`, which the next vertex would land on.
2228
+ * - `rect` and `ellipse`: two opposite corners of the axis-aligned box (the drag's start and
2229
+ * the pointer).
2230
+ */
2231
+ type DraftShapeSpec = {
2232
+ kind: "point";
2233
+ x: number;
2234
+ y: number;
2235
+ } | {
2236
+ kind: "line";
2237
+ from: Point;
2238
+ to: Point;
2239
+ } | {
2240
+ kind: "polyline";
2241
+ points: ArrayLike<number>;
2242
+ cursor?: Point | undefined;
2243
+ } | {
2244
+ kind: "polygon";
2245
+ points: ArrayLike<number>;
2246
+ cursor?: Point | undefined;
2247
+ } | {
2248
+ kind: "rect";
2249
+ from: Point;
2250
+ to: Point;
2251
+ } | {
2252
+ kind: "ellipse";
2253
+ from: Point;
2254
+ to: Point;
2255
+ };
2256
+ /** Props of `DraftShape`. */
2257
+ interface DraftShapeProps {
2258
+ /** The shape so far, or `null` when nothing is being drawn. */
2259
+ shape: DraftShapeSpec | null;
2260
+ /** The overlay role it is drawn in. Defaults to `"selection"`, the accent. */
2261
+ role?: OverlayRole | undefined;
2262
+ /** Draw the dark band under the outline. On by default. */
2263
+ halo?: boolean | undefined;
2264
+ }
2265
+ /**
2266
+ * A dashed preview of a shape being drawn, inside an `ImageStage`.
2267
+ *
2268
+ * The outline is 1.5 screen px, dashed 6 4 screen px, in the accent (`selection`) role by
2269
+ * default, with a halo; regions (`polygon`, `rect`, `ellipse`) carry the 12 % fill. A polyline
2270
+ * or polygon shows its placed vertices as dots and a segment on to the pointer; a polygon also
2271
+ * shows, fainter, the segment that would close it. It takes no pointer events and is hidden
2272
+ * from assistive technology: it is transient feedback for a gesture.
2273
+ *
2274
+ * The SVG carries `data-draft` (the shape's kind).
2275
+ */
2276
+ export declare function DraftShape({ shape, role, halo }: DraftShapeProps): import("react").JSX.Element;
2277
+ /** Props of `MarqueeRect`. */
2278
+ interface MarqueeRectProps {
2279
+ /** The band in image coordinates, or `null` when no band is being dragged. */
2280
+ rect: Rect | null;
2281
+ /** CSS colour of the band. Defaults to the overlay `selection` role. */
2282
+ stroke?: string | undefined;
2283
+ }
2284
+ /**
2285
+ * The rubber band of a multi-select, inside an `ImageStage`: the 12 % fill and a 1 screen px
2286
+ * outline in the selection colour, the same as `PolylineSet`'s own band. Feed it the box
2287
+ * between the press and the pointer from `StageSurface`, and the box to `pointsInRect`,
2288
+ * `polylinesInRect` or `areasInRect` at the release. It takes no pointer events.
2289
+ *
2290
+ * The SVG carries `data-marquee`.
2291
+ */
2292
+ export declare function MarqueeRect({ rect, stroke }: MarqueeRectProps): import("react").JSX.Element;
2293
+ //#endregion
2294
+ //#region src/components/useShapeDrag.d.ts
2295
+ /** What a shape drag does as the pointer moves and when it ends. Displacements are total, from the press. */
2296
+ interface ShapeDragHandlers {
2297
+ /**
2298
+ * Each move of the pointer once it has left the click slop: how far it is from where the
2299
+ * press landed, in image pixels. Draw the shape shifted by it.
2300
+ */
2301
+ onMove?: ((delta: Point, event: PointerEvent) => void) | undefined;
2302
+ /**
2303
+ * The release. `moved` is whether the pointer ever left the click slop; when it did not,
2304
+ * `delta` is `{ x: 0, y: 0 }` and the press was a click. Commit the shape shifted by `delta`.
2305
+ */
2306
+ onEnd?: ((delta: Point, moved: boolean, event: PointerEvent) => void) | undefined;
2307
+ /** The drag was interrupted (`pointercancel`) or the component unmounted mid-drag: drop the preview. */
2308
+ onCancel?: (() => void) | undefined;
2309
+ }
2310
+ /** Options of the function `useShapeDrag` returns. */
2311
+ interface ShapeDragOptions {
2312
+ /** How far the pointer may travel before the press is a drag, in screen pixels. Defaults to 3. */
2313
+ slop?: number | undefined;
2314
+ }
2315
+ /**
2316
+ * Start moving a shape from a press, inside an `ImageStage`.
2317
+ *
2318
+ * Returns `start(event, handlers, options?)`. Call it from `onItemPress` of a layer with the
2319
+ * press event: the press is claimed, so the stage does not pan, and the pointer is followed on
2320
+ * `window` until it is released, whether or not it leaves the canvas. A touch tap reaches
2321
+ * `onItemPress` on release, so there is nothing to follow: it ends at once as a click
2322
+ * (`moved` false). Move a shape on touch with `ShapeEditor`'s handles or the app's own mode.
2323
+ *
2324
+ * @returns `start`.
2325
+ */
2326
+ export declare function useShapeDrag(): (event: StagePointerEvent, handlers: ShapeDragHandlers, options?: ShapeDragOptions) => void;
2327
+ /**
2328
+ * Move flat points by a displacement.
2329
+ *
2330
+ * @param points - `[x0, y0, x1, y1, …]`.
2331
+ * @param delta - The displacement, in the points' units.
2332
+ * @returns A new array, `points` shifted.
2333
+ */
2334
+ export declare function translatePoints(points: ArrayLike<number>, delta: Point): number[];
2335
+ //#endregion
1634
2336
  //#region src/components/MaskEditor.d.ts
1635
2337
  /** Paint a continuous round stroke into a copied binary mask. Pixel centers are integers. */
1636
2338
  export declare function paintMask(mask: Uint8Array, width: number, height: number, from: Point, to: Point, radius: number, value: 0 | 1): Uint8Array;
@@ -1656,5 +2358,5 @@ interface MaskEditorProps {
1656
2358
  /** Render and edit a binary raster mask within the enclosing ImageStage. */
1657
2359
  export declare function MaskEditor({ mask, onChange, onCommit, editable, brushRadius, mode, label, color }: MaskEditorProps): import("react").JSX.Element;
1658
2360
  //#endregion
1659
- export type { ArcPrimitive, Box, BuiltinMarkerKind, CaliperPrimitive, CirclePrimitive, ClampOptions, ContourEditorProps, DimensionGeometry, DimensionPrimitive, HitCandidate, HitId, ImageLayerProps, ImageStageProps, ImageTier, MarkerShape, 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, SegmentPrimitive, StageButtonProps, StageContext, StageDrag, StageHandle, StageHit, StageHitLayerOptions, StageHitOptions, StageHitTestApi, StageLayer, StageLayersMenuProps, StageMouseButton, StagePointerEvent, StagePress, StageReadoutProps, StageSurfaceProps, StageToolbarDividerProps, StageToolbarProps, StageView, ValuePlane, View, ZoomPanCanvasProps };
2361
+ export type { ArcPrimitive, Area, AreaHit, AreaId, AreaIndex, AreaSetItem, AreaSetProps, Box, BuiltinMarkerKind, CaliperPrimitive, CirclePrimitive, ClampOptions, Colormap, ContourEditorProps, DimensionGeometry, DimensionPrimitive, DraftShapeProps, DraftShapeSpec, 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 };
1660
2362
  //# sourceMappingURL=index.d.ts.map