canvu-react 0.4.63 → 0.4.64

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.
@@ -202,6 +202,101 @@ type VectorItemsChangeInfo = {
202
202
  itemIds?: readonly string[];
203
203
  toolId?: string;
204
204
  };
205
+ /**
206
+ * Interaction categories emitted by the React viewport lifecycle hooks.
207
+ *
208
+ * These describe pointer gestures owned by `VectorViewport`, not every possible
209
+ * input event. Camera pan/zoom, keyboard shortcuts, paste/drop, toolbar clicks,
210
+ * and custom UI events are intentionally outside this lifecycle.
211
+ */
212
+ type CanvuInteractionKind = "move" | "resize" | "rotate" | "marquee" | "stroke" | "erase" | "tap" | "place" | "select-mode-item-click";
213
+ /**
214
+ * World and client coordinates for a viewport interaction sample.
215
+ *
216
+ * `start` stays fixed for the accepted gesture. `current` is updated for the
217
+ * after hook so integrations can compare where the gesture began and ended.
218
+ */
219
+ type CanvuInteractionPoint = {
220
+ readonly worldX: number;
221
+ readonly worldY: number;
222
+ readonly clientX: number;
223
+ readonly clientY: number;
224
+ };
225
+ /**
226
+ * Stable interaction metadata passed to before/after interaction hooks.
227
+ *
228
+ * Use this for custom tool behavior that needs to observe or claim a viewport
229
+ * gesture before Canvu mutates selection, previews, or items. Do not use it to
230
+ * intercept item-list writes; use `wrapOnItemsChange` when you need exact
231
+ * document mutation middleware.
232
+ *
233
+ * @example
234
+ * ```tsx
235
+ * <VectorViewport
236
+ * onBeforeInteraction={(detail) =>
237
+ * detail.toolId === "review-pin" ? "handled" : undefined
238
+ * }
239
+ * />
240
+ * ```
241
+ */
242
+ type CanvuInteractionDetail = {
243
+ /** Stable id for this accepted pointer gesture. */
244
+ readonly interactionId: string;
245
+ /** Canvu interaction category resolved before built-in state changes. */
246
+ readonly kind: CanvuInteractionKind;
247
+ /** Active viewport tool when the gesture started. */
248
+ readonly toolId: string;
249
+ /** Browser pointer type such as `"mouse"`, `"pen"`, or `"touch"`. */
250
+ readonly pointerType: string;
251
+ /** Pointer button reported by the start event. Touch fallbacks use `0`. */
252
+ readonly button: number;
253
+ readonly shiftKey: boolean;
254
+ readonly altKey: boolean;
255
+ readonly metaKey: boolean;
256
+ readonly ctrlKey: boolean;
257
+ /** Pointer position when the interaction started. */
258
+ readonly start: CanvuInteractionPoint;
259
+ /** Latest pointer position known to Canvu for this interaction. */
260
+ readonly current: CanvuInteractionPoint;
261
+ /** Selection snapshot before Canvu applies this interaction. */
262
+ readonly selectedIds: readonly string[];
263
+ /** Primary target item ids when the interaction has known targets. */
264
+ readonly itemIds: readonly string[];
265
+ /** Current viewport items when the interaction was accepted. */
266
+ readonly items: readonly VectorSceneItem[];
267
+ };
268
+ /** Return value that lets a before hook claim a gesture. */
269
+ type CanvuBeforeInteractionResult = "handled" | undefined;
270
+ /**
271
+ * Runs after Canvu resolves an interaction kind and before built-in mutation.
272
+ *
273
+ * Return `"handled"` to claim the gesture. Canvu will prevent the pointer event,
274
+ * skip later before hooks, skip built-in behavior, and will not emit an after
275
+ * hook for that gesture.
276
+ */
277
+ type CanvuBeforeInteractionHook = (detail: CanvuInteractionDetail) => CanvuBeforeInteractionResult;
278
+ /** Final state reported when an accepted interaction leaves Canvu's active state. */
279
+ type CanvuInteractionOutcome = "completed" | "cancelled";
280
+ /**
281
+ * Metadata passed to after interaction hooks.
282
+ *
283
+ * `info` mirrors the best-effort `VectorItemsChangeInfo` used by
284
+ * `onItemsChange`; it is intentionally advisory and may be omitted when the
285
+ * gesture did not write items.
286
+ */
287
+ type CanvuAfterInteractionDetail = CanvuInteractionDetail & {
288
+ readonly outcome: CanvuInteractionOutcome;
289
+ readonly info?: VectorItemsChangeInfo;
290
+ };
291
+ /**
292
+ * Runs once when an accepted Canvu interaction completes or is cancelled.
293
+ *
294
+ * Use this for analytics, custom UI cleanup, or tool-specific side effects that
295
+ * should happen after Canvu's gesture lifecycle finishes. Use
296
+ * `wrapOnItemsChange` instead when you need to transform or persist item
297
+ * mutations.
298
+ */
299
+ type CanvuAfterInteractionHook = (detail: CanvuAfterInteractionDetail) => void;
205
300
  /**
206
301
  * Imperative API for pan/zoom and integrations (e.g. AI agents following a region).
207
302
  * Call {@link requestRender} after mutating the {@link Camera2D} from {@link getCamera}.
@@ -278,6 +373,24 @@ type VectorViewportProps = {
278
373
  * omit `info`.
279
374
  */
