@reekon-tools/boldr-utils 1.6.11 → 1.6.13

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 (89) hide show
  1. package/dist/{canvas → annotation/canvas}/AnnotationCanvasInner.d.ts +5 -3
  2. package/dist/{canvas → annotation/canvas}/AnnotationCanvasInner.js +36 -17
  3. package/dist/{canvas → annotation/canvas}/AnnotationCanvasInner.native.d.ts +5 -3
  4. package/dist/annotation/canvas/AnnotationCanvasInner.native.js +810 -0
  5. package/dist/annotation/canvas/AnnotationCanvasSkia.d.ts +61 -0
  6. package/dist/annotation/canvas/AnnotationCanvasSkia.js +158 -0
  7. package/dist/annotation/canvas/Tool.d.ts +77 -0
  8. package/dist/{canvas → annotation/canvas}/elements/BackgroundImageElement.d.ts +2 -2
  9. package/dist/{canvas → annotation/canvas}/elements/BackgroundImageElement.js +17 -7
  10. package/dist/annotation/canvas/elements/ShapeElement.d.ts +7 -0
  11. package/dist/{canvas → annotation/canvas}/elements/ShapeElement.js +33 -5
  12. package/dist/annotation/canvas/elements/StrokeElement.d.ts +7 -0
  13. package/dist/annotation/canvas/elements/StrokeElement.js +45 -0
  14. package/dist/annotation/canvas/measurementGeometry.d.ts +43 -0
  15. package/dist/annotation/canvas/measurementGeometry.js +111 -0
  16. package/dist/{canvas → annotation/canvas}/measurementPicker.d.ts +1 -1
  17. package/dist/{canvas → annotation/canvas}/measurementStampOverlay.d.ts +2 -2
  18. package/dist/annotation/canvas/stampLayout.d.ts +1 -0
  19. package/dist/annotation/canvas/stampLayout.js +11 -0
  20. package/dist/annotation/canvas/strokeGeometry.d.ts +5 -0
  21. package/dist/annotation/canvas/strokeGeometry.js +41 -0
  22. package/dist/annotation/canvas/textGeometry.d.ts +24 -0
  23. package/dist/annotation/canvas/textGeometry.js +110 -0
  24. package/dist/{canvas → annotation/canvas}/tools/measurementStampTool.d.ts +1 -1
  25. package/dist/{canvas → annotation/canvas}/tools/measurementStampTool.js +1 -1
  26. package/dist/{canvas → annotation/canvas}/tools/panTool.js +3 -0
  27. package/dist/{canvas → annotation/canvas}/tools/penTool.d.ts +3 -1
  28. package/dist/{canvas → annotation/canvas}/tools/penTool.js +34 -5
  29. package/dist/annotation/canvas/tools/selectTool.js +446 -0
  30. package/dist/annotation/canvas/tools/textTool.d.ts +12 -0
  31. package/dist/annotation/canvas/tools/textTool.js +78 -0
  32. package/dist/{canvas → annotation/canvas}/useAnnotationCanvasState.d.ts +11 -3
  33. package/dist/{canvas → annotation/canvas}/useAnnotationCanvasState.js +142 -2
  34. package/dist/{canvas → annotation/canvas}/viewport.d.ts +1 -1
  35. package/dist/{data → annotation/data}/AnnotationDataProvider.d.ts +1 -1
  36. package/dist/{data → annotation/data}/InMemoryAnnotationProvider.d.ts +1 -1
  37. package/dist/{data → annotation/data}/InMemoryAnnotationProvider.js +1 -1
  38. package/dist/{data → annotation/data}/canvasPersistence.d.ts +1 -1
  39. package/dist/{data → annotation/data}/canvasPersistence.js +1 -1
  40. package/dist/annotation/data/coalescedRunner.d.ts +1 -0
  41. package/dist/annotation/data/coalescedRunner.js +48 -0
  42. package/dist/{data → annotation/data}/hooks/useAnnotationCanvasDoc.d.ts +1 -1
  43. package/dist/{data → annotation/data}/hooks/useAnnotationCanvasDoc.js +37 -16
  44. package/dist/exports.d.ts +23 -19
  45. package/dist/exports.js +18 -14
  46. package/dist/index.d.ts +2 -2
  47. package/dist/index.js +2 -2
  48. package/dist/index.native.d.ts +1 -1
  49. package/dist/index.native.js +1 -1
  50. package/dist/types/annotation.d.ts +22 -3
  51. package/dist/types/firestore.d.ts +0 -1
  52. package/dist/{hooks → utils}/useParseMeasurement.js +1 -1
  53. package/package.json +1 -1
  54. package/dist/canvas/AnnotationCanvasInner.native.js +0 -138
  55. package/dist/canvas/AnnotationCanvasSkia.d.ts +0 -27
  56. package/dist/canvas/AnnotationCanvasSkia.js +0 -20
  57. package/dist/canvas/Tool.d.ts +0 -38
  58. package/dist/canvas/elements/MeasurementStampElement.d.ts +0 -13
  59. package/dist/canvas/elements/MeasurementStampElement.js +0 -30
  60. package/dist/canvas/elements/ShapeElement.d.ts +0 -7
  61. package/dist/canvas/elements/StrokeElement.d.ts +0 -7
  62. package/dist/canvas/elements/StrokeElement.js +0 -18
  63. package/dist/canvas/stampLayout.d.ts +0 -5
  64. package/dist/canvas/stampLayout.js +0 -14
  65. package/dist/canvas/tools/selectTool.js +0 -182
  66. package/dist/utils/evaluateFormula.d.ts +0 -20
  67. package/dist/utils/evaluateFormula.js +0 -31
  68. /package/dist/{canvas → annotation/canvas}/AnnotationCanvas.d.ts +0 -0
  69. /package/dist/{canvas → annotation/canvas}/AnnotationCanvas.js +0 -0
  70. /package/dist/{canvas → annotation/canvas}/AnnotationCanvas.native.d.ts +0 -0
  71. /package/dist/{canvas → annotation/canvas}/AnnotationCanvas.native.js +0 -0
  72. /package/dist/{canvas → annotation/canvas}/Tool.js +0 -0
  73. /package/dist/{canvas → annotation/canvas}/measurementPicker.js +0 -0
  74. /package/dist/{canvas → annotation/canvas}/measurementStampOverlay.js +0 -0
  75. /package/dist/{canvas → annotation/canvas}/pointerAdapter.d.ts +0 -0
  76. /package/dist/{canvas → annotation/canvas}/pointerAdapter.js +0 -0
  77. /package/dist/{canvas → annotation/canvas}/tools/panTool.d.ts +0 -0
  78. /package/dist/{canvas → annotation/canvas}/tools/selectTool.d.ts +0 -0
  79. /package/dist/{canvas → annotation/canvas}/viewport.js +0 -0
  80. /package/dist/{data → annotation/data}/AnnotationDataContext.d.ts +0 -0
  81. /package/dist/{data → annotation/data}/AnnotationDataContext.js +0 -0
  82. /package/dist/{data → annotation/data}/AnnotationDataProvider.js +0 -0
  83. /package/dist/{data → annotation/data}/hooks/useAnnotationDoc.d.ts +0 -0
  84. /package/dist/{data → annotation/data}/hooks/useAnnotationDoc.js +0 -0
  85. /package/dist/{data → annotation/data}/hooks/useAnnotationList.d.ts +0 -0
  86. /package/dist/{data → annotation/data}/hooks/useAnnotationList.js +0 -0
  87. /package/dist/{data → annotation/data}/hooks/useAnnotationMutations.d.ts +0 -0
  88. /package/dist/{data → annotation/data}/hooks/useAnnotationMutations.js +0 -0
  89. /package/dist/{hooks → utils}/useParseMeasurement.d.ts +0 -0
