fromsrc 0.0.2 → 0.0.21

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 (408) hide show
  1. package/dist/access.d.ts +7 -7
  2. package/dist/access.js +12 -5
  3. package/dist/adapter.js +8 -16
  4. package/dist/adapterbrowser.js +6 -10
  5. package/dist/adapternext.js +7 -18
  6. package/dist/adapterreactrouter.js +5 -9
  7. package/dist/adapterremix.js +8 -17
  8. package/dist/adaptertanstack.js +6 -10
  9. package/dist/algolia.js +43 -21
  10. package/dist/analytics.d.ts +1 -1
  11. package/dist/analytics.js +16 -10
  12. package/dist/ansi.js +76 -37
  13. package/dist/api.d.ts +10 -10
  14. package/dist/api.js +14 -11
  15. package/dist/audit.d.ts +6 -6
  16. package/dist/audit.js +29 -10
  17. package/dist/autotype.js +20 -10
  18. package/dist/batch.d.ts +6 -6
  19. package/dist/batch.js +16 -9
  20. package/dist/changelog.js +28 -14
  21. package/dist/changelogutil.d.ts +4 -4
  22. package/dist/changelogutil.js +33 -13
  23. package/dist/cli.d.ts +6 -6
  24. package/dist/cli.js +7 -3
  25. package/dist/client.d.ts +1 -1
  26. package/dist/codesample.d.ts +4 -4
  27. package/dist/codesample.js +63 -24
  28. package/dist/collapse.js +31 -13
  29. package/dist/collections.js +36 -16
  30. package/dist/components/accordion.d.ts +1 -1
  31. package/dist/components/accordion.js +5 -1
  32. package/dist/components/alert.d.ts +1 -1
  33. package/dist/components/alert.js +24 -13
  34. package/dist/components/announce.js +40 -17
  35. package/dist/components/autofill.js +17 -7
  36. package/dist/components/avatar.js +4 -4
  37. package/dist/components/avatarstack.js +2 -2
  38. package/dist/components/backtotop.d.ts +1 -1
  39. package/dist/components/backtotop.js +17 -4
  40. package/dist/components/badge.js +9 -4
  41. package/dist/components/banner.js +22 -5
  42. package/dist/components/breadcrumb.js +11 -4
  43. package/dist/components/breadcrumbnav.js +37 -21
  44. package/dist/components/button.js +23 -8
  45. package/dist/components/callout.d.ts +1 -1
  46. package/dist/components/callout.js +33 -29
  47. package/dist/components/changelog.js +21 -8
  48. package/dist/components/checkbox.js +32 -19
  49. package/dist/components/code.d.ts +1 -1
  50. package/dist/components/code.js +6 -3
  51. package/dist/components/codeblock.js +157 -39
  52. package/dist/components/codecopy.d.ts +1 -1
  53. package/dist/components/codecopy.js +36 -13
  54. package/dist/components/codegroup.js +87 -25
  55. package/dist/components/collapsible.d.ts +1 -1
  56. package/dist/components/collapsible.js +5 -1
  57. package/dist/components/command.d.ts +1 -1
  58. package/dist/components/command.js +42 -15
  59. package/dist/components/compare.js +20 -8
  60. package/dist/components/content.js +121 -79
  61. package/dist/components/copybutton.d.ts +1 -1
  62. package/dist/components/copybutton.js +14 -7
  63. package/dist/components/countdown.js +9 -3
  64. package/dist/components/create.js +34 -24
  65. package/dist/components/definition.js +11 -4
  66. package/dist/components/diffview.js +63 -29
  67. package/dist/components/divider.js +5 -1
  68. package/dist/components/docheader.js +8 -1
  69. package/dist/components/doclinkcard.js +27 -3
  70. package/dist/components/dropdown.d.ts +1 -1
  71. package/dist/components/dropdown.js +32 -11
  72. package/dist/components/dynamiccode.js +5 -3
  73. package/dist/components/editlink.js +35 -23
  74. package/dist/components/embed.js +15 -7
  75. package/dist/components/endpoint.d.ts +3 -3
  76. package/dist/components/endpoint.js +24 -9
  77. package/dist/components/errormessage.d.ts +1 -1
  78. package/dist/components/errormessage.js +4 -1
  79. package/dist/components/expandcode.d.ts +1 -1
  80. package/dist/components/expandcode.js +6 -2
  81. package/dist/components/feature.js +8 -1
  82. package/dist/components/featuregrid.d.ts +4 -4
  83. package/dist/components/featuregrid.js +7 -1
  84. package/dist/components/feedback.js +6 -2
  85. package/dist/components/feedbackwidget.js +10 -4
  86. package/dist/components/files.d.ts +1 -1
  87. package/dist/components/files.js +52 -18
  88. package/dist/components/folder.d.ts +1 -1
  89. package/dist/components/folder.js +21 -4
  90. package/dist/components/footer.js +5 -1
  91. package/dist/components/formlabel.d.ts +1 -1
  92. package/dist/components/formlabel.js +31 -18
  93. package/dist/components/github.js +43 -14
  94. package/dist/components/graph.js +38 -14
  95. package/dist/components/heading.js +36 -29
  96. package/dist/components/headingcopy.js +13 -5
  97. package/dist/components/hero.js +20 -14
  98. package/dist/components/highlight.d.ts +2 -2
  99. package/dist/components/highlight.js +14 -8
  100. package/dist/components/hover.d.ts +2 -2
  101. package/dist/components/hover.js +11 -4
  102. package/dist/components/icons.js +4 -1
  103. package/dist/components/inlinetoc.js +3 -1
  104. package/dist/components/input.js +13 -3
  105. package/dist/components/install.js +34 -24
  106. package/dist/components/kbd.js +19 -11
  107. package/dist/components/langicon.d.ts +1 -1
  108. package/dist/components/langicon.js +22 -17
  109. package/dist/components/language.d.ts +1 -1
  110. package/dist/components/language.js +12 -4
  111. package/dist/components/lastupdated.d.ts +2 -2
  112. package/dist/components/lastupdated.js +36 -12
  113. package/dist/components/link.d.ts +1 -1
  114. package/dist/components/linkcard.js +3 -1
  115. package/dist/components/list.d.ts +1 -1
  116. package/dist/components/list.js +4 -1
  117. package/dist/components/math.js +33 -8
  118. package/dist/components/mermaid.js +3 -3
  119. package/dist/components/mobilenav.d.ts +2 -1
  120. package/dist/components/mobilenav.js +116 -47
  121. package/dist/components/modal.d.ts +1 -1
  122. package/dist/components/modal.js +9 -2
  123. package/dist/components/navlink.js +17 -3
  124. package/dist/components/openapi.d.ts +1 -1
  125. package/dist/components/openapi.js +102 -32
  126. package/dist/components/openapischema.d.ts +1 -1
  127. package/dist/components/openapischema.js +29 -9
  128. package/dist/components/openapitags.js +6 -2
  129. package/dist/components/pagetransition.js +5 -3
  130. package/dist/components/pagination.js +3 -2
  131. package/dist/components/panel.js +91 -15
  132. package/dist/components/playground.d.ts +1 -1
  133. package/dist/components/playground.js +153 -50
  134. package/dist/components/popover.js +9 -7
  135. package/dist/components/prelink.js +40 -9
  136. package/dist/components/prevnext.d.ts +1 -1
  137. package/dist/components/prevnext.js +36 -16
  138. package/dist/components/progress.js +2 -2
  139. package/dist/components/property.js +3 -1
  140. package/dist/components/quote.d.ts +2 -2
  141. package/dist/components/quote.js +32 -4
  142. package/dist/components/radio.js +36 -18
  143. package/dist/components/rating.js +14 -3
  144. package/dist/components/recent.d.ts +1 -1
  145. package/dist/components/recent.js +26 -10
  146. package/dist/components/responsive.js +21 -13
  147. package/dist/components/results.js +8 -4
  148. package/dist/components/screenshot.js +61 -21
  149. package/dist/components/scrollprogress.js +9 -5
  150. package/dist/components/scrollspy.d.ts +2 -2
  151. package/dist/components/scrollspy.js +9 -3
  152. package/dist/components/search.js +47 -18
  153. package/dist/components/searchbutton.js +3 -1
  154. package/dist/components/searchdialog.js +35 -22
  155. package/dist/components/searcher.d.ts +1 -1
  156. package/dist/components/searcher.js +51 -26
  157. package/dist/components/select.js +27 -13
  158. package/dist/components/shortcuts.d.ts +1 -1
  159. package/dist/components/shortcuts.js +57 -38
  160. package/dist/components/sidebar.d.ts +2 -1
  161. package/dist/components/sidebar.js +221 -56
  162. package/dist/components/sidebarfilter.d.ts +1 -1
  163. package/dist/components/sidebarfilter.js +30 -6
  164. package/dist/components/sidebarscript.d.ts +5 -0
  165. package/dist/components/sidebarscript.js +18 -0
  166. package/dist/components/skeleton.js +15 -3
  167. package/dist/components/spinner.js +13 -3
  168. package/dist/components/status.js +20 -8
  169. package/dist/components/steps.js +3 -1
  170. package/dist/components/switch.js +4 -4
  171. package/dist/components/table.js +37 -12
  172. package/dist/components/tabnav.d.ts +1 -1
  173. package/dist/components/tabnav.js +48 -36
  174. package/dist/components/tabs.d.ts +1 -1
  175. package/dist/components/tabs.js +56 -40
  176. package/dist/components/tag.js +8 -3
  177. package/dist/components/terminal.js +14 -4
  178. package/dist/components/textarea.js +96 -82
  179. package/dist/components/theme.d.ts +1 -1
  180. package/dist/components/theme.js +25 -3
  181. package/dist/components/themeprovider.d.ts +4 -4
  182. package/dist/components/themeprovider.js +16 -5
  183. package/dist/components/toast.d.ts +1 -1
  184. package/dist/components/toast.js +23 -14
  185. package/dist/components/toc/default.d.ts +1 -1
  186. package/dist/components/toc/default.js +28 -13
  187. package/dist/components/toc/hook.js +28 -14
  188. package/dist/components/toc/index.js +8 -4
  189. package/dist/components/toc/inline.js +12 -2
  190. package/dist/components/toc/minimal.js +11 -5
  191. package/dist/components/toc/zigzag.d.ts +1 -1
  192. package/dist/components/toc/zigzag.js +37 -17
  193. package/dist/components/tocprogress.d.ts +1 -1
  194. package/dist/components/tocprogress.js +66 -34
  195. package/dist/components/tooltip.d.ts +1 -1
  196. package/dist/components/tooltip.js +20 -8
  197. package/dist/components/trigger.js +13 -5
  198. package/dist/components/twoslash.js +49 -26
  199. package/dist/components/typetable.js +23 -4
  200. package/dist/components/typewriter.js +6 -2
  201. package/dist/components/version.js +40 -14
  202. package/dist/components/video.js +25 -15
  203. package/dist/components/zoom.js +6 -2
  204. package/dist/config.d.ts +2 -2
  205. package/dist/config.js +56 -30
  206. package/dist/content.d.ts +5 -5
  207. package/dist/content.js +121 -57
  208. package/dist/contentcache.d.ts +10 -10
  209. package/dist/contentcache.js +9 -5
  210. package/dist/contentdiff.d.ts +4 -4
  211. package/dist/contentdiff.js +16 -8
  212. package/dist/contributors.d.ts +4 -4
  213. package/dist/contributors.js +49 -19
  214. package/dist/diff.d.ts +6 -6
  215. package/dist/diff.js +37 -16
  216. package/dist/draft.d.ts +11 -11
  217. package/dist/draft.js +9 -5
  218. package/dist/env.js +21 -7
  219. package/dist/export.js +4 -4
  220. package/dist/frontmatter.js +11 -9
  221. package/dist/github.js +60 -30
  222. package/dist/gitsource.d.ts +1 -1
  223. package/dist/gitsource.js +16 -9
  224. package/dist/hash.d.ts +6 -6
  225. package/dist/hash.js +19 -7
  226. package/dist/highlight.d.ts +4 -4
  227. package/dist/highlight.js +34 -14
  228. package/dist/hooks/anchor.js +26 -14
  229. package/dist/hooks/arrownav.js +25 -7
  230. package/dist/hooks/async.js +3 -3
  231. package/dist/hooks/battery.js +11 -3
  232. package/dist/hooks/breakpoint.js +10 -2
  233. package/dist/hooks/clickoutside.js +10 -3
  234. package/dist/hooks/clipboard-paste.js +7 -3
  235. package/dist/hooks/clipboard.d.ts +2 -2
  236. package/dist/hooks/clipboard.js +21 -15
  237. package/dist/hooks/copy.js +11 -6
  238. package/dist/hooks/countdown.js +1 -1
  239. package/dist/hooks/counter.js +1 -1
  240. package/dist/hooks/escapekey.js +6 -1
  241. package/dist/hooks/eventlistener.js +3 -1
  242. package/dist/hooks/eventsource.js +4 -2
  243. package/dist/hooks/eyedropper.js +7 -3
  244. package/dist/hooks/favicon.js +1 -1
  245. package/dist/hooks/fetch.js +12 -4
  246. package/dist/hooks/focustrap.js +20 -8
  247. package/dist/hooks/focuswithin.js +6 -2
  248. package/dist/hooks/form.d.ts +2 -2
  249. package/dist/hooks/form.js +15 -2
  250. package/dist/hooks/fullscreen.js +1 -1
  251. package/dist/hooks/geolocation.js +8 -8
  252. package/dist/hooks/hotkeys.js +19 -7
  253. package/dist/hooks/hover.d.ts +4 -1
  254. package/dist/hooks/hover.js +3 -1
  255. package/dist/hooks/idle.js +13 -3
  256. package/dist/hooks/infinitescroll.js +4 -2
  257. package/dist/hooks/interval.js +3 -1
  258. package/dist/hooks/inview.js +7 -3
  259. package/dist/hooks/keyboard.js +36 -12
  260. package/dist/hooks/keypress.js +6 -2
  261. package/dist/hooks/list.js +11 -1
  262. package/dist/hooks/longpress.js +3 -3
  263. package/dist/hooks/map.js +1 -1
  264. package/dist/hooks/measure.js +16 -7
  265. package/dist/hooks/mediarecorder.js +7 -3
  266. package/dist/hooks/networkstate.js +4 -2
  267. package/dist/hooks/os.js +12 -4
  268. package/dist/hooks/pagination.js +6 -4
  269. package/dist/hooks/permission.js +6 -2
  270. package/dist/hooks/queue.js +4 -2
  271. package/dist/hooks/readprogress.js +6 -2
  272. package/dist/hooks/resizeobserver.js +6 -4
  273. package/dist/hooks/script.js +1 -1
  274. package/dist/hooks/scrolllock.js +6 -2
  275. package/dist/hooks/scrollspy.js +4 -2
  276. package/dist/hooks/selection.js +6 -3
  277. package/dist/hooks/share.js +18 -9
  278. package/dist/hooks/speechrecognition.js +7 -3
  279. package/dist/hooks/stepper.js +4 -4
  280. package/dist/hooks/storage.js +9 -3
  281. package/dist/hooks/stylesheet.js +4 -2
  282. package/dist/hooks/textselection.js +6 -3
  283. package/dist/hooks/throttle.js +6 -2
  284. package/dist/hooks/undoredo.js +19 -11
  285. package/dist/hooks/vibrate.js +3 -1
  286. package/dist/hooks/viewtransition.js +8 -4
  287. package/dist/hooks/wakelock.js +12 -7
  288. package/dist/hooks/websocket.js +4 -2
  289. package/dist/hooks/windowsize.js +2 -2
  290. package/dist/i18n.d.ts +2 -2
  291. package/dist/i18n.js +27 -14
  292. package/dist/index.d.ts +1 -0
  293. package/dist/index.js +1 -0
  294. package/dist/lastmodified.js +11 -5
  295. package/dist/linkcheck.d.ts +6 -6
  296. package/dist/linkcheck.js +55 -14
  297. package/dist/llms.js +20 -4
  298. package/dist/manifest.js +7 -7
  299. package/dist/mcp.js +28 -22
  300. package/dist/mdtoc.d.ts +4 -4
  301. package/dist/mdtoc.js +11 -5
  302. package/dist/mdxscope.d.ts +2 -2
  303. package/dist/mdxscope.js +3 -1
  304. package/dist/meta.js +19 -7
  305. package/dist/migrate.js +35 -25
  306. package/dist/navgen.d.ts +8 -8
  307. package/dist/navgen.js +73 -30
  308. package/dist/navtree.d.ts +1 -1
  309. package/dist/navtree.js +39 -19
  310. package/dist/oembed.d.ts +4 -4
  311. package/dist/oembed.js +24 -18
  312. package/dist/ogimage.d.ts +11 -11
  313. package/dist/ogimage.js +24 -24
  314. package/dist/openapi.js +60 -33
  315. package/dist/openapiguard.js +21 -11
  316. package/dist/openapiutil.js +66 -20
  317. package/dist/orama.js +52 -34
  318. package/dist/pipeline.d.ts +4 -4
  319. package/dist/pipeline.js +4 -4
  320. package/dist/preload.d.ts +2 -2
  321. package/dist/preload.js +4 -4
  322. package/dist/ranking.d.ts +6 -6
  323. package/dist/ranking.js +39 -13
  324. package/dist/readtime.js +3 -1
  325. package/dist/redirects.d.ts +2 -2
  326. package/dist/redirects.js +20 -12
  327. package/dist/rehype.js +16 -9
  328. package/dist/rehypeautolink.d.ts +2 -2
  329. package/dist/rehypeautolink.js +25 -23
  330. package/dist/rehypecode.js +38 -28
  331. package/dist/rehypecopy.js +17 -13
  332. package/dist/rehypeinline.js +33 -27
  333. package/dist/rehypelinks.js +28 -20
  334. package/dist/rehyperaw.js +9 -3
  335. package/dist/rehypeslug.d.ts +1 -1
  336. package/dist/rehypeslug.js +23 -19
  337. package/dist/rehypetablewrap.d.ts +2 -2
  338. package/dist/rehypetablewrap.js +9 -5
  339. package/dist/rehypetoc.d.ts +1 -1
  340. package/dist/rehypetoc.js +15 -7
  341. package/dist/remark.js +28 -13
  342. package/dist/remarkadmonition.js +40 -14
  343. package/dist/remarkannotation.d.ts +2 -2
  344. package/dist/remarkannotation.js +26 -10
  345. package/dist/remarkbadge.js +43 -31
  346. package/dist/remarkblockmath.js +29 -15
  347. package/dist/remarkcallout.js +32 -14
  348. package/dist/remarkcaption.js +28 -16
  349. package/dist/remarkcodetitle.js +29 -13
  350. package/dist/remarkcolumns.js +22 -10
  351. package/dist/remarkdetails.js +34 -14
  352. package/dist/remarkdirective.js +47 -20
  353. package/dist/remarkembed.js +38 -22
  354. package/dist/remarkfiletree.js +29 -19
  355. package/dist/remarkfootnote.js +46 -18
  356. package/dist/remarkgfm.js +13 -8
  357. package/dist/remarkheadingid.js +16 -6
  358. package/dist/remarkimage.js +54 -34
  359. package/dist/remarkinclude.js +20 -8
  360. package/dist/remarkinstall.js +20 -12
  361. package/dist/remarklinkcard.js +33 -14
  362. package/dist/remarkmath.js +34 -15
  363. package/dist/remarkmermaid.js +10 -6
  364. package/dist/remarkmeta.d.ts +2 -2
  365. package/dist/remarkmeta.js +15 -5
  366. package/dist/remarkreadingtime.d.ts +2 -2
  367. package/dist/remarkreadingtime.js +3 -1
  368. package/dist/remarksteps.js +26 -14
  369. package/dist/remarkstructure.js +16 -10
  370. package/dist/remarktabs.js +31 -14
  371. package/dist/remarktoc.js +40 -24
  372. package/dist/remarkts2js.js +51 -40
  373. package/dist/remarktwoslash.d.ts +4 -4
  374. package/dist/remarktwoslash.js +24 -14
  375. package/dist/remarkvideo.d.ts +4 -4
  376. package/dist/remarkvideo.js +42 -16
  377. package/dist/schema.d.ts +14 -14
  378. package/dist/schema.js +2 -2
  379. package/dist/search.js +106 -48
  380. package/dist/searchindex.js +86 -34
  381. package/dist/searchpolicy.js +1 -1
  382. package/dist/searchscore.js +5 -5
  383. package/dist/searchtypo.js +30 -10
  384. package/dist/seo.d.ts +2 -2
  385. package/dist/seo.js +14 -14
  386. package/dist/shortcodes.d.ts +4 -4
  387. package/dist/shortcodes.js +25 -20
  388. package/dist/sitemap.js +18 -8
  389. package/dist/snippets.js +26 -18
  390. package/dist/source.js +75 -41
  391. package/dist/stats.d.ts +4 -4
  392. package/dist/stats.js +18 -12
  393. package/dist/testing.d.ts +7 -7
  394. package/dist/testing.js +74 -29
  395. package/dist/themeutil.d.ts +6 -6
  396. package/dist/themeutil.js +145 -27
  397. package/dist/typegen.js +31 -12
  398. package/dist/validate.js +19 -7
  399. package/dist/validator.d.ts +11 -11
  400. package/dist/validator.js +68 -19
  401. package/dist/versioning.d.ts +7 -7
  402. package/dist/versioning.js +27 -11
  403. package/dist/watcher.js +39 -15
  404. package/dist/webhook.d.ts +6 -6
  405. package/dist/webhook.js +34 -12
  406. package/dist/workspace.js +26 -12
  407. package/package.json +137 -137
  408. package/styles/reset.css +1 -1