280
375
  onItemsChange?: (items: VectorSceneItem[], info?: VectorItemsChangeInfo) => void;
376
+ /**
377
+ * Runs before a Canvu-owned pointer interaction mutates viewport state.
378
+ *
379
+ * Return `"handled"` to claim the gesture and prevent Canvu's built-in
380
+ * selection, drawing, placement, or resize behavior for that pointerdown.
381
+ * Prefer this for custom tool behavior. Prefer `wrapOnItemsChange` when your
382
+ * integration needs document mutation middleware instead.
383
+ */
384
+ onBeforeInteraction?: CanvuBeforeInteractionHook;
385
+ /**
386
+ * Runs once after an accepted Canvu-owned pointer interaction completes or is
387
+ * cancelled.
388
+ *
389
+ * This is useful for analytics, custom tool cleanup, and UI side effects.
390
+ * The optional `info` payload is best-effort mutation metadata; continue to use
391
+ * `wrapOnItemsChange` for exact item-list interception.
392
+ */
393
+ onAfterInteraction?: CanvuAfterInteractionHook;
281
394
  /**
282
395
  * Fires when a link/bookmark item is activated (double-click / double-tap).
283
396
  * When omitted, the link opens in a new browser tab by default (web only).
@@ -417,6 +530,19 @@ type CanvasPluginContribution = {
417
530
  viewportProps?: Partial<Pick<VectorViewportProps, "remotePresence" | "presenceOverlay">>;
418
531
  /** Event callbacks chained into the viewport without manual wiring in app code. */
419
532
  callbacks?: Partial<Pick<VectorViewportProps, "onWorldPointerDown" | "onWorldPointerMove" | "onWorldPointerLeave" | "onPlacementPreviewChange" | "onCameraChange">>;
533
+ /**
534
+ * Hooks around Canvu-owned pointer interactions.
535
+ *
536
+ * Use these for custom tool behavior that needs to observe or claim a gesture
537
+ * before the viewport mutates state. Use `wrapOnItemsChange` for exact item
538
+ * mutation middleware.
539
+ */
540
+ interactionHooks?: {
541
+ /** Return `"handled"` to claim the gesture and skip Canvu's built-in behavior. */
542
+ onBeforeInteraction?: CanvuBeforeInteractionHook;
543
+ /** Runs once when an accepted gesture completes or is cancelled. */
544
+ onAfterInteraction?: CanvuAfterInteractionHook;
545
+ };
420
546
  /** Middleware around `onItemsChange` for collaboration, comments, persistence, etc. */
421
547
  wrapOnItemsChange?: (nextItems: VectorSceneItem[], ctx: CanvasPluginItemsChangeMiddlewareContext, info?: VectorItemsChangeInfo) => void;
422
548
  };
@@ -498,4 +624,4 @@ declare function useCanvuResolvedTools(): VectorToolDefinition[];
498
624
  */
499
625
  declare function useCanvuPluginContribution(pluginId: string, contribution: CanvasPluginContribution): void;
500
626
 
