@funstack/ui 0.1.0-alpha.18 → 0.1.0-alpha.19

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 (345) hide show
  1. package/dist/accordion/accordion-item.mjs +1 -1
  2. package/dist/accordion/accordion-panel.mjs +1 -1
  3. package/dist/accordion/accordion-root.d.mts.map +1 -1
  4. package/dist/accordion/accordion-root.mjs +30 -35
  5. package/dist/accordion/accordion-root.mjs.map +1 -1
  6. package/dist/accordion/accordion-trigger.mjs +1 -1
  7. package/dist/button/button.d.mts +11 -6
  8. package/dist/button/button.d.mts.map +1 -1
  9. package/dist/button/button.mjs +25 -14
  10. package/dist/button/button.mjs.map +1 -1
  11. package/dist/checkbox/checkbox.mjs +1 -1
  12. package/dist/checkbox/checkbox.mjs.map +1 -1
  13. package/dist/checkbox-group/checkbox-group-item.mjs +3 -3
  14. package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -1
  15. package/dist/checkbox-group/checkbox-group-parent.mjs +3 -3
  16. package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -1
  17. package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
  18. package/dist/checkbox-group/checkbox-group-root.mjs +5 -5
  19. package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
  20. package/dist/combobox/combobox-context.mjs.map +1 -1
  21. package/dist/combobox/combobox-input.mjs +2 -2
  22. package/dist/combobox/combobox-input.mjs.map +1 -1
  23. package/dist/combobox/combobox-keyboard.mjs +81 -0
  24. package/dist/combobox/combobox-keyboard.mjs.map +1 -0
  25. package/dist/combobox/combobox-popup.mjs +3 -3
  26. package/dist/combobox/combobox-popup.mjs.map +1 -1
  27. package/dist/combobox/combobox-root.d.mts.map +1 -1
  28. package/dist/combobox/combobox-root.mjs +44 -129
  29. package/dist/combobox/combobox-root.mjs.map +1 -1
  30. package/dist/combobox/combobox-trigger.d.mts.map +1 -1
  31. package/dist/combobox/combobox-trigger.mjs +2 -9
  32. package/dist/combobox/combobox-trigger.mjs.map +1 -1
  33. package/dist/combobox/use-active-option.mjs +49 -0
  34. package/dist/combobox/use-active-option.mjs.map +1 -0
  35. package/dist/combobox/use-combobox-form.mjs +3 -5
  36. package/dist/combobox/use-combobox-form.mjs.map +1 -1
  37. package/dist/combobox/use-combobox-text.mjs +43 -0
  38. package/dist/combobox/use-combobox-text.mjs.map +1 -0
  39. package/dist/combobox/use-option-registry.mjs +7 -17
  40. package/dist/combobox/use-option-registry.mjs.map +1 -1
  41. package/dist/dialog/dialog-close.mjs +2 -2
  42. package/dist/dialog/dialog-close.mjs.map +1 -1
  43. package/dist/dialog/dialog-context.mjs.map +1 -1
  44. package/dist/dialog/dialog-dismiss.mjs +108 -0
  45. package/dist/dialog/dialog-dismiss.mjs.map +1 -0
  46. package/dist/dialog/dialog-form.mjs +4 -4
  47. package/dist/dialog/dialog-form.mjs.map +1 -1
  48. package/dist/dialog/dialog-popup.d.mts.map +1 -1
  49. package/dist/dialog/dialog-popup.mjs +73 -169
  50. package/dist/dialog/dialog-popup.mjs.map +1 -1
  51. package/dist/dialog/dialog-root.d.mts.map +1 -1
  52. package/dist/dialog/dialog-root.mjs +4 -3
  53. package/dist/dialog/dialog-root.mjs.map +1 -1
  54. package/dist/dialog/dialog-trigger.mjs +11 -8
  55. package/dist/dialog/dialog-trigger.mjs.map +1 -1
  56. package/dist/docs/components/button.md +3 -3
  57. package/dist/docs/components/dialog.md +3 -3
  58. package/dist/docs/components/field.md +4 -3
  59. package/dist/docs/components/popover.md +3 -3
  60. package/dist/docs/components/toast.md +8 -5
  61. package/dist/docs/roadmap.md +9 -1
  62. package/dist/field/field-control.d.mts +1 -1
  63. package/dist/field/field-control.mjs +2 -2
  64. package/dist/field/field-control.mjs.map +1 -1
  65. package/dist/field/field-description.d.mts +1 -1
  66. package/dist/field/field-description.mjs +1 -1
  67. package/dist/field/field-description.mjs.map +1 -1
  68. package/dist/field/field-error.d.mts +1 -1
  69. package/dist/field/field-error.mjs +1 -1
  70. package/dist/field/field-error.mjs.map +1 -1
  71. package/dist/field/field-label.d.mts +1 -1
  72. package/dist/field/field-label.mjs +1 -1
  73. package/dist/field/field-label.mjs.map +1 -1
  74. package/dist/field/field-root.d.mts +2 -2
  75. package/dist/field/field-root.d.mts.map +1 -1
  76. package/dist/field/field-root.mjs +4 -4
  77. package/dist/field/field-root.mjs.map +1 -1
  78. package/dist/field/index.d.mts +2 -2
  79. package/dist/form/form-root.d.mts +1 -1
  80. package/dist/form/form-root.d.mts.map +1 -1
  81. package/dist/form/form-root.mjs +14 -4
  82. package/dist/form/form-root.mjs.map +1 -1
  83. package/dist/form/form-submit.d.mts +7 -3
  84. package/dist/form/form-submit.d.mts.map +1 -1
  85. package/dist/form/form-submit.mjs +11 -7
  86. package/dist/form/form-submit.mjs.map +1 -1
  87. package/dist/form/index.d.mts +1 -1
  88. package/dist/index.d.mts +2 -2
  89. package/dist/internal/{action-details.mjs → action/action-details.mjs} +1 -1
  90. package/dist/internal/action/action-details.mjs.map +1 -0
  91. package/dist/internal/{call-urgent-handler.mjs → action/call-urgent-handler.mjs} +5 -10
  92. package/dist/internal/action/call-urgent-handler.mjs.map +1 -0
  93. package/dist/internal/{report-dropped.mjs → action/report-dropped.mjs} +3 -21
  94. package/dist/internal/action/report-dropped.mjs.map +1 -0
  95. package/dist/internal/{use-action-trigger.mjs → action/use-action-trigger.mjs} +3 -2
  96. package/dist/internal/action/use-action-trigger.mjs.map +1 -0
  97. package/dist/internal/action/use-connected.mjs +24 -0
  98. package/dist/internal/action/use-connected.mjs.map +1 -0
  99. package/dist/internal/{use-controllable-action.mjs → action/use-controllable-action.mjs} +13 -28
  100. package/dist/internal/action/use-controllable-action.mjs.map +1 -0
  101. package/dist/internal/action/use-pure-trigger.mjs +34 -0
  102. package/dist/internal/action/use-pure-trigger.mjs.map +1 -0
  103. package/dist/internal/action/use-step-commit.mjs +147 -0
  104. package/dist/internal/action/use-step-commit.mjs.map +1 -0
  105. package/dist/internal/{field-context.d.mts → form/field-context.d.mts} +1 -1
  106. package/dist/internal/form/field-context.d.mts.map +1 -0
  107. package/dist/internal/{field-context.mjs → form/field-context.mjs} +2 -2
  108. package/dist/internal/form/field-context.mjs.map +1 -0
  109. package/dist/internal/{focus-first-invalid.mjs → form/focus-first-invalid.mjs} +3 -3
  110. package/dist/internal/form/focus-first-invalid.mjs.map +1 -0
  111. package/dist/internal/{form-status-watcher.mjs → form/form-status-watcher.mjs} +1 -1
  112. package/dist/internal/form/form-status-watcher.mjs.map +1 -0
  113. package/dist/internal/{group-member.mjs → form/group-member.mjs} +2 -2
  114. package/dist/internal/form/group-member.mjs.map +1 -0
  115. package/dist/internal/{sync-presence.mjs → form/sync-presence.mjs} +1 -1
  116. package/dist/internal/form/sync-presence.mjs.map +1 -0
  117. package/dist/internal/{use-checkable-input.mjs → form/use-checkable-input.mjs} +5 -5
  118. package/dist/internal/form/use-checkable-input.mjs.map +1 -0
  119. package/dist/internal/{use-field-control.mjs → form/use-field-control.mjs} +3 -3
  120. package/dist/internal/form/use-field-control.mjs.map +1 -0
  121. package/dist/internal/{use-fieldset-group.mjs → form/use-fieldset-group.mjs} +3 -3
  122. package/dist/internal/form/use-fieldset-group.mjs.map +1 -0
  123. package/dist/internal/{use-form-owner-event.mjs → form/use-form-owner-event.mjs} +1 -1
  124. package/dist/internal/form/use-form-owner-event.mjs.map +1 -0
  125. package/dist/internal/{use-form-reset.mjs → form/use-form-reset.mjs} +15 -3
  126. package/dist/internal/form/use-form-reset.mjs.map +1 -0
  127. package/dist/internal/{use-native-checked.mjs → form/use-native-checked.mjs} +5 -4
  128. package/dist/internal/form/use-native-checked.mjs.map +1 -0
  129. package/dist/internal/{use-native-group-reconciliation.mjs → form/use-native-group-reconciliation.mjs} +2 -2
  130. package/dist/internal/form/use-native-group-reconciliation.mjs.map +1 -0
  131. package/dist/internal/{use-native-select-value.mjs → form/use-native-select-value.mjs} +2 -2
  132. package/dist/internal/form/use-native-select-value.mjs.map +1 -0
  133. package/dist/internal/{validity.d.mts → form/validity.d.mts} +1 -1
  134. package/dist/internal/form/validity.d.mts.map +1 -0
  135. package/dist/internal/{validity.mjs → form/validity.mjs} +1 -1
  136. package/dist/internal/form/validity.mjs.map +1 -0
  137. package/dist/internal/{anchor-position.d.mts → overlay/anchor-position.d.mts} +1 -1
  138. package/dist/internal/overlay/anchor-position.d.mts.map +1 -0
  139. package/dist/internal/{anchor-position.mjs → overlay/anchor-position.mjs} +1 -1
  140. package/dist/internal/overlay/anchor-position.mjs.map +1 -0
  141. package/dist/internal/{content-focus-probe.mjs → overlay/content-focus-probe.mjs} +1 -1
  142. package/dist/internal/overlay/content-focus-probe.mjs.map +1 -0
  143. package/dist/internal/{css-transition-cut.mjs → overlay/css-transition-cut.mjs} +1 -1
  144. package/dist/internal/overlay/css-transition-cut.mjs.map +1 -0
  145. package/dist/internal/{focus-visible.mjs → overlay/focus-visible.mjs} +1 -1
  146. package/dist/internal/overlay/focus-visible.mjs.map +1 -0
  147. package/dist/internal/{invokers.mjs → overlay/invokers.mjs} +1 -1
  148. package/dist/internal/overlay/invokers.mjs.map +1 -0
  149. package/dist/internal/{modal-registry.mjs → overlay/modal-registry.mjs} +1 -1
  150. package/dist/internal/overlay/modal-registry.mjs.map +1 -0
  151. package/dist/internal/{overlay-popup.mjs → overlay/overlay-popup.mjs} +3 -3
  152. package/dist/internal/overlay/overlay-popup.mjs.map +1 -0
  153. package/dist/internal/overlay/overlay-show.mjs +73 -0
  154. package/dist/internal/overlay/overlay-show.mjs.map +1 -0
  155. package/dist/internal/{popover-open.mjs → overlay/popover-open.mjs} +1 -1
  156. package/dist/internal/overlay/popover-open.mjs.map +1 -0
  157. package/dist/internal/{trigger-ref.mjs → overlay/trigger-ref.mjs} +1 -1
  158. package/dist/internal/overlay/trigger-ref.mjs.map +1 -0
  159. package/dist/internal/overlay/use-apply-open-state.mjs +44 -0
  160. package/dist/internal/overlay/use-apply-open-state.mjs.map +1 -0
  161. package/dist/internal/{use-exit-animation.mjs → overlay/use-exit-animation.mjs} +2 -2
  162. package/dist/internal/overlay/use-exit-animation.mjs.map +1 -0
  163. package/dist/internal/{use-interest-dismiss.mjs → overlay/use-interest-dismiss.mjs} +1 -1
  164. package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -0
  165. package/dist/internal/{use-modal-registration.mjs → overlay/use-modal-registration.mjs} +1 -1
  166. package/dist/internal/overlay/use-modal-registration.mjs.map +1 -0
  167. package/dist/internal/{use-overlay-close.mjs → overlay/use-overlay-close.mjs} +14 -13
  168. package/dist/internal/overlay/use-overlay-close.mjs.map +1 -0
  169. package/dist/internal/overlay/use-overlay-root.d.mts +2 -0
  170. package/dist/internal/{use-overlay-root.mjs → overlay/use-overlay-root.mjs} +44 -28
  171. package/dist/internal/overlay/use-overlay-root.mjs.map +1 -0
  172. package/dist/internal/{use-popover-popup.mjs → overlay/use-popover-popup.mjs} +74 -66
  173. package/dist/internal/overlay/use-popover-popup.mjs.map +1 -0
  174. package/dist/internal/{use-popover-trigger.d.mts → overlay/use-popover-trigger.d.mts} +3 -3
  175. package/dist/internal/overlay/use-popover-trigger.d.mts.map +1 -0
  176. package/dist/internal/{use-popover-trigger.mjs → overlay/use-popover-trigger.mjs} +47 -26
  177. package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -0
  178. package/dist/internal/{use-resolved-placement.mjs → overlay/use-resolved-placement.mjs} +2 -2
  179. package/dist/internal/overlay/use-resolved-placement.mjs.map +1 -0
  180. package/dist/internal/render-element.mjs +47 -9
  181. package/dist/internal/render-element.mjs.map +1 -1
  182. package/dist/internal/transition-boundary.mjs +4 -8
  183. package/dist/internal/transition-boundary.mjs.map +1 -1
  184. package/dist/internal/use-mount-fixed.mjs +22 -0
  185. package/dist/internal/use-mount-fixed.mjs.map +1 -0
  186. package/dist/internal/use-register-count.mjs +4 -1
  187. package/dist/internal/use-register-count.mjs.map +1 -1
  188. package/dist/internal/use-render.mjs +2 -2
  189. package/dist/internal/use-render.mjs.map +1 -1
  190. package/dist/internal/use-roving-focus.mjs.map +1 -1
  191. package/dist/menu/menu-checkbox-item.mjs +2 -2
  192. package/dist/menu/menu-checkbox-item.mjs.map +1 -1
  193. package/dist/menu/menu-context.d.mts +1 -1
  194. package/dist/menu/menu-context.mjs.map +1 -1
  195. package/dist/menu/menu-gestures.mjs +1 -1
  196. package/dist/menu/menu-gestures.mjs.map +1 -1
  197. package/dist/menu/menu-item.d.mts.map +1 -1
  198. package/dist/menu/menu-item.mjs +9 -10
  199. package/dist/menu/menu-item.mjs.map +1 -1
  200. package/dist/menu/menu-outside.mjs +1 -1
  201. package/dist/menu/menu-outside.mjs.map +1 -1
  202. package/dist/menu/menu-popup.d.mts +1 -1
  203. package/dist/menu/menu-popup.d.mts.map +1 -1
  204. package/dist/menu/menu-popup.mjs +10 -6
  205. package/dist/menu/menu-popup.mjs.map +1 -1
  206. package/dist/menu/menu-radio-group.mjs +2 -2
  207. package/dist/menu/menu-radio-group.mjs.map +1 -1
  208. package/dist/menu/menu-root.mjs +2 -2
  209. package/dist/menu/menu-root.mjs.map +1 -1
  210. package/dist/menu/menu-submenu-trigger.mjs +3 -3
  211. package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
  212. package/dist/menu/menu-trigger.d.mts +1 -1
  213. package/dist/menu/menu-trigger.mjs +3 -3
  214. package/dist/menu/menu-trigger.mjs.map +1 -1
  215. package/dist/number-field/number-field-input.mjs +1 -1
  216. package/dist/number-field/number-field-input.mjs.map +1 -1
  217. package/dist/number-field/number-field-root.d.mts.map +1 -1
  218. package/dist/number-field/number-field-root.mjs +43 -107
  219. package/dist/number-field/number-field-root.mjs.map +1 -1
  220. package/dist/popover/popover-close.mjs +3 -3
  221. package/dist/popover/popover-close.mjs.map +1 -1
  222. package/dist/popover/popover-context.mjs.map +1 -1
  223. package/dist/popover/popover-popup.d.mts +1 -1
  224. package/dist/popover/popover-popup.mjs +3 -3
  225. package/dist/popover/popover-popup.mjs.map +1 -1
  226. package/dist/popover/popover-root.mjs +2 -2
  227. package/dist/popover/popover-root.mjs.map +1 -1
  228. package/dist/popover/popover-trigger.d.mts +1 -1
  229. package/dist/popover/popover-trigger.mjs +1 -1
  230. package/dist/popover/popover-trigger.mjs.map +1 -1
  231. package/dist/radio-group/radio-group-item.mjs +3 -3
  232. package/dist/radio-group/radio-group-item.mjs.map +1 -1
  233. package/dist/radio-group/radio-group-root.d.mts.map +1 -1
  234. package/dist/radio-group/radio-group-root.mjs +5 -5
  235. package/dist/radio-group/radio-group-root.mjs.map +1 -1
  236. package/dist/select/select-group-label.d.mts.map +1 -1
  237. package/dist/select/select-group-label.mjs +3 -1
  238. package/dist/select/select-group-label.mjs.map +1 -1
  239. package/dist/select/select-option.mjs +1 -1
  240. package/dist/select/select-option.mjs.map +1 -1
  241. package/dist/select/select-root.d.mts.map +1 -1
  242. package/dist/select/select-root.mjs +7 -7
  243. package/dist/select/select-root.mjs.map +1 -1
  244. package/dist/select/select-trigger.d.mts.map +1 -1
  245. package/dist/select/select-trigger.mjs +3 -1
  246. package/dist/select/select-trigger.mjs.map +1 -1
  247. package/dist/select/select-value.mjs +3 -6
  248. package/dist/select/select-value.mjs.map +1 -1
  249. package/dist/slider/slider-root.d.mts.map +1 -1
  250. package/dist/slider/slider-root.mjs +38 -104
  251. package/dist/slider/slider-root.mjs.map +1 -1
  252. package/dist/slider/use-thumb-registry.mjs.map +1 -1
  253. package/dist/switch/switch.mjs +1 -1
  254. package/dist/switch/switch.mjs.map +1 -1
  255. package/dist/tabs/tabs-panel.mjs +1 -1
  256. package/dist/tabs/tabs-panel.mjs.map +1 -1
  257. package/dist/tabs/tabs-root.d.mts.map +1 -1
  258. package/dist/tabs/tabs-root.mjs +4 -4
  259. package/dist/tabs/tabs-root.mjs.map +1 -1
  260. package/dist/{internal → tabs}/use-until-found.mjs +1 -1
  261. package/dist/tabs/use-until-found.mjs.map +1 -0
  262. package/dist/toast/toast-action.d.mts +13 -3
  263. package/dist/toast/toast-action.d.mts.map +1 -1
  264. package/dist/toast/toast-action.mjs +23 -13
  265. package/dist/toast/toast-action.mjs.map +1 -1
  266. package/dist/toast/toast-close.d.mts +13 -2
  267. package/dist/toast/toast-close.d.mts.map +1 -1
  268. package/dist/toast/toast-close.mjs +16 -6
  269. package/dist/toast/toast-close.mjs.map +1 -1
  270. package/dist/toast/toast-root.mjs +1 -1
  271. package/dist/toast/toast-root.mjs.map +1 -1
  272. package/dist/toast/toast-viewport.d.mts.map +1 -1
  273. package/dist/toast/toast-viewport.mjs +48 -143
  274. package/dist/toast/toast-viewport.mjs.map +1 -1
  275. package/dist/toast/use-modal-portal-host.mjs +1 -1
  276. package/dist/toast/use-modal-portal-host.mjs.map +1 -1
  277. package/dist/toast/use-toast-announcements.mjs +46 -0
  278. package/dist/toast/use-toast-announcements.mjs.map +1 -0
  279. package/dist/toast/use-toast-focus.mjs +75 -0
  280. package/dist/toast/use-toast-focus.mjs.map +1 -0
  281. package/dist/toast/use-toast-pauses.mjs +58 -0
  282. package/dist/toast/use-toast-pauses.mjs.map +1 -0
  283. package/dist/toggle/toggle.mjs +2 -2
  284. package/dist/toggle/toggle.mjs.map +1 -1
  285. package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
  286. package/dist/toggle-group/toggle-group-root.mjs +5 -5
  287. package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
  288. package/dist/tooltip/tooltip-context.d.mts +1 -1
  289. package/dist/tooltip/tooltip-context.mjs.map +1 -1
  290. package/dist/tooltip/tooltip-popup.mjs +1 -1
  291. package/dist/tooltip/tooltip-popup.mjs.map +1 -1
  292. package/dist/tooltip/tooltip-root.d.mts.map +1 -1
  293. package/dist/tooltip/tooltip-root.mjs +9 -4
  294. package/dist/tooltip/tooltip-root.mjs.map +1 -1
  295. package/dist/tooltip/tooltip-trigger.mjs +1 -1
  296. package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
  297. package/dist/{internal → tooltip}/tooltip-warm.mjs +1 -1
  298. package/dist/tooltip/tooltip-warm.mjs.map +1 -0
  299. package/dist/tooltip/use-tooltip-interaction.mjs +2 -2
  300. package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
  301. package/package.json +1 -1
  302. package/skills/funstack-ui-knowledge/SKILL.md +1 -1
  303. package/dist/internal/action-details.mjs.map +0 -1
  304. package/dist/internal/anchor-position.d.mts.map +0 -1
  305. package/dist/internal/anchor-position.mjs.map +0 -1
  306. package/dist/internal/call-urgent-handler.mjs.map +0 -1
  307. package/dist/internal/content-focus-probe.mjs.map +0 -1
  308. package/dist/internal/css-transition-cut.mjs.map +0 -1
  309. package/dist/internal/field-context.d.mts.map +0 -1
  310. package/dist/internal/field-context.mjs.map +0 -1
  311. package/dist/internal/focus-first-invalid.mjs.map +0 -1
  312. package/dist/internal/focus-visible.mjs.map +0 -1
  313. package/dist/internal/form-status-watcher.mjs.map +0 -1
  314. package/dist/internal/group-member.mjs.map +0 -1
  315. package/dist/internal/invokers.mjs.map +0 -1
  316. package/dist/internal/modal-registry.mjs.map +0 -1
  317. package/dist/internal/overlay-popup.mjs.map +0 -1
  318. package/dist/internal/popover-open.mjs.map +0 -1
  319. package/dist/internal/report-dropped.mjs.map +0 -1
  320. package/dist/internal/sync-presence.mjs.map +0 -1
  321. package/dist/internal/tooltip-warm.mjs.map +0 -1
  322. package/dist/internal/trigger-ref.mjs.map +0 -1
  323. package/dist/internal/use-action-trigger.mjs.map +0 -1
  324. package/dist/internal/use-checkable-input.mjs.map +0 -1
  325. package/dist/internal/use-controllable-action.mjs.map +0 -1
  326. package/dist/internal/use-exit-animation.mjs.map +0 -1
  327. package/dist/internal/use-field-control.mjs.map +0 -1
  328. package/dist/internal/use-fieldset-group.mjs.map +0 -1
  329. package/dist/internal/use-form-owner-event.mjs.map +0 -1
  330. package/dist/internal/use-form-reset.mjs.map +0 -1
  331. package/dist/internal/use-interest-dismiss.mjs.map +0 -1
  332. package/dist/internal/use-modal-registration.mjs.map +0 -1
  333. package/dist/internal/use-native-checked.mjs.map +0 -1
  334. package/dist/internal/use-native-group-reconciliation.mjs.map +0 -1
  335. package/dist/internal/use-native-select-value.mjs.map +0 -1
  336. package/dist/internal/use-overlay-close.mjs.map +0 -1
  337. package/dist/internal/use-overlay-root.d.mts +0 -2
  338. package/dist/internal/use-overlay-root.mjs.map +0 -1
  339. package/dist/internal/use-popover-popup.mjs.map +0 -1
  340. package/dist/internal/use-popover-trigger.d.mts.map +0 -1
  341. package/dist/internal/use-popover-trigger.mjs.map +0 -1
  342. package/dist/internal/use-resolved-placement.mjs.map +0 -1
  343. package/dist/internal/use-until-found.mjs.map +0 -1
  344. package/dist/internal/validity.d.mts.map +0 -1
  345. package/dist/internal/validity.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-form-reset.mjs","names":[],"sources":["../../../src/internal/form/use-form-reset.ts"],"sourcesContent":["\"use client\";\nimport { useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport { useFormOwnerEvent } from \"./use-form-owner-event.js\";\nimport type { FormAssociatedElement } from \"./use-form-owner-event.js\";\nimport { useLatest } from \"../use-latest.js\";\n\n/**\n * Stable `reset` subscription on the form owner of `ref.current` (conventions 3.8).\n *\n * - Built on `useFormOwnerEvent`, with its owner-following rules (rule 4).\n * - The `reset` event fires before the reset algorithm, so `onReset` is called in a microtask,\n * when the inputs hold their reset values (rule 5), and only if no listener cancelled the reset\n * (rule 7).\n * - `onReset` always sees the latest committed render's values.\n */\nexport function useFormReset(\n ref: RefObject<FormAssociatedElement | null>,\n onReset: (event: Event) => void,\n /**\n * Called synchronously from the `reset` event, before the reset algorithm runs: the last\n * moment to write a reset target the browser will restore (Combobox re-applies its mirrored\n * `defaultValue`, which react-dom's attribute syncing overwrites after every keystroke).\n */\n onResetEvent?: (event: Event) => void,\n): void {\n // Read in the microtask, after the commit that may have run the reset (React's own reset runs\n // in a commit's mutation phase): the latest committed `onReset`.\n const latestOnReset = useLatest(onReset);\n useFormOwnerEvent(ref, \"reset\", (event) => {\n onResetEvent?.(event);\n queueMicrotask(() => {\n if (event.defaultPrevented) return;\n latestOnReset.current(event);\n });\n });\n}\n\n/**\n * The form-reset target of a value prop by mode (conventions 3.8 rule 6): controlled\n * (`value !== undefined`), the value it had at mount; uncontrolled, the latest `defaultValue`.\n * `undefined` when that is absent: an uncontrolled Root with no `defaultValue`, or a Root that\n * became controlled after it mounted uncontrolled. The caller supplies its own fallback\n * (`?? null`, `?? value`, a platform default).\n */\nexport function useResetTarget<T>(\n value: T | undefined,\n defaultValue: T | undefined,\n): T | undefined {\n const [mountValue] = useState(value);\n return value !== undefined ? mountValue : defaultValue;\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAgB,aACd,KACA,SAMA,cACM;CAGN,MAAM,gBAAgB,UAAU,OAAO;CACvC,kBAAkB,KAAK,UAAU,UAAU;EACzC,eAAe,KAAK;EACpB,qBAAqB;GACnB,IAAI,MAAM,kBAAkB;GAC5B,cAAc,QAAQ,KAAK;EAC7B,CAAC;CACH,CAAC;AACH;;;;;;;;AASA,SAAgB,eACd,OACA,cACe;CACf,MAAM,CAAC,cAAc,SAAS,KAAK;CACnC,OAAO,UAAU,KAAA,IAAY,aAAa;AAC5C"}
