@opsydyn/effect-three-foldkit 0.6.4 → 1.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +26 -21
  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 +11 -909
  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 -2565
  14. package/dist/index.js.map +14 -39
  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 +21 -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 -110
  35. package/src/index.ts +32 -16
  36. package/src/inspector.ts +70 -93
  37. package/src/measuringTape.ts +28 -92
  38. package/src/mount.ts +53 -309
  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 +73 -54
  43. package/src/viewportGizmo.ts +8 -97
  44. package/dist/assetRegistry.d.ts +0 -49
  45. package/dist/assetRegistry.d.ts.map +0 -1
  46. package/dist/assets.d.ts +0 -66
  47. package/dist/assets.d.ts.map +0 -1
  48. package/dist/dom/animationFrames.d.ts +0 -12
  49. package/dist/dom/animationFrames.d.ts.map +0 -1
  50. package/dist/dom/canvas.d.ts +0 -33
  51. package/dist/dom/canvas.d.ts.map +0 -1
  52. package/dist/dom/latch.d.ts +0 -15
  53. package/dist/dom/latch.d.ts.map +0 -1
  54. package/dist/dom/models.d.ts +0 -10
  55. package/dist/dom/models.d.ts.map +0 -1
  56. package/dist/dom/overlays.d.ts +0 -24
  57. package/dist/dom/overlays.d.ts.map +0 -1
  58. package/dist/dom/pointer.d.ts +0 -49
  59. package/dist/dom/pointer.d.ts.map +0 -1
  60. package/dist/dom/postprocessing.d.ts +0 -22
  61. package/dist/dom/postprocessing.d.ts.map +0 -1
  62. package/dist/dom/property.d.ts +0 -15
  63. package/dist/dom/property.d.ts.map +0 -1
  64. package/dist/dom/reconciled.d.ts +0 -10
  65. package/dist/dom/reconciled.d.ts.map +0 -1
  66. package/dist/dom/renderSettings.d.ts +0 -58
  67. package/dist/dom/renderSettings.d.ts.map +0 -1
  68. package/dist/dom/typedScenes.d.ts +0 -14
  69. package/dist/dom/typedScenes.d.ts.map +0 -1
  70. package/dist/dom/updates.d.ts +0 -8
  71. package/dist/dom/updates.d.ts.map +0 -1
  72. package/dist/dom/viewport.d.ts +0 -40
  73. package/dist/dom/viewport.d.ts.map +0 -1
  74. package/dist/dom/webgl.d.ts +0 -12
  75. package/dist/dom/webgl.d.ts.map +0 -1
  76. package/dist/dom/webgpu.d.ts +0 -24
  77. package/dist/dom/webgpu.d.ts.map +0 -1
  78. package/dist/dom/webgpuPostprocessing.d.ts +0 -4
  79. package/dist/dom/webgpuPostprocessing.d.ts.map +0 -1
  80. package/dist/dom/xr.d.ts +0 -53
  81. package/dist/dom/xr.d.ts.map +0 -1
  82. package/dist/dom/xrGlide.d.ts +0 -49
  83. package/dist/dom/xrGlide.d.ts.map +0 -1
  84. package/dist/dom/xrHub.d.ts +0 -45
  85. package/dist/dom/xrHub.d.ts.map +0 -1
  86. package/dist/dom/xrInputs.d.ts +0 -40
  87. package/dist/dom/xrInputs.d.ts.map +0 -1
  88. package/dist/dom/xrSpaces.d.ts +0 -33
  89. package/dist/dom/xrSpaces.d.ts.map +0 -1
  90. package/dist/dom/xrTarget.d.ts +0 -36
  91. package/dist/dom/xrTarget.d.ts.map +0 -1
  92. package/dist/environment.d.ts +0 -70
  93. package/dist/environment.d.ts.map +0 -1
  94. package/dist/xr.d.ts +0 -34
  95. package/dist/xr.d.ts.map +0 -1
  96. package/src/assetRegistry.ts +0 -218
  97. package/src/assets.ts +0 -208
  98. package/src/dom/animationFrames.ts +0 -32
  99. package/src/dom/canvas.ts +0 -66
  100. package/src/dom/latch.ts +0 -36
  101. package/src/dom/models.ts +0 -37
  102. package/src/dom/overlays.ts +0 -63
  103. package/src/dom/pointer.ts +0 -176
  104. package/src/dom/postprocessing.ts +0 -116
  105. package/src/dom/property.ts +0 -43
  106. package/src/dom/reconciled.ts +0 -51
  107. package/src/dom/renderSettings.ts +0 -117
  108. package/src/dom/typedScenes.ts +0 -21
  109. package/src/dom/updates.ts +0 -14
  110. package/src/dom/viewport.ts +0 -97
  111. package/src/dom/webgl.ts +0 -231
  112. package/src/dom/webgpu.ts +0 -220
  113. package/src/dom/webgpuPostprocessing.ts +0 -102
  114. package/src/dom/xr.ts +0 -211
  115. package/src/dom/xrGlide.ts +0 -114
  116. package/src/dom/xrHub.ts +0 -118
  117. package/src/dom/xrInputs.ts +0 -309
  118. package/src/dom/xrSpaces.ts +0 -287
  119. package/src/dom/xrTarget.ts +0 -71
  120. package/src/environment.ts +0 -83
  121. 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,
