@weasel-js/measure 0.0.0-stage → 1.19.1
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/LICENSE +21 -0
- package/README.md +31 -2
- package/dist/index.d.ts +195 -0
- package/dist/index.js +558 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 orochi235
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @weasel-js/measure
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Measuring for a weasel canvas. A measurement is a scene node on an annotation
|
|
4
|
+
layer, so it saves and undoes with the document and stays out of export and
|
|
5
|
+
content picking. The measure tool draws one per drag; under every tool a click
|
|
6
|
+
picks one, a drag moves it or one of its ends, and Move by and Rotate by carry
|
|
7
|
+
the selection by the picked measurement.
|
|
8
|
+
|
|
9
|
+
Part of [weasel](https://github.com/orochi235/weasel), a domain-agnostic
|
|
10
|
+
scene-graph engine for React. See the
|
|
11
|
+
[API reference](https://orochi235.github.io/weasel/#pkg/measure).
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @weasel-js/measure
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## On a canvas
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
const [measurements] = useState(() => createMeasurements({ layer: 'notes' }));
|
|
21
|
+
const tools = useMeasureTools({ measurements });
|
|
22
|
+
const ambient = useMemo(() => [measurementsContribution(scene, measurements)], [scene, measurements]);
|
|
23
|
+
|
|
24
|
+
<SceneCanvas scene={scene} tools={[tools.measure]} ambient={ambient} snap={{ sources: [measureEndSource()] }} />
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`notes` is a layer the scene declares with `annotation: true`. The contribution
|
|
28
|
+
registers the painter that draws measurements in the scene's own node shapes
|
|
29
|
+
(`nodeShapesOf(scene)`), the layer that shows the picked one, and the
|
|
30
|
+
commands, which `MEASURE_ACTION_IDS` names and `<MeasureReadout>` in
|
|
31
|
+
`@weasel-js/ui` binds buttons to. `MEASURE_TOOLS` names the tool for a palette.
|
|
32
|
+
A render with no canvas registers `MEASURE_PAINTER` itself.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { NodeId, SceneNode, ScopedScene, MarkNode, RectPose, Scene, SnapSource, SurfaceContribution, NodeShapeEntry, Tool, ToolSet } from '@weasel-js/core';
|
|
2
|
+
import { Point } from '@weasel-js/geom';
|
|
3
|
+
import { ValueStore } from '@weasel-js/registry';
|
|
4
|
+
import { ToolKeybinding } from '@weasel-js/routing';
|
|
5
|
+
|
|
6
|
+
/** A world-space point. */
|
|
7
|
+
type MeasurePoint = Point;
|
|
8
|
+
/**
|
|
9
|
+
* The frame each end of a measurement landed in: the node declaring a unit
|
|
10
|
+
* scope it was placed inside (`unitFrameAt`), or `null` for the top of the
|
|
11
|
+
* tree. The measurement reads in the scope chain the two frames share, so ends
|
|
12
|
+
* in one frame, or in frames declaring equal scopes, read that frame's
|
|
13
|
+
* modeled length, and ends whose frames disagree read the innermost frame
|
|
14
|
+
* holding both, which is world when only the root does.
|
|
15
|
+
*/
|
|
16
|
+
interface MeasureFrames {
|
|
17
|
+
readonly start: NodeId | null;
|
|
18
|
+
readonly end: NodeId | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The offset from `start` to `end`, in world units. `dx` and `dy` are on the
|
|
22
|
+
* world's own axes, where y grows downward; `angle` reads like a protractor
|
|
23
|
+
* instead, counterclockwise-positive on screen, so a line rising up and to
|
|
24
|
+
* the right at 30° reads +30°. The canvas's own rotations are
|
|
25
|
+
* clockwise-positive: a rotate that follows the line turns by `-angle`.
|
|
26
|
+
*/
|
|
27
|
+
interface Measurement {
|
|
28
|
+
readonly start: MeasurePoint;
|
|
29
|
+
readonly end: MeasurePoint;
|
|
30
|
+
readonly dx: number;
|
|
31
|
+
readonly dy: number;
|
|
32
|
+
readonly distance: number;
|
|
33
|
+
/** `atan2(-dy, dx)`, in `(-π, π]`. Zero for a zero-length measurement. */
|
|
34
|
+
readonly angle: number;
|
|
35
|
+
/** The frames its ends landed in. Absent, it reads in world. */
|
|
36
|
+
readonly frames?: MeasureFrames;
|
|
37
|
+
}
|
|
38
|
+
/** Measure from `start` to `end`, landed in `frames`. */
|
|
39
|
+
declare function measureBetween(start: MeasurePoint, end: MeasurePoint, frames?: MeasureFrames): Measurement;
|
|
40
|
+
/** How large the frame `frames` share is drawn in world: a measurement's
|
|
41
|
+
* world lengths divided by it are its modeled lengths. 1 without frames. */
|
|
42
|
+
declare function measureMagnification(scene: ScopedScene, frames: MeasureFrames | undefined): number;
|
|
43
|
+
/** What a measurement node keeps in `data`: its two ends, in world units, and
|
|
44
|
+
* the frames they landed in. A `label` beside it names the node in a layer
|
|
45
|
+
* list. */
|
|
46
|
+
interface MeasureData {
|
|
47
|
+
measure: {
|
|
48
|
+
start: MeasurePoint;
|
|
49
|
+
end: MeasurePoint;
|
|
50
|
+
frames?: MeasureFrames;
|
|
51
|
+
};
|
|
52
|
+
label?: string;
|
|
53
|
+
}
|
|
54
|
+
/** Where an end placed at a world point lands: what `unitFrameAt` builds. */
|
|
55
|
+
type MeasureFrameAt = (p: MeasurePoint) => NodeId | null;
|
|
56
|
+
/** Which end of a measurement. */
|
|
57
|
+
type MeasureEnd = 'start' | 'end';
|
|
58
|
+
/** The ends `node` measures between, or null when it is not a measurement. */
|
|
59
|
+
declare function measureEndsOf(node: Pick<SceneNode<unknown, string, unknown>, 'data'> | undefined): MeasureData['measure'] | null;
|
|
60
|
+
/** The measurement `node` holds, or null when it is not one. */
|
|
61
|
+
declare function measurementOf(node: Pick<SceneNode<unknown, string, unknown>, 'data'> | undefined): Measurement | null;
|
|
62
|
+
/** The box a measurement's pose holds: its two ends' bounds, which is what
|
|
63
|
+
* culling, area queries, and fitting the view read. */
|
|
64
|
+
declare function measurePose(start: MeasurePoint, end: MeasurePoint): RectPose;
|
|
65
|
+
/** A measurement node on `layer`, ready to insert, or to list in a scene's
|
|
66
|
+
* `initial` nodes: typed with that layer and a `RectPose`. */
|
|
67
|
+
declare function measureNode<TLayer extends string>(id: NodeId, layer: TLayer, start: MeasurePoint, end: MeasurePoint, frames?: MeasureFrames): MarkNode<MeasureData, TLayer, RectPose>;
|
|
68
|
+
|
|
69
|
+
/** One value, readable and watchable — what a readout re-renders from. */
|
|
70
|
+
type MeasureCell<T> = ValueStore<T>;
|
|
71
|
+
/**
|
|
72
|
+
* Where a scene's measurements go, and the state around them that is not
|
|
73
|
+
* the document's: which one is picked, and the one a measure drag is still
|
|
74
|
+
* drawing. The measurements themselves are nodes on `layer`, an annotation
|
|
75
|
+
* layer (`isAnnotationLayer`), so they save with the scene, undo with it,
|
|
76
|
+
* and stay out of export and content picking.
|
|
77
|
+
*
|
|
78
|
+
* The pick sits beside the content selection rather than in it: picking a
|
|
79
|
+
* measurement leaves the selection alone, so Move by can carry the selection
|
|
80
|
+
* by the picked measurement.
|
|
81
|
+
*/
|
|
82
|
+
interface Measurements {
|
|
83
|
+
/** The annotation layer new measurements are added to. */
|
|
84
|
+
readonly layer: string;
|
|
85
|
+
/** The picked measurement's id. */
|
|
86
|
+
readonly picked: MeasureCell<NodeId | null>;
|
|
87
|
+
/** The measurement a measure drag is drawing, before it is added. */
|
|
88
|
+
readonly draft: MeasureCell<Measurement | null>;
|
|
89
|
+
/** Whether the measure tool is active, which changes what a press on a
|
|
90
|
+
* measurement does: under it, only the picked one's ends take a drag, so a
|
|
91
|
+
* drag from anywhere else starts a new measurement. */
|
|
92
|
+
readonly measuring: MeasureCell<boolean>;
|
|
93
|
+
}
|
|
94
|
+
/** The measurements on `layer`, none picked and none in progress. */
|
|
95
|
+
declare function createMeasurements(options: {
|
|
96
|
+
layer: string;
|
|
97
|
+
}): Measurements;
|
|
98
|
+
/** The measurement nodes on `ms.layer`, oldest first. */
|
|
99
|
+
declare function measureIds(scene: Pick<Scene<unknown, string, unknown>, 'nodesOnLayer'>, ms: Pick<Measurements, 'layer'>): NodeId[];
|
|
100
|
+
/** The measurement commands act on: the picked one while it is still in the
|
|
101
|
+
* scene, else the newest. */
|
|
102
|
+
declare function currentMeasureId(scene: Pick<Scene<unknown, string, unknown>, 'nodesOnLayer' | 'get'>, ms: Pick<Measurements, 'layer' | 'picked'>): NodeId | null;
|
|
103
|
+
|
|
104
|
+
/** Which part of which measurement lies under a point. */
|
|
105
|
+
interface MeasureHit {
|
|
106
|
+
id: NodeId;
|
|
107
|
+
part: MeasureEnd | 'line';
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The measurement under `p`, newest first: an end within `tolerance` world
|
|
111
|
+
* units of it, else a line within the same distance. A hidden or locked
|
|
112
|
+
* measurement (`nodeGates`) is passed over.
|
|
113
|
+
*/
|
|
114
|
+
declare function measureAt(scene: Pick<Scene<unknown, string, unknown>, 'nodesOnLayer' | 'get' | 'layers' | 'overrides'>, ms: Pick<Measurements, 'layer'>, p: MeasurePoint, tolerance: number): MeasureHit | null;
|
|
115
|
+
/** Options for `measureEndSource`. */
|
|
116
|
+
interface MeasureEndSourceOptions {
|
|
117
|
+
/** Overrides the canvas's reach for measurement ends, in screen px. */
|
|
118
|
+
reachPx?: number;
|
|
119
|
+
}
|
|
120
|
+
/** The ends of every shown measurement as snap targets for a pointer probe. */
|
|
121
|
+
declare function measureEndSource(opts?: MeasureEndSourceOptions): SnapSource;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A scene's measurements on a canvas, whatever tool is active: the painter
|
|
125
|
+
* that draws them, the layer that shows the picked one and claims presses on measurements, a click on
|
|
126
|
+
* one to pick it and a drag to edit it, and the commands — Move by, Rotate
|
|
127
|
+
* by, Delete, Clear — a readout binds buttons to. Install it with
|
|
128
|
+
* `<SceneCanvas ambient={[…]}>`; `useMeasureTool` adds the measuring itself.
|
|
129
|
+
*/
|
|
130
|
+
declare function measurementsContribution(scene: Scene<unknown, string, unknown>, ms: Measurements): SurfaceContribution;
|
|
131
|
+
|
|
132
|
+
/** The ids of the measure feature's actions. */
|
|
133
|
+
declare const MEASURE_ACTION_IDS: {
|
|
134
|
+
/** The measure tool's drag, which adds a measurement. */
|
|
135
|
+
readonly measure: "measure";
|
|
136
|
+
/** The measure tool's click, which picks the measurement under it. */
|
|
137
|
+
readonly pickAt: "measure.pickAt";
|
|
138
|
+
/** A click on a measurement under any tool, which picks it. */
|
|
139
|
+
readonly pick: "measure.pick";
|
|
140
|
+
/** A drag on a measurement under any tool: a picked end moves that end, the
|
|
141
|
+
* rest moves the whole measurement. */
|
|
142
|
+
readonly drag: "measure.drag";
|
|
143
|
+
readonly moveBy: "measure.moveBy";
|
|
144
|
+
readonly rotateBy: "measure.rotateBy";
|
|
145
|
+
readonly delete: "measure.delete";
|
|
146
|
+
readonly clear: "measure.clear";
|
|
147
|
+
readonly unpick: "measure.unpick";
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/** The registered layer's id; a press it claims routes as `layer:<id>`. */
|
|
151
|
+
declare const MEASURE_LAYER_ID = "weasel-measure";
|
|
152
|
+
/** The affordance kind a press on a measurement routes under. */
|
|
153
|
+
declare const MEASURE_AFFORDANCE_KIND = "layer:weasel-measure";
|
|
154
|
+
|
|
155
|
+
/** Paints a measurement node — `data.measure`, in world units — in the
|
|
156
|
+
* canvas's measure color. It has no silhouette: a measurement is not content
|
|
157
|
+
* to pick. `measurementsContribution` registers it for its scene; a render
|
|
158
|
+
* with no canvas registers it itself (`nodeShapesOf(scene).register`). */
|
|
159
|
+
declare const MEASURE_PAINTER: NodeShapeEntry;
|
|
160
|
+
|
|
161
|
+
/** Options for `useMeasureTool`. */
|
|
162
|
+
interface UseMeasureToolOptions {
|
|
163
|
+
/** Where the measurements go and which one is picked — the same object the
|
|
164
|
+
* canvas's `measurementsContribution` and a readout are given. */
|
|
165
|
+
measurements: Measurements;
|
|
166
|
+
/** The angle step, in radians, Shift holds a measurement to. Default 15°.
|
|
167
|
+
* Read on every pointer move, so a change mid-drag applies at once. */
|
|
168
|
+
angleStep?: number;
|
|
169
|
+
/** Override the default keybinding (`{ key: 'M' }`). Pass `null` to omit. */
|
|
170
|
+
keybinding?: ToolKeybinding | null;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Measure tool. A drag adds a measurement from press to release in world
|
|
174
|
+
* units — both ends through the `snap` dep, Shift holding the angle to
|
|
175
|
+
* `angleStep` — as one undo step, and picks it. A click picks the
|
|
176
|
+
* measurement under it, Escape drops the pick, and Delete removes the
|
|
177
|
+
* current measurement. The measurements are scene nodes on an annotation
|
|
178
|
+
* layer, so they stay when the tool changes; editing them under any tool,
|
|
179
|
+
* and the commands that transform by them, come from
|
|
180
|
+
* `measurementsContribution`, which the canvas installs beside this tool.
|
|
181
|
+
*/
|
|
182
|
+
declare function useMeasureTool(options: UseMeasureToolOptions): Tool;
|
|
183
|
+
|
|
184
|
+
/** The ids {@link useMeasureTools} keys its tools by. */
|
|
185
|
+
type MeasureToolId = 'measure';
|
|
186
|
+
/** Every tool `@weasel-js/measure` ships: the measure tool. */
|
|
187
|
+
declare const MEASURE_TOOLS: ToolSet<MeasureToolId>;
|
|
188
|
+
/**
|
|
189
|
+
* Every tool in {@link MEASURE_TOOLS}, keyed by id, for `<SceneCanvas tools>` beside the
|
|
190
|
+
* `measurementsContribution` whose actions they bind. `options` go to `useMeasureTool`.
|
|
191
|
+
*/
|
|
192
|
+
declare function useMeasureTools(options: UseMeasureToolOptions): Record<MeasureToolId, Tool>;
|
|
193
|
+
|
|
194
|
+
export { MEASURE_ACTION_IDS, MEASURE_AFFORDANCE_KIND, MEASURE_LAYER_ID, MEASURE_PAINTER, MEASURE_TOOLS, createMeasurements, currentMeasureId, measureAt, measureBetween, measureEndSource, measureEndsOf, measureIds, measureMagnification, measureNode, measurePose, measurementOf, measurementsContribution, useMeasureTool, useMeasureTools };
|
|
195
|
+
export type { MeasureCell, MeasureData, MeasureEnd, MeasureEndSourceOptions, MeasureFrameAt, MeasureFrames, MeasureHit, MeasurePoint, MeasureToolId, Measurement, Measurements, UseMeasureToolOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
import { toolSet, sceneMagnification, nodeGates, shownLookup, nodesAsShown, isRectPose, nodeShapesOf, defineTool, SNAP_ROLE_MODS, OVERLAY_ROLE_STROKES, SNAP_ROLES, commitOps, spanSnap, SNAP_ANGLE_STEP, snapMods, viewToTransform, transformSelection, unitFrameAt, insertAt, worldToScreen, requiresSelection, reachesLocked, deleteNode, createTransformOp, createSetDataOp } from '@weasel-js/core';
|
|
2
|
+
import { rectBetween, pointSegmentDist, polylineFromPoints, pxReach, rectPath } from '@weasel-js/geom';
|
|
3
|
+
import { createValueStore } from '@weasel-js/registry';
|
|
4
|
+
import { hitPredicate, ANY_MODS } from '@weasel-js/gestures';
|
|
5
|
+
import { defineAction, resolveParams, ActionDisabledReason } from '@weasel-js/routing';
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
import { useLatest } from '@weasel-js/react';
|
|
8
|
+
|
|
9
|
+
// src/measurement.ts
|
|
10
|
+
function measureBetween(start, end, frames) {
|
|
11
|
+
const dx = end.x - start.x;
|
|
12
|
+
const dy = end.y - start.y;
|
|
13
|
+
return {
|
|
14
|
+
start: { x: start.x, y: start.y },
|
|
15
|
+
end: { x: end.x, y: end.y },
|
|
16
|
+
dx,
|
|
17
|
+
dy,
|
|
18
|
+
distance: Math.hypot(dx, dy),
|
|
19
|
+
// `|| 0` drops the sign of a negated zero, which would read a leftward line as -π.
|
|
20
|
+
angle: dx === 0 && dy === 0 ? 0 : Math.atan2(-dy || 0, dx),
|
|
21
|
+
...frames ? { frames: { start: frames.start, end: frames.end } } : {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function measureMagnification(scene, frames) {
|
|
25
|
+
if (!frames || frames.start === null || frames.end === null) return 1;
|
|
26
|
+
return sceneMagnification(scene, [frames.start, frames.end], { inclusive: true });
|
|
27
|
+
}
|
|
28
|
+
function measureEndsOf(node) {
|
|
29
|
+
const m = node?.data?.measure;
|
|
30
|
+
if (!m || typeof m !== "object" || !m.start || !m.end) return null;
|
|
31
|
+
return m;
|
|
32
|
+
}
|
|
33
|
+
function measurementOf(node) {
|
|
34
|
+
const ends = measureEndsOf(node);
|
|
35
|
+
return ends ? measureBetween(ends.start, ends.end, ends.frames) : null;
|
|
36
|
+
}
|
|
37
|
+
function measurePose(start, end) {
|
|
38
|
+
return rectBetween(start.x, start.y, end.x, end.y);
|
|
39
|
+
}
|
|
40
|
+
function measureNode(id, layer, start, end, frames) {
|
|
41
|
+
const data = { measure: { start: { ...start }, end: { ...end }, ...frames ? { frames: { ...frames } } : {} } };
|
|
42
|
+
return { id, kind: "mark", layer, parent: null, pose: measurePose(start, end), data };
|
|
43
|
+
}
|
|
44
|
+
function withMeasureEnd(node, which, to, frame) {
|
|
45
|
+
const ends = measureEndsOf(node);
|
|
46
|
+
if (!ends) return null;
|
|
47
|
+
const next = { ...ends, [which]: { x: to.x, y: to.y } };
|
|
48
|
+
if (frame !== void 0) next.frames = { start: ends.frames?.start ?? null, end: ends.frames?.end ?? null, [which]: frame };
|
|
49
|
+
const data = { ...node.data, measure: next };
|
|
50
|
+
return { data, pose: measurePose(next.start, next.end) };
|
|
51
|
+
}
|
|
52
|
+
function createMeasurements(options) {
|
|
53
|
+
return {
|
|
54
|
+
layer: options.layer,
|
|
55
|
+
picked: createValueStore(null),
|
|
56
|
+
draft: createValueStore(null),
|
|
57
|
+
measuring: createValueStore(false)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function measureIds(scene, ms) {
|
|
61
|
+
return scene.nodesOnLayer(ms.layer).filter((n) => measurementOf(n) !== null).map((n) => n.id);
|
|
62
|
+
}
|
|
63
|
+
function currentMeasureId(scene, ms) {
|
|
64
|
+
const picked = ms.picked.get();
|
|
65
|
+
if (picked !== null && measurementOf(scene.get(picked)) !== null) return picked;
|
|
66
|
+
return measureIds(scene, ms).at(-1) ?? null;
|
|
67
|
+
}
|
|
68
|
+
function measureAt(scene, ms, p, tolerance) {
|
|
69
|
+
const gates = nodeGates(scene);
|
|
70
|
+
const shown = shownLookup(scene);
|
|
71
|
+
const ids = measureIds(scene, ms).reverse().filter((id) => !gates.hidden(id) && !gates.locked(id));
|
|
72
|
+
for (const id of ids) {
|
|
73
|
+
const ends = measureEndsOf(shown.get(id));
|
|
74
|
+
if (!ends) continue;
|
|
75
|
+
for (const part of ["end", "start"]) {
|
|
76
|
+
if (Math.hypot(p.x - ends[part].x, p.y - ends[part].y) <= tolerance) return { id, part };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const id of ids) {
|
|
80
|
+
const ends = measureEndsOf(shown.get(id));
|
|
81
|
+
if (ends && pointSegmentDist(p.x, p.y, ends.start.x, ends.start.y, ends.end.x, ends.end.y) <= tolerance) return { id, part: "line" };
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
function measureEndSource(opts = {}) {
|
|
86
|
+
return {
|
|
87
|
+
id: "measure-ends",
|
|
88
|
+
roles: ["pointer"],
|
|
89
|
+
...opts.reachPx !== void 0 ? { reachPx: opts.reachPx } : {},
|
|
90
|
+
*collect(q) {
|
|
91
|
+
if (!q.scene) return;
|
|
92
|
+
const gates = nodeGates(q.scene);
|
|
93
|
+
const skip = new Set(q.exclude);
|
|
94
|
+
const reach = q.reachWorld(q.reachPx);
|
|
95
|
+
for (const node of nodesAsShown(q.scene.overrides, q.scene.renderOrderNodes())) {
|
|
96
|
+
const ends = measureEndsOf(node);
|
|
97
|
+
if (!ends || skip.has(node.id) || gates.hidden(node.id)) continue;
|
|
98
|
+
for (const end of [ends.start, ends.end]) {
|
|
99
|
+
const at = { x: end.x, y: end.y };
|
|
100
|
+
for (const p of q.probes) {
|
|
101
|
+
if (Math.hypot(at.x - p.at.x, at.y - p.at.y) > reach) continue;
|
|
102
|
+
yield { probe: p.id, locus: { at, dirs: [] }, mark: { kind: "point", at, glyph: "center" } };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
var MEASURE_LABELS = {
|
|
110
|
+
add: "Measure",
|
|
111
|
+
moveEnd: "Move Measurement End",
|
|
112
|
+
move: "Move Measurement",
|
|
113
|
+
delete: "Delete Measurement",
|
|
114
|
+
clear: "Clear Measurements"
|
|
115
|
+
};
|
|
116
|
+
function addMeasureOp(scene, layer, start, end, frames) {
|
|
117
|
+
const id = scene.mintId();
|
|
118
|
+
return { id, op: insertAt(measureNode(id, layer, start, end, frames), -1, MEASURE_LABELS.add) };
|
|
119
|
+
}
|
|
120
|
+
function changeOps(node, next, label) {
|
|
121
|
+
return [
|
|
122
|
+
createTransformOp({ id: node.id, from: node.pose, to: next.pose, label }),
|
|
123
|
+
createSetDataOp({ id: node.id, from: node.data, to: next.data, label })
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
function moveEndOps(node, which, to, frame) {
|
|
127
|
+
const next = withMeasureEnd(node, which, to, frame);
|
|
128
|
+
return next ? changeOps(node, next, MEASURE_LABELS.moveEnd) : [];
|
|
129
|
+
}
|
|
130
|
+
function translatedMeasure(node, dx, dy, frameAt) {
|
|
131
|
+
const ends = measureEndsOf(node);
|
|
132
|
+
if (!ends) return null;
|
|
133
|
+
const start = { x: ends.start.x + dx, y: ends.start.y + dy };
|
|
134
|
+
const end = { x: ends.end.x + dx, y: ends.end.y + dy };
|
|
135
|
+
const frames = frameAt ? { start: frameAt(start), end: frameAt(end) } : ends.frames;
|
|
136
|
+
const measure = { start, end, ...frames ? { frames } : {} };
|
|
137
|
+
return { data: { ...node.data, measure }, pose: measurePose(start, end) };
|
|
138
|
+
}
|
|
139
|
+
function moveMeasureOps(node, dx, dy, frameAt) {
|
|
140
|
+
const next = translatedMeasure(node, dx, dy, frameAt);
|
|
141
|
+
return next ? changeOps(node, next, MEASURE_LABELS.move) : [];
|
|
142
|
+
}
|
|
143
|
+
function deleteMeasureOps(scene, ids, label) {
|
|
144
|
+
const ops = [];
|
|
145
|
+
for (const id of ids) {
|
|
146
|
+
const node = scene.get(id);
|
|
147
|
+
if (node) ops.push(deleteNode(scene, node, label));
|
|
148
|
+
}
|
|
149
|
+
return ops;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/actionIds.ts
|
|
153
|
+
var MEASURE_ACTION_IDS = {
|
|
154
|
+
/** The measure tool's drag, which adds a measurement. */
|
|
155
|
+
measure: "measure",
|
|
156
|
+
/** The measure tool's click, which picks the measurement under it. */
|
|
157
|
+
pickAt: "measure.pickAt",
|
|
158
|
+
/** A click on a measurement under any tool, which picks it. */
|
|
159
|
+
pick: "measure.pick",
|
|
160
|
+
/** A drag on a measurement under any tool: a picked end moves that end, the
|
|
161
|
+
* rest moves the whole measurement. */
|
|
162
|
+
drag: "measure.drag",
|
|
163
|
+
moveBy: "measure.moveBy",
|
|
164
|
+
rotateBy: "measure.rotateBy",
|
|
165
|
+
delete: "measure.delete",
|
|
166
|
+
clear: "measure.clear",
|
|
167
|
+
unpick: "measure.unpick"
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// src/measureCommands.ts
|
|
171
|
+
var MOVE_LABEL = "Move by Measurement";
|
|
172
|
+
var ROTATE_LABEL = "Rotate by Measurement";
|
|
173
|
+
function current(deps, ms) {
|
|
174
|
+
const scene = deps?.scene;
|
|
175
|
+
if (!scene) return null;
|
|
176
|
+
const id = currentMeasureId(scene, ms);
|
|
177
|
+
const m = id === null ? null : measurementOf(scene.get(id));
|
|
178
|
+
return id !== null && m ? { id, m } : null;
|
|
179
|
+
}
|
|
180
|
+
function transformable(ms, moves) {
|
|
181
|
+
return (deps) => {
|
|
182
|
+
const c = current(deps, ms);
|
|
183
|
+
if (!c || !moves(c.m)) return ActionDisabledReason.NotApplicable;
|
|
184
|
+
return requiresSelection(deps);
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
var travels = (m) => m.distance !== 0;
|
|
188
|
+
var turns = (m) => m.distance !== 0 && m.angle !== 0;
|
|
189
|
+
function moveBy(ms) {
|
|
190
|
+
return {
|
|
191
|
+
id: MEASURE_ACTION_IDS.moveBy,
|
|
192
|
+
label: MOVE_LABEL,
|
|
193
|
+
group: "measure",
|
|
194
|
+
eligible: { capability: "transforms-selection" },
|
|
195
|
+
requires: ["selection", "scene", "applyOps", "geometryProjection", "poseDescriptor", "transformFollowers"],
|
|
196
|
+
enabled: transformable(ms, travels),
|
|
197
|
+
invoker: {
|
|
198
|
+
timing: "immediate",
|
|
199
|
+
run: (deps) => {
|
|
200
|
+
const c = current(deps, ms);
|
|
201
|
+
if (c) transformSelection(deps, { kind: "translate", dx: c.m.dx, dy: c.m.dy }, MOVE_LABEL);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function rotateBy(ms) {
|
|
207
|
+
return {
|
|
208
|
+
id: MEASURE_ACTION_IDS.rotateBy,
|
|
209
|
+
label: ROTATE_LABEL,
|
|
210
|
+
group: "measure",
|
|
211
|
+
eligible: { capability: "transforms-selection" },
|
|
212
|
+
requires: ["selection", "scene", "applyOps", "poseDescriptor", "view", "boundsIncludeStroke", "drawnBoxes", "transformFollowers"],
|
|
213
|
+
enabled: transformable(ms, turns),
|
|
214
|
+
invoker: {
|
|
215
|
+
timing: "immediate",
|
|
216
|
+
run: (deps) => {
|
|
217
|
+
const c = current(deps, ms);
|
|
218
|
+
if (c) transformSelection(deps, { kind: "rotate", angle: -c.m.angle, pivot: "union" }, ROTATE_LABEL);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
var removesLocked = (deps, ids) => reachesLocked(deps?.scene, ids);
|
|
224
|
+
function remove(ms) {
|
|
225
|
+
return {
|
|
226
|
+
id: MEASURE_ACTION_IDS.delete,
|
|
227
|
+
label: MEASURE_LABELS.delete,
|
|
228
|
+
group: "measure",
|
|
229
|
+
requires: ["scene", "applyOps", "selection"],
|
|
230
|
+
// Declining with nothing measured leaves Delete to the ambient `delete`.
|
|
231
|
+
enabled: (deps) => {
|
|
232
|
+
const c = current(deps, ms);
|
|
233
|
+
if (!c) return ActionDisabledReason.NotApplicable;
|
|
234
|
+
return removesLocked(deps, [c.id]) ? ActionDisabledReason.Locked : true;
|
|
235
|
+
},
|
|
236
|
+
invoker: {
|
|
237
|
+
timing: "immediate",
|
|
238
|
+
run: (deps) => {
|
|
239
|
+
const c = current(deps, ms);
|
|
240
|
+
if (!c || removesLocked(deps, [c.id])) return;
|
|
241
|
+
commitOps(deps, deleteMeasureOps(deps.scene, [c.id], MEASURE_LABELS.delete), MEASURE_LABELS.delete);
|
|
242
|
+
if (ms.picked.get() === c.id) ms.picked.set(null);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function clearAll(ms) {
|
|
248
|
+
const all = (deps) => {
|
|
249
|
+
const scene = deps?.scene;
|
|
250
|
+
return scene ? measureIds(scene, ms) : [];
|
|
251
|
+
};
|
|
252
|
+
return {
|
|
253
|
+
id: MEASURE_ACTION_IDS.clear,
|
|
254
|
+
label: MEASURE_LABELS.clear,
|
|
255
|
+
group: "measure",
|
|
256
|
+
requires: ["scene", "applyOps", "selection"],
|
|
257
|
+
enabled: (deps) => {
|
|
258
|
+
const ids = all(deps);
|
|
259
|
+
if (ids.length === 0) return ActionDisabledReason.NotApplicable;
|
|
260
|
+
return removesLocked(deps, ids) ? ActionDisabledReason.Locked : true;
|
|
261
|
+
},
|
|
262
|
+
invoker: {
|
|
263
|
+
timing: "immediate",
|
|
264
|
+
run: (deps) => {
|
|
265
|
+
const ids = all(deps);
|
|
266
|
+
if (ids.length === 0 || removesLocked(deps, ids)) return;
|
|
267
|
+
commitOps(deps, deleteMeasureOps(deps.scene, ids, MEASURE_LABELS.clear), MEASURE_LABELS.clear);
|
|
268
|
+
ms.picked.set(null);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function unpick(ms) {
|
|
274
|
+
return {
|
|
275
|
+
id: MEASURE_ACTION_IDS.unpick,
|
|
276
|
+
label: "Deselect Measurement",
|
|
277
|
+
// Declining with nothing picked leaves Escape to the ambient `escape`.
|
|
278
|
+
enabled: () => ms.picked.get() !== null ? true : ActionDisabledReason.NotApplicable,
|
|
279
|
+
invoker: { timing: "immediate", run: () => ms.picked.set(null) }
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function measureCommands(ms) {
|
|
283
|
+
return [moveBy(ms), rotateBy(ms), remove(ms), clearAll(ms), unpick(ms)];
|
|
284
|
+
}
|
|
285
|
+
var MEASURE_HIT_PX = 6;
|
|
286
|
+
var pointOf = (at) => at.drag?.current ?? at.world;
|
|
287
|
+
var framesOf = (scene) => scene ? unitFrameAt(scene) : () => null;
|
|
288
|
+
function measureCreateAction(ms) {
|
|
289
|
+
return defineAction({
|
|
290
|
+
id: MEASURE_ACTION_IDS.measure,
|
|
291
|
+
label: "Measure",
|
|
292
|
+
modifierRoles: SNAP_ROLES,
|
|
293
|
+
requires: ["snap", "scene", "applyOps", "selection"],
|
|
294
|
+
invoker: {
|
|
295
|
+
timing: "ongoing",
|
|
296
|
+
// The dispatcher builds deps once, for `start`; later events carry none.
|
|
297
|
+
start(ctx, opts) {
|
|
298
|
+
const deps = ctx.deps;
|
|
299
|
+
const snap = spanSnap(deps.snap, () => {
|
|
300
|
+
return { step: resolveParams(opts?.params)?.angleStep ?? SNAP_ANGLE_STEP };
|
|
301
|
+
});
|
|
302
|
+
const scene = deps.scene;
|
|
303
|
+
const frameAt = framesOf(scene);
|
|
304
|
+
const start = snap.start(ctx.drag?.start ?? ctx.world, snapMods(ctx)).point;
|
|
305
|
+
const startFrame = frameAt(start);
|
|
306
|
+
const endAt = (at) => snap.end(pointOf(at), snapMods(at)).point;
|
|
307
|
+
const between = (end) => measureBetween(start, end, { start: startFrame, end: frameAt(end) });
|
|
308
|
+
ms.draft.set(between(start));
|
|
309
|
+
return {
|
|
310
|
+
kind: "measure",
|
|
311
|
+
onMove: (moveCtx) => ms.draft.set(between(endAt(moveCtx))),
|
|
312
|
+
onEnd: (endCtx, reason) => {
|
|
313
|
+
try {
|
|
314
|
+
ms.draft.set(null);
|
|
315
|
+
if (reason !== "commit" || !scene) return;
|
|
316
|
+
const end = endAt(endCtx);
|
|
317
|
+
if (end.x === start.x && end.y === start.y) return;
|
|
318
|
+
const { id, op } = addMeasureOp(scene, ms.layer, start, end, between(end).frames);
|
|
319
|
+
commitOps(deps, [op], "Measure");
|
|
320
|
+
ms.picked.set(id);
|
|
321
|
+
} finally {
|
|
322
|
+
snap.close();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
function measurePickAtAction(ms) {
|
|
331
|
+
return defineAction({
|
|
332
|
+
id: MEASURE_ACTION_IDS.pickAt,
|
|
333
|
+
label: "Pick Measurement",
|
|
334
|
+
requires: ["scene", "view"],
|
|
335
|
+
invoker: {
|
|
336
|
+
timing: "immediate",
|
|
337
|
+
run: (deps, params) => {
|
|
338
|
+
const press = params?.press;
|
|
339
|
+
const scene = deps.scene;
|
|
340
|
+
if (!scene || !press) return;
|
|
341
|
+
const hit = measureAt(scene, ms, press, pxReach(MEASURE_HIT_PX, deps.view?.get().scale ?? { x: 1, y: 1 }));
|
|
342
|
+
ms.picked.set(hit?.id ?? null);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
var hitOf = (affordance) => affordance?.payload ?? null;
|
|
348
|
+
function measurePickAction(ms) {
|
|
349
|
+
return defineAction({
|
|
350
|
+
id: MEASURE_ACTION_IDS.pick,
|
|
351
|
+
label: "Pick Measurement",
|
|
352
|
+
invoker: {
|
|
353
|
+
timing: "immediate",
|
|
354
|
+
run: (_deps, params) => {
|
|
355
|
+
const hit = hitOf(params?.affordance);
|
|
356
|
+
if (hit) ms.picked.set(hit.id);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
function nodeOf(scene, id) {
|
|
362
|
+
return scene?.get(id);
|
|
363
|
+
}
|
|
364
|
+
function measureDragAction(ms) {
|
|
365
|
+
return {
|
|
366
|
+
id: MEASURE_ACTION_IDS.drag,
|
|
367
|
+
label: "Drag Measurement",
|
|
368
|
+
modifierRoles: SNAP_ROLES,
|
|
369
|
+
requires: ["scene", "snap", "applyOps", "selection"],
|
|
370
|
+
invoker: {
|
|
371
|
+
timing: "ongoing",
|
|
372
|
+
start(ctx) {
|
|
373
|
+
const hit = hitOf(ctx.drag?.affordance);
|
|
374
|
+
const deps = ctx.deps;
|
|
375
|
+
const scene = deps.scene;
|
|
376
|
+
const node = hit ? nodeOf(scene, hit.id) : void 0;
|
|
377
|
+
if (!hit || !node) return {};
|
|
378
|
+
const end = hit.part !== "line" && ms.picked.get() === hit.id ? hit.part : null;
|
|
379
|
+
const from = ctx.drag?.start ?? ctx.world;
|
|
380
|
+
const grabbed = end && measureEndsOf(node)?.[end] || from;
|
|
381
|
+
const snap = end ? deps.snap?.begin({ gesture: "point", press: grabbed, ids: [hit.id] }) ?? null : null;
|
|
382
|
+
const frameAt = framesOf(scene);
|
|
383
|
+
let at = from;
|
|
384
|
+
let landed = grabbed;
|
|
385
|
+
const next = () => end ? withMeasureEnd(node, end, landed, frameAt(landed)) : translatedMeasure(node, at.x - from.x, at.y - from.y, frameAt);
|
|
386
|
+
const follow = (c) => {
|
|
387
|
+
at = pointOf(c);
|
|
388
|
+
const held = { x: grabbed.x + at.x - from.x, y: grabbed.y + at.y - from.y };
|
|
389
|
+
landed = snap ? snap.at(held, snapMods(c)).point : held;
|
|
390
|
+
};
|
|
391
|
+
ms.picked.set(hit.id);
|
|
392
|
+
return {
|
|
393
|
+
kind: MEASURE_ACTION_IDS.drag,
|
|
394
|
+
onMove: follow,
|
|
395
|
+
onEnd: (endCtx, reason) => {
|
|
396
|
+
try {
|
|
397
|
+
if (reason !== "commit") return;
|
|
398
|
+
follow(endCtx);
|
|
399
|
+
const ops = end ? moveEndOps(node, end, landed, frameAt(landed)) : moveMeasureOps(node, at.x - from.x, at.y - from.y, frameAt);
|
|
400
|
+
commitOps(deps, ops, ops[0]?.label ?? "Move Measurement");
|
|
401
|
+
} finally {
|
|
402
|
+
snap?.end();
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
previewIds: () => [hit.id],
|
|
406
|
+
previewOpaqueIds: () => [hit.id],
|
|
407
|
+
previewPose: () => next()?.pose ?? null,
|
|
408
|
+
previewData: () => next()?.data ?? null
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
var MEASURE_TICK_PX = 5;
|
|
415
|
+
function measureCommands2(start, end, perPx) {
|
|
416
|
+
const stroke = { ...OVERLAY_ROLE_STROKES["measure"], width: { px: 1 } };
|
|
417
|
+
const len = Math.hypot(end.x - start.x, end.y - start.y);
|
|
418
|
+
const nx = len > 0 ? -(end.y - start.y) / len : 0;
|
|
419
|
+
const ny = len > 0 ? (end.x - start.x) / len : 1;
|
|
420
|
+
const half = MEASURE_TICK_PX * perPx;
|
|
421
|
+
const tick = (p) => ({
|
|
422
|
+
kind: "path",
|
|
423
|
+
path: polylineFromPoints([{ x: p.x - nx * half, y: p.y - ny * half }, { x: p.x + nx * half, y: p.y + ny * half }]),
|
|
424
|
+
stroke
|
|
425
|
+
});
|
|
426
|
+
const out = [tick(start), tick(end)];
|
|
427
|
+
if (len > 0) out.unshift({ kind: "path", path: polylineFromPoints([start, end]), stroke });
|
|
428
|
+
return out;
|
|
429
|
+
}
|
|
430
|
+
var MEASURE_PAINTER = {
|
|
431
|
+
id: "measure:measurement",
|
|
432
|
+
matches: (node) => (node.pose === void 0 || isRectPose(node.pose)) && measureEndsOf(node) !== null,
|
|
433
|
+
paint: (node, _pose, ctx) => {
|
|
434
|
+
const ends = measureEndsOf(node);
|
|
435
|
+
if (!ends) return [];
|
|
436
|
+
return measureCommands2(ends.start, ends.end, 1 / (ctx?.scale ?? 1));
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// src/measureLayer.ts
|
|
441
|
+
var MEASURE_LAYER_ID = "weasel-measure";
|
|
442
|
+
var MEASURE_AFFORDANCE_KIND = `layer:${MEASURE_LAYER_ID}`;
|
|
443
|
+
var HANDLE_PX = 3.5;
|
|
444
|
+
function measurementsLayer(scene, ms) {
|
|
445
|
+
return {
|
|
446
|
+
id: MEASURE_LAYER_ID,
|
|
447
|
+
label: "Measurements",
|
|
448
|
+
space: "screen",
|
|
449
|
+
subscribe: (listener) => {
|
|
450
|
+
const offs = [ms.picked.subscribe(listener), ms.draft.subscribe(listener), ms.measuring.subscribe(listener)];
|
|
451
|
+
return () => {
|
|
452
|
+
for (const off of offs) off();
|
|
453
|
+
};
|
|
454
|
+
},
|
|
455
|
+
draw: (_data, view) => {
|
|
456
|
+
const t = viewToTransform(view);
|
|
457
|
+
const toScreen = (p) => {
|
|
458
|
+
const [x, y] = worldToScreen(p.x, p.y, t);
|
|
459
|
+
return { x, y };
|
|
460
|
+
};
|
|
461
|
+
const out = [];
|
|
462
|
+
const draft = ms.draft.get();
|
|
463
|
+
if (draft) out.push(...measureCommands2(toScreen(draft.start), toScreen(draft.end), 1));
|
|
464
|
+
const picked = ms.picked.get();
|
|
465
|
+
const ends = picked === null ? null : measureEndsOf(shownLookup(scene).get(picked));
|
|
466
|
+
if (ends && !scene.isHidden(picked)) {
|
|
467
|
+
const stroke = { ...OVERLAY_ROLE_STROKES["measure"], width: 1 };
|
|
468
|
+
for (const p of [ends.start, ends.end].map(toScreen)) {
|
|
469
|
+
out.push({
|
|
470
|
+
kind: "path",
|
|
471
|
+
path: rectPath(p.x - HANDLE_PX, p.y - HANDLE_PX, HANDLE_PX * 2, HANDLE_PX * 2),
|
|
472
|
+
fill: { paint: { color: "#ffffff" } },
|
|
473
|
+
stroke
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return out;
|
|
478
|
+
},
|
|
479
|
+
hitTest: (wx, wy, _data, view) => {
|
|
480
|
+
const hit = measureAt(scene, ms, { x: wx, y: wy }, pxReach(MEASURE_HIT_PX, view.scale));
|
|
481
|
+
if (!hit) return null;
|
|
482
|
+
const onPickedEnd = hit.part !== "line" && hit.id === ms.picked.get();
|
|
483
|
+
if (ms.measuring.get() && !onPickedEnd) return null;
|
|
484
|
+
return {
|
|
485
|
+
initialScratch: hit,
|
|
486
|
+
strength: "exclusive",
|
|
487
|
+
claimedKinds: ["pointer"],
|
|
488
|
+
cursor: onPickedEnd ? "crosshair" : "move"
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// src/measureContribution.ts
|
|
495
|
+
var onMeasurement = hitPredicate((hit) => hit?.kind === MEASURE_AFFORDANCE_KIND);
|
|
496
|
+
function measurementsContribution(scene, ms) {
|
|
497
|
+
const layer = measurementsLayer(scene, ms);
|
|
498
|
+
return {
|
|
499
|
+
id: "weasel-measure",
|
|
500
|
+
eligibility: { claimed: true },
|
|
501
|
+
attach: (api) => {
|
|
502
|
+
const offShape = nodeShapesOf(scene).register(MEASURE_PAINTER);
|
|
503
|
+
const offLayer = api.registerLayer(layer);
|
|
504
|
+
api.requestRedraw();
|
|
505
|
+
return () => {
|
|
506
|
+
offLayer();
|
|
507
|
+
offShape();
|
|
508
|
+
};
|
|
509
|
+
},
|
|
510
|
+
actions: [...measureCommands(ms), measurePickAction(ms), measureDragAction(ms)],
|
|
511
|
+
bindings: [
|
|
512
|
+
{ spec: { kind: "click", target: { kindOf: onMeasurement }, mods: ANY_MODS }, actionId: MEASURE_ACTION_IDS.pick, opts: { id: "weasel-measure.click" } },
|
|
513
|
+
{ spec: { kind: "drag", target: { kindOf: onMeasurement }, mods: ANY_MODS }, actionId: MEASURE_ACTION_IDS.drag, opts: { id: "weasel-measure.drag" } }
|
|
514
|
+
]
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function useMeasureTool(options) {
|
|
518
|
+
const { measurements: ms, keybinding } = options;
|
|
519
|
+
const actions = useMemo(() => [measureCreateAction(ms), measurePickAtAction(ms)], [ms]);
|
|
520
|
+
const angleStep = useLatest(options.angleStep);
|
|
521
|
+
return useMemo(() => defineTool({
|
|
522
|
+
id: "measure",
|
|
523
|
+
capabilities: ["navigation"],
|
|
524
|
+
hookName: "useMeasureTool",
|
|
525
|
+
cursor: "crosshair",
|
|
526
|
+
presentation: { label: "Measure", icon: (
|
|
527
|
+
/* @icon */
|
|
528
|
+
"core:measure"
|
|
529
|
+
), group: "view" },
|
|
530
|
+
...keybinding === null ? {} : { keybinding: keybinding ?? { key: "M" } },
|
|
531
|
+
actions,
|
|
532
|
+
onActivate: () => ms.measuring.set(true),
|
|
533
|
+
onDeactivate: () => {
|
|
534
|
+
ms.measuring.set(false);
|
|
535
|
+
ms.draft.set(null);
|
|
536
|
+
},
|
|
537
|
+
bindings: [
|
|
538
|
+
{ spec: { kind: "click" }, actionId: MEASURE_ACTION_IDS.pickAt, opts: { id: "measure.pick" } },
|
|
539
|
+
{
|
|
540
|
+
spec: { kind: "drag", mods: SNAP_ROLE_MODS },
|
|
541
|
+
actionId: MEASURE_ACTION_IDS.measure,
|
|
542
|
+
opts: { id: "measure.drag", params: () => angleStep.current === void 0 ? {} : { angleStep: angleStep.current } }
|
|
543
|
+
},
|
|
544
|
+
{ spec: { kind: "key", key: "Escape" }, actionId: MEASURE_ACTION_IDS.unpick, opts: { id: "measure.unpick" } },
|
|
545
|
+
{ spec: { kind: "key", key: "Delete" }, actionId: MEASURE_ACTION_IDS.delete, opts: { id: "measure.delete" } },
|
|
546
|
+
{ spec: { kind: "key", key: "Backspace" }, actionId: MEASURE_ACTION_IDS.delete, opts: { id: "measure.backspace" } }
|
|
547
|
+
]
|
|
548
|
+
}), [actions, keybinding, ms, angleStep]);
|
|
549
|
+
}
|
|
550
|
+
var MEASURE_TOOLS = toolSet("measure", ["measure"], { label: "Measure" });
|
|
551
|
+
function useMeasureTools(options) {
|
|
552
|
+
const measure = useMeasureTool(options);
|
|
553
|
+
return useMemo(() => ({ measure }), [measure]);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export { MEASURE_ACTION_IDS, MEASURE_AFFORDANCE_KIND, MEASURE_LAYER_ID, MEASURE_PAINTER, MEASURE_TOOLS, createMeasurements, currentMeasureId, measureAt, measureBetween, measureEndSource, measureEndsOf, measureIds, measureMagnification, measureNode, measurePose, measurementOf, measurementsContribution, useMeasureTool, useMeasureTools };
|
|
557
|
+
//# sourceMappingURL=index.js.map
|
|
558
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/measurement.ts","../src/measurements.ts","../src/measureHit.ts","../src/measureEdits.ts","../src/actionIds.ts","../src/measureCommands.ts","../src/measureGestures.ts","../src/measurePainter.ts","../src/measureLayer.ts","../src/measureContribution.ts","../src/useMeasureTool.ts","../src/toolSets.ts"],"names":["commitOps","measureCommands","shownLookup","OVERLAY_ROLE_STROKES","pxReach","useMemo"],"mappings":";;;;;;;;;AAyCO,SAAS,cAAA,CAAe,KAAA,EAAqB,GAAA,EAAmB,MAAA,EAAqC;AAC1G,EAAA,MAAM,EAAA,GAAK,GAAA,CAAI,CAAA,GAAI,KAAA,CAAM,CAAA;AACzB,EAAA,MAAM,EAAA,GAAK,GAAA,CAAI,CAAA,GAAI,KAAA,CAAM,CAAA;AACzB,EAAA,OAAO;AAAA,IACL,OAAO,EAAE,CAAA,EAAG,MAAM,CAAA,EAAG,CAAA,EAAG,MAAM,CAAA,EAAE;AAAA,IAChC,KAAK,EAAE,CAAA,EAAG,IAAI,CAAA,EAAG,CAAA,EAAG,IAAI,CAAA,EAAE;AAAA,IAC1B,EAAA;AAAA,IACA,EAAA;AAAA,IACA,QAAA,EAAU,IAAA,CAAK,KAAA,CAAM,EAAA,EAAI,EAAE,CAAA;AAAA;AAAA,IAE3B,KAAA,EAAO,EAAA,KAAO,CAAA,IAAK,EAAA,KAAO,CAAA,GAAI,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,CAAC,EAAA,IAAM,CAAA,EAAG,EAAE,CAAA;AAAA,IACzD,GAAI,MAAA,GAAS,EAAE,MAAA,EAAQ,EAAE,KAAA,EAAO,MAAA,CAAO,KAAA,EAAO,GAAA,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AA,EAAQ,IAAA,EAAM,EAAE,EAAA,EAAI,qBAAoB;AAClH;AACF,GAAC,GAAG,CAAC,OAAA,EAAS,UAAA,EAAY,EAAA,EAAI,SAAS,CAAC,CAAA;AAC1C;ACtDO,IAAM,aAAA,GAAwC,QAAQ,SAAA,EAAW,CAAC,SAAS,CAAA,EAAG,EAAE,KAAA,EAAO,SAAA,EAAW;AAMlG,SAAS,gBAAgB,OAAA,EAA6D;AAC3F,EAAA,MAAM,OAAA,GAAU,eAAe,OAAO,CAAA;AACtC,EAAA,OAAOC,QAAQ,OAAO,EAAE,SAAQ,CAAA,EAAI,CAAC,OAAO,CAAC,CAAA;AAC/C","file":"index.js","sourcesContent":["import {\n type MarkNode, type NodeId, type SceneNode, type RectPose, sceneMagnification, type ScopedScene,\n} from '@weasel-js/core';\nimport { rectBetween, type Point } from '@weasel-js/geom';\n\n/** A world-space point. */\nexport type MeasurePoint = Point;\n\n/**\n * The frame each end of a measurement landed in: the node declaring a unit\n * scope it was placed inside (`unitFrameAt`), or `null` for the top of the\n * tree. The measurement reads in the scope chain the two frames share, so ends\n * in one frame, or in frames declaring equal scopes, read that frame's\n * modeled length, and ends whose frames disagree read the innermost frame\n * holding both, which is world when only the root does.\n */\nexport interface MeasureFrames {\n readonly start: NodeId | null;\n readonly end: NodeId | null;\n}\n\n/**\n * The offset from `start` to `end`, in world units. `dx` and `dy` are on the\n * world's own axes, where y grows downward; `angle` reads like a protractor\n * instead, counterclockwise-positive on screen, so a line rising up and to\n * the right at 30° reads +30°. The canvas's own rotations are\n * clockwise-positive: a rotate that follows the line turns by `-angle`.\n */\nexport interface Measurement {\n readonly start: MeasurePoint;\n readonly end: MeasurePoint;\n readonly dx: number;\n readonly dy: number;\n readonly distance: number;\n /** `atan2(-dy, dx)`, in `(-π, π]`. Zero for a zero-length measurement. */\n readonly angle: number;\n /** The frames its ends landed in. Absent, it reads in world. */\n readonly frames?: MeasureFrames;\n}\n\n/** Measure from `start` to `end`, landed in `frames`. */\nexport function measureBetween(start: MeasurePoint, end: MeasurePoint, frames?: MeasureFrames): Measurement {\n const dx = end.x - start.x;\n const dy = end.y - start.y;\n return {\n start: { x: start.x, y: start.y },\n end: { x: end.x, y: end.y },\n dx,\n dy,\n distance: Math.hypot(dx, dy),\n // `|| 0` drops the sign of a negated zero, which would read a leftward line as -π.\n angle: dx === 0 && dy === 0 ? 0 : Math.atan2(-dy || 0, dx),\n ...(frames ? { frames: { start: frames.start, end: frames.end } } : {}),\n };\n}\n\n/** How large the frame `frames` share is drawn in world: a measurement's\n * world lengths divided by it are its modeled lengths. 1 without frames. */\nexport function measureMagnification(scene: ScopedScene, frames: MeasureFrames | undefined): number {\n if (!frames || frames.start === null || frames.end === null) return 1;\n return sceneMagnification(scene, [frames.start, frames.end], { inclusive: true });\n}\n\n/** What a measurement node keeps in `data`: its two ends, in world units, and\n * the frames they landed in. A `label` beside it names the node in a layer\n * list. */\nexport interface MeasureData {\n measure: { start: MeasurePoint; end: MeasurePoint; frames?: MeasureFrames };\n label?: string;\n}\n\n/** Where an end placed at a world point lands: what `unitFrameAt` builds. */\nexport type MeasureFrameAt = (p: MeasurePoint) => NodeId | null;\n\n/** Which end of a measurement. */\nexport type MeasureEnd = 'start' | 'end';\n\n\n/** The ends `node` measures between, or null when it is not a measurement. */\nexport function measureEndsOf(node: Pick<SceneNode<unknown, string, unknown>, 'data'> | undefined): MeasureData['measure'] | null {\n const m = (node?.data as Partial<MeasureData> | null | undefined)?.measure;\n if (!m || typeof m !== 'object' || !m.start || !m.end) return null;\n return m;\n}\n\n/** The measurement `node` holds, or null when it is not one. */\nexport function measurementOf(node: Pick<SceneNode<unknown, string, unknown>, 'data'> | undefined): Measurement | null {\n const ends = measureEndsOf(node);\n return ends ? measureBetween(ends.start, ends.end, ends.frames) : null;\n}\n\n/** The box a measurement's pose holds: its two ends' bounds, which is what\n * culling, area queries, and fitting the view read. */\nexport function measurePose(start: MeasurePoint, end: MeasurePoint): RectPose {\n return rectBetween(start.x, start.y, end.x, end.y);\n}\n\n/** A measurement node on `layer`, ready to insert, or to list in a scene's\n * `initial` nodes: typed with that layer and a `RectPose`. */\nexport function measureNode<TLayer extends string>(\n id: NodeId,\n layer: TLayer,\n start: MeasurePoint,\n end: MeasurePoint,\n frames?: MeasureFrames,\n): MarkNode<MeasureData, TLayer, RectPose> {\n const data: MeasureData = { measure: { start: { ...start }, end: { ...end }, ...(frames ? { frames: { ...frames } } : {}) } };\n return { id, kind: 'mark', layer, parent: null, pose: measurePose(start, end), data };\n}\n\n/** `node`'s data and pose with its `which` end moved to `to`, landed in\n * `frame`. Without `frame` the end keeps the one it had. */\nexport function withMeasureEnd(\n node: SceneNode<unknown, string, unknown>,\n which: MeasureEnd,\n to: MeasurePoint,\n frame?: NodeId | null,\n): { data: MeasureData; pose: RectPose } | null {\n const ends = measureEndsOf(node);\n if (!ends) return null;\n const next = { ...ends, [which]: { x: to.x, y: to.y } };\n if (frame !== undefined) next.frames = { start: ends.frames?.start ?? null, end: ends.frames?.end ?? null, [which]: frame };\n const data: MeasureData = { ...(node.data as MeasureData), measure: next };\n return { data, pose: measurePose(next.start, next.end) };\n}\n","import { createValueStore, type ValueStore } from '@weasel-js/registry';\nimport type { NodeId, Scene } from '@weasel-js/core';\nimport { measurementOf, type Measurement } from './measurement';\n\n/** One value, readable and watchable — what a readout re-renders from. */\nexport type MeasureCell<T> = ValueStore<T>;\n\n/**\n * Where a scene's measurements go, and the state around them that is not\n * the document's: which one is picked, and the one a measure drag is still\n * drawing. The measurements themselves are nodes on `layer`, an annotation\n * layer (`isAnnotationLayer`), so they save with the scene, undo with it,\n * and stay out of export and content picking.\n *\n * The pick sits beside the content selection rather than in it: picking a\n * measurement leaves the selection alone, so Move by can carry the selection\n * by the picked measurement.\n */\nexport interface Measurements {\n /** The annotation layer new measurements are added to. */\n readonly layer: string;\n /** The picked measurement's id. */\n readonly picked: MeasureCell<NodeId | null>;\n /** The measurement a measure drag is drawing, before it is added. */\n readonly draft: MeasureCell<Measurement | null>;\n /** Whether the measure tool is active, which changes what a press on a\n * measurement does: under it, only the picked one's ends take a drag, so a\n * drag from anywhere else starts a new measurement. */\n readonly measuring: MeasureCell<boolean>;\n}\n\n/** The measurements on `layer`, none picked and none in progress. */\nexport function createMeasurements(options: { layer: string }): Measurements {\n return {\n layer: options.layer,\n picked: createValueStore<NodeId | null>(null),\n draft: createValueStore<Measurement | null>(null),\n measuring: createValueStore(false),\n };\n}\n\n\n/** The measurement nodes on `ms.layer`, oldest first. */\nexport function measureIds(scene: Pick<Scene<unknown, string, unknown>, 'nodesOnLayer'>, ms: Pick<Measurements, 'layer'>): NodeId[] {\n return scene.nodesOnLayer(ms.layer).filter((n) => measurementOf(n) !== null).map((n) => n.id);\n}\n\n/** The measurement commands act on: the picked one while it is still in the\n * scene, else the newest. */\nexport function currentMeasureId(\n scene: Pick<Scene<unknown, string, unknown>, 'nodesOnLayer' | 'get'>,\n ms: Pick<Measurements, 'layer' | 'picked'>,\n): NodeId | null {\n const picked = ms.picked.get();\n if (picked !== null && measurementOf(scene.get(picked)) !== null) return picked;\n return measureIds(scene, ms).at(-1) ?? null;\n}\n","import { pointSegmentDist } from '@weasel-js/geom';\nimport { nodeGates, type NodeId, nodesAsShown, type Scene, shownLookup, type SnapSource } from '@weasel-js/core';\nimport { measureEndsOf, type MeasureEnd, type MeasurePoint } from './measurement';\nimport { measureIds, type Measurements } from './measurements';\n\n/** Which part of which measurement lies under a point. */\nexport interface MeasureHit {\n id: NodeId;\n part: MeasureEnd | 'line';\n}\n\n\n/**\n * The measurement under `p`, newest first: an end within `tolerance` world\n * units of it, else a line within the same distance. A hidden or locked\n * measurement (`nodeGates`) is passed over.\n */\nexport function measureAt(\n scene: Pick<Scene<unknown, string, unknown>, 'nodesOnLayer' | 'get' | 'layers' | 'overrides'>,\n ms: Pick<Measurements, 'layer'>,\n p: MeasurePoint,\n tolerance: number,\n): MeasureHit | null {\n const gates = nodeGates(scene);\n // Hit where the ends are shown: a gesture moving one publishes it as a data override.\n const shown = shownLookup(scene);\n const ids = measureIds(scene, ms).reverse().filter((id) => !gates.hidden(id) && !gates.locked(id));\n for (const id of ids) {\n const ends = measureEndsOf(shown.get(id));\n if (!ends) continue;\n for (const part of ['end', 'start'] as const) {\n if (Math.hypot(p.x - ends[part].x, p.y - ends[part].y) <= tolerance) return { id, part };\n }\n }\n for (const id of ids) {\n const ends = measureEndsOf(shown.get(id));\n if (ends && pointSegmentDist(p.x, p.y, ends.start.x, ends.start.y, ends.end.x, ends.end.y) <= tolerance) return { id, part: 'line' };\n }\n return null;\n}\n\n/** Options for `measureEndSource`. */\nexport interface MeasureEndSourceOptions {\n /** Overrides the canvas's reach for measurement ends, in screen px. */\n reachPx?: number;\n}\n\n/** The ends of every shown measurement as snap targets for a pointer probe. */\nexport function measureEndSource(opts: MeasureEndSourceOptions = {}): SnapSource {\n return {\n id: 'measure-ends',\n roles: ['pointer'],\n ...(opts.reachPx !== undefined ? { reachPx: opts.reachPx } : {}),\n *collect(q) {\n if (!q.scene) return;\n const gates = nodeGates(q.scene);\n const skip = new Set(q.exclude);\n const reach = q.reachWorld(q.reachPx);\n for (const node of nodesAsShown(q.scene.overrides, q.scene.renderOrderNodes())) {\n const ends = measureEndsOf(node);\n if (!ends || skip.has(node.id) || gates.hidden(node.id)) continue;\n for (const end of [ends.start, ends.end]) {\n const at = { x: end.x, y: end.y };\n for (const p of q.probes) {\n if (Math.hypot(at.x - p.at.x, at.y - p.at.y) > reach) continue;\n yield { probe: p.id, locus: { at, dirs: [] }, mark: { kind: 'point', at, glyph: 'center' } };\n }\n }\n }\n },\n };\n}\n","import {\n type AnyNode, type AnyScene, createSetDataOp, createTransformOp, deleteNode, insertAt, type NodeId, type Op,\n} from '@weasel-js/core';\nimport {\n measureEndsOf, measureNode, measurePose, withMeasureEnd,\n type MeasureData, type MeasureEnd, type MeasureFrameAt, type MeasureFrames, type MeasurePoint,\n} from './measurement';\n\n/** The labels measurement edits land in history under. */\nexport const MEASURE_LABELS = {\n add: 'Measure',\n moveEnd: 'Move Measurement End',\n move: 'Move Measurement',\n delete: 'Delete Measurement',\n clear: 'Clear Measurements',\n} as const;\n\n/** The op adding a measurement from `start` to `end` on `layer`, at the top,\n * its ends landed in `frames`. */\nexport function addMeasureOp(\n scene: AnyScene,\n layer: string,\n start: MeasurePoint,\n end: MeasurePoint,\n frames?: MeasureFrames,\n): { id: NodeId; op: Op } {\n const id = scene.mintId();\n return { id, op: insertAt(measureNode(id, layer, start, end, frames), -1, MEASURE_LABELS.add) };\n}\n\n/** `node` as it reads after `next`: what an edit writes and its preview shows. */\nfunction changeOps(node: AnyNode, next: { data: MeasureData; pose: unknown }, label: string): Op[] {\n return [\n createTransformOp({ id: node.id, from: node.pose, to: next.pose, label }),\n createSetDataOp({ id: node.id, from: node.data, to: next.data, label }),\n ];\n}\n\n/** The ops moving `node`'s `which` end to `to`, landed in `frame`. */\nexport function moveEndOps(node: AnyNode, which: MeasureEnd, to: MeasurePoint, frame?: NodeId | null): Op[] {\n const next = withMeasureEnd(node, which, to, frame);\n return next ? changeOps(node, next, MEASURE_LABELS.moveEnd) : [];\n}\n\n/** `node` carried by `(dx, dy)`, both ends together, each landing where\n * `frameAt` says. Without `frameAt` the ends keep the frames they had. */\nexport function translatedMeasure(\n node: AnyNode,\n dx: number,\n dy: number,\n frameAt?: MeasureFrameAt,\n): { data: MeasureData; pose: unknown } | null {\n const ends = measureEndsOf(node);\n if (!ends) return null;\n const start = { x: ends.start.x + dx, y: ends.start.y + dy };\n const end = { x: ends.end.x + dx, y: ends.end.y + dy };\n const frames = frameAt ? { start: frameAt(start), end: frameAt(end) } : ends.frames;\n const measure = { start, end, ...(frames ? { frames } : {}) };\n return { data: { ...(node.data as MeasureData), measure }, pose: measurePose(start, end) };\n}\n\n/** The ops carrying `node` by `(dx, dy)`, its ends landing where `frameAt` says. */\nexport function moveMeasureOps(node: AnyNode, dx: number, dy: number, frameAt?: MeasureFrameAt): Op[] {\n const next = translatedMeasure(node, dx, dy, frameAt);\n return next ? changeOps(node, next, MEASURE_LABELS.move) : [];\n}\n\n/** The ops deleting each of `ids`, as one edit labeled `label`. */\nexport function deleteMeasureOps(scene: AnyScene, ids: readonly NodeId[], label: string): Op[] {\n const ops: Op[] = [];\n for (const id of ids) {\n const node = scene.get(id);\n if (node) ops.push(deleteNode(scene, node, label));\n }\n return ops;\n}\n","/** The ids of the measure feature's actions. */\nexport const MEASURE_ACTION_IDS = {\n /** The measure tool's drag, which adds a measurement. */\n measure: 'measure',\n /** The measure tool's click, which picks the measurement under it. */\n pickAt: 'measure.pickAt',\n /** A click on a measurement under any tool, which picks it. */\n pick: 'measure.pick',\n /** A drag on a measurement under any tool: a picked end moves that end, the\n * rest moves the whole measurement. */\n drag: 'measure.drag',\n moveBy: 'measure.moveBy',\n rotateBy: 'measure.rotateBy',\n delete: 'measure.delete',\n clear: 'measure.clear',\n unpick: 'measure.unpick',\n} as const;\n","import type { Action, ActionDeps } from '@weasel-js/routing';\nimport { ActionDisabledReason } from '@weasel-js/routing';\nimport { type AnyScene, commitOps, type NodeId, reachesLocked, requiresSelection, transformSelection } from '@weasel-js/core';\nimport { measurementOf, type Measurement } from './measurement';\nimport { currentMeasureId, measureIds, type Measurements } from './measurements';\nimport { deleteMeasureOps, MEASURE_LABELS } from './measureEdits';\nimport { MEASURE_ACTION_IDS } from './actionIds';\n\nconst MOVE_LABEL = 'Move by Measurement';\nconst ROTATE_LABEL = 'Rotate by Measurement';\n\nfunction current(deps: ActionDeps | undefined, ms: Measurements): { id: NodeId; m: Measurement } | null {\n const scene = deps?.scene as AnyScene | undefined;\n if (!scene) return null;\n const id = currentMeasureId(scene, ms);\n const m = id === null ? null : measurementOf(scene.get(id));\n return id !== null && m ? { id, m } : null;\n}\n\n/** Enabled with a measurement `moves` reads as a change and a selection to apply it to. */\nfunction transformable(ms: Measurements, moves: (m: Measurement) => boolean) {\n return (deps?: ActionDeps) => {\n const c = current(deps, ms);\n if (!c || !moves(c.m)) return ActionDisabledReason.NotApplicable;\n return requiresSelection(deps);\n };\n}\n\nconst travels = (m: Measurement): boolean => m.distance !== 0;\n/** A measurement along the x axis turns nothing. */\nconst turns = (m: Measurement): boolean => m.distance !== 0 && m.angle !== 0;\n\nfunction moveBy(ms: Measurements): Action {\n return {\n id: MEASURE_ACTION_IDS.moveBy,\n label: MOVE_LABEL,\n group: 'measure',\n eligible: { capability: 'transforms-selection' },\n requires: ['selection', 'scene', 'applyOps', 'geometryProjection', 'poseDescriptor', 'transformFollowers'],\n enabled: transformable(ms, travels),\n invoker: {\n timing: 'immediate',\n run: (deps) => {\n const c = current(deps, ms);\n if (c) transformSelection(deps, { kind: 'translate', dx: c.m.dx, dy: c.m.dy }, MOVE_LABEL);\n },\n },\n };\n}\n\nfunction rotateBy(ms: Measurements): Action {\n return {\n id: MEASURE_ACTION_IDS.rotateBy,\n label: ROTATE_LABEL,\n group: 'measure',\n eligible: { capability: 'transforms-selection' },\n requires: ['selection', 'scene', 'applyOps', 'poseDescriptor', 'view', 'boundsIncludeStroke', 'drawnBoxes', 'transformFollowers'],\n enabled: transformable(ms, turns),\n invoker: {\n timing: 'immediate',\n run: (deps) => {\n const c = current(deps, ms);\n // The measurement reads counterclockwise-positive; the canvas turns clockwise-positive.\n if (c) transformSelection(deps, { kind: 'rotate', angle: -c.m.angle, pivot: 'union' }, ROTATE_LABEL);\n },\n },\n };\n}\n\n/** Whether removing `ids` would reach a locked node, which disables a removal rather than throwing from it. */\nconst removesLocked = (deps: ActionDeps | undefined, ids: readonly NodeId[]): boolean =>\n reachesLocked(deps?.scene as never, ids);\n\nfunction remove(ms: Measurements): Action {\n return {\n id: MEASURE_ACTION_IDS.delete,\n label: MEASURE_LABELS.delete,\n group: 'measure',\n requires: ['scene', 'applyOps', 'selection'],\n // Declining with nothing measured leaves Delete to the ambient `delete`.\n enabled: (deps) => {\n const c = current(deps, ms);\n if (!c) return ActionDisabledReason.NotApplicable;\n return removesLocked(deps, [c.id]) ? ActionDisabledReason.Locked : true;\n },\n invoker: {\n timing: 'immediate',\n run: (deps) => {\n const c = current(deps, ms);\n if (!c || removesLocked(deps, [c.id])) return;\n commitOps(deps, deleteMeasureOps(deps.scene as AnyScene, [c.id], MEASURE_LABELS.delete), MEASURE_LABELS.delete);\n if (ms.picked.get() === c.id) ms.picked.set(null);\n },\n },\n };\n}\n\nfunction clearAll(ms: Measurements): Action {\n const all = (deps: ActionDeps | undefined) => {\n const scene = deps?.scene as AnyScene | undefined;\n return scene ? measureIds(scene, ms) : [];\n };\n return {\n id: MEASURE_ACTION_IDS.clear,\n label: MEASURE_LABELS.clear,\n group: 'measure',\n requires: ['scene', 'applyOps', 'selection'],\n enabled: (deps) => {\n const ids = all(deps);\n if (ids.length === 0) return ActionDisabledReason.NotApplicable;\n return removesLocked(deps, ids) ? ActionDisabledReason.Locked : true;\n },\n invoker: {\n timing: 'immediate',\n run: (deps) => {\n const ids = all(deps);\n if (ids.length === 0 || removesLocked(deps, ids)) return;\n commitOps(deps, deleteMeasureOps(deps.scene as AnyScene, ids, MEASURE_LABELS.clear), MEASURE_LABELS.clear);\n ms.picked.set(null);\n },\n },\n };\n}\n\nfunction unpick(ms: Measurements): Action {\n return {\n id: MEASURE_ACTION_IDS.unpick,\n label: 'Deselect Measurement',\n // Declining with nothing picked leaves Escape to the ambient `escape`.\n enabled: () => (ms.picked.get() !== null ? true : ActionDisabledReason.NotApplicable),\n invoker: { timing: 'immediate', run: () => ms.picked.set(null) },\n };\n}\n\n/**\n * The commands over a scene's measurements: move the content selection by\n * the current measurement's offset, or turn it about its center by the\n * measured angle — each one undo step Transform Again can repeat — delete the\n * current measurement, clear them all, and drop the pick. The current\n * measurement is the picked one, else the newest. All but the pick's are in\n * the `measure` group.\n */\nexport function measureCommands(ms: Measurements): Action[] {\n return [moveBy(ms), rotateBy(ms), remove(ms), clearAll(ms), unpick(ms)];\n}\n","import type { Action, InvocationCtx, OngoingHandle } from '@weasel-js/routing';\nimport { defineAction, resolveParams } from '@weasel-js/routing';\nimport {\n type AnyScene, commitOps, type NodeId, SNAP_ANGLE_STEP, SNAP_ROLES, snapMods, spanSnap, unitFrameAt,\n} from '@weasel-js/core';\nimport {\n measureBetween, measureEndsOf, withMeasureEnd,\n type MeasureEnd, type MeasureFrameAt, type MeasurePoint,\n} from './measurement';\nimport type { Measurements } from './measurements';\nimport { measureAt, type MeasureHit } from './measureHit';\nimport { addMeasureOp, moveEndOps, moveMeasureOps, translatedMeasure } from './measureEdits';\nimport { MEASURE_ACTION_IDS } from './actionIds';\nimport type {} from './actionParamSchema';\nimport { pxReach } from '@weasel-js/geom';\n\n/** Screen-px radius around a measurement that picks it. */\nexport const MEASURE_HIT_PX = 6;\n\nconst pointOf = (at: InvocationCtx): MeasurePoint => at.drag?.current ?? at.world;\n\n/** Where an end lands among `scene`'s unit-scope frames; the top of the tree\n * without a scene. Built once per gesture: the scene holds still under it. */\nconst framesOf = (scene: AnyScene | undefined): MeasureFrameAt => (scene ? unitFrameAt(scene) : () => null);\n\n/**\n * The measure tool's drag: from press to pointer, each end through a `point`\n * session of the `snap` dep. While `snap.constrain` (Shift) is held the end\n * stays on the line through the snapped start at the nearest step of the\n * binding param `angleStep` (radians, default 15°), and lands where that line\n * meets a target. Each end records the unit-scope frame it lands in\n * (`unitFrameAt`), so the measurement reads in that frame's units. The drawing\n * shows in `ms.draft`; on release it becomes a measurement node, one undo\n * step, and the picked one.\n */\nexport function measureCreateAction(ms: Measurements): Action {\n return defineAction({\n id: MEASURE_ACTION_IDS.measure,\n label: 'Measure',\n modifierRoles: SNAP_ROLES,\n requires: ['snap', 'scene', 'applyOps', 'selection'],\n invoker: {\n timing: 'ongoing',\n // The dispatcher builds deps once, for `start`; later events carry none.\n start(ctx, opts) {\n const deps = ctx.deps;\n // Read on every event, so a step changed mid-drag reaches it.\n const snap = spanSnap(deps.snap, () => {\n return { step: resolveParams(opts?.params)?.angleStep ?? SNAP_ANGLE_STEP };\n });\n const scene = deps.scene as AnyScene | undefined;\n const frameAt = framesOf(scene);\n const start = snap.start(ctx.drag?.start ?? ctx.world, snapMods(ctx)).point;\n const startFrame = frameAt(start);\n const endAt = (at: InvocationCtx): MeasurePoint => snap.end(pointOf(at), snapMods(at)).point;\n const between = (end: MeasurePoint) => measureBetween(start, end, { start: startFrame, end: frameAt(end) });\n ms.draft.set(between(start));\n return {\n kind: 'measure',\n onMove: (moveCtx) => ms.draft.set(between(endAt(moveCtx))),\n onEnd: (endCtx, reason) => {\n try {\n ms.draft.set(null);\n if (reason !== 'commit' || !scene) return;\n const end = endAt(endCtx);\n if (end.x === start.x && end.y === start.y) return;\n const { id, op } = addMeasureOp(scene, ms.layer, start, end, between(end).frames);\n commitOps(deps, [op], 'Measure');\n ms.picked.set(id);\n } finally {\n snap.close();\n }\n },\n };\n },\n },\n });\n}\n\n/** The measure tool's click: picks the measurement under it, or drops the\n * pick on empty canvas. */\nexport function measurePickAtAction(ms: Measurements): Action {\n return defineAction({\n id: MEASURE_ACTION_IDS.pickAt,\n label: 'Pick Measurement',\n requires: ['scene', 'view'],\n invoker: {\n timing: 'immediate',\n run: (deps, params) => {\n const press = params?.press;\n const scene = deps.scene as AnyScene | undefined;\n if (!scene || !press) return;\n const hit = measureAt(scene, ms, press, pxReach(MEASURE_HIT_PX, deps.view?.get().scale ?? { x: 1, y: 1 }));\n ms.picked.set(hit?.id ?? null);\n },\n },\n });\n}\n\n/** What a press on the measurements layer resolved, as its hit-test claims it. */\nexport const hitOf = (affordance: unknown): MeasureHit | null =>\n (affordance as { payload?: MeasureHit } | null | undefined)?.payload ?? null;\n\n/** A click on a measurement under any tool: picks it, leaving the content\n * selection as it was. */\nexport function measurePickAction(ms: Measurements): Action {\n return defineAction({\n id: MEASURE_ACTION_IDS.pick,\n label: 'Pick Measurement',\n invoker: {\n timing: 'immediate',\n run: (_deps, params) => {\n const hit = hitOf(params?.affordance);\n if (hit) ms.picked.set(hit.id);\n },\n },\n });\n}\n\n/** The node `id` on `scene`, as a measurement edit reads it. */\nfunction nodeOf(scene: AnyScene | undefined, id: NodeId) {\n return scene?.get(id);\n}\n\n/**\n * A drag on a measurement under any tool. On an end of the picked\n * measurement it moves that end, keeping its offset from the press, through\n * a `point` session of the `snap` dep in which the measurement's own ends\n * offer nothing; anywhere else on a\n * measurement it carries the whole measurement with the pointer. Either way\n * each moved end records the unit-scope frame it lands in. Previewed while it\n * runs; one undo step on release.\n */\nexport function measureDragAction(ms: Measurements): Action {\n return {\n id: MEASURE_ACTION_IDS.drag,\n label: 'Drag Measurement',\n modifierRoles: SNAP_ROLES,\n requires: ['scene', 'snap', 'applyOps', 'selection'],\n invoker: {\n timing: 'ongoing',\n start(ctx: InvocationCtx): OngoingHandle {\n const hit = hitOf(ctx.drag?.affordance);\n const deps = ctx.deps;\n const scene = deps.scene as AnyScene | undefined;\n const node = hit ? nodeOf(scene, hit.id) : undefined;\n if (!hit || !node) return {};\n const end: MeasureEnd | null = hit.part !== 'line' && ms.picked.get() === hit.id ? hit.part : null;\n const from = ctx.drag?.start ?? ctx.world;\n const grabbed = (end && measureEndsOf(node)?.[end]) || from;\n const snap = end ? deps.snap?.begin({ gesture: 'point', press: grabbed, ids: [hit.id] }) ?? null : null;\n const frameAt = framesOf(scene);\n let at = from;\n let landed = grabbed;\n const next = () => (end\n ? withMeasureEnd(node, end, landed, frameAt(landed))\n : translatedMeasure(node, at.x - from.x, at.y - from.y, frameAt));\n const follow = (c: InvocationCtx) => {\n at = pointOf(c);\n const held = { x: grabbed.x + at.x - from.x, y: grabbed.y + at.y - from.y };\n landed = snap ? snap.at(held, snapMods(c)).point : held;\n };\n ms.picked.set(hit.id);\n return {\n kind: MEASURE_ACTION_IDS.drag,\n onMove: follow,\n onEnd: (endCtx, reason) => {\n try {\n if (reason !== 'commit') return;\n follow(endCtx);\n const ops = end\n ? moveEndOps(node, end, landed, frameAt(landed))\n : moveMeasureOps(node, at.x - from.x, at.y - from.y, frameAt);\n commitOps(deps, ops, ops[0]?.label ?? 'Move Measurement');\n } finally {\n snap?.end();\n }\n },\n previewIds: () => [hit.id],\n previewOpaqueIds: () => [hit.id],\n previewPose: () => next()?.pose ?? null,\n previewData: () => next()?.data ?? null,\n };\n },\n },\n };\n}\n","import { polylineFromPoints } from '@weasel-js/geom';\nimport type { DrawCommand } from '@weasel-js/renderer';\nimport { isRectPose, type NodeShapeEntry, OVERLAY_ROLE_STROKES } from '@weasel-js/core';\nimport { measureEndsOf, type MeasurePoint } from './measurement';\n\n/** Screen-px half-length of the tick across each end of a measurement. */\nexport const MEASURE_TICK_PX = 5;\n\n/**\n * A measurement's line and a tick across each end, as the measure painter\n * and the measurements layer draw it. `perPx` is world units per screen pixel, so the\n * line and its ticks keep their screen size at any zoom.\n */\nexport function measureCommands(start: MeasurePoint, end: MeasurePoint, perPx: number): DrawCommand[] {\n const stroke = { ...OVERLAY_ROLE_STROKES['measure'], width: { px: 1 } };\n const len = Math.hypot(end.x - start.x, end.y - start.y);\n // The ticks run across the line; with no length yet they stand upright.\n const nx = len > 0 ? -(end.y - start.y) / len : 0;\n const ny = len > 0 ? (end.x - start.x) / len : 1;\n const half = MEASURE_TICK_PX * perPx;\n const tick = (p: MeasurePoint): DrawCommand => ({\n kind: 'path',\n path: polylineFromPoints([{ x: p.x - nx * half, y: p.y - ny * half }, { x: p.x + nx * half, y: p.y + ny * half }]),\n stroke,\n });\n const out: DrawCommand[] = [tick(start), tick(end)];\n if (len > 0) out.unshift({ kind: 'path', path: polylineFromPoints([start, end]), stroke });\n return out;\n}\n\n/** Paints a measurement node — `data.measure`, in world units — in the\n * canvas's measure color. It has no silhouette: a measurement is not content\n * to pick. `measurementsContribution` registers it for its scene; a render\n * with no canvas registers it itself (`nodeShapesOf(scene).register`). */\nexport const MEASURE_PAINTER: NodeShapeEntry = {\n id: 'measure:measurement',\n matches: (node) => (node.pose === undefined || isRectPose(node.pose)) && measureEndsOf(node) !== null,\n paint: (node, _pose, ctx) => {\n const ends = measureEndsOf(node);\n if (!ends) return [];\n return measureCommands(ends.start, ends.end, 1 / (ctx?.scale ?? 1));\n },\n};\n","import {\n type AnyScene, type LayerHit, OVERLAY_ROLE_STROKES, type RenderLayer, shownLookup, viewToTransform, worldToScreen,\n} from '@weasel-js/core';\nimport type { DrawCommand } from '@weasel-js/renderer';\nimport { pxReach, rectPath } from '@weasel-js/geom';\nimport { measureCommands } from './measurePainter';\nimport { measureEndsOf, type MeasurePoint } from './measurement';\nimport type { Measurements } from './measurements';\nimport { measureAt, type MeasureHit } from './measureHit';\nimport { MEASURE_HIT_PX } from './measureGestures';\n\n/** The registered layer's id; a press it claims routes as `layer:<id>`. */\nexport const MEASURE_LAYER_ID = 'weasel-measure';\n/** The affordance kind a press on a measurement routes under. */\nexport const MEASURE_AFFORDANCE_KIND = `layer:${MEASURE_LAYER_ID}`;\n\nconst HANDLE_PX = 3.5;\n\n/**\n * The measurements' interactive layer, under every tool: it draws the\n * measurement a measure drag is making and a handle on each end of the picked\n * one, and claims a press on a measurement so a click picks it and a drag\n * edits it rather than reaching the tool. Under the measure tool it claims\n * only the picked measurement's ends, so a drag from anywhere else measures.\n */\nexport function measurementsLayer(scene: AnyScene, ms: Measurements): RenderLayer<unknown> {\n return {\n id: MEASURE_LAYER_ID,\n label: 'Measurements',\n space: 'screen',\n subscribe: (listener) => {\n const offs = [ms.picked.subscribe(listener), ms.draft.subscribe(listener), ms.measuring.subscribe(listener)];\n return () => { for (const off of offs) off(); };\n },\n draw: (_data, view) => {\n const t = viewToTransform(view);\n const toScreen = (p: MeasurePoint): MeasurePoint => {\n const [x, y] = worldToScreen(p.x, p.y, t);\n return { x, y };\n };\n const out: DrawCommand[] = [];\n const draft = ms.draft.get();\n if (draft) out.push(...measureCommands(toScreen(draft.start), toScreen(draft.end), 1));\n const picked = ms.picked.get();\n const ends = picked === null ? null : measureEndsOf(shownLookup(scene).get(picked));\n if (ends && !scene.isHidden(picked!)) {\n const stroke = { ...OVERLAY_ROLE_STROKES['measure'], width: 1 };\n for (const p of [ends.start, ends.end].map(toScreen)) {\n out.push({\n kind: 'path',\n path: rectPath(p.x - HANDLE_PX, p.y - HANDLE_PX, HANDLE_PX * 2, HANDLE_PX * 2),\n fill: { paint: { color: '#ffffff' } },\n stroke,\n });\n }\n }\n return out;\n },\n hitTest: (wx, wy, _data, view): LayerHit<MeasureHit> | null => {\n const hit = measureAt(scene, ms, { x: wx, y: wy }, pxReach(MEASURE_HIT_PX, view.scale));\n if (!hit) return null;\n const onPickedEnd = hit.part !== 'line' && hit.id === ms.picked.get();\n if (ms.measuring.get() && !onPickedEnd) return null;\n return {\n initialScratch: hit,\n strength: 'exclusive',\n claimedKinds: ['pointer'],\n cursor: onPickedEnd ? 'crosshair' : 'move',\n };\n },\n };\n}\n","import { ANY_MODS, hitPredicate } from '@weasel-js/gestures';\nimport { nodeShapesOf, type Scene, type SurfaceContribution } from '@weasel-js/core';\nimport type { Measurements } from './measurements';\nimport { measureCommands } from './measureCommands';\nimport { measureDragAction, measurePickAction } from './measureGestures';\nimport { MEASURE_AFFORDANCE_KIND, measurementsLayer } from './measureLayer';\nimport { MEASURE_ACTION_IDS } from './actionIds';\nimport { MEASURE_PAINTER } from './measurePainter';\n\nconst onMeasurement = hitPredicate((hit) => (hit as { kind?: string } | null | undefined)?.kind === MEASURE_AFFORDANCE_KIND);\n\n/**\n * A scene's measurements on a canvas, whatever tool is active: the painter\n * that draws them, the layer that shows the picked one and claims presses on measurements, a click on\n * one to pick it and a drag to edit it, and the commands — Move by, Rotate\n * by, Delete, Clear — a readout binds buttons to. Install it with\n * `<SceneCanvas ambient={[…]}>`; `useMeasureTool` adds the measuring itself.\n */\nexport function measurementsContribution(\n scene: Scene<unknown, string, unknown>,\n ms: Measurements,\n): SurfaceContribution {\n const layer = measurementsLayer(scene, ms);\n return {\n id: 'weasel-measure',\n eligibility: { claimed: true },\n attach: (api) => {\n const offShape = nodeShapesOf(scene).register(MEASURE_PAINTER);\n const offLayer = api.registerLayer(layer);\n api.requestRedraw();\n return () => {\n offLayer();\n offShape();\n };\n },\n actions: [...measureCommands(ms), measurePickAction(ms), measureDragAction(ms)],\n bindings: [\n { spec: { kind: 'click', target: { kindOf: onMeasurement }, mods: ANY_MODS }, actionId: MEASURE_ACTION_IDS.pick, opts: { id: 'weasel-measure.click' } },\n { spec: { kind: 'drag', target: { kindOf: onMeasurement }, mods: ANY_MODS }, actionId: MEASURE_ACTION_IDS.drag, opts: { id: 'weasel-measure.drag' } },\n ],\n };\n}\n","import { useMemo } from 'react';\nimport { useLatest } from '@weasel-js/react';\nimport { defineTool, SNAP_ROLE_MODS, type Tool } from '@weasel-js/core';\nimport { icon } from './icons.gen';\nimport type { ToolKeybinding } from '@weasel-js/routing';\nimport type { Measurements } from './measurements';\nimport { measureCreateAction, measurePickAtAction } from './measureGestures';\nimport { MEASURE_ACTION_IDS } from './actionIds';\nimport type {} from './actionParamSchema';\n\n/** Options for `useMeasureTool`. */\nexport interface UseMeasureToolOptions {\n /** Where the measurements go and which one is picked — the same object the\n * canvas's `measurementsContribution` and a readout are given. */\n measurements: Measurements;\n /** The angle step, in radians, Shift holds a measurement to. Default 15°.\n * Read on every pointer move, so a change mid-drag applies at once. */\n angleStep?: number;\n /** Override the default keybinding (`{ key: 'M' }`). Pass `null` to omit. */\n keybinding?: ToolKeybinding | null;\n}\n\n/**\n * Measure tool. A drag adds a measurement from press to release in world\n * units — both ends through the `snap` dep, Shift holding the angle to\n * `angleStep` — as one undo step, and picks it. A click picks the\n * measurement under it, Escape drops the pick, and Delete removes the\n * current measurement. The measurements are scene nodes on an annotation\n * layer, so they stay when the tool changes; editing them under any tool,\n * and the commands that transform by them, come from\n * `measurementsContribution`, which the canvas installs beside this tool.\n */\nexport function useMeasureTool(options: UseMeasureToolOptions): Tool {\n const { measurements: ms, keybinding } = options;\n const actions = useMemo(() => [measureCreateAction(ms), measurePickAtAction(ms)], [ms]);\n const angleStep = useLatest(options.angleStep);\n\n return useMemo(() => defineTool({\n id: 'measure',\n capabilities: ['navigation'],\n hookName: 'useMeasureTool',\n cursor: 'crosshair',\n presentation: { label: 'Measure', icon: /* @icon */ 'core:measure', group: 'view' },\n ...(keybinding === null ? {} : { keybinding: keybinding ?? { key: 'M' } }),\n actions,\n onActivate: () => ms.measuring.set(true),\n onDeactivate: () => {\n ms.measuring.set(false);\n ms.draft.set(null);\n },\n bindings: [\n { spec: { kind: 'click' }, actionId: MEASURE_ACTION_IDS.pickAt, opts: { id: 'measure.pick' } },\n {\n spec: { kind: 'drag', mods: SNAP_ROLE_MODS },\n actionId: MEASURE_ACTION_IDS.measure,\n opts: { id: 'measure.drag', params: () => (angleStep.current === undefined ? {} : { angleStep: angleStep.current }) },\n },\n { spec: { kind: 'key', key: 'Escape' }, actionId: MEASURE_ACTION_IDS.unpick, opts: { id: 'measure.unpick' } },\n { spec: { kind: 'key', key: 'Delete' }, actionId: MEASURE_ACTION_IDS.delete, opts: { id: 'measure.delete' } },\n { spec: { kind: 'key', key: 'Backspace' }, actionId: MEASURE_ACTION_IDS.delete, opts: { id: 'measure.backspace' } },\n ],\n }), [actions, keybinding, ms, angleStep]);\n}\n","import { useMemo } from 'react';\nimport { toolSet, type Tool, type ToolSet } from '@weasel-js/core';\nimport { useMeasureTool, type UseMeasureToolOptions } from './useMeasureTool';\n\n/** The ids {@link useMeasureTools} keys its tools by. */\nexport type MeasureToolId = 'measure';\n\n/** Every tool `@weasel-js/measure` ships: the measure tool. */\nexport const MEASURE_TOOLS: ToolSet<MeasureToolId> = toolSet('measure', ['measure'], { label: 'Measure' });\n\n/**\n * Every tool in {@link MEASURE_TOOLS}, keyed by id, for `<SceneCanvas tools>` beside the\n * `measurementsContribution` whose actions they bind. `options` go to `useMeasureTool`.\n */\nexport function useMeasureTools(options: UseMeasureToolOptions): Record<MeasureToolId, Tool> {\n const measure = useMeasureTool(options);\n return useMemo(() => ({ measure }), [measure]);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weasel-js/measure",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.19.1",
|
|
4
|
+
"description": "Measuring for a weasel canvas: a measure tool, measurements kept as scene nodes on an annotation layer, and the commands that move and rotate by them.",
|
|
5
|
+
"weasel": {
|
|
6
|
+
"tier": "plugin"
|
|
7
|
+
},
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"author": "orochi235",
|
|
22
|
+
"homepage": "https://orochi235.github.io/weasel/",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/orochi235/weasel.git",
|
|
26
|
+
"directory": "packages/measure"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/orochi235/weasel/issues"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=24"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"test": "node ../../scripts/package-test.mjs"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@weasel-js/gestures": "1.19.1",
|
|
45
|
+
"@weasel-js/icons": "1.19.1",
|
|
46
|
+
"@weasel-js/react": "1.19.1",
|
|
47
|
+
"@weasel-js/registry": "1.19.1",
|
|
48
|
+
"@weasel-js/renderer": "1.19.1",
|
|
49
|
+
"@weasel-js/routing": "1.19.1"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@weasel-js/core": "1.19.1",
|
|
53
|
+
"@weasel-js/geom": "1.19.1",
|
|
54
|
+
"react": ">=18"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public",
|
|
58
|
+
"provenance": true
|
|
59
|
+
}
|
|
60
|
+
}
|