kuinetic 0.2.4 → 0.4.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 (99) hide show
  1. package/README.md +2 -2
  2. package/dist/esm/advanced/index.mjs +1 -1
  3. package/dist/esm/{chunk-FASAEQDR.mjs → chunk-CG37RODK.mjs} +1232 -277
  4. package/dist/esm/{chunk-AEQGC2KM.mjs → chunk-EDFJTT5B.mjs} +2 -1
  5. package/dist/esm/{chunk-MZQG2VMG.mjs → chunk-W7U4A2NK.mjs} +708 -610
  6. package/dist/esm/{chunk-EHS45PIK.mjs → chunk-Y2FP56K5.mjs} +9228 -4275
  7. package/dist/esm/core/index.mjs +3 -3
  8. package/dist/esm/effects/index.mjs +3 -3
  9. package/dist/esm/index.mjs +4 -4
  10. package/dist/esm/notes/index.mjs +347 -9
  11. package/dist/kuinetic.advanced.js +2 -1
  12. package/dist/kuinetic.advanced.min.js +1 -1
  13. package/dist/kuinetic.all.js +9099 -3152
  14. package/dist/kuinetic.all.min.js +4 -2
  15. package/dist/kuinetic.css +2408 -161
  16. package/dist/kuinetic.js +9098 -3151
  17. package/dist/kuinetic.min.css +1 -1
  18. package/dist/kuinetic.min.js +3 -1
  19. package/dist/kuinetic.notes.js +1 -1
  20. package/dist/types/advanced/shaders.d.ts +1 -1
  21. package/dist/types/core/animator.d.ts +61 -2
  22. package/dist/types/core/attrs.d.ts +0 -2
  23. package/dist/types/core/auto-motion.d.ts +139 -0
  24. package/dist/types/core/cadence.d.ts +90 -0
  25. package/dist/types/core/channels.d.ts +5 -1
  26. package/dist/types/core/compile.d.ts +14 -2
  27. package/dist/types/core/deck-viewer.d.ts +2 -0
  28. package/dist/types/core/declarations.d.ts +6 -0
  29. package/dist/types/core/derived/group-gate.d.ts +18 -4
  30. package/dist/types/core/describe.d.ts +1 -1
  31. package/dist/types/core/easing.d.ts +9 -0
  32. package/dist/types/core/effect-context.d.ts +5 -0
  33. package/dist/types/core/element-config.d.ts +5 -4
  34. package/dist/types/core/flip.d.ts +25 -1
  35. package/dist/types/core/gesture.d.ts +5 -0
  36. package/dist/types/core/image-flight.d.ts +23 -0
  37. package/dist/types/core/instances.d.ts +27 -3
  38. package/dist/types/core/js-effect-preparer.d.ts +3 -1
  39. package/dist/types/core/owned-styles.d.ts +2 -1
  40. package/dist/types/core/params.d.ts +2 -3
  41. package/dist/types/core/parse.d.ts +21 -1
  42. package/dist/types/core/pause-scope.d.ts +40 -0
  43. package/dist/types/core/play.d.ts +2 -2
  44. package/dist/types/core/registry.d.ts +17 -2
  45. package/dist/types/core/repeat.d.ts +6 -4
  46. package/dist/types/core/sequence.d.ts +10 -0
  47. package/dist/types/core/stagger-config.d.ts +23 -101
  48. package/dist/types/core/stagger-keys.d.ts +2 -4
  49. package/dist/types/core/stagger.d.ts +12 -21
  50. package/dist/types/core/types.d.ts +76 -19
  51. package/dist/types/effects/auto-motion.d.ts +22 -117
  52. package/dist/types/effects/carousel/archive.d.ts +18 -0
  53. package/dist/types/effects/carousel/coast.d.ts +7 -0
  54. package/dist/types/effects/carousel/deck.d.ts +31 -2
  55. package/dist/types/effects/carousel/drag.d.ts +24 -7
  56. package/dist/types/effects/carousel/glide.d.ts +89 -0
  57. package/dist/types/effects/carousel/line.d.ts +10 -0
  58. package/dist/types/effects/carousel/row-copies.d.ts +13 -0
  59. package/dist/types/effects/carousel/row.d.ts +3 -0
  60. package/dist/types/effects/carousel/shape-fit.d.ts +54 -0
  61. package/dist/types/effects/carousel/sources.d.ts +26 -0
  62. package/dist/types/effects/carousel/sphere.d.ts +23 -0
  63. package/dist/types/effects/carousel/stack.d.ts +2 -1
  64. package/dist/types/effects/catalog/confetti.d.ts +2 -0
  65. package/dist/types/effects/catalog/cursor-trail.d.ts +2 -0
  66. package/dist/types/effects/catalog/curtains.d.ts +2 -0
  67. package/dist/types/effects/catalog/feedback.d.ts +1 -1
  68. package/dist/types/effects/catalog/image-flight.d.ts +2 -0
  69. package/dist/types/effects/catalog/line-boil.d.ts +2 -0
  70. package/dist/types/effects/catalog/media-shared.d.ts +10 -0
  71. package/dist/types/effects/catalog/number-tokens.d.ts +5 -0
  72. package/dist/types/effects/catalog/numbers-shared.d.ts +3 -4
  73. package/dist/types/effects/catalog/pause-scope.d.ts +20 -0
  74. package/dist/types/effects/catalog/text-shared.d.ts +17 -6
  75. package/dist/types/effects/catalog/typewriter-scatter.d.ts +5 -0
  76. package/dist/types/effects/catalog/view-transitions.d.ts +32 -1
  77. package/dist/types/effects/catalog/wobble.d.ts +2 -0
  78. package/dist/types/effects/gestures/drag-options.d.ts +17 -0
  79. package/dist/types/effects/layout/departures.d.ts +21 -0
  80. package/dist/types/effects/motion-path/fit.d.ts +4 -0
  81. package/dist/types/effects/scroll-mechanics/progress-output.d.ts +9 -0
  82. package/dist/types/effects/scroll-mechanics/snap-autoplay.d.ts +20 -0
  83. package/dist/types/effects/step-index.d.ts +19 -1
  84. package/dist/types/effects/step-marking.d.ts +7 -4
  85. package/dist/types/effects/svg/morph-loop.d.ts +7 -0
  86. package/dist/types/effects/svg/text-path.d.ts +2 -0
  87. package/dist/types/effects/three-d/cube.d.ts +2 -0
  88. package/dist/types/effects/tween/index.d.ts +2 -1
  89. package/dist/types/effects/tween/properties.d.ts +1 -1
  90. package/dist/types/effects/tween/toggle.d.ts +6 -0
  91. package/dist/types/effects/tween/waypoints.d.ts +1 -1
  92. package/dist/types/notes/effects.d.ts +1 -0
  93. package/dist/types/notes/index.d.ts +11 -0
  94. package/dist/types/notes/showcase.d.ts +1 -0
  95. package/dist/types/showcase/lightbox-flight.d.ts +11 -0
  96. package/dist/types/showcase/media-source.d.ts +1 -0
  97. package/dist/types/showcase/modal-shell.d.ts +5 -0
  98. package/dist/types/showcase/youtube.d.ts +3 -0
  99. package/package.json +1 -1
@@ -2,25 +2,36 @@ import {
2
2
  ALL_TIMING_TOKENS,
3
3
  ATTR,
4
4
  BREAKPOINT_NAMES,
5
+ EASING_KEYWORDS,
5
6
  KUI_EVENT,
7
+ MIN_PERIOD_MS,
6
8
  Registry,
7
9
  SEGMENT_HOIST_KEYS,
10
+ applyStagger,
8
11
  applyToggleVerb,
9
12
  assignOnce,
10
13
  breakpointsIn,
14
+ claimTargetGroupHost,
15
+ clampPeriod,
11
16
  control,
12
17
  createActivationBinder,
18
+ createAutoMotion,
13
19
  createCssInstance,
14
20
  createGateWatcher,
15
21
  createRootResolver,
16
22
  createScrollScheduler,
17
23
  cssEasingValue,
24
+ customEasing,
18
25
  decimalNumber,
19
26
  directionValue,
27
+ elementStaggerKeys,
20
28
  emitLifecycle,
21
29
  gateMatches,
22
30
  gatedAnimationName,
23
31
  gatesOverlap,
32
+ indexTargetGroup,
33
+ isGroupOnly,
34
+ isGroupedKeys,
24
35
  isInfiniteRepeat,
25
36
  isOneShot,
26
37
  isSafeCssValue,
@@ -32,12 +43,18 @@ import {
32
43
  queryScoped,
33
44
  readEffectParams,
34
45
  readEffectTiming,
46
+ releaseStagger,
47
+ releaseStaggerGroup,
35
48
  repeatCount,
49
+ repeatedInstance,
36
50
  resolveActivationSpec,
37
51
  resolveParams,
38
52
  resolvePlayback,
53
+ restageAfterRemoval,
54
+ restageAround,
39
55
  selectorBreadth,
40
56
  splitTopLevel,
57
+ staggerKeysFor,
41
58
  startKindOf,
42
59
  suggest,
43
60
  timingContractOf,
@@ -46,19 +63,22 @@ import {
46
63
  validate,
47
64
  warnAboutActivation,
48
65
  warnAboutToggleActions
49
- } from "./chunk-FASAEQDR.mjs";
66
+ } from "./chunk-CG37RODK.mjs";
50
67
  import {
51
68
  createLedgerSet
52
- } from "./chunk-AEQGC2KM.mjs";
69
+ } from "./chunk-EDFJTT5B.mjs";
53
70
 
54
71
  // src/core/bundles.ts
55
- var HOIST_KEYS = ["activation", "timeline", "threshold", "rm", "func"];
72
+ var HOIST_KEYS = ["activation", "via", "timeline", "range", "threshold", "rm", "func", "every"];
56
73
  var HOIST_LABELS = {
57
74
  activation: "on",
75
+ via: "via",
58
76
  timeline: "timeline",
77
+ range: "range",
59
78
  threshold: "threshold",
60
79
  rm: "rm",
61
- func: "func"
80
+ func: "func",
81
+ every: "every"
62
82
  };
