@vritti/quantum-ui 0.2.7 → 0.2.9

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 (207) hide show
  1. package/README.md +7 -7
  2. package/dist/Alert.js +110 -0
  3. package/dist/Alert.js.map +1 -0
  4. package/dist/Avatar.js +219 -0
  5. package/dist/Avatar.js.map +1 -0
  6. package/dist/Badge.js +32 -0
  7. package/dist/Badge.js.map +1 -0
  8. package/dist/Button2.js +2 -2
  9. package/dist/Chart.js +19003 -0
  10. package/dist/Chart.js.map +1 -0
  11. package/dist/Checkbox.js +6 -26
  12. package/dist/Checkbox.js.map +1 -1
  13. package/dist/Combination.js +3856 -0
  14. package/dist/Combination.js.map +1 -0
  15. package/dist/DatePicker.js +15 -3886
  16. package/dist/DatePicker.js.map +1 -1
  17. package/dist/DropdownMenu.js +1522 -0
  18. package/dist/DropdownMenu.js.map +1 -0
  19. package/dist/Form.js +34 -23
  20. package/dist/Form.js.map +1 -1
  21. package/dist/Label.js +1 -1
  22. package/dist/OTPField.js +16 -5
  23. package/dist/OTPField.js.map +1 -1
  24. package/dist/PhoneField.js +14 -6
  25. package/dist/PhoneField.js.map +1 -1
  26. package/dist/Progress.js +116 -0
  27. package/dist/Progress.js.map +1 -0
  28. package/dist/SelectField.js +1351 -0
  29. package/dist/SelectField.js.map +1 -0
  30. package/dist/Separator.js +6 -0
  31. package/dist/Separator.js.map +1 -0
  32. package/dist/Sonner.js +3 -38
  33. package/dist/Sonner.js.map +1 -1
  34. package/dist/Spinner.js +1 -9
  35. package/dist/Spinner.js.map +1 -1
  36. package/dist/Switch.js +210 -0
  37. package/dist/Switch.js.map +1 -0
  38. package/dist/ThemeContext.js +57 -0
  39. package/dist/ThemeContext.js.map +1 -0
  40. package/dist/ThemeToggle.js +4 -15
  41. package/dist/ThemeToggle.js.map +1 -1
  42. package/dist/Toggle.js +69 -0
  43. package/dist/Toggle.js.map +1 -0
  44. package/dist/_commonjsHelpers.js +6 -0
  45. package/dist/_commonjsHelpers.js.map +1 -0
  46. package/dist/assets/quantum-ui.css +18 -0
  47. package/dist/axios.js.map +1 -1
  48. package/dist/check.js +15 -0
  49. package/dist/check.js.map +1 -0
  50. package/dist/chevron-down.js +15 -0
  51. package/dist/chevron-down.js.map +1 -0
  52. package/dist/chevron-right.js +15 -0
  53. package/dist/chevron-right.js.map +1 -0
  54. package/dist/components/Alert.js +2 -0
  55. package/dist/components/Alert.js.map +1 -0
  56. package/dist/components/Avatar.js +2 -0
  57. package/dist/components/Avatar.js.map +1 -0
  58. package/dist/components/Badge.js +2 -0
  59. package/dist/components/Badge.js.map +1 -0
  60. package/dist/components/Chart.js +2 -0
  61. package/dist/components/Chart.js.map +1 -0
  62. package/dist/components/DropdownMenu.js +2 -0
  63. package/dist/components/DropdownMenu.js.map +1 -0
  64. package/dist/components/Progress.js +1 -174
  65. package/dist/components/Progress.js.map +1 -1
  66. package/dist/components/SelectField.js +2 -0
  67. package/dist/components/SelectField.js.map +1 -0
  68. package/dist/components/Separator.js +2 -0
  69. package/dist/components/Separator.js.map +1 -0
  70. package/dist/components/Switch.js +2 -0
  71. package/dist/components/Switch.js.map +1 -0
  72. package/dist/components/Toggle.js +2 -0
  73. package/dist/components/Toggle.js.map +1 -0
  74. package/dist/context/index.js +2 -0
  75. package/dist/context/index.js.map +1 -0
  76. package/dist/field.js +2 -49
  77. package/dist/field.js.map +1 -1
  78. package/dist/hooks/index.js +2 -0
  79. package/dist/hooks/index.js.map +1 -0
  80. package/dist/index.js +12 -0
  81. package/dist/index.js.map +1 -1
  82. package/dist/index10.js +105 -0
  83. package/dist/index10.js.map +1 -0
  84. package/dist/index11.js +79 -0
  85. package/dist/index11.js.map +1 -0
  86. package/dist/index12.js +101 -0
  87. package/dist/index12.js.map +1 -0
  88. package/dist/index13.js +205 -0
  89. package/dist/index13.js.map +1 -0
  90. package/dist/index14.js +199 -0
  91. package/dist/index14.js.map +1 -0
  92. package/dist/index2.js +55 -130
  93. package/dist/index2.js.map +1 -1
  94. package/dist/index3.js +10 -42
  95. package/dist/index3.js.map +1 -1
  96. package/dist/index4.js +125 -35
  97. package/dist/index4.js.map +1 -1
  98. package/dist/index5.js +26 -414
  99. package/dist/index5.js.map +1 -1
  100. package/dist/index6.js +8 -0
  101. package/dist/index6.js.map +1 -0
  102. package/dist/index7.js +16 -0
  103. package/dist/index7.js.map +1 -0
  104. package/dist/index8.js +45 -0
  105. package/dist/index8.js.map +1 -0
  106. package/dist/index9.js +41 -0
  107. package/dist/index9.js.map +1 -0
  108. package/dist/lib/components/Alert/Alert.d.ts +10 -0
  109. package/dist/lib/components/Alert/Alert.d.ts.map +1 -0
  110. package/dist/lib/components/Alert/index.d.ts +2 -0
  111. package/dist/lib/components/Alert/index.d.ts.map +1 -0
  112. package/dist/lib/components/Avatar/Avatar.d.ts +8 -0
  113. package/dist/lib/components/Avatar/Avatar.d.ts.map +1 -0
  114. package/dist/lib/components/Avatar/index.d.ts +2 -0
  115. package/dist/lib/components/Avatar/index.d.ts.map +1 -0
  116. package/dist/lib/components/Badge/Badge.d.ts +5 -0
  117. package/dist/lib/components/Badge/Badge.d.ts.map +1 -0
  118. package/dist/lib/components/Badge/index.d.ts +3 -0
  119. package/dist/lib/components/Badge/index.d.ts.map +1 -0
  120. package/dist/lib/components/Button/index.d.ts +1 -1
  121. package/dist/lib/components/Button/index.d.ts.map +1 -1
  122. package/dist/lib/components/Chart/Chart.d.ts +13 -0
  123. package/dist/lib/components/Chart/Chart.d.ts.map +1 -0
  124. package/dist/lib/components/Chart/index.d.ts +3 -0
  125. package/dist/lib/components/Chart/index.d.ts.map +1 -0
  126. package/dist/lib/components/DropdownMenu/DropdownMenu.d.ts +28 -0
  127. package/dist/lib/components/DropdownMenu/DropdownMenu.d.ts.map +1 -0
  128. package/dist/lib/components/DropdownMenu/index.d.ts +3 -0
  129. package/dist/lib/components/DropdownMenu/index.d.ts.map +1 -0
  130. package/dist/lib/components/DropdownMenu/types.d.ts +72 -0
  131. package/dist/lib/components/DropdownMenu/types.d.ts.map +1 -0
  132. package/dist/lib/components/Form/Form.d.ts +1 -1
  133. package/dist/lib/components/Form/Form.d.ts.map +1 -1
  134. package/dist/lib/components/OTPField/OTPField.d.ts.map +1 -1
  135. package/dist/lib/components/PhoneField/PhoneField.d.ts.map +1 -1
  136. package/dist/lib/components/SelectField/SelectField.d.ts +24 -0
  137. package/dist/lib/components/SelectField/SelectField.d.ts.map +1 -0
  138. package/dist/lib/components/SelectField/index.d.ts +3 -0
  139. package/dist/lib/components/SelectField/index.d.ts.map +1 -0
  140. package/dist/lib/components/Separator/Separator.d.ts +3 -0
  141. package/dist/lib/components/Separator/Separator.d.ts.map +1 -0
  142. package/dist/lib/components/Separator/index.d.ts +2 -0
  143. package/dist/lib/components/Separator/index.d.ts.map +1 -0
  144. package/dist/lib/components/Switch/Switch.d.ts +9 -0
  145. package/dist/lib/components/Switch/Switch.d.ts.map +1 -0
  146. package/dist/lib/components/Switch/index.d.ts +3 -0
  147. package/dist/lib/components/Switch/index.d.ts.map +1 -0
  148. package/dist/lib/components/ThemeToggle/ThemeToggle.d.ts.map +1 -1
  149. package/dist/lib/components/Toggle/Toggle.d.ts +7 -0
  150. package/dist/lib/components/Toggle/Toggle.d.ts.map +1 -0
  151. package/dist/lib/components/Toggle/index.d.ts +2 -0
  152. package/dist/lib/components/Toggle/index.d.ts.map +1 -0
  153. package/dist/lib/components/index.d.ts +10 -0
  154. package/dist/lib/components/index.d.ts.map +1 -1
  155. package/dist/lib/context/ThemeContext.d.ts +18 -0
  156. package/dist/lib/context/ThemeContext.d.ts.map +1 -0
  157. package/dist/lib/context/index.d.ts +2 -0
  158. package/dist/lib/context/index.d.ts.map +1 -0
  159. package/dist/lib/hooks/index.d.ts +2 -0
  160. package/dist/lib/hooks/index.d.ts.map +1 -0
  161. package/dist/lib/hooks/useTheme.d.ts +8 -0
  162. package/dist/lib/hooks/useTheme.d.ts.map +1 -0
  163. package/dist/lib/index.d.ts +2 -0
  164. package/dist/lib/index.d.ts.map +1 -1
  165. package/dist/lib/theme/index.d.ts +13 -0
  166. package/dist/lib/theme/index.d.ts.map +1 -0
  167. package/dist/lib/utils/axios.d.ts +1 -0
  168. package/dist/lib/utils/axios.d.ts.map +1 -1
  169. package/dist/lib/utils/formHelpers.d.ts +7 -3
  170. package/dist/lib/utils/formHelpers.d.ts.map +1 -1
  171. package/dist/separator2.js +53 -0
  172. package/dist/separator2.js.map +1 -0
  173. package/dist/shadcn/index.d.ts +1 -1
  174. package/dist/shadcn/index.d.ts.map +1 -1
  175. package/dist/shadcn/shadcnAlert/alert.d.ts +11 -0
  176. package/dist/shadcn/shadcnAlert/alert.d.ts.map +1 -0
  177. package/dist/shadcn/shadcnAlert/index.d.ts +2 -0
  178. package/dist/shadcn/shadcnAlert/index.d.ts.map +1 -0
  179. package/dist/shadcn/shadcnAvatar/Avatar.d.ts +12 -0
  180. package/dist/shadcn/shadcnAvatar/Avatar.d.ts.map +1 -0
  181. package/dist/shadcn/shadcnAvatar/index.d.ts +2 -0
  182. package/dist/shadcn/shadcnAvatar/index.d.ts.map +1 -0
  183. package/dist/shadcn/shadcnBadge/Badge.d.ts +11 -0
  184. package/dist/shadcn/shadcnBadge/Badge.d.ts.map +1 -0
  185. package/dist/shadcn/shadcnBadge/index.d.ts +3 -0
  186. package/dist/shadcn/shadcnBadge/index.d.ts.map +1 -0
  187. package/dist/shadcn/shadcnButton/Button.d.ts +2 -2
  188. package/dist/shadcn/shadcnChart/Chart.d.ts +58 -0
  189. package/dist/shadcn/shadcnChart/Chart.d.ts.map +1 -0
  190. package/dist/shadcn/shadcnChart/index.d.ts +3 -0
  191. package/dist/shadcn/shadcnChart/index.d.ts.map +1 -0
  192. package/dist/shadcn/shadcnSpinner/Spinner.d.ts.map +1 -1
  193. package/dist/shadcn/shadcnSwitch/Switch.d.ts +7 -0
  194. package/dist/shadcn/shadcnSwitch/Switch.d.ts.map +1 -0
  195. package/dist/shadcn/shadcnSwitch/index.d.ts +2 -0
  196. package/dist/shadcn/shadcnSwitch/index.d.ts.map +1 -0
  197. package/dist/shadcn/shadcnToggle/Toggle.d.ts +10 -0
  198. package/dist/shadcn/shadcnToggle/Toggle.d.ts.map +1 -0
  199. package/dist/shadcn/shadcnToggle/index.d.ts +2 -0
  200. package/dist/shadcn/shadcnToggle/index.d.ts.map +1 -0
  201. package/dist/theme/index.js +11 -0
  202. package/dist/theme/index.js.map +1 -0
  203. package/dist/triangle-alert.js +40 -0
  204. package/dist/triangle-alert.js.map +1 -0
  205. package/dist/useTheme.js +15 -0
  206. package/dist/useTheme.js.map +1 -0
  207. package/package.json +59 -6
