@reekon-tools/boldr-utils 1.6.4 → 1.6.6

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 (67) hide show
  1. package/dist/canvas/AnnotationCanvas.d.ts +11 -0
  2. package/dist/canvas/AnnotationCanvas.js +10 -0
  3. package/dist/canvas/AnnotationCanvas.native.d.ts +8 -0
  4. package/dist/canvas/AnnotationCanvas.native.js +6 -0
  5. package/dist/canvas/AnnotationCanvasInner.d.ts +37 -0
  6. package/dist/canvas/AnnotationCanvasInner.js +179 -0
  7. package/dist/canvas/AnnotationCanvasInner.native.d.ts +33 -0
  8. package/dist/canvas/AnnotationCanvasInner.native.js +102 -0
  9. package/dist/canvas/AnnotationCanvasSkia.d.ts +26 -0
  10. package/dist/canvas/AnnotationCanvasSkia.js +19 -0
  11. package/dist/canvas/Tool.d.ts +38 -0
  12. package/dist/canvas/Tool.js +1 -0
  13. package/dist/canvas/elements/BackgroundImageElement.d.ts +9 -0
  14. package/dist/canvas/elements/BackgroundImageElement.js +37 -0
  15. package/dist/canvas/elements/MeasurementStampElement.d.ts +13 -0
  16. package/dist/canvas/elements/MeasurementStampElement.js +30 -0
  17. package/dist/canvas/elements/ShapeElement.d.ts +7 -0
  18. package/dist/canvas/elements/ShapeElement.js +62 -0
  19. package/dist/canvas/elements/StrokeElement.d.ts +7 -0
  20. package/dist/canvas/elements/StrokeElement.js +18 -0
  21. package/dist/canvas/measurementPicker.d.ts +10 -0
  22. package/dist/canvas/measurementPicker.js +1 -0
  23. package/dist/canvas/pointerAdapter.d.ts +3 -0
  24. package/dist/canvas/pointerAdapter.js +19 -0
  25. package/dist/canvas/stampLayout.d.ts +4 -0
  26. package/dist/canvas/stampLayout.js +8 -0
  27. package/dist/canvas/tools/measurementStampTool.d.ts +9 -0
  28. package/dist/canvas/tools/measurementStampTool.js +37 -0
  29. package/dist/canvas/tools/panTool.d.ts +5 -0
  30. package/dist/canvas/tools/panTool.js +25 -0
  31. package/dist/canvas/tools/penTool.d.ts +13 -0
  32. package/dist/canvas/tools/penTool.js +68 -0
  33. package/dist/canvas/tools/selectTool.d.ts +2 -0
  34. package/dist/canvas/tools/selectTool.js +182 -0
  35. package/dist/canvas/useAnnotationCanvasState.d.ts +53 -0
  36. package/dist/canvas/useAnnotationCanvasState.js +182 -0
  37. package/dist/canvas/viewport.d.ts +16 -0
  38. package/dist/canvas/viewport.js +54 -0
  39. package/dist/data/AnnotationDataContext.d.ts +8 -0
  40. package/dist/data/AnnotationDataContext.js +11 -0
  41. package/dist/data/AnnotationDataProvider.d.ts +65 -0
  42. package/dist/data/AnnotationDataProvider.js +4 -0
  43. package/dist/data/InMemoryAnnotationProvider.d.ts +30 -0
  44. package/dist/data/InMemoryAnnotationProvider.js +197 -0
  45. package/dist/data/hooks/useAnnotationDoc.d.ts +7 -0
  46. package/dist/data/hooks/useAnnotationDoc.js +33 -0
  47. package/dist/data/hooks/useAnnotationList.d.ts +7 -0
  48. package/dist/data/hooks/useAnnotationList.js +26 -0
  49. package/dist/data/hooks/useAnnotationMutations.d.ts +9 -0
  50. package/dist/data/hooks/useAnnotationMutations.js +11 -0
  51. package/dist/exports.d.ts +25 -0
  52. package/dist/exports.js +26 -0
  53. package/dist/index.d.ts +2 -8
  54. package/dist/index.js +6 -8
  55. package/dist/index.native.d.ts +5 -0
  56. package/dist/index.native.js +6 -0
  57. package/dist/types/annotation.d.ts +139 -0
  58. package/dist/types/annotation.js +147 -0
  59. package/dist/types/firestore.d.ts +4 -15
  60. package/dist/types/firestore.js +0 -2
  61. package/dist/utils/groups.d.ts +4 -0
  62. package/dist/utils/groups.js +3 -0
  63. package/dist/utils/micrometersToUnit.d.ts +0 -1
  64. package/dist/utils/micrometersToUnit.js +1 -24
  65. package/dist/utils/tolerance.d.ts +0 -15
  66. package/dist/utils/tolerance.js +0 -41
  67. package/package.json +33 -2
