@vitavision/stage2d 0.15.1 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2229,6 +2229,75 @@ interface PointSetProps {
2229
2229
  */
2230
2230
  export declare function PointSet({ items, kind, markers, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, pickable, labels, halo, selectionStroke, layerId, priority, label }: PointSetProps): import("react").JSX.Element;
2231
2231
  //#endregion
2232
+ //#region src/components/PointMarquee.d.ts
2233
+ /** The key that arms a `PointMarquee`. `"meta"` is ⌘ on macOS and Ctrl elsewhere. */
2234
+ type PointMarqueeModifier = "shift" | "alt" | "meta";
2235
+ /** How a marquee combines with the current selection: replaces it, or adds to it. */
2236
+ type PointMarqueeMode = "replace" | "add";
2237
+ /**
2238
+ * What `PointMarquee`'s `ref` exposes, for an app that already has a `StageSurface` (a stage
2239
+ * has one full-frame press target) and starts the marquee from its `onPress`.
2240
+ */
2241
+ interface PointMarqueeHandle {
2242
+ /**
2243
+ * The marquee as a `StageDrag`, to return from `StageSurface`'s `onPress`.
2244
+ *
2245
+ * @param press - The press the surface was given.
2246
+ * @returns The drag when the press holds the marquee's modifier, `undefined` otherwise: a
2247
+ * declined press is for the surface's other tools or the stage's pan. A touch has no
2248
+ * modifier, so it is never started here.
2249
+ */
2250
+ sweepDrag(press: StagePress): StageDrag | undefined;
2251
+ }
2252
+ /** Props of `PointMarquee`. */
2253
+ interface PointMarqueeProps {
2254
+ /** The points the marquee selects among, in image coordinates. Pass a stable array: a new one rebuilds the index. */
2255
+ items: readonly PointItem[];
2256
+ /**
2257
+ * Called on release with the ids of the points inside the rectangle (edges included), in
2258
+ * item order; an empty list for a rectangle that holds none. Not called for a modifier-press
2259
+ * that did not move (a click is not a rectangle), nor after `Escape`.
2260
+ *
2261
+ * `mode` is `"add"` when ⌘/Ctrl is held as well as the modifier, `"replace"` otherwise. When
2262
+ * the modifier is `"meta"` itself, the mode is always `"replace"`.
2263
+ */
2264
+ onSelect: (ids: PointId[], mode: PointMarqueeMode) => void;
2265
+ /** Called with the rectangle (image coordinates) while it is dragged, and with `null` when it ends. */
2266
+ onBandChange?: ((band: Rect | null) => void) | undefined;
2267
+ /** Called when a marquee is abandoned: `Escape`, or the pointer was cancelled. `onSelect` is not called. */
2268
+ onCancel?: (() => void) | undefined;
2269
+ /** The key that arms the marquee. Defaults to `"shift"`. */
2270
+ modifier?: PointMarqueeModifier | undefined;
2271
+ /**
2272
+ * Whether the layer has a full-frame press target of its own. Defaults to `true`. The target
2273
+ * exists only while the modifier is held, so it never covers the layers below otherwise. Turn
2274
+ * it off to start the marquee from your own `StageSurface` through `ref`.
2275
+ */
2276
+ surface?: boolean | undefined;
2277
+ /** Turn the marquee off without unmounting it. Defaults to `true`. */
2278
+ enabled?: boolean | undefined;
2279
+ /** CSS colour of the rectangle. Defaults to the overlay `selection` role. */
2280
+ stroke?: string | undefined;
2281
+ /** Start a marquee from a press elsewhere; see `PointMarqueeHandle`. */
2282
+ ref?: Ref<PointMarqueeHandle> | undefined;
2283
+ }
2284
+ /**
2285
+ * A modifier-drag rectangle that selects points, inside an `ImageStage`.
2286
+ *
2287
+ * - **Opt-in**: a press without the modifier is left alone, so pan, wheel zoom and the layers
2288
+ * below behave as without it. While the modifier is held the layer takes presses over the
2289
+ * whole image and the cursor is a crosshair.
2290
+ * - **Reports ids**, by the points' centres, through a spatial index: thousands of points cost
2291
+ * microseconds.
2292
+ * - **Escape** abandons a marquee in flight; releasing the pointer without moving does nothing.
2293
+ * - **Touch** has no modifier: a finger pans as usual.
2294
+ *
2295
+ * It draws only the rectangle (`data-marquee`); selection feedback is the point layer's, fed by
2296
+ * the ids the app keeps. The layer carries `data-armed` while the modifier is held and
2297
+ * `data-sweeping` while a rectangle is being dragged.
2298
+ */
2299
+ export declare function PointMarquee({ items, onSelect, onBandChange, onCancel, modifier, surface, enabled, stroke, ref }: PointMarqueeProps): import("react").JSX.Element;
2300
+ //#endregion
2232
2301
  //#region src/components/areaIndex.d.ts
2233
2302
  /** An area's identity. */
2234
2303
  type AreaId = string | number;
@@ -3727,5 +3796,5 @@ interface MaskEditorProps {
3727
3796
  */
3728
3797
  export declare function MaskEditor({ mask, onChange, onCommit, editable, brushRadius, mode, label, color }: MaskEditorProps): import("react").JSX.Element;
3729
3798
  //#endregion
3730
- export type { ArcPrimitive, Area, AreaHit, AreaId, AreaIndex, AreaSetItem, AreaSetProps, ArrowStyle, Box, BuiltinMarkerKind, CaliperPrimitive, CirclePrimitive, ClampOptions, Colormap, CompareLayerProps, CompareMode, CompareOrientation, ContourEditorProps, ContourLayerProps, ContourLine, Datum, DatumEditorProps, DatumPressOptions, DimensionGeometry, DimensionPrimitive, DraftShapeProps, DraftShapeSpec, Ellipse, EllipseHit, EllipseId, EllipseIndex, EllipseSetItem, EllipseSetProps, FitOptions, GridEdgeStyle, GridLayerProps, GridNode, HeatmapLayerBaseProps, HeatmapLayerProps, HeatmapPlaneProps, HeatmapRgbaProps, HitCandidate, HitId, ImageLayerBaseProps, ImageLayerProps, ImageStageProps, ImageTier, LatticeAxis, LatticeEdge, LatticeNode, MarkerShape, MarqueeRectProps, MaskEditorProps, MeasureOverlayProps, MeasurePrimitive, MoveDatumOptions, OverlayRole, OverlayState, Point, PointHit, PointId, PointIndex, PointIndexOptions, PointItem, PointPrimitive, PointSetItem, PointSetProps, Polyline, PolylineHit, PolylineId, PolylineIndex, PolylinePrimitive, PolylineSelectMode, PolylineSetHandle, PolylineSetItem, PolylineSetProps, PrimitiveCommon, Rect, RectRoiEditorHandle, RectRoiEditorProps, RoiHandle, RotatedShape, SegmentPrimitive, SegmentsPrimitive, ShapeDragHandlers, ShapeDragOptions, ShapeEditorProps, StageButtonProps, StageContext, StageDrag, StageHandle, StageHit, StageHitLayerOptions, StageHitOptions, StageHitTestApi, StageLayer, StageLayersMenuProps, StageMouseButton, StagePointerEvent, StagePress, StageReadoutProps, StageSurfaceProps, StageToolbarDividerProps, StageToolbarProps, StageView, StageViewChange, ValuePlane, ValueRange, VectorFieldKeyProps, VectorFieldProps, VectorScale, View, ZoomPanCanvasProps };
3799
+ export type { ArcPrimitive, Area, AreaHit, AreaId, AreaIndex, AreaSetItem, AreaSetProps, ArrowStyle, Box, BuiltinMarkerKind, CaliperPrimitive, CirclePrimitive, ClampOptions, Colormap, CompareLayerProps, CompareMode, CompareOrientation, ContourEditorProps, ContourLayerProps, ContourLine, Datum, DatumEditorProps, DatumPressOptions, DimensionGeometry, DimensionPrimitive, DraftShapeProps, DraftShapeSpec, Ellipse, EllipseHit, EllipseId, EllipseIndex, EllipseSetItem, EllipseSetProps, FitOptions, GridEdgeStyle, GridLayerProps, GridNode, HeatmapLayerBaseProps, HeatmapLayerProps, HeatmapPlaneProps, HeatmapRgbaProps, HitCandidate, HitId, ImageLayerBaseProps, ImageLayerProps, ImageStageProps, ImageTier, LatticeAxis, LatticeEdge, LatticeNode, MarkerShape, MarqueeRectProps, MaskEditorProps, MeasureOverlayProps, MeasurePrimitive, MoveDatumOptions, OverlayRole, OverlayState, Point, PointHit, PointId, PointIndex, PointIndexOptions, PointItem, PointMarqueeHandle, PointMarqueeMode, PointMarqueeModifier, PointMarqueeProps, PointPrimitive, PointSetItem, PointSetProps, Polyline, PolylineHit, PolylineId, PolylineIndex, PolylinePrimitive, PolylineSelectMode, PolylineSetHandle, PolylineSetItem, PolylineSetProps, PrimitiveCommon, Rect, RectRoiEditorHandle, RectRoiEditorProps, RoiHandle, RotatedShape, SegmentPrimitive, SegmentsPrimitive, ShapeDragHandlers, ShapeDragOptions, ShapeEditorProps, StageButtonProps, StageContext, StageDrag, StageHandle, StageHit, StageHitLayerOptions, StageHitOptions, StageHitTestApi, StageLayer, StageLayersMenuProps, StageMouseButton, StagePointerEvent, StagePress, StageReadoutProps, StageSurfaceProps, StageToolbarDividerProps, StageToolbarProps, StageView, StageViewChange, ValuePlane, ValueRange, VectorFieldKeyProps, VectorFieldProps, VectorScale, View, ZoomPanCanvasProps };
3731
3800
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -5860,10 +5860,10 @@ function PolylineSet({ items, selected, dimmed, hovered, onHover, onHoverChange,
5860
5860
  });
5861
5861
  setHover(null);
5862
5862
  return {
5863
- onMove: (p) => setBand(boxBetween(from, p)),
5863
+ onMove: (p) => setBand(boxBetween$1(from, p)),
5864
5864
  onEnd: (p) => {
5865
5865
  setBand(null);
5866
- onSelect?.(polylinesInRect(index, boxBetween(from, p)), additive ? "add" : "replace");
5866
+ onSelect?.(polylinesInRect(index, boxBetween$1(from, p)), additive ? "add" : "replace");
5867
5867
  },
5868
5868
  onCancel: () => setBand(null)
5869
5869
  };
@@ -6017,7 +6017,7 @@ function PolylineSet({ items, selected, dimmed, hovered, onHover, onHoverChange,
6017
6017
  ]
6018
6018
  });
6019
6019
  }
