@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.
Files changed (118) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +29 -23
  3. package/dist/boxSelect.d.ts +91 -117
  4. package/dist/boxSelect.d.ts.map +1 -1
  5. package/dist/browser.d.ts +3 -0
  6. package/dist/browser.d.ts.map +1 -0
  7. package/dist/browser.js +32 -0
  8. package/dist/browser.js.map +10 -0
  9. package/dist/element.d.ts +13 -869
  10. package/dist/element.d.ts.map +1 -1
  11. package/dist/index.d.ts +17 -17
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +173 -2383
  14. package/dist/index.js.map +14 -38
  15. package/dist/inspector.d.ts +4 -21
  16. package/dist/inspector.d.ts.map +1 -1
  17. package/dist/measuringTape.d.ts +39 -46
  18. package/dist/measuringTape.d.ts.map +1 -1
  19. package/dist/mount.d.ts +17 -11
  20. package/dist/mount.d.ts.map +1 -1
  21. package/dist/overlayView.d.ts +7 -18
  22. package/dist/overlayView.d.ts.map +1 -1
  23. package/dist/pivotControls.d.ts +64 -76
  24. package/dist/pivotControls.d.ts.map +1 -1
  25. package/dist/transformGizmo.d.ts +113 -125
  26. package/dist/transformGizmo.d.ts.map +1 -1
  27. package/dist/view.d.ts +37 -4
  28. package/dist/view.d.ts.map +1 -1
  29. package/dist/viewportGizmo.d.ts +107 -119
  30. package/dist/viewportGizmo.d.ts.map +1 -1
  31. package/package.json +15 -10
  32. package/src/boxSelect.ts +12 -133
  33. package/src/browser.ts +16 -0
  34. package/src/element.ts +19 -106
  35. package/src/index.ts +35 -16
  36. package/src/inspector.ts +70 -93
  37. package/src/measuringTape.ts +28 -92
  38. package/src/mount.ts +53 -286
  39. package/src/overlayView.ts +36 -57
  40. package/src/pivotControls.ts +8 -94
  41. package/src/transformGizmo.ts +8 -108
  42. package/src/view.ts +89 -51
  43. package/src/viewportGizmo.ts +8 -97
  44. package/dist/assets.d.ts +0 -53
  45. package/dist/assets.d.ts.map +0 -1
  46. package/dist/dom/animationFrames.d.ts +0 -12
  47. package/dist/dom/animationFrames.d.ts.map +0 -1
  48. package/dist/dom/canvas.d.ts +0 -26
  49. package/dist/dom/canvas.d.ts.map +0 -1
  50. package/dist/dom/latch.d.ts +0 -15
  51. package/dist/dom/latch.d.ts.map +0 -1
  52. package/dist/dom/models.d.ts +0 -10
  53. package/dist/dom/models.d.ts.map +0 -1
  54. package/dist/dom/overlays.d.ts +0 -24
  55. package/dist/dom/overlays.d.ts.map +0 -1
  56. package/dist/dom/pointer.d.ts +0 -49
  57. package/dist/dom/pointer.d.ts.map +0 -1
  58. package/dist/dom/postprocessing.d.ts +0 -22
  59. package/dist/dom/postprocessing.d.ts.map +0 -1
  60. package/dist/dom/property.d.ts +0 -15
  61. package/dist/dom/property.d.ts.map +0 -1
  62. package/dist/dom/reconciled.d.ts +0 -10
  63. package/dist/dom/reconciled.d.ts.map +0 -1
  64. package/dist/dom/renderSettings.d.ts +0 -58
  65. package/dist/dom/renderSettings.d.ts.map +0 -1
  66. package/dist/dom/typedScenes.d.ts +0 -14
  67. package/dist/dom/typedScenes.d.ts.map +0 -1
  68. package/dist/dom/updates.d.ts +0 -8
  69. package/dist/dom/updates.d.ts.map +0 -1
  70. package/dist/dom/viewport.d.ts +0 -40
  71. package/dist/dom/viewport.d.ts.map +0 -1
  72. package/dist/dom/webgl.d.ts +0 -12
  73. package/dist/dom/webgl.d.ts.map +0 -1
  74. package/dist/dom/webgpu.d.ts +0 -24
  75. package/dist/dom/webgpu.d.ts.map +0 -1
  76. package/dist/dom/webgpuPostprocessing.d.ts +0 -4
  77. package/dist/dom/webgpuPostprocessing.d.ts.map +0 -1
  78. package/dist/dom/xr.d.ts +0 -53
  79. package/dist/dom/xr.d.ts.map +0 -1
  80. package/dist/dom/xrGlide.d.ts +0 -49
  81. package/dist/dom/xrGlide.d.ts.map +0 -1
  82. package/dist/dom/xrHub.d.ts +0 -45
  83. package/dist/dom/xrHub.d.ts.map +0 -1
  84. package/dist/dom/xrInputs.d.ts +0 -40
  85. package/dist/dom/xrInputs.d.ts.map +0 -1
  86. package/dist/dom/xrSpaces.d.ts +0 -33
  87. package/dist/dom/xrSpaces.d.ts.map +0 -1
  88. package/dist/dom/xrTarget.d.ts +0 -36
  89. package/dist/dom/xrTarget.d.ts.map +0 -1
  90. package/dist/environment.d.ts +0 -64
  91. package/dist/environment.d.ts.map +0 -1
  92. package/dist/xr.d.ts +0 -34
  93. package/dist/xr.d.ts.map +0 -1
  94. package/src/assets.ts +0 -151
  95. package/src/dom/animationFrames.ts +0 -32
  96. package/src/dom/canvas.ts +0 -54
  97. package/src/dom/latch.ts +0 -36
  98. package/src/dom/models.ts +0 -37
  99. package/src/dom/overlays.ts +0 -63
  100. package/src/dom/pointer.ts +0 -163
  101. package/src/dom/postprocessing.ts +0 -116
  102. package/src/dom/property.ts +0 -43
  103. package/src/dom/reconciled.ts +0 -51
  104. package/src/dom/renderSettings.ts +0 -117
  105. package/src/dom/typedScenes.ts +0 -21
  106. package/src/dom/updates.ts +0 -14
  107. package/src/dom/viewport.ts +0 -97
  108. package/src/dom/webgl.ts +0 -231
  109. package/src/dom/webgpu.ts +0 -220
  110. package/src/dom/webgpuPostprocessing.ts +0 -102
  111. package/src/dom/xr.ts +0 -211
  112. package/src/dom/xrGlide.ts +0 -114
  113. package/src/dom/xrHub.ts +0 -118
  114. package/src/dom/xrInputs.ts +0 -309
  115. package/src/dom/xrSpaces.ts +0 -287
  116. package/src/dom/xrTarget.ts +0 -71
  117. package/src/environment.ts +0 -78
  118. package/src/xr.ts +0 -36
