@weasel-js/measure 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +55 -2
- 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 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1022 -0
- package/dist/index.js.map +1 -0
- 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 +68 -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,56 @@
|
|
|
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(() => [createMeasurementsContribution(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. `MEASURE_TOOLS` names the tool for
|
|
31
|
+
a palette. A render with no canvas registers `MEASURE_PAINTER` itself.
|
|
32
|
+
|
|
33
|
+
## The readout
|
|
34
|
+
|
|
35
|
+
`<MeasureReadout>` is a chip pinned to the bottom of its nearest positioned
|
|
36
|
+
ancestor. It shows the measurement a drag is drawing, else the picked one,
|
|
37
|
+
else the newest: its distance, offsets and angle, in the units of the frame
|
|
38
|
+
its ends landed in. Its Move by, Rotate by, Delete and Clear all buttons run
|
|
39
|
+
the contribution's commands from the actions registry, and one that cannot run
|
|
40
|
+
says why in its tooltip. It reads the canvas's registries, so it and the
|
|
41
|
+
canvas share one `<DepRegistryProvider>` and `<ActionsProvider>`. It draws with
|
|
42
|
+
`@weasel-js/ui`'s components, so load both stylesheets.
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import '@weasel-js/ui/style.css';
|
|
46
|
+
import '@weasel-js/measure/style.css';
|
|
47
|
+
|
|
48
|
+
<DepRegistryProvider>
|
|
49
|
+
<ActionsProvider>
|
|
50
|
+
<div className="stage">
|
|
51
|
+
<SceneCanvas scene={scene} tools={[tools.measure]} ambient={ambient} />
|
|
52
|
+
<MeasureReadout scene={scene} measurements={measurements} />
|
|
53
|
+
</div>
|
|
54
|
+
</ActionsProvider>
|
|
55
|
+
</DepRegistryProvider>
|
|
56
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type Scene } from '@weasel-js/core';
|
|
3
|
+
import { type Measurements } from '../measurements.js';
|
|
4
|
+
/** Props for {@link MeasureReadout}. */
|
|
5
|
+
export interface MeasureReadoutProps {
|
|
6
|
+
/** The scene the measurements are nodes of. */
|
|
7
|
+
scene: Scene<unknown, string, unknown>;
|
|
8
|
+
/** The same object `useMeasureTool` and `createMeasurementsContribution` are given. */
|
|
9
|
+
measurements: Measurements;
|
|
10
|
+
/** Additional class for the root, to place it. */
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The measurement readout: a chip pinned to the bottom of the nearest
|
|
15
|
+
* positioned ancestor, showing the measurement a measure drag is drawing,
|
|
16
|
+
* else the picked one, else the newest — its distance, offset, and angle in
|
|
17
|
+
* the units of the frame its ends landed in, its world lengths divided by that
|
|
18
|
+
* frame's magnification (`measureMagnification`) — with Move by, Rotate by, Delete, and Clear all from the
|
|
19
|
+
* actions registry. A command that cannot run says why in its tooltip. The
|
|
20
|
+
* angle reads like a protractor, counterclockwise-positive: a line rising to
|
|
21
|
+
* the right at 30° reads 30°, and Rotate by turns the selection that way.
|
|
22
|
+
*/
|
|
23
|
+
export declare function MeasureReadout({ scene, measurements: ms, className }: MeasureReadoutProps): ReactElement | null;
|
|
24
|
+
//# sourceMappingURL=MeasureReadout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MeasureReadout.d.ts","sourceRoot":"","sources":["../../src/MeasureReadout/MeasureReadout.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAKL,KAAK,KAAK,EAEX,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAetE,wCAAwC;AACxC,MAAM,WAAW,mBAAmB;IAClC,+CAA+C;IAC/C,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,uFAAuF;IACvF,YAAY,EAAE,YAAY,CAAC;IAC3B,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAaD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,mBAAmB,GAAG,YAAY,GAAG,IAAI,CAgD/G"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/MeasureReadout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** The ids of the measure feature's actions. */
|
|
2
|
+
export declare const MEASURE_ACTION_IDS: {
|
|
3
|
+
/** The measure tool's drag, which adds a measurement. */
|
|
4
|
+
readonly measure: "measure";
|
|
5
|
+
/** The measure tool's click, which picks the measurement under it. */
|
|
6
|
+
readonly pickAt: "measure.pickAt";
|
|
7
|
+
/** A click on a measurement under any tool, which picks it. */
|
|
8
|
+
readonly pick: "measure.pick";
|
|
9
|
+
/** A drag on a measurement under any tool: a picked end moves that end, the
|
|
10
|
+
* rest moves the whole measurement. */
|
|
11
|
+
readonly drag: "measure.drag";
|
|
12
|
+
readonly moveBy: "measure.moveBy";
|
|
13
|
+
readonly rotateBy: "measure.rotateBy";
|
|
14
|
+
readonly delete: "measure.delete";
|
|
15
|
+
readonly clear: "measure.clear";
|
|
16
|
+
readonly unpick: "measure.unpick";
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=actionIds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionIds.d.ts","sourceRoot":"","sources":["../src/actionIds.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,eAAO,MAAM,kBAAkB;IAC7B,yDAAyD;;IAEzD,sEAAsE;;IAEtE,+DAA+D;;IAE/D;4CACwC;;;;;;;CAOhC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The params this package's actions read, merged into routing's
|
|
3
|
+
* `ActionParamSchema` so `<SceneCanvas tune>` types them.
|
|
4
|
+
*/
|
|
5
|
+
import type { ImmediateParams } from '@weasel-js/routing';
|
|
6
|
+
declare module '@weasel-js/routing' {
|
|
7
|
+
interface ActionParamSchema {
|
|
8
|
+
measure: {
|
|
9
|
+
angleStep?: number;
|
|
10
|
+
};
|
|
11
|
+
'measure.pickAt': Pick<ImmediateParams, 'press'>;
|
|
12
|
+
'measure.pick': Pick<ImmediateParams, 'affordance'>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=actionParamSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionParamSchema.d.ts","sourceRoot":"","sources":["../src/actionParamSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,QAAQ,oBAAoB,CAAC;IAClC,UAAU,iBAAiB;QACzB,OAAO,EAAE;YAAE,SAAS,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAChC,gBAAgB,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QACjD,cAAc,EAAE,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;KACrD;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icons.gen.d.ts","sourceRoot":"","sources":["../src/icons.gen.ts"],"names":[],"mappings":"AAIA,yGAAyG;AACzG,eAAO,MAAM,IAAI,4FAA+B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { measureBetween, measurementOf, measureEndsOf, measureMagnification, measurePose, measureNode, type Measurement, type MeasurePoint, type MeasureData, type MeasureEnd, type MeasureFrames, type MeasureFrameAt, } from './measurement.js';
|
|
2
|
+
export { createMeasurements, currentMeasureId, measureIds, type Measurements, type MeasureCell, } from './measurements.js';
|
|
3
|
+
export { measureHitAt, measureEndSource, type MeasureEndSourceOptions, type MeasureHit } from './measureHit.js';
|
|
4
|
+
export { createMeasurementsContribution } from './measureContribution.js';
|
|
5
|
+
export { MEASURE_ACTION_IDS } from './actionIds.js';
|
|
6
|
+
export { MEASURE_AFFORDANCE_KIND, MEASURE_LAYER_ID } from './measureLayer.js';
|
|
7
|
+
export { MEASURE_PAINTER } from './measurePainter.js';
|
|
8
|
+
export { useMeasureTool, type UseMeasureToolOptions } from './useMeasureTool.js';
|
|
9
|
+
export { MEASURE_TOOLS, useMeasureTools, type MeasureToolId } from './toolSets.js';
|
|
10
|
+
export { MeasureReadout, type MeasureReadoutProps } from './MeasureReadout/index.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,oBAAoB,EAAE,WAAW,EAAE,WAAW,EAC5F,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,cAAc,GAChH,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAAE,gBAAgB,EAAE,UAAU,EAChD,KAAK,YAAY,EAAE,KAAK,WAAW,GACpC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC7G,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
|