@vitavision/stage2d 0.8.0 → 0.9.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 +14 -0
- package/dist/index.d.ts +381 -3
- package/dist/index.js +1090 -61
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/PointSet.tsx +391 -0
- package/src/components/PolylineSet.tsx +39 -0
- package/src/components/markerShapes.ts +119 -0
- package/src/components/pointIndex.ts +320 -0
- package/src/components/stage/ImageStage.tsx +264 -59
- package/src/components/stage/gesture.ts +81 -0
- package/src/components/stage/hitContext.ts +16 -0
- package/src/components/stage/hitTest.ts +181 -0
- package/src/components/stage/useStageHitTest.ts +127 -0
- package/src/index.ts +35 -0
package/README.md
CHANGED
|
@@ -49,6 +49,20 @@ batched paths and picks through a spatial index, not the DOM.
|
|
|
49
49
|
`polylinePath` are pure; hit-testing is microseconds at 100k segments
|
|
50
50
|
(`docs/measurements/u4-polyline-set.md`).
|
|
51
51
|
|
|
52
|
+
**Points**: `PointSet` draws many points (corners, ring centres, keypoints, labelled landmarks) as
|
|
53
|
+
a few batched paths, with a marker per kind (`dot`, `plus`, `cross`, `square`, `hollow`,
|
|
54
|
+
`directed`, or your own path generator) and the same states as `PolylineSet`, plus a ring on the
|
|
55
|
+
selected. Labels appear where points are 24 screen px apart.
|
|
56
|
+
- **Pointer:** `onHoverChange` and `onItemPress` come from the stage's pointer handling and the
|
|
57
|
+
layer's index, not from per-point elements.
|
|
58
|
+
- **Pure functions:** `buildPointIndex`, `nearestPoint`, `pointsInRect` and `thinPoints`
|
|
59
|
+
(`docs/measurements/l6-2a-points-hit-test.md`).
|
|
60
|
+
|
|
61
|
+
**Hit-test**: `useStageHitTest()` answers "what is under the pointer" across layers, ranked by
|
|
62
|
+
`STAGE_HIT_PRIORITY` (points above lines above areas above images). `PointSet` and `PolylineSet`
|
|
63
|
+
answer it; `useStageHitLayer` registers any other layer. `ImageStage` also takes `panButton`,
|
|
64
|
+
`doubleClickFit` and `touchPan`, and handles two-finger pinch.
|
|
65
|
+
|
|
52
66
|
**Tool model**: `StageSurface` is the one full-frame press target per stage.
|
|
53
67
|
- **Claiming:** its `onPress` returns a drag to claim a press, or nothing to let the stage pan.
|
|
54
68
|
- **Drags:** `useStageDrag` starts a window-level drag from any element, e.g. a handle.
|
package/dist/index.d.ts
CHANGED
|
@@ -219,6 +219,10 @@ export declare function steppedScale(scale: number, direction: 1 | -1, min: numb
|
|
|
219
219
|
/** `0.5` → `"50%"`, `1` → `"100%"`, `0.0833` → `"8%"`. */
|
|
220
220
|
export declare function formatScale(scale: number): string;
|
|
221
221
|
//#endregion
|
|
222
|
+
//#region src/components/stage/gesture.d.ts
|
|
223
|
+
/** A mouse button that can pan the stage. */
|
|
224
|
+
type StageMouseButton = "left" | "middle" | "right";
|
|
225
|
+
//#endregion
|
|
222
226
|
//#region src/components/stage/ImageStage.d.ts
|
|
223
227
|
/** What `useStage` returns: the transform of the enclosing `ImageStage`, and its controls. */
|
|
224
228
|
interface StageContext {
|
|
@@ -298,6 +302,26 @@ interface ImageStageProps {
|
|
|
298
302
|
banner?: ReactNode;
|
|
299
303
|
/** Force panning regardless of where the press lands (a "hand tool"). */
|
|
300
304
|
panTool?: boolean;
|
|
305
|
+
/**
|
|
306
|
+
* The mouse buttons that pan on drag, over background no layer claimed. Defaults to
|
|
307
|
+
* `["left", "middle"]`. An app whose left button belongs to the active drawing tool passes
|
|
308
|
+
* `"right"`; the context menu is then suppressed on the stage, since the button's job is
|
|
309
|
+
* to drag. The hand tool and a held space bar still pan with the left button.
|
|
310
|
+
*/
|
|
311
|
+
panButton?: StageMouseButton | readonly StageMouseButton[] | undefined;
|
|
312
|
+
/**
|
|
313
|
+
* Whether a double-click toggles fit and the previous view. On by default; turn it off in
|
|
314
|
+
* an app whose tools use double-click, such as closing a polygon.
|
|
315
|
+
*/
|
|
316
|
+
doubleClickFit?: boolean | undefined;
|
|
317
|
+
/**
|
|
318
|
+
* What one finger does on background no layer claimed: `"one-finger"` (the default) pans,
|
|
319
|
+
* as the mouse does; `"two-finger"` leaves it to the app's tools and pans only with two.
|
|
320
|
+
* Two fingers always pinch-zoom about their midpoint and pan with it. A tap (a touch that
|
|
321
|
+
* stays put and is short) is a press: a layer's `onItemPress` hears it, or else
|
|
322
|
+
* `onBackgroundClick`.
|
|
323
|
+
*/
|
|
324
|
+
touchPan?: "one-finger" | "two-finger" | undefined;
|
|
301
325
|
/** Merged onto the viewport with `cn`. */
|
|
302
326
|
className?: string;
|
|
303
327
|
/** Inline style for the viewport. */
|
|
@@ -336,7 +360,107 @@ interface ImageStageProps {
|
|
|
336
360
|
* is in progress) and `data-pan-mode` (the hand tool is on or space is held), each present
|
|
337
361
|
* or absent.
|
|
338
362
|
*/
|
|
339
|
-
export declare function ImageStage({ image, view, onView, children, toolbar, readout, banner, panTool, className, style, onHover, onBackgroundClick, clamp, shortcuts, panKeys, label, initialView: opening, ref }: ImageStageProps): import("react").JSX.Element;
|
|
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;
|
|
364
|
+
//#endregion
|
|
365
|
+
//#region src/components/stage/hitTest.d.ts
|
|
366
|
+
/** What a layer is picked as, and so how it ranks against the layers around it. */
|
|
367
|
+
export declare const STAGE_HIT_PRIORITY: {
|
|
368
|
+
/** A raster layer: only picked when nothing else is. */
|
|
369
|
+
readonly image: 0;
|
|
370
|
+
/** A filled region or heatmap cell. */
|
|
371
|
+
readonly area: 100;
|
|
372
|
+
/** A line or contour. */
|
|
373
|
+
readonly line: 200;
|
|
374
|
+
/** A marker: small, so it wins over what it sits on. */
|
|
375
|
+
readonly point: 300;
|
|
376
|
+
};
|
|
377
|
+
/** An item's identity within its layer. */
|
|
378
|
+
type HitId = string | number;
|
|
379
|
+
/** What a layer's `pick` returns: the item, and how far from the pointer it is. */
|
|
380
|
+
interface HitCandidate {
|
|
381
|
+
/** The item's id. */
|
|
382
|
+
id: HitId;
|
|
383
|
+
/** Distance from the query point, in image pixels. Compared only within one priority. */
|
|
384
|
+
dist: number;
|
|
385
|
+
}
|
|
386
|
+
/** One answer to a hit-test. */
|
|
387
|
+
interface StageHit extends HitCandidate {
|
|
388
|
+
/** The layer that answered. */
|
|
389
|
+
layerId: string;
|
|
390
|
+
/** The layer's priority. */
|
|
391
|
+
priority: number;
|
|
392
|
+
}
|
|
393
|
+
/** Options of a hit-test. */
|
|
394
|
+
interface StageHitOptions {
|
|
395
|
+
/** Consider only layers whose presses are claimed (`pressable`). */
|
|
396
|
+
pressable?: boolean | undefined;
|
|
397
|
+
}
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region src/components/stage/hitContext.d.ts
|
|
400
|
+
/** The press event a layer's `press` handler receives. */
|
|
401
|
+
type StagePointerEvent = PointerEvent$1<Element>;
|
|
402
|
+
//#endregion
|
|
403
|
+
//#region src/components/stage/useStageHitTest.d.ts
|
|
404
|
+
/** What `useStageHitTest` returns. */
|
|
405
|
+
interface StageHitTestApi {
|
|
406
|
+
/**
|
|
407
|
+
* The best item under a point across every layer, or `null`.
|
|
408
|
+
*
|
|
409
|
+
* @param point - In image coordinates, e.g. a `StagePress.point`.
|
|
410
|
+
* @param radiusScreenPx - The pointer's tolerance in screen pixels. Defaults to 6.
|
|
411
|
+
* @param options - `pressable` limits the answer to layers that claim presses.
|
|
412
|
+
*/
|
|
413
|
+
hitTest: (point: Point, radiusScreenPx?: number, options?: StageHitOptions) => StageHit | null;
|
|
414
|
+
/**
|
|
415
|
+
* Every layer's best item under a point, best first: higher priority, then nearer.
|
|
416
|
+
* Parameters as `hitTest`.
|
|
417
|
+
*/
|
|
418
|
+
hitTestAll: (point: Point, radiusScreenPx?: number, options?: StageHitOptions) => StageHit[];
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* The stage's one hit-test, across every registered layer (`PointSet`, `PolylineSet`, and
|
|
422
|
+
* any layer built with `useStageHitLayer`). A press handler uses it to decide what a press
|
|
423
|
+
* means: an item under the pointer is selected, bare image is drawn on or panned.
|
|
424
|
+
*
|
|
425
|
+
* The answer comes from each layer's spatial index, never from the DOM, so it costs
|
|
426
|
+
* microseconds at any scene size.
|
|
427
|
+
*
|
|
428
|
+
* @returns `{ hitTest, hitTestAll }`.
|
|
429
|
+
* @throws `Error` outside an `ImageStage`, which is always a wiring bug.
|
|
430
|
+
*/
|
|
431
|
+
export declare function useStageHitTest(): StageHitTestApi;
|
|
432
|
+
/** What a layer passes `useStageHitLayer`. */
|
|
433
|
+
interface StageHitLayerOptions {
|
|
434
|
+
/** The id hits report. Defaults to a generated, stable one; set it to tell layers apart. */
|
|
435
|
+
layerId?: string | undefined;
|
|
436
|
+
/** Rank against other layers; see `STAGE_HIT_PRIORITY`. */
|
|
437
|
+
priority: number;
|
|
438
|
+
/**
|
|
439
|
+
* The item under `point`, if any, within `radius` image pixels. Use the layer's index
|
|
440
|
+
* (`nearestPoint`, `nearestPolyline`), not the DOM.
|
|
441
|
+
*/
|
|
442
|
+
pick: (point: Point, radius: number) => HitCandidate | null;
|
|
443
|
+
/**
|
|
444
|
+
* The hovered item changed. Setting this makes the stage route hover to the layer; the
|
|
445
|
+
* best item under the pointer across layers is the hovered one.
|
|
446
|
+
*/
|
|
447
|
+
onHover?: ((id: HitId | null) => void) | undefined;
|
|
448
|
+
/**
|
|
449
|
+
* A press landed on an item and nothing above it claimed it. Setting this makes the layer
|
|
450
|
+
* claim presses on its items, so the stage does not pan from them. Return `false` to
|
|
451
|
+
* decline one. For a touch tap this is the `pointerup`.
|
|
452
|
+
*/
|
|
453
|
+
onPress?: ((id: HitId, event: StagePointerEvent) => boolean | void) | undefined;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Register a layer with the stage's hit-test. The callbacks may change every render; the
|
|
457
|
+
* registration does not, so a layer is never missing from a hit-test for a frame.
|
|
458
|
+
*
|
|
459
|
+
* @param options - How the layer answers `pick`, and whether it takes hover and presses.
|
|
460
|
+
* @returns The layer's id, as hits report it.
|
|
461
|
+
* @throws `Error` outside an `ImageStage`.
|
|
462
|
+
*/
|
|
463
|
+
export declare function useStageHitLayer(options: StageHitLayerOptions): string;
|
|
340
464
|
//#endregion
|
|
341
465
|
//#region src/components/stage/ImageLayer.d.ts
|
|
342
466
|
/**
|
|
@@ -1141,6 +1265,17 @@ interface PolylineSetProps {
|
|
|
1141
1265
|
hovered?: PolylineId | null | undefined;
|
|
1142
1266
|
/** Called when the line under the pointer changes. */
|
|
1143
1267
|
onHover?: ((id: PolylineId | null) => void) | undefined;
|
|
1268
|
+
/**
|
|
1269
|
+
* Called when the line under the pointer changes: the same as `onHover`, under the name
|
|
1270
|
+
* `PointSet` uses, so an app handles every layer's hover alike.
|
|
1271
|
+
*/
|
|
1272
|
+
onHoverChange?: ((id: PolylineId | null) => void) | undefined;
|
|
1273
|
+
/**
|
|
1274
|
+
* Called when a press lands on a line, with the `pointerdown`, before `onSelect`. It does
|
|
1275
|
+
* not fire for a rubber band, nor when a point of a `PointSet` over the line takes the
|
|
1276
|
+
* press instead.
|
|
1277
|
+
*/
|
|
1278
|
+
onItemPress?: ((id: PolylineId, event: PointerEvent$1<SVGPathElement>) => void) | undefined;
|
|
1144
1279
|
/**
|
|
1145
1280
|
* Called on a selection gesture.
|
|
1146
1281
|
* - A click on a line → `[id]`, "replace".
|
|
@@ -1165,6 +1300,10 @@ interface PolylineSetProps {
|
|
|
1165
1300
|
vertexScale?: number | undefined;
|
|
1166
1301
|
/** The layer's accessible name. Defaults to "Lines". */
|
|
1167
1302
|
label?: string | undefined;
|
|
1303
|
+
/** The id hit-tests report for this layer. Defaults to a generated one. */
|
|
1304
|
+
layerId?: string | undefined;
|
|
1305
|
+
/** Rank against other layers in hit-tests. Defaults to `STAGE_HIT_PRIORITY.line`. */
|
|
1306
|
+
priority?: number | undefined;
|
|
1168
1307
|
}
|
|
1169
1308
|
/**
|
|
1170
1309
|
* A selectable set of polylines inside an `ImageStage`.
|
|
@@ -1180,7 +1319,246 @@ interface PolylineSetProps {
|
|
|
1180
1319
|
*
|
|
1181
1320
|
* The SVG carries `data-hovered` (the hovered id) and `data-sweeping` while a band is drawn.
|
|
1182
1321
|
*/
|
|
1183
|
-
export declare function PolylineSet({ items, selected, dimmed, hovered, onHover, onSelect, marquee, stroke, selectionStroke, hitWidth, vertexScale, label }: PolylineSetProps): import("react").JSX.Element;
|
|
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;
|
|
1323
|
+
//#endregion
|
|
1324
|
+
//#region src/components/markerShapes.d.ts
|
|
1325
|
+
/** One kind of marker. */
|
|
1326
|
+
interface MarkerShape {
|
|
1327
|
+
/**
|
|
1328
|
+
* How the path is painted:
|
|
1329
|
+
* - `"disc"`: `path` returns a zero-length segment per marker; the stroke width is the
|
|
1330
|
+
* disc's diameter. Independent of `unit`, so a batched path survives a zoom unchanged.
|
|
1331
|
+
* - `"line"`: `path` returns an outline, stroked at the state's width.
|
|
1332
|
+
*/
|
|
1333
|
+
readonly paint: "disc" | "line";
|
|
1334
|
+
/** Half the glyph's extent in screen pixels at rest: a disc's radius, a plus's arm. */
|
|
1335
|
+
readonly size: number;
|
|
1336
|
+
/** The role a marker of this kind has unless the item says otherwise. Defaults to `feature`. */
|
|
1337
|
+
readonly role?: OverlayRole | undefined;
|
|
1338
|
+
/**
|
|
1339
|
+
* The path data for one marker.
|
|
1340
|
+
*
|
|
1341
|
+
* @param x - Centre x, in image coordinates.
|
|
1342
|
+
* @param y - Centre y, in image coordinates.
|
|
1343
|
+
* @param unit - Image pixels per screen pixel.
|
|
1344
|
+
* @param angle - The item's orientation in radians, `0` when it has none.
|
|
1345
|
+
* @returns Path commands, absolute at the start (`M x y …`) and self-contained.
|
|
1346
|
+
*/
|
|
1347
|
+
path: (x: number, y: number, unit: number, angle: number) => string;
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* A circle as two arcs, centred at `(x, y)`.
|
|
1351
|
+
*
|
|
1352
|
+
* @param x - Centre x.
|
|
1353
|
+
* @param y - Centre y.
|
|
1354
|
+
* @param r - Radius, in the units of `x` and `y`.
|
|
1355
|
+
* @returns Path data.
|
|
1356
|
+
*/
|
|
1357
|
+
export declare function circlePath(x: number, y: number, r: number): string;
|
|
1358
|
+
/** The names of the built-in marker kinds. */
|
|
1359
|
+
type BuiltinMarkerKind = "dot" | "plus" | "cross" | "square" | "hollow" | "directed";
|
|
1360
|
+
/** The built-in kinds, with the overlay grammar's glyph for each. */
|
|
1361
|
+
export declare const MARKER_SHAPES: Readonly<Record<BuiltinMarkerKind, MarkerShape>>;
|
|
1362
|
+
//#endregion
|
|
1363
|
+
//#region src/components/pointIndex.d.ts
|
|
1364
|
+
/** A point's identity. */
|
|
1365
|
+
type PointId = string | number;
|
|
1366
|
+
/** The shape `buildPointIndexFrom` reads from each item. */
|
|
1367
|
+
interface PointItem {
|
|
1368
|
+
/** Its identity, unique in the set. */
|
|
1369
|
+
id: PointId;
|
|
1370
|
+
/** Horizontal position, in image coordinates. */
|
|
1371
|
+
x: number;
|
|
1372
|
+
/** Vertical position, in image coordinates. */
|
|
1373
|
+
y: number;
|
|
1374
|
+
/** How far from the point a query still picks it, in image pixels. Defaults to `0`. */
|
|
1375
|
+
pickRadius?: number | undefined;
|
|
1376
|
+
}
|
|
1377
|
+
/** Options of `buildPointIndex`. */
|
|
1378
|
+
interface PointIndexOptions {
|
|
1379
|
+
/** Ids by point index. Defaults to the index itself. */
|
|
1380
|
+
ids?: ArrayLike<PointId> | undefined;
|
|
1381
|
+
/**
|
|
1382
|
+
* Per-point pick radius, in image pixels. A query at distance `d` from point `i` picks it
|
|
1383
|
+
* when `d ≤ radius + radii[i]`, so a ring marker whose circle is data (it scales with the
|
|
1384
|
+
* image) can be picked anywhere on it. Defaults to `0` for every point.
|
|
1385
|
+
*/
|
|
1386
|
+
radii?: ArrayLike<number> | undefined;
|
|
1387
|
+
/**
|
|
1388
|
+
* The grid cell side, in image pixels. Defaults to a side that puts about two points in
|
|
1389
|
+
* each cell, bounded to `[4, 256]`.
|
|
1390
|
+
*/
|
|
1391
|
+
cell?: number | undefined;
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* An index built by `buildPointIndex`. Treat it as opaque and query it with `nearestPoint`,
|
|
1395
|
+
* `pointsInRect` and `thinPoints`; its layout may change.
|
|
1396
|
+
*/
|
|
1397
|
+
interface PointIndex {
|
|
1398
|
+
/** The number of points given, indexed or not. */
|
|
1399
|
+
readonly count: number;
|
|
1400
|
+
/** The points, flat `[x0, y0, …]`. Not copied: do not change it after building. */
|
|
1401
|
+
readonly xy: ArrayLike<number>;
|
|
1402
|
+
/** Ids by point index, or `null` when a point's id is its index. */
|
|
1403
|
+
readonly ids: ArrayLike<PointId> | null;
|
|
1404
|
+
/** Per-point pick radii, or `null` when every point has none. */
|
|
1405
|
+
readonly radii: ArrayLike<number> | null;
|
|
1406
|
+
/** The largest pick radius, widening every query window. */
|
|
1407
|
+
readonly maxRadius: number;
|
|
1408
|
+
/** Grid cell side, in image pixels. */
|
|
1409
|
+
readonly cell: number;
|
|
1410
|
+
/** The grid's origin x. */
|
|
1411
|
+
readonly x0: number;
|
|
1412
|
+
/** The grid's origin y. */
|
|
1413
|
+
readonly y0: number;
|
|
1414
|
+
/** Grid columns. */
|
|
1415
|
+
readonly cols: number;
|
|
1416
|
+
/** Grid rows. */
|
|
1417
|
+
readonly rows: number;
|
|
1418
|
+
/** CSR layout: cell `c`'s entries are `items[starts[c] .. starts[c + 1]]`. */
|
|
1419
|
+
readonly starts: Uint32Array;
|
|
1420
|
+
/** Point indices by cell, ascending within a cell. */
|
|
1421
|
+
readonly items: Uint32Array;
|
|
1422
|
+
}
|
|
1423
|
+
/** The nearest point to a query. */
|
|
1424
|
+
interface PointHit {
|
|
1425
|
+
/** Its index in the array the index was built from. */
|
|
1426
|
+
index: number;
|
|
1427
|
+
/** Its id. */
|
|
1428
|
+
id: PointId;
|
|
1429
|
+
/** The distance from the query to the point's centre, in image pixels. */
|
|
1430
|
+
dist: number;
|
|
1431
|
+
}
|
|
1432
|
+
/**
|
|
1433
|
+
* Index a set of points.
|
|
1434
|
+
*
|
|
1435
|
+
* @param xy - Flat `[x0, y0, x1, y1, …]` in image coordinates; a `Float32Array` or
|
|
1436
|
+
* `Float64Array` avoids a copy at the call site.
|
|
1437
|
+
* @param options - Ids, per-point pick radii and the cell side.
|
|
1438
|
+
* @returns The index.
|
|
1439
|
+
*/
|
|
1440
|
+
export declare function buildPointIndex(xy: ArrayLike<number>, options?: PointIndexOptions): PointIndex;
|
|
1441
|
+
/**
|
|
1442
|
+
* Index items that carry their own position.
|
|
1443
|
+
*
|
|
1444
|
+
* @param items - The points, in order.
|
|
1445
|
+
* @param cell - The grid cell side; see `PointIndexOptions`.
|
|
1446
|
+
* @returns The index; its point indices are positions in `items`.
|
|
1447
|
+
*/
|
|
1448
|
+
export declare function buildPointIndexFrom(items: readonly PointItem[], cell?: number): PointIndex;
|
|
1449
|
+
/**
|
|
1450
|
+
* The point nearest to `(x, y)` whose pick disc reaches it, or `null`.
|
|
1451
|
+
*
|
|
1452
|
+
* @param index - The index.
|
|
1453
|
+
* @param x - The query's x, in image coordinates.
|
|
1454
|
+
* @param y - The query's y, in image coordinates.
|
|
1455
|
+
* @param radius - How far from a point's centre the query still picks it, in image pixels.
|
|
1456
|
+
* For a screen-constant tolerance, pass `useScreenPx()(css)`. A point's own `radii` entry
|
|
1457
|
+
* adds to it.
|
|
1458
|
+
* @returns The point nearest by centre distance; ties go to the lower index, so the result
|
|
1459
|
+
* does not depend on cell order.
|
|
1460
|
+
*/
|
|
1461
|
+
export declare function nearestPoint(index: PointIndex, x: number, y: number, radius: number): PointHit | null;
|
|
1462
|
+
/**
|
|
1463
|
+
* The points whose centre is inside `rect`, edges included.
|
|
1464
|
+
*
|
|
1465
|
+
* @param index - The index.
|
|
1466
|
+
* @param rect - The band, in image coordinates. A negative extent is read as the box
|
|
1467
|
+
* between its corners.
|
|
1468
|
+
* @returns Their indices, ascending.
|
|
1469
|
+
*/
|
|
1470
|
+
export declare function pointsInRect(index: PointIndex, rect: Rect): number[];
|
|
1471
|
+
/**
|
|
1472
|
+
* A greedy thinning: walk the points in `order` and keep each one that is at least `minDist`
|
|
1473
|
+
* from every point kept so far. This is how a label layer decides which labels the zoom has
|
|
1474
|
+
* room for.
|
|
1475
|
+
*
|
|
1476
|
+
* The result is *maximal*: every point left out is within `minDist` of one kept before it,
|
|
1477
|
+
* and every pair kept is at least `minDist` apart.
|
|
1478
|
+
*
|
|
1479
|
+
* @param xy - Flat points, in the units `minDist` is in (image pixels for a screen-px spacing
|
|
1480
|
+
* converted with `useScreenPx`).
|
|
1481
|
+
* @param minDist - The least distance between two kept points.
|
|
1482
|
+
* @param order - Point indices in priority order. Defaults to every point, in order.
|
|
1483
|
+
* Indices of non-finite points are skipped.
|
|
1484
|
+
* @returns The kept indices, in the order they were kept.
|
|
1485
|
+
*/
|
|
1486
|
+
export declare function thinPoints(xy: ArrayLike<number>, minDist: number, order?: Iterable<number>): number[];
|
|
1487
|
+
//#endregion
|
|
1488
|
+
//#region src/components/PointSet.d.ts
|
|
1489
|
+
/** One point of a `PointSet`. */
|
|
1490
|
+
interface PointSetItem extends PointItem {
|
|
1491
|
+
/**
|
|
1492
|
+
* The marker kind: a built-in (`dot`, `plus`, `cross`, `square`, `hollow`, `directed`) or
|
|
1493
|
+
* a key of the layer's `markers`. Defaults to the layer's `kind`.
|
|
1494
|
+
*/
|
|
1495
|
+
kind?: string | undefined;
|
|
1496
|
+
/** The overlay role it is painted in. Defaults to the marker kind's role, usually `feature`. */
|
|
1497
|
+
role?: OverlayRole | undefined;
|
|
1498
|
+
/** Its orientation in radians, clockwise from +x; read by `directed`. */
|
|
1499
|
+
angle?: number | undefined;
|
|
1500
|
+
/** Text drawn beside it, when the zoom leaves room (points at least 24 screen px apart). */
|
|
1501
|
+
label?: string | undefined;
|
|
1502
|
+
}
|
|
1503
|
+
/** Props of `PointSet`. */
|
|
1504
|
+
interface PointSetProps {
|
|
1505
|
+
/** The points, in image coordinates. */
|
|
1506
|
+
items: readonly PointSetItem[];
|
|
1507
|
+
/** The marker kind of an item that names none. Defaults to `"dot"`. */
|
|
1508
|
+
kind?: string | undefined;
|
|
1509
|
+
/** More marker kinds, or replacements for built-in ones, by name. */
|
|
1510
|
+
markers?: Readonly<Record<string, MarkerShape>> | undefined;
|
|
1511
|
+
/** The hovered id, when the app controls hover (a list beside the stage hovers points too). */
|
|
1512
|
+
hoveredId?: PointId | null | undefined;
|
|
1513
|
+
/** Called when the point under the pointer changes. `null` when it leaves every point. */
|
|
1514
|
+
onHoverChange?: ((id: PointId | null) => void) | undefined;
|
|
1515
|
+
/** The selected ids, drawn at 2.5 px in the selection colour with a ring. */
|
|
1516
|
+
selectedIds?: Iterable<PointId> | undefined;
|
|
1517
|
+
/**
|
|
1518
|
+
* Ids drawn at 35 % opacity, as a set or a predicate (outside the current filter, say).
|
|
1519
|
+
* They still take hover and presses. Pass a stable value: a new one re-batches the layer.
|
|
1520
|
+
*/
|
|
1521
|
+
dimmed?: Iterable<PointId> | ((id: PointId) => boolean) | undefined;
|
|
1522
|
+
/**
|
|
1523
|
+
* A press landed on a point. Setting it makes the layer claim presses on its points, so
|
|
1524
|
+
* the stage does not pan from them. The event is the `pointerdown` (the `pointerup` for a
|
|
1525
|
+
* touch tap), so `useStageDrag` can start a drag from it.
|
|
1526
|
+
*
|
|
1527
|
+
* A mounted `StageSurface` hears a press first; there, ask `useStageHitTest` what is
|
|
1528
|
+
* under it instead.
|
|
1529
|
+
*/
|
|
1530
|
+
onItemPress?: ((id: PointId, event: StagePointerEvent) => void) | undefined;
|
|
1531
|
+
/** Show the items' `label`s where the zoom leaves room for them. On by default. */
|
|
1532
|
+
labels?: boolean | undefined;
|
|
1533
|
+
/** Draw the dark band under every mark. On by default; off for a fast, flat layer. */
|
|
1534
|
+
halo?: boolean | undefined;
|
|
1535
|
+
/** CSS colour of selected points and rings. Defaults to the overlay `selection` role. */
|
|
1536
|
+
selectionStroke?: string | undefined;
|
|
1537
|
+
/** The id hit-tests report for this layer. Defaults to a generated one. */
|
|
1538
|
+
layerId?: string | undefined;
|
|
1539
|
+
/** Rank against other layers in hit-tests. Defaults to `STAGE_HIT_PRIORITY.point`. */
|
|
1540
|
+
priority?: number | undefined;
|
|
1541
|
+
/** The layer's accessible name. Defaults to "Points". */
|
|
1542
|
+
label?: string | undefined;
|
|
1543
|
+
}
|
|
1544
|
+
/**
|
|
1545
|
+
* A selectable set of points inside an `ImageStage`.
|
|
1546
|
+
*
|
|
1547
|
+
* - **Markers** by kind, from the overlay grammar: `dot`, `plus` (corner), `cross`, `square`,
|
|
1548
|
+
* `hollow` (predicted), `directed`. Add your own through `markers`.
|
|
1549
|
+
* - **States**, from visual-language §5: default 1.5 screen px, hover 2, selected 2.5 in the
|
|
1550
|
+
* selection colour with a ring, dimmed at 35 % opacity. Every mark has a halo.
|
|
1551
|
+
* - **Labels** only where points are at least 24 screen px apart, at most 200 at a time.
|
|
1552
|
+
* - **Picking** goes through the stage's hit registry: `onHoverChange` and `onItemPress` here,
|
|
1553
|
+
* and `useStageHitTest` for an app that arbitrates between layers.
|
|
1554
|
+
*
|
|
1555
|
+
* Outlines (`plus`, `cross`, …) are regenerated when the zoom changes, since their size is in
|
|
1556
|
+
* screen pixels; past 3,000 points only those near the viewport are generated. `dot` is a
|
|
1557
|
+
* zero-length stroke whose width is its size, so it is not regenerated at all.
|
|
1558
|
+
*
|
|
1559
|
+
* The SVG carries `data-hovered` (the hovered id).
|
|
1560
|
+
*/
|
|
1561
|
+
export declare function PointSet({ items, kind, markers, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, labels, halo, selectionStroke, layerId, priority, label }: PointSetProps): import("react").JSX.Element;
|
|
1184
1562
|
//#endregion
|
|
1185
1563
|
//#region src/components/roiEdit.d.ts
|
|
1186
1564
|
/** A region's handle, by compass direction. */
|
|
@@ -1278,5 +1656,5 @@ interface MaskEditorProps {
|
|
|
1278
1656
|
/** Render and edit a binary raster mask within the enclosing ImageStage. */
|
|
1279
1657
|
export declare function MaskEditor({ mask, onChange, onCommit, editable, brushRadius, mode, label, color }: MaskEditorProps): import("react").JSX.Element;
|
|
1280
1658
|
//#endregion
|
|
1281
|
-
export type { ArcPrimitive, Box, CaliperPrimitive, CirclePrimitive, ClampOptions, ContourEditorProps, DimensionGeometry, DimensionPrimitive, ImageLayerProps, ImageStageProps, ImageTier, MaskEditorProps, MeasureOverlayProps, MeasurePrimitive, OverlayRole, OverlayState, Point, PointPrimitive, Polyline, PolylineHit, PolylineId, PolylineIndex, PolylinePrimitive, PolylineSelectMode, PolylineSetItem, PolylineSetProps, PrimitiveCommon, Rect, RectRoiEditorProps, RoiHandle, SegmentPrimitive, StageButtonProps, StageContext, StageDrag, StageHandle, StageLayer, StageLayersMenuProps, StagePress, StageReadoutProps, StageSurfaceProps, StageToolbarDividerProps, StageToolbarProps, StageView, ValuePlane, View, ZoomPanCanvasProps };
|
|
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 };
|
|
1282
1660
|
//# sourceMappingURL=index.d.ts.map
|