@wardic/dom 1.1.2 → 1.1.3
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/ReorderController.d.ts +12 -1
- package/dist/ReorderController.d.ts.map +1 -1
- package/dist/ReorderController.js +25 -2
- package/dist/ReorderController.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/appear.d.ts +7 -2
- package/dist/internal/appear.d.ts.map +1 -1
- package/dist/internal/appear.js +2 -2
- package/dist/internal/appear.js.map +1 -1
- package/dist/internal/clock.d.ts +3 -0
- package/dist/internal/clock.d.ts.map +1 -1
- package/dist/internal/clock.js +3 -0
- package/dist/internal/clock.js.map +1 -1
- package/dist/internal/reorder.d.ts +3 -0
- package/dist/internal/reorder.d.ts.map +1 -1
- package/dist/internal/reorder.js +1 -1
- package/dist/internal/reorder.js.map +1 -1
- package/dist/unstable/AppearAnimations.d.ts +14 -1
- package/dist/unstable/AppearAnimations.d.ts.map +1 -1
- package/dist/unstable/AppearAnimations.js +16 -3
- package/dist/unstable/AppearAnimations.js.map +1 -1
- package/dist/unstable/DragDefaults.d.ts +6 -5
- package/dist/unstable/DragDefaults.d.ts.map +1 -1
- package/dist/unstable/DragDefaults.js +2 -6
- package/dist/unstable/DragDefaults.js.map +1 -1
- package/dist/unstable/DragTrack.d.ts +8 -0
- package/dist/unstable/DragTrack.d.ts.map +1 -1
- package/dist/unstable/DragTrack.js +17 -0
- package/dist/unstable/DragTrack.js.map +1 -1
- package/dist/unstable/ElementSetup.d.ts +8 -2
- package/dist/unstable/ElementSetup.d.ts.map +1 -1
- package/dist/unstable/ElementSetup.js +14 -2
- package/dist/unstable/ElementSetup.js.map +1 -1
- package/dist/unstable/Feature.d.ts +5 -4
- package/dist/unstable/Feature.d.ts.map +1 -1
- package/dist/unstable/Feature.js +7 -4
- package/dist/unstable/Feature.js.map +1 -1
- package/dist/unstable/GestureFeatures.d.ts +132 -3
- package/dist/unstable/GestureFeatures.d.ts.map +1 -1
- package/dist/unstable/GestureFeatures.js +189 -11
- package/dist/unstable/GestureFeatures.js.map +1 -1
- package/dist/unstable/Imperative.d.ts +11 -0
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +37 -7
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/InstanceFeatures.d.ts +7 -0
- package/dist/unstable/InstanceFeatures.d.ts.map +1 -0
- package/dist/unstable/InstanceFeatures.js +69 -0
- package/dist/unstable/InstanceFeatures.js.map +1 -0
- package/dist/unstable/ReorderInput.d.ts +45 -0
- package/dist/unstable/ReorderInput.d.ts.map +1 -0
- package/dist/unstable/ReorderInput.js +116 -0
- package/dist/unstable/ReorderInput.js.map +1 -0
- package/package.json +3 -3
- package/src/ReorderController.ts +34 -1
- package/src/index.ts +1 -1
- package/src/internal/appear.ts +9 -4
- package/src/internal/clock.ts +3 -0
- package/src/internal/reorder.ts +1 -1
- package/src/unstable/AppearAnimations.ts +21 -3
- package/src/unstable/DragDefaults.ts +9 -9
- package/src/unstable/DragTrack.ts +21 -0
- package/src/unstable/ElementSetup.ts +14 -1
- package/src/unstable/Feature.ts +9 -5
- package/src/unstable/GestureFeatures.ts +297 -3
- package/src/unstable/Imperative.ts +45 -13
- package/src/unstable/InstanceFeatures.ts +82 -0
- package/src/unstable/ReorderInput.ts +143 -0
package/src/internal/appear.ts
CHANGED
|
@@ -891,8 +891,13 @@ export interface BatchSlot {
|
|
|
891
891
|
|
|
892
892
|
/** One render's Appear rules: a slot per element, and the `<style>` text for the head and each late chunk. */
|
|
893
893
|
export interface Sheet {
|
|
894
|
-
/**
|
|
895
|
-
|
|
894
|
+
/**
|
|
895
|
+
* A slot for the next element: named by the sheet's count, or by `name` under `--wardic-a` when the
|
|
896
|
+
* binding names it (a Foldkit render names each by its element's path, the same on the server and the
|
|
897
|
+
* hydration render, #794). A Batch's slot (`batch`) stays on the count, in the same namespace: a
|
|
898
|
+
* binding naming slots keeps its names apart from the count's digits, or asks for no Batch rule.
|
|
899
|
+
*/
|
|
900
|
+
readonly slot: (name?: string | undefined) => Slot
|
|
896
901
|
/**
|
|
897
902
|
* A slot for a Batch's members on `play`'s rule, and under `prefers-reduced-motion: reduce` `reduced`'s
|
|
898
903
|
* when given (a provider's `"user"`): both rules, and the slot's `:root` lines naming each with no delay,
|
|
@@ -966,8 +971,8 @@ export const sheet = (): Sheet => {
|
|
|
966
971
|
}),
|
|
967
972
|
}
|
|
968
973
|
},
|
|
969
|
-
slot: () => {
|
|
970
|
-
const property = `--${PREFIX}a${slots++}`
|
|
974
|
+
slot: (name) => {
|
|
975
|
+
const property = `--${PREFIX}a${UndefinedOr.match(name, { onUndefined: () => String(slots++), onDefined: identity })}`
|
|
971
976
|
return {
|
|
972
977
|
animation: `var(${property})`,
|
|
973
978
|
define: (play, reduced, supports = []) =>
|
package/src/internal/clock.ts
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* requests its flushes from the same member, so the Clock and the gate share the browser's
|
|
6
6
|
* frames. Everything else — the ref-counted Refresh frame loop, the `dt` computation and the
|
|
7
7
|
* `wardic.clock` span — lives in core, so every Environment's Clock behaves the same (ADR-0004).
|
|
8
|
+
* So the Clock's `frameAt` (#791) is the last tick's `requestAnimationFrame` timestamp: what
|
|
9
|
+
* `document.timeline.currentTime` reads inside that frame, which a binding's hint passes to the
|
|
10
|
+
* Frame loop (ADR-0071, decision 32).
|
|
8
11
|
*/
|
|
9
12
|
import * as Clock from "@wardic/core/Clock"
|
|
10
13
|
import * as RefreshFrameSource from "@wardic/core/RefreshFrameSource"
|
package/src/internal/reorder.ts
CHANGED
|
@@ -623,7 +623,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
|
|
|
623
623
|
const noop = (): void => {}
|
|
624
624
|
|
|
625
625
|
/** Whether two orders hold the same items in the same order. */
|
|
626
|
-
const sameOrder: Equivalence.Equivalence<ReadonlyArray<unknown>> = Arr.makeEquivalence(Equivalence.strictEqual())
|
|
626
|
+
export const sameOrder: Equivalence.Equivalence<ReadonlyArray<unknown>> = Arr.makeEquivalence(Equivalence.strictEqual())
|
|
627
627
|
|
|
628
628
|
/** Whether `values` is the order the group last asked for (ADR-0037, *Amendment (#721)*): its items, in its order. */
|
|
629
629
|
const isAsked = (asked: ReadonlyArray<unknown> | undefined, values: ReadonlyArray<unknown>): boolean =>
|
|
@@ -303,6 +303,8 @@ export interface ServerAppear {
|
|
|
303
303
|
/** Its tag and its targets at mount, which name it when the provider explains (#585). */
|
|
304
304
|
tag: string | undefined,
|
|
305
305
|
to: Option.Option<Values.Values>,
|
|
306
|
+
/** Its slot's name under `--wardic-a`, when the binding names it ({@link Appear.Sheet.slot}; #794); the sheet's count without. */
|
|
307
|
+
slot?: string | undefined,
|
|
306
308
|
) => {
|
|
307
309
|
readonly entry: Entry
|
|
308
310
|
readonly animation: Option.Option<string>
|
|
@@ -376,6 +378,20 @@ export const explainerOf = (appear: boolean | "explain" | undefined): ((message:
|
|
|
376
378
|
return (message) => Effect.runSync(Effect.logWarning(message))
|
|
377
379
|
}
|
|
378
380
|
|
|
381
|
+
/** Why an element's own `animation` in its style rules its Appear animation out (decision 4): the one CSS animation it has would be taken. What each binding's veto says. */
|
|
382
|
+
export const OWN_ANIMATION = "its own style sets an animation"
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* A render's Appear animations from a provider's settings (decisions 3 and 5): none with `appear:
|
|
386
|
+
* false`; else {@link serverAppear} under `reducedMotion`, the user's preference with none set, the
|
|
387
|
+
* explainer `appear` asks for (#585) and the `nonce` (#618). Each binding's provider makes its own
|
|
388
|
+
* through it, Foldkit's walk too (#794).
|
|
389
|
+
*/
|
|
390
|
+
export const serverAppearUnder = (appear: boolean | "explain" | undefined, reducedMotion: ReducedMotion.Config | undefined, nonce: string | undefined): ServerAppear | undefined => {
|
|
391
|
+
if (appear === false) return undefined
|
|
392
|
+
return serverAppear(UndefinedOr.match(reducedMotion, { onUndefined: (): ReducedMotion.Config => "user", onDefined: identity }), explainerOf(appear), nonce)
|
|
393
|
+
}
|
|
394
|
+
|
|
379
395
|
/** An element as the provider's explanation names it (#585): its tag and the keys its mount animates. */
|
|
380
396
|
const nameOf = (entry: Entry): string => {
|
|
381
397
|
const element = UndefinedOr.match(entry.tag, { onUndefined: () => "an element", onDefined: (tag) => `<${tag}>` })
|
|
@@ -438,11 +454,11 @@ export const serverAppear = (reducedMotion: ReducedMotion.Config, explain?: (mes
|
|
|
438
454
|
const chunkCss = (): string => write(nextBatch())
|
|
439
455
|
return {
|
|
440
456
|
reducedMotion,
|
|
441
|
-
enter: (given, group, setting, skipped, tag, to) => {
|
|
457
|
+
enter: (given, group, setting, skipped, tag, to, name) => {
|
|
442
458
|
// Skipped (#468): its one play in both slots, under no media query.
|
|
443
459
|
const own = Bool.match(skipped, { onTrue: (): ReducedMotion.Config => "never", onFalse: () => settingOr(setting, reducedMotion) })
|
|
444
460
|
const animation = playsUnder(given, own)
|
|
445
|
-
const slot = Option.liftPredicate(animation, plays).pipe(Option.map(() => sheet.slot()))
|
|
461
|
+
const slot = Option.liftPredicate(animation, plays).pipe(Option.map(() => sheet.slot(name)))
|
|
446
462
|
const entry: Entry = { plays: animation, slot, group, vetoes: [], user: own === "user", skipped, tag, to }
|
|
447
463
|
// Why it plays neither: its normal play's reason, its reduced one's when that differs (#585).
|
|
448
464
|
if (Predicate.isNotUndefined(explain)) {
|
|
@@ -667,6 +683,8 @@ export interface ServerElement {
|
|
|
667
683
|
readonly reducedMotion?: ReducedMotion.Config | undefined
|
|
668
684
|
/** Whether its nearest `WardicConfig` skips its animations (#468). Its transition's own `skipAnimations` counts too. */
|
|
669
685
|
readonly skipAnimations?: boolean | undefined
|
|
686
|
+
/** Its slot's name under `--wardic-a`, when the binding names it by the element's place (#794); the sheet's count without. */
|
|
687
|
+
readonly slot?: string | undefined
|
|
670
688
|
}
|
|
671
689
|
|
|
672
690
|
/**
|
|
@@ -718,7 +736,7 @@ export const enterServer = (
|
|
|
718
736
|
},
|
|
719
737
|
onFalse: () => ({ normal: play(false), reduced: play(true) }),
|
|
720
738
|
})
|
|
721
|
-
const { entry, animation: inline, late, chunkRoot } = appear.enter(plays, el.group, el.reducedMotion, skipped, el.tag, el.to)
|
|
739
|
+
const { entry, animation: inline, late, chunkRoot } = appear.enter(plays, el.group, el.reducedMotion, skipped, el.tag, el.to, el.slot)
|
|
722
740
|
return {
|
|
723
741
|
late,
|
|
724
742
|
chunkRoot,
|
|
@@ -10,25 +10,27 @@
|
|
|
10
10
|
// Unstable: ADR-0071, decision 5. #672 (Q11, PR2-Q3): solid's `drag-defaults.ts`, out of `spine.ts` since
|
|
11
11
|
// PR 2, moved to dom for every DOM binding's drag elements.
|
|
12
12
|
import * as Style from "../Style.ts"
|
|
13
|
-
import * as
|
|
13
|
+
import * as ElementSetup from "./ElementSetup.ts"
|
|
14
14
|
import * as Option from "effect/Option"
|
|
15
|
-
import * as Rec from "effect/Record"
|
|
16
15
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
17
16
|
import type * as WardConfig from "./WardConfig.ts"
|
|
18
17
|
|
|
19
|
-
/** What a
|
|
20
|
-
interface DragInternals {
|
|
18
|
+
/** What a Reorder item adds to an element's drag: its gesture's axis, read at each drag's start. */
|
|
19
|
+
export interface DragInternals {
|
|
21
20
|
readonly dragAxis?: (() => boolean | "x" | "y") | undefined
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
/** A plain element's drag internals: none. */
|
|
25
24
|
const NO_DRAG_INTERNALS: DragInternals = {}
|
|
26
25
|
|
|
26
|
+
/** The drag props the defaults are read from: whether the element drags, and whether its own presses do. */
|
|
27
|
+
export type DragProps = Pick<WardConfig.WardConfig, "drag" | "dragListener">
|
|
28
|
+
|
|
27
29
|
/**
|
|
28
30
|
* The drag axis a spine runs with: its static `drag` config, else `true` for a
|
|
29
31
|
* `<Reorder>` item (its gesture's axis comes from `dragAxis`), else none.
|
|
30
32
|
*/
|
|
31
|
-
export const dragAxisOf = (config:
|
|
33
|
+
export const dragAxisOf = (config: DragProps, internal: DragInternals = NO_DRAG_INTERNALS): boolean | "x" | "y" | undefined =>
|
|
32
34
|
Option.getOrUndefined(
|
|
33
35
|
Option.orElse(Option.filter(Option.fromUndefinedOr(config.drag), (drag) => drag !== false), () =>
|
|
34
36
|
Option.map(Option.fromUndefinedOr(internal.dragAxis), (): true => true)),
|
|
@@ -38,7 +40,7 @@ export const dragAxisOf = (config: WardConfig.WardConfig, internal: DragInternal
|
|
|
38
40
|
* A drag element's defaults (ADR-0019 *Amendment (Reorder)*): its axis's, unless its own presses don't
|
|
39
41
|
* drag it (`dragListener={false}`, #431), as Motion's come with its listener.
|
|
40
42
|
*/
|
|
41
|
-
export const dragDefaultsOf = (config:
|
|
43
|
+
export const dragDefaultsOf = (config: DragProps, internal: DragInternals = NO_DRAG_INTERNALS): Style.DragDefaults | undefined => {
|
|
42
44
|
if (config.dragListener === false) return undefined
|
|
43
45
|
return UndefinedOr.map(dragAxisOf(config, internal), Style.dragDefaults)
|
|
44
46
|
}
|
|
@@ -50,8 +52,6 @@ export const dragDefaultsOf = (config: WardConfig.WardConfig, internal: DragInte
|
|
|
50
52
|
* component may not pass them on.
|
|
51
53
|
*/
|
|
52
54
|
export const applyDragDefaults = (element: HTMLElement, defaults: Style.DragDefaults): void => {
|
|
53
|
-
|
|
54
|
-
if (element.style.getPropertyValue(key) === "") element.style.setProperty(key, UndefinedOr.getOrThrow(defaults[key]))
|
|
55
|
-
})
|
|
55
|
+
ElementSetup.writeUnderStyle(element, defaults)
|
|
56
56
|
if (!element.hasAttribute("draggable")) element.setAttribute("draggable", Style.DRAG_DEFAULT_ATTRIBUTES.draggable)
|
|
57
57
|
}
|
|
@@ -142,6 +142,27 @@ export interface DragTrackConfig {
|
|
|
142
142
|
readonly listen?: boolean | undefined
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
/** The drag props a track's config is read from: an element's, its axis and its constraints resolved by the binding. */
|
|
146
|
+
export type DragOptions = Pick<WardConfig.WardDragConfig, "dragElastic" | "dragMomentum" | "dragSnapToOrigin" | "dragPropagation" | "dragDirectionLock" | "dragListener">
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A track's config from an element's drag props (#793), for every binding: `axis` and `constraints` as
|
|
150
|
+
* the binding resolved them, `transition` the element's drag transition ({@link DragTransition.dragTransitionOf}),
|
|
151
|
+
* which its layout node shares.
|
|
152
|
+
*/
|
|
153
|
+
// #793 (PR 2): solid's `create-ward.tsx`'s `trackConfig`, moved to dom for both bindings' tracks.
|
|
154
|
+
export const trackConfigOf = (c: DragOptions, axis: boolean | "x" | "y", constraints: Drag.Bounds | undefined, transition: ProjectionSystem.DragTransition): DragTrackConfig => ({
|
|
155
|
+
axis,
|
|
156
|
+
constraints,
|
|
157
|
+
elastic: c.dragElastic,
|
|
158
|
+
momentum: c.dragMomentum,
|
|
159
|
+
snapToOrigin: c.dragSnapToOrigin,
|
|
160
|
+
propagation: c.dragPropagation,
|
|
161
|
+
directionLock: c.dragDirectionLock,
|
|
162
|
+
transition,
|
|
163
|
+
listen: c.dragListener,
|
|
164
|
+
})
|
|
165
|
+
|
|
145
166
|
/** What the track's watches and responses run with: the provider's services and the gestures' input (#511). */
|
|
146
167
|
export type TrackServices = WardicServices.WardicServices | InputSource.InputSource
|
|
147
168
|
|
|
@@ -276,6 +276,17 @@ export const draggingWithWillChange = (live: LiveStyle.LiveStyle | undefined, se
|
|
|
276
276
|
*/
|
|
277
277
|
export const claimForDrag = (element: Element): (() => void) => () => Spine.tellDrag(element, true)
|
|
278
278
|
|
|
279
|
+
/**
|
|
280
|
+
* Write `style` on `element` under its own inline style (#793): each key its inline style doesn't set,
|
|
281
|
+
* so the app's wins, as a drag element's defaults and a Reorder group's style go on (ADR-0019
|
|
282
|
+
* *Amendment (Reorder)*).
|
|
283
|
+
*/
|
|
284
|
+
export const writeUnderStyle = (element: HTMLElement, style: Readonly<Record<string, string>>): void => {
|
|
285
|
+
Arr.forEach(Rec.keys(style), (key) => {
|
|
286
|
+
if (element.style.getPropertyValue(key) === "") element.style.setProperty(key, UndefinedOr.getOrThrow(style[key]))
|
|
287
|
+
})
|
|
288
|
+
}
|
|
289
|
+
|
|
279
290
|
/** Log, once per element, that a `transform` string gave way to the transform keys in its `style` (#130). */
|
|
280
291
|
export const warnDroppedTransform = (runtime: WardicServices.Runner<WardicServices.WardicServices>, id: string): void => {
|
|
281
292
|
runtime.runFork(
|
|
@@ -341,7 +352,7 @@ const NO_APPEAR_ENTRY = (provided: VariantTree.WardicVariantContextValue | undef
|
|
|
341
352
|
* values, its targets at mount (`animate`, or an inherited variant name against its `variants`),
|
|
342
353
|
* its transition, its place in its parent's group, and its nearest `WardicConfig`'s reduced motion
|
|
343
354
|
* (#434). `state` is the provider's, `undefined` with `appear={false}`: each binding reads it from its
|
|
344
|
-
* own context.
|
|
355
|
+
* own context. `slot` names its slot when the binding names them by the element's place (#794).
|
|
345
356
|
*/
|
|
346
357
|
export const appearEntryOf = (
|
|
347
358
|
state: AppearAnimations.ServerAppear | undefined,
|
|
@@ -352,6 +363,7 @@ export const appearEntryOf = (
|
|
|
352
363
|
quiet: boolean,
|
|
353
364
|
reducedMotion: ReducedMotion.Config | undefined,
|
|
354
365
|
skipAnimations = false,
|
|
366
|
+
slot?: string | undefined,
|
|
355
367
|
): ServerAppearOf =>
|
|
356
368
|
UndefinedOr.match(state, {
|
|
357
369
|
onUndefined: () => NO_APPEAR_ENTRY(node.provided),
|
|
@@ -374,6 +386,7 @@ export const appearEntryOf = (
|
|
|
374
386
|
ownTransition: VariantTarget.transitionOfTarget(own, c.transition),
|
|
375
387
|
reducedMotion,
|
|
376
388
|
skipAnimations,
|
|
389
|
+
slot,
|
|
377
390
|
})
|
|
378
391
|
return {
|
|
379
392
|
style: Option.match(entered.animation, { onNone: constUndefined, onSome: (animation) => ({ animation }) }),
|
package/src/unstable/Feature.ts
CHANGED
|
@@ -485,10 +485,14 @@ export const wantsLayoutNode = (c: WardConfig.WardConfig): boolean =>
|
|
|
485
485
|
c.layout === true || Predicate.isString(c.layout) || Predicate.isNotUndefined(c.layoutId) || c.layoutScroll === true || c.layoutRoot === true
|
|
486
486
|
|
|
487
487
|
/**
|
|
488
|
-
* Development's word on a missing Feature (#511, ADR-0067 decision 7): what needed it,
|
|
489
|
-
*
|
|
490
|
-
*
|
|
488
|
+
* Development's word on a missing Feature (#511, ADR-0067 decision 7): what needed it, and `how` to
|
|
489
|
+
* add it: by default a Solid provider's `features`, the Feature imported from the binding's `entry`;
|
|
490
|
+
* a binding with another way (Foldkit's `Wardic.make`) says so. Not a Complete element, which a
|
|
491
|
+
* `strict` section makes an error (#581).
|
|
491
492
|
*/
|
|
492
|
-
export const missingMessage = (feature: string, what: string, entry: string): string =>
|
|
493
|
-
|
|
493
|
+
export const missingMessage = (feature: string, what: string, entry: string, how: string = providerHow(feature, entry)): string => `wardic: ${what} needs the \`${feature}\` Feature, ${how}`
|
|
494
|
+
|
|
495
|
+
/** How a Solid app adds a Feature (the default `how`): a provider's `features`, the Feature imported from `entry`. */
|
|
496
|
+
const providerHow = (feature: string, entry: string): string =>
|
|
497
|
+
`which no WardicProvider or LazyWardic above this element has. ` +
|
|
494
498
|
`Add it: \`import { ${feature} } from "${entry}"\`, then \`<WardicProvider features={[${feature}]}>\` or \`<LazyWardic features={[${feature}]}>\`.`
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* What an element reads of its section's gesture Features (#511, ADR-0067 decision 3): each gesture's
|
|
3
|
-
* service, `undefined` without its Feature, the gestures' input a section with one has,
|
|
4
|
-
* development's message on a missing one names
|
|
5
|
-
* their keys.
|
|
3
|
+
* service, `undefined` without its Feature, the gestures' input a section with one has, the words
|
|
4
|
+
* development's message on a missing one names, and which gestures a config wants (Motion's feature
|
|
5
|
+
* definitions). Every binding's; it reaches no Feature's code, only their keys.
|
|
6
6
|
*
|
|
7
7
|
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
8
8
|
*
|
|
9
9
|
* @module
|
|
10
10
|
*/
|
|
11
11
|
// Unstable: ADR-0071, decision 5. #672: solid's `gesture-features.ts`, moved to dom with the Features.
|
|
12
|
+
import type * as Drag from "@wardic/core/Drag"
|
|
13
|
+
import type * as DragRecognizer from "@wardic/core/DragRecognizer"
|
|
12
14
|
import * as InputSource from "@wardic/core/InputSource"
|
|
15
|
+
import type * as Recognizer from "@wardic/core/Recognizer"
|
|
16
|
+
import * as Bool from "effect/Boolean"
|
|
13
17
|
import * as Context from "effect/Context"
|
|
18
|
+
import * as Match from "effect/Match"
|
|
14
19
|
import * as Option from "effect/Option"
|
|
20
|
+
import * as Predicate from "effect/Predicate"
|
|
21
|
+
import { constUndefined, identity } from "effect/Function"
|
|
22
|
+
import * as MutableRef from "effect/MutableRef"
|
|
23
|
+
import * as UndefinedOr from "effect/UndefinedOr"
|
|
24
|
+
import * as GestureInfo from "./GestureInfo.ts"
|
|
15
25
|
|
|
16
26
|
/** `key`'s service among `services`, or `undefined` when they hold none: its Feature isn't there. */
|
|
17
27
|
export const serviceIn = <I, S>(services: Context.Context<never>, key: Context.Key<I, S>): S | undefined =>
|
|
@@ -36,3 +46,287 @@ export const hasService = <I, S>(services: Context.Context<never>, key: Context.
|
|
|
36
46
|
|
|
37
47
|
/** `key`'s service among `services`, which hold it: a Feature a hook or component brought. */
|
|
38
48
|
export const serviceOf = <I, S>(services: Context.Context<never>, key: Context.Key<I, S>): S => Context.get(services as Context.Context<I>, key)
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The keys a gesture is wanted by (Motion's `features/definitions.ts`): every binding's config has
|
|
52
|
+
* them, its callbacks in its own shape (Solid 1's functions, Foldkit's Messages), so only their presence
|
|
53
|
+
* is read.
|
|
54
|
+
*/
|
|
55
|
+
export interface GestureWants {
|
|
56
|
+
readonly whileHover?: unknown
|
|
57
|
+
readonly onHoverStart?: unknown
|
|
58
|
+
readonly onHoverEnd?: unknown
|
|
59
|
+
readonly whileTap?: unknown
|
|
60
|
+
readonly onTap?: unknown
|
|
61
|
+
readonly onTapStart?: unknown
|
|
62
|
+
readonly onTapCancel?: unknown
|
|
63
|
+
readonly onPan?: unknown
|
|
64
|
+
readonly onPanStart?: unknown
|
|
65
|
+
readonly onPanSessionStart?: unknown
|
|
66
|
+
readonly onPanEnd?: unknown
|
|
67
|
+
readonly whileInView?: unknown
|
|
68
|
+
readonly onViewportEnter?: unknown
|
|
69
|
+
readonly onViewportLeave?: unknown
|
|
70
|
+
readonly whileFocus?: unknown
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Every key the `wants*` below read (#525): an element given none of them, its keys fixed, can never
|
|
75
|
+
* want a gesture, so it starts no computation to watch for one. Solid's `gesture-keys.ssr.test.tsx`
|
|
76
|
+
* checks each of them turns its gesture on.
|
|
77
|
+
*/
|
|
78
|
+
// #793 (PR 1's review): solid's `gesture-callbacks.ts`'s, moved to dom for every binding's gesture start.
|
|
79
|
+
export const GESTURE_KEYS = [
|
|
80
|
+
"whileHover",
|
|
81
|
+
"onHoverStart",
|
|
82
|
+
"onHoverEnd",
|
|
83
|
+
"whileTap",
|
|
84
|
+
"onTap",
|
|
85
|
+
"onTapStart",
|
|
86
|
+
"onTapCancel",
|
|
87
|
+
"onPan",
|
|
88
|
+
"onPanStart",
|
|
89
|
+
"onPanSessionStart",
|
|
90
|
+
"onPanEnd",
|
|
91
|
+
"whileInView",
|
|
92
|
+
"onViewportEnter",
|
|
93
|
+
"onViewportLeave",
|
|
94
|
+
"whileFocus",
|
|
95
|
+
] as const satisfies ReadonlyArray<keyof GestureWants>
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Whether `config` runs the hover recognizer (Motion's hover feature). Read at every config change of
|
|
99
|
+
* an element that doesn't run it yet: statement `if`s, no array (ADR-0025).
|
|
100
|
+
*/
|
|
101
|
+
export const wantsHover = (config: GestureWants): boolean => {
|
|
102
|
+
if (Predicate.isNotUndefined(config.whileHover)) return true
|
|
103
|
+
if (Predicate.isNotUndefined(config.onHoverStart)) return true
|
|
104
|
+
return Predicate.isNotUndefined(config.onHoverEnd)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Whether `config` runs the press recognizer (Motion's tap feature): as {@link wantsHover}. */
|
|
108
|
+
export const wantsPress = (config: GestureWants): boolean => {
|
|
109
|
+
if (Predicate.isNotUndefined(config.whileTap)) return true
|
|
110
|
+
if (Predicate.isNotUndefined(config.onTap)) return true
|
|
111
|
+
if (Predicate.isNotUndefined(config.onTapStart)) return true
|
|
112
|
+
return Predicate.isNotUndefined(config.onTapCancel)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Whether `config` runs the pan recognizer (Motion's pan feature, #273): as {@link wantsHover}. */
|
|
116
|
+
export const wantsPan = (config: GestureWants): boolean => {
|
|
117
|
+
if (Predicate.isNotUndefined(config.onPan)) return true
|
|
118
|
+
if (Predicate.isNotUndefined(config.onPanStart)) return true
|
|
119
|
+
if (Predicate.isNotUndefined(config.onPanSessionStart)) return true
|
|
120
|
+
return Predicate.isNotUndefined(config.onPanEnd)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Whether `config` runs the in-view recognizer (Motion's inView feature, #273): `whileInView` or a viewport callback. */
|
|
124
|
+
export const wantsInView = (config: GestureWants): boolean => {
|
|
125
|
+
if (Predicate.isNotUndefined(config.whileInView)) return true
|
|
126
|
+
if (Predicate.isNotUndefined(config.onViewportEnter)) return true
|
|
127
|
+
return Predicate.isNotUndefined(config.onViewportLeave)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Whether `config` runs the focus recognizer (Motion's focus feature, #273): `whileFocus`. */
|
|
131
|
+
export const wantsFocus = (config: GestureWants): boolean => Predicate.isNotUndefined(config.whileFocus)
|
|
132
|
+
|
|
133
|
+
/** Each press phase's callback (Motion's `onTapStart`, `onTap`, `onTapCancel`): a press a drag took over has none, as Motion tells neither. */
|
|
134
|
+
export const PRESS_CALLBACK = { start: "onTapStart", tap: "onTap", cancel: "onTapCancel", dragged: undefined } as const
|
|
135
|
+
|
|
136
|
+
/** Each drag phase's callback (Motion's `onDragStart`, `onDragEnd`), `onDrag` aside, which hears the start and each move. */
|
|
137
|
+
// #793 (PR 2): solid's `gesture-callbacks.ts`'s, moved to dom for every binding's drag callbacks.
|
|
138
|
+
export const DRAG_CALLBACK = { start: "onDragStart", move: undefined, end: "onDragEnd" } as const
|
|
139
|
+
|
|
140
|
+
/** Each pan phase's callback past its session's start (Motion's `onPanStart`, `onPanEnd`), `onPan` aside. */
|
|
141
|
+
export const PAN_CALLBACK = { start: "onPanStart", move: undefined, end: "onPanEnd" } as const
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A config's gesture callbacks (Motion's `onHoverStart`, `onTap`, `onDragEnd` and the rest), each in the
|
|
145
|
+
* binding's own shape (Solid 1's functions, Foldkit's Messages): read by name at the event, their
|
|
146
|
+
* presence alone typed here; and `dragDirectionLock`, which says whether a drag's start tells its lock.
|
|
147
|
+
*/
|
|
148
|
+
export interface GestureCallbacks {
|
|
149
|
+
readonly onHoverStart?: unknown
|
|
150
|
+
readonly onHoverEnd?: unknown
|
|
151
|
+
readonly onTapStart?: unknown
|
|
152
|
+
readonly onTap?: unknown
|
|
153
|
+
readonly onTapCancel?: unknown
|
|
154
|
+
readonly onDragStart?: unknown
|
|
155
|
+
readonly onDrag?: unknown
|
|
156
|
+
readonly onDragEnd?: unknown
|
|
157
|
+
readonly onDragTransitionEnd?: unknown
|
|
158
|
+
readonly onDirectionLock?: unknown
|
|
159
|
+
readonly onPanSessionStart?: unknown
|
|
160
|
+
readonly onPanStart?: unknown
|
|
161
|
+
readonly onPan?: unknown
|
|
162
|
+
readonly onPanEnd?: unknown
|
|
163
|
+
readonly onViewportEnter?: unknown
|
|
164
|
+
readonly onViewportLeave?: unknown
|
|
165
|
+
readonly dragDirectionLock?: boolean | undefined
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** A gesture callback's name, as a report says it. */
|
|
169
|
+
export type GestureCallbackName = Exclude<keyof GestureCallbacks, "dragDirectionLock">
|
|
170
|
+
|
|
171
|
+
/** What a binding tells its element's gesture callbacks with. */
|
|
172
|
+
export interface Telling {
|
|
173
|
+
/** The element's config now, read at each event. */
|
|
174
|
+
readonly config: () => GestureCallbacks
|
|
175
|
+
/** Run `handler`, a callback of the config's, with the event's `args`: Solid 1 calls it, Foldkit sends its Message. */
|
|
176
|
+
readonly invoke: (handler: unknown, args: ReadonlyArray<unknown>) => void
|
|
177
|
+
/** Report that the callback `name` threw `defect`. */
|
|
178
|
+
readonly report: (name: GestureCallbackName, defect: unknown) => void
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* What tells an element's gestures to its config's callbacks, for every binding (#273, ADR-0047):
|
|
183
|
+
* Motion's `(event, info)`, the platform's own event carried through (`raw`), then the info
|
|
184
|
+
* (`GestureInfo`), in Motion's order: a locked drag's `onDirectionLock` before its `onDragStart`, a
|
|
185
|
+
* pan's `onPanSessionStart` at the down with the point alone, `onDrag` and `onPan` at the start and
|
|
186
|
+
* each move after. A drag its controls cancelled ends untold (#431). A callback that throws is reported
|
|
187
|
+
* by name and the gesture goes on; `onDrag`'s and `onPan`'s run of throws at its first (#257 item 4).
|
|
188
|
+
*/
|
|
189
|
+
export interface GestureTeller {
|
|
190
|
+
readonly hovered: (edge: Recognizer.Edge) => void
|
|
191
|
+
readonly pressed: (press: Recognizer.PressEvent, element: Element) => void
|
|
192
|
+
readonly dragged: (sample: Drag.Sample) => void
|
|
193
|
+
/** The drag's release came to rest on its own. */
|
|
194
|
+
readonly released: () => void
|
|
195
|
+
readonly panned: (sample: DragRecognizer.PanSample) => void
|
|
196
|
+
/** An in-view edge: `onViewportEnter` or `onViewportLeave`, with the platform's entry. */
|
|
197
|
+
readonly viewed: (edge: Recognizer.ViewEdge) => void
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** A drag's or a pan's start or end callback. */
|
|
201
|
+
type MovementCallback = "onDragStart" | "onDragEnd" | "onPanStart" | "onPanEnd"
|
|
202
|
+
|
|
203
|
+
/** A {@link GestureTeller} over `telling`'s config, invoking and reporting as the binding says. */
|
|
204
|
+
// #793 (PR 2): solid's `gestureCallbacksOf`, moved to dom for both bindings: each gives how a handler is invoked.
|
|
205
|
+
export const gestureTellerOf = ({ config, invoke, report }: Telling): GestureTeller => {
|
|
206
|
+
const guard = callbackGuard(report)
|
|
207
|
+
/** Tell the config's `name`, if it has one, `args`: reported if it throws. */
|
|
208
|
+
const tell = (name: GestureCallbackName, ...args: ReadonlyArray<unknown>): void => {
|
|
209
|
+
const handler = config()[name]
|
|
210
|
+
if (Predicate.isUndefined(handler)) return
|
|
211
|
+
guard.once(name, () => invoke(handler, args))
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* A drag's or a pan's sample, past a pan's session's start: its start's or its end's callback
|
|
215
|
+
* (`named`), then `every`, which hears its start and each move (Motion's pan session runs `onMove` at
|
|
216
|
+
* the start too). The info is built once, for whichever is set.
|
|
217
|
+
*/
|
|
218
|
+
const moved = (named: MovementCallback | undefined, every: "onDrag" | "onPan", sample: Drag.Sample): void => {
|
|
219
|
+
const c = config()
|
|
220
|
+
const own = UndefinedOr.match(named, { onUndefined: constUndefined, onDefined: (key) => c[key] })
|
|
221
|
+
const each = Bool.match(sample.phase !== "end", { onTrue: () => c[every], onFalse: constUndefined })
|
|
222
|
+
if (Bool.and(Predicate.isUndefined(own), Predicate.isUndefined(each))) return
|
|
223
|
+
const raw = sample.raw as PointerEvent
|
|
224
|
+
const info = GestureInfo.dragInfoOf(sample)
|
|
225
|
+
UndefinedOr.map(named, (key) => UndefinedOr.map(own, (handler) => guard.once(key, () => invoke(handler, [raw, info]))))
|
|
226
|
+
UndefinedOr.map(each, (handler) => guard.perMove(every, () => invoke(handler, [raw, info])))
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
hovered: (edge) => {
|
|
230
|
+
const name = Bool.match(edge.active, { onTrue: () => "onHoverStart" as const, onFalse: () => "onHoverEnd" as const })
|
|
231
|
+
tell(name, edge.event.raw as PointerEvent, GestureInfo.pointInfoOf(edge.event))
|
|
232
|
+
},
|
|
233
|
+
pressed: (press, element) => {
|
|
234
|
+
const name = PRESS_CALLBACK[press.phase]
|
|
235
|
+
if (Predicate.isUndefined(name)) return
|
|
236
|
+
tell(name, press.event.raw as GestureInfo.WardicPressEvent, GestureInfo.pressInfoOf(press, element))
|
|
237
|
+
},
|
|
238
|
+
dragged: (sample) => {
|
|
239
|
+
// A drag its controls cancelled (#431) ends untold, as Motion's `cancel` tells no `onDragEnd`.
|
|
240
|
+
if (sample.cancelled === true) return
|
|
241
|
+
// A direction-locked drag's lock, at its start, before `onDragStart` (Motion's order).
|
|
242
|
+
if (Bool.and(sample.phase === "start", config().dragDirectionLock === true)) tell("onDirectionLock", sample.axis as "x" | "y")
|
|
243
|
+
moved(DRAG_CALLBACK[sample.phase], "onDrag", sample)
|
|
244
|
+
},
|
|
245
|
+
released: () => tell("onDragTransitionEnd"),
|
|
246
|
+
panned: (sample) => {
|
|
247
|
+
// Its session's start, at the down: Motion's `onPanSessionStart`, with the point only.
|
|
248
|
+
if (sample.phase === "session") {
|
|
249
|
+
tell("onPanSessionStart", sample.raw as PointerEvent, GestureInfo.pointOfSample(sample))
|
|
250
|
+
return
|
|
251
|
+
}
|
|
252
|
+
moved(PAN_CALLBACK[sample.phase], "onPan", sample as Drag.Sample)
|
|
253
|
+
},
|
|
254
|
+
viewed: (edge) => {
|
|
255
|
+
const name = Bool.match(edge.active, { onTrue: () => "onViewportEnter" as const, onFalse: () => "onViewportLeave" as const })
|
|
256
|
+
tell(name, edge.raw as IntersectionObserverEntry)
|
|
257
|
+
},
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* A guard around an element's gesture callbacks (#257 item 4): `once` runs `call` and reports what it
|
|
263
|
+
* throws; `perMove`, for `onDrag` and `onPan`, reports a run of throws at its first, so one that throws
|
|
264
|
+
* at every move logs once, and a call that returns ends the run. The gesture goes on either way.
|
|
265
|
+
*/
|
|
266
|
+
interface CallbackGuard {
|
|
267
|
+
readonly once: (name: GestureCallbackName, call: () => void) => void
|
|
268
|
+
readonly perMove: (name: GestureCallbackName, call: () => void) => void
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** A {@link CallbackGuard} reporting through `report`, told the callback's name and what it threw. */
|
|
272
|
+
// #793 (PR 2): solid's `gesture-callbacks.ts`'s `call` and `callPerMove`, moved to dom with the teller.
|
|
273
|
+
const callbackGuard = (report: Telling["report"]): CallbackGuard => {
|
|
274
|
+
// The per-move callbacks whose last call threw, made at the first throw: most elements never see one.
|
|
275
|
+
const failing = MutableRef.make<Set<string> | undefined>(undefined)
|
|
276
|
+
const failingNow = (): Set<string> =>
|
|
277
|
+
UndefinedOr.match(MutableRef.get(failing), {
|
|
278
|
+
onUndefined: () => {
|
|
279
|
+
const made = new Set<string>()
|
|
280
|
+
MutableRef.set(failing, made)
|
|
281
|
+
return made
|
|
282
|
+
},
|
|
283
|
+
onDefined: identity,
|
|
284
|
+
})
|
|
285
|
+
return {
|
|
286
|
+
once: (name, call) => {
|
|
287
|
+
try {
|
|
288
|
+
call()
|
|
289
|
+
} catch (defect) {
|
|
290
|
+
report(name, defect)
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
perMove: (name, call) => {
|
|
294
|
+
try {
|
|
295
|
+
call()
|
|
296
|
+
UndefinedOr.map(MutableRef.get(failing), (names) => names.delete(name))
|
|
297
|
+
} catch (defect) {
|
|
298
|
+
const names = failingNow()
|
|
299
|
+
if (names.has(name)) return
|
|
300
|
+
names.add(name)
|
|
301
|
+
report(name, defect)
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** Motion's `amount` as a share of the element: `"some"` any of it, `"all"` all of it; a number as it is. Built once. */
|
|
308
|
+
export const amountOf: (amount: "some" | "all" | number | undefined) => number | undefined = Match.type<"some" | "all" | number | undefined>().pipe(
|
|
309
|
+
Match.when("some", () => 0),
|
|
310
|
+
Match.when("all", () => 1),
|
|
311
|
+
Match.orElse((share) => share),
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
/** Motion's `viewport` as a binding holds it: dom's `WardicViewport`, or Foldkit's with its root resolved into an accessor. */
|
|
315
|
+
export interface ViewportLike {
|
|
316
|
+
readonly once?: boolean | undefined
|
|
317
|
+
readonly margin?: string | undefined
|
|
318
|
+
readonly amount?: "some" | "all" | number | undefined
|
|
319
|
+
readonly root?: (() => Element | undefined) | undefined
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** Motion's `viewport` as core's in-view options (#273): its root read now, when the recognizer starts. */
|
|
323
|
+
export const inViewOptionsOf = (viewport: ViewportLike | undefined): Recognizer.InViewOptions =>
|
|
324
|
+
UndefinedOr.match(viewport, {
|
|
325
|
+
onUndefined: () => ({}),
|
|
326
|
+
onDefined: (v) => ({
|
|
327
|
+
once: v.once,
|
|
328
|
+
margin: v.margin,
|
|
329
|
+
amount: amountOf(v.amount),
|
|
330
|
+
...UndefinedOr.match(v.root, { onUndefined: () => ({}), onDefined: (root) => ({ root: root() }) }),
|
|
331
|
+
}),
|
|
332
|
+
})
|
|
@@ -761,8 +761,8 @@ export const serverAnimate: WardicAnimate = () => finishedControls()
|
|
|
761
761
|
|
|
762
762
|
// --- Sequences (#433's PR 2) ------------------------------------------------------------------
|
|
763
763
|
|
|
764
|
-
/** Whether `
|
|
765
|
-
const isSequence = (given: unknown): given is WardicAnimationSequence =>
|
|
764
|
+
/** Whether `given` is a sequence rather than a subject (#433, Motion's `isSequence`): a list with a Segment, itself a list, in it; a list of elements has none. A binding whose `animate` is its own tells the forms apart by it (#798). */
|
|
765
|
+
export const isSequence = (given: unknown): given is WardicAnimationSequence =>
|
|
766
766
|
Bool.match(Arr.isArray(given), { onTrue: () => Arr.some(given as ReadonlyArray<unknown>, Arr.isArray), onFalse: () => false })
|
|
767
767
|
|
|
768
768
|
/** A function Segment's value (Motion's motion value): its own subject, its callback told each frame. */
|
|
@@ -905,6 +905,21 @@ const stepsOf = (sequence: WardicAnimationSequence, scope: Element | undefined,
|
|
|
905
905
|
})
|
|
906
906
|
}
|
|
907
907
|
|
|
908
|
+
/**
|
|
909
|
+
* Whether a Segment animates anything under `scope` (#798): a function Segment does, and a Batch's; a
|
|
910
|
+
* Segment of elements when its subject finds one, a selector inside `scope`, else the document; a
|
|
911
|
+
* label (a string, or `{ name, at }`) never. What a binding asks of a sequence before it plays it,
|
|
912
|
+
* since one that animates nothing lands at once.
|
|
913
|
+
*/
|
|
914
|
+
export const segmentAnimates = (segment: WardicSegment, scope: Element | undefined): boolean => {
|
|
915
|
+
if (Predicate.isString(segment)) return false
|
|
916
|
+
if (Bool.not(Arr.isArray(segment))) return false
|
|
917
|
+
const parts = segment as ReadonlyArray<unknown>
|
|
918
|
+
if (Predicate.isNotUndefined(BatchMembers.batchSubjectOf(parts[0]))) return true
|
|
919
|
+
if (Predicate.isFunction(parts[0])) return true
|
|
920
|
+
return subjectsOf(parts[0] as WardicAnimationSubject, scope).length > 0
|
|
921
|
+
}
|
|
922
|
+
|
|
908
923
|
/**
|
|
909
924
|
* A function Segment's value animated (#433): its stops, a first `null` 0, through the
|
|
910
925
|
* Interpolators on its tween over the sequence, each frame told to its callback. Cancelled, the
|
|
@@ -995,6 +1010,22 @@ export interface WardicAnimationScope<T extends Element = HTMLElement> {
|
|
|
995
1010
|
readonly animations: ReadonlyArray<WardicPlaybackControls>
|
|
996
1011
|
}
|
|
997
1012
|
|
|
1013
|
+
/** `watch`, with `also` told each start and end after it, when given: a scope's own watch beside its owner's (#433), a binding's beside a scope's (#798). */
|
|
1014
|
+
export const alsoTold = (watch: AnimationWatch, also: AnimationWatch | undefined): AnimationWatch =>
|
|
1015
|
+
UndefinedOr.match(also, {
|
|
1016
|
+
onUndefined: () => watch,
|
|
1017
|
+
onDefined: (more) => ({
|
|
1018
|
+
started: (controls) => {
|
|
1019
|
+
watch.started(controls)
|
|
1020
|
+
more.started(controls)
|
|
1021
|
+
},
|
|
1022
|
+
ended: (controls, landed) => {
|
|
1023
|
+
watch.ended(controls, landed)
|
|
1024
|
+
more.ended(controls, landed)
|
|
1025
|
+
},
|
|
1026
|
+
}),
|
|
1027
|
+
})
|
|
1028
|
+
|
|
998
1029
|
/**
|
|
999
1030
|
* An Animation scope's ref and what it hears of its animations (#433): each in `animations` while in
|
|
1000
1031
|
* flight, and `also` told too (Solid 2's `settled()`). `stopAll` stops them, at its owner's cleanup.
|
|
@@ -1020,18 +1051,19 @@ export const scopeOf = <T extends Element>(also?: AnimationWatch): {
|
|
|
1020
1051
|
current: { get: () => current },
|
|
1021
1052
|
animations: { get: animationsNow },
|
|
1022
1053
|
}) as WardicAnimationScope<T>
|
|
1023
|
-
const watch
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1054
|
+
const watch = alsoTold(
|
|
1055
|
+
{
|
|
1056
|
+
started: (controls) => {
|
|
1057
|
+
live.add(controls)
|
|
1058
|
+
listed = undefined
|
|
1059
|
+
},
|
|
1060
|
+
ended: (controls) => {
|
|
1061
|
+
live.delete(controls)
|
|
1062
|
+
listed = undefined
|
|
1063
|
+
},
|
|
1028
1064
|
},
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
listed = undefined
|
|
1032
|
-
UndefinedOr.map(also, (more) => more.ended(controls, landed))
|
|
1033
|
-
},
|
|
1034
|
-
}
|
|
1065
|
+
also,
|
|
1066
|
+
)
|
|
1035
1067
|
// Stopping one ends it, which deletes it from the set: safe in the set's own walk.
|
|
1036
1068
|
return { scope, watch, stopAll: () => Iter.forEach(live, (controls) => controls.stop()) }
|
|
1037
1069
|
}
|