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.
- package/app/apps/github/.dev.vars.example +6 -0
- package/app/apps/github/README.md +70 -0
- package/app/apps/github/THIRD_PARTY_NOTICES.md +214 -0
- package/app/apps/github/components.json +25 -0
- package/app/apps/github/generated/git-rest.ts +10444 -0
- package/app/apps/github/generated/routeTree.gen.ts +1242 -0
- package/app/apps/github/migrations/postgres/0001_auth.sql +46 -0
- package/app/apps/github/migrations/sql/0001_auth.sql +19 -0
- package/app/apps/github/migrations/sql/0002_passkeys.sql +9 -0
- package/app/apps/github/migrations/sql/0003_orgs.sql +22 -0
- package/app/apps/github/migrations/sql/0004_avatars.sql +6 -0
- package/app/apps/github/package.json +80 -0
- package/app/apps/github/src/branches/branch-list.tsx +385 -0
- package/app/apps/github/src/branches/branches.ts +55 -0
- package/app/apps/github/src/clients/allowed.ts +213 -0
- package/app/apps/github/src/clients/at-most.ts +17 -0
- package/app/apps/github/src/clients/avatars.ts +410 -0
- package/app/apps/github/src/clients/cached.ts +65 -0
- package/app/apps/github/src/clients/calls.ts +160 -0
- package/app/apps/github/src/clients/clients.ts +82 -0
- package/app/apps/github/src/clients/graphql.ts +50 -0
- package/app/apps/github/src/clients/host-answer.ts +28 -0
- package/app/apps/github/src/clients/host-calls.ts +382 -0
- package/app/apps/github/src/clients/icon-bytes.ts +203 -0
- package/app/apps/github/src/clients/proxy.ts +59 -0
- package/app/apps/github/src/clients/session-ended.ts +18 -0
- package/app/apps/github/src/clients/transfers.ts +212 -0
- package/app/apps/github/src/code/breadcrumbs.tsx +50 -0
- package/app/apps/github/src/code/code-page.tsx +147 -0
- package/app/apps/github/src/code/code-tree.tsx +338 -0
- package/app/apps/github/src/code/controls.tsx +230 -0
- package/app/apps/github/src/code/file-view.tsx +450 -0
- package/app/apps/github/src/code/files.ts +332 -0
- package/app/apps/github/src/code/folder-list.tsx +122 -0
- package/app/apps/github/src/code/go-to-file.tsx +131 -0
- package/app/apps/github/src/code/highlighted.tsx +58 -0
- package/app/apps/github/src/code/lines.ts +46 -0
- package/app/apps/github/src/code/load.ts +147 -0
- package/app/apps/github/src/code/markdown-files.ts +58 -0
- package/app/apps/github/src/code/places.ts +88 -0
- package/app/apps/github/src/code/ref-pages.ts +179 -0
- package/app/apps/github/src/code/ref-switcher.tsx +203 -0
- package/app/apps/github/src/code/refs.ts +142 -0
- package/app/apps/github/src/code/repo-home.tsx +240 -0
- package/app/apps/github/src/code/repo.ts +105 -0
- package/app/apps/github/src/code/saved-reads.ts +199 -0
- package/app/apps/github/src/code/saved.ts +110 -0
- package/app/apps/github/src/code/tree-fold.ts +186 -0
- package/app/apps/github/src/code/trees.ts +136 -0
- package/app/apps/github/src/components/avatar-picture.ts +53 -0
- package/app/apps/github/src/components/avatar-url.ts +16 -0
- package/app/apps/github/src/components/confirm-action.tsx +100 -0
- package/app/apps/github/src/components/count.tsx +24 -0
- package/app/apps/github/src/components/create-button.tsx +38 -0
- package/app/apps/github/src/components/file-icons/file-icons.css +225 -0
- package/app/apps/github/src/components/file-icons/file-icons.tsx +138 -0
- package/app/apps/github/src/components/filter.tsx +35 -0
- package/app/apps/github/src/components/hotkeys/hotkeys.tsx +255 -0
- package/app/apps/github/src/components/item-list.tsx +65 -0
- package/app/apps/github/src/components/language-dot.tsx +29 -0
- package/app/apps/github/src/components/list-toolbar.tsx +82 -0
- package/app/apps/github/src/components/markdown/editor.tsx +57 -0
- package/app/apps/github/src/components/markdown/markdown.css +177 -0
- package/app/apps/github/src/components/markdown/markdown.tsx +82 -0
- package/app/apps/github/src/components/owner-card.tsx +196 -0
- package/app/apps/github/src/components/pull-status.tsx +34 -0
- package/app/apps/github/src/components/recent.ts +41 -0
- package/app/apps/github/src/components/relative-time.tsx +78 -0
- package/app/apps/github/src/components/repos/icon-hashes.ts +91 -0
- package/app/apps/github/src/components/repos/new-repo-form.tsx +196 -0
- package/app/apps/github/src/components/repos/repo-icon.tsx +47 -0
- package/app/apps/github/src/components/repos/repo-list.tsx +528 -0
- package/app/apps/github/src/components/repos/your-repos.tsx +124 -0
- package/app/apps/github/src/components/review-state.tsx +75 -0
- package/app/apps/github/src/components/route-dialog.tsx +137 -0
- package/app/apps/github/src/components/save-button.tsx +58 -0
- package/app/apps/github/src/components/shell/app-shell.tsx +164 -0
- package/app/apps/github/src/components/shell/create-org-dialog.tsx +118 -0
- package/app/apps/github/src/components/shell/create-row.tsx +49 -0
- package/app/apps/github/src/components/shell/link-menu.tsx +94 -0
- package/app/apps/github/src/components/shell/nav-user.tsx +97 -0
- package/app/apps/github/src/components/shell/owner-repos.tsx +247 -0
- package/app/apps/github/src/components/shell/owner-switcher.tsx +104 -0
- package/app/apps/github/src/components/shell/repo-switcher.tsx +179 -0
- package/app/apps/github/src/components/shell/sections.ts +31 -0
- package/app/apps/github/src/components/shell/submenu-chevron.ts +147 -0
- package/app/apps/github/src/components/signin/device-card.tsx +139 -0
- package/app/apps/github/src/components/signin/login-form.tsx +88 -0
- package/app/apps/github/src/components/signin/signin-page.tsx +33 -0
- package/app/apps/github/src/components/signin/signup-form.tsx +106 -0
- package/app/apps/github/src/components/states/live-status.tsx +42 -0
- package/app/apps/github/src/components/states/states.tsx +126 -0
- package/app/apps/github/src/components/tab-indicator.tsx +143 -0
- package/app/apps/github/src/components/theme-choice.tsx +108 -0
- package/app/apps/github/src/components/theme-provider.tsx +126 -0
- package/app/apps/github/src/components/tones.ts +23 -0
- package/app/apps/github/src/components/ui/alert-dialog.tsx +187 -0
- package/app/apps/github/src/components/ui/alert.tsx +78 -0
- package/app/apps/github/src/components/ui/avatar.tsx +106 -0
- package/app/apps/github/src/components/ui/badge.tsx +51 -0
- package/app/apps/github/src/components/ui/breadcrumb.tsx +124 -0
- package/app/apps/github/src/components/ui/button-group.tsx +87 -0
- package/app/apps/github/src/components/ui/button.tsx +61 -0
- package/app/apps/github/src/components/ui/calendar.tsx +221 -0
- package/app/apps/github/src/components/ui/card.tsx +102 -0
- package/app/apps/github/src/components/ui/checkbox.tsx +26 -0
- package/app/apps/github/src/components/ui/collapsible.tsx +19 -0
- package/app/apps/github/src/components/ui/combobox.tsx +304 -0
- package/app/apps/github/src/components/ui/command.tsx +208 -0
- package/app/apps/github/src/components/ui/dialog.tsx +156 -0
- package/app/apps/github/src/components/ui/dropdown-menu.tsx +290 -0
- package/app/apps/github/src/components/ui/empty.tsx +100 -0
- package/app/apps/github/src/components/ui/field.tsx +236 -0
- package/app/apps/github/src/components/ui/hover-card.tsx +48 -0
- package/app/apps/github/src/components/ui/input-group.tsx +163 -0
- package/app/apps/github/src/components/ui/input.tsx +19 -0
- package/app/apps/github/src/components/ui/item.tsx +201 -0
- package/app/apps/github/src/components/ui/kbd.tsx +27 -0
- package/app/apps/github/src/components/ui/label.tsx +33 -0
- package/app/apps/github/src/components/ui/popover.tsx +87 -0
- package/app/apps/github/src/components/ui/radio-group.tsx +35 -0
- package/app/apps/github/src/components/ui/select.tsx +198 -0
- package/app/apps/github/src/components/ui/separator.tsx +22 -0
- package/app/apps/github/src/components/ui/sheet.tsx +138 -0
- package/app/apps/github/src/components/ui/sidebar.tsx +724 -0
- package/app/apps/github/src/components/ui/skeleton.tsx +13 -0
- package/app/apps/github/src/components/ui/sonner.tsx +47 -0
- package/app/apps/github/src/components/ui/styles.css +242 -0
- package/app/apps/github/src/components/ui/table.tsx +113 -0
- package/app/apps/github/src/components/ui/tabs.tsx +79 -0
- package/app/apps/github/src/components/ui/textarea.tsx +17 -0
- package/app/apps/github/src/components/ui/title.ts +6 -0
- package/app/apps/github/src/components/ui/toggle-group.tsx +89 -0
- package/app/apps/github/src/components/ui/toggle.tsx +42 -0
- package/app/apps/github/src/components/ui/tooltip.tsx +63 -0
- package/app/apps/github/src/components/user-avatar.tsx +145 -0
- package/app/apps/github/src/components/view-tabs.tsx +42 -0
- package/app/apps/github/src/context/context.ts +133 -0
- package/app/apps/github/src/diffs/blobs.ts +94 -0
- package/app/apps/github/src/diffs/diff-view.tsx +155 -0
- package/app/apps/github/src/diffs/files.ts +121 -0
- package/app/apps/github/src/diffs/hunks.tsx +454 -0
- package/app/apps/github/src/diffs/patch.ts +131 -0
- package/app/apps/github/src/diffs/rows.ts +137 -0
- package/app/apps/github/src/history/commit-diff.ts +54 -0
- package/app/apps/github/src/history/commit-list.tsx +207 -0
- package/app/apps/github/src/history/commit-page.tsx +147 -0
- package/app/apps/github/src/history/history.ts +129 -0
- package/app/apps/github/src/hooks/allowed.ts +31 -0
- package/app/apps/github/src/hooks/answers.ts +65 -0
- package/app/apps/github/src/hooks/avatars.ts +54 -0
- package/app/apps/github/src/hooks/draft.ts +38 -0
- package/app/apps/github/src/hooks/open-counts.ts +127 -0
- package/app/apps/github/src/hooks/profiles.ts +120 -0
- package/app/apps/github/src/hooks/repos.ts +440 -0
- package/app/apps/github/src/hooks/use-mobile.ts +19 -0
- package/app/apps/github/src/hooks/viewer.ts +39 -0
- package/app/apps/github/src/inbox/count.ts +70 -0
- package/app/apps/github/src/inbox/inbox-item.tsx +66 -0
- package/app/apps/github/src/inbox/inbox-page.tsx +572 -0
- package/app/apps/github/src/inbox/marks.ts +130 -0
- package/app/apps/github/src/inbox/release-tags.ts +65 -0
- package/app/apps/github/src/inbox/search.ts +97 -0
- package/app/apps/github/src/inbox/subjects.ts +184 -0
- package/app/apps/github/src/inbox/subscription-controls.tsx +184 -0
- package/app/apps/github/src/inbox/subscriptions.ts +189 -0
- package/app/apps/github/src/inbox/threads.ts +198 -0
- package/app/apps/github/src/issues/changes.ts +332 -0
- package/app/apps/github/src/issues/counts.ts +62 -0
- package/app/apps/github/src/issues/issue-list.tsx +682 -0
- package/app/apps/github/src/issues/issue-page.tsx +533 -0
- package/app/apps/github/src/issues/issues.ts +566 -0
- package/app/apps/github/src/issues/label-dialog.tsx +310 -0
- package/app/apps/github/src/issues/labels-page.tsx +119 -0
- package/app/apps/github/src/issues/new-issue.tsx +79 -0
- package/app/apps/github/src/issues/parts.tsx +71 -0
- package/app/apps/github/src/issues/picker.tsx +298 -0
- package/app/apps/github/src/issues/search.ts +238 -0
- package/app/apps/github/src/issues/sidebar.tsx +236 -0
- package/app/apps/github/src/lib/cn.ts +8 -0
- package/app/apps/github/src/lib/highlighting.ts +13 -0
- package/app/apps/github/src/live/follow.ts +129 -0
- package/app/apps/github/src/live/sse.ts +74 -0
- package/app/apps/github/src/live/use-follow.ts +37 -0
- package/app/apps/github/src/markdown/README.md +53 -0
- package/app/apps/github/src/markdown/allowed-html.ts +69 -0
- package/app/apps/github/src/markdown/context.ts +206 -0
- package/app/apps/github/src/markdown/images.ts +81 -0
- package/app/apps/github/src/markdown/lookup.ts +122 -0
- package/app/apps/github/src/markdown/patches.ts +299 -0
- package/app/apps/github/src/markdown/query.ts +25 -0
- package/app/apps/github/src/markdown/references.ts +158 -0
- package/app/apps/github/src/markdown/render.ts +103 -0
- package/app/apps/github/src/names/owners.ts +51 -0
- package/app/apps/github/src/names/repos.ts +24 -0
- package/app/apps/github/src/palette/palette.tsx +547 -0
- package/app/apps/github/src/palette/recent.ts +116 -0
- package/app/apps/github/src/palette/rows.tsx +455 -0
- package/app/apps/github/src/palette/server.ts +104 -0
- package/app/apps/github/src/palette/targets.ts +306 -0
- package/app/apps/github/src/policy.ts +600 -0
- package/app/apps/github/src/private-repos.ts +47 -0
- package/app/apps/github/src/pulls/compare-page.tsx +342 -0
- package/app/apps/github/src/pulls/files-tab.tsx +776 -0
- package/app/apps/github/src/pulls/live.ts +124 -0
- package/app/apps/github/src/pulls/merge-box.tsx +367 -0
- package/app/apps/github/src/pulls/merge-button.ts +86 -0
- package/app/apps/github/src/pulls/pull-list.tsx +235 -0
- package/app/apps/github/src/pulls/pull-page.tsx +474 -0
- package/app/apps/github/src/pulls/pull.ts +468 -0
- package/app/apps/github/src/pulls/pulls.ts +318 -0
- package/app/apps/github/src/pulls/review.ts +350 -0
- package/app/apps/github/src/pulls/search.ts +130 -0
- package/app/apps/github/src/queue/queue-page.tsx +405 -0
- package/app/apps/github/src/queue/queue.ts +231 -0
- package/app/apps/github/src/releases/latest-release.tsx +55 -0
- package/app/apps/github/src/releases/overview.tsx +30 -0
- package/app/apps/github/src/releases/release-form.tsx +353 -0
- package/app/apps/github/src/releases/release-list.tsx +173 -0
- package/app/apps/github/src/releases/release-view.tsx +183 -0
- package/app/apps/github/src/releases/releases.ts +308 -0
- package/app/apps/github/src/releases/tag-list.tsx +134 -0
- package/app/apps/github/src/router.tsx +46 -0
- package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +33 -0
- package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +28 -0
- package/app/apps/github/src/routes/$owner/$repo/_code.tsx +11 -0
- package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/_releases.tsx +23 -0
- package/app/apps/github/src/routes/$owner/$repo/branches.tsx +39 -0
- package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +34 -0
- package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +42 -0
- package/app/apps/github/src/routes/$owner/$repo/compare/$.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/index.tsx +24 -0
- package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +50 -0
- package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +53 -0
- package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +43 -0
- package/app/apps/github/src/routes/$owner/$repo/labels.tsx +22 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/checks.tsx +15 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/commits.tsx +15 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/files.tsx +15 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/index.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +52 -0
- package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +48 -0
- package/app/apps/github/src/routes/$owner/$repo/queue.tsx +22 -0
- package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +58 -0
- package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +40 -0
- package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +35 -0
- package/app/apps/github/src/routes/$owner/$repo/route.tsx +102 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +9 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +16 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/hooks/new.tsx +25 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +17 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/route.tsx +28 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/rules.tsx +12 -0
- package/app/apps/github/src/routes/$owner/$repo/tokens.tsx +16 -0
- package/app/apps/github/src/routes/$owner/index.tsx +45 -0
- package/app/apps/github/src/routes/-nav.tsx +293 -0
- package/app/apps/github/src/routes/-root-testing.ts +107 -0
- package/app/apps/github/src/routes/__root.tsx +225 -0
- package/app/apps/github/src/routes/api.auth.$.ts +18 -0
- package/app/apps/github/src/routes/downloads/$owner/$repo/$asset.tsx +10 -0
- package/app/apps/github/src/routes/file-icons[.]svg.ts +21 -0
- package/app/apps/github/src/routes/icons/$owner/$repo.tsx +14 -0
- package/app/apps/github/src/routes/icons/$owner/index.tsx +14 -0
- package/app/apps/github/src/routes/icons/index.tsx +12 -0
- package/app/apps/github/src/routes/index.tsx +48 -0
- package/app/apps/github/src/routes/login.tsx +24 -0
- package/app/apps/github/src/routes/login_.code.tsx +31 -0
- package/app/apps/github/src/routes/new.tsx +91 -0
- package/app/apps/github/src/routes/notifications.tsx +20 -0
- package/app/apps/github/src/routes/orgs/$owner/issues.tsx +8 -0
- package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +8 -0
- package/app/apps/github/src/routes/orgs/$owner/releases.tsx +8 -0
- package/app/apps/github/src/routes/orgs/$owner/route.tsx +25 -0
- package/app/apps/github/src/routes/orgs/$owner/settings.tsx +30 -0
- package/app/apps/github/src/routes/orgs/$owner/tokens.tsx +15 -0
- package/app/apps/github/src/routes/settings.tsx +54 -0
- package/app/apps/github/src/routes/signup.tsx +24 -0
- package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +10 -0
- package/app/apps/github/src/seed/acme.ts +498 -0
- package/app/apps/github/src/seed/licenses.ts +114 -0
- package/app/apps/github/src/seed/seed.ts +538 -0
- package/app/apps/github/src/server.ts +97 -0
- package/app/apps/github/src/settings/account-avatar.tsx +43 -0
- package/app/apps/github/src/settings/avatar-section.tsx +140 -0
- package/app/apps/github/src/settings/avatar.ts +58 -0
- package/app/apps/github/src/settings/general-settings.tsx +439 -0
- package/app/apps/github/src/settings/general.ts +73 -0
- package/app/apps/github/src/settings/hook-form.tsx +195 -0
- package/app/apps/github/src/settings/hook-list.tsx +166 -0
- package/app/apps/github/src/settings/hooks.ts +87 -0
- package/app/apps/github/src/settings/org-settings.tsx +228 -0
- package/app/apps/github/src/settings/orgs.ts +116 -0
- package/app/apps/github/src/settings/rule-list.tsx +72 -0
- package/app/apps/github/src/settings/rules.ts +27 -0
- package/app/apps/github/src/settings/settings-layout.tsx +114 -0
- package/app/apps/github/src/signin/approval.ts +186 -0
- package/app/apps/github/src/signin/auth-client.ts +127 -0
- package/app/apps/github/src/signin/auth.ts +753 -0
- package/app/apps/github/src/signin/avatars.ts +126 -0
- package/app/apps/github/src/signin/client-ip.ts +39 -0
- package/app/apps/github/src/signin/credentials.ts +26 -0
- package/app/apps/github/src/signin/device-code.ts +95 -0
- package/app/apps/github/src/signin/device-prompt.ts +125 -0
- package/app/apps/github/src/signin/errors.ts +135 -0
- package/app/apps/github/src/signin/host-session.ts +68 -0
- package/app/apps/github/src/signin/orgs.ts +283 -0
- package/app/apps/github/src/signin/owner-names.ts +183 -0
- package/app/apps/github/src/signin/person-lock.ts +104 -0
- package/app/apps/github/src/signin/seal.ts +88 -0
- package/app/apps/github/src/signin/seed-people.ts +92 -0
- package/app/apps/github/src/signin/session.ts +48 -0
- package/app/apps/github/src/signin/unborn.ts +110 -0
- package/app/apps/github/src/signin/viewer-orgs.ts +47 -0
- package/app/apps/github/src/signin/viewer.ts +74 -0
- package/app/apps/github/src/signin/with-headers.ts +14 -0
- package/app/apps/github/src/tokens/tokens-page.tsx +529 -0
- package/app/apps/github/src/tokens/tokens.ts +54 -0
- package/app/apps/github/tsconfig.json +25 -0
- package/app/apps/github/tsconfig.worker.json +24 -0
- package/app/apps/github/vite.config.ts +21 -0
- package/app/pnpm-workspace.yaml +216 -0
- package/app/tsconfig.base.json +127 -0
- package/dist/LICENSE +202 -0
- package/dist/cli/child.mjs +42 -0
- package/dist/cli/commands.mjs +23 -0
- package/dist/cli/credentials.mjs +84 -0
- package/dist/cli/documents.mjs +214 -0
- package/dist/cli/events.mjs +55 -0
- package/dist/cli/failure.mjs +105 -0
- package/dist/cli/folders.mjs +32 -0
- package/dist/cli/git-remote-ref0.d.mts +1 -0
- package/dist/cli/git-remote-ref0.mjs +29 -0
- package/dist/cli/git.mjs +48 -0
- package/dist/cli/helpers.mjs +51 -0
- package/dist/cli/hosts.mjs +127 -0
- package/dist/cli/node.mjs +15 -0
- package/dist/cli/output.mjs +135 -0
- package/dist/cli/prompt.mjs +35 -0
- package/dist/cli/queue.mjs +215 -0
- package/dist/cli/ref0-git.d.mts +1 -0
- package/dist/cli/ref0-git.mjs +144 -0
- package/dist/cli/repos.mjs +162 -0
- package/dist/cli/resources.mjs +131 -0
- package/dist/cli/run-end.mjs +57 -0
- package/dist/cli/runtime.mjs +50 -0
- package/dist/cli/setup.mjs +1410 -0
- package/dist/cli/sign-in.mjs +162 -0
- package/dist/cli/sign-ins.mjs +79 -0
- package/dist/cli/sqlite.mjs +28 -0
- package/dist/cli/tokens.mjs +141 -0
- package/dist/cli/vendor.mjs +123 -0
- package/dist/init/app.mjs +231 -0
- package/dist/init/astro.mjs +49 -0
- package/dist/init/choices.mjs +497 -0
- package/dist/init/cloudflare.mjs +324 -0
- package/dist/init/create.mjs +151 -0
- package/dist/init/detect.mjs +297 -0
- package/dist/init/files.mjs +75 -0
- package/dist/init/frameworks.mjs +248 -0
- package/dist/init/git-module.mjs +49 -0
- package/dist/init/github-routes.mjs +66 -0
- package/dist/init/jsonc.mjs +143 -0
- package/dist/init/metadata.mjs +48 -0
- package/dist/init/mounts.mjs +109 -0
- package/dist/init/next.mjs +205 -0
- package/dist/init/node-app.mjs +189 -0
- package/dist/init/node.mjs +458 -0
- package/dist/init/nuxt.mjs +115 -0
- package/dist/init/output.mjs +21 -0
- package/dist/init/plan.mjs +82 -0
- package/dist/init/range-major.mjs +257 -0
- package/dist/init/react-router.mjs +59 -0
- package/dist/init/routes.mjs +148 -0
- package/dist/init/shell.mjs +4 -0
- package/dist/init/stores.mjs +51 -0
- package/dist/init/sveltekit.mjs +139 -0
- package/dist/init/template.mjs +142 -0
- package/dist/init/templates.mjs +343 -0
- package/dist/init/vercel.mjs +383 -0
- package/dist/init/versions.mjs +32 -0
- package/dist/init/workspace.mjs +20 -0
- package/package.json +52 -3
- package/README.md +0 -3
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { escapeHtml } from '@pierre/words/html';
|
|
2
|
+
import GithubSlugger from 'github-slugger';
|
|
3
|
+
|
|
4
|
+
import { githubHtml, unwrapped } from './allowed-html.ts';
|
|
5
|
+
import { repoImageAt, resolveHref, type Linker, type MarkdownContext } from './context.ts';
|
|
6
|
+
import { htmlParts, linkHtml } from './references.ts';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A hook takes the HTML words made for one element, its children's hooks already run. Words finds
|
|
10
|
+
* each element by its tags, `<[^>]*>`, which holds only while no `<`, `>` or `"` stands raw inside
|
|
11
|
+
* a tag, as words writes none. So a hook writes each value it takes from the text or a URL through
|
|
12
|
+
* words' `escapeHtml`, and nothing raw: the rest are fixed strings, or `references`' labels, which
|
|
13
|
+
* match only `[\w./#@-]`. `references` and `lineBreaks` read a quoted value as part of its tag
|
|
14
|
+
* besides (`htmlParts`), so they never take one for text.
|
|
15
|
+
*/
|
|
16
|
+
type Hook = (html: string) => string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* One thing words' own render lacks, which GitHub's has: raw tags for words to keep, hooks by tag,
|
|
20
|
+
* and URLs to drop. The README beside this file says what each is for and which test proves words
|
|
21
|
+
* still needs it.
|
|
22
|
+
*/
|
|
23
|
+
export interface Patch {
|
|
24
|
+
readonly allowed?: Readonly<Record<string, readonly string[]>>;
|
|
25
|
+
readonly hooks?: Readonly<Record<string, Hook>>;
|
|
26
|
+
readonly drops?: (url: string) => boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const entities = new Map([
|
|
30
|
+
['&', '&'],
|
|
31
|
+
['<', '<'],
|
|
32
|
+
['>', '>'],
|
|
33
|
+
['"', '"'],
|
|
34
|
+
[''', "'"],
|
|
35
|
+
[''', "'"],
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
/** HTML's text, its tags dropped and its entities read. */
|
|
39
|
+
export const textOf = (html: string) =>
|
|
40
|
+
html
|
|
41
|
+
.replace(/<[^>]*>/g, '')
|
|
42
|
+
.replace(/&(?:amp|lt|gt|quot|#x27|#39);/g, (entity) => entities.get(entity) ?? entity);
|
|
43
|
+
|
|
44
|
+
/** A tag the text wrote as raw HTML: words marks each element it makes with `data-markdown`. */
|
|
45
|
+
const isRaw = (html: string) => !/^<[a-z0-9]+ data-markdown=/.test(html);
|
|
46
|
+
|
|
47
|
+
/** `hook` on the opening tag of raw HTML alone. */
|
|
48
|
+
const onRawOpening =
|
|
49
|
+
(hook: (opening: string) => string): Hook =>
|
|
50
|
+
(html) =>
|
|
51
|
+
isRaw(html) ? html.replace(/^<[^>]*>/, hook) : html;
|
|
52
|
+
|
|
53
|
+
/** The same hook for each tag. */
|
|
54
|
+
const each = (tags: readonly string[], hook: Hook) =>
|
|
55
|
+
Object.fromEntries(tags.map((tag) => [tag, hook]));
|
|
56
|
+
|
|
57
|
+
const headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const;
|
|
58
|
+
|
|
59
|
+
/** A tag GitHub drops while it shows its text: its text, without it. */
|
|
60
|
+
const unwrap: Hook = (html) => html.replace(/^<[^>]*>/, '').replace(/<\/[a-z]+>\s*$/, '');
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Each alert's octicon, as GitHub's title draws it: Primer's, MIT, as `rehype-github-alert` 1.0.0
|
|
64
|
+
* copied them.
|
|
65
|
+
*/
|
|
66
|
+
const alertIcons = new Map<string, readonly [name: string, path: string]>([
|
|
67
|
+
[
|
|
68
|
+
'caution',
|
|
69
|
+
[
|
|
70
|
+
'octicon-stop',
|
|
71
|
+
'M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z',
|
|
72
|
+
],
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
'important',
|
|
76
|
+
[
|
|
77
|
+
'octicon-report',
|
|
78
|
+
'M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z',
|
|
79
|
+
],
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
'note',
|
|
83
|
+
[
|
|
84
|
+
'octicon-info',
|
|
85
|
+
'M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z',
|
|
86
|
+
],
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
'tip',
|
|
90
|
+
[
|
|
91
|
+
'octicon-light-bulb',
|
|
92
|
+
'M8 1.5c-2.363 0-4 1.69-4 3.75 0 .984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75 0 0 1-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456 0 0 0-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863 0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751 0 0 1-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304 0-2.06-1.637-3.75-4-3.75ZM5.75 12h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM6 15.25a.75.75 0 0 1 .75-.75h2.5a.75.75 0 0 1 0 1.5h-2.5a.75.75 0 0 1-.75-.75Z',
|
|
93
|
+
],
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
'warning',
|
|
97
|
+
[
|
|
98
|
+
'octicon-alert',
|
|
99
|
+
'M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z',
|
|
100
|
+
],
|
|
101
|
+
],
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
const alertOpening =
|
|
105
|
+
/^<blockquote([^>]*)>\n<p([^>]*)>\[!([a-z]+)\][ \t]*(?:\n|<br \/>\n|<br>\n|$)/i;
|
|
106
|
+
|
|
107
|
+
/** `> [!NOTE]` and the rest, opening a quote, as GitHub's alert. */
|
|
108
|
+
const alert: Hook = (html) => {
|
|
109
|
+
if (html.startsWith('<blockquote data-nested')) return html;
|
|
110
|
+
|
|
111
|
+
const opening = alertOpening.exec(html);
|
|
112
|
+
const type = opening?.[3]?.toLowerCase() ?? '';
|
|
113
|
+
const icon = alertIcons.get(type);
|
|
114
|
+
if (opening === null || icon === undefined) return html;
|
|
115
|
+
|
|
116
|
+
const body = `<p${opening[2] ?? ''}>${html.slice(opening[0].length)}`;
|
|
117
|
+
const inside = body.replace(/<\/blockquote>\s*$/, '').replace(/^<p[^>]*><\/p>\n?/, '');
|
|
118
|
+
const title = `${type[0]?.toUpperCase() ?? ''}${type.slice(1)}`;
|
|
119
|
+
|
|
120
|
+
const [name, path] = icon;
|
|
121
|
+
const svg = `<svg class="octicon ${name} mr-2" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="${path}"></path></svg>`;
|
|
122
|
+
|
|
123
|
+
return `<div class="markdown-alert markdown-alert-${type}"><p class="markdown-alert-title">${svg}${title}</p>${inside}</div>`;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** A comment's soft line breaks, as GitHub shows them: each a `<br>`, outside `<pre>`. */
|
|
127
|
+
const breakLines: Hook = (html) => {
|
|
128
|
+
let out = '';
|
|
129
|
+
let pre = 0;
|
|
130
|
+
|
|
131
|
+
for (const part of htmlParts(html)) {
|
|
132
|
+
if (part.startsWith('<')) {
|
|
133
|
+
const tag = /^<(\/?)pre\b/i.exec(part);
|
|
134
|
+
if (tag !== null) pre += tag[1] === '/' ? -1 : 1;
|
|
135
|
+
out += part;
|
|
136
|
+
} else out += pre > 0 ? part : part.replace(/\n(?=.)/g, '<br>\n');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return out;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* URLs GitHub's rule drops, past those words drops itself: `ftp:` and `tel:`, where
|
|
144
|
+
* `rehype-sanitize`'s record of GitHub's rule allows only `http`, `https`, `mailto`, `irc`, `ircs`
|
|
145
|
+
* and `xmpp`.
|
|
146
|
+
*/
|
|
147
|
+
export const dropped = (url: string) => /^\s*(?:ftp|tel):/i.test(textOf(url));
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Words' render, patched to GitHub's, in `context`, with `linker`'s references, named so a test can
|
|
151
|
+
* leave one out. In order: words runs each tag's hooks in the order the patches first name the
|
|
152
|
+
* tag, so `alerts` marks a list's quotes before it reads quotes.
|
|
153
|
+
*/
|
|
154
|
+
export const patchesFor = (context: MarkdownContext, linker: Linker) => {
|
|
155
|
+
const file = context.kind === 'file';
|
|
156
|
+
const slugger = new GithubSlugger();
|
|
157
|
+
const linked: Hook = (html) => linkHtml(html, context, linker);
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
/** GitHub's tags, fitted to words' 4,096 bytes: without it, words keeps no raw tag. */
|
|
161
|
+
githubHtml: { allowed: githubHtml },
|
|
162
|
+
|
|
163
|
+
/** Tags GitHub drops but shows the text of: words drops a block-level one, text and all. */
|
|
164
|
+
unwrap: {
|
|
165
|
+
allowed: Object.fromEntries(unwrapped.map((tag) => [tag, []])),
|
|
166
|
+
hooks: each(unwrapped, unwrap),
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
/** A raw `id` or `name` with `user-content-`, as GitHub's: words' `idPrefix` reaches only its own. */
|
|
170
|
+
rawIds: {
|
|
171
|
+
hooks: each(
|
|
172
|
+
['a', 'div', 'p', ...headings],
|
|
173
|
+
onRawOpening((opening) =>
|
|
174
|
+
opening.replace(/ (id|name)="([^"]*)"/g, ' $1="user-content-$2"'),
|
|
175
|
+
),
|
|
176
|
+
),
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
/** A raw link's URL resolved in a file, as Markdown's are: words' `urlTransform` skips raw tags. */
|
|
180
|
+
rawUrls: {
|
|
181
|
+
hooks: file
|
|
182
|
+
? {
|
|
183
|
+
a: onRawOpening((opening) =>
|
|
184
|
+
opening.replace(
|
|
185
|
+
/ href="([^"]*)"/,
|
|
186
|
+
(_href, url: string) => ` href="${escapeHtml(resolveHref(textOf(url), context))}"`,
|
|
187
|
+
),
|
|
188
|
+
),
|
|
189
|
+
}
|
|
190
|
+
: {},
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* A file's image in its repo, Markdown's or raw: no `src`, but `data-repo`, `data-ref` and
|
|
195
|
+
* `data-path`, which no text can write, as words keeps no `data-` attribute, and the browser
|
|
196
|
+
* reads it as a blob through the REST client (Q310).
|
|
197
|
+
*/
|
|
198
|
+
repoImages: {
|
|
199
|
+
hooks: file
|
|
200
|
+
? {
|
|
201
|
+
img: (html) =>
|
|
202
|
+
html.replace(/ src="([^"]*)"/, (whole, url: string) => {
|
|
203
|
+
const image = repoImageAt(textOf(url), context);
|
|
204
|
+
if (image === undefined) return whole;
|
|
205
|
+
|
|
206
|
+
return ` data-repo="${escapeHtml(image.repo)}" data-ref="${escapeHtml(image.ref)}" data-path="${escapeHtml(image.path)}"`;
|
|
207
|
+
}),
|
|
208
|
+
}
|
|
209
|
+
: {},
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
/** `ftp:` and `tel:` dropped, in Markdown and raw HTML, as GitHub's rule drops them. */
|
|
213
|
+
schemes: {
|
|
214
|
+
drops: dropped,
|
|
215
|
+
hooks: each(['a', 'img'], (html) =>
|
|
216
|
+
html.replace(/^<[^>]*>/, (opening) =>
|
|
217
|
+
opening.replace(/ (href|src)="([^"]*)"/g, (whole, _key, url: string) =>
|
|
218
|
+
dropped(url) ? '' : whole,
|
|
219
|
+
),
|
|
220
|
+
),
|
|
221
|
+
),
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
/** GitHub's alerts, `> [!NOTE]` and the rest, but not a quote in a list, as GitHub leaves it. */
|
|
225
|
+
alerts: {
|
|
226
|
+
hooks: {
|
|
227
|
+
li: (html: string) => html.replace(/<blockquote /g, '<blockquote data-nested="" '),
|
|
228
|
+
blockquote: alert,
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
/** The references that exist linked: a comment's all, and a file's `owner/repo#12` alone. */
|
|
233
|
+
references: { hooks: each(['p', 'li', 'td', 'th', ...headings], linked) },
|
|
234
|
+
|
|
235
|
+
/** A comment's soft line breaks as `<br>`, as GitHub's comments break where the text does. */
|
|
236
|
+
lineBreaks: { hooks: file ? {} : { p: breakLines } },
|
|
237
|
+
|
|
238
|
+
/** A comment's soft break between two raw tags as `<br>` too: `lineBreaks` needs text after it. */
|
|
239
|
+
rawBreaks: {
|
|
240
|
+
hooks: file
|
|
241
|
+
? {}
|
|
242
|
+
: {
|
|
243
|
+
p: (html: string) => html.replace(/(<\/?[a-z][^>]*>)\n(?=<(?!\/p>)[a-z])/g, '$1<br>\n'),
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
/** A file's headings' anchors, GitHub's slugs, unless the text gave a raw heading an `id`. */
|
|
248
|
+
anchors: {
|
|
249
|
+
hooks: file
|
|
250
|
+
? each(headings, (html) => {
|
|
251
|
+
if (isRaw(html) && / id="/.test(/^<[^>]*>/.exec(html)?.[0] ?? '')) return html;
|
|
252
|
+
|
|
253
|
+
const id = escapeHtml(`user-content-${slugger.slug(textOf(html))}`);
|
|
254
|
+
|
|
255
|
+
return html.replace(
|
|
256
|
+
/^<(h[1-6])([^>]*)>/,
|
|
257
|
+
(_opening, tag: string, rest: string) => `<${tag}${rest} id="${id}">`,
|
|
258
|
+
);
|
|
259
|
+
})
|
|
260
|
+
: {},
|
|
261
|
+
},
|
|
262
|
+
} satisfies Record<string, Patch>;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
export type PatchName = keyof ReturnType<typeof patchesFor>;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* What words takes from `patches`: their raw tags, each tag's hooks run one after another, and a
|
|
269
|
+
* `urlTransform` that drops their URLs and resolves a file's links against its repo, ref and folder.
|
|
270
|
+
* A file's image keeps its URL for `repoImages`; a comment keeps its URLs.
|
|
271
|
+
*/
|
|
272
|
+
export const compose = (context: MarkdownContext, patches: readonly Patch[]) => {
|
|
273
|
+
const hooks = new Map<string, Hook[]>();
|
|
274
|
+
|
|
275
|
+
for (const patch of patches) {
|
|
276
|
+
for (const [tag, hook] of Object.entries(patch.hooks ?? {})) {
|
|
277
|
+
hooks.set(tag, [...(hooks.get(tag) ?? []), hook]);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const allowedHtml = Object.fromEntries(
|
|
282
|
+
patches.flatMap((patch) => Object.entries(patch.allowed ?? {})),
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
return {
|
|
286
|
+
allowedHtml,
|
|
287
|
+
components: Object.fromEntries(
|
|
288
|
+
[...hooks].map(([tag, chain]) => [
|
|
289
|
+
tag,
|
|
290
|
+
(html: string) => chain.reduce((out, hook) => hook(out), html),
|
|
291
|
+
]),
|
|
292
|
+
),
|
|
293
|
+
urlTransform: (url: string, key: 'href' | 'src'): string | null => {
|
|
294
|
+
if (patches.some((patch) => patch.drops?.(url) === true)) return null;
|
|
295
|
+
|
|
296
|
+
return key === 'href' ? resolveHref(url, context) : url;
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { queryOptions } from '@tanstack/react-query';
|
|
2
|
+
|
|
3
|
+
import type { MarkdownContext } from './context.ts';
|
|
4
|
+
import { githubLookups, lookUp } from './lookup.ts';
|
|
5
|
+
import { referencesIn, renderMarkdown } from './render.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* How long a comment's render, and the references it looked up, are trusted: an issue it names
|
|
9
|
+
* may close, or a user may go, and a page drawn again past this looks them up again behind.
|
|
10
|
+
*/
|
|
11
|
+
export const renderFresh = 60_000;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A text's render in its context, its references looked up first through the drop-in, as the
|
|
15
|
+
* viewer: a loader can fetch it ahead, so the server's page has its links. The same text in the
|
|
16
|
+
* same context draws again from the cache for `renderFresh`, so an issue opened again draws its
|
|
17
|
+
* body and comments with no lookups (F10).
|
|
18
|
+
*/
|
|
19
|
+
export const markdownQuery = (text: string, context: MarkdownContext) =>
|
|
20
|
+
queryOptions({
|
|
21
|
+
queryKey: ['markdown', context, text],
|
|
22
|
+
queryFn: async () =>
|
|
23
|
+
renderMarkdown(text, context, await lookUp(referencesIn(text, context), githubLookups)),
|
|
24
|
+
staleTime: renderFresh,
|
|
25
|
+
});
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { escapeHtml } from '@pierre/words/html';
|
|
2
|
+
|
|
3
|
+
import type { Linker, MarkdownContext } from './context.ts';
|
|
4
|
+
|
|
5
|
+
const nameChar = /^[\w.-]$/;
|
|
6
|
+
|
|
7
|
+
const wordChar = /^\w$/;
|
|
8
|
+
|
|
9
|
+
const digit = /^\d$/;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Where an owner whose name runs from `start` to `end` may begin, as the regex's lookbehind,
|
|
13
|
+
* `(?<![\w/])`, allows: the leftmost place not after a word character or a slash, which inside
|
|
14
|
+
* a name is just after a `.` or a `-`.
|
|
15
|
+
*/
|
|
16
|
+
const ownerStart = (text: string, start: number, end: number) => {
|
|
17
|
+
for (let at = start; at < end; at += 1) {
|
|
18
|
+
if (!/^[\w/]$/.test(text[at - 1] ?? '')) return at;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return undefined;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** How far back from `at` the run of name characters reaches, stopping at `floor`. */
|
|
25
|
+
const nameStart = (text: string, at: number, floor: number) => {
|
|
26
|
+
let start = at;
|
|
27
|
+
|
|
28
|
+
while (start > floor && nameChar.test(text[start - 1] ?? '')) start -= 1;
|
|
29
|
+
|
|
30
|
+
return start;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Each `owner/repo#12` in a file's text, which GitHub's file view links, and nothing shorter: not
|
|
35
|
+
* after a word character or a slash, and not before one. A scan from each `#` back over its own
|
|
36
|
+
* name, so text of any length takes one pass, where a regex retried every position.
|
|
37
|
+
*/
|
|
38
|
+
export const repoIssues = function* (text: string) {
|
|
39
|
+
let floor = 0;
|
|
40
|
+
|
|
41
|
+
for (let hash = text.indexOf('#'); hash !== -1; hash = text.indexOf('#', hash + 1)) {
|
|
42
|
+
let end = hash + 1;
|
|
43
|
+
|
|
44
|
+
while (end < text.length && digit.test(text[end] ?? '')) end += 1;
|
|
45
|
+
|
|
46
|
+
if (end === hash + 1 || wordChar.test(text[end] ?? '')) continue;
|
|
47
|
+
|
|
48
|
+
const slash = nameStart(text, hash, floor);
|
|
49
|
+
if (slash === hash || text[slash - 1] !== '/') continue;
|
|
50
|
+
|
|
51
|
+
const start = ownerStart(text, nameStart(text, slash - 1, floor), slash - 1);
|
|
52
|
+
if (start === undefined) continue;
|
|
53
|
+
|
|
54
|
+
yield { start, end, repo: text.slice(start, hash), number: text.slice(hash + 1, end) };
|
|
55
|
+
floor = end;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A comment's references, as GitHub links them: `owner/repo#12`, `#12`, `GH-12`, `@login` (a
|
|
61
|
+
* team's `@org/team` stays text), and a commit's SHA, alone or as `owner/repo@sha`. None starts
|
|
62
|
+
* after a name's character, a slash, an `@` or an `&`, which opens an entity, so each try fails at
|
|
63
|
+
* once inside a run and text of any length takes one pass.
|
|
64
|
+
*/
|
|
65
|
+
const commentReference =
|
|
66
|
+
/(?<![\w/@.&-])(?:([\w.-]+\/[\w.-]+)#(\d+)|#(\d+)|GH-(\d+)|@([a-z\d][a-z\d-]{0,38})(\/[\w-]+)?|(?:([\w.-]+\/[\w.-]+)@)?([0-9a-f]{7,64}))(?![\w-])/gi;
|
|
67
|
+
|
|
68
|
+
const link = (href: string | undefined, kind: string, label: string) =>
|
|
69
|
+
href === undefined ? undefined : `<a href="${escapeHtml(href)}" class="${kind}">${label}</a>`;
|
|
70
|
+
|
|
71
|
+
/** One reference in a comment's text, as its link, or `undefined` while it doesn't exist. */
|
|
72
|
+
const commentLink = (
|
|
73
|
+
groups: readonly (string | undefined)[],
|
|
74
|
+
context: MarkdownContext,
|
|
75
|
+
linker: Linker,
|
|
76
|
+
): string | undefined => {
|
|
77
|
+
const [whole = '', repo, repoNumber, number, ghNumber, login, team, shaRepo, sha] = groups;
|
|
78
|
+
|
|
79
|
+
if (repo !== undefined && repoNumber !== undefined) {
|
|
80
|
+
const label = repo === context.repo ? `#${repoNumber}` : whole;
|
|
81
|
+
|
|
82
|
+
return link(linker.issue({ repo, number: repoNumber }), 'issue-link', label);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const own = number ?? ghNumber;
|
|
86
|
+
if (own !== undefined)
|
|
87
|
+
return link(linker.issue({ repo: context.repo, number: own }), 'issue-link', whole);
|
|
88
|
+
|
|
89
|
+
if (login !== undefined) {
|
|
90
|
+
return team === undefined ? link(linker.user(login), 'user-mention', whole) : undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (sha === undefined) return undefined;
|
|
94
|
+
|
|
95
|
+
const at = shaRepo ?? context.repo;
|
|
96
|
+
const href = linker.commit({ repo: at, sha });
|
|
97
|
+
const short = `<tt>${(href?.split('/').at(-1) ?? sha).slice(0, 7)}</tt>`;
|
|
98
|
+
|
|
99
|
+
return link(href, 'commit-link', at === context.repo ? short : `${at}@${short}`);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* `text`, a run of HTML text, with each reference GitHub links in `context` that exists as a
|
|
104
|
+
* link: in a comment all of a comment's, and in a file only `owner/repo#12`, as GitHub's file view
|
|
105
|
+
* links no other.
|
|
106
|
+
*/
|
|
107
|
+
export const linkText = (text: string, context: MarkdownContext, linker: Linker): string => {
|
|
108
|
+
if (context.kind === 'comment') {
|
|
109
|
+
return text.replace(
|
|
110
|
+
commentReference,
|
|
111
|
+
(...match: (string | number | undefined)[]) =>
|
|
112
|
+
commentLink(
|
|
113
|
+
match.slice(0, 9).map((group) => group?.toString()),
|
|
114
|
+
context,
|
|
115
|
+
linker,
|
|
116
|
+
) ?? String(match[0]),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let out = '';
|
|
121
|
+
let at = 0;
|
|
122
|
+
|
|
123
|
+
for (const { start, end, repo, number } of repoIssues(text)) {
|
|
124
|
+
const label = repo === context.repo ? `#${number}` : text.slice(start, end);
|
|
125
|
+
const linked = link(linker.issue({ repo, number }), 'issue-link', label);
|
|
126
|
+
if (linked === undefined) continue;
|
|
127
|
+
|
|
128
|
+
out += text.slice(at, start) + linked;
|
|
129
|
+
at = end;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return out + text.slice(at);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/** Tags whose text is never linked: a link's, code's, and a diagram's or math's drawing. */
|
|
136
|
+
const unlinked = /^<(\/?)(a|code|pre|svg)\b/i;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* `html`'s tags and the text between them, each tag whole: a quoted value is read as part of its
|
|
140
|
+
* tag, so a `>` in one, which words never writes raw, can't end the tag and leave the rest as text.
|
|
141
|
+
*/
|
|
142
|
+
export const htmlParts = (html: string) => html.split(/(<(?:[^>"']|"[^"]*"|'[^']*')*>)/);
|
|
143
|
+
|
|
144
|
+
/** `html` with the references in its text linked, outside tags, links, code and drawings. */
|
|
145
|
+
export const linkHtml = (html: string, context: MarkdownContext, linker: Linker) => {
|
|
146
|
+
let out = '';
|
|
147
|
+
let skip = 0;
|
|
148
|
+
|
|
149
|
+
for (const part of htmlParts(html)) {
|
|
150
|
+
if (part.startsWith('<')) {
|
|
151
|
+
const tag = unlinked.exec(part);
|
|
152
|
+
if (tag !== null && !part.endsWith('/>')) skip += tag[1] === '/' ? -1 : 1;
|
|
153
|
+
out += part;
|
|
154
|
+
} else out += skip > 0 ? part : linkText(part, context, linker);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return out;
|
|
158
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createHtmlRenderer, escapeHtml, type MermaidPlugin } from '@pierre/words/html';
|
|
2
|
+
import * as pele from 'pele';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
fragmentTargets,
|
|
6
|
+
linkerOf,
|
|
7
|
+
recorder,
|
|
8
|
+
type Found,
|
|
9
|
+
type MarkdownContext,
|
|
10
|
+
type References,
|
|
11
|
+
} from './context.ts';
|
|
12
|
+
import { compose, patchesFor, textOf, type Patch } from './patches.ts';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Mermaid as SVG, by Pele, with no links or images, as GitHub's Mermaid draws at its strict level,
|
|
16
|
+
* and ids of its own, so two diagrams' never meet, nor the text's, which all start
|
|
17
|
+
* `user-content-`. A diagram Pele can't read, as a preview meets mid-edit, stays its code.
|
|
18
|
+
*/
|
|
19
|
+
const mermaid = (): MermaidPlugin => {
|
|
20
|
+
let diagrams = 0;
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
render: ({ code, isIncomplete }) => {
|
|
24
|
+
if (isIncomplete) return null;
|
|
25
|
+
|
|
26
|
+
diagrams += 1;
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
return pele.render(code, { links: false, images: false, idPrefix: `mermaid-${diagrams}` })
|
|
30
|
+
.svg;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A fragment link to an id the text gave, which the render prefixed: `#setup` goes to
|
|
40
|
+
* `#user-content-setup`, and `#Setup` to it too, as GitHub's page script tries the fragment as
|
|
41
|
+
* written, then prefixed, then lowercased. A fragment with no such target stays as written.
|
|
42
|
+
*/
|
|
43
|
+
const fragments = (html: string) => {
|
|
44
|
+
const targets = new Set(
|
|
45
|
+
[...html.matchAll(/ (?:id|name)="([^"]*)"/g)].map(([, id = '']) => textOf(id)),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return html.replace(
|
|
49
|
+
/(<a\b[^>]*? href=")#([^"]*)"/g,
|
|
50
|
+
(whole, opening: string, fragment: string) => {
|
|
51
|
+
const [asWritten = '', ...prefixed] = fragmentTargets(textOf(fragment));
|
|
52
|
+
if (targets.has(asWritten)) return whole;
|
|
53
|
+
|
|
54
|
+
const target = prefixed.find((id) => targets.has(id));
|
|
55
|
+
|
|
56
|
+
return target === undefined ? whole : `${opening}#${escapeHtml(target)}"`;
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Words, with `patches`: every patch, for the app, or all but one, for a test showing words still
|
|
63
|
+
* needs it. `draw` off leaves diagrams as code, for a pass that only reads references.
|
|
64
|
+
*/
|
|
65
|
+
export const rendered = (
|
|
66
|
+
text: string,
|
|
67
|
+
context: MarkdownContext,
|
|
68
|
+
patches: readonly Patch[],
|
|
69
|
+
draw: boolean,
|
|
70
|
+
) => {
|
|
71
|
+
const { allowedHtml, components, urlTransform } = compose(context, patches);
|
|
72
|
+
const renderer = createHtmlRenderer({
|
|
73
|
+
math: true,
|
|
74
|
+
allowedHtml,
|
|
75
|
+
components,
|
|
76
|
+
plugins: draw ? { mermaid: mermaid() } : {},
|
|
77
|
+
controls: false,
|
|
78
|
+
lineNumbers: false,
|
|
79
|
+
urlTransform,
|
|
80
|
+
idPrefix: 'user-content-',
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
return renderer.render(text, false).html;
|
|
85
|
+
} finally {
|
|
86
|
+
renderer.dispose();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* `text` as sanitized HTML, the same in a preview and on the server: its references linked only
|
|
92
|
+
* where `found` says they exist.
|
|
93
|
+
*/
|
|
94
|
+
export const renderMarkdown = (text: string, context: MarkdownContext, found: Found): string =>
|
|
95
|
+
fragments(rendered(text, context, Object.values(patchesFor(context, linkerOf(found))), true));
|
|
96
|
+
|
|
97
|
+
/** The issues, pulls, people and commits `text` names in `context`, for a lookup before rendering. */
|
|
98
|
+
export const referencesIn = (text: string, context: MarkdownContext): References => {
|
|
99
|
+
const { linker, references } = recorder();
|
|
100
|
+
rendered(text, context, Object.values(patchesFor(context, linker)), false);
|
|
101
|
+
|
|
102
|
+
return references();
|
|
103
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The logins no person or org may take. The app's own first path segments: a repo at
|
|
3
|
+
* `/{owner}/{repo}` under one would be shadowed by the app's page, or shadow it. `login`, `logout`
|
|
4
|
+
* and `signup` are sign-in's, `new`, `notifications`, `settings` and `orgs` the app's pages, `uploads` and
|
|
5
|
+
* `downloads` its release assets' routes, `icons` its avatars', `repos`, `tokens` and `me` Git's
|
|
6
|
+
* REST, and the rest what the drop-in, Better Auth's `/api/auth` and the build serve. And `admin`,
|
|
7
|
+
* so no one looks like the admin, whose actor is `_admin`, which no login can spell. Start's
|
|
8
|
+
* `/_serverFn` needs no entry: no login starts with `_`.
|
|
9
|
+
*/
|
|
10
|
+
export const reservedOwners: ReadonlySet<string> = new Set([
|
|
11
|
+
'admin',
|
|
12
|
+
'api',
|
|
13
|
+
'assets',
|
|
14
|
+
'avatars',
|
|
15
|
+
'downloads',
|
|
16
|
+
'icons',
|
|
17
|
+
'login',
|
|
18
|
+
'logout',
|
|
19
|
+
'me',
|
|
20
|
+
'new',
|
|
21
|
+
'notifications',
|
|
22
|
+
'orgs',
|
|
23
|
+
'repos',
|
|
24
|
+
'settings',
|
|
25
|
+
'signup',
|
|
26
|
+
'tokens',
|
|
27
|
+
'uploads',
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The admin's actor, whom `ADMIN_TOKEN` signs in as: `_admin`, which no person can hold, since a
|
|
32
|
+
* person's ID is their login and no login spells an underscore.
|
|
33
|
+
*/
|
|
34
|
+
export const admin = { id: '_admin' } as const;
|
|
35
|
+
|
|
36
|
+
/** A GitHub login: letters, digits and single hyphens, not at either end, at most 39 characters. */
|
|
37
|
+
const loginPattern = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Why `login` isn't a login at all, or `undefined` when it is: what every place that makes a
|
|
41
|
+
* person's actor checks, so no row, however it was written, acts as the admin's `_admin`.
|
|
42
|
+
*/
|
|
43
|
+
export const loginProblem = (login: string): string | undefined =>
|
|
44
|
+
loginPattern.test(login)
|
|
45
|
+
? undefined
|
|
46
|
+
: 'Use letters, digits and single hyphens, up to 39, not starting or ending with one';
|
|
47
|
+
|
|
48
|
+
/** Why `owner` can't name a new owner, or `undefined` when it can: a login, and not a reserved one. */
|
|
49
|
+
export const ownerProblem = (owner: string): string | undefined =>
|
|
50
|
+
loginProblem(owner) ??
|
|
51
|
+
(reservedOwners.has(owner.toLowerCase()) ? `'${owner}' is reserved` : undefined);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** GitHub's most for a repository's name. */
|
|
2
|
+
const maxName = 100;
|
|
3
|
+
|
|
4
|
+
/** The app's pages under an owner, such as `/pip/settings`, which no repo's name may take. */
|
|
5
|
+
export const reservedRepos: ReadonlySet<string> = new Set(['login', 'new', 'settings']);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Why `name` can't name a repository, or `undefined` when it can. The drop-in turns each character
|
|
9
|
+
* outside these into `-`, and refuses a name starting with `.` or `-` or ending in `.git` or
|
|
10
|
+
* `.lock`, as Git's repo IDs do; the form says so before it sends one.
|
|
11
|
+
*/
|
|
12
|
+
export const repoProblem = (name: string): string | undefined => {
|
|
13
|
+
if (name === '') return 'Name the repository';
|
|
14
|
+
|
|
15
|
+
if (name.length > maxName) return `Use at most ${maxName} characters`;
|
|
16
|
+
|
|
17
|
+
if (!/^[A-Za-z0-9._-]+$/.test(name)) return "Use letters, digits, '.', '-' and '_'";
|
|
18
|
+
|
|
19
|
+
if (!/^[A-Za-z0-9_]/.test(name)) return "Start with a letter, a digit or '_'";
|
|
20
|
+
|
|
21
|
+
if (reservedRepos.has(name.toLowerCase())) return `'${name}' is one of the app's pages`;
|
|
22
|
+
|
|
23
|
+
return /\.(?:git|lock)$/.test(name) ? "Don't end with .git or .lock" : undefined;
|
|
24
|
+
};
|