@vitavision/stage2d 0.13.0 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/api/mapValues.ts +1 -4
- package/src/components/AreaSet.tsx +28 -5
- package/src/components/ContourEditor.tsx +48 -12
- package/src/components/DraftShape.tsx +37 -5
- package/src/components/GridLayer.tsx +7 -1
- package/src/components/MaskEditor.tsx +57 -9
- package/src/components/MeasureOverlay.tsx +36 -6
- package/src/components/PointSet.tsx +19 -8
- package/src/components/PolylineSet.tsx +2 -10
- package/src/components/RectRoiEditor.tsx +1 -9
- package/src/components/ShapeEditor.tsx +12 -7
- package/src/components/areaBatching.ts +22 -2
- package/src/components/areaIndex.ts +2 -1
- package/src/components/labelLod.ts +1 -4
- package/src/components/markerShapes.ts +1 -3
- package/src/components/measureGeometry.ts +12 -27
- package/src/components/measureHit.ts +16 -4
- package/src/components/pointIndex.ts +12 -2
- package/src/components/stage/CompareLayer.tsx +4 -1
- package/src/components/stage/ImageLayer.tsx +1 -10
- package/src/components/stage/ImageStage.tsx +4 -30
- package/src/components/stage/StageSurface.tsx +33 -30
- package/src/components/stage/StageToolbar.tsx +9 -29
- package/src/components/stage/useStageHitTest.ts +6 -12
- package/src/components/stage/view.ts +3 -15
- package/src/index.ts +11 -72
|
@@ -93,8 +93,14 @@ export function segmentsPath(points: ArrayLike<number>): string {
|
|
|
93
93
|
/** The two line segments of a cross mark centred on `(x, y)`, each `2·size` long. */
|
|
94
94
|
export function crossSegments(x: number, y: number, size: number): [[Point, Point], [Point, Point]] {
|
|
95
95
|
return [
|
|
96
|
-
[
|
|
97
|
-
|
|
96
|
+
[
|
|
97
|
+
{ x: x - size, y },
|
|
98
|
+
{ x: x + size, y },
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
{ x, y: y - size },
|
|
102
|
+
{ x, y: y + size },
|
|
103
|
+
],
|
|
98
104
|
];
|
|
99
105
|
}
|
|
100
106
|
|
|
@@ -159,13 +165,7 @@ export function arcPath(cx: number, cy: number, r: number, startAngle: number, e
|
|
|
159
165
|
* by `height`, centred at `(cx, cy)` and rotated by `angle` radians. Corner order is
|
|
160
166
|
* suitable for `polygonPath` — around the box, not crossed.
|
|
161
167
|
*/
|
|
162
|
-
export function caliperCorners(
|
|
163
|
-
cx: number,
|
|
164
|
-
cy: number,
|
|
165
|
-
width: number,
|
|
166
|
-
height: number,
|
|
167
|
-
angle: number,
|
|
168
|
-
): [Point, Point, Point, Point] {
|
|
168
|
+
export function caliperCorners(cx: number, cy: number, width: number, height: number, angle: number): [Point, Point, Point, Point] {
|
|
169
169
|
const hw = width / 2;
|
|
170
170
|
const hh = height / 2;
|
|
171
171
|
const local: [number, number][] = [
|
|
@@ -186,12 +186,7 @@ export function caliperCorners(
|
|
|
186
186
|
* along the box's own measurement axis. What the arrow points at is the scan direction the
|
|
187
187
|
* caliper was evaluated in, not merely a decoration on the box.
|
|
188
188
|
*/
|
|
189
|
-
export function caliperArrow(
|
|
190
|
-
cx: number,
|
|
191
|
-
cy: number,
|
|
192
|
-
width: number,
|
|
193
|
-
angle: number,
|
|
194
|
-
): { from: Point; to: Point } {
|
|
189
|
+
export function caliperArrow(cx: number, cy: number, width: number, angle: number): { from: Point; to: Point } {
|
|
195
190
|
const reach = width / 2 + Math.max(4, width * 0.2);
|
|
196
191
|
const tip = rotatePoint(reach, 0, angle);
|
|
197
192
|
return { from: { x: cx, y: cy }, to: { x: cx + tip.x, y: cy + tip.y } };
|
|
@@ -208,11 +203,7 @@ export function arrowHeadPoints(tip: Point, angle: number, size: number): [Point
|
|
|
208
203
|
const spread = size;
|
|
209
204
|
const left = rotatePoint(-back, spread, angle);
|
|
210
205
|
const right = rotatePoint(-back, -spread, angle);
|
|
211
|
-
return [
|
|
212
|
-
{ x: tip.x + left.x, y: tip.y + left.y },
|
|
213
|
-
tip,
|
|
214
|
-
{ x: tip.x + right.x, y: tip.y + right.y },
|
|
215
|
-
];
|
|
206
|
+
return [{ x: tip.x + left.x, y: tip.y + left.y }, tip, { x: tip.x + right.x, y: tip.y + right.y }];
|
|
216
207
|
}
|
|
217
208
|
|
|
218
209
|
/** What `dimensionGeometry` computes: the lines and label placement of a dimension annotation. */
|
|
@@ -237,13 +228,7 @@ export interface DimensionGeometry {
|
|
|
237
228
|
* Degenerate input (`x1 === x2 && y1 === y2`) falls back to an arbitrary rightward normal
|
|
238
229
|
* rather than dividing by zero, so a caller need not special-case a zero-length dimension.
|
|
239
230
|
*/
|
|
240
|
-
export function dimensionGeometry(
|
|
241
|
-
x1: number,
|
|
242
|
-
y1: number,
|
|
243
|
-
x2: number,
|
|
244
|
-
y2: number,
|
|
245
|
-
offset: number,
|
|
246
|
-
): DimensionGeometry {
|
|
231
|
+
export function dimensionGeometry(x1: number, y1: number, x2: number, y2: number, offset: number): DimensionGeometry {
|
|
247
232
|
const dx = x2 - x1;
|
|
248
233
|
const dy = y2 - y1;
|
|
249
234
|
const length = Math.hypot(dx, dy);
|
|
@@ -99,7 +99,8 @@ export function measurePrimitiveDistance(primitive: MeasurePrimitive, point: Poi
|
|
|
99
99
|
case "dimension": {
|
|
100
100
|
const g = dimensionGeometry(primitive.x1, primitive.y1, primitive.x2, primitive.y2, primitive.offset ?? MEASURE_DIMENSION_OFFSET);
|
|
101
101
|
let best = Infinity;
|
|
102
|
-
for (const [a, b] of [g.extensionLine1, g.extensionLine2, g.dimensionLine])
|
|
102
|
+
for (const [a, b] of [g.extensionLine1, g.extensionLine2, g.dimensionLine])
|
|
103
|
+
best = Math.min(best, segmentDistance(p, a.x, a.y, b.x, b.y));
|
|
103
104
|
return best;
|
|
104
105
|
}
|
|
105
106
|
|
|
@@ -204,7 +205,12 @@ function indexOf(primitives: readonly MeasurePrimitive[]): MeasureIndex {
|
|
|
204
205
|
const counts = new Uint32Array(cols * rows + 1);
|
|
205
206
|
const spans: [number, number, number, number][] = [];
|
|
206
207
|
for (const i of gridded) {
|
|
207
|
-
const span: [number, number, number, number] = [
|
|
208
|
+
const span: [number, number, number, number] = [
|
|
209
|
+
cellX(boxes[i * 5]!),
|
|
210
|
+
cellY(boxes[i * 5 + 1]!),
|
|
211
|
+
cellX(boxes[i * 5 + 2]!),
|
|
212
|
+
cellY(boxes[i * 5 + 3]!),
|
|
213
|
+
];
|
|
208
214
|
spans.push(span);
|
|
209
215
|
if ((span[2] - span[0] + 1) * (span[3] - span[1] + 1) > LARGE_CELLS) {
|
|
210
216
|
large.push(i);
|
|
@@ -273,7 +279,8 @@ function boxOf(primitive: MeasurePrimitive): [number, number, number, number, nu
|
|
|
273
279
|
add(primitive.cx + primitive.r, primitive.cy + primitive.r);
|
|
274
280
|
break;
|
|
275
281
|
case "caliper": {
|
|
276
|
-
for (const corner of caliperCorners(primitive.cx, primitive.cy, primitive.width, primitive.height, primitive.angle))
|
|
282
|
+
for (const corner of caliperCorners(primitive.cx, primitive.cy, primitive.width, primitive.height, primitive.angle))
|
|
283
|
+
add(corner.x, corner.y);
|
|
277
284
|
const tip = caliperArrow(primitive.cx, primitive.cy, primitive.width, primitive.angle).to;
|
|
278
285
|
add(tip.x, tip.y);
|
|
279
286
|
// The head's back corners reach 1.6 × its size behind the tip and 1 × to the side.
|
|
@@ -342,7 +349,12 @@ export function nearestMeasurePrimitive(
|
|
|
342
349
|
seen[i] = query;
|
|
343
350
|
const reach = radius + boxes[i * 5 + 4]! * screen;
|
|
344
351
|
if (
|
|
345
|
-
!(
|
|
352
|
+
!(
|
|
353
|
+
point.x >= boxes[i * 5]! - reach &&
|
|
354
|
+
point.x <= boxes[i * 5 + 2]! + reach &&
|
|
355
|
+
point.y >= boxes[i * 5 + 1]! - reach &&
|
|
356
|
+
point.y <= boxes[i * 5 + 3]! + reach
|
|
357
|
+
)
|
|
346
358
|
) {
|
|
347
359
|
return;
|
|
348
360
|
}
|
|
@@ -122,8 +122,18 @@ export function buildPointIndex(xy: ArrayLike<number>, options: PointIndexOption
|
|
|
122
122
|
}
|
|
123
123
|
if (live === 0) {
|
|
124
124
|
return {
|
|
125
|
-
count,
|
|
126
|
-
|
|
125
|
+
count,
|
|
126
|
+
xy,
|
|
127
|
+
ids: ids,
|
|
128
|
+
radii,
|
|
129
|
+
maxRadius,
|
|
130
|
+
cell: 1,
|
|
131
|
+
x0: 0,
|
|
132
|
+
y0: 0,
|
|
133
|
+
cols: 1,
|
|
134
|
+
rows: 1,
|
|
135
|
+
starts: new Uint32Array(2),
|
|
136
|
+
items: new Uint32Array(0),
|
|
127
137
|
};
|
|
128
138
|
}
|
|
129
139
|
|
|
@@ -124,7 +124,10 @@ export function CompareLayer({
|
|
|
124
124
|
const extent = vertical ? image.width : image.height;
|
|
125
125
|
const at = current * extent;
|
|
126
126
|
const visible = visibleRect(stage.view, stage.box);
|
|
127
|
-
const along = knobPosition(
|
|
127
|
+
const along = knobPosition(
|
|
128
|
+
visible === null ? null : vertical ? [visible.y, visible.y + visible.height] : [visible.x, visible.x + visible.width],
|
|
129
|
+
length,
|
|
130
|
+
);
|
|
128
131
|
const knob = vertical ? { x: at, y: along } : { x: along, y: at };
|
|
129
132
|
const line = vertical ? { x1: at, y1: 0, x2: at, y2: image.height } : { x1: 0, y1: at, x2: image.width, y2: at };
|
|
130
133
|
|
|
@@ -83,16 +83,7 @@ export type ImageLayerProps = ImageLayerBaseProps &
|
|
|
83
83
|
* once it has loaded, the preview carries `data-wants-full` from the moment the full image is
|
|
84
84
|
* wanted until it has loaded, and both carry `data-pixelated` while pixelated.
|
|
85
85
|
*/
|
|
86
|
-
export function ImageLayer({
|
|
87
|
-
src,
|
|
88
|
-
preview,
|
|
89
|
-
alt,
|
|
90
|
-
pixelatedAbove = 4,
|
|
91
|
-
onFullNeeded,
|
|
92
|
-
onLoad,
|
|
93
|
-
onError,
|
|
94
|
-
className,
|
|
95
|
-
}: ImageLayerProps) {
|
|
86
|
+
export function ImageLayer({ src, preview, alt, pixelatedAbove = 4, onFullNeeded, onLoad, onError, className }: ImageLayerProps) {
|
|
96
87
|
const stage = useStage();
|
|
97
88
|
const scale = stage.view.scale;
|
|
98
89
|
// The full image is wanted once the preview would be magnified on screen: its own pixels
|
|
@@ -25,24 +25,8 @@
|
|
|
25
25
|
* with the image.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
use,
|
|
31
|
-
useCallback,
|
|
32
|
-
useEffect,
|
|
33
|
-
useImperativeHandle,
|
|
34
|
-
useLayoutEffect,
|
|
35
|
-
useMemo,
|
|
36
|
-
useRef,
|
|
37
|
-
useState,
|
|
38
|
-
} from "react";
|
|
39
|
-
import type {
|
|
40
|
-
CSSProperties,
|
|
41
|
-
KeyboardEvent as ReactKeyboardEvent,
|
|
42
|
-
PointerEvent as ReactPointerEvent,
|
|
43
|
-
ReactNode,
|
|
44
|
-
Ref,
|
|
45
|
-
} from "react";
|
|
28
|
+
import { createContext, use, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
29
|
+
import type { CSSProperties, KeyboardEvent as ReactKeyboardEvent, PointerEvent as ReactPointerEvent, ReactNode, Ref } from "react";
|
|
46
30
|
|
|
47
31
|
import { cn } from "@vitavision/ui";
|
|
48
32
|
import type { Point } from "../measureGeometry";
|
|
@@ -960,18 +944,8 @@ function contentSize(element: HTMLElement): Box {
|
|
|
960
944
|
const style = getComputedStyle(element);
|
|
961
945
|
const px = (value: string) => Number.parseFloat(value) || 0;
|
|
962
946
|
return {
|
|
963
|
-
width:
|
|
964
|
-
|
|
965
|
-
px(style.borderLeftWidth) -
|
|
966
|
-
px(style.borderRightWidth) -
|
|
967
|
-
px(style.paddingLeft) -
|
|
968
|
-
px(style.paddingRight),
|
|
969
|
-
height:
|
|
970
|
-
rect.height -
|
|
971
|
-
px(style.borderTopWidth) -
|
|
972
|
-
px(style.borderBottomWidth) -
|
|
973
|
-
px(style.paddingTop) -
|
|
974
|
-
px(style.paddingBottom),
|
|
947
|
+
width: rect.width - px(style.borderLeftWidth) - px(style.borderRightWidth) - px(style.paddingLeft) - px(style.paddingRight),
|
|
948
|
+
height: rect.height - px(style.borderTopWidth) - px(style.borderBottomWidth) - px(style.paddingTop) - px(style.paddingBottom),
|
|
975
949
|
};
|
|
976
950
|
}
|
|
977
951
|
|
|
@@ -64,37 +64,40 @@ export function useStageDrag(): (event: ReactPointerEvent<Element>, drag: StageD
|
|
|
64
64
|
// A drag still in flight when the component unmounts is cancelled, not leaked.
|
|
65
65
|
useEffect(() => () => cleanupRef.current?.(), []);
|
|
66
66
|
|
|
67
|
-
return useCallback(
|
|
68
|
-
event
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
return useCallback(
|
|
68
|
+
(event: ReactPointerEvent<Element>, drag: StageDrag) => {
|
|
69
|
+
event.stopPropagation();
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
cleanupRef.current?.();
|
|
72
|
+
const from = { x: event.clientX, y: event.clientY };
|
|
73
|
+
let moved = false;
|
|
74
|
+
const at = (e: PointerEvent) => toImage({ x: e.clientX, y: e.clientY });
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
76
|
+
const move = (e: PointerEvent) => {
|
|
77
|
+
if (!moved && Math.hypot(e.clientX - from.x, e.clientY - from.y) > CLICK_SLOP) moved = true;
|
|
78
|
+
drag.onMove?.(at(e), e);
|
|
79
|
+
};
|
|
80
|
+
const up = (e: PointerEvent) => {
|
|
81
|
+
stop();
|
|
82
|
+
drag.onEnd?.(at(e), e, moved);
|
|
83
|
+
};
|
|
84
|
+
const cancel = () => {
|
|
85
|
+
stop();
|
|
86
|
+
drag.onCancel?.();
|
|
87
|
+
};
|
|
88
|
+
const stop = () => {
|
|
89
|
+
window.removeEventListener("pointermove", move);
|
|
90
|
+
window.removeEventListener("pointerup", up);
|
|
91
|
+
window.removeEventListener("pointercancel", cancel);
|
|
92
|
+
cleanupRef.current = null;
|
|
93
|
+
};
|
|
94
|
+
window.addEventListener("pointermove", move);
|
|
95
|
+
window.addEventListener("pointerup", up);
|
|
96
|
+
window.addEventListener("pointercancel", cancel);
|
|
97
|
+
cleanupRef.current = cancel;
|
|
98
|
+
},
|
|
99
|
+
[toImage],
|
|
100
|
+
);
|
|
98
101
|
}
|
|
99
102
|
|
|
100
103
|
/** A press on the surface, as the app's `onPress` sees it. */
|
|
@@ -61,10 +61,7 @@ export function StageToolbar({ children, className }: StageToolbarProps) {
|
|
|
61
61
|
return (
|
|
62
62
|
<div
|
|
63
63
|
data-fit={stage.isFit ? "" : undefined}
|
|
64
|
-
className={cn(
|
|
65
|
-
"flex items-center gap-0.5 rounded-panel border border-line bg-overlay/85 p-1 shadow-lg backdrop-blur",
|
|
66
|
-
className,
|
|
67
|
-
)}
|
|
64
|
+
className={cn("flex items-center gap-0.5 rounded-panel border border-line bg-overlay/85 p-1 shadow-lg backdrop-blur", className)}
|
|
68
65
|
// Every press here is a control, never the start of a pan.
|
|
69
66
|
onPointerDown={(event) => event.stopPropagation()}
|
|
70
67
|
onDoubleClick={(event) => event.stopPropagation()}
|
|
@@ -88,18 +85,12 @@ export function StageToolbar({ children, className }: StageToolbarProps) {
|
|
|
88
85
|
aria-expanded={menuOpen}
|
|
89
86
|
data-state={menuOpen ? "open" : "closed"}
|
|
90
87
|
onClick={() => setMenuOpen((open) => !open)}
|
|
91
|
-
className={cn(
|
|
92
|
-
"h-7 min-w-14 rounded-control px-2 font-mono text-xs text-fg tabular-nums hover:bg-raised",
|
|
93
|
-
focusRing,
|
|
94
|
-
)}
|
|
88
|
+
className={cn("h-7 min-w-14 rounded-control px-2 font-mono text-xs text-fg tabular-nums hover:bg-raised", focusRing)}
|
|
95
89
|
>
|
|
96
90
|
{stage.isFit ? "Fit" : formatScale(stage.view.scale)}
|
|
97
91
|
</button>
|
|
98
92
|
{menuOpen && (
|
|
99
|
-
<div
|
|
100
|
-
role="menu"
|
|
101
|
-
className="absolute bottom-9 left-0 z-20 min-w-28 rounded-panel border border-line bg-overlay p-1 shadow-lg"
|
|
102
|
-
>
|
|
93
|
+
<div role="menu" className="absolute bottom-9 left-0 z-20 min-w-28 rounded-panel border border-line bg-overlay p-1 shadow-lg">
|
|
103
94
|
<MenuItem
|
|
104
95
|
onClick={() => {
|
|
105
96
|
stage.fit();
|
|
@@ -159,8 +150,10 @@ export function StageToolbar({ children, className }: StageToolbarProps) {
|
|
|
159
150
|
}
|
|
160
151
|
|
|
161
152
|
/** Props of `StageButton`: a `<button>`'s, less the ones it sets itself. */
|
|
162
|
-
export interface StageButtonProps
|
|
163
|
-
|
|
153
|
+
export interface StageButtonProps extends Omit<
|
|
154
|
+
ComponentPropsWithRef<"button">,
|
|
155
|
+
"type" | "title" | "aria-label" | "aria-pressed" | "children"
|
|
156
|
+
> {
|
|
164
157
|
/** The accessible name, also shown as the tooltip. */
|
|
165
158
|
label: string;
|
|
166
159
|
/** A toggle's state; omit for a plain action button. */
|
|
@@ -311,15 +304,7 @@ export function StageToolbarDivider({ className }: StageToolbarDividerProps) {
|
|
|
311
304
|
return <span className={cn("mx-0.5 h-5 w-px bg-line", className)} aria-hidden />;
|
|
312
305
|
}
|
|
313
306
|
|
|
314
|
-
function MenuItem({
|
|
315
|
-
onClick,
|
|
316
|
-
active,
|
|
317
|
-
children,
|
|
318
|
-
}: {
|
|
319
|
-
onClick: () => void;
|
|
320
|
-
active?: boolean;
|
|
321
|
-
children: ReactNode;
|
|
322
|
-
}) {
|
|
307
|
+
function MenuItem({ onClick, active, children }: { onClick: () => void; active?: boolean; children: ReactNode }) {
|
|
323
308
|
return (
|
|
324
309
|
<button
|
|
325
310
|
type="button"
|
|
@@ -356,12 +341,7 @@ export interface StageReadoutProps {
|
|
|
356
341
|
export function StageReadout({ cursor, extra, className }: StageReadoutProps) {
|
|
357
342
|
const stage = useStage();
|
|
358
343
|
return (
|
|
359
|
-
<span
|
|
360
|
-
className={cn(
|
|
361
|
-
"rounded-control bg-black/60 px-1.5 py-0.5 font-mono text-[10px] text-white tabular-nums",
|
|
362
|
-
className,
|
|
363
|
-
)}
|
|
364
|
-
>
|
|
344
|
+
<span className={cn("rounded-control bg-black/60 px-1.5 py-0.5 font-mono text-[10px] text-white tabular-nums", className)}>
|
|
365
345
|
{cursor ? `${cursor.x.toFixed(1)}, ${cursor.y.toFixed(1)} px` : `${stage.image.width}×${stage.image.height}`}
|
|
366
346
|
{" · "}
|
|
367
347
|
{stage.isFit ? "fit" : formatScale(stage.view.scale)}
|
|
@@ -8,13 +8,7 @@ import { use, useId, useLayoutEffect, useMemo, useRef } from "react";
|
|
|
8
8
|
import type { Point } from "../measureGeometry";
|
|
9
9
|
import { useStage } from "./ImageStage";
|
|
10
10
|
import { StageHitContext, type StagePointerEvent } from "./hitContext";
|
|
11
|
-
import {
|
|
12
|
-
type HitCandidate,
|
|
13
|
-
type HitId,
|
|
14
|
-
type StageHit,
|
|
15
|
-
type StageHitLayerSpec,
|
|
16
|
-
type StageHitOptions,
|
|
17
|
-
} from "./hitTest";
|
|
11
|
+
import { type HitCandidate, type HitId, type StageHit, type StageHitLayerSpec, type StageHitOptions } from "./hitTest";
|
|
18
12
|
|
|
19
13
|
/** The default pointer tolerance of `hitTest`, in screen pixels. */
|
|
20
14
|
const DEFAULT_RADIUS_PX = 6;
|
|
@@ -53,10 +47,8 @@ export function useStageHitTest(): StageHitTestApi {
|
|
|
53
47
|
const { imageLength } = useStage();
|
|
54
48
|
return useMemo(
|
|
55
49
|
() => ({
|
|
56
|
-
hitTest: (point, radiusScreenPx = DEFAULT_RADIUS_PX, options) =>
|
|
57
|
-
|
|
58
|
-
hitTestAll: (point, radiusScreenPx = DEFAULT_RADIUS_PX, options) =>
|
|
59
|
-
registry.hitTestAll(point, imageLength(radiusScreenPx), options),
|
|
50
|
+
hitTest: (point, radiusScreenPx = DEFAULT_RADIUS_PX, options) => registry.hitTest(point, imageLength(radiusScreenPx), options),
|
|
51
|
+
hitTestAll: (point, radiusScreenPx = DEFAULT_RADIUS_PX, options) => registry.hitTestAll(point, imageLength(radiusScreenPx), options),
|
|
60
52
|
}),
|
|
61
53
|
[registry, imageLength],
|
|
62
54
|
);
|
|
@@ -124,7 +116,9 @@ export function useStageHitLayer(options: StageHitLayerOptions): string {
|
|
|
124
116
|
return latestRef.current.onHover === undefined ? undefined : (hovered: HitId | null) => latestRef.current.onHover?.(hovered);
|
|
125
117
|
},
|
|
126
118
|
get press() {
|
|
127
|
-
return latestRef.current.onPress === undefined
|
|
119
|
+
return latestRef.current.onPress === undefined
|
|
120
|
+
? undefined
|
|
121
|
+
: (hit: HitId, event: StagePointerEvent) => latestRef.current.onPress?.(hit, event);
|
|
128
122
|
},
|
|
129
123
|
get doubleClick() {
|
|
130
124
|
return latestRef.current.onDoubleClick === undefined
|
|
@@ -96,9 +96,7 @@ export const MAX_SCALE = 32;
|
|
|
96
96
|
export const MIN_SCALE_VS_FIT = 0.25;
|
|
97
97
|
|
|
98
98
|
/** Zoom in/out steps, as the percentages a readout can show without apologising. */
|
|
99
|
-
const SCALE_LADDER = [
|
|
100
|
-
0.05, 0.0833, 0.125, 0.1667, 0.25, 0.3333, 0.5, 0.6667, 1, 1.5, 2, 3, 4, 6, 8, 12, 16, 24, 32,
|
|
101
|
-
];
|
|
99
|
+
const SCALE_LADDER = [0.05, 0.0833, 0.125, 0.1667, 0.25, 0.3333, 0.5, 0.6667, 1, 1.5, 2, 3, 4, 6, 8, 12, 16, 24, 32];
|
|
102
100
|
|
|
103
101
|
/** Relative tolerance for "is this the same scale" — a hair under a tenth of a percent. */
|
|
104
102
|
const SCALE_EPSILON = 1e-3;
|
|
@@ -203,12 +201,7 @@ export function toImage(view: StageView, p: Point): Point {
|
|
|
203
201
|
|
|
204
202
|
/** Whether an image coordinate is inside the image, in the pixel-centre convention. */
|
|
205
203
|
export function insideImage(p: Point, image: Box): boolean {
|
|
206
|
-
return
|
|
207
|
-
p.x >= -PIXEL_CENTRE &&
|
|
208
|
-
p.y >= -PIXEL_CENTRE &&
|
|
209
|
-
p.x < image.width - PIXEL_CENTRE &&
|
|
210
|
-
p.y < image.height - PIXEL_CENTRE
|
|
211
|
-
);
|
|
204
|
+
return p.x >= -PIXEL_CENTRE && p.y >= -PIXEL_CENTRE && p.x < image.width - PIXEL_CENTRE && p.y < image.height - PIXEL_CENTRE;
|
|
212
205
|
}
|
|
213
206
|
|
|
214
207
|
/**
|
|
@@ -277,12 +270,7 @@ export function scaleRange(box: Box, image: Box, options: ClampOptions = {}): [n
|
|
|
277
270
|
* larger is held so the viewport stays covered. With `"center"`, each axis only keeps some
|
|
278
271
|
* image point at or past the viewport's centre.
|
|
279
272
|
*/
|
|
280
|
-
export function clampView(
|
|
281
|
-
view: StageView,
|
|
282
|
-
box: Box,
|
|
283
|
-
image: Box,
|
|
284
|
-
options: ClampOptions = {},
|
|
285
|
-
): StageView {
|
|
273
|
+
export function clampView(view: StageView, box: Box, image: Box, options: ClampOptions = {}): StageView {
|
|
286
274
|
const [min, max] = scaleRange(box, image, options);
|
|
287
275
|
const scale = clamp(view.scale, min, max);
|
|
288
276
|
const axis = options.panBounds === "center" ? centreAxis : clampAxis;
|
package/src/index.ts
CHANGED
|
@@ -14,33 +14,16 @@ export {
|
|
|
14
14
|
|
|
15
15
|
export type { StageMouseButton } from "./components/stage/gesture";
|
|
16
16
|
|
|
17
|
-
export {
|
|
18
|
-
STAGE_HIT_PRIORITY,
|
|
19
|
-
type HitCandidate,
|
|
20
|
-
type HitId,
|
|
21
|
-
type StageHit,
|
|
22
|
-
type StageHitOptions,
|
|
23
|
-
} from "./components/stage/hitTest";
|
|
17
|
+
export { STAGE_HIT_PRIORITY, type HitCandidate, type HitId, type StageHit, type StageHitOptions } from "./components/stage/hitTest";
|
|
24
18
|
export type { StagePointerEvent } from "./components/stage/hitContext";
|
|
25
|
-
export {
|
|
26
|
-
useStageHitLayer,
|
|
27
|
-
useStageHitTest,
|
|
28
|
-
type StageHitLayerOptions,
|
|
29
|
-
type StageHitTestApi,
|
|
30
|
-
} from "./components/stage/useStageHitTest";
|
|
19
|
+
export { useStageHitLayer, useStageHitTest, type StageHitLayerOptions, type StageHitTestApi } from "./components/stage/useStageHitTest";
|
|
31
20
|
|
|
32
21
|
export { CompareLayer, type CompareLayerProps } from "./components/stage/CompareLayer";
|
|
33
22
|
export type { CompareMode, CompareOrientation } from "./components/stage/compareStyle";
|
|
34
23
|
|
|
35
24
|
export { ImageLayer, type ImageLayerBaseProps, type ImageLayerProps, type ImageTier } from "./components/stage/ImageLayer";
|
|
36
25
|
|
|
37
|
-
export {
|
|
38
|
-
StageSurface,
|
|
39
|
-
useStageDrag,
|
|
40
|
-
type StageDrag,
|
|
41
|
-
type StagePress,
|
|
42
|
-
type StageSurfaceProps,
|
|
43
|
-
} from "./components/stage/StageSurface";
|
|
26
|
+
export { StageSurface, useStageDrag, type StageDrag, type StagePress, type StageSurfaceProps } from "./components/stage/StageSurface";
|
|
44
27
|
|
|
45
28
|
export {
|
|
46
29
|
StageButton,
|
|
@@ -97,15 +80,7 @@ export {
|
|
|
97
80
|
type ZoomPanCanvasProps,
|
|
98
81
|
} from "./components/ZoomPanCanvas";
|
|
99
82
|
|
|
100
|
-
export {
|
|
101
|
-
PlaneFormatError,
|
|
102
|
-
decodePlane,
|
|
103
|
-
fetchPlane,
|
|
104
|
-
fractionOf,
|
|
105
|
-
valueAt,
|
|
106
|
-
valuesAt,
|
|
107
|
-
type ValuePlane,
|
|
108
|
-
} from "./api/mapValues";
|
|
83
|
+
export { PlaneFormatError, decodePlane, fetchPlane, fractionOf, valueAt, valuesAt, type ValuePlane } from "./api/mapValues";
|
|
109
84
|
|
|
110
85
|
export {
|
|
111
86
|
MeasureOverlay,
|
|
@@ -134,15 +109,7 @@ export {
|
|
|
134
109
|
export { useScreenPx } from "./components/stage/useScreenPx";
|
|
135
110
|
|
|
136
111
|
export { ContourEditor, nearestContourSegment, type ContourEditorProps } from "./components/ContourEditor";
|
|
137
|
-
export {
|
|
138
|
-
arcLengths,
|
|
139
|
-
deformContour,
|
|
140
|
-
eraseArc,
|
|
141
|
-
normalAtArc,
|
|
142
|
-
pointAtArc,
|
|
143
|
-
projectToArc,
|
|
144
|
-
subPath,
|
|
145
|
-
} from "./components/contourArc";
|
|
112
|
+
export { arcLengths, deformContour, eraseArc, normalAtArc, pointAtArc, projectToArc, subPath } from "./components/contourArc";
|
|
146
113
|
export { RectRoiEditor, type RectRoiEditorHandle, type RectRoiEditorProps } from "./components/RectRoiEditor";
|
|
147
114
|
export {
|
|
148
115
|
PolylineSet,
|
|
@@ -162,11 +129,7 @@ export {
|
|
|
162
129
|
type PolylineId,
|
|
163
130
|
type PolylineIndex,
|
|
164
131
|
} from "./components/polylineIndex";
|
|
165
|
-
export {
|
|
166
|
-
PointSet,
|
|
167
|
-
type PointSetItem,
|
|
168
|
-
type PointSetProps,
|
|
169
|
-
} from "./components/PointSet";
|
|
132
|
+
export { PointSet, type PointSetItem, type PointSetProps } from "./components/PointSet";
|
|
170
133
|
export {
|
|
171
134
|
buildPointIndex,
|
|
172
135
|
buildPointIndexFrom,
|
|
@@ -179,11 +142,7 @@ export {
|
|
|
179
142
|
type PointIndexOptions,
|
|
180
143
|
type PointItem,
|
|
181
144
|
} from "./components/pointIndex";
|
|
182
|
-
export {
|
|
183
|
-
AreaSet,
|
|
184
|
-
type AreaSetItem,
|
|
185
|
-
type AreaSetProps,
|
|
186
|
-
} from "./components/AreaSet";
|
|
145
|
+
export { AreaSet, type AreaSetItem, type AreaSetProps } from "./components/AreaSet";
|
|
187
146
|
export {
|
|
188
147
|
areaCentre,
|
|
189
148
|
areaPath,
|
|
@@ -196,11 +155,7 @@ export {
|
|
|
196
155
|
type AreaId,
|
|
197
156
|
type AreaIndex,
|
|
198
157
|
} from "./components/areaIndex";
|
|
199
|
-
export {
|
|
200
|
-
EllipseSet,
|
|
201
|
-
type EllipseSetItem,
|
|
202
|
-
type EllipseSetProps,
|
|
203
|
-
} from "./components/EllipseSet";
|
|
158
|
+
export { EllipseSet, type EllipseSetItem, type EllipseSetProps } from "./components/EllipseSet";
|
|
204
159
|
export {
|
|
205
160
|
buildEllipseIndex,
|
|
206
161
|
ellipseBounds,
|
|
@@ -213,12 +168,7 @@ export {
|
|
|
213
168
|
type EllipseId,
|
|
214
169
|
type EllipseIndex,
|
|
215
170
|
} from "./components/ellipseIndex";
|
|
216
|
-
export {
|
|
217
|
-
GridLayer,
|
|
218
|
-
type GridEdgeStyle,
|
|
219
|
-
type GridLayerProps,
|
|
220
|
-
type GridNode,
|
|
221
|
-
} from "./components/GridLayer";
|
|
171
|
+
export { GridLayer, type GridEdgeStyle, type GridLayerProps, type GridNode } from "./components/GridLayer";
|
|
222
172
|
export { latticeEdges, type LatticeAxis, type LatticeEdge, type LatticeNode } from "./components/gridEdges";
|
|
223
173
|
export {
|
|
224
174
|
HeatmapLayer,
|
|
@@ -258,19 +208,8 @@ export {
|
|
|
258
208
|
type DatumPressOptions,
|
|
259
209
|
type MoveDatumOptions,
|
|
260
210
|
} from "./components/datumEdit";
|
|
261
|
-
export {
|
|
262
|
-
|
|
263
|
-
MarqueeRect,
|
|
264
|
-
type DraftShapeProps,
|
|
265
|
-
type DraftShapeSpec,
|
|
266
|
-
type MarqueeRectProps,
|
|
267
|
-
} from "./components/DraftShape";
|
|
268
|
-
export {
|
|
269
|
-
translatePoints,
|
|
270
|
-
useShapeDrag,
|
|
271
|
-
type ShapeDragHandlers,
|
|
272
|
-
type ShapeDragOptions,
|
|
273
|
-
} from "./components/useShapeDrag";
|
|
211
|
+
export { DraftShape, MarqueeRect, type DraftShapeProps, type DraftShapeSpec, type MarqueeRectProps } from "./components/DraftShape";
|
|
212
|
+
export { translatePoints, useShapeDrag, type ShapeDragHandlers, type ShapeDragOptions } from "./components/useShapeDrag";
|
|
274
213
|
export { MARKER_SHAPES, circlePath, type BuiltinMarkerKind, type MarkerShape } from "./components/markerShapes";
|
|
275
214
|
export {
|
|
276
215
|
ROI_HANDLES,
|