@pluot/react 0.1.16 → 0.1.17
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 +994 -100
- package/dist-tsc/BrushOverlay.d.ts +31 -0
- package/dist-tsc/BrushOverlay.d.ts.map +1 -0
- package/dist-tsc/BrushOverlay.js +91 -0
- package/dist-tsc/Pluot.d.ts +2 -1
- package/dist-tsc/Pluot.d.ts.map +1 -1
- package/dist-tsc/Pluot.js +59 -22
- package/dist-tsc/Tooltip.d.ts +2 -1
- package/dist-tsc/Tooltip.d.ts.map +1 -1
- package/dist-tsc/Tooltip.js +15 -1
- package/dist-tsc/brush.d.ts +155 -0
- package/dist-tsc/brush.d.ts.map +1 -0
- package/dist-tsc/brush.js +312 -0
- package/dist-tsc/brush.test.d.ts +2 -0
- package/dist-tsc/brush.test.d.ts.map +1 -0
- package/dist-tsc/brush.test.js +487 -0
- package/dist-tsc/index.d.ts +3 -1
- package/dist-tsc/index.d.ts.map +1 -1
- package/dist-tsc/index.js +1 -0
- package/dist-tsc/types.d.ts +255 -0
- package/dist-tsc/types.d.ts.map +1 -0
- package/dist-tsc/types.js +11 -0
- package/dist-tsc/use-brush.d.ts +53 -0
- package/dist-tsc/use-brush.d.ts.map +1 -0
- package/dist-tsc/use-brush.js +360 -0
- package/package.json +5 -3
- package/src/BrushOverlay.tsx +254 -0
- package/src/{Pluot.jsx → Pluot.tsx} +132 -46
- package/src/{Tooltip.jsx → Tooltip.tsx} +19 -3
- package/src/brush.test.ts +590 -0
- package/src/brush.ts +435 -0
- package/src/index.ts +24 -0
- package/src/types.ts +378 -0
- package/src/use-brush.ts +501 -0
- package/src/index.js +0 -2
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { AspectRatioMode, AspectRatioAlignmentMode, CameraMatrix, StoreInput, StoresInput, StoresOutput } from "@pluot/core";
|
|
3
|
+
/** Mirrors the Rust `ViewMode` enum (serde-renamed to lowercase). */
|
|
4
|
+
export type ViewMode = "2d" | "3d";
|
|
5
|
+
/** Mirrors the Rust `GraphicsFormat` enum. */
|
|
6
|
+
export type GraphicsFormat = "Raster" | "Vector";
|
|
7
|
+
/** Mirrors the adjacently-tagged Rust `PlotParams` enum discriminant. */
|
|
8
|
+
export type PlotType = "LayeredPlot";
|
|
9
|
+
/**
|
|
10
|
+
* One entry of `PlotParams.layers`, mirroring the adjacently-tagged Rust
|
|
11
|
+
* `LayerParams` enum: `{ "layer_type": "PointLayer", "layer_params": { ... } }`.
|
|
12
|
+
*
|
|
13
|
+
* `layer_type` must name a registered layer (see the `LayerParams` enum in
|
|
14
|
+
* `crates/pluot/src/render_params.rs`), and the shape of `layer_params`
|
|
15
|
+
* depends on which layer was named.
|
|
16
|
+
*/
|
|
17
|
+
export type LayerParams = {
|
|
18
|
+
layer_type: string;
|
|
19
|
+
layer_params: Record<string, unknown>;
|
|
20
|
+
};
|
|
21
|
+
/** Mirrors the Rust `LayeredPlotRenderParams` struct. */
|
|
22
|
+
export type PlotParams = {
|
|
23
|
+
layers: LayerParams[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The object handed to the wasm `render_wasm` / `pick_wasm` functions.
|
|
27
|
+
* Mirrors the Rust `RenderParams` struct (snake_case, unlike the props of
|
|
28
|
+
* the {@link PluotProps} React API).
|
|
29
|
+
*/
|
|
30
|
+
export type RenderParams = {
|
|
31
|
+
schema_version: string | null;
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
format: GraphicsFormat;
|
|
35
|
+
margin_top: number;
|
|
36
|
+
margin_right: number;
|
|
37
|
+
margin_bottom: number;
|
|
38
|
+
margin_left: number;
|
|
39
|
+
device_pixel_ratio: number;
|
|
40
|
+
aspect_ratio_mode: AspectRatioMode;
|
|
41
|
+
aspect_ratio_alignment_mode: AspectRatioAlignmentMode;
|
|
42
|
+
view_mode: ViewMode;
|
|
43
|
+
pickable: boolean;
|
|
44
|
+
camera_view: CameraMatrix | null;
|
|
45
|
+
plot_id: string;
|
|
46
|
+
plot_type: PlotType;
|
|
47
|
+
stores: StoresOutput | undefined;
|
|
48
|
+
plot_params: PlotParams;
|
|
49
|
+
/** In milliseconds. Has no effect when `wait_for_store_gets` is false. */
|
|
50
|
+
timeout: number | null;
|
|
51
|
+
wait_for_store_gets: boolean;
|
|
52
|
+
cache_enabled: boolean;
|
|
53
|
+
svg_compression_enabled: boolean;
|
|
54
|
+
svg_include_document: boolean;
|
|
55
|
+
};
|
|
56
|
+
/** Mirrors the Rust `ScreenCoord` struct. Y increases upwards. */
|
|
57
|
+
export type ScreenCoord = {
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
};
|
|
61
|
+
/** Mirrors the externally-tagged Rust `DataCoord` enum. */
|
|
62
|
+
export type DataCoord = {
|
|
63
|
+
TwoD: {
|
|
64
|
+
x: number;
|
|
65
|
+
y: number;
|
|
66
|
+
};
|
|
67
|
+
} | {
|
|
68
|
+
ThreeD: {
|
|
69
|
+
x: number;
|
|
70
|
+
y: number;
|
|
71
|
+
z: number;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
/** Mirrors the Rust `LayerPickingResult` struct. */
|
|
75
|
+
export type LayerPickingResult = {
|
|
76
|
+
layer_id: string;
|
|
77
|
+
info: Record<string, string>;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Mirrors the Rust `PickingResult` struct, after normalization
|
|
81
|
+
* of the `info` Maps (produced by serde-wasm-bindgen) to plain objects.
|
|
82
|
+
*
|
|
83
|
+
* Note: `serde_wasm_bindgen` serializes a Rust `None` as `undefined`
|
|
84
|
+
* (not `null`), so `data_coord` is absent rather than null when picking
|
|
85
|
+
* did not resolve to a data coordinate.
|
|
86
|
+
*/
|
|
87
|
+
export type PickingResult = {
|
|
88
|
+
data_coord: DataCoord | undefined;
|
|
89
|
+
screen_coord: ScreenCoord;
|
|
90
|
+
layer_results: LayerPickingResult[];
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The un-normalized shape that `pick_wasm` actually resolves to. It is typed
|
|
94
|
+
* `any` on the wasm-bindgen side, so this type is what documents the wire
|
|
95
|
+
* format: `serde_wasm_bindgen` converts the Rust `HashMap` behind `info` into
|
|
96
|
+
* a JS `Map`, which {@link PickingResult} flattens to a plain object.
|
|
97
|
+
*/
|
|
98
|
+
export type RawLayerPickingResult = Omit<LayerPickingResult, "info"> & {
|
|
99
|
+
info: Map<string, string>;
|
|
100
|
+
};
|
|
101
|
+
export type RawPickingResult = Omit<PickingResult, "layer_results"> & {
|
|
102
|
+
layer_results: RawLayerPickingResult[];
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* What a {@link PluotProps.onHover} callback may return for the tooltip to
|
|
106
|
+
* render. A plain object is rendered as a key/value table when `asTable`
|
|
107
|
+
* is set, and as pretty-printed JSON otherwise.
|
|
108
|
+
*/
|
|
109
|
+
export type TooltipContent = string | number | ReactElement | Record<string, unknown> | null | undefined;
|
|
110
|
+
export type TooltipProps = {
|
|
111
|
+
content: TooltipContent;
|
|
112
|
+
/** Render a plain-object `content` as a two-column key/value table. */
|
|
113
|
+
asTable?: boolean;
|
|
114
|
+
};
|
|
115
|
+
/** The hovered point plus the tooltip content to show for it. */
|
|
116
|
+
export type HoverInfo = {
|
|
117
|
+
content: TooltipContent;
|
|
118
|
+
/** Mouse position in the coordinate space of the outer (width x height) container. */
|
|
119
|
+
mouseX: number;
|
|
120
|
+
mouseY: number;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Which representation of a {@link BrushVertex} is authoritative for an axis.
|
|
124
|
+
*
|
|
125
|
+
* - `Pixels`: relative to the top-left of the outer (width x height) container,
|
|
126
|
+
* with Y increasing downwards (the DOM/SVG convention). Unaffected by the camera.
|
|
127
|
+
* - `Data`: the data coordinate under the current camera, as reported by
|
|
128
|
+
* `getBounds`, with Y increasing upwards. A brush in this mode is pinned to the
|
|
129
|
+
* data, so it moves on screen as the user zooms/pans.
|
|
130
|
+
* - `Normalized`: a 0-to-1 fraction of the brushable region, with Y increasing
|
|
131
|
+
* upwards (0 at the bottom edge, 1 at the top edge). Unaffected by the camera.
|
|
132
|
+
*/
|
|
133
|
+
export type BrushUnitsMode = "Pixels" | "Data" | "Normalized";
|
|
134
|
+
export type BrushVertex = {
|
|
135
|
+
x_data: number;
|
|
136
|
+
y_data: number;
|
|
137
|
+
x_pixels: number;
|
|
138
|
+
y_pixels: number;
|
|
139
|
+
x_normalized: number;
|
|
140
|
+
y_normalized: number;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* The shape the user draws, and which the resulting {@link BrushState} holds.
|
|
144
|
+
*
|
|
145
|
+
* - `Rect`: click and drag to draw a rectangle.
|
|
146
|
+
* - `Polygon`: click and drag to draw a lasso, defining vertices as the user
|
|
147
|
+
* drags. The number of vertices is limited by using lodash-es throttle.
|
|
148
|
+
* - `RangeX`: select a horizontal range. The overlay renders as a rectangle
|
|
149
|
+
* which takes up the full brush height, according to the brush margins.
|
|
150
|
+
* - `RangeY`: select a vertical range. The overlay renders as a rectangle
|
|
151
|
+
* which takes up the full brush width, according to the brush margins.
|
|
152
|
+
*/
|
|
153
|
+
export type BrushMode = 'Rect' | 'Polygon' | 'RangeX' | 'RangeY';
|
|
154
|
+
/** The axis-aligned modes, all of which are stored as four rectangle corners. */
|
|
155
|
+
export type RectLikeBrushMode = Exclude<BrushMode, 'Polygon'>;
|
|
156
|
+
export type BrushState = {
|
|
157
|
+
status: 'Drawing' | 'Complete';
|
|
158
|
+
shape: BrushMode;
|
|
159
|
+
vertices: BrushVertex[];
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* The value of {@link PluotProps.brush} meaning "controlled, but nothing is
|
|
163
|
+
* brushed right now".
|
|
164
|
+
*
|
|
165
|
+
* `undefined` cannot play this role: a prop that was never passed is
|
|
166
|
+
* indistinguishable from one explicitly set to `undefined`, and an absent
|
|
167
|
+
* `brush` has to mean uncontrolled. A parent that controls the brush therefore
|
|
168
|
+
* passes `NO_BRUSH` rather than `undefined` to show no brush, which keeps it
|
|
169
|
+
* controlled across the empty state instead of silently handing control back.
|
|
170
|
+
*/
|
|
171
|
+
export declare const NO_BRUSH = "NoBrush";
|
|
172
|
+
export type NoBrush = typeof NO_BRUSH;
|
|
173
|
+
export type BrushResult = {};
|
|
174
|
+
export type PluotProps = {
|
|
175
|
+
/**
|
|
176
|
+
* The schema version used to generate the plot, for forward compatibility.
|
|
177
|
+
* A mismatch with the Rust crate version logs a warning.
|
|
178
|
+
*/
|
|
179
|
+
schemaVersion?: string | null;
|
|
180
|
+
/** Width of the plot, in pixels. */
|
|
181
|
+
width: number;
|
|
182
|
+
/** Height of the plot, in pixels. */
|
|
183
|
+
height: number;
|
|
184
|
+
/**
|
|
185
|
+
* Unique-per-page plot ID, used to key caches of intermediate values.
|
|
186
|
+
* Also the default store name when `store` is used without `storeName`.
|
|
187
|
+
*/
|
|
188
|
+
plotId: string;
|
|
189
|
+
plotType: PlotType;
|
|
190
|
+
plotParams: PlotParams;
|
|
191
|
+
/**
|
|
192
|
+
* A single Zarr store: a URL string, a zarrita store instance,
|
|
193
|
+
* or already-derived `ZarrStoreInfo` metadata.
|
|
194
|
+
* Mutually exclusive with `stores`.
|
|
195
|
+
*/
|
|
196
|
+
store?: StoreInput;
|
|
197
|
+
/** The name to register `store` under. Defaults to `plotId`. */
|
|
198
|
+
storeName?: string;
|
|
199
|
+
/** Multiple Zarr stores, keyed by store name. Mutually exclusive with `store`. */
|
|
200
|
+
stores?: StoresInput;
|
|
201
|
+
/**
|
|
202
|
+
* Whether to register the store(s) with the wasm module.
|
|
203
|
+
* Set to false when they have already been registered elsewhere.
|
|
204
|
+
*/
|
|
205
|
+
registerStores?: boolean;
|
|
206
|
+
viewMode?: ViewMode;
|
|
207
|
+
format?: GraphicsFormat;
|
|
208
|
+
marginTop?: number;
|
|
209
|
+
marginRight?: number;
|
|
210
|
+
marginBottom?: number;
|
|
211
|
+
marginLeft?: number;
|
|
212
|
+
aspectRatioMode?: AspectRatioMode;
|
|
213
|
+
aspectRatioAlignmentMode?: AspectRatioAlignmentMode;
|
|
214
|
+
/** Outline the margin box and the plot area, to help debug layout. */
|
|
215
|
+
debugMargins?: boolean;
|
|
216
|
+
backgroundColor?: string;
|
|
217
|
+
/** Lower bound (in ms) of the exponential backoff between bailed-early renders. */
|
|
218
|
+
minTimeout?: number;
|
|
219
|
+
/** Upper bound (in ms) of the exponential backoff between bailed-early renders. */
|
|
220
|
+
maxTimeout?: number;
|
|
221
|
+
/** Whether a new render may start while a previous one is still in flight. */
|
|
222
|
+
allowSimultaneousRenders?: boolean;
|
|
223
|
+
/**
|
|
224
|
+
* The 4x4 camera matrix. Without `setCameraMatrix`, this is treated as the
|
|
225
|
+
* initial value only, and the camera is managed internally.
|
|
226
|
+
*/
|
|
227
|
+
cameraMatrix?: CameraMatrix | null;
|
|
228
|
+
/** Provide to take control of the camera matrix. */
|
|
229
|
+
setCameraMatrix?: ((cameraMatrix: CameraMatrix) => void) | null;
|
|
230
|
+
/** Whether clicking should run a picking query and call `onClick`. */
|
|
231
|
+
enableClick?: boolean;
|
|
232
|
+
/** Whether hovering should run a picking query and show a tooltip via `onHover`. */
|
|
233
|
+
enableTooltip?: boolean;
|
|
234
|
+
onClick?: ((result: PickingResult) => void) | null;
|
|
235
|
+
onHover?: ((result: PickingResult) => TooltipContent) | null;
|
|
236
|
+
brushUnitsModeX?: BrushUnitsMode;
|
|
237
|
+
brushUnitsModeY?: BrushUnitsMode;
|
|
238
|
+
brushMarginTop?: number;
|
|
239
|
+
brushMarginBottom?: number;
|
|
240
|
+
brushMarginLeft?: number;
|
|
241
|
+
brushMarginRight?: number;
|
|
242
|
+
enableBrushCreate?: boolean;
|
|
243
|
+
enableBrushEdit?: boolean;
|
|
244
|
+
enableBrushClear?: boolean;
|
|
245
|
+
brushDelay?: number;
|
|
246
|
+
maybeBrushDelay?: number;
|
|
247
|
+
persistBrush?: boolean;
|
|
248
|
+
brushMode?: BrushMode;
|
|
249
|
+
brushColor?: string;
|
|
250
|
+
brush?: BrushState | NoBrush | null;
|
|
251
|
+
onBrush?: (state: BrushState, snappedState: BrushState) => BrushResult;
|
|
252
|
+
onBrushEnd?: (state: BrushState, snappedState: BrushState) => BrushResult;
|
|
253
|
+
onBrushClear?: (state: BrushState) => void;
|
|
254
|
+
};
|
|
255
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EACV,eAAe,EACf,wBAAwB,EACxB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,YAAY,EACb,MAAM,aAAa,CAAC;AAOrB,qEAAqE;AACrE,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC;AAEnC,8CAA8C;AAC9C,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEjD,yEAAyE;AACzE,MAAM,MAAM,QAAQ,GAAG,aAAa,CAAC;AAErC;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC,CAAC;AAEF,yDAAyD;AACzD,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,cAAc,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,C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,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,KAAK,WAAW,CAAC;IAEvE,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,KAAK,WAAW,CAAC;IAG1E,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;CAE5C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The value of {@link PluotProps.brush} meaning "controlled, but nothing is
|
|
3
|
+
* brushed right now".
|
|
4
|
+
*
|
|
5
|
+
* `undefined` cannot play this role: a prop that was never passed is
|
|
6
|
+
* indistinguishable from one explicitly set to `undefined`, and an absent
|
|
7
|
+
* `brush` has to mean uncontrolled. A parent that controls the brush therefore
|
|
8
|
+
* passes `NO_BRUSH` rather than `undefined` to show no brush, which keeps it
|
|
9
|
+
* controlled across the empty state instead of silently handing control back.
|
|
10
|
+
*/
|
|
11
|
+
export const NO_BRUSH = "NoBrush";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import type { AspectRatioMode, AspectRatioAlignmentMode, CameraMatrix } from "@pluot/core";
|
|
3
|
+
import { type BrushEdge, type BrushGeometry } from "./brush.js";
|
|
4
|
+
import type { BrushState, PluotProps } from "./types.js";
|
|
5
|
+
/** Radius (in pixels) of the hover target around the clear button. */
|
|
6
|
+
export declare const CLEAR_BUTTON_RADIUS_PX = 9;
|
|
7
|
+
/** What the overlay needs to draw the long-click progress indicator. */
|
|
8
|
+
export type BrushPressProgress = {
|
|
9
|
+
xPixels: number;
|
|
10
|
+
yPixels: number;
|
|
11
|
+
/** 0 to 1, reaching 1 exactly when `brushDelay` elapses. */
|
|
12
|
+
fraction: number;
|
|
13
|
+
};
|
|
14
|
+
export type UseBrushParams = Pick<PluotProps, "brushUnitsModeX" | "brushUnitsModeY" | "brushMarginTop" | "brushMarginRight" | "brushMarginBottom" | "brushMarginLeft" | "enableBrushCreate" | "enableBrushEdit" | "enableBrushClear" | "brushDelay" | "maybeBrushDelay" | "persistBrush" | "brushMode" | "brush" | "onBrush" | "onBrushEnd" | "onBrushClear"> & {
|
|
15
|
+
containerRef: RefObject<HTMLDivElement | null>;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
marginTop: number;
|
|
19
|
+
marginRight: number;
|
|
20
|
+
marginBottom: number;
|
|
21
|
+
marginLeft: number;
|
|
22
|
+
aspectRatioMode: AspectRatioMode;
|
|
23
|
+
aspectRatioAlignmentMode: AspectRatioAlignmentMode;
|
|
24
|
+
cameraMatrix: CameraMatrix;
|
|
25
|
+
};
|
|
26
|
+
export type UseBrushResult = {
|
|
27
|
+
/** The brush to draw, already reprojected into the current geometry. */
|
|
28
|
+
brushState: BrushState | undefined;
|
|
29
|
+
geometry: BrushGeometry;
|
|
30
|
+
/** Must be attached to the overlay SVG, so its handles are excluded from brush creation. */
|
|
31
|
+
overlayRef: RefObject<SVGSVGElement | null>;
|
|
32
|
+
pressProgress: BrushPressProgress | null;
|
|
33
|
+
/** Whether the clear button should be shown (hovering the brush, `enableBrushClear`). */
|
|
34
|
+
isBrushHovered: boolean;
|
|
35
|
+
/** True while a create/edit drag is in flight, so the camera can stand down. */
|
|
36
|
+
isBrushingRef: RefObject<boolean>;
|
|
37
|
+
/** Set when a brush drag just ended, so the ensuing `click` does not also pick. */
|
|
38
|
+
shouldSuppressClickRef: RefObject<boolean>;
|
|
39
|
+
onVertexMouseDown: (vertexIndex: number, event: React.MouseEvent) => void;
|
|
40
|
+
onEdgeMouseDown: (edge: BrushEdge, event: React.MouseEvent) => void;
|
|
41
|
+
onClearClick: (event: React.MouseEvent) => void;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Implements the brush interactions: long-click to create a rect/lasso, drag a
|
|
45
|
+
* vertex to edit, and click the clear button to cancel.
|
|
46
|
+
*
|
|
47
|
+
* Brushing is controlled when `brush` is a `BrushState` or `undefined`, and
|
|
48
|
+
* uncontrolled when `brush` is `null` (mirroring `cameraMatrix`/`setCameraMatrix`).
|
|
49
|
+
* When controlled, nothing is stored here: updates are emitted via `onBrush`/
|
|
50
|
+
* `onBrushEnd` and the parent is expected to feed them back through `brush`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function useBrush(params: UseBrushParams): UseBrushResult;
|
|
53
|
+
//# sourceMappingURL=use-brush.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-brush.d.ts","sourceRoot":"","sources":["../src/use-brush.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE1G,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,EAWL,KAAK,SAAS,EACd,KAAK,aAAa,EACnB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,UAAU,EAAe,UAAU,EAAE,MAAM,YAAY,CAAC;AAQtE,sEAAsE;AACtE,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,wEAAwE;AACxE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,EACxC,iBAAiB,GAAG,iBAAiB,GACrC,gBAAgB,GAAG,kBAAkB,GAAG,mBAAmB,GAAG,iBAAiB,GAC/E,mBAAmB,GAAG,iBAAiB,GAAG,kBAAkB,GAC5D,YAAY,GAAG,iBAAiB,GAAG,cAAc,GAAG,WAAW,GAC/D,OAAO,GAAG,SAAS,GAAG,YAAY,GAAG,cAAc,CACtD,GAAG;IACF,YAAY,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CA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