@opsydyn/effect-three-foldkit 0.4.0 → 1.0.0-next.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/CHANGELOG.md +39 -0
- package/README.md +29 -23
- package/dist/boxSelect.d.ts +91 -117
- package/dist/boxSelect.d.ts.map +1 -1
- package/dist/browser.d.ts +3 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +32 -0
- package/dist/browser.js.map +10 -0
- package/dist/element.d.ts +13 -869
- package/dist/element.d.ts.map +1 -1
- package/dist/index.d.ts +17 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +173 -2383
- package/dist/index.js.map +14 -38
- package/dist/inspector.d.ts +4 -21
- package/dist/inspector.d.ts.map +1 -1
- package/dist/measuringTape.d.ts +39 -46
- package/dist/measuringTape.d.ts.map +1 -1
- package/dist/mount.d.ts +17 -11
- package/dist/mount.d.ts.map +1 -1
- package/dist/overlayView.d.ts +7 -18
- package/dist/overlayView.d.ts.map +1 -1
- package/dist/pivotControls.d.ts +64 -76
- package/dist/pivotControls.d.ts.map +1 -1
- package/dist/transformGizmo.d.ts +113 -125
- package/dist/transformGizmo.d.ts.map +1 -1
- package/dist/view.d.ts +37 -4
- package/dist/view.d.ts.map +1 -1
- package/dist/viewportGizmo.d.ts +107 -119
- package/dist/viewportGizmo.d.ts.map +1 -1
- package/package.json +15 -10
- package/src/boxSelect.ts +12 -133
- package/src/browser.ts +16 -0
- package/src/element.ts +19 -106
- package/src/index.ts +35 -16
- package/src/inspector.ts +70 -93
- package/src/measuringTape.ts +28 -92
- package/src/mount.ts +53 -286
- package/src/overlayView.ts +36 -57
- package/src/pivotControls.ts +8 -94
- package/src/transformGizmo.ts +8 -108
- package/src/view.ts +89 -51
- package/src/viewportGizmo.ts +8 -97
- package/dist/assets.d.ts +0 -53
- package/dist/assets.d.ts.map +0 -1
- package/dist/dom/animationFrames.d.ts +0 -12
- package/dist/dom/animationFrames.d.ts.map +0 -1
- package/dist/dom/canvas.d.ts +0 -26
- package/dist/dom/canvas.d.ts.map +0 -1
- package/dist/dom/latch.d.ts +0 -15
- package/dist/dom/latch.d.ts.map +0 -1
- package/dist/dom/models.d.ts +0 -10
- package/dist/dom/models.d.ts.map +0 -1
- package/dist/dom/overlays.d.ts +0 -24
- package/dist/dom/overlays.d.ts.map +0 -1
- package/dist/dom/pointer.d.ts +0 -49
- package/dist/dom/pointer.d.ts.map +0 -1
- package/dist/dom/postprocessing.d.ts +0 -22
- package/dist/dom/postprocessing.d.ts.map +0 -1
- package/dist/dom/property.d.ts +0 -15
- package/dist/dom/property.d.ts.map +0 -1
- package/dist/dom/reconciled.d.ts +0 -10
- package/dist/dom/reconciled.d.ts.map +0 -1
- package/dist/dom/renderSettings.d.ts +0 -58
- package/dist/dom/renderSettings.d.ts.map +0 -1
- package/dist/dom/typedScenes.d.ts +0 -14
- package/dist/dom/typedScenes.d.ts.map +0 -1
- package/dist/dom/updates.d.ts +0 -8
- package/dist/dom/updates.d.ts.map +0 -1
- package/dist/dom/viewport.d.ts +0 -40
- package/dist/dom/viewport.d.ts.map +0 -1
- package/dist/dom/webgl.d.ts +0 -12
- package/dist/dom/webgl.d.ts.map +0 -1
- package/dist/dom/webgpu.d.ts +0 -24
- package/dist/dom/webgpu.d.ts.map +0 -1
- package/dist/dom/webgpuPostprocessing.d.ts +0 -4
- package/dist/dom/webgpuPostprocessing.d.ts.map +0 -1
- package/dist/dom/xr.d.ts +0 -53
- package/dist/dom/xr.d.ts.map +0 -1
- package/dist/dom/xrGlide.d.ts +0 -49
- package/dist/dom/xrGlide.d.ts.map +0 -1
- package/dist/dom/xrHub.d.ts +0 -45
- package/dist/dom/xrHub.d.ts.map +0 -1
- package/dist/dom/xrInputs.d.ts +0 -40
- package/dist/dom/xrInputs.d.ts.map +0 -1
- package/dist/dom/xrSpaces.d.ts +0 -33
- package/dist/dom/xrSpaces.d.ts.map +0 -1
- package/dist/dom/xrTarget.d.ts +0 -36
- package/dist/dom/xrTarget.d.ts.map +0 -1
- package/dist/environment.d.ts +0 -64
- package/dist/environment.d.ts.map +0 -1
- package/dist/xr.d.ts +0 -34
- package/dist/xr.d.ts.map +0 -1
- package/src/assets.ts +0 -151
- package/src/dom/animationFrames.ts +0 -32
- package/src/dom/canvas.ts +0 -54
- package/src/dom/latch.ts +0 -36
- package/src/dom/models.ts +0 -37
- package/src/dom/overlays.ts +0 -63
- package/src/dom/pointer.ts +0 -163
- package/src/dom/postprocessing.ts +0 -116
- package/src/dom/property.ts +0 -43
- package/src/dom/reconciled.ts +0 -51
- package/src/dom/renderSettings.ts +0 -117
- package/src/dom/typedScenes.ts +0 -21
- package/src/dom/updates.ts +0 -14
- package/src/dom/viewport.ts +0 -97
- package/src/dom/webgl.ts +0 -231
- package/src/dom/webgpu.ts +0 -220
- package/src/dom/webgpuPostprocessing.ts +0 -102
- package/src/dom/xr.ts +0 -211
- package/src/dom/xrGlide.ts +0 -114
- package/src/dom/xrHub.ts +0 -118
- package/src/dom/xrInputs.ts +0 -309
- package/src/dom/xrSpaces.ts +0 -287
- package/src/dom/xrTarget.ts +0 -71
- package/src/environment.ts +0 -78
- package/src/xr.ts +0 -36
package/src/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Effect UI adapter for `@opsydyn/effect-three`.
|
|
3
3
|
*
|
|
4
4
|
* ```ts
|
|
5
5
|
* // entry.ts: once per app
|
|
6
|
-
* const environment =
|
|
7
|
-
* export const sceneMount =
|
|
6
|
+
* const environment = EffectThreeUi.makeEnvironment(window);
|
|
7
|
+
* export const sceneMount = EffectThreeUi.makeSceneMount(environment);
|
|
8
8
|
*
|
|
9
9
|
* // view.ts
|
|
10
|
-
*
|
|
10
|
+
* EffectThreeUi.view(
|
|
11
11
|
* { scene: sceneFor(model), mount: sceneMount, onLifecycle: GotSceneLifecycle, onClick: ClickedNode },
|
|
12
12
|
* h,
|
|
13
13
|
* );
|
|
@@ -15,18 +15,27 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @module
|
|
17
17
|
*/
|
|
18
|
-
export {
|
|
19
|
-
|
|
18
|
+
export {
|
|
19
|
+
AssetLoadError,
|
|
20
|
+
type Assets,
|
|
21
|
+
makeAssets,
|
|
22
|
+
type ModelInfo,
|
|
23
|
+
} from '@opsydyn/effect-three/browser';
|
|
24
|
+
export { animationFrameScheduler, type AnimationFrameHost } from '@opsydyn/effect-three/browser';
|
|
20
25
|
export {
|
|
21
26
|
capturesPointer,
|
|
22
27
|
claimsContextMenu,
|
|
23
28
|
type Rect,
|
|
24
29
|
toNdc,
|
|
25
30
|
toPointerInput,
|
|
26
|
-
} from '
|
|
27
|
-
export {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
} from '@opsydyn/effect-three/browser';
|
|
32
|
+
export {
|
|
33
|
+
defaultPixelRatio,
|
|
34
|
+
type PixelRatio,
|
|
35
|
+
resolvePixelRatio,
|
|
36
|
+
} from '@opsydyn/effect-three/browser';
|
|
37
|
+
export { webglRendererFactory, type WebGLOptions } from '@opsydyn/effect-three/browser';
|
|
38
|
+
export { type WebGPUOptions, webgpuRendererFactory } from '@opsydyn/effect-three/browser';
|
|
30
39
|
export {
|
|
31
40
|
domEventName,
|
|
32
41
|
ReconciledDetail,
|
|
@@ -35,24 +44,31 @@ export {
|
|
|
35
44
|
SceneLifecycle,
|
|
36
45
|
XrSessionDetail,
|
|
37
46
|
} from './element.ts';
|
|
38
|
-
export { type XrMode } from '
|
|
39
|
-
export { type XrControls, XrUnavailable } from '
|
|
40
|
-
export { summarise } from '
|
|
47
|
+
export { type XrMode } from '@opsydyn/effect-three/browser';
|
|
48
|
+
export { type XrControls, XrUnavailable } from '@opsydyn/effect-three/browser';
|
|
49
|
+
export { summarise } from '@opsydyn/effect-three/browser';
|
|
41
50
|
export {
|
|
42
51
|
type Environment,
|
|
43
52
|
type EnvironmentHost,
|
|
44
53
|
type EnvironmentOptions,
|
|
45
54
|
makeEnvironment,
|
|
46
|
-
} from '
|
|
55
|
+
} from '@opsydyn/effect-three/browser';
|
|
47
56
|
export { inspectorView, type OnEdit } from './inspector.ts';
|
|
48
|
-
export {
|
|
57
|
+
export {
|
|
58
|
+
defineScopedSceneMount,
|
|
59
|
+
makeSceneMount,
|
|
60
|
+
type SceneMount,
|
|
61
|
+
type SceneMountArgs,
|
|
62
|
+
} from './mount.ts';
|
|
49
63
|
export * as BoxSelect from './boxSelect.ts';
|
|
50
64
|
export * as MeasuringTape from './measuringTape.ts';
|
|
51
65
|
export * as PivotControls from './pivotControls.ts';
|
|
52
66
|
export * as TransformGizmo from './transformGizmo.ts';
|
|
53
67
|
export * as ViewportGizmo from './viewportGizmo.ts';
|
|
54
|
-
export { type OverlayView } from './overlayView.ts';
|
|
68
|
+
export { overlayLayer, type OverlayView, withOverlays } from './overlayView.ts';
|
|
55
69
|
export {
|
|
70
|
+
type AssetFailedDetail,
|
|
71
|
+
type AssetLoadedDetail,
|
|
56
72
|
type AutoRotatedDetail,
|
|
57
73
|
type ButtonDetail,
|
|
58
74
|
type CollisionDetail,
|
|
@@ -66,12 +82,15 @@ export {
|
|
|
66
82
|
type MeasuredDetail,
|
|
67
83
|
type MissDetail,
|
|
68
84
|
type PerformanceDetail,
|
|
85
|
+
type PhysicsReachedDetail,
|
|
69
86
|
view,
|
|
70
87
|
type ViewConfig,
|
|
71
88
|
type WheelDetail,
|
|
72
89
|
type XrButtonDetail,
|
|
73
90
|
type XrMeshesDetail,
|
|
74
91
|
type XrMovedDetail,
|
|
92
|
+
type XrTeleportedDetail,
|
|
93
|
+
type XrPosesDetail,
|
|
75
94
|
type XrPlanesDetail,
|
|
76
95
|
type XrStickDetail,
|
|
77
96
|
type XrSurfaceDetail,
|
package/src/inspector.ts
CHANGED
|
@@ -1,112 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
* An inspector panel for Foldkit views (roadmap, "Beyond parity" 4): the fields the
|
|
3
|
-
* core's `Inspector.fields` reads from a schema, drawn as a form. Each control reports
|
|
4
|
-
* an edit as the app's own Message, with the field's path and the new value; the app
|
|
5
|
-
* applies it with `Inspector.edit`, which the schema checks, and keeps the result (or
|
|
6
|
-
* shows why it was refused).
|
|
7
|
-
*
|
|
8
|
-
* Numbers, text and choices report when they change (on Enter or leaving the field),
|
|
9
|
-
* colours as they are picked, switches when clicked, and each of a vector's three
|
|
10
|
-
* numbers on its own. Kinds, absent parts and lists are shown, not edited.
|
|
11
|
-
*
|
|
12
|
-
* @module
|
|
13
|
-
*/
|
|
1
|
+
import type { Html } from '@effect/ui/html';
|
|
14
2
|
import type { FieldPath, FieldValue, InspectedField } from '@opsydyn/effect-three';
|
|
15
|
-
import
|
|
3
|
+
import { Match, Schema } from 'effect';
|
|
16
4
|
|
|
17
|
-
/**
|
|
5
|
+
/** Maps a field edit to an application message. */
|
|
18
6
|
export type OnEdit<Message> = (path: FieldPath, value: FieldValue) => Message;
|
|
19
7
|
|
|
20
8
|
const axisNames = ['x', 'y', 'z'] as const;
|
|
21
9
|
|
|
22
|
-
/** The field's name for people: its property names, without list indices. */
|
|
23
10
|
const nameOf = (field: InspectedField): string =>
|
|
24
|
-
field.path.filter((
|
|
25
|
-
|
|
26
|
-
const hex = (colour: number): string => `#${colour.toString(16).padStart(6, '0')}`;
|
|
11
|
+
field.path.filter(Schema.is(Schema.String)).join(' ') || field.label;
|
|
27
12
|
|
|
28
13
|
const numberInput = <Message>(
|
|
29
|
-
h:
|
|
14
|
+
h: Html.H<Message>,
|
|
30
15
|
label: string,
|
|
31
16
|
value: number,
|
|
32
|
-
report: (
|
|
33
|
-
)
|
|
34
|
-
h.input
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
]);
|
|
17
|
+
report: (value: number) => Message,
|
|
18
|
+
) =>
|
|
19
|
+
h.input
|
|
20
|
+
.attr('type', 'number')
|
|
21
|
+
.attr('step', 'any')
|
|
22
|
+
.attr('aria-label', label)
|
|
23
|
+
.value(String(value))
|
|
24
|
+
.on('change', ({ value }) => report(Number(value)));
|
|
41
25
|
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
onEdit: OnEdit<Message>,
|
|
46
|
-
): Html => {
|
|
26
|
+
const numberFromHex = (value: string): number => Number.parseInt(value.slice(1), 16);
|
|
27
|
+
|
|
28
|
+
const controlOf = <Message>(h: Html.H<Message>, field: InspectedField, onEdit: OnEdit<Message>) => {
|
|
47
29
|
const name = nameOf(field);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
h.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
30
|
+
return Match.value(field).pipe(
|
|
31
|
+
Match.tagsExhaustive({
|
|
32
|
+
Number: ({ path, value }) => numberInput(h, name, value, (number) => onEdit(path, number)),
|
|
33
|
+
Text: ({ path, value }) =>
|
|
34
|
+
h.input
|
|
35
|
+
.attr('type', 'text')
|
|
36
|
+
.attr('aria-label', name)
|
|
37
|
+
.value(value)
|
|
38
|
+
.on('change', ({ value }) => onEdit(path, value)),
|
|
39
|
+
Toggle: ({ path, value }) =>
|
|
40
|
+
h.input
|
|
41
|
+
.attr('type', 'checkbox')
|
|
42
|
+
.attr('aria-label', name)
|
|
43
|
+
.checked(value)
|
|
44
|
+
.on('click', onEdit(path, !value)),
|
|
45
|
+
Choice: ({ path, value, options }) =>
|
|
46
|
+
h.select
|
|
47
|
+
.attr('aria-label', name)
|
|
48
|
+
.on('change', ({ value }) => onEdit(path, value))
|
|
49
|
+
.children(
|
|
50
|
+
...options.map((option) =>
|
|
51
|
+
h.option
|
|
52
|
+
.attr('value', option)
|
|
53
|
+
.selected(option === value)
|
|
54
|
+
.children(option),
|
|
55
|
+
),
|
|
56
|
+
),
|
|
57
|
+
Colour: ({ path, value }) =>
|
|
58
|
+
h.input
|
|
59
|
+
.attr('type', 'color')
|
|
60
|
+
.attr('aria-label', name)
|
|
61
|
+
.value(`#${value.toString(16).padStart(6, '0')}`)
|
|
62
|
+
.on('input', ({ value }) => onEdit(path, numberFromHex(value))),
|
|
63
|
+
Vector: ({ path, value }) =>
|
|
64
|
+
h.span
|
|
65
|
+
.class('e3-inspector-vector')
|
|
66
|
+
.children(
|
|
67
|
+
...value.map((component, index) =>
|
|
68
|
+
numberInput(h, `${name} ${axisNames[index] ?? index}`, component, (number) =>
|
|
69
|
+
onEdit([...path, index], number),
|
|
70
|
+
),
|
|
71
|
+
),
|
|
85
72
|
),
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
73
|
+
Fixed: ({ text }) => h.span.class('e3-inspector-fixed').children(text),
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const fieldRow = <Message>(h: Html.H<Message>, field: InspectedField, onEdit: OnEdit<Message>) => {
|
|
79
|
+
const label = h.span.class('e3-inspector-name').children(nameOf(field));
|
|
80
|
+
const control = controlOf(h, field, onEdit);
|
|
81
|
+
return h.label.key(field.path.join('.')).class('e3-inspector-row').children(label, control);
|
|
91
82
|
};
|
|
92
83
|
|
|
93
|
-
/**
|
|
94
|
-
* The fields as a form: a row each, its name and its control, keyed by path. Style it
|
|
95
|
-
* with the classes `e3-inspector`, `e3-inspector-row`, `e3-inspector-name`,
|
|
96
|
-
* `e3-inspector-vector` and `e3-inspector-fixed`.
|
|
97
|
-
*/
|
|
84
|
+
/** Displays schema-derived field controls and maps edits to application messages. */
|
|
98
85
|
export const inspectorView = <Message>(
|
|
99
|
-
h:
|
|
86
|
+
h: Html.H<Message>,
|
|
100
87
|
fields: ReadonlyArray<InspectedField>,
|
|
101
88
|
onEdit: OnEdit<Message>,
|
|
102
|
-
)
|
|
103
|
-
h.div(
|
|
104
|
-
[h.Class('e3-inspector')],
|
|
105
|
-
fields.map((field) =>
|
|
106
|
-
h.keyed('label')(
|
|
107
|
-
field.path.join('.'),
|
|
108
|
-
[h.Class('e3-inspector-row')],
|
|
109
|
-
[h.span([h.Class('e3-inspector-name')], [nameOf(field)]), controlOf(h, field, onEdit)],
|
|
110
|
-
),
|
|
111
|
-
),
|
|
112
|
-
);
|
|
89
|
+
) => h.div.class('e3-inspector').children(...fields.map((field) => fieldRow(h, field, onEdit)));
|
package/src/measuringTape.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A measuring tape as a
|
|
2
|
+
* A measuring tape as a Effect UI submodel (roadmap, "Beyond parity" 5): the core's pure
|
|
3
3
|
* `tape` with Messages for clicks and pointer moves on the scene, an OutMessage when a
|
|
4
4
|
* length is measured, and its length as HTML at the tape's middle. The parent decides
|
|
5
5
|
* when the tape is in use and which clicks are on the scene:
|
|
@@ -15,90 +15,23 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @module
|
|
17
17
|
*/
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
SceneSchema,
|
|
24
|
-
type SceneNode,
|
|
25
|
-
tape,
|
|
26
|
-
tapeLength,
|
|
27
|
-
type TapeLook,
|
|
28
|
-
tapeMiddle,
|
|
29
|
-
tapeNodes,
|
|
30
|
-
} from '@opsydyn/effect-three';
|
|
31
|
-
import { Option, Schema } from 'effect';
|
|
32
|
-
import type { HtmlBuilder } from 'foldkit/html';
|
|
33
|
-
import { defineMessageUnion } from 'foldkit/message';
|
|
34
|
-
import type { ReturnWithOutMessage } from 'foldkit/update';
|
|
18
|
+
import { UiSchema } from '@effect/ui';
|
|
19
|
+
import type { Html } from '@effect/ui/html';
|
|
20
|
+
import { overlay, tapeMiddle } from '@opsydyn/effect-three';
|
|
21
|
+
import { MeasuringTape as Controller } from '@opsydyn/effect-three/browser';
|
|
22
|
+
import { Option } from 'effect';
|
|
35
23
|
|
|
36
24
|
import type { OverlayView } from './overlayView.ts';
|
|
37
25
|
|
|
38
|
-
export const Model =
|
|
39
|
-
|
|
40
|
-
key: Schema.String,
|
|
41
|
-
tape: SceneSchema.Tape,
|
|
42
|
-
});
|
|
43
|
-
export type Model = typeof Model.Type;
|
|
26
|
+
export const { Model, init, length, nodes } = Controller;
|
|
27
|
+
export type Model = Controller.Model;
|
|
44
28
|
|
|
45
|
-
export const Message =
|
|
46
|
-
Placed: { point: SceneSchema.Vec3 },
|
|
47
|
-
Pointed: { point: Schema.NullOr(SceneSchema.Vec3) },
|
|
48
|
-
Cleared: {},
|
|
49
|
-
ChoseSnap: { snap: SceneSchema.Tape.fields.snap },
|
|
50
|
-
});
|
|
29
|
+
export const Message = UiSchema.TaggedEnum(Controller.MessageFields);
|
|
51
30
|
export type Message = typeof Message.Type;
|
|
52
|
-
|
|
53
|
-
export const OutMessage = defineMessageUnion({
|
|
54
|
-
/** Both ends are placed: where, and how far apart. */
|
|
55
|
-
Measured: { from: SceneSchema.Vec3, to: SceneSchema.Vec3, length: Schema.Finite },
|
|
56
|
-
});
|
|
31
|
+
export const OutMessage = UiSchema.TaggedEnum(Controller.OutMessageFields);
|
|
57
32
|
export type OutMessage = typeof OutMessage.Type;
|
|
58
33
|
|
|
59
|
-
|
|
60
|
-
export const init = (key: string, options: { readonly snap?: number | null } = {}): Model => ({
|
|
61
|
-
key,
|
|
62
|
-
tape: tape(options),
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
type Return = ReturnWithOutMessage<Model, Message, OutMessage>;
|
|
66
|
-
|
|
67
|
-
/** The OutMessage for a tape that has just been measured, if it has. */
|
|
68
|
-
const measured = (next: Model): Return =>
|
|
69
|
-
Option.match(
|
|
70
|
-
Option.all([Option.fromNullishOr(next.tape.from), Option.fromNullishOr(next.tape.to)]),
|
|
71
|
-
{
|
|
72
|
-
onNone: () => ({ model: next }),
|
|
73
|
-
onSome: ([from, to]) => ({
|
|
74
|
-
model: next,
|
|
75
|
-
outMessage: OutMessage.Measured({ from, to, length: tapeLength(next.tape) ?? 0 }),
|
|
76
|
-
}),
|
|
77
|
-
},
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
export const update = (model: Model, message: Message): Return =>
|
|
81
|
-
Message.match<Return>(message, {
|
|
82
|
-
Placed: ({ point }) => measured({ ...model, tape: placeTapeEnd(model.tape, point) }),
|
|
83
|
-
Pointed: ({ point }) => ({ model: { ...model, tape: pointTape(model.tape, point) } }),
|
|
84
|
-
Cleared: () => ({ model: { ...model, tape: clearTape(model.tape) } }),
|
|
85
|
-
ChoseSnap: ({ snap }) => ({ model: { ...model, tape: { ...model.tape, snap } } }),
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
/** The tape's length, while it has one (to the pointer while the second end is placed). */
|
|
89
|
-
export const length = (model: Model): Option.Option<number> =>
|
|
90
|
-
Option.fromNullishOr(tapeLength(model.tape));
|
|
91
|
-
|
|
92
|
-
/** The tape, for the parent's scene. */
|
|
93
|
-
export const nodes = (model: Model, look: Partial<TapeLook> = {}): SceneNode =>
|
|
94
|
-
tapeNodes(model.key, model.tape, look);
|
|
95
|
-
|
|
96
|
-
/** The label's class, when one is given. */
|
|
97
|
-
const classOf = <Message>(h: HtmlBuilder<Message>, className: string | undefined) =>
|
|
98
|
-
Option.match(Option.fromNullishOr(className), {
|
|
99
|
-
onNone: () => [],
|
|
100
|
-
onSome: (name) => [h.Class(name)],
|
|
101
|
-
});
|
|
34
|
+
export const update = Controller.update;
|
|
102
35
|
|
|
103
36
|
/**
|
|
104
37
|
* The length at the tape's middle, for the view's `overlays`: two decimals and `unit`
|
|
@@ -107,18 +40,21 @@ const classOf = <Message>(h: HtmlBuilder<Message>, className: string | undefined
|
|
|
107
40
|
*/
|
|
108
41
|
export const label = <Message>(
|
|
109
42
|
model: Model,
|
|
110
|
-
h:
|
|
43
|
+
h: Html.H<Message>,
|
|
111
44
|
options: { readonly unit?: string; readonly className?: string } = {},
|
|
112
|
-
): ReadonlyArray<OverlayView
|
|
113
|
-
Option.match(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
`${
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
45
|
+
): ReadonlyArray<OverlayView<Message>> =>
|
|
46
|
+
Option.match(
|
|
47
|
+
Option.all([Controller.length(model), Option.fromNullishOr(tapeMiddle(model.tape))]),
|
|
48
|
+
{
|
|
49
|
+
onNone: () => [],
|
|
50
|
+
onSome: ([measuredLength, middle]) => [
|
|
51
|
+
{
|
|
52
|
+
overlay: overlay({ key: `${model.key}:label`, position: middle, center: true }),
|
|
53
|
+
content: h.span
|
|
54
|
+
.attr('class', options.className)
|
|
55
|
+
.children(`${measuredLength.toFixed(2)} ${options.unit ?? 'm'}`),
|
|
56
|
+
pointerEvents: 'none',
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
);
|