501
- export { useCanvuPluginContribution as A, type BoardComponentPosition as B, type CustomShapePlacementOptions as C, useCanvuResolvedTools as D, useCanvuViewportContext as E, type PlacementPreview as P, type SelectModeItemClickDetail as S, type VectorToolDefinition as V, type WorldPointerDownDetail as W, type CanvasPlugin as a, VectorSelectionInspector as b, type CanvasPluginComponentProps as c, type CanvasPluginContribution as d, type CanvasPluginItemsChangeMiddlewareContext as e, type CanvasPluginRenderContext as f, type CanvuChromeActiveToolStyle as g, CanvuChromeContext as h, type CanvuChromeContextValue as i, type CanvuChromeSelectionStyleChange as j, CanvuPluginContext as k, type CanvuPluginContextValue as l, type CanvuPluginViewportSnapshot as m, type SelectModeItemClickResult as n, type VectorCanvasSpacePosition as o, type VectorItemsChangeInfo as p, type VectorItemsChangeMotive as q, type VectorSelectionInspectorProps as r, VectorViewport as s, type VectorViewportHandle as t, type VectorViewportProps as u, createCanvuPlugin as v, getBoardPositionStyle as w, useCanvuChromeContext as x, useCanvuDocumentContext as y, useCanvuPluginContext as z };
627
+ export { VectorViewport as A, type BoardComponentPosition as B, type CustomShapePlacementOptions as C, type VectorViewportHandle as D, type VectorViewportProps as E, createCanvuPlugin as F, getBoardPositionStyle as G, useCanvuChromeContext as H, useCanvuDocumentContext as I, useCanvuPluginContext as J, useCanvuPluginContribution as K, useCanvuResolvedTools as L, useCanvuViewportContext as M, type PlacementPreview as P, type SelectModeItemClickDetail as S, type VectorToolDefinition as V, type WorldPointerDownDetail as W, type CanvuBeforeInteractionHook as a, type CanvuAfterInteractionHook as b, type CanvasPlugin as c, VectorSelectionInspector as d, type CanvasPluginComponentProps as e, type CanvasPluginContribution as f, type CanvasPluginItemsChangeMiddlewareContext as g, type CanvasPluginRenderContext as h, type CanvuAfterInteractionDetail as i, type CanvuBeforeInteractionResult as j, type CanvuChromeActiveToolStyle as k, CanvuChromeContext as l, type CanvuChromeContextValue as m, type CanvuChromeSelectionStyleChange as n, type CanvuInteractionDetail as o, type CanvuInteractionKind as p, type CanvuInteractionOutcome as q, type CanvuInteractionPoint as r, CanvuPluginContext as s, type CanvuPluginContextValue as t, type CanvuPluginViewportSnapshot as u, type SelectModeItemClickResult as v, type VectorCanvasSpacePosition as w, type VectorItemsChangeInfo as x, type VectorItemsChangeMotive as y, type VectorSelectionInspectorProps as z };
@@ -202,6 +202,101 @@ type VectorItemsChangeInfo = {
202
202
  itemIds?: readonly string[];
203
203
  toolId?: string;
204
204
  };