@@ -1,5 +1,5 @@
1
1
  /**
2
- * A transform gizmo as a Foldkit submodel (roadmap, "Beyond parity" 5): the core's pure
2
+ * A transform gizmo as an Effect UI submodel (roadmap, "Beyond parity" 5): the core's pure
3
3
  * gizmo (`gizmoNodes`, `pressGizmo`, `dragGizmo`, after three's `TransformControls`)
4
4
  * with Messages for the scene's pointer events and OutMessages for what the parent does
5
5
  * with them. The parent owns where its objects are; the submodel owns only the gizmo:
@@ -16,116 +16,16 @@
16
16
  *
17
17
  * @module
18
18
  */
19
- import {
20
- type Camera,
21
- dragGizmo,
22
- type Gizmo,
23
- gizmo,
24
- type GizmoHandle,
25
- gizmoHandleOf,
26
- gizmoNodes,
27
- hoverGizmo,
28
- type Placement,
29
- pressGizmo,
30
- releaseGizmo,
31
- SceneSchema,
32
- type SceneNode,
33
- type Vec3,
34
- } from '@opsydyn/effect-three';
35
- import { Option, Schema } from 'effect';
36
- import { defineMessageUnion } from 'foldkit/message';
37
- import type { ReturnWithOutMessage } from 'foldkit/update';
38
19
 
39
- export const Model = Schema.Struct({
40
- /** The key its handles are drawn under: `${key}:x`, `${key}:xy` and so on. */
41
- key: Schema.String,
42
- gizmo: SceneSchema.Gizmo,
43
- /** The placement the drag last reported, so `Released` can report where it ended. */
44
- last: Schema.Option(SceneSchema.Placement),
45
- });
46
- export type Model = typeof Model.Type;
20
+ import { UiSchema } from '@effect/ui';
21
+ import { TransformGizmo as Controller } from '@opsydyn/effect-three/browser';
47
22
 
48
- const Handle = Schema.Literals(['x', 'y', 'z', 'xy', 'yz', 'xz', 'xyz']);
23
+ export const { Model, init, handleOf, held, nodes } = Controller;
24
+ export type Model = Controller.Model;
49
25
 
50
- export const Message = defineMessageUnion({
51
- Pressed: {
52
- handle: Handle,
53
- origin: SceneSchema.Vec3,
54
- direction: SceneSchema.Vec3,
55
- placement: SceneSchema.Placement,
56
- camera: SceneSchema.Camera,
57
- },
58
- Dragged: { origin: SceneSchema.Vec3, direction: SceneSchema.Vec3 },
59
- Released: {},
60
- Hovered: { handle: Schema.NullOr(Handle) },
61
- ChoseMode: { mode: Schema.Literals(['translate', 'rotate', 'scale']) },
62
- ChoseSpace: { space: Schema.Literals(['world', 'local']) },
63
- });
26
+ export const Message = UiSchema.TaggedEnum(Controller.MessageFields);
64
27
  export type Message = typeof Message.Type;
65
-
66
- export const OutMessage = defineMessageUnion({
67
- /** The object's placement now, during a drag. */
68
- Moved: { placement: SceneSchema.Placement },
69
- /** The drag is over, the object here: a step for history. */
70
- Finished: { placement: SceneSchema.Placement },
71
- });
28
+ export const OutMessage = UiSchema.TaggedEnum(Controller.OutMessageFields);
72
29
  export type OutMessage = typeof OutMessage.Type;
73
30
 