@@ -1,9 +1,9 @@
1
- type ClipboardResult = {
1
+ interface ClipboardResult {
2
2
  copy: (text: string) => Promise<void>;
3
3
  paste: () => Promise<string>;
4
4
  copied: boolean;
5
5
  supported: boolean;
6
- };
6
+ }
7
7
  declare function useClipboard(timeout?: number): ClipboardResult;
8
8
 
9
9
  export { type ClipboardResult, useClipboard };
@@ -4,21 +4,27 @@ function useClipboard(timeout = 2e3) {
4
4
  const [copied, setCopied] = useState(false);
5
5
  const timer = useRef(null);
6
6
  const supported = typeof navigator !== "undefined" && !!navigator.clipboard;
7
- const copy = useCallback(async (text) => {
8
- await navigator.clipboard.writeText(text);
9
- setCopied(true);
10
- if (timer.current) clearTimeout(timer.current);
11
- timer.current = setTimeout(() => setCopied(false), timeout);
12
- }, [timeout]);
13
- const paste = useCallback(async () => {
14
- return navigator.clipboard.readText();
15
- }, []);
16
- useEffect(() => {
17
- return () => {
18
- if (timer.current) clearTimeout(timer.current);
19
- };
20
- }, []);
21
- return { copy, paste, copied, supported };
7
+ const copy = useCallback(
8
+ async (text) => {
9
+ await navigator.clipboard.writeText(text);
10
+ setCopied(true);
11
+ if (timer.current) {
12
+ clearTimeout(timer.current);
13
+ }
14
+ timer.current = setTimeout(() => setCopied(false), timeout);
15
+ },
16
+ [timeout]
17
+ );
18
+ const paste = useCallback(() => navigator.clipboard.readText(), []);
19
+ useEffect(
20
+ () => () => {
21
+ if (timer.current) {
22
+ clearTimeout(timer.current);
23
+ }
24
+ },
25
+ []
26
+ );
27
+ return { copied, copy, paste, supported };
22
28
  }
