@vite-hub/docs 0.0.0 → 0.4.1

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 (115) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +456 -0
  3. package/dist/agent-copy-xPaWye_g.js +33 -0
  4. package/dist/assistant-pages-BN7hNsSZ.js +37 -0
  5. package/dist/assistant-shared-CWIKRtBv.d.ts +28 -0
  6. package/dist/assistant-shared-WzButktj.js +113 -0
  7. package/dist/assistant-worker.d.ts +11 -0
  8. package/dist/assistant-worker.js +16 -0
  9. package/dist/assistant.d.ts +14 -0
  10. package/dist/assistant.js +19 -0
  11. package/dist/content-CPZGnn3S.js +141 -0
  12. package/dist/draft-BjWmaiLn.js +45 -0
  13. package/dist/error-diagnostics-B_ZOy7kF.js +93 -0
  14. package/dist/files-UY4h1_36.js +38 -0
  15. package/dist/index.d.ts +28 -0
  16. package/dist/index.js +27 -0
  17. package/dist/link-checker-redirects.d.ts +13 -0
  18. package/dist/link-checker-redirects.js +25 -0
  19. package/dist/manifest-CMoxcwPm.d.ts +80 -0
  20. package/dist/manifest-ZdxLrcvt.js +434 -0
  21. package/dist/markdown-DUWnEMPp.js +378 -0
  22. package/dist/navigation.d.ts +283 -0
  23. package/dist/navigation.js +519 -0
  24. package/dist/nuxt-CAGpKl_-.d.ts +241 -0
  25. package/dist/nuxt.d.ts +3 -0
  26. package/dist/nuxt.js +1868 -0
  27. package/dist/page-Dx2JD3y1.d.ts +74 -0
  28. package/dist/page-GPt09oex.js +82 -0
  29. package/dist/primitive-rail.d.ts +110 -0
  30. package/dist/primitive-rail.js +289 -0
  31. package/dist/raw-BChwipz_.js +857 -0
  32. package/dist/redirects-CmR1yu5A.js +74 -0
  33. package/dist/runtime/app/app.vue +11 -0
  34. package/dist/runtime/app/assistant/DocsAssistant.vue +81 -0
  35. package/dist/runtime/app/assistant/DocsAssistantOff.vue +8 -0
  36. package/dist/runtime/app/assistant/DocsAssistantPanel.vue +322 -0
  37. package/dist/runtime/app/components/AppHeader.vue +368 -0
  38. package/dist/runtime/app/components/AppSearch.vue +68 -0
  39. package/dist/runtime/app/components/DocsAppShell.vue +62 -0
  40. package/dist/runtime/app/components/DocsArticle.vue +184 -0
  41. package/dist/runtime/app/components/DocsAsideFooter.vue +94 -0
  42. package/dist/runtime/app/components/DocsAsideLeftBody.vue +584 -0
  43. package/dist/runtime/app/components/DocsAsideLeftTop.vue +132 -0
  44. package/dist/runtime/app/components/DocsBrandMark.vue +52 -0
  45. package/dist/runtime/app/components/DocsCatalogFooter.vue +129 -0
  46. package/dist/runtime/app/components/DocsCodePanel.vue +388 -0
  47. package/dist/runtime/app/components/DocsCodePre.vue +120 -0
  48. package/dist/runtime/app/components/DocsHeaderActions.vue +4 -0
  49. package/dist/runtime/app/components/DocsLanding.vue +83 -0
  50. package/dist/runtime/app/components/DocsMarkdown.vue +64 -0
  51. package/dist/runtime/app/components/DocsPage.vue +149 -0
  52. package/dist/runtime/app/components/DocsPageCredits.vue +41 -0
  53. package/dist/runtime/app/components/DocsPageHeaderLinks.vue +120 -0
  54. package/dist/runtime/app/components/DocsRail.vue +239 -0
  55. package/dist/runtime/app/components/DocsSidebarStrip.vue +81 -0
  56. package/dist/runtime/app/components/DocsSidebars.vue +63 -0
  57. package/dist/runtime/app/components/OgImage/DocsPage.takumi.vue +33 -0
  58. package/dist/runtime/app/components/content/AgentOnly.vue +9 -0
  59. package/dist/runtime/app/components/content/CodeTree.vue +203 -0
  60. package/dist/runtime/app/components/content/ComarkHtml.vue +31 -0
  61. package/dist/runtime/app/components/content/Correct.vue +17 -0
  62. package/dist/runtime/app/components/content/Example.vue +260 -0
  63. package/dist/runtime/app/components/content/ExamplePreview.vue +6 -0
  64. package/dist/runtime/app/components/content/Examples.vue +71 -0
  65. package/dist/runtime/app/components/content/Incorrect.vue +17 -0
  66. package/dist/runtime/app/components/content/McpClient.vue +170 -0
  67. package/dist/runtime/app/components/content/McpInstall.vue +238 -0
  68. package/dist/runtime/app/components/content/PageList.vue +206 -0
  69. package/dist/runtime/app/components/content/ProductFeatureItem.vue +43 -0
  70. package/dist/runtime/app/components/content/ProductFeatures.vue +17 -0
  71. package/dist/runtime/app/components/content/TutorialStep.vue +39 -0
  72. package/dist/runtime/app/composables/docs-assistant-problem.ts +59 -0
  73. package/dist/runtime/app/composables/docs-theme.ts +15 -0
  74. package/dist/runtime/app/composables/docs.ts +83 -0
  75. package/dist/runtime/app/composables/headerActions.ts +6 -0
  76. package/dist/runtime/app/composables/icons.ts +14 -0
  77. package/dist/runtime/app/composables/seo.ts +64 -0
  78. package/dist/runtime/app/composables/tutorial.ts +40 -0
  79. package/dist/runtime/app/composables/useDocsAssistant.ts +17 -0
  80. package/dist/runtime/app/error.vue +88 -0
  81. package/dist/runtime/app/layouts/default.vue +7 -0
  82. package/dist/runtime/app/layouts/docs.vue +104 -0
  83. package/dist/runtime/app/middleware/docs-layout.ts +23 -0
  84. package/dist/runtime/app/pages/docs-page.vue +3 -0
  85. package/dist/runtime/app/plugins/comark-css.ts +14 -0
  86. package/dist/runtime/app/plugins/icon-stroke.ts +12 -0
  87. package/dist/runtime/app/plugins/theme-color.ts +18 -0
  88. package/dist/runtime/app/utils/docs-theme.ts +43 -0
  89. package/dist/runtime/app/utils/file-tree.ts +40 -0
  90. package/dist/runtime/server/llms.d.ts +6 -0
  91. package/dist/runtime/server/llms.js +7 -0
  92. package/dist/runtime/server/markdown.d.ts +10 -0
  93. package/dist/runtime/server/markdown.js +11 -0
  94. package/dist/runtime/server/mcp.d.ts +6 -0
  95. package/dist/runtime/server/mcp.js +7 -0
  96. package/dist/runtime/server/page.d.ts +7 -0
  97. package/dist/runtime/server/page.js +27 -0
  98. package/dist/runtime/server/raw.d.ts +10 -0
  99. package/dist/runtime/server/raw.js +23 -0
  100. package/dist/runtime/server/search.d.ts +6 -0
  101. package/dist/runtime/server/search.js +32 -0
  102. package/dist/runtime/server/sitemap.d.ts +6 -0
  103. package/dist/runtime/server/sitemap.js +52 -0
  104. package/dist/runtime/server/trailing-slash.d.ts +10 -0
  105. package/dist/runtime/server/trailing-slash.js +28 -0
  106. package/dist/runtime/theme/design.css +464 -0
  107. package/dist/schema-DwpXW0VZ.js +98 -0
  108. package/dist/server.d.ts +15 -0
  109. package/dist/server.js +5 -0
  110. package/dist/theme-BXyu4uFL.d.ts +32 -0
  111. package/dist/theme-DzC8LtMH.js +237 -0
  112. package/dist/theme.d.ts +2 -0
  113. package/dist/theme.js +2 -0
  114. package/dist/types-BhG6vGfG.d.ts +212 -0
  115. package/package.json +144 -1