@@ -1,8 +1,8 @@
1
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';
2
+ import type { DecimalTolerance, FractionalTolerance, Measurement, Units } from '../../types/firestore.js';
3
+ import type { AnnotationCanvasState, AnnotationDocumentPatch, PlacedMeasurementRef, Selection } from '../../types/annotation.js';
4
4
  import type { MeasurementRef } from './measurementPicker.js';
5
- import type { Tool } from './Tool.js';
5
+ import type { RequestTextInput, Tool } from './Tool.js';
6
6
  import { type AnnotationCanvasHandle } from './useAnnotationCanvasState.js';
7
7
  import { type ViewportState } from './viewport.js';
8
8
  import type { RenderMeasurementStamp } from './measurementStampOverlay.js';
@@ -20,7 +20,9 @@ export interface AnnotationCanvasInnerProps {
20
20
  decimalTolerance?: DecimalTolerance;
21
21
  resolveImageUrl?: (storagePath: string) => Promise<string>;
22
22
  pickMeasurement?: () => Promise<MeasurementRef | null>;
23
+ requestTextInput?: RequestTextInput;
23
24
  renderMeasurementStamp?: RenderMeasurementStamp;
25
+ onMeasurementStampPress?: (placed: PlacedMeasurementRef) => void;
24
26
  stampFontSource?: unknown;
25
27
  stampValueFontSize?: number;
26
28
  stampLabelFontSize?: number;
@@ -2,18 +2,21 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useFont } from '@shopify/react-native-skia';
3
3
  import { useCallback, useEffect, useRef, } from 'react';
