@wardic/core 1.0.0-rc.1 → 1.0.0-rc.11
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/dist/Batch.d.ts +244 -0
- package/dist/Batch.d.ts.map +1 -0
- package/dist/Batch.js +1862 -0
- package/dist/Batch.js.map +1 -0
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +20 -12
- package/dist/Clock.js.map +1 -1
- package/dist/DragRecognizer.d.ts +16 -1
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +87 -1
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/Frame.d.ts +13 -0
- package/dist/Frame.d.ts.map +1 -1
- package/dist/Frame.js +2 -0
- package/dist/Frame.js.map +1 -1
- package/dist/FrameLoop.d.ts +12 -1
- package/dist/FrameLoop.d.ts.map +1 -1
- package/dist/FrameLoop.js +23 -1
- package/dist/FrameLoop.js.map +1 -1
- package/dist/InputSource.d.ts +21 -0
- package/dist/InputSource.d.ts.map +1 -1
- package/dist/InputSource.js.map +1 -1
- package/dist/LiveValue.d.ts +4 -3
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +7 -5
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +18 -4
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +96 -107
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +18 -8
- package/dist/Playback.js.map +1 -1
- package/dist/Probe.d.ts +10 -49
- package/dist/Probe.d.ts.map +1 -1
- package/dist/Probe.js +7 -6
- package/dist/Probe.js.map +1 -1
- package/dist/Projection.d.ts +4 -3
- package/dist/Projection.d.ts.map +1 -1
- package/dist/Projection.js +5 -2
- package/dist/Projection.js.map +1 -1
- package/dist/Recognizer.d.ts +35 -2
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +211 -16
- package/dist/Recognizer.js.map +1 -1
- package/dist/Reorder.d.ts +3 -3
- package/dist/Reorder.d.ts.map +1 -1
- package/dist/Reorder.js +28 -14
- package/dist/Reorder.js.map +1 -1
- package/dist/ScrollSource.d.ts +62 -0
- package/dist/ScrollSource.d.ts.map +1 -0
- package/dist/ScrollSource.js +21 -0
- package/dist/ScrollSource.js.map +1 -0
- package/dist/Sequence.d.ts +7 -2
- package/dist/Sequence.d.ts.map +1 -1
- package/dist/Sequence.js +8 -2
- package/dist/Sequence.js.map +1 -1
- package/dist/SharedSource.d.ts +35 -15
- package/dist/SharedSource.d.ts.map +1 -1
- package/dist/SharedSource.js +84 -108
- package/dist/SharedSource.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/frameLoop.d.ts +33 -7
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +214 -38
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/hearing.d.ts +13 -0
- package/dist/internal/hearing.d.ts.map +1 -0
- package/dist/internal/hearing.js +71 -0
- package/dist/internal/hearing.js.map +1 -0
- package/dist/internal/keyframes.d.ts +40 -0
- package/dist/internal/keyframes.d.ts.map +1 -0
- package/dist/internal/keyframes.js +70 -0
- package/dist/internal/keyframes.js.map +1 -0
- package/dist/internal/playhead.d.ts +16 -0
- package/dist/internal/playhead.d.ts.map +1 -0
- package/dist/internal/playhead.js +6 -0
- package/dist/internal/playhead.js.map +1 -0
- package/dist/internal/stepper.d.ts +6 -0
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +16 -0
- package/dist/internal/stepper.js.map +1 -1
- package/dist/internal/watch.d.ts +6 -0
- package/dist/internal/watch.d.ts.map +1 -1
- package/dist/internal/watch.js +7 -0
- package/dist/internal/watch.js.map +1 -1
- package/package.json +2 -2
- package/src/Batch.ts +2128 -0
- package/src/Clock.ts +29 -17
- package/src/DragRecognizer.ts +97 -2
- package/src/Frame.ts +16 -0
- package/src/FrameLoop.ts +24 -1
- package/src/InputSource.ts +25 -0
- package/src/LiveValue.ts +9 -7
- package/src/Machine.ts +106 -135
- package/src/Playback.ts +18 -15
- package/src/Probe.ts +16 -58
- package/src/Projection.ts +11 -5
- package/src/Recognizer.ts +242 -17
- package/src/Reorder.ts +39 -18
- package/src/ScrollSource.ts +68 -0
- package/src/Sequence.ts +20 -5
- package/src/SharedSource.ts +113 -146
- package/src/index.ts +3 -1
- package/src/internal/frameLoop.ts +246 -43
- package/src/internal/hearing.ts +76 -0
- package/src/internal/keyframes.ts +98 -0
- package/src/internal/playhead.ts +19 -0
- package/src/internal/stepper.ts +16 -0
- package/src/internal/watch.ts +15 -0
package/src/Clock.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// per-Environment re-implementation.
|
|
17
17
|
//
|
|
18
18
|
// The loop is the single update path: every Refresh frame computes `dt` from successive timestamps and
|
|
19
|
-
// calls `tick`, the only
|
|
19
|
+
// calls `tick`, the only one that hands a tick to the subscribers. There is deliberately no `MAX_DT` clamp
|
|
20
20
|
// here: clamping is a consumer-boundary concern (each leaf's step clamps at `Machine.MAX_DT`, #78), so the
|
|
21
21
|
// Clock reports raw deltas.
|
|
22
22
|
//
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
// `InterpolatorRegistry.layer` is the precedent for a shared constructor living in core. Observability:
|
|
42
42
|
// each subscription to `ticks` runs inside a `wardic.clock` span and emits a debug log on subscribe; the
|
|
43
43
|
// per-frame `tick` path stays quiet, the hot path.
|
|
44
|
+
import * as Arr from "effect/Array"
|
|
44
45
|
import * as Bool from "effect/Boolean"
|
|
45
46
|
import * as Context from "effect/Context"
|
|
46
47
|
import * as Effect from "effect/Effect"
|
|
@@ -48,11 +49,11 @@ import * as Layer from "effect/Layer"
|
|
|
48
49
|
import * as MutableRef from "effect/MutableRef"
|
|
49
50
|
import * as Option from "effect/Option"
|
|
50
51
|
import * as Predicate from "effect/Predicate"
|
|
51
|
-
import * as PubSub from "effect/PubSub"
|
|
52
52
|
import * as Scope from "effect/Scope"
|
|
53
53
|
import * as Stream from "effect/Stream"
|
|
54
54
|
import * as Microtask from "./Microtask.ts"
|
|
55
55
|
import * as RefreshFrameSource from "./RefreshFrameSource.ts"
|
|
56
|
+
import * as Hearing from "./internal/hearing.ts"
|
|
56
57
|
import { tracedStream } from "./internal/tracing.ts"
|
|
57
58
|
|
|
58
59
|
/**
|
|
@@ -132,8 +133,10 @@ export const fromRefreshFrames: <Handle>(
|
|
|
132
133
|
const { requestFrame, cancelFrame } = source
|
|
133
134
|
const now = Option.getOrElse(Option.fromNullishOr(source.now), () => () => performance.now())
|
|
134
135
|
|
|
135
|
-
//
|
|
136
|
-
|
|
136
|
+
// Who hears each dt (seconds): each subscriber's hearing, which resumes a waiting subscriber inside the
|
|
137
|
+
// Refresh frame's callback. Replaced, never changed in place, as `InputFeed.byTarget`'s list is (#518: a
|
|
138
|
+
// `PubSub` did this, and every app shipped its code).
|
|
139
|
+
let hearers: ReadonlyArray<(dt: number) => void> = []
|
|
137
140
|
|
|
138
141
|
// The previous Refresh frame's time (ms), for dt computation; None => no
|
|
139
142
|
// Refresh frame since the loop started (ADR-0017, decision 2). It is the frame's
|
|
@@ -173,17 +176,17 @@ export const fromRefreshFrames: <Handle>(
|
|
|
173
176
|
* gets the rest of the interval, and a dt never goes below 0. There is no upper
|
|
174
177
|
* clamp here: that is the consumer boundary's (`MAX_DT`).
|
|
175
178
|
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
179
|
+
* Hands dt to every subscriber. Hot path — intentionally unlogged; one `now()` read per
|
|
180
|
+
* Refresh frame.
|
|
178
181
|
*/
|
|
179
182
|
const tick = (t: number): Effect.Effect<void> =>
|
|
180
|
-
Effect.
|
|
183
|
+
Effect.sync(() => {
|
|
181
184
|
const at = now()
|
|
182
185
|
const [current, delta] = timing(t, at)
|
|
183
186
|
MutableRef.set(lastTime, Option.some(current))
|
|
184
187
|
MutableRef.set(lastStamp, Option.some(t))
|
|
185
188
|
MutableRef.set(lastNow, at)
|
|
186
|
-
|
|
189
|
+
Arr.forEach(hearers, (hear) => hear(delta))
|
|
187
190
|
})
|
|
188
191
|
|
|
189
192
|
// One Refresh frame as an interruptible Effect: requests a frame, resumes with
|
|
@@ -266,20 +269,29 @@ export const fromRefreshFrames: <Handle>(
|
|
|
266
269
|
MutableRef.decrement(subscribers)
|
|
267
270
|
})
|
|
268
271
|
|
|
269
|
-
// Subscribing joins the
|
|
270
|
-
//
|
|
272
|
+
// Subscribing joins the hearers, then joins the loop. Join the hearers FIRST,
|
|
273
|
+
// so no tick once the loop runs can miss this subscriber.
|
|
271
274
|
// A Stream, not a Channel: measured 2026-11-02, Stream's own layers were ~5% of a pull of 1,000
|
|
272
275
|
// subscribers' ticks (bench:core's `ticksOnly`), and at most one pull a frame a provider on an
|
|
273
276
|
// app's path, under 0.3% of a frame. Channel goes only where a profile shows it (#618, M5).
|
|
274
277
|
const ticks = tracedStream(
|
|
275
278
|
Stream.unwrap(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
279
|
+
Effect.gen(function* () {
|
|
280
|
+
yield* Effect.logDebug("wardic.clock: subscribe")
|
|
281
|
+
const { hear, stream } = Hearing.make<number>()
|
|
282
|
+
yield* Effect.acquireRelease(
|
|
283
|
+
Effect.sync(() => {
|
|
284
|
+
hearers = Arr.append(hearers, hear)
|
|
285
|
+
}),
|
|
286
|
+
() =>
|
|
287
|
+
Effect.sync(() => {
|
|
288
|
+
hearers = Arr.filter(hearers, (heard) => heard !== hear)
|
|
289
|
+
}),
|
|
290
|
+
)
|
|
291
|
+
yield* Effect.acquireRelease(join, () => leave)
|
|
292
|
+
return stream
|
|
293
|
+
}),
|
|
294
|
+
),
|
|
283
295
|
"wardic.clock",
|
|
284
296
|
)
|
|
285
297
|
|
package/src/DragRecognizer.ts
CHANGED
|
@@ -22,12 +22,13 @@
|
|
|
22
22
|
import * as Arr from "effect/Array"
|
|
23
23
|
import * as Bool from "effect/Boolean"
|
|
24
24
|
import * as Effect from "effect/Effect"
|
|
25
|
+
import * as Exit from "effect/Exit"
|
|
25
26
|
import { constant, constTrue, constVoid, identity, type LazyArg } from "effect/Function"
|
|
26
27
|
import * as Match from "effect/Match"
|
|
27
28
|
import * as MutableRef from "effect/MutableRef"
|
|
28
29
|
import * as Option from "effect/Option"
|
|
29
30
|
import * as Predicate from "effect/Predicate"
|
|
30
|
-
import
|
|
31
|
+
import * as Scope from "effect/Scope"
|
|
31
32
|
import * as Stream from "effect/Stream"
|
|
32
33
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
33
34
|
import type * as Drag from "./Drag.ts"
|
|
@@ -37,7 +38,8 @@ import * as InputSource from "./InputSource.ts"
|
|
|
37
38
|
import type * as Point from "./Point.ts"
|
|
38
39
|
import * as Velocity from "./Velocity.ts"
|
|
39
40
|
|
|
40
|
-
import {
|
|
41
|
+
import { tracedScoped } from "./internal/tracing.ts"
|
|
42
|
+
import { type AmongHandlers, amongFeed, streamOf, watchFeed } from "./internal/watch.ts"
|
|
41
43
|
|
|
42
44
|
/**
|
|
43
45
|
* Movement distance (px) from the down-origin required before a gesture
|
|
@@ -522,6 +524,99 @@ const axisAtOf = (axis: Drag.Axis | LazyArg<Drag.Axis>): LazyArg<Drag.Axis> =>
|
|
|
522
524
|
Match.orElse((read) => read),
|
|
523
525
|
)
|
|
524
526
|
|
|
527
|
+
// A host global in every environment Wardic runs on, which core's own `lib` doesn't declare (Microtask.ts).
|
|
528
|
+
declare const queueMicrotask: (callback: () => void) => void
|
|
529
|
+
|
|
530
|
+
/** A press's release: its pointer let go or cancelled, or a lost release (an unpressed move). */
|
|
531
|
+
const isRelease = (event: InputSource.PointerLikeEvent): boolean =>
|
|
532
|
+
Bool.or(Bool.or(event.type === "up", event.type === "cancel"), Bool.and(event.type === "move", Bool.not(event.pressed)))
|
|
533
|
+
|
|
534
|
+
/** A pressed member's own drag watch: its Scope, the pointer that pressed it, and whether its gesture started. */
|
|
535
|
+
interface PressedMember {
|
|
536
|
+
readonly scope: Scope.Closeable
|
|
537
|
+
pointerId: number
|
|
538
|
+
started: boolean
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Watches drags among many members while the Scope is open, from one feed over them (`pointerAmong`):
|
|
543
|
+
* a member's down starts `watchDrag` on that member alone, handed the down as drag controls hand one
|
|
544
|
+
* (`adoptPointer`), so it drags as its own press would, with the same threshold, claim, samples and
|
|
545
|
+
* velocity. `handlers.on` hears each sample with its member. No member listens until it's pressed.
|
|
546
|
+
* - **A gesture that started** ends its member's watch at its `"end"`, which the member's own feed hears.
|
|
547
|
+
* - **A press that never started** ends it at that pointer's release, a lost one too: there's nothing
|
|
548
|
+
* to tell, and no claim to give back. Another pointer's release on the member ends nothing.
|
|
549
|
+
* - **A down on a member pressed but not started** is handed to its watch, as the gesture's new press.
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* yield* DragRecognizer.watchDragAmong(memberOf, { axis: "y" }, { on: (member, sample) => follow(member, sample) })
|
|
553
|
+
*/
|
|
554
|
+
// #712, ADR-0072 decision 7: a Batch Reorder group's members, where a drag watch each would cost a listener
|
|
555
|
+
// set each. Over the feed `watchHoverAmong` and `watchPressAmong` watch (ADR-0055, *Amendment (#665)*).
|
|
556
|
+
// Held strongly, not weakly as their states are: each pressed member's entry is a Scope to close, gone at
|
|
557
|
+
// its gesture's end. A trusted event runs the page's microtasks between its listeners, and this feed's run
|
|
558
|
+
// before the member's own, so a started gesture's watch isn't touched at the release: it ends at its own
|
|
559
|
+
// `"end"`. Tier 2, for bindings.
|
|
560
|
+
export const watchDragAmong: (
|
|
561
|
+
memberOf: (node: unknown) => Option.Option<unknown>,
|
|
562
|
+
options: Omit<DragOptions, "listen" | "adoptable">,
|
|
563
|
+
handlers: AmongHandlers<Drag.Sample>,
|
|
564
|
+
) => Effect.Effect<void, never, Scope.Scope | InputSource.InputSource> = /*#__PURE__*/ Effect.fnUntraced(
|
|
565
|
+
function* (memberOf: (node: unknown) => Option.Option<unknown>, options: Omit<DragOptions, "listen" | "adoptable">, handlers: AmongHandlers<Drag.Sample>) {
|
|
566
|
+
yield* Effect.logDebug("wardic.drag: watch among")
|
|
567
|
+
const input = yield* InputSource.InputSource
|
|
568
|
+
const pointer = yield* amongFeed(input.pointerAmong, "pointerAmong")
|
|
569
|
+
const scope = yield* Effect.scope
|
|
570
|
+
const run = Effect.runSyncWith(yield* Effect.context<InputSource.InputSource>())
|
|
571
|
+
const pressed = new Map<unknown, PressedMember>()
|
|
572
|
+
/** `member`'s watch ended: after this event's dispatch, which its own feed may still be hearing. */
|
|
573
|
+
const end = (member: unknown, own: PressedMember): void => {
|
|
574
|
+
if (pressed.get(member) !== own) return
|
|
575
|
+
pressed.delete(member)
|
|
576
|
+
queueMicrotask(() => run(Scope.close(own.scope, Exit.void)))
|
|
577
|
+
}
|
|
578
|
+
/** `told`'s down handed to `member`'s watch, as drag controls hand one: the event's own platform event, else the event. */
|
|
579
|
+
const hand = (member: unknown, own: PressedMember, told: InputSource.PointerLikeEvent): void => {
|
|
580
|
+
own.pointerId = told.pointerId
|
|
581
|
+
const raw = UndefinedOr.match(told.raw, { onUndefined: () => told, onDefined: identity })
|
|
582
|
+
// A down that isn't a pressed pointer's starts nothing.
|
|
583
|
+
if (Option.isNone(input.adoptPointer(member, raw))) end(member, own)
|
|
584
|
+
}
|
|
585
|
+
/** `member`'s down: handed to its watch while one is open and hasn't started, else to a new one. */
|
|
586
|
+
const press = (member: unknown, told: InputSource.PointerLikeEvent): void => {
|
|
587
|
+
const open = pressed.get(member)
|
|
588
|
+
if (Predicate.isNotUndefined(open)) {
|
|
589
|
+
if (open.started) return
|
|
590
|
+
return hand(member, open, told)
|
|
591
|
+
}
|
|
592
|
+
const own: PressedMember = { scope: Scope.forkUnsafe(scope, "sequential"), pointerId: told.pointerId, started: false }
|
|
593
|
+
pressed.set(member, own)
|
|
594
|
+
const on = (sample: Drag.Sample): void => {
|
|
595
|
+
if (sample.phase === "start") own.started = true
|
|
596
|
+
handlers.on(member, sample)
|
|
597
|
+
if (sample.phase === "end") end(member, own)
|
|
598
|
+
}
|
|
599
|
+
run(watchDrag(member, { ...options, listen: false, adoptable: true }, { on, onDefect: handlers.onDefect }).pipe(Scope.provide(own.scope)))
|
|
600
|
+
hand(member, own, told)
|
|
601
|
+
}
|
|
602
|
+
/** A release by the pointer that pressed `member`, its gesture never started: its watch ends. */
|
|
603
|
+
const released = (member: unknown, told: InputSource.PointerLikeEvent): void => {
|
|
604
|
+
const own = pressed.get(member)
|
|
605
|
+
if (Predicate.isUndefined(own)) return
|
|
606
|
+
if (own.started) return
|
|
607
|
+
if (own.pointerId !== told.pointerId) return
|
|
608
|
+
end(member, own)
|
|
609
|
+
}
|
|
610
|
+
const onPointer = (): ((told: InputSource.TargetEvent<InputSource.PointerLikeEvent>) => boolean) => ({ target, event }) => {
|
|
611
|
+
if (event.type === "down") press(target, event)
|
|
612
|
+
if (isRelease(event)) released(target, event)
|
|
613
|
+
return true
|
|
614
|
+
}
|
|
615
|
+
yield* InputFeed.watchWith(pointer(memberOf), onPointer, { onDefect: handlers.onDefect, onEnd: handlers.onEnd, onStop: handlers.onStop })
|
|
616
|
+
},
|
|
617
|
+
(self) => tracedScoped(self, "wardic.drag"),
|
|
618
|
+
)
|
|
619
|
+
|
|
525
620
|
/**
|
|
526
621
|
* A drag on `target`, as a Stream of samples kept to its `axis`, with `watchDrag`'s rules: each sample
|
|
527
622
|
* arrives inside its pointer event's dispatch, and the Stream ends when the input does, as a test's
|
package/src/Frame.ts
CHANGED
|
@@ -37,5 +37,21 @@ export interface MultiPhysics extends Frame<Record<string, number>> {
|
|
|
37
37
|
readonly velocity: Record<string, number>
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* `Machine.springValues`' own Frame: its records, and the same values and velocities by index, in
|
|
42
|
+
* `keys`' order. A sink that reads them every frame reads `positions` and `velocities`: storing a
|
|
43
|
+
* number under a key a frame costs where an index doesn't. A velocity record the run wasn't asked to
|
|
44
|
+
* write (`records: "value"`) holds its start. Rewritten each tick, as its records are.
|
|
45
|
+
*/
|
|
46
|
+
// #663. The arrays are the run's own state: `Machine.toStream`'s copies carry the records alone.
|
|
47
|
+
export interface SpringValues extends MultiPhysics {
|
|
48
|
+
readonly keys: ReadonlyArray<string>
|
|
49
|
+
readonly positions: ReadonlyArray<number>
|
|
50
|
+
readonly velocities: ReadonlyArray<number>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Whether a record Frame is `Machine.springValues`' own, with its keys by index (#663). */
|
|
54
|
+
export const isSpringValues = (frame: MultiPhysics): frame is SpringValues => Predicate.hasProperty(frame, "positions")
|
|
55
|
+
|
|
40
56
|
/** Whether `frame` carries a velocity: a spring's, a decay's. */
|
|
41
57
|
export const isPhysics = (frame: Frame<number>): frame is Physics => Predicate.isNumber((frame as Physics).velocity)
|
package/src/FrameLoop.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* The Frame loop: the one loop per Environment that steps every running animation once a tick, in one
|
|
3
3
|
* pass, so many animations cost one loop and not a fiber each. A binding runs its animations on it with
|
|
4
4
|
* `Machine.run`, each Frame handed to its sink. `CheckFrames` turns on a check for development, which
|
|
5
|
-
* fails a run whose step gives a NaN or an Infinity, with `NonFiniteFrame
|
|
5
|
+
* fails a run whose step gives a NaN or an Infinity, with `NonFiniteFrame`, and `layerMetrics` the loop's
|
|
6
|
+
* metrics, for the devtools or an exporter.
|
|
6
7
|
*
|
|
7
8
|
* @example
|
|
8
9
|
* import * as FrameLoop from "@wardic/core/FrameLoop"
|
|
@@ -17,6 +18,7 @@
|
|
|
17
18
|
// authors.
|
|
18
19
|
import * as Context from "effect/Context"
|
|
19
20
|
import * as Layer from "effect/Layer"
|
|
21
|
+
import * as Metric from "effect/Metric"
|
|
20
22
|
import * as internal from "./internal/frameLoop.ts"
|
|
21
23
|
|
|
22
24
|
export { CheckFrames, NonFiniteFrame } from "./internal/frameLoop.ts"
|
|
@@ -41,3 +43,24 @@ export class FrameLoop extends Context.Service<FrameLoop, internal.Shape>()("@wa
|
|
|
41
43
|
// `DomLive`, `testLayer`. Built from the internal `make` (#618, C1): a service class with a `make` of its
|
|
42
44
|
// own showed it to callers, who build the loop only through this Layer (ADR-0028, decision 11).
|
|
43
45
|
export const layer = Layer.effect(FrameLoop)(internal.make())
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The Frame loop's metrics, for an app that reads them: `wardic_frameloop_animations`, the animations
|
|
49
|
+
* running now; `wardic_frameloop_settled` and `wardic_frameloop_failed`, counts of the runs that ended;
|
|
50
|
+
* and `wardic_frameloop_tick_ms`, each tick's work, as a histogram. Merge it beside the Environment, as
|
|
51
|
+
* you give the devtools or an exporter. Without it, the loop records no metric.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const env = Layer.mergeAll(DomLive, devtools, FrameLoop.layerMetrics)
|
|
55
|
+
*/
|
|
56
|
+
// #518, ADR-0067 *Amendment (#518)*, decision 2: opt-in, so an app that reads none ships none. Marked pure,
|
|
57
|
+
// so an app that never imports it drops `Metric`.
|
|
58
|
+
export const layerMetrics: Layer.Layer<never> = /*#__PURE__*/ Layer.sync(internal.MetricsGiven, () => ({
|
|
59
|
+
animations: Metric.gauge("wardic_frameloop_animations", { description: "Primitives running on the Frame loop" }),
|
|
60
|
+
settled: Metric.counter("wardic_frameloop_settled", { description: "Runs on the Frame loop that settled" }),
|
|
61
|
+
failed: Metric.counter("wardic_frameloop_failed", { description: "Runs on the Frame loop that failed" }),
|
|
62
|
+
tickMs: Metric.histogram("wardic_frameloop_tick_ms", {
|
|
63
|
+
description: "Milliseconds the Frame loop spends on one tick",
|
|
64
|
+
boundaries: Metric.linearBoundaries({ start: 0, width: 0.5, count: 32 }),
|
|
65
|
+
}),
|
|
66
|
+
}))
|
package/src/InputSource.ts
CHANGED
|
@@ -232,6 +232,14 @@ export interface FocusLikeEvent {
|
|
|
232
232
|
readonly visible?: boolean
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
/** An event, with the target it's for: what a feed over many targets tells, `pointerAmong`'s and `focusAmong`'s. */
|
|
236
|
+
// #665's PR 5 (Q56): a Batch's members' gestures, from one source.
|
|
237
|
+
export interface TargetEvent<A> {
|
|
238
|
+
/** The target it's for, as the feed's `memberOf` named it. */
|
|
239
|
+
readonly target: unknown
|
|
240
|
+
readonly event: A
|
|
241
|
+
}
|
|
242
|
+
|
|
235
243
|
/**
|
|
236
244
|
* Input from the Environment, as Input feeds: each target's pointer, keys and focus, shared by every
|
|
237
245
|
* subscriber to that target, and heard inside the platform's dispatch. A consumer that wants a Stream
|
|
@@ -282,6 +290,23 @@ export class InputSource extends Context.Service<InputSource, {
|
|
|
282
290
|
*/
|
|
283
291
|
// #431: **Drag controls**. An `Option` (#618, A1): a down that may not be there, outside the per-frame path.
|
|
284
292
|
readonly adoptPointer: (target: unknown, raw: unknown) => Option.Option<PointerLikeEvent>
|
|
293
|
+
/**
|
|
294
|
+
* The pointer events over many targets, from one source, each told with the target it's for:
|
|
295
|
+
* `memberOf(node)` names the target a node the pointer hit is, `Option.none()` for none, and each target
|
|
296
|
+
* hears what `pointer(target)` would, its enter and leave, the downs and releases over it, and a held
|
|
297
|
+
* pointer's events wherever they land. For many like targets, a Batch's members, where a feed each
|
|
298
|
+
* would cost a listener set each. Absent: `Recognizer.watchHoverAmong` and `watchPressAmong` fail,
|
|
299
|
+
* naming it.
|
|
300
|
+
*/
|
|
301
|
+
// #665's PR 5 (Q56, Q17's probe: a listener set per member cost 12 ms and 4.6 KB a member per 1,000).
|
|
302
|
+
readonly pointerAmong?: ((memberOf: (node: unknown) => Option.Option<unknown>) => InputFeed.InputFeed<TargetEvent<PointerLikeEvent>>) | undefined
|
|
303
|
+
/**
|
|
304
|
+
* The focus and blur of many targets and of whatever inside each, from one source, each told with the
|
|
305
|
+
* target it's for, as its `memberOf` names it: what `focus(target)` would tell it, and at its start a
|
|
306
|
+
* focus already within one. Absent: no key presses a target among them.
|
|
307
|
+
*/
|
|
308
|
+
// #665's PR 5 (Q57): a **Keyboard press** on a Batch's member.
|
|
309
|
+
readonly focusAmong?: ((memberOf: (node: unknown) => Option.Option<unknown>) => InputFeed.InputFeed<TargetEvent<FocusLikeEvent>>) | undefined
|
|
285
310
|
}>()("@wardic/core/InputSource") {}
|
|
286
311
|
|
|
287
312
|
/**
|
package/src/LiveValue.ts
CHANGED
|
@@ -27,7 +27,8 @@ import * as Match from "effect/Match"
|
|
|
27
27
|
import { constant, constFalse, constTrue, constUndefined, constVoid, identity } from "effect/Function"
|
|
28
28
|
import * as Option from "effect/Option"
|
|
29
29
|
import * as Predicate from "effect/Predicate"
|
|
30
|
-
import
|
|
30
|
+
import * as Atom from "effect/reactivity/Atom"
|
|
31
|
+
import * as AtomRegistry from "effect/reactivity/AtomRegistry"
|
|
31
32
|
import * as Rec from "effect/Record"
|
|
32
33
|
import type * as Scope from "effect/Scope"
|
|
33
34
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
@@ -36,7 +37,7 @@ import * as Easing from "./Easing.ts"
|
|
|
36
37
|
import * as InterpolatorRegistry from "./InterpolatorRegistry.ts"
|
|
37
38
|
import type * as Frame from "./Frame.ts"
|
|
38
39
|
import * as Machine from "./Machine.ts"
|
|
39
|
-
import * as
|
|
40
|
+
import * as ScrollSource from "./ScrollSource.ts"
|
|
40
41
|
import * as Supersede from "./Supersede.ts"
|
|
41
42
|
import { dual } from "./internal/dual.ts"
|
|
42
43
|
|
|
@@ -534,11 +535,12 @@ export interface ScrollValues {
|
|
|
534
535
|
* @example
|
|
535
536
|
* const { scrollYProgress } = yield* LiveValue.scroll({ container })
|
|
536
537
|
*/
|
|
537
|
-
// #234, ADR-0043 *Amendment (#233, #234)*: derived from the Environment's `Probe
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
const
|
|
538
|
+
// #234, ADR-0043 *Amendment (#233, #234)*: derived from the Environment's `ScrollSource` (the Probe's
|
|
539
|
+
// `scroll` until #518).
|
|
540
|
+
export const scroll: (options?: ScrollSource.Options) => Effect.Effect<ScrollValues, never, ScrollSource.ScrollSource | Scope.Scope> =
|
|
541
|
+
Effect.fnUntraced(function* (options: ScrollSource.Options = {}) {
|
|
542
|
+
const source = yield* ScrollSource.ScrollSource
|
|
543
|
+
const info = yield* source.scroll(options)
|
|
542
544
|
return {
|
|
543
545
|
scrollX: Atom.make((get) => get(info).x.current),
|
|
544
546
|
scrollY: Atom.make((get) => get(info).y.current),
|