@reekon-tools/boldr-utils 1.6.34 → 1.6.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/annotation/canvas/stampLayout.d.ts +2 -0
- package/dist/annotation/canvas/stampLayout.js +18 -0
- package/dist/annotation/canvas/useAnnotationCanvasState.d.ts +2 -0
- package/dist/annotation/canvas/useAnnotationCanvasState.js +42 -5
- package/dist/canvas/AnnotationCanvas.d.ts +11 -0
- package/dist/canvas/AnnotationCanvas.js +10 -0
- package/dist/canvas/AnnotationCanvas.native.d.ts +8 -0
- package/dist/canvas/AnnotationCanvas.native.js +6 -0
- package/dist/canvas/AnnotationCanvasInner.d.ts +39 -0
- package/dist/canvas/AnnotationCanvasInner.js +219 -0
- package/dist/canvas/AnnotationCanvasInner.native.d.ts +35 -0
- package/dist/canvas/AnnotationCanvasInner.native.js +138 -0
- package/dist/canvas/AnnotationCanvasSkia.d.ts +27 -0
- package/dist/canvas/AnnotationCanvasSkia.js +20 -0
- package/dist/canvas/Tool.d.ts +38 -0
- package/dist/canvas/Tool.js +1 -0
- package/dist/canvas/elements/BackgroundImageElement.d.ts +9 -0
- package/dist/canvas/elements/BackgroundImageElement.js +37 -0
- package/dist/canvas/elements/MeasurementStampElement.d.ts +13 -0
- package/dist/canvas/elements/MeasurementStampElement.js +30 -0
- package/dist/canvas/elements/ShapeElement.d.ts +7 -0
- package/dist/canvas/elements/ShapeElement.js +62 -0
- package/dist/canvas/elements/StrokeElement.d.ts +7 -0
- package/dist/canvas/elements/StrokeElement.js +18 -0
- package/dist/canvas/measurementPicker.d.ts +10 -0
- package/dist/canvas/measurementPicker.js +1 -0
- package/dist/canvas/measurementStampOverlay.d.ts +11 -0
- package/dist/canvas/measurementStampOverlay.js +1 -0
- package/dist/canvas/pointerAdapter.d.ts +3 -0
- package/dist/canvas/pointerAdapter.js +19 -0
- package/dist/canvas/stampLayout.d.ts +5 -0
- package/dist/canvas/stampLayout.js +14 -0
- package/dist/canvas/tools/measurementStampTool.d.ts +9 -0
- package/dist/canvas/tools/measurementStampTool.js +37 -0
- package/dist/canvas/tools/panTool.d.ts +5 -0
- package/dist/canvas/tools/panTool.js +25 -0
- package/dist/canvas/tools/penTool.d.ts +13 -0
- package/dist/canvas/tools/penTool.js +68 -0
- package/dist/canvas/tools/selectTool.d.ts +2 -0
- package/dist/canvas/tools/selectTool.js +182 -0
- package/dist/canvas/useAnnotationCanvasState.d.ts +54 -0
- package/dist/canvas/useAnnotationCanvasState.js +210 -0
- package/dist/canvas/viewport.d.ts +16 -0
- package/dist/canvas/viewport.js +54 -0
- package/dist/data/AnnotationDataContext.d.ts +8 -0
- package/dist/data/AnnotationDataContext.js +11 -0
- package/dist/data/AnnotationDataProvider.d.ts +65 -0
- package/dist/data/AnnotationDataProvider.js +4 -0
- package/dist/data/InMemoryAnnotationProvider.d.ts +30 -0
- package/dist/data/InMemoryAnnotationProvider.js +197 -0
- package/dist/data/canvasPersistence.d.ts +3 -0
- package/dist/data/canvasPersistence.js +26 -0
- package/dist/data/hooks/useAnnotationCanvasDoc.d.ts +33 -0
- package/dist/data/hooks/useAnnotationCanvasDoc.js +314 -0
- package/dist/data/hooks/useAnnotationDoc.d.ts +7 -0
- package/dist/data/hooks/useAnnotationDoc.js +33 -0
- package/dist/data/hooks/useAnnotationList.d.ts +7 -0
- package/dist/data/hooks/useAnnotationList.js +26 -0
- package/dist/data/hooks/useAnnotationMutations.d.ts +9 -0
- package/dist/data/hooks/useAnnotationMutations.js +11 -0
- package/dist/exports.d.ts +1 -1
- package/dist/exports.js +1 -1
- package/dist/hooks/useParseMeasurement.d.ts +4 -0
- package/dist/hooks/useParseMeasurement.js +14 -0
- package/dist/types/annotation.d.ts +4 -0
- package/dist/types/annotation.js +12 -0
- package/dist/utils/evaluateFormula.d.ts +20 -0
- package/dist/utils/evaluateFormula.js +31 -0
- package/package.json +2 -1
- package/dist/annotation/canvas/tools/measurementLineTool.d.ts +0 -12
- package/dist/annotation/canvas/tools/measurementLineTool.js +0 -95
package/dist/exports.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type { GestureConfig, PanTrigger, AnnotationCanvasInnerProps, } from './a
|
|
|
23
23
|
export type { CanvasPointerEvent, RequestTextInput, ShapeDrawConfig, Tool, ToolContext, ToolState, } from './annotation/canvas/Tool.js';
|
|
24
24
|
export type { MeasurementRef, PickMeasurement, } from './annotation/canvas/measurementPicker.js';
|
|
25
25
|
export type { MeasurementStampRenderArgs, RenderMeasurementStamp, } from './annotation/canvas/measurementStampOverlay.js';
|
|
26
|
-
export { STAMP_TILE_SIZE, DEFAULT_TILE_SCALE, TILE_SCALE_MIN, TILE_SCALE_MAX, clampTileScale, resolveTileScaleFactor, stampTileSize, isUnassociatedStamp, } from './annotation/canvas/stampLayout.js';
|
|
26
|
+
export { STAMP_TILE_SIZE, DEFAULT_TILE_SCALE, TILE_SCALE_MIN, TILE_SCALE_MAX, clampTileScale, resolveTileScaleFactor, tileDocSizeForFactor, tileScaleFromDocSize, stampTileSize, isUnassociatedStamp, } from './annotation/canvas/stampLayout.js';
|
|
27
27
|
export { createViewportApi, fitToScreen, fitRectToScreen, imageDocRect, panBy, zoomAt, DEFAULT_VIEWPORT, type ViewportApi, type ViewportState, } from './annotation/canvas/viewport.js';
|
|
28
28
|
export { createPenTool, type PenToolOptions, } from './annotation/canvas/tools/penTool.js';
|
|
29
29
|
export { createSelectTool, type SelectToolOptions, } from './annotation/canvas/tools/selectTool.js';
|
package/dist/exports.js
CHANGED
|
@@ -23,7 +23,7 @@ export { useAnnotationMutations, } from './annotation/data/hooks/useAnnotationMu
|
|
|
23
23
|
export { useAnnotationCanvasDoc, } from './annotation/data/hooks/useAnnotationCanvasDoc.js';
|
|
24
24
|
export { hydrateCanvasState } from './annotation/data/canvasPersistence.js';
|
|
25
25
|
export { InMemoryAnnotationProvider } from './annotation/data/InMemoryAnnotationProvider.js';
|
|
26
|
-
export { STAMP_TILE_SIZE, DEFAULT_TILE_SCALE, TILE_SCALE_MIN, TILE_SCALE_MAX, clampTileScale, resolveTileScaleFactor, stampTileSize, isUnassociatedStamp, } from './annotation/canvas/stampLayout.js';
|
|
26
|
+
export { STAMP_TILE_SIZE, DEFAULT_TILE_SCALE, TILE_SCALE_MIN, TILE_SCALE_MAX, clampTileScale, resolveTileScaleFactor, tileDocSizeForFactor, tileScaleFromDocSize, stampTileSize, isUnassociatedStamp, } from './annotation/canvas/stampLayout.js';
|
|
27
27
|
export { createViewportApi, fitToScreen, fitRectToScreen, imageDocRect, panBy, zoomAt, DEFAULT_VIEWPORT, } from './annotation/canvas/viewport.js';
|
|
28
28
|
export { createPenTool, } from './annotation/canvas/tools/penTool.js';
|
|
29
29
|
export { createSelectTool, } from './annotation/canvas/tools/selectTool.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { parseMeasurement } from '../utils/parseMeasurement.js';
|
|
3
|
+
export const useParseMeasurement = () => {
|
|
4
|
+
const [error, setError] = useState(null);
|
|
5
|
+
const parseMeasurementInput = (input, defaultUnit = 'mm') => {
|
|
6
|
+
setError(null);
|
|
7
|
+
const result = parseMeasurement(input, defaultUnit);
|
|
8
|
+
if (result === null) {
|
|
9
|
+
setError('Invalid measurement. Please provide a valid number and unit.');
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
return { parseMeasurementInput, error };
|
|
14
|
+
};
|
|
@@ -111,6 +111,7 @@ export interface AnnotationCanvasState {
|
|
|
111
111
|
placedMeasurements: PlacedMeasurementRef[];
|
|
112
112
|
tileScaleFactor?: number;
|
|
113
113
|
tileScaleFactorMobile?: number;
|
|
114
|
+
tileDocSize?: number;
|
|
114
115
|
externalPayloadPath?: string;
|
|
115
116
|
}
|
|
116
117
|
export type AnnotationElement = (AnnotationStroke & {
|
|
@@ -160,6 +161,9 @@ export type AnnotationPatchOp = {
|
|
|
160
161
|
op: 'setTileScaleFactor';
|
|
161
162
|
value: number;
|
|
162
163
|
platform?: TileScalePlatform;
|
|
164
|
+
} | {
|
|
165
|
+
op: 'setTileDocSize';
|
|
166
|
+
value: number;
|
|
163
167
|
} | {
|
|
164
168
|
op: 'setLayers';
|
|
165
169
|
layers: AnnotationLayer[];
|
package/dist/types/annotation.js
CHANGED
|
@@ -77,6 +77,10 @@ const applyOp = (state, op) => {
|
|
|
77
77
|
return op.platform === 'mobile'
|
|
78
78
|
? { ...state, tileScaleFactorMobile: op.value }
|
|
79
79
|
: { ...state, tileScaleFactor: op.value };
|
|
80
|
+
case 'setTileDocSize':
|
|
81
|
+
// Guard nonsense values (a zero/negative doc size would derive a
|
|
82
|
+
// zero/negative mobile factor) — keep the existing calibration instead.
|
|
83
|
+
return op.value > 0 ? { ...state, tileDocSize: op.value } : state;
|
|
80
84
|
case 'setLayers':
|
|
81
85
|
return { ...state, layers: op.layers };
|
|
82
86
|
}
|
|
@@ -163,6 +167,14 @@ const invertOp = (before, op) => {
|
|
|
163
167
|
: before.tileScaleFactor) ?? 1,
|
|
164
168
|
...(op.platform && { platform: op.platform }),
|
|
165
169
|
};
|
|
170
|
+
case 'setTileDocSize':
|
|
171
|
+
// Restore the prior calibration when there was one. A doc that never
|
|
172
|
+
// had a calibration can't be reverted to "absent" through this op
|
|
173
|
+
// (applyOp ignores non-positive values), so the stamp survives undo —
|
|
174
|
+
// benign, since it still describes what the web user last saw.
|
|
175
|
+
return before.tileDocSize != null && before.tileDocSize > 0
|
|
176
|
+
? { op: 'setTileDocSize', value: before.tileDocSize }
|
|
177
|
+
: null;
|
|
166
178
|
case 'setLayers':
|
|
167
179
|
return { op: 'setLayers', layers: before.layers };
|
|
168
180
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type MeasurementMap = Map<string, {
|
|
2
|
+
id: string;
|
|
3
|
+
value: number;
|
|
4
|
+
}[]>;
|
|
5
|
+
interface FormulaEvaluationOptions {
|
|
6
|
+
expression: string;
|
|
7
|
+
mappings: Record<string, string>;
|
|
8
|
+
group: {
|
|
9
|
+
id: string;
|
|
10
|
+
columns: Map<string, any>;
|
|
11
|
+
};
|
|
12
|
+
columns: {
|
|
13
|
+
id: string;
|
|
14
|
+
type: string;
|
|
15
|
+
}[];
|
|
16
|
+
measurementMap: MeasurementMap;
|
|
17
|
+
defaultUnit?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function evaluateFormula({ expression, mappings, group, columns, measurementMap, defaultUnit, }: FormulaEvaluationOptions): number | string;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { create, all } from 'mathjs';
|
|
2
|
+
const math = create(all);
|
|
3
|
+
export function evaluateFormula({ expression, mappings, group, columns, measurementMap, defaultUnit = 'um', }) {
|
|
4
|
+
const scope = {};
|
|
5
|
+
for (const [variable, columnId] of Object.entries(mappings)) {
|
|
6
|
+
const rawValue = group.columns.get(columnId);
|
|
7
|
+
const columnDef = columns.find((c) => c.id === columnId);
|
|
8
|
+
if (columnDef?.type === 'Measurement') {
|
|
9
|
+
const groupMeasurements = measurementMap.get(group.id) || [];
|
|
10
|
+
const measurement = groupMeasurements.find((m) => m.id === rawValue);
|
|
11
|
+
if (measurement?.value !== undefined) {
|
|
12
|
+
scope[variable] = math.unit(measurement.value, defaultUnit);
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const parsedValue = typeof rawValue === 'number' ? rawValue : parseFloat(rawValue || '');
|
|
17
|
+
scope[variable] = isNaN(parsedValue) ? 0 : parsedValue;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const compiled = math.compile(expression);
|
|
21
|
+
const result = compiled.evaluate(scope);
|
|
22
|
+
if (math.typeOf(result) === 'Unit') {
|
|
23
|
+
return result.toNumber(defaultUnit);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.error(`Formula evaluation failed:`, err);
|
|
29
|
+
return 'Error';
|
|
30
|
+
}
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reekon-tools/boldr-utils",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.35",
|
|
4
4
|
"description": "Shared utilities for formulas and measurement conversion used in Reekon apps",
|
|
5
5
|
"author": "REEKON Tools",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsc",
|
|
26
26
|
"prepack": "yarn run build",
|
|
27
|
+
"sync:local": "./scripts/sync-local.sh",
|
|
27
28
|
"test": "vitest",
|
|
28
29
|
"coverage": "vitest run --coverage",
|
|
29
30
|
"format": "prettier --write .",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { PlacedMeasurementRef } from '../../../types/annotation.js';
|
|
2
|
-
import type { Tool } from '../Tool.js';
|
|
3
|
-
export interface MeasurementLineToolOptions {
|
|
4
|
-
id?: string;
|
|
5
|
-
label?: string;
|
|
6
|
-
minDragPx?: number;
|
|
7
|
-
autoSwitchToSelect?: boolean;
|
|
8
|
-
selectToolId?: string;
|
|
9
|
-
onAutoSwitch?: (toToolId: string) => void;
|
|
10
|
-
onPlaced?: (measurement: PlacedMeasurementRef) => void;
|
|
11
|
-
}
|
|
12
|
-
export declare const createMeasurementLineTool: (options?: MeasurementLineToolOptions) => Tool;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_LAYER_ID } from '../../../types/annotation.js';
|
|
2
|
-
import { DEFAULT_LINE_POS, recomputeAnchor } from '../measurementGeometry.js';
|
|
3
|
-
let counter = 0;
|
|
4
|
-
const makeId = () => `annotation-${Date.now().toString(36)}-${(counter++).toString(36)}`;
|
|
5
|
-
const firstLayerId = (doc) => doc.layers[0]?.id ?? DEFAULT_LAYER_ID;
|
|
6
|
-
// Build the blank line-measurement annotation for a drag from `a` to `b`: a
|
|
7
|
-
// 2-point line with a value tile magnetized to its center (linePos 0.5). The
|
|
8
|
-
// payload mirrors useAnnotationCanvasState's placeAnnotationAtCenter so a drawn
|
|
9
|
-
// line and a (legacy) center-placed one are byte-identical once committed.
|
|
10
|
-
const buildLineMeasurement = (opts) => {
|
|
11
|
-
const line = { a: opts.a, b: opts.b };
|
|
12
|
-
return {
|
|
13
|
-
id: opts.id,
|
|
14
|
-
layerId: opts.layerId,
|
|
15
|
-
placement: 'line',
|
|
16
|
-
line,
|
|
17
|
-
linePos: DEFAULT_LINE_POS,
|
|
18
|
-
// Center of the line; recomputeAnchor keeps this in sync on edits.
|
|
19
|
-
anchor: recomputeAnchor(line, 'line', DEFAULT_LINE_POS, {
|
|
20
|
-
x: (opts.a.x + opts.b.x) / 2,
|
|
21
|
-
y: (opts.a.y + opts.b.y) / 2,
|
|
22
|
-
}),
|
|
23
|
-
showLabel: true,
|
|
24
|
-
showValue: true,
|
|
25
|
-
createdAt: Date.now(),
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
// Drag-to-draw measurement-line tool. Press-drag rubber-bands a measurement
|
|
29
|
-
// annotation (a line with a blank value tile at its center); release commits
|
|
30
|
-
// it. Mirrors createShapeTool's interaction so "input lines" are placed the
|
|
31
|
-
// same way as shapes — draw to add, not tap-the-icon-to-add — replacing the
|
|
32
|
-
// old center-place affordance. The annotation stays blank (no measurement
|
|
33
|
-
// associated) until the user fills it via the tile / picker. Skia-free, like
|
|
34
|
-
// every tool factory; it renders its live preview through ctx.preview, so it
|
|
35
|
-
// works on web and (via the generic tool-pan dispatch) on native.
|
|
36
|
-
export const createMeasurementLineTool = (options = {}) => {
|
|
37
|
-
const minDragPx = options.minDragPx ?? 4;
|
|
38
|
-
const autoSwitchToSelect = options.autoSwitchToSelect ?? true;
|
|
39
|
-
const selectToolId = options.selectToolId ?? 'select';
|
|
40
|
-
return {
|
|
41
|
-
id: options.id ?? 'measure-line',
|
|
42
|
-
label: options.label ?? 'Measurement line',
|
|
43
|
-
cursor: 'crosshair',
|
|
44
|
-
onPointerDown(event) {
|
|
45
|
-
return {
|
|
46
|
-
kind: 'measurement-line-drawing',
|
|
47
|
-
id: makeId(),
|
|
48
|
-
startWorld: event.world,
|
|
49
|
-
startScreen: event.screen,
|
|
50
|
-
moved: false,
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
onPointerMove(event, ctx, state) {
|
|
54
|
-
const s = state;
|
|
55
|
-
if (s?.kind !== 'measurement-line-drawing')
|
|
56
|
-
return s;
|
|
57
|
-
const measurement = buildLineMeasurement({
|
|
58
|
-
id: s.id,
|
|
59
|
-
layerId: firstLayerId(ctx.document),
|
|
60
|
-
a: s.startWorld,
|
|
61
|
-
b: event.world,
|
|
62
|
-
});
|
|
63
|
-
ctx.preview({ ops: [{ op: 'addMeasurement', measurement }] });
|
|
64
|
-
return { ...s, moved: true };
|
|
65
|
-
},
|
|
66
|
-
onPointerUp(event, ctx, state) {
|
|
67
|
-
const s = state;
|
|
68
|
-
if (s?.kind !== 'measurement-line-drawing')
|
|
69
|
-
return;
|
|
70
|
-
const dx = event.screen.x - s.startScreen.x;
|
|
71
|
-
const dy = event.screen.y - s.startScreen.y;
|
|
72
|
-
if (!s.moved || dx * dx + dy * dy < minDragPx * minDragPx) {
|
|
73
|
-
// Accidental tap — discard the rubber-band, commit nothing.
|
|
74
|
-
ctx.preview({ ops: [] });
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const measurement = buildLineMeasurement({
|
|
78
|
-
id: s.id,
|
|
79
|
-
layerId: firstLayerId(ctx.document),
|
|
80
|
-
a: s.startWorld,
|
|
81
|
-
b: event.world,
|
|
82
|
-
});
|
|
83
|
-
ctx.commit({ ops: [{ op: 'addMeasurement', measurement }] });
|
|
84
|
-
// Leave it selected (and hand back to select) so the blank line can be
|
|
85
|
-
// filled / moved straight away — the same flow as the text tool.
|
|
86
|
-
ctx.setSelection({ ids: [measurement.id] });
|
|
87
|
-
options.onPlaced?.(measurement);
|
|
88
|
-
if (autoSwitchToSelect)
|
|
89
|
-
options.onAutoSwitch?.(selectToolId);
|
|
90
|
-
},
|
|
91
|
-
onCancel(_state, ctx) {
|
|
92
|
-
ctx.preview({ ops: [] });
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
};
|