4
4
  import { AnnotationCanvasSkia } from './AnnotationCanvasSkia.js';
5
+ import { buildRemoveMeasurementOps } from './measurementGeometry.js';
5
6
  import { useAnnotationCanvasState, } from './useAnnotationCanvasState.js';
6
7
  import { STAMP_TILE_SIZE } from './stampLayout.js';
8
+ // Screen-px radius of a measurement-annotation endpoint handle (matches the
9
+ // native HANDLE_RADIUS_PX). Divided by zoom for a constant on-screen size.
10
+ const HANDLE_PX = 7;
7
11
  const DEFAULT_PAN_TRIGGERS = ['middleMouse', 'space'];
8
12
  export const AnnotationCanvasInner = (props) => {
9
- const { fallbackUnit, fractionalTolerance, decimalTolerance, resolveImageUrl, stampFontSource, stampValueFontSize = 14, stampLabelFontSize = 11, gestures, width, height, style, activeToolId, tools, } = props;
13
+ const { resolveImageUrl, stampFontSource, stampValueFontSize = 14, gestures, width, height, style, activeToolId, tools, } = props;
10
14
  const wheelMode = gestures?.wheel ?? 'auto';
11
15
  const panTriggers = gestures?.panTriggers ?? DEFAULT_PAN_TRIGGERS;
12
16
  const allowSpacePan = panTriggers.includes('space');
13
17
  const allowMiddlePan = panTriggers.includes('middleMouse');
14
18
  const allowRightPan = panTriggers.includes('rightMouse');
15
19
  const valueFont = useFont(stampFontSource, stampValueFontSize);
16
- const labelFont = useFont(stampFontSource, stampLabelFontSize);
17
20
  const state = useAnnotationCanvasState(props);
18
21
  const containerRef = useRef(null);
19
22
  const panGestureRef = useRef(null);
@@ -52,7 +55,10 @@ export const AnnotationCanvasInner = (props) => {
52
55
  y: event.clientY - (rect?.top ?? 0),
53
56
  };
54
57
  if (isPanTriggerDown(event)) {
55
- panGestureRef.current = { pointerId: event.pointerId, lastScreen: screen };
58
+ panGestureRef.current = {
59
+ pointerId: event.pointerId,
60
+ lastScreen: screen,
61
+ };
56
62
  event.currentTarget.setPointerCapture(event.pointerId);
57
63
  event.preventDefault();
58
64
  return;
@@ -72,7 +78,10 @@ export const AnnotationCanvasInner = (props) => {
72
78
  x: screen.x - pan.lastScreen.x,
73
79
  y: screen.y - pan.lastScreen.y,
74
80
  });
75
- panGestureRef.current = { pointerId: pan.pointerId, lastScreen: screen };
81
+ panGestureRef.current = {
82
+ pointerId: pan.pointerId,
83
+ lastScreen: screen,
84
+ };
76
85
  return;
77
86
  }
78
87
  state.dispatchPointerMove(toCanvasPointer(event));
@@ -162,21 +171,20 @@ export const AnnotationCanvasInner = (props) => {
162
171
  ...style,
163
172
  };
164
173
  const customPreview = activeTool?.renderPreview?.(state.customPreviewState, state.ctx);
