@yamada-ui/react 2.0.10-dev-20260221082120 → 2.0.10-dev-20260226033228

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 (332) hide show
  1. package/dist/cjs/components/accordion/use-accordion.cjs.map +1 -1
  2. package/dist/cjs/components/airy/airy.cjs.map +1 -1
  3. package/dist/cjs/components/autocomplete/use-autocomplete.cjs.map +1 -1
  4. package/dist/cjs/components/avatar/use-avatar.cjs.map +1 -1
  5. package/dist/cjs/components/button/button.cjs.map +1 -1
  6. package/dist/cjs/components/calendar/use-calendar.cjs.map +1 -1
  7. package/dist/cjs/components/checkbox/use-checkbox.cjs.map +1 -1
  8. package/dist/cjs/components/color-picker/use-color-picker.cjs.map +1 -1
  9. package/dist/cjs/components/date-picker/use-date-picker.cjs.map +1 -1
  10. package/dist/cjs/components/dropzone/use-dropzone.cjs.map +1 -1
  11. package/dist/cjs/components/field/field.cjs.map +1 -1
  12. package/dist/cjs/components/file-input/file-input.cjs.map +1 -1
  13. package/dist/cjs/components/flip/flip.cjs.map +1 -1
  14. package/dist/cjs/components/for/for.cjs.map +1 -1
  15. package/dist/cjs/components/highlight/highlight.cjs.map +1 -1
  16. package/dist/cjs/components/infinite-scroll-area/use-infinite-scroll.cjs.map +1 -1
  17. package/dist/cjs/components/loading/loading-provider.cjs.map +1 -1
  18. package/dist/cjs/components/menu/use-menu.cjs.map +1 -1
  19. package/dist/cjs/components/notice/use-notice.cjs.map +1 -1
  20. package/dist/cjs/components/pagination/use-pagination.cjs.map +1 -1
  21. package/dist/cjs/components/password-input/use-strength-meter.cjs.map +1 -1
  22. package/dist/cjs/components/picture/picture.cjs.map +1 -1
  23. package/dist/cjs/components/pin-input/use-pin-input.cjs.map +1 -1
  24. package/dist/cjs/components/radio/use-radio.cjs.map +1 -1
  25. package/dist/cjs/components/rating/use-rating.cjs.map +1 -1
  26. package/dist/cjs/components/resizable/use-resizable.cjs.map +1 -1
  27. package/dist/cjs/components/ripple/ripple.cjs.map +1 -1
  28. package/dist/cjs/components/rotate/rotate.cjs.map +1 -1
  29. package/dist/cjs/components/saturation-slider/use-saturation-slider.cjs.map +1 -1
  30. package/dist/cjs/components/scroll-area/use-scroll-area.cjs.map +1 -1
  31. package/dist/cjs/components/segmented-control/use-segmented-control.cjs.map +1 -1
  32. package/dist/cjs/components/select/use-select.cjs.map +1 -1
  33. package/dist/cjs/components/slider/slider.cjs.map +1 -1
  34. package/dist/cjs/components/slider/use-slider.cjs.map +1 -1
  35. package/dist/cjs/components/snacks/snacks.cjs.map +1 -1
  36. package/dist/cjs/components/switch/use-switch.cjs.map +1 -1
  37. package/dist/cjs/components/table/table.cjs.map +1 -1
  38. package/dist/cjs/components/textarea/use-autosize.cjs.map +1 -1
  39. package/dist/cjs/components/toggle/use-toggle-group.cjs.map +1 -1
  40. package/dist/cjs/core/components/use-component-style.cjs.map +1 -1
  41. package/dist/cjs/core/css/styles.cjs.map +1 -1
  42. package/dist/cjs/core/css/utils.cjs.map +1 -1
  43. package/dist/cjs/core/system/breakpoint.cjs.map +1 -1
  44. package/dist/cjs/core/system/color-mode-provider.cjs.map +1 -1
  45. package/dist/cjs/core/system/layer.cjs.map +1 -1
  46. package/dist/cjs/core/system/storage-script.cjs.map +1 -1
  47. package/dist/cjs/core/system/styled.cjs.map +1 -1
  48. package/dist/cjs/core/system/use-system-color-mode.cjs.map +1 -1
  49. package/dist/cjs/hooks/use-async/index.cjs.map +1 -1
  50. package/dist/cjs/hooks/use-boolean/index.cjs.map +1 -1
  51. package/dist/cjs/hooks/use-clickable/index.cjs.map +1 -1
  52. package/dist/cjs/hooks/use-combobox/index.cjs.map +1 -1
  53. package/dist/cjs/hooks/use-controllable-state/index.cjs.map +1 -1
  54. package/dist/cjs/hooks/use-local-storage/index.cjs.map +1 -1
  55. package/dist/cjs/providers/i18n-provider/i18n-provider.cjs.map +1 -1
  56. package/dist/cjs/utils/context.cjs.map +1 -1
  57. package/dist/cjs/utils/store.cjs.map +1 -1
  58. package/dist/esm/components/accordion/use-accordion.js.map +1 -1
  59. package/dist/esm/components/airy/airy.js.map +1 -1
  60. package/dist/esm/components/autocomplete/use-autocomplete.js.map +1 -1
  61. package/dist/esm/components/avatar/use-avatar.js.map +1 -1
  62. package/dist/esm/components/button/button.js.map +1 -1
  63. package/dist/esm/components/calendar/use-calendar.js.map +1 -1
  64. package/dist/esm/components/checkbox/use-checkbox.js.map +1 -1
  65. package/dist/esm/components/color-picker/use-color-picker.js.map +1 -1
  66. package/dist/esm/components/date-picker/use-date-picker.js.map +1 -1
  67. package/dist/esm/components/dropzone/use-dropzone.js.map +1 -1
  68. package/dist/esm/components/field/field.js.map +1 -1
  69. package/dist/esm/components/file-input/file-input.js.map +1 -1
  70. package/dist/esm/components/flip/flip.js.map +1 -1
  71. package/dist/esm/components/for/for.js.map +1 -1
  72. package/dist/esm/components/highlight/highlight.js.map +1 -1
  73. package/dist/esm/components/infinite-scroll-area/use-infinite-scroll.js.map +1 -1
  74. package/dist/esm/components/loading/loading-provider.js.map +1 -1
  75. package/dist/esm/components/menu/use-menu.js.map +1 -1
  76. package/dist/esm/components/notice/use-notice.js.map +1 -1
  77. package/dist/esm/components/pagination/use-pagination.js.map +1 -1
  78. package/dist/esm/components/password-input/use-strength-meter.js.map +1 -1
  79. package/dist/esm/components/picture/picture.js.map +1 -1
  80. package/dist/esm/components/pin-input/use-pin-input.js.map +1 -1
  81. package/dist/esm/components/radio/use-radio.js.map +1 -1
  82. package/dist/esm/components/rating/use-rating.js.map +1 -1
  83. package/dist/esm/components/resizable/use-resizable.js.map +1 -1
  84. package/dist/esm/components/ripple/ripple.js.map +1 -1
  85. package/dist/esm/components/rotate/rotate.js.map +1 -1
  86. package/dist/esm/components/saturation-slider/use-saturation-slider.js.map +1 -1
  87. package/dist/esm/components/scroll-area/use-scroll-area.js.map +1 -1
  88. package/dist/esm/components/segmented-control/use-segmented-control.js.map +1 -1
  89. package/dist/esm/components/select/use-select.js.map +1 -1
  90. package/dist/esm/components/slider/slider.js.map +1 -1
  91. package/dist/esm/components/slider/use-slider.js.map +1 -1
  92. package/dist/esm/components/snacks/snacks.js.map +1 -1
  93. package/dist/esm/components/switch/use-switch.js.map +1 -1
  94. package/dist/esm/components/table/table.js.map +1 -1
  95. package/dist/esm/components/textarea/use-autosize.js.map +1 -1
  96. package/dist/esm/components/toggle/use-toggle-group.js.map +1 -1
  97. package/dist/esm/core/components/use-component-style.js.map +1 -1
  98. package/dist/esm/core/css/styles.js.map +1 -1
  99. package/dist/esm/core/css/utils.js.map +1 -1
  100. package/dist/esm/core/system/breakpoint.js.map +1 -1
  101. package/dist/esm/core/system/color-mode-provider.js.map +1 -1
  102. package/dist/esm/core/system/layer.js.map +1 -1
  103. package/dist/esm/core/system/storage-script.js.map +1 -1
  104. package/dist/esm/core/system/styled.js.map +1 -1
  105. package/dist/esm/core/system/use-system-color-mode.js.map +1 -1
  106. package/dist/esm/hooks/use-async/index.js.map +1 -1
  107. package/dist/esm/hooks/use-boolean/index.js.map +1 -1
  108. package/dist/esm/hooks/use-clickable/index.js.map +1 -1
  109. package/dist/esm/hooks/use-combobox/index.js.map +1 -1
  110. package/dist/esm/hooks/use-controllable-state/index.js.map +1 -1
  111. package/dist/esm/hooks/use-local-storage/index.js.map +1 -1
  112. package/dist/esm/providers/i18n-provider/i18n-provider.js.map +1 -1
  113. package/dist/esm/utils/context.js.map +1 -1
  114. package/dist/esm/utils/store.js.map +1 -1
  115. package/dist/types/components/accordion/accordion.d.ts +2 -2
  116. package/dist/types/components/accordion/accordion.style.d.ts +1 -1
  117. package/dist/types/components/accordion/use-accordion.d.ts +15 -15
  118. package/dist/types/components/airy/airy.d.ts +10 -10
  119. package/dist/types/components/alert/alert.d.ts +2 -2
  120. package/dist/types/components/alert/alert.style.d.ts +1 -1
  121. package/dist/types/components/alpha-slider/alpha-slider.d.ts +2 -2
  122. package/dist/types/components/aspect-ratio/aspect-ratio.d.ts +2 -2
  123. package/dist/types/components/autocomplete/autocomplete.d.ts +2 -2
  124. package/dist/types/components/autocomplete/autocomplete.style.d.ts +1 -1
  125. package/dist/types/components/autocomplete/use-autocomplete.d.ts +18 -18
  126. package/dist/types/components/avatar/avatar.d.ts +5 -5
  127. package/dist/types/components/avatar/use-avatar-group.d.ts +2 -2
  128. package/dist/types/components/avatar/use-avatar.d.ts +19 -19
  129. package/dist/types/components/badge/badge.d.ts +2 -2
  130. package/dist/types/components/bleed/bleed.d.ts +2 -2
  131. package/dist/types/components/blockquote/blockquote.d.ts +2 -2
  132. package/dist/types/components/breadcrumb/breadcrumb.d.ts +2 -2
  133. package/dist/types/components/breadcrumb/breadcrumb.style.d.ts +1 -1
  134. package/dist/types/components/breadcrumb/use-breadcrumb.d.ts +2 -2
  135. package/dist/types/components/button/button.d.ts +8 -8
  136. package/dist/types/components/button/icon-button.d.ts +2 -2
  137. package/dist/types/components/calendar/calendar.d.ts +2 -2
  138. package/dist/types/components/calendar/calendar.style.d.ts +2 -2
  139. package/dist/types/components/calendar/use-calendar.d.ts +12 -12
  140. package/dist/types/components/card/card.d.ts +2 -2
  141. package/dist/types/components/carousel/carousel.d.ts +2 -2
  142. package/dist/types/components/carousel/carousel.style.d.ts +2 -2
  143. package/dist/types/components/carousel/use-carousel.d.ts +3 -3
  144. package/dist/types/components/center/center.d.ts +2 -2
  145. package/dist/types/components/checkbox/checkbox.d.ts +5 -5
  146. package/dist/types/components/checkbox/checkbox.style.d.ts +1 -1
  147. package/dist/types/components/checkbox/use-checkbox-group.d.ts +2 -2
  148. package/dist/types/components/checkbox/use-checkbox.d.ts +8 -8
  149. package/dist/types/components/checkbox-card/checkbox-card.d.ts +5 -5
  150. package/dist/types/components/checkbox-card/checkbox-card.style.d.ts +1 -1
  151. package/dist/types/components/circle-progress/circle-progress.d.ts +2 -2
  152. package/dist/types/components/close-button/close-button.d.ts +2 -2
  153. package/dist/types/components/code/code.d.ts +2 -2
  154. package/dist/types/components/collapse/collapse.d.ts +2 -2
  155. package/dist/types/components/color-picker/color-picker.d.ts +2 -2
  156. package/dist/types/components/color-picker/use-color-picker.d.ts +12 -12
  157. package/dist/types/components/color-selector/color-selector.d.ts +2 -2
  158. package/dist/types/components/color-selector/use-color-selector.d.ts +3 -3
  159. package/dist/types/components/color-swatch/color-swatch.d.ts +2 -2
  160. package/dist/types/components/container/container.d.ts +2 -2
  161. package/dist/types/components/data-list/data-list.d.ts +2 -2
  162. package/dist/types/components/data-list/data-list.style.d.ts +1 -1
  163. package/dist/types/components/date-picker/date-picker.d.ts +2 -2
  164. package/dist/types/components/date-picker/use-date-picker.d.ts +21 -21
  165. package/dist/types/components/drawer/drawer.d.ts +2 -2
  166. package/dist/types/components/dropzone/dropzone.d.ts +5 -5
  167. package/dist/types/components/dropzone/dropzone.style.d.ts +1 -1
  168. package/dist/types/components/dropzone/use-dropzone.d.ts +4 -4
  169. package/dist/types/components/editable/editable.d.ts +4 -4
  170. package/dist/types/components/editable/use-editable.d.ts +2 -2
  171. package/dist/types/components/em/em.d.ts +2 -2
  172. package/dist/types/components/empty-state/empty-state.d.ts +2 -2
  173. package/dist/types/components/empty-state/empty-state.style.d.ts +2 -2
  174. package/dist/types/components/fade/fade.d.ts +2 -2
  175. package/dist/types/components/field/field.d.ts +4 -4
  176. package/dist/types/components/field/use-field-props.d.ts +4 -4
  177. package/dist/types/components/fieldset/fieldset.d.ts +3 -3
  178. package/dist/types/components/file-button/file-button.d.ts +2 -2
  179. package/dist/types/components/file-button/use-file-button.d.ts +17 -17
  180. package/dist/types/components/file-input/file-input.d.ts +8 -8
  181. package/dist/types/components/file-input/use-file-input.d.ts +17 -17
  182. package/dist/types/components/flex/flex.d.ts +2 -2
  183. package/dist/types/components/flip/flip.d.ts +12 -12
  184. package/dist/types/components/flip/flip.style.d.ts +1 -1
  185. package/dist/types/components/float/float.d.ts +2 -2
  186. package/dist/types/components/for/for.d.ts +8 -8
  187. package/dist/types/components/format/format-byte.d.ts +4 -4
  188. package/dist/types/components/format/format-date-time.d.ts +4 -4
  189. package/dist/types/components/format/format-number.d.ts +2 -2
  190. package/dist/types/components/grid/grid-item.d.ts +2 -2
  191. package/dist/types/components/grid/grid.d.ts +2 -2
  192. package/dist/types/components/group/group.d.ts +2 -2
  193. package/dist/types/components/group/use-group.d.ts +2 -2
  194. package/dist/types/components/heading/heading.d.ts +2 -2
  195. package/dist/types/components/highlight/highlight.d.ts +4 -4
  196. package/dist/types/components/hue-slider/hue-slider.d.ts +3 -3
  197. package/dist/types/components/icon/icon.d.ts +5 -5
  198. package/dist/types/components/image/image.d.ts +2 -2
  199. package/dist/types/components/indicator/indicator.d.ts +4 -4
  200. package/dist/types/components/infinite-scroll-area/infinite-scroll-area.d.ts +2 -2
  201. package/dist/types/components/infinite-scroll-area/use-infinite-scroll.d.ts +2 -2
  202. package/dist/types/components/input/input-addon.d.ts +2 -2
  203. package/dist/types/components/input/input-element.d.ts +2 -2
  204. package/dist/types/components/input/input.d.ts +2 -2
  205. package/dist/types/components/kbd/kbd.d.ts +2 -2
  206. package/dist/types/components/link/link.d.ts +2 -2
  207. package/dist/types/components/link-box/link-box.d.ts +2 -2
  208. package/dist/types/components/list/list.d.ts +2 -2
  209. package/dist/types/components/list/list.style.d.ts +2 -2
  210. package/dist/types/components/loading/loading-provider.d.ts +3 -3
  211. package/dist/types/components/loading/loading.d.ts +3 -3
  212. package/dist/types/components/mark/mark.d.ts +2 -2
  213. package/dist/types/components/menu/menu.d.ts +2 -2
  214. package/dist/types/components/menu/use-menu.d.ts +17 -17
  215. package/dist/types/components/modal/modal.d.ts +2 -2
  216. package/dist/types/components/native-select/native-select.d.ts +2 -2
  217. package/dist/types/components/native-table/native-table.d.ts +4 -4
  218. package/dist/types/components/notice/notice.style.d.ts +1 -1
  219. package/dist/types/components/notice/use-notice.d.ts +4 -4
  220. package/dist/types/components/number-input/number-input.d.ts +2 -2
  221. package/dist/types/components/number-input/number-input.style.d.ts +1 -1
  222. package/dist/types/components/pagination/pagination.d.ts +2 -2
  223. package/dist/types/components/pagination/pagination.style.d.ts +1 -1
  224. package/dist/types/components/pagination/use-pagination.d.ts +6 -6
  225. package/dist/types/components/password-input/password-input.d.ts +2 -2
  226. package/dist/types/components/password-input/strength-meter.d.ts +2 -2
  227. package/dist/types/components/password-input/strength-meter.style.d.ts +1 -1
  228. package/dist/types/components/password-input/use-password-input.d.ts +2 -2
  229. package/dist/types/components/password-input/use-strength-meter.d.ts +4 -4
  230. package/dist/types/components/picture/picture.d.ts +4 -4
  231. package/dist/types/components/pin-input/pin-input.d.ts +2 -2
  232. package/dist/types/components/pin-input/use-pin-input.d.ts +18 -18
  233. package/dist/types/components/popover/popover.d.ts +2 -2
  234. package/dist/types/components/progress/progress.d.ts +4 -4
  235. package/dist/types/components/progress/use-progress.d.ts +706 -706
  236. package/dist/types/components/radio/radio.d.ts +5 -5
  237. package/dist/types/components/radio/radio.style.d.ts +1 -1
  238. package/dist/types/components/radio/use-radio-group.d.ts +2 -2
  239. package/dist/types/components/radio/use-radio.d.ts +8 -8
  240. package/dist/types/components/radio-card/radio-card.d.ts +5 -5
  241. package/dist/types/components/radio-card/radio-card.style.d.ts +1 -1
  242. package/dist/types/components/rating/rating.style.d.ts +2 -2
  243. package/dist/types/components/rating/use-rating.d.ts +16 -16
  244. package/dist/types/components/reorder/reorder.d.ts +2 -2
  245. package/dist/types/components/reorder/reorder.style.d.ts +1 -1
  246. package/dist/types/components/reorder/use-reorder.d.ts +3 -3
  247. package/dist/types/components/resizable/resizable.d.ts +2 -2
  248. package/dist/types/components/resizable/resizable.style.d.ts +2 -2
  249. package/dist/types/components/resizable/use-resizable.d.ts +8 -8
  250. package/dist/types/components/ripple/ripple.d.ts +8 -8
  251. package/dist/types/components/ripple/use-ripple.d.ts +2 -2
  252. package/dist/types/components/rotate/rotate.d.ts +10 -10
  253. package/dist/types/components/saturation-slider/saturation-slider.d.ts +2 -2
  254. package/dist/types/components/saturation-slider/use-saturation-slider.d.ts +15 -15
  255. package/dist/types/components/scroll-area/scroll-area.d.ts +2 -2
  256. package/dist/types/components/scroll-area/use-scroll-area.d.ts +6 -6
  257. package/dist/types/components/segmented-control/segmented-control.d.ts +2 -2
  258. package/dist/types/components/segmented-control/segmented-control.style.d.ts +2 -2
  259. package/dist/types/components/segmented-control/use-segmented-control.d.ts +13 -13
  260. package/dist/types/components/select/select.d.ts +2 -2
  261. package/dist/types/components/select/select.style.d.ts +1 -1
  262. package/dist/types/components/select/use-select.d.ts +16 -16
  263. package/dist/types/components/separator/separator.d.ts +2 -2
  264. package/dist/types/components/simple-grid/simple-grid.d.ts +2 -2
  265. package/dist/types/components/skeleton/skeleton.d.ts +2 -2
  266. package/dist/types/components/slide/slide.d.ts +2 -2
  267. package/dist/types/components/slide-fade/slide-fade.d.ts +2 -2
  268. package/dist/types/components/slider/slider.d.ts +7 -7
  269. package/dist/types/components/slider/use-slider.d.ts +16 -16
  270. package/dist/types/components/snacks/snacks.d.ts +4 -4
  271. package/dist/types/components/stack/h-stack.d.ts +2 -2
  272. package/dist/types/components/stack/stack.d.ts +2 -2
  273. package/dist/types/components/stack/v-stack.d.ts +2 -2
  274. package/dist/types/components/stack/z-stack.d.ts +2 -2
  275. package/dist/types/components/stat/stat.d.ts +2 -2
  276. package/dist/types/components/status/status.d.ts +2 -2
  277. package/dist/types/components/status/status.style.d.ts +2 -2
  278. package/dist/types/components/steps/steps.d.ts +2 -2
  279. package/dist/types/components/steps/steps.style.d.ts +1 -1
  280. package/dist/types/components/steps/use-steps.d.ts +10 -10
  281. package/dist/types/components/switch/switch.d.ts +2 -2
  282. package/dist/types/components/switch/use-switch.d.ts +8 -8
  283. package/dist/types/components/table/table.d.ts +3 -3
  284. package/dist/types/components/tabs/tabs.d.ts +2 -2
  285. package/dist/types/components/tabs/tabs.style.d.ts +1 -1
  286. package/dist/types/components/tabs/use-tabs.d.ts +16 -16
  287. package/dist/types/components/tag/tag.d.ts +2 -2
  288. package/dist/types/components/text/text.d.ts +2 -2
  289. package/dist/types/components/textarea/textarea.d.ts +2 -2
  290. package/dist/types/components/textarea/use-autosize.d.ts +2 -2
  291. package/dist/types/components/timeline/timeline.d.ts +5 -5
  292. package/dist/types/components/timeline/timeline.style.d.ts +2 -2
  293. package/dist/types/components/toggle/toggle.d.ts +5 -5
  294. package/dist/types/components/toggle/use-toggle-group.d.ts +3 -3
  295. package/dist/types/components/toggle/use-toggle.d.ts +2 -2
  296. package/dist/types/components/tooltip/tooltip.d.ts +2 -2
  297. package/dist/types/components/visually-hidden/visually-hidden.d.ts +2 -2
  298. package/dist/types/components/wrap/wrap.d.ts +2 -2
  299. package/dist/types/core/components/create-component.d.ts +7 -7
  300. package/dist/types/core/components/use-component-style.d.ts +1 -1
  301. package/dist/types/core/css/index.types.d.ts +1 -1
  302. package/dist/types/core/css/styles.d.ts +219 -219
  303. package/dist/types/core/css/utils.d.ts +1 -1
  304. package/dist/types/core/generated-theme-tokens.types.d.ts +1 -1
  305. package/dist/types/core/system/breakpoint.d.ts +3 -3
  306. package/dist/types/core/system/color-mode-provider.d.ts +4 -4
  307. package/dist/types/core/system/index.types.d.ts +6 -6
  308. package/dist/types/core/system/layer.d.ts +1 -1
  309. package/dist/types/core/system/storage-script.d.ts +5 -5
  310. package/dist/types/core/system/styled.d.ts +4 -4
  311. package/dist/types/core/system/system-provider.d.ts +2 -2
  312. package/dist/types/core/system/use-system-color-mode.d.ts +1 -1
  313. package/dist/types/hooks/use-async/index.d.ts +13 -13
  314. package/dist/types/hooks/use-boolean/index.d.ts +1 -1
  315. package/dist/types/hooks/use-breakpoint/use-breakpoint-state.d.ts +2 -2
  316. package/dist/types/hooks/use-clickable/index.d.ts +6 -6
  317. package/dist/types/hooks/use-clipboard/index.d.ts +2 -2
  318. package/dist/types/hooks/use-combobox/index.d.ts +13 -13
  319. package/dist/types/hooks/use-controllable-state/index.d.ts +2 -2
  320. package/dist/types/hooks/use-counter/index.d.ts +2 -2
  321. package/dist/types/hooks/use-descendants/index.d.ts +2 -2
  322. package/dist/types/hooks/use-field-sizing/index.d.ts +2 -2
  323. package/dist/types/hooks/use-hover/index.d.ts +2 -2
  324. package/dist/types/hooks/use-local-storage/index.d.ts +1 -1
  325. package/dist/types/hooks/use-popper/index.d.ts +2 -2
  326. package/dist/types/hooks/use-resize-observer/index.d.ts +3 -3
  327. package/dist/types/providers/i18n-provider/i18n-provider.d.ts +4 -4
  328. package/dist/types/providers/ui-provider/ui-provider.d.ts +2 -2
  329. package/dist/types/utils/children.d.ts +2 -2
  330. package/dist/types/utils/context.d.ts +3 -3
  331. package/dist/types/utils/store.d.ts +2 -2
  332. package/package.json +3 -2
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","names":["value","isColorScheme","getColorSchemeVar"],"sources":["../../../../src/core/css/utils.ts"],"sourcesContent":["import type { Dict } from \"../../utils\"\nimport type { ColorMode, System, ThemeToken, UsageTheme } from \"../system\"\nimport type { StyleConfig } from \"./config\"\nimport type { CSSFunction } from \"./css\"\nimport type { CSSProperties } from \"./index.types\"\nimport { isObject, isString, isUndefined } from \"../../utils\"\nimport { getColorSchemeVar, isColorScheme } from \"../system\"\n\nexport interface TransformOptions {\n css?: CSSFunction\n fallback?: any\n prev?: Dict\n properties?: CSSProperties[]\n system: System\n theme?: UsageTheme\n}\n\nexport interface Transform {\n (value: any, options: TransformOptions): any\n}\n\nexport const globalValues = new Set([\n \"inherit\",\n \"initial\",\n \"none\",\n \"revert\",\n \"unset\",\n])\n\nexport function isCSSFunction(value: any) {\n return isString(value) && value.includes(\"(\") && value.includes(\")\")\n}\n\nexport function getCSSFunction(value: any) {\n const regex = /(^[a-z-A-Z]+)\\((.*)\\)/g\n const [, type, values] = regex.exec(value) ?? []\n\n return { type, values }\n}\n\nexport function splitValues(\n values: string,\n cb: (\n current: string,\n prev: string | undefined,\n next: string | undefined,\n ) => boolean = (current) => current === \",\",\n addSeparator = false,\n) {\n const result = []\n\n let value = \"\"\n let depth = 0\n\n for (let i = 0; i < values.length; i++) {\n const current = values[i]\n const prev = values[i - 1]\n const next = values[i + 1]\n\n if (current === \"(\") depth++\n if (current === \")\") depth--\n\n if (!isUndefined(current) && cb(current, prev, next) && depth === 0) {\n if (value) result.push(value.trim())\n\n if (addSeparator) result.push(current)\n\n value = \"\"\n } else {\n value += current\n }\n }\n\n if (value) result.push(value.trim())\n\n return result.filter(Boolean)\n}\n\nexport function isCSSVar(value: string) {\n return /^var\\(--.+\\)$/.test(value)\n}\n\nexport function isCSSToken({ cssMap }: System) {\n return function (value: any) {\n return isObject(cssMap) && value in cssMap && !!cssMap[value]?.ref\n }\n}\n\nexport function isImportant(value: any): boolean {\n return (\n isString(value) && (/\\s*!important$/.test(value) || /\\s*!$/.test(value))\n )\n}\n\nexport function omitImportant(value: any): string {\n return isString(value) ? value.replace(/(!important|!)$/, \"\").trim() : value\n}\n\nexport function insertImportant(value: any, style?: StyleConfig): any {\n if (isString(value)) {\n return value + \" !important\"\n } else if (isObject(value)) {\n if (style?.important) {\n return Object.fromEntries(\n Object.entries(value).map(([key, value]) => [\n key,\n value + \" !important\",\n ]),\n )\n } else {\n if (!style?.properties) return value\n\n for (const property of style.properties) {\n value[property] += \" !important\"\n }\n }\n }\n\n return value\n}\n\nexport function analyzeCSSValue(value: any) {\n let n = parseFloat(value.toString())\n const unit = value.toString().replace(String(n), \"\")\n\n return { unit, unitless: !unit, value }\n}\n\nexport function tokenToVar(system: System) {\n return function (token: ThemeToken, value: any, fallbackValue?: any) {\n if (isColorScheme(value)) return getColorSchemeVar(system)(value)\n\n const resolvedToken = `${token}.${value}`\n\n if (isCSSToken(system)(resolvedToken)) {\n return system.cssMap[resolvedToken]!.ref\n } else {\n return fallbackValue || value\n }\n }\n}\n\nexport function varToValue(system: System) {\n return function (variable: string): string {\n const value = system.cssVars[variable]\n\n if (isCSSVar(value)) {\n return varToValue(system)(value.replace(/^var\\(/, \"\").replace(/\\)$/, \"\"))\n } else {\n return value\n }\n }\n}\n\nexport function tokenToValue(system: System) {\n return function (token: ThemeToken, value: any, fallbackValue?: any) {\n const resolvedToken = `${token}.${value}`\n\n if (isCSSToken(system)(resolvedToken)) {\n const variable = system.cssMap[resolvedToken]!.var\n\n return varToValue(system)(variable)\n } else {\n return fallbackValue || value\n }\n }\n}\n\nexport function mode<L, D>(light: L, dark: D) {\n return function (colorMode: ColorMode | undefined = \"light\"): D | L {\n return colorMode === \"light\" ? light : dark\n }\n}\n\nfunction combineFunctions(a: Transform, b: Transform): Transform {\n return function (value, ...args) {\n return b(a(value, ...args), ...args)\n }\n}\n\nexport function pipe(...transformers: Transform[]) {\n return transformers.reduce(combineFunctions)\n}\n"],"mappings":";;;;;AAqBA,MAAa,eAAe,IAAI,IAAI;CAClC;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAgB,cAAc,OAAY;AACxC,wDAAgB,MAAM,IAAI,MAAM,SAAS,IAAI,IAAI,MAAM,SAAS,IAAI;;AAGtE,SAAgB,eAAe,OAAY;CAEzC,MAAM,GAAG,MAAM,UADD,yBACiB,KAAK,MAAM,IAAI,EAAE;AAEhD,QAAO;EAAE;EAAM;EAAQ;;AAGzB,SAAgB,YACd,QACA,MAIgB,YAAY,YAAY,KACxC,eAAe,OACf;CACA,MAAM,SAAS,EAAE;CAEjB,IAAI,QAAQ;CACZ,IAAI,QAAQ;AAEZ,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,MAAM,UAAU,OAAO;EACvB,MAAM,OAAO,OAAO,IAAI;EACxB,MAAM,OAAO,OAAO,IAAI;AAExB,MAAI,YAAY,IAAK;AACrB,MAAI,YAAY,IAAK;AAErB,MAAI,oDAAa,QAAQ,IAAI,GAAG,SAAS,MAAM,KAAK,IAAI,UAAU,GAAG;AACnE,OAAI,MAAO,QAAO,KAAK,MAAM,MAAM,CAAC;AAEpC,OAAI,aAAc,QAAO,KAAK,QAAQ;AAEtC,WAAQ;QAER,UAAS;;AAIb,KAAI,MAAO,QAAO,KAAK,MAAM,MAAM,CAAC;AAEpC,QAAO,OAAO,OAAO,QAAQ;;AAG/B,SAAgB,SAA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MAAI,SAAS,MAAM,CACjB,QAAO,WAAW,OAAO,CAAC,MAAM,QAAQ,UAAU,GAAG,CAAC,QAAQ,OAAO,GAAG,CAAC;MAEzE,QAAO;;;AAKb,SAAgB,aAAa,QAAgB;AAC3C,QAAO,SAAU,OAAmB,OAAY,eAAqB;EACnE,MAAM,gBAAgB,GAAG,MAAM,GAAG;AAElC,MAAI,WAAW,OAAO,CAAC,cAAc,EAAE;GACrC,MAAM,WAAW,OAAO,OAAO,eAAgB;AAE/C,UAAO,WAAW,OAAO,CAAC,SAAS;QAEnC,QAAO,iBAAiB;;;AAW9B,SAAS,iBAAiB,GAAc,GAAyB;AAC/D,QAAO,SAAU,OAAO,GAAG,MAAM;AAC/B,SAAO,EAAE,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,KAAK;;;AAIxC,SAAgB,KAAK,GAAG,cAA2B;AACjD,QAAO,aAAa,OAAO,iBAAiB"}
1
+ {"version":3,"file":"utils.cjs","names":["value","isColorScheme","getColorSchemeVar"],"sources":["../../../../src/core/css/utils.ts"],"sourcesContent":["import type { Dict } from \"../../utils\"\nimport type { ColorMode, System, ThemeToken, UsageTheme } from \"../system\"\nimport type { StyleConfig } from \"./config\"\nimport type { CSSFunction } from \"./css\"\nimport type { CSSProperties } from \"./index.types\"\nimport { isObject, isString, isUndefined } from \"../../utils\"\nimport { getColorSchemeVar, isColorScheme } from \"../system\"\n\nexport interface TransformOptions {\n system: System\n css?: CSSFunction\n fallback?: any\n prev?: Dict\n properties?: CSSProperties[]\n theme?: UsageTheme\n}\n\nexport interface Transform {\n (value: any, options: TransformOptions): any\n}\n\nexport const globalValues = new Set([\n \"inherit\",\n \"initial\",\n \"none\",\n \"revert\",\n \"unset\",\n])\n\nexport function isCSSFunction(value: any) {\n return isString(value) && value.includes(\"(\") && value.includes(\")\")\n}\n\nexport function getCSSFunction(value: any) {\n const regex = /(^[a-z-A-Z]+)\\((.*)\\)/g\n const [, type, values] = regex.exec(value) ?? []\n\n return { type, values }\n}\n\nexport function splitValues(\n values: string,\n cb: (\n current: string,\n prev: string | undefined,\n next: string | undefined,\n ) => boolean = (current) => current === \",\",\n addSeparator = false,\n) {\n const result = []\n\n let value = \"\"\n let depth = 0\n\n for (let i = 0; i < values.length; i++) {\n const current = values[i]\n const prev = values[i - 1]\n const next = values[i + 1]\n\n if (current === \"(\") depth++\n if (current === \")\") depth--\n\n if (!isUndefined(current) && cb(current, prev, next) && depth === 0) {\n if (value) result.push(value.trim())\n\n if (addSeparator) result.push(current)\n\n value = \"\"\n } else {\n value += current\n }\n }\n\n if (value) result.push(value.trim())\n\n return result.filter(Boolean)\n}\n\nexport function isCSSVar(value: string) {\n return /^var\\(--.+\\)$/.test(value)\n}\n\nexport function isCSSToken({ cssMap }: System) {\n return function (value: any) {\n return isObject(cssMap) && value in cssMap && !!cssMap[value]?.ref\n }\n}\n\nexport function isImportant(value: any): boolean {\n return (\n isString(value) && (/\\s*!important$/.test(value) || /\\s*!$/.test(value))\n )\n}\n\nexport function omitImportant(value: any): string {\n return isString(value) ? value.replace(/(!important|!)$/, \"\").trim() : value\n}\n\nexport function insertImportant(value: any, style?: StyleConfig): any {\n if (isString(value)) {\n return value + \" !important\"\n } else if (isObject(value)) {\n if (style?.important) {\n return Object.fromEntries(\n Object.entries(value).map(([key, value]) => [\n key,\n value + \" !important\",\n ]),\n )\n } else {\n if (!style?.properties) return value\n\n for (const property of style.properties) {\n value[property] += \" !important\"\n }\n }\n }\n\n return value\n}\n\nexport function analyzeCSSValue(value: any) {\n let n = parseFloat(value.toString())\n const unit = value.toString().replace(String(n), \"\")\n\n return { unit, unitless: !unit, value }\n}\n\nexport function tokenToVar(system: System) {\n return function (token: ThemeToken, value: any, fallbackValue?: any) {\n if (isColorScheme(value)) return getColorSchemeVar(system)(value)\n\n const resolvedToken = `${token}.${value}`\n\n if (isCSSToken(system)(resolvedToken)) {\n return system.cssMap[resolvedToken]!.ref\n } else {\n return fallbackValue || value\n }\n }\n}\n\nexport function varToValue(system: System) {\n return function (variable: string): string {\n const value = system.cssVars[variable]\n\n if (isCSSVar(value)) {\n return varToValue(system)(value.replace(/^var\\(/, \"\").replace(/\\)$/, \"\"))\n } else {\n return value\n }\n }\n}\n\nexport function tokenToValue(system: System) {\n return function (token: ThemeToken, value: any, fallbackValue?: any) {\n const resolvedToken = `${token}.${value}`\n\n if (isCSSToken(system)(resolvedToken)) {\n const variable = system.cssMap[resolvedToken]!.var\n\n return varToValue(system)(variable)\n } else {\n return fallbackValue || value\n }\n }\n}\n\nexport function mode<L, D>(light: L, dark: D) {\n return function (colorMode: ColorMode | undefined = \"light\"): D | L {\n return colorMode === \"light\" ? light : dark\n }\n}\n\nfunction combineFunctions(a: Transform, b: Transform): Transform {\n return function (value, ...args) {\n return b(a(value, ...args), ...args)\n }\n}\n\nexport function pipe(...transformers: Transform[]) {\n return transformers.reduce(combineFunctions)\n}\n"],"mappings":";;;;;AAqBA,MAAa,eAAe,IAAI,IAAI;CAClC;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAgB,cAAc,OAAY;AACxC,wDAAgB,MAAM,IAAI,MAAM,SAAS,IAAI,IAAI,MAAM,SAAS,IAAI;;AAGtE,SAAgB,eAAe,OAAY;CAEzC,MAAM,GAAG,MAAM,UADD,yBACiB,KAAK,MAAM,IAAI,EAAE;AAEhD,QAAO;EAAE;EAAM;EAAQ;;AAGzB,SAAgB,YACd,QACA,MAIgB,YAAY,YAAY,KACxC,eAAe,OACf;CACA,MAAM,SAAS,EAAE;CAEjB,IAAI,QAAQ;CACZ,IAAI,QAAQ;AAEZ,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,MAAM,UAAU,OAAO;EACvB,MAAM,OAAO,OAAO,IAAI;EACxB,MAAM,OAAO,OAAO,IAAI;AAExB,MAAI,YAAY,IAAK;AACrB,MAAI,YAAY,IAAK;AAErB,MAAI,oDAAa,QAAQ,IAAI,GAAG,SAAS,MAAM,KAAK,IAAI,UAAU,GAAG;AAC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,gBAAgB,GAAG,MAAM,GAAG;AAElC,MAAI,WAAW,OAAO,CAAC,cAAc,CACnC,QAAO,OAAO,OAAO,eAAgB;MAErC,QAAO,iBAAiB;;;AAK9B,SAAgB,WAAW,QAAgB;AACzC,QAAO,SAAU,UAA0B;EACzC,MAAM,QAAQ,OAAO,QAAQ;AAE7B,MAAI,SAAS,MAAM,CACjB,QAAO,WAAW,OAAO,CAAC,MAAM,QAAQ,UAAU,GAAG,CAAC,QAAQ,OAAO,GAAG,CAAC;MAEzE,QAAO;;;AAKb,SAAgB,aAAa,QAAgB;AAC3C,QAAO,SAAU,OAAmB,OAAY,eAAqB;EACnE,MAAM,gBAAgB,GAAG,MAAM,GAAG;AAElC,MAAI,WAAW,OAAO,CAAC,cAAc,EAAE;GACrC,MAAM,WAAW,OAAO,OAAO,eAAgB;AAE/C,UAAO,WAAW,OAAO,CAAC,SAAS;QAEnC,QAAO,iBAAiB;;;AAW9B,SAAS,iBAAiB,GAAc,GAAyB;AAC/D,QAAO,SAAU,OAAO,GAAG,MAAM;AAC/B,SAAO,EAAE,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,KAAK;;;AAIxC,SAAgB,KAAK,GAAG,cAA2B;AACjD,QAAO,aAAa,OAAO,iBAAiB"}
@@ -1 +1 @@
1
- {"version":3,"file":"breakpoint.cjs","names":[],"sources":["../../../../src/core/system/breakpoint.ts"],"sourcesContent":["import type { Dict } from \"../../utils\"\nimport type {\n Breakpoint,\n BreakpointConfig,\n DefineThemeBreakpointTokens,\n} from \"./index.types\"\nimport { getPx, isObject } from \"../../utils\"\n\ninterface BreakpointQuery {\n breakpoint: Breakpoint\n maxW: number | undefined\n maxWQuery: string | undefined\n minMaxQuery: string | undefined\n minW: number | undefined\n minWQuery: string | undefined\n query: string | undefined\n}\n\nexport interface Breakpoints {\n getQuery: (key: string) => string | undefined\n isResponsive: (obj: any, strict?: boolean) => boolean\n isResponsiveKey: (key: string) => boolean\n keys: Breakpoint[]\n queries: BreakpointQuery[]\n queriesObj: { [key: string]: BreakpointQuery }\n}\n\nfunction createQuery(\n min: number | undefined,\n max: number | undefined,\n identifier = \"@media screen\",\n): string | undefined {\n const query = [identifier]\n\n if (min) query.push(\"and\", `(min-width: ${min}px)`)\n if (max) query.push(\"and\", `(max-width: ${max}px)`)\n\n return query.length > 1\n ? query.join(\" \").replace(/^@container(\\s+\\w*)?\\s+and/, `@container$1`)\n : undefined\n}\n\nfunction createQueries(breakpoints: Dict<number>, config: BreakpointConfig) {\n const { direction, identifier } = config\n const down = direction !== \"up\"\n\n const queryEntries = Object.entries(breakpoints)\n .map(([breakpoint, width], i, entry) => {\n const [, relatedWidth] = entry[i + 1] ?? []\n let minW = down ? relatedWidth : width\n let maxW = down ? width : relatedWidth\n\n if (breakpoint === \"base\") {\n if (down) {\n maxW = undefined\n } else {\n minW = undefined\n }\n }\n\n if (down) {\n if (minW) minW += 1\n } else {\n if (maxW) maxW -= 1\n }\n\n const maxWQuery = createQuery(undefined, maxW, identifier)\n const minWQuery = createQuery(minW, undefined, identifier)\n const minMaxQuery = createQuery(minW, maxW, identifier)\n const query = down ? maxWQuery : minWQuery\n\n return [\n breakpoint,\n {\n breakpoint: breakpoint as Breakpoint,\n maxW,\n maxWQuery,\n minMaxQuery,\n minW,\n minWQuery,\n query,\n },\n ] as const\n })\n .sort((a, b) =>\n down\n ? (b[1].maxW ?? Infinity) - (a[1].maxW ?? Infinity)\n : (a[1].minW ?? 0) - (b[1].minW ?? 0),\n )\n\n const queries = queryEntries.map(([_, query]) => query)\n const queriesObj = Object.fromEntries(queryEntries)\n\n return { queries, queriesObj }\n}\n\nfunction transformBreakpoints(\n breakpoints: Dict,\n config: BreakpointConfig,\n): Dict {\n return Object.fromEntries(\n Object.entries(breakpoints)\n .map(([name, value]) => [name, getPx(value)] as const)\n .sort((a, b) => {\n if (config.direction !== \"up\") {\n return b[1] - a[1]\n } else {\n return a[1] - b[1]\n }\n }),\n )\n}\n\nexport function createBreakpoints(\n breakpoints: DefineThemeBreakpointTokens = {},\n config: BreakpointConfig = {},\n): Breakpoints {\n config.base ??= \"9999px\"\n config.direction ??= \"down\"\n\n breakpoints.base = config.direction !== \"up\" ? config.base : \"0px\"\n\n const transformedBreakpoints = transformBreakpoints(breakpoints, config)\n const { queries, queriesObj } = createQueries(transformedBreakpoints, config)\n const keys = Object.keys(queriesObj) as Breakpoint[]\n\n function isResponsive(obj: any, strict = false) {\n if (!isObject(obj)) return false\n\n const providedKeys = Object.keys(obj) as Breakpoint[]\n\n if (!providedKeys.length) return false\n\n if (strict && !providedKeys.includes(\"base\")) return false\n\n return providedKeys.every((key) => keys.includes(key))\n }\n\n function isResponsiveKey(key: string) {\n return key in queriesObj\n }\n\n function getQuery(key: string) {\n return key in queriesObj ? queriesObj[key]?.query : undefined\n }\n\n return {\n getQuery,\n isResponsive,\n isResponsiveKey,\n keys,\n queries,\n queriesObj,\n }\n}\n"],"mappings":";;;AA2BA,SAAS,YACP,KACA,KACA,aAAa,iBACO;CACpB,MAAM,QAAQ,CAAC,WAAW;AAE1B,KAAI,IAAK,OAAM,KAAK,OAAO,eAAe,IAAI,KAAK;AACnD,KAAI,IAAK,OAAM,KAAK,OAAO,eAAe,IAAI,KAAK;AAEnD,QAAO,MAAM,SAAS,IAClB,MAAM,KAAK,IAAI,CAAC,QAAQ,8BAA8B,eAAe,GACrE;;AAGN,SAAS,cAAc,aAA2B,QAA0B;CAC1E,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,OAAO,cAAc;CAE3B,MAAM,eAAe,OAAO,QAAQ,YAAY,CAC7C,KAAK,CAAC,YAAY,QAAQ,GAAG,UAAU;EACtC,MAAM,GAAG,gBAAgB,MAAM,IAAI,MAAM,EAAE;EAC3C,IAAI,OAAO,OAAO,eAAe;EACjC,IAAI,OAAO,OAAO,QAAQ;AAE1B,MAAI,eAAe,OACjB,KAAI,KACF,QAAO;MAEP,QAAO;AAIX,MAAI,MACF;OAAI,KAAM,SAAQ;aAEd,KAAM,SAAQ;EA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Aa;AACpC,SAAO,OAAO;;CAGhB,SAAS,SAAS,KAAa;AAC7B,SAAO,OAAO,aAAa,WAAW,MAAM,QAAQ;;AAGtD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"breakpoint.cjs","names":[],"sources":["../../../../src/core/system/breakpoint.ts"],"sourcesContent":["import type { Dict } from \"../../utils\"\nimport type {\n Breakpoint,\n BreakpointConfig,\n DefineThemeBreakpointTokens,\n} from \"./index.types\"\nimport { getPx, isObject } from \"../../utils\"\n\ninterface BreakpointQuery {\n breakpoint: Breakpoint\n maxW: number | undefined\n maxWQuery: string | undefined\n minMaxQuery: string | undefined\n minW: number | undefined\n minWQuery: string | undefined\n query: string | undefined\n}\n\nexport interface Breakpoints {\n keys: Breakpoint[]\n queries: BreakpointQuery[]\n queriesObj: { [key: string]: BreakpointQuery }\n getQuery: (key: string) => string | undefined\n isResponsive: (obj: any, strict?: boolean) => boolean\n isResponsiveKey: (key: string) => boolean\n}\n\nfunction createQuery(\n min: number | undefined,\n max: number | undefined,\n identifier = \"@media screen\",\n): string | undefined {\n const query = [identifier]\n\n if (min) query.push(\"and\", `(min-width: ${min}px)`)\n if (max) query.push(\"and\", `(max-width: ${max}px)`)\n\n return query.length > 1\n ? query.join(\" \").replace(/^@container(\\s+\\w*)?\\s+and/, `@container$1`)\n : undefined\n}\n\nfunction createQueries(breakpoints: Dict<number>, config: BreakpointConfig) {\n const { direction, identifier } = config\n const down = direction !== \"up\"\n\n const queryEntries = Object.entries(breakpoints)\n .map(([breakpoint, width], i, entry) => {\n const [, relatedWidth] = entry[i + 1] ?? []\n let minW = down ? relatedWidth : width\n let maxW = down ? width : relatedWidth\n\n if (breakpoint === \"base\") {\n if (down) {\n maxW = undefined\n } else {\n minW = undefined\n }\n }\n\n if (down) {\n if (minW) minW += 1\n } else {\n if (maxW) maxW -= 1\n }\n\n const maxWQuery = createQuery(undefined, maxW, identifier)\n const minWQuery = createQuery(minW, undefined, identifier)\n const minMaxQuery = createQuery(minW, maxW, identifier)\n const query = down ? maxWQuery : minWQuery\n\n return [\n breakpoint,\n {\n breakpoint: breakpoint as Breakpoint,\n maxW,\n maxWQuery,\n minMaxQuery,\n minW,\n minWQuery,\n query,\n },\n ] as const\n })\n .sort((a, b) =>\n down\n ? (b[1].maxW ?? Infinity) - (a[1].maxW ?? Infinity)\n : (a[1].minW ?? 0) - (b[1].minW ?? 0),\n )\n\n const queries = queryEntries.map(([_, query]) => query)\n const queriesObj = Object.fromEntries(queryEntries)\n\n return { queries, queriesObj }\n}\n\nfunction transformBreakpoints(\n breakpoints: Dict,\n config: BreakpointConfig,\n): Dict {\n return Object.fromEntries(\n Object.entries(breakpoints)\n .map(([name, value]) => [name, getPx(value)] as const)\n .sort((a, b) => {\n if (config.direction !== \"up\") {\n return b[1] - a[1]\n } else {\n return a[1] - b[1]\n }\n }),\n )\n}\n\nexport function createBreakpoints(\n breakpoints: DefineThemeBreakpointTokens = {},\n config: BreakpointConfig = {},\n): Breakpoints {\n config.base ??= \"9999px\"\n config.direction ??= \"down\"\n\n breakpoints.base = config.direction !== \"up\" ? config.base : \"0px\"\n\n const transformedBreakpoints = transformBreakpoints(breakpoints, config)\n const { queries, queriesObj } = createQueries(transformedBreakpoints, config)\n const keys = Object.keys(queriesObj) as Breakpoint[]\n\n function isResponsive(obj: any, strict = false) {\n if (!isObject(obj)) return false\n\n const providedKeys = Object.keys(obj) as Breakpoint[]\n\n if (!providedKeys.length) return false\n\n if (strict && !providedKeys.includes(\"base\")) return false\n\n return providedKeys.every((key) => keys.includes(key))\n }\n\n function isResponsiveKey(key: string) {\n return key in queriesObj\n }\n\n function getQuery(key: string) {\n return key in queriesObj ? queriesObj[key]?.query : undefined\n }\n\n return {\n getQuery,\n isResponsive,\n isResponsiveKey,\n keys,\n queries,\n queriesObj,\n }\n}\n"],"mappings":";;;AA2BA,SAAS,YACP,KACA,KACA,aAAa,iBACO;CACpB,MAAM,QAAQ,CAAC,WAAW;AAE1B,K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AAE;MAEhB,QAAO,EAAE,KAAK,EAAE;GAElB,CACL;;AAGH,SAAgB,kBACd,cAA2C,EAAE,EAC7C,SAA2B,EAAE,EAChB;AACb,QAAO,SAAS;AAChB,QAAO,cAAc;AAErB,aAAY,OAAO,OAAO,cAAc,OAAO,OAAO,OAAO;CAG7D,MAAM,EAAE,SAAS,eAAe,cADD,qBAAqB,aAAa,OAAO,EACF,OAAO;CAC7E,MAAM,OAAO,OAAO,KAAK,WAAW;CAEpC,SAAS,aAAa,KAAU,SAAS,OAAO;AAC9C,MAAI,iDAAU,IAAI,CAAE,QAAO;EAE3B,MAAM,eAAe,OAAO,KAAK,IAAI;AAErC,MAAI,CAAC,aAAa,OAAQ,QAAO;AAEjC,MAAI,UAAU,CAAC,aAAa,SAAS,OAAO,CAAE,QAAO;AAErD,SAAO,aAAa,OAAO,QAAQ,KAAK,SAAS,IAAI,CAAC;;CAGxD,SAAS,gBAAgB,KAAa;AACpC,SAAO,OAAO;;CAGhB,SAAS,SAAS,KAAa;AAC7B,SAAO,OAAO,aAAa,WAAW,MAAM,QAAQ;;AAGtD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"color-mode-provider.cjs","names":["ColorModeProvider: FC<ColorModeProviderProps>","COLOR_MODE_STORAGE_KEY","createStorageManager","useEnvironment","useSystemColorMode","systemColorMode","getPreventTransition","colorMode","internalColorMode"],"sources":["../../../../src/core/system/color-mode-provider.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren } from \"react\"\nimport type { ColorMode, ColorModeWithSystem, ThemeConfig } from \"./index.types\"\nimport type { Storage } from \"./storage-manager\"\nimport {\n createContext,\n use,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from \"react\"\nimport { isEmptyObject, noop } from \"../../utils\"\nimport { COLOR_MODE_STORAGE_KEY } from \"../constant\"\nimport { useEnvironment } from \"./environment-provider\"\nimport { createStorageManager } from \"./storage-manager\"\nimport { getPreventTransition } from \"./theme-provider\"\nimport { useSystemColorMode } from \"./use-system-color-mode\"\n\ninterface ColorModeContext {\n changeColorMode: (colorMode: ColorModeWithSystem) => void\n colorMode: ColorMode\n forced?: boolean\n internalColorMode: ColorModeWithSystem\n toggleColorMode: () => void\n}\n\nexport const ColorModeContext = createContext<ColorModeContext>({\n changeColorMode: noop,\n colorMode: \"light\",\n forced: false,\n internalColorMode: \"light\",\n toggleColorMode: noop,\n})\n\nexport interface ColorModeProviderProps extends PropsWithChildren {\n /**\n * The forced color mode.\n */\n colorMode?: ColorMode\n /**\n * The config of the yamada ui.\n */\n config?: ThemeConfig\n /**\n * If `storage` is `cookie`, the cookie to use.\n * If not provided, the cookie will be set to `document.cookie`.\n */\n cookie?: string\n /**\n * The storage to use.\n * If you are using a server-side rendering library, you should use `cookie`.\n *\n * @default 'localStorage'\n */\n storage?: Storage\n /**\n * The key of the value saved in storage.\n *\n * @default 'color-mode'\n */\n storageKey?: string\n}\n\nexport const ColorModeProvider: FC<ColorModeProviderProps> = ({\n children,\n colorMode: forcedColorMode,\n config: {\n defaultColorMode = \"light\" as ColorModeWithSystem,\n disableTransitionOnChange = true,\n } = {},\n cookie,\n storage = !!cookie ? \"cookie\" : \"localStorage\",\n storageKey = COLOR_MODE_STORAGE_KEY,\n}) => {\n const storageManager = useMemo(\n () =>\n createStorageManager<ColorModeWithSystem, ColorMode>(\n storage,\n storageKey,\n defaultColorMode,\n cookie,\n ),\n [cookie, defaultColorMode, storage, storageKey],\n )\n const environment = useEnvironment()\n const { getDocument } = environment\n const [internalColorMode, setInternalColorMode] =\n useState<ColorModeWithSystem>(storageManager.get())\n const { getSystemColorMode, systemColorMode } = useSystemColorMode({\n callback: (systemColorMode) => {\n if (internalColorMode !== \"system\") return\n\n setClassName(systemColorMode === \"dark\")\n setDataset(systemColorMode)\n },\n defaultColorMode: storageManager.default(\n defaultColorMode === \"dark\" ? \"dark\" : \"light\",\n ),\n })\n const colorMode =\n internalColorMode === \"system\" ? systemColorMode : internalColorMode\n\n const setDataset = useCallback(\n (colorMode: ColorMode) => {\n const doc = getDocument()\n\n if (!doc) return\n\n const cleanup = disableTransitionOnChange\n ? getPreventTransition(environment)\n : undefined\n\n doc.documentElement.dataset.mode = colorMode\n doc.documentElement.style.colorScheme = colorMode\n\n cleanup?.()\n },\n [disableTransitionOnChange, environment, getDocument],\n )\n\n const setClassName = useCallback(\n (isDark: boolean) => {\n const doc = getDocument()\n\n if (!doc) return\n\n doc.body.classList.add(isDark ? \"dark\" : \"light\")\n doc.body.classList.remove(isDark ? \"light\" : \"dark\")\n },\n [getDocument],\n )\n\n const changeColorMode = useCallback(\n (internalColorMode: ColorModeWithSystem) => {\n const colorMode =\n internalColorMode === \"system\"\n ? getSystemColorMode()\n : internalColorMode\n\n setInternalColorMode(internalColorMode)\n setClassName(colorMode === \"dark\")\n setDataset(colorMode)\n\n storageManager.set(internalColorMode)\n },\n [storageManager, getSystemColorMode, setClassName, setDataset],\n )\n\n const toggleColorMode = useCallback(() => {\n changeColorMode(colorMode === \"dark\" ? \"light\" : \"dark\")\n }, [changeColorMode, colorMode])\n\n useEffect(() => {\n const internalColorMode = storageManager.get()\n\n changeColorMode(internalColorMode)\n }, [changeColorMode, storageManager])\n\n const context = useMemo(\n () => ({\n changeColorMode: forcedColorMode ? noop : changeColorMode,\n colorMode: forcedColorMode ?? colorMode,\n forced: forcedColorMode !== undefined,\n internalColorMode,\n toggleColorMode: forcedColorMode ? noop : toggleColorMode,\n }),\n [\n forcedColorMode,\n colorMode,\n internalColorMode,\n changeColorMode,\n toggleColorMode,\n ],\n )\n\n return <ColorModeContext value={context}>{children}</ColorModeContext>\n}\n\n/**\n * `useColorMode` is a custom hook that returns the current color mode.\n *\n * @see https://yamada-ui.com/docs/hooks/use-color-mode\n */\nexport const useColorMode = (): ColorModeContext => {\n const context = use(ColorModeContext)\n\n if (isEmptyObject(context)) {\n return {\n changeColorMode: noop,\n colorMode: \"light\",\n forced: false,\n internalColorMode: \"light\",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,MAAMA,cACJC,wBAAsB,WAClB,oBAAoB,GACpBA;AAEN,uBAAqBA,oBAAkB;AACvC,eAAaD,gBAAc,OAAO;AAClC,aAAWA,YAAU;AAErB,iBAAe,IAAIC,oBAAkB;IAEvC;EAAC;EAAgB;EAAoB;EAAc;EAAW,CAC/D;CAED,MAAM,+CAAoC;AACxC,kBAAgB,cAAc,SAAS,UAAU,OAAO;IACvD,CAAC,iBAAiB,UAAU,CAAC;AAEhC,4BAAgB;AAGd,kBAF0B,eAAe,KAAK,CAEZ;IACjC,CAAC,iBAAiB,eAAe,CAAC;AAmBrC,QAAO,2CAAC;EAAiB,iCAhBhB;GACL,iBAAiB,oDAAkB,OAAO;GAC1C,WAAW,mBAAmB;GAC9B,QAAQ,oBAAoB;GAC5B;GACA,iBAAiB,oDAAkB,OAAO;GAC3C,GACD;GACE;GACA;GACA;GACA;GACA;GACD,CACF;EAEyC;GAA4B;;;;;;;AAQxE,MAAa,qBAAuC;CAClD,MAAM,yBAAc,iBAAiB;AAErC,0DAAkB,QAAQ,CACxB,QAAO;EACL,mDAAiB;EACjB,WAAW;EACX,QAAQ;EACR,mBAAmB;EACnB,mDAAiB;EAClB;KAED,QAAO"}
1
+ {"version":3,"file":"color-mode-provider.cjs","names":["ColorModeProvider: FC<ColorModeProviderProps>","COLOR_MODE_STORAGE_KEY","createStorageManager","useEnvironment","useSystemColorMode","systemColorMode","getPreventTransition","colorMode","internalColorMode"],"sources":["../../../../src/core/system/color-mode-provider.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren } from \"react\"\nimport type { ColorMode, ColorModeWithSystem, ThemeConfig } from \"./index.types\"\nimport type { Storage } from \"./storage-manager\"\nimport {\n createContext,\n use,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from \"react\"\nimport { isEmptyObject, noop } from \"../../utils\"\nimport { COLOR_MODE_STORAGE_KEY } from \"../constant\"\nimport { useEnvironment } from \"./environment-provider\"\nimport { createStorageManager } from \"./storage-manager\"\nimport { getPreventTransition } from \"./theme-provider\"\nimport { useSystemColorMode } from \"./use-system-color-mode\"\n\ninterface ColorModeContext {\n colorMode: ColorMode\n internalColorMode: ColorModeWithSystem\n changeColorMode: (colorMode: ColorModeWithSystem) => void\n toggleColorMode: () => void\n forced?: boolean\n}\n\nexport const ColorModeContext = createContext<ColorModeContext>({\n changeColorMode: noop,\n colorMode: \"light\",\n forced: false,\n internalColorMode: \"light\",\n toggleColorMode: noop,\n})\n\nexport interface ColorModeProviderProps extends PropsWithChildren {\n /**\n * The forced color mode.\n */\n colorMode?: ColorMode\n /**\n * The config of the yamada ui.\n */\n config?: ThemeConfig\n /**\n * If `storage` is `cookie`, the cookie to use.\n * If not provided, the cookie will be set to `document.cookie`.\n */\n cookie?: string\n /**\n * The storage to use.\n * If you are using a server-side rendering library, you should use `cookie`.\n *\n * @default 'localStorage'\n */\n storage?: Storage\n /**\n * The key of the value saved in storage.\n *\n * @default 'color-mode'\n */\n storageKey?: string\n}\n\nexport const ColorModeProvider: FC<ColorModeProviderProps> = ({\n children,\n colorMode: forcedColorMode,\n config: {\n defaultColorMode = \"light\" as ColorModeWithSystem,\n disableTransitionOnChange = true,\n } = {},\n cookie,\n storage = !!cookie ? \"cookie\" : \"localStorage\",\n storageKey = COLOR_MODE_STORAGE_KEY,\n}) => {\n const storageManager = useMemo(\n () =>\n createStorageManager<ColorModeWithSystem, ColorMode>(\n storage,\n storageKey,\n defaultColorMode,\n cookie,\n ),\n [cookie, defaultColorMode, storage, storageKey],\n )\n const environment = useEnvironment()\n const { getDocument } = environment\n const [internalColorMode, setInternalColorMode] =\n useState<ColorModeWithSystem>(storageManager.get())\n const { getSystemColorMode, systemColorMode } = useSystemColorMode({\n callback: (systemColorMode) => {\n if (internalColorMode !== \"system\") return\n\n setClassName(systemColorMode === \"dark\")\n setDataset(systemColorMode)\n },\n defaultColorMode: storageManager.default(\n defaultColorMode === \"dark\" ? \"dark\" : \"light\",\n ),\n })\n const colorMode =\n internalColorMode === \"system\" ? systemColorMode : internalColorMode\n\n const setDataset = useCallback(\n (colorMode: ColorMode) => {\n const doc = getDocument()\n\n if (!doc) return\n\n const cleanup = disableTransitionOnChange\n ? getPreventTransition(environment)\n : undefined\n\n doc.documentElement.dataset.mode = colorMode\n doc.documentElement.style.colorScheme = colorMode\n\n cleanup?.()\n },\n [disableTransitionOnChange, environment, getDocument],\n )\n\n const setClassName = useCallback(\n (isDark: boolean) => {\n const doc = getDocument()\n\n if (!doc) return\n\n doc.body.classList.add(isDark ? \"dark\" : \"light\")\n doc.body.classList.remove(isDark ? \"light\" : \"dark\")\n },\n [getDocument],\n )\n\n const changeColorMode = useCallback(\n (internalColorMode: ColorModeWithSystem) => {\n const colorMode =\n internalColorMode === \"system\"\n ? getSystemColorMode()\n : internalColorMode\n\n setInternalColorMode(internalColorMode)\n setClassName(colorMode === \"dark\")\n setDataset(colorMode)\n\n storageManager.set(internalColorMode)\n },\n [storageManager, getSystemColorMode, setClassName, setDataset],\n )\n\n const toggleColorMode = useCallback(() => {\n changeColorMode(colorMode === \"dark\" ? \"light\" : \"dark\")\n }, [changeColorMode, colorMode])\n\n useEffect(() => {\n const internalColorMode = storageManager.get()\n\n changeColorMode(internalColorMode)\n }, [changeColorMode, storageManager])\n\n const context = useMemo(\n () => ({\n changeColorMode: forcedColorMode ? noop : changeColorMode,\n colorMode: forcedColorMode ?? colorMode,\n forced: forcedColorMode !== undefined,\n internalColorMode,\n toggleColorMode: forcedColorMode ? noop : toggleColorMode,\n }),\n [\n forcedColorMode,\n colorMode,\n internalColorMode,\n changeColorMode,\n toggleColorMode,\n ],\n )\n\n return <ColorModeContext value={context}>{children}</ColorModeContext>\n}\n\n/**\n * `useColorMode` is a custom hook that returns the current color mode.\n *\n * @see https://yamada-ui.com/docs/hooks/use-color-mode\n */\nexport const useColorMode = (): ColorModeContext => {\n const context = use(ColorModeContext)\n\n if (isEmptyObject(context)) {\n return {\n changeColorMode: noop,\n colorMode: \"light\",\n forced: false,\n internalColorMode: \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AC1C,MAAMA,cACJC,wBAAsB,WAClB,oBAAoB,GACpBA;AAEN,uBAAqBA,oBAAkB;AACvC,eAAaD,gBAAc,OAAO;AAClC,aAAWA,YAAU;AAErB,iBAAe,IAAIC,oBAAkB;IAEvC;EAAC;EAAgB;EAAoB;EAAc;EAAW,CAC/D;CAED,MAAM,+CAAoC;AACxC,kBAAgB,cAAc,SAAS,UAAU,OAAO;IACvD,CAAC,iBAAiB,UAAU,CAAC;AAEhC,4BAAgB;AAGd,kBAF0B,eAAe,KAAK,CAEZ;IACjC,CAAC,iBAAiB,eAAe,CAAC;AAmBrC,QAAO,2CAAC;EAAiB,iCAhBhB;GACL,iBAAiB,oDAAkB,OAAO;GAC1C,WAAW,mBAAmB;GAC9B,QAAQ,oBAAoB;GAC5B;GACA,iBAAiB,oDAAkB,OAAO;GAC3C,GACD;GACE;GACA;GACA;GACA;GACA;GACD,CACF;EAEyC;GAA4B;;;;;;;AAQxE,MAAa,qBAAuC;CAClD,MAAM,yBAAc,iBAAiB;AAErC,0DAAkB,QAAQ,CACxB,QAAO;EACL,mDAAiB;EACjB,WAAW;EACX,QAAQ;EACR,mBAAmB;EACnB,mDAAiB;EAClB;KAED,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"layer.cjs","names":["defaultLayers: Layers","DEFAULT_LAYERS"],"sources":["../../../../src/core/system/layer.ts"],"sourcesContent":["import type { Dict } from \"../../utils\"\nimport type { LayerScheme, LayersConfig } from \"./index.types\"\nimport { runIfFn } from \"../../utils\"\nimport { DEFAULT_LAYERS } from \"../constant\"\n\nexport interface Layers {\n atRule: string | undefined\n getAtRule?: (name: LayerScheme) => string\n names: string[]\n wrap: (name: LayerScheme, style?: (() => Dict) | Dict) => Dict\n}\n\nexport const defaultLayers: Layers = {\n atRule: undefined,\n names: [] as string[],\n wrap: function (_: LayerScheme, style?: (() => Dict) | Dict) {\n return runIfFn(style) ?? {}\n },\n}\n\nexport function createLayers(\n layers: false | LayersConfig = DEFAULT_LAYERS,\n): Layers {\n if (!layers) return defaultLayers\n\n const names = Object.values(layers)\n .sort((a, b) => a.order - b.order)\n .map((layer) => layer.name)\n const atRule = `@layer ${names.join(\", \")};`\n\n const getAtRule = (name: LayerScheme) => `@layer ${layers[name].name}`\n\n const wrap = (name: LayerScheme, style?: (() => Dict) | Dict) => {\n const atRule = getAtRule(name)\n\n return { [atRule]: runIfFn(style) }\n }\n\n return {\n atRule,\n getAtRule,\n names,\n wrap,\n }\n}\n"],"mappings":";;;;AAYA,MAAaA,gBAAwB;CACnC,QAAQ;CACR,OAAO,EAAE;CACT,MAAM,SAAU,GAAgB,OAA6B;AAC3D,wDAAe,MAAM,IAAI,EAAE;;CAE9B;AAED,SAAgB,aACd,SAA+BC,iCACvB;AACR,KAAI,CAAC,OAAQ,QAAO;CAEpB,MAAM,QAAQ,OAAO,OAAO,OAAO,CAChC,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,CACjC,KAAK,UAAU,MAAM,KAAK;CAC7B,MAAM,SAAS,UAAU,MAAM,KAAK,KAAK,CAAC;CAE1C,MAAM,aAAa,SAAsB,UAAU,OAAO,MAAM;CAEhE,MAAM,QAAQ,MAAmB,UAAgC;AAG/D,SAAO,GAFQ,UAAU,KAAK,kDAEH,MAAM,EAAE;;AAGrC,QAAO;EACL;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"layer.cjs","names":["defaultLayers: Layers","DEFAULT_LAYERS"],"sources":["../../../../src/core/system/layer.ts"],"sourcesContent":["import type { Dict } from \"../../utils\"\nimport type { LayerScheme, LayersConfig } from \"./index.types\"\nimport { runIfFn } from \"../../utils\"\nimport { DEFAULT_LAYERS } from \"../constant\"\n\nexport interface Layers {\n atRule: string | undefined\n names: string[]\n wrap: (name: LayerScheme, style?: (() => Dict) | Dict) => Dict\n getAtRule?: (name: LayerScheme) => string\n}\n\nexport const defaultLayers: Layers = {\n atRule: undefined,\n names: [] as string[],\n wrap: function (_: LayerScheme, style?: (() => Dict) | Dict) {\n return runIfFn(style) ?? {}\n },\n}\n\nexport function createLayers(\n layers: false | LayersConfig = DEFAULT_LAYERS,\n): Layers {\n if (!layers) return defaultLayers\n\n const names = Object.values(layers)\n .sort((a, b) => a.order - b.order)\n .map((layer) => layer.name)\n const atRule = `@layer ${names.join(\", \")};`\n\n const getAtRule = (name: LayerScheme) => `@layer ${layers[name].name}`\n\n const wrap = (name: LayerScheme, style?: (() => Dict) | Dict) => {\n const atRule = getAtRule(name)\n\n return { [atRule]: runIfFn(style) }\n }\n\n return {\n atRule,\n getAtRule,\n names,\n wrap,\n }\n}\n"],"mappings":";;;;AAYA,MAAaA,gBAAwB;CACnC,QAAQ;CACR,OAAO,EAAE;CACT,MAAM,SAAU,GAAgB,OAA6B;AAC3D,wDAAe,MAAM,IAAI,EAAE;;CAE9B;AAED,SAAgB,aACd,SAA+BC,iCACvB;AACR,KAAI,CAAC,OAAQ,QAAO;CAEpB,MAAM,QAAQ,OAAO,OAAO,OAAO,CAChC,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,CACjC,KAAK,UAAU,MAAM,KAAK;CAC7B,MAAM,SAAS,UAAU,MAAM,KAAK,KAAK,CAAC;CAE1C,MAAM,aAAa,SAAsB,UAAU,OAAO,MAAM;CAEhE,MAAM,QAAQ,MAAmB,UAAgC;AAG/D,SAAO,GAFQ,UAAU,KAAK,kDAEH,MAAM,EAAE;;AAGrC,QAAO;EACL;EACA;EACA;EACA;EACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"storage-script.cjs","names":["COLOR_MODE_STORAGE_KEY","THEME_SCHEME_STORAGE_KEY"],"sources":["../../../../src/core/system/storage-script.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ColorModeWithSystem, ThemeScheme } from \"./index.types\"\nimport type { Storage } from \"./storage-manager\"\nimport { COLOR_MODE_STORAGE_KEY, THEME_SCHEME_STORAGE_KEY } from \"../constant\"\n\nexport interface StorageScriptProps<Y extends string> {\n key?: string\n type?: Storage\n defaultValue?: Y\n nonce?: string\n}\n\nexport function getStorageScript<Y extends string>(\n type: \"colorMode\" | \"themeScheme\",\n defaultKey: string,\n) {\n return function ({\n key = defaultKey,\n type: storage = \"localStorage\",\n defaultValue,\n }: Omit<StorageScriptProps<Y>, \"nonce\"> = {}) {\n if (type === \"colorMode\") {\n if (storage === \"localStorage\") {\n return `!(function(){try{var a=function(c){var v=\"(prefers-color-scheme: dark)\",h=window.matchMedia(v).matches?\"dark\":\"light\",r=c===\"system\"?h:c,o=document.documentElement,s=document.body,l=\"light\",d=\"dark\",i=r===\"dark\";return s.classList.add(i?d:l),s.classList.remove(i?l:d),o.style.colorScheme=r,o.dataset.mode=r,r},m=\"${defaultValue}\",e=\"${key}\",t=localStorage.getItem(e);t?a(t):(localStorage.setItem(e,m),localStorage.setItem(\\`default-\\${e}\\`,a(m)))}catch{}})();`\n } else {\n return `!(function(){try{var a=function(o){var l=\"(prefers-color-scheme: dark)\",v=window.matchMedia(l).matches?\"dark\":\"light\",e=o===\"system\"?v:o,d=document.documentElement,m=document.body,i=\"light\",n=\"dark\",s=e===\"dark\";return m.classList.add(s?n:i),m.classList.remove(s?i:n),d.style.colorScheme=e,d.dataset.mode=e,e},h=\"${defaultValue}\",r=\"${key}\",t=document.cookie.match(new RegExp(\"(^| )\".concat(r,\"=([^;]+)\"))),c=t?t[2]:null;c?a(c):(document.cookie=\"\".concat(r,\"=\").concat(h,\"; max-age=31536000; path=/\"),document.cookie=\"\".concat(\\`default-\\${r}\\`,\"=\").concat(a(h),\"; max-age=31536000; path=/\"))}catch{}})();`\n }\n } else {\n if (storage === \"localStorage\") {\n return `!(function(){try{var a=function(c){var o=document.documentElement;return o.dataset.theme=c,c},m='${defaultValue}',e='${key}',t=localStorage.getItem(e);t?a(t):localStorage.setItem(e, a(m))}catch{}})();`\n } else {\n return `!(function(){try{var a=function(c){var o=document.documentElement;return o.dataset.theme=c,c},h='${defaultValue}',r='${key}',t=document.cookie.match(new RegExp('(^| )'.concat(r,'=([^;]+)'))),c=t?t[2]:null;c?a(c):(document.cookie=''.concat(r,'=').concat(a(h),'; max-age=31536000; path=/'))}catch{}})();`\n }\n }\n }\n}\n\nexport function ColorModeScript({\n nonce,\n ...rest\n}: StorageScriptProps<ColorModeWithSystem>) {\n const html = getStorageScript(\n \"colorMode\",\n COLOR_MODE_STORAGE_KEY,\n )({ defaultValue: \"light\", ...rest })\n\n return <script dangerouslySetInnerHTML={{ __html: html }} nonce={nonce} />\n}\n\nexport function ThemeSchemeScript({\n nonce,\n ...rest\n}: StorageScriptProps<ThemeScheme>) {\n const html = getStorageScript(\n \"themeScheme\",\n THEME_SCHEME_STORAGE_KEY,\n )({\n defaultValue: \"base\",\n ...rest,\n })\n\n return <script dangerouslySetInnerHTML={{ __html: html }} nonce={nonce} />\n}\n"],"mappings":";;;;;;;AAaA,SAAgB,iBACd,MACA,YACA;AACA,QAAO,SAAU,EACf,MAAM,YACN,MAAM,UAAU,gBAChB,iBACwC,EAAE,EAAE;AAC5C,MAAI,SAAS,YACX,KAAI,YAAY,eACd,QAAO,4TAA4T,aAAa,OAAO,IAAI;MAE3V,QAAO,4TAA4T,aAAa,OAAO,IAAI;WAGzV,YAAY,eACd,QAAO,oGAAoG,aAAa,OAAO,IAAI;MAEnI,QAAO,oGAAoG,aAAa,OAAO,IAAI;;;AAM3I,SAAgB,gBAAgB,EAC9B,OACA,GAAG,QACuC;AAM1C,QAAO,2CAAC;EAAO,yBAAyB,EAAE,QAL7B,iBACX,aACAA,wCACD,CAAC;GAAE,cAAc;GAAS,GAAG;GAAM,CAAC,EAEmB;EAAS;GAAS;;AAG5E,SAAgB,kBAAkB,EAChC,OACA,GAAG,QAC+B;AASlC,QAAO,2CAAC;EAAO,yBAAyB,EAAE,QAR7B,iBACX,eACAC,0CACD,CAAC;GACA,cAAc;GACd,GAAG;GACJ,CAAC,EAEsD;EAAS;GAAS"}
1
+ {"version":3,"file":"storage-script.cjs","names":["COLOR_MODE_STORAGE_KEY","THEME_SCHEME_STORAGE_KEY"],"sources":["../../../../src/core/system/storage-script.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ColorModeWithSystem, ThemeScheme } from \"./index.types\"\nimport type { Storage } from \"./storage-manager\"\nimport { COLOR_MODE_STORAGE_KEY, THEME_SCHEME_STORAGE_KEY } from \"../constant\"\n\nexport interface StorageScriptProps<Y extends string> {\n defaultValue?: Y\n key?: string\n nonce?: string\n type?: Storage\n}\n\nexport function getStorageScript<Y extends string>(\n type: \"colorMode\" | \"themeScheme\",\n defaultKey: string,\n) {\n return function ({\n key = defaultKey,\n type: storage = \"localStorage\",\n defaultValue,\n }: Omit<StorageScriptProps<Y>, \"nonce\"> = {}) {\n if (type === \"colorMode\") {\n if (storage === \"localStorage\") {\n return `!(function(){try{var a=function(c){var v=\"(prefers-color-scheme: dark)\",h=window.matchMedia(v).matches?\"dark\":\"light\",r=c===\"system\"?h:c,o=document.documentElement,s=document.body,l=\"light\",d=\"dark\",i=r===\"dark\";return s.classList.add(i?d:l),s.classList.remove(i?l:d),o.style.colorScheme=r,o.dataset.mode=r,r},m=\"${defaultValue}\",e=\"${key}\",t=localStorage.getItem(e);t?a(t):(localStorage.setItem(e,m),localStorage.setItem(\\`default-\\${e}\\`,a(m)))}catch{}})();`\n } else {\n return `!(function(){try{var a=function(o){var l=\"(prefers-color-scheme: dark)\",v=window.matchMedia(l).matches?\"dark\":\"light\",e=o===\"system\"?v:o,d=document.documentElement,m=document.body,i=\"light\",n=\"dark\",s=e===\"dark\";return m.classList.add(s?n:i),m.classList.remove(s?i:n),d.style.colorScheme=e,d.dataset.mode=e,e},h=\"${defaultValue}\",r=\"${key}\",t=document.cookie.match(new RegExp(\"(^| )\".concat(r,\"=([^;]+)\"))),c=t?t[2]:null;c?a(c):(document.cookie=\"\".concat(r,\"=\").concat(h,\"; max-age=31536000; path=/\"),document.cookie=\"\".concat(\\`default-\\${r}\\`,\"=\").concat(a(h),\"; max-age=31536000; path=/\"))}catch{}})();`\n }\n } else {\n if (storage === \"localStorage\") {\n return `!(function(){try{var a=function(c){var o=document.documentElement;return o.dataset.theme=c,c},m='${defaultValue}',e='${key}',t=localStorage.getItem(e);t?a(t):localStorage.setItem(e, a(m))}catch{}})();`\n } else {\n return `!(function(){try{var a=function(c){var o=document.documentElement;return o.dataset.theme=c,c},h='${defaultValue}',r='${key}',t=document.cookie.match(new RegExp('(^| )'.concat(r,'=([^;]+)'))),c=t?t[2]:null;c?a(c):(document.cookie=''.concat(r,'=').concat(a(h),'; max-age=31536000; path=/'))}catch{}})();`\n }\n }\n }\n}\n\nexport function ColorModeScript({\n nonce,\n ...rest\n}: StorageScriptProps<ColorModeWithSystem>) {\n const html = getStorageScript(\n \"colorMode\",\n COLOR_MODE_STORAGE_KEY,\n )({ defaultValue: \"light\", ...rest })\n\n return <script dangerouslySetInnerHTML={{ __html: html }} nonce={nonce} />\n}\n\nexport function ThemeSchemeScript({\n nonce,\n ...rest\n}: StorageScriptProps<ThemeScheme>) {\n const html = getStorageScript(\n \"themeScheme\",\n THEME_SCHEME_STORAGE_KEY,\n )({\n defaultValue: \"base\",\n ...rest,\n })\n\n return <script dangerouslySetInnerHTML={{ __html: html }} nonce={nonce} />\n}\n"],"mappings":";;;;;;;AAaA,SAAgB,iBACd,MACA,YACA;AACA,QAAO,SAAU,EACf,MAAM,YACN,MAAM,UAAU,gBAChB,iBACwC,EAAE,EAAE;AAC5C,MAAI,SAAS,YACX,KAAI,YAAY,eACd,QAAO,4TAA4T,aAAa,OAAO,IAAI;MAE3V,QAAO,4TAA4T,aAAa,OAAO,IAAI;WAGzV,YAAY,eACd,QAAO,oGAAoG,aAAa,OAAO,IAAI;MAEnI,QAAO,oGAAoG,aAAa,OAAO,IAAI;;;AAM3I,SAAgB,gBAAgB,EAC9B,OACA,GAAG,QACuC;AAM1C,QAAO,2CAAC;EAAO,yBAAyB,EAAE,QAL7B,iBACX,aACAA,wCACD,CAAC;GAAE,cAAc;GAAS,GAAG;GAAM,CAAC,EAEmB;EAAS;GAAS;;AAG5E,SAAgB,kBAAkB,EAChC,OACA,GAAG,QAC+B;AASlC,QAAO,2CAAC;EAAO,yBAAyB,EAAE,QAR7B,iBACX,eACAC,0CACD,CAAC;GACA,cAAc;GACd,GAAG;GACJ,CAAC,EAEsD;EAAS;GAAS"}
@@ -1 +1 @@
1
- {"version":3,"file":"styled.cjs","names":["Insertion: FC<InsertionProps>","createContext","getDisplayName","createShouldForwardProp","props","className: string | undefined","useSystem","useTheme","useComponentStyle","forwardProps","css","colorScheme","Slot"],"sources":["../../../../src/core/system/styled.tsx"],"sourcesContent":["\"use client\"\n\nimport type { EmotionCache, SerializedStyles } from \"@emotion/utils\"\nimport type { FC } from \"react\"\nimport type { Dict } from \"../../utils\"\nimport type { As, ShouldForwardProp, StyledComponent } from \"../components\"\nimport type { CSSModifierObject, CSSPropObject } from \"../css\"\nimport type {\n ColorScheme,\n ComponentStyle,\n System,\n UsageTheme,\n} from \"./index.types\"\nimport { withEmotionCache } from \"@emotion/react\"\nimport { serializeStyles } from \"@emotion/serialize\"\nimport { useInsertionEffectAlwaysWithSyncFallback } from \"@emotion/use-insertion-effect-with-fallbacks\"\nimport {\n getRegisteredStyles,\n insertStyles,\n registerStyles,\n} from \"@emotion/utils\"\nimport { useMemo, useRef } from \"react\"\nimport isEqual from \"react-fast-compare\"\nimport { Slot } from \"../../components/slot\"\nimport {\n createContext,\n createdDom,\n cx,\n filterEmpty,\n filterUndefined,\n isString,\n isUndefined,\n runIfFn,\n splitObject,\n toArray,\n toKebabCase,\n} from \"../../utils\"\nimport {\n createShouldForwardProp,\n getDisplayName,\n useComponentStyle,\n} from \"../components\"\nimport { css } from \"../css\"\nimport { useSystem } from \"./system-provider\"\nimport { useTheme } from \"./theme-provider\"\n\ninterface InsertionProps {\n cache: EmotionCache\n htmlTag: boolean\n serialized: SerializedStyles\n}\n\nconst Insertion: FC<InsertionProps> = ({ cache, htmlTag, serialized }) => {\n registerStyles(cache, serialized, htmlTag)\n\n const style = useInsertionEffectAlwaysWithSyncFallback(() =>\n insertStyles(cache, serialized, htmlTag),\n )\n\n if (!createdDom() && !isUndefined(style)) {\n let className = serialized.name\n let next = serialized.next\n\n while (next !== undefined) {\n className = cx(className, next.name)\n next = next.next\n }\n\n return (\n <style\n data-emotion={cx(cache.key, className)}\n dangerouslySetInnerHTML={{ __html: style }}\n nonce={cache.sheet.nonce}\n />\n )\n } else {\n return null\n }\n}\n\nconst useSplitProps = <Y extends Dict, M extends Dict>(\n props: Dict,\n shouldForwardProp?: ShouldForwardProp,\n) => {\n const propsRef = useRef(props)\n\n if (!isEqual(propsRef.current, props)) propsRef.current = props\n\n const computedProps = propsRef.current\n\n return useMemo(\n () => splitObject<Y, M>(computedProps, shouldForwardProp),\n [computedProps, shouldForwardProp],\n )\n}\n\nexport const [ColorSchemeContext, useColorSchemeContext] =\n createContext<ColorScheme>({\n name: \"ColorSchemeContext\",\n strict: false,\n })\n\nexport interface StyledOptions<\n Y extends CSSPropObject = CSSPropObject,\n M extends CSSModifierObject = CSSModifierObject,\n D extends CSSModifierObject = CSSModifierObject,\n H extends number | string | symbol = string,\n> extends Omit<ComponentStyle<Y, M, D>, \"className\"> {\n name?: string\n target?: string\n className?: ((system: System) => string) | string\n displayName?: string\n forwardAsChild?: boolean\n shouldForwardProp?: boolean | ShouldForwardProp\n forwardProps?: string[]\n transferProps?: H[]\n}\n\nexport function createStyled<\n Y extends As,\n M extends object = {},\n D extends CSSPropObject = CSSPropObject,\n H extends CSSModifierObject = CSSModifierObject,\n R extends CSSModifierObject = CSSModifierObject,\n>(\n el: Y,\n {\n base,\n compounds,\n props,\n sizes,\n variants,\n defaultProps,\n transferProps,\n ...options\n }: StyledOptions<D, H, R, keyof M> = {},\n) {\n const displayName = options.displayName ?? getDisplayName(options.name, \"\")\n const shouldForwardProp = !options.shouldForwardProp\n ? createShouldForwardProp(options.forwardProps)\n : undefined\n const style = filterUndefined({\n base,\n compounds,\n props,\n sizes,\n variants,\n defaultProps,\n })\n\n const StyledComponent = withEmotionCache<Dict>(function (\n { as: Component = el, asChild, children, ...props },\n cache,\n ref,\n ) {\n let className: string | undefined = \"\"\n\n const system = useSystem()\n const { theme } = useTheme<UsageTheme>()\n const componentStyleOptions = {\n className: system.utils.getClassName(\n runIfFn(options.className, system) ?? toKebabCase(options.name ?? \"\"),\n ),\n style,\n transferProps,\n }\n const registered = useRef<string[]>([])\n const htmlTag = isString(Component)\n const forwardAsChild =\n options.forwardAsChild || options.forwardProps?.includes(\"asChild\")\n const [omittedProps, styleProps] = useSplitProps(props, shouldForwardProp)\n const [, rest] = useComponentStyle<any, {}>(\n omittedProps,\n componentStyleOptions,\n )\n const [cssArray, colorScheme, forwardProps] = useMemo(() => {\n const { css, colorScheme, ...forwardProps } = rest\n\n return [toArray(css), colorScheme, forwardProps]\n }, [rest])\n\n styleProps.colorScheme ??= colorScheme\n\n if (forwardProps.className)\n className = getRegisteredStyles(\n cache.registered,\n registered.current,\n forwardProps.className,\n ).trim()\n\n const interpolations = useMemo(\n () => [\n ...registered.current,\n ...filterEmpty([...cssArray, styleProps].map(css(system, theme))),\n ],\n [cssArray, system, styleProps, theme],\n )\n\n const serialized = useMemo(\n () => serializeStyles(interpolations, cache.registered),\n [interpolations, cache.registered],\n )\n\n className = cx(\n className,\n !!serialized.styles ? `${cache.key}-${serialized.name}` : undefined,\n )\n className = cx(className, options.target)\n\n if (!className) className = undefined\n\n const mergedProps = { ...forwardProps, className, children }\n\n return (\n <ColorSchemeContext value={styleProps.colorScheme}>\n <Insertion cache={cache} htmlTag={htmlTag} serialized={serialized} />\n\n {asChild && !forwardAsChild ? (\n <Slot ref={ref} {...mergedProps} />\n ) : (\n <Component ref={ref} {...mergedProps} />\n )}\n </ColorSchemeContext>\n )\n }) as StyledComponent<Y, M>\n\n StyledComponent.displayName = displayName || \"StyledComponent\"\n\n return StyledComponent\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAMA,aAAiC,EAAE,OAAO,SAAS,iBAAiB;AACxE,oCAAe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B,EAAE,CAAC;EACvC,MAAM,0DAAmB,UAAU;EACnC,MAAM,iBACJ,QAAQ,kBAAkB,QAAQ,cAAc,SAAS,UAAU;EACrE,MAAM,CAAC,cAAc,cAAc,cAAcH,SAAO,kBAAkB;EAC1E,MAAM,GAAG,QAAQI,8CACf,cACA,sBACD;EACD,MAAM,CAAC,UAAU,aAAa,yCAA8B;GAC1D,MAAM,EAAE,YAAK,4BAAa,GAAGC,mBAAiB;AAE9C,UAAO;mDAASC,MAAI;IAAEC;IAAaF;IAAa;KAC/C,CAAC,KAAK,CAAC;AAEV,aAAW,gBAAgB;AAE3B,MAAI,aAAa,UACf,qDACE,MAAM,YACN,WAAW,SACX,aAAa,UACd,CAAC,MAAM;EAEV,MAAM,0CACE,CACJ,GAAG,WAAW,SACd,sDAAe,CAAC,GAAG,UAAU,WAAW,CAAC,IAAIC,gBAAI,QAAQ,MAAM,CAAC,CAAC,CAClE,EACD;GAAC;GAAU;GAAQ;GAAY;GAAM,CACtC;EAED,MAAM,8EACkB,gBAAgB,MAAM,WAAW,EACvD,CAAC,gBAAgB,MAAM,WAAW,CACnC;AAED,wDACE,WACA,CAAC,CAAC,WAAW,SAAS,GAAG,MAAM,IAAI,GAAG,WAAW,SAAS,OAC3D;AACD,wDAAe,WAAW,QAAQ,OAAO;AAEzC,MAAI,CAAC,UAAW,aAAY;EAE5B,MAAM,cAAc;GAAE,GAAG;GAAc;GAAW;GAAU;AAE5D,SACE,4CAAC;GAAmB,OAAO,WAAW;cACpC,2CAAC;IAAiB;IAAgB;IAAqB;KAAc,EAEpE,WAAW,CAAC,iBACX,2CAACE;IAAU;IAAK,GAAI;KAAe,GAEnC,2CAAC;IAAe;IAAK,GAAI;KAAe;IAEvB;GAEvB;AAEF,iBAAgB,cAAc,eAAe;AAE7C,QAAO"}
1
+ {"version":3,"file":"styled.cjs","names":["Insertion: FC<InsertionProps>","createContext","getDisplayName","createShouldForwardProp","props","className: string | undefined","useSystem","useTheme","useComponentStyle","forwardProps","css","colorScheme","Slot"],"sources":["../../../../src/core/system/styled.tsx"],"sourcesContent":["\"use client\"\n\nimport type { EmotionCache, SerializedStyles } from \"@emotion/utils\"\nimport type { FC } from \"react\"\nimport type { Dict } from \"../../utils\"\nimport type { As, ShouldForwardProp, StyledComponent } from \"../components\"\nimport type { CSSModifierObject, CSSPropObject } from \"../css\"\nimport type {\n ColorScheme,\n ComponentStyle,\n System,\n UsageTheme,\n} from \"./index.types\"\nimport { withEmotionCache } from \"@emotion/react\"\nimport { serializeStyles } from \"@emotion/serialize\"\nimport { useInsertionEffectAlwaysWithSyncFallback } from \"@emotion/use-insertion-effect-with-fallbacks\"\nimport {\n getRegisteredStyles,\n insertStyles,\n registerStyles,\n} from \"@emotion/utils\"\nimport { useMemo, useRef } from \"react\"\nimport isEqual from \"react-fast-compare\"\nimport { Slot } from \"../../components/slot\"\nimport {\n createContext,\n createdDom,\n cx,\n filterEmpty,\n filterUndefined,\n isString,\n isUndefined,\n runIfFn,\n splitObject,\n toArray,\n toKebabCase,\n} from \"../../utils\"\nimport {\n createShouldForwardProp,\n getDisplayName,\n useComponentStyle,\n} from \"../components\"\nimport { css } from \"../css\"\nimport { useSystem } from \"./system-provider\"\nimport { useTheme } from \"./theme-provider\"\n\ninterface InsertionProps {\n cache: EmotionCache\n htmlTag: boolean\n serialized: SerializedStyles\n}\n\nconst Insertion: FC<InsertionProps> = ({ cache, htmlTag, serialized }) => {\n registerStyles(cache, serialized, htmlTag)\n\n const style = useInsertionEffectAlwaysWithSyncFallback(() =>\n insertStyles(cache, serialized, htmlTag),\n )\n\n if (!createdDom() && !isUndefined(style)) {\n let className = serialized.name\n let next = serialized.next\n\n while (next !== undefined) {\n className = cx(className, next.name)\n next = next.next\n }\n\n return (\n <style\n data-emotion={cx(cache.key, className)}\n dangerouslySetInnerHTML={{ __html: style }}\n nonce={cache.sheet.nonce}\n />\n )\n } else {\n return null\n }\n}\n\nconst useSplitProps = <Y extends Dict, M extends Dict>(\n props: Dict,\n shouldForwardProp?: ShouldForwardProp,\n) => {\n const propsRef = useRef(props)\n\n if (!isEqual(propsRef.current, props)) propsRef.current = props\n\n const computedProps = propsRef.current\n\n return useMemo(\n () => splitObject<Y, M>(computedProps, shouldForwardProp),\n [computedProps, shouldForwardProp],\n )\n}\n\nexport const [ColorSchemeContext, useColorSchemeContext] =\n createContext<ColorScheme>({\n name: \"ColorSchemeContext\",\n strict: false,\n })\n\nexport interface StyledOptions<\n Y extends CSSPropObject = CSSPropObject,\n M extends CSSModifierObject = CSSModifierObject,\n D extends CSSModifierObject = CSSModifierObject,\n H extends number | string | symbol = string,\n> extends Omit<ComponentStyle<Y, M, D>, \"className\"> {\n className?: ((system: System) => string) | string\n displayName?: string\n forwardAsChild?: boolean\n name?: string\n shouldForwardProp?: boolean | ShouldForwardProp\n target?: string\n forwardProps?: string[]\n transferProps?: H[]\n}\n\nexport function createStyled<\n Y extends As,\n M extends object = {},\n D extends CSSPropObject = CSSPropObject,\n H extends CSSModifierObject = CSSModifierObject,\n R extends CSSModifierObject = CSSModifierObject,\n>(\n el: Y,\n {\n base,\n compounds,\n props,\n sizes,\n variants,\n defaultProps,\n transferProps,\n ...options\n }: StyledOptions<D, H, R, keyof M> = {},\n) {\n const displayName = options.displayName ?? getDisplayName(options.name, \"\")\n const shouldForwardProp = !options.shouldForwardProp\n ? createShouldForwardProp(options.forwardProps)\n : undefined\n const style = filterUndefined({\n base,\n compounds,\n props,\n sizes,\n variants,\n defaultProps,\n })\n\n const StyledComponent = withEmotionCache<Dict>(function (\n { as: Component = el, asChild, children, ...props },\n cache,\n ref,\n ) {\n let className: string | undefined = \"\"\n\n const system = useSystem()\n const { theme } = useTheme<UsageTheme>()\n const componentStyleOptions = {\n className: system.utils.getClassName(\n runIfFn(options.className, system) ?? toKebabCase(options.name ?? \"\"),\n ),\n style,\n transferProps,\n }\n const registered = useRef<string[]>([])\n const htmlTag = isString(Component)\n const forwardAsChild =\n options.forwardAsChild || options.forwardProps?.includes(\"asChild\")\n const [omittedProps, styleProps] = useSplitProps(props, shouldForwardProp)\n const [, rest] = useComponentStyle<any, {}>(\n omittedProps,\n componentStyleOptions,\n )\n const [cssArray, colorScheme, forwardProps] = useMemo(() => {\n const { css, colorScheme, ...forwardProps } = rest\n\n return [toArray(css), colorScheme, forwardProps]\n }, [rest])\n\n styleProps.colorScheme ??= colorScheme\n\n if (forwardProps.className)\n className = getRegisteredStyles(\n cache.registered,\n registered.current,\n forwardProps.className,\n ).trim()\n\n const interpolations = useMemo(\n () => [\n ...registered.current,\n ...filterEmpty([...cssArray, styleProps].map(css(system, theme))),\n ],\n [cssArray, system, styleProps, theme],\n )\n\n const serialized = useMemo(\n () => serializeStyles(interpolations, cache.registered),\n [interpolations, cache.registered],\n )\n\n className = cx(\n className,\n !!serialized.styles ? `${cache.key}-${serialized.name}` : undefined,\n )\n className = cx(className, options.target)\n\n if (!className) className = undefined\n\n const mergedProps = { ...forwardProps, className, children }\n\n return (\n <ColorSchemeContext value={styleProps.colorScheme}>\n <Insertion cache={cache} htmlTag={htmlTag} serialized={serialized} />\n\n {asChild && !forwardAsChild ? (\n <Slot ref={ref} {...mergedProps} />\n ) : (\n <Component ref={ref} {...mergedProps} />\n )}\n </ColorSchemeContext>\n )\n }) as StyledComponent<Y, M>\n\n StyledComponent.displayName = displayName || \"StyledComponent\"\n\n return StyledComponent\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAMA,aAAiC,EAAE,OAAO,SAAS,iBAAiB;AACxE,oCAAe,OAAO,YAAY,QAAQ;CAE1C,MAAM,0IACS,OAAO,YAAY,QAAQ,CACzC;AAED,KAAI,oDAAa,IAAI,oDAAa,MAAM,EAAE;EACxC,IAAI,YAAY,WAAW;EAC3B,IAAI,OAAO,WAAW;AAEtB,SAAO,SAAS,QAAW;AACzB,yDAAe,WAAW,KAAK,KAAK;AACpC,UAAO,KAAK;;AAGd,SACE,2CAAC;GACC,0DAAiB,MAAM,KAAK,UAAU;GACtC,yBAAy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mDAASC,MAAI;IAAEC;IAAaF;IAAa;KAC/C,CAAC,KAAK,CAAC;AAEV,aAAW,gBAAgB;AAE3B,MAAI,aAAa,UACf,qDACE,MAAM,YACN,WAAW,SACX,aAAa,UACd,CAAC,MAAM;EAEV,MAAM,0CACE,CACJ,GAAG,WAAW,SACd,sDAAe,CAAC,GAAG,UAAU,WAAW,CAAC,IAAIC,gBAAI,QAAQ,MAAM,CAAC,CAAC,CAClE,EACD;GAAC;GAAU;GAAQ;GAAY;GAAM,CACtC;EAED,MAAM,8EACkB,gBAAgB,MAAM,WAAW,EACvD,CAAC,gBAAgB,MAAM,WAAW,CACnC;AAED,wDACE,WACA,CAAC,CAAC,WAAW,SAAS,GAAG,MAAM,IAAI,GAAG,WAAW,SAAS,OAC3D;AACD,wDAAe,WAAW,QAAQ,OAAO;AAEzC,MAAI,CAAC,UAAW,aAAY;EAE5B,MAAM,cAAc;GAAE,GAAG;GAAc;GAAW;GAAU;AAE5D,SACE,4CAAC;GAAmB,OAAO,WAAW;cACpC,2CAAC;IAAiB;IAAgB;IAAqB;KAAc,EAEpE,WAAW,CAAC,iBACX,2CAACE;IAAU;IAAK,GAAI;KAAe,GAEnC,2CAAC;IAAe;IAAK,GAAI;KAAe;IAEvB;GAEvB;AAEF,iBAAgB,cAAc,eAAe;AAE7C,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-system-color-mode.cjs","names":["useEnvironment","useCallbackRef"],"sources":["../../../../src/core/system/use-system-color-mode.ts"],"sourcesContent":["\"use client\"\n\nimport type { ColorMode } from \"./index.types\"\nimport { useCallback, useEffect, useState } from \"react\"\nimport { fnAll, useCallbackRef, useSafeLayoutEffect } from \"../../utils\"\nimport { useEnvironment } from \"./environment-provider\"\n\nexport interface UseSystemColorModeProps {\n callback?: (colorMode: ColorMode) => void\n defaultColorMode: ColorMode\n}\n\n/**\n * `useSystemColorMode` is a custom hook that returns the current system color mode.\n */\nexport const useSystemColorMode = ({\n callback,\n defaultColorMode,\n}: UseSystemColorModeProps) => {\n const { getWindow } = useEnvironment()\n const callbackRef = useCallbackRef(callback)\n const [systemColorMode, setSystemColorMode] =\n useState<ColorMode>(defaultColorMode)\n\n const getSystemColorMode = useCallback(\n (fallback?: ColorMode) => {\n const mql = getWindow()?.matchMedia(\"(prefers-color-scheme: dark)\")\n const dark = mql?.matches ?? fallback === \"dark\"\n\n return dark ? \"dark\" : \"light\"\n },\n [getWindow],\n )\n\n const systemColorModeObserver = useCallback(\n (func: (cm: ColorMode) => void) => {\n const mql = getWindow()?.matchMedia(\"(prefers-color-scheme: dark)\")\n\n const listener = (e: MediaQueryListEvent) => {\n func(e.matches ? \"dark\" : \"light\")\n }\n\n if (typeof mql?.addListener === \"function\") {\n mql.addListener(listener)\n } else {\n mql?.addEventListener(\"change\", listener)\n }\n\n return () => {\n if (typeof mql?.removeListener === \"function\") {\n mql.removeListener(listener)\n } else {\n mql?.removeEventListener(\"change\", listener)\n }\n }\n },\n [getWindow],\n )\n\n useSafeLayoutEffect(() => {\n setSystemColorMode(getSystemColorMode())\n }, [getSystemColorMode])\n\n useEffect(() => {\n return systemColorModeObserver(fnAll(setSystemColorMode, callbackRef))\n }, [systemColorModeObserver, getSystemColorMode, callbackRef])\n\n return { getSystemColorMode, systemColorMode }\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAa,sBAAsB,EACjC,UACA,uBAC6B;CAC7B,MAAM,EAAE,cAAcA,6CAAgB;CACtC,MAAM,cAAcC,2BAAe,SAAS;CAC5C,MAAM,CAAC,iBAAiB,0CACF,iBAAiB;CAEvC,MAAM,6CACH,aAAyB;AAIxB,UAHY,WAAW,EAAE,WAAW,+BAA+B,GACjD,WAAW,aAAa,SAE5B,SAAS;IAEzB,CAAC,UAAU,CACZ;CAED,MAAM,kDACH,SAAkC;EACjC,MAAM,MAAM,WAAW,EAAE,WAAW,+BAA+B;EAEnE,MAAM,YAAY,MAA2B;AAC3C,QAAK,EAAE,UAAU,SAAS,QAAQ;;AAGpC,MAAI,OAAO,KAAK,gBAAgB,WAC9B,KAAI,YAAY,SAAS;MAEzB,MAAK,iBAAiB,UAAU,SAAS;AAG3C,eAAa;AACX,OAAI,OAAO,KAAK,mBAAmB,WACjC,KAAI,eAAe,SAAS;OAE5B,MAAK,oBAAoB,UAAU,SAAS;;IAIlD,CAAC,UAAU,CACZ;AAED,0CAA0B;AACxB,qBAAmB,oBAAoB,CAAC;IACvC,CAAC,mBAAmB,CAAC;AAExB,4BAAgB;AACd,SAAO,qEAA8B,oBAAoB,YAAY,CAAC;IACrE;EAAC;EAAyB;EAAoB;EAAY,CAAC;AAE9D,QAAO;EAAE;EAAoB;EAAiB"}
1
+ {"version":3,"file":"use-system-color-mode.cjs","names":["useEnvironment","useCallbackRef"],"sources":["../../../../src/core/system/use-system-color-mode.ts"],"sourcesContent":["\"use client\"\n\nimport type { ColorMode } from \"./index.types\"\nimport { useCallback, useEffect, useState } from \"react\"\nimport { fnAll, useCallbackRef, useSafeLayoutEffect } from \"../../utils\"\nimport { useEnvironment } from \"./environment-provider\"\n\nexport interface UseSystemColorModeProps {\n defaultColorMode: ColorMode\n callback?: (colorMode: ColorMode) => void\n}\n\n/**\n * `useSystemColorMode` is a custom hook that returns the current system color mode.\n */\nexport const useSystemColorMode = ({\n callback,\n defaultColorMode,\n}: UseSystemColorModeProps) => {\n const { getWindow } = useEnvironment()\n const callbackRef = useCallbackRef(callback)\n const [systemColorMode, setSystemColorMode] =\n useState<ColorMode>(defaultColorMode)\n\n const getSystemColorMode = useCallback(\n (fallback?: ColorMode) => {\n const mql = getWindow()?.matchMedia(\"(prefers-color-scheme: dark)\")\n const dark = mql?.matches ?? fallback === \"dark\"\n\n return dark ? \"dark\" : \"light\"\n },\n [getWindow],\n )\n\n const systemColorModeObserver = useCallback(\n (func: (cm: ColorMode) => void) => {\n const mql = getWindow()?.matchMedia(\"(prefers-color-scheme: dark)\")\n\n const listener = (e: MediaQueryListEvent) => {\n func(e.matches ? \"dark\" : \"light\")\n }\n\n if (typeof mql?.addListener === \"function\") {\n mql.addListener(listener)\n } else {\n mql?.addEventListener(\"change\", listener)\n }\n\n return () => {\n if (typeof mql?.removeListener === \"function\") {\n mql.removeListener(listener)\n } else {\n mql?.removeEventListener(\"change\", listener)\n }\n }\n },\n [getWindow],\n )\n\n useSafeLayoutEffect(() => {\n setSystemColorMode(getSystemColorMode())\n }, [getSystemColorMode])\n\n useEffect(() => {\n return systemColorModeObserver(fnAll(setSystemColorMode, callbackRef))\n }, [systemColorModeObserver, getSystemColorMode, callbackRef])\n\n return { getSystemColorMode, systemColorMode }\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAa,sBAAsB,EACjC,UACA,uBAC6B;CAC7B,MAAM,EAAE,cAAcA,6CAAgB;CACtC,MAAM,cAAcC,2BAAe,SAAS;CAC5C,MAAM,CAAC,iBAAiB,0CACF,iBAAiB;CAEvC,MAAM,6CACH,aAAyB;AAIxB,UAHY,WAAW,EAAE,WAAW,+BAA+B,GACjD,WAAW,aAAa,SAE5B,SAAS;IAEzB,CAAC,UAAU,CACZ;CAED,MAAM,kDACH,SAAkC;EACjC,MAAM,MAAM,WAAW,EAAE,WAAW,+BAA+B;EAEnE,MAAM,YAAY,MAA2B;AAC3C,QAAK,EAAE,UAAU,SAAS,QAAQ;;AAGpC,MAAI,OAAO,KAAK,gBAAgB,WAC9B,KAAI,YAAY,SAAS;MAEzB,MAAK,iBAAiB,UAAU,SAAS;AAG3C,eAAa;AACX,OAAI,OAAO,KAAK,mBAAmB,WACjC,KAAI,eAAe,SAAS;OAE5B,MAAK,oBAAoB,UAAU,SAAS;;IAIlD,CAAC,UAAU,CACZ;AAED,0CAA0B;AACxB,qBAAmB,oBAAoB,CAAC;IACvC,CAAC,mBAAmB,CAAC;AAExB,4BAAgB;AACd,SAAO,qEAA8B,oBAAoB,YAAY,CAAC;IACrE;EAAC;EAAyB;EAAoB;EAAY,CAAC;AAE9D,QAAO;EAAE;EAAoB;EAAiB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["useMounted"],"sources":["../../../../src/hooks/use-async/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { DependencyList } from \"react\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\nimport { useMounted } from \"../use-mounted\"\n\nexport type FunctionReturningPromise = (...args: any[]) => Promise<any>\n\n/**\n * `useAsync` is a custom hook that executes an asynchronous function and tracks its state.\n *\n * @see https://yamada-ui.com/docs/hooks/use-async\n */\nexport function useAsync<Y extends FunctionReturningPromise>(\n func: Y,\n deps: DependencyList = [],\n) {\n const [state, callback] = useAsyncFunc(func, deps, { loading: true })\n\n useEffect(() => {\n callback()\n }, [callback])\n\n return state\n}\n\nexport type AsyncState<Y> =\n | {\n error: Error\n loading: false\n value?: undefined\n }\n | {\n error?: Error | undefined\n loading: true\n value?: Y\n }\n | {\n error?: undefined\n loading: boolean\n value?: undefined\n }\n | {\n error?: undefined\n loading: false\n value: Y\n }\n\nexport type PromiseType<P extends Promise<any>> =\n P extends Promise<infer Y> ? Y : never\n\ntype StateFromFunctionReturningPromise<Y extends FunctionReturningPromise> =\n AsyncState<PromiseType<ReturnType<Y>>>\n\nexport type AsyncFnReturn<\n Y extends FunctionReturningPromise = FunctionReturningPromise,\n> = [StateFromFunctionReturningPromise<Y>, Y]\n\nexport function useAsyncFunc<Y extends FunctionReturningPromise>(\n func: Y,\n deps: DependencyList = [],\n initialState: StateFromFunctionReturningPromise<Y> = { loading: false },\n): AsyncFnReturn<Y> {\n const lastCallId = useRef(0)\n const mounted = useMounted()\n const [state, setState] =\n useState<StateFromFunctionReturningPromise<Y>>(initialState)\n\n const callback = useCallback(\n (...args: Parameters<Y>): ReturnType<Y> => {\n const callId = ++lastCallId.current\n\n if (!state.loading)\n setState((prevState) => ({ ...prevState, loading: true }))\n\n return func(...args).then(\n (value) => {\n if (mounted() && callId === lastCallId.current)\n setState({ loading: false, value })\n\n return value\n },\n (error) => {\n if (mounted() && callId === lastCallId.current)\n setState({ error, loading: false })\n\n return error\n },\n ) as ReturnType<Y>\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n deps,\n )\n\n return [state, callback as unknown as Y]\n}\n\nexport type AsyncStateRetry<Y> = AsyncState<Y> & {\n retry(): void\n}\n\nexport function useAsyncRetry<Y>(\n func: () => Promise<Y>,\n deps: DependencyList = [],\n) {\n const [attempt, setAttempt] = useState<number>(0)\n const state = useAsync(func, [...deps, attempt])\n\n const stateLoading = state.loading\n\n const retry = useCallback(() => {\n if (stateLoading) return\n\n setAttempt((currentAttempt) => currentAttempt + 1)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [...deps, stateLoading])\n\n return { ...state, retry }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,SACd,MACA,OAAuB,EAAE,EACzB;CACA,MAAM,CAAC,OAAO,YAAY,aAAa,MAAM,MAAM,EAAE,SAAS,MAAM,CAAC;AAErE,4BAAgB;AACd,YAAU;IACT,CAAC,SAAS,CAAC;AAEd,QAAO;;AAmCT,SAAgB,aACd,MACA,OAAuB,EAAE,EACzB,eAAqD,EAAE,SAAS,OAAO,EACrD;CAClB,MAAM,+BAAoB,EAAE;CAC5B,MAAM,UAAUA,4CAAY;CAC5B,MAAM,CAAC,OAAO,gCACmC,aAAa;AA4B9D,QAAO,CAAC,+BAzBL,GAAG,SAAuC;EACzC,MAAM,SAAS,EAAE,WAAW;AAE5B,MAAI,CAAC,MAAM,QACT,WAAU,eAAe;GAAE,GAAG;GAAW,SAAS;GAAM,EAAE;AAE5D,SAAO,KAAK,GAAG,KAAK,CAAC,MAClB,UAAU;AACT,OAAI,SAAS,IAAI,WAAW,WAAW,QACrC,UAAS;IAAE,SAAS;IAAO;IAAO,CAAC;AAErC,UAAO;MAER,UAAU;AACT,OAAI,SAAS,IAAI,WAAW,WAAW,QACrC,UAAS;IAAE;IAAO,SAAS;IAAO,CAAC;AAErC,UAAO;IAEV;IAGH,KACD,CAEuC;;AAO1C,SAAgB,cACd,MACA,OAAuB,EAAE,EACzB;CACA,MAAM,CAAC,SAAS,kCAA+B,EAAE;CACjD,MAAM,QAAQ,SAAS,MAAM,CAAC,GAAG,MAAM,QAAQ,CAAC;CAEhD,MAAM,eAAe,MAAM;CAE3B,MAAM,qCAA0B;AAC9B,MAAI,aAAc;AAElB,cAAY,mBAAmB,iBAAiB,EAAE;IAEjD,CAAC,GAAG,MAAM,aAAa,CAAC;AAE3B,QAAO;EAAE,GAAG;EAAO;EAAO"}
1
+ {"version":3,"file":"index.cjs","names":["useMounted"],"sources":["../../../../src/hooks/use-async/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { DependencyList } from \"react\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\nimport { useMounted } from \"../use-mounted\"\n\nexport type FunctionReturningPromise = (...args: any[]) => Promise<any>\n\n/**\n * `useAsync` is a custom hook that executes an asynchronous function and tracks its state.\n *\n * @see https://yamada-ui.com/docs/hooks/use-async\n */\nexport function useAsync<Y extends FunctionReturningPromise>(\n func: Y,\n deps: DependencyList = [],\n) {\n const [state, callback] = useAsyncFunc(func, deps, { loading: true })\n\n useEffect(() => {\n callback()\n }, [callback])\n\n return state\n}\n\nexport type AsyncState<Y> =\n | {\n error: Error\n loading: false\n value?: undefined\n }\n | {\n loading: boolean\n error?: undefined\n value?: undefined\n }\n | {\n loading: false\n value: Y\n error?: undefined\n }\n | {\n loading: true\n error?: Error | undefined\n value?: Y\n }\n\nexport type PromiseType<P extends Promise<any>> =\n P extends Promise<infer Y> ? Y : never\n\ntype StateFromFunctionReturningPromise<Y extends FunctionReturningPromise> =\n AsyncState<PromiseType<ReturnType<Y>>>\n\nexport type AsyncFnReturn<\n Y extends FunctionReturningPromise = FunctionReturningPromise,\n> = [StateFromFunctionReturningPromise<Y>, Y]\n\nexport function useAsyncFunc<Y extends FunctionReturningPromise>(\n func: Y,\n deps: DependencyList = [],\n initialState: StateFromFunctionReturningPromise<Y> = { loading: false },\n): AsyncFnReturn<Y> {\n const lastCallId = useRef(0)\n const mounted = useMounted()\n const [state, setState] =\n useState<StateFromFunctionReturningPromise<Y>>(initialState)\n\n const callback = useCallback(\n (...args: Parameters<Y>): ReturnType<Y> => {\n const callId = ++lastCallId.current\n\n if (!state.loading)\n setState((prevState) => ({ ...prevState, loading: true }))\n\n return func(...args).then(\n (value) => {\n if (mounted() && callId === lastCallId.current)\n setState({ loading: false, value })\n\n return value\n },\n (error) => {\n if (mounted() && callId === lastCallId.current)\n setState({ error, loading: false })\n\n return error\n },\n ) as ReturnType<Y>\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n deps,\n )\n\n return [state, callback as unknown as Y]\n}\n\nexport type AsyncStateRetry<Y> = AsyncState<Y> & {\n retry(): void\n}\n\nexport function useAsyncRetry<Y>(\n func: () => Promise<Y>,\n deps: DependencyList = [],\n) {\n const [attempt, setAttempt] = useState<number>(0)\n const state = useAsync(func, [...deps, attempt])\n\n const stateLoading = state.loading\n\n const retry = useCallback(() => {\n if (stateLoading) return\n\n setAttempt((currentAttempt) => currentAttempt + 1)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [...deps, stateLoading])\n\n return { ...state, retry }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,SACd,MACA,OAAuB,EAAE,EACzB;CACA,MAAM,CAAC,OAAO,YAAY,aAAa,MAAM,MAAM,EAAE,SAAS,MAAM,CAAC;AAErE,4BAAgB;AACd,YAAU;IACT,CAAC,SAAS,CAAC;AAEd,QAAO;;AAmCT,SAAgB,aACd,MACA,OAAuB,EAAE,EACzB,eAAqD,EAAE,SAAS,OAAO,EACrD;CAClB,MAAM,+BAAoB,EAAE;CAC5B,MAAM,UAAUA,4CAAY;CAC5B,MAAM,CAAC,OAAO,gCACmC,aAAa;AA4B9D,QAAO,CAAC,+BAzBL,GAAG,SAAuC;EACzC,MAAM,SAAS,EAAE,WAAW;AAE5B,MAAI,CAAC,MAAM,QACT,WAAU,eAAe;GAAE,GAAG;GAAW,SAAS;GAAM,EAAE;AAE5D,SAAO,KAAK,GAAG,KAAK,CAAC,MAClB,UAAU;AACT,OAAI,SAAS,IAAI,WAAW,WAAW,QACrC,UAAS;IAAE,SAAS;IAAO;IAAO,CAAC;AAErC,UAAO;MAER,UAAU;AACT,OAAI,SAAS,IAAI,WAAW,WAAW,QACrC,UAAS;IAAE;IAAO,SAAS;IAAO,CAAC;AAErC,UAAO;IAEV;IAGH,KACD,CAEuC;;AAO1C,SAAgB,cACd,MACA,OAAuB,EAAE,EACzB;CACA,MAAM,CAAC,SAAS,kCAA+B,EAAE;CACjD,MAAM,QAAQ,SAAS,MAAM,CAAC,GAAG,MAAM,QAAQ,CAAC;CAEhD,MAAM,eAAe,MAAM;CAE3B,MAAM,qCAA0B;AAC9B,MAAI,aAAc;AAElB,cAAY,mBAAmB,iBAAiB,EAAE;IAEjD,CAAC,GAAG,MAAM,aAAa,CAAC;AAE3B,QAAO;EAAE,GAAG;EAAO;EAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../../../src/hooks/use-boolean/index.ts"],"sourcesContent":["\"use client\"\n\nimport { useCallback, useState } from \"react\"\n\n/**\n * `useBoolean` is a custom hook used to manage boolean values using `on`, `off`, and `toggle` functions.\n *\n * @see https://yamada-ui.com/docs/hooks/use-boolean\n */\nexport const useBoolean = (init = false): UseBooleanReturn => {\n const [flg, setFlg] = useState<boolean>(init)\n\n const on = useCallback(() => setFlg(true), [])\n\n const off = useCallback(() => setFlg(false), [])\n\n const toggle = useCallback(() => setFlg((prev) => !prev), [])\n\n return [flg, { off, toggle, on }]\n}\n\nexport type UseBooleanReturn = [\n flg: boolean,\n setFlg: { off: () => void; toggle: () => void; on: () => void },\n]\n"],"mappings":";;;;;;;;;;;AASA,MAAa,cAAc,OAAO,UAA4B;CAC5D,MAAM,CAAC,KAAK,8BAA4B,KAAK;CAE7C,MAAM,kCAAuB,OAAO,KAAK,EAAE,EAAE,CAAC;AAM9C,QAAO,CAAC,KAAK;EAAE,kCAJe,OAAO,MAAM,EAAE,EAAE,CAAC;EAI5B,qCAFa,QAAQ,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC;EAEjC;EAAI,CAAC"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../../../src/hooks/use-boolean/index.ts"],"sourcesContent":["\"use client\"\n\nimport { useCallback, useState } from \"react\"\n\n/**\n * `useBoolean` is a custom hook used to manage boolean values using `on`, `off`, and `toggle` functions.\n *\n * @see https://yamada-ui.com/docs/hooks/use-boolean\n */\nexport const useBoolean = (init = false): UseBooleanReturn => {\n const [flg, setFlg] = useState<boolean>(init)\n\n const on = useCallback(() => setFlg(true), [])\n\n const off = useCallback(() => setFlg(false), [])\n\n const toggle = useCallback(() => setFlg((prev) => !prev), [])\n\n return [flg, { off, toggle, on }]\n}\n\nexport type UseBooleanReturn = [\n flg: boolean,\n setFlg: { off: () => void; on: () => void; toggle: () => void },\n]\n"],"mappings":";;;;;;;;;;;AASA,MAAa,cAAc,OAAO,UAA4B;CAC5D,MAAM,CAAC,KAAK,8BAA4B,KAAK;CAE7C,MAAM,kCAAuB,OAAO,KAAK,EAAE,EAAE,CAAC;AAM9C,QAAO,CAAC,KAAK;EAAE,kCAJe,OAAO,MAAM,EAAE,EAAE,CAAC;EAI5B,qCAFa,QAAQ,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC;EAEjC;EAAI,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["useEventListeners","mergeRefs"],"sources":["../../../../src/hooks/use-clickable/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { HTMLAttributes, KeyboardEvent, MouseEvent, Ref } from \"react\"\nimport type { StyledProps } from \"../../core\"\nimport { useCallback, useState } from \"react\"\nimport { dataAttr, isTouchDevice, mergeRefs } from \"../../utils\"\nimport { useEventListeners } from \"../use-event-listener\"\n\ntype Props<Y extends HTMLElement = HTMLElement> = Omit<\n HTMLAttributes<Y>,\n \"ref\" | \"size\" | keyof StyledProps\n>\n\nexport type UseClickableProps<\n Y extends HTMLElement = HTMLElement,\n M extends Props<Y> = Props<Y>,\n> = M & {\n /**\n * The ref for the element.\n */\n ref?: Ref<Y>\n /**\n * Whether or not trigger click on pressing `Enter`.\n *\n * @default true\n */\n clickOnEnter?: boolean\n /**\n * Whether or not trigger click on pressing `Space`.\n *\n * @default true\n */\n clickOnSpace?: boolean\n /**\n * If `true`, the element will be disabled. It will set the `disabled` HTML attribute.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * Disable the touch device behavior.\n *\n * @default true\n */\n disableTouchBehavior?: boolean\n /**\n * If `true` and isDisabled, the element will have only `aria-disabled` set to `true`.\n *\n * @default false\n */\n focusable?: boolean\n /**\n * Whether or not to focus the element when it is clicked.\n * If `true`, the element will receive focus upon click.\n *\n * @default true\n */\n focusOnClick?: boolean\n}\n\nconst isValidElement = (\n ev: KeyboardEvent | KeyboardEvent[\"nativeEvent\"],\n): boolean => {\n const { isContentEditable, tagName } = ev.target as HTMLElement\n\n return tagName !== \"INPUT\" && tagName !== \"TEXTAREA\" && !isContentEditable\n}\n\nexport const useClickable = <\n Y extends HTMLElement = HTMLElement,\n M extends Props<Y> = Props<Y>,\n>(\n {\n ref,\n clickOnEnter = true,\n clickOnSpace = true,\n disabled,\n disableTouchBehavior = true,\n focusable,\n focusOnClick = true,\n tabIndex: tabIndexProp,\n onClick: onClickProp,\n onKeyDown: onKeyDownProp,\n onKeyUp: onKeyUpProp,\n onMouseDown: onMouseDownProp,\n onMouseLeave: onMouseLeaveProp,\n onMouseOver: onMouseOverProp,\n onMouseUp: onMouseUpProp,\n ...props\n }: UseClickableProps<Y, M> = {} as UseClickableProps<Y, M>,\n) => {\n const [button, setButton] = useState<boolean>(true)\n const [pressed, setPressed] = useState<boolean>(false)\n\n const listeners = useEventListeners()\n\n const tabIndex = button ? tabIndexProp : tabIndexProp || 0\n const trulyDisabled = disabled && !focusable\n\n const refCb = (node: any) => {\n if (!node) return\n\n if (node.tagName !== \"BUTTON\") setButton(false)\n }\n\n const onClick = useCallback(\n (ev: MouseEvent<Y>) => {\n if (disabled) {\n ev.stopPropagation()\n ev.preventDefault()\n\n return\n }\n\n if (focusOnClick) ev.currentTarget.focus()\n onClickProp?.(ev)\n },\n [disabled, focusOnClick, onClickProp],\n )\n\n const onDocumentKeyUp = useCallback(\n (ev: globalThis.KeyboardEvent) => {\n if (pressed && isValidElement(ev)) {\n ev.preventDefault()\n ev.stopPropagation()\n\n setPressed(false)\n\n listeners.remove(document, \"keyup\", onDocumentKeyUp, false)\n }\n },\n [pressed, listeners],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<Y>) => {\n onKeyDownProp?.(ev)\n\n if (disabled || ev.defaultPrevented || ev.metaKey) return\n\n if (!isValidElement(ev.nativeEvent) || button) return\n\n if (clickOnSpace && ev.key === \" \") {\n ev.preventDefault()\n setPressed(true)\n }\n\n if (clickOnEnter && ev.key === \"Enter\") {\n ev.preventDefault()\n ev.currentTarget.click()\n }\n\n listeners.add(document, \"keyup\", onDocumentKeyUp, false)\n },\n [\n disabled,\n button,\n onKeyDownProp,\n clickOnEnter,\n clickOnSpace,\n listeners,\n onDocumentKeyUp,\n ],\n )\n\n const onKeyUp = useCallback(\n (ev: KeyboardEvent<Y>) => {\n onKeyUpProp?.(ev)\n\n if (disabled || ev.defaultPrevented || ev.metaKey) return\n\n if (!isValidElement(ev.nativeEvent) || button) return\n\n if (clickOnSpace && ev.key === \" \") {\n ev.preventDefault()\n setPressed(false)\n\n ev.currentTarget.click()\n }\n },\n [clickOnSpace, button, disabled, onKeyUpProp],\n )\n\n const onDocumentMouseUp = useCallback(\n (ev: globalThis.MouseEvent) => {\n if (ev.button !== 0) return\n\n setPressed(false)\n\n listeners.remove(document, \"mouseup\", onDocumentMouseUp, false)\n },\n [listeners],\n )\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<Y>) => {\n if (ev.button !== 0) return\n\n if (disabled) {\n ev.stopPropagation()\n ev.preventDefault()\n\n return\n }\n\n if (!button) setPressed(true)\n\n if (focusOnClick) ev.currentTarget.focus({ preventScroll: true })\n\n listeners.add(document, \"mouseup\", onDocumentMouseUp, false)\n\n onMouseDownProp?.(ev)\n },\n [\n disabled,\n button,\n onMouseDownProp,\n listeners,\n onDocumentMouseUp,\n focusOnClick,\n ],\n )\n\n const onMouseUp = useCallback(\n (ev: MouseEvent<Y>) => {\n if (ev.button !== 0) return\n\n if (!button) setPressed(false)\n\n onMouseUpProp?.(ev)\n },\n [onMouseUpProp, button],\n )\n\n const onMouseOver = useCallback(\n (ev: MouseEvent<Y>) => {\n if (disabled) {\n ev.preventDefault()\n\n return\n }\n\n if (disableTouchBehavior && isTouchDevice()) return\n\n onMouseOverProp?.(ev)\n },\n [disabled, onMouseOverProp, disableTouchBehavior],\n )\n\n const onMouseLeave = useCallback(\n (ev: MouseEvent<Y>) => {\n if (pressed) {\n ev.preventDefault()\n\n setPressed(false)\n }\n\n if (disableTouchBehavior && isTouchDevice()) return\n\n onMouseLeaveProp?.(ev)\n },\n [pressed, onMouseLeaveProp, disableTouchBehavior],\n )\n\n if (button) {\n return {\n ...props,\n ref: mergeRefs(ref, refCb),\n type: \"button\" as const,\n \"aria-disabled\": trulyDisabled ? undefined : disabled,\n disabled: trulyDisabled,\n onClick: onClick,\n onKeyDown: onKeyDownProp,\n onKeyUp: onKeyUpProp,\n onMouseDown: onMouseDownProp,\n onMouseLeave: onMouseLeaveProp,\n onMouseOver: onMouseOverProp,\n onMouseUp: onMouseUpProp,\n }\n } else {\n return {\n ...props,\n ref: mergeRefs(ref, refCb),\n \"aria-disabled\": disabled ? (\"true\" as const) : undefined,\n \"data-active\": dataAttr(pressed),\n role: \"button\",\n tabIndex: trulyDisabled ? undefined : tabIndex,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseLeave,\n onMouseOver,\n onMouseUp,\n }\n }\n}\n\nexport type UseClickableReturn = ReturnType<typeof useClickable>\n"],"mappings":";;;;;;;;;AA4DA,MAAM,kBACJ,OACY;CACZ,MAAM,EAA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AEnB,cAAW,MAAM;;AAGnB,MAAI,8EAAuC,CAAE;AAE7C,qBAAmB,GAAG;IAExB;EAAC;EAAS;EAAkB;EAAqB,CAClD;AAED,KAAI,OACF,QAAO;EACL,GAAG;EACH,KAAKC,sBAAU,KAAK,MAAM;EAC1B,MAAM;EACN,iBAAiB,gBAAgB,SAAY;EAC7C,UAAU;EACD;EACT,WAAW;EACX,SAAS;EACT,aAAa;EACb,cAAc;EACd,aAAa;EACb,WAAW;EACZ;KAED,QAAO;EACL,GAAG;EACH,KAAKA,sBAAU,KAAK,MAAM;EAC1B,iBAAiB,WAAY,SAAmB;EAChD,+DAAwB,QAAQ;EAChC,MAAM;EACN,UAAU,gBAAgB,SAAY;EACtC;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"index.cjs","names":["useEventListeners","mergeRefs"],"sources":["../../../../src/hooks/use-clickable/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { HTMLAttributes, KeyboardEvent, MouseEvent, Ref } from \"react\"\nimport type { StyledProps } from \"../../core\"\nimport { useCallback, useState } from \"react\"\nimport { dataAttr, isTouchDevice, mergeRefs } from \"../../utils\"\nimport { useEventListeners } from \"../use-event-listener\"\n\ntype Props<Y extends HTMLElement = HTMLElement> = Omit<\n HTMLAttributes<Y>,\n \"ref\" | \"size\" | keyof StyledProps\n>\n\nexport type UseClickableProps<\n Y extends HTMLElement = HTMLElement,\n M extends Props<Y> = Props<Y>,\n> = M & {\n /**\n * Whether or not trigger click on pressing `Enter`.\n *\n * @default true\n */\n clickOnEnter?: boolean\n /**\n * Whether or not trigger click on pressing `Space`.\n *\n * @default true\n */\n clickOnSpace?: boolean\n /**\n * If `true`, the element will be disabled. It will set the `disabled` HTML attribute.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * Disable the touch device behavior.\n *\n * @default true\n */\n disableTouchBehavior?: boolean\n /**\n * If `true` and isDisabled, the element will have only `aria-disabled` set to `true`.\n *\n * @default false\n */\n focusable?: boolean\n /**\n * Whether or not to focus the element when it is clicked.\n * If `true`, the element will receive focus upon click.\n *\n * @default true\n */\n focusOnClick?: boolean\n /**\n * The ref for the element.\n */\n ref?: Ref<Y>\n}\n\nconst isValidElement = (\n ev: KeyboardEvent | KeyboardEvent[\"nativeEvent\"],\n): boolean => {\n const { isContentEditable, tagName } = ev.target as HTMLElement\n\n return tagName !== \"INPUT\" && tagName !== \"TEXTAREA\" && !isContentEditable\n}\n\nexport const useClickable = <\n Y extends HTMLElement = HTMLElement,\n M extends Props<Y> = Props<Y>,\n>(\n {\n ref,\n clickOnEnter = true,\n clickOnSpace = true,\n disabled,\n disableTouchBehavior = true,\n focusable,\n focusOnClick = true,\n tabIndex: tabIndexProp,\n onClick: onClickProp,\n onKeyDown: onKeyDownProp,\n onKeyUp: onKeyUpProp,\n onMouseDown: onMouseDownProp,\n onMouseLeave: onMouseLeaveProp,\n onMouseOver: onMouseOverProp,\n onMouseUp: onMouseUpProp,\n ...props\n }: UseClickableProps<Y, M> = {} as UseClickableProps<Y, M>,\n) => {\n const [button, setButton] = useState<boolean>(true)\n const [pressed, setPressed] = useState<boolean>(false)\n\n const listeners = useEventListeners()\n\n const tabIndex = button ? tabIndexProp : tabIndexProp || 0\n const trulyDisabled = disabled && !focusable\n\n const refCb = (node: any) => {\n if (!node) return\n\n if (node.tagName !== \"BUTTON\") setButton(false)\n }\n\n const onClick = useCallback(\n (ev: MouseEvent<Y>) => {\n if (disabled) {\n ev.stopPropagation()\n ev.preventDefault()\n\n return\n }\n\n if (focusOnClick) ev.currentTarget.focus()\n onClickProp?.(ev)\n },\n [disabled, focusOnClick, onClickProp],\n )\n\n const onDocumentKeyUp = useCallback(\n (ev: globalThis.KeyboardEvent) => {\n if (pressed && isValidElement(ev)) {\n ev.preventDefault()\n ev.stopPropagation()\n\n setPressed(false)\n\n listeners.remove(document, \"keyup\", onDocumentKeyUp, false)\n }\n },\n [pressed, listeners],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<Y>) => {\n onKeyDownProp?.(ev)\n\n if (disabled || ev.defaultPrevented || ev.metaKey) return\n\n if (!isValidElement(ev.nativeEvent) || button) return\n\n if (clickOnSpace && ev.key === \" \") {\n ev.preventDefault()\n setPressed(true)\n }\n\n if (clickOnEnter && ev.key === \"Enter\") {\n ev.preventDefault()\n ev.currentTarget.click()\n }\n\n listeners.add(document, \"keyup\", onDocumentKeyUp, false)\n },\n [\n disabled,\n button,\n onKeyDownProp,\n clickOnEnter,\n clickOnSpace,\n listeners,\n onDocumentKeyUp,\n ],\n )\n\n const onKeyUp = useCallback(\n (ev: KeyboardEvent<Y>) => {\n onKeyUpProp?.(ev)\n\n if (disabled || ev.defaultPrevented || ev.metaKey) return\n\n if (!isValidElement(ev.nativeEvent) || button) return\n\n if (clickOnSpace && ev.key === \" \") {\n ev.preventDefault()\n setPressed(false)\n\n ev.currentTarget.click()\n }\n },\n [clickOnSpace, button, disabled, onKeyUpProp],\n )\n\n const onDocumentMouseUp = useCallback(\n (ev: globalThis.MouseEvent) => {\n if (ev.button !== 0) return\n\n setPressed(false)\n\n listeners.remove(document, \"mouseup\", onDocumentMouseUp, false)\n },\n [listeners],\n )\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<Y>) => {\n if (ev.button !== 0) return\n\n if (disabled) {\n ev.stopPropagation()\n ev.preventDefault()\n\n return\n }\n\n if (!button) setPressed(true)\n\n if (focusOnClick) ev.currentTarget.focus({ preventScroll: true })\n\n listeners.add(document, \"mouseup\", onDocumentMouseUp, false)\n\n onMouseDownProp?.(ev)\n },\n [\n disabled,\n button,\n onMouseDownProp,\n listeners,\n onDocumentMouseUp,\n focusOnClick,\n ],\n )\n\n const onMouseUp = useCallback(\n (ev: MouseEvent<Y>) => {\n if (ev.button !== 0) return\n\n if (!button) setPressed(false)\n\n onMouseUpProp?.(ev)\n },\n [onMouseUpProp, button],\n )\n\n const onMouseOver = useCallback(\n (ev: MouseEvent<Y>) => {\n if (disabled) {\n ev.preventDefault()\n\n return\n }\n\n if (disableTouchBehavior && isTouchDevice()) return\n\n onMouseOverProp?.(ev)\n },\n [disabled, onMouseOverProp, disableTouchBehavior],\n )\n\n const onMouseLeave = useCallback(\n (ev: MouseEvent<Y>) => {\n if (pressed) {\n ev.preventDefault()\n\n setPressed(false)\n }\n\n if (disableTouchBehavior && isTouchDevice()) return\n\n onMouseLeaveProp?.(ev)\n },\n [pressed, onMouseLeaveProp, disableTouchBehavior],\n )\n\n if (button) {\n return {\n ...props,\n ref: mergeRefs(ref, refCb),\n type: \"button\" as const,\n \"aria-disabled\": trulyDisabled ? undefined : disabled,\n disabled: trulyDisabled,\n onClick: onClick,\n onKeyDown: onKeyDownProp,\n onKeyUp: onKeyUpProp,\n onMouseDown: onMouseDownProp,\n onMouseLeave: onMouseLeaveProp,\n onMouseOver: onMouseOverProp,\n onMouseUp: onMouseUpProp,\n }\n } else {\n return {\n ...props,\n ref: mergeRefs(ref, refCb),\n \"aria-disabled\": disabled ? (\"true\" as const) : undefined,\n \"data-active\": dataAttr(pressed),\n role: \"button\",\n tabIndex: trulyDisabled ? undefined : tabIndex,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseLeave,\n onMouseOver,\n onMouseUp,\n }\n }\n}\n\nexport type UseClickableReturn = ReturnType<typeof useClickable>\n"],"mappings":";;;;;;;;;AA4DA,MAAM,kBACJ,OACY;CACZ,MAAM,EAAE,mBAAmB,YAAY,GAAG;AAE1C,QAAO,YAAY,WAAW,YAAY,cAAc,CAAC;;AAG3D,MAAa,gBAIX,EACE,KACA,eAAe,MACf,eAAe,MACf,UACA,uBAAuB,MACvB,WACA,eAAe,MACf,UAAU,cACV,SAAS,aACT,WAAW,eACX,SAAS,aACT,aAAa,iBACb,cAAc,kBACd,aAAa,iBACb,WAAW,eACX,GAAG,UACwB,EAAE,KAC5B;CACH,MAAM,CAAC,QAAQ,iCAA+B,KAAK;CACnD,MAAM,CAAC,SAAS,kCAAgC,MAAM;CAEtD,MAAM,YAAYA,0DA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AAY,SAAmB;EAChD,+DAAwB,QAAQ;EAChC,MAAM;EACN,UAAU,gBAAgB,SAAY;EACtC;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["getValidChildren","isSomeElement","findChild","type","props","items","rest","label","index","createDescendants","createContext","usePopoverProps","useEnvironment","useDisclosure","isComposing","getTriggerProps: PropGetter","mergeRefs","getItemProps: PropGetter"],"sources":["../../../../src/hooks/use-combobox/index.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n JSXElementConstructor,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n RefObject,\n} from \"react\"\nimport type { UsePopoverProps } from \"../../components/popover\"\nimport type { HTMLProps, PropGetter, SimpleDirection } from \"../../core\"\nimport type { Descendant } from \"../use-descendants\"\nimport type { UseDisclosureProps } from \"../use-disclosure\"\nimport { useCallback, useId, useMemo, useRef } from \"react\"\nimport scrollIntoView from \"scroll-into-view-if-needed\"\nimport { usePopoverProps } from \"../../components/popover\"\nimport { useEnvironment } from \"../../core\"\nimport {\n ariaAttr,\n createContext,\n cx,\n dataAttr,\n findChild,\n getValidChildren,\n handlerAll,\n isComposing,\n isSomeElement,\n isUndefined,\n mergeRefs,\n runKeyAction,\n useUpdateEffect,\n} from \"../../utils\"\nimport { createDescendants } from \"../use-descendants\"\nimport { useDisclosure } from \"../use-disclosure\"\n\ninterface ComboboxSharedItem extends Omit<HTMLProps, \"children\" | \"value\"> {\n label: ReactNode\n}\n\nexport interface ComboboxItemWithValue extends ComboboxSharedItem {\n query?: string\n value?: string\n}\n\nexport interface ComboboxItemWithItems extends ComboboxSharedItem {\n items: ComboboxItemWithValue[]\n}\n\nexport type ComboboxItem = ComboboxItemWithItems | ComboboxItemWithValue\n\nexport interface CreateComboboxItemOptions {\n Group: JSXElementConstructor<any>\n Label: JSXElementConstructor<any>\n Option: JSXElementConstructor<any>\n}\n\nexport const createComboboxItem = (\n children: ReactNode,\n { Group, Label, Option }: CreateComboboxItemOptions,\n) => {\n const validChildren = getValidChildren(children)\n\n return validChildren\n .filter(\n ({ type }) => isSomeElement(type, Option) || isSomeElement(type, Group),\n )\n .map(({ type, props }) => {\n if (isSomeElement(type, Option)) {\n return { ...props, label: props.children }\n } else {\n const validChildren = getValidChildren(props.children)\n const label = findChild(validChildren, Label)\n\n return {\n ...props,\n items: validChildren\n .filter(({ type }) => isSomeElement(type, Option))\n .map(({ props }) => ({ ...props, label: props.children })),\n label: label?.props.children ?? props.label,\n }\n }\n })\n}\n\nexport interface CreateComboboxChildrenOptions {\n Empty?: JSXElementConstructor<any>\n Group: JSXElementConstructor<any>\n Option: JSXElementConstructor<any>\n}\n\nexport const createComboboxChildren = (\n items: ComboboxItem[],\n { Empty, Group, Option }: CreateComboboxChildrenOptions,\n) => {\n return items.map((item, index) => {\n if (\"data-empty\" in item && Empty) {\n const { label, ...rest } = item\n\n return (\n <Empty key={index} {...rest}>\n {label}\n </Empty>\n )\n } else if (\"items\" in item) {\n const { items = [], label, ...rest } = item\n\n return (\n <Group key={index} label={label} {...rest}>\n {items.map(({ label, ...rest }, index) => (\n <Option key={index} {...rest}>\n {label}\n </Option>\n ))}\n </Group>\n )\n } else {\n const { label, ...rest } = item\n\n return (\n <Option key={index} {...rest}>\n {label}\n </Option>\n )\n }\n })\n}\n\nexport interface ComboboxDescendantProps {\n id: string\n closeOnSelect?: boolean\n value?: string\n}\nexport type ComboboxDescendant = Descendant<\n HTMLDivElement,\n ComboboxDescendantProps\n>\n\nconst {\n DescendantsContext: ComboboxDescendantsContext,\n useDescendant: useComboboxDescendant,\n useDescendantRegister: useComboboxDescendantRegister,\n useDescendants: useComboboxDescendants,\n} = createDescendants<HTMLDivElement, ComboboxDescendantProps>()\n\nexport {\n ComboboxDescendantsContext,\n useComboboxDescendant,\n useComboboxDescendantRegister,\n useComboboxDescendants,\n}\n\ninterface ComboboxContext extends Pick<\n UseComboboxReturn,\n \"onActiveDescendant\" | \"onClose\" | \"onSelect\"\n> {}\n\nconst [ComboboxContext, useComboboxContext] = createContext<ComboboxContext>({\n name: \"ComboboxContext\",\n})\n\ninterface ComboboxGroupContext extends Pick<\n UseComboboxGroupReturn,\n \"getLabelProps\"\n> {}\n\nconst [ComboboxGroupContext, useComboboxGroupContext] =\n createContext<ComboboxGroupContext>({\n name: \"ComboboxGroupContext\",\n })\n\nexport {\n ComboboxContext,\n ComboboxGroupContext,\n useComboboxContext,\n useComboboxGroupContext,\n}\n\nexport interface UseComboboxProps\n extends\n Omit<HTMLProps, \"onChange\">,\n Omit<UseDisclosureProps, \"timing\">,\n Omit<\n UsePopoverProps,\n \"autoFocus\" | \"initialFocusRef\" | \"modal\" | \"transform\" | \"updateRef\"\n > {\n /**\n * If `true`, the list element will be closed when value is selected.\n *\n * @default true\n */\n closeOnSelect?: boolean\n /**\n * If `true`, the combobox will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The value to focus on when the combobox is opened.\n */\n initialFocusValue?: string\n /**\n * If `true`, the combobox will be opened when click on the field.\n *\n * @default true\n */\n openOnClick?: boolean\n /**\n * If `true`, the combobox will be opened when enter is pressed.\n *\n * @default true\n */\n openOnEnter?: boolean\n /**\n * If `true`, the combobox will be opened when space is pressed.\n *\n * @default true\n */\n openOnSpace?: boolean\n /**\n * If `true`, the combobox will be readonly.\n *\n * @default false\n */\n readOnly?: boolean\n /**\n * The `ref` of the element that should receive focus when selected.\n */\n selectFocusRef?: RefObject<HTMLElement | null>\n /**\n * If `true`, the item will be selected when space is pressed.\n *\n * @default true\n */\n selectOnSpace?: boolean\n /**\n * The callback invoked when value is selected.\n */\n onChange?: (value: string) => void\n}\n\nexport const useCombobox = (props: UseComboboxProps = {}) => {\n const [\n popoverProps,\n {\n \"aria-label\": ariaLabelProp,\n \"aria-labelledby\": ariaLabelledbyProp,\n closeOnSelect: closeOnSelectProp = true,\n defaultOpen,\n disabled,\n initialFocusValue,\n open: openProp,\n openOnClick = true,\n openOnEnter = true,\n openOnSpace = true,\n readOnly,\n selectFocusRef,\n selectOnSpace = true,\n onChange: onChangeProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n ...rest\n },\n ] = usePopoverProps(props, [\n \"disabled\",\n \"open\",\n \"defaultOpen\",\n \"onOpen\",\n \"onClose\",\n \"openOnClick\",\n ])\n const { getWindow } = useEnvironment()\n const interactive = !(readOnly || disabled)\n const triggerRef = useRef<HTMLDivElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const contentId = useId()\n const descendants = useComboboxDescendants()\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const activeDescendant = useRef<ComboboxDescendant | null>(null)\n const mergedPopoverProps = useMemo<UsePopoverProps>(\n () => ({\n autoFocus: false,\n matchWidth: true,\n openOnClick: false,\n ...popoverProps,\n disabled: !interactive,\n open,\n onClose,\n onOpen,\n }),\n [interactive, onClose, onOpen, open, popoverProps],\n )\n\n const onSelect = useCallback(\n (value?: string, closeOnSelect = closeOnSelectProp) => {\n const ref = selectFocusRef ?? triggerRef\n\n ref.current?.focus()\n\n if (!interactive || isUndefined(value)) return\n\n onChangeProp?.(value)\n\n if (!closeOnSelect) return\n\n onClose()\n },\n [closeOnSelectProp, interactive, onChangeProp, onClose, selectFocusRef],\n )\n\n const onScrollIntoView = useCallback(\n (descendant?: ComboboxDescendant, block: SimpleDirection = \"start\") => {\n if (!contentRef.current || !descendant) return\n\n const style = getWindow()?.getComputedStyle(contentRef.current)\n const padding =\n block === \"start\" ? style?.paddingBlockStart : style?.paddingBlockEnd\n const value = parseInt(padding ?? \"0px\")\n\n scrollIntoView(descendant.node, {\n behavior: (actions) =>\n actions.forEach(({ el, top }) => {\n el.scrollTop = block === \"start\" ? top - value : top + value\n }),\n block,\n boundary: contentRef.current,\n inline: \"nearest\",\n scrollMode: \"if-needed\",\n })\n },\n [getWindow],\n )\n\n const onActiveDescendant = useCallback(\n (descendant?: ComboboxDescendant) => {\n if (!triggerRef.current || !descendant || disabled) return\n\n triggerRef.current.setAttribute(\"aria-activedescendant\", descendant.id)\n\n activeDescendant.current = descendant\n\n descendants.active(descendant)\n },\n [descendants, disabled],\n )\n\n const onOpenWithActiveDescendant = useCallback(\n (\n getFallbackDescendant: () => ComboboxDescendant | undefined,\n block: SimpleDirection = \"start\",\n ) => {\n onOpen()\n\n setTimeout(() => {\n if (!initialFocusValue) {\n const descendant = getFallbackDescendant()\n\n onActiveDescendant(descendant)\n onScrollIntoView(descendant, block)\n } else {\n const values = descendants.values()\n const descendant =\n values.find(({ value }) => initialFocusValue === value) ??\n getFallbackDescendant()\n\n onActiveDescendant(descendant)\n onScrollIntoView(descendant, block)\n }\n })\n },\n [\n descendants,\n initialFocusValue,\n onActiveDescendant,\n onOpen,\n onScrollIntoView,\n ],\n )\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n if (disabled) return\n\n ev.preventDefault()\n\n if (!open) {\n if (openOnClick)\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n } else {\n onClose()\n }\n },\n [\n descendants,\n disabled,\n onClose,\n onOpenWithActiveDescendant,\n open,\n openOnClick,\n ],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLDivElement>) => {\n if (disabled || isComposing(ev)) return\n\n runKeyAction(\n ev,\n {\n ArrowDown: (ev) => {\n ev.preventDefault()\n\n if (!open) {\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n } else if (activeDescendant.current) {\n const descendant = descendants.enabledNextValue(\n activeDescendant.current,\n )\n\n onActiveDescendant(descendant)\n\n onScrollIntoView(\n descendant,\n descendant?.recurred ? \"start\" : \"end\",\n )\n } else {\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n\n onScrollIntoView(descendant)\n }\n },\n ArrowUp: (ev) => {\n ev.preventDefault()\n\n if (!open) {\n onOpenWithActiveDescendant(descendants.enabledLastValue, \"end\")\n } else if (activeDescendant.current) {\n const descendant = descendants.enabledPrevValue(\n activeDescendant.current,\n )\n\n onActiveDescendant(descendant)\n\n onScrollIntoView(\n descendant,\n descendant?.recurred ? \"end\" : \"start\",\n )\n } else {\n const descendant = descendants.enabledLastValue()\n\n onActiveDescendant(descendant)\n\n onScrollIntoView(descendant, \"end\")\n }\n },\n End: (ev) => {\n ev.preventDefault()\n\n if (!open) return\n\n const descendant = descendants.enabledLastValue()\n\n onActiveDescendant(descendant)\n\n onScrollIntoView(descendant, \"end\")\n },\n Enter: (ev) => {\n if (!open) {\n if (!openOnEnter) return\n\n ev.preventDefault()\n\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n } else {\n if (!activeDescendant.current) return\n\n ev.preventDefault()\n\n const { closeOnSelect, value } = activeDescendant.current\n\n onSelect(value, closeOnSelect)\n }\n },\n Home: (ev) => {\n if (!open) return\n\n ev.preventDefault()\n\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n\n onScrollIntoView(descendant)\n },\n Space: (ev) => {\n if (!open) {\n if (!openOnSpace) return\n\n ev.preventDefault()\n\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n } else {\n if (!activeDescendant.current || !selectOnSpace) return\n\n ev.preventDefault()\n\n const { closeOnSelect, value } = activeDescendant.current\n\n onSelect(value, closeOnSelect)\n }\n },\n },\n { preventDefault: false },\n )\n },\n [\n disabled,\n open,\n onOpenWithActiveDescendant,\n descendants,\n onActiveDescendant,\n onScrollIntoView,\n openOnEnter,\n onSelect,\n openOnSpace,\n selectOnSpace,\n ],\n )\n\n useUpdateEffect(() => {\n if (open) return\n\n activeDescendant.current = null\n }, [open])\n\n const getTriggerProps: PropGetter = useCallback(\n ({\n ref,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledby,\n ...props\n } = {}) => ({\n \"aria-controls\": open ? contentId : undefined,\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-expanded\": open,\n \"aria-haspopup\": \"listbox\",\n \"aria-label\": ariaLabel || ariaLabelProp,\n \"aria-labelledby\": cx(ariaLabelledby, ariaLabelledbyProp),\n \"data-disabled\": dataAttr(disabled),\n \"data-readonly\": dataAttr(readOnly),\n role: \"combobox\",\n tabIndex: interactive ? 0 : -1,\n ...rest,\n ...props,\n ref: mergeRefs(ref, rest.ref, triggerRef),\n onClick: handlerAll(props.onClick, rest.onClick, onClick),\n onKeyDown: handlerAll(props.onKeyDown, rest.onKeyDown, onKeyDown),\n }),\n [\n open,\n contentId,\n interactive,\n ariaLabelledbyProp,\n disabled,\n readOnly,\n ariaLabelProp,\n rest,\n onClick,\n onKeyDown,\n ],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id: contentId,\n role: \"listbox\",\n ...props,\n ref: mergeRefs(ref, contentRef),\n onKeyDown: handlerAll(props.onKeyDown),\n }),\n [contentId],\n )\n\n const getSeparatorProps: PropGetter = useCallback(\n (props) => ({ role: \"separator\", ...props }),\n [],\n )\n\n return {\n activeDescendant,\n descendants,\n interactive,\n open,\n getContentProps,\n getSeparatorProps,\n getTriggerProps,\n popoverProps: mergedPopoverProps,\n onActiveDescendant,\n onClose,\n onOpen,\n onOpenWithActiveDescendant,\n onScrollIntoView,\n onSelect,\n }\n}\n\nexport type UseComboboxReturn = ReturnType<typeof useCombobox>\n\nexport interface UseComboboxGroupProps extends HTMLProps {}\n\nexport const useComboboxGroup = ({\n \"aria-labelledby\": ariaLabelledbyProp,\n ...rest\n}: UseComboboxGroupProps = {}) => {\n const labelId = useId()\n\n const getGroupProps: PropGetter = useCallback(\n ({ \"aria-labelledby\": ariaLabelledby, ...props } = {}) => ({\n \"aria-labelledby\": cx(ariaLabelledbyProp, ariaLabelledby, labelId),\n role: \"group\",\n ...rest,\n ...props,\n }),\n [ariaLabelledbyProp, labelId, rest],\n )\n\n const getLabelProps: PropGetter<\"span\"> = useCallback(\n (props) => ({ id: labelId, role: \"presentation\", ...props }),\n [labelId],\n )\n\n return { getGroupProps, getLabelProps }\n}\n\nexport type UseComboboxGroupReturn = ReturnType<typeof useComboboxGroup>\n\nexport interface UseComboboxItemProps extends HTMLProps {\n /**\n * If `true`, the item will be closed when selected.\n */\n closeOnSelect?: boolean\n /**\n * If `true`, the item will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * If `true`, the item will be selected.\n */\n selected?: boolean\n /**\n * The value of the item.\n */\n value?: string\n}\n\nexport const useComboboxItem = ({\n id,\n \"aria-disabled\": ariaDisabled,\n \"data-disabled\": dataDisabled,\n closeOnSelect,\n disabled = false,\n selected = false,\n value,\n ...rest\n}: UseComboboxItemProps = {}) => {\n const uuid = useId()\n const itemRef = useRef<HTMLDivElement>(null)\n const { onActiveDescendant, onClose, onSelect } = useComboboxContext()\n\n id ??= uuid\n\n const { descendants, register } = useComboboxDescendant({\n id,\n closeOnSelect,\n disabled,\n value,\n })\n\n const onActive = useCallback(() => {\n if (disabled) return\n\n const current = descendants.value(itemRef.current)\n\n onActiveDescendant(current)\n }, [descendants, disabled, onActiveDescendant])\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n ev.preventDefault()\n\n if (disabled) return\n\n onSelect(value, closeOnSelect)\n },\n [closeOnSelect, disabled, onSelect, value],\n )\n\n const getItemProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id,\n \"aria-disabled\": ariaDisabled ?? ariaAttr(disabled),\n \"aria-selected\": selected,\n \"data-disabled\": dataDisabled ?? dataAttr(disabled),\n \"data-selected\": dataAttr(selected),\n \"data-value\": value,\n role: \"option\",\n tabIndex: -1,\n ...rest,\n ...props,\n ref: mergeRefs(ref, rest.ref, itemRef, register),\n onClick: handlerAll(props.onClick, rest.onClick, onClick),\n onMouseMove: handlerAll(props.onMouseMove, rest.onMouseMove, onActive),\n }),\n [\n id,\n ariaDisabled,\n disabled,\n selected,\n dataDisabled,\n value,\n rest,\n register,\n onClick,\n onActive,\n ],\n )\n\n const getIndicatorProps: PropGetter = useCallback(\n ({ style, ...props } = {}) => ({\n style: { opacity: selected ? 1 : 0, ...style },\n ...props,\n }),\n [selected],\n )\n\n return {\n descendants,\n disabled,\n selected,\n getIndicatorProps,\n getItemProps,\n onActiveDescendant,\n onClose,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwDA,MAAa,sBACX,UACA,EAAE,OAAO,OAAO,aACb;AAGH,QAFsBA,kCAAiB,SAAS,CAG7C,QACE,EAAE,WAAWC,+BAAc,MAAM,OAAO,IAAIA,+BAAc,MAAM,MAAM,CACxE,CACA,KAAK,EAAE,MAAM,YAAY;AACxB,MAAIA,+BAAc,MAAM,OAAO,CAC7B,QAAO;GAAE,GAAG;GAAO,OAAO,MAAM;GAAU;OACrC;GACL,MAAM,gBAAgBD,kCAAiB,MAAM,SAAS;GACtD,MAAM,QAAQE,2BAAU,eAAe,MAAM;AAE7C,UAAO;IACL,GAAG;IACH,OAAO,cACJ,QAAQ,EAAE,mBAAWD,+BAAcE,QAAM,OAAO,CAAC,CACjD,KAAK,EAAE,sBAAa;KAAE,GAAGC;KAAO,OAAOA,QAAM;KAAU,EAAE;IAC5D,OAAO,OAAO,MAAM,YAAY,MAAM;IACvC;;GAEH;;AASN,MAAa,0BACX,OACA,EAAE,OAAO,OAAO,aACb;AACH,QAAO,MAAM,KAAK,MAAM,UAAU;AAChC,MAAI,gBAAgB,QAAQ,OAAO;GACjC,MAAM,EAAE,OAAO,GAAG,SAAS;AAE3B,UACE,2CAAC;IAAkB,GAAI;cACpB;MADS,MAEJ;aAED,WAAW,MAAM;GAC1B,MAAM,EAAE,iBAAQ,EAAE,EAAE,OAAO,GAAG,SAAS;AAEvC,UACE,2CAAC;IAAyB;IAAO,GAAI;cAClCC,QAAM,KAAK,EAAE,gBAAO,GAAGC,UAAQ,YAC9B,2CAAC;KAAmB,GAAIA;eACrBC;OADUC,QAEJ,CACT;MALQ,MAMJ;SAEL;GACL,MAAM,EAAE,OAAO,GAAG,SAAS;AAE3B,UACE,2CAAC;IAAmB,GAAI;cACrB;MADU,MAEJ;;GA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A;EACA;EACA;EACA;EACA;EACA;EACD,CACF;AAUD,QAAO;EACL;EACA;EACA;EACA,2CAXC,EAAE,OAAO,GAAG,UAAU,EAAE,MAAM;GAC7B,OAAO;IAAE,SAAS,WAAW,IAAI;IAAG,GAAG;IAAO;GAC9C,GAAG;GACJ,GACD,CAAC,SAAS,CACX;EAOC;EACA;EACA;EACD"}
1
+ {"version":3,"file":"index.cjs","names":["getValidChildren","isSomeElement","findChild","type","props","items","rest","label","index","createDescendants","createContext","usePopoverProps","useEnvironment","useDisclosure","isComposing","getTriggerProps: PropGetter","mergeRefs","getItemProps: PropGetter"],"sources":["../../../../src/hooks/use-combobox/index.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n JSXElementConstructor,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n RefObject,\n} from \"react\"\nimport type { UsePopoverProps } from \"../../components/popover\"\nimport type { HTMLProps, PropGetter, SimpleDirection } from \"../../core\"\nimport type { Descendant } from \"../use-descendants\"\nimport type { UseDisclosureProps } from \"../use-disclosure\"\nimport { useCallback, useId, useMemo, useRef } from \"react\"\nimport scrollIntoView from \"scroll-into-view-if-needed\"\nimport { usePopoverProps } from \"../../components/popover\"\nimport { useEnvironment } from \"../../core\"\nimport {\n ariaAttr,\n createContext,\n cx,\n dataAttr,\n findChild,\n getValidChildren,\n handlerAll,\n isComposing,\n isSomeElement,\n isUndefined,\n mergeRefs,\n runKeyAction,\n useUpdateEffect,\n} from \"../../utils\"\nimport { createDescendants } from \"../use-descendants\"\nimport { useDisclosure } from \"../use-disclosure\"\n\ninterface ComboboxSharedItem extends Omit<HTMLProps, \"children\" | \"value\"> {\n label: ReactNode\n}\n\nexport interface ComboboxItemWithValue extends ComboboxSharedItem {\n query?: string\n value?: string\n}\n\nexport interface ComboboxItemWithItems extends ComboboxSharedItem {\n items: ComboboxItemWithValue[]\n}\n\nexport type ComboboxItem = ComboboxItemWithItems | ComboboxItemWithValue\n\nexport interface CreateComboboxItemOptions {\n Group: JSXElementConstructor<any>\n Label: JSXElementConstructor<any>\n Option: JSXElementConstructor<any>\n}\n\nexport const createComboboxItem = (\n children: ReactNode,\n { Group, Label, Option }: CreateComboboxItemOptions,\n) => {\n const validChildren = getValidChildren(children)\n\n return validChildren\n .filter(\n ({ type }) => isSomeElement(type, Option) || isSomeElement(type, Group),\n )\n .map(({ type, props }) => {\n if (isSomeElement(type, Option)) {\n return { ...props, label: props.children }\n } else {\n const validChildren = getValidChildren(props.children)\n const label = findChild(validChildren, Label)\n\n return {\n ...props,\n items: validChildren\n .filter(({ type }) => isSomeElement(type, Option))\n .map(({ props }) => ({ ...props, label: props.children })),\n label: label?.props.children ?? props.label,\n }\n }\n })\n}\n\nexport interface CreateComboboxChildrenOptions {\n Group: JSXElementConstructor<any>\n Option: JSXElementConstructor<any>\n Empty?: JSXElementConstructor<any>\n}\n\nexport const createComboboxChildren = (\n items: ComboboxItem[],\n { Empty, Group, Option }: CreateComboboxChildrenOptions,\n) => {\n return items.map((item, index) => {\n if (\"data-empty\" in item && Empty) {\n const { label, ...rest } = item\n\n return (\n <Empty key={index} {...rest}>\n {label}\n </Empty>\n )\n } else if (\"items\" in item) {\n const { items = [], label, ...rest } = item\n\n return (\n <Group key={index} label={label} {...rest}>\n {items.map(({ label, ...rest }, index) => (\n <Option key={index} {...rest}>\n {label}\n </Option>\n ))}\n </Group>\n )\n } else {\n const { label, ...rest } = item\n\n return (\n <Option key={index} {...rest}>\n {label}\n </Option>\n )\n }\n })\n}\n\nexport interface ComboboxDescendantProps {\n id: string\n closeOnSelect?: boolean\n value?: string\n}\nexport type ComboboxDescendant = Descendant<\n HTMLDivElement,\n ComboboxDescendantProps\n>\n\nconst {\n DescendantsContext: ComboboxDescendantsContext,\n useDescendant: useComboboxDescendant,\n useDescendantRegister: useComboboxDescendantRegister,\n useDescendants: useComboboxDescendants,\n} = createDescendants<HTMLDivElement, ComboboxDescendantProps>()\n\nexport {\n ComboboxDescendantsContext,\n useComboboxDescendant,\n useComboboxDescendantRegister,\n useComboboxDescendants,\n}\n\ninterface ComboboxContext extends Pick<\n UseComboboxReturn,\n \"onActiveDescendant\" | \"onClose\" | \"onSelect\"\n> {}\n\nconst [ComboboxContext, useComboboxContext] = createContext<ComboboxContext>({\n name: \"ComboboxContext\",\n})\n\ninterface ComboboxGroupContext extends Pick<\n UseComboboxGroupReturn,\n \"getLabelProps\"\n> {}\n\nconst [ComboboxGroupContext, useComboboxGroupContext] =\n createContext<ComboboxGroupContext>({\n name: \"ComboboxGroupContext\",\n })\n\nexport {\n ComboboxContext,\n ComboboxGroupContext,\n useComboboxContext,\n useComboboxGroupContext,\n}\n\nexport interface UseComboboxProps\n extends\n Omit<HTMLProps, \"onChange\">,\n Omit<UseDisclosureProps, \"timing\">,\n Omit<\n UsePopoverProps,\n \"autoFocus\" | \"initialFocusRef\" | \"modal\" | \"transform\" | \"updateRef\"\n > {\n /**\n * If `true`, the list element will be closed when value is selected.\n *\n * @default true\n */\n closeOnSelect?: boolean\n /**\n * If `true`, the combobox will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The value to focus on when the combobox is opened.\n */\n initialFocusValue?: string\n /**\n * If `true`, the combobox will be opened when click on the field.\n *\n * @default true\n */\n openOnClick?: boolean\n /**\n * If `true`, the combobox will be opened when enter is pressed.\n *\n * @default true\n */\n openOnEnter?: boolean\n /**\n * If `true`, the combobox will be opened when space is pressed.\n *\n * @default true\n */\n openOnSpace?: boolean\n /**\n * If `true`, the combobox will be readonly.\n *\n * @default false\n */\n readOnly?: boolean\n /**\n * The `ref` of the element that should receive focus when selected.\n */\n selectFocusRef?: RefObject<HTMLElement | null>\n /**\n * If `true`, the item will be selected when space is pressed.\n *\n * @default true\n */\n selectOnSpace?: boolean\n /**\n * The callback invoked when value is selected.\n */\n onChange?: (value: string) => void\n}\n\nexport const useCombobox = (props: UseComboboxProps = {}) => {\n const [\n popoverProps,\n {\n \"aria-label\": ariaLabelProp,\n \"aria-labelledby\": ariaLabelledbyProp,\n closeOnSelect: closeOnSelectProp = true,\n defaultOpen,\n disabled,\n initialFocusValue,\n open: openProp,\n openOnClick = true,\n openOnEnter = true,\n openOnSpace = true,\n readOnly,\n selectFocusRef,\n selectOnSpace = true,\n onChange: onChangeProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n ...rest\n },\n ] = usePopoverProps(props, [\n \"disabled\",\n \"open\",\n \"defaultOpen\",\n \"onOpen\",\n \"onClose\",\n \"openOnClick\",\n ])\n const { getWindow } = useEnvironment()\n const interactive = !(readOnly || disabled)\n const triggerRef = useRef<HTMLDivElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const contentId = useId()\n const descendants = useComboboxDescendants()\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const activeDescendant = useRef<ComboboxDescendant | null>(null)\n const mergedPopoverProps = useMemo<UsePopoverProps>(\n () => ({\n autoFocus: false,\n matchWidth: true,\n openOnClick: false,\n ...popoverProps,\n disabled: !interactive,\n open,\n onClose,\n onOpen,\n }),\n [interactive, onClose, onOpen, open, popoverProps],\n )\n\n const onSelect = useCallback(\n (value?: string, closeOnSelect = closeOnSelectProp) => {\n const ref = selectFocusRef ?? triggerRef\n\n ref.current?.focus()\n\n if (!interactive || isUndefined(value)) return\n\n onChangeProp?.(value)\n\n if (!closeOnSelect) return\n\n onClose()\n },\n [closeOnSelectProp, interactive, onChangeProp, onClose, selectFocusRef],\n )\n\n const onScrollIntoView = useCallback(\n (descendant?: ComboboxDescendant, block: SimpleDirection = \"start\") => {\n if (!contentRef.current || !descendant) return\n\n const style = getWindow()?.getComputedStyle(contentRef.current)\n const padding =\n block === \"start\" ? style?.paddingBlockStart : style?.paddingBlockEnd\n const value = parseInt(padding ?? \"0px\")\n\n scrollIntoView(descendant.node, {\n behavior: (actions) =>\n actions.forEach(({ el, top }) => {\n el.scrollTop = block === \"start\" ? top - value : top + value\n }),\n block,\n boundary: contentRef.current,\n inline: \"nearest\",\n scrollMode: \"if-needed\",\n })\n },\n [getWindow],\n )\n\n const onActiveDescendant = useCallback(\n (descendant?: ComboboxDescendant) => {\n if (!triggerRef.current || !descendant || disabled) return\n\n triggerRef.current.setAttribute(\"aria-activedescendant\", descendant.id)\n\n activeDescendant.current = descendant\n\n descendants.active(descendant)\n },\n [descendants, disabled],\n )\n\n const onOpenWithActiveDescendant = useCallback(\n (\n getFallbackDescendant: () => ComboboxDescendant | undefined,\n block: SimpleDirection = \"start\",\n ) => {\n onOpen()\n\n setTimeout(() => {\n if (!initialFocusValue) {\n const descendant = getFallbackDescendant()\n\n onActiveDescendant(descendant)\n onScrollIntoView(descendant, block)\n } else {\n const values = descendants.values()\n const descendant =\n values.find(({ value }) => initialFocusValue === value) ??\n getFallbackDescendant()\n\n onActiveDescendant(descendant)\n onScrollIntoView(descendant, block)\n }\n })\n },\n [\n descendants,\n initialFocusValue,\n onActiveDescendant,\n onOpen,\n onScrollIntoView,\n ],\n )\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n if (disabled) return\n\n ev.preventDefault()\n\n if (!open) {\n if (openOnClick)\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n } else {\n onClose()\n }\n },\n [\n descendants,\n disabled,\n onClose,\n onOpenWithActiveDescendant,\n open,\n openOnClick,\n ],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLDivElement>) => {\n if (disabled || isComposing(ev)) return\n\n runKeyAction(\n ev,\n {\n ArrowDown: (ev) => {\n ev.preventDefault()\n\n if (!open) {\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n } else if (activeDescendant.current) {\n const descendant = descendants.enabledNextValue(\n activeDescendant.current,\n )\n\n onActiveDescendant(descendant)\n\n onScrollIntoView(\n descendant,\n descendant?.recurred ? \"start\" : \"end\",\n )\n } else {\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n\n onScrollIntoView(descendant)\n }\n },\n ArrowUp: (ev) => {\n ev.preventDefault()\n\n if (!open) {\n onOpenWithActiveDescendant(descendants.enabledLastValue, \"end\")\n } else if (activeDescendant.current) {\n const descendant = descendants.enabledPrevValue(\n activeDescendant.current,\n )\n\n onActiveDescendant(descendant)\n\n onScrollIntoView(\n descendant,\n descendant?.recurred ? \"end\" : \"start\",\n )\n } else {\n const descendant = descendants.enabledLastValue()\n\n onActiveDescendant(descendant)\n\n onScrollIntoView(descendant, \"end\")\n }\n },\n End: (ev) => {\n ev.preventDefault()\n\n if (!open) return\n\n const descendant = descendants.enabledLastValue()\n\n onActiveDescendant(descendant)\n\n onScrollIntoView(descendant, \"end\")\n },\n Enter: (ev) => {\n if (!open) {\n if (!openOnEnter) return\n\n ev.preventDefault()\n\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n } else {\n if (!activeDescendant.current) return\n\n ev.preventDefault()\n\n const { closeOnSelect, value } = activeDescendant.current\n\n onSelect(value, closeOnSelect)\n }\n },\n Home: (ev) => {\n if (!open) return\n\n ev.preventDefault()\n\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n\n onScrollIntoView(descendant)\n },\n Space: (ev) => {\n if (!open) {\n if (!openOnSpace) return\n\n ev.preventDefault()\n\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n } else {\n if (!activeDescendant.current || !selectOnSpace) return\n\n ev.preventDefault()\n\n const { closeOnSelect, value } = activeDescendant.current\n\n onSelect(value, closeOnSelect)\n }\n },\n },\n { preventDefault: false },\n )\n },\n [\n disabled,\n open,\n onOpenWithActiveDescendant,\n descendants,\n onActiveDescendant,\n onScrollIntoView,\n openOnEnter,\n onSelect,\n openOnSpace,\n selectOnSpace,\n ],\n )\n\n useUpdateEffect(() => {\n if (open) return\n\n activeDescendant.current = null\n }, [open])\n\n const getTriggerProps: PropGetter = useCallback(\n ({\n ref,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledby,\n ...props\n } = {}) => ({\n \"aria-controls\": open ? contentId : undefined,\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-expanded\": open,\n \"aria-haspopup\": \"listbox\",\n \"aria-label\": ariaLabel || ariaLabelProp,\n \"aria-labelledby\": cx(ariaLabelledby, ariaLabelledbyProp),\n \"data-disabled\": dataAttr(disabled),\n \"data-readonly\": dataAttr(readOnly),\n role: \"combobox\",\n tabIndex: interactive ? 0 : -1,\n ...rest,\n ...props,\n ref: mergeRefs(ref, rest.ref, triggerRef),\n onClick: handlerAll(props.onClick, rest.onClick, onClick),\n onKeyDown: handlerAll(props.onKeyDown, rest.onKeyDown, onKeyDown),\n }),\n [\n open,\n contentId,\n interactive,\n ariaLabelledbyProp,\n disabled,\n readOnly,\n ariaLabelProp,\n rest,\n onClick,\n onKeyDown,\n ],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id: contentId,\n role: \"listbox\",\n ...props,\n ref: mergeRefs(ref, contentRef),\n onKeyDown: handlerAll(props.onKeyDown),\n }),\n [contentId],\n )\n\n const getSeparatorProps: PropGetter = useCallback(\n (props) => ({ role: \"separator\", ...props }),\n [],\n )\n\n return {\n activeDescendant,\n descendants,\n interactive,\n open,\n getContentProps,\n getSeparatorProps,\n getTriggerProps,\n popoverProps: mergedPopoverProps,\n onActiveDescendant,\n onClose,\n onOpen,\n onOpenWithActiveDescendant,\n onScrollIntoView,\n onSelect,\n }\n}\n\nexport type UseComboboxReturn = ReturnType<typeof useCombobox>\n\nexport interface UseComboboxGroupProps extends HTMLProps {}\n\nexport const useComboboxGroup = ({\n \"aria-labelledby\": ariaLabelledbyProp,\n ...rest\n}: UseComboboxGroupProps = {}) => {\n const labelId = useId()\n\n const getGroupProps: PropGetter = useCallback(\n ({ \"aria-labelledby\": ariaLabelledby, ...props } = {}) => ({\n \"aria-labelledby\": cx(ariaLabelledbyProp, ariaLabelledby, labelId),\n role: \"group\",\n ...rest,\n ...props,\n }),\n [ariaLabelledbyProp, labelId, rest],\n )\n\n const getLabelProps: PropGetter<\"span\"> = useCallback(\n (props) => ({ id: labelId, role: \"presentation\", ...props }),\n [labelId],\n )\n\n return { getGroupProps, getLabelProps }\n}\n\nexport type UseComboboxGroupReturn = ReturnType<typeof useComboboxGroup>\n\nexport interface UseComboboxItemProps extends HTMLProps {\n /**\n * If `true`, the item will be closed when selected.\n */\n closeOnSelect?: boolean\n /**\n * If `true`, the item will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * If `true`, the item will be selected.\n */\n selected?: boolean\n /**\n * The value of the item.\n */\n value?: string\n}\n\nexport const useComboboxItem = ({\n id,\n \"aria-disabled\": ariaDisabled,\n \"data-disabled\": dataDisabled,\n closeOnSelect,\n disabled = false,\n selected = false,\n value,\n ...rest\n}: UseComboboxItemProps = {}) => {\n const uuid = useId()\n const itemRef = useRef<HTMLDivElement>(null)\n const { onActiveDescendant, onClose, onSelect } = useComboboxContext()\n\n id ??= uuid\n\n const { descendants, register } = useComboboxDescendant({\n id,\n closeOnSelect,\n disabled,\n value,\n })\n\n const onActive = useCallback(() => {\n if (disabled) return\n\n const current = descendants.value(itemRef.current)\n\n onActiveDescendant(current)\n }, [descendants, disabled, onActiveDescendant])\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n ev.preventDefault()\n\n if (disabled) return\n\n onSelect(value, closeOnSelect)\n },\n [closeOnSelect, disabled, onSelect, value],\n )\n\n const getItemProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id,\n \"aria-disabled\": ariaDisabled ?? ariaAttr(disabled),\n \"aria-selected\": selected,\n \"data-disabled\": dataDisabled ?? dataAttr(disabled),\n \"data-selected\": dataAttr(selected),\n \"data-value\": value,\n role: \"option\",\n tabIndex: -1,\n ...rest,\n ...props,\n ref: mergeRefs(ref, rest.ref, itemRef, register),\n onClick: handlerAll(props.onClick, rest.onClick, onClick),\n onMouseMove: handlerAll(props.onMouseMove, rest.onMouseMove, onActive),\n }),\n [\n id,\n ariaDisabled,\n disabled,\n selected,\n dataDisabled,\n value,\n rest,\n register,\n onClick,\n onActive,\n ],\n )\n\n const getIndicatorProps: PropGetter = useCallback(\n ({ style, ...props } = {}) => ({\n style: { opacity: selected ? 1 : 0, ...style },\n ...props,\n }),\n [selected],\n )\n\n return {\n descendants,\n disabled,\n selected,\n getIndicatorProps,\n getItemProps,\n onActiveDescendant,\n onClose,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwDA,MAAa,sBACX,UACA,EAAE,OAAO,OAAO,aACb;AAGH,QAFsBA,kCAAiB,SAAS,CAG7C,QACE,EAAE,WAAWC,+BAAc,MAAM,OAAO,IAAIA,+BAAc,MAAM,MAAM,CACxE,CACA,KAAK,EAAE,MAAM,YAAY;AACxB,MAAIA,+BAAc,MAAM,OAAO,CAC7B,QAAO;GAAE,GAAG;GAAO,OAAO,MAAM;GAAU;OACrC;GACL,MAAM,gBAAgBD,kCAAiB,MAAM,SAAS;GACtD,MAAM,QAAQE,2BAAU,eAAe,MAAM;AAE7C,UAAO;IACL,GAAG;IACH,OAAO,cACJ,QAAQ,EAAE,mBAAWD,+BAAcE,QAAM,OAAO,CAAC,CACjD,KAAK,EAAE,sBAAa;KAAE,GAAGC;KAAO,OAAOA,QAAM;KAAU,EAAE;IAC5D,OAAO,OAAO,MAAM,YAAY,MAAM;IACvC;;GAEH;;AASN,MAAa,0BACX,OACA,EAAE,OAAO,OAAO,aACb;AACH,QAAO,MAAM,KAAK,MAAM,UAAU;AAChC,MAAI,gBAAgB,QAAQ,OAAO;GACjC,MAAM,EAAE,OAAO,GAAG,SAAS;AAE3B,UACE,2CAAC;IAAkB,GAAI;cACpB;MADS,MAEJ;aAED,WAAW,MAAM;GAC1B,MAAM,EAAE,iBAAQ,EAAE,EAAE,OAAO,GAAG,SAAS;AAEvC,UACE,2CAAC;IAAyB;IAAO,GAAI;cAClCC,QAAM,KAAK,EAAE,gBAAO,GAAGC,UAAQ,YAC9B,2CAAC;KAAmB,GAAIA;eACrBC;OADUC,QAEJ,CACT;MALQ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,SAAS,KAAK,SAAS,QAAQ;EACzD,+DAAwB,MAAM,aAAa,KAAK,aAAa,SAAS;EACvE,GACD;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CACF;AAUD,QAAO;EACL;EACA;EACA;EACA,2CAXC,EAAE,OAAO,GAAG,UAAU,EAAE,MAAM;GAC7B,OAAO;IAAE,SAAS,WAAW,IAAI;IAAG,GAAG;IAAO;GAC9C,GAAG;GACJ,GACD,CAAC,SAAS,CACX;EAOC;EACA;EACA;EACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["useCallbackRef","value"],"sources":["../../../../src/hooks/use-controllable-state/index.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n ChangeEventHandler,\n Dispatch,\n SetStateAction,\n} from \"react\"\nimport { useState } from \"react\"\nimport {\n isBoolean,\n isNull,\n isUndefined,\n runIfFn,\n useCallbackRef,\n} from \"../../utils\"\n\ninterface UseControllableStateMethods<Y> {\n onChange?: (value: Y) => void\n onUpdate?: (prev: Y, next: Y) => boolean\n}\n\nexport interface UseControllableStateProps<\n Y,\n> extends UseControllableStateMethods<Y> {\n defaultValue?: (() => Y) | Y\n value?: Y\n}\n\nexport function useControllableState<Y>(\n props: UseControllableStateMethods<Y> & {\n defaultValue?: (() => Y) | Y\n value: Y\n },\n): [Y, Dispatch<SetStateAction<Y>>]\n\nexport function useControllableState<Y>(\n props: UseControllableStateMethods<Y> & {\n defaultValue: (() => Y) | Y\n value?: Y\n },\n): [Y, Dispatch<SetStateAction<Y>>]\n\nexport function useControllableState<Y>(\n props: UseControllableStateProps<Y>,\n): [Y, Dispatch<SetStateAction<Y>>]\n\nexport function useControllableState<Y>({\n defaultValue: defaultValueProp,\n value,\n onChange: onChangeProp,\n onUpdate: onUpdateProp = (prev, next) => prev !== next,\n}: UseControllableStateProps<Y>) {\n const onChange = useCallbackRef(onChangeProp)\n const onUpdate = useCallbackRef(onUpdateProp)\n const [defaultValue, setDefaultValue] = useState(defaultValueProp)\n const controlled = !isUndefined(value)\n const currentValue = (controlled ? value : defaultValue) as Y\n\n const setValue = useCallbackRef(\n (next: SetStateAction<Y>) => {\n const nextValue = runIfFn(next, currentValue)\n\n if (!onUpdate(currentValue, nextValue)) return\n\n if (!controlled || isUndefined(nextValue) || isNull(nextValue))\n setDefaultValue(nextValue)\n\n onChange(nextValue)\n },\n [controlled, currentValue, onChange, onUpdate],\n )\n\n return [currentValue, setValue]\n}\n\nfunction isHTMLInputElement(el: HTMLElement): el is HTMLInputElement {\n return el instanceof HTMLInputElement\n}\n\ninterface UseControllableEventStateMethods<\n Y extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,\n> {\n onChange?: ChangeEventHandler<Y>\n}\n\nexport interface UseControllableEventStateProps<\n Y extends boolean | number | string,\n M extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,\n> extends UseControllableEventStateMethods<M> {\n defaultValue?: (() => Y) | Y\n value?: Y\n}\n\nexport function useControllableEventState<\n Y extends boolean | number | string,\n M extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,\n>(\n props: UseControllableEventStateMethods<M> & {\n defaultValue?: (() => Y) | Y\n value: Y\n },\n): [Y, ChangeEventHandler<M>]\n\nexport function useControllableEventState<\n Y extends boolean | number | string,\n M extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,\n>(\n props: UseControllableEventStateMethods<M> & {\n defaultValue: (() => Y) | Y\n value?: Y\n },\n): [Y, ChangeEventHandler<M>]\n\nexport function useControllableEventState<\n Y extends boolean | number | string,\n M extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,\n>(props: UseControllableEventStateProps<Y, M>): [Y, ChangeEventHandler<M>]\n\nexport function useControllableEventState<\n Y extends boolean | number | string,\n M extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,\n>({\n defaultValue: defaultValueProp,\n value,\n onChange: onChangeProp,\n}: UseControllableEventStateProps<Y, M>) {\n const onChange = useCallbackRef(onChangeProp)\n const [defaultValue, setDefaultValue] = useState(defaultValueProp)\n const controlled = !isUndefined(value)\n const currentValue = (controlled ? value : defaultValue) as Y\n const boolean = isBoolean(currentValue)\n\n const setValue = useCallbackRef(\n (ev: ChangeEvent<M>) => {\n const value =\n boolean && isHTMLInputElement(ev.target)\n ? (ev.target.checked as Y)\n : (ev.target.value as Y)\n\n if (!controlled || isUndefined(value) || isNull(value)) {\n setDefaultValue(value)\n }\n\n onChange(ev)\n },\n [controlled, currentValue, onChange],\n )\n\n return [currentValue, setValue]\n}\n"],"mappings":";;;;;;;;AA+CA,SAAgB,qBAAwB,EACtC,cAAc,kBACd,OACA,UAAU,cACV,UAAU,gBAAgB,MAAM,SAAS,SAAS,QACnB;CAC/B,MAAM,WAAWA,2BAAe,aAAa;CAC7C,MAAM,WAAWA,2BAAe,aAAa;CAC7C,MAAM,CAAC,cAAc,uCAA4B,iBAAiB;CAClE,MAAM,aAAa,oDAAa,MAAM;CACtC,MAAM,eAAgB,aAAa,QAAQ;AAgB3C,QAAO,CAAC,cAdSA,4BACd,SAA4B;EAC3B,MAAM,2DAAoB,MAAM,aAAa;AAE7C,MAAI,CAAC,SAAS,cAAc,UAAU,CAAE;AAExC,MAAI,CAAC,iEAA0B,UAAU,kDAAW,UAAU,CAC5D,iBAAgB,UAAU;AAE5B,WAAS,UAAU;IAErB;EAAC;EAAY;EAAc;EAAU;EAAS,CAC/C,CAE8B;;AAGjC,SAAS,mBAAmB,IAAyC;AACnE,QAAO,cAAc;;AA0CvB,SAAgB,0BAGd,EACA,cAAc,kBACd,OACA,UAAU,gBAC6B;CACvC,MAAM,WAAWA,2BAAe,aAAa;CAC7C,MAAM,CAAC,cAAc,uCAA4B,iBAAiB;CAClE,MAAM,aAAa,oDAAa,MAAM;CACtC,MAAM,eAAgB,aAAa,QAAQ;CAC3C,MAAM,2DAAoB,aAAa;AAkBvC,QAAO,CAAC,cAhBSA,4BACd,OAAuB;EACtB,MAAMC,UACJ,WAAW,mBAAmB,GAAG,OAAO,GACnC,GAAG,OAAO,UACV,GAAG,OAAO;AAEjB,MAAI,CAAC,iEAA0BA,QAAM,kDAAWA,QAAM,CACpD,iBAAgBA,QAAM;AAGxB,WAAS,GAAG;IAEd;EAAC;EAAY;EAAc;EAAS,CACrC,CAE8B"}
1
+ {"version":3,"file":"index.cjs","names":["useCallbackRef","value"],"sources":["../../../../src/hooks/use-controllable-state/index.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n ChangeEventHandler,\n Dispatch,\n SetStateAction,\n} from \"react\"\nimport { useState } from \"react\"\nimport {\n isBoolean,\n isNull,\n isUndefined,\n runIfFn,\n useCallbackRef,\n} from \"../../utils\"\n\ninterface UseControllableStateMethods<Y> {\n onChange?: (value: Y) => void\n onUpdate?: (prev: Y, next: Y) => boolean\n}\n\nexport interface UseControllableStateProps<\n Y,\n> extends UseControllableStateMethods<Y> {\n defaultValue?: (() => Y) | Y\n value?: Y\n}\n\nexport function useControllableState<Y>(\n props: UseControllableStateMethods<Y> & {\n value: Y\n defaultValue?: (() => Y) | Y\n },\n): [Y, Dispatch<SetStateAction<Y>>]\n\nexport function useControllableState<Y>(\n props: UseControllableStateMethods<Y> & {\n defaultValue: (() => Y) | Y\n value?: Y\n },\n): [Y, Dispatch<SetStateAction<Y>>]\n\nexport function useControllableState<Y>(\n props: UseControllableStateProps<Y>,\n): [Y, Dispatch<SetStateAction<Y>>]\n\nexport function useControllableState<Y>({\n defaultValue: defaultValueProp,\n value,\n onChange: onChangeProp,\n onUpdate: onUpdateProp = (prev, next) => prev !== next,\n}: UseControllableStateProps<Y>) {\n const onChange = useCallbackRef(onChangeProp)\n const onUpdate = useCallbackRef(onUpdateProp)\n const [defaultValue, setDefaultValue] = useState(defaultValueProp)\n const controlled = !isUndefined(value)\n const currentValue = (controlled ? value : defaultValue) as Y\n\n const setValue = useCallbackRef(\n (next: SetStateAction<Y>) => {\n const nextValue = runIfFn(next, currentValue)\n\n if (!onUpdate(currentValue, nextValue)) return\n\n if (!controlled || isUndefined(nextValue) || isNull(nextValue))\n setDefaultValue(nextValue)\n\n onChange(nextValue)\n },\n [controlled, currentValue, onChange, onUpdate],\n )\n\n return [currentValue, setValue]\n}\n\nfunction isHTMLInputElement(el: HTMLElement): el is HTMLInputElement {\n return el instanceof HTMLInputElement\n}\n\ninterface UseControllableEventStateMethods<\n Y extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,\n> {\n onChange?: ChangeEventHandler<Y>\n}\n\nexport interface UseControllableEventStateProps<\n Y extends boolean | number | string,\n M extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,\n> extends UseControllableEventStateMethods<M> {\n defaultValue?: (() => Y) | Y\n value?: Y\n}\n\nexport function useControllableEventState<\n Y extends boolean | number | string,\n M extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,\n>(\n props: UseControllableEventStateMethods<M> & {\n value: Y\n defaultValue?: (() => Y) | Y\n },\n): [Y, ChangeEventHandler<M>]\n\nexport function useControllableEventState<\n Y extends boolean | number | string,\n M extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,\n>(\n props: UseControllableEventStateMethods<M> & {\n defaultValue: (() => Y) | Y\n value?: Y\n },\n): [Y, ChangeEventHandler<M>]\n\nexport function useControllableEventState<\n Y extends boolean | number | string,\n M extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,\n>(props: UseControllableEventStateProps<Y, M>): [Y, ChangeEventHandler<M>]\n\nexport function useControllableEventState<\n Y extends boolean | number | string,\n M extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,\n>({\n defaultValue: defaultValueProp,\n value,\n onChange: onChangeProp,\n}: UseControllableEventStateProps<Y, M>) {\n const onChange = useCallbackRef(onChangeProp)\n const [defaultValue, setDefaultValue] = useState(defaultValueProp)\n const controlled = !isUndefined(value)\n const currentValue = (controlled ? value : defaultValue) as Y\n const boolean = isBoolean(currentValue)\n\n const setValue = useCallbackRef(\n (ev: ChangeEvent<M>) => {\n const value =\n boolean && isHTMLInputElement(ev.target)\n ? (ev.target.checked as Y)\n : (ev.target.value as Y)\n\n if (!controlled || isUndefined(value) || isNull(value)) {\n setDefaultValue(value)\n }\n\n onChange(ev)\n },\n [controlled, currentValue, onChange],\n )\n\n return [currentValue, setValue]\n}\n"],"mappings":";;;;;;;;AA+CA,SAAgB,qBAAwB,EACtC,cAAc,kBACd,OACA,UAAU,cACV,UAAU,gBAAgB,MAAM,SAAS,SAAS,QACnB;CAC/B,MAAM,WAAWA,2BAAe,aAAa;CAC7C,MAAM,WAAWA,2BAAe,aAAa;CAC7C,MAAM,CAAC,cAAc,uCAA4B,iBAAiB;CAClE,MAAM,aAAa,oDAAa,MAAM;CACtC,MAAM,eAAgB,aAAa,QAAQ;AAgB3C,QAAO,CAAC,cAdSA,4BACd,SAA4B;EAC3B,MAAM,2DAAoB,MAAM,aAAa;AAE7C,MAAI,CAAC,SAAS,cAAc,UAAU,CAAE;AAExC,MAAI,CAAC,iEAA0B,UAAU,kDAAW,UAAU,CAC5D,iBAAgB,UAAU;AAE5B,WAAS,UAAU;IAErB;EAAC;EAAY;EAAc;EAAU;EAAS,CAC/C,CAE8B;;AAGjC,SAAS,mBAAmB,IAAyC;AACnE,QAAO,cAAc;;AA0CvB,SAAgB,0BAGd,EACA,cAAc,kBACd,OACA,UAAU,gBAC6B;CACvC,MAAM,WAAWA,2BAAe,aAAa;CAC7C,MAAM,CAAC,cAAc,uCAA4B,iBAAiB;CAClE,MAAM,aAAa,oDAAa,MAAM;CACtC,MAAM,eAAgB,aAAa,QAAQ;CAC3C,MAAM,2DAAoB,aAAa;AAkBvC,QAAO,CAAC,cAhBSA,4BACd,OAAuB;EACtB,MAAMC,UACJ,WAAW,mBAAmB,GAAG,OAAO,GACnC,GAAG,OAAO,UACV,GAAG,OAAO;AAEjB,MAAI,CAAC,iEAA0BA,QAAM,kDAAWA,QAAM,CACpD,iBAAgBA,QAAM;AAGxB,WAAS,GAAG;IAEd;EAAC;EAAY;EAAc;EAAS,CACrC,CAE8B"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["value"],"sources":["../../../../src/hooks/use-local-storage/index.ts"],"sourcesContent":["\"use client\"\n\nimport { useCallback, useEffect, useState } from \"react\"\nimport { isFunction } from \"../../utils\"\nimport { useWindowEvent } from \"../use-window-event\"\n\nexport type StorageType = \"localStorage\" | \"sessionStorage\"\n\nexport interface StorageProps<Y> {\n key: string\n defaultValue?: Y\n deserialize?: (value: string | undefined) => Y\n getInitialValueInEffect?: boolean\n serialize?: (value: Y) => string\n}\n\nconst serializeJSON = <Y>(value: Y, name: string) => {\n try {\n return JSON.stringify(value)\n } catch {\n throw new Error(`useLocalStorage ${name}: Failed to serialize the value`)\n }\n}\n\nconst deserializeJSON = (value: string | undefined) => {\n if (!value) return value\n\n try {\n return JSON.parse(value)\n } catch {\n return value\n }\n}\n\nexport const createStorage = <Y>(type: StorageType, name: string) => {\n const eventName =\n type === \"localStorage\" ? \"local-storage\" : \"session-storage\"\n\n return ({\n key,\n defaultValue = undefined,\n deserialize = deserializeJSON,\n getInitialValueInEffect = true,\n serialize = (value: Y) => serializeJSON(value, name),\n }: StorageProps<Y>) => {\n const readStorageValue = useCallback(\n (skipStorage?: boolean): Y => {\n if (\n typeof window === \"undefined\" ||\n !(type in window) ||\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n window[type] == null ||\n skipStorage\n ) {\n return (defaultValue ?? \"\") as Y\n }\n\n const storageValue = window[type].getItem(key)\n\n return storageValue !== null\n ? deserialize(storageValue)\n : ((defaultValue ?? \"\") as Y)\n },\n [key, deserialize, defaultValue],\n )\n\n const [value, setValue] = useState<Y>(\n readStorageValue(getInitialValueInEffect),\n )\n\n const setStorageValue = useCallback(\n (valOrFn: ((prevState: Y) => Y) | Y) => {\n if (isFunction(valOrFn)) {\n setValue((current) => {\n const result = valOrFn(current)\n\n window[type].setItem(key, serialize(result))\n window.dispatchEvent(\n new CustomEvent(eventName, {\n detail: { key, value: valOrFn(current) },\n }),\n )\n\n return result\n })\n } else {\n window[type].setItem(key, serialize(valOrFn))\n window.dispatchEvent(\n new CustomEvent(eventName, { detail: { key, value: valOrFn } }),\n )\n\n setValue(valOrFn)\n }\n },\n [key, serialize],\n )\n\n const removeStorageValue = useCallback(() => {\n window[type].removeItem(key)\n setValue(defaultValue as Y)\n }, [defaultValue, key])\n\n useWindowEvent(\"storage\", (ev) => {\n if (ev.storageArea === window[type] && ev.key === key)\n setValue(deserialize(ev.newValue ?? undefined))\n })\n\n useWindowEvent(eventName, (ev) => {\n if (ev.detail.key === key) setValue(ev.detail.value)\n })\n\n useEffect(() => {\n if (defaultValue !== undefined && value === undefined)\n setStorageValue(defaultValue)\n }, [defaultValue, value, setStorageValue])\n\n useEffect(() => {\n if (getInitialValueInEffect) setValue(readStorageValue())\n }, [getInitialValueInEffect, readStorageValue])\n\n return [\n value === undefined ? defaultValue : value,\n setStorageValue,\n removeStorageValue,\n ] as const\n }\n}\n\n/**\n * `useLocalStorage` is a custom hook for storing, updating, and retrieving values in local storage.\n *\n * @see https://yamada-ui.com/docs/hooks/use-local-storage\n */\nexport const useLocalStorage = <Y = string>(props: StorageProps<Y>) =>\n createStorage<Y>(\"localStorage\", \"use-local-storage\")(props)\n"],"mappings":";;;;;;;;AAgBA,MAAM,iBAAoB,OAAU,SAAiB;AACnD,KAAI;AACF,SAAO,KAAK,UAAU,MAAM;SACtB;AACN,QAAM,IAAI,MAAM,mBAAmB,KAAK,iCAAiC;;;AAI7E,MAAM,mBAAmB,UAA8B;AACrD,KAAI,CAAC,MAAO,QAAO;AAEnB,KAAI;AACF,SAAO,KAAK,MAAM,MAAM;SAClB;AACN,SAAO;;;AAIX,MAAa,iBAAoB,MAAmB,SAAiB;CACnE,MAAM,YACJ,SAAS,iBAAiB,kBAAkB;AAE9C,SAAQ,EACN,KACA,eAAe,QACf,cAAc,iBACd,0BAA0B,MAC1B,aAAa,YAAa,cAAcA,SAAO,KAAK,OAC/B;EACrB,MAAM,2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AC;KACxD,CAAC,yBAAyB,iBAAiB,CAAC;AAE/C,SAAO;GACL,UAAU,SAAY,eAAe;GACrC;GACA;GACD;;;;;;;;AASL,MAAa,mBAA+B,UAC1C,cAAiB,gBAAgB,oBAAoB,CAAC,MAAM"}
1
+ {"version":3,"file":"index.cjs","names":["value"],"sources":["../../../../src/hooks/use-local-storage/index.ts"],"sourcesContent":["\"use client\"\n\nimport { useCallback, useEffect, useState } from \"react\"\nimport { isFunction } from \"../../utils\"\nimport { useWindowEvent } from \"../use-window-event\"\n\nexport type StorageType = \"localStorage\" | \"sessionStorage\"\n\nexport interface StorageProps<Y> {\n key: string\n defaultValue?: Y\n getInitialValueInEffect?: boolean\n deserialize?: (value: string | undefined) => Y\n serialize?: (value: Y) => string\n}\n\nconst serializeJSON = <Y>(value: Y, name: string) => {\n try {\n return JSON.stringify(value)\n } catch {\n throw new Error(`useLocalStorage ${name}: Failed to serialize the value`)\n }\n}\n\nconst deserializeJSON = (value: string | undefined) => {\n if (!value) return value\n\n try {\n return JSON.parse(value)\n } catch {\n return value\n }\n}\n\nexport const createStorage = <Y>(type: StorageType, name: string) => {\n const eventName =\n type === \"localStorage\" ? \"local-storage\" : \"session-storage\"\n\n return ({\n key,\n defaultValue = undefined,\n deserialize = deserializeJSON,\n getInitialValueInEffect = true,\n serialize = (value: Y) => serializeJSON(value, name),\n }: StorageProps<Y>) => {\n const readStorageValue = useCallback(\n (skipStorage?: boolean): Y => {\n if (\n typeof window === \"undefined\" ||\n !(type in window) ||\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n window[type] == null ||\n skipStorage\n ) {\n return (defaultValue ?? \"\") as Y\n }\n\n const storageValue = window[type].getItem(key)\n\n return storageValue !== null\n ? deserialize(storageValue)\n : ((defaultValue ?? \"\") as Y)\n },\n [key, deserialize, defaultValue],\n )\n\n const [value, setValue] = useState<Y>(\n readStorageValue(getInitialValueInEffect),\n )\n\n const setStorageValue = useCallback(\n (valOrFn: ((prevState: Y) => Y) | Y) => {\n if (isFunction(valOrFn)) {\n setValue((current) => {\n const result = valOrFn(current)\n\n window[type].setItem(key, serialize(result))\n window.dispatchEvent(\n new CustomEvent(eventName, {\n detail: { key, value: valOrFn(current) },\n }),\n )\n\n return result\n })\n } else {\n window[type].setItem(key, serialize(valOrFn))\n window.dispatchEvent(\n new CustomEvent(eventName, { detail: { key, value: valOrFn } }),\n )\n\n setValue(valOrFn)\n }\n },\n [key, serialize],\n )\n\n const removeStorageValue = useCallback(() => {\n window[type].removeItem(key)\n setValue(defaultValue as Y)\n }, [defaultValue, key])\n\n useWindowEvent(\"storage\", (ev) => {\n if (ev.storageArea === window[type] && ev.key === key)\n setValue(deserialize(ev.newValue ?? undefined))\n })\n\n useWindowEvent(eventName, (ev) => {\n if (ev.detail.key === key) setValue(ev.detail.value)\n })\n\n useEffect(() => {\n if (defaultValue !== undefined && value === undefined)\n setStorageValue(defaultValue)\n }, [defaultValue, value, setStorageValue])\n\n useEffect(() => {\n if (getInitialValueInEffect) setValue(readStorageValue())\n }, [getInitialValueInEffect, readStorageValue])\n\n return [\n value === undefined ? defaultValue : value,\n setStorageValue,\n removeStorageValue,\n ] as const\n }\n}\n\n/**\n * `useLocalStorage` is a custom hook for storing, updating, and retrieving values in local storage.\n *\n * @see https://yamada-ui.com/docs/hooks/use-local-storage\n */\nexport const useLocalStorage = <Y = string>(props: StorageProps<Y>) =>\n createStorage<Y>(\"localStorage\", \"use-local-storage\")(props)\n"],"mappings":";;;;;;;;AAgBA,MAAM,iBAAoB,OAAU,SAAiB;AACnD,KAAI;AACF,SAAO,KAAK,UAAU,MAAM;SACtB;AACN,QAAM,IAAI,MAAM,mBAAmB,KAAK,iCAAiC;;;AAI7E,MAAM,mBAAmB,UAA8B;AACrD,KAAI,CAAC,MAAO,QAAO;AAEnB,KAAI;AACF,SAAO,KAAK,MAAM,MAAM;SAClB;AACN,SAAO;;;AAIX,MAAa,iBAAoB,MAAmB,SAAiB;CACnE,MAAM,YACJ,SAAS,iBAA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B,UAAa,UAAU,OAC1C,iBAAgB,aAAa;KAC9B;GAAC;GAAc;GAAO;GAAgB,CAAC;AAE1C,6BAAgB;AACd,OAAI,wBAAyB,UAAS,kBAAkB,CAAC;KACxD,CAAC,yBAAyB,iBAAiB,CAAC;AAE/C,SAAO;GACL,UAAU,SAAY,eAAe;GACrC;GACA;GACD;;;;;;;;AASL,MAAa,mBAA+B,UAC1C,cAAiB,gBAAgB,oBAAoB,CAAC,MAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"i18n-provider.cjs","names":["DEFAULT_LANGUAGE: Language","DEFAULT_DIRECTION","DEFAULT_LOCALE","INTL","I18nProvider: FC<I18nProviderProps>","locale","value","key","IntlMessageFormat"],"sources":["../../../../src/providers/i18n-provider/i18n-provider.tsx"],"sourcesContent":["\"use client\"\n\nimport type { Formats, Options } from \"intl-messageformat\"\nimport type { FC, ReactNode } from \"react\"\nimport type { TextDirection } from \"../../core\"\nimport type { AnyString, Dict, Path, Value } from \"../../utils\"\nimport type { IcuArgs } from \"./icu.types\"\nimport type { DefaultIntlData } from \"./intl\"\nimport IntlMessageFormat from \"intl-messageformat\"\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\"\nimport { DEFAULT_DIRECTION, DEFAULT_LOCALE } from \"../../core\"\nimport {\n createdDom,\n getMemoizedObject as get,\n isEmptyObject,\n isRtl,\n isString,\n isUndefined,\n noop,\n useUpdateEffect,\n} from \"../../utils\"\nimport INTL from \"./intl\"\n\nexport interface Language {\n dir: TextDirection\n locale: string\n}\n\nconst DEFAULT_LANGUAGE: Language = {\n dir: DEFAULT_DIRECTION,\n locale: DEFAULT_LOCALE,\n}\n\nexport const LOCALES = Object.keys(INTL) as readonly Locale[]\n\nexport function getLanguage(locale?: string, dir?: TextDirection): Language {\n locale ??= createdDom() ? navigator.language : DEFAULT_LOCALE\n\n try {\n Intl.DateTimeFormat.supportedLocalesOf([locale])\n } catch (_err) {\n locale = DEFAULT_LOCALE\n }\n\n dir ??= isRtl(locale) ? \"rtl\" : \"ltr\"\n\n return { dir, locale }\n}\n\ntype IntlData = DefaultIntlData\ntype IntlKey = keyof IntlData\ntype IntlPath = Path<IntlData>\n\nexport type Locale = keyof typeof INTL\n\ntype Translation<Y extends object = IntlData, M extends string = IntlPath> = <\n D extends M,\n>(\n path: D,\n ...args: IcuArgs<Value<Y, D>> extends never\n ? [replaceValues?: IcuArgs<Value<Y, D>, IntlPath | M>]\n : [replaceValues: IcuArgs<Value<Y, D>, IntlPath | M>]\n) => string\n\ninterface I18nContext<\n Y extends object = IntlData,\n M extends string = IntlPath,\n> extends Language {\n changeLanguage: (locale?: string, dir?: TextDirection) => void\n getTranslation: (key?: IntlKey) => Translation<Y, M>\n t: Translation<Y, M>\n}\n\nexport const I18nContext = createContext<I18nContext>({\n ...DEFAULT_LANGUAGE,\n changeLanguage: noop,\n getTranslation: () => () => \"\",\n t: () => \"\",\n})\n\nexport interface I18nProviderProps {\n children?: ReactNode\n /**\n * The text direction to apply to the application.\n *\n * If not provided, the direction will be determined by the locale.\n */\n dir?: TextDirection\n /**\n * The formats to pass to the `intlMessageFormat` instance.\n */\n formats?: Formats\n /**\n * The internationalization messages to apply to the application.\n *\n * This prop expects a dictionary object where the keys are locale strings (e.g., \"en-US\").\n */\n intl?: Dict\n /**\n * The options to pass to the `intlMessageFormat` instance.\n */\n intlMessageFormatOptions?: Options\n /**\n * The locale to apply to the application.\n *\n * If not provided, the locale will be determined by the browser.\n */\n locale?: AnyString | Locale\n}\n\nexport const I18nProvider: FC<I18nProviderProps> = ({\n children,\n dir: forcedDir,\n formats,\n intl = INTL as Dict,\n intlMessageFormatOptions,\n locale: forcedLocale,\n}) => {\n const [language, setLanguage] = useState(getLanguage(forcedLocale, forcedDir))\n const controlled = !isUndefined(forcedLocale)\n const { locale } = language\n\n const messages = useMemo(() => intl[locale], [intl, locale])\n\n const changeSystemLanguage = useCallback(() => {\n setLanguage(getLanguage())\n }, [])\n\n const changeLanguage = useCallback((locale?: string, dir?: TextDirection) => {\n setLanguage(getLanguage(locale, dir))\n }, [])\n\n const getValue = useCallback(\n (path: number | string) => {\n const value = get<string | undefined>(messages, path)\n\n if (!isUndefined(value)) {\n return value\n } else {\n path = path.toString().replace(/^[^.]+\\./g, \"\")\n\n return get<string | undefined>(messages, path)\n }\n },\n [messages],\n )\n\n const getTranslation = useCallback(\n (key?: IntlKey) =>\n <Y extends IntlPath>(\n path: Y,\n replaceValues?: IcuArgs<Value<IntlData, Y>, IntlPath>,\n ) => {\n const value = getValue(key ? `${key}.${path}` : path) ?? path\n\n if (isUndefined(replaceValues)) return value\n\n try {\n const resolvedReplaceValues = Object.entries(replaceValues).reduce<{\n [key: string]: any\n }>((prev, [key, pathOrValue]) => {\n if (isString(pathOrValue)) {\n const resolvedPathOrValue = String(pathOrValue)\n const value =\n getValue(\n key ? `${key}.${resolvedPathOrValue}` : resolvedPathOrValue,\n ) ?? resolvedPathOrValue\n\n prev[key] = value\n } else {\n prev[key] = pathOrValue\n }\n\n return prev\n }, {})\n\n const message = new IntlMessageFormat(\n value,\n locale,\n formats,\n intlMessageFormatOptions,\n )\n\n return message.format(resolvedReplaceValues) as string\n } catch (e) {\n if (e instanceof Error) console.warn(e.message)\n\n return value\n }\n },\n [getValue, locale, formats, intlMessageFormatOptions],\n )\n\n const value = useMemo(() => {\n const rest = { changeLanguage, getTranslation, t: getTranslation() }\n\n return { ...language, ...rest }\n }, [changeLanguage, getTranslation, language])\n\n useEffect(() => {\n if (controlled) return\n\n window.addEventListener(\"languagechange\", changeSystemLanguage)\n\n return () => {\n window.removeEventListener(\"languagechange\", changeSystemLanguage)\n }\n }, [controlled, changeSystemLanguage])\n\n useUpdateEffect(() => {\n setLanguage(getLanguage(forcedLocale, forcedDir))\n }, [forcedLocale, forcedDir])\n\n return <I18nContext value={value}>{children}</I18nContext>\n}\n\nexport function useI18n(): I18nContext\n\nexport function useI18n<Y extends IntlKey>(\n key: Y,\n): I18nContext<IntlData[Y], Path<IntlData[Y]>>\n\nexport function useI18n<Y extends IntlKey>(key?: Y) {\n const context = useContext(I18nContext)\n\n const translation = useCallback(\n <M extends Path<IntlData[Y]>>(\n path: M,\n replaceValues?: IcuArgs<\n Value<IntlData[Y], M>,\n IntlPath | Path<IntlData[Y]>\n >,\n ) => context.getTranslation(key)(path as any, replaceValues as any),\n [key, context],\n )\n\n if (isEmptyObject(context))\n return {\n ...DEFAULT_LANGUAGE,\n changeLanguage: noop,\n t: () => \"\",\n }\n\n if (key) {\n return { ...context, t: translation }\n } else {\n return context\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAmCA,MAAMA,mBAA6B;CACjC,KAAKC;CACL,QAAQC;CACT;AAED,MAAa,UAAU,OAAO,KAAKC,mDAAK;AAExC,SAAgB,YAAY,QAAiB,KAA+B;AAC1E,+DAAuB,GAAG,UAAU,WAAWD;AAE/C,KAAI;AACF,OAAK,eAAe,mBAAmB,CAAC,OAAO,CAAC;UACzC,MAAM;AACb,WAASA;;AAGX,sDAAc,OAAO,GAAG,QAAQ;AAEhC,QAAO;EAAE;EAAK;EAAQ;;AA2BxB,MAAa,uCAAyC;CACpD,GAAG;CACH,kDAAgB;CAChB,4BAA4B;CAC5B,SAAS;CACV,CAAC;AAgCF,MAAaE,gBAAuC,EAClD,UACA,KAAK,WACL,SACA,OAAOD,oDACP,0BACA,QAAQ,mBACJ;CACJ,MAAM,CAAC,UAAU,mCAAwB,YAAY,cAAc,UAAU,CAAC;CAC9E,MAAM,aAAa,oDAAa,aAAa;CAC7C,MAAM,EAAE,WAAW;CAEnB,MAAM,oCAAyB,KAAK,SAAS,CAAC,MAAM,OAAO,CAAC;CAE5D,MAAM,oDAAyC;AAC7C,cAAY,aAAa,CAAC;IACzB,EAAE,CAAC;CAEN,MAAM,yCAA8B,UAAiB,QAAwB;AAC3E,cAAY,YAAYE,UAAQ,IAAI,CAAC;IACpC,EAAE,CAAC;CAEN,MAAM,mCACH,SAA0B;EACzB,MAAMC,mEAAgC,U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AM,gCAAqB,YAAY;CAEvC,MAAM,sCAEF,MACA,kBAIG,QAAQ,eAAe,IAAI,CAAC,MAAa,cAAqB,EACnE,CAAC,KAAK,QAAQ,CACf;AAED,0DAAkB,QAAQ,CACxB,QAAO;EACL,GAAG;EACH,kDAAgB;EAChB,SAAS;EACV;AAEH,KAAI,IACF,QAAO;EAAE,GAAG;EAAS,GAAG;EAAa;KAErC,QAAO"}
1
+ {"version":3,"file":"i18n-provider.cjs","names":["DEFAULT_LANGUAGE: Language","DEFAULT_DIRECTION","DEFAULT_LOCALE","INTL","I18nProvider: FC<I18nProviderProps>","locale","value","key","IntlMessageFormat"],"sources":["../../../../src/providers/i18n-provider/i18n-provider.tsx"],"sourcesContent":["\"use client\"\n\nimport type { Formats, Options } from \"intl-messageformat\"\nimport type { FC, ReactNode } from \"react\"\nimport type { TextDirection } from \"../../core\"\nimport type { AnyString, Dict, Path, Value } from \"../../utils\"\nimport type { IcuArgs } from \"./icu.types\"\nimport type { DefaultIntlData } from \"./intl\"\nimport IntlMessageFormat from \"intl-messageformat\"\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\"\nimport { DEFAULT_DIRECTION, DEFAULT_LOCALE } from \"../../core\"\nimport {\n createdDom,\n getMemoizedObject as get,\n isEmptyObject,\n isRtl,\n isString,\n isUndefined,\n noop,\n useUpdateEffect,\n} from \"../../utils\"\nimport INTL from \"./intl\"\n\nexport interface Language {\n dir: TextDirection\n locale: string\n}\n\nconst DEFAULT_LANGUAGE: Language = {\n dir: DEFAULT_DIRECTION,\n locale: DEFAULT_LOCALE,\n}\n\nexport const LOCALES = Object.keys(INTL) as readonly Locale[]\n\nexport function getLanguage(locale?: string, dir?: TextDirection): Language {\n locale ??= createdDom() ? navigator.language : DEFAULT_LOCALE\n\n try {\n Intl.DateTimeFormat.supportedLocalesOf([locale])\n } catch (_err) {\n locale = DEFAULT_LOCALE\n }\n\n dir ??= isRtl(locale) ? \"rtl\" : \"ltr\"\n\n return { dir, locale }\n}\n\ntype IntlData = DefaultIntlData\ntype IntlKey = keyof IntlData\ntype IntlPath = Path<IntlData>\n\nexport type Locale = keyof typeof INTL\n\ntype Translation<Y extends object = IntlData, M extends string = IntlPath> = <\n D extends M,\n>(\n path: D,\n ...args: IcuArgs<Value<Y, D>> extends never\n ? [replaceValues?: IcuArgs<Value<Y, D>, IntlPath | M>]\n : [replaceValues: IcuArgs<Value<Y, D>, IntlPath | M>]\n) => string\n\ninterface I18nContext<\n Y extends object = IntlData,\n M extends string = IntlPath,\n> extends Language {\n t: Translation<Y, M>\n changeLanguage: (locale?: string, dir?: TextDirection) => void\n getTranslation: (key?: IntlKey) => Translation<Y, M>\n}\n\nexport const I18nContext = createContext<I18nContext>({\n ...DEFAULT_LANGUAGE,\n changeLanguage: noop,\n getTranslation: () => () => \"\",\n t: () => \"\",\n})\n\nexport interface I18nProviderProps {\n children?: ReactNode\n /**\n * The text direction to apply to the application.\n *\n * If not provided, the direction will be determined by the locale.\n */\n dir?: TextDirection\n /**\n * The formats to pass to the `intlMessageFormat` instance.\n */\n formats?: Formats\n /**\n * The internationalization messages to apply to the application.\n *\n * This prop expects a dictionary object where the keys are locale strings (e.g., \"en-US\").\n */\n intl?: Dict\n /**\n * The options to pass to the `intlMessageFormat` instance.\n */\n intlMessageFormatOptions?: Options\n /**\n * The locale to apply to the application.\n *\n * If not provided, the locale will be determined by the browser.\n */\n locale?: AnyString | Locale\n}\n\nexport const I18nProvider: FC<I18nProviderProps> = ({\n children,\n dir: forcedDir,\n formats,\n intl = INTL as Dict,\n intlMessageFormatOptions,\n locale: forcedLocale,\n}) => {\n const [language, setLanguage] = useState(getLanguage(forcedLocale, forcedDir))\n const controlled = !isUndefined(forcedLocale)\n const { locale } = language\n\n const messages = useMemo(() => intl[locale], [intl, locale])\n\n const changeSystemLanguage = useCallback(() => {\n setLanguage(getLanguage())\n }, [])\n\n const changeLanguage = useCallback((locale?: string, dir?: TextDirection) => {\n setLanguage(getLanguage(locale, dir))\n }, [])\n\n const getValue = useCallback(\n (path: number | string) => {\n const value = get<string | undefined>(messages, path)\n\n if (!isUndefined(value)) {\n return value\n } else {\n path = path.toString().replace(/^[^.]+\\./g, \"\")\n\n return get<string | undefined>(messages, path)\n }\n },\n [messages],\n )\n\n const getTranslation = useCallback(\n (key?: IntlKey) =>\n <Y extends IntlPath>(\n path: Y,\n replaceValues?: IcuArgs<Value<IntlData, Y>, IntlPath>,\n ) => {\n const value = getValue(key ? `${key}.${path}` : path) ?? path\n\n if (isUndefined(replaceValues)) return value\n\n try {\n const resolvedReplaceValues = Object.entries(replaceValues).reduce<{\n [key: string]: any\n }>((prev, [key, pathOrValue]) => {\n if (isString(pathOrValue)) {\n const resolvedPathOrValue = String(pathOrValue)\n const value =\n getValue(\n key ? `${key}.${resolvedPathOrValue}` : resolvedPathOrValue,\n ) ?? resolvedPathOrValue\n\n prev[key] = value\n } else {\n prev[key] = pathOrValue\n }\n\n return prev\n }, {})\n\n const message = new IntlMessageFormat(\n value,\n locale,\n formats,\n intlMessageFormatOptions,\n )\n\n return message.format(resolvedReplaceValues) as string\n } catch (e) {\n if (e instanceof Error) console.warn(e.message)\n\n return value\n }\n },\n [getValue, locale, formats, intlMessageFormatOptions],\n )\n\n const value = useMemo(() => {\n const rest = { changeLanguage, getTranslation, t: getTranslation() }\n\n return { ...language, ...rest }\n }, [changeLanguage, getTranslation, language])\n\n useEffect(() => {\n if (controlled) return\n\n window.addEventListener(\"languagechange\", changeSystemLanguage)\n\n return () => {\n window.removeEventListener(\"languagechange\", changeSystemLanguage)\n }\n }, [controlled, changeSystemLanguage])\n\n useUpdateEffect(() => {\n setLanguage(getLanguage(forcedLocale, forcedDir))\n }, [forcedLocale, forcedDir])\n\n return <I18nContext value={value}>{children}</I18nContext>\n}\n\nexport function useI18n(): I18nContext\n\nexport function useI18n<Y extends IntlKey>(\n key: Y,\n): I18nContext<IntlData[Y], Path<IntlData[Y]>>\n\nexport function useI18n<Y extends IntlKey>(key?: Y) {\n const context = useContext(I18nContext)\n\n const translation = useCallback(\n <M extends Path<IntlData[Y]>>(\n path: M,\n replaceValues?: IcuArgs<\n Value<IntlData[Y], M>,\n IntlPath | Path<IntlData[Y]>\n >,\n ) => context.getTranslation(key)(path as any, replaceValues as any),\n [key, context],\n )\n\n if (isEmptyObject(context))\n return {\n ...DEFAULT_LANGUAGE,\n changeLanguage: noop,\n t: () => \"\",\n }\n\n if (key) {\n return { ...context, t: translation }\n } else {\n return context\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAmCA,MAAMA,mBAA6B;CACjC,KAAKC;CACL,QAAQC;CACT;AAED,MAAa,UAAU,OAAO,KAAKC,mDAAK;AAExC,SAAgB,YAAY,QAAiB,KAA+B;AAC1E,+DAAuB,GAAG,UAAU,WAAWD;AAE/C,KAAI;AACF,OAAK,eAAe,mBAAmB,CAAC,OAAO,CAAC;UACzC,MAAM;AACb,WAASA;;AAGX,sDAAc,OAAO,GAAG,QAAQ;AAEhC,QAAO;EAAE;EAAK;EAAQ;;AA2BxB,MAAa,uCAAyC;CACpD,GAAG;CACH,kDAAgB;CAChB,4BAA4B;CAC5B,SAAS;CACV,CAAC;AAgCF,MAAaE,gBAAuC,EAClD,UACA,KAAK,WACL,SACA,OAAOD,oDACP,0BACA,QAAQ,mBACJ;CACJ,MAAM,CAAC,UAAU,mCAAwB,YAAY,cAAc,UAAU,CAAC;CAC9E,MAAM,aAAa,oDAAa,aAAa;CAC7C,MAAM,EAAE,WAAW;CAEnB,MAAM,oCAAyB,KAAK,SAAS,CAAC,MAAM,OAAO,CAAC;CAE5D,MAAM,oDAAyC;AAC7C,cAAY,aAAa,CAAC;IACzB,EAAE,CAAC;CAEN,MAAM,yCAA8B,UAAiB,QAAwB;AAC3E,cAAY,YAAYE,UAAQ,IAAI,CAAC;IACpC,EAAE,CAAC;CAEN,MAAM,mCACH,SAA0B;EACzB,MAAMC,mEAAgC,UAAU,KAAK;AAErD,MAAI,oDAAaA,QAAM,CACrB,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kBAIG,QAAQ,eAAe,IAAI,CAAC,MAAa,cAAqB,EACnE,CAAC,KAAK,QAAQ,CACf;AAED,0DAAkB,QAAQ,CACxB,QAAO;EACL,GAAG;EACH,kDAAgB;EAChB,SAAS;EACV;AAEH,KAAI,IACF,QAAO;EAAE,GAAG;EAAS,GAAG;EAAa;KAErC,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"context.cjs","names":["React"],"sources":["../../../src/utils/context.ts"],"sourcesContent":["\"use client\"\n\nimport { use } from \"react\"\nimport * as React from \"react\"\n\nfunction getErrorMessage(hookName: string, ContextName: string) {\n return `${hookName} returned \\`undefined\\`. Seems you forgot to wrap component within ${ContextName}`\n}\n\ninterface Options<Y = any> {\n name?: string\n defaultValue?: Y\n errorMessage?: string\n hookName?: string\n strict?: boolean\n}\n\ntype CreateContextReturn<Y> = [React.Context<Y>, () => Y]\n\nexport function createContext<Y = any>(options: {\n name?: string\n defaultValue?: Y\n errorMessage?: string\n hookName?: string\n strict?: true\n}): CreateContextReturn<Y>\nexport function createContext<Y = any>(options: {\n name?: string\n defaultValue: Y\n errorMessage?: string\n hookName?: string\n strict?: false\n}): CreateContextReturn<Y>\nexport function createContext<Y = any>(options: {\n name?: string\n defaultValue?: Y\n errorMessage?: string\n hookName?: string\n strict?: false\n}): CreateContextReturn<undefined | Y>\n\nexport function createContext<Y = any>({\n name = \"Context\",\n defaultValue,\n errorMessage,\n hookName = `use${name}`,\n strict = true,\n}: Options<Y> = {}) {\n const Context = React.createContext<undefined | Y>(defaultValue)\n\n Context.displayName = name\n\n const useContext = () => {\n const context = use(Context)\n\n if (!context && strict) {\n const error = new Error(errorMessage ?? getErrorMessage(hookName, name))\n error.name = \"ContextError\"\n Error.captureStackTrace(error, useContext)\n throw error\n }\n\n return context\n }\n\n return [Context, useContext] as CreateContextReturn<undefined | Y>\n}\n"],"mappings":";;;;;;;AAKA,SAAS,gBAAgB,UAAkB,aAAqB;AAC9D,QAAO,GAAG,SAAS,qEAAqE;;AAmC1F,SAAgB,cAAuB,EACrC,OAAO,WACP,cACA,cACA,WAAW,MAAM,QACjB,SAAS,SACK,EAAE,EAAE;CAClB,MAAM,UAAUA,MAAM,cAA6B,aAAa;AAEhE,SAAQ,cAAc;CAEtB,MAAM,mBAAmB;EACvB,MAAM,yBAAc,QAAQ;AAE5B,MAAI,CAAC,WAAW,QAAQ;GACtB,MAAM,QAAQ,IAAI,MAAM,gBAAgB,gBAAgB,UAAU,KAAK,CAAC;AACxE,SAAM,OAAO;AACb,SAAM,kBAAkB,OAAO,WAAW;AAC1C,SAAM;;AAGR,SAAO;;AAGT,QAAO,CAAC,SAAS,WAAW"}
1
+ {"version":3,"file":"context.cjs","names":["React"],"sources":["../../../src/utils/context.ts"],"sourcesContent":["\"use client\"\n\nimport { use } from \"react\"\nimport * as React from \"react\"\n\nfunction getErrorMessage(hookName: string, ContextName: string) {\n return `${hookName} returned \\`undefined\\`. Seems you forgot to wrap component within ${ContextName}`\n}\n\ninterface Options<Y = any> {\n defaultValue?: Y\n errorMessage?: string\n hookName?: string\n name?: string\n strict?: boolean\n}\n\ntype CreateContextReturn<Y> = [React.Context<Y>, () => Y]\n\nexport function createContext<Y = any>(options: {\n defaultValue?: Y\n errorMessage?: string\n hookName?: string\n name?: string\n strict?: true\n}): CreateContextReturn<Y>\nexport function createContext<Y = any>(options: {\n defaultValue: Y\n errorMessage?: string\n hookName?: string\n name?: string\n strict?: false\n}): CreateContextReturn<Y>\nexport function createContext<Y = any>(options: {\n defaultValue?: Y\n errorMessage?: string\n hookName?: string\n name?: string\n strict?: false\n}): CreateContextReturn<undefined | Y>\n\nexport function createContext<Y = any>({\n name = \"Context\",\n defaultValue,\n errorMessage,\n hookName = `use${name}`,\n strict = true,\n}: Options<Y> = {}) {\n const Context = React.createContext<undefined | Y>(defaultValue)\n\n Context.displayName = name\n\n const useContext = () => {\n const context = use(Context)\n\n if (!context && strict) {\n const error = new Error(errorMessage ?? getErrorMessage(hookName, name))\n error.name = \"ContextError\"\n Error.captureStackTrace(error, useContext)\n throw error\n }\n\n return context\n }\n\n return [Context, useContext] as CreateContextReturn<undefined | Y>\n}\n"],"mappings":";;;;;;;AAKA,SAAS,gBAAgB,UAAkB,aAAqB;AAC9D,QAAO,GAAG,SAAS,qEAAqE;;AAmC1F,SAAgB,cAAuB,EACrC,OAAO,WACP,cACA,cACA,WAAW,MAAM,QACjB,SAAS,SACK,EAAE,EAAE;CAClB,MAAM,UAAUA,MAAM,cAA6B,aAAa;AAEhE,SAAQ,cAAc;CAEtB,MAAM,mBAAmB;EACvB,MAAM,yBAAc,QAAQ;AAE5B,MAAI,CAAC,WAAW,QAAQ;GACtB,MAAM,QAAQ,IAAI,MAAM,gBAAgB,gBAAgB,UAAU,KAAK,CAAC;AACxE,SAAM,OAAO;AACb,SAAM,kBAAkB,OAAO,WAAW;AAC1C,SAAM;;AAGR,SAAO;;AAGT,QAAO,CAAC,SAAS,WAAW"}