23
29
 
24
30
  export { useClipboard };
@@ -4,17 +4,22 @@ import { useState, useRef, useEffect, useCallback } from 'react';
4
4
  function useCopy(duration = 1500) {
5
5
  const [copied, setCopied] = useState(false);
6
6
  const timeoutRef = useRef(null);
7
- useEffect(() => {
8
- return () => {
9
- if (timeoutRef.current) clearTimeout(timeoutRef.current);
10
- };
11
- }, []);
7
+ useEffect(
8
+ () => () => {
9
+ if (timeoutRef.current) {
10
+ clearTimeout(timeoutRef.current);
11
+ }
12
+ },
13
+ []
14
+ );
12
15
  const copy = useCallback(
13
16
  async (text) => {
14
17
  try {
15
18
  await navigator.clipboard.writeText(text);
16
19
  setCopied(true);
17
- if (timeoutRef.current) clearTimeout(timeoutRef.current);
20
+ if (timeoutRef.current) {
21
+ clearTimeout(timeoutRef.current);
22
+ }
18
23
  timeoutRef.current = setTimeout(() => setCopied(false), duration);
19
24
  } catch {
20
25
  setCopied(false);
@@ -35,7 +35,7 @@ function useCountdown(seconds) {
35
35
  setRemaining(seconds);
36
36
  }, [clear, seconds]);
37
37
  useEffect(() => clear, [clear]);
38
- return { remaining, running, start, pause, reset };
38
+ return { pause, remaining, reset, running, start };
39
39
  }
40
40
 
41
41
  export { useCountdown };
@@ -6,7 +6,7 @@ function useCounter(initial = 0) {
6
6
  const increment = useCallback(() => setCount((c) => c + 1), []);
7
7
  const decrement = useCallback(() => setCount((c) => c - 1), []);
8
8
  const reset = useCallback(() => setCount(initial), [initial]);
9
- return { count, increment, decrement, reset, set: setCount };
9
+ return { count, decrement, increment, reset, set: setCount };
10
10
  }
11
11
 
12
12
  export { useCounter };
@@ -12,7 +12,12 @@ function useEscapeKey(handler, enabled = true) {
12
12
  },
13
13
  [handler]
14
14
  );
15
- useEventListener(typeof document !== "undefined" ? document : null, "keydown", handleKey, enabled);
15
+ useEventListener(
16
+ typeof document !== "undefined" ? document : null,
17
+ "keydown",
18
+ handleKey,
19
+ enabled
20
+ );
16
21
  }
