@wardic/dom 1.0.0-rc.8 → 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 (86) 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.d.ts +7 -0
  50. package/dist/internal/measure.d.ts.map +1 -1
  51. package/dist/internal/measure.js +19 -1
  52. package/dist/internal/measure.js.map +1 -1
  53. package/dist/internal/projection.d.ts +13 -5
  54. package/dist/internal/projection.d.ts.map +1 -1
  55. package/dist/internal/projection.js +271 -33
  56. package/dist/internal/projection.js.map +1 -1
  57. package/dist/internal/renderer.d.ts +18 -0
  58. package/dist/internal/renderer.d.ts.map +1 -1
  59. package/dist/internal/renderer.js +4 -2
  60. package/dist/internal/renderer.js.map +1 -1
  61. package/dist/internal/reorder.d.ts +28 -13
  62. package/dist/internal/reorder.d.ts.map +1 -1
  63. package/dist/internal/reorder.js +55 -26
  64. package/dist/internal/reorder.js.map +1 -1
  65. package/dist/internal/reveal.d.ts +7 -3
  66. package/dist/internal/reveal.d.ts.map +1 -1
  67. package/dist/internal/reveal.js +8 -3
  68. package/dist/internal/reveal.js.map +1 -1
  69. package/package.json +4 -4
  70. package/src/Appear.ts +12 -3
  71. package/src/DomBatch.ts +22 -0
  72. package/src/DomInput.ts +2 -1
  73. package/src/KeyboardPress.ts +16 -0
  74. package/src/ReorderController.ts +54 -4
  75. package/src/index.ts +5 -3
  76. package/src/internal/appear-slot.ts +32 -0
  77. package/src/internal/appear.ts +462 -67
  78. package/src/internal/batch-writer.ts +95 -0
  79. package/src/internal/gate.ts +7 -3
  80. package/src/internal/input.ts +209 -25
  81. package/src/internal/keyboard-press.ts +45 -0
  82. package/src/internal/measure.ts +17 -1
  83. package/src/internal/projection.ts +272 -38
  84. package/src/internal/renderer.ts +4 -2
  85. package/src/internal/reorder.ts +85 -39
  86. package/src/internal/reveal.ts +10 -4