package/dist/index4.js CHANGED
@@ -1,41 +1,131 @@
1
1
  import * as React from 'react';
2
- import 'react-dom';
3
- import { c as createSlot } from './index2.js';
4
- import { jsx } from 'react/jsx-runtime';
2
+ import { u as useComposedRefs } from './index5.js';
3
+ import { u as useLayoutEffect2 } from './index6.js';
5
4
 
6
- // src/primitive.tsx
7
- var NODES = [
8
- "a",
9
- "button",
10
- "div",
11
- "form",
12
- "h2",
13
- "h3",
14
- "img",
15
- "input",
16
- "label",
17
- "li",
18
- "nav",
19
- "ol",
20
- "p",
21
- "select",
22
- "span",
23
- "svg",
24
- "ul"
25
- ];
26
- var Primitive = NODES.reduce((primitive, node) => {
27
- const Slot = createSlot(`Primitive.${node}`);
28
- const Node = React.forwardRef((props, forwardedRef) => {
29
- const { asChild, ...primitiveProps } = props;
30
- const Comp = asChild ? Slot : node;
31
- if (typeof window !== "undefined") {
32
- window[Symbol.for("radix-ui")] = true;
5
+ function useStateMachine(initialState, machine) {
6
+ return React.useReducer((state, event) => {
7
+ const nextState = machine[state][event];
8
+ return nextState ?? state;
9
+ }, initialState);
10
+ }
11
+
12
+ // src/presence.tsx
13
+ var Presence = (props) => {
14
+ const { present, children } = props;
15
+ const presence = usePresence(present);
16
+ const child = typeof children === "function" ? children({ present: presence.isPresent }) : React.Children.only(children);
17
+ const ref = useComposedRefs(presence.ref, getElementRef(child));
18
+ const forceMount = typeof children === "function";
19
+ return forceMount || presence.isPresent ? React.cloneElement(child, { ref }) : null;
20
+ };
21
+ Presence.displayName = "Presence";
22
+ function usePresence(present) {
23
+ const [node, setNode] = React.useState();
24
+ const stylesRef = React.useRef(null);
25
+ const prevPresentRef = React.useRef(present);
26
+ const prevAnimationNameRef = React.useRef("none");
27
+ const initialState = present ? "mounted" : "unmounted";
28
+ const [state, send] = useStateMachine(initialState, {
29
+ mounted: {
30
+ UNMOUNT: "unmounted",
31
+ ANIMATION_OUT: "unmountSuspended"
32
+ },
33
+ unmountSuspended: {
34
+ MOUNT: "mounted",
35
+ ANIMATION_END: "unmounted"
36
+ },
37
+ unmounted: {
38
+ MOUNT: "mounted"
33
39
  }
34
- return /* @__PURE__ */ jsx(Comp, { ...primitiveProps, ref: forwardedRef });
35
40
  });
36
- Node.displayName = `Primitive.${node}`;
37
- return { ...primitive, [node]: Node };
38
- }, {});
41
+ React.useEffect(() => {
42
+ const currentAnimationName = getAnimationName(stylesRef.current);
43
+ prevAnimationNameRef.current = state === "mounted" ? currentAnimationName : "none";
44
+ }, [state]);
45
+ useLayoutEffect2(() => {
46
+ const styles = stylesRef.current;
47
+ const wasPresent = prevPresentRef.current;
48
+ const hasPresentChanged = wasPresent !== present;
49
+ if (hasPresentChanged) {
50
+ const prevAnimationName = prevAnimationNameRef.current;
51
+ const currentAnimationName = getAnimationName(styles);
52
+ if (present) {
53
+ send("MOUNT");
54
+ } else if (currentAnimationName === "none" || styles?.display === "none") {
55
+ send("UNMOUNT");
56
+ } else {
57
+ const isAnimating = prevAnimationName !== currentAnimationName;
58
+ if (wasPresent && isAnimating) {
59
+ send("ANIMATION_OUT");
60
+ } else {
61
+ send("UNMOUNT");
62
+ }
63
+ }
64
+ prevPresentRef.current = present;
65
+ }
66
+ }, [present, send]);
67
+ useLayoutEffect2(() => {
68
+ if (node) {
69
+ let timeoutId;
70
+ const ownerWindow = node.ownerDocument.defaultView ?? window;
71
+ const handleAnimationEnd = (event) => {
72
+ const currentAnimationName = getAnimationName(stylesRef.current);
73
+ const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));
74
+ if (event.target === node && isCurrentAnimation) {
75
+ send("ANIMATION_END");
76
+ if (!prevPresentRef.current) {
77
+ const currentFillMode = node.style.animationFillMode;
78
+ node.style.animationFillMode = "forwards";
79
+ timeoutId = ownerWindow.setTimeout(() => {
80
+ if (node.style.animationFillMode === "forwards") {
81
+ node.style.animationFillMode = currentFillMode;
82
+ }
83
+ });
84
+ }
85
+ }
86
+ };
87
+ const handleAnimationStart = (event) => {
88
+ if (event.target === node) {
89
+ prevAnimationNameRef.current = getAnimationName(stylesRef.current);
90
+ }
91
+ };
92
+ node.addEventListener("animationstart", handleAnimationStart);
93
+ node.addEventListener("animationcancel", handleAnimationEnd);
94
+ node.addEventListener("animationend", handleAnimationEnd);
95
+ return () => {
96
+ ownerWindow.clearTimeout(timeoutId);
97
+ node.removeEventListener("animationstart", handleAnimationStart);
98
+ node.removeEventListener("animationcancel", handleAnimationEnd);
99
+ node.removeEventListener("animationend", handleAnimationEnd);
100
+ };
101
+ } else {
102
+ send("ANIMATION_END");
103
+ }
104
+ }, [node, send]);
105
+ return {
106
+ isPresent: ["mounted", "unmountSuspended"].includes(state),
107
+ ref: React.useCallback((node2) => {
108
+ stylesRef.current = node2 ? getComputedStyle(node2) : null;
109
+ setNode(node2);
110
+ }, [])
111
+ };
112
+ }
113
+ function getAnimationName(styles) {
114
+ return styles?.animationName || "none";
115
+ }
116
+ function getElementRef(element) {
117
+ let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
118
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
119
+ if (mayWarn) {
120
+ return element.ref;
121
+ }
122
+ getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
123
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
124
+ if (mayWarn) {
125
+ return element.props.ref;
126
+ }
127
+ return element.props.ref || element.ref;
128
+ }
39
129
 
40
- export { Primitive as P };
130
+ export { Presence as P };
41
131
  //# sourceMappingURL=index4.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index4.js","sources":["../node_modules/.pnpm/@radix-ui+react-primitive@2.1.4_@types+react-dom@19.2.3_@types+react@19.2.9__@types+rea_80b0e86615c8e72f2e6ad5b837a6e15c/node_modules/@radix-ui/react-primitive/dist/index.mjs"],"sourcesContent":["// src/primitive.tsx\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport { createSlot } from \"@radix-ui/react-slot\";\nimport { jsx } from \"react/jsx-runtime\";\nvar NODES = [\n \"a\",\n \"button\",\n \"div\",\n \"form\",\n \"h2\",\n \"h3\",\n \"img\",\n \"input\",\n \"label\",\n \"li\",\n \"nav\",\n \"ol\",\n \"p\",\n \"select\",\n \"span\",\n \"svg\",\n \"ul\"\n];\nvar Primitive = NODES.reduce((primitive, node) => {\n const Slot = createSlot(`Primitive.${node}`);\n const Node = React.forwardRef((props, forwardedRef) => {\n const { asChild, ...primitiveProps } = props;\n const Comp = asChild ? Slot : node;\n if (typeof window !== \"undefined\") {\n window[Symbol.for(\"radix-ui\")] = true;\n }\n return /* @__PURE__ */ jsx(Comp, { ...primitiveProps, ref: forwardedRef });\n });\n Node.displayName = `Primitive.${node}`;\n return { ...primitive, [node]: Node };\n}, {});\nfunction dispatchDiscreteCustomEvent(target, event) {\n if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));\n}\nvar Root = Primitive;\nexport {\n Primitive,\n Root,\n dispatchDiscreteCustomEvent\n};\n//# sourceMappingURL=index.mjs.map\n"],"names":[],"mappings":";;;;;AAAA;AAKA,IAAI,KAAK,GAAG;AACZ,EAAE,GAAG;AACL,EAAE,QAAQ;AACV,EAAE,KAAK;AACP,EAAE,MAAM;AACR,EAAE,IAAI;AACN,EAAE,IAAI;AACN,EAAE,KAAK;AACP,EAAE,OAAO;AACT,EAAE,OAAO;AACT,EAAE,IAAI;AACN,EAAE,KAAK;AACP,EAAE,IAAI;AACN,EAAE,GAAG;AACL,EAAE,QAAQ;AACV,EAAE,MAAM;AACR,EAAE,KAAK;AACP,EAAE;AACF,CAAC;AACE,IAAC,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,IAAI,KAAK;AAClD,EAAE,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;AAC9C,EAAE,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK;AACzD,IAAI,MAAM,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,GAAG,KAAK;AAChD,IAAI,MAAM,IAAI,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI;AACtC,IAAI,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AACvC,MAAM,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,IAAI;AAC3C,IAAI;AACJ,IAAI,uBAAuB,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC;AAC9E,EAAE,CAAC,CAAC;AACJ,EAAE,IAAI,CAAC,WAAW,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACxC,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE,CAAC,IAAI,GAAG,IAAI,EAAE;AACvC,CAAC,EAAE,EAAE;;;;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"index4.js","sources":["../node_modules/.pnpm/@radix-ui+react-presence@1.1.5_@types+react-dom@19.2.3_@types+react@19.2.9__@types+reac_e89ee5370fa5954404ef113347ae9cd5/node_modules/@radix-ui/react-presence/dist/index.mjs"],"sourcesContent":["\"use client\";\n\n// src/presence.tsx\nimport * as React2 from \"react\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { useLayoutEffect } from \"@radix-ui/react-use-layout-effect\";\n\n// src/use-state-machine.tsx\nimport * as React from \"react\";\nfunction useStateMachine(initialState, machine) {\n return React.useReducer((state, event) => {\n const nextState = machine[state][event];\n return nextState ?? state;\n }, initialState);\n}\n\n// src/presence.tsx\nvar Presence = (props) => {\n const { present, children } = props;\n const presence = usePresence(present);\n const child = typeof children === \"function\" ? children({ present: presence.isPresent }) : React2.Children.only(children);\n const ref = useComposedRefs(presence.ref, getElementRef(child));\n const forceMount = typeof children === \"function\";\n return forceMount || presence.isPresent ? React2.cloneElement(child, { ref }) : null;\n};\nPresence.displayName = \"Presence\";\nfunction usePresence(present) {\n const [node, setNode] = React2.useState();\n const stylesRef = React2.useRef(null);\n const prevPresentRef = React2.useRef(present);\n const prevAnimationNameRef = React2.useRef(\"none\");\n const initialState = present ? \"mounted\" : \"unmounted\";\n const [state, send] = useStateMachine(initialState, {\n mounted: {\n UNMOUNT: \"unmounted\",\n ANIMATION_OUT: \"unmountSuspended\"\n },\n unmountSuspended: {\n MOUNT: \"mounted\",\n ANIMATION_END: \"unmounted\"\n },\n unmounted: {\n MOUNT: \"mounted\"\n }\n });\n React2.useEffect(() => {\n const currentAnimationName = getAnimationName(stylesRef.current);\n prevAnimationNameRef.current = state === \"mounted\" ? currentAnimationName : \"none\";\n }, [state]);\n useLayoutEffect(() => {\n const styles = stylesRef.current;\n const wasPresent = prevPresentRef.current;\n const hasPresentChanged = wasPresent !== present;\n if (hasPresentChanged) {\n const prevAnimationName = prevAnimationNameRef.current;\n const currentAnimationName = getAnimationName(styles);\n if (present) {\n send(\"MOUNT\");\n } else if (currentAnimationName === \"none\" || styles?.display === \"none\") {\n send(\"UNMOUNT\");\n } else {\n const isAnimating = prevAnimationName !== currentAnimationName;\n if (wasPresent && isAnimating) {\n send(\"ANIMATION_OUT\");\n } else {\n send(\"UNMOUNT\");\n }\n }\n prevPresentRef.current = present;\n }\n }, [present, send]);\n useLayoutEffect(() => {\n if (node) {\n let timeoutId;\n const ownerWindow = node.ownerDocument.defaultView ?? window;\n const handleAnimationEnd = (event) => {\n const currentAnimationName = getAnimationName(stylesRef.current);\n const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));\n if (event.target === node && isCurrentAnimation) {\n send(\"ANIMATION_END\");\n if (!prevPresentRef.current) {\n const currentFillMode = node.style.animationFillMode;\n node.style.animationFillMode = \"forwards\";\n timeoutId = ownerWindow.setTimeout(() => {\n if (node.style.animationFillMode === \"forwards\") {\n node.style.animationFillMode = currentFillMode;\n }\n });\n }\n }\n };\n const handleAnimationStart = (event) => {\n if (event.target === node) {\n prevAnimationNameRef.current = getAnimationName(stylesRef.current);\n }\n };\n node.addEventListener(\"animationstart\", handleAnimationStart);\n node.addEventListener(\"animationcancel\", handleAnimationEnd);\n node.addEventListener(\"animationend\", handleAnimationEnd);\n return () => {\n ownerWindow.clearTimeout(timeoutId);\n node.removeEventListener(\"animationstart\", handleAnimationStart);\n node.removeEventListener(\"animationcancel\", handleAnimationEnd);\n node.removeEventListener(\"animationend\", handleAnimationEnd);\n };\n } else {\n send(\"ANIMATION_END\");\n }\n }, [node, send]);\n return {\n isPresent: [\"mounted\", \"unmountSuspended\"].includes(state),\n ref: React2.useCallback((node2) => {\n stylesRef.current = node2 ? getComputedStyle(node2) : null;\n setNode(node2);\n }, [])\n };\n}\nfunction getAnimationName(styles) {\n return styles?.animationName || \"none\";\n}\nfunction getElementRef(element) {\n let getter = Object.getOwnPropertyDescriptor(element.props, \"ref\")?.get;\n let mayWarn = getter && \"isReactWarning\" in getter && getter.isReactWarning;\n if (mayWarn) {\n return element.ref;\n }\n getter = Object.getOwnPropertyDescriptor(element, \"ref\")?.get;\n mayWarn = getter && \"isReactWarning\" in getter && getter.isReactWarning;\n if (mayWarn) {\n return element.props.ref;\n }\n return element.props.ref || element.ref;\n}\nvar Root = Presence;\nexport {\n Presence,\n Root\n};\n//# sourceMappingURL=index.mjs.map\n"],"names":["React2","useLayoutEffect"],"mappings":";;;;AASA,SAAS,eAAe,CAAC,YAAY,EAAE,OAAO,EAAE;AACh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M;AACxC;AACA,SAAS,aAAa,CAAC,OAAO,EAAE;AAChC,EAAE,IAAI,MAAM,GAAG,MAAM,CAAC,wBAAwB,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,GAAG;AACzE,EAAE,IAAI,OAAO,GAAG,MAAM,IAAI,gBAAgB,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc;AAC7E,EAAE,IAAI,OAAO,EAAE;AACf,IAAI,OAAO,OAAO,CAAC,GAAG;AACtB,EAAE;AACF,EAAE,MAAM,GAAG,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,GAAG;AAC/D,EAAE,OAAO,GAAG,MAAM,IAAI,gBAAgB,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc;AACzE,EAAE,IAAI,OAAO,EAAE;AACf,IAAI,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG;AAC5B,EAAE;AACF,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG;AACzC;;;;","x_google_ignoreList":[0]}
package/dist/index5.js CHANGED
@@ -1,428 +1,40 @@
1
1
  import * as React from 'react';
2
- import { jsx } from 'react/jsx-runtime';
3
- import { u as useComposedRefs, a as composeRefs } from './index2.js';
4
- import * as ReactDOM from 'react-dom';
5
2
 
6
- // packages/react/context/src/create-context.tsx
7
- function createContextScope(scopeName, createContextScopeDeps = []) {
8
- let defaultContexts = [];
9
- function createContext3(rootComponentName, defaultContext) {
10
- const BaseContext = React.createContext(defaultContext);
11
- const index = defaultContexts.length;
12
- defaultContexts = [...defaultContexts, defaultContext];
13
- const Provider = (props) => {
14
- const { scope, children, ...context } = props;
15
- const Context = scope?.[scopeName]?.[index] || BaseContext;
16
- const value = React.useMemo(() => context, Object.values(context));
17
- return /* @__PURE__ */ jsx(Context.Provider, { value, children });
18
- };
19
- Provider.displayName = rootComponentName + "Provider";
20
- function useContext2(consumerName, scope) {
21
- const Context = scope?.[scopeName]?.[index] || BaseContext;
22
- const context = React.useContext(Context);
23
- if (context) return context;
24
- if (defaultContext !== void 0) return defaultContext;
25
- throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
26
- }
27
- return [Provider, useContext2];
3
+ // packages/react/compose-refs/src/compose-refs.tsx
4
+ function setRef(ref, value) {
5
+ if (typeof ref === "function") {
6
+ return ref(value);
7
+ } else if (ref !== null && ref !== void 0) {
8
+ ref.current = value;
28
9
  }
29
- const createScope = () => {
30
- const scopeContexts = defaultContexts.map((defaultContext) => {
31
- return React.createContext(defaultContext);
32
- });
33
- return function useScope(scope) {
34
- const contexts = scope?.[scopeName] || scopeContexts;
35
- return React.useMemo(
36
- () => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),
37
- [scope, contexts]
38
- );
39
- };
40
- };
41
- createScope.scopeName = scopeName;
42
- return [createContext3, composeContextScopes(createScope, ...createContextScopeDeps)];
43
- }
44
- function composeContextScopes(...scopes) {
45
- const baseScope = scopes[0];
46
- if (scopes.length === 1) return baseScope;
47
- const createScope = () => {
48
- const scopeHooks = scopes.map((createScope2) => ({
49
- useScope: createScope2(),
50
- scopeName: createScope2.scopeName
51
- }));
52
- return function useComposedScopes(overrideScopes) {
53
- const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
54
- const scopeProps = useScope(overrideScopes);
55
- const currentScope = scopeProps[`__scope${scopeName}`];
56
- return { ...nextScopes2, ...currentScope };
57
- }, {});
58
- return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
59
- };
60
- };
61
- createScope.scopeName = baseScope.scopeName;
62
- return createScope;
63
10
  }
