page-mascot 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 +91 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/mascot.d.ts +11 -0
- package/dist/mascot.js +168 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kamran Ahmed <https://kamran.fyi>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<img src=".github/fox.png" width="160" alt="">
|
|
2
|
+
|
|
3
|
+
# page-mascot
|
|
4
|
+
|
|
5
|
+
A character for the top of your page. It follows the reader's cursor and blinks when they
|
|
6
|
+
poke it. Fifty-two are already drawn. An agent skill draws new ones, or one that looks
|
|
7
|
+
like you.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i page-mascot
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Use one that is drawn
|
|
16
|
+
|
|
17
|
+
Pick a character on the [demo page](https://koboyo.com/page-mascot) and download its two
|
|
18
|
+
sheets into `public/mascots`, then point the component at them:
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { Mascot } from 'page-mascot'
|
|
22
|
+
|
|
23
|
+
<Mascot
|
|
24
|
+
directions="/mascots/fox-directions.webp"
|
|
25
|
+
reactions="/mascots/fox-reactions.webp"
|
|
26
|
+
/>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The paths are whatever your app serves, so imported images work too.
|
|
30
|
+
|
|
31
|
+
Or let an agent do it, once the skill below is installed:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
/page-mascot put the fox on my page
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Draw your own
|
|
38
|
+
|
|
39
|
+
Install the skill:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx skills add nilbuild/page-mascot --skill page-mascot --global --yes
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then ask your agent:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
/page-mascot a chibi otter with chocolate-brown fur
|
|
49
|
+
/page-mascot make one that looks like me [attach a photo]
|
|
50
|
+
/page-mascot a chibi fox, in the riso style
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
It draws the nine directions and nine expressions, builds them into two aligned sheets,
|
|
54
|
+
checks the character does not jump between them, and puts the component on your page, with
|
|
55
|
+
the same two props as above.
|
|
56
|
+
|
|
57
|
+
Drawing needs an image tool. Codex has one. Claude Code uses the OpenAI images API, so set
|
|
58
|
+
`OPENAI_API_KEY` first. With neither, `skills/page-mascot/reference/prompts.md` has the
|
|
59
|
+
prompts for making the sheets by hand in any chat UI.
|
|
60
|
+
|
|
61
|
+
## Props
|
|
62
|
+
|
|
63
|
+
| prop | default | |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| `directions` | none | path to the directions sheet |
|
|
66
|
+
| `reactions` | none | path to the reactions sheet |
|
|
67
|
+
| `size` | `140` | px, square |
|
|
68
|
+
| `label` | `'mascot'` | what a screen reader calls it |
|
|
69
|
+
| `className` | | |
|
|
70
|
+
|
|
71
|
+
Tracking switches off without a fine pointer, and the click squash honours
|
|
72
|
+
`prefers-reduced-motion`.
|
|
73
|
+
|
|
74
|
+
## How it works
|
|
75
|
+
|
|
76
|
+
Each character is two 3×3 sprite sheets: nine head directions, and nine expressions.
|
|
77
|
+
|
|
78
|
+

|
|
79
|
+
|
|
80
|
+
The pointer's angle picks a cell on the directions sheet, with a dead zone so the head
|
|
81
|
+
settles when the cursor is close. A click shows a cell from the reactions sheet for half a
|
|
82
|
+
second. One `background-position` and no animation library.
|
|
83
|
+
|
|
84
|
+
The same character can be drawn in six styles: colour, ink, sketch, riso, paper and pixel.
|
|
85
|
+
Only the rendering changes, so the alignment holds.
|
|
86
|
+
|
|
87
|
+

|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT © [Kamran Ahmed](https://kamran.fyi)
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Mascot } from './mascot.js';
|
package/dist/mascot.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type MascotProps = {
|
|
2
|
+
/** The 3x3 sheet of head directions. A served path, or an imported image. */
|
|
3
|
+
directions: string;
|
|
4
|
+
/** The 3x3 sheet of expressions. */
|
|
5
|
+
reactions: string;
|
|
6
|
+
size?: number;
|
|
7
|
+
className?: string;
|
|
8
|
+
/** What a screen reader calls it. */
|
|
9
|
+
label?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function Mascot(props: MascotProps): import("react").JSX.Element;
|
package/dist/mascot.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
const DIRECTIONS = [
|
|
4
|
+
'up-left',
|
|
5
|
+
'up',
|
|
6
|
+
'up-right',
|
|
7
|
+
'left',
|
|
8
|
+
'center',
|
|
9
|
+
'right',
|
|
10
|
+
'down-left',
|
|
11
|
+
'down',
|
|
12
|
+
'down-right',
|
|
13
|
+
];
|
|
14
|
+
const REACTIONS = [
|
|
15
|
+
'blink',
|
|
16
|
+
'heart',
|
|
17
|
+
'sparkle',
|
|
18
|
+
'surprised',
|
|
19
|
+
'wink',
|
|
20
|
+
'bashful',
|
|
21
|
+
'sleepy',
|
|
22
|
+
'dizzy',
|
|
23
|
+
'delighted',
|
|
24
|
+
];
|
|
25
|
+
// Clockwise from the right, matching atan2 with y pointing down.
|
|
26
|
+
const CLOCKWISE = [
|
|
27
|
+
'right',
|
|
28
|
+
'down-right',
|
|
29
|
+
'down',
|
|
30
|
+
'down-left',
|
|
31
|
+
'left',
|
|
32
|
+
'up-left',
|
|
33
|
+
'up',
|
|
34
|
+
'up-right',
|
|
35
|
+
];
|
|
36
|
+
const SECTOR = (Math.PI * 2) / CLOCKWISE.length;
|
|
37
|
+
const HYSTERESIS = 0.12;
|
|
38
|
+
const DEAD_ZONE = 70;
|
|
39
|
+
const PAYOFFS = ['heart', 'sparkle', 'delighted'];
|
|
40
|
+
const BOOP_PAYOFF = 120;
|
|
41
|
+
const BOOP_END = 560;
|
|
42
|
+
const SQUASH_MS = 420;
|
|
43
|
+
const DIZZY_AFTER = 4;
|
|
44
|
+
const DIZZY_WINDOW = 1600;
|
|
45
|
+
const DIZZY_END = 1100;
|
|
46
|
+
const SQUASH = [
|
|
47
|
+
{ transform: 'scale(1, 1)', easing: 'ease-in' },
|
|
48
|
+
{ transform: 'scale(1.10, 0.86)', offset: 0.18, easing: 'ease-out' },
|
|
49
|
+
{ transform: 'scale(0.95, 1.08)', offset: 0.45, easing: 'ease-in-out' },
|
|
50
|
+
{ transform: 'scale(1.03, 0.97)', offset: 0.72, easing: 'ease-in-out' },
|
|
51
|
+
{ transform: 'scale(1, 1)' },
|
|
52
|
+
];
|
|
53
|
+
// background-size 300% makes each cell a clean 0/50/100% step on both axes.
|
|
54
|
+
function cell(index) {
|
|
55
|
+
return { backgroundPosition: `${(index % 3) * 50}% ${Math.floor(index / 3) * 50}%` };
|
|
56
|
+
}
|
|
57
|
+
function wrap(angle) {
|
|
58
|
+
return Math.atan2(Math.sin(angle), Math.cos(angle));
|
|
59
|
+
}
|
|
60
|
+
const layer = {
|
|
61
|
+
position: 'absolute',
|
|
62
|
+
inset: 0,
|
|
63
|
+
backgroundSize: '300% 300%',
|
|
64
|
+
backgroundRepeat: 'no-repeat',
|
|
65
|
+
};
|
|
66
|
+
export function Mascot(props) {
|
|
67
|
+
const { directions, reactions, size = 140, className, label = 'mascot' } = props;
|
|
68
|
+
const buttonRef = useRef(null);
|
|
69
|
+
const squashRef = useRef(null);
|
|
70
|
+
const timersRef = useRef([]);
|
|
71
|
+
const boopsRef = useRef({ count: 0, at: 0 });
|
|
72
|
+
const [direction, setDirection] = useState('center');
|
|
73
|
+
const [reaction, setReaction] = useState(null);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (!window.matchMedia('(hover: hover) and (pointer: fine)').matches) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
let sector = -1;
|
|
79
|
+
let pointer = null;
|
|
80
|
+
const aim = () => {
|
|
81
|
+
const button = buttonRef.current;
|
|
82
|
+
if (!button || !pointer) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const box = button.getBoundingClientRect();
|
|
86
|
+
const dx = pointer.x - (box.left + box.width / 2);
|
|
87
|
+
const dy = pointer.y - (box.top + box.height / 2);
|
|
88
|
+
if (Math.hypot(dx, dy) < DEAD_ZONE) {
|
|
89
|
+
sector = -1;
|
|
90
|
+
setDirection('center');
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// Hold the current sector until the pointer is well past its edge.
|
|
94
|
+
const angle = Math.atan2(dy, dx);
|
|
95
|
+
if (sector !== -1 && Math.abs(wrap(angle - sector * SECTOR)) < SECTOR / 2 + HYSTERESIS) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
sector = (Math.round(angle / SECTOR) + CLOCKWISE.length) % CLOCKWISE.length;
|
|
99
|
+
setDirection(CLOCKWISE[sector]);
|
|
100
|
+
};
|
|
101
|
+
const onPointerMove = (event) => {
|
|
102
|
+
pointer = { x: event.clientX, y: event.clientY };
|
|
103
|
+
aim();
|
|
104
|
+
};
|
|
105
|
+
window.addEventListener('pointermove', onPointerMove, { passive: true });
|
|
106
|
+
window.addEventListener('scroll', aim, { passive: true });
|
|
107
|
+
return () => {
|
|
108
|
+
window.removeEventListener('pointermove', onPointerMove);
|
|
109
|
+
window.removeEventListener('scroll', aim);
|
|
110
|
+
};
|
|
111
|
+
}, []);
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
return () => {
|
|
114
|
+
timersRef.current.forEach(window.clearTimeout);
|
|
115
|
+
};
|
|
116
|
+
}, []);
|
|
117
|
+
const boop = () => {
|
|
118
|
+
timersRef.current.forEach(window.clearTimeout);
|
|
119
|
+
timersRef.current = [];
|
|
120
|
+
const later = (ms, next) => {
|
|
121
|
+
timersRef.current.push(window.setTimeout(() => setReaction(next), ms));
|
|
122
|
+
};
|
|
123
|
+
const now = Date.now();
|
|
124
|
+
const boops = boopsRef.current;
|
|
125
|
+
boops.count = now - boops.at < DIZZY_WINDOW ? boops.count + 1 : 1;
|
|
126
|
+
boops.at = now;
|
|
127
|
+
if (boops.count >= DIZZY_AFTER) {
|
|
128
|
+
boops.count = 0;
|
|
129
|
+
setReaction('dizzy');
|
|
130
|
+
later(DIZZY_END, null);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
setReaction('blink');
|
|
134
|
+
later(BOOP_PAYOFF, PAYOFFS[(boops.count - 1) % PAYOFFS.length]);
|
|
135
|
+
later(BOOP_END, null);
|
|
136
|
+
}
|
|
137
|
+
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Per-keyframe easing with the effect itself linear: an easing on the effect
|
|
141
|
+
// would reinterpret every offset and front-load the whole bounce.
|
|
142
|
+
squashRef.current?.animate(SQUASH, { duration: SQUASH_MS, easing: 'linear' });
|
|
143
|
+
};
|
|
144
|
+
// Inline styles so the file drops into any project without a CSS framework.
|
|
145
|
+
return (_jsx("button", { ref: buttonRef, type: "button", onClick: boop, "aria-label": `Boop the ${label}`, className: className, style: {
|
|
146
|
+
position: 'relative',
|
|
147
|
+
display: 'block',
|
|
148
|
+
flexShrink: 0,
|
|
149
|
+
width: size,
|
|
150
|
+
height: size,
|
|
151
|
+
padding: 0,
|
|
152
|
+
border: 0,
|
|
153
|
+
background: 'transparent',
|
|
154
|
+
appearance: 'none',
|
|
155
|
+
cursor: 'pointer',
|
|
156
|
+
userSelect: 'none',
|
|
157
|
+
}, children: _jsxs("span", { ref: squashRef, style: { position: 'relative', display: 'block', width: '100%', height: '100%', transformOrigin: '50% 78%' }, children: [_jsx("span", { style: {
|
|
158
|
+
...layer,
|
|
159
|
+
backgroundImage: `url(${directions})`,
|
|
160
|
+
...cell(DIRECTIONS.indexOf(direction)),
|
|
161
|
+
opacity: reaction ? 0 : 1,
|
|
162
|
+
} }), _jsx("span", { style: {
|
|
163
|
+
...layer,
|
|
164
|
+
backgroundImage: `url(${reactions})`,
|
|
165
|
+
...cell(REACTIONS.indexOf(reaction ?? 'blink')),
|
|
166
|
+
opacity: reaction ? 1 : 0,
|
|
167
|
+
} })] }) }));
|
|
168
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "page-mascot",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A character for the top of your page that follows the reader's cursor and blinks when they poke it.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Kamran Ahmed",
|
|
7
|
+
"homepage": "https://koboyo.com/page-mascot",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/nilbuild/page-mascot.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": ["mascot", "avatar", "react", "cursor", "sprite", "portfolio"],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"dev": "vite",
|
|
25
|
+
"build": "tsc -p tsconfig.build.json && cp src/mascot.tsx skills/page-mascot/mascot.tsx",
|
|
26
|
+
"build:site": "npm run typecheck && vite build",
|
|
27
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
28
|
+
"lint": "oxlint",
|
|
29
|
+
"preview": "vite preview",
|
|
30
|
+
"prepack": "npm run build"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
37
|
+
"@types/node": "^24.13.3",
|
|
38
|
+
"@types/react": "^19.2.18",
|
|
39
|
+
"@types/react-dom": "^19.2.4",
|
|
40
|
+
"@vitejs/plugin-react": "^6.1.0",
|
|
41
|
+
"oxlint": "^1.79.0",
|
|
42
|
+
"react": "^19.2.8",
|
|
43
|
+
"react-dom": "^19.2.8",
|
|
44
|
+
"tailwindcss": "^4.3.3",
|
|
45
|
+
"typescript": "~6.0.2",
|
|
46
|
+
"vite": "^8.2.2"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=20"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
}
|
|
54
|
+
}
|