@wardic/dom 1.0.0-rc.9 → 1.0.0

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 (82) hide show
  1. package/dist/Appear.d.ts +7 -1
  2. package/dist/Appear.d.ts.map +1 -1
  3. package/dist/Appear.js +7 -1
  4. package/dist/Appear.js.map +1 -1
  5. package/dist/DomBatch.d.ts +20 -0
  6. package/dist/DomBatch.d.ts.map +1 -0
  7. package/dist/DomBatch.js +23 -0
  8. package/dist/DomBatch.js.map +1 -0
  9. package/dist/DomInput.d.ts +2 -1
  10. package/dist/DomInput.d.ts.map +1 -1
  11. package/dist/DomInput.js +3 -1
  12. package/dist/DomInput.js.map +1 -1
  13. package/dist/KeyboardPress.d.ts +16 -0
  14. package/dist/KeyboardPress.d.ts.map +1 -0
  15. package/dist/KeyboardPress.js +17 -0
  16. package/dist/KeyboardPress.js.map +1 -0
  17. package/dist/ReorderController.d.ts +24 -4
  18. package/dist/ReorderController.d.ts.map +1 -1
  19. package/dist/ReorderController.js +38 -4
  20. package/dist/ReorderController.js.map +1 -1
  21. package/dist/index.d.ts +5 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +3 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/internal/appear-slot.d.ts +23 -0
  26. package/dist/internal/appear-slot.d.ts.map +1 -0
  27. package/dist/internal/appear-slot.js +29 -0
  28. package/dist/internal/appear-slot.js.map +1 -0
  29. package/dist/internal/appear.d.ts +84 -16
  30. package/dist/internal/appear.d.ts.map +1 -1
  31. package/dist/internal/appear.js +302 -61
  32. package/dist/internal/appear.js.map +1 -1
  33. package/dist/internal/batch-writer.d.ts +16 -0
  34. package/dist/internal/batch-writer.d.ts.map +1 -0
  35. package/dist/internal/batch-writer.js +77 -0
  36. package/dist/internal/batch-writer.js.map +1 -0
  37. package/dist/internal/gate.d.ts +3 -2
  38. package/dist/internal/gate.d.ts.map +1 -1
  39. package/dist/internal/gate.js +5 -1
  40. package/dist/internal/gate.js.map +1 -1
  41. package/dist/internal/input.d.ts +0 -6
  42. package/dist/internal/input.d.ts.map +1 -1
  43. package/dist/internal/input.js +205 -23
  44. package/dist/internal/input.js.map +1 -1
  45. package/dist/internal/keyboard-press.d.ts +7 -0
  46. package/dist/internal/keyboard-press.d.ts.map +1 -0
  47. package/dist/internal/keyboard-press.js +45 -0
  48. package/dist/internal/keyboard-press.js.map +1 -0
  49. package/dist/internal/measure.js +1 -1
  50. package/dist/internal/measure.js.map +1 -1
  51. package/dist/internal/projection.js +1 -1
  52. package/dist/internal/projection.js.map +1 -1
  53. package/dist/internal/renderer.d.ts +18 -0
  54. package/dist/internal/renderer.d.ts.map +1 -1
  55. package/dist/internal/renderer.js +4 -2
  56. package/dist/internal/renderer.js.map +1 -1
  57. package/dist/internal/reorder.d.ts +28 -13
  58. package/dist/internal/reorder.d.ts.map +1 -1
  59. package/dist/internal/reorder.js +55 -26
  60. package/dist/internal/reorder.js.map +1 -1
  61. package/dist/internal/reveal.d.ts +7 -3
  62. package/dist/internal/reveal.d.ts.map +1 -1
  63. package/dist/internal/reveal.js +8 -3
  64. package/dist/internal/reveal.js.map +1 -1
  65. package/package.json +4 -4
  66. package/src/Appear.ts +12 -3
  67. package/src/DomBatch.ts +22 -0
  68. package/src/DomInput.ts +2 -1
  69. package/src/KeyboardPress.ts +16 -0
  70. package/src/ReorderController.ts +54 -4
  71. package/src/index.ts +5 -3
  72. package/src/internal/appear-slot.ts +32 -0
  73. package/src/internal/appear.ts +462 -67
  74. package/src/internal/batch-writer.ts +95 -0
  75. package/src/internal/gate.ts +7 -3
  76. package/src/internal/input.ts +209 -25
  77. package/src/internal/keyboard-press.ts +45 -0
  78. package/src/internal/measure.ts +1 -1
  79. package/src/internal/projection.ts +1 -1
  80. package/src/internal/renderer.ts +4 -2
  81. package/src/internal/reorder.ts +85 -39
  82. package/src/internal/reveal.ts +10 -4