@@ -1,8 +1,9 @@
1
1
  "use client";
2
- import { useElementCheck } from "./use-element-check.mjs";
2
+ import { intendedValue } from "../action/use-controllable-action.mjs";
3
+ import { useElementCheck } from "../use-element-check.mjs";
3
4
  import { useFormReset } from "./use-form-reset.mjs";
4
5
  import { useCallback, useEffectEvent, useLayoutEffect, useRef } from "react";
5
- //#region src/internal/use-native-checked.ts
6
+ //#region src/internal/form/use-native-checked.ts
6
7
  const isDev = process.env.NODE_ENV !== "production";
7
8
  /**
8
9
  * Per-element machinery for a controlled native `<input type="checkbox" | "radio">`
@@ -33,7 +34,7 @@ function useNativeChecked(options) {
33
34
  };
34
35
  }, [checkElement]);
35
36
  /** What the user intends: the latest in-flight dispatch, else the optimistic value (rule 1). */
36
- const readBase = useEffectEvent(() => options.latestInFlight?.()?.next ?? checked);
37
+ const readBase = useEffectEvent(() => intendedValue(options.latestInFlight, checked));
37
38
  const report = useEffectEvent((next, event) => {
38
39
  options.onPlatformChange?.(next, event);
39
40
  });
@@ -70,7 +71,7 @@ function useNativeChecked(options) {
70
71
  const el = node.current;
71
72
  if (el === null) return;
72
73
  const next = el.defaultChecked;
73
- const base = options.latestInFlight?.()?.next ?? checked;
74
+ const base = intendedValue(options.latestInFlight, checked);
74
75
  if (next !== base) options.onPlatformChange?.(next, event);
75
76
  else if (el.checked !== base) el.checked = base;
76
77
  });
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-native-checked.mjs","names":[],"sources":["../../../src/internal/form/use-native-checked.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { RefCallback } from \"react\";\nimport { intendedValue } from \"../action/use-controllable-action.js\";\nimport { useElementCheck } from \"../use-element-check.js\";\nimport { useFormReset } from \"./use-form-reset.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface UseNativeCheckedOptions {\n /** Dev-only: the expected `input.type`. */\n readonly type: \"checkbox\" | \"radio\";\n /** Dev-only: the part's name in warnings (`\"Switch\"`, `\"RadioGroup.Item\"`). */\n readonly component: string;\n /** What the DOM must show after every commit: the optimistic value. */\n readonly checked: boolean;\n /**\n * The form-reset target. Uncontrolled parts pass the latest `defaultChecked` prop (`?? false`),\n * mirrored into `el.defaultChecked` after every commit. Controlled parts pass `undefined`:\n * React's mount-time value stays (conventions 3.8 rule 6).\n */\n readonly defaultChecked: boolean | undefined;\n /** Checkbox only: `el.indeterminate` after every commit (the part passes `indeterminate && !pending`). */\n readonly indeterminate?: boolean | undefined;\n /**\n * `true` inside a group (`RadioGroup.Item`, `CheckboxGroup.Item` and `.Parent`): the hook does\n * the element check and the re-apply only; mount reconciliation and form reset are reported\n * once per group by the Root through `useNativeGroupReconciliation`. Default `false`: the hook\n * reports both paths itself.\n */\n readonly group?: boolean | undefined;\n /**\n * Group members only: the Root's `onItemMounted` from `useNativeGroupReconciliation`. Called\n * from this member's mount layout effect so that a member mounting after the Root (a Suspense\n * boundary that hydrates later) still gets the group reconciled. Receives the member's element\n * (`null` if the ref is not attached). Ignored without `group`.\n */\n readonly onItemMounted?: ((element: HTMLInputElement | null) => void) | undefined;\n /** From `useControllableAction`: the value the DOM is compared against on the residual paths. */\n readonly latestInFlight?: (() => { readonly next: boolean } | null) | undefined;\n /**\n * Single controls only. The browser changed the value on a residual path and it differs from\n * what the user intends. `event` is the `reset` event, or `undefined` for mount reconciliation.\n * The part dispatches with `reason: \"platform\"`.\n */\n readonly onPlatformChange?: ((next: boolean, event: Event | undefined) => void) | undefined;\n}\n\n/**\n * Per-element machinery for a controlled native `<input type=\"checkbox\" | \"radio\">`\n * (conventions 3.8): returns the ref to attach to the input (merged by `useRender`).\n *\n * 1. Ref callback: stores the node; in development warns once when it is not an `<input>` of\n * the expected `type`.\n * 2. Mount reconciliation (single controls): a click before hydration or Firefox's form-state\n * restoration left the DOM different from what the user intends; reported once with\n * `event: undefined`.\n * 3. Re-apply after every commit: `checked` (optimistic, or the latest in-flight value),\n * `indeterminate` and `defaultChecked`, none of which React manages for a controlled input\n * except `checked`.\n * 4. Form reset (single controls): in a microtask after the reset, compares `el.defaultChecked`\n * with what the user intends and reports a difference with the `reset` event.\n *\n * The hook knows nothing about transitions or `reason`; the part wires `onPlatformChange`.\n */\nexport function useNativeChecked(options: UseNativeCheckedOptions): RefCallback<HTMLInputElement> {\n const { type, component, checked, defaultChecked, indeterminate, group = false } = options;\n const node = useRef<HTMLInputElement | null>(null);\n const checkElement = useElementCheck<HTMLInputElement>(\n isDev &&\n ((el) =>\n isInputOfType(el, type)\n ? null\n : `${component}: expected to render an \\`<input type=\"${type}\">\\` but got ` +\n `${describeElement(el)}; the platform semantics (form participation, labels, ` +\n `keyboard, reset) need a real input. A \\`render\\` element must keep the input.`),\n );\n\n const ref = useCallback(\n (el: HTMLInputElement) => {\n node.current = el;\n checkElement?.(el);\n return () => {\n node.current = null;\n };\n },\n [checkElement],\n );\n\n /** What the user intends: the latest in-flight dispatch, else the optimistic value (rule 1). */\n const readBase = useEffectEvent(() => intendedValue(options.latestInFlight, checked));\n const report = useEffectEvent((next: boolean, event: Event | undefined) => {\n options.onPlatformChange?.(next, event);\n });\n\n // 2. Mount reconciliation. Declared before the re-apply effect so that the hydrated DOM value is\n // read before anything overwrites it (rule 3). StrictMode's second run finds the first run's\n // dispatch in flight and does nothing.\n const reconcileMount = useEffectEvent(() => {\n if (group) return;\n const el = node.current;\n if (el === null) return;\n if (el.checked !== readBase()) report(el.checked, undefined);\n });\n useLayoutEffect(() => {\n reconcileMount();\n }, []);\n\n // 2b. Group members tell the Root they mounted; the Root reconciles the group again if its own\n // mount reconciliation already ran (a member mounting later), which covers the `checked`\n // write this member skips in its mount commit (below).\n const notifyMounted = useEffectEvent(() => {\n if (group) options.onItemMounted?.(node.current);\n });\n useLayoutEffect(() => {\n notifyMounted();\n }, []);\n\n // 3. Re-apply after every commit (rule 8). `checked` is skipped in the mount commit (including\n // StrictMode's re-run of it, which closes over the same render): React has just written it\n // from the prop, or kept the hydrated DOM value for the residual path to read. That matters\n // for groups, whose Root reconciles in its own layout effect, after its Items' effects.\n const renderToken = {};\n const mountToken = useRef<object | null>(null);\n useLayoutEffect(() => {\n if (mountToken.current === null) mountToken.current = renderToken;\n const el = node.current;\n if (el === null) return;\n // defaultChecked before checked (conventions 3.8): after React's automatic `<form action>`\n // reset clears the dirty flag, writing `defaultChecked` moves `checked` too, and the `checked`\n // write that follows restores the intended value. `indeterminate` is independent and goes\n // last. Pinned by use-native-checked.test.tsx (\"re-apply order\").\n if (defaultChecked !== undefined && el.defaultChecked !== defaultChecked) {\n el.defaultChecked = defaultChecked;\n }\n if (mountToken.current !== renderToken) {\n const want = readBase();\n if (el.checked !== want) el.checked = want;\n }\n if (indeterminate !== undefined && el.indeterminate !== indeterminate) {\n el.indeterminate = indeterminate;\n }\n });\n\n // 4. Form reset (rules 4 to 7). `el.defaultChecked` is the value the browser reset to; by the\n // time the microtask runs after React's own reset, the re-apply effect may already have put\n // the optimistic value back into `checked`. (`useFormReset` already calls this through an\n // Effect Event, so it reads the latest render's options directly.)\n useFormReset(node, (event) => {\n if (group) return;\n const el = node.current;\n if (el === null) return;\n const next = el.defaultChecked;\n const base = intendedValue(options.latestInFlight, checked);\n if (next !== base) options.onPlatformChange?.(next, event);\n else if (el.checked !== base) el.checked = base;\n });\n\n return ref;\n}\n\nfunction isInputOfType(el: Element, type: string): boolean {\n return el.tagName === \"INPUT\" && (el as HTMLInputElement).type === type;\n}\n\nfunction describeElement(el: Element): string {\n const tag = el.tagName.toLowerCase();\n return tag === \"input\" ? `\\`<input type=\"${(el as HTMLInputElement).type}\">\\`` : `\\`<${tag}>\\``;\n}\n\nconst warnedPreventDefault = new WeakSet<EventTarget>();\n\n/**\n * Shared `onChange` guard for checkable inputs (conventions 3.8 rule 9, 2.3 item 3):\n *\n * - A click that is already cancelled (`preventDefault()` in a pass-through `onClick`, which runs\n * before the library's `onChange`) is not a change: the browser reverts the DOM after dispatch\n * and React restores unchanged props. Nothing is dispatched.\n * - Otherwise `dispatch()` runs (the action's sync prefix included); if the event is cancelled\n * now, the action's sync prefix called `preventDefault()`, which desyncs the input while the\n * action is pending. Development warns once per input element.\n */\nexport function guardCheckableChange(\n event: Event,\n dispatch: () => void,\n component: string = \"A checkable input\",\n): void {\n if (event.defaultPrevented) return;\n dispatch();\n if (!isDev || !event.defaultPrevented) return;\n const target = event.target;\n if (target !== null) {\n if (warnedPreventDefault.has(target)) return;\n warnedPreventDefault.add(target);\n }\n console.error(\n `${component}: \\`preventDefault()\\` on the change event is not supported; it desyncs the ` +\n `input while the action is pending. Use controlled mode to veto a change.`,\n );\n}\n"],"mappings":";;;;;;AAOA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;;;AA0DvC,SAAgB,iBAAiB,SAAiE;CAChG,MAAM,EAAE,MAAM,WAAW,SAAS,gBAAgB,eAAe,QAAQ,UAAU;CACnF,MAAM,OAAO,OAAgC,IAAI;CACjD,MAAM,eAAe,gBACnB,WACI,OACA,cAAc,IAAI,IAAI,IAClB,OACA,GAAG,UAAU,yCAAyC,KAAK,eACxD,gBAAgB,EAAE,EAAE,qIAEjC;CAEA,MAAM,MAAM,aACT,OAAyB;EACxB,KAAK,UAAU;EACf,eAAe,EAAE;EACjB,aAAa;GACX,KAAK,UAAU;EACjB;CACF,GACA,CAAC,YAAY,CACf;;CAGA,MAAM,WAAW,qBAAqB,cAAc,QAAQ,gBAAgB,OAAO,CAAC;CACpF,MAAM,SAAS,gBAAgB,MAAe,UAA6B;EACzE,QAAQ,mBAAmB,MAAM,KAAK;CACxC,CAAC;CAKD,MAAM,iBAAiB,qBAAqB;EAC1C,IAAI,OAAO;EACX,MAAM,KAAK,KAAK;EAChB,IAAI,OAAO,MAAM;EACjB,IAAI,GAAG,YAAY,SAAS,GAAG,OAAO,GAAG,SAAS,KAAA,CAAS;CAC7D,CAAC;CACD,sBAAsB;EACpB,eAAe;CACjB,GAAG,CAAC,CAAC;CAKL,MAAM,gBAAgB,qBAAqB;EACzC,IAAI,OAAO,QAAQ,gBAAgB,KAAK,OAAO;CACjD,CAAC;CACD,sBAAsB;EACpB,cAAc;CAChB,GAAG,CAAC,CAAC;CAML,MAAM,cAAc,CAAC;CACrB,MAAM,aAAa,OAAsB,IAAI;CAC7C,sBAAsB;EACpB,IAAI,WAAW,YAAY,MAAM,WAAW,UAAU;EACtD,MAAM,KAAK,KAAK;EAChB,IAAI,OAAO,MAAM;EAKjB,IAAI,mBAAmB,KAAA,KAAa,GAAG,mBAAmB,gBACxD,GAAG,iBAAiB;EAEtB,IAAI,WAAW,YAAY,aAAa;GACtC,MAAM,OAAO,SAAS;GACtB,IAAI,GAAG,YAAY,MAAM,GAAG,UAAU;EACxC;EACA,IAAI,kBAAkB,KAAA,KAAa,GAAG,kBAAkB,eACtD,GAAG,gBAAgB;CAEvB,CAAC;CAMD,aAAa,OAAO,UAAU;EAC5B,IAAI,OAAO;EACX,MAAM,KAAK,KAAK;EAChB,IAAI,OAAO,MAAM;EACjB,MAAM,OAAO,GAAG;EAChB,MAAM,OAAO,cAAc,QAAQ,gBAAgB,OAAO;EAC1D,IAAI,SAAS,MAAM,QAAQ,mBAAmB,MAAM,KAAK;OACpD,IAAI,GAAG,YAAY,MAAM,GAAG,UAAU;CAC7C,CAAC;CAED,OAAO;AACT;AAEA,SAAS,cAAc,IAAa,MAAuB;CACzD,OAAO,GAAG,YAAY,WAAY,GAAwB,SAAS;AACrE;AAEA,SAAS,gBAAgB,IAAqB;CAC5C,MAAM,MAAM,GAAG,QAAQ,YAAY;CACnC,OAAO,QAAQ,UAAU,kBAAmB,GAAwB,KAAK,QAAQ,MAAM,IAAI;AAC7F;AAEA,MAAM,uCAAuB,IAAI,QAAqB;;;;;;;;;;;AAYtD,SAAgB,qBACd,OACA,UACA,YAAoB,qBACd;CACN,IAAI,MAAM,kBAAkB;CAC5B,SAAS;CACT,IAAI,CAAC,SAAS,CAAC,MAAM,kBAAkB;CACvC,MAAM,SAAS,MAAM;CACrB,IAAI,WAAW,MAAM;EACnB,IAAI,qBAAqB,IAAI,MAAM,GAAG;EACtC,qBAAqB,IAAI,MAAM;CACjC;CACA,QAAQ,MACN,GAAG,UAAU,qJAEf;AACF"}
@@ -1,8 +1,8 @@
1
1
  "use client";