17
22
 
18
23
  export { useEscapeKey };
@@ -3,7 +3,9 @@ import { useEffect } from 'react';
3
3
 
4
4
  function useEventListener(target, event, handler, enabled = true, options) {
5
5
  useEffect(() => {
6
- if (!enabled || !target) return;
6
+ if (!enabled || !target) {
7
+ return;
8
+ }
7
9
  const listener = handler;
8
10
  target.addEventListener(event, listener, options);
9
11
  return () => {
@@ -11,7 +11,9 @@ function useEventSource(url) {
11
11
  setStatus("closed");
12
12
  }, []);
13
13
  useEffect(() => {
14
- if (!url) return;
14
+ if (!url) {
15
+ return;
16
+ }
15
17
  setStatus("connecting");
16
18
  const source = new EventSource(url);
17
19
  sourceRef.current = source;
@@ -25,7 +27,7 @@ function useEventSource(url) {
25
27
  source.close();
26
28
  };
27
29
  }, [url]);
28
- return { status, lastEvent, lastData, close };
30
+ return { close, lastData, lastEvent, status };
29
31
  }
30
32
 
31
33
  export { useEventSource };
@@ -5,10 +5,14 @@ function useEyeDropper() {
5
5
  const [color, setColor] = useState(null);
6
6
  const supported = typeof window !== "undefined" && "EyeDropper" in window;
7
7
  const pick = useCallback(async () => {
8
- if (!supported) return null;
8
+ if (!supported) {
9
+ return null;
10
+ }
9
11
  try {
10
12
  const Dropper = window.EyeDropper;
11
- if (!Dropper) return null;
13
+ if (!Dropper) {
14
+ return null;
15
+ }
12
16
  const dropper = new Dropper();
13
17
  const result = await dropper.open();
14
18
  setColor(result.sRGBHex);
@@ -17,7 +21,7 @@ function useEyeDropper() {
17
21
  return null;
18
22
  }
19
23
  }, [supported]);
20
- return { color, supported, pick };
24
+ return { color, pick, supported };
21
25
  }
22
26
 
23
27
  export { useEyeDropper };
@@ -7,7 +7,7 @@ function useFavicon(href) {
7
7
  link.type = "image/x-icon";
8
8
  link.rel = "shortcut icon";
9
9
  link.href = href;
10
- document.head.appendChild(link);
10
+ document.head.append(link);
11
11
  }, [href]);
12
12
  }
13
13
 
@@ -8,16 +8,24 @@ function useFetch(url, options) {
8
8
  loading: !!url
9
9
  });
