@vitavision/stage2d 0.13.2 → 0.15.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 CHANGED
@@ -21,7 +21,8 @@ deprecated predecessor, still exported unchanged.
21
21
 
22
22
  `ImageLayer` draws the photograph at its natural size. It can show a `preview` tier until
23
23
  the stage would magnify it, then load the full image and keep it, and it turns pixelated past
24
- `pixelatedAbove`. `StageButton` takes a `hint` and a `shortcut` for a richer tooltip, and
24
+ `pixelatedAbove`. `gain` and `gamma` draw it through a display tone curve (`gain × v^(1 / gamma)`
25
+ per channel, on screen only) for reading a dark or low-contrast frame. `StageButton` takes a `hint` and a `shortcut` for a richer tooltip, and
25
26
  `StageLayersMenu` is a layers button for `StageToolbar`. Code outside the stage, such as an
26
27
  inspector's "frame this", drives it through `ImageStage`'s `ref` (`StageHandle`: `frame`,
27
28
  `fit`, `zoomTo`). `initialView="fit"` opens a `null` view at fit even when the image would fit
package/dist/index.d.ts CHANGED
@@ -538,6 +538,12 @@ interface StageHitLayerOptions {
538
538
  layerId?: string | undefined;
539
539
  /** Rank against other layers; see `STAGE_HIT_PRIORITY`. */
540
540
  priority: number;
541
+ /**
542
+ * Whether the layer is in the hit-test. Defaults to `true`. Off, it answers no hit-test and
543
+ * takes no hover or press; turning it off while it holds the hover calls `onHover(null)`.
544
+ * The layer id stays the same either way.
545
+ */
546
+ enabled?: boolean | undefined;
541
547
  /**
542
548
  * The item under `point`, if any, within `radius` image pixels. Use the layer's index
543
549
  * (`nearestPoint`, `nearestPolyline`), not the DOM.
@@ -650,6 +656,8 @@ export declare function CompareLayer({ a, b, mode, split, defaultSplit, onSplitC
650
656
  * - **Pixelated past a zoom.** Above about 4× the browser's smoothing paints detail the
651
657
  * sensor never recorded; on a metrology bench the sensor's own samples are what is worth
652
658
  * looking at.
659
+ * - **A display tone curve.** A dark or low-contrast frame is read with a gain and a gamma
660
+ * applied on screen only (`gain`, `gamma`): the pixels the app measures are untouched.
653
661
  */
654
662
  /** A downscaled tier of the image, shown until the stage would magnify it. */
655
663
  interface ImageTier {
@@ -675,6 +683,20 @@ interface ImageLayerBaseProps {
675
683
  onLoad?: (() => void) | undefined;
676
684
  /** Called when the full image fails to load. */
677
685
  onError?: (() => void) | undefined;
686
+ /**
687
+ * Display gain: each channel is multiplied by it and clipped at white, after `gamma`.
688
+ * Defaults to 1. A negative value counts as 0, one that is not finite as 1.
689
+ *
690
+ * Like `gamma`, it changes what is drawn, never the image data: a way to read a dark or
691
+ * low-contrast frame, not a correction to measure on.
692
+ */
693
+ gain?: number | undefined;
694
+ /**
695
+ * Display gamma, as an image editor's levels control: each channel `v` (0 to 1, as encoded in
696
+ * the file) is drawn as `gain × v^(1 / gamma)`. Above 1 it lifts the shadows and mid-tones,
697
+ * below 1 it darkens them. Defaults to 1; a value that is not positive counts as 1.
698
+ */
699
+ gamma?: number | undefined;
678
700
  /** Merged onto both images with `cn`. */
679
701
  className?: string | undefined;
680
702
  }
@@ -701,11 +723,14 @@ type ImageLayerProps = ImageLayerBaseProps & ({
701
723
  * With a `preview`, the full image is wanted once the stage would magnify the preview, and
702
724
  * `onFullNeeded` says so; `src` can be supplied then rather than up front.
703
725
  *
726
+ * With a `gain` or `gamma` other than 1, both images are drawn through one SVG tone-curve filter
727
+ * (sRGB values, per channel) and carry `data-adjusted`.
728
+ *
704
729
  * Each image carries `data-tier` (`preview` or `full`); the full image carries `data-loaded`
705
730
  * once it has loaded, the preview carries `data-wants-full` from the moment the full image is
706
731
  * wanted until it has loaded, and both carry `data-pixelated` while pixelated.
707
732
  */
708
- export declare function ImageLayer({ src, preview, alt, pixelatedAbove, onFullNeeded, onLoad, onError, className }: ImageLayerProps): import("react").JSX.Element;
733
+ export declare function ImageLayer({ src, preview, alt, pixelatedAbove, onFullNeeded, onLoad, onError, gain, gamma, className }: ImageLayerProps): import("react").JSX.Element;
709
734
  //#endregion
710
735
  //#region src/components/stage/StageSurface.d.ts
711
736
  /** What a drag does as the pointer moves and when it is released, in image coordinates. */
@@ -2148,7 +2173,7 @@ interface PointSetProps {
2148
2173
  markers?: Readonly<Record<string, MarkerShape>> | undefined;
2149
2174
  /** The hovered id, when the app controls hover (a list beside the stage hovers points too). */
2150
2175
  hoveredId?: PointId | null | undefined;
2151
- /** Called when the point under the pointer changes. `null` when it leaves every point. */
2176
+ /** Called when the point under the pointer changes. `null` when it leaves every point. Not called while `pickable` is off; turning it off ends a hover with `null`. */
2152
2177
  onHoverChange?: ((id: PointId | null) => void) | undefined;
2153
2178
  /** The selected ids, drawn at 2.5 px in the selection colour with a ring. */
2154
2179
  selectedIds?: Iterable<PointId> | undefined;
@@ -2172,6 +2197,12 @@ interface PointSetProps {
2172
2197
  halo?: boolean | undefined;
2173
2198
  /** CSS colour of selected points and rings. Defaults to the overlay `selection` role. */
2174
2199
  selectionStroke?: string | undefined;
2200
+ /**
2201
+ * Whether the layer takes part in the stage's hit-test. On by default. Turn it off for a
2202
+ * decorative layer (a backdrop of markers under the points that matter), so it neither
2203
+ * hovers, nor claims presses, nor answers `useStageHitTest`.
2204
+ */
2205
+ pickable?: boolean | undefined;
2175
2206
  /** The id hit-tests report for this layer. Defaults to a generated one. */
2176
2207
  layerId?: string | undefined;
2177
2208
  /** Rank against other layers in hit-tests. Defaults to `STAGE_HIT_PRIORITY.point`. */
@@ -2188,7 +2219,7 @@ interface PointSetProps {
2188
2219
  * selection colour with a ring, dimmed at 35 % opacity. Every mark has a halo.
2189
2220
  * - **Labels** only where points are at least 24 screen px apart, at most 200 at a time.
2190
2221
  * - **Picking** goes through the stage's hit registry: `onHoverChange` and `onItemPress` here,
2191
- * and `useStageHitTest` for an app that arbitrates between layers.
2222
+ * and `useStageHitTest` for an app that arbitrates between layers. `pickable={false}` turns it off.
2192
2223
  *
2193
2224
  * Outlines (`plus`, `cross`, …) are regenerated when the zoom changes, since their size is in
2194
2225
  * screen pixels; past 3,000 points only those near the viewport are generated. `dot` is a
@@ -2196,7 +2227,7 @@ interface PointSetProps {
2196
2227
  *
2197
2228
  * The SVG carries `data-hovered` (the hovered id).
2198
2229
  */
2199
- export declare function PointSet({ items, kind, markers, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, labels, halo, selectionStroke, layerId, priority, label }: PointSetProps): import("react").JSX.Element;
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;
2200
2231
  //#endregion
2201
2232
  //#region src/components/areaIndex.d.ts
2202
2233
  /** An area's identity. */
@@ -2330,7 +2361,7 @@ interface AreaSetProps {
2330
2361
  role?: OverlayRole | undefined;
2331
2362
  /** The hovered id, when the app controls hover (a list beside the stage hovers regions too). */
2332
2363
  hoveredId?: AreaId | null | undefined;
2333
- /** Called when the region under the pointer changes. `null` when it leaves every region. */
2364
+ /** Called when the region under the pointer changes. `null` when it leaves every region. Not called while `pickable` is off; turning it off ends a hover with `null`. */
2334
2365
  onHoverChange?: ((id: AreaId | null) => void) | undefined;
2335
2366
  /** The selected ids, drawn at 2.5 px in the selection colour. */
2336
2367
  selectedIds?: Iterable<AreaId> | undefined;
@@ -2383,6 +2414,12 @@ interface AreaSetProps {
2383
2414
  halo?: boolean | undefined;
2384
2415
  /** CSS colour of selected regions. Defaults to the overlay `selection` role. */
2385
2416
  selectionStroke?: string | undefined;
2417
+ /**
2418
+ * Whether the layer takes part in the stage's hit-test. On by default. Turn it off for a
2419
+ * decorative layer (a shaded backdrop under the regions that matter), so it neither hovers,
2420
+ * nor claims presses, nor answers `useStageHitTest`.
2421
+ */
2422
+ pickable?: boolean | undefined;
2386
2423
  /** The id hit-tests report for this layer. Defaults to a generated one. */
2387
2424
  layerId?: string | undefined;
2388
2425
  /** Rank against other layers in hit-tests. Defaults to `STAGE_HIT_PRIORITY.area`. */
@@ -2405,10 +2442,11 @@ interface AreaSetProps {
2405
2442
  * - **Picking** goes through the stage's hit registry: a press within the pointer's tolerance of
2406
2443
  * an outline picks that region, else the smallest region containing the point. `onHoverChange`
2407
2444
  * and `onItemPress` here, and `useStageHitTest` for an app that arbitrates between layers.
2445
+ * `pickable={false}` turns it off.
2408
2446
  *
2409
2447
  * The SVG carries `data-hovered` (the hovered id).
2410
2448
  */
2411
- export declare function AreaSet({ items, role, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, labels, firstVertexTick, stroke, fillOpacity, fillRule, paintOrder, selectionFill, halo, selectionStroke, layerId, priority, label }: AreaSetProps): import("react").JSX.Element;
2449
+ export declare function AreaSet({ items, role, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, pickable, labels, firstVertexTick, stroke, fillOpacity, fillRule, paintOrder, selectionFill, halo, selectionStroke, layerId, priority, label }: AreaSetProps): import("react").JSX.Element;
2412
2450
  //#endregion
2413
2451
  //#region src/components/ellipseIndex.d.ts
2414
2452
  /** An ellipse's identity. */
@@ -2517,6 +2555,12 @@ export declare function ellipsesInRect(index: EllipseIndex, rect: Rect): Ellipse
2517
2555
  interface EllipseSetItem extends Ellipse {
2518
2556
  /** The overlay role it is painted in. Defaults to the layer's `role`. */
2519
2557
  role?: OverlayRole | undefined;
2558
+ /**
2559
+ * CSS colour of its outline (`#hex`, `var(--x)`, `color-mix(…)`; used as given), so a layer can
2560
+ * encode a scalar per ellipse. Overrides the role; selection still paints in `selectionStroke`.
2561
+ * Ellipses sharing a colour share a path, so quantise a continuous scale to a few dozen steps.
2562
+ */
2563
+ color?: string | undefined;
2520
2564
  /** Draw it dashed (4 3 screen px), so two kinds differ by more than colour. */
2521
2565
  dashed?: boolean | undefined;
2522
2566
  /** Opacity in [0, 1], rounded to a tenth so ellipses still share paths. Defaults to 1. */
@@ -2530,7 +2574,7 @@ interface EllipseSetProps {
2530
2574
  role?: OverlayRole | undefined;
2531
2575
  /** The hovered id, when the app controls hover: its ellipses are drawn at 2 px. */
2532
2576
  hoveredId?: EllipseId | null | undefined;
2533
- /** Called when the ellipse under the pointer changes. `null` when it leaves every ellipse. Not called when `pickable` is off. */
2577
+ /** Called when the ellipse under the pointer changes. `null` when it leaves every ellipse. Not called while `pickable` is off; turning it off ends a hover with `null`. */
2534
2578
  onHoverChange?: ((id: EllipseId | null) => void) | undefined;
2535
2579
  /** The selected ids, drawn at 2.5 px in the selection colour. */
2536
2580
  selectedIds?: Iterable<EllipseId> | undefined;
@@ -2574,7 +2618,7 @@ interface EllipseSetProps {
2574
2618
  * the stroke is a screen constant.
2575
2619
  * - **States**: 1.5 screen px (1 for `model` and `structure`), hover
2576
2620
  * 2, selected 2.5 in the selection colour, dimmed at 35 % opacity. Every stroke has a halo.
2577
- * - **Batching** is by (role, dash, opacity, dimming): a thousand rings are a dozen elements.
2621
+ * - **Batching** is by (role, colour, dash, opacity, dimming): a thousand rings are a dozen elements.
2578
2622
  * - **Picking** goes through the stage's hit registry: a press within the pointer's tolerance of
2579
2623
  * an outline picks that ellipse, else the smallest ellipse containing the point.
2580
2624
  * `onHoverChange` and `onItemPress` here, and `useStageHitTest` for an app that arbitrates
package/dist/index.js CHANGED
@@ -391,7 +391,10 @@ function createHitRegistry() {
391
391
  layers.add(layer);
392
392
  return () => {
393
393
  layers.delete(layer);
394
- if (hovered?.layer === layer) hovered = null;
394
+ if (hovered?.layer === layer) {
395
+ hovered = null;
396
+ layer.hover?.(null);
397
+ }
395
398
  };
396
399
  },
397
400
  hitTestAll: (point, radius, options) => answers(point, radius, options).map((a) => a.hit),
@@ -1141,7 +1144,9 @@ function useStageHitLayer(options) {
1141
1144
  latestRef.current = options;
1142
1145
  });
1143
1146
  const priority = options.priority;
1147
+ const enabled = options.enabled ?? true;
1144
1148
  useLayoutEffect(() => {
1149
+ if (!enabled) return;
1145
1150
  const layer = {
1146
1151
  id,
1147
1152
  priority,
@@ -1163,7 +1168,8 @@ function useStageHitLayer(options) {
1163
1168
  }, [
1164
1169
  registry,
1165
1170
  id,
1166
- priority
1171
+ priority,
1172
+ enabled
1167
1173
  ]);
1168
1174
  return id;
1169
1175
  }
@@ -2163,6 +2169,8 @@ function CompareLayer({ a, b, mode, split, defaultSplit = .5, onSplitChange, ori
2163
2169
  * - **Pixelated past a zoom.** Above about 4× the browser's smoothing paints detail the
2164
2170
  * sensor never recorded; on a metrology bench the sensor's own samples are what is worth
2165
2171
  * looking at.
2172
+ * - **A display tone curve.** A dark or low-contrast frame is read with a gain and a gamma
2173
+ * applied on screen only (`gain`, `gamma`): the pixels the app measures are untouched.
2166
2174
  */
2167
2175
  /**
2168
2176
  * The photograph at its natural size inside an `ImageStage`, with an optional preview tier
@@ -2172,12 +2180,17 @@ function CompareLayer({ a, b, mode, split, defaultSplit = .5, onSplitChange, ori
2172
2180
  * With a `preview`, the full image is wanted once the stage would magnify the preview, and
2173
2181
  * `onFullNeeded` says so; `src` can be supplied then rather than up front.
2174
2182
  *
2183
+ * With a `gain` or `gamma` other than 1, both images are drawn through one SVG tone-curve filter
2184
+ * (sRGB values, per channel) and carry `data-adjusted`.
2185
+ *
2175
2186
  * Each image carries `data-tier` (`preview` or `full`); the full image carries `data-loaded`
2176
2187
  * once it has loaded, the preview carries `data-wants-full` from the moment the full image is
2177
2188
  * wanted until it has loaded, and both carry `data-pixelated` while pixelated.
2178
2189
  */
2179
- function ImageLayer({ src, preview, alt, pixelatedAbove = 4, onFullNeeded, onLoad, onError, className }) {
2190
+ function ImageLayer({ src, preview, alt, pixelatedAbove = 4, onFullNeeded, onLoad, onError, gain, gamma, className }) {
2180
2191
  const stage = useStage();
2192
+ const curve = toneCurve(gain, gamma);
2193
+ const filterId = `stage-image-tone-${useId().replace(/[^A-Za-z0-9_-]/g, "")}`;
2181
2194
  const scale = stage.view.scale;
2182
2195
  const measured = stage.box.width > 0;
2183
2196
  const previewSrc = preview?.src ?? null;
@@ -2200,32 +2213,86 @@ function ImageLayer({ src, preview, alt, pixelatedAbove = 4, onFullNeeded, onLoa
2200
2213
  const fullReady = src !== void 0 && loaded === src;
2201
2214
  const pixelated = scale >= pixelatedAbove;
2202
2215
  const shared = cn("pointer-events-none absolute inset-0 h-full w-full select-none", className);
2203
- const rendering = pixelated ? "pixelated" : void 0;
2204
- return /* @__PURE__ */ jsxs(Fragment, { children: [preview && !fullReady && /* @__PURE__ */ jsx("img", {
2205
- src: preview.src,
2206
- alt: showFull ? "" : alt,
2207
- "aria-hidden": showFull ? true : void 0,
2208
- draggable: false,
2209
- "data-tier": "preview",
2210
- "data-wants-full": wanted ? "" : void 0,
2211
- "data-pixelated": pixelated ? "" : void 0,
2212
- className: shared,
2213
- style: { imageRendering: rendering }
2214
- }), showFull && /* @__PURE__ */ jsx("img", {
2215
- src,
2216
- alt,
2217
- draggable: false,
2218
- "data-tier": "full",
2219
- "data-loaded": fullReady ? "" : void 0,
2220
- "data-pixelated": pixelated ? "" : void 0,
2221
- onLoad: () => {
2222
- setLoaded(src);
2223
- onLoad?.();
2224
- },
2225
- onError: () => onError?.(),
2226
- className: cn(shared, preview && !fullReady && "opacity-0"),
2227
- style: { imageRendering: rendering }
2228
- })] });
2216
+ const style = {
2217
+ imageRendering: pixelated ? "pixelated" : void 0,
2218
+ filter: curve ? `url(#${filterId})` : void 0
2219
+ };
2220
+ const adjusted = curve ? "" : void 0;
2221
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2222
+ curve && /* @__PURE__ */ jsx("svg", {
2223
+ "aria-hidden": "true",
2224
+ width: "0",
2225
+ height: "0",
2226
+ className: "pointer-events-none absolute",
2227
+ focusable: "false",
2228
+ children: /* @__PURE__ */ jsx("filter", {
2229
+ id: filterId,
2230
+ colorInterpolationFilters: "sRGB",
2231
+ "data-tone-curve": "",
2232
+ children: /* @__PURE__ */ jsxs("feComponentTransfer", { children: [
2233
+ /* @__PURE__ */ jsx("feFuncR", {
2234
+ type: "gamma",
2235
+ amplitude: curve.amplitude,
2236
+ exponent: curve.exponent,
2237
+ offset: 0
2238
+ }),
2239
+ /* @__PURE__ */ jsx("feFuncG", {
2240
+ type: "gamma",
2241
+ amplitude: curve.amplitude,
2242
+ exponent: curve.exponent,
2243
+ offset: 0
2244
+ }),
2245
+ /* @__PURE__ */ jsx("feFuncB", {
2246
+ type: "gamma",
2247
+ amplitude: curve.amplitude,
2248
+ exponent: curve.exponent,
2249
+ offset: 0
2250
+ })
2251
+ ] })
2252
+ })
2253
+ }),
2254
+ preview && !fullReady && /* @__PURE__ */ jsx("img", {
2255
+ src: preview.src,
2256
+ alt: showFull ? "" : alt,
2257
+ "aria-hidden": showFull ? true : void 0,
2258
+ draggable: false,
2259
+ "data-tier": "preview",
2260
+ "data-wants-full": wanted ? "" : void 0,
2261
+ "data-pixelated": pixelated ? "" : void 0,
2262
+ "data-adjusted": adjusted,
2263
+ className: shared,
2264
+ style
2265
+ }),
2266
+ showFull && /* @__PURE__ */ jsx("img", {
2267
+ src,
2268
+ alt,
2269
+ draggable: false,
2270
+ "data-tier": "full",
2271
+ "data-loaded": fullReady ? "" : void 0,
2272
+ "data-pixelated": pixelated ? "" : void 0,
2273
+ "data-adjusted": adjusted,
2274
+ onLoad: () => {
2275
+ setLoaded(src);
2276
+ onLoad?.();
2277
+ },
2278
+ onError: () => onError?.(),
2279
+ className: cn(shared, preview && !fullReady && "opacity-0"),
2280
+ style
2281
+ })
2282
+ ] });
2283
+ }
2284
+ /**
2285
+ * The `feFuncX type="gamma"` parameters (`amplitude × v^exponent`) for a gain and a gamma, or
2286
+ * `null` when the curve is the identity and no filter is needed.
2287
+ */
2288
+ function toneCurve(gain, gamma) {
2289
+ const amplitude = gain === void 0 || !Number.isFinite(gain) ? 1 : Math.max(0, gain);
2290
+ const g = gamma === void 0 || !(gamma > 0) || !Number.isFinite(gamma) ? 1 : gamma;
2291
+ if (amplitude === 1 && g === 1) return null;
2292
+ return {
2293
+ amplitude,
2294
+ exponent: 1 / g
2295
+ };
2229
2296
  }
2230
2297
  //#endregion
2231
2298
  //#region src/components/stage/StageToolbar.tsx
@@ -4159,7 +4226,6 @@ function MeasureHitLayer({ primitives, strokeScale, layerId, priority, setOwnHov
4159
4226
  },
4160
4227
  onPress: onItemPress ? (id, event) => onItemPress(String(id), event) : void 0
4161
4228
  });
4162
- useEffect(() => () => setOwnHover(null), [setOwnHover]);
4163
4229
  return null;
4164
4230
  }
4165
4231
  function Primitive({ primitive, colour, hairline, thick, dash, labelSize, labelHalo, strokeScale, grow }) {
@@ -6058,7 +6124,7 @@ const LABEL$1 = overlayRole("label");
6058
6124
  * selection colour with a ring, dimmed at 35 % opacity. Every mark has a halo.
6059
6125
  * - **Labels** only where points are at least 24 screen px apart, at most 200 at a time.
6060
6126
  * - **Picking** goes through the stage's hit registry: `onHoverChange` and `onItemPress` here,
6061
- * and `useStageHitTest` for an app that arbitrates between layers.
6127
+ * and `useStageHitTest` for an app that arbitrates between layers. `pickable={false}` turns it off.
6062
6128
  *
6063
6129
  * Outlines (`plus`, `cross`, …) are regenerated when the zoom changes, since their size is in
6064
6130
  * screen pixels; past 3,000 points only those near the viewport are generated. `dot` is a
@@ -6066,7 +6132,7 @@ const LABEL$1 = overlayRole("label");
6066
6132
  *
6067
6133
  * The SVG carries `data-hovered` (the hovered id).
6068
6134
  */
6069
- function PointSet({ items, kind = "dot", markers, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, labels = true, halo = true, selectionStroke = overlayRole("selection"), layerId, priority = STAGE_HIT_PRIORITY.point, label = "Points" }) {
6135
+ function PointSet({ items, kind = "dot", markers, hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, pickable = true, labels = true, halo = true, selectionStroke = overlayRole("selection"), layerId, priority = STAGE_HIT_PRIORITY.point, label = "Points" }) {
6070
6136
  const stage = useStage();
6071
6137
  const px = useScreenPx();
6072
6138
  const unit = px(1);
@@ -6087,6 +6153,7 @@ function PointSet({ items, kind = "dot", markers, hoveredId, onHoverChange, sele
6087
6153
  useStageHitLayer({
6088
6154
  layerId,
6089
6155
  priority,
6156
+ enabled: pickable,
6090
6157
  pick: (point, radius) => {
6091
6158
  const hit = nearestPoint(index, point.x, point.y, radius);
6092
6159
  return hit ? {
@@ -6098,7 +6165,7 @@ function PointSet({ items, kind = "dot", markers, hoveredId, onHoverChange, sele
6098
6165
  setOwnHover(id);
6099
6166
  onHoverChange?.(id);
6100
6167
  },
6101
- onPress: onItemPress ? (id, event) => onItemPress(id, event) : void 0
6168
+ onPress: onItemPress
6102
6169
  });
6103
6170
  const groups = useMemo(() => {
6104
6171
  const normal = /* @__PURE__ */ new Map();
@@ -6758,14 +6825,15 @@ const TICK_PX = 8;
6758
6825
  * - **Picking** goes through the stage's hit registry: a press within the pointer's tolerance of
6759
6826
  * an outline picks that region, else the smallest region containing the point. `onHoverChange`
6760
6827
  * and `onItemPress` here, and `useStageHitTest` for an app that arbitrates between layers.
6828
+ * `pickable={false}` turns it off.
6761
6829
  *
6762
6830
  * The SVG carries `data-hovered` (the hovered id).
6763
6831
  */
6764
- function AreaSet({ items, role = "feature", hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, labels = true, firstVertexTick = false, stroke, fillOpacity = FILL_OPACITY, fillRule = "nonzero", paintOrder = "appearance", selectionFill = "selection", halo = true, selectionStroke = overlayRole("selection"), layerId, priority = STAGE_HIT_PRIORITY.area, label = "Areas" }) {
6832
+ function AreaSet({ items, role = "feature", hoveredId, onHoverChange, selectedIds, dimmed, onItemPress, pickable = true, labels = true, firstVertexTick = false, stroke, fillOpacity = FILL_OPACITY, fillRule = "nonzero", paintOrder = "appearance", selectionFill = "selection", halo = true, selectionStroke = overlayRole("selection"), layerId, priority = STAGE_HIT_PRIORITY.area, label = "Areas" }) {
6765
6833
  const stage = useStage();
6766
6834
  const px = useScreenPx();
6767
6835
  const unit = px(1);
6768
- const index = useMemo(() => buildAreaIndex(items), [items]);
6836
+ const index = useMemo(() => pickable ? buildAreaIndex(items) : null, [items, pickable]);
6769
6837
  const selectedSet = useMemo(() => new Set(selectedIds ?? []), [selectedIds]);
6770
6838
  const isDimmed = useMemo(() => {
6771
6839
  if (typeof dimmed === "function") return dimmed;
@@ -6778,8 +6846,9 @@ function AreaSet({ items, role = "feature", hoveredId, onHoverChange, selectedId
6778
6846
  useStageHitLayer({
6779
6847
  layerId,
6780
6848
  priority,
6849
+ enabled: pickable,
6781
6850
  pick: (point, radius) => {
6782
- const hit = nearestArea(index, point, radius);
6851
+ const hit = index && nearestArea(index, point, radius);
6783
6852
  return hit ? {
6784
6853
  id: hit.id,
6785
6854
  dist: hit.inside ? 0 : hit.distance
@@ -6789,7 +6858,7 @@ function AreaSet({ items, role = "feature", hoveredId, onHoverChange, selectedId
6789
6858
  setOwnHover(id);
6790
6859
  onHoverChange?.(id);
6791
6860
  },
6792
- onPress: onItemPress ? (id, event) => onItemPress(id, event) : void 0
6861
+ onPress: onItemPress
6793
6862
  });
6794
6863
  const groups = useMemo(() => batchAreas(items, {
6795
6864
  role,
@@ -7273,33 +7342,13 @@ function batchPath(items, indices, floor) {
7273
7342
  return d;
7274
7343
  }
7275
7344
  /**
7276
- * The layer's entry in the stage's hit registry: a component, not a hook call in
7277
- * `EllipseSet`, so `pickable={false}` really unregisters it. Renders nothing.
7278
- */
7279
- function EllipseHits({ index, layerId, priority, onHover, onPress }) {
7280
- useStageHitLayer({
7281
- layerId,
7282
- priority,
7283
- pick: (point, radius) => {
7284
- const hit = nearestEllipse(index, point, radius);
7285
- return hit ? {
7286
- id: hit.id,
7287
- dist: hit.inside ? 0 : hit.distance
7288
- } : null;
7289
- },
7290
- onHover,
7291
- onPress: onPress ? (id, event) => onPress(id, event) : void 0
7292
- });
7293
- return null;
7294
- }
7295
- /**
7296
7345
  * A batched set of ellipses inside an `ImageStage`.
7297
7346
  *
7298
7347
  * - **Geometry** is data: `rx`, `ry` and the centre are image pixels and scale with the image;
7299
7348
  * the stroke is a screen constant.
7300
7349
  * - **States**: 1.5 screen px (1 for `model` and `structure`), hover
7301
7350
  * 2, selected 2.5 in the selection colour, dimmed at 35 % opacity. Every stroke has a halo.
7302
- * - **Batching** is by (role, dash, opacity, dimming): a thousand rings are a dozen elements.
7351
+ * - **Batching** is by (role, colour, dash, opacity, dimming): a thousand rings are a dozen elements.
7303
7352
  * - **Picking** goes through the stage's hit registry: a press within the pointer's tolerance of
7304
7353
  * an outline picks that ellipse, else the smallest ellipse containing the point.
7305
7354
  * `onHoverChange` and `onItemPress` here, and `useStageHitTest` for an app that arbitrates
@@ -7319,12 +7368,30 @@ function EllipseSet({ items, role = "feature", hoveredId, onHoverChange, selecte
7319
7368
  }, [dimmed]);
7320
7369
  const index = useMemo(() => pickable ? buildEllipseIndex(items) : null, [items, pickable]);
7321
7370
  const [ownHover, setOwnHover] = useState(null);
7322
- const hoverId = hoveredId !== void 0 ? hoveredId : pickable ? ownHover : null;
7371
+ const hoverId = hoveredId !== void 0 ? hoveredId : ownHover;
7372
+ useStageHitLayer({
7373
+ layerId,
7374
+ priority,
7375
+ enabled: pickable,
7376
+ pick: (point, radius) => {
7377
+ const hit = index && nearestEllipse(index, point, radius);
7378
+ return hit ? {
7379
+ id: hit.id,
7380
+ dist: hit.inside ? 0 : hit.distance
7381
+ } : null;
7382
+ },
7383
+ onHover: (id) => {
7384
+ setOwnHover(id);
7385
+ onHoverChange?.(id);
7386
+ },
7387
+ onPress: onItemPress
7388
+ });
7323
7389
  const batches = useMemo(() => {
7324
7390
  const normal = /* @__PURE__ */ new Map();
7325
7391
  const picked = {
7326
7392
  key: "selected",
7327
7393
  role: "selection",
7394
+ color: void 0,
7328
7395
  dashed: false,
7329
7396
  opacity: 1,
7330
7397
  dim: false,
@@ -7336,15 +7403,17 @@ function EllipseSet({ items, role = "feature", hoveredId, onHoverChange, selecte
7336
7403
  return;
7337
7404
  }
7338
7405
  const itemRole = item.role ?? role;
7406
+ const color = item.color || void 0;
7339
7407
  const dashed = item.dashed ?? false;
7340
7408
  const opacity = Math.round(Math.min(1, Math.max(0, item.opacity ?? 1)) * 10) / 10;
7341
7409
  const dim = isDimmed(item.id);
7342
- const key = `${dim ? 1 : 0}|${itemRole}|${dashed ? "dashed" : "solid"}|${opacity}`;
7410
+ const key = `${dim ? 1 : 0}|${itemRole}|${dashed ? "dashed" : "solid"}|${opacity}${color ? `|${color}` : ""}`;
7343
7411
  let batch = normal.get(key);
7344
7412
  if (!batch) {
7345
7413
  batch = {
7346
7414
  key,
7347
7415
  role: itemRole,
7416
+ color,
7348
7417
  dashed,
7349
7418
  opacity,
7350
7419
  dim,
@@ -7388,7 +7457,7 @@ function EllipseSet({ items, role = "feature", hoveredId, onHoverChange, selecte
7388
7457
  return px(OVERLAY_STATE_WIDTH[state] - (thin && state !== "selected" ? .5 : 0));
7389
7458
  };
7390
7459
  const dash = `${px(4)} ${px(3)}`;
7391
- return /* @__PURE__ */ jsxs("svg", {
7460
+ return /* @__PURE__ */ jsx("svg", {
7392
7461
  viewBox: imageViewBox(stage.image),
7393
7462
  className: "pointer-events-none absolute inset-0 h-full w-full overflow-visible",
7394
7463
  ...label !== void 0 ? {
@@ -7397,16 +7466,7 @@ function EllipseSet({ items, role = "feature", hoveredId, onHoverChange, selecte
7397
7466
  } : { "aria-hidden": true },
7398
7467
  "data-ellipses": items.length,
7399
7468
  "data-hovered": hoverId ?? void 0,
7400
- children: [index && /* @__PURE__ */ jsx(EllipseHits, {
7401
- index,
7402
- layerId,
7403
- priority,
7404
- onHover: (id) => {
7405
- setOwnHover(id);
7406
- onHoverChange?.(id);
7407
- },
7408
- onPress: onItemPress
7409
- }), /* @__PURE__ */ jsxs("g", {
7469
+ children: /* @__PURE__ */ jsxs("g", {
7410
7470
  fill: "none",
7411
7471
  strokeLinecap: "round",
7412
7472
  strokeLinejoin: "round",
@@ -7422,7 +7482,7 @@ function EllipseSet({ items, role = "feature", hoveredId, onHoverChange, selecte
7422
7482
  }), /* @__PURE__ */ jsx("path", {
7423
7483
  "data-batch": batch.key,
7424
7484
  d,
7425
- stroke: overlayRole(batch.role),
7485
+ stroke: batch.color ?? overlayRole(batch.role),
7426
7486
  strokeWidth: widthOf(batch.role, "default"),
7427
7487
  strokeDasharray: batch.dashed ? dash : void 0,
7428
7488
  opacity: batch.opacity
@@ -7449,12 +7509,12 @@ function EllipseSet({ items, role = "feature", hoveredId, onHoverChange, selecte
7449
7509
  }), /* @__PURE__ */ jsx("path", {
7450
7510
  "data-hovered-ellipse": "",
7451
7511
  d: outlineOf(item, floor),
7452
- stroke: hoverSelected ? selectionStroke : overlayRole(itemRole),
7512
+ stroke: hoverSelected ? selectionStroke : item.color || overlayRole(itemRole),
7453
7513
  strokeWidth: widthOf(itemRole, state)
7454
7514
  })] }, position);
7455
7515
  })
7456
7516
  ]
7457
- })]
7517
+ })
7458
7518
  });
7459
7519
  }
7460
7520
  //#endregion