package/src/Appear.ts CHANGED
@@ -9,6 +9,11 @@
9
9
  * - **At mount:** `find` the element's animation, check it `matches` the client's own spec, start the run
10
10
  * `elapsedOf` it in (`Machine.startAt`), and `release` the element in the task that writes the engine's
11
11
  * first frame.
12
+ * - **A Batch's members** (#706): `batchKeyframes` samples one rule for every member on one set of
13
+ * transitions, each member's own values read from custom properties; a sheet's `batch` gives them one
14
+ * slot, and each member its style. At the Handoff, `findAll` reads every member's animation in one call,
15
+ * each `matchesBatch` the client's key, and its change starts `elapsedOf` it in (`Batch.retarget`'s
16
+ * `startAt`).
12
17
  *
13
18
  * @example
14
19
  * import * as Appear from "@wardic/dom/Appear"
@@ -24,22 +29,26 @@
24
29
  export {
25
30
  adoptChunks,
26
31
  animationOf,
32
+ batchKeyframes,
33
+ type BatchKeyframes,
34
+ type BatchSlot,
35
+ type BatchSpec,
27
36
  CHUNK_ATTRIBUTE,
28
37
  chunkStyle,
29
38
  delayOf,
30
39
  elapsedOf,
31
40
  find,
41
+ findAll,
32
42
  keyframes,
33
43
  type Keyframes,
34
44
  matches,
45
+ matchesBatch,
35
46
  MAX_SECONDS,
36
47
  nameOf,
37
- pending,
38
48
  type Play,
39
- PREFIX,
40
- release,
41
49
  sheet,
42
50
  type Sheet,
43
51
  type Slot,
44
52
  type Spec,
45
53
  } from "./internal/appear.ts"
54
+ export { pending, PREFIX, release } from "./internal/appear-slot.ts"
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The DOM's writer for a Batch: each moving member's `transform` and `opacity`, written onto its
3
+ * element's style as Wardic's renderer draws the same values. A Batch's keys on the DOM are the
4
+ * transform keys (`x`, `y`, `z`, `translateX/Y/Z`, `scale`, `scaleX/Y`, `rotate`, `rotateX/Y/Z`,
5
+ * `skewX/Y`) and `opacity`, as numbers. A server renders a member's start with `styleOf`, the strings
6
+ * the writer draws it with.
7
+ *
8
+ * @example
9
+ * import * as Batch from "@wardic/core/Batch"
10
+ * import * as DomBatch from "@wardic/dom/DomBatch"
11
+ *
12
+ * const grid = Batch.make({ keys: ["x", "y", "opacity"], writer: DomBatch.writer, transition: { type: "spring" } })
13
+ *
14
+ * @example
15
+ * import * as DomBatch from "@wardic/dom/DomBatch"
16
+ *
17
+ * DomBatch.styleOf({ x: 10, opacity: 0 }) // { transform: "translateX(10px)", opacity: "0" }
18
+ */
19
+ // `@wardic/dom/DomBatch` (#665, ADR-0070 *Amendment (#665)*): the DOM's implementation of core's
20
+ // `Batch.Writer`, Dom-prefixed as `DomRenderer` is, its member without the module's noun (ADR-0041).
21
+ // Not in `DomLive`: a binding's `createBatch` imports it, so an app that never makes a Batch ships none.
22
+ export { styleOf, writer } from "./internal/batch-writer.ts"
package/src/DomInput.ts CHANGED
@@ -15,8 +15,9 @@ export {
15
15
  InputDomLive as layer,
16
16
  keyOf,
17
17
  kindOf,
18
- makeFocusable,
19
18
  buttonOf,
20
19
  toPointer,
21
20
  type Where,
22
21
  } from "./internal/input.ts"
