Commit 6609ecd4f2
Unsigned
Layout: unified · split
docs/.vitepress/theme/Layout.vue +2 −2
| @@ -33,7 +33,7 @@ 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 TakodachiChaser from './components/TakodachiChaser.vue' | 36 | import PetChaser from './components/PetChaser.vue' |
| 37 | import { AccentBgStorageKey, AccentBgStrengthStorageKey, AccentColorStorageKey } from './constants' | 37 | import { AccentBgStorageKey, AccentBgStrengthStorageKey, AccentColorStorageKey } from './constants' |
| 38 | import { useEffects } from './composables/useEffects' | 38 | import { useEffects } from './composables/useEffects' |
| 39 | 39 | ||
| @@ -1305,7 +1305,7 @@ onUnmounted(() => { | |||
| 1305 | <template> | 1305 | <template> |
| 1306 | <Layout> | 1306 | <Layout> |
| 1307 | <template #layout-top> | 1307 | <template #layout-top> |
| 1308 | <TakodachiChaser /> | 1308 | <PetChaser /> |
| 1309 | <!-- Home sidebar menu --> | 1309 | <!-- Home sidebar menu --> |
| 1310 | <template v-if="isHome"> | 1310 | <template v-if="isHome"> |
| 1311 | <Transition name="home-fade"> | 1311 | <Transition name="home-fade"> |
docs/.vitepress/theme/components/TakodachiChaser.vue → docs/.vitepress/theme/components/FollowChaser.vue renamed +13 −11
| @@ -1,14 +1,18 @@ | |||
| 1 | <script setup lang="ts"> | 1 | <script setup lang="ts"> |
| 2 | import { useStorage } from '@vueuse/core' | ||
| 3 | import { onMounted, onUnmounted, ref, watch } from 'vue' | 2 | import { onMounted, onUnmounted, ref, watch } from 'vue' |
| 4 | 3 | ||
| 5 | import { TakodachiStorageKey } from '../constants' | ||
| 6 | import { v2add, v2mag, v2norm, v2smul, v2sub, type Vec2D } from '../math' | 4 | import { v2add, v2mag, v2norm, v2smul, v2sub, type Vec2D } from '../math' |
| 7 | 5 | ||
| 6 | const props = defineProps<{ | ||
| 7 | active: boolean | ||
| 8 | src: string | ||
| 9 | alt?: string | ||
| 10 | }>() | ||
| 11 | |||
| 8 | const speed = 2 | 12 | const speed = 2 |
| 9 | const snapThreshold = 5 // px | 13 | const snapThreshold = 5 // px |
| 10 | 14 | ||
| 11 | const takodachiRef = ref<HTMLImageElement | null>(null) | 15 | const chaserRef = ref<HTMLImageElement | null>(null) |
| 12 | let mousePos: Vec2D | null = null | 16 | let mousePos: Vec2D | null = null |
| 13 | let target: Vec2D | null = null | 17 | let target: Vec2D | null = null |
| 14 | let offset: Vec2D = [0, 0] | 18 | let offset: Vec2D = [0, 0] |
| @@ -23,18 +27,17 @@ const updateMousePos = (e: MouseEvent | TouchEvent) => { | |||
| 23 | } | 27 | } |
| 24 | } | 28 | } |
| 25 | 29 | ||
| 26 | const takodachiToggledOn = useStorage(TakodachiStorageKey, false) | ||
| 27 | let disable: (() => void) | null = null | 30 | let disable: (() => void) | null = null |
| 28 | 31 | ||
| 29 | const reload = () => { | 32 | const reload = () => { |
| 30 | disable?.() | 33 | disable?.() |
| 31 | 34 | ||
| 32 | if (!takodachiToggledOn.value) return | 35 | if (!props.active) return |
| 33 | 36 | ||
| 34 | window.addEventListener('mousemove', updateMousePos) | 37 | window.addEventListener('mousemove', updateMousePos) |
| 35 | window.addEventListener('touchstart', updateMousePos) | 38 | window.addEventListener('touchstart', updateMousePos) |
| 36 | 39 | ||
| 37 | const chaser = takodachiRef.value | 40 | const chaser = chaserRef.value |
| 38 | if (chaser) { | 41 | if (chaser) { |
| 39 | offset = v2smul([chaser.clientWidth, chaser.clientHeight], 0.5) | 42 | offset = v2smul([chaser.clientWidth, chaser.clientHeight], 0.5) |
| 40 | setTimeout(() => { | 43 | setTimeout(() => { |
| @@ -74,7 +77,7 @@ const reload = () => { | |||
| 74 | } | 77 | } |
| 75 | } | 78 | } |
| 76 | 79 | ||
| 77 | watch(takodachiToggledOn, reload) | 80 | watch(() => props.active, reload) |
| 78 | 81 | ||
| 79 | onMounted(reload) | 82 | onMounted(reload) |
| 80 | onUnmounted(() => disable?.()) | 83 | onUnmounted(() => disable?.()) |
| @@ -82,10 +85,9 @@ onUnmounted(() => disable?.()) | |||
| 82 | 85 | ||
| 83 | <template> | 86 | <template> |
| 84 | <img | 87 | <img |
| 85 | id="takodachi" | 88 | ref="chaserRef" |
| 86 | ref="takodachiRef" | 89 | :src="src" |
| 87 | src="/takodachi.webp" | 90 | :alt="alt ?? ''" |
| 88 | alt="Takodachi" | ||
| 89 | class="pointer-events-none fixed absolute z-[9999] h-10 w-10 opacity-0 transition-opacity duration-500" | 91 | class="pointer-events-none fixed absolute z-[9999] h-10 w-10 opacity-0 transition-opacity duration-500" |
| 90 | :style="{ | 92 | :style="{ |
| 91 | left: `${position.x}px`, | 93 | left: `${position.x}px`, |
docs/.vitepress/theme/components/OnekoChaser.vue added +357
| @@ -0,0 +1,357 @@ | |||
| 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 — or drag me around!" | ||
| 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 added +28
| @@ -0,0 +1,28 @@ | |||
| 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/settings/Menu.vue +2 −2
| @@ -11,8 +11,8 @@ import LayoutSwitchContentLayoutWidthInput from './LayoutSwitchContentLayoutMaxW | |||
| 11 | import LayoutSwitchPageLayoutWidthInput from './LayoutSwitchPageLayoutMaxWidthSlider.vue' | 11 | import LayoutSwitchPageLayoutWidthInput from './LayoutSwitchPageLayoutMaxWidthSlider.vue' |
| 12 | import Spotlight from './Spotlight.vue' | 12 | import Spotlight from './Spotlight.vue' |
| 13 | import SpotlightStyles from './SpotlightStyles.vue' | 13 | import SpotlightStyles from './SpotlightStyles.vue' |
| 14 | import Pet from './Pet.vue' | ||
| 14 | import SettingsFlyout from './SettingsFlyout.vue' | 15 | import SettingsFlyout from './SettingsFlyout.vue' |
| 15 | import Takodachi from './Takodachi.vue' | ||
| 16 | 16 | ||
| 17 | const options = inject(InjectionKey, {}) | 17 | const options = inject(InjectionKey, {}) |
| 18 | const mounted = useMounted() | 18 | const mounted = useMounted() |
| @@ -35,7 +35,7 @@ const mounted = useMounted() | |||
| 35 | <Effects /> | 35 | <Effects /> |
| 36 | <AccentColor /> | 36 | <AccentColor /> |
| 37 | <AccentBackground /> | 37 | <AccentBackground /> |
| 38 | <Takodachi /> | 38 | <Pet /> |
| 39 | </div> | 39 | </div> |
| 40 | </SettingsFlyout> | 40 | </SettingsFlyout> |
| 41 | </template> | 41 | </template> |
docs/.vitepress/theme/components/settings/Pet.vue added +271
| @@ -0,0 +1,271 @@ | |||
| 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/Takodachi.vue deleted −74
| @@ -1,74 +0,0 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { NuInputHighlight, NuInputHorizontalRadioGroup } from '@nolebase/ui' | ||
| 3 | import { useStorage } from '@vueuse/core' | ||
| 4 | import { computed, ref } from 'vue' | ||
| 5 | |||
| 6 | import MenuHelp from './MenuHelp.vue' | ||
| 7 | import MenuTitle from './MenuTitle.vue' | ||
| 8 | |||
| 9 | import { TakodachiStorageKey } from '../../constants' | ||
| 10 | |||
| 11 | const menuTitleElementRef = ref<HTMLDivElement>() | ||
| 12 | const isMenuHelpPoppedUp = ref(false) | ||
| 13 | const disabled = ref(false) | ||
| 14 | |||
| 15 | const takodachToggledOn = useStorage(TakodachiStorageKey, false) | ||
| 16 | |||
| 17 | const fieldOptions = computed(() => [ | ||
| 18 | { | ||
| 19 | value: true, | ||
| 20 | title: 'On', | ||
| 21 | ariaLabel: 'On', | ||
| 22 | text: 'ON', | ||
| 23 | name: 'Takodachi Toggle Switch' | ||
| 24 | }, | ||
| 25 | { | ||
| 26 | value: false, | ||
| 27 | title: 'Off', | ||
| 28 | ariaLabel: 'Off', | ||
| 29 | text: 'OFF', | ||
| 30 | name: 'Takodachi Toggle Switch' | ||
| 31 | } | ||
| 32 | ]) | ||
| 33 | </script> | ||
| 34 | |||
| 35 | <template> | ||
| 36 | <div space-y-2 role="radiogroup"> | ||
| 37 | <div ref="menuTitleElementRef" relative flex items-center> | ||
| 38 | <MenuTitle | ||
| 39 | title="Takodachi" | ||
| 40 | aria-label="Takodachi" | ||
| 41 | :disabled="disabled" | ||
| 42 | flex="1" | ||
| 43 | pr-4 | ||
| 44 | > | ||
| 45 | <template #icon> | ||
| 46 | <img | ||
| 47 | src="/takodachi.webp" | ||
| 48 | alt="Takodachi" | ||
| 49 | class="w-6 h-6 mr-1" | ||
| 50 | aria-hidden="true" | ||
| 51 | /> | ||
| 52 | </template> | ||
| 53 | </MenuTitle> | ||
| 54 | <MenuHelp | ||
| 55 | v-model:is-popped-up="isMenuHelpPoppedUp" | ||
| 56 | :menu-title-element-ref="menuTitleElementRef" | ||
| 57 | > | ||
| 58 | <h4 text-md mb-1 font-semibold>Takodachi</h4> | ||
| 59 | <p text="sm" mb-2 max-w-100> | ||
| 60 | <span>Gives you a cool takodachi following your cursor.</span> | ||
| 61 | </p> | ||
| 62 | </MenuHelp> | ||
| 63 | </div> | ||
| 64 | <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md"> | ||
| 65 | <NuInputHorizontalRadioGroup | ||
| 66 | v-model="takodachToggledOn" | ||
| 67 | bg="$vp-nolebase-enhanced-readabilities-menu-background-color" | ||
| 68 | text="sm $vp-nolebase-enhanced-readabilities-menu-text-color" | ||
| 69 | :options="fieldOptions" | ||
| 70 | :disabled="disabled" | ||
| 71 | /> | ||
| 72 | </NuInputHighlight> | ||
| 73 | </div> | ||
| 74 | </template> | ||
docs/.vitepress/theme/constants.ts +5
| @@ -27,7 +27,12 @@ export const SpotlightStylesStorageKey = | |||
| 27 | 'vitepress-nolebase-enhanced-readabilities-spotlight-styles' | 27 | 'vitepress-nolebase-enhanced-readabilities-spotlight-styles' |
| 28 | 28 | ||
| 29 | export const EffectsStorageKey = 'preference-effects' | 29 | export const EffectsStorageKey = 'preference-effects' |
| 30 | /** Legacy on/off key for the cursor companion; migrated to {@link PetStorageKey}. */ | ||
| 30 | export const TakodachiStorageKey = 'preference-takodachi' | 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' | ||
| 31 | export const AccentColorStorageKey = 'preference-accent-color' | 36 | export const AccentColorStorageKey = 'preference-accent-color' |
| 32 | export const AccentBgStorageKey = 'preference-accent-bg' | 37 | export const AccentBgStorageKey = 'preference-accent-bg' |
| 33 | /** Accent background tint strength, 0–100. */ | 38 | /** Accent background tint strength, 0–100. */ |
docs/.vitepress/theme/pets.ts added +92
| @@ -0,0 +1,92 @@ | |||
| 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: 'tako', | ||
| 37 | label: 'Takodachi', | ||
| 38 | behavior: 'chaser', | ||
| 39 | icon: { type: 'image', src: '/takodachi.webp' }, | ||
| 40 | src: '/takodachi.webp' | ||
| 41 | }, | ||
| 42 | { | ||
| 43 | key: 'oneko', | ||
| 44 | label: 'Oneko', | ||
| 45 | behavior: 'oneko', | ||
| 46 | icon: { | ||
| 47 | type: 'sprite', | ||
| 48 | src: '/oneko.gif', | ||
| 49 | cell: [-2, 0], | ||
| 50 | sheet: [256, 128], | ||
| 51 | cellSize: 32, | ||
| 52 | frames: [ | ||
| 53 | [-2, 0], | ||
| 54 | [-2, -1] | ||
| 55 | ] | ||
| 56 | } | ||
| 57 | } | ||
| 58 | ] | ||
| 59 | |||
| 60 | export const defaultPetKey = petCharacters[0].key | ||
| 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/public/oneko.gif added
Binary file not shown.