@wardic/dom 1.3.1 → 1.3.2

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 (132) hide show
  1. package/dist/MeasuredPair.d.ts +14 -1
  2. package/dist/MeasuredPair.d.ts.map +1 -1
  3. package/dist/MeasuredPair.js +11 -13
  4. package/dist/MeasuredPair.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/internal/appear.d.ts +6 -0
  10. package/dist/internal/appear.d.ts.map +1 -1
  11. package/dist/internal/appear.js +20 -2
  12. package/dist/internal/appear.js.map +1 -1
  13. package/dist/internal/batch-handoff.d.ts.map +1 -1
  14. package/dist/internal/batch-handoff.js +25 -15
  15. package/dist/internal/batch-handoff.js.map +1 -1
  16. package/dist/internal/batch-writer.d.ts +1 -1
  17. package/dist/internal/batch-writer.d.ts.map +1 -1
  18. package/dist/internal/batch-writer.js +26 -6
  19. package/dist/internal/batch-writer.js.map +1 -1
  20. package/dist/internal/clock.d.ts +6 -0
  21. package/dist/internal/clock.d.ts.map +1 -1
  22. package/dist/internal/clock.js +9 -0
  23. package/dist/internal/clock.js.map +1 -1
  24. package/dist/internal/default-transition.d.ts +3 -2
  25. package/dist/internal/default-transition.d.ts.map +1 -1
  26. package/dist/internal/default-transition.js +14 -3
  27. package/dist/internal/default-transition.js.map +1 -1
  28. package/dist/internal/failing.d.ts +9 -0
  29. package/dist/internal/failing.d.ts.map +1 -0
  30. package/dist/internal/failing.js +33 -0
  31. package/dist/internal/failing.js.map +1 -0
  32. package/dist/internal/length-keys.d.ts +19 -0
  33. package/dist/internal/length-keys.d.ts.map +1 -0
  34. package/dist/internal/length-keys.js +77 -0
  35. package/dist/internal/length-keys.js.map +1 -0
  36. package/dist/internal/measured-pairs.d.ts +3 -2
  37. package/dist/internal/measured-pairs.d.ts.map +1 -1
  38. package/dist/internal/measured-pairs.js +60 -23
  39. package/dist/internal/measured-pairs.js.map +1 -1
  40. package/dist/internal/own-values.d.ts.map +1 -1
  41. package/dist/internal/own-values.js +2 -2
  42. package/dist/internal/own-values.js.map +1 -1
  43. package/dist/internal/positional-keys.d.ts +1 -1
  44. package/dist/internal/positional-keys.d.ts.map +1 -1
  45. package/dist/internal/positional-keys.js +4 -2
  46. package/dist/internal/positional-keys.js.map +1 -1
  47. package/dist/internal/projection.d.ts.map +1 -1
  48. package/dist/internal/projection.js +138 -39
  49. package/dist/internal/projection.js.map +1 -1
  50. package/dist/internal/renderer.d.ts +26 -16
  51. package/dist/internal/renderer.d.ts.map +1 -1
  52. package/dist/internal/renderer.js +45 -106
  53. package/dist/internal/renderer.js.map +1 -1
  54. package/dist/internal/scroll.d.ts.map +1 -1
  55. package/dist/internal/scroll.js +26 -2
  56. package/dist/internal/scroll.js.map +1 -1
  57. package/dist/internal/transform-keys.d.ts +22 -0
  58. package/dist/internal/transform-keys.d.ts.map +1 -0
  59. package/dist/internal/transform-keys.js +43 -0
  60. package/dist/internal/transform-keys.js.map +1 -0
  61. package/dist/unstable/AppearAnimations.d.ts +2 -1
  62. package/dist/unstable/AppearAnimations.d.ts.map +1 -1
  63. package/dist/unstable/AppearAnimations.js +73 -22
  64. package/dist/unstable/AppearAnimations.js.map +1 -1
  65. package/dist/unstable/BatchMembers.d.ts +2 -2
  66. package/dist/unstable/BatchMembers.d.ts.map +1 -1
  67. package/dist/unstable/BatchMembers.js +29 -6
  68. package/dist/unstable/BatchMembers.js.map +1 -1
  69. package/dist/unstable/DomValues.js +1 -1
  70. package/dist/unstable/DomValues.js.map +1 -1
  71. package/dist/unstable/DragTrack.d.ts +2 -2
  72. package/dist/unstable/DragTrack.d.ts.map +1 -1
  73. package/dist/unstable/DragTrack.js +34 -8
  74. package/dist/unstable/DragTrack.js.map +1 -1
  75. package/dist/unstable/ElementSetup.d.ts.map +1 -1
  76. package/dist/unstable/ElementSetup.js +2 -1
  77. package/dist/unstable/ElementSetup.js.map +1 -1
  78. package/dist/unstable/GestureFeatures.d.ts +2 -1
  79. package/dist/unstable/GestureFeatures.d.ts.map +1 -1
  80. package/dist/unstable/GestureFeatures.js +18 -37
  81. package/dist/unstable/GestureFeatures.js.map +1 -1
  82. package/dist/unstable/LiveStyle.d.ts +28 -2
  83. package/dist/unstable/LiveStyle.d.ts.map +1 -1
  84. package/dist/unstable/LiveStyle.js +8 -32
  85. package/dist/unstable/LiveStyle.js.map +1 -1
  86. package/dist/unstable/MemberHold.js +2 -2
  87. package/dist/unstable/MemberHold.js.map +1 -1
  88. package/dist/unstable/PointerValues.d.ts.map +1 -1
  89. package/dist/unstable/PointerValues.js +82 -8
  90. package/dist/unstable/PointerValues.js.map +1 -1
  91. package/dist/unstable/PresenceController.d.ts +5 -2
  92. package/dist/unstable/PresenceController.d.ts.map +1 -1
  93. package/dist/unstable/PresenceController.js +68 -41
  94. package/dist/unstable/PresenceController.js.map +1 -1
  95. package/dist/unstable/ReorderInput.d.ts +2 -2
  96. package/dist/unstable/ReorderInput.js +2 -2
  97. package/dist/unstable/WardConfig.d.ts +13 -4
  98. package/dist/unstable/WardConfig.d.ts.map +1 -1
  99. package/dist/unstable/WardConfig.js.map +1 -1
  100. package/dist/unstable/features/TimelineKeys.d.ts.map +1 -1
  101. package/dist/unstable/features/TimelineKeys.js +18 -2
  102. package/dist/unstable/features/TimelineKeys.js.map +1 -1
  103. package/package.json +3 -3
  104. package/src/MeasuredPair.ts +21 -1
  105. package/src/index.ts +4 -1
  106. package/src/internal/appear.ts +20 -2
  107. package/src/internal/batch-handoff.ts +19 -11
  108. package/src/internal/batch-writer.ts +27 -6
  109. package/src/internal/clock.ts +10 -0
  110. package/src/internal/default-transition.ts +14 -4
  111. package/src/internal/failing.ts +37 -0
  112. package/src/internal/length-keys.ts +80 -0
  113. package/src/internal/measured-pairs.ts +58 -22
  114. package/src/internal/own-values.ts +2 -2
  115. package/src/internal/positional-keys.ts +4 -2
  116. package/src/internal/projection.ts +141 -37
  117. package/src/internal/renderer.ts +45 -92
  118. package/src/internal/scroll.ts +24 -2
  119. package/src/internal/transform-keys.ts +47 -0
  120. package/src/unstable/AppearAnimations.ts +73 -24
  121. package/src/unstable/BatchMembers.ts +32 -8
  122. package/src/unstable/DomValues.ts +1 -1
  123. package/src/unstable/DragTrack.ts +46 -12
  124. package/src/unstable/ElementSetup.ts +2 -1
  125. package/src/unstable/GestureFeatures.ts +23 -44
  126. package/src/unstable/LiveStyle.ts +12 -8
  127. package/src/unstable/MemberHold.ts +2 -2
  128. package/src/unstable/PointerValues.ts +73 -8
  129. package/src/unstable/PresenceController.ts +66 -40
  130. package/src/unstable/ReorderInput.ts +2 -2
  131. package/src/unstable/WardConfig.ts +17 -5
  132. package/src/unstable/features/TimelineKeys.ts +19 -2
