Commit 704ae192f6
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/Search.vue +38 −153
| @@ -29,7 +29,6 @@ import { | ||
| 29 | 29 | watchDebounced |
| 30 | 30 | } from '@vueuse/core' |
| 31 | 31 | import { useFocusTrap } from '@vueuse/integrations/useFocusTrap' |
| 32 | import { AnimatePresence, motion } from 'motion-v' | |
| 33 | 32 | |
| 34 | 33 | // @ts-ignore |
| 35 | 34 | import localSearchIndex from '@localSearchIndex' |
| @@ -504,7 +503,7 @@ watchDebounced( | ||
| 504 | 503 | } |
| 505 | 504 | centerExcerptsUntilSettled() |
| 506 | 505 | }, |
| 507 | { debounce: 180, immediate: true } | |
| 506 | { debounce: 80, immediate: true } | |
| 508 | 507 | ) |
| 509 | 508 | |
| 510 | 509 | function centerExcerpts() { |
| @@ -534,18 +533,14 @@ function centerExcerpts() { | ||
| 534 | 533 | |
| 535 | 534 | let centerHandle = 0 |
| 536 | 535 | |
| 537 | function centerExcerptsUntilSettled(duration = 450) { | |
| 536 | function centerExcerptsUntilSettled() { | |
| 537 | // No layout animations to wait on anymore — a single pass after the | |
| 538 | // DOM has painted is enough. | |
| 538 | 539 | if (centerHandle) cancelAnimationFrame(centerHandle) |
| 539 | const start = performance.now() | |
| 540 | const tick = () => { | |
| 540 | centerHandle = requestAnimationFrame(() => { | |
| 541 | 541 | 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 | }) | |
| 549 | 544 | } |
| 550 | 545 | |
| 551 | 546 | onBeforeUnmount(() => { |
| @@ -824,51 +819,17 @@ function onMouseMove(e: MouseEvent) { | ||
| 824 | 819 | class="VPLocalSearchBox" |
| 825 | 820 | :class="{ 'pointer-events-none': !showSearch }" |
| 826 | 821 | > |
| 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 | |
| 872 | 833 | class="search-bar" |
| 873 | 834 | @pointerup="onSearchBarClick($event)" |
| 874 | 835 | @submit.prevent="" |
| @@ -943,18 +904,12 @@ function onMouseMove(e: MouseEvent) { | ||
| 943 | 904 | <Delete :size="19" stroke-width="1.25" /> |
| 944 | 905 | </button> |
| 945 | 906 | </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 | > | |
| 958 | 913 | <button |
| 959 | 914 | v-if="ribbonCanScrollLeft" |
| 960 | 915 | type="button" |
| @@ -999,8 +954,7 @@ function onMouseMove(e: MouseEvent) { | ||
| 999 | 954 | > |
| 1000 | 955 | <ChevronRight :size="18" stroke-width="1.75" /> |
| 1001 | 956 | </button> |
| 1002 | </motion.div> | |
| 1003 | </AnimatePresence> | |
| 957 | </div> | |
| 1004 | 958 | |
| 1005 | 959 | <ul |
| 1006 | 960 | ref="resultsEl" |
| @@ -1010,31 +964,10 @@ function onMouseMove(e: MouseEvent) { | ||
| 1010 | 964 | class="results" |
| 1011 | 965 | @mousemove="onMouseMove" |
| 1012 | 966 | > |
| 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 | > | |
| 1038 | 971 | <img |
| 1039 | 972 | class="h-40 object-contain object-center -translate-x-2" |
| 1040 | 973 | src="/asset/smolame.png" |
| @@ -1044,39 +977,15 @@ function onMouseMove(e: MouseEvent) { | ||
| 1044 | 977 | Couldn't find anything, try again? |
| 1045 | 978 | </h1> |
| 1046 | 979 | <h1 v-else>Looking for something?</h1> |
| 1047 | </motion.div> | |
| 1048 | </AnimatePresence> | |
| 980 | </div> | |
| 1049 | 981 | |
| 1050 | <AnimatePresence> | |
| 1051 | <motion.li | |
| 982 | <li | |
| 1052 | 983 | v-for="(p, index) in filteredResults" |
| 1053 | 984 | :key="p.id" |
| 1054 | layout | |
| 1055 | 985 | class="result-layout" |
| 1056 | 986 | :id="'localsearch-item-' + (index + 1)" |
| 1057 | 987 | :aria-selected="selectedIndex === index + 1 ? 'true' : 'false'" |
| 1058 | 988 | 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 | }" | |
| 1080 | 989 | > |
| 1081 | 990 | <a |
| 1082 | 991 | :href="p.id" |
| @@ -1118,37 +1027,22 @@ function onMouseMove(e: MouseEvent) { | ||
| 1118 | 1027 | </div> |
| 1119 | 1028 | |
| 1120 | 1029 | <div v-if="showDetailedList" class="excerpt-wrapper"> |
| 1121 | <motion.div | |
| 1030 | <div | |
| 1122 | 1031 | v-if="p.text" |
| 1123 | layout | |
| 1124 | 1032 | class="excerpt" |
| 1125 | 1033 | 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 | }" | |
| 1139 | 1034 | > |
| 1140 | 1035 | <div class="vp-doc" v-html="p.text" /> |
| 1141 | </motion.div> | |
| 1036 | </div> | |
| 1142 | 1037 | <div class="excerpt-gradient-bottom" /> |
| 1143 | 1038 | <div class="excerpt-gradient-top" /> |
| 1144 | 1039 | </div> |
| 1145 | 1040 | </div> |
| 1146 | 1041 | </a> |
| 1147 | </motion.li> | |
| 1148 | </AnimatePresence> | |
| 1042 | </li> | |
| 1149 | 1043 | </ul> |
| 1150 | 1044 | |
| 1151 | <motion.div layout class="search-keyboard-shortcuts"> | |
| 1045 | <div class="search-keyboard-shortcuts"> | |
| 1152 | 1046 | <span> |
| 1153 | 1047 | <kbd |
| 1154 | 1048 | :aria-label="translate( |
| @@ -1178,9 +1072,8 @@ function onMouseMove(e: MouseEvent) { | ||
| 1178 | 1072 | </kbd> |
| 1179 | 1073 | {{ translate('modal.footer.closeText') }} |
| 1180 | 1074 | </span> |
| 1181 | </motion.div> | |
| 1182 | </motion.div> | |
| 1183 | </AnimatePresence> | |
| 1075 | </div> | |
| 1076 | </div> | |
| 1184 | 1077 | |
| 1185 | 1078 | <button v-if="!showSearch" /> |
| 1186 | 1079 | </div> |
| @@ -1199,8 +1092,6 @@ function onMouseMove(e: MouseEvent) { | ||
| 1199 | 1092 | position: absolute; |
| 1200 | 1093 | inset: 0; |
| 1201 | 1094 | background: var(--vp-backdrop-bg-color); |
| 1202 | transition: opacity 0.5s; | |
| 1203 | will-change: opacity; | |
| 1204 | 1095 | } |
| 1205 | 1096 | |
| 1206 | 1097 | .shell { |
| @@ -1215,7 +1106,6 @@ function onMouseMove(e: MouseEvent) { | ||
| 1215 | 1106 | height: min-content; |
| 1216 | 1107 | max-height: min(100vh - 128px, 900px); |
| 1217 | 1108 | border-radius: 6px; |
| 1218 | will-change: transform, opacity, height; | |
| 1219 | 1109 | } |
| 1220 | 1110 | |
| 1221 | 1111 | @media (max-width: 767px) { |
| @@ -1235,7 +1125,6 @@ function onMouseMove(e: MouseEvent) { | ||
| 1235 | 1125 | align-items: center; |
| 1236 | 1126 | padding: 0 12px; |
| 1237 | 1127 | cursor: text; |
| 1238 | will-change: height; | |
| 1239 | 1128 | } |
| 1240 | 1129 | |
| 1241 | 1130 | @media (max-width: 767px) { |
| @@ -1486,10 +1375,6 @@ function onMouseMove(e: MouseEvent) { | ||
| 1486 | 1375 | overscroll-behavior: contain; |
| 1487 | 1376 | } |
| 1488 | 1377 | |
| 1489 | .result-layout { | |
| 1490 | will-change: transform, opacity, height; | |
| 1491 | } | |
| 1492 | ||
| 1493 | 1378 | .result { |
| 1494 | 1379 | display: flex; |
| 1495 | 1380 | align-items: center; |
| @@ -1553,11 +1438,11 @@ function onMouseMove(e: MouseEvent) { | ||
| 1553 | 1438 | .excerpt { |
| 1554 | 1439 | opacity: 50%; |
| 1555 | 1440 | pointer-events: none; |
| 1441 | height: 84px; | |
| 1556 | 1442 | max-height: 84px; |
| 1557 | 1443 | overflow: hidden; |
| 1558 | 1444 | position: relative; |
| 1559 | 1445 | margin-top: 4px; |
| 1560 | will-change: height; | |
| 1561 | 1446 | } |
| 1562 | 1447 | |
| 1563 | 1448 | .result.selected .excerpt { |