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