oneko 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +97 -2
- package/SKIN-CREDITS.md +61 -0
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.js +11 -0
- package/dist/cat-sounds/Cat_baby_ambient1.ogg +0 -0
- package/dist/cat-sounds/Cat_baby_ambient2.ogg +0 -0
- package/dist/cat-sounds/Cat_baby_ambient3.ogg +0 -0
- package/dist/cat-sounds/Cat_baby_ambient4.ogg +0 -0
- package/dist/cat-sounds/Cat_baby_ambient5.ogg +0 -0
- package/dist/cat-sounds/Cat_baby_ambient6.ogg +0 -0
- package/dist/cat-sounds/Cat_baby_ambient7.ogg +0 -0
- package/dist/cat-sounds/Cat_baby_death.ogg +0 -0
- package/dist/cat-sounds/Cat_baby_hurt1.ogg +0 -0
- package/dist/cat-sounds/Cat_baby_hurt2.ogg +0 -0
- package/dist/cat-sounds/Cat_baby_hurt3.ogg +0 -0
- package/dist/cat-sounds/Cat_beg1.ogg +0 -0
- package/dist/cat-sounds/Cat_beg2.ogg +0 -0
- package/dist/cat-sounds/Cat_beg3.ogg +0 -0
- package/dist/cat-sounds/Cat_eat1.ogg +0 -0
- package/dist/cat-sounds/Cat_eat2.ogg +0 -0
- package/dist/cat-sounds/Cat_hiss1.ogg +0 -0
- package/dist/cat-sounds/Cat_hiss2.ogg +0 -0
- package/dist/cat-sounds/Cat_hiss3.ogg +0 -0
- package/dist/cat-sounds/Cat_hurt1.ogg +0 -0
- package/dist/cat-sounds/Cat_hurt2.ogg +0 -0
- package/dist/cat-sounds/Cat_hurt3.ogg +0 -0
- package/dist/cat-sounds/Cat_idle1.ogg +0 -0
- package/dist/cat-sounds/Cat_idle2.ogg +0 -0
- package/dist/cat-sounds/Cat_idle3.ogg +0 -0
- package/dist/cat-sounds/Cat_idle4.ogg +0 -0
- package/dist/cat-sounds/Cat_purr1.ogg +0 -0
- package/dist/cat-sounds/Cat_purr2.ogg +0 -0
- package/dist/cat-sounds/Cat_purr3.ogg +0 -0
- package/dist/cat-sounds/Cat_purreow1.ogg +0 -0
- package/dist/cat-sounds/Cat_purreow2.ogg +0 -0
- package/dist/cat-sounds/Cat_royal_ambient1.ogg +0 -0
- package/dist/cat-sounds/Cat_royal_ambient2.ogg +0 -0
- package/dist/cat-sounds/Cat_royal_ambient3.ogg +0 -0
- package/dist/cat-sounds/Cat_royal_ambient4.ogg +0 -0
- package/dist/cat-sounds/Cat_royal_ambient5.ogg +1 -0
- package/dist/cat-sounds/Cat_royal_ambient6.ogg +1 -0
- package/dist/cat-sounds/Cat_royal_death.ogg +1 -0
- package/dist/cat-sounds/Cat_royal_hurt1.ogg +1 -0
- package/dist/cat-sounds/Cat_royal_hurt2.ogg +1 -0
- package/dist/cat-sounds/Cat_royal_hurt3.ogg +1 -0
- package/dist/cat-sounds/Stray_cat_idle1.ogg +1 -0
- package/dist/cat-sounds/Stray_cat_idle2.ogg +1 -0
- package/dist/cat-sounds/Stray_cat_idle3.ogg +1 -0
- package/dist/cat-sounds/Stray_cat_idle4.ogg +1 -0
- package/dist/chunks/skin-sheets-CG0yKeZb.js +71 -0
- package/dist/chunks/vanilla-CUrawvWx.js +2993 -0
- package/dist/index.js +286 -0
- package/dist/solid.js +17 -0
- package/dist/svelte/Oneko.svelte +17 -0
- package/dist/svelte/Oneko.svelte.d.ts +4 -0
- package/dist/types/components/laser-cursor.d.ts +3 -0
- package/dist/types/components/oneko.d.ts +11 -0
- package/dist/types/hooks/use-cat-animation.d.ts +23 -0
- package/dist/types/hooks/use-motion-allowed.d.ts +3 -0
- package/dist/types/hooks/use-oneko-props-sync.d.ts +14 -0
- package/dist/types/hooks/use-skin-source.d.ts +3 -0
- package/dist/types/hooks/use-sprite-appearance.d.ts +6 -0
- package/dist/types/lib/oneko/animation/activity.d.ts +5 -0
- package/dist/types/lib/oneko/animation/attention.d.ts +13 -0
- package/dist/types/lib/oneko/animation/bubbles.d.ts +5 -0
- package/dist/types/lib/oneko/animation/debug-render.d.ts +5 -0
- package/dist/types/lib/oneko/animation/deps.d.ts +21 -0
- package/dist/types/lib/oneko/animation/frame/interrupt-idle.d.ts +2 -0
- package/dist/types/lib/oneko/animation/frame/tick-laser.d.ts +2 -0
- package/dist/types/lib/oneko/animation/frame/tick-live-state.d.ts +3 -0
- package/dist/types/lib/oneko/animation/frame/tick-movement.d.ts +2 -0
- package/dist/types/lib/oneko/animation/frame/tick-prelude.d.ts +2 -0
- package/dist/types/lib/oneko/animation/frame/tick-sounds.d.ts +3 -0
- package/dist/types/lib/oneko/animation/frame.d.ts +2 -0
- package/dist/types/lib/oneko/animation/grid.d.ts +3 -0
- package/dist/types/lib/oneko/animation/idle.d.ts +4 -0
- package/dist/types/lib/oneko/animation/mouse.d.ts +2 -0
- package/dist/types/lib/oneko/animation/movement.d.ts +3 -0
- package/dist/types/lib/oneko/animation/sprites.d.ts +5 -0
- package/dist/types/lib/oneko/animation-loop.d.ts +5 -0
- package/dist/types/lib/oneko/constants.d.ts +118 -0
- package/dist/types/lib/oneko/debug-controls/bubble.d.ts +4 -0
- package/dist/types/lib/oneko/debug-controls/force-state.d.ts +4 -0
- package/dist/types/lib/oneko/debug-controls/index.d.ts +14 -0
- package/dist/types/lib/oneko/debug-controls/playback.d.ts +4 -0
- package/dist/types/lib/oneko/debug-controls/position.d.ts +4 -0
- package/dist/types/lib/oneko/debug-controls/speed.d.ts +4 -0
- package/dist/types/lib/oneko/debug-controls/ui.d.ts +5 -0
- package/dist/types/lib/oneko/defaults.d.ts +39 -0
- package/dist/types/lib/oneko/dom.d.ts +10 -0
- package/dist/types/lib/oneko/initial-state.d.ts +9 -0
- package/dist/types/lib/oneko/konami.d.ts +4 -0
- package/dist/types/lib/oneko/laser-cursor-dom.d.ts +1 -0
- package/dist/types/lib/oneko/obstacle-filters.d.ts +12 -0
- package/dist/types/lib/oneko/pack.d.ts +12 -0
- package/dist/types/lib/oneko/pathfinding.d.ts +6 -0
- package/dist/types/lib/oneko/persistence.d.ts +18 -0
- package/dist/types/lib/oneko/runtime-config.d.ts +28 -0
- package/dist/types/lib/oneko/skin-catalog.d.ts +98 -0
- package/dist/types/lib/oneko/skin-classic.json.d.ts +4 -0
- package/dist/types/lib/oneko/skin-sheets.json.d.ts +27 -0
- package/dist/types/lib/oneko/skins.d.ts +14 -0
- package/dist/types/lib/oneko/start-cat-animation.d.ts +24 -0
- package/dist/types/lib/oneko/teardown.d.ts +17 -0
- package/dist/types/lib/oneko/types.d.ts +183 -0
- package/dist/types/lib/oneko/vanilla.d.ts +13 -0
- package/dist/types/lib/oneko/zone-runtime.d.ts +20 -0
- package/dist/types/lib/oneko/zones.d.ts +26 -0
- package/dist/types/packages/oneko/src/adapter.d.ts +3 -0
- package/dist/types/packages/oneko/src/index.d.ts +3 -0
- package/dist/types/packages/oneko/src/solid.d.ts +3 -0
- package/dist/types/packages/oneko/src/vanilla.d.ts +7 -0
- package/dist/types/packages/oneko/src/vue.d.ts +173 -0
- package/dist/vanilla.d.ts +1 -0
- package/dist/vanilla.js +9 -0
- package/dist/vue.js +71 -0
- package/package.json +82 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { m as mountLaserCursor, s as startCatAnimation, g as getSkinSource, l as loadSkinSource, a as applyRuntimeConfig, b as createInitialCatState, O as ONEKO_DEFAULTS, r as readPersistedPosition, o as onCatsHiddenChange, d as areCatsHidden, T as TILE } from "./chunks/vanilla-CUrawvWx.js";
|
|
5
|
+
import { e, c, i, f } from "./chunks/vanilla-CUrawvWx.js";
|
|
6
|
+
function LaserCursor({ zIndex }) {
|
|
7
|
+
useEffect(() => mountLaserCursor(zIndex), [zIndex]);
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
function useCatAnimation({
|
|
11
|
+
enabled,
|
|
12
|
+
stateRef,
|
|
13
|
+
elRef,
|
|
14
|
+
lastStateRef,
|
|
15
|
+
onStateChangeRef,
|
|
16
|
+
liveStateRef,
|
|
17
|
+
persistPosition,
|
|
18
|
+
storageKey,
|
|
19
|
+
zIndex,
|
|
20
|
+
pettable
|
|
21
|
+
}) {
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!enabled || typeof window === "undefined") {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return startCatAnimation({
|
|
27
|
+
stateRef,
|
|
28
|
+
elRef,
|
|
29
|
+
lastStateRef,
|
|
30
|
+
onStateChangeRef,
|
|
31
|
+
liveStateRef,
|
|
32
|
+
persistPosition,
|
|
33
|
+
storageKey,
|
|
34
|
+
zIndex,
|
|
35
|
+
pettable
|
|
36
|
+
});
|
|
37
|
+
}, [
|
|
38
|
+
enabled,
|
|
39
|
+
stateRef,
|
|
40
|
+
elRef,
|
|
41
|
+
lastStateRef,
|
|
42
|
+
onStateChangeRef,
|
|
43
|
+
persistPosition,
|
|
44
|
+
storageKey,
|
|
45
|
+
zIndex,
|
|
46
|
+
pettable,
|
|
47
|
+
liveStateRef
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
function useSpriteAppearance(elRef, source, hueRotate = 0) {
|
|
51
|
+
const previous = useRef(null);
|
|
52
|
+
const transition = useRef(null);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const el = elRef.current;
|
|
55
|
+
if (!el || !source) return;
|
|
56
|
+
const filter = hueRotate ? `hue-rotate(${hueRotate}deg)` : "blur(0px)";
|
|
57
|
+
const last = previous.current;
|
|
58
|
+
if (last?.el === el && last.source === source && last.filter === filter) return;
|
|
59
|
+
transition.current?.cancel();
|
|
60
|
+
transition.current = null;
|
|
61
|
+
el.style.backgroundImage = `url(${JSON.stringify(source)})`;
|
|
62
|
+
el.style.filter = filter;
|
|
63
|
+
previous.current = { el, source, filter };
|
|
64
|
+
if (last?.el === el && last.source !== source && !window.matchMedia("(prefers-reduced-motion: reduce)").matches && typeof el.animate === "function") {
|
|
65
|
+
transition.current = el.animate(
|
|
66
|
+
[{ filter: `${filter} blur(2px)` }, { filter: `${filter} blur(0px)` }],
|
|
67
|
+
{ duration: 220, easing: "ease-out" }
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
useEffect(() => () => transition.current?.cancel(), []);
|
|
72
|
+
}
|
|
73
|
+
function useSkinSource(skin, spriteSrc) {
|
|
74
|
+
const ready = spriteSrc || getSkinSource(skin);
|
|
75
|
+
const [, setLoadedSkin] = useState();
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (ready) return;
|
|
78
|
+
let current = true;
|
|
79
|
+
loadSkinSource(skin).then(
|
|
80
|
+
() => current && setLoadedSkin(skin),
|
|
81
|
+
() => {
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
return () => {
|
|
85
|
+
current = false;
|
|
86
|
+
};
|
|
87
|
+
}, [ready, skin]);
|
|
88
|
+
return ready;
|
|
89
|
+
}
|
|
90
|
+
function useOnekoPropsSync(stateRef, elRef, props) {
|
|
91
|
+
useSpriteAppearance(elRef, useSkinSource(props.skin, props.spriteSrc), props.hueRotate);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
const state = stateRef.current;
|
|
94
|
+
applyRuntimeConfig(state, props);
|
|
95
|
+
const el = elRef.current;
|
|
96
|
+
if (!el) return;
|
|
97
|
+
el.style.transform = `scale(${props.scale}) rotate(${state.currentRotation}deg)`;
|
|
98
|
+
el.style.opacity = String(props.opacity);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
102
|
+
function subscribe(onChange) {
|
|
103
|
+
const query = window.matchMedia?.(REDUCED_MOTION_QUERY);
|
|
104
|
+
query?.addEventListener("change", onChange);
|
|
105
|
+
return () => query?.removeEventListener("change", onChange);
|
|
106
|
+
}
|
|
107
|
+
function getSnapshot() {
|
|
108
|
+
return !(window.matchMedia?.(REDUCED_MOTION_QUERY).matches ?? false);
|
|
109
|
+
}
|
|
110
|
+
function useMotionAllowed() {
|
|
111
|
+
return useSyncExternalStore(subscribe, getSnapshot, () => false);
|
|
112
|
+
}
|
|
113
|
+
function useReducedMotion() {
|
|
114
|
+
return !useSyncExternalStore(subscribe, getSnapshot, () => true);
|
|
115
|
+
}
|
|
116
|
+
function useCatsHidden() {
|
|
117
|
+
return useSyncExternalStore(onCatsHiddenChange, areCatsHidden, () => false);
|
|
118
|
+
}
|
|
119
|
+
function Oneko({
|
|
120
|
+
paused = ONEKO_DEFAULTS.paused,
|
|
121
|
+
followCursor = ONEKO_DEFAULTS.followCursor,
|
|
122
|
+
sleepEnabled = ONEKO_DEFAULTS.sleepEnabled,
|
|
123
|
+
bubblePlacement = ONEKO_DEFAULTS.bubblePlacement,
|
|
124
|
+
bubbleScale = ONEKO_DEFAULTS.bubbleScale,
|
|
125
|
+
soundBasePath = ONEKO_DEFAULTS.soundBasePath,
|
|
126
|
+
storageKey = ONEKO_DEFAULTS.storageKey,
|
|
127
|
+
zones,
|
|
128
|
+
zoneAttractionChance = ONEKO_DEFAULTS.zoneAttractionChance,
|
|
129
|
+
zoneAttractionDuration = ONEKO_DEFAULTS.zoneAttractionDuration,
|
|
130
|
+
skin = ONEKO_DEFAULTS.skin,
|
|
131
|
+
spriteSrc,
|
|
132
|
+
persistPosition = ONEKO_DEFAULTS.persistPosition,
|
|
133
|
+
/** One below max so fixed UI can sit above the cat. */
|
|
134
|
+
zIndex = ONEKO_DEFAULTS.zIndex,
|
|
135
|
+
initialPos,
|
|
136
|
+
speed = ONEKO_DEFAULTS.speed,
|
|
137
|
+
scale = ONEKO_DEFAULTS.scale,
|
|
138
|
+
opacity = ONEKO_DEFAULTS.opacity,
|
|
139
|
+
rotationAmount = ONEKO_DEFAULTS.rotationAmount,
|
|
140
|
+
idleThreshold = ONEKO_DEFAULTS.idleThreshold,
|
|
141
|
+
meow = ONEKO_DEFAULTS.meow,
|
|
142
|
+
onStateChange,
|
|
143
|
+
freerunChance = ONEKO_DEFAULTS.freerunChance,
|
|
144
|
+
freerunDuration = ONEKO_DEFAULTS.freerunDuration,
|
|
145
|
+
bubbleEnabled = ONEKO_DEFAULTS.bubbleEnabled,
|
|
146
|
+
bubbleDisplayFrames = ONEKO_DEFAULTS.bubbleDisplayFrames,
|
|
147
|
+
bubbleCooldown = ONEKO_DEFAULTS.bubbleCooldown,
|
|
148
|
+
hueRotate = ONEKO_DEFAULTS.hueRotate,
|
|
149
|
+
liveStateRef,
|
|
150
|
+
bubbleChance = ONEKO_DEFAULTS.bubbleChance,
|
|
151
|
+
followDistance = ONEKO_DEFAULTS.followDistance,
|
|
152
|
+
animationSpeed = ONEKO_DEFAULTS.animationSpeed,
|
|
153
|
+
bubbleText = ONEKO_DEFAULTS.bubbleText,
|
|
154
|
+
volume = ONEKO_DEFAULTS.volume,
|
|
155
|
+
laserPointer = ONEKO_DEFAULTS.laserPointer,
|
|
156
|
+
reducedMotion = ONEKO_DEFAULTS.reducedMotion,
|
|
157
|
+
chase = ONEKO_DEFAULTS.chase,
|
|
158
|
+
napWhileTyping = ONEKO_DEFAULTS.napWhileTyping,
|
|
159
|
+
followFocus = ONEKO_DEFAULTS.followFocus,
|
|
160
|
+
perchOnHover = ONEKO_DEFAULTS.perchOnHover,
|
|
161
|
+
pettable = ONEKO_DEFAULTS.pettable
|
|
162
|
+
}) {
|
|
163
|
+
const hidden = useCatsHidden();
|
|
164
|
+
const motionAllowed = useMotionAllowed() && !hidden;
|
|
165
|
+
const prefersReducedMotion = useReducedMotion();
|
|
166
|
+
const restingSource = useSkinSource(skin, spriteSrc);
|
|
167
|
+
const elRef = useRef(null);
|
|
168
|
+
const lastStateRef = useRef("idle");
|
|
169
|
+
const onStateChangeRef = useRef(onStateChange);
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
onStateChangeRef.current = onStateChange;
|
|
172
|
+
}, [onStateChange]);
|
|
173
|
+
const config = {
|
|
174
|
+
paused,
|
|
175
|
+
followCursor,
|
|
176
|
+
sleepEnabled,
|
|
177
|
+
bubblePlacement,
|
|
178
|
+
bubbleScale,
|
|
179
|
+
soundBasePath,
|
|
180
|
+
zones,
|
|
181
|
+
zoneAttractionChance,
|
|
182
|
+
zoneAttractionDuration,
|
|
183
|
+
speed,
|
|
184
|
+
scale,
|
|
185
|
+
opacity,
|
|
186
|
+
rotationAmount,
|
|
187
|
+
idleThreshold,
|
|
188
|
+
freerunChance,
|
|
189
|
+
freerunDuration,
|
|
190
|
+
bubbleEnabled,
|
|
191
|
+
bubbleDisplayFrames,
|
|
192
|
+
bubbleCooldown,
|
|
193
|
+
bubbleChance,
|
|
194
|
+
followDistance,
|
|
195
|
+
animationSpeed,
|
|
196
|
+
bubbleText,
|
|
197
|
+
meow,
|
|
198
|
+
volume,
|
|
199
|
+
laserPointer: laserPointer && followCursor && !paused,
|
|
200
|
+
chase,
|
|
201
|
+
napWhileTyping,
|
|
202
|
+
followFocus,
|
|
203
|
+
perchOnHover
|
|
204
|
+
};
|
|
205
|
+
const [initialState] = useState(() => createInitialCatState({ initialPos, ...config }));
|
|
206
|
+
const stateRef = useRef(initialState);
|
|
207
|
+
useCatAnimation({
|
|
208
|
+
enabled: motionAllowed,
|
|
209
|
+
stateRef,
|
|
210
|
+
elRef,
|
|
211
|
+
lastStateRef,
|
|
212
|
+
onStateChangeRef,
|
|
213
|
+
liveStateRef,
|
|
214
|
+
persistPosition,
|
|
215
|
+
storageKey,
|
|
216
|
+
zIndex,
|
|
217
|
+
pettable
|
|
218
|
+
});
|
|
219
|
+
useOnekoPropsSync(stateRef, elRef, {
|
|
220
|
+
...config,
|
|
221
|
+
hueRotate,
|
|
222
|
+
skin,
|
|
223
|
+
spriteSrc
|
|
224
|
+
});
|
|
225
|
+
if (!hidden && prefersReducedMotion && reducedMotion === "rest" && restingSource) {
|
|
226
|
+
return /* @__PURE__ */ jsx(
|
|
227
|
+
RestingCat,
|
|
228
|
+
{
|
|
229
|
+
source: restingSource,
|
|
230
|
+
position: persistPosition && readPersistedPosition(storageKey) || initialPos,
|
|
231
|
+
scale,
|
|
232
|
+
opacity,
|
|
233
|
+
hueRotate,
|
|
234
|
+
zIndex
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
return motionAllowed && config.laserPointer ? /* @__PURE__ */ jsx(LaserCursor, { zIndex }) : null;
|
|
239
|
+
}
|
|
240
|
+
function RestingCat({
|
|
241
|
+
source,
|
|
242
|
+
position,
|
|
243
|
+
scale,
|
|
244
|
+
opacity,
|
|
245
|
+
hueRotate,
|
|
246
|
+
zIndex
|
|
247
|
+
}) {
|
|
248
|
+
const inset = TILE * scale / 2 + 16;
|
|
249
|
+
return /* @__PURE__ */ jsx(
|
|
250
|
+
"div",
|
|
251
|
+
{
|
|
252
|
+
"aria-hidden": "true",
|
|
253
|
+
style: {
|
|
254
|
+
position: "fixed",
|
|
255
|
+
left: position ? position.x - TILE / 2 : void 0,
|
|
256
|
+
top: position ? position.y - TILE / 2 : void 0,
|
|
257
|
+
right: position ? void 0 : inset - TILE / 2,
|
|
258
|
+
bottom: position ? void 0 : inset - TILE / 2,
|
|
259
|
+
width: TILE,
|
|
260
|
+
height: TILE,
|
|
261
|
+
pointerEvents: "none",
|
|
262
|
+
imageRendering: "pixelated",
|
|
263
|
+
backgroundImage: `url(${JSON.stringify(source)})`,
|
|
264
|
+
backgroundRepeat: "no-repeat",
|
|
265
|
+
backgroundSize: "256px 128px",
|
|
266
|
+
// Sleeping frame, matching defaultSpriteSets.sleeping[0].
|
|
267
|
+
backgroundPosition: `-${2 * TILE}px 0`,
|
|
268
|
+
transform: `scale(${scale})`,
|
|
269
|
+
opacity,
|
|
270
|
+
filter: hueRotate ? `hue-rotate(${hueRotate}deg)` : void 0,
|
|
271
|
+
zIndex
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
export {
|
|
277
|
+
e as ONEKO_SKINS,
|
|
278
|
+
Oneko,
|
|
279
|
+
areCatsHidden,
|
|
280
|
+
c as createOneko,
|
|
281
|
+
Oneko as default,
|
|
282
|
+
i as isOnekoSkin,
|
|
283
|
+
onCatsHiddenChange,
|
|
284
|
+
f as setCatsHidden,
|
|
285
|
+
useCatsHidden
|
|
286
|
+
};
|
package/dist/solid.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { onMount, onCleanup, createEffect } from "solid-js";
|
|
2
|
+
import { c as createOneko } from "./chunks/vanilla-CUrawvWx.js";
|
|
3
|
+
import { createPropsUpdater } from "./adapter.js";
|
|
4
|
+
function Oneko(props) {
|
|
5
|
+
let update;
|
|
6
|
+
onMount(() => {
|
|
7
|
+
const cat = createOneko();
|
|
8
|
+
update = createPropsUpdater(cat);
|
|
9
|
+
update({ ...props });
|
|
10
|
+
onCleanup(() => cat.destroy());
|
|
11
|
+
});
|
|
12
|
+
createEffect(() => update?.({ ...props }));
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
Oneko as default
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
import { createOneko, type OnekoOptions } from "../vanilla.js";
|
|
4
|
+
import { createPropsUpdater } from "../adapter.js";
|
|
5
|
+
|
|
6
|
+
const props: OnekoOptions = $props();
|
|
7
|
+
let update = $state.raw<ReturnType<typeof createPropsUpdater>>();
|
|
8
|
+
|
|
9
|
+
onMount(() => {
|
|
10
|
+
const cat = createOneko();
|
|
11
|
+
update = createPropsUpdater(cat);
|
|
12
|
+
update({ ...props });
|
|
13
|
+
return () => cat.destroy();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
$effect(() => update?.({ ...props }));
|
|
17
|
+
</script>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { setCatsHidden } from "../lib/oneko/pack";
|
|
2
|
+
import type { CatActivityState, CatLiveState, OnekoProps } from "../lib/oneko/types";
|
|
3
|
+
export type { CatActivityState, CatLiveState, OnekoProps };
|
|
4
|
+
export type { OnekoSkin } from "../lib/oneko/skins";
|
|
5
|
+
export type { OnekoZone } from "../lib/oneko/zones";
|
|
6
|
+
export { setCatsHidden };
|
|
7
|
+
/** The visitor's remembered choice to hide every cat on the site. Pair with setCatsHidden. */
|
|
8
|
+
export declare function useCatsHidden(): boolean;
|
|
9
|
+
export default function Oneko({ paused, followCursor, sleepEnabled, bubblePlacement, bubbleScale, soundBasePath, storageKey, zones, zoneAttractionChance, zoneAttractionDuration, skin, spriteSrc, persistPosition,
|
|
10
|
+
/** One below max so fixed UI can sit above the cat. */
|
|
11
|
+
zIndex, initialPos, speed, scale, opacity, rotationAmount, idleThreshold, meow, onStateChange, freerunChance, freerunDuration, bubbleEnabled, bubbleDisplayFrames, bubbleCooldown, hueRotate, liveStateRef, bubbleChance, followDistance, animationSpeed, bubbleText, volume, laserPointer, reducedMotion, chase, napWhileTyping, followFocus, perchOnHover, pettable, }: OnekoProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CatActivityState, CatLiveState, CatRuntimeState } from "../lib/oneko/types";
|
|
2
|
+
export declare function useCatAnimation({ enabled, stateRef, elRef, lastStateRef, onStateChangeRef, liveStateRef, persistPosition, storageKey, zIndex, pettable, }: {
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
stateRef: {
|
|
5
|
+
current: CatRuntimeState;
|
|
6
|
+
};
|
|
7
|
+
elRef: {
|
|
8
|
+
current: HTMLDivElement | null;
|
|
9
|
+
};
|
|
10
|
+
lastStateRef: {
|
|
11
|
+
current: CatActivityState;
|
|
12
|
+
};
|
|
13
|
+
onStateChangeRef: {
|
|
14
|
+
current: ((state: CatActivityState) => void) | undefined;
|
|
15
|
+
};
|
|
16
|
+
liveStateRef?: {
|
|
17
|
+
current: CatLiveState;
|
|
18
|
+
};
|
|
19
|
+
persistPosition: boolean;
|
|
20
|
+
storageKey: string;
|
|
21
|
+
zIndex: number;
|
|
22
|
+
pettable: boolean;
|
|
23
|
+
}): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type CatRuntimeConfig } from "../lib/oneko/runtime-config";
|
|
2
|
+
import type { OnekoSkin } from "../lib/oneko/skins";
|
|
3
|
+
import type { CatRuntimeState } from "../lib/oneko/types";
|
|
4
|
+
type SyncableProps = CatRuntimeConfig & {
|
|
5
|
+
hueRotate: number;
|
|
6
|
+
skin: OnekoSkin;
|
|
7
|
+
spriteSrc?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function useOnekoPropsSync(stateRef: {
|
|
10
|
+
current: CatRuntimeState;
|
|
11
|
+
}, elRef: {
|
|
12
|
+
current: HTMLDivElement | null;
|
|
13
|
+
}, props: SyncableProps): void;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Soften sprite changes without affecting movement, scale, or the selected tint. */
|
|
2
|
+
export declare function useSpriteAppearance(elRef: {
|
|
3
|
+
current: HTMLElement | null;
|
|
4
|
+
},
|
|
5
|
+
/** Undefined while a skin loads; the current sheet stays until the next one is ready. */
|
|
6
|
+
source: string | undefined, hueRotate?: number): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CatActivityState, CatRuntimeState } from "../types";
|
|
2
|
+
import type { CatAnimationDeps } from "./deps";
|
|
3
|
+
export declare function getActivityLabel(deps: CatAnimationDeps): CatActivityState;
|
|
4
|
+
export declare function getBubbleStatus(s: CatRuntimeState): string;
|
|
5
|
+
export declare function playSound(deps: CatAnimationDeps, pool: string[]): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CatRuntimeState } from "../types";
|
|
2
|
+
import type { CatAnimationDeps } from "./deps";
|
|
3
|
+
/** How close the cat gets before it settles, depending on what it is after. */
|
|
4
|
+
export declare function stopDistance(s: CatRuntimeState): number;
|
|
5
|
+
/** Per-frame upkeep for page reactions; runs before the movement target is chosen. */
|
|
6
|
+
export declare function tickAttention(deps: CatAnimationDeps): void;
|
|
7
|
+
/**
|
|
8
|
+
* Listens to the page for typing, keyboard focus, and resting pointers. Options are read from
|
|
9
|
+
* the runtime state on every event, so toggling them needs no restart.
|
|
10
|
+
*/
|
|
11
|
+
export declare function watchPage(deps: CatAnimationDeps): () => void;
|
|
12
|
+
/** Turns the cat into a focusable "Pet the cat" button. It holds still while focused. */
|
|
13
|
+
export declare function makePettable(deps: CatAnimationDeps): () => void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CatAnimationDeps } from "./deps";
|
|
2
|
+
export declare function pickFromPool(deps: CatAnimationDeps, pool: readonly string[]): string;
|
|
3
|
+
export declare function showBubble(deps: CatAnimationDeps): void;
|
|
4
|
+
export declare function hideBubble(deps: CatAnimationDeps): void;
|
|
5
|
+
export declare function updateBubble(deps: CatAnimationDeps): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CatActivityState, CatLiveState, CatRuntimeState } from "../types";
|
|
2
|
+
export interface CatAnimationDeps {
|
|
3
|
+
stateRef: {
|
|
4
|
+
current: CatRuntimeState;
|
|
5
|
+
};
|
|
6
|
+
el: HTMLDivElement;
|
|
7
|
+
bubbleEl: HTMLDivElement;
|
|
8
|
+
bubbleTextEl: HTMLDivElement;
|
|
9
|
+
bubbleTail: HTMLDivElement;
|
|
10
|
+
debugSVG: SVGSVGElement;
|
|
11
|
+
debugHUD: HTMLDivElement;
|
|
12
|
+
lastStateRef: {
|
|
13
|
+
current: CatActivityState;
|
|
14
|
+
};
|
|
15
|
+
onStateChangeRef: {
|
|
16
|
+
current: ((state: CatActivityState) => void) | undefined;
|
|
17
|
+
};
|
|
18
|
+
liveStateRef?: {
|
|
19
|
+
current: CatLiveState;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CatAnimationDeps } from "./deps";
|
|
2
|
+
export declare function maybeStartIdleAnimation(deps: CatAnimationDeps): void;
|
|
3
|
+
export declare function updateIdleAnimation(deps: CatAnimationDeps): boolean;
|
|
4
|
+
export declare function freezeLockedState(deps: CatAnimationDeps): boolean;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { defaultSpriteSets } from "../constants";
|
|
2
|
+
import type { CatAnimationDeps } from "./deps";
|
|
3
|
+
export declare function setSprite(deps: CatAnimationDeps, name: keyof typeof defaultSpriteSets | string, frame: number): void;
|
|
4
|
+
export declare function directionFromDelta(dx: number, dy: number): string | null;
|
|
5
|
+
export declare function clearRotation(deps: CatAnimationDeps): void;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { CatActivityState } from "./types";
|
|
2
|
+
export declare const TILE = 32;
|
|
3
|
+
export declare const DEFAULT_Z_INDEX = 2147483646;
|
|
4
|
+
export declare const STEER_LERP = 0.3;
|
|
5
|
+
export declare const MAX_VEL_FACTOR = 1.5;
|
|
6
|
+
export declare const OBSTACLE_INTERVAL = 30;
|
|
7
|
+
export declare const MIN_OBSTACLE_AREA = 500;
|
|
8
|
+
export declare const OBSTACLE_SELECTOR = "h1,h2,h3,h4,h5,h6,p,blockquote,a,button,img,svg,picture,video,nav,header,label,[role='button'],[data-oneko-obstacle]";
|
|
9
|
+
export declare const CELL_SIZE = 16;
|
|
10
|
+
export declare const SPRITE_RADIUS = 8;
|
|
11
|
+
export declare const PATH_RECALC_INTERVAL = 10;
|
|
12
|
+
export declare const PATH_RECALC_MOUSE_CELLS = 2;
|
|
13
|
+
export declare const WAYPOINT_REACH_DIST = 16;
|
|
14
|
+
export declare const BUBBLE_DISPLAY_FRAMES = 180;
|
|
15
|
+
export declare const BUBBLE_COOLDOWN_FRAMES = 120;
|
|
16
|
+
/** Pixels between mouse samples before we treat movement as a new heading */
|
|
17
|
+
export declare const MOUSE_LOOP_MIN_STEP = 5;
|
|
18
|
+
/** Total radians of cursor-heading spin to count as “going in circles” */
|
|
19
|
+
export declare const MOUSE_LOOP_WINDING_TRIGGER = 6.2;
|
|
20
|
+
/** Soft cap so winding doesn’t run away (about two full spins) */
|
|
21
|
+
export declare const MOUSE_LOOP_WINDING_CAP = 13;
|
|
22
|
+
/** Per logic frame decay so old spinning fades out */
|
|
23
|
+
export declare const MOUSE_LOOP_WINDING_DECAY = 0.96;
|
|
24
|
+
export declare const IDLE_MESSAGES: string[];
|
|
25
|
+
export declare const MOVING_MESSAGES: string[];
|
|
26
|
+
export declare const CIRCLE_LOOP_MESSAGES: string[];
|
|
27
|
+
export declare const SLEEPING_MESSAGES: string[];
|
|
28
|
+
export declare const SCRATCHING_MESSAGES: string[];
|
|
29
|
+
export declare const TIRED_MESSAGES: string[];
|
|
30
|
+
export declare const WALL_SCRATCH_MESSAGES: string[];
|
|
31
|
+
export declare const ALERT_MESSAGES: string[];
|
|
32
|
+
export declare const FREERUN_MESSAGES: string[];
|
|
33
|
+
export declare const FREERUN_CHANCE = 0.06;
|
|
34
|
+
export declare const FREERUN_DURATION = 40;
|
|
35
|
+
export declare const DEFAULT_SPEED = 10;
|
|
36
|
+
export declare const DEFAULT_SCALE = 1;
|
|
37
|
+
export declare const DEFAULT_OPACITY = 1;
|
|
38
|
+
export declare const DEFAULT_ROTATION_AMOUNT = 15;
|
|
39
|
+
export declare const DEFAULT_IDLE_THRESHOLD_MS = 1000;
|
|
40
|
+
export declare const DEFAULT_VOLUME = 0.5;
|
|
41
|
+
export declare const DEFAULT_BUBBLE_CHANCE = 0.5;
|
|
42
|
+
export declare const DEFAULT_FOLLOW_DISTANCE = 20;
|
|
43
|
+
export declare const DEFAULT_ANIMATION_SPEED = 1;
|
|
44
|
+
export declare const PET_MESSAGES: string[];
|
|
45
|
+
export declare const PET_SOUND_POOL: string[];
|
|
46
|
+
export declare const LASER_CATCH_POOL: string[];
|
|
47
|
+
export declare const SOUND_POOLS: Record<CatActivityState, string[]>;
|
|
48
|
+
export declare const KONAMI_SEQUENCE: string[];
|
|
49
|
+
export declare const KONAMI_TARGET: string;
|
|
50
|
+
export declare const DIRECTION_RANGES: readonly [{
|
|
51
|
+
readonly min: -22.5;
|
|
52
|
+
readonly max: 22.5;
|
|
53
|
+
readonly dir: "E";
|
|
54
|
+
}, {
|
|
55
|
+
readonly min: 22.5;
|
|
56
|
+
readonly max: 67.5;
|
|
57
|
+
readonly dir: "SE";
|
|
58
|
+
}, {
|
|
59
|
+
readonly min: 67.5;
|
|
60
|
+
readonly max: 112.5;
|
|
61
|
+
readonly dir: "S";
|
|
62
|
+
}, {
|
|
63
|
+
readonly min: 112.5;
|
|
64
|
+
readonly max: 157.5;
|
|
65
|
+
readonly dir: "SW";
|
|
66
|
+
}, {
|
|
67
|
+
readonly min: -157.5;
|
|
68
|
+
readonly max: -112.5;
|
|
69
|
+
readonly dir: "NW";
|
|
70
|
+
}, {
|
|
71
|
+
readonly min: -112.5;
|
|
72
|
+
readonly max: -67.5;
|
|
73
|
+
readonly dir: "N";
|
|
74
|
+
}, {
|
|
75
|
+
readonly min: -67.5;
|
|
76
|
+
readonly max: -22.5;
|
|
77
|
+
readonly dir: "NE";
|
|
78
|
+
}];
|
|
79
|
+
export declare const NEIGHBOR_OFFSETS: [number, number, number][];
|
|
80
|
+
export declare const defaultSpriteSets: {
|
|
81
|
+
readonly idle: readonly [readonly [-3, -3]];
|
|
82
|
+
readonly alert: readonly [readonly [-7, -3]];
|
|
83
|
+
readonly scratchSelf: readonly [readonly [-5, 0], readonly [-6, 0], readonly [-7, 0]];
|
|
84
|
+
readonly scratchWallN: readonly [readonly [0, 0], readonly [0, -1]];
|
|
85
|
+
readonly scratchWallS: readonly [readonly [-7, -1], readonly [-6, -2]];
|
|
86
|
+
readonly scratchWallE: readonly [readonly [-2, -2], readonly [-2, -3]];
|
|
87
|
+
readonly scratchWallW: readonly [readonly [-4, 0], readonly [-4, -1]];
|
|
88
|
+
readonly tired: readonly [readonly [-3, -2]];
|
|
89
|
+
readonly sleeping: readonly [readonly [-2, 0], readonly [-2, -1]];
|
|
90
|
+
readonly N: readonly [readonly [-1, -2], readonly [-1, -3]];
|
|
91
|
+
readonly NE: readonly [readonly [0, -2], readonly [0, -3]];
|
|
92
|
+
readonly E: readonly [readonly [-3, 0], readonly [-3, -1]];
|
|
93
|
+
readonly SE: readonly [readonly [-5, -1], readonly [-5, -2]];
|
|
94
|
+
readonly S: readonly [readonly [-6, -3], readonly [-7, -2]];
|
|
95
|
+
readonly SW: readonly [readonly [-5, -3], readonly [-6, -1]];
|
|
96
|
+
readonly W: readonly [readonly [-4, -2], readonly [-4, -3]];
|
|
97
|
+
readonly NW: readonly [readonly [-1, 0], readonly [-1, -1]];
|
|
98
|
+
};
|
|
99
|
+
export declare const IDLE_ANIMATION_DURATIONS: Record<string, number>;
|
|
100
|
+
export declare const debugColor: {
|
|
101
|
+
panelBg: string;
|
|
102
|
+
panelBorder: string;
|
|
103
|
+
panelText: string;
|
|
104
|
+
panelSubtle: string;
|
|
105
|
+
controlBg: string;
|
|
106
|
+
controlBorder: string;
|
|
107
|
+
accent: string;
|
|
108
|
+
accentStrong: string;
|
|
109
|
+
danger: string;
|
|
110
|
+
dangerSoft: string;
|
|
111
|
+
trail: string;
|
|
112
|
+
trailDot: string;
|
|
113
|
+
gridStroke: string;
|
|
114
|
+
};
|
|
115
|
+
export declare const DEFAULT_POSITION: {
|
|
116
|
+
x: number;
|
|
117
|
+
y: number;
|
|
118
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CatRuntimeState } from "../types";
|
|
2
|
+
export declare function appendBubbleSection(body: HTMLElement, stateRef: {
|
|
3
|
+
current: CatRuntimeState;
|
|
4
|
+
}, bubbleEl: HTMLDivElement, bubbleTextEl: HTMLDivElement, showBubble: () => void, hideBubble: () => void, bubbleDisplayFrames: number): void;
|