64
-
65
- // src/primitive.tsx
66
- function composeEventHandlers(originalEventHandler, ourEventHandler, { checkForDefaultPrevented = true } = {}) {
67
- return function handleEvent(event) {
68
- originalEventHandler?.(event);
69
- if (checkForDefaultPrevented === false || !event.defaultPrevented) {
70
- return ourEventHandler?.(event);
71
- }
72
- };
73
- }
74
-
75
- // packages/react/use-layout-effect/src/use-layout-effect.tsx
76
- var useLayoutEffect2 = globalThis?.document ? React.useLayoutEffect : () => {
77
- };
78
-
79
- // src/use-controllable-state.tsx
80
- var useInsertionEffect = React[" useInsertionEffect ".trim().toString()] || useLayoutEffect2;
81
- function useControllableState({
82
- prop,
83
- defaultProp,
84
- onChange = () => {
85
- },
86
- caller
87
- }) {
88
- const [uncontrolledProp, setUncontrolledProp, onChangeRef] = useUncontrolledState({
89
- defaultProp,
90
- onChange
91
- });
92
- const isControlled = prop !== void 0;
93
- const value = isControlled ? prop : uncontrolledProp;
94
- {
95
- const isControlledRef = React.useRef(prop !== void 0);
96
- React.useEffect(() => {
97
- const wasControlled = isControlledRef.current;
98
- if (wasControlled !== isControlled) {
99
- const from = wasControlled ? "controlled" : "uncontrolled";
100
- const to = isControlled ? "controlled" : "uncontrolled";
101
- console.warn(
102
- `${caller} is changing from ${from} to ${to}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`
103
- );
104
- }
105
- isControlledRef.current = isControlled;
106
- }, [isControlled, caller]);
107
- }
108
- const setValue = React.useCallback(
109
- (nextValue) => {
110
- if (isControlled) {
111
- const value2 = isFunction(nextValue) ? nextValue(prop) : nextValue;
112
- if (value2 !== prop) {
113
- onChangeRef.current?.(value2);
114
- }
115
- } else {
116
- setUncontrolledProp(nextValue);
117
- }
118
- },
119
- [isControlled, prop, setUncontrolledProp, onChangeRef]
120
- );
121
- return [value, setValue];
122
- }
123
- function useUncontrolledState({
124
- defaultProp,
125
- onChange
126
- }) {
127
- const [value, setValue] = React.useState(defaultProp);
128
- const prevValueRef = React.useRef(value);
129
- const onChangeRef = React.useRef(onChange);
130
- useInsertionEffect(() => {
131
- onChangeRef.current = onChange;
132
- }, [onChange]);
133
- React.useEffect(() => {
134
- if (prevValueRef.current !== value) {
135
- onChangeRef.current?.(value);
136
- prevValueRef.current = value;
137
- }
138
- }, [value, prevValueRef]);
139
- return [value, setValue, onChangeRef];
140
- }
141
- function isFunction(value) {
142
- return typeof value === "function";
143
- }
144
-
145
- // packages/react/use-size/src/use-size.tsx
146
- function useSize(element) {
147
- const [size, setSize] = React.useState(void 0);
148
- useLayoutEffect2(() => {
149
- if (element) {
150
- setSize({ width: element.offsetWidth, height: element.offsetHeight });
151
- const resizeObserver = new ResizeObserver((entries) => {
152
- if (!Array.isArray(entries)) {
153
- return;
154
- }
155
- if (!entries.length) {
156
- return;
157
- }
158
- const entry = entries[0];
159
- let width;
160
- let height;
161
- if ("borderBoxSize" in entry) {
162
- const borderSizeEntry = entry["borderBoxSize"];
163
- const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
164
- width = borderSize["inlineSize"];
165
- height = borderSize["blockSize"];
166
- } else {
167
- width = element.offsetWidth;
168
- height = element.offsetHeight;
169
- }
170
- setSize({ width, height });
171
- });
172
- resizeObserver.observe(element, { box: "border-box" });
173
- return () => resizeObserver.unobserve(element);
174
- } else {
175
- setSize(void 0);
176
- }
177
- }, [element]);
178
- return size;
179
- }
180
-
181
- function useStateMachine(initialState, machine) {
182
- return React.useReducer((state, event) => {
183
- const nextState = machine[state][event];
184
- return nextState ?? state;
185
- }, initialState);
186
- }
187
-
188
- // src/presence.tsx
189
- var Presence = (props) => {
190
- const { present, children } = props;
191
- const presence = usePresence(present);
192
- const child = typeof children === "function" ? children({ present: presence.isPresent }) : React.Children.only(children);
193
- const ref = useComposedRefs(presence.ref, getElementRef$1(child));
194
- const forceMount = typeof children === "function";
195
- return forceMount || presence.isPresent ? React.cloneElement(child, { ref }) : null;
196
- };
197
- Presence.displayName = "Presence";
198
- function usePresence(present) {
199
- const [node, setNode] = React.useState();
200
- const stylesRef = React.useRef(null);
201
- const prevPresentRef = React.useRef(present);
202
- const prevAnimationNameRef = React.useRef("none");
203
- const initialState = present ? "mounted" : "unmounted";
204
- const [state, send] = useStateMachine(initialState, {
205
- mounted: {
206
- UNMOUNT: "unmounted",
207
- ANIMATION_OUT: "unmountSuspended"
208
- },
209
- unmountSuspended: {
210
- MOUNT: "mounted",
211
- ANIMATION_END: "unmounted"
212
- },
213
- unmounted: {
214
- MOUNT: "mounted"
215
- }
216
- });
217
- React.useEffect(() => {
218
- const currentAnimationName = getAnimationName(stylesRef.current);
219
- prevAnimationNameRef.current = state === "mounted" ? currentAnimationName : "none";
220
- }, [state]);
221
- useLayoutEffect2(() => {
222
- const styles = stylesRef.current;
223
- const wasPresent = prevPresentRef.current;
224
- const hasPresentChanged = wasPresent !== present;
225
- if (hasPresentChanged) {
226
- const prevAnimationName = prevAnimationNameRef.current;
227
- const currentAnimationName = getAnimationName(styles);
228
- if (present) {
229
- send("MOUNT");
230
- } else if (currentAnimationName === "none" || styles?.display === "none") {
231
- send("UNMOUNT");
232
- } else {
233
- const isAnimating = prevAnimationName !== currentAnimationName;
234
- if (wasPresent && isAnimating) {
235
- send("ANIMATION_OUT");
236
- } else {
237
- send("UNMOUNT");
238
- }
11
+ function composeRefs(...refs) {
12
+ return (node) => {
13
+ let hasCleanup = false;
14
+ const cleanups = refs.map((ref) => {
15
+ const cleanup = setRef(ref, node);
16
+ if (!hasCleanup && typeof cleanup == "function") {
17
+ hasCleanup = true;
239
18
  }
240
- prevPresentRef.current = present;
241
- }
242
- }, [present, send]);
243
- useLayoutEffect2(() => {
244
- if (node) {
245
- let timeoutId;
246
- const ownerWindow = node.ownerDocument.defaultView ?? window;
247
- const handleAnimationEnd = (event) => {
248
- const currentAnimationName = getAnimationName(stylesRef.current);
249
- const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));
250
- if (event.target === node && isCurrentAnimation) {
251
- send("ANIMATION_END");
252
- if (!prevPresentRef.current) {
253
- const currentFillMode = node.style.animationFillMode;
254
- node.style.animationFillMode = "forwards";
255
- timeoutId = ownerWindow.setTimeout(() => {
256
- if (node.style.animationFillMode === "forwards") {
257
- node.style.animationFillMode = currentFillMode;
258
- }
259
- });
19
+ return cleanup;
20
+ });
21
+ if (hasCleanup) {
22
+ return () => {
23
+ for (let i = 0; i < cleanups.length; i++) {
24
+ const cleanup = cleanups[i];
25
+ if (typeof cleanup == "function") {
26
+ cleanup();
27
+ } else {
28
+ setRef(refs[i], null);
260
29
  }
261
30
  }
262
31
  };
263
- const handleAnimationStart = (event) => {
264
- if (event.target === node) {
265
- prevAnimationNameRef.current = getAnimationName(stylesRef.current);
266
- }
267
- };
268
- node.addEventListener("animationstart", handleAnimationStart);
269
- node.addEventListener("animationcancel", handleAnimationEnd);
270
- node.addEventListener("animationend", handleAnimationEnd);
271
- return () => {
272
- ownerWindow.clearTimeout(timeoutId);
273
- node.removeEventListener("animationstart", handleAnimationStart);
274
- node.removeEventListener("animationcancel", handleAnimationEnd);
275
- node.removeEventListener("animationend", handleAnimationEnd);
276
- };
277
- } else {
278
- send("ANIMATION_END");
279
32
  }
280
- }, [node, send]);
281
- return {
282
- isPresent: ["mounted", "unmountSuspended"].includes(state),
283
- ref: React.useCallback((node2) => {
284
- stylesRef.current = node2 ? getComputedStyle(node2) : null;
285
- setNode(node2);
286
- }, [])
287
33
  };
288
34
  }
289
- function getAnimationName(styles) {
290
- return styles?.animationName || "none";
291
- }
292
- function getElementRef$1(element) {
293
- let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
294
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
295
- if (mayWarn) {
296
- return element.ref;
297
- }
298
- getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
299
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
300
- if (mayWarn) {
301
- return element.props.ref;
302
- }
303
- return element.props.ref || element.ref;
304
- }
305
-
306
- // src/slot.tsx
307
- // @__NO_SIDE_EFFECTS__
308
- function createSlot(ownerName) {
309
- const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
310
- const Slot2 = React.forwardRef((props, forwardedRef) => {
311
- const { children, ...slotProps } = props;
312
- const childrenArray = React.Children.toArray(children);
313
- const slottable = childrenArray.find(isSlottable);
314
- if (slottable) {
315
- const newElement = slottable.props.children;
316
- const newChildren = childrenArray.map((child) => {
317
- if (child === slottable) {
318
- if (React.Children.count(newElement) > 1) return React.Children.only(null);
319
- return React.isValidElement(newElement) ? newElement.props.children : null;
320
- } else {
321
- return child;
322
- }
323
- });
324
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
325
- }
326
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
327
- });
328
- Slot2.displayName = `${ownerName}.Slot`;
329
- return Slot2;
330
- }
331
- // @__NO_SIDE_EFFECTS__
332
- function createSlotClone(ownerName) {
333
- const SlotClone = React.forwardRef((props, forwardedRef) => {
334
- const { children, ...slotProps } = props;
335
- if (React.isValidElement(children)) {
336
- const childrenRef = getElementRef(children);
337
- const props2 = mergeProps(slotProps, children.props);
338
- if (children.type !== React.Fragment) {
339
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
340
- }
341
- return React.cloneElement(children, props2);
342
- }
343
- return React.Children.count(children) > 1 ? React.Children.only(null) : null;
344
- });
345
- SlotClone.displayName = `${ownerName}.SlotClone`;
346
- return SlotClone;
347
- }
348
- var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
349
- function isSlottable(child) {
350
- return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
351
- }
352
- function mergeProps(slotProps, childProps) {
353
- const overrideProps = { ...childProps };
354
- for (const propName in childProps) {
355
- const slotPropValue = slotProps[propName];
356
- const childPropValue = childProps[propName];
357
- const isHandler = /^on[A-Z]/.test(propName);
358
- if (isHandler) {
359
- if (slotPropValue && childPropValue) {
360
- overrideProps[propName] = (...args) => {
361
- const result = childPropValue(...args);
362
- slotPropValue(...args);
363
- return result;
364
- };
365
- } else if (slotPropValue) {
366
- overrideProps[propName] = slotPropValue;
367
- }
368
- } else if (propName === "style") {
369
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
370
- } else if (propName === "className") {
371
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
372
- }
373
- }
374
- return { ...slotProps, ...overrideProps };
375
- }
376
- function getElementRef(element) {
377
- let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
378
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
379
- if (mayWarn) {
380
- return element.ref;
381
- }
382
- getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
383
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
384
- if (mayWarn) {
385
- return element.props.ref;
386
- }
387
- return element.props.ref || element.ref;
388
- }
389
-
390
- // src/primitive.tsx
391
- var NODES = [
392
- "a",
393
- "button",
394
- "div",
395
- "form",
396
- "h2",
397
- "h3",
398
- "img",
399
- "input",
400
- "label",
401
- "li",
402
- "nav",
403
- "ol",
404
- "p",
405
- "select",
406
- "span",
407
- "svg",
408
- "ul"
409
- ];
410
- var Primitive = NODES.reduce((primitive, node) => {
411
- const Slot = createSlot(`Primitive.${node}`);
412
- const Node = React.forwardRef((props, forwardedRef) => {
413
- const { asChild, ...primitiveProps } = props;
414
- const Comp = asChild ? Slot : node;
415
- if (typeof window !== "undefined") {
416
- window[Symbol.for("radix-ui")] = true;
417
- }
418
- return /* @__PURE__ */ jsx(Comp, { ...primitiveProps, ref: forwardedRef });
419
- });
420
- Node.displayName = `Primitive.${node}`;
421
- return { ...primitive, [node]: Node };
422
- }, {});
423
- function dispatchDiscreteCustomEvent(target, event) {
424
- if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
35
+ function useComposedRefs(...refs) {
36
+ return React.useCallback(composeRefs(...refs), refs);
425
37
  }
426
38
 
427
- export { Presence as P, Primitive as a, composeEventHandlers as b, createContextScope as c, useSize as d, dispatchDiscreteCustomEvent as e, useLayoutEffect2 as f, createSlot as g, useControllableState as u };
39
+ export { composeRefs as c, useComposedRefs as u };
428
40
  //# sourceMappingURL=index5.js.map