| @@ -6,11 +6,7 @@ |
| 6 | 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 | 8 | <script setup lang="ts"> |
| 9 | | import { |
| 10 | | useEventListener, |
| 11 | | useStorage, |
| 12 | | useThrottleFn |
| 13 | | } from '@vueuse/core' |
| 9 | import { useEventListener, useStorage, useThrottleFn } from '@vueuse/core' |
| 14 | 10 | import { getScrollOffset, useData, useRoute } from 'vitepress' |
| 15 | 11 | import type { DefaultTheme as Theme } from 'vitepress' |
| 16 | 12 | import VPSidebarGroup from 'vitepress/dist/client/theme-default/components/VPSidebarGroup.vue' |
| @@ -26,16 +22,24 @@ import { |
| 26 | 22 | watchEffect |
| 27 | 23 | } from 'vue' |
| 28 | 24 | import { sidebar } from '../configs/constants' |
| 29 | | import { useBookmarks, BOOKMARK_CHANGE_EVENT } from './composables/useBookmarks' |
| 30 | 25 | import AnnouncementPill from './components/AnnouncementPill.vue' |
| 31 | | import SiteFooter from './components/SiteFooter.vue' |
| 26 | import NavActions from './components/NavActions.vue' |
| 32 | 27 | import NotFoundComponent from './components/NotFound.vue' |
| 33 | 28 | import { NolebaseEnhancedReadabilitiesScreenMenu } from './components/settings' |
| 34 | | import NavActions from './components/NavActions.vue' |
| 35 | 29 | import SidebarCard from './components/SidebarCard.vue' |
| 36 | | import { AccentBgStorageKey, AccentBgStrengthStorageKey, AccentColorStorageKey } from './constants' |
| 30 | import SiteFooter from './components/SiteFooter.vue' |
| 31 | import { BOOKMARK_CHANGE_EVENT, useBookmarks } from './composables/useBookmarks' |
| 37 | 32 | import { useEffects } from './composables/useEffects' |
| 38 | | import { applyFavicons, removeFavicons, useFavicons } from './composables/useFavicons' |
| 33 | import { |
| 34 | applyFavicons, |
| 35 | removeFavicons, |
| 36 | useFavicons |
| 37 | } from './composables/useFavicons' |
| 38 | import { |
| 39 | AccentBgStorageKey, |
| 40 | AccentBgStrengthStorageKey, |
| 41 | AccentColorStorageKey |
| 42 | } from './constants' |
| 39 | 43 | import { searchResultHighlightMode } from './searchState' |
| 40 | 44 | |
| 41 | 45 | const route = useRoute() |
| @@ -84,6 +88,12 @@ if (!import.meta.env.SSR) { |
| 84 | 88 | if (target) { |
| 85 | 89 | void nextTick(() => { |
| 86 | 90 | if (searchNavigated) { |
| 91 | scanSectionForTerms( |
| 92 | target, |
| 93 | getSearchTerms(searchQuery), |
| 94 | () => {}, |
| 95 | expandTableMoreEl |
| 96 | ) |
| 87 | 97 | highlightSearchResult(target) |
| 88 | 98 | resetSearchNavigation() |
| 89 | 99 | } |
| @@ -99,6 +109,12 @@ if (!import.meta.env.SSR) { |
| 99 | 109 | if (!currentHash) return |
| 100 | 110 | const target = getTargetByHash(currentHash) |
| 101 | 111 | if (target) { |
| 112 | scanSectionForTerms( |
| 113 | target, |
| 114 | getSearchTerms(searchQuery), |
| 115 | () => {}, |
| 116 | expandTableMoreEl |
| 117 | ) |
| 102 | 118 | highlightSearchResult(target) |
| 103 | 119 | resetSearchNavigation() |
| 104 | 120 | } else if (attempts < 15) { |
| @@ -131,7 +147,6 @@ const removeSearchResultHighlights = () => { |
| 131 | 147 | ) |
| 132 | 148 | } |
| 133 | 149 | |
| 134 | | |
| 135 | 150 | let highlightTerm = '' |
| 136 | 151 | let highlightTabPath: string[] | null = null |
| 137 | 152 | |
| @@ -164,7 +179,9 @@ const applyHighlightWithin = (root: HTMLElement, term: string) => { |
| 164 | 179 | const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, { |
| 165 | 180 | acceptNode(node) { |
| 166 | 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 | 185 | return NodeFilter.FILTER_REJECT |
| 169 | 186 | } |
| 170 | 187 | return NodeFilter.FILTER_ACCEPT |
| @@ -225,7 +242,7 @@ const highlightSearchResult = (target?: HTMLElement) => { |
| 225 | 242 | ) |
| 226 | 243 | highlightTabPath = panel ? getPanelTabPath(panel) : null |
| 227 | 244 | highlightTerm = term |
| 228 | | |
| 245 | |
| 229 | 246 | if (!applyHighlightWithin(target, term)) { |
| 230 | 247 | const docRoot = document.querySelector<HTMLElement>('.VPDoc .vp-doc') |
| 231 | 248 | if (docRoot) { |
| @@ -271,6 +288,7 @@ const getScrollTargetForAnchor = (target: HTMLElement) => { |
| 271 | 288 | |
| 272 | 289 | const TAB_QUERY_PARAM = 't' |
| 273 | 290 | const COLLAPSIBLE_QUERY_PARAM = 'c' |
| 291 | const TABLE_MORE_QUERY_PARAM = 'm' |
| 274 | 292 | |
| 275 | 293 | const getRequestedAnchorPath = (param: string) => { |
| 276 | 294 | const value = new URLSearchParams(window.location.search).get(param) |
| @@ -283,29 +301,43 @@ const getRequestedAnchorPath = (param: string) => { |
| 283 | 301 | const getRequestedTabPath = () => getRequestedAnchorPath(TAB_QUERY_PARAM) |
| 284 | 302 | const getRequestedCollapsiblePath = () => |
| 285 | 303 | getRequestedAnchorPath(COLLAPSIBLE_QUERY_PARAM) |
| 304 | const getRequestedTableMorePath = () => |
| 305 | getRequestedAnchorPath(TABLE_MORE_QUERY_PARAM) |
| 286 | 306 | |
| 287 | 307 | const encodeAnchorList = (anchors: string[]) => |
| 288 | 308 | anchors.map((anchor) => encodeURIComponent(anchor)).join(',') |
| 289 | 309 | |
| 290 | 310 | const 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 | 318 | const params = new URLSearchParams(window.location.search) |
| 294 | 319 | const currentTabs = params.get(TAB_QUERY_PARAM) |
| 295 | 320 | const currentCollapsibles = params.get(COLLAPSIBLE_QUERY_PARAM) |
| 321 | const currentTables = params.get(TABLE_MORE_QUERY_PARAM) |
| 296 | 322 | params.delete(TAB_QUERY_PARAM) |
| 297 | 323 | params.delete(COLLAPSIBLE_QUERY_PARAM) |
| 324 | params.delete(TABLE_MORE_QUERY_PARAM) |
| 298 | 325 | |
| 299 | 326 | const tabs = options.tabs ?? |
| 300 | 327 | (currentTabs ? currentTabs.split(',').filter(Boolean) : []) |
| 301 | 328 | const collapsibles = options.collapsibles ?? |
| 302 | 329 | (currentCollapsibles ? currentCollapsibles.split(',').filter(Boolean) : []) |
| 330 | const tables = options.tables ?? |
| 331 | (currentTables ? currentTables.split(',').filter(Boolean) : []) |
| 303 | 332 | |
| 304 | 333 | const queryParts = [ |
| 305 | 334 | params.toString(), |
| 306 | 335 | tabs.length ? `${TAB_QUERY_PARAM}=${encodeAnchorList(tabs)}` : '', |
| 307 | 336 | collapsibles.length |
| 308 | 337 | ? `${COLLAPSIBLE_QUERY_PARAM}=${encodeAnchorList(collapsibles)}` |
| 338 | : '', |
| 339 | tables.length |
| 340 | ? `${TABLE_MORE_QUERY_PARAM}=${encodeAnchorList(tables)}` |
| 309 | 341 | : '' |
| 310 | 342 | ].filter(Boolean) |
| 311 | 343 | |
| @@ -374,6 +406,73 @@ const queueTabQueryUpdateForSelection = (target: EventTarget | null) => { |
| 374 | 406 | |
| 375 | 407 | const COLLAPSIBLE_SELECTOR = 'details[data-collapsible-anchor]' |
| 376 | 408 | |
| 409 | const 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. |
| 416 | const 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 | |
| 423 | const expandTableMoreEl = (t: HTMLElement) => { |
| 424 | const box = getTableMoreCheckbox(t) |
| 425 | if (box && !box.checked) box.checked = true |
| 426 | } |
| 427 | |
| 428 | const 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 | |
| 377 | 476 | const getOpenCollapsiblePath = (details: HTMLElement) => { |
| 378 | 477 | const path: string[] = [] |
| 379 | 478 | let el: HTMLElement | null = details |
| @@ -430,6 +529,34 @@ const queueCollapsibleQueryUpdate = (target: EventTarget | null) => { |
| 430 | 529 | } |
| 431 | 530 | } |
| 432 | 531 | |
| 532 | const 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 | |
| 551 | const 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 | |
| 433 | 560 | const selectCollapsiblesByPath = async (collapsiblePath: string[]) => { |
| 434 | 561 | let root: ParentNode = document |
| 435 | 562 | let opened: HTMLElement | undefined |
| @@ -453,6 +580,45 @@ const selectCollapsiblesByPath = async (collapsiblePath: string[]) => { |
| 453 | 580 | return opened |
| 454 | 581 | } |
| 455 | 582 | |
| 583 | const TABLE_MORE_SELECTOR = 'table[data-table-more]' |
| 584 | |
| 585 | const getTableMoreCheckbox = (table: HTMLElement) => |
| 586 | table.querySelector<HTMLInputElement>('.table-more-checkbox') |
| 587 | |
| 588 | const 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 | |
| 609 | const 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 | |
| 456 | 622 | const TAB_LINK_MARKER = 'tab-' |
| 457 | 623 | |
| 458 | 624 | const rewriteAnchorLinks = () => { |
| @@ -585,44 +751,19 @@ const openCollapsibles = async (target: HTMLElement) => { |
| 585 | 751 | |
| 586 | 752 | const tagName = activeTarget.tagName |
| 587 | 753 | if (tagName.length === 2 && tagName[0] === 'H') { |
| 588 | | const level = +tagName[1] |
| 589 | | if (level >= 1 && level <= 6) { |
| 590 | | const terms = getSearchTerms(searchQuery) |
| 591 | | const detailsContainsTerms = (d: HTMLElement) => { |
| 592 | | if (!terms.length) return false |
| 593 | | const text = (d.textContent ?? '').toLowerCase() |
| 594 | | return terms.every((term) => text.includes(term)) |
| 595 | | } |
| 596 | | |
| 597 | | let sibling = activeTarget.nextElementSibling |
| 598 | | |
| 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 |
| 754 | const terms = getSearchTerms(searchQuery) |
| 755 | scanSectionForTerms( |
| 756 | activeTarget, |
| 757 | terms, |
| 758 | (d) => { |
| 759 | ;(d as HTMLDetailsElement).open = true |
| 760 | if (scrollTarget === activeTarget) scrollTarget = d |
| 761 | }, |
| 762 | (t) => { |
| 763 | expandTableMoreEl(t) |
| 764 | if (scrollTarget === activeTarget) scrollTarget = t |
| 624 | 765 | } |
| 625 | | } |
| 766 | ) |
| 626 | 767 | } |
| 627 | 768 | |
| 628 | 769 | await nextTick() |
| @@ -649,6 +790,10 @@ const tryOpenAnchoredContent = async () => { |
| 649 | 790 | const openedCollapsible = requestedCollapsibles.length |
| 650 | 791 | ? await selectCollapsiblesByPath(requestedCollapsibles) |
| 651 | 792 | : undefined |
| 793 | const requestedTables = getRequestedTableMorePath() |
| 794 | const openedTable = requestedTables.length |
| 795 | ? await selectTablesByPath(requestedTables) |
| 796 | : undefined |
| 652 | 797 | const hash = window.location.hash.slice(1) |
| 653 | 798 | |
| 654 | 799 | if (!hash) { |
| @@ -662,6 +807,8 @@ const tryOpenAnchoredContent = async () => { |
| 662 | 807 | scrollToElement(openedCollapsible, false) |
| 663 | 808 | } else if (selectedTabs) { |
| 664 | 809 | scrollToElement(getSelectedTabScrollTarget(selectedTabs), false) |
| 810 | } else if (openedTable) { |
| 811 | scrollToElement(openedTable, false) |
| 665 | 812 | } |
| 666 | 813 | return |
| 667 | 814 | } |
| @@ -686,14 +833,16 @@ const tryOpenAnchoredContent = async () => { |
| 686 | 833 | await openCollapsibles(target) |
| 687 | 834 | highlightSearchResult(target) |
| 688 | 835 | const collapsiblePath = getOpenCollapsiblePath(target) |
| 689 | | if (collapsiblePath.length) { |
| 836 | const tablePath = getOpenTableMorePath() |
| 837 | if (collapsiblePath.length || tablePath.length) { |
| 690 | 838 | const tabPath = getEnclosingTabPath(target) |
| 691 | 839 | window.history.replaceState( |
| 692 | 840 | null, |
| 693 | 841 | '', |
| 694 | 842 | buildUrl({ |
| 695 | 843 | tabs: tabPath.length ? tabPath : undefined, |
| 696 | | collapsibles: collapsiblePath |
| 844 | collapsibles: collapsiblePath, |
| 845 | tables: tablePath |
| 697 | 846 | }) |
| 698 | 847 | ) |
| 699 | 848 | rewriteAnchorLinks() |
| @@ -833,7 +982,8 @@ const setupOutlineFollow = () => { |
| 833 | 982 | followActiveOutlineLink() |
| 834 | 983 | } |
| 835 | 984 | |
| 836 | | const 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>` |
| 985 | const 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 | |
| 838 | 988 | function syncTocBookmarkStates() { |
| 839 | 989 | const path = route.path |
| @@ -877,14 +1027,20 @@ let tocRaf = 0 |
| 877 | 1027 | |
| 878 | 1028 | function scanTocItems(path: string) { |
| 879 | 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 | 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 | |
| 885 | 1039 | function setupTocBookmarks() { |
| 886 | 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 | 1044 | scanTocItems(path) |
| 889 | 1045 | |
| 890 | 1046 | // Mobile dropdown items are v-if rendered on open — watch for them being added |
| @@ -903,7 +1059,9 @@ onMounted(tryOpenAnchoredContent) |
| 903 | 1059 | onMounted(rewriteAnchorLinksDeferred) |
| 904 | 1060 | onMounted(() => nextTick(setupOutlineFollow)) |
| 905 | 1061 | onMounted(() => nextTick(setupTocBookmarks)) |
| 906 | | onMounted(() => window.addEventListener('scroll', onMobileOutlineScroll, { passive: true })) |
| 1062 | onMounted(() => |
| 1063 | window.addEventListener('scroll', onMobileOutlineScroll, { passive: true }) |
| 1064 | ) |
| 907 | 1065 | onUnmounted(() => window.removeEventListener('scroll', onMobileOutlineScroll)) |
| 908 | 1066 | watch(() => route.data, () => { |
| 909 | 1067 | void tryOpenAnchoredContent() |
| @@ -987,7 +1145,10 @@ watch(faviconsEnabled, (enabled) => { |
| 987 | 1145 | |
| 988 | 1146 | watch( |
| 989 | 1147 | () => route.path, |
| 990 | | () => nextTick(() => { if (faviconsEnabled.value) applyFavicons(document) }), |
| 1148 | () => |
| 1149 | nextTick(() => { |
| 1150 | if (faviconsEnabled.value) applyFavicons(document) |
| 1151 | }), |
| 991 | 1152 | { flush: 'post' } |
| 992 | 1153 | ) |
| 993 | 1154 | |
| @@ -1000,56 +1161,56 @@ const accentPalettes: Record<string, PaletteEntry> = { |
| 1000 | 1161 | 500: 'oklch(0.626 0.098 247.46)', |
| 1001 | 1162 | 600: 'oklch(0.523 0.081 246.86)', |
| 1002 | 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 | 1166 | asuka: { |
| 1006 | 1167 | 400: 'oklch(0.740 0.210 32)', |
| 1007 | 1168 | 500: 'oklch(0.650 0.240 30)', |
| 1008 | 1169 | 600: 'oklch(0.555 0.238 28)', |
| 1009 | 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 | 1173 | irys: { |
| 1013 | 1174 | 400: 'oklch(0.716 0.188 5.18)', |
| 1014 | 1175 | 500: 'oklch(0.659 0.237 8.99)', |
| 1015 | 1176 | 600: 'oklch(0.584 0.229 10.32)', |
| 1016 | 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 | 1180 | inanis: { |
| 1020 | 1181 | 400: 'oklch(0.762 0.073 302.02)', |
| 1021 | 1182 | 500: 'oklch(0.663 0.102 301.22)', |
| 1022 | 1183 | 600: 'oklch(0.580 0.119 301.34)', |
| 1023 | 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 | 1187 | baelz: { |
| 1027 | 1188 | 400: 'oklch(0.720 0.215 22.00)', |
| 1028 | 1189 | 500: 'oklch(0.640 0.255 22.00)', |
| 1029 | 1190 | 600: 'oklch(0.555 0.268 22.00)', |
| 1030 | 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 | 1194 | amelia: { |
| 1034 | 1195 | 400: 'oklch(0.800 0.085 75.49)', |
| 1035 | 1196 | 500: 'oklch(0.710 0.090 72.47)', |
| 1036 | 1197 | 600: 'oklch(0.594 0.085 69.07)', |
| 1037 | 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 | 1201 | suisei: { |
| 1041 | 1202 | 400: 'oklch(0.827 0.096 224.60)', |
| 1042 | 1203 | 500: 'oklch(0.740 0.119 230.91)', |
| 1043 | 1204 | 600: 'oklch(0.645 0.127 236.29)', |
| 1044 | 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 | 1208 | miku: { |
| 1048 | 1209 | 400: 'oklch(0.788 0.133 184.43)', |
| 1049 | 1210 | 500: 'oklch(0.711 0.123 185.28)', |
| 1050 | 1211 | 600: 'oklch(0.607 0.104 187.31)', |
| 1051 | 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 | 1215 | fubuki: { |
| 1055 | 1216 | dark: { |
| @@ -1057,16 +1218,16 @@ const accentPalettes: Record<string, PaletteEntry> = { |
| 1057 | 1218 | 500: 'oklch(0.78 0 0)', |
| 1058 | 1219 | 600: 'oklch(0.68 0 0)', |
| 1059 | 1220 | 700: 'oklch(0.58 0 0)', |
| 1060 | | 800: 'oklch(0.48 0 0)', |
| 1221 | 800: 'oklch(0.48 0 0)' |
| 1061 | 1222 | }, |
| 1062 | 1223 | light: { |
| 1063 | 1224 | 400: 'oklch(0.52 0 0)', |
| 1064 | 1225 | 500: 'oklch(0.42 0 0)', |
| 1065 | 1226 | 600: 'oklch(0.32 0 0)', |
| 1066 | 1227 | 700: 'oklch(0.22 0 0)', |
| 1067 | | 800: 'oklch(0.12 0 0)', |
| 1068 | | }, |
| 1069 | | }, |
| 1228 | 800: 'oklch(0.12 0 0)' |
| 1229 | } |
| 1230 | } |
| 1070 | 1231 | } |
| 1071 | 1232 | |
| 1072 | 1233 | const accentColor = useStorage(AccentColorStorageKey, 'ayanami') |
| @@ -1091,7 +1252,7 @@ const accentBgTokens: Record<'dark' | 'light', Record<string, TintEntry>> = { |
| 1091 | 1252 | '--wk-c-menu-bg': [0.295, 0.032], |
| 1092 | 1253 | '--wk-c-nav-solid-bg': [0.2, 0.024], |
| 1093 | 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 | 1257 | light: { |
| 1097 | 1258 | '--vp-c-bg': [0.986, 0.012], |
| @@ -1107,13 +1268,15 @@ const accentBgTokens: Record<'dark' | 'light', Record<string, TintEntry>> = { |
| 1107 | 1268 | '--wk-c-menu-bg': [0.928, 0.026], |
| 1108 | 1269 | '--wk-c-nav-solid-bg': [0.986, 0.012], |
| 1109 | 1270 | '--nav-pill-bg': [0.99, 0.01, 0.8], |
| 1110 | | '--wk-fs-header-divider': [0.715, 0.02, 0.25], |
| 1111 | | }, |
| 1271 | '--wk-fs-header-divider': [0.715, 0.02, 0.25] |
| 1272 | } |
| 1112 | 1273 | } |
| 1113 | | const accentBgTokenKeys = [...new Set([ |
| 1114 | | ...Object.keys(accentBgTokens.dark), |
| 1115 | | ...Object.keys(accentBgTokens.light), |
| 1116 | | ])] |
| 1274 | const accentBgTokenKeys = [ |
| 1275 | ...new Set([ |
| 1276 | ...Object.keys(accentBgTokens.dark), |
| 1277 | ...Object.keys(accentBgTokens.light) |
| 1278 | ]) |
| 1279 | ] |
| 1117 | 1280 | |
| 1118 | 1281 | const applyAccentTheme = () => { |
| 1119 | 1282 | if (import.meta.env.SSR) return |
| @@ -1126,14 +1289,26 @@ const applyAccentTheme = () => { |
| 1126 | 1289 | el.style.setProperty('--vp-c-brand-1', shades['400']) |
| 1127 | 1290 | el.style.setProperty('--vp-c-brand-2', shades['500']) |
| 1128 | 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)`) |
| 1130 | | el.style.setProperty('--vp-c-sidebar-active', `color-mix(in srgb, ${shades['500']} 15%, transparent)`) |
| 1292 | el.style.setProperty( |
| 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 | 1300 | } else { |
| 1132 | 1301 | el.style.setProperty('--vp-c-brand-1', shades['500']) |
| 1133 | 1302 | el.style.setProperty('--vp-c-brand-2', shades['600']) |
| 1134 | 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)`) |
| 1136 | | el.style.setProperty('--vp-c-sidebar-active', `color-mix(in srgb, ${shades['800']} 15%, transparent)`) |
| 1304 | el.style.setProperty( |
| 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 | 1314 | for (const key of accentBgTokenKeys) el.style.removeProperty(key) |
| @@ -1145,7 +1320,8 @@ const applyAccentTheme = () => { |
| 1145 | 1320 | if (parsed) { |
| 1146 | 1321 | // Tint scales with the accent's own chroma (full tint at C >= 0.10, |
| 1147 | 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 | 1325 | const hue = parsed[2] |
| 1150 | 1326 | const tokens = accentBgTokens[isDark.value ? 'dark' : 'light'] |
| 1151 | 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. |
| 1357 | function resetTableMoreInRoot(root: ParentNode) { |
| 1358 | root.querySelectorAll<HTMLInputElement>('.table-more-checkbox:checked') |
| 1359 | .forEach((el) => { |
| 1360 | el.checked = false |
| 1361 | }) |
| 1362 | } |
| 1363 | |
| 1180 | 1364 | // Wrap bare tables in their own scroll container so they scroll independently of sibling content. |
| 1181 | 1365 | function wrapTablesInRoot(root: ParentNode) { |
| 1182 | | root.querySelectorAll<HTMLTableElement>('table:not(.scrape-table)').forEach(table => { |
| 1183 | | if (table.parentElement?.classList.contains('table-scroll')) return |
| 1184 | | const wrapper = document.createElement('div') |
| 1185 | | wrapper.className = 'table-scroll' |
| 1186 | | table.replaceWith(wrapper) |
| 1187 | | wrapper.appendChild(table) |
| 1188 | | }) |
| 1366 | root.querySelectorAll<HTMLTableElement>('table:not(.scrape-table)').forEach( |
| 1367 | table => { |
| 1368 | if (table.parentElement?.classList.contains('table-scroll')) return |
| 1369 | const wrapper = document.createElement('div') |
| 1370 | wrapper.className = 'table-scroll' |
| 1371 | table.replaceWith(wrapper) |
| 1372 | wrapper.appendChild(table) |
| 1373 | } |
| 1374 | ) |
| 1189 | 1375 | } |
| 1190 | 1376 | |
| 1191 | 1377 | function initCopyButtonsInRoot(root: ParentNode) { |
| @@ -1269,6 +1455,7 @@ let copyButtonObserver: MutationObserver | null = null |
| 1269 | 1455 | |
| 1270 | 1456 | function setupManualCopyButtons() { |
| 1271 | 1457 | wrapTablesInRoot(document) |
| 1458 | resetTableMoreInRoot(document) |
| 1272 | 1459 | initCopyButtonsInRoot(document) |
| 1273 | 1460 | |
| 1274 | 1461 | copyButtonObserver?.disconnect() |
| @@ -1278,6 +1465,7 @@ function setupManualCopyButtons() { |
| 1278 | 1465 | if (!(node instanceof HTMLElement)) continue |
| 1279 | 1466 | if (node.classList.contains('plugin-tabs--content')) { |
| 1280 | 1467 | wrapTablesInRoot(node) |
| 1468 | resetTableMoreInRoot(node) |
| 1281 | 1469 | initCopyButtonsInRoot(node) |
| 1282 | 1470 | if (faviconsEnabled.value) applyFavicons(node) |
| 1283 | 1471 | reapplyHighlightIfNeeded(node) |
| @@ -1285,6 +1473,7 @@ function setupManualCopyButtons() { |
| 1285 | 1473 | node.querySelectorAll<HTMLElement>('.plugin-tabs--content').forEach( |
| 1286 | 1474 | (panel) => { |
| 1287 | 1475 | wrapTablesInRoot(panel) |
| 1476 | resetTableMoreInRoot(panel) |
| 1288 | 1477 | initCopyButtonsInRoot(panel) |
| 1289 | 1478 | if (faviconsEnabled.value) applyFavicons(panel) |
| 1290 | 1479 | reapplyHighlightIfNeeded(panel) |
| @@ -1302,7 +1491,10 @@ watch( |
| 1302 | 1491 | () => { |
| 1303 | 1492 | highlightTerm = '' |
| 1304 | 1493 | highlightTabPath = null |
| 1305 | | nextTick(() => { initTitleOnly(); setupManualCopyButtons() }) |
| 1494 | nextTick(() => { |
| 1495 | initTitleOnly() |
| 1496 | setupManualCopyButtons() |
| 1497 | }) |
| 1306 | 1498 | }, |
| 1307 | 1499 | { flush: 'post' } |
| 1308 | 1500 | ) |
| @@ -1315,6 +1507,11 @@ onMounted(() => { |
| 1315 | 1507 | initTitleOnly() |
| 1316 | 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 | 1515 | // Icon tooltip: fixed-position popup appended to <body> to escape table overflow clipping |
| 1319 | 1516 | const tooltipEl = document.createElement('div') |
| 1320 | 1517 | tooltipEl.className = 'icon-tip-popup' |
| @@ -1421,6 +1618,11 @@ onMounted(() => { |
| 1421 | 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 | 1626 | useEventListener(document, 'keydown', (e: KeyboardEvent) => { |
| 1425 | 1627 | if (!e.isTrusted || (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight')) { |
| 1426 | 1628 | return |
| @@ -1627,4 +1829,4 @@ onUnmounted(() => { |
| 1627 | 1829 | </span> |
| 1628 | 1830 | </template> |
| 1629 | 1831 | </Layout> |
| 1630 | | </template> |
| \ No newline at end of file |
| 1832 | </template> |