2
- import { useLatest } from "./use-latest.mjs";
2
+ import { useLatest } from "../use-latest.mjs";
3
3
  import { useFormReset } from "./use-form-reset.mjs";
4
4
  import { useCallback, useEffectEvent, useLayoutEffect, useRef } from "react";
5
- //#region src/internal/use-native-group-reconciliation.ts
5
+ //#region src/internal/form/use-native-group-reconciliation.ts
6
6
  /**
7
7
  * Group adapter of the native-input machinery (conventions 3.8): one dispatch per group for the
8
8
  * residual browser paths, from the Root rather than once per member.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-native-group-reconciliation.mjs","names":[],"sources":["../../../src/internal/form/use-native-group-reconciliation.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport { useFormReset } from \"./use-form-reset.js\";\nimport type { FormAssociatedElement } from \"./use-form-owner-event.js\";\nimport { useLatest } from \"../use-latest.js\";\n\n/** Which residual path found the change: mount reconciliation (Root or late member) or form reset. */\nexport type NativeGroupPath = \"mount\" | \"reset\";\n\nexport interface UseNativeGroupReconciliationOptions<T> {\n /**\n * The group's form-associated element: `RadioGroup.Root`'s / `CheckboxGroup.Root`'s\n * `<fieldset>`, `Select.Root`'s `<select>` (whose options are the members), or any member\n * input when the Root renders no form-associated element (`Slider.Root` subscribes through its\n * first Thumb's `<input type=\"range\">`).\n */\n readonly element: RefObject<FormAssociatedElement | null>;\n /** The group's value as the DOM shows it now (`checked` of the members). */\n readonly readCurrent: () => T;\n /** The value the browser resets the group to (`defaultChecked` of the members, rule 5). */\n readonly readDefault: () => T;\n /**\n * What the user intends (rule 1): the latest in-flight dispatch's `next`, else the optimistic\n * value. `intendedValue` (use-controllable-action.ts) keeps an in-flight dispatch of a nullish\n * value (a pending reset to \"nothing checked\"), which `?.next ?? optimistic` would drop.\n */\n readonly base: () => T;\n /**\n * The browser changed the group's value on a residual path and it differs from `base()` (for a\n * form reset, also when equal while `dispatchEqualReset()` holds). `path` names the path:\n * `\"mount\"` for mount reconciliation (the Root's mount, or a member mounting later; `event` is\n * `undefined`), `\"reset\"` for a form reset (`event` is the `reset` event). CheckboxGroup reads\n * `path`, not `event`, to dispatch a reset as absolute (`DispatchOptions.whole`). The Root\n * dispatches once for the whole group with `reason: \"platform\"`.\n */\n readonly onPlatformChange: (next: T, event: Event | undefined, path: NativeGroupPath) => void;\n /**\n * Form reset only: dispatch the reset target even when it equals `base()`, while this returns\n * `true`. A set-valued group (CheckboxGroup) passes \"a dispatch is in flight\"\n * (`latestInFlight() !== null`): its reset is absolute in the uncontrolled replay (conventions\n * 3.3), so it must enter the burst even with an empty diff, or an earlier in-flight change that\n * rejects later would roll the group back past the reset (#151). Default: never.\n */\n readonly dispatchEqualReset?: (() => boolean) | undefined;\n /**\n * Equality between a read value and `base()`. Default `Object.is`, right for a primitive value\n * (RadioGroup's `string | null`); a group with a collection value (CheckboxGroup's\n * `ReadonlySet<string>`) passes structural equality, since every read builds a new object.\n */\n readonly equals?: ((a: T, b: T) => boolean) | undefined;\n /**\n * Passed through to `useFormReset`: called synchronously from the `reset` event, before the\n * reset algorithm runs. A group of controlled **value** inputs (Slider) writes each input's\n * `defaultValue` to the reset target here, because react-dom keeps that attribute equal to the\n * current value after every update (conventions 3.8 rule 6).\n */\n readonly onResetEvent?: ((event: Event) => void) | undefined;\n}\n\nexport interface UseNativeGroupReconciliationResult {\n /**\n * Stable. Pass it to every member, which hands it to\n * `useNativeChecked({ group: true, onItemMounted })`; the hook calls it from the member's mount\n * layout effect. A member that mounts after the Root's own mount reconciliation (inside a\n * Suspense boundary that hydrates later, selective hydration, or a member added on the client)\n * makes the adapter reconcile the group again: `readCurrent()` vs `base()`, in a microtask, once\n * for all members mounted in the same commit. Members mounting in the Root's own commit are\n * covered by the Root's mount reconciliation (their effects run before the Root's) and are\n * ignored. The member's element argument is not used here; the Root may use it (dev warnings).\n */\n readonly onItemMounted: (element?: Element | null) => void;\n}\n\n/**\n * Group adapter of the native-input machinery (conventions 3.8): one dispatch per group for the\n * residual browser paths, from the Root rather than once per member.\n *\n * - Mount reconciliation, once, in a layout effect: `readCurrent()` vs `base()`. The members'\n * `useNativeChecked({ group: true })` leaves `checked` alone in their mount commit, so this\n * effect, which runs after the members' (children first), still reads the hydrated DOM.\n * - Late members: a member mounting in a later commit (a Suspense boundary that hydrates after the\n * Root, where a click before hydration changed the DOM) reports through `onItemMounted`, and the\n * group is reconciled again the same way (see `UseNativeGroupReconciliationResult`).\n * - Form reset through `useFormReset` on the container: in a microtask after the reset,\n * `readDefault()` vs `base()` (or dispatched regardless while `dispatchEqualReset()` holds).\n *\n * Values are compared with `equals` (default `Object.is`).\n */\nexport function useNativeGroupReconciliation<T>(\n options: UseNativeGroupReconciliationOptions<T>,\n): UseNativeGroupReconciliationResult {\n const { element } = options;\n\n // The latest committed options, for the late reconciliation, which runs in a microtask outside\n // any effect (so it cannot go through an Effect Event).\n const latest = useLatest(options);\n\n /** The Root's own mount reconciliation has run (reset by its cleanup, StrictMode included). */\n const rootReconciled = useRef(false);\n /** A late reconciliation is queued; members mounting in the same commit share it. */\n const lateQueued = useRef(false);\n\n const reconcileMount = useEffectEvent(() => {\n if (element.current === null) return;\n reconcile(options, options.readCurrent(), \"mount\");\n });\n useLayoutEffect(() => {\n reconcileMount();\n rootReconciled.current = true;\n return () => {\n rootReconciled.current = false;\n };\n }, []);\n\n const onItemMounted = useCallback(() => {\n if (!rootReconciled.current || lateQueued.current) return;\n lateQueued.current = true;\n queueMicrotask(() => {\n lateQueued.current = false;\n if (!rootReconciled.current) return;\n const current = latest.current;\n if (current.element.current === null) return;\n reconcile(current, current.readCurrent(), \"mount\");\n });\n }, [latest]);\n\n useFormReset(\n element,\n (event) => {\n if (element.current === null) return;\n const next = options.readDefault();\n if (options.dispatchEqualReset?.()) options.onPlatformChange(next, event, \"reset\");\n else reconcile(options, next, \"reset\", event);\n },\n (event) => {\n if (element.current === null) return;\n options.onResetEvent?.(event);\n },\n );\n\n return { onItemMounted };\n}\n\nfunction reconcile<T>(\n options: UseNativeGroupReconciliationOptions<T>,\n next: T,\n path: NativeGroupPath,\n event?: Event,\n) {\n const equals = options.equals ?? Object.is;\n if (!equals(next, options.base())) options.onPlatformChange(next, event, path);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,6BACd,SACoC;CACpC,MAAM,EAAE,YAAY;CAIpB,MAAM,SAAS,UAAU,OAAO;;CAGhC,MAAM,iBAAiB,OAAO,KAAK;;CAEnC,MAAM,aAAa,OAAO,KAAK;CAE/B,MAAM,iBAAiB,qBAAqB;EAC1C,IAAI,QAAQ,YAAY,MAAM;EAC9B,UAAU,SAAS,QAAQ,YAAY,GAAG,OAAO;CACnD,CAAC;CACD,sBAAsB;EACpB,eAAe;EACf,eAAe,UAAU;EACzB,aAAa;GACX,eAAe,UAAU;EAC3B;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAgB,kBAAkB;EACtC,IAAI,CAAC,eAAe,WAAW,WAAW,SAAS;EACnD,WAAW,UAAU;EACrB,qBAAqB;GACnB,WAAW,UAAU;GACrB,IAAI,CAAC,eAAe,SAAS;GAC7B,MAAM,UAAU,OAAO;GACvB,IAAI,QAAQ,QAAQ,YAAY,MAAM;GACtC,UAAU,SAAS,QAAQ,YAAY,GAAG,OAAO;EACnD,CAAC;CACH,GAAG,CAAC,MAAM,CAAC;CAEX,aACE,UACC,UAAU;EACT,IAAI,QAAQ,YAAY,MAAM;EAC9B,MAAM,OAAO,QAAQ,YAAY;EACjC,IAAI,QAAQ,qBAAqB,GAAG,QAAQ,iBAAiB,MAAM,OAAO,OAAO;OAC5E,UAAU,SAAS,MAAM,SAAS,KAAK;CAC9C,IACC,UAAU;EACT,IAAI,QAAQ,YAAY,MAAM;EAC9B,QAAQ,eAAe,KAAK;CAC9B,CACF;CAEA,OAAO,EAAE,cAAc;AACzB;AAEA,SAAS,UACP,SACA,MACA,MACA,OACA;CAEA,IAAI,EADW,QAAQ,UAAU,OAAO,GAAA,CAC5B,MAAM,QAAQ,KAAK,CAAC,GAAG,QAAQ,iBAAiB,MAAM,OAAO,IAAI;AAC/E"}
@@ -1,8 +1,8 @@
1
1
  "use client";
2
- import { useLatest } from "./use-latest.mjs";
2
+ import { useLatest } from "../use-latest.mjs";
3
3
  import { useNativeGroupReconciliation } from "./use-native-group-reconciliation.mjs";
4
4
  import { useCallback, useEffectEvent, useLayoutEffect, useMemo, useRef } from "react";
5
- //#region src/internal/use-native-select-value.ts
5
+ //#region src/internal/form/use-native-select-value.ts
6
6
  /** The first option whose value is `value` (react-dom's `updateOptions` selects the first). */