@@ -73,6 +72,10 @@ export type XrButtonDetail = typeof SceneSchema.XrButtonDetail.Type;
73
72
 
74
73
  /** Detail of XR moved events: where gliding left the player. */
75
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;
76
79
 
77
80
  /** Detail of XR planes events: every plane the session detected, as it is now. */
78
81
  export type XrPlanesDetail = typeof SceneSchema.XrPlanesDetail.Type;
@@ -186,6 +189,16 @@ export type ViewConfig<Message> = {
186
189
  * with `glided(model.xr, detail)`.
187
190
  */
188
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;
189
202
  /**
190
203
  * With `xr({ planes: true })`, the detected planes changed (found, reshaped, lost, or
191
204
  * seen from where the player moved to): every plane, as it is now. Follow one with
@@ -223,60 +236,66 @@ export type ViewConfig<Message> = {
223
236
  * perhaps on a node), `content` what. The scene moves the HTML there every frame it
224
237
  * draws; the content is ordinary view HTML, rendered from the Model.
225
238
  */
226
- readonly overlays?: ReadonlyArray<OverlayView>;
239
+ readonly overlays?: ReadonlyArray<OverlayView<Message>>;
227
240
  readonly className?: string;
241
+ /** When false, pointer and XR input is ignored until the scene is live again. */
242
+ readonly live?: boolean;
228
243
  };
229
244
 
230
- const given = Option.fromNullishOr;
231
-
232
245
  /** Renders a scene element. Only the event handlers you pass are bound. */