@@ -0,0 +1,132 @@
1
+ <script setup lang="ts">
2
+ import { docsHomePath, docsSidebarGroup } from "#docs/navigation"
3
+
4
+ const props = defineProps<{
5
+ /** Shows the brand, for a wide-screen sidebar without the rail that carries it. */
6
+ brand?: boolean
7
+ /** Shows search, for a wide-screen sidebar, which has no site header beside it. */
8
+ search?: boolean
9
+ /** Shows the name of what the panel lists, for a panel beside the rail. */
10
+ title?: boolean
11
+ /** Shows a button before search that collapses the sidebar, on a site without the rail, which holds it otherwise. */
12
+ collapsible?: boolean
13
+ }>()
14
+
15
+ const { groups, site, start } = useDocsConfig()
16
+ const manifest = useDocsManifest()
17
+ const section = useDocsSection()
18
+ const docsHome = docsHomePath(manifest, start)
19
+ // The group of the current section, or the section itself.
20
+ const heading = computed(() => {
21
+ if (!props.title || !section.value) return null
22
+ return docsSidebarGroup(manifest, section.value, groups)?.title ?? section.value.title
23
+ })
24
+ const { toggle, focusMounted } = useDocsSidebarToggle()
25
+ onMounted(focusMounted)
26
+ </script>
27
+
28
+ <template>
29
+ <!-- Like the header brand on other pages, it opens the docs home. 40px including the border, as the search row and the banner. -->
30
+ <UTooltip
31
+ v-if="brand"
32
+ :text="site.badge?.tooltip ?? undefined"
33
+ :disabled="!site.badge?.tooltip"
34
+ :content="{ side: 'right', sideOffset: 8 }"
35
+ ignore-non-keyboard-focus
36
+ :ui="{ content: 'h-auto max-w-64 whitespace-normal px-3 py-2 text-left leading-5' }"
37
+ >
38
+ <NuxtLink :to="docsHome ?? '/'" class="vh-docs-panel-brand" data-focus-inset :aria-label="site.badge ? `${site.name} ${site.badge.label}` : site.name">
39
+ <DocsBrandMark />
40
+ <span>{{ site.name }}</span>
41
+ <span v-if="site.badge" class="vh-docs-panel-brand-badge">{{ site.badge.label }}</span>
42
+ </NuxtLink>
43
+ </UTooltip>
44
+ <!-- The collapse button sits where the collapsed strip has its open button, so the pointer can toggle in place. -->
45
+ <div v-if="search" class="vh-docs-panel-search-row">
46
+ <UTooltip v-if="collapsible" text="Hide navigation" :content="{ side: 'right', sideOffset: 6 }" :delay-duration="150" ignore-non-keyboard-focus>
47
+ <button :id="docsSidebarToggleIds.hide" type="button" class="vh-docs-panel-collapse" data-focus-inset aria-label="Hide navigation" @click="toggle(false)">
48
+ <UIcon name="i-lucide-panel-left-close" class="size-4" />
49
+ </button>
50
+ </UTooltip>
51
+ <UContentSearchButton
52
+ :collapsed="false"
53
+ label="Search docs"
54
+ :kbds="['meta', 'K']"
55
+ class="vh-docs-panel-search"
56
+ :ui="{
57
+ base: 'h-10 w-full rounded-none border-0 bg-transparent px-4 text-muted hover:bg-elevated/50 hover:text-highlighted',
58
+ // Touch screens have no keyboard shortcut to show.
59
+ trailing: 'ms-auto flex items-center gap-0.5 pointer-coarse:hidden',
60
+ }"
61
+ />
62
+ </div>
63
+ <p v-if="heading" class="vh-docs-panel-title">{{ heading }}</p>
64
+ </template>
65
+
66
+ <style scoped>
67
+ .vh-docs-panel-brand {
68
+ --vh-docs-mark-size: 1.25rem;
69
+ display: flex;
70
+ flex: none;
71
+ height: 3.5rem;
72
+ align-items: center;
73
+ gap: 0.5rem;
74
+ padding-inline: 1rem;
75
+ color: var(--ui-text-highlighted);
76
+ font-size: 0.9375rem;
77
+ font-weight: 600;
78
+ }
79
+
80
+
81
+ .vh-docs-panel-brand-badge {
82
+ border-bottom: 1px dotted currentcolor;
83
+ color: var(--ui-text-muted);
84
+ font-family: var(--font-mono);
85
+ font-size: 0.625rem;
86
+ font-weight: 500;
87
+ }
88
+
89
+ .vh-docs-panel-search-row {
90
+ display: flex;
91
+ flex: none;
92
+ border-bottom: 1px solid var(--ui-border);
93
+ }
94
+
95
+ .vh-docs-panel-search {
96
+ min-width: 0;
97
+ flex: 1 1 auto;
98
+ font-size: 0.875rem;
99
+ }
100
+
101
+ .vh-docs-panel-brand + .vh-docs-panel-search-row {
102
+ border-top: 1px solid var(--ui-border);
103
+ }
104
+
105
+ .vh-docs-panel-collapse {
106
+ display: flex;
107
+ width: var(--vh-rail-width);
108
+ flex: none;
109
+ align-items: center;
110
+ justify-content: center;
111
+ border-right: 1px solid var(--ui-border);
112
+ color: var(--ui-text-dimmed);
113
+ transition: color 150ms ease, background-color 150ms ease;
114
+ }
115
+
116
+ @media (hover: hover) {
117
+ .vh-docs-panel-collapse:hover {
118
+ background: color-mix(in oklab, var(--ui-bg-elevated) 50%, transparent);
119
+ color: var(--ui-text-highlighted);
120
+ }
121
+ }
122
+
123
+ .vh-docs-panel-title {
124
+ flex: none;
125
+ margin: 0;
126
+ padding: 1rem 1rem 0.5rem;
127
+ color: var(--ui-text-highlighted);
128
+ font-size: 0.875rem;
129
+ font-weight: 600;
130
+ line-height: 1.4;
131
+ }
132
+ </style>
@@ -0,0 +1,52 @@
1
+ <script setup lang="ts">
2
+ // The site mark beside its name in the header, the rail, and the sidebar. A one-color mark is a mask filled with the
3
+ // text color, so it follows light and dark mode. A colored logo shows as it is, with its dark version in dark mode.
4
+ // The parent sets its size with `--vh-docs-mark-size`.
5
+ const { site } = useDocsConfig()
6
+ // Nuxt turns a `null` in runtime config into "", so an empty value means no logo.
7
+ const logo = site.logo || null
8
+ // A mask image is fetched only once the CSS applies to the mark, after the text around it has painted. The preload
9
+ // fetches it with the HTML, in CORS mode like a mask.
10
+ if (logo?.mask) {
11
+ useHead({ link: [{ key: "vh-docs-logo", rel: "preload", as: "image", href: logo.src, crossorigin: "anonymous", fetchpriority: "high" }] })
12
+ }
13
+ </script>
14
+
15
+ <template>
16
+ <span v-if="logo?.mask" class="vh-docs-mark is-mask" :style="{ '--vh-docs-logo': `url(${logo.src})` }" aria-hidden="true" />
17
+ <span v-else-if="logo" class="vh-docs-mark" aria-hidden="true">
18
+ <img :src="logo.src" alt="" :class="{ 'is-light': logo.dark }">
19
+ <img v-if="logo.dark" :src="logo.dark" alt="" class="is-dark">
20
+ </span>
21
+ </template>
22
+
23
+ <style scoped>
24
+ .vh-docs-mark {
25
+ display: block;
26
+ flex: none;
27
+ width: var(--vh-docs-mark-size, 1.25rem);
28
+ height: var(--vh-docs-mark-size, 1.25rem);
29
+ }
30
+
31
+ .vh-docs-mark.is-mask {
32
+ background-color: var(--ui-text-highlighted);
33
+ mask: var(--vh-docs-logo) center / contain no-repeat;
34
+ }
35
+
36
+ .vh-docs-mark img {
37
+ display: block;
38
+ width: 100%;
39
+ height: 100%;
40
+ object-fit: contain;
41
+ }
42
+
43
+ /* `:global(.dark) .a` compiles to `.dark` alone, so each rule names the whole selector inside `:global()`. */
44
+ .vh-docs-mark .is-dark,
45
+ :global(.dark .vh-docs-mark .is-light) {
46
+ display: none;
47
+ }
48
+
49
+ :global(.dark .vh-docs-mark .is-dark) {
50
+ display: block;
51
+ }
52
+ </style>
@@ -0,0 +1,129 @@
1
+ <script setup lang="ts">
2
+ // The end of every docs page: every documented area by category, with the current one marked.
3
+ import { docsCatalog, docsSectionHome } from "#docs/navigation"
4
+
5
+ import type { DocsAppPage, DocsSection } from "@vite-hub/docs"
6
+
7
+ const props = defineProps<{
8
+ current?: DocsSection<DocsAppPage> | null
9
+ }>()
10
+
11
+ const { categories, footer, site } = useDocsConfig()
12
+ const icons = useDocsIcons()
13
+ const groups = docsCatalog(useDocsManifest(), categories)
14
+
15
+ function isCurrent(section: DocsSection<DocsAppPage>) {
16
+ return section.id === props.current?.id
17
+ }
18
+ </script>
19
+
20
+ <template>
21
+ <!-- The rail and the sidebar already mark the current page, so the catalog marks the current section as the current
22
+ item of its list. Sections join the catalog through their `category`. A site without categories has no catalog. -->
23
+ <footer v-if="groups.length || footer.length" class="vh-product-footer" :aria-label="`Explore ${site.name} documentation`">
24
+ <h2 v-if="groups.length" class="vh-product-footer-title">Explore {{ site.name }}</h2>
25
+
26
+ <div v-if="groups.length" class="vh-product-footer-grid">
27
+ <section v-for="group in groups" :key="group.category" class="vh-product-footer-group">
28
+ <h3 class="vh-product-footer-category">{{ group.category }}</h3>
29
+ <ul class="vh-product-footer-list">
30
+ <li v-for="section in group.sections" :key="section.id">
31
+ <NuxtLink
32
+ :to="docsSectionHome(section)"
33
+ class="vh-product-footer-link"
34
+ :class="{ 'is-current': isCurrent(section) }"
35
+ :aria-current="isCurrent(section) ? 'true' : undefined"
36
+ >
37
+ <UIcon :name="icons.section(section)" class="mt-[0.1875rem] size-4 shrink-0" />
38
+ <span class="min-w-0">{{ section.title }}</span>
39
+ </NuxtLink>
40
+ </li>
41
+ </ul>
42
+ </section>
43
+ </div>
44
+
45
+ <nav v-if="footer.length" class="vh-product-footer-site" :aria-label="site.name">
46
+ <NuxtLink v-for="link in footer" :key="link.to" :to="link.to" class="vh-product-footer-link">{{ link.label }}</NuxtLink>
47
+ </nav>
48
+ </footer>
49
+ </template>
50
+
51
+ <style scoped>
52
+ .vh-product-footer {
53
+ margin-top: 4rem;
54
+ border-top: 1px solid var(--ui-border);
55
+ padding-top: 2rem;
56
+ }
57
+
58
+ .vh-product-footer-title {
59
+ margin: 0 0 1.25rem;
60
+ color: var(--ui-text-dimmed);
61
+ font-size: 0.6875rem;
62
+ font-weight: 600;
63
+ letter-spacing: 0.06em;
64
+ text-transform: uppercase;
65
+ }
66
+
67
+ /* Columns keep a readable width and fill the row, so long section titles fit instead of truncating. */
68
+ .vh-product-footer-grid {
69
+ display: grid;
70
+ grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
71
+ gap: 1.5rem;
72
+ }
73
+
74
+ .vh-product-footer-category {
75
+ margin: 0 0 0.5rem;
76
+ color: var(--ui-text-dimmed);
77
+ font-size: 0.6875rem;
78
+ font-weight: 600;
79
+ letter-spacing: 0.06em;
80
+ text-transform: uppercase;
81
+ }
82
+
83
+ .vh-product-footer-list {
84
+ margin: 0;
85
+ padding: 0;
86
+ list-style: none;
87
+ }
88
+
89
+ .vh-product-footer-link {
90
+ display: flex;
91
+ align-items: flex-start;
92
+ gap: 0.5rem;
93
+ padding: 0.1875rem 0;
94
+ color: var(--ui-text-muted);
95
+ font-size: 0.8125rem;
96
+ line-height: 1.375rem;
97
+ transition: color 150ms ease;
98
+ }
99
+
100
+ @media (hover: hover) {
101
+ .vh-product-footer-link:hover {
102
+ color: var(--ui-text-highlighted);
103
+ }
104
+ }
105
+
106
+ /* 44px rows for fingers. The list has no gaps, so the rows grow instead of using hidden tap areas. */
107
+ @media (pointer: coarse) {
108
+ .vh-product-footer-link {
109
+ padding-block: 0.6875rem;
110
+ }
111
+ }
112
+
113
+ .vh-product-footer-site {
114
+ display: flex;
115
+ flex-wrap: wrap;
116
+ column-gap: 1.25rem;
117
+ margin-top: 2rem;
118
+ }
119
+
120
+ .vh-product-footer-grid + .vh-product-footer-site {
121
+ border-top: 1px solid var(--ui-border);
122
+ padding-top: 1rem;
123
+ }
124
+
125
+ .vh-product-footer-link.is-current {
126
+ color: var(--ui-text-highlighted);
127
+ font-weight: 500;
128
+ }
129
+ </style>
@@ -0,0 +1,388 @@
1
+ <script setup lang="ts">
2
+ import { CopyButton } from "@vite-hub/ui"
3
+ import { buildFileTree } from "../utils/file-tree"
4
+
5
+ // The sticky code panel beside a tutorial. It reads the code blocks of the article body in order.
6
+ // While the reader scrolls, the tree lists every file seen so far and the panel shows the file being read.
7
+ // Shell blocks (`bash`, or a `commands/` name) are steps to run, not project files, so the panel skips them.
8
+ // On wide screens each file block in the prose shrinks to its name bar, which opens the file in the panel.
9
+ const props = defineProps<{
10
+ /** The rendered article body that holds the code blocks. */
11
+ body: HTMLElement | null | undefined
12
+ }>()
13
+
14
+ type Block = { path: string; wrapper: HTMLElement; pre: HTMLPreElement }
15
+
16
+ const blocks = shallowRef<Block[]>([])
17
+ const reached = ref(0)
18
+ const selectedPath = ref<string>()
19
+ const code = useTemplateRef<HTMLElement>("code")
20
+ const panel = useTemplateRef<HTMLElement>("panel")
21
+ const codeId = useId()
22
+ // Only a deliberate choice is announced. The file that changes while the reader scrolls stays quiet.
23
+ const announcement = ref("")
24
+
25
+ function filenameFor(pre: HTMLPreElement): string {
26
+ return (pre.dataset.filename ?? pre.dataset.codeFilename ?? "").trim()
27
+ }
28
+
29
+ function collectBlocks(body: HTMLElement): Block[] {
30
+ return [...body.querySelectorAll<HTMLPreElement>("pre")].flatMap((pre) => {
31
+ const wrapper = pre.closest<HTMLElement>(".code-block-wrapper")
32
+ const path = filenameFor(pre)
33
+ const isShell = /\blanguage-(bash|sh|shell|zsh)\b/.test(pre.className) || path.startsWith("commands/")
34
+ const isOutput = path.startsWith("output/")
35
+ return wrapper && path && !isShell && !isOutput ? [{ path, wrapper, pre }] : []
36
+ })
37
+ }
38
+
39
+ // The file being read is the last block whose top crossed 40% of the viewport. Before the first one, it is the first block.
40
+ function updateReached() {
41
+ const line = window.innerHeight * 0.4
42
+ let index = 0
43
+ blocks.value.forEach((block, position) => {
44
+ if (block.wrapper.getBoundingClientRect().top < line) index = position
45
+ })
46
+ if (index !== reached.value || !selectedPath.value) {
47
+ reached.value = index
48
+ selectedPath.value = blocks.value[index]?.path
49
+ }
50
+ }
51
+
52
+ // One entry per path, in order of first appearance. A later block with the same path replaces the earlier code.
53
+ const seenFiles = computed(() => {
54
+ const latest = new Map<string, Block>()
55
+ for (const block of blocks.value.slice(0, reached.value + 1)) latest.set(block.path, block)
56
+ return [...latest.values()]
57
+ })
58
+ const rows = computed(() => buildFileTree(seenFiles.value.map((file) => file.path)))
59
+ const selected = computed(() => seenFiles.value.find((file) => file.path === selectedPath.value))
60
+
61
+ // The panel reuses the highlighted markup the article already rendered, so both copies look the same.
62
+ watch([selected, code], ([file, container]) => {
63
+ if (!container) return
64
+ container.replaceChildren(...(file ? [file.pre.cloneNode(true)] : []))
65
+ container.scrollTop = 0
66
+ }, { flush: "post" })
67
+
68
+ let frame = 0
69
+ let rescanTimer = 0
70
+ let observer: MutationObserver | undefined
71
+ // The panel sticks below the header, but at the top of the page the banner pushes it down. Its height is the
72
+ // viewport below its top edge, so the file tree under the code stays in view at every scroll position.
73
+ let panelTop = -1
74
+ function fitPanel() {
75
+ const element = panel.value
76
+ if (!element) return
77
+ const top = Math.max(0, Math.round(element.getBoundingClientRect().top))
78
+ if (top === panelTop) return
79
+ panelTop = top
80
+ element.style.setProperty("--vh-code-panel-top", `${top}px`)
81
+ }
82
+
83
+ function onScroll() {
84
+ cancelAnimationFrame(frame)
85
+ frame = requestAnimationFrame(() => {
86
+ updateReached()
87
+ fitPanel()
88
+ })
89
+ }
90
+
91
+ function selectFile(path: string | undefined) {
92
+ selectedPath.value = path
93
+ if (path) announcement.value = `Showing ${path}`
94
+ }
95
+
96
+ function selectBlock(index: number) {
97
+ reached.value = Math.max(reached.value, index)
98
+ selectFile(blocks.value[index]?.path)
99
+ }
100
+
101
+ // Each source block gets a class for the wide-screen styles and a click on its name bar.
102
+ const releases: (() => void)[] = []
103
+ function releaseSources() {
104
+ for (const release of releases.splice(0)) release()
105
+ }
106
+ function markSources(list: Block[]) {
107
+ list.forEach((block, index) => {
108
+ // Filename metadata lives on the `<pre>` for collection, but that node is
109
+ // hidden on wide screens. Bind the selection handler to the visible header
110
+ // sibling instead of the hidden code element.
111
+ const bar = [...block.wrapper.children].find(
112
+ (child) => child !== block.pre && !child.matches("button"),
113
+ ) as HTMLElement | undefined
114
+ // Keep the original filename bar as text. Add a native button for keyboard readers. A click anywhere on the bar,
115
+ // the button included, opens the file, so the whole bar that highlights on hover works.
116
+ const trigger = document.createElement("button")
117
+ trigger.type = "button"
118
+ trigger.className = "vh-code-panel-trigger"
119
+ trigger.textContent = "View file"
120
+ trigger.setAttribute("aria-label", `View ${block.path} in the file panel`)
121
+ trigger.setAttribute("aria-controls", codeId)
122
+ const onClick = () => selectBlock(index)
123
+ block.wrapper.classList.add("vh-code-panel-source")
124
+ bar?.addEventListener("click", onClick)
125
+ bar?.append(trigger)
126
+ releases.push(() => {
127
+ block.wrapper.classList.remove("vh-code-panel-source", "is-active")
128
+ bar?.removeEventListener("click", onClick)
129
+ trigger.remove()
130
+ })
131
+ })
132
+ }
133
+
134
+ function scan(body: HTMLElement | null | undefined) {
135
+ releaseSources()
136
+ blocks.value = body ? collectBlocks(body) : []
137
+ reached.value = 0
138
+ selectedPath.value = blocks.value[0]?.path
139
+ markSources(blocks.value)
140
+ if (body) updateReached()
141
+ }
142
+
143
+ watch(() => props.body, (body) => {
144
+ observer?.disconnect()
145
+ scan(body)
146
+ if (!body) return
147
+ observer = new MutationObserver((records) => {
148
+ // Our native filename buttons are presentation only. Rescanning for their
149
+ // insertion/removal would trigger another scan indefinitely.
150
+ const contentChanged = records.some(record =>
151
+ [...record.addedNodes, ...record.removedNodes].some(node =>
152
+ !(node instanceof HTMLElement && node.classList.contains("vh-code-panel-trigger")),
153
+ ),
154
+ )
155
+ if (!contentChanged) return
156
+ window.clearTimeout(rescanTimer)
157
+ rescanTimer = window.setTimeout(() => scan(body), 0)
158
+ })
159
+ observer.observe(body, { childList: true, subtree: true })
160
+ }, { immediate: true, flush: "post" })
161
+
162
+ watch(selectedPath, (path) => {
163
+ for (const block of blocks.value) block.wrapper.classList.toggle("is-active", block.path === path)
164
+ }, { flush: "post" })
165
+
166
+ watch(panel, () => {
167
+ panelTop = -1
168
+ fitPanel()
169
+ }, { flush: "post" })
170
+
171
+ onMounted(() => {
172
+ window.addEventListener("scroll", onScroll, { passive: true })
173
+ window.addEventListener("resize", onScroll, { passive: true })
174
+ })
175
+ onBeforeUnmount(() => {
176
+ window.removeEventListener("scroll", onScroll)
177
+ window.removeEventListener("resize", onScroll)
178
+ cancelAnimationFrame(frame)
179
+ window.clearTimeout(rescanTimer)
180
+ observer?.disconnect()
181
+ releaseSources()
182
+ })
183
+ </script>
184
+
185
+ <template>
186
+ <aside v-if="blocks.length" ref="panel" class="vh-code-panel" aria-label="Files in this tutorial">
187
+ <nav class="vh-code-panel-tree" aria-label="Files so far">
188
+ <template v-for="row in rows" :key="row.path">
189
+ <div v-if="row.kind === 'folder'" class="vh-code-panel-row is-folder" :style="{ '--depth': row.depth }">
190
+ <UIcon name="i-lucide-folder-open" class="size-3.5 shrink-0" aria-hidden="true" />
191
+ <span>{{ row.name }}</span>
192
+ </div>
193
+ <UButton
194
+ v-else
195
+ variant="ghost"
196
+ size="xs"
197
+ icon="i-lucide-file"
198
+ :label="row.name"
199
+ class="vh-code-panel-row is-file"
200
+ :class="{ 'is-active': row.path === selectedPath }"
201
+ :style="{ '--depth': row.depth }"
202
+ :aria-current="row.path === selectedPath ? 'true' : undefined"
203
+ :aria-label="row.path"
204
+ @click="selectFile(row.path)"
205
+ />
206
+ </template>
207
+ </nav>
208
+
209
+ <div class="vh-code-panel-file">
210
+ <div class="vh-code-panel-path">
211
+ <p :id="`${codeId}-path`" class="vh-code-panel-path-name">{{ selected?.path }}</p>
212
+ <!-- The key resets the check when the panel shows another file. -->
213
+ <CopyButton
214
+ v-if="selected"
215
+ :key="selected.path"
216
+ :value="() => selected?.pre.textContent ?? ''"
217
+ size="xs"
218
+ :aria-label="`Copy ${selected.path}`"
219
+ class="vh-code-panel-copy"
220
+ />
221
+ </div>
222
+ <div :id="codeId" ref="code" class="vh-code-panel-code" role="region" :aria-labelledby="`${codeId}-path`" tabindex="0" />
223
+ <p class="sr-only" role="status">{{ announcement }}</p>
224
+ </div>
225
+ </aside>
226
+ </template>
227
+
228
+ <style scoped>
229
+ /* The panel fills the right half and stays in view, like an editor beside the tutorial. Narrow screens keep the code inline.
230
+ The file tree sits under the code, so each line gets the full panel width. */
231
+ .vh-code-panel {
232
+ position: sticky;
233
+ top: var(--ui-header-height);
234
+ display: none;
235
+ height: calc(100dvh - var(--vh-code-panel-top, var(--ui-header-height)));
236
+ grid-template-rows: minmax(0, 1fr) auto;
237
+ grid-template-areas: "file" "tree";
238
+ border-left: 1px solid var(--ui-border);
239
+ background: var(--ui-bg);
240
+ }
241
+
242
+ @media (min-width: 80rem) {
243
+ .vh-code-panel {
244
+ display: grid;
245
+ }
246
+ }
247
+
248
+ .vh-code-panel-tree {
249
+ display: flex;
250
+ min-width: 0;
251
+ max-height: 30dvh;
252
+ grid-area: tree;
253
+ flex-direction: column;
254
+ overflow-y: auto;
255
+ overflow-x: auto;
256
+ border-top: 1px solid var(--ui-border);
257
+ background: var(--ui-bg-muted);
258
+ padding: 0.5rem 0.375rem;
259
+ font-family: var(--font-mono);
260
+ font-size: 0.75rem;
261
+ white-space: nowrap;
262
+ }
263
+
264
+ /* Rows indent by depth. File rows are ghost buttons, so only the indent, the font, and the current file are set here. */
265
+ .vh-code-panel-row {
266
+ display: flex;
267
+ min-height: 1.75rem;
268
+ flex: none;
269
+ align-items: center;
270
+ gap: 0.4375rem;
271
+ padding-inline: calc(0.375rem + var(--depth) * 0.75rem) 0.5rem;
272
+ color: var(--ui-text-muted);
273
+ font: inherit;
274
+ text-align: start;
275
+ }
276
+
277
+ .vh-code-panel-row.is-folder {
278
+ color: var(--ui-text-dimmed);
279
+ }
280
+
281
+ .vh-code-panel-row.is-file.is-active {
282
+ background: var(--ui-bg-elevated);
283
+ color: var(--ui-text-highlighted);
284
+ }
285
+
286
+ .vh-code-panel-file {
287
+ display: flex;
288
+ grid-area: file;
289
+ min-width: 0;
290
+ min-height: 0;
291
+ flex-direction: column;
292
+ }
293
+
294
+ .vh-code-panel-path {
295
+ display: flex;
296
+ min-height: 2.75rem;
297
+ flex: none;
298
+ align-items: center;
299
+ gap: 0.5rem;
300
+ border-bottom: 1px solid var(--ui-border);
301
+ padding-inline: 1rem 0.5rem;
302
+ }
303
+
304
+ .vh-code-panel-path-name {
305
+ min-width: 0;
306
+ flex: 1;
307
+ margin: 0;
308
+ overflow-wrap: anywhere;
309
+ color: var(--ui-text-dimmed);
310
+ font-family: var(--font-mono);
311
+ font-size: 0.75rem;
312
+ }
313
+
314
+ .vh-code-panel-copy {
315
+ flex: none;
316
+ }
317
+
318
+ .vh-code-panel-code {
319
+ min-height: 0;
320
+ flex: 1;
321
+ overflow: auto;
322
+ overscroll-behavior: contain;
323
+ padding: 1rem;
324
+ }
325
+
326
+ .vh-code-panel-code :deep(pre) {
327
+ margin: 0;
328
+ border: 0;
329
+ border-radius: 0;
330
+ background: transparent;
331
+ padding: 0;
332
+ font-size: 0.75rem;
333
+ line-height: 1.85;
334
+ /* Long lines wrap instead of scrolling sideways, so the whole file stays readable in half the page. */
335
+ white-space: pre-wrap;
336
+ overflow-wrap: anywhere;
337
+ }
338
+ </style>
339
+
340
+ <!-- The source blocks live in the article, outside this component, so these rules are global. They apply only where the panel shows. -->
341
+ <style>
342
+ .vh-code-panel-trigger {
343
+ display: none;
344
+ }
345
+
346
+ @media (min-width: 80rem) {
347
+ .vh-code-panel-source > pre,
348
+ .vh-code-panel-source > button {
349
+ display: none;
350
+ }
351
+
352
+ /* The name bar is the whole block now. The wrapper draws the frame, so the bar drops its bottom rule and takes all
353
+ four corners, and the copy button is hidden, so "View file" sits at the end. Two classes, so it wins over the
354
+ scoped style of the bar. */
355
+ .code-block-wrapper.vh-code-panel-source > :first-child {
356
+ border-bottom-width: 0;
357
+ border-radius: inherit;
358
+ padding-inline-end: 0.375rem;
359
+ cursor: pointer;
360
+ transition:
361
+ background-color 150ms ease,
362
+ color 150ms ease;
363
+ }
364
+
365
+ .vh-code-panel-trigger {
366
+ display: inline-flex;
367
+ flex: none;
368
+ margin-inline-start: auto;
369
+ border-radius: calc(var(--ui-radius) * 1.5);
370
+ padding: 0.25rem 0.5rem;
371
+ color: var(--ui-text);
372
+ font: inherit;
373
+ cursor: pointer;
374
+ }
375
+
376
+ @media (hover: hover) {
377
+ .vh-code-panel-source > :first-child:hover {
378
+ background: var(--ui-bg-elevated);
379
+ color: var(--ui-text-highlighted);
380
+ }
381
+ }
382
+
383
+ .vh-code-panel-source.is-active > :first-child {
384
+ background: var(--ui-bg-elevated);
385
+ color: var(--ui-text-highlighted);
386
+ }
387
+ }
388
+ </style>