7
7
  function findOption(select, value) {
8
8
  for (const option of select.options) if (option.value === value) return option;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-native-select-value.mjs","names":[],"sources":["../../../src/internal/form/use-native-select-value.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffectEvent, useLayoutEffect, useMemo, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport { useLatest } from \"../use-latest.js\";\nimport { useNativeGroupReconciliation } from \"./use-native-group-reconciliation.js\";\n\nexport interface UseNativeSelectValueOptions {\n /** The `<select>`. */\n readonly ref: RefObject<HTMLSelectElement | null>;\n /** The optimistic value (what the `<select>` renders). */\n readonly optimistic: string;\n /** From `useControllableAction`: the latest in-flight dispatch, if any. */\n readonly latestInFlight: () => { readonly next: string } | null;\n /**\n * The value a form reset must return to, mirrored into `option.defaultSelected` after every\n * commit: uncontrolled, the latest `defaultValue`; controlled, the Root's mount-time value.\n * Ignored in adopt mode (`adoptDefault` set), where the target is the value adopted at mount.\n */\n readonly resetTarget: string | undefined;\n /**\n * Uncontrolled without `defaultValue` (design/components/select.md 5): adopts the browser's\n * choice as the committed value, without a dispatch. `undefined` in every other mode.\n */\n readonly adoptDefault: AdoptDefault | undefined;\n /**\n * The browser changed the value on a residual path (pre-hydration pick, Firefox form-state\n * restoration, a late hydrated option, a form reset) and it differs from what the user intends.\n * `event` is the `reset` event or `undefined`. The Root dispatches once with\n * `reason: \"platform\"`.\n */\n readonly onPlatformChange: (next: string, event: Event | undefined) => void;\n}\n\nexport interface AdoptDefault {\n /** `adopt` of `useControllableAction`: writes the committed value, no action. */\n readonly adopt: (next: string) => void;\n /**\n * A dispatch (a pick or a platform change) has set the value. From then on the browser's\n * default is never adopted again: late options only get the re-apply, so options that suspend\n * again (a keyed boundary, a refetch) and come back keep the user's value.\n */\n readonly established: () => boolean;\n}\n\nexport interface UseNativeSelectValueResult {\n /**\n * Stable. Each `Select.Option` calls it from its mount layout effect with its element and\n * whether that render hydrated server HTML (`useHydratedMount`). Reports from the Root's own\n * commit are ignored (the Root's effects cover them). A later report re-applies the intended\n * option (React never selects options mounted after the select's own commit); a hydrated one\n * is also reconciled, from a DOM snapshot taken before the re-apply.\n */\n readonly optionMounted: (el: HTMLOptionElement | null, hydrated: boolean) => void;\n}\n\n/** The first option whose value is `value` (react-dom's `updateOptions` selects the first). */\nexport function findOption(select: HTMLSelectElement, value: string): HTMLOptionElement | null {\n for (const option of select.options) {\n if (option.value === value) return option;\n }\n return null;\n}\n\nfunction isEnabled(option: HTMLOptionElement): boolean {\n if (option.disabled) return false;\n const parent = option.parentElement;\n return !(parent?.tagName === \"OPTGROUP\" && (parent as HTMLOptGroupElement).disabled);\n}\n\nfunction firstEnabled(select: HTMLSelectElement): string {\n for (const option of select.options) {\n if (isEnabled(option)) return option.value;\n }\n return \"\";\n}\n\n/**\n * The spec's reset result for a single select: the last option whose `defaultSelected` is true,\n * else the first enabled option, else `\"\"` (nothing selected).\n */\nexport function readResetValue(select: HTMLSelectElement): string {\n let last: HTMLOptionElement | null = null;\n for (const option of select.options) {\n if (option.defaultSelected) last = option;\n }\n return last !== null ? last.value : firstEnabled(select);\n}\n\n/**\n * The option a `<select>` rendered with the value `\"\"` selects: an option whose value is `\"\"`\n * (react-dom's `updateOptions(\"\")` and Fizz's `selected` attribute both pick it, even when it is\n * disabled), else the first enabled option (the selectedness setting algorithm), else `\"\"`.\n */\nexport function implicitDefault(select: HTMLSelectElement): string {\n return findOption(select, \"\") !== null ? \"\" : firstEnabled(select);\n}\n\n/**\n * The reset-target mirror followed by the re-apply, in one synchronous step\n * (design/components/select.md 6.1). Writing `defaultSelected = true` on an option whose\n * dirtiness is false selects it, so the intended option is re-selected right after. Writes only\n * what differs: the common commit writes nothing.\n */\nexport function applySelection(\n select: HTMLSelectElement,\n target: string,\n resetTarget: string | undefined,\n): void {\n if (resetTarget !== undefined) {\n // Only the first match, the option react-dom would select for that value.\n const def = findOption(select, resetTarget);\n for (const option of select.options) {\n const want = option === def;\n if (option.defaultSelected !== want) option.defaultSelected = want;\n }\n }\n const option = findOption(select, target);\n if (option !== null && !option.selected) option.selected = true;\n}\n\ninterface Snapshot {\n readonly value: string;\n readonly index: number;\n}\n\nconst read = (select: HTMLSelectElement): Snapshot => ({\n value: select.value,\n index: select.selectedIndex,\n});\n\n/**\n * Native-`<select>` machinery for `Select.Root` (conventions 3.8, the select analogue of\n * `useNativeChecked`), on top of `useNativeGroupReconciliation`:\n *\n * 1. Adoption (uncontrolled without `defaultValue`): at mount the browser's default becomes the\n * committed value with no dispatch, and the mount reconciliation compares against it, so a\n * pre-hydration pick of another option still dispatches. It is also the reset target (the\n * value Fizz marks `selected` when it comes from a `\"\"` option). While no dispatch has set\n * the value, late options mounting without the state's option adopt again (loading).\n * 2. Mount reconciliation and form reset through the group adapter: one dispatch per Select, and\n * only when the intended option exists in the DOM (a value whose option is still loading is\n * never \"reconciled\" to the fallback).\n * 3. After every Root commit: the reset-target mirror, then the re-apply of the intended option.\n * 4. Late options: the same, once per commit; a hydrated late option is also reconciled, from a\n * snapshot of the selection taken before the re-apply.\n */\nexport function useNativeSelectValue(\n options: UseNativeSelectValueOptions,\n): UseNativeSelectValueResult {\n const { ref: elementRef } = options;\n // A `render` element that is not a <select> (dev warning in the Root) gets no DOM work.\n const ref = useMemo(\n () => ({\n get current(): HTMLSelectElement | null {\n const el = elementRef.current;\n // Tag, not `instanceof`: the element may come from another realm (an iframe).\n return el?.tagName === \"SELECT\" ? (el as HTMLSelectElement) : null;\n },\n }),\n [elementRef],\n );\n\n // The latest committed options. Written in the mutation phase (`useLatest`), so an Option's\n // mount layout effect, which runs before this Root's layout effects, already reads this commit's.\n const latest = useLatest(options);\n\n /**\n * A default adopted in this layout phase. Until the adoption's render (a sync update, flushed\n * right after this commit) the state still says the old value, so this is what the user\n * intends unless a dispatch is in flight. Cleared in a microtask, after that render.\n */\n const adopted = useRef<string | null>(null);\n const intended = (o: UseNativeSelectValueOptions): string => {\n const f = o.latestInFlight();\n if (f !== null) return f.next;\n return adopted.current ?? o.optimistic;\n };\n\n const adoptNow = (value: string, adopt: (next: string) => void) => {\n adopted.current = value;\n adopt(value);\n queueMicrotask(() => {\n adopted.current = null;\n });\n };\n\n /** Adopt mode: the value adopted at mount, the reset target (as the mount value is, controlled). */\n const mountAdopted = useRef<string | undefined>(undefined);\n const resetTargetOf = (o: UseNativeSelectValueOptions): string | undefined =>\n o.adoptDefault !== undefined ? mountAdopted.current : o.resetTarget;\n\n /** The selection read in the layout phase of a late-option commit (conventions 3.8 rule 3). */\n const lateSnapshot = useRef<Snapshot | null>(null);\n\n // 1. Adoption at mount. Declared before the adapter so that its mount reconciliation compares\n // the DOM against the adopted default.\n const adoptAtMount = useEffectEvent(() => {\n const select = ref.current;\n const adoptDefault = options.adoptDefault;\n // `established`: StrictMode's re-run after a mount reconciliation already dispatched.\n if (select === null || adoptDefault === undefined || adoptDefault.established()) return;\n const value = implicitDefault(select);\n // `\"\"` from a select with nothing selectable is no reset target (design 6.1): only a `\"\"`\n // option, the placeholder react-dom and Fizz select, is mirrored.\n mountAdopted.current = value === \"\" && findOption(select, \"\") === null ? undefined : value;\n adoptNow(value, adoptDefault.adopt);\n });\n useLayoutEffect(() => {\n adoptAtMount();\n }, []);\n\n // 2. Residual paths: one dispatch per Select.\n const { onItemMounted } = useNativeGroupReconciliation<string>({\n element: ref,\n readCurrent: () => {\n const select = ref.current;\n const snapshot = lateSnapshot.current;\n lateSnapshot.current = null;\n const base = intended(latest.current);\n if (select === null) return base;\n const current = snapshot ?? read(select);\n // The dispatch gate: nothing selected, or the intended option absent, is not a pick.\n if (current.index === -1 || findOption(select, base) === null) return base;\n return current.value;\n },\n readDefault: () => {\n const select = ref.current;\n return select === null ? intended(latest.current) : readResetValue(select);\n },\n base: () => intended(latest.current),\n onPlatformChange: (next, event) => latest.current.onPlatformChange(next, event),\n });\n\n // 3. After every commit. Declared after the adapter, so the mount commit's DOM is read by the\n // mount reconciliation before anything is re-applied.\n useLayoutEffect(() => {\n const select = ref.current;\n if (select === null) return;\n applySelection(select, intended(options), resetTargetOf(options));\n });\n\n /** The Root's own mount effects have run: later Option mounts are late. */\n const rootMounted = useRef(false);\n useLayoutEffect(() => {\n rootMounted.current = true;\n return () => {\n rootMounted.current = false;\n };\n }, []);\n /**\n * This commit's late options were handled (snapshot, adoption, re-apply). A microtask window,\n * not a per-commit flag: an Option's layout effect cannot tell which commit it belongs to (the\n * Root does not commit with a boundary that resolves inside it). A second commit in the same\n * task is covered by the per-report re-apply below; its hydrated options are reconciled against\n * the first commit's snapshot (theoretical: no part triggers such a commit).\n */\n const lateHandled = useRef(false);\n\n // 4. Late options.\n const optionMounted = useCallback(\n (el: HTMLOptionElement | null, hydrated: boolean) => {\n if (!rootMounted.current) return;\n const select = ref.current;\n if (select === null) return;\n if (!lateHandled.current) {\n lateHandled.current = true;\n // Every option of this commit is in the DOM already (the mutation phase precedes layout).\n lateSnapshot.current = read(select);\n const current = latest.current;\n const adoptDefault = current.adoptDefault;\n if (\n adoptDefault !== undefined &&\n !adoptDefault.established() &&\n current.latestInFlight() === null &&\n findOption(select, intended(current)) === null\n ) {\n // Still loading and nothing chosen yet (the fallback-only case): adopt the browser's\n // default. Never after a dispatch: that would overwrite the user's value silently.\n adoptNow(implicitDefault(select), adoptDefault.adopt);\n }\n applySelection(select, intended(current), resetTargetOf(current));\n // Cleared after the adapter's microtask, which a later report of this same commit may\n // queue after this point: two hops keep the snapshot for it.\n queueMicrotask(() =>\n queueMicrotask(() => {\n lateHandled.current = false;\n lateSnapshot.current = null;\n }),\n );\n } else if (el !== null) {\n // Per report, for an option that matters (cheap: at most the intended and the reset\n // target's options): a second commit within the window gets its re-apply too.\n const current = latest.current;\n if (el.value === intended(current) || el.value === resetTargetOf(current)) {\n applySelection(select, intended(current), resetTargetOf(current));\n }\n }\n if (hydrated) onItemMounted(el);\n },\n [ref, latest, onItemMounted],\n );\n\n return { optionMounted };\n}\n"],"mappings":"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"}
@@ -1,4 +1,4 @@
1
- //#region src/internal/validity.d.ts
1
+ //#region src/internal/form/validity.d.ts
2
2
  /** A field error: a message, several messages, or nothing (`""`, `[]`, `null`, `undefined`). */
3
3
  export type FieldErrorValue = string | readonly string[] | null | undefined;
4
4
  /** Field errors keyed by field `name` (usually `state.errors` from `useActionState`). */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validity.d.mts","names":[],"sources":["../../../src/internal/form/validity.ts"],"mappings":";;YAIY;;YAGA,aAAa,SAAS,eAAe;;;;;iBAMhC;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA"}