63
83
  var BundleTable = class {
64
84
  /**
@@ -246,8 +266,11 @@ function overlay(member, ref) {
246
266
  delay: ref.delay ?? member.delay,
247
267
  easing: ref.easing ?? member.easing,
248
268
  at: ref.at ?? member.at,
269
+ split: ref.split ?? member.split,
270
+ rows: ref.rows ?? member.rows,
249
271
  gate: ref.gate ?? member.gate,
250
272
  repeat: ref.repeat ?? member.repeat,
273
+ repeatDelay: ref.repeatDelay ?? member.repeatDelay,
251
274
  yoyo: ref.yoyo ?? member.yoyo,
252
275
  params: { ...member.params, ...ref.params },
253
276
  hoists: overlayHoists(member.hoists, ref.hoists)
@@ -294,46 +317,6 @@ function resolveGlobalFunction(el, name) {
294
317
  return typeof candidate === "function" ? candidate : void 0;
295
318
  }
296
319
 
297
- // src/core/capabilities.ts
298
- function supports(property, value) {
299
- if (typeof CSS === "undefined" || typeof CSS.supports !== "function") return false;
300
- try {
301
- return CSS.supports(property, value);
302
- } catch {
303
- return false;
304
- }
305
- }
306
- var cached;
307
- function detect(force = false) {
308
- if (cached && !force) return cached;
309
- cached = {
310
- viewTimeline: supports("animation-timeline", "view()"),
311
- scrollTimeline: supports("animation-timeline", "scroll()"),
312
- animationRange: supports("animation-range", "entry 0% cover 30%"),
313
- // `translate`/`rotate`/`scale` as independent properties is what makes the channel model
314
- // possible at all — under the `transform` shorthand every effect would collide.
315
- individualTransforms: supports("translate", "0 10px") && supports("scale", "1.1"),
316
- scrollTimelineName: supports("scroll-timeline-name", "--x"),
317
- viewTransitions: typeof document !== "undefined" && "startViewTransition" in document,
318
- intersectionObserver: typeof IntersectionObserver !== "undefined",
319
- reducedMotion: typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches,
320
- motionPath: supports("offset-path", 'path("M 0 0")')
321
- };
322
- return cached;
323
- }
324
- var CHANNEL_REQUIREMENTS = [
325
- {
326
- channel: "offset",
327
- capability: "motionPath",
328
- message: "this browser does not support CSS Motion Path (offset-path), so the element will not travel \u2014 the animation still runs and completes, it just has no path to follow"
329
- }
330
- ];
331
- function unsupportedChannelWarnings(channels, capabilities) {
332
- return CHANNEL_REQUIREMENTS.filter(
333
- (entry) => channels.includes(entry.channel) && !capabilities[entry.capability]
334
- ).map((entry) => entry.message);
335
- }
336
-
337
320
  // src/core/channels.ts
338
321
  var INDEPENDENT_PHASES = /* @__PURE__ */ new Set(["entrance|state", "exit|state"]);
339
322
  function phasePair(a, b) {
@@ -349,12 +332,20 @@ var CHANNEL_COMPOSITION = {
349
332
  function additiveChannels(channels) {
350
333
  return channels.length > 0 && channels.every((channel) => CHANNEL_COMPOSITION[channel] === "add");
351
334
  }
335
+ function claimsOverlap(a, b) {
336
+ return gatesOverlap(a.gate, b.gate) && !independentPhases(a, b) && !a.follows?.has(b) && !b.follows?.has(a);
337
+ }
338
+ function contestsChannel(a, b, contested) {
339
+ return claimsOverlap(a, b) && a.channels.some((channel) => contested.has(channel) && b.channels.includes(channel));
340
+ }
352
341
  function additiveResolution(claims, conflicts) {
353
342
  if (conflicts.some((conflict) => conflict.effects[0] === conflict.effects[1])) return void 0;
354
343
  const contested = new Set(conflicts.map((conflict) => conflict.channel));
355
344
  const involved = /* @__PURE__ */ new Set();
356
- claims.forEach((claim2, index) => {
357
- if (claim2.channels.some((channel) => contested.has(channel))) involved.add(index);
345
+ claims.forEach((claim, index) => {
346
+ if (claims.some(
347
+ (other, otherIndex) => otherIndex !== index && contestsChannel(claim, other, contested)
348
+ )) involved.add(index);
358
349
  });
359
350
  for (const index of involved) if (!claims[index].additive) return void 0;
360
351
  return involved;
@@ -362,29 +353,29 @@ function additiveResolution(claims, conflicts) {
362
353
  function findConflicts(claims) {
363
354
  const conflicts = [];
364
355
  const seen = /* @__PURE__ */ new Map();
365
- for (const claim2 of claims) {
366
- for (const channel of claim2.channels) {
356
+ for (const claim of claims) {
357
+ for (const channel of claim.channels) {
367
358
  const claimants = seen.get(channel) ?? [];
368
359
  const clash = claimants.find(
369
360
  // Same effect name twice in one list claims the channel against itself; still a conflict,
370
361
  // and a more likely author typo than a deliberate choice. Phase cannot exempt that pair
371
362
  // either, because a phase is only ever independent of a *different* one.
372
- (other) => gatesOverlap(other.gate, claim2.gate) && !independentPhases(other, claim2)
363
+ (other) => claimsOverlap(other, claim)
373
364
  );
374
- if (clash) conflicts.push({ channel, effects: [clash.name, claim2.name] });
375
- claimants.push(claim2);
365
+ if (clash) conflicts.push({ channel, effects: [clash.name, claim.name] });
366
+ claimants.push(claim);
376
367
  seen.set(channel, claimants);
377
368
  }
378
369
  }
379
370
  return conflicts;
380
371
  }
381
372
  function deliveryClobbers(claims) {
382
- const stylesheet = claims.filter((claim2) => claim2.delivery === "stylesheet-animation");
373
+ const stylesheet = claims.filter((claim) => claim.delivery === "stylesheet-animation");
383
374
  if (stylesheet.length === 0) return [];
384
- const inline = claims.find((claim2) => claim2.inlineAnimation && !claim2.delivery);
375
+ const inline = claims.find((claim) => claim.inlineAnimation && !claim.delivery);
385
376
  if (!inline) return [];
386
377
  return stylesheet.map(
387
- (claim2) => `"${inline.name}" writes an inline animation, which outranks the stylesheet rule "${claim2.name}" delivers its motion from`
378
+ (claim) => `"${inline.name}" writes an inline animation, which outranks the stylesheet rule "${claim.name}" delivers its motion from`
388
379
  );
389
380
  }
390
381
  function describeConflicts(conflicts) {
@@ -435,6 +426,43 @@ function refusalReason(value) {
435
426
  }
436
427
  return `at:"${value}" is not a position \u2014 expected at:with, at:after, or a signed time such as at:-200ms, at:+100ms or at:with+150ms`;
437
428
  }
429
+ function startsAfter(earlier, later) {
430
+ const { member } = earlier;
431
+ if (isInfiniteRepeat(member.repeat)) return false;
432
+ if (earlier.stagger !== later.stagger) {
433
+ const first = timeMs(earlier.stagger ?? "");
434
+ const second = timeMs(later.stagger ?? "");
435
+ if (first === void 0 || second === void 0 || second < first) return false;
436
+ }
437
+ const duration = durationExpression(member.duration, member.primitiveId);
438
+ const end = `${earlier.step.delayExpr} + ${playbackExpression(duration, member.repeat, member.repeatDelay)}`;
439
+ const vars = /* @__PURE__ */ new Map();
440
+ const lowerBound = accumulateTime(later.step.delayExpr, 1, vars) + accumulateTime(end, -1, vars);
441
+ return lowerBound >= 0 && [...vars].every(
442
+ ([term, weight]) => weight === 0 || weight > 0 && term.startsWith("var(") && term.includes("-duration,")
443
+ );
444
+ }
445
+ function accumulateTime(expression, direction, vars) {
446
+ const parts = splitTopLevel(expression, " ");
447
+ let total = 0;
448
+ for (let i = 0, sign = direction; i < parts.length; ) {
449
+ const term = parts[i++];
450
+ if (term === "+" || term === "-") {
451
+ sign = direction * Number(`${term}1`);
452
+ continue;
453
+ }
454
+ const multiplied = parts[i] === "*";
455
+ const weight = multiplied ? sign * Number(parts[i + 1]) : sign;
456
+ i += 2 * Number(multiplied);
457
+ const ms = timeMs(term);
458
+ if (ms !== void 0) {
459
+ total += weight * ms;
460
+ continue;
461
+ }
462
+ vars.set(term, (vars.get(term) ?? 0) + weight);
463
+ }
464
+ return total;
465
+ }
438
466
  function resolveSequence(members, timeline, warn) {
439
467
  const chain = { members, steps: [], warn };
440
468
  let warnedAboutTimeline = false;
@@ -508,11 +536,13 @@ function follow(chain, index, position, own) {
508
536
  }
509
537
  const played = playbackExpression(
510
538
  durationExpression(previous.duration, previous.primitiveId),
511
- previous.repeat
539
+ previous.repeat,
540
+ previous.repeatDelay
512
541
  );
542
+ const count = repeatCount(previous.repeat) ?? 1;
513
543
  return {
514
544
  delayExpr: `${anchor.delayExpr} + ${played}${position.term}`,
515
- delayMs: anchor.delayMs + durationMs * (repeatCount(previous.repeat) ?? 1) + position.offsetMs,
545
+ delayMs: anchor.delayMs + durationMs * count + (previous.repeatDelay ?? 0) * (count - 1) + position.offsetMs,
516
546
  sequenced: true
517
547
  };
518
548
  }
@@ -533,7 +563,7 @@ function refuseEndless(chain, index, own) {
533
563
  return own;
534
564
  }
535
565
  function timelineRefusal(timeline) {
536
- return `at: compiles to an animation-delay, and a "${timeline}" timeline is driven by scroll position rather than a clock, so it ignores one \u2014 position a scroll-driven effect with a range instead (the trailing tokens of data-kui-timeline, e.g. data-kui-timeline="${timeline} entry 0% cover 60%"). The delay still applies where the browser has no scroll-driven animations and the effect degrades to a clock.`;
566
+ return `at: compiles to an animation-delay, and a "${timeline}" timeline is driven by scroll position rather than a clock, so it ignores one \u2014 position a scroll-driven effect with timeline:${timeline} range:'${timeline === "scroll" ? "0% 100%" : "entry 0% cover 60%"}'. The delay still applies where the browser has no scroll-driven animations and the effect degrades to a clock.`;
537
567
  }
538
568
  function timeMs(value) {
539
569
  const ms = toMilliseconds(value, Number.NaN);
@@ -551,8 +581,10 @@ function emptyTracks() {
551
581
  durations: [],
552
582
  delays: [],
553
583
  ends: [],
584
+ staggerSpans: [],
554
585
  easings: [],
555
586
  iterationCounts: [],
587
+ fillModes: [],
556
588
  directions: [],
557
589
  compositions: []
558
590
  };
@@ -561,35 +593,47 @@ function keyframesFor(entry) {
561
593
  const { preset } = entry.resolved;
562
594
  return entry.variant?.keyframes ?? [preset.keyframes ?? `kui-${preset.name}`];
563
595
  }
564
- function iterationCountProperty(presetName) {
565
- return `--kui-fx-${presetName}-iterations`;
596
+ function iterationsFor(entry) {
597
+ return entry.spec.repeat ?? (entry.handoffEnd ? "1" : `var(--kui-fx-${entry.resolved.preset.name}-iterations, 1)`);
566
598
  }
567
599
  function pushTrack(tracks, entry, step) {
568
600
  const { spec, resolved } = entry;
569
601
  const id = resolved.primitive.id;
570
602
  const duration = durationExpression(spec.duration, id);
571
- const delay = staggerDelay(step.delayExpr);
572
- const end = `${step.delayExpr} + ${playbackExpression(duration, spec.repeat)}`;
603
+ const delay = staggerDelay(step.delayExpr, entry.stagger);
604
+ const staggerSpan = entry.stagger === void 0 ? FLAT_SPAN : `(var(--kui-stagger-count, 1) - 1) * (${entry.stagger})`;
605
+ const end = `${step.delayExpr} + ${playbackExpression(duration, spec.repeat, spec.repeatDelay)}`;
573
606
  const easing = easingValue(spec.easing, id);
574
- const iterations = spec.repeat ?? `var(${iterationCountProperty(resolved.preset.name)}, 1)`;
607
+ const iterations = iterationsFor(entry);
575
608
  const direction = directionValue(spec.yoyo);
576
609
  const composition = entry.composite ?? "replace";
577
- for (const name of keyframesFor(entry)) {
610
+ for (const [index, name] of keyframesFor(entry).entries()) {
611
+ if (spec.repeatDelay) {
612
+ tracks.repeatDelays ??= /* @__PURE__ */ new Map();
613
+ tracks.repeatDelays.set(tracks.names.length, spec.repeatDelay);
614
+ }
578
615
  tracks.names.push(gatedAnimationName(name, spec.gate));
579
616
  tracks.keyframes.push(name);
580
617
  tracks.durations.push(duration);
581
618
  tracks.delays.push(delay);
582
619
  tracks.ends.push(end);
620
+ tracks.staggerSpans.push(staggerSpan);
583
621
  tracks.easings.push(easing);
584
622
  tracks.iterationCounts.push(iterations);
623
+ tracks.fillModes.push(fillFor(entry, index));
585
624
  tracks.directions.push(direction);
586
625
  tracks.compositions.push(composition);
587
626
  }
588
627
  }
628
+ function fillFor(entry, index) {
629
+ const channel = entry.variant?.channels?.[index];
630
+ const follows = channel === void 0 ? entry.handoff?.size : entry.handoff?.has(channel);
631
+ return follows ? "forwards" : "both";
632
+ }
589
633
  function pushTransitions(segments, owners, entry, warnings) {
590
634
  const { spec, resolved } = entry;
591
635
  const { preset, primitive } = resolved;
592
- for (const segment of preset.transitions ?? []) {
636
+ for (const segment of [...preset.transitions ?? [], ...entry.variant?.transitions ?? []]) {
593
637
  const previousOwner = owners.get(segment.property);
594
638
  if (previousOwner !== void 0 && previousOwner !== preset.name) {
595
639
  warnings.push(
@@ -612,7 +656,7 @@ function declarationsFor(tracks, timeline) {
612
656
  "animation-delay": delays.join(", "),
613
657
  "animation-timing-function": tracks.easings.join(", "),
614
658
  "animation-iteration-count": tracks.iterationCounts.join(", "),
615
- "animation-fill-mode": tracks.names.map(() => "both").join(", ")
659
+ "animation-fill-mode": tracks.fillModes.join(", ")
616
660
  };
617
661
  if (tracks.directions.some((value) => value !== "normal")) {
618
662
  declarations["animation-direction"] = tracks.directions.join(", ");
@@ -622,16 +666,23 @@ function declarationsFor(tracks, timeline) {
622
666
  }
623
667
  return declarations;
624
668
  }
625
- function staggerDelay(base) {
626
- return `${base} + var(--kui-i, 0) * var(--kui-stagger, 0ms)`;
669
+ var FLAT_STAGGER = "var(--kui-i, 0) * var(--kui-stagger, 0ms)";
670
+ var FLAT_SPAN = "(var(--kui-stagger-count, 1) - 1) * var(--kui-stagger, 0ms)";
671
+ function staggerDelay(base, step) {
672
+ const offset = step === void 0 ? FLAT_STAGGER : `var(--kui-i, 0) * (${step})`;
673
+ return `${base} + ${offset}`;
674
+ }
675
+ function withNestedStagger(delay) {
676
+ return delay.replaceAll(FLAT_STAGGER, `var(--kui-stagger-offset, ${FLAT_STAGGER})`).replaceAll(FLAT_SPAN, `var(--kui-stagger-span, ${FLAT_SPAN})`);
627
677
  }
628
678
  function wrapped(sum) {
629
679
  return `calc(${sum})`;
630
680
  }
631
681
  function pinnedDelays(tracks) {
632
- const ends = [...new Set(tracks.ends)];
682
+ const sharedSpan = tracks.staggerSpans.every((span2) => span2 === tracks.staggerSpans[0]);
683
+ const ends = [...new Set(sharedSpan ? tracks.ends : tracks.ends.map((end, i) => `${end} + ${tracks.staggerSpans[i]}`))];
633
684
  const span = ends.length === 1 ? ends[0] : `max(${ends.join(", ")})`;
634
- const head = `${span} + (var(--kui-stagger-count, 1) - 1) * var(--kui-stagger, 0ms)`;
685
+ const head = sharedSpan ? `${span} + ${tracks.staggerSpans[0]}` : span;
635
686
  return tracks.delays.map((delay) => wrapped(`${delay} - var(--kui-progress, 0) * (${head})`));
636
687
  }
637
688
  function easingValue(easing, primitiveId) {
@@ -645,12 +696,11 @@ function readAttributes(el) {
645
696
  return {
646
697
  source: el.getAttribute(ATTR.source) ?? "",
647
698
  on: el.getAttribute(ATTR.on),
648
- timeline: el.getAttribute(ATTR.timeline),
649
699
  threshold: el.getAttribute(ATTR.threshold)
650
700
  };
651
701
  }
652
702
  function resolveConfig(attributes, parsed) {
653
- const rawTimeline = parsed.timeline ?? attributes.timeline ?? "time";
703
+ const rawTimeline = parsed.timeline ?? "time";
654
704
  const [head = "time", ...rest] = rawTimeline.trim().split(/\s+/);
655
705
  const longhand = parseActivationAttribute(attributes.on);
656
706
  const authored = parsed.activation ?? longhand.activation;
@@ -664,10 +714,19 @@ function resolveConfig(attributes, parsed) {
664
714
  // `actions:` refines `on:` and has only the inline spelling.
665
715
  ...parsed.actions === void 0 ? {} : { actions: parseToggleActions(parsed.actions) },
666
716
  timeline: TIMELINES.has(head) ? head : "time",
667
- range: rest.join(" "),
717
+ ...timelineOptions(rest, parsed.range),
668
718
  threshold: parsed.threshold ?? attributes.threshold ?? "0%"
669
719
  };
670
720
  }
721
+ function timelineOptions(tokens, range) {
722
+ const timelineAxis = /^(block|inline|x|y)$/.test(tokens[0] ?? "") ? tokens.shift() : void 0;
723
+ const timelineName = /^--[\w-]+$/.test(tokens[0] ?? "") ? tokens.shift() : void 0;
724
+ return {
725
+ range: range ?? tokens.join(" "),
726
+ ...timelineAxis ? { timelineAxis } : {},
727
+ ...timelineName ? { timelineName } : {}
728
+ };
729
+ }
671
730
  function resolveTimelineHead(raw, fallback) {
672
731
  if (raw === void 0) return fallback;
673
732
  const [head] = raw.trim().split(/\s+/);
@@ -681,12 +740,16 @@ function resolveGroupConfig(base, hoists) {
681
740
  activation: authored ?? base.activation,
682
741
  activationAuthored: authored !== void 0 || base.activationAuthored
683
742
  };
743
+ if (hoists.via !== void 0) config.activationSource = hoists.via;
684
744
  if (hoists.actions !== void 0) config.actions = parseToggleActions(hoists.actions);
685
745
  if (hoists.timeline !== void 0) {
686
- const [head = "time", ...rest] = hoists.timeline.trim().split(/\s+/);
746
+ const [head, ...rest] = hoists.timeline.trim().split(/\s+/);
687
747
  config.timeline = TIMELINES.has(head) ? head : base.timeline;
688
- config.range = rest.join(" ");
748
+ delete config.timelineAxis;
749
+ delete config.timelineName;
750
+ Object.assign(config, timelineOptions(rest));
689
751
  }
752
+ config.range = hoists.range ?? config.range;
690
753
  if (hoists.threshold !== void 0) config.threshold = hoists.threshold;
691
754
  return config;
692
755
  }
@@ -694,6 +757,7 @@ function sourceFromLonghand({
694
757
  parsed,
695
758
  longhand
696
759
  }) {
760
+ if (parsed.via !== void 0) return { activationSource: parsed.via };
697
761
  if (parsed.activation !== void 0 || longhand.from === void 0) return {};
698
762
  return { activationSource: longhand.from };
699
763
  }
@@ -701,9 +765,9 @@ function sourceFromLonghand({
701
765
  // src/core/host-facts.ts
702
766
  var RM_RANK = { shorten: 0, crossfade: 1, disable: 2 };
703
767
  function resolveDefaultActivation(claims) {
704
- const declared = claims.map((claim2) => claim2.defaultActivation);
768
+ const declared = claims.map((claim) => claim.defaultActivation);
705
769
  const firstWins = declared.find((value) => value !== void 0);
706
- const entrance = claims.findIndex((claim2) => claim2.phase === "entrance");
770
+ const entrance = claims.findIndex((claim) => claim.phase === "entrance");
707
771
  if (firstWins === void 0 || entrance === -1) return firstWins;
708
772
  return declared[entrance] ?? "enter";
709
773
  }
@@ -763,7 +827,8 @@ function schemaFor(entry) {
763
827
  if (!extra) return entry.resolved.primitive.parameters;
764
828
  return { ...entry.resolved.primitive.parameters, ...extra };
765
829
  }
766
- function compileTargets(parsed, registry, timeline) {
830
+ function compileTargets(parsed, registry, timeline, repeatDelaySupport = true) {
831
+ if (parsed.specs.some((spec) => spec.split !== void 0)) parsed = scopeHoists(parsed, registry);
767
832
  const warnings = [...parsed.warnings];
768
833
  const unquoted = findUnquotedSelectors(parsed.specs, registry);
769
834
  for (const found of unquoted) warnings.push(unquotedSelectorWarning(found));
@@ -776,17 +841,30 @@ function compileTargets(parsed, registry, timeline) {
776
841
  ...suspects
777
842
  };
778
843
  }
779
- const sanitized = entries.map(
780
- (entry) => refusePlayback(refuseContainerGate(entry, warnings), timeline, warnings)
781
- );
844
+ const scopedTimelines = new Map(entries.flatMap(
845
+ (entry) => entry.spec.hoists?.timeline === void 0 ? [] : [[groupKeyOf(entry), entry.spec.hoists.timeline]]
846
+ ).reverse());
847
+ const sanitized = entries.map((entry) => refusePlayback(
848
+ refuseContainerGate(entry, warnings),
849
+ entry.spec.repeatDelay ? resolveTimelineHead(scopedTimelines.get(groupKeyOf(entry)), timeline) : timeline,
850
+ repeatDelaySupport,
851
+ warnings
852
+ ));
782
853
  const steps = resolveSequence(sanitized.map(memberFor), timeline, (m) => warnings.push(m));
783
854
  const sequenced = sanitized.map((entry, index) => ({ ...entry, step: steps[index] }));
784
855
  warnCrossGroupSequencing(sequenced, parsed.activation, warnings);
785
- const targets = partitionByTarget(sequenced).map(({ selector, scope, entries: group }) => {
856
+ const targets = partitionByTarget(sequenced).map(({ entries: group, ...identity }) => {
786
857
  const groupWarnings = [];
787
- const composed = resolveComposition(group, registry, groupWarnings);
858
+ if (identity.split || identity.selector) applyTrackStagger(group, parsed.spread);
788
859
  const groupHoists = mergeGroupHoists(group, groupWarnings);
860
+ const [rows, ...conflicts] = new Set(group.flatMap(
861
+ ({ spec }) => spec.split === "tiles" && spec.rows !== void 0 ? [spec.rows] : []
862
+ ));
863
+ for (const conflict of conflicts) {
864
+ groupWarnings.push(`conflicting tile row counts "${rows}" and "${conflict}" in one split:tiles group \u2014 the first wins`);
865
+ }
789
866
  const groupTimeline = resolveTimelineHead(groupHoists?.timeline, timeline);
867
+ const composed = resolveComposition(group, registry, groupWarnings, groupTimeline);
790
868
  const plan = buildPlan(composed, groupTimeline, unknown, groupWarnings);
791
869
  plan.defaultActivation = resolveDefaultActivation(
792
870
  composed.map((entry) => ({
@@ -794,7 +872,8 @@ function compileTargets(parsed, registry, timeline) {
794
872
  defaultActivation: entry.resolved.primitive.defaultActivation
795
873
  }))
796
874
  );
797
- return { selector, scope, hoists: groupHoists, specs: group.map((entry) => entry.spec), plan };
875
+ const tileFit = group.find((entry) => entry.tileFit)?.tileFit;
876
+ return { ...identity, ...rows === void 0 ? {} : { rows }, ...tileFit && { tileFit }, hoists: groupHoists, specs: group.map((entry) => entry.spec), plan };
798
877
  });
799
878
  mergeHostFacts(targets);
800
879
  const reducedMotion = resolvedPolicy(targets[0].plan.reducedMotion, parsed.rm, warnings);
@@ -802,31 +881,42 @@ function compileTargets(parsed, registry, timeline) {
802
881
  return { targets, warnings, ...suspects };
803
882
  }
804
883
  function scopeHoists(parsed, registry) {
805
- if (!parsed.specs.some((spec) => spec.hoists)) return parsed;
884
+ const ignoreSplit = parsed.specs.some((spec) => spec.split !== void 0) && parsed.specs.some((spec) => Object.hasOwn(spec.params, "target"));
885
+ if (!ignoreSplit && !parsed.specs.some((spec) => spec.hoists)) return parsed;
806
886
  const warnings = [...parsed.warnings];
887
+ if (ignoreSplit) warnings.push('cannot combine "split:" with "target:" on one element \u2014 ignoring "split:"');
807
888
  const folded = { ...parsed, warnings };
808
889
  const specs = parsed.specs.map((spec) => {
809
- if (!spec.hoists || !staysOnHost(spec, registry)) return spec;
810
- for (const key of SEGMENT_HOIST_KEYS) {
811
- const value = spec.hoists[key];
812
- if (value === void 0) continue;
813
- assignOnce(folded, key, value, HOIST_LABELS2[key]);
814
- }
890
+ if (!ignoreSplit && !spec.hoists) return spec;
815
891
  const rest = { ...spec };
816
- delete rest.hoists;
892
+ if (ignoreSplit) {
893
+ delete rest.split;
894
+ delete rest.rows;
895
+ }
896
+ if (rest.hoists && staysOnHost(rest, registry)) {
897
+ for (const key of SEGMENT_HOIST_KEYS) {
898
+ const value = rest.hoists[key];
899
+ if (value !== void 0) assignOnce(folded, key, value, HOIST_LABELS2[key]);
900
+ }
901
+ delete rest.hoists;
902
+ }
817
903
  return rest;
818
904
  });
819
905
  return { ...folded, specs };
820
906
  }
821
907
  function staysOnHost(spec, registry) {
908
+ if (spec.split !== void 0) return false;
909
+ if (!spec.params.target) return true;
822
910
  const resolved = registry.resolve(spec.name);
823
911
  if (!resolved) return true;
824
912
  return Object.hasOwn(resolved.primitive.parameters, "target");
825
913
  }
826
914
  var HOIST_LABELS2 = {
827
915
  activation: "activations",
916
+ via: "activation sources",
828
917
  actions: "crossing actions",
829
918
  timeline: "timelines",
919
+ range: "ranges",
830
920
  threshold: "thresholds",
831
921
  cascade: "stagger steps",
832
922
  spread: "stagger budgets",
@@ -834,21 +924,32 @@ var HOIST_LABELS2 = {
834
924
  cols: "stagger column counts",
835
925
  along: "stagger axes"
836
926
  };
927
+ function applyTrackStagger(entries, fallbackSpread) {
928
+ if (entries.length < 2) return;
929
+ const spread = entries.map(({ spec }) => spec.hoists?.spread).find((value) => value !== void 0) ?? fallbackSpread;
930
+ if (spread !== void 0 && isSafeCssValue(spread)) return;
931
+ for (const entry of entries) {
932
+ const cascade = entry.spec.hoists?.cascade;
933
+ if (cascade !== void 0 && isSafeCssValue(cascade) && entry.resolved.primitive.renderer === "css-keyframes") {
934
+ entry.stagger = cascade;
935
+ }
936
+ }
937
+ }
837
938
  function mergeGroupHoists(entries, warnings) {
838
939
  let merged;
839
940
  for (const entry of entries) {
840
941
  if (!entry.spec.hoists) continue;
841
- merged = absorbGroupHoists(merged ?? {}, entry.spec.hoists, warnings);
942
+ merged = absorbGroupHoists(merged ?? {}, entry.spec.hoists, warnings, entry.stagger !== void 0);
842
943
  }
843
944
  return merged;
844
945
  }
845
- function absorbGroupHoists(merged, hoists, warnings) {
946
+ function absorbGroupHoists(merged, hoists, warnings, rendersCascade) {
846
947
  for (const key of SEGMENT_HOIST_KEYS) {
847
948
  const value = hoists[key];
848
949
  if (value === void 0) continue;
849
950
  const current = merged[key];
850
951
  if (current === void 0) merged[key] = value;
851
- else if (current !== value) {
952
+ else if (current !== value && (key !== "cascade" || !rendersCascade)) {
852
953
  warnings.push(
853
954
  `conflicting ${HOIST_LABELS2[key]} "${current}" and "${value}" in one target: group \u2014 the first wins`
854
955
  );
@@ -871,6 +972,7 @@ function warnCrossGroupSequencing(sequenced, elementActivation, warnings) {
871
972
  }
872
973
  }
873
974
  function groupKeyOf(entry) {
975
+ if (entry.spec.split !== void 0) return `split ${entry.spec.split}`;
874
976
  return `${entry.scope ?? "self"} ${entry.target ?? ""}`;
875
977
  }
876
978
  function partitionByTarget(entries) {
@@ -879,16 +981,18 @@ function partitionByTarget(entries) {
879
981
  for (const entry of entries) {
880
982
  const selector = entry.target ?? "";
881
983
  const scope = entry.scope ?? "self";
882
- const key = `${scope} ${selector}`;
984
+ const key = groupKeyOf(entry);
883
985
  let group = byKey.get(key);
884
986
  if (!group) {
885
987
  group = { selector, scope, entries: [] };
988
+ if (entry.spec.split !== void 0) group.split = entry.spec.split;
886
989
  byKey.set(key, group);
887
990
  order.push(group);
888
991
  }
992
+ if (entry.mountTargets) group.mountTargets ??= entry.mountTargets;
889
993
  group.entries.push(entry);
890
994
  }
891
- const hostIndex = order.findIndex((group) => group.selector === "");
995
+ const hostIndex = order.findIndex((group) => group.selector === "" && group.split === void 0);
892
996
  if (hostIndex > 0) {
893
997
  const [host] = order.splice(hostIndex, 1);
894
998
  order.unshift(host);
@@ -914,6 +1018,7 @@ function emptyPlan(unknown, warnings) {
914
1018
  function resolveEntries(specs, registry, warnings) {
915
1019
  const entries = [];
916
1020
  const unknown = [];
1021
+ let split;
917
1022
  for (const spec of specs) {
918
1023
  const resolved = registry.resolve(spec.name);
919
1024
  if (!resolved) {
@@ -921,14 +1026,28 @@ function resolveEntries(specs, registry, warnings) {
921
1026
  warnUnknownEffect(spec.name, registry, warnings);
922
1027
  continue;
923
1028
  }
1029
+ if (spec.split !== void 0) {
1030
+ split ??= spec.split;
1031
+ if (spec.split !== split) {
1032
+ warnings.push(`cannot combine "split:${split}" with "split:${spec.split}" \u2014 skipping "${spec.name}"`);
1033
+ continue;
1034
+ }
1035
+ }
924
1036
  entries.push(entryFor(spec, resolved, warnings));
925
1037
  }
926
1038
  return { entries, unknown };
927
1039
  }
928
1040
  function entryFor(spec, resolved, warnings) {
1041
+ const tileFit = spec.split === "tiles" && spec.params.fit === "stretch" ? "stretch" : void 0;
1042
+ if (tileFit) {
1043
+ spec = { ...spec, params: { ...spec.params } };
1044
+ delete spec.params.fit;
1045
+ }
929
1046
  const lifted = liftTarget(spec, resolved, warnings);
930
1047
  const variant = resolved.primitive.variantFor?.(lifted.spec, (m) => warnings.push(m));
931
1048
  const entry = variant ? { spec: lifted.spec, resolved, variant } : { spec: lifted.spec, resolved };
1049
+ if (tileFit) entry.tileFit = tileFit;
1050
+ if (lifted.mountTargets) entry.mountTargets = lifted.mountTargets;
932
1051
  if (lifted.target !== void 0) {
933
1052
  entry.target = lifted.target;
934
1053
  entry.scope = lifted.scope;
@@ -941,6 +1060,20 @@ function warnUnknownEffect(name, registry, warnings) {
941
1060
  warnings.push(`unknown effect "${name}"${suffix}`);
942
1061
  }
943
1062
  function liftTarget(spec, resolved, warnings) {
1063
+ const generator = resolved.preset.generatedTargets;
1064
+ const values = spec.params.values;
1065
+ if (generator && values !== void 0) {
1066
+ const params = { ...spec.params };
1067
+ delete params.values;
1068
+ delete params.target;
1069
+ delete params.scope;
1070
+ return {
1071
+ spec: { ...spec, params, split: void 0 },
1072
+ target: generator.selector,
1073
+ scope: "self",
1074
+ mountTargets: (host, warn) => generator.mount(host, values, warn)
1075
+ };
1076
+ }
944
1077
  if (Object.hasOwn(resolved.primitive.parameters, "target")) return { spec };
945
1078
  const target = spec.params.target;
946
1079
  if (!target) return { spec };
@@ -969,19 +1102,34 @@ function refuseContainerGate(entry, warnings) {
969
1102
  const gate = above || below ? { above, below } : void 0;
970
1103
  return { ...entry, spec: { ...spec, gate } };
971
1104
  }
972
- function refusePlayback(entry, timeline, warnings) {
1105
+ function entryPolicy(entry) {
1106
+ const declared = entry.variant?.reducedMotion ?? entry.resolved.primitive.reducedMotion;
1107
+ return entry.spec.repeat === "infinite" ? strictestPolicy(declared, "disable") : declared;
1108
+ }
1109
+ function refusePlayback(entry, timeline, repeatDelaySupport, warnings) {
973
1110
  const { spec, resolved } = entry;
974
- if (spec.repeat === void 0 && spec.yoyo === void 0) return entry;
1111
+ if (spec.repeat === void 0 && spec.yoyo === void 0 && spec.repeatDelay === void 0) return entry;
975
1112
  const { repeat, yoyo, warnings: raised } = resolvePlayback({
976
1113
  name: resolved.preset.name,
977
1114
  renderer: resolved.primitive.renderer,
978
1115
  cloak: resolved.preset.cloak,
979
1116
  timeline,
980
1117
  repeat: spec.repeat,
981
- yoyo: spec.yoyo
1118
+ yoyo: spec.yoyo,
1119
+ repeatable: resolved.primitive.repeatable === true
982
1120
  });
983
1121
  warnings.push(...raised);
984
- return { ...entry, spec: { ...spec, repeat, yoyo } };
1122
+ if (!spec.repeatDelay) return { ...entry, spec: { ...spec, repeat, yoyo } };
1123
+ const count = Number(repeat);
1124
+ const wholeRepeat = repeat === "infinite" || Number.isInteger(count) && count > 1;
1125
+ const keyframeTrack = resolved.primitive.renderer === "css-keyframes" && entry.variant?.keyframes?.length !== 0;
1126
+ const eligible = timeline === "time" && wholeRepeat && keyframeTrack;
1127
+ const reason = eligible ? "this browser lacks the required animation timing support" : "it needs a time-driven CSS keyframe track with an explicit whole repeat count above one or repeat:infinite";
1128
+ if (!eligible || repeatDelaySupport === false) {
1129
+ warnings.push(`"${spec.name}" ignores repeat-delay: ${reason}`);
1130
+ }
1131
+ const repeatDelay = eligible && repeatDelaySupport === true ? spec.repeatDelay : void 0;
1132
+ return { ...entry, spec: { ...spec, repeat, yoyo, repeatDelay } };
985
1133
  }
986
1134
  function phaseOf(entry) {
987
1135
  if (entry.spec.repeat === "infinite") return "idle";
@@ -995,7 +1143,7 @@ function additivelyComposable(entry) {
995
1143
  if (entry.variant?.keyframes) return false;
996
1144
  return additiveChannels(channelsFor(entry));
997
1145
  }
998
- function resolveComposition(entries, registry, warnings) {
1146
+ function resolveComposition(entries, registry, warnings, timeline) {
999
1147
  if (entries.length <= 1) return entries;
1000
1148
  const claims = entries.map((e) => ({
1001
1149
  name: e.spec.name,
@@ -1009,22 +1157,82 @@ function resolveComposition(entries, registry, warnings) {
1009
1157
  // the tracks. Only the losing side of a delivery clobber has to say what it is.
1010
1158
  inlineAnimation: e.resolved.primitive.renderer === "css-keyframes"
1011
1159
  }));
1160
+ const shared = timeline === "time" ? resolveHandoffs(entries, claims) : [];
1012
1161
  const conflicts = findConflicts(claims);
1013
- const clobbers = deliveryClobbers(claims);
1014
- if (conflicts.length === 0 && clobbers.length === 0) return entries;
1162
+ const clobbers = [...deliveryClobbers(claims), ...shared];
1163
+ if (conflicts.length === 0 && clobbers.length === 0) return orderHandoffs(entries, claims);
1015
1164
  if (clobbers.length === 0) {
1016
1165
  const additive = additiveResolution(claims, conflicts);
1017
- if (additive) return entries.map((e, i) => additive.has(i) ? { ...e, composite: "add" } : e);
1166
+ if (additive) return orderHandoffs(entries.map((e, i) => additive.has(i) ? { ...e, composite: "add" } : e), claims);
1018
1167
  }
1019
1168
  const combo = registry.findCombo(entries.map((e) => e.spec.name));
1020
1169
  const remedy = combo ? `Use the "${combo.preset.name}" effect instead.` : "Apply them to nested elements, or register a combined effect.";
1021
1170
  const kept = entries[0].spec.name;
1022
1171
  const dropped = entries.slice(1).map((entry) => `"${entry.spec.name}"`);
1023
1172
  const loss = `Dropped ${dropped.join(", ")} \u2014 only "${kept}" will run.`;
1024
- const diagnosis = [...conflicts.length > 0 ? [describeConflicts(conflicts)] : [], ...clobbers];
1173
+ const diagnosis = [describeConflicts(conflicts), ...clobbers].filter(Boolean);
1025
1174
  warnings.push(`cannot compose: ${diagnosis.join("; ")}. ${loss} ${remedy}`);
1026
1175
  return [entries[0]];
1027
1176
  }
1177
+ function resolveHandoffs(entries, claims) {
1178
+ const windows = entries.map((entry) => ({ step: entry.step, member: memberFor(entry), stagger: entry.stagger }));
1179
+ const shared = [];
1180
+ claims.forEach((claim, i) => {
1181
+ if (!claim.inlineAnimation) return;
1182
+ claims.slice(0, i).forEach((other, j) => {
1183
+ if (!other.inlineAnimation || !claimsOverlap(other, claim)) return;
1184
+ if (!other.channels.some((channel) => claim.channels.includes(channel))) return;
1185
+ const first = { entry: entries[j], claim: other, window: windows[j] };
1186
+ const second = { entry: entries[i], claim, window: windows[i] };
1187
+ const diagnosis = recordHandoff(first, second);
1188
+ if (diagnosis) shared.push(diagnosis);
1189
+ });
1190
+ });
1191
+ return shared;
1192
+ }
1193
+ function recordHandoff(first, second) {
1194
+ const forward = startsAfter(first.window, second.window);
1195
+ if (!forward && !startsAfter(second.window, first.window)) return;
1196
+ const before = forward ? first : second;
1197
+ const after = forward ? second : first;
1198
+ after.claim.follows ??= /* @__PURE__ */ new Set();
1199
+ after.claim.follows.add(before.claim);
1200
+ const earlier = keyframeInputs(before.entry);
1201
+ const later = keyframeInputs(after.entry);
1202
+ const clobbered = [...earlier].find(([key, value]) => later.has(key) && later.get(key) !== value);
1203
+ if (clobbered) return `"${first.claim.name}" and "${second.claim.name}" have disjoint playback but share the keyframe input ${clobbered[0]}`;
1204
+ }
1205
+ function keyframeInputs(entry) {
1206
+ const authored = authoredParams(entry);
1207
+ const isTween = entry.spec.name === "tween" || entry.spec.name === "tween-from";
1208
+ const schema = schemaFor(entry);
1209
+ const keys = isTween ? [.../* @__PURE__ */ new Set([...Object.keys(entry.variant?.schema ?? {}), ...Object.keys(authored)])] : Object.keys(schema);
1210
+ return new Map(keys.flatMap((key) => {
1211
+ const param = Object.hasOwn(schema, key) ? schema[key] : void 0;
1212
+ if (!param?.cssProperty) return [];
1213
+ const fallback = isTween ? "" : param.default;
1214
+ return [[param.cssProperty, authored[key] ?? entry.resolved.preset.params?.[key] ?? fallback]];
1215
+ }));
1216
+ }
1217
+ function orderHandoffs(entries, claims) {
1218
+ const remaining = new Map(claims.map((claim, i) => [claim, entries[i]]));
1219
+ const earlier = new Set(claims.flatMap((claim) => [...claim.follows ?? []]));
1220
+ if (earlier.size === 0) return entries;
1221
+ const ordered = [];
1222
+ for (const claim of claims) append(claim);
1223
+ return ordered;
1224
+ function append(claim) {
1225
+ const entry = remaining.get(claim);
1226
+ if (!entry) return;
1227
+ remaining.delete(claim);
1228
+ const handoff = /* @__PURE__ */ new Set();
1229
+ for (const previous of claim.follows ?? []) {
1230
+ append(previous);
1231
+ for (const channel of previous.channels) if (claim.channels.includes(channel)) handoff.add(channel);
1232
+ }
1233
+ ordered.push({ ...entry, handoff, handoffEnd: earlier.has(claim) });
1234
+ }
1235
+ }
1028
1236
  function buildPlan(entries, timeline, unknown, warnings) {
1029
1237
  const plan = emptyPlan(unknown, warnings);
1030
1238
  const tracks = emptyTracks();
@@ -1037,7 +1245,7 @@ function buildPlan(entries, timeline, unknown, warnings) {
1037
1245
  const { preset, primitive } = entry.resolved;
1038
1246
  const step = entry.step;
1039
1247
  plan.fxNames.push(preset.name);
1040
- plan.reducedMotion = strictestPolicy(plan.reducedMotion, primitive.reducedMotion);
1248
+ plan.reducedMotion = strictestPolicy(plan.reducedMotion, entryPolicy(entry));
1041
1249
  activations = intersect(activations, primitive.supportedActivations);
1042
1250
  plan.activationClaims.push({
1043
1251
  supported: primitive.supportedActivations,
@@ -1051,11 +1259,12 @@ function buildPlan(entries, timeline, unknown, warnings) {
1051
1259
  resolveParams(authoredParams(entry), schemaFor(entry), (m) => warnings.push(m))
1052
1260
  );
1053
1261
  if (primitive.renderer === "css-keyframes") pushTrack(tracks, entry, step);
1054
- else plan.jsEffects.push(positioned(entry, step));
1262
+ if (primitive.renderer !== "css-keyframes" || entry.variant?.prepare) plan.jsEffects.push(positioned(entry, step));
1055
1263
  pushTransitions(transitionSegments, transitionOwners, entry, warnings);
1056
1264
  }
1057
1265
  Object.assign(plan.declarations, declarationsFor(tracks, timeline));
1058
1266
  plan.keyframeNames = tracks.keyframes;
1267
+ if (tracks.repeatDelays) plan.repeatDelays = tracks.repeatDelays;
1059
1268
  if (transitionSegments.length > 0) plan.transition = transitionSegments.join(", ");
1060
1269
  plan.supportedActivations = activations;
1061
1270
  plan.supportedTimelines = timelines;
@@ -1074,7 +1283,8 @@ function memberFor(entry) {
1074
1283
  duration: spec.duration,
1075
1284
  cascadeDelay: cascadeValue(authored, preset, primitive.parameters, "delay"),
1076
1285
  cascadeDuration: cascadeValue(authored, preset, primitive.parameters, "duration"),
1077
- repeat: spec.repeat,
1286
+ repeat: spec.repeat ?? (primitive.renderer === "css-keyframes" && preset.phase === "idle" ? "infinite" : void 0),
1287
+ repeatDelay: spec.repeatDelay,
1078
1288
  // A `css-keyframes` segment is always positionable — it compiles to an `animation-delay` and
1079
1289
  // the browser honours it. A JavaScript-rendered one is positionable only if it declares the
1080
1290
  // parameter, which is the single compile-time signal that it reads a delay at all.
@@ -1096,6 +1306,108 @@ function warnUnsupportedTimeline(name, supported, timeline, warnings) {
1096
1306
  );
1097
1307
  }
1098
1308
 
1309
+ // src/core/cadence.ts
1310
+ function createCadence(request) {
1311
+ const { el, periodMs, host, tick, warn } = request;
1312
+ const period = clampPeriod(periodMs);
1313
+ if (period === 0) {
1314
+ warn("every: needs a period above zero, such as every:3s; no cadence started");
1315
+ return { release() {
1316
+ } };
1317
+ }
1318
+ if (period !== periodMs) {
1319
+ warn(`every: minimum is ${MIN_PERIOD_MS / 1e3}s; clamped to ${period / 1e3}s`);
1320
+ }
1321
+ const motion = createAutoMotion({
1322
+ el,
1323
+ ctx: host,
1324
+ spinMs: 0,
1325
+ autoplayMs: period,
1326
+ settleMs: 0,
1327
+ pauseOnHover: false,
1328
+ step: () => tick(),
1329
+ onPausedChange: () => {
1330
+ }
1331
+ });
1332
+ return { release: () => motion.release() };
1333
+ }
1334
+ function everyToMs(every) {
1335
+ const token = every.trim();
1336
+ const milliseconds = token.endsWith("ms");
1337
+ if (!milliseconds && !token.endsWith("s")) return Number.NaN;
1338
+ const value = Number(token.slice(0, milliseconds ? -2 : -1));
1339
+ return value * (milliseconds ? 1 : 1e3);
1340
+ }
1341
+ function cycleThunks(el, document2, warn) {
1342
+ const doc = el.ownerDocument;
1343
+ const ctx = { doc, win: doc.defaultView ?? globalThis, warn };
1344
+ const thunks = [];
1345
+ const host = document2.targets.find((target) => target.selector === "");
1346
+ for (const entry of host?.plan.jsEffects ?? []) {
1347
+ const cycle = entry.resolved.primitive.cycle;
1348
+ if (!cycle) continue;
1349
+ const params = readEffectParams(
1350
+ { ...entry.resolved.preset.params, ...authoredParams(entry) },
1351
+ schemaFor(entry),
1352
+ warn
1353
+ );
1354
+ const name = entry.spec.name;
1355
+ thunks.push(() => {
1356
+ try {
1357
+ cycle.call(entry.resolved.primitive, el, params, ctx);
1358
+ } catch (error) {
1359
+ warn(`"${name}" failed to cycle: ${String(error)}`);
1360
+ }
1361
+ });
1362
+ }
1363
+ return thunks;
1364
+ }
1365
+ function hasGroupedCycle(document2) {
1366
+ return document2.targets.some(
1367
+ (target) => target.selector !== "" && target.plan.jsEffects.some((entry) => entry.resolved.primitive.cycle)
1368
+ );
1369
+ }
1370
+
1371
+ // src/core/capabilities.ts
1372
+ function supports(property, value) {
1373
+ if (typeof CSS === "undefined" || typeof CSS.supports !== "function") return false;
1374
+ try {
1375
+ return CSS.supports(property, value);
1376
+ } catch {
1377
+ return false;
1378
+ }
1379
+ }
1380
+ var cached;
1381
+ function detect(force = false) {
1382
+ if (cached && !force) return cached;
1383
+ cached = {
1384
+ viewTimeline: supports("animation-timeline", "view()"),
1385
+ scrollTimeline: supports("animation-timeline", "scroll()"),
1386
+ animationRange: supports("animation-range", "entry 0% cover 30%"),
1387
+ // `translate`/`rotate`/`scale` as independent properties is what makes the channel model
1388
+ // possible at all — under the `transform` shorthand every effect would collide.
1389
+ individualTransforms: supports("translate", "0 10px") && supports("scale", "1.1"),
1390
+ scrollTimelineName: supports("scroll-timeline-name", "--x"),
1391
+ viewTransitions: typeof document !== "undefined" && "startViewTransition" in document,
1392
+ intersectionObserver: typeof IntersectionObserver !== "undefined",
1393
+ reducedMotion: typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches,
1394
+ motionPath: supports("offset-path", 'path("M 0 0")')
1395
+ };
1396
+ return cached;
1397
+ }
1398
+ var CHANNEL_REQUIREMENTS = [
1399
+ {
1400
+ channel: "offset",
1401
+ capability: "motionPath",
1402
+ message: "this browser does not support CSS Motion Path (offset-path), so the element will not travel \u2014 the animation still runs and completes, it just has no path to follow"
1403
+ }
1404
+ ];
1405
+ function unsupportedChannelWarnings(channels, capabilities) {
1406
+ return CHANNEL_REQUIREMENTS.filter(
1407
+ (entry) => channels.includes(entry.channel) && !capabilities[entry.capability]
1408
+ ).map((entry) => entry.message);
1409
+ }
1410
+
1099
1411
  // src/core/derived/book.ts
1100
1412
  function createDerivedBook() {
1101
1413
  return {
@@ -1235,7 +1547,7 @@ function planStyles(input) {
1235
1547
  }
1236
1548
  function timelineMode(plan, config, capabilities) {
1237
1549
  const scrubbed = config.timeline === "pin" && plan.supportedTimelines.includes("pin");
1238
- const useNativeTimeline = !scrubbed && supportsTimeline(config.timeline, capabilities) && plan.supportedTimelines.includes(config.timeline);
1550
+ const useNativeTimeline = !scrubbed && supportsTimeline(config.timeline, capabilities) && (!config.timelineName || capabilities.scrollTimelineName) && plan.supportedTimelines.includes(config.timeline);
1239
1551
  return { scrubbed, useNativeTimeline };
1240
1552
  }
1241
1553
  function transitionProperty(plan) {
@@ -1244,7 +1556,7 @@ function transitionProperty(plan) {
1244
1556
  function timelineProperties(config, capabilities, useNativeTimeline) {
1245
1557
  if (!useNativeTimeline) return {};
1246
1558
  const properties = {
1247
- "animation-timeline": config.timeline === "scroll" ? "scroll()" : "view()"
1559
+ "animation-timeline": config.timelineName ?? `${config.timeline}(${config.timelineAxis ?? ""})`
1248
1560
  };
1249
1561
  if (capabilities.animationRange) {
1250
1562
  properties["animation-range"] = config.range || (config.timeline === "scroll" ? "0% 100%" : "entry 0% cover 60%");
@@ -1275,45 +1587,10 @@ function effectiveActivation(config) {
1275
1587
  return config.activation;
1276
1588
  }
1277
1589
 
1278
- // src/core/stagger-keys.ts
1279
- var GROUP_KEY_NAMES = ["cascade", "spread", "order", "cols", "along"];
1280
- function collectKeys(lookup) {
1281
- const keys = {};
1282
- for (const name of GROUP_KEY_NAMES) {
1283
- const value = lookup(name);
1284
- if (value !== void 0) keys[name] = value;
1285
- }
1286
- return Object.keys(keys).length > 0 ? keys : void 0;
1287
- }
1288
- function elementStaggerKeys(parsed) {
1289
- return collectKeys((name) => parsed[name]);
1290
- }
1291
- function staggerKeysFor(scoped, elementWide) {
1292
- return collectKeys((name) => scoped?.[name] ?? elementWide?.[name]);
1293
- }
1294
- function isGroupedKeys(keys) {
1295
- return keys?.cascade !== void 0 || keys?.spread !== void 0 || keys?.order !== void 0;
1296
- }
1297
- var TARGET_GROUP_HOSTS = /* @__PURE__ */ new WeakMap();
1298
- function claimTargetGroupHost(host) {
1299
- TARGET_GROUP_HOSTS.set(host, (TARGET_GROUP_HOSTS.get(host) ?? 0) + 1);
1300
- let released = false;
1301
- return () => {
1302
- if (released) return;
1303
- released = true;
1304
- const remaining = TARGET_GROUP_HOSTS.get(host) - 1;
1305
- if (remaining > 0) TARGET_GROUP_HOSTS.set(host, remaining);
1306
- else TARGET_GROUP_HOSTS.delete(host);
1307
- };
1308
- }
1309
- function isTargetGroupHost(el) {
1310
- return TARGET_GROUP_HOSTS.has(el);
1311
- }
1312
-
1313
1590
  // src/core/derived/group-gate.ts
1314
1591
  function groupGateOwner(port, context, target) {
1315
1592
  const keys = staggerKeysFor(target.hoists, elementStaggerKeys(context.parsed));
1316
- return isGroupedKeys(keys) ? context.host : void 0;
1593
+ return target.split || isGroupedKeys(keys) ? context.host : void 0;
1317
1594
  }
1318
1595
  function skipsOwnBinding(state) {
1319
1596
  return state.gateOwner !== void 0;
@@ -1358,415 +1635,6 @@ function bindGroups(port, host) {
1358
1635
  }
1359
1636
  }
1360
1637
 
1361
- // src/core/stagger-config.ts
1362
- var FROM_KEYWORDS = /* @__PURE__ */ new Set(["start", "end", "center", "edges", "random"]);
1363
- var ORDER_KEYS = /* @__PURE__ */ new Set(["from", "order"]);
1364
- var SPREAD_KEY = "spread";
1365
- var COLS_KEY = "cols";
1366
- var AXIS_KEYS = /* @__PURE__ */ new Set(["axis", "along"]);
1367
- var AXIS_VALUES = /* @__PURE__ */ new Set(["x", "y"]);
1368
- var ORIGIN_RE = /^(\d+(?:\.\d+)?|\.\d+)\/(\d+(?:\.\d+)?|\.\d+)$/;
1369
- var COLS_RE = /^\d{1,9}$/;
1370
- var PAIR_RE = /^([a-zA-Z-]+):(.*)$/;
1371
- var INDEX_RE = /^-?\d{1,9}$/;
1372
- function parseStaggerTokens(value, warnings) {
1373
- const config = { from: "start" };
1374
- const seen = { from: false, spread: false, cols: false, along: false };
1375
- for (const token of splitTopLevel(value, " ", warnings)) {
1376
- const pair = PAIR_RE.exec(token);
1377
- if (pair) applyStaggerPair(pair[1], pair[2], { config, seen, warnings });
1378
- else config.step = keepFirstStep(config.step, token, warnings);
1379
- }
1380
- return { config, sawFrom: seen.from };
1381
- }
1382
- function applyStaggerPair(key, raw, state) {
1383
- const slot = slotFor(key);
1384
- if (slot === void 0) {
1385
- state.warnings.push(
1386
- `unrecognised key "${key}" in data-kui-stagger \u2014 expected a time step, "spread:", "cols:", "along:", "from:" or "order:"`
1387
- );
1388
- return;
1389
- }
1390
- if (claim(slot, raw, state, key)) ASSIGN[slot](raw, state, key);
1391
- }
1392
- function slotFor(key) {
1393
- if (key === SPREAD_KEY) return "spread";
1394
- if (key === COLS_KEY) return "cols";
1395
- if (AXIS_KEYS.has(key)) return "along";
1396
- if (ORDER_KEYS.has(key)) return "from";
1397
- return void 0;
1398
- }
1399
- var ASSIGN = {
1400
- spread: (raw, state) => {
1401
- state.config.spread = raw.trim();
1402
- },
1403
- cols: (raw, state) => {
1404
- state.config.cols = parseCols(raw, state.warnings);
1405
- },
1406
- along: (raw, state, key) => {
1407
- state.config.along = parseAxis(raw, state.warnings, key);
1408
- },
1409
- from: (raw, state, key) => {
1410
- state.config.from = parseFrom(raw, state.warnings, key);
1411
- }
1412
- };
1413
- function claim(slot, raw, state, spelling) {
1414
- if (state.seen[slot]) {
1415
- state.warnings.push(`duplicate "${spelling}:" in data-kui-stagger \u2014 "${raw}" ignored`);
1416
- return false;
1417
- }
1418
- state.seen[slot] = true;
1419
- return true;
1420
- }
1421
- function parseCols(raw, warnings) {
1422
- const value = raw.trim();
1423
- if (value === "auto") return "auto";
1424
- if (COLS_RE.test(value) && Number(value) > 0) return Number(value);
1425
- warnings.push(`unrecognised "cols:${raw}" \u2014 expected a column count or "auto"`);
1426
- return void 0;
1427
- }
1428
- function parseAxis(raw, warnings, key) {
1429
- const value = raw.trim();
1430
- if (AXIS_VALUES.has(value)) return value;
1431
- warnings.push(`unrecognised "${key}:${raw}" \u2014 expected x or y`);
1432
- return void 0;
1433
- }
1434
- function resolveStaggerConfig(attribute, source, warnings = []) {
1435
- const inline = inlineGroupKeys(source);
1436
- if (attribute === null && inline === void 0) return void 0;
1437
- return resolveStaggerConfigFrom(attribute, inline, warnings);
1438
- }
1439
- function resolveStaggerConfigFrom(attribute, inline, warnings = []) {
1440
- if (attribute === null && inline === void 0) return void 0;
1441
- const { config: longhand, sawFrom } = parseStaggerTokens(attribute ?? "", warnings);
1442
- return oneStepMode(screenStep(mergeInline(longhand, sawFrom, inline ?? {}, warnings), warnings), warnings);
1443
- }
1444
- function oneStepMode(config, warnings) {
1445
- if (config.spread === void 0 || config.step === void 0) return config;
1446
- warnings.push(
1447
- `stagger step "${config.step}" is ignored \u2014 "spread:${config.spread}" already budgets the whole group, and the step is what it divides out`
1448
- );
1449
- const budgeted = { ...config };
1450
- delete budgeted.step;
1451
- return budgeted;
1452
- }
1453
- function inlineGroupKeys(source) {
1454
- if (!hasGroupKey(source)) return void 0;
1455
- const { cascade, spread, order, cols, along } = parse(source);
1456
- const keys = { cascade, spread, order, cols, along };
1457
- return Object.values(keys).some((value) => value !== void 0) ? keys : void 0;
1458
- }
1459
- function screenStep(config, warnings) {
1460
- const screened = { ...config };
1461
- if (!keepValue("step", config.step, warnings)) delete screened.step;
1462
- if (!keepValue("spread", config.spread, warnings)) delete screened.spread;
1463
- return screened;
1464
- }
1465
- function keepValue(label, value, warnings) {
1466
- if (value === void 0) return false;
1467
- if (isSafeCssValue(value)) return true;
1468
- warnings.push(`stagger ${label} "${value}" contains disallowed CSS syntax \u2014 ignored`);
1469
- return false;
1470
- }
1471
- function mergeInline(longhand, sawFrom, inline, warnings) {
1472
- const config = { ...longhand };
1473
- if (inline.cascade !== void 0) {
1474
- warnOverride("stagger step", longhand.step, inline.cascade, warnings);
1475
- config.step = inline.cascade;
1476
- }
1477
- if (inline.spread !== void 0) {
1478
- warnOverride("stagger budget", longhand.spread, inline.spread, warnings);
1479
- config.spread = inline.spread;
1480
- }
1481
- mergeInlineGrid(config, longhand, inline, warnings);
1482
- if (inline.order !== void 0) {
1483
- const order = parseFrom(inline.order, warnings, "order");
1484
- warnOverride("stagger order", sawFrom ? longhand.from : void 0, order, warnings);
1485
- config.from = order;
1486
- }
1487
- return config;
1488
- }
1489
- function mergeInlineGrid(config, longhand, inline, warnings) {
1490
- if (inline.cols !== void 0) {
1491
- const cols = parseCols(inline.cols, warnings);
1492
- warnOverride("stagger columns", longhand.cols, cols, warnings);
1493
- if (cols !== void 0) config.cols = cols;
1494
- }
1495
- if (inline.along !== void 0) {
1496
- const along = parseAxis(inline.along, warnings, "along");
1497
- warnOverride("stagger axis", longhand.along, along, warnings);
1498
- if (along !== void 0) config.along = along;
1499
- }
1500
- }
1501
- function hasGroupKey(source) {
1502
- return GROUP_KEY_PREFIXES.some((prefix) => source.includes(prefix));
1503
- }
1504
- var GROUP_KEY_PREFIXES = [
1505
- "cascade:",
1506
- "spread:",
1507
- "order:",
1508
- "cols:",
1509
- "along:"
1510
- ];
1511
- function warnOverride(label, previous, next, warnings) {
1512
- if (previous === void 0 || next === void 0 || previous === next) return;
1513
- warnings.push(
1514
- `conflicting ${label}: data-kui-stagger says "${String(previous)}", data-kui says "${String(next)}" \u2014 data-kui wins`
1515
- );
1516
- }
1517
- function keepFirstStep(current, token, warnings) {
1518
- if (current === void 0) return token;
1519
- warnings.push(`extra token "${token}" in data-kui-stagger (expected one time step)`);
1520
- return current;
1521
- }
1522
- function parseFrom(raw, warnings, key = "from") {
1523
- const value = raw.trim();
1524
- if (FROM_KEYWORDS.has(value)) return value;
1525
- if (INDEX_RE.test(value)) return Number(value);
1526
- const origin = ORIGIN_RE.exec(value);
1527
- if (origin) return { x: clamp01(Number(origin[1]), value, warnings), y: clamp01(Number(origin[2]), value, warnings) };
1528
- warnings.push(
1529
- `unrecognised "${key}:${raw}" \u2014 expected start, end, center, edges, random, a child index, or an "x/y" point in a grid`
1530
- );
1531
- return "start";
1532
- }
1533
- function clamp01(value, source, warnings) {
1534
- if (value >= 0 && value <= 1) return value;
1535
- warnings.push(`stagger order "${source}" is outside the grid (0 to 1 on each axis) \u2014 clamped`);
1536
- return Math.min(Math.max(value, 0), 1);
1537
- }
1538
-
1539
- // src/core/stagger.ts
1540
- var RANK_PRECISION = 1e3;
1541
- var RANDOM_SALT = 2654435761;
1542
- var COUNT_SALT = 2246822507;
1543
- var MIX_A = 569420461;
1544
- var MIX_B = 1935289751;
1545
- function resolveStep(config, maxRank) {
1546
- if (config.spread === void 0) return config.step;
1547
- if (maxRank <= 0) return "0ms";
1548
- return `calc((${config.spread}) / ${String(maxRank)})`;
1549
- }
1550
- function staggerRanks(count, from, warnings = [], layout) {
1551
- if (count <= 0) return [];
1552
- if (from === "random") return randomRanks(count);
1553
- if (layout) return gridRanks(count, from, layout, warnings);
1554
- if (typeof from === "object") {
1555
- warnings.push(
1556
- `stagger order "${String(from.x)}/${String(from.y)}" is a point in a grid, but this group has no "cols:" \u2014 add one, or name an edge with start/end/center/edges`
1557
- );
1558
- return staggerRanks(count, "start", warnings);
1559
- }
1560
- const last = count - 1;
1561
- if (from === "edges") {
1562
- return Array.from({ length: count }, (_, index) => Math.min(index, last - index));
1563
- }
1564
- const origin = originOf(from, last, warnings);
1565
- return Array.from({ length: count }, (_, index) => Math.floor(Math.abs(index - origin)));
1566
- }
1567
- function originOf(from, last, warnings) {
1568
- if (from === "start") return 0;
1569
- if (from === "end") return last;
1570
- if (from === "center") return last / 2;
1571
- return clampIndex(from, last, warnings);
1572
- }
1573
- function clampIndex(index, last, warnings) {
1574
- if (index < 0 || index > last) {
1575
- warnings.push(`stagger order "${String(index)}" is outside the group (0 to ${String(last)}) \u2014 clamped`);
1576
- }
1577
- return Math.min(Math.max(index, 0), last);
1578
- }
1579
- function gridRanks(count, from, layout, warnings) {
1580
- const cols = Math.min(Math.max(1, layout.cols), count);
1581
- const rows = Math.ceil(count / cols);
1582
- if (from === "edges") {
1583
- const inward = gridRanks(count, "center", layout, warnings);
1584
- let furthest = 0;
1585
- for (const rank of inward) furthest = Math.max(furthest, rank);
1586
- return inward.map((rank) => round(furthest - rank));
1587
- }
1588
- const origin = gridOrigin(from, { cols, rows, last: count - 1 }, warnings);
1589
- return Array.from({ length: count }, (_, index) => {
1590
- const dx = index % cols - origin.x;
1591
- const dy = Math.floor(index / cols) - origin.y;
1592
- if (layout.along === "x") return round(Math.abs(dx));
1593
- if (layout.along === "y") return round(Math.abs(dy));
1594
- return round(Math.hypot(dx, dy));
1595
- });
1596
- }
1597
- function gridOrigin(from, grid, warnings) {
1598
- const { cols, rows, last } = grid;
1599
- if (typeof from === "object") return { x: from.x * (cols - 1), y: from.y * (rows - 1) };
1600
- if (from === "start") return { x: 0, y: 0 };
1601
- if (from === "end") return { x: cols - 1, y: rows - 1 };
1602
- if (from === "center") return { x: (cols - 1) / 2, y: (rows - 1) / 2 };
1603
- const index = clampIndex(from, last, warnings);
1604
- return { x: index % cols, y: Math.floor(index / cols) };
1605
- }
1606
- function round(value) {
1607
- return Math.round(value * RANK_PRECISION) / RANK_PRECISION;
1608
- }
1609
- function randomRanks(count) {
1610
- const order = Array.from({ length: count }, (_, index) => index);
1611
- order.sort((a, b) => scatterKey(a, count) - scatterKey(b, count));
1612
- const ranks = new Array(count);
1613
- for (const [rank, index] of order.entries()) ranks[index] = rank;
1614
- return ranks;
1615
- }
1616
- function scatterKey(index, count) {
1617
- let hash = (Math.imul(index, RANDOM_SALT) ^ Math.imul(count, COUNT_SALT)) >>> 0;
1618
- hash ^= hash >>> 16;
1619
- hash = Math.imul(hash, MIX_A) >>> 0;
1620
- hash ^= hash >>> 15;
1621
- hash = Math.imul(hash, MIX_B) >>> 0;
1622
- hash ^= hash >>> 15;
1623
- return hash >>> 0;
1624
- }
1625
- function indexStaggerGroup(group, reporter) {
1626
- const warnings = [];
1627
- const ledgers = reopenLedger(group);
1628
- const config = resolveStaggerConfig(
1629
- group.getAttribute(ATTR.stagger),
1630
- group.getAttribute(ATTR.source) ?? "",
1631
- warnings
1632
- ) ?? { from: "start" };
1633
- const children = animatedChildren(group);
1634
- const ranks = staggerRanks(children.length, config.from, warnings, resolveLayout(config, children, warnings));
1635
- let maxRank = 0;
1636
- for (const [index, child] of children.entries()) {
1637
- const rank = ranks[index];
1638
- ledgers.style(child).set("--kui-i", String(rank));
1639
- GROUP_OF_CHILD.set(child, group);
1640
- if (rank > maxRank) maxRank = rank;
1641
- }
1642
- const step = resolveStep(config, maxRank);
1643
- if (step) ledgers.style(group).set("--kui-stagger", step);
1644
- ledgers.style(group).set("--kui-stagger-count", String(round(maxRank + 1)));
1645
- for (const warning of warnings) reporter?.warn(warning, group);
1646
- }
1647
- var GROUP_LEDGERS = /* @__PURE__ */ new WeakMap();
1648
- var GROUP_OF_CHILD = /* @__PURE__ */ new WeakMap();
1649
- function restageAfterRemoval(removed, reporter) {
1650
- const groups = /* @__PURE__ */ new Set();
1651
- for (const el of removed) {
1652
- const group = GROUP_OF_CHILD.get(el);
1653
- if (group) groups.add(group);
1654
- }
1655
- for (const group of groups) indexStaggerGroup(group, reporter);
1656
- }
1657
- function reopenLedger(group) {
1658
- GROUP_LEDGERS.get(group)?.restore();
1659
- const ledgers = createLedgerSet(group);
1660
- GROUP_LEDGERS.set(group, ledgers);
1661
- return ledgers;
1662
- }
1663
- function releaseStaggerGroup(group) {
1664
- GROUP_LEDGERS.get(group)?.restore();
1665
- GROUP_LEDGERS.delete(group);
1666
- }
1667
- function releaseStagger(root) {
1668
- const selector = `[${ATTR.stagger}], [${ATTR.source}]`;
1669
- if (root instanceof Element && root.matches(selector)) releaseStaggerGroup(root);
1670
- for (const el of root.querySelectorAll(selector)) releaseStaggerGroup(el);
1671
- }
1672
- function restageAround(el, reporter) {
1673
- restageOne(el, reporter);
1674
- const parent = el.parentElement;
1675
- if (parent) restageOne(parent, reporter);
1676
- }
1677
- function restageOne(el, reporter) {
1678
- if (declaresGroup(el)) indexStaggerGroup(el, reporter);
1679
- else releaseStaggerGroup(el);
1680
- }
1681
- function indexTargetGroup(request) {
1682
- const { host, matches, styleOf, keys, reporter } = request;
1683
- const warnings = [];
1684
- const attribute = host.getAttribute(ATTR.stagger);
1685
- const config = (keys ? resolveStaggerConfigFrom(attribute, keys, warnings) : resolveStaggerConfig(attribute, host.getAttribute(ATTR.source) ?? "", warnings)) ?? { from: "start" };
1686
- const maxRank = rankBuckets(bucketByParent(matches), config, styleOf, warnings);
1687
- const step = resolveStep(config, maxRank);
1688
- if (step) styleOf(host).set("--kui-stagger", step);
1689
- styleOf(host).set("--kui-stagger-count", String(round(maxRank + 1)));
1690
- for (const warning of warnings) reporter?.warn(warning, host);
1691
- }
1692
- function bucketByParent(matches) {
1693
- const byParent = /* @__PURE__ */ new Map();
1694
- for (const match of matches) {
1695
- const siblings = byParent.get(match.parentElement);
1696
- if (siblings) siblings.push(match);
1697
- else byParent.set(match.parentElement, [match]);
1698
- }
1699
- return byParent;
1700
- }
1701
- function rankBuckets(byParent, config, styleOf, warnings) {
1702
- let maxRank = 0;
1703
- for (const siblings of byParent.values()) {
1704
- const layout = resolveLayout(config, siblings, warnings);
1705
- const ranks = staggerRanks(siblings.length, config.from, warnings, layout);
1706
- for (const [index, match] of siblings.entries()) {
1707
- const rank = ranks[index];
1708
- styleOf(match).set("--kui-i", String(rank));
1709
- if (rank > maxRank) maxRank = rank;
1710
- }
1711
- }
1712
- return maxRank;
1713
- }
1714
- function resolveLayout(config, members, warnings) {
1715
- if (config.cols === void 0) {
1716
- if (config.along !== void 0) {
1717
- warnings.push(
1718
- `"along:${config.along}" names an axis of a grid this group has not declared \u2014 add "cols:" (a column count, or "auto")`
1719
- );
1720
- }
1721
- return void 0;
1722
- }
1723
- const cols = config.cols === "auto" ? measureColumns(members, warnings) : config.cols;
1724
- if (cols === void 0) return void 0;
1725
- return config.along === void 0 ? { cols } : { cols, along: config.along };
1726
- }
1727
- function measureColumns(members, warnings) {
1728
- if (members.length < 2) return 1;
1729
- const lefts = [];
1730
- let laidOut = false;
1731
- for (const member of members) {
1732
- const box = member.getBoundingClientRect();
1733
- if (box.width !== 0 || box.height !== 0) laidOut = true;
1734
- lefts.push(box.left);
1735
- }
1736
- if (!laidOut) {
1737
- warnings.push(
1738
- `"cols:auto" could not measure this group \u2014 none of its children have been laid out yet (display:none, or detached), so the stagger falls back to DOM order`
1739
- );
1740
- return void 0;
1741
- }
1742
- const direction = Math.sign(lefts[1] - lefts[0]);
1743
- if (direction === 0) return 1;
1744
- let cols = 1;
1745
- for (let index = 1; index < lefts.length; index++) {
1746
- if (Math.sign(lefts[index] - lefts[index - 1]) !== direction) break;
1747
- cols = index + 1;
1748
- }
1749
- return cols;
1750
- }
1751
- function animatedChildren(group) {
1752
- const children = [];
1753
- for (const child of group.children) {
1754
- if (child.hasAttribute(ATTR.source)) children.push(child);
1755
- }
1756
- return children;
1757
- }
1758
- function applyStagger(root, reporter) {
1759
- const selector = `[${ATTR.stagger}], [${ATTR.source}]`;
1760
- if (root instanceof Element && root.matches(selector)) restageOne(root, reporter);
1761
- for (const group of root.querySelectorAll(selector)) restageOne(group, reporter);
1762
- }
1763
- function declaresGroup(el) {
1764
- if (el.hasAttribute(ATTR.define)) return false;
1765
- if (isTargetGroupHost(el)) return false;
1766
- if (el.hasAttribute(ATTR.stagger)) return true;
1767
- return resolveStaggerConfig(null, el.getAttribute(ATTR.source) ?? "") !== void 0;
1768
- }
1769
-
1770
1638
  // src/core/derived/diagnostics.ts
1771
1639
  var ANCESTOR_WALK_BOUND = 64;
1772
1640
  function describe(el) {
@@ -1834,6 +1702,7 @@ function formerHostOf(book, match) {
1834
1702
  return FORMER_HOST.get(book)?.get(match);
1835
1703
  }
1836
1704
  function targetKey(target) {
1705
+ if (target.split) return `split ${target.split}`;
1837
1706
  return `${target.scope} ${target.selector}`;
1838
1707
  }
1839
1708
  function matchKey(targets) {
@@ -1847,13 +1716,16 @@ function groupConfigFor(port, context, target, cache) {
1847
1716
  cache.set(target, config);
1848
1717
  return config;
1849
1718
  }
1850
- function resolveGroups(port, context, targets, cache) {
1719
+ function resolveGroups(port, context, { targets, pieces }, cache) {
1851
1720
  const live = [];
1852
1721
  const resolved = [];
1853
1722
  const unmatched = [];
1854
- for (const target of targets) {
1855
- if (target.selector === "") continue;
1856
- const matches = port.resolveGroupMatches(context.host, target);
1723
+ const mounted = new Map(targets.flatMap((target) => target.mountTargets ? [[target, target.mountTargets(context.host, (message) => port.reporter.warn(message, context.host))]] : []));
1724
+ if (targets.every((target) => mounted.get(target)?.length === 0)) return void 0;
1725
+ for (const target of targets.filter((group) => group.split ? pieces.length > 0 : group.selector !== "")) {
1726
+ const marks = mounted.get(target);
1727
+ if (marks?.length === 0) continue;
1728
+ const matches = marks ?? (target.split ? pieces : port.resolveGroupMatches(context.host, target));
1857
1729
  if (matches.length === 0) unmatched.push(target.selector);
1858
1730
  resolved.push({ target, matches });
1859
1731
  live.push({
@@ -1863,7 +1735,7 @@ function resolveGroups(port, context, targets, cache) {
1863
1735
  members: []
1864
1736
  });
1865
1737
  }
1866
- return { live, resolved, unmatched };
1738
+ return { live, resolved, unmatched, generated: [...mounted.values()].flat() };
1867
1739
  }
1868
1740
  function buildContext(request) {
1869
1741
  const baseConfig = request.baseConfig;
@@ -1897,6 +1769,8 @@ function finalizeInstall(port, context, input) {
1897
1769
  registerCleanup2(port, host, claimTargetGroupHost(host));
1898
1770
  restageTargets(port, host);
1899
1771
  bindGroups(port, host);
1772
+ if (input.restoreSplit) registerCleanup2(port, host, input.restoreSplit);
1773
+ if (input.generated.length) registerCleanup2(port, host, () => input.generated.forEach((el) => el.remove()));
1900
1774
  for (const [match, targets] of input.claims) {
1901
1775
  warnNested3d(port, host, match, installedTargetFor(port, context, targets));
1902
1776
  }
@@ -1905,20 +1779,60 @@ function finalizeInstall(port, context, input) {
1905
1779
  }
1906
1780
  function installWithTargets(port, request) {
1907
1781
  const context = buildContext(request);
1782
+ const { host } = context;
1783
+ const { targets } = request.document;
1784
+ const group = targets.find((target) => target.split);
1785
+ const stage = makeSplitStage(port, host, group);
1908
1786
  const cache = /* @__PURE__ */ new Map();
1909
- const { live, resolved, unmatched } = resolveGroups(port, context, request.document.targets, cache);
1787
+ const groups = resolveGroups(port, context, { targets, pieces: stage.cells }, cache);
1788
+ if (!groups) return;
1789
+ const { live, resolved, unmatched, generated } = groups;
1910
1790
  port.book.contexts.set(context.host, context);
1911
1791
  port.book.groups.set(context.host, live);
1912
1792
  const claims = claimMatches(port, context.host, resolved);
1913
- const own = request.document.targets.find((target) => target.selector === "");
1914
- if (!own && claims.size === 0) {
1793
+ const own = targets.find((target) => target.selector === "" && !target.split);
1794
+ if (!own && claims.size === 0 && !stage.onReady) {
1915
1795
  context.host.setAttribute(ATTR.state, "failed");
1916
1796
  markUnmatched(context.host, [...unmatched, ...request.document.suspectSelectors ?? []]);
1917
1797
  return;
1918
1798
  }
1919
1799
  installDerivedMatches(port, context, claims, cache);
1920
1800
  installHostGroup(port, request, own);
1921
- finalizeInstall(port, context, { claims, resolved, unmatched, suspects: request.document.suspectSelectors });
1801
+ finalizeInstall(port, context, { claims, resolved, unmatched, suspects: request.document.suspectSelectors, restoreSplit: stage.restore, generated });
1802
+ if (stage.onReady) {
1803
+ const state = port.stateOf(host);
1804
+ if (!own && claims.size === 0) port.writeStatus(host, state, "pending");
1805
+ armSplitGroup(port, context, { stage, target: group, cache });
1806
+ }
1807
+ }
1808
+ function makeSplitStage(port, host, group) {
1809
+ if (!group?.split) return { cells: [] };
1810
+ const install = port.registry.getSplitProvider(group.split);
1811
+ if (!install) {
1812
+ port.reporter.warn(`split:${group.split} is unavailable \u2014 no split provider is registered`, host);
1813
+ return { cells: [] };
1814
+ }
1815
+ return install(host, group, port.reporter) ?? { cells: [] };
1816
+ }
1817
+ function armSplitGroup(port, context, { stage, target, cache }) {
1818
+ const { host } = context;
1819
+ const root = host.getRootNode();
1820
+ const state = port.stateOf(host);
1821
+ stage.onReady?.((cells) => {
1822
+ if (port.stateOf(host) !== state || host.getRootNode() !== root) return;
1823
+ const group = {
1824
+ target,
1825
+ config: groupConfigFor(port, context, target, cache),
1826
+ gateOwner: groupGateOwner(port, context, target),
1827
+ members: []
1828
+ };
1829
+ port.book.groups.get(host).push(group);
1830
+ const claims = claimMatches(port, host, [{ target, matches: cells }]);
1831
+ installDerivedMatches(port, context, claims, cache);
1832
+ restageTargets(port, host);
1833
+ if (group.gateOwner === host) bindOneGroup(port, host, group);
1834
+ syncAggregate(port, host);
1835
+ });
1922
1836
  }
1923
1837
  function releaseMatch(port, host, match) {
1924
1838
  const { book } = port;
@@ -1946,7 +1860,7 @@ function releaseDerived(port, el) {
1946
1860
  releaseMatch(port, host, el);
1947
1861
  return;
1948
1862
  }
1949
- if (port.book.derived.has(el)) releaseHost(port, el);
1863
+ if (port.book.derived.has(el) || port.book.cleanups.has(el)) releaseHost(port, el);
1950
1864
  }
1951
1865
  function restageAfterTreeRelease(port, removed) {
1952
1866
  const formerHosts = /* @__PURE__ */ new Set();
@@ -2009,35 +1923,35 @@ function matchGateOwner(port, context, targets) {
2009
1923
  const grouped = targets.some((target) => groupGateOwner(port, context, target) !== void 0);
2010
1924
  return grouped ? context.host : void 0;
2011
1925
  }
2012
- function recordClaim(port, context, claim2) {
1926
+ function recordClaim(port, context, claim) {
2013
1927
  const { book } = port;
2014
- book.hosts.set(claim2.match, context.host);
1928
+ book.hosts.set(claim.match, context.host);
2015
1929
  const derived = book.derived.get(context.host) ?? /* @__PURE__ */ new Set();
2016
- derived.add(claim2.match);
1930
+ derived.add(claim.match);
2017
1931
  book.derived.set(context.host, derived);
2018
1932
  const live = book.groups.get(context.host) ?? [];
2019
- for (const target of claim2.targets) {
2020
- live.find((group) => group.target === target)?.members.push(claim2.match);
1933
+ for (const target of claim.targets) {
1934
+ live.find((group) => group.target === target)?.members.push(claim.match);
2021
1935
  }
2022
1936
  }
2023
- function installClaim(port, context, claim2) {
1937
+ function installClaim(port, context, claim) {
2024
1938
  port.install({
2025
- el: claim2.match,
2026
- fingerprint: `${context.fingerprint}\0${matchKey(claim2.targets)}`,
2027
- parsed: { specs: claim2.target.specs, warnings: [] },
2028
- config: claim2.config,
2029
- document: { targets: [{ ...claim2.target, selector: "", scope: "self" }], warnings: [] },
1939
+ el: claim.match,
1940
+ fingerprint: `${context.fingerprint}\0${matchKey(claim.targets)}`,
1941
+ parsed: { specs: claim.target.specs, warnings: [] },
1942
+ config: claim.config,
1943
+ document: { targets: [{ ...claim.target, selector: "", scope: "self" }], warnings: [] },
2030
1944
  host: context.host,
2031
- gateOwner: matchGateOwner(port, context, claim2.targets)
1945
+ gateOwner: matchGateOwner(port, context, claim.targets)
2032
1946
  });
2033
- recordClaim(port, context, claim2);
1947
+ recordClaim(port, context, claim);
2034
1948
  }
2035
1949
  function installDerivedMatches(port, context, claims, cache = /* @__PURE__ */ new Map()) {
2036
1950
  const installed = [];
2037
1951
  for (const [match, targets] of claims) {
2038
- const claim2 = resolveClaim(port, context, { match, targets }, cache);
2039
- installClaim(port, context, claim2);
2040
- installed.push(claim2.match);
1952
+ const claim = resolveClaim(port, context, { match, targets }, cache);
1953
+ installClaim(port, context, claim);
1954
+ installed.push(claim.match);
2041
1955
  }
2042
1956
  return installed;
2043
1957
  }
@@ -2047,13 +1961,16 @@ function restageTargets(port, host) {
2047
1961
  const hostState = port.stateOf(host);
2048
1962
  if (!context || !live || !hostState) return;
2049
1963
  const elementWide = elementStaggerKeys(context.parsed);
2050
- const styleOf = (el) => el === host ? hostState.ledgers.style(host) : port.stateOf(el).ledgers.style(el);
2051
1964
  for (const group of live) {
2052
1965
  if (group.members.length === 0) continue;
1966
+ const splitLayer = group.target.split ? group.members[0].closest(`[${ATTR.part}="split"]`) ?? void 0 : void 0;
1967
+ const styleOf = (el) => el === host || el === splitLayer ? hostState.ledgers.style(el) : port.stateOf(el).ledgers.style(el);
1968
+ if (splitLayer) styleOf(splitLayer).set("--kui-stagger", "0ms");
2053
1969
  indexTargetGroup({
2054
1970
  host,
2055
1971
  matches: group.members,
2056
1972
  styleOf,
1973
+ splitLayer,
2057
1974
  keys: staggerKeysFor(group.target.hoists, elementWide),
2058
1975
  reporter: port.reporter
2059
1976
  });
@@ -2065,14 +1982,14 @@ var ANCESTOR_WALK_BOUND2 = 64;
2065
1982
  function newMatchesFor(node, host, target) {
2066
1983
  const candidates = [...node.querySelectorAll(target.selector)];
2067
1984
  if (node.matches(target.selector)) candidates.unshift(node);
2068
- return candidates.filter((el) => host.contains(el) && el !== host && !el.hasAttribute(ATTR.part));
1985
+ return candidates.filter((el) => host.contains(el) && el !== host && !el.hasAttribute(ATTR.part) && !el.closest(`[${ATTR.part}="split"]`));
2069
1986
  }
2070
1987
  function resolveNewGroups(node, host, groups) {
2071
1988
  const resolved = [];
2072
1989
  const before = /* @__PURE__ */ new Map();
2073
1990
  for (const group of groups) {
2074
1991
  before.set(group, group.members.length);
2075
- if (group.target.scope !== "self") continue;
1992
+ if (group.target.scope !== "self" || group.target.split) continue;
2076
1993
  const matches = newMatchesFor(node, host, group.target);
2077
1994
  if (matches.length > 0) resolved.push({ target: group.target, matches });
2078
1995
  }
@@ -2108,7 +2025,7 @@ function adoptIntoHost(port, node, host) {
2108
2025
  restageTargets(port, host);
2109
2026
  }
2110
2027
  function adoptLateMatches(port, node) {
2111
- if (node.hasAttribute(ATTR.part)) return;
2028
+ if (node.hasAttribute(ATTR.part) || node.closest(`[${ATTR.part}="split"]`)) return;
2112
2029
  let ancestor = node.parentElement;
2113
2030
  let depth = 0;
2114
2031
  while (ancestor && depth < ANCESTOR_WALK_BOUND2) {
@@ -2168,10 +2085,7 @@ function createDomWatcher(options) {
2168
2085
  subtree: true,
2169
2086
  childList: true,
2170
2087
  attributes: true,
2171
- // `ATTR.stagger` is watched for the same reason `ATTR.source` is: both spell a stagger
2172
- // group, and an edit to either has to re-rank the group. Its absence here meant editing
2173
- // `data-kui-stagger` produced no record at all — not a missed handler, no mutation.
2174
- attributeFilter: [ATTR.source, ATTR.on, ATTR.timeline, ATTR.threshold, ATTR.stagger]
2088
+ attributeFilter: [ATTR.source, ATTR.on, ATTR.threshold]
2175
2089
  });
2176
2090
  },
2177
2091
  destroy() {
@@ -2224,12 +2138,17 @@ function sequencedTiming(entry, warn) {
2224
2138
  if (entry.sequencedDelayMs !== void 0) timing.delayMs = entry.sequencedDelayMs;
2225
2139
  return timing;
2226
2140
  }
2141
+ function withRepeat(instance, repeat, ctx) {
2142
+ if (repeat === void 0 || repeat === "1" || ctx.reducedMotion) return instance;
2143
+ return repeatedInstance(instance, repeat, ctx.win);
2144
+ }
2227
2145
  function createJsEffectPreparer(options) {
2228
2146
  const { scheduler, rootResolver, capabilities, reporter, respectReducedMotion } = options;
2229
- function contextFor(el, signal, ledger) {
2147
+ function contextFor(el, { signal, ledger, timeline, cancel }) {
2230
2148
  const doc = el.ownerDocument;
2231
2149
  return {
2232
2150
  doc,
2151
+ timeline,
2233
2152
  win: doc.defaultView ?? globalThis,
2234
2153
  scheduler,
2235
2154
  rootFor: rootResolver,
@@ -2238,27 +2157,28 @@ function createJsEffectPreparer(options) {
2238
2157
  warn: (message) => reporter.warn(message, el),
2239
2158
  reducedMotion: respectReducedMotion && capabilities.reducedMotion,
2240
2159
  signal,
2160
+ cancel,
2241
2161
  style: ledger
2242
2162
  };
2243
2163
  }
2244
2164
  return {
2245
- prepare({ el, plan, signal, ledger }) {
2165
+ prepare({ el, plan, signal, ledger, timeline = "time", cancel }) {
2246
2166
  const instances = [];
2247
2167
  if (plan.jsEffects.length === 0) return instances;
2248
- const ctx = contextFor(el, signal, ledger);
2168
+ const ctx = contextFor(el, { signal, ledger, timeline, cancel });
2249
2169
  for (const entry of plan.jsEffects) {
2250
2170
  const { spec, resolved } = entry;
2251
- const prepare = resolved.primitive.prepare;
2171
+ const prepare = entry.variant?.prepare ?? resolved.primitive.prepare;
2252
2172
  if (!prepare) continue;
2253
2173
  const warn = (message) => reporter.warn(message, el);
2254
2174
  const params = readEffectParams(
2255
2175
  { ...resolved.preset.params, ...authoredParams(entry) },
2256
- resolved.primitive.parameters,
2176
+ schemaFor(entry),
2257
2177
  warn,
2258
2178
  sequencedTiming(entry, warn)
2259
2179
  );
2260
2180
  try {
2261
- instances.push(prepare(el, params, ctx));
2181
+ instances.push(withRepeat(prepare(el, params, ctx), spec.repeat, ctx));
2262
2182
  } catch (error) {
2263
2183
  reporter.warn(`"${spec.name}" failed to initialise: ${String(error)}`, el);
2264
2184
  }
@@ -2294,7 +2214,7 @@ function collectingReporter() {
2294
2214
  // src/core/animator.ts
2295
2215
  var CLOAK_WATCHDOG_MS = 3e3;
2296
2216
  function fingerprintOf(attributes) {
2297
- return [attributes.source, attributes.on, attributes.timeline, attributes.threshold].join("\0");
2217
+ return [attributes.source, attributes.on, attributes.threshold].join("\0");
2298
2218
  }
2299
2219
  function isElementNode(node) {
2300
2220
  return typeof Element !== "undefined" && node instanceof Element;
@@ -2372,10 +2292,22 @@ var Animator = class {
2372
2292
  */
2373
2293
  gateWatcher;
2374
2294
  started = false;
2295
+ /**
2296
+ * Live `every:` cadences, one per element that authors one.
2297
+ *
2298
+ * Deliberately NOT part of `InstanceState`: `replay()` is `reset()` → `process()` → `activate()`,
2299
+ * and `reset()` releases that state. A cadence stored there would kill itself on the first tick
2300
+ * that replays. Reconciled by `syncCadence` on every `process()` and dropped only when the
2301
+ * element is removed, its `every:` goes away, or the animator is destroyed — never in `release()`.
2302
+ * `thunks` is replaced on each reconcile so a recompile's fresh cycle hooks are the ones a later
2303
+ * tick calls, while the scheduler (and its one IntersectionObserver) is kept.
2304
+ */
2305
+ cadences = /* @__PURE__ */ new Map();
2375
2306
  /** This animator's derived-host bookkeeping — see `DerivedBook`. */
2376
2307
  book = createDerivedBook();
2377
2308
  /** The narrow window the `derived/*` modules get onto this animator — see `AnimatorPort`. */
2378
2309
  port;
2310
+ repeatDelaySupport;
2379
2311
  constructor(options = {}) {
2380
2312
  const resolved = resolveCollaborators(options);
2381
2313
  this.registry = resolved.registry;
@@ -2390,6 +2322,8 @@ var Animator = class {
2390
2322
  this.domWatcher = resolved.domWatcher;
2391
2323
  this.respectReducedMotion = resolved.respectReducedMotion;
2392
2324
  this.shouldObserve = resolved.shouldObserve;
2325
+ const canHold = typeof globalThis.Element?.prototype.getAnimations === "function" && typeof globalThis.KeyframeEffect?.prototype.updateTiming === "function" && globalThis.CSS?.supports("animation-timing-function", "linear(0, 1 80% 100%)") === true;
2326
+ this.repeatDelaySupport = canHold && (this.respectReducedMotion && this.capabilities.reducedMotion ? "reduced" : true);
2393
2327
  this.port = {
2394
2328
  registry: this.registry,
2395
2329
  reporter: this.reporter,
@@ -2449,7 +2383,9 @@ var Animator = class {
2449
2383
  const defined = this.bundles.collect(root, this.reporter);
2450
2384
  const selector = `[${ATTR.source}]`;
2451
2385
  if (isElementNode(root) && root.matches(selector)) this.process(root);
2452
- for (const el of root.querySelectorAll(selector)) this.process(el);
2386
+ for (const el of root.querySelectorAll(selector)) {
2387
+ if (root.contains(el)) this.process(el);
2388
+ }
2453
2389
  applyStagger(root, this.reporter);
2454
2390
  if (defined > 0 && root !== this.root) this.retryPending();
2455
2391
  return this;
@@ -2483,18 +2419,129 @@ var Animator = class {
2483
2419
  if (existing?.fingerprint === fingerprint) return;
2484
2420
  if (existing) this.release(el);
2485
2421
  const parsed = scopeHoists(this.bundles.expand(parse(attributes.source)), this.registry);
2422
+ if (isGroupOnly(parsed) || !el.hasAttribute(ATTR.source)) {
2423
+ parsed.warnings.forEach((warning) => this.reporter.warn(warning, el));
2424
+ el.removeAttribute(ATTR.state);
2425
+ this.dropCadence(el);
2426
+ return;
2427
+ }
2486
2428
  const baseConfig = resolveConfig(attributes, parsed);
2487
2429
  const config = { ...baseConfig };
2488
- const document2 = compileTargets(parsed, this.registry, baseConfig.timeline);
2430
+ const document2 = compileTargets(parsed, this.registry, baseConfig.timeline, this.repeatDelaySupport);
2489
2431
  const facts = document2.targets[0].plan;
2490
2432
  this.applyViewportGates(el, document2);
2491
2433
  config.activation = this.resolveActivation(el, baseConfig, facts);
2492
2434
  this.reportCompiled(el, document2);
2493
2435
  if (document2.targets.every((target) => target.plan.fxNames.length === 0)) {
2494
2436
  el.setAttribute(ATTR.state, facts.unknown.length > 0 ? "pending" : "failed");
2437
+ this.dropCadence(el);
2495
2438
  return;
2496
2439
  }
2497
2440
  this.install({ el, fingerprint, parsed, config, baseConfig, document: document2 });
2441
+ this.syncCadence(el, parsed, baseConfig, document2);
2442
+ }
2443
+ /**
2444
+ * Make this element's `every:` cadence match what its attribute now says.
2445
+ *
2446
+ * Runs after `install` on every `process()`, including the one `replay()` triggers — which is why
2447
+ * an unchanged `every:` keeps the running scheduler (and its observer) and only swaps in the fresh
2448
+ * cycle hooks; see `cadences`. Refusals warn and leave no cadence: a scroll-driven element is
2449
+ * already driven by scroll (an `every:` replays clock time), and an element whose every effect is
2450
+ * `repeat:infinite` never finishes, so every tick would be skipped.
2451
+ *
2452
+ * @complexity O(e) time in composed effects; O(1) space.
2453
+ * @overallScore 100
2454
+ */
2455
+ syncCadence(el, parsed, config, document2) {
2456
+ const every = parsed.every;
2457
+ if (every === void 0) {
2458
+ this.dropCadence(el);
2459
+ return;
2460
+ }
2461
+ const warn = (message) => this.reporter.warn(message, el);
2462
+ const refusal = cadenceRefusal(config, document2);
2463
+ if (refusal) {
2464
+ this.dropCadence(el);
2465
+ warn(refusal);
2466
+ return;
2467
+ }
2468
+ const thunks = document2.targets.some((target) => target.split) ? [] : cycleThunks(el, document2, warn);
2469
+ const existing = this.cadences.get(el);
2470
+ if (existing && existing.every === every) {
2471
+ existing.thunks = thunks;
2472
+ return;
2473
+ }
2474
+ this.dropCadence(el);
2475
+ if (hasGroupedCycle(document2)) {
2476
+ warn("every: cycles only the host element's own effects; a target: group with a cycle hook replays instead");
2477
+ }
2478
+ const win = el.ownerDocument.defaultView ?? globalThis;
2479
+ const { release } = createCadence({
2480
+ el,
2481
+ periodMs: everyToMs(every),
2482
+ host: { win, doc: el.ownerDocument, reducedMotion: this.respectReducedMotion && this.capabilities.reducedMotion },
2483
+ tick: () => this.cadenceTick(el, entry.thunks),
2484
+ warn
2485
+ });
2486
+ const entry = { every, release, thunks };
2487
+ this.cadences.set(el, entry);
2488
+ }
2489
+ /** Release and forget one element's cadence, if it has one. O(1). */
2490
+ dropCadence(el) {
2491
+ const entry = this.cadences.get(el);
2492
+ if (!entry) return;
2493
+ this.cadences.delete(el);
2494
+ entry.release();
2495
+ }
2496
+ /**
2497
+ * One `every:` step. In order, and exactly one of them:
2498
+ *
2499
+ * 1. never activated (`ready`, e.g. `on:manual`) → `activate`. A tick never both activates and
2500
+ * cycles: a FLIP watcher needs its first snapshot before a reorder means anything.
2501
+ * 2. any composed primitive has a cycle hook → run them all. A DOM state change the primitive's
2502
+ * own watcher animates; replaying would reset the very state being demonstrated.
2503
+ * 3. still `running` → skip. A tick never interrupts a run in progress.
2504
+ * 4. otherwise → `replay`, the route `play()` shares.
2505
+ *
2506
+ * A state that is none of those (`pending`/`failed`, or no state because the element was
2507
+ * recompiled away) skips: there is nothing installed to step.
2508
+ *
2509
+ * @complexity O(c) time in cycle hooks; O(1) space.
2510
+ * @overallScore 100
2511
+ */
2512
+ cadenceTick(el, thunks) {
2513
+ const status = this.states.get(el)?.status;
2514
+ if (status === "ready") {
2515
+ this.activate(el);
2516
+ return;
2517
+ }
2518
+ if (status === void 0 || status === "pending" || status === "failed") return;
2519
+ if (thunks.length > 0) {
2520
+ for (const thunk of thunks) thunk();
2521
+ return;
2522
+ }
2523
+ if (status === "running") return;
2524
+ this.replay(el);
2525
+ }
2526
+ /**
2527
+ * Run an element's effects again from their from-state: reset, recompile, activate.
2528
+ *
2529
+ * The remounting replay route. A local toggle can reverse on a second `activate()`, and
2530
+ * `process()` short-circuits on an unchanged fingerprint. `play()` and the `every:` cadence
2531
+ * share it so "replay" cannot mean two things. The cadence survives the round trip because it
2532
+ * lives outside the state `reset()` releases (see `cadences`).
2533
+ *
2534
+ * Restores whatever the effects wrote, so a JS-rendered effect that restores on finish
2535
+ * (`slat-assemble`) starts again from the author's own markup. A cycle hook's DOM change is the
2536
+ * exception: it is a state change the author asked for, and nothing here undoes it.
2537
+ *
2538
+ * @complexity O(e) time in composed effects; O(e) space for the recompiled plan.
2539
+ * @overallScore 100
2540
+ */
2541
+ replay(el) {
2542
+ this.reset(el);
2543
+ this.process(el);
2544
+ this.activate(el);
2498
2545
  }
2499
2546
  /**
2500
2547
  * Report everything a finished compile has to say about one element.
@@ -2611,10 +2658,9 @@ var Animator = class {
2611
2658
  this.release(el);
2612
2659
  this.process(el);
2613
2660
  }
2614
- /** Route a document with any non-empty-selector group through the derived-host path; `true`
2615
- * when it did (a derived install's own `document` never carries one, so this cannot recurse). */
2661
+ /** Route selector and split groups through the derived-host path, once per authored host. */
2616
2662
  installedAsHost(request) {
2617
- if (!request.document.targets.some((t) => t.selector !== "")) return false;
2663
+ if (request.host || !request.document.targets.some((t) => t.selector !== "" || t.split)) return false;
2618
2664
  installWithTargets(this.port, request);
2619
2665
  return true;
2620
2666
  }
@@ -2644,7 +2690,7 @@ var Animator = class {
2644
2690
  timeline: config.timeline,
2645
2691
  fxNames: document2.targets.flatMap((target) => target.plan.fxNames),
2646
2692
  jsEffectNames: document2.targets.flatMap(
2647
- (target) => target.plan.jsEffects.map((entry) => entry.spec.name)
2693
+ (target) => target.plan.jsEffects.filter((entry) => entry.resolved.primitive.renderer !== "css-keyframes").map((entry) => entry.spec.name)
2648
2694
  ),
2649
2695
  progressDriven: elementStylePlan.gate === "scrubbed" || elementStylePlan.gate === "native-timeline",
2650
2696
  instances: [],
@@ -2668,6 +2714,7 @@ var Animator = class {
2668
2714
  elementHasCssAnimation
2669
2715
  };
2670
2716
  for (const group of groups) this.installGroup(group, context);
2717
+ warnNamedEasings(el, state.specs, this.reporter);
2671
2718
  this.openGate({ el, state, stylePlan: elementStylePlan, config, plan: groups[0].target.plan });
2672
2719
  }
2673
2720
  /**
@@ -2735,6 +2782,8 @@ var Animator = class {
2735
2782
  const hasCssAnimation = Object.keys(stylePlan.properties).some(
2736
2783
  (property) => property.startsWith("animation-")
2737
2784
  );
2785
+ const delay = stylePlan.properties["animation-delay"];
2786
+ if (delay && !context.state.host) stylePlan.properties["animation-delay"] = withNestedStagger(delay);
2738
2787
  const writes = { target, stylePlan, hasCssAnimation };
2739
2788
  for (const match of matches) this.installMatch(match, writes, context);
2740
2789
  }
@@ -2762,16 +2811,26 @@ var Animator = class {
2762
2811
  matchLedger.claim("animation-play-state");
2763
2812
  if (hasCssAnimation) {
2764
2813
  const scrubbed = stylePlan.gate === "scrubbed";
2814
+ const trigger = stylePlan.activation && resolveActivationSpec(stylePlan.activation);
2815
+ const restart = trigger && trigger.end === void 0 && trigger.start.kind === "events" && (context.config.activationSource !== void 0 || target.split && trigger.source === "hover");
2765
2816
  state.instances.push(
2766
- createCssInstance(match, matchLedger, target.plan.keyframeNames, scrubbed)
2817
+ createCssInstance(
2818
+ match,
2819
+ matchLedger,
2820
+ target.plan.keyframeNames,
2821
+ restart ? "restart" : scrubbed,
2822
+ target.plan.repeatDelays
2823
+ )
2767
2824
  );
2768
2825
  }
2769
2826
  state.instances.push(
2770
2827
  ...this.jsEffectPreparer.prepare({
2828
+ timeline: context.config.timeline,
2771
2829
  el: match,
2772
2830
  plan: target.plan,
2773
2831
  signal: context.signal,
2774
- ledger: matchLedger
2832
+ ledger: matchLedger,
2833
+ cancel: () => this.cancel(match)
2775
2834
  })
2776
2835
  );
2777
2836
  }
@@ -2966,7 +3025,10 @@ var Animator = class {
2966
3025
  this.turnAround(el, state);
2967
3026
  return;
2968
3027
  }
2969
- if (state.status === "running") return;
3028
+ if (state.status === "running") {
3029
+ if (!state.instances.some((instance) => instance.replaceOnActivate)) return;
3030
+ this.cancelOne(el);
3031
+ }
2970
3032
  state.releaseActivation?.();
2971
3033
  state.releaseActivation = void 0;
2972
3034
  this.writeStatus(el, state, "running");
@@ -2978,9 +3040,9 @@ var Animator = class {
2978
3040
  this.syncHost(state);
2979
3041
  return;
2980
3042
  }
3043
+ this.settleWhen({ el, state, run }, started, "finished");
2981
3044
  this.emit(el, state, KUI_EVENT.start, "activated");
2982
3045
  this.syncHost(state);
2983
- this.settleWhen({ el, state, run }, started, "finished");
2984
3046
  }
2985
3047
  /**
2986
3048
  * Play an element's effects back out.
@@ -3008,8 +3070,7 @@ var Animator = class {
3008
3070
  if (!state) return;
3009
3071
  if (state.status !== "running" && state.status !== "finished") return;
3010
3072
  if (state.direction === "reverse") return;
3011
- const reversible = state.instances.filter(isDirectional);
3012
- if (reversible.length < state.instances.length) {
3073
+ if (state.instances.some((instance) => !instance.setupOnly && !isDirectional(instance))) {
3013
3074
  this.reporter.warn(
3014
3075
  "effect cannot play backwards, so the exit half of this activation does nothing for it (JS-rendered effects have no playhead \u2014 see EffectInstance.reverse)",
3015
3076
  el
@@ -3356,6 +3417,7 @@ var Animator = class {
3356
3417
  const candidates = [node, ...node.querySelectorAll("*")];
3357
3418
  for (const el of candidates) {
3358
3419
  if (this.liveElements.has(el)) this.release(el);
3420
+ this.dropCadence(el);
3359
3421
  }
3360
3422
  restageAfterRemoval(candidates, this.reporter);
3361
3423
  restageAfterTreeRelease(this.port, candidates);
@@ -3363,6 +3425,7 @@ var Animator = class {
3363
3425
  destroy() {
3364
3426
  this.domWatcher?.destroy();
3365
3427
  releaseStagger(this.root);
3428
+ for (const el of [...this.cadences.keys()]) this.dropCadence(el);
3366
3429
  for (const el of [...this.liveElements]) this.release(el);
3367
3430
  this.gateWatcher?.destroy();
3368
3431
  this.binder.destroy();
@@ -3388,6 +3451,7 @@ var Animator = class {
3388
3451
  },
3389
3452
  onElementRemoved: (el) => this.releaseTree(el),
3390
3453
  onAttributeChanged: (el) => {
3454
+ releaseStaggerGroup(el);
3391
3455
  this.process(el);
3392
3456
  restageAround(el, this.reporter);
3393
3457
  }
@@ -3437,8 +3501,32 @@ function defaultRootResolver(root) {
3437
3501
  const win = doc?.defaultView ?? globalThis;
3438
3502
  return createRootResolver({ win });
3439
3503
  }
3504
+ function cadenceRefusal(config, document2) {
3505
+ if (config.timeline !== "time") {
3506
+ return "every: needs a clock timeline; a scroll-driven element is already driven by scroll, so no cadence started";
3507
+ }
3508
+ const eventDriven = document2.targets.some(({ plan, hoists }) => {
3509
+ const group = resolveGroupConfig(config, hoists);
3510
+ const activation = group.activationAuthored ? group.activation : plan.defaultActivation ?? group.activation;
3511
+ const { start, end } = resolveActivationSpec(activation);
3512
+ return start.kind === "events" || end?.kind === "events";
3513
+ });
3514
+ if (eventDriven) return "every: cannot replay a DOM-event trigger; no cadence started and the authored trigger still works";
3515
+ if (document2.targets.every(({ specs }) => specs.every(({ repeat }) => isInfiniteRepeat(repeat)))) {
3516
+ return "every: has nothing to replay; every effect is repeat:infinite and never finishes, so no cadence started";
3517
+ }
3518
+ }
3440
3519
  function isDirectional(instance) {
3441
- return instance.play !== void 0 && instance.reverse !== void 0;
3520
+ return !instance.setupOnly && instance.play !== void 0 && instance.reverse !== void 0;
3521
+ }
3522
+ function warnNamedEasings(el, specs, reporter) {
3523
+ const names = new Set(specs.flatMap((spec) => [spec.easing, spec.params.ease]));
3524
+ for (const name of names) {
3525
+ if (!name || EASING_KEYWORDS.has(name) || name.includes("(")) continue;
3526
+ if (!customEasing(name, el)) {
3527
+ reporter.warn(`easing "${name}" has no --kui-ease-${name} definition \u2014 using ease-out`, el);
3528
+ }
3529
+ }
3442
3530
  }
3443
3531
  function runQuietly(cleanup) {
3444
3532
  try {
@@ -3536,8 +3624,11 @@ function writtenArgs(spec) {
3536
3624
  function writtenStepKeys(spec) {
3537
3625
  const written = {};
3538
3626
  if (spec.at !== void 0) written.at = spec.at;
3627
+ if (spec.split !== void 0) written.split = spec.split;
3628
+ if (spec.rows !== void 0) written.rows = spec.rows;
3539
3629
  Object.assign(written, spec.gate);
3540
3630
  if (spec.repeat !== void 0) written.repeat = spec.repeat;
3631
+ if (spec.repeatDelay !== void 0) written["repeat-delay"] = `${spec.repeatDelay}ms`;
3541
3632
  if (spec.yoyo !== void 0) written.yoyo = String(spec.yoyo);
3542
3633
  for (const [field, value] of Object.entries(spec.hoists ?? {})) {
3543
3634
  written[ELEMENT_KEYS[field].key] = value;
@@ -3565,8 +3656,10 @@ var TIMELINES2 = Object.keys({ time: 0, view: 0, scroll: 0, pointer: 0, pin: 0 }
3565
3656
  var RM_POLICIES = Object.keys({ shorten: 0, crossfade: 0, disable: 0 });
3566
3657
  var ELEMENT_KEYS = {
3567
3658
  activation: { key: "on", type: "text", default: "", spellings: ["enter", "load", "hover", "click", "hover/unhover"] },
3659
+ via: { key: "via", type: "text", default: "", spellings: ["#play"] },
3568
3660
  actions: { key: "actions", type: "text", default: "", spellings: ["play/pause/resume/reset", "play/none/none/reset"] },
3569
3661
  timeline: { key: "timeline", type: "keyword", default: "", spellings: TIMELINES2, keywords: TIMELINES2 },
3662
+ range: { key: "range", type: "text", default: "", spellings: ["'entry 0% cover 60%'", "'0% 100%'"] },
3570
3663
  threshold: { key: "threshold", type: "percentage", default: "", spellings: ["0%", "25%"] },
3571
3664
  cascade: { key: "cascade", type: "time", default: "", spellings: ["90ms", "0.09s"] },
3572
3665
  spread: { key: "spread", type: "time", default: "", spellings: ["600ms", "0.6s"] },
@@ -3574,7 +3667,8 @@ var ELEMENT_KEYS = {
3574
3667
  cols: { key: "cols", type: "text", default: "", spellings: ["auto", "4"] },
3575
3668
  along: { key: "along", type: "keyword", default: "", spellings: ["x", "y"], keywords: ["x", "y"] },
3576
3669
  rm: { key: "rm", type: "keyword", default: "", spellings: RM_POLICIES, keywords: RM_POLICIES },
3577
- func: { key: "func", type: "text", default: "", spellings: ["onRevealDone"] }
3670
+ func: { key: "func", type: "text", default: "", spellings: ["onRevealDone"] },
3671
+ every: { key: "every", type: "time", default: "", spellings: ["2.6s", "900ms"] }
3578
3672
  };
3579
3673
  var gateKey = (key) => ({
3580
3674
  key,
@@ -3585,8 +3679,11 @@ var gateKey = (key) => ({
3585
3679
  });
3586
3680
  var STEP_KEYS = {
3587
3681
  at: { key: "at", type: "text", default: "", spellings: ["after", "with", "-200ms", "with+100ms"] },
3682
+ split: { key: "split", type: "keyword", default: "", spellings: ["chars", "words", "tiles"], keywords: ["chars", "words", "tiles"] },
3683
+ rows: { key: "rows", type: "number", default: "", spellings: ["5"] },
3588
3684
  gate: { above: gateKey("above"), below: gateKey("below"), wide: gateKey("wide"), narrow: gateKey("narrow") },
3589
3685
  repeat: { key: "repeat", type: "text", default: "", spellings: ["infinite", "3"] },
3686
+ repeatDelay: { key: "repeat-delay", type: "time", default: "", spellings: ["300ms", "0.3s"] },
3590
3687
  yoyo: { key: "yoyo", type: "keyword", default: "", spellings: ["true", "false"], keywords: ["true", "false"] }
3591
3688
  };
3592
3689
  var STEP_KEY_LIST = Object.values(STEP_KEYS).flatMap(
@@ -3606,6 +3703,7 @@ function spellingsFor(spec, fallback = spec.default) {
3606
3703
  var EXAMPLES = {
3607
3704
  angle: (value) => angleForms(value),
3608
3705
  "angle|keyword": (value, keywords) => [...angleForms(keywords.includes(value) ? "" : value), ...keywords],
3706
+ "number|keyword": (value, keywords) => [keywords.includes(value) ? "1" : value || "1", ...keywords],
3609
3707
  keyword: (_, keywords) => [...keywords],
3610
3708
  time: timeForms,
3611
3709
  number: (value) => [value || "1"],