22
+ // The Keyboard press's own module's (#709): `KeyboardPress.makeFocusable`, the same function.
23
+ export { makeFocusable } from "./internal/keyboard-press.ts"
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A Keyboard press's focusability: `makeFocusable` gives an HTML element that doesn't take the
3
+ * keyboard's focus of itself `tabindex="0"`, so Enter and Space can press it, as Motion's press does. A
4
+ * control, a link with its `href`, an editable region, an element given a `tabindex` and an SVG element
5
+ * are left as they are. `DomInput.makeFocusable` is the same function, here apart from the DOM's input,
6
+ * so a binding calls it as each pressable element mounts without loading the input.
7
+ *
8
+ * @example
9
+ * import * as KeyboardPress from "@wardic/dom/KeyboardPress"
10
+ *
11
+ * const tile = document.createElement("div")
12
+ * KeyboardPress.makeFocusable(tile)
13
+ * // tile.getAttribute("tabindex") === "0"
14
+ */
15
+ // `@wardic/dom/KeyboardPress` (#709, Q2; ADR-0056, *Amendment (#709)*): ADR-0041's module per concern.
16
+ export { makeFocusable } from "./internal/keyboard-press.ts"
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * A Reorder group on the DOM: the group, its items' drags, its keyboard and its announcements, one
3
- * controller a group. `make` builds one over the context's Projection system and `Announcer`; a binding
4
- * attaches its group element, gets a driver for each item, and closing the Scope ends the controller. A
5
- * server render gets `inert`.
3
+ * controller a group. `make` builds one over the context's Projection system and `Announcer`, for items
4
+ * that are layout nodes; `makePlaced` one over the `Announcer` alone, for a Batch Reorder group's items,
5
+ * placed from their index and never measured. A binding attaches its group element, gets a driver for
6
+ * each item, and closing the Scope ends the controller. A server render gets `inert`.
6
7
  *
7
8
  * @example
8
9
  * import * as ReorderController from "@wardic/dom/ReorderController"
@@ -10,14 +11,21 @@
10
11
  * const controller = yield* ReorderController.make({ values: () => items, onReorder: (next) => (items = next) })
11
12
  * controller.attach(list)
12
13
  * const driver = controller.item(item, () => Option.some(element))
14
+ *
15
+ * // Items placed from their index: placed() once they're laid out in a new order.
16
+ * const placedGroup = yield* ReorderController.makePlaced({ values: () => items, onReorder: (next) => (items = next) })
17
+ * placedGroup.placed()
13
18
  */
14
19
  // A **Reorder group**'s controller (ADR-0019 *Amendment (Reorder)*, ADR-0037); a server render's `inert`
15
20
  // (ADR-0021). `@wardic/dom/ReorderController` (#132, ADR-0041). A scoped constructor, one per group (#132's
16
21
  // PR 3): `make` logs its `wardic.reorder:` events through the context's Logger, and ends with its Scope,
17
22
  // which stops its listening to Measure passes, resets its Auto-scroll and clears a pending announcement.
23
+ // `makePlaced` (#712, ADR-0072) is the same controller wired to its binding's placing: no projection system,
24
+ // and `placed` where `make`'s hears a Measure pass's end.
18
25
  // Its items' drivers stay plain, each with its own `dispose`, since one is made per element.
