Commit 6609ecd4f2

6609ecd4f210052b12152a6af529eb40a2ac65cd

parent: f502b97e61

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-07-09 08:48 UTC

pet

Layout: unified · split

docs/.vitepress/theme/Layout.vue +2 −2
@@ -33,7 +33,7 @@ import NotFoundComponent from './components/NotFound.vue'
3333import { NolebaseEnhancedReadabilitiesScreenMenu } from './components/settings'
3434import NavActions from './components/NavActions.vue'
3535import SidebarCard from './components/SidebarCard.vue'
36import TakodachiChaser from './components/TakodachiChaser.vue'
36import PetChaser from './components/PetChaser.vue'
3737import { AccentBgStorageKey, AccentBgStrengthStorageKey, AccentColorStorageKey } from './constants'
3838import { useEffects } from './composables/useEffects'
3939
@@ -1305,7 +1305,7 @@ onUnmounted(() => {
13051305<template>
13061306 <Layout>
13071307 <template #layout-top>
1308 <TakodachiChaser />
1308 <PetChaser />
13091309 <!-- Home sidebar menu -->
13101310 <template v-if="isHome">
13111311 <Transition name="home-fade">
docs/.vitepress/theme/components/TakodachiChaser.vue → docs/.vitepress/theme/components/FollowChaser.vue renamed +13 −11
@@ -1,14 +1,18 @@
11<script setup lang="ts">
2import { useStorage } from '@vueuse/core'
32import { onMounted, onUnmounted, ref, watch } from 'vue'
43
5import { TakodachiStorageKey } from '../constants'
64import { v2add, v2mag, v2norm, v2smul, v2sub, type Vec2D } from '../math'
75
6const props = defineProps<{
7 active: boolean
8 src: string
9 alt?: string
10}>()
11
812const speed = 2
913const snapThreshold = 5 // px
1014
11const takodachiRef = ref<HTMLImageElement | null>(null)
15const chaserRef = ref<HTMLImageElement | null>(null)
1216let mousePos: Vec2D | null = null
1317let target: Vec2D | null = null
1418let offset: Vec2D = [0, 0]
@@ -23,18 +27,17 @@ const updateMousePos = (e: MouseEvent | TouchEvent) => {
2327 }
2428}
2529
26const takodachiToggledOn = useStorage(TakodachiStorageKey, false)
2730let disable: (() => void) | null = null
2831
2932const reload = () => {
3033 disable?.()
3134
32 if (!takodachiToggledOn.value) return
35 if (!props.active) return
3336
3437 window.addEventListener('mousemove', updateMousePos)
3538 window.addEventListener('touchstart', updateMousePos)
3639
37 const chaser = takodachiRef.value
40 const chaser = chaserRef.value
3841 if (chaser) {
3942 offset = v2smul([chaser.clientWidth, chaser.clientHeight], 0.5)
4043 setTimeout(() => {
@@ -74,7 +77,7 @@ const reload = () => {
7477 }
7578}
7679
77watch(takodachiToggledOn, reload)
80watch(() => props.active, reload)
7881
7982onMounted(reload)
8083onUnmounted(() => disable?.())
@@ -82,10 +85,9 @@ onUnmounted(() => disable?.())
8285
8386<template>
8487 <img
85 id="takodachi"
86 ref="takodachiRef"
87 src="/takodachi.webp"
88 alt="Takodachi"
88 ref="chaserRef"
89 :src="src"
90 :alt="alt ?? ''"
8991 class="pointer-events-none fixed absolute z-[9999] h-10 w-10 opacity-0 transition-opacity duration-500"
9092 :style="{
9193 left: `${position.x}px`,
docs/.vitepress/theme/components/OnekoChaser.vue added +357
@@ -0,0 +1,357 @@
1<script setup lang="ts">
2import { onMounted, onUnmounted, ref, watch } from 'vue'
3
4// Adapted from oneko.js by adryd — https://github.com/adryd325/oneko.js
5
6const props = defineProps<{ active: boolean }>()
7
8const anchorSelectors = ['.wotaku-hero-logo', '.VPNavBarTitle']
9const dragThreshold = 4
10
11const nekoRef = ref<HTMLDivElement | null>(null)
12
13const nekoSpeed = 10
14const 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
77let mode: 'sleep' | 'awake' = 'sleep'
78
79let nekoPosX = 32
80let nekoPosY = 32
81let mousePosX = 0
82let mousePosY = 0
83let frameCount = 0
84let idleTime = 0
85let idleAnimation: string | null = null
86let idleAnimationFrame = 0
87let sleepFrame = 0
88let lastFrameTimestamp: number | undefined
89let rafId: number | null = null
90
91let pointerDown = false
92let didDrag = false
93let pointerStartX = 0
94let pointerStartY = 0
95let grabOffsetX = 0
96let grabOffsetY = 0
97
98const clamp = (v: number, min: number, max: number) =>
99 Math.min(Math.max(min, v), max)
100
101const updateMousePos = (e: MouseEvent) => {
102 mousePosX = e.clientX
103 mousePosY = e.clientY
104}
105
106function 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
114function 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
121function 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
141function resetIdleAnimation() {
142 idleAnimation = null
143 idleAnimationFrame = 0
144}
145
146function 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
178function sleep() {
179 sleepFrame += 1
180 if (sleepFrame < 8) {
181 setSprite('tired', 0)
182 return
183 }
184 setSprite('sleeping', Math.floor(sleepFrame / 4))
185}
186
187function 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
223function 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
235function 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
245function wake() {
246 mode = 'awake'
247 idleTime = 0
248 resetIdleAnimation()
249}
250
251function goToSleep() {
252 mode = 'sleep'
253 sleepFrame = 0
254}
255
256const 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
267const 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
283const 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
295let disable: (() => void) | null = null
296
297const 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
331watch(() => props.active, reload)
332
333onMounted(reload)
334onUnmounted(() => 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">
2import { useStorage } from '@vueuse/core'
3
4import { PetCharacterStorageKey, PetStorageKey } from '../constants'
5import { defaultPetKey, petCharacters } from '../pets'
6import FollowChaser from './FollowChaser.vue'
7import OnekoChaser from './OnekoChaser.vue'
8
9const petEnabled = useStorage(PetStorageKey, false)
10const petCharacter = useStorage(PetCharacterStorageKey, defaultPetKey)
11
12const chaserCharacters = petCharacters.filter((c) => c.behavior === 'chaser')
13
14function 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
1111import LayoutSwitchPageLayoutWidthInput from './LayoutSwitchPageLayoutMaxWidthSlider.vue'
1212import Spotlight from './Spotlight.vue'
1313import SpotlightStyles from './SpotlightStyles.vue'
14import Pet from './Pet.vue'
1415import SettingsFlyout from './SettingsFlyout.vue'
15import Takodachi from './Takodachi.vue'
1616
1717const options = inject(InjectionKey, {})
1818const mounted = useMounted()
@@ -35,7 +35,7 @@ const mounted = useMounted()
3535 <Effects />
3636 <AccentColor />
3737 <AccentBackground />
38 <Takodachi />
38 <Pet />
3939 </div>
4040 </SettingsFlyout>
4141</template>
docs/.vitepress/theme/components/settings/Pet.vue added +271
@@ -0,0 +1,271 @@
1<script setup lang="ts">
2import {
3 NuInputHighlight,
4 NuInputHorizontalRadioGroup,
5 NuVerticalTransition
6} from '@nolebase/ui'
7import { useStorage } from '@vueuse/core'
8import { computed, onMounted, onUnmounted, ref } from 'vue'
9
10import { PetCharacterStorageKey, PetStorageKey } from '../../constants'
11import {
12 defaultPetKey,
13 petCharacters,
14 spriteIconStyle,
15 type PetCharacter
16} from '../../pets'
17import MenuHelp from './MenuHelp.vue'
18import MenuTitle from './MenuTitle.vue'
19
20const menuTitleElementRef = ref<HTMLDivElement>()
21const isMenuHelpPoppedUp = ref(false)
22
23const petEnabled = useStorage(PetStorageKey, false)
24const petCharacter = useStorage(PetCharacterStorageKey, defaultPetKey)
25
26const open = ref(false)
27const rootRef = ref<HTMLDivElement>()
28
29// Drives the animated sprite previews (e.g. Oneko's two-frame sleep).
30const frameTick = ref(0)
31let frameTimer: ReturnType<typeof setInterval> | null = null
32
33const selectedOption = computed(
34 () =>
35 petCharacters.find((o) => o.key === petCharacter.value) ?? petCharacters[0]
36)
37
38function iconStyle(option: PetCharacter) {
39 return option.icon.type === 'sprite'
40 ? spriteIconStyle(option.icon, 24, frameTick.value)
41 : undefined
42}
43
44function select(key: string) {
45 petCharacter.value = key
46 open.value = false
47}
48
49function onDocClick(e: MouseEvent) {
50 if (rootRef.value && !rootRef.value.contains(e.target as Node)) {
51 open.value = false
52 }
53}
54
55const 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
72onMounted(() => {
73 document.addEventListener('click', onDocClick, true)
74 frameTimer = setInterval(() => {
75 frameTick.value += 1
76 }, 400)
77})
78onUnmounted(() => {
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">
2import { NuInputHighlight, NuInputHorizontalRadioGroup } from '@nolebase/ui'
3import { useStorage } from '@vueuse/core'
4import { computed, ref } from 'vue'
5
6import MenuHelp from './MenuHelp.vue'
7import MenuTitle from './MenuTitle.vue'
8
9import { TakodachiStorageKey } from '../../constants'
10
11const menuTitleElementRef = ref<HTMLDivElement>()
12const isMenuHelpPoppedUp = ref(false)
13const disabled = ref(false)
14
15const takodachToggledOn = useStorage(TakodachiStorageKey, false)
16
17const 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 =
2727 'vitepress-nolebase-enhanced-readabilities-spotlight-styles'
2828
2929export const EffectsStorageKey = 'preference-effects'
30/** Legacy on/off key for the cursor companion; migrated to {@link PetStorageKey}. */
3031export const TakodachiStorageKey = 'preference-takodachi'
32/** Whether the cursor pet companion is enabled. */
33export const PetStorageKey = 'preference-pet'
34/** Which pet character follows the cursor (see `pets.ts`). */
35export const PetCharacterStorageKey = 'preference-pet-character'
3136export const AccentColorStorageKey = 'preference-accent-color'
3237export const AccentBgStorageKey = 'preference-accent-bg'
3338/** Accent background tint strength, 0–100. */
docs/.vitepress/theme/pets.ts added +92
@@ -0,0 +1,92 @@
1import {
2 PetCharacterStorageKey,
3 PetStorageKey,
4 TakodachiStorageKey
5} from './constants'
6
7export interface PetIconImage {
8 type: 'image'
9 src: string
10}
11
12export 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
23export type PetIcon = PetIconImage | PetIconSprite
24
25export 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
34export 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
60export 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`. */
64export 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.
83if (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.