@fluentui/react-motion-components-preview 0.12.0 → 0.14.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.
- package/CHANGELOG.md +20 -2
- package/dist/index.d.ts +230 -0
- package/lib/choreography/Stagger/Stagger.js +189 -0
- package/lib/choreography/Stagger/Stagger.js.map +1 -0
- package/lib/choreography/Stagger/index.js +1 -0
- package/lib/choreography/Stagger/index.js.map +1 -0
- package/lib/choreography/Stagger/stagger-types.js +1 -0
- package/lib/choreography/Stagger/stagger-types.js.map +1 -0
- package/lib/choreography/Stagger/useStaggerItemsVisibility.js +176 -0
- package/lib/choreography/Stagger/useStaggerItemsVisibility.js.map +1 -0
- package/lib/choreography/Stagger/utils/constants.js +5 -0
- package/lib/choreography/Stagger/utils/constants.js.map +1 -0
- package/lib/choreography/Stagger/utils/getStaggerChildMapping.js +29 -0
- package/lib/choreography/Stagger/utils/getStaggerChildMapping.js.map +1 -0
- package/lib/choreography/Stagger/utils/index.js +4 -0
- package/lib/choreography/Stagger/utils/index.js.map +1 -0
- package/lib/choreography/Stagger/utils/motionComponentDetection.js +83 -0
- package/lib/choreography/Stagger/utils/motionComponentDetection.js.map +1 -0
- package/lib/choreography/Stagger/utils/stagger-calculations.js +71 -0
- package/lib/choreography/Stagger/utils/stagger-calculations.js.map +1 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -1
- package/lib-commonjs/choreography/Stagger/Stagger.js +137 -0
- package/lib-commonjs/choreography/Stagger/Stagger.js.map +1 -0
- package/lib-commonjs/choreography/Stagger/index.js +11 -0
- package/lib-commonjs/choreography/Stagger/index.js.map +1 -0
- package/lib-commonjs/choreography/Stagger/stagger-types.js +6 -0
- package/lib-commonjs/choreography/Stagger/stagger-types.js.map +1 -0
- package/lib-commonjs/choreography/Stagger/useStaggerItemsVisibility.js +161 -0
- package/lib-commonjs/choreography/Stagger/useStaggerItemsVisibility.js.map +1 -0
- package/lib-commonjs/choreography/Stagger/utils/constants.js +23 -0
- package/lib-commonjs/choreography/Stagger/utils/constants.js.map +1 -0
- package/lib-commonjs/choreography/Stagger/utils/getStaggerChildMapping.js +27 -0
- package/lib-commonjs/choreography/Stagger/utils/getStaggerChildMapping.js.map +1 -0
- package/lib-commonjs/choreography/Stagger/utils/index.js +37 -0
- package/lib-commonjs/choreography/Stagger/utils/index.js.map +1 -0
- package/lib-commonjs/choreography/Stagger/utils/motionComponentDetection.js +48 -0
- package/lib-commonjs/choreography/Stagger/utils/motionComponentDetection.js.map +1 -0
- package/lib-commonjs/choreography/Stagger/utils/stagger-calculations.js +76 -0
- package/lib-commonjs/choreography/Stagger/utils/stagger-calculations.js.map +1 -0
- package/lib-commonjs/index.js +25 -0
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useAnimationFrame, useEventCallback } from '@fluentui/react-utilities';
|
|
4
|
+
import { staggerItemsVisibilityAtTime, DEFAULT_ITEM_DURATION } from './utils';
|
|
5
|
+
/**
|
|
6
|
+
* Hook that tracks the visibility of a staggered sequence of items as time progresses.
|
|
7
|
+
*
|
|
8
|
+
* Behavior summary for all hide modes:
|
|
9
|
+
* - On the first render, items are placed in their final state (enter => visible, exit => hidden)
|
|
10
|
+
* and no animation runs.
|
|
11
|
+
* - On subsequent renders when direction changes, items animate from the opposite state
|
|
12
|
+
* to the final state over the stagger timeline.
|
|
13
|
+
* - Changes to the `reversed` prop do not trigger re-animation; they only affect the order
|
|
14
|
+
* during the next direction change animation.
|
|
15
|
+
*
|
|
16
|
+
* This hook uses child key mapping instead of item count to track individual items.
|
|
17
|
+
* This allows it to correctly handle:
|
|
18
|
+
* - Items being added and removed simultaneously (when count stays the same)
|
|
19
|
+
* - Items being reordered
|
|
20
|
+
* - Individual item identity across renders
|
|
21
|
+
*
|
|
22
|
+
* @param childMapping - Mapping of child keys to elements and indices
|
|
23
|
+
* @param itemDelay - Milliseconds between the start of each item's animation
|
|
24
|
+
* @param itemDuration - Milliseconds each item's animation lasts
|
|
25
|
+
* @param direction - 'enter' (show items) or 'exit' (hide items)
|
|
26
|
+
* @param reversed - Whether to reverse the stagger order (last item first)
|
|
27
|
+
* @param onMotionFinish - Callback fired when the full stagger sequence completes
|
|
28
|
+
* @param hideMode - How children's visibility is managed: 'visibleProp', 'visibilityStyle', or 'unmount'
|
|
29
|
+
*
|
|
30
|
+
* @returns An object with `itemsVisibility: Record<string, boolean>` indicating which items are currently visible by key
|
|
31
|
+
*/ export function useStaggerItemsVisibility({ childMapping, itemDelay, itemDuration = DEFAULT_ITEM_DURATION, direction, reversed = false, onMotionFinish, hideMode = 'visibleProp' }) {
|
|
32
|
+
const [requestAnimationFrame, cancelAnimationFrame] = useAnimationFrame();
|
|
33
|
+
// Stabilize the callback reference to avoid re-triggering effects on every render
|
|
34
|
+
const handleMotionFinish = useEventCallback(onMotionFinish !== null && onMotionFinish !== void 0 ? onMotionFinish : ()=>{
|
|
35
|
+
return;
|
|
36
|
+
});
|
|
37
|
+
// Track animation state independently of child changes
|
|
38
|
+
const [animationKey, setAnimationKey] = React.useState(0);
|
|
39
|
+
const prevDirection = React.useRef(direction);
|
|
40
|
+
// Only trigger new animation when direction actually changes, not when children change
|
|
41
|
+
React.useEffect(()=>{
|
|
42
|
+
if (prevDirection.current !== direction) {
|
|
43
|
+
setAnimationKey((prev)=>prev + 1);
|
|
44
|
+
prevDirection.current = direction;
|
|
45
|
+
}
|
|
46
|
+
}, [
|
|
47
|
+
direction
|
|
48
|
+
]);
|
|
49
|
+
// State: visibility mapping for all items by key
|
|
50
|
+
const [itemsVisibility, setItemsVisibility] = React.useState(()=>{
|
|
51
|
+
const initial = {};
|
|
52
|
+
// All hide modes start in final state: visible for 'enter', hidden for 'exit'
|
|
53
|
+
const initialState = direction === 'enter';
|
|
54
|
+
Object.keys(childMapping).forEach((key)=>{
|
|
55
|
+
initial[key] = initialState;
|
|
56
|
+
});
|
|
57
|
+
return initial;
|
|
58
|
+
});
|
|
59
|
+
// Update visibility mapping when childMapping changes
|
|
60
|
+
React.useEffect(()=>{
|
|
61
|
+
setItemsVisibility((prev)=>{
|
|
62
|
+
const next = {};
|
|
63
|
+
const targetState = direction === 'enter';
|
|
64
|
+
// Add or update items from new mapping
|
|
65
|
+
Object.keys(childMapping).forEach((key)=>{
|
|
66
|
+
if (key in prev) {
|
|
67
|
+
// Existing item - preserve its visibility state
|
|
68
|
+
next[key] = prev[key];
|
|
69
|
+
} else {
|
|
70
|
+
// New item - set to target state
|
|
71
|
+
next[key] = targetState;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
// Note: Items that were in prev but not in childMapping are automatically removed
|
|
75
|
+
// because we only iterate over keys in childMapping
|
|
76
|
+
return next;
|
|
77
|
+
});
|
|
78
|
+
}, [
|
|
79
|
+
childMapping,
|
|
80
|
+
direction
|
|
81
|
+
]);
|
|
82
|
+
// Refs: animation timing and control
|
|
83
|
+
const startTimeRef = React.useRef(null);
|
|
84
|
+
const frameRef = React.useRef(null);
|
|
85
|
+
const finishedRef = React.useRef(false);
|
|
86
|
+
const isFirstRender = React.useRef(true);
|
|
87
|
+
// Use ref to avoid re-running the animation when child mapping changes
|
|
88
|
+
const childMappingRef = React.useRef(childMapping);
|
|
89
|
+
// Update childMapping ref whenever it changes
|
|
90
|
+
React.useEffect(()=>{
|
|
91
|
+
childMappingRef.current = childMapping;
|
|
92
|
+
}, [
|
|
93
|
+
childMapping
|
|
94
|
+
]);
|
|
95
|
+
// Use ref for reversed to avoid re-running animation when it changes
|
|
96
|
+
const reversedRef = React.useRef(reversed);
|
|
97
|
+
// Update reversed ref whenever it changes
|
|
98
|
+
React.useEffect(()=>{
|
|
99
|
+
reversedRef.current = reversed;
|
|
100
|
+
}, [
|
|
101
|
+
reversed
|
|
102
|
+
]);
|
|
103
|
+
// ====== ANIMATION EFFECT ======
|
|
104
|
+
React.useEffect(()=>{
|
|
105
|
+
let cancelled = false;
|
|
106
|
+
startTimeRef.current = null;
|
|
107
|
+
finishedRef.current = false;
|
|
108
|
+
// All hide modes skip animation on first render - items are already in their final state
|
|
109
|
+
if (isFirstRender.current) {
|
|
110
|
+
isFirstRender.current = false;
|
|
111
|
+
// Items are already in their final state from useState, no animation needed
|
|
112
|
+
handleMotionFinish();
|
|
113
|
+
return; // No cleanup needed for first render
|
|
114
|
+
}
|
|
115
|
+
// For animations after first render, start from the opposite of the final state
|
|
116
|
+
// - Enter animation: start hidden (false), animate to visible (true)
|
|
117
|
+
// - Exit animation: start visible (true), animate to hidden (false)
|
|
118
|
+
const startState = direction === 'exit';
|
|
119
|
+
// Use childMappingRef.current to avoid adding childMapping to dependencies
|
|
120
|
+
const initialVisibility = {};
|
|
121
|
+
Object.keys(childMappingRef.current).forEach((key)=>{
|
|
122
|
+
initialVisibility[key] = startState;
|
|
123
|
+
});
|
|
124
|
+
setItemsVisibility(initialVisibility);
|
|
125
|
+
// Animation loop: update visibility on each frame until complete
|
|
126
|
+
const tick = (now)=>{
|
|
127
|
+
if (cancelled) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (startTimeRef.current === null) {
|
|
131
|
+
startTimeRef.current = now;
|
|
132
|
+
}
|
|
133
|
+
const elapsed = now - startTimeRef.current;
|
|
134
|
+
const childKeys = Object.keys(childMappingRef.current);
|
|
135
|
+
const itemCount = childKeys.length;
|
|
136
|
+
const result = staggerItemsVisibilityAtTime({
|
|
137
|
+
itemCount,
|
|
138
|
+
elapsed,
|
|
139
|
+
itemDelay,
|
|
140
|
+
itemDuration,
|
|
141
|
+
direction,
|
|
142
|
+
reversed: reversedRef.current
|
|
143
|
+
});
|
|
144
|
+
// Convert boolean array to keyed object
|
|
145
|
+
const nextVisibility = {};
|
|
146
|
+
childKeys.forEach((key, idx)=>{
|
|
147
|
+
nextVisibility[key] = result.itemsVisibility[idx];
|
|
148
|
+
});
|
|
149
|
+
setItemsVisibility(nextVisibility);
|
|
150
|
+
if (elapsed < result.totalDuration) {
|
|
151
|
+
frameRef.current = requestAnimationFrame(tick);
|
|
152
|
+
} else if (!finishedRef.current) {
|
|
153
|
+
finishedRef.current = true;
|
|
154
|
+
handleMotionFinish();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
frameRef.current = requestAnimationFrame(tick);
|
|
158
|
+
return ()=>{
|
|
159
|
+
cancelled = true;
|
|
160
|
+
if (frameRef.current) {
|
|
161
|
+
cancelAnimationFrame();
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}, [
|
|
165
|
+
animationKey,
|
|
166
|
+
itemDelay,
|
|
167
|
+
itemDuration,
|
|
168
|
+
direction,
|
|
169
|
+
requestAnimationFrame,
|
|
170
|
+
cancelAnimationFrame,
|
|
171
|
+
handleMotionFinish
|
|
172
|
+
]);
|
|
173
|
+
return {
|
|
174
|
+
itemsVisibility
|
|
175
|
+
};
|
|
176
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/choreography/Stagger/useStaggerItemsVisibility.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useAnimationFrame, useEventCallback } from '@fluentui/react-utilities';\nimport type { StaggerProps } from './stagger-types';\nimport {\n staggerItemsVisibilityAtTime,\n type StaggerItemsVisibilityAtTimeParams,\n DEFAULT_ITEM_DURATION,\n type StaggerChildMapping,\n} from './utils';\n\nexport interface UseStaggerItemsVisibilityParams\n extends Pick<StaggerProps, 'onMotionFinish'>,\n Omit<StaggerItemsVisibilityAtTimeParams, 'elapsed' | 'itemCount'> {\n hideMode: StaggerProps['hideMode'];\n childMapping: StaggerChildMapping;\n}\n\n/**\n * Hook that tracks the visibility of a staggered sequence of items as time progresses.\n *\n * Behavior summary for all hide modes:\n * - On the first render, items are placed in their final state (enter => visible, exit => hidden)\n * and no animation runs.\n * - On subsequent renders when direction changes, items animate from the opposite state\n * to the final state over the stagger timeline.\n * - Changes to the `reversed` prop do not trigger re-animation; they only affect the order\n * during the next direction change animation.\n *\n * This hook uses child key mapping instead of item count to track individual items.\n * This allows it to correctly handle:\n * - Items being added and removed simultaneously (when count stays the same)\n * - Items being reordered\n * - Individual item identity across renders\n *\n * @param childMapping - Mapping of child keys to elements and indices\n * @param itemDelay - Milliseconds between the start of each item's animation\n * @param itemDuration - Milliseconds each item's animation lasts\n * @param direction - 'enter' (show items) or 'exit' (hide items)\n * @param reversed - Whether to reverse the stagger order (last item first)\n * @param onMotionFinish - Callback fired when the full stagger sequence completes\n * @param hideMode - How children's visibility is managed: 'visibleProp', 'visibilityStyle', or 'unmount'\n *\n * @returns An object with `itemsVisibility: Record<string, boolean>` indicating which items are currently visible by key\n */\nexport function useStaggerItemsVisibility({\n childMapping,\n itemDelay,\n itemDuration = DEFAULT_ITEM_DURATION,\n direction,\n reversed = false,\n onMotionFinish,\n hideMode = 'visibleProp',\n}: UseStaggerItemsVisibilityParams): { itemsVisibility: Record<string, boolean> } {\n const [requestAnimationFrame, cancelAnimationFrame] = useAnimationFrame();\n\n // Stabilize the callback reference to avoid re-triggering effects on every render\n const handleMotionFinish = useEventCallback(\n onMotionFinish ??\n (() => {\n return;\n }),\n );\n\n // Track animation state independently of child changes\n const [animationKey, setAnimationKey] = React.useState(0);\n const prevDirection = React.useRef(direction);\n\n // Only trigger new animation when direction actually changes, not when children change\n React.useEffect(() => {\n if (prevDirection.current !== direction) {\n setAnimationKey(prev => prev + 1);\n prevDirection.current = direction;\n }\n }, [direction]);\n\n // State: visibility mapping for all items by key\n const [itemsVisibility, setItemsVisibility] = React.useState<Record<string, boolean>>(() => {\n const initial: Record<string, boolean> = {};\n // All hide modes start in final state: visible for 'enter', hidden for 'exit'\n const initialState = direction === 'enter';\n Object.keys(childMapping).forEach(key => {\n initial[key] = initialState;\n });\n return initial;\n });\n\n // Update visibility mapping when childMapping changes\n React.useEffect(() => {\n setItemsVisibility(prev => {\n const next: Record<string, boolean> = {};\n const targetState = direction === 'enter';\n\n // Add or update items from new mapping\n Object.keys(childMapping).forEach(key => {\n if (key in prev) {\n // Existing item - preserve its visibility state\n next[key] = prev[key];\n } else {\n // New item - set to target state\n next[key] = targetState;\n }\n });\n\n // Note: Items that were in prev but not in childMapping are automatically removed\n // because we only iterate over keys in childMapping\n\n return next;\n });\n }, [childMapping, direction]);\n\n // Refs: animation timing and control\n const startTimeRef = React.useRef<number | null>(null);\n const frameRef = React.useRef<number | null>(null);\n const finishedRef = React.useRef(false);\n const isFirstRender = React.useRef(true);\n\n // Use ref to avoid re-running the animation when child mapping changes\n const childMappingRef = React.useRef(childMapping);\n\n // Update childMapping ref whenever it changes\n React.useEffect(() => {\n childMappingRef.current = childMapping;\n }, [childMapping]);\n\n // Use ref for reversed to avoid re-running animation when it changes\n const reversedRef = React.useRef(reversed);\n\n // Update reversed ref whenever it changes\n React.useEffect(() => {\n reversedRef.current = reversed;\n }, [reversed]);\n\n // ====== ANIMATION EFFECT ======\n\n React.useEffect(() => {\n let cancelled = false;\n startTimeRef.current = null;\n finishedRef.current = false;\n\n // All hide modes skip animation on first render - items are already in their final state\n if (isFirstRender.current) {\n isFirstRender.current = false;\n // Items are already in their final state from useState, no animation needed\n handleMotionFinish();\n return; // No cleanup needed for first render\n }\n\n // For animations after first render, start from the opposite of the final state\n // - Enter animation: start hidden (false), animate to visible (true)\n // - Exit animation: start visible (true), animate to hidden (false)\n const startState = direction === 'exit';\n // Use childMappingRef.current to avoid adding childMapping to dependencies\n const initialVisibility: Record<string, boolean> = {};\n Object.keys(childMappingRef.current).forEach(key => {\n initialVisibility[key] = startState;\n });\n setItemsVisibility(initialVisibility);\n\n // Animation loop: update visibility on each frame until complete\n const tick = (now: number) => {\n if (cancelled) {\n return;\n }\n if (startTimeRef.current === null) {\n startTimeRef.current = now;\n }\n const elapsed = now - (startTimeRef.current as number);\n\n const childKeys = Object.keys(childMappingRef.current);\n const itemCount = childKeys.length;\n\n const result = staggerItemsVisibilityAtTime({\n itemCount,\n elapsed,\n itemDelay,\n itemDuration,\n direction,\n reversed: reversedRef.current,\n });\n\n // Convert boolean array to keyed object\n const nextVisibility: Record<string, boolean> = {};\n childKeys.forEach((key, idx) => {\n nextVisibility[key] = result.itemsVisibility[idx];\n });\n\n setItemsVisibility(nextVisibility);\n\n if (elapsed < result.totalDuration) {\n frameRef.current = requestAnimationFrame(tick);\n } else if (!finishedRef.current) {\n finishedRef.current = true;\n handleMotionFinish();\n }\n };\n\n frameRef.current = requestAnimationFrame(tick);\n return () => {\n cancelled = true;\n if (frameRef.current) {\n cancelAnimationFrame();\n }\n };\n }, [\n animationKey,\n itemDelay,\n itemDuration,\n direction,\n requestAnimationFrame,\n cancelAnimationFrame,\n handleMotionFinish,\n ]);\n\n return { itemsVisibility };\n}\n"],"names":["React","useAnimationFrame","useEventCallback","staggerItemsVisibilityAtTime","DEFAULT_ITEM_DURATION","useStaggerItemsVisibility","childMapping","itemDelay","itemDuration","direction","reversed","onMotionFinish","hideMode","requestAnimationFrame","cancelAnimationFrame","handleMotionFinish","animationKey","setAnimationKey","useState","prevDirection","useRef","useEffect","current","prev","itemsVisibility","setItemsVisibility","initial","initialState","Object","keys","forEach","key","next","targetState","startTimeRef","frameRef","finishedRef","isFirstRender","childMappingRef","reversedRef","cancelled","startState","initialVisibility","tick","now","elapsed","childKeys","itemCount","length","result","nextVisibility","idx","totalDuration"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,iBAAiB,EAAEC,gBAAgB,QAAQ,4BAA4B;AAEhF,SACEC,4BAA4B,EAE5BC,qBAAqB,QAEhB,UAAU;AASjB;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,SAASC,0BAA0B,EACxCC,YAAY,EACZC,SAAS,EACTC,eAAeJ,qBAAqB,EACpCK,SAAS,EACTC,WAAW,KAAK,EAChBC,cAAc,EACdC,WAAW,aAAa,EACQ;IAChC,MAAM,CAACC,uBAAuBC,qBAAqB,GAAGb;IAEtD,kFAAkF;IAClF,MAAMc,qBAAqBb,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MAAM4B,iBAA0C,CAAC;YACjDJ,UAAUhB,OAAO,CAAC,CAACC,KAAKoB;gBACtBD,cAAc,CAACnB,IAAI,GAAGkB,OAAOzB,eAAe,CAAC2B,IAAI;YACnD;YAEA1B,mBAAmByB;YAEnB,IAAIL,UAAUI,OAAOG,aAAa,EAAE;gBAClCjB,SAASb,OAAO,GAAGT,sBAAsB8B;YAC3C,OAAO,IAAI,CAACP,YAAYd,OAAO,EAAE;gBAC/Bc,YAAYd,OAAO,GAAG;gBACtBP;YACF;QACF;QAEAoB,SAASb,OAAO,GAAGT,sBAAsB8B;QACzC,OAAO;YACLH,YAAY;YACZ,IAAIL,SAASb,OAAO,EAAE;gBACpBR;YACF;QACF;IACF,GAAG;QACDE;QACAT;QACAC;QACAC;QACAI;QACAC;QACAC;KACD;IAED,OAAO;QAAES;IAAgB;AAC3B"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default timing constants for stagger animations (milliseconds).
|
|
3
|
+
*/ import { motionTokens } from '@fluentui/react-motion';
|
|
4
|
+
/** Default delay in milliseconds between each item's animation start */ export const DEFAULT_ITEM_DELAY = motionTokens.durationFaster;
|
|
5
|
+
/** Default duration in milliseconds for each item's animation */ export const DEFAULT_ITEM_DURATION = motionTokens.durationNormal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/choreography/Stagger/utils/constants.ts"],"sourcesContent":["/**\n * Default timing constants for stagger animations (milliseconds).\n */\n\nimport { motionTokens } from '@fluentui/react-motion';\n\n/** Default delay in milliseconds between each item's animation start */\nexport const DEFAULT_ITEM_DELAY = motionTokens.durationFaster;\n\n/** Default duration in milliseconds for each item's animation */\nexport const DEFAULT_ITEM_DURATION = motionTokens.durationNormal;\n"],"names":["motionTokens","DEFAULT_ITEM_DELAY","durationFaster","DEFAULT_ITEM_DURATION","durationNormal"],"mappings":"AAAA;;CAEC,GAED,SAASA,YAAY,QAAQ,yBAAyB;AAEtD,sEAAsE,GACtE,OAAO,MAAMC,qBAAqBD,aAAaE,cAAc,CAAC;AAE9D,+DAA+D,GAC/D,OAAO,MAAMC,wBAAwBH,aAAaI,cAAc,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Given `children`, return an object mapping key to child element and its index.
|
|
4
|
+
* This allows tracking individual items by identity (via React keys) rather than by position.
|
|
5
|
+
*
|
|
6
|
+
* Uses React.Children.toArray() which:
|
|
7
|
+
* - Automatically provides stable indices (0, 1, 2, ...)
|
|
8
|
+
* - Handles key normalization (e.g., 'a' → '.$a') consistently
|
|
9
|
+
* - Flattens fragments automatically
|
|
10
|
+
* - Generates keys for elements without explicit keys (e.g., '.0', '.1', '.2')
|
|
11
|
+
*
|
|
12
|
+
* @param children - React children to map
|
|
13
|
+
* @returns Object mapping child keys to { element, index }
|
|
14
|
+
*/ // TODO: consider unifying with getChildMapping from react-motion package by making it generic
|
|
15
|
+
export function getStaggerChildMapping(children) {
|
|
16
|
+
const childMapping = {};
|
|
17
|
+
if (children) {
|
|
18
|
+
React.Children.toArray(children).forEach((child, index)=>{
|
|
19
|
+
if (React.isValidElement(child)) {
|
|
20
|
+
var _child_key;
|
|
21
|
+
childMapping[(_child_key = child.key) !== null && _child_key !== void 0 ? _child_key : ''] = {
|
|
22
|
+
element: child,
|
|
23
|
+
index
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return childMapping;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/choreography/Stagger/utils/getStaggerChildMapping.ts"],"sourcesContent":["import * as React from 'react';\n\nexport type StaggerChildMapping = Record<string, { element: React.ReactElement; index: number }>;\n\n/**\n * Given `children`, return an object mapping key to child element and its index.\n * This allows tracking individual items by identity (via React keys) rather than by position.\n *\n * Uses React.Children.toArray() which:\n * - Automatically provides stable indices (0, 1, 2, ...)\n * - Handles key normalization (e.g., 'a' → '.$a') consistently\n * - Flattens fragments automatically\n * - Generates keys for elements without explicit keys (e.g., '.0', '.1', '.2')\n *\n * @param children - React children to map\n * @returns Object mapping child keys to { element, index }\n */\n// TODO: consider unifying with getChildMapping from react-motion package by making it generic\nexport function getStaggerChildMapping(children: React.ReactNode | undefined): StaggerChildMapping {\n const childMapping: StaggerChildMapping = {};\n\n if (children) {\n React.Children.toArray(children).forEach((child, index) => {\n if (React.isValidElement(child)) {\n childMapping[child.key ?? ''] = {\n element: child,\n index,\n };\n }\n });\n }\n\n return childMapping;\n}\n"],"names":["React","getStaggerChildMapping","children","childMapping","Children","toArray","forEach","child","index","isValidElement","key","element"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAI/B;;;;;;;;;;;;CAYC,GACD,8FAA8F;AAC9F,OAAO,SAASC,uBAAuBC,QAAqC;IAC1E,MAAMC,eAAoC,CAAC;IAE3C,IAAID,UAAU;QACZF,MAAMI,QAAQ,CAACC,OAAO,CAACH,UAAUI,OAAO,CAAC,CAACC,OAAOC;YAC/C,IAAIR,MAAMS,cAAc,CAACF,QAAQ;oBAClBA;gBAAbJ,YAAY,CAACI,CAAAA,aAAAA,MAAMG,GAAG,cAATH,wBAAAA,aAAa,GAAG,GAAG;oBAC9BI,SAASJ;oBACTC;gBACF;YACF;QACF;IACF;IAEA,OAAOL;AACT"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DEFAULT_ITEM_DELAY, DEFAULT_ITEM_DURATION } from './constants';
|
|
2
|
+
export { getStaggerTotalDuration, staggerItemsVisibilityAtTime } from './stagger-calculations';
|
|
3
|
+
export { acceptsVisibleProp, acceptsDelayProps } from './motionComponentDetection';
|
|
4
|
+
export { getStaggerChildMapping } from './getStaggerChildMapping';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/choreography/Stagger/utils/index.ts"],"sourcesContent":["export { DEFAULT_ITEM_DELAY, DEFAULT_ITEM_DURATION } from './constants';\nexport { getStaggerTotalDuration, staggerItemsVisibilityAtTime } from './stagger-calculations';\nexport type { StaggerItemsVisibilityAtTimeParams } from './stagger-calculations';\nexport { acceptsVisibleProp, acceptsDelayProps } from './motionComponentDetection';\nexport { getStaggerChildMapping } from './getStaggerChildMapping';\nexport type { StaggerChildMapping } from './getStaggerChildMapping';\n"],"names":["DEFAULT_ITEM_DELAY","DEFAULT_ITEM_DURATION","getStaggerTotalDuration","staggerItemsVisibilityAtTime","acceptsVisibleProp","acceptsDelayProps","getStaggerChildMapping"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,qBAAqB,QAAQ,cAAc;AACxE,SAASC,uBAAuB,EAAEC,4BAA4B,QAAQ,yBAAyB;AAE/F,SAASC,kBAAkB,EAAEC,iBAAiB,QAAQ,6BAA6B;AACnF,SAASC,sBAAsB,QAAQ,2BAA2B"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a React element has all of the specified props explicitly provided.
|
|
4
|
+
*
|
|
5
|
+
* @param element - React element to inspect
|
|
6
|
+
* @param props - Array of prop names to verify presence on the element
|
|
7
|
+
* @returns true if all props exist on element.props, false otherwise
|
|
8
|
+
*
|
|
9
|
+
* @internal - Exported for testing purposes
|
|
10
|
+
*/ /**
|
|
11
|
+
* Checks if a React element is a motion component created by createMotionComponent.
|
|
12
|
+
* Motion components are detected by the presence of the MOTION_DEFINITION symbol on the component.
|
|
13
|
+
*
|
|
14
|
+
* @param element - React element to inspect
|
|
15
|
+
* @returns true when the element's type contains the MOTION_DEFINITION symbol
|
|
16
|
+
*
|
|
17
|
+
* **Note:** This is a heuristic detection. Motion components may or may not support
|
|
18
|
+
* specific props like `delay` or `visible` depending on their implementation.
|
|
19
|
+
*
|
|
20
|
+
* @internal - Exported for testing purposes
|
|
21
|
+
*/ export function isMotionComponent(element) {
|
|
22
|
+
if (!(element === null || element === void 0 ? void 0 : element.type) || typeof element.type !== 'function') {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
// Check if the component has the MOTION_DEFINITION symbol (internal to createMotionComponent)
|
|
26
|
+
const symbols = Object.getOwnPropertySymbols(element.type);
|
|
27
|
+
return symbols.some((sym)=>sym.description === 'MOTION_DEFINITION');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a React element is a presence motion component by looking for the PRESENCE_MOTION_DEFINITION symbol.
|
|
31
|
+
* This symbol is added internally by createPresenceComponent and provides reliable detection.
|
|
32
|
+
*
|
|
33
|
+
* @param element - React element to inspect
|
|
34
|
+
* @returns true when the element's type contains the PRESENCE_MOTION_DEFINITION symbol
|
|
35
|
+
*
|
|
36
|
+
* **Presence components** (like Fade, Scale, Slide) are guaranteed to support both `visible` and `delay` props.
|
|
37
|
+
*
|
|
38
|
+
* @internal - Exported for testing purposes
|
|
39
|
+
*/ export function isPresenceComponent(element) {
|
|
40
|
+
if (!(element === null || element === void 0 ? void 0 : element.type) || typeof element.type !== 'function') {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// Check if the component has the PRESENCE_MOTION_DEFINITION symbol (internal to createPresenceComponent)
|
|
44
|
+
const symbols = Object.getOwnPropertySymbols(element.type);
|
|
45
|
+
return symbols.some((sym)=>sym.description === 'PRESENCE_MOTION_DEFINITION');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a React element accepts both `delay` and `exitDelay` props.
|
|
49
|
+
* This uses a best-effort heuristic to detect components that support both delay props.
|
|
50
|
+
*
|
|
51
|
+
* @param element - React element to inspect
|
|
52
|
+
* @returns true when the element likely supports both delay and exitDelay props
|
|
53
|
+
*
|
|
54
|
+
* **Auto-detection includes:**
|
|
55
|
+
* - Presence components (Fade, Scale, etc.) - guaranteed to support both delay and exitDelay
|
|
56
|
+
* - Motion components (.In/.Out variants, custom motion components) - may support both delay props
|
|
57
|
+
* - Elements with explicit delay and exitDelay props already set
|
|
58
|
+
*
|
|
59
|
+
* **When to override:** If auto-detection is incorrect, use explicit `delayMode` prop on Stagger.
|
|
60
|
+
* For example, custom motion components that don't support both props should use `delayMode="timing"`.
|
|
61
|
+
*
|
|
62
|
+
* @internal - Exported for testing purposes
|
|
63
|
+
*/ export function acceptsDelayProps(element) {
|
|
64
|
+
return isPresenceComponent(element) || isMotionComponent(element);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Checks if a React element accepts a `visible` prop.
|
|
68
|
+
* This uses a best-effort heuristic to detect components that support visible props.
|
|
69
|
+
*
|
|
70
|
+
* @param element - React element to inspect
|
|
71
|
+
* @returns true when the element likely supports a `visible` prop
|
|
72
|
+
*
|
|
73
|
+
* **Auto-detection includes:**
|
|
74
|
+
* - Presence components (Fade, Scale, etc.) - guaranteed to support visible
|
|
75
|
+
* - Elements with explicit visible props already set
|
|
76
|
+
*
|
|
77
|
+
* **When to override:** If auto-detection is incorrect, use explicit `hideMode` prop on Stagger.
|
|
78
|
+
* For example, custom components that don't support visible should use `hideMode="visibilityStyle"` or `hideMode="unmount"`.
|
|
79
|
+
*
|
|
80
|
+
* @internal - Exported for testing purposes
|
|
81
|
+
*/ export function acceptsVisibleProp(element) {
|
|
82
|
+
return isPresenceComponent(element);
|
|
83
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/choreography/Stagger/utils/motionComponentDetection.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * Checks if a React element has all of the specified props explicitly provided.\n *\n * @param element - React element to inspect\n * @param props - Array of prop names to verify presence on the element\n * @returns true if all props exist on element.props, false otherwise\n *\n * @internal - Exported for testing purposes\n */\n\n/**\n * Checks if a React element is a motion component created by createMotionComponent.\n * Motion components are detected by the presence of the MOTION_DEFINITION symbol on the component.\n *\n * @param element - React element to inspect\n * @returns true when the element's type contains the MOTION_DEFINITION symbol\n *\n * **Note:** This is a heuristic detection. Motion components may or may not support\n * specific props like `delay` or `visible` depending on their implementation.\n *\n * @internal - Exported for testing purposes\n */\nexport function isMotionComponent(element: React.ReactElement): boolean {\n if (!element?.type || typeof element.type !== 'function') {\n return false;\n }\n\n // Check if the component has the MOTION_DEFINITION symbol (internal to createMotionComponent)\n const symbols = Object.getOwnPropertySymbols(element.type);\n return symbols.some(sym => sym.description === 'MOTION_DEFINITION');\n}\n\n/**\n * Checks if a React element is a presence motion component by looking for the PRESENCE_MOTION_DEFINITION symbol.\n * This symbol is added internally by createPresenceComponent and provides reliable detection.\n *\n * @param element - React element to inspect\n * @returns true when the element's type contains the PRESENCE_MOTION_DEFINITION symbol\n *\n * **Presence components** (like Fade, Scale, Slide) are guaranteed to support both `visible` and `delay` props.\n *\n * @internal - Exported for testing purposes\n */\nexport function isPresenceComponent(element: React.ReactElement): boolean {\n if (!element?.type || typeof element.type !== 'function') {\n return false;\n }\n\n // Check if the component has the PRESENCE_MOTION_DEFINITION symbol (internal to createPresenceComponent)\n const symbols = Object.getOwnPropertySymbols(element.type);\n return symbols.some(sym => sym.description === 'PRESENCE_MOTION_DEFINITION');\n}\n\n/**\n * Checks if a React element accepts both `delay` and `exitDelay` props.\n * This uses a best-effort heuristic to detect components that support both delay props.\n *\n * @param element - React element to inspect\n * @returns true when the element likely supports both delay and exitDelay props\n *\n * **Auto-detection includes:**\n * - Presence components (Fade, Scale, etc.) - guaranteed to support both delay and exitDelay\n * - Motion components (.In/.Out variants, custom motion components) - may support both delay props\n * - Elements with explicit delay and exitDelay props already set\n *\n * **When to override:** If auto-detection is incorrect, use explicit `delayMode` prop on Stagger.\n * For example, custom motion components that don't support both props should use `delayMode=\"timing\"`.\n *\n * @internal - Exported for testing purposes\n */\nexport function acceptsDelayProps(element: React.ReactElement): boolean {\n return isPresenceComponent(element) || isMotionComponent(element);\n}\n\n/**\n * Checks if a React element accepts a `visible` prop.\n * This uses a best-effort heuristic to detect components that support visible props.\n *\n * @param element - React element to inspect\n * @returns true when the element likely supports a `visible` prop\n *\n * **Auto-detection includes:**\n * - Presence components (Fade, Scale, etc.) - guaranteed to support visible\n * - Elements with explicit visible props already set\n *\n * **When to override:** If auto-detection is incorrect, use explicit `hideMode` prop on Stagger.\n * For example, custom components that don't support visible should use `hideMode=\"visibilityStyle\"` or `hideMode=\"unmount\"`.\n *\n * @internal - Exported for testing purposes\n */\nexport function acceptsVisibleProp(element: React.ReactElement): boolean {\n return isPresenceComponent(element);\n}\n"],"names":["React","isMotionComponent","element","type","symbols","Object","getOwnPropertySymbols","some","sym","description","isPresenceComponent","acceptsDelayProps","acceptsVisibleProp"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B;;;;;;;;CAQC,GAED;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,kBAAkBC,OAA2B;IAC3D,IAAI,EAACA,oBAAAA,8BAAAA,QAASC,IAAI,KAAI,OAAOD,QAAQC,IAAI,KAAK,YAAY;QACxD,OAAO;IACT;IAEA,8FAA8F;IAC9F,MAAMC,UAAUC,OAAOC,qBAAqB,CAACJ,QAAQC,IAAI;IACzD,OAAOC,QAAQG,IAAI,CAACC,CAAAA,MAAOA,IAAIC,WAAW,KAAK;AACjD;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASC,oBAAoBR,OAA2B;IAC7D,IAAI,EAACA,oBAAAA,8BAAAA,QAASC,IAAI,KAAI,OAAOD,QAAQC,IAAI,KAAK,YAAY;QACxD,OAAO;IACT;IAEA,yGAAyG;IACzG,MAAMC,UAAUC,OAAOC,qBAAqB,CAACJ,QAAQC,IAAI;IACzD,OAAOC,QAAQG,IAAI,CAACC,CAAAA,MAAOA,IAAIC,WAAW,KAAK;AACjD;AAEA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASE,kBAAkBT,OAA2B;IAC3D,OAAOQ,oBAAoBR,YAAYD,kBAAkBC;AAC3D;AAEA;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASU,mBAAmBV,OAA2B;IAC5D,OAAOQ,oBAAoBR;AAC7B"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { DEFAULT_ITEM_DELAY, DEFAULT_ITEM_DURATION } from './constants';
|
|
2
|
+
/**
|
|
3
|
+
* Calculate the total stagger duration — from the moment the stagger begins
|
|
4
|
+
* until the final item's animation completes.
|
|
5
|
+
*
|
|
6
|
+
* Uses the formula:
|
|
7
|
+
* max(0, itemDelay * (itemCount - 1) + itemDuration)
|
|
8
|
+
*
|
|
9
|
+
* @param params.itemCount Total number of items to stagger
|
|
10
|
+
* @param params.itemDelay Milliseconds between the start of each item (default: DEFAULT_ITEM_DELAY)
|
|
11
|
+
* @param params.itemDuration Milliseconds each item's animation lasts (default: DEFAULT_ITEM_DURATION)
|
|
12
|
+
* @returns Total duration in milliseconds (never negative)
|
|
13
|
+
*/ export function getStaggerTotalDuration({ itemCount, itemDelay = DEFAULT_ITEM_DELAY, itemDuration = DEFAULT_ITEM_DURATION }) {
|
|
14
|
+
if (itemCount <= 0) {
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
if (itemCount <= 1) {
|
|
18
|
+
return Math.max(0, itemDuration);
|
|
19
|
+
}
|
|
20
|
+
const staggerDuration = itemDelay * (itemCount - 1);
|
|
21
|
+
return Math.max(0, staggerDuration + itemDuration);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns visibility flags plus timing metrics for a stagger sequence.
|
|
25
|
+
*/ export function staggerItemsVisibilityAtTime({ itemCount, elapsed, itemDelay = DEFAULT_ITEM_DELAY, itemDuration = DEFAULT_ITEM_DURATION, direction = 'enter', reversed = false }) {
|
|
26
|
+
// If no items, return the empty state
|
|
27
|
+
if (itemCount <= 0) {
|
|
28
|
+
return {
|
|
29
|
+
itemsVisibility: [],
|
|
30
|
+
totalDuration: 0
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const totalDuration = getStaggerTotalDuration({
|
|
34
|
+
itemCount,
|
|
35
|
+
itemDelay,
|
|
36
|
+
itemDuration
|
|
37
|
+
});
|
|
38
|
+
// Calculate progression through the stagger sequence
|
|
39
|
+
let completedSteps;
|
|
40
|
+
if (itemDelay <= 0) {
|
|
41
|
+
// When itemDelay is 0 or negative, all steps complete immediately
|
|
42
|
+
completedSteps = itemCount;
|
|
43
|
+
} else {
|
|
44
|
+
// Both enter and exit should start their first item immediately, but handle t=0 differently
|
|
45
|
+
if (elapsed === 0) {
|
|
46
|
+
// At exactly t=0, for enter we want first item visible, for exit we want all items visible
|
|
47
|
+
completedSteps = direction === 'enter' ? 1 : 0;
|
|
48
|
+
} else {
|
|
49
|
+
// After t=0, both directions should progress at the same rate
|
|
50
|
+
const stepsFromElapsedTime = Math.floor(elapsed / itemDelay) + 1;
|
|
51
|
+
completedSteps = Math.min(itemCount, stepsFromElapsedTime);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const itemsVisibility = Array.from({
|
|
55
|
+
length: itemCount
|
|
56
|
+
}, (_, idx)=>{
|
|
57
|
+
// Calculate based on progression through the sequence (enter pattern)
|
|
58
|
+
const fromStart = idx < completedSteps;
|
|
59
|
+
const fromEnd = idx >= itemCount - completedSteps;
|
|
60
|
+
let itemVisible = reversed ? fromEnd : fromStart;
|
|
61
|
+
// For exit, invert the enter pattern
|
|
62
|
+
if (direction === 'exit') {
|
|
63
|
+
itemVisible = !itemVisible;
|
|
64
|
+
}
|
|
65
|
+
return itemVisible;
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
itemsVisibility,
|
|
69
|
+
totalDuration
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/choreography/Stagger/utils/stagger-calculations.ts"],"sourcesContent":["import type { StaggerProps } from '../stagger-types';\nimport { DEFAULT_ITEM_DELAY, DEFAULT_ITEM_DURATION } from './constants';\n\n/**\n * Calculate the total stagger duration — from the moment the stagger begins\n * until the final item's animation completes.\n *\n * Uses the formula:\n * max(0, itemDelay * (itemCount - 1) + itemDuration)\n *\n * @param params.itemCount Total number of items to stagger\n * @param params.itemDelay Milliseconds between the start of each item (default: DEFAULT_ITEM_DELAY)\n * @param params.itemDuration Milliseconds each item's animation lasts (default: DEFAULT_ITEM_DURATION)\n * @returns Total duration in milliseconds (never negative)\n */\nexport function getStaggerTotalDuration({\n itemCount,\n itemDelay = DEFAULT_ITEM_DELAY,\n itemDuration = DEFAULT_ITEM_DURATION,\n}: {\n itemCount: number;\n} & Pick<StaggerProps, 'itemDelay' | 'itemDuration'>): number {\n if (itemCount <= 0) {\n return 0;\n }\n if (itemCount <= 1) {\n return Math.max(0, itemDuration);\n }\n const staggerDuration = itemDelay * (itemCount - 1);\n return Math.max(0, staggerDuration + itemDuration);\n}\n\nexport interface StaggerItemsVisibilityAtTimeParams\n extends Pick<StaggerProps, 'itemDelay' | 'itemDuration' | 'reversed'> {\n itemCount: number;\n elapsed: number;\n direction?: 'enter' | 'exit';\n}\n\n/**\n * Returns visibility flags plus timing metrics for a stagger sequence.\n */\nexport function staggerItemsVisibilityAtTime({\n itemCount,\n elapsed,\n itemDelay = DEFAULT_ITEM_DELAY,\n itemDuration = DEFAULT_ITEM_DURATION,\n direction = 'enter',\n reversed = false,\n}: StaggerItemsVisibilityAtTimeParams): {\n itemsVisibility: boolean[];\n totalDuration: number;\n} {\n // If no items, return the empty state\n if (itemCount <= 0) {\n return { itemsVisibility: [], totalDuration: 0 };\n }\n\n const totalDuration = getStaggerTotalDuration({ itemCount, itemDelay, itemDuration });\n\n // Calculate progression through the stagger sequence\n let completedSteps: number;\n if (itemDelay <= 0) {\n // When itemDelay is 0 or negative, all steps complete immediately\n completedSteps = itemCount;\n } else {\n // Both enter and exit should start their first item immediately, but handle t=0 differently\n if (elapsed === 0) {\n // At exactly t=0, for enter we want first item visible, for exit we want all items visible\n completedSteps = direction === 'enter' ? 1 : 0;\n } else {\n // After t=0, both directions should progress at the same rate\n const stepsFromElapsedTime = Math.floor(elapsed / itemDelay) + 1;\n completedSteps = Math.min(itemCount, stepsFromElapsedTime);\n }\n }\n\n const itemsVisibility = Array.from({ length: itemCount }, (_, idx) => {\n // Calculate based on progression through the sequence (enter pattern)\n const fromStart = idx < completedSteps;\n const fromEnd = idx >= itemCount - completedSteps;\n\n let itemVisible = reversed ? fromEnd : fromStart;\n\n // For exit, invert the enter pattern\n if (direction === 'exit') {\n itemVisible = !itemVisible;\n }\n\n return itemVisible;\n });\n\n return { itemsVisibility, totalDuration };\n}\n"],"names":["DEFAULT_ITEM_DELAY","DEFAULT_ITEM_DURATION","getStaggerTotalDuration","itemCount","itemDelay","itemDuration","Math","max","staggerDuration","staggerItemsVisibilityAtTime","elapsed","direction","reversed","itemsVisibility","totalDuration","completedSteps","stepsFromElapsedTime","floor","min","Array","from","length","_","idx","fromStart","fromEnd","itemVisible"],"mappings":"AACA,SAASA,kBAAkB,EAAEC,qBAAqB,QAAQ,cAAc;AAExE;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,wBAAwB,EACtCC,SAAS,EACTC,YAAYJ,kBAAkB,EAC9BK,eAAeJ,qBAAqB,EAGc;IAClD,IAAIE,aAAa,GAAG;QAClB,OAAO;IACT;IACA,IAAIA,aAAa,GAAG;QAClB,OAAOG,KAAKC,GAAG,CAAC,GAAGF;IACrB;IACA,MAAMG,kBAAkBJ,YAAaD,CAAAA,YAAY,CAAA;IACjD,OAAOG,KAAKC,GAAG,CAAC,GAAGC,kBAAkBH;AACvC;AASA;;CAEC,GACD,OAAO,SAASI,6BAA6B,EAC3CN,SAAS,EACTO,OAAO,EACPN,YAAYJ,kBAAkB,EAC9BK,eAAeJ,qBAAqB,EACpCU,YAAY,OAAO,EACnBC,WAAW,KAAK,EACmB;IAInC,sCAAsC;IACtC,IAAIT,aAAa,GAAG;QAClB,OAAO;YAAEU,iBAAiB,EAAE;YAAEC,eAAe;QAAE;IACjD;IAEA,MAAMA,gBAAgBZ,wBAAwB;QAAEC;QAAWC;QAAWC;IAAa;IAEnF,qDAAqD;IACrD,IAAIU;IACJ,IAAIX,aAAa,GAAG;QAClB,kEAAkE;QAClEW,iBAAiBZ;IACnB,OAAO;QACL,4FAA4F;QAC5F,IAAIO,YAAY,GAAG;YACjB,2FAA2F;YAC3FK,iBAAiBJ,cAAc,UAAU,IAAI;QAC/C,OAAO;YACL,8DAA8D;YAC9D,MAAMK,uBAAuBV,KAAKW,KAAK,CAACP,UAAUN,aAAa;YAC/DW,iBAAiBT,KAAKY,GAAG,CAACf,WAAWa;QACvC;IACF;IAEA,MAAMH,kBAAkBM,MAAMC,IAAI,CAAC;QAAEC,QAAQlB;IAAU,GAAG,CAACmB,GAAGC;QAC5D,sEAAsE;QACtE,MAAMC,YAAYD,MAAMR;QACxB,MAAMU,UAAUF,OAAOpB,YAAYY;QAEnC,IAAIW,cAAcd,WAAWa,UAAUD;QAEvC,qCAAqC;QACrC,IAAIb,cAAc,QAAQ;YACxBe,cAAc,CAACA;QACjB;QAEA,OAAOA;IACT;IAEA,OAAO;QAAEb;QAAiBC;IAAc;AAC1C"}
|
package/lib/index.js
CHANGED
|
@@ -4,3 +4,10 @@ export { Scale, ScaleSnappy, ScaleRelaxed } from './components/Scale';
|
|
|
4
4
|
export { Slide, SlideSnappy, SlideRelaxed } from './components/Slide';
|
|
5
5
|
export { Blur } from './components/Blur';
|
|
6
6
|
export { Rotate } from './components/Rotate';
|
|
7
|
+
export { Stagger } from './choreography/Stagger';
|
|
8
|
+
// Motion Atoms
|
|
9
|
+
export { blurAtom } from './atoms/blur-atom';
|
|
10
|
+
export { fadeAtom } from './atoms/fade-atom';
|
|
11
|
+
export { rotateAtom } from './atoms/rotate-atom';
|
|
12
|
+
export { scaleAtom } from './atoms/scale-atom';
|
|
13
|
+
export { slideAtom } from './atoms/slide-atom'; // TODO: consider whether to export some or all collapse atoms
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {\n Collapse,\n CollapseSnappy,\n CollapseRelaxed,\n CollapseDelayed,\n type CollapseParams,\n type CollapseDurations,\n} from './components/Collapse';\nexport { Fade, FadeSnappy, FadeRelaxed, type FadeParams } from './components/Fade';\nexport { Scale, ScaleSnappy, ScaleRelaxed, type ScaleParams } from './components/Scale';\nexport { Slide, SlideSnappy, SlideRelaxed, type SlideParams } from './components/Slide';\nexport { Blur, type BlurParams } from './components/Blur';\nexport { Rotate, type RotateParams } from './components/Rotate';\n"],"names":["Collapse","CollapseSnappy","CollapseRelaxed","CollapseDelayed","Fade","FadeSnappy","FadeRelaxed","Scale","ScaleSnappy","ScaleRelaxed","Slide","SlideSnappy","SlideRelaxed","Blur","Rotate"],"mappings":"AAAA,SACEA,QAAQ,EACRC,cAAc,EACdC,eAAe,EACfC,eAAe,QAGV,wBAAwB;AAC/B,SAASC,IAAI,EAAEC,UAAU,EAAEC,WAAW,QAAyB,oBAAoB;AACnF,SAASC,KAAK,EAAEC,WAAW,EAAEC,YAAY,QAA0B,qBAAqB;AACxF,SAASC,KAAK,EAAEC,WAAW,EAAEC,YAAY,QAA0B,qBAAqB;AACxF,SAASC,IAAI,QAAyB,oBAAoB;AAC1D,SAASC,MAAM,QAA2B,sBAAsB"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {\n Collapse,\n CollapseSnappy,\n CollapseRelaxed,\n CollapseDelayed,\n type CollapseParams,\n type CollapseDurations,\n} from './components/Collapse';\nexport { Fade, FadeSnappy, FadeRelaxed, type FadeParams } from './components/Fade';\nexport { Scale, ScaleSnappy, ScaleRelaxed, type ScaleParams } from './components/Scale';\nexport { Slide, SlideSnappy, SlideRelaxed, type SlideParams } from './components/Slide';\nexport { Blur, type BlurParams } from './components/Blur';\nexport { Rotate, type RotateParams } from './components/Rotate';\nexport { Stagger, type StaggerProps } from './choreography/Stagger';\n\n// Motion Atoms\nexport { blurAtom } from './atoms/blur-atom';\nexport { fadeAtom } from './atoms/fade-atom';\nexport { rotateAtom } from './atoms/rotate-atom';\nexport { scaleAtom } from './atoms/scale-atom';\nexport { slideAtom } from './atoms/slide-atom';\n// TODO: consider whether to export some or all collapse atoms\n"],"names":["Collapse","CollapseSnappy","CollapseRelaxed","CollapseDelayed","Fade","FadeSnappy","FadeRelaxed","Scale","ScaleSnappy","ScaleRelaxed","Slide","SlideSnappy","SlideRelaxed","Blur","Rotate","Stagger","blurAtom","fadeAtom","rotateAtom","scaleAtom","slideAtom"],"mappings":"AAAA,SACEA,QAAQ,EACRC,cAAc,EACdC,eAAe,EACfC,eAAe,QAGV,wBAAwB;AAC/B,SAASC,IAAI,EAAEC,UAAU,EAAEC,WAAW,QAAyB,oBAAoB;AACnF,SAASC,KAAK,EAAEC,WAAW,EAAEC,YAAY,QAA0B,qBAAqB;AACxF,SAASC,KAAK,EAAEC,WAAW,EAAEC,YAAY,QAA0B,qBAAqB;AACxF,SAASC,IAAI,QAAyB,oBAAoB;AAC1D,SAASC,MAAM,QAA2B,sBAAsB;AAChE,SAASC,OAAO,QAA2B,yBAAyB;AAEpE,eAAe;AACf,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,UAAU,QAAQ,sBAAsB;AACjD,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,SAASC,SAAS,QAAQ,qBAAqB,CAC/C,8DAA8D"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Stagger", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return Stagger;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
13
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
14
|
+
const _useStaggerItemsVisibility = require("./useStaggerItemsVisibility");
|
|
15
|
+
const _utils = require("./utils");
|
|
16
|
+
/**
|
|
17
|
+
* Shared utility to detect optimal stagger modes based on children components.
|
|
18
|
+
* Consolidates the auto-detection logic used by both StaggerMain and createStaggerDirection.
|
|
19
|
+
*/ const detectStaggerModes = (children, options)=>{
|
|
20
|
+
const { hideMode, delayMode, fallbackHideMode = 'visibilityStyle' } = options;
|
|
21
|
+
const childMapping = (0, _utils.getStaggerChildMapping)(children);
|
|
22
|
+
const elements = Object.values(childMapping).map((item)=>item.element);
|
|
23
|
+
const hasVisiblePropSupport = elements.every((child)=>(0, _utils.acceptsVisibleProp)(child));
|
|
24
|
+
const hasDelayPropSupport = elements.every((child)=>(0, _utils.acceptsDelayProps)(child));
|
|
25
|
+
return {
|
|
26
|
+
hideMode: hideMode !== null && hideMode !== void 0 ? hideMode : hasVisiblePropSupport ? 'visibleProp' : fallbackHideMode,
|
|
27
|
+
delayMode: delayMode !== null && delayMode !== void 0 ? delayMode : hasDelayPropSupport ? 'delayProp' : 'timing'
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const StaggerOneWay = ({ children, direction, itemDelay = _utils.DEFAULT_ITEM_DELAY, itemDuration = _utils.DEFAULT_ITEM_DURATION, reversed = false, hideMode, delayMode = 'timing', onMotionFinish })=>{
|
|
31
|
+
const childMapping = _react.useMemo(()=>(0, _utils.getStaggerChildMapping)(children), [
|
|
32
|
+
children
|
|
33
|
+
]);
|
|
34
|
+
// Always call hooks at the top level, regardless of delayMode
|
|
35
|
+
const { itemsVisibility } = (0, _useStaggerItemsVisibility.useStaggerItemsVisibility)({
|
|
36
|
+
childMapping,
|
|
37
|
+
itemDelay,
|
|
38
|
+
itemDuration,
|
|
39
|
+
direction,
|
|
40
|
+
reversed,
|
|
41
|
+
onMotionFinish,
|
|
42
|
+
hideMode
|
|
43
|
+
});
|
|
44
|
+
// For delayProp mode, pass delay props directly to motion components
|
|
45
|
+
if (delayMode === 'delayProp') {
|
|
46
|
+
return /*#__PURE__*/ _react.createElement(_react.Fragment, null, Object.entries(childMapping).map(([key, { element, index }])=>{
|
|
47
|
+
const staggerIndex = reversed ? Object.keys(childMapping).length - 1 - index : index;
|
|
48
|
+
const delay = staggerIndex * itemDelay;
|
|
49
|
+
// Clone element with delay prop (for enter direction) or exitDelay prop (for exit direction)
|
|
50
|
+
const delayProp = direction === 'enter' ? {
|
|
51
|
+
delay
|
|
52
|
+
} : {
|
|
53
|
+
exitDelay: delay
|
|
54
|
+
};
|
|
55
|
+
// Only set visible prop if the component supports it
|
|
56
|
+
// Set visible based on direction: true for enter, false for exit
|
|
57
|
+
const visibleProp = (0, _utils.acceptsVisibleProp)(element) ? {
|
|
58
|
+
visible: direction === 'enter'
|
|
59
|
+
} : {};
|
|
60
|
+
return /*#__PURE__*/ _react.cloneElement(element, {
|
|
61
|
+
key,
|
|
62
|
+
...visibleProp,
|
|
63
|
+
...delayProp
|
|
64
|
+
});
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
// For timing mode, use the existing timing-based implementation
|
|
68
|
+
return /*#__PURE__*/ _react.createElement(_react.Fragment, null, Object.entries(childMapping).map(([key, { element }])=>{
|
|
69
|
+
if (hideMode === 'visibleProp') {
|
|
70
|
+
// Use a generic record type for props to avoid `any` while still allowing unknown prop shapes.
|
|
71
|
+
return /*#__PURE__*/ _react.cloneElement(element, {
|
|
72
|
+
key,
|
|
73
|
+
visible: itemsVisibility[key]
|
|
74
|
+
});
|
|
75
|
+
} else if (hideMode === 'visibilityStyle') {
|
|
76
|
+
const childProps = element.props;
|
|
77
|
+
const style = {
|
|
78
|
+
...childProps === null || childProps === void 0 ? void 0 : childProps.style,
|
|
79
|
+
visibility: itemsVisibility[key] ? 'visible' : 'hidden'
|
|
80
|
+
};
|
|
81
|
+
return /*#__PURE__*/ _react.cloneElement(element, {
|
|
82
|
+
key,
|
|
83
|
+
style
|
|
84
|
+
});
|
|
85
|
+
} else {
|
|
86
|
+
// unmount mode
|
|
87
|
+
return itemsVisibility[key] ? /*#__PURE__*/ _react.cloneElement(element, {
|
|
88
|
+
key
|
|
89
|
+
}) : null;
|
|
90
|
+
}
|
|
91
|
+
}));
|
|
92
|
+
};
|
|
93
|
+
// Shared helper for StaggerIn and StaggerOut
|
|
94
|
+
const createStaggerDirection = (direction)=>{
|
|
95
|
+
const StaggerDirection = ({ hideMode, delayMode, children, ...props })=>{
|
|
96
|
+
// Auto-detect modes for better performance with motion components
|
|
97
|
+
const { hideMode: resolvedHideMode, delayMode: resolvedDelayMode } = detectStaggerModes(children, {
|
|
98
|
+
hideMode,
|
|
99
|
+
delayMode,
|
|
100
|
+
// One-way stagger falls back to visibilityStyle if it doesn't detect visibleProp support
|
|
101
|
+
fallbackHideMode: 'visibilityStyle'
|
|
102
|
+
});
|
|
103
|
+
return /*#__PURE__*/ _react.createElement(StaggerOneWay, {
|
|
104
|
+
...props,
|
|
105
|
+
children: children,
|
|
106
|
+
direction: direction,
|
|
107
|
+
hideMode: resolvedHideMode,
|
|
108
|
+
delayMode: resolvedDelayMode
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
return StaggerDirection;
|
|
112
|
+
};
|
|
113
|
+
const StaggerIn = createStaggerDirection('enter');
|
|
114
|
+
const StaggerOut = createStaggerDirection('exit');
|
|
115
|
+
// Main Stagger component with auto-detection or explicit modes
|
|
116
|
+
const StaggerMain = (props)=>{
|
|
117
|
+
const { children, visible = false, hideMode, delayMode, ...rest } = props;
|
|
118
|
+
// Auto-detect modes for bidirectional stagger
|
|
119
|
+
const { hideMode: resolvedHideMode, delayMode: resolvedDelayMode } = detectStaggerModes(children, {
|
|
120
|
+
hideMode,
|
|
121
|
+
delayMode,
|
|
122
|
+
// Bidirectional stagger falls back to visibilityStyle if it doesn't detect visibleProp support
|
|
123
|
+
fallbackHideMode: 'visibilityStyle'
|
|
124
|
+
});
|
|
125
|
+
const direction = visible ? 'enter' : 'exit';
|
|
126
|
+
return /*#__PURE__*/ _react.createElement(StaggerOneWay, {
|
|
127
|
+
...rest,
|
|
128
|
+
children: children,
|
|
129
|
+
hideMode: resolvedHideMode,
|
|
130
|
+
delayMode: resolvedDelayMode,
|
|
131
|
+
direction: direction
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
const Stagger = Object.assign(StaggerMain, {
|
|
135
|
+
In: StaggerIn,
|
|
136
|
+
Out: StaggerOut
|
|
137
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/choreography/Stagger/Stagger.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useStaggerItemsVisibility } from './useStaggerItemsVisibility';\nimport {\n DEFAULT_ITEM_DURATION,\n DEFAULT_ITEM_DELAY,\n acceptsVisibleProp,\n acceptsDelayProps,\n getStaggerChildMapping,\n} from './utils';\nimport { StaggerOneWayProps, StaggerProps, type StaggerHideMode, type StaggerDelayMode } from './stagger-types';\n\n/**\n * Shared utility to detect optimal stagger modes based on children components.\n * Consolidates the auto-detection logic used by both StaggerMain and createStaggerDirection.\n */\nconst detectStaggerModes = (\n children: React.ReactNode,\n options: {\n hideMode?: StaggerHideMode;\n delayMode?: StaggerDelayMode;\n fallbackHideMode?: StaggerHideMode;\n },\n): { hideMode: StaggerHideMode; delayMode: StaggerDelayMode } => {\n const { hideMode, delayMode, fallbackHideMode = 'visibilityStyle' } = options;\n\n const childMapping = getStaggerChildMapping(children);\n const elements = Object.values(childMapping).map(item => item.element);\n const hasVisiblePropSupport = elements.every(child => acceptsVisibleProp(child));\n const hasDelayPropSupport = elements.every(child => acceptsDelayProps(child));\n\n return {\n hideMode: hideMode ?? (hasVisiblePropSupport ? 'visibleProp' : fallbackHideMode),\n delayMode: delayMode ?? (hasDelayPropSupport ? 'delayProp' : 'timing'),\n };\n};\n\nconst StaggerOneWay: React.FC<StaggerOneWayProps> = ({\n children,\n direction,\n itemDelay = DEFAULT_ITEM_DELAY,\n itemDuration = DEFAULT_ITEM_DURATION,\n reversed = false,\n hideMode,\n delayMode = 'timing',\n onMotionFinish,\n}) => {\n const childMapping = React.useMemo(() => getStaggerChildMapping(children), [children]);\n\n // Always call hooks at the top level, regardless of delayMode\n const { itemsVisibility } = useStaggerItemsVisibility({\n childMapping,\n itemDelay,\n itemDuration,\n direction,\n reversed,\n onMotionFinish,\n hideMode,\n });\n\n // For delayProp mode, pass delay props directly to motion components\n if (delayMode === 'delayProp') {\n return (\n <>\n {Object.entries(childMapping).map(([key, { element, index }]) => {\n const staggerIndex = reversed ? Object.keys(childMapping).length - 1 - index : index;\n const delay = staggerIndex * itemDelay;\n\n // Clone element with delay prop (for enter direction) or exitDelay prop (for exit direction)\n const delayProp = direction === 'enter' ? { delay } : { exitDelay: delay };\n\n // Only set visible prop if the component supports it\n // Set visible based on direction: true for enter, false for exit\n const visibleProp = acceptsVisibleProp(element) ? { visible: direction === 'enter' } : {};\n\n return React.cloneElement(element, {\n key,\n ...visibleProp,\n ...delayProp,\n });\n })}\n </>\n );\n }\n\n // For timing mode, use the existing timing-based implementation\n\n return (\n <>\n {Object.entries(childMapping).map(([key, { element }]) => {\n if (hideMode === 'visibleProp') {\n // Use a generic record type for props to avoid `any` while still allowing unknown prop shapes.\n return React.cloneElement(element, {\n key,\n visible: itemsVisibility[key],\n } as Partial<Record<string, unknown>>);\n } else if (hideMode === 'visibilityStyle') {\n const childProps = element.props as Record<string, unknown> | undefined;\n const style = {\n ...(childProps?.style as Record<string, unknown> | undefined),\n visibility: itemsVisibility[key] ? 'visible' : 'hidden',\n };\n return React.cloneElement(element, { key, style } as Partial<Record<string, unknown>>);\n } else {\n // unmount mode\n return itemsVisibility[key] ? React.cloneElement(element, { key }) : null;\n }\n })}\n </>\n );\n};\n\n// Shared helper for StaggerIn and StaggerOut\nconst createStaggerDirection = (direction: 'enter' | 'exit') => {\n const StaggerDirection: React.FC<Omit<StaggerProps, 'visible'>> = ({ hideMode, delayMode, children, ...props }) => {\n // Auto-detect modes for better performance with motion components\n const { hideMode: resolvedHideMode, delayMode: resolvedDelayMode } = detectStaggerModes(children, {\n hideMode,\n delayMode,\n // One-way stagger falls back to visibilityStyle if it doesn't detect visibleProp support\n fallbackHideMode: 'visibilityStyle',\n });\n\n return (\n <StaggerOneWay\n {...props}\n children={children}\n direction={direction}\n hideMode={resolvedHideMode}\n delayMode={resolvedDelayMode}\n />\n );\n };\n\n return StaggerDirection;\n};\n\nconst StaggerIn = createStaggerDirection('enter');\nconst StaggerOut = createStaggerDirection('exit');\n\n// Main Stagger component with auto-detection or explicit modes\nconst StaggerMain: React.FC<StaggerProps> = props => {\n const { children, visible = false, hideMode, delayMode, ...rest } = props;\n\n // Auto-detect modes for bidirectional stagger\n const { hideMode: resolvedHideMode, delayMode: resolvedDelayMode } = detectStaggerModes(children, {\n hideMode,\n delayMode,\n // Bidirectional stagger falls back to visibilityStyle if it doesn't detect visibleProp support\n fallbackHideMode: 'visibilityStyle',\n });\n\n const direction = visible ? 'enter' : 'exit';\n\n return (\n <StaggerOneWay\n {...rest}\n children={children}\n hideMode={resolvedHideMode}\n delayMode={resolvedDelayMode}\n direction={direction}\n />\n );\n};\n\n/**\n * Stagger is a component that manages the staggered entrance and exit of its children.\n * Children are animated in sequence with configurable timing between each item.\n * Stagger can be interactively toggled between entrance and exit animations using the `visible` prop.\n *\n * @param children - React elements to animate. Elements are cloned with animation props.\n * @param visible - Controls animation direction. When `true`, the group is animating \"enter\" (items shown);\n * when `false`, the group is animating \"exit\" (items hidden). Defaults to `false`.\n * @param itemDelay - Milliseconds between each item's animation start.\n * Defaults to the package's default delay (see `DEFAULT_ITEM_DELAY`).\n * @param itemDuration - Milliseconds each item's animation lasts. Only used with `delayMode=\"timing\"`.\n * Defaults to the package's default item duration (see `DEFAULT_ITEM_DURATION`).\n * @param reversed - Whether to reverse the stagger sequence (last item animates first). Defaults to `false`.\n * @param hideMode - How children's visibility/mounting is managed. Auto-detects if not specified.\n * @param delayMode - How staggering timing is implemented. Auto-detects if not specified.\n * @param onMotionFinish - Callback invoked when the staggered animation sequence completes.\n *\n * **Auto-detection behavior:**\n * - **hideMode**: Presence components use `'visibleProp'`, DOM elements use `'visibilityStyle'`\n * - **delayMode**: Components with delay support use `'delayProp'` (most performant), others use `'timing'`\n *\n * **hideMode options:**\n * - `'visibleProp'`: Children are presence components with `visible` prop (always rendered, visibility controlled via prop)\n * - `'visibilityStyle'`: Children remain in DOM with inline style visibility: hidden/visible (preserves layout space)\n * - `'unmount'`: Children are mounted/unmounted from DOM based on visibility\n *\n * **delayMode options:**\n * - `'timing'`: Manages visibility over time using JavaScript timing\n * - `'delayProp'`: Passes delay props to motion components to use native Web Animations API delays (most performant)\n *\n * **Static variants:**\n * - `<Stagger.In>` - One-way stagger for entrance animations only (auto-detects optimal modes)\n * - `<Stagger.Out>` - One-way stagger for exit animations only (auto-detects optimal modes)\n *\n * @example\n * ```tsx\n * import { Stagger, Fade, Scale, Rotate } from '@fluentui/react-motion-components-preview';\n *\n * // Auto-detects optimal modes for presence components (delayProp + visibleProp)\n * <Stagger visible={isVisible} itemDelay={150}>\n * <Fade><div>Item 2</div></Fade>\n * <Scale><div>Item 1</div></Scale>\n * <Rotate><div>Item 3</div></Rotate>\n * </Stagger>\n *\n * // Auto-detects optimal modes for motion components (delayProp + unmount)\n * <Stagger.In itemDelay={100}>\n * <Scale.In><div>Item 1</div></Scale.In>\n * <Fade.In><div>Item 2</div></Fade.In>\n * </Stagger.In>\n *\n * // Auto-detects timing mode for DOM elements (timing + visibilityStyle)\n * <Stagger visible={isVisible} itemDelay={150} onMotionFinish={handleComplete}>\n * <div>Item 1</div>\n * <div>Item 2</div>\n * <div>Item 3</div>\n * </Stagger>\n *\n * // Override auto-detection when needed\n * <Stagger visible={isVisible} delayMode=\"timing\" hideMode=\"unmount\">\n * <CustomComponent>Item 1</CustomComponent>\n * </Stagger>\n * ```\n */\nexport const Stagger = Object.assign(StaggerMain, {\n In: StaggerIn,\n Out: StaggerOut,\n});\n"],"names":["Stagger","detectStaggerModes","children","options","hideMode","delayMode","fallbackHideMode","childMapping","getStaggerChildMapping","elements","Object","values","map","item","element","hasVisiblePropSupport","every","child","acceptsVisibleProp","hasDelayPropSupport","acceptsDelayProps","StaggerOneWay","direction","itemDelay","DEFAULT_ITEM_DELAY","itemDuration","DEFAULT_ITEM_DURATION","reversed","onMotionFinish","React","useMemo","itemsVisibility","useStaggerItemsVisibility","entries","key","index","staggerIndex","keys","length","delay","delayProp","exitDelay","visibleProp","visible","cloneElement","childProps","props","style","visibility","createStaggerDirection","StaggerDirection","resolvedHideMode","resolvedDelayMode","StaggerIn","StaggerOut","StaggerMain","rest","assign","In","Out"],"mappings":"AAAA;;;;;+BAsOaA;;;eAAAA;;;;iEApOU;2CACmB;uBAOnC;AAGP;;;CAGC,GACD,MAAMC,qBAAqB,CACzBC,UACAC;IAMA,MAAM,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,mBAAmB,iBAAiB,EAAE,GAAGH;IAEtE,MAAMI,eAAeC,IAAAA,6BAAsB,EAACN;IAC5C,MAAMO,WAAWC,OAAOC,MAAM,CAACJ,cAAcK,GAAG,CAACC,CAAAA,OAAQA,KAAKC,OAAO;IACrE,MAAMC,wBAAwBN,SAASO,KAAK,CAACC,CAAAA,QAASC,IAAAA,yBAAkB,EAACD;IACzE,MAAME,sBAAsBV,SAASO,KAAK,CAACC,CAAAA,QAASG,IAAAA,wBAAiB,EAACH;IAEtE,OAAO;QACLb,UAAUA,qBAAAA,sBAAAA,WAAaW,wBAAwB,gBAAgBT;QAC/DD,WAAWA,sBAAAA,uBAAAA,YAAcc,sBAAsB,cAAc;IAC/D;AACF;AAEA,MAAME,gBAA8C,CAAC,EACnDnB,QAAQ,EACRoB,SAAS,EACTC,YAAYC,yBAAkB,EAC9BC,eAAeC,4BAAqB,EACpCC,WAAW,KAAK,EAChBvB,QAAQ,EACRC,YAAY,QAAQ,EACpBuB,cAAc,EACf;IACC,MAAMrB,eAAesB,OAAMC,OAAO,CAAC,IAAMtB,IAAAA,6BAAsB,EAACN,WAAW;QAACA;KAAS;IAErF,8DAA8D;IAC9D,MAAM,EAAE6B,eAAe,EAAE,GAAG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