6020
- function boxBetween(a, b) {
6020
+ function boxBetween$1(a, b) {
6021
6021
  return {
6022
6022
  x: Math.min(a.x, b.x),
6023
6023
  y: Math.min(a.y, b.y),
@@ -6401,6 +6401,160 @@ function cullWindow$1(view, box, count) {
6401
6401
  };
6402
6402
  }
6403
6403
  //#endregion
6404
+ //#region src/components/PointMarquee.tsx
6405
+ /**
6406
+ * A rectangular marquee over a point set: hold a modifier, drag, and the ids of the points
6407
+ * inside the rectangle are reported.
6408
+ *
6409
+ * Opt-in and inert without its modifier: a press without it is left to the stage (which pans),
6410
+ * the wheel still zooms, and the layers below keep their own targets. The rectangle is drawn
6411
+ * with `MarqueeRect` while the pointer moves.
6412
+ */
6413
+ /** Whether a pointer or key event holds the modifier. */
6414
+ function holds(modifier, event) {
6415
+ if (modifier === "shift") return event.shiftKey;
6416
+ if (modifier === "alt") return event.altKey;
6417
+ return event.metaKey || event.ctrlKey;
6418
+ }
6419
+ function boxBetween(a, b) {
6420
+ return {
6421
+ x: Math.min(a.x, b.x),
6422
+ y: Math.min(a.y, b.y),
6423
+ width: Math.abs(b.x - a.x),
6424
+ height: Math.abs(b.y - a.y)
6425
+ };
6426
+ }
6427
+ /**
6428
+ * A modifier-drag rectangle that selects points, inside an `ImageStage`.
6429
+ *
6430
+ * - **Opt-in**: a press without the modifier is left alone, so pan, wheel zoom and the layers
6431
+ * below behave as without it. While the modifier is held the layer takes presses over the
6432
+ * whole image and the cursor is a crosshair.
6433
+ * - **Reports ids**, by the points' centres, through a spatial index: thousands of points cost
6434
+ * microseconds.
6435
+ * - **Escape** abandons a marquee in flight; releasing the pointer without moving does nothing.
6436
+ * - **Touch** has no modifier: a finger pans as usual.
6437
+ *
6438
+ * It draws only the rectangle (`data-marquee`); selection feedback is the point layer's, fed by
6439
+ * the ids the app keeps. The layer carries `data-armed` while the modifier is held and
6440
+ * `data-sweeping` while a rectangle is being dragged.
6441
+ */
6442
+ function PointMarquee({ items, onSelect, onBandChange, onCancel, modifier = "shift", surface = true, enabled = true, stroke, ref }) {
6443
+ const stage = useStage();
6444
+ const startDrag = useStageDrag();
6445
+ const index = useMemo(() => buildPointIndexFrom(items), [items]);
6446
+ const [band, setBand] = useState(null);
6447
+ const [held, setHeld] = useState(false);
6448
+ const armed = enabled && surface && held;
6449
+ const abandoned = useRef(false);
6450
+ const live = useRef({
6451
+ onSelect,
6452
+ onBandChange,
6453
+ onCancel
6454
+ });
6455
+ useEffect(() => {
6456
+ live.current = {
6457
+ onSelect,
6458
+ onBandChange,
6459
+ onCancel
6460
+ };
6461
+ });
6462
+ const publish = (next) => {
6463
+ setBand(next);
6464
+ live.current.onBandChange?.(next);
6465
+ };
6466
+ useEffect(() => {
6467
+ if (!enabled || !surface) return;
6468
+ const sync = (event) => setHeld(holds(modifier, event));
6469
+ const off = () => setHeld(false);
6470
+ window.addEventListener("keydown", sync);
6471
+ window.addEventListener("keyup", sync);
6472
+ window.addEventListener("pointermove", sync);
6473
+ window.addEventListener("blur", off);
6474
+ return () => {
6475
+ window.removeEventListener("keydown", sync);
6476
+ window.removeEventListener("keyup", sync);
6477
+ window.removeEventListener("pointermove", sync);
6478
+ window.removeEventListener("blur", off);
6479
+ };
6480
+ }, [
6481
+ enabled,
6482
+ surface,
6483
+ modifier
6484
+ ]);
6485
+ const sweeping = band !== null;
6486
+ useEffect(() => {
6487
+ if (!sweeping) return;
6488
+ const onKey = (event) => {
6489
+ if (event.key !== "Escape" || abandoned.current) return;
6490
+ abandoned.current = true;
6491
+ publish(null);
6492
+ live.current.onCancel?.();
6493
+ };
6494
+ window.addEventListener("keydown", onKey);
6495
+ return () => window.removeEventListener("keydown", onKey);
6496
+ }, [sweeping]);
6497
+ const dragFrom = (from, additive, claimsTouch) => {
6498
+ abandoned.current = false;
6499
+ publish({
6500
+ x: from.x,
6501
+ y: from.y,
6502
+ width: 0,
6503
+ height: 0
6504
+ });
6505
+ return {
6506
+ claimsTouch,
6507
+ onMove: (p) => {
6508
+ if (!abandoned.current) publish(boxBetween(from, p));
6509
+ },
6510
+ onEnd: (p, _event, moved) => {
6511
+ if (abandoned.current) return;
6512
+ publish(null);
6513
+ if (moved) live.current.onSelect(pointsInRect(index, boxBetween(from, p)).map((i) => idAt(i)), additive ? "add" : "replace");
6514
+ },
6515
+ onCancel: () => {
6516
+ if (abandoned.current) return;
6517
+ abandoned.current = true;
6518
+ publish(null);
6519
+ live.current.onCancel?.();
6520
+ }
6521
+ };
6522
+ };
6523
+ const idAt = (i) => index.ids ? index.ids[i] : i;
6524
+ const additiveOf = (event) => modifier !== "meta" && (event.metaKey || event.ctrlKey);
6525
+ useImperativeHandle(ref, () => ({ sweepDrag: (press) => {
6526
+ if (!enabled || press.touch) return void 0;
6527
+ return (modifier === "shift" ? press.shiftKey : modifier === "alt" ? press.altKey : press.metaKey) ? dragFrom(press.point, modifier !== "meta" && press.metaKey, false) : void 0;
6528
+ } }));
6529
+ const onPointerDown = (event) => {
6530
+ if (!enabled || stage.panMode || event.button !== 0 || event.pointerType === "touch" || !holds(modifier, event)) return;
6531
+ startDrag(event, dragFrom(stage.toImage({
6532
+ x: event.clientX,
6533
+ y: event.clientY
6534
+ }), additiveOf(event), false));
6535
+ };
6536
+ return /* @__PURE__ */ jsxs(Fragment, { children: [armed && /* @__PURE__ */ jsx("svg", {
6537
+ viewBox: imageViewBox(stage.image),
6538
+ className: "pointer-events-none absolute inset-0 h-full w-full overflow-visible",
6539
+ "aria-hidden": true,
6540
+ "data-armed": "",
6541
+ "data-sweeping": sweeping ? "" : void 0,
6542
+ children: /* @__PURE__ */ jsx("rect", {
6543
+ "data-marquee-surface": "",
6544
+ x: -.5,
6545
+ y: -.5,
6546
+ width: stage.image.width,
6547
+ height: stage.image.height,
6548
+ fill: "transparent",
6549
+ className: "pointer-events-auto cursor-crosshair",
6550
+ onPointerDown
6551
+ })
6552
+ }), /* @__PURE__ */ jsx(MarqueeRect, {
6553
+ rect: band,
6554
+ stroke
6555
+ })] });
6556
+ }
6557
+ //#endregion
6404
6558
  //#region src/components/areaIndex.ts
6405
6559
  /** The most grid cells an index allocates, and the most area-to-cell entries. */
6406
6560
  const MAX_CELLS = 4e6;
@@ -9625,6 +9779,6 @@ function MaskEditor({ mask, onChange, onCommit, editable = false, brushRadius =
9625
9779
  })] });