205
+ /**
206
+ * Interaction categories emitted by the React viewport lifecycle hooks.
207
+ *
208
+ * These describe pointer gestures owned by `VectorViewport`, not every possible
209
+ * input event. Camera pan/zoom, keyboard shortcuts, paste/drop, toolbar clicks,
210
+ * and custom UI events are intentionally outside this lifecycle.
211
+ */
212
+ type CanvuInteractionKind = "move" | "resize" | "rotate" | "marquee" | "stroke" | "erase" | "tap" | "place" | "select-mode-item-click";
213
+ /**
214
+ * World and client coordinates for a viewport interaction sample.
215
+ *
216
+ * `start` stays fixed for the accepted gesture. `current` is updated for the
217
+ * after hook so integrations can compare where the gesture began and ended.
218
+ */
219
+ type CanvuInteractionPoint = {
220
+ readonly worldX: number;
221
+ readonly worldY: number;
222
+ readonly clientX: number;
223
+ readonly clientY: number;
224
+ };
225
+ /**
226
+ * Stable interaction metadata passed to before/after interaction hooks.
227
+ *
228
+ * Use this for custom tool behavior that needs to observe or claim a viewport
229
+ * gesture before Canvu mutates selection, previews, or items. Do not use it to
230
+ * intercept item-list writes; use `wrapOnItemsChange` when you need exact
231
+ * document mutation middleware.
232
+ *
233
+ * @example
234
+ * ```tsx
235
+ * <VectorViewport
236
+ * onBeforeInteraction={(detail) =>
237
+ * detail.toolId === "review-pin" ? "handled" : undefined
238
+ * }
239
+ * />
240
+ * ```
241
+ */
242
+ type CanvuInteractionDetail = {
243
+ /** Stable id for this accepted pointer gesture. */
244
+ readonly interactionId: string;
245
+ /** Canvu interaction category resolved before built-in state changes. */
246
+ readonly kind: CanvuInteractionKind;
247
+ /** Active viewport tool when the gesture started. */
248
+ readonly toolId: string;
249
+ /** Browser pointer type such as `"mouse"`, `"pen"`, or `"touch"`. */
250
+ readonly pointerType: string;
251
+ /** Pointer button reported by the start event. Touch fallbacks use `0`. */
252
+ readonly button: number;
253
+ readonly shiftKey: boolean;
254
+ readonly altKey: boolean;
255
+ readonly metaKey: boolean;
256
+ readonly ctrlKey: boolean;
257
+ /** Pointer position when the interaction started. */
258
+ readonly start: CanvuInteractionPoint;
259
+ /** Latest pointer position known to Canvu for this interaction. */
260
+ readonly current: CanvuInteractionPoint;
261
+ /** Selection snapshot before Canvu applies this interaction. */
262
+ readonly selectedIds: readonly string[];
263
+ /** Primary target item ids when the interaction has known targets. */
264
+ readonly itemIds: readonly string[];
265
+ /** Current viewport items when the interaction was accepted. */
266
+ readonly items: readonly VectorSceneItem[];
267
+ };
268
+ /** Return value that lets a before hook claim a gesture. */
269
+ type CanvuBeforeInteractionResult = "handled" | undefined;
270
+ /**
271
+ * Runs after Canvu resolves an interaction kind and before built-in mutation.
272
+ *
273
+ * Return `"handled"` to claim the gesture. Canvu will prevent the pointer event,
274
+ * skip later before hooks, skip built-in behavior, and will not emit an after
275
+ * hook for that gesture.
276
+ */
277
+ type CanvuBeforeInteractionHook = (detail: CanvuInteractionDetail) => CanvuBeforeInteractionResult;
278
+ /** Final state reported when an accepted interaction leaves Canvu's active state. */
279
+ type CanvuInteractionOutcome = "completed" | "cancelled";
280
+ /**
281
+ * Metadata passed to after interaction hooks.
282
+ *
283
+ * `info` mirrors the best-effort `VectorItemsChangeInfo` used by
284
+ * `onItemsChange`; it is intentionally advisory and may be omitted when the
285
+ * gesture did not write items.
286
+ */
287
+ type CanvuAfterInteractionDetail = CanvuInteractionDetail & {
288
+ readonly outcome: CanvuInteractionOutcome;
289
+ readonly info?: VectorItemsChangeInfo;
290
+ };
291
+ /**
292
+ * Runs once when an accepted Canvu interaction completes or is cancelled.
293
+ *
294
+ * Use this for analytics, custom UI cleanup, or tool-specific side effects that
295
+ * should happen after Canvu's gesture lifecycle finishes. Use
296
+ * `wrapOnItemsChange` instead when you need to transform or persist item
297
+ * mutations.
298
+ */
299
+ type CanvuAfterInteractionHook = (detail: CanvuAfterInteractionDetail) => void;
205
300
  /**
206
301
  * Imperative API for pan/zoom and integrations (e.g. AI agents following a region).
207
302
  * Call {@link requestRender} after mutating the {@link Camera2D} from {@link getCamera}.
@@ -278,6 +373,24 @@ type VectorViewportProps = {
278
373
  * omit `info`.
279
374
  */
280
375
  onItemsChange?: (items: VectorSceneItem[], info?: VectorItemsChangeInfo) => void;
376
+ /**
377
+ * Runs before a Canvu-owned pointer interaction mutates viewport state.
378
+ *
379
+ * Return `"handled"` to claim the gesture and prevent Canvu's built-in
380
+ * selection, drawing, placement, or resize behavior for that pointerdown.
381
+ * Prefer this for custom tool behavior. Prefer `wrapOnItemsChange` when your
382
+ * integration needs document mutation middleware instead.
383
+ */
384
+ onBeforeInteraction?: CanvuBeforeInteractionHook;
385
+ /**
386
+ * Runs once after an accepted Canvu-owned pointer interaction completes or is
387
+ * cancelled.
388
+ *
389
+ * This is useful for analytics, custom tool cleanup, and UI side effects.
390
+ * The optional `info` payload is best-effort mutation metadata; continue to use
391
+ * `wrapOnItemsChange` for exact item-list interception.
392
+ */
393
+ onAfterInteraction?: CanvuAfterInteractionHook;
281
394
  /**
282
395
  * Fires when a link/bookmark item is activated (double-click / double-tap).
283
396
  * When omitted, the link opens in a new browser tab by default (web only).
@@ -417,6 +530,19 @@ type CanvasPluginContribution = {
417
530
  viewportProps?: Partial<Pick<VectorViewportProps, "remotePresence" | "presenceOverlay">>;
418
531
  /** Event callbacks chained into the viewport without manual wiring in app code. */