74
- /** A gizmo drawn under `key`, with the core's defaults or the options given. */
75
- export const init = (key: string, options: Parameters<typeof gizmo>[0] = {}): Model => ({
76
- key,
77
- gizmo: gizmo(options),
78
- last: Option.none(),
79
- });
80
-
81
- type Return = ReturnWithOutMessage<Model, Message, OutMessage>;
82
-
83
- const withGizmo = (model: Model, next: Gizmo): Model => ({ ...model, gizmo: next });
84
-
85
- const finished = (model: Model): Return => ({
86
- model: { ...withGizmo(model, releaseGizmo(model.gizmo)), last: Option.none() },
87
- ...Option.match(model.last, {
88
- onNone: () => ({}),
89
- onSome: (placement) => ({ outMessage: OutMessage.Finished({ placement }) }),
90
- }),
91
- });
92
-
93
- const dragged = (model: Model, origin: Vec3, direction: Vec3): Return => {
94
- const placement = Option.fromNullishOr(dragGizmo(model.gizmo, { origin, direction }));
95
- return Option.match(placement, {
96
- onNone: () => ({ model }),
97
- onSome: (placement) => ({
98
- model: { ...model, last: Option.some(placement) },
99
- outMessage: OutMessage.Moved({ placement }),
100
- }),
101
- });
102
- };
103
-
104
- export const update = (model: Model, message: Message): Return =>
105
- Message.match<Return>(message, {
106
- Pressed: ({ handle, origin, direction, placement, camera }) => ({
107
- model: {
108
- ...withGizmo(
109
- model,
110
- pressGizmo(model.gizmo, placement, handle, { origin, direction }, camera),
111
- ),
112
- last: Option.none(),
113
- },
114
- }),
115
- Dragged: ({ origin, direction }) => dragged(model, origin, direction),
116
- Released: () => finished(model),
117
- Hovered: ({ handle }) => ({ model: withGizmo(model, hoverGizmo(model.gizmo, handle)) }),
118
- ChoseMode: ({ mode }) => ({ model: withGizmo(model, { ...model.gizmo, mode }) }),
119
- ChoseSpace: ({ space }) => ({ model: withGizmo(model, { ...model.gizmo, space }) }),
120
- });
121
-
122
- /** Whether a hit `key` is one of this gizmo's handles, and which. */
123
- export const handleOf = (model: Model, key: string): Option.Option<GizmoHandle> =>
124
- Option.fromNullishOr(gizmoHandleOf(model.key, key));
125
-
126
- /** Whether the gizmo is held: the parent leaves the camera alone while it is. */
127
- export const held = (model: Model): boolean => model.gizmo.grab !== null;
128
-
129
- /** The handles for `placement`, seen from `camera`, for the parent's scene. */
130
- export const nodes = (model: Model, placement: Placement, camera: Camera): SceneNode =>
131
- gizmoNodes(model.key, model.gizmo, placement, camera);
31
+ export const update = Controller.update;
package/src/view.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  /**
2
- * The scene view: one call from a Foldkit `view` renders a scene and maps its events to
2
+ * The scene view: one call from an Effect UI view renders a scene and maps its events to
3
3
  * the app's typed Messages. The scene is plain data derived from the Model.
4
4
  *
5
5
  * @module
6
6
  */
7
+ import { Mount, type View } from '@effect/ui';
8
+ import type { Html } from '@effect/ui/html';
7
9
  import type { SceneDescription, SceneSchema } from '@opsydyn/effect-three';
8
- import { Array as Arr, Option } from 'effect';
9
- import { Mount } from 'foldkit';
10
- import type { Html, HtmlBuilder } from 'foldkit/html';
10
+ import { Option, type Scope } from 'effect';
11
11
 