9626
9780
  }
9627
9781
  //#endregion
9628
- export { AreaSet, CompareLayer, ContourEditor, ContourLayer, DATUM_ARM_PX, DATUM_HANDLE_PX, DATUM_RING_PX, DatumEditor, DraftShape, EllipseSet, FULL_TIER_ZOOM, GridLayer, HeatmapLayer, ImageLayer, ImageStage, MARKER_SHAPES, MAX_SCALE, MAX_ZOOM, MIN_SCALE_VS_FIT, MIN_ZOOM, MarqueeRect, MaskEditor, MeasureOverlay, OVERLAY_ROLES, OVERLAY_STATE_OPACITY, OVERLAY_STATE_WIDTH, PIXEL_CENTRE, PlaneFormatError, PointSet, PolylineSet, RESET_VIEW, ROI_HANDLES, ROI_HANDLE_CURSOR, RectRoiEditor, STAGE_HIT_PRIORITY, ShapeEditor, StageButton, StageLayersMenu, StageReadout, StageSurface, StageToolbar, StageToolbarDivider, VECTOR_COLOR_BINS, VectorField, VectorFieldKey, ZoomPanCanvas, arcLengths, arcPath, areaCentre, areaPath, areasInRect, arrowHeadPoints, arrowPath, buildAreaIndex, buildEllipseIndex, buildPointIndex, buildPointIndexFrom, buildPolylineIndex, caliperArrow, caliperCorners, circlePath, clampRect, clampToImage, clampView, colorBin, contentUnder, contourPaths, crossSegments, datumAxes, datumPress, decodePlane, deformContour, dimensionGeometry, ellipseBounds, ellipsePath, ellipsesInRect, eraseArc, fetchPlane, fitScale, fitView, formatScale, fractionOf, frameRect, fromShapeFrame, imageLengthFor, imagePerUnit, imageViewBox, initialView, insideImage, isFit, latticeEdges, magnitudePercentile, measurePrimitiveDistance, moveDatum, moveRect, moveShape, nativeZoomFor, nearestArea, nearestContourSegment, nearestEllipse, nearestMeasurePrimitive, nearestPoint, nearestPolyline, niceLength, normalAtArc, normalizeAngle, overlayRole, paintMask, planeRange, pointAtArc, pointInEllipse, pointInPolygon, pointsInRect, polygonPath, polylineBounds, polylinePath, polylinesInRect, preserveCenter, projectToArc, rasterizePlane, rectFromCorners, resizeRect, resizeShape, resolveLevels, roiHandlePoint, rotateDatum, rotatePoint, rotateShape, rotationHandlePoint, sameRect, sameShape, scaleRange, segmentsPath, shapeCorner, shapeFromCorner, shapeHandleCursor, shapeHandlePoint, snapAngle, steppedScale, strokeWidthFor, subPath, thinPoints, toImage, toScreen, toShapeFrame, translatePoints, useScreenPx, useShapeDrag, useStage, useStageDrag, useStageHitLayer, useStageHitTest, useVectorScale, valueAt, valuesAt, vectorMagnitude, vectorMagnitudes, zoomAbout, zoomAt };
9782
+ export { AreaSet, CompareLayer, ContourEditor, ContourLayer, DATUM_ARM_PX, DATUM_HANDLE_PX, DATUM_RING_PX, DatumEditor, DraftShape, EllipseSet, FULL_TIER_ZOOM, GridLayer, HeatmapLayer, ImageLayer, ImageStage, MARKER_SHAPES, MAX_SCALE, MAX_ZOOM, MIN_SCALE_VS_FIT, MIN_ZOOM, MarqueeRect, MaskEditor, MeasureOverlay, OVERLAY_ROLES, OVERLAY_STATE_OPACITY, OVERLAY_STATE_WIDTH, PIXEL_CENTRE, PlaneFormatError, PointMarquee, PointSet, PolylineSet, RESET_VIEW, ROI_HANDLES, ROI_HANDLE_CURSOR, RectRoiEditor, STAGE_HIT_PRIORITY, ShapeEditor, StageButton, StageLayersMenu, StageReadout, StageSurface, StageToolbar, StageToolbarDivider, VECTOR_COLOR_BINS, VectorField, VectorFieldKey, ZoomPanCanvas, arcLengths, arcPath, areaCentre, areaPath, areasInRect, arrowHeadPoints, arrowPath, buildAreaIndex, buildEllipseIndex, buildPointIndex, buildPointIndexFrom, buildPolylineIndex, caliperArrow, caliperCorners, circlePath, clampRect, clampToImage, clampView, colorBin, contentUnder, contourPaths, crossSegments, datumAxes, datumPress, decodePlane, deformContour, dimensionGeometry, ellipseBounds, ellipsePath, ellipsesInRect, eraseArc, fetchPlane, fitScale, fitView, formatScale, fractionOf, frameRect, fromShapeFrame, imageLengthFor, imagePerUnit, imageViewBox, initialView, insideImage, isFit, latticeEdges, magnitudePercentile, measurePrimitiveDistance, moveDatum, moveRect, moveShape, nativeZoomFor, nearestArea, nearestContourSegment, nearestEllipse, nearestMeasurePrimitive, nearestPoint, nearestPolyline, niceLength, normalAtArc, normalizeAngle, overlayRole, paintMask, planeRange, pointAtArc, pointInEllipse, pointInPolygon, pointsInRect, polygonPath, polylineBounds, polylinePath, polylinesInRect, preserveCenter, projectToArc, rasterizePlane, rectFromCorners, resizeRect, resizeShape, resolveLevels, roiHandlePoint, rotateDatum, rotatePoint, rotateShape, rotationHandlePoint, sameRect, sameShape, scaleRange, segmentsPath, shapeCorner, shapeFromCorner, shapeHandleCursor, shapeHandlePoint, snapAngle, steppedScale, strokeWidthFor, subPath, thinPoints, toImage, toScreen, toShapeFrame, translatePoints, useScreenPx, useShapeDrag, useStage, useStageDrag, useStageHitLayer, useStageHitTest, useVectorScale, valueAt, valuesAt, vectorMagnitude, vectorMagnitudes, zoomAbout, zoomAt };
9629
9783
 
9630
9784
  //# sourceMappingURL=index.js.map