ref0-git 0.0.0-stage → 0.2.0

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 (385) hide show
  1. package/app/apps/github/.dev.vars.example +6 -0
  2. package/app/apps/github/README.md +70 -0
  3. package/app/apps/github/THIRD_PARTY_NOTICES.md +214 -0
  4. package/app/apps/github/components.json +25 -0
  5. package/app/apps/github/generated/git-rest.ts +10444 -0
  6. package/app/apps/github/generated/routeTree.gen.ts +1242 -0
  7. package/app/apps/github/migrations/postgres/0001_auth.sql +46 -0
  8. package/app/apps/github/migrations/sql/0001_auth.sql +19 -0
  9. package/app/apps/github/migrations/sql/0002_passkeys.sql +9 -0
  10. package/app/apps/github/migrations/sql/0003_orgs.sql +22 -0
  11. package/app/apps/github/migrations/sql/0004_avatars.sql +6 -0
  12. package/app/apps/github/package.json +80 -0
  13. package/app/apps/github/src/branches/branch-list.tsx +385 -0
  14. package/app/apps/github/src/branches/branches.ts +55 -0
  15. package/app/apps/github/src/clients/allowed.ts +213 -0
  16. package/app/apps/github/src/clients/at-most.ts +17 -0
  17. package/app/apps/github/src/clients/avatars.ts +410 -0
  18. package/app/apps/github/src/clients/cached.ts +65 -0
  19. package/app/apps/github/src/clients/calls.ts +160 -0
  20. package/app/apps/github/src/clients/clients.ts +82 -0
  21. package/app/apps/github/src/clients/graphql.ts +50 -0
  22. package/app/apps/github/src/clients/host-answer.ts +28 -0
  23. package/app/apps/github/src/clients/host-calls.ts +382 -0
  24. package/app/apps/github/src/clients/icon-bytes.ts +203 -0
  25. package/app/apps/github/src/clients/proxy.ts +59 -0
  26. package/app/apps/github/src/clients/session-ended.ts +18 -0
  27. package/app/apps/github/src/clients/transfers.ts +212 -0
  28. package/app/apps/github/src/code/breadcrumbs.tsx +50 -0
  29. package/app/apps/github/src/code/code-page.tsx +147 -0
  30. package/app/apps/github/src/code/code-tree.tsx +338 -0
  31. package/app/apps/github/src/code/controls.tsx +230 -0
  32. package/app/apps/github/src/code/file-view.tsx +450 -0
  33. package/app/apps/github/src/code/files.ts +332 -0
  34. package/app/apps/github/src/code/folder-list.tsx +122 -0
  35. package/app/apps/github/src/code/go-to-file.tsx +131 -0
  36. package/app/apps/github/src/code/highlighted.tsx +58 -0
  37. package/app/apps/github/src/code/lines.ts +46 -0
  38. package/app/apps/github/src/code/load.ts +147 -0
  39. package/app/apps/github/src/code/markdown-files.ts +58 -0
  40. package/app/apps/github/src/code/places.ts +88 -0
  41. package/app/apps/github/src/code/ref-pages.ts +179 -0
  42. package/app/apps/github/src/code/ref-switcher.tsx +203 -0
  43. package/app/apps/github/src/code/refs.ts +142 -0
  44. package/app/apps/github/src/code/repo-home.tsx +240 -0
  45. package/app/apps/github/src/code/repo.ts +105 -0
  46. package/app/apps/github/src/code/saved-reads.ts +199 -0
  47. package/app/apps/github/src/code/saved.ts +110 -0
  48. package/app/apps/github/src/code/tree-fold.ts +186 -0
  49. package/app/apps/github/src/code/trees.ts +136 -0
  50. package/app/apps/github/src/components/avatar-picture.ts +53 -0
  51. package/app/apps/github/src/components/avatar-url.ts +16 -0
  52. package/app/apps/github/src/components/confirm-action.tsx +100 -0
  53. package/app/apps/github/src/components/count.tsx +24 -0
  54. package/app/apps/github/src/components/create-button.tsx +38 -0
  55. package/app/apps/github/src/components/file-icons/file-icons.css +225 -0
  56. package/app/apps/github/src/components/file-icons/file-icons.tsx +138 -0
  57. package/app/apps/github/src/components/filter.tsx +35 -0
  58. package/app/apps/github/src/components/hotkeys/hotkeys.tsx +255 -0
  59. package/app/apps/github/src/components/item-list.tsx +65 -0
  60. package/app/apps/github/src/components/language-dot.tsx +29 -0
  61. package/app/apps/github/src/components/list-toolbar.tsx +82 -0
  62. package/app/apps/github/src/components/markdown/editor.tsx +57 -0
  63. package/app/apps/github/src/components/markdown/markdown.css +177 -0
  64. package/app/apps/github/src/components/markdown/markdown.tsx +82 -0
  65. package/app/apps/github/src/components/owner-card.tsx +196 -0
  66. package/app/apps/github/src/components/pull-status.tsx +34 -0
  67. package/app/apps/github/src/components/recent.ts +41 -0
  68. package/app/apps/github/src/components/relative-time.tsx +78 -0
  69. package/app/apps/github/src/components/repos/icon-hashes.ts +91 -0
  70. package/app/apps/github/src/components/repos/new-repo-form.tsx +196 -0
  71. package/app/apps/github/src/components/repos/repo-icon.tsx +47 -0
  72. package/app/apps/github/src/components/repos/repo-list.tsx +528 -0
  73. package/app/apps/github/src/components/repos/your-repos.tsx +124 -0
  74. package/app/apps/github/src/components/review-state.tsx +75 -0
  75. package/app/apps/github/src/components/route-dialog.tsx +137 -0
  76. package/app/apps/github/src/components/save-button.tsx +58 -0
  77. package/app/apps/github/src/components/shell/app-shell.tsx +164 -0
  78. package/app/apps/github/src/components/shell/create-org-dialog.tsx +118 -0
  79. package/app/apps/github/src/components/shell/create-row.tsx +49 -0
  80. package/app/apps/github/src/components/shell/link-menu.tsx +94 -0
  81. package/app/apps/github/src/components/shell/nav-user.tsx +97 -0
  82. package/app/apps/github/src/components/shell/owner-repos.tsx +247 -0
  83. package/app/apps/github/src/components/shell/owner-switcher.tsx +104 -0
  84. package/app/apps/github/src/components/shell/repo-switcher.tsx +179 -0
  85. package/app/apps/github/src/components/shell/sections.ts +31 -0
  86. package/app/apps/github/src/components/shell/submenu-chevron.ts +147 -0
  87. package/app/apps/github/src/components/signin/device-card.tsx +139 -0
  88. package/app/apps/github/src/components/signin/login-form.tsx +88 -0
  89. package/app/apps/github/src/components/signin/signin-page.tsx +33 -0
  90. package/app/apps/github/src/components/signin/signup-form.tsx +106 -0
  91. package/app/apps/github/src/components/states/live-status.tsx +42 -0
  92. package/app/apps/github/src/components/states/states.tsx +126 -0
  93. package/app/apps/github/src/components/tab-indicator.tsx +143 -0
  94. package/app/apps/github/src/components/theme-choice.tsx +108 -0
  95. package/app/apps/github/src/components/theme-provider.tsx +126 -0
  96. package/app/apps/github/src/components/tones.ts +23 -0
  97. package/app/apps/github/src/components/ui/alert-dialog.tsx +187 -0
  98. package/app/apps/github/src/components/ui/alert.tsx +78 -0
  99. package/app/apps/github/src/components/ui/avatar.tsx +106 -0
  100. package/app/apps/github/src/components/ui/badge.tsx +51 -0
  101. package/app/apps/github/src/components/ui/breadcrumb.tsx +124 -0
  102. package/app/apps/github/src/components/ui/button-group.tsx +87 -0
  103. package/app/apps/github/src/components/ui/button.tsx +61 -0
  104. package/app/apps/github/src/components/ui/calendar.tsx +221 -0
  105. package/app/apps/github/src/components/ui/card.tsx +102 -0
  106. package/app/apps/github/src/components/ui/checkbox.tsx +26 -0
  107. package/app/apps/github/src/components/ui/collapsible.tsx +19 -0
  108. package/app/apps/github/src/components/ui/combobox.tsx +304 -0
  109. package/app/apps/github/src/components/ui/command.tsx +208 -0
  110. package/app/apps/github/src/components/ui/dialog.tsx +156 -0
  111. package/app/apps/github/src/components/ui/dropdown-menu.tsx +290 -0
  112. package/app/apps/github/src/components/ui/empty.tsx +100 -0
  113. package/app/apps/github/src/components/ui/field.tsx +236 -0
  114. package/app/apps/github/src/components/ui/hover-card.tsx +48 -0
  115. package/app/apps/github/src/components/ui/input-group.tsx +163 -0
  116. package/app/apps/github/src/components/ui/input.tsx +19 -0
  117. package/app/apps/github/src/components/ui/item.tsx +201 -0
  118. package/app/apps/github/src/components/ui/kbd.tsx +27 -0
  119. package/app/apps/github/src/components/ui/label.tsx +33 -0
  120. package/app/apps/github/src/components/ui/popover.tsx +87 -0
  121. package/app/apps/github/src/components/ui/radio-group.tsx +35 -0
  122. package/app/apps/github/src/components/ui/select.tsx +198 -0
  123. package/app/apps/github/src/components/ui/separator.tsx +22 -0
  124. package/app/apps/github/src/components/ui/sheet.tsx +138 -0
  125. package/app/apps/github/src/components/ui/sidebar.tsx +724 -0
  126. package/app/apps/github/src/components/ui/skeleton.tsx +13 -0
  127. package/app/apps/github/src/components/ui/sonner.tsx +47 -0
  128. package/app/apps/github/src/components/ui/styles.css +242 -0
  129. package/app/apps/github/src/components/ui/table.tsx +113 -0
  130. package/app/apps/github/src/components/ui/tabs.tsx +79 -0
  131. package/app/apps/github/src/components/ui/textarea.tsx +17 -0
  132. package/app/apps/github/src/components/ui/title.ts +6 -0
  133. package/app/apps/github/src/components/ui/toggle-group.tsx +89 -0
  134. package/app/apps/github/src/components/ui/toggle.tsx +42 -0
  135. package/app/apps/github/src/components/ui/tooltip.tsx +63 -0
  136. package/app/apps/github/src/components/user-avatar.tsx +145 -0
  137. package/app/apps/github/src/components/view-tabs.tsx +42 -0
  138. package/app/apps/github/src/context/context.ts +133 -0
  139. package/app/apps/github/src/diffs/blobs.ts +94 -0
  140. package/app/apps/github/src/diffs/diff-view.tsx +155 -0
  141. package/app/apps/github/src/diffs/files.ts +121 -0
  142. package/app/apps/github/src/diffs/hunks.tsx +454 -0
  143. package/app/apps/github/src/diffs/patch.ts +131 -0
  144. package/app/apps/github/src/diffs/rows.ts +137 -0
  145. package/app/apps/github/src/history/commit-diff.ts +54 -0
  146. package/app/apps/github/src/history/commit-list.tsx +207 -0
  147. package/app/apps/github/src/history/commit-page.tsx +147 -0
  148. package/app/apps/github/src/history/history.ts +129 -0
  149. package/app/apps/github/src/hooks/allowed.ts +31 -0
  150. package/app/apps/github/src/hooks/answers.ts +65 -0
  151. package/app/apps/github/src/hooks/avatars.ts +54 -0
  152. package/app/apps/github/src/hooks/draft.ts +38 -0
  153. package/app/apps/github/src/hooks/open-counts.ts +127 -0
  154. package/app/apps/github/src/hooks/profiles.ts +120 -0
  155. package/app/apps/github/src/hooks/repos.ts +440 -0
  156. package/app/apps/github/src/hooks/use-mobile.ts +19 -0
  157. package/app/apps/github/src/hooks/viewer.ts +39 -0
  158. package/app/apps/github/src/inbox/count.ts +70 -0
  159. package/app/apps/github/src/inbox/inbox-item.tsx +66 -0
  160. package/app/apps/github/src/inbox/inbox-page.tsx +572 -0
  161. package/app/apps/github/src/inbox/marks.ts +130 -0
  162. package/app/apps/github/src/inbox/release-tags.ts +65 -0
  163. package/app/apps/github/src/inbox/search.ts +97 -0
  164. package/app/apps/github/src/inbox/subjects.ts +184 -0
  165. package/app/apps/github/src/inbox/subscription-controls.tsx +184 -0
  166. package/app/apps/github/src/inbox/subscriptions.ts +189 -0
  167. package/app/apps/github/src/inbox/threads.ts +198 -0
  168. package/app/apps/github/src/issues/changes.ts +332 -0
  169. package/app/apps/github/src/issues/counts.ts +62 -0
  170. package/app/apps/github/src/issues/issue-list.tsx +682 -0
  171. package/app/apps/github/src/issues/issue-page.tsx +533 -0
  172. package/app/apps/github/src/issues/issues.ts +566 -0
  173. package/app/apps/github/src/issues/label-dialog.tsx +310 -0
  174. package/app/apps/github/src/issues/labels-page.tsx +119 -0
  175. package/app/apps/github/src/issues/new-issue.tsx +79 -0
  176. package/app/apps/github/src/issues/parts.tsx +71 -0
  177. package/app/apps/github/src/issues/picker.tsx +298 -0
  178. package/app/apps/github/src/issues/search.ts +238 -0
  179. package/app/apps/github/src/issues/sidebar.tsx +236 -0
  180. package/app/apps/github/src/lib/cn.ts +8 -0
  181. package/app/apps/github/src/lib/highlighting.ts +13 -0
  182. package/app/apps/github/src/live/follow.ts +129 -0
  183. package/app/apps/github/src/live/sse.ts +74 -0
  184. package/app/apps/github/src/live/use-follow.ts +37 -0
  185. package/app/apps/github/src/markdown/README.md +53 -0
  186. package/app/apps/github/src/markdown/allowed-html.ts +69 -0
  187. package/app/apps/github/src/markdown/context.ts +206 -0
  188. package/app/apps/github/src/markdown/images.ts +81 -0
  189. package/app/apps/github/src/markdown/lookup.ts +122 -0
  190. package/app/apps/github/src/markdown/patches.ts +299 -0
  191. package/app/apps/github/src/markdown/query.ts +25 -0
  192. package/app/apps/github/src/markdown/references.ts +158 -0
  193. package/app/apps/github/src/markdown/render.ts +103 -0
  194. package/app/apps/github/src/names/owners.ts +51 -0
  195. package/app/apps/github/src/names/repos.ts +24 -0
  196. package/app/apps/github/src/palette/palette.tsx +547 -0
  197. package/app/apps/github/src/palette/recent.ts +116 -0
  198. package/app/apps/github/src/palette/rows.tsx +455 -0
  199. package/app/apps/github/src/palette/server.ts +104 -0
  200. package/app/apps/github/src/palette/targets.ts +306 -0
  201. package/app/apps/github/src/policy.ts +600 -0
  202. package/app/apps/github/src/private-repos.ts +47 -0
  203. package/app/apps/github/src/pulls/compare-page.tsx +342 -0
  204. package/app/apps/github/src/pulls/files-tab.tsx +776 -0
  205. package/app/apps/github/src/pulls/live.ts +124 -0
  206. package/app/apps/github/src/pulls/merge-box.tsx +367 -0
  207. package/app/apps/github/src/pulls/merge-button.ts +86 -0
  208. package/app/apps/github/src/pulls/pull-list.tsx +235 -0
  209. package/app/apps/github/src/pulls/pull-page.tsx +474 -0
  210. package/app/apps/github/src/pulls/pull.ts +468 -0
  211. package/app/apps/github/src/pulls/pulls.ts +318 -0
  212. package/app/apps/github/src/pulls/review.ts +350 -0
  213. package/app/apps/github/src/pulls/search.ts +130 -0
  214. package/app/apps/github/src/queue/queue-page.tsx +405 -0
  215. package/app/apps/github/src/queue/queue.ts +231 -0
  216. package/app/apps/github/src/releases/latest-release.tsx +55 -0
  217. package/app/apps/github/src/releases/overview.tsx +30 -0
  218. package/app/apps/github/src/releases/release-form.tsx +353 -0
  219. package/app/apps/github/src/releases/release-list.tsx +173 -0
  220. package/app/apps/github/src/releases/release-view.tsx +183 -0
  221. package/app/apps/github/src/releases/releases.ts +308 -0
  222. package/app/apps/github/src/releases/tag-list.tsx +134 -0
  223. package/app/apps/github/src/router.tsx +46 -0
  224. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +33 -0
  225. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +28 -0
  226. package/app/apps/github/src/routes/$owner/$repo/_code.tsx +11 -0
  227. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +19 -0
  228. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +19 -0
  229. package/app/apps/github/src/routes/$owner/$repo/_releases.tsx +23 -0
  230. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +39 -0
  231. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +34 -0
  232. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +42 -0
  233. package/app/apps/github/src/routes/$owner/$repo/compare/$.tsx +19 -0
  234. package/app/apps/github/src/routes/$owner/$repo/index.tsx +24 -0
  235. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +50 -0
  236. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +53 -0
  237. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +43 -0
  238. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +22 -0
  239. package/app/apps/github/src/routes/$owner/$repo/pull/$number/checks.tsx +15 -0
  240. package/app/apps/github/src/routes/$owner/$repo/pull/$number/commits.tsx +15 -0
  241. package/app/apps/github/src/routes/$owner/$repo/pull/$number/files.tsx +15 -0
  242. package/app/apps/github/src/routes/$owner/$repo/pull/$number/index.tsx +19 -0
  243. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +52 -0
  244. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +48 -0
  245. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +22 -0
  246. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +58 -0
  247. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +40 -0
  248. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +35 -0
  249. package/app/apps/github/src/routes/$owner/$repo/route.tsx +102 -0
  250. package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +9 -0
  251. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +16 -0
  252. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/new.tsx +25 -0
  253. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +17 -0
  254. package/app/apps/github/src/routes/$owner/$repo/settings/route.tsx +28 -0
  255. package/app/apps/github/src/routes/$owner/$repo/settings/rules.tsx +12 -0
  256. package/app/apps/github/src/routes/$owner/$repo/tokens.tsx +16 -0
  257. package/app/apps/github/src/routes/$owner/index.tsx +45 -0
  258. package/app/apps/github/src/routes/-nav.tsx +293 -0
  259. package/app/apps/github/src/routes/-root-testing.ts +107 -0
  260. package/app/apps/github/src/routes/__root.tsx +225 -0
  261. package/app/apps/github/src/routes/api.auth.$.ts +18 -0
  262. package/app/apps/github/src/routes/downloads/$owner/$repo/$asset.tsx +10 -0
  263. package/app/apps/github/src/routes/file-icons[.]svg.ts +21 -0
  264. package/app/apps/github/src/routes/icons/$owner/$repo.tsx +14 -0
  265. package/app/apps/github/src/routes/icons/$owner/index.tsx +14 -0
  266. package/app/apps/github/src/routes/icons/index.tsx +12 -0
  267. package/app/apps/github/src/routes/index.tsx +48 -0
  268. package/app/apps/github/src/routes/login.tsx +24 -0
  269. package/app/apps/github/src/routes/login_.code.tsx +31 -0
  270. package/app/apps/github/src/routes/new.tsx +91 -0
  271. package/app/apps/github/src/routes/notifications.tsx +20 -0
  272. package/app/apps/github/src/routes/orgs/$owner/issues.tsx +8 -0
  273. package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +8 -0
  274. package/app/apps/github/src/routes/orgs/$owner/releases.tsx +8 -0
  275. package/app/apps/github/src/routes/orgs/$owner/route.tsx +25 -0
  276. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +30 -0
  277. package/app/apps/github/src/routes/orgs/$owner/tokens.tsx +15 -0
  278. package/app/apps/github/src/routes/settings.tsx +54 -0
  279. package/app/apps/github/src/routes/signup.tsx +24 -0
  280. package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +10 -0
  281. package/app/apps/github/src/seed/acme.ts +498 -0
  282. package/app/apps/github/src/seed/licenses.ts +114 -0
  283. package/app/apps/github/src/seed/seed.ts +538 -0
  284. package/app/apps/github/src/server.ts +97 -0
  285. package/app/apps/github/src/settings/account-avatar.tsx +43 -0
  286. package/app/apps/github/src/settings/avatar-section.tsx +140 -0
  287. package/app/apps/github/src/settings/avatar.ts +58 -0
  288. package/app/apps/github/src/settings/general-settings.tsx +439 -0
  289. package/app/apps/github/src/settings/general.ts +73 -0
  290. package/app/apps/github/src/settings/hook-form.tsx +195 -0
  291. package/app/apps/github/src/settings/hook-list.tsx +166 -0
  292. package/app/apps/github/src/settings/hooks.ts +87 -0
  293. package/app/apps/github/src/settings/org-settings.tsx +228 -0
  294. package/app/apps/github/src/settings/orgs.ts +116 -0
  295. package/app/apps/github/src/settings/rule-list.tsx +72 -0
  296. package/app/apps/github/src/settings/rules.ts +27 -0
  297. package/app/apps/github/src/settings/settings-layout.tsx +114 -0
  298. package/app/apps/github/src/signin/approval.ts +186 -0
  299. package/app/apps/github/src/signin/auth-client.ts +127 -0
  300. package/app/apps/github/src/signin/auth.ts +753 -0
  301. package/app/apps/github/src/signin/avatars.ts +126 -0
  302. package/app/apps/github/src/signin/client-ip.ts +39 -0
  303. package/app/apps/github/src/signin/credentials.ts +26 -0
  304. package/app/apps/github/src/signin/device-code.ts +95 -0
  305. package/app/apps/github/src/signin/device-prompt.ts +125 -0
  306. package/app/apps/github/src/signin/errors.ts +135 -0
  307. package/app/apps/github/src/signin/host-session.ts +68 -0
  308. package/app/apps/github/src/signin/orgs.ts +283 -0
  309. package/app/apps/github/src/signin/owner-names.ts +183 -0
  310. package/app/apps/github/src/signin/person-lock.ts +104 -0
  311. package/app/apps/github/src/signin/seal.ts +88 -0
  312. package/app/apps/github/src/signin/seed-people.ts +92 -0
  313. package/app/apps/github/src/signin/session.ts +48 -0
  314. package/app/apps/github/src/signin/unborn.ts +110 -0
  315. package/app/apps/github/src/signin/viewer-orgs.ts +47 -0
  316. package/app/apps/github/src/signin/viewer.ts +74 -0
  317. package/app/apps/github/src/signin/with-headers.ts +14 -0
  318. package/app/apps/github/src/tokens/tokens-page.tsx +529 -0
  319. package/app/apps/github/src/tokens/tokens.ts +54 -0
  320. package/app/apps/github/tsconfig.json +25 -0
  321. package/app/apps/github/tsconfig.worker.json +24 -0
  322. package/app/apps/github/vite.config.ts +21 -0
  323. package/app/pnpm-workspace.yaml +216 -0
  324. package/app/tsconfig.base.json +127 -0
  325. package/dist/LICENSE +202 -0
  326. package/dist/cli/child.mjs +42 -0
  327. package/dist/cli/commands.mjs +23 -0
  328. package/dist/cli/credentials.mjs +84 -0
  329. package/dist/cli/documents.mjs +214 -0
  330. package/dist/cli/events.mjs +55 -0
  331. package/dist/cli/failure.mjs +105 -0
  332. package/dist/cli/folders.mjs +32 -0
  333. package/dist/cli/git-remote-ref0.d.mts +1 -0
  334. package/dist/cli/git-remote-ref0.mjs +29 -0
  335. package/dist/cli/git.mjs +48 -0
  336. package/dist/cli/helpers.mjs +51 -0
  337. package/dist/cli/hosts.mjs +127 -0
  338. package/dist/cli/node.mjs +15 -0
  339. package/dist/cli/output.mjs +135 -0
  340. package/dist/cli/prompt.mjs +35 -0
  341. package/dist/cli/queue.mjs +215 -0
  342. package/dist/cli/ref0-git.d.mts +1 -0
  343. package/dist/cli/ref0-git.mjs +144 -0
  344. package/dist/cli/repos.mjs +162 -0
  345. package/dist/cli/resources.mjs +131 -0
  346. package/dist/cli/run-end.mjs +57 -0
  347. package/dist/cli/runtime.mjs +50 -0
  348. package/dist/cli/setup.mjs +1410 -0
  349. package/dist/cli/sign-in.mjs +162 -0
  350. package/dist/cli/sign-ins.mjs +79 -0
  351. package/dist/cli/sqlite.mjs +28 -0
  352. package/dist/cli/tokens.mjs +141 -0
  353. package/dist/cli/vendor.mjs +123 -0
  354. package/dist/init/app.mjs +231 -0
  355. package/dist/init/astro.mjs +49 -0
  356. package/dist/init/choices.mjs +497 -0
  357. package/dist/init/cloudflare.mjs +324 -0
  358. package/dist/init/create.mjs +151 -0
  359. package/dist/init/detect.mjs +297 -0
  360. package/dist/init/files.mjs +75 -0
  361. package/dist/init/frameworks.mjs +248 -0
  362. package/dist/init/git-module.mjs +49 -0
  363. package/dist/init/github-routes.mjs +66 -0
  364. package/dist/init/jsonc.mjs +143 -0
  365. package/dist/init/metadata.mjs +48 -0
  366. package/dist/init/mounts.mjs +109 -0
  367. package/dist/init/next.mjs +205 -0
  368. package/dist/init/node-app.mjs +189 -0
  369. package/dist/init/node.mjs +458 -0
  370. package/dist/init/nuxt.mjs +115 -0
  371. package/dist/init/output.mjs +21 -0
  372. package/dist/init/plan.mjs +82 -0
  373. package/dist/init/range-major.mjs +257 -0
  374. package/dist/init/react-router.mjs +59 -0
  375. package/dist/init/routes.mjs +148 -0
  376. package/dist/init/shell.mjs +4 -0
  377. package/dist/init/stores.mjs +51 -0
  378. package/dist/init/sveltekit.mjs +139 -0
  379. package/dist/init/template.mjs +142 -0
  380. package/dist/init/templates.mjs +343 -0
  381. package/dist/init/vercel.mjs +383 -0
  382. package/dist/init/versions.mjs +32 -0
  383. package/dist/init/workspace.mjs +20 -0
  384. package/package.json +52 -3
  385. package/README.md +0 -3
