@vitavision/stage2d 0.9.0 → 0.11.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/README.md +40 -4
- package/dist/index.d.ts +1001 -18
- package/dist/index.js +2643 -124
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AreaSet.tsx +312 -0
- package/src/components/DraftShape.tsx +175 -0
- package/src/components/EllipseSet.tsx +292 -0
- package/src/components/GridLayer.tsx +209 -0
- package/src/components/HeatmapLayer.tsx +211 -0
- package/src/components/PointSet.tsx +16 -39
- package/src/components/PolylineSet.tsx +56 -15
- package/src/components/ShapeEditor.tsx +370 -0
- package/src/components/areaIndex.ts +364 -0
- package/src/components/ellipseIndex.ts +279 -0
- package/src/components/gridEdges.ts +70 -0
- package/src/components/heatmapRaster.ts +84 -0
- package/src/components/labelLod.ts +90 -0
- package/src/components/markerShapes.ts +3 -1
- package/src/components/polylineIndex.ts +4 -3
- package/src/components/shapeEdit.ts +298 -0
- package/src/components/stage/ImageStage.tsx +61 -20
- package/src/components/stage/StageSurface.tsx +80 -9
- package/src/components/stage/gesture.ts +15 -0
- package/src/components/stage/touchWatch.ts +85 -0
- package/src/components/stage/useCoarsePointer.ts +30 -0
- package/src/components/stage/view.ts +55 -14
- package/src/components/useShapeDrag.ts +104 -0
- package/src/index.ts +79 -0
package/dist/index.d.ts
CHANGED
|
@@ -148,14 +148,50 @@ export declare const MAX_SCALE = 32;
|
|
|
148
148
|
* the frame edge or checking that a model's points do not run off the image.
|
|
149
149
|
*/
|
|
150
150
|
export declare const MIN_SCALE_VS_FIT = 0.25;
|
|
151
|
-
/**
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
151
|
+
/** How `fitScale` and `fitView` treat the margin and a small image. */
|
|
152
|
+
interface FitOptions {
|
|
153
|
+
/**
|
|
154
|
+
* A margin on each side of the fitted image, in CSS pixels. Defaults to 0: the image fills
|
|
155
|
+
* the box edge to edge. A margin that leaves no room (the box is smaller than twice the
|
|
156
|
+
* padding) is ignored.
|
|
157
|
+
*/
|
|
158
|
+
padding?: number | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* Whether fit may magnify a small image past 1:1. On by default; `false` caps the fit scale
|
|
161
|
+
* at 1, so a small image opens at its own size, centred.
|
|
162
|
+
*/
|
|
163
|
+
upscale?: boolean | undefined;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The scale at which the whole image is just visible inside `box`.
|
|
167
|
+
*
|
|
168
|
+
* @param box - The viewport, in CSS pixels.
|
|
169
|
+
* @param image - The image, in image pixels.
|
|
170
|
+
* @param options - A margin and an upscale cap; the defaults fill the box edge to edge.
|
|
171
|
+
* @returns CSS pixels per image pixel; `1` for a degenerate box or image.
|
|
172
|
+
*/
|
|
173
|
+
export declare function fitScale(box: Box, image: Box, options?: FitOptions): number;
|
|
174
|
+
/**
|
|
175
|
+
* Fit, centred: the view a viewer opens at and the one `0` returns to.
|
|
176
|
+
*
|
|
177
|
+
* @param box - The viewport, in CSS pixels.
|
|
178
|
+
* @param image - The image, in image pixels.
|
|
179
|
+
* @param options - A margin and an upscale cap; see `FitOptions`.
|
|
180
|
+
* @returns The view.
|
|
181
|
+
*/
|
|
182
|
+
export declare function fitView(box: Box, image: Box, options?: FitOptions): StageView;
|
|
183
|
+
/**
|
|
184
|
+
* The whole image visible at 1:1 if it fits, otherwise fit — a sane opening view.
|
|
185
|
+
*
|
|
186
|
+
* @param box - The viewport, in CSS pixels.
|
|
187
|
+
* @param image - The image, in image pixels.
|
|
188
|
+
* @param options - Only `padding` matters here (the image must fit inside the margin to open
|
|
189
|
+
* at 1:1, and "otherwise fit" is the padded fit); it never magnifies, so `upscale` is moot.
|
|
190
|
+
* @returns The view.
|
|
191
|
+
*/
|
|
192
|
+
export declare function initialView(box: Box, image: Box, options?: FitOptions): StageView;
|
|
193
|
+
/** Whether `view` is (indistinguishably) the fit view for this box, image and `FitOptions`. */
|
|
194
|
+
export declare function isFit(view: StageView, box: Box, image: Box, options?: FitOptions): boolean;
|
|
159
195
|
/** Where the **centre of** image pixel `p` lands in the viewport. */
|
|
160
196
|
export declare function toScreen(view: StageView, p: Point): Point;
|
|
161
197
|
/**
|
|
@@ -210,7 +246,7 @@ export declare function frameRect(box: Box, image: Box, rect: Rect, pad?: number
|
|
|
210
246
|
* that was *fit* re-fits instead, because fit is a relationship to the viewport rather than
|
|
211
247
|
* a particular pair of numbers.
|
|
212
248
|
*/
|
|
213
|
-
export declare function preserveCenter(view: StageView, from: Box, to: Box, image: Box, options?: ClampOptions): StageView;
|
|
249
|
+
export declare function preserveCenter(view: StageView, from: Box, to: Box, image: Box, options?: ClampOptions, fit?: FitOptions): StageView;
|
|
214
250
|
/**
|
|
215
251
|
* The next scale up or down the ladder from `scale`, so the readout lands on a round
|
|
216
252
|
* percentage rather than wherever a multiplier happened to leave it.
|
|
@@ -344,10 +380,17 @@ interface ImageStageProps {
|
|
|
344
380
|
label?: string;
|
|
345
381
|
/**
|
|
346
382
|
* How a `null` view opens: `"auto"` (the default) at 1:1 when the image fits the viewport
|
|
347
|
-
* and fit otherwise; `"fit"` always fit, for a viewer that should show the whole frame
|
|
383
|
+
* (inside the `fit` margin) and fit otherwise; `"fit"` always fit, for a viewer that should show the whole frame
|
|
348
384
|
* whatever its size.
|
|
349
385
|
*/
|
|
350
386
|
initialView?: "auto" | "fit" | undefined;
|
|
387
|
+
/**
|
|
388
|
+
* The margin and upscale cap of every fit: `initialView="fit"`, the handle's and the
|
|
389
|
+
* context's `fit()`, the `0` key, the double-click toggle, the toolbar's Fit button, and
|
|
390
|
+
* `isFit` / `data-fit`. Defaults to filling the viewport edge to edge, upscaling freely.
|
|
391
|
+
* Each field is read by value, so an inline object does not re-fit the view.
|
|
392
|
+
*/
|
|
393
|
+
fit?: FitOptions | undefined;
|
|
351
394
|
/** The stage's controls for code outside it; see `StageHandle`. */
|
|
352
395
|
ref?: Ref<StageHandle> | undefined;
|
|
353
396
|
}
|
|
@@ -356,11 +399,15 @@ interface ImageStageProps {
|
|
|
356
399
|
* size, so an overlay drawn in image coordinates stays registered with the photograph at
|
|
357
400
|
* any zoom and window size. Layers read the transform through `useStage`.
|
|
358
401
|
*
|
|
402
|
+
* The transformed box (`[data-stage]`) carries `will-change: transform` and `data-moving` while
|
|
403
|
+
* the view changes and for 150 ms after, so a pan stays on the compositor and the layer
|
|
404
|
+
* re-rasterises sharp once the view settles.
|
|
405
|
+
*
|
|
359
406
|
* State is exposed on the viewport as `data-fit` (the view is fit), `data-panning` (a drag
|
|
360
407
|
* is in progress) and `data-pan-mode` (the hand tool is on or space is held), each present
|
|
361
408
|
* or absent.
|
|
362
409
|
*/
|
|
363
|
-
export declare function ImageStage({ image, view, onView, children, toolbar, readout, banner, panTool, panButton, doubleClickFit, touchPan, className, style, onHover, onBackgroundClick, clamp, shortcuts, panKeys, label, initialView: opening, ref }: ImageStageProps): import("react").JSX.Element;
|
|
410
|
+
export declare function ImageStage({ image, view, onView, children, toolbar, readout, banner, panTool, panButton, doubleClickFit, touchPan, className, style, onHover, onBackgroundClick, clamp, shortcuts, panKeys, label, initialView: opening, fit: fitOptions, ref }: ImageStageProps): import("react").JSX.Element;
|
|
364
411
|
//#endregion
|
|
365
412
|
//#region src/components/stage/hitTest.d.ts
|
|
366
413
|
/** What a layer is picked as, and so how it ranks against the layers around it. */
|
|
@@ -526,6 +573,13 @@ interface StageDrag {
|
|
|
526
573
|
onEnd?: ((point: Point, event: PointerEvent, moved: boolean) => void) | undefined;
|
|
527
574
|
/** The drag was interrupted (`pointercancel`) or the component unmounted mid-drag. */
|
|
528
575
|
onCancel?: (() => void) | undefined;
|
|
576
|
+
/**
|
|
577
|
+
* Claim a touch that starts this gesture, as a mouse press is claimed: the stage neither
|
|
578
|
+
* pans nor pinches from it. Without it a touch is only watched (see `StageSurface`), so
|
|
579
|
+
* return `true` for a gesture a finger must own, such as moving a selected shape. Ignored for
|
|
580
|
+
* a mouse or pen.
|
|
581
|
+
*/
|
|
582
|
+
claimsTouch?: boolean | undefined;
|
|
529
583
|
}
|
|
530
584
|
/**
|
|
531
585
|
* Start a drag from a press on any element inside an `ImageStage`.
|
|
@@ -541,6 +595,12 @@ export declare function useStageDrag(): (event: PointerEvent$1<Element>, drag: S
|
|
|
541
595
|
interface StagePress {
|
|
542
596
|
/** Where, in image coordinates. */
|
|
543
597
|
point: Point;
|
|
598
|
+
/** Where, in client coordinates, for anchoring a tooltip or a menu. */
|
|
599
|
+
client: Point;
|
|
600
|
+
/** The press is a touch: act on its release (see `StageSurface`), and expect a fingertip's tolerance. */
|
|
601
|
+
touch: boolean;
|
|
602
|
+
/** The hit-test tolerance for this pointer, in screen pixels: 12 for a touch, 6 otherwise. Pass it to `useStageHitTest`. */
|
|
603
|
+
radius: number;
|
|
544
604
|
/** Shift was held. */
|
|
545
605
|
shiftKey: boolean;
|
|
546
606
|
/** Alt / Option was held. */
|
|
@@ -553,22 +613,42 @@ interface StageSurfaceProps {
|
|
|
553
613
|
/**
|
|
554
614
|
* What a press means. Return a `StageDrag` to claim it (a click is a drag that never
|
|
555
615
|
* moved), or nothing to decline it: a declined press reaches the stage, which pans.
|
|
616
|
+
*
|
|
617
|
+
* **For a touch, act in `onEnd` when `moved` is `false` (a tap), not here.** The press may
|
|
618
|
+
* become a pan or the first finger of a pinch, so nothing should happen until the finger
|
|
619
|
+
* lifts. Return `claimsTouch: true` for a gesture the finger must own.
|
|
556
620
|
*/
|
|
557
621
|
onPress: (press: StagePress) => StageDrag | null | undefined | void;
|
|
558
622
|
/** The cursor over the image while no drag is in flight, e.g. `crosshair` for a draw tool. */
|
|
559
623
|
cursor?: string | undefined;
|
|
560
|
-
/** Where the
|
|
624
|
+
/** Where the mouse is over the image while no drag is in flight, for hover feedback. Not called for a touch. */
|
|
561
625
|
onHover?: ((point: Point) => void) | undefined;
|
|
626
|
+
/**
|
|
627
|
+
* A double click or double tap on the surface. When given, the surface handles it and the
|
|
628
|
+
* stage's double-click-to-fit does not run; leave it out to keep the fit.
|
|
629
|
+
*/
|
|
630
|
+
onDoubleClick?: ((point: Point) => void) | undefined;
|
|
562
631
|
}
|
|
563
632
|
/**
|
|
564
633
|
* The stage's one full-frame press target. Put it inside an `ImageStage`, below the layers
|
|
565
634
|
* that have their own small targets (handles, strokes). Each press is offered to `onPress`
|
|
566
635
|
* unless the hand tool or a held space bar make it a pan; a declined press pans.
|
|
567
636
|
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
637
|
+
* **Mouse and pen.** Only the left button comes here. The press is claimed and followed on
|
|
638
|
+
* `window`, so the stage does not pan from it.
|
|
639
|
+
*
|
|
640
|
+
* **Touch.** A touch is only *watched* unless its `StageDrag` sets `claimsTouch`: the surface
|
|
641
|
+
* neither stops the press nor captures the pointer, so the stage still pans (one-finger mode)
|
|
642
|
+
* and a second finger still pinches. The drag then sees:
|
|
643
|
+
* - `onMove`, only once the finger has left the tap slop;
|
|
644
|
+
* - `onEnd(point, event, moved)` on release, with `moved` `false` for a tap;
|
|
645
|
+
* - `onCancel` on `pointercancel`, or when a second finger lands (a pinch).
|
|
646
|
+
*
|
|
647
|
+
* A touch gesture that sets `claimsTouch: true` is claimed like a mouse press.
|
|
648
|
+
*
|
|
649
|
+
* The surface draws nothing. It carries `data-dragging` while a gesture it started is in flight.
|
|
570
650
|
*/
|
|
571
|
-
export declare function StageSurface({ onPress, cursor, onHover }: StageSurfaceProps): import("react").JSX.Element;
|
|
651
|
+
export declare function StageSurface({ onPress, cursor, onHover, onDoubleClick }: StageSurfaceProps): import("react").JSX.Element;
|
|
572
652
|
//#endregion
|
|
573
653
|
//#region src/components/stage/StageToolbar.d.ts
|
|
574
654
|
/** Props of `StageToolbar`. */
|
|
@@ -1290,6 +1370,17 @@ interface PolylineSetProps {
|
|
|
1290
1370
|
* and to the layers below.
|
|
1291
1371
|
*/
|
|
1292
1372
|
marquee?: boolean | undefined;
|
|
1373
|
+
/**
|
|
1374
|
+
* Whether the layer takes presses and hover. Defaults to `true` when any of `onItemPress`,
|
|
1375
|
+
* `onSelect`, `onHover`, `onHoverChange` or `marquee` is given. When `false` the layer
|
|
1376
|
+
* renders no press target at all: a press on a line falls through to whatever is below (a
|
|
1377
|
+
* draw tool's `StageSurface`, say), while `useStageHitTest` still finds the lines. Set it
|
|
1378
|
+
* `false` while a tool other than selection is active.
|
|
1379
|
+
*
|
|
1380
|
+
* A touch on an interactive layer is not claimed: the stage still pans and pinches, and the
|
|
1381
|
+
* line is selected when the finger lifts after a tap.
|
|
1382
|
+
*/
|
|
1383
|
+
interactive?: boolean | undefined;
|
|
1293
1384
|
/** CSS colour of the lines. Defaults to the overlay `feature` role: they are detected lines. */
|
|
1294
1385
|
stroke?: string | undefined;
|
|
1295
1386
|
/** CSS colour of a selected line. Defaults to the overlay `selection` role. */
|
|
@@ -1316,10 +1407,12 @@ interface PolylineSetProps {
|
|
|
1316
1407
|
* - **Halo.** Every line has a halo, so it holds on any image.
|
|
1317
1408
|
* - **Points.** Above `vertexScale`, the points of the hovered and selected lines are drawn.
|
|
1318
1409
|
* - **Panning.** The hand tool and a held space bar still pan.
|
|
1410
|
+
* - **Tools.** Without a handler (or with `interactive={false}`) the layer takes no presses
|
|
1411
|
+
* and only answers `useStageHitTest`, so a draw tool's surface below receives them.
|
|
1319
1412
|
*
|
|
1320
1413
|
* The SVG carries `data-hovered` (the hovered id) and `data-sweeping` while a band is drawn.
|
|
1321
1414
|
*/
|
|
1322
|
-
export declare function PolylineSet({ items, selected, dimmed, hovered, onHover, onHoverChange, onItemPress, onSelect, marquee, stroke, selectionStroke, hitWidth, vertexScale, label, layerId, priority }: PolylineSetProps): import("react").JSX.Element;
|
|
1415
|
+
export declare function PolylineSet({ items, selected, dimmed, hovered, onHover, onHoverChange, onItemPress, onSelect, marquee, interactive, stroke, selectionStroke, hitWidth, vertexScale, label, layerId, priority }: PolylineSetProps): import("react").JSX.Element;
|
|
1323
1416
|
//#endregion
|
|
1324
1417
|
//#region src/components/markerShapes.d.ts
|
|
1325
1418
|
/** One kind of marker. */
|
|
@@ -1342,9 +1435,11 @@ interface MarkerShape {
|
|
|
1342
1435
|
* @param y - Centre y, in image coordinates.
|
|
1343
1436
|
* @param unit - Image pixels per screen pixel.
|
|
1344
1437
|
* @param angle - The item's orientation in radians, `0` when it has none.
|
|
1438
|
+
* @param angle2 - The item's second angle in radians, `undefined` when it has none. Most
|
|
1439
|
+
* shapes ignore it; a glyph with two axes (a corner's two edge directions) reads it.
|
|
1345
1440
|
* @returns Path commands, absolute at the start (`M x y …`) and self-contained.
|
|
1346
1441
|
*/
|
|
1347
|
-
path: (x: number, y: number, unit: number, angle: number) => string;
|
|
1442
|
+
path: (x: number, y: number, unit: number, angle: number, angle2?: number) => string;
|
|
1348
1443
|
}
|
|
1349
1444
|
/**
|
|
1350
1445
|
* A circle as two arcs, centred at `(x, y)`.
|
|
@@ -1497,6 +1592,8 @@ interface PointSetItem extends PointItem {
|
|
|
1497
1592
|
role?: OverlayRole | undefined;
|
|
1498
1593
|
/** Its orientation in radians, clockwise from +x; read by `directed`. */
|
|
1499
1594
|
angle?: number | undefined;
|
|
1595
|
+
/** A second angle in radians, for a glyph with two axes. `MarkerShape.path` gets `undefined` without it. */
|
|
1596
|
+
angle2?: number | undefined;
|
|
1500
1597
|
/** Text drawn beside it, when the zoom leaves room (points at least 24 screen px apart). */
|
|
1501
1598
|
label?: string | undefined;
|
|
1502
1599
|
}
|
|
@@ -1560,6 +1657,593 @@ interface PointSetProps {
|
|
|
1560
1657
|
*/
|
|
1561
1658
|
export declare function PointSet({ items, kind, markers, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, labels, halo, selectionStroke, layerId, priority, label }: PointSetProps): import("react").JSX.Element;
|
|
1562
1659
|
//#endregion
|
|
1660
|
+
//#region src/components/areaIndex.d.ts
|
|
1661
|
+
/** An area's identity. */
|
|
1662
|
+
type AreaId = string | number;
|
|
1663
|
+
/** One closed polygon. */
|
|
1664
|
+
interface Area {
|
|
1665
|
+
/** Its identity, unique in the set. */
|
|
1666
|
+
id: AreaId;
|
|
1667
|
+
/** `[x0, y0, x1, y1, …]` in image coordinates; the last vertex joins the first. */
|
|
1668
|
+
points: ArrayLike<number>;
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
* An index built by `buildAreaIndex`. Treat it as opaque and query it with `nearestArea` and
|
|
1672
|
+
* `areasInRect`; its layout may change.
|
|
1673
|
+
*/
|
|
1674
|
+
interface AreaIndex {
|
|
1675
|
+
/** The areas, in the order given. */
|
|
1676
|
+
readonly items: readonly Area[];
|
|
1677
|
+
/** Per area, `[minX, minY, maxX, maxY]`; `NaN`s for an area with no finite vertex. */
|
|
1678
|
+
readonly bounds: Float64Array;
|
|
1679
|
+
/** Per area, its unsigned area (shoelace), used to prefer the smaller of nested areas. */
|
|
1680
|
+
readonly size: Float64Array;
|
|
1681
|
+
/** Grid cell side, in image pixels. */
|
|
1682
|
+
readonly cell: number;
|
|
1683
|
+
/** The grid's origin x. */
|
|
1684
|
+
readonly x0: number;
|
|
1685
|
+
/** The grid's origin y. */
|
|
1686
|
+
readonly y0: number;
|
|
1687
|
+
/** Grid columns. */
|
|
1688
|
+
readonly cols: number;
|
|
1689
|
+
/** Grid rows. */
|
|
1690
|
+
readonly rows: number;
|
|
1691
|
+
/** CSR layout: cell `c`'s entries are `entries[starts[c] .. starts[c + 1]]`. */
|
|
1692
|
+
readonly starts: Uint32Array;
|
|
1693
|
+
/** Area indices by cell. */
|
|
1694
|
+
readonly entries: Uint32Array;
|
|
1695
|
+
}
|
|
1696
|
+
/** The area `nearestArea` picked. */
|
|
1697
|
+
interface AreaHit {
|
|
1698
|
+
/** Its id. */
|
|
1699
|
+
id: AreaId;
|
|
1700
|
+
/** Its position in the array the index was built from. */
|
|
1701
|
+
index: number;
|
|
1702
|
+
/** Whether the query is inside the polygon (even-odd rule). */
|
|
1703
|
+
inside: boolean;
|
|
1704
|
+
/** The distance from the query to the polygon's outline, in image pixels. */
|
|
1705
|
+
distance: number;
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Whether `(x, y)` is inside the polygon, by the even-odd rule.
|
|
1709
|
+
*
|
|
1710
|
+
* @param points - Flat ring, implicitly closed.
|
|
1711
|
+
* @param x - The query's x.
|
|
1712
|
+
* @param y - The query's y.
|
|
1713
|
+
* @returns `false` for a ring with fewer than three vertices. A point exactly on the outline
|
|
1714
|
+
* may be either; `nearestArea` treats the outline separately.
|
|
1715
|
+
*/
|
|
1716
|
+
export declare function pointInPolygon(points: ArrayLike<number>, x: number, y: number): boolean;
|
|
1717
|
+
/**
|
|
1718
|
+
* A polygon as an SVG path (`M … L … Z`) from its first vertex, wound the same way whatever the
|
|
1719
|
+
* input's winding.
|
|
1720
|
+
* A batched path of overlapping polygons filled with the nonzero rule would otherwise cut a
|
|
1721
|
+
* hole where a clockwise ring overlaps an anticlockwise one.
|
|
1722
|
+
*
|
|
1723
|
+
* @param points - Flat ring.
|
|
1724
|
+
* @returns Path data; `""` with no vertices.
|
|
1725
|
+
*/
|
|
1726
|
+
export declare function areaPath(points: ArrayLike<number>): string;
|
|
1727
|
+
/**
|
|
1728
|
+
* The centre a label is drawn at: the mean of the vertices.
|
|
1729
|
+
*
|
|
1730
|
+
* @param points - Flat ring.
|
|
1731
|
+
* @returns The mean, or `null` for an empty ring.
|
|
1732
|
+
*/
|
|
1733
|
+
export declare function areaCentre(points: ArrayLike<number>): Point | null;
|
|
1734
|
+
/**
|
|
1735
|
+
* Index a set of polygons.
|
|
1736
|
+
*
|
|
1737
|
+
* @param items - The polygons.
|
|
1738
|
+
* @param cell - The grid cell side in image pixels. Defaults to the median of the polygons'
|
|
1739
|
+
* larger bounding-box sides, within `[8, 256]`, doubled if the grid would be huge.
|
|
1740
|
+
* @returns The index.
|
|
1741
|
+
*/
|
|
1742
|
+
export declare function buildAreaIndex(items: readonly Area[], cell?: number): AreaIndex;
|
|
1743
|
+
/**
|
|
1744
|
+
* The area under a point: one whose outline passes within `radius`, or else one that contains it.
|
|
1745
|
+
*
|
|
1746
|
+
* An outline is the more precise gesture, so it wins: among areas whose outline is within
|
|
1747
|
+
* `radius` the nearest is picked, and only without one the containing area. Ties (equal
|
|
1748
|
+
* distance, or several containing areas) go to the smaller area, so a quad drawn inside a
|
|
1749
|
+
* region is picked rather than the region, then to the earlier one. The result does not depend
|
|
1750
|
+
* on cell order.
|
|
1751
|
+
*
|
|
1752
|
+
* @param index - The index.
|
|
1753
|
+
* @param p - The query, in image coordinates.
|
|
1754
|
+
* @param radius - How far from an outline the query still picks it, in image pixels.
|
|
1755
|
+
* @returns The area, or `null`.
|
|
1756
|
+
*/
|
|
1757
|
+
export declare function nearestArea(index: AreaIndex, p: Point, radius: number): AreaHit | null;
|
|
1758
|
+
/**
|
|
1759
|
+
* The areas any part of which is inside `rect`: a vertex, an edge crossing it, or the whole
|
|
1760
|
+
* rectangle lying inside the polygon.
|
|
1761
|
+
*
|
|
1762
|
+
* @param index - The index.
|
|
1763
|
+
* @param rect - The band, in image coordinates. A negative extent is read as the box between
|
|
1764
|
+
* its corners.
|
|
1765
|
+
* @returns Their ids, in the order the areas were given.
|
|
1766
|
+
*/
|
|
1767
|
+
export declare function areasInRect(index: AreaIndex, rect: Rect): AreaId[];
|
|
1768
|
+
//#endregion
|
|
1769
|
+
//#region src/components/AreaSet.d.ts
|
|
1770
|
+
/** One region of an `AreaSet`. */
|
|
1771
|
+
interface AreaSetItem extends Area {
|
|
1772
|
+
/** The overlay role it is painted in. Defaults to the layer's `role`. */
|
|
1773
|
+
role?: OverlayRole | undefined;
|
|
1774
|
+
/** Text drawn at its centre (the mean of its vertices), when the zoom leaves room. */
|
|
1775
|
+
label?: string | undefined;
|
|
1776
|
+
}
|
|
1777
|
+
/** Props of `AreaSet`. */
|
|
1778
|
+
interface AreaSetProps {
|
|
1779
|
+
/** The regions, as closed rings in image coordinates. */
|
|
1780
|
+
items: readonly AreaSetItem[];
|
|
1781
|
+
/** The role of an item that names none. Defaults to `"feature"`: they are detected regions. */
|
|
1782
|
+
role?: OverlayRole | undefined;
|
|
1783
|
+
/** The hovered id, when the app controls hover (a list beside the stage hovers regions too). */
|
|
1784
|
+
hoveredId?: AreaId | null | undefined;
|
|
1785
|
+
/** Called when the region under the pointer changes. `null` when it leaves every region. */
|
|
1786
|
+
onHoverChange?: ((id: AreaId | null) => void) | undefined;
|
|
1787
|
+
/** The selected ids, drawn at 2.5 px in the selection colour. */
|
|
1788
|
+
selectedIds?: Iterable<AreaId> | undefined;
|
|
1789
|
+
/**
|
|
1790
|
+
* Ids drawn at 35 % opacity, as a set or a predicate (outside the current filter, say).
|
|
1791
|
+
* They still take hover and presses. Pass a stable value: a new one re-batches the layer.
|
|
1792
|
+
*/
|
|
1793
|
+
dimmed?: Iterable<AreaId> | ((id: AreaId) => boolean) | undefined;
|
|
1794
|
+
/**
|
|
1795
|
+
* A press landed on a region. Setting it makes the layer claim presses inside its regions,
|
|
1796
|
+
* so the stage does not pan from them. The event is the `pointerdown` (the `pointerup` for
|
|
1797
|
+
* a touch tap), so `useShapeDrag` can start a drag from it.
|
|
1798
|
+
*
|
|
1799
|
+
* A mounted `StageSurface` hears a press first; there, ask `useStageHitTest` what is
|
|
1800
|
+
* under it instead.
|
|
1801
|
+
*/
|
|
1802
|
+
onItemPress?: ((id: AreaId, event: StagePointerEvent) => void) | undefined;
|
|
1803
|
+
/** Show the items' `label`s where the zoom leaves room for them. On by default. */
|
|
1804
|
+
labels?: boolean | undefined;
|
|
1805
|
+
/**
|
|
1806
|
+
* Tick the first vertex: a short line from vertex 0 towards the centre, so the orientation
|
|
1807
|
+
* of a marker quad reads (the overlay grammar's "corner 0 ticked"). Off by default.
|
|
1808
|
+
*/
|
|
1809
|
+
firstVertexTick?: boolean | undefined;
|
|
1810
|
+
/** Draw the dark band under every outline. On by default; off for a fast, flat layer. */
|
|
1811
|
+
halo?: boolean | undefined;
|
|
1812
|
+
/** CSS colour of selected regions. Defaults to the overlay `selection` role. */
|
|
1813
|
+
selectionStroke?: string | undefined;
|
|
1814
|
+
/** The id hit-tests report for this layer. Defaults to a generated one. */
|
|
1815
|
+
layerId?: string | undefined;
|
|
1816
|
+
/** Rank against other layers in hit-tests. Defaults to `STAGE_HIT_PRIORITY.area`. */
|
|
1817
|
+
priority?: number | undefined;
|
|
1818
|
+
/** The layer's accessible name. Defaults to "Areas". */
|
|
1819
|
+
label?: string | undefined;
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* A selectable set of closed regions inside an `ImageStage`.
|
|
1823
|
+
*
|
|
1824
|
+
* - **Rendering**: an outline and its 12 % fill, in the item's role (`feature` by default).
|
|
1825
|
+
* Rings are wound alike before they are batched, so overlapping regions never cut a hole in
|
|
1826
|
+
* each other.
|
|
1827
|
+
* - **States**, from visual-language §5: default 1.5 screen px (1 for `model` and
|
|
1828
|
+
* `structure`), hover 2, selected 2.5 in the selection colour, dimmed at 35 % opacity. Every
|
|
1829
|
+
* outline has a halo. A region has no ring: its outline at 2.5 px is the mark.
|
|
1830
|
+
* - **Labels** at the centre of a region, only where regions are at least 24 screen px apart,
|
|
1831
|
+
* at most 200 at a time. The hovered and selected regions always carry theirs.
|
|
1832
|
+
* - **Picking** goes through the stage's hit registry: a press within the pointer's tolerance of
|
|
1833
|
+
* an outline picks that region, else the smallest region containing the point. `onHoverChange`
|
|
1834
|
+
* and `onItemPress` here, and `useStageHitTest` for an app that arbitrates between layers.
|
|
1835
|
+
*
|
|
1836
|
+
* The SVG carries `data-hovered` (the hovered id).
|
|
1837
|
+
*/
|
|
1838
|
+
export declare function AreaSet({ items, role, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, labels, firstVertexTick, halo, selectionStroke, layerId, priority, label }: AreaSetProps): import("react").JSX.Element;
|
|
1839
|
+
//#endregion
|
|
1840
|
+
//#region src/components/ellipseIndex.d.ts
|
|
1841
|
+
/** An ellipse's identity. */
|
|
1842
|
+
type EllipseId = string | number;
|
|
1843
|
+
/** One ellipse. */
|
|
1844
|
+
interface Ellipse {
|
|
1845
|
+
/** Its identity, unique in the set. */
|
|
1846
|
+
id: EllipseId;
|
|
1847
|
+
/** Centre x, image pixels. */
|
|
1848
|
+
x: number;
|
|
1849
|
+
/** Centre y, image pixels. */
|
|
1850
|
+
y: number;
|
|
1851
|
+
/** Semi-axis along the rotated x axis, image pixels. */
|
|
1852
|
+
rx: number;
|
|
1853
|
+
/** Semi-axis along the rotated y axis, image pixels. */
|
|
1854
|
+
ry: number;
|
|
1855
|
+
/** Rotation of the `rx` axis, radians clockwise on screen (y points down). Defaults to 0. */
|
|
1856
|
+
angle?: number | undefined;
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1859
|
+
* An index built by `buildEllipseIndex`. Treat it as opaque and query it with `nearestEllipse`
|
|
1860
|
+
* and `ellipsesInRect`; its layout may change.
|
|
1861
|
+
*/
|
|
1862
|
+
interface EllipseIndex {
|
|
1863
|
+
/** The ellipses, in the order given. */
|
|
1864
|
+
readonly items: readonly Ellipse[];
|
|
1865
|
+
/** The grid over their bounding boxes (an `AreaIndex` of boxes, one per ellipse). */
|
|
1866
|
+
readonly grid: AreaIndex;
|
|
1867
|
+
/** Per ellipse, its area `π·rx·ry`, used to prefer the smaller of nested ellipses; `NaN` for a degenerate one. */
|
|
1868
|
+
readonly size: Float64Array;
|
|
1869
|
+
}
|
|
1870
|
+
/** The ellipse `nearestEllipse` picked. */
|
|
1871
|
+
interface EllipseHit {
|
|
1872
|
+
/** Its id. */
|
|
1873
|
+
id: EllipseId;
|
|
1874
|
+
/** Its position in the array the index was built from. */
|
|
1875
|
+
index: number;
|
|
1876
|
+
/** Whether the query is inside the ellipse. */
|
|
1877
|
+
inside: boolean;
|
|
1878
|
+
/** The distance from the query to the ellipse's outline, in image pixels (also when inside). */
|
|
1879
|
+
distance: number;
|
|
1880
|
+
}
|
|
1881
|
+
/**
|
|
1882
|
+
* The axis-aligned bounding box of an ellipse.
|
|
1883
|
+
*
|
|
1884
|
+
* @param e - The ellipse.
|
|
1885
|
+
* @returns `[minX, minY, maxX, maxY]`, or `null` for a degenerate ellipse.
|
|
1886
|
+
*/
|
|
1887
|
+
export declare function ellipseBounds(e: Ellipse): [number, number, number, number] | null;
|
|
1888
|
+
/**
|
|
1889
|
+
* Whether `(x, y)` is inside the ellipse (its outline counts as inside).
|
|
1890
|
+
*
|
|
1891
|
+
* @param e - The ellipse.
|
|
1892
|
+
* @param x - The query's x.
|
|
1893
|
+
* @param y - The query's y.
|
|
1894
|
+
* @returns `false` for a degenerate ellipse.
|
|
1895
|
+
*/
|
|
1896
|
+
export declare function pointInEllipse(e: Ellipse, x: number, y: number): boolean;
|
|
1897
|
+
/**
|
|
1898
|
+
* An ellipse as an SVG path: two arcs, exactly, so it stays round at any zoom.
|
|
1899
|
+
*
|
|
1900
|
+
* @param cx - Centre x, image pixels.
|
|
1901
|
+
* @param cy - Centre y, image pixels.
|
|
1902
|
+
* @param rx - Semi-axis along the rotated x axis, image pixels.
|
|
1903
|
+
* @param ry - Semi-axis along the rotated y axis, image pixels.
|
|
1904
|
+
* @param angle - Rotation of the `rx` axis, radians clockwise on screen.
|
|
1905
|
+
* @returns Path data, or `""` for a degenerate ellipse (a non-finite value, or a radius not above zero).
|
|
1906
|
+
*/
|
|
1907
|
+
export declare function ellipsePath(cx: number, cy: number, rx: number, ry: number, angle?: number): string;
|
|
1908
|
+
/**
|
|
1909
|
+
* Index a set of ellipses.
|
|
1910
|
+
*
|
|
1911
|
+
* @param items - The ellipses.
|
|
1912
|
+
* @param cell - The grid cell side in image pixels; see `buildAreaIndex` for the default.
|
|
1913
|
+
* @returns The index.
|
|
1914
|
+
*/
|
|
1915
|
+
export declare function buildEllipseIndex(items: readonly Ellipse[], cell?: number): EllipseIndex;
|
|
1916
|
+
/**
|
|
1917
|
+
* The ellipse under a point: one whose outline passes within `radius`, or else one that
|
|
1918
|
+
* contains it.
|
|
1919
|
+
*
|
|
1920
|
+
* An outline is the more precise gesture, so it wins: among ellipses whose outline is within
|
|
1921
|
+
* `radius` the nearest is picked, and only without one the containing ellipse. Ties (equal
|
|
1922
|
+
* distance, or several containing ellipses) go to the smaller ellipse, so a ring drawn inside
|
|
1923
|
+
* another is picked rather than the outer one, then to the earlier one.
|
|
1924
|
+
*
|
|
1925
|
+
* @param index - The index.
|
|
1926
|
+
* @param p - The query, in image coordinates.
|
|
1927
|
+
* @param radius - How far from an outline the query still picks it, in image pixels.
|
|
1928
|
+
* @returns The ellipse, or `null`.
|
|
1929
|
+
*/
|
|
1930
|
+
export declare function nearestEllipse(index: EllipseIndex, p: Point, radius: number): EllipseHit | null;
|
|
1931
|
+
/**
|
|
1932
|
+
* The ellipses any part of which is inside `rect`: the rectangle meets the outline, or lies
|
|
1933
|
+
* inside the ellipse, or contains it.
|
|
1934
|
+
*
|
|
1935
|
+
* @param index - The index.
|
|
1936
|
+
* @param rect - The band, in image coordinates. A negative extent is read as the box between
|
|
1937
|
+
* its corners.
|
|
1938
|
+
* @returns Their ids, in the order the ellipses were given.
|
|
1939
|
+
*/
|
|
1940
|
+
export declare function ellipsesInRect(index: EllipseIndex, rect: Rect): EllipseId[];
|
|
1941
|
+
//#endregion
|
|
1942
|
+
//#region src/components/EllipseSet.d.ts
|
|
1943
|
+
/** One ellipse of an `EllipseSet`. */
|
|
1944
|
+
interface EllipseSetItem extends Ellipse {
|
|
1945
|
+
/** The overlay role it is painted in. Defaults to the layer's `role`. */
|
|
1946
|
+
role?: OverlayRole | undefined;
|
|
1947
|
+
/** Draw it dashed (4 3 screen px), so two kinds differ by more than colour. */
|
|
1948
|
+
dashed?: boolean | undefined;
|
|
1949
|
+
/** Opacity in [0, 1], rounded to a tenth so ellipses still share paths. Defaults to 1. */
|
|
1950
|
+
opacity?: number | undefined;
|
|
1951
|
+
}
|
|
1952
|
+
/** Props of `EllipseSet`. */
|
|
1953
|
+
interface EllipseSetProps {
|
|
1954
|
+
/** The ellipses, in image coordinates. */
|
|
1955
|
+
items: readonly EllipseSetItem[];
|
|
1956
|
+
/** The role of an item that names none. Defaults to `"feature"`. */
|
|
1957
|
+
role?: OverlayRole | undefined;
|
|
1958
|
+
/** The hovered id, when the app controls hover: its ellipses are drawn at 2 px. */
|
|
1959
|
+
hoveredId?: EllipseId | null | undefined;
|
|
1960
|
+
/** Called when the ellipse under the pointer changes. `null` when it leaves every ellipse. Not called when `pickable` is off. */
|
|
1961
|
+
onHoverChange?: ((id: EllipseId | null) => void) | undefined;
|
|
1962
|
+
/** The selected ids, drawn at 2.5 px in the selection colour. */
|
|
1963
|
+
selectedIds?: Iterable<EllipseId> | undefined;
|
|
1964
|
+
/** Ids drawn at 35 % opacity, as a set or a predicate. Pass a stable value: a new one re-batches the layer. */
|
|
1965
|
+
dimmed?: Iterable<EllipseId> | ((id: EllipseId) => boolean) | undefined;
|
|
1966
|
+
/**
|
|
1967
|
+
* A press landed on an ellipse. Setting it makes the layer claim presses on its ellipses,
|
|
1968
|
+
* so the stage does not pan from them. The event is the `pointerdown` (the `pointerup` for
|
|
1969
|
+
* a touch tap), so `useShapeDrag` can start a drag from it.
|
|
1970
|
+
*
|
|
1971
|
+
* A mounted `StageSurface` hears a press first; there, ask `useStageHitTest` what is
|
|
1972
|
+
* under it instead.
|
|
1973
|
+
*/
|
|
1974
|
+
onItemPress?: ((id: EllipseId, event: StagePointerEvent) => void) | undefined;
|
|
1975
|
+
/**
|
|
1976
|
+
* Whether the layer takes part in the stage's hit-test. On by default. Turn it off for a
|
|
1977
|
+
* decorative layer (the ring outlines under a `PointSet` of centres), so it neither
|
|
1978
|
+
* hovers, nor claims presses, nor answers `useStageHitTest`.
|
|
1979
|
+
*/
|
|
1980
|
+
pickable?: boolean | undefined;
|
|
1981
|
+
/** The id hit-tests report for this layer. Defaults to a generated one. */
|
|
1982
|
+
layerId?: string | undefined;
|
|
1983
|
+
/** Rank against other layers in hit-tests. Defaults to `STAGE_HIT_PRIORITY.area`. */
|
|
1984
|
+
priority?: number | undefined;
|
|
1985
|
+
/** Draw the dark band under every stroke. On by default. */
|
|
1986
|
+
halo?: boolean | undefined;
|
|
1987
|
+
/**
|
|
1988
|
+
* The smallest semi-axis, in screen pixels: a dot whose data size would vanish at the fitted
|
|
1989
|
+
* zoom is still drawn this large. Omit for none.
|
|
1990
|
+
*/
|
|
1991
|
+
minRadius?: number | undefined;
|
|
1992
|
+
/** CSS colour of selected ellipses. Defaults to the overlay `selection` role. */
|
|
1993
|
+
selectionStroke?: string | undefined;
|
|
1994
|
+
/** Name the layer as an image for assistive technology. Without it the layer is decorative (`aria-hidden`). */
|
|
1995
|
+
label?: string | undefined;
|
|
1996
|
+
}
|
|
1997
|
+
/**
|
|
1998
|
+
* A batched set of ellipses inside an `ImageStage`.
|
|
1999
|
+
*
|
|
2000
|
+
* - **Geometry** is data: `rx`, `ry` and the centre are image pixels and scale with the image;
|
|
2001
|
+
* the stroke is a screen constant.
|
|
2002
|
+
* - **States** follow visual-language §5: 1.5 screen px (1 for `model` and `structure`), hover
|
|
2003
|
+
* 2, selected 2.5 in the selection colour, dimmed at 35 % opacity. Every stroke has a halo.
|
|
2004
|
+
* - **Batching** is by (role, dash, opacity, dimming): a thousand rings are a dozen elements.
|
|
2005
|
+
* - **Picking** goes through the stage's hit registry: a press within the pointer's tolerance of
|
|
2006
|
+
* an outline picks that ellipse, else the smallest ellipse containing the point.
|
|
2007
|
+
* `onHoverChange` and `onItemPress` here, and `useStageHitTest` for an app that arbitrates
|
|
2008
|
+
* between layers. `pickable={false}` turns it off.
|
|
2009
|
+
*
|
|
2010
|
+
* The SVG carries `data-ellipses` (the count) and `data-hovered` (the hovered id).
|
|
2011
|
+
*/
|
|
2012
|
+
export declare function EllipseSet({ items, role, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, pickable, layerId, priority, halo, minRadius, selectionStroke, label }: EllipseSetProps): import("react").JSX.Element;
|
|
2013
|
+
//#endregion
|
|
2014
|
+
//#region src/components/GridLayer.d.ts
|
|
2015
|
+
/** One node of a `GridLayer`: a point with its lattice index. */
|
|
2016
|
+
interface GridNode extends PointSetItem {
|
|
2017
|
+
/** The lattice index along the first axis. */
|
|
2018
|
+
i: number;
|
|
2019
|
+
/** The lattice index along the second axis. */
|
|
2020
|
+
j: number;
|
|
2021
|
+
}
|
|
2022
|
+
/** How the edges along one lattice axis are drawn. */
|
|
2023
|
+
interface GridEdgeStyle {
|
|
2024
|
+
/** The overlay role of the edges. Defaults to `"structure"`: they are context. */
|
|
2025
|
+
role?: OverlayRole | undefined;
|
|
2026
|
+
/** Draw them dashed (4 3 screen px), so the two axes differ by more than colour. */
|
|
2027
|
+
dashed?: boolean | undefined;
|
|
2028
|
+
/** Draw them at all. Defaults to `true`. */
|
|
2029
|
+
visible?: boolean | undefined;
|
|
2030
|
+
}
|
|
2031
|
+
/** Props of `GridLayer`. */
|
|
2032
|
+
interface GridLayerProps {
|
|
2033
|
+
/** The nodes, in image coordinates, with their lattice indices. Gaps are allowed. */
|
|
2034
|
+
nodes: readonly GridNode[];
|
|
2035
|
+
/**
|
|
2036
|
+
* How edges are drawn, by axis: `i` joins `(i, j)` to `(i + 1, j)` (the rows, when `i`
|
|
2037
|
+
* counts columns), `j` joins `(i, j)` to `(i, j + 1)`. Both are solid `structure` by default.
|
|
2038
|
+
*/
|
|
2039
|
+
edges?: {
|
|
2040
|
+
i?: GridEdgeStyle | undefined;
|
|
2041
|
+
j?: GridEdgeStyle | undefined;
|
|
2042
|
+
} | undefined;
|
|
2043
|
+
/** The marker kind of a node that names none. Defaults to `"plus"`: a corner. */
|
|
2044
|
+
kind?: string | undefined;
|
|
2045
|
+
/** More marker kinds, or replacements for built-in ones, by name; see `PointSet`. */
|
|
2046
|
+
markers?: Readonly<Record<string, MarkerShape>> | undefined;
|
|
2047
|
+
/**
|
|
2048
|
+
* Label every node without a `label` of its own with its lattice index, `i,j`, where the
|
|
2049
|
+
* zoom leaves room (nodes at least 24 screen px apart). Off by default.
|
|
2050
|
+
*/
|
|
2051
|
+
indexLabels?: boolean | undefined;
|
|
2052
|
+
/** Show the nodes' labels where the zoom leaves room for them. On by default. */
|
|
2053
|
+
labels?: boolean | undefined;
|
|
2054
|
+
/** The hovered node id, when the app controls hover. */
|
|
2055
|
+
hoveredId?: PointId | null | undefined;
|
|
2056
|
+
/** Called when the node under the pointer changes. `null` when it leaves every node. */
|
|
2057
|
+
onHoverChange?: ((id: PointId | null) => void) | undefined;
|
|
2058
|
+
/** The selected node ids, drawn at 2.5 px in the selection colour with a ring. */
|
|
2059
|
+
selectedIds?: Iterable<PointId> | undefined;
|
|
2060
|
+
/**
|
|
2061
|
+
* Node ids drawn at 35 % opacity, as a set or a predicate. An edge is dimmed when both its
|
|
2062
|
+
* nodes are. Pass a stable value: a new one re-batches the layer.
|
|
2063
|
+
*/
|
|
2064
|
+
dimmed?: Iterable<PointId> | ((id: PointId) => boolean) | undefined;
|
|
2065
|
+
/** A press landed on a node; see `PointSet`. Setting it makes the layer claim presses on its nodes. */
|
|
2066
|
+
onItemPress?: ((id: PointId, event: StagePointerEvent) => void) | undefined;
|
|
2067
|
+
/** Draw the dark band under every mark. On by default; off for a fast, flat layer. */
|
|
2068
|
+
halo?: boolean | undefined;
|
|
2069
|
+
/** CSS colour of selected nodes and rings. Defaults to the overlay `selection` role. */
|
|
2070
|
+
selectionStroke?: string | undefined;
|
|
2071
|
+
/** The id hit-tests report for the nodes. Defaults to a generated one. */
|
|
2072
|
+
layerId?: string | undefined;
|
|
2073
|
+
/** Rank against other layers in hit-tests. Defaults to `STAGE_HIT_PRIORITY.point`. */
|
|
2074
|
+
priority?: number | undefined;
|
|
2075
|
+
/** The layer's accessible name. Defaults to "Grid". */
|
|
2076
|
+
label?: string | undefined;
|
|
2077
|
+
}
|
|
2078
|
+
/**
|
|
2079
|
+
* A detected lattice inside an `ImageStage`.
|
|
2080
|
+
*
|
|
2081
|
+
* - **Nodes** are a `PointSet`: `plus` markers by default, picked through the point index at
|
|
2082
|
+
* point priority, with `onHoverChange`, `onItemPress`, selection (with ring) and dimming.
|
|
2083
|
+
* - **Edges** join `(i, j)` to `(i + 1, j)` and to `(i, j + 1)` where both nodes exist
|
|
2084
|
+
* (`latticeEdges`), in one path per axis and dimming, below the nodes. They are `structure`
|
|
2085
|
+
* role by default, 1 screen px with a halo; `edges` restyles each axis.
|
|
2086
|
+
* - **Labels** are the nodes' own `label`s, or with `indexLabels` their `i,j`, only where nodes
|
|
2087
|
+
* are at least 24 screen px apart.
|
|
2088
|
+
*
|
|
2089
|
+
* The edges' SVG carries `data-edges`; the nodes' is the `PointSet`'s.
|
|
2090
|
+
*/
|
|
2091
|
+
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;
|
|
2092
|
+
//#endregion
|
|
2093
|
+
//#region src/components/gridEdges.d.ts
|
|
2094
|
+
/**
|
|
2095
|
+
* The edges of a detected lattice: which nodes are neighbours.
|
|
2096
|
+
*
|
|
2097
|
+
* A calibration detector returns its corners with integer lattice indices `(i, j)` and gaps
|
|
2098
|
+
* where a corner was not found. The edges are not data: node `(i, j)` is joined to
|
|
2099
|
+
* `(i + 1, j)` and to `(i, j + 1)` when both exist. This module computes them in O(n) with a
|
|
2100
|
+
* hash of the indices. It imports neither React nor the DOM.
|
|
2101
|
+
*/
|
|
2102
|
+
/** What `latticeEdges` reads from each node. */
|
|
2103
|
+
interface LatticeNode {
|
|
2104
|
+
/** The lattice index along the first axis. A non-integer index is not part of the lattice. */
|
|
2105
|
+
i: number;
|
|
2106
|
+
/** The lattice index along the second axis. A non-integer index is not part of the lattice. */
|
|
2107
|
+
j: number;
|
|
2108
|
+
}
|
|
2109
|
+
/** The lattice axis an edge runs along: `"i"` joins `(i, j)` to `(i + 1, j)`, `"j"` joins `(i, j)` to `(i, j + 1)`. */
|
|
2110
|
+
type LatticeAxis = "i" | "j";
|
|
2111
|
+
/** An edge between two neighbouring nodes. */
|
|
2112
|
+
interface LatticeEdge {
|
|
2113
|
+
/** Position in the node array of the end with the lower index along `axis`. */
|
|
2114
|
+
a: number;
|
|
2115
|
+
/** Position in the node array of the end with the higher index along `axis`. */
|
|
2116
|
+
b: number;
|
|
2117
|
+
/** The axis it runs along. */
|
|
2118
|
+
axis: LatticeAxis;
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* The edges of a lattice: every pair of nodes whose indices differ by one along exactly one
|
|
2122
|
+
* axis.
|
|
2123
|
+
*
|
|
2124
|
+
* @param nodes - The nodes, in any order, with gaps allowed. A node whose index is not an
|
|
2125
|
+
* integer of magnitude below 2²⁵ takes no edges, and when two nodes share an index the
|
|
2126
|
+
* first one is the lattice's node there.
|
|
2127
|
+
* @returns The edges, ordered by the position of `a`, then `"i"` before `"j"`.
|
|
2128
|
+
*/
|
|
2129
|
+
export declare function latticeEdges(nodes: ArrayLike<LatticeNode>): LatticeEdge[];
|
|
2130
|
+
//#endregion
|
|
2131
|
+
//#region src/components/heatmapRaster.d.ts
|
|
2132
|
+
/**
|
|
2133
|
+
* A sequential colour map: a position in `[0, 1]` to an `[r, g, b]` colour, each channel
|
|
2134
|
+
* 0 to 255. `@vitavision/charts`' `colormapRgb(name, t)` is one: `(t) => colormapRgb("viridis", t)`.
|
|
2135
|
+
*/
|
|
2136
|
+
type Colormap = (t: number) => readonly [number, number, number];
|
|
2137
|
+
/** A range of values mapped onto the colour map: `low` to its start, `high` to its end. */
|
|
2138
|
+
interface ValueRange {
|
|
2139
|
+
/** The value drawn in the map's first colour. */
|
|
2140
|
+
low: number;
|
|
2141
|
+
/** The value drawn in the map's last colour. */
|
|
2142
|
+
high: number;
|
|
2143
|
+
}
|
|
2144
|
+
/**
|
|
2145
|
+
* The extent of a plane's finite values.
|
|
2146
|
+
*
|
|
2147
|
+
* @param plane - The plane.
|
|
2148
|
+
* @param channel - Which of its channels. Defaults to the first.
|
|
2149
|
+
* @returns `{ low, high }`, or `null` when the channel is missing or has no finite value.
|
|
2150
|
+
*/
|
|
2151
|
+
export declare function planeRange(plane: ValuePlane, channel?: number): ValueRange | null;
|
|
2152
|
+
/**
|
|
2153
|
+
* Colour a plane through a colour map.
|
|
2154
|
+
*
|
|
2155
|
+
* Opaque where the value is finite; transparent where it is `NaN` or infinite (an uncovered
|
|
2156
|
+
* pixel, as in `valueAt`). Values outside `range` take the map's end colours. A flat range
|
|
2157
|
+
* (`high <= low`) draws every pixel in the map's first colour.
|
|
2158
|
+
*
|
|
2159
|
+
* @param plane - The plane.
|
|
2160
|
+
* @param colormap - The colour map; sampled at 256 positions.
|
|
2161
|
+
* @param range - What the map spans. Defaults to the extent of the channel's finite values.
|
|
2162
|
+
* @param channel - Which channel to draw. Defaults to the first.
|
|
2163
|
+
* @returns `width · height` RGBA pixels, row-major; all transparent for a missing channel.
|
|
2164
|
+
*/
|
|
2165
|
+
export declare function rasterizePlane(plane: ValuePlane, colormap: Colormap, range?: ValueRange, channel?: number): Uint8ClampedArray;
|
|
2166
|
+
//#endregion
|
|
2167
|
+
//#region src/components/HeatmapLayer.d.ts
|
|
2168
|
+
/** What every `HeatmapLayer` takes. */
|
|
2169
|
+
interface HeatmapLayerBaseProps {
|
|
2170
|
+
/** How opaque the heatmap is, 0 to 1. Defaults to `1`. */
|
|
2171
|
+
opacity?: number | undefined;
|
|
2172
|
+
/** Draw it. Defaults to `true`. While `false` nothing is rasterised. */
|
|
2173
|
+
visible?: boolean | undefined;
|
|
2174
|
+
/**
|
|
2175
|
+
* Where the raster is placed, in image coordinates: `x` and `y` the top-left edge of its
|
|
2176
|
+
* first pixel's footprint (`-0.5, -0.5` is the image's own top-left corner), `width` and `height`
|
|
2177
|
+
* the extent it is stretched over. Defaults to the whole image, so a raster of any
|
|
2178
|
+
* resolution covers it 1:1 in position.
|
|
2179
|
+
*/
|
|
2180
|
+
rect?: Rect | undefined;
|
|
2181
|
+
/** The zoom (CSS pixels per heatmap pixel) from which heatmap pixels are drawn as blocks. Defaults to 4. */
|
|
2182
|
+
pixelatedAbove?: number | undefined;
|
|
2183
|
+
/** A description for assistive technology. Defaults to `""`: decorative, as the legend carries the meaning. */
|
|
2184
|
+
alt?: string | undefined;
|
|
2185
|
+
/** Called once the raster is on screen (and again for each new one). */
|
|
2186
|
+
onReady?: (() => void) | undefined;
|
|
2187
|
+
/** Called when the raster could not be made: a canvas that could not be allocated, or an `rgba` buffer too short for its size. */
|
|
2188
|
+
onError?: (() => void) | undefined;
|
|
2189
|
+
/** Merged onto the image with `cn`. */
|
|
2190
|
+
className?: string | undefined;
|
|
2191
|
+
}
|
|
2192
|
+
/** A heatmap from pixels that are already coloured. */
|
|
2193
|
+
interface HeatmapRgbaProps extends HeatmapLayerBaseProps {
|
|
2194
|
+
/** Row-major RGBA, `width · height · 4` bytes. A `Uint8Array` is read in place, not copied. */
|
|
2195
|
+
rgba: Uint8ClampedArray | Uint8Array;
|
|
2196
|
+
/** The raster's width in pixels. */
|
|
2197
|
+
width: number;
|
|
2198
|
+
/** The raster's height in pixels. */
|
|
2199
|
+
height: number;
|
|
2200
|
+
/** Not used with `rgba`. */
|
|
2201
|
+
plane?: undefined;
|
|
2202
|
+
/** Not used with `rgba`. */
|
|
2203
|
+
colormap?: undefined;
|
|
2204
|
+
/** Not used with `rgba`. */
|
|
2205
|
+
range?: undefined;
|
|
2206
|
+
/** Not used with `rgba`. */
|
|
2207
|
+
channel?: undefined;
|
|
2208
|
+
}
|
|
2209
|
+
/** A heatmap from a scalar field and a colour map. */
|
|
2210
|
+
interface HeatmapPlaneProps extends HeatmapLayerBaseProps {
|
|
2211
|
+
/** The field, as decoded by `decodePlane`. */
|
|
2212
|
+
plane: ValuePlane;
|
|
2213
|
+
/**
|
|
2214
|
+
* The colour map. `NaN` pixels stay transparent. Pass a stable function: a new one
|
|
2215
|
+
* re-rasterises the heatmap. `@vitavision/charts`' `(t) => colormapRgb("viridis", t)` is one.
|
|
2216
|
+
*/
|
|
2217
|
+
colormap: Colormap;
|
|
2218
|
+
/** What the map spans. Defaults to the extent of the channel's finite values. */
|
|
2219
|
+
range?: ValueRange | undefined;
|
|
2220
|
+
/** Which channel of the plane to draw. Defaults to the first. */
|
|
2221
|
+
channel?: number | undefined;
|
|
2222
|
+
/** Not used with `plane`. */
|
|
2223
|
+
rgba?: undefined;
|
|
2224
|
+
/** Not used with `plane`. */
|
|
2225
|
+
width?: undefined;
|
|
2226
|
+
/** Not used with `plane`. */
|
|
2227
|
+
height?: undefined;
|
|
2228
|
+
}
|
|
2229
|
+
/** Props of `HeatmapLayer`: pre-coloured `rgba` pixels, or a `plane` with a `colormap`. */
|
|
2230
|
+
type HeatmapLayerProps = HeatmapRgbaProps | HeatmapPlaneProps;
|
|
2231
|
+
/**
|
|
2232
|
+
* A heatmap inside an `ImageStage`: a scalar field coloured through a colour map, or an RGBA
|
|
2233
|
+
* buffer, placed over the image (default) or any rectangle of it.
|
|
2234
|
+
*
|
|
2235
|
+
* - **Rasterised in an effect**, once per change of its data, into an offscreen canvas and an
|
|
2236
|
+
* object URL that is revoked when replaced and on unmount. Server rendering draws nothing.
|
|
2237
|
+
* - **Pixelated** from 4 CSS pixels per heatmap pixel, like `ImageLayer`, so the cells of a
|
|
2238
|
+
* coarse map are not smoothed into a blur.
|
|
2239
|
+
* - **Stacking:** it is drawn where it is placed among the stage's children. Before the
|
|
2240
|
+
* overlays it sits under them; the image layer goes before it.
|
|
2241
|
+
* - **Input:** none. It takes no pointer events, so presses reach the layers above and the stage.
|
|
2242
|
+
*
|
|
2243
|
+
* The image carries `data-heatmap`, `data-pixelated` while pixelated, and `data-ready`.
|
|
2244
|
+
*/
|
|
2245
|
+
export declare function HeatmapLayer(props: HeatmapLayerProps): import("react").JSX.Element | null;
|
|
2246
|
+
//#endregion
|
|
1563
2247
|
//#region src/components/roiEdit.d.ts
|
|
1564
2248
|
/** A region's handle, by compass direction. */
|
|
1565
2249
|
type RoiHandle = "nw" | "n" | "ne" | "e" | "se" | "s" | "sw" | "w";
|
|
@@ -1631,6 +2315,305 @@ export declare function moveRect(rect: Rect, dx: number, dy: number, bounds: Rec
|
|
|
1631
2315
|
*/
|
|
1632
2316
|
export declare function sameRect(a: Rect | null, b: Rect | null, epsilon?: number): boolean;
|
|
1633
2317
|
//#endregion
|
|
2318
|
+
//#region src/components/shapeEdit.d.ts
|
|
2319
|
+
/** A rotated rectangle, or the ellipse inscribed in one. */
|
|
2320
|
+
interface RotatedShape {
|
|
2321
|
+
/** Centre x, in image coordinates. */
|
|
2322
|
+
cx: number;
|
|
2323
|
+
/** Centre y, in image coordinates. */
|
|
2324
|
+
cy: number;
|
|
2325
|
+
/** Extent along the shape's own x axis: a rectangle's width, an ellipse's full axis `2·rx`. */
|
|
2326
|
+
width: number;
|
|
2327
|
+
/** Extent along the shape's own y axis: a rectangle's height, an ellipse's full axis `2·ry`. */
|
|
2328
|
+
height: number;
|
|
2329
|
+
/** Radians, clockwise on screen: the turn from the image's x axis to the shape's own. */
|
|
2330
|
+
rotation: number;
|
|
2331
|
+
}
|
|
2332
|
+
/**
|
|
2333
|
+
* A point of image space in the shape's own frame: origin at its centre, axes along its sides.
|
|
2334
|
+
*
|
|
2335
|
+
* @param shape - The shape.
|
|
2336
|
+
* @param p - A point in image coordinates.
|
|
2337
|
+
* @returns The point relative to the shape.
|
|
2338
|
+
*/
|
|
2339
|
+
export declare function toShapeFrame(shape: RotatedShape, p: Point): Point;
|
|
2340
|
+
/**
|
|
2341
|
+
* A point of the shape's own frame in image space; the inverse of `toShapeFrame`.
|
|
2342
|
+
*
|
|
2343
|
+
* @param shape - The shape.
|
|
2344
|
+
* @param p - A point relative to the shape.
|
|
2345
|
+
* @returns The point in image coordinates.
|
|
2346
|
+
*/
|
|
2347
|
+
export declare function fromShapeFrame(shape: RotatedShape, p: Point): Point;
|
|
2348
|
+
/**
|
|
2349
|
+
* Where a handle sits: a corner or the middle of a side, turned with the shape.
|
|
2350
|
+
*
|
|
2351
|
+
* @param shape - The shape.
|
|
2352
|
+
* @param handle - The handle, by compass direction in the shape's own frame.
|
|
2353
|
+
* @returns The handle's centre, in image coordinates.
|
|
2354
|
+
*/
|
|
2355
|
+
export declare function shapeHandlePoint(shape: RotatedShape, handle: RoiHandle): Point;
|
|
2356
|
+
/**
|
|
2357
|
+
* Where the rotation handle sits: beyond the middle of the top side, along the shape's own
|
|
2358
|
+
* up direction.
|
|
2359
|
+
*
|
|
2360
|
+
* @param shape - The shape.
|
|
2361
|
+
* @param distance - How far past the top side, in image pixels. For a screen-constant handle,
|
|
2362
|
+
* pass `useScreenPx()(css)`.
|
|
2363
|
+
* @returns The handle's centre, in image coordinates.
|
|
2364
|
+
*/
|
|
2365
|
+
export declare function rotationHandlePoint(shape: RotatedShape, distance: number): Point;
|
|
2366
|
+
/**
|
|
2367
|
+
* Drag a handle to `to`.
|
|
2368
|
+
*
|
|
2369
|
+
* The dragged side or corner follows the pointer in the shape's own frame and the opposite
|
|
2370
|
+
* side or corner stays where it is in the image, which is what makes a handle feel attached.
|
|
2371
|
+
* The shape does not flip when dragged through the opposite side: it stops at `minSize`.
|
|
2372
|
+
*
|
|
2373
|
+
* @param shape - The shape before the drag.
|
|
2374
|
+
* @param handle - The handle being dragged.
|
|
2375
|
+
* @param to - The pointer, in image coordinates.
|
|
2376
|
+
* @param minSize - The smallest extent on either axis, in image pixels.
|
|
2377
|
+
* @returns The resized shape: the same rotation, and the opposite side or corner unmoved.
|
|
2378
|
+
*/
|
|
2379
|
+
export declare function resizeShape(shape: RotatedShape, handle: RoiHandle, to: Point, minSize: number): RotatedShape;
|
|
2380
|
+
/**
|
|
2381
|
+
* Turn the shape about its centre so that its rotation handle points at `to`.
|
|
2382
|
+
*
|
|
2383
|
+
* @param shape - The shape before the drag.
|
|
2384
|
+
* @param to - The pointer, in image coordinates.
|
|
2385
|
+
* @param snap - Round the rotation to a multiple of this many radians (Shift while dragging
|
|
2386
|
+
* rounds to 15°). Defaults to no rounding.
|
|
2387
|
+
* @returns The rotated shape: the same centre and size, `rotation` in `(-π, π]`.
|
|
2388
|
+
*/
|
|
2389
|
+
export declare function rotateShape(shape: RotatedShape, to: Point, snap?: number): RotatedShape;
|
|
2390
|
+
/**
|
|
2391
|
+
* Move the shape.
|
|
2392
|
+
*
|
|
2393
|
+
* @param shape - The shape.
|
|
2394
|
+
* @param dx - Horizontal shift, in image pixels.
|
|
2395
|
+
* @param dy - Vertical shift, in image pixels.
|
|
2396
|
+
* @returns The moved shape.
|
|
2397
|
+
*/
|
|
2398
|
+
export declare function moveShape(shape: RotatedShape, dx: number, dy: number): RotatedShape;
|
|
2399
|
+
/**
|
|
2400
|
+
* An angle as the equivalent one in `(-π, π]`.
|
|
2401
|
+
*
|
|
2402
|
+
* @param angle - Radians.
|
|
2403
|
+
* @returns The angle in `(-π, π]`.
|
|
2404
|
+
*/
|
|
2405
|
+
export declare function normalizeAngle(angle: number): number;
|
|
2406
|
+
/**
|
|
2407
|
+
* The resize cursor for a handle of a rotated shape: the nearest of the four CSS resize
|
|
2408
|
+
* cursors to the handle's direction on screen.
|
|
2409
|
+
*
|
|
2410
|
+
* @param handle - The handle.
|
|
2411
|
+
* @param rotation - The shape's rotation, in radians.
|
|
2412
|
+
* @returns A CSS `cursor` value.
|
|
2413
|
+
*/
|
|
2414
|
+
export declare function shapeHandleCursor(handle: RoiHandle, rotation: number): string;
|
|
2415
|
+
/**
|
|
2416
|
+
* The shape for a rectangle given as an origin corner, a size and a rotation about that
|
|
2417
|
+
* corner: Konva's `Rect` (`x`, `y`, `width`, `height`, `rotation` in degrees), for one.
|
|
2418
|
+
*
|
|
2419
|
+
* @param corner - The corner the rotation is about, in image coordinates.
|
|
2420
|
+
* @param width - Extent along the rotated x axis.
|
|
2421
|
+
* @param height - Extent along the rotated y axis.
|
|
2422
|
+
* @param rotation - Radians, clockwise on screen.
|
|
2423
|
+
* @returns The same rectangle as a `RotatedShape`.
|
|
2424
|
+
*/
|
|
2425
|
+
export declare function shapeFromCorner(corner: Point, width: number, height: number, rotation: number): RotatedShape;
|
|
2426
|
+
/**
|
|
2427
|
+
* The top-left corner of a shape in its own frame, the origin Konva rotates a `Rect` about;
|
|
2428
|
+
* the inverse of `shapeFromCorner`.
|
|
2429
|
+
*
|
|
2430
|
+
* @param shape - The shape.
|
|
2431
|
+
* @returns The corner, in image coordinates.
|
|
2432
|
+
*/
|
|
2433
|
+
export declare function shapeCorner(shape: RotatedShape): Point;
|
|
2434
|
+
/**
|
|
2435
|
+
* Whether two shapes are the same, to within `epsilon` on every field (rotations compared modulo a turn).
|
|
2436
|
+
*
|
|
2437
|
+
* @param a - A shape, or `null`.
|
|
2438
|
+
* @param b - A shape, or `null`.
|
|
2439
|
+
* @param epsilon - The tolerance. Defaults to 1e-6.
|
|
2440
|
+
* @returns `true` for two equal shapes, or two `null`s.
|
|
2441
|
+
*/
|
|
2442
|
+
export declare function sameShape(a: RotatedShape | null, b: RotatedShape | null, epsilon?: number): boolean;
|
|
2443
|
+
//#endregion
|
|
2444
|
+
//#region src/components/ShapeEditor.d.ts
|
|
2445
|
+
/** Props of `ShapeEditor`. */
|
|
2446
|
+
interface ShapeEditorProps {
|
|
2447
|
+
/** `"rect"` draws a rotated rectangle, `"ellipse"` the ellipse inscribed in it. */
|
|
2448
|
+
kind: "rect" | "ellipse";
|
|
2449
|
+
/**
|
|
2450
|
+
* The shape in image coordinates, or `null` for none. `rotation` is in **radians, clockwise
|
|
2451
|
+
* on screen**, so a value in degrees (Konva's, say) is `degrees * Math.PI / 180`. An
|
|
2452
|
+
* ellipse's `width` and `height` are its full axes, `2 · radiusX` and `2 · radiusY`.
|
|
2453
|
+
*/
|
|
2454
|
+
value: RotatedShape | null;
|
|
2455
|
+
/** Called with the shape as it changes: on every move of a drag, and on each key nudge. */
|
|
2456
|
+
onValueChange: (value: RotatedShape) => void;
|
|
2457
|
+
/** Called once a gesture ends (a drag released, a nudge made): the moment to save or re-run. */
|
|
2458
|
+
onCommit?: ((value: RotatedShape) => void) | undefined;
|
|
2459
|
+
/** Show handles and accept moves, resizes and rotations. Defaults to `true`. */
|
|
2460
|
+
editable?: boolean | undefined;
|
|
2461
|
+
/** Show the rotation handle and accept `[` / `]`. Defaults to `true`; off for a shape that must stay level. */
|
|
2462
|
+
rotatable?: boolean | undefined;
|
|
2463
|
+
/** The smallest extent on either axis, in image pixels. Defaults to 5. */
|
|
2464
|
+
minSize?: number | undefined;
|
|
2465
|
+
/** The shape's accessible name. Defaults to "Shape". */
|
|
2466
|
+
label?: string | undefined;
|
|
2467
|
+
/** CSS colour of the outline and handles. Defaults to the overlay `selection` role. */
|
|
2468
|
+
stroke?: string | undefined;
|
|
2469
|
+
}
|
|
2470
|
+
/**
|
|
2471
|
+
* An editable rotated rectangle or ellipse inside an `ImageStage`.
|
|
2472
|
+
*
|
|
2473
|
+
* - **Handles.** Eight handles resize the shape in its own frame: the dragged side follows the
|
|
2474
|
+
* pointer and the opposite side stays where it is, whatever the rotation. A shape stops at
|
|
2475
|
+
* `minSize` rather than flipping. The interior moves it, and so does the band along its
|
|
2476
|
+
* outline (the pointer's tolerance: 6 px for a mouse, 12 px for a finger), which is how a thin
|
|
2477
|
+
* or rotated shape is grabbed. The band is as wide as the device's primary pointer needs
|
|
2478
|
+
* (`(pointer: coarse)`), so on a touch laptop whose primary pointer is fine, a touch 6 to
|
|
2479
|
+
* 12 px outside the outline reaches the layers below instead of the editor.
|
|
2480
|
+
* - **Press order.** One decision serves every part of the editor: the nearest handle first,
|
|
2481
|
+
* then the interior or outline band (move), then nothing. A small shape's interior does not
|
|
2482
|
+
* steal a press meant for a handle, and a press that hits none of them is not claimed, so
|
|
2483
|
+
* it reaches whatever is below, or the stage.
|
|
2484
|
+
* - **Touch.** A press that grabs the shape is claimed; a second finger landing during an edit
|
|
2485
|
+
* cancels it (the shape reverts, nothing is committed) and is left to the stage.
|
|
2486
|
+
* - **Rotation.** The handle past the top side turns the shape about its centre; hold Shift to
|
|
2487
|
+
* round to 15°.
|
|
2488
|
+
* - **Keyboard.** The shape is focusable: arrow keys move it by one image pixel (ten with Shift),
|
|
2489
|
+
* with Alt they grow or shrink it along its own axes from its top-left corner, and `[` / `]`
|
|
2490
|
+
* turn it by 1° (15° with Shift).
|
|
2491
|
+
* - **Rendering.** Handles and the outline are a constant size on screen at every zoom; an
|
|
2492
|
+
* ellipse also shows its bounding box, where the handles are.
|
|
2493
|
+
* - **Panning.** A press with the hand tool, or with space held, still pans.
|
|
2494
|
+
*
|
|
2495
|
+
* It does not draw a new shape (`DraftShape` previews one while the app's tool does), and does
|
|
2496
|
+
* not keep the shape inside the image.
|
|
2497
|
+
*
|
|
2498
|
+
* The SVG carries `data-editable`; the outline carries `data-shape`.
|
|
2499
|
+
*/
|
|
2500
|
+
export declare function ShapeEditor({ kind, value, onValueChange, onCommit, editable, rotatable, minSize, label, stroke }: ShapeEditorProps): import("react").JSX.Element;
|
|
2501
|
+
//#endregion
|
|
2502
|
+
//#region src/components/DraftShape.d.ts
|
|
2503
|
+
/**
|
|
2504
|
+
* The shape being drawn.
|
|
2505
|
+
* - `point`: a position.
|
|
2506
|
+
* - `line`: a segment from `from` to `to`.
|
|
2507
|
+
* - `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.
|
|
2509
|
+
* - `rect` and `ellipse`: two opposite corners of the axis-aligned box (the drag's start and
|
|
2510
|
+
* the pointer).
|
|
2511
|
+
*/
|
|
2512
|
+
type DraftShapeSpec = {
|
|
2513
|
+
kind: "point";
|
|
2514
|
+
x: number;
|
|
2515
|
+
y: number;
|
|
2516
|
+
} | {
|
|
2517
|
+
kind: "line";
|
|
2518
|
+
from: Point;
|
|
2519
|
+
to: Point;
|
|
2520
|
+
} | {
|
|
2521
|
+
kind: "polyline";
|
|
2522
|
+
points: ArrayLike<number>;
|
|
2523
|
+
cursor?: Point | undefined;
|
|
2524
|
+
} | {
|
|
2525
|
+
kind: "polygon";
|
|
2526
|
+
points: ArrayLike<number>;
|
|
2527
|
+
cursor?: Point | undefined;
|
|
2528
|
+
} | {
|
|
2529
|
+
kind: "rect";
|
|
2530
|
+
from: Point;
|
|
2531
|
+
to: Point;
|
|
2532
|
+
} | {
|
|
2533
|
+
kind: "ellipse";
|
|
2534
|
+
from: Point;
|
|
2535
|
+
to: Point;
|
|
2536
|
+
};
|
|
2537
|
+
/** Props of `DraftShape`. */
|
|
2538
|
+
interface DraftShapeProps {
|
|
2539
|
+
/** The shape so far, or `null` when nothing is being drawn. */
|
|
2540
|
+
shape: DraftShapeSpec | null;
|
|
2541
|
+
/** The overlay role it is drawn in. Defaults to `"selection"`, the accent. */
|
|
2542
|
+
role?: OverlayRole | undefined;
|
|
2543
|
+
/** Draw the dark band under the outline. On by default. */
|
|
2544
|
+
halo?: boolean | undefined;
|
|
2545
|
+
}
|
|
2546
|
+
/**
|
|
2547
|
+
* A dashed preview of a shape being drawn, inside an `ImageStage`.
|
|
2548
|
+
*
|
|
2549
|
+
* The outline is 1.5 screen px, dashed 6 4 screen px, in the accent (`selection`) role by
|
|
2550
|
+
* default, with a halo; regions (`polygon`, `rect`, `ellipse`) carry the 12 % fill. A polyline
|
|
2551
|
+
* 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
|
|
2553
|
+
* from assistive technology: it is transient feedback for a gesture.
|
|
2554
|
+
*
|
|
2555
|
+
* The SVG carries `data-draft` (the shape's kind).
|
|
2556
|
+
*/
|
|
2557
|
+
export declare function DraftShape({ shape, role, halo }: DraftShapeProps): import("react").JSX.Element;
|
|
2558
|
+
/** Props of `MarqueeRect`. */
|
|
2559
|
+
interface MarqueeRectProps {
|
|
2560
|
+
/** The band in image coordinates, or `null` when no band is being dragged. */
|
|
2561
|
+
rect: Rect | null;
|
|
2562
|
+
/** CSS colour of the band. Defaults to the overlay `selection` role. */
|
|
2563
|
+
stroke?: string | undefined;
|
|
2564
|
+
}
|
|
2565
|
+
/**
|
|
2566
|
+
* The rubber band of a multi-select, inside an `ImageStage`: the 12 % fill and a 1 screen px
|
|
2567
|
+
* outline in the selection colour, the same as `PolylineSet`'s own band. Feed it the box
|
|
2568
|
+
* between the press and the pointer from `StageSurface`, and the box to `pointsInRect`,
|
|
2569
|
+
* `polylinesInRect` or `areasInRect` at the release. It takes no pointer events.
|
|
2570
|
+
*
|
|
2571
|
+
* The SVG carries `data-marquee`.
|
|
2572
|
+
*/
|
|
2573
|
+
export declare function MarqueeRect({ rect, stroke }: MarqueeRectProps): import("react").JSX.Element;
|
|
2574
|
+
//#endregion
|
|
2575
|
+
//#region src/components/useShapeDrag.d.ts
|
|
2576
|
+
/** What a shape drag does as the pointer moves and when it ends. Displacements are total, from the press. */
|
|
2577
|
+
interface ShapeDragHandlers {
|
|
2578
|
+
/**
|
|
2579
|
+
* Each move of the pointer once it has left the click slop: how far it is from where the
|
|
2580
|
+
* press landed, in image pixels. Draw the shape shifted by it.
|
|
2581
|
+
*/
|
|
2582
|
+
onMove?: ((delta: Point, event: PointerEvent) => void) | undefined;
|
|
2583
|
+
/**
|
|
2584
|
+
* The release. `moved` is whether the pointer ever left the click slop; when it did not,
|
|
2585
|
+
* `delta` is `{ x: 0, y: 0 }` and the press was a click. Commit the shape shifted by `delta`.
|
|
2586
|
+
*/
|
|
2587
|
+
onEnd?: ((delta: Point, moved: boolean, event: PointerEvent) => void) | undefined;
|
|
2588
|
+
/** The drag was interrupted (`pointercancel`) or the component unmounted mid-drag: drop the preview. */
|
|
2589
|
+
onCancel?: (() => void) | undefined;
|
|
2590
|
+
}
|
|
2591
|
+
/** Options of the function `useShapeDrag` returns. */
|
|
2592
|
+
interface ShapeDragOptions {
|
|
2593
|
+
/** How far the pointer may travel before the press is a drag, in screen pixels. Defaults to 3. */
|
|
2594
|
+
slop?: number | undefined;
|
|
2595
|
+
}
|
|
2596
|
+
/**
|
|
2597
|
+
* Start moving a shape from a press, inside an `ImageStage`.
|
|
2598
|
+
*
|
|
2599
|
+
* Returns `start(event, handlers, options?)`. Call it from `onItemPress` of a layer with the
|
|
2600
|
+
* press event: the press is claimed, so the stage does not pan, and the pointer is followed on
|
|
2601
|
+
* `window` until it is released, whether or not it leaves the canvas. A touch tap reaches
|
|
2602
|
+
* `onItemPress` on release, so there is nothing to follow: it ends at once as a click
|
|
2603
|
+
* (`moved` false). Move a shape on touch with `ShapeEditor`'s handles or the app's own mode.
|
|
2604
|
+
*
|
|
2605
|
+
* @returns `start`.
|
|
2606
|
+
*/
|
|
2607
|
+
export declare function useShapeDrag(): (event: StagePointerEvent, handlers: ShapeDragHandlers, options?: ShapeDragOptions) => void;
|
|
2608
|
+
/**
|
|
2609
|
+
* Move flat points by a displacement.
|
|
2610
|
+
*
|
|
2611
|
+
* @param points - `[x0, y0, x1, y1, …]`.
|
|
2612
|
+
* @param delta - The displacement, in the points' units.
|
|
2613
|
+
* @returns A new array, `points` shifted.
|
|
2614
|
+
*/
|
|
2615
|
+
export declare function translatePoints(points: ArrayLike<number>, delta: Point): number[];
|
|
2616
|
+
//#endregion
|
|
1634
2617
|
//#region src/components/MaskEditor.d.ts
|
|
1635
2618
|
/** Paint a continuous round stroke into a copied binary mask. Pixel centers are integers. */
|
|
1636
2619
|
export declare function paintMask(mask: Uint8Array, width: number, height: number, from: Point, to: Point, radius: number, value: 0 | 1): Uint8Array;
|
|
@@ -1656,5 +2639,5 @@ interface MaskEditorProps {
|
|
|
1656
2639
|
/** Render and edit a binary raster mask within the enclosing ImageStage. */
|
|
1657
2640
|
export declare function MaskEditor({ mask, onChange, onCommit, editable, brushRadius, mode, label, color }: MaskEditorProps): import("react").JSX.Element;
|
|
1658
2641
|
//#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 };
|
|
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 };
|
|
1660
2643
|
//# sourceMappingURL=index.d.ts.map
|