@vitavision/stage2d 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,7 +15,7 @@ bun add @vitavision/stage2d @vitavision/ui
15
15
  child layer together (image, mask, measurement overlay, interactive handles) so they never
16
16
  drift apart, with `StageToolbar` / `StageReadout` as the in-canvas controls and `useStage()`
17
17
  as the way a layer reads the transform. The arithmetic behind it is pure and exported —
18
- `fitScale`, `fitView`, `toImage`, `toScreen`, `zoomAbout`, `clampView`, `frameRect`,
18
+ `fitScale`, `fitView` (both take `FitOptions`), `toImage`, `toScreen`, `zoomAbout`, `clampView`, `frameRect`,
19
19
  `preserveCenter`, `steppedScale`. See "The image stage" below. `ZoomPanCanvas` is its
20
20
  deprecated predecessor, still exported unchanged.
21
21
 
@@ -25,7 +25,11 @@ the stage would magnify it, then load the full image and keep it, and it turns p
25
25
  `StageLayersMenu` is a layers button for `StageToolbar`. Code outside the stage, such as an
26
26
  inspector's "frame this", drives it through `ImageStage`'s `ref` (`StageHandle`: `frame`,
27
27
  `fit`, `zoomTo`). `initialView="fit"` opens a `null` view at fit even when the image would fit
28
- at 1:1.
28
+ at 1:1. `fit={{ padding, upscale }}` gives every fit path (the initial fit, `fit()`, the `0` key, the
29
+ double-click toggle, the toolbar button, `data-fit`) a margin in CSS pixels and, with `upscale: false`, a cap
30
+ at 1:1. The transformed box carries `will-change: transform` (and `data-moving`) only while the view
31
+ moves and for 150 ms after: always on, Chromium keeps the layer at the raster scale it had when the hint
32
+ was applied and a zoomed-in image and its strokes stay blurry.
29
33
  `api/mapValues.ts` decodes the `VAM1` float32-plane wire format into indexable values
30
34
  (`decodePlane`, `valueAt`, `valuesAt`, `fractionOf`, `fetchPlane`) — it never draws;
31
35
  colour range and colormap stay the caller's decision.
@@ -58,9 +62,41 @@ selected. Labels appear where points are 24 screen px apart.
58
62
  - **Pure functions:** `buildPointIndex`, `nearestPoint`, `pointsInRect` and `thinPoints`
59
63
  (`docs/measurements/l6-2a-points-hit-test.md`).
60
64
 
65
+ **Areas**: `AreaSet` draws many closed regions (marker quads, drawn polygons, region annotations) as a
66
+ few batched paths, each an outline with its 12 % fill, in a role (`feature`, `model`, `structure`).
67
+ - **Pointer:** a press near an outline picks that region, else the smallest region containing it;
68
+ `onHoverChange` and `onItemPress` as `PointSet`.
69
+ - **Quads:** `firstVertexTick` ticks corner 0; labels sit at the centre, where regions are 24 screen px apart.
70
+ - **Pure functions:** `buildAreaIndex`, `nearestArea`, `areasInRect`, `pointInPolygon`, `areaPath`
71
+ (`docs/measurements/l6-2b-areas-grid-heatmap.md`).
72
+
73
+ **Grids**: `GridLayer` draws a detected lattice: nodes `{ id, i, j, x, y }` as a `PointSet` (`plus` by default)
74
+ and the edges between lattice neighbours as two batched paths, each axis restyled through `edges`.
75
+ `indexLabels` labels nodes with `i,j`. `latticeEdges(nodes)` is the pure neighbour search.
76
+
77
+ **Heatmaps**: `HeatmapLayer` draws a `ValuePlane` through a `colormap` (`(t) => [r, g, b]`; the
78
+ `@vitavision/charts` maps fit) or an `rgba` buffer as one image, rasterised in an effect, placed over the
79
+ image (or `rect`), pixelated from 4 CSS px per cell. `rasterizePlane` and `planeRange` are pure.
80
+
81
+ **Rotated shapes**: `ShapeEditor` edits `{ cx, cy, width, height, rotation }` as a rectangle or an ellipse:
82
+ eight handles resize in the shape's own frame (the opposite side stays put), a rotation handle turns it, the
83
+ interior moves it, arrow keys nudge it. **Rotation is radians, clockwise on screen** (Konva's degrees are
84
+ `deg * Math.PI / 180`; `shapeFromCorner` converts Konva's rotate-about-the-corner `Rect`). The arithmetic
85
+ (`resizeShape`, `rotateShape`, `moveShape`, `shapeHandlePoint`, …) is pure.
86
+
87
+ **Drawing and moving**: `DraftShape` is the dashed preview of a point, line, polyline, polygon, rectangle or
88
+ ellipse being drawn, and `MarqueeRect` the rubber band; `useShapeDrag` turns a press on an item into
89
+ image-space displacements with click slop, for select → drag → commit of manual shapes (`translatePoints`
90
+ shifts flat coordinates).
91
+
92
+ **Ellipses**: `EllipseSet` draws many ellipses whose size is data (fitted rings, edge-bit dots, drawn ellipses) as
93
+ exact arcs in a few batched paths, with the states of `AreaSet`. It is picked like `AreaSet`: a press near an
94
+ outline picks that ellipse, else the smallest containing it; `pickable={false}` leaves a decorative layer out.
95
+ - **Pure functions:** `buildEllipseIndex`, `nearestEllipse`, `ellipsesInRect`, `pointInEllipse`, `ellipseBounds`, `ellipsePath`.
96
+
61
97
  **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`,
98
+ `STAGE_HIT_PRIORITY` (points above lines above areas above images). `PointSet`, `PolylineSet`,
99
+ `AreaSet`, `EllipseSet` and `GridLayer` answer it; `useStageHitLayer` registers any other layer. `ImageStage` also takes `panButton`,
64
100
  `doubleClickFit` and `touchPan`, and handles two-finger pinch.
65
101
 
66
102
  **Tool model**: `StageSurface` is the one full-frame press target per stage.