@@ -0,0 +1,338 @@
1
+ import { preloadFileTree, type FileTreeIconConfig, type FileTreeOptions } from '@pierre/trees';
2
+ import { FileTree, useFileTree } from '@pierre/trees/react';
3
+ import { useQueries } from '@tanstack/react-query';
4
+ import { useNavigate } from '@tanstack/react-router';
5
+ import { CircleAlertIcon } from 'lucide-react';
6
+ import { useEffect, useRef, useState } from 'react';
7
+
8
+ import { fileIcons, glyphSprite, glyphSymbols } from '../components/file-icons/file-icons.tsx';
9
+ import { Alert, AlertAction, AlertDescription } from '../components/ui/alert.tsx';
10
+ import { Button } from '../components/ui/button.tsx';
11
+ import { ancestry, blobHref, treeHref, type At } from './places.ts';
12
+ import { foldOnPress } from './tree-fold.ts';
13
+ import { folder, type Folder } from './trees.ts';
14
+
15
+ /**
16
+ * The file tree beside a folder's or a file's page, which `@pierre/trees` draws, a screen of rows
17
+ * at a time, in a shadow root of its own. It holds what the page's path walked through, which the
18
+ * server draws, and reads a folder's level only when the reader opens it: a 10,000-file tree costs
19
+ * a call for each folder opened. Picking a row leads to its page; a submodule, which has none
20
+ * here, keeps the page where it is.
21
+ */
22
+
23
+ /** The tree's own path for an entry: a folder's ends with `/`. */
24
+ const treePath = (path: string, isFolder: boolean) => (isFolder ? `${path}/` : path);
25
+
26
+ /** Every path a folder's level adds to the tree. */
27
+ const pathsOf = (level: Folder) =>
28
+ level.entries.map((entry) => treePath(entry.path, entry.kind === 'folder'));
29
+
30
+ /** Each submodule's path in `levels`, with its commit. */
31
+ const submodulesOf = (levels: readonly Folder[]) =>
32
+ new Map(
33
+ levels.flatMap((level) =>
34
+ level.entries.flatMap((entry) =>
35
+ entry.kind === 'submodule' ? [[entry.path, entry.sha] as const] : [],
36
+ ),
37
+ ),
38
+ );
39
+
40
+ /**
41
+ * The tree's icons: a folder's, a file's by its name, and a submodule's or a symlink's glyph. The tree picks a
42
+ * row's icon by its name alone, wherever it sits, so a glyph goes only to a name no other row
43
+ * loaded has: a symlink `CLAUDE.md` keeps a file's icon while another `CLAUDE.md` is loaded.
44
+ */
45
+ const iconsOf = (levels: readonly Folder[]): FileTreeIconConfig => {
46
+ const entries = [
47
+ ...new Map(
48
+ levels.flatMap((level) => level.entries.map((entry) => [entry.path, entry])),
49
+ ).values(),
50
+ ];
51
+ const rows = new Map<string, number>();
52
+
53
+ for (const { name } of entries)
54
+ rows.set(name.toLowerCase(), (rows.get(name.toLowerCase()) ?? 0) + 1);
55
+
56
+ return {
57
+ ...fileIcons,
58
+ spriteSheet: glyphSprite,
59
+ remap: { 'file-tree-icon-chevron': glyphSymbols.folder },
60
+ byFileName: Object.fromEntries(
61
+ entries.flatMap((entry) =>
62
+ (entry.kind === 'submodule' || entry.kind === 'symlink') &&
63
+ rows.get(entry.name.toLowerCase()) === 1
64
+ ? [[entry.name, glyphSymbols[entry.kind]]]
65
+ : [],
66
+ ),
67
+ ),
68
+ };
69
+ };
70
+
71
+ /** The row the page is: its folder's, with the `/` the tree gives one, or its file's. */
72
+ const hereOf = (at: At, walked: readonly Folder[]) =>
73
+ walked.at(-1)?.path === at.path ? treePath(at.path, true) : at.path;
74
+
75
+ /** Folders first, then by name as Git's bytes sort it, as the folder's own list does. */
76
+ const byKindThenName: FileTreeOptions['sort'] = (left, right) =>
77
+ Number(right.isDirectory) - Number(left.isDirectory) ||
78
+ (left.basename < right.basename ? -1 : left.basename > right.basename ? 1 : 0);
79
+
80
+ /**
81
+ * The tree's colours, type and square corners, from the app's tokens, which `.dark` swaps: each
82
+ * `--trees-*-override` wins over `@pierre/theming`'s defaults, which the tree's shadow root keeps.
83
+ * It sits on its box's card, at a reading size: 14px names beside 18px icons, its rows 8px in from
84
+ * the card's edges, not the tree's 16.
85
+ */
86
+ const themed = [
87
+ '[--trees-bg-override:var(--card)]',
88
+ // Hover and the picked row tint the foreground, which shows on light's white, as `--accent` doesn't.
89
+ // Each tint is mixed into the card, not laid over it, so a row sliding over another hides it.
90
+ '[--trees-bg-muted-override:color-mix(in_oklch,var(--foreground)_8%,var(--card))]',
91
+ '[--trees-fg-override:var(--foreground)]',
92
+ '[--trees-fg-muted-override:var(--muted-foreground)]',
93
+ '[--trees-selected-bg-override:color-mix(in_oklch,var(--foreground)_12%,var(--card))]',
94
+ '[--trees-selected-fg-override:var(--foreground)]',
95
+ '[--trees-selected-focused-border-color-override:var(--ring)]',
96
+ '[--trees-accent-override:var(--primary)]',
97
+ '[--trees-focus-ring-color-override:var(--ring)]',
98
+ '[--trees-border-color-override:var(--border)]',
99
+ '[--trees-font-family-override:inherit]',
100
+ '[--trees-font-size-override:0.875rem]',
101
+ '[--trees-icon-width-override:1.125rem]',
102
+ '[--trees-border-radius-override:0]',
103
+ '[--trees-padding-inline-override:0.5rem]',
104
+ // A level steps 16px, not the tree's 24, so a name ten folders deep still reads: the 18px
105
+ // icon's half and the row gap take 14.5px of it.
106
+ '[--trees-level-gap-override:2px]',
107
+ ].join(' ');
108
+
109
+ /**
110
+ * The tree's own CSS, which the server's draw carries too. Its sprite sits out of the flow, as the
111
+ * browser's tree puts it: the server's, inline, opens a line above the rows, which then jump up.
112
+ * Its icons draw at the icon width, 18px.
113
+ *
114
+ * A folder's icon is lucide's folder, closed or open, in the folder list's link colour. The tree
115
+ * draws a folder's icon in its chevron's slot, which `remap` fills with the folder, so the slot
116
+ * keeps the chevron's name and the turn the tree gives a closed one, which this CSS takes off. The
117
+ * chevron is the row's `::after` instead, 14px at the row's right end, muted on the picked row too:
118
+ * it marks the row, and the name says what it is. It points right, and down while the folder is
119
+ * open, and `tree-fold.ts` turns it between the two.
120
+ */
121
+ const treeCss = `[data-icon-sprite] { position: absolute; }
122
+ [data-item-section="icon"] svg { width: var(--trees-icon-width); height: var(--trees-icon-width); }
123
+ [data-icon-name="file-tree-icon-chevron"] { color: var(--link); }
124
+ [aria-expanded="false"][data-item-type="folder"] > [data-item-section="icon"] > [data-icon-name="file-tree-icon-chevron"][data-align-capitals] { transform: none; }
125
+ [aria-expanded="true"][data-item-type="folder"] { --ref0-folder-closed: none; --ref0-folder-open: inline; }
126
+ [data-item-type="folder"]::after {
127
+ content: "";
128
+ flex: none;
129
+ width: 0.875rem;
130
+ height: 0.875rem;
131
+ margin-inline-start: auto;
132
+ background-color: var(--trees-fg-muted);
133
+ mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E") center / contain no-repeat;
134
+ }
135
+ [aria-expanded="true"][data-item-type="folder"]::after { transform: rotate(90deg); }`;
136
+
137
+ /** What the tree starts from: the levels the page walked, open down to its row, which is picked. */
138
+ export const treeOptions = (
139
+ id: string,
140
+ at: At,
141
+ walked: readonly Folder[],
142
+ submodules: () => ReadonlyMap<string, string>,
143
+ ): FileTreeOptions => {
144
+ const here = hereOf(at, walked);
145
+
146
+ return {
147
+ id,
148
+ paths: walked.flatMap(pathsOf),
149
+ initialExpandedPaths: ancestry(at.path).map((path) => treePath(path, true)),
150
+ initialSelectedPaths: at.path === '' ? [] : [here],
151
+ flattenEmptyDirectories: false,
152
+ search: false,
153
+ sort: byKindThenName,
154
+ icons: iconsOf(walked),
155
+ density: 'default',
156
+ unsafeCSS: treeCss,
157
+ // A submodule's row says which commit it is, as the folder's list does.
158
+ renderRowDecoration: ({ row }) => {
159
+ const sha = submodules().get(row.path);
160
+
161
+ return sha === undefined
162
+ ? null
163
+ : { text: sha.slice(0, 7), title: `A submodule: another repository's commit, ${sha}` };
164
+ },
165
+ };
166
+ };
167
+
168
+ /** The tree's first rows, which the server draws into its shadow root; the browser takes them up. */
169
+ const preloaded = (options: FileTreeOptions) =>
170
+ typeof document === 'undefined'
171
+ ? preloadFileTree(options)
172
+ : { id: options.id ?? '', shadowHtml: '' };
173
+
174
+ function Tree({
175
+ id,
176
+ at,
177
+ walked,
178
+ }: {
179
+ readonly id: string;
180
+ readonly at: At;
181
+ readonly walked: readonly Folder[];
182
+ }) {
183
+ const navigate = useNavigate();
184
+ const ref = at.ref.name;
185
+ const here = hereOf(at, walked);
186
+ const [opened, setOpened] = useState<ReadonlyMap<string, string>>(new Map());
187
+ const submodules = useRef(submodulesOf(walked));
188
+ const latest = useRef({ navigate, ref, here });
189
+ latest.current = { navigate, ref, here };
190
+ // Whether the page is setting the tree's picked row to its own, which leads nowhere: clearing
191
+ // two picked rows leaves one, which would read as the reader's pick.
192
+ const syncing = useRef(false);
193
+
194
+ const [options] = useState(() => ({
195
+ ...treeOptions(id, at, walked, () => submodules.current),
196
+ onSelectionChange: (paths: readonly string[]) => {
197
+ const current = latest.current;
198
+ const [path] = paths;
199
+
200
+ // Shift and Ctrl pick more than one row, which leads nowhere.
201
+ if (syncing.current || paths.length !== 1 || path === undefined || path === current.here) {
202
+ return;
203
+ }
204
+
205
+ if (submodules.current.has(path)) {
206
+ model.getItem(path)?.deselect();
207
+ model.getItem(current.here)?.select();
208
+
209
+ return;
210
+ }
211
+
212
+ const href = path.endsWith('/')
213
+ ? treeHref(at, current.ref, path.slice(0, -1))
214
+ : blobHref(at, current.ref, path);
215
+ void current.navigate({ href });
216
+ },
217
+ }));
218
+ const [preloadedData] = useState(() => preloaded(options));
219
+ const { model } = useFileTree(options);
220
+
221
+ // A folder a pointer opens or closes moves its rows, as `tree-fold.ts` says.
222
+ const drawn = useRef<HTMLDivElement>(null);
223
+ useEffect(() => (drawn.current === null ? undefined : foldOnPress(drawn.current)), []);
224
+
225
+ const openedPaths = [...opened.keys()];
226
+ const levels = useQueries({
227
+ queries: [...opened].map(([path, sha]) => folder(at, sha, path)),
228
+ combine: (results) => ({
229
+ read: results.flatMap((result) => result.data ?? []),
230
+ failed: results.flatMap((result, index) =>
231
+ result.error === null ? [] : [{ path: openedPaths[index] ?? '', retry: result.refetch }],
232
+ ),
233
+ }),
234
+ });
235
+ const loaded = [...walked, ...levels.read];
236
+ submodules.current = submodulesOf(loaded);
237
+
238
+ // Each level's paths go in once, as it arrives: a folder opened in the tree and then reached by
239
+ // its page arrives both ways at once.
240
+ const added = useRef(new Set(walked.flatMap(pathsOf)));
241
+ useEffect(() => {
242
+ const fresh = [...new Set(loaded.flatMap(pathsOf))].filter((path) => !added.current.has(path));
243
+ if (fresh.length === 0) return;
244
+
245
+ for (const path of fresh) added.current.add(path);
246
+ model.batch(fresh.map((path) => ({ type: 'add', path })));
247
+ model.setIcons(iconsOf(loaded));
248
+ });
249
+
250
+ // A page reached by a link, not the tree, opens its folders and picks its row, which it brings to
251
+ // the tree's middle: the tree's foot starts below the window, until the page scrolls. A row the
252
+ // reader picked in the tree stays under their pointer.
253
+ const first = useRef(true);
254
+ useEffect(() => {
255
+ const picked = model.getSelectedPaths();
256
+ const fromTree = !first.current && picked.length === 1 && picked[0] === here;
257
+ first.current = false;
258
+
259
+ for (const path of ancestry(at.path).slice(0, -1)) {
260
+ const item = model.getItem(treePath(path, true));
261
+ if (item !== null && 'expand' in item) item.expand();
262
+ }
263
+
264
+ syncing.current = true;
265
+
266
+ for (const path of picked) if (path !== here) model.getItem(path)?.deselect();
267
+
268
+ if (at.path !== '') model.getItem(here)?.select();
269
+ syncing.current = false;
270
+
271
+ if (at.path !== '' && !fromTree) model.scrollToPath(here, { offset: 'center', focus: false });
272
+ }, [model, at.path, here]);
273
+
274
+ // The tree says nothing when a folder opens: a change that opened one not yet read reads it.
275
+ const seen = useRef(loaded);
276
+ seen.current = loaded;
277
+ useEffect(
278
+ () =>
279
+ model.subscribe(() => {
280
+ const read = new Set(seen.current.map((level) => level.path));
281
+ const fresh = seen.current.flatMap((level) =>
282
+ level.entries.flatMap((entry) => {
283
+ const item = entry.kind === 'folder' ? model.getItem(treePath(entry.path, true)) : null;
284
+ const open = item !== null && 'isExpanded' in item && item.isExpanded();
285
+
286
+ return open && !read.has(entry.path) ? [[entry.path, entry.sha] as const] : [];
287
+ }),
288
+ );
289
+ if (fresh.length > 0) setOpened((was) => new Map([...was, ...fresh]));
290
+ }),
291
+ [model],
292
+ );
293
+
294
+ return (
295
+ <div ref={drawn} className="flex h-full min-h-0 flex-col">
296
+ <FileTree
297
+ model={model}
298
+ preloadedData={preloadedData}
299
+ aria-label="Files"
300
+ className={`block min-h-0 grow ${themed}`}
301
+ />
302
+ {levels.failed.map((each) => (
303
+ <Alert key={each.path} variant="destructive" className="border-x-0 border-b-0">
304
+ <CircleAlertIcon />
305
+ <AlertDescription>Couldn't read {each.path}.</AlertDescription>
306
+ <AlertAction>
307
+ <Button variant="outline" size="xs" onClick={() => void each.retry()}>
308
+ Try again
309
+ </Button>
310
+ </AlertAction>
311
+ </Alert>
312
+ ))}
313
+ </div>
314
+ );
315
+ }
316
+
317
+ /**
318
+ * The tree from the repository's root folder, with `walked`, the levels the page walked from it.
319
+ * `id` names it, as a page may draw it twice: beside the page, and in the phone's sheet. A new
320
+ * root, at another ref, draws a new tree.
321
+ */
322
+ export function CodeTree({
323
+ id,
324
+ at,
325
+ root,
326
+ walked,
327
+ }: {
328
+ readonly id: string;
329
+ readonly at: At;
330
+ readonly root: string;
331
+ readonly walked: readonly Folder[];
332
+ }) {
333
+ return (
334
+ <nav aria-label="Files" className="flex h-full min-h-0 flex-col">
335
+ <Tree key={`${root}:${at.ref.name}`} id={id} at={at} walked={walked} />
336
+ </nav>
337
+ );
338
+ }
@@ -0,0 +1,230 @@
1
+ import { useNavigate, useRouter } from '@tanstack/react-router';
2
+ import { cn } from '#/lib/cn';
3
+ import { CheckIcon, CopyIcon, XIcon } from 'lucide-react';
4
+ import { useCallback, useEffect, useRef, useState, type ComponentProps } from 'react';
5
+
6
+ import { Button } from '../components/ui/button.tsx';
7
+ import { InputGroupButton } from '../components/ui/input-group.tsx';
8
+ import { Tooltip, TooltipContent, TooltipTrigger } from '../components/ui/tooltip.tsx';
9
+
10
+ /** The code pages' own controls: a link within the app, and a copy button. */
11
+
12
+ /**
13
+ * Loads the page at `href` ahead, its loaders' reads into the cache, so a click on it draws from
14
+ * there (F10). A read that fails leaves the page to show it once it's opened.
15
+ */
16
+ const usePreload = () => {
17
+ const router = useRouter();
18
+
19
+ return useCallback(
20
+ (href: string) => void router.preloadRoute<string, string>({ href }).catch(() => undefined),
21
+ [router],
22
+ );
23
+ };
24
+
25
+ /**
26
+ * Loads each of `hrefs`' pages ahead once the page drawing them has drawn, as the Open and Closed
27
+ * tabs load the other state's list, so a switch draws from the cache.
28
+ */
29
+ export const usePreloaded = (hrefs: readonly string[]) => {
30
+ const preload = usePreload();
31
+ const key = hrefs.join('\n');
32
+
33
+ useEffect(() => {
34
+ for (const href of key.split('\n')) if (href !== '') preload(href);
35
+ }, [key, preload]);
36
+ };
37
+
38
+ /**
39
+ * A link to one of the app's pages, built from a path rather than a route's name: a plain click
40
+ * moves within the app, and any other, a new tab's, is the browser's. Under the router's
41
+ * `defaultPreload: 'intent'`, its page loads ahead once a pointer has rested on it for the
42
+ * router's `defaultPreloadDelay`, it takes focus or a finger touches it, as the router's own links
43
+ * do. The router's options are the one place that says when.
44
+ */
45
+ export function Go({ href, ...props }: ComponentProps<'a'> & { readonly href: string }) {
46
+ const navigate = useNavigate();
47
+ const { options } = useRouter();
48
+ const preload = usePreload();
49
+ const resting = useRef<ReturnType<typeof setTimeout>>(undefined);
50
+ const stop = () => clearTimeout(resting.current);
51
+ const intends = options.defaultPreload === 'intent';
52
+ const loadNow = () => {
53
+ if (intends) preload(href);
54
+ };
55
+
56
+ const loadOnRest = () => {
57
+ stop();
58
+
59
+ if (intends) resting.current = setTimeout(loadNow, options.defaultPreloadDelay ?? 50);
60
+ };
61
+
62
+ useEffect(() => stop, []);
63
+
64
+ return (
65
+ <a
66
+ {...props}
67
+ href={href}
68
+ onMouseEnter={(event) => {
69
+ props.onMouseEnter?.(event);
70
+ loadOnRest();
71
+ }}
72
+ onMouseLeave={(event) => {
73
+ props.onMouseLeave?.(event);
74
+ stop();
75
+ }}
76
+ onFocus={(event) => {
77
+ props.onFocus?.(event);
78
+ loadNow();
79
+ }}
80
+ onTouchStart={(event) => {
81
+ props.onTouchStart?.(event);
82
+ loadNow();
83
+ }}
84
+ onClick={(event) => {
85
+ props.onClick?.(event);
86
+ const own = event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey;
87
+ if (event.defaultPrevented || !own || event.altKey) return;
88
+
89
+ event.preventDefault();
90
+ void navigate({ href });
91
+ }}
92
+ />
93
+ );
94
+ }
95
+
96
+ /** What a copy button says it did, for a moment after a click: copied, or couldn't. */
97
+ const afterCopy = {
98
+ copied: { said: 'Copied', Icon: CheckIcon },
99
+ failed: {
100
+ said: "Couldn't copy: select it and copy it yourself",
101
+ Icon: XIcon,
102
+ },
103
+ } as const;
104
+
105
+ /**
106
+ * Copies `text` where the page has no `navigator.clipboard`, as off a secure origin, such as a
107
+ * preview served over plain http: from a hidden field, selected, with the browser's own copy
108
+ * command. Focus goes back to where it was. Whether the browser copied it.
109
+ */
110
+ const copiedBySelection = (text: string) => {
111
+ const focused = document.activeElement;
112
+ const field = document.createElement('textarea');
113
+ field.value = text;
114
+ field.readOnly = true;
115
+ field.style.position = 'fixed';
116
+ field.style.opacity = '0';
117
+ document.body.append(field);
118
+ field.select();
119
+
120
+ try {
121
+ return document.execCommand('copy');
122
+ } catch {
123
+ return false;
124
+ } finally {
125
+ field.remove();
126
+
127
+ if (focused instanceof HTMLElement) focused.focus();
128
+ }
129
+ };
130
+
131
+ /**
132
+ * Copies `text`, and whether it did. Off a secure origin `navigator.clipboard` is missing, so the
133
+ * copy goes through a selection, at once, while the click that asked for it still counts.
134
+ */
135
+ export const copyText = async (text: string): Promise<boolean> => {
136
+ const clipboard: Clipboard | undefined = navigator.clipboard;
137
+ if (clipboard === undefined) return copiedBySelection(text);
138
+
139
+ // A clipboard that throws before it returns a promise has failed too.
140
+ try {
141
+ await clipboard.writeText(text);
142
+
143
+ return true;
144
+ } catch {
145
+ return false;
146
+ }
147
+ };
148
+
149
+ type Copied = keyof typeof afterCopy;
150
+
151
+ /**
152
+ * Copies `text`, its icon a tick for a moment once it has, or a cross when it couldn't, and its
153
+ * name and tooltip saying which: the tooltip opens for that moment, and a screen reader hears it.
154
+ * It's an outline button by default. In a field's `InputGroup`,
155
+ * `look="field"` draws it as the group's own button; beside text, `look="quiet"` draws a bare
156
+ * icon, which shows only while the `group/copy` it sits in is hovered or focused, or it has just
157
+ * copied.
158
+ */
159
+ export function CopyButton({
160
+ text,
161
+ label,
162
+ look = 'outline',
163
+ }: {
164
+ readonly text: string;
165
+ readonly label: string;
166
+ readonly look?: 'outline' | 'field' | 'quiet';
167
+ }) {
168
+ const [shown, setShown] = useState<Copied>();
169
+ const [hovered, setHovered] = useState(false);
170
+ useEffect(() => {
171
+ if (shown === undefined) return;
172
+
173
+ const timer = setTimeout(() => setShown(undefined), 2000);
174
+
175
+ return () => clearTimeout(timer);
176
+ }, [shown]);
177
+
178
+ const now = shown === undefined ? { said: label, Icon: CopyIcon } : afterCopy[shown];
179
+ const copy = () => void copyText(text).then((copied) => setShown(copied ? 'copied' : 'failed'));
180
+ const button = {
181
+ outline: <Button variant="outline" size="icon-sm" aria-label={now.said} onClick={copy} />,
182
+ field: <InputGroupButton size="icon-xs" aria-label={now.said} onClick={copy} />,
183
+ // A phone has no hover, so there the icon always shows.
184
+ quiet: (
185
+ <Button
186
+ variant="ghost"
187
+ size="icon-xs"
188
+ aria-label={now.said}
189
+ onClick={copy}
190
+ className={cn(
191
+ 'text-muted-foreground opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 pointer-coarse:opacity-100',
192
+ shown !== undefined && 'opacity-100',
193
+ )}
194
+ />
195
+ ),
196
+ }[look];
197
+
198
+ return (
199
+ <>
200
+ <Tooltip open={hovered || shown !== undefined} onOpenChange={setHovered}>
201
+ <TooltipTrigger render={button}>
202
+ <now.Icon />
203
+ </TooltipTrigger>
204
+ <TooltipContent>{now.said}</TooltipContent>
205
+ </Tooltip>
206
+ <span role="status" className="sr-only">
207
+ {shown === undefined ? '' : now.said}
208
+ </span>
209
+ </>
210
+ );
211
+ }
212
+
213
+ const sized = new Intl.NumberFormat('en', { maximumFractionDigits: 1 });
214
+
215
+ /** A file's size as people read one: `512 Bytes`, `1.5 KB`, `50 MB`. */
216
+ export const sizeText = (bytes: number) => {
217
+ if (bytes < 1024) return `${bytes} ${bytes === 1 ? 'Byte' : 'Bytes'}`;
218
+
219
+ const [value, unit] =
220
+ bytes < 1024 ** 2
221
+ ? [bytes / 1024, 'KB']
222
+ : bytes < 1024 ** 3
223
+ ? [bytes / 1024 ** 2, 'MB']
224
+ : [bytes / 1024 ** 3, 'GB'];
225
+
226
+ return `${sized.format(value)} ${unit}`;
227
+ };
228
+
229
+ /** The same date on the server and in every browser, whatever their zone. */
230
+ export const day = new Intl.DateTimeFormat('en', { dateStyle: 'medium', timeZone: 'UTC' });