Commit 90e81c5c31

90e81c5c319055779ed7fa0ba898d22381afb18b

parent: 129566db03

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-05-24 04:23 UTC

a

Layout: unified · split

docs/.vitepress/theme/Layout.vue +28 −26
@@ -65,7 +65,7 @@ if (!import.meta.env.SSR) {
6565 })
6666}
6767
68const openCollapsibles = (target: HTMLElement) => {
68const openCollapsibles = (target: HTMLElement, ancestorOnly = false) => {
6969 let scrollTarget = target
7070 let el: HTMLElement | null = target
7171
@@ -75,31 +75,33 @@ const openCollapsibles = (target: HTMLElement) => {
7575 el = el.parentElement
7676 }
7777
78 const tagName = target.tagName
79 if (tagName.length === 2 && tagName[0] === 'H') {
80 const level = +tagName[1]
81 if (level >= 1 && level <= 6) {
82 let sibling = target.nextElementSibling
83
84 while (sibling) {
85 const siblingTag = sibling.tagName
86 if (
87 siblingTag.length === 2 && siblingTag[0] === 'H' &&
88 +siblingTag[1] <= level
89 ) break
90
91 if (siblingTag === 'DETAILS') {
92 ;(sibling as HTMLDetailsElement).open = true
93 if (scrollTarget === target) scrollTarget = sibling as HTMLElement
78 if (!ancestorOnly) {
79 const tagName = target.tagName
80 if (tagName.length === 2 && tagName[0] === 'H') {
81 const level = +tagName[1]
82 if (level >= 1 && level <= 6) {
83 let sibling = target.nextElementSibling
84
85 while (sibling) {
86 const siblingTag = sibling.tagName
87 if (
88 siblingTag.length === 2 && siblingTag[0] === 'H' &&
89 +siblingTag[1] <= level
90 ) break
91
92 if (siblingTag === 'DETAILS') {
93 ;(sibling as HTMLDetailsElement).open = true
94 if (scrollTarget === target) scrollTarget = sibling as HTMLElement
95 }
96
97 const nested = sibling.getElementsByTagName('details')
98 for (let i = 0, len = nested.length; i < len; i++) {
99 nested[i].open = true
100 if (scrollTarget === target) scrollTarget = nested[i]
101 }
102
103 sibling = sibling.nextElementSibling
94104 }
95
96 const nested = sibling.getElementsByTagName('details')
97 for (let i = 0, len = nested.length; i < len; i++) {
98 nested[i].open = true
99 if (scrollTarget === target) scrollTarget = nested[i]
100 }
101
102 sibling = sibling.nextElementSibling
103105 }
104106 }
105107 }
@@ -136,7 +138,7 @@ const tryOpenCollapsibles = async () => {
136138 const target = document.getElementById(id) || document.getElementById(hash)
137139
138140 if (target) {
139 openCollapsibles(target)
141 openCollapsibles(target, true)
140142 searchNavigated = false
141143 }
142144 })
docs/.vitepress/theme/components/Collapsible.vue +24 −1
@@ -1,11 +1,21 @@
11<script setup lang="ts">
2import { ref } from 'vue'
2import { computed, ref } from 'vue'
33
44const props = defineProps<{
55 title?: string
66}>()
77
88const open = ref(false)
9
10const headingId = computed(() =>
11 props.title
12 ? props.title
13 .toLowerCase()
14 .trim()
15 .replace(/\s+/g, '-')
16 .replace(/[^\w-]/g, '')
17 : undefined
18)
919</script>
1020
1121<template>
@@ -15,6 +25,7 @@ const open = ref(false)
1525 <span v-else class="i-iconoir-nav-arrow-right collapsible-icon" />
1626 {{ title || 'Details' }}
1727 </summary>
28 <h3 v-if="headingId" :id="headingId" class="collapsible-anchor" aria-hidden="true">{{ title }}</h3>
1829 <slot />
1930 </details>
2031</template>
@@ -37,4 +48,16 @@ summary::-webkit-details-marker {
3748 height: 1em;
3849 flex-shrink: 0;
3950}
51
52.collapsible-anchor {
53 position: absolute;
54 width: 1px;
55 height: 1px;
56 overflow: hidden;
57 clip: rect(0, 0, 0, 0);
58 white-space: nowrap;
59 border: 0;
60 margin: 0;
61 padding: 0;
62}
4063</style>
\ No newline at end of file