10
10
  useEffect(() => {
11
- if (!url) return;
11
+ if (!url) {
12
+ return;
13
+ }
12
14
  let cancelled = false;
13
15
  setState({ data: null, error: null, loading: true });
14
16
  fetch(url, options).then((res) => {
15
- if (!res.ok) throw new Error(res.statusText);
17
+ if (!res.ok) {
18
+ throw new Error(res.statusText);
19
+ }
16
20
  return res.json();
17
21
  }).then((data) => {
18
- if (!cancelled) setState({ data, error: null, loading: false });
22
+ if (!cancelled) {
23
+ setState({ data, error: null, loading: false });
24
+ }
19
25
  }).catch((error) => {
20
- if (!cancelled) setState({ data: null, error, loading: false });
26
+ if (!cancelled) {
27
+ setState({ data: null, error, loading: false });
28
+ }
21
29
  });
22
30
  return () => {
23
31
  cancelled = true;
@@ -6,8 +6,10 @@ function useFocusTrap(ref, options) {
6
6
  const { enabled, onEscape, autoFocus = true, restoreFocus = true } = options;
7
7
  const previousFocus = useRef(null);
8
8
  const getFocusableElements = useCallback(() => {
9
- if (!ref.current) return [];
10
- return Array.from(ref.current.querySelectorAll(FOCUSABLE_SELECTOR));
9
+ if (!ref.current) {
10
+ return [];
11
+ }
12
+ return [...ref.current.querySelectorAll(FOCUSABLE_SELECTOR)];
11
13
  }, [ref]);
12
14
  const handleKeyDown = useCallback(
13
15
  (e) => {
@@ -15,11 +17,15 @@ function useFocusTrap(ref, options) {
15
17
  onEscape();
16
18
  return;
17
19
  }
18
- if (e.key !== "Tab") return;
20
+ if (e.key !== "Tab") {
21
+ return;
22
+ }
19
23
  const focusable = getFocusableElements();
20
- if (focusable.length === 0) return;
24
+ if (focusable.length === 0) {
25
+ return;
26
+ }
21
27
  const first = focusable[0];
22
- const last = focusable[focusable.length - 1];
28
+ const last = focusable.at(-1);
23
29
  if (e.shiftKey && document.activeElement === first) {
24
30
  e.preventDefault();
25
31
  last?.focus();
@@ -31,7 +37,9 @@ function useFocusTrap(ref, options) {
31
37
  [onEscape, getFocusableElements]
32
38
  );
33
39
  useEffect(() => {
34
- if (!enabled) return;
40
+ if (!enabled) {
41
+ return;
42
+ }
35
43
  previousFocus.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
36
44
  document.addEventListener("keydown", handleKeyDown);
37
45
  return () => {
@@ -42,12 +50,16 @@ function useFocusTrap(ref, options) {
42
50
  };
43
51
  }, [enabled, handleKeyDown, restoreFocus]);
44
52
  useEffect(() => {
45
- if (!enabled || !autoFocus) return;
53
+ if (!enabled || !autoFocus) {
54
+ return;
55
+ }
46
56
  const focusable = getFocusableElements();
47
57
  focusable[0]?.focus();
48
58
  }, [enabled, autoFocus, getFocusableElements]);
49
59
  useEffect(() => {
50
- if (!enabled) return;
60
+ if (!enabled) {
61
+ return;
62
+ }
51
63
  const handleFocusIn = (e) => {
52
64
  if (!(e.target instanceof Node) || !ref.current?.contains(e.target)) {
53
65
  const focusable = getFocusableElements();
@@ -6,10 +6,14 @@ function useFocusWithin() {
6
6
  const [focused, setFocused] = useState(false);
7
7
  useEffect(() => {
8
8
  const el = ref.current;
9
- if (!el) return;
9
+ if (!el) {
10
+ return;
11
+ }
10
12
  const onFocusIn = () => setFocused(true);
11
13
  const onFocusOut = (e) => {
12
- if (!(e.relatedTarget instanceof Node) || !el.contains(e.relatedTarget)) setFocused(false);
14
+ if (!(e.relatedTarget instanceof Node) || !el.contains(e.relatedTarget)) {
15
+ setFocused(false);
16
+ }
13
17
  };
14
18
  el.addEventListener("focusin", onFocusIn);
15
19
  el.addEventListener("focusout", onFocusOut);
@@ -1,8 +1,8 @@
1
- type changeevent = {
1
+ interface changeevent {
2
2
  target: {
3
3
  value: unknown;
4
4
  };
5
- };
5
+ }
6
6
  interface FormState<T extends Record<string, unknown>> {
7
7
  values: T;
8
8
  errors: Partial<Record<keyof T, string>>;
@@ -14,7 +14,9 @@ function useForm(initial, validate) {
14
14
  (field, value) => {
15
15
  setValues((prev) => {
16
16
  const next = update(prev, field, value);
17
- if (validate) setErrors(validate(next));
17
+ if (validate) {
18
+ setErrors(validate(next));
19
+ }
18
20
  return next;
19
21
  });
20
22
  },
@@ -36,7 +38,18 @@ function useForm(initial, validate) {
36
38
  (field) => () => setTouched((prev) => ({ ...prev, [field]: true })),
37
39
  []
38
40
  );
39
- return { values, errors, touched, dirty, valid, set, setError, reset, handleChange, handleBlur };
41
+ return {
42
+ dirty,
43
+ errors,
44
+ handleBlur,
45
+ handleChange,
46
+ reset,
47
+ set,
48
+ setError,
49
+ touched,
50
+ valid,
51
+ values
52
+ };
40
53
  }
41
54
 
42
55
  export { useForm };
@@ -28,7 +28,7 @@ function useFullscreen() {
28
28
  await ref.current.requestFullscreen();
29
29
  }
30
30
  }, []);
31
- return { isFullscreen, enter, exit, toggle, ref };
31
+ return { enter, exit, isFullscreen, ref, toggle };
32
32
  }
33
33
 
34
34
  export { useFullscreen };
@@ -3,27 +3,27 @@ import { useState, useCallback, useEffect } from 'react';
3
3
 
4
4
  function useGeolocation(watch = false) {
5
5
  const [pos, setPos] = useState({
6
- latitude: null,
7
- longitude: null,
8
6
  accuracy: null,
7
+ error: null,
8
+ latitude: null,
9
9
  loading: true,
10
- error: null
10
+ longitude: null
11
11
  });
12
12
  const onSuccess = useCallback((p) => {
13
13
  setPos({
14
- latitude: p.coords.latitude,
15
- longitude: p.coords.longitude,
16
14
  accuracy: p.coords.accuracy,
15
+ error: null,
16
+ latitude: p.coords.latitude,
17
17
  loading: false,
18
- error: null
18
+ longitude: p.coords.longitude
19
19
  });
20
20
  }, []);
21
21
  const onError = useCallback((e) => {
22
- setPos((prev) => ({ ...prev, loading: false, error: e.message }));
22
+ setPos((prev) => ({ ...prev, error: e.message, loading: false }));
23
23
  }, []);
24
24
  useEffect(() => {
25
25
  if (typeof navigator === "undefined" || !navigator.geolocation) {
26
- setPos((prev) => ({ ...prev, loading: false, error: "unsupported" }));
26
+ setPos((prev) => ({ ...prev, error: "unsupported", loading: false }));
27
27
  return;
28
28
  }
29
29
  navigator.geolocation.getCurrentPosition(onSuccess, onError);
@@ -2,11 +2,21 @@
2
2
  import { useRef, useEffect } from 'react';
3
3
 
4
4
  function matches(e, binding) {
5
- if (e.key.toLowerCase() !== binding.key.toLowerCase()) return false;
6
- if (binding.ctrl && !e.ctrlKey) return false;
7
- if (binding.meta && !e.metaKey) return false;
8
- if (binding.shift && !e.shiftKey) return false;
9
- if (binding.alt && !e.altKey) return false;
5
+ if (e.key.toLowerCase() !== binding.key.toLowerCase()) {
6
+ return false;
7
+ }
8
+ if (binding.ctrl && !e.ctrlKey) {
9
+ return false;
10
+ }
11
+ if (binding.meta && !e.metaKey) {
12
+ return false;
13
+ }
14
+ if (binding.shift && !e.shiftKey) {
15
+ return false;
16
+ }
17
+ if (binding.alt && !e.altKey) {
18
+ return false;
19
+ }
10
20
  return true;
11
21
  }
12
22
  function useHotkeys(bindings) {
@@ -14,8 +24,10 @@ function useHotkeys(bindings) {
14
24
  ref.current = bindings;
15
25
  useEffect(() => {
16
26
  function handle(e) {
17
- if (!(e.target instanceof HTMLElement)) return;
18
- const target = e.target;
27
+ if (!(e.target instanceof HTMLElement)) {
28
+ return;
29
+ }
30
+ const { target } = e;
19
31
  if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) {
20
32
  return;
21
33
  }
@@ -1,3 +1,6 @@
1
- declare function useHover<T extends HTMLElement>(): [React.RefObject<T | null>, boolean];
1
+ declare function useHover<T extends HTMLElement>(): [
2
+ React.RefObject<T | null>,
3
+ boolean
4
+ ];
2
5
 
3
6
  export { useHover };
@@ -6,7 +6,9 @@ function useHover() {
6
6
  const [hovered, setHovered] = useState(false);
7
7
  useEffect(() => {
8
8
  const el = ref.current;
9
- if (!el) return;
9
+ if (!el) {
10
+ return;
11
+ }
10
12
  const enter = () => setHovered(true);
11
13
  const leave = () => setHovered(false);
12
14
  el.addEventListener("mouseenter", enter);
@@ -7,10 +7,18 @@ function useIdle(timeout = 6e4) {
7
7
  useEffect(() => {
8
8
  function reset() {
9
9
  setIdle(false);
10
- if (timer.current) clearTimeout(timer.current);
10
+ if (timer.current) {
11
+ clearTimeout(timer.current);
12
+ }
11
13
  timer.current = setTimeout(() => setIdle(true), timeout);
12
14
  }
13
- const events = ["mousemove", "keydown", "scroll", "touchstart", "click"];
15
+ const events = [
16
+ "mousemove",
17
+ "keydown",
18
+ "scroll",
19
+ "touchstart",
20
+ "click"
21
+ ];
14
22
  for (const event of events) {
15
23
  window.addEventListener(event, reset, { passive: true });
16
24
  }
@@ -19,7 +27,9 @@ function useIdle(timeout = 6e4) {
19
27
  for (const event of events) {
20
28
  window.removeEventListener(event, reset);
21
29
  }
22
- if (timer.current) clearTimeout(timer.current);
30
+ if (timer.current) {
31
+ clearTimeout(timer.current);
32
+ }
23
33
  };
24
34
  }, [timeout]);
25
35
  return idle;
@@ -7,7 +7,9 @@ function useInfiniteScroll(onLoadMore, threshold = 200) {
7
7
  const [done, setDone] = useState(false);
8
8
  const loadingRef = useRef(false);
9
9
  const handleScroll = useCallback(() => {
10
- if (loadingRef.current || done) return;
10
+ if (loadingRef.current || done) {
11
+ return;
12
+ }
11
13
  const el = ref.current;
12
14
  const target = el || document.documentElement;
13
15
  const scrollBottom = target.scrollHeight - target.scrollTop - target.clientHeight;
@@ -25,7 +27,7 @@ function useInfiniteScroll(onLoadMore, threshold = 200) {
25
27
  el.addEventListener("scroll", handleScroll, { passive: true });
26
28
  return () => el.removeEventListener("scroll", handleScroll);
27
29
  }, [handleScroll]);
28
- return { ref, loading, done, setDone };
30
+ return { done, loading, ref, setDone };
29
31
  }
30
32
 
31
33
  export { useInfiniteScroll };
@@ -7,7 +7,9 @@ function useInterval(callback, delay) {
7
7
  savedCallback.current = callback;
8
8
  }, [callback]);
9
9
  useEffect(() => {
10
- if (delay === null) return;
10
+ if (delay === null) {
11
+ return;
12
+ }
11
13
  const id = setInterval(() => savedCallback.current(), delay);
12
14
  return () => clearInterval(id);
13
15
  }, [delay]);
@@ -7,17 +7,21 @@ function useInView(options = {}) {
7
7
  const [inView, setInView] = useState(false);
8
8
  useEffect(() => {
9
9
  const element = ref.current;
10
- if (!element) return;
10
+ if (!element) {
11
+ return;
12
+ }
11
13
  const observer = new IntersectionObserver(
12
14
  ([entry]) => {
13
- if (!entry) return;
15
+ if (!entry) {
16
+ return;
17
+ }
14
18
  const visible = entry.isIntersecting;
15
19
  setInView(visible);
16
20
  if (visible && once) {
17
21
  observer.disconnect();
18
22
  }
19
23
  },
20
- { threshold, rootMargin }
24
+ { rootMargin, threshold }
21
25
  );
22
26
  observer.observe(element);
23
27
  return () => observer.disconnect();
@@ -31,20 +31,30 @@ function useKeyboardNav(docs, basePath = "/docs") {
31
31
  const router = useRouter();
32
32
  useEffect(() => {
33
33
  const sorted = sortDocs(docs);
34
- const paths = sorted.map((d) => d.slug ? `${basePath}/${d.slug}` : basePath);
34
+ const paths = sorted.map(
35
+ (d) => d.slug ? `${basePath}/${d.slug}` : basePath
36
+ );
35
37
  const current = paths.indexOf(pathname);
36
38
  const handleKeyDown = (e) => {
37
- if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) return;
38
- if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return;
39
+ if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
40
+ return;
41
+ }
42
+ if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) {
43
+ return;
44
+ }
39
45
  if (e.key === "ArrowRight" && current < paths.length - 1) {
40
46
  e.preventDefault();
41
47
  const next = paths[current + 1];
42
- if (next) router.push(next);
48
+ if (next) {
49
+ router.push(next);
50
+ }
43
51
  }
44
52
  if (e.key === "ArrowLeft" && current > 0) {
45
53
  e.preventDefault();
46
54
  const prev = paths[current - 1];
47
- if (prev) router.push(prev);
55
+ if (prev) {
56
+ router.push(prev);
57
+ }
48
58
  }
49
59
  };
50
60
  window.addEventListener("keydown", handleKeyDown);
@@ -52,8 +62,12 @@ function useKeyboardNav(docs, basePath = "/docs") {
52
62
  }, [docs, pathname, router, basePath]);
53
63
  }
54
64
  function editable(target) {
55
- if (!(target instanceof HTMLElement)) return false;
56
- if (target.tagName === "INPUT" || target.tagName === "TEXTAREA") return true;
65
+ if (!(target instanceof HTMLElement)) {
66
+ return false;
67
+ }
68
+ if (target.tagName === "INPUT" || target.tagName === "TEXTAREA") {
69
+ return true;
70
+ }
57
71
  return target.isContentEditable;
58
72
  }
59
73
  function useKeyboardShortcut(key, callback, options = {}) {
@@ -63,12 +77,22 @@ function useKeyboardShortcut(key, callback, options = {}) {
63
77
  optionsRef.current = options;
64
78
  useEffect(() => {
65
79
  function handler(e) {
66
- if (editable(e.target)) return;
80
+ if (editable(e.target)) {
81
+ return;
82
+ }
67
83
  const opts = optionsRef.current;
68
- if (opts.ctrl && !e.ctrlKey) return;
69
- if (opts.meta && !e.metaKey) return;
70
- if (opts.shift && !e.shiftKey) return;
71
- if (e.key.toLowerCase() !== key.toLowerCase()) return;
84
+ if (opts.ctrl && !e.ctrlKey) {
85
+ return;
86
+ }
87
+ if (opts.meta && !e.metaKey) {
88
+ return;
89
+ }
90
+ if (opts.shift && !e.shiftKey) {
91
+ return;
92
+ }
93
+ if (e.key.toLowerCase() !== key.toLowerCase()) {
94
+ return;
95
+ }
72
96
  if (opts.preventDefault !== false) {
73
97
  e.preventDefault();
74
98
  }
@@ -5,10 +5,14 @@ function useKeyPress(targetKey) {
5
5
  const [pressed, setPressed] = useState(false);
6
6
  useEffect(() => {
7
7
  function down(e) {
8
- if (e.key === targetKey) setPressed(true);
8
+ if (e.key === targetKey) {
9
+ setPressed(true);
10
+ }
9
11
  }
10
12
  function up(e) {
11
- if (e.key === targetKey) setPressed(false);
13
+ if (e.key === targetKey) {
14
+ setPressed(false);
15
+ }
12
16
  }
13
17
  window.addEventListener("keydown", down);
14
18
  window.addEventListener("keyup", up);
@@ -22,7 +22,17 @@ function useList(initial = []) {
22
22
  const sort = useCallback((fn) => {
23
23
  setItems((prev) => [...prev].sort(fn));
24
24
  }, []);
25
- return { items, set: setItems, push, removeAt, updateAt, insertAt, clear, filter, sort };
25
+ return {
26
+ clear,
27
+ filter,
28
+ insertAt,
29
+ items,
30
+ push,
31
+ removeAt,
32
+ set: setItems,
33
+ sort,
34
+ updateAt
35
+ };
26
36
  }
27
37
 
28
38
  export { useList };