@@ -0,0 +1,11 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { AnnotationCanvasInnerProps } from './AnnotationCanvasInner.js';
3
+ export type { AnnotationCanvasHandle, GestureConfig, PanTrigger, } from './AnnotationCanvasInner.js';
4
+ export interface CanvasKitOpts {
5
+ locateFile?: (file: string) => string;
6
+ }
7
+ export type AnnotationCanvasProps = AnnotationCanvasInnerProps & {
8
+ fallback?: ReactNode;
9
+ canvasKitOpts?: CanvasKitOpts;
10
+ };
11
+ export declare const AnnotationCanvas: ({ fallback, canvasKitOpts, ...rest }: AnnotationCanvasProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { WithSkiaWeb } from '@shopify/react-native-skia/lib/module/web/index.js';
3
+ // Web-only entry point: lazy-loads CanvasKit wasm via WithSkiaWeb. Imperative
4
+ // API (undo/redo/zoom) is exposed through the `imperativeRef` prop rather
5
+ // than React refs, since WithSkiaWeb can't forward refs through its lazy
6
+ // component boundary. The native build sits in `AnnotationCanvas.native.tsx`
7
+ // and skips WithSkiaWeb entirely (no wasm to load).
8
+ export const AnnotationCanvas = ({ fallback, canvasKitOpts, ...rest }) => (_jsx(WithSkiaWeb, { getComponent: () => import('./AnnotationCanvasInner.js').then((m) => ({
9
+ default: m.AnnotationCanvasInner,
10
+ })), fallback: fallback ?? null, componentProps: rest, opts: canvasKitOpts }));
@@ -0,0 +1,8 @@
1
+ import type { AnnotationCanvasInnerProps } from './AnnotationCanvasInner.native.js';
2
+ export type { AnnotationCanvasHandle, } from './useAnnotationCanvasState.js';
3
+ export type { GestureConfig, PanTrigger, } from './AnnotationCanvasInner.js';
4
+ export type AnnotationCanvasProps = AnnotationCanvasInnerProps & {
5
+ fallback?: unknown;
6
+ canvasKitOpts?: unknown;
7
+ };
8
+ export declare const AnnotationCanvas: (props: AnnotationCanvasProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { AnnotationCanvasInner } from './AnnotationCanvasInner.native.js';
3
+ export const AnnotationCanvas = (props) => {
4
+ const { fallback: _f, canvasKitOpts: _o, ...rest } = props;
5
+ return _jsx(AnnotationCanvasInner, { ...rest });
6
+ };
@@ -0,0 +1,37 @@
1
+ import { type CSSProperties, type MutableRefObject } from 'react';
2
+ import type { DecimalTolerance, FractionalTolerance, Measurement, Units } from '../types/firestore.js';
3
+ import type { AnnotationCanvasState, AnnotationDocumentPatch, Selection } from '../types/annotation.js';
4
+ import type { MeasurementRef } from './measurementPicker.js';
5
+ import type { Tool } from './Tool.js';
6
+ import { type AnnotationCanvasHandle } from './useAnnotationCanvasState.js';
7
+ import { type ViewportState } from './viewport.js';
8
+ export type { AnnotationCanvasHandle };
9
+ export interface AnnotationCanvasInnerProps {
10
+ canvas: AnnotationCanvasState;
11
+ onCommit(patch: AnnotationDocumentPatch): void;
12
+ tools: Tool[];
13
+ activeToolId: string;
14
+ selection: Selection | null;
15
+ onSelectionChange(selection: Selection | null): void;
16
+ measurements?: Measurement[];
17
+ fallbackUnit?: Units;
18
+ fractionalTolerance?: FractionalTolerance;
19
+ decimalTolerance?: DecimalTolerance;
20
+ resolveImageUrl?: (storagePath: string) => Promise<string>;
21
+ pickMeasurement?: () => Promise<MeasurementRef | null>;
22
+ stampFontSource?: unknown;
23
+ stampValueFontSize?: number;
24
+ stampLabelFontSize?: number;
25
+ gestures?: GestureConfig;
26
+ width: number;
27
+ height: number;
28
+ initialViewport?: ViewportState;
29
+ style?: CSSProperties;
30
+ imperativeRef?: MutableRefObject<AnnotationCanvasHandle | null>;
31
+ }
32
+ export type PanTrigger = 'middleMouse' | 'rightMouse' | 'space';
33
+ export interface GestureConfig {
34
+ wheel?: 'zoom' | 'pan' | 'auto';
35
+ panTriggers?: PanTrigger[];
36
+ }
37
+ export declare const AnnotationCanvasInner: (props: AnnotationCanvasInnerProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,179 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useFont } from '@shopify/react-native-skia';
3
+ import { useCallback, useEffect, useRef, } from 'react';
4
+ import { AnnotationCanvasSkia } from './AnnotationCanvasSkia.js';
5
+ import { useAnnotationCanvasState, } from './useAnnotationCanvasState.js';
6
+ const DEFAULT_PAN_TRIGGERS = ['middleMouse', 'space'];
7
+ export const AnnotationCanvasInner = (props) => {
8
+ const { fallbackUnit, fractionalTolerance, decimalTolerance, resolveImageUrl, stampFontSource, stampValueFontSize = 14, stampLabelFontSize = 11, gestures, width, height, style, activeToolId, tools, } = props;
9
+ const wheelMode = gestures?.wheel ?? 'auto';
10
+ const panTriggers = gestures?.panTriggers ?? DEFAULT_PAN_TRIGGERS;
11
+ const allowSpacePan = panTriggers.includes('space');
12
+ const allowMiddlePan = panTriggers.includes('middleMouse');
13
+ const allowRightPan = panTriggers.includes('rightMouse');
14
+ const valueFont = useFont(stampFontSource, stampValueFontSize);
15
+ const labelFont = useFont(stampFontSource, stampLabelFontSize);
16
+ const state = useAnnotationCanvasState(props);
17
+ const containerRef = useRef(null);
18
+ const panGestureRef = useRef(null);
19
+ const spaceDownRef = useRef(false);
20
+ const activeTool = tools.find((t) => t.id === activeToolId) ?? null;
21
+ const toCanvasPointer = useCallback((event) => {
22
+ const rect = containerRef.current?.getBoundingClientRect();
23
+ const screen = {
24
+ x: event.clientX - (rect?.left ?? 0),
25
+ y: event.clientY - (rect?.top ?? 0),
26
+ };
27
+ return {
28
+ pointerId: event.pointerId,
29
+ screen,
30
+ world: state.ctx.viewport.screenToWorld(screen),
31
+ pressure: event.pressure || undefined,
32
+ shiftKey: event.shiftKey,
33
+ altKey: event.altKey,
34
+ metaKey: event.metaKey,
35
+ ctrlKey: event.ctrlKey,
36
+ };
37
+ }, [state.ctx.viewport]);
38
+ const isPanTriggerDown = useCallback((event) => {
39
+ if (allowMiddlePan && event.button === 1)
40
+ return true;
41
+ if (allowRightPan && event.button === 2)
42
+ return true;
43
+ if (allowSpacePan && event.button === 0 && spaceDownRef.current)
44
+ return true;
45
+ return false;
46
+ }, [allowMiddlePan, allowRightPan, allowSpacePan]);
47
+ const handlePointerDown = useCallback((event) => {
48
+ const rect = containerRef.current?.getBoundingClientRect();
49
+ const screen = {
50
+ x: event.clientX - (rect?.left ?? 0),
51
+ y: event.clientY - (rect?.top ?? 0),
52
+ };
53
+ if (isPanTriggerDown(event)) {
54
+ panGestureRef.current = { pointerId: event.pointerId, lastScreen: screen };
55
+ event.currentTarget.setPointerCapture(event.pointerId);
56
+ event.preventDefault();
57
+ return;
58
+ }
59
+ event.currentTarget.setPointerCapture(event.pointerId);
60
+ state.dispatchPointerDown(toCanvasPointer(event));
61
+ }, [state, toCanvasPointer, isPanTriggerDown]);
62
+ const handlePointerMove = useCallback((event) => {
63
+ const pan = panGestureRef.current;
64
+ if (pan && event.pointerId === pan.pointerId) {
65
+ const rect = containerRef.current?.getBoundingClientRect();
66
+ const screen = {
67
+ x: event.clientX - (rect?.left ?? 0),
68
+ y: event.clientY - (rect?.top ?? 0),
69
+ };
70
+ state.pan({
71
+ x: screen.x - pan.lastScreen.x,
72
+ y: screen.y - pan.lastScreen.y,
73
+ });
74
+ panGestureRef.current = { pointerId: pan.pointerId, lastScreen: screen };
75
+ return;
76
+ }
77
+ state.dispatchPointerMove(toCanvasPointer(event));
78
+ }, [state, toCanvasPointer]);
79
+ const handlePointerUp = useCallback((event) => {
80
+ const pan = panGestureRef.current;
81
+ if (pan && event.pointerId === pan.pointerId) {
82
+ panGestureRef.current = null;
83
+ return;
84
+ }
85
+ state.dispatchPointerUp(toCanvasPointer(event));
86
+ }, [state, toCanvasPointer]);
87
+ const handlePointerCancel = useCallback(() => {
88
+ panGestureRef.current = null;
89
+ state.dispatchPointerCancel();
90
+ }, [state]);
91
+ const handleWheel = useCallback((event) => {
92
+ const rect = containerRef.current?.getBoundingClientRect();
93
+ const focal = {
94
+ x: event.clientX - (rect?.left ?? 0),
95
+ y: event.clientY - (rect?.top ?? 0),
96
+ };
97
+ if (event.ctrlKey || event.metaKey) {
98
+ const factor = Math.exp(-event.deltaY / 200);
99
+ state.zoom(focal, state.ctx.viewport.state.zoom * factor);
100
+ return;
101
+ }
102
+ if (wheelMode === 'zoom') {
103
+ const factor = Math.exp(-event.deltaY / 300);
104
+ state.zoom(focal, state.ctx.viewport.state.zoom * factor);
105
+ return;
106
+ }
107
+ if (event.shiftKey) {
108
+ state.pan({ x: event.deltaY, y: event.deltaX });
109
+ return;
110
+ }
111
+ state.pan({ x: event.deltaX, y: event.deltaY });
112
+ }, [state, wheelMode]);
113
+ const handleContextMenu = useCallback((event) => {
114
+ if (allowRightPan)
115
+ event.preventDefault();
116
+ }, [allowRightPan]);
117
+ useEffect(() => {
118
+ const el = containerRef.current;
119
+ if (!el)
120
+ return;
121
+ const stop = (e) => {
122
+ if (e.target === el || el.contains(e.target)) {
123
+ e.preventDefault();
124
+ }
125
+ };
126
+ el.addEventListener('wheel', stop, { passive: false });
127
+ return () => el.removeEventListener('wheel', stop);
128
+ }, []);
129
+ useEffect(() => {
130
+ if (!allowSpacePan)
131
+ return;
132
+ const onKeyDown = (e) => {
133
+ if (e.code === 'Space' && !e.repeat) {
134
+ spaceDownRef.current = true;
135
+ if (containerRef.current)
136
+ containerRef.current.style.cursor = 'grab';
137
+ }
138
+ };
139
+ const onKeyUp = (e) => {
140
+ if (e.code === 'Space') {
141
+ spaceDownRef.current = false;
142
+ if (containerRef.current)
143
+ containerRef.current.style.cursor = '';
144
+ }
145
+ };
146
+ window.addEventListener('keydown', onKeyDown);
147
+ window.addEventListener('keyup', onKeyUp);
148
+ return () => {
149
+ window.removeEventListener('keydown', onKeyDown);
150
+ window.removeEventListener('keyup', onKeyUp);
151
+ };
152
+ }, [allowSpacePan]);
153
+ const containerStyle = {
154
+ position: 'relative',
155
+ width,
156
+ height,
157
+ overflow: 'hidden',
158
+ touchAction: 'none',
159
+ userSelect: 'none',
160
+ cursor: activeTool?.cursor ?? 'default',
161
+ ...style,
162
+ };
163
+ const customPreview = activeTool?.renderPreview?.(state.customPreviewState, state.ctx);
164
+ return (_jsx("div", { ref: containerRef, style: containerStyle, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onPointerUp: handlePointerUp, onPointerCancel: handlePointerCancel, onWheel: handleWheel, onContextMenu: handleContextMenu, children: AnnotationCanvasSkia({
165
+ width,
166
+ height,
167
+ effectiveCanvas: state.effectiveCanvas,
168
+ worldTransform: state.worldTransform,
169
+ measurementsById: state.measurementsById,
170
+ fallbackUnit,
171
+ fractionalTolerance,
172
+ decimalTolerance,
173
+ resolveImageUrl,
174
+ valueFont,
175
+ labelFont,
176
+ penDrawingStroke: state.penDrawingStroke,
177
+ customPreview,
178
+ }) }));
179
+ };
@@ -0,0 +1,33 @@
1
+ import { type MutableRefObject } from 'react';
2
+ import { type ViewStyle } from 'react-native';
3
+ import type { DecimalTolerance, FractionalTolerance, Measurement, Units } from '../types/firestore.js';
4
+ import type { AnnotationCanvasState, AnnotationDocumentPatch, Selection } from '../types/annotation.js';
5
+ import type { MeasurementRef } from './measurementPicker.js';
6
+ import type { Tool } from './Tool.js';
7
+ import { type AnnotationCanvasHandle } from './useAnnotationCanvasState.js';
8
+ import type { ViewportState } from './viewport.js';
9
+ export type { AnnotationCanvasHandle };
10
+ export interface AnnotationCanvasInnerProps {
11
+ canvas: AnnotationCanvasState;
12
+ onCommit(patch: AnnotationDocumentPatch): void;
13
+ tools: Tool[];
14
+ activeToolId: string;
15
+ selection: Selection | null;
16
+ onSelectionChange(selection: Selection | null): void;
17
+ measurements?: Measurement[];
18
+ fallbackUnit?: Units;
19
+ fractionalTolerance?: FractionalTolerance;
20
+ decimalTolerance?: DecimalTolerance;
21
+ resolveImageUrl?: (storagePath: string) => Promise<string>;
22
+ pickMeasurement?: () => Promise<MeasurementRef | null>;
23
+ stampFontSource?: unknown;
24
+ stampValueFontSize?: number;
25
+ stampLabelFontSize?: number;
26
+ gestures?: unknown;
27
+ width: number;
28
+ height: number;
29
+ initialViewport?: ViewportState;
30
+ style?: ViewStyle;
31
+ imperativeRef?: MutableRefObject<AnnotationCanvasHandle | null>;
32
+ }
33
+ export declare const AnnotationCanvasInner: (props: AnnotationCanvasInnerProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,102 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useFont } from '@shopify/react-native-skia';
3
+ import { useMemo, useRef } from 'react';
4
+ import { View } from 'react-native';
5
+ import { Gesture, GestureDetector, GestureHandlerRootView, } from 'react-native-gesture-handler';
6
+ import { AnnotationCanvasSkia } from './AnnotationCanvasSkia.js';
7
+ import { useAnnotationCanvasState, } from './useAnnotationCanvasState.js';
8
+ // Native fingerprint: one finger drives the active tool, two fingers
9
+ // pan/zoom the viewport. Tap counts as a brief pointer down+up so tools
10
+ // like measurement-stamp (which only listen to onPointerUp) work via tap.
11
+ export const AnnotationCanvasInner = (props) => {
12
+ const { fallbackUnit, fractionalTolerance, decimalTolerance, resolveImageUrl, stampFontSource, stampValueFontSize = 14, stampLabelFontSize = 11, width, height, style, } = props;
13
+ const valueFont = useFont(stampFontSource, stampValueFontSize);
14
+ const labelFont = useFont(stampFontSource, stampLabelFontSize);
15
+ const state = useAnnotationCanvasState(props);
16
+ // Per-gesture refs so we always emit a matching down/move/up sequence.
17
+ const pointerIdRef = useRef(1);
18
+ const inFlightRef = useRef(null);
19
+ const pinchStartZoomRef = useRef(1);
20
+ const buildEvent = (pointerId, screen) => ({
21
+ pointerId,
22
+ screen,
23
+ world: state.ctx.viewport.screenToWorld(screen),
24
+ });
25
+ const gesture = useMemo(() => {
26
+ const toolPan = Gesture.Pan()
27
+ .minPointers(1)
28
+ .maxPointers(1)
29
+ .runOnJS(true)
30
+ .onBegin((e) => {
31
+ const id = pointerIdRef.current++;
32
+ const screen = { x: e.x, y: e.y };
33
+ inFlightRef.current = { id, lastScreen: screen };
34
+ state.dispatchPointerDown(buildEvent(id, screen));
35
+ })
36
+ .onUpdate((e) => {
37
+ const f = inFlightRef.current;
38
+ if (!f)
39
+ return;
40
+ const screen = { x: e.x, y: e.y };
41
+ f.lastScreen = screen;
42
+ state.dispatchPointerMove(buildEvent(f.id, screen));
43
+ })
44
+ .onEnd((e) => {
45
+ const f = inFlightRef.current;
46
+ if (!f)
47
+ return;
48
+ state.dispatchPointerUp(buildEvent(f.id, { x: e.x, y: e.y }));
49
+ inFlightRef.current = null;
50
+ })
51
+ .onFinalize(() => {
52
+ if (inFlightRef.current) {
53
+ state.dispatchPointerCancel();
54
+ inFlightRef.current = null;
55
+ }
56
+ });
57
+ const tap = Gesture.Tap()
58
+ .maxDuration(250)
59
+ .runOnJS(true)
60
+ .onEnd((e) => {
61
+ const id = pointerIdRef.current++;
62
+ const screen = { x: e.x, y: e.y };
63
+ // Synthesize a down+up sequence so tools that only listen to
64
+ // onPointerUp (e.g. measurement stamp) still fire.
65
+ state.dispatchPointerDown(buildEvent(id, screen));
66
+ state.dispatchPointerUp(buildEvent(id, screen));
67
+ });
68
+ const viewportPan = Gesture.Pan()
69
+ .minPointers(2)
70
+ .maxPointers(2)
71
+ .runOnJS(true)
72
+ .onChange((e) => {
73
+ state.pan({ x: e.changeX, y: e.changeY });
74
+ });
75
+ const pinch = Gesture.Pinch()
76
+ .runOnJS(true)
77
+ .onBegin(() => {
78
+ pinchStartZoomRef.current = state.ctx.viewport.state.zoom;
79
+ })
80
+ .onUpdate((e) => {
81
+ state.zoom({ x: e.focalX, y: e.focalY }, pinchStartZoomRef.current * e.scale);
82
+ });
83
+ return Gesture.Race(tap, Gesture.Simultaneous(viewportPan, pinch), toolPan);
84
+ }, [state]);
85
+ const activeTool = props.tools.find((t) => t.id === props.activeToolId) ?? null;
86
+ const customPreview = activeTool?.renderPreview?.(state.customPreviewState, state.ctx);
87
+ return (_jsx(GestureHandlerRootView, { style: [{ width, height }, style], children: _jsx(GestureDetector, { gesture: gesture, children: _jsx(View, { style: { width, height }, collapsable: false, children: AnnotationCanvasSkia({
88
+ width,
89
+ height,
90
+ effectiveCanvas: state.effectiveCanvas,
91
+ worldTransform: state.worldTransform,
92
+ measurementsById: state.measurementsById,
93
+ fallbackUnit,
94
+ fractionalTolerance,
95
+ decimalTolerance,
96
+ resolveImageUrl,
97
+ valueFont,
98
+ labelFont,
99
+ penDrawingStroke: state.penDrawingStroke,
100
+ customPreview,
101
+ }) }) }) }));
102
+ };
@@ -0,0 +1,26 @@
1
+ import { type SkFont } from '@shopify/react-native-skia';
2
+ import type { ReactNode } from 'react';
3
+ import type { AnnotationCanvasState, AnnotationStroke } from '../types/annotation.js';
4
+ import { DecimalTolerance, FractionalTolerance, Units, type Measurement } from '../types/firestore.js';
5
+ export interface AnnotationCanvasSkiaProps {
6
+ width: number;
7
+ height: number;
8
+ effectiveCanvas: AnnotationCanvasState;
9
+ worldTransform: Array<{
10
+ scale: number;
11
+ } | {
12
+ translateX: number;
13
+ } | {
14
+ translateY: number;
15
+ }>;
16
+ measurementsById: Map<string, Measurement>;
17
+ fallbackUnit?: Units;
18
+ fractionalTolerance?: FractionalTolerance;
19
+ decimalTolerance?: DecimalTolerance;
20
+ resolveImageUrl?: (storagePath: string) => Promise<string>;
21
+ valueFont: SkFont | null;
22
+ labelFont: SkFont | null;
23
+ penDrawingStroke: AnnotationStroke | null;
24
+ customPreview?: ReactNode;
25
+ }
26
+ export declare const AnnotationCanvasSkia: ({ width, height, effectiveCanvas, worldTransform, measurementsById, fallbackUnit, fractionalTolerance, decimalTolerance, resolveImageUrl, valueFont, labelFont, penDrawingStroke, customPreview, }: AnnotationCanvasSkiaProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Canvas, Group } from '@shopify/react-native-skia';
3
+ import { Units, } from '../types/firestore.js';
4
+ import { BackgroundImageElement } from './elements/BackgroundImageElement.js';
5
+ import { MeasurementStampElement } from './elements/MeasurementStampElement.js';
6
+ import { ShapeElement } from './elements/ShapeElement.js';
7
+ import { StrokeElement } from './elements/StrokeElement.js';
8
+ // Platform-agnostic Skia subtree shared by web and native Inners.
9
+ //
10
+ // Call this as a FUNCTION (`AnnotationCanvasSkia({ ... })`), not as a JSX
11
+ // component (`<AnnotationCanvasSkia ... />`). Used as a component, it adds
12
+ // a React component boundary between the parent and Skia's `<Canvas>` that
13
+ // breaks Skia's reconciler when the page first calls `useFont` — the JS
14
+ // thread hangs in `MakeFreeTypeFaceFromData`. Symptoms only appeared on
15
+ // Vite's dev server with a symlinked boldr-utils + React Refresh, but
16
+ // since the function-call pattern works identically on native we use it
17
+ // in both Inners for consistency. Don't add hooks here; this is a plain
18
+ // JSX-returning helper, not a component.
19
+ export const AnnotationCanvasSkia = ({ width, height, effectiveCanvas, worldTransform, measurementsById, fallbackUnit, fractionalTolerance, decimalTolerance, resolveImageUrl, valueFont, labelFont, penDrawingStroke, customPreview, }) => (_jsx(Canvas, { style: { width, height }, children: _jsxs(Group, { transform: worldTransform, children: [effectiveCanvas.viewport.backgroundImage && (_jsx(BackgroundImageElement, { image: effectiveCanvas.viewport.backgroundImage, docWidth: effectiveCanvas.viewport.width, docHeight: effectiveCanvas.viewport.height, fit: effectiveCanvas.viewport.backgroundFit ?? 'contain', resolveUrl: resolveImageUrl })), effectiveCanvas.strokes.map((stroke) => (_jsx(StrokeElement, { stroke: stroke }, stroke.id))), effectiveCanvas.shapes.map((shape) => (_jsx(ShapeElement, { shape: shape, font: valueFont }, shape.id))), effectiveCanvas.placedMeasurements.map((placed) => (_jsx(MeasurementStampElement, { placed: placed, measurement: measurementsById.get(placed.measurementId) ?? null, fallbackUnit: fallbackUnit ?? Units.Millimeters, fractionalTolerance: fractionalTolerance, decimalTolerance: decimalTolerance, valueFont: valueFont, labelFont: labelFont }, placed.id))), penDrawingStroke && _jsx(StrokeElement, { stroke: penDrawingStroke }), customPreview] }) }));
@@ -0,0 +1,38 @@
1
+ import type { ReactNode, ComponentType } from 'react';
2
+ import type { AnnotationCanvasState, AnnotationDocumentPatch, AnnotationElement, Selection, Vec2 } from '../types/annotation.js';
3
+ import type { MeasurementRef } from './measurementPicker.js';
4
+ import type { ViewportApi } from './viewport.js';
5
+ export interface CanvasPointerEvent {
6
+ pointerId: number;
7
+ world: Vec2;
8
+ screen: Vec2;
9
+ pressure?: number;
10
+ shiftKey?: boolean;
11
+ altKey?: boolean;
12
+ metaKey?: boolean;
13
+ ctrlKey?: boolean;
14
+ }
15
+ export interface ToolContext {
16
+ document: AnnotationCanvasState;
17
+ selection: Selection | null;
18
+ viewport: ViewportApi;
19
+ preview(patch: AnnotationDocumentPatch): void;
20
+ commit(patch: AnnotationDocumentPatch): void;
21
+ setSelection(selection: Selection | null): void;
22
+ requestPickMeasurement(): Promise<MeasurementRef | null>;
23
+ applyPan(deltaScreen: Vec2): void;
24
+ applyZoom(focalScreen: Vec2, nextZoom: number): void;
25
+ }
26
+ export type ToolState = unknown;
27
+ export interface Tool {
28
+ id: string;
29
+ label: string;
30
+ icon?: ComponentType;
31
+ cursor?: string;
32
+ onPointerDown?(event: CanvasPointerEvent, ctx: ToolContext, state: ToolState): ToolState | void;
33
+ onPointerMove?(event: CanvasPointerEvent, ctx: ToolContext, state: ToolState): ToolState | void;
34
+ onPointerUp?(event: CanvasPointerEvent, ctx: ToolContext, state: ToolState): ToolState | void;
35
+ onCancel?(state: ToolState, ctx: ToolContext): void;
36
+ renderPreview?(state: ToolState, ctx: ToolContext): ReactNode;
37
+ hitTest?(element: AnnotationElement, worldPoint: Vec2): boolean;
38
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { AnnotationBackgroundImage, BackgroundFit } from '../../types/annotation.js';
2
+ export interface BackgroundImageElementProps {
3
+ image: AnnotationBackgroundImage;
4
+ docWidth: number;
5
+ docHeight: number;
6
+ fit?: BackgroundFit;
7
+ resolveUrl?: (path: string) => Promise<string>;
8
+ }
9
+ export declare const BackgroundImageElement: ({ image, docWidth, docHeight, fit, resolveUrl, }: BackgroundImageElementProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Image, useImage } from '@shopify/react-native-skia';
3
+ import { useEffect, useState } from 'react';
4
+ const computeFit = (imgW, imgH, docW, docH, fit) => {
5
+ if (fit === 'stretch') {
6
+ return { x: 0, y: 0, width: docW, height: docH };
7
+ }
8
+ const scale = fit === 'cover'
9
+ ? Math.max(docW / imgW, docH / imgH)
10
+ : Math.min(docW / imgW, docH / imgH);
11
+ const w = imgW * scale;
12
+ const h = imgH * scale;
13
+ return { x: (docW - w) / 2, y: (docH - h) / 2, width: w, height: h };
14
+ };
15
+ export const BackgroundImageElement = ({ image, docWidth, docHeight, fit = 'contain', resolveUrl, }) => {
16
+ const [url, setUrl] = useState(image.downloadUrl);
17
+ useEffect(() => {
18
+ let cancelled = false;
19
+ if (resolveUrl) {
20
+ resolveUrl(image.storagePath).then((next) => {
21
+ if (!cancelled)
22
+ setUrl(next);
23
+ });
24
+ }
25
+ else {
26
+ setUrl(image.downloadUrl);
27
+ }
28
+ return () => {
29
+ cancelled = true;
30
+ };
31
+ }, [image.downloadUrl, image.storagePath, resolveUrl]);
32
+ const skImage = useImage(url);
33
+ if (!skImage)
34
+ return null;
35
+ const dims = computeFit(image.widthPx, image.heightPx, docWidth, docHeight, fit);
36
+ return (_jsx(Image, { image: skImage, x: dims.x, y: dims.y, width: dims.width, height: dims.height, fit: "fill" }));
37
+ };
@@ -0,0 +1,13 @@
1
+ import { type SkFont } from '@shopify/react-native-skia';
2
+ import type { PlacedMeasurementRef } from '../../types/annotation.js';
3
+ import { DecimalTolerance, FractionalTolerance, type Measurement, type Units } from '../../types/firestore.js';
4
+ export interface MeasurementStampElementProps {
5
+ placed: PlacedMeasurementRef;
6
+ measurement: Measurement | null;
7
+ fallbackUnit: Units;
8
+ fractionalTolerance?: FractionalTolerance;
9
+ decimalTolerance?: DecimalTolerance;
10
+ valueFont?: SkFont | null;
11
+ labelFont?: SkFont | null;
12
+ }
13
+ export declare const MeasurementStampElement: ({ placed, measurement, fallbackUnit, fractionalTolerance, decimalTolerance, valueFont, labelFont, }: MeasurementStampElementProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Group, Line, RoundedRect, Text, } from '@shopify/react-native-skia';
3
+ import { DecimalTolerance, FractionalTolerance, } from '../../types/firestore.js';
4
+ import { convertMicrometers } from '../../utils/micrometersToUnit.js';
5
+ import { STAMP_HEIGHT, STAMP_PADDING_X, STAMP_PADDING_Y, STAMP_WIDTH, } from '../stampLayout.js';
6
+ const VALUE_FONT_BASELINE_OFFSET = 14;
7
+ const LABEL_FONT_BASELINE_OFFSET = 24;
8
+ const formatValue = (measurement, unit, fractionalTolerance, decimalTolerance) => {
9
+ if (!measurement)
10
+ return '—';
11
+ const result = convertMicrometers(measurement.value, unit, fractionalTolerance, decimalTolerance);
12
+ return `${result.value}${result.unit ? ` ${result.unit}` : ''}`;
13
+ };
14
+ export const MeasurementStampElement = ({ placed, measurement, fallbackUnit, fractionalTolerance = FractionalTolerance.Sixteenth, decimalTolerance = DecimalTolerance.Hundredth, valueFont, labelFont, }) => {
15
+ const unit = placed.unitOverride ?? measurement?.unit ?? fallbackUnit;
16
+ const valueText = formatValue(measurement, unit, fractionalTolerance, decimalTolerance);
17
+ const label = placed.labelOverride ??
18
+ measurement?.label ??
19
+ (measurement
20
+ ? `M${measurement.measurementIndex ?? ''}`
21
+ : '');
22
+ const showLabel = placed.showLabel !== false && !!label;
23
+ const showValue = placed.showValue !== false;
24
+ const scale = placed.scale ?? 1;
25
+ // Fixed-size stamp — no measureText calls. Keeps rendering deterministic
26
+ // even when no font is loaded (browser/native both).
27
+ const baseX = placed.anchor.x - (STAMP_WIDTH * scale) / 2;
28
+ const baseY = placed.anchor.y - (STAMP_HEIGHT * scale) / 2;
29
+ return (_jsxs(Group, { transform: [{ translateX: baseX }, { translateY: baseY }, { scale }], children: [placed.leader && (_jsx(Line, { p1: placed.leader.from, p2: placed.leader.to, color: "#3B82F6", style: "stroke", strokeWidth: 1.5 })), _jsx(RoundedRect, { x: 0, y: 0, width: STAMP_WIDTH, height: STAMP_HEIGHT, r: 6, color: "#FFFFFFEE" }), _jsx(RoundedRect, { x: 0, y: 0, width: STAMP_WIDTH, height: STAMP_HEIGHT, r: 6, color: "#3B82F6", style: "stroke", strokeWidth: 1.25 }), showValue && valueFont && (_jsx(Text, { x: STAMP_PADDING_X, y: STAMP_PADDING_Y + VALUE_FONT_BASELINE_OFFSET, text: valueText, font: valueFont, color: "#111827" })), showLabel && labelFont && (_jsx(Text, { x: STAMP_PADDING_X, y: STAMP_PADDING_Y + LABEL_FONT_BASELINE_OFFSET, text: label, font: labelFont, color: "#6B7280" }))] }));
30
+ };
@@ -0,0 +1,7 @@
1
+ import { type SkFont } from '@shopify/react-native-skia';
2
+ import type { AnnotationShape } from '../../types/annotation.js';
3
+ export interface ShapeElementProps {
4
+ shape: AnnotationShape;
5
+ font?: SkFont | null;
6
+ }
7
+ export declare const ShapeElement: ({ shape, font }: ShapeElementProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,62 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Circle, Line, Path, Rect, Skia, Text, } from '@shopify/react-native-skia';
3
+ import { useMemo } from 'react';
4
+ const polygonPath = (points) => {
5
+ const path = Skia.Path.Make();
6
+ if (points.length === 0)
7
+ return path;
8
+ path.moveTo(points[0].x, points[0].y);
9
+ for (let i = 1; i < points.length; i++) {
10
+ path.lineTo(points[i].x, points[i].y);
11
+ }
12
+ path.close();
13
+ return path;
14
+ };
15
+ export const ShapeElement = ({ shape, font }) => {
16
+ const { kind, geometry, style, text } = shape;
17
+ const stroke = style.stroke ?? '#000000';
18
+ const fill = style.fill;
19
+ const strokeWidth = style.strokeWidth ?? 2;
20
+ const polyPath = useMemo(() => (kind === 'polygon' ? polygonPath(geometry.points) : null), [kind, geometry.points]);
21
+ switch (kind) {
22
+ case 'rect': {
23
+ const [a, b] = geometry.points;
24
+ if (!a || !b)
25
+ return null;
26
+ const x = Math.min(a.x, b.x);
27
+ const y = Math.min(a.y, b.y);
28
+ const w = Math.abs(b.x - a.x);
29
+ const h = Math.abs(b.y - a.y);
30
+ return (_jsxs(_Fragment, { children: [fill && _jsx(Rect, { x: x, y: y, width: w, height: h, color: fill }), _jsx(Rect, { x: x, y: y, width: w, height: h, color: stroke, style: "stroke", strokeWidth: strokeWidth })] }));
31
+ }
32
+ case 'ellipse': {
33
+ const [a, b] = geometry.points;
34
+ if (!a || !b)
35
+ return null;
36
+ const cx = (a.x + b.x) / 2;
37
+ const cy = (a.y + b.y) / 2;
38
+ const r = Math.max(Math.abs(b.x - a.x), Math.abs(b.y - a.y)) / 2;
39
+ return (_jsxs(_Fragment, { children: [fill && _jsx(Circle, { cx: cx, cy: cy, r: r, color: fill }), _jsx(Circle, { cx: cx, cy: cy, r: r, color: stroke, style: "stroke", strokeWidth: strokeWidth })] }));
40
+ }
41
+ case 'line':
42
+ case 'arrow': {
43
+ const [a, b] = geometry.points;
44
+ if (!a || !b)
45
+ return null;
46
+ return (_jsx(Line, { p1: a, p2: b, color: stroke, style: "stroke", strokeWidth: strokeWidth, strokeCap: "round" }));
47
+ }
48
+ case 'polygon': {
49
+ if (!polyPath)
50
+ return null;
51
+ return (_jsxs(_Fragment, { children: [fill && _jsx(Path, { path: polyPath, color: fill }), _jsx(Path, { path: polyPath, color: stroke, style: "stroke", strokeWidth: strokeWidth })] }));
52
+ }
53
+ case 'text': {
54
+ const [origin] = geometry.points;
55
+ if (!origin || !text)
56
+ return null;
57
+ if (!font)
58
+ return null;
59
+ return (_jsx(Text, { x: origin.x, y: origin.y, text: text, font: font, color: stroke }));
60
+ }
61
+ }
62
+ };