165
- const { renderMeasurementStamp, selection } = props;
174
+ const { renderMeasurementStamp, onMeasurementStampPress, selection } = props;
166
175
  return (_jsxs("div", { ref: containerRef, style: containerStyle, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onPointerUp: handlePointerUp, onPointerCancel: handlePointerCancel, onWheel: handleWheel, onContextMenu: handleContextMenu, children: [AnnotationCanvasSkia({
167
176
  width,
168
177
  height,
169
178
  effectiveCanvas: state.effectiveCanvas,
170
179
  worldTransform: state.worldTransform,
171
- measurementsById: state.measurementsById,
172
- fallbackUnit,
173
- fractionalTolerance,
174
- decimalTolerance,
175
180
  resolveImageUrl,
176
181
  valueFont,
177
- labelFont,
178
- hideMeasurementStamps: !!renderMeasurementStamp,
179
182
  penDrawingStroke: state.penDrawingStroke,
183
+ // Endpoint handles on the selected line annotation. Web drives endpoint
184
+ // drag through selectTool's pointer handlers (preview patches update the
185
+ // line, so the handles follow via re-render); no live geometry needed.
186
+ selectedId: selection?.ids[0] ?? null,
187
+ handleRadius: HANDLE_PX / state.viewport.zoom,
180
188
  customPreview,
181
189
  }), renderMeasurementStamp && (_jsx("div", { style: {
182
190
  position: 'absolute',
@@ -187,6 +195,9 @@ export const AnnotationCanvasInner = (props) => {
187
195
  const cx = (placed.anchor.x - state.viewport.pan.x) * state.viewport.zoom;
188
196
  const cy = (placed.anchor.y - state.viewport.pan.y) * state.viewport.zoom;
189
197
  const isSelected = selection?.ids.includes(placed.id) ?? false;
198
+ const measurement = placed.measurementId
199
+ ? (state.measurementsById.get(placed.measurementId) ?? null)
200
+ : null;
190
201
  return (_jsxs("div", { style: {
191
202
  position: 'absolute',
192
203
  left: 0,
@@ -196,16 +207,24 @@ export const AnnotationCanvasInner = (props) => {
196
207
  transform: `translate(${cx - size / 2}px, ${cy - size / 2}px)`,
197
208
  }, children: [renderMeasurementStamp({
198
209
  placed,
199
- measurement: state.measurementsById.get(placed.measurementId) ?? null,
210
+ measurement,
200
211
  selected: isSelected,
201
212
  size,
202
213
  zoom: state.viewport.zoom,
203
- }), isSelected && (_jsx("div", { role: "button", "aria-label": "Remove measurement", onPointerDown: (e) => {
214
+ }), onMeasurementStampPress && (_jsx("button", { "aria-label": "Open measurement", onPointerDown: (e) => e.stopPropagation(), onClick: () => onMeasurementStampPress(placed), style: {
215
+ position: 'absolute',
216
+ inset: 0,
217
+ pointerEvents: 'auto',
218
+ cursor: 'pointer',
219
+ background: 'transparent',
220
+ border: 'none',
221
+ padding: 0,
222
+ } })), isSelected && measurement && (_jsx("div", { role: "button", "aria-label": "Remove measurement", onPointerDown: (e) => {
204
223
  e.stopPropagation();
205
- state.ctx.commit({
206
- ops: [{ op: 'removeMeasurement', id: placed.id }],
207
- });
208
- state.ctx.setSelection(null);
224
+ const { ops, keepSelection } = buildRemoveMeasurementOps(placed);
225
+ state.ctx.commit({ ops });
226
+ if (!keepSelection)
227
+ state.ctx.setSelection(null);
209
228
  }, style: {
210
229
  position: 'absolute',
211
230
  top: -10,
@@ -1,10 +1,10 @@
1
1
  import { type MutableRefObject } from 'react';
2
2
  import { type ViewStyle } from 'react-native';
3
3
  import type { RenderMeasurementStamp } from './measurementStampOverlay.js';
4
- import type { DecimalTolerance, FractionalTolerance, Measurement, Units } from '../types/firestore.js';
5
- import type { AnnotationCanvasState, AnnotationDocumentPatch, Selection } from '../types/annotation.js';
4
+ import type { DecimalTolerance, FractionalTolerance, Measurement, Units } from '../../types/firestore.js';
5
+ import { type AnnotationCanvasState, type AnnotationDocumentPatch, type PlacedMeasurementRef, type Selection } from '../../types/annotation.js';
6
6
  import type { MeasurementRef } from './measurementPicker.js';
7
- import type { Tool } from './Tool.js';
7
+ import type { RequestTextInput, Tool } from './Tool.js';
8
8
  import { type AnnotationCanvasHandle } from './useAnnotationCanvasState.js';
9
9
  import type { ViewportState } from './viewport.js';
10
10
  export type { AnnotationCanvasHandle };
@@ -21,7 +21,9 @@ export interface AnnotationCanvasInnerProps {
21
21
  decimalTolerance?: DecimalTolerance;
22
22
  resolveImageUrl?: (storagePath: string) => Promise<string>;
23
23
  pickMeasurement?: () => Promise<MeasurementRef | null>;
24
+ requestTextInput?: RequestTextInput;
24
25
  renderMeasurementStamp?: RenderMeasurementStamp;
26
+ onMeasurementStampPress?: (placed: PlacedMeasurementRef) => void;
25
27
  stampFontSource?: unknown;
26
28
  stampValueFontSize?: number;
27
29
  stampLabelFontSize?: number;