@reekon-tools/boldr-utils 1.6.18 → 1.6.19

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.
Files changed (82) hide show
  1. package/dist/annotation/canvas/AnnotationCanvasInner.js +7 -1
  2. package/dist/annotation/canvas/AnnotationCanvasInner.native.js +58 -5
  3. package/dist/annotation/canvas/AnnotationCanvasSkia.d.ts +5 -1
  4. package/dist/annotation/canvas/AnnotationCanvasSkia.js +53 -4
  5. package/dist/annotation/canvas/Tool.d.ts +5 -2
  6. package/dist/annotation/canvas/measurementGeometry.d.ts +1 -1
  7. package/dist/annotation/canvas/measurementGeometry.js +3 -2
  8. package/dist/annotation/canvas/stampLayout.d.ts +7 -1
  9. package/dist/annotation/canvas/stampLayout.js +66 -5
  10. package/dist/annotation/canvas/tools/measurementLineTool.d.ts +12 -0
  11. package/dist/annotation/canvas/tools/measurementLineTool.js +95 -0
  12. package/dist/annotation/canvas/tools/panTool.js +1 -1
  13. package/dist/annotation/canvas/tools/selectTool.js +75 -9
  14. package/dist/annotation/canvas/useAnnotationCanvasState.d.ts +1 -0
  15. package/dist/annotation/canvas/useAnnotationCanvasState.js +9 -0
  16. package/dist/exports.d.ts +1 -0
  17. package/dist/exports.js +1 -0
  18. package/dist/types/annotation.d.ts +4 -0
  19. package/dist/types/annotation.js +6 -0
  20. package/dist/types/firestore.d.ts +53 -0
  21. package/dist/types/firestore.js +49 -0
  22. package/package.json +1 -1
  23. package/dist/canvas/AnnotationCanvas.d.ts +0 -11
  24. package/dist/canvas/AnnotationCanvas.js +0 -10
  25. package/dist/canvas/AnnotationCanvas.native.d.ts +0 -8
  26. package/dist/canvas/AnnotationCanvas.native.js +0 -6
  27. package/dist/canvas/AnnotationCanvasInner.d.ts +0 -39
  28. package/dist/canvas/AnnotationCanvasInner.js +0 -219
  29. package/dist/canvas/AnnotationCanvasInner.native.d.ts +0 -35
  30. package/dist/canvas/AnnotationCanvasInner.native.js +0 -138
  31. package/dist/canvas/AnnotationCanvasSkia.d.ts +0 -27
  32. package/dist/canvas/AnnotationCanvasSkia.js +0 -20
  33. package/dist/canvas/Tool.d.ts +0 -38
  34. package/dist/canvas/Tool.js +0 -1
  35. package/dist/canvas/elements/BackgroundImageElement.d.ts +0 -9
  36. package/dist/canvas/elements/BackgroundImageElement.js +0 -37
  37. package/dist/canvas/elements/MeasurementStampElement.d.ts +0 -13
  38. package/dist/canvas/elements/MeasurementStampElement.js +0 -30
  39. package/dist/canvas/elements/ShapeElement.d.ts +0 -7
  40. package/dist/canvas/elements/ShapeElement.js +0 -62
  41. package/dist/canvas/elements/StrokeElement.d.ts +0 -7
  42. package/dist/canvas/elements/StrokeElement.js +0 -18
  43. package/dist/canvas/measurementPicker.d.ts +0 -10
  44. package/dist/canvas/measurementPicker.js +0 -1
  45. package/dist/canvas/measurementStampOverlay.d.ts +0 -11
  46. package/dist/canvas/measurementStampOverlay.js +0 -1
  47. package/dist/canvas/pointerAdapter.d.ts +0 -3
  48. package/dist/canvas/pointerAdapter.js +0 -19
  49. package/dist/canvas/stampLayout.d.ts +0 -5
  50. package/dist/canvas/stampLayout.js +0 -14
  51. package/dist/canvas/tools/measurementStampTool.d.ts +0 -9
  52. package/dist/canvas/tools/measurementStampTool.js +0 -37
  53. package/dist/canvas/tools/panTool.d.ts +0 -5
  54. package/dist/canvas/tools/panTool.js +0 -25
  55. package/dist/canvas/tools/penTool.d.ts +0 -13
  56. package/dist/canvas/tools/penTool.js +0 -68
  57. package/dist/canvas/tools/selectTool.d.ts +0 -2
  58. package/dist/canvas/tools/selectTool.js +0 -182
  59. package/dist/canvas/useAnnotationCanvasState.d.ts +0 -54
  60. package/dist/canvas/useAnnotationCanvasState.js +0 -210
  61. package/dist/canvas/viewport.d.ts +0 -16
  62. package/dist/canvas/viewport.js +0 -54
  63. package/dist/data/AnnotationDataContext.d.ts +0 -8
  64. package/dist/data/AnnotationDataContext.js +0 -11
  65. package/dist/data/AnnotationDataProvider.d.ts +0 -65
  66. package/dist/data/AnnotationDataProvider.js +0 -4
  67. package/dist/data/InMemoryAnnotationProvider.d.ts +0 -30
  68. package/dist/data/InMemoryAnnotationProvider.js +0 -197
  69. package/dist/data/canvasPersistence.d.ts +0 -3
  70. package/dist/data/canvasPersistence.js +0 -26
  71. package/dist/data/hooks/useAnnotationCanvasDoc.d.ts +0 -33
  72. package/dist/data/hooks/useAnnotationCanvasDoc.js +0 -314
  73. package/dist/data/hooks/useAnnotationDoc.d.ts +0 -7
  74. package/dist/data/hooks/useAnnotationDoc.js +0 -33
  75. package/dist/data/hooks/useAnnotationList.d.ts +0 -7
  76. package/dist/data/hooks/useAnnotationList.js +0 -26
  77. package/dist/data/hooks/useAnnotationMutations.d.ts +0 -9
  78. package/dist/data/hooks/useAnnotationMutations.js +0 -11
  79. package/dist/hooks/useParseMeasurement.d.ts +0 -4
  80. package/dist/hooks/useParseMeasurement.js +0 -14
  81. package/dist/utils/evaluateFormula.d.ts +0 -20
  82. package/dist/utils/evaluateFormula.js +0 -31
