Commit f5dd6fbdfc
Unsigned
Layout: unified · split
docs/.vitepress/theme/Layout.vue −2
| @@ -33,7 +33,6 @@ import NotFoundComponent from './components/NotFound.vue' | |||
| 33 | import { NolebaseEnhancedReadabilitiesScreenMenu } from './components/settings' | 33 | import { NolebaseEnhancedReadabilitiesScreenMenu } from './components/settings' |
| 34 | import NavActions from './components/NavActions.vue' | 34 | import NavActions from './components/NavActions.vue' |
| 35 | import SidebarCard from './components/SidebarCard.vue' | 35 | import SidebarCard from './components/SidebarCard.vue' |
| 36 | import PetChaser from './components/PetChaser.vue' | ||
| 37 | import { AccentBgStorageKey, AccentBgStrengthStorageKey, AccentColorStorageKey } from './constants' | 36 | import { AccentBgStorageKey, AccentBgStrengthStorageKey, AccentColorStorageKey } from './constants' |
| 38 | import { useEffects } from './composables/useEffects' | 37 | import { useEffects } from './composables/useEffects' |
| 39 | 38 | ||
| @@ -1305,7 +1304,6 @@ onUnmounted(() => { | |||
| 1305 | <template> | 1304 | <template> |
| 1306 | <Layout> | 1305 | <Layout> |
| 1307 | <template #layout-top> | 1306 | <template #layout-top> |
| 1308 | <PetChaser /> | ||
| 1309 | <!-- Home sidebar menu --> | 1307 | <!-- Home sidebar menu --> |
| 1310 | <template v-if="isHome"> | 1308 | <template v-if="isHome"> |
| 1311 | <Transition name="home-fade"> | 1309 | <Transition name="home-fade"> |
docs/.vitepress/theme/components/CardField.vue deleted −24
| @@ -1,24 +0,0 @@ | |||
| 1 | <!-- | ||
| 2 | All Rights Reserved | ||
| 3 | |||
| 4 | Copyright (c) 2025 taskylizard | ||
| 5 | |||
| 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 | --> | ||
| 8 | <script setup lang="ts"> | ||
| 9 | defineProps<{ | ||
| 10 | icon: string | ||
| 11 | iconClass?: string | ||
| 12 | }>() | ||
| 13 | </script> | ||
| 14 | |||
| 15 | <template> | ||
| 16 | <div class="g-[12px] mb-[8px] flex items-center"> | ||
| 17 | <span class="flex items-center"> | ||
| 18 | <span class="size-6" :class="[icon, iconClass]" /> | ||
| 19 | <div class="ml-2 text-sm text-$vp-c-text-2"> | ||
| 20 | <slot /> | ||
| 21 | </div> | ||
| 22 | </span> | ||
| 23 | </div> | ||
| 24 | </template> | ||
docs/.vitepress/theme/components/FollowChaser.vue deleted −97
| @@ -1,97 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { onMounted, onUnmounted, ref, watch } from 'vue' | ||
| 3 | |||
| 4 | import { v2add, v2mag, v2norm, v2smul, v2sub, type Vec2D } from '../math' | ||
| 5 | |||
| 6 | const props = defineProps<{ | ||
| 7 | active: boolean | ||
| 8 | src: string | ||
| 9 | alt?: string | ||
| 10 | }>() | ||
| 11 | |||
| 12 | const speed = 2 | ||
| 13 | const snapThreshold = 5 // px | ||
| 14 | |||
| 15 | const chaserRef = ref<HTMLImageElement | null>(null) | ||
| 16 | let mousePos: Vec2D | null = null | ||
| 17 | let target: Vec2D | null = null | ||
| 18 | let offset: Vec2D = [0, 0] | ||
| 19 | |||
| 20 | const position = ref({ x: 0, y: 0 }) | ||
| 21 | |||
| 22 | const updateMousePos = (e: MouseEvent | TouchEvent) => { | ||
| 23 | if (e instanceof MouseEvent) { | ||
| 24 | mousePos = [e.clientX, e.clientY] | ||
| 25 | } else { | ||
| 26 | mousePos = [e.touches[0].clientX, e.touches[0].clientY] | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | let disable: (() => void) | null = null | ||
| 31 | |||
| 32 | const reload = () => { | ||
| 33 | disable?.() | ||
| 34 | |||
| 35 | if (!props.active) return | ||
| 36 | |||
| 37 | window.addEventListener('mousemove', updateMousePos) | ||
| 38 | window.addEventListener('touchstart', updateMousePos) | ||
| 39 | |||
| 40 | const chaser = chaserRef.value | ||
| 41 | if (chaser) { | ||
| 42 | offset = v2smul([chaser.clientWidth, chaser.clientHeight], 0.5) | ||
| 43 | setTimeout(() => { | ||
| 44 | chaser.classList.remove('opacity-0') | ||
| 45 | }, 1000) | ||
| 46 | } | ||
| 47 | |||
| 48 | const intervalId = setInterval(() => { | ||
| 49 | if (!mousePos) return | ||
| 50 | |||
| 51 | const currentPos: Vec2D = [ | ||
| 52 | position.value.x + offset[0], | ||
| 53 | position.value.y + offset[1] | ||
| 54 | ] | ||
| 55 | |||
| 56 | target = target ?? currentPos | ||
| 57 | |||
| 58 | const diff = v2sub(mousePos, currentPos) | ||
| 59 | |||
| 60 | target = v2mag(diff) < snapThreshold | ||
| 61 | ? mousePos | ||
| 62 | : v2add(target, v2smul(v2norm(diff), speed)) | ||
| 63 | |||
| 64 | const finalVec = v2sub(target, offset) | ||
| 65 | |||
| 66 | position.value = { x: finalVec[0], y: finalVec[1] } | ||
| 67 | }, 10) | ||
| 68 | |||
| 69 | disable = () => { | ||
| 70 | chaser?.classList.add('opacity-0') | ||
| 71 | |||
| 72 | window.removeEventListener('mousemove', updateMousePos) | ||
| 73 | window.removeEventListener('touchstart', updateMousePos) | ||
| 74 | clearInterval(intervalId) | ||
| 75 | |||
| 76 | disable = null | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | watch(() => props.active, reload) | ||
| 81 | |||
| 82 | onMounted(reload) | ||
| 83 | onUnmounted(() => disable?.()) | ||
| 84 | </script> | ||
| 85 | |||
| 86 | <template> | ||
| 87 | <img | ||
| 88 | ref="chaserRef" | ||
| 89 | :src="src" | ||
| 90 | :alt="alt ?? ''" | ||
| 91 | class="pointer-events-none fixed absolute z-[9999] h-10 w-10 opacity-0 transition-opacity duration-500" | ||
| 92 | :style="{ | ||
| 93 | left: `${position.x}px`, | ||
| 94 | top: `${position.y}px` | ||
| 95 | }" | ||
| 96 | /> | ||
| 97 | </template> | ||
docs/.vitepress/theme/components/OnekoChaser.vue deleted −357
| @@ -1,357 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { onMounted, onUnmounted, ref, watch } from 'vue' | ||
| 3 | |||
| 4 | // Adapted from oneko.js by adryd — https://github.com/adryd325/oneko.js | ||
| 5 | |||
| 6 | const props = defineProps<{ active: boolean }>() | ||
| 7 | |||
| 8 | const anchorSelectors = ['.wotaku-hero-logo', '.VPNavBarTitle'] | ||
| 9 | const dragThreshold = 4 | ||
| 10 | |||
| 11 | const nekoRef = ref<HTMLDivElement | null>(null) | ||
| 12 | |||
| 13 | const nekoSpeed = 10 | ||
| 14 | const spriteSets: Record<string, [number, number][]> = { | ||
| 15 | idle: [[-3, -3]], | ||
| 16 | alert: [[-7, -3]], | ||
| 17 | scratchSelf: [ | ||
| 18 | [-5, 0], | ||
| 19 | [-6, 0], | ||
| 20 | [-7, 0] | ||
| 21 | ], | ||
| 22 | scratchWallN: [ | ||
| 23 | [0, 0], | ||
| 24 | [0, -1] | ||
| 25 | ], | ||
| 26 | scratchWallS: [ | ||
| 27 | [-7, -1], | ||
| 28 | [-6, -2] | ||
| 29 | ], | ||
| 30 | scratchWallE: [ | ||
| 31 | [-2, -2], | ||
| 32 | [-2, -3] | ||
| 33 | ], | ||
| 34 | scratchWallW: [ | ||
| 35 | [-4, 0], | ||
| 36 | [-4, -1] | ||
| 37 | ], | ||
| 38 | tired: [[-3, -2]], | ||
| 39 | sleeping: [ | ||
| 40 | [-2, 0], | ||
| 41 | [-2, -1] | ||
| 42 | ], | ||
| 43 | N: [ | ||
| 44 | [-1, -2], | ||
| 45 | [-1, -3] | ||
| 46 | ], | ||
| 47 | NE: [ | ||
| 48 | [0, -2], | ||
| 49 | [0, -3] | ||
| 50 | ], | ||
| 51 | E: [ | ||
| 52 | [-3, 0], | ||
| 53 | [-3, -1] | ||
| 54 | ], | ||
| 55 | SE: [ | ||
| 56 | [-5, -1], | ||
| 57 | [-5, -2] | ||
| 58 | ], | ||
| 59 | S: [ | ||
| 60 | [-6, -3], | ||
| 61 | [-7, -2] | ||
| 62 | ], | ||
| 63 | SW: [ | ||
| 64 | [-5, -3], | ||
| 65 | [-6, -1] | ||
| 66 | ], | ||
| 67 | W: [ | ||
| 68 | [-4, -2], | ||
| 69 | [-4, -3] | ||
| 70 | ], | ||
| 71 | NW: [ | ||
| 72 | [-1, 0], | ||
| 73 | [-1, -1] | ||
| 74 | ] | ||
| 75 | } | ||
| 76 | |||
| 77 | let mode: 'sleep' | 'awake' = 'sleep' | ||
| 78 | |||
| 79 | let nekoPosX = 32 | ||
| 80 | let nekoPosY = 32 | ||
| 81 | let mousePosX = 0 | ||
| 82 | let mousePosY = 0 | ||
| 83 | let frameCount = 0 | ||
| 84 | let idleTime = 0 | ||
| 85 | let idleAnimation: string | null = null | ||
| 86 | let idleAnimationFrame = 0 | ||
| 87 | let sleepFrame = 0 | ||
| 88 | let lastFrameTimestamp: number | undefined | ||
| 89 | let rafId: number | null = null | ||
| 90 | |||
| 91 | let pointerDown = false | ||
| 92 | let didDrag = false | ||
| 93 | let pointerStartX = 0 | ||
| 94 | let pointerStartY = 0 | ||
| 95 | let grabOffsetX = 0 | ||
| 96 | let grabOffsetY = 0 | ||
| 97 | |||
| 98 | const clamp = (v: number, min: number, max: number) => | ||
| 99 | Math.min(Math.max(min, v), max) | ||
| 100 | |||
| 101 | const updateMousePos = (e: MouseEvent) => { | ||
| 102 | mousePosX = e.clientX | ||
| 103 | mousePosY = e.clientY | ||
| 104 | } | ||
| 105 | |||
| 106 | function setSprite(name: string, frame: number) { | ||
| 107 | const neko = nekoRef.value | ||
| 108 | if (!neko) return | ||
| 109 | const set = spriteSets[name] | ||
| 110 | const sprite = set[frame % set.length] | ||
| 111 | neko.style.backgroundPosition = `${sprite[0] * 32}px ${sprite[1] * 32}px` | ||
| 112 | } | ||
| 113 | |||
| 114 | function applyPosition() { | ||
| 115 | const neko = nekoRef.value | ||
| 116 | if (!neko) return | ||
| 117 | neko.style.left = `${nekoPosX - 16}px` | ||
| 118 | neko.style.top = `${nekoPosY - 16}px` | ||
| 119 | } | ||
| 120 | |||
| 121 | function parkOnAnchor() { | ||
| 122 | let rect: DOMRect | null = null | ||
| 123 | for (const selector of anchorSelectors) { | ||
| 124 | const el = document.querySelector(selector) | ||
| 125 | if (el) { | ||
| 126 | rect = el.getBoundingClientRect() | ||
| 127 | break | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | if (rect && rect.width > 0) { | ||
| 132 | nekoPosX = clamp(rect.left + rect.width * 0.72, 16, window.innerWidth - 16) | ||
| 133 | nekoPosY = clamp(rect.top - 4, 16, window.innerHeight - 16) | ||
| 134 | } else { | ||
| 135 | nekoPosX = clamp(64, 16, window.innerWidth - 16) | ||
| 136 | nekoPosY = clamp(64, 16, window.innerHeight - 16) | ||
| 137 | } | ||
| 138 | applyPosition() | ||
| 139 | } | ||
| 140 | |||
| 141 | function resetIdleAnimation() { | ||
| 142 | idleAnimation = null | ||
| 143 | idleAnimationFrame = 0 | ||
| 144 | } | ||
| 145 | |||
| 146 | function idle() { | ||
| 147 | idleTime += 1 | ||
| 148 | |||
| 149 | if ( | ||
| 150 | idleTime > 10 && | ||
| 151 | Math.floor(Math.random() * 200) === 0 && | ||
| 152 | idleAnimation == null | ||
| 153 | ) { | ||
| 154 | const available = ['scratchSelf'] | ||
| 155 | if (nekoPosX < 32) available.push('scratchWallW') | ||
| 156 | if (nekoPosY < 32) available.push('scratchWallN') | ||
| 157 | if (nekoPosX > window.innerWidth - 32) available.push('scratchWallE') | ||
| 158 | if (nekoPosY > window.innerHeight - 32) available.push('scratchWallS') | ||
| 159 | idleAnimation = available[Math.floor(Math.random() * available.length)] | ||
| 160 | } | ||
| 161 | |||
| 162 | switch (idleAnimation) { | ||
| 163 | case 'scratchWallN': | ||
| 164 | case 'scratchWallS': | ||
| 165 | case 'scratchWallE': | ||
| 166 | case 'scratchWallW': | ||
| 167 | case 'scratchSelf': | ||
| 168 | setSprite(idleAnimation, idleAnimationFrame) | ||
| 169 | if (idleAnimationFrame > 9) resetIdleAnimation() | ||
| 170 | break | ||
| 171 | default: | ||
| 172 | setSprite('idle', 0) | ||
| 173 | return | ||
| 174 | } | ||
| 175 | idleAnimationFrame += 1 | ||
| 176 | } | ||
| 177 | |||
| 178 | function sleep() { | ||
| 179 | sleepFrame += 1 | ||
| 180 | if (sleepFrame < 8) { | ||
| 181 | setSprite('tired', 0) | ||
| 182 | return | ||
| 183 | } | ||
| 184 | setSprite('sleeping', Math.floor(sleepFrame / 4)) | ||
| 185 | } | ||
| 186 | |||
| 187 | function chase() { | ||
| 188 | frameCount += 1 | ||
| 189 | const diffX = nekoPosX - mousePosX | ||
| 190 | const diffY = nekoPosY - mousePosY | ||
| 191 | const distance = Math.sqrt(diffX ** 2 + diffY ** 2) | ||
| 192 | |||
| 193 | if (distance < nekoSpeed || distance < 48) { | ||
| 194 | idle() | ||
| 195 | return | ||
| 196 | } | ||
| 197 | |||
| 198 | idleAnimation = null | ||
| 199 | idleAnimationFrame = 0 | ||
| 200 | |||
| 201 | if (idleTime > 1) { | ||
| 202 | setSprite('alert', 0) | ||
| 203 | idleTime = Math.min(idleTime, 7) | ||
| 204 | idleTime -= 1 | ||
| 205 | return | ||
| 206 | } | ||
| 207 | |||
| 208 | let direction = diffY / distance > 0.5 ? 'N' : '' | ||
| 209 | direction += diffY / distance < -0.5 ? 'S' : '' | ||
| 210 | direction += diffX / distance > 0.5 ? 'W' : '' | ||
| 211 | direction += diffX / distance < -0.5 ? 'E' : '' | ||
| 212 | setSprite(direction, frameCount) | ||
| 213 | |||
| 214 | nekoPosX -= (diffX / distance) * nekoSpeed | ||
| 215 | nekoPosY -= (diffY / distance) * nekoSpeed | ||
| 216 | |||
| 217 | nekoPosX = clamp(nekoPosX, 16, window.innerWidth - 16) | ||
| 218 | nekoPosY = clamp(nekoPosY, 16, window.innerHeight - 16) | ||
| 219 | |||
| 220 | applyPosition() | ||
| 221 | } | ||
| 222 | |||
| 223 | function frame() { | ||
| 224 | if (pointerDown && didDrag) { | ||
| 225 | setSprite('alert', 0) | ||
| 226 | return | ||
| 227 | } | ||
| 228 | if (mode === 'sleep') { | ||
| 229 | sleep() | ||
| 230 | return | ||
| 231 | } | ||
| 232 | chase() | ||
| 233 | } | ||
| 234 | |||
| 235 | function onAnimationFrame(timestamp: number) { | ||
| 236 | if (rafId == null) return | ||
| 237 | if (!lastFrameTimestamp) lastFrameTimestamp = timestamp | ||
| 238 | if (timestamp - lastFrameTimestamp > 100) { | ||
| 239 | lastFrameTimestamp = timestamp | ||
| 240 | frame() | ||
| 241 | } | ||
| 242 | rafId = requestAnimationFrame(onAnimationFrame) | ||
| 243 | } | ||
| 244 | |||
| 245 | function wake() { | ||
| 246 | mode = 'awake' | ||
| 247 | idleTime = 0 | ||
| 248 | resetIdleAnimation() | ||
| 249 | } | ||
| 250 | |||
| 251 | function goToSleep() { | ||
| 252 | mode = 'sleep' | ||
| 253 | sleepFrame = 0 | ||
| 254 | } | ||
| 255 | |||
| 256 | const onPointerDown = (e: PointerEvent) => { | ||
| 257 | e.preventDefault() | ||
| 258 | pointerDown = true | ||
| 259 | didDrag = false | ||
| 260 | pointerStartX = e.clientX | ||
| 261 | pointerStartY = e.clientY | ||
| 262 | grabOffsetX = e.clientX - nekoPosX | ||
| 263 | grabOffsetY = e.clientY - nekoPosY | ||
| 264 | nekoRef.value?.setPointerCapture?.(e.pointerId) | ||
| 265 | } | ||
| 266 | |||
| 267 | const onPointerMove = (e: PointerEvent) => { | ||
| 268 | if (!pointerDown) return | ||
| 269 | if ( | ||
| 270 | !didDrag && | ||
| 271 | Math.hypot(e.clientX - pointerStartX, e.clientY - pointerStartY) > | ||
| 272 | dragThreshold | ||
| 273 | ) { | ||
| 274 | didDrag = true | ||
| 275 | } | ||
| 276 | if (didDrag) { | ||
| 277 | nekoPosX = clamp(e.clientX - grabOffsetX, 16, window.innerWidth - 16) | ||
| 278 | nekoPosY = clamp(e.clientY - grabOffsetY, 16, window.innerHeight - 16) | ||
| 279 | applyPosition() | ||
| 280 | } | ||
| 281 | } | ||
| 282 | |||
| 283 | const onPointerUp = (e: PointerEvent) => { | ||
| 284 | if (!pointerDown) return | ||
| 285 | pointerDown = false | ||
| 286 | nekoRef.value?.releasePointerCapture?.(e.pointerId) | ||
| 287 | if (didDrag) { | ||
| 288 | goToSleep() | ||
| 289 | } else { | ||
| 290 | mode === 'sleep' ? wake() : goToSleep() | ||
| 291 | } | ||
| 292 | didDrag = false | ||
| 293 | } | ||
| 294 | |||
| 295 | let disable: (() => void) | null = null | ||
| 296 | |||
| 297 | const reload = () => { | ||
| 298 | disable?.() | ||
| 299 | |||
| 300 | if (!props.active) return | ||
| 301 | |||
| 302 | const neko = nekoRef.value | ||
| 303 | if (!neko) return | ||
| 304 | |||
| 305 | goToSleep() | ||
| 306 | parkOnAnchor() | ||
| 307 | neko.classList.remove('opacity-0') | ||
| 308 | |||
| 309 | window.addEventListener('mousemove', updateMousePos) | ||
| 310 | neko.addEventListener('pointerdown', onPointerDown) | ||
| 311 | window.addEventListener('pointermove', onPointerMove) | ||
| 312 | window.addEventListener('pointerup', onPointerUp) | ||
| 313 | |||
| 314 | lastFrameTimestamp = undefined | ||
| 315 | rafId = requestAnimationFrame(onAnimationFrame) | ||
| 316 | |||
| 317 | disable = () => { | ||
| 318 | neko.classList.add('opacity-0') | ||
| 319 | window.removeEventListener('mousemove', updateMousePos) | ||
| 320 | neko.removeEventListener('pointerdown', onPointerDown) | ||
| 321 | window.removeEventListener('pointermove', onPointerMove) | ||
| 322 | window.removeEventListener('pointerup', onPointerUp) | ||
| 323 | if (rafId != null) cancelAnimationFrame(rafId) | ||
| 324 | rafId = null | ||
| 325 | pointerDown = false | ||
| 326 | didDrag = false | ||
| 327 | disable = null | ||
| 328 | } | ||
| 329 | } | ||
| 330 | |||
| 331 | watch(() => props.active, reload) | ||
| 332 | |||
| 333 | onMounted(reload) | ||
| 334 | onUnmounted(() => disable?.()) | ||
| 335 | </script> | ||
| 336 | |||
| 337 | <template> | ||
| 338 | <div | ||
| 339 | id="oneko" | ||
| 340 | ref="nekoRef" | ||
| 341 | aria-hidden="true" | ||
| 342 | title="Click to wake me up!" | ||
| 343 | class="oneko fixed z-[9999] h-8 w-8 opacity-0 transition-opacity duration-500" | ||
| 344 | style="image-rendering: pixelated; background-image: url(/oneko.gif)" | ||
| 345 | /> | ||
| 346 | </template> | ||
| 347 | |||
| 348 | <style scoped> | ||
| 349 | .oneko { | ||
| 350 | cursor: grab; | ||
| 351 | touch-action: none; | ||
| 352 | } | ||
| 353 | |||
| 354 | .oneko:active { | ||
| 355 | cursor: grabbing; | ||
| 356 | } | ||
| 357 | </style> | ||
docs/.vitepress/theme/components/PetChaser.vue deleted −28
| @@ -1,28 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { useStorage } from '@vueuse/core' | ||
| 3 | |||
| 4 | import { PetCharacterStorageKey, PetStorageKey } from '../constants' | ||
| 5 | import { defaultPetKey, petCharacters } from '../pets' | ||
| 6 | import FollowChaser from './FollowChaser.vue' | ||
| 7 | import OnekoChaser from './OnekoChaser.vue' | ||
| 8 | |||
| 9 | const petEnabled = useStorage(PetStorageKey, false) | ||
| 10 | const petCharacter = useStorage(PetCharacterStorageKey, defaultPetKey) | ||
| 11 | |||
| 12 | const chaserCharacters = petCharacters.filter((c) => c.behavior === 'chaser') | ||
| 13 | |||
| 14 | function isActive(key: string) { | ||
| 15 | return petEnabled.value && petCharacter.value === key | ||
| 16 | } | ||
| 17 | </script> | ||
| 18 | |||
| 19 | <template> | ||
| 20 | <FollowChaser | ||
| 21 | v-for="c in chaserCharacters" | ||
| 22 | :key="c.key" | ||
| 23 | :active="isActive(c.key)" | ||
| 24 | :src="c.src!" | ||
| 25 | :alt="c.label" | ||
| 26 | /> | ||
| 27 | <OnekoChaser :active="isActive('oneko')" /> | ||
| 28 | </template> | ||
docs/.vitepress/theme/components/PreferenceRadio.vue deleted −97
| @@ -1,97 +0,0 @@ | |||
| 1 | <!-- | ||
| 2 | All Rights Reserved | ||
| 3 | |||
| 4 | Copyright (c) 2025 taskylizard | ||
| 5 | |||
| 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 | --> | ||
| 8 | <script setup lang="ts"> | ||
| 9 | import { useLocalStorage } from '@vueuse/core' | ||
| 10 | |||
| 11 | const props = defineProps<{ | ||
| 12 | text: string | ||
| 13 | group: string | ||
| 14 | options: string[] | ||
| 15 | defaultOption: string | ||
| 16 | screenMenu?: boolean | ||
| 17 | }>() | ||
| 18 | |||
| 19 | const key = removeSpaces( | ||
| 20 | `preference-${props.group}-${ | ||
| 21 | props.options | ||
| 22 | .map((key) => key.toLowerCase()) | ||
| 23 | .join('-') | ||
| 24 | }` | ||
| 25 | ) | ||
| 26 | const name = key + (props.screenMenu ? '-screen-menu' : '') | ||
| 27 | |||
| 28 | const selected = useLocalStorage(key, () => props.defaultOption) | ||
| 29 | |||
| 30 | const optionsWithKeys = props.options.map((option) => ({ | ||
| 31 | key: name + '-' + removeSpaces(option), | ||
| 32 | value: option | ||
| 33 | })) | ||
| 34 | |||
| 35 | function removeSpaces(str: string) { | ||
| 36 | return str.replace(/\s/g, '_') | ||
| 37 | } | ||
| 38 | </script> | ||
| 39 | |||
| 40 | <template> | ||
| 41 | <p class="title">{{ text }}</p> | ||
| 42 | <div class="VPPreference" :class="{ 'screen-menu': screenMenu }"> | ||
| 43 | <template v-for="option in optionsWithKeys" :key="option"> | ||
| 44 | <input | ||
| 45 | type="radio" | ||
| 46 | :id="option.key" | ||
| 47 | :name="name" | ||
| 48 | :value="option.value" | ||
| 49 | v-model="selected" | ||
| 50 | /> | ||
| 51 | <label :for="option.key">{{ option.value }}</label> | ||
| 52 | </template> | ||
| 53 | </div> | ||
| 54 | </template> | ||
| 55 | |||
| 56 | <style scoped> | ||
| 57 | .VPPreference { | ||
| 58 | display: flex; | ||
| 59 | margin: 12px 0; | ||
| 60 | border: 1px solid var(--vp-c-border); | ||
| 61 | border-radius: 6px; | ||
| 62 | font-size: 14px; | ||
| 63 | color: var(--vp-c-text-1); | ||
| 64 | } | ||
| 65 | |||
| 66 | .VPPreference:first-child { | ||
| 67 | margin-top: 0; | ||
| 68 | } | ||
| 69 | |||
| 70 | .VPPreference:last-child { | ||
| 71 | margin-bottom: 0; | ||
| 72 | } | ||
| 73 | |||
| 74 | .VPPreference.screen-menu { | ||
| 75 | margin: 12px 0 0 12px; | ||
| 76 | } | ||
| 77 | |||
| 78 | .VPPreference input[type="radio"] { | ||
| 79 | pointer-events: none; | ||
| 80 | position: fixed; | ||
| 81 | opacity: 0; | ||
| 82 | } | ||
| 83 | |||
| 84 | .VPPreference label { | ||
| 85 | flex: 1; | ||
| 86 | margin: 2px; | ||
| 87 | padding: 4px 12px; | ||
| 88 | cursor: pointer; | ||
| 89 | border-radius: 4px; | ||
| 90 | text-align: center; | ||
| 91 | } | ||
| 92 | |||
| 93 | .VPPreference input[type="radio"]:checked + label { | ||
| 94 | background-color: var(--vp-c-default-soft); | ||
| 95 | color: var(--vp-c-brand-1); | ||
| 96 | } | ||
| 97 | </style> | ||
docs/.vitepress/theme/components/settings/LayoutSwitch.vue deleted −630
| @@ -1,630 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { NuInputHighlight, NuInputHorizontalRadioGroup } from '@nolebase/ui' | ||
| 3 | import { useLocalStorage, useMediaQuery, useMounted } from '@vueuse/core' | ||
| 4 | import { useRoute } from 'vitepress' | ||
| 5 | import { computed, inject, onMounted, ref, watch } from 'vue' | ||
| 6 | |||
| 7 | import MenuHelp from './MenuHelp.vue' | ||
| 8 | import MenuTitle from './MenuTitle.vue' | ||
| 9 | |||
| 10 | import { useLayoutAppearanceChangeAnimation } from '../../composables/animation' | ||
| 11 | import { | ||
| 12 | InjectionKey, | ||
| 13 | LayoutMode, | ||
| 14 | LayoutSwitchModeStorageKey, | ||
| 15 | supportedLayoutModes | ||
| 16 | } from '../../constants' | ||
| 17 | |||
| 18 | const options = inject(InjectionKey, {}) | ||
| 19 | |||
| 20 | const menuTitleElementRef = ref<HTMLDivElement>() | ||
| 21 | const isMenuHelpPoppedUp = ref(false) | ||
| 22 | const disabled = ref(false) | ||
| 23 | |||
| 24 | const route = useRoute() | ||
| 25 | const mounted = useMounted() | ||
| 26 | const isLargerThanMobile = useMediaQuery('(min-width: 768px)') | ||
| 27 | const layoutMode = useLocalStorage<LayoutMode>( | ||
| 28 | LayoutSwitchModeStorageKey, | ||
| 29 | options.layoutSwitch?.defaultMode || LayoutMode.Original | ||
| 30 | ) | ||
| 31 | const { trigger: triggerAnimation } = useLayoutAppearanceChangeAnimation() | ||
| 32 | |||
| 33 | const fieldOptions = computed(() => [ | ||
| 34 | { | ||
| 35 | value: LayoutMode.FullWidth, | ||
| 36 | title: 'Expand all', | ||
| 37 | helpMessage: | ||
| 38 | 'The sidebar and content area occupy the entire width of the screen.', | ||
| 39 | ariaLabel: 'Expand all', | ||
| 40 | icon: 'i-icon-park-outline:full-screen-one', | ||
| 41 | name: 'VitePress Nolebase Enhanced Readabilities Layout Mode Checkbox' | ||
| 42 | }, | ||
| 43 | { | ||
| 44 | value: LayoutMode.SidebarWidthAdjustableOnly, | ||
| 45 | title: 'Expand sidebar with adjustable values', | ||
| 46 | helpMessage: | ||
| 47 | 'Expand sidebar width and add a new slider for user to choose and customize their desired width of the maximum width of sidebar can go, but the content area width will remain the same.', | ||
| 48 | ariaLabel: 'Expand sidebar with adjustable values', | ||
| 49 | icon: 'i-icon-park-outline:full-screen-two', | ||
| 50 | name: 'VitePress Nolebase Enhanced Readabilities Layout Mode Checkbox' | ||
| 51 | }, | ||
| 52 | { | ||
| 53 | value: LayoutMode.BothWidthAdjustable, | ||
| 54 | title: 'Expand all with adjustable values', | ||
| 55 | helpMessage: | ||
| 56 | 'Expand both sidebar and document content and add two new slider for user to choose and customize their desired width of the maximum width of either sidebar or document content can go.', | ||
| 57 | ariaLabel: 'Expand all with adjustable values', | ||
| 58 | icon: 'i-icon-park-outline:full-screen', | ||
| 59 | name: 'VitePress Nolebase Enhanced Readabilities Layout Mode Checkbox' | ||
| 60 | }, | ||
| 61 | { | ||
| 62 | value: LayoutMode.Original, | ||
| 63 | title: 'Original width', | ||
| 64 | helpMessage: | ||
| 65 | 'Expand both sidebar and document content and add two new slider for user to choose and customize their desired width of the maximum width of either sidebar or document content can go.', | ||
| 66 | ariaLabel: 'Original width', | ||
| 67 | icon: 'i-icon-park-outline:overall-reduction', | ||
| 68 | name: 'VitePress Nolebase Enhanced Readabilities Layout Mode Checkbox' | ||
| 69 | } | ||
| 70 | ]) | ||
| 71 | |||
| 72 | function setClasses(val: LayoutMode, animated: boolean) { | ||
| 73 | switch (val) { | ||
| 74 | case LayoutMode.FullWidth: | ||
| 75 | animated && triggerAnimation(document.body) | ||
| 76 | document.body.classList.add( | ||
| 77 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchFullWidth' | ||
| 78 | ) | ||
| 79 | document.body.classList.remove( | ||
| 80 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchSidebarWidthAdjustableOnly' | ||
| 81 | ) | ||
| 82 | document.body.classList.remove( | ||
| 83 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchBothWidthAdjustable' | ||
| 84 | ) | ||
| 85 | break | ||
| 86 | case LayoutMode.SidebarWidthAdjustableOnly: | ||
| 87 | animated && triggerAnimation(document.body) | ||
| 88 | document.body.classList.remove( | ||
| 89 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchFullWidth' | ||
| 90 | ) | ||
| 91 | document.body.classList.add( | ||
| 92 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchSidebarWidthAdjustableOnly' | ||
| 93 | ) | ||
| 94 | document.body.classList.remove( | ||
| 95 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchBothWidthAdjustable' | ||
| 96 | ) | ||
| 97 | break | ||
| 98 | case LayoutMode.BothWidthAdjustable: | ||
| 99 | animated && triggerAnimation(document.body) | ||
| 100 | document.body.classList.remove( | ||
| 101 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchFullWidth' | ||
| 102 | ) | ||
| 103 | document.body.classList.remove( | ||
| 104 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchSidebarWidthAdjustableOnly' | ||
| 105 | ) | ||
| 106 | document.body.classList.add( | ||
| 107 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchBothWidthAdjustable' | ||
| 108 | ) | ||
| 109 | break | ||
| 110 | case LayoutMode.Original: | ||
| 111 | animated && triggerAnimation(document.body) | ||
| 112 | document.body.classList.remove( | ||
| 113 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchFullWidth' | ||
| 114 | ) | ||
| 115 | document.body.classList.remove( | ||
| 116 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchSidebarWidthAdjustableOnly' | ||
| 117 | ) | ||
| 118 | document.body.classList.remove( | ||
| 119 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchBothWidthAdjustable' | ||
| 120 | ) | ||
| 121 | break | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | watch(mounted, (val) => { | ||
| 126 | if (!val) return | ||
| 127 | |||
| 128 | setClasses(layoutMode.value, !options.layoutSwitch?.disableAnimation) | ||
| 129 | if (!supportedLayoutModes.includes(layoutMode.value)) { | ||
| 130 | layoutMode.value = options.layoutSwitch?.defaultMode || | ||
| 131 | LayoutMode.BothWidthAdjustable | ||
| 132 | } | ||
| 133 | }) | ||
| 134 | |||
| 135 | watch(layoutMode, (val) => { | ||
| 136 | if (!mounted.value) return | ||
| 137 | |||
| 138 | setClasses(val, !options.layoutSwitch?.disableAnimation) | ||
| 139 | if (!supportedLayoutModes.includes(val)) { | ||
| 140 | layoutMode.value = options.layoutSwitch?.defaultMode || | ||
| 141 | LayoutMode.BothWidthAdjustable | ||
| 142 | } | ||
| 143 | }) | ||
| 144 | |||
| 145 | watch(route, () => { | ||
| 146 | setClasses(layoutMode.value, !options.layoutSwitch?.disableAnimation) | ||
| 147 | }) | ||
| 148 | |||
| 149 | watch(isLargerThanMobile, () => { | ||
| 150 | if (!isLargerThanMobile.value) disabled.value = true | ||
| 151 | }) | ||
| 152 | |||
| 153 | onMounted(() => { | ||
| 154 | if (!isLargerThanMobile.value) disabled.value = true | ||
| 155 | }) | ||
| 156 | </script> | ||
| 157 | |||
| 158 | <template> | ||
| 159 | <div space-y-2 role="radiogroup"> | ||
| 160 | <div ref="menuTitleElementRef" flex items-center> | ||
| 161 | <MenuTitle | ||
| 162 | title="Layout Switch" | ||
| 163 | aria-label="Layout Switch" | ||
| 164 | flex="1" | ||
| 165 | :disabled="disabled" | ||
| 166 | pr-4 | ||
| 167 | > | ||
| 168 | <template #icon> | ||
| 169 | <span i-icon-park-outline:layout-one mr-1 aria-hidden="true" /> | ||
| 170 | </template> | ||
| 171 | </MenuTitle> | ||
| 172 | <MenuHelp | ||
| 173 | v-if="!options.layoutSwitch?.disableHelp" | ||
| 174 | v-model:is-popped-up="isMenuHelpPoppedUp" | ||
| 175 | :menu-title-element-ref="menuTitleElementRef" | ||
| 176 | > | ||
| 177 | <h4 text-md mb-1 font-semibold>Layout Switch</h4> | ||
| 178 | <p text="sm" mb-2 max-w-100> | ||
| 179 | <span> | ||
| 180 | Adjust the layout style of VitePress to adapt to different reading | ||
| 181 | needs and screens. | ||
| 182 | </span> | ||
| 183 | </p> | ||
| 184 | <div space-y-2 class="VPNolebaseEnhancedReadabilitiesMenu"> | ||
| 185 | <div | ||
| 186 | v-for="(option, index) in fieldOptions" | ||
| 187 | :key="index" | ||
| 188 | text="sm" | ||
| 189 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 190 | max-w-100 | ||
| 191 | rounded-xl | ||
| 192 | p-3 | ||
| 193 | > | ||
| 194 | <h5 text="sm" mb-2 flex="~" items-center align-middle> | ||
| 195 | <span mr-1 :class="[option.icon]" /> | ||
| 196 | <span font-semibold>{{ option.title }}</span> | ||
| 197 | </h5> | ||
| 198 | <span>{{ option.helpMessage }}</span> | ||
| 199 | </div> | ||
| 200 | </div> | ||
| 201 | </MenuHelp> | ||
| 202 | </div> | ||
| 203 | <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md"> | ||
| 204 | <NuInputHorizontalRadioGroup | ||
| 205 | v-model="layoutMode" | ||
| 206 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 207 | text="sm $vp-nolebase-enhanced-readabilities-menu-text-color" | ||
| 208 | :options="fieldOptions" | ||
| 209 | :disabled="disabled" | ||
| 210 | /> | ||
| 211 | </NuInputHighlight> | ||
| 212 | </div> | ||
| 213 | </template> | ||
| 214 | |||
| 215 | <style less> | ||
| 216 | .VPNolebaseEnhancedReadabilitiesLayoutSwitchAnimated { | ||
| 217 | /* with sidebar */ | ||
| 218 | .VPNavBar.has-sidebar > .wrapper > .container > .title { | ||
| 219 | transition: width 0.5s ease-in-out, padding-left 0.5s ease-in-out; | ||
| 220 | } | ||
| 221 | |||
| 222 | /* without sidebar */ | ||
| 223 | .VPNavBar > .wrapper > .container > .title { | ||
| 224 | transition: width 0.5s ease-in-out, padding-left 0.5s ease-in-out; | ||
| 225 | } | ||
| 226 | |||
| 227 | .VPNavBar > .wrapper > .container { | ||
| 228 | transition: width 0.5s ease-in-out, max-width 0.5s ease-in-out; | ||
| 229 | } | ||
| 230 | |||
| 231 | /* with sidebar */ | ||
| 232 | .VPNavBar.has-sidebar > .wrapper > .container > .content, | ||
| 233 | .VPNavBar > .wrapper > .container > .content { | ||
| 234 | transition: padding-right 0.5s ease-in-out, padding-left 0.5s ease-in-out; | ||
| 235 | } | ||
| 236 | |||
| 237 | /* line below the nav */ | ||
| 238 | .VPNavBar.has-sidebar > .divider { | ||
| 239 | transition: padding-left 0.5s ease-in-out, width 0.5s ease-in-out; | ||
| 240 | } | ||
| 241 | |||
| 242 | .VPSidebar { | ||
| 243 | transition: width 0.5s ease-in-out, padding-left 0.5s ease-in-out; | ||
| 244 | } | ||
| 245 | |||
| 246 | .VPContent.has-sidebar { | ||
| 247 | transition: | ||
| 248 | width 0.5s ease-in-out, | ||
| 249 | padding-left 0.5s ease-in-out, | ||
| 250 | padding-right 0.5s ease-in-out; | ||
| 251 | } | ||
| 252 | |||
| 253 | .VPDoc .container { | ||
| 254 | transition: width 0.5s ease-in-out, max-width 0.5s ease-in-out; | ||
| 255 | } | ||
| 256 | |||
| 257 | .VPDoc.has-aside .content-container { | ||
| 258 | transition: width 0.5s ease-in-out, max-width 0.5s ease-in-out; | ||
| 259 | } | ||
| 260 | |||
| 261 | .VPDoc:not(.has-sidebar) .container { | ||
| 262 | transition: width 0.5s ease-in-out, max-width 0.5s ease-in-out; | ||
| 263 | } | ||
| 264 | |||
| 265 | .VPDoc:not(.has-sidebar) .container > .content { | ||
| 266 | transition: width 0.5s ease-in-out, max-width 0.5s ease-in-out; | ||
| 267 | } | ||
| 268 | } | ||
| 269 | |||
| 270 | :root { | ||
| 271 | --vp-nolebase-enhanced-readabilities-page-max-width: 100%; | ||
| 272 | --vp-nolebase-enhanced-readabilities-content-max-width: 100%; | ||
| 273 | --vp-nolebase-enhanced-readabilities-full-width-max-width: 100%; | ||
| 274 | } | ||
| 275 | |||
| 276 | .VPNolebaseEnhancedReadabilitiesLayoutSwitchFullWidth { | ||
| 277 | @media (min-width: 1280px) { | ||
| 278 | /* Overriding styles of navbar section */ | ||
| 279 | .VPNavBar.has-sidebar > .wrapper > .container > .title { | ||
| 280 | padding-left: max( | ||
| 281 | 32px, | ||
| 282 | calc( | ||
| 283 | ( | ||
| 284 | 100% - | ||
| 285 | ( | ||
| 286 | var(--vp-nolebase-enhanced-readabilities-full-width-max-width) - | ||
| 287 | 64px | ||
| 288 | ) | ||
| 289 | ) / | ||
| 290 | 2 | ||
| 291 | ) | ||
| 292 | ) !important; | ||
| 293 | width: calc( | ||
| 294 | ( | ||
| 295 | 100% - | ||
| 296 | ( | ||
| 297 | var(--vp-nolebase-enhanced-readabilities-full-width-max-width) - | ||
| 298 | 64px | ||
| 299 | ) | ||
| 300 | ) / | ||
| 301 | 2 + | ||
| 302 | var(--vp-sidebar-width) - | ||
| 303 | 32px | ||
| 304 | ) !important; | ||
| 305 | } | ||
| 306 | |||
| 307 | .VPNavBar > .wrapper > .container, | ||
| 308 | .VPNavBar.has-sidebar > .wrapper > .container { | ||
| 309 | max-width: var(--vp-nolebase-enhanced-readabilities-full-width-max-width) | ||
| 310 | !important; | ||
| 311 | } | ||
| 312 | |||
| 313 | .VPNavBar.has-sidebar > .wrapper > .container > .content { | ||
| 314 | padding-left: max(32px, var(--vp-sidebar-width)) !important; | ||
| 315 | width: 100% !important; | ||
| 316 | padding-right: 32px !important; | ||
| 317 | } | ||
| 318 | |||
| 319 | /* Overriding styles of sidebar section */ | ||
| 320 | .VPSidebar { | ||
| 321 | padding-left: max( | ||
| 322 | 32px, | ||
| 323 | calc( | ||
| 324 | ( | ||
| 325 | 100% - | ||
| 326 | ( | ||
| 327 | var(--vp-nolebase-enhanced-readabilities-full-width-max-width) - | ||
| 328 | 64px | ||
| 329 | ) | ||
| 330 | ) / | ||
| 331 | 2 | ||
| 332 | ) | ||
| 333 | ) !important; | ||
| 334 | width: calc( | ||
| 335 | ( | ||
| 336 | 100% - | ||
| 337 | ( | ||
| 338 | var(--vp-nolebase-enhanced-readabilities-full-width-max-width) - | ||
| 339 | 64px | ||
| 340 | ) | ||
| 341 | ) / | ||
| 342 | 2 + | ||
| 343 | var(--vp-sidebar-width) - | ||
| 344 | 32px | ||
| 345 | ) !important; | ||
| 346 | } | ||
| 347 | |||
| 348 | /* Overriding styles of document section */ | ||
| 349 | .VPContent.has-sidebar { | ||
| 350 | padding-left: calc( | ||
| 351 | ( | ||
| 352 | 100vw - var(--vp-nolebase-enhanced-readabilities-full-width-max-width) | ||
| 353 | ) / | ||
| 354 | 2 + | ||
| 355 | var(--vp-sidebar-width) | ||
| 356 | ) !important; | ||
| 357 | padding-right: calc( | ||
| 358 | ( | ||
| 359 | 100vw - var(--vp-nolebase-enhanced-readabilities-full-width-max-width) | ||
| 360 | ) / | ||
| 361 | 2 | ||
| 362 | ) !important; | ||
| 363 | } | ||
| 364 | |||
| 365 | .VPDoc.has-aside div.content-container { | ||
| 366 | max-width: var(--vp-nolebase-enhanced-readabilities-full-width-max-width); | ||
| 367 | } | ||
| 368 | |||
| 369 | .VPDoc:not(.has-sidebar) .container { | ||
| 370 | max-width: var(--vp-nolebase-enhanced-readabilities-full-width-max-width); | ||
| 371 | } | ||
| 372 | |||
| 373 | .VPDoc:not(.has-sidebar) .container > .content { | ||
| 374 | max-width: var(--vp-nolebase-enhanced-readabilities-full-width-max-width); | ||
| 375 | } | ||
| 376 | } | ||
| 377 | |||
| 378 | @media (min-width: 1440px) { | ||
| 379 | .VPNavBar > .wrapper > .container { | ||
| 380 | max-width: var(--vp-nolebase-enhanced-readabilities-full-width-max-width); | ||
| 381 | } | ||
| 382 | |||
| 383 | .VPNavBar.has-sidebar > .divider { | ||
| 384 | padding-left: calc( | ||
| 385 | ( | ||
| 386 | 100vw - var(--vp-nolebase-enhanced-readabilities-full-width-max-width) | ||
| 387 | ) / | ||
| 388 | 2 + | ||
| 389 | var(--vp-sidebar-width) | ||
| 390 | ) !important; | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | @media (min-width: 1536px) { | ||
| 395 | .VPNavBar > .wrapper > .container { | ||
| 396 | max-width: var(--vp-nolebase-enhanced-readabilities-full-width-max-width); | ||
| 397 | } | ||
| 398 | |||
| 399 | .VPDoc .container { | ||
| 400 | max-width: var(--vp-nolebase-enhanced-readabilities-full-width-max-width); | ||
| 401 | } | ||
| 402 | } | ||
| 403 | } | ||
| 404 | |||
| 405 | .VPNolebaseEnhancedReadabilitiesLayoutSwitchSidebarWidthAdjustableOnly { | ||
| 406 | @media (min-width: 1280px) { | ||
| 407 | /* Overriding styles of navbar section */ | ||
| 408 | .VPNavBar.has-sidebar > .wrapper > .container > .title { | ||
| 409 | padding-left: max( | ||
| 410 | 32px, | ||
| 411 | calc( | ||
| 412 | ( | ||
| 413 | 100% - | ||
| 414 | ( | ||
| 415 | var(--vp-nolebase-enhanced-readabilities-page-max-width) - 64px | ||
| 416 | ) | ||
| 417 | ) / | ||
| 418 | 2 | ||
| 419 | ) | ||
| 420 | ) !important; | ||
| 421 | width: calc( | ||
| 422 | ( | ||
| 423 | 100% - | ||
| 424 | ( | ||
| 425 | var(--vp-nolebase-enhanced-readabilities-page-max-width) - 64px | ||
| 426 | ) | ||
| 427 | ) / | ||
| 428 | 2 + | ||
| 429 | var(--vp-sidebar-width) - | ||
| 430 | 32px | ||
| 431 | ) !important; | ||
| 432 | } | ||
| 433 | |||
| 434 | .VPNavBar > .wrapper > .container, | ||
| 435 | .VPNavBar.has-sidebar > .wrapper > .container { | ||
| 436 | max-width: var(--vp-nolebase-enhanced-readabilities-page-max-width) | ||
| 437 | !important; | ||
| 438 | } | ||
| 439 | |||
| 440 | .VPNavBar.has-sidebar > .wrapper > .container > .content { | ||
| 441 | padding-left: max(32px, calc(var(--vp-sidebar-width))) !important; | ||
| 442 | width: 100% !important; | ||
| 443 | padding-right: 32px !important; | ||
| 444 | } | ||
| 445 | |||
| 446 | /* Overriding styles of sidebar section */ | ||
| 447 | .VPSidebar { | ||
| 448 | padding-left: max( | ||
| 449 | 32px, | ||
| 450 | calc( | ||
| 451 | ( | ||
| 452 | 100% - | ||
| 453 | ( | ||
| 454 | var(--vp-nolebase-enhanced-readabilities-page-max-width) - 64px | ||
| 455 | ) | ||
| 456 | ) / | ||
| 457 | 2 | ||
| 458 | ) | ||
| 459 | ) !important; | ||
| 460 | width: calc( | ||
| 461 | ( | ||
| 462 | 100% - | ||
| 463 | ( | ||
| 464 | var(--vp-nolebase-enhanced-readabilities-page-max-width) - 64px | ||
| 465 | ) | ||
| 466 | ) / | ||
| 467 | 2 + | ||
| 468 | var(--vp-sidebar-width) - | ||
| 469 | 32px | ||
| 470 | ) !important; | ||
| 471 | } | ||
| 472 | } | ||
| 473 | |||
| 474 | @media (min-width: 1440px) { | ||
| 475 | .VPNavBar > .wrapper > .container, | ||
| 476 | .VPNavBar.has-sidebar > .wrapper > .container { | ||
| 477 | max-width: var(--vp-nolebase-enhanced-readabilities-page-max-width) | ||
| 478 | !important; | ||
| 479 | } | ||
| 480 | |||
| 481 | .VPNavBar.has-sidebar > .divider { | ||
| 482 | padding-left: calc( | ||
| 483 | (100vw - var(--vp-nolebase-enhanced-readabilities-page-max-width)) / 2 + | ||
| 484 | var(--vp-sidebar-width) | ||
| 485 | ) !important; | ||
| 486 | } | ||
| 487 | |||
| 488 | .VPContent.has-sidebar { | ||
| 489 | padding-left: calc( | ||
| 490 | ( | ||
| 491 | 100vw - var(--vp-nolebase-enhanced-readabilities-content-max-width) | ||
| 492 | ) / | ||
| 493 | 2 + | ||
| 494 | var(--vp-sidebar-width) | ||
| 495 | ) !important; | ||
| 496 | padding-right: calc( | ||
| 497 | ( | ||
| 498 | 100vw - var(--vp-nolebase-enhanced-readabilities-content-max-width) | ||
| 499 | ) / | ||
| 500 | 2 | ||
| 501 | ) !important; | ||
| 502 | } | ||
| 503 | } | ||
| 504 | } | ||
| 505 | |||
| 506 | .VPNolebaseEnhancedReadabilitiesLayoutSwitchBothWidthAdjustable { | ||
| 507 | @media (min-width: 1280px) { | ||
| 508 | /* Overriding styles of navbar section */ | ||
| 509 | .VPNavBar.has-sidebar > .wrapper > .container > .title { | ||
| 510 | padding-left: max( | ||
| 511 | 32px, | ||
| 512 | calc( | ||
| 513 | ( | ||
| 514 | 100% - | ||
| 515 | ( | ||
| 516 | var(--vp-nolebase-enhanced-readabilities-page-max-width) - 64px | ||
| 517 | ) | ||
| 518 | ) / | ||
| 519 | 2 | ||
| 520 | ) | ||
| 521 | ) !important; | ||
| 522 | width: calc( | ||
| 523 | ( | ||
| 524 | 100% - | ||
| 525 | ( | ||
| 526 | var(--vp-nolebase-enhanced-readabilities-page-max-width) - 64px | ||
| 527 | ) | ||
| 528 | ) / | ||
| 529 | 2 + | ||
| 530 | var(--vp-sidebar-width) - | ||
| 531 | 32px | ||
| 532 | ) !important; | ||
| 533 | } | ||
| 534 | |||
| 535 | .VPNavBar > .wrapper > .container, | ||
| 536 | .VPNavBar.has-sidebar > .wrapper > .container { | ||
| 537 | max-width: var(--vp-nolebase-enhanced-readabilities-page-max-width) | ||
| 538 | !important; | ||
| 539 | } | ||
| 540 | |||
| 541 | .VPNavBar.has-sidebar > .wrapper > .container > .content { | ||
| 542 | padding-left: max(32px, var(--vp-sidebar-width)) !important; | ||
| 543 | width: 100% !important; | ||
| 544 | padding-right: 32px !important; | ||
| 545 | } | ||
| 546 | |||
| 547 | /* Overriding styles of sidebar section */ | ||
| 548 | .VPSidebar { | ||
| 549 | padding-left: max( | ||
| 550 | 32px, | ||
| 551 | calc( | ||
| 552 | ( | ||
| 553 | 100% - | ||
| 554 | ( | ||
| 555 | var(--vp-nolebase-enhanced-readabilities-page-max-width) - 64px | ||
| 556 | ) | ||
| 557 | ) / | ||
| 558 | 2 | ||
| 559 | ) | ||
| 560 | ) !important; | ||
| 561 | width: calc( | ||
| 562 | ( | ||
| 563 | 100% - | ||
| 564 | ( | ||
| 565 | var(--vp-nolebase-enhanced-readabilities-page-max-width) - 64px | ||
| 566 | ) | ||
| 567 | ) / | ||
| 568 | 2 + | ||
| 569 | var(--vp-sidebar-width) - | ||
| 570 | 32px | ||
| 571 | ) !important; | ||
| 572 | } | ||
| 573 | |||
| 574 | .VPDoc.has-aside .content-container { | ||
| 575 | max-width: var(--vp-nolebase-enhanced-readabilities-content-max-width); | ||
| 576 | } | ||
| 577 | |||
| 578 | .VPDoc:not(.has-sidebar) .container { | ||
| 579 | max-width: var(--vp-nolebase-enhanced-readabilities-content-max-width); | ||
| 580 | } | ||
| 581 | |||
| 582 | .VPDoc:not(.has-sidebar) .container > .content { | ||
| 583 | max-width: var(--vp-nolebase-enhanced-readabilities-content-max-width); | ||
| 584 | } | ||
| 585 | } | ||
| 586 | |||
| 587 | @media (min-width: 1440px) { | ||
| 588 | .VPNavBar > .wrapper > .container, | ||
| 589 | .VPNavBar.has-sidebar > .wrapper > .container { | ||
| 590 | max-width: var(--vp-nolebase-enhanced-readabilities-page-max-width) | ||
| 591 | !important; | ||
| 592 | } | ||
| 593 | |||
| 594 | .VPNavBar.has-sidebar > .divider { | ||
| 595 | padding-left: calc( | ||
| 596 | (100vw - var(--vp-nolebase-enhanced-readabilities-page-max-width)) / 2 + | ||
| 597 | var(--vp-sidebar-width) | ||
| 598 | ) !important; | ||
| 599 | } | ||
| 600 | |||
| 601 | .VPContent.has-sidebar { | ||
| 602 | padding-left: calc( | ||
| 603 | ( | ||
| 604 | 100vw - var(--vp-nolebase-enhanced-readabilities-content-max-width) | ||
| 605 | ) / | ||
| 606 | 2 + | ||
| 607 | var(--vp-sidebar-width) | ||
| 608 | ) !important; | ||
| 609 | padding-right: calc( | ||
| 610 | ( | ||
| 611 | 100vw - var(--vp-nolebase-enhanced-readabilities-content-max-width) | ||
| 612 | ) / | ||
| 613 | 2 | ||
| 614 | ) !important; | ||
| 615 | } | ||
| 616 | } | ||
| 617 | |||
| 618 | @media (min-width: 1536px) { | ||
| 619 | .VPNavBar > .wrapper > .container, | ||
| 620 | .VPNavBar.has-sidebar > .wrapper > .container { | ||
| 621 | max-width: var(--vp-nolebase-enhanced-readabilities-page-max-width) | ||
| 622 | !important; | ||
| 623 | } | ||
| 624 | |||
| 625 | .VPDoc .container { | ||
| 626 | max-width: var(--vp-nolebase-enhanced-readabilities-content-max-width); | ||
| 627 | } | ||
| 628 | } | ||
| 629 | } | ||
| 630 | </style> | ||
docs/.vitepress/theme/components/settings/LayoutSwitchContentLayoutMaxWidthSlider.vue deleted −190
| @@ -1,190 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { | ||
| 3 | NuInputHighlight, | ||
| 4 | NuInputSlider, | ||
| 5 | NuVerticalTransition | ||
| 6 | } from '@nolebase/ui' | ||
| 7 | import { | ||
| 8 | useDebounceFn, | ||
| 9 | useLocalStorage, | ||
| 10 | useMediaQuery, | ||
| 11 | useMounted, | ||
| 12 | useStorage | ||
| 13 | } from '@vueuse/core' | ||
| 14 | import { computed, inject, onMounted, ref, watch } from 'vue' | ||
| 15 | |||
| 16 | import MenuHelp from './MenuHelp.vue' | ||
| 17 | import MenuTitle from './MenuTitle.vue' | ||
| 18 | |||
| 19 | import { useLayoutAppearanceChangeAnimation } from '../../composables/animation' | ||
| 20 | import { | ||
| 21 | ContentLayoutMaxWidthStorageKey, | ||
| 22 | InjectionKey, | ||
| 23 | LayoutMode, | ||
| 24 | LayoutSwitchModeStorageKey | ||
| 25 | } from '../../constants' | ||
| 26 | |||
| 27 | const min = ref(60) | ||
| 28 | const minScaled = computed(() => min.value * 100) | ||
| 29 | |||
| 30 | const max = ref(100) | ||
| 31 | const maxScaled = computed(() => max.value * 100) | ||
| 32 | |||
| 33 | const options = inject(InjectionKey, {}) | ||
| 34 | |||
| 35 | const menuTitleElementRef = ref<HTMLDivElement>() | ||
| 36 | const isMenuHelpPoppedUp = ref(false) | ||
| 37 | const disabled = ref(false) | ||
| 38 | |||
| 39 | const mounted = useMounted() | ||
| 40 | const isLargerThanMobile = useMediaQuery('(min-width: 768px)') | ||
| 41 | const shouldActivateMaxWidth = useMediaQuery('(min-width: 1440px)') | ||
| 42 | const maxWidthLocalStorageValue = useStorage( | ||
| 43 | ContentLayoutMaxWidthStorageKey, | ||
| 44 | (options.layoutSwitch?.contentLayoutMaxWidth?.defaultMaxWidth || 80) * 100 | ||
| 45 | ) | ||
| 46 | const layoutMode = useLocalStorage<LayoutMode>( | ||
| 47 | LayoutSwitchModeStorageKey, | ||
| 48 | options.layoutSwitch?.defaultMode || LayoutMode.BothWidthAdjustable | ||
| 49 | ) | ||
| 50 | |||
| 51 | const maxWidthValue = computed({ | ||
| 52 | get: () => { | ||
| 53 | const parsedMaxWidth = Number.parseInt( | ||
| 54 | String(maxWidthLocalStorageValue.value) | ||
| 55 | ) | ||
| 56 | |||
| 57 | if (Number.isNaN(parsedMaxWidth)) return maxScaled.value | ||
| 58 | |||
| 59 | if (parsedMaxWidth < minScaled.value) return minScaled.value | ||
| 60 | |||
| 61 | if (parsedMaxWidth > maxScaled.value) return maxScaled.value | ||
| 62 | |||
| 63 | return parsedMaxWidth | ||
| 64 | }, | ||
| 65 | set: (val) => { | ||
| 66 | if (val < minScaled.value) val = minScaled.value | ||
| 67 | |||
| 68 | if (val > maxScaled.value) val = maxScaled.value | ||
| 69 | |||
| 70 | maxWidthLocalStorageValue.value = val | ||
| 71 | } | ||
| 72 | }) | ||
| 73 | |||
| 74 | const { trigger: triggerAnimation } = useLayoutAppearanceChangeAnimation() | ||
| 75 | |||
| 76 | const updatePageMaxWidth = useDebounceFn((val: number) => { | ||
| 77 | if (!shouldActivateMaxWidth.value) { | ||
| 78 | if (!options.layoutSwitch?.contentLayoutMaxWidth?.disableAnimation) { | ||
| 79 | triggerAnimation(document.body) | ||
| 80 | } | ||
| 81 | document.body.style.setProperty( | ||
| 82 | '--vp-nolebase-enhanced-readabilities-content-max-width', | ||
| 83 | `100%` | ||
| 84 | ) | ||
| 85 | } else { | ||
| 86 | if (!options.layoutSwitch?.contentLayoutMaxWidth?.disableAnimation) { | ||
| 87 | triggerAnimation(document.body) | ||
| 88 | } | ||
| 89 | document.body.style.setProperty( | ||
| 90 | '--vp-nolebase-enhanced-readabilities-content-max-width', | ||
| 91 | `${Math.ceil(val / 100)}%` | ||
| 92 | ) | ||
| 93 | } | ||
| 94 | }, 1000) | ||
| 95 | |||
| 96 | watch(mounted, (val) => { | ||
| 97 | if (!val) return | ||
| 98 | |||
| 99 | updatePageMaxWidth(maxWidthValue.value) | ||
| 100 | }) | ||
| 101 | |||
| 102 | watch(isLargerThanMobile, () => { | ||
| 103 | if (!isLargerThanMobile.value) disabled.value = true | ||
| 104 | }) | ||
| 105 | |||
| 106 | watch(shouldActivateMaxWidth, () => { | ||
| 107 | updatePageMaxWidth(maxWidthValue.value) | ||
| 108 | }) | ||
| 109 | |||
| 110 | onMounted(() => { | ||
| 111 | if (!isLargerThanMobile.value) disabled.value = true | ||
| 112 | }) | ||
| 113 | |||
| 114 | watch(maxWidthValue, (val) => { | ||
| 115 | if (!mounted.value) return | ||
| 116 | |||
| 117 | updatePageMaxWidth(val) | ||
| 118 | }) | ||
| 119 | </script> | ||
| 120 | |||
| 121 | <template> | ||
| 122 | <NuVerticalTransition :duration="200"> | ||
| 123 | <div | ||
| 124 | v-show="layoutMode === LayoutMode.BothWidthAdjustable" | ||
| 125 | space-y-2 | ||
| 126 | role="range" | ||
| 127 | > | ||
| 128 | <div ref="menuTitleElementRef" flex items-center> | ||
| 129 | <MenuTitle | ||
| 130 | title="Content Layout Max Width" | ||
| 131 | aria-label="Content Layout Max Width" | ||
| 132 | :disabled="disabled" | ||
| 133 | flex="1" | ||
| 134 | pr-4 | ||
| 135 | > | ||
| 136 | <template #icon> | ||
| 137 | <span i-icon-park-outline:layout-one mr-1 aria-hidden="true" /> | ||
| 138 | </template> | ||
| 139 | <span i-icon-park-outline:auto-line-width /> | ||
| 140 | </MenuTitle> | ||
| 141 | <MenuHelp | ||
| 142 | v-if="!options.layoutSwitch?.contentLayoutMaxWidth?.disableHelp" | ||
| 143 | v-model:is-popped-up="isMenuHelpPoppedUp" | ||
| 144 | :menu-title-element-ref="menuTitleElementRef" | ||
| 145 | > | ||
| 146 | <h4 text-md mb-1 font-semibold>Content Layout Max Width</h4> | ||
| 147 | <p text="sm" mb-2 max-w-100> | ||
| 148 | <span> | ||
| 149 | Adjust the exact value of the document content width of VitePress | ||
| 150 | layout to adapt to different reading needs and screens. | ||
| 151 | </span> | ||
| 152 | </p> | ||
| 153 | <div space-y-2 class="VPNolebaseEnhancedReadabilitiesMenu"> | ||
| 154 | <div | ||
| 155 | text="sm" | ||
| 156 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 157 | max-w-100 | ||
| 158 | rounded-xl | ||
| 159 | p-3 | ||
| 160 | > | ||
| 161 | <h5 text="sm" mb-2 flex="~" items-center align-middle> | ||
| 162 | <span i-icon-park-outline:scale mr-1 /> | ||
| 163 | <span font-semibold> | ||
| 164 | Adjust the maximum width of the content layout | ||
| 165 | </span> | ||
| 166 | </h5> | ||
| 167 | <span> | ||
| 168 | A ranged slider for user to choose and customize their desired | ||
| 169 | width of the maximum width of the content layout can go. | ||
| 170 | </span> | ||
| 171 | </div> | ||
| 172 | </div> | ||
| 173 | </MenuHelp> | ||
| 174 | </div> | ||
| 175 | <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md"> | ||
| 176 | <NuInputSlider | ||
| 177 | v-model="maxWidthValue" | ||
| 178 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 179 | text="sm $vp-nolebase-enhanced-readabilities-menu-text-color" | ||
| 180 | name="VitePress Nolebase Enhanced Readabilities content layout max width range slider" | ||
| 181 | aria-label="Adjust the maximum width of the content layout" | ||
| 182 | :disabled="disabled" | ||
| 183 | :min="minScaled" | ||
| 184 | :max="maxScaled" | ||
| 185 | :formatter="(val) => `${Math.ceil(val / 100)}%`" | ||
| 186 | /> | ||
| 187 | </NuInputHighlight> | ||
| 188 | </div> | ||
| 189 | </NuVerticalTransition> | ||
| 190 | </template> | ||
docs/.vitepress/theme/components/settings/LayoutSwitchPageLayoutMaxWidthSlider.vue deleted −187
| @@ -1,187 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { | ||
| 3 | NuInputHighlight, | ||
| 4 | NuInputSlider, | ||
| 5 | NuVerticalTransition | ||
| 6 | } from '@nolebase/ui' | ||
| 7 | import { | ||
| 8 | useDebounceFn, | ||
| 9 | useLocalStorage, | ||
| 10 | useMediaQuery, | ||
| 11 | useMounted, | ||
| 12 | useStorage | ||
| 13 | } from '@vueuse/core' | ||
| 14 | import { computed, inject, onMounted, ref, watch } from 'vue' | ||
| 15 | |||
| 16 | import MenuHelp from './MenuHelp.vue' | ||
| 17 | import MenuTitle from './MenuTitle.vue' | ||
| 18 | |||
| 19 | import { useLayoutAppearanceChangeAnimation } from '../../composables/animation' | ||
| 20 | import { | ||
| 21 | InjectionKey, | ||
| 22 | LayoutMode, | ||
| 23 | LayoutSwitchModeStorageKey, | ||
| 24 | PageLayoutMaxWidthStorageKey | ||
| 25 | } from '../../constants' | ||
| 26 | |||
| 27 | const min = ref(60) | ||
| 28 | const minScaled = computed(() => min.value * 100) | ||
| 29 | |||
| 30 | const max = ref(100) | ||
| 31 | const maxScaled = computed(() => max.value * 100) | ||
| 32 | |||
| 33 | const options = inject(InjectionKey, {}) | ||
| 34 | |||
| 35 | const menuTitleElementRef = ref<HTMLDivElement>() | ||
| 36 | const isMenuHelpPoppedUp = ref(false) | ||
| 37 | const disabled = ref(false) | ||
| 38 | |||
| 39 | const mounted = useMounted() | ||
| 40 | const isLargerThanMobile = useMediaQuery('(min-width: 768px)') | ||
| 41 | const shouldActivateMaxWidth = useMediaQuery('(min-width: 1440px)') | ||
| 42 | const maxWidthLocalStorageValue = useStorage( | ||
| 43 | PageLayoutMaxWidthStorageKey, | ||
| 44 | (options.layoutSwitch?.pageLayoutMaxWidth?.defaultMaxWidth || 100) * 100 | ||
| 45 | ) | ||
| 46 | const layoutMode = useLocalStorage<LayoutMode>( | ||
| 47 | LayoutSwitchModeStorageKey, | ||
| 48 | options.layoutSwitch?.defaultMode || LayoutMode.BothWidthAdjustable | ||
| 49 | ) | ||
| 50 | |||
| 51 | const maxWidthValue = computed({ | ||
| 52 | get: () => { | ||
| 53 | const parsedMaxWidth = Number.parseInt( | ||
| 54 | String(maxWidthLocalStorageValue.value) | ||
| 55 | ) | ||
| 56 | |||
| 57 | if (Number.isNaN(parsedMaxWidth)) return maxScaled.value | ||
| 58 | |||
| 59 | if (parsedMaxWidth < minScaled.value) return minScaled.value | ||
| 60 | |||
| 61 | if (parsedMaxWidth > maxScaled.value) return maxScaled.value | ||
| 62 | |||
| 63 | return parsedMaxWidth | ||
| 64 | }, | ||
| 65 | set: (val) => { | ||
| 66 | if (val < minScaled.value) val = minScaled.value | ||
| 67 | |||
| 68 | if (val > maxScaled.value) val = maxScaled.value | ||
| 69 | |||
| 70 | maxWidthLocalStorageValue.value = val | ||
| 71 | } | ||
| 72 | }) | ||
| 73 | |||
| 74 | const { trigger: triggerAnimation } = useLayoutAppearanceChangeAnimation() | ||
| 75 | |||
| 76 | const updatePageMaxWidth = useDebounceFn((val: number) => { | ||
| 77 | if (!shouldActivateMaxWidth.value) { | ||
| 78 | document.body.style.setProperty( | ||
| 79 | '--vp-nolebase-enhanced-readabilities-page-max-width', | ||
| 80 | `100%` | ||
| 81 | ) | ||
| 82 | } else { | ||
| 83 | if (!options.layoutSwitch?.pageLayoutMaxWidth?.disableAnimation) { | ||
| 84 | triggerAnimation(document.body) | ||
| 85 | } | ||
| 86 | document.body.style.setProperty( | ||
| 87 | '--vp-nolebase-enhanced-readabilities-page-max-width', | ||
| 88 | `${Math.ceil(val / 100)}%` | ||
| 89 | ) | ||
| 90 | } | ||
| 91 | }, 1000) | ||
| 92 | |||
| 93 | watch(mounted, (val) => { | ||
| 94 | if (!val) return | ||
| 95 | |||
| 96 | updatePageMaxWidth(maxWidthValue.value) | ||
| 97 | }) | ||
| 98 | |||
| 99 | watch(isLargerThanMobile, () => { | ||
| 100 | if (!isLargerThanMobile.value) disabled.value = true | ||
| 101 | }) | ||
| 102 | |||
| 103 | watch(shouldActivateMaxWidth, () => { | ||
| 104 | updatePageMaxWidth(maxWidthValue.value) | ||
| 105 | }) | ||
| 106 | |||
| 107 | onMounted(() => { | ||
| 108 | if (!isLargerThanMobile.value) disabled.value = true | ||
| 109 | }) | ||
| 110 | |||
| 111 | watch(maxWidthValue, (val) => { | ||
| 112 | if (!mounted.value) return | ||
| 113 | |||
| 114 | updatePageMaxWidth(val) | ||
| 115 | }) | ||
| 116 | </script> | ||
| 117 | |||
| 118 | <template> | ||
| 119 | <NuVerticalTransition :duration="200"> | ||
| 120 | <div | ||
| 121 | v-show="layoutMode === LayoutMode.SidebarWidthAdjustableOnly || | ||
| 122 | layoutMode === LayoutMode.BothWidthAdjustable" | ||
| 123 | space-y-2 | ||
| 124 | role="range" | ||
| 125 | > | ||
| 126 | <div ref="menuTitleElementRef" flex items-center> | ||
| 127 | <MenuTitle | ||
| 128 | title="Page Layout Max Width" | ||
| 129 | aria-label="Page Layout Max Width" | ||
| 130 | :disabled="disabled" | ||
| 131 | flex="1" | ||
| 132 | pr-2 | ||
| 133 | > | ||
| 134 | <template #icon> | ||
| 135 | <span i-icon-park-outline:auto-width-one mr-1 aria-hidden="true" /> | ||
| 136 | </template> | ||
| 137 | </MenuTitle> | ||
| 138 | <MenuHelp | ||
| 139 | v-if="!options.layoutSwitch?.pageLayoutMaxWidth?.disableHelp" | ||
| 140 | v-model:is-popped-up="isMenuHelpPoppedUp" | ||
| 141 | :menu-title-element-ref="menuTitleElementRef" | ||
| 142 | > | ||
| 143 | <h4 text-md mb-1 font-semibold>Page Layout Max Width</h4> | ||
| 144 | <p text="sm" mb-2 max-w-100> | ||
| 145 | <span> | ||
| 146 | Adjust the exact value of the page width of VitePress layout to | ||
| 147 | adapt to different reading needs and screens. | ||
| 148 | </span> | ||
| 149 | </p> | ||
| 150 | <div space-y-2 class="VPNolebaseEnhancedReadabilitiesMenu"> | ||
| 151 | <div | ||
| 152 | text="sm" | ||
| 153 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 154 | max-w-100 | ||
| 155 | rounded-xl | ||
| 156 | p-3 | ||
| 157 | > | ||
| 158 | <h5 text="sm" mb-2 flex="~" items-center align-middle> | ||
| 159 | <span i-icon-park-outline:scale mr-1 /> | ||
| 160 | <span font-semibold> | ||
| 161 | Adjust the maximum width of the page layout | ||
| 162 | </span> | ||
| 163 | </h5> | ||
| 164 | <span> | ||
| 165 | A ranged slider for user to choose and customize their desired | ||
| 166 | width of the maximum width of the page layout can go. | ||
| 167 | </span> | ||
| 168 | </div> | ||
| 169 | </div> | ||
| 170 | </MenuHelp> | ||
| 171 | </div> | ||
| 172 | <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md"> | ||
| 173 | <NuInputSlider | ||
| 174 | v-model="maxWidthValue" | ||
| 175 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 176 | text="sm $vp-nolebase-enhanced-readabilities-menu-text-color" | ||
| 177 | name="VitePress Nolebase Enhanced Readabilities page layout max width range slider" | ||
| 178 | aria-label="VitePress Nolebase Enhanced Readabilities page layout max width range slider" | ||
| 179 | :disabled="disabled" | ||
| 180 | :min="minScaled" | ||
| 181 | :max="maxScaled" | ||
| 182 | :formatter="(val) => `${Math.ceil(val / 100)}%`" | ||
| 183 | /> | ||
| 184 | </NuInputHighlight> | ||
| 185 | </div> | ||
| 186 | </NuVerticalTransition> | ||
| 187 | </template> | ||
docs/.vitepress/theme/components/settings/Menu.vue +1 −16
| @@ -1,20 +1,11 @@ | |||
| 1 | <script setup lang="ts"> | 1 | <script setup lang="ts"> |
| 2 | import { useMounted } from '@vueuse/core' | 2 | import { useMounted } from '@vueuse/core' |
| 3 | import { inject } from 'vue' | ||
| 4 | 3 | ||
| 5 | import { InjectionKey } from '../../constants' | ||
| 6 | import AccentBackground from './AccentBackground.vue' | 4 | import AccentBackground from './AccentBackground.vue' |
| 7 | import AccentColor from './AccentColor.vue' | 5 | import AccentColor from './AccentColor.vue' |
| 8 | import Effects from './Effects.vue' | 6 | import Effects from './Effects.vue' |
| 9 | import LayoutSwitch from './LayoutSwitch.vue' | ||
| 10 | import LayoutSwitchContentLayoutWidthInput from './LayoutSwitchContentLayoutMaxWidthSlider.vue' | ||
| 11 | import LayoutSwitchPageLayoutWidthInput from './LayoutSwitchPageLayoutMaxWidthSlider.vue' | ||
| 12 | import Spotlight from './Spotlight.vue' | ||
| 13 | import SpotlightStyles from './SpotlightStyles.vue' | ||
| 14 | import Pet from './Pet.vue' | ||
| 15 | import SettingsFlyout from './SettingsFlyout.vue' | 7 | import SettingsFlyout from './SettingsFlyout.vue' |
| 16 | 8 | ||
| 17 | const options = inject(InjectionKey, {}) | ||
| 18 | const mounted = useMounted() | 9 | const mounted = useMounted() |
| 19 | </script> | 10 | </script> |
| 20 | 11 | ||
| @@ -27,15 +18,9 @@ const mounted = useMounted() | |||
| 27 | aria-label="Enhanced Readability" | 18 | aria-label="Enhanced Readability" |
| 28 | class="min-w-64 p-2 space-y-2" | 19 | class="min-w-64 p-2 space-y-2" |
| 29 | > | 20 | > |
| 30 | <LayoutSwitch /> | ||
| 31 | <LayoutSwitchPageLayoutWidthInput /> | ||
| 32 | <LayoutSwitchContentLayoutWidthInput /> | ||
| 33 | <Spotlight v-if="!options.spotlight?.disabled" /> | ||
| 34 | <SpotlightStyles v-if="!options.spotlight?.disabled" /> | ||
| 35 | <Effects /> | ||
| 36 | <AccentColor /> | 21 | <AccentColor /> |
| 37 | <AccentBackground /> | 22 | <AccentBackground /> |
| 38 | <Pet /> | 23 | <Effects /> |
| 39 | </div> | 24 | </div> |
| 40 | </SettingsFlyout> | 25 | </SettingsFlyout> |
| 41 | </template> | 26 | </template> |
docs/.vitepress/theme/components/settings/Pet.vue deleted −271
| @@ -1,271 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { | ||
| 3 | NuInputHighlight, | ||
| 4 | NuInputHorizontalRadioGroup, | ||
| 5 | NuVerticalTransition | ||
| 6 | } from '@nolebase/ui' | ||
| 7 | import { useStorage } from '@vueuse/core' | ||
| 8 | import { computed, onMounted, onUnmounted, ref } from 'vue' | ||
| 9 | |||
| 10 | import { PetCharacterStorageKey, PetStorageKey } from '../../constants' | ||
| 11 | import { | ||
| 12 | defaultPetKey, | ||
| 13 | petCharacters, | ||
| 14 | spriteIconStyle, | ||
| 15 | type PetCharacter | ||
| 16 | } from '../../pets' | ||
| 17 | import MenuHelp from './MenuHelp.vue' | ||
| 18 | import MenuTitle from './MenuTitle.vue' | ||
| 19 | |||
| 20 | const menuTitleElementRef = ref<HTMLDivElement>() | ||
| 21 | const isMenuHelpPoppedUp = ref(false) | ||
| 22 | |||
| 23 | const petEnabled = useStorage(PetStorageKey, false) | ||
| 24 | const petCharacter = useStorage(PetCharacterStorageKey, defaultPetKey) | ||
| 25 | |||
| 26 | const open = ref(false) | ||
| 27 | const rootRef = ref<HTMLDivElement>() | ||
| 28 | |||
| 29 | // Drives the animated sprite previews (e.g. Oneko's two-frame sleep). | ||
| 30 | const frameTick = ref(0) | ||
| 31 | let frameTimer: ReturnType<typeof setInterval> | null = null | ||
| 32 | |||
| 33 | const selectedOption = computed( | ||
| 34 | () => | ||
| 35 | petCharacters.find((o) => o.key === petCharacter.value) ?? petCharacters[0] | ||
| 36 | ) | ||
| 37 | |||
| 38 | function iconStyle(option: PetCharacter) { | ||
| 39 | return option.icon.type === 'sprite' | ||
| 40 | ? spriteIconStyle(option.icon, 24, frameTick.value) | ||
| 41 | : undefined | ||
| 42 | } | ||
| 43 | |||
| 44 | function select(key: string) { | ||
| 45 | petCharacter.value = key | ||
| 46 | open.value = false | ||
| 47 | } | ||
| 48 | |||
| 49 | function onDocClick(e: MouseEvent) { | ||
| 50 | if (rootRef.value && !rootRef.value.contains(e.target as Node)) { | ||
| 51 | open.value = false | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | const fieldOptions = computed(() => [ | ||
| 56 | { | ||
| 57 | value: true, | ||
| 58 | title: 'On', | ||
| 59 | ariaLabel: 'On', | ||
| 60 | text: 'ON', | ||
| 61 | name: 'Pet Toggle Switch' | ||
| 62 | }, | ||
| 63 | { | ||
| 64 | value: false, | ||
| 65 | title: 'Off', | ||
| 66 | ariaLabel: 'Off', | ||
| 67 | text: 'OFF', | ||
| 68 | name: 'Pet Toggle Switch' | ||
| 69 | } | ||
| 70 | ]) | ||
| 71 | |||
| 72 | onMounted(() => { | ||
| 73 | document.addEventListener('click', onDocClick, true) | ||
| 74 | frameTimer = setInterval(() => { | ||
| 75 | frameTick.value += 1 | ||
| 76 | }, 400) | ||
| 77 | }) | ||
| 78 | onUnmounted(() => { | ||
| 79 | document.removeEventListener('click', onDocClick, true) | ||
| 80 | if (frameTimer) clearInterval(frameTimer) | ||
| 81 | }) | ||
| 82 | </script> | ||
| 83 | |||
| 84 | <template> | ||
| 85 | <div ref="rootRef" space-y-2 role="radiogroup"> | ||
| 86 | <div ref="menuTitleElementRef" relative flex items-center> | ||
| 87 | <MenuTitle title="Pet" aria-label="Pet" flex="1" pr-4> | ||
| 88 | <template #icon> | ||
| 89 | <span i-lucide:cat mr-1 aria-hidden="true" /> | ||
| 90 | </template> | ||
| 91 | </MenuTitle> | ||
| 92 | <MenuHelp | ||
| 93 | v-model:is-popped-up="isMenuHelpPoppedUp" | ||
| 94 | :menu-title-element-ref="menuTitleElementRef" | ||
| 95 | > | ||
| 96 | <h4 text-md mb-1 font-semibold>Pet</h4> | ||
| 97 | <p text="sm" mb-2 max-w-100> | ||
| 98 | <span>Gives you a cute companion that follows your cursor. Pick your | ||
| 99 | favorite character.</span> | ||
| 100 | </p> | ||
| 101 | </MenuHelp> | ||
| 102 | </div> | ||
| 103 | |||
| 104 | <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md"> | ||
| 105 | <NuInputHorizontalRadioGroup | ||
| 106 | v-model="petEnabled" | ||
| 107 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 108 | text="sm $vp-nolebase-enhanced-readabilities-menu-text-color" | ||
| 109 | :options="fieldOptions" | ||
| 110 | /> | ||
| 111 | </NuInputHighlight> | ||
| 112 | |||
| 113 | <NuVerticalTransition :duration="200"> | ||
| 114 | <div v-show="petEnabled" class="pet-select" :class="{ 'pet-select--open': open }"> | ||
| 115 | <button | ||
| 116 | type="button" | ||
| 117 | class="pet-trigger" | ||
| 118 | aria-haspopup="listbox" | ||
| 119 | :aria-expanded="open" | ||
| 120 | :aria-label="`Pet: ${selectedOption.label}`" | ||
| 121 | @click="open = !open" | ||
| 122 | > | ||
| 123 | <span | ||
| 124 | v-if="selectedOption.icon.type === 'image'" | ||
| 125 | class="pet-icon" | ||
| 126 | > | ||
| 127 | <img :src="selectedOption.icon.src" :alt="selectedOption.label" /> | ||
| 128 | </span> | ||
| 129 | <span v-else class="pet-icon" :style="iconStyle(selectedOption)" /> | ||
| 130 | <span class="pet-label">{{ selectedOption.label }}</span> | ||
| 131 | <span | ||
| 132 | class="pet-chevron i-lucide:chevron-down" | ||
| 133 | :class="{ 'pet-chevron--open': open }" | ||
| 134 | aria-hidden="true" | ||
| 135 | /> | ||
| 136 | </button> | ||
| 137 | |||
| 138 | <NuVerticalTransition :duration="200"> | ||
| 139 | <div v-show="open" class="pet-options" role="listbox"> | ||
| 140 | <button | ||
| 141 | v-for="option in petCharacters" | ||
| 142 | :key="option.key" | ||
| 143 | type="button" | ||
| 144 | role="option" | ||
| 145 | class="pet-btn" | ||
| 146 | :class="{ 'pet-btn--selected': petCharacter === option.key }" | ||
| 147 | :aria-selected="petCharacter === option.key" | ||
| 148 | :aria-label="option.label" | ||
| 149 | @click="select(option.key)" | ||
| 150 | > | ||
| 151 | <span v-if="option.icon.type === 'image'" class="pet-icon"> | ||
| 152 | <img :src="option.icon.src" :alt="option.label" /> | ||
| 153 | </span> | ||
| 154 | <span v-else class="pet-icon" :style="iconStyle(option)" /> | ||
| 155 | <span class="pet-label">{{ option.label }}</span> | ||
| 156 | </button> | ||
| 157 | </div> | ||
| 158 | </NuVerticalTransition> | ||
| 159 | </div> | ||
| 160 | </NuVerticalTransition> | ||
| 161 | </div> | ||
| 162 | </template> | ||
| 163 | |||
| 164 | <style scoped> | ||
| 165 | .pet-select { | ||
| 166 | position: relative; | ||
| 167 | } | ||
| 168 | |||
| 169 | .pet-trigger { | ||
| 170 | display: flex; | ||
| 171 | align-items: center; | ||
| 172 | gap: 8px; | ||
| 173 | width: 100%; | ||
| 174 | min-height: 44px; | ||
| 175 | padding: 7px 10px; | ||
| 176 | border-radius: 8px; | ||
| 177 | border: 2px solid var(--vp-c-divider); | ||
| 178 | background: var(--wk-c-menu-bg); | ||
| 179 | color: var(--vp-c-text-1); | ||
| 180 | font-size: 13px; | ||
| 181 | cursor: pointer; | ||
| 182 | transition: border-color 0.15s, background-color 0.15s; | ||
| 183 | } | ||
| 184 | |||
| 185 | .pet-trigger:hover { | ||
| 186 | border-color: var(--vp-c-brand-1); | ||
| 187 | } | ||
| 188 | |||
| 189 | .pet-select--open .pet-trigger { | ||
| 190 | border-color: var(--vp-c-brand-1); | ||
| 191 | } | ||
| 192 | |||
| 193 | .pet-chevron { | ||
| 194 | flex-shrink: 0; | ||
| 195 | width: 16px; | ||
| 196 | height: 16px; | ||
| 197 | color: var(--vp-c-text-2); | ||
| 198 | transition: transform 0.2s ease; | ||
| 199 | } | ||
| 200 | |||
| 201 | .pet-chevron--open { | ||
| 202 | transform: rotate(180deg); | ||
| 203 | } | ||
| 204 | |||
| 205 | .pet-options { | ||
| 206 | margin-top: 6px; | ||
| 207 | max-height: 240px; | ||
| 208 | overflow-y: auto; | ||
| 209 | overscroll-behavior: contain; | ||
| 210 | display: flex; | ||
| 211 | flex-direction: column; | ||
| 212 | gap: 2px; | ||
| 213 | padding: 4px; | ||
| 214 | border-radius: 8px; | ||
| 215 | border: 1px solid var(--vp-c-divider); | ||
| 216 | background: var(--vp-c-bg-elv); | ||
| 217 | box-shadow: var(--vp-shadow-2); | ||
| 218 | } | ||
| 219 | |||
| 220 | .pet-btn { | ||
| 221 | display: flex; | ||
| 222 | align-items: center; | ||
| 223 | gap: 8px; | ||
| 224 | padding: 5px 8px; | ||
| 225 | border-radius: 8px; | ||
| 226 | border: none; | ||
| 227 | background: transparent; | ||
| 228 | cursor: pointer; | ||
| 229 | color: var(--vp-c-text-1); | ||
| 230 | font-size: 13px; | ||
| 231 | width: 100%; | ||
| 232 | transition: background-color 0.15s; | ||
| 233 | } | ||
| 234 | |||
| 235 | .pet-btn:hover { | ||
| 236 | background-color: var(--vp-c-bg-soft); | ||
| 237 | } | ||
| 238 | |||
| 239 | .pet-btn--selected { | ||
| 240 | background-color: var(--vp-c-brand-soft); | ||
| 241 | } | ||
| 242 | |||
| 243 | .pet-btn--selected .pet-label { | ||
| 244 | font-weight: 600; | ||
| 245 | } | ||
| 246 | |||
| 247 | .pet-btn--selected:hover { | ||
| 248 | background-color: var(--vp-c-brand-soft); | ||
| 249 | } | ||
| 250 | |||
| 251 | .pet-label { | ||
| 252 | flex: 1; | ||
| 253 | text-align: left; | ||
| 254 | } | ||
| 255 | |||
| 256 | .pet-icon { | ||
| 257 | flex-shrink: 0; | ||
| 258 | width: 24px; | ||
| 259 | height: 24px; | ||
| 260 | background-repeat: no-repeat; | ||
| 261 | display: inline-flex; | ||
| 262 | align-items: center; | ||
| 263 | justify-content: center; | ||
| 264 | } | ||
| 265 | |||
| 266 | .pet-icon img { | ||
| 267 | width: 24px; | ||
| 268 | height: 24px; | ||
| 269 | object-fit: contain; | ||
| 270 | } | ||
| 271 | </style> | ||
docs/.vitepress/theme/components/settings/ScreenAppearance.vue deleted −54
| @@ -1,54 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { NuInputHorizontalRadioGroup } from '@nolebase/ui' | ||
| 3 | import { useData } from 'vitepress' | ||
| 4 | import { computed, inject } from 'vue' | ||
| 5 | |||
| 6 | import MenuTitle from './MenuTitle.vue' | ||
| 7 | |||
| 8 | const { isDark } = useData() | ||
| 9 | const toggleAppearance = inject<() => void>('toggle-appearance', () => { | ||
| 10 | isDark.value = !isDark.value | ||
| 11 | }) | ||
| 12 | |||
| 13 | const fieldOptions = [ | ||
| 14 | { | ||
| 15 | value: 'on', | ||
| 16 | title: 'On', | ||
| 17 | ariaLabel: 'On', | ||
| 18 | text: 'ON', | ||
| 19 | name: 'Dark Mode' | ||
| 20 | }, | ||
| 21 | { | ||
| 22 | value: 'off', | ||
| 23 | title: 'Off', | ||
| 24 | ariaLabel: 'Off', | ||
| 25 | text: 'OFF', | ||
| 26 | name: 'Dark Mode' | ||
| 27 | } | ||
| 28 | ] | ||
| 29 | |||
| 30 | const currentMode = computed({ | ||
| 31 | get: () => (isDark.value ? 'on' : 'off'), | ||
| 32 | set: (value) => { | ||
| 33 | if ((value === 'on') !== isDark.value) { | ||
| 34 | toggleAppearance() | ||
| 35 | } | ||
| 36 | } | ||
| 37 | }) | ||
| 38 | </script> | ||
| 39 | |||
| 40 | <template> | ||
| 41 | <div space-y-2> | ||
| 42 | <MenuTitle title="Dark mode" aria-label="Dark mode"> | ||
| 43 | <template #icon> | ||
| 44 | <span i-icon-park-outline:dark-mode mr-1 aria-hidden="true" /> | ||
| 45 | </template> | ||
| 46 | </MenuTitle> | ||
| 47 | <NuInputHorizontalRadioGroup | ||
| 48 | v-model="currentMode" | ||
| 49 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 50 | text="sm $vp-nolebase-enhanced-readabilities-menu-text-color" | ||
| 51 | :options="fieldOptions" | ||
| 52 | /> | ||
| 53 | </div> | ||
| 54 | </template> | ||
docs/.vitepress/theme/components/settings/ScreenLayoutSwitch.vue deleted −24
| @@ -1,24 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import MenuTitle from './MenuTitle.vue' | ||
| 3 | </script> | ||
| 4 | |||
| 5 | <template> | ||
| 6 | <div space-y-2> | ||
| 7 | <MenuTitle title="Layout Switch" aria-label="Layout Switch" disabled> | ||
| 8 | <template #icon> | ||
| 9 | <slot i-icon-park-outline:layout-one mr-1 aria-hidden="true" /> | ||
| 10 | </template> | ||
| 11 | </MenuTitle> | ||
| 12 | <div | ||
| 13 | border="1 red/50 solid" | ||
| 14 | bg="red/30" | ||
| 15 | flex | ||
| 16 | items-center | ||
| 17 | rounded-lg | ||
| 18 | p-2 | ||
| 19 | opacity-50 | ||
| 20 | > | ||
| 21 | <span text-xs>No available layout can be switched in mobile screen.</span> | ||
| 22 | </div> | ||
| 23 | </div> | ||
| 24 | </template> | ||
docs/.vitepress/theme/components/settings/ScreenMenu.vue +1 −1
| @@ -13,9 +13,9 @@ const { theme } = useData() | |||
| 13 | 13 | ||
| 14 | <template> | 14 | <template> |
| 15 | <div v-if="mounted" space-y-2 class="VPNolebaseEnhancedReadabilitiesMenu"> | 15 | <div v-if="mounted" space-y-2 class="VPNolebaseEnhancedReadabilitiesMenu"> |
| 16 | <Effects /> | ||
| 17 | <AccentColor /> | 16 | <AccentColor /> |
| 18 | <AccentBackground /> | 17 | <AccentBackground /> |
| 18 | <Effects /> | ||
| 19 | <VPSocialLinks | 19 | <VPSocialLinks |
| 20 | v-if="theme.socialLinks" | 20 | v-if="theme.socialLinks" |
| 21 | :links="theme.socialLinks" | 21 | :links="theme.socialLinks" |
docs/.vitepress/theme/components/settings/ScreenSpotlight.vue deleted −52
| @@ -1,52 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { NuInputHorizontalRadioGroup } from '@nolebase/ui' | ||
| 3 | import { computed } from 'vue' | ||
| 4 | |||
| 5 | import MenuTitle from './MenuTitle.vue' | ||
| 6 | |||
| 7 | const fieldOptions = computed(() => [ | ||
| 8 | { | ||
| 9 | title: 'On', | ||
| 10 | ariaLabel: 'On', | ||
| 11 | value: true, | ||
| 12 | text: 'ON', | ||
| 13 | name: 'VitePress Nolebase Enhanced Readabilities Spotlight Toggle Switch' | ||
| 14 | }, | ||
| 15 | { | ||
| 16 | title: 'Off', | ||
| 17 | ariaLabel: 'Off', | ||
| 18 | value: false, | ||
| 19 | text: 'OFF', | ||
| 20 | name: 'VitePress Nolebase Enhanced Readabilities Spotlight Toggle Switch' | ||
| 21 | } | ||
| 22 | ]) | ||
| 23 | </script> | ||
| 24 | |||
| 25 | <template> | ||
| 26 | <div space-y-2> | ||
| 27 | <MenuTitle title="Spotlight" aria-label="Spotlight" disabled> | ||
| 28 | <template #icon> | ||
| 29 | <span i-icon-park-outline:click mr-1 aria-hidden="true" /> | ||
| 30 | </template> | ||
| 31 | </MenuTitle> | ||
| 32 | <div | ||
| 33 | border="1 red/50 solid" | ||
| 34 | bg="red/30" | ||
| 35 | flex | ||
| 36 | items-center | ||
| 37 | rounded-lg | ||
| 38 | p-2 | ||
| 39 | opacity-50 | ||
| 40 | > | ||
| 41 | <span text-xs> | ||
| 42 | Spotlight Styles is not available in mobile screen temporarily. | ||
| 43 | </span> | ||
| 44 | </div> | ||
| 45 | <NuInputHorizontalRadioGroup | ||
| 46 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 47 | text="sm $vp-nolebase-enhanced-readabilities-menu-text-color" | ||
| 48 | :options="fieldOptions" | ||
| 49 | disabled | ||
| 50 | /> | ||
| 51 | </div> | ||
| 52 | </template> | ||
docs/.vitepress/theme/components/settings/Spotlight.vue deleted −122
| @@ -1,122 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { NuInputHighlight, NuInputHorizontalRadioGroup } from '@nolebase/ui' | ||
| 3 | import { useMediaQuery, useMounted, useStorage } from '@vueuse/core' | ||
| 4 | import { computed, inject, onMounted, ref, watch } from 'vue' | ||
| 5 | |||
| 6 | import MenuHelp from './MenuHelp.vue' | ||
| 7 | import MenuTitle from './MenuTitle.vue' | ||
| 8 | import SpotlightHoverBlock from './SpotlightHoverBlock.vue' | ||
| 9 | |||
| 10 | import { InjectionKey, SpotlightToggledStorageKey } from '../../constants' | ||
| 11 | |||
| 12 | const options = inject(InjectionKey, {}) | ||
| 13 | |||
| 14 | const menuTitleElementRef = ref<HTMLDivElement>() | ||
| 15 | const isMenuHelpPoppedUp = ref(false) | ||
| 16 | const disabled = ref(false) | ||
| 17 | |||
| 18 | const mounted = useMounted() | ||
| 19 | const isTouchScreen = useMediaQuery('(pointer: coarse)') | ||
| 20 | const spotlightToggledOn = useStorage( | ||
| 21 | SpotlightToggledStorageKey, | ||
| 22 | options.spotlight?.defaultToggle || false | ||
| 23 | ) | ||
| 24 | |||
| 25 | const fieldOptions = computed(() => [ | ||
| 26 | { | ||
| 27 | value: true, | ||
| 28 | title: 'On', | ||
| 29 | ariaLabel: 'On', | ||
| 30 | text: 'ON', | ||
| 31 | name: 'VitePress Nolebase Enhanced Readabilities Spotlight Toggle Switch' | ||
| 32 | }, | ||
| 33 | { | ||
| 34 | value: false, | ||
| 35 | title: 'Off', | ||
| 36 | ariaLabel: 'Off', | ||
| 37 | text: 'OFF', | ||
| 38 | name: 'VitePress Nolebase Enhanced Readabilities Spotlight Toggle Switch' | ||
| 39 | } | ||
| 40 | ]) | ||
| 41 | |||
| 42 | onMounted(() => { | ||
| 43 | disabled.value = isTouchScreen.value | ||
| 44 | }) | ||
| 45 | |||
| 46 | watch(isTouchScreen, () => { | ||
| 47 | disabled.value = isTouchScreen.value | ||
| 48 | }) | ||
| 49 | </script> | ||
| 50 | |||
| 51 | <template> | ||
| 52 | <div space-y-2 role="radiogroup"> | ||
| 53 | <SpotlightHoverBlock | ||
| 54 | v-if="mounted && spotlightToggledOn && !disabled" | ||
| 55 | :enabled="spotlightToggledOn && !disabled" | ||
| 56 | /> | ||
| 57 | <div ref="menuTitleElementRef" relative flex items-center> | ||
| 58 | <MenuTitle | ||
| 59 | title="Spotlight" | ||
| 60 | aria-label="Spotlight" | ||
| 61 | :disabled="disabled" | ||
| 62 | flex="1" | ||
| 63 | pr-4 | ||
| 64 | > | ||
| 65 | <template #icon> | ||
| 66 | <span i-icon-park-outline:click mr-1 aria-hidden="true" /> | ||
| 67 | </template> | ||
| 68 | </MenuTitle> | ||
| 69 | <MenuHelp | ||
| 70 | v-if="!options.spotlight?.disableHelp" | ||
| 71 | v-model:is-popped-up="isMenuHelpPoppedUp" | ||
| 72 | :menu-title-element-ref="menuTitleElementRef" | ||
| 73 | > | ||
| 74 | <h4 text-md mb-1 font-semibold>Spotlight</h4> | ||
| 75 | <p text="sm" mb-2 max-w-100> | ||
| 76 | <span> | ||
| 77 | Highlight the line where the mouse is currently hovering in the | ||
| 78 | content to optimize for users who may have reading and focusing | ||
| 79 | difficulties. | ||
| 80 | </span> | ||
| 81 | </p> | ||
| 82 | <div space-y-2 class="VPNolebaseEnhancedReadabilitiesMenu"> | ||
| 83 | <div | ||
| 84 | text="sm" | ||
| 85 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 86 | max-w-100 | ||
| 87 | rounded-xl | ||
| 88 | p-3 | ||
| 89 | > | ||
| 90 | <h5 text="sm" mb-2> | ||
| 91 | <span mr-1 font-bold>ON</span> | ||
| 92 | <span font-semibold>On</span> | ||
| 93 | </h5> | ||
| 94 | <span>Turn on the Spotlight feature</span> | ||
| 95 | </div> | ||
| 96 | <div | ||
| 97 | text="sm" | ||
| 98 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 99 | max-w-100 | ||
| 100 | rounded-xl | ||
| 101 | p-3 | ||
| 102 | > | ||
| 103 | <h5 text="sm" mb-2> | ||
| 104 | <span mr-1 font-bold>OFF</span> | ||
| 105 | <span font-semibold>Off</span> | ||
| 106 | </h5> | ||
| 107 | <span>Turn off the Spotlight feature</span> | ||
| 108 | </div> | ||
| 109 | </div> | ||
| 110 | </MenuHelp> | ||
| 111 | </div> | ||
| 112 | <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md"> | ||
| 113 | <NuInputHorizontalRadioGroup | ||
| 114 | v-model="spotlightToggledOn" | ||
| 115 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 116 | text="sm $vp-nolebase-enhanced-readabilities-menu-text-color" | ||
| 117 | :options="fieldOptions" | ||
| 118 | :disabled="disabled" | ||
| 119 | /> | ||
| 120 | </NuInputHighlight> | ||
| 121 | </div> | ||
| 122 | </template> | ||
docs/.vitepress/theme/components/settings/SpotlightHoverBlock.vue deleted −221
| @@ -1,221 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { | ||
| 3 | useElementBounding, | ||
| 4 | useElementByPoint, | ||
| 5 | useElementVisibility, | ||
| 6 | useEventListener, | ||
| 7 | useMouse, | ||
| 8 | useMouseInElement, | ||
| 9 | useStorage | ||
| 10 | } from '@vueuse/core' | ||
| 11 | import { useRoute } from 'vitepress' | ||
| 12 | import { inject, nextTick, onMounted, reactive, ref, watch } from 'vue' | ||
| 13 | |||
| 14 | import { | ||
| 15 | InjectionKey, | ||
| 16 | SpotlightStyle, | ||
| 17 | SpotlightStylesStorageKey | ||
| 18 | } from '../../constants' | ||
| 19 | |||
| 20 | const props = defineProps<{ enabled: boolean }>() | ||
| 21 | |||
| 22 | const options = inject(InjectionKey, {}) | ||
| 23 | |||
| 24 | const shouldRecalculate = ref(false) | ||
| 25 | const boxStyles = ref<Record<string, string | number>>({ display: 'none' }) | ||
| 26 | const vpDocElement = ref<HTMLDivElement>() | ||
| 27 | const highlightedElement = ref<HTMLElement>() | ||
| 28 | |||
| 29 | const route = useRoute() | ||
| 30 | const spotlightStyle = useStorage<SpotlightStyle>( | ||
| 31 | SpotlightStylesStorageKey, | ||
| 32 | options.spotlight?.defaultStyle || SpotlightStyle.Aside | ||
| 33 | ) | ||
| 34 | |||
| 35 | const { x, y } = useMouse({ type: 'client' }) | ||
| 36 | const { isOutside } = useMouseInElement(vpDocElement) | ||
| 37 | const { element } = useElementByPoint({ x, y }) | ||
| 38 | const bounding = reactive(useElementBounding(element)) | ||
| 39 | const elementVisibility = useElementVisibility(highlightedElement) | ||
| 40 | |||
| 41 | useEventListener('scroll', bounding.update, true) | ||
| 42 | |||
| 43 | function computeBoxStyles(bounding: { | ||
| 44 | height: number | ||
| 45 | left: number | ||
| 46 | top: number | ||
| 47 | width: number | ||
| 48 | }) { | ||
| 49 | return { | ||
| 50 | display: 'block', | ||
| 51 | width: `${bounding.width + 8}px`, | ||
| 52 | height: `${bounding.height + 8}px`, | ||
| 53 | left: `${bounding.left - 4}px`, | ||
| 54 | top: `${bounding.top - 4}px`, | ||
| 55 | transition: 'all 0.2s ease', | ||
| 56 | borderRadius: '8px' | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | function findChildElementUnderVPDocElement(element: HTMLElement | null) { | ||
| 61 | if (element === null) return null | ||
| 62 | |||
| 63 | if ( | ||
| 64 | element.parentElement === | ||
| 65 | document.querySelector('.VPDoc main .vp-doc > div') | ||
| 66 | ) { | ||
| 67 | return element | ||
| 68 | } else return findChildElementUnderVPDocElement(element.parentElement) | ||
| 69 | } | ||
| 70 | |||
| 71 | function watchHandler() { | ||
| 72 | if (!(element.value && !isOutside.value)) return | ||
| 73 | |||
| 74 | const el = findChildElementUnderVPDocElement(element.value) | ||
| 75 | highlightedElement.value = el || undefined | ||
| 76 | |||
| 77 | if (highlightedElement.value && highlightedElement.value.tagName === 'P') { | ||
| 78 | const val = highlightedElement.value | ||
| 79 | const style = window.getComputedStyle(val) | ||
| 80 | const lineHeight = Number.parseFloat(style.lineHeight) | ||
| 81 | const lines = Math.floor(val.offsetHeight / lineHeight) | ||
| 82 | |||
| 83 | const rect = val.getBoundingClientRect() | ||
| 84 | const relativeY = y.value - rect.top | ||
| 85 | |||
| 86 | for (let i = 0; i < lines; i++) { | ||
| 87 | const top = i * lineHeight | ||
| 88 | const height = lineHeight | ||
| 89 | const left = val.offsetLeft | ||
| 90 | const width = val.offsetWidth | ||
| 91 | |||
| 92 | if (relativeY >= top && relativeY < top + height) { | ||
| 93 | boxStyles.value = computeBoxStyles({ | ||
| 94 | top: top + rect.top, | ||
| 95 | left: left + rect.left, | ||
| 96 | width, | ||
| 97 | height | ||
| 98 | }) | ||
| 99 | |||
| 100 | break | ||
| 101 | } | ||
| 102 | } | ||
| 103 | } else { | ||
| 104 | if (highlightedElement.value) { | ||
| 105 | const rect = highlightedElement.value.getBoundingClientRect() | ||
| 106 | |||
| 107 | boxStyles.value = computeBoxStyles({ | ||
| 108 | top: rect.top, | ||
| 109 | left: rect.left, | ||
| 110 | width: rect.width, | ||
| 111 | height: rect.height | ||
| 112 | }) | ||
| 113 | } | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | onMounted(() => { | ||
| 118 | if (!document) return | ||
| 119 | if (!document.body) return | ||
| 120 | |||
| 121 | document.body.style.setProperty( | ||
| 122 | '--vp-nolebase-enhanced-readabilities-spotlight-under-bg-color', | ||
| 123 | options?.spotlight?.hoverBlockColor || `rgb(240 197 52 / 10%)` | ||
| 124 | ) | ||
| 125 | |||
| 126 | vpDocElement.value = document.querySelector( | ||
| 127 | '.VPDoc main .vp-doc' | ||
| 128 | ) as HTMLDivElement | ||
| 129 | }) | ||
| 130 | |||
| 131 | watch(route, async () => { | ||
| 132 | // Wait for the next tick to ensure the DOM is updated since the route change | ||
| 133 | // may trigger a page reload. | ||
| 134 | await nextTick() | ||
| 135 | |||
| 136 | vpDocElement.value = document.querySelector( | ||
| 137 | '.VPDoc main .vp-doc' | ||
| 138 | ) as HTMLDivElement | ||
| 139 | |||
| 140 | shouldRecalculate.value = true | ||
| 141 | boxStyles.value = { display: 'none' } | ||
| 142 | |||
| 143 | bounding.update() | ||
| 144 | |||
| 145 | watchHandler() | ||
| 146 | shouldRecalculate.value = false | ||
| 147 | }) | ||
| 148 | |||
| 149 | watch([x, y], () => { | ||
| 150 | if (props.enabled) watchHandler() | ||
| 151 | }) | ||
| 152 | |||
| 153 | watch(bounding, (val) => { | ||
| 154 | if (!props.enabled) return | ||
| 155 | |||
| 156 | if (val.width === 0 && val.height === 0) boxStyles.value = { display: 'none' } | ||
| 157 | else watchHandler() | ||
| 158 | }) | ||
| 159 | |||
| 160 | watch(elementVisibility, (val) => { | ||
| 161 | if (props.enabled && !val) boxStyles.value = { display: 'none' } | ||
| 162 | }) | ||
| 163 | |||
| 164 | watch( | ||
| 165 | () => props.enabled, | ||
| 166 | (val) => { | ||
| 167 | if (!val) boxStyles.value = { display: 'none' } | ||
| 168 | } | ||
| 169 | ) | ||
| 170 | </script> | ||
| 171 | |||
| 172 | <template> | ||
| 173 | <Teleport to="body"> | ||
| 174 | <div | ||
| 175 | v-if="props.enabled && !shouldRecalculate" | ||
| 176 | :style="boxStyles" | ||
| 177 | aria-hidden="true" | ||
| 178 | focusable="false" | ||
| 179 | pointer-events-none | ||
| 180 | fixed | ||
| 181 | class="VPNolebaseEnhancedReadabilitiesSpotlightHoverBlock" | ||
| 182 | :class="[ | ||
| 183 | spotlightStyle === SpotlightStyle.Under | ||
| 184 | ? 'VPNolebaseEnhancedReadabilitiesSpotlightHoverBlockUnder' | ||
| 185 | : '', | ||
| 186 | spotlightStyle === SpotlightStyle.Aside | ||
| 187 | ? 'VPNolebaseEnhancedReadabilitiesSpotlightHoverBlockAside' | ||
| 188 | : '' | ||
| 189 | ]" | ||
| 190 | /> | ||
| 191 | </Teleport> | ||
| 192 | </template> | ||
| 193 | |||
| 194 | <style less scoped> | ||
| 195 | :root { | ||
| 196 | --vp-nolebase-enhanced-readabilities-spotlight-under-bg-color: rgb( | ||
| 197 | 240 | ||
| 198 | 197 | ||
| 199 | 52 | ||
| 200 | / | ||
| 201 | 10% | ||
| 202 | ); | ||
| 203 | } | ||
| 204 | |||
| 205 | .VPNolebaseEnhancedReadabilitiesSpotlightHoverBlock.VPNolebaseEnhancedReadabilitiesSpotlightHoverBlockUnder { | ||
| 206 | background-color: var( | ||
| 207 | --vp-nolebase-enhanced-readabilities-spotlight-under-bg-color | ||
| 208 | ); | ||
| 209 | } | ||
| 210 | |||
| 211 | .VPNolebaseEnhancedReadabilitiesSpotlightHoverBlock.VPNolebaseEnhancedReadabilitiesSpotlightHoverBlockAside::before { | ||
| 212 | content: ""; | ||
| 213 | position: absolute; | ||
| 214 | display: block; | ||
| 215 | width: 4px; | ||
| 216 | height: 100%; | ||
| 217 | border-radius: 4px; | ||
| 218 | background-color: var(--vp-c-brand); | ||
| 219 | left: -24px; | ||
| 220 | } | ||
| 221 | </style> | ||
docs/.vitepress/theme/components/settings/SpotlightStyles.vue deleted −156
| @@ -1,156 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { NuInputHighlight, NuInputHorizontalRadioGroup } from '@nolebase/ui' | ||
| 3 | import { useMediaQuery, useStorage } from '@vueuse/core' | ||
| 4 | import { computed, inject, onMounted, ref, watch } from 'vue' | ||
| 5 | |||
| 6 | import MenuHelp from './MenuHelp.vue' | ||
| 7 | import MenuTitle from './MenuTitle.vue' | ||
| 8 | |||
| 9 | import { | ||
| 10 | InjectionKey, | ||
| 11 | SpotlightStyle, | ||
| 12 | SpotlightStylesStorageKey, | ||
| 13 | SpotlightToggledStorageKey | ||
| 14 | } from '../../constants' | ||
| 15 | |||
| 16 | const options = inject(InjectionKey, {}) | ||
| 17 | |||
| 18 | const menuTitleElementRef = ref<HTMLDivElement>() | ||
| 19 | const isMenuHelpPoppedUp = ref(false) | ||
| 20 | const disabled = ref(false) | ||
| 21 | |||
| 22 | const isTouchScreen = useMediaQuery('(pointer: coarse)') | ||
| 23 | const spotlightToggledOn = useStorage( | ||
| 24 | SpotlightToggledStorageKey, | ||
| 25 | options.spotlight?.defaultToggle || false | ||
| 26 | ) | ||
| 27 | const spotlightStyle = useStorage<SpotlightStyle>( | ||
| 28 | SpotlightStylesStorageKey, | ||
| 29 | options.spotlight?.defaultStyle || SpotlightStyle.Aside | ||
| 30 | ) | ||
| 31 | |||
| 32 | const fieldOptions = computed(() => [ | ||
| 33 | { | ||
| 34 | value: SpotlightStyle.Under, | ||
| 35 | title: 'Under', | ||
| 36 | ariaLabel: 'Under', | ||
| 37 | icon: 'i-icon-park-outline:align-text-left-one', | ||
| 38 | name: 'VitePress Nolebase Enhanced Readabilities Spotlight Style Checkbox' | ||
| 39 | }, | ||
| 40 | { | ||
| 41 | value: SpotlightStyle.Aside, | ||
| 42 | title: 'Aside', | ||
| 43 | ariaLabel: 'Aside', | ||
| 44 | icon: 'i-icon-park-outline:align-left-one', | ||
| 45 | name: 'VitePress Nolebase Enhanced Readabilities Spotlight Style Checkbox' | ||
| 46 | } | ||
| 47 | ]) | ||
| 48 | |||
| 49 | onMounted(() => { | ||
| 50 | disabled.value = isTouchScreen.value | ||
| 51 | }) | ||
| 52 | |||
| 53 | watch(isTouchScreen, () => { | ||
| 54 | disabled.value = isTouchScreen.value | ||
| 55 | }) | ||
| 56 | </script> | ||
| 57 | |||
| 58 | <template> | ||
| 59 | <Transition name="fade-shift"> | ||
| 60 | <div | ||
| 61 | v-if="spotlightToggledOn" | ||
| 62 | space-y-2 | ||
| 63 | role="radiogroup" | ||
| 64 | class="VPNolebaseEnhancedReadabilitiesSpotlightStyles" | ||
| 65 | > | ||
| 66 | <div ref="menuTitleElementRef" relative flex items-center> | ||
| 67 | <MenuTitle | ||
| 68 | title="Spotlight Styles" | ||
| 69 | aria-label="Spotlight Styles" | ||
| 70 | :disabled="disabled" | ||
| 71 | flex="1" | ||
| 72 | pr-4 | ||
| 73 | > | ||
| 74 | <template #icon> | ||
| 75 | <span i-icon-park-outline:click mr-1 aria-hidden="true" /> | ||
| 76 | </template> | ||
| 77 | </MenuTitle> | ||
| 78 | <MenuHelp | ||
| 79 | v-if="!options.spotlight?.disableHelp" | ||
| 80 | v-model:is-popped-up="isMenuHelpPoppedUp" | ||
| 81 | :menu-title-element-ref="menuTitleElementRef" | ||
| 82 | > | ||
| 83 | <h4 text-md mb-1 font-semibold>Spotlight Styles</h4> | ||
| 84 | <p text="sm" mb-2 max-w-100> | ||
| 85 | <span>Adjust the styles of Spotlight.</span> | ||
| 86 | </p> | ||
| 87 | <div space-y-2 class="VPNolebaseEnhancedReadabilitiesMenu"> | ||
| 88 | <div | ||
| 89 | text="sm" | ||
| 90 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 91 | max-w-100 | ||
| 92 | rounded-xl | ||
| 93 | p-3 | ||
| 94 | > | ||
| 95 | <h5 text="sm" mb-2> | ||
| 96 | <span i-icon-park-outline:align-text-left-one mr-1 /> | ||
| 97 | <span font-semibold>Under</span> | ||
| 98 | </h5> | ||
| 99 | <span> | ||
| 100 | Add a solid background color underneath the hovering element to | ||
| 101 | highlight where the cursor is currently hovering. | ||
| 102 | </span> | ||
| 103 | </div> | ||
| 104 | <div | ||
| 105 | text="sm" | ||
| 106 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 107 | max-w-100 | ||
| 108 | rounded-xl | ||
| 109 | p-3 | ||
| 110 | > | ||
| 111 | <h5 text="sm" mb-2> | ||
| 112 | <span i-icon-park-outline:align-left-one mr-1 /> | ||
| 113 | <span font-semibold>Aside</span> | ||
| 114 | </h5> | ||
| 115 | <span> | ||
| 116 | Add a fixed line with solid color aside the hovering element to | ||
| 117 | highlight where the cursor is currently hovering. | ||
| 118 | </span> | ||
| 119 | </div> | ||
| 120 | </div> | ||
| 121 | </MenuHelp> | ||
| 122 | </div> | ||
| 123 | <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md"> | ||
| 124 | <NuInputHorizontalRadioGroup | ||
| 125 | v-model="spotlightStyle" | ||
| 126 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 127 | text="sm $vp-nolebase-enhanced-readabilities-menu-text-color" | ||
| 128 | :options="fieldOptions" | ||
| 129 | :disabled="disabled" | ||
| 130 | /> | ||
| 131 | </NuInputHighlight> | ||
| 132 | </div> | ||
| 133 | </Transition> | ||
| 134 | </template> | ||
| 135 | |||
| 136 | <style scoped> | ||
| 137 | .VPNolebaseEnhancedReadabilitiesSpotlightStyles { | ||
| 138 | max-height: 100px; | ||
| 139 | height: 100%; | ||
| 140 | } | ||
| 141 | |||
| 142 | .fade-shift-enter-active, | ||
| 143 | .fade-shift-leave-active { | ||
| 144 | transition: | ||
| 145 | opacity 0.2s ease-in-out, | ||
| 146 | transform 0.2s ease-in-out, | ||
| 147 | max-height 0.2s ease-in-out; | ||
| 148 | } | ||
| 149 | |||
| 150 | .fade-shift-enter-from, | ||
| 151 | .fade-shift-leave-to { | ||
| 152 | opacity: 0; | ||
| 153 | transform: translateY(-8px); | ||
| 154 | max-height: 0; | ||
| 155 | } | ||
| 156 | </style> | ||
docs/.vitepress/theme/components/settings/index.ts +1 −65
| @@ -1,67 +1,3 @@ | |||
| 1 | import type { Plugin } from 'vue' | ||
| 2 | |||
| 3 | import type { Options } from '../../types' | ||
| 4 | |||
| 5 | import Effects from './Effects.vue' | ||
| 6 | import LayoutSwitch from './LayoutSwitch.vue' | ||
| 7 | import LayoutSwitchContentLayoutMaxWidthSlider from './LayoutSwitchContentLayoutMaxWidthSlider.vue' | ||
| 8 | import LayoutSwitchPageLayoutMaxWidthSlider from './LayoutSwitchPageLayoutMaxWidthSlider.vue' | ||
| 9 | import NolebaseEnhancedReadabilitiesMenu from './Menu.vue' | ||
| 10 | import ScreenLayoutSwitch from './ScreenLayoutSwitch.vue' | ||
| 11 | import NolebaseEnhancedReadabilitiesScreenMenu from './ScreenMenu.vue' | 1 | import NolebaseEnhancedReadabilitiesScreenMenu from './ScreenMenu.vue' |
| 12 | import ScreenSpotlight from './ScreenSpotlight.vue' | ||
| 13 | import Spotlight from './Spotlight.vue' | ||
| 14 | import SpotlightStyles from './SpotlightStyles.vue' | ||
| 15 | |||
| 16 | import { | ||
| 17 | InjectionKey, | ||
| 18 | LayoutMode, | ||
| 19 | EffectsStorageKey, | ||
| 20 | LayoutSwitchModeStorageKey, | ||
| 21 | SpotlightStyle, | ||
| 22 | SpotlightToggledStorageKey | ||
| 23 | } from '../../constants' | ||
| 24 | |||
| 25 | export type { Options } | ||
| 26 | |||
| 27 | export { | ||
| 28 | Effects, | ||
| 29 | EffectsStorageKey, | ||
| 30 | InjectionKey, | ||
| 31 | LayoutMode, | ||
| 32 | LayoutSwitch, | ||
| 33 | LayoutSwitchContentLayoutMaxWidthSlider, | ||
| 34 | LayoutSwitchModeStorageKey, | ||
| 35 | LayoutSwitchPageLayoutMaxWidthSlider, | ||
| 36 | NolebaseEnhancedReadabilitiesMenu, | ||
| 37 | NolebaseEnhancedReadabilitiesScreenMenu, | ||
| 38 | ScreenLayoutSwitch, | ||
| 39 | ScreenSpotlight, | ||
| 40 | Spotlight, | ||
| 41 | SpotlightStyle, | ||
| 42 | SpotlightStyles, | ||
| 43 | SpotlightToggledStorageKey | ||
| 44 | } | ||
| 45 | |||
| 46 | const components = { | ||
| 47 | NolebaseEnhancedReadabilitiesEffects: Effects, | ||
| 48 | NolebaseEnhancedReadabilitiesMenu, | ||
| 49 | NolebaseEnhancedReadabilitiesScreenMenu, | ||
| 50 | NolebaseEnhancedReadabilitiesLayoutSwitch: LayoutSwitch, | ||
| 51 | NolebaseEnhancedReadabilitiesScreenLayoutSwitch: ScreenLayoutSwitch, | ||
| 52 | NolebaseEnhancedReadabilitiesSpotlight: Spotlight, | ||
| 53 | NolebaseEnhancedReadabilitiesSpotlightStyles: SpotlightStyles, | ||
| 54 | NolebaseEnhancedReadabilitiesScreenSpotlight: ScreenSpotlight | ||
| 55 | } | ||
| 56 | |||
| 57 | export const NolebaseEnhancedReadabilitiesPlugin: Plugin<Options[]> = { | ||
| 58 | install(app, options?) { | ||
| 59 | if (typeof options !== 'undefined' && typeof options === 'object') { | ||
| 60 | app.provide(InjectionKey, options) | ||
| 61 | } | ||
| 62 | 2 | ||
| 63 | for (const key of Object.keys(components)) { | 3 | export { NolebaseEnhancedReadabilitiesScreenMenu } |
| 64 | app.component(key, components[key as keyof typeof components]) | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
docs/.vitepress/theme/composables/animation.ts deleted −23
| @@ -1,23 +0,0 @@ | |||
| 1 | import { useDebounceFn, useMounted } from '@vueuse/core' | ||
| 2 | |||
| 3 | export function useLayoutAppearanceChangeAnimation() { | ||
| 4 | const mounted = useMounted() | ||
| 5 | |||
| 6 | return { | ||
| 7 | trigger: (animateElement: HTMLElement) => { | ||
| 8 | animateElement.classList.add( | ||
| 9 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchAnimated' | ||
| 10 | ) | ||
| 11 | |||
| 12 | const removeAnimatedClassName = useDebounceFn(() => { | ||
| 13 | if (!(mounted.value && animateElement)) return | ||
| 14 | |||
| 15 | animateElement.classList.remove( | ||
| 16 | 'VPNolebaseEnhancedReadabilitiesLayoutSwitchAnimated' | ||
| 17 | ) | ||
| 18 | }, 5000) | ||
| 19 | |||
| 20 | removeAnimatedClassName() | ||
| 21 | } | ||
| 22 | } | ||
| 23 | } | ||
docs/.vitepress/theme/composables/op.ts deleted −28
| @@ -1,28 +0,0 @@ | |||
| 1 | /** | ||
| 2 | * All Rights Reserved | ||
| 3 | * | ||
| 4 | * Copyright (c) 2025 taskylizard | ||
| 5 | * | ||
| 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 | */ | ||
| 8 | import type { App, InjectionKey } from 'vue' | ||
| 9 | import { Internal } from '../internal/browser' | ||
| 10 | |||
| 11 | export const opSymbol: InjectionKey<Internal> = Symbol('op') | ||
| 12 | |||
| 13 | export function createOpProvider(app: App) { | ||
| 14 | // Disable in dev | ||
| 15 | if (import.meta.env.DEV) return | ||
| 16 | |||
| 17 | const op = new Internal({ | ||
| 18 | clientId: 'e0e39d6b-2692-45a0-9422-4d668f113f70', | ||
| 19 | trackScreenViews: true, | ||
| 20 | trackOutgoingLinks: true, | ||
| 21 | trackAttributes: true, | ||
| 22 | trackHashChanges: true | ||
| 23 | }) | ||
| 24 | |||
| 25 | op.init() | ||
| 26 | |||
| 27 | app.provide(opSymbol, op) | ||
| 28 | } | ||
docs/.vitepress/theme/composables/useTooltips.ts deleted −32
| @@ -1,32 +0,0 @@ | |||
| 1 | /** | ||
| 2 | * All Rights Reserved | ||
| 3 | * | ||
| 4 | * Copyright (c) 2025 taskylizard | ||
| 5 | * | ||
| 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 | */ | ||
| 8 | import { getTooltip, type TooltipData } from 'virtual:tooltips' | ||
| 9 | import { ref } from 'vue' | ||
| 10 | |||
| 11 | const tooltipCache = ref<Map<string, TooltipData>>(new Map()) | ||
| 12 | |||
| 13 | export function useTooltips() { | ||
| 14 | const getTooltipData = (id: string): TooltipData | null => { | ||
| 15 | if (tooltipCache.value.has(id)) { | ||
| 16 | return tooltipCache.value.get(id)! | ||
| 17 | } | ||
| 18 | |||
| 19 | const tooltip = getTooltip(id) | ||
| 20 | if (tooltip) { | ||
| 21 | tooltipCache.value.set(id, tooltip) | ||
| 22 | return tooltip | ||
| 23 | } | ||
| 24 | |||
| 25 | console.warn(`Tooltip with id "${id}" not found`) | ||
| 26 | return null | ||
| 27 | } | ||
| 28 | |||
| 29 | return { | ||
| 30 | getTooltipData | ||
| 31 | } | ||
| 32 | } | ||
docs/.vitepress/theme/constants.ts −58
| @@ -1,63 +1,5 @@ | |||
| 1 | import type { InjectionKey as VueInjectionKey } from 'vue' | ||
| 2 | |||
| 3 | import type { Options } from './types' | ||
| 4 | // @ts-ignore - VitePress doesn't have types for its internal components | ||
| 5 | import _VPFlyout from 'vitepress/dist/client/theme-default/components/VPFlyout.vue' | ||
| 6 | // @ts-ignore - VitePress doesn't have types for its internal components | ||
| 7 | import _VPLocalNavOutlineDropdown from 'vitepress/dist/client/theme-default/components/VPLocalNavOutlineDropdown.vue' | ||
| 8 | export const VPFlyout: any = _VPFlyout | ||
| 9 | export const VPLocalNavOutlineDropdown: any = _VPLocalNavOutlineDropdown | ||
| 10 | |||
| 11 | export const InjectionKey: VueInjectionKey<Options> = Symbol( | ||
| 12 | 'vitepress-nolebase-enhanced-readabilities' | ||
| 13 | ) | ||
| 14 | |||
| 15 | export const LayoutSwitchModeStorageKey = | ||
| 16 | 'vitepress-nolebase-enhanced-readabilities-layout-switch-mode' | ||
| 17 | export const LayoutSwitchMaxWidthStrategyStorageKey = | ||
| 18 | 'vitepress-nolebase-enhanced-readabilities-layout-switch-max-width-strategy' | ||
| 19 | export const ContentLayoutMaxWidthStorageKey = | ||
| 20 | 'vitepress-nolebase-enhanced-readabilities-content-layout-max-width' | ||
| 21 | export const PageLayoutMaxWidthStorageKey = | ||
| 22 | 'vitepress-nolebase-enhanced-readabilities-page-layout-max-width' | ||
| 23 | |||
| 24 | export const SpotlightToggledStorageKey = | ||
| 25 | 'vitepress-nolebase-enhanced-readabilities-spotlight-mode' | ||
| 26 | export const SpotlightStylesStorageKey = | ||
| 27 | 'vitepress-nolebase-enhanced-readabilities-spotlight-styles' | ||
| 28 | |||
| 29 | export const EffectsStorageKey = 'preference-effects' | 1 | export const EffectsStorageKey = 'preference-effects' |
| 30 | /** Legacy on/off key for the cursor companion; migrated to {@link PetStorageKey}. */ | ||
| 31 | export const TakodachiStorageKey = 'preference-takodachi' | ||
| 32 | /** Whether the cursor pet companion is enabled. */ | ||
| 33 | export const PetStorageKey = 'preference-pet' | ||
| 34 | /** Which pet character follows the cursor (see `pets.ts`). */ | ||
| 35 | export const PetCharacterStorageKey = 'preference-pet-character' | ||
| 36 | export const AccentColorStorageKey = 'preference-accent-color' | 2 | export const AccentColorStorageKey = 'preference-accent-color' |
| 37 | export const AccentBgStorageKey = 'preference-accent-bg' | 3 | export const AccentBgStorageKey = 'preference-accent-bg' |
| 38 | /** Accent background tint strength, 0–100. */ | 4 | /** Accent background tint strength, 0–100. */ |
| 39 | export const AccentBgStrengthStorageKey = 'preference-accent-bg-strength' | 5 | export const AccentBgStrengthStorageKey = 'preference-accent-bg-strength' |
| 40 | |||
| 41 | export enum LayoutMode { | ||
| 42 | FullWidth = 1, | ||
| 43 | Original = 3, | ||
| 44 | SidebarWidthAdjustableOnly = 4, | ||
| 45 | BothWidthAdjustable = 5 | ||
| 46 | } | ||
| 47 | |||
| 48 | export const supportedLayoutModes = [ | ||
| 49 | LayoutMode.FullWidth, | ||
| 50 | LayoutMode.Original, | ||
| 51 | LayoutMode.SidebarWidthAdjustableOnly, | ||
| 52 | LayoutMode.BothWidthAdjustable | ||
| 53 | ] | ||
| 54 | |||
| 55 | export enum SpotlightStyle { | ||
| 56 | Under = 1, | ||
| 57 | Aside = 2 | ||
| 58 | } | ||
| 59 | |||
| 60 | export const supportedSpotlightStyles = [ | ||
| 61 | SpotlightStyle.Under, | ||
| 62 | SpotlightStyle.Aside | ||
| 63 | ] | ||
docs/.vitepress/theme/internal/api.ts deleted −294
| @@ -1,294 +0,0 @@ | |||
| 1 | /** | ||
| 2 | * All Rights Reserved | ||
| 3 | * | ||
| 4 | * Copyright (c) 2025 taskylizard | ||
| 5 | * | ||
| 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 | */ | ||
| 8 | interface ApiConfig { | ||
| 9 | baseUrl: string | ||
| 10 | defaultHeaders?: Record<string, string | Promise<string | null>> | ||
| 11 | maxRetries?: number | ||
| 12 | initialRetryDelay?: number | ||
| 13 | } | ||
| 14 | |||
| 15 | interface FetchOptions extends RequestInit { | ||
| 16 | retries?: number | ||
| 17 | } | ||
| 18 | |||
| 19 | class Api { | ||
| 20 | private baseUrl: string | ||
| 21 | private headers: Record<string, string | Promise<string | null>> | ||
| 22 | private maxRetries: number | ||
| 23 | private initialRetryDelay: number | ||
| 24 | |||
| 25 | constructor(config: ApiConfig) { | ||
| 26 | this.baseUrl = config.baseUrl | ||
| 27 | this.headers = { | ||
| 28 | 'Content-Type': 'application/json', | ||
| 29 | ...config.defaultHeaders | ||
| 30 | } | ||
| 31 | this.maxRetries = config.maxRetries ?? 3 | ||
| 32 | this.initialRetryDelay = config.initialRetryDelay ?? 500 | ||
| 33 | } | ||
| 34 | |||
| 35 | private async resolveHeaders(): Promise<Record<string, string>> { | ||
| 36 | const resolvedHeaders: Record<string, string> = {} | ||
| 37 | for (const [key, value] of Object.entries(this.headers)) { | ||
| 38 | const resolvedValue = await value | ||
| 39 | if (resolvedValue !== null) { | ||
| 40 | resolvedHeaders[key] = resolvedValue | ||
| 41 | } | ||
| 42 | } | ||
| 43 | return resolvedHeaders | ||
| 44 | } | ||
| 45 | |||
| 46 | public addHeader(key: string, value: string | Promise<string | null>) { | ||
| 47 | this.headers[key] = value | ||
| 48 | } | ||
| 49 | |||
| 50 | private async post<ReqBody, ResBody>( | ||
| 51 | url: string, | ||
| 52 | data: ReqBody, | ||
| 53 | options: FetchOptions, | ||
| 54 | attempt: number | ||
| 55 | ): Promise<ResBody | null> { | ||
| 56 | try { | ||
| 57 | const response = await fetch(url, { | ||
| 58 | method: 'POST', | ||
| 59 | headers: await this.resolveHeaders(), | ||
| 60 | body: JSON.stringify(data ?? {}), | ||
| 61 | keepalive: true, | ||
| 62 | ...options | ||
| 63 | }) | ||
| 64 | |||
| 65 | if (response.status === 401) return null | ||
| 66 | |||
| 67 | if (response.status !== 200 && response.status !== 202) { | ||
| 68 | throw new Error(`HTTP error! status: ${response.status}`) | ||
| 69 | } | ||
| 70 | |||
| 71 | const responseText = await response.text() | ||
| 72 | return responseText ? JSON.parse(responseText) : null | ||
| 73 | } catch (error) { | ||
| 74 | if (attempt < this.maxRetries) { | ||
| 75 | const delay = this.initialRetryDelay * 2 ** attempt | ||
| 76 | await new Promise((resolve) => setTimeout(resolve, delay)) | ||
| 77 | return this.post<ReqBody, ResBody>(url, data, options, attempt + 1) | ||
| 78 | } | ||
| 79 | console.error('Max retries reached:', error) | ||
| 80 | return null | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | async fetch<ReqBody, ResBody>( | ||
| 85 | path: string, | ||
| 86 | data: ReqBody, | ||
| 87 | options: FetchOptions = {} | ||
| 88 | ): Promise<ResBody | null> { | ||
| 89 | const url = `${this.baseUrl}${path}` | ||
| 90 | return this.post<ReqBody, ResBody>(url, data, options, 0) | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | export type TrackHandlerPayload = | ||
| 95 | | { | ||
| 96 | type: 'track' | ||
| 97 | payload: TrackPayload | ||
| 98 | } | ||
| 99 | | { | ||
| 100 | type: 'increment' | ||
| 101 | payload: IncrementPayload | ||
| 102 | } | ||
| 103 | | { | ||
| 104 | type: 'decrement' | ||
| 105 | payload: DecrementPayload | ||
| 106 | } | ||
| 107 | | { | ||
| 108 | type: 'alias' | ||
| 109 | payload: AliasPayload | ||
| 110 | } | ||
| 111 | | { | ||
| 112 | type: 'identify' | ||
| 113 | payload: IdentifyPayload | ||
| 114 | } | ||
| 115 | |||
| 116 | export type TrackPayload = { | ||
| 117 | name: string | ||
| 118 | properties?: Record<string, unknown> | ||
| 119 | profileId?: string | ||
| 120 | } | ||
| 121 | |||
| 122 | export type TrackProperties = { | ||
| 123 | [key: string]: unknown | ||
| 124 | profileId?: string | ||
| 125 | } | ||
| 126 | |||
| 127 | export type IdentifyPayload = { | ||
| 128 | profileId: string | ||
| 129 | firstName?: string | ||
| 130 | lastName?: string | ||
| 131 | email?: string | ||
| 132 | avatar?: string | ||
| 133 | properties?: Record<string, unknown> | ||
| 134 | } | ||
| 135 | |||
| 136 | export type AliasPayload = { | ||
| 137 | profileId: string | ||
| 138 | alias: string | ||
| 139 | } | ||
| 140 | |||
| 141 | export type IncrementPayload = { | ||
| 142 | profileId: string | ||
| 143 | property: string | ||
| 144 | value?: number | ||
| 145 | } | ||
| 146 | |||
| 147 | export type DecrementPayload = { | ||
| 148 | profileId: string | ||
| 149 | property: string | ||
| 150 | value?: number | ||
| 151 | } | ||
| 152 | |||
| 153 | export type InternalOptions = { | ||
| 154 | clientId: string | ||
| 155 | clientSecret?: string | ||
| 156 | apiUrl?: string | ||
| 157 | sdk?: string | ||
| 158 | sdkVersion?: string | ||
| 159 | waitForProfile?: boolean | ||
| 160 | filter?: (payload: TrackHandlerPayload) => boolean | ||
| 161 | disabled?: boolean | ||
| 162 | } | ||
| 163 | |||
| 164 | export class InternalAPI { | ||
| 165 | api: Api | ||
| 166 | profileId?: string | ||
| 167 | global?: Record<string, unknown> | ||
| 168 | queue: TrackHandlerPayload[] = [] | ||
| 169 | |||
| 170 | constructor(public options: InternalOptions) { | ||
| 171 | const defaultHeaders: Record<string, string> = { | ||
| 172 | 'openpanel-client-id': options.clientId | ||
| 173 | } | ||
| 174 | |||
| 175 | if (options.clientSecret) { | ||
| 176 | defaultHeaders['openpanel-client-secret'] = options.clientSecret | ||
| 177 | } | ||
| 178 | |||
| 179 | defaultHeaders['openpanel-sdk-name'] = options.sdk || 'node' | ||
| 180 | defaultHeaders['openpanel-sdk-version'] = options.sdkVersion || | ||
| 181 | process.env.SDK_VERSION! | ||
| 182 | |||
| 183 | this.api = new Api({ | ||
| 184 | baseUrl: 'https://wotaku.wiki', | ||
| 185 | defaultHeaders | ||
| 186 | }) | ||
| 187 | } | ||
| 188 | |||
| 189 | // placeholder for future use | ||
| 190 | init() { | ||
| 191 | // empty | ||
| 192 | } | ||
| 193 | |||
| 194 | ready() { | ||
| 195 | this.options.waitForProfile = false | ||
| 196 | this.flush() | ||
| 197 | } | ||
| 198 | |||
| 199 | async send(payload: TrackHandlerPayload) { | ||
| 200 | if (this.options.disabled) { | ||
| 201 | return Promise.resolve() | ||
| 202 | } | ||
| 203 | |||
| 204 | if (this.options.filter && !this.options.filter(payload)) { | ||
| 205 | return Promise.resolve() | ||
| 206 | } | ||
| 207 | |||
| 208 | if (this.options.waitForProfile && !this.profileId) { | ||
| 209 | this.queue.push(payload) | ||
| 210 | return Promise.resolve() | ||
| 211 | } | ||
| 212 | return this.api.fetch('/icons', payload) | ||
| 213 | } | ||
| 214 | |||
| 215 | setGlobalProperties(properties: Record<string, unknown>) { | ||
| 216 | this.global = { | ||
| 217 | ...this.global, | ||
| 218 | ...properties | ||
| 219 | } | ||
| 220 | } | ||
| 221 | |||
| 222 | async track(name: string, properties?: TrackProperties) { | ||
| 223 | return this.send({ | ||
| 224 | type: 'track', | ||
| 225 | payload: { | ||
| 226 | name, | ||
| 227 | profileId: properties?.profileId ?? this.profileId, | ||
| 228 | properties: { | ||
| 229 | ...(this.global ?? {}), | ||
| 230 | ...(properties ?? {}) | ||
| 231 | } | ||
| 232 | } | ||
| 233 | }) | ||
| 234 | } | ||
| 235 | |||
| 236 | async identify(payload: IdentifyPayload) { | ||
| 237 | if (payload.profileId) { | ||
| 238 | this.profileId = payload.profileId | ||
| 239 | this.flush() | ||
| 240 | } | ||
| 241 | |||
| 242 | if (Object.keys(payload).length > 1) { | ||
| 243 | return this.send({ | ||
| 244 | type: 'identify', | ||
| 245 | payload: { | ||
| 246 | ...payload, | ||
| 247 | properties: { | ||
| 248 | ...this.global, | ||
| 249 | ...payload.properties | ||
| 250 | } | ||
| 251 | } | ||
| 252 | }) | ||
| 253 | } | ||
| 254 | } | ||
| 255 | |||
| 256 | async alias(payload: AliasPayload) { | ||
| 257 | return this.send({ | ||
| 258 | type: 'alias', | ||
| 259 | payload | ||
| 260 | }) | ||
| 261 | } | ||
| 262 | |||
| 263 | async increment(payload: IncrementPayload) { | ||
| 264 | return this.send({ | ||
| 265 | type: 'increment', | ||
| 266 | payload | ||
| 267 | }) | ||
| 268 | } | ||
| 269 | |||
| 270 | async decrement(payload: DecrementPayload) { | ||
| 271 | return this.send({ | ||
| 272 | type: 'decrement', | ||
| 273 | payload | ||
| 274 | }) | ||
| 275 | } | ||
| 276 | |||
| 277 | clear() { | ||
| 278 | this.profileId = undefined | ||
| 279 | } | ||
| 280 | |||
| 281 | flush() { | ||
| 282 | this.queue.forEach((item) => { | ||
| 283 | this.send({ | ||
| 284 | ...item, | ||
| 285 | // @ts-expect-error | ||
| 286 | payload: { | ||
| 287 | ...item.payload, | ||
| 288 | profileId: item.payload.profileId ?? this.profileId | ||
| 289 | } | ||
| 290 | }) | ||
| 291 | }) | ||
| 292 | this.queue = [] | ||
| 293 | } | ||
| 294 | } | ||
docs/.vitepress/theme/internal/browser.ts deleted −187
| @@ -1,187 +0,0 @@ | |||
| 1 | /** | ||
| 2 | * All Rights Reserved | ||
| 3 | * | ||
| 4 | * Copyright (c) 2025 taskylizard | ||
| 5 | * | ||
| 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 | */ | ||
| 8 | import type { | ||
| 9 | InternalOptions as InternalBaseOptions, | ||
| 10 | TrackProperties | ||
| 11 | } from './api' | ||
| 12 | import { InternalAPI as InternalBase } from './api' | ||
| 13 | |||
| 14 | export type InternalOptions = InternalBaseOptions & { | ||
| 15 | trackOutgoingLinks?: boolean | ||
| 16 | trackScreenViews?: boolean | ||
| 17 | trackAttributes?: boolean | ||
| 18 | trackHashChanges?: boolean | ||
| 19 | } | ||
| 20 | |||
| 21 | function toCamelCase(str: string) { | ||
| 22 | return str.replace( | ||
| 23 | /([-_][a-z])/gi, | ||
| 24 | ($1) => $1.toUpperCase().replace('-', '').replace('_', '') | ||
| 25 | ) | ||
| 26 | } | ||
| 27 | |||
| 28 | export class Internal extends InternalBase { | ||
| 29 | private lastPath = '' | ||
| 30 | private debounceTimer: any | ||
| 31 | |||
| 32 | constructor(public options: InternalOptions) { | ||
| 33 | super({ | ||
| 34 | sdk: 'web', | ||
| 35 | sdkVersion: process.env.WEB_VERSION!, | ||
| 36 | ...options | ||
| 37 | }) | ||
| 38 | |||
| 39 | if (!this.isServer()) { | ||
| 40 | this.setGlobalProperties({ | ||
| 41 | __referrer: document.referrer | ||
| 42 | }) | ||
| 43 | |||
| 44 | if (this.options.trackScreenViews) { | ||
| 45 | this.trackScreenViews() | ||
| 46 | setTimeout(() => this.screenView(), 0) | ||
| 47 | } | ||
| 48 | |||
| 49 | if (this.options.trackOutgoingLinks) { | ||
| 50 | this.trackOutgoingLinks() | ||
| 51 | } | ||
| 52 | |||
| 53 | if (this.options.trackAttributes) { | ||
| 54 | this.trackAttributes() | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | private debounce(func: () => void, delay: number) { | ||
| 60 | clearTimeout(this.debounceTimer) | ||
| 61 | this.debounceTimer = setTimeout(func, delay) | ||
| 62 | } | ||
| 63 | |||
| 64 | private isServer() { | ||
| 65 | return typeof document === 'undefined' | ||
| 66 | } | ||
| 67 | |||
| 68 | public trackOutgoingLinks() { | ||
| 69 | if (this.isServer()) { | ||
| 70 | return | ||
| 71 | } | ||
| 72 | |||
| 73 | document.addEventListener('click', (event) => { | ||
| 74 | const target = event.target as HTMLElement | ||
| 75 | const link = target.closest('a') | ||
| 76 | if (link && target) { | ||
| 77 | const href = link.getAttribute('href') | ||
| 78 | if (href?.startsWith('http')) { | ||
| 79 | super.track('link_out', { | ||
| 80 | href, | ||
| 81 | text: link.innerText || | ||
| 82 | link.getAttribute('title') || | ||
| 83 | target.getAttribute('alt') || | ||
| 84 | target.getAttribute('title') | ||
| 85 | }) | ||
| 86 | } | ||
| 87 | } | ||
| 88 | }) | ||
| 89 | } | ||
| 90 | |||
| 91 | public trackScreenViews() { | ||
| 92 | if (this.isServer()) { | ||
| 93 | return | ||
| 94 | } | ||
| 95 | |||
| 96 | const oldPushState = history.pushState | ||
| 97 | history.pushState = function pushState(...args) { | ||
| 98 | const ret = oldPushState.apply(this, args) | ||
| 99 | window.dispatchEvent(new Event('pushstate')) | ||
| 100 | window.dispatchEvent(new Event('locationchange')) | ||
| 101 | return ret | ||
| 102 | } | ||
| 103 | |||
| 104 | const oldReplaceState = history.replaceState | ||
| 105 | history.replaceState = function replaceState(...args) { | ||
| 106 | const ret = oldReplaceState.apply(this, args) | ||
| 107 | window.dispatchEvent(new Event('replacestate')) | ||
| 108 | window.dispatchEvent(new Event('locationchange')) | ||
| 109 | return ret | ||
| 110 | } | ||
| 111 | |||
| 112 | window.addEventListener('popstate', () => { | ||
| 113 | window.dispatchEvent(new Event('locationchange')) | ||
| 114 | }) | ||
| 115 | |||
| 116 | const eventHandler = () => this.debounce(() => this.screenView(), 50) | ||
| 117 | |||
| 118 | if (this.options.trackHashChanges) { | ||
| 119 | window.addEventListener('hashchange', eventHandler) | ||
| 120 | } else { | ||
| 121 | window.addEventListener('locationchange', eventHandler) | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | public trackAttributes() { | ||
| 126 | if (this.isServer()) { | ||
| 127 | return | ||
| 128 | } | ||
| 129 | |||
| 130 | document.addEventListener('click', (event) => { | ||
| 131 | const target = event.target as HTMLElement | ||
| 132 | const btn = target.closest('button') | ||
| 133 | const anchor = target.closest('a') | ||
| 134 | const element = btn?.getAttribute('data-track') | ||
| 135 | ? btn | ||
| 136 | : anchor?.getAttribute('data-track') | ||
| 137 | ? anchor | ||
| 138 | : null | ||
| 139 | if (element) { | ||
| 140 | const properties: Record<string, unknown> = {} | ||
| 141 | for (const attr of Array.from(element.attributes)) { | ||
| 142 | if (attr.name.startsWith('data-') && attr.name !== 'data-track') { | ||
| 143 | properties[toCamelCase(attr.name.replace(/^data-/, ''))] = | ||
| 144 | attr.value | ||
| 145 | } | ||
| 146 | } | ||
| 147 | const name = element.getAttribute('data-track') | ||
| 148 | if (name) { | ||
| 149 | super.track(name, properties) | ||
| 150 | } | ||
| 151 | } | ||
| 152 | }) | ||
| 153 | } | ||
| 154 | |||
| 155 | screenView(properties?: TrackProperties): void | ||
| 156 | screenView(path: string, properties?: TrackProperties): void | ||
| 157 | screenView( | ||
| 158 | pathOrProperties?: string | TrackProperties, | ||
| 159 | propertiesOrUndefined?: TrackProperties | ||
| 160 | ): void { | ||
| 161 | if (this.isServer()) { | ||
| 162 | return | ||
| 163 | } | ||
| 164 | |||
| 165 | let path: string | ||
| 166 | let properties: TrackProperties | undefined | ||
| 167 | |||
| 168 | if (typeof pathOrProperties === 'string') { | ||
| 169 | path = pathOrProperties | ||
| 170 | properties = propertiesOrUndefined | ||
| 171 | } else { | ||
| 172 | path = window.location.href | ||
| 173 | properties = pathOrProperties | ||
| 174 | } | ||
| 175 | |||
| 176 | if (this.lastPath === path) { | ||
| 177 | return | ||
| 178 | } | ||
| 179 | |||
| 180 | this.lastPath = path | ||
| 181 | super.track('screen_view', { | ||
| 182 | ...(properties ?? {}), | ||
| 183 | __path: path, | ||
| 184 | __title: document.title | ||
| 185 | }) | ||
| 186 | } | ||
| 187 | } | ||
docs/.vitepress/theme/math.ts deleted −58
| @@ -1,58 +0,0 @@ | |||
| 1 | /** | ||
| 2 | * All Rights Reserved | ||
| 3 | * | ||
| 4 | * Copyright (c) 2025 taskylizard | ||
| 5 | * | ||
| 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 | */ | ||
| 8 | // Thanks to @yellowsink for the original code!! <3 | ||
| 9 | // https://github.com/uwu/uwu.network/blob/master/src/components/sink/Takodachi.astro | ||
| 10 | |||
| 11 | export type Vec2D = [number, number] | ||
| 12 | |||
| 13 | // Mathmaticians hate him!!! | ||
| 14 | /** Lenient square root */ | ||
| 15 | export const lSqrt = (n: number) => Math.sqrt(Math.abs(n)) | ||
| 16 | |||
| 17 | export const v2mag = (vec: Vec2D) => | ||
| 18 | Math.sqrt(vec[0] * vec[0] + vec[1] * vec[1]) | ||
| 19 | |||
| 20 | export const v2add = (v1: Vec2D, v2: Vec2D): Vec2D => [ | ||
| 21 | v1[0] + v2[0], | ||
| 22 | v1[1] + v2[1] | ||
| 23 | ] | ||
| 24 | |||
| 25 | export const v2sub = (v1: Vec2D, v2: Vec2D): Vec2D => [ | ||
| 26 | v1[0] - v2[0], | ||
| 27 | v1[1] - v2[1] | ||
| 28 | ] | ||
| 29 | |||
| 30 | /** Multiplies a 2D vector by a scalar */ | ||
| 31 | export const v2smul = (vec: Vec2D, scalar: number): Vec2D => [ | ||
| 32 | vec[0] * scalar, | ||
| 33 | vec[1] * scalar | ||
| 34 | ] | ||
| 35 | |||
| 36 | export function v2norm(vec: Vec2D): Vec2D { | ||
| 37 | const l = v2mag(vec) | ||
| 38 | if (l === 0) return [Math.sqrt(2), Math.sqrt(2)] | ||
| 39 | |||
| 40 | return [vec[0] / l, vec[1] / l] | ||
| 41 | } | ||
| 42 | |||
| 43 | export const rad2deg = (n: number) => (n * 180) / Math.PI | ||
| 44 | |||
| 45 | /** Calculates the gradient of a vector */ | ||
| 46 | export const v2grad = (vec: Vec2D) => vec[1] / vec[0] | ||
| 47 | |||
| 48 | /** Calculates the angle of the vector against [1, 0] in radians */ | ||
| 49 | export const v2rad = (vec: Vec2D) => Math.atan(v2grad(vec)) | ||
| 50 | |||
| 51 | /** Calculates the angle of the vector against [1, 0] in degrees */ | ||
| 52 | export const v2deg = (vec: Vec2D) => rad2deg(v2rad(vec)) | ||
| 53 | |||
| 54 | /** Angle in degrees between two vec2ds in radians */ | ||
| 55 | export const v2radBtw = (v1: Vec2D, v2: Vec2D) => v2rad(v1) - v2rad(v2) | ||
| 56 | |||
| 57 | /** Angle in degrees between two vec2ds in degrees */ | ||
| 58 | export const v2degBtw = (v1: Vec2D, v2: Vec2D) => rad2deg(v2radBtw(v1, v2)) | ||
docs/.vitepress/theme/pets.ts deleted −92
| @@ -1,92 +0,0 @@ | |||
| 1 | import { | ||
| 2 | PetCharacterStorageKey, | ||
| 3 | PetStorageKey, | ||
| 4 | TakodachiStorageKey | ||
| 5 | } from './constants' | ||
| 6 | |||
| 7 | export interface PetIconImage { | ||
| 8 | type: 'image' | ||
| 9 | src: string | ||
| 10 | } | ||
| 11 | |||
| 12 | export interface PetIconSprite { | ||
| 13 | type: 'sprite' | ||
| 14 | src: string | ||
| 15 | /** Grid cell to show, in [-col, -row] units matching oneko's sprite map. */ | ||
| 16 | cell: [number, number] | ||
| 17 | sheet: [number, number] | ||
| 18 | cellSize: number | ||
| 19 | /** Cells to cycle through for an animated preview. */ | ||
| 20 | frames?: [number, number][] | ||
| 21 | } | ||
| 22 | |||
| 23 | export type PetIcon = PetIconImage | PetIconSprite | ||
| 24 | |||
| 25 | export interface PetCharacter { | ||
| 26 | key: string | ||
| 27 | label: string | ||
| 28 | behavior: 'chaser' | 'oneko' | ||
| 29 | icon: PetIcon | ||
| 30 | /** For `chaser` behavior: image that follows the cursor. */ | ||
| 31 | src?: string | ||
| 32 | } | ||
| 33 | |||
| 34 | export const petCharacters: PetCharacter[] = [ | ||
| 35 | { | ||
| 36 | key: 'oneko', | ||
| 37 | label: 'Oneko', | ||
| 38 | behavior: 'oneko', | ||
| 39 | icon: { | ||
| 40 | type: 'sprite', | ||
| 41 | src: '/oneko.gif', | ||
| 42 | cell: [-2, 0], | ||
| 43 | sheet: [256, 128], | ||
| 44 | cellSize: 32, | ||
| 45 | frames: [ | ||
| 46 | [-2, 0], | ||
| 47 | [-2, -1] | ||
| 48 | ] | ||
| 49 | } | ||
| 50 | }, | ||
| 51 | { | ||
| 52 | key: 'tako', | ||
| 53 | label: 'Takodachi', | ||
| 54 | behavior: 'chaser', | ||
| 55 | icon: { type: 'image', src: '/takodachi.webp' }, | ||
| 56 | src: '/takodachi.webp' | ||
| 57 | } | ||
| 58 | ] | ||
| 59 | |||
| 60 | export const defaultPetKey = 'tako' | ||
| 61 | |||
| 62 | /** Style for a sprite frame scaled to a `size` px box; pass an incrementing | ||
| 63 | * `frameIndex` to cycle an icon's `frames`. */ | ||
| 64 | export function spriteIconStyle( | ||
| 65 | icon: PetIconSprite, | ||
| 66 | size: number, | ||
| 67 | frameIndex = 0 | ||
| 68 | ) { | ||
| 69 | const scale = size / icon.cellSize | ||
| 70 | const frames = icon.frames?.length ? icon.frames : [icon.cell] | ||
| 71 | const cell = frames[frameIndex % frames.length] | ||
| 72 | return { | ||
| 73 | width: `${size}px`, | ||
| 74 | height: `${size}px`, | ||
| 75 | backgroundImage: `url(${icon.src})`, | ||
| 76 | backgroundPosition: `${cell[0] * icon.cellSize * scale}px ${cell[1] * icon.cellSize * scale}px`, | ||
| 77 | backgroundSize: `${icon.sheet[0] * scale}px ${icon.sheet[1] * scale}px`, | ||
| 78 | imageRendering: 'pixelated' as const | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | // Migrate the old single "Takodachi" toggle to the enabled + character pair. | ||
| 83 | if (typeof window !== 'undefined') { | ||
| 84 | try { | ||
| 85 | const legacy = window.localStorage.getItem(TakodachiStorageKey) | ||
| 86 | if (legacy !== null && window.localStorage.getItem(PetStorageKey) === null) { | ||
| 87 | window.localStorage.setItem(PetStorageKey, legacy) | ||
| 88 | window.localStorage.setItem(PetCharacterStorageKey, defaultPetKey) | ||
| 89 | window.localStorage.removeItem(TakodachiStorageKey) | ||
| 90 | } | ||
| 91 | } catch {} | ||
| 92 | } | ||
docs/.vitepress/theme/types.ts deleted −132
| @@ -1,132 +0,0 @@ | |||
| 1 | import type { LayoutMode, SpotlightStyle } from './constants' | ||
| 2 | |||
| 3 | /** | ||
| 4 | * Options | ||
| 5 | */ | ||
| 6 | export interface Options { | ||
| 7 | /** | ||
| 8 | * Internationalization configuration | ||
| 9 | * | ||
| 10 | * When configuring, please configure according to the language code configured in | ||
| 11 | * VitePress internationalization configuration. In the following configuration, 'en' | ||
| 12 | * and 'zh-CN' are the language codes configured in VitePress internationalization | ||
| 13 | * configuration. | ||
| 14 | * | ||
| 15 | * @default undefined | ||
| 16 | * @example | ||
| 17 | * ```ts | ||
| 18 | * { | ||
| 19 | * locales: { | ||
| 20 | * 'en': { | ||
| 21 | * title: { | ||
| 22 | * title: 'Reading Mode', | ||
| 23 | * titleAriaLabel: 'Reading Mode', | ||
| 24 | * }, | ||
| 25 | * 'zh-CN': { | ||
| 26 | * title: { | ||
| 27 | * title: '阅读模式', | ||
| 28 | * titleAriaLabel: '阅读模式', | ||
| 29 | * }, | ||
| 30 | * } | ||
| 31 | * } | ||
| 32 | * ``` | ||
| 33 | */ | ||
| 34 | /** | ||
| 35 | * Layout switch configuration | ||
| 36 | */ | ||
| 37 | layoutSwitch?: { | ||
| 38 | /** | ||
| 39 | * Disable layout switch help tooltip | ||
| 40 | * | ||
| 41 | * @default false | ||
| 42 | */ | ||
| 43 | disableHelp?: boolean | ||
| 44 | /** | ||
| 45 | * Default mode for layout switch | ||
| 46 | * | ||
| 47 | * @default LayoutMode.Original (3) | ||
| 48 | */ | ||
| 49 | defaultMode?: LayoutMode | ||
| 50 | /** | ||
| 51 | * Disable Layout Switch animation | ||
| 52 | */ | ||
| 53 | disableAnimation?: boolean | ||
| 54 | /** | ||
| 55 | * Content layout max width slider configuration | ||
| 56 | */ | ||
| 57 | contentLayoutMaxWidth?: { | ||
| 58 | /** | ||
| 59 | * Disable content layout max width help tooltip | ||
| 60 | * | ||
| 61 | * @default false | ||
| 62 | */ | ||
| 63 | disableHelp?: boolean | ||
| 64 | /** | ||
| 65 | * Default percentage of content layout max width | ||
| 66 | * | ||
| 67 | * @default 80 (80%) | ||
| 68 | */ | ||
| 69 | defaultMaxWidth?: number | ||
| 70 | /** | ||
| 71 | * Disable Layout Max Width animation | ||
| 72 | */ | ||
| 73 | disableAnimation?: boolean | ||
| 74 | } | ||
| 75 | /** | ||
| 76 | * Page layout max width slider configuration | ||
| 77 | */ | ||
| 78 | pageLayoutMaxWidth?: { | ||
| 79 | /** | ||
| 80 | * Disable page layout max width help tooltip | ||
| 81 | * | ||
| 82 | * @default false | ||
| 83 | */ | ||
| 84 | disableHelp?: boolean | ||
| 85 | /** | ||
| 86 | * Default percentage of page layout max width | ||
| 87 | * | ||
| 88 | * @default 100 (100%) | ||
| 89 | */ | ||
| 90 | defaultMaxWidth?: number | ||
| 91 | /** | ||
| 92 | * Disable Layout Max Width animation | ||
| 93 | */ | ||
| 94 | disableAnimation?: boolean | ||
| 95 | } | ||
| 96 | } | ||
| 97 | /** | ||
| 98 | * Spotlight configuration | ||
| 99 | */ | ||
| 100 | spotlight?: { | ||
| 101 | /** | ||
| 102 | * Disable spotlight | ||
| 103 | * | ||
| 104 | * @default false | ||
| 105 | */ | ||
| 106 | disabled?: boolean | ||
| 107 | /** | ||
| 108 | * Disable spotlight help tooltip | ||
| 109 | * | ||
| 110 | * @default false | ||
| 111 | */ | ||
| 112 | disableHelp?: boolean | ||
| 113 | /** | ||
| 114 | * Spotlight hover block color | ||
| 115 | * | ||
| 116 | * @default 'rgb(240 197 52 / 10%)' | ||
| 117 | */ | ||
| 118 | hoverBlockColor?: string | ||
| 119 | /** | ||
| 120 | * Default toggle for spotlight | ||
| 121 | * | ||
| 122 | * @default false | ||
| 123 | */ | ||
| 124 | defaultToggle?: boolean | ||
| 125 | /** | ||
| 126 | * Default style for spotlight | ||
| 127 | * | ||
| 128 | * @default SpotlightStyle.Aside (2) | ||
| 129 | */ | ||
| 130 | defaultStyle?: SpotlightStyle | ||
| 131 | } | ||
| 132 | } | ||
docs/public/oneko.gif deleted
Binary file not shown.
docs/public/takodachi.webp deleted
Binary file not shown.