233
246
  export const view = <Message>(
234
247
  config: ViewConfig<NoInfer<Message>>,
235
- h: HtmlBuilder<Message>,
236
- ): Html => {
237
- const element = sceneElement.withMessage(h);
238
- const optional = Arr.getSomes([
239
- Option.map(given(config.onClick), element.OnSceneClick),
240
- Option.map(given(config.onDoubleClick), element.OnSceneDoubleClick),
241
- Option.map(given(config.onContextMenu), element.OnSceneContextMenu),
242
- Option.map(given(config.onPointerDown), element.OnScenePointerDown),
243
- Option.map(given(config.onPointerUp), element.OnScenePointerUp),
244
- Option.map(given(config.onPointerEnter), element.OnScenePointerEnter),
245
- Option.map(given(config.onPointerMove), element.OnScenePointerMove),
246
- Option.map(given(config.onPointerLeave), element.OnScenePointerLeave),
247
- Option.map(given(config.onPointerMissed), element.OnScenePointerMissed),
248
- Option.map(given(config.onWheel), element.OnSceneWheel),
249
- Option.map(given(config.onDrag), element.OnSceneDrag),
250
- Option.map(given(config.onDragEnd), element.OnSceneDragEnd),
251
- Option.map(given(config.onCollision), element.OnSceneCollision),
252
- Option.map(given(config.onContactForce), element.OnSceneContactForce),
253
- Option.map(given(config.onPhysicsReached), element.OnScenePhysicsReached),
254
- Option.map(given(config.onMeasured), element.OnSceneMeasured),
255
- Option.map(given(config.onLabelMeasured), element.OnSceneLabelMeasured),
256
- Option.map(given(config.onXRSession), element.OnSceneXr),
257
- Option.map(given(config.onXRStick), element.OnSceneXrStick),
258
- Option.map(given(config.onXRButton), element.OnSceneXrButton),
259
- Option.map(given(config.onXRSurface), element.OnSceneXrSurface),
260
- Option.map(given(config.onXRMoved), element.OnSceneXrMoved),
261
- Option.map(given(config.onXRPlanes), element.OnSceneXrPlanes),
262
- Option.map(given(config.onXRMeshes), element.OnSceneXrMeshes),
263
- Option.map(given(config.onAutoRotated), element.OnSceneAutoRotated),
264
- Option.map(given(config.onGesture), (toMessage) =>
265
- element.OnSceneGesture((detail) => toMessage(detail.gesture)),
266
- ),
267
- Option.map(given(config.onGestureEnd), element.OnSceneGestureEnd),
268
- Option.map(given(config.onPerformanceChange), element.OnScenePerformance),
269
- Option.map(given(config.onError), element.OnSceneError),
270
- Option.map(given(config.onAssetLoaded), element.OnSceneAssetLoaded),
271
- Option.map(given(config.onAssetFailed), element.OnSceneAssetFailed),
272
- Option.map(given(config.onReconciled), element.OnSceneReconciled),
273
- Option.map(given(config.className), h.Class),
274
- ]);
275
- const lifecycle = Mount.mapMessage(config.mount(), config.onLifecycle);
276
- const overlays = config.overlays ?? [];
277
- const scene = markTyped(withOverlays(config.scene, overlays));
278
- return element(
279
- [element.Scene(scene), h.OnMount(lifecycle), ...optional],
280
- 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)),
281
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));
282
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;
@@ -1,49 +0,0 @@
1
- /**
2
- * The assets scenes ask for with `scene({ assets })` (ADR-015), held for the environment:
3
- * each loaded once however many scenes ask, lent to the store under its id, its load
4
- * cancelled when no scene asks for it any more, and withdrawn and disposed when the last
5
- * scene stops asking. Each scene hears whether what it asked for loaded or failed.
6
- *
7
- * An asset with coarser `levels` streams in: every level loads at once, each is lent as it
8
- * arrives if it is finer than what is shown (replacing it), and once the finest is shown
9
- * the coarser loads still under way are cancelled. Only the finest failing fails it.
10
- *
11
- * An id names one asset at a time: a scene asking for an id another scene holds as
12
- * something else (another kind or URL) is told it failed, and gets it once the other lets
13
- * go.
14
- *
15
- * @module
16
- */
17
- import { type Asset } from '@opsydyn/effect-three';
18
- /** An asset as loaded and lent: what a model offers, and how to withdraw and free it. */
19
- export type Lent = {
20
- readonly parts: ReadonlyArray<string>;
21
- readonly clips: ReadonlyArray<string>;
22
- readonly release: () => void;
23
- };
24
- /** Loads one asset and lends it under its id; gives up (rejecting) when `signal` aborts. */
25
- export type AssetLoader = (asset: Asset, signal: AbortSignal) => Promise<Lent>;
26
- /**
27
- * What a scene hears about an asset it asked for: a level of detail shown (0 for the
28
- * coarsest of its levels, `levels.length` for its URL, the finest), or its finest failed.
29
- */
30
- export type AssetNotice = ({
31
- readonly _tag: 'Loaded';
32
- readonly level: number;
33
- readonly final: boolean;
34
- } & Asset & Pick<Lent, 'parts' | 'clips'>) | ({
35
- readonly _tag: 'Failed';
36
- readonly reason: string;
37
- } & Asset);
38
- /** Who asks: a mounted scene, by any object that stands for it. */
39
- type Holder = object;
40
- type Notify = (notice: AssetNotice) => void;
41
- /** Creates the registry for one environment, loading with `load`. */
42
- export declare const makeAssetRegistry: (load: AssetLoader) => {
43
- want: (holder: Holder, assets: ReadonlyArray<Asset>, notify: Notify) => void;
44
- release: (holder: Holder) => void;
45
- dispose: () => void;
46
- };
47
- export type AssetRegistry = ReturnType<typeof makeAssetRegistry>;
48
- export {};
49
- //# sourceMappingURL=assetRegistry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assetRegistry.d.ts","sourceRoot":"","sources":["../src/assetRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,KAAK,KAAK,EAAe,MAAM,uBAAuB,CAAC;AAEhE,yFAAyF;AACzF,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAEF,4FAA4F;AAC5F,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE/E;;;GAGG;AACH,MAAM,MAAM,WAAW,GACnB,CAAC;IACC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,GAAG,KAAK,GACP,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,GAChC,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,KAAK,CAAC,CAAC;AAEnE,mEAAmE;AACnE,KAAK,MAAM,GAAG,MAAM,CAAC;AAErB,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;AAiC5C,qEAAqE;AACrE,eAAO,MAAM,iBAAiB,SAAU,WAAW;mBAiH3B,MAAM,UAAU,aAAa,CAAC,KAAK,CAAC,UAAU,MAAM,KAAG,IAAI;sBAYxD,MAAM,KAAG,IAAI;mBAMlB,IAAI;CAMzB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
package/dist/assets.d.ts DELETED
@@ -1,66 +0,0 @@
1
- /**
2
- * Loading textures, glTF models, HDR panoramas and typeface fonts by URL. Each asset is
3
- * lent to the shared resource store under an id: materials use a texture with `map: id`,
4
- * a `borrowed({ id })` node shows a model, `environment({ map: id })` a panorama, and
5
- * `text({ font: id })` geometry draws with a font.
6
- *
7
- * Two ways in. A scene can ask for assets in its description (`scene({ assets })`), and
8
- * the environment's registry loads, shares, cancels and frees them as scenes ask
9
- * (`assetLoader` is what it loads with; ADR-015). Or an application loads one with an
10
- * Effect from a Command and settles it into `AsyncData`; the environment owns what it
11
- * loads that way, loading an id again replaces and disposes the earlier asset, and
12
- * `unload` or the environment's `dispose` frees it. Use one way for any one id.
13
- *
14
- * @module
15
- */
16
- import type { ResourceStore } from '@opsydyn/effect-three';
17
- import { Effect } from 'effect';
18
- import type { AssetLoader } from './assetRegistry.ts';
19
- 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 & {
20
- readonly _tag: "AssetLoadError";
21
- } & Readonly<A>;
22
- /** An asset could not be fetched or decoded. */
23
- export declare class AssetLoadError extends AssetLoadError_base<{
24
- readonly url: string;
25
- readonly cause: unknown;
26
- }> {
27
- }
28
- /** What a loaded model offers: named parts to match hits against, and animation clips. */
29
- export type ModelInfo = {
30
- readonly id: string;
31
- /** Names of the objects inside the model, as hits report them in `part`. */
32
- readonly parts: ReadonlyArray<string>;
33
- /** Names of the model's animation clips. */
34
- readonly clips: ReadonlyArray<string>;
35
- };
36
- /**
37
- * What the environment's registry loads scenes' assets with: three's loaders, each load
38
- * with a loading manager of its own, so aborting it cancels its requests (three's file
39
- * and image-bitmap loaders honour the manager's abort).
40
- */
41
- export declare const assetLoader: (store: ResourceStore) => AssetLoader;
42
- /** Creates the asset loader for a store. One per environment. */
43
- export declare const makeAssets: (store: ResourceStore) => {
44
- /** Loads a colour texture (sRGB) and lends it under `id`. Succeeds with the id. */
45
- loadTexture: (id: string, url: string) => Effect.Effect<string, AssetLoadError, never>;
46
- /** Loads a glTF or GLB model and lends its scene under `id`, with its clips. */
47
- loadModel: (id: string, url: string) => Effect.Effect<ModelInfo, AssetLoadError, never>;
48
- /**
49
- * Loads an equirectangular HDR panorama (`.hdr`, three.js's `HDRLoader`) and lends it
50
- * under `id` for `environment({ map: id })`. Succeeds with the id. Image panoramas
51
- * load with `loadTexture`; the scene maps them for reflection.
52
- */
53
- loadEnvironment: (id: string, url: string) => Effect.Effect<string, AssetLoadError, never>;
54
- /**
55
- * Loads a typeface JSON font (three.js's `FontLoader` format, as Drei's `Text3D` takes)
56
- * and lends it under `id`. Succeeds with the id.
57
- */
58
- loadFont: (id: string, url: string) => Effect.Effect<string, AssetLoadError, never>;
59
- /** Withdraws and disposes the asset loaded under `id`, if any. */
60
- unload: (id: string) => Effect.Effect<void, never, never>;
61
- /** Withdraws and disposes every loaded asset. */
62
- dispose: () => void;
63
- };
64
- export type Assets = ReturnType<typeof makeAssets>;
65
- export {};
66
- //# sourceMappingURL=assets.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAoB,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAQ,MAAM,EAAE,MAAM,QAAQ,CAAC;AAatC,OAAO,KAAK,EAAE,WAAW,EAAQ,MAAM,oBAAoB,CAAC;;;;AAG5D,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;AA6DF;;;;GAIG;AACH,eAAO,MAAM,WAAW,UACd,aAAa,KAAG,WAKvB,CAAC;AAEJ,iEAAiE;AACjE,eAAO,MAAM,UAAU,UAAW,aAAa;IAqC3C,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,33 +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 { AssetNotice } from '../assetRegistry.ts';
8
- import { type SceneError } from '../element.ts';
9
- import type { Latch } from './latch.ts';
10
- /** Creates a canvas filling `host` and appends it. */
11
- export declare const appendCanvas: (host: Element) => HTMLCanvasElement;
12
- /** Dispatches a scene event as the element's typed DOM event. */
13
- export declare const dispatchSceneEvent: (element: Element, event: SceneEvent) => void;
14
- /** Dispatches a rejected scene update as a `scene-error` event. */
15
- export declare const dispatchSceneError: (element: Element, error: SceneError) => void;
16
- /**
17
- * Dispatches what the environment says about an asset the scene asked for, as a
18
- * `scene-asset-loaded` or `scene-asset-failed` event. Not held back while time travel is
19
- * paused: whether an asset loaded is a fact about the page, not a frame.
20
- */
21
- export declare const dispatchAssetNotice: (element: Element, notice: AssetNotice) => void;
22
- /** Thunk builders, so Effect code can run DOM work with `Effect.sync(thunk)`. */
23
- export declare const canvasIn: (host: Element) => () => HTMLCanvasElement;
24
- export declare const removal: (node: ChildNode) => () => void;
25
- /** Dispatches only while `live` is open: events are dropped during time-travel pause. */
26
- export declare const sceneEventDispatch: (element: Element, live: Latch) => (event: SceneEvent) => () => void;
27
- export declare const sceneErrorDispatch: (element: Element) => (error: SceneError) => () => void;
28
- /**
29
- * Dispatches a `scene-reconciled` summary when an update changed something. Updates with
30
- * no operations dispatch nothing, so an app storing the summary in its Model can't loop.
31
- */
32
- export declare const reconciledDispatch: (element: Element, store: ResourceStore) => (ops: ReadonlyArray<Op>) => () => void;
33
- //# 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,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,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;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,YAAa,OAAO,UAAU,WAAW,KAAG,IAI3E,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"}