@weasel-js/measure 1.19.1 → 2.0.0
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/README.md +28 -4
- package/dist/MeasureReadout/MeasureReadout.d.ts +24 -0
- package/dist/MeasureReadout/MeasureReadout.d.ts.map +1 -0
- package/dist/MeasureReadout/index.d.ts +3 -0
- package/dist/MeasureReadout/index.d.ts.map +1 -0
- package/dist/actionIds.d.ts +18 -0
- package/dist/actionIds.d.ts.map +1 -0
- package/dist/actionParamSchema.d.ts +15 -0
- package/dist/actionParamSchema.d.ts.map +1 -0
- package/dist/icons.gen.d.ts +3 -0
- package/dist/icons.gen.d.ts.map +1 -0
- package/dist/index.d.ts +11 -195
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +940 -476
- package/dist/index.js.map +1 -1
- package/dist/measureActions.d.ts +35 -0
- package/dist/measureActions.d.ts.map +1 -0
- package/dist/measureCommands.d.ts +12 -0
- package/dist/measureCommands.d.ts.map +1 -0
- package/dist/measureContribution.d.ts +11 -0
- package/dist/measureContribution.d.ts.map +1 -0
- package/dist/measureEdits.d.ts +29 -0
- package/dist/measureEdits.d.ts.map +1 -0
- package/dist/measureHit.d.ts +22 -0
- package/dist/measureHit.d.ts.map +1 -0
- package/dist/measureLayer.d.ts +15 -0
- package/dist/measureLayer.d.ts.map +1 -0
- package/dist/measurePainter.d.ts +17 -0
- package/dist/measurePainter.d.ts.map +1 -0
- package/dist/measurement.d.ts +71 -0
- package/dist/measurement.d.ts.map +1 -0
- package/dist/measurements.d.ts +39 -0
- package/dist/measurements.d.ts.map +1 -0
- package/dist/style.css +47 -0
- package/dist/toolSets.d.ts +12 -0
- package/dist/toolSets.d.ts.map +1 -0
- package/dist/useMeasureTool.d.ts +26 -0
- package/dist/useMeasureTool.d.ts.map +1 -0
- package/package.json +23 -13
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type AnyNode, type AnyScene, type NodeId, type Op } from '@weasel-js/core';
|
|
2
|
+
import { type MeasureData, type MeasureEnd, type MeasureFrameAt, type MeasureFrames, type MeasurePoint } from './measurement.js';
|
|
3
|
+
/** The labels measurement edits land in history under. */
|
|
4
|
+
export declare const MEASURE_LABELS: {
|
|
5
|
+
readonly add: "Measure";
|
|
6
|
+
readonly moveEnd: "Move Measurement End";
|
|
7
|
+
readonly move: "Move Measurement";
|
|
8
|
+
readonly delete: "Delete Measurement";
|
|
9
|
+
readonly clear: "Clear Measurements";
|
|
10
|
+
};
|
|
11
|
+
/** The op adding a measurement from `start` to `end` on `layer`, at the top,
|
|
12
|
+
* its ends landed in `frames`. */
|
|
13
|
+
export declare function addMeasureOp(scene: AnyScene, layer: string, start: MeasurePoint, end: MeasurePoint, frames?: MeasureFrames): {
|
|
14
|
+
id: NodeId;
|
|
15
|
+
op: Op;
|
|
16
|
+
};
|
|
17
|
+
/** The ops moving `node`'s `which` end to `to`, landed in `frame`. */
|
|
18
|
+
export declare function moveEndOps(node: AnyNode, which: MeasureEnd, to: MeasurePoint, frame?: NodeId | null): Op[];
|
|
19
|
+
/** `node` carried by `(dx, dy)`, both ends together, each landing where
|
|
20
|
+
* `frameAt` says. Without `frameAt` the ends keep the frames they had. */
|
|
21
|
+
export declare function translatedMeasure(node: AnyNode, dx: number, dy: number, frameAt?: MeasureFrameAt): {
|
|
22
|
+
data: MeasureData;
|
|
23
|
+
pose: unknown;
|
|
24
|
+
} | null;
|
|
25
|
+
/** The ops carrying `node` by `(dx, dy)`, its ends landing where `frameAt` says. */
|
|
26
|
+
export declare function moveMeasureOps(node: AnyNode, dx: number, dy: number, frameAt?: MeasureFrameAt): Op[];
|
|
27
|
+
/** The ops deleting each of `ids`, as one edit labeled `label`. */
|
|
28
|
+
export declare function deleteMeasureOps(scene: AnyScene, ids: readonly NodeId[], label: string): Op[];
|
|
29
|
+
//# sourceMappingURL=measureEdits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measureEdits.d.ts","sourceR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M,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,EAAE,EAAE,CAO7F"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type NodeId, type Scene, type SnapSource } from '@weasel-js/core';
|
|
2
|
+
import { type MeasureEnd, type MeasurePoint } from './measurement.js';
|
|
3
|
+
import { type Measurements } from './measurements.js';
|
|
4
|
+
/** Which part of which measurement lies under a point. */
|
|
5
|
+
export interface MeasureHit {
|
|
6
|
+
id: NodeId;
|
|
7
|
+
part: MeasureEnd | 'line';
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The measurement under `p`, newest first: an end within `tolerance` world
|
|
11
|
+
* units of it, else a line within the same distance. A hidden or locked
|
|
12
|
+
* measurement (`nodeGates`) is passed over.
|
|
13
|
+
*/
|
|
14
|
+
export declare function measureHitAt(scene: Pick<Scene<unknown, string, unknown>, 'nodesOnLayer' | 'get' | 'layers' | 'overrides'>, ms: Pick<Measurements, 'layer'>, p: MeasurePoint, tolerance: number): MeasureHit | null;
|
|
15
|
+
/** Options for `measureEndSource`. */
|
|
16
|
+
export interface MeasureEndSourceOptions {
|
|
17
|
+
/** Overrides the canvas's reach for measurement ends, in screen px. */
|
|
18
|
+
reachPx?: number;
|
|
19
|
+
}
|
|
20
|
+
/** The ends of every shown measurement as snap targets for a pointer probe. */
|
|
21
|
+
export declare function measureEndSource(opts?: MeasureEndSourceOptions): SnapSource;
|
|
22
|
+
//# sourceMappingURL=measureHit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measureHit.d.ts","sourceRoot":"","sources":["../src/measureHit.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,MAAM,EAAgB,KAAK,KAAK,EAAe,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACjH,OAAO,EAAiB,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE/D,0DAA0D;AAC1D,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;CAC3B;AAGD;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,WAAW,CAAC,EAC7F,EAAE,EAAE,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,EAC/B,CAAC,EAAE,YAAY,EACf,SAAS,EAAE,MAAM,GAChB,UAAU,GAAG,IAAI,CAiBnB;AAED,sCAAsC;AACtC,MAAM,WAAW,uBAAuB;IACtC,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAAC,IAAI,GAAE,uBAA4B,GAAG,UAAU,CAuB/E"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type AnyScene, type RenderLayer } from '@weasel-js/core';
|
|
2
|
+
import type { Measurements } from './measurements.js';
|
|
3
|
+
/** The registered layer's id; a press it claims routes as `layer:<id>`. */
|
|
4
|
+
export declare const MEASURE_LAYER_ID = "weasel-measure";
|
|
5
|
+
/** The affordance kind a press on a measurement routes under. */
|
|
6
|
+
export declare const MEASURE_AFFORDANCE_KIND = "layer:weasel-measure";
|
|
7
|
+
/**
|
|
8
|
+
* The measurements' interactive layer, under every tool: it draws the
|
|
9
|
+
* measurement a measure drag is making and a handle on each end of the picked
|
|
10
|
+
* one, and claims a press on a measurement so a click picks it and a drag
|
|
11
|
+
* edits it rather than reaching the tool. Under the measure tool it claims
|
|
12
|
+
* only the picked measurement's ends, so a drag from anywhere else measures.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createMeasureLayer(scene: AnyScene, ms: Measurements): RenderLayer<unknown>;
|
|
15
|
+
//# sourceMappingURL=measureLayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measureLayer.d.ts","sourceRoot":"","sources":["../src/measureLayer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EAAuC,KAAK,WAAW,EACrE,MAAM,iBAAiB,CAAC;AAKzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAInD,2EAA2E;AAC3E,eAAO,MAAM,gBAAgB,mBAAmB,CAAC;AACjD,iEAAiE;AACjE,eAAO,MAAM,uBAAuB,yBAA8B,CAAC;AAInE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,YAAY,GAAG,WAAW,CAAC,OAAO,CAAC,CA8C1F"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DrawCommand } from '@weasel-js/renderer';
|
|
2
|
+
import { type NodeShapeEntry } from '@weasel-js/core';
|
|
3
|
+
import { type MeasurePoint } from './measurement.js';
|
|
4
|
+
/** Screen-px half-length of the tick across each end of a measurement. */
|
|
5
|
+
export declare const MEASURE_TICK_PX = 5;
|
|
6
|
+
/**
|
|
7
|
+
* A measurement's line and a tick across each end, as the measure painter
|
|
8
|
+
* and the measurements layer draw it. `perPx` is world units per screen pixel, so the
|
|
9
|
+
* line and its ticks keep their screen size at any zoom.
|
|
10
|
+
*/
|
|
11
|
+
export declare function measureDrawCommands(start: MeasurePoint, end: MeasurePoint, perPx: number): DrawCommand[];
|
|
12
|
+
/** Paints a measurement node — `data.measure`, in world units — in the
|
|
13
|
+
* canvas's measure color. It has no silhouette: a measurement is not content
|
|
14
|
+
* to pick. `createMeasurementsContribution` registers it for its scene; a render
|
|
15
|
+
* with no canvas registers it itself (`nodeShapesOf(scene).register`). */
|
|
16
|
+
export declare const MEASURE_PAINTER: NodeShapeEntry;
|
|
17
|
+
//# sourceMappingURL=measurePainter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measurePainter.d.ts","sourceRoot":"","sources":["../src/measurePainter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAc,KAAK,cAAc,EAAwB,MAAM,iBAAiB,CAAC;AACxF,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAEjE,0EAA0E;AAC1E,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE,CAexG;AAED;;;2EAG2E;AAC3E,eAAO,MAAM,eAAe,EAAE,cAQ7B,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type MarkNode, type NodeId, type SceneNode, type RectPose, type ScopedScene } from '@weasel-js/core';
|
|
2
|
+
import { type Point } from '@weasel-js/geom';
|
|
3
|
+
/** A world-space point. */
|
|
4
|
+
export type MeasurePoint = Point;
|
|
5
|
+
/**
|
|
6
|
+
* The frame each end of a measurement landed in: the node declaring a unit
|
|
7
|
+
* scope it was placed inside (`createUnitFrameLookup`), or `null` for the top of the
|
|
8
|
+
* tree. The measurement reads in the scope chain the two frames share, so ends
|
|
9
|
+
* in one frame, or in frames declaring equal scopes, read that frame's
|
|
10
|
+
* modeled length, and ends whose frames disagree read the innermost frame
|
|
11
|
+
* holding both, which is world when only the root does.
|
|
12
|
+
*/
|
|
13
|
+
export interface MeasureFrames {
|
|
14
|
+
readonly start: NodeId | null;
|
|
15
|
+
readonly end: NodeId | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The offset from `start` to `end`, in world units. `dx` and `dy` are on the
|
|
19
|
+
* world's own axes, where y grows downward; `angle` reads like a protractor
|
|
20
|
+
* instead, counterclockwise-positive on screen, so a line rising up and to
|
|
21
|
+
* the right at 30° reads +30°. The canvas's own rotations are
|
|
22
|
+
* clockwise-positive: a rotate that follows the line turns by `-angle`.
|
|
23
|
+
*/
|
|
24
|
+
export interface Measurement {
|
|
25
|
+
readonly start: MeasurePoint;
|
|
26
|
+
readonly end: MeasurePoint;
|
|
27
|
+
readonly dx: number;
|
|
28
|
+
readonly dy: number;
|
|
29
|
+
readonly distance: number;
|
|
30
|
+
/** `atan2(-dy, dx)`, in `(-π, π]`. Zero for a zero-length measurement. */
|
|
31
|
+
readonly angle: number;
|
|
32
|
+
/** The frames its ends landed in. Absent, it reads in world. */
|
|
33
|
+
readonly frames?: MeasureFrames;
|
|
34
|
+
}
|
|
35
|
+
/** Measure from `start` to `end`, landed in `frames`. */
|
|
36
|
+
export declare function measureBetween(start: MeasurePoint, end: MeasurePoint, frames?: MeasureFrames): Measurement;
|
|
37
|
+
/** How large the frame `frames` share is drawn in world: a measurement's
|
|
38
|
+
* world lengths divided by it are its modeled lengths. 1 without frames. */
|
|
39
|
+
export declare function measureMagnification(scene: ScopedScene, frames: MeasureFrames | undefined): number;
|
|
40
|
+
/** What a measurement node keeps in `data`: its two ends, in world units, and
|
|
41
|
+
* the frames they landed in. A `label` beside it names the node in a layer
|
|
42
|
+
* list. */
|
|
43
|
+
export interface MeasureData {
|
|
44
|
+
measure: {
|
|
45
|
+
start: MeasurePoint;
|
|
46
|
+
end: MeasurePoint;
|
|
47
|
+
frames?: MeasureFrames;
|
|
48
|
+
};
|
|
49
|
+
label?: string;
|
|
50
|
+
}
|
|
51
|
+
/** Where an end placed at a world point lands: what a `createUnitFrameLookup` lookup answers. */
|
|
52
|
+
export type MeasureFrameAt = (p: MeasurePoint) => NodeId | null;
|
|
53
|
+
/** Which end of a measurement. */
|
|
54
|
+
export type MeasureEnd = 'start' | 'end';
|
|
55
|
+
/** The ends `node` measures between, or null when it is not a measurement. */
|
|
56
|
+
export declare function measureEndsOf(node: Pick<SceneNode<unknown, string, unknown>, 'data'> | undefined): MeasureData['measure'] | null;
|
|
57
|
+
/** The measurement `node` holds, or null when it is not one. */
|
|
58
|
+
export declare function measurementOf(node: Pick<SceneNode<unknown, string, unknown>, 'data'> | undefined): Measurement | null;
|
|
59
|
+
/** The box a measurement's pose holds: its two ends' bounds, which is what
|
|
60
|
+
* culling, area queries, and fitting the view read. */
|
|
61
|
+
export declare function measurePose(start: MeasurePoint, end: MeasurePoint): RectPose;
|
|
62
|
+
/** A measurement node on `layer`, ready to insert, or to list in a scene's
|
|
63
|
+
* `initial` nodes: typed with that layer and a `RectPose`. */
|
|
64
|
+
export declare function measureNode<TLayer extends string>(id: NodeId, layer: TLayer, start: MeasurePoint, end: MeasurePoint, frames?: MeasureFrames): MarkNode<MeasureData, TLayer, RectPose>;
|
|
65
|
+
/** `node`'s data and pose with its `which` end moved to `to`, landed in
|
|
66
|
+
* `frame`. Without `frame` the end keeps the one it had. */
|
|
67
|
+
export declare function withMeasureEnd(node: SceneNode<unknown, string, unknown>, which: MeasureEnd, to: MeasurePoint, frame?: NodeId | null): {
|
|
68
|
+
data: MeasureData;
|
|
69
|
+
pose: RectPose;
|
|
70
|
+
} | null;
|
|
71
|
+
//# sourceMappingURL=measurement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measurement.d.ts","sourceRoot":"","sources":["../src/measurement.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAsB,KAAK,WAAW,EAChG,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE1D,2BAA2B;AAC3B,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC;AAEjC;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;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E,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,WAAW,GAAG,IAAI,CAGrH;AAED;wDACwD;AACxD,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,GAAG,QAAQ,CAE5E;AAED;+DAC+D;AAC/D,wBAAgB,WAAW,CAAC,MAAM,SAAS,MAAM,EAC/C,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,YAAY,EACnB,GAAG,EAAE,YAAY,EACjB,MAAM,CAAC,EAAE,aAAa,GACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,CAGzC;AAED;6DAC6D;AAC7D,wBAAgB,cAAc,CAC5B,IAAI,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EACzC,KAAK,EAAE,UAAU,EACjB,EAAE,EAAE,YAAY,EAChB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG,IAAI,CAO9C"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ValueStore } from '@weasel-js/registry';
|
|
2
|
+
import { type NodeId, type Scene } from '@weasel-js/core';
|
|
3
|
+
import { type Measurement } from './measurement.js';
|
|
4
|
+
/** One value, readable and watchable — what a readout re-renders from. */
|
|
5
|
+
export type MeasureCell<T> = ValueStore<T>;
|
|
6
|
+
/**
|
|
7
|
+
* Where a scene's measurements go, and the state around them that is not
|
|
8
|
+
* the document's: which one is picked, and the one a measure drag is still
|
|
9
|
+
* drawing. The measurements themselves are nodes on `layer`, an annotation
|
|
10
|
+
* layer (`isAnnotationLayer`), so they save with the scene, undo with it,
|
|
11
|
+
* and stay out of export and content picking.
|
|
12
|
+
*
|
|
13
|
+
* The pick sits beside the content selection rather than in it: picking a
|
|
14
|
+
* measurement leaves the selection alone, so Move by can carry the selection
|
|
15
|
+
* by the picked measurement.
|
|
16
|
+
*/
|
|
17
|
+
export interface Measurements {
|
|
18
|
+
/** The annotation layer new measurements are added to. */
|
|
19
|
+
readonly layer: string;
|
|
20
|
+
/** The picked measurement's id. */
|
|
21
|
+
readonly picked: MeasureCell<NodeId | null>;
|
|
22
|
+
/** The measurement a measure drag is drawing, before it is added. */
|
|
23
|
+
readonly draft: MeasureCell<Measurement | null>;
|
|
24
|
+
/** Whether the measure tool is active, which changes what a press on a
|
|
25
|
+
* measurement does: under it, only the picked one's ends take a drag, so a
|
|
26
|
+
* drag from anywhere else starts a new measurement. */
|
|
27
|
+
readonly measuring: MeasureCell<boolean>;
|
|
28
|
+
}
|
|
29
|
+
/** The measurements on `layer`, none picked and none in progress. */
|
|
30
|
+
export declare function createMeasurements(options: {
|
|
31
|
+
layer: string;
|
|
32
|
+
}): Measurements;
|
|
33
|
+
/** The measurement nodes on `ms.layer`, oldest first. */
|
|
34
|
+
export declare function measureIds(scene: Pick<Scene<unknown, string, unknown>, 'nodesOnLayer'>, ms: Pick<Measurements, 'layer'>): NodeId[];
|
|
35
|
+
/** The measurement commands act on: the picked one while it is still in the
|
|
36
|
+
* scene, else the newest. A hidden one (`nodeGates`), which nothing draws, is
|
|
37
|
+
* passed over as the hit test passes over it. */
|
|
38
|
+
export declare function currentMeasureId(scene: Pick<Scene<unknown, string, unknown>, 'nodesOnLayer' | 'get'> & Partial<Pick<Scene<unknown, string, unknown>, 'layers'>>, ms: Pick<Measurements, 'layer' | 'picked'>): NodeId | null;
|
|
39
|
+
//# sourceMappingURL=measurements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measurements.d.ts","sourceRoot":"","sources":["../src/measurements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC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MAAM,GAAG,IAAI,CAKf"}
|
package/dist/style.css
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* Numeric text: equal-width digits in the UI face. This is the one definition —
|
|
2
|
+
* compose it, mix it into Less, or put its class on the element; never restate
|
|
3
|
+
* the pair. `npm run check:numeric` holds every stylesheet to that. */._numeric_25fd0b {
|
|
4
|
+
font-family: var(--wzl-font-numeric);
|
|
5
|
+
font-variant-numeric: tabular-nums;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
._readout_7e51b2 {
|
|
9
|
+
position: absolute;
|
|
10
|
+
bottom: var(--wzl-space-6);
|
|
11
|
+
left: 50%;
|
|
12
|
+
translate: -50% 0;
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
gap: var(--wzl-space-5);
|
|
16
|
+
padding: var(--wzl-space-2) var(--wzl-space-5);
|
|
17
|
+
border-radius: var(--wzl-radius-md);
|
|
18
|
+
background: color-mix(in srgb, var(--wzl-surface-raised) 78%, transparent);
|
|
19
|
+
backdrop-filter: blur(var(--wzl-glass-blur));
|
|
20
|
+
color: var(--wzl-fg);
|
|
21
|
+
font-size: var(--wzl-font-size-sm);
|
|
22
|
+
white-space: nowrap;
|
|
23
|
+
z-index: var(--wzl-z-overlay);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
._actions_7e51b2 {
|
|
27
|
+
flex: none;
|
|
28
|
+
display: flex;
|
|
29
|
+
gap: var(--wzl-space-2);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
._cell_7e51b2 {
|
|
33
|
+
display: inline-flex;
|
|
34
|
+
gap: var(--wzl-space-2);
|
|
35
|
+
align-items: baseline;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
._name_7e51b2 {
|
|
39
|
+
color: var(--wzl-fg-muted);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* Sized for the widest value a page holds, so a live readout does not shift its neighbors. */
|
|
43
|
+
._value_7e51b2 {
|
|
44
|
+
min-width: 9ch;
|
|
45
|
+
text-align: end;
|
|
46
|
+
}
|
|
47
|
+
/*$vite$:1*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Tool, type ToolSet } from '@weasel-js/core';
|
|
2
|
+
import { type UseMeasureToolOptions } from './useMeasureTool.js';
|
|
3
|
+
/** The ids {@link useMeasureTools} keys its tools by. */
|
|
4
|
+
export type MeasureToolId = 'measure';
|
|
5
|
+
/** Every tool `@weasel-js/measure` ships: the measure tool. */
|
|
6
|
+
export declare const MEASURE_TOOLS: ToolSet<MeasureToolId>;
|
|
7
|
+
/**
|
|
8
|
+
* Every tool in {@link MEASURE_TOOLS}, keyed by id, for `<SceneCanvas tools>` beside the
|
|
9
|
+
* `createMeasurementsContribution` whose actions they bind. `options` go to `useMeasureTool`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useMeasureTools(options: UseMeasureToolOptions): Record<MeasureToolId, Tool>;
|
|
12
|
+
//# sourceMappingURL=toolSets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolSets.d.ts","sourceRoot":"","sources":["../src/toolSets.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,KAAK,IAAI,EAAE,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,yDAAyD;AACzD,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC;AAEtC,+DAA+D;AAC/D,eAAO,MAAM,aAAa,EAAE,OAAO,CAAC,aAAa,CAAyD,CAAC;AAE3G;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,CAG3F"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Tool } from '@weasel-js/core';
|
|
2
|
+
import type { ToolKeybinding } from '@weasel-js/routing';
|
|
3
|
+
import type { Measurements } from './measurements.js';
|
|
4
|
+
/** Options for `useMeasureTool`. */
|
|
5
|
+
export interface UseMeasureToolOptions {
|
|
6
|
+
/** Where the measurements go and which one is picked — the same object the
|
|
7
|
+
* canvas's `createMeasurementsContribution` and a readout are given. */
|
|
8
|
+
measurements: Measurements;
|
|
9
|
+
/** The angle step, in radians, Shift holds a measurement to. Default 15°.
|
|
10
|
+
* Read on every pointer move, so a change mid-drag applies at once. */
|
|
11
|
+
angleStep?: number;
|
|
12
|
+
/** Override the default keybinding (`{ key: 'M' }`). Pass `null` to omit. */
|
|
13
|
+
keybinding?: ToolKeybinding | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Measure tool. A drag adds a measurement from press to release in world
|
|
17
|
+
* units — both ends through the `snap` dep, Shift holding the angle to
|
|
18
|
+
* `angleStep` — as one undo step, and picks it. A click picks the
|
|
19
|
+
* measurement under it, Escape drops the pick, and Delete removes the
|
|
20
|
+
* current measurement. The measurements are scene nodes on an annotation
|
|
21
|
+
* layer, so they stay when the tool changes; editing them under any tool,
|
|
22
|
+
* and the commands that transform by them, come from
|
|
23
|
+
* `createMeasurementsContribution`, which the canvas installs beside this tool.
|
|
24
|
+
*/
|
|
25
|
+
export declare function useMeasureTool(options: UseMeasureToolOptions): Tool;
|
|
26
|
+
//# sourceMappingURL=useMeasureTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMeasureTool.d.ts","sourceRoot":"","sources":["../src/useMeasureTool.ts"],"names":[],"mappings":"AAEA,OAAO,EAA8B,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAExE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAKnD,oCAAoC;AACpC,MAAM,WAAW,qBAAqB;IACpC;6EACyE;IACzE,YAAY,EAAE,YAAY,CAAC;IAC3B;4EACwE;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,UAAU,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CACpC;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,CA8BnE"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weasel-js/measure",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Measuring for a weasel canvas: a measure tool, measurements kept as scene nodes on an annotation layer,
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Measuring for a weasel canvas: a measure tool, measurements kept as scene nodes on an annotation layer, the commands that move and rotate by them, and a readout that shows them.",
|
|
5
5
|
"weasel": {
|
|
6
6
|
"tier": "plugin"
|
|
7
7
|
},
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|
|
10
|
-
"sideEffects":
|
|
10
|
+
"sideEffects": [
|
|
11
|
+
"*.css"
|
|
12
|
+
],
|
|
11
13
|
"main": "./dist/index.js",
|
|
12
14
|
"module": "./dist/index.js",
|
|
13
15
|
"types": "./dist/index.d.ts",
|
|
@@ -16,6 +18,7 @@
|
|
|
16
18
|
"types": "./dist/index.d.ts",
|
|
17
19
|
"import": "./dist/index.js"
|
|
18
20
|
},
|
|
21
|
+
"./style.css": "./dist/style.css",
|
|
19
22
|
"./package.json": "./package.json"
|
|
20
23
|
},
|
|
21
24
|
"author": "orochi235",
|
|
@@ -37,24 +40,31 @@
|
|
|
37
40
|
"LICENSE"
|
|
38
41
|
],
|
|
39
42
|
"scripts": {
|
|
40
|
-
"build": "
|
|
43
|
+
"build": "vite build && tsc -p tsconfig.build.json && node ../../scripts/dts-extensions.mjs dist",
|
|
41
44
|
"test": "node ../../scripts/package-test.mjs"
|
|
42
45
|
},
|
|
43
46
|
"dependencies": {
|
|
44
|
-
"@weasel-js/
|
|
45
|
-
"@weasel-js/
|
|
46
|
-
"@weasel-js/
|
|
47
|
-
"@weasel-js/
|
|
48
|
-
"@weasel-js/
|
|
49
|
-
"@weasel-js/
|
|
47
|
+
"@weasel-js/editing": "2.0.0",
|
|
48
|
+
"@weasel-js/gestures": "2.0.0",
|
|
49
|
+
"@weasel-js/icons": "2.0.0",
|
|
50
|
+
"@weasel-js/quantity": "2.0.0",
|
|
51
|
+
"@weasel-js/react": "2.0.0",
|
|
52
|
+
"@weasel-js/registry": "2.0.0",
|
|
53
|
+
"@weasel-js/renderer": "2.0.0",
|
|
54
|
+
"@weasel-js/routing": "2.0.0",
|
|
55
|
+
"@weasel-js/ui": "2.0.0"
|
|
50
56
|
},
|
|
51
57
|
"peerDependencies": {
|
|
52
|
-
"@weasel-js/core": "
|
|
53
|
-
"@weasel-js/geom": "
|
|
54
|
-
"react": ">=18"
|
|
58
|
+
"@weasel-js/core": "2.0.0",
|
|
59
|
+
"@weasel-js/geom": "2.0.0",
|
|
60
|
+
"react": ">=18",
|
|
61
|
+
"react-dom": ">=18"
|
|
55
62
|
},
|
|
56
63
|
"publishConfig": {
|
|
57
64
|
"access": "public",
|
|
58
65
|
"provenance": true
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@weasel-js/theme": "2.0.0"
|
|
59
69
|
}
|
|
60
70
|
}
|