Commit 49d0900bcc

49d0900bcc0ebff8bae8207d42986611be60f0af

parent: 1b82d38766

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-09-19 12:16 UTC

init

Layout: unified · split

docs/.vitepress/configs/markdown/index.ts +3 −3
@@ -28,6 +28,7 @@ import { extRepoPlugin } from './extRepoPlugin'
28import { nestedContainersPlugin } from './nestedContainers' 28import { nestedContainersPlugin } from './nestedContainers'
29import { scrapeTablePlugin } from './scrapeTablePlugin' 29import { scrapeTablePlugin } from './scrapeTablePlugin'
30import markdownSteps from './steps' 30import markdownSteps from './steps'
31import { tableMorePlugin } from './tableMore'
31import { tabsMarkdownPlugin } from './tabs' 32import { tabsMarkdownPlugin } from './tabs'
32 33
33export function configureMarkdown(md: MarkdownRenderer) { 34export function configureMarkdown(md: MarkdownRenderer) {
@@ -50,6 +51,7 @@ export function configureMarkdown(md: MarkdownRenderer) {
50 renderTooltip(md) 51 renderTooltip(md)
51 renderInlineTooltip(md) 52 renderInlineTooltip(md)
52 md.use(markdownSteps) 53 md.use(markdownSteps)
54 md.use(tableMorePlugin)
53 md.use(scrapeTablePlugin) 55 md.use(scrapeTablePlugin)
54 md.use(extRepoPlugin) 56 md.use(extRepoPlugin)
55 renderHighlight(md) 57 renderHighlight(md)
@@ -260,9 +262,7 @@ function injectSearchHeadings(src: string) {
260 i + 1, 262 i + 1,
261 0, 263 0,
262 '', 264 '',
263 `${indent}${ 265 `${indent}${'#'.repeat(headingLevel)} ${headingTitle} {#${
264 '#'.repeat(headingLevel)
265 } ${headingTitle} {#${
266 getCollapsibleHeadingAnchor(collapsibleAnchor) 266 getCollapsibleHeadingAnchor(collapsibleAnchor)
267 } .collapsible-search-heading}`, 267 } .collapsible-search-heading}`,
268 '' 268 ''
docs/.vitepress/configs/markdown/tableMore.ts added +336
@@ -0,0 +1,336 @@
1import type MarkdownIt from 'markdown-it'
2
3const MARKER_RE = /^<more\s*\/?>$/i
4
5const ROW_TOKEN_TYPES = new Set([
6 'tr_open',
7 'tr_close',
8 'td_open',
9 'td_close',
10 'th_open',
11 'th_close',
12 'inline'
13])
14
15function buildToggleHtml(cols: number): string {
16 return `<tbody class="table-more-toggle">\n` +
17 `<tr class="table-more-toggle-row">\n` +
18 `<td colspan="${cols}">\n` +
19 `<label class="table-more-label">\n` +
20 `<input type="checkbox" class="table-more-checkbox" aria-label="Toggle more rows">\n` +
21 `<span class="table-more-text table-more-text--more">Show more</span>\n` +
22 `<span class="table-more-text table-more-text--less">Show less</span>\n` +
23 `<span class="table-more-icon i-mdi-chevron-down" aria-hidden="true"></span>\n` +
24 `</label>\n</td>\n</tr>\n</tbody>\n`
25}
26
27function getLine(state: any, n: number): string {
28 return state.src.slice(
29 state.bMarks[n] + state.tShift[n],
30 state.eMarks[n]
31 )
32}
33
34function isPipeLine(line: string): boolean {
35 return line.trim().startsWith('|')
36}
37
38function splitCells(line: string): string[] {
39 let s = line.trim()
40 if (s.startsWith('|')) s = s.slice(1)
41 if (s.endsWith('|') && !s.endsWith('\\|')) s = s.slice(0, -1)
42 return s.split(/(?<!\\)\|/).map((c) =>
43 c.replace(/\\\|/g, '|').replace(/\\\\/g, '\\')
44 )
45}
46
47function isDelimiterRow(line: string): boolean {
48 const cells = splitCells(line)
49 return cells.length > 0 &&
50 cells.every((c) => /^:?-+:?$/.test(c.trim()))
51}
52
53function findTableClose(tokens: any[], from: number): number {
54 let depth = 0
55 for (let j = from; j < tokens.length; j++) {
56 if (tokens[j].type === 'table_open') depth++
57 else if (tokens[j].type === 'table_close') {
58 depth--
59 if (depth === 0) return j
60 }
61 }
62 return -1
63}
64
65function countCells(
66 tokens: any[],
67 from: number,
68 to: number,
69 type: string
70): number {
71 let count = 0
72 for (let k = from; k < to; k++) {
73 if (tokens[k].type === type) count++
74 }
75 return count
76}
77
78function findTableOpen(tokens: any[], tableCloseIdx: number): number {
79 let depth = 0
80 for (let k = tableCloseIdx; k >= 0; k--) {
81 if (tokens[k].type === 'table_close') depth++
82 else if (tokens[k].type === 'table_open') {
83 if (depth <= 1) return k
84 depth--
85 }
86 }
87 return -1
88}
89
90function countTableCols(tokens: any[], tableCloseIdx: number): number {
91 const openIdx = findTableOpen(tokens, tableCloseIdx)
92 if (openIdx === -1) return 0
93 let theadOpen = -1
94 let theadClose = -1
95 for (let k = openIdx; k < tableCloseIdx; k++) {
96 if (tokens[k].type === 'thead_open' && theadOpen === -1) {
97 theadOpen = k
98 }
99 if (tokens[k].type === 'thead_close') {
100 theadClose = k
101 break
102 }
103 }
104 if (theadOpen !== -1 && theadClose !== -1) {
105 return countCells(tokens, theadOpen, theadClose, 'th_open')
106 }
107 return 0
108}
109
110function stampTableAnchor(state: any, tokens: any[], tableCloseIdx: number) {
111 const openIdx = findTableOpen(tokens, tableCloseIdx)
112 if (openIdx === -1) return
113 state.env.__tableMoreCount = (state.env.__tableMoreCount ?? 0) + 1
114 tokens[openIdx].attrJoin(
115 'data-table-more',
116 `table-more-${state.env.__tableMoreCount}`
117 )
118}
119
120export function tableMorePlugin(md: MarkdownIt): void {
121 md.block.ruler.before(
122 'html_block',
123 'table_more_marker',
124 (state, startLine, endLine, silent) => {
125 const pos = state.bMarks[startLine] + state.tShift[startLine]
126 const max = state.eMarks[startLine]
127 if (!MARKER_RE.test(state.src.slice(pos, max).trim())) {
128 return false
129 }
130 // Only a marker directly after a table; otherwise literal text.
131 const prev = state.tokens[state.tokens.length - 1]
132 if (!prev || prev.type !== 'table_close') return false
133 if (silent) return true
134
135 // Full table follows: let the table parser handle it, merge later.
136 const next1 = startLine + 1 < endLine
137 ? getLine(state, startLine + 1)
138 : ''
139 const next2 = startLine + 2 < endLine
140 ? getLine(state, startLine + 2)
141 : ''
142 const fullTableFollows = isPipeLine(next1) && isDelimiterRow(next2)
143
144 const marker = state.push('table_more', '', 0)
145 marker.map = [startLine, startLine + 1]
146 marker.content = ''
147
148 if (fullTableFollows) {
149 state.line = startLine + 1
150 return true
151 }
152
153 // Else consume pipe rows as bare continuation rows (no header needed).
154 let line = startLine + 1
155 let rows = 0
156 while (line < endLine && isPipeLine(getLine(state, line))) {
157 const cells = splitCells(getLine(state, line))
158 const trOpen = state.push('tr_open', 'tr', 1)
159 trOpen.map = [line, line + 1]
160 let openTd: any = null
161 let span = 1
162 const flush = () => {
163 if (openTd && span > 1) openTd.attrJoin('colspan', String(span))
164 openTd = null
165 span = 1
166 }
167 for (const raw of cells) {
168 if (raw === '' && openTd) {
169 span++
170 continue
171 }
172 flush()
173 const td = state.push('td_open', 'td', 1)
174 td.attrs = []
175 const inline = state.push('inline', '', 0)
176 inline.content = raw.trim()
177 inline.map = [line, line + 1]
178 inline.children = []
179 state.push('td_close', 'td', -1)
180 openTd = td
181 }
182 flush()
183 state.push('tr_close', 'tr', -1)
184 rows++
185 line++
186 }
187
188 if (rows > 0) {
189 const closer = state.push('html_block', '', 0)
190 closer.map = [line, line]
191 closer.content = '</tbody>\n'
192 }
193 state.line = line
194 return true
195 }
196 )
197
198 // Unmatched markers (no second table) render as nothing.
199 md.renderer.rules.table_more = () => ''
200
201 md.core.ruler.after('block', 'table_more_merge', (state: any) => {
202 const tokens = state.tokens as any[]
203 let i = 0
204 while (i < tokens.length) {
205 if (
206 tokens[i].type !== 'table_close' ||
207 tokens[i + 1]?.type !== 'table_more'
208 ) {
209 i++
210 continue
211 }
212
213 // full second table follows the marker.
214 if (tokens[i + 2]?.type === 'table_open') {
215 const openIdx = i + 2
216 const closeIdx = findTableClose(tokens, openIdx)
217 if (closeIdx === -1) {
218 i++
219 continue
220 }
221
222 let theadOpen = -1
223 let theadClose = -1
224 for (let k = openIdx; k < closeIdx; k++) {
225 if (tokens[k].type === 'thead_open' && theadOpen === -1) {
226 theadOpen = k
227 }
228 if (tokens[k].type === 'thead_close') {
229 theadClose = k
230 break
231 }
232 }
233 const bodyStart = theadClose !== -1 ? theadClose + 1 : openIdx + 1
234 const kept = tokens.slice(bodyStart, closeIdx)
235
236 let cols = theadOpen !== -1 && theadClose !== -1
237 ? countCells(tokens, theadOpen, theadClose, 'th_open')
238 : 0
239 if (cols <= 0) cols = countTableCols(tokens, i)
240 if (cols <= 0) cols = 1
241
242 const hidden = kept.filter((t) => t.type === 'tr_open').length
243 if (hidden === 0) {
244 i = closeIdx + 1
245 continue
246 }
247
248 for (const t of kept) {
249 if (t.type === 'tbody_open') t.attrJoin('class', 'table-more-hidden')
250 }
251
252 stampTableAnchor(state, tokens, i)
253
254 // Toggle + hidden rows go inside the first table, before its close.
255 const marker = tokens[i + 1]
256 marker.type = 'html_block'
257 marker.tag = ''
258 marker.nesting = 0
259 marker.attrs = null
260 marker.children = null
261 marker.info = ''
262 marker.markup = ''
263 marker.content = buildToggleHtml(cols)
264
265 const merged = tokens.slice(0, i)
266 merged.push(marker)
267 merged.push(...kept)
268 merged.push(tokens[i])
269 merged.push(...tokens.slice(closeIdx + 1))
270 tokens.splice(0, tokens.length, ...merged)
271 i += 2 + kept.length
272 continue
273 }
274
275 // bare continuation rows follow the marker.
276 if (tokens[i + 2]?.type === 'tr_open') {
277 let j = i + 2
278 while (j < tokens.length && ROW_TOKEN_TYPES.has(tokens[j].type)) j++
279 const closer = tokens[j]
280 if (
281 !closer || closer.type !== 'html_block' ||
282 !closer.content.includes('</tbody>')
283 ) {
284 i++
285 continue
286 }
287 const kept = tokens.slice(i + 2, j)
288 const hidden = kept.filter((t) => t.type === 'tr_open').length
289 if (hidden === 0) {
290 tokens.splice(i + 1, j - i)
291 continue
292 }
293
294 let cols = countTableCols(tokens, i)
295 if (cols <= 0) {
296 const firstTr = kept.findIndex((t) => t.type === 'tr_open')
297 const end = kept.findIndex(
298 (t, idx) => idx > firstTr && t.type === 'tr_close'
299 )
300 cols = countCells(
301 kept,
302 firstTr,
303 end === -1 ? kept.length : end,
304 'td_open'
305 )
306 }
307 if (cols <= 0) cols = 1
308
309 stampTableAnchor(state, tokens, i)
310
311 const marker = tokens[i + 1]
312 marker.type = 'html_block'
313 marker.tag = ''
314 marker.nesting = 0
315 marker.attrs = null
316 marker.children = null
317 marker.info = ''
318 marker.markup = ''
319 marker.content = buildToggleHtml(cols) +
320 '<tbody class="table-more-hidden">\n'
321
322 // Move the toggle + bare rows inside the first table.
323 const segment = tokens.slice(i + 1, j + 1)
324 const merged = tokens.slice(0, i)
325 merged.push(...segment)
326 merged.push(tokens[i])
327 merged.push(...tokens.slice(j + 1))
328 tokens.splice(0, tokens.length, ...merged)
329 i += segment.length + 1
330 continue
331 }
332
333 i++
334 }
335 })
336}
docs/.vitepress/theme/Layout.vue +294 −92
@@ -6,11 +6,7 @@
6 All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder. 6 All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
7--> 7-->
8<script setup lang="ts"> 8<script setup lang="ts">
9import { 9import { useEventListener, useStorage, useThrottleFn } from '@vueuse/core'
10 useEventListener,
11 useStorage,
12 useThrottleFn
13} from '@vueuse/core'
14import { getScrollOffset, useData, useRoute } from 'vitepress' 10import { getScrollOffset, useData, useRoute } from 'vitepress'
15import type { DefaultTheme as Theme } from 'vitepress' 11import type { DefaultTheme as Theme } from 'vitepress'
16import VPSidebarGroup from 'vitepress/dist/client/theme-default/components/VPSidebarGroup.vue' 12import VPSidebarGroup from 'vitepress/dist/client/theme-default/components/VPSidebarGroup.vue'
@@ -26,16 +22,24 @@ import {
26 watchEffect 22 watchEffect
27} from 'vue' 23} from 'vue'
28import { sidebar } from '../configs/constants' 24import { sidebar } from '../configs/constants'
29import { useBookmarks, BOOKMARK_CHANGE_EVENT } from './composables/useBookmarks'
30import AnnouncementPill from './components/AnnouncementPill.vue' 25import AnnouncementPill from './components/AnnouncementPill.vue'
31import SiteFooter from './components/SiteFooter.vue' 26import NavActions from './components/NavActions.vue'
32import NotFoundComponent from './components/NotFound.vue' 27import NotFoundComponent from './components/NotFound.vue'
33import { NolebaseEnhancedReadabilitiesScreenMenu } from './components/settings' 28import { NolebaseEnhancedReadabilitiesScreenMenu } from './components/settings'
34import NavActions from './components/NavActions.vue'
35import SidebarCard from './components/SidebarCard.vue' 29import SidebarCard from './components/SidebarCard.vue'
36import { AccentBgStorageKey, AccentBgStrengthStorageKey, AccentColorStorageKey } from './constants' 30import SiteFooter from './components/SiteFooter.vue'
31import { BOOKMARK_CHANGE_EVENT, useBookmarks } from './composables/useBookmarks'
37import { useEffects } from './composables/useEffects' 32import { useEffects } from './composables/useEffects'
38import { applyFavicons, removeFavicons, useFavicons } from './composables/useFavicons' 33import {
34 applyFavicons,
35 removeFavicons,
36 useFavicons
37} from './composables/useFavicons'
38import {
39 AccentBgStorageKey,
40 AccentBgStrengthStorageKey,
41 AccentColorStorageKey
42} from './constants'
39import { searchResultHighlightMode } from './searchState' 43import { searchResultHighlightMode } from './searchState'
40 44
41const route = useRoute() 45const route = useRoute()
@@ -84,6 +88,12 @@ if (!import.meta.env.SSR) {
84 if (target) { 88 if (target) {
85 void nextTick(() => { 89 void nextTick(() => {
86 if (searchNavigated) { 90 if (searchNavigated) {
91 scanSectionForTerms(
92 target,
93 getSearchTerms(searchQuery),
94 () => {},
95 expandTableMoreEl
96 )
87 highlightSearchResult(target) 97 highlightSearchResult(target)
88 resetSearchNavigation() 98 resetSearchNavigation()
89 } 99 }
@@ -99,6 +109,12 @@ if (!import.meta.env.SSR) {
99 if (!currentHash) return 109 if (!currentHash) return
100 const target = getTargetByHash(currentHash) 110 const target = getTargetByHash(currentHash)
101 if (target) { 111 if (target) {
112 scanSectionForTerms(
113 target,
114 getSearchTerms(searchQuery),
115 () => {},
116 expandTableMoreEl
117 )
102 highlightSearchResult(target) 118 highlightSearchResult(target)
103 resetSearchNavigation() 119 resetSearchNavigation()
104 } else if (attempts < 15) { 120 } else if (attempts < 15) {
@@ -131,7 +147,6 @@ const removeSearchResultHighlights = () => {
131 ) 147 )
132} 148}
133 149
134
135let highlightTerm = '' 150let highlightTerm = ''
136let highlightTabPath: string[] | null = null 151let highlightTabPath: string[] | null = null
137 152
@@ -164,7 +179,9 @@ const applyHighlightWithin = (root: HTMLElement, term: string) => {
164 const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, { 179 const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
165 acceptNode(node) { 180 acceptNode(node) {
166 const parent = node.parentElement 181 const parent = node.parentElement
167 if (!parent || parent.closest('.search-result-highlight, script, style')) { 182 if (
183 !parent || parent.closest('.search-result-highlight, script, style')
184 ) {
168 return NodeFilter.FILTER_REJECT 185 return NodeFilter.FILTER_REJECT
169 } 186 }
170 return NodeFilter.FILTER_ACCEPT 187 return NodeFilter.FILTER_ACCEPT
@@ -225,7 +242,7 @@ const highlightSearchResult = (target?: HTMLElement) => {
225 ) 242 )
226 highlightTabPath = panel ? getPanelTabPath(panel) : null 243 highlightTabPath = panel ? getPanelTabPath(panel) : null
227 highlightTerm = term 244 highlightTerm = term
228 245
229 if (!applyHighlightWithin(target, term)) { 246 if (!applyHighlightWithin(target, term)) {
230 const docRoot = document.querySelector<HTMLElement>('.VPDoc .vp-doc') 247 const docRoot = document.querySelector<HTMLElement>('.VPDoc .vp-doc')
231 if (docRoot) { 248 if (docRoot) {
@@ -271,6 +288,7 @@ const getScrollTargetForAnchor = (target: HTMLElement) => {
271 288
272const TAB_QUERY_PARAM = 't' 289const TAB_QUERY_PARAM = 't'
273const COLLAPSIBLE_QUERY_PARAM = 'c' 290const COLLAPSIBLE_QUERY_PARAM = 'c'
291const TABLE_MORE_QUERY_PARAM = 'm'
274 292
275const getRequestedAnchorPath = (param: string) => { 293const getRequestedAnchorPath = (param: string) => {
276 const value = new URLSearchParams(window.location.search).get(param) 294 const value = new URLSearchParams(window.location.search).get(param)
@@ -283,29 +301,43 @@ const getRequestedAnchorPath = (param: string) => {
283const getRequestedTabPath = () => getRequestedAnchorPath(TAB_QUERY_PARAM) 301const getRequestedTabPath = () => getRequestedAnchorPath(TAB_QUERY_PARAM)
284const getRequestedCollapsiblePath = () => 302const getRequestedCollapsiblePath = () =>
285 getRequestedAnchorPath(COLLAPSIBLE_QUERY_PARAM) 303 getRequestedAnchorPath(COLLAPSIBLE_QUERY_PARAM)
304const getRequestedTableMorePath = () =>
305 getRequestedAnchorPath(TABLE_MORE_QUERY_PARAM)
286 306
287const encodeAnchorList = (anchors: string[]) => 307const encodeAnchorList = (anchors: string[]) =>
288 anchors.map((anchor) => encodeURIComponent(anchor)).join(',') 308 anchors.map((anchor) => encodeURIComponent(anchor)).join(',')
289 309
290const buildUrl = ( 310const buildUrl = (
291 options: { tabs?: string[]; collapsibles?: string[]; hash?: string } = {} 311 options: {
312 tabs?: string[]
313 collapsibles?: string[]
314 tables?: string[]
315 hash?: string
316 } = {}
292) => { 317) => {
293 const params = new URLSearchParams(window.location.search) 318 const params = new URLSearchParams(window.location.search)
294 const currentTabs = params.get(TAB_QUERY_PARAM) 319 const currentTabs = params.get(TAB_QUERY_PARAM)
295 const currentCollapsibles = params.get(COLLAPSIBLE_QUERY_PARAM) 320 const currentCollapsibles = params.get(COLLAPSIBLE_QUERY_PARAM)
321 const currentTables = params.get(TABLE_MORE_QUERY_PARAM)
296 params.delete(TAB_QUERY_PARAM) 322 params.delete(TAB_QUERY_PARAM)
297 params.delete(COLLAPSIBLE_QUERY_PARAM) 323 params.delete(COLLAPSIBLE_QUERY_PARAM)
324 params.delete(TABLE_MORE_QUERY_PARAM)
298 325
299 const tabs = options.tabs ?? 326 const tabs = options.tabs ??
300 (currentTabs ? currentTabs.split(',').filter(Boolean) : []) 327 (currentTabs ? currentTabs.split(',').filter(Boolean) : [])
301 const collapsibles = options.collapsibles ?? 328 const collapsibles = options.collapsibles ??
302 (currentCollapsibles ? currentCollapsibles.split(',').filter(Boolean) : []) 329 (currentCollapsibles ? currentCollapsibles.split(',').filter(Boolean) : [])
330 const tables = options.tables ??
331 (currentTables ? currentTables.split(',').filter(Boolean) : [])
303 332
304 const queryParts = [ 333 const queryParts = [
305 params.toString(), 334 params.toString(),
306 tabs.length ? `${TAB_QUERY_PARAM}=${encodeAnchorList(tabs)}` : '', 335 tabs.length ? `${TAB_QUERY_PARAM}=${encodeAnchorList(tabs)}` : '',
307 collapsibles.length 336 collapsibles.length
308 ? `${COLLAPSIBLE_QUERY_PARAM}=${encodeAnchorList(collapsibles)}` 337 ? `${COLLAPSIBLE_QUERY_PARAM}=${encodeAnchorList(collapsibles)}`
338 : '',
339 tables.length
340 ? `${TABLE_MORE_QUERY_PARAM}=${encodeAnchorList(tables)}`
309 : '' 341 : ''
310 ].filter(Boolean) 342 ].filter(Boolean)
311 343
@@ -374,6 +406,73 @@ const queueTabQueryUpdateForSelection = (target: EventTarget | null) => {
374 406
375const COLLAPSIBLE_SELECTOR = 'details[data-collapsible-anchor]' 407const COLLAPSIBLE_SELECTOR = 'details[data-collapsible-anchor]'
376 408
409const detailsContainsTerms = (d: HTMLElement, terms: string[]) => {
410 if (!terms.length) return false
411 const text = (d.textContent ?? '').toLowerCase()
412 return terms.every((term) => text.includes(term))
413}
414
415// Expand tables whose hidden rows hold all searched terms.
416const tableContainsTerms = (t: HTMLElement, terms: string[]) => {
417 if (!terms.length) return false
418 const hidden = t.querySelector('tbody.table-more-hidden')
419 const text = ((hidden ?? t).textContent ?? '').toLowerCase()
420 return terms.every((term) => text.includes(term))
421}
422
423const expandTableMoreEl = (t: HTMLElement) => {
424 const box = getTableMoreCheckbox(t)
425 if (box && !box.checked) box.checked = true
426}
427
428const scanSectionForTerms = (
429 target: HTMLElement,
430 terms: string[],
431 onDetails: (d: HTMLElement) => void,
432 onTable: (t: HTMLElement) => void
433) => {
434 const tagName = target.tagName
435 if (tagName.length !== 2 || tagName[0] !== 'H') return
436 const level = +tagName[1]
437 if (level < 1 || level > 6 || !terms.length) return
438
439 let sibling = target.nextElementSibling
440
441 while (sibling) {
442 const siblingTag = sibling.tagName
443 if (
444 siblingTag.length === 2 && siblingTag[0] === 'H' &&
445 +siblingTag[1] <= level
446 ) break
447
448 if (siblingTag === 'DETAILS') {
449 if (detailsContainsTerms(sibling as HTMLElement, terms)) {
450 onDetails(sibling as HTMLElement)
451 }
452 }
453
454 const nested = sibling.getElementsByTagName('details')
455 for (let i = 0, len = nested.length; i < len; i++) {
456 if (detailsContainsTerms(nested[i], terms)) onDetails(nested[i])
457 }
458
459 if (siblingTag === 'TABLE') {
460 if (tableContainsTerms(sibling as HTMLElement, terms)) {
461 onTable(sibling as HTMLElement)
462 }
463 }
464
465 const nestedTables = sibling.getElementsByTagName('table')
466 for (let i = 0, len = nestedTables.length; i < len; i++) {
467 if (tableContainsTerms(nestedTables[i], terms)) {
468 onTable(nestedTables[i])
469 }
470 }
471
472 sibling = sibling.nextElementSibling
473 }
474}
475
377const getOpenCollapsiblePath = (details: HTMLElement) => { 476const getOpenCollapsiblePath = (details: HTMLElement) => {
378 const path: string[] = [] 477 const path: string[] = []
379 let el: HTMLElement | null = details 478 let el: HTMLElement | null = details
@@ -430,6 +529,34 @@ const queueCollapsibleQueryUpdate = (target: EventTarget | null) => {
430 } 529 }
431} 530}
432 531
532const updateQueryForTableMore = async (table: HTMLElement) => {
533 await nextTick()
534 await nextFrame()
535
536 const tables = getOpenTableMorePath()
537 const tabPath = getEnclosingTabPath(table)
538
539 const nextUrl = buildUrl({
540 tabs: tabPath.length ? tabPath : undefined,
541 tables
542 })
543 const currentUrl =
544 `${window.location.pathname}${window.location.search}${window.location.hash}`
545 if (nextUrl === currentUrl) return
546
547 window.history.pushState(null, '', nextUrl)
548 rewriteAnchorLinks()
549}
550
551const queueTableMoreQueryUpdate = (target: EventTarget | null) => {
552 if (!(target instanceof HTMLElement)) return
553
554 const box = target.closest<HTMLInputElement>('.table-more-checkbox')
555 if (!box) return
556 const table = box.closest<HTMLElement>('table')
557 if (table) void updateQueryForTableMore(table)
558}
559
433const selectCollapsiblesByPath = async (collapsiblePath: string[]) => { 560const selectCollapsiblesByPath = async (collapsiblePath: string[]) => {
434 let root: ParentNode = document 561 let root: ParentNode = document
435 let opened: HTMLElement | undefined 562 let opened: HTMLElement | undefined
@@ -453,6 +580,45 @@ const selectCollapsiblesByPath = async (collapsiblePath: string[]) => {
453 return opened 580 return opened
454} 581}
455 582
583const TABLE_MORE_SELECTOR = 'table[data-table-more]'
584
585const getTableMoreCheckbox = (table: HTMLElement) =>
586 table.querySelector<HTMLInputElement>('.table-more-checkbox')
587
588const selectTablesByPath = async (anchors: string[]) => {
589 let opened: HTMLTableElement | undefined
590
591 for (const anchor of anchors) {
592 const table = document.querySelector<HTMLTableElement>(
593 `table[data-table-more="${CSS.escape(anchor)}"]`
594 )
595 if (!table) continue
596
597 const box = getTableMoreCheckbox(table)
598 if (box && !box.checked) {
599 box.checked = true
600 await nextTick()
601 await nextFrame()
602 }
603 opened = table
604 }
605
606 return opened
607}
608
609const getOpenTableMorePath = () => {
610 const anchors: string[] = []
611 document.querySelectorAll<HTMLTableElement>(TABLE_MORE_SELECTOR).forEach(
612 (table) => {
613 if (getTableMoreCheckbox(table)?.checked) {
614 const anchor = table.dataset.tableMore
615 if (anchor) anchors.push(anchor)
616 }
617 }
618 )
619 return anchors
620}
621
456const TAB_LINK_MARKER = 'tab-' 622const TAB_LINK_MARKER = 'tab-'
457 623
458const rewriteAnchorLinks = () => { 624const rewriteAnchorLinks = () => {
@@ -585,44 +751,19 @@ const openCollapsibles = async (target: HTMLElement) => {
585 751
586 const tagName = activeTarget.tagName 752 const tagName = activeTarget.tagName
587 if (tagName.length === 2 && tagName[0] === 'H') { 753 if (tagName.length === 2 && tagName[0] === 'H') {
588 const level = +tagName[1] 754 const terms = getSearchTerms(searchQuery)
589 if (level >= 1 && level <= 6) { 755 scanSectionForTerms(
590 const terms = getSearchTerms(searchQuery) 756 activeTarget,
591 const detailsContainsTerms = (d: HTMLElement) => { 757 terms,
592 if (!terms.length) return false 758 (d) => {
593 const text = (d.textContent ?? '').toLowerCase() 759 ;(d as HTMLDetailsElement).open = true
594 return terms.every((term) => text.includes(term)) 760 if (scrollTarget === activeTarget) scrollTarget = d
595 } 761 },
596 762 (t) => {
597 let sibling = activeTarget.nextElementSibling 763 expandTableMoreEl(t)
598 764 if (scrollTarget === activeTarget) scrollTarget = t
599 while (sibling) {
600 const siblingTag = sibling.tagName
601 if (
602 siblingTag.length === 2 && siblingTag[0] === 'H' &&
603 +siblingTag[1] <= level
604 ) break
605
606 if (siblingTag === 'DETAILS') {
607 if (detailsContainsTerms(sibling as HTMLElement)) {
608 ;(sibling as HTMLDetailsElement).open = true
609 if (scrollTarget === activeTarget) {
610 scrollTarget = sibling as HTMLElement
611 }
612 }
613 }
614
615 const nested = sibling.getElementsByTagName('details')
616 for (let i = 0, len = nested.length; i < len; i++) {
617 if (detailsContainsTerms(nested[i])) {
618 nested[i].open = true
619 if (scrollTarget === activeTarget) scrollTarget = nested[i]
620 }
621 }
622
623 sibling = sibling.nextElementSibling
624 } 765 }
625 } 766 )
626 } 767 }
627 768
628 await nextTick() 769 await nextTick()
@@ -649,6 +790,10 @@ const tryOpenAnchoredContent = async () => {
649 const openedCollapsible = requestedCollapsibles.length 790 const openedCollapsible = requestedCollapsibles.length
650 ? await selectCollapsiblesByPath(requestedCollapsibles) 791 ? await selectCollapsiblesByPath(requestedCollapsibles)
651 : undefined 792 : undefined
793 const requestedTables = getRequestedTableMorePath()
794 const openedTable = requestedTables.length
795 ? await selectTablesByPath(requestedTables)
796 : undefined
652 const hash = window.location.hash.slice(1) 797 const hash = window.location.hash.slice(1)
653 798
654 if (!hash) { 799 if (!hash) {
@@ -662,6 +807,8 @@ const tryOpenAnchoredContent = async () => {
662 scrollToElement(openedCollapsible, false) 807 scrollToElement(openedCollapsible, false)
663 } else if (selectedTabs) { 808 } else if (selectedTabs) {
664 scrollToElement(getSelectedTabScrollTarget(selectedTabs), false) 809 scrollToElement(getSelectedTabScrollTarget(selectedTabs), false)
810 } else if (openedTable) {
811 scrollToElement(openedTable, false)
665 } 812 }
666 return 813 return
667 } 814 }
@@ -686,14 +833,16 @@ const tryOpenAnchoredContent = async () => {
686 await openCollapsibles(target) 833 await openCollapsibles(target)
687 highlightSearchResult(target) 834 highlightSearchResult(target)
688 const collapsiblePath = getOpenCollapsiblePath(target) 835 const collapsiblePath = getOpenCollapsiblePath(target)
689 if (collapsiblePath.length) { 836 const tablePath = getOpenTableMorePath()
837 if (collapsiblePath.length || tablePath.length) {
690 const tabPath = getEnclosingTabPath(target) 838 const tabPath = getEnclosingTabPath(target)
691 window.history.replaceState( 839 window.history.replaceState(
692 null, 840 null,
693 '', 841 '',
694 buildUrl({ 842 buildUrl({
695 tabs: tabPath.length ? tabPath : undefined, 843 tabs: tabPath.length ? tabPath : undefined,
696 collapsibles: collapsiblePath 844 collapsibles: collapsiblePath,
845 tables: tablePath
697 }) 846 })
698 ) 847 )
699 rewriteAnchorLinks() 848 rewriteAnchorLinks()
@@ -833,7 +982,8 @@ const setupOutlineFollow = () => {
833 followActiveOutlineLink() 982 followActiveOutlineLink()
834} 983}
835 984
836const BOOKMARK_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"/></svg>` 985const BOOKMARK_SVG =
986 `<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"/></svg>`
837 987
838function syncTocBookmarkStates() { 988function syncTocBookmarkStates() {
839 const path = route.path 989 const path = route.path
@@ -877,14 +1027,20 @@ let tocRaf = 0
877 1027
878function scanTocItems(path: string) { 1028function scanTocItems(path: string) {
879 // Desktop sidebar — VPDocOutlineItem is called with :root="true" 1029 // Desktop sidebar — VPDocOutlineItem is called with :root="true"
880 document.querySelectorAll<HTMLElement>('.VPDocOutlineItem.root > li').forEach(li => addBookmarkBtnToLi(li, path)) 1030 document.querySelectorAll<HTMLElement>('.VPDocOutlineItem.root > li').forEach(
1031 li => addBookmarkBtnToLi(li, path)
1032 )
881 // Mobile dropdown — VPDocOutlineItem is called without root prop, so the ul gets class "nested" 1033 // Mobile dropdown — VPDocOutlineItem is called without root prop, so the ul gets class "nested"
882 document.querySelectorAll<HTMLElement>('.VPLocalNavOutlineDropdown .outline > .VPDocOutlineItem > li').forEach(li => addBookmarkBtnToLi(li, path)) 1034 document.querySelectorAll<HTMLElement>(
1035 '.VPLocalNavOutlineDropdown .outline > .VPDocOutlineItem > li'
1036 ).forEach(li => addBookmarkBtnToLi(li, path))
883} 1037}
884 1038
885function setupTocBookmarks() { 1039function setupTocBookmarks() {
886 const path = route.path 1040 const path = route.path
887 document.querySelectorAll<HTMLElement>('.toc-bookmark-btn').forEach(btn => btn.remove()) 1041 document.querySelectorAll<HTMLElement>('.toc-bookmark-btn').forEach(btn =>
1042 btn.remove()
1043 )
888 scanTocItems(path) 1044 scanTocItems(path)
889 1045
890 // Mobile dropdown items are v-if rendered on open — watch for them being added 1046 // Mobile dropdown items are v-if rendered on open — watch for them being added
@@ -903,7 +1059,9 @@ onMounted(tryOpenAnchoredContent)
903onMounted(rewriteAnchorLinksDeferred) 1059onMounted(rewriteAnchorLinksDeferred)
904onMounted(() => nextTick(setupOutlineFollow)) 1060onMounted(() => nextTick(setupOutlineFollow))
905onMounted(() => nextTick(setupTocBookmarks)) 1061onMounted(() => nextTick(setupTocBookmarks))
906onMounted(() => window.addEventListener('scroll', onMobileOutlineScroll, { passive: true })) 1062onMounted(() =>
1063 window.addEventListener('scroll', onMobileOutlineScroll, { passive: true })
1064)
907onUnmounted(() => window.removeEventListener('scroll', onMobileOutlineScroll)) 1065onUnmounted(() => window.removeEventListener('scroll', onMobileOutlineScroll))
908watch(() => route.data, () => { 1066watch(() => route.data, () => {
909 void tryOpenAnchoredContent() 1067 void tryOpenAnchoredContent()
@@ -987,7 +1145,10 @@ watch(faviconsEnabled, (enabled) => {
987 1145
988watch( 1146watch(
989 () => route.path, 1147 () => route.path,
990 () => nextTick(() => { if (faviconsEnabled.value) applyFavicons(document) }), 1148 () =>
1149 nextTick(() => {
1150 if (faviconsEnabled.value) applyFavicons(document)
1151 }),
991 { flush: 'post' } 1152 { flush: 'post' }
992) 1153)
993 1154
@@ -1000,56 +1161,56 @@ const accentPalettes: Record<string, PaletteEntry> = {
1000 500: 'oklch(0.626 0.098 247.46)', 1161 500: 'oklch(0.626 0.098 247.46)',
1001 600: 'oklch(0.523 0.081 246.86)', 1162 600: 'oklch(0.523 0.081 246.86)',
1002 700: 'oklch(0.43 0.066 246.75)', 1163 700: 'oklch(0.43 0.066 246.75)',
1003 800: 'oklch(0.335 0.052 246.76)', 1164 800: 'oklch(0.335 0.052 246.76)'
1004 }, 1165 },
1005 asuka: { 1166 asuka: {
1006 400: 'oklch(0.740 0.210 32)', 1167 400: 'oklch(0.740 0.210 32)',
1007 500: 'oklch(0.650 0.240 30)', 1168 500: 'oklch(0.650 0.240 30)',
1008 600: 'oklch(0.555 0.238 28)', 1169 600: 'oklch(0.555 0.238 28)',
1009 700: 'oklch(0.455 0.205 26)', 1170 700: 'oklch(0.455 0.205 26)',
1010 800: 'oklch(0.370 0.165 24)', 1171 800: 'oklch(0.370 0.165 24)'
1011 }, 1172 },
1012 irys: { 1173 irys: {
1013 400: 'oklch(0.716 0.188 5.18)', 1174 400: 'oklch(0.716 0.188 5.18)',
1014 500: 'oklch(0.659 0.237 8.99)', 1175 500: 'oklch(0.659 0.237 8.99)',
1015 600: 'oklch(0.584 0.229 10.32)', 1176 600: 'oklch(0.584 0.229 10.32)',
1016 700: 'oklch(0.538 0.213 9.67)', 1177 700: 'oklch(0.538 0.213 9.67)',
1017 800: 'oklch(0.475 0.187 5.94)', 1178 800: 'oklch(0.475 0.187 5.94)'
1018 }, 1179 },
1019 inanis: { 1180 inanis: {
1020 400: 'oklch(0.762 0.073 302.02)', 1181 400: 'oklch(0.762 0.073 302.02)',
1021 500: 'oklch(0.663 0.102 301.22)', 1182 500: 'oklch(0.663 0.102 301.22)',
1022 600: 'oklch(0.580 0.119 301.34)', 1183 600: 'oklch(0.580 0.119 301.34)',
1023 700: 'oklch(0.508 0.114 301.00)', 1184 700: 'oklch(0.508 0.114 301.00)',
1024 800: 'oklch(0.452 0.094 302.20)', 1185 800: 'oklch(0.452 0.094 302.20)'
1025 }, 1186 },
1026 baelz: { 1187 baelz: {
1027 400: 'oklch(0.720 0.215 22.00)', 1188 400: 'oklch(0.720 0.215 22.00)',
1028 500: 'oklch(0.640 0.255 22.00)', 1189 500: 'oklch(0.640 0.255 22.00)',
1029 600: 'oklch(0.555 0.268 22.00)', 1190 600: 'oklch(0.555 0.268 22.00)',
1030 700: 'oklch(0.472 0.248 22.00)', 1191 700: 'oklch(0.472 0.248 22.00)',
1031 800: 'oklch(0.395 0.208 22.00)', 1192 800: 'oklch(0.395 0.208 22.00)'
1032 }, 1193 },
1033 amelia: { 1194 amelia: {
1034 400: 'oklch(0.800 0.085 75.49)', 1195 400: 'oklch(0.800 0.085 75.49)',
1035 500: 'oklch(0.710 0.090 72.47)', 1196 500: 'oklch(0.710 0.090 72.47)',
1036 600: 'oklch(0.594 0.085 69.07)', 1197 600: 'oklch(0.594 0.085 69.07)',
1037 700: 'oklch(0.496 0.078 72.12)', 1198 700: 'oklch(0.496 0.078 72.12)',
1038 800: 'oklch(0.391 0.062 68.86)', 1199 800: 'oklch(0.391 0.062 68.86)'
1039 }, 1200 },
1040 suisei: { 1201 suisei: {
1041 400: 'oklch(0.827 0.096 224.60)', 1202 400: 'oklch(0.827 0.096 224.60)',
1042 500: 'oklch(0.740 0.119 230.91)', 1203 500: 'oklch(0.740 0.119 230.91)',
1043 600: 'oklch(0.645 0.127 236.29)', 1204 600: 'oklch(0.645 0.127 236.29)',
1044 700: 'oklch(0.548 0.120 241.26)', 1205 700: 'oklch(0.548 0.120 241.26)',
1045 800: 'oklch(0.451 0.106 244.63)', 1206 800: 'oklch(0.451 0.106 244.63)'
1046 }, 1207 },
1047 miku: { 1208 miku: {
1048 400: 'oklch(0.788 0.133 184.43)', 1209 400: 'oklch(0.788 0.133 184.43)',
1049 500: 'oklch(0.711 0.123 185.28)', 1210 500: 'oklch(0.711 0.123 185.28)',
1050 600: 'oklch(0.607 0.104 187.31)', 1211 600: 'oklch(0.607 0.104 187.31)',
1051 700: 'oklch(0.515 0.086 189.60)', 1212 700: 'oklch(0.515 0.086 189.60)',
1052 800: 'oklch(0.441 0.071 190.95)', 1213 800: 'oklch(0.441 0.071 190.95)'
1053 }, 1214 },
1054 fubuki: { 1215 fubuki: {
1055 dark: { 1216 dark: {
@@ -1057,16 +1218,16 @@ const accentPalettes: Record<string, PaletteEntry> = {
1057 500: 'oklch(0.78 0 0)', 1218 500: 'oklch(0.78 0 0)',
1058 600: 'oklch(0.68 0 0)', 1219 600: 'oklch(0.68 0 0)',
1059 700: 'oklch(0.58 0 0)', 1220 700: 'oklch(0.58 0 0)',
1060 800: 'oklch(0.48 0 0)', 1221 800: 'oklch(0.48 0 0)'
1061 }, 1222 },
1062 light: { 1223 light: {
1063 400: 'oklch(0.52 0 0)', 1224 400: 'oklch(0.52 0 0)',
1064 500: 'oklch(0.42 0 0)', 1225 500: 'oklch(0.42 0 0)',
1065 600: 'oklch(0.32 0 0)', 1226 600: 'oklch(0.32 0 0)',
1066 700: 'oklch(0.22 0 0)', 1227 700: 'oklch(0.22 0 0)',
1067 800: 'oklch(0.12 0 0)', 1228 800: 'oklch(0.12 0 0)'
1068 }, 1229 }
1069 }, 1230 }
1070} 1231}
1071 1232
1072const accentColor = useStorage(AccentColorStorageKey, 'ayanami') 1233const accentColor = useStorage(AccentColorStorageKey, 'ayanami')
@@ -1091,7 +1252,7 @@ const accentBgTokens: Record<'dark' | 'light', Record<string, TintEntry>> = {
1091 '--wk-c-menu-bg': [0.295, 0.032], 1252 '--wk-c-menu-bg': [0.295, 0.032],
1092 '--wk-c-nav-solid-bg': [0.2, 0.024], 1253 '--wk-c-nav-solid-bg': [0.2, 0.024],
1093 '--nav-pill-bg': [0.205, 0.024, 0.7], 1254 '--nav-pill-bg': [0.205, 0.024, 0.7],
1094 '--wk-fs-header-divider': [0.44, 0.02, 0.65], 1255 '--wk-fs-header-divider': [0.44, 0.02, 0.65]
1095 }, 1256 },
1096 light: { 1257 light: {
1097 '--vp-c-bg': [0.986, 0.012], 1258 '--vp-c-bg': [0.986, 0.012],
@@ -1107,13 +1268,15 @@ const accentBgTokens: Record<'dark' | 'light', Record<string, TintEntry>> = {
1107 '--wk-c-menu-bg': [0.928, 0.026], 1268 '--wk-c-menu-bg': [0.928, 0.026],
1108 '--wk-c-nav-solid-bg': [0.986, 0.012], 1269 '--wk-c-nav-solid-bg': [0.986, 0.012],
1109 '--nav-pill-bg': [0.99, 0.01, 0.8], 1270 '--nav-pill-bg': [0.99, 0.01, 0.8],
1110 '--wk-fs-header-divider': [0.715, 0.02, 0.25], 1271 '--wk-fs-header-divider': [0.715, 0.02, 0.25]
1111 }, 1272 }
1112} 1273}
1113const accentBgTokenKeys = [...new Set([ 1274const accentBgTokenKeys = [
1114 ...Object.keys(accentBgTokens.dark), 1275 ...new Set([
1115 ...Object.keys(accentBgTokens.light), 1276 ...Object.keys(accentBgTokens.dark),
1116])] 1277 ...Object.keys(accentBgTokens.light)
1278 ])
1279]
1117 1280
1118const applyAccentTheme = () => { 1281const applyAccentTheme = () => {
1119 if (import.meta.env.SSR) return 1282 if (import.meta.env.SSR) return
@@ -1126,14 +1289,26 @@ const applyAccentTheme = () => {
1126 el.style.setProperty('--vp-c-brand-1', shades['400']) 1289 el.style.setProperty('--vp-c-brand-1', shades['400'])
1127 el.style.setProperty('--vp-c-brand-2', shades['500']) 1290 el.style.setProperty('--vp-c-brand-2', shades['500'])
1128 el.style.setProperty('--vp-c-brand-3', shades['700']) 1291 el.style.setProperty('--vp-c-brand-3', shades['700'])
1129 el.style.setProperty('--vp-c-brand-soft', `color-mix(in srgb, ${shades['500']} 20%, transparent)`) 1292 el.style.setProperty(
1130 el.style.setProperty('--vp-c-sidebar-active', `color-mix(in srgb, ${shades['500']} 15%, transparent)`) 1293 '--vp-c-brand-soft',
1294 `color-mix(in srgb, ${shades['500']} 20%, transparent)`
1295 )
1296 el.style.setProperty(
1297 '--vp-c-sidebar-active',
1298 `color-mix(in srgb, ${shades['500']} 15%, transparent)`
1299 )
1131 } else { 1300 } else {
1132 el.style.setProperty('--vp-c-brand-1', shades['500']) 1301 el.style.setProperty('--vp-c-brand-1', shades['500'])
1133 el.style.setProperty('--vp-c-brand-2', shades['600']) 1302 el.style.setProperty('--vp-c-brand-2', shades['600'])
1134 el.style.setProperty('--vp-c-brand-3', shades['800']) 1303 el.style.setProperty('--vp-c-brand-3', shades['800'])
1135 el.style.setProperty('--vp-c-brand-soft', `color-mix(in srgb, ${shades['400']} 40%, transparent)`) 1304 el.style.setProperty(
1136 el.style.setProperty('--vp-c-sidebar-active', `color-mix(in srgb, ${shades['800']} 15%, transparent)`) 1305 '--vp-c-brand-soft',
1306 `color-mix(in srgb, ${shades['400']} 40%, transparent)`
1307 )
1308 el.style.setProperty(
1309 '--vp-c-sidebar-active',
1310 `color-mix(in srgb, ${shades['800']} 15%, transparent)`
1311 )
1137 } 1312 }
1138 1313
1139 for (const key of accentBgTokenKeys) el.style.removeProperty(key) 1314 for (const key of accentBgTokenKeys) el.style.removeProperty(key)
@@ -1145,7 +1320,8 @@ const applyAccentTheme = () => {
1145 if (parsed) { 1320 if (parsed) {
1146 // Tint scales with the accent's own chroma (full tint at C >= 0.10, 1321 // Tint scales with the accent's own chroma (full tint at C >= 0.10,
1147 // grayscale accents stay gray), then with the intensity preset. 1322 // grayscale accents stay gray), then with the intensity preset.
1148 const strength = Math.min(1, Number(parsed[1]) / 0.10) * userStrength * 1.5 1323 const strength = Math.min(1, Number(parsed[1]) / 0.10) * userStrength *
1324 1.5
1149 const hue = parsed[2] 1325 const hue = parsed[2]
1150 const tokens = accentBgTokens[isDark.value ? 'dark' : 'light'] 1326 const tokens = accentBgTokens[isDark.value ? 'dark' : 'light']
1151 for (const [key, [l, c, alpha]] of Object.entries(tokens)) { 1327 for (const [key, [l, c, alpha]] of Object.entries(tokens)) {
@@ -1177,15 +1353,25 @@ function initTitleOnly() {
1177 }) 1353 })
1178} 1354}
1179 1355
1356// Browsers restore checkbox state on reload; always start collapsed.
1357function resetTableMoreInRoot(root: ParentNode) {
1358 root.querySelectorAll<HTMLInputElement>('.table-more-checkbox:checked')
1359 .forEach((el) => {
1360 el.checked = false
1361 })
1362}
1363
1180// Wrap bare tables in their own scroll container so they scroll independently of sibling content. 1364// Wrap bare tables in their own scroll container so they scroll independently of sibling content.
1181function wrapTablesInRoot(root: ParentNode) { 1365function wrapTablesInRoot(root: ParentNode) {
1182 root.querySelectorAll<HTMLTableElement>('table:not(.scrape-table)').forEach(table => { 1366 root.querySelectorAll<HTMLTableElement>('table:not(.scrape-table)').forEach(
1183 if (table.parentElement?.classList.contains('table-scroll')) return 1367 table => {
1184 const wrapper = document.createElement('div') 1368 if (table.parentElement?.classList.contains('table-scroll')) return
1185 wrapper.className = 'table-scroll' 1369 const wrapper = document.createElement('div')
1186 table.replaceWith(wrapper) 1370 wrapper.className = 'table-scroll'
1187 wrapper.appendChild(table) 1371 table.replaceWith(wrapper)
1188 }) 1372 wrapper.appendChild(table)
1373 }
1374 )
1189} 1375}
1190 1376
1191function initCopyButtonsInRoot(root: ParentNode) { 1377function initCopyButtonsInRoot(root: ParentNode) {
@@ -1269,6 +1455,7 @@ let copyButtonObserver: MutationObserver | null = null
1269 1455
1270function setupManualCopyButtons() { 1456function setupManualCopyButtons() {
1271 wrapTablesInRoot(document) 1457 wrapTablesInRoot(document)
1458 resetTableMoreInRoot(document)
1272 initCopyButtonsInRoot(document) 1459 initCopyButtonsInRoot(document)
1273 1460
1274 copyButtonObserver?.disconnect() 1461 copyButtonObserver?.disconnect()
@@ -1278,6 +1465,7 @@ function setupManualCopyButtons() {
1278 if (!(node instanceof HTMLElement)) continue 1465 if (!(node instanceof HTMLElement)) continue
1279 if (node.classList.contains('plugin-tabs--content')) { 1466 if (node.classList.contains('plugin-tabs--content')) {
1280 wrapTablesInRoot(node) 1467 wrapTablesInRoot(node)
1468 resetTableMoreInRoot(node)
1281 initCopyButtonsInRoot(node) 1469 initCopyButtonsInRoot(node)
1282 if (faviconsEnabled.value) applyFavicons(node) 1470 if (faviconsEnabled.value) applyFavicons(node)
1283 reapplyHighlightIfNeeded(node) 1471 reapplyHighlightIfNeeded(node)
@@ -1285,6 +1473,7 @@ function setupManualCopyButtons() {
1285 node.querySelectorAll<HTMLElement>('.plugin-tabs--content').forEach( 1473 node.querySelectorAll<HTMLElement>('.plugin-tabs--content').forEach(
1286 (panel) => { 1474 (panel) => {
1287 wrapTablesInRoot(panel) 1475 wrapTablesInRoot(panel)
1476 resetTableMoreInRoot(panel)
1288 initCopyButtonsInRoot(panel) 1477 initCopyButtonsInRoot(panel)
1289 if (faviconsEnabled.value) applyFavicons(panel) 1478 if (faviconsEnabled.value) applyFavicons(panel)
1290 reapplyHighlightIfNeeded(panel) 1479 reapplyHighlightIfNeeded(panel)
@@ -1302,7 +1491,10 @@ watch(
1302 () => { 1491 () => {
1303 highlightTerm = '' 1492 highlightTerm = ''
1304 highlightTabPath = null 1493 highlightTabPath = null
1305 nextTick(() => { initTitleOnly(); setupManualCopyButtons() }) 1494 nextTick(() => {
1495 initTitleOnly()
1496 setupManualCopyButtons()
1497 })
1306 }, 1498 },
1307 { flush: 'post' } 1499 { flush: 'post' }
1308) 1500)
@@ -1315,6 +1507,11 @@ onMounted(() => {
1315 initTitleOnly() 1507 initTitleOnly()
1316 nextTick(setupManualCopyButtons) 1508 nextTick(setupManualCopyButtons)
1317 1509
1510 // bfcache can restore the <more> table checkboxes as checked.
1511 window.addEventListener('pageshow', (e) => {
1512 if (e.persisted) resetTableMoreInRoot(document)
1513 })
1514
1318 // Icon tooltip: fixed-position popup appended to <body> to escape table overflow clipping 1515 // Icon tooltip: fixed-position popup appended to <body> to escape table overflow clipping
1319 const tooltipEl = document.createElement('div') 1516 const tooltipEl = document.createElement('div')
1320 tooltipEl.className = 'icon-tip-popup' 1517 tooltipEl.className = 'icon-tip-popup'
@@ -1421,6 +1618,11 @@ onMounted(() => {
1421 queueCollapsibleQueryUpdate(e.target) 1618 queueCollapsibleQueryUpdate(e.target)
1422 }) 1619 })
1423 1620
1621 useEventListener(document, 'change', (e: Event) => {
1622 if (!e.isTrusted) return
1623 queueTableMoreQueryUpdate(e.target)
1624 })
1625
1424 useEventListener(document, 'keydown', (e: KeyboardEvent) => { 1626 useEventListener(document, 'keydown', (e: KeyboardEvent) => {
1425 if (!e.isTrusted || (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight')) { 1627 if (!e.isTrusted || (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight')) {
1426 return 1628 return
@@ -1627,4 +1829,4 @@ onUnmounted(() => {
1627 </span> 1829 </span>
1628 </template> 1830 </template>
1629 </Layout> 1831 </Layout>
1630</template>\ No newline at end of file 1832</template>
docs/.vitepress/theme/index.ts +2 −1
@@ -17,6 +17,7 @@ import { createMediumZoomProvider } from './composables/medium-zoom'
17import 'virtual:uno.css' 17import 'virtual:uno.css'
18import Layout from './Layout.vue' 18import Layout from './Layout.vue'
19import './styles/tooltip-hint.css' 19import './styles/tooltip-hint.css'
20import './styles/table-more.css'
20import './styles/steps.css' 21import './styles/steps.css'
21import { enhanceAppWithTabs } from './components/tabs' 22import { enhanceAppWithTabs } from './components/tabs'
22import { registerGlobalComponents } from './globalComponents' 23import { registerGlobalComponents } from './globalComponents'
@@ -91,4 +92,4 @@ export default {
91 ] 92 ]
92 ) 93 )
93 } 94 }
94} satisfies Theme\ No newline at end of file 95} satisfies Theme
docs/.vitepress/theme/styles/table-more.css added +85
@@ -0,0 +1,85 @@
1/* Expandable table sections ("<more>" marker). Pure CSS toggle
2 (hidden checkbox + :has()): no JS, SSR-safe. */
3
4.vp-doc table tbody.table-more-hidden {
5 display: none;
6}
7
8.vp-doc table:has(.table-more-checkbox:checked) tbody.table-more-hidden {
9 display: table-row-group;
10}
11
12.table-more-toggle-row > td {
13 padding: 0 !important;
14 text-align: center;
15}
16
17.table-more-label {
18 display: flex;
19 align-items: center;
20 justify-content: center;
21 gap: 0.4em;
22 padding: 8px 16px;
23 cursor: pointer;
24 font-size: 0.875rem;
25 font-weight: 600;
26 color: var(--vp-c-text-2);
27 user-select: none;
28}
29
30.table-more-label:hover {
31 color: var(--vp-c-brand-1);
32}
33
34.table-more-label:focus-within .table-more-text,
35.table-more-label:focus-within .table-more-icon {
36 color: var(--vp-c-brand-1);
37}
38
39/* Keep the checkbox keyboard-focusable but invisible. */
40.table-more-checkbox {
41 position: absolute;
42 opacity: 0;
43 pointer-events: none;
44}
45
46.table-more-icon {
47 transition: transform 0.2s;
48}
49
50.vp-doc table:has(.table-more-checkbox:checked) .table-more-icon {
51 transform: rotate(180deg);
52}
53
54.table-more-text--less {
55 display: none;
56}
57
58.vp-doc table:has(.table-more-checkbox:checked) .table-more-text--more {
59 display: none;
60}
61
62.vp-doc table:has(.table-more-checkbox:checked) .table-more-text--less {
63 display: inline;
64}
65
66@media (prefers-reduced-motion: reduce) {
67 .table-more-icon {
68 transition: none;
69 }
70}
71
72/* Respect the "Effects: OFF" site setting. */
73html.effects-disabled .table-more-icon {
74 transition: none;
75}
76
77@media print {
78 .vp-doc table tbody.table-more-hidden {
79 display: table-row-group !important;
80 }
81
82 .vp-doc table tbody.table-more-toggle {
83 display: none !important;
84 }
85}
unocss.config.ts +8 −2
@@ -18,7 +18,10 @@ import {
18 transformerDirectives 18 transformerDirectives
19} from 'unocss' 19} from 'unocss'
20import { aliases } from './docs/.vitepress/configs/markdown/emoji' 20import { aliases } from './docs/.vitepress/configs/markdown/emoji'
21import { LANG_FLAG_FALLBACK, LANG_FLAG_ICONS } from './docs/.vitepress/configs/markdown/langFlags' 21import {
22 LANG_FLAG_FALLBACK,
23 LANG_FLAG_ICONS
24} from './docs/.vitepress/configs/markdown/langFlags'
22 25
23const iconPrefixes = [ 26const iconPrefixes = [
24 'octicon-', 27 'octicon-',
@@ -79,6 +82,7 @@ const safelist = [
79 'i-lucide:settings', 82 'i-lucide:settings',
80 'i-lucide:download', 83 'i-lucide:download',
81 'i-lucide:chevron-down', 84 'i-lucide:chevron-down',
85 'i-mdi-chevron-down',
82 'i-lucide:search', 86 'i-lucide:search',
83 'i-lucide:languages', 87 'i-lucide:languages',
84 'i-lucide:shield', 88 'i-lucide:shield',
@@ -97,7 +101,9 @@ const safelist = [
97 'i-twemoji-growing-heart', 101 'i-twemoji-growing-heart',
98 'i-twemoji-folded-hands', 102 'i-twemoji-folded-hands',
99 'i-twemoji-glowing-star', 103 'i-twemoji-glowing-star',
100 ...Array.from(new Set([...Object.values(LANG_FLAG_ICONS), LANG_FLAG_FALLBACK])).map( 104 ...Array.from(
105 new Set([...Object.values(LANG_FLAG_ICONS), LANG_FLAG_FALLBACK])
106 ).map(
101 (icon) => `i-twemoji-${icon}` 107 (icon) => `i-twemoji-${icon}`
102 ) 108 )
103] 109]