19
26
  import * as Announcer from "@wardic/core/Announcer"
20
27
  import * as Effect from "effect/Effect"
28
+ import { constVoid } from "effect/Function"
21
29
  import type * as Scope from "effect/Scope"
22
30
  import { PassEnds } from "./internal/pass-ends.ts"
23
31
  import * as internal from "./internal/reorder.ts"
@@ -30,6 +38,7 @@ export {
30
38
  type ReorderHoldHow as HoldHow,
31
39
  type ReorderHoldStart as HoldStart,
32
40
  type ReorderItemDriver as ItemDriver,
41
+ type ReorderItemHandle as ItemHandle,
33
42
  DEFAULT_REORDER_INSTRUCTIONS as DEFAULT_INSTRUCTIONS,
34
43
  REORDER_GROUP_STYLE as GROUP_STYLE,
35
44
  } from "./internal/reorder.ts"
@@ -57,13 +66,54 @@ export const make: <V>(options: Options<V>) => Effect.Effect<ReorderController<V
57
66
  const passEnds = yield* PassEnds
58
67
  const announcer = yield* Announcer.Announcer
59
68
  const controller = internal.makeReorderController(
60
- { runtime: yield* makeRunner<never>(), projection, announce: announcer.announce, onPassEnd: passEnds.onPassEnd },
69
+ { runtime: yield* makeRunner<never>(), layOut: () => projection.notify(), announce: announcer.announce, onLaidOut: passEnds.onPassEnd },
61
70
  options,
62
71
  )
63
72
  yield* Effect.addFinalizer(() => Effect.sync(controller.dispose))
64
73
  return controller
65
74
  })
66
75
 
76
+ /**
77
+ * A **Batch Reorder group**'s controller, whose items are placed from their index, never measured: `placed`
78
+ * tells it the binding has laid its items out in a new order, as a Measure pass's end tells `make`'s.
79
+ */
80
+ // #712, ADR-0072 decision 6.
81
+ export interface Placed<V> extends ReorderController<V> {
82
+ /** The binding has placed its items in the new order: their layout's turn, a stepped item revealed. */
83
+ readonly placed: () => void
84
+ }
85
+
86
+ /**
87
+ * Build a group's controller for items placed rather than measured, a Batch Reorder group's, announcing
88
+ * through the context's `Announcer`, in the current Scope: closing it ends the controller. It needs no
89
+ * projection system: each item registers a handle whose box is its place, raising its box's version as
90
+ * it's placed, and the binding calls `placed` once it has placed a new order.
91
+ */
92
+ // #712, ADR-0072 decision 6: the same controller, wired to its binding's placing.
93
+ export const makePlaced: <V>(options: Options<V>) => Effect.Effect<Placed<V>, never, Announcer.Announcer | Scope.Scope> = Effect.fnUntraced(
94
+ function* <V>(options: Options<V>) {
95
+ const announcer = yield* Announcer.Announcer
96
+ // What hears the binding's placing: the controller's own, once, until it's disposed.
97
+ let laidOut: () => void = constVoid
98
+ const controller = internal.makeReorderController(
99
+ {
100
+ runtime: yield* makeRunner<never>(),
101
+ // The binding places its items on a change of `values` itself.
102
+ layOut: constVoid,
103
+ announce: announcer.announce,
104
+ onLaidOut: (listener) => {
105
+ laidOut = listener
106
+ return () => {
107
+ laidOut = constVoid
108
+ }
109
+ },
110
+ },
111
+ options,
112
+ )
113
+ yield* Effect.addFinalizer(() => Effect.sync(controller.dispose))
114
+ return { ...controller, placed: () => laidOut() }
115
+ })
116
+
67
117
  /**
68
118
  * The controller a server render gets: its group has no values, so every operation on it does nothing,
69
119
  * its axis is `"y"`, and an item's driver does nothing too.
package/src/index.ts CHANGED
@@ -12,8 +12,8 @@
12
12
  * `DomInterpolators`, `DomPositionalKeys`, `DomDefaultTransition`), and `DomKeyRules`, the Key
13
13
  * rules `DomInterpolators.layer` installs, which has none of its own;
14
14
  * - dom's own concepts, by the glossary's names: `FlushGate`, `ProjectionSystem`,
15
- * `ReorderController`, `Style`, `Svg`, `Color`, `Variables`, `ScrollOffset`, `Appear`, `OwnValues`
16
- * and `Report`.
15
+ * `ReorderController`, `Style`, `Svg`, `Color`, `Variables`, `ScrollOffset`, `Appear`, `OwnValues`,
16
+ * `KeyboardPress` and `Report`.
17
17
  *
18
18
  * Everything under `internal/` is dom's own and not exported.
19
19
  */