@@ -1 +1 @@
1
- {"version":3,"file":"appear.d.ts","sourceRoot":"","sources":["../../src/internal/appear.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAA;AAE/C,OAAO,KAAK,KAAK,MAAM,MAAM,qBAAqB,CAAA;AAGlD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,EAAsC,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAG1F,iEAAiE;AACjE,MAAM,WAAW,IAAI;IACnB;;;;OAIG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,yGAAyG;IAEzG,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACtE,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IACvC,wGAAwG;IAExG,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IACxC;;;;OAIG;IAEH,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAA;CAClD;AAED,kCAAkC;AAClC,MAAM,WAAW,SAAS;IACxB,sDAAsD;IACtD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,iGAA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I3C,CAAA"}
@@ -9,16 +9,20 @@
9
9
  * - **A sheet** collects one render's rules. An element's inline style names only a custom
10
10
  * property, `animation: var(--wardic-aN)`, which the sheet defines in `:root` once the render
11
11
  * knows its timing (decision 5); undefined, it leaves the element at its Starting style.
12
- * - **The Handoff's reads:** the element's `wardic-…` animation, how far it has got, and its
13
- * removal, written in the same task as the engine's first frame (decision 6).
12
+ * - **The Handoff's reads:** the element's `wardic-…` animation and how far it has got. Its removal,
13
+ * written in the same task as the engine's first frame (decision 6), is `appear-slot.ts`'s, with
14
+ * `pending`: what a page's code asks before any Handoff, kept out of this module.
14
15
  *
15
16
  * @module
16
17
  */
18
+ import * as Batch from "@wardic/core/Batch";
17
19
  import * as BaseValue from "@wardic/core/BaseValue";
18
20
  import * as Machine from "@wardic/core/Machine";
19
21
  import * as Projection from "@wardic/core/Projection";
20
22
  import * as Arr from "effect/Array";
21
23
  import * as Bool from "effect/Boolean";
24
+ import { identity } from "effect/Function";
25
+ import * as Match from "effect/Match";
22
26
  import * as Option from "effect/Option";
23
27
  import * as Order from "effect/Order";
24
28
  import * as Predicate from "effect/Predicate";
@@ -26,13 +30,12 @@ import * as Rec from "effect/Record";
26
30
  import * as Result from "effect/Result";
27
31
  import * as UndefinedOr from "effect/UndefinedOr";
28
32
  import { spacesRegistered } from "./colors.js";
29
- import { drawnUnitOf, project, TEMPLATE_KEY } from "./renderer.js";
33
+ import { drawnUnitOf, project, TEMPLATE_KEY, TRANSFORM_FUNCS, unitOf } from "./renderer.js";
34
+ import { PREFIX } from "./appear-slot.js";
30
35
  import { dashCase, isPathKey, isSvgInnerTag, splitPatchForTag, svgAttrNameOf } from "./svg.js";
31
- /** The prefix every Appear rule's name starts with. */
32
- export const PREFIX = "wardic-";
33
36
  /** The longest mount animation sampled, in seconds; a longer one keeps its Starting style. */
34
37
  export const MAX_SECONDS = 60;
35
- const MAX_STEPS = Math.round(MAX_SECONDS / Machine.CATCH_UP_DT);
38
+ const MAX_STEPS = /*#__PURE__*/ Math.round(MAX_SECONDS / Machine.CATCH_UP_DT);
36
39
  // --- The spec's name ---------------------------------------------------------------------------
37
40
  /** cyrb53, a 53-bit string hash: plenty for a page's specs, and the same in every engine. */
38
41
  const hash53 = (text) => {
@@ -46,7 +49,7 @@ const hash53 = (text) => {
46
49
  };
47
50
  /** Each spec's name by its text, so a page's elements sharing a spec hash it once; the oldest dropped past `NAMES_SIZE`. */
48
51
  // Module state (#460, Q7): a cache keyed by what it caches: a bounded set of names.
49
- const names = new Map();
52
+ const names = /*#__PURE__*/ new Map();
50
53
  const NAMES_SIZE = 4096;
51
54
  /** The rule's name for a spec: its key, tag, repeat and projection, hashed. */
52
55
  // Once a text: a server names each element's spec.
@@ -70,14 +73,20 @@ const specTextOf = (spec) => `${UndefinedOr.match(spec.tag, { onUndefined: () =>
70
73
  */
71
74
  const framesOf = (machine) => {
72
75
  const step = machine.start();
73
- const copy = (frame) => ({ values: { ...frame.value }, done: frame.done });
74
76
  // Copied before the next step, which may rewrite it.
75
- const first = copy(step(0));
76
- const rest = Arr.unfold({ frame: first, steps: 0 }, ({ frame, steps }) => Bool.match(frame.done || steps >= MAX_STEPS, {
77
+ const copy = (frame) => ({ values: { ...frame.value }, done: frame.done });
78
+ return unfoldFrames(copy(step(0)), () => copy(step(Machine.CATCH_UP_DT)));
79
+ };
80
+ /**
81
+ * A series' values from its first sample and each next one, 1/60 s on, to the one that settles: `None`
82
+ * past `MAX_SECONDS`. An element's machine's (`framesOf`) and a Batch's (#706).
83
+ */
84
+ const unfoldFrames = (first, next) => {
85
+ const rest = Arr.unfold({ frame: first, steps: 0 }, ({ frame, steps }) => Bool.match(Bool.or(frame.done, steps >= MAX_STEPS), {
77
86
  onTrue: () => Option.none(),
78
87
  onFalse: () => {
79
- const next = copy(step(Machine.CATCH_UP_DT));
80
- return Option.some([next, { frame: next, steps: steps + 1 }]);
88
+ const sampled = next();
89
+ return Option.some([sampled, { frame: sampled, steps: steps + 1 }]);
81
90
  },
82
91
  }));
83
92
  const frames = Arr.prepend(rest, first);
@@ -128,7 +137,7 @@ const bareTolerance = (key) => Bool.match(drawnUnitOf(key) === "", {
128
137
  onFalse: () => 0.1,
129
138
  });
130
139
  /** The opacities an svg-inner element draws as attributes, judged as opacity is. */
131
- const SVG_OPACITIES = new Set(["opacity", "fillOpacity", "strokeOpacity", "stopOpacity", "floodOpacity"]);
140
+ const SVG_OPACITIES = /*#__PURE__*/ new Set(["opacity", "fillOpacity", "strokeOpacity", "stopOpacity", "floodOpacity"]);
132
141
  /**
133
142
  * A bare number's tolerance on an svg-inner element (#245), by what its attribute means: a
134
143
  * normalised dash (`pathLength`, `pathOffset`, `pathSpacing`: 0 to 1 of the path) 0.001, an
@@ -206,6 +215,8 @@ export const thin = (frames, tag) => {
206
215
  };
207
216
  /** A number written to at most four decimals, `-0` as `0`: finer than any tolerance, and short. */
208
217
  const trimNumbers = (text) => text.replace(/-?(?:\d+\.\d+|\.\d+)(?:e[-+]?\d+)?|-?\d+e[-+]?\d+/gi, (token) => String(Number(Number(token).toFixed(4)) + 0));
218
+ /** A number for a rule's text: at most four decimals, as every stop's. */
219
+ const numberText = (value) => trimNumbers(String(value));
209
220
  /** Text CSS can't hold inside a declaration, or that would end the `<style>` it sits in. */
210
221
  const UNSAFE = /[<>{};]|\/\*|\\/;
211
222
  /**
@@ -213,7 +224,7 @@ const UNSAFE = /[<>{};]|\/\*|\\/;
213
224
  * presentation attributes, which a stylesheet's or an animation's value overrides, so the attribute
214
225
  * the engine writes at the Handoff takes over value for value. Unitless, as the attribute is.
215
226
  */
216
- const SVG_PRESENTATION = new Set([
227
+ const SVG_PRESENTATION = /*#__PURE__*/ new Set([
217
228
  "opacity",
218
229
  "fill",
219
230
  "stroke",
@@ -233,9 +244,9 @@ const SVG_PRESENTATION = new Set([
233
244
  * `@supports (width: 0px)` holds for HTML in every browser, so it can't tell whether one draws a
234
245
  * `<rect>`'s from CSS.
235
246
  */
236
- const SVG_GEOMETRY = new Set(["cx", "cy", "r", "rx", "ry", "x", "y"]);
247
+ const SVG_GEOMETRY = /*#__PURE__*/ new Set(["cx", "cy", "r", "rx", "ry", "x", "y"]);
237
248
  /** The attribute the stroke dash writes beside it, `pathLength="1"`: the Starting style writes it too, and it never changes. */
238
- const SVG_FIXED = new Set(["pathLength"]);
249
+ const SVG_FIXED = /*#__PURE__*/ new Set(["pathLength"]);
239
250
  const BARE_NUMBER = /^-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i;
240
251
  /** An SVG attribute's declaration: a geometry property's bare number in px, what a user unit is. */
241
252
  const attributeDeclaration = ([name, value]) => `${name}:${trimNumbers(Bool.match(Bool.and(SVG_GEOMETRY.has(name), BARE_NUMBER.test(value)), { onTrue: () => `${value}px`, onFalse: () => value }))}`;
@@ -271,33 +282,46 @@ const percentOf = (stop, last) => `${String(Number(Bool.match(last === 0, { onTr
271
282
  */
272
283
  const JUMP_AT = 0.5;
273
284
  const JUMP_TAKES = 0.001;
285
+ /**
286
+ * A sampled series' stops (decision 9): each one `thin` keeps, and at a jump, the Frame before it held to
287
+ * halfway, then its own; the end drawn as the settled Frame. An element's rule's and a Batch's.
288
+ */
289
+ const stopsOf = (frames, tag) => {
290
+ const last = frames.length - 1;
291
+ const { kept, end, jumps } = thin(frames, tag);
292
+ /** A kept stop's Frame: the end drawn as the settled Frame. */
293
+ const frameAt = (stop) => frames[Bool.match(stop === end, { onTrue: () => last, onFalse: () => stop })];
294
+ const stops = Arr.flatMap(kept, (stop) => Bool.match(Arr.contains(jumps, stop), {
295
+ onTrue: () => [
296
+ { offset: stop - JUMP_AT, frame: frames[stop - 1] },
297
+ { offset: stop - JUMP_AT + JUMP_TAKES, frame: frameAt(stop) },
298
+ { offset: stop, frame: frameAt(stop) },
299
+ ],
300
+ onFalse: () => [{ offset: stop, frame: frameAt(stop) }],
301
+ }));
302
+ return { stops, kept, end, last };
303
+ };
304
+ /** A rule's timing from its stops: how long it plays, when it settles, each stop's time. */
305
+ const timingOf = (series) => ({
306
+ duration: series.end * Machine.CATCH_UP_DT,
307
+ settled: series.last * Machine.CATCH_UP_DT,
308
+ times: Arr.map(series.kept, (stop) => stop * Machine.CATCH_UP_DT),
309
+ });
310
+ /** A rule's body: each stop's offset and its declarations, one stop of `0%,100%` for a rule that settles at once. */
311
+ const bodyOf = ({ stops, end }, texts) => Arr.map(Bool.match(end === 0, { onTrue: () => ["0%,100%"], onFalse: () => Arr.map(stops, ({ offset }) => percentOf(offset, end)) }), (offset, i) => `${offset}{${texts[i]}}`).join("");
274
312
  /** A spec sampled into its rule, or why it can't be one. Not cached: {@link keyframes} is. */
275
313
  const sample = (spec) => Option.match(framesOf(spec.machine()), {
276
314
  onNone: () => Result.fail(`longer than ${MAX_SECONDS} s`),
277
315
  onSome: (frames) => {
278
- const last = frames.length - 1;
279
316
  const projected = spec.projected === true;
280
- const { kept, end, jumps } = thin(frames, spec.tag);
281
- /** A kept stop's Frame: the end drawn as the settled Frame. */
282
- const frameAt = (stop) => frames[Bool.match(stop === end, { onTrue: () => last, onFalse: () => stop })];
283
- // The rule's stops: each kept one, and at a jump, the Frame before it held to halfway, then its own.
284
- const stops = Arr.flatMap(kept, (stop) => Bool.match(Arr.contains(jumps, stop), {
285
- onTrue: () => [
286
- { offset: stop - JUMP_AT, frame: frames[stop - 1] },
287
- { offset: stop - JUMP_AT + JUMP_TAKES, frame: frameAt(stop) },
288
- { offset: stop, frame: frameAt(stop) },
289
- ],
290
- onFalse: () => [{ offset: stop, frame: frameAt(stop) }],
291
- }));
292
- return Result.map(Result.all(Arr.map(stops, ({ frame }) => declarationsOf(spec.tag, frame, projected, spec.template))), (declarations) => {
293
- const body = Arr.map(Bool.match(end === 0, { onTrue: () => ["0%,100%"], onFalse: () => Arr.map(stops, ({ offset }) => percentOf(offset, end)) }), (offset, i) => `${offset}{${declarations[i].text}}`).join("");
317
+ const series = stopsOf(frames, spec.tag);
318
+ return Result.map(Result.all(Arr.map(series.stops, ({ frame }) => declarationsOf(spec.tag, frame, projected, spec.template))), (declarations) => {
319
+ const body = bodyOf(series, Arr.map(declarations, (d) => d.text));
294
320
  const name = ruleNameOf(spec, body);
295
321
  return {
296
322
  name,
297
- duration: end * Machine.CATCH_UP_DT,
298
- settled: last * Machine.CATCH_UP_DT,
323
+ ...timingOf(series),
299
324
  infinite: spec.infinite === true,
300
- times: Arr.map(kept, (stop) => stop * Machine.CATCH_UP_DT),
301
325
  css: `@keyframes ${name}{${body}}`,
302
326
  supports: supportsOf(Arr.flatMap(declarations, (d) => d.supports)),
303
327
  };
@@ -321,7 +345,7 @@ const conditionOf = (properties) => Arr.map(properties, (property) => `(${proper
321
345
  * registered when it was (#511); the oldest dropped past `CACHE_SIZE`.
322
346
  */
323
347
  // Module state (#460, Q7): a cache keyed by what it caches: each mount animation's sampled keyframes, by its text.
324
- const cache = new Map();
348
+ const cache = /*#__PURE__*/ new Map();
325
349
  const CACHE_SIZE = 512;
326
350
  /**
327
351
  * A spec's rule, or why it has none, for a debug log. Sampled once a spec and cached across requests by
@@ -340,10 +364,15 @@ export const keyframes = (spec) => {
340
364
  if (Predicate.isNotUndefined(kept) && kept.spaces === spaces)
341
365
  return kept.rule;
342
366
  const sampled = sample(spec);
343
- Option.map(Arr.head(Arr.take(Array.from(cache.keys()), Math.max(0, cache.size + 1 - CACHE_SIZE))), (oldest) => cache.delete(oldest));
344
- cache.set(name, { spaces, rule: sampled });
367
+ remember(cache, name, { spaces, rule: sampled });
345
368
  return sampled;
346
369
  };
370
+ /** `value` kept in `kept` by `name`, the oldest dropped past `CACHE_SIZE`: each rule cache's. */
371
+ const remember = (kept, name, value) => {
372
+ Option.map(Arr.head(Arr.take(Array.from(kept.keys()), Math.max(0, kept.size + 1 - CACHE_SIZE))), (oldest) => kept.delete(oldest));
373
+ kept.set(name, value);
374
+ return value;
375
+ };
347
376
  /**
348
377
  * An element's `animation` value for a play of `rule`: its name, length, delay and repeat, filling
349
378
  * forwards. Not backwards: through its delay the element shows its inline starting style, which is the
@@ -351,7 +380,180 @@ export const keyframes = (spec) => {
351
380
  */
352
381
  // And the start a reduced rule's snap holds until the delay ends (ADR-0029), where the first stop is
353
382
  // already snapped.
354
- export const animationOf = (rule, delay) => `${rule.name} ${trimNumbers(String(rule.duration))}s linear ${trimNumbers(String(delay))}s ${Bool.match(rule.infinite, { onTrue: () => "infinite", onFalse: () => "1" })} forwards`;
383
+ export const animationOf = (rule, delay) => `${rule.name} ${numberText(rule.duration)}s linear ${numberText(delay)}s ${Bool.match(rule.infinite, { onTrue: () => "infinite", onFalse: () => "1" })} forwards`;
384
+ /** The prefix a Batch rule's name starts with, from its spec's `key`: what a client checks. */
385
+ const batchPrefixOf = (key) => `${PREFIX}b${hash53(key)}-`;
386
+ /** The transform functions a Batch draws, in the renderer's order: its writer's, less a path's turn. */
387
+ const BATCH_FUNCS = /*#__PURE__*/ Arr.filter(TRANSFORM_FUNCS, (func) => func.key !== "pathRotation");
388
+ /** Whether every member that moves starts at one value and ends at one: the rule writes the key as it is. */
389
+ const isShared = (column) => Bool.and(column.sharedStart, column.sharedTarget);
390
+ /** The custom property for a key's start (`0`) or target (`1`). */
391
+ const propertyOf = (key, end) => `--${PREFIX}${key}${end}`;
392
+ /** A key's value with its unit: `120px`, `45deg`, `0.8`. */
393
+ const unitText = (column, value) => `${numberText(value)}${column.unit}`;
394
+ /** A progress, 0 to 1, for a `calc()`: five decimals, a 0.03 px miss at a move of 4,096 px; `-0` as `0`, as `trimNumbers`. */
395
+ const progressText = (p) => String(Number(p.toFixed(5)) + 0);
396
+ /** What a stop writes for a key whose members' values differ: the shortest form for where it is. */
397
+ const ownText = /*#__PURE__*/ Match.type().pipe(Match.when(({ column }) => Bool.not(column.moves), ({ target }) => target), Match.when(({ p }) => p === 0, ({ start }) => start), Match.when(({ p }) => p === 1, ({ target }) => target), Match.when(({ column }) => Bool.and(column.sharedStart, column.start === 0), ({ p, target }) => `calc(${target} * ${progressText(p)})`), Match.when(({ column }) => Bool.and(column.sharedTarget, column.target === 0), ({ p, start }) => `calc(${start} * ${progressText(1 - p)})`), Match.orElse(({ p, start, target }) => `calc(${start} + (${target} - ${start}) * ${progressText(p)})`));
398
+ /** What a stop writes for a key, from its sampled value: a shared one as it is, an own one as its progress. */
399
+ const valueText = (column, frame) => {
400
+ const value = UndefinedOr.match(frame[column.key], { onUndefined: () => column.target, onDefined: identity });
401
+ return Bool.match(isShared(column), {
402
+ onTrue: () => unitText(column, value),
403
+ onFalse: () => ownText({
404
+ column,
405
+ p: value / column.span,
406
+ start: Bool.match(column.sharedStart, { onTrue: () => unitText(column, column.start), onFalse: () => `var(${propertyOf(column.key, 0)})` }),
407
+ target: Bool.match(column.sharedTarget, { onTrue: () => unitText(column, column.target), onFalse: () => `var(${propertyOf(column.key, 1)})` }),
408
+ }),
409
+ });
410
+ };
411
+ /** The power of two at or above `move`: a span shared by Batches whose longest moves are near. */
412
+ const spanOf = (move) => 2 ** Math.ceil(Math.log2(move));
413
+ /** Whether a member moves: some key's start isn't its target. */
414
+ const moves = (start, target) => Arr.some(start, (s, k) => s !== target[k]);
415
+ /** The members that move: one that plays nothing shares nothing with the rule. */
416
+ const moversOf = (spec) => {
417
+ const moving = Arr.filter(Arr.range(0, spec.starts.length - 1), (m) => moves(spec.starts[m], spec.targets[m]));
418
+ return {
419
+ starts: Arr.map(moving, (m) => spec.starts[m]),
420
+ targets: Arr.map(moving, (m) => spec.targets[m]),
421
+ };
422
+ };
423
+ /** Each of the spec's keys as a rule writes it, from the members that move. */
424
+ const columnsOf = (keys, movers) => Arr.map(keys, (key, k) => {
425
+ const starts = Arr.map(movers.starts, (start) => start[k]);
426
+ const targets = Arr.map(movers.targets, (target) => target[k]);
427
+ const start = UndefinedOr.match(starts[0], { onUndefined: () => 0, onDefined: identity });
428
+ const target = UndefinedOr.match(targets[0], { onUndefined: () => 0, onDefined: identity });
429
+ const longest = Math.max(0, ...Arr.map(starts, (s, m) => Math.abs(targets[m] - s)));
430
+ return {
431
+ key,
432
+ k,
433
+ unit: Bool.match(key === "opacity", { onTrue: () => "", onFalse: () => unitOf(key) }),
434
+ moves: longest > 0,
435
+ sharedStart: Arr.every(starts, (s) => s === start),
436
+ sharedTarget: Arr.every(targets, (t) => t === target),
437
+ start,
438
+ target,
439
+ span: Bool.match(longest > 0, { onTrue: () => spanOf(longest), onFalse: () => 1 }),
440
+ };
441
+ });
442
+ /**
443
+ * The columns a rule writes: `opacity` when it moves; and when any transform key moves, every transform
444
+ * key off its identity for some member, in the renderer's order, since the rule's `transform` replaces the
445
+ * element's whole.
446
+ */
447
+ const writtenOf = (movers, columns) => {
448
+ const byKey = new Map(Arr.map(columns, (column) => [column.key, column]));
449
+ const transform = Arr.filterMap(BATCH_FUNCS, (func) => Option.match(Option.fromUndefinedOr(byKey.get(func.key)), {
450
+ onNone: () => Result.failVoid,
451
+ onSome: (column) => {
452
+ const off = (value) => value[column.k] !== func.identity;
453
+ return Bool.match(Bool.or(Arr.some(movers.starts, off), Arr.some(movers.targets, off)), {
454
+ onTrue: () => Result.succeed({ ...column, fn: func.fn }),
455
+ onFalse: () => Result.failVoid,
456
+ });
457
+ },
458
+ }));
459
+ return {
460
+ transform: Bool.match(Arr.some(transform, (column) => column.moves), { onTrue: () => transform, onFalse: () => [] }),
461
+ opacity: Option.filter(Option.fromUndefinedOr(byKey.get("opacity")), (column) => column.moves),
462
+ };
463
+ };
464
+ /** A writer that draws nothing: the sampler reads a Batch's values, not its writes. */
465
+ const UNDRAWN = { writes: () => true, forKeys: () => () => undefined };
466
+ /**
467
+ * The Batch's own frames for its moving keys, at 0, 1/60 s, 2/60 s… to rest: one member from each key's
468
+ * shared start to its shared target, or from 0 to its span, stepped as a client's Batch steps it. `None`
469
+ * past `MAX_SECONDS`.
470
+ */
471
+ const batchFramesOf = (spec, columns) => {
472
+ const moving = Arr.filter(columns, (column) => column.moves);
473
+ const batch = Batch.make({ keys: spec.keys, writer: UNDRAWN, transition: spec.transition });
474
+ const slot = Batch.enter(batch, null, Rec.fromEntries(Arr.map(moving, (column) => [column.key, Bool.match(isShared(column), { onTrue: () => column.start, onFalse: () => 0 })])));
475
+ const targets = Arr.map(columns, (column) => Bool.match(column.moves, {
476
+ onTrue: () => Bool.match(isShared(column), { onTrue: () => column.target, onFalse: () => column.span }),
477
+ onFalse: () => Number.NaN,
478
+ }));
479
+ Batch.retarget(batch, [slot], (_, k) => targets[k]);
480
+ // Each step's values, and whether the Batch rests after it; the first at 0 s, as `framesOf`'s.
481
+ const after = (done) => ({ values: Rec.fromEntries(Arr.map(moving, (column) => [column.key, Batch.get(batch, slot, column.key)])), done });
482
+ return unfoldFrames(after(Batch.step(batch, 0)), () => after(Batch.step(batch, Machine.CATCH_UP_DT)));
483
+ };
484
+ /**
485
+ * A Batch's rule's name: its key's hash, then the hash of what it writes and how: each key's shared start
486
+ * and target, written into it, and an own key's span. Members' own values aren't in it, so Batches whose
487
+ * members differ but whose longest moves share a span share a rule.
488
+ */
489
+ const batchNameOf = (spec, columns) => {
490
+ const shape = Arr.map(columns, (column) => {
491
+ const start = Bool.match(column.sharedStart, { onTrue: () => String(column.start), onFalse: () => "*" });
492
+ const target = Bool.match(column.sharedTarget, { onTrue: () => String(column.target), onFalse: () => "*" });
493
+ return `${column.key}:${column.moves}:${start}:${target}:${column.span}`;
494
+ }).join("|");
495
+ return `${batchPrefixOf(spec.key)}${hash53(`${spec.keys.join(",")}|${shape}`)}`;
496
+ };
497
+ /** The Batch rules sampled so far, across requests, by name (as {@link keyframes}' cache): each member's own values aren't in them. */
498
+ // Module state (#460, Q7): a cache keyed by what it caches.
499
+ const batchCache = /*#__PURE__*/ new Map();
500
+ /** A spec's first key with a start or target that isn't a finite number: a rule can't write it. */
501
+ const unfiniteKeyOf = (spec) => Arr.findFirst(spec.keys, (_, k) => Arr.some(Arr.appendAll(spec.starts, spec.targets), (values) => Bool.not(Number.isFinite(values[k]))));
502
+ /**
503
+ * A Batch's rule for its members' entrance, or why it has none: one `@keyframes` for every member, each
504
+ * key's stops sampled from the Batch's own spring or tween at 60 Hz and thinned within its tolerance at
505
+ * its longest move. A key whose start and target every member that moves shares is written as it is;
506
+ * one whose values differ, as each member's custom properties and its progress between them.
507
+ */
508
+ // #706, Q2 A. Sampled once a shape a process, as an element's spec is.
509
+ export const batchKeyframes = (spec) => {
510
+ const unfinite = unfiniteKeyOf(spec);
511
+ if (Option.isSome(unfinite))
512
+ return Result.fail(`a start or target that isn't a finite number (${unfinite.value})`);
513
+ const movers = moversOf(spec);
514
+ const columns = columnsOf(spec.keys, movers);
515
+ const written = writtenOf(movers, columns);
516
+ if (Bool.and(Arr.isReadonlyArrayEmpty(written.transform), Option.isNone(written.opacity)))
517
+ return Result.fail("no key moves");
518
+ const name = batchNameOf(spec, columns);
519
+ const rule = Option.getOrElse(Option.fromUndefinedOr(batchCache.get(name)), () => remember(batchCache, name, sampleBatch(spec, columns, written, name)));
520
+ const own = Arr.filter(Arr.appendAll(written.transform, Option.toArray(written.opacity)), (column) => Bool.not(isShared(column)));
521
+ return Result.map(rule, (keyframes) => ({
522
+ ...keyframes,
523
+ memberStyle: (member) => {
524
+ const start = spec.starts[member];
525
+ const target = spec.targets[member];
526
+ return Bool.match(moves(start, target), {
527
+ onFalse: () => undefined,
528
+ onTrue: () => Rec.fromEntries(Arr.flatMap(own, (column) => [
529
+ ...Bool.match(Bool.and(column.moves, Bool.not(column.sharedStart)), { onTrue: () => [[propertyOf(column.key, 0), unitText(column, start[column.k])]], onFalse: () => [] }),
530
+ ...Bool.match(column.sharedTarget, { onTrue: () => [], onFalse: () => [[propertyOf(column.key, 1), unitText(column, target[column.k])]] }),
531
+ ])),
532
+ });
533
+ },
534
+ }));
535
+ };
536
+ /** A Batch's rule sampled, or why it can't be. Not cached: {@link batchKeyframes} is. */
537
+ const sampleBatch = (spec, columns, written, name) => Option.match(batchFramesOf(spec, columns), {
538
+ onNone: () => Result.fail(`longer than ${MAX_SECONDS} s`),
539
+ onSome: (frames) => {
540
+ const series = stopsOf(frames, undefined);
541
+ const texts = Arr.map(series.stops, ({ frame }) => {
542
+ const transform = Arr.map(written.transform, (column) => `${column.fn}(${valueText(column, frame)})`).join(" ");
543
+ const declarations = Arr.appendAll(Bool.match(transform === "", { onTrue: () => [], onFalse: () => [`transform:${transform}`] }), Option.toArray(Option.map(written.opacity, (column) => `opacity:${valueText(column, frame)}`)));
544
+ return declarations.join(";");
545
+ });
546
+ const body = bodyOf(series, texts);
547
+ return Result.succeed({ name, ...timingOf(series), infinite: false, css: `@keyframes ${name}{${body}}`, supports: [] });
548
+ },
549
+ });
550
+ /**
551
+ * A Batch slot's `animation`, less a delay: each member's inline `animation` names the slot and gives its
552
+ * own after it, `var(--wardic-aN) 0.035s`, the shorthand's second time. A delay here too would be a third,
553
+ * and the member's `animation` invalid: it would keep its start.
554
+ */
555
+ // #706, Q2 and Q6: one `:root` line a rule group, which reduced motion's media query switches; a member's stagger its own.
556
+ const slotAnimationOf = (rule) => `${rule.name} ${numberText(rule.duration)}s linear 1 forwards`;
355
557
  /** A block's declarations added under its condition. */
356
558
  const addTo = (blocks, condition, line) => {
357
559
  Option.match(Option.fromUndefinedOr(blocks.get(condition)), {
@@ -372,13 +574,36 @@ export const sheet = () => {
372
574
  const written = new Set();
373
575
  const blocks = new Map();
374
576
  const reducedBlocks = new Map();
375
- /** A play's rule added to the sheet: its `animation` value, and the geometry properties it writes. */
376
- const animationFor = (play) => Result.map(keyframes(play.spec), (rule) => {
577
+ /** A rule added to the sheet, unless it has been written. */
578
+ const add = (rule) => {
377
579
  if (Bool.not(written.has(rule.name)))
378
580
  rules.set(rule.name, rule.css);
581
+ };
582
+ /** A play's rule added to the sheet: its `animation` value, and the geometry properties it writes. */
583
+ const animationFor = (play) => Result.map(keyframes(play.spec), (rule) => {
584
+ add(rule);
379
585
  return { animation: animationOf(rule, play.delay), supports: rule.supports };
380
586
  });
381
587
  return {
588
+ batch: (play, reduced) => {
589
+ const property = `--${PREFIX}a${slots++}`;
590
+ add(play);
591
+ addTo(blocks, "", `${property}:${slotAnimationOf(play)}`);
592
+ UndefinedOr.map(reduced, (rule) => {
593
+ add(rule);
594
+ addTo(reducedBlocks, "", `${property}:${slotAnimationOf(rule)}`);
595
+ });
596
+ return {
597
+ styleOf: (member, delay) => UndefinedOr.map(play.memberStyle(member), (own) => {
598
+ // Once a member a render, on a server: its own values (both rules', which read the same), and the
599
+ // slot with its delay after it, the shorthand's second time: a longhand after a `var()` shorthand
600
+ // leaves the inline `animation` unreadable, which `pending` reads.
601
+ const reducedOwn = UndefinedOr.match(reduced, { onUndefined: () => ({}), onDefined: (rule) => rule.memberStyle(member) });
602
+ const wait = Bool.match(delay === 0, { onTrue: () => "", onFalse: () => ` ${numberText(delay)}s` });
603
+ return { ...own, ...reducedOwn, animation: `var(${property})${wait}` };
604
+ }),
605
+ };
606
+ },
382
607
  slot: () => {
383
608
  const property = `--${PREFIX}a${slots++}`;
384
609
  return {
@@ -427,7 +652,7 @@ export const chunkStyle = (css, nonce) => {
427
652
  const escapeAttribute = (value) => value.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;");
428
653
  /** The documents {@link adoptChunks} watches, or has: one observer a document. */
429
654
  // Module state (#460, Q7): the documents already watched, held weakly.
430
- const watched = new WeakSet();
655
+ const watched = /*#__PURE__*/ new WeakSet();
431
656
  /**
432
657
  * Moves each late chunk's Appear rules into the head: its `<style data-wardic-appear-chunk>`'s text into a
433
658
  * head `<style>`, then the node out, before the chunk hydrates, since a hydrating client expects no node it
@@ -460,14 +685,48 @@ export const adoptChunks = (doc) => {
460
685
  // --- The Handoff -------------------------------------------------------------------------------
461
686
  /** A `CSSAnimation`'s name, where the animation has one. */
462
687
  const nameOfAnimation = (animation) => Option.filter(Option.some(animation.animationName), Predicate.isString);
463
- /** The element's Appear animation: its `wardic-…` CSS animation, running, or finished and filling. */
688
+ /** Whether `animation` is an Appear one: a `wardic-…` CSS animation. */
689
+ const isAppearAnimation = (animation) => Option.exists(nameOfAnimation(animation), (name) => name.startsWith(PREFIX));
690
+ /**
691
+ * Whether `name` is a Batch's rule's (#706): `wardic-b<key>-<shape>`, two hashes, where an element's is
692
+ * `wardic-<hash>`, one, and a hash has no `-`.
693
+ */
694
+ const isBatchRuleName = (name) => name.includes("-", PREFIX.length);
695
+ /** Whether `animation` is an element's own Appear one: a `wardic-…` CSS animation, not a Batch's rule. */
696
+ const isElementAppearAnimation = (animation) => Option.exists(nameOfAnimation(animation), (name) => Bool.and(name.startsWith(PREFIX), Bool.not(isBatchRuleName(name))));
697
+ /** The element an animation draws, where it has one. */
698
+ const targetOf = (animation) => Option.flatMap(Option.fromNullishOr(animation.effect), (effect) => Option.fromNullishOr(effect.target));
699
+ /**
700
+ * The element's Appear animation: its `wardic-…` CSS animation, running, or finished and filling. A
701
+ * Batch's rule on a member's element isn't one (#706): its Batch takes it over, not a Wardic element there.
702
+ */
464
703
  // ADR-0044, decision 6.
465
704
  export const find = (element) => Bool.match(Predicate.hasProperty(element, "getAnimations"), {
466
705
  onFalse: () => Option.none(),
467
- onTrue: () => Arr.findFirst(element.getAnimations(), (animation) => Option.exists(nameOfAnimation(animation), (name) => name.startsWith(PREFIX))),
706
+ onTrue: () => Arr.findFirst(element.getAnimations(), isElementAppearAnimation),
468
707
  });
708
+ /**
709
+ * A document's Appear animations by element, running or finished and filling: one `getAnimations()` for
710
+ * the page, for a Handoff of many elements at once, a Batch's members (#706). Each element's first: a
711
+ * member's Batch rule, or the one `find` gets.
712
+ */
713
+ // #706, Q3: measured at a Batch's 1,000 members in one list, Chromium's `Element.getAnimations()` cost
714
+ // about a whole document's each (5.6 s for every member; the document's, 5.6 ms); Firefox's, alike either way.
715
+ export const findAll = (doc) => {
716
+ const byElement = new Map();
717
+ if (Bool.not(Predicate.hasProperty(doc, "getAnimations")))
718
+ return byElement;
719
+ // Once a Handoff, over the page's animations: the first per element, as `find`'s.
720
+ Arr.forEach(Arr.filter(doc.getAnimations(), isAppearAnimation), (animation) => Option.map(Option.filter(targetOf(animation), (target) => Bool.not(byElement.has(target))), (target) => byElement.set(target, animation)));
721
+ return byElement;
722
+ };
469
723
  /** Whether `animation` is `spec`'s: the rule the server sampled from the same spec. */
470
724
  export const matches = (animation, spec) => Option.exists(nameOfAnimation(animation), (name) => name === nameOf(spec));
725
+ /**
726
+ * Whether `animation` is a Batch rule for a spec's `key`: its name starts with the key's prefix, so the
727
+ * server's transitions and reduced motion are the client's. Its members' values aren't checked (#706, Q9).
728
+ */
729
+ export const matchesBatch = (animation, key) => Option.exists(nameOfAnimation(animation), (name) => name.startsWith(batchPrefixOf(key)));
471
730
  /** How far `animation` has got, in seconds since it started (its delay included): 0 before it has. */
472
731
  export const elapsedOf = (animation) => Option.match(Option.filter(Option.fromNullishOr(animation.currentTime), Predicate.isNumber), {
473
732
  onNone: () => 0,
@@ -478,22 +737,4 @@ export const delayOf = (animation) => Option.match(Option.filter(Option.fromNull
478
737
  onNone: () => 0,
479
738
  onSome: (effect) => Option.getOrElse(Option.filter(Option.some(effect.getTiming().delay), Predicate.isNumber), () => 0) / 1000,
480
739
  });
481
- /** What a slot's inline `animation` starts with: `var(--wardic-a`. */
482
- const SLOT_PREFIX = `var(--${PREFIX}a`;
483
- /**
484
- * Whether `element`'s Appear animation is running, not yet handed over: its inline style still names its
485
- * slot, which `release` removes. A layout measure asks it of each node, so a running animation's
486
- * transform, which beats the inline one, stays out of the box it reads.
487
- */
488
- // #245: a Measure pass; a string read, no style resolved.
489
- export const pending = (element) => element.style.getPropertyValue("animation").startsWith(SLOT_PREFIX);
490
- /**
491
- * The handover's last step: the element's inline `animation` removed, in the task that writes the
492
- * engine's first frame, so no paint falls between. While it ran, its value beat the inline style the
493
- * engine writes; removing it ends the CSS animation at that task's style update.
494
- */
495
- // The **Handoff** (ADR-0044, decision 6). A `cancel()` too changed nothing (a mutation, #48's PR 1).
496
- export const release = (element) => {
497
- element.style.removeProperty("animation");
498
- };
499
740
  //# sourceMappingURL=appear.js.map