Commit 90a1d8537e
Unsigned
Layout: unified · split
docs/.vitepress/theme/Layout.vue +26 −28
| @@ -65,7 +65,7 @@ if (!import.meta.env.SSR) { | |||
| 65 | }) | 65 | }) |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | const openCollapsibles = (target: HTMLElement, ancestorOnly = false) => { | 68 | const openCollapsibles = (target: HTMLElement) => { |
| 69 | let scrollTarget = target | 69 | let scrollTarget = target |
| 70 | let el: HTMLElement | null = target | 70 | let el: HTMLElement | null = target |
| 71 | 71 | ||
| @@ -75,33 +75,31 @@ const openCollapsibles = (target: HTMLElement, ancestorOnly = false) => { | |||
| 75 | el = el.parentElement | 75 | el = el.parentElement |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | if (!ancestorOnly) { | 78 | const tagName = target.tagName |
| 79 | const tagName = target.tagName | 79 | if (tagName.length === 2 && tagName[0] === 'H') { |
| 80 | if (tagName.length === 2 && tagName[0] === 'H') { | 80 | const level = +tagName[1] |
| 81 | const level = +tagName[1] | 81 | if (level >= 1 && level <= 6) { |
| 82 | if (level >= 1 && level <= 6) { | 82 | let sibling = target.nextElementSibling |
| 83 | let sibling = target.nextElementSibling | 83 | |
| 84 | 84 | while (sibling) { | |
| 85 | while (sibling) { | 85 | const siblingTag = sibling.tagName |
| 86 | const siblingTag = sibling.tagName | 86 | if ( |
| 87 | if ( | 87 | siblingTag.length === 2 && siblingTag[0] === 'H' && |
| 88 | siblingTag.length === 2 && siblingTag[0] === 'H' && | 88 | +siblingTag[1] <= level |
| 89 | +siblingTag[1] <= level | 89 | ) break |
| 90 | ) break | 90 | |
| 91 | 91 | if (siblingTag === 'DETAILS') { | |
| 92 | if (siblingTag === 'DETAILS') { | 92 | ;(sibling as HTMLDetailsElement).open = true |
| 93 | ;(sibling as HTMLDetailsElement).open = true | 93 | if (scrollTarget === target) scrollTarget = sibling as HTMLElement |
| 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 | ||
| 104 | } | 94 | } |
| 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 | ||
| 105 | } | 103 | } |
| 106 | } | 104 | } |
| 107 | } | 105 | } |
| @@ -138,7 +136,7 @@ const tryOpenCollapsibles = async () => { | |||
| 138 | const target = document.getElementById(id) || document.getElementById(hash) | 136 | const target = document.getElementById(id) || document.getElementById(hash) |
| 139 | 137 | ||
| 140 | if (target) { | 138 | if (target) { |
| 141 | openCollapsibles(target, true) | 139 | openCollapsibles(target) |
| 142 | searchNavigated = false | 140 | searchNavigated = false |
| 143 | } | 141 | } |
| 144 | }) | 142 | }) |
docs/.vitepress/theme/components/Collapsible.vue +1 −24
| @@ -1,21 +1,11 @@ | |||
| 1 | <script setup lang="ts"> | 1 | <script setup lang="ts"> |
| 2 | import { computed, ref } from 'vue' | 2 | import { ref } from 'vue' |
| 3 | 3 | ||
| 4 | const props = defineProps<{ | 4 | const props = defineProps<{ |
| 5 | title?: string | 5 | title?: string |
| 6 | }>() | 6 | }>() |
| 7 | 7 | ||
| 8 | const open = ref(false) | 8 | const open = ref(false) |
| 9 | |||
| 10 | const headingId = computed(() => | ||
| 11 | props.title | ||
| 12 | ? props.title | ||
| 13 | .toLowerCase() | ||
| 14 | .trim() | ||
| 15 | .replace(/\s+/g, '-') | ||
| 16 | .replace(/[^\w-]/g, '') | ||
| 17 | : undefined | ||
| 18 | ) | ||
| 19 | </script> | 9 | </script> |
| 20 | 10 | ||
| 21 | <template> | 11 | <template> |
| @@ -25,7 +15,6 @@ const headingId = computed(() => | |||
| 25 | <span v-else class="i-iconoir-nav-arrow-right collapsible-icon" /> | 15 | <span v-else class="i-iconoir-nav-arrow-right collapsible-icon" /> |
| 26 | {{ title || 'Details' }} | 16 | {{ title || 'Details' }} |
| 27 | </summary> | 17 | </summary> |
| 28 | <h3 v-if="headingId" :id="headingId" class="collapsible-anchor" aria-hidden="true">{{ title }}</h3> | ||
| 29 | <slot /> | 18 | <slot /> |
| 30 | </details> | 19 | </details> |
| 31 | </template> | 20 | </template> |
| @@ -48,16 +37,4 @@ summary::-webkit-details-marker { | |||
| 48 | height: 1em; | 37 | height: 1em; |
| 49 | flex-shrink: 0; | 38 | flex-shrink: 0; |
| 50 | } | 39 | } |
| 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 | } | ||
| 63 | </style>\ No newline at end of file | 40 | </style>\ No newline at end of file |