Commit 704ae192f6

704ae192f64e374e5e15a6d9381802b797e7cff3

parent: de045e8d05

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-05-31 01:48 UTC

Update Search.vue

Layout: unified · split

docs/.vitepress/theme/components/Search.vue +38 −153
@@ -29,7 +29,6 @@ import {
2929 watchDebounced
3030} from '@vueuse/core'
3131import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'
32import { AnimatePresence, motion } from 'motion-v'
3332
3433// @ts-ignore
3534import localSearchIndex from '@localSearchIndex'
@@ -504,7 +503,7 @@ watchDebounced(
504503 }
505504 centerExcerptsUntilSettled()
506505 },
507 { debounce: 180, immediate: true }
506 { debounce: 80, immediate: true }
508507)
509508
510509function centerExcerpts() {
@@ -534,18 +533,14 @@ function centerExcerpts() {
534533
535534let centerHandle = 0
536535
537function centerExcerptsUntilSettled(duration = 450) {
536function centerExcerptsUntilSettled() {
537 // No layout animations to wait on anymore — a single pass after the
538 // DOM has painted is enough.
538539 if (centerHandle) cancelAnimationFrame(centerHandle)
539 const start = performance.now()
540 const tick = () => {
540 centerHandle = requestAnimationFrame(() => {
541541 centerExcerpts()
542 if (performance.now() - start < duration) {
543 centerHandle = requestAnimationFrame(tick)
544 } else {
545 centerHandle = 0
546 }
547 }
548 centerHandle = requestAnimationFrame(tick)
542 centerHandle = 0
543 })
549544}
550545
551546onBeforeUnmount(() => {
@@ -824,51 +819,17 @@ function onMouseMove(e: MouseEvent) {
824819 class="VPLocalSearchBox"
825820 :class="{ 'pointer-events-none': !showSearch }"
826821 >
827 <AnimatePresence>
828 <motion.div
829 v-if="showSearch"
830 class="backdrop"
831 @click="showSearch = false"
832 :initial="{
833 opacity: 0
834 }"
835 :animate="{
836 opacity: 1
837 }"
838 :exit="{
839 opacity: 0
840 }"
841 :transition="{
842 duration: 0.55,
843 ease: [0.16, 1, 0.3, 1]
844 }"
845 />
846 </AnimatePresence>
847
848 <AnimatePresence>
849 <motion.div
850 v-if="showSearch"
851 layout="size"
852 class="shell"
853 :initial="{
854 opacity: 0,
855 scale: 0.9375
856 }"
857 :animate="{
858 opacity: 1,
859 scale: 1
860 }"
861 :exit="{
862 opacity: 0,
863 scale: 0.9375
864 }"
865 :transition="{
866 duration: 0.55,
867 ease: [0.16, 1, 0.3, 1]
868 }"
869 >
870 <motion.form
871 layout="position"
822 <div
823 v-if="showSearch"
824 class="backdrop"
825 @click="showSearch = false"
826 />
827
828 <div
829 v-if="showSearch"
830 class="shell"
831 >
832 <form
872833 class="search-bar"
873834 @pointerup="onSearchBarClick($event)"
874835 @submit.prevent=""
@@ -943,18 +904,12 @@ function onMouseMove(e: MouseEvent) {
943904 <Delete :size="19" stroke-width="1.25" />
944905 </button>
945906 </div>
946 </motion.form>
947
948 <AnimatePresence>
949 <motion.div
950 v-if="pageGroups.length > 1"
951 layout="position"
952 class="page-ribbon"
953 :initial="{ opacity: 0, height: 0 }"
954 :animate="{ opacity: 1, height: 'auto' }"
955 :exit="{ opacity: 0, height: 0 }"
956 :transition="{ duration: 0.4, ease: [0.16, 1, 0.3, 1] }"
957 >
907 </form>
908
909 <div
910 v-if="pageGroups.length > 1"
911 class="page-ribbon"
912 >
958913 <button
959914 v-if="ribbonCanScrollLeft"
960915 type="button"
@@ -999,8 +954,7 @@ function onMouseMove(e: MouseEvent) {
999954 >
1000955 <ChevronRight :size="18" stroke-width="1.75" />
1001956 </button>
1002 </motion.div>
1003 </AnimatePresence>
957 </div>
1004958
1005959 <ul
1006960 ref="resultsEl"
@@ -1010,31 +964,10 @@ function onMouseMove(e: MouseEvent) {
1010964 class="results"
1011965 @mousemove="onMouseMove"
1012966 >
1013 <AnimatePresence>
1014 <motion.div
1015 class="flex flex-col justify-center items-center h-47.5 gap-2 font-medium text-sm text-gray-500 dark:text-gray-300 m-auto md:mt-10 md:mb-6 opacity-90"
1016 v-if="!filterText || (filterText && !filteredResults.length)"
1017 :initial="{
1018 opacity: 0
1019 }"
1020 :animate="{
1021 opacity: 1,
1022 transition: {
1023 delay: 0.1
1024 }
1025 }"
1026 :exit="{
1027 opacity: 0,
1028 height: 0,
1029 transition: {
1030 duration: 0.2
1031 }
1032 }"
1033 :transition="{
1034 duration: 0.7,
1035 ease: [0.16, 1, 0.3, 1]
1036 }"
1037 >
967 <div
968 class="flex flex-col justify-center items-center h-47.5 gap-2 font-medium text-sm text-gray-500 dark:text-gray-300 m-auto md:mt-10 md:mb-6 opacity-90"
969 v-if="!filterText || (filterText && !filteredResults.length)"
970 >
1038971 <img
1039972 class="h-40 object-contain object-center -translate-x-2"
1040973 src="/asset/smolame.png"
@@ -1044,39 +977,15 @@ function onMouseMove(e: MouseEvent) {
1044977 Couldn't find anything, try again?
1045978 </h1>
1046979 <h1 v-else>Looking for something?</h1>
1047 </motion.div>
1048 </AnimatePresence>
980 </div>
1049981
1050 <AnimatePresence>
1051 <motion.li
982 <li
1052983 v-for="(p, index) in filteredResults"
1053984 :key="p.id"
1054 layout
1055985 class="result-layout"
1056986 :id="'localsearch-item-' + (index + 1)"
1057987 :aria-selected="selectedIndex === index + 1 ? 'true' : 'false'"
1058988 role="option"
1059 :initial="{
1060 opacity: 0,
1061 scale: 0.9375
1062 }"
1063 :animate="{
1064 opacity: 1,
1065 scale: 1
1066 }"
1067 :exit="{
1068 opacity: 0,
1069 scale: 0.9375,
1070 height: 0,
1071 transition: {
1072 duration: 0.25
1073 }
1074 }"
1075 :transition="{
1076 duration: 0.55,
1077 ease: [0.16, 1, 0.3, 1],
1078 delay: index * 0.02
1079 }"
1080989 >
1081990 <a
1082991 :href="p.id"
@@ -1118,37 +1027,22 @@ function onMouseMove(e: MouseEvent) {
11181027 </div>
11191028
11201029 <div v-if="showDetailedList" class="excerpt-wrapper">
1121 <motion.div
1030 <div
11221031 v-if="p.text"
1123 layout
11241032 class="excerpt"
11251033 inert
1126 :initial="{
1127 height: 0
1128 }"
1129 :animate="{
1130 height: '84px'
1131 }"
1132 :exit="{
1133 height: 0
1134 }"
1135 :transition="{
1136 duration: 0.4,
1137 ease: [0.16, 1, 0.3, 1]
1138 }"
11391034 >
11401035 <div class="vp-doc" v-html="p.text" />
1141 </motion.div>
1036 </div>
11421037 <div class="excerpt-gradient-bottom" />
11431038 <div class="excerpt-gradient-top" />
11441039 </div>
11451040 </div>
11461041 </a>
1147 </motion.li>
1148 </AnimatePresence>
1042 </li>
11491043 </ul>
11501044
1151 <motion.div layout class="search-keyboard-shortcuts">
1045 <div class="search-keyboard-shortcuts">
11521046 <span>
11531047 <kbd
11541048 :aria-label="translate(
@@ -1178,9 +1072,8 @@ function onMouseMove(e: MouseEvent) {
11781072 </kbd>
11791073 {{ translate('modal.footer.closeText') }}
11801074 </span>
1181 </motion.div>
1182 </motion.div>
1183 </AnimatePresence>
1075 </div>
1076 </div>
11841077
11851078 <button v-if="!showSearch" />
11861079 </div>
@@ -1199,8 +1092,6 @@ function onMouseMove(e: MouseEvent) {
11991092 position: absolute;
12001093 inset: 0;
12011094 background: var(--vp-backdrop-bg-color);
1202 transition: opacity 0.5s;
1203 will-change: opacity;
12041095}
12051096
12061097.shell {
@@ -1215,7 +1106,6 @@ function onMouseMove(e: MouseEvent) {
12151106 height: min-content;
12161107 max-height: min(100vh - 128px, 900px);
12171108 border-radius: 6px;
1218 will-change: transform, opacity, height;
12191109}
12201110
12211111@media (max-width: 767px) {
@@ -1235,7 +1125,6 @@ function onMouseMove(e: MouseEvent) {
12351125 align-items: center;
12361126 padding: 0 12px;
12371127 cursor: text;
1238 will-change: height;
12391128}
12401129
12411130@media (max-width: 767px) {
@@ -1486,10 +1375,6 @@ function onMouseMove(e: MouseEvent) {
14861375 overscroll-behavior: contain;
14871376}
14881377
1489.result-layout {
1490 will-change: transform, opacity, height;
1491}
1492
14931378.result {
14941379 display: flex;
14951380 align-items: center;
@@ -1553,11 +1438,11 @@ function onMouseMove(e: MouseEvent) {
15531438.excerpt {
15541439 opacity: 50%;
15551440 pointer-events: none;
1441 height: 84px;
15561442 max-height: 84px;
15571443 overflow: hidden;
15581444 position: relative;
15591445 margin-top: 4px;
1560 will-change: height;
15611446}
15621447
15631448.result.selected .excerpt {