@wardic/core 1.0.1 → 1.1.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 (147) hide show
  1. package/dist/Batch.d.ts +4 -2
  2. package/dist/Batch.d.ts.map +1 -1
  3. package/dist/Batch.js +80 -13
  4. package/dist/Batch.js.map +1 -1
  5. package/dist/DefaultTransition.d.ts.map +1 -1
  6. package/dist/DefaultTransition.js +1 -1
  7. package/dist/DefaultTransition.js.map +1 -1
  8. package/dist/LiveValue.d.ts +61 -0
  9. package/dist/LiveValue.d.ts.map +1 -1
  10. package/dist/LiveValue.js +79 -5
  11. package/dist/LiveValue.js.map +1 -1
  12. package/dist/Machine.d.ts +10 -1
  13. package/dist/Machine.d.ts.map +1 -1
  14. package/dist/Machine.js +18 -1
  15. package/dist/Machine.js.map +1 -1
  16. package/dist/Renderer.js +2 -2
  17. package/dist/Renderer.js.map +1 -1
  18. package/dist/Spans.d.ts +41 -0
  19. package/dist/Spans.d.ts.map +1 -0
  20. package/dist/Spans.js +39 -0
  21. package/dist/Spans.js.map +1 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +1 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/internal/frameLoop.d.ts +1 -1
  27. package/dist/internal/frameLoop.d.ts.map +1 -1
  28. package/dist/internal/frameLoop.js +42 -19
  29. package/dist/internal/frameLoop.js.map +1 -1
  30. package/dist/internal/options.d.ts.map +1 -1
  31. package/dist/internal/options.js +2 -2
  32. package/dist/internal/options.js.map +1 -1
  33. package/dist/internal/tracing.d.ts +34 -14
  34. package/dist/internal/tracing.d.ts.map +1 -1
  35. package/dist/internal/tracing.js +56 -24
  36. package/dist/internal/tracing.js.map +1 -1
  37. package/dist/unstable/AnimationControls.d.ts +110 -0
  38. package/dist/unstable/AnimationControls.d.ts.map +1 -0
  39. package/dist/unstable/AnimationControls.js +107 -0
  40. package/dist/unstable/AnimationControls.js.map +1 -0
  41. package/dist/unstable/AppearHandoff.d.ts +53 -0
  42. package/dist/unstable/AppearHandoff.d.ts.map +1 -0
  43. package/dist/unstable/AppearHandoff.js +23 -0
  44. package/dist/unstable/AppearHandoff.js.map +1 -0
  45. package/dist/unstable/Config.d.ts +285 -0
  46. package/dist/unstable/Config.d.ts.map +1 -0
  47. package/dist/unstable/Config.js +3 -0
  48. package/dist/unstable/Config.js.map +1 -0
  49. package/dist/unstable/FlushGate.d.ts +222 -0
  50. package/dist/unstable/FlushGate.d.ts.map +1 -0
  51. package/dist/unstable/FlushGate.js +567 -0
  52. package/dist/unstable/FlushGate.js.map +1 -0
  53. package/dist/unstable/FrameTime.d.ts +21 -0
  54. package/dist/unstable/FrameTime.d.ts.map +1 -0
  55. package/dist/unstable/FrameTime.js +45 -0
  56. package/dist/unstable/FrameTime.js.map +1 -0
  57. package/dist/unstable/MeasuredPairs.d.ts +51 -0
  58. package/dist/unstable/MeasuredPairs.d.ts.map +1 -0
  59. package/dist/unstable/MeasuredPairs.js +20 -0
  60. package/dist/unstable/MeasuredPairs.js.map +1 -0
  61. package/dist/unstable/OwnValues.d.ts +29 -0
  62. package/dist/unstable/OwnValues.d.ts.map +1 -0
  63. package/dist/unstable/OwnValues.js +22 -0
  64. package/dist/unstable/OwnValues.js.map +1 -0
  65. package/dist/unstable/PresenceRecord.d.ts +176 -0
  66. package/dist/unstable/PresenceRecord.d.ts.map +1 -0
  67. package/dist/unstable/PresenceRecord.js +26 -0
  68. package/dist/unstable/PresenceRecord.js.map +1 -0
  69. package/dist/unstable/Reactivity.d.ts +29 -0
  70. package/dist/unstable/Reactivity.d.ts.map +1 -0
  71. package/dist/unstable/Reactivity.js +15 -0
  72. package/dist/unstable/Reactivity.js.map +1 -0
  73. package/dist/unstable/Report.d.ts +30 -0
  74. package/dist/unstable/Report.d.ts.map +1 -0
  75. package/dist/unstable/Report.js +66 -0
  76. package/dist/unstable/Report.js.map +1 -0
  77. package/dist/unstable/RetargetLegs.d.ts +189 -0
  78. package/dist/unstable/RetargetLegs.d.ts.map +1 -0
  79. package/dist/unstable/RetargetLegs.js +834 -0
  80. package/dist/unstable/RetargetLegs.js.map +1 -0
  81. package/dist/unstable/Spine.d.ts +696 -0
  82. package/dist/unstable/Spine.d.ts.map +1 -0
  83. package/dist/unstable/Spine.js +2617 -0
  84. package/dist/unstable/Spine.js.map +1 -0
  85. package/dist/unstable/Stops.d.ts +82 -0
  86. package/dist/unstable/Stops.d.ts.map +1 -0
  87. package/dist/unstable/Stops.js +149 -0
  88. package/dist/unstable/Stops.js.map +1 -0
  89. package/dist/unstable/Subject.d.ts +11 -0
  90. package/dist/unstable/Subject.d.ts.map +1 -0
  91. package/dist/unstable/Subject.js +12 -0
  92. package/dist/unstable/Subject.js.map +1 -0
  93. package/dist/unstable/Timelines.d.ts +51 -0
  94. package/dist/unstable/Timelines.d.ts.map +1 -0
  95. package/dist/unstable/Timelines.js +10 -0
  96. package/dist/unstable/Timelines.js.map +1 -0
  97. package/dist/unstable/VariableValues.d.ts +27 -0
  98. package/dist/unstable/VariableValues.d.ts.map +1 -0
  99. package/dist/unstable/VariableValues.js +19 -0
  100. package/dist/unstable/VariableValues.js.map +1 -0
  101. package/dist/unstable/VariantTarget.d.ts +106 -0
  102. package/dist/unstable/VariantTarget.d.ts.map +1 -0
  103. package/dist/unstable/VariantTarget.js +185 -0
  104. package/dist/unstable/VariantTarget.js.map +1 -0
  105. package/dist/unstable/VariantTree.d.ts +351 -0
  106. package/dist/unstable/VariantTree.d.ts.map +1 -0
  107. package/dist/unstable/VariantTree.js +362 -0
  108. package/dist/unstable/VariantTree.js.map +1 -0
  109. package/dist/unstable/WardicConfigValue.d.ts +89 -0
  110. package/dist/unstable/WardicConfigValue.d.ts.map +1 -0
  111. package/dist/unstable/WardicConfigValue.js +106 -0
  112. package/dist/unstable/WardicConfigValue.js.map +1 -0
  113. package/dist/unstable/WardicServices.d.ts +46 -0
  114. package/dist/unstable/WardicServices.d.ts.map +1 -0
  115. package/dist/unstable/WardicServices.js +72 -0
  116. package/dist/unstable/WardicServices.js.map +1 -0
  117. package/package.json +1 -1
  118. package/src/Batch.ts +68 -12
  119. package/src/DefaultTransition.ts +1 -1
  120. package/src/LiveValue.ts +129 -5
  121. package/src/Machine.ts +22 -1
  122. package/src/Renderer.ts +2 -2
  123. package/src/Spans.ts +50 -0
  124. package/src/index.ts +1 -0
  125. package/src/internal/frameLoop.ts +44 -20
  126. package/src/internal/options.ts +2 -2
  127. package/src/internal/tracing.ts +82 -28
  128. package/src/unstable/AnimationControls.ts +199 -0
  129. package/src/unstable/AppearHandoff.ts +81 -0
  130. package/src/unstable/Config.ts +326 -0
  131. package/src/unstable/FlushGate.ts +730 -0
  132. package/src/unstable/FrameTime.ts +52 -0
  133. package/src/unstable/MeasuredPairs.ts +56 -0
  134. package/src/unstable/OwnValues.ts +32 -0
  135. package/src/unstable/PresenceRecord.ts +201 -0
  136. package/src/unstable/Reactivity.ts +35 -0
  137. package/src/unstable/Report.ts +75 -0
  138. package/src/unstable/RetargetLegs.ts +1062 -0
  139. package/src/unstable/Spine.ts +3275 -0
  140. package/src/unstable/Stops.ts +221 -0
  141. package/src/unstable/Subject.ts +13 -0
  142. package/src/unstable/Timelines.ts +58 -0
  143. package/src/unstable/VariableValues.ts +27 -0
  144. package/src/unstable/VariantTarget.ts +246 -0
  145. package/src/unstable/VariantTree.ts +643 -0
  146. package/src/unstable/WardicConfigValue.ts +154 -0
  147. package/src/unstable/WardicServices.ts +125 -0
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The time a key's velocity is read against (#464, Motion's `sync-time.ts`): its provider's Clock's
3
+ * `now` (#460, Q7), read once per synchronous block and kept until a microtask clears it, so every
4
+ * sink a tick runs, and a Retarget in the same task, read one time: an Environment's own (`@wardic/dom`'s
5
+ * reads its runtime's clock; a test Environment's advances as its test says).
6
+ *
7
+ * Unstable, for Wardic's own packages: public, with no semver promise.
8
+ *
9
+ * @module
10
+ */
11
+ // Unstable: ADR-0071, decision 5. #672: solid's `frame-time.ts`, moved for the spine to read its
12
+ // Clock's time in core; its WeakMap keyed by the Runner since PR 1 (the move plan's *Built in PR 1*).
13
+ import * as Clock from "../Clock.ts"
14
+ import * as Effect from "effect/Effect"
15
+ import * as Predicate from "effect/Predicate"
16
+ import type * as WardicServices from "./WardicServices.ts"
17
+
18
+ /**
19
+ * How long a key's velocity holds once nothing has moved it, in ms (Motion's `MAX_VELOCITY_DELTA`):
20
+ * past it, the key is at rest. A velocity worked out from two frames further apart takes this as their
21
+ * time apart.
22
+ */
23
+ export const MAX_VELOCITY_DELTA = 30
24
+
25
+ /** A frame at 60 Hz, in ms: the time a leg's first frame is read over, from where it started (Motion's first-frame delta). */
26
+ export const NOMINAL_FRAME = 1000 / 60
27
+
28
+ // #672: declared here, as core's `Clock.ts` declares it, since core builds with no DOM in its lib.
29
+ declare const performance: { readonly now: () => number }
30
+
31
+ /**
32
+ * The time now, in ms: the same for the rest of this synchronous block (core's `Clock.syncNow`).
33
+ * Per frame: a check, and a read once a tick. A Snapshot's time until its spine gives it its
34
+ * provider's ({@link clockNowOf}).
35
+ */
36
+ export const frameNow: () => number = Clock.syncNow(() => performance.now())
37
+
38
+ /** Each runtime's Clock's `now`, read once. */
39
+ // Module state (#460, Q7): each runtime's clock, held weakly by the runtime.
40
+ const clockNows = new WeakMap<WardicServices.Runner<WardicServices.WardicServices>, () => number>()
41
+
42
+ /**
43
+ * The time a provider's elements read their velocities against (#460, Q7): its Environment's Clock's
44
+ * `now` (#464's sync time, `@wardic/dom`'s or a test Environment's own), kept per runtime.
45
+ */
46
+ export const clockNowOf = (runtime: WardicServices.Runner<WardicServices.WardicServices>): (() => number) => {
47
+ const kept = clockNows.get(runtime)
48
+ if (Predicate.isNotUndefined(kept)) return kept
49
+ const read = runtime.runSync(Clock.Clock.use((clock) => Effect.succeed(clock.now)))
50
+ clockNows.set(runtime, read)
51
+ return read
52
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * How an Environment measures a key whose two ends are in units its interpolators can't blend
3
+ * (**Measured pair**): whether a pair needs it, and its measure, whose result each pair reads once
4
+ * it's done. One of the Environment's optional members. An Environment other than `@wardic/dom`'s gives
5
+ * one (`@wardic/test`'s `TestLive` a headless one); a binding on `@wardic/dom` falls back to
6
+ * `@wardic/dom/unstable/DomValues`' when its Environment gives none, so an app that never reads it
7
+ * ships none of that code.
8
+ *
9
+ * Unstable, for Wardic's own packages: public, with no semver promise.
10
+ *
11
+ * @module
12
+ */
13
+ // Unstable: ADR-0071, decision 5. #672 (PR2-Q1, PR2-Q2; ADR-0071's *Amendment (#672)*): a port, so the
14
+ // spine reads its Environment's measures through it, not through dom. A pair carries the read of its
15
+ // result, so the legs that run it need no port of their own.
16
+ import * as Context from "effect/Context"
17
+ import type * as Option from "effect/Option"
18
+ import type * as Values from "../Values.ts"
19
+
20
+ /** A key's pair: its two ends, as given. */
21
+ export interface Pair {
22
+ readonly key: string
23
+ /** Its start, as given. */
24
+ readonly from: number | string
25
+ /** Its target, as given. */
26
+ readonly to: number | string
27
+ }
28
+
29
+ /** A pair asked to be measured, which reads its result once it's done. */
30
+ export interface Requested extends Pair {
31
+ /** Its ends in px, once measured; none before, or when they couldn't be read. */
32
+ readonly measured: () => Option.Option<Measured>
33
+ }
34
+
35
+ /** A pair, measured. */
36
+ export interface Measured extends Pair {
37
+ /** Its start in px. */
38
+ readonly fromPx: number
39
+ /** Its target in px. */
40
+ readonly toPx: number
41
+ }
42
+
43
+ /** An Environment's measures of its Subjects' pairs. */
44
+ export interface Shape {
45
+ /** Whether `key` from `from` to `to` needs its pair measured: its ends in units that don't blend. */
46
+ readonly needs: (key: string, from: number | string, to: number | string) => boolean
47
+ /** Asks `pairs` measured on `subject`, at `values`: each key's pair, whose result it reads once it's done. */
48
+ readonly measure: (
49
+ subject: object,
50
+ pairs: Readonly<Record<string, { readonly from: number | string; readonly to: number | string }>>,
51
+ values: Values.Values,
52
+ ) => Readonly<Record<string, Requested>>
53
+ }
54
+
55
+ /** The Environment's member that measures its Subjects' pairs. */
56
+ export class MeasuredPairs extends /*#__PURE__*/ Context.Service<MeasuredPairs, Shape>()("@wardic/core/unstable/MeasuredPairs") {}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * How an Environment reads a Subject's own values (**Own value**): a raw value in the shape of a
3
+ * target, a key's value in the style a binding was given for its Subject, and that style as a record.
4
+ * One of the Environment's optional members. An Environment other than `@wardic/dom`'s gives
5
+ * one (`@wardic/test`'s `TestLive` a headless one); a binding on `@wardic/dom` falls back to
6
+ * `@wardic/dom/unstable/DomValues`' when its Environment gives none, so an app that never reads it
7
+ * ships none of that code.
8
+ *
9
+ * Unstable, for Wardic's own packages: public, with no semver promise.
10
+ *
11
+ * @module
12
+ */
13
+ // Unstable: ADR-0071, decision 5. #672 (PR2-Q1, PR2-Q2; ADR-0071's *Amendment (#672)*): a port, so the
14
+ // spine and `live-style` read their Environment's values through it, not through dom. A provider
15
+ // resolves it once into its record when its Environment gives one, else its DOM binding gives the
16
+ // DOM's (PR2-Q4: so `DomLive` ships none of it to an app that never reads it); each element's spine gets it in its options. Each member is a plain
17
+ // function: `valueLike` runs on a Follow leg's every step.
18
+ import * as Context from "effect/Context"
19
+ import type * as Option from "effect/Option"
20
+
21
+ /** An Environment's reads of its Subjects' own values. */
22
+ export interface Shape {
23
+ /** `raw` in the shape of `like`: a number for a number, a string with `like`'s unit for a string; none when it can't be read so. */
24
+ readonly valueLike: (raw: unknown, like: number | string) => Option.Option<number | string>
25
+ /** `key`'s value in `style`, the style a binding was given for its Subject: an object, or the Environment's text form. */
26
+ readonly styleValueOf: (style: object | string | undefined, key: string) => Option.Option<unknown>
27
+ /** `style` as a record: an object as it is, the Environment's text form read into one, none as an empty one. */
28
+ readonly recordOf: (style: object | string | undefined) => Readonly<Record<string, unknown>>
29
+ }
30
+
31
+ /** The Environment's member that reads its Subjects' own values. */
32
+ export class OwnValues extends /*#__PURE__*/ Context.Service<OwnValues, Shape>()("@wardic/core/unstable/OwnValues") {}
@@ -0,0 +1,201 @@
1
+ /**
2
+ * What a Ward and its presence share (ADR-0007): the record a child registers, and the presence's
3
+ * context value, over the Subjects its Environment draws. Every binding's spine writes the same record.
4
+ *
5
+ * Unstable, for Wardic's own packages: public, with no semver promise.
6
+ *
7
+ * @module
8
+ */
9
+ // Unstable: ADR-0071, decision 5. #672: solid's presence protocol, moved for the spine to share from
10
+ // core (#209: it was Solid-free already); solid's `presence-record.ts` names it over Element.
11
+ import type * as Box from "../Box.ts"
12
+ import type * as Values from "../Values.ts"
13
+ import type * as Subject from "./Subject.ts"
14
+ import type * as Stops from "./Stops.ts"
15
+ import type * as Config from "./Config.ts"
16
+ import { constFalse } from "effect/Function"
17
+ import * as Predicate from "effect/Predicate"
18
+ import * as UndefinedOr from "effect/UndefinedOr"
19
+
20
+ /**
21
+ * A child's live presence registration. `snapshot` / `exit` are MUTABLE ref
22
+ * cells (`{ current }`) the child's spine writes to while alive; they outlive
23
+ * the child's owner so the parent-driven exit reads them after the child leaves.
24
+ */
25
+ export interface PresenceRecord<E extends Subject.Subject = Subject.Subject> {
26
+ /** The child's root Subject (the same `el` the spine wires). */
27
+ readonly element: E
28
+ /** The latest emitted value-map, updated by the spine each frame. */
29
+ readonly snapshot: { current: Values.Values }
30
+ /**
31
+ * The exit, resolved as the child leaves: its target, a variant name or a dynamic variant
32
+ * resolved with `custom` (the presence's, when it has one, else the child's last), and the
33
+ * transition it runs on. The child keeps what it's resolved from current while alive.
34
+ */
35
+ readonly exitOf: (custom: unknown, inherited: Config.WardicVariantLabels | undefined) => PresenceExit
36
+ /**
37
+ * Where it sits in the variant tree, decided at setup as the tree is: whether it joins the
38
+ * nearest element that provides a context (a **Variant child**, which then exits on that one's
39
+ * exit name, in its stagger), whether its own Variant children join it, and whether it's a twin
40
+ * (a `layoutId`, whose crossfade replaces its exit). Left out: none of them.
41
+ */
42
+ readonly tree?: PresenceTree
43
+ /**
44
+ * Where an exit key with no value in `snapshot` starts: its value as the element was given it (in
45
+ * `@wardic/dom`, its `style`), else its Own value, read from the Subject kept at the exit, in the
46
+ * shape of `like` (the key's exit target). `undefined` starts it at its target. Optional: a record
47
+ * without it starts such a key at its target.
48
+ */
49
+ readonly startOf?: ((key: string, like: number | string) => number | string | undefined) | undefined
50
+ /**
51
+ * Its velocities now, each numeric key's: what a child back under its key starts with, when
52
+ * this one is taken over without an exit running. Optional: left out, 0.
53
+ */
54
+ readonly velocities?: (() => Readonly<Record<string, number>>) | undefined
55
+ /**
56
+ * Whether reduced motion applies to it now: its nearest `WardicConfig`'s, else the
57
+ * provider's, read as its exit starts. Optional: left out, the presence's.
58
+ */
59
+ readonly reducedMotion?: (() => boolean) | undefined
60
+ /**
61
+ * Whether its animations are skipped now: its nearest `WardicConfig`'s, read as its exit
62
+ * starts. Optional: left out, never.
63
+ */
64
+ readonly skipAnimations?: (() => boolean) | undefined
65
+ }
66
+
67
+ /** Where a Wardic element starts when its child takes over from a leaver (#286, ADR-0048): the values and velocities it's drawn at. */
68
+ export interface PresenceSeed {
69
+ readonly values: Values.Values
70
+ readonly velocities: Readonly<Record<string, number>>
71
+ /** Where the element it takes over from painted, in the Root frame: a layout node moves from there. */
72
+ readonly box?: Box.Box | undefined
73
+ /** The crossfade factor a twin it takes over from had faded out to: its handover's fade goes on from there. */
74
+ readonly fade?: number | undefined
75
+ }
76
+
77
+ /**
78
+ * A child's exit, resolved as it leaves (#277): its values, and the transition it runs on, whose
79
+ * orchestration its Variant children's exits take.
80
+ */
81
+ export interface PresenceExit {
82
+ readonly values: Values.Values
83
+ readonly transition: Config.WardicTransition | undefined
84
+ /** The exit name it hands its Variant children (#290): its own `exit`, if a name or a list (#297), else the one it took. */
85
+ readonly name: Config.WardicVariantLabels | undefined
86
+ /**
87
+ * A list's exit by name (#297): each name's keys (those it's the last to set) on its own transition,
88
+ * else the element's, and its orchestration for its Variant children's keys of that name. Every
89
+ * name has one, keys or none. Left out for a single name or a values map: the whole exit is one.
90
+ */
91
+ readonly groups?: ReadonlyArray<ExitGroup> | undefined
92
+ /** Its Keyframes (#429): each such key's stops, its value in `values` their last. Left out with none. */
93
+ readonly keyframes?: Readonly<Record<string, Stops.Stops>> | undefined
94
+ }
95
+
96
+ /** One name of a list's exit (#297): its keys, and the transition they and its orchestration run on. */
97
+ export interface ExitGroup {
98
+ readonly name: string
99
+ readonly values: Values.Values
100
+ readonly transition: Config.WardicTransition | undefined
101
+ }
102
+
103
+ /** A record's place in the variant tree (#290, {@link PresenceRecord.tree}). */
104
+ export interface PresenceTree {
105
+ readonly joins: boolean
106
+ readonly provides: boolean
107
+ readonly twin: boolean
108
+ }
109
+
110
+ /** The value a presence publishes to the spines below it. */
111
+ export interface PresenceContextValue<E extends Subject.Subject = Subject.Subject> {
112
+ /**
113
+ * Register a child's live record. Returns a disposer the registrant MAY call,
114
+ * but the child does NOT call it on its own cleanup — the presence
115
+ * removes the registration after the exit completes.
116
+ */
117
+ readonly register: (rec: PresenceRecord<E>) => () => void
118
+ /**
119
+ * Whether an element setting up now starts at its `animate`, with nothing animating at mount:
120
+ * `<AnimatePresence initial={false}>`, during its first render (Motion's
121
+ * `presenceContext.initial`). A child that enters later animates in. Optional: left out, never.
122
+ */
123
+ readonly blocksInitial?: () => boolean
124
+ /**
125
+ * Whether an element setting up now is inside a child `mode="wait"` holds back: `undefined`
126
+ * when it isn't, and it starts now. Else `start` is called once the child is shown, and the
127
+ * call returned cancels that (the element gone first). Optional: left out, never.
128
+ */
129
+ readonly hold?: (el: E, start: () => void) => (() => void) | undefined
130
+ /**
131
+ * A presence hook's registration: `usePresence`'s and `useIsPresent`'s.
132
+ * Optional: left out, nothing is watched.
133
+ */
134
+ readonly watch?: (watch: PresenceWatch<E>) => void
135
+ /** The presence's `custom`, reactive: `usePresenceData`'s. Left out, `undefined`. */
136
+ readonly data?: () => unknown
137
+ /**
138
+ * A Wardic element made: its `key` and whether it's a twin, told as its element is
139
+ * made, before the presence decides what it shows (so `mode="wait"` doesn't hold a child
140
+ * back under its key), and before any of its child's wards mount (so the elements inside pair).
141
+ * Optional: left out, no child is keyed.
142
+ */
143
+ readonly made?: (el: E, key: string | number | undefined, twin: boolean) => void
144
+ /**
145
+ * Where an element mounting now starts, when its child takes over from a leaver: asked once,
146
+ * before its first Retarget. `undefined`: as it would. Optional: left out, never.
147
+ */
148
+ readonly takeOverOf?: (el: E) => PresenceSeed | undefined
149
+ }
150
+
151
+ /** Tell `presence` a Wardic element was made ({@link PresenceContextValue.made}): nothing without one. */
152
+ export const presenceMade = <E extends Subject.Subject>(presence: PresenceContextValue<E> | undefined, el: E, key: string | number | undefined, twin: boolean): void => {
153
+ if (Predicate.isUndefined(presence)) return
154
+ UndefinedOr.map(presence.made, (tell) => tell(el, key, twin))
155
+ }
156
+
157
+ /** Where `el` starts as it mounts, taking over from a leaver ({@link PresenceContextValue.takeOverOf}): `undefined` as it would. */
158
+ export const presenceSeedOf = <E extends Subject.Subject>(presence: PresenceContextValue<E> | undefined, el: E): PresenceSeed | undefined => {
159
+ if (Predicate.isUndefined(presence)) return undefined
160
+ return UndefinedOr.map(presence.takeOverOf, (of) => of(el))
161
+ }
162
+
163
+ /**
164
+ * What a presence hook registers (#277's PR 5b, ADR-0048): its element, whose leaving child it
165
+ * belongs to, and what it's told. Kept until that child goes, the presence goes, or its element
166
+ * goes some other way.
167
+ */
168
+ export interface PresenceWatch<E extends Subject.Subject = Subject.Subject> {
169
+ /** Its element, once it has one: the child that holds it is the one it belongs to. */
170
+ readonly element: () => E | undefined
171
+ /** Whether it holds its child as it leaves, until `release` is called (`usePresence`). */
172
+ readonly holds: boolean
173
+ /**
174
+ * Its child left: called once, with the node back in place (or popped, `mode="popLayout"`), with
175
+ * the presence's `custom`, and `release`, which lets the child go once it holds it. `release(false)`
176
+ * cuts the child's exit short: it goes at once, uncompleted, as a child taken over does (#286).
177
+ */
178
+ readonly leave: (custom: unknown, release: (completed?: boolean) => void) => void
179
+ /** Its child went some other way, or the presence did: it's dropped, with no leave. */
180
+ readonly gone: () => void
181
+ /**
182
+ * Its child's exit, once it was told it left, was cut short: the child is gone, uncompleted (a
183
+ * take-over, the presence going). Optional: left out, it isn't told.
184
+ */
185
+ // #665, Q46: a keyed Batch's member mid-exit stops waiting on it.
186
+ readonly interrupted?: () => void
187
+ }
188
+
189
+ /** Whether `presence` holds an element setting up now at its `animate` ({@link PresenceContextValue.blocksInitial}). */
190
+ export const presenceBlocksInitial = <E extends Subject.Subject>(presence: PresenceContextValue<E> | undefined): boolean =>
191
+ UndefinedOr.match(presence, {
192
+ onUndefined: constFalse,
193
+ onDefined: (p) => UndefinedOr.match(p.blocksInitial, { onUndefined: constFalse, onDefined: (blocks) => blocks() }),
194
+ })
195
+
196
+ /**
197
+ * Whether `el` waits for its child to be shown ({@link PresenceContextValue.hold}): the call
198
+ * that cancels `start`, or `undefined` when it starts now.
199
+ */
200
+ export const presenceHold = <E extends Subject.Subject>(presence: PresenceContextValue<E> | undefined, el: E, start: () => void): (() => void) | undefined =>
201
+ UndefinedOr.map(presence, (p) => UndefinedOr.map(p.hold, (hold) => hold(el, start)))
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The few reactive primitives the binding-free modules take from a binding (#209): each binding gives
3
+ * its own, over its framework's graph or, with none, over the latest config it received. A module that
4
+ * takes one never imports a framework, so every binding runs the same code.
5
+ *
6
+ * Unstable, for Wardic's own packages: public, with no semver promise.
7
+ *
8
+ * @module
9
+ */
10
+ // Unstable: ADR-0071, decision 5. #672: solid's `reactivity.ts`, moved for the spine and its
11
+ // neighbours to take from core. Solid 1's and Solid 2's implementations stay in solid
12
+ // (`solid-reactivity.ts`, `unstable/v2/solid-reactivity.ts`); Foldkit's is getters over the latest
13
+ // delivery, with watches re-checked once a patch (ADR-0071, decision 17).
14
+
15
+ /** A value read through a function: a signal, a memo, a getter. */
16
+ export type Accessor<A> = () => A
17
+
18
+ /** A change notice: the computation that calls `track` re-runs on each `notify`. */
19
+ export interface Trigger {
20
+ readonly track: () => void
21
+ readonly notify: () => void
22
+ }
23
+
24
+ /** A binding's reactive primitives, as the binding-free modules use them. */
25
+ export interface Reactivity {
26
+ /** Runs `fn` without tracking what it reads. */
27
+ readonly untrack: <A>(fn: () => A) => A
28
+ /** A {@link Trigger}, made under the current owner. Its `notify` may be called from anywhere. */
29
+ readonly trigger: () => Trigger
30
+ /**
31
+ * Calls `onChange` with each later value of `accessor`, not its first, until the returned stop.
32
+ * In a root of its own, which no owner disposes.
33
+ */
34
+ readonly watch: <A>(accessor: Accessor<A>, onChange: (value: A) => void) => () => void
35
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Where a binding's failure stops: `failure` logs it at Error and reports it to the Environment's
3
+ * `ErrorReporter`s. Core's engine doesn't report: the Frame loop hands each run's failure to its
4
+ * caller, and a Tier 2 caller may recover. A binding boundary that ends a fiber nobody observes calls
5
+ * this, so a failure there reaches the console and an app's reporters instead of stopping its feature
6
+ * with nothing said.
7
+ *
8
+ * An app installs its reporters on the Environment it hands the provider,
9
+ * `ErrorReporter.layer([…])` merged into `env`; Wardic ships none. With none installed, a report
10
+ * is one `getRef` and a size check, on the failure path only. A reporter built with
11
+ * `ErrorReporter.make` dedupes a cause and its original error, so a failure that crosses two
12
+ * boundaries reports once: pass the cause on as it came, never wrapped.
13
+ *
14
+ * Unstable, for Wardic's own packages: public, with no semver promise. Binding authors import
15
+ * `@wardic/dom/Report`, which re-exports it.
16
+ *
17
+ * @module
18
+ */
19
+ // ADR-0030, decision 4 (the Frame loop's hand-off: ADR-0027, decision 7). Unstable: ADR-0071,
20
+ // decision 5. #672 (ADR-0030, *Amendment (#672)*): moved from dom's `internal/report.ts`, so the spine
21
+ // reports from core once it's lifted there.
22
+ import * as Bool from "effect/Boolean"
23
+ import * as Cause from "effect/Cause"
24
+ import * as Effect from "effect/Effect"
25
+ import * as ErrorReporter from "effect/ErrorReporter"
26
+ import * as LogLevel from "effect/LogLevel"
27
+ import * as Predicate from "effect/Predicate"
28
+ import * as References from "effect/References"
29
+
30
+ /**
31
+ * `cause` logged at Error as `message`, with the cause, and handed to the Environment's
32
+ * `ErrorReporter`s. An interruption is neither: it's how a run is removed, by a retarget, an unmount or a
33
+ * dispose. Annotate the log by piping `Effect.annotateLogs` onto it.
34
+ */
35
+ export const failure = (message: string, cause: Cause.Cause<unknown>): Effect.Effect<void> =>
36
+ Bool.match(Cause.hasInterruptsOnly(cause), {
37
+ onTrue: () => Effect.void,
38
+ onFalse: () => Effect.logError(message, cause).pipe(Effect.andThen(ErrorReporter.report(cause))),
39
+ })
40
+
41
+ /**
42
+ * Whether a Debug log would be kept, as Effect's `MinimumLogLevel` says. Run it once (a runtime, a
43
+ * build) and keep the answer, not once a log.
44
+ */
45
+ // #618: the spine reads it alone, so an app that logs nothing else doesn't ship debugOf's log.
46
+ export const debugKept: Effect.Effect<boolean> = /*#__PURE__*/ Effect.map(References.MinimumLogLevel, (level) => Bool.not(LogLevel.isGreaterThan(level, "Debug")))
47
+
48
+ /**
49
+ * A lifecycle debug log for `scope` (`wardic.projection`, say): `log(event, annotations?)` logs
50
+ * `scope: event` at Debug, forked on `runner`, with the annotations. Whether a Debug log would be kept
51
+ * is read once, here ({@link debugKept}): when it wouldn't, `on` is `false` and `log` returns at once,
52
+ * forking nothing. A site that builds its annotations per element checks `on` first.
53
+ */
54
+ // #618 (M4): each call forked a fiber whatever the level, 0.3-0.5 µs to log nothing (one per layout
55
+ // node's mount and unmount); core's Frame loop reads the level once as this does (frameLoop.ts).
56
+ export const debugOf = (runner: { readonly runSync: <A>(effect: Effect.Effect<A>) => A; readonly runFork: <A>(effect: Effect.Effect<A>) => unknown }, scope: string): DebugLog => {
57
+ const on = runner.runSync(debugKept)
58
+ const log = (event: string, annotations?: Record<string, unknown>): void => {
59
+ if (!on) return
60
+ const logged = Effect.logDebug(`${scope}: ${event}`)
61
+ if (Predicate.isUndefined(annotations)) {
62
+ runner.runFork(logged)
63
+ return
64
+ }
65
+ runner.runFork(Effect.annotateLogs(logged, annotations))
66
+ }
67
+ return Object.assign(log, { on })
68
+ }
69
+
70
+ /** {@link debugOf}'s log: called with an event and its annotations, and `on` when a Debug log is kept. */
71
+ export interface DebugLog {
72
+ (event: string, annotations?: Record<string, unknown>): void
73
+ /** Whether a Debug log would be kept: when it's `false`, a call logs nothing. */
74
+ readonly on: boolean
75
+ }