@@ -38,8 +38,9 @@ import * as DomPositionalKeys from "./DomPositionalKeys.ts"
38
38
  import * as DomProbe from "./DomProbe.ts"
39
39
  import * as DomRenderer from "./DomRenderer.ts"
40
40
 
41
- export const VERSION = "1.0.0-rc.9"
41
+ export const VERSION = "1.0.0"
42
42
 
43
+ export * as DomBatch from "./DomBatch.ts"
43
44
  export * as DomClock from "./DomClock.ts"
44
45
  export * as DomInput from "./DomInput.ts"
45
46
  export * as DomProbe from "./DomProbe.ts"
@@ -61,6 +62,7 @@ export * as Variables from "./Variables.ts"
61
62
  export * as ScrollOffset from "./ScrollOffset.ts"
62
63
  export * as Appear from "./Appear.ts"
63
64
  export * as OwnValues from "./OwnValues.ts"
65
+ export * as KeyboardPress from "./KeyboardPress.ts"
64
66
  export * as Report from "./Report.ts"
65
67
 
66
68
  /**
@@ -0,0 +1,32 @@
1
+ /**
2
+ * An Appear animation's slot on its element (#48, ADR-0044), as a page's code reads it before any Handoff:
3
+ * whether the element's animation still runs, and the Handoff's last step, its removal. Kept apart from the
4
+ * sampler and the Handoff's reads (`appear.ts`), so code that only asks, or lets one go, ships neither: a
5
+ * Batch's, whose reads load at its first Handoff (#706, Q11).
6
+ *
7
+ * @module
8
+ */
9
+
10
+ /** The prefix every Appear rule's name starts with. */
11
+ export const PREFIX = "wardic-"
12
+
13
+ /** What a slot's inline `animation` starts with: `var(--wardic-a`. */
14
+ const SLOT_PREFIX = `var(--${PREFIX}a`
15
+
16
+ /**
17
+ * Whether `element`'s Appear animation is running, not yet handed over: its inline style still names its
18
+ * slot, which `release` removes. A layout measure asks it of each node, so a running animation's
19
+ * transform, which beats the inline one, stays out of the box it reads.
20
+ */
21
+ // #245: a Measure pass; a string read, no style resolved.
22
+ export const pending = (element: ElementCSSInlineStyle): boolean => element.style.getPropertyValue("animation").startsWith(SLOT_PREFIX)
23
+
24
+ /**
25
+ * The handover's last step: the element's inline `animation` removed, in the task that writes the
26
+ * engine's first frame, so no paint falls between. While it ran, its value beat the inline style the
27
+ * engine writes; removing it ends the CSS animation at that task's style update.
28
+ */
29
+ // The **Handoff** (ADR-0044, decision 6). A `cancel()` too changed nothing (a mutation, #48's PR 1).
30
+ export const release = (element: ElementCSSInlineStyle): void => {
31
+ element.style.removeProperty("animation")
32
+ }