@@ -1,18 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Path, Skia } from '@shopify/react-native-skia';
3
- import { useMemo } from 'react';
4
- export const pointsToSkPath = (points) => {
5
- const path = Skia.Path.Make();
6
- if (points.length < 2)
7
- return path;
8
- path.moveTo(points[0], points[1]);
9
- for (let i = 2; i < points.length; i += 2) {
10
- path.lineTo(points[i], points[i + 1]);
11
- }
12
- return path;
13
- };
14
- export const StrokeElement = ({ stroke }) => {
15
- const path = useMemo(() => pointsToSkPath(stroke.points), [stroke.points]);
16
- const opacity = stroke.tool === 'highlighter' ? 0.3 : 1;
17
- return (_jsx(Path, { path: path, color: stroke.color, style: "stroke", strokeWidth: stroke.width, strokeCap: "round", strokeJoin: "round", opacity: opacity }));
18
- };
@@ -1,10 +0,0 @@
1
- import type { Units } from '../types/firestore.js';
2
- export interface MeasurementRef {
3
- measurementId: string;
4
- measurementPath: string;
5
- groupId: string;
6
- label?: string;
7
- value?: number;
8
- unit?: Units;
9
- }
10
- export type PickMeasurement = () => Promise<MeasurementRef | null>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { PlacedMeasurementRef } from '../types/annotation.js';
3
- import type { Measurement } from '../types/firestore.js';
4
- export interface MeasurementStampRenderArgs {
5
- placed: PlacedMeasurementRef;
6
- measurement: Measurement | null;
7
- selected: boolean;
8
- size: number;
9
- zoom: number;
10
- }
11
- export type RenderMeasurementStamp = (args: MeasurementStampRenderArgs) => ReactNode;
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import type { CanvasPointerEvent } from './Tool.js';
2
- import type { ViewportApi } from './viewport.js';
3
- export declare const domEventToCanvasPointerEvent: (event: PointerEvent, canvas: HTMLElement, viewport: ViewportApi) => CanvasPointerEvent;
@@ -1,19 +0,0 @@
1
- // Web DOM PointerEvent → CanvasPointerEvent. The native variant will live
2
- // in pointerAdapter.native.ts and will translate gesture-handler events.
3
- export const domEventToCanvasPointerEvent = (event, canvas, viewport) => {
4
- const rect = canvas.getBoundingClientRect();
5
- const screen = {
6
- x: event.clientX - rect.left,
7
- y: event.clientY - rect.top,
8
- };
9
- return {
10
- pointerId: event.pointerId,
11
- screen,
12
- world: viewport.screenToWorld(screen),
13
- pressure: event.pressure || undefined,
14
- shiftKey: event.shiftKey,
15
- altKey: event.altKey,
16
- metaKey: event.metaKey,
17
- ctrlKey: event.ctrlKey,
18
- };
19
- };
@@ -1,5 +0,0 @@
1
- export declare const STAMP_WIDTH = 120;
2
- export declare const STAMP_HEIGHT = 44;
3
- export declare const STAMP_PADDING_X = 10;
4
- export declare const STAMP_PADDING_Y = 6;
5
- export declare const STAMP_TILE_SIZE = 120;
@@ -1,14 +0,0 @@
1
- // Shared layout constants for the placed measurement stamp. Lives in a
2
- // Skia-free module so both render (MeasurementStampElement) and hit-test
3
- // (selectTool) can import it without dragging @shopify/react-native-skia
4
- // into the consumer's static import graph.
5
- export const STAMP_WIDTH = 120;
6
- export const STAMP_HEIGHT = 44;
7
- export const STAMP_PADDING_X = 10;
8
- export const STAMP_PADDING_Y = 6;
9
- // Constant SCREEN-space edge length of a placed measurement rendered as a
10
- // square tile (the overlay path — see measurementStampOverlay.ts). The tile
11
- // is a fixed-size pin: its on-screen size is this times `placed.scale` and
12
- // does NOT change with zoom (only its position tracks the canvas). Also drives
13
- // the select-tool hit box, which converts it back to doc space via the zoom.
14
- export const STAMP_TILE_SIZE = 120;
@@ -1,9 +0,0 @@
1
- import type { PlacedMeasurementRef } from '../../types/annotation.js';
2
- import type { Tool } from '../Tool.js';
3
- export interface MeasurementStampToolOptions {
4
- autoSwitchToSelect?: boolean;
5
- onPlaced?: (ref: PlacedMeasurementRef) => void;
6
- onAutoSwitch?: (toToolId: string) => void;
7
- selectToolId?: string;
8
- }
9
- export declare const createMeasurementStampTool: (options?: MeasurementStampToolOptions) => Tool;
@@ -1,37 +0,0 @@
1
- import { DEFAULT_LAYER_ID } from '../../types/annotation.js';
2
- let counter = 0;
3
- const makeId = () => `measurement-${Date.now().toString(36)}-${(counter++).toString(36)}`;
4
- const firstLayerId = (doc) => doc.layers[0]?.id ?? DEFAULT_LAYER_ID;
5
- export const createMeasurementStampTool = (options = {}) => {
6
- const autoSwitchToSelect = options.autoSwitchToSelect ?? true;
7
- const selectToolId = options.selectToolId ?? 'select';
8
- return {
9
- id: 'measurement',
10
- label: 'Place measurement',
11
- cursor: 'copy',
12
- onPointerUp(event, ctx) {
13
- // Tap-to-place. Open the consumer's picker and commit on selection.
14
- void ctx.requestPickMeasurement().then((ref) => {
15
- if (!ref)
16
- return;
17
- const placed = {
18
- id: makeId(),
19
- layerId: firstLayerId(ctx.document),
20
- measurementPath: ref.measurementPath,
21
- measurementId: ref.measurementId,
22
- groupId: ref.groupId,
23
- anchor: event.world,
24
- labelOverride: ref.label,
25
- unitOverride: ref.unit,
26
- showLabel: true,
27
- showValue: true,
28
- createdAt: Date.now(),
29
- };
30
- ctx.commit({ ops: [{ op: 'addMeasurement', measurement: placed }] });
31
- options.onPlaced?.(placed);
32
- if (autoSwitchToSelect)
33
- options.onAutoSwitch?.(selectToolId);
34
- });
35
- },
36
- };
37
- };
@@ -1,5 +0,0 @@
1
- import type { Tool } from '../Tool.js';
2
- export interface PanToolOptions {
3
- cursor?: string;
4
- }
5
- export declare const createPanTool: (options?: PanToolOptions) => Tool;
@@ -1,25 +0,0 @@
1
- // Built-in "Hand" tool. When active, any drag pans the viewport. Tools that
2
- // want one-off pan triggers (middle-mouse, space-drag) get those via the
3
- // AnnotationCanvas `gestures` prop without needing to switch tools.
4
- export const createPanTool = (options = {}) => ({
5
- id: 'pan',
6
- label: 'Hand',
7
- cursor: options.cursor ?? 'grab',
8
- onPointerDown(event, _ctx, _state) {
9
- return { kind: 'panning', lastScreen: event.screen };
10
- },
11
- onPointerMove(event, ctx, state) {
12
- const s = state;
13
- if (s?.kind !== 'panning')
14
- return s;
15
- const delta = {
16
- x: event.screen.x - s.lastScreen.x,
17
- y: event.screen.y - s.lastScreen.y,
18
- };
19
- ctx.applyPan(delta);
20
- return { kind: 'panning', lastScreen: event.screen };
21
- },
22
- onPointerUp(_event, _ctx, _state) {
23
- // No commit — viewport state is canvas-internal, not persisted.
24
- },
25
- });
@@ -1,13 +0,0 @@
1
- import type { AnnotationStroke } from '../../types/annotation.js';
2
- import type { Tool } from '../Tool.js';
3
- export interface PenToolOptions {
4
- color?: string;
5
- width?: number;
6
- minSampleDistance?: number;
7
- variant?: 'pen' | 'marker' | 'highlighter';
8
- }
9
- export interface PenDrawingState {
10
- kind: 'pen-drawing';
11
- stroke: AnnotationStroke;
12
- }
13
- export declare const createPenTool: (options?: PenToolOptions) => Tool;
@@ -1,68 +0,0 @@
1
- import { DEFAULT_LAYER_ID } from '../../types/annotation.js';
2
- const distSq = (ax, ay, bx, by) => {
3
- const dx = ax - bx;
4
- const dy = ay - by;
5
- return dx * dx + dy * dy;
6
- };
7
- let counter = 0;
8
- const makeId = (prefix) => `${prefix}-${Date.now().toString(36)}-${(counter++).toString(36)}`;
9
- export const createPenTool = (options = {}) => {
10
- const color = options.color ?? '#111827';
11
- const width = options.width ?? 2;
12
- const variant = options.variant ?? 'pen';
13
- const minSampleDistance = options.minSampleDistance ?? 1.5;
14
- const minSampleDistanceSq = minSampleDistance * minSampleDistance;
15
- return {
16
- id: variant,
17
- label: variant === 'pen' ? 'Pen' : variant === 'marker' ? 'Marker' : 'Highlighter',
18
- cursor: 'crosshair',
19
- onPointerDown(event, ctx) {
20
- const stroke = {
21
- id: makeId('stroke'),
22
- layerId: ctx.document.layers[0]?.id ?? DEFAULT_LAYER_ID,
23
- tool: variant,
24
- color,
25
- width,
26
- points: [event.world.x, event.world.y],
27
- pressure: event.pressure !== undefined ? [event.pressure] : undefined,
28
- createdAt: Date.now(),
29
- };
30
- return { kind: 'pen-drawing', stroke };
31
- },
32
- onPointerMove(event, _ctx, state) {
33
- const s = state;
34
- if (s?.kind !== 'pen-drawing')
35
- return s;
36
- const len = s.stroke.points.length;
37
- const lastX = s.stroke.points[len - 2];
38
- const lastY = s.stroke.points[len - 1];
39
- if (distSq(lastX, lastY, event.world.x, event.world.y) < minSampleDistanceSq) {
40
- return s;
41
- }
42
- return {
43
- kind: 'pen-drawing',
44
- stroke: {
45
- ...s.stroke,
46
- points: [...s.stroke.points, event.world.x, event.world.y],
47
- pressure: s.stroke.pressure && event.pressure !== undefined
48
- ? [...s.stroke.pressure, event.pressure]
49
- : s.stroke.pressure,
50
- },
51
- };
52
- },
53
- onPointerUp(_event, ctx, state) {
54
- const s = state;
55
- if (s?.kind !== 'pen-drawing')
56
- return;
57
- // Need at least two distinct samples to be a stroke.
58
- if (s.stroke.points.length < 4)
59
- return;
60
- ctx.commit({ ops: [{ op: 'addStroke', stroke: s.stroke }] });
61
- },
62
- // No renderPreview. The canvas inner detects PenDrawingState in
63
- // toolState and renders the in-flight stroke directly with its own
64
- // (Skia-aware) StrokeElement. Keeping tools Skia-free is what lets
65
- // consumers import them statically without breaking WithSkiaWeb's
66
- // lazy-load ordering on web.
67
- };
68
- };
@@ -1,2 +0,0 @@
1
- import type { Tool } from '../Tool.js';
2
- export declare const createSelectTool: () => Tool;
@@ -1,182 +0,0 @@
1
- import { STAMP_TILE_SIZE } from '../stampLayout.js';
2
- const HIT_PADDING = 6;
3
- // Hit-test in doc-space. Crude but fast — good enough for v1; tools can
4
- // override via `hitTest` for more precision later.
5
- const hitStroke = (stroke, p) => {
6
- const r = stroke.width / 2 + HIT_PADDING;
7
- const r2 = r * r;
8
- for (let i = 0; i < stroke.points.length - 2; i += 2) {
9
- if (segmentDistanceSq(p.x, p.y, stroke.points[i], stroke.points[i + 1], stroke.points[i + 2], stroke.points[i + 3]) <= r2) {
10
- return true;
11
- }
12
- }
13
- return false;
14
- };
15
- const hitMeasurement = (m, p, zoom = 1) => {
16
- // The stamp renders as a constant *screen*-size square centered on the
17
- // anchor, so its doc-space footprint shrinks as you zoom in. Convert the
18
- // screen-space half-extent (+ padding) back to doc space via the zoom so
19
- // the hit box always matches what's drawn.
20
- const scale = m.scale ?? 1;
21
- const half = ((STAMP_TILE_SIZE * scale) / 2 + HIT_PADDING) / zoom;
22
- const dx = Math.abs(p.x - m.anchor.x);
23
- const dy = Math.abs(p.y - m.anchor.y);
24
- return dx <= half && dy <= half;
25
- };
26
- const segmentDistanceSq = (px, py, ax, ay, bx, by) => {
27
- const abx = bx - ax;
28
- const aby = by - ay;
29
- const lenSq = abx * abx + aby * aby;
30
- let t = lenSq === 0 ? 0 : ((px - ax) * abx + (py - ay) * aby) / lenSq;
31
- t = Math.max(0, Math.min(1, t));
32
- const cx = ax + t * abx;
33
- const cy = ay + t * aby;
34
- const dx = px - cx;
35
- const dy = py - cy;
36
- return dx * dx + dy * dy;
37
- };
38
- const findHit = (doc, world, zoom) => {
39
- // Hit-test in z-order (top first): measurements > shapes > strokes.
40
- for (let i = doc.placedMeasurements.length - 1; i >= 0; i--) {
41
- const m = doc.placedMeasurements[i];
42
- if (hitMeasurement(m, world, zoom))
43
- return { id: m.id, kind: 'measurement' };
44
- }
45
- for (let i = doc.shapes.length - 1; i >= 0; i--) {
46
- // Default shape hit test: bounding box of the shape's points + padding.
47
- const s = doc.shapes[i];
48
- const pts = s.geometry.points;
49
- if (pts.length === 0)
50
- continue;
51
- let minX = pts[0].x;
52
- let maxX = pts[0].x;
53
- let minY = pts[0].y;
54
- let maxY = pts[0].y;
55
- for (let j = 1; j < pts.length; j++) {
56
- const p = pts[j];
57
- if (p.x < minX)
58
- minX = p.x;
59
- if (p.x > maxX)
60
- maxX = p.x;
61
- if (p.y < minY)
62
- minY = p.y;
63
- if (p.y > maxY)
64
- maxY = p.y;
65
- }
66
- if (world.x >= minX - HIT_PADDING &&
67
- world.x <= maxX + HIT_PADDING &&
68
- world.y >= minY - HIT_PADDING &&
69
- world.y <= maxY + HIT_PADDING) {
70
- return { id: s.id, kind: 'shape' };
71
- }
72
- }
73
- for (let i = doc.strokes.length - 1; i >= 0; i--) {
74
- const s = doc.strokes[i];
75
- if (hitStroke(s, world))
76
- return { id: s.id, kind: 'stroke' };
77
- }
78
- return null;
79
- };
80
- const translatePatch = (elementKind, id, doc, delta) => {
81
- if (elementKind === 'measurement') {
82
- const m = doc.placedMeasurements.find((x) => x.id === id);
83
- if (!m)
84
- return null;
85
- return {
86
- op: 'updateMeasurement',
87
- id,
88
- patch: {
89
- anchor: { x: m.anchor.x + delta.x, y: m.anchor.y + delta.y },
90
- leader: m.leader
91
- ? {
92
- from: {
93
- x: m.leader.from.x + delta.x,
94
- y: m.leader.from.y + delta.y,
95
- },
96
- to: {
97
- x: m.leader.to.x + delta.x,
98
- y: m.leader.to.y + delta.y,
99
- },
100
- }
101
- : undefined,
102
- },
103
- };
104
- }
105
- if (elementKind === 'shape') {
106
- const s = doc.shapes.find((x) => x.id === id);
107
- if (!s)
108
- return null;
109
- return {
110
- op: 'updateShape',
111
- id,
112
- patch: {
113
- geometry: {
114
- ...s.geometry,
115
- points: s.geometry.points.map((p) => ({
116
- x: p.x + delta.x,
117
- y: p.y + delta.y,
118
- })),
119
- },
120
- },
121
- };
122
- }
123
- const stroke = doc.strokes.find((x) => x.id === id);
124
- if (!stroke)
125
- return null;
126
- const points = stroke.points.slice();
127
- for (let i = 0; i < points.length; i += 2) {
128
- points[i] = points[i] + delta.x;
129
- points[i + 1] = points[i + 1] + delta.y;
130
- }
131
- return { op: 'updateStroke', id, patch: { points } };
132
- };
133
- export const createSelectTool = () => ({
134
- id: 'select',
135
- label: 'Select',
136
- cursor: 'default',
137
- onPointerDown(event, ctx) {
138
- const hit = findHit(ctx.document, event.world, ctx.viewport.state.zoom);
139
- if (!hit) {
140
- ctx.setSelection(null);
141
- return { kind: 'idle' };
142
- }
143
- ctx.setSelection({ ids: [hit.id] });
144
- return {
145
- kind: 'dragging',
146
- id: hit.id,
147
- elementKind: hit.kind,
148
- start: event.world,
149
- delta: { x: 0, y: 0 },
150
- };
151
- },
152
- onPointerMove(event, ctx, state) {
153
- const s = state;
154
- if (s?.kind !== 'dragging')
155
- return s;
156
- const delta = { x: event.world.x - s.start.x, y: event.world.y - s.start.y };
157
- const op = translatePatch(s.elementKind, s.id, ctx.document, delta);
158
- if (op)
159
- ctx.preview({ ops: [op] });
160
- return { ...s, delta };
161
- },
162
- onPointerUp(_event, ctx, state) {
163
- const s = state;
164
- if (s?.kind !== 'dragging')
165
- return;
166
- if (s.delta.x === 0 && s.delta.y === 0)
167
- return;
168
- const op = translatePatch(s.elementKind, s.id, ctx.document, s.delta);
169
- if (op)
170
- ctx.commit({ ops: [op] });
171
- },
172
- onCancel(_state, ctx) {
173
- ctx.preview({ ops: [] });
174
- },
175
- hitTest(element, p) {
176
- if (element.kind === 'measurement')
177
- return hitMeasurement(element, p);
178
- if (element.kind === 'stroke')
179
- return hitStroke(element, p);
180
- return false;
181
- },
182
- });
@@ -1,54 +0,0 @@
1
- import type { Measurement } from '../types/firestore.js';
2
- import { type AnnotationCanvasState, type AnnotationDocumentPatch, type AnnotationStroke, type Selection, type Vec2 } from '../types/annotation.js';
3
- import type { MeasurementRef } from './measurementPicker.js';
4
- import type { CanvasPointerEvent, Tool, ToolContext, ToolState } from './Tool.js';
5
- import { type ViewportState } from './viewport.js';
6
- export interface AnnotationCanvasHandle {
7
- undo(): void;
8
- redo(): void;
9
- canUndo(): boolean;
10
- canRedo(): boolean;
11
- zoomToFit(): void;
12
- resetView(): void;
13
- placeMeasurementAtCenter(ref: MeasurementRef): void;
14
- }
15
- export interface UseAnnotationCanvasStateProps {
16
- canvas: AnnotationCanvasState;
17
- onCommit(patch: AnnotationDocumentPatch): void;
18
- tools: Tool[];
19
- activeToolId: string;
20
- selection: Selection | null;
21
- onSelectionChange(selection: Selection | null): void;
22
- measurements?: Measurement[];
23
- pickMeasurement?: () => Promise<MeasurementRef | null>;
24
- width: number;
25
- height: number;
26
- initialViewport?: ViewportState;
27
- imperativeRef?: {
28
- current: AnnotationCanvasHandle | null;
29
- };
30
- }
31
- export interface AnnotationCanvasStateApi {
32
- effectiveCanvas: AnnotationCanvasState;
33
- worldTransform: Array<{
34
- scale: number;
35
- } | {
36
- translateX: number;
37
- } | {
38
- translateY: number;
39
- }>;
40
- viewport: ViewportState;
41
- measurementsById: Map<string, Measurement>;
42
- activeTool: Tool | null;
43
- toolState: ToolState;
44
- ctx: ToolContext;
45
- penDrawingStroke: AnnotationStroke | null;
46
- customPreviewState: ToolState;
47
- dispatchPointerDown(event: CanvasPointerEvent): void;
48
- dispatchPointerMove(event: CanvasPointerEvent): void;
49
- dispatchPointerUp(event: CanvasPointerEvent): void;
50
- dispatchPointerCancel(): void;
51
- pan(deltaScreen: Vec2): void;
52
- zoom(focalScreen: Vec2, nextZoom: number): void;
53
- }
54
- export declare const useAnnotationCanvasState: (props: UseAnnotationCanvasStateProps) => AnnotationCanvasStateApi;