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,106 @@
1
+ import { type FormEvent, useState } from 'react';
2
+
3
+ import { type SignUp, signUp } from '../../signin/auth-client.ts';
4
+ import { type RefusalText, signUpRefusal } from '../../signin/errors.ts';
5
+ import { Alert, AlertDescription } from '../ui/alert.tsx';
6
+ import { Button } from '../ui/button.tsx';
7
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card.tsx';
8
+ import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel } from '../ui/field.tsx';
9
+ import { Input } from '../ui/input.tsx';
10
+
11
+ /**
12
+ * `/signup`'s Card, from shadcn's `signup-01`: a login, an optional name and a password, sent to
13
+ * Better Auth, which signs the person in, then back to `returnTo`, with sign-in a link away.
14
+ */
15
+ export function SignupForm({ returnTo }: { readonly returnTo: string }) {
16
+ const [person, setPerson] = useState<SignUp>({ login: '', name: '', password: '' });
17
+ const [refused, setRefused] = useState<RefusalText | undefined>(undefined);
18
+ const [pending, setPending] = useState(false);
19
+ const under = (place: RefusalText['place']) =>
20
+ refused?.place === place ? <FieldError>{refused.text}</FieldError> : undefined;
21
+
22
+ const submit = async (event: FormEvent<HTMLFormElement>) => {
23
+ event.preventDefault();
24
+ setPending(true);
25
+
26
+ const { error } = await signUp(person);
27
+ setPending(false);
28
+
29
+ if (error === null) return window.location.assign(returnTo);
30
+
31
+ setRefused(signUpRefusal(error));
32
+ };
33
+
34
+ return (
35
+ <Card>
36
+ <CardHeader>
37
+ <CardTitle>
38
+ <h1>Create an account</h1>
39
+ </CardTitle>
40
+ <CardDescription>Choose a username and a password.</CardDescription>
41
+ </CardHeader>
42
+ <CardContent>
43
+ <form onSubmit={submit}>
44
+ <FieldGroup>
45
+ {refused?.place === 'form' && (
46
+ <Alert variant="destructive">
47
+ <AlertDescription>{refused.text}</AlertDescription>
48
+ </Alert>
49
+ )}
50
+ <Field data-invalid={refused?.place === 'login'}>
51
+ <FieldLabel htmlFor="login" required>
52
+ Username
53
+ </FieldLabel>
54
+ <Input
55
+ id="login"
56
+ autoComplete="username"
57
+ maxLength={39}
58
+ required
59
+ value={person.login}
60
+ onChange={(event) => setPerson({ ...person, login: event.target.value })}
61
+ />
62
+ {under('login')}
63
+ </Field>
64
+ <Field>
65
+ <FieldLabel htmlFor="name">Name</FieldLabel>
66
+ <Input
67
+ id="name"
68
+ autoComplete="name"
69
+ maxLength={100}
70
+ value={person.name ?? ''}
71
+ onChange={(event) => setPerson({ ...person, name: event.target.value })}
72
+ />
73
+ <FieldDescription>Optional: your username when left empty.</FieldDescription>
74
+ </Field>
75
+ <Field data-invalid={refused?.place === 'password'}>
76
+ <FieldLabel htmlFor="password" required>
77
+ Password
78
+ </FieldLabel>
79
+ <Input
80
+ id="password"
81
+ type="password"
82
+ autoComplete="new-password"
83
+ minLength={15}
84
+ maxLength={256}
85
+ required
86
+ value={person.password}
87
+ onChange={(event) => setPerson({ ...person, password: event.target.value })}
88
+ />
89
+ <FieldDescription>At least 15 characters.</FieldDescription>
90
+ {under('password')}
91
+ </Field>
92
+ <Field>
93
+ <Button type="submit" disabled={pending}>
94
+ Create account
95
+ </Button>
96
+ <FieldDescription className="text-center">
97
+ Already have an account?{' '}
98
+ <a href={`/login?${new URLSearchParams({ return_to: returnTo })}`}>Sign in</a>
99
+ </FieldDescription>
100
+ </Field>
101
+ </FieldGroup>
102
+ </form>
103
+ </CardContent>
104
+ </Card>
105
+ );
106
+ }
@@ -0,0 +1,42 @@
1
+ import { LogInIcon, RefreshCwIcon } from 'lucide-react';
2
+
3
+ import type { FollowState } from '../../live/follow.ts';
4
+ import { Alert, AlertDescription } from '../ui/alert.tsx';
5
+ import { signInHref } from './states.tsx';
6
+
7
+ /**
8
+ * The line a live page shows while it isn't live: nothing while it is, or while it first connects,
9
+ * as GitHub shows nothing; a line while it reconnects; and a way back once the viewer's sign-in
10
+ * stopped holding, since the page no longer updates.
11
+ */
12
+ export function LiveStatus({
13
+ state,
14
+ returnTo,
15
+ }: {
16
+ readonly state: FollowState;
17
+ readonly returnTo: string;
18
+ }) {
19
+ if (state === 'retrying')
20
+ return (
21
+ <Alert role="status">
22
+ <RefreshCwIcon className="motion-safe:animate-spin" />
23
+ <AlertDescription>Lost the live connection. Reconnecting…</AlertDescription>
24
+ </Alert>
25
+ );
26
+
27
+ if (state !== 'signed-out') return null;
28
+
29
+ return (
30
+ <Alert role="status">
31
+ <LogInIcon />
32
+ <AlertDescription>
33
+ <span>
34
+ You're signed out, so this page stopped updating.{' '}
35
+ <a className="font-medium text-foreground underline" href={signInHref(returnTo)}>
36
+ Sign in again
37
+ </a>
38
+ </span>
39
+ </AlertDescription>
40
+ </Alert>
41
+ );
42
+ }
@@ -0,0 +1,126 @@
1
+ import { FolderSearchIcon, LayersIcon, LockIcon, LogInIcon } from 'lucide-react';
2
+ import { useEffect, useState, type ReactNode } from 'react';
3
+
4
+ import { Alert, AlertDescription } from '../ui/alert.tsx';
5
+ import { buttonVariants } from '../ui/button.tsx';
6
+ import {
7
+ Empty,
8
+ EmptyContent,
9
+ EmptyDescription,
10
+ EmptyHeader,
11
+ EmptyMedia,
12
+ EmptyTitle,
13
+ } from '../ui/empty.tsx';
14
+
15
+ /** The states every page shares: signed out, not found, read-only, and a load that failed. */
16
+
17
+ /** Sign-in's link, coming back to `returnTo` once it ends. */
18
+ export const signInHref = (returnTo: string) =>
19
+ `/login?${new URLSearchParams({ return_to: returnTo })}`;
20
+
21
+ /** A page that needs someone signed in, for a visitor who isn't. */
22
+ export function SignedOut({
23
+ returnTo,
24
+ what,
25
+ }: {
26
+ readonly returnTo: string;
27
+ readonly what: string;
28
+ }) {
29
+ return (
30
+ <Empty>
31
+ <EmptyHeader>
32
+ <EmptyMedia variant="icon">
33
+ <LogInIcon />
34
+ </EmptyMedia>
35
+ <EmptyTitle>Sign in to see {what}</EmptyTitle>
36
+ <EmptyDescription>
37
+ Public repositories are open to read without signing in.
38
+ </EmptyDescription>
39
+ </EmptyHeader>
40
+ <EmptyContent>
41
+ <a className={buttonVariants()} href={signInHref(returnTo)}>
42
+ Sign in
43
+ </a>
44
+ </EmptyContent>
45
+ </Empty>
46
+ );
47
+ }
48
+
49
+ /** A page whose owner or repository doesn't exist, or isn't the viewer's to read. */
50
+ export function NotFound() {
51
+ return (
52
+ <Empty>
53
+ <EmptyHeader>
54
+ <EmptyMedia variant="icon">
55
+ <FolderSearchIcon />
56
+ </EmptyMedia>
57
+ <EmptyTitle>Not found</EmptyTitle>
58
+ <EmptyDescription>There's nothing here, or it isn't yours to read.</EmptyDescription>
59
+ </EmptyHeader>
60
+ <EmptyContent>
61
+ <a className={buttonVariants({ variant: 'outline' })} href="/">
62
+ Back to your repositories
63
+ </a>
64
+ </EmptyContent>
65
+ </Empty>
66
+ );
67
+ }
68
+
69
+ /** The line a page shows over what the viewer may read but only `owner` may change. */
70
+ export function ReadOnly({ owner }: { readonly owner: string }) {
71
+ return (
72
+ <Alert>
73
+ <LockIcon />
74
+ <AlertDescription>You can read these. Only {owner} can change them.</AlertDescription>
75
+ </Alert>
76
+ );
77
+ }
78
+
79
+ /** A page whose data the drop-in refused for a reason but not finding it: retrying may load it. */
80
+ export function LoadFailed({ message }: { readonly message: string }) {
81
+ return (
82
+ <Alert variant="destructive">
83
+ <AlertDescription>{message}. Reload the page to try again.</AlertDescription>
84
+ </Alert>
85
+ );
86
+ }
87
+
88
+ /**
89
+ * An org's list across its repos, such as its issues, which waits on one read across them: the
90
+ * page never reads each repo's list in turn.
91
+ */
92
+ export function AcrossRepos({ what }: { readonly what: string }) {
93
+ return (
94
+ <Empty className="border">
95
+ <EmptyHeader>
96
+ <EmptyMedia variant="icon">
97
+ <LayersIcon />
98
+ </EmptyMedia>
99
+ <EmptyTitle>Lists across repositories are coming</EmptyTitle>
100
+ <EmptyDescription>For now, pick a repository above to see its {what}.</EmptyDescription>
101
+ </EmptyHeader>
102
+ </Empty>
103
+ );
104
+ }
105
+
106
+ /** How long a load runs before its skeleton shows: a quicker one shows no skeleton at all. */
107
+ export const skeletonAfterMs = 200;
108
+
109
+ /**
110
+ * A page's skeleton while its data loads, drawn only once the load has run `skeletonAfterMs`: data
111
+ * that comes sooner replaces nothing, so the page doesn't flash a skeleton for a moment.
112
+ */
113
+ export function LoadingSkeleton({ children }: { readonly children: ReactNode }) {
114
+ const [late, setLate] = useState(false);
115
+ useEffect(() => {
116
+ const timer = setTimeout(() => setLate(true), skeletonAfterMs);
117
+
118
+ return () => clearTimeout(timer);
119
+ }, []);
120
+
121
+ return late ? (
122
+ <div aria-busy="true" aria-label="Loading">
123
+ {children}
124
+ </div>
125
+ ) : null;
126
+ }
@@ -0,0 +1,143 @@
1
+ import { useEffectEvent, useLayoutEffect, useRef } from 'react';
2
+
3
+ /** Where a tab's bar stands in its list. */
4
+ interface Place {
5
+ readonly x: number;
6
+ readonly y: number;
7
+ readonly width: number;
8
+ }
9
+
10
+ /**
11
+ * What the viewer last pressed: a key or a pointer. A tab reached from the keyboard, by a hotkey
12
+ * or Enter, moves its line at once, since what the keyboard does repeats too often to animate.
13
+ */
14
+ let lastInput: 'key' | 'pointer' = 'pointer';
15
+
16
+ let listening = false;
17
+
18
+ /** Hears each key and pointer press, once for every row, before the page handles it. */
19
+ const listen = () => {
20
+ if (listening) return;
21
+
22
+ listening = true;
23
+ document.addEventListener('keydown', () => (lastInput = 'key'), { capture: true });
24
+ document.addEventListener('pointerdown', () => (lastInput = 'pointer'), { capture: true });
25
+ };
26
+
27
+ export const tabIndicatorDataAttributes = {
28
+ /** On the row's list, once its bar stands under the current tab, which then draws no line. */
29
+ sliding: 'data-sliding',
30
+ /** On the bar while it slides to a new tab, until its slide ends. */
31
+ slide: 'data-slide',
32
+ } as const;
33
+
34
+ /** A tab row's link: its own line under it while it's current, until the row's bar takes over. */
35
+ export const tabLinkClass =
36
+ 'pressable border-b-2 border-transparent text-muted-foreground hover:text-foreground aria-[current]:border-foreground aria-[current]:font-medium aria-[current]:text-foreground in-data-sliding:aria-[current]:border-transparent';
37
+
38
+ /** The transform each line was last given, as written: its style reads it back rounded. */
39
+ const lastTransforms = new WeakMap<HTMLElement, string>();
40
+
41
+ /** Stands `line` at `place`, sliding there or not; a place it already stands at changes nothing. */
42
+ const moveTo = (line: HTMLElement, place: Place, slide: boolean) => {
43
+ const transform = `translate(${place.x}px, ${place.y}px) scaleX(${place.width})`;
44
+ line.style.opacity = '1';
45
+
46
+ if (lastTransforms.get(line) === transform) return;
47
+
48
+ lastTransforms.set(line, transform);
49
+ line.toggleAttribute(tabIndicatorDataAttributes.slide, slide);
50
+ line.style.transform = transform;
51
+ };
52
+
53
+ /** Ends `line`'s slide once its move has run, or was cut short. */
54
+ const settle = (event: TransitionEvent) => {
55
+ if (event.target instanceof HTMLElement)
56
+ event.target.removeAttribute(tabIndicatorDataAttributes.slide);
57
+ };
58
+
59
+ /**
60
+ * The line under a tab row's current tab, which slides to the next current tab when the page
61
+ * changes: one line moving, not one going out as another comes in.
62
+ *
63
+ * Put it last in the row's list, which must be `relative` and stay drawn from page to page, as a
64
+ * layout route's does; it finds the current tab by its
65
+ * `aria-current`. Until it has measured, as in the server's page, the current tab draws its own
66
+ * line. A tab reached from the keyboard, and reduced motion, move it at once.
67
+ */
68
+ export function TabIndicator() {
69
+ const bar = useRef<HTMLSpanElement>(null);
70
+ const shown = useRef(false);
71
+
72
+ const place = useEffectEvent((slide: boolean) => {
73
+ const line = bar.current;
74
+ const list = line?.closest('ul, ol');
75
+ if (line === null || list === null || list === undefined) return;
76
+
77
+ const current = list.querySelector<HTMLElement>('[aria-current="page"]');
78
+
79
+ if (current === null) {
80
+ list.removeAttribute(tabIndicatorDataAttributes.sliding);
81
+ line.style.opacity = '0';
82
+ shown.current = false;
83
+
84
+ return;
85
+ }
86
+
87
+ // Unscaled about the tab's centre, as a press scales it: a tab clicked while it springs back
88
+ // from its press would otherwise read a pixel short.
89
+ const box = current.getBoundingClientRect();
90
+ const from = list.getBoundingClientRect();
91
+ const scale = Number.parseFloat(getComputedStyle(current).scale) || 1;
92
+ const width = box.width / scale;
93
+ const height = box.height / scale;
94
+ const next = {
95
+ x: box.left + (box.width - width) / 2 - from.left,
96
+ y: box.top + (box.height + height) / 2 - from.top - line.offsetHeight,
97
+ width,
98
+ };
99
+
100
+ moveTo(line, next, slide && lastInput === 'pointer');
101
+ list.setAttribute(tabIndicatorDataAttributes.sliding, '');
102
+ shown.current = true;
103
+ });
104
+
105
+ // After every render, since a page change re-renders the row with another tab current.
106
+ useLayoutEffect(() => place(shown.current));
107
+
108
+ // The row reflows as it wraps, its fonts load or the page resizes: follow it at once. A row as
109
+ // wide as its tabs also resizes as a slide starts, since the current tab's weight changes its
110
+ // width: then the slide carries on to where the tab now stands.
111
+ useLayoutEffect(() => {
112
+ listen();
113
+
114
+ const list = bar.current?.closest('ul, ol');
115
+ if (list === null || list === undefined) return;
116
+
117
+ let first = true;
118
+ const watcher = new ResizeObserver(() => {
119
+ // Its first call is for the size it already has.
120
+ if (first) {
121
+ first = false;
122
+
123
+ return;
124
+ }
125
+
126
+ place(bar.current?.hasAttribute(tabIndicatorDataAttributes.slide) === true);
127
+ });
128
+ watcher.observe(list);
129
+
130
+ return () => watcher.disconnect();
131
+ }, []);
132
+
133
+ return (
134
+ <li aria-hidden className="contents">
135
+ <span
136
+ ref={bar}
137
+ onTransitionEnd={(event) => settle(event.nativeEvent)}
138
+ onTransitionCancel={(event) => settle(event.nativeEvent)}
139
+ className="pointer-events-none absolute top-0 left-0 h-0.5 w-px origin-left bg-foreground opacity-0 transition-transform duration-200 ease-fold not-data-slide:transition-none motion-reduce:transition-none"
140
+ />
141
+ </li>
142
+ );
143
+ }
@@ -0,0 +1,108 @@
1
+ import { type LucideIcon, MonitorIcon, MoonIcon, SunIcon } from 'lucide-react';
2
+
3
+ import { type Theme, useTheme } from './theme-provider.tsx';
4
+ import {
5
+ DropdownMenuRadioGroup,
6
+ DropdownMenuRadioItem,
7
+ DropdownMenuSub,
8
+ DropdownMenuSubContent,
9
+ DropdownMenuSubTrigger,
10
+ } from './ui/dropdown-menu.tsx';
11
+ import { ToggleGroup, ToggleGroupItem } from './ui/toggle-group.tsx';
12
+
13
+ /** The three themes, in the order every switch shows them, each with its name and icon. */
14
+ export const themeChoices = [
15
+ { theme: 'light', label: 'Light', Icon: SunIcon },
16
+ { theme: 'dark', label: 'Dark', Icon: MoonIcon },
17
+ { theme: 'system', label: 'System', Icon: MonitorIcon },
18
+ ] as const satisfies readonly {
19
+ readonly theme: Theme;
20
+ readonly label: string;
21
+ readonly Icon: LucideIcon;
22
+ }[];
23
+
24
+ const isTheme = (value: string): value is Theme =>
25
+ themeChoices.some((choice) => choice.theme === value);
26
+
27
+ /**
28
+ * The theme picked, as the switches show it: none until the browser's own choice is known, so a
29
+ * page drawn on the server never checks System and then moves the check.
30
+ */
31
+ const useThemeChoice = () => {
32
+ const { theme, known, setTheme } = useTheme();
33
+
34
+ return {
35
+ picked: known ? theme : undefined,
36
+ /** Picks the toggle's or the menu item's value, which Base UI hands back untyped. */
37
+ pick: (value: string) => {
38
+ if (isTheme(value)) setTheme(value);
39
+ },
40
+ };
41
+ };
42
+
43
+ /**
44
+ * The theme switch, as three toggles in a row with the picked one pressed: on `/settings`'s
45
+ * Appearance and under a sign-in page's card. `named` writes each one's name beside its icon,
46
+ * where there's room; without, each is named for a screen reader and a pointer's hover.
47
+ */
48
+ export function ThemeToggles({ named = false }: { readonly named?: boolean }) {
49
+ const { picked, pick } = useThemeChoice();
50
+
51
+ return (
52
+ <ToggleGroup
53
+ aria-label="Theme"
54
+ variant="outline"
55
+ size={named ? 'default' : 'sm'}
56
+ spacing={0}
57
+ value={picked === undefined ? [] : [picked]}
58
+ // Pressing the pressed one would leave none picked: there's always a theme, so it stays.
59
+ onValueChange={([value]) => {
60
+ if (value !== undefined) pick(value);
61
+ }}
62
+ >
63
+ {themeChoices.map(({ theme, label, Icon }) => (
64
+ <ToggleGroupItem
65
+ key={theme}
66
+ value={theme}
67
+ aria-label={named ? undefined : label}
68
+ title={named ? undefined : label}
69
+ >
70
+ <Icon />
71
+ {named ? label : null}
72
+ </ToggleGroupItem>
73
+ ))}
74
+ </ToggleGroup>
75
+ );
76
+ }
77
+
78
+ /**
79
+ * The account menu's Theme row, a submenu of the same three, the picked one checked: a menu's
80
+ * arrow keys reach each of them, as they wouldn't a row of toggles inside it. The row shows the
81
+ * picked one's icon and name, so the menu says the theme without opening it.
82
+ */
83
+ export function ThemeMenu() {
84
+ const { picked, pick } = useThemeChoice();
85
+ const shown = themeChoices.find((choice) => choice.theme === picked) ?? themeChoices[2];
86
+
87
+ return (
88
+ <DropdownMenuSub>
89
+ <DropdownMenuSubTrigger>
90
+ <shown.Icon />
91
+ Theme
92
+ <span className="ml-auto text-muted-foreground">
93
+ {picked === undefined ? '' : shown.label}
94
+ </span>
95
+ </DropdownMenuSubTrigger>
96
+ <DropdownMenuSubContent aria-label="Theme" className="min-w-36">
97
+ <DropdownMenuRadioGroup value={picked ?? null} onValueChange={pick}>
98
+ {themeChoices.map(({ theme, label, Icon }) => (
99
+ <DropdownMenuRadioItem key={theme} value={theme} closeOnClick={false}>
100
+ <Icon />
101
+ {label}
102
+ </DropdownMenuRadioItem>
103
+ ))}
104
+ </DropdownMenuRadioGroup>
105
+ </DropdownMenuSubContent>
106
+ </DropdownMenuSub>
107
+ );
108
+ }
@@ -0,0 +1,126 @@
1
+ import { createContext, useContext, useEffect, useState } from 'react';
2
+
3
+ /**
4
+ * shadcn's theme provider for Vite, as its dark mode guide gives it: the `.dark` class on <html>,
5
+ * from the theme kept in the browser or, by default, the system's. While the theme is `system`, it
6
+ * follows the system's setting as it changes. `themeScript` sets the class before the first paint,
7
+ * so a dark page never flashes light.
8
+ */
9
+
10
+ export type Theme = 'dark' | 'light' | 'system';
11
+
12
+ const themes: ReadonlySet<string> = new Set<Theme>(['dark', 'light', 'system']);
13
+
14
+ const isTheme = (value: string | null): value is Theme => value !== null && themes.has(value);
15
+
16
+ /** Where the browser keeps the theme someone picked. */
17
+ const storageKey = 'theme';
18
+
19
+ const darkQuery = '(prefers-color-scheme: dark)';
20
+
21
+ /** The theme kept in the browser, or `system`; storage that throws, as a private window's may, too. */
22
+ const storedTheme = (): Theme => {
23
+ try {
24
+ const stored = window.localStorage.getItem(storageKey);
25
+
26
+ return isTheme(stored) ? stored : 'system';
27
+ } catch {
28
+ return 'system';
29
+ }
30
+ };
31
+
32
+ /**
33
+ * Run inline in <head>, before the body paints: the same choice `ThemeProvider` makes, as a string
34
+ * of script, since nothing the bundle holds has loaded yet.
35
+ */
36
+ export const themeScript = `(function(){try{var t=localStorage.getItem(${JSON.stringify(storageKey)});var d=t==='dark'||(t!=='light'&&matchMedia(${JSON.stringify(darkQuery)}).matches);document.documentElement.classList.add(d?'dark':'light')}catch(e){}})()`;
37
+
38
+ interface ThemeState {
39
+ readonly theme: Theme;
40
+ /** Whether `theme` is the browser's own choice yet: the server, and hydration, know only the default. */
41
+ readonly known: boolean;
42
+ readonly setTheme: (theme: Theme) => void;
43
+ }
44
+
45
+ const ThemeContext = createContext<ThemeState>({
46
+ theme: 'system',
47
+ known: false,
48
+ setTheme: () => undefined,
49
+ });
50
+
51
+ /**
52
+ * Swaps <html>'s class with every transition held, so the colours change at once, as one frame,
53
+ * rather than each control easing to its new colours on its own, as the press's would.
54
+ */
55
+ const swapped = (root: HTMLElement, dark: boolean) => {
56
+ const wanted = dark ? 'dark' : 'light';
57
+ if (root.classList.contains(wanted) && !root.classList.contains(dark ? 'light' : 'dark')) return;
58
+
59
+ const held = document.createElement('style');
60
+ held.textContent = '*,*::before,*::after{transition:none!important}';
61
+ document.head.append(held);
62
+
63
+ root.classList.remove('light', 'dark');
64
+ root.classList.add(wanted);
65
+
66
+ // Styles computed with the transitions held, then the hold lifted once that frame is drawn.
67
+ void window.getComputedStyle(document.body).color;
68
+ window.requestAnimationFrame(() => window.requestAnimationFrame(() => held.remove()));
69
+ };
70
+
71
+ /** Shows `theme` on <html>: `system` as the system's setting, now and as it changes. */
72
+ const shown = (theme: Theme) => {
73
+ const root = window.document.documentElement;
74
+ const apply = (dark: boolean) => swapped(root, dark);
75
+
76
+ if (theme !== 'system') {
77
+ apply(theme === 'dark');
78
+
79
+ return undefined;
80
+ }
81
+
82
+ const query = window.matchMedia(darkQuery);
83
+ apply(query.matches);
84
+ const changed = (event: MediaQueryListEvent) => apply(event.matches);
85
+ query.addEventListener('change', changed);
86
+
87
+ return () => query.removeEventListener('change', changed);
88
+ };
89
+
90
+ export function ThemeProvider({
91
+ children,
92
+ defaultTheme = 'system',
93
+ }: {
94
+ readonly children: React.ReactNode;
95
+ readonly defaultTheme?: Theme;
96
+ }) {
97
+ const [theme, setTheme] = useState<Theme>(defaultTheme);
98
+ const [known, setKnown] = useState(false);
99
+
100
+ // The server renders the default; the browser's own choice arrives once it has hydrated.
101
+ useEffect(() => {
102
+ setTheme(storedTheme());
103
+ setKnown(true);
104
+ }, []);
105
+ // Until then the head's script has the class right, which the default could only get wrong.
106
+ useEffect(() => (known ? shown(theme) : undefined), [theme, known]);
107
+
108
+ const value: ThemeState = {
109
+ theme,
110
+ known,
111
+ setTheme: (next) => {
112
+ try {
113
+ window.localStorage.setItem(storageKey, next);
114
+ } catch {
115
+ // Storage refused: the choice lasts until the page reloads.
116
+ }
117
+
118
+ setTheme(next);
119
+ },
120
+ };
121
+
122
+ return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
123
+ }
124
+
125
+ /** The theme, and a way to change it, for a switch. */
126
+ export const useTheme = () => useContext(ThemeContext);
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The colours of an issue's and a pull request's states, from the theme's state tokens, as
3
+ * GitHub's tell them apart: open is green, a closed issue and a merged pull request purple, one
4
+ * closed unmerged red, and a draft grey. `link` is the app's blue, for what the search box reads
5
+ * as a filter.
6
+ */
7
+ export const tones = {
8
+ open: 'text-state-open',
9
+ closed: 'text-state-closed',
10
+ merged: 'text-state-merged',
11
+ unmerged: 'text-state-unmerged',
12
+ draft: 'text-muted-foreground',
13
+ link: 'text-link',
14
+ } as const;
15
+
16
+ /** The same states as a badge's fill, as an issue's or a pull request's page shows its own. */
17
+ export const fills = {
18
+ open: 'bg-state-open text-state-open-foreground',
19
+ closed: 'bg-state-closed text-state-closed-foreground',
20
+ merged: 'bg-state-merged text-state-merged-foreground',
21
+ unmerged: 'bg-state-unmerged text-state-unmerged-foreground',
22
+ draft: 'bg-secondary text-secondary-foreground',
23
+ } as const;