12
- import { markTyped } from './dom/typedScenes.ts';
13
12
  import {
14
13
  type ReconciledDetail,
15
14
  type SceneError,
@@ -52,6 +51,9 @@ export type CollisionDetail = typeof SceneSchema.CollisionDetail.Type;
52
51
 
53
52
  /** Detail of contact force events: the two bodies, and how hard they pushed. */
54
53
  export type ContactForceDetail = typeof SceneSchema.ContactForceDetail.Type;
54
+ export type PhysicsReachedDetail = typeof SceneSchema.PhysicsReachedDetail.Type;
55
+ export type AssetLoadedDetail = typeof SceneSchema.AssetLoadedDetail.Type;
56
+ export type AssetFailedDetail = typeof SceneSchema.AssetFailedDetail.Type;
55
57
 
56
58
  /** Detail of measured events: a node's world bounding box. */
57
59
  export type MeasuredDetail = typeof SceneSchema.MeasuredDetail.Type;
@@ -70,6 +72,10 @@ export type XrButtonDetail = typeof SceneSchema.XrButtonDetail.Type;
70
72
 
71
73
  /** Detail of XR moved events: where gliding left the player. */
72
74
  export type XrMovedDetail = typeof SceneSchema.XrMovedDetail.Type;
75
+ export type XrTeleportedDetail = typeof SceneSchema.XrTeleportedDetail.Type;
76
+
77
+ /** Detail of XR poses events: where the player's head and hands are, in the scene. */
78
+ export type XrPosesDetail = typeof SceneSchema.XrPosesDetail.Type;
73
79
 
74
80
  /** Detail of XR planes events: every plane the session detected, as it is now. */
75
81
  export type XrPlanesDetail = typeof SceneSchema.XrPlanesDetail.Type;
@@ -144,6 +150,12 @@ export type ViewConfig<Message> = {
144
150
  * set the threshold high.
145
151
  */
146
152
  readonly onContactForce?: (detail: ContactForceDetail) => Message;
153
+ /**
154
+ * A world on `physics({ until })` reached that step and waits there, with its run and a
155
+ * checksum of its bodies' poses (ADR-014): the moment to apply the inputs due at that
156
+ * step and move `until` on. It follows the collisions of the steps that led there.
157
+ */
158
+ readonly onPhysicsReached?: (detail: PhysicsReachedDetail) => Message;
147
159
  /**
148
160
  * A node listed in the scene's `measure` has a new world bounding box (Drei's `Bounds`
149
161
  * measuring, as a Message): fit the camera to it with `fitCamera`.
@@ -177,6 +189,16 @@ export type ViewConfig<Message> = {
177
189
  * with `glided(model.xr, detail)`.
178
190
  */
179
191
  readonly onXRMoved?: (detail: XrMovedDetail) => Message;
192
+ /**
193
+ * The teleport arc (`xr({ teleportArc })`) was let go over a target: where it landed and
194
+ * where the player's origin goes, to keep in the Model (`teleported`).
195
+ */
196
+ readonly onXRTeleported?: (detail: XrTeleportedDetail) => Message;
197
+ /**
198
+ * With `xr({ poses })`, every so many seconds while presenting: where the player's head
199
+ * and hands are, in the scene's space, to send to other players (`avatar`).
200
+ */
201
+ readonly onXRPoses?: (detail: XrPosesDetail) => Message;
180
202
  /**
181
203
  * With `xr({ planes: true })`, the detected planes changed (found, reshaped, lost, or
182
204
  * seen from where the player moved to): every plane, as it is now. Follow one with
@@ -197,6 +219,13 @@ export type ViewConfig<Message> = {
197
219
  readonly onPerformanceChange?: (detail: PerformanceDetail) => Message;
198
220
  /** A scene update was rejected; the scene keeps its last good state. */
199
221
  readonly onError?: (detail: { readonly error: SceneError }) => Message;
222
+ /**
223
+ * An asset the scene asks for (`scene({ assets })`) has loaded and is lent under its id:
224
+ * at once, for one another scene loaded already. A model's parts and clips come with it.
225
+ */
226
+ readonly onAssetLoaded?: (detail: AssetLoadedDetail) => Message;
227
+ /** An asset the scene asks for could not be loaded, and why. */
228
+ readonly onAssetFailed?: (detail: AssetFailedDetail) => Message;
200
229
  /**
201
230
  * What each scene update did (operations by kind) and the GPU resources held afterwards.
202
231
  * Fires at startup and after every update that changed something, never for no-ops.
@@ -207,57 +236,66 @@ export type ViewConfig<Message> = {
207
236
  * perhaps on a node), `content` what. The scene moves the HTML there every frame it
208
237
  * draws; the content is ordinary view HTML, rendered from the Model.
209
238
  */
210
- readonly overlays?: ReadonlyArray<OverlayView>;
239
+ readonly overlays?: ReadonlyArray<OverlayView<Message>>;
211
240
  readonly className?: string;
241
+ /** When false, pointer and XR input is ignored until the scene is live again. */
242
+ readonly live?: boolean;
212
243
  };
213
244
 
214
- const given = Option.fromNullishOr;
215
-
216
245
  /** Renders a scene element. Only the event handlers you pass are bound. */
217
246
  export const view = <Message>(
218
247
  config: ViewConfig<NoInfer<Message>>,
219
- h: HtmlBuilder<Message>,
220
- ): Html => {
221
- const element = sceneElement.withMessage(h);
222
- const optional = Arr.getSomes([
223
- Option.map(given(config.onClick), element.OnSceneClick),
224
- Option.map(given(config.onDoubleClick), element.OnSceneDoubleClick),
225
- Option.map(given(config.onContextMenu), element.OnSceneContextMenu),
226
- Option.map(given(config.onPointerDown), element.OnScenePointerDown),
227
- Option.map(given(config.onPointerUp), element.OnScenePointerUp),
228
- Option.map(given(config.onPointerEnter), element.OnScenePointerEnter),
229
- Option.map(given(config.onPointerMove), element.OnScenePointerMove),
230
- Option.map(given(config.onPointerLeave), element.OnScenePointerLeave),
231
- Option.map(given(config.onPointerMissed), element.OnScenePointerMissed),
232
- Option.map(given(config.onWheel), element.OnSceneWheel),
233
- Option.map(given(config.onDrag), element.OnSceneDrag),
234
- Option.map(given(config.onDragEnd), element.OnSceneDragEnd),
235
- Option.map(given(config.onCollision), element.OnSceneCollision),
236
- Option.map(given(config.onContactForce), element.OnSceneContactForce),
237
- Option.map(given(config.onMeasured), element.OnSceneMeasured),
238
- Option.map(given(config.onLabelMeasured), element.OnSceneLabelMeasured),
239
- Option.map(given(config.onXRSession), element.OnSceneXr),
240
- Option.map(given(config.onXRStick), element.OnSceneXrStick),
241
- Option.map(given(config.onXRButton), element.OnSceneXrButton),
242
- Option.map(given(config.onXRSurface), element.OnSceneXrSurface),
243
- Option.map(given(config.onXRMoved), element.OnSceneXrMoved),
244
- Option.map(given(config.onXRPlanes), element.OnSceneXrPlanes),
245
- Option.map(given(config.onXRMeshes), element.OnSceneXrMeshes),
246
- Option.map(given(config.onAutoRotated), element.OnSceneAutoRotated),
247
- Option.map(given(config.onGesture), (toMessage) =>
248
- element.OnSceneGesture((detail) => toMessage(detail.gesture)),
249
- ),
250
- Option.map(given(config.onGestureEnd), element.OnSceneGestureEnd),
251
- Option.map(given(config.onPerformanceChange), element.OnScenePerformance),
252
- Option.map(given(config.onError), element.OnSceneError),
253
- Option.map(given(config.onReconciled), element.OnSceneReconciled),
254
- Option.map(given(config.className), h.Class),
255
- ]);
256
- const lifecycle = Mount.mapMessage(config.mount(), config.onLifecycle);
257
- const overlays = config.overlays ?? [];
258
- const scene = markTyped(withOverlays(config.scene, overlays));
259
- return element(
260
- [element.Scene(scene), h.OnMount(lifecycle), ...optional],
261
- overlayLayer(h, overlays),
248
+ h: Html.H<Message>,
249
+ ): View.Content<Message, Scope.Scope> => {
250
+ let element = sceneElement(h).attr('class', config.className);
251
+ const bind = <Detail>(
252
+ handler: ((detail: Detail) => Message) | undefined,
253
+ attach: (handler: (detail: Detail) => Message) => typeof element,
254
+ ) => {
255
+ const input = Option.fromNullishOr(handler);
256
+ const attached = Option.map(input, attach);
257
+ element = Option.getOrElse(attached, () => element);
258
+ };
259
+ bind(config.onClick, (handler) => element.on('scene-click', handler));
260
+ bind(config.onDoubleClick, (handler) => element.on('scene-double-click', handler));
261
+ bind(config.onContextMenu, (handler) => element.on('scene-context-menu', handler));
262
+ bind(config.onPointerDown, (handler) => element.on('scene-pointer-down', handler));
263
+ bind(config.onPointerUp, (handler) => element.on('scene-pointer-up', handler));
264
+ bind(config.onPointerEnter, (handler) => element.on('scene-pointer-enter', handler));
265
+ bind(config.onPointerMove, (handler) => element.on('scene-pointer-move', handler));
266
+ bind(config.onPointerLeave, (handler) => element.on('scene-pointer-leave', handler));
267
+ bind(config.onPointerMissed, (handler) => element.on('scene-pointer-missed', handler));
268
+ bind(config.onWheel, (handler) => element.on('scene-wheel', handler));
269
+ bind(config.onDrag, (handler) => element.on('scene-drag', handler));
270
+ bind(config.onDragEnd, (handler) => element.on('scene-drag-end', handler));
271
+ bind(config.onCollision, (handler) => element.on('scene-collision', handler));
272
+ bind(config.onContactForce, (handler) => element.on('scene-contact-force', handler));
273
+ bind(config.onPhysicsReached, (handler) => element.on('scene-physics-reached', handler));
274
+ bind(config.onMeasured, (handler) => element.on('scene-measured', handler));
275
+ bind(config.onLabelMeasured, (handler) => element.on('scene-label-measured', handler));
276
+ bind(config.onXRSession, (handler) => element.on('scene-xr', handler));
277
+ bind(config.onXRStick, (handler) => element.on('scene-xr-stick', handler));
278
+ bind(config.onXRButton, (handler) => element.on('scene-xr-button', handler));
279
+ bind(config.onXRSurface, (handler) => element.on('scene-xr-surface', handler));
280
+ bind(config.onXRMoved, (handler) => element.on('scene-xr-moved', handler));
281
+ bind(config.onXRTeleported, (handler) => element.on('scene-xr-teleported', handler));
282
+ bind(config.onXRPoses, (handler) => element.on('scene-xr-poses', handler));
283
+ bind(config.onXRPlanes, (handler) => element.on('scene-xr-planes', handler));
284
+ bind(config.onXRMeshes, (handler) => element.on('scene-xr-meshes', handler));
285
+ bind(config.onAutoRotated, (handler) => element.on('scene-auto-rotated', handler));
286
+ bind(config.onGestureEnd, (handler) => element.on('scene-gesture-end', handler));
287
+ bind(config.onPerformanceChange, (handler) => element.on('scene-performance', handler));
288
+ bind(config.onError, (handler) => element.on('scene-error', handler));
289
+ bind(config.onAssetLoaded, (handler) => element.on('scene-asset-loaded', handler));
290
+ bind(config.onAssetFailed, (handler) => element.on('scene-asset-failed', handler));
291
+ bind(config.onReconciled, (handler) => element.on('scene-reconciled', handler));
292
+ bind(config.onGesture, (handler) =>
293
+ element.on('scene-gesture', ({ gesture }) => handler(gesture)),
262
294
  );
295
+
296
+ const overlays = config.overlays ?? [];
297
+ const scene = withOverlays(config.scene, overlays);
298
+ const mounted = config.mount({ scene, live: config.live ?? true });
299
+ const lifecycle = Mount.map(mounted, config.onLifecycle);
300
+ return element.onMount(lifecycle).children(overlayLayer(h, overlays));
263
301
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * A viewport gizmo as a Foldkit submodel (roadmap, "Beyond parity" 5), after Drei's
2
+ * A viewport gizmo as an Effect UI submodel (roadmap, "Beyond parity" 5), after Drei's
3
3
  * `GizmoHelper` with `GizmoViewport`: the core's `viewportGizmoNodes` in a scene's
4
4
  * `hud`, its heads highlighted under the pointer, and a press on one turning the camera
5
5
  * to look from that axis. The parent owns the camera; the submodel owns the highlight:
@@ -15,105 +15,16 @@
15
15
  *
16
16
  * @module
17
17
  */
18
- import {
19
- type Camera,
20
- cameraAlong,
21
- hud as describeHud,
22
- type Hud,
23
- type HudAlignment,
24
- SceneSchema,
25
- type SceneNode,
26
- type ViewAxis,
27
- viewportAxisOf,
28
- viewportGizmoNodes,
29
- } from '@opsydyn/effect-three';
30
- import { Option, Schema } from 'effect';
31
- import { defineMessageUnion } from 'foldkit/message';
32
- import type { ReturnWithOutMessage } from 'foldkit/update';
33
18
 
34
- const Axis = Schema.Literals(['x', 'y', 'z', '-x', '-y', '-z']);
19
+ import { UiSchema } from '@effect/ui';
20
+ import { ViewportGizmo as Controller } from '@opsydyn/effect-three/browser';
35
21
 
36
- export const Model = Schema.Struct({
37
- /** The key its nodes are drawn under: `${key}:x`, `${key}:-y` and so on. */
38
- key: Schema.String,
39
- /** The head under the pointer. */
40
- hovered: Schema.NullOr(Axis),
41
- /** Leaves out the negative heads. */
42
- hideNegativeAxes: Schema.Boolean,
43
- });
44
- export type Model = typeof Model.Type;
22
+ export const { Model, init, axisOf, nodes, hud } = Controller;
23
+ export type Model = Controller.Model;
45
24
 
46
- export const Message = defineMessageUnion({
47
- Entered: { key: Schema.String },
48
- Left: { key: Schema.String },
49
- Pressed: { key: Schema.String, camera: SceneSchema.Camera },
50
- });
25
+ export const Message = UiSchema.TaggedEnum(Controller.MessageFields);
51
26
  export type Message = typeof Message.Type;
52
-
53
- export const OutMessage = defineMessageUnion({
54
- /** The camera, looking from the axis of the head pressed. */
55
- Turned: { camera: SceneSchema.Camera },
56
- });
27
+ export const OutMessage = UiSchema.TaggedEnum(Controller.OutMessageFields);
57
28
  export type OutMessage = typeof OutMessage.Type;
58
29
 
59
- /** A gizmo drawn under `key`, every head shown unless `hideNegativeAxes`. */
60
- export const init = (
61
- key: string,
62
- options: { readonly hideNegativeAxes?: boolean } = {},
63
- ): Model => ({
64
- key,
65
- hovered: null,
66
- hideNegativeAxes: options.hideNegativeAxes ?? false,
67
- });
68
-
69
- type Return = ReturnWithOutMessage<Model, Message, OutMessage>;
70
-
71
- /** Which head a hit `key` is on, if it is one of this gizmo's. */
72
- export const axisOf = (model: Model, key: string): Option.Option<ViewAxis> =>
73
- Option.fromNullishOr(viewportAxisOf(model.key, key));
74
-
75
- const entered = (model: Model, key: string): Model =>
76
- Option.match(axisOf(model, key), {
77
- onNone: () => model,
78
- onSome: (axis) => ({ ...model, hovered: axis }),
79
- });
80
-
81
- /** Leaving a head clears the highlight; leaving anything else changes nothing. */
82
- const left = (model: Model, key: string): Model =>
83
- Option.match(axisOf(model, key), {
84
- onNone: () => model,
85
- onSome: () => ({ ...model, hovered: null }),
86
- });
87
-
88
- const pressed = (model: Model, key: string, camera: Camera): Return =>
89
- Option.match(axisOf(model, key), {
90
- onNone: () => ({ model }),
91
- onSome: (axis) => ({
92
- model,
93
- outMessage: OutMessage.Turned({ camera: cameraAlong(camera, axis) }),
94
- }),
95
- });
96
-
97
- export const update = (model: Model, message: Message): Return =>
98
- Message.match<Return>(message, {
99
- Entered: ({ key }) => ({ model: entered(model, key) }),
100
- Left: ({ key }) => ({ model: left(model, key) }),
101
- Pressed: ({ key, camera }) => pressed(model, key, camera),
102
- });
103
-
104
- /** The gizmo for `camera`, for a HUD. */
105
- export const nodes = (model: Model, camera: Camera): SceneNode =>
106
- viewportGizmoNodes(model.key, camera, {
107
- hovered: model.hovered,
108
- hideNegativeAxes: model.hideNegativeAxes,
109
- });
110
-
111
- /** A HUD holding only the gizmo, 80 pixels in from the bottom right unless placed. */
112
- export const hud = (
113
- model: Model,
114
- camera: Camera,
115
- placement: {
116
- readonly alignment?: HudAlignment;
117
- readonly margin?: readonly [number, number];
118
- } = {},
119
- ): Hud => describeHud({ ...placement, children: [nodes(model, camera)] });
30
+ export const update = Controller.update;
package/dist/assets.d.ts DELETED
@@ -1,53 +0,0 @@
1
- /**
2
- * Loading textures, glTF models and typeface fonts by URL, as Effects an application runs
3
- * from a Foldkit Command and settles into `AsyncData`. Each asset is lent to the shared
4
- * resource store under an id: materials use a texture with `map: id`, a `borrowed({ id })`
5
- * node shows a model, and `text({ font: id })` geometry draws with a font. The environment owns what it loads: loading an id again replaces and disposes
6
- * the earlier asset, and `unload` or the environment's `dispose` frees it.
7
- *
8
- * @module
9
- */
10
- import type { ResourceStore } from '@opsydyn/effect-three';
11
- import { Effect } from 'effect';
12
- declare const AssetLoadError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
13
- readonly _tag: "AssetLoadError";
14
- } & Readonly<A>;
15
- /** An asset could not be fetched or decoded. */
16
- export declare class AssetLoadError extends AssetLoadError_base<{
17
- readonly url: string;
18
- readonly cause: unknown;
19
- }> {
20
- }
21
- /** What a loaded model offers: named parts to match hits against, and animation clips. */
22
- export type ModelInfo = {
23
- readonly id: string;
24
- /** Names of the objects inside the model, as hits report them in `part`. */
25
- readonly parts: ReadonlyArray<string>;
26
- /** Names of the model's animation clips. */
27
- readonly clips: ReadonlyArray<string>;
28
- };
29
- /** Creates the asset loader for a store. One per environment. */
30
- export declare const makeAssets: (store: ResourceStore) => {
31
- /** Loads a colour texture (sRGB) and lends it under `id`. Succeeds with the id. */
32
- loadTexture: (id: string, url: string) => Effect.Effect<string, AssetLoadError, never>;
33
- /** Loads a glTF or GLB model and lends its scene under `id`, with its clips. */
34
- loadModel: (id: string, url: string) => Effect.Effect<ModelInfo, AssetLoadError, never>;
35
- /**
36
- * Loads an equirectangular HDR panorama (`.hdr`, three.js's `HDRLoader`) and lends it
37
- * under `id` for `environment({ map: id })`. Succeeds with the id. Image panoramas
38
- * load with `loadTexture`; the scene maps them for reflection.
39
- */
40
- loadEnvironment: (id: string, url: string) => Effect.Effect<string, AssetLoadError, never>;
41
- /**
42
- * Loads a typeface JSON font (three.js's `FontLoader` format, as Drei's `Text3D` takes)
43
- * and lends it under `id`. Succeeds with the id.
44
- */
45
- loadFont: (id: string, url: string) => Effect.Effect<string, AssetLoadError, never>;
46
- /** Withdraws and disposes the asset loaded under `id`, if any. */
47
- unload: (id: string) => Effect.Effect<void, never, never>;
48
- /** Withdraws and disposes every loaded asset. */
49
- dispose: () => void;
50
- };
51
- export type Assets = ReturnType<typeof makeAssets>;
52
- export {};
53
- //# sourceMappingURL=assets.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAQ,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;AActC,gDAAgD;AAChD,qBAAa,cAAe,SAAQ,oBAAmC;IACrE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,CAAC;CAAG;AAEL,0FAA0F;AAC1F,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC,4CAA4C;IAC5C,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACvC,CAAC;AAEF,iEAAiE;AACjE,eAAO,MAAM,UAAU,UAAW,aAAa;IA4D3C,mFAAmF;IACnF,WAAW,OAAO,MAAM,OAAO,MAAM;IAOrC,gFAAgF;IAChF,SAAS,OAAO,MAAM,OAAO,MAAM;IAOnC;;;;OAIG;IACH,eAAe,OAAO,MAAM,OAAO,MAAM;IAOzC;;;OAGG;IACH,QAAQ,OAAO,MAAM,OAAO,MAAM;IAOlC,kEAAkE;IAClE,MAAM,OAAO,MAAM;IAKnB,iDAAiD;IACjD,OAAO,QApDc,IAAI;CAsD5B,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC"}
@@ -1,12 +0,0 @@
1
- /**
2
- * A `requestAnimationFrame` scheduler shared by every scene on the page: one browser
3
- * callback per frame, running only while at least one scene is subscribed.
4
- *
5
- * @module
6
- */
7
- import type { FrameScheduler } from '@opsydyn/effect-three';
8
- /** The part of `Window` the scheduler needs. */
9
- export type AnimationFrameHost = Pick<Window, 'requestAnimationFrame' | 'cancelAnimationFrame'>;
10
- /** Creates a shared animation-frame scheduler for `host` (normally `window`). */
11
- export declare const animationFrameScheduler: (host: AnimationFrameHost) => FrameScheduler;
12
- //# sourceMappingURL=animationFrames.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"animationFrames.d.ts","sourceRoot":"","sources":["../../src/dom/animationFrames.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,gDAAgD;AAChD,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,MAAM,EAAE,uBAAuB,GAAG,sBAAsB,CAAC,CAAC;AAEhG,iFAAiF;AACjF,eAAO,MAAM,uBAAuB,SAAU,kBAAkB,KAAG,cAmBlE,CAAC"}
@@ -1,26 +0,0 @@
1
- /**
2
- * The canvas a scene draws into, and DOM event dispatch from scene events.
3
- *
4
- * @module
5
- */
6
- import type { Op, ResourceStore, SceneEvent } from '@opsydyn/effect-three';
7
- import { type SceneError } from '../element.ts';
8
- import type { Latch } from './latch.ts';
9
- /** Creates a canvas filling `host` and appends it. */
10
- export declare const appendCanvas: (host: Element) => HTMLCanvasElement;
11
- /** Dispatches a scene event as the element's typed DOM event. */
12
- export declare const dispatchSceneEvent: (element: Element, event: SceneEvent) => void;
13
- /** Dispatches a rejected scene update as a `scene-error` event. */
14
- export declare const dispatchSceneError: (element: Element, error: SceneError) => void;
15
- /** Thunk builders, so Effect code can run DOM work with `Effect.sync(thunk)`. */
16
- export declare const canvasIn: (host: Element) => () => HTMLCanvasElement;
17
- export declare const removal: (node: ChildNode) => () => void;
18
- /** Dispatches only while `live` is open: events are dropped during time-travel pause. */
19
- export declare const sceneEventDispatch: (element: Element, live: Latch) => (event: SceneEvent) => () => void;
20
- export declare const sceneErrorDispatch: (element: Element) => (error: SceneError) => () => void;
21
- /**
22
- * Dispatches a `scene-reconciled` summary when an update changed something. Updates with
23
- * no operations dispatch nothing, so an app storing the summary in its Model can't loop.
24
- */
25
- export declare const reconciledDispatch: (element: Element, store: ResourceStore) => (ops: ReadonlyArray<Op>) => () => void;
26
- //# sourceMappingURL=canvas.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../src/dom/canvas.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE3E,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,sDAAsD;AACtD,eAAO,MAAM,YAAY,SAAU,OAAO,KAAG,iBAS5C,CAAC;AAEF,iEAAiE;AACjE,eAAO,MAAM,kBAAkB,YAAa,OAAO,SAAS,UAAU,KAAG,IAExE,CAAC;AAEF,mEAAmE;AACnE,eAAO,MAAM,kBAAkB,YAAa,OAAO,SAAS,UAAU,KAAG,IAExE,CAAC;AAEF,iFAAiF;AACjF,eAAO,MAAM,QAAQ,SAAU,OAAO,4BAA6B,CAAC;AACpE,eAAO,MAAM,OAAO,SAAU,SAAS,eAAwB,CAAC;AAChE,yFAAyF;AACzF,eAAO,MAAM,kBAAkB,YAAa,OAAO,QAAQ,KAAK,aAAa,UAAU,eAEtF,CAAC;AACF,eAAO,MAAM,kBAAkB,YAAa,OAAO,aAAa,UAAU,eACtC,CAAC;AAErC;;;GAGG;AACH,eAAO,MAAM,kBAAkB,YACnB,OAAO,SAAS,aAAa,WAAW,aAAa,CAAC,EAAE,CAAC,eAKlE,CAAC"}
@@ -1,15 +0,0 @@
1
- /**
2
- * A boolean read synchronously by DOM callbacks and written by Effect code.
3
- *
4
- * @module
5
- */
6
- export type Latch = {
7
- readonly isOpen: () => boolean;
8
- readonly set: (open: boolean) => void;
9
- };
10
- export declare const createLatch: (open: boolean) => Latch;
11
- /** Calls `route` only while `latch` is open, returning what it routed (nothing when shut). */
12
- export declare const routedWhileOpen: <A, B>(latch: Latch, route: (value: A) => ReadonlyArray<B>) => (value: A) => ReadonlyArray<B>;
13
- /** A thunk calling `f(value)`, so Effect code can write `Effect.sync(applying(f, value))`. */
14
- export declare const applying: <A, B>(f: (value: A) => B, value: A) => () => B;
15
- //# sourceMappingURL=latch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"latch.d.ts","sourceRoot":"","sources":["../../src/dom/latch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CACvC,CAAC;AAEF,eAAO,MAAM,WAAW,SAAU,OAAO,KAAG,KAQ3C,CAAC;AAIF,8FAA8F;AAC9F,eAAO,MAAM,eAAe,GACzB,CAAC,EAAE,CAAC,SAAS,KAAK,SAAS,CAAC,KAAK,EAAE,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,aAClD,CAAC,KAAG,aAAa,CAAC,CAAC,CAG1B,CAAC;AAEJ,8FAA8F;AAC9F,eAAO,MAAM,QAAQ,GAClB,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,WAC/B,CACM,CAAC"}
@@ -1,10 +0,0 @@
1
- /**
2
- * Plain three.js helpers for loaded models.
3
- *
4
- * @module
5
- */
6
- import { type Object3D } from 'three';
7
- /** Disposes a loaded model's GPU resources: it was ours, not the application's. */
8
- export declare const disposeModel: (root: Object3D) => void;
9
- export declare const namesIn: (root: Object3D) => ReadonlyArray<string>;
10
- //# sourceMappingURL=models.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/dom/models.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAuB,KAAK,QAAQ,EAAW,MAAM,OAAO,CAAC;AAoBpE,mFAAmF;AACnF,eAAO,MAAM,YAAY,SAAU,QAAQ,KAAG,IAE7C,CAAC;AAEF,eAAO,MAAM,OAAO,SAAU,QAAQ,KAAG,aAAa,CAAC,MAAM,CAM5D,CAAC"}
@@ -1,24 +0,0 @@
1
- /**
2
- * Moves the application's overlay HTML to where the scene placed each overlay, as Drei's
3
- * `Html` does every frame (`src/web/Html.tsx` at `bf6f4ad`): a translate to the point,
4
- * the distance scale, centring, the depth's z-index, and hiding when not visible.
5
- *
6
- * @module
7
- */
8
- import type { OverlayPlacement } from '@opsydyn/effect-three';
9
- /** The data attribute naming the overlay an element's HTML belongs to. */
10
- export declare const overlayData: {
11
- readonly key: 'effect-three-overlay';
12
- readonly attribute: 'data-effect-three-overlay';
13
- };
14
- export type OverlayWriter = {
15
- /** Takes the latest placements and writes them. */
16
- readonly place: (placements: ReadonlyArray<OverlayPlacement>) => void;
17
- /** Writes the latest placements again, for overlay elements the view has just made. */
18
- readonly rewrite: () => void;
19
- };
20
- /** Creates the writer for overlays rendered inside `host`. */
21
- export declare const createOverlayWriter: (host: Element) => OverlayWriter;
22
- /** Makes the scene element the overlays' containing block, unless it already is one. */
23
- export declare const containOverlays: (host: Element) => () => void;
24
- //# sourceMappingURL=overlays.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"overlays.d.ts","sourceRoot":"","sources":["../../src/dom/overlays.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,0EAA0E;AAC1E,eAAO,MAAM,WAAW;aACtB,GAAG,EAAE,sBAAsB;aAC3B,SAAS,EAAE,2BAA2B;CAC9B,CAAC;AAkBX,MAAM,MAAM,aAAa,GAAG;IAC1B,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACtE,uFAAuF;IACvF,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAEF,8DAA8D;AAC9D,eAAO,MAAM,mBAAmB,SAAU,OAAO,KAAG,aAiBnD,CAAC;AAEF,wFAAwF;AACxF,eAAO,MAAM,eAAe,SAAU,OAAO,WAAS,IAGrD,CAAC"}