@@ -1,4 +1,4 @@
1
- //#region src/internal/validity.ts
1
+ //#region src/internal/form/validity.ts
2
2
  const VALIDITY_KEYS = [
3
3
  "valueMissing",
4
4
  "typeMismatch",
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validity.mjs","names":[],"sources":["../../../src/internal/form/validity.ts"],"sourcesContent":["// Directive-free helpers for Field and Form (design/components/field-form.md 2, 14): the validity\n// snapshot, error-value normalisation, the `:user-invalid` read and the element resolution.\n\n/** A field error: a message, several messages, or nothing (`\"\"`, `[]`, `null`, `undefined`). */\nexport type FieldErrorValue = string | readonly string[] | null | undefined;\n\n/** Field errors keyed by field `name` (usually `state.errors` from `useActionState`). */\nexport type FormErrors = Readonly<Record<string, FieldErrorValue>>;\n\n/**\n * A plain, serialisable snapshot of the control's `ValidityState` (all `false` and\n * `valid: true` on the server and before the first read).\n */\nexport interface FieldValidity {\n /** A required control has no value. */\n readonly valueMissing: boolean;\n /** The value does not match the `type` (email, url). */\n readonly typeMismatch: boolean;\n /** The value does not match `pattern`. */\n readonly patternMismatch: boolean;\n /** The value is longer than `maxLength`. */\n readonly tooLong: boolean;\n /** The value is shorter than `minLength`. */\n readonly tooShort: boolean;\n /** The value is below `min`. */\n readonly rangeUnderflow: boolean;\n /** The value is above `max`. */\n readonly rangeOverflow: boolean;\n /** The value is not on the `step` grid. */\n readonly stepMismatch: boolean;\n /** The browser cannot convert the input to a value. */\n readonly badInput: boolean;\n /** A custom message is set (`validate` or a shown server error). */\n readonly customError: boolean;\n /** No constraint is violated. */\n readonly valid: boolean;\n}\n\nconst VALIDITY_KEYS = [\n \"valueMissing\",\n \"typeMismatch\",\n \"patternMismatch\",\n \"tooLong\",\n \"tooShort\",\n \"rangeUnderflow\",\n \"rangeOverflow\",\n \"stepMismatch\",\n \"badInput\",\n \"customError\",\n \"valid\",\n] as const satisfies readonly (keyof FieldValidity)[];\n\nexport const VALID: FieldValidity = Object.freeze({\n valueMissing: false,\n typeMismatch: false,\n patternMismatch: false,\n tooLong: false,\n tooShort: false,\n rangeUnderflow: false,\n rangeOverflow: false,\n stepMismatch: false,\n badInput: false,\n customError: false,\n valid: true,\n});\n\nexport function snapshotValidity(validity: ValidityState): FieldValidity {\n const result = {} as Record<keyof FieldValidity, boolean>;\n for (const key of VALIDITY_KEYS) result[key] = validity[key];\n return result;\n}\n\nexport function validityEquals(a: FieldValidity, b: FieldValidity): boolean {\n return VALIDITY_KEYS.every((key) => a[key] === b[key]);\n}\n\nconst NONE: readonly string[] = Object.freeze([]);\n\n/** `\"\"`, `[]`, `null` and `undefined` mean no error; empty strings inside an array are dropped. */\nexport function normaliseErrorValue(value: FieldErrorValue): readonly string[] {\n if (value === null || value === undefined || value === \"\") return NONE;\n if (typeof value === \"string\") return [value];\n const list = value.filter((v) => typeof v === \"string\" && v !== \"\");\n return list.length === 0 ? NONE : list;\n}\n\n/** Some entry of `errors` is a non-empty error. */\nexport function hasAnyError(errors: FormErrors | undefined): boolean {\n if (errors === undefined) return false;\n return Object.values(errors).some((v) => normaliseErrorValue(v).length > 0);\n}\n\nlet userInvalidSupport: boolean | undefined;\n\n/**\n * Whether the environment implements `:user-invalid` (every engine the library supports does).\n * Decided once per module, so the read is not on a hot path.\n *\n * Detected with `CSS.supports(\"selector(:user-invalid)\")` rather than by `matches()` throwing:\n * jsdom 30's selector engine knows the name and silently answers `false` (it does not throw), and\n * its `CSS.supports` reports `false`, so the fallback engages there and nowhere else\n * (memo/developer/field-form.md).\n */\nexport function supportsUserInvalid(): boolean {\n if (userInvalidSupport === undefined) {\n try {\n userInvalidSupport =\n typeof CSS !== \"undefined\" &&\n typeof CSS.supports === \"function\" &&\n CSS.supports(\"selector(:user-invalid)\");\n } catch {\n userInvalidSupport = false;\n }\n }\n return userInvalidSupport;\n}\n\n/** An element that takes part in constraint validation. */\nexport type ValidatableElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;\n\nfunction isValidatable(el: Element): el is ValidatableElement {\n return (\n el instanceof HTMLInputElement ||\n el instanceof HTMLSelectElement ||\n el instanceof HTMLTextAreaElement\n );\n}\n\n/**\n * Where `validity`, `validationMessage`, `:user-invalid` and `setCustomValidity` are read and\n * written (design 7.1): the element itself when it is a form control, else the first named\n * `willValidate` member of a `<fieldset>` (a group's first enabled item, not a CheckboxGroup\n * Parent, which has no name), else the first `input` / `select` / `textarea` inside.\n */\nexport function validityElementOf(el: Element | null): ValidatableElement | null {\n if (el === null) return null;\n if (isValidatable(el)) return el;\n const members =\n el instanceof HTMLFieldSetElement\n ? [...el.elements]\n : [...el.querySelectorAll(\"input, select, textarea\")];\n const controls = members.filter(isValidatable);\n return (\n controls.find((c) => c.willValidate && c.name !== \"\") ??\n controls.find((c) => c.willValidate) ??\n controls[0] ??\n null\n );\n}\n\n/**\n * What the Field focuses (design 2.5): the control itself, or for a group the checked radio if\n * any, else the first enabled named member (a group's first item, not a CheckboxGroup Parent,\n * which has no name), else the first enabled member.\n */\nexport function focusTargetOf(el: Element | null): HTMLElement | null {\n if (el === null) return null;\n if (isValidatable(el)) return el;\n const members = (\n el instanceof HTMLFieldSetElement\n ? [...el.elements]\n : [...el.querySelectorAll(\"input, select, textarea, button\")]\n ).filter(\n (m): m is HTMLElement =>\n m instanceof HTMLElement &&\n !(m as HTMLInputElement).disabled &&\n (m as HTMLInputElement).type !== \"hidden\",\n );\n const checkedRadio = members.find(\n (m) => m instanceof HTMLInputElement && m.type === \"radio\" && m.checked,\n );\n return (\n checkedRadio ??\n members.find((m) => isValidatable(m) && m.name !== \"\") ??\n members.find(isValidatable) ??\n members[0] ??\n null\n );\n}\n"],"mappings":";AAsCA,MAAM,gBAAgB;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,QAAuB,OAAO,OAAO;CAChD,cAAc;CACd,cAAc;CACd,iBAAiB;CACjB,SAAS;CACT,UAAU;CACV,gBAAgB;CAChB,eAAe;CACf,cAAc;CACd,UAAU;CACV,aAAa;CACb,OAAO;AACT,CAAC;AAED,SAAgB,iBAAiB,UAAwC;CACvE,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,OAAO,eAAe,OAAO,OAAO,SAAS;CACxD,OAAO;AACT;AAEA,SAAgB,eAAe,GAAkB,GAA2B;CAC1E,OAAO,cAAc,OAAO,QAAQ,EAAE,SAAS,EAAE,IAAI;AACvD;AAEA,MAAM,OAA0B,OAAO,OAAO,CAAC,CAAC;;AAGhD,SAAgB,oBAAoB,OAA2C;CAC7E,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,UAAU,IAAI,OAAO;CAClE,IAAI,OAAO,UAAU,UAAU,OAAO,CAAC,KAAK;CAC5C,MAAM,OAAO,MAAM,QAAQ,MAAM,OAAO,MAAM,YAAY,MAAM,EAAE;CAClE,OAAO,KAAK,WAAW,IAAI,OAAO;AACpC;;AAGA,SAAgB,YAAY,QAAyC;CACnE,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,OAAO,OAAO,OAAO,MAAM,CAAC,CAAC,MAAM,MAAM,oBAAoB,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5E;AAEA,IAAI;;;;;;;;;;AAWJ,SAAgB,sBAA+B;CAC7C,IAAI,uBAAuB,KAAA,GACzB,IAAI;EACF,qBACE,OAAO,QAAQ,eACf,OAAO,IAAI,aAAa,cACxB,IAAI,SAAS,yBAAyB;CAC1C,QAAQ;EACN,qBAAqB;CACvB;CAEF,OAAO;AACT;AAKA,SAAS,cAAc,IAAuC;CAC5D,OACE,cAAc,oBACd,cAAc,qBACd,cAAc;AAElB;;;;;;;AAQA,SAAgB,kBAAkB,IAA+C;CAC/E,IAAI,OAAO,MAAM,OAAO;CACxB,IAAI,cAAc,EAAE,GAAG,OAAO;CAK9B,MAAM,YAHJ,cAAc,sBACV,CAAC,GAAG,GAAG,QAAQ,IACf,CAAC,GAAG,GAAG,iBAAiB,yBAAyB,CAAC,EAAA,CAC/B,OAAO,aAAa;CAC7C,OACE,SAAS,MAAM,MAAM,EAAE,gBAAgB,EAAE,SAAS,EAAE,KACpD,SAAS,MAAM,MAAM,EAAE,YAAY,KACnC,SAAS,MACT;AAEJ;;;;;;AAOA,SAAgB,cAAc,IAAwC;CACpE,IAAI,OAAO,MAAM,OAAO;CACxB,IAAI,cAAc,EAAE,GAAG,OAAO;CAC9B,MAAM,WACJ,cAAc,sBACV,CAAC,GAAG,GAAG,QAAQ,IACf,CAAC,GAAG,GAAG,iBAAiB,iCAAiC,CAAC,EAAA,CAC9D,QACC,MACC,aAAa,eACb,CAAE,EAAuB,YACxB,EAAuB,SAAS,QACrC;CAIA,OAHqB,QAAQ,MAC1B,MAAM,aAAa,oBAAoB,EAAE,SAAS,WAAW,EAAE,OAGrD,KACX,QAAQ,MAAM,MAAM,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,KACrD,QAAQ,KAAK,aAAa,KAC1B,QAAQ,MACR;AAEJ"}
@@ -1,4 +1,4 @@
1
- //#region src/internal/anchor-position.d.ts
1
+ //#region src/internal/overlay/anchor-position.d.ts
2
2
  /** A physical side of the anchor. */
3
3
  export type PhysicalSide = "top" | "bottom" | "left" | "right";
4
4
  /**
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchor-position.d.mts","names":[],"sources":["../../../src/internal/overlay/anchor-position.ts"],"mappings":";;YAcY;;;;;YAKA,aAAa;;;;;YAKb"}
@@ -1,4 +1,4 @@
1
- //#region src/internal/anchor-position.ts
1
+ //#region src/internal/overlay/anchor-position.ts
2
2
  /** Flip to the opposite side, then the other axis, then both, when the popup does not fit. */
3
3
  const POSITION_TRY_FALLBACKS = "flip-block, flip-inline, flip-block flip-inline";
4
4
  const SIDE_KEYWORD = {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchor-position.mjs","names":[],"sources":["../../../src/internal/overlay/anchor-position.ts"],"sourcesContent":["// Placement of a popover against its implicit anchor (the invoker set by `popovertarget`, `commandfor`,\n// `interestfor` or `showPopover({ source })`): inline `position-area` from a side and an\n// alignment, plus `position-try-fallbacks` that flip it when it does not fit; and the parser that\n// reads back which option the browser applied. Shared by Tooltip, Popover and Menu\n// (design/conventions.md 13; design/components/tooltip.md 7.1, popover.md 8).\n//\n// Keyword policy (conventions 13.1): physical keywords and the `self-*` group only. A plain\n// logical keyword (`block-end`, `span-inline-end`) on a top-layer popup resolves against the\n// root's writing mode, so it would ignore a `dir=\"rtl\"` container; `self-x-*` resolves against the\n// popup's own (inherited) direction. Keyword groups are never mixed in one value.\n//\n// No \"use client\" directive: pure functions, importable from anywhere (conventions 7.1).\n\n/** A physical side of the anchor. */\nexport type PhysicalSide = \"top\" | \"bottom\" | \"left\" | \"right\";\n/**\n * Side of the anchor the popup is placed on: physical, or inline-logical (`inline-start` /\n * `inline-end` follow the popup's own `direction` through the `self-x-*` keywords).\n */\nexport type AnchorSide = PhysicalSide | \"inline-start\" | \"inline-end\";\n/**\n * Alignment along that side: inline-relative on a `top` / `bottom` side (`start`: the popup's\n * inline-start edge meets the anchor's), the top / bottom edges on the others.\n */\nexport type AnchorAlign = \"start\" | \"center\" | \"end\";\n/** A computed `direction`. */\nexport type Direction = \"ltr\" | \"rtl\";\n\n/** Flip to the opposite side, then the other axis, then both, when the popup does not fit. */\nexport const POSITION_TRY_FALLBACKS = \"flip-block, flip-inline, flip-block flip-inline\";\n\nconst SIDE_KEYWORD: Record<AnchorSide, string> = {\n top: \"top\",\n bottom: \"bottom\",\n left: \"left\",\n right: \"right\",\n \"inline-start\": \"self-x-start\",\n \"inline-end\": \"self-x-end\",\n};\n\n/**\n * The `position-area` for a side and an alignment (the matrix of conventions 13.1):\n * `bottom` + `center` is `bottom`, `bottom` + `start` is `bottom span-self-x-end`, `right` +\n * `start` is `right span-bottom`, `inline-end` + `start` is `self-x-end span-bottom`.\n */\nexport function positionArea(side: AnchorSide, align: AnchorAlign): string {\n const keyword = SIDE_KEYWORD[side];\n if (align === \"center\") return keyword;\n const horizontal = side === \"top\" || side === \"bottom\";\n const span = horizontal\n ? align === \"start\"\n ? \"span-self-x-end\"\n : \"span-self-x-start\"\n : align === \"start\"\n ? \"span-bottom\"\n : \"span-top\";\n return `${keyword} ${span}`;\n}\n\n// --- Reading back the applied option (conventions 13.2) --------------------------------------\n\n/** Where the browser placed a popup: a physical side and the alignment along it. */\nexport interface ResolvedPlacement {\n readonly side: PhysicalSide;\n readonly align: AnchorAlign;\n}\n\ntype Axis = \"x\" | \"y\";\n\ninterface Token {\n /** `side`: the cell is on that side; `span`: spans toward a direction; `neutral`: neither. */\n readonly kind: \"side\" | \"span\" | \"neutral\";\n /** The physical direction of a `side` or `span` token. */\n readonly physical: PhysicalSide | null;\n}\n\nconst AXIS_OF: Record<PhysicalSide, Axis> = { top: \"y\", bottom: \"y\", left: \"x\", right: \"x\" };\n\n/**\n * Parses a computed `position-area` (conventions 13.2) into the physical side the popup sits on\n * and its alignment. Total: anything it cannot map returns `null` (`none`, an empty value, a\n * vertical `writing-mode`, a corner cell, the cell over the anchor, an unknown keyword), and the\n * part keeps the requested values. The engines serialise in grammar order, in any keyword group:\n * `span-left top`, `span-all bottom` (Firefox's form of a flipped `bottom`), `self-end\n * span-self-end`, `span-self-x-end bottom`, `self-x-start span-top`.\n *\n * `selfDirection` is the popup's computed `direction` (it resolves `self-*` tokens);\n * `rootDirection` the root's (plain `x-*` / `inline-*` tokens, which a consumer `style` override\n * may use), passed as a function so it is read only when such a token appears.\n */\nexport function parsePositionArea(\n value: string | null | undefined,\n selfDirection: Direction,\n rootDirection: Direction | (() => Direction),\n writingMode: string = \"horizontal-tb\",\n): ResolvedPlacement | null {\n if (writingMode !== \"horizontal-tb\" || typeof value !== \"string\") return null;\n const words = value.trim().split(/\\s+/);\n if (words.length > 2 || words[0] === \"\" || words[0] === \"none\") return null;\n let root: Direction | undefined;\n const rootDir = (): Direction =>\n (root ??= typeof rootDirection === \"function\" ? rootDirection() : rootDirection);\n\n const tokens: Token[] = [];\n for (let index = 0; index < words.length; index++) {\n const token = classify(words[index]!, index, words.length, selfDirection, rootDir);\n if (token === null) return null;\n tokens.push(token);\n }\n\n const sides = tokens.filter((t) => t.kind === \"side\");\n // No side (the cell over the anchor) or two (a corner): not a placement of the table.\n if (sides.length !== 1) return null;\n const side = sides[0]!.physical!;\n const span = tokens.find((t) => t.kind === \"span\");\n if (span === undefined) return { side, align: \"center\" };\n const toward = span.physical!;\n if (AXIS_OF[toward] === AXIS_OF[side]) return null;\n if (AXIS_OF[side] === \"y\") {\n // Inline-relative: spanning toward the popup's inline-end puts the inline-start edges\n // together.\n const inlineEnd: PhysicalSide = selfDirection === \"rtl\" ? \"left\" : \"right\";\n return { side, align: toward === inlineEnd ? \"start\" : \"end\" };\n }\n return { side, align: toward === \"bottom\" ? \"start\" : \"end\" };\n}\n\nfunction classify(\n word: string,\n index: number,\n count: number,\n selfDirection: Direction,\n rootDirection: () => Direction,\n): Token | null {\n if (word === \"center\" || word === \"span-all\") return { kind: \"neutral\", physical: null };\n const span = word.startsWith(\"span-\");\n const physical = physicalOf(\n span ? word.slice(5) : word,\n index,\n count,\n selfDirection,\n rootDirection,\n );\n return physical === null ? null : { kind: span ? \"span\" : \"side\", physical };\n}\n\n/**\n * The physical direction a keyword names, in `horizontal-tb`. Bare `start` / `end` /\n * `self-start` / `self-end` are positional: the block axis first, the inline axis second; alone\n * they name both axes (a corner, or a span over both), which the table does not describe.\n */\nfunction physicalOf(\n name: string,\n index: number,\n count: number,\n selfDirection: Direction,\n rootDirection: () => Direction,\n): PhysicalSide | null {\n switch (name) {\n case \"top\":\n case \"bottom\":\n case \"left\":\n case \"right\":\n return name;\n // The block axis is top / bottom in horizontal-tb, whatever the direction.\n case \"y-start\":\n case \"self-y-start\":\n case \"y-self-start\":\n case \"block-start\":\n case \"self-block-start\":\n return \"top\";\n case \"y-end\":\n case \"self-y-end\":\n case \"y-self-end\":\n case \"block-end\":\n case \"self-block-end\":\n return \"bottom\";\n // The inline axis against the popup's own direction.\n case \"self-x-start\":\n case \"x-self-start\":\n case \"self-inline-start\":\n return inlineEdge(\"start\", selfDirection);\n case \"self-x-end\":\n case \"x-self-end\":\n case \"self-inline-end\":\n return inlineEdge(\"end\", selfDirection);\n // The inline axis against the containing block's (the root's, for a top-layer popup).\n case \"x-start\":\n case \"inline-start\":\n return inlineEdge(\"start\", rootDirection());\n case \"x-end\":\n case \"inline-end\":\n return inlineEdge(\"end\", rootDirection());\n case \"start\":\n case \"end\":\n case \"self-start\":\n case \"self-end\": {\n if (count !== 2) return null;\n const edge = name.endsWith(\"start\") ? \"start\" : \"end\";\n if (index === 0) return edge === \"start\" ? \"top\" : \"bottom\";\n return inlineEdge(edge, name.startsWith(\"self-\") ? selfDirection : rootDirection());\n }\n default:\n return null;\n }\n}\n\nfunction inlineEdge(edge: \"start\" | \"end\", direction: Direction): PhysicalSide {\n return (edge === \"start\") === (direction === \"ltr\") ? \"left\" : \"right\";\n}\n"],"mappings":"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"}
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { useCallback, useLayoutEffect, useRef } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
- //#region src/internal/content-focus-probe.tsx
4
+ //#region src/internal/overlay/content-focus-probe.tsx
5
5
  /**
6
6
  * Records, from its layout-effect cleanup, whether focus is inside the popup when the content
7
7
  * goes away: React runs a deleted component's layout cleanups before it detaches the host nodes,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-focus-probe.mjs","names":[],"sources":["../../../src/internal/overlay/content-focus-probe.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useLayoutEffect, useRef } from \"react\";\nimport type { ReactNode, RefObject } from \"react\";\n\n/**\n * Records, from its layout-effect cleanup, whether focus is inside the popup when the content\n * goes away: React runs a deleted component's layout cleanups before it detaches the host nodes,\n * so `document.activeElement` still names the focused element there.\n */\nfunction ContentFocusProbe({\n onDetach,\n children,\n}: {\n onDetach: () => void;\n children?: ReactNode;\n}): ReactNode {\n useLayoutEffect(() => onDetach, [onDetach]);\n return children;\n}\n\nexport interface ContentFocusProbeHook {\n /**\n * Wraps the library-mode content of a top-layer popup: call it only while the content is\n * shown (`visible ? wrapContent(x) : null`), or inside the `<Activity>` for `keepMounted`.\n */\n readonly wrapContent: (children: ReactNode) => ReactNode;\n /**\n * Whether the wrapped content unmounted (or was hidden by `<Activity>`) while it held focus\n * since the last `forget()`. The owner reads it after its close\n * (design/components/popover.md 6.2 rule 2, design/components/dialog.md 6.2 rule 2).\n * Handlers and effects only.\n */\n readonly hadFocus: () => boolean;\n /**\n * Clear the record: on every open, after the owner used it, and whenever the content went\n * away while the popup stays open (not a close).\n */\n readonly forget: () => void;\n}\n\n/**\n * The content probe shared by the popover-like Popups (Popover, Menu) and Dialog.Popup: a\n * library-driven close with `transition` unmounts the content, the focused Close part included,\n * in the close commit, before the layout effect that hides the popup runs, so focus falls to\n * `<body>` and the platform may restore nothing. The probe tells the owner that this happened.\n */\nexport function useContentFocusProbe(\n popupRef: RefObject<HTMLElement | null>,\n): ContentFocusProbeHook {\n const lostFocus = useRef(false);\n\n const record = useCallback(() => {\n const element = popupRef.current;\n if (element === null) return;\n const active = element.ownerDocument.activeElement;\n if (active !== null && active !== element && element.contains(active)) {\n lostFocus.current = true;\n }\n }, [popupRef]);\n\n const wrapContent = useCallback(\n (children: ReactNode): ReactNode => (\n <ContentFocusProbe onDetach={record}>{children}</ContentFocusProbe>\n ),\n [record],\n );\n const hadFocus = useCallback(() => lostFocus.current, []);\n const forget = useCallback(() => {\n lostFocus.current = false;\n }, []);\n\n return { wrapContent, hadFocus, forget };\n}\n"],"mappings":";;;;;;;;;AASA,SAAS,kBAAkB,EACzB,UACA,YAIY;CACZ,sBAAsB,UAAU,CAAC,QAAQ,CAAC;CAC1C,OAAO;AACT;;;;;;;AA4BA,SAAgB,qBACd,UACuB;CACvB,MAAM,YAAY,OAAO,KAAK;CAE9B,MAAM,SAAS,kBAAkB;EAC/B,MAAM,UAAU,SAAS;EACzB,IAAI,YAAY,MAAM;EACtB,MAAM,SAAS,QAAQ,cAAc;EACrC,IAAI,WAAW,QAAQ,WAAW,WAAW,QAAQ,SAAS,MAAM,GAClE,UAAU,UAAU;CAExB,GAAG,CAAC,QAAQ,CAAC;CAab,OAAO;EAAE,aAXW,aACjB,aACC,oBAAC,mBAAD;GAAmB,UAAU;GAAS;EAA4B,CAAA,GAEpE,CAAC,MAAM,CAOU;EAAG,UALL,kBAAkB,UAAU,SAAS,CAAC,CAK1B;EAAG,QAJjB,kBAAkB;GAC/B,UAAU,UAAU;EACtB,GAAG,CAAC,CAEiC;CAAE;AACzC"}
@@ -1,4 +1,4 @@
1
- //#region src/internal/css-transition-cut.ts
1
+ //#region src/internal/overlay/css-transition-cut.ts
2
2
  /** What `transition: none` sets, each restored on its own. */
3
3
  const LONGHANDS = [
4
4
  "transition-property",
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css-transition-cut.mjs","names":[],"sources":["../../../src/internal/overlay/css-transition-cut.ts"],"sourcesContent":["// No directive: a DOM helper (conventions 7.1).\n\n/** What `transition: none` sets, each restored on its own. */\nconst LONGHANDS = [\n \"transition-property\",\n \"transition-duration\",\n \"transition-timing-function\",\n \"transition-delay\",\n \"transition-behavior\",\n] as const;\n\n/** Elements inside a cut right now: a nested call (Menu's `reshow`) runs inside the outer one. */\nconst cutting = new WeakSet<HTMLElement>();\n\n/** Whether a document view transition is running (`html:active-view-transition`). */\nfunction viewTransitionActive(element: HTMLElement): boolean {\n try {\n return element.ownerDocument.documentElement.matches(\":active-view-transition\");\n } catch {\n // An engine (or jsdom) that does not know the pseudo-class has no view transition to avoid.\n return false;\n }\n}\n\n/**\n * Runs the library's own show or hide of a popup (`showPopover()`, `hidePopover()`,\n * `showModal()`, `show()`, `close()`) with the popup's CSS transitions cut, when the Popup has a\n * `transition` prop and a view transition is running (conventions 5.1, issue #147). The view\n * transition animates that show or hide; a CSS `transition` on the popup would run next to it\n * (the open's `@starting-style` enter under the view transition's enter; in Chromium the close's\n * `display` / `overlay` fade keeps the hidden box in the new snapshot, a double image).\n *\n * One synchronous step: an inline `transition: none !important`, the call, a forced style\n * recalculation (without it Chromium sees the restored value and the fade runs), and the inline\n * `transition` longhands restored as they were, so nothing is left for React's `style` diffing.\n * Everything goes through CSSOM, never the `style` attribute: a CSP without `'unsafe-inline'`\n * for styles blocks an attribute write (React's `style` prop is CSSOM too). Only CSS\n * transitions are cut, not a `@keyframes` animation. Dismissals (Escape, light dismiss) never\n * come here: their CSS exit plays.\n */\nexport function withCssTransitionCut<T>(\n element: HTMLElement,\n hasTransition: boolean,\n run: () => T,\n): T {\n if (!hasTransition || cutting.has(element) || !viewTransitionActive(element)) return run();\n const { style } = element;\n const hadAttribute = element.hasAttribute(\"style\");\n // The shorthand, and the longhands for a consumer who set only some of them (the shorthand\n // then reads as \"\").\n const shorthand = style.getPropertyValue(\"transition\");\n const shorthandPriority = style.getPropertyPriority(\"transition\");\n const longhands = LONGHANDS.map(\n (name) => [name, style.getPropertyValue(name), style.getPropertyPriority(name)] as const,\n );\n cutting.add(element);\n style.setProperty(\"transition\", \"none\", \"important\");\n try {\n return run();\n } finally {\n // The show or hide's style change is processed while the cut is in place.\n void getComputedStyle(element).opacity;\n // Only while the cut is still ours: a listener inside the call that wrote its own\n // `transition` keeps it.\n const ours = (name: string) =>\n style.getPropertyValue(name) === \"none\" && style.getPropertyPriority(name) === \"important\";\n if (ours(\"transition-property\") || ours(\"transition\")) {\n style.removeProperty(\"transition\");\n if (shorthand !== \"\") {\n style.setProperty(\"transition\", shorthand, shorthandPriority);\n } else {\n for (const [name, value, priority] of longhands) {\n if (value !== \"\") style.setProperty(name, value, priority);\n }\n }\n }\n // `removeAttribute` parses nothing, so CSP does not block it.\n if (!hadAttribute && style.length === 0) element.removeAttribute(\"style\");\n cutting.delete(element);\n }\n}\n"],"mappings":";;AAGA,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,0BAAU,IAAI,QAAqB;;AAGzC,SAAS,qBAAqB,SAA+B;CAC3D,IAAI;EACF,OAAO,QAAQ,cAAc,gBAAgB,QAAQ,yBAAyB;CAChF,QAAQ;EAEN,OAAO;CACT;AACF;;;;;;;;;;;;;;;;;AAkBA,SAAgB,qBACd,SACA,eACA,KACG;CACH,IAAI,CAAC,iBAAiB,QAAQ,IAAI,OAAO,KAAK,CAAC,qBAAqB,OAAO,GAAG,OAAO,IAAI;CACzF,MAAM,EAAE,UAAU;CAClB,MAAM,eAAe,QAAQ,aAAa,OAAO;CAGjD,MAAM,YAAY,MAAM,iBAAiB,YAAY;CACrD,MAAM,oBAAoB,MAAM,oBAAoB,YAAY;CAChE,MAAM,YAAY,UAAU,KACzB,SAAS;EAAC;EAAM,MAAM,iBAAiB,IAAI;EAAG,MAAM,oBAAoB,IAAI;CAAC,CAChF;CACA,QAAQ,IAAI,OAAO;CACnB,MAAM,YAAY,cAAc,QAAQ,WAAW;CACnD,IAAI;EACF,OAAO,IAAI;CACb,UAAU;EAER,iBAAsB,OAAO,CAAC,CAAC;EAG/B,MAAM,QAAQ,SACZ,MAAM,iBAAiB,IAAI,MAAM,UAAU,MAAM,oBAAoB,IAAI,MAAM;EACjF,IAAI,KAAK,qBAAqB,KAAK,KAAK,YAAY,GAAG;GACrD,MAAM,eAAe,YAAY;GACjC,IAAI,cAAc,IAChB,MAAM,YAAY,cAAc,WAAW,iBAAiB;QAE5D,KAAK,MAAM,CAAC,MAAM,OAAO,aAAa,WACpC,IAAI,UAAU,IAAI,MAAM,YAAY,MAAM,OAAO,QAAQ;EAG/D;EAEA,IAAI,CAAC,gBAAgB,MAAM,WAAW,GAAG,QAAQ,gBAAgB,OAAO;EACxE,QAAQ,OAAO,OAAO;CACxB;AACF"}
@@ -1,4 +1,4 @@
1
- //#region src/internal/focus-visible.ts
1
+ //#region src/internal/overlay/focus-visible.ts
2
2
  let focusVisibleOption;
3
3
  /**
4
4
  * The engine reads the `focusVisible` member of `focus()`'s options (Chromium 145, Firefox 104,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus-visible.mjs","names":[],"sources":["../../../src/internal/overlay/focus-visible.ts"],"sourcesContent":["// Directive-free: the `focus({ focusVisible })` probe behind a pointer open's quiet initial focus\n// (design/components/popover.md 6.1, menu.md 6.1).\n\n/**\n * An initial focus target opened by a pointer: where the engine reads `focus({ focusVisible })`,\n * the library focuses it with `focusVisible: false` right after `showPopover()` instead of\n * writing `autofocus` (WebKit shows the ring for an `autofocus` target after a click).\n * Elsewhere it is an ordinary target.\n */\nexport interface QuietFocusTarget {\n readonly element: HTMLElement;\n readonly focusVisible: false;\n}\n\nlet focusVisibleOption: boolean | undefined;\n\n/**\n * The engine reads the `focusVisible` member of `focus()`'s options (Chromium 145, Firefox 104,\n * Safari 18.4). Detected once through a getter: the bindings convert the dictionary before the\n * method runs, so a detached element is enough and nothing is focused.\n */\nexport function supportsFocusVisibleOption(doc: Document): boolean {\n if (focusVisibleOption === undefined) {\n let read = false;\n try {\n doc.createElement(\"div\").focus({\n get focusVisible() {\n read = true;\n return false;\n },\n } as FocusOptions);\n } catch {\n read = false;\n }\n focusVisibleOption = read;\n }\n return focusVisibleOption;\n}\n\n/** Tests only: forget the detection, so the next pointer open detects the option again. */\nexport function resetFocusVisibleOption(): void {\n focusVisibleOption = undefined;\n}\n"],"mappings":";AAcA,IAAI;;;;;;AAOJ,SAAgB,2BAA2B,KAAwB;CACjE,IAAI,uBAAuB,KAAA,GAAW;EACpC,IAAI,OAAO;EACX,IAAI;GACF,IAAI,cAAc,KAAK,CAAC,CAAC,MAAM,EAC7B,IAAI,eAAe;IACjB,OAAO;IACP,OAAO;GACT,EACF,CAAiB;EACnB,QAAQ;GACN,OAAO;EACT;EACA,qBAAqB;CACvB;CACA,OAAO;AACT"}
@@ -1,4 +1,4 @@
1
- //#region src/internal/invokers.ts
1
+ //#region src/internal/overlay/invokers.ts
2
2
  /**
3
3
  * The `source` of a `ToggleEvent` (Chromium 140, Firefox 145, Safari 26.5), a `CommandEvent` or
4
4
  * an `InterestEvent`: the invoker that caused it, `null` without one. Not in TypeScript's DOM lib
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invokers.mjs","names":[],"sources":["../../../src/internal/overlay/invokers.ts"],"sourcesContent":["// No directive: DOM reads and listeners only (conventions 7.1). The platform's invoker\n// relationship between a button and a popover, as the overlays read it.\n\n/** An invoker button's IDL; absent where the engine lacks the Popover API or Invoker Commands. */\ninterface InvokerButton {\n readonly popoverTargetElement?: Element | null;\n readonly commandForElement?: Element | null;\n readonly command?: string;\n}\n\n/**\n * The `source` of a `ToggleEvent` (Chromium 140, Firefox 145, Safari 26.5), a `CommandEvent` or\n * an `InterestEvent`: the invoker that caused it, `null` without one. Not in TypeScript's DOM lib\n * for all three.\n */\nexport function eventSource(event: Event): Element | null {\n return (event as Event & { readonly source?: Element | null }).source ?? null;\n}\n\n/**\n * Whether the `ToggleEvent.source` of a close is a `popovertarget` invoker of `popup`. A\n * `commandfor` or `interestfor` invoker sets `source` too (Chromium's lost-interest hide, a\n * dismissal), and so names no `popovertarget` here.\n */\nexport function closedByPopoverTarget(event: ToggleEvent, popup: HTMLElement): boolean {\n const source = eventSource(event);\n return (\n (source instanceof HTMLButtonElement || source instanceof HTMLInputElement) &&\n source.popoverTargetElement === popup\n );\n}\n\n/** The `<input>` types HTML counts as buttons: the ones `popovertarget` applies to. */\nconst INPUT_BUTTON_TYPES = new Set([\"submit\", \"image\", \"reset\", \"button\"]);\n\n/**\n * Whether a press on `target` is a press on a foreign invoker of `popup`: its closest button (a\n * `<button>`, or an `<input>` of a button type) is outside the popup and names it through\n * `popovertarget`, or (a `<button>`) through `commandfor` with a popover command\n * (`toggle-popover`, `show-popover`, `hide-popover`). HTML's invoker relationship, the one light\n * dismiss exempts (conventions 3.5): a disabled button and a submit button with a form owner\n * invoke nothing. Read through the IDL, so an engine without it has no such invoker.\n */\nexport function isPopoverInvoker(target: EventTarget | null, popup: Element): boolean {\n if (!(target instanceof Element)) return false;\n const button = target.closest<HTMLButtonElement | HTMLInputElement>(\"button, input\");\n if (button === null || popup.contains(button)) return false;\n const isInput = button.tagName === \"INPUT\";\n if (isInput && !INPUT_BUTTON_TYPES.has(button.type)) return false;\n if (button.disabled) return false;\n if (button.form !== null && (button.type === \"submit\" || button.type === \"image\")) return false;\n const invoker = button as InvokerButton;\n if (invoker.popoverTargetElement === popup) return true;\n return !isInput && invoker.commandForElement === popup && /-popover$/.test(invoker.command ?? \"\");\n}\n\n/**\n * While a popup that closes on focus leaving is shown: a primary-button `mousedown` on a foreign\n * invoker of it moves no focus (conventions 3.5). Chromium and Firefox focus a button on\n * press, which would close the popup at the `focusout` before the click's own toggle (as\n * `\"dismiss\"`, and the toggle then re-showed it). Returns the cleanup.\n */\nexport function listenInvokerPresses(popup: HTMLElement): () => void {\n const doc = popup.ownerDocument;\n const onMouseDown = (event: MouseEvent) => {\n if (event.button === 0 && isPopoverInvoker(event.target, popup)) event.preventDefault();\n };\n doc.addEventListener(\"mousedown\", onMouseDown, true);\n return () => doc.removeEventListener(\"mousedown\", onMouseDown, true);\n}\n"],"mappings":";;;;;;AAeA,SAAgB,YAAY,OAA8B;CACxD,OAAQ,MAAuD,UAAU;AAC3E;;;;;;AAOA,SAAgB,sBAAsB,OAAoB,OAA6B;CACrF,MAAM,SAAS,YAAY,KAAK;CAChC,QACG,kBAAkB,qBAAqB,kBAAkB,qBAC1D,OAAO,yBAAyB;AAEpC;;AAGA,MAAM,qCAAqB,IAAI,IAAI;CAAC;CAAU;CAAS;CAAS;AAAQ,CAAC;;;;;;;;;AAUzE,SAAgB,iBAAiB,QAA4B,OAAyB;CACpF,IAAI,EAAE,kBAAkB,UAAU,OAAO;CACzC,MAAM,SAAS,OAAO,QAA8C,eAAe;CACnF,IAAI,WAAW,QAAQ,MAAM,SAAS,MAAM,GAAG,OAAO;CACtD,MAAM,UAAU,OAAO,YAAY;CACnC,IAAI,WAAW,CAAC,mBAAmB,IAAI,OAAO,IAAI,GAAG,OAAO;CAC5D,IAAI,OAAO,UAAU,OAAO;CAC5B,IAAI,OAAO,SAAS,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU,OAAO;CAC1F,MAAM,UAAU;CAChB,IAAI,QAAQ,yBAAyB,OAAO,OAAO;CACnD,OAAO,CAAC,WAAW,QAAQ,sBAAsB,SAAS,YAAY,KAAK,QAAQ,WAAW,EAAE;AAClG;;;;;;;AAQA,SAAgB,qBAAqB,OAAgC;CACnE,MAAM,MAAM,MAAM;CAClB,MAAM,eAAe,UAAsB;EACzC,IAAI,MAAM,WAAW,KAAK,iBAAiB,MAAM,QAAQ,KAAK,GAAG,MAAM,eAAe;CACxF;CACA,IAAI,iBAAiB,aAAa,aAAa,IAAI;CACnD,aAAa,IAAI,oBAAoB,aAAa,aAAa,IAAI;AACrE"}
@@ -1,4 +1,4 @@
1
- //#region src/internal/modal-registry.ts
1
+ //#region src/internal/overlay/modal-registry.ts
2
2
  const stack = [];
3
3
  const listeners = /* @__PURE__ */ new Set();
4
4
  function notify() {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modal-registry.mjs","names":[],"sources":["../../../src/internal/overlay/modal-registry.ts"],"sourcesContent":["// No \"use client\" directive: a plain module-level store, no React and no DOM calls\n// (design/components/toast.md 4.3, conventions 3.5 \"module-level registry\").\n//\n// The stack of open modal `<dialog>` elements the library's Dialog opened. A top-layer element\n// outside the topmost modal dialog is inert and absent from the accessibility tree, so Toast's\n// Viewport portals its region into the topmost one. Writers (`use-modal-registration.ts`) run\n// in layout effects and platform event listeners, never during render; readers subscribe through\n// `useSyncExternalStore` with a server snapshot of `null`. Never the source of truth for a\n// component's own state.\n\nconst stack: Element[] = [];\nconst listeners = new Set<() => void>();\n\nfunction notify(): void {\n for (const listener of [...listeners]) listener();\n}\n\n/** Records `dialog` as the topmost open modal dialog (moves it to the top if already present). */\nexport function pushModal(dialog: Element): void {\n const index = stack.indexOf(dialog);\n if (index !== -1 && index === stack.length - 1) return;\n if (index !== -1) stack.splice(index, 1);\n stack.push(dialog);\n notify();\n}\n\n/** Forgets `dialog` (closed or unmounted). */\nexport function removeModal(dialog: Element): void {\n const index = stack.indexOf(dialog);\n if (index === -1) return;\n stack.splice(index, 1);\n notify();\n}\n\nexport function subscribeModals(listener: () => void): () => void {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n}\n\n/** The topmost open modal dialog the library opened, or `null`. */\nexport function getTopmostModal(): Element | null {\n return stack.at(-1) ?? null;\n}\n\n/** The server snapshot: nothing is open on the server. */\nexport function getServerTopmostModal(): Element | null {\n return null;\n}\n"],"mappings":";AAUA,MAAM,QAAmB,CAAC;AAC1B,MAAM,4BAAY,IAAI,IAAgB;AAEtC,SAAS,SAAe;CACtB,KAAK,MAAM,YAAY,CAAC,GAAG,SAAS,GAAG,SAAS;AAClD;;AAGA,SAAgB,UAAU,QAAuB;CAC/C,MAAM,QAAQ,MAAM,QAAQ,MAAM;CAClC,IAAI,UAAU,MAAM,UAAU,MAAM,SAAS,GAAG;CAChD,IAAI,UAAU,IAAI,MAAM,OAAO,OAAO,CAAC;CACvC,MAAM,KAAK,MAAM;CACjB,OAAO;AACT;;AAGA,SAAgB,YAAY,QAAuB;CACjD,MAAM,QAAQ,MAAM,QAAQ,MAAM;CAClC,IAAI,UAAU,IAAI;CAClB,MAAM,OAAO,OAAO,CAAC;CACrB,OAAO;AACT;AAEA,SAAgB,gBAAgB,UAAkC;CAChE,UAAU,IAAI,QAAQ;CACtB,aAAa;EACX,UAAU,OAAO,QAAQ;CAC3B;AACF;;AAGA,SAAgB,kBAAkC;CAChD,OAAO,MAAM,GAAG,EAAE,KAAK;AACzB;;AAGA,SAAgB,wBAAwC;CACtD,OAAO;AACT"}
@@ -1,10 +1,10 @@
1
1
  "use client";
2
- import { ToolbarContext } from "./toolbar-context.mjs";
3
- import { useDevWarning } from "./use-dev-warning.mjs";
2
+ import { ToolbarContext } from "../toolbar-context.mjs";
3
+ import { useDevWarning } from "../use-dev-warning.mjs";
4
4
  import { useExitAnimation } from "./use-exit-animation.mjs";
5
5
  import { Activity, useRef, useState } from "react";
6
6
  import { jsx } from "react/jsx-runtime";
7
- //#region src/internal/overlay-popup.tsx
7
+ //#region src/internal/overlay/overlay-popup.tsx
8
8
  const isDev = process.env.NODE_ENV !== "production";
9
9
  /**
10
10
  * The children of a popup (Popover, Dialog, Menu, Combobox). JS-free mode: always rendered.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overlay-popup.mjs","names":[],"sources":["../../../src/internal/overlay/overlay-popup.tsx"],"sourcesContent":["\"use client\";\n// The pieces Dialog.Popup shares with usePopoverPopup (Popover, Menu, Combobox); the close /\n// echo / refused-fact flags and the show wrapper are in overlay-show.ts, the apply effect in\n// use-apply-open-state.ts. The two stay separate: Dialog has showModal / show, `close` /\n// `cancel` / `submit` and light dismiss. What they still write twice: mount reconciliation, the\n// platform listeners and the JS-free `autofocus` write.\nimport { Activity, useRef, useState } from \"react\";\nimport type { ReactNode, RefObject, ViewTransitionClass } from \"react\";\nimport { ToolbarContext } from \"../toolbar-context.js\";\nimport { useDevWarning } from \"../use-dev-warning.js\";\nimport { useExitAnimation } from \"./use-exit-animation.js\";\nimport type { ExitAnimation } from \"./use-exit-animation.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface OverlayContentOptions {\n readonly isLibrary: boolean;\n readonly keepMounted: boolean | undefined;\n /** Committed open, or held while the exit animates (design/components/popover.md 4.4). */\n readonly visible: boolean;\n readonly wrapContent: (children: ReactNode) => ReactNode;\n}\n\n/**\n * The children of a popup (Popover, Dialog, Menu, Combobox). JS-free mode: always rendered.\n * Library mode: rendered while `visible`, or with `keepMounted` inside an `<Activity>` whose mode\n * changes with committed state, inside the Root's transition (conventions 5.5). The content is\n * not part of an enclosing Toolbar's sequence (the engine excludes `[popover]` and `dialog`), so\n * parts inside it see no Toolbar. `children` is called only when rendered.\n */\nexport function renderOverlayContent(\n { isLibrary, keepMounted, visible, wrapContent }: OverlayContentOptions,\n children: () => ReactNode,\n): ReactNode {\n let node: ReactNode;\n if (!isLibrary) {\n node = children();\n } else if (keepMounted === true) {\n node = <Activity mode={visible ? \"visible\" : \"hidden\"}>{wrapContent(children())}</Activity>;\n } else {\n node = visible ? wrapContent(children()) : null;\n }\n return <ToolbarContext value={null}>{node}</ToolbarContext>;\n}\n\nexport interface CloseHold extends ExitAnimation {\n /**\n * The close's native event (`toggle` / `close`) arrived: hold the content until the exit\n * animations settle, or release a hold now when nothing animates (Firefox, or no CSS exit: the\n * popup is already `display: none`, the commit is invisible). Call before reporting the fact,\n * so its commit keeps the children. Nothing for the library's own close (`echo`) with\n * `transition`: the close commit's view transition carried the content out.\n */\n readonly afterClose: (popup: Element, echo: boolean) => void;\n /**\n * The apply effect's release rule: a hold the close commit set (or a fact's commit) that no\n * exit animation is going to release, the popup being hidden and its close event handled.\n */\n readonly releaseIfIdle: (committed: boolean, awaitingClose: boolean, shown: boolean) => void;\n}\n\n/**\n * `held` for a popup (design/components/popover.md 4.4): the children stay mounted while the\n * close animates. A library-driven close commits `false` first and hides in the layout effect,\n * so without `transition` the children are held through the close commit (\"previous value in\n * state\"). With `transition` the close commit unmounts them inside the view transition, whose old\n * snapshot carries the content out.\n */\nexport function useCloseHold(\n committed: boolean,\n isLibrary: boolean,\n transition: ViewTransitionClass | undefined,\n): CloseHold {\n const exit = useExitAnimation();\n const [prevCommitted, setPrevCommitted] = useState(committed);\n if (prevCommitted !== committed) {\n setPrevCommitted(committed);\n if (isLibrary && prevCommitted && transition === undefined) exit.holdDuringRender();\n }\n return {\n ...exit,\n afterClose: (popup, echo) => {\n if (echo && transition !== undefined) return;\n const animations = exit.exitAnimations(popup);\n if (animations.length > 0) exit.holdUntil(animations);\n else exit.release();\n },\n releaseIfIdle: (isCommitted, awaitingClose, shown) => {\n if (exit.held && !isCommitted && !exit.waiting() && !awaitingClose && !shown) {\n exit.release();\n }\n },\n };\n}\n\n/** The lower-cased `command` of a `command` event. */\nexport function commandOf(event: Event): string {\n return String((event as Event & { command?: string }).command ?? \"\").toLowerCase();\n}\n\n/** Resolves `initialFocus` against the popup (a ref, or a selector inside the popup). */\nexport function resolveInitialFocus(\n popup: HTMLElement,\n initialFocus: RefObject<HTMLElement | null> | string,\n): HTMLElement | null {\n if (typeof initialFocus === \"string\") return popup.querySelector<HTMLElement>(initialFocus);\n return initialFocus.current;\n}\n\nexport type InitialFocusTarget = (\n popup: HTMLElement,\n initialFocus: RefObject<HTMLElement | null> | string | undefined,\n) => HTMLElement | null;\n\n/**\n * `initialFocus` resolved right before a library open (design 6.1): the target, or `null` (the\n * platform picks) without one, or when it resolves to nothing or outside the popup; those two\n * warn once per instance in development. `noun` names the popup in the warning.\n */\nexport function useInitialFocusTarget(part: string, noun: string): InitialFocusTarget {\n const warned = useRef(false);\n return (popup, initialFocus) => {\n if (initialFocus === undefined) return null;\n const target = resolveInitialFocus(popup, initialFocus);\n if (target !== null && popup.contains(target)) return target;\n if (isDev && !warned.current) {\n warned.current = true;\n console.error(\n target === null\n ? `${part}: \\`initialFocus\\` resolved to no element; the platform picks the focus target.`\n : `${part}: \\`initialFocus\\` is outside the ${noun}; the platform picks the focus target.`,\n );\n }\n return null;\n };\n}\n\n/**\n * Design 6.2 rule 2, after a close that began with focus inside (or whose commit unmounted the\n * focused content): when focus is now on `<body>` or still inside the hidden popup, focus the\n * Trigger (connected, and `canFocus` when given), else blur what holds focus.\n */\nexport function returnFocusToTrigger(\n popup: HTMLElement,\n trigger: HTMLElement | null,\n canFocus?: (trigger: HTMLElement) => boolean,\n): void {\n const doc = popup.ownerDocument;\n const active = doc.activeElement;\n if (active !== null && active !== doc.body && !popup.contains(active)) return;\n if (trigger !== null && trigger.isConnected && (canFocus === undefined || canFocus(trigger))) {\n trigger.focus();\n } else if (active instanceof HTMLElement && active !== doc.body) {\n active.blur();\n }\n}\n\n/** The development warnings for a Popup's library-only props in JS-free mode. */\nexport function useJsFreePropWarnings(\n part: string,\n noun: string,\n isLibrary: boolean,\n transition: ViewTransitionClass | undefined,\n keepMounted: boolean | undefined,\n): void {\n useDevWarning(\n !isLibrary && transition !== undefined,\n isDev &&\n `${part}: \\`transition\\` has no effect in JS-free mode; the browser opens and closes the ` +\n `${noun} outside any React transition. Animate it with CSS (\\`@starting-style\\`).`,\n );\n useDevWarning(\n !isLibrary && keepMounted === false,\n isDev &&\n `${part}: \\`keepMounted={false}\\` cannot be honoured in JS-free mode; the content is ` +\n \"always mounted so that the server HTML is complete.\",\n );\n}\n"],"mappings":";;;;;;;AAaA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;AAiBvC,SAAgB,qBACd,EAAE,WAAW,aAAa,SAAS,eACnC,UACW;CACX,IAAI;CACJ,IAAI,CAAC,WACH,OAAO,SAAS;MACX,IAAI,gBAAgB,MACzB,OAAO,oBAAC,UAAD;EAAU,MAAM,UAAU,YAAY;EAAW,UAAA,YAAY,SAAS,CAAC;CAAY,CAAA;MAE1F,OAAO,UAAU,YAAY,SAAS,CAAC,IAAI;CAE7C,OAAO,oBAAC,gBAAD;EAAgB,OAAO;EAAO,UAAA;CAAqB,CAAA;AAC5D;;;;;;;;AAyBA,SAAgB,aACd,WACA,WACA,YACW;CACX,MAAM,OAAO,iBAAiB;CAC9B,MAAM,CAAC,eAAe,oBAAoB,SAAS,SAAS;CAC5D,IAAI,kBAAkB,WAAW;EAC/B,iBAAiB,SAAS;EAC1B,IAAI,aAAa,iBAAiB,eAAe,KAAA,GAAW,KAAK,iBAAiB;CACpF;CACA,OAAO;EACL,GAAG;EACH,aAAa,OAAO,SAAS;GAC3B,IAAI,QAAQ,eAAe,KAAA,GAAW;GACtC,MAAM,aAAa,KAAK,eAAe,KAAK;GAC5C,IAAI,WAAW,SAAS,GAAG,KAAK,UAAU,UAAU;QAC/C,KAAK,QAAQ;EACpB;EACA,gBAAgB,aAAa,eAAe,UAAU;GACpD,IAAI,KAAK,QAAQ,CAAC,eAAe,CAAC,KAAK,QAAQ,KAAK,CAAC,iBAAiB,CAAC,OACrE,KAAK,QAAQ;EAEjB;CACF;AACF;;AAGA,SAAgB,UAAU,OAAsB;CAC9C,OAAO,OAAQ,MAAuC,WAAW,EAAE,CAAC,CAAC,YAAY;AACnF;;AAGA,SAAgB,oBACd,OACA,cACoB;CACpB,IAAI,OAAO,iBAAiB,UAAU,OAAO,MAAM,cAA2B,YAAY;CAC1F,OAAO,aAAa;AACtB;;;;;;AAYA,SAAgB,sBAAsB,MAAc,MAAkC;CACpF,MAAM,SAAS,OAAO,KAAK;CAC3B,QAAQ,OAAO,iBAAiB;EAC9B,IAAI,iBAAiB,KAAA,GAAW,OAAO;EACvC,MAAM,SAAS,oBAAoB,OAAO,YAAY;EACtD,IAAI,WAAW,QAAQ,MAAM,SAAS,MAAM,GAAG,OAAO;EACtD,IAAI,SAAS,CAAC,OAAO,SAAS;GAC5B,OAAO,UAAU;GACjB,QAAQ,MACN,WAAW,OACP,GAAG,KAAK,mFACR,GAAG,KAAK,oCAAoC,KAAK,uCACvD;EACF;EACA,OAAO;CACT;AACF;;;;;;AAOA,SAAgB,qBACd,OACA,SACA,UACM;CACN,MAAM,MAAM,MAAM;CAClB,MAAM,SAAS,IAAI;CACnB,IAAI,WAAW,QAAQ,WAAW,IAAI,QAAQ,CAAC,MAAM,SAAS,MAAM,GAAG;CACvE,IAAI,YAAY,QAAQ,QAAQ,gBAAgB,aAAa,KAAA,KAAa,SAAS,OAAO,IACxF,QAAQ,MAAM;MACT,IAAI,kBAAkB,eAAe,WAAW,IAAI,MACzD,OAAO,KAAK;AAEhB;;AAGA,SAAgB,sBACd,MACA,MACA,WACA,YACA,aACM;CACN,cACE,CAAC,aAAa,eAAe,KAAA,GAC7B,SACE,GAAG,KAAK,mFACH,KAAK,0EACd;CACA,cACE,CAAC,aAAa,gBAAgB,OAC9B,SACE,GAAG,KAAK,iIAEZ;AACF"}
@@ -0,0 +1,73 @@
1
+ //#region src/internal/overlay/overlay-show.ts
2
+ /** A fresh set of flags, all clear. Keep one per Popup instance (`useState(createPopupFlags)`). */
3
+ function createPopupFlags() {
4
+ let awaitingClose = false;
5
+ let libraryClose = false;
6
+ let refusedFact = false;
7
+ let attached = null;
8
+ let replaying = false;
9
+ return {
10
+ awaitingClose: () => awaitingClose,
11
+ beginClose: () => {
12
+ awaitingClose = true;
13
+ },
14
+ endClose: () => {
15
+ awaitingClose = false;
16
+ },
17
+ markLibraryClose: () => {
18
+ libraryClose = true;
19
+ },
20
+ takeLibraryClose: () => {
21
+ const echo = libraryClose;
22
+ libraryClose = false;
23
+ return echo;
24
+ },
25
+ markFact: () => {
26
+ refusedFact = true;
27
+ },
28
+ factAdopted: () => {
29
+ refusedFact = false;
30
+ },
31
+ takeRefusedFact: () => {
32
+ const refused = refusedFact;
33
+ refusedFact = false;
34
+ return refused;
35
+ },
36
+ attach: (element, replayLostFact) => {
37
+ if (element === attached) return;
38
+ const lost = attached;
39
+ attached = element;
40
+ if (lost !== null && awaitingClose && !libraryClose) {
41
+ if (replaying) return;
42
+ replaying = true;
43
+ setTimeout(() => {
44
+ replaying = false;
45
+ replayLostFact(lost);
46
+ }, 0);
47
+ return;
48
+ }
49
+ if (!replaying) awaitingClose = false;
50
+ libraryClose = false;
51
+ }
52
+ };
53
+ }
54
+ /**
55
+ * Runs a library show with the refused re-open's `inert` guard and the initial focus `autofocus`
56
+ * write, both undone right after the call (also when it throws).
57
+ */
58
+ function showWithFocus(element, { refused, autofocus, show }) {
59
+ const inerted = refused && !element.hasAttribute("inert");
60
+ if (inerted) element.setAttribute("inert", "");
61
+ const autofocused = autofocus !== null && !autofocus.hasAttribute("autofocus") ? autofocus : null;
62
+ autofocused?.setAttribute("autofocus", "");
63
+ try {
64
+ show();
65
+ } finally {
66
+ autofocused?.removeAttribute("autofocus");
67
+ if (inerted) element.removeAttribute("inert");
68
+ }
69
+ }
70
+ //#endregion
71
+ export { createPopupFlags, showWithFocus };
72
+
73
+ //# sourceMappingURL=overlay-show.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overlay-show.mjs","names":[],"sources":["../../../src/internal/overlay/overlay-show.ts"],"sourcesContent":["// Two pieces of the popup state machine that usePopoverPopup (Popover, Menu, Combobox) and\n// Dialog.Popup share: the close / echo / refused-fact flags, and the show wrapper (the refused\n// re-open's `inert` guard and the `autofocus` write around the show call). What differs stays\n// with the caller: whether a refused fact applies to the show (Dialog: non-modal dialogs only),\n// the initial focus target, the show call itself. No \"use client\" directive: no hook, no React\n// (conventions 7.1); a Popup keeps its flags with `useState(createPopupFlags)`.\n\n/**\n * The bookkeeping flags of one Popup between a platform event and the apply effect\n * (design/components/popover.md 2.5, dialog.md 2.3, conventions 3.9.2 and 3.9.4).\n */\nexport interface PopupFlags {\n /**\n * `awaitingClose`: set by the synchronous `beforetoggle` of a close, cleared by the close's\n * `toggle` / `close` event a task later. While set the popup is hidden but its event has not\n * arrived, so the apply effect must not show it again from a commit that lands in between.\n */\n readonly awaitingClose: () => boolean;\n readonly beginClose: () => void;\n readonly endClose: () => void;\n /**\n * The library echo (`libraryHide` / `libraryClose`): marked right before the apply effect's\n * own hide, consumed by the next `toggle` / `close` event. That hide is the library's; every\n * other is a fact. The echo is recognised by its source, not by what is intended: a dismissal\n * during a pending part close is a fact.\n */\n readonly markLibraryClose: () => void;\n /** Reads and clears the echo marker. */\n readonly takeLibraryClose: () => boolean;\n /**\n * `refusedFact`: marked when a fact hid the popup, cleared by a commit with committed `false`\n * (the fact was adopted). A show while it is set is the re-open of a dismissal a controlled\n * parent refused (conventions 3.9.4), which leaves focus where the dismissal put it.\n */\n readonly markFact: () => void;\n readonly factAdopted: () => void;\n /**\n * Reads and clears the refused-fact flag; call once per show, also when the caller does not\n * apply it (a modal dialog).\n */\n readonly takeRefusedFact: () => boolean;\n /**\n * The popup element the callback ref attached (#159). When it is a different element than the\n * last one during a close (a remount mid-close, such as a change of `transition`), the old\n * element went away with its listeners and its queued `toggle` / `close` event never reaches the\n * Popup:\n * - a library close (echo set): nothing to report; the wait and the echo end here;\n * - a fact: `replayLostFact(old element)` runs in a timer task (`setTimeout(0)`), not in the\n * lost event's own task: it can run later than that event would have, and an input task can\n * come first. It must do what the event's handler does (end the wait, report the fact). The\n * wait stays set until then, so no apply shows the new element first. At most one replay is\n * queued. The caller skips it once the Popup has unmounted, not when a Suspense hide only\n * detached the ref.\n *\n * Called at the ref's attach. Refs attach in the layout phase, children first, so this runs\n * before the Popup's own layout effects (the element is its descendant): the apply effect must\n * stay in an ancestor of the popup element to see it. The same element attached again (a new\n * merged ref, StrictMode) changes nothing: its event still comes.\n */\n readonly attach: (element: Element, replayLostFact: (lost: Element) => void) => void;\n}\n\n/** A fresh set of flags, all clear. Keep one per Popup instance (`useState(createPopupFlags)`). */\nexport function createPopupFlags(): PopupFlags {\n let awaitingClose = false;\n let libraryClose = false;\n let refusedFact = false;\n let attached: Element | null = null;\n // A lost fact's replay is queued: its wait stays set until it runs.\n let replaying = false;\n return {\n awaitingClose: () => awaitingClose,\n beginClose: () => {\n awaitingClose = true;\n },\n endClose: () => {\n awaitingClose = false;\n },\n markLibraryClose: () => {\n libraryClose = true;\n },\n takeLibraryClose: () => {\n const echo = libraryClose;\n libraryClose = false;\n return echo;\n },\n markFact: () => {\n refusedFact = true;\n },\n factAdopted: () => {\n refusedFact = false;\n },\n takeRefusedFact: () => {\n const refused = refusedFact;\n refusedFact = false;\n return refused;\n },\n attach: (element, replayLostFact) => {\n if (element === attached) return;\n const lost = attached;\n attached = element;\n if (lost !== null && awaitingClose && !libraryClose) {\n if (replaying) return;\n replaying = true;\n setTimeout(() => {\n replaying = false;\n replayLostFact(lost);\n }, 0);\n return;\n }\n if (!replaying) awaitingClose = false;\n libraryClose = false;\n },\n };\n}\n\nexport interface ShowWithFocusOptions {\n /**\n * The show is the re-open of a refused fact (#155, #156): the popup is `inert` for the duration\n * of `show`, so the platform's focusing steps find nothing focusable and do nothing (the dialog\n * focusing steps of a `<dialog>`, a consumer's own `autofocus`). The element the dismissal\n * focused sees no blur. A consumer's own `inert` is left alone.\n */\n readonly refused: boolean;\n /**\n * The element to carry `autofocus` during `show`, or `null`. The platform's focusing steps\n * honour the attribute; React drops `autoFocus` on client-rendered content (react/react#23301),\n * and the library never calls `.focus()` for initial focus (popover.md 6.1). An element that\n * already has the attribute keeps it.\n */\n readonly autofocus: HTMLElement | null;\n /** The show itself (`showPopover()`, `showModal()`, `show()`), called synchronously once. */\n readonly show: () => void;\n}\n\n/**\n * Runs a library show with the refused re-open's `inert` guard and the initial focus `autofocus`\n * write, both undone right after the call (also when it throws).\n */\nexport function showWithFocus(\n element: HTMLElement,\n { refused, autofocus, show }: ShowWithFocusOptions,\n): void {\n const inerted = refused && !element.hasAttribute(\"inert\");\n if (inerted) element.setAttribute(\"inert\", \"\");\n const autofocused = autofocus !== null && !autofocus.hasAttribute(\"autofocus\") ? autofocus : null;\n autofocused?.setAttribute(\"autofocus\", \"\");\n try {\n show();\n } finally {\n autofocused?.removeAttribute(\"autofocus\");\n if (inerted) element.removeAttribute(\"inert\");\n }\n}\n"],"mappings":";;AA+DA,SAAgB,mBAA+B;CAC7C,IAAI,gBAAgB;CACpB,IAAI,eAAe;CACnB,IAAI,cAAc;CAClB,IAAI,WAA2B;CAE/B,IAAI,YAAY;CAChB,OAAO;EACL,qBAAqB;EACrB,kBAAkB;GAChB,gBAAgB;EAClB;EACA,gBAAgB;GACd,gBAAgB;EAClB;EACA,wBAAwB;GACtB,eAAe;EACjB;EACA,wBAAwB;GACtB,MAAM,OAAO;GACb,eAAe;GACf,OAAO;EACT;EACA,gBAAgB;GACd,cAAc;EAChB;EACA,mBAAmB;GACjB,cAAc;EAChB;EACA,uBAAuB;GACrB,MAAM,UAAU;GAChB,cAAc;GACd,OAAO;EACT;EACA,SAAS,SAAS,mBAAmB;GACnC,IAAI,YAAY,UAAU;GAC1B,MAAM,OAAO;GACb,WAAW;GACX,IAAI,SAAS,QAAQ,iBAAiB,CAAC,cAAc;IACnD,IAAI,WAAW;IACf,YAAY;IACZ,iBAAiB;KACf,YAAY;KACZ,eAAe,IAAI;IACrB,GAAG,CAAC;IACJ;GACF;GACA,IAAI,CAAC,WAAW,gBAAgB;GAChC,eAAe;EACjB;CACF;AACF;;;;;AAyBA,SAAgB,cACd,SACA,EAAE,SAAS,WAAW,QAChB;CACN,MAAM,UAAU,WAAW,CAAC,QAAQ,aAAa,OAAO;CACxD,IAAI,SAAS,QAAQ,aAAa,SAAS,EAAE;CAC7C,MAAM,cAAc,cAAc,QAAQ,CAAC,UAAU,aAAa,WAAW,IAAI,YAAY;CAC7F,aAAa,aAAa,aAAa,EAAE;CACzC,IAAI;EACF,KAAK;CACP,UAAU;EACR,aAAa,gBAAgB,WAAW;EACxC,IAAI,SAAS,QAAQ,gBAAgB,OAAO;CAC9C;AACF"}
@@ -1,4 +1,4 @@
1
- //#region src/internal/popover-open.ts
1
+ //#region src/internal/overlay/popover-open.ts
2
2
  /**
3
3
  * Whether `element` is a showing popover (`:popover-open`). `false` for `null` and where the
4
4
  * selector is unsupported (it throws there, for example on a `render` element in an engine
@@ -0,0 +1 @@
1
+ {"version":3,"file":"popover-open.mjs","names":[],"sources":["../../../src/internal/overlay/popover-open.ts"],"sourcesContent":["// No directive: a pure DOM read (conventions 7.1).\n\n/**\n * Whether `element` is a showing popover (`:popover-open`). `false` for `null` and where the\n * selector is unsupported (it throws there, for example on a `render` element in an engine\n * without the Popover API).\n */\nexport function isPopoverOpen(element: Element | null): boolean {\n if (element === null) return false;\n try {\n return element.matches(\":popover-open\");\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,cAAc,SAAkC;CAC9D,IAAI,YAAY,MAAM,OAAO;CAC7B,IAAI;EACF,OAAO,QAAQ,QAAQ,eAAe;CACxC,QAAQ;EACN,OAAO;CACT;AACF"}
@@ -1,4 +1,4 @@
1
- //#region src/internal/trigger-ref.ts
1
+ //#region src/internal/overlay/trigger-ref.ts
2
2
  const isDev = process.env.NODE_ENV !== "production";
3
3
  /** The Roots that already warned about a second Trigger, keyed by their `triggerRef`. */
4
4
  const warned = /* @__PURE__ */ new WeakSet();
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trigger-ref.mjs","names":[],"sources":["../../../src/internal/overlay/trigger-ref.ts"],"sourcesContent":["import type { RefObject } from \"react\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The Roots that already warned about a second Trigger, keyed by their `triggerRef`. */\nconst warned = new WeakSet<RefObject<HTMLElement | null>>();\n\n/**\n * Registers `element` as the Root's one Trigger (`triggerRef`, last mounted wins) and returns\n * the ref cleanup. In development, a second Trigger mounting while another is registered\n * warns once per Root (popover.md 14.2): only the registered one is the popup's `source` (anchor,\n * focus return) and, in JS-free mode, the one whose `data-open` is kept current.\n */\nexport function registerTrigger(\n triggerRef: RefObject<HTMLElement | null>,\n element: HTMLElement,\n part: string,\n): () => void {\n // A Trigger's own cleanup clears the ref first (a remount, StrictMode, a ref change), so a\n // registered element here is another, still mounted Trigger.\n if (isDev && triggerRef.current !== null) {\n if (!warned.has(triggerRef)) {\n warned.add(triggerRef);\n console.error(\n `${part}: a second ${part} mounted in the same Root. A Root supports one ${part}: ` +\n \"the popup only follows the last one mounted (its anchor, focus return and, \" +\n `without an action, data-open). Render one ${part} per Root.`,\n );\n }\n }\n triggerRef.current = element;\n return () => {\n if (triggerRef.current === element) triggerRef.current = null;\n };\n}\n"],"mappings":";AAEA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAM,yBAAS,IAAI,QAAuC;;;;;;;AAQ1D,SAAgB,gBACd,YACA,SACA,MACY;CAGZ,IAAI,SAAS,WAAW,YAAY,MAC9B;MAAA,CAAC,OAAO,IAAI,UAAU,GAAG;GAC3B,OAAO,IAAI,UAAU;GACrB,QAAQ,MACN,GAAG,KAAK,aAAa,KAAK,iDAAiD,KAAK,yHAEjC,KAAK,WACtD;EACF;;CAEF,WAAW,UAAU;CACrB,aAAa;EACX,IAAI,WAAW,YAAY,SAAS,WAAW,UAAU;CAC3D;AACF"}
@@ -0,0 +1,44 @@
1
+ "use client";
2
+ import { useLayoutEffect } from "react";
3
+ //#region src/internal/overlay/use-apply-open-state.ts
4
+ /**
5
+ * The apply effect (design 2.5): a dependency-free layout effect that, after every commit that
6
+ * re-renders the Popup, once nothing is in flight, makes the DOM follow committed state. One
7
+ * effect covers the normal open, `defaultOpen`, a controlled open or close, a library-driven close
8
+ * after `openChangeAction(false)` settled, the re-open of a dismissal a controlled parent refused
9
+ * (in the fact's own commit, or once the requests it superseded settled: conventions 3.9.4), and
10
+ * the close after a refused or failed pre-hydration open. The Root's value is memoised, so an
11
+ * unrelated Root render does not re-render the Popup and does not run this; every path that makes
12
+ * the DOM diverge from state goes through a dispatch, whose `pending` flips do, or a fact, whose
13
+ * `epoch` does. Do not rely on an unrelated render to re-apply state.
14
+ *
15
+ * Also forgets content that unmounted while the popup stays open, and releases a `held` no exit
16
+ * animation is going to release (4.4).
17
+ *
18
+ * A layout effect without deps runs in call order among the component's layout effects: call it
19
+ * right after the Popup's mount reconciliation, whose dispatch makes this wait for it.
20
+ */
21
+ function useApplyOpenState(ctx, { flags, exit, probe, isShown, show, hide }) {
22
+ useLayoutEffect(() => {
23
+ if (ctx.mode !== "library") return;
24
+ const element = ctx.popupRef.current;
25
+ if (element === null || !element.isConnected) return;
26
+ if (!ctx.committed) flags.factAdopted();
27
+ if (!ctx.pending && ctx.latestInFlight() === null) {
28
+ const shown = isShown(element);
29
+ if (ctx.committed && !shown) {
30
+ if (!flags.awaitingClose()) show(element);
31
+ } else if (!ctx.committed && shown) {
32
+ ctx.recordCloseIntent(void 0);
33
+ flags.markLibraryClose();
34
+ hide(element);
35
+ }
36
+ }
37
+ if (ctx.committed && isShown(element)) probe.forget();
38
+ exit.releaseIfIdle(ctx.committed, flags.awaitingClose(), isShown(element));
39
+ });
40
+ }
41
+ //#endregion
42
+ export { useApplyOpenState };
43
+
44
+ //# sourceMappingURL=use-apply-open-state.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-apply-open-state.mjs","names":[],"sources":["../../../src/internal/overlay/use-apply-open-state.ts"],"sourcesContent":["\"use client\";\n// The apply effect (design/components/popover.md 2.5, dialog.md 2.5) that usePopoverPopup\n// (Popover, Menu, Combobox) and Dialog.Popup share: the same algorithm over a three-member\n// platform driver (`isShown`, `show`, `hide`). The platform listeners and mount reconciliation\n// stay in each Popup; they differ in order and content.\nimport { useLayoutEffect } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { ContentFocusProbeHook } from \"./content-focus-probe.js\";\nimport type { CloseHold } from \"./overlay-popup.js\";\nimport type { PopupFlags } from \"./overlay-show.js\";\nimport type { OverlayRootValue } from \"./use-overlay-root.js\";\n\n/** What the apply effect reads from the Root (both Popups' contexts have it). */\nexport type ApplyOpenStateContext<Popup extends HTMLElement> = Pick<\n OverlayRootValue<Popup, never[]>,\n \"mode\" | \"committed\" | \"pending\" | \"latestInFlight\" | \"recordCloseIntent\"\n> & { readonly popupRef: RefObject<Popup | null> };\n\nexport interface ApplyOpenStateOptions<Popup extends HTMLElement> {\n readonly flags: PopupFlags;\n readonly exit: Pick<CloseHold, \"releaseIfIdle\">;\n readonly probe: Pick<ContentFocusProbeHook, \"forget\">;\n /** Whether the popup is in the top layer (`:popover-open`, or the dialog's `open`). */\n readonly isShown: (element: Popup) => boolean;\n /** The library's own show: initial focus, the refused re-open, the platform call. */\n readonly show: (element: Popup) => void;\n /**\n * The library's own hide, after the echo was marked: the platform call (with its CSS\n * transition cut), then the focus-return fallback for a close commit that unmounted the\n * focused content (design 6.2 rule 2).\n */\n readonly hide: (element: Popup) => void;\n}\n\n/**\n * The apply effect (design 2.5): a dependency-free layout effect that, after every commit that\n * re-renders the Popup, once nothing is in flight, makes the DOM follow committed state. One\n * effect covers the normal open, `defaultOpen`, a controlled open or close, a library-driven close\n * after `openChangeAction(false)` settled, the re-open of a dismissal a controlled parent refused\n * (in the fact's own commit, or once the requests it superseded settled: conventions 3.9.4), and\n * the close after a refused or failed pre-hydration open. The Root's value is memoised, so an\n * unrelated Root render does not re-render the Popup and does not run this; every path that makes\n * the DOM diverge from state goes through a dispatch, whose `pending` flips do, or a fact, whose\n * `epoch` does. Do not rely on an unrelated render to re-apply state.\n *\n * Also forgets content that unmounted while the popup stays open, and releases a `held` no exit\n * animation is going to release (4.4).\n *\n * A layout effect without deps runs in call order among the component's layout effects: call it\n * right after the Popup's mount reconciliation, whose dispatch makes this wait for it.\n */\nexport function useApplyOpenState<Popup extends HTMLElement>(\n ctx: ApplyOpenStateContext<Popup>,\n { flags, exit, probe, isShown, show, hide }: ApplyOpenStateOptions<Popup>,\n): void {\n useLayoutEffect(() => {\n if (ctx.mode !== \"library\") return;\n const element = ctx.popupRef.current;\n if (element === null || !element.isConnected) return;\n // The fact was adopted (or anything else closed the popup in state): a later show is a new\n // open, with initial focus.\n if (!ctx.committed) flags.factAdopted();\n if (!ctx.pending && ctx.latestInFlight() === null) {\n const shown = isShown(element);\n if (ctx.committed && !shown) {\n // Hidden, but its `toggle` / `close` event has not arrived yet: wait for it.\n if (!flags.awaitingClose()) show(element);\n } else if (!ctx.committed && shown) {\n // The library's own hide: the `toggle` / `close` listener recognises it by the echo\n // marker and reports nothing.\n ctx.recordCloseIntent(undefined);\n flags.markLibraryClose();\n hide(element);\n }\n }\n // Content that unmounted while the popup stays open (not a close): forget it.\n if (ctx.committed && isShown(element)) probe.forget();\n // A hold the close commit set (or a fact's commit) that no exit animation is going to\n // release: the popup is hidden and its close event has been handled.\n exit.releaseIfIdle(ctx.committed, flags.awaitingClose(), isShown(element));\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmDA,SAAgB,kBACd,KACA,EAAE,OAAO,MAAM,OAAO,SAAS,MAAM,QAC/B;CACN,sBAAsB;EACpB,IAAI,IAAI,SAAS,WAAW;EAC5B,MAAM,UAAU,IAAI,SAAS;EAC7B,IAAI,YAAY,QAAQ,CAAC,QAAQ,aAAa;EAG9C,IAAI,CAAC,IAAI,WAAW,MAAM,YAAY;EACtC,IAAI,CAAC,IAAI,WAAW,IAAI,eAAe,MAAM,MAAM;GACjD,MAAM,QAAQ,QAAQ,OAAO;GAC7B,IAAI,IAAI,aAAa,CAAC,OAEhB;QAAA,CAAC,MAAM,cAAc,GAAG,KAAK,OAAO;GAAA,OACnC,IAAI,CAAC,IAAI,aAAa,OAAO;IAGlC,IAAI,kBAAkB,KAAA,CAAS;IAC/B,MAAM,iBAAiB;IACvB,KAAK,OAAO;GACd;EACF;EAEA,IAAI,IAAI,aAAa,QAAQ,OAAO,GAAG,MAAM,OAAO;EAGpD,KAAK,cAAc,IAAI,WAAW,MAAM,cAAc,GAAG,QAAQ,OAAO,CAAC;CAC3E,CAAC;AACH"}
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { useRef, useState } from "react";
3
- //#region src/internal/use-exit-animation.ts
3
+ //#region src/internal/overlay/use-exit-animation.ts
4
4
  /** An animation that ends: infinite ones (a spinner) would hold the content forever. */
5
5
  function ends(animation) {
6
6
  const end = animation.effect?.getComputedTiming().endTime;
@@ -31,7 +31,7 @@ function exitAnimations(element, baseline) {
31
31
  * The deferred unmount of a top-layer popup's content while its hide animates. `held` is cleared
32
32
  * with a normal (urgent) update, never in a transition: the popup is already hidden, nothing
33
33
  * visible changes, and only transition commits start a document view transition, so a dismissal
34
- * (a fact, an urgent commit) runs none (design 4.4, overlay-open-change.md 2.8).
34
+ * (a fact, an urgent commit) runs none (design 4.4, conventions 3.9.8).
35
35
  */
36
36
  function useExitAnimation() {
37
37
  const [held, setHeld] = useState(false);