419
532
  callbacks?: Partial<Pick<VectorViewportProps, "onWorldPointerDown" | "onWorldPointerMove" | "onWorldPointerLeave" | "onPlacementPreviewChange" | "onCameraChange">>;
533
+ /**
534
+ * Hooks around Canvu-owned pointer interactions.
535
+ *
536
+ * Use these for custom tool behavior that needs to observe or claim a gesture
537
+ * before the viewport mutates state. Use `wrapOnItemsChange` for exact item
538
+ * mutation middleware.
539
+ */
540
+ interactionHooks?: {
541
+ /** Return `"handled"` to claim the gesture and skip Canvu's built-in behavior. */
542
+ onBeforeInteraction?: CanvuBeforeInteractionHook;
543
+ /** Runs once when an accepted gesture completes or is cancelled. */
544
+ onAfterInteraction?: CanvuAfterInteractionHook;
545
+ };
420
546
  /** Middleware around `onItemsChange` for collaboration, comments, persistence, etc. */
421
547
  wrapOnItemsChange?: (nextItems: VectorSceneItem[], ctx: CanvasPluginItemsChangeMiddlewareContext, info?: VectorItemsChangeInfo) => void;
422
548
  };
@@ -498,4 +624,4 @@ declare function useCanvuResolvedTools(): VectorToolDefinition[];
498
624
  */
499
625
  declare function useCanvuPluginContribution(pluginId: string, contribution: CanvasPluginContribution): void;
500
626
 
501
- export { useCanvuPluginContribution as A, type BoardComponentPosition as B, type CustomShapePlacementOptions as C, useCanvuResolvedTools as D, useCanvuViewportContext as E, type PlacementPreview as P, type SelectModeItemClickDetail as S, type VectorToolDefinition as V, type WorldPointerDownDetail as W, type CanvasPlugin as a, VectorSelectionInspector as b, type CanvasPluginComponentProps as c, type CanvasPluginContribution as d, type CanvasPluginItemsChangeMiddlewareContext as e, type CanvasPluginRenderContext as f, type CanvuChromeActiveToolStyle as g, CanvuChromeContext as h, type CanvuChromeContextValue as i, type CanvuChromeSelectionStyleChange as j, CanvuPluginContext as k, type CanvuPluginContextValue as l, type CanvuPluginViewportSnapshot as m, type SelectModeItemClickResult as n, type VectorCanvasSpacePosition as o, type VectorItemsChangeInfo as p, type VectorItemsChangeMotive as q, type VectorSelectionInspectorProps as r, VectorViewport as s, type VectorViewportHandle as t, type VectorViewportProps as u, createCanvuPlugin as v, getBoardPositionStyle as w, useCanvuChromeContext as x, useCanvuDocumentContext as y, useCanvuPluginContext as z };
627
+ export { VectorViewport as A, type BoardComponentPosition as B, type CustomShapePlacementOptions as C, type VectorViewportHandle as D, type VectorViewportProps as E, createCanvuPlugin as F, getBoardPositionStyle as G, useCanvuChromeContext as H, useCanvuDocumentContext as I, useCanvuPluginContext as J, useCanvuPluginContribution as K, useCanvuResolvedTools as L, useCanvuViewportContext as M, type PlacementPreview as P, type SelectModeItemClickDetail as S, type VectorToolDefinition as V, type WorldPointerDownDetail as W, type CanvuBeforeInteractionHook as a, type CanvuAfterInteractionHook as b, type CanvasPlugin as c, VectorSelectionInspector as d, type CanvasPluginComponentProps as e, type CanvasPluginContribution as f, type CanvasPluginItemsChangeMiddlewareContext as g, type CanvasPluginRenderContext as h, type CanvuAfterInteractionDetail as i, type CanvuBeforeInteractionResult as j, type CanvuChromeActiveToolStyle as k, CanvuChromeContext as l, type CanvuChromeContextValue as m, type CanvuChromeSelectionStyleChange as n, type CanvuInteractionDetail as o, type CanvuInteractionKind as p, type CanvuInteractionOutcome as q, type CanvuInteractionPoint as r, CanvuPluginContext as s, type CanvuPluginContextValue as t, type CanvuPluginViewportSnapshot as u, type SelectModeItemClickResult as v, type VectorCanvasSpacePosition as w, type VectorItemsChangeInfo as x, type VectorItemsChangeMotive as y, type VectorSelectionInspectorProps as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvu-react",
3
- "version": "0.4.63",
3
+ "version": "0.4.64",
4
4
  "description": "Vector-first infinite canvas (SVG) with pan, zoom, React bindings, and optional plugins",
5
5
  "license": "MIT",
6
6
  "type": "module",