@zayne-labs/ui-react 0.11.0 → 0.11.1

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 (42) hide show
  1. package/css/animation.css +13 -0
  2. package/dist/esm/{cn-Bbh2G587.js → cn-CIbU5eI0.js} +1 -1
  3. package/dist/esm/{cn-Bbh2G587.js.map → cn-CIbU5eI0.js.map} +1 -1
  4. package/dist/esm/common/await/index.d.ts +2 -2
  5. package/dist/esm/common/await/index.js +3 -3
  6. package/dist/esm/common/error-boundary/index.d.ts +1 -1
  7. package/dist/esm/common/error-boundary/index.js +1 -1
  8. package/dist/esm/common/for/index.d.ts +1 -1
  9. package/dist/esm/common/presence/index.d.ts +7 -7
  10. package/dist/esm/common/presence/index.js +1 -1
  11. package/dist/esm/common/show/index.js +1 -1
  12. package/dist/esm/common/slot/index.js +1 -1
  13. package/dist/esm/common/suspense-with-boundary/index.d.ts +1 -1
  14. package/dist/esm/common/suspense-with-boundary/index.js +1 -1
  15. package/dist/esm/common/switch/index.js +1 -34
  16. package/dist/esm/common/teleport/index.js +2 -6
  17. package/dist/esm/common/teleport/index.js.map +1 -1
  18. package/dist/esm/{error-boundary-C4btQhu_.js → error-boundary-C9o5EzC9.js} +2 -2
  19. package/dist/esm/{error-boundary-C4btQhu_.js.map → error-boundary-C9o5EzC9.js.map} +1 -1
  20. package/dist/esm/{index-ClV6w6nv.d.ts → index-CaUmIQiv.d.ts} +2 -2
  21. package/dist/esm/{index-BUIvQ2wP.d.ts → index-DpVwG1sA.d.ts} +2 -2
  22. package/dist/esm/presence-DgJvW30C.js +225 -0
  23. package/dist/esm/presence-DgJvW30C.js.map +1 -0
  24. package/dist/esm/{show-BzfAw7y3.js → show-mvRnLPj8.js} +1 -1
  25. package/dist/esm/{show-BzfAw7y3.js.map → show-mvRnLPj8.js.map} +1 -1
  26. package/dist/esm/{slot-DuwoiC2C.js → slot-CHR5Li4r.js} +1 -1
  27. package/dist/esm/{slot-DuwoiC2C.js.map → slot-CHR5Li4r.js.map} +1 -1
  28. package/dist/esm/switch-Dwy5Gzsb.js +35 -0
  29. package/dist/esm/switch-Dwy5Gzsb.js.map +1 -0
  30. package/dist/esm/ui/card/index.js +2 -2
  31. package/dist/esm/ui/carousel/index.js +3 -3
  32. package/dist/esm/ui/drag-scroll/index.d.ts +0 -1
  33. package/dist/esm/ui/drag-scroll/index.js +3 -3
  34. package/dist/esm/ui/drop-zone/index.d.ts +19 -10
  35. package/dist/esm/ui/drop-zone/index.js +65 -62
  36. package/dist/esm/ui/drop-zone/index.js.map +1 -1
  37. package/dist/esm/ui/form/index.js +3 -3
  38. package/dist/style.css +16 -0
  39. package/package.json +6 -6
  40. package/dist/esm/common/switch/index.js.map +0 -1
  41. package/dist/esm/presence-CWOGx-be.js +0 -209
  42. package/dist/esm/presence-CWOGx-be.js.map +0 -1