@@ -16,7 +16,6 @@
16
16
  * @module
17
17
  */
18
18
  import * as Batch from "@wardic/core/Batch"
19
- import * as BaseValue from "@wardic/core/BaseValue"
20
19
  import type * as Frame from "@wardic/core/Frame"
21
20
  import * as Machine from "@wardic/core/Machine"
22
21
  import * as Projection from "@wardic/core/Projection"
@@ -35,6 +34,7 @@ import { spacesRegistered } from "./colors.ts"
35
34
  import { drawnUnitOf, project, TEMPLATE_KEY, TRANSFORM_FUNCS, type TransformTemplate, unitOf } from "./renderer.ts"
36
35
  import { PREFIX } from "./appear-slot.ts"
37
36
  import { dashCase, isPathKey, isSvgInnerTag, splitPatchForTag, svgAttrNameOf } from "./svg.ts"
37
+ import * as TransformKeys from "./transform-keys.ts"
38
38
 
39
39
  /** An element's mount animation, as its binding describes it. */
40
40
  export interface Spec {
@@ -245,7 +245,7 @@ const toleranceFor = (key: string, svgInner: boolean, bare: boolean, unit: strin
245
245
  /** A bare number's tolerance, by the unit `project` draws `key` in. */
246
246
  const bareTolerance = (key: string): number =>
247
247
  Bool.match(drawnUnitOf(key) === "", {
248
- onTrue: () => Bool.match(BaseValue.TRANSFORM_IDENTITY[key] === 1, { onTrue: () => 0.001, onFalse: () => 0.002 }),
248
+ onTrue: () => Bool.match(TransformKeys.TRANSFORM_IDENTITY[key] === 1, { onTrue: () => 0.001, onFalse: () => 0.002 }),
249
249
  onFalse: () => 0.1,
250
250
  })
251
251
 
@@ -796,6 +796,21 @@ const batchNameOf = (spec: BatchSpec, columns: ReadonlyArray<Column>): string =>
796
796
  // Module state (#460, Q7): a cache keyed by what it caches.
797
797
  const batchCache = /*#__PURE__*/ new Map<string, Result.Result<Keyframes, string>>()
798
798
 
799
+ /**
800
+ * Why a rule can't stand in for an element's own depth that moves: CSS blends two `perspective()`s by
801
+ * decomposing their matrices, linear in 1/depth (CSS Transforms 2, §14), so 100px to 1000px reads 181.8px
802
+ * halfway, where Wardic's frame reads 550px. A depth that doesn't move is drawn the same in every stop.
803
+ */
804
+ // #887 (ADR-0073, *Amendment (#887)*, Q13), as Timeline values leave `perspective()` out (`timeline.ts`).
805
+ export const DEPTH_MOVES_REASON = `${TransformKeys.PERSPECTIVE} moves, and CSS blends a depth by its inverse, not as Wardic draws it`
806
+
807
+ /**
808
+ * Why a Batch's rule can't draw its members' depths: a member's is at or below 0, which Wardic leaves out,
809
+ * and CSS draws as 1px, or refuses with the stop's whole `transform`.
810
+ */
811
+ // #887: a rule draws a depth its members hold in every stop, each one's own as a custom property.
812
+ const DEPTH_AT_FLOOR_REASON = `${TransformKeys.PERSPECTIVE} at or below 0 on a member, which CSS draws unlike Wardic`
813
+
799
814
  /** A spec's first key with a start or target that isn't a finite number: a rule can't write it. */
800
815
  const unfiniteKeyOf = (spec: BatchSpec): Option.Option<string> =>
801
816
  Arr.findFirst(spec.keys, (_, k) => Arr.some(Arr.appendAll(spec.starts, spec.targets), (values) => Bool.not(Number.isFinite(values[k] as number))))
@@ -812,7 +827,10 @@ export const batchKeyframes = (spec: BatchSpec): Result.Result<BatchKeyframes, s
812
827
  if (Option.isSome(unfinite)) return Result.fail(`a start or target that isn't a finite number (${unfinite.value})`)
813
828
  const movers = moversOf(spec)
814
829
  const columns = columnsOf(spec.keys, movers)
830
+ if (Arr.some(columns, (column) => Bool.and(column.key === TransformKeys.PERSPECTIVE, column.moves))) return Result.fail(DEPTH_MOVES_REASON)
815
831
  const written = writtenOf(movers, columns)
832
+ const depth = Arr.findFirst(written.transform, (column) => column.key === TransformKeys.PERSPECTIVE)
833
+ if (Option.isSome(depth) && Arr.some(movers.targets, (values) => Bool.not(TransformKeys.drawsDepth(values[depth.value.k])))) return Result.fail(DEPTH_AT_FLOOR_REASON)
816
834
  if (Bool.and(Arr.isReadonlyArrayEmpty(written.transform), Option.isNone(written.opacity))) return Result.fail("no key moves")
817
835
  const name = batchNameOf(spec, columns)
818
836
  const rule = Option.getOrElse(Option.fromUndefinedOr(batchCache.get(name)), () => remember(batchCache, name, sampleBatch(spec, columns, written, name)))
@@ -43,6 +43,9 @@ const MISMATCH = /*#__PURE__*/ Effect.logDebug("wardic.hydration: a Batch member
43
43
  */
44
44
  export const startAtOf = (members: HandoffMembers): ((slot: number) => number) => {
45
45
  let times: Map<number, number> | undefined = undefined
46
+ // Each member whose read threw, by slot: its own start throws it, for its Batch to report, and it plays
47
+ // its change from its start; every other member keeps its time (#977).
48
+ const failures = new Map<number, unknown>()
46
49
  /** Every such member's time, read at once. */
47
50
  const timesNow = (): Map<number, number> => {
48
51
  const read = new Map<number, number>()
@@ -50,16 +53,20 @@ export const startAtOf = (members: HandoffMembers): ((slot: number) => number) =
50
53
  const keyOf = members.keyOf
51
54
  // Once a Handoff, over its members (#665's per-member site): reads alone.
52
55
  Iter.forEach(members.appearing, (slot) => {
53
- const el = members.elementOf(slot)
54
- if (Predicate.isUndefined(el)) return
55
- const animation = AppearAnimations.pageAnimationsOf(el).get(el)
56
- if (Predicate.isUndefined(animation)) return
57
- const name = (animation as Animation & { readonly animationName: string }).animationName
58
- if (Predicate.isNotUndefined(keyOf) && !checked.has(name)) {
59
- checked.add(name)
60
- if (!Option.exists(keyOf(slot), (key) => Appear.matchesBatch(animation, key))) members.runtime.runFork(MISMATCH)
56
+ try {
57
+ const el = members.elementOf(slot)
58
+ if (Predicate.isUndefined(el)) return
59
+ const animation = AppearAnimations.pageAnimationsOf(el).get(el)
60
+ if (Predicate.isUndefined(animation)) return
61
+ const name = (animation as Animation & { readonly animationName: string }).animationName
62
+ if (Predicate.isNotUndefined(keyOf) && !checked.has(name)) {
63
+ checked.add(name)
64
+ if (!Option.exists(keyOf(slot), (key) => Appear.matchesBatch(animation, key))) members.runtime.runFork(MISMATCH)
65
+ }
66
+ read.set(slot, Appear.elapsedOf(animation))
67
+ } catch (defect) {
68
+ failures.set(slot, defect)
61
69
  }
62
- read.set(slot, Appear.elapsedOf(animation))
63
70
  })
64
71
  // Every one let go once this step's starts are done, a member it didn't move among them.
65
72
  queueMicrotask(members.release)
@@ -69,7 +76,8 @@ export const startAtOf = (members: HandoffMembers): ((slot: number) => number) =
69
76
  return (slot) => {
70
77
  if (Predicate.isUndefined(times)) times = timesNow()
71
78
  const time = times.get(slot)
72
- if (Predicate.isUndefined(time)) return Number.NaN
73
- return time
79
+ if (Predicate.isNotUndefined(time)) return time
80
+ if (failures.has(slot)) throw failures.get(slot)
81
+ return Number.NaN
74
82
  }
75
83
  }
@@ -14,6 +14,7 @@ import * as Option from "effect/Option"
14
14
  import * as Predicate from "effect/Predicate"
15
15
  import * as Result from "effect/Result"
16
16
  import { TRANSFORM_FUNCS, unitOf } from "./renderer.ts"
17
+ import * as TransformKeys from "./transform-keys.ts"
17
18
 
18
19
  /** A transform function a Batch writes: its key's index in the Batch, what goes either side of its value, and its identity. */
19
20
  interface Part {
@@ -37,9 +38,17 @@ const FUNC_PARTS: ReadonlyArray<Omit<Part, "k"> & { readonly key: string }> = Ar
37
38
  identity: func.identity,
38
39
  }))
39
40
 
41
+ /** What a member's write walks: every part but the element's own depth, which it writes ahead of them. */
42
+ // #887 (ADR-0073, *Amendment (#887)*, Q8), as the renderer's walk.
43
+ const WALKED_PARTS = Arr.filter(FUNC_PARTS, (part) => part.key !== TransformKeys.PERSPECTIVE)
44
+
45
+ /** What goes either side of a member's own depth in its write. */
46
+ const DEPTH_OPEN = "perspective("
47
+ const DEPTH_CLOSE = `${unitOf(TransformKeys.PERSPECTIVE)})`
48
+
40
49
  /** A Batch's write, for its keys in their order: built once, when the Batch is made. */
41
50
  const forKeys = (keys: ReadonlyArray<string>): ((el: Element, positions: Float64Array, base: number) => void) => {
42
- const parts: ReadonlyArray<Part> = Arr.filterMap(FUNC_PARTS, (part) =>
51
+ const parts: ReadonlyArray<Part> = Arr.filterMap(WALKED_PARTS, (part) =>
43
52
  Option.match(Arr.findFirstIndex(keys, (key) => key === part.key), {
44
53
  onNone: () => Result.failVoid,
45
54
  onSome: (k) => Result.succeed({ k, open: part.open, close: part.close, identity: part.identity }),
@@ -47,14 +56,23 @@ const forKeys = (keys: ReadonlyArray<string>): ((el: Element, positions: Float64
47
56
  const count = parts.length
48
57
  // Its index for the per-frame write, or -1 for none: a plain read there (ADR-0025, the per-frame path).
49
58
  const opacityAt = Option.getOrElse(Arr.findFirstIndex(keys, (key) => key === "opacity"), () => -1)
50
- // Per frame, per moving member (ADR-0025, *Amendment (#69)*): a counted loop over its transform
51
- // functions in the renderer's order, each left out at its identity, the string built by concatenation
52
- // as the renderer's is (ADR-0034); `none` when every one is at its identity (ADR-0023).
59
+ const depthAt = Option.getOrElse(Arr.findFirstIndex(keys, (key) => key === TransformKeys.PERSPECTIVE), () => -1)
60
+ const writesTransform = Bool.or(count > 0, depthAt !== -1)
61
+ // Per frame, per moving member (ADR-0025, *Amendment (#69)*): its own depth first, then a counted loop
62
+ // over its transform functions in the renderer's order, each left out at its identity, the string built
63
+ // by concatenation as the renderer's is (ADR-0034); `none` when every one is left out (ADR-0023).
53
64
  return (el, positions, base) => {
54
65
  const style = (el as HTMLElement).style
55
- if (count > 0) {
66
+ if (writesTransform) {
56
67
  let transform = ""
57
68
  let separator = ""
69
+ if (depthAt !== -1) {
70
+ const depth = positions[base + depthAt]
71
+ if (TransformKeys.drawsDepth(depth)) {
72
+ transform = DEPTH_OPEN + depth + DEPTH_CLOSE
73
+ separator = " "
74
+ }
75
+ }
58
76
  for (let p = 0; p < count; p++) {
59
77
  const part = parts[p]
60
78
  const value = positions[base + part.k]
@@ -71,7 +89,7 @@ const forKeys = (keys: ReadonlyArray<string>): ((el: Element, positions: Float64
71
89
 
72
90
  /**
73
91
  * A member's style as a server writes it (#665's PR 6, Q63): `values`' `transform` and `opacity`, the
74
- * strings `forKeys`' write draws them with, each left out at its identity. What the client then writes
92
+ * strings `forKeys`' write draws them with, each left out as there. What the client then writes
75
93
  * at the member's arrival is the same, so its element doesn't move at hydration.
76
94
  */
77
95
  export const styleOf = (values: Readonly<Record<string, number>>): Readonly<Record<string, string>> => {
@@ -80,6 +98,9 @@ export const styleOf = (values: Readonly<Record<string, number>>): Readonly<Reco
80
98
  const functions = Arr.filterMap(FUNC_PARTS, (part) => {
81
99
  const value = values[part.key]
82
100
  if (Bool.or(Predicate.isUndefined(value), value === part.identity)) return Result.failVoid
101
+ if (part.key === TransformKeys.PERSPECTIVE) {
102
+ if (Bool.not(TransformKeys.drawsDepth(value))) return Result.failVoid
103
+ }
83
104
  return Result.succeed(part.open + value + part.close)
84
105
  })
85
106
  if (functions.length > 0) style.transform = functions.join(" ")
@@ -46,3 +46,13 @@ const frames: Layer.Layer<RefreshFrameSource.RefreshFrameSource> = Layer.effect(
46
46
  export const ClockDomLive: Layer.Layer<Clock.Clock | RefreshFrameSource.RefreshFrameSource> = Clock.layer.pipe(
47
47
  Layer.provideMerge(frames),
48
48
  )
49
+
50
+ /**
51
+ * The DOM's late frames, for its Frame loop (`Clock.LateFrames`, #1026): `requestAnimationFrame`'s
52
+ * timestamps are on `performance.now()`'s timebase, the Clock's `now()`, so a frame whose callback ran
53
+ * more than 40 ms after its timestamp was held by a long task.
54
+ */
55
+ // 40 ms is Motion's own line for "main thread work" (`MAX_START_DELAY`, motion-dom 14.6
56
+ // `resolve-start-time.mjs`): a frame less late is on time, so a frame's jitter, and a privacy setting's
57
+ // coarse timers, aren't taken for a task.
58
+ export const LateFramesDomLive = Layer.succeed(Clock.LateFrames, { ranAfter: 40 })
@@ -2,7 +2,8 @@
2
2
  * The DOM Environment's Default transition (CONTEXT.md; ADR-0051, #357): Motion's, by value
3
3
  * (`.reference/motion` at 16c6122, `motion-dom/src/animation/utils/default-transitions.ts`,
4
4
  * `getDefaultTransition`):
5
- * - a transform but a scale: a spring, 500 / 25, at rest under 10 px/s;
5
+ * - a transform but a scale, the element's own depth (`transformPerspective`) among them: a spring,
6
+ * 500 / 25, at rest under 10 px/s;
6
7
  * - `scale`, `scaleX`, `scaleY`: a spring, 550, critically damped toward 0 (2·√550), else 30;
7
8
  * - anything else (opacity, colours, a box's size, a filter): a 0.3 s tween on
8
9
  * `cubic-bezier(0.25, 0.1, 0.35, 1)`, "a slightly shallower version of the browser's default ease".
@@ -16,13 +17,22 @@
16
17
  */
17
18
  // #882 (ADR-0073, *Amendment (#882)*, Q2): core's table, `DefaultTransition.byKey`, the same objects.
18
19
  import * as DefaultTransition from "@wardic/core/DefaultTransition"
19
- import type * as Layer from "effect/Layer"
20
+ import * as Layer from "effect/Layer"
21
+ import * as TransformKeys from "./transform-keys.ts"
20
22
 
21
23
  /** The transition through more than two keyframes, as Motion's `keyframesTransition`: a 0.8 s tween, eased out. */
22
24
  export const keyframes: DefaultTransition.KeyframesTransition = DefaultTransition.KEYFRAMES_TWEEN
23
25
 
26
+ /** The key whose transition the element's own depth runs on: a turn's, so a depth and a turn leaving together decay in step. */
27
+ const DEPTH_RUNS_AS = "rotateY"
28
+
24
29
  /** The transition `key` runs on toward `target` when its own isn't defined, in the DOM: Motion's. */
25
- export const transitionFor: (key: string, target: number | string) => DefaultTransition.Transition = DefaultTransition.byKey
30
+ // #887 (ADR-0073, *Amendment (#887)*, Q10): core's `byKey` knows core's transforms. The DOM's own depth takes
31
+ // a turn's, the same object.
32
+ export const transitionFor = (key: string, target: number | string): DefaultTransition.Transition => {
33
+ if (key === TransformKeys.PERSPECTIVE) return DefaultTransition.byKey(DEPTH_RUNS_AS, target)
34
+ return DefaultTransition.byKey(key, target)
35
+ }
26
36
 
27
37
  /** The DOM Environment's `DefaultTransition.DefaultTransition`. */
28
- export const DefaultTransitionDomLive: Layer.Layer<DefaultTransition.DefaultTransition> = DefaultTransition.layerByKey
38
+ export const DefaultTransitionDomLive: Layer.Layer<DefaultTransition.DefaultTransition> = /*#__PURE__*/ Layer.succeed(DefaultTransition.DefaultTransition, { transitionFor, keyframes })
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Which of a Subject's callbacks are in a run of throws, by name: a callback's run starts at its first
3
+ * throw and ends at its next call that returns. The set of names is made at the first throw, as most
4
+ * Subjects never see one.
5
+ *
6
+ * @module
7
+ */
8
+ // #979 group I (ADR-0074 decision 3): an element's gesture callbacks, a layout node's callbacks and a drag
9
+ // track's failures, each reported at its run's first throw.
10
+ import { identity } from "effect/Function"
11
+ import * as Predicate from "effect/Predicate"
12
+ import * as UndefinedOr from "effect/UndefinedOr"
13
+
14
+ /** What holds a Subject's failing names: `undefined` until its first throw. */
15
+ export interface Failing<N extends string> {
16
+ failing: Set<N> | undefined
17
+ }
18
+
19
+ /** Whether a throw of `name`'s is its run's first: the run is on from now. */
20
+ export const firstThrowOf = <N extends string>(holder: Failing<N>, name: N): boolean => {
21
+ const failing = UndefinedOr.match(holder.failing, {
22
+ onUndefined: () => {
23
+ const made = new Set<N>()
24
+ holder.failing = made
25
+ return made
26
+ },
27
+ onDefined: identity,
28
+ })
29
+ if (failing.has(name)) return false
30
+ failing.add(name)
31
+ return true
32
+ }
33
+
34
+ /** A clean call of `name`'s: its run, if one is on, ended. */
35
+ export const endRunOf = <N extends string>(holder: Failing<N>, name: N): void => {
36
+ if (Predicate.isNotUndefined(holder.failing)) holder.failing.delete(name)
37
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The CSS lengths a bare number on is drawn in `px`, spelled as Wardic's keys are (`margin-top`). The DOM
3
+ * renderer draws them, and `LiveStyle` hands such a number in an element's `style` to it.
4
+ *
5
+ * @module
6
+ */
7
+ /**
8
+ * The CSS properties a bare number on is a length, drawn in `px`, spelled as Wardic's keys are
9
+ * (`margin-top`): Motion's, and `min-width`, `min-height`, the gaps and `letter-spacing`. The Solid
10
+ * bindings' value types take a number on these and on no other length, so a number never draws CSS a
11
+ * browser drops. `line-height` isn't one: CSS reads its bare number as a multiple. A number on any other
12
+ * key, `opacity`, `z-index`, a custom property, is drawn as it is; a string always is.
13
+ */
14
+ // #522: Motion's `numberValueTypes`' `px` keys; the bindings' `WardicValues`.
15
+ export const LENGTH_KEYS = [
16
+ "border-width",
17
+ "border-top-width",
18
+ "border-right-width",
19
+ "border-bottom-width",
20
+ "border-left-width",
21
+ "border-radius",
22
+ "border-top-left-radius",
23
+ "border-top-right-radius",
24
+ "border-bottom-right-radius",
25
+ "border-bottom-left-radius",
26
+ "width",
27
+ "min-width",
28
+ "max-width",
29
+ "height",
30
+ "min-height",
31
+ "max-height",
32
+ "top",
33
+ "right",
34
+ "bottom",
35
+ "left",
36
+ "inset",
37
+ "inset-block",
38
+ "inset-block-start",
39
+ "inset-block-end",
40
+ "inset-inline",
41
+ "inset-inline-start",
42
+ "inset-inline-end",
43
+ "padding",
44
+ "padding-top",
45
+ "padding-right",
46
+ "padding-bottom",
47
+ "padding-left",
48
+ "padding-block",
49
+ "padding-block-start",
50
+ "padding-block-end",
51
+ "padding-inline",
52
+ "padding-inline-start",
53
+ "padding-inline-end",
54
+ "margin",
55
+ "margin-top",
56
+ "margin-right",
57
+ "margin-bottom",
58
+ "margin-left",
59
+ "margin-block",
60
+ "margin-block-start",
61
+ "margin-block-end",
62
+ "margin-inline",
63
+ "margin-inline-start",
64
+ "margin-inline-end",
65
+ "gap",
66
+ "row-gap",
67
+ "column-gap",
68
+ "font-size",
69
+ "letter-spacing",
70
+ "background-position-x",
71
+ "background-position-y",
72
+ // An element's children's depth (#887), Motion's: the property beside the element's own `transformPerspective`.
73
+ "perspective",
74
+ ] as const
75
+
76
+ /** One of `LENGTH_KEYS`: a CSS property a bare number on is drawn in `px`. */
77
+ export type LengthKey = (typeof LENGTH_KEYS)[number]
78
+
79
+ /** {@link LENGTH_KEYS}, for a membership test a frame can make. */
80
+ export const LENGTH_KEY_SET: ReadonlySet<string> = new Set(LENGTH_KEYS)
@@ -100,6 +100,10 @@ interface Request {
100
100
  readonly element: HTMLElement
101
101
  readonly slots: ReadonlyArray<Slot>
102
102
  readonly values: Values.Values
103
+ /** Its asker's, told what its write threw (#979, row 8). */
104
+ readonly failed: (defect: unknown) => void
105
+ /** Whether its write threw: its pairs are left unread. */
106
+ threw: boolean
103
107
  }
104
108
 
105
109
  // Module state (#460, Q7): each pair its batch has read, by the pair as asked, kept as long as its asker
@@ -122,16 +126,18 @@ let scheduled = false
122
126
  /**
123
127
  * Measures `pairs` on `element` at the end of this task, with every other element's in the same batch:
124
128
  * each pair, as asked, {@link measured} before the next tick. `values` are what the element draws now,
125
- * its other transforms among them.
129
+ * its other transforms among them. Writing them can throw (a Transform template among `values`): then
130
+ * its pairs are never measured, `failed` is told, and the rest of the batch goes on.
126
131
  */
127
- // #430's Q2.
132
+ // #430's Q2. #979, row 8 (ADR-0074): `failed`, its asker's, which reports through its own runtime.
128
133
  export const measure = (
129
134
  element: HTMLElement,
130
135
  pairs: Readonly<Record<string, { readonly from: number | string; readonly to: number | string }>>,
131
136
  values: Values.Values,
137
+ failed: (defect: unknown) => void,
132
138
  ): Readonly<Record<string, Requested>> => {
133
139
  const made = Rec.map(pairs, ({ from, to }, key): Requested => ({ key, from, to }))
134
- queued.push({ element, slots: Arr.map(Rec.values(made), (pair): Slot => ({ pair, fromPx: undefined, toPx: undefined })), values })
140
+ queued.push({ element, slots: Arr.map(Rec.values(made), (pair): Slot => ({ pair, fromPx: undefined, toPx: undefined })), values, failed, threw: false })
135
141
  if (Bool.not(scheduled)) {
136
142
  scheduled = true
137
143
  queueMicrotask(flush)
@@ -207,35 +213,42 @@ const savedOf = (element: HTMLElement, property: string): Saved => ({ element, p
207
213
 
208
214
  /**
209
215
  * Write `pairs`' translates at their `end` through the element's whole transform, keeping what was
210
- * there: the browser lays out any unit, `-100%` included (#594).
216
+ * there in `saved` before it's written: the browser lays out any unit, `-100%` included (#594).
211
217
  */
212
- const writeTranslates = (request: Request, slots: ReadonlyArray<Slot>, end: "from" | "to"): ReadonlyArray<Saved> => {
213
- if (slots.length === 0) return []
218
+ const writeTranslates = (request: Request, slots: ReadonlyArray<Slot>, end: "from" | "to", saved: Array<Saved>): void => {
219
+ if (slots.length === 0) return
214
220
  const { element, values } = request
215
- const saved = savedOf(element, "transform")
216
221
  const transform = project({ ...values, ...Rec.fromEntries(Arr.map(slots, ({ pair }) => [pair.key, pair[end]] as const)) })["transform"]
222
+ saved.push(savedOf(element, "transform"))
217
223
  element.style.setProperty("transform", UndefinedOr.match(transform as string | undefined, { onUndefined: () => "none", onDefined: String }))
218
- return [saved]
219
224
  }
220
225
 
221
- /** Write each pair's target inline on its element, keeping what was there; a translate through the element's whole transform. */
222
- const writeTargets = (request: Request): ReadonlyArray<Saved> => {
226
+ /**
227
+ * Write each pair's target inline on its element, keeping what was there in `saved` before each is
228
+ * written; a translate through the element's whole transform.
229
+ */
230
+ const writeTargets = (request: Request, saved: Array<Saved>): void => {
223
231
  const unread = Arr.filter(request.slots, (slot) => Predicate.isUndefined(slot.toPx))
224
- const saved: Array<Saved> = [...writeTranslates(request, Arr.filter(unread, (slot) => TRANSLATES.has(slot.pair.key)), "to")]
232
+ writeTranslates(request, Arr.filter(unread, (slot) => TRANSLATES.has(slot.pair.key)), "to", saved)
225
233
  Arr.forEach(unread, ({ pair }) => {
226
234
  if (TRANSLATES.has(pair.key)) return
227
235
  saved.push(savedOf(request.element, pair.key))
228
236
  request.element.style.setProperty(pair.key, cssOf(pair.to))
229
237
  })
230
- return saved
231
238
  }
232
239
 
233
240
  /**
234
241
  * Write each translate pair's start not in px, as a target is (#594): a layout element's transform at
235
242
  * this moment is its projection's, or held off for its Measure pass, so reading it as it is gave 0.
236
243
  */
237
- const writeTranslateStarts = (request: Request): ReadonlyArray<Saved> =>
238
- writeTranslates(request, Arr.filter(request.slots, (slot) => Bool.and(TRANSLATES.has(slot.pair.key), Predicate.isUndefined(slot.fromPx))), "from")
244
+ const writeTranslateStarts = (request: Request, saved: Array<Saved>): void =>
245
+ writeTranslates(request, Arr.filter(request.slots, (slot) => Bool.and(TRANSLATES.has(slot.pair.key), Predicate.isUndefined(slot.fromPx))), "from", saved)
246
+
247
+ /** `request`'s write threw: its pairs are left unread, so its animation switches, and its asker is told. */
248
+ const requestThrew = (request: Request, defect: unknown): void => {
249
+ request.threw = true
250
+ request.failed(defect)
251
+ }
239
252
 
240
253
  /** Put back what {@link writeTargets} replaced. */
241
254
  const restore = (saved: ReadonlyArray<Saved>): void =>
@@ -260,27 +273,49 @@ const flush = (): void => {
260
273
  slot.toPx = givenPx(slot.pair.to)
261
274
  slot.fromPx = givenPx(slot.pair.from)
262
275
  }))
276
+ // #979, row 8 (ADR-0074): each request's write is its own, in a `try` of its own in each write's loop.
277
+ // One that throws (an exit's Transform template, say) is left unread, its asker told, and the rest of
278
+ // the batch goes on, every style written so far put back: before, its throw ended the batch
279
+ // uncaught, every pair in it voided and the targets written before it left inline.
263
280
  // WRITE, READ, WRITE: each translate's start not in px, written alone and read (#594).
264
- const starts = Arr.flatMap(batch, writeTranslateStarts)
265
- if (Arr.isArrayNonEmpty(starts)) {
266
- try {
281
+ const starts: Array<Saved> = []
282
+ try {
283
+ Arr.forEach(batch, (request) => {
284
+ try {
285
+ writeTranslateStarts(request, starts)
286
+ } catch (defect) {
287
+ requestThrew(request, defect)
288
+ }
289
+ })
290
+ if (Arr.isArrayNonEmpty(starts)) {
267
291
  Arr.forEach(batch, (request, i) => Arr.forEach(request.slots, (slot) => {
292
+ if (request.threw) return
268
293
  if (Bool.and(TRANSLATES.has(slot.pair.key), Predicate.isUndefined(slot.fromPx))) slot.fromPx = readPx(request.element, UndefinedOr.getOrThrow(styles[i]), slot.pair.key)
269
294
  }))
270
- } finally {
271
- restore(starts)
272
295
  }
296
+ } finally {
297
+ restore(starts)
273
298
  }
274
299
  // READ: each other start not already in px, as the element lays out now.
275
300
  Arr.forEach(batch, (request, i) => Arr.forEach(request.slots, (slot) => {
301
+ if (request.threw) return
276
302
  if (Predicate.isUndefined(slot.fromPx)) slot.fromPx = readPx(request.element, UndefinedOr.getOrThrow(styles[i]), slot.pair.key)
277
303
  }))
278
304
  const scrollY = globalThis.scrollY
279
- // WRITE: each target, inline.
280
- const saved = Arr.flatMap(batch, writeTargets)
305
+ const saved: Array<Saved> = []
281
306
  try {
307
+ // WRITE: each target, inline.
308
+ Arr.forEach(batch, (request) => {
309
+ if (request.threw) return
310
+ try {
311
+ writeTargets(request, saved)
312
+ } catch (defect) {
313
+ requestThrew(request, defect)
314
+ }
315
+ })
282
316
  // READ: each target not already in px, laid out once.
283
317
  Arr.forEach(batch, (request, i) => Arr.forEach(request.slots, (slot) => {
318
+ if (request.threw) return
284
319
  if (Predicate.isUndefined(slot.toPx)) slot.toPx = readPx(request.element, UndefinedOr.getOrThrow(styles[i]), slot.pair.key)
285
320
  }))
286
321
  } finally {
@@ -288,8 +323,9 @@ const flush = (): void => {
288
323
  restore(saved)
289
324
  if (globalThis.scrollY !== scrollY) globalThis.scrollTo(globalThis.scrollX, scrollY)
290
325
  }
291
- // Each pair read at both ends, as a record of its own.
326
+ // Each pair read at both ends, as a record of its own: none of a request whose write threw.
292
327
  Arr.forEach(batch, (request) => Arr.forEach(request.slots, ({ pair, fromPx, toPx }) => {
328
+ if (request.threw) return
293
329
  if (Predicate.isUndefined(fromPx)) return
294
330
  if (Predicate.isUndefined(toPx)) return
295
331
  if (Bool.and(Number.isFinite(fromPx), Number.isFinite(toPx))) read.set(pair, { ...pair, fromPx, toPx })
@@ -10,7 +10,6 @@
10
10
  * Observability: per element and cold (once per key), so quiet; the spine logs what it
11
11
  * started from and returned to.
12
12
  */
13
- import * as BaseValue from "@wardic/core/BaseValue"
14
13
  import * as Interpolator from "@wardic/core/Interpolator"
15
14
  import * as Bool from "effect/Boolean"
16
15
  import * as Match from "effect/Match"
@@ -20,6 +19,7 @@ import * as Predicate from "effect/Predicate"
20
19
  import * as Str from "effect/String"
21
20
  import { parseCssText } from "./starting-style.ts"
22
21
  import { dashCase, isSvgInner, svgAttrNameOf } from "./svg.ts"
22
+ import * as TransformKeys from "./transform-keys.ts"
23
23
 
24
24
  /** An element's own value for a key: the raw value read, a string, a transform key's identity, or `None`. */
25
25
  export type OwnValue = (key: string) => Option.Option<number | string>
@@ -53,7 +53,7 @@ export const ownValues = (element: Element): OwnValue => {
53
53
  onFalse: () => Option.none(),
54
54
  })
55
55
  const read = (key: string): Option.Option<number | string> =>
56
- Option.orElse(BaseValue.transformIdentity(key), () =>
56
+ Option.orElse(TransformKeys.transformIdentity(key), () =>
57
57
  Option.orElse(attributeOf(key), () => nonEmpty(computedStyle().getPropertyValue(dashCase(key)).trim()))
58
58
  )
59
59
  return (key) =>
@@ -10,6 +10,7 @@ import * as ReducedMotion from "@wardic/core/ReducedMotion"
10
10
  import * as Layer from "effect/Layer"
11
11
  import * as Predicate from "effect/Predicate"
12
12
  import { dashCase } from "./svg.ts"
13
+ import * as TransformKeys from "./transform-keys.ts"
13
14
 
14
15
  /** The box's position and size, as CSS properties. */
15
16
  const BOX_KEYS: ReadonlySet<string> = new Set(["width", "height", "top", "left", "right", "bottom"])
@@ -17,8 +18,9 @@ const BOX_KEYS: ReadonlySet<string> = new Set(["width", "height", "top", "left",
17
18
  /** A key of the box's position or size, written as a CSS name or in camelCase. */
18
19
  const isBoxKey: Predicate.Predicate<string> = (key) => BOX_KEYS.has(dashCase(key))
19
20
 
20
- /** Whether reduced motion lands `key` at once: a transform, or a key that places or sizes the box. */
21
- export const isPositional: Predicate.Predicate<string> = Predicate.or(ReducedMotion.isTransform, isBoxKey)
21
+ /** Whether reduced motion lands `key` at once: one of the DOM's transforms, or a key that places or sizes the box. */
22
+ // #887 (Q11): the DOM's transforms, core's and its own, so its depth lands at once, as Motion's does.
23
+ export const isPositional: Predicate.Predicate<string> = Predicate.or(TransformKeys.isTransformKey, isBoxKey)
22
24
 
23
25
  /** The DOM Environment's `ReducedMotion.PositionalKeys`. */
24
26
  export const PositionalKeysDomLive: Layer.Layer<ReducedMotion.PositionalKeys> = Layer.succeed(ReducedMotion.PositionalKeys, { isPositional })