@@ -1,209 +0,0 @@
1
- import { n as SlotRoot } from "./slot-DuwoiC2C.js";
2
- import { isFunction } from "@zayne-labs/toolkit-type-helpers";
3
- import { useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState } from "react";
4
- import { useCallbackRef, useComposeRefs, useToggle } from "@zayne-labs/toolkit-react";
5
- import { jsx } from "react/jsx-runtime";
6
- import { dataAttr, on } from "@zayne-labs/toolkit-core";
7
- //#region src/components/common/presence/use-presence.ts
8
- const useStateMachine = (config) => {
9
- const reducer = (prevState, event) => {
10
- return config.states[prevState][event] ?? prevState;
11
- };
12
- return useReducer(reducer, config.initial);
13
- };
14
- const getAnimationName = (styles) => styles?.animationName ?? "none";
15
- /**
16
- * React hook that provides the ability to animate the mount/unmount of a component.
17
- * @see https://github.com/radix-ui/primitives/blob/main/packages/react/presence/src/presence.tsx
18
- */
19
- const usePresence = (options) => {
20
- const { onExitComplete, present: presentProp, variant = "animation" } = options;
21
- const stableOnExitComplete = useCallbackRef(onExitComplete);
22
- const [node, setNode] = useState(null);
23
- const [hasTransitioned, toggleHasTransitioned] = useToggle(false);
24
- const stylesRef = useRef(null);
25
- const prevNodeStateRef = useRef({
26
- prevAnimationName: "none",
27
- prevPresent: presentProp
28
- });
29
- const [state, send] = useStateMachine({
30
- initial: presentProp ? "mounted" : "unmounted",
31
- states: {
32
- mounted: {
33
- ANIMATION_OUT: "unmountSuspended",
34
- UNMOUNT: "unmounted"
35
- },
36
- unmounted: { MOUNT: "mounted" },
37
- unmountSuspended: {
38
- ANIMATION_END: "unmounted",
39
- MOUNT: "mounted"
40
- }
41
- }
42
- });
43
- useEffect(() => {
44
- const currentAnimationName = getAnimationName(stylesRef.current);
45
- prevNodeStateRef.current.prevAnimationName = state === "mounted" ? currentAnimationName : "none";
46
- }, [state]);
47
- useLayoutEffect(() => {
48
- const styles = stylesRef.current;
49
- const wasPresent = prevNodeStateRef.current.prevPresent;
50
- if (!(wasPresent !== presentProp)) return;
51
- const prevAnimationName = prevNodeStateRef.current.prevAnimationName;
52
- const currentAnimationName = getAnimationName(styles);
53
- switch (true) {
54
- case presentProp:
55
- send("MOUNT");
56
- if (variant === "transition") requestAnimationFrame(() => toggleHasTransitioned(true));
57
- break;
58
- case Boolean(node) && variant === "animation": {
59
- /**
60
- * When `present` changes to `false`, we check changes to animation-name to
61
- * determine whether an animation has started. We chose this approach (reading
62
- * computed styles) because there is no `animationrun` event (like the `transitionrun` event) and `animationstart`
63
- * fires after `animation-delay` has expired which would be too late.
64
- */
65
- const isAnimationStarted = currentAnimationName !== "none" && styles?.display !== "none" && prevAnimationName !== currentAnimationName;
66
- send(wasPresent && isAnimationStarted ? "ANIMATION_OUT" : "UNMOUNT");
67
- break;
68
- }
69
- default:
70
- send("UNMOUNT");
71
- break;
72
- }
73
- prevNodeStateRef.current.prevPresent = presentProp;
74
- }, [
75
- presentProp,
76
- node,
77
- send,
78
- variant,
79
- toggleHasTransitioned
80
- ]);
81
- useLayoutEffect(() => {
82
- if (!node) {
83
- send("ANIMATION_END");
84
- return;
85
- }
86
- let timeoutId;
87
- const ownerWindow = node.ownerDocument.defaultView ?? globalThis;
88
- const handleAnimationStart = (event) => {
89
- if (!(event.target === node)) return;
90
- prevNodeStateRef.current.prevAnimationName = getAnimationName(stylesRef.current);
91
- };
92
- /**
93
- * @description Triggering an ANIMATION_OUT during an ANIMATION_IN will fire an `animationcancel`
94
- * event for ANIMATION_IN after we have entered `unmountSuspended` state. So, we
95
- * make sure we only trigger ANIMATION_END for the currently active animation.
96
- */
97
- const handleAnimationEnd = (event) => {
98
- const isCurrentAnimation = getAnimationName(stylesRef.current).includes(CSS.escape(event.animationName));
99
- if (!(event.target === node && isCurrentAnimation)) return;
100
- send("ANIMATION_END");
101
- if (!prevNodeStateRef.current.prevPresent) {
102
- const currentFillMode = node.style.animationFillMode;
103
- node.style.animationFillMode = "forwards";
104
- timeoutId = ownerWindow.setTimeout(() => {
105
- if (node.style.animationFillMode === "forwards") node.style.animationFillMode = currentFillMode;
106
- });
107
- }
108
- };
109
- const handleTransitionRun = (event) => {
110
- if (!(event.target === node)) return;
111
- send("ANIMATION_OUT");
112
- };
113
- const handleTransitionEnd = (event) => {
114
- if (!(event.target === node && !prevNodeStateRef.current.prevPresent)) return;
115
- send("ANIMATION_END");
116
- };
117
- const onAnimationStartCleanup = on(node, "animationstart", handleAnimationStart);
118
- const onAnimationEndCleanup = on(node, "animationend", handleAnimationEnd);
119
- const onAnimationCancelCleanup = on(node, "animationcancel", handleAnimationEnd);
120
- const onTransitionRunCleanup = on(node, "transitionrun", handleTransitionRun);
121
- const onTransitionEndCleanup = on(node, "transitionend", handleTransitionEnd);
122
- const onTransitionCancelCleanup = on(node, "transitioncancel", handleTransitionEnd);
123
- return () => {
124
- ownerWindow.clearTimeout(timeoutId);
125
- onAnimationStartCleanup();
126
- onAnimationEndCleanup();
127
- onAnimationCancelCleanup();
128
- onTransitionRunCleanup();
129
- onTransitionEndCleanup();
130
- onTransitionCancelCleanup();
131
- };
132
- }, [node, send]);
133
- useEffect(() => {
134
- if (state === "unmounted" && !presentProp) {
135
- toggleHasTransitioned(false);
136
- stableOnExitComplete?.();
137
- }
138
- }, [
139
- state,
140
- presentProp,
141
- stableOnExitComplete,
142
- toggleHasTransitioned
143
- ]);
144
- const ref = useCallbackRef((refNode) => {
145
- setNode(refNode);
146
- if (refNode) stylesRef.current = getComputedStyle(refNode);
147
- });
148
- const isPresent = ["mounted", "unmountSuspended"].includes(state);
149
- const isPresentOrIsTransitionComplete = isPresent || hasTransitioned;
150
- const shouldStartTransition = presentProp && hasTransitioned;
151
- const getPresenceProps = useCallback((innerProps) => {
152
- const transitionState = shouldStartTransition ? "active" : "inactive";
153
- return {
154
- "data-present": dataAttr(isPresent),
155
- "data-present-or-transition-complete": dataAttr(isPresentOrIsTransitionComplete),
156
- "data-state": state,
157
- ...variant === "transition" && { "data-transition": transitionState },
158
- ...innerProps,
159
- className: innerProps.className
160
- };
161
- }, [
162
- isPresent,
163
- isPresentOrIsTransitionComplete,
164
- shouldStartTransition,
165
- state,
166
- variant
167
- ]);
168
- const propGetters = useMemo(() => ({ getPresenceProps }), [getPresenceProps]);
169
- return useMemo(() => ({
170
- isPresent,
171
- isPresentOrIsTransitionComplete,
172
- propGetters,
173
- ref,
174
- shouldStartTransition
175
- }), [
176
- isPresent,
177
- isPresentOrIsTransitionComplete,
178
- propGetters,
179
- ref,
180
- shouldStartTransition
181
- ]);
182
- };
183
- //#endregion
184
- //#region src/components/common/presence/presence.tsx
185
- function Presence(props) {
186
- const { children, className, forceMount = false, onExitComplete, present, variant } = props;
187
- const { isPresent, isPresentOrIsTransitionComplete, propGetters, ref: presenceRef, shouldStartTransition } = usePresence({
188
- onExitComplete,
189
- present,
190
- variant
191
- });
192
- const context = {
193
- isPresent,
194
- isPresentOrIsTransitionComplete,
195
- shouldStartTransition
196
- };
197
- const resolvedChild = isFunction(children) ? children(context) : children;
198
- const ref = useComposeRefs(presenceRef, resolvedChild?.props.ref ?? resolvedChild.ref);
199
- if (!(forceMount || (variant === "transition" ? isPresentOrIsTransitionComplete : isPresent))) return null;
200
- return /* @__PURE__ */ jsx(SlotRoot, {
201
- ref,
202
- ...propGetters.getPresenceProps({ className }),
203
- children: resolvedChild
204
- });
205
- }
206
- //#endregion
207
- export { Presence as t };
208
-
209
- //# sourceMappingURL=presence-CWOGx-be.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"presence-CWOGx-be.js","names":["Slot.Root"],"sources":["../../src/components/common/presence/use-presence.ts","../../src/components/common/presence/presence.tsx"],"sourcesContent":["import { dataAttr, on } from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef, useToggle } from \"@zayne-labs/toolkit-react\";\nimport type { InferProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState } from \"react\";\n\ntype StateMachineConfig<TState extends string, TEvent extends string> = {\n\tinitial: TState;\n\tstates: Record<TState, Partial<Record<TEvent, TState>>>;\n};\n\nconst useStateMachine = <TState extends string, TEvent extends string>(\n\tconfig: StateMachineConfig<TState, TEvent>\n) => {\n\tconst reducer = (prevState: TState, event: TEvent): TState => {\n\t\tconst newState = config.states[prevState][event] ?? prevState;\n\n\t\treturn newState;\n\t};\n\n\treturn useReducer(reducer, config.initial);\n};\n\nconst getAnimationName = (styles: CSSStyleDeclaration | null) => styles?.animationName ?? \"none\";\n\nexport type UsePresenceOptions = {\n\tonExitComplete?: () => void;\n\tpresent: boolean;\n\t/**\n\t * @default \"animation\"\n\t */\n\tvariant?: \"animation\" | \"transition\";\n};\n\nexport type UsePresenceResult = {\n\tisPresent: boolean;\n\tisPresentOrIsTransitionComplete: boolean;\n\tpropGetters: {\n\t\tgetPresenceProps: (innerProps: InferProps<HTMLElement>) => InferProps<HTMLElement>;\n\t};\n\tref: React.Ref<HTMLElement>;\n\tshouldStartTransition: boolean;\n};\n\n/**\n * React hook that provides the ability to animate the mount/unmount of a component.\n * @see https://github.com/radix-ui/primitives/blob/main/packages/react/presence/src/presence.tsx\n */\n\nconst usePresence = (options: UsePresenceOptions): UsePresenceResult => {\n\tconst { onExitComplete, present: presentProp, variant = \"animation\" } = options;\n\n\tconst stableOnExitComplete = useCallbackRef(onExitComplete);\n\n\tconst [node, setNode] = useState<HTMLElement | null>(null);\n\n\tconst [hasTransitioned, toggleHasTransitioned] = useToggle(false);\n\n\tconst stylesRef = useRef<CSSStyleDeclaration | null>(null);\n\n\tconst prevNodeStateRef = useRef<{\n\t\tprevAnimationName: string;\n\t\tprevPresent: boolean;\n\t}>({\n\t\tprevAnimationName: \"none\",\n\t\tprevPresent: presentProp,\n\t});\n\n\tconst initialState = presentProp ? \"mounted\" : \"unmounted\";\n\n\tconst [state, send] = useStateMachine({\n\t\tinitial: initialState,\n\t\tstates: {\n\t\t\tmounted: {\n\t\t\t\tANIMATION_OUT: \"unmountSuspended\",\n\t\t\t\tUNMOUNT: \"unmounted\",\n\t\t\t},\n\t\t\tunmounted: {\n\t\t\t\tMOUNT: \"mounted\",\n\t\t\t},\n\t\t\tunmountSuspended: {\n\t\t\t\tANIMATION_END: \"unmounted\",\n\t\t\t\tMOUNT: \"mounted\",\n\t\t\t},\n\t\t},\n\t});\n\n\tuseEffect(() => {\n\t\tconst currentAnimationName = getAnimationName(stylesRef.current);\n\n\t\tprevNodeStateRef.current.prevAnimationName = state === \"mounted\" ? currentAnimationName : \"none\";\n\t}, [state]);\n\n\tuseLayoutEffect(() => {\n\t\tconst styles = stylesRef.current;\n\t\tconst wasPresent = prevNodeStateRef.current.prevPresent;\n\t\tconst hasPresentChanged = wasPresent !== presentProp;\n\n\t\tif (!hasPresentChanged) return;\n\n\t\tconst prevAnimationName = prevNodeStateRef.current.prevAnimationName;\n\t\tconst currentAnimationName = getAnimationName(styles);\n\n\t\tswitch (true) {\n\t\t\tcase presentProp: {\n\t\t\t\tsend(\"MOUNT\");\n\n\t\t\t\tif (variant === \"transition\") {\n\t\t\t\t\trequestAnimationFrame(() => toggleHasTransitioned(true));\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line react-hooks/todo -- Ignore\n\t\t\tcase Boolean(node) && variant === \"animation\": {\n\t\t\t\tconst hasAnimation = currentAnimationName !== \"none\" && styles?.display !== \"none\";\n\n\t\t\t\t/**\n\t\t\t\t * When `present` changes to `false`, we check changes to animation-name to\n\t\t\t\t * determine whether an animation has started. We chose this approach (reading\n\t\t\t\t * computed styles) because there is no `animationrun` event (like the `transitionrun` event) and `animationstart`\n\t\t\t\t * fires after `animation-delay` has expired which would be too late.\n\t\t\t\t */\n\n\t\t\t\tconst isAnimationStarted = hasAnimation && prevAnimationName !== currentAnimationName;\n\n\t\t\t\tconst isAnimatingOut = wasPresent && isAnimationStarted;\n\n\t\t\t\tsend(isAnimatingOut ? \"ANIMATION_OUT\" : \"UNMOUNT\");\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tsend(\"UNMOUNT\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tprevNodeStateRef.current.prevPresent = presentProp;\n\t}, [presentProp, node, send, variant, toggleHasTransitioned]);\n\n\tuseLayoutEffect(() => {\n\t\tif (!node) {\n\t\t\t// Transition to the unmounted state if the node is removed prematurely.\n\t\t\t// We avoid doing so during cleanup as the node may change but still exist.\n\t\t\tsend(\"ANIMATION_END\");\n\t\t\treturn;\n\t\t}\n\n\t\tlet timeoutId: number;\n\n\t\tconst ownerWindow = node.ownerDocument.defaultView ?? globalThis;\n\n\t\tconst handleAnimationStart = (event: AnimationEvent) => {\n\t\t\tconst isTargetAnimatingNode = event.target === node;\n\n\t\t\tif (!isTargetAnimatingNode) return;\n\n\t\t\tprevNodeStateRef.current.prevAnimationName = getAnimationName(stylesRef.current);\n\t\t};\n\n\t\t/**\n\t\t * @description Triggering an ANIMATION_OUT during an ANIMATION_IN will fire an `animationcancel`\n\t\t * event for ANIMATION_IN after we have entered `unmountSuspended` state. So, we\n\t\t * make sure we only trigger ANIMATION_END for the currently active animation.\n\t\t */\n\t\tconst handleAnimationEnd = (event: AnimationEvent) => {\n\t\t\tconst currentAnimationName = getAnimationName(stylesRef.current);\n\n\t\t\t// The event.animationName is unescaped for CSS syntax, so we need to escape it to compare with the animationName computed from the style.\n\t\t\tconst isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));\n\n\t\t\tconst isTargetAnimatingNode = event.target === node && isCurrentAnimation;\n\n\t\t\tif (!isTargetAnimatingNode) return;\n\n\t\t\t// With React 18 concurrency this update is applied a frame after the\n\t\t\t// animation ends, creating a flash of visible content. By setting the\n\t\t\t// animation fill mode to \"forwards\", we force the node to keep the\n\t\t\t// styles of the last keyframe, removing the flash.\n\n\t\t\t// Previously we flushed the update via ReactDom.flushSync, but with\n\t\t\t// exit animations this resulted in the node being removed from the\n\t\t\t// DOM before the synthetic animationEnd event was dispatched, meaning\n\t\t\t// user-provided event handlers would not be called.\n\t\t\t// https://github.com/radix-ui/primitives/pull/1849\n\t\t\tsend(\"ANIMATION_END\");\n\n\t\t\tif (!prevNodeStateRef.current.prevPresent) {\n\t\t\t\tconst currentFillMode = node.style.animationFillMode;\n\t\t\t\tnode.style.animationFillMode = \"forwards\";\n\n\t\t\t\t// Reset the style after the node had time to unmount (for cases\n\t\t\t\t// where the component chooses not to unmount). Doing this any\n\t\t\t\t// sooner than `setTimeout` (e.g. with `requestAnimationFrame`)\n\t\t\t\t// still causes a flash.\n\t\t\t\ttimeoutId = ownerWindow.setTimeout(() => {\n\t\t\t\t\tif (node.style.animationFillMode === \"forwards\") {\n\t\t\t\t\t\tnode.style.animationFillMode = currentFillMode;\n\t\t\t\t\t}\n\t\t\t\t}) as never;\n\t\t\t}\n\t\t};\n\n\t\tconst handleTransitionRun = (event: TransitionEvent) => {\n\t\t\tconst isTargetTransitioningNode = event.target === node;\n\n\t\t\tif (!isTargetTransitioningNode) return;\n\n\t\t\tsend(\"ANIMATION_OUT\");\n\t\t};\n\n\t\tconst handleTransitionEnd = (event: TransitionEvent) => {\n\t\t\tconst isTargetTransitioningNode = event.target === node && !prevNodeStateRef.current.prevPresent;\n\n\t\t\tif (!isTargetTransitioningNode) return;\n\n\t\t\tsend(\"ANIMATION_END\");\n\t\t};\n\n\t\tconst onAnimationStartCleanup = on(node, \"animationstart\", handleAnimationStart);\n\t\tconst onAnimationEndCleanup = on(node, \"animationend\", handleAnimationEnd);\n\t\tconst onAnimationCancelCleanup = on(node, \"animationcancel\", handleAnimationEnd);\n\n\t\tconst onTransitionRunCleanup = on(node, \"transitionrun\", handleTransitionRun);\n\t\tconst onTransitionEndCleanup = on(node, \"transitionend\", handleTransitionEnd);\n\t\tconst onTransitionCancelCleanup = on(node, \"transitioncancel\", handleTransitionEnd);\n\n\t\treturn () => {\n\t\t\townerWindow.clearTimeout(timeoutId);\n\t\t\tonAnimationStartCleanup();\n\t\t\tonAnimationEndCleanup();\n\t\t\tonAnimationCancelCleanup();\n\n\t\t\tonTransitionRunCleanup();\n\t\t\tonTransitionEndCleanup();\n\t\t\tonTransitionCancelCleanup();\n\t\t};\n\t}, [node, send]);\n\n\tuseEffect(() => {\n\t\tconst isExitCompleted = state === \"unmounted\" && !presentProp;\n\n\t\tif (isExitCompleted) {\n\t\t\ttoggleHasTransitioned(false);\n\t\t\tstableOnExitComplete?.();\n\t\t}\n\t}, [state, presentProp, stableOnExitComplete, toggleHasTransitioned]);\n\n\tconst ref = useCallbackRef((refNode: HTMLElement | null) => {\n\t\tsetNode(refNode);\n\n\t\tif (refNode) {\n\t\t\tstylesRef.current = getComputedStyle(refNode);\n\t\t}\n\t});\n\n\tconst MOUNTED_STATES = [\"mounted\", \"unmountSuspended\"] satisfies Array<typeof state>;\n\tconst isPresent = MOUNTED_STATES.includes(state);\n\tconst isPresentOrIsTransitionComplete = isPresent || hasTransitioned;\n\tconst shouldStartTransition = presentProp && hasTransitioned;\n\n\tconst getPresenceProps: UsePresenceResult[\"propGetters\"][\"getPresenceProps\"] = useCallback(\n\t\t(innerProps) => {\n\t\t\tconst transitionState = shouldStartTransition ? \"active\" : \"inactive\";\n\n\t\t\treturn {\n\t\t\t\t\"data-present\": dataAttr(isPresent),\n\t\t\t\t\"data-present-or-transition-complete\": dataAttr(isPresentOrIsTransitionComplete),\n\t\t\t\t\"data-state\": state,\n\t\t\t\t...(variant === \"transition\" && { \"data-transition\": transitionState }),\n\t\t\t\t...innerProps,\n\t\t\t\tclassName: innerProps.className,\n\t\t\t};\n\t\t},\n\t\t[isPresent, isPresentOrIsTransitionComplete, shouldStartTransition, state, variant]\n\t);\n\n\tconst propGetters = useMemo(() => ({ getPresenceProps }), [getPresenceProps]);\n\n\tconst result = useMemo<UsePresenceResult>(\n\t\t() =>\n\t\t\t({\n\t\t\t\tisPresent,\n\t\t\t\tisPresentOrIsTransitionComplete,\n\t\t\t\tpropGetters,\n\t\t\t\tref,\n\t\t\t\tshouldStartTransition,\n\t\t\t}) satisfies UsePresenceResult,\n\t\t[isPresent, isPresentOrIsTransitionComplete, propGetters, ref, shouldStartTransition]\n\t);\n\n\treturn result;\n};\n\nexport { usePresence };\n","\"use client\";\n\nimport { useComposeRefs } from \"@zayne-labs/toolkit-react\";\nimport { isFunction, type UnknownObject } from \"@zayne-labs/toolkit-type-helpers\";\nimport { Slot } from \"../slot\";\nimport { usePresence, type UsePresenceOptions, type UsePresenceResult } from \"./use-presence\";\n\ntype RefProp = { ref?: React.Ref<HTMLElement> };\n\ntype RenderPropContext = Omit<UsePresenceResult, \"propGetters\" | \"ref\">;\n\nexport type PresenceProps = UsePresenceOptions & {\n\tchildren?: React.ReactElement<RefProp> | ((props: RenderPropContext) => React.ReactElement<RefProp>);\n\tclassName?: string;\n\tforceMount?: boolean;\n};\n\nfunction Presence(props: PresenceProps) {\n\tconst { children, className, forceMount = false, onExitComplete, present, variant } = props;\n\n\tconst {\n\t\tisPresent,\n\t\tisPresentOrIsTransitionComplete,\n\t\tpropGetters,\n\t\tref: presenceRef,\n\t\tshouldStartTransition,\n\t} = usePresence({ onExitComplete, present, variant });\n\n\tconst context = {\n\t\tisPresent,\n\t\tisPresentOrIsTransitionComplete,\n\t\tshouldStartTransition,\n\t} satisfies RenderPropContext;\n\n\tconst resolvedChild = isFunction(children) ? children(context) : children;\n\n\tconst childRef = (resolvedChild?.props.ref\n\t\t?? (resolvedChild as unknown as UnknownObject).ref) as React.Ref<HTMLElement>;\n\n\tconst ref = useComposeRefs(presenceRef, childRef);\n\n\tconst shouldRender =\n\t\tforceMount || (variant === \"transition\" ? isPresentOrIsTransitionComplete : isPresent);\n\n\tif (!shouldRender) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Slot.Root ref={ref} {...propGetters.getPresenceProps({ className })}>\n\t\t\t{resolvedChild}\n\t\t</Slot.Root>\n\t);\n}\n\nexport { Presence };\n"],"mappings":";;;;;;;AAUA,MAAM,mBACL,WACI;CACJ,MAAM,WAAW,WAAmB,UAA0B;AAG7D,SAFiB,OAAO,OAAO,WAAW,UAAU;;AAKrD,QAAO,WAAW,SAAS,OAAO,QAAQ;;AAG3C,MAAM,oBAAoB,WAAuC,QAAQ,iBAAiB;;;;;AA0B1F,MAAM,eAAe,YAAmD;CACvE,MAAM,EAAE,gBAAgB,SAAS,aAAa,UAAU,gBAAgB;CAExE,MAAM,uBAAuB,eAAe,eAAe;CAE3D,MAAM,CAAC,MAAM,WAAW,SAA6B,KAAK;CAE1D,MAAM,CAAC,iBAAiB,yBAAyB,UAAU,MAAM;CAEjE,MAAM,YAAY,OAAmC,KAAK;CAE1D,MAAM,mBAAmB,OAGtB;EACF,mBAAmB;EACnB,aAAa;EACb,CAAC;CAIF,MAAM,CAAC,OAAO,QAAQ,gBAAgB;EACrC,SAHoB,cAAc,YAAY;EAI9C,QAAQ;GACP,SAAS;IACR,eAAe;IACf,SAAS;IACT;GACD,WAAW,EACV,OAAO,WACP;GACD,kBAAkB;IACjB,eAAe;IACf,OAAO;IACP;GACD;EACD,CAAC;AAEF,iBAAgB;EACf,MAAM,uBAAuB,iBAAiB,UAAU,QAAQ;AAEhE,mBAAiB,QAAQ,oBAAoB,